1998-03-31 23:43:49 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
#include <stdio.h>
|
1998-03-31 23:43:49 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-01-03 19:26:36 +00:00
|
|
|
static void destroy( GtkWidget *widget,
|
|
|
|
gpointer data )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
2002-02-19 01:25:26 +00:00
|
|
|
gtk_main_quit ();
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] )
|
1998-03-31 23:43:49 +00:00
|
|
|
{
|
|
|
|
static GtkWidget *window;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *button;
|
|
|
|
char buffer[32];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
/* Create a new dialog window for the scrolled window to be
|
1999-11-13 23:06:46 +00:00
|
|
|
* packed into. */
|
1998-03-31 23:43:49 +00:00
|
|
|
window = gtk_dialog_new ();
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect (G_OBJECT (window), "destroy",
|
|
|
|
G_CALLBACK (destroy), NULL);
|
1998-12-13 22:25:07 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (window, 300, 300);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
/* create a new scrolled window. */
|
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
|
1999-01-28 10:35:40 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
/* the policy is one of GTK_POLICY AUTOMATIC, or GTK_POLICY_ALWAYS.
|
|
|
|
* GTK_POLICY_AUTOMATIC will automatically decide whether you need
|
1998-12-10 17:31:04 +00:00
|
|
|
* scrollbars, whereas GTK_POLICY_ALWAYS will always leave the scrollbars
|
1998-03-31 23:43:49 +00:00
|
|
|
* there. The first one is the horizontal scrollbar, the second,
|
|
|
|
* the vertical. */
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
|
|
|
|
/* The dialog window is created with a vbox packed into it. */
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window,
|
|
|
|
TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
|
|
|
|
/* create a table of 10 by 10 squares. */
|
|
|
|
table = gtk_table_new (10, 10, FALSE);
|
|
|
|
|
|
|
|
/* set the spacing to 10 on x and 10 on y */
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 10);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
|
|
|
|
|
|
|
|
/* pack the table into the scrolled window */
|
1999-11-13 23:06:46 +00:00
|
|
|
gtk_scrolled_window_add_with_viewport (
|
|
|
|
GTK_SCROLLED_WINDOW (scrolled_window), table);
|
1998-03-31 23:43:49 +00:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
/* this simply creates a grid of toggle buttons on the table
|
|
|
|
* to demonstrate the scrolled window. */
|
|
|
|
for (i = 0; i < 10; i++)
|
1998-12-10 17:31:04 +00:00
|
|
|
for (j = 0; j < 10; j++) {
|
|
|
|
sprintf (buffer, "button (%d,%d)\n", i, j);
|
|
|
|
button = gtk_toggle_button_new_with_label (buffer);
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), button,
|
|
|
|
i, i+1, j, j+1);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
}
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
/* Add a "close" button to the bottom of the dialog */
|
|
|
|
button = gtk_button_new_with_label ("close");
|
2002-02-19 19:47:16 +00:00
|
|
|
g_signal_connect_swapped (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
2002-08-25 11:28:42 +00:00
|
|
|
G_OBJECT (window));
|
1998-03-31 23:43:49 +00:00
|
|
|
|
|
|
|
/* this makes it so the button is the default. */
|
|
|
|
|
|
|
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
/* This grabs this button to be the default button. Simply hitting
|
|
|
|
* the "Enter" key will cause this button to activate. */
|
|
|
|
gtk_widget_grab_default (button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
gtk_widget_show (window);
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return 0;
|
1998-03-31 23:43:49 +00:00
|
|
|
}
|