1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
5
>Scrolled Windows</TITLE
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
TITLE="GTK+ 2.0 Tutorial"
11
HREF="book1.html"><LINK
13
TITLE="Container Widgets"
14
HREF="c1228.html"><LINK
17
HREF="x1354.html"><LINK
20
HREF="x1392.html"></HEAD
31
SUMMARY="Header navigation table"
40
>GTK+ 2.0 Tutorial</TH
50
><<< Previous</A
56
>Container Widgets</TD
64
>Next >>></A
76
NAME="SEC-SCROLLEDWINDOWS"
80
>Scrolled windows are used to create a scrollable area with another
81
widget inside it. You may insert any type of widget into a scrolled
82
window, and it will be accessible regardless of the size by using the
85
>The following function is used to create a new scrolled window.</P
93
CLASS="PROGRAMLISTING"
94
>GtkWidget *gtk_scrolled_window_new( GtkAdjustment *hadjustment,
95
GtkAdjustment *vadjustment );</PRE
100
>Where the first argument is the adjustment for the horizontal
101
direction, and the second, the adjustment for the vertical direction.
102
These are almost always set to NULL.</P
110
CLASS="PROGRAMLISTING"
111
>void gtk_scrolled_window_set_policy( GtkScrolledWindow *scrolled_window,
112
GtkPolicyType hscrollbar_policy,
113
GtkPolicyType vscrollbar_policy );</PRE
118
>This sets the policy to be used with respect to the scrollbars.
119
The first argument is the scrolled window you wish to change. The second
120
sets the policy for the horizontal scrollbar, and the third the policy for
121
the vertical scrollbar.</P
123
>The policy may be one of <TT
125
>GTK_POLICY_AUTOMATIC</TT
129
>GTK_POLICY_ALWAYS</TT
132
>GTK_POLICY_AUTOMATIC</TT
134
decide whether you need scrollbars, whereas <TT
136
>GTK_POLICY_ALWAYS</TT
138
will always leave the scrollbars there.</P
140
>You can then place your object into the scrolled window using the
141
following function.</P
149
CLASS="PROGRAMLISTING"
150
>void gtk_scrolled_window_add_with_viewport( GtkScrolledWindow *scrolled_window,
151
GtkWidget *child);</PRE
156
>Here is a simple example that packs a table with 100 toggle buttons
157
into a scrolled window. I've only commented on the parts that may be
161
CLASS="INLINEMEDIAOBJECT"
163
SRC="images/scrolledwin.png"></SPAN
172
CLASS="PROGRAMLISTING"
173
> #include <stdio.h>
174
#include <gtk/gtk.h>
176
static void destroy( GtkWidget *widget,
185
static GtkWidget *window;
186
GtkWidget *scrolled_window;
192
gtk_init (&argc, &argv);
194
/* Create a new dialog window for the scrolled window to be
196
window = gtk_dialog_new ();
197
g_signal_connect (G_OBJECT (window), "destroy",
198
G_CALLBACK (destroy), NULL);
199
gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
200
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
201
gtk_widget_set_size_request (window, 300, 300);
203
/* create a new scrolled window. */
204
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
206
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
208
/* the policy is one of GTK_POLICY AUTOMATIC, or GTK_POLICY_ALWAYS.
209
* GTK_POLICY_AUTOMATIC will automatically decide whether you need
210
* scrollbars, whereas GTK_POLICY_ALWAYS will always leave the scrollbars
211
* there. The first one is the horizontal scrollbar, the second,
213
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
214
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
215
/* The dialog window is created with a vbox packed into it. */
216
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window,
218
gtk_widget_show (scrolled_window);
220
/* create a table of 10 by 10 squares. */
221
table = gtk_table_new (10, 10, FALSE);
223
/* set the spacing to 10 on x and 10 on y */
224
gtk_table_set_row_spacings (GTK_TABLE (table), 10);
225
gtk_table_set_col_spacings (GTK_TABLE (table), 10);
227
/* pack the table into the scrolled window */
228
gtk_scrolled_window_add_with_viewport (
229
GTK_SCROLLED_WINDOW (scrolled_window), table);
230
gtk_widget_show (table);
232
/* this simply creates a grid of toggle buttons on the table
233
* to demonstrate the scrolled window. */
234
for (i = 0; i < 10; i++)
235
for (j = 0; j < 10; j++) {
236
sprintf (buffer, "button (%d,%d)\n", i, j);
237
button = gtk_toggle_button_new_with_label (buffer);
238
gtk_table_attach_defaults (GTK_TABLE (table), button,
240
gtk_widget_show (button);
243
/* Add a "close" button to the bottom of the dialog */
244
button = gtk_button_new_with_label ("close");
245
g_signal_connect_swapped (G_OBJECT (button), "clicked",
246
G_CALLBACK (gtk_widget_destroy),
249
/* this makes it so the button is the default. */
251
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
252
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, TRUE, TRUE, 0);
254
/* This grabs this button to be the default button. Simply hitting
255
* the "Enter" key will cause this button to activate. */
256
gtk_widget_grab_default (button);
257
gtk_widget_show (button);
259
gtk_widget_show (window);
269
>Try playing with resizing the window. You'll notice how the scrollbars
270
react. You may also wish to use the gtk_widget_set_size_request() call to set
271
the default size of the window or other widgets.</P
278
SUMMARY="Footer navigation table"
291
><<< Previous</A
309
>Next >>></A
b'\\ No newline at end of file'