summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGMT 1999 Tony Gale <gale@gtk.org>1999-02-22 08:51:02 +0000
committerTony Gale <gale@src.gnome.org>1999-02-22 08:51:02 +0000
commitd5aed59bbcefe89a34da745a0f7e2abe7bcdcae6 (patch)
treeed6a2996d992e51f27831d4dc242c244a99d4c60 /examples
parent619ca57c5a58f7ec143c61880daa6ea33144df91 (diff)
downloadgtk+-d5aed59bbcefe89a34da745a0f7e2abe7bcdcae6.tar.gz
- Complete the ProgressBar API - Fix the CList example code
Mon Feb 22 08:45:10 GMT 1999 Tony Gale <gale@gtk.org> * docs/gtk_tut.sgml: - Complete the ProgressBar API - Fix the CList example code * examples/clist/clist.c, examples/progressbar/progressbar.c: Update from tutorial
Diffstat (limited to 'examples')
-rw-r--r--examples/clist/clist.c169
-rw-r--r--examples/progressbar/progressbar.c7
2 files changed, 87 insertions, 89 deletions
diff --git a/examples/clist/clist.c b/examples/clist/clist.c
index 7068dcae58..41a5dcaa53 100644
--- a/examples/clist/clist.c
+++ b/examples/clist/clist.c
@@ -1,26 +1,94 @@
/* example-start clist clist.c */
-#include <gtk/gtk.h>
-#include <glib.h>
+#include <gtk/gtk.h>
-/* These are just the prototypes of the various callbacks */
-void button_add_clicked( GtkWidget *button, gpointer data);
-void button_clear_clicked( GtkWidget *button, gpointer data);
-void button_hide_show_clicked( GtkWidget *button, gpointer data);
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data);
+/* User clicked the "Add List" button. */
+void button_add_clicked( gpointer data )
+{
+ int indx;
+
+ /* Something silly to add to the list. 4 rows of 2 columns each */
+ gchar *drink[4][2] = { { "Milk", "3 Oz" },
+ { "Water", "6 l" },
+ { "Carrots", "2" },
+ { "Snakes", "55" } };
+
+ /* Here we do the actual adding of the text. It's done once for
+ * each row.
+ */
+ for ( indx=0 ; indx < 4 ; indx++ )
+ gtk_clist_append( (GtkCList *) data, drink[indx]);
+
+ return;
+}
+
+/* User clicked the "Clear List" button. */
+void button_clear_clicked( gpointer data )
+{
+ /* Clear the list using gtk_clist_clear. This is much faster than
+ * calling gtk_clist_remove once for each row.
+ */
+ gtk_clist_clear( (GtkCList *) data);
+
+ return;
+}
+
+/* The user clicked the "Hide/Show titles" button. */
+void button_hide_show_clicked( gpointer data )
+{
+ /* Just a flag to remember the status. 0 = currently visible */
+ static short int flag = 0;
+
+ if (flag == 0)
+ {
+ /* Hide the titles and set the flag to 1 */
+ gtk_clist_column_titles_hide((GtkCList *) data);
+ flag++;
+ }
+ else
+ {
+ /* Show the titles and reset flag to 0 */
+ gtk_clist_column_titles_show((GtkCList *) data);
+ flag--;
+ }
+
+ return;
+}
+
+/* If we come here, then the user has selected a row in the list. */
+void selection_made( GtkWidget *clist,
+ gint row,
+ gint column,
+ GdkEventButton *event,
+ gpointer data )
+{
+ gchar *text;
-gint main (int argc, gchar *argv[])
+ /* Get the text that is stored in the selected row and column
+ * which was clicked in. We will receive it as a pointer in the
+ * argument text.
+ */
+ gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
+
+ /* Just prints some information about the selected row */
+ g_print("You selected row %d. More specifically you clicked in "
+ "column %d, and the text in this cell is %s\n\n",
+ row, column, text);
+
+ return;
+}
+
+int main( int argc,
+ gchar *argv[] )
{
- GtkWidget *window;
- GtkWidget *vbox, *hbox;
- GtkWidget *clist;
- GtkWidget *button_add, *button_clear, *button_hide_show;
- gchar *titles[2] = {"Ingredients","Amount"};
+ GtkWidget *window;
+ GtkWidget *vbox, *hbox;
+ GtkWidget *clist;
+ GtkWidget *button_add, *button_clear, *button_hide_show;
+ gchar *titles[2] = { "Ingredients", "Amount" };
gtk_init(&argc, &argv);
-
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize(GTK_WIDGET(window), 300, 150);
@@ -95,75 +163,4 @@ gint main (int argc, gchar *argv[])
return(0);
}
-
-/* User clicked the "Add List" button. */
-void button_add_clicked( GtkWidget *button, gpointer data)
-{
- int indx;
-
- /* Something silly to add to the list. 4 rows of 2 columns each */
- gchar *drink[4][2] = {{"Milk", "3 Oz"},
- {"Water", "6 l"},
- {"Carrots", "2"},
- {"Snakes", "55"}};
-
- /* Here we do the actual adding of the text. It's done once for
- * each row.
- */
- for( indx=0; indx < 4; indx++)
- gtk_clist_append( (GtkCList*) data, drink[indx]);
-
- return;
-}
-
-/* User clicked the "Clear List" button. */
-void button_clear_clicked( GtkWidget *button, gpointer data)
-{
- /* Clear the list using gtk_clist_clear. This is much faster than
- * calling gtk_clist_remove once for each row.
- */
- gtk_clist_clear((GtkCList*) data);
-
- return;
-}
-
-/* The user clicked the "Hide/Show titles" button. */
-void button_hide_show_clicked( GtkWidget *button, gpointer data)
-{
- /* Just a flag to remember the status. 0 = currently visible */
- static short int flag = 0;
-
- if (flag == 0)
- {
- /* Hide the titles and set the flag to 1 */
- gtk_clist_column_titles_hide((GtkCList*) data);
- flag++;
- }
- else
- {
- /* Show the titles and reset flag to 0 */
- gtk_clist_column_titles_show((GtkCList*) data);
- flag--;
- }
-
- return;
-}
-
-/* If we come here, then the user has selected a row in the list. */
-void selection_made( GtkWidget *clist, gint row, gint column,
- GdkEventButton *event, gpointer data)
-{
- gchar *text;
-
- /* Get the text that is stored in the selected row and column
- * which was clicked in. We will receive it as a pointer in the
- * argument text.
- */
- gtk_clist_get_text(GTK_CLIST(clist), row, column, &text);
-
- /* Just prints some information about the selected row */
- g_print("You selected row %d. More specifically you clicked in column %d, and the text in this cell is %s\n\n", row, column, text);
-
- return;
-}
/* example-end */
diff --git a/examples/progressbar/progressbar.c b/examples/progressbar/progressbar.c
index efb20cc597..073e74fa7b 100644
--- a/examples/progressbar/progressbar.c
+++ b/examples/progressbar/progressbar.c
@@ -15,11 +15,12 @@ gint progress_timeout( gpointer data )
gfloat new_val;
GtkAdjustment *adj;
- adj = GTK_PROGRESS (data)->adjustment;
-
/* Calculate the value of the progress bar using the
* value range set in the adjustment object */
- new_val = adj->value + 1;
+
+ new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 1;
+
+ adj = GTK_PROGRESS (data)->adjustment;
if (new_val > adj->upper)
new_val = adj->lower;