From ee3d13766031e30653d82764aef92ae444015c5e Mon Sep 17 00:00:00 2001 From: GMT 1999 Tony Gale Date: Sat, 13 Nov 1999 23:06:46 +0000 Subject: [PATCH] threads example from Erik Mouw. New question on GtkLabel background Sat Nov 13 22:30:29 GMT 1999 Tony Gale * 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. --- ChangeLog | 14 + ChangeLog.pre-2-0 | 14 + ChangeLog.pre-2-10 | 14 + ChangeLog.pre-2-2 | 14 + ChangeLog.pre-2-4 | 14 + ChangeLog.pre-2-6 | 14 + ChangeLog.pre-2-8 | 14 + docs/faq/gtkfaq.sgml | 160 +++- docs/gtk_tut.sgml | 838 ++++++++++++++++----- docs/gtkfaq.sgml | 160 +++- docs/tutorial/gtk_tut.sgml | 838 ++++++++++++++++----- examples/Makefile | 1 + examples/aspectframe/aspectframe.c | 4 +- examples/buttonbox/buttonbox.c | 12 +- examples/buttons/buttons.c | 1 - examples/entry/entry.c | 14 +- examples/eventbox/eventbox.c | 4 +- examples/filesel/filesel.c | 12 +- examples/fixed/fixed.c | 2 +- examples/frame/frame.c | 2 +- examples/gtkdial/gtkdial.c | 119 ++- examples/gtkdial/gtkdial.h | 1 + examples/helloworld/helloworld.c | 4 +- examples/helloworld2/helloworld2.c | 9 +- examples/label/label.c | 2 +- examples/list/list.c | 34 +- examples/menu/itemfactory.c | 82 +- examples/menu/menu.c | 72 +- examples/notebook/notebook.c | 28 +- examples/packbox/packbox.c | 33 +- examples/paned/paned.c | 18 +- examples/pixmap/pixmap.c | 14 +- examples/progressbar/progressbar.c | 2 +- examples/radiobuttons/radiobuttons.c | 5 +- examples/rangewidgets/rangewidgets.c | 6 +- examples/rulers/rulers.c | 28 +- examples/scribble-simple/scribble-simple.c | 28 +- examples/scribble-xinput/Makefile | 8 + examples/scribble-xinput/scribble-xinput.c | 270 +++++++ examples/scrolledwin/scrolledwin.c | 14 +- examples/selection/gettargets.c | 20 +- examples/selection/setselection.c | 35 +- examples/statusbar/statusbar.c | 12 +- examples/table/table.c | 5 +- examples/text/text.c | 27 +- examples/tictactoe/tictactoe.c | 6 +- examples/tictactoe/ttt_test.c | 8 +- examples/tree/tree.c | 15 +- examples/wheelbarrow/wheelbarrow.c | 9 +- 49 files changed, 2379 insertions(+), 681 deletions(-) create mode 100644 examples/scribble-xinput/Makefile create mode 100644 examples/scribble-xinput/scribble-xinput.c diff --git a/ChangeLog b/ChangeLog index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 01094f781c..0f70d9b3f2 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +Sat Nov 13 22:30:29 GMT 1999 Tony Gale + + * 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. + 1999-11-10 Tor Lillqvist * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode diff --git a/docs/faq/gtkfaq.sgml b/docs/faq/gtkfaq.sgml index 3ed17164b6..6d8c35fa10 100644 --- a/docs/faq/gtkfaq.sgml +++ b/docs/faq/gtkfaq.sgml @@ -9,7 +9,7 @@ Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd -October 30th 1999 +November 9th 1999 This document is intended to answer questions that are likely to be frequently asked by programmers using GTK+ or people who are just looking at @@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal handler you do not need to call gdk_threads_enter(), but within the other types of callbacks, you do. +Erik Mouw contributed the following code example to illustrate how to +use threads within GTK+ programs. + + +/*------------------------------------------------------------------------- + * Filename: gtk-thread.c + * Version: 0.99.1 + * Copyright: Copyright (C) 1999, Erik Mouw + * Author: Erik Mouw + * Description: GTK threads example. + * Created at: Sun Oct 17 21:27:09 1999 + * Modified by: Erik Mouw + * Modified at: Sun Oct 24 17:21:41 1999 + *-----------------------------------------------------------------------*/ +/* + * Compile with: + * + * cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread` + * + * Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some + * bugs. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#define YES_IT_IS (1) +#define NO_IT_IS_NOT (0) + +typedef struct +{ + GtkWidget *label; + int what; +} yes_or_no_args; + +G_LOCK_DEFINE_STATIC (yes_or_no); +static volatile int yes_or_no = YES_IT_IS; + +void destroy(GtkWidget *widget, gpointer data) +{ + gtk_main_quit(); +} + +void *argument_thread(void *args) +{ + yes_or_no_args *data = (yes_or_no_args *)args; + gboolean say_something; + + for(;;) + { + /* sleep a while */ + sleep(rand() / (RAND_MAX / 3) + 1); + + /* lock the yes_or_no_variable */ + G_LOCK(yes_or_no); + + /* do we have to say something? */ + say_something = (yes_or_no != data->what); + + if(say_something) + { + /* set the variable */ + yes_or_no = data->what; + } + + /* Unlock the yes_or_no variable */ + G_UNLOCK(yes_or_no); + + if(say_something) + { + /* get GTK thread lock */ + gdk_threads_enter(); + + /* set label text */ + if(data->what == YES_IT_IS) + gtk_label_set_text(GTK_LABEL(data->label), "O yes, it is!"); + else + gtk_label_set_text(GTK_LABEL(data->label), "O no, it isn't!"); + + /* release GTK thread lock */ + gdk_threads_leave(); + } + } + + return(NULL); +} + +int main(int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *label; + yes_or_no_args yes_args, no_args; + pthread_t no_tid, yes_tid; + + /* init threads */ + g_thread_init(NULL); + + /* init gtk */ + gtk_init(&argc, &argv); + + /* init random number generator */ + srand((unsigned int)time(NULL)); + + /* create a window */ + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect(GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(destroy), NULL); + + gtk_container_set_border_width(GTK_CONTAINER (window), 10); + + /* create a label */ + label = gtk_label_new("And now for something completely different ..."); + gtk_container_add(GTK_CONTAINER(window), label); + + /* show everything */ + gtk_widget_show(label); + gtk_widget_show (window); + + /* create the threads */ + yes_args.label = label; + yes_args.what = YES_IT_IS; + pthread_create(&yes_tid, NULL, argument_thread, &yes_args); + + no_args.label = label; + no_args.what = NO_IT_IS_NOT; + pthread_create(&no_tid, NULL, argument_thread, &no_args); + + /* enter the GTK main loop */ + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + return(0); +} + + -Why do this strange 'x io error' occur when I Why does this strange 'x io error' occur when I This is not really a GTK+ problem, and the problem is not related to @@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f); gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f); + +How do I set the background color of a GtkLabel widget? +

+The Gtklabel widget is one of a few GTK+ widgets that don't create +their own window to render themselves into. Instead, they draw +themselves directly onto their parents window. + +This means that in order to set the background color for a GtkLabel +widget, you need to change the background color of its parent, +i.e. the object that you pack it into. + How do I set the color and font of a GtkLabel using a Resource File?

diff --git a/docs/gtk_tut.sgml b/docs/gtk_tut.sgml index a7d5a705d2..c03f8d9463 100644 --- a/docs/gtk_tut.sgml +++ b/docs/gtk_tut.sgml @@ -11,7 +11,7 @@ Tony Gale , Ian Main -April 10th, 1999 +November 13th, 1999 This is a tutorial on how to use GTK (the GIMP Toolkit) through its C interface. @@ -343,7 +343,7 @@ program "knows" what compiler switches are needed to compile programs that use GTK. gtk-config --libs will output the list of libraries for the compiler to link with and -the directories to find them in. In the aboce example they could have +the directories to find them in. In the above example they could have been combined into a single instance, such as - return (0; + return (0); Now, when we click the mouse button on a GTK button, the widget emits @@ -870,11 +870,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, @@ -1094,13 +1095,15 @@ it. Compile it yourself and play with it. /* example-start packbox packbox.c */ #include +#include #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 @@ -1558,11 +1561,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, @@ -1952,7 +1956,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); @@ -2182,11 +2185,12 @@ The following example creates a radio button group with three buttons. #include #include -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, @@ -4159,18 +4163,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; @@ -4362,11 +4372,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; @@ -4523,12 +4538,17 @@ Placement of the drawing area and the rulers is done using a table. #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 */ @@ -4654,7 +4674,8 @@ back off. GtkWidget *status_bar; -void push_item (GtkWidget *widget, gpointer data) +void push_item( GtkWidget *widget, + gpointer data ) { static int count = 1; char buff[20]; @@ -4665,13 +4686,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; @@ -4821,28 +4844,30 @@ The following code is an example of using an Entry widget. #include -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; @@ -5104,7 +5129,6 @@ void gtk_spin_button_set_update_policy( GtkSpinButton *spin_button, The possible values of +The combo widget makes a copy of the strings passed to it in the glist +structure. As a result, you need to make sure you free the memory used +by the list if that is appropriate for your application. + At this point you have a working combo box that has been set up. There are a few aspects of its behavior that you can change. These are accomplished with the functions: @@ -5655,7 +5683,8 @@ GtkWidget *drawingarea = NULL; /* Color changed handler */ -void color_changed_cb (GtkWidget *widget, GtkColorSelection *colorsel) +void color_changed_cb( GtkWidget *widget, + GtkColorSelection *colorsel ) { gdouble color[3]; GdkColor gdk_color; @@ -5691,7 +5720,9 @@ void color_changed_cb (GtkWidget *widget, GtkColorSelection *colorsel) /* Drawingarea event handler */ -gint area_event (GtkWidget *widget, GdkEvent *event, gpointer client_data) +gint area_event( GtkWidget *widget, + GdkEvent *event, + gpointer client_data ) { gint handled = FALSE; GtkWidget *colorsel; @@ -5728,14 +5759,18 @@ gint area_event (GtkWidget *widget, GdkEvent *event, gpointer client_data) /* Close down and exit handler */ -void destroy_window (GtkWidget *widget, gpointer client_data) +gint destroy_window( GtkWidget *widget, + GdkEvent *event, + gpointer client_data ) { gtk_main_quit (); + return(TRUE); } /* Main */ -gint main (gint argc, gchar *argv[]) +gint main( gint argc, + gchar *argv[] ) { GtkWidget *window; @@ -5753,9 +5788,6 @@ gint main (gint argc, gchar *argv[]) gtk_signal_connect (GTK_OBJECT(window), "delete_event", (GtkSignalFunc)destroy_window, (gpointer)window); - - gtk_signal_connect (GTK_OBJECT(window), "destroy", - (GtkSignalFunc)destroy_window, (gpointer)window); /* Create drawingarea, set size and catch button events */ @@ -5842,17 +5874,20 @@ screen, it does nothing as there is not a signal attached to it. #include /* 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; @@ -5931,8 +5966,8 @@ window reveals varying amounts of the label. #include -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *event_box; @@ -6367,8 +6402,8 @@ user resizes the top-level window. #include -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *aspect_frame; @@ -6473,8 +6508,7 @@ window. #include /* Create the list of "messages" */ -GtkWidget * -create_list (void) +GtkWidget *create_list( void ) { GtkWidget *scrolled_window; @@ -6514,8 +6548,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, @@ -6532,8 +6566,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; @@ -6570,8 +6603,8 @@ create_text (void) return table; } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *vpaned; @@ -6720,12 +6753,14 @@ new to you. #include -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; @@ -6887,12 +6922,12 @@ for Button Boxes. #include /* 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; @@ -7134,9 +7169,10 @@ additional explanations): /* This function is connected to the Close button or * closing the window from the WM */ -void delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) +gint delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) { gtk_main_quit (); + return(FALSE); } @@ -7597,13 +7633,15 @@ backward manner, and exit the program. #include /* 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; @@ -7617,7 +7655,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; @@ -7628,12 +7667,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; @@ -9102,7 +9145,8 @@ can see when they are emitted. #include /* 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; @@ -9118,8 +9162,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); @@ -9134,7 +9179,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; @@ -9157,7 +9202,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", @@ -9610,7 +9656,8 @@ int main( int argc, * 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) { @@ -9629,7 +9676,7 @@ 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); } @@ -9727,7 +9774,7 @@ void get_main_menu( GtkWidget *window, 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. */ @@ -10026,12 +10073,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; @@ -11116,13 +11165,13 @@ converted. #include -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; @@ -11136,9 +11185,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; @@ -11174,8 +11223,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; @@ -11219,27 +11268,24 @@ handlers that will be called when your selection is requested. For each selection/target pair you will handle, you make a call to: -void gtk_selection_add_handler( GtkWidget *widget, - GdkAtom selection, - GdkAtom target, - GtkSelectionFunction function, - GtkRemoveFunction remove_func, - gpointer data ); +void gtk_selection_add_target (GtkWidget *widget, + GdkAtom selection, + GdkAtom target, + guint info); -typedef void (*GtkSelectionFunction)( GtkWidget *widget, - GtkSelectionData *selection_data, - gpointer data ); - +void "selection_get" (GtkWidget *widget, + GtkSelectionData *selection_data, + guint info, + guint time); The GtkSelectionData is the same as above, but this time, we're @@ -11288,8 +11334,8 @@ string representation of the time is returned. #include /* 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) { @@ -11316,9 +11362,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); @@ -11327,15 +11373,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(&current_time)); /* When we return a single string, it should not be null terminated. That will be done for us */ @@ -11344,11 +11391,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; @@ -11375,9 +11421,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); @@ -13974,13 +14023,7 @@ needs to be updated. X will eventually generate an expose event to copy the relevant portions to the screen. We have now covered the entire drawing program except for a few -mundane details like creating the main window. The complete -source code is available from the location from which you got -this tutorial, or from: - - - +mundane details like creating the main window. Adding XInput support @@ -14297,13 +14340,7 @@ print_button_press (guint32 deviceid) } -That completes the changes to "XInputize" our program. As with -the first version, the complete source is available at the location -from which you got this tutorial, or from: - - - +That completes the changes to "XInputize" our program. Further sophistications

@@ -15862,15 +15899,15 @@ tictactoe_toggle (GtkWidget *widget, Tictactoe *ttt) #include #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; @@ -15972,6 +16009,7 @@ struct _GtkDial /* Current angle */ gfloat angle; + gfloat last_angle; /* Old values from adjustment stored so we know when something changes */ gfloat old_value; @@ -16139,8 +16177,7 @@ gtk_dial_new (GtkAdjustment *adjustment) dial = gtk_type_new (gtk_dial_get_type ()); if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, - 0.0, 0.0, 0.0); + adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); gtk_dial_set_adjustment (dial, adjustment); @@ -16192,8 +16229,7 @@ gtk_dial_set_adjustment (GtkDial *dial, if (dial->adjustment) { - gtk_signal_disconnect_by_data (GTK_OBJECT (dial->adjustment), - (gpointer) dial); + gtk_signal_disconnect_by_data (GTK_OBJECT (dial->adjustment), (gpointer) dial); gtk_object_unref (GTK_OBJECT (dial->adjustment)); } @@ -16241,9 +16277,7 @@ gtk_dial_realize (GtkWidget *widget) attributes.colormap = gtk_widget_get_colormap (widget); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - widget->window = gdk_window_new (widget->parent->window, - &attributes, - attributes_mask); + widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); @@ -16290,12 +16324,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); @@ -16306,37 +16342,22 @@ 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; - /* Draw ticks */ + upper = dial->adjustment->upper; + lower = dial->adjustment->lower; - for (i=0; i<25; i++) - { - theta = (i*M_PI/18. - M_PI/6.); - s = sin(theta); - c = cos(theta); - - tick_length = (i%6 == 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); - } - - /* Draw pointer */ - - s = sin(dial->angle); - c = cos(dial->angle); + /* 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; @@ -16344,14 +16365,90 @@ 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; + + 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 */ + + 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 = ((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%(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); + } + + /* 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; + 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; + gtk_draw_polygon (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - points, 3, + points, 5, TRUE); - + return FALSE; } @@ -16422,8 +16519,7 @@ gtk_dial_button_release (GtkWidget *widget, if ((dial->policy != GTK_UPDATE_CONTINUOUS) && (dial->old_value != dial->adjustment->value)) - gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), - "value_changed"); + gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); } return FALSE; @@ -16481,8 +16577,7 @@ gtk_dial_timer (GtkDial *dial) g_return_val_if_fail (GTK_IS_DIAL (dial), FALSE); if (dial->policy == GTK_UPDATE_DELAYED) - gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), - "value_changed"); + gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); return FALSE; } @@ -16518,8 +16613,7 @@ gtk_dial_update_mouse (GtkDial *dial, gint x, gint y) { if (dial->policy == GTK_UPDATE_CONTINUOUS) { - gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), - "value_changed"); + gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); } else { @@ -16560,8 +16654,7 @@ gtk_dial_update (GtkDial *dial) gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); } - dial->angle = 7.*M_PI/6. - (new_value - dial->adjustment->lower) * - 4.*M_PI/3. / + dial->angle = 7.*M_PI/6. - (new_value - dial->adjustment->lower) * 4.*M_PI/3. / (dial->adjustment->upper - dial->adjustment->lower); gtk_widget_draw (GTK_WIDGET(dial), NULL); @@ -16609,11 +16702,86 @@ gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment, } } /* example-end */ + + + + + dial_test.c +

+ +#include +#include "gtkdial.h" + +void value_changed( GtkAdjustment *adjustment, + GtkWidget *label ) +{ + char buffer[16]; + + sprintf(buffer,"%4.2f",adjustment->value); + gtk_label_set (GTK_LABEL (label), buffer); +} + +int main( int argc, + char *argv[]) +{ + GtkWidget *window; + GtkAdjustment *adjustment; + GtkWidget *dial; + GtkWidget *frame; + GtkWidget *vbox; + GtkWidget *label; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title (GTK_WINDOW (window), "Dial"); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_exit), NULL); + + gtk_container_border_width (GTK_CONTAINER (window), 10); + + vbox = gtk_vbox_new (FALSE, 5); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show(vbox); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (vbox), frame); + gtk_widget_show (frame); + + adjustment = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 100, 0.01, 0.1, 0)); + + dial = gtk_dial_new(adjustment); + gtk_dial_set_update_policy (GTK_DIAL(dial), GTK_UPDATE_DELAYED); + /* gtk_widget_set_usize (dial, 100, 100); */ + + gtk_container_add (GTK_CONTAINER (frame), dial); + gtk_widget_show (dial); + + label = gtk_label_new("0.00"); + gtk_box_pack_end (GTK_BOX(vbox), label, 0, 0, 0); + gtk_widget_show (label); + + gtk_signal_connect (GTK_OBJECT(adjustment), "value_changed", + GTK_SIGNAL_FUNC (value_changed), label); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} + Scribble

+ + scribble-simple.c +

/* example-start scribble-simple scribble-simple.c */ @@ -16642,8 +16810,8 @@ gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment, 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); @@ -16663,8 +16831,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)], @@ -16677,8 +16845,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; @@ -16694,8 +16863,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); @@ -16703,8 +16872,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; @@ -16724,14 +16893,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; @@ -16797,6 +16965,282 @@ main (int argc, char *argv[]) /* example-end */ + + scribble-xinput.c +

+ +/* 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 + +/* 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 */ + + List Widget @@ -17060,8 +17504,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; @@ -17274,7 +17718,7 @@ void sigh_button_event( GtkWidget *gtklist, * emits the "selection_changed" signal */ void sigh_print_selection( GtkWidget *gtklist, - gpointer func_data) + gpointer func_data ) { GList *dlist; diff --git a/docs/gtkfaq.sgml b/docs/gtkfaq.sgml index 3ed17164b6..6d8c35fa10 100644 --- a/docs/gtkfaq.sgml +++ b/docs/gtkfaq.sgml @@ -9,7 +9,7 @@ Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd -October 30th 1999 +November 9th 1999 This document is intended to answer questions that are likely to be frequently asked by programmers using GTK+ or people who are just looking at @@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal handler you do not need to call gdk_threads_enter(), but within the other types of callbacks, you do. +Erik Mouw contributed the following code example to illustrate how to +use threads within GTK+ programs. + + +/*------------------------------------------------------------------------- + * Filename: gtk-thread.c + * Version: 0.99.1 + * Copyright: Copyright (C) 1999, Erik Mouw + * Author: Erik Mouw + * Description: GTK threads example. + * Created at: Sun Oct 17 21:27:09 1999 + * Modified by: Erik Mouw + * Modified at: Sun Oct 24 17:21:41 1999 + *-----------------------------------------------------------------------*/ +/* + * Compile with: + * + * cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread` + * + * Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some + * bugs. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#define YES_IT_IS (1) +#define NO_IT_IS_NOT (0) + +typedef struct +{ + GtkWidget *label; + int what; +} yes_or_no_args; + +G_LOCK_DEFINE_STATIC (yes_or_no); +static volatile int yes_or_no = YES_IT_IS; + +void destroy(GtkWidget *widget, gpointer data) +{ + gtk_main_quit(); +} + +void *argument_thread(void *args) +{ + yes_or_no_args *data = (yes_or_no_args *)args; + gboolean say_something; + + for(;;) + { + /* sleep a while */ + sleep(rand() / (RAND_MAX / 3) + 1); + + /* lock the yes_or_no_variable */ + G_LOCK(yes_or_no); + + /* do we have to say something? */ + say_something = (yes_or_no != data->what); + + if(say_something) + { + /* set the variable */ + yes_or_no = data->what; + } + + /* Unlock the yes_or_no variable */ + G_UNLOCK(yes_or_no); + + if(say_something) + { + /* get GTK thread lock */ + gdk_threads_enter(); + + /* set label text */ + if(data->what == YES_IT_IS) + gtk_label_set_text(GTK_LABEL(data->label), "O yes, it is!"); + else + gtk_label_set_text(GTK_LABEL(data->label), "O no, it isn't!"); + + /* release GTK thread lock */ + gdk_threads_leave(); + } + } + + return(NULL); +} + +int main(int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *label; + yes_or_no_args yes_args, no_args; + pthread_t no_tid, yes_tid; + + /* init threads */ + g_thread_init(NULL); + + /* init gtk */ + gtk_init(&argc, &argv); + + /* init random number generator */ + srand((unsigned int)time(NULL)); + + /* create a window */ + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect(GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(destroy), NULL); + + gtk_container_set_border_width(GTK_CONTAINER (window), 10); + + /* create a label */ + label = gtk_label_new("And now for something completely different ..."); + gtk_container_add(GTK_CONTAINER(window), label); + + /* show everything */ + gtk_widget_show(label); + gtk_widget_show (window); + + /* create the threads */ + yes_args.label = label; + yes_args.what = YES_IT_IS; + pthread_create(&yes_tid, NULL, argument_thread, &yes_args); + + no_args.label = label; + no_args.what = NO_IT_IS_NOT; + pthread_create(&no_tid, NULL, argument_thread, &no_args); + + /* enter the GTK main loop */ + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + return(0); +} + + -Why do this strange 'x io error' occur when I Why does this strange 'x io error' occur when I This is not really a GTK+ problem, and the problem is not related to @@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f); gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f); + +How do I set the background color of a GtkLabel widget? +

+The Gtklabel widget is one of a few GTK+ widgets that don't create +their own window to render themselves into. Instead, they draw +themselves directly onto their parents window. + +This means that in order to set the background color for a GtkLabel +widget, you need to change the background color of its parent, +i.e. the object that you pack it into. + How do I set the color and font of a GtkLabel using a Resource File?

diff --git a/docs/tutorial/gtk_tut.sgml b/docs/tutorial/gtk_tut.sgml index a7d5a705d2..c03f8d9463 100644 --- a/docs/tutorial/gtk_tut.sgml +++ b/docs/tutorial/gtk_tut.sgml @@ -11,7 +11,7 @@ Tony Gale , Ian Main -April 10th, 1999 +November 13th, 1999 This is a tutorial on how to use GTK (the GIMP Toolkit) through its C interface. @@ -343,7 +343,7 @@ program "knows" what compiler switches are needed to compile programs that use GTK. gtk-config --libs will output the list of libraries for the compiler to link with and -the directories to find them in. In the aboce example they could have +the directories to find them in. In the above example they could have been combined into a single instance, such as - return (0; + return (0); Now, when we click the mouse button on a GTK button, the widget emits @@ -870,11 +870,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, @@ -1094,13 +1095,15 @@ it. Compile it yourself and play with it. /* example-start packbox packbox.c */ #include +#include #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 @@ -1558,11 +1561,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, @@ -1952,7 +1956,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); @@ -2182,11 +2185,12 @@ The following example creates a radio button group with three buttons. #include #include -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, @@ -4159,18 +4163,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; @@ -4362,11 +4372,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; @@ -4523,12 +4538,17 @@ Placement of the drawing area and the rulers is done using a table. #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 */ @@ -4654,7 +4674,8 @@ back off. GtkWidget *status_bar; -void push_item (GtkWidget *widget, gpointer data) +void push_item( GtkWidget *widget, + gpointer data ) { static int count = 1; char buff[20]; @@ -4665,13 +4686,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; @@ -4821,28 +4844,30 @@ The following code is an example of using an Entry widget. #include -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; @@ -5104,7 +5129,6 @@ void gtk_spin_button_set_update_policy( GtkSpinButton *spin_button, The possible values of +The combo widget makes a copy of the strings passed to it in the glist +structure. As a result, you need to make sure you free the memory used +by the list if that is appropriate for your application. + At this point you have a working combo box that has been set up. There are a few aspects of its behavior that you can change. These are accomplished with the functions: @@ -5655,7 +5683,8 @@ GtkWidget *drawingarea = NULL; /* Color changed handler */ -void color_changed_cb (GtkWidget *widget, GtkColorSelection *colorsel) +void color_changed_cb( GtkWidget *widget, + GtkColorSelection *colorsel ) { gdouble color[3]; GdkColor gdk_color; @@ -5691,7 +5720,9 @@ void color_changed_cb (GtkWidget *widget, GtkColorSelection *colorsel) /* Drawingarea event handler */ -gint area_event (GtkWidget *widget, GdkEvent *event, gpointer client_data) +gint area_event( GtkWidget *widget, + GdkEvent *event, + gpointer client_data ) { gint handled = FALSE; GtkWidget *colorsel; @@ -5728,14 +5759,18 @@ gint area_event (GtkWidget *widget, GdkEvent *event, gpointer client_data) /* Close down and exit handler */ -void destroy_window (GtkWidget *widget, gpointer client_data) +gint destroy_window( GtkWidget *widget, + GdkEvent *event, + gpointer client_data ) { gtk_main_quit (); + return(TRUE); } /* Main */ -gint main (gint argc, gchar *argv[]) +gint main( gint argc, + gchar *argv[] ) { GtkWidget *window; @@ -5753,9 +5788,6 @@ gint main (gint argc, gchar *argv[]) gtk_signal_connect (GTK_OBJECT(window), "delete_event", (GtkSignalFunc)destroy_window, (gpointer)window); - - gtk_signal_connect (GTK_OBJECT(window), "destroy", - (GtkSignalFunc)destroy_window, (gpointer)window); /* Create drawingarea, set size and catch button events */ @@ -5842,17 +5874,20 @@ screen, it does nothing as there is not a signal attached to it. #include /* 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; @@ -5931,8 +5966,8 @@ window reveals varying amounts of the label. #include -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *event_box; @@ -6367,8 +6402,8 @@ user resizes the top-level window. #include -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *aspect_frame; @@ -6473,8 +6508,7 @@ window. #include /* Create the list of "messages" */ -GtkWidget * -create_list (void) +GtkWidget *create_list( void ) { GtkWidget *scrolled_window; @@ -6514,8 +6548,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, @@ -6532,8 +6566,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; @@ -6570,8 +6603,8 @@ create_text (void) return table; } -int -main (int argc, char *argv[]) +int main( int argc, + char *argv[] ) { GtkWidget *window; GtkWidget *vpaned; @@ -6720,12 +6753,14 @@ new to you. #include -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; @@ -6887,12 +6922,12 @@ for Button Boxes. #include /* 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; @@ -7134,9 +7169,10 @@ additional explanations): /* This function is connected to the Close button or * closing the window from the WM */ -void delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) +gint delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) { gtk_main_quit (); + return(FALSE); } @@ -7597,13 +7633,15 @@ backward manner, and exit the program. #include /* 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; @@ -7617,7 +7655,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; @@ -7628,12 +7667,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; @@ -9102,7 +9145,8 @@ can see when they are emitted. #include /* 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; @@ -9118,8 +9162,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); @@ -9134,7 +9179,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; @@ -9157,7 +9202,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", @@ -9610,7 +9656,8 @@ int main( int argc, * 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) { @@ -9629,7 +9676,7 @@ 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); } @@ -9727,7 +9774,7 @@ void get_main_menu( GtkWidget *window, 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. */ @@ -10026,12 +10073,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; @@ -11116,13 +11165,13 @@ converted. #include -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; @@ -11136,9 +11185,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; @@ -11174,8 +11223,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; @@ -11219,27 +11268,24 @@ handlers that will be called when your selection is requested. For each selection/target pair you will handle, you make a call to: -void gtk_selection_add_handler( GtkWidget *widget, - GdkAtom selection, - GdkAtom target, - GtkSelectionFunction function, - GtkRemoveFunction remove_func, - gpointer data ); +void gtk_selection_add_target (GtkWidget *widget, + GdkAtom selection, + GdkAtom target, + guint info); -typedef void (*GtkSelectionFunction)( GtkWidget *widget, - GtkSelectionData *selection_data, - gpointer data ); - +void "selection_get" (GtkWidget *widget, + GtkSelectionData *selection_data, + guint info, + guint time); The GtkSelectionData is the same as above, but this time, we're @@ -11288,8 +11334,8 @@ string representation of the time is returned. #include /* 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) { @@ -11316,9 +11362,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); @@ -11327,15 +11373,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(&current_time)); /* When we return a single string, it should not be null terminated. That will be done for us */ @@ -11344,11 +11391,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; @@ -11375,9 +11421,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); @@ -13974,13 +14023,7 @@ needs to be updated. X will eventually generate an expose event to copy the relevant portions to the screen. We have now covered the entire drawing program except for a few -mundane details like creating the main window. The complete -source code is available from the location from which you got -this tutorial, or from: - - - +mundane details like creating the main window. Adding XInput support @@ -14297,13 +14340,7 @@ print_button_press (guint32 deviceid) } -That completes the changes to "XInputize" our program. As with -the first version, the complete source is available at the location -from which you got this tutorial, or from: - - - +That completes the changes to "XInputize" our program. Further sophistications

@@ -15862,15 +15899,15 @@ tictactoe_toggle (GtkWidget *widget, Tictactoe *ttt) #include #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; @@ -15972,6 +16009,7 @@ struct _GtkDial /* Current angle */ gfloat angle; + gfloat last_angle; /* Old values from adjustment stored so we know when something changes */ gfloat old_value; @@ -16139,8 +16177,7 @@ gtk_dial_new (GtkAdjustment *adjustment) dial = gtk_type_new (gtk_dial_get_type ()); if (!adjustment) - adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, - 0.0, 0.0, 0.0); + adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); gtk_dial_set_adjustment (dial, adjustment); @@ -16192,8 +16229,7 @@ gtk_dial_set_adjustment (GtkDial *dial, if (dial->adjustment) { - gtk_signal_disconnect_by_data (GTK_OBJECT (dial->adjustment), - (gpointer) dial); + gtk_signal_disconnect_by_data (GTK_OBJECT (dial->adjustment), (gpointer) dial); gtk_object_unref (GTK_OBJECT (dial->adjustment)); } @@ -16241,9 +16277,7 @@ gtk_dial_realize (GtkWidget *widget) attributes.colormap = gtk_widget_get_colormap (widget); attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - widget->window = gdk_window_new (widget->parent->window, - &attributes, - attributes_mask); + widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); @@ -16290,12 +16324,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); @@ -16306,37 +16342,22 @@ 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; - /* Draw ticks */ + upper = dial->adjustment->upper; + lower = dial->adjustment->lower; - for (i=0; i<25; i++) - { - theta = (i*M_PI/18. - M_PI/6.); - s = sin(theta); - c = cos(theta); - - tick_length = (i%6 == 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); - } - - /* Draw pointer */ - - s = sin(dial->angle); - c = cos(dial->angle); + /* 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; @@ -16344,14 +16365,90 @@ 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; + + 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 */ + + 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 = ((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%(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); + } + + /* 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; + 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; + gtk_draw_polygon (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - points, 3, + points, 5, TRUE); - + return FALSE; } @@ -16422,8 +16519,7 @@ gtk_dial_button_release (GtkWidget *widget, if ((dial->policy != GTK_UPDATE_CONTINUOUS) && (dial->old_value != dial->adjustment->value)) - gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), - "value_changed"); + gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); } return FALSE; @@ -16481,8 +16577,7 @@ gtk_dial_timer (GtkDial *dial) g_return_val_if_fail (GTK_IS_DIAL (dial), FALSE); if (dial->policy == GTK_UPDATE_DELAYED) - gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), - "value_changed"); + gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); return FALSE; } @@ -16518,8 +16613,7 @@ gtk_dial_update_mouse (GtkDial *dial, gint x, gint y) { if (dial->policy == GTK_UPDATE_CONTINUOUS) { - gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), - "value_changed"); + gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); } else { @@ -16560,8 +16654,7 @@ gtk_dial_update (GtkDial *dial) gtk_signal_emit_by_name (GTK_OBJECT (dial->adjustment), "value_changed"); } - dial->angle = 7.*M_PI/6. - (new_value - dial->adjustment->lower) * - 4.*M_PI/3. / + dial->angle = 7.*M_PI/6. - (new_value - dial->adjustment->lower) * 4.*M_PI/3. / (dial->adjustment->upper - dial->adjustment->lower); gtk_widget_draw (GTK_WIDGET(dial), NULL); @@ -16609,11 +16702,86 @@ gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment, } } /* example-end */ + + + + + dial_test.c +

+ +#include +#include "gtkdial.h" + +void value_changed( GtkAdjustment *adjustment, + GtkWidget *label ) +{ + char buffer[16]; + + sprintf(buffer,"%4.2f",adjustment->value); + gtk_label_set (GTK_LABEL (label), buffer); +} + +int main( int argc, + char *argv[]) +{ + GtkWidget *window; + GtkAdjustment *adjustment; + GtkWidget *dial; + GtkWidget *frame; + GtkWidget *vbox; + GtkWidget *label; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_window_set_title (GTK_WINDOW (window), "Dial"); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_exit), NULL); + + gtk_container_border_width (GTK_CONTAINER (window), 10); + + vbox = gtk_vbox_new (FALSE, 5); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show(vbox); + + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (vbox), frame); + gtk_widget_show (frame); + + adjustment = GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 100, 0.01, 0.1, 0)); + + dial = gtk_dial_new(adjustment); + gtk_dial_set_update_policy (GTK_DIAL(dial), GTK_UPDATE_DELAYED); + /* gtk_widget_set_usize (dial, 100, 100); */ + + gtk_container_add (GTK_CONTAINER (frame), dial); + gtk_widget_show (dial); + + label = gtk_label_new("0.00"); + gtk_box_pack_end (GTK_BOX(vbox), label, 0, 0, 0); + gtk_widget_show (label); + + gtk_signal_connect (GTK_OBJECT(adjustment), "value_changed", + GTK_SIGNAL_FUNC (value_changed), label); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} + Scribble

+ + scribble-simple.c +

/* example-start scribble-simple scribble-simple.c */ @@ -16642,8 +16810,8 @@ gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment, 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); @@ -16663,8 +16831,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)], @@ -16677,8 +16845,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; @@ -16694,8 +16863,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); @@ -16703,8 +16872,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; @@ -16724,14 +16893,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; @@ -16797,6 +16965,282 @@ main (int argc, char *argv[]) /* example-end */ + + scribble-xinput.c +

+ +/* 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 + +/* 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 */ + + List Widget @@ -17060,8 +17504,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; @@ -17274,7 +17718,7 @@ void sigh_button_event( GtkWidget *gtklist, * emits the "selection_changed" signal */ void sigh_print_selection( GtkWidget *gtklist, - gpointer func_data) + gpointer func_data ) { GList *dlist; 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 -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 /* 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 -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 -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 /* 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,22 @@ 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; - /* Draw ticks */ + upper = dial->adjustment->upper; + lower = dial->adjustment->lower; - for (i=0; i<25; i++) - { - theta = (i*M_PI/18. - M_PI/6.); - s = sin(theta); - c = cos(theta); - - tick_length = (i%6 == 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); - } - - /* Draw pointer */ - - s = sin(dial->angle); - c = cos(dial->angle); + /* 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; @@ -329,14 +316,90 @@ 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; + + 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 */ + + 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 = ((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%(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); + } + + /* 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; + 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; + 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 @@ -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 /* 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) { "" -> create a radio item -> path of a radio item to link against "" -> create a separator - "" -> create an item to hold sub items + "" -> create an item to hold sub items (optional) "" -> create a right justified branch */ static GtkItemFactoryEntry menu_items[] = { - {"/_File", NULL, NULL, 0, ""}, - {"/File/_New", "N", print_hello, 0, NULL}, - {"/File/_Open", "O", print_hello, 0, NULL}, - {"/File/_Save", "S", print_hello, 0, NULL}, - {"/File/Save _As", NULL, NULL, 0, NULL}, - {"/File/sep1", NULL, NULL, 0, ""}, - {"/File/Quit", "Q", gtk_main_quit, 0, NULL}, - {"/_Options", NULL, NULL, 0, ""}, - {"/Options/Test", NULL, NULL, 0, NULL}, - {"/_Help", NULL, NULL, 0, ""}, - {"/_Help/About", NULL, NULL, 0, NULL}, + { "/_File", NULL, NULL, 0, "" }, + { "/File/_New", "N", print_hello, 0, NULL }, + { "/File/_Open", "O", print_hello, 0, NULL }, + { "/File/_Save", "S", print_hello, 0, NULL }, + { "/File/Save _As", NULL, NULL, 0, NULL }, + { "/File/sep1", NULL, NULL, 0, "" }, + { "/File/Quit", "Q", gtk_main_quit, 0, NULL }, + { "/_Options", NULL, NULL, 0, "" }, + { "/Options/Test", NULL, NULL, 0, NULL }, + { "/_Help", NULL, NULL, 0, "" }, + { "/_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, "

", + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", 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, "
"); + *menubar = gtk_item_factory_get_widget (item_factory, "
"); } -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 /* 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 +#include #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 /* 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 #include -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 + +/* 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 -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 -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 /* 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 #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 /* 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;