summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGMT 1998 Tony Gale <gale@gtk.org>1998-12-10 17:31:04 +0000
committerTony Gale <gale@src.gnome.org>1998-12-10 17:31:04 +0000
commit3821880398cc553882b9f1fc5905046518b9cd4e (patch)
tree88867e7f0ad2d19deeb5f850e920827b4232a6ef /examples
parent600ef4e7d1b45dd4cd88606b6da402ffe2a885bf (diff)
downloadgdk-pixbuf-3821880398cc553882b9f1fc5905046518b9cd4e.tar.gz
- re-write the GtkProgressBar section to the 1.1 API. - add an Appendix
Thu Dec 10 17:58:49 GMT 1998 Tony Gale <gale@gtk.org> * docs/gtk_tut.sgml: - re-write the GtkProgressBar section to the 1.1 API. - add an Appendix listing all the signals (apologies to TimJ for taking so long in using his hard work in automating the extraction - thanx Tim). * examples/*: bring them all upto the tutorial versions
Diffstat (limited to 'examples')
-rw-r--r--examples/aspectframe/aspectframe.c5
-rw-r--r--examples/base/base.c4
-rw-r--r--examples/clist/clist.c2
-rw-r--r--examples/entry/entry.c5
-rw-r--r--examples/eventbox/eventbox.c5
-rw-r--r--examples/filesel/filesel.c5
-rw-r--r--examples/gtkdial/gtkdial.c7
-rw-r--r--examples/gtkdial/gtkdial.h3
-rw-r--r--examples/list/list.c17
-rw-r--r--examples/menu/menu.c9
-rw-r--r--examples/notebook/notebook.c7
-rw-r--r--examples/packer/Makefile2
-rw-r--r--examples/paned/paned.c3
-rw-r--r--examples/pixmap/pixmap.c8
-rw-r--r--examples/progressbar/progressbar.c271
-rw-r--r--examples/rulers/rulers.c31
-rw-r--r--examples/scribble-simple/scribble-simple.c3
-rw-r--r--examples/scrolledwin/scrolledwin.c23
-rw-r--r--examples/selection/gettargets.c7
-rw-r--r--examples/selection/setselection.c5
-rw-r--r--examples/statusbar/statusbar.c5
-rw-r--r--examples/tictactoe/tictactoe.c4
-rw-r--r--examples/tictactoe/tictactoe.h4
-rw-r--r--examples/tictactoe/ttt_test.c4
-rw-r--r--examples/tree/tree.c2
-rw-r--r--examples/wheelbarrow/wheelbarrow.c20
26 files changed, 294 insertions, 167 deletions
diff --git a/examples/aspectframe/aspectframe.c b/examples/aspectframe/aspectframe.c
index 0376bf92b..f82e0276a 100644
--- a/examples/aspectframe/aspectframe.c
+++ b/examples/aspectframe/aspectframe.c
@@ -1,4 +1,4 @@
-/* aspectframe.c */
+/* example-start aspectframe aspectframe.c */
#include <gtk/gtk.h>
@@ -13,7 +13,7 @@ main (int argc, char *argv[])
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Aspect Frame");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
- GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+ GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
/* Create an aspect_frame and add it to our toplevel window */
@@ -41,3 +41,4 @@ main (int argc, char *argv[])
gtk_main ();
return 0;
}
+/* example-end */
diff --git a/examples/base/base.c b/examples/base/base.c
index aefd0c062..d0e9d8daa 100644
--- a/examples/base/base.c
+++ b/examples/base/base.c
@@ -10,10 +10,10 @@ int main( int argc,
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_widget_show (window);
+ gtk_widget_show (window);
gtk_main ();
- return 0;
+ return(0);
}
/* example-end */
diff --git a/examples/clist/clist.c b/examples/clist/clist.c
index 2d766a13d..430deb268 100644
--- a/examples/clist/clist.c
+++ b/examples/clist/clist.c
@@ -39,7 +39,7 @@ gint main (int argc, gchar *argv[])
clist = gtk_clist_new_with_titles( 2, titles);
/* When a selection is made, we want to know about it. The callback
- * used is selection_made, and it's code can be found further down */
+ * used is selection_made, and its code can be found further down */
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
GTK_SIGNAL_FUNC(selection_made),
NULL);
diff --git a/examples/entry/entry.c b/examples/entry/entry.c
index d34153889..7d41048e4 100644
--- a/examples/entry/entry.c
+++ b/examples/entry/entry.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* entry.c */
+/* example-start entry entry.c */
#include <gtk/gtk.h>
@@ -90,3 +88,4 @@ int main (int argc, char *argv[])
gtk_main();
return(0);
}
+/* example-end */
diff --git a/examples/eventbox/eventbox.c b/examples/eventbox/eventbox.c
index c3ec105ee..b902cc1f4 100644
--- a/examples/eventbox/eventbox.c
+++ b/examples/eventbox/eventbox.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* eventbox.c */
+/* example-start eventbox eventbox.c */
#include <gtk/gtk.h>
@@ -53,3 +51,4 @@ main (int argc, char *argv[])
return 0;
}
+/* example-end */
diff --git a/examples/filesel/filesel.c b/examples/filesel/filesel.c
index c5afd8899..63b5172cb 100644
--- a/examples/filesel/filesel.c
+++ b/examples/filesel/filesel.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* filesel.c */
+/* example-start filesel filesel.c */
#include <gtk/gtk.h>
@@ -44,3 +42,4 @@ int main (int argc, char *argv[])
gtk_main ();
return 0;
}
+/* example-end */
diff --git a/examples/gtkdial/gtkdial.c b/examples/gtkdial/gtkdial.c
index 8bea29456..3c662f7e2 100644
--- a/examples/gtkdial/gtkdial.c
+++ b/examples/gtkdial/gtkdial.c
@@ -1,3 +1,5 @@
+/* example-start gtkdial gtkdial.c */
+
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
@@ -26,7 +28,7 @@
#define SCROLL_DELAY_LENGTH 300
#define DIAL_DEFAULT_SIZE 100
-/* Forward declararations */
+/* Forward declarations */
static void gtk_dial_class_init (GtkDialClass *klass);
static void gtk_dial_init (GtkDial *dial);
@@ -587,5 +589,4 @@ gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment,
dial->old_value = adjustment->value;
}
}
-
-
+/* example-end */
diff --git a/examples/gtkdial/gtkdial.h b/examples/gtkdial/gtkdial.h
index 38904a98e..c6a54027c 100644
--- a/examples/gtkdial/gtkdial.h
+++ b/examples/gtkdial/gtkdial.h
@@ -1,3 +1,5 @@
+/* example-start gtkdial gtkdial.h */
+
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
@@ -87,3 +89,4 @@ void gtk_dial_set_adjustment (GtkDial *dial,
#endif /* __GTK_DIAL_H__ */
+/* example-end */
diff --git a/examples/list/list.c b/examples/list/list.c
index 6bed62360..abf81f2c0 100644
--- a/examples/list/list.c
+++ b/examples/list/list.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* list.c */
+/* example-start list list.c */
/* include the gtk+ header files
* include stdio.h, we need that for the printf() function
@@ -65,7 +63,7 @@ gint main (int argc, gchar *argv[])
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_widget_show(vbox);
- /* this is the scolled window to put the GtkList widget inside */
+ /* this is the scrolled window to put the GtkList widget inside */
scrolled_window=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_usize(scrolled_window, 250, 150);
gtk_container_add(GTK_CONTAINER(vbox), scrolled_window);
@@ -94,7 +92,7 @@ gint main (int argc, gchar *argv[])
gtk_widget_show(frame);
/* connect the sigh_button_event() signal handler to the GtkList
- * wich will handle the "arresting" of list items
+ * which will handle the "arresting" of list items
*/
gtk_signal_connect(GTK_OBJECT(gtklist),
"button_release_event",
@@ -107,8 +105,8 @@ gint main (int argc, gchar *argv[])
gtk_container_add(GTK_CONTAINER(vbox), separator);
gtk_widget_show(separator);
- /* finaly create a button and connect itīs "clicked" signal
- * to the destroyment of the window
+ /* finally create a button and connect itīs "clicked" signal
+ * to the destruction of the window
*/
button=gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(vbox), button);
@@ -165,7 +163,7 @@ gint main (int argc, gchar *argv[])
}
gtk_list_append_items(GTK_LIST(gtklist), dlist);
- /* finaly we want to see the window, donīt we? ;)
+ /* finally we want to see the window, don't we? ;)
*/
gtk_widget_show(window);
@@ -204,7 +202,7 @@ sigh_button_event (GtkWidget *gtklist,
else
new_prisoner=NULL;
- /* look for already prisoned list items, we
+ /* look for already imprisoned list items, we
* will put them back into the list
* remember to free the doubly linked list that
* gtk_container_children() returns
@@ -282,3 +280,4 @@ sigh_print_selection (GtkWidget *gtklist,
}
g_print("\n");
}
+/* example-end */
diff --git a/examples/menu/menu.c b/examples/menu/menu.c
index 4053fab7b..a53019b02 100644
--- a/examples/menu/menu.c
+++ b/examples/menu/menu.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* menu.c */
+/* example-start menu menu.c */
#include <gtk/gtk.h>
@@ -27,7 +25,7 @@ int main (int argc, char *argv[])
gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
gtk_window_set_title(GTK_WINDOW (window), "GTK Menu Test");
gtk_signal_connect(GTK_OBJECT (window), "delete_event",
- (GtkSignalFunc) gtk_exit, NULL);
+ (GtkSignalFunc) gtk_main_quit, NULL);
/* Init the menu-widget, and remember -- never
* gtk_show_widget() the menu widget!!
@@ -101,8 +99,6 @@ int main (int argc, char *argv[])
return 0;
}
-
-
/* Respond to a button-press by posting a menu passed in as widget.
*
* Note that the "widget" argument is the menu being posted, NOT
@@ -132,3 +128,4 @@ static void menuitem_response (gchar *string)
{
printf("%s\n", string);
}
+/* example-end */
diff --git a/examples/notebook/notebook.c b/examples/notebook/notebook.c
index 781990dac..62508eab0 100644
--- a/examples/notebook/notebook.c
+++ b/examples/notebook/notebook.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* notebook.c */
+/* example-start notebook notebook.c */
#include <gtk/gtk.h>
@@ -36,7 +34,7 @@ void remove_book (GtkButton *button, GtkNotebook *notebook)
gtk_widget_draw(GTK_WIDGET(notebook), NULL);
}
-void delete (GtkWidget *widget, GdkEvent *event, gpointer data)
+void delete (GtkWidget *widget, GtkWidget *event, gpointer data)
{
gtk_main_quit ();
}
@@ -172,3 +170,4 @@ int main (int argc, char *argv[])
return 0;
}
+/* example-end */
diff --git a/examples/packer/Makefile b/examples/packer/Makefile
index eea54f3c0..f2cb96052 100644
--- a/examples/packer/Makefile
+++ b/examples/packer/Makefile
@@ -1,7 +1,7 @@
CC = gcc
-packer: packer.c
+packer: pack.c
$(CC) `gtk-config --cflags` pack.c -o packer `gtk-config --libs`
clean:
diff --git a/examples/paned/paned.c b/examples/paned/paned.c
index 46b7c6e12..86c31081a 100644
--- a/examples/paned/paned.c
+++ b/examples/paned/paned.c
@@ -1,4 +1,4 @@
-/* paned.c */
+/* example-start paned paned.c */
#include <gtk/gtk.h>
@@ -134,3 +134,4 @@ main (int argc, char *argv[])
gtk_main ();
return 0;
}
+/* example-end */
diff --git a/examples/pixmap/pixmap.c b/examples/pixmap/pixmap.c
index 48f1d4410..6e0607a2a 100644
--- a/examples/pixmap/pixmap.c
+++ b/examples/pixmap/pixmap.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* pixmap.c */
+/* example-start pixmap pixmap.c */
#include <gtk/gtk.h>
@@ -31,8 +29,7 @@ static const char * xpm_data[] = {
/* when invoked (via signal delete_event), terminates the application.
*/
-void close_application( GtkWidget *widget, GdkEvent *event, gpointer data )
-{
+void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
gtk_main_quit();
}
@@ -84,3 +81,4 @@ int main( int argc, char *argv[] )
return 0;
}
+/* example-end */
diff --git a/examples/progressbar/progressbar.c b/examples/progressbar/progressbar.c
index 193db0b48..efb20cc59 100644
--- a/examples/progressbar/progressbar.c
+++ b/examples/progressbar/progressbar.c
@@ -1,93 +1,220 @@
-/* This file extracted from the GTK tutorial. */
-
-/* progressbar.c */
+/* example-start progressbar progressbar.c */
#include <gtk/gtk.h>
-static int ptimer = 0;
-int pstat = TRUE;
+typedef struct _ProgressData {
+ GtkWidget *window;
+ GtkWidget *pbar;
+ int timer;
+} ProgressData;
-/* This function increments and updates the progress bar, it also resets
- the progress bar if pstat is FALSE */
-gint progress (gpointer data)
+/* Update the value of the progress bar so that we get
+ * some movement */
+gint progress_timeout( gpointer data )
{
- gfloat pvalue;
-
- /* get the current value of the progress bar */
- pvalue = GTK_PROGRESS_BAR (data)->percentage;
-
- if ((pvalue >= 1.0) || (pstat == FALSE)) {
- pvalue = 0.0;
- pstat = TRUE;
- }
- pvalue += 0.01;
-
- gtk_progress_bar_update (GTK_PROGRESS_BAR (data), pvalue);
-
- return TRUE;
+ 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;
+ if (new_val > adj->upper)
+ new_val = adj->lower;
+
+ /* Set the new value */
+ gtk_progress_set_value (GTK_PROGRESS (data), new_val);
+
+ /* As this is a timeout function, return TRUE so that it
+ * continues to get called */
+ return(TRUE);
+}
+
+/* Callback that toggles the text display within the progress
+ * bar trough */
+void toggle_show_text( GtkWidget *widget,
+ ProgressData *pdata )
+{
+ gtk_progress_set_show_text (GTK_PROGRESS (pdata->pbar),
+ GTK_TOGGLE_BUTTON (widget)->active);
}
-/* This function signals a reset of the progress bar */
-void progress_r (void)
-{
- pstat = FALSE;
+/* Callback that toggles the activity mode of the progress
+ * bar */
+void toggle_activity_mode( GtkWidget *widget,
+ ProgressData *pdata )
+{
+ gtk_progress_set_activity_mode (GTK_PROGRESS (pdata->pbar),
+ GTK_TOGGLE_BUTTON (widget)->active);
}
-void destroy (GtkWidget *widget, GdkEvent *event, gpointer data)
+/* Callback that toggles the continuous mode of the progress
+ * bar */
+void set_continuous_mode( GtkWidget *widget,
+ ProgressData *pdata )
{
- gtk_main_quit ();
+ gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar),
+ GTK_PROGRESS_CONTINUOUS);
}
-int main (int argc, char *argv[])
+/* Callback that toggles the discrete mode of the progress
+ * bar */
+void set_discrete_mode( GtkWidget *widget,
+ ProgressData *pdata )
{
- GtkWidget *window;
- GtkWidget *button;
- GtkWidget *label;
+ gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar),
+ GTK_PROGRESS_DISCRETE);
+}
+
+/* Clean up allocated memory and remove the timer */
+void destroy_progress( GtkWidget *widget,
+ ProgressData *pdata)
+{
+ gtk_timeout_remove (pdata->timer);
+ pdata->timer = 0;
+ pdata->window = NULL;
+ g_free(pdata);
+ gtk_main_quit();
+}
+
+int main( int argc,
+ char *argv[])
+{
+ ProgressData *pdata;
+ GtkWidget *align;
+ GtkWidget *separator;
GtkWidget *table;
- GtkWidget *pbar;
-
+ GtkAdjustment *adj;
+ GtkWidget *button;
+ GtkWidget *check;
+ GtkWidget *vbox;
+
gtk_init (&argc, &argv);
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- gtk_signal_connect (GTK_OBJECT (window), "delete_event",
- GTK_SIGNAL_FUNC (destroy), NULL);
-
- gtk_container_border_width (GTK_CONTAINER (window), 10);
-
- table = gtk_table_new(3,2,TRUE);
- gtk_container_add (GTK_CONTAINER (window), table);
-
- label = gtk_label_new ("Progress Bar Example");
- gtk_table_attach_defaults(GTK_TABLE(table), label, 0,2,0,1);
- gtk_widget_show(label);
-
- /* Create a new progress bar, pack it into the table, and show it */
- pbar = gtk_progress_bar_new ();
- gtk_table_attach_defaults(GTK_TABLE(table), pbar, 0,2,1,2);
- gtk_widget_show (pbar);
-
- /* Set the timeout to handle automatic updating of the progress bar */
- ptimer = gtk_timeout_add (100, progress, pbar);
-
- /* This button signals the progress bar to be reset */
- button = gtk_button_new_with_label ("Reset");
+
+ /* Allocate memory for the data that is passwd to the callbacks */
+ pdata = g_malloc( sizeof(ProgressData) );
+
+ pdata->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_policy (GTK_WINDOW (pdata->window), FALSE, FALSE, TRUE);
+
+ gtk_signal_connect (GTK_OBJECT (pdata->window), "destroy",
+ GTK_SIGNAL_FUNC (destroy_progress),
+ pdata);
+ gtk_window_set_title (GTK_WINDOW (pdata->window), "GtkProgressBar");
+ gtk_container_set_border_width (GTK_CONTAINER (pdata->window), 0);
+
+ vbox = gtk_vbox_new (FALSE, 5);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
+ gtk_container_add (GTK_CONTAINER (pdata->window), vbox);
+ gtk_widget_show(vbox);
+
+ /* Create a centering alignment object */
+ align = gtk_alignment_new (0.5, 0.5, 0, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
+ gtk_widget_show(align);
+
+ /* Create a GtkAdjusment object to hold the range of the
+ * progress bar */
+ adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0);
+
+ /* Create the GtkProgressBar using the adjustment */
+ pdata->pbar = gtk_progress_bar_new_with_adjustment (adj);
+
+ /* Set the format of the string that can be displayed in the
+ * trough of the progress bar:
+ * %p - percentage
+ * %v - value
+ * %l - lower range value
+ * %u - upper range value */
+ gtk_progress_set_format_string (GTK_PROGRESS (pdata->pbar),
+ "%v from [%l-%u] (=%p%%)");
+ gtk_container_add (GTK_CONTAINER (align), pdata->pbar);
+ gtk_widget_show(pdata->pbar);
+
+ /* Add a timer callback to update the value of the progress bar */
+ pdata->timer = gtk_timeout_add (100, progress_timeout, pdata->pbar);
+
+ separator = gtk_hseparator_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
+ gtk_widget_show(separator);
+
+ /* rows, columns, homogeneous */
+ table = gtk_table_new (2, 3, FALSE);
+ gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
+ gtk_widget_show(table);
+
+ /* Add a check button to select displaying of the trough text */
+ check = gtk_check_button_new_with_label ("Show text");
+ gtk_table_attach (GTK_TABLE (table), check, 0, 1, 0, 1,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
+ 5, 5);
+ gtk_signal_connect (GTK_OBJECT (check), "clicked",
+ GTK_SIGNAL_FUNC (toggle_show_text),
+ pdata);
+ gtk_widget_show(check);
+
+ /* Add a check button to toggle activity mode */
+ check = gtk_check_button_new_with_label ("Activity mode");
+ gtk_table_attach (GTK_TABLE (table), check, 0, 1, 1, 2,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
+ 5, 5);
+ gtk_signal_connect (GTK_OBJECT (check), "clicked",
+ GTK_SIGNAL_FUNC (toggle_activity_mode),
+ pdata);
+ gtk_widget_show(check);
+
+ separator = gtk_vseparator_new ();
+ gtk_table_attach (GTK_TABLE (table), separator, 1, 2, 0, 2,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
+ 5, 5);
+ gtk_widget_show(separator);
+
+ /* Add a radio button to select continuous display mode */
+ button = gtk_radio_button_new_with_label (NULL, "Continuous");
+ gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
+ 5, 5);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
- GTK_SIGNAL_FUNC (progress_r), NULL);
- gtk_table_attach_defaults(GTK_TABLE(table), button, 0,1,2,3);
- gtk_widget_show(button);
-
- button = gtk_button_new_with_label ("Cancel");
+ GTK_SIGNAL_FUNC (set_continuous_mode),
+ pdata);
+ gtk_widget_show (button);
+
+ /* Add a radio button to select discrete display mode */
+ button = gtk_radio_button_new_with_label(
+ gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
+ "Discrete");
+ gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
+ GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
+ 5, 5);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
- GTK_SIGNAL_FUNC (destroy), NULL);
-
- gtk_table_attach_defaults(GTK_TABLE(table), button, 1,2,2,3);
+ GTK_SIGNAL_FUNC (set_discrete_mode),
+ pdata);
gtk_widget_show (button);
-
- gtk_widget_show(table);
- gtk_widget_show(window);
-
+
+ separator = gtk_hseparator_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
+ gtk_widget_show(separator);
+
+ /* Add a button to exit the program */
+ button = gtk_button_new_with_label ("close");
+ gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+ (GtkSignalFunc) gtk_widget_destroy,
+ GTK_OBJECT (pdata->window));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+ /* This makes it so the button is the default. */
+ GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+
+ /* This grabs this button to be the default button. Simply hitting
+ * the "Enter" key will cause this button to activate. */
+ gtk_widget_grab_default (button);
+ gtk_widget_show(button);
+
+ gtk_widget_show (pdata->window);
+
gtk_main ();
- return 0;
+ return(0);
}
+/* example-end */
diff --git a/examples/rulers/rulers.c b/examples/rulers/rulers.c
index e9aa4a7b5..014d6be22 100644
--- a/examples/rulers/rulers.c
+++ b/examples/rulers/rulers.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* rulers.c */
+/* example-start rulers rulers.c */
#include <gtk/gtk.h>
@@ -9,20 +7,16 @@
#define XSIZE 600
#define YSIZE 400
-/* this routine gets control when the close button is clicked
- */
-void close_application( GtkWidget *widget, GdkEvent *event, gpointer data )
-{
+/* This routine gets control when the close button is clicked */
+void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
gtk_main_quit();
}
-
-/* the main routine
- */
+/* The main routine */
int main( int argc, char *argv[] ) {
GtkWidget *window, *table, *area, *hrule, *vrule;
- /* initialize gtk and create the main window */
+ /* Initialize GTK and create the main window */
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
@@ -30,7 +24,7 @@ int main( int argc, char *argv[] ) {
GTK_SIGNAL_FUNC( close_application ), NULL);
gtk_container_border_width (GTK_CONTAINER (window), 10);
- /* create a table for placing the ruler and the drawing area */
+ /* Create a table for placing the ruler and the drawing area */
table = gtk_table_new( 3, 2, FALSE );
gtk_container_add( GTK_CONTAINER(window), table );
@@ -40,8 +34,8 @@ int main( int argc, char *argv[] ) {
GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 );
gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK );
- /* The horizontal ruler goes on top. As the mouse moves across the drawing area,
- a motion_notify_event is passed to the appropriate event handler for the ruler. */
+ /* The horizontal ruler goes on top. As the mouse moves across the drawing area,
+ * a motion_notify_event is passed to the appropriate event handler for the ruler. */
hrule = gtk_hruler_new();
gtk_ruler_set_metric( GTK_RULER(hrule), GTK_PIXELS );
gtk_ruler_set_range( GTK_RULER(hrule), 7, 13, 0, 20 );
@@ -52,8 +46,8 @@ int main( int argc, char *argv[] ) {
gtk_table_attach( GTK_TABLE(table), hrule, 1, 2, 0, 1,
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0 );
- /* The vertical ruler goes on the left. As the mouse moves across the drawing area,
- a motion_notify_event is passed to the appropriate event handler for the ruler. */
+ /* The vertical ruler goes on the left. As the mouse moves across the drawing area,
+ * a motion_notify_event is passed to the appropriate event handler for the ruler. */
vrule = gtk_vruler_new();
gtk_ruler_set_metric( GTK_RULER(vrule), GTK_PIXELS );
gtk_ruler_set_range( GTK_RULER(vrule), 0, YSIZE, 10, YSIZE );
@@ -64,7 +58,7 @@ int main( int argc, char *argv[] ) {
gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2,
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 );
- /* now show everything */
+ /* Now show everything */
gtk_widget_show( area );
gtk_widget_show( hrule );
gtk_widget_show( vrule );
@@ -72,5 +66,6 @@ int main( int argc, char *argv[] ) {
gtk_widget_show( window );
gtk_main();
- return 0;
+ return(0);
}
+/* example-end */
diff --git a/examples/scribble-simple/scribble-simple.c b/examples/scribble-simple/scribble-simple.c
index df5690408..365219b38 100644
--- a/examples/scribble-simple/scribble-simple.c
+++ b/examples/scribble-simple/scribble-simple.c
@@ -1,3 +1,5 @@
+/* example-start scribble-simple scribble-simple.c */
+
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
@@ -175,3 +177,4 @@ main (int argc, char *argv[])
return 0;
}
+/* example-end */
diff --git a/examples/scrolledwin/scrolledwin.c b/examples/scrolledwin/scrolledwin.c
index af3666a1a..f222d7510 100644
--- a/examples/scrolledwin/scrolledwin.c
+++ b/examples/scrolledwin/scrolledwin.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* scrolledwin.c */
+/* example-start scrolledwin scrolledwin.c */
#include <gtk/gtk.h>
@@ -22,7 +20,7 @@ int main (int argc, char *argv[])
/* Create a new dialog window for the scrolled window to be
* packed into. A dialog is just like a normal window except it has a
- * vbox and a horizontal seperator packed into it. It's just a shortcut
+ * vbox and a horizontal separator packed into it. It's just a shortcut
* for creating dialogs */
window = gtk_dialog_new ();
gtk_signal_connect (GTK_OBJECT (window), "destroy",
@@ -38,7 +36,7 @@ int main (int argc, char *argv[])
/* the policy is one of GTK_POLICY AUTOMATIC, or GTK_POLICY_ALWAYS.
* GTK_POLICY_AUTOMATIC will automatically decide whether you need
- * scrollbars, wheras GTK_POLICY_ALWAYS will always leave the scrollbars
+ * scrollbars, whereas GTK_POLICY_ALWAYS will always leave the scrollbars
* there. The first one is the horizontal scrollbar, the second,
* the vertical. */
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
@@ -62,13 +60,13 @@ int main (int argc, char *argv[])
/* this simply creates a grid of toggle buttons on the table
* to demonstrate the scrolled window. */
for (i = 0; i < 10; i++)
- for (j = 0; j < 10; j++) {
- sprintf (buffer, "button (%d,%d)\n", i, j);
- button = gtk_toggle_button_new_with_label (buffer);
- gtk_table_attach_defaults (GTK_TABLE (table), button,
- i, i+1, j, j+1);
- gtk_widget_show (button);
- }
+ for (j = 0; j < 10; j++) {
+ sprintf (buffer, "button (%d,%d)\n", i, j);
+ button = gtk_toggle_button_new_with_label (buffer);
+ gtk_table_attach_defaults (GTK_TABLE (table), button,
+ i, i+1, j, j+1);
+ gtk_widget_show (button);
+ }
/* Add a "close" button to the bottom of the dialog */
button = gtk_button_new_with_label ("close");
@@ -92,3 +90,4 @@ int main (int argc, char *argv[])
return(0);
}
+/* example-end */
diff --git a/examples/selection/gettargets.c b/examples/selection/gettargets.c
index 47f7adbb7..433cab21e 100644
--- a/examples/selection/gettargets.c
+++ b/examples/selection/gettargets.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* gettargets.c */
+/* example-start selection gettargets.c */
#include <gtk/gtk.h>
@@ -14,7 +12,7 @@ get_targets (GtkWidget *widget, gpointer data)
{
static GdkAtom targets_atom = GDK_NONE;
- /* Get the atom corresonding to the string "TARGETS" */
+ /* Get the atom corresponding to the string "TARGETS" */
if (targets_atom == GDK_NONE)
targets_atom = gdk_atom_intern ("TARGETS", FALSE);
@@ -96,3 +94,4 @@ main (int argc, char *argv[])
return 0;
}
+/* example-end */
diff --git a/examples/selection/setselection.c b/examples/selection/setselection.c
index c3e784b8a..2f8532b10 100644
--- a/examples/selection/setselection.c
+++ b/examples/selection/setselection.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* setselection.c */
+/* example-start selection setselection.c */
#include <gtk/gtk.h>
#include <time.h>
@@ -104,3 +102,4 @@ main (int argc, char *argv[])
return 0;
}
+/* example-end */
diff --git a/examples/statusbar/statusbar.c b/examples/statusbar/statusbar.c
index 111592eb1..7956ffdec 100644
--- a/examples/statusbar/statusbar.c
+++ b/examples/statusbar/statusbar.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* statusbar.c (Tony Gale) */
+/* example-start statusbar statusbar.c */
#include <gtk/gtk.h>
#include <glib.h>
@@ -72,3 +70,4 @@ int main (int argc, char *argv[])
return 0;
}
+/* example-end */
diff --git a/examples/tictactoe/tictactoe.c b/examples/tictactoe/tictactoe.c
index e1ad29fac..93b1633ad 100644
--- a/examples/tictactoe/tictactoe.c
+++ b/examples/tictactoe/tictactoe.c
@@ -1,3 +1,5 @@
+/* example-start tictactoe tictactoe.c */
+
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
@@ -154,3 +156,5 @@ tictactoe_toggle (GtkWidget *widget, Tictactoe *ttt)
}
}
}
+
+/* example-end */
diff --git a/examples/tictactoe/tictactoe.h b/examples/tictactoe/tictactoe.h
index 2d5693b68..6dfa203ad 100644
--- a/examples/tictactoe/tictactoe.h
+++ b/examples/tictactoe/tictactoe.h
@@ -1,3 +1,5 @@
+/* example-start tictactoe tictactoe.h */
+
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
@@ -59,3 +61,5 @@ void tictactoe_clear (Tictactoe *ttt);
#endif /* __cplusplus */
#endif /* __TICTACTOE_H__ */
+
+/* example-end */
diff --git a/examples/tictactoe/ttt_test.c b/examples/tictactoe/ttt_test.c
index 2dca32923..a3c413778 100644
--- a/examples/tictactoe/ttt_test.c
+++ b/examples/tictactoe/ttt_test.c
@@ -1,3 +1,5 @@
+/* example-start tictactoe ttt_test.c */
+
#include <gtk/gtk.h>
#include "tictactoe.h"
@@ -39,3 +41,5 @@ main (int argc, char *argv[])
return 0;
}
+
+/* example-end */
diff --git a/examples/tree/tree.c b/examples/tree/tree.c
index 3b19f8db3..e4613ef7d 100644
--- a/examples/tree/tree.c
+++ b/examples/tree/tree.c
@@ -126,7 +126,7 @@ int main (int argc, char *argv[])
g_print ("-> item %s->%p, subtree %p\n", itemnames[i], item,
subtree);
- /* This is still necesary if you want these signals to be called
+ /* This is still necessary if you want these signals to be called
for the subtree's children. Note that selection_change will be
signalled for the root tree regardless. */
gtk_signal_connect (GTK_OBJECT(subtree), "select_child",
diff --git a/examples/wheelbarrow/wheelbarrow.c b/examples/wheelbarrow/wheelbarrow.c
index 22f956cc2..d129ca682 100644
--- a/examples/wheelbarrow/wheelbarrow.c
+++ b/examples/wheelbarrow/wheelbarrow.c
@@ -1,6 +1,4 @@
-/* This file extracted from the GTK tutorial. */
-
-/* wheelbarrow.c */
+/* example-start wheelbarrow wheelbarrow.c */
#include <gtk/gtk.h>
@@ -121,8 +119,7 @@ static char * WheelbarrowFull_xpm[] = {
" "};
-/* when invoked (via signal delete_event), terminates the application.
- */
+/* When invoked (via signal delete_event), terminates the application */
void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) {
gtk_main_quit();
}
@@ -136,16 +133,16 @@ int main (int argc, char *argv[])
GtkStyle *style;
GdkGC *gc;
- /* create the main window, and attach delete_event signal to terminate
- the application. Note that the main window will not have a titlebar
- since we're making it a popup. */
+ /* Create the main window, and attach delete_event signal to terminate
+ * the application. Note that the main window will not have a titlebar
+ * since we're making it a popup. */
gtk_init (&argc, &argv);
window = gtk_window_new( GTK_WINDOW_POPUP );
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (close_application), NULL);
- gtk_widget_realize (window);
+ gtk_widget_show (window);
- /* now for the pixmap and the pixmap widget */
+ /* Now for the pixmap and the pixmap widget */
style = gtk_widget_get_default_style();
gc = style->black_gc;
gdk_pixmap = gdk_pixmap_create_from_xpm_d( window->window, &mask,
@@ -169,5 +166,6 @@ int main (int argc, char *argv[])
gtk_widget_show( window );
gtk_main ();
- return 0;
+ return(0);
}
+/* example-end */