From: BST 2000 Tony Gale Date: Mon, 17 Jul 2000 17:21:13 +0000 (+0000) Subject: Clean ups. X-Git-Url: http://pileus.org/git/?a=commitdiff_plain;h=2465ad85f9d97f15841b7d22a87fe08afc19a815;p=~andy%2Fgtk Clean ups. Mon Jul 17 18:19:06 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Clean ups. --- diff --git a/ChangeLog b/ChangeLog index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5b4b34bef..3d8cb6b04 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,4 +1,8 @@ -Mon Jul 17 13:59:29 BST 2000 Tony Gale +Mon Jul 17 18:19:06 BST 2000 Tony Gale + + * docs/tutorial/gtk-tut.sgml: Clean ups. + +Mon Jul 17 13:59:29 BST 2000 Tony Gale * docs/tutorial/gtk-tut.sgml: Initial DocBook version. Lots of cleaning up to do. diff --git a/docs/tutorial/gtk-tut.sgml b/docs/tutorial/gtk-tut.sgml index 0fa1ebe87..7f776f689 100755 --- a/docs/tutorial/gtk-tut.sgml +++ b/docs/tutorial/gtk-tut.sgml @@ -1,8 +1,8 @@ - + - July 15th 2000 + July 17th 2000 GTK+ 1.2 Tutorial @@ -165,9 +165,9 @@ application. The next line: - -gtk_init (&argc, &argv); - + +gtk_init (&argc, &argv); + calls the function gtk_init(gint *argc, gchar ***argv) which will be called in all GTK applications. This sets up a few things for us such @@ -208,10 +208,10 @@ of standard arguments accepted by all GTK applications. The next two lines of code create and display a window. - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_widget_show (window); - + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_show (window); + The GTK_WINDOW_TOPLEVEL argument specifies that we want the window to undergo window manager decoration and placement. Rather than @@ -223,9 +223,9 @@ the attributes of this widget, and that it can display it. The last line enters the GTK main processing loop. - - gtk_main (); - + + gtk_main (); + gtk_main() is another call you will see in every GTK application. When control reaches this point, GTK will sleep waiting for X events @@ -424,12 +424,12 @@ button. catch these signals and call the appropriate function. This is done by using a function such as: - -gint gtk_signal_connect( GtkObject *object, + +gint gtk_signal_connect( GtkObject *object, gchar *name, GtkSignalFunc func, - gpointer func_data ); - + gpointer func_data ); + where the first argument is the widget which will be emitting the signal, and the second the name of the signal you wish to catch. The @@ -439,10 +439,10 @@ fourth, the data you wish to have passed to this function. The function specified in the third argument is called a "callback function", and should generally be of the form - -void callback_func( GtkWidget *widget, - gpointer callback_data ); - + +void callback_func( GtkWidget *widget, + gpointer callback_data ); + where the first argument will be a pointer to the widget that emitted the signal, and the second a pointer to the data given as the last @@ -455,21 +455,21 @@ signal provides both row and column parameters. Another call used in the helloworld example, is: - -gint gtk_signal_connect_object( GtkObject *object, + +gint gtk_signal_connect_object( GtkObject *object, gchar *name, GtkSignalFunc func, - GtkObject *slot_object ); - + GtkObject *slot_object ); + gtk_signal_connect_object() is the same as gtk_signal_connect() except that the callback function only uses one argument, a pointer to a GTK object. So when using this function to connect signals, the callback should be of the form - -void callback_func( GtkObject *object ); - + +void callback_func( GtkObject *object ); + where the object is usually a widget. We usually don't setup callbacks for gtk_signal_connect_object however. They are usually used to call a @@ -560,11 +560,11 @@ the above event names as the name parameter. The callback function for events has a slightly different form than that for signals: - -void callback_func( GtkWidget *widget, + +void callback_func( GtkWidget *widget, GdkEvent *event, - gpointer callback_data ); - + gpointer callback_data ); + GdkEvent is a C union structure whose type will depend upon which of the above events has occurred. In order for us to tell which event @@ -611,22 +611,22 @@ event. Possible values for the type are: So, to connect a callback function to one of these events we would use something like: - -gtk_signal_connect( GTK_OBJECT(button), "button_press_event", + +gtk_signal_connect( GTK_OBJECT(button), "button_press_event", GTK_SIGNAL_FUNC(button_press_callback), - NULL); - + NULL); + This assumes that button is a Button widget. Now, when the mouse is over the button and a mouse button is pressed, the function button_press_callback will be called. This function may be declared as: - -static gint button_press_callback( GtkWidget *widget, + +static gint button_press_callback( GtkWidget *widget, GdkEventButton *event, - gpointer data ); - + gpointer data ); + Note that we can declare the second argument as type GdkEventButton as we know what type of event will occur for this @@ -1123,12 +1123,16 @@ first. There are a lot of options, and it's not immediately obvious how they all fit together. In the end, however, there are basically five different styles. - > - -> - > + + + + + + + + + + Each line contains one horizontal box (hbox) with several buttons. The call to gtk_box_pack is shorthand for the call to pack each of the @@ -1137,13 +1141,13 @@ same way (i.e., same arguments to the gtk_box_pack_start() function). This is the declaration of the gtk_box_pack_start function. - -void gtk_box_pack_start( GtkBox *box, + +void gtk_box_pack_start( GtkBox *box, GtkWidget *child, gint expand, gint fill, - gint padding ); - + gint padding ); + The first argument is the box you are packing the object into, the second is the object. The objects will all be buttons for now, so @@ -1165,10 +1169,10 @@ if the expand argument is also TRUE. When creating a new box, the function looks like this: - -GtkWidget *gtk_hbox_new (gint homogeneous, - gint spacing); - + +GtkWidget *gtk_hbox_new (gint homogeneous, + gint spacing); + The homogeneous argument to gtk_hbox_new (and the same for gtk_vbox_new) controls whether each object in the box has the same @@ -1181,13 +1185,16 @@ and padding (set when elements are packed)? Spacing is added between objects, and padding is added on either side of an object. The following figure should make it clearer: - > - -> - > + + + + + + + + + + Here is the code used to create the above images. I've commented it fairly heavily so I hope you won't have any problems following @@ -1509,11 +1516,11 @@ widgets may take up as many spaces as we specify. The first thing to look at, of course, is the gtk_table_new function: - -GtkWidget *gtk_table_new( gint rows, + +GtkWidget *gtk_table_new( gint rows, gint columns, - gint homogeneous ); - + gint homogeneous ); + The first argument is the number of rows to make in the table, while the second, obviously, is the number of columns. @@ -1594,14 +1601,14 @@ specified in pixels. gtk_table_attach() has a LOT of options. So, there's a shortcut: - -void gtk_table_attach_defaults( GtkTable *table, + +void gtk_table_attach_defaults( GtkTable *table, GtkWidget *widget, gint left_attach, gint right_attach, gint top_attach, - gint bottom_attach ); - + gint bottom_attach ); + The X and Y options default to GTK_FILL | GTK_EXPAND, and X and Y padding are set to 0. The rest of the arguments are identical to the @@ -1611,36 +1618,36 @@ previous function. gtk_table_set_col_spacing(). These places spacing between the rows at the specified row or column. - -void gtk_table_set_row_spacing( GtkTable *table, + +void gtk_table_set_row_spacing( GtkTable *table, gint row, - gint spacing ); - + gint spacing ); + and - -void gtk_table_set_col_spacing ( GtkTable *table, + +void gtk_table_set_col_spacing ( GtkTable *table, gint column, - gint spacing ); - + gint spacing ); + Note that for columns, the space goes to the right of the column, and for rows, the space goes below the row. You can also set a consistent spacing of all rows and/or columns with: - -void gtk_table_set_row_spacings( GtkTable *table, - gint spacing ); - + +void gtk_table_set_row_spacings( GtkTable *table, + gint spacing ); + And, - -void gtk_table_set_col_spacings( GtkTable *table, - gint spacing ); - + +void gtk_table_set_col_spacings( GtkTable *table, + gint spacing ); + Note that with these calls, the last row and last column do not get any spacing. @@ -1656,12 +1663,16 @@ The first two buttons will be placed in the upper row. A third, quit button, is placed in the lower row, spanning both columns. Which means it should look something like this: - > - -> - > + + + + + + + + + + Here's the source code: @@ -1859,8 +1870,8 @@ learn how a widget works just by looking at the function declarations. For your reference, here is the class hierarchy tree used to implement widgets. - - GtkObject + + GtkObject +GtkWidget | +GtkMisc | | +GtkLabel @@ -1952,8 +1963,8 @@ learn how a widget works just by looking at the function declarations. +GtkData | +GtkAdjustment | `GtkTooltips - `GtkItemFactory - + `GtkItemFactory + @@ -1965,8 +1976,8 @@ learn how a widget works just by looking at the function declarations. capture events, you'll have to use the EventBox. See the section on the EventBox widget. - -GtkAlignment + +GtkAlignment GtkArrow GtkBin GtkBox @@ -1982,8 +1993,8 @@ GtkFrame GtkVBox GtkHBox GtkVSeparator -GtkHSeparator - +GtkHSeparator + We'll further our exploration of GTK by examining each widget in turn, creating a few simple functions to display them. Another good source @@ -2202,8 +2213,8 @@ the "toggled" signal. To check the state of these buttons, set up a signal handler to catch the toggled signal, and access the structure to determine its state. The callback will look something like: - -void toggle_button_callback (GtkWidget *widget, gpointer data) + +void toggle_button_callback (GtkWidget *widget, gpointer data) { if (GTK_TOGGLE_BUTTON (widget)->active) { @@ -2213,16 +2224,16 @@ to determine its state. The callback will look something like: /* If control reaches here, the toggle button is up */ } -} - +} + To force the state of a toggle button, and its children, the radio and check buttons, use this function: - -void gtk_toggle_button_set_active( GtkToggleButton *toggle_button, - gint state ); - + +void gtk_toggle_button_set_active( GtkToggleButton *toggle_button, + gint state ); + The above call can be used to set the state of the toggle button, and its children the radio and check buttons. Passing in your created @@ -2234,9 +2245,9 @@ argument to specify whether it should be down (depressed) or up the state is actually changed, it causes the "clicked" signal to be emitted from the button. - -void gtk_toggle_button_toggled (GtkToggleButton *toggle_button); - + +void gtk_toggle_button_toggled (GtkToggleButton *toggle_button); + This simply toggles the button, and emits the "toggled" signal. @@ -2254,11 +2265,11 @@ off in applications. The two creation functions are similar to those of the normal button. - -GtkWidget *gtk_check_button_new( void ); + +GtkWidget *gtk_check_button_new( void ); -GtkWidget *gtk_check_button_new_with_label ( gchar *label ); - +GtkWidget *gtk_check_button_new_with_label ( gchar *label ); + The new_with_label function creates a check button with a label beside it. @@ -2269,7 +2280,8 @@ toggle button. - Radio Buttons