]> Pileus Git - ~andy/gtk/blob - examples/table/table.c
Tue Mar 31 15:41:57 PST 1998 Shawn T. Amundson
[~andy/gtk] / examples / table / table.c
1 /* This file extracted from the GTK tutorial. */
2
3 /* table.c */
4 #include <gtk/gtk.h>
5
6 /* our callback.
7  * the data passed to this function is printed to stdout */
8 void callback (GtkWidget *widget, gpointer *data)
9 {
10     g_print ("Hello again - %s was pressed\n", (char *) data);
11 }
12
13 /* this callback quits the program */
14 void delete_event (GtkWidget *widget, gpointer *data)
15 {
16     gtk_main_quit ();
17 }
18
19 int main (int argc, char *argv[])
20 {
21     GtkWidget *window;
22     GtkWidget *button;
23     GtkWidget *table;
24
25     gtk_init (&argc, &argv);
26
27     /* create a new window */
28     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
29
30     /* set the window title */
31     gtk_window_set_title (GTK_WINDOW (window), "Table");
32
33     /* set a handler for delete_event that immediately
34      * exits GTK. */
35     gtk_signal_connect (GTK_OBJECT (window), "delete_event",
36                         GTK_SIGNAL_FUNC (delete_event), NULL);
37
38     /* sets the border width of the window. */
39     gtk_container_border_width (GTK_CONTAINER (window), 20);
40
41     /* create a 2x2 table */
42     table = gtk_table_new (2, 2, TRUE);
43
44     /* put the table in the main window */
45     gtk_container_add (GTK_CONTAINER (window), table);
46
47     /* create first button */
48     button = gtk_button_new_with_label ("button 1");
49
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");
54
55
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);
58
59     gtk_widget_show (button);
60
61     /* create second button */
62
63     button = gtk_button_new_with_label ("button 2");
64
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);
71
72     gtk_widget_show (button);
73
74     /* create "Quit" button */
75     button = gtk_button_new_with_label ("Quit");
76
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);
81
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);
85
86     gtk_widget_show (button);
87
88     gtk_widget_show (table);
89     gtk_widget_show (window);
90
91     gtk_main ();
92
93     return 0;
94 }