diff options
author | GMT 1999 Tony Gale <gale@gtk.org> | 1999-11-13 23:06:46 +0000 |
---|---|---|
committer | Tony Gale <gale@src.gnome.org> | 1999-11-13 23:06:46 +0000 |
commit | ee3d13766031e30653d82764aef92ae444015c5e (patch) | |
tree | c0d025531a52bee6a44d65babd111b6d3f04bed7 /examples | |
parent | e4df9fa95b83ce233c2129c3098e2727316e982b (diff) | |
download | gtk+-ee3d13766031e30653d82764aef92ae444015c5e.tar.gz |
threads example from Erik Mouw. New question on GtkLabel background
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
Diffstat (limited to 'examples')
38 files changed, 674 insertions, 270 deletions
diff --git a/examples/Makefile b/examples/Makefile index 1b04a5bc89..940dd15a48 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -27,6 +27,7 @@ SUBDIRS = arrow \ rangewidgets \ rulers \ scribble-simple \ + scribble-xinput \ scrolledwin \ selection \ spinbutton \ diff --git a/examples/aspectframe/aspectframe.c b/examples/aspectframe/aspectframe.c index 021673073d..c1201fbbe7 100644 --- a/examples/aspectframe/aspectframe.c +++ b/examples/aspectframe/aspectframe.c @@ -2,8 +2,8 @@ #include <gtk/gtk.h> -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *aspect_frame; diff --git a/examples/buttonbox/buttonbox.c b/examples/buttonbox/buttonbox.c index 46ee861a07..18346403ac 100644 --- a/examples/buttonbox/buttonbox.c +++ b/examples/buttonbox/buttonbox.c @@ -3,12 +3,12 @@ #include <gtk/gtk.h> /* Create a Button Box with the specified parameters */ -GtkWidget *create_bbox (gint horizontal, - char* title, - gint spacing, - gint child_w, - gint child_h, - gint layout) +GtkWidget *create_bbox( gint horizontal, + char *title, + gint spacing, + gint child_w, + gint child_h, + gint layout ) { GtkWidget *frame; GtkWidget *bbox; diff --git a/examples/buttons/buttons.c b/examples/buttons/buttons.c index 1dc2fd418d..82bc5069ea 100644 --- a/examples/buttons/buttons.c +++ b/examples/buttons/buttons.c @@ -75,7 +75,6 @@ int main( int argc, gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (gtk_exit), NULL); - /* Sets the border width of the window. */ gtk_container_set_border_width (GTK_CONTAINER (window), 10); gtk_widget_realize(window); diff --git a/examples/entry/entry.c b/examples/entry/entry.c index 510f5e2166..b53a9f9a32 100644 --- a/examples/entry/entry.c +++ b/examples/entry/entry.c @@ -2,28 +2,30 @@ #include <gtk/gtk.h> -void enter_callback(GtkWidget *widget, GtkWidget *entry) +void enter_callback( GtkWidget *widget, + GtkWidget *entry ) { gchar *entry_text; entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); printf("Entry contents: %s\n", entry_text); } -void entry_toggle_editable (GtkWidget *checkbutton, - GtkWidget *entry) +void entry_toggle_editable( GtkWidget *checkbutton, + GtkWidget *entry ) { gtk_entry_set_editable(GTK_ENTRY(entry), GTK_TOGGLE_BUTTON(checkbutton)->active); } -void entry_toggle_visibility (GtkWidget *checkbutton, - GtkWidget *entry) +void entry_toggle_visibility( GtkWidget *checkbutton, + GtkWidget *entry ) { gtk_entry_set_visibility(GTK_ENTRY(entry), GTK_TOGGLE_BUTTON(checkbutton)->active); } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; diff --git a/examples/eventbox/eventbox.c b/examples/eventbox/eventbox.c index f6b34bb3be..ac1e524897 100644 --- a/examples/eventbox/eventbox.c +++ b/examples/eventbox/eventbox.c @@ -2,8 +2,8 @@ #include <gtk/gtk.h> -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *event_box; diff --git a/examples/filesel/filesel.c b/examples/filesel/filesel.c index 63b5172cba..1e1fcaad40 100644 --- a/examples/filesel/filesel.c +++ b/examples/filesel/filesel.c @@ -3,17 +3,20 @@ #include <gtk/gtk.h> /* Get the selected filename and print it to the console */ -void file_ok_sel (GtkWidget *w, GtkFileSelection *fs) +void file_ok_sel( GtkWidget *w, + GtkFileSelection *fs ) { g_print ("%s\n", gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs))); } -void destroy (GtkWidget *widget, gpointer data) +void destroy( GtkWidget *widget, + gpointer data ) { gtk_main_quit (); } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *filew; @@ -29,7 +32,8 @@ int main (int argc, char *argv[]) "clicked", (GtkSignalFunc) file_ok_sel, filew ); /* Connect the cancel_button to destroy the widget */ - gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), + gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION + (filew)->cancel_button), "clicked", (GtkSignalFunc) gtk_widget_destroy, GTK_OBJECT (filew)); diff --git a/examples/fixed/fixed.c b/examples/fixed/fixed.c index 372b1add15..645f976cff 100644 --- a/examples/fixed/fixed.c +++ b/examples/fixed/fixed.c @@ -51,7 +51,7 @@ int main( int argc, button = gtk_button_new_with_label ("Press me"); /* When the button receives the "clicked" signal, it will call the - * function move_button() passing it the Fixed Containter as its + * function move_button() passing it the Fixed Container as its * argument. */ gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (move_button), fixed); diff --git a/examples/frame/frame.c b/examples/frame/frame.c index 6091f0131d..e2cb09a39a 100644 --- a/examples/frame/frame.c +++ b/examples/frame/frame.c @@ -30,7 +30,7 @@ int main( int argc, frame = gtk_frame_new(NULL); gtk_container_add(GTK_CONTAINER(window), frame); - /* Set the frames label */ + /* Set the frame's label */ gtk_frame_set_label( GTK_FRAME(frame), "GTK Frame Widget" ); /* Align the label at the right of the frame */ diff --git a/examples/gtkdial/gtkdial.c b/examples/gtkdial/gtkdial.c index 3c662f7e29..51e70d2d67 100644 --- a/examples/gtkdial/gtkdial.c +++ b/examples/gtkdial/gtkdial.c @@ -275,12 +275,14 @@ gtk_dial_expose (GtkWidget *widget, GdkEventExpose *event) { GtkDial *dial; - GdkPoint points[3]; + GdkPoint points[6]; gdouble s,c; - gdouble theta; + gdouble theta, last, increment; + GtkStyle *blankstyle; gint xc, yc; + gint upper, lower; gint tick_length; - gint i; + gint i, inc; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE); @@ -291,37 +293,93 @@ gtk_dial_expose (GtkWidget *widget, dial = GTK_DIAL (widget); - gdk_window_clear_area (widget->window, +/* gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width, widget->allocation.height); - +*/ xc = widget->allocation.width/2; yc = widget->allocation.height/2; + upper = dial->adjustment->upper; + lower = dial->adjustment->lower; + + /* Erase old pointer */ + + s = sin(dial->last_angle); + c = cos(dial->last_angle); + dial->last_angle = dial->angle; + + points[0].x = xc + s*dial->pointer_width/2; + points[0].y = yc + c*dial->pointer_width/2; + points[1].x = xc + c*dial->radius; + points[1].y = yc - s*dial->radius; + points[2].x = xc - s*dial->pointer_width/2; + points[2].y = yc - c*dial->pointer_width/2; + points[3].x = xc - c*dial->radius/10; + points[3].y = yc + s*dial->radius/10; + points[4].x = points[0].x; + points[4].y = points[0].y; + + blankstyle = gtk_style_new (); + blankstyle->bg_gc[GTK_STATE_NORMAL] = + widget->style->bg_gc[GTK_STATE_NORMAL]; + blankstyle->dark_gc[GTK_STATE_NORMAL] = + widget->style->bg_gc[GTK_STATE_NORMAL]; + blankstyle->light_gc[GTK_STATE_NORMAL] = + widget->style->bg_gc[GTK_STATE_NORMAL]; + blankstyle->black_gc = + widget->style->bg_gc[GTK_STATE_NORMAL]; + + gtk_draw_polygon (blankstyle, + widget->window, + GTK_STATE_NORMAL, + GTK_SHADOW_OUT, + points, 5, + FALSE); + + gtk_style_unref(blankstyle); + + /* Draw ticks */ - for (i=0; i<25; i++) + if ((upper - lower) == 0) + return; + + increment = (100*M_PI)/(dial->radius*dial->radius); + + inc = (upper - lower); + + while (inc < 100) inc *=10; + while (inc >= 1000) inc /=10; + last = -1; + + for (i=0; i<=inc; i++) { - theta = (i*M_PI/18. - M_PI/6.); + theta = ((gfloat)i*M_PI/(18*inc/24.) - M_PI/6.); + + if ((theta - last) < (increment)) + continue; + last = theta; + s = sin(theta); c = cos(theta); - tick_length = (i%6 == 0) ? dial->pointer_width : dial->pointer_width/2; - + tick_length = (i%(inc/10) == 0) ? dial->pointer_width : dial->pointer_width/2; + gdk_draw_line (widget->window, - widget->style->fg_gc[widget->state], - xc + c*(dial->radius - tick_length), - yc - s*(dial->radius - tick_length), - xc + c*dial->radius, - yc - s*dial->radius); + widget->style->fg_gc[widget->state], + xc + c*(dial->radius - tick_length), + yc - s*(dial->radius - tick_length), + xc + c*dial->radius, + yc - s*dial->radius); } /* Draw pointer */ s = sin(dial->angle); c = cos(dial->angle); - + dial->last_angle = dial->angle; points[0].x = xc + s*dial->pointer_width/2; points[0].y = yc + c*dial->pointer_width/2; @@ -329,14 +387,19 @@ gtk_dial_expose (GtkWidget *widget, points[1].y = yc - s*dial->radius; points[2].x = xc - s*dial->pointer_width/2; points[2].y = yc - c*dial->pointer_width/2; + points[3].x = xc - c*dial->radius/10; + points[3].y = yc + s*dial->radius/10; + points[4].x = points[0].x; + points[4].y = points[0].y; + gtk_draw_polygon (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - points, 3, + points, 5, TRUE); - + return FALSE; } diff --git a/examples/gtkdial/gtkdial.h b/examples/gtkdial/gtkdial.h index c6a54027c5..781943548a 100644 --- a/examples/gtkdial/gtkdial.h +++ b/examples/gtkdial/gtkdial.h @@ -59,6 +59,7 @@ struct _GtkDial /* Current angle */ gfloat angle; + gfloat last_angle; /* Old values from adjustment stored so we know when something changes */ gfloat old_value; diff --git a/examples/helloworld/helloworld.c b/examples/helloworld/helloworld.c index 062252ddfc..eaa56fb327 100644 --- a/examples/helloworld/helloworld.c +++ b/examples/helloworld/helloworld.c @@ -50,7 +50,7 @@ int main( int argc, window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* When the window is given the "delete_event" signal (this is given - * by the window manager, usually by the 'close' option, or on the + * by the window manager, usually by the "close" option, or on the * titlebar), we ask it to call the delete_event () function * as defined above. The data passed to the callback * function is NULL and is ignored in the callback function. */ @@ -59,7 +59,7 @@ int main( int argc, /* Here we connect the "destroy" event to a signal handler. * This event occurs when we call gtk_widget_destroy() on the window, - * or if we return 'FALSE' in the "delete_event" callback. */ + * or if we return FALSE in the "delete_event" callback. */ gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL); diff --git a/examples/helloworld2/helloworld2.c b/examples/helloworld2/helloworld2.c index a525aa3ebc..ae41fd15f8 100644 --- a/examples/helloworld2/helloworld2.c +++ b/examples/helloworld2/helloworld2.c @@ -11,11 +11,12 @@ void callback( GtkWidget *widget, } /* another callback */ -void delete_event( GtkWidget *widget, +gint delete_event( GtkWidget *widget, GdkEvent *event, - gpointer data ) + gpointer data ) { - gtk_main_quit (); + gtk_main_quit(); + return(FALSE); } int main( int argc, @@ -33,7 +34,7 @@ int main( int argc, /* Create a new window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - /* This is a new call, this just sets the title of our + /* This is a new call, which just sets the title of our * new window to "Hello Buttons!" */ gtk_window_set_title (GTK_WINDOW (window), "Hello Buttons!"); diff --git a/examples/label/label.c b/examples/label/label.c index 2a22a73d5e..5711a4c98f 100644 --- a/examples/label/label.c +++ b/examples/label/label.c @@ -72,7 +72,7 @@ int main( int argc, label = gtk_label_new ("This is an example of a line-wrapped, filled label. " \ "It should be taking "\ "up the entire width allocated to it. " \ - "Here is a seneance to prove "\ + "Here is a sentence to prove "\ "my point. Here is another sentence. "\ "Here comes the sun, do de do de do.\n"\ " This is a new paragraph.\n"\ diff --git a/examples/list/list.c b/examples/list/list.c index 0a7147dc6b..812786bdc0 100644 --- a/examples/list/list.c +++ b/examples/list/list.c @@ -1,6 +1,6 @@ /* example-start list list.c */ -/* Include the gtk+ header files +/* Include the GTK header files * Include stdio.h, we need that for the printf() function */ #include <gtk/gtk.h> @@ -13,7 +13,7 @@ const gchar *list_item_data_key="list_item_data"; /* prototypes for signal handler that we are going to connect - * to the GtkList widget + * to the List widget */ static void sigh_print_selection( GtkWidget *gtklist, gpointer func_data); @@ -25,8 +25,8 @@ static void sigh_button_event( GtkWidget *gtklist, /* Main function to set up the user interface */ -gint main (int argc, - gchar *argv[]) +gint main( int argc, + gchar *argv[] ) { GtkWidget *separator; GtkWidget *window; @@ -41,7 +41,7 @@ gint main (int argc, gchar buffer[64]; - /* Initialize gtk+ (and subsequently gdk) */ + /* Initialize GTK (and subsequently GDK) */ gtk_init(&argc, &argv); @@ -65,15 +65,15 @@ gint main (int argc, gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show(vbox); - /* This is the scrolled window to put the GtkList widget inside */ + /* This is the scrolled window to put the List 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); gtk_widget_show(scrolled_window); - /* Create the GtkList widget. + /* Create thekList widget. * Connect the sigh_print_selection() signal handler - * function to the "selection_changed" signal of the GtkList + * function to the "selection_changed" signal of the List * to print out the selected items each time the selection * has changed */ gtklist=gtk_list_new(); @@ -93,7 +93,7 @@ gint main (int argc, gtk_container_add(GTK_CONTAINER(vbox), frame); gtk_widget_show(frame); - /* Connect the sigh_button_event() signal handler to the GtkList + /* Connect the sigh_button_event() signal handler to the List * which will handle the "arresting" of list items */ gtk_signal_connect(GTK_OBJECT(gtklist), @@ -106,7 +106,7 @@ gint main (int argc, gtk_container_add(GTK_CONTAINER(vbox), separator); gtk_widget_show(separator); - /* Finally create a button and connect it's "clicked" signal + /* Finally create a button and connect its "clicked" signal * to the destruction of the window */ button=gtk_button_new_with_label("Close"); gtk_container_add(GTK_CONTAINER(vbox), button); @@ -117,8 +117,8 @@ gint main (int argc, GTK_OBJECT(window)); - /* Now we create 5 list items, each having it's own - * label and add them to the GtkList using gtk_container_add() + /* Now we create 5 list items, each having its own + * label and add them to the List using gtk_container_add() * Also we query the text string from the label and * associate it with the list_item_data_key for each list item */ @@ -176,7 +176,7 @@ gint main (int argc, } /* This is the signal handler that got connected to button - * press/release events of the GtkList + * press/release events of the List */ void sigh_button_event( GtkWidget *gtklist, GdkEventButton *event, @@ -218,7 +218,7 @@ void sigh_button_event( GtkWidget *gtklist, g_list_free(free_list); /* If we have a new prisoner, remove him from the - * GtkList and put him into the frame "Prison". + * List and put him into the frame "Prison". * We need to unselect the item first. */ if (new_prisoner) { @@ -235,16 +235,16 @@ void sigh_button_event( GtkWidget *gtklist, } } -/* This is the signal handler that gets called if GtkList +/* This is the signal handler that gets called if List * emits the "selection_changed" signal */ void sigh_print_selection( GtkWidget *gtklist, - gpointer func_data) + gpointer func_data ) { GList *dlist; /* Fetch the doubly linked list of selected items - * of the GtkList, remember to treat this as read-only! + * of the List, remember to treat this as read-only! */ dlist=GTK_LIST(gtklist)->selection; diff --git a/examples/menu/itemfactory.c b/examples/menu/itemfactory.c index b47e3dfe85..d1239baff2 100644 --- a/examples/menu/itemfactory.c +++ b/examples/menu/itemfactory.c @@ -4,8 +4,10 @@ #include <strings.h> /* Obligatory basic callback */ -static void print_hello(GtkWidget *w, gpointer data) { - g_message("Hello, World!\n"); +static void print_hello( GtkWidget *w, + gpointer data ) +{ + g_message ("Hello, World!\n"); } /* This is the GtkItemFactoryEntry structure used to generate new menus. @@ -27,31 +29,33 @@ static void print_hello(GtkWidget *w, gpointer data) { "<RadioItem>" -> create a radio item <path> -> path of a radio item to link against "<Separator>" -> create a separator - "<Branch>" -> create an item to hold sub items + "<Branch>" -> create an item to hold sub items (optional) "<LastBranch>" -> create a right justified branch */ static GtkItemFactoryEntry menu_items[] = { - {"/_File", NULL, NULL, 0, "<Branch>"}, - {"/File/_New", "<control>N", print_hello, 0, NULL}, - {"/File/_Open", "<control>O", print_hello, 0, NULL}, - {"/File/_Save", "<control>S", print_hello, 0, NULL}, - {"/File/Save _As", NULL, NULL, 0, NULL}, - {"/File/sep1", NULL, NULL, 0, "<Separator>"}, - {"/File/Quit", "<control>Q", gtk_main_quit, 0, NULL}, - {"/_Options", NULL, NULL, 0, "<Branch>"}, - {"/Options/Test", NULL, NULL, 0, NULL}, - {"/_Help", NULL, NULL, 0, "<LastBranch>"}, - {"/_Help/About", NULL, NULL, 0, NULL}, + { "/_File", NULL, NULL, 0, "<Branch>" }, + { "/File/_New", "<control>N", print_hello, 0, NULL }, + { "/File/_Open", "<control>O", print_hello, 0, NULL }, + { "/File/_Save", "<control>S", print_hello, 0, NULL }, + { "/File/Save _As", NULL, NULL, 0, NULL }, + { "/File/sep1", NULL, NULL, 0, "<Separator>" }, + { "/File/Quit", "<control>Q", gtk_main_quit, 0, NULL }, + { "/_Options", NULL, NULL, 0, "<Branch>" }, + { "/Options/Test", NULL, NULL, 0, NULL }, + { "/_Help", NULL, NULL, 0, "<LastBranch>" }, + { "/_Help/About", NULL, NULL, 0, NULL }, }; -void get_main_menu(GtkWidget *window, GtkWidget ** menubar) { - int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); +void get_main_menu( GtkWidget *window, + GtkWidget **menubar ) +{ GtkItemFactory *item_factory; GtkAccelGroup *accel_group; + gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); - accel_group = gtk_accel_group_new(); + accel_group = gtk_accel_group_new (); /* This function initializes the item factory. Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU, @@ -61,47 +65,49 @@ void get_main_menu(GtkWidget *window, GtkWidget ** menubar) { the accelerator table while generating menus. */ - item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); /* This function generates the menu items. Pass the item factory, the number of items in the array, the array itself, and any callback data for the the menu items. */ - gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL); + gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); /* Attach the new accelerator group to the window. */ - gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); if (menubar) /* Finally, return the actual menu bar created by the item factory. */ - *menubar = gtk_item_factory_get_widget(item_factory, "<main>"); + *menubar = gtk_item_factory_get_widget (item_factory, "<main>"); } -int main(int argc, char *argv[]) { +int main( int argc, + char *argv[] ) +{ GtkWidget *window; GtkWidget *main_vbox; GtkWidget *menubar; - gtk_init(&argc, &argv); + gtk_init (&argc, &argv); - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_signal_connect(GTK_OBJECT(window), "destroy", - GTK_SIGNAL_FUNC(gtk_main_quit), - "WM destroy"); - gtk_window_set_title(GTK_WINDOW(window), "Item Factory"); - gtk_widget_set_usize(GTK_WIDGET(window), 300, 200); + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), + "WM destroy"); + gtk_window_set_title (GTK_WINDOW(window), "Item Factory"); + gtk_widget_set_usize (GTK_WIDGET(window), 300, 200); - main_vbox = gtk_vbox_new(FALSE, 1); - gtk_container_border_width(GTK_CONTAINER(main_vbox), 1); - gtk_container_add(GTK_CONTAINER(window), main_vbox); - gtk_widget_show(main_vbox); + main_vbox = gtk_vbox_new (FALSE, 1); + gtk_container_border_width (GTK_CONTAINER (main_vbox), 1); + gtk_container_add (GTK_CONTAINER (window), main_vbox); + gtk_widget_show (main_vbox); - get_main_menu(window, &menubar); - gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0); - gtk_widget_show(menubar); + get_main_menu (window, &menubar); + gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0); + gtk_widget_show (menubar); - gtk_widget_show(window); - gtk_main(); + gtk_widget_show (window); + gtk_main (); return(0); } diff --git a/examples/menu/menu.c b/examples/menu/menu.c index a53019b02e..e1420e80aa 100644 --- a/examples/menu/menu.c +++ b/examples/menu/menu.c @@ -5,7 +5,8 @@ static gint button_press (GtkWidget *, GdkEvent *); static void menuitem_response (gchar *); -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; @@ -21,17 +22,17 @@ int main (int argc, char *argv[]) gtk_init (&argc, &argv); /* create a new window */ - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - 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_main_quit, NULL); + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + 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_main_quit, NULL); /* Init the menu-widget, and remember -- never * gtk_show_widget() the menu widget!! * This is the menu that holds the menu items, the one that * will pop up when you click on the "Root Menu" in the app */ - menu = gtk_menu_new(); + menu = gtk_menu_new (); /* Next we make a little loop that makes three menu-entries for "test-menu". * Notice the call to gtk_menu_append. Here we are adding a list of @@ -39,64 +40,64 @@ int main (int argc, char *argv[]) * signal on each of the menu items and setup a callback for it, * but it's omitted here to save space. */ - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { /* Copy the names to the buf. */ - sprintf(buf, "Test-undermenu - %d", i); + sprintf (buf, "Test-undermenu - %d", i); /* Create a new menu-item with a name... */ - menu_items = gtk_menu_item_new_with_label(buf); + menu_items = gtk_menu_item_new_with_label (buf); /* ...and add it to the menu. */ - gtk_menu_append(GTK_MENU (menu), menu_items); + gtk_menu_append (GTK_MENU (menu), menu_items); /* Do something interesting when the menuitem is selected */ - gtk_signal_connect_object(GTK_OBJECT(menu_items), "activate", - GTK_SIGNAL_FUNC(menuitem_response), (gpointer) g_strdup(buf)); + gtk_signal_connect_object (GTK_OBJECT (menu_items), "activate", + GTK_SIGNAL_FUNC (menuitem_response), (gpointer) g_strdup (buf)); /* Show the widget */ - gtk_widget_show(menu_items); + gtk_widget_show (menu_items); } /* This is the root menu, and will be the label * displayed on the menu bar. There won't be a signal handler attached, * as it only pops up the rest of the menu when pressed. */ - root_menu = gtk_menu_item_new_with_label("Root Menu"); + root_menu = gtk_menu_item_new_with_label ("Root Menu"); - gtk_widget_show(root_menu); + gtk_widget_show (root_menu); /* Now we specify that we want our newly created "menu" to be the menu * for the "root menu" */ - gtk_menu_item_set_submenu(GTK_MENU_ITEM (root_menu), menu); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu); /* A vbox to put a menu and a button in: */ - vbox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(window), vbox); - gtk_widget_show(vbox); + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show (vbox); /* Create a menu-bar to hold the menus and add it to our main window */ - menu_bar = gtk_menu_bar_new(); - gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 2); - gtk_widget_show(menu_bar); + menu_bar = gtk_menu_bar_new (); + gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 2); + gtk_widget_show (menu_bar); /* Create a button to which to attach menu as a popup */ - button = gtk_button_new_with_label("press me"); - gtk_signal_connect_object(GTK_OBJECT(button), "event", - GTK_SIGNAL_FUNC (button_press), GTK_OBJECT(menu)); - gtk_box_pack_end(GTK_BOX(vbox), button, TRUE, TRUE, 2); - gtk_widget_show(button); + button = gtk_button_new_with_label ("press me"); + gtk_signal_connect_object (GTK_OBJECT (button), "event", + GTK_SIGNAL_FUNC (button_press), GTK_OBJECT (menu)); + gtk_box_pack_end (GTK_BOX (vbox), button, TRUE, TRUE, 2); + gtk_widget_show (button); /* And finally we append the menu-item to the menu-bar -- this is the * "root" menu-item I have been raving about =) */ - gtk_menu_bar_append(GTK_MENU_BAR (menu_bar), root_menu); + gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), root_menu); /* always display the window as the last step so it all splashes on * the screen at once. */ - gtk_widget_show(window); + gtk_widget_show (window); gtk_main (); - return 0; + return(0); } /* Respond to a button-press by posting a menu passed in as widget. @@ -105,12 +106,13 @@ int main (int argc, char *argv[]) * the button that was pressed. */ -static gint button_press (GtkWidget *widget, GdkEvent *event) +static gint button_press( GtkWidget *widget, + GdkEvent *event ) { if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *bevent = (GdkEventButton *) event; - gtk_menu_popup (GTK_MENU(widget), NULL, NULL, NULL, NULL, + gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, bevent->button, bevent->time); /* Tell calling code that we have handled this event; the buck * stops here. */ @@ -124,8 +126,8 @@ static gint button_press (GtkWidget *widget, GdkEvent *event) /* Print a string when a menu item is selected */ -static void menuitem_response (gchar *string) +static void menuitem_response( gchar *string ) { - printf("%s\n", string); + printf ("%s\n", string); } /* example-end */ diff --git a/examples/notebook/notebook.c b/examples/notebook/notebook.c index 3cb1007dc0..79c4bc4148 100644 --- a/examples/notebook/notebook.c +++ b/examples/notebook/notebook.c @@ -3,13 +3,15 @@ #include <gtk/gtk.h> /* This function rotates the position of the tabs */ -void rotate_book (GtkButton *button, GtkNotebook *notebook) +void rotate_book( GtkButton *button, + GtkNotebook *notebook ) { gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos +1) %4); } /* Add/Remove the page tabs and the borders */ -void tabsborder_book (GtkButton *button, GtkNotebook *notebook) +void tabsborder_book( GtkButton *button, + GtkNotebook *notebook ) { gint tval = FALSE; gint bval = FALSE; @@ -23,7 +25,8 @@ void tabsborder_book (GtkButton *button, GtkNotebook *notebook) } /* Remove a page from the notebook */ -void remove_book (GtkButton *button, GtkNotebook *notebook) +void remove_book( GtkButton *button, + GtkNotebook *notebook ) { gint page; @@ -34,12 +37,16 @@ void remove_book (GtkButton *button, GtkNotebook *notebook) gtk_widget_draw(GTK_WIDGET(notebook), NULL); } -void delete (GtkWidget *widget, GtkWidget *event, gpointer data) +gint delete( GtkWidget *widget, + GtkWidget *event, + gpointer data ) { - gtk_main_quit (); + gtk_main_quit(); + return(FALSE); } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *button; @@ -70,7 +77,7 @@ int main (int argc, char *argv[]) gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1); gtk_widget_show(notebook); - /* Lets append a bunch of pages to the notebook */ + /* Let's append a bunch of pages to the notebook */ for (i=0; i < 5; i++) { sprintf(bufferf, "Append Frame %d", i+1); sprintf(bufferl, "Page %d", i+1); @@ -88,7 +95,7 @@ int main (int argc, char *argv[]) gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label); } - /* Now lets add a page to a specific spot */ + /* Now let's add a page to a specific spot */ checkbutton = gtk_check_button_new_with_label ("Check me please!"); gtk_widget_set_usize(checkbutton, 100, 75); gtk_widget_show (checkbutton); @@ -96,7 +103,7 @@ int main (int argc, char *argv[]) label = gtk_label_new ("Add page"); gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, label, 2); - /* Now finally lets prepend pages to the notebook */ + /* Now finally let's prepend pages to the notebook */ for (i=0; i < 5; i++) { sprintf(bufferf, "Prepend Frame %d", i+1); sprintf(bufferl, "PPage %d", i+1); @@ -140,7 +147,8 @@ int main (int argc, char *argv[]) button = gtk_button_new_with_label ("tab position"); gtk_signal_connect (GTK_OBJECT (button), "clicked", - (GtkSignalFunc) rotate_book, GTK_OBJECT(notebook)); + (GtkSignalFunc) rotate_book, + GTK_OBJECT(notebook)); gtk_table_attach_defaults(GTK_TABLE(table), button, 3,4,1,2); gtk_widget_show(button); diff --git a/examples/packbox/packbox.c b/examples/packbox/packbox.c index ba67b9505f..637836d30a 100644 --- a/examples/packbox/packbox.c +++ b/examples/packbox/packbox.c @@ -1,13 +1,15 @@ /* example-start packbox packbox.c */ #include <stdio.h> +#include <stdlib.h> #include "gtk/gtk.h" -void delete_event( GtkWidget *widget, +gint delete_event( GtkWidget *widget, GdkEvent *event, - gpointer data ) + gpointer data ) { - gtk_main_quit (); + gtk_main_quit(); + return(FALSE); } /* Make a new hbox filled with button-labels. Arguments for the @@ -82,7 +84,7 @@ int main( int argc, if (argc != 2) { fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n"); - /* this just does cleanup in GTK, and exits with an exit status of 1. */ + /* This just does cleanup in GTK and exits with an exit status of 1. */ gtk_exit (1); } @@ -91,8 +93,8 @@ int main( int argc, /* Create our window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - /* You should always remember to connect the destroy signal to the - * main window. This is very important for proper intuitive + /* You should always remember to connect the delete_event signal + * to the main window. This is very important for proper intuitive * behavior */ gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); @@ -128,7 +130,7 @@ int main( int argc, gtk_widget_show (box2); /* Call our make box function - homogeneous = FALSE, spacing = 0, - * expand = FALSE, fill = FALSE, padding = 0 */ + * expand = TRUE, fill = FALSE, padding = 0 */ box2 = make_box (FALSE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); @@ -142,8 +144,8 @@ int main( int argc, * but they are quite simple. */ separator = gtk_hseparator_new (); - /* Cack the separator into the vbox. Remember each of these - * widgets are being packed into a vbox, so they'll be stacked + /* Pack the separator into the vbox. Remember each of these + * widgets is being packed into a vbox, so they'll be stacked * vertically. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); @@ -166,7 +168,8 @@ int main( int argc, /* Another new separator. */ separator = gtk_hseparator_new (); - /* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */ + /* The last 3 arguments to gtk_box_pack_start are: + * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); @@ -192,7 +195,8 @@ int main( int argc, gtk_widget_show (box2); separator = gtk_hseparator_new (); - /* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */ + /* The last 3 arguments to gtk_box_pack_start are: + * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); @@ -255,14 +259,13 @@ int main( int argc, /* Our quit button. */ button = gtk_button_new_with_label ("Quit"); - /* Setup the signal to destroy the window. Remember that this will send - * the "destroy" signal to the window which will be caught by our signal - * handler as defined above. */ + /* Setup the signal to terminate the program when the button is clicked */ gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), GTK_OBJECT (window)); /* Pack the button into the quitbox. - * The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */ + * The last 3 arguments to gtk_box_pack_start are: + * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0); /* pack the quitbox into the vbox (box1) */ gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0); diff --git a/examples/paned/paned.c b/examples/paned/paned.c index 3cd0e7fa85..7fafb33ad5 100644 --- a/examples/paned/paned.c +++ b/examples/paned/paned.c @@ -3,8 +3,7 @@ #include <gtk/gtk.h> /* Create the list of "messages" */ -GtkWidget * -create_list (void) +GtkWidget *create_list( void ) { GtkWidget *scrolled_window; @@ -22,8 +21,8 @@ create_list (void) /* Create a new list and put it in the scrolled window */ list = gtk_list_new (); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), - list); + gtk_scrolled_window_add_with_viewport ( + GTK_SCROLLED_WINDOW (scrolled_window), list); gtk_widget_show (list); /* Add some messages to the window */ @@ -44,8 +43,8 @@ when our window is realized. We could also force our window to be realized with gtk_widget_realize, but it would have to be part of a hierarchy first */ -void -realize_text (GtkWidget *text, gpointer data) +void realize_text( GtkWidget *text, + gpointer data ) { gtk_text_freeze (GTK_TEXT (text)); gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, @@ -62,8 +61,7 @@ realize_text (GtkWidget *text, gpointer data) } /* Create a scrolled text area that displays a "message" */ -GtkWidget * -create_text (void) +GtkWidget *create_text( void ) { GtkWidget *table; GtkWidget *text; @@ -100,8 +98,8 @@ create_text (void) return table; } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *vpaned; diff --git a/examples/pixmap/pixmap.c b/examples/pixmap/pixmap.c index bb48c41837..8834c9e2b3 100644 --- a/examples/pixmap/pixmap.c +++ b/examples/pixmap/pixmap.c @@ -29,18 +29,24 @@ static const char * xpm_data[] = { /* when invoked (via signal delete_event), terminates the application. */ -void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) { +gint close_application( GtkWidget *widget, + GdkEvent *event, + gpointer data ) +{ gtk_main_quit(); + return(FALSE); } /* is invoked when the button is clicked. It just prints a message. */ -void button_clicked( GtkWidget *widget, gpointer data ) { - printf( "button clicked\n" ); +void button_clicked( GtkWidget *widget, + gpointer data ) { + g_print( "button clicked\n" ); } -int main( int argc, char *argv[] ) +int main( int argc, + char *argv[] ) { /* GtkWidget is the storage type for widgets */ GtkWidget *window, *pixmapwid, *button; diff --git a/examples/progressbar/progressbar.c b/examples/progressbar/progressbar.c index 073e74fa7b..1a824e2869 100644 --- a/examples/progressbar/progressbar.c +++ b/examples/progressbar/progressbar.c @@ -115,7 +115,7 @@ int main( int argc, 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 + /* Create a Adjusment object to hold the range of the * progress bar */ adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0); diff --git a/examples/radiobuttons/radiobuttons.c b/examples/radiobuttons/radiobuttons.c index 4f708c95c7..8fc81872f6 100644 --- a/examples/radiobuttons/radiobuttons.c +++ b/examples/radiobuttons/radiobuttons.c @@ -3,11 +3,12 @@ #include <gtk/gtk.h> #include <glib.h> -void close_application( GtkWidget *widget, +gint close_application( GtkWidget *widget, GdkEvent *event, - gpointer data ) + gpointer data ) { gtk_main_quit(); + return(FALSE); } int main( int argc, diff --git a/examples/rangewidgets/rangewidgets.c b/examples/rangewidgets/rangewidgets.c index 72d2f54678..e293664f09 100644 --- a/examples/rangewidgets/rangewidgets.c +++ b/examples/rangewidgets/rangewidgets.c @@ -102,7 +102,7 @@ void create_range_controls( void ) gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); gtk_widget_show (box2); - /* calue, lower, upper, step_increment, page_increment, page_size */ + /* value, lower, upper, step_increment, page_increment, page_size */ /* Note that the page_size value only makes a difference for * scrollbar widgets, and the highest value you'll get is actually * (upper - page_size). */ @@ -218,7 +218,7 @@ void create_range_controls( void ) box2 = gtk_hbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10); - /* A GtkHScale widget for adjusting the number of digits on the + /* An HScale widget for adjusting the number of digits on the * sample scales. */ label = gtk_label_new ("Scale Digits:"); gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0); @@ -238,7 +238,7 @@ void create_range_controls( void ) box2 = gtk_hbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10); - /* And, one last GtkHScale widget for adjusting the page size of the + /* And, one last HScale widget for adjusting the page size of the * scrollbar. */ label = gtk_label_new ("Scrollbar Page Size:"); gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0); diff --git a/examples/rulers/rulers.c b/examples/rulers/rulers.c index 41260c6bc8..fa933f172d 100644 --- a/examples/rulers/rulers.c +++ b/examples/rulers/rulers.c @@ -8,12 +8,17 @@ #define YSIZE 400 /* This routine gets control when the close button is clicked */ -void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) { +gint close_application( GtkWidget *widget, + GdkEvent *event, + gpointer data ) +{ gtk_main_quit(); + return(FALSE); } /* The main routine */ -int main( int argc, char *argv[] ) { +int main( int argc, + char *argv[] ) { GtkWidget *window, *table, *area, *hrule, *vrule; /* Initialize GTK and create the main window */ @@ -32,28 +37,33 @@ int main( int argc, char *argv[] ) { gtk_drawing_area_size( (GtkDrawingArea *)area, XSIZE, YSIZE ); gtk_table_attach( GTK_TABLE(table), area, 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 ); - gtk_widget_set_events( area, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK ); + 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 ); gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event", - (GtkSignalFunc)EVENT_METHOD(hrule, motion_notify_event), + (GtkSignalFunc)EVENT_METHOD(hrule, + motion_notify_event), GTK_OBJECT(hrule) ); /* GTK_WIDGET_CLASS(GTK_OBJECT(hrule)->klass)->motion_notify_event, */ 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 ); gtk_signal_connect_object( GTK_OBJECT(area), "motion_notify_event", (GtkSignalFunc) - GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)->motion_notify_event, + GTK_WIDGET_CLASS(GTK_OBJECT(vrule)->klass)-> + motion_notify_event, GTK_OBJECT(vrule) ); gtk_table_attach( GTK_TABLE(table), vrule, 0, 1, 1, 2, GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 ); diff --git a/examples/scribble-simple/scribble-simple.c b/examples/scribble-simple/scribble-simple.c index 365219b382..3e6bdf30f5 100644 --- a/examples/scribble-simple/scribble-simple.c +++ b/examples/scribble-simple/scribble-simple.c @@ -25,8 +25,8 @@ static GdkPixmap *pixmap = NULL; /* Create a new backing pixmap of the appropriate size */ -static gint -configure_event (GtkWidget *widget, GdkEventConfigure *event) +static gint configure_event( GtkWidget *widget, + GdkEventConfigure *event ) { if (pixmap) gdk_pixmap_unref(pixmap); @@ -46,8 +46,8 @@ configure_event (GtkWidget *widget, GdkEventConfigure *event) } /* Redraw the screen from the backing pixmap */ -static gint -expose_event (GtkWidget *widget, GdkEventExpose *event) +static gint expose_event( GtkWidget *widget, + GdkEventExpose *event ) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], @@ -60,8 +60,9 @@ expose_event (GtkWidget *widget, GdkEventExpose *event) } /* Draw a rectangle on the screen */ -static void -draw_brush (GtkWidget *widget, gdouble x, gdouble y) +static void draw_brush( GtkWidget *widget, + gdouble x, + gdouble y) { GdkRectangle update_rect; @@ -77,8 +78,8 @@ draw_brush (GtkWidget *widget, gdouble x, gdouble y) gtk_widget_draw (widget, &update_rect); } -static gint -button_press_event (GtkWidget *widget, GdkEventButton *event) +static gint button_press_event( GtkWidget *widget, + GdkEventButton *event ) { if (event->button == 1 && pixmap != NULL) draw_brush (widget, event->x, event->y); @@ -86,8 +87,8 @@ button_press_event (GtkWidget *widget, GdkEventButton *event) return TRUE; } -static gint -motion_notify_event (GtkWidget *widget, GdkEventMotion *event) +static gint motion_notify_event( GtkWidget *widget, + GdkEventMotion *event ) { int x, y; GdkModifierType state; @@ -107,14 +108,13 @@ motion_notify_event (GtkWidget *widget, GdkEventMotion *event) return TRUE; } -void -quit () +void quit () { gtk_exit (0); } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *drawing_area; diff --git a/examples/scribble-xinput/Makefile b/examples/scribble-xinput/Makefile new file mode 100644 index 0000000000..008575c04b --- /dev/null +++ b/examples/scribble-xinput/Makefile @@ -0,0 +1,8 @@ + +CC = gcc + +scribble-xinput: scribble-xinput.c + $(CC) `gtk-config --cflags` scribble-xinput.c -o scribble-xinput `gtk-config --libs` + +clean: + rm -f *.o scribble-xinput diff --git a/examples/scribble-xinput/scribble-xinput.c b/examples/scribble-xinput/scribble-xinput.c new file mode 100644 index 0000000000..81d4e6423b --- /dev/null +++ b/examples/scribble-xinput/scribble-xinput.c @@ -0,0 +1,270 @@ +/* example-start scribble-xinput scribble-xinput.c */ + +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtk.h> + +/* Backing pixmap for drawing area */ +static GdkPixmap *pixmap = NULL; + +/* Create a new backing pixmap of the appropriate size */ +static gint +configure_event (GtkWidget *widget, GdkEventConfigure *event) +{ + if (pixmap) + gdk_pixmap_unref(pixmap); + + pixmap = gdk_pixmap_new(widget->window, + widget->allocation.width, + widget->allocation.height, + -1); + gdk_draw_rectangle (pixmap, + widget->style->white_gc, + TRUE, + 0, 0, + widget->allocation.width, + widget->allocation.height); + + return TRUE; +} + +/* Redraw the screen from the backing pixmap */ +static gint +expose_event (GtkWidget *widget, GdkEventExpose *event) +{ + gdk_draw_pixmap(widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + pixmap, + event->area.x, event->area.y, + event->area.x, event->area.y, + event->area.width, event->area.height); + + return FALSE; +} + +/* Draw a rectangle on the screen, size depending on pressure, + and color on the type of device */ +static void +draw_brush (GtkWidget *widget, GdkInputSource source, + gdouble x, gdouble y, gdouble pressure) +{ + GdkGC *gc; + GdkRectangle update_rect; + + switch (source) + { + case GDK_SOURCE_MOUSE: + gc = widget->style->dark_gc[GTK_WIDGET_STATE (widget)]; + break; + case GDK_SOURCE_PEN: + gc = widget->style->black_gc; + break; + case GDK_SOURCE_ERASER: + gc = widget->style->white_gc; + break; + default: + gc = widget->style->light_gc[GTK_WIDGET_STATE (widget)]; + } + + update_rect.x = x - 10 * pressure; + update_rect.y = y - 10 * pressure; + update_rect.width = 20 * pressure; + update_rect.height = 20 * pressure; + gdk_draw_rectangle (pixmap, gc, TRUE, + update_rect.x, update_rect.y, + update_rect.width, update_rect.height); + gtk_widget_draw (widget, &update_rect); +} + +static void +print_button_press (guint32 deviceid) +{ + GList *tmp_list; + + /* gdk_input_list_devices returns an internal list, so we shouldn't + free it afterwards */ + tmp_list = gdk_input_list_devices(); + + while (tmp_list) + { + GdkDeviceInfo *info = (GdkDeviceInfo *)tmp_list->data; + + if (info->deviceid == deviceid) + { + g_print("Button press on device '%s'\n", info->name); + return; + } + + tmp_list = tmp_list->next; + } +} + +static gint +button_press_event (GtkWidget *widget, GdkEventButton *event) +{ + print_button_press (event->deviceid); + + if (event->button == 1 && pixmap != NULL) + draw_brush (widget, event->source, event->x, event->y, event->pressure); + + return TRUE; +} + +static gint +motion_notify_event (GtkWidget *widget, GdkEventMotion *event) +{ + gdouble x, y; + gdouble pressure; + GdkModifierType state; + + if (event->is_hint) + gdk_input_window_get_pointer (event->window, event->deviceid, + &x, &y, &pressure, + NULL, NULL, &state); + else + { + x = event->x; + y = event->y; + pressure = event->pressure; + state = event->state; + } + + if (state & GDK_BUTTON1_MASK && pixmap != NULL) + draw_brush (widget, event->source, x, y, pressure); + + return TRUE; +} + +void +input_dialog_destroy (GtkWidget *w, gpointer data) +{ + *((GtkWidget **)data) = NULL; +} + +void +create_input_dialog () +{ + static GtkWidget *inputd = NULL; + + if (!inputd) + { + inputd = gtk_input_dialog_new(); + + gtk_signal_connect (GTK_OBJECT(inputd), "destroy", + (GtkSignalFunc)input_dialog_destroy, &inputd); + gtk_signal_connect_object (GTK_OBJECT(GTK_INPUT_DIALOG(inputd)->close_button), + "clicked", + (GtkSignalFunc)gtk_widget_hide, + GTK_OBJECT(inputd)); + gtk_widget_hide ( GTK_INPUT_DIALOG(inputd)->save_button); + + gtk_widget_show (inputd); + } + else + { + if (!GTK_WIDGET_MAPPED(inputd)) + gtk_widget_show(inputd); + else + gdk_window_raise(inputd->window); + } +} + +void +quit () +{ + gtk_exit (0); +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *drawing_area; + GtkWidget *vbox; + + GtkWidget *button; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_set_name (window, "Test Input"); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show (vbox); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (quit), NULL); + + /* Create the drawing area */ + + drawing_area = gtk_drawing_area_new (); + gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200); + gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0); + + gtk_widget_show (drawing_area); + + /* Signals used to handle backing pixmap */ + + gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event", + (GtkSignalFunc) expose_event, NULL); + gtk_signal_connect (GTK_OBJECT(drawing_area),"configure_event", + (GtkSignalFunc) configure_event, NULL); + + /* Event signals */ + + gtk_signal_connect (GTK_OBJECT (drawing_area), "motion_notify_event", + (GtkSignalFunc) motion_notify_event, NULL); + gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event", + (GtkSignalFunc) button_press_event, NULL); + + gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK + | GDK_LEAVE_NOTIFY_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK); + + /* The following call enables tracking and processing of extension + events for the drawing area */ + gtk_widget_set_extension_events (drawing_area, GDK_EXTENSION_EVENTS_CURSOR); + + /* .. And some buttons */ + button = gtk_button_new_with_label ("Input Dialog"); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (create_input_dialog), NULL); + gtk_widget_show (button); + + button = gtk_button_new_with_label ("Quit"); + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT (window)); + gtk_widget_show (button); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} +/* example-end */ diff --git a/examples/scrolledwin/scrolledwin.c b/examples/scrolledwin/scrolledwin.c index 8521b83665..977dcf20fd 100644 --- a/examples/scrolledwin/scrolledwin.c +++ b/examples/scrolledwin/scrolledwin.c @@ -2,12 +2,14 @@ #include <gtk/gtk.h> -void destroy(GtkWidget *widget, gpointer data) +void destroy( GtkWidget *widget, + gpointer data ) { gtk_main_quit(); } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { static GtkWidget *window; GtkWidget *scrolled_window; @@ -19,9 +21,7 @@ int main (int argc, char *argv[]) gtk_init (&argc, &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 separator packed into it. It's just a shortcut - * for creating dialogs */ + * packed into. */ window = gtk_dialog_new (); gtk_signal_connect (GTK_OBJECT (window), "destroy", (GtkSignalFunc) destroy, NULL); @@ -54,8 +54,8 @@ int main (int argc, char *argv[]) gtk_table_set_col_spacings (GTK_TABLE (table), 10); /* pack the table into the scrolled window */ - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), - table); + gtk_scrolled_window_add_with_viewport ( + GTK_SCROLLED_WINDOW (scrolled_window), table); gtk_widget_show (table); /* this simply creates a grid of toggle buttons on the table diff --git a/examples/selection/gettargets.c b/examples/selection/gettargets.c index fa183b5973..20292c700b 100644 --- a/examples/selection/gettargets.c +++ b/examples/selection/gettargets.c @@ -2,13 +2,13 @@ #include <gtk/gtk.h> -void selection_received (GtkWidget *widget, - GtkSelectionData *selection_data, - gpointer data); +void selection_received( GtkWidget *widget, + GtkSelectionData *selection_data, + gpointer data ); /* Signal handler invoked when user clicks on the "Get Targets" button */ -void -get_targets (GtkWidget *widget, gpointer data) +void get_targets( GtkWidget *widget, + gpointer data ) { static GdkAtom targets_atom = GDK_NONE; @@ -22,9 +22,9 @@ get_targets (GtkWidget *widget, gpointer data) } /* Signal handler called when the selections owner returns the data */ -void -selection_received (GtkWidget *widget, GtkSelectionData *selection_data, - gpointer data) +void selection_received( GtkWidget *widget, + GtkSelectionData *selection_data, + gpointer data ) { GdkAtom *atoms; GList *item_list; @@ -60,8 +60,8 @@ selection_received (GtkWidget *widget, GtkSelectionData *selection_data, return; } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *button; diff --git a/examples/selection/setselection.c b/examples/selection/setselection.c index fcde84b2d0..690aa49c6c 100644 --- a/examples/selection/setselection.c +++ b/examples/selection/setselection.c @@ -4,8 +4,8 @@ #include <time.h> /* Callback when the user toggles the selection */ -void -selection_toggled (GtkWidget *widget, gint *have_selection) +void selection_toggled( GtkWidget *widget, + gint *have_selection ) { if (GTK_TOGGLE_BUTTON(widget)->active) { @@ -32,9 +32,9 @@ selection_toggled (GtkWidget *widget, gint *have_selection) } /* Called when another application claims the selection */ -gint -selection_clear (GtkWidget *widget, GdkEventSelection *event, - gint *have_selection) +gint selection_clear( GtkWidget *widget, + GdkEventSelection *event, + gint *have_selection ) { *have_selection = FALSE; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE); @@ -43,15 +43,16 @@ selection_clear (GtkWidget *widget, GdkEventSelection *event, } /* Supplies the current time as the selection. */ -void -selection_handle (GtkWidget *widget, - GtkSelectionData *selection_data, - gpointer data) +void selection_handle( GtkWidget *widget, + GtkSelectionData *selection_data, + guint info, + guint time_stamp, + gpointer data ) { gchar *timestr; time_t current_time; - current_time = time (NULL); + current_time = time(NULL); timestr = asctime (localtime(¤t_time)); /* When we return a single string, it should not be null terminated. That will be done for us */ @@ -60,11 +61,10 @@ selection_handle (GtkWidget *widget, 8, timestr, strlen(timestr)); } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; - GtkWidget *selection_button; static int have_selection = FALSE; @@ -91,9 +91,12 @@ main (int argc, char *argv[]) gtk_signal_connect (GTK_OBJECT(selection_button), "selection_clear_event", GTK_SIGNAL_FUNC (selection_clear), &have_selection); - gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - selection_handle, NULL); + gtk_selection_add_target (selection_button, + GDK_SELECTION_PRIMARY, + GDK_SELECTION_TYPE_STRING, + 1); + gtk_signal_connect (GTK_OBJECT(selection_button), "selection_get", + GTK_SIGNAL_FUNC (selection_handle), &have_selection); gtk_widget_show (selection_button); gtk_widget_show (window); diff --git a/examples/statusbar/statusbar.c b/examples/statusbar/statusbar.c index 2a4e8cf8a9..c738bf02c0 100644 --- a/examples/statusbar/statusbar.c +++ b/examples/statusbar/statusbar.c @@ -5,7 +5,8 @@ GtkWidget *status_bar; -void push_item (GtkWidget *widget, gpointer data) +void push_item( GtkWidget *widget, + gpointer data ) { static int count = 1; char buff[20]; @@ -16,13 +17,15 @@ void push_item (GtkWidget *widget, gpointer data) return; } -void pop_item (GtkWidget *widget, gpointer data) +void pop_item( GtkWidget *widget, + gpointer data ) { gtk_statusbar_pop( GTK_STATUSBAR(status_bar), GPOINTER_TO_INT(data) ); return; } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; @@ -48,7 +51,8 @@ int main (int argc, char *argv[]) gtk_box_pack_start (GTK_BOX (vbox), status_bar, TRUE, TRUE, 0); gtk_widget_show (status_bar); - context_id = gtk_statusbar_get_context_id( GTK_STATUSBAR(status_bar), "Statusbar example"); + context_id = gtk_statusbar_get_context_id( + GTK_STATUSBAR(status_bar), "Statusbar example"); button = gtk_button_new_with_label("push item"); gtk_signal_connect(GTK_OBJECT(button), "clicked", diff --git a/examples/table/table.c b/examples/table/table.c index dbd9aad873..a6b020c149 100644 --- a/examples/table/table.c +++ b/examples/table/table.c @@ -11,11 +11,12 @@ void callback( GtkWidget *widget, } /* This callback quits the program */ -void delete_event( GtkWidget *widget, +gint delete_event( GtkWidget *widget, GdkEvent *event, - gpointer data ) + gpointer data ) { gtk_main_quit (); + return(FALSE); } int main( int argc, diff --git a/examples/text/text.c b/examples/text/text.c index f98ba09c00..d94e06f564 100644 --- a/examples/text/text.c +++ b/examples/text/text.c @@ -19,12 +19,14 @@ void text_toggle_word_wrap (GtkWidget *checkbutton, GTK_TOGGLE_BUTTON(checkbutton)->active); } -void close_application( GtkWidget *widget, gpointer data ) +void close_application( GtkWidget *widget, + gpointer data ) { gtk_main_quit(); } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *box1; @@ -37,7 +39,7 @@ int main (int argc, char *argv[]) GtkWidget *vscrollbar; GtkWidget *text; GdkColormap *cmap; - GdkColor colour; + GdkColor color; GdkFont *fixed_font; FILE *infile; @@ -85,28 +87,29 @@ int main (int argc, char *argv[]) GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0); gtk_widget_show (vscrollbar); - /* Get the system colour map and allocate the colour red */ + /* Get the system color map and allocate the color red */ cmap = gdk_colormap_get_system(); - colour.red = 0xffff; - colour.green = 0; - colour.blue = 0; - if (!gdk_color_alloc(cmap, &colour)) { - g_error("couldn't allocate colour"); + color.red = 0xffff; + color.green = 0; + color.blue = 0; + if (!gdk_color_alloc(cmap, &color)) { + g_error("couldn't allocate color"); } /* Load a fixed font */ fixed_font = gdk_font_load ("-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*"); - /* Realizing a widget creates a window for it, ready for us to insert some text */ + /* Realizing a widget creates a window for it, + * ready for us to insert some text */ gtk_widget_realize (text); /* Freeze the text widget, ready for multiple updates */ gtk_text_freeze (GTK_TEXT (text)); - /* Insert some coloured text */ + /* Insert some colored text */ gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, "Supports ", -1); - gtk_text_insert (GTK_TEXT (text), NULL, &colour, NULL, + gtk_text_insert (GTK_TEXT (text), NULL, &color, NULL, "colored ", -1); gtk_text_insert (GTK_TEXT (text), NULL, &text->style->black, NULL, "text and different ", -1); diff --git a/examples/tictactoe/tictactoe.c b/examples/tictactoe/tictactoe.c index 530d72e3d6..040d472ea3 100644 --- a/examples/tictactoe/tictactoe.c +++ b/examples/tictactoe/tictactoe.c @@ -68,8 +68,10 @@ tictactoe_class_init (TictactoeClass *class) tictactoe_signals[TICTACTOE_SIGNAL] = gtk_signal_new ("tictactoe", GTK_RUN_FIRST, object_class->type, - GTK_SIGNAL_OFFSET (TictactoeClass, tictactoe), - gtk_signal_default_marshaller, GTK_TYPE_NONE, 0); + GTK_SIGNAL_OFFSET (TictactoeClass, + tictactoe), + gtk_signal_default_marshaller, + GTK_TYPE_NONE, 0); gtk_object_class_add_signals (object_class, tictactoe_signals, LAST_SIGNAL); diff --git a/examples/tictactoe/ttt_test.c b/examples/tictactoe/ttt_test.c index 4a08248c7c..82941e8930 100644 --- a/examples/tictactoe/ttt_test.c +++ b/examples/tictactoe/ttt_test.c @@ -3,15 +3,15 @@ #include <gtk/gtk.h> #include "tictactoe.h" -void -win (GtkWidget *widget, gpointer data) +void win( GtkWidget *widget, + gpointer data ) { g_print ("Yay!\n"); tictactoe_clear (TICTACTOE (widget)); } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *ttt; diff --git a/examples/tree/tree.c b/examples/tree/tree.c index 3ac6a4cb28..67b93fe283 100644 --- a/examples/tree/tree.c +++ b/examples/tree/tree.c @@ -3,12 +3,13 @@ #include <gtk/gtk.h> /* for all the GtkItem:: and GtkTreeItem:: signals */ -static void cb_itemsignal (GtkWidget *item, gchar *signame) +static void cb_itemsignal( GtkWidget *item, + gchar *signame ) { gchar *name; GtkLabel *label; - /* It's a GtkBin, so it has one child, which we know to be a + /* It's a Bin, so it has one child, which we know to be a label, so get that */ label = GTK_LABEL (GTK_BIN (item)->child); /* Get the text of the label */ @@ -19,8 +20,9 @@ static void cb_itemsignal (GtkWidget *item, gchar *signame) } /* Note that this is never called */ -static void cb_unselect_child (GtkWidget *root_tree, GtkWidget *child, - GtkWidget *subtree) +static void cb_unselect_child( GtkWidget *root_tree, + GtkWidget *child, + GtkWidget *subtree ) { g_print ("unselect_child called for root tree %p, subtree %p, child %p\n", root_tree, subtree, child); @@ -35,7 +37,7 @@ static void cb_select_child (GtkWidget *root_tree, GtkWidget *child, root_tree, subtree, child); } -static void cb_selection_changed (GtkWidget *tree) +static void cb_selection_changed( GtkWidget *tree ) { GList *i; @@ -58,7 +60,8 @@ static void cb_selection_changed (GtkWidget *tree) } } -int main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window, *scrolled_win, *tree; static gchar *itemnames[] = {"Foo", "Bar", "Baz", "Quux", diff --git a/examples/wheelbarrow/wheelbarrow.c b/examples/wheelbarrow/wheelbarrow.c index d129ca6827..5d1df1d155 100644 --- a/examples/wheelbarrow/wheelbarrow.c +++ b/examples/wheelbarrow/wheelbarrow.c @@ -120,11 +120,16 @@ static char * WheelbarrowFull_xpm[] = { /* When invoked (via signal delete_event), terminates the application */ -void close_application( GtkWidget *widget, GdkEvent *event, gpointer data ) { +gint close_application( GtkWidget *widget, + GdkEvent *event, + gpointer data ) +{ gtk_main_quit(); + return(FALSE); } -int main (int argc, char *argv[]) +int main (int argc, + char *argv[] ) { /* GtkWidget is the storage type for widgets */ GtkWidget *window, *pixmap, *fixed; |