~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to examples/packbox/packbox.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdio.h>
 
3
#include <stdlib.h>
 
4
#include "gtk/gtk.h"
 
5
 
 
6
static gboolean delete_event( GtkWidget *widget,
 
7
                              GdkEvent  *event,
 
8
                              gpointer   data )
 
9
{
 
10
    gtk_main_quit ();
 
11
    return FALSE;
 
12
}
 
13
 
 
14
/* Make a new hbox filled with button-labels. Arguments for the 
 
15
 * variables we're interested are passed in to this function. 
 
16
 * We do not show the box, but do show everything inside. */
 
17
static GtkWidget *make_box( gboolean homogeneous,
 
18
                            gint     spacing,
 
19
                            gboolean expand,
 
20
                            gboolean fill,
 
21
                            guint    padding ) 
 
22
{
 
23
    GtkWidget *box;
 
24
    GtkWidget *button;
 
25
    char padstr[80];
 
26
    
 
27
    /* Create a new hbox with the appropriate homogeneous
 
28
     * and spacing settings */
 
29
    box = gtk_hbox_new (homogeneous, spacing);
 
30
    
 
31
    /* Create a series of buttons with the appropriate settings */
 
32
    button = gtk_button_new_with_label ("gtk_box_pack");
 
33
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
 
34
    gtk_widget_show (button);
 
35
    
 
36
    button = gtk_button_new_with_label ("(box,");
 
37
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
 
38
    gtk_widget_show (button);
 
39
    
 
40
    button = gtk_button_new_with_label ("button,");
 
41
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
 
42
    gtk_widget_show (button);
 
43
    
 
44
    /* Create a button with the label depending on the value of
 
45
     * expand. */
 
46
    if (expand == TRUE)
 
47
            button = gtk_button_new_with_label ("TRUE,");
 
48
    else
 
49
            button = gtk_button_new_with_label ("FALSE,");
 
50
    
 
51
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
 
52
    gtk_widget_show (button);
 
53
    
 
54
    /* This is the same as the button creation for "expand"
 
55
     * above, but uses the shorthand form. */
 
56
    button = gtk_button_new_with_label (fill ? "TRUE," : "FALSE,");
 
57
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
 
58
    gtk_widget_show (button);
 
59
    
 
60
    sprintf (padstr, "%d);", padding);
 
61
    
 
62
    button = gtk_button_new_with_label (padstr);
 
63
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
 
64
    gtk_widget_show (button);
 
65
    
 
66
    return box;
 
67
}
 
68
 
 
69
int main( int   argc,
 
70
          char *argv[]) 
 
71
{
 
72
    GtkWidget *window;
 
73
    GtkWidget *button;
 
74
    GtkWidget *box1;
 
75
    GtkWidget *box2;
 
76
    GtkWidget *separator;
 
77
    GtkWidget *label;
 
78
    GtkWidget *quitbox;
 
79
    int which;
 
80
    
 
81
    /* Our init, don't forget this! :) */
 
82
    gtk_init (&argc, &argv);
 
83
    
 
84
    if (argc != 2) {
 
85
        fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n");
 
86
        /* This just does cleanup in GTK and exits with an exit status of 1. */
 
87
        exit (1);
 
88
    }
 
89
    
 
90
    which = atoi (argv[1]);
 
91
 
 
92
    /* Create our window */
 
93
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
94
 
 
95
    /* You should always remember to connect the delete_event signal
 
96
     * to the main window. This is very important for proper intuitive
 
97
     * behavior */
 
98
    g_signal_connect (G_OBJECT (window), "delete_event",
 
99
                      G_CALLBACK (delete_event), NULL);
 
100
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
 
101
    
 
102
    /* We create a vertical box (vbox) to pack the horizontal boxes into.
 
103
     * This allows us to stack the horizontal boxes filled with buttons one
 
104
     * on top of the other in this vbox. */
 
105
    box1 = gtk_vbox_new (FALSE, 0);
 
106
    
 
107
    /* which example to show. These correspond to the pictures above. */
 
108
    switch (which) {
 
109
    case 1:
 
110
        /* create a new label. */
 
111
        label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
 
112
        
 
113
        /* Align the label to the left side.  We'll discuss this function and 
 
114
         * others in the section on Widget Attributes. */
 
115
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
116
 
 
117
        /* Pack the label into the vertical box (vbox box1).  Remember that 
 
118
         * widgets added to a vbox will be packed one on top of the other in
 
119
         * order. */
 
120
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
 
121
        
 
122
        /* Show the label */
 
123
        gtk_widget_show (label);
 
124
        
 
125
        /* Call our make box function - homogeneous = FALSE, spacing = 0,
 
126
         * expand = FALSE, fill = FALSE, padding = 0 */
 
127
        box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
 
128
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
129
        gtk_widget_show (box2);
 
130
 
 
131
        /* Call our make box function - homogeneous = FALSE, spacing = 0,
 
132
         * expand = TRUE, fill = FALSE, padding = 0 */
 
133
        box2 = make_box (FALSE, 0, TRUE, FALSE, 0);
 
134
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
135
        gtk_widget_show (box2);
 
136
        
 
137
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
138
        box2 = make_box (FALSE, 0, TRUE, TRUE, 0);
 
139
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
140
        gtk_widget_show (box2);
 
141
        
 
142
        /* Creates a separator, we'll learn more about these later, 
 
143
         * but they are quite simple. */
 
144
        separator = gtk_hseparator_new ();
 
145
        
 
146
        /* Pack the separator into the vbox. Remember each of these
 
147
         * widgets is being packed into a vbox, so they'll be stacked
 
148
         * vertically. */
 
149
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
 
150
        gtk_widget_show (separator);
 
151
        
 
152
        /* Create another new label, and show it. */
 
153
        label = gtk_label_new ("gtk_hbox_new (TRUE, 0);");
 
154
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
155
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
 
156
        gtk_widget_show (label);
 
157
        
 
158
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
159
        box2 = make_box (TRUE, 0, TRUE, FALSE, 0);
 
160
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
161
        gtk_widget_show (box2);
 
162
        
 
163
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
164
        box2 = make_box (TRUE, 0, TRUE, TRUE, 0);
 
165
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
166
        gtk_widget_show (box2);
 
167
        
 
168
        /* Another new separator. */
 
169
        separator = gtk_hseparator_new ();
 
170
        /* The last 3 arguments to gtk_box_pack_start are:
 
171
         * expand, fill, padding. */
 
172
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
 
173
        gtk_widget_show (separator);
 
174
        
 
175
        break;
 
176
 
 
177
    case 2:
 
178
 
 
179
        /* Create a new label, remember box1 is a vbox as created 
 
180
         * near the beginning of main() */
 
181
        label = gtk_label_new ("gtk_hbox_new (FALSE, 10);");
 
182
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
183
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
 
184
        gtk_widget_show (label);
 
185
        
 
186
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
187
        box2 = make_box (FALSE, 10, TRUE, FALSE, 0);
 
188
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
189
        gtk_widget_show (box2);
 
190
        
 
191
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
192
        box2 = make_box (FALSE, 10, TRUE, TRUE, 0);
 
193
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
194
        gtk_widget_show (box2);
 
195
        
 
196
        separator = gtk_hseparator_new ();
 
197
        /* The last 3 arguments to gtk_box_pack_start are:
 
198
         * expand, fill, padding. */
 
199
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
 
200
        gtk_widget_show (separator);
 
201
        
 
202
        label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
 
203
        gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
 
204
        gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
 
205
        gtk_widget_show (label);
 
206
        
 
207
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
208
        box2 = make_box (FALSE, 0, TRUE, FALSE, 10);
 
209
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
210
        gtk_widget_show (box2);
 
211
        
 
212
        /* Args are: homogeneous, spacing, expand, fill, padding */
 
213
        box2 = make_box (FALSE, 0, TRUE, TRUE, 10);
 
214
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
215
        gtk_widget_show (box2);
 
216
        
 
217
        separator = gtk_hseparator_new ();
 
218
        /* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */
 
219
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
 
220
        gtk_widget_show (separator);
 
221
        break;
 
222
    
 
223
    case 3:
 
224
 
 
225
        /* This demonstrates the ability to use gtk_box_pack_end() to
 
226
         * right justify widgets. First, we create a new box as before. */
 
227
        box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
 
228
 
 
229
        /* Create the label that will be put at the end. */
 
230
        label = gtk_label_new ("end");
 
231
        /* Pack it using gtk_box_pack_end(), so it is put on the right
 
232
         * side of the hbox created in the make_box() call. */
 
233
        gtk_box_pack_end (GTK_BOX (box2), label, FALSE, FALSE, 0);
 
234
        /* Show the label. */
 
235
        gtk_widget_show (label);
 
236
        
 
237
        /* Pack box2 into box1 (the vbox remember ? :) */
 
238
        gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
 
239
        gtk_widget_show (box2);
 
240
        
 
241
        /* A separator for the bottom. */
 
242
        separator = gtk_hseparator_new ();
 
243
        /* This explicitly sets the separator to 400 pixels wide by 5 pixels
 
244
         * high. This is so the hbox we created will also be 400 pixels wide,
 
245
         * and the "end" label will be separated from the other labels in the
 
246
         * hbox. Otherwise, all the widgets in the hbox would be packed as
 
247
         * close together as possible. */
 
248
        gtk_widget_set_size_request (separator, 400, 5);
 
249
        /* pack the separator into the vbox (box1) created near the start 
 
250
         * of main() */
 
251
        gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
 
252
        gtk_widget_show (separator);    
 
253
    }
 
254
    
 
255
    /* Create another new hbox.. remember we can use as many as we need! */
 
256
    quitbox = gtk_hbox_new (FALSE, 0);
 
257
    
 
258
    /* Our quit button. */
 
259
    button = gtk_button_new_with_label ("Quit");
 
260
    
 
261
    /* Setup the signal to terminate the program when the button is clicked */
 
262
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
 
263
                              G_CALLBACK (gtk_main_quit),
 
264
                              G_OBJECT (window));
 
265
    /* Pack the button into the quitbox.
 
266
     * The last 3 arguments to gtk_box_pack_start are:
 
267
     * expand, fill, padding. */
 
268
    gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
 
269
    /* pack the quitbox into the vbox (box1) */
 
270
    gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);
 
271
    
 
272
    /* Pack the vbox (box1) which now contains all our widgets, into the
 
273
     * main window. */
 
274
    gtk_container_add (GTK_CONTAINER (window), box1);
 
275
    
 
276
    /* And show everything left */
 
277
    gtk_widget_show (button);
 
278
    gtk_widget_show (quitbox);
 
279
    
 
280
    gtk_widget_show (box1);
 
281
    /* Showing the window last so everything pops up at once. */
 
282
    gtk_widget_show (window);
 
283
    
 
284
    /* And of course, our main function. */
 
285
    gtk_main ();
 
286
 
 
287
    /* Control returns here when gtk_main_quit() is called, but not when 
 
288
     * exit() is used. */
 
289
    
 
290
    return 0;
 
291
}