1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
5
>Table Packing Example</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
TITLE="GTK+ 2.0 Tutorial"
11
HREF="book1.html"><LINK
13
TITLE="Packing Widgets"
14
HREF="c355.html"><LINK
16
TITLE="Packing Using Tables"
17
HREF="x390.html"><LINK
19
TITLE="Widget Overview"
20
HREF="c451.html"></HEAD
31
SUMMARY="Header navigation table"
40
>GTK+ 2.0 Tutorial</TH
50
><<< Previous</A
64
>Next >>></A
76
NAME="SEC-TABLEPACKINGEXAMPLES"
77
>Table Packing Example</A
80
>Here we make a window with three buttons in a 2x2 table.
81
The first two buttons will be placed in the upper row.
82
A third, quit button, is placed in the lower row, spanning both columns.
83
Which means it should look something like this:</P
86
CLASS="INLINEMEDIAOBJECT"
88
SRC="images/table.png"></SPAN
91
>Here's the source code:</P
99
CLASS="PROGRAMLISTING"
100
> #include <gtk/gtk.h>
103
* The data passed to this function is printed to stdout */
104
static void callback( GtkWidget *widget,
107
g_print ("Hello again - %s was pressed\n", (char *) data);
110
/* This callback quits the program */
111
static gboolean delete_event( GtkWidget *widget,
126
gtk_init (&argc, &argv);
128
/* Create a new window */
129
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
131
/* Set the window title */
132
gtk_window_set_title (GTK_WINDOW (window), "Table");
134
/* Set a handler for delete_event that immediately
136
g_signal_connect (G_OBJECT (window), "delete_event",
137
G_CALLBACK (delete_event), NULL);
139
/* Sets the border width of the window. */
140
gtk_container_set_border_width (GTK_CONTAINER (window), 20);
142
/* Create a 2x2 table */
143
table = gtk_table_new (2, 2, TRUE);
145
/* Put the table in the main window */
146
gtk_container_add (GTK_CONTAINER (window), table);
148
/* Create first button */
149
button = gtk_button_new_with_label ("button 1");
151
/* When the button is clicked, we call the "callback" function
152
* with a pointer to "button 1" as its argument */
153
g_signal_connect (G_OBJECT (button), "clicked",
154
G_CALLBACK (callback), (gpointer) "button 1");
157
/* Insert button 1 into the upper left quadrant of the table */
158
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 0, 1);
160
gtk_widget_show (button);
162
/* Create second button */
164
button = gtk_button_new_with_label ("button 2");
166
/* When the button is clicked, we call the "callback" function
167
* with a pointer to "button 2" as its argument */
168
g_signal_connect (G_OBJECT (button), "clicked",
169
G_CALLBACK (callback), (gpointer) "button 2");
170
/* Insert button 2 into the upper right quadrant of the table */
171
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 0, 1);
173
gtk_widget_show (button);
175
/* Create "Quit" button */
176
button = gtk_button_new_with_label ("Quit");
178
/* When the button is clicked, we call the "delete_event" function
179
* and the program exits */
180
g_signal_connect (G_OBJECT (button), "clicked",
181
G_CALLBACK (delete_event), NULL);
183
/* Insert the quit button into the both
184
* lower quadrants of the table */
185
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 1, 2);
187
gtk_widget_show (button);
189
gtk_widget_show (table);
190
gtk_widget_show (window);
205
SUMMARY="Footer navigation table"
218
><<< Previous</A
236
>Next >>></A
244
>Packing Using Tables</TD
b'\\ No newline at end of file'