1 /* This file extracted from the GTK tutorial. */
7 * the data passed to this function is printed to stdout */
8 void callback (GtkWidget *widget, gpointer *data)
10 g_print ("Hello again - %s was pressed\n", (char *) data);
13 /* this callback quits the program */
14 void delete_event (GtkWidget *widget, gpointer *data)
19 int main (int argc, char *argv[])
25 gtk_init (&argc, &argv);
27 /* create a new window */
28 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
30 /* set the window title */
31 gtk_window_set_title (GTK_WINDOW (window), "Table");
33 /* set a handler for delete_event that immediately
35 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
36 GTK_SIGNAL_FUNC (delete_event), NULL);
38 /* sets the border width of the window. */
39 gtk_container_border_width (GTK_CONTAINER (window), 20);
41 /* create a 2x2 table */
42 table = gtk_table_new (2, 2, TRUE);
44 /* put the table in the main window */
45 gtk_container_add (GTK_CONTAINER (window), table);
47 /* create first button */
48 button = gtk_button_new_with_label ("button 1");
50 /* when the button is clicked, we call the "callback" function
51 * with a pointer to "button 1" as it's argument */
52 gtk_signal_connect (GTK_OBJECT (button), "clicked",
53 GTK_SIGNAL_FUNC (callback), (gpointer) "button 1");
56 /* insert button 1 into the upper left quadrant of the table */
57 gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 1, 0, 1);
59 gtk_widget_show (button);
61 /* create second button */
63 button = gtk_button_new_with_label ("button 2");
65 /* when the button is clicked, we call the "callback" function
66 * with a pointer to "button 2" as it's argument */
67 gtk_signal_connect (GTK_OBJECT (button), "clicked",
68 GTK_SIGNAL_FUNC (callback), (gpointer) "button 2");
69 /* insert button 2 into the upper right quadrant of the table */
70 gtk_table_attach_defaults (GTK_TABLE(table), button, 1, 2, 0, 1);
72 gtk_widget_show (button);
74 /* create "Quit" button */
75 button = gtk_button_new_with_label ("Quit");
77 /* when the button is clicked, we call the "delete_event" function
78 * and the program exits */
79 gtk_signal_connect (GTK_OBJECT (button), "clicked",
80 GTK_SIGNAL_FUNC (delete_event), NULL);
82 /* insert the quit button into the both
83 * lower quadrants of the table */
84 gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 2, 1, 2);
86 gtk_widget_show (button);
88 gtk_widget_show (table);
89 gtk_widget_show (window);