5 static void destroy( GtkWidget *widget,
14 static GtkWidget *window;
15 GtkWidget *scrolled_window;
21 gtk_init (&argc, &argv);
23 /* Create a new dialog window for the scrolled window to be
25 window = gtk_dialog_new ();
26 g_signal_connect (G_OBJECT (window), "destroy",
27 G_CALLBACK (destroy), NULL);
28 gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
29 gtk_container_set_border_width (GTK_CONTAINER (window), 0);
30 gtk_widget_set_size_request (window, 300, 300);
32 /* create a new scrolled window. */
33 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
35 gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
37 /* the policy is one of GTK_POLICY AUTOMATIC, or GTK_POLICY_ALWAYS.
38 * GTK_POLICY_AUTOMATIC will automatically decide whether you need
39 * scrollbars, whereas GTK_POLICY_ALWAYS will always leave the scrollbars
40 * there. The first one is the horizontal scrollbar, the second,
42 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
43 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
44 /* The dialog window is created with a vbox packed into it. */
45 gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window,
47 gtk_widget_show (scrolled_window);
49 /* create a table of 10 by 10 squares. */
50 table = gtk_table_new (10, 10, FALSE);
52 /* set the spacing to 10 on x and 10 on y */
53 gtk_table_set_row_spacings (GTK_TABLE (table), 10);
54 gtk_table_set_col_spacings (GTK_TABLE (table), 10);
56 /* pack the table into the scrolled window */
57 gtk_scrolled_window_add_with_viewport (
58 GTK_SCROLLED_WINDOW (scrolled_window), table);
59 gtk_widget_show (table);
61 /* this simply creates a grid of toggle buttons on the table
62 * to demonstrate the scrolled window. */
63 for (i = 0; i < 10; i++)
64 for (j = 0; j < 10; j++) {
65 sprintf (buffer, "button (%d,%d)\n", i, j);
66 button = gtk_toggle_button_new_with_label (buffer);
67 gtk_table_attach_defaults (GTK_TABLE (table), button,
69 gtk_widget_show (button);
72 /* Add a "close" button to the bottom of the dialog */
73 button = gtk_button_new_with_label ("close");
74 g_signal_connect_swapped (G_OBJECT (button), "clicked",
75 G_CALLBACK (gtk_widget_destroy),
78 /* this makes it so the button is the default. */
80 gtk_widget_set_can_default (button, TRUE);
81 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, TRUE, TRUE, 0);
83 /* This grabs this button to be the default button. Simply hitting
84 * the "Enter" key will cause this button to activate. */
85 gtk_widget_grab_default (button);
86 gtk_widget_show (button);
88 gtk_widget_show (window);