1 | /* GTK - The GIMP Toolkit |
---|
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
3 | * |
---|
4 | * This library is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU Library General Public |
---|
6 | * License as published by the Free Software Foundation; either |
---|
7 | * version 2 of the License, or (at your option) any later version. |
---|
8 | * |
---|
9 | * This library is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | * Library General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU Library General Public |
---|
15 | * License along with this library; if not, write to the |
---|
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
17 | * Boston, MA 02111-1307, USA. |
---|
18 | */ |
---|
19 | |
---|
20 | /* |
---|
21 | * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS |
---|
22 | * file for a list of people on the GTK+ Team. See the ChangeLog |
---|
23 | * files for a list of changes. These files are distributed with |
---|
24 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
---|
25 | */ |
---|
26 | |
---|
27 | #undef G_LOG_DOMAIN |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | #include <stdlib.h> |
---|
31 | #include <string.h> |
---|
32 | #include <math.h> |
---|
33 | #include <sys/stat.h> |
---|
34 | #include <time.h> |
---|
35 | #include <unistd.h> |
---|
36 | #include "gtk.h" |
---|
37 | #include "../gdk/gdk.h" |
---|
38 | #include "../gdk/gdkx.h" |
---|
39 | #include "../gdk/gdkkeysyms.h" |
---|
40 | |
---|
41 | #include "circles.xbm" |
---|
42 | |
---|
43 | typedef struct _OptionMenuItem |
---|
44 | { |
---|
45 | gchar *name; |
---|
46 | GtkSignalFunc func; |
---|
47 | } OptionMenuItem; |
---|
48 | |
---|
49 | GtkWidget * |
---|
50 | shape_create_icon (char *xpm_file, |
---|
51 | gint x, |
---|
52 | gint y, |
---|
53 | gint px, |
---|
54 | gint py, |
---|
55 | gint window_type); |
---|
56 | |
---|
57 | static GtkWidget * |
---|
58 | build_option_menu (OptionMenuItem items[], |
---|
59 | gint num_items, |
---|
60 | gint history, |
---|
61 | gpointer data); |
---|
62 | |
---|
63 | /* macro, structure and variables used by tree window demos */ |
---|
64 | #define DEFAULT_NUMBER_OF_ITEM 3 |
---|
65 | #define DEFAULT_RECURSION_LEVEL 3 |
---|
66 | |
---|
67 | struct { |
---|
68 | GSList* selection_mode_group; |
---|
69 | GtkWidget* single_button; |
---|
70 | GtkWidget* browse_button; |
---|
71 | GtkWidget* multiple_button; |
---|
72 | GtkWidget* draw_line_button; |
---|
73 | GtkWidget* view_line_button; |
---|
74 | GtkWidget* no_root_item_button; |
---|
75 | GtkWidget* nb_item_spinner; |
---|
76 | GtkWidget* recursion_spinner; |
---|
77 | } sTreeSampleSelection; |
---|
78 | |
---|
79 | typedef struct sTreeButtons { |
---|
80 | guint nb_item_add; |
---|
81 | GtkWidget* add_button; |
---|
82 | GtkWidget* remove_button; |
---|
83 | GtkWidget* subtree_button; |
---|
84 | } sTreeButtons; |
---|
85 | /* end of tree section */ |
---|
86 | |
---|
87 | static GtkWidget * |
---|
88 | build_option_menu (OptionMenuItem items[], |
---|
89 | gint num_items, |
---|
90 | gint history, |
---|
91 | gpointer data) |
---|
92 | { |
---|
93 | GtkWidget *omenu; |
---|
94 | GtkWidget *menu; |
---|
95 | GtkWidget *menu_item; |
---|
96 | GSList *group; |
---|
97 | gint i; |
---|
98 | |
---|
99 | omenu = gtk_option_menu_new (); |
---|
100 | |
---|
101 | menu = gtk_menu_new (); |
---|
102 | group = NULL; |
---|
103 | |
---|
104 | for (i = 0; i < num_items; i++) |
---|
105 | { |
---|
106 | menu_item = gtk_radio_menu_item_new_with_label (group, items[i].name); |
---|
107 | gtk_signal_connect (GTK_OBJECT (menu_item), "activate", |
---|
108 | (GtkSignalFunc) items[i].func, data); |
---|
109 | group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menu_item)); |
---|
110 | gtk_menu_append (GTK_MENU (menu), menu_item); |
---|
111 | if (i == history) |
---|
112 | gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE); |
---|
113 | gtk_widget_show (menu_item); |
---|
114 | } |
---|
115 | |
---|
116 | gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); |
---|
117 | gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), history); |
---|
118 | |
---|
119 | return omenu; |
---|
120 | } |
---|
121 | |
---|
122 | static void |
---|
123 | destroy_tooltips (GtkWidget *widget, GtkWindow **window) |
---|
124 | { |
---|
125 | GtkTooltips *tt = gtk_object_get_data (GTK_OBJECT (*window), "tooltips"); |
---|
126 | gtk_object_unref (GTK_OBJECT (tt)); |
---|
127 | *window = NULL; |
---|
128 | } |
---|
129 | |
---|
130 | /* |
---|
131 | * GtkButton |
---|
132 | */ |
---|
133 | |
---|
134 | static void |
---|
135 | button_window (GtkWidget *widget, |
---|
136 | GtkWidget *button) |
---|
137 | { |
---|
138 | if (!GTK_WIDGET_VISIBLE (button)) |
---|
139 | gtk_widget_show (button); |
---|
140 | else |
---|
141 | gtk_widget_hide (button); |
---|
142 | } |
---|
143 | |
---|
144 | static void |
---|
145 | create_buttons (void) |
---|
146 | { |
---|
147 | static GtkWidget *window = NULL; |
---|
148 | GtkWidget *box1; |
---|
149 | GtkWidget *box2; |
---|
150 | GtkWidget *table; |
---|
151 | GtkWidget *button[10]; |
---|
152 | GtkWidget *separator; |
---|
153 | |
---|
154 | if (!window) |
---|
155 | { |
---|
156 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
157 | |
---|
158 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
159 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
160 | &window); |
---|
161 | |
---|
162 | gtk_window_set_title (GTK_WINDOW (window), "GtkButton"); |
---|
163 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
164 | |
---|
165 | box1 = gtk_vbox_new (FALSE, 0); |
---|
166 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
167 | |
---|
168 | table = gtk_table_new (3, 3, FALSE); |
---|
169 | gtk_table_set_row_spacings (GTK_TABLE (table), 5); |
---|
170 | gtk_table_set_col_spacings (GTK_TABLE (table), 5); |
---|
171 | gtk_container_set_border_width (GTK_CONTAINER (table), 10); |
---|
172 | gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0); |
---|
173 | |
---|
174 | button[0] = gtk_button_new_with_label ("button1"); |
---|
175 | button[1] = gtk_button_new_with_label ("button2"); |
---|
176 | button[2] = gtk_button_new_with_label ("button3"); |
---|
177 | button[3] = gtk_button_new_with_label ("button4"); |
---|
178 | button[4] = gtk_button_new_with_label ("button5"); |
---|
179 | button[5] = gtk_button_new_with_label ("button6"); |
---|
180 | button[6] = gtk_button_new_with_label ("button7"); |
---|
181 | button[7] = gtk_button_new_with_label ("button8"); |
---|
182 | button[8] = gtk_button_new_with_label ("button9"); |
---|
183 | |
---|
184 | gtk_signal_connect (GTK_OBJECT (button[0]), "clicked", |
---|
185 | GTK_SIGNAL_FUNC(button_window), |
---|
186 | button[1]); |
---|
187 | |
---|
188 | gtk_table_attach (GTK_TABLE (table), button[0], 0, 1, 0, 1, |
---|
189 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
190 | |
---|
191 | gtk_signal_connect (GTK_OBJECT (button[1]), "clicked", |
---|
192 | GTK_SIGNAL_FUNC(button_window), |
---|
193 | button[2]); |
---|
194 | |
---|
195 | gtk_table_attach (GTK_TABLE (table), button[1], 1, 2, 1, 2, |
---|
196 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
197 | |
---|
198 | gtk_signal_connect (GTK_OBJECT (button[2]), "clicked", |
---|
199 | GTK_SIGNAL_FUNC(button_window), |
---|
200 | button[3]); |
---|
201 | gtk_table_attach (GTK_TABLE (table), button[2], 2, 3, 2, 3, |
---|
202 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
203 | |
---|
204 | gtk_signal_connect (GTK_OBJECT (button[3]), "clicked", |
---|
205 | GTK_SIGNAL_FUNC(button_window), |
---|
206 | button[4]); |
---|
207 | gtk_table_attach (GTK_TABLE (table), button[3], 0, 1, 2, 3, |
---|
208 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
209 | |
---|
210 | gtk_signal_connect (GTK_OBJECT (button[4]), "clicked", |
---|
211 | GTK_SIGNAL_FUNC(button_window), |
---|
212 | button[5]); |
---|
213 | gtk_table_attach (GTK_TABLE (table), button[4], 2, 3, 0, 1, |
---|
214 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
215 | |
---|
216 | gtk_signal_connect (GTK_OBJECT (button[5]), "clicked", |
---|
217 | GTK_SIGNAL_FUNC(button_window), |
---|
218 | button[6]); |
---|
219 | gtk_table_attach (GTK_TABLE (table), button[5], 1, 2, 2, 3, |
---|
220 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
221 | |
---|
222 | gtk_signal_connect (GTK_OBJECT (button[6]), "clicked", |
---|
223 | GTK_SIGNAL_FUNC(button_window), |
---|
224 | button[7]); |
---|
225 | gtk_table_attach (GTK_TABLE (table), button[6], 1, 2, 0, 1, |
---|
226 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
227 | |
---|
228 | gtk_signal_connect (GTK_OBJECT (button[7]), "clicked", |
---|
229 | GTK_SIGNAL_FUNC(button_window), |
---|
230 | button[8]); |
---|
231 | gtk_table_attach (GTK_TABLE (table), button[7], 2, 3, 1, 2, |
---|
232 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
233 | |
---|
234 | gtk_signal_connect (GTK_OBJECT (button[8]), "clicked", |
---|
235 | GTK_SIGNAL_FUNC(button_window), |
---|
236 | button[0]); |
---|
237 | gtk_table_attach (GTK_TABLE (table), button[8], 0, 1, 1, 2, |
---|
238 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
239 | |
---|
240 | separator = gtk_hseparator_new (); |
---|
241 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
242 | |
---|
243 | box2 = gtk_vbox_new (FALSE, 10); |
---|
244 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
245 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
246 | |
---|
247 | button[9] = gtk_button_new_with_label ("close"); |
---|
248 | gtk_signal_connect_object (GTK_OBJECT (button[9]), "clicked", |
---|
249 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
250 | GTK_OBJECT (window)); |
---|
251 | gtk_box_pack_start (GTK_BOX (box2), button[9], TRUE, TRUE, 0); |
---|
252 | GTK_WIDGET_SET_FLAGS (button[9], GTK_CAN_DEFAULT); |
---|
253 | gtk_widget_grab_default (button[9]); |
---|
254 | } |
---|
255 | |
---|
256 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
257 | gtk_widget_show_all (window); |
---|
258 | else |
---|
259 | gtk_widget_destroy (window); |
---|
260 | } |
---|
261 | |
---|
262 | /* |
---|
263 | * GtkToggleButton |
---|
264 | */ |
---|
265 | |
---|
266 | static void |
---|
267 | create_toggle_buttons (void) |
---|
268 | { |
---|
269 | static GtkWidget *window = NULL; |
---|
270 | GtkWidget *box1; |
---|
271 | GtkWidget *box2; |
---|
272 | GtkWidget *button; |
---|
273 | GtkWidget *separator; |
---|
274 | |
---|
275 | if (!window) |
---|
276 | { |
---|
277 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
278 | |
---|
279 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
280 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
281 | &window); |
---|
282 | |
---|
283 | gtk_window_set_title (GTK_WINDOW (window), "GtkToggleButton"); |
---|
284 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
285 | |
---|
286 | box1 = gtk_vbox_new (FALSE, 0); |
---|
287 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
288 | |
---|
289 | box2 = gtk_vbox_new (FALSE, 10); |
---|
290 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
291 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
292 | |
---|
293 | button = gtk_toggle_button_new_with_label ("button1"); |
---|
294 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
295 | |
---|
296 | button = gtk_toggle_button_new_with_label ("button2"); |
---|
297 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
298 | |
---|
299 | button = gtk_toggle_button_new_with_label ("button3"); |
---|
300 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
301 | |
---|
302 | separator = gtk_hseparator_new (); |
---|
303 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
304 | |
---|
305 | box2 = gtk_vbox_new (FALSE, 10); |
---|
306 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
307 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
308 | |
---|
309 | button = gtk_button_new_with_label ("close"); |
---|
310 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
311 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
312 | GTK_OBJECT (window)); |
---|
313 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
314 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
315 | gtk_widget_grab_default (button); |
---|
316 | } |
---|
317 | |
---|
318 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
319 | gtk_widget_show_all (window); |
---|
320 | else |
---|
321 | gtk_widget_destroy (window); |
---|
322 | } |
---|
323 | |
---|
324 | /* |
---|
325 | * GtkCheckButton |
---|
326 | */ |
---|
327 | |
---|
328 | static void |
---|
329 | create_check_buttons (void) |
---|
330 | { |
---|
331 | static GtkWidget *window = NULL; |
---|
332 | GtkWidget *box1; |
---|
333 | GtkWidget *box2; |
---|
334 | GtkWidget *button; |
---|
335 | GtkWidget *separator; |
---|
336 | |
---|
337 | if (!window) |
---|
338 | { |
---|
339 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
340 | |
---|
341 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
342 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
343 | &window); |
---|
344 | |
---|
345 | gtk_window_set_title (GTK_WINDOW (window), "GtkCheckButton"); |
---|
346 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
347 | |
---|
348 | box1 = gtk_vbox_new (FALSE, 0); |
---|
349 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
350 | |
---|
351 | box2 = gtk_vbox_new (FALSE, 10); |
---|
352 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
353 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
354 | |
---|
355 | button = gtk_check_button_new_with_label ("button1"); |
---|
356 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
357 | |
---|
358 | button = gtk_check_button_new_with_label ("button2"); |
---|
359 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
360 | |
---|
361 | button = gtk_check_button_new_with_label ("button3"); |
---|
362 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
363 | |
---|
364 | separator = gtk_hseparator_new (); |
---|
365 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
366 | |
---|
367 | box2 = gtk_vbox_new (FALSE, 10); |
---|
368 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
369 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
370 | |
---|
371 | button = gtk_button_new_with_label ("close"); |
---|
372 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
373 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
374 | GTK_OBJECT (window)); |
---|
375 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
376 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
377 | gtk_widget_grab_default (button); |
---|
378 | } |
---|
379 | |
---|
380 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
381 | gtk_widget_show_all (window); |
---|
382 | else |
---|
383 | gtk_widget_destroy (window); |
---|
384 | } |
---|
385 | |
---|
386 | /* |
---|
387 | * GtkRadioButton |
---|
388 | */ |
---|
389 | |
---|
390 | static void |
---|
391 | create_radio_buttons (void) |
---|
392 | { |
---|
393 | static GtkWidget *window = NULL; |
---|
394 | GtkWidget *box1; |
---|
395 | GtkWidget *box2; |
---|
396 | GtkWidget *button; |
---|
397 | GtkWidget *separator; |
---|
398 | |
---|
399 | if (!window) |
---|
400 | { |
---|
401 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
402 | |
---|
403 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
404 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
405 | &window); |
---|
406 | |
---|
407 | gtk_window_set_title (GTK_WINDOW (window), "radio buttons"); |
---|
408 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
409 | |
---|
410 | box1 = gtk_vbox_new (FALSE, 0); |
---|
411 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
412 | |
---|
413 | box2 = gtk_vbox_new (FALSE, 10); |
---|
414 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
415 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
416 | |
---|
417 | button = gtk_radio_button_new_with_label (NULL, "button1"); |
---|
418 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
419 | |
---|
420 | button = gtk_radio_button_new_with_label ( |
---|
421 | gtk_radio_button_group (GTK_RADIO_BUTTON (button)), |
---|
422 | "button2"); |
---|
423 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); |
---|
424 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
425 | |
---|
426 | button = gtk_radio_button_new_with_label ( |
---|
427 | gtk_radio_button_group (GTK_RADIO_BUTTON (button)), |
---|
428 | "button3"); |
---|
429 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
430 | |
---|
431 | separator = gtk_hseparator_new (); |
---|
432 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
433 | |
---|
434 | box2 = gtk_vbox_new (FALSE, 10); |
---|
435 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
436 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
437 | |
---|
438 | button = gtk_button_new_with_label ("close"); |
---|
439 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
440 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
441 | GTK_OBJECT (window)); |
---|
442 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
443 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
444 | gtk_widget_grab_default (button); |
---|
445 | } |
---|
446 | |
---|
447 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
448 | gtk_widget_show_all (window); |
---|
449 | else |
---|
450 | gtk_widget_destroy (window); |
---|
451 | } |
---|
452 | |
---|
453 | /* |
---|
454 | * GtkButtonBox |
---|
455 | */ |
---|
456 | |
---|
457 | static GtkWidget * |
---|
458 | create_bbox (gint horizontal, |
---|
459 | char* title, |
---|
460 | gint spacing, |
---|
461 | gint child_w, |
---|
462 | gint child_h, |
---|
463 | gint layout) |
---|
464 | { |
---|
465 | GtkWidget *frame; |
---|
466 | GtkWidget *bbox; |
---|
467 | GtkWidget *button; |
---|
468 | |
---|
469 | frame = gtk_frame_new (title); |
---|
470 | |
---|
471 | if (horizontal) |
---|
472 | bbox = gtk_hbutton_box_new (); |
---|
473 | else |
---|
474 | bbox = gtk_vbutton_box_new (); |
---|
475 | |
---|
476 | gtk_container_set_border_width (GTK_CONTAINER (bbox), 5); |
---|
477 | gtk_container_add (GTK_CONTAINER (frame), bbox); |
---|
478 | |
---|
479 | gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout); |
---|
480 | gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), spacing); |
---|
481 | gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h); |
---|
482 | |
---|
483 | button = gtk_button_new_with_label ("OK"); |
---|
484 | gtk_container_add (GTK_CONTAINER (bbox), button); |
---|
485 | |
---|
486 | button = gtk_button_new_with_label ("Cancel"); |
---|
487 | gtk_container_add (GTK_CONTAINER (bbox), button); |
---|
488 | |
---|
489 | button = gtk_button_new_with_label ("Help"); |
---|
490 | gtk_container_add (GTK_CONTAINER (bbox), button); |
---|
491 | |
---|
492 | return frame; |
---|
493 | } |
---|
494 | |
---|
495 | static void |
---|
496 | create_button_box (void) |
---|
497 | { |
---|
498 | static GtkWidget* window = NULL; |
---|
499 | GtkWidget *main_vbox; |
---|
500 | GtkWidget *vbox; |
---|
501 | GtkWidget *hbox; |
---|
502 | GtkWidget *frame_horz; |
---|
503 | GtkWidget *frame_vert; |
---|
504 | |
---|
505 | if (!window) |
---|
506 | { |
---|
507 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
508 | gtk_window_set_title (GTK_WINDOW (window), "Button Boxes"); |
---|
509 | |
---|
510 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
511 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
512 | &window); |
---|
513 | |
---|
514 | gtk_container_set_border_width (GTK_CONTAINER (window), 10); |
---|
515 | |
---|
516 | main_vbox = gtk_vbox_new (FALSE, 0); |
---|
517 | gtk_container_add (GTK_CONTAINER (window), main_vbox); |
---|
518 | |
---|
519 | frame_horz = gtk_frame_new ("Horizontal Button Boxes"); |
---|
520 | gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10); |
---|
521 | |
---|
522 | vbox = gtk_vbox_new (FALSE, 0); |
---|
523 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); |
---|
524 | gtk_container_add (GTK_CONTAINER (frame_horz), vbox); |
---|
525 | |
---|
526 | gtk_box_pack_start (GTK_BOX (vbox), |
---|
527 | create_bbox (TRUE, "Spread", 40, 85, 20, GTK_BUTTONBOX_SPREAD), |
---|
528 | TRUE, TRUE, 0); |
---|
529 | |
---|
530 | gtk_box_pack_start (GTK_BOX (vbox), |
---|
531 | create_bbox (TRUE, "Edge", 40, 85, 20, GTK_BUTTONBOX_EDGE), |
---|
532 | TRUE, TRUE, 5); |
---|
533 | |
---|
534 | gtk_box_pack_start (GTK_BOX (vbox), |
---|
535 | create_bbox (TRUE, "Start", 40, 85, 20, GTK_BUTTONBOX_START), |
---|
536 | TRUE, TRUE, 5); |
---|
537 | |
---|
538 | gtk_box_pack_start (GTK_BOX (vbox), |
---|
539 | create_bbox (TRUE, "End", 40, 85, 20, GTK_BUTTONBOX_END), |
---|
540 | TRUE, TRUE, 5); |
---|
541 | |
---|
542 | frame_vert = gtk_frame_new ("Vertical Button Boxes"); |
---|
543 | gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10); |
---|
544 | |
---|
545 | hbox = gtk_hbox_new (FALSE, 0); |
---|
546 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); |
---|
547 | gtk_container_add (GTK_CONTAINER (frame_vert), hbox); |
---|
548 | |
---|
549 | gtk_box_pack_start (GTK_BOX (hbox), |
---|
550 | create_bbox (FALSE, "Spread", 30, 85, 20, GTK_BUTTONBOX_SPREAD), |
---|
551 | TRUE, TRUE, 0); |
---|
552 | |
---|
553 | gtk_box_pack_start (GTK_BOX (hbox), |
---|
554 | create_bbox (FALSE, "Edge", 30, 85, 20, GTK_BUTTONBOX_EDGE), |
---|
555 | TRUE, TRUE, 5); |
---|
556 | |
---|
557 | gtk_box_pack_start (GTK_BOX (hbox), |
---|
558 | create_bbox (FALSE, "Start", 30, 85, 20, GTK_BUTTONBOX_START), |
---|
559 | TRUE, TRUE, 5); |
---|
560 | |
---|
561 | gtk_box_pack_start (GTK_BOX (hbox), |
---|
562 | create_bbox (FALSE, "End", 30, 85, 20, GTK_BUTTONBOX_END), |
---|
563 | TRUE, TRUE, 5); |
---|
564 | } |
---|
565 | |
---|
566 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
567 | gtk_widget_show_all (window); |
---|
568 | else |
---|
569 | gtk_widget_destroy (window); |
---|
570 | } |
---|
571 | |
---|
572 | /* |
---|
573 | * GtkToolBar |
---|
574 | */ |
---|
575 | |
---|
576 | static GtkWidget* |
---|
577 | new_pixmap (char *filename, |
---|
578 | GdkWindow *window, |
---|
579 | GdkColor *background) |
---|
580 | { |
---|
581 | GtkWidget *wpixmap; |
---|
582 | GdkPixmap *pixmap; |
---|
583 | GdkBitmap *mask; |
---|
584 | |
---|
585 | pixmap = gdk_pixmap_create_from_xpm (window, &mask, |
---|
586 | background, |
---|
587 | filename); |
---|
588 | wpixmap = gtk_pixmap_new (pixmap, mask); |
---|
589 | |
---|
590 | return wpixmap; |
---|
591 | } |
---|
592 | |
---|
593 | static void |
---|
594 | set_toolbar_horizontal (GtkWidget *widget, |
---|
595 | gpointer data) |
---|
596 | { |
---|
597 | gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_HORIZONTAL); |
---|
598 | } |
---|
599 | |
---|
600 | static void |
---|
601 | set_toolbar_vertical (GtkWidget *widget, |
---|
602 | gpointer data) |
---|
603 | { |
---|
604 | gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_VERTICAL); |
---|
605 | } |
---|
606 | |
---|
607 | static void |
---|
608 | set_toolbar_icons (GtkWidget *widget, |
---|
609 | gpointer data) |
---|
610 | { |
---|
611 | gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS); |
---|
612 | } |
---|
613 | |
---|
614 | static void |
---|
615 | set_toolbar_text (GtkWidget *widget, |
---|
616 | gpointer data) |
---|
617 | { |
---|
618 | gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT); |
---|
619 | } |
---|
620 | |
---|
621 | static void |
---|
622 | set_toolbar_both (GtkWidget *widget, |
---|
623 | gpointer data) |
---|
624 | { |
---|
625 | gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH); |
---|
626 | } |
---|
627 | |
---|
628 | static void |
---|
629 | set_toolbar_small_space (GtkWidget *widget, |
---|
630 | gpointer data) |
---|
631 | { |
---|
632 | gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 5); |
---|
633 | } |
---|
634 | |
---|
635 | static void |
---|
636 | set_toolbar_big_space (GtkWidget *widget, |
---|
637 | gpointer data) |
---|
638 | { |
---|
639 | gtk_toolbar_set_space_size (GTK_TOOLBAR (data), 10); |
---|
640 | } |
---|
641 | |
---|
642 | static void |
---|
643 | set_toolbar_enable (GtkWidget *widget, |
---|
644 | gpointer data) |
---|
645 | { |
---|
646 | gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), TRUE); |
---|
647 | } |
---|
648 | |
---|
649 | static void |
---|
650 | set_toolbar_disable (GtkWidget *widget, |
---|
651 | gpointer data) |
---|
652 | { |
---|
653 | gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), FALSE); |
---|
654 | } |
---|
655 | |
---|
656 | static void |
---|
657 | set_toolbar_borders (GtkWidget *widget, |
---|
658 | gpointer data) |
---|
659 | { |
---|
660 | gtk_toolbar_set_button_relief (GTK_TOOLBAR (data), GTK_RELIEF_NORMAL); |
---|
661 | } |
---|
662 | |
---|
663 | static void |
---|
664 | set_toolbar_borderless (GtkWidget *widget, |
---|
665 | gpointer data) |
---|
666 | { |
---|
667 | gtk_toolbar_set_button_relief (GTK_TOOLBAR (data), GTK_RELIEF_NONE); |
---|
668 | } |
---|
669 | |
---|
670 | static void |
---|
671 | set_toolbar_space_style_empty (GtkWidget *widget, |
---|
672 | gpointer data) |
---|
673 | { |
---|
674 | gtk_toolbar_set_space_style (GTK_TOOLBAR (data), GTK_TOOLBAR_SPACE_EMPTY); |
---|
675 | } |
---|
676 | |
---|
677 | static void |
---|
678 | set_toolbar_space_style_line (GtkWidget *widget, |
---|
679 | gpointer data) |
---|
680 | { |
---|
681 | gtk_toolbar_set_space_style (GTK_TOOLBAR (data), GTK_TOOLBAR_SPACE_LINE); |
---|
682 | } |
---|
683 | |
---|
684 | static void |
---|
685 | create_toolbar (void) |
---|
686 | { |
---|
687 | static GtkWidget *window = NULL; |
---|
688 | GtkWidget *toolbar; |
---|
689 | GtkWidget *entry; |
---|
690 | |
---|
691 | if (!window) |
---|
692 | { |
---|
693 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
694 | gtk_window_set_title (GTK_WINDOW (window), "Toolbar test"); |
---|
695 | gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, TRUE); |
---|
696 | |
---|
697 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
698 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
699 | &window); |
---|
700 | |
---|
701 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
702 | gtk_widget_realize (window); |
---|
703 | |
---|
704 | toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); |
---|
705 | gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NONE); |
---|
706 | |
---|
707 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
708 | "Horizontal", "Horizontal toolbar layout", "Toolbar/Horizontal", |
---|
709 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
710 | (GtkSignalFunc) set_toolbar_horizontal, toolbar); |
---|
711 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
712 | "Vertical", "Vertical toolbar layout", "Toolbar/Vertical", |
---|
713 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
714 | (GtkSignalFunc) set_toolbar_vertical, toolbar); |
---|
715 | |
---|
716 | gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); |
---|
717 | |
---|
718 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
719 | "Icons", "Only show toolbar icons", "Toolbar/IconsOnly", |
---|
720 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
721 | (GtkSignalFunc) set_toolbar_icons, toolbar); |
---|
722 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
723 | "Text", "Only show toolbar text", "Toolbar/TextOnly", |
---|
724 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
725 | (GtkSignalFunc) set_toolbar_text, toolbar); |
---|
726 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
727 | "Both", "Show toolbar icons and text", "Toolbar/Both", |
---|
728 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
729 | (GtkSignalFunc) set_toolbar_both, toolbar); |
---|
730 | |
---|
731 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
732 | |
---|
733 | entry = gtk_entry_new (); |
---|
734 | |
---|
735 | gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), entry, "This is an unusable GtkEntry ;)", "Hey don't click me!!!"); |
---|
736 | |
---|
737 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
738 | |
---|
739 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
740 | "Small", "Use small spaces", "Toolbar/Small", |
---|
741 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
742 | (GtkSignalFunc) set_toolbar_small_space, toolbar); |
---|
743 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
744 | "Big", "Use big spaces", "Toolbar/Big", |
---|
745 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
746 | (GtkSignalFunc) set_toolbar_big_space, toolbar); |
---|
747 | |
---|
748 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
749 | |
---|
750 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
751 | "Enable", "Enable tooltips", NULL, |
---|
752 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
753 | (GtkSignalFunc) set_toolbar_enable, toolbar); |
---|
754 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
755 | "Disable", "Disable tooltips", NULL, |
---|
756 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
757 | (GtkSignalFunc) set_toolbar_disable, toolbar); |
---|
758 | |
---|
759 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
760 | |
---|
761 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
762 | "Borders", "Show Borders", NULL, |
---|
763 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
764 | (GtkSignalFunc) set_toolbar_borders, toolbar); |
---|
765 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
766 | "Borderless", "Hide Borders", NULL, |
---|
767 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
768 | (GtkSignalFunc) set_toolbar_borderless, toolbar); |
---|
769 | |
---|
770 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
771 | |
---|
772 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
773 | "Empty", "Empty spaces", NULL, |
---|
774 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
775 | (GtkSignalFunc) set_toolbar_space_style_empty, toolbar); |
---|
776 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
777 | "Lines", "Lines in spaces", NULL, |
---|
778 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
779 | (GtkSignalFunc) set_toolbar_space_style_line, toolbar); |
---|
780 | |
---|
781 | gtk_container_add (GTK_CONTAINER (window), toolbar); |
---|
782 | } |
---|
783 | |
---|
784 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
785 | gtk_widget_show_all (window); |
---|
786 | else |
---|
787 | gtk_widget_destroy (window); |
---|
788 | } |
---|
789 | |
---|
790 | static GtkWidget* |
---|
791 | make_toolbar (GtkWidget *window) |
---|
792 | { |
---|
793 | GtkWidget *toolbar; |
---|
794 | |
---|
795 | if (!GTK_WIDGET_REALIZED (window)) |
---|
796 | gtk_widget_realize (window); |
---|
797 | |
---|
798 | toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); |
---|
799 | gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NONE); |
---|
800 | |
---|
801 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
802 | "Horizontal", "Horizontal toolbar layout", NULL, |
---|
803 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
804 | (GtkSignalFunc) set_toolbar_horizontal, toolbar); |
---|
805 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
806 | "Vertical", "Vertical toolbar layout", NULL, |
---|
807 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
808 | (GtkSignalFunc) set_toolbar_vertical, toolbar); |
---|
809 | |
---|
810 | gtk_toolbar_append_space (GTK_TOOLBAR(toolbar)); |
---|
811 | |
---|
812 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
813 | "Icons", "Only show toolbar icons", NULL, |
---|
814 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
815 | (GtkSignalFunc) set_toolbar_icons, toolbar); |
---|
816 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
817 | "Text", "Only show toolbar text", NULL, |
---|
818 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
819 | (GtkSignalFunc) set_toolbar_text, toolbar); |
---|
820 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
821 | "Both", "Show toolbar icons and text", NULL, |
---|
822 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
823 | (GtkSignalFunc) set_toolbar_both, toolbar); |
---|
824 | |
---|
825 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
826 | |
---|
827 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
828 | "Small", "Use small spaces", NULL, |
---|
829 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
830 | (GtkSignalFunc) set_toolbar_small_space, toolbar); |
---|
831 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
832 | "Big", "Use big spaces", "Toolbar/Big", |
---|
833 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
834 | (GtkSignalFunc) set_toolbar_big_space, toolbar); |
---|
835 | |
---|
836 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
837 | |
---|
838 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
839 | "Enable", "Enable tooltips", NULL, |
---|
840 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
841 | (GtkSignalFunc) set_toolbar_enable, toolbar); |
---|
842 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
843 | "Disable", "Disable tooltips", NULL, |
---|
844 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
845 | (GtkSignalFunc) set_toolbar_disable, toolbar); |
---|
846 | |
---|
847 | gtk_toolbar_append_space (GTK_TOOLBAR (toolbar)); |
---|
848 | |
---|
849 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
850 | "Borders", "Show Borders", NULL, |
---|
851 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
852 | (GtkSignalFunc) set_toolbar_borders, toolbar); |
---|
853 | gtk_toolbar_append_item (GTK_TOOLBAR (toolbar), |
---|
854 | "Borderless", "Hide Borders", NULL, |
---|
855 | new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]), |
---|
856 | (GtkSignalFunc) set_toolbar_borderless, toolbar); |
---|
857 | |
---|
858 | return toolbar; |
---|
859 | } |
---|
860 | |
---|
861 | /* |
---|
862 | * GtkStatusBar |
---|
863 | */ |
---|
864 | |
---|
865 | static guint statusbar_counter = 1; |
---|
866 | |
---|
867 | static void |
---|
868 | statusbar_push (GtkWidget *button, |
---|
869 | GtkStatusbar *statusbar) |
---|
870 | { |
---|
871 | gchar text[1024]; |
---|
872 | |
---|
873 | sprintf (text, "something %d", statusbar_counter++); |
---|
874 | |
---|
875 | gtk_statusbar_push (statusbar, 1, text); |
---|
876 | } |
---|
877 | |
---|
878 | static void |
---|
879 | statusbar_pop (GtkWidget *button, |
---|
880 | GtkStatusbar *statusbar) |
---|
881 | { |
---|
882 | gtk_statusbar_pop (statusbar, 1); |
---|
883 | } |
---|
884 | |
---|
885 | static void |
---|
886 | statusbar_steal (GtkWidget *button, |
---|
887 | GtkStatusbar *statusbar) |
---|
888 | { |
---|
889 | gtk_statusbar_remove (statusbar, 1, 4); |
---|
890 | } |
---|
891 | |
---|
892 | static void |
---|
893 | statusbar_popped (GtkStatusbar *statusbar, |
---|
894 | guint context_id, |
---|
895 | const gchar *text) |
---|
896 | { |
---|
897 | if (!statusbar->messages) |
---|
898 | statusbar_counter = 1; |
---|
899 | } |
---|
900 | |
---|
901 | static void |
---|
902 | statusbar_contexts (GtkStatusbar *statusbar) |
---|
903 | { |
---|
904 | gchar *string; |
---|
905 | |
---|
906 | string = "any context"; |
---|
907 | g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n", |
---|
908 | string, |
---|
909 | gtk_statusbar_get_context_id (statusbar, string)); |
---|
910 | |
---|
911 | string = "idle messages"; |
---|
912 | g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n", |
---|
913 | string, |
---|
914 | gtk_statusbar_get_context_id (statusbar, string)); |
---|
915 | |
---|
916 | string = "some text"; |
---|
917 | g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n", |
---|
918 | string, |
---|
919 | gtk_statusbar_get_context_id (statusbar, string)); |
---|
920 | |
---|
921 | string = "hit the mouse"; |
---|
922 | g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n", |
---|
923 | string, |
---|
924 | gtk_statusbar_get_context_id (statusbar, string)); |
---|
925 | |
---|
926 | string = "hit the mouse2"; |
---|
927 | g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n", |
---|
928 | string, |
---|
929 | gtk_statusbar_get_context_id (statusbar, string)); |
---|
930 | } |
---|
931 | |
---|
932 | static void |
---|
933 | statusbar_dump_stack (GtkStatusbar *statusbar) |
---|
934 | { |
---|
935 | GSList *list; |
---|
936 | |
---|
937 | for (list = statusbar->messages; list; list = list->next) |
---|
938 | { |
---|
939 | GtkStatusbarMsg *msg; |
---|
940 | |
---|
941 | msg = list->data; |
---|
942 | g_print ("context_id: %d, message_id: %d, status_text: \"%s\"\n", |
---|
943 | msg->context_id, |
---|
944 | msg->message_id, |
---|
945 | msg->text); |
---|
946 | } |
---|
947 | } |
---|
948 | |
---|
949 | static void |
---|
950 | create_statusbar (void) |
---|
951 | { |
---|
952 | static GtkWidget *window = NULL; |
---|
953 | GtkWidget *box1; |
---|
954 | GtkWidget *box2; |
---|
955 | GtkWidget *button; |
---|
956 | GtkWidget *separator; |
---|
957 | GtkWidget *statusbar; |
---|
958 | |
---|
959 | if (!window) |
---|
960 | { |
---|
961 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
962 | |
---|
963 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
964 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
965 | &window); |
---|
966 | |
---|
967 | gtk_window_set_title (GTK_WINDOW (window), "statusbar"); |
---|
968 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
969 | |
---|
970 | box1 = gtk_vbox_new (FALSE, 0); |
---|
971 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
972 | |
---|
973 | box2 = gtk_vbox_new (FALSE, 10); |
---|
974 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
975 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
976 | |
---|
977 | statusbar = gtk_statusbar_new (); |
---|
978 | gtk_box_pack_end (GTK_BOX (box1), statusbar, TRUE, TRUE, 0); |
---|
979 | gtk_signal_connect (GTK_OBJECT (statusbar), |
---|
980 | "text_popped", |
---|
981 | GTK_SIGNAL_FUNC (statusbar_popped), |
---|
982 | NULL); |
---|
983 | |
---|
984 | button = gtk_widget_new (gtk_button_get_type (), |
---|
985 | "label", "push something", |
---|
986 | "visible", TRUE, |
---|
987 | "parent", box2, |
---|
988 | "signal::clicked", statusbar_push, statusbar, |
---|
989 | NULL); |
---|
990 | |
---|
991 | button = gtk_widget_new (gtk_button_get_type (), |
---|
992 | "label", "pop", |
---|
993 | "visible", TRUE, |
---|
994 | "parent", box2, |
---|
995 | "signal_after::clicked", statusbar_pop, statusbar, |
---|
996 | NULL); |
---|
997 | |
---|
998 | button = gtk_widget_new (gtk_button_get_type (), |
---|
999 | "label", "steal #4", |
---|
1000 | "visible", TRUE, |
---|
1001 | "parent", box2, |
---|
1002 | "signal_after::clicked", statusbar_steal, statusbar, |
---|
1003 | NULL); |
---|
1004 | |
---|
1005 | button = gtk_widget_new (gtk_button_get_type (), |
---|
1006 | "label", "dump stack", |
---|
1007 | "visible", TRUE, |
---|
1008 | "parent", box2, |
---|
1009 | "object_signal::clicked", statusbar_dump_stack, statusbar, |
---|
1010 | NULL); |
---|
1011 | |
---|
1012 | button = gtk_widget_new (gtk_button_get_type (), |
---|
1013 | "label", "test contexts", |
---|
1014 | "visible", TRUE, |
---|
1015 | "parent", box2, |
---|
1016 | "object_signal_after::clicked", statusbar_contexts, statusbar, |
---|
1017 | NULL); |
---|
1018 | |
---|
1019 | separator = gtk_hseparator_new (); |
---|
1020 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
1021 | |
---|
1022 | box2 = gtk_vbox_new (FALSE, 10); |
---|
1023 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
1024 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
1025 | |
---|
1026 | button = gtk_button_new_with_label ("close"); |
---|
1027 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
1028 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
1029 | GTK_OBJECT (window)); |
---|
1030 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
1031 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
1032 | gtk_widget_grab_default (button); |
---|
1033 | } |
---|
1034 | |
---|
1035 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
1036 | gtk_widget_show_all (window); |
---|
1037 | else |
---|
1038 | gtk_widget_destroy (window); |
---|
1039 | } |
---|
1040 | |
---|
1041 | /* |
---|
1042 | * GtkTree |
---|
1043 | */ |
---|
1044 | |
---|
1045 | static void |
---|
1046 | cb_tree_destroy_event(GtkWidget* w) |
---|
1047 | { |
---|
1048 | sTreeButtons* tree_buttons; |
---|
1049 | |
---|
1050 | /* free buttons structure associate at this tree */ |
---|
1051 | tree_buttons = gtk_object_get_user_data (GTK_OBJECT (w)); |
---|
1052 | g_free (tree_buttons); |
---|
1053 | } |
---|
1054 | |
---|
1055 | static void |
---|
1056 | cb_add_new_item(GtkWidget* w, GtkTree* tree) |
---|
1057 | { |
---|
1058 | sTreeButtons* tree_buttons; |
---|
1059 | GList* selected_list; |
---|
1060 | GtkWidget* selected_item; |
---|
1061 | GtkWidget* subtree; |
---|
1062 | GtkWidget* item_new; |
---|
1063 | char buffer[255]; |
---|
1064 | |
---|
1065 | tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree)); |
---|
1066 | |
---|
1067 | selected_list = GTK_TREE_SELECTION(tree); |
---|
1068 | |
---|
1069 | if(selected_list == NULL) |
---|
1070 | { |
---|
1071 | /* there is no item in tree */ |
---|
1072 | subtree = GTK_WIDGET(tree); |
---|
1073 | } |
---|
1074 | else |
---|
1075 | { |
---|
1076 | /* list can have only one element */ |
---|
1077 | selected_item = GTK_WIDGET(selected_list->data); |
---|
1078 | |
---|
1079 | subtree = GTK_TREE_ITEM_SUBTREE(selected_item); |
---|
1080 | |
---|
1081 | if(subtree == NULL) |
---|
1082 | { |
---|
1083 | /* current selected item have not subtree ... create it */ |
---|
1084 | subtree = gtk_tree_new(); |
---|
1085 | gtk_tree_item_set_subtree(GTK_TREE_ITEM(selected_item), |
---|
1086 | subtree); |
---|
1087 | } |
---|
1088 | } |
---|
1089 | |
---|
1090 | /* at this point, we know which subtree will be used to add new item */ |
---|
1091 | /* create a new item */ |
---|
1092 | sprintf(buffer, "item add %d", tree_buttons->nb_item_add); |
---|
1093 | item_new = gtk_tree_item_new_with_label(buffer); |
---|
1094 | gtk_tree_append(GTK_TREE(subtree), item_new); |
---|
1095 | gtk_widget_show(item_new); |
---|
1096 | |
---|
1097 | tree_buttons->nb_item_add++; |
---|
1098 | } |
---|
1099 | |
---|
1100 | static void |
---|
1101 | cb_remove_item(GtkWidget*w, GtkTree* tree) |
---|
1102 | { |
---|
1103 | GList* selected_list; |
---|
1104 | GList* clear_list; |
---|
1105 | |
---|
1106 | selected_list = GTK_TREE_SELECTION(tree); |
---|
1107 | |
---|
1108 | clear_list = NULL; |
---|
1109 | |
---|
1110 | while (selected_list) |
---|
1111 | { |
---|
1112 | clear_list = g_list_prepend (clear_list, selected_list->data); |
---|
1113 | selected_list = selected_list->next; |
---|
1114 | } |
---|
1115 | |
---|
1116 | clear_list = g_list_reverse (clear_list); |
---|
1117 | gtk_tree_remove_items(tree, clear_list); |
---|
1118 | |
---|
1119 | g_list_free (clear_list); |
---|
1120 | } |
---|
1121 | |
---|
1122 | static void |
---|
1123 | cb_remove_subtree(GtkWidget*w, GtkTree* tree) |
---|
1124 | { |
---|
1125 | GList* selected_list; |
---|
1126 | GtkTreeItem *item; |
---|
1127 | |
---|
1128 | selected_list = GTK_TREE_SELECTION(tree); |
---|
1129 | |
---|
1130 | if (selected_list) |
---|
1131 | { |
---|
1132 | item = GTK_TREE_ITEM (selected_list->data); |
---|
1133 | if (item->subtree) |
---|
1134 | gtk_tree_item_remove_subtree (item); |
---|
1135 | } |
---|
1136 | } |
---|
1137 | |
---|
1138 | static void |
---|
1139 | cb_tree_changed(GtkTree* tree) |
---|
1140 | { |
---|
1141 | sTreeButtons* tree_buttons; |
---|
1142 | GList* selected_list; |
---|
1143 | guint nb_selected; |
---|
1144 | |
---|
1145 | tree_buttons = gtk_object_get_user_data(GTK_OBJECT(tree)); |
---|
1146 | |
---|
1147 | selected_list = GTK_TREE_SELECTION(tree); |
---|
1148 | nb_selected = g_list_length(selected_list); |
---|
1149 | |
---|
1150 | if(nb_selected == 0) |
---|
1151 | { |
---|
1152 | if(tree->children == NULL) |
---|
1153 | gtk_widget_set_sensitive(tree_buttons->add_button, TRUE); |
---|
1154 | else |
---|
1155 | gtk_widget_set_sensitive(tree_buttons->add_button, FALSE); |
---|
1156 | gtk_widget_set_sensitive(tree_buttons->remove_button, FALSE); |
---|
1157 | gtk_widget_set_sensitive(tree_buttons->subtree_button, FALSE); |
---|
1158 | } |
---|
1159 | else |
---|
1160 | { |
---|
1161 | gtk_widget_set_sensitive(tree_buttons->remove_button, TRUE); |
---|
1162 | gtk_widget_set_sensitive(tree_buttons->add_button, (nb_selected == 1)); |
---|
1163 | gtk_widget_set_sensitive(tree_buttons->subtree_button, (nb_selected == 1)); |
---|
1164 | } |
---|
1165 | } |
---|
1166 | |
---|
1167 | static void |
---|
1168 | create_subtree(GtkWidget* item, guint level, guint nb_item_max, guint recursion_level_max) |
---|
1169 | { |
---|
1170 | GtkWidget* item_subtree; |
---|
1171 | GtkWidget* item_new; |
---|
1172 | guint nb_item; |
---|
1173 | char buffer[255]; |
---|
1174 | int no_root_item; |
---|
1175 | |
---|
1176 | if(level == recursion_level_max) return; |
---|
1177 | |
---|
1178 | if(level == -1) |
---|
1179 | { |
---|
1180 | /* query with no root item */ |
---|
1181 | level = 0; |
---|
1182 | item_subtree = item; |
---|
1183 | no_root_item = 1; |
---|
1184 | } |
---|
1185 | else |
---|
1186 | { |
---|
1187 | /* query with no root item */ |
---|
1188 | /* create subtree and associate it with current item */ |
---|
1189 | item_subtree = gtk_tree_new(); |
---|
1190 | no_root_item = 0; |
---|
1191 | } |
---|
1192 | |
---|
1193 | for(nb_item = 0; nb_item < nb_item_max; nb_item++) |
---|
1194 | { |
---|
1195 | sprintf(buffer, "item %d-%d", level, nb_item); |
---|
1196 | item_new = gtk_tree_item_new_with_label(buffer); |
---|
1197 | gtk_tree_append(GTK_TREE(item_subtree), item_new); |
---|
1198 | create_subtree(item_new, level+1, nb_item_max, recursion_level_max); |
---|
1199 | gtk_widget_show(item_new); |
---|
1200 | } |
---|
1201 | |
---|
1202 | if(!no_root_item) |
---|
1203 | gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), item_subtree); |
---|
1204 | } |
---|
1205 | |
---|
1206 | static void |
---|
1207 | create_tree_sample(guint selection_mode, |
---|
1208 | guint draw_line, guint view_line, guint no_root_item, |
---|
1209 | guint nb_item_max, guint recursion_level_max) |
---|
1210 | { |
---|
1211 | GtkWidget* window; |
---|
1212 | GtkWidget* box1; |
---|
1213 | GtkWidget* box2; |
---|
1214 | GtkWidget* separator; |
---|
1215 | GtkWidget* button; |
---|
1216 | GtkWidget* scrolled_win; |
---|
1217 | GtkWidget* root_tree; |
---|
1218 | GtkWidget* root_item; |
---|
1219 | sTreeButtons* tree_buttons; |
---|
1220 | |
---|
1221 | /* create tree buttons struct */ |
---|
1222 | if ((tree_buttons = g_malloc (sizeof (sTreeButtons))) == NULL) |
---|
1223 | { |
---|
1224 | g_error("can't allocate memory for tree structure !\n"); |
---|
1225 | return; |
---|
1226 | } |
---|
1227 | tree_buttons->nb_item_add = 0; |
---|
1228 | |
---|
1229 | /* create top level window */ |
---|
1230 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
---|
1231 | gtk_window_set_title(GTK_WINDOW(window), "Tree Sample"); |
---|
1232 | gtk_signal_connect(GTK_OBJECT(window), "destroy", |
---|
1233 | (GtkSignalFunc) cb_tree_destroy_event, NULL); |
---|
1234 | gtk_object_set_user_data(GTK_OBJECT(window), tree_buttons); |
---|
1235 | |
---|
1236 | box1 = gtk_vbox_new(FALSE, 0); |
---|
1237 | gtk_container_add(GTK_CONTAINER(window), box1); |
---|
1238 | gtk_widget_show(box1); |
---|
1239 | |
---|
1240 | /* create tree box */ |
---|
1241 | box2 = gtk_vbox_new(FALSE, 0); |
---|
1242 | gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0); |
---|
1243 | gtk_container_set_border_width(GTK_CONTAINER(box2), 5); |
---|
1244 | gtk_widget_show(box2); |
---|
1245 | |
---|
1246 | /* create scrolled window */ |
---|
1247 | scrolled_win = gtk_scrolled_window_new (NULL, NULL); |
---|
1248 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), |
---|
1249 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
---|
1250 | gtk_box_pack_start (GTK_BOX (box2), scrolled_win, TRUE, TRUE, 0); |
---|
1251 | gtk_widget_set_usize (scrolled_win, 200, 200); |
---|
1252 | gtk_widget_show (scrolled_win); |
---|
1253 | |
---|
1254 | /* create root tree widget */ |
---|
1255 | root_tree = gtk_tree_new(); |
---|
1256 | gtk_signal_connect(GTK_OBJECT(root_tree), "selection_changed", |
---|
1257 | (GtkSignalFunc)cb_tree_changed, |
---|
1258 | (gpointer)NULL); |
---|
1259 | gtk_object_set_user_data(GTK_OBJECT(root_tree), tree_buttons); |
---|
1260 | gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), root_tree); |
---|
1261 | gtk_tree_set_selection_mode(GTK_TREE(root_tree), selection_mode); |
---|
1262 | gtk_tree_set_view_lines(GTK_TREE(root_tree), draw_line); |
---|
1263 | gtk_tree_set_view_mode(GTK_TREE(root_tree), !view_line); |
---|
1264 | gtk_widget_show(root_tree); |
---|
1265 | |
---|
1266 | if ( no_root_item ) |
---|
1267 | { |
---|
1268 | /* set root tree to subtree function with root item variable */ |
---|
1269 | root_item = GTK_WIDGET(root_tree); |
---|
1270 | } |
---|
1271 | else |
---|
1272 | { |
---|
1273 | /* create root tree item widget */ |
---|
1274 | root_item = gtk_tree_item_new_with_label("root item"); |
---|
1275 | gtk_tree_append(GTK_TREE(root_tree), root_item); |
---|
1276 | gtk_widget_show(root_item); |
---|
1277 | } |
---|
1278 | create_subtree(root_item, -no_root_item, nb_item_max, recursion_level_max); |
---|
1279 | |
---|
1280 | box2 = gtk_vbox_new(FALSE, 0); |
---|
1281 | gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); |
---|
1282 | gtk_container_set_border_width(GTK_CONTAINER(box2), 5); |
---|
1283 | gtk_widget_show(box2); |
---|
1284 | |
---|
1285 | button = gtk_button_new_with_label("Add Item"); |
---|
1286 | gtk_widget_set_sensitive(button, FALSE); |
---|
1287 | gtk_signal_connect(GTK_OBJECT (button), "clicked", |
---|
1288 | (GtkSignalFunc) cb_add_new_item, |
---|
1289 | (gpointer)root_tree); |
---|
1290 | gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); |
---|
1291 | gtk_widget_show(button); |
---|
1292 | tree_buttons->add_button = button; |
---|
1293 | |
---|
1294 | button = gtk_button_new_with_label("Remove Item(s)"); |
---|
1295 | gtk_widget_set_sensitive(button, FALSE); |
---|
1296 | gtk_signal_connect(GTK_OBJECT (button), "clicked", |
---|
1297 | (GtkSignalFunc) cb_remove_item, |
---|
1298 | (gpointer)root_tree); |
---|
1299 | gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); |
---|
1300 | gtk_widget_show(button); |
---|
1301 | tree_buttons->remove_button = button; |
---|
1302 | |
---|
1303 | button = gtk_button_new_with_label("Remove Subtree"); |
---|
1304 | gtk_widget_set_sensitive(button, FALSE); |
---|
1305 | gtk_signal_connect(GTK_OBJECT (button), "clicked", |
---|
1306 | (GtkSignalFunc) cb_remove_subtree, |
---|
1307 | (gpointer)root_tree); |
---|
1308 | gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); |
---|
1309 | gtk_widget_show(button); |
---|
1310 | tree_buttons->subtree_button = button; |
---|
1311 | |
---|
1312 | /* create separator */ |
---|
1313 | separator = gtk_hseparator_new(); |
---|
1314 | gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0); |
---|
1315 | gtk_widget_show(separator); |
---|
1316 | |
---|
1317 | /* create button box */ |
---|
1318 | box2 = gtk_vbox_new(FALSE, 0); |
---|
1319 | gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); |
---|
1320 | gtk_container_set_border_width(GTK_CONTAINER(box2), 5); |
---|
1321 | gtk_widget_show(box2); |
---|
1322 | |
---|
1323 | button = gtk_button_new_with_label("Close"); |
---|
1324 | gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); |
---|
1325 | gtk_signal_connect_object(GTK_OBJECT (button), "clicked", |
---|
1326 | (GtkSignalFunc) gtk_widget_destroy, |
---|
1327 | GTK_OBJECT(window)); |
---|
1328 | gtk_widget_show(button); |
---|
1329 | |
---|
1330 | gtk_widget_show(window); |
---|
1331 | } |
---|
1332 | |
---|
1333 | static void |
---|
1334 | cb_create_tree(GtkWidget* w) |
---|
1335 | { |
---|
1336 | guint selection_mode = GTK_SELECTION_SINGLE; |
---|
1337 | guint view_line; |
---|
1338 | guint draw_line; |
---|
1339 | guint no_root_item; |
---|
1340 | guint nb_item; |
---|
1341 | guint recursion_level; |
---|
1342 | |
---|
1343 | /* get selection mode choice */ |
---|
1344 | if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.single_button)->active) |
---|
1345 | selection_mode = GTK_SELECTION_SINGLE; |
---|
1346 | else |
---|
1347 | if(GTK_TOGGLE_BUTTON(sTreeSampleSelection.browse_button)->active) |
---|
1348 | selection_mode = GTK_SELECTION_BROWSE; |
---|
1349 | else |
---|
1350 | selection_mode = GTK_SELECTION_MULTIPLE; |
---|
1351 | |
---|
1352 | /* get options choice */ |
---|
1353 | draw_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.draw_line_button)->active; |
---|
1354 | view_line = GTK_TOGGLE_BUTTON(sTreeSampleSelection.view_line_button)->active; |
---|
1355 | no_root_item = GTK_TOGGLE_BUTTON(sTreeSampleSelection.no_root_item_button)->active; |
---|
1356 | |
---|
1357 | /* get levels */ |
---|
1358 | nb_item = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.nb_item_spinner)); |
---|
1359 | recursion_level = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sTreeSampleSelection.recursion_spinner)); |
---|
1360 | |
---|
1361 | if (pow (nb_item, recursion_level) > 10000) |
---|
1362 | { |
---|
1363 | g_print ("%g total items? That will take a very long time. Try less\n", |
---|
1364 | pow (nb_item, recursion_level)); |
---|
1365 | return; |
---|
1366 | } |
---|
1367 | |
---|
1368 | create_tree_sample(selection_mode, draw_line, view_line, no_root_item, nb_item, recursion_level); |
---|
1369 | } |
---|
1370 | |
---|
1371 | void |
---|
1372 | create_tree_mode_window(void) |
---|
1373 | { |
---|
1374 | static GtkWidget* window; |
---|
1375 | GtkWidget* box1; |
---|
1376 | GtkWidget* box2; |
---|
1377 | GtkWidget* box3; |
---|
1378 | GtkWidget* box4; |
---|
1379 | GtkWidget* box5; |
---|
1380 | GtkWidget* button; |
---|
1381 | GtkWidget* frame; |
---|
1382 | GtkWidget* separator; |
---|
1383 | GtkWidget* label; |
---|
1384 | GtkWidget* spinner; |
---|
1385 | GtkAdjustment *adj; |
---|
1386 | |
---|
1387 | if (!window) |
---|
1388 | { |
---|
1389 | /* create toplevel window */ |
---|
1390 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
---|
1391 | gtk_window_set_title(GTK_WINDOW(window), "Set Tree Parameters"); |
---|
1392 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
1393 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
1394 | &window); |
---|
1395 | box1 = gtk_vbox_new(FALSE, 0); |
---|
1396 | gtk_container_add(GTK_CONTAINER(window), box1); |
---|
1397 | |
---|
1398 | /* create upper box - selection box */ |
---|
1399 | box2 = gtk_vbox_new(FALSE, 5); |
---|
1400 | gtk_box_pack_start(GTK_BOX(box1), box2, TRUE, TRUE, 0); |
---|
1401 | gtk_container_set_border_width(GTK_CONTAINER(box2), 5); |
---|
1402 | |
---|
1403 | box3 = gtk_hbox_new(FALSE, 5); |
---|
1404 | gtk_box_pack_start(GTK_BOX(box2), box3, TRUE, TRUE, 0); |
---|
1405 | |
---|
1406 | /* create selection mode frame */ |
---|
1407 | frame = gtk_frame_new("Selection Mode"); |
---|
1408 | gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0); |
---|
1409 | |
---|
1410 | box4 = gtk_vbox_new(FALSE, 0); |
---|
1411 | gtk_container_add(GTK_CONTAINER(frame), box4); |
---|
1412 | gtk_container_set_border_width(GTK_CONTAINER(box4), 5); |
---|
1413 | |
---|
1414 | /* create radio button */ |
---|
1415 | button = gtk_radio_button_new_with_label(NULL, "SINGLE"); |
---|
1416 | gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0); |
---|
1417 | sTreeSampleSelection.single_button = button; |
---|
1418 | |
---|
1419 | button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)), |
---|
1420 | "BROWSE"); |
---|
1421 | gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0); |
---|
1422 | sTreeSampleSelection.browse_button = button; |
---|
1423 | |
---|
1424 | button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)), |
---|
1425 | "MULTIPLE"); |
---|
1426 | gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0); |
---|
1427 | sTreeSampleSelection.multiple_button = button; |
---|
1428 | |
---|
1429 | sTreeSampleSelection.selection_mode_group = gtk_radio_button_group (GTK_RADIO_BUTTON (button)); |
---|
1430 | |
---|
1431 | /* create option mode frame */ |
---|
1432 | frame = gtk_frame_new("Options"); |
---|
1433 | gtk_box_pack_start(GTK_BOX(box3), frame, TRUE, TRUE, 0); |
---|
1434 | |
---|
1435 | box4 = gtk_vbox_new(FALSE, 0); |
---|
1436 | gtk_container_add(GTK_CONTAINER(frame), box4); |
---|
1437 | gtk_container_set_border_width(GTK_CONTAINER(box4), 5); |
---|
1438 | |
---|
1439 | /* create check button */ |
---|
1440 | button = gtk_check_button_new_with_label("Draw line"); |
---|
1441 | gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0); |
---|
1442 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); |
---|
1443 | sTreeSampleSelection.draw_line_button = button; |
---|
1444 | |
---|
1445 | button = gtk_check_button_new_with_label("View Line mode"); |
---|
1446 | gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0); |
---|
1447 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); |
---|
1448 | sTreeSampleSelection.view_line_button = button; |
---|
1449 | |
---|
1450 | button = gtk_check_button_new_with_label("Without Root item"); |
---|
1451 | gtk_box_pack_start(GTK_BOX(box4), button, TRUE, TRUE, 0); |
---|
1452 | sTreeSampleSelection.no_root_item_button = button; |
---|
1453 | |
---|
1454 | /* create recursion parameter */ |
---|
1455 | frame = gtk_frame_new("Size Parameters"); |
---|
1456 | gtk_box_pack_start(GTK_BOX(box2), frame, TRUE, TRUE, 0); |
---|
1457 | |
---|
1458 | box4 = gtk_hbox_new(FALSE, 5); |
---|
1459 | gtk_container_add(GTK_CONTAINER(frame), box4); |
---|
1460 | gtk_container_set_border_width(GTK_CONTAINER(box4), 5); |
---|
1461 | |
---|
1462 | /* create number of item spin button */ |
---|
1463 | box5 = gtk_hbox_new(FALSE, 5); |
---|
1464 | gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0); |
---|
1465 | |
---|
1466 | label = gtk_label_new("Number of items : "); |
---|
1467 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
1468 | gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0); |
---|
1469 | |
---|
1470 | adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_NUMBER_OF_ITEM, 1.0, 255.0, 1.0, |
---|
1471 | 5.0, 0.0); |
---|
1472 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
1473 | gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0); |
---|
1474 | sTreeSampleSelection.nb_item_spinner = spinner; |
---|
1475 | |
---|
1476 | /* create recursion level spin button */ |
---|
1477 | box5 = gtk_hbox_new(FALSE, 5); |
---|
1478 | gtk_box_pack_start(GTK_BOX(box4), box5, FALSE, FALSE, 0); |
---|
1479 | |
---|
1480 | label = gtk_label_new("Depth : "); |
---|
1481 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
1482 | gtk_box_pack_start (GTK_BOX (box5), label, FALSE, TRUE, 0); |
---|
1483 | |
---|
1484 | adj = (GtkAdjustment *) gtk_adjustment_new ((gfloat)DEFAULT_RECURSION_LEVEL, 0.0, 255.0, 1.0, |
---|
1485 | 5.0, 0.0); |
---|
1486 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
1487 | gtk_box_pack_start (GTK_BOX (box5), spinner, FALSE, TRUE, 0); |
---|
1488 | sTreeSampleSelection.recursion_spinner = spinner; |
---|
1489 | |
---|
1490 | /* create horizontal separator */ |
---|
1491 | separator = gtk_hseparator_new(); |
---|
1492 | gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, FALSE, 0); |
---|
1493 | |
---|
1494 | /* create bottom button box */ |
---|
1495 | box2 = gtk_hbox_new(TRUE, 10); |
---|
1496 | gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); |
---|
1497 | gtk_container_set_border_width(GTK_CONTAINER(box2), 5); |
---|
1498 | |
---|
1499 | button = gtk_button_new_with_label("Create Tree"); |
---|
1500 | gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); |
---|
1501 | gtk_signal_connect(GTK_OBJECT (button), "clicked", |
---|
1502 | (GtkSignalFunc) cb_create_tree, NULL); |
---|
1503 | |
---|
1504 | button = gtk_button_new_with_label("Close"); |
---|
1505 | gtk_box_pack_start(GTK_BOX(box2), button, TRUE, TRUE, 0); |
---|
1506 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
1507 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
1508 | GTK_OBJECT (window)); |
---|
1509 | } |
---|
1510 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
1511 | gtk_widget_show_all (window); |
---|
1512 | else |
---|
1513 | gtk_widget_destroy (window); |
---|
1514 | } |
---|
1515 | |
---|
1516 | /* |
---|
1517 | * GtkHandleBox |
---|
1518 | */ |
---|
1519 | |
---|
1520 | static void |
---|
1521 | handle_box_child_signal (GtkHandleBox *hb, |
---|
1522 | GtkWidget *child, |
---|
1523 | const gchar *action) |
---|
1524 | { |
---|
1525 | printf ("%s: child <%s> %sed\n", |
---|
1526 | gtk_type_name (GTK_OBJECT_TYPE (hb)), |
---|
1527 | gtk_type_name (GTK_OBJECT_TYPE (child)), |
---|
1528 | action); |
---|
1529 | } |
---|
1530 | |
---|
1531 | static void |
---|
1532 | create_handle_box (void) |
---|
1533 | { |
---|
1534 | static GtkWidget* window = NULL; |
---|
1535 | GtkWidget *handle_box; |
---|
1536 | GtkWidget *handle_box2; |
---|
1537 | GtkWidget *vbox; |
---|
1538 | GtkWidget *hbox; |
---|
1539 | GtkWidget *toolbar; |
---|
1540 | GtkWidget *label; |
---|
1541 | GtkWidget *separator; |
---|
1542 | |
---|
1543 | if (!window) |
---|
1544 | { |
---|
1545 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
1546 | gtk_window_set_title (GTK_WINDOW (window), |
---|
1547 | "Handle Box Test"); |
---|
1548 | gtk_window_set_policy (GTK_WINDOW (window), |
---|
1549 | TRUE, |
---|
1550 | TRUE, |
---|
1551 | TRUE); |
---|
1552 | |
---|
1553 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
1554 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
1555 | &window); |
---|
1556 | |
---|
1557 | gtk_container_set_border_width (GTK_CONTAINER (window), 20); |
---|
1558 | |
---|
1559 | vbox = gtk_vbox_new (FALSE, 0); |
---|
1560 | gtk_container_add (GTK_CONTAINER (window), vbox); |
---|
1561 | gtk_widget_show (vbox); |
---|
1562 | |
---|
1563 | label = gtk_label_new ("Above"); |
---|
1564 | gtk_container_add (GTK_CONTAINER (vbox), label); |
---|
1565 | gtk_widget_show (label); |
---|
1566 | |
---|
1567 | separator = gtk_hseparator_new (); |
---|
1568 | gtk_container_add (GTK_CONTAINER (vbox), separator); |
---|
1569 | gtk_widget_show (separator); |
---|
1570 | |
---|
1571 | hbox = gtk_hbox_new (FALSE, 10); |
---|
1572 | gtk_container_add (GTK_CONTAINER (vbox), hbox); |
---|
1573 | gtk_widget_show (hbox); |
---|
1574 | |
---|
1575 | separator = gtk_hseparator_new (); |
---|
1576 | gtk_container_add (GTK_CONTAINER (vbox), separator); |
---|
1577 | gtk_widget_show (separator); |
---|
1578 | |
---|
1579 | label = gtk_label_new ("Below"); |
---|
1580 | gtk_container_add (GTK_CONTAINER (vbox), label); |
---|
1581 | gtk_widget_show (label); |
---|
1582 | |
---|
1583 | handle_box = gtk_handle_box_new (); |
---|
1584 | gtk_box_pack_start (GTK_BOX (hbox), handle_box, FALSE, FALSE, 0); |
---|
1585 | gtk_signal_connect (GTK_OBJECT (handle_box), |
---|
1586 | "child_attached", |
---|
1587 | GTK_SIGNAL_FUNC (handle_box_child_signal), |
---|
1588 | "attached"); |
---|
1589 | gtk_signal_connect (GTK_OBJECT (handle_box), |
---|
1590 | "child_detached", |
---|
1591 | GTK_SIGNAL_FUNC (handle_box_child_signal), |
---|
1592 | "detached"); |
---|
1593 | gtk_widget_show (handle_box); |
---|
1594 | |
---|
1595 | toolbar = make_toolbar (window); |
---|
1596 | gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NORMAL); |
---|
1597 | gtk_container_add (GTK_CONTAINER (handle_box), toolbar); |
---|
1598 | gtk_widget_show (toolbar); |
---|
1599 | |
---|
1600 | handle_box = gtk_handle_box_new (); |
---|
1601 | gtk_box_pack_start (GTK_BOX (hbox), handle_box, FALSE, FALSE, 0); |
---|
1602 | gtk_signal_connect (GTK_OBJECT (handle_box), |
---|
1603 | "child_attached", |
---|
1604 | GTK_SIGNAL_FUNC (handle_box_child_signal), |
---|
1605 | "attached"); |
---|
1606 | gtk_signal_connect (GTK_OBJECT (handle_box), |
---|
1607 | "child_detached", |
---|
1608 | GTK_SIGNAL_FUNC (handle_box_child_signal), |
---|
1609 | "detached"); |
---|
1610 | gtk_widget_show (handle_box); |
---|
1611 | |
---|
1612 | handle_box2 = gtk_handle_box_new (); |
---|
1613 | gtk_container_add (GTK_CONTAINER (handle_box), handle_box2); |
---|
1614 | gtk_signal_connect (GTK_OBJECT (handle_box2), |
---|
1615 | "child_attached", |
---|
1616 | GTK_SIGNAL_FUNC (handle_box_child_signal), |
---|
1617 | "attached"); |
---|
1618 | gtk_signal_connect (GTK_OBJECT (handle_box2), |
---|
1619 | "child_detached", |
---|
1620 | GTK_SIGNAL_FUNC (handle_box_child_signal), |
---|
1621 | "detached"); |
---|
1622 | gtk_widget_show (handle_box2); |
---|
1623 | |
---|
1624 | label = gtk_label_new ("Fooo!"); |
---|
1625 | gtk_container_add (GTK_CONTAINER (handle_box2), label); |
---|
1626 | gtk_widget_show (label); |
---|
1627 | } |
---|
1628 | |
---|
1629 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
1630 | gtk_widget_show (window); |
---|
1631 | else |
---|
1632 | gtk_widget_destroy (window); |
---|
1633 | } |
---|
1634 | |
---|
1635 | /* |
---|
1636 | * Label Demo |
---|
1637 | */ |
---|
1638 | void create_labels (void) |
---|
1639 | { |
---|
1640 | static GtkWidget *window = NULL; |
---|
1641 | GtkWidget *hbox; |
---|
1642 | GtkWidget *vbox; |
---|
1643 | GtkWidget *frame; |
---|
1644 | GtkWidget *label; |
---|
1645 | |
---|
1646 | if (!window) |
---|
1647 | { |
---|
1648 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
1649 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
1650 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
1651 | &window); |
---|
1652 | |
---|
1653 | gtk_window_set_title (GTK_WINDOW (window), "Label"); |
---|
1654 | vbox = gtk_vbox_new (FALSE, 5); |
---|
1655 | hbox = gtk_hbox_new (FALSE, 5); |
---|
1656 | gtk_container_add (GTK_CONTAINER (window), hbox); |
---|
1657 | gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); |
---|
1658 | gtk_container_set_border_width (GTK_CONTAINER (window), 5); |
---|
1659 | |
---|
1660 | frame = gtk_frame_new ("Normal Label"); |
---|
1661 | label = gtk_label_new ("This is a Normal label"); |
---|
1662 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1663 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1664 | |
---|
1665 | frame = gtk_frame_new ("Multi-line Label"); |
---|
1666 | label = gtk_label_new ("This is a Multi-line label.\nSecond line\nThird line"); |
---|
1667 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1668 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1669 | |
---|
1670 | frame = gtk_frame_new ("Left Justified Label"); |
---|
1671 | label = gtk_label_new ("This is a Left-Justified\nMulti-line label.\nThird line"); |
---|
1672 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); |
---|
1673 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1674 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1675 | |
---|
1676 | frame = gtk_frame_new ("Right Justified Label"); |
---|
1677 | label = gtk_label_new ("This is a Right-Justified\nMulti-line label.\nFourth line, (j/k)"); |
---|
1678 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT); |
---|
1679 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1680 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1681 | |
---|
1682 | vbox = gtk_vbox_new (FALSE, 5); |
---|
1683 | gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); |
---|
1684 | frame = gtk_frame_new ("Line wrapped label"); |
---|
1685 | label = gtk_label_new ("This is an example of a line-wrapped label. It should not be taking "\ |
---|
1686 | "up the entire "/* big space to test spacing */\ |
---|
1687 | "width allocated to it, but automatically wraps the words to fit. "\ |
---|
1688 | "The time has come, for all good men, to come to the aid of their party. "\ |
---|
1689 | "The sixth sheik's six sheep's sick.\n"\ |
---|
1690 | " It supports multiple paragraphs correctly, and correctly adds "\ |
---|
1691 | "many extra spaces. "); |
---|
1692 | |
---|
1693 | gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); |
---|
1694 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1695 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1696 | |
---|
1697 | frame = gtk_frame_new ("Filled, wrapped label"); |
---|
1698 | label = gtk_label_new ("This is an example of a line-wrapped, filled label. It should be taking "\ |
---|
1699 | "up the entire width allocated to it. Here is a seneance to prove "\ |
---|
1700 | "my point. Here is another sentence. "\ |
---|
1701 | "Here comes the sun, do de do de do.\n"\ |
---|
1702 | " This is a new paragraph.\n"\ |
---|
1703 | " This is another newer, longer, better paragraph. It is coming to an end, "\ |
---|
1704 | "unfortunately."); |
---|
1705 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL); |
---|
1706 | gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); |
---|
1707 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1708 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1709 | |
---|
1710 | frame = gtk_frame_new ("Underlined label"); |
---|
1711 | label = gtk_label_new ("This label is underlined!\n" |
---|
1712 | "This one is underlined in ÆüËܸì¤ÎÆþÍÑquite a funky fashion"); |
---|
1713 | gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); |
---|
1714 | gtk_label_set_pattern (GTK_LABEL (label), "_________________________ _ _________ _ _____ _ __ __ ___ ____ _____"); |
---|
1715 | gtk_container_add (GTK_CONTAINER (frame), label); |
---|
1716 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); |
---|
1717 | |
---|
1718 | } |
---|
1719 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
1720 | gtk_widget_show_all (window); |
---|
1721 | else |
---|
1722 | gtk_widget_destroy (window); |
---|
1723 | } |
---|
1724 | |
---|
1725 | /* |
---|
1726 | * Reparent demo |
---|
1727 | */ |
---|
1728 | |
---|
1729 | static void |
---|
1730 | reparent_label (GtkWidget *widget, |
---|
1731 | GtkWidget *new_parent) |
---|
1732 | { |
---|
1733 | GtkWidget *label; |
---|
1734 | |
---|
1735 | label = gtk_object_get_user_data (GTK_OBJECT (widget)); |
---|
1736 | |
---|
1737 | gtk_widget_reparent (label, new_parent); |
---|
1738 | } |
---|
1739 | |
---|
1740 | static void |
---|
1741 | set_parent_signal (GtkWidget *child, |
---|
1742 | GtkWidget *old_parent, |
---|
1743 | gpointer func_data) |
---|
1744 | { |
---|
1745 | g_print ("set_parent for \"%s\": new parent: \"%s\", old parent: \"%s\", data: %d\n", |
---|
1746 | gtk_type_name (GTK_OBJECT_TYPE (child)), |
---|
1747 | child->parent ? gtk_type_name (GTK_OBJECT_TYPE (child->parent)) : "NULL", |
---|
1748 | old_parent ? gtk_type_name (GTK_OBJECT_TYPE (old_parent)) : "NULL", |
---|
1749 | GPOINTER_TO_INT (func_data)); |
---|
1750 | } |
---|
1751 | |
---|
1752 | static void |
---|
1753 | create_reparent (void) |
---|
1754 | { |
---|
1755 | static GtkWidget *window = NULL; |
---|
1756 | GtkWidget *box1; |
---|
1757 | GtkWidget *box2; |
---|
1758 | GtkWidget *box3; |
---|
1759 | GtkWidget *frame; |
---|
1760 | GtkWidget *button; |
---|
1761 | GtkWidget *label; |
---|
1762 | GtkWidget *separator; |
---|
1763 | |
---|
1764 | if (!window) |
---|
1765 | { |
---|
1766 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
1767 | |
---|
1768 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
1769 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
1770 | &window); |
---|
1771 | |
---|
1772 | gtk_window_set_title (GTK_WINDOW (window), "reparent"); |
---|
1773 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
1774 | |
---|
1775 | box1 = gtk_vbox_new (FALSE, 0); |
---|
1776 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
1777 | |
---|
1778 | box2 = gtk_hbox_new (FALSE, 5); |
---|
1779 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
1780 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
1781 | |
---|
1782 | label = gtk_label_new ("Hello World"); |
---|
1783 | |
---|
1784 | frame = gtk_frame_new ("Frame 1"); |
---|
1785 | gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0); |
---|
1786 | |
---|
1787 | box3 = gtk_vbox_new (FALSE, 5); |
---|
1788 | gtk_container_set_border_width (GTK_CONTAINER (box3), 5); |
---|
1789 | gtk_container_add (GTK_CONTAINER (frame), box3); |
---|
1790 | |
---|
1791 | button = gtk_button_new_with_label ("switch"); |
---|
1792 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
1793 | GTK_SIGNAL_FUNC(reparent_label), |
---|
1794 | box3); |
---|
1795 | gtk_object_set_user_data (GTK_OBJECT (button), label); |
---|
1796 | gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0); |
---|
1797 | |
---|
1798 | gtk_box_pack_start (GTK_BOX (box3), label, FALSE, TRUE, 0); |
---|
1799 | gtk_signal_connect (GTK_OBJECT (label), |
---|
1800 | "parent_set", |
---|
1801 | GTK_SIGNAL_FUNC (set_parent_signal), |
---|
1802 | GINT_TO_POINTER (42)); |
---|
1803 | |
---|
1804 | frame = gtk_frame_new ("Frame 2"); |
---|
1805 | gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0); |
---|
1806 | |
---|
1807 | box3 = gtk_vbox_new (FALSE, 5); |
---|
1808 | gtk_container_set_border_width (GTK_CONTAINER (box3), 5); |
---|
1809 | gtk_container_add (GTK_CONTAINER (frame), box3); |
---|
1810 | |
---|
1811 | button = gtk_button_new_with_label ("switch"); |
---|
1812 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
1813 | GTK_SIGNAL_FUNC(reparent_label), |
---|
1814 | box3); |
---|
1815 | gtk_object_set_user_data (GTK_OBJECT (button), label); |
---|
1816 | gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0); |
---|
1817 | |
---|
1818 | separator = gtk_hseparator_new (); |
---|
1819 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
1820 | |
---|
1821 | box2 = gtk_vbox_new (FALSE, 10); |
---|
1822 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
1823 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
1824 | |
---|
1825 | button = gtk_button_new_with_label ("close"); |
---|
1826 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
1827 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
1828 | GTK_OBJECT (window)); |
---|
1829 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
1830 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
1831 | gtk_widget_grab_default (button); |
---|
1832 | } |
---|
1833 | |
---|
1834 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
1835 | gtk_widget_show_all (window); |
---|
1836 | else |
---|
1837 | gtk_widget_destroy (window); |
---|
1838 | } |
---|
1839 | |
---|
1840 | /* |
---|
1841 | * Saved Position |
---|
1842 | */ |
---|
1843 | gint upositionx = 0; |
---|
1844 | gint upositiony = 0; |
---|
1845 | |
---|
1846 | static gint |
---|
1847 | uposition_configure (GtkWidget *window) |
---|
1848 | { |
---|
1849 | GtkLabel *lx; |
---|
1850 | GtkLabel *ly; |
---|
1851 | gchar buffer[64]; |
---|
1852 | |
---|
1853 | lx = gtk_object_get_data (GTK_OBJECT (window), "x"); |
---|
1854 | ly = gtk_object_get_data (GTK_OBJECT (window), "y"); |
---|
1855 | |
---|
1856 | gdk_window_get_root_origin (window->window, &upositionx, &upositiony); |
---|
1857 | sprintf (buffer, "%d", upositionx); |
---|
1858 | gtk_label_set_text (lx, buffer); |
---|
1859 | sprintf (buffer, "%d", upositiony); |
---|
1860 | gtk_label_set_text (ly, buffer); |
---|
1861 | |
---|
1862 | return FALSE; |
---|
1863 | } |
---|
1864 | |
---|
1865 | static void |
---|
1866 | create_saved_position (void) |
---|
1867 | { |
---|
1868 | static GtkWidget *window = NULL; |
---|
1869 | |
---|
1870 | if (!window) |
---|
1871 | { |
---|
1872 | GtkWidget *hbox; |
---|
1873 | GtkWidget *main_vbox; |
---|
1874 | GtkWidget *vbox; |
---|
1875 | GtkWidget *x_label; |
---|
1876 | GtkWidget *y_label; |
---|
1877 | GtkWidget *button; |
---|
1878 | GtkWidget *label; |
---|
1879 | GtkWidget *any; |
---|
1880 | |
---|
1881 | window = gtk_widget_new (GTK_TYPE_WINDOW, |
---|
1882 | "type", GTK_WINDOW_TOPLEVEL, |
---|
1883 | "signal::configure_event", uposition_configure, NULL, |
---|
1884 | "x", upositionx, |
---|
1885 | "y", upositiony, |
---|
1886 | "title", "Saved Position", |
---|
1887 | NULL); |
---|
1888 | |
---|
1889 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
1890 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
1891 | &window); |
---|
1892 | |
---|
1893 | main_vbox = gtk_vbox_new (FALSE, 5); |
---|
1894 | gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 0); |
---|
1895 | gtk_container_add (GTK_CONTAINER (window), main_vbox); |
---|
1896 | |
---|
1897 | vbox = |
---|
1898 | gtk_widget_new (gtk_vbox_get_type (), |
---|
1899 | "GtkBox::homogeneous", FALSE, |
---|
1900 | "GtkBox::spacing", 5, |
---|
1901 | "GtkContainer::border_width", 10, |
---|
1902 | "GtkWidget::parent", main_vbox, |
---|
1903 | "GtkWidget::visible", TRUE, |
---|
1904 | NULL); |
---|
1905 | |
---|
1906 | hbox = gtk_hbox_new (FALSE, 0); |
---|
1907 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
1908 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); |
---|
1909 | |
---|
1910 | label = gtk_label_new ("X Origin : "); |
---|
1911 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
1912 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
1913 | |
---|
1914 | x_label = gtk_label_new (""); |
---|
1915 | gtk_box_pack_start (GTK_BOX (hbox), x_label, TRUE, TRUE, 0); |
---|
1916 | gtk_object_set_data (GTK_OBJECT (window), "x", x_label); |
---|
1917 | |
---|
1918 | hbox = gtk_hbox_new (FALSE, 0); |
---|
1919 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
1920 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); |
---|
1921 | |
---|
1922 | label = gtk_label_new ("Y Origin : "); |
---|
1923 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
1924 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
1925 | |
---|
1926 | y_label = gtk_label_new (""); |
---|
1927 | gtk_box_pack_start (GTK_BOX (hbox), y_label, TRUE, TRUE, 0); |
---|
1928 | gtk_object_set_data (GTK_OBJECT (window), "y", y_label); |
---|
1929 | |
---|
1930 | any = |
---|
1931 | gtk_widget_new (gtk_hseparator_get_type (), |
---|
1932 | "GtkWidget::visible", TRUE, |
---|
1933 | NULL); |
---|
1934 | gtk_box_pack_start (GTK_BOX (main_vbox), any, FALSE, TRUE, 0); |
---|
1935 | |
---|
1936 | hbox = gtk_hbox_new (FALSE, 0); |
---|
1937 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); |
---|
1938 | gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0); |
---|
1939 | |
---|
1940 | button = gtk_button_new_with_label ("Close"); |
---|
1941 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
1942 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
1943 | GTK_OBJECT (window)); |
---|
1944 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
1945 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
1946 | gtk_widget_grab_default (button); |
---|
1947 | |
---|
1948 | gtk_widget_show_all (window); |
---|
1949 | } |
---|
1950 | else |
---|
1951 | gtk_widget_destroy (window); |
---|
1952 | } |
---|
1953 | |
---|
1954 | /* |
---|
1955 | * GtkPixmap |
---|
1956 | */ |
---|
1957 | |
---|
1958 | static void |
---|
1959 | create_pixmap (void) |
---|
1960 | { |
---|
1961 | static GtkWidget *window = NULL; |
---|
1962 | GtkWidget *box1; |
---|
1963 | GtkWidget *box2; |
---|
1964 | GtkWidget *box3; |
---|
1965 | GtkWidget *button; |
---|
1966 | GtkWidget *label; |
---|
1967 | GtkWidget *separator; |
---|
1968 | GtkWidget *pixmapwid; |
---|
1969 | GdkPixmap *pixmap; |
---|
1970 | GdkBitmap *mask; |
---|
1971 | |
---|
1972 | if (!window) |
---|
1973 | { |
---|
1974 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
1975 | |
---|
1976 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
1977 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
1978 | &window); |
---|
1979 | |
---|
1980 | gtk_window_set_title (GTK_WINDOW (window), "GtkPixmap"); |
---|
1981 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
1982 | gtk_widget_realize(window); |
---|
1983 | |
---|
1984 | box1 = gtk_vbox_new (FALSE, 0); |
---|
1985 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
1986 | |
---|
1987 | box2 = gtk_vbox_new (FALSE, 10); |
---|
1988 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
1989 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
1990 | |
---|
1991 | button = gtk_button_new (); |
---|
1992 | gtk_box_pack_start (GTK_BOX (box2), button, FALSE, FALSE, 0); |
---|
1993 | |
---|
1994 | pixmap = gdk_pixmap_create_from_xpm (window->window, &mask, NULL, |
---|
1995 | "test.xpm"); |
---|
1996 | pixmapwid = gtk_pixmap_new (pixmap, mask); |
---|
1997 | gdk_pixmap_unref (pixmap); |
---|
1998 | gdk_pixmap_unref (mask); |
---|
1999 | |
---|
2000 | label = gtk_label_new ("Pixmap\ntest"); |
---|
2001 | box3 = gtk_hbox_new (FALSE, 0); |
---|
2002 | gtk_container_set_border_width (GTK_CONTAINER (box3), 2); |
---|
2003 | gtk_container_add (GTK_CONTAINER (box3), pixmapwid); |
---|
2004 | gtk_container_add (GTK_CONTAINER (box3), label); |
---|
2005 | gtk_container_add (GTK_CONTAINER (button), box3); |
---|
2006 | |
---|
2007 | separator = gtk_hseparator_new (); |
---|
2008 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
2009 | |
---|
2010 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2011 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2012 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
2013 | |
---|
2014 | button = gtk_button_new_with_label ("close"); |
---|
2015 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
2016 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2017 | GTK_OBJECT (window)); |
---|
2018 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2019 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2020 | gtk_widget_grab_default (button); |
---|
2021 | } |
---|
2022 | |
---|
2023 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
2024 | gtk_widget_show_all (window); |
---|
2025 | else |
---|
2026 | gtk_widget_destroy (window); |
---|
2027 | } |
---|
2028 | |
---|
2029 | static void |
---|
2030 | tips_query_widget_entered (GtkTipsQuery *tips_query, |
---|
2031 | GtkWidget *widget, |
---|
2032 | const gchar *tip_text, |
---|
2033 | const gchar *tip_private, |
---|
2034 | GtkWidget *toggle) |
---|
2035 | { |
---|
2036 | if (GTK_TOGGLE_BUTTON (toggle)->active) |
---|
2037 | { |
---|
2038 | gtk_label_set_text (GTK_LABEL (tips_query), tip_text ? "There is a Tip!" : "There is no Tip!"); |
---|
2039 | /* don't let GtkTipsQuery reset its label */ |
---|
2040 | gtk_signal_emit_stop_by_name (GTK_OBJECT (tips_query), "widget_entered"); |
---|
2041 | } |
---|
2042 | } |
---|
2043 | |
---|
2044 | static gint |
---|
2045 | tips_query_widget_selected (GtkWidget *tips_query, |
---|
2046 | GtkWidget *widget, |
---|
2047 | const gchar *tip_text, |
---|
2048 | const gchar *tip_private, |
---|
2049 | GdkEventButton *event, |
---|
2050 | gpointer func_data) |
---|
2051 | { |
---|
2052 | if (widget) |
---|
2053 | g_print ("Help \"%s\" requested for <%s>\n", |
---|
2054 | tip_private ? tip_private : "None", |
---|
2055 | gtk_type_name (GTK_OBJECT_TYPE (widget))); |
---|
2056 | return TRUE; |
---|
2057 | } |
---|
2058 | |
---|
2059 | static void |
---|
2060 | create_tooltips (void) |
---|
2061 | { |
---|
2062 | static GtkWidget *window = NULL; |
---|
2063 | GtkWidget *box1; |
---|
2064 | GtkWidget *box2; |
---|
2065 | GtkWidget *box3; |
---|
2066 | GtkWidget *button; |
---|
2067 | GtkWidget *toggle; |
---|
2068 | GtkWidget *frame; |
---|
2069 | GtkWidget *tips_query; |
---|
2070 | GtkWidget *separator; |
---|
2071 | GtkTooltips *tooltips; |
---|
2072 | |
---|
2073 | if (!window) |
---|
2074 | { |
---|
2075 | window = |
---|
2076 | gtk_widget_new (gtk_window_get_type (), |
---|
2077 | "GtkWindow::type", GTK_WINDOW_TOPLEVEL, |
---|
2078 | "GtkContainer::border_width", 0, |
---|
2079 | "GtkWindow::title", "Tooltips", |
---|
2080 | "GtkWindow::allow_shrink", TRUE, |
---|
2081 | "GtkWindow::allow_grow", FALSE, |
---|
2082 | "GtkWindow::auto_shrink", TRUE, |
---|
2083 | "GtkWidget::width", 200, |
---|
2084 | NULL); |
---|
2085 | |
---|
2086 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2087 | GTK_SIGNAL_FUNC (destroy_tooltips), |
---|
2088 | &window); |
---|
2089 | |
---|
2090 | tooltips=gtk_tooltips_new(); |
---|
2091 | gtk_object_set_data (GTK_OBJECT (window), "tooltips", tooltips); |
---|
2092 | |
---|
2093 | box1 = gtk_vbox_new (FALSE, 0); |
---|
2094 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
2095 | |
---|
2096 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2097 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2098 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
2099 | |
---|
2100 | button = gtk_toggle_button_new_with_label ("button1"); |
---|
2101 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2102 | |
---|
2103 | gtk_tooltips_set_tip (tooltips,button,"This is button 1", "ContextHelp/buttons/1"); |
---|
2104 | |
---|
2105 | button = gtk_toggle_button_new_with_label ("button2"); |
---|
2106 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2107 | |
---|
2108 | gtk_tooltips_set_tip (tooltips, |
---|
2109 | button, |
---|
2110 | "This is button 2. This is also a really long tooltip which probably won't fit on a single line and will therefore need to be wrapped. Hopefully the wrapping will work correctly.", |
---|
2111 | "ContextHelp/buttons/2_long"); |
---|
2112 | |
---|
2113 | toggle = gtk_toggle_button_new_with_label ("Override TipsQuery Label"); |
---|
2114 | gtk_box_pack_start (GTK_BOX (box2), toggle, TRUE, TRUE, 0); |
---|
2115 | |
---|
2116 | gtk_tooltips_set_tip (tooltips, toggle, "Toggle TipsQuery view.", "Hi msw! ;)"); |
---|
2117 | |
---|
2118 | box3 = |
---|
2119 | gtk_widget_new (gtk_vbox_get_type (), |
---|
2120 | "GtkBox::homogeneous", FALSE, |
---|
2121 | "GtkBox::spacing", 5, |
---|
2122 | "GtkContainer::border_width", 5, |
---|
2123 | "GtkWidget::visible", TRUE, |
---|
2124 | NULL); |
---|
2125 | |
---|
2126 | tips_query = gtk_tips_query_new (); |
---|
2127 | |
---|
2128 | button = |
---|
2129 | gtk_widget_new (gtk_button_get_type (), |
---|
2130 | "GtkButton::label", "[?]", |
---|
2131 | "GtkWidget::visible", TRUE, |
---|
2132 | "GtkWidget::parent", box3, |
---|
2133 | "GtkObject::object_signal::clicked", gtk_tips_query_start_query, tips_query, |
---|
2134 | NULL); |
---|
2135 | gtk_box_set_child_packing (GTK_BOX (box3), button, FALSE, FALSE, 0, GTK_PACK_START); |
---|
2136 | gtk_tooltips_set_tip (tooltips, |
---|
2137 | button, |
---|
2138 | "Start the Tooltips Inspector", |
---|
2139 | "ContextHelp/buttons/?"); |
---|
2140 | |
---|
2141 | |
---|
2142 | gtk_widget_set (tips_query, |
---|
2143 | "GtkWidget::visible", TRUE, |
---|
2144 | "GtkWidget::parent", box3, |
---|
2145 | "GtkTipsQuery::caller", button, |
---|
2146 | "GtkObject::signal::widget_entered", tips_query_widget_entered, toggle, |
---|
2147 | "GtkObject::signal::widget_selected", tips_query_widget_selected, NULL, |
---|
2148 | NULL); |
---|
2149 | |
---|
2150 | frame = |
---|
2151 | gtk_widget_new (gtk_frame_get_type (), |
---|
2152 | "GtkFrame::label", "ToolTips Inspector", |
---|
2153 | "GtkFrame::label_xalign", (double) 0.5, |
---|
2154 | "GtkContainer::border_width", 0, |
---|
2155 | "GtkWidget::visible", TRUE, |
---|
2156 | "GtkWidget::parent", box2, |
---|
2157 | "GtkContainer::child", box3, |
---|
2158 | NULL); |
---|
2159 | gtk_box_set_child_packing (GTK_BOX (box2), frame, TRUE, TRUE, 10, GTK_PACK_START); |
---|
2160 | |
---|
2161 | separator = gtk_hseparator_new (); |
---|
2162 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
2163 | |
---|
2164 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2165 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2166 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
2167 | |
---|
2168 | button = gtk_button_new_with_label ("close"); |
---|
2169 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
2170 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2171 | GTK_OBJECT (window)); |
---|
2172 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2173 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2174 | gtk_widget_grab_default (button); |
---|
2175 | |
---|
2176 | gtk_tooltips_set_tip (tooltips, button, "Push this button to close window", "ContextHelp/buttons/Close"); |
---|
2177 | } |
---|
2178 | |
---|
2179 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
2180 | gtk_widget_show_all (window); |
---|
2181 | else |
---|
2182 | gtk_widget_destroy (window); |
---|
2183 | } |
---|
2184 | |
---|
2185 | /* |
---|
2186 | * Menu demo |
---|
2187 | */ |
---|
2188 | |
---|
2189 | static GtkWidget* |
---|
2190 | create_menu (gint depth, gboolean tearoff) |
---|
2191 | { |
---|
2192 | GtkWidget *menu; |
---|
2193 | GtkWidget *menuitem; |
---|
2194 | GSList *group; |
---|
2195 | char buf[32]; |
---|
2196 | int i, j; |
---|
2197 | |
---|
2198 | if (depth < 1) |
---|
2199 | return NULL; |
---|
2200 | |
---|
2201 | menu = gtk_menu_new (); |
---|
2202 | group = NULL; |
---|
2203 | |
---|
2204 | if (tearoff) |
---|
2205 | { |
---|
2206 | menuitem = gtk_tearoff_menu_item_new (); |
---|
2207 | gtk_menu_append (GTK_MENU (menu), menuitem); |
---|
2208 | gtk_widget_show (menuitem); |
---|
2209 | } |
---|
2210 | |
---|
2211 | for (i = 0, j = 1; i < 5; i++, j++) |
---|
2212 | { |
---|
2213 | sprintf (buf, "item %2d - %d", depth, j); |
---|
2214 | menuitem = gtk_radio_menu_item_new_with_label (group, buf); |
---|
2215 | group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); |
---|
2216 | if (depth % 2) |
---|
2217 | gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (menuitem), TRUE); |
---|
2218 | gtk_menu_append (GTK_MENU (menu), menuitem); |
---|
2219 | gtk_widget_show (menuitem); |
---|
2220 | if (i == 3) |
---|
2221 | gtk_widget_set_sensitive (menuitem, FALSE); |
---|
2222 | |
---|
2223 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE)); |
---|
2224 | } |
---|
2225 | |
---|
2226 | return menu; |
---|
2227 | } |
---|
2228 | |
---|
2229 | static void |
---|
2230 | create_menus (void) |
---|
2231 | { |
---|
2232 | static GtkWidget *window = NULL; |
---|
2233 | GtkWidget *box1; |
---|
2234 | GtkWidget *box2; |
---|
2235 | GtkWidget *button; |
---|
2236 | GtkWidget *optionmenu; |
---|
2237 | GtkWidget *separator; |
---|
2238 | |
---|
2239 | if (!window) |
---|
2240 | { |
---|
2241 | GtkWidget *menubar; |
---|
2242 | GtkWidget *menu; |
---|
2243 | GtkWidget *menuitem; |
---|
2244 | GtkAccelGroup *accel_group; |
---|
2245 | |
---|
2246 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
2247 | |
---|
2248 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2249 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
2250 | &window); |
---|
2251 | gtk_signal_connect (GTK_OBJECT (window), "delete-event", |
---|
2252 | GTK_SIGNAL_FUNC (gtk_true), |
---|
2253 | NULL); |
---|
2254 | |
---|
2255 | accel_group = gtk_accel_group_new (); |
---|
2256 | gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); |
---|
2257 | |
---|
2258 | gtk_window_set_title (GTK_WINDOW (window), "menus"); |
---|
2259 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
2260 | |
---|
2261 | |
---|
2262 | box1 = gtk_vbox_new (FALSE, 0); |
---|
2263 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
2264 | gtk_widget_show (box1); |
---|
2265 | |
---|
2266 | menubar = gtk_menu_bar_new (); |
---|
2267 | gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0); |
---|
2268 | gtk_widget_show (menubar); |
---|
2269 | |
---|
2270 | menu = create_menu (2, TRUE); |
---|
2271 | |
---|
2272 | menuitem = gtk_menu_item_new_with_label ("test\nline2"); |
---|
2273 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu); |
---|
2274 | gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); |
---|
2275 | gtk_widget_show (menuitem); |
---|
2276 | |
---|
2277 | menuitem = gtk_menu_item_new_with_label ("foo"); |
---|
2278 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, TRUE)); |
---|
2279 | gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); |
---|
2280 | gtk_widget_show (menuitem); |
---|
2281 | |
---|
2282 | menuitem = gtk_menu_item_new_with_label ("bar"); |
---|
2283 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, TRUE)); |
---|
2284 | gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem)); |
---|
2285 | gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem); |
---|
2286 | gtk_widget_show (menuitem); |
---|
2287 | |
---|
2288 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2289 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2290 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
2291 | gtk_widget_show (box2); |
---|
2292 | |
---|
2293 | menu = create_menu (1, FALSE); |
---|
2294 | gtk_menu_set_accel_group (GTK_MENU (menu), accel_group); |
---|
2295 | |
---|
2296 | menuitem = gtk_check_menu_item_new_with_label ("Accelerate Me"); |
---|
2297 | gtk_menu_append (GTK_MENU (menu), menuitem); |
---|
2298 | gtk_widget_show (menuitem); |
---|
2299 | gtk_widget_add_accelerator (menuitem, |
---|
2300 | "activate", |
---|
2301 | accel_group, |
---|
2302 | GDK_F1, |
---|
2303 | 0, |
---|
2304 | GTK_ACCEL_VISIBLE | GTK_ACCEL_SIGNAL_VISIBLE); |
---|
2305 | menuitem = gtk_check_menu_item_new_with_label ("Accelerator Locked"); |
---|
2306 | gtk_menu_append (GTK_MENU (menu), menuitem); |
---|
2307 | gtk_widget_show (menuitem); |
---|
2308 | gtk_widget_add_accelerator (menuitem, |
---|
2309 | "activate", |
---|
2310 | accel_group, |
---|
2311 | GDK_F2, |
---|
2312 | 0, |
---|
2313 | GTK_ACCEL_VISIBLE | GTK_ACCEL_LOCKED); |
---|
2314 | menuitem = gtk_check_menu_item_new_with_label ("Accelerators Frozen"); |
---|
2315 | gtk_menu_append (GTK_MENU (menu), menuitem); |
---|
2316 | gtk_widget_show (menuitem); |
---|
2317 | gtk_widget_add_accelerator (menuitem, |
---|
2318 | "activate", |
---|
2319 | accel_group, |
---|
2320 | GDK_F2, |
---|
2321 | 0, |
---|
2322 | GTK_ACCEL_VISIBLE); |
---|
2323 | gtk_widget_add_accelerator (menuitem, |
---|
2324 | "activate", |
---|
2325 | accel_group, |
---|
2326 | GDK_F3, |
---|
2327 | 0, |
---|
2328 | GTK_ACCEL_VISIBLE); |
---|
2329 | gtk_widget_lock_accelerators (menuitem); |
---|
2330 | |
---|
2331 | optionmenu = gtk_option_menu_new (); |
---|
2332 | gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu); |
---|
2333 | gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), 3); |
---|
2334 | gtk_box_pack_start (GTK_BOX (box2), optionmenu, TRUE, TRUE, 0); |
---|
2335 | gtk_widget_show (optionmenu); |
---|
2336 | |
---|
2337 | separator = gtk_hseparator_new (); |
---|
2338 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
2339 | gtk_widget_show (separator); |
---|
2340 | |
---|
2341 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2342 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2343 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
2344 | gtk_widget_show (box2); |
---|
2345 | |
---|
2346 | button = gtk_button_new_with_label ("close"); |
---|
2347 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
2348 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2349 | GTK_OBJECT (window)); |
---|
2350 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2351 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2352 | gtk_widget_grab_default (button); |
---|
2353 | gtk_widget_show (button); |
---|
2354 | } |
---|
2355 | |
---|
2356 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
2357 | gtk_widget_show (window); |
---|
2358 | else |
---|
2359 | gtk_widget_destroy (window); |
---|
2360 | } |
---|
2361 | |
---|
2362 | static void |
---|
2363 | gtk_ifactory_cb (gpointer callback_data, |
---|
2364 | guint callback_action, |
---|
2365 | GtkWidget *widget) |
---|
2366 | { |
---|
2367 | g_message ("ItemFactory: activated \"%s\"", gtk_item_factory_path_from_widget (widget)); |
---|
2368 | } |
---|
2369 | |
---|
2370 | static GtkItemFactoryEntry menu_items[] = |
---|
2371 | { |
---|
2372 | { "/_File", NULL, 0, 0, "<Branch>" }, |
---|
2373 | { "/File/tearoff1", NULL, gtk_ifactory_cb, 0, "<Tearoff>" }, |
---|
2374 | { "/File/_New", "<control>N", gtk_ifactory_cb, 0 }, |
---|
2375 | { "/File/_Open", "<control>O", gtk_ifactory_cb, 0 }, |
---|
2376 | { "/File/_Save", "<control>S", gtk_ifactory_cb, 0 }, |
---|
2377 | { "/File/Save _As...", NULL, gtk_ifactory_cb, 0 }, |
---|
2378 | { "/File/sep1", NULL, gtk_ifactory_cb, 0, "<Separator>" }, |
---|
2379 | { "/File/_Quit", "<control>Q", gtk_ifactory_cb, 0 }, |
---|
2380 | |
---|
2381 | { "/_Preferences", NULL, 0, 0, "<Branch>" }, |
---|
2382 | { "/_Preferences/_Color", NULL, 0, 0, "<Branch>" }, |
---|
2383 | { "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, |
---|
2384 | { "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, |
---|
2385 | { "/_Preferences/Color/_Blue", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" }, |
---|
2386 | { "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" }, |
---|
2387 | { "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" }, |
---|
2388 | { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" }, |
---|
2389 | { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" }, |
---|
2390 | { "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" }, |
---|
2391 | { "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" }, |
---|
2392 | |
---|
2393 | /* For testing deletion of menus */ |
---|
2394 | { "/_Preferences/Should_NotAppear", NULL, 0, 0, "<Branch>" }, |
---|
2395 | { "/Preferences/ShouldNotAppear/SubItem1", NULL, gtk_ifactory_cb, 0 }, |
---|
2396 | { "/Preferences/ShouldNotAppear/SubItem2", NULL, gtk_ifactory_cb, 0 }, |
---|
2397 | |
---|
2398 | { "/_Help", NULL, 0, 0, "<LastBranch>" }, |
---|
2399 | { "/Help/_About", NULL, gtk_ifactory_cb, 0 }, |
---|
2400 | }; |
---|
2401 | |
---|
2402 | |
---|
2403 | static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); |
---|
2404 | |
---|
2405 | static void |
---|
2406 | create_item_factory (void) |
---|
2407 | { |
---|
2408 | static GtkWidget *window = NULL; |
---|
2409 | |
---|
2410 | if (!window) |
---|
2411 | { |
---|
2412 | GtkWidget *box1; |
---|
2413 | GtkWidget *box2; |
---|
2414 | GtkWidget *separator; |
---|
2415 | GtkWidget *label; |
---|
2416 | GtkWidget *button; |
---|
2417 | GtkAccelGroup *accel_group; |
---|
2418 | GtkItemFactory *item_factory; |
---|
2419 | |
---|
2420 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
2421 | |
---|
2422 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2423 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
2424 | &window); |
---|
2425 | gtk_signal_connect (GTK_OBJECT (window), "delete-event", |
---|
2426 | GTK_SIGNAL_FUNC (gtk_true), |
---|
2427 | NULL); |
---|
2428 | |
---|
2429 | accel_group = gtk_accel_group_new (); |
---|
2430 | item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group); |
---|
2431 | gtk_object_set_data_full (GTK_OBJECT (window), |
---|
2432 | "<main>", |
---|
2433 | item_factory, |
---|
2434 | (GtkDestroyNotify) gtk_object_unref); |
---|
2435 | gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); |
---|
2436 | gtk_window_set_title (GTK_WINDOW (window), "Item Factory"); |
---|
2437 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
2438 | gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); |
---|
2439 | |
---|
2440 | /* preselect /Preferences/Shape/Oval over the other radios |
---|
2441 | */ |
---|
2442 | gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory, |
---|
2443 | "/Preferences/Shape/Oval")), |
---|
2444 | TRUE); |
---|
2445 | |
---|
2446 | box1 = gtk_vbox_new (FALSE, 0); |
---|
2447 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
2448 | |
---|
2449 | gtk_box_pack_start (GTK_BOX (box1), |
---|
2450 | gtk_item_factory_get_widget (item_factory, "<main>"), |
---|
2451 | FALSE, FALSE, 0); |
---|
2452 | |
---|
2453 | label = gtk_label_new ("Type\n<alt>\nto start"); |
---|
2454 | gtk_widget_set_usize (label, 200, 200); |
---|
2455 | gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5); |
---|
2456 | gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0); |
---|
2457 | |
---|
2458 | |
---|
2459 | separator = gtk_hseparator_new (); |
---|
2460 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
2461 | |
---|
2462 | |
---|
2463 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2464 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2465 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
2466 | |
---|
2467 | button = gtk_button_new_with_label ("close"); |
---|
2468 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
2469 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2470 | GTK_OBJECT (window)); |
---|
2471 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2472 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2473 | gtk_widget_grab_default (button); |
---|
2474 | |
---|
2475 | gtk_item_factory_delete_item (item_factory, "/Preferences/ShouldNotAppear"); |
---|
2476 | |
---|
2477 | gtk_widget_show_all (window); |
---|
2478 | } |
---|
2479 | else |
---|
2480 | gtk_widget_destroy (window); |
---|
2481 | } |
---|
2482 | |
---|
2483 | /* |
---|
2484 | create_modal_window |
---|
2485 | */ |
---|
2486 | |
---|
2487 | static gboolean |
---|
2488 | cmw_destroy_cb(GtkWidget *widget) |
---|
2489 | { |
---|
2490 | /* This is needed to get out of gtk_main */ |
---|
2491 | gtk_main_quit (); |
---|
2492 | |
---|
2493 | return FALSE; |
---|
2494 | } |
---|
2495 | |
---|
2496 | static void |
---|
2497 | cmw_color (GtkWidget *widget, GtkWidget *parent) |
---|
2498 | { |
---|
2499 | GtkWidget *csd; |
---|
2500 | |
---|
2501 | csd=gtk_color_selection_dialog_new ("This is a modal color selection dialog"); |
---|
2502 | |
---|
2503 | /* Set as modal */ |
---|
2504 | gtk_window_set_modal (GTK_WINDOW(csd),TRUE); |
---|
2505 | |
---|
2506 | /* And mark it as a transient dialog */ |
---|
2507 | gtk_window_set_transient_for (GTK_WINDOW (csd), GTK_WINDOW (parent)); |
---|
2508 | |
---|
2509 | gtk_signal_connect (GTK_OBJECT(csd), "destroy", |
---|
2510 | GTK_SIGNAL_FUNC(cmw_destroy_cb),NULL); |
---|
2511 | |
---|
2512 | gtk_signal_connect_object (GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(csd)->ok_button), |
---|
2513 | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2514 | GTK_OBJECT (csd)); |
---|
2515 | gtk_signal_connect_object (GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(csd)->cancel_button), |
---|
2516 | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2517 | GTK_OBJECT (csd)); |
---|
2518 | |
---|
2519 | /* wait until destroy calls gtk_main_quit */ |
---|
2520 | gtk_widget_show (csd); |
---|
2521 | gtk_main (); |
---|
2522 | } |
---|
2523 | |
---|
2524 | static void |
---|
2525 | cmw_file (GtkWidget *widget, GtkWidget *parent) |
---|
2526 | { |
---|
2527 | GtkWidget *fs; |
---|
2528 | |
---|
2529 | fs = gtk_file_selection_new("This is a modal file selection dialog"); |
---|
2530 | |
---|
2531 | /* Set as modal */ |
---|
2532 | gtk_window_set_modal (GTK_WINDOW(fs),TRUE); |
---|
2533 | |
---|
2534 | /* And mark it as a transient dialog */ |
---|
2535 | gtk_window_set_transient_for (GTK_WINDOW (fs), GTK_WINDOW (parent)); |
---|
2536 | |
---|
2537 | gtk_signal_connect (GTK_OBJECT(fs), "destroy", |
---|
2538 | GTK_SIGNAL_FUNC(cmw_destroy_cb),NULL); |
---|
2539 | |
---|
2540 | gtk_signal_connect_object (GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button), |
---|
2541 | "clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2542 | GTK_OBJECT (fs)); |
---|
2543 | gtk_signal_connect_object (GTK_OBJECT(GTK_FILE_SELECTION(fs)->cancel_button), |
---|
2544 | "clicked",GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2545 | GTK_OBJECT (fs)); |
---|
2546 | |
---|
2547 | /* wait until destroy calls gtk_main_quit */ |
---|
2548 | gtk_widget_show (fs); |
---|
2549 | |
---|
2550 | gtk_main(); |
---|
2551 | } |
---|
2552 | |
---|
2553 | |
---|
2554 | static void |
---|
2555 | create_modal_window (void) |
---|
2556 | { |
---|
2557 | GtkWidget *window = NULL; |
---|
2558 | GtkWidget *box1,*box2; |
---|
2559 | GtkWidget *frame1; |
---|
2560 | GtkWidget *btnColor,*btnFile,*btnClose; |
---|
2561 | |
---|
2562 | /* Create modal window (Here you can use any window descendent )*/ |
---|
2563 | window=gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
2564 | gtk_window_set_title (GTK_WINDOW(window),"This window is modal"); |
---|
2565 | |
---|
2566 | /* Set window as modal */ |
---|
2567 | gtk_window_set_modal (GTK_WINDOW(window),TRUE); |
---|
2568 | |
---|
2569 | /* Create widgets */ |
---|
2570 | box1 = gtk_vbox_new (FALSE,5); |
---|
2571 | frame1 = gtk_frame_new ("Standard dialogs in modal form"); |
---|
2572 | box2 = gtk_vbox_new (TRUE,5); |
---|
2573 | btnColor = gtk_button_new_with_label ("Color"); |
---|
2574 | btnFile = gtk_button_new_with_label ("File Selection"); |
---|
2575 | btnClose = gtk_button_new_with_label ("Close"); |
---|
2576 | |
---|
2577 | /* Init widgets */ |
---|
2578 | gtk_container_set_border_width (GTK_CONTAINER(box1),3); |
---|
2579 | gtk_container_set_border_width (GTK_CONTAINER(box2),3); |
---|
2580 | |
---|
2581 | /* Pack widgets */ |
---|
2582 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
2583 | gtk_box_pack_start (GTK_BOX (box1), frame1, TRUE, TRUE, 4); |
---|
2584 | gtk_container_add (GTK_CONTAINER (frame1), box2); |
---|
2585 | gtk_box_pack_start (GTK_BOX (box2), btnColor, FALSE, FALSE, 4); |
---|
2586 | gtk_box_pack_start (GTK_BOX (box2), btnFile, FALSE, FALSE, 4); |
---|
2587 | gtk_box_pack_start (GTK_BOX (box1), gtk_hseparator_new (), FALSE, FALSE, 4); |
---|
2588 | gtk_box_pack_start (GTK_BOX (box1), btnClose, FALSE, FALSE, 4); |
---|
2589 | |
---|
2590 | /* connect signals */ |
---|
2591 | gtk_signal_connect_object (GTK_OBJECT (btnClose), "clicked", |
---|
2592 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
2593 | GTK_OBJECT (window)); |
---|
2594 | |
---|
2595 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2596 | GTK_SIGNAL_FUNC (cmw_destroy_cb),NULL); |
---|
2597 | |
---|
2598 | gtk_signal_connect (GTK_OBJECT (btnColor), "clicked", |
---|
2599 | GTK_SIGNAL_FUNC (cmw_color),window); |
---|
2600 | gtk_signal_connect (GTK_OBJECT (btnFile), "clicked", |
---|
2601 | GTK_SIGNAL_FUNC (cmw_file),window); |
---|
2602 | |
---|
2603 | /* Show widgets */ |
---|
2604 | gtk_widget_show_all (window); |
---|
2605 | |
---|
2606 | /* wait until dialog get destroyed */ |
---|
2607 | gtk_main(); |
---|
2608 | } |
---|
2609 | |
---|
2610 | /* |
---|
2611 | * GtkScrolledWindow |
---|
2612 | */ |
---|
2613 | |
---|
2614 | static GtkWidget *sw_parent = NULL; |
---|
2615 | static GtkWidget *sw_float_parent; |
---|
2616 | static guint sw_destroyed_handler = 0; |
---|
2617 | |
---|
2618 | static gboolean |
---|
2619 | scrolled_windows_delete_cb (GtkWidget *widget, GdkEventAny *event, GtkWidget *scrollwin) |
---|
2620 | { |
---|
2621 | gtk_widget_reparent (scrollwin, sw_parent); |
---|
2622 | |
---|
2623 | gtk_signal_disconnect (GTK_OBJECT (sw_parent), sw_destroyed_handler); |
---|
2624 | sw_float_parent = NULL; |
---|
2625 | sw_parent = NULL; |
---|
2626 | sw_destroyed_handler = 0; |
---|
2627 | |
---|
2628 | return FALSE; |
---|
2629 | } |
---|
2630 | |
---|
2631 | static void |
---|
2632 | scrolled_windows_destroy_cb (GtkWidget *widget, GtkWidget *scrollwin) |
---|
2633 | { |
---|
2634 | gtk_widget_destroy (sw_float_parent); |
---|
2635 | |
---|
2636 | sw_float_parent = NULL; |
---|
2637 | sw_parent = NULL; |
---|
2638 | sw_destroyed_handler = 0; |
---|
2639 | } |
---|
2640 | |
---|
2641 | static void |
---|
2642 | scrolled_windows_remove (GtkWidget *widget, GtkWidget *scrollwin) |
---|
2643 | { |
---|
2644 | if (sw_parent) |
---|
2645 | { |
---|
2646 | gtk_widget_reparent (scrollwin, sw_parent); |
---|
2647 | gtk_widget_destroy (sw_float_parent); |
---|
2648 | |
---|
2649 | gtk_signal_disconnect (GTK_OBJECT (sw_parent), sw_destroyed_handler); |
---|
2650 | sw_float_parent = NULL; |
---|
2651 | sw_parent = NULL; |
---|
2652 | sw_destroyed_handler = 0; |
---|
2653 | } |
---|
2654 | else |
---|
2655 | { |
---|
2656 | sw_parent = scrollwin->parent; |
---|
2657 | sw_float_parent = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
2658 | gtk_window_set_default_size (GTK_WINDOW (sw_float_parent), 200, 200); |
---|
2659 | |
---|
2660 | gtk_widget_reparent (scrollwin, sw_float_parent); |
---|
2661 | gtk_widget_show (sw_float_parent); |
---|
2662 | |
---|
2663 | sw_destroyed_handler = |
---|
2664 | gtk_signal_connect (GTK_OBJECT (sw_parent), "destroy", |
---|
2665 | GTK_SIGNAL_FUNC (scrolled_windows_destroy_cb), scrollwin); |
---|
2666 | gtk_signal_connect (GTK_OBJECT (sw_float_parent), "delete_event", |
---|
2667 | GTK_SIGNAL_FUNC (scrolled_windows_delete_cb), scrollwin); |
---|
2668 | } |
---|
2669 | } |
---|
2670 | |
---|
2671 | static void |
---|
2672 | create_scrolled_windows (void) |
---|
2673 | { |
---|
2674 | static GtkWidget *window; |
---|
2675 | GtkWidget *scrolled_window; |
---|
2676 | GtkWidget *table; |
---|
2677 | GtkWidget *button; |
---|
2678 | char buffer[32]; |
---|
2679 | int i, j; |
---|
2680 | |
---|
2681 | if (!window) |
---|
2682 | { |
---|
2683 | window = gtk_dialog_new (); |
---|
2684 | |
---|
2685 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2686 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
2687 | &window); |
---|
2688 | |
---|
2689 | gtk_window_set_title (GTK_WINDOW (window), "dialog"); |
---|
2690 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
2691 | |
---|
2692 | |
---|
2693 | scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
---|
2694 | gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10); |
---|
2695 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), |
---|
2696 | GTK_POLICY_AUTOMATIC, |
---|
2697 | GTK_POLICY_AUTOMATIC); |
---|
2698 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), |
---|
2699 | scrolled_window, TRUE, TRUE, 0); |
---|
2700 | gtk_widget_show (scrolled_window); |
---|
2701 | |
---|
2702 | table = gtk_table_new (20, 20, FALSE); |
---|
2703 | gtk_table_set_row_spacings (GTK_TABLE (table), 10); |
---|
2704 | gtk_table_set_col_spacings (GTK_TABLE (table), 10); |
---|
2705 | gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), table); |
---|
2706 | gtk_container_set_focus_hadjustment (GTK_CONTAINER (table), |
---|
2707 | gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); |
---|
2708 | gtk_container_set_focus_vadjustment (GTK_CONTAINER (table), |
---|
2709 | gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); |
---|
2710 | gtk_widget_show (table); |
---|
2711 | |
---|
2712 | for (i = 0; i < 20; i++) |
---|
2713 | for (j = 0; j < 20; j++) |
---|
2714 | { |
---|
2715 | sprintf (buffer, "button (%d,%d)\n", i, j); |
---|
2716 | button = gtk_toggle_button_new_with_label (buffer); |
---|
2717 | gtk_table_attach_defaults (GTK_TABLE (table), button, |
---|
2718 | i, i+1, j, j+1); |
---|
2719 | gtk_widget_show (button); |
---|
2720 | } |
---|
2721 | |
---|
2722 | |
---|
2723 | button = gtk_button_new_with_label ("Close"); |
---|
2724 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
2725 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2726 | GTK_OBJECT (window)); |
---|
2727 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2728 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
2729 | button, TRUE, TRUE, 0); |
---|
2730 | gtk_widget_grab_default (button); |
---|
2731 | gtk_widget_show (button); |
---|
2732 | |
---|
2733 | button = gtk_button_new_with_label ("Reparent Out"); |
---|
2734 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
2735 | GTK_SIGNAL_FUNC(scrolled_windows_remove), |
---|
2736 | scrolled_window); |
---|
2737 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2738 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
2739 | button, TRUE, TRUE, 0); |
---|
2740 | gtk_widget_grab_default (button); |
---|
2741 | gtk_widget_show (button); |
---|
2742 | |
---|
2743 | gtk_window_set_default_size (GTK_WINDOW (window), 300, 300); |
---|
2744 | } |
---|
2745 | |
---|
2746 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
2747 | gtk_widget_show (window); |
---|
2748 | else |
---|
2749 | gtk_widget_destroy (window); |
---|
2750 | } |
---|
2751 | |
---|
2752 | /* |
---|
2753 | * GtkEntry |
---|
2754 | */ |
---|
2755 | |
---|
2756 | static void |
---|
2757 | entry_toggle_editable (GtkWidget *checkbutton, |
---|
2758 | GtkWidget *entry) |
---|
2759 | { |
---|
2760 | gtk_entry_set_editable(GTK_ENTRY(entry), |
---|
2761 | GTK_TOGGLE_BUTTON(checkbutton)->active); |
---|
2762 | } |
---|
2763 | |
---|
2764 | static void |
---|
2765 | entry_toggle_sensitive (GtkWidget *checkbutton, |
---|
2766 | GtkWidget *entry) |
---|
2767 | { |
---|
2768 | gtk_widget_set_sensitive (entry, GTK_TOGGLE_BUTTON(checkbutton)->active); |
---|
2769 | } |
---|
2770 | |
---|
2771 | static void |
---|
2772 | entry_toggle_visibility (GtkWidget *checkbutton, |
---|
2773 | GtkWidget *entry) |
---|
2774 | { |
---|
2775 | gtk_entry_set_visibility(GTK_ENTRY(entry), |
---|
2776 | GTK_TOGGLE_BUTTON(checkbutton)->active); |
---|
2777 | } |
---|
2778 | |
---|
2779 | static void |
---|
2780 | create_entry (void) |
---|
2781 | { |
---|
2782 | static GtkWidget *window = NULL; |
---|
2783 | GtkWidget *box1; |
---|
2784 | GtkWidget *box2; |
---|
2785 | GtkWidget *editable_check; |
---|
2786 | GtkWidget *sensitive_check; |
---|
2787 | GtkWidget *entry, *cb; |
---|
2788 | GtkWidget *button; |
---|
2789 | GtkWidget *separator; |
---|
2790 | GList *cbitems = NULL; |
---|
2791 | |
---|
2792 | if (!window) |
---|
2793 | { |
---|
2794 | cbitems = g_list_append(cbitems, "item0"); |
---|
2795 | cbitems = g_list_append(cbitems, "item1 item1"); |
---|
2796 | cbitems = g_list_append(cbitems, "item2 item2 item2"); |
---|
2797 | cbitems = g_list_append(cbitems, "item3 item3 item3 item3"); |
---|
2798 | cbitems = g_list_append(cbitems, "item4 item4 item4 item4 item4"); |
---|
2799 | cbitems = g_list_append(cbitems, "item5 item5 item5 item5 item5 item5"); |
---|
2800 | cbitems = g_list_append(cbitems, "item6 item6 item6 item6 item6"); |
---|
2801 | cbitems = g_list_append(cbitems, "item7 item7 item7 item7"); |
---|
2802 | cbitems = g_list_append(cbitems, "item8 item8 item8"); |
---|
2803 | cbitems = g_list_append(cbitems, "item9 item9"); |
---|
2804 | |
---|
2805 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
2806 | |
---|
2807 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2808 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
2809 | &window); |
---|
2810 | |
---|
2811 | gtk_window_set_title (GTK_WINDOW (window), "entry"); |
---|
2812 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
2813 | |
---|
2814 | |
---|
2815 | box1 = gtk_vbox_new (FALSE, 0); |
---|
2816 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
2817 | gtk_widget_show (box1); |
---|
2818 | |
---|
2819 | |
---|
2820 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2821 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2822 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
2823 | gtk_widget_show (box2); |
---|
2824 | |
---|
2825 | entry = gtk_entry_new (); |
---|
2826 | gtk_entry_set_text (GTK_ENTRY (entry), "hello world"); |
---|
2827 | gtk_editable_select_region (GTK_EDITABLE (entry), 0, 5); |
---|
2828 | gtk_box_pack_start (GTK_BOX (box2), entry, TRUE, TRUE, 0); |
---|
2829 | gtk_widget_show (entry); |
---|
2830 | |
---|
2831 | cb = gtk_combo_new (); |
---|
2832 | gtk_combo_set_popdown_strings (GTK_COMBO (cb), cbitems); |
---|
2833 | gtk_entry_set_text (GTK_ENTRY (GTK_COMBO(cb)->entry), "hello world"); |
---|
2834 | gtk_editable_select_region (GTK_EDITABLE (GTK_COMBO(cb)->entry), |
---|
2835 | 0, -1); |
---|
2836 | gtk_box_pack_start (GTK_BOX (box2), cb, TRUE, TRUE, 0); |
---|
2837 | gtk_widget_show (cb); |
---|
2838 | |
---|
2839 | editable_check = gtk_check_button_new_with_label("Editable"); |
---|
2840 | gtk_box_pack_start (GTK_BOX (box2), editable_check, FALSE, TRUE, 0); |
---|
2841 | gtk_signal_connect (GTK_OBJECT(editable_check), "toggled", |
---|
2842 | GTK_SIGNAL_FUNC(entry_toggle_editable), entry); |
---|
2843 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(editable_check), TRUE); |
---|
2844 | gtk_widget_show (editable_check); |
---|
2845 | |
---|
2846 | editable_check = gtk_check_button_new_with_label("Visible"); |
---|
2847 | gtk_box_pack_start (GTK_BOX (box2), editable_check, FALSE, TRUE, 0); |
---|
2848 | gtk_signal_connect (GTK_OBJECT(editable_check), "toggled", |
---|
2849 | GTK_SIGNAL_FUNC(entry_toggle_visibility), entry); |
---|
2850 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(editable_check), TRUE); |
---|
2851 | gtk_widget_show (editable_check); |
---|
2852 | |
---|
2853 | sensitive_check = gtk_check_button_new_with_label("Sensitive"); |
---|
2854 | gtk_box_pack_start (GTK_BOX (box2), sensitive_check, FALSE, TRUE, 0); |
---|
2855 | gtk_signal_connect (GTK_OBJECT(sensitive_check), "toggled", |
---|
2856 | GTK_SIGNAL_FUNC(entry_toggle_sensitive), entry); |
---|
2857 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sensitive_check), TRUE); |
---|
2858 | gtk_widget_show (sensitive_check); |
---|
2859 | |
---|
2860 | separator = gtk_hseparator_new (); |
---|
2861 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
2862 | gtk_widget_show (separator); |
---|
2863 | |
---|
2864 | |
---|
2865 | box2 = gtk_vbox_new (FALSE, 10); |
---|
2866 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
2867 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
2868 | gtk_widget_show (box2); |
---|
2869 | |
---|
2870 | |
---|
2871 | button = gtk_button_new_with_label ("close"); |
---|
2872 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
2873 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
2874 | GTK_OBJECT (window)); |
---|
2875 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
2876 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
2877 | gtk_widget_grab_default (button); |
---|
2878 | gtk_widget_show (button); |
---|
2879 | } |
---|
2880 | |
---|
2881 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
2882 | gtk_widget_show (window); |
---|
2883 | else |
---|
2884 | gtk_widget_destroy (window); |
---|
2885 | } |
---|
2886 | |
---|
2887 | /* |
---|
2888 | * GtkSpinButton |
---|
2889 | */ |
---|
2890 | |
---|
2891 | static GtkWidget *spinner1; |
---|
2892 | |
---|
2893 | static void |
---|
2894 | toggle_snap (GtkWidget *widget, GtkSpinButton *spin) |
---|
2895 | { |
---|
2896 | gtk_spin_button_set_snap_to_ticks (spin, GTK_TOGGLE_BUTTON (widget)->active); |
---|
2897 | } |
---|
2898 | |
---|
2899 | static void |
---|
2900 | toggle_numeric (GtkWidget *widget, GtkSpinButton *spin) |
---|
2901 | { |
---|
2902 | gtk_spin_button_set_numeric (spin, GTK_TOGGLE_BUTTON (widget)->active); |
---|
2903 | } |
---|
2904 | |
---|
2905 | static void |
---|
2906 | change_digits (GtkWidget *widget, GtkSpinButton *spin) |
---|
2907 | { |
---|
2908 | gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinner1), |
---|
2909 | gtk_spin_button_get_value_as_int (spin)); |
---|
2910 | } |
---|
2911 | |
---|
2912 | static void |
---|
2913 | get_value (GtkWidget *widget, gpointer data) |
---|
2914 | { |
---|
2915 | gchar buf[32]; |
---|
2916 | GtkLabel *label; |
---|
2917 | GtkSpinButton *spin; |
---|
2918 | |
---|
2919 | spin = GTK_SPIN_BUTTON (spinner1); |
---|
2920 | label = GTK_LABEL (gtk_object_get_user_data (GTK_OBJECT (widget))); |
---|
2921 | if (GPOINTER_TO_INT (data) == 1) |
---|
2922 | sprintf (buf, "%d", gtk_spin_button_get_value_as_int (spin)); |
---|
2923 | else |
---|
2924 | sprintf (buf, "%0.*f", spin->digits, |
---|
2925 | gtk_spin_button_get_value_as_float (spin)); |
---|
2926 | gtk_label_set_text (label, buf); |
---|
2927 | } |
---|
2928 | |
---|
2929 | static void |
---|
2930 | create_spins (void) |
---|
2931 | { |
---|
2932 | static GtkWidget *window = NULL; |
---|
2933 | GtkWidget *frame; |
---|
2934 | GtkWidget *hbox; |
---|
2935 | GtkWidget *main_vbox; |
---|
2936 | GtkWidget *vbox; |
---|
2937 | GtkWidget *vbox2; |
---|
2938 | GtkWidget *spinner2; |
---|
2939 | GtkWidget *spinner; |
---|
2940 | GtkWidget *button; |
---|
2941 | GtkWidget *label; |
---|
2942 | GtkWidget *val_label; |
---|
2943 | GtkAdjustment *adj; |
---|
2944 | |
---|
2945 | if (!window) |
---|
2946 | { |
---|
2947 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
2948 | |
---|
2949 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
2950 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
2951 | &window); |
---|
2952 | |
---|
2953 | gtk_window_set_title (GTK_WINDOW (window), "GtkSpinButton"); |
---|
2954 | |
---|
2955 | main_vbox = gtk_vbox_new (FALSE, 5); |
---|
2956 | gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 10); |
---|
2957 | gtk_container_add (GTK_CONTAINER (window), main_vbox); |
---|
2958 | |
---|
2959 | frame = gtk_frame_new ("Not accelerated"); |
---|
2960 | gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0); |
---|
2961 | |
---|
2962 | vbox = gtk_vbox_new (FALSE, 0); |
---|
2963 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); |
---|
2964 | gtk_container_add (GTK_CONTAINER (frame), vbox); |
---|
2965 | |
---|
2966 | /* Day, month, year spinners */ |
---|
2967 | |
---|
2968 | hbox = gtk_hbox_new (FALSE, 0); |
---|
2969 | gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); |
---|
2970 | |
---|
2971 | vbox2 = gtk_vbox_new (FALSE, 0); |
---|
2972 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5); |
---|
2973 | |
---|
2974 | label = gtk_label_new ("Day :"); |
---|
2975 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
2976 | gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0); |
---|
2977 | |
---|
2978 | adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 31.0, 1.0, |
---|
2979 | 5.0, 0.0); |
---|
2980 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
2981 | gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE); |
---|
2982 | gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner), |
---|
2983 | GTK_SHADOW_OUT); |
---|
2984 | gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0); |
---|
2985 | |
---|
2986 | vbox2 = gtk_vbox_new (FALSE, 0); |
---|
2987 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5); |
---|
2988 | |
---|
2989 | label = gtk_label_new ("Month :"); |
---|
2990 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
2991 | gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0); |
---|
2992 | |
---|
2993 | adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 1.0, 12.0, 1.0, |
---|
2994 | 5.0, 0.0); |
---|
2995 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
2996 | gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE); |
---|
2997 | gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner), |
---|
2998 | GTK_SHADOW_ETCHED_IN); |
---|
2999 | gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0); |
---|
3000 | |
---|
3001 | vbox2 = gtk_vbox_new (FALSE, 0); |
---|
3002 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5); |
---|
3003 | |
---|
3004 | label = gtk_label_new ("Year :"); |
---|
3005 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
3006 | gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0); |
---|
3007 | |
---|
3008 | adj = (GtkAdjustment *) gtk_adjustment_new (1998.0, 0.0, 2100.0, |
---|
3009 | 1.0, 100.0, 0.0); |
---|
3010 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
3011 | gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE); |
---|
3012 | gtk_spin_button_set_shadow_type (GTK_SPIN_BUTTON (spinner), |
---|
3013 | GTK_SHADOW_IN); |
---|
3014 | gtk_widget_set_usize (spinner, 55, 0); |
---|
3015 | gtk_box_pack_start (GTK_BOX (vbox2), spinner, FALSE, TRUE, 0); |
---|
3016 | |
---|
3017 | frame = gtk_frame_new ("Accelerated"); |
---|
3018 | gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0); |
---|
3019 | |
---|
3020 | vbox = gtk_vbox_new (FALSE, 0); |
---|
3021 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); |
---|
3022 | gtk_container_add (GTK_CONTAINER (frame), vbox); |
---|
3023 | |
---|
3024 | hbox = gtk_hbox_new (FALSE, 0); |
---|
3025 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 5); |
---|
3026 | |
---|
3027 | vbox2 = gtk_vbox_new (FALSE, 0); |
---|
3028 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5); |
---|
3029 | |
---|
3030 | label = gtk_label_new ("Value :"); |
---|
3031 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
3032 | gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0); |
---|
3033 | |
---|
3034 | adj = (GtkAdjustment *) gtk_adjustment_new (0.0, -10000.0, 10000.0, |
---|
3035 | 0.5, 100.0, 0.0); |
---|
3036 | spinner1 = gtk_spin_button_new (adj, 1.0, 2); |
---|
3037 | gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner1), TRUE); |
---|
3038 | gtk_widget_set_usize (spinner1, 100, 0); |
---|
3039 | gtk_box_pack_start (GTK_BOX (vbox2), spinner1, FALSE, TRUE, 0); |
---|
3040 | |
---|
3041 | vbox2 = gtk_vbox_new (FALSE, 0); |
---|
3042 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 5); |
---|
3043 | |
---|
3044 | label = gtk_label_new ("Digits :"); |
---|
3045 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
3046 | gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0); |
---|
3047 | |
---|
3048 | adj = (GtkAdjustment *) gtk_adjustment_new (2, 1, 5, 1, 1, 0); |
---|
3049 | spinner2 = gtk_spin_button_new (adj, 0.0, 0); |
---|
3050 | gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner2), TRUE); |
---|
3051 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
3052 | GTK_SIGNAL_FUNC (change_digits), |
---|
3053 | (gpointer) spinner2); |
---|
3054 | gtk_box_pack_start (GTK_BOX (vbox2), spinner2, FALSE, TRUE, 0); |
---|
3055 | |
---|
3056 | hbox = gtk_hbox_new (FALSE, 0); |
---|
3057 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 5); |
---|
3058 | |
---|
3059 | button = gtk_check_button_new_with_label ("Snap to 0.5-ticks"); |
---|
3060 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3061 | GTK_SIGNAL_FUNC (toggle_snap), |
---|
3062 | spinner1); |
---|
3063 | gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
---|
3064 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); |
---|
3065 | |
---|
3066 | button = gtk_check_button_new_with_label ("Numeric only input mode"); |
---|
3067 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3068 | GTK_SIGNAL_FUNC (toggle_numeric), |
---|
3069 | spinner1); |
---|
3070 | gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); |
---|
3071 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); |
---|
3072 | |
---|
3073 | val_label = gtk_label_new (""); |
---|
3074 | |
---|
3075 | hbox = gtk_hbox_new (FALSE, 0); |
---|
3076 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 5); |
---|
3077 | |
---|
3078 | button = gtk_button_new_with_label ("Value as Int"); |
---|
3079 | gtk_object_set_user_data (GTK_OBJECT (button), val_label); |
---|
3080 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3081 | GTK_SIGNAL_FUNC (get_value), |
---|
3082 | GINT_TO_POINTER (1)); |
---|
3083 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
3084 | |
---|
3085 | button = gtk_button_new_with_label ("Value as Float"); |
---|
3086 | gtk_object_set_user_data (GTK_OBJECT (button), val_label); |
---|
3087 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3088 | GTK_SIGNAL_FUNC (get_value), |
---|
3089 | GINT_TO_POINTER (2)); |
---|
3090 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
3091 | |
---|
3092 | gtk_box_pack_start (GTK_BOX (vbox), val_label, TRUE, TRUE, 0); |
---|
3093 | gtk_label_set_text (GTK_LABEL (val_label), "0"); |
---|
3094 | |
---|
3095 | hbox = gtk_hbox_new (FALSE, 0); |
---|
3096 | gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0); |
---|
3097 | |
---|
3098 | button = gtk_button_new_with_label ("Close"); |
---|
3099 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
3100 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
3101 | GTK_OBJECT (window)); |
---|
3102 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
3103 | } |
---|
3104 | |
---|
3105 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
3106 | gtk_widget_show_all (window); |
---|
3107 | else |
---|
3108 | gtk_widget_destroy (window); |
---|
3109 | } |
---|
3110 | |
---|
3111 | /* |
---|
3112 | * Cursors |
---|
3113 | */ |
---|
3114 | |
---|
3115 | static gint |
---|
3116 | cursor_expose_event (GtkWidget *widget, |
---|
3117 | GdkEvent *event, |
---|
3118 | gpointer user_data) |
---|
3119 | { |
---|
3120 | GtkDrawingArea *darea; |
---|
3121 | GdkDrawable *drawable; |
---|
3122 | GdkGC *black_gc; |
---|
3123 | GdkGC *gray_gc; |
---|
3124 | GdkGC *white_gc; |
---|
3125 | guint max_width; |
---|
3126 | guint max_height; |
---|
3127 | |
---|
3128 | g_return_val_if_fail (widget != NULL, TRUE); |
---|
3129 | g_return_val_if_fail (GTK_IS_DRAWING_AREA (widget), TRUE); |
---|
3130 | |
---|
3131 | darea = GTK_DRAWING_AREA (widget); |
---|
3132 | drawable = widget->window; |
---|
3133 | white_gc = widget->style->white_gc; |
---|
3134 | gray_gc = widget->style->bg_gc[GTK_STATE_NORMAL]; |
---|
3135 | black_gc = widget->style->black_gc; |
---|
3136 | max_width = widget->allocation.width; |
---|
3137 | max_height = widget->allocation.height; |
---|
3138 | |
---|
3139 | gdk_draw_rectangle (drawable, white_gc, |
---|
3140 | TRUE, |
---|
3141 | 0, |
---|
3142 | 0, |
---|
3143 | max_width, |
---|
3144 | max_height / 2); |
---|
3145 | |
---|
3146 | gdk_draw_rectangle (drawable, black_gc, |
---|
3147 | TRUE, |
---|
3148 | 0, |
---|
3149 | max_height / 2, |
---|
3150 | max_width, |
---|
3151 | max_height / 2); |
---|
3152 | |
---|
3153 | gdk_draw_rectangle (drawable, gray_gc, |
---|
3154 | TRUE, |
---|
3155 | max_width / 3, |
---|
3156 | max_height / 3, |
---|
3157 | max_width / 3, |
---|
3158 | max_height / 3); |
---|
3159 | |
---|
3160 | return TRUE; |
---|
3161 | } |
---|
3162 | |
---|
3163 | static void |
---|
3164 | set_cursor (GtkWidget *spinner, |
---|
3165 | GtkWidget *widget) |
---|
3166 | { |
---|
3167 | guint c; |
---|
3168 | GdkCursor *cursor; |
---|
3169 | GtkWidget *label; |
---|
3170 | GtkFlagValue *vals; |
---|
3171 | |
---|
3172 | c = CLAMP (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner)), 0, 152); |
---|
3173 | c &= 0xfe; |
---|
3174 | |
---|
3175 | label = gtk_object_get_user_data (GTK_OBJECT (spinner)); |
---|
3176 | vals = gtk_type_enum_get_values (GTK_TYPE_GDK_CURSOR_TYPE); |
---|
3177 | while (vals && vals->value != c) |
---|
3178 | vals++; |
---|
3179 | if (vals) |
---|
3180 | gtk_label_set_text (GTK_LABEL (label), vals->value_nick); |
---|
3181 | else |
---|
3182 | gtk_label_set_text (GTK_LABEL (label), "<unknown>"); |
---|
3183 | |
---|
3184 | cursor = gdk_cursor_new (c); |
---|
3185 | gdk_window_set_cursor (widget->window, cursor); |
---|
3186 | gdk_cursor_destroy (cursor); |
---|
3187 | } |
---|
3188 | |
---|
3189 | static gint |
---|
3190 | cursor_event (GtkWidget *widget, |
---|
3191 | GdkEvent *event, |
---|
3192 | GtkSpinButton *spinner) |
---|
3193 | { |
---|
3194 | if ((event->type == GDK_BUTTON_PRESS) && |
---|
3195 | ((event->button.button == 1) || |
---|
3196 | (event->button.button == 3))) |
---|
3197 | { |
---|
3198 | gtk_spin_button_spin (spinner, event->button.button == 1 ? |
---|
3199 | GTK_SPIN_STEP_FORWARD : GTK_SPIN_STEP_BACKWARD, 0); |
---|
3200 | return TRUE; |
---|
3201 | } |
---|
3202 | |
---|
3203 | return FALSE; |
---|
3204 | } |
---|
3205 | |
---|
3206 | static void |
---|
3207 | create_cursors (void) |
---|
3208 | { |
---|
3209 | static GtkWidget *window = NULL; |
---|
3210 | GtkWidget *frame; |
---|
3211 | GtkWidget *hbox; |
---|
3212 | GtkWidget *main_vbox; |
---|
3213 | GtkWidget *vbox; |
---|
3214 | GtkWidget *darea; |
---|
3215 | GtkWidget *spinner; |
---|
3216 | GtkWidget *button; |
---|
3217 | GtkWidget *label; |
---|
3218 | GtkWidget *any; |
---|
3219 | GtkAdjustment *adj; |
---|
3220 | |
---|
3221 | if (!window) |
---|
3222 | { |
---|
3223 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
3224 | |
---|
3225 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
3226 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
3227 | &window); |
---|
3228 | |
---|
3229 | gtk_window_set_title (GTK_WINDOW (window), "Cursors"); |
---|
3230 | |
---|
3231 | main_vbox = gtk_vbox_new (FALSE, 5); |
---|
3232 | gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 0); |
---|
3233 | gtk_container_add (GTK_CONTAINER (window), main_vbox); |
---|
3234 | |
---|
3235 | vbox = |
---|
3236 | gtk_widget_new (gtk_vbox_get_type (), |
---|
3237 | "GtkBox::homogeneous", FALSE, |
---|
3238 | "GtkBox::spacing", 5, |
---|
3239 | "GtkContainer::border_width", 10, |
---|
3240 | "GtkWidget::parent", main_vbox, |
---|
3241 | "GtkWidget::visible", TRUE, |
---|
3242 | NULL); |
---|
3243 | |
---|
3244 | hbox = gtk_hbox_new (FALSE, 0); |
---|
3245 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
3246 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); |
---|
3247 | |
---|
3248 | label = gtk_label_new ("Cursor Value : "); |
---|
3249 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
3250 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
3251 | |
---|
3252 | adj = (GtkAdjustment *) gtk_adjustment_new (0, |
---|
3253 | 0, 152, |
---|
3254 | 2, |
---|
3255 | 10, 0); |
---|
3256 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
3257 | gtk_box_pack_start (GTK_BOX (hbox), spinner, TRUE, TRUE, 0); |
---|
3258 | |
---|
3259 | frame = |
---|
3260 | gtk_widget_new (gtk_frame_get_type (), |
---|
3261 | "GtkFrame::shadow", GTK_SHADOW_ETCHED_IN, |
---|
3262 | "GtkFrame::label_xalign", 0.5, |
---|
3263 | "GtkFrame::label", "Cursor Area", |
---|
3264 | "GtkContainer::border_width", 10, |
---|
3265 | "GtkWidget::parent", vbox, |
---|
3266 | "GtkWidget::visible", TRUE, |
---|
3267 | NULL); |
---|
3268 | |
---|
3269 | darea = gtk_drawing_area_new (); |
---|
3270 | gtk_widget_set_usize (darea, 80, 80); |
---|
3271 | gtk_container_add (GTK_CONTAINER (frame), darea); |
---|
3272 | gtk_signal_connect (GTK_OBJECT (darea), |
---|
3273 | "expose_event", |
---|
3274 | GTK_SIGNAL_FUNC (cursor_expose_event), |
---|
3275 | NULL); |
---|
3276 | gtk_widget_set_events (darea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); |
---|
3277 | gtk_signal_connect (GTK_OBJECT (darea), |
---|
3278 | "button_press_event", |
---|
3279 | GTK_SIGNAL_FUNC (cursor_event), |
---|
3280 | spinner); |
---|
3281 | gtk_widget_show (darea); |
---|
3282 | |
---|
3283 | gtk_signal_connect (GTK_OBJECT (spinner), "changed", |
---|
3284 | GTK_SIGNAL_FUNC (set_cursor), |
---|
3285 | darea); |
---|
3286 | |
---|
3287 | label = gtk_widget_new (GTK_TYPE_LABEL, |
---|
3288 | "visible", TRUE, |
---|
3289 | "label", "XXX", |
---|
3290 | "parent", vbox, |
---|
3291 | NULL); |
---|
3292 | gtk_container_child_set (GTK_CONTAINER (vbox), label, |
---|
3293 | "expand", FALSE, |
---|
3294 | NULL); |
---|
3295 | gtk_object_set_user_data (GTK_OBJECT (spinner), label); |
---|
3296 | |
---|
3297 | any = |
---|
3298 | gtk_widget_new (gtk_hseparator_get_type (), |
---|
3299 | "GtkWidget::visible", TRUE, |
---|
3300 | NULL); |
---|
3301 | gtk_box_pack_start (GTK_BOX (main_vbox), any, FALSE, TRUE, 0); |
---|
3302 | |
---|
3303 | hbox = gtk_hbox_new (FALSE, 0); |
---|
3304 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); |
---|
3305 | gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0); |
---|
3306 | |
---|
3307 | button = gtk_button_new_with_label ("Close"); |
---|
3308 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
3309 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
3310 | GTK_OBJECT (window)); |
---|
3311 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
3312 | |
---|
3313 | gtk_widget_show_all (window); |
---|
3314 | |
---|
3315 | set_cursor (spinner, darea); |
---|
3316 | } |
---|
3317 | else |
---|
3318 | gtk_widget_destroy (window); |
---|
3319 | } |
---|
3320 | |
---|
3321 | /* |
---|
3322 | * GtkList |
---|
3323 | */ |
---|
3324 | |
---|
3325 | static void |
---|
3326 | list_add (GtkWidget *widget, |
---|
3327 | GtkWidget *list) |
---|
3328 | { |
---|
3329 | static int i = 1; |
---|
3330 | gchar buffer[64]; |
---|
3331 | GtkWidget *list_item; |
---|
3332 | GtkContainer *container; |
---|
3333 | |
---|
3334 | container = GTK_CONTAINER (list); |
---|
3335 | |
---|
3336 | sprintf (buffer, "added item %d", i++); |
---|
3337 | list_item = gtk_list_item_new_with_label (buffer); |
---|
3338 | gtk_widget_show (list_item); |
---|
3339 | |
---|
3340 | gtk_container_add (container, list_item); |
---|
3341 | } |
---|
3342 | |
---|
3343 | static void |
---|
3344 | list_remove (GtkWidget *widget, |
---|
3345 | GtkList *list) |
---|
3346 | { |
---|
3347 | GList *clear_list = NULL; |
---|
3348 | GList *sel_row = NULL; |
---|
3349 | GList *work = NULL; |
---|
3350 | |
---|
3351 | if (list->selection_mode == GTK_SELECTION_EXTENDED) |
---|
3352 | { |
---|
3353 | GtkWidget *item; |
---|
3354 | |
---|
3355 | item = GTK_CONTAINER (list)->focus_child; |
---|
3356 | if (!item && list->selection) |
---|
3357 | item = list->selection->data; |
---|
3358 | |
---|
3359 | if (item) |
---|
3360 | { |
---|
3361 | work = g_list_find (list->children, item); |
---|
3362 | for (sel_row = work; sel_row; sel_row = sel_row->next) |
---|
3363 | if (GTK_WIDGET (sel_row->data)->state != GTK_STATE_SELECTED) |
---|
3364 | break; |
---|
3365 | |
---|
3366 | if (!sel_row) |
---|
3367 | { |
---|
3368 | for (sel_row = work; sel_row; sel_row = sel_row->prev) |
---|
3369 | if (GTK_WIDGET (sel_row->data)->state != GTK_STATE_SELECTED) |
---|
3370 | break; |
---|
3371 | } |
---|
3372 | } |
---|
3373 | } |
---|
3374 | |
---|
3375 | for (work = list->selection; work; work = work->next) |
---|
3376 | clear_list = g_list_prepend (clear_list, work->data); |
---|
3377 | |
---|
3378 | clear_list = g_list_reverse (clear_list); |
---|
3379 | gtk_list_remove_items (GTK_LIST (list), clear_list); |
---|
3380 | g_list_free (clear_list); |
---|
3381 | |
---|
3382 | if (list->selection_mode == GTK_SELECTION_EXTENDED && sel_row) |
---|
3383 | gtk_list_select_child (list, GTK_WIDGET(sel_row->data)); |
---|
3384 | } |
---|
3385 | |
---|
3386 | static void |
---|
3387 | list_clear (GtkWidget *widget, |
---|
3388 | GtkWidget *list) |
---|
3389 | { |
---|
3390 | gtk_list_clear_items (GTK_LIST (list), 0, -1); |
---|
3391 | } |
---|
3392 | |
---|
3393 | #define RADIOMENUTOGGLED(_rmi_, __i) { \ |
---|
3394 | GSList * __g; \ |
---|
3395 | __i = 0; \ |
---|
3396 | __g = gtk_radio_menu_item_group(_rmi_); \ |
---|
3397 | while( __g && !((GtkCheckMenuItem *)(__g->data))->active) { \ |
---|
3398 | __g = __g->next; \ |
---|
3399 | __i++; \ |
---|
3400 | }\ |
---|
3401 | } |
---|
3402 | |
---|
3403 | static GtkWidget *list_omenu; |
---|
3404 | |
---|
3405 | static void |
---|
3406 | list_toggle_sel_mode (GtkWidget *widget, GtkList *list) |
---|
3407 | { |
---|
3408 | gint i; |
---|
3409 | |
---|
3410 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
3411 | return; |
---|
3412 | |
---|
3413 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
3414 | (((GtkOptionMenu *)list_omenu)->menu_item), i); |
---|
3415 | |
---|
3416 | gtk_list_set_selection_mode (list, (GtkSelectionMode) (3-i)); |
---|
3417 | } |
---|
3418 | |
---|
3419 | static void |
---|
3420 | create_list (void) |
---|
3421 | { |
---|
3422 | static GtkWidget *window = NULL; |
---|
3423 | |
---|
3424 | static OptionMenuItem items[] = |
---|
3425 | { |
---|
3426 | { "Single", list_toggle_sel_mode }, |
---|
3427 | { "Browse", list_toggle_sel_mode }, |
---|
3428 | { "Multiple", list_toggle_sel_mode }, |
---|
3429 | { "Extended", list_toggle_sel_mode } |
---|
3430 | }; |
---|
3431 | |
---|
3432 | if (!window) |
---|
3433 | { |
---|
3434 | GtkWidget *cbox; |
---|
3435 | GtkWidget *vbox; |
---|
3436 | GtkWidget *hbox; |
---|
3437 | GtkWidget *label; |
---|
3438 | GtkWidget *scrolled_win; |
---|
3439 | GtkWidget *list; |
---|
3440 | GtkWidget *button; |
---|
3441 | GtkWidget *separator; |
---|
3442 | FILE *infile; |
---|
3443 | |
---|
3444 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
3445 | |
---|
3446 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
3447 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
3448 | &window); |
---|
3449 | |
---|
3450 | gtk_window_set_title (GTK_WINDOW (window), "list"); |
---|
3451 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
3452 | |
---|
3453 | vbox = gtk_vbox_new (FALSE, 0); |
---|
3454 | gtk_container_add (GTK_CONTAINER (window), vbox); |
---|
3455 | |
---|
3456 | scrolled_win = gtk_scrolled_window_new (NULL, NULL); |
---|
3457 | gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 5); |
---|
3458 | gtk_widget_set_usize (scrolled_win, -1, 300); |
---|
3459 | gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0); |
---|
3460 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), |
---|
3461 | GTK_POLICY_AUTOMATIC, |
---|
3462 | GTK_POLICY_AUTOMATIC); |
---|
3463 | |
---|
3464 | list = gtk_list_new (); |
---|
3465 | gtk_list_set_selection_mode (GTK_LIST (list), GTK_SELECTION_EXTENDED); |
---|
3466 | gtk_scrolled_window_add_with_viewport |
---|
3467 | (GTK_SCROLLED_WINDOW (scrolled_win), list); |
---|
3468 | gtk_container_set_focus_vadjustment |
---|
3469 | (GTK_CONTAINER (list), |
---|
3470 | gtk_scrolled_window_get_vadjustment |
---|
3471 | (GTK_SCROLLED_WINDOW (scrolled_win))); |
---|
3472 | gtk_container_set_focus_hadjustment |
---|
3473 | (GTK_CONTAINER (list), |
---|
3474 | gtk_scrolled_window_get_hadjustment |
---|
3475 | (GTK_SCROLLED_WINDOW (scrolled_win))); |
---|
3476 | |
---|
3477 | if ((infile = fopen("gtkenums.h", "r"))) |
---|
3478 | { |
---|
3479 | char buffer[256]; |
---|
3480 | char *pos; |
---|
3481 | GtkWidget *item; |
---|
3482 | |
---|
3483 | while (fgets (buffer, 256, infile)) |
---|
3484 | { |
---|
3485 | if ((pos = strchr (buffer, '\n'))) |
---|
3486 | *pos = 0; |
---|
3487 | item = gtk_list_item_new_with_label (buffer); |
---|
3488 | gtk_container_add (GTK_CONTAINER (list), item); |
---|
3489 | } |
---|
3490 | |
---|
3491 | fclose (infile); |
---|
3492 | } |
---|
3493 | |
---|
3494 | |
---|
3495 | hbox = gtk_hbox_new (TRUE, 5); |
---|
3496 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
3497 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); |
---|
3498 | |
---|
3499 | button = gtk_button_new_with_label ("Insert Row"); |
---|
3500 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3501 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3502 | GTK_SIGNAL_FUNC (list_add), |
---|
3503 | list); |
---|
3504 | |
---|
3505 | button = gtk_button_new_with_label ("Clear List"); |
---|
3506 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3507 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3508 | GTK_SIGNAL_FUNC (list_clear), |
---|
3509 | list); |
---|
3510 | |
---|
3511 | button = gtk_button_new_with_label ("Remove Selection"); |
---|
3512 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3513 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3514 | GTK_SIGNAL_FUNC (list_remove), |
---|
3515 | list); |
---|
3516 | |
---|
3517 | cbox = gtk_hbox_new (FALSE, 0); |
---|
3518 | gtk_box_pack_start (GTK_BOX (vbox), cbox, FALSE, TRUE, 0); |
---|
3519 | |
---|
3520 | hbox = gtk_hbox_new (FALSE, 5); |
---|
3521 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
3522 | gtk_box_pack_start (GTK_BOX (cbox), hbox, TRUE, FALSE, 0); |
---|
3523 | |
---|
3524 | label = gtk_label_new ("Selection Mode :"); |
---|
3525 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
3526 | |
---|
3527 | list_omenu = build_option_menu (items, 4, 3, list); |
---|
3528 | gtk_box_pack_start (GTK_BOX (hbox), list_omenu, FALSE, TRUE, 0); |
---|
3529 | |
---|
3530 | separator = gtk_hseparator_new (); |
---|
3531 | gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0); |
---|
3532 | |
---|
3533 | cbox = gtk_hbox_new (FALSE, 0); |
---|
3534 | gtk_box_pack_start (GTK_BOX (vbox), cbox, FALSE, TRUE, 0); |
---|
3535 | |
---|
3536 | button = gtk_button_new_with_label ("close"); |
---|
3537 | gtk_container_set_border_width (GTK_CONTAINER (button), 10); |
---|
3538 | gtk_box_pack_start (GTK_BOX (cbox), button, TRUE, TRUE, 0); |
---|
3539 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
3540 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
3541 | GTK_OBJECT (window)); |
---|
3542 | |
---|
3543 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
3544 | gtk_widget_grab_default (button); |
---|
3545 | } |
---|
3546 | |
---|
3547 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
3548 | gtk_widget_show_all (window); |
---|
3549 | else |
---|
3550 | gtk_widget_destroy (window); |
---|
3551 | } |
---|
3552 | |
---|
3553 | /* |
---|
3554 | * GtkCList |
---|
3555 | */ |
---|
3556 | |
---|
3557 | static char * book_open_xpm[] = { |
---|
3558 | "16 16 4 1", |
---|
3559 | " c None s None", |
---|
3560 | ". c black", |
---|
3561 | "X c #808080", |
---|
3562 | "o c white", |
---|
3563 | " ", |
---|
3564 | " .. ", |
---|
3565 | " .Xo. ... ", |
---|
3566 | " .Xoo. ..oo. ", |
---|
3567 | " .Xooo.Xooo... ", |
---|
3568 | " .Xooo.oooo.X. ", |
---|
3569 | " .Xooo.Xooo.X. ", |
---|
3570 | " .Xooo.oooo.X. ", |
---|
3571 | " .Xooo.Xooo.X. ", |
---|
3572 | " .Xooo.oooo.X. ", |
---|
3573 | " .Xoo.Xoo..X. ", |
---|
3574 | " .Xo.o..ooX. ", |
---|
3575 | " .X..XXXXX. ", |
---|
3576 | " ..X....... ", |
---|
3577 | " .. ", |
---|
3578 | " "}; |
---|
3579 | |
---|
3580 | static char * book_closed_xpm[] = { |
---|
3581 | "16 16 6 1", |
---|
3582 | " c None s None", |
---|
3583 | ". c black", |
---|
3584 | "X c red", |
---|
3585 | "o c yellow", |
---|
3586 | "O c #808080", |
---|
3587 | "# c white", |
---|
3588 | " ", |
---|
3589 | " .. ", |
---|
3590 | " ..XX. ", |
---|
3591 | " ..XXXXX. ", |
---|
3592 | " ..XXXXXXXX. ", |
---|
3593 | ".ooXXXXXXXXX. ", |
---|
3594 | "..ooXXXXXXXXX. ", |
---|
3595 | ".X.ooXXXXXXXXX. ", |
---|
3596 | ".XX.ooXXXXXX.. ", |
---|
3597 | " .XX.ooXXX..#O ", |
---|
3598 | " .XX.oo..##OO. ", |
---|
3599 | " .XX..##OO.. ", |
---|
3600 | " .X.#OO.. ", |
---|
3601 | " ..O.. ", |
---|
3602 | " .. ", |
---|
3603 | " "}; |
---|
3604 | |
---|
3605 | static char * mini_page_xpm[] = { |
---|
3606 | "16 16 4 1", |
---|
3607 | " c None s None", |
---|
3608 | ". c black", |
---|
3609 | "X c white", |
---|
3610 | "o c #808080", |
---|
3611 | " ", |
---|
3612 | " ....... ", |
---|
3613 | " .XXXXX.. ", |
---|
3614 | " .XoooX.X. ", |
---|
3615 | " .XXXXX.... ", |
---|
3616 | " .XooooXoo.o ", |
---|
3617 | " .XXXXXXXX.o ", |
---|
3618 | " .XooooooX.o ", |
---|
3619 | " .XXXXXXXX.o ", |
---|
3620 | " .XooooooX.o ", |
---|
3621 | " .XXXXXXXX.o ", |
---|
3622 | " .XooooooX.o ", |
---|
3623 | " .XXXXXXXX.o ", |
---|
3624 | " ..........o ", |
---|
3625 | " oooooooooo ", |
---|
3626 | " "}; |
---|
3627 | |
---|
3628 | static char * gtk_mini_xpm[] = { |
---|
3629 | "15 20 17 1", |
---|
3630 | " c None", |
---|
3631 | ". c #14121F", |
---|
3632 | "+ c #278828", |
---|
3633 | "@ c #9B3334", |
---|
3634 | "# c #284C72", |
---|
3635 | "$ c #24692A", |
---|
3636 | "% c #69282E", |
---|
3637 | "& c #37C539", |
---|
3638 | "* c #1D2F4D", |
---|
3639 | "= c #6D7076", |
---|
3640 | "- c #7D8482", |
---|
3641 | "; c #E24A49", |
---|
3642 | "> c #515357", |
---|
3643 | ", c #9B9C9B", |
---|
3644 | "' c #2FA232", |
---|
3645 | ") c #3CE23D", |
---|
3646 | "! c #3B6CCB", |
---|
3647 | " ", |
---|
3648 | " ***> ", |
---|
3649 | " >.*!!!* ", |
---|
3650 | " ***....#*= ", |
---|
3651 | " *!*.!!!**!!# ", |
---|
3652 | " .!!#*!#*!!!!# ", |
---|
3653 | " @%#!.##.*!!$& ", |
---|
3654 | " @;%*!*.#!#')) ", |
---|
3655 | " @;;@%!!*$&)'' ", |
---|
3656 | " @%.%@%$'&)$+' ", |
---|
3657 | " @;...@$'*'*)+ ", |
---|
3658 | " @;%..@$+*.')$ ", |
---|
3659 | " @;%%;;$+..$)# ", |
---|
3660 | " @;%%;@$$$'.$# ", |
---|
3661 | " %;@@;;$$+))&* ", |
---|
3662 | " %;;;@+$&)&* ", |
---|
3663 | " %;;@'))+> ", |
---|
3664 | " %;@'&# ", |
---|
3665 | " >%$$ ", |
---|
3666 | " >= "}; |
---|
3667 | |
---|
3668 | #define TESTGTK_CLIST_COLUMNS 12 |
---|
3669 | static gint clist_rows = 0; |
---|
3670 | static GtkWidget *clist_omenu; |
---|
3671 | |
---|
3672 | static void |
---|
3673 | add1000_clist (GtkWidget *widget, gpointer data) |
---|
3674 | { |
---|
3675 | gint i, row; |
---|
3676 | char text[TESTGTK_CLIST_COLUMNS][50]; |
---|
3677 | char *texts[TESTGTK_CLIST_COLUMNS]; |
---|
3678 | GdkBitmap *mask; |
---|
3679 | GdkPixmap *pixmap; |
---|
3680 | GtkCList *clist; |
---|
3681 | |
---|
3682 | clist = GTK_CLIST (data); |
---|
3683 | |
---|
3684 | pixmap = gdk_pixmap_create_from_xpm_d (clist->clist_window, |
---|
3685 | &mask, |
---|
3686 | >K_WIDGET (data)->style->white, |
---|
3687 | gtk_mini_xpm); |
---|
3688 | |
---|
3689 | for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++) |
---|
3690 | { |
---|
3691 | texts[i] = text[i]; |
---|
3692 | sprintf (text[i], "Column %d", i); |
---|
3693 | } |
---|
3694 | |
---|
3695 | texts[3] = NULL; |
---|
3696 | sprintf (text[1], "Right"); |
---|
3697 | sprintf (text[2], "Center"); |
---|
3698 | |
---|
3699 | gtk_clist_freeze (GTK_CLIST (data)); |
---|
3700 | for (i = 0; i < 1000; i++) |
---|
3701 | { |
---|
3702 | sprintf (text[0], "CListRow %d", rand() % 10000); |
---|
3703 | row = gtk_clist_append (clist, texts); |
---|
3704 | gtk_clist_set_pixtext (clist, row, 3, "gtk+", 5, pixmap, mask); |
---|
3705 | } |
---|
3706 | |
---|
3707 | gtk_clist_thaw (GTK_CLIST (data)); |
---|
3708 | |
---|
3709 | gdk_pixmap_unref (pixmap); |
---|
3710 | gdk_bitmap_unref (mask); |
---|
3711 | } |
---|
3712 | |
---|
3713 | static void |
---|
3714 | add10000_clist (GtkWidget *widget, gpointer data) |
---|
3715 | { |
---|
3716 | gint i; |
---|
3717 | char text[TESTGTK_CLIST_COLUMNS][50]; |
---|
3718 | char *texts[TESTGTK_CLIST_COLUMNS]; |
---|
3719 | |
---|
3720 | for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++) |
---|
3721 | { |
---|
3722 | texts[i] = text[i]; |
---|
3723 | sprintf (text[i], "Column %d", i); |
---|
3724 | } |
---|
3725 | |
---|
3726 | sprintf (text[1], "Right"); |
---|
3727 | sprintf (text[2], "Center"); |
---|
3728 | |
---|
3729 | gtk_clist_freeze (GTK_CLIST (data)); |
---|
3730 | for (i = 0; i < 10000; i++) |
---|
3731 | { |
---|
3732 | sprintf (text[0], "CListRow %d", rand() % 10000); |
---|
3733 | gtk_clist_append (GTK_CLIST (data), texts); |
---|
3734 | } |
---|
3735 | gtk_clist_thaw (GTK_CLIST (data)); |
---|
3736 | } |
---|
3737 | |
---|
3738 | void |
---|
3739 | clear_clist (GtkWidget *widget, gpointer data) |
---|
3740 | { |
---|
3741 | gtk_clist_clear (GTK_CLIST (data)); |
---|
3742 | clist_rows = 0; |
---|
3743 | } |
---|
3744 | |
---|
3745 | void clist_remove_selection (GtkWidget *widget, GtkCList *clist) |
---|
3746 | { |
---|
3747 | gtk_clist_freeze (clist); |
---|
3748 | |
---|
3749 | while (clist->selection) |
---|
3750 | { |
---|
3751 | gint row; |
---|
3752 | |
---|
3753 | clist_rows--; |
---|
3754 | row = GPOINTER_TO_INT (clist->selection->data); |
---|
3755 | |
---|
3756 | gtk_clist_remove (clist, row); |
---|
3757 | |
---|
3758 | if (clist->selection_mode == GTK_SELECTION_BROWSE) |
---|
3759 | break; |
---|
3760 | } |
---|
3761 | |
---|
3762 | if (clist->selection_mode == GTK_SELECTION_EXTENDED && !clist->selection && |
---|
3763 | clist->focus_row >= 0) |
---|
3764 | gtk_clist_select_row (clist, clist->focus_row, -1); |
---|
3765 | |
---|
3766 | gtk_clist_thaw (clist); |
---|
3767 | } |
---|
3768 | |
---|
3769 | void toggle_title_buttons (GtkWidget *widget, GtkCList *clist) |
---|
3770 | { |
---|
3771 | if (GTK_TOGGLE_BUTTON (widget)->active) |
---|
3772 | gtk_clist_column_titles_show (clist); |
---|
3773 | else |
---|
3774 | gtk_clist_column_titles_hide (clist); |
---|
3775 | } |
---|
3776 | |
---|
3777 | void toggle_reorderable (GtkWidget *widget, GtkCList *clist) |
---|
3778 | { |
---|
3779 | gtk_clist_set_reorderable (clist, GTK_TOGGLE_BUTTON (widget)->active); |
---|
3780 | } |
---|
3781 | |
---|
3782 | static void |
---|
3783 | insert_row_clist (GtkWidget *widget, gpointer data) |
---|
3784 | { |
---|
3785 | static char *text[] = |
---|
3786 | { |
---|
3787 | "This", "is an", "inserted", "row.", |
---|
3788 | "This", "is an", "inserted", "row.", |
---|
3789 | "This", "is an", "inserted", "row." |
---|
3790 | }; |
---|
3791 | |
---|
3792 | static GtkStyle *style1 = NULL; |
---|
3793 | static GtkStyle *style2 = NULL; |
---|
3794 | static GtkStyle *style3 = NULL; |
---|
3795 | gint row; |
---|
3796 | |
---|
3797 | if (GTK_CLIST (data)->focus_row >= 0) |
---|
3798 | row = gtk_clist_insert (GTK_CLIST (data), GTK_CLIST (data)->focus_row, |
---|
3799 | text); |
---|
3800 | else |
---|
3801 | row = gtk_clist_prepend (GTK_CLIST (data), text); |
---|
3802 | |
---|
3803 | if (!style1) |
---|
3804 | { |
---|
3805 | GdkColor col1; |
---|
3806 | GdkColor col2; |
---|
3807 | |
---|
3808 | col1.red = 0; |
---|
3809 | col1.green = 56000; |
---|
3810 | col1.blue = 0; |
---|
3811 | col2.red = 32000; |
---|
3812 | col2.green = 0; |
---|
3813 | col2.blue = 56000; |
---|
3814 | |
---|
3815 | style1 = gtk_style_copy (GTK_WIDGET (data)->style); |
---|
3816 | style1->base[GTK_STATE_NORMAL] = col1; |
---|
3817 | style1->base[GTK_STATE_SELECTED] = col2; |
---|
3818 | |
---|
3819 | style2 = gtk_style_copy (GTK_WIDGET (data)->style); |
---|
3820 | style2->fg[GTK_STATE_NORMAL] = col1; |
---|
3821 | style2->fg[GTK_STATE_SELECTED] = col2; |
---|
3822 | |
---|
3823 | style3 = gtk_style_copy (GTK_WIDGET (data)->style); |
---|
3824 | style3->fg[GTK_STATE_NORMAL] = col1; |
---|
3825 | style3->base[GTK_STATE_NORMAL] = col2; |
---|
3826 | gdk_font_unref (style3->font); |
---|
3827 | style3->font = |
---|
3828 | gdk_font_load ("-*-courier-medium-*-*-*-*-120-*-*-*-*-*-*"); |
---|
3829 | } |
---|
3830 | |
---|
3831 | gtk_clist_set_cell_style (GTK_CLIST (data), row, 3, style1); |
---|
3832 | gtk_clist_set_cell_style (GTK_CLIST (data), row, 4, style2); |
---|
3833 | gtk_clist_set_cell_style (GTK_CLIST (data), row, 0, style3); |
---|
3834 | |
---|
3835 | clist_rows++; |
---|
3836 | } |
---|
3837 | |
---|
3838 | static void |
---|
3839 | clist_warning_test (GtkWidget *button, |
---|
3840 | GtkWidget *clist) |
---|
3841 | { |
---|
3842 | GtkWidget *child; |
---|
3843 | static gboolean add_remove = FALSE; |
---|
3844 | |
---|
3845 | add_remove = !add_remove; |
---|
3846 | |
---|
3847 | child = gtk_label_new ("Test"); |
---|
3848 | gtk_widget_ref (child); |
---|
3849 | gtk_object_sink (GTK_OBJECT (child)); |
---|
3850 | |
---|
3851 | if (add_remove) |
---|
3852 | gtk_container_add (GTK_CONTAINER (clist), child); |
---|
3853 | else |
---|
3854 | { |
---|
3855 | child->parent = clist; |
---|
3856 | gtk_container_remove (GTK_CONTAINER (clist), child); |
---|
3857 | child->parent = NULL; |
---|
3858 | } |
---|
3859 | |
---|
3860 | gtk_widget_destroy (child); |
---|
3861 | gtk_widget_unref (child); |
---|
3862 | } |
---|
3863 | |
---|
3864 | static void |
---|
3865 | undo_selection (GtkWidget *button, GtkCList *clist) |
---|
3866 | { |
---|
3867 | gtk_clist_undo_selection (clist); |
---|
3868 | } |
---|
3869 | |
---|
3870 | static void |
---|
3871 | clist_toggle_sel_mode (GtkWidget *widget, GtkCList *clist) |
---|
3872 | { |
---|
3873 | gint i; |
---|
3874 | |
---|
3875 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
3876 | return; |
---|
3877 | |
---|
3878 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
3879 | (((GtkOptionMenu *)clist_omenu)->menu_item), i); |
---|
3880 | |
---|
3881 | gtk_clist_set_selection_mode (clist, (GtkSelectionMode) (3-i)); |
---|
3882 | } |
---|
3883 | |
---|
3884 | static void |
---|
3885 | clist_click_column (GtkCList *clist, gint column, gpointer data) |
---|
3886 | { |
---|
3887 | if (column == 4) |
---|
3888 | gtk_clist_set_column_visibility (clist, column, FALSE); |
---|
3889 | else if (column == clist->sort_column) |
---|
3890 | { |
---|
3891 | if (clist->sort_type == GTK_SORT_ASCENDING) |
---|
3892 | clist->sort_type = GTK_SORT_DESCENDING; |
---|
3893 | else |
---|
3894 | clist->sort_type = GTK_SORT_ASCENDING; |
---|
3895 | } |
---|
3896 | else |
---|
3897 | gtk_clist_set_sort_column (clist, column); |
---|
3898 | |
---|
3899 | gtk_clist_sort (clist); |
---|
3900 | } |
---|
3901 | |
---|
3902 | static void |
---|
3903 | create_clist (void) |
---|
3904 | { |
---|
3905 | gint i; |
---|
3906 | static GtkWidget *window = NULL; |
---|
3907 | |
---|
3908 | static char *titles[] = |
---|
3909 | { |
---|
3910 | "auto resize", "not resizeable", "max width 100", "min width 50", |
---|
3911 | "hide column", "Title 5", "Title 6", "Title 7", |
---|
3912 | "Title 8", "Title 9", "Title 10", "Title 11" |
---|
3913 | }; |
---|
3914 | |
---|
3915 | static OptionMenuItem items[] = |
---|
3916 | { |
---|
3917 | { "Single", clist_toggle_sel_mode }, |
---|
3918 | { "Browse", clist_toggle_sel_mode }, |
---|
3919 | { "Multiple", clist_toggle_sel_mode }, |
---|
3920 | { "Extended", clist_toggle_sel_mode } |
---|
3921 | }; |
---|
3922 | |
---|
3923 | char text[TESTGTK_CLIST_COLUMNS][50]; |
---|
3924 | char *texts[TESTGTK_CLIST_COLUMNS]; |
---|
3925 | |
---|
3926 | GtkWidget *vbox; |
---|
3927 | GtkWidget *hbox; |
---|
3928 | GtkWidget *clist; |
---|
3929 | GtkWidget *button; |
---|
3930 | GtkWidget *separator; |
---|
3931 | GtkWidget *scrolled_win; |
---|
3932 | GtkWidget *check; |
---|
3933 | |
---|
3934 | GtkWidget *undo_button; |
---|
3935 | GtkWidget *label; |
---|
3936 | |
---|
3937 | GtkStyle *style; |
---|
3938 | GdkColor col1; |
---|
3939 | GdkColor col2; |
---|
3940 | |
---|
3941 | if (!window) |
---|
3942 | { |
---|
3943 | clist_rows = 0; |
---|
3944 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
3945 | |
---|
3946 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
3947 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), &window); |
---|
3948 | |
---|
3949 | gtk_window_set_title (GTK_WINDOW (window), "clist"); |
---|
3950 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
3951 | |
---|
3952 | vbox = gtk_vbox_new (FALSE, 0); |
---|
3953 | gtk_container_add (GTK_CONTAINER (window), vbox); |
---|
3954 | |
---|
3955 | scrolled_win = gtk_scrolled_window_new (NULL, NULL); |
---|
3956 | gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 5); |
---|
3957 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), |
---|
3958 | GTK_POLICY_AUTOMATIC, |
---|
3959 | GTK_POLICY_AUTOMATIC); |
---|
3960 | |
---|
3961 | /* create GtkCList here so we have a pointer to throw at the |
---|
3962 | * button callbacks -- more is done with it later */ |
---|
3963 | clist = gtk_clist_new_with_titles (TESTGTK_CLIST_COLUMNS, titles); |
---|
3964 | gtk_container_add (GTK_CONTAINER (scrolled_win), clist); |
---|
3965 | gtk_signal_connect (GTK_OBJECT (clist), "click_column", |
---|
3966 | (GtkSignalFunc) clist_click_column, NULL); |
---|
3967 | |
---|
3968 | /* control buttons */ |
---|
3969 | hbox = gtk_hbox_new (FALSE, 5); |
---|
3970 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
3971 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); |
---|
3972 | |
---|
3973 | button = gtk_button_new_with_label ("Insert Row"); |
---|
3974 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3975 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3976 | (GtkSignalFunc) insert_row_clist, (gpointer) clist); |
---|
3977 | |
---|
3978 | button = gtk_button_new_with_label ("Add 1,000 Rows With Pixmaps"); |
---|
3979 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3980 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3981 | (GtkSignalFunc) add1000_clist, (gpointer) clist); |
---|
3982 | |
---|
3983 | button = gtk_button_new_with_label ("Add 10,000 Rows"); |
---|
3984 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3985 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3986 | (GtkSignalFunc) add10000_clist, (gpointer) clist); |
---|
3987 | |
---|
3988 | /* second layer of buttons */ |
---|
3989 | hbox = gtk_hbox_new (FALSE, 5); |
---|
3990 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
3991 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); |
---|
3992 | |
---|
3993 | button = gtk_button_new_with_label ("Clear List"); |
---|
3994 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
3995 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
3996 | (GtkSignalFunc) clear_clist, (gpointer) clist); |
---|
3997 | |
---|
3998 | button = gtk_button_new_with_label ("Remove Selection"); |
---|
3999 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4000 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4001 | (GtkSignalFunc) clist_remove_selection, |
---|
4002 | (gpointer) clist); |
---|
4003 | |
---|
4004 | undo_button = gtk_button_new_with_label ("Undo Selection"); |
---|
4005 | gtk_box_pack_start (GTK_BOX (hbox), undo_button, TRUE, TRUE, 0); |
---|
4006 | gtk_signal_connect (GTK_OBJECT (undo_button), "clicked", |
---|
4007 | (GtkSignalFunc) undo_selection, (gpointer) clist); |
---|
4008 | |
---|
4009 | button = gtk_button_new_with_label ("Warning Test"); |
---|
4010 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4011 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4012 | (GtkSignalFunc) clist_warning_test,(gpointer) clist); |
---|
4013 | |
---|
4014 | /* third layer of buttons */ |
---|
4015 | hbox = gtk_hbox_new (FALSE, 5); |
---|
4016 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
4017 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); |
---|
4018 | |
---|
4019 | check = gtk_check_button_new_with_label ("Show Title Buttons"); |
---|
4020 | gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); |
---|
4021 | gtk_signal_connect (GTK_OBJECT (check), "clicked", |
---|
4022 | GTK_SIGNAL_FUNC (toggle_title_buttons), clist); |
---|
4023 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); |
---|
4024 | |
---|
4025 | check = gtk_check_button_new_with_label ("Reorderable"); |
---|
4026 | gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); |
---|
4027 | gtk_signal_connect (GTK_OBJECT (check), "clicked", |
---|
4028 | GTK_SIGNAL_FUNC (toggle_reorderable), clist); |
---|
4029 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); |
---|
4030 | |
---|
4031 | label = gtk_label_new ("Selection Mode :"); |
---|
4032 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
4033 | |
---|
4034 | clist_omenu = build_option_menu (items, 4, 3, clist); |
---|
4035 | gtk_box_pack_start (GTK_BOX (hbox), clist_omenu, FALSE, TRUE, 0); |
---|
4036 | |
---|
4037 | /* |
---|
4038 | * the rest of the clist configuration |
---|
4039 | */ |
---|
4040 | |
---|
4041 | gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0); |
---|
4042 | gtk_clist_set_row_height (GTK_CLIST (clist), 18); |
---|
4043 | gtk_widget_set_usize (clist, -1, 300); |
---|
4044 | |
---|
4045 | for (i = 1; i < TESTGTK_CLIST_COLUMNS; i++) |
---|
4046 | gtk_clist_set_column_width (GTK_CLIST (clist), i, 80); |
---|
4047 | |
---|
4048 | gtk_clist_set_column_auto_resize (GTK_CLIST (clist), 0, TRUE); |
---|
4049 | gtk_clist_set_column_resizeable (GTK_CLIST (clist), 1, FALSE); |
---|
4050 | gtk_clist_set_column_max_width (GTK_CLIST (clist), 2, 100); |
---|
4051 | gtk_clist_set_column_min_width (GTK_CLIST (clist), 3, 50); |
---|
4052 | gtk_clist_set_selection_mode (GTK_CLIST (clist), GTK_SELECTION_EXTENDED); |
---|
4053 | gtk_clist_set_column_justification (GTK_CLIST (clist), 1, |
---|
4054 | GTK_JUSTIFY_RIGHT); |
---|
4055 | gtk_clist_set_column_justification (GTK_CLIST (clist), 2, |
---|
4056 | GTK_JUSTIFY_CENTER); |
---|
4057 | |
---|
4058 | for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++) |
---|
4059 | { |
---|
4060 | texts[i] = text[i]; |
---|
4061 | sprintf (text[i], "Column %d", i); |
---|
4062 | } |
---|
4063 | |
---|
4064 | sprintf (text[1], "Right"); |
---|
4065 | sprintf (text[2], "Center"); |
---|
4066 | |
---|
4067 | col1.red = 56000; |
---|
4068 | col1.green = 0; |
---|
4069 | col1.blue = 0; |
---|
4070 | col2.red = 0; |
---|
4071 | col2.green = 56000; |
---|
4072 | col2.blue = 32000; |
---|
4073 | |
---|
4074 | style = gtk_style_new (); |
---|
4075 | style->fg[GTK_STATE_NORMAL] = col1; |
---|
4076 | style->base[GTK_STATE_NORMAL] = col2; |
---|
4077 | |
---|
4078 | gdk_font_unref (style->font); |
---|
4079 | style->font = |
---|
4080 | gdk_font_load ("-adobe-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*"); |
---|
4081 | |
---|
4082 | for (i = 0; i < 10; i++) |
---|
4083 | { |
---|
4084 | sprintf (text[0], "CListRow %d", clist_rows++); |
---|
4085 | gtk_clist_append (GTK_CLIST (clist), texts); |
---|
4086 | |
---|
4087 | switch (i % 4) |
---|
4088 | { |
---|
4089 | case 2: |
---|
4090 | gtk_clist_set_row_style (GTK_CLIST (clist), i, style); |
---|
4091 | break; |
---|
4092 | default: |
---|
4093 | gtk_clist_set_cell_style (GTK_CLIST (clist), i, i % 4, style); |
---|
4094 | break; |
---|
4095 | } |
---|
4096 | } |
---|
4097 | |
---|
4098 | separator = gtk_hseparator_new (); |
---|
4099 | gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0); |
---|
4100 | |
---|
4101 | hbox = gtk_hbox_new (FALSE, 0); |
---|
4102 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); |
---|
4103 | |
---|
4104 | button = gtk_button_new_with_label ("close"); |
---|
4105 | gtk_container_set_border_width (GTK_CONTAINER (button), 10); |
---|
4106 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4107 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
4108 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
4109 | GTK_OBJECT (window)); |
---|
4110 | |
---|
4111 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
4112 | gtk_widget_grab_default (button); |
---|
4113 | } |
---|
4114 | |
---|
4115 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
4116 | gtk_widget_show_all (window); |
---|
4117 | else |
---|
4118 | { |
---|
4119 | clist_rows = 0; |
---|
4120 | gtk_widget_destroy (window); |
---|
4121 | } |
---|
4122 | } |
---|
4123 | |
---|
4124 | /* |
---|
4125 | * GtkCTree |
---|
4126 | */ |
---|
4127 | |
---|
4128 | GdkPixmap *pixmap1; |
---|
4129 | GdkPixmap *pixmap2; |
---|
4130 | GdkPixmap *pixmap3; |
---|
4131 | GdkBitmap *mask1; |
---|
4132 | GdkBitmap *mask2; |
---|
4133 | GdkBitmap *mask3; |
---|
4134 | |
---|
4135 | static gint books = 0; |
---|
4136 | static gint pages = 0; |
---|
4137 | |
---|
4138 | static GtkWidget *book_label; |
---|
4139 | static GtkWidget *page_label; |
---|
4140 | static GtkWidget *sel_label; |
---|
4141 | static GtkWidget *vis_label; |
---|
4142 | static GtkWidget *omenu1; |
---|
4143 | static GtkWidget *omenu2; |
---|
4144 | static GtkWidget *omenu3; |
---|
4145 | static GtkWidget *omenu4; |
---|
4146 | static GtkWidget *spin1; |
---|
4147 | static GtkWidget *spin2; |
---|
4148 | static GtkWidget *spin3; |
---|
4149 | static gint line_style; |
---|
4150 | |
---|
4151 | void after_press (GtkCTree *ctree, gpointer data) |
---|
4152 | { |
---|
4153 | char buf[80]; |
---|
4154 | |
---|
4155 | sprintf (buf, "%d", g_list_length (GTK_CLIST (ctree)->selection)); |
---|
4156 | gtk_label_set_text (GTK_LABEL (sel_label), buf); |
---|
4157 | |
---|
4158 | sprintf (buf, "%d", g_list_length (GTK_CLIST (ctree)->row_list)); |
---|
4159 | gtk_label_set_text (GTK_LABEL (vis_label), buf); |
---|
4160 | |
---|
4161 | sprintf (buf, "%d", books); |
---|
4162 | gtk_label_set_text (GTK_LABEL (book_label), buf); |
---|
4163 | |
---|
4164 | sprintf (buf, "%d", pages); |
---|
4165 | gtk_label_set_text (GTK_LABEL (page_label), buf); |
---|
4166 | } |
---|
4167 | |
---|
4168 | void after_move (GtkCTree *ctree, GtkCTreeNode *child, GtkCTreeNode *parent, |
---|
4169 | GtkCTreeNode *sibling, gpointer data) |
---|
4170 | { |
---|
4171 | char *source; |
---|
4172 | char *target1; |
---|
4173 | char *target2; |
---|
4174 | |
---|
4175 | gtk_ctree_get_node_info (ctree, child, &source, |
---|
4176 | NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
---|
4177 | if (parent) |
---|
4178 | gtk_ctree_get_node_info (ctree, parent, &target1, |
---|
4179 | NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
---|
4180 | if (sibling) |
---|
4181 | gtk_ctree_get_node_info (ctree, sibling, &target2, |
---|
4182 | NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
---|
4183 | |
---|
4184 | g_print ("Moving \"%s\" to \"%s\" with sibling \"%s\".\n", source, |
---|
4185 | (parent) ? target1 : "nil", (sibling) ? target2 : "nil"); |
---|
4186 | } |
---|
4187 | |
---|
4188 | void count_items (GtkCTree *ctree, GtkCTreeNode *list) |
---|
4189 | { |
---|
4190 | if (GTK_CTREE_ROW (list)->is_leaf) |
---|
4191 | pages--; |
---|
4192 | else |
---|
4193 | books--; |
---|
4194 | } |
---|
4195 | |
---|
4196 | void expand_all (GtkWidget *widget, GtkCTree *ctree) |
---|
4197 | { |
---|
4198 | gtk_ctree_expand_recursive (ctree, NULL); |
---|
4199 | after_press (ctree, NULL); |
---|
4200 | } |
---|
4201 | |
---|
4202 | void collapse_all (GtkWidget *widget, GtkCTree *ctree) |
---|
4203 | { |
---|
4204 | gtk_ctree_collapse_recursive (ctree, NULL); |
---|
4205 | after_press (ctree, NULL); |
---|
4206 | } |
---|
4207 | |
---|
4208 | void select_all (GtkWidget *widget, GtkCTree *ctree) |
---|
4209 | { |
---|
4210 | gtk_ctree_select_recursive (ctree, NULL); |
---|
4211 | after_press (ctree, NULL); |
---|
4212 | } |
---|
4213 | |
---|
4214 | void change_style (GtkWidget *widget, GtkCTree *ctree) |
---|
4215 | { |
---|
4216 | static GtkStyle *style1 = NULL; |
---|
4217 | static GtkStyle *style2 = NULL; |
---|
4218 | |
---|
4219 | GtkCTreeNode *node; |
---|
4220 | GdkColor col1; |
---|
4221 | GdkColor col2; |
---|
4222 | |
---|
4223 | if (GTK_CLIST (ctree)->focus_row >= 0) |
---|
4224 | node = GTK_CTREE_NODE |
---|
4225 | (g_list_nth (GTK_CLIST (ctree)->row_list,GTK_CLIST (ctree)->focus_row)); |
---|
4226 | else |
---|
4227 | node = GTK_CTREE_NODE (GTK_CLIST (ctree)->row_list); |
---|
4228 | |
---|
4229 | if (!node) |
---|
4230 | return; |
---|
4231 | |
---|
4232 | if (!style1) |
---|
4233 | { |
---|
4234 | col1.red = 0; |
---|
4235 | col1.green = 56000; |
---|
4236 | col1.blue = 0; |
---|
4237 | col2.red = 32000; |
---|
4238 | col2.green = 0; |
---|
4239 | col2.blue = 56000; |
---|
4240 | |
---|
4241 | style1 = gtk_style_new (); |
---|
4242 | style1->base[GTK_STATE_NORMAL] = col1; |
---|
4243 | style1->fg[GTK_STATE_SELECTED] = col2; |
---|
4244 | |
---|
4245 | style2 = gtk_style_new (); |
---|
4246 | style2->base[GTK_STATE_SELECTED] = col2; |
---|
4247 | style2->fg[GTK_STATE_NORMAL] = col1; |
---|
4248 | style2->base[GTK_STATE_NORMAL] = col2; |
---|
4249 | gdk_font_unref (style2->font); |
---|
4250 | style2->font = |
---|
4251 | gdk_font_load ("-*-courier-medium-*-*-*-*-300-*-*-*-*-*-*"); |
---|
4252 | } |
---|
4253 | |
---|
4254 | gtk_ctree_node_set_cell_style (ctree, node, 1, style1); |
---|
4255 | gtk_ctree_node_set_cell_style (ctree, node, 0, style2); |
---|
4256 | |
---|
4257 | if (GTK_CTREE_ROW (node)->children) |
---|
4258 | gtk_ctree_node_set_row_style (ctree, GTK_CTREE_ROW (node)->children, |
---|
4259 | style2); |
---|
4260 | } |
---|
4261 | |
---|
4262 | void unselect_all (GtkWidget *widget, GtkCTree *ctree) |
---|
4263 | { |
---|
4264 | gtk_ctree_unselect_recursive (ctree, NULL); |
---|
4265 | after_press (ctree, NULL); |
---|
4266 | } |
---|
4267 | |
---|
4268 | void remove_selection (GtkWidget *widget, GtkCTree *ctree) |
---|
4269 | { |
---|
4270 | GtkCList *clist; |
---|
4271 | GtkCTreeNode *node; |
---|
4272 | |
---|
4273 | clist = GTK_CLIST (ctree); |
---|
4274 | |
---|
4275 | gtk_clist_freeze (clist); |
---|
4276 | |
---|
4277 | while (clist->selection) |
---|
4278 | { |
---|
4279 | node = clist->selection->data; |
---|
4280 | |
---|
4281 | if (GTK_CTREE_ROW (node)->is_leaf) |
---|
4282 | pages--; |
---|
4283 | else |
---|
4284 | gtk_ctree_post_recursive (ctree, node, |
---|
4285 | (GtkCTreeFunc) count_items, NULL); |
---|
4286 | |
---|
4287 | gtk_ctree_remove_node (ctree, node); |
---|
4288 | |
---|
4289 | if (clist->selection_mode == GTK_SELECTION_BROWSE) |
---|
4290 | break; |
---|
4291 | } |
---|
4292 | |
---|
4293 | if (clist->selection_mode == GTK_SELECTION_EXTENDED && !clist->selection && |
---|
4294 | clist->focus_row >= 0) |
---|
4295 | { |
---|
4296 | node = gtk_ctree_node_nth (ctree, clist->focus_row); |
---|
4297 | |
---|
4298 | if (node) |
---|
4299 | gtk_ctree_select (ctree, node); |
---|
4300 | } |
---|
4301 | |
---|
4302 | gtk_clist_thaw (clist); |
---|
4303 | after_press (ctree, NULL); |
---|
4304 | } |
---|
4305 | |
---|
4306 | struct _ExportStruct { |
---|
4307 | gchar *tree; |
---|
4308 | gchar *info; |
---|
4309 | gboolean is_leaf; |
---|
4310 | }; |
---|
4311 | |
---|
4312 | typedef struct _ExportStruct ExportStruct; |
---|
4313 | |
---|
4314 | gboolean |
---|
4315 | gnode2ctree (GtkCTree *ctree, |
---|
4316 | guint depth, |
---|
4317 | GNode *gnode, |
---|
4318 | GtkCTreeNode *cnode, |
---|
4319 | gpointer data) |
---|
4320 | { |
---|
4321 | ExportStruct *es; |
---|
4322 | GdkPixmap *pixmap_closed; |
---|
4323 | GdkBitmap *mask_closed; |
---|
4324 | GdkPixmap *pixmap_opened; |
---|
4325 | GdkBitmap *mask_opened; |
---|
4326 | |
---|
4327 | if (!cnode || !gnode || (!(es = gnode->data))) |
---|
4328 | return FALSE; |
---|
4329 | |
---|
4330 | if (es->is_leaf) |
---|
4331 | { |
---|
4332 | pixmap_closed = pixmap3; |
---|
4333 | mask_closed = mask3; |
---|
4334 | pixmap_opened = NULL; |
---|
4335 | mask_opened = NULL; |
---|
4336 | } |
---|
4337 | else |
---|
4338 | { |
---|
4339 | pixmap_closed = pixmap1; |
---|
4340 | mask_closed = mask1; |
---|
4341 | pixmap_opened = pixmap2; |
---|
4342 | mask_opened = mask2; |
---|
4343 | } |
---|
4344 | |
---|
4345 | gtk_ctree_set_node_info (ctree, cnode, es->tree, 2, pixmap_closed, |
---|
4346 | mask_closed, pixmap_opened, mask_opened, |
---|
4347 | es->is_leaf, (depth < 3)); |
---|
4348 | gtk_ctree_node_set_text (ctree, cnode, 1, es->info); |
---|
4349 | g_free (es); |
---|
4350 | gnode->data = NULL; |
---|
4351 | |
---|
4352 | return TRUE; |
---|
4353 | } |
---|
4354 | |
---|
4355 | gboolean |
---|
4356 | ctree2gnode (GtkCTree *ctree, |
---|
4357 | guint depth, |
---|
4358 | GNode *gnode, |
---|
4359 | GtkCTreeNode *cnode, |
---|
4360 | gpointer data) |
---|
4361 | { |
---|
4362 | ExportStruct *es; |
---|
4363 | |
---|
4364 | if (!cnode || !gnode) |
---|
4365 | return FALSE; |
---|
4366 | |
---|
4367 | es = g_new (ExportStruct, 1); |
---|
4368 | gnode->data = es; |
---|
4369 | es->is_leaf = GTK_CTREE_ROW (cnode)->is_leaf; |
---|
4370 | es->tree = GTK_CELL_PIXTEXT (GTK_CTREE_ROW (cnode)->row.cell[0])->text; |
---|
4371 | es->info = GTK_CELL_PIXTEXT (GTK_CTREE_ROW (cnode)->row.cell[1])->text; |
---|
4372 | return TRUE; |
---|
4373 | } |
---|
4374 | |
---|
4375 | void export_ctree (GtkWidget *widget, GtkCTree *ctree) |
---|
4376 | { |
---|
4377 | char *title[] = { "Tree" , "Info" }; |
---|
4378 | static GtkWidget *export_window = NULL; |
---|
4379 | static GtkCTree *export_ctree; |
---|
4380 | GtkWidget *vbox; |
---|
4381 | GtkWidget *scrolled_win; |
---|
4382 | GtkWidget *button; |
---|
4383 | GtkWidget *sep; |
---|
4384 | GNode *gnode; |
---|
4385 | GtkCTreeNode *node; |
---|
4386 | |
---|
4387 | if (!export_window) |
---|
4388 | { |
---|
4389 | export_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
4390 | |
---|
4391 | gtk_signal_connect (GTK_OBJECT (export_window), "destroy", |
---|
4392 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
4393 | &export_window); |
---|
4394 | |
---|
4395 | gtk_window_set_title (GTK_WINDOW (export_window), "exported ctree"); |
---|
4396 | gtk_container_set_border_width (GTK_CONTAINER (export_window), 5); |
---|
4397 | |
---|
4398 | vbox = gtk_vbox_new (FALSE, 0); |
---|
4399 | gtk_container_add (GTK_CONTAINER (export_window), vbox); |
---|
4400 | |
---|
4401 | button = gtk_button_new_with_label ("Close"); |
---|
4402 | gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, TRUE, 0); |
---|
4403 | |
---|
4404 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
4405 | (GtkSignalFunc) gtk_widget_destroy, |
---|
4406 | GTK_OBJECT(export_window)); |
---|
4407 | |
---|
4408 | sep = gtk_hseparator_new (); |
---|
4409 | gtk_box_pack_end (GTK_BOX (vbox), sep, FALSE, TRUE, 10); |
---|
4410 | |
---|
4411 | export_ctree = GTK_CTREE (gtk_ctree_new_with_titles (2, 0, title)); |
---|
4412 | gtk_ctree_set_line_style (export_ctree, GTK_CTREE_LINES_DOTTED); |
---|
4413 | |
---|
4414 | scrolled_win = gtk_scrolled_window_new (NULL, NULL); |
---|
4415 | gtk_container_add (GTK_CONTAINER (scrolled_win), |
---|
4416 | GTK_WIDGET (export_ctree)); |
---|
4417 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), |
---|
4418 | GTK_POLICY_AUTOMATIC, |
---|
4419 | GTK_POLICY_AUTOMATIC); |
---|
4420 | gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0); |
---|
4421 | gtk_clist_set_selection_mode (GTK_CLIST (export_ctree), |
---|
4422 | GTK_SELECTION_EXTENDED); |
---|
4423 | gtk_clist_set_column_width (GTK_CLIST (export_ctree), 0, 200); |
---|
4424 | gtk_clist_set_column_width (GTK_CLIST (export_ctree), 1, 200); |
---|
4425 | gtk_widget_set_usize (GTK_WIDGET (export_ctree), 300, 200); |
---|
4426 | } |
---|
4427 | |
---|
4428 | if (!GTK_WIDGET_VISIBLE (export_window)) |
---|
4429 | gtk_widget_show_all (export_window); |
---|
4430 | |
---|
4431 | gtk_clist_clear (GTK_CLIST (export_ctree)); |
---|
4432 | |
---|
4433 | node = GTK_CTREE_NODE (g_list_nth (GTK_CLIST (ctree)->row_list, |
---|
4434 | GTK_CLIST (ctree)->focus_row)); |
---|
4435 | if (!node) |
---|
4436 | return; |
---|
4437 | |
---|
4438 | gnode = gtk_ctree_export_to_gnode (ctree, NULL, NULL, node, |
---|
4439 | ctree2gnode, NULL); |
---|
4440 | if (gnode) |
---|
4441 | { |
---|
4442 | gtk_ctree_insert_gnode (export_ctree, NULL, NULL, gnode, |
---|
4443 | gnode2ctree, NULL); |
---|
4444 | g_node_destroy (gnode); |
---|
4445 | } |
---|
4446 | } |
---|
4447 | |
---|
4448 | void change_indent (GtkWidget *widget, GtkCTree *ctree) |
---|
4449 | { |
---|
4450 | gtk_ctree_set_indent (ctree, GTK_ADJUSTMENT (widget)->value); |
---|
4451 | } |
---|
4452 | |
---|
4453 | void change_spacing (GtkWidget *widget, GtkCTree *ctree) |
---|
4454 | { |
---|
4455 | gtk_ctree_set_spacing (ctree, GTK_ADJUSTMENT (widget)->value); |
---|
4456 | } |
---|
4457 | |
---|
4458 | void change_row_height (GtkWidget *widget, GtkCList *clist) |
---|
4459 | { |
---|
4460 | gtk_clist_set_row_height (clist, GTK_ADJUSTMENT (widget)->value); |
---|
4461 | } |
---|
4462 | |
---|
4463 | void set_background (GtkCTree *ctree, GtkCTreeNode *node, gpointer data) |
---|
4464 | { |
---|
4465 | GtkStyle *style = NULL; |
---|
4466 | |
---|
4467 | if (!node) |
---|
4468 | return; |
---|
4469 | |
---|
4470 | if (ctree->line_style != GTK_CTREE_LINES_TABBED) |
---|
4471 | { |
---|
4472 | if (!GTK_CTREE_ROW (node)->is_leaf) |
---|
4473 | style = GTK_CTREE_ROW (node)->row.data; |
---|
4474 | else if (GTK_CTREE_ROW (node)->parent) |
---|
4475 | style = GTK_CTREE_ROW (GTK_CTREE_ROW (node)->parent)->row.data; |
---|
4476 | } |
---|
4477 | |
---|
4478 | gtk_ctree_node_set_row_style (ctree, node, style); |
---|
4479 | } |
---|
4480 | |
---|
4481 | void ctree_toggle_line_style (GtkWidget *widget, GtkCTree *ctree) |
---|
4482 | { |
---|
4483 | gint i; |
---|
4484 | |
---|
4485 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
4486 | return; |
---|
4487 | |
---|
4488 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
4489 | (((GtkOptionMenu *)omenu1)->menu_item), i); |
---|
4490 | |
---|
4491 | if ((ctree->line_style == GTK_CTREE_LINES_TABBED && |
---|
4492 | ((GtkCTreeLineStyle) (3 - i)) != GTK_CTREE_LINES_TABBED) || |
---|
4493 | (ctree->line_style != GTK_CTREE_LINES_TABBED && |
---|
4494 | ((GtkCTreeLineStyle) (3 - i)) == GTK_CTREE_LINES_TABBED)) |
---|
4495 | gtk_ctree_pre_recursive (ctree, NULL, set_background, NULL); |
---|
4496 | gtk_ctree_set_line_style (ctree, 3 - i); |
---|
4497 | line_style = 3 - i; |
---|
4498 | } |
---|
4499 | |
---|
4500 | void ctree_toggle_expander_style (GtkWidget *widget, GtkCTree *ctree) |
---|
4501 | { |
---|
4502 | gint i; |
---|
4503 | |
---|
4504 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
4505 | return; |
---|
4506 | |
---|
4507 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
4508 | (((GtkOptionMenu *)omenu2)->menu_item), i); |
---|
4509 | |
---|
4510 | gtk_ctree_set_expander_style (ctree, (GtkCTreeExpanderStyle) (3 - i)); |
---|
4511 | } |
---|
4512 | |
---|
4513 | void ctree_toggle_justify (GtkWidget *widget, GtkCTree *ctree) |
---|
4514 | { |
---|
4515 | gint i; |
---|
4516 | |
---|
4517 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
4518 | return; |
---|
4519 | |
---|
4520 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
4521 | (((GtkOptionMenu *)omenu3)->menu_item), i); |
---|
4522 | |
---|
4523 | gtk_clist_set_column_justification (GTK_CLIST (ctree), ctree->tree_column, |
---|
4524 | (GtkJustification) (1 - i)); |
---|
4525 | } |
---|
4526 | |
---|
4527 | void ctree_toggle_sel_mode (GtkWidget *widget, GtkCTree *ctree) |
---|
4528 | { |
---|
4529 | gint i; |
---|
4530 | |
---|
4531 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
4532 | return; |
---|
4533 | |
---|
4534 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
4535 | (((GtkOptionMenu *)omenu4)->menu_item), i); |
---|
4536 | |
---|
4537 | gtk_clist_set_selection_mode (GTK_CLIST (ctree), (GtkSelectionMode) (3 - i)); |
---|
4538 | after_press (ctree, NULL); |
---|
4539 | } |
---|
4540 | |
---|
4541 | void build_recursive (GtkCTree *ctree, gint cur_depth, gint depth, |
---|
4542 | gint num_books, gint num_pages, GtkCTreeNode *parent) |
---|
4543 | { |
---|
4544 | gchar *text[2]; |
---|
4545 | gchar buf1[60]; |
---|
4546 | gchar buf2[60]; |
---|
4547 | GtkCTreeNode *sibling; |
---|
4548 | gint i; |
---|
4549 | |
---|
4550 | text[0] = buf1; |
---|
4551 | text[1] = buf2; |
---|
4552 | sibling = NULL; |
---|
4553 | |
---|
4554 | for (i = num_pages + num_books; i > num_books; i--) |
---|
4555 | { |
---|
4556 | pages++; |
---|
4557 | sprintf (buf1, "Page %02d", (gint) rand() % 100); |
---|
4558 | sprintf (buf2, "Item %d-%d", cur_depth, i); |
---|
4559 | sibling = gtk_ctree_insert_node (ctree, parent, sibling, text, 5, |
---|
4560 | pixmap3, mask3, NULL, NULL, |
---|
4561 | TRUE, FALSE); |
---|
4562 | |
---|
4563 | if (parent && ctree->line_style == GTK_CTREE_LINES_TABBED) |
---|
4564 | gtk_ctree_node_set_row_style (ctree, sibling, |
---|
4565 | GTK_CTREE_ROW (parent)->row.style); |
---|
4566 | } |
---|
4567 | |
---|
4568 | if (cur_depth == depth) |
---|
4569 | return; |
---|
4570 | |
---|
4571 | for (i = num_books; i > 0; i--) |
---|
4572 | { |
---|
4573 | GtkStyle *style; |
---|
4574 | |
---|
4575 | books++; |
---|
4576 | sprintf (buf1, "Book %02d", (gint) rand() % 100); |
---|
4577 | sprintf (buf2, "Item %d-%d", cur_depth, i); |
---|
4578 | sibling = gtk_ctree_insert_node (ctree, parent, sibling, text, 5, |
---|
4579 | pixmap1, mask1, pixmap2, mask2, |
---|
4580 | FALSE, FALSE); |
---|
4581 | |
---|
4582 | style = gtk_style_new (); |
---|
4583 | switch (cur_depth % 3) |
---|
4584 | { |
---|
4585 | case 0: |
---|
4586 | style->base[GTK_STATE_NORMAL].red = 10000 * (cur_depth % 6); |
---|
4587 | style->base[GTK_STATE_NORMAL].green = 0; |
---|
4588 | style->base[GTK_STATE_NORMAL].blue = 65535 - ((i * 10000) % 65535); |
---|
4589 | break; |
---|
4590 | case 1: |
---|
4591 | style->base[GTK_STATE_NORMAL].red = 10000 * (cur_depth % 6); |
---|
4592 | style->base[GTK_STATE_NORMAL].green = 65535 - ((i * 10000) % 65535); |
---|
4593 | style->base[GTK_STATE_NORMAL].blue = 0; |
---|
4594 | break; |
---|
4595 | default: |
---|
4596 | style->base[GTK_STATE_NORMAL].red = 65535 - ((i * 10000) % 65535); |
---|
4597 | style->base[GTK_STATE_NORMAL].green = 0; |
---|
4598 | style->base[GTK_STATE_NORMAL].blue = 10000 * (cur_depth % 6); |
---|
4599 | break; |
---|
4600 | } |
---|
4601 | gtk_ctree_node_set_row_data_full (ctree, sibling, style, |
---|
4602 | (GtkDestroyNotify) gtk_style_unref); |
---|
4603 | |
---|
4604 | if (ctree->line_style == GTK_CTREE_LINES_TABBED) |
---|
4605 | gtk_ctree_node_set_row_style (ctree, sibling, style); |
---|
4606 | |
---|
4607 | build_recursive (ctree, cur_depth + 1, depth, num_books, num_pages, |
---|
4608 | sibling); |
---|
4609 | } |
---|
4610 | } |
---|
4611 | |
---|
4612 | void rebuild_tree (GtkWidget *widget, GtkCTree *ctree) |
---|
4613 | { |
---|
4614 | gchar *text [2]; |
---|
4615 | gchar label1[] = "Root"; |
---|
4616 | gchar label2[] = ""; |
---|
4617 | GtkCTreeNode *parent; |
---|
4618 | GtkStyle *style; |
---|
4619 | guint b, d, p, n; |
---|
4620 | |
---|
4621 | text[0] = label1; |
---|
4622 | text[1] = label2; |
---|
4623 | |
---|
4624 | d = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin1)); |
---|
4625 | b = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin2)); |
---|
4626 | p = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin3)); |
---|
4627 | |
---|
4628 | n = ((pow (b, d) - 1) / (b - 1)) * (p + 1); |
---|
4629 | |
---|
4630 | if (n > 100000) |
---|
4631 | { |
---|
4632 | g_print ("%d total items? Try less\n",n); |
---|
4633 | return; |
---|
4634 | } |
---|
4635 | |
---|
4636 | gtk_clist_freeze (GTK_CLIST (ctree)); |
---|
4637 | gtk_clist_clear (GTK_CLIST (ctree)); |
---|
4638 | |
---|
4639 | books = 1; |
---|
4640 | pages = 0; |
---|
4641 | |
---|
4642 | parent = gtk_ctree_insert_node (ctree, NULL, NULL, text, 5, pixmap1, |
---|
4643 | mask1, pixmap2, mask2, FALSE, TRUE); |
---|
4644 | |
---|
4645 | style = gtk_style_new (); |
---|
4646 | style->base[GTK_STATE_NORMAL].red = 0; |
---|
4647 | style->base[GTK_STATE_NORMAL].green = 45000; |
---|
4648 | style->base[GTK_STATE_NORMAL].blue = 55000; |
---|
4649 | gtk_ctree_node_set_row_data_full (ctree, parent, style, |
---|
4650 | (GtkDestroyNotify) gtk_style_unref); |
---|
4651 | |
---|
4652 | if (ctree->line_style == GTK_CTREE_LINES_TABBED) |
---|
4653 | gtk_ctree_node_set_row_style (ctree, parent, style); |
---|
4654 | |
---|
4655 | build_recursive (ctree, 1, d, b, p, parent); |
---|
4656 | gtk_clist_thaw (GTK_CLIST (ctree)); |
---|
4657 | after_press (ctree, NULL); |
---|
4658 | } |
---|
4659 | |
---|
4660 | static void |
---|
4661 | ctree_click_column (GtkCTree *ctree, gint column, gpointer data) |
---|
4662 | { |
---|
4663 | GtkCList *clist; |
---|
4664 | |
---|
4665 | clist = GTK_CLIST (ctree); |
---|
4666 | |
---|
4667 | if (column == clist->sort_column) |
---|
4668 | { |
---|
4669 | if (clist->sort_type == GTK_SORT_ASCENDING) |
---|
4670 | clist->sort_type = GTK_SORT_DESCENDING; |
---|
4671 | else |
---|
4672 | clist->sort_type = GTK_SORT_ASCENDING; |
---|
4673 | } |
---|
4674 | else |
---|
4675 | gtk_clist_set_sort_column (clist, column); |
---|
4676 | |
---|
4677 | gtk_ctree_sort_recursive (ctree, NULL); |
---|
4678 | } |
---|
4679 | |
---|
4680 | void create_ctree (void) |
---|
4681 | { |
---|
4682 | static GtkWidget *window = NULL; |
---|
4683 | GtkTooltips *tooltips; |
---|
4684 | GtkCTree *ctree; |
---|
4685 | GtkWidget *scrolled_win; |
---|
4686 | GtkWidget *vbox; |
---|
4687 | GtkWidget *bbox; |
---|
4688 | GtkWidget *mbox; |
---|
4689 | GtkWidget *hbox; |
---|
4690 | GtkWidget *hbox2; |
---|
4691 | GtkWidget *frame; |
---|
4692 | GtkWidget *label; |
---|
4693 | GtkWidget *button; |
---|
4694 | GtkWidget *check; |
---|
4695 | GtkAdjustment *adj; |
---|
4696 | GtkWidget *spinner; |
---|
4697 | GdkColor transparent = { 0 }; |
---|
4698 | |
---|
4699 | char *title[] = { "Tree" , "Info" }; |
---|
4700 | char buf[80]; |
---|
4701 | |
---|
4702 | static OptionMenuItem items1[] = |
---|
4703 | { |
---|
4704 | { "No lines", ctree_toggle_line_style }, |
---|
4705 | { "Solid", ctree_toggle_line_style }, |
---|
4706 | { "Dotted", ctree_toggle_line_style }, |
---|
4707 | { "Tabbed", ctree_toggle_line_style } |
---|
4708 | }; |
---|
4709 | |
---|
4710 | static OptionMenuItem items2[] = |
---|
4711 | { |
---|
4712 | { "None", ctree_toggle_expander_style }, |
---|
4713 | { "Square", ctree_toggle_expander_style }, |
---|
4714 | { "Triangle", ctree_toggle_expander_style }, |
---|
4715 | { "Circular", ctree_toggle_expander_style } |
---|
4716 | }; |
---|
4717 | |
---|
4718 | static OptionMenuItem items3[] = |
---|
4719 | { |
---|
4720 | { "Left", ctree_toggle_justify }, |
---|
4721 | { "Right", ctree_toggle_justify } |
---|
4722 | }; |
---|
4723 | |
---|
4724 | static OptionMenuItem items4[] = |
---|
4725 | { |
---|
4726 | { "Single", ctree_toggle_sel_mode }, |
---|
4727 | { "Browse", ctree_toggle_sel_mode }, |
---|
4728 | { "Multiple", ctree_toggle_sel_mode }, |
---|
4729 | { "Extended", ctree_toggle_sel_mode } |
---|
4730 | }; |
---|
4731 | |
---|
4732 | if (!window) |
---|
4733 | { |
---|
4734 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
4735 | |
---|
4736 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
4737 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
4738 | &window); |
---|
4739 | |
---|
4740 | gtk_window_set_title (GTK_WINDOW (window), "GtkCTree"); |
---|
4741 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
4742 | |
---|
4743 | tooltips = gtk_tooltips_new (); |
---|
4744 | gtk_object_ref (GTK_OBJECT (tooltips)); |
---|
4745 | gtk_object_sink (GTK_OBJECT (tooltips)); |
---|
4746 | |
---|
4747 | gtk_object_set_data_full (GTK_OBJECT (window), "tooltips", tooltips, |
---|
4748 | (GtkDestroyNotify) gtk_object_unref); |
---|
4749 | |
---|
4750 | vbox = gtk_vbox_new (FALSE, 0); |
---|
4751 | gtk_container_add (GTK_CONTAINER (window), vbox); |
---|
4752 | |
---|
4753 | hbox = gtk_hbox_new (FALSE, 5); |
---|
4754 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); |
---|
4755 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); |
---|
4756 | |
---|
4757 | label = gtk_label_new ("Depth :"); |
---|
4758 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
4759 | |
---|
4760 | adj = (GtkAdjustment *) gtk_adjustment_new (4, 1, 10, 1, 5, 0); |
---|
4761 | spin1 = gtk_spin_button_new (adj, 0, 0); |
---|
4762 | gtk_box_pack_start (GTK_BOX (hbox), spin1, FALSE, TRUE, 5); |
---|
4763 | |
---|
4764 | label = gtk_label_new ("Books :"); |
---|
4765 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
4766 | |
---|
4767 | adj = (GtkAdjustment *) gtk_adjustment_new (3, 1, 20, 1, 5, 0); |
---|
4768 | spin2 = gtk_spin_button_new (adj, 0, 0); |
---|
4769 | gtk_box_pack_start (GTK_BOX (hbox), spin2, FALSE, TRUE, 5); |
---|
4770 | |
---|
4771 | label = gtk_label_new ("Pages :"); |
---|
4772 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
4773 | |
---|
4774 | adj = (GtkAdjustment *) gtk_adjustment_new (5, 1, 20, 1, 5, 0); |
---|
4775 | spin3 = gtk_spin_button_new (adj, 0, 0); |
---|
4776 | gtk_box_pack_start (GTK_BOX (hbox), spin3, FALSE, TRUE, 5); |
---|
4777 | |
---|
4778 | button = gtk_button_new_with_label ("Close"); |
---|
4779 | gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4780 | |
---|
4781 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
4782 | (GtkSignalFunc) gtk_widget_destroy, |
---|
4783 | GTK_OBJECT(window)); |
---|
4784 | |
---|
4785 | button = gtk_button_new_with_label ("Rebuild Tree"); |
---|
4786 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4787 | |
---|
4788 | scrolled_win = gtk_scrolled_window_new (NULL, NULL); |
---|
4789 | gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 5); |
---|
4790 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), |
---|
4791 | GTK_POLICY_AUTOMATIC, |
---|
4792 | GTK_POLICY_ALWAYS); |
---|
4793 | gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0); |
---|
4794 | |
---|
4795 | ctree = GTK_CTREE (gtk_ctree_new_with_titles (2, 0, title)); |
---|
4796 | gtk_container_add (GTK_CONTAINER (scrolled_win), GTK_WIDGET (ctree)); |
---|
4797 | |
---|
4798 | gtk_clist_set_column_auto_resize (GTK_CLIST (ctree), 0, TRUE); |
---|
4799 | gtk_clist_set_column_width (GTK_CLIST (ctree), 1, 200); |
---|
4800 | gtk_clist_set_selection_mode (GTK_CLIST (ctree), GTK_SELECTION_EXTENDED); |
---|
4801 | gtk_ctree_set_line_style (ctree, GTK_CTREE_LINES_DOTTED); |
---|
4802 | line_style = GTK_CTREE_LINES_DOTTED; |
---|
4803 | |
---|
4804 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4805 | GTK_SIGNAL_FUNC (rebuild_tree), ctree); |
---|
4806 | gtk_signal_connect (GTK_OBJECT (ctree), "click_column", |
---|
4807 | (GtkSignalFunc) ctree_click_column, NULL); |
---|
4808 | |
---|
4809 | gtk_signal_connect_after (GTK_OBJECT (ctree), "button_press_event", |
---|
4810 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4811 | gtk_signal_connect_after (GTK_OBJECT (ctree), "button_release_event", |
---|
4812 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4813 | gtk_signal_connect_after (GTK_OBJECT (ctree), "tree_move", |
---|
4814 | GTK_SIGNAL_FUNC (after_move), NULL); |
---|
4815 | gtk_signal_connect_after (GTK_OBJECT (ctree), "end_selection", |
---|
4816 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4817 | gtk_signal_connect_after (GTK_OBJECT (ctree), "toggle_focus_row", |
---|
4818 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4819 | gtk_signal_connect_after (GTK_OBJECT (ctree), "select_all", |
---|
4820 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4821 | gtk_signal_connect_after (GTK_OBJECT (ctree), "unselect_all", |
---|
4822 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4823 | gtk_signal_connect_after (GTK_OBJECT (ctree), "scroll_vertical", |
---|
4824 | GTK_SIGNAL_FUNC (after_press), NULL); |
---|
4825 | |
---|
4826 | bbox = gtk_hbox_new (FALSE, 5); |
---|
4827 | gtk_container_set_border_width (GTK_CONTAINER (bbox), 5); |
---|
4828 | gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, TRUE, 0); |
---|
4829 | |
---|
4830 | mbox = gtk_vbox_new (TRUE, 5); |
---|
4831 | gtk_box_pack_start (GTK_BOX (bbox), mbox, FALSE, TRUE, 0); |
---|
4832 | |
---|
4833 | label = gtk_label_new ("Row Height :"); |
---|
4834 | gtk_box_pack_start (GTK_BOX (mbox), label, FALSE, FALSE, 0); |
---|
4835 | |
---|
4836 | label = gtk_label_new ("Indent :"); |
---|
4837 | gtk_box_pack_start (GTK_BOX (mbox), label, FALSE, FALSE, 0); |
---|
4838 | |
---|
4839 | label = gtk_label_new ("Spacing :"); |
---|
4840 | gtk_box_pack_start (GTK_BOX (mbox), label, FALSE, FALSE, 0); |
---|
4841 | |
---|
4842 | mbox = gtk_vbox_new (TRUE, 5); |
---|
4843 | gtk_box_pack_start (GTK_BOX (bbox), mbox, FALSE, TRUE, 0); |
---|
4844 | |
---|
4845 | adj = (GtkAdjustment *) gtk_adjustment_new (20, 12, 100, 1, 10, 0); |
---|
4846 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
4847 | gtk_box_pack_start (GTK_BOX (mbox), spinner, FALSE, FALSE, 5); |
---|
4848 | gtk_tooltips_set_tip (tooltips, spinner, |
---|
4849 | "Row height of list items", NULL); |
---|
4850 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
4851 | GTK_SIGNAL_FUNC (change_row_height), ctree); |
---|
4852 | gtk_clist_set_row_height ( GTK_CLIST (ctree), adj->value); |
---|
4853 | |
---|
4854 | adj = (GtkAdjustment *) gtk_adjustment_new (20, 0, 60, 1, 10, 0); |
---|
4855 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
4856 | gtk_box_pack_start (GTK_BOX (mbox), spinner, FALSE, FALSE, 5); |
---|
4857 | gtk_tooltips_set_tip (tooltips, spinner, "Tree Indentation.", NULL); |
---|
4858 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
4859 | GTK_SIGNAL_FUNC (change_indent), ctree); |
---|
4860 | |
---|
4861 | adj = (GtkAdjustment *) gtk_adjustment_new (5, 0, 60, 1, 10, 0); |
---|
4862 | spinner = gtk_spin_button_new (adj, 0, 0); |
---|
4863 | gtk_box_pack_start (GTK_BOX (mbox), spinner, FALSE, FALSE, 5); |
---|
4864 | gtk_tooltips_set_tip (tooltips, spinner, "Tree Spacing.", NULL); |
---|
4865 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
4866 | GTK_SIGNAL_FUNC (change_spacing), ctree); |
---|
4867 | |
---|
4868 | mbox = gtk_vbox_new (TRUE, 5); |
---|
4869 | gtk_box_pack_start (GTK_BOX (bbox), mbox, FALSE, TRUE, 0); |
---|
4870 | |
---|
4871 | hbox = gtk_hbox_new (FALSE, 5); |
---|
4872 | gtk_box_pack_start (GTK_BOX (mbox), hbox, FALSE, FALSE, 0); |
---|
4873 | |
---|
4874 | button = gtk_button_new_with_label ("Expand All"); |
---|
4875 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4876 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4877 | GTK_SIGNAL_FUNC (expand_all), ctree); |
---|
4878 | |
---|
4879 | button = gtk_button_new_with_label ("Collapse All"); |
---|
4880 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4881 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4882 | GTK_SIGNAL_FUNC (collapse_all), ctree); |
---|
4883 | |
---|
4884 | button = gtk_button_new_with_label ("Change Style"); |
---|
4885 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4886 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4887 | GTK_SIGNAL_FUNC (change_style), ctree); |
---|
4888 | |
---|
4889 | button = gtk_button_new_with_label ("Export Tree"); |
---|
4890 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4891 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4892 | GTK_SIGNAL_FUNC (export_ctree), ctree); |
---|
4893 | |
---|
4894 | hbox = gtk_hbox_new (FALSE, 5); |
---|
4895 | gtk_box_pack_start (GTK_BOX (mbox), hbox, FALSE, FALSE, 0); |
---|
4896 | |
---|
4897 | button = gtk_button_new_with_label ("Select All"); |
---|
4898 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4899 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4900 | GTK_SIGNAL_FUNC (select_all), ctree); |
---|
4901 | |
---|
4902 | button = gtk_button_new_with_label ("Unselect All"); |
---|
4903 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4904 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4905 | GTK_SIGNAL_FUNC (unselect_all), ctree); |
---|
4906 | |
---|
4907 | button = gtk_button_new_with_label ("Remove Selection"); |
---|
4908 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); |
---|
4909 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
4910 | GTK_SIGNAL_FUNC (remove_selection), ctree); |
---|
4911 | |
---|
4912 | check = gtk_check_button_new_with_label ("Reorderable"); |
---|
4913 | gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); |
---|
4914 | gtk_tooltips_set_tip (tooltips, check, |
---|
4915 | "Tree items can be reordered by dragging.", NULL); |
---|
4916 | gtk_signal_connect (GTK_OBJECT (check), "clicked", |
---|
4917 | GTK_SIGNAL_FUNC (toggle_reorderable), ctree); |
---|
4918 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); |
---|
4919 | |
---|
4920 | hbox = gtk_hbox_new (TRUE, 5); |
---|
4921 | gtk_box_pack_start (GTK_BOX (mbox), hbox, FALSE, FALSE, 0); |
---|
4922 | |
---|
4923 | omenu1 = build_option_menu (items1, 4, 2, ctree); |
---|
4924 | gtk_box_pack_start (GTK_BOX (hbox), omenu1, FALSE, TRUE, 0); |
---|
4925 | gtk_tooltips_set_tip (tooltips, omenu1, "The tree's line style.", NULL); |
---|
4926 | |
---|
4927 | omenu2 = build_option_menu (items2, 4, 1, ctree); |
---|
4928 | gtk_box_pack_start (GTK_BOX (hbox), omenu2, FALSE, TRUE, 0); |
---|
4929 | gtk_tooltips_set_tip (tooltips, omenu2, "The tree's expander style.", |
---|
4930 | NULL); |
---|
4931 | |
---|
4932 | omenu3 = build_option_menu (items3, 2, 0, ctree); |
---|
4933 | gtk_box_pack_start (GTK_BOX (hbox), omenu3, FALSE, TRUE, 0); |
---|
4934 | gtk_tooltips_set_tip (tooltips, omenu3, "The tree's justification.", |
---|
4935 | NULL); |
---|
4936 | |
---|
4937 | omenu4 = build_option_menu (items4, 4, 3, ctree); |
---|
4938 | gtk_box_pack_start (GTK_BOX (hbox), omenu4, FALSE, TRUE, 0); |
---|
4939 | gtk_tooltips_set_tip (tooltips, omenu4, "The list's selection mode.", |
---|
4940 | NULL); |
---|
4941 | |
---|
4942 | gtk_widget_realize (window); |
---|
4943 | |
---|
4944 | pixmap1 = gdk_pixmap_create_from_xpm_d (window->window, &mask1, |
---|
4945 | &transparent, book_closed_xpm); |
---|
4946 | pixmap2 = gdk_pixmap_create_from_xpm_d (window->window, &mask2, |
---|
4947 | &transparent, book_open_xpm); |
---|
4948 | pixmap3 = gdk_pixmap_create_from_xpm_d (window->window, &mask3, |
---|
4949 | &transparent, mini_page_xpm); |
---|
4950 | |
---|
4951 | gtk_widget_set_usize (GTK_WIDGET (ctree), 0, 300); |
---|
4952 | |
---|
4953 | frame = gtk_frame_new (NULL); |
---|
4954 | gtk_container_set_border_width (GTK_CONTAINER (frame), 0); |
---|
4955 | gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); |
---|
4956 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); |
---|
4957 | |
---|
4958 | hbox = gtk_hbox_new (TRUE, 2); |
---|
4959 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 2); |
---|
4960 | gtk_container_add (GTK_CONTAINER (frame), hbox); |
---|
4961 | |
---|
4962 | frame = gtk_frame_new (NULL); |
---|
4963 | gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); |
---|
4964 | gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0); |
---|
4965 | |
---|
4966 | hbox2 = gtk_hbox_new (FALSE, 0); |
---|
4967 | gtk_container_set_border_width (GTK_CONTAINER (hbox2), 2); |
---|
4968 | gtk_container_add (GTK_CONTAINER (frame), hbox2); |
---|
4969 | |
---|
4970 | label = gtk_label_new ("Books :"); |
---|
4971 | gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, TRUE, 0); |
---|
4972 | |
---|
4973 | sprintf (buf, "%d", books); |
---|
4974 | book_label = gtk_label_new (buf); |
---|
4975 | gtk_box_pack_end (GTK_BOX (hbox2), book_label, FALSE, TRUE, 5); |
---|
4976 | |
---|
4977 | frame = gtk_frame_new (NULL); |
---|
4978 | gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); |
---|
4979 | gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0); |
---|
4980 | |
---|
4981 | hbox2 = gtk_hbox_new (FALSE, 0); |
---|
4982 | gtk_container_set_border_width (GTK_CONTAINER (hbox2), 2); |
---|
4983 | gtk_container_add (GTK_CONTAINER (frame), hbox2); |
---|
4984 | |
---|
4985 | label = gtk_label_new ("Pages :"); |
---|
4986 | gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, TRUE, 0); |
---|
4987 | |
---|
4988 | sprintf (buf, "%d", pages); |
---|
4989 | page_label = gtk_label_new (buf); |
---|
4990 | gtk_box_pack_end (GTK_BOX (hbox2), page_label, FALSE, TRUE, 5); |
---|
4991 | |
---|
4992 | frame = gtk_frame_new (NULL); |
---|
4993 | gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); |
---|
4994 | gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0); |
---|
4995 | |
---|
4996 | hbox2 = gtk_hbox_new (FALSE, 0); |
---|
4997 | gtk_container_set_border_width (GTK_CONTAINER (hbox2), 2); |
---|
4998 | gtk_container_add (GTK_CONTAINER (frame), hbox2); |
---|
4999 | |
---|
5000 | label = gtk_label_new ("Selected :"); |
---|
5001 | gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, TRUE, 0); |
---|
5002 | |
---|
5003 | sprintf (buf, "%d", g_list_length (GTK_CLIST (ctree)->selection)); |
---|
5004 | sel_label = gtk_label_new (buf); |
---|
5005 | gtk_box_pack_end (GTK_BOX (hbox2), sel_label, FALSE, TRUE, 5); |
---|
5006 | |
---|
5007 | frame = gtk_frame_new (NULL); |
---|
5008 | gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); |
---|
5009 | gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0); |
---|
5010 | |
---|
5011 | hbox2 = gtk_hbox_new (FALSE, 0); |
---|
5012 | gtk_container_set_border_width (GTK_CONTAINER (hbox2), 2); |
---|
5013 | gtk_container_add (GTK_CONTAINER (frame), hbox2); |
---|
5014 | |
---|
5015 | label = gtk_label_new ("Visible :"); |
---|
5016 | gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, TRUE, 0); |
---|
5017 | |
---|
5018 | sprintf (buf, "%d", g_list_length (GTK_CLIST (ctree)->row_list)); |
---|
5019 | vis_label = gtk_label_new (buf); |
---|
5020 | gtk_box_pack_end (GTK_BOX (hbox2), vis_label, FALSE, TRUE, 5); |
---|
5021 | |
---|
5022 | rebuild_tree (NULL, ctree); |
---|
5023 | } |
---|
5024 | |
---|
5025 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5026 | gtk_widget_show_all (window); |
---|
5027 | else |
---|
5028 | gtk_widget_destroy (window); |
---|
5029 | } |
---|
5030 | |
---|
5031 | /* |
---|
5032 | * GtkColorSelection |
---|
5033 | */ |
---|
5034 | |
---|
5035 | void |
---|
5036 | color_selection_ok (GtkWidget *w, |
---|
5037 | GtkColorSelectionDialog *cs) |
---|
5038 | { |
---|
5039 | GtkColorSelection *colorsel; |
---|
5040 | gdouble color[4]; |
---|
5041 | |
---|
5042 | colorsel=GTK_COLOR_SELECTION(cs->colorsel); |
---|
5043 | |
---|
5044 | gtk_color_selection_get_color(colorsel,color); |
---|
5045 | gtk_color_selection_set_color(colorsel,color); |
---|
5046 | } |
---|
5047 | |
---|
5048 | void |
---|
5049 | color_selection_changed (GtkWidget *w, |
---|
5050 | GtkColorSelectionDialog *cs) |
---|
5051 | { |
---|
5052 | GtkColorSelection *colorsel; |
---|
5053 | gdouble color[4]; |
---|
5054 | |
---|
5055 | colorsel=GTK_COLOR_SELECTION(cs->colorsel); |
---|
5056 | gtk_color_selection_get_color(colorsel,color); |
---|
5057 | } |
---|
5058 | |
---|
5059 | void |
---|
5060 | create_color_selection (void) |
---|
5061 | { |
---|
5062 | static GtkWidget *window = NULL; |
---|
5063 | |
---|
5064 | if (!window) |
---|
5065 | { |
---|
5066 | window = gtk_color_selection_dialog_new ("color selection dialog"); |
---|
5067 | |
---|
5068 | gtk_color_selection_set_opacity ( |
---|
5069 | GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel), |
---|
5070 | TRUE); |
---|
5071 | |
---|
5072 | gtk_color_selection_set_update_policy( |
---|
5073 | GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (window)->colorsel), |
---|
5074 | GTK_UPDATE_CONTINUOUS); |
---|
5075 | |
---|
5076 | gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE); |
---|
5077 | |
---|
5078 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5079 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5080 | &window); |
---|
5081 | |
---|
5082 | gtk_signal_connect ( |
---|
5083 | GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->colorsel), |
---|
5084 | "color_changed", |
---|
5085 | GTK_SIGNAL_FUNC(color_selection_changed), |
---|
5086 | window); |
---|
5087 | |
---|
5088 | gtk_signal_connect ( |
---|
5089 | GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->ok_button), |
---|
5090 | "clicked", |
---|
5091 | GTK_SIGNAL_FUNC(color_selection_ok), |
---|
5092 | window); |
---|
5093 | |
---|
5094 | gtk_signal_connect_object ( |
---|
5095 | GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (window)->cancel_button), |
---|
5096 | "clicked", |
---|
5097 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
5098 | GTK_OBJECT (window)); |
---|
5099 | } |
---|
5100 | |
---|
5101 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5102 | gtk_widget_show (window); |
---|
5103 | else |
---|
5104 | gtk_widget_destroy (window); |
---|
5105 | } |
---|
5106 | |
---|
5107 | /* |
---|
5108 | * GtkFileSelection |
---|
5109 | */ |
---|
5110 | |
---|
5111 | void |
---|
5112 | file_selection_hide_fileops (GtkWidget *widget, |
---|
5113 | GtkFileSelection *fs) |
---|
5114 | { |
---|
5115 | gtk_file_selection_hide_fileop_buttons (fs); |
---|
5116 | } |
---|
5117 | |
---|
5118 | void |
---|
5119 | file_selection_ok (GtkWidget *w, |
---|
5120 | GtkFileSelection *fs) |
---|
5121 | { |
---|
5122 | g_print ("%s\n", gtk_file_selection_get_filename (fs)); |
---|
5123 | gtk_widget_destroy (GTK_WIDGET (fs)); |
---|
5124 | } |
---|
5125 | |
---|
5126 | void |
---|
5127 | create_file_selection (void) |
---|
5128 | { |
---|
5129 | static GtkWidget *window = NULL; |
---|
5130 | GtkWidget *button; |
---|
5131 | |
---|
5132 | if (!window) |
---|
5133 | { |
---|
5134 | window = gtk_file_selection_new ("file selection dialog"); |
---|
5135 | |
---|
5136 | gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (window)); |
---|
5137 | |
---|
5138 | gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE); |
---|
5139 | |
---|
5140 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5141 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5142 | &window); |
---|
5143 | |
---|
5144 | gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (window)->ok_button), |
---|
5145 | "clicked", GTK_SIGNAL_FUNC(file_selection_ok), |
---|
5146 | window); |
---|
5147 | gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (window)->cancel_button), |
---|
5148 | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
5149 | GTK_OBJECT (window)); |
---|
5150 | |
---|
5151 | button = gtk_button_new_with_label ("Hide Fileops"); |
---|
5152 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
5153 | (GtkSignalFunc) file_selection_hide_fileops, |
---|
5154 | (gpointer) window); |
---|
5155 | gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (window)->action_area), |
---|
5156 | button, FALSE, FALSE, 0); |
---|
5157 | gtk_widget_show (button); |
---|
5158 | |
---|
5159 | button = gtk_button_new_with_label ("Show Fileops"); |
---|
5160 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
5161 | (GtkSignalFunc) gtk_file_selection_show_fileop_buttons, |
---|
5162 | (gpointer) window); |
---|
5163 | gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (window)->action_area), |
---|
5164 | button, FALSE, FALSE, 0); |
---|
5165 | gtk_widget_show (button); |
---|
5166 | } |
---|
5167 | |
---|
5168 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5169 | gtk_widget_show (window); |
---|
5170 | else |
---|
5171 | gtk_widget_destroy (window); |
---|
5172 | } |
---|
5173 | |
---|
5174 | /* |
---|
5175 | * GtkFontSelection |
---|
5176 | */ |
---|
5177 | |
---|
5178 | void |
---|
5179 | font_selection_ok (GtkWidget *w, |
---|
5180 | GtkFontSelectionDialog *fs) |
---|
5181 | { |
---|
5182 | gchar *s = gtk_font_selection_dialog_get_font_name (fs); |
---|
5183 | |
---|
5184 | g_print ("%s\n", s); |
---|
5185 | g_free (s); |
---|
5186 | gtk_widget_destroy (GTK_WIDGET (fs)); |
---|
5187 | } |
---|
5188 | |
---|
5189 | void |
---|
5190 | create_font_selection (void) |
---|
5191 | { |
---|
5192 | static GtkWidget *window = NULL; |
---|
5193 | |
---|
5194 | if (!window) |
---|
5195 | { |
---|
5196 | window = gtk_font_selection_dialog_new ("Font Selection Dialog"); |
---|
5197 | |
---|
5198 | gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_MOUSE); |
---|
5199 | |
---|
5200 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5201 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5202 | &window); |
---|
5203 | |
---|
5204 | gtk_signal_connect (GTK_OBJECT (GTK_FONT_SELECTION_DIALOG (window)->ok_button), |
---|
5205 | "clicked", GTK_SIGNAL_FUNC(font_selection_ok), |
---|
5206 | GTK_FONT_SELECTION_DIALOG (window)); |
---|
5207 | gtk_signal_connect_object (GTK_OBJECT (GTK_FONT_SELECTION_DIALOG (window)->cancel_button), |
---|
5208 | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
5209 | GTK_OBJECT (window)); |
---|
5210 | } |
---|
5211 | |
---|
5212 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5213 | gtk_widget_show (window); |
---|
5214 | else |
---|
5215 | gtk_widget_destroy (window); |
---|
5216 | } |
---|
5217 | |
---|
5218 | /* |
---|
5219 | * GtkDialog |
---|
5220 | */ |
---|
5221 | |
---|
5222 | static GtkWidget *dialog_window = NULL; |
---|
5223 | |
---|
5224 | static void |
---|
5225 | label_toggle (GtkWidget *widget, |
---|
5226 | GtkWidget **label) |
---|
5227 | { |
---|
5228 | if (!(*label)) |
---|
5229 | { |
---|
5230 | *label = gtk_label_new ("Dialog Test"); |
---|
5231 | gtk_signal_connect (GTK_OBJECT (*label), |
---|
5232 | "destroy", |
---|
5233 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
5234 | label); |
---|
5235 | gtk_misc_set_padding (GTK_MISC (*label), 10, 10); |
---|
5236 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox), |
---|
5237 | *label, TRUE, TRUE, 0); |
---|
5238 | gtk_widget_show (*label); |
---|
5239 | } |
---|
5240 | else |
---|
5241 | gtk_widget_destroy (*label); |
---|
5242 | } |
---|
5243 | |
---|
5244 | static void |
---|
5245 | create_dialog (void) |
---|
5246 | { |
---|
5247 | static GtkWidget *label; |
---|
5248 | GtkWidget *button; |
---|
5249 | |
---|
5250 | if (!dialog_window) |
---|
5251 | { |
---|
5252 | dialog_window = gtk_dialog_new (); |
---|
5253 | |
---|
5254 | gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy", |
---|
5255 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5256 | &dialog_window); |
---|
5257 | |
---|
5258 | gtk_window_set_title (GTK_WINDOW (dialog_window), "GtkDialog"); |
---|
5259 | gtk_container_set_border_width (GTK_CONTAINER (dialog_window), 0); |
---|
5260 | gtk_widget_set_usize (dialog_window, 200, 110); |
---|
5261 | |
---|
5262 | button = gtk_button_new_with_label ("OK"); |
---|
5263 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
5264 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area), |
---|
5265 | button, TRUE, TRUE, 0); |
---|
5266 | gtk_widget_grab_default (button); |
---|
5267 | gtk_widget_show (button); |
---|
5268 | |
---|
5269 | button = gtk_button_new_with_label ("Toggle"); |
---|
5270 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
5271 | GTK_SIGNAL_FUNC (label_toggle), |
---|
5272 | &label); |
---|
5273 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
5274 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area), |
---|
5275 | button, TRUE, TRUE, 0); |
---|
5276 | gtk_widget_show (button); |
---|
5277 | |
---|
5278 | label = NULL; |
---|
5279 | } |
---|
5280 | |
---|
5281 | if (!GTK_WIDGET_VISIBLE (dialog_window)) |
---|
5282 | gtk_widget_show (dialog_window); |
---|
5283 | else |
---|
5284 | gtk_widget_destroy (dialog_window); |
---|
5285 | } |
---|
5286 | |
---|
5287 | /* Event Watcher |
---|
5288 | */ |
---|
5289 | static gboolean event_watcher_enter_id = 0; |
---|
5290 | static gboolean event_watcher_leave_id = 0; |
---|
5291 | |
---|
5292 | static gboolean |
---|
5293 | event_watcher (GtkObject *object, |
---|
5294 | guint signal_id, |
---|
5295 | guint n_params, |
---|
5296 | GtkArg *params, |
---|
5297 | gpointer data) |
---|
5298 | { |
---|
5299 | g_print ("Watch: \"%s\" emitted for %s\n", |
---|
5300 | gtk_signal_name (signal_id), |
---|
5301 | gtk_type_name (GTK_OBJECT_TYPE (object))); |
---|
5302 | |
---|
5303 | return TRUE; |
---|
5304 | } |
---|
5305 | |
---|
5306 | static void |
---|
5307 | event_watcher_down (void) |
---|
5308 | { |
---|
5309 | if (event_watcher_enter_id) |
---|
5310 | { |
---|
5311 | guint signal_id; |
---|
5312 | |
---|
5313 | signal_id = gtk_signal_lookup ("enter_notify_event", GTK_TYPE_WIDGET); |
---|
5314 | gtk_signal_remove_emission_hook (signal_id, event_watcher_enter_id); |
---|
5315 | event_watcher_enter_id = 0; |
---|
5316 | signal_id = gtk_signal_lookup ("leave_notify_event", GTK_TYPE_WIDGET); |
---|
5317 | gtk_signal_remove_emission_hook (signal_id, event_watcher_leave_id); |
---|
5318 | event_watcher_leave_id = 0; |
---|
5319 | } |
---|
5320 | } |
---|
5321 | |
---|
5322 | static void |
---|
5323 | event_watcher_toggle (void) |
---|
5324 | { |
---|
5325 | if (event_watcher_enter_id) |
---|
5326 | event_watcher_down (); |
---|
5327 | else |
---|
5328 | { |
---|
5329 | guint signal_id; |
---|
5330 | |
---|
5331 | signal_id = gtk_signal_lookup ("enter_notify_event", GTK_TYPE_WIDGET); |
---|
5332 | event_watcher_enter_id = gtk_signal_add_emission_hook (signal_id, event_watcher, NULL); |
---|
5333 | signal_id = gtk_signal_lookup ("leave_notify_event", GTK_TYPE_WIDGET); |
---|
5334 | event_watcher_leave_id = gtk_signal_add_emission_hook (signal_id, event_watcher, NULL); |
---|
5335 | } |
---|
5336 | } |
---|
5337 | |
---|
5338 | static void |
---|
5339 | create_event_watcher (void) |
---|
5340 | { |
---|
5341 | GtkWidget *button; |
---|
5342 | |
---|
5343 | if (!dialog_window) |
---|
5344 | { |
---|
5345 | dialog_window = gtk_dialog_new (); |
---|
5346 | |
---|
5347 | gtk_signal_connect (GTK_OBJECT (dialog_window), "destroy", |
---|
5348 | GTK_SIGNAL_FUNC (gtk_widget_destroyed), |
---|
5349 | &dialog_window); |
---|
5350 | gtk_signal_connect (GTK_OBJECT (dialog_window), |
---|
5351 | "destroy", |
---|
5352 | GTK_SIGNAL_FUNC (event_watcher_down), |
---|
5353 | NULL); |
---|
5354 | |
---|
5355 | gtk_window_set_title (GTK_WINDOW (dialog_window), "Event Watcher"); |
---|
5356 | gtk_container_set_border_width (GTK_CONTAINER (dialog_window), 0); |
---|
5357 | gtk_widget_set_usize (dialog_window, 200, 110); |
---|
5358 | |
---|
5359 | button = gtk_toggle_button_new_with_label ("Activate Watch"); |
---|
5360 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
5361 | GTK_SIGNAL_FUNC (event_watcher_toggle), |
---|
5362 | NULL); |
---|
5363 | gtk_container_set_border_width (GTK_CONTAINER (button), 10); |
---|
5364 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->vbox), |
---|
5365 | button, TRUE, TRUE, 0); |
---|
5366 | gtk_widget_show (button); |
---|
5367 | |
---|
5368 | button = gtk_button_new_with_label ("Close"); |
---|
5369 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
5370 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
5371 | (GtkObject*) dialog_window); |
---|
5372 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
5373 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_window)->action_area), |
---|
5374 | button, TRUE, TRUE, 0); |
---|
5375 | gtk_widget_grab_default (button); |
---|
5376 | gtk_widget_show (button); |
---|
5377 | } |
---|
5378 | |
---|
5379 | if (!GTK_WIDGET_VISIBLE (dialog_window)) |
---|
5380 | gtk_widget_show (dialog_window); |
---|
5381 | else |
---|
5382 | gtk_widget_destroy (dialog_window); |
---|
5383 | } |
---|
5384 | |
---|
5385 | /* |
---|
5386 | * GtkRange |
---|
5387 | */ |
---|
5388 | |
---|
5389 | static void |
---|
5390 | create_range_controls (void) |
---|
5391 | { |
---|
5392 | static GtkWidget *window = NULL; |
---|
5393 | GtkWidget *box1; |
---|
5394 | GtkWidget *box2; |
---|
5395 | GtkWidget *button; |
---|
5396 | GtkWidget *scrollbar; |
---|
5397 | GtkWidget *scale; |
---|
5398 | GtkWidget *separator; |
---|
5399 | GtkObject *adjustment; |
---|
5400 | |
---|
5401 | if (!window) |
---|
5402 | { |
---|
5403 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
5404 | |
---|
5405 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5406 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5407 | &window); |
---|
5408 | |
---|
5409 | gtk_window_set_title (GTK_WINDOW (window), "range controls"); |
---|
5410 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
5411 | |
---|
5412 | |
---|
5413 | box1 = gtk_vbox_new (FALSE, 0); |
---|
5414 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
5415 | gtk_widget_show (box1); |
---|
5416 | |
---|
5417 | |
---|
5418 | box2 = gtk_vbox_new (FALSE, 10); |
---|
5419 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
5420 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
5421 | gtk_widget_show (box2); |
---|
5422 | |
---|
5423 | |
---|
5424 | adjustment = gtk_adjustment_new (0.0, 0.0, 101.0, 0.1, 1.0, 1.0); |
---|
5425 | |
---|
5426 | scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment)); |
---|
5427 | gtk_widget_set_usize (GTK_WIDGET (scale), 150, 30); |
---|
5428 | gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED); |
---|
5429 | gtk_scale_set_digits (GTK_SCALE (scale), 1); |
---|
5430 | gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE); |
---|
5431 | gtk_box_pack_start (GTK_BOX (box2), scale, TRUE, TRUE, 0); |
---|
5432 | gtk_widget_show (scale); |
---|
5433 | |
---|
5434 | scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (adjustment)); |
---|
5435 | gtk_range_set_update_policy (GTK_RANGE (scrollbar), |
---|
5436 | GTK_UPDATE_CONTINUOUS); |
---|
5437 | gtk_box_pack_start (GTK_BOX (box2), scrollbar, TRUE, TRUE, 0); |
---|
5438 | gtk_widget_show (scrollbar); |
---|
5439 | |
---|
5440 | |
---|
5441 | separator = gtk_hseparator_new (); |
---|
5442 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
5443 | gtk_widget_show (separator); |
---|
5444 | |
---|
5445 | |
---|
5446 | box2 = gtk_vbox_new (FALSE, 10); |
---|
5447 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
5448 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
5449 | gtk_widget_show (box2); |
---|
5450 | |
---|
5451 | |
---|
5452 | button = gtk_button_new_with_label ("close"); |
---|
5453 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
5454 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
5455 | GTK_OBJECT (window)); |
---|
5456 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
5457 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
5458 | gtk_widget_grab_default (button); |
---|
5459 | gtk_widget_show (button); |
---|
5460 | } |
---|
5461 | |
---|
5462 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5463 | gtk_widget_show (window); |
---|
5464 | else |
---|
5465 | gtk_widget_destroy (window); |
---|
5466 | } |
---|
5467 | |
---|
5468 | /* |
---|
5469 | * GtkRulers |
---|
5470 | */ |
---|
5471 | |
---|
5472 | void |
---|
5473 | create_rulers (void) |
---|
5474 | { |
---|
5475 | static GtkWidget *window = NULL; |
---|
5476 | GtkWidget *table; |
---|
5477 | GtkWidget *ruler; |
---|
5478 | |
---|
5479 | if (!window) |
---|
5480 | { |
---|
5481 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
5482 | gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE); |
---|
5483 | |
---|
5484 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5485 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5486 | &window); |
---|
5487 | |
---|
5488 | gtk_window_set_title (GTK_WINDOW (window), "rulers"); |
---|
5489 | gtk_widget_set_usize (window, 300, 300); |
---|
5490 | gtk_widget_set_events (window, |
---|
5491 | GDK_POINTER_MOTION_MASK |
---|
5492 | | GDK_POINTER_MOTION_HINT_MASK); |
---|
5493 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
5494 | |
---|
5495 | table = gtk_table_new (2, 2, FALSE); |
---|
5496 | gtk_container_add (GTK_CONTAINER (window), table); |
---|
5497 | gtk_widget_show (table); |
---|
5498 | |
---|
5499 | ruler = gtk_hruler_new (); |
---|
5500 | gtk_ruler_set_metric (GTK_RULER (ruler), GTK_CENTIMETERS); |
---|
5501 | gtk_ruler_set_range (GTK_RULER (ruler), 100, 0, 0, 20); |
---|
5502 | |
---|
5503 | gtk_signal_connect_object ( |
---|
5504 | GTK_OBJECT (window), |
---|
5505 | "motion_notify_event", |
---|
5506 | GTK_SIGNAL_FUNC( |
---|
5507 | GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event), |
---|
5508 | GTK_OBJECT (ruler)); |
---|
5509 | |
---|
5510 | gtk_table_attach (GTK_TABLE (table), ruler, 1, 2, 0, 1, |
---|
5511 | GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); |
---|
5512 | gtk_widget_show (ruler); |
---|
5513 | |
---|
5514 | |
---|
5515 | ruler = gtk_vruler_new (); |
---|
5516 | gtk_ruler_set_range (GTK_RULER (ruler), 5, 15, 0, 20); |
---|
5517 | |
---|
5518 | gtk_signal_connect_object ( |
---|
5519 | GTK_OBJECT (window), |
---|
5520 | "motion_notify_event", |
---|
5521 | GTK_SIGNAL_FUNC (GTK_WIDGET_CLASS (GTK_OBJECT (ruler)->klass)->motion_notify_event), |
---|
5522 | GTK_OBJECT (ruler)); |
---|
5523 | |
---|
5524 | gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 2, |
---|
5525 | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); |
---|
5526 | gtk_widget_show (ruler); |
---|
5527 | } |
---|
5528 | |
---|
5529 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5530 | gtk_widget_show (window); |
---|
5531 | else |
---|
5532 | gtk_widget_destroy (window); |
---|
5533 | } |
---|
5534 | |
---|
5535 | static void |
---|
5536 | text_toggle_editable (GtkWidget *checkbutton, |
---|
5537 | GtkWidget *text) |
---|
5538 | { |
---|
5539 | gtk_text_set_editable(GTK_TEXT(text), |
---|
5540 | GTK_TOGGLE_BUTTON(checkbutton)->active); |
---|
5541 | } |
---|
5542 | |
---|
5543 | static void |
---|
5544 | text_toggle_word_wrap (GtkWidget *checkbutton, |
---|
5545 | GtkWidget *text) |
---|
5546 | { |
---|
5547 | gtk_text_set_word_wrap(GTK_TEXT(text), |
---|
5548 | GTK_TOGGLE_BUTTON(checkbutton)->active); |
---|
5549 | } |
---|
5550 | |
---|
5551 | struct { |
---|
5552 | GdkColor color; |
---|
5553 | gchar *name; |
---|
5554 | } text_colors[] = { |
---|
5555 | { { 0, 0x0000, 0x0000, 0x0000 }, "black" }, |
---|
5556 | { { 0, 0xFFFF, 0xFFFF, 0xFFFF }, "white" }, |
---|
5557 | { { 0, 0xFFFF, 0x0000, 0x0000 }, "red" }, |
---|
5558 | { { 0, 0x0000, 0xFFFF, 0x0000 }, "green" }, |
---|
5559 | { { 0, 0x0000, 0x0000, 0xFFFF }, "blue" }, |
---|
5560 | { { 0, 0x0000, 0xFFFF, 0xFFFF }, "cyan" }, |
---|
5561 | { { 0, 0xFFFF, 0x0000, 0xFFFF }, "magenta" }, |
---|
5562 | { { 0, 0xFFFF, 0xFFFF, 0x0000 }, "yellow" } |
---|
5563 | }; |
---|
5564 | |
---|
5565 | int ntext_colors = sizeof(text_colors) / sizeof(text_colors[0]); |
---|
5566 | |
---|
5567 | /* |
---|
5568 | * GtkText |
---|
5569 | */ |
---|
5570 | void |
---|
5571 | text_insert_random (GtkWidget *w, GtkText *text) |
---|
5572 | { |
---|
5573 | int i; |
---|
5574 | char c; |
---|
5575 | for (i=0; i<10; i++) |
---|
5576 | { |
---|
5577 | c = 'A' + rand() % ('Z' - 'A'); |
---|
5578 | gtk_text_set_point (text, rand() % gtk_text_get_length (text)); |
---|
5579 | gtk_text_insert (text, NULL, NULL, NULL, &c, 1); |
---|
5580 | } |
---|
5581 | } |
---|
5582 | |
---|
5583 | void |
---|
5584 | create_text (void) |
---|
5585 | { |
---|
5586 | int i, j; |
---|
5587 | |
---|
5588 | static GtkWidget *window = NULL; |
---|
5589 | GtkWidget *box1; |
---|
5590 | GtkWidget *box2; |
---|
5591 | GtkWidget *hbox; |
---|
5592 | GtkWidget *button; |
---|
5593 | GtkWidget *check; |
---|
5594 | GtkWidget *separator; |
---|
5595 | GtkWidget *scrolled_window; |
---|
5596 | GtkWidget *text; |
---|
5597 | GdkFont *font; |
---|
5598 | |
---|
5599 | FILE *infile; |
---|
5600 | |
---|
5601 | if (!window) |
---|
5602 | { |
---|
5603 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
5604 | gtk_widget_set_name (window, "text window"); |
---|
5605 | gtk_widget_set_usize (window, 500, 500); |
---|
5606 | gtk_window_set_policy (GTK_WINDOW(window), TRUE, TRUE, FALSE); |
---|
5607 | |
---|
5608 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5609 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5610 | &window); |
---|
5611 | |
---|
5612 | gtk_window_set_title (GTK_WINDOW (window), "test"); |
---|
5613 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
5614 | |
---|
5615 | |
---|
5616 | box1 = gtk_vbox_new (FALSE, 0); |
---|
5617 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
5618 | gtk_widget_show (box1); |
---|
5619 | |
---|
5620 | |
---|
5621 | box2 = gtk_vbox_new (FALSE, 10); |
---|
5622 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
5623 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
5624 | gtk_widget_show (box2); |
---|
5625 | |
---|
5626 | |
---|
5627 | scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
---|
5628 | gtk_box_pack_start (GTK_BOX (box2), scrolled_window, TRUE, TRUE, 0); |
---|
5629 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), |
---|
5630 | GTK_POLICY_NEVER, |
---|
5631 | GTK_POLICY_ALWAYS); |
---|
5632 | gtk_widget_show (scrolled_window); |
---|
5633 | |
---|
5634 | text = gtk_text_new (NULL, NULL); |
---|
5635 | gtk_text_set_editable (GTK_TEXT (text), TRUE); |
---|
5636 | gtk_container_add (GTK_CONTAINER (scrolled_window), text); |
---|
5637 | gtk_widget_grab_focus (text); |
---|
5638 | gtk_widget_show (text); |
---|
5639 | |
---|
5640 | |
---|
5641 | gtk_text_freeze (GTK_TEXT (text)); |
---|
5642 | |
---|
5643 | font = gdk_font_load ("-adobe-courier-medium-r-normal--*-120-*-*-*-*-*-*"); |
---|
5644 | |
---|
5645 | for (i=0; i<ntext_colors; i++) |
---|
5646 | { |
---|
5647 | gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, |
---|
5648 | text_colors[i].name, -1); |
---|
5649 | gtk_text_insert (GTK_TEXT (text), font, NULL, NULL, "\t", -1); |
---|
5650 | |
---|
5651 | for (j=0; j<ntext_colors; j++) |
---|
5652 | { |
---|
5653 | gtk_text_insert (GTK_TEXT (text), font, |
---|
5654 | &text_colors[j].color, &text_colors[i].color, |
---|
5655 | "XYZ", -1); |
---|
5656 | } |
---|
5657 | gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, "\n", -1); |
---|
5658 | } |
---|
5659 | |
---|
5660 | /* The Text widget will reference count the font, so we |
---|
5661 | * unreference it here |
---|
5662 | */ |
---|
5663 | gdk_font_unref (font); |
---|
5664 | |
---|
5665 | infile = fopen("/tmp/dosfile", "r"); |
---|
5666 | |
---|
5667 | if (infile) |
---|
5668 | { |
---|
5669 | char *buffer; |
---|
5670 | int nbytes_read, nbytes_alloc; |
---|
5671 | |
---|
5672 | nbytes_read = 0; |
---|
5673 | nbytes_alloc = 1024; |
---|
5674 | buffer = g_new (char, nbytes_alloc); |
---|
5675 | while (1) |
---|
5676 | { |
---|
5677 | int len; |
---|
5678 | if (nbytes_alloc < nbytes_read + 1024) |
---|
5679 | { |
---|
5680 | nbytes_alloc *= 2; |
---|
5681 | buffer = g_realloc (buffer, nbytes_alloc); |
---|
5682 | } |
---|
5683 | len = fread (buffer + nbytes_read, 1, 1024, infile); |
---|
5684 | nbytes_read += len; |
---|
5685 | if (len < 1024) |
---|
5686 | break; |
---|
5687 | } |
---|
5688 | |
---|
5689 | gtk_text_insert (GTK_TEXT (text), NULL, NULL, |
---|
5690 | NULL, buffer, nbytes_read); |
---|
5691 | g_free(buffer); |
---|
5692 | fclose (infile); |
---|
5693 | } |
---|
5694 | |
---|
5695 | gtk_text_thaw (GTK_TEXT (text)); |
---|
5696 | |
---|
5697 | hbox = gtk_hbutton_box_new (); |
---|
5698 | gtk_box_pack_start (GTK_BOX (box2), hbox, FALSE, FALSE, 0); |
---|
5699 | gtk_widget_show (hbox); |
---|
5700 | |
---|
5701 | check = gtk_check_button_new_with_label("Editable"); |
---|
5702 | gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0); |
---|
5703 | gtk_signal_connect (GTK_OBJECT(check), "toggled", |
---|
5704 | GTK_SIGNAL_FUNC(text_toggle_editable), text); |
---|
5705 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE); |
---|
5706 | gtk_widget_show (check); |
---|
5707 | |
---|
5708 | check = gtk_check_button_new_with_label("Wrap Words"); |
---|
5709 | gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, TRUE, 0); |
---|
5710 | gtk_signal_connect (GTK_OBJECT(check), "toggled", |
---|
5711 | GTK_SIGNAL_FUNC(text_toggle_word_wrap), text); |
---|
5712 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), FALSE); |
---|
5713 | gtk_widget_show (check); |
---|
5714 | |
---|
5715 | separator = gtk_hseparator_new (); |
---|
5716 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
5717 | gtk_widget_show (separator); |
---|
5718 | |
---|
5719 | |
---|
5720 | box2 = gtk_vbox_new (FALSE, 10); |
---|
5721 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
5722 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
5723 | gtk_widget_show (box2); |
---|
5724 | |
---|
5725 | |
---|
5726 | button = gtk_button_new_with_label ("insert random"); |
---|
5727 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
5728 | GTK_SIGNAL_FUNC(text_insert_random), |
---|
5729 | GTK_TEXT (text)); |
---|
5730 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
5731 | gtk_widget_show (button); |
---|
5732 | |
---|
5733 | button = gtk_button_new_with_label ("close"); |
---|
5734 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
5735 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
5736 | GTK_OBJECT (window)); |
---|
5737 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
5738 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
5739 | gtk_widget_grab_default (button); |
---|
5740 | gtk_widget_show (button); |
---|
5741 | } |
---|
5742 | |
---|
5743 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
5744 | gtk_widget_show (window); |
---|
5745 | else |
---|
5746 | gtk_widget_destroy (window); |
---|
5747 | } |
---|
5748 | |
---|
5749 | /* |
---|
5750 | * GtkNotebook |
---|
5751 | */ |
---|
5752 | |
---|
5753 | GdkPixmap *book_open; |
---|
5754 | GdkPixmap *book_closed; |
---|
5755 | GdkBitmap *book_open_mask; |
---|
5756 | GdkBitmap *book_closed_mask; |
---|
5757 | GtkWidget *sample_notebook; |
---|
5758 | |
---|
5759 | static void |
---|
5760 | page_switch (GtkWidget *widget, GtkNotebookPage *page, gint page_num) |
---|
5761 | { |
---|
5762 | GtkNotebookPage *oldpage; |
---|
5763 | GtkWidget *pixwid; |
---|
5764 | |
---|
5765 | oldpage = GTK_NOTEBOOK (widget)->cur_page; |
---|
5766 | |
---|
5767 | if (page == oldpage) |
---|
5768 | return; |
---|
5769 | pixwid = ((GtkBoxChild*) |
---|
5770 | (GTK_BOX (page->tab_label)->children->data))->widget; |
---|
5771 | gtk_pixmap_set (GTK_PIXMAP (pixwid), book_open, book_open_mask); |
---|
5772 | pixwid = ((GtkBoxChild*) |
---|
5773 | (GTK_BOX (page->menu_label)->children->data))->widget; |
---|
5774 | gtk_pixmap_set (GTK_PIXMAP (pixwid), book_open, book_open_mask); |
---|
5775 | |
---|
5776 | if (oldpage) |
---|
5777 | { |
---|
5778 | pixwid = ((GtkBoxChild*) |
---|
5779 | (GTK_BOX (oldpage->tab_label)->children->data))->widget; |
---|
5780 | gtk_pixmap_set (GTK_PIXMAP (pixwid), book_closed, book_closed_mask); |
---|
5781 | pixwid = ((GtkBoxChild*) |
---|
5782 | (GTK_BOX (oldpage->menu_label)->children->data))->widget; |
---|
5783 | gtk_pixmap_set (GTK_PIXMAP (pixwid), book_closed, book_closed_mask); |
---|
5784 | } |
---|
5785 | } |
---|
5786 | |
---|
5787 | static void |
---|
5788 | tab_fill (GtkToggleButton *button, GtkWidget *child) |
---|
5789 | { |
---|
5790 | gboolean expand; |
---|
5791 | GtkPackType pack_type; |
---|
5792 | |
---|
5793 | gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (sample_notebook), child, |
---|
5794 | &expand, NULL, &pack_type); |
---|
5795 | gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (sample_notebook), child, |
---|
5796 | expand, button->active, pack_type); |
---|
5797 | } |
---|
5798 | |
---|
5799 | static void |
---|
5800 | tab_expand (GtkToggleButton *button, GtkWidget *child) |
---|
5801 | { |
---|
5802 | gboolean fill; |
---|
5803 | GtkPackType pack_type; |
---|
5804 | |
---|
5805 | gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (sample_notebook), child, |
---|
5806 | NULL, &fill, &pack_type); |
---|
5807 | gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (sample_notebook), child, |
---|
5808 | button->active, fill, pack_type); |
---|
5809 | } |
---|
5810 | |
---|
5811 | static void |
---|
5812 | tab_pack (GtkToggleButton *button, GtkWidget *child) |
---|
5813 | |
---|
5814 | { |
---|
5815 | gboolean expand; |
---|
5816 | gboolean fill; |
---|
5817 | |
---|
5818 | gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (sample_notebook), child, |
---|
5819 | &expand, &fill, NULL); |
---|
5820 | gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (sample_notebook), child, |
---|
5821 | expand, fill, button->active); |
---|
5822 | } |
---|
5823 | |
---|
5824 | static void |
---|
5825 | create_pages (GtkNotebook *notebook, gint start, gint end) |
---|
5826 | { |
---|
5827 | GtkWidget *child = NULL; |
---|
5828 | GtkWidget *button; |
---|
5829 | GtkWidget *label; |
---|
5830 | GtkWidget *hbox; |
---|
5831 | GtkWidget *vbox; |
---|
5832 | GtkWidget *label_box; |
---|
5833 | GtkWidget *menu_box; |
---|
5834 | GtkWidget *pixwid; |
---|
5835 | gint i; |
---|
5836 | char buffer[32]; |
---|
5837 | |
---|
5838 | for (i = start; i <= end; i++) |
---|
5839 | { |
---|
5840 | sprintf (buffer, "Page %d", i); |
---|
5841 | |
---|
5842 | child = gtk_frame_new (buffer); |
---|
5843 | gtk_container_set_border_width (GTK_CONTAINER (child), 10); |
---|
5844 | |
---|
5845 | vbox = gtk_vbox_new (TRUE,0); |
---|
5846 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); |
---|
5847 | gtk_container_add (GTK_CONTAINER (child), vbox); |
---|
5848 | |
---|
5849 | hbox = gtk_hbox_new (TRUE,0); |
---|
5850 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 5); |
---|
5851 | |
---|
5852 | button = gtk_check_button_new_with_label ("Fill Tab"); |
---|
5853 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
5854 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); |
---|
5855 | gtk_signal_connect (GTK_OBJECT (button), "toggled", |
---|
5856 | GTK_SIGNAL_FUNC (tab_fill), child); |
---|
5857 | |
---|
5858 | button = gtk_check_button_new_with_label ("Expand Tab"); |
---|
5859 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
5860 | gtk_signal_connect (GTK_OBJECT (button), "toggled", |
---|
5861 | GTK_SIGNAL_FUNC (tab_expand), child); |
---|
5862 | |
---|
5863 | button = gtk_check_button_new_with_label ("Pack end"); |
---|
5864 | gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 5); |
---|
5865 | gtk_signal_connect (GTK_OBJECT (button), "toggled", |
---|
5866 | GTK_SIGNAL_FUNC (tab_pack), child); |
---|
5867 | |
---|
5868 | button = gtk_button_new_with_label ("Hide Page"); |
---|
5869 | gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 5); |
---|
5870 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
5871 | GTK_SIGNAL_FUNC (gtk_widget_hide), |
---|
5872 | GTK_OBJECT (child)); |
---|
5873 | |
---|
5874 | gtk_widget_show_all (child); |
---|
5875 | |
---|
5876 | label_box = gtk_hbox_new (FALSE, 0); |
---|
5877 | pixwid = gtk_pixmap_new (book_closed, book_closed_mask); |
---|
5878 | gtk_box_pack_start (GTK_BOX (label_box), pixwid, FALSE, TRUE, 0); |
---|
5879 | gtk_misc_set_padding (GTK_MISC (pixwid), 3, 1); |
---|
5880 | label = gtk_label_new (buffer); |
---|
5881 | gtk_box_pack_start (GTK_BOX (label_box), label, FALSE, TRUE, 0); |
---|
5882 | gtk_widget_show_all (label_box); |
---|
5883 | |
---|
5884 | menu_box = gtk_hbox_new (FALSE, 0); |
---|
5885 | pixwid = gtk_pixmap_new (book_closed, book_closed_mask); |
---|
5886 | gtk_box_pack_start (GTK_BOX (menu_box), pixwid, FALSE, TRUE, 0); |
---|
5887 | gtk_misc_set_padding (GTK_MISC (pixwid), 3, 1); |
---|
5888 | label = gtk_label_new (buffer); |
---|
5889 | gtk_box_pack_start (GTK_BOX (menu_box), label, FALSE, TRUE, 0); |
---|
5890 | gtk_widget_show_all (menu_box); |
---|
5891 | gtk_notebook_append_page_menu (notebook, child, label_box, menu_box); |
---|
5892 | } |
---|
5893 | } |
---|
5894 | |
---|
5895 | static void |
---|
5896 | rotate_notebook (GtkButton *button, |
---|
5897 | GtkNotebook *notebook) |
---|
5898 | { |
---|
5899 | gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos + 1) % 4); |
---|
5900 | } |
---|
5901 | |
---|
5902 | static void |
---|
5903 | show_all_pages (GtkButton *button, |
---|
5904 | GtkNotebook *notebook) |
---|
5905 | { |
---|
5906 | gtk_container_foreach (GTK_CONTAINER (notebook), |
---|
5907 | (GtkCallback) gtk_widget_show, NULL); |
---|
5908 | } |
---|
5909 | |
---|
5910 | static void |
---|
5911 | standard_notebook (GtkButton *button, |
---|
5912 | GtkNotebook *notebook) |
---|
5913 | { |
---|
5914 | gint i; |
---|
5915 | |
---|
5916 | gtk_notebook_set_show_tabs (notebook, TRUE); |
---|
5917 | gtk_notebook_set_scrollable (notebook, FALSE); |
---|
5918 | if (g_list_length (notebook->children) == 15) |
---|
5919 | for (i = 0; i < 10; i++) |
---|
5920 | gtk_notebook_remove_page (notebook, 5); |
---|
5921 | } |
---|
5922 | |
---|
5923 | static void |
---|
5924 | notabs_notebook (GtkButton *button, |
---|
5925 | GtkNotebook *notebook) |
---|
5926 | { |
---|
5927 | gint i; |
---|
5928 | |
---|
5929 | gtk_notebook_set_show_tabs (notebook, FALSE); |
---|
5930 | if (g_list_length (notebook->children) == 15) |
---|
5931 | for (i = 0; i < 10; i++) |
---|
5932 | gtk_notebook_remove_page (notebook, 5); |
---|
5933 | } |
---|
5934 | |
---|
5935 | static void |
---|
5936 | scrollable_notebook (GtkButton *button, |
---|
5937 | GtkNotebook *notebook) |
---|
5938 | { |
---|
5939 | gtk_notebook_set_show_tabs (notebook, TRUE); |
---|
5940 | gtk_notebook_set_scrollable (notebook, TRUE); |
---|
5941 | if (g_list_length (notebook->children) == 5) |
---|
5942 | create_pages (notebook, 6, 15); |
---|
5943 | } |
---|
5944 | |
---|
5945 | static void |
---|
5946 | notebook_popup (GtkToggleButton *button, |
---|
5947 | GtkNotebook *notebook) |
---|
5948 | { |
---|
5949 | if (button->active) |
---|
5950 | gtk_notebook_popup_enable (notebook); |
---|
5951 | else |
---|
5952 | gtk_notebook_popup_disable (notebook); |
---|
5953 | } |
---|
5954 | |
---|
5955 | static void |
---|
5956 | notebook_homogeneous (GtkToggleButton *button, |
---|
5957 | GtkNotebook *notebook) |
---|
5958 | { |
---|
5959 | gtk_notebook_set_homogeneous_tabs (notebook, button->active); |
---|
5960 | } |
---|
5961 | |
---|
5962 | static void |
---|
5963 | create_notebook (void) |
---|
5964 | { |
---|
5965 | static GtkWidget *window = NULL; |
---|
5966 | GtkWidget *box1; |
---|
5967 | GtkWidget *box2; |
---|
5968 | GtkWidget *button; |
---|
5969 | GtkWidget *separator; |
---|
5970 | GtkWidget *omenu; |
---|
5971 | GdkColor *transparent = NULL; |
---|
5972 | GtkWidget *label; |
---|
5973 | |
---|
5974 | static OptionMenuItem items[] = |
---|
5975 | { |
---|
5976 | { "Standard", standard_notebook }, |
---|
5977 | { "No tabs", notabs_notebook }, |
---|
5978 | { "Scrollable", scrollable_notebook } |
---|
5979 | }; |
---|
5980 | |
---|
5981 | if (!window) |
---|
5982 | { |
---|
5983 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
5984 | |
---|
5985 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
5986 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
5987 | &window); |
---|
5988 | |
---|
5989 | gtk_window_set_title (GTK_WINDOW (window), "notebook"); |
---|
5990 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
5991 | |
---|
5992 | box1 = gtk_vbox_new (FALSE, 0); |
---|
5993 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
5994 | |
---|
5995 | sample_notebook = gtk_notebook_new (); |
---|
5996 | gtk_signal_connect (GTK_OBJECT (sample_notebook), "switch_page", |
---|
5997 | GTK_SIGNAL_FUNC (page_switch), NULL); |
---|
5998 | gtk_notebook_set_tab_pos (GTK_NOTEBOOK (sample_notebook), GTK_POS_TOP); |
---|
5999 | gtk_box_pack_start (GTK_BOX (box1), sample_notebook, TRUE, TRUE, 0); |
---|
6000 | gtk_container_set_border_width (GTK_CONTAINER (sample_notebook), 10); |
---|
6001 | |
---|
6002 | gtk_widget_realize (sample_notebook); |
---|
6003 | book_open = gdk_pixmap_create_from_xpm_d (sample_notebook->window, |
---|
6004 | &book_open_mask, |
---|
6005 | transparent, |
---|
6006 | book_open_xpm); |
---|
6007 | book_closed = gdk_pixmap_create_from_xpm_d (sample_notebook->window, |
---|
6008 | &book_closed_mask, |
---|
6009 | transparent, |
---|
6010 | book_closed_xpm); |
---|
6011 | |
---|
6012 | create_pages (GTK_NOTEBOOK (sample_notebook), 1, 5); |
---|
6013 | |
---|
6014 | separator = gtk_hseparator_new (); |
---|
6015 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 10); |
---|
6016 | |
---|
6017 | box2 = gtk_hbox_new (FALSE, 5); |
---|
6018 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
6019 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
6020 | |
---|
6021 | button = gtk_check_button_new_with_label ("popup menu"); |
---|
6022 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, FALSE, 0); |
---|
6023 | gtk_signal_connect (GTK_OBJECT(button), "clicked", |
---|
6024 | GTK_SIGNAL_FUNC (notebook_popup), |
---|
6025 | GTK_OBJECT (sample_notebook)); |
---|
6026 | |
---|
6027 | button = gtk_check_button_new_with_label ("homogeneous tabs"); |
---|
6028 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, FALSE, 0); |
---|
6029 | gtk_signal_connect (GTK_OBJECT(button), "clicked", |
---|
6030 | GTK_SIGNAL_FUNC (notebook_homogeneous), |
---|
6031 | GTK_OBJECT (sample_notebook)); |
---|
6032 | |
---|
6033 | box2 = gtk_hbox_new (FALSE, 5); |
---|
6034 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
6035 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
6036 | |
---|
6037 | label = gtk_label_new ("Notebook Style :"); |
---|
6038 | gtk_box_pack_start (GTK_BOX (box2), label, FALSE, TRUE, 0); |
---|
6039 | |
---|
6040 | omenu = build_option_menu (items, 3, 0, sample_notebook); |
---|
6041 | gtk_box_pack_start (GTK_BOX (box2), omenu, FALSE, TRUE, 0); |
---|
6042 | |
---|
6043 | button = gtk_button_new_with_label ("Show all Pages"); |
---|
6044 | gtk_box_pack_start (GTK_BOX (box2), button, FALSE, TRUE, 0); |
---|
6045 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
6046 | GTK_SIGNAL_FUNC (show_all_pages), sample_notebook); |
---|
6047 | |
---|
6048 | box2 = gtk_hbox_new (TRUE, 10); |
---|
6049 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
6050 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
6051 | |
---|
6052 | button = gtk_button_new_with_label ("prev"); |
---|
6053 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
6054 | GTK_SIGNAL_FUNC (gtk_notebook_prev_page), |
---|
6055 | GTK_OBJECT (sample_notebook)); |
---|
6056 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
6057 | |
---|
6058 | button = gtk_button_new_with_label ("next"); |
---|
6059 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
6060 | GTK_SIGNAL_FUNC (gtk_notebook_next_page), |
---|
6061 | GTK_OBJECT (sample_notebook)); |
---|
6062 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
6063 | |
---|
6064 | button = gtk_button_new_with_label ("rotate"); |
---|
6065 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
6066 | GTK_SIGNAL_FUNC (rotate_notebook), sample_notebook); |
---|
6067 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
6068 | |
---|
6069 | separator = gtk_hseparator_new (); |
---|
6070 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); |
---|
6071 | |
---|
6072 | button = gtk_button_new_with_label ("close"); |
---|
6073 | gtk_container_set_border_width (GTK_CONTAINER (button), 5); |
---|
6074 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
6075 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
6076 | GTK_OBJECT (window)); |
---|
6077 | gtk_box_pack_start (GTK_BOX (box1), button, FALSE, FALSE, 0); |
---|
6078 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
6079 | gtk_widget_grab_default (button); |
---|
6080 | } |
---|
6081 | |
---|
6082 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
6083 | gtk_widget_show_all (window); |
---|
6084 | else |
---|
6085 | gtk_widget_destroy (window); |
---|
6086 | } |
---|
6087 | |
---|
6088 | /* |
---|
6089 | * GtkPanes |
---|
6090 | */ |
---|
6091 | |
---|
6092 | void |
---|
6093 | toggle_resize (GtkWidget *widget, GtkWidget *child) |
---|
6094 | { |
---|
6095 | GtkPaned *paned = GTK_PANED (child->parent); |
---|
6096 | gboolean is_child1 = (child == paned->child1); |
---|
6097 | gboolean resize, shrink; |
---|
6098 | |
---|
6099 | resize = is_child1 ? paned->child1_resize : paned->child2_resize; |
---|
6100 | shrink = is_child1 ? paned->child1_shrink : paned->child2_shrink; |
---|
6101 | |
---|
6102 | gtk_widget_ref (child); |
---|
6103 | gtk_container_remove (GTK_CONTAINER (child->parent), child); |
---|
6104 | if (is_child1) |
---|
6105 | gtk_paned_pack1 (paned, child, !resize, shrink); |
---|
6106 | else |
---|
6107 | gtk_paned_pack2 (paned, child, !resize, shrink); |
---|
6108 | gtk_widget_unref (child); |
---|
6109 | } |
---|
6110 | |
---|
6111 | void |
---|
6112 | toggle_shrink (GtkWidget *widget, GtkWidget *child) |
---|
6113 | { |
---|
6114 | GtkPaned *paned = GTK_PANED (child->parent); |
---|
6115 | gboolean is_child1 = (child == paned->child1); |
---|
6116 | gboolean resize, shrink; |
---|
6117 | |
---|
6118 | resize = is_child1 ? paned->child1_resize : paned->child2_resize; |
---|
6119 | shrink = is_child1 ? paned->child1_shrink : paned->child2_shrink; |
---|
6120 | |
---|
6121 | gtk_widget_ref (child); |
---|
6122 | gtk_container_remove (GTK_CONTAINER (child->parent), child); |
---|
6123 | if (is_child1) |
---|
6124 | gtk_paned_pack1 (paned, child, resize, !shrink); |
---|
6125 | else |
---|
6126 | gtk_paned_pack2 (paned, child, resize, !shrink); |
---|
6127 | gtk_widget_unref (child); |
---|
6128 | } |
---|
6129 | |
---|
6130 | GtkWidget * |
---|
6131 | create_pane_options (GtkPaned *paned, |
---|
6132 | const gchar *frame_label, |
---|
6133 | const gchar *label1, |
---|
6134 | const gchar *label2) |
---|
6135 | { |
---|
6136 | GtkWidget *frame; |
---|
6137 | GtkWidget *table; |
---|
6138 | GtkWidget *label; |
---|
6139 | GtkWidget *check_button; |
---|
6140 | |
---|
6141 | frame = gtk_frame_new (frame_label); |
---|
6142 | gtk_container_set_border_width (GTK_CONTAINER (frame), 4); |
---|
6143 | |
---|
6144 | table = gtk_table_new (3, 2, 4); |
---|
6145 | gtk_container_add (GTK_CONTAINER (frame), table); |
---|
6146 | |
---|
6147 | label = gtk_label_new (label1); |
---|
6148 | gtk_table_attach_defaults (GTK_TABLE (table), label, |
---|
6149 | 0, 1, 0, 1); |
---|
6150 | |
---|
6151 | check_button = gtk_check_button_new_with_label ("Resize"); |
---|
6152 | gtk_table_attach_defaults (GTK_TABLE (table), check_button, |
---|
6153 | 0, 1, 1, 2); |
---|
6154 | gtk_signal_connect (GTK_OBJECT (check_button), "toggled", |
---|
6155 | GTK_SIGNAL_FUNC (toggle_resize), |
---|
6156 | paned->child1); |
---|
6157 | |
---|
6158 | check_button = gtk_check_button_new_with_label ("Shrink"); |
---|
6159 | gtk_table_attach_defaults (GTK_TABLE (table), check_button, |
---|
6160 | 0, 1, 2, 3); |
---|
6161 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), |
---|
6162 | TRUE); |
---|
6163 | gtk_signal_connect (GTK_OBJECT (check_button), "toggled", |
---|
6164 | GTK_SIGNAL_FUNC (toggle_shrink), |
---|
6165 | paned->child1); |
---|
6166 | |
---|
6167 | label = gtk_label_new (label2); |
---|
6168 | gtk_table_attach_defaults (GTK_TABLE (table), label, |
---|
6169 | 1, 2, 0, 1); |
---|
6170 | |
---|
6171 | check_button = gtk_check_button_new_with_label ("Resize"); |
---|
6172 | gtk_table_attach_defaults (GTK_TABLE (table), check_button, |
---|
6173 | 1, 2, 1, 2); |
---|
6174 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), |
---|
6175 | TRUE); |
---|
6176 | gtk_signal_connect (GTK_OBJECT (check_button), "toggled", |
---|
6177 | GTK_SIGNAL_FUNC (toggle_resize), |
---|
6178 | paned->child2); |
---|
6179 | |
---|
6180 | check_button = gtk_check_button_new_with_label ("Shrink"); |
---|
6181 | gtk_table_attach_defaults (GTK_TABLE (table), check_button, |
---|
6182 | 1, 2, 2, 3); |
---|
6183 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), |
---|
6184 | TRUE); |
---|
6185 | gtk_signal_connect (GTK_OBJECT (check_button), "toggled", |
---|
6186 | GTK_SIGNAL_FUNC (toggle_shrink), |
---|
6187 | paned->child2); |
---|
6188 | |
---|
6189 | return frame; |
---|
6190 | } |
---|
6191 | |
---|
6192 | void |
---|
6193 | create_panes (void) |
---|
6194 | { |
---|
6195 | static GtkWidget *window = NULL; |
---|
6196 | GtkWidget *frame; |
---|
6197 | GtkWidget *hpaned; |
---|
6198 | GtkWidget *vpaned; |
---|
6199 | GtkWidget *button; |
---|
6200 | GtkWidget *vbox; |
---|
6201 | |
---|
6202 | if (!window) |
---|
6203 | { |
---|
6204 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
6205 | |
---|
6206 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
6207 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6208 | &window); |
---|
6209 | |
---|
6210 | gtk_window_set_title (GTK_WINDOW (window), "Panes"); |
---|
6211 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
6212 | |
---|
6213 | vbox = gtk_vbox_new (FALSE, 0); |
---|
6214 | gtk_container_add (GTK_CONTAINER (window), vbox); |
---|
6215 | |
---|
6216 | vpaned = gtk_vpaned_new (); |
---|
6217 | gtk_box_pack_start (GTK_BOX (vbox), vpaned, TRUE, TRUE, 0); |
---|
6218 | gtk_container_set_border_width (GTK_CONTAINER(vpaned), 5); |
---|
6219 | |
---|
6220 | hpaned = gtk_hpaned_new (); |
---|
6221 | gtk_paned_add1 (GTK_PANED (vpaned), hpaned); |
---|
6222 | |
---|
6223 | frame = gtk_frame_new (NULL); |
---|
6224 | gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); |
---|
6225 | gtk_widget_set_usize (frame, 60, 60); |
---|
6226 | gtk_paned_add1 (GTK_PANED (hpaned), frame); |
---|
6227 | |
---|
6228 | button = gtk_button_new_with_label ("Hi there"); |
---|
6229 | gtk_container_add (GTK_CONTAINER(frame), button); |
---|
6230 | |
---|
6231 | frame = gtk_frame_new (NULL); |
---|
6232 | gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); |
---|
6233 | gtk_widget_set_usize (frame, 80, 60); |
---|
6234 | gtk_paned_add2 (GTK_PANED (hpaned), frame); |
---|
6235 | |
---|
6236 | frame = gtk_frame_new (NULL); |
---|
6237 | gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_IN); |
---|
6238 | gtk_widget_set_usize (frame, 60, 80); |
---|
6239 | gtk_paned_add2 (GTK_PANED (vpaned), frame); |
---|
6240 | |
---|
6241 | /* Now create toggle buttons to control sizing */ |
---|
6242 | |
---|
6243 | gtk_box_pack_start (GTK_BOX (vbox), |
---|
6244 | create_pane_options (GTK_PANED (hpaned), |
---|
6245 | "Horizontal", |
---|
6246 | "Left", |
---|
6247 | "Right"), |
---|
6248 | FALSE, FALSE, 0); |
---|
6249 | |
---|
6250 | gtk_box_pack_start (GTK_BOX (vbox), |
---|
6251 | create_pane_options (GTK_PANED (vpaned), |
---|
6252 | "Vertical", |
---|
6253 | "Top", |
---|
6254 | "Bottom"), |
---|
6255 | FALSE, FALSE, 0); |
---|
6256 | |
---|
6257 | gtk_widget_show_all (vbox); |
---|
6258 | } |
---|
6259 | |
---|
6260 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
6261 | gtk_widget_show (window); |
---|
6262 | else |
---|
6263 | gtk_widget_destroy (window); |
---|
6264 | } |
---|
6265 | |
---|
6266 | /* |
---|
6267 | * Drag -N- Drop |
---|
6268 | */ |
---|
6269 | |
---|
6270 | #if 0 |
---|
6271 | gint |
---|
6272 | dnd_drop_destroy_popup (GtkWidget *widget, GtkWindow **window) |
---|
6273 | { |
---|
6274 | if(GTK_IS_BUTTON(widget)) /* I.e. they clicked the close button */ |
---|
6275 | gtk_widget_destroy(GTK_WIDGET(*window)); |
---|
6276 | else { |
---|
6277 | gtk_grab_remove(GTK_WIDGET(*window)); |
---|
6278 | *window = NULL; |
---|
6279 | } |
---|
6280 | |
---|
6281 | return FALSE; |
---|
6282 | } |
---|
6283 | |
---|
6284 | void |
---|
6285 | dnd_drop (GtkWidget *button, GdkEvent *event) |
---|
6286 | { |
---|
6287 | static GtkWidget *window = NULL; |
---|
6288 | GtkWidget *vbox, *lbl, *btn; |
---|
6289 | gchar *msg; |
---|
6290 | |
---|
6291 | /* DND doesn't obey gtk_grab's, so check if we're already displaying |
---|
6292 | * drop modal dialog first |
---|
6293 | */ |
---|
6294 | if (window) |
---|
6295 | return; |
---|
6296 | |
---|
6297 | window = gtk_window_new(GTK_WINDOW_DIALOG); |
---|
6298 | gtk_container_set_border_width (GTK_CONTAINER(window), 10); |
---|
6299 | |
---|
6300 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
6301 | GTK_SIGNAL_FUNC(dnd_drop_destroy_popup), |
---|
6302 | &window); |
---|
6303 | gtk_signal_connect (GTK_OBJECT (window), "delete-event", |
---|
6304 | GTK_SIGNAL_FUNC(gtk_false), |
---|
6305 | &window); |
---|
6306 | |
---|
6307 | vbox = gtk_vbox_new(FALSE, 5); |
---|
6308 | |
---|
6309 | /* Display message that we got from drop source */ |
---|
6310 | msg = g_malloc(strlen(event->dropdataavailable.data) |
---|
6311 | + strlen(event->dropdataavailable.data_type) + 100); |
---|
6312 | sprintf(msg, "Drop data of type %s was:\n\n%s", |
---|
6313 | event->dropdataavailable.data_type, |
---|
6314 | (char *)event->dropdataavailable.data); |
---|
6315 | lbl = gtk_label_new(msg); |
---|
6316 | gtk_label_set_justify(GTK_LABEL(lbl), GTK_JUSTIFY_FILL); |
---|
6317 | g_free(msg); |
---|
6318 | gtk_widget_show(lbl); |
---|
6319 | gtk_box_pack_start_defaults(GTK_BOX(vbox), lbl); |
---|
6320 | |
---|
6321 | /* Provide an obvious way out of this heinousness */ |
---|
6322 | btn = gtk_button_new_with_label("Continue with life in\nspite of this oppression"); |
---|
6323 | gtk_signal_connect_object (GTK_OBJECT (btn), "clicked", |
---|
6324 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
6325 | GTK_OBJECT (window)); |
---|
6326 | gtk_widget_show(btn); |
---|
6327 | gtk_box_pack_start_defaults(GTK_BOX(vbox), btn); |
---|
6328 | |
---|
6329 | gtk_container_add(GTK_CONTAINER(window), vbox); |
---|
6330 | |
---|
6331 | gtk_widget_show(vbox); |
---|
6332 | gtk_grab_add(window); |
---|
6333 | gtk_widget_show(window); |
---|
6334 | } |
---|
6335 | |
---|
6336 | void |
---|
6337 | dnd_drag_request (GtkWidget *button, GdkEvent *event) |
---|
6338 | { |
---|
6339 | #define DND_STRING "Bill Gates demands royalties for\nyour use of his innovation." |
---|
6340 | gtk_widget_dnd_data_set (button, event, DND_STRING, strlen(DND_STRING) + 1); |
---|
6341 | } |
---|
6342 | |
---|
6343 | void |
---|
6344 | create_dnd (void) |
---|
6345 | { |
---|
6346 | static GtkWidget *window = NULL; |
---|
6347 | GtkWidget *box1; |
---|
6348 | GtkWidget *box2; |
---|
6349 | GtkWidget *box3; |
---|
6350 | GtkWidget *frame; |
---|
6351 | GtkWidget *button; |
---|
6352 | GtkWidget *separator; |
---|
6353 | |
---|
6354 | /* For clarity... */ |
---|
6355 | char *possible_drag_types[] = {"text/plain"}; |
---|
6356 | char *accepted_drop_types[] = {"text/plain"}; |
---|
6357 | |
---|
6358 | static GtkWidget *drag_icon = NULL; |
---|
6359 | static GtkWidget *drop_icon = NULL; |
---|
6360 | |
---|
6361 | if (!window) |
---|
6362 | { |
---|
6363 | GdkPoint hotspot = {5,5}; |
---|
6364 | |
---|
6365 | if (!drag_icon) |
---|
6366 | { |
---|
6367 | drag_icon = shape_create_icon ("Modeller.xpm", |
---|
6368 | 440, 140, 0,0, GTK_WINDOW_POPUP); |
---|
6369 | |
---|
6370 | gtk_signal_connect (GTK_OBJECT (drag_icon), "destroy", |
---|
6371 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6372 | &drag_icon); |
---|
6373 | |
---|
6374 | gtk_widget_hide (drag_icon); |
---|
6375 | } |
---|
6376 | |
---|
6377 | if (!drop_icon) |
---|
6378 | { |
---|
6379 | drop_icon = shape_create_icon ("3DRings.xpm", |
---|
6380 | 440, 140, 0,0, GTK_WINDOW_POPUP); |
---|
6381 | |
---|
6382 | gtk_signal_connect (GTK_OBJECT (drop_icon), "destroy", |
---|
6383 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6384 | &drop_icon); |
---|
6385 | |
---|
6386 | gtk_widget_hide (drop_icon); |
---|
6387 | } |
---|
6388 | |
---|
6389 | gdk_dnd_set_drag_shape(drag_icon->window, |
---|
6390 | &hotspot, |
---|
6391 | drop_icon->window, |
---|
6392 | &hotspot); |
---|
6393 | |
---|
6394 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
6395 | |
---|
6396 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
6397 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6398 | &window); |
---|
6399 | |
---|
6400 | gtk_window_set_title (GTK_WINDOW (window), "Drag -N- Drop"); |
---|
6401 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
6402 | |
---|
6403 | box1 = gtk_vbox_new (FALSE, 0); |
---|
6404 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
6405 | gtk_widget_show (box1); |
---|
6406 | |
---|
6407 | box2 = gtk_hbox_new (FALSE, 5); |
---|
6408 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
6409 | gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); |
---|
6410 | gtk_widget_show (box2); |
---|
6411 | |
---|
6412 | frame = gtk_frame_new ("Drag"); |
---|
6413 | gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0); |
---|
6414 | gtk_widget_show (frame); |
---|
6415 | |
---|
6416 | box3 = gtk_vbox_new (FALSE, 5); |
---|
6417 | gtk_container_set_border_width (GTK_CONTAINER (box3), 5); |
---|
6418 | gtk_container_add (GTK_CONTAINER (frame), box3); |
---|
6419 | gtk_widget_show (box3); |
---|
6420 | |
---|
6421 | /* |
---|
6422 | * FROM Button |
---|
6423 | */ |
---|
6424 | button = gtk_button_new_with_label ("Drag me!"); |
---|
6425 | gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0); |
---|
6426 | gtk_widget_show (button); |
---|
6427 | |
---|
6428 | /* |
---|
6429 | * currently, the widget has to be realized to |
---|
6430 | * set dnd on it, this needs to change |
---|
6431 | */ |
---|
6432 | gtk_widget_realize (button); |
---|
6433 | gtk_signal_connect (GTK_OBJECT (button), |
---|
6434 | "drag_request_event", |
---|
6435 | GTK_SIGNAL_FUNC(dnd_drag_request), |
---|
6436 | button); |
---|
6437 | |
---|
6438 | gtk_widget_dnd_drag_set (button, TRUE, possible_drag_types, 1); |
---|
6439 | |
---|
6440 | |
---|
6441 | frame = gtk_frame_new ("Drop"); |
---|
6442 | gtk_box_pack_start (GTK_BOX (box2), frame, TRUE, TRUE, 0); |
---|
6443 | gtk_widget_show (frame); |
---|
6444 | |
---|
6445 | box3 = gtk_vbox_new (FALSE, 5); |
---|
6446 | gtk_container_set_border_width (GTK_CONTAINER (box3), 5); |
---|
6447 | gtk_container_add (GTK_CONTAINER (frame), box3); |
---|
6448 | gtk_widget_show (box3); |
---|
6449 | |
---|
6450 | |
---|
6451 | /* |
---|
6452 | * TO Button |
---|
6453 | */ |
---|
6454 | button = gtk_button_new_with_label ("To"); |
---|
6455 | gtk_box_pack_start (GTK_BOX (box3), button, FALSE, TRUE, 0); |
---|
6456 | gtk_widget_show (button); |
---|
6457 | |
---|
6458 | gtk_widget_realize (button); |
---|
6459 | gtk_signal_connect (GTK_OBJECT (button), |
---|
6460 | "drop_data_available_event", |
---|
6461 | GTK_SIGNAL_FUNC(dnd_drop), |
---|
6462 | button); |
---|
6463 | |
---|
6464 | gtk_widget_dnd_drop_set (button, TRUE, accepted_drop_types, 1, FALSE); |
---|
6465 | |
---|
6466 | |
---|
6467 | separator = gtk_hseparator_new (); |
---|
6468 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
6469 | gtk_widget_show (separator); |
---|
6470 | |
---|
6471 | |
---|
6472 | box2 = gtk_vbox_new (FALSE, 10); |
---|
6473 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
6474 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
6475 | gtk_widget_show (box2); |
---|
6476 | |
---|
6477 | |
---|
6478 | button = gtk_button_new_with_label ("close"); |
---|
6479 | |
---|
6480 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
6481 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
6482 | GTK_OBJECT (window)); |
---|
6483 | |
---|
6484 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
6485 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
6486 | gtk_widget_grab_default (button); |
---|
6487 | gtk_widget_show (button); |
---|
6488 | } |
---|
6489 | |
---|
6490 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
6491 | gtk_widget_show (window); |
---|
6492 | else |
---|
6493 | gtk_widget_destroy (window); |
---|
6494 | } |
---|
6495 | #endif |
---|
6496 | |
---|
6497 | /* |
---|
6498 | * Shaped Windows |
---|
6499 | */ |
---|
6500 | |
---|
6501 | static GdkWindow *root_win = NULL; |
---|
6502 | |
---|
6503 | typedef struct _cursoroffset {gint x,y;} CursorOffset; |
---|
6504 | |
---|
6505 | static void |
---|
6506 | shape_pressed (GtkWidget *widget, GdkEventButton *event) |
---|
6507 | { |
---|
6508 | CursorOffset *p; |
---|
6509 | |
---|
6510 | /* ignore double and triple click */ |
---|
6511 | if (event->type != GDK_BUTTON_PRESS) |
---|
6512 | return; |
---|
6513 | |
---|
6514 | p = gtk_object_get_user_data (GTK_OBJECT(widget)); |
---|
6515 | p->x = (int) event->x; |
---|
6516 | p->y = (int) event->y; |
---|
6517 | |
---|
6518 | gtk_grab_add (widget); |
---|
6519 | gdk_pointer_grab (widget->window, TRUE, |
---|
6520 | GDK_BUTTON_RELEASE_MASK | |
---|
6521 | GDK_BUTTON_MOTION_MASK | |
---|
6522 | GDK_POINTER_MOTION_HINT_MASK, |
---|
6523 | NULL, NULL, 0); |
---|
6524 | } |
---|
6525 | |
---|
6526 | static void |
---|
6527 | shape_released (GtkWidget *widget) |
---|
6528 | { |
---|
6529 | gtk_grab_remove (widget); |
---|
6530 | gdk_pointer_ungrab (0); |
---|
6531 | } |
---|
6532 | |
---|
6533 | static void |
---|
6534 | shape_motion (GtkWidget *widget, |
---|
6535 | GdkEventMotion *event) |
---|
6536 | { |
---|
6537 | gint xp, yp; |
---|
6538 | CursorOffset * p; |
---|
6539 | GdkModifierType mask; |
---|
6540 | |
---|
6541 | p = gtk_object_get_user_data (GTK_OBJECT (widget)); |
---|
6542 | |
---|
6543 | /* |
---|
6544 | * Can't use event->x / event->y here |
---|
6545 | * because I need absolute coordinates. |
---|
6546 | */ |
---|
6547 | gdk_window_get_pointer (root_win, &xp, &yp, &mask); |
---|
6548 | gtk_widget_set_uposition (widget, xp - p->x, yp - p->y); |
---|
6549 | } |
---|
6550 | |
---|
6551 | GtkWidget * |
---|
6552 | shape_create_icon (char *xpm_file, |
---|
6553 | gint x, |
---|
6554 | gint y, |
---|
6555 | gint px, |
---|
6556 | gint py, |
---|
6557 | gint window_type) |
---|
6558 | { |
---|
6559 | GtkWidget *window; |
---|
6560 | GtkWidget *pixmap; |
---|
6561 | GtkWidget *fixed; |
---|
6562 | CursorOffset* icon_pos; |
---|
6563 | GdkGC* gc; |
---|
6564 | GdkBitmap *gdk_pixmap_mask; |
---|
6565 | GdkPixmap *gdk_pixmap; |
---|
6566 | GtkStyle *style; |
---|
6567 | |
---|
6568 | style = gtk_widget_get_default_style (); |
---|
6569 | gc = style->black_gc; |
---|
6570 | |
---|
6571 | /* |
---|
6572 | * GDK_WINDOW_TOPLEVEL works also, giving you a title border |
---|
6573 | */ |
---|
6574 | window = gtk_window_new (window_type); |
---|
6575 | |
---|
6576 | fixed = gtk_fixed_new (); |
---|
6577 | gtk_widget_set_usize (fixed, 100,100); |
---|
6578 | gtk_container_add (GTK_CONTAINER (window), fixed); |
---|
6579 | gtk_widget_show (fixed); |
---|
6580 | |
---|
6581 | gtk_widget_set_events (window, |
---|
6582 | gtk_widget_get_events (window) | |
---|
6583 | GDK_BUTTON_MOTION_MASK | |
---|
6584 | GDK_POINTER_MOTION_HINT_MASK | |
---|
6585 | GDK_BUTTON_PRESS_MASK); |
---|
6586 | |
---|
6587 | gtk_widget_realize (window); |
---|
6588 | gdk_pixmap = gdk_pixmap_create_from_xpm (window->window, &gdk_pixmap_mask, |
---|
6589 | &style->bg[GTK_STATE_NORMAL], |
---|
6590 | xpm_file); |
---|
6591 | |
---|
6592 | pixmap = gtk_pixmap_new (gdk_pixmap, gdk_pixmap_mask); |
---|
6593 | gtk_fixed_put (GTK_FIXED (fixed), pixmap, px,py); |
---|
6594 | gtk_widget_show (pixmap); |
---|
6595 | |
---|
6596 | gtk_widget_shape_combine_mask (window, gdk_pixmap_mask, px,py); |
---|
6597 | |
---|
6598 | |
---|
6599 | gtk_signal_connect (GTK_OBJECT (window), "button_press_event", |
---|
6600 | GTK_SIGNAL_FUNC (shape_pressed),NULL); |
---|
6601 | gtk_signal_connect (GTK_OBJECT (window), "button_release_event", |
---|
6602 | GTK_SIGNAL_FUNC (shape_released),NULL); |
---|
6603 | gtk_signal_connect (GTK_OBJECT (window), "motion_notify_event", |
---|
6604 | GTK_SIGNAL_FUNC (shape_motion),NULL); |
---|
6605 | |
---|
6606 | icon_pos = g_new (CursorOffset, 1); |
---|
6607 | gtk_object_set_user_data(GTK_OBJECT(window), icon_pos); |
---|
6608 | |
---|
6609 | gtk_widget_set_uposition (window, x, y); |
---|
6610 | gtk_widget_show (window); |
---|
6611 | |
---|
6612 | return window; |
---|
6613 | } |
---|
6614 | |
---|
6615 | void |
---|
6616 | create_shapes (void) |
---|
6617 | { |
---|
6618 | /* Variables used by the Drag/Drop and Shape Window demos */ |
---|
6619 | static GtkWidget *modeller = NULL; |
---|
6620 | static GtkWidget *sheets = NULL; |
---|
6621 | static GtkWidget *rings = NULL; |
---|
6622 | |
---|
6623 | root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ()); |
---|
6624 | |
---|
6625 | if (!modeller) |
---|
6626 | { |
---|
6627 | modeller = shape_create_icon ("Modeller.xpm", |
---|
6628 | 440, 140, 0,0, GTK_WINDOW_POPUP); |
---|
6629 | |
---|
6630 | gtk_signal_connect (GTK_OBJECT (modeller), "destroy", |
---|
6631 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6632 | &modeller); |
---|
6633 | } |
---|
6634 | else |
---|
6635 | gtk_widget_destroy (modeller); |
---|
6636 | |
---|
6637 | if (!sheets) |
---|
6638 | { |
---|
6639 | sheets = shape_create_icon ("FilesQueue.xpm", |
---|
6640 | 580, 170, 0,0, GTK_WINDOW_POPUP); |
---|
6641 | |
---|
6642 | gtk_signal_connect (GTK_OBJECT (sheets), "destroy", |
---|
6643 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6644 | &sheets); |
---|
6645 | |
---|
6646 | } |
---|
6647 | else |
---|
6648 | gtk_widget_destroy (sheets); |
---|
6649 | |
---|
6650 | if (!rings) |
---|
6651 | { |
---|
6652 | rings = shape_create_icon ("3DRings.xpm", |
---|
6653 | 460, 270, 25,25, GTK_WINDOW_TOPLEVEL); |
---|
6654 | |
---|
6655 | gtk_signal_connect (GTK_OBJECT (rings), "destroy", |
---|
6656 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6657 | &rings); |
---|
6658 | } |
---|
6659 | else |
---|
6660 | gtk_widget_destroy (rings); |
---|
6661 | } |
---|
6662 | |
---|
6663 | /* |
---|
6664 | * WM Hints demo |
---|
6665 | */ |
---|
6666 | |
---|
6667 | void |
---|
6668 | create_wmhints (void) |
---|
6669 | { |
---|
6670 | static GtkWidget *window = NULL; |
---|
6671 | GtkWidget *label; |
---|
6672 | GtkWidget *separator; |
---|
6673 | GtkWidget *button; |
---|
6674 | GtkWidget *box1; |
---|
6675 | GtkWidget *box2; |
---|
6676 | |
---|
6677 | GdkBitmap *circles; |
---|
6678 | |
---|
6679 | if (!window) |
---|
6680 | { |
---|
6681 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
6682 | |
---|
6683 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
6684 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
6685 | &window); |
---|
6686 | |
---|
6687 | gtk_window_set_title (GTK_WINDOW (window), "WM Hints"); |
---|
6688 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
6689 | |
---|
6690 | gtk_widget_realize (window); |
---|
6691 | |
---|
6692 | circles = gdk_bitmap_create_from_data (window->window, |
---|
6693 | circles_bits, |
---|
6694 | circles_width, |
---|
6695 | circles_height); |
---|
6696 | gdk_window_set_icon (window->window, NULL, |
---|
6697 | circles, circles); |
---|
6698 | |
---|
6699 | gdk_window_set_icon_name (window->window, "WMHints Test Icon"); |
---|
6700 | |
---|
6701 | gdk_window_set_decorations (window->window, GDK_DECOR_ALL | GDK_DECOR_MENU); |
---|
6702 | gdk_window_set_functions (window->window, GDK_FUNC_ALL | GDK_FUNC_RESIZE); |
---|
6703 | |
---|
6704 | box1 = gtk_vbox_new (FALSE, 0); |
---|
6705 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
6706 | gtk_widget_show (box1); |
---|
6707 | |
---|
6708 | label = gtk_label_new ("Try iconizing me!"); |
---|
6709 | gtk_widget_set_usize (label, 150, 50); |
---|
6710 | gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0); |
---|
6711 | gtk_widget_show (label); |
---|
6712 | |
---|
6713 | |
---|
6714 | separator = gtk_hseparator_new (); |
---|
6715 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
6716 | gtk_widget_show (separator); |
---|
6717 | |
---|
6718 | |
---|
6719 | box2 = gtk_vbox_new (FALSE, 10); |
---|
6720 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
6721 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
6722 | gtk_widget_show (box2); |
---|
6723 | |
---|
6724 | |
---|
6725 | button = gtk_button_new_with_label ("close"); |
---|
6726 | |
---|
6727 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
6728 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
6729 | GTK_OBJECT (window)); |
---|
6730 | |
---|
6731 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
6732 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
6733 | gtk_widget_grab_default (button); |
---|
6734 | gtk_widget_show (button); |
---|
6735 | } |
---|
6736 | |
---|
6737 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
6738 | gtk_widget_show (window); |
---|
6739 | else |
---|
6740 | gtk_widget_destroy (window); |
---|
6741 | } |
---|
6742 | |
---|
6743 | /* |
---|
6744 | * GtkProgressBar |
---|
6745 | */ |
---|
6746 | |
---|
6747 | typedef struct _ProgressData { |
---|
6748 | GtkWidget *window; |
---|
6749 | GtkWidget *pbar; |
---|
6750 | GtkWidget *block_spin; |
---|
6751 | GtkWidget *x_align_spin; |
---|
6752 | GtkWidget *y_align_spin; |
---|
6753 | GtkWidget *step_spin; |
---|
6754 | GtkWidget *act_blocks_spin; |
---|
6755 | GtkWidget *label; |
---|
6756 | GtkWidget *omenu1; |
---|
6757 | GtkWidget *omenu2; |
---|
6758 | GtkWidget *entry; |
---|
6759 | int timer; |
---|
6760 | } ProgressData; |
---|
6761 | |
---|
6762 | gint |
---|
6763 | progress_timeout (gpointer data) |
---|
6764 | { |
---|
6765 | gfloat new_val; |
---|
6766 | GtkAdjustment *adj; |
---|
6767 | |
---|
6768 | adj = GTK_PROGRESS (data)->adjustment; |
---|
6769 | |
---|
6770 | new_val = adj->value + 1; |
---|
6771 | if (new_val > adj->upper) |
---|
6772 | new_val = adj->lower; |
---|
6773 | |
---|
6774 | gtk_progress_set_value (GTK_PROGRESS (data), new_val); |
---|
6775 | |
---|
6776 | return TRUE; |
---|
6777 | } |
---|
6778 | |
---|
6779 | static void |
---|
6780 | destroy_progress (GtkWidget *widget, |
---|
6781 | ProgressData **pdata) |
---|
6782 | { |
---|
6783 | gtk_timeout_remove ((*pdata)->timer); |
---|
6784 | (*pdata)->timer = 0; |
---|
6785 | (*pdata)->window = NULL; |
---|
6786 | g_free (*pdata); |
---|
6787 | *pdata = NULL; |
---|
6788 | } |
---|
6789 | |
---|
6790 | static void |
---|
6791 | progressbar_toggle_orientation (GtkWidget *widget, ProgressData *pdata) |
---|
6792 | { |
---|
6793 | gint i; |
---|
6794 | |
---|
6795 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
6796 | return; |
---|
6797 | |
---|
6798 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
6799 | (((GtkOptionMenu *)(pdata->omenu1))->menu_item), i); |
---|
6800 | |
---|
6801 | gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (pdata->pbar), |
---|
6802 | (GtkProgressBarOrientation) (3-i)); |
---|
6803 | } |
---|
6804 | |
---|
6805 | static void |
---|
6806 | toggle_show_text (GtkWidget *widget, ProgressData *pdata) |
---|
6807 | { |
---|
6808 | gtk_progress_set_show_text (GTK_PROGRESS (pdata->pbar), |
---|
6809 | GTK_TOGGLE_BUTTON (widget)->active); |
---|
6810 | gtk_widget_set_sensitive (pdata->entry, GTK_TOGGLE_BUTTON (widget)->active); |
---|
6811 | gtk_widget_set_sensitive (pdata->x_align_spin, |
---|
6812 | GTK_TOGGLE_BUTTON (widget)->active); |
---|
6813 | gtk_widget_set_sensitive (pdata->y_align_spin, |
---|
6814 | GTK_TOGGLE_BUTTON (widget)->active); |
---|
6815 | } |
---|
6816 | |
---|
6817 | static void |
---|
6818 | progressbar_toggle_bar_style (GtkWidget *widget, ProgressData *pdata) |
---|
6819 | { |
---|
6820 | gint i; |
---|
6821 | |
---|
6822 | if (!GTK_WIDGET_MAPPED (widget)) |
---|
6823 | return; |
---|
6824 | |
---|
6825 | RADIOMENUTOGGLED ((GtkRadioMenuItem *) |
---|
6826 | (((GtkOptionMenu *)(pdata->omenu2))->menu_item), i); |
---|
6827 | |
---|
6828 | i = 1 - i; |
---|
6829 | |
---|
6830 | if (i == 1) |
---|
6831 | gtk_widget_set_sensitive (pdata->block_spin, TRUE); |
---|
6832 | else |
---|
6833 | gtk_widget_set_sensitive (pdata->block_spin, FALSE); |
---|
6834 | |
---|
6835 | gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar), |
---|
6836 | (GtkProgressBarStyle) i); |
---|
6837 | } |
---|
6838 | |
---|
6839 | static void |
---|
6840 | progress_value_changed (GtkAdjustment *adj, ProgressData *pdata) |
---|
6841 | { |
---|
6842 | char buf[20]; |
---|
6843 | |
---|
6844 | if (GTK_PROGRESS (pdata->pbar)->activity_mode) |
---|
6845 | sprintf (buf, "???"); |
---|
6846 | else |
---|
6847 | sprintf (buf, "%.0f%%", 100 * |
---|
6848 | gtk_progress_get_current_percentage (GTK_PROGRESS (pdata->pbar))); |
---|
6849 | gtk_label_set_text (GTK_LABEL (pdata->label), buf); |
---|
6850 | } |
---|
6851 | |
---|
6852 | static void |
---|
6853 | adjust_blocks (GtkAdjustment *adj, ProgressData *pdata) |
---|
6854 | { |
---|
6855 | gtk_progress_set_percentage (GTK_PROGRESS (pdata->pbar), 0); |
---|
6856 | gtk_progress_bar_set_discrete_blocks (GTK_PROGRESS_BAR (pdata->pbar), |
---|
6857 | gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (pdata->block_spin))); |
---|
6858 | } |
---|
6859 | |
---|
6860 | static void |
---|
6861 | adjust_step (GtkAdjustment *adj, ProgressData *pdata) |
---|
6862 | { |
---|
6863 | gtk_progress_bar_set_activity_step (GTK_PROGRESS_BAR (pdata->pbar), |
---|
6864 | gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (pdata->step_spin))); |
---|
6865 | } |
---|
6866 | |
---|
6867 | static void |
---|
6868 | adjust_act_blocks (GtkAdjustment *adj, ProgressData *pdata) |
---|
6869 | { |
---|
6870 | gtk_progress_bar_set_activity_blocks (GTK_PROGRESS_BAR (pdata->pbar), |
---|
6871 | gtk_spin_button_get_value_as_int |
---|
6872 | (GTK_SPIN_BUTTON (pdata->act_blocks_spin))); |
---|
6873 | } |
---|
6874 | |
---|
6875 | static void |
---|
6876 | adjust_align (GtkAdjustment *adj, ProgressData *pdata) |
---|
6877 | { |
---|
6878 | gtk_progress_set_text_alignment (GTK_PROGRESS (pdata->pbar), |
---|
6879 | gtk_spin_button_get_value_as_float |
---|
6880 | (GTK_SPIN_BUTTON (pdata->x_align_spin)), |
---|
6881 | gtk_spin_button_get_value_as_float |
---|
6882 | (GTK_SPIN_BUTTON (pdata->y_align_spin))); |
---|
6883 | } |
---|
6884 | |
---|
6885 | static void |
---|
6886 | toggle_activity_mode (GtkWidget *widget, ProgressData *pdata) |
---|
6887 | { |
---|
6888 | gtk_progress_set_activity_mode (GTK_PROGRESS (pdata->pbar), |
---|
6889 | GTK_TOGGLE_BUTTON (widget)->active); |
---|
6890 | gtk_widget_set_sensitive (pdata->step_spin, |
---|
6891 | GTK_TOGGLE_BUTTON (widget)->active); |
---|
6892 | gtk_widget_set_sensitive (pdata->act_blocks_spin, |
---|
6893 | GTK_TOGGLE_BUTTON (widget)->active); |
---|
6894 | } |
---|
6895 | |
---|
6896 | static void |
---|
6897 | entry_changed (GtkWidget *widget, ProgressData *pdata) |
---|
6898 | { |
---|
6899 | gtk_progress_set_format_string (GTK_PROGRESS (pdata->pbar), |
---|
6900 | gtk_entry_get_text (GTK_ENTRY (pdata->entry))); |
---|
6901 | } |
---|
6902 | |
---|
6903 | void |
---|
6904 | create_progress_bar (void) |
---|
6905 | { |
---|
6906 | GtkWidget *button; |
---|
6907 | GtkWidget *vbox; |
---|
6908 | GtkWidget *vbox2; |
---|
6909 | GtkWidget *hbox; |
---|
6910 | GtkWidget *check; |
---|
6911 | GtkWidget *frame; |
---|
6912 | GtkWidget *tab; |
---|
6913 | GtkWidget *label; |
---|
6914 | GtkWidget *align; |
---|
6915 | GtkAdjustment *adj; |
---|
6916 | static ProgressData *pdata = NULL; |
---|
6917 | |
---|
6918 | static OptionMenuItem items1[] = |
---|
6919 | { |
---|
6920 | { "Left-Right", progressbar_toggle_orientation }, |
---|
6921 | { "Right-Left", progressbar_toggle_orientation }, |
---|
6922 | { "Bottom-Top", progressbar_toggle_orientation }, |
---|
6923 | { "Top-Bottom", progressbar_toggle_orientation } |
---|
6924 | }; |
---|
6925 | |
---|
6926 | static OptionMenuItem items2[] = |
---|
6927 | { |
---|
6928 | { "Continuous", progressbar_toggle_bar_style }, |
---|
6929 | { "Discrete", progressbar_toggle_bar_style } |
---|
6930 | }; |
---|
6931 | |
---|
6932 | if (!pdata) |
---|
6933 | pdata = g_new0 (ProgressData, 1); |
---|
6934 | |
---|
6935 | if (!pdata->window) |
---|
6936 | { |
---|
6937 | pdata->window = gtk_dialog_new (); |
---|
6938 | |
---|
6939 | gtk_window_set_policy (GTK_WINDOW (pdata->window), FALSE, FALSE, TRUE); |
---|
6940 | |
---|
6941 | gtk_signal_connect (GTK_OBJECT (pdata->window), "destroy", |
---|
6942 | GTK_SIGNAL_FUNC (destroy_progress), |
---|
6943 | &pdata); |
---|
6944 | |
---|
6945 | pdata->timer = 0; |
---|
6946 | |
---|
6947 | gtk_window_set_title (GTK_WINDOW (pdata->window), "GtkProgressBar"); |
---|
6948 | gtk_container_set_border_width (GTK_CONTAINER (pdata->window), 0); |
---|
6949 | |
---|
6950 | vbox = gtk_vbox_new (FALSE, 5); |
---|
6951 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); |
---|
6952 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (pdata->window)->vbox), |
---|
6953 | vbox, FALSE, TRUE, 0); |
---|
6954 | |
---|
6955 | frame = gtk_frame_new ("Progress"); |
---|
6956 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); |
---|
6957 | |
---|
6958 | vbox2 = gtk_vbox_new (FALSE, 5); |
---|
6959 | gtk_container_add (GTK_CONTAINER (frame), vbox2); |
---|
6960 | |
---|
6961 | align = gtk_alignment_new (0.5, 0.5, 0, 0); |
---|
6962 | gtk_box_pack_start (GTK_BOX (vbox2), align, FALSE, FALSE, 5); |
---|
6963 | |
---|
6964 | adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 300, 0, 0, 0); |
---|
6965 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
6966 | GTK_SIGNAL_FUNC (progress_value_changed), pdata); |
---|
6967 | |
---|
6968 | pdata->pbar = gtk_progress_bar_new_with_adjustment (adj); |
---|
6969 | gtk_progress_set_format_string (GTK_PROGRESS (pdata->pbar), |
---|
6970 | "%v from [%l,%u] (=%p%%)"); |
---|
6971 | gtk_container_add (GTK_CONTAINER (align), pdata->pbar); |
---|
6972 | pdata->timer = gtk_timeout_add (100, progress_timeout, pdata->pbar); |
---|
6973 | |
---|
6974 | align = gtk_alignment_new (0.5, 0.5, 0, 0); |
---|
6975 | gtk_box_pack_start (GTK_BOX (vbox2), align, FALSE, FALSE, 5); |
---|
6976 | |
---|
6977 | hbox = gtk_hbox_new (FALSE, 5); |
---|
6978 | gtk_container_add (GTK_CONTAINER (align), hbox); |
---|
6979 | label = gtk_label_new ("Label updated by user :"); |
---|
6980 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
6981 | pdata->label = gtk_label_new (""); |
---|
6982 | gtk_box_pack_start (GTK_BOX (hbox), pdata->label, FALSE, TRUE, 0); |
---|
6983 | |
---|
6984 | frame = gtk_frame_new ("Options"); |
---|
6985 | gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); |
---|
6986 | |
---|
6987 | vbox2 = gtk_vbox_new (FALSE, 5); |
---|
6988 | gtk_container_add (GTK_CONTAINER (frame), vbox2); |
---|
6989 | |
---|
6990 | tab = gtk_table_new (7, 2, FALSE); |
---|
6991 | gtk_box_pack_start (GTK_BOX (vbox2), tab, FALSE, TRUE, 0); |
---|
6992 | |
---|
6993 | label = gtk_label_new ("Orientation :"); |
---|
6994 | gtk_table_attach (GTK_TABLE (tab), label, 0, 1, 0, 1, |
---|
6995 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
6996 | 5, 5); |
---|
6997 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
6998 | |
---|
6999 | pdata->omenu1 = build_option_menu (items1, 4, 0, pdata); |
---|
7000 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7001 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 0, 1, |
---|
7002 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7003 | 5, 5); |
---|
7004 | gtk_box_pack_start (GTK_BOX (hbox), pdata->omenu1, TRUE, TRUE, 0); |
---|
7005 | |
---|
7006 | check = gtk_check_button_new_with_label ("Show text"); |
---|
7007 | gtk_signal_connect (GTK_OBJECT (check), "clicked", |
---|
7008 | GTK_SIGNAL_FUNC (toggle_show_text), |
---|
7009 | pdata); |
---|
7010 | gtk_table_attach (GTK_TABLE (tab), check, 0, 1, 1, 2, |
---|
7011 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7012 | 5, 5); |
---|
7013 | |
---|
7014 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7015 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 1, 2, |
---|
7016 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7017 | 5, 5); |
---|
7018 | |
---|
7019 | label = gtk_label_new ("Format : "); |
---|
7020 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
7021 | |
---|
7022 | pdata->entry = gtk_entry_new (); |
---|
7023 | gtk_signal_connect (GTK_OBJECT (pdata->entry), "changed", |
---|
7024 | GTK_SIGNAL_FUNC (entry_changed), |
---|
7025 | pdata); |
---|
7026 | gtk_box_pack_start (GTK_BOX (hbox), pdata->entry, TRUE, TRUE, 0); |
---|
7027 | gtk_entry_set_text (GTK_ENTRY (pdata->entry), "%v from [%l,%u] (=%p%%)"); |
---|
7028 | gtk_widget_set_usize (pdata->entry, 100, -1); |
---|
7029 | gtk_widget_set_sensitive (pdata->entry, FALSE); |
---|
7030 | |
---|
7031 | label = gtk_label_new ("Text align :"); |
---|
7032 | gtk_table_attach (GTK_TABLE (tab), label, 0, 1, 2, 3, |
---|
7033 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7034 | 5, 5); |
---|
7035 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
7036 | |
---|
7037 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7038 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 2, 3, |
---|
7039 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7040 | 5, 5); |
---|
7041 | |
---|
7042 | label = gtk_label_new ("x :"); |
---|
7043 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 5); |
---|
7044 | |
---|
7045 | adj = (GtkAdjustment *) gtk_adjustment_new (0.5, 0, 1, 0.1, 0.1, 0); |
---|
7046 | pdata->x_align_spin = gtk_spin_button_new (adj, 0, 1); |
---|
7047 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
7048 | GTK_SIGNAL_FUNC (adjust_align), pdata); |
---|
7049 | gtk_box_pack_start (GTK_BOX (hbox), pdata->x_align_spin, FALSE, TRUE, 0); |
---|
7050 | gtk_widget_set_sensitive (pdata->x_align_spin, FALSE); |
---|
7051 | |
---|
7052 | label = gtk_label_new ("y :"); |
---|
7053 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 5); |
---|
7054 | |
---|
7055 | adj = (GtkAdjustment *) gtk_adjustment_new (0.5, 0, 1, 0.1, 0.1, 0); |
---|
7056 | pdata->y_align_spin = gtk_spin_button_new (adj, 0, 1); |
---|
7057 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
7058 | GTK_SIGNAL_FUNC (adjust_align), pdata); |
---|
7059 | gtk_box_pack_start (GTK_BOX (hbox), pdata->y_align_spin, FALSE, TRUE, 0); |
---|
7060 | gtk_widget_set_sensitive (pdata->y_align_spin, FALSE); |
---|
7061 | |
---|
7062 | label = gtk_label_new ("Bar Style :"); |
---|
7063 | gtk_table_attach (GTK_TABLE (tab), label, 0, 1, 3, 4, |
---|
7064 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7065 | 5, 5); |
---|
7066 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
7067 | |
---|
7068 | pdata->omenu2 = build_option_menu (items2, 2, 0, pdata); |
---|
7069 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7070 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 3, 4, |
---|
7071 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7072 | 5, 5); |
---|
7073 | gtk_box_pack_start (GTK_BOX (hbox), pdata->omenu2, TRUE, TRUE, 0); |
---|
7074 | |
---|
7075 | label = gtk_label_new ("Block count :"); |
---|
7076 | gtk_table_attach (GTK_TABLE (tab), label, 0, 1, 4, 5, |
---|
7077 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7078 | 5, 5); |
---|
7079 | gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); |
---|
7080 | |
---|
7081 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7082 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 4, 5, |
---|
7083 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7084 | 5, 5); |
---|
7085 | adj = (GtkAdjustment *) gtk_adjustment_new (10, 2, 20, 1, 5, 0); |
---|
7086 | pdata->block_spin = gtk_spin_button_new (adj, 0, 0); |
---|
7087 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
7088 | GTK_SIGNAL_FUNC (adjust_blocks), pdata); |
---|
7089 | gtk_box_pack_start (GTK_BOX (hbox), pdata->block_spin, FALSE, TRUE, 0); |
---|
7090 | gtk_widget_set_sensitive (pdata->block_spin, FALSE); |
---|
7091 | |
---|
7092 | check = gtk_check_button_new_with_label ("Activity mode"); |
---|
7093 | gtk_signal_connect (GTK_OBJECT (check), "clicked", |
---|
7094 | GTK_SIGNAL_FUNC (toggle_activity_mode), |
---|
7095 | pdata); |
---|
7096 | gtk_table_attach (GTK_TABLE (tab), check, 0, 1, 5, 6, |
---|
7097 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7098 | 5, 5); |
---|
7099 | |
---|
7100 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7101 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 5, 6, |
---|
7102 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7103 | 5, 5); |
---|
7104 | label = gtk_label_new ("Step size : "); |
---|
7105 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
7106 | adj = (GtkAdjustment *) gtk_adjustment_new (3, 1, 20, 1, 5, 0); |
---|
7107 | pdata->step_spin = gtk_spin_button_new (adj, 0, 0); |
---|
7108 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
7109 | GTK_SIGNAL_FUNC (adjust_step), pdata); |
---|
7110 | gtk_box_pack_start (GTK_BOX (hbox), pdata->step_spin, FALSE, TRUE, 0); |
---|
7111 | gtk_widget_set_sensitive (pdata->step_spin, FALSE); |
---|
7112 | |
---|
7113 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7114 | gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 6, 7, |
---|
7115 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
7116 | 5, 5); |
---|
7117 | label = gtk_label_new ("Blocks : "); |
---|
7118 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); |
---|
7119 | adj = (GtkAdjustment *) gtk_adjustment_new (5, 2, 10, 1, 5, 0); |
---|
7120 | pdata->act_blocks_spin = gtk_spin_button_new (adj, 0, 0); |
---|
7121 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
7122 | GTK_SIGNAL_FUNC (adjust_act_blocks), pdata); |
---|
7123 | gtk_box_pack_start (GTK_BOX (hbox), pdata->act_blocks_spin, FALSE, TRUE, |
---|
7124 | 0); |
---|
7125 | gtk_widget_set_sensitive (pdata->act_blocks_spin, FALSE); |
---|
7126 | |
---|
7127 | button = gtk_button_new_with_label ("close"); |
---|
7128 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
7129 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
7130 | GTK_OBJECT (pdata->window)); |
---|
7131 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7132 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (pdata->window)->action_area), |
---|
7133 | button, TRUE, TRUE, 0); |
---|
7134 | gtk_widget_grab_default (button); |
---|
7135 | } |
---|
7136 | |
---|
7137 | if (!GTK_WIDGET_VISIBLE (pdata->window)) |
---|
7138 | gtk_widget_show_all (pdata->window); |
---|
7139 | else |
---|
7140 | gtk_widget_destroy (pdata->window); |
---|
7141 | } |
---|
7142 | |
---|
7143 | /* |
---|
7144 | * Color Preview |
---|
7145 | */ |
---|
7146 | |
---|
7147 | static int color_idle = 0; |
---|
7148 | |
---|
7149 | gint |
---|
7150 | color_idle_func (GtkWidget *preview) |
---|
7151 | { |
---|
7152 | static int count = 1; |
---|
7153 | guchar buf[768]; |
---|
7154 | int i, j, k; |
---|
7155 | |
---|
7156 | for (i = 0; i < 256; i++) |
---|
7157 | { |
---|
7158 | for (j = 0, k = 0; j < 256; j++) |
---|
7159 | { |
---|
7160 | buf[k+0] = i + count; |
---|
7161 | buf[k+1] = 0; |
---|
7162 | buf[k+2] = j + count; |
---|
7163 | k += 3; |
---|
7164 | } |
---|
7165 | |
---|
7166 | gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256); |
---|
7167 | } |
---|
7168 | |
---|
7169 | count += 1; |
---|
7170 | |
---|
7171 | gtk_widget_draw (preview, NULL); |
---|
7172 | |
---|
7173 | return TRUE; |
---|
7174 | } |
---|
7175 | |
---|
7176 | static void |
---|
7177 | color_preview_destroy (GtkWidget *widget, |
---|
7178 | GtkWidget **window) |
---|
7179 | { |
---|
7180 | gtk_idle_remove (color_idle); |
---|
7181 | color_idle = 0; |
---|
7182 | |
---|
7183 | *window = NULL; |
---|
7184 | } |
---|
7185 | |
---|
7186 | void |
---|
7187 | create_color_preview (void) |
---|
7188 | { |
---|
7189 | static GtkWidget *window = NULL; |
---|
7190 | GtkWidget *preview; |
---|
7191 | guchar buf[768]; |
---|
7192 | int i, j, k; |
---|
7193 | |
---|
7194 | if (!window) |
---|
7195 | { |
---|
7196 | gtk_widget_push_visual (gdk_rgb_get_visual ()); |
---|
7197 | gtk_widget_push_colormap (gdk_rgb_get_cmap ()); |
---|
7198 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
7199 | gtk_widget_pop_colormap (); |
---|
7200 | gtk_widget_pop_visual (); |
---|
7201 | |
---|
7202 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7203 | GTK_SIGNAL_FUNC(color_preview_destroy), |
---|
7204 | &window); |
---|
7205 | |
---|
7206 | gtk_window_set_title (GTK_WINDOW (window), "test"); |
---|
7207 | gtk_container_set_border_width (GTK_CONTAINER (window), 10); |
---|
7208 | |
---|
7209 | preview = gtk_preview_new (GTK_PREVIEW_COLOR); |
---|
7210 | gtk_preview_size (GTK_PREVIEW (preview), 256, 256); |
---|
7211 | gtk_container_add (GTK_CONTAINER (window), preview); |
---|
7212 | |
---|
7213 | for (i = 0; i < 256; i++) |
---|
7214 | { |
---|
7215 | for (j = 0, k = 0; j < 256; j++) |
---|
7216 | { |
---|
7217 | buf[k+0] = i; |
---|
7218 | buf[k+1] = 0; |
---|
7219 | buf[k+2] = j; |
---|
7220 | k += 3; |
---|
7221 | } |
---|
7222 | |
---|
7223 | gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256); |
---|
7224 | } |
---|
7225 | |
---|
7226 | color_idle = gtk_idle_add ((GtkFunction) color_idle_func, preview); |
---|
7227 | } |
---|
7228 | |
---|
7229 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7230 | gtk_widget_show_all (window); |
---|
7231 | else |
---|
7232 | gtk_widget_destroy (window); |
---|
7233 | } |
---|
7234 | |
---|
7235 | /* |
---|
7236 | * Gray Preview |
---|
7237 | */ |
---|
7238 | |
---|
7239 | static int gray_idle = 0; |
---|
7240 | |
---|
7241 | gint |
---|
7242 | gray_idle_func (GtkWidget *preview) |
---|
7243 | { |
---|
7244 | static int count = 1; |
---|
7245 | guchar buf[256]; |
---|
7246 | int i, j; |
---|
7247 | |
---|
7248 | for (i = 0; i < 256; i++) |
---|
7249 | { |
---|
7250 | for (j = 0; j < 256; j++) |
---|
7251 | buf[j] = i + j + count; |
---|
7252 | |
---|
7253 | gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256); |
---|
7254 | } |
---|
7255 | |
---|
7256 | count += 1; |
---|
7257 | |
---|
7258 | gtk_widget_draw (preview, NULL); |
---|
7259 | |
---|
7260 | return TRUE; |
---|
7261 | } |
---|
7262 | |
---|
7263 | static void |
---|
7264 | gray_preview_destroy (GtkWidget *widget, |
---|
7265 | GtkWidget **window) |
---|
7266 | { |
---|
7267 | gtk_idle_remove (gray_idle); |
---|
7268 | gray_idle = 0; |
---|
7269 | |
---|
7270 | *window = NULL; |
---|
7271 | } |
---|
7272 | |
---|
7273 | void |
---|
7274 | create_gray_preview (void) |
---|
7275 | { |
---|
7276 | static GtkWidget *window = NULL; |
---|
7277 | GtkWidget *preview; |
---|
7278 | guchar buf[256]; |
---|
7279 | int i, j; |
---|
7280 | |
---|
7281 | if (!window) |
---|
7282 | { |
---|
7283 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
7284 | |
---|
7285 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7286 | GTK_SIGNAL_FUNC(gray_preview_destroy), |
---|
7287 | &window); |
---|
7288 | |
---|
7289 | gtk_window_set_title (GTK_WINDOW (window), "test"); |
---|
7290 | gtk_container_set_border_width (GTK_CONTAINER (window), 10); |
---|
7291 | |
---|
7292 | preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE); |
---|
7293 | gtk_preview_size (GTK_PREVIEW (preview), 256, 256); |
---|
7294 | gtk_container_add (GTK_CONTAINER (window), preview); |
---|
7295 | |
---|
7296 | for (i = 0; i < 256; i++) |
---|
7297 | { |
---|
7298 | for (j = 0; j < 256; j++) |
---|
7299 | buf[j] = i + j; |
---|
7300 | |
---|
7301 | gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, 256); |
---|
7302 | } |
---|
7303 | |
---|
7304 | gray_idle = gtk_idle_add ((GtkFunction) gray_idle_func, preview); |
---|
7305 | } |
---|
7306 | |
---|
7307 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7308 | gtk_widget_show_all (window); |
---|
7309 | else |
---|
7310 | gtk_widget_destroy (window); |
---|
7311 | } |
---|
7312 | |
---|
7313 | |
---|
7314 | /* |
---|
7315 | * Selection Test |
---|
7316 | */ |
---|
7317 | |
---|
7318 | void |
---|
7319 | selection_test_received (GtkWidget *list, GtkSelectionData *data) |
---|
7320 | { |
---|
7321 | GdkAtom *atoms; |
---|
7322 | GtkWidget *list_item; |
---|
7323 | GList *item_list; |
---|
7324 | int i, l; |
---|
7325 | |
---|
7326 | if (data->length < 0) |
---|
7327 | { |
---|
7328 | g_print ("Selection retrieval failed\n"); |
---|
7329 | return; |
---|
7330 | } |
---|
7331 | if (data->type != GDK_SELECTION_TYPE_ATOM) |
---|
7332 | { |
---|
7333 | g_print ("Selection \"TARGETS\" was not returned as atoms!\n"); |
---|
7334 | return; |
---|
7335 | } |
---|
7336 | |
---|
7337 | /* Clear out any current list items */ |
---|
7338 | |
---|
7339 | gtk_list_clear_items (GTK_LIST(list), 0, -1); |
---|
7340 | |
---|
7341 | /* Add new items to list */ |
---|
7342 | |
---|
7343 | atoms = (GdkAtom *)data->data; |
---|
7344 | |
---|
7345 | item_list = NULL; |
---|
7346 | l = data->length / sizeof (GdkAtom); |
---|
7347 | for (i = 0; i < l; i++) |
---|
7348 | { |
---|
7349 | char *name; |
---|
7350 | name = gdk_atom_name (atoms[i]); |
---|
7351 | if (name != NULL) |
---|
7352 | { |
---|
7353 | list_item = gtk_list_item_new_with_label (name); |
---|
7354 | g_free (name); |
---|
7355 | } |
---|
7356 | else |
---|
7357 | list_item = gtk_list_item_new_with_label ("(bad atom)"); |
---|
7358 | |
---|
7359 | gtk_widget_show (list_item); |
---|
7360 | item_list = g_list_append (item_list, list_item); |
---|
7361 | } |
---|
7362 | |
---|
7363 | gtk_list_append_items (GTK_LIST (list), item_list); |
---|
7364 | |
---|
7365 | return; |
---|
7366 | } |
---|
7367 | |
---|
7368 | void |
---|
7369 | selection_test_get_targets (GtkWidget *widget, GtkWidget *list) |
---|
7370 | { |
---|
7371 | static GdkAtom targets_atom = GDK_NONE; |
---|
7372 | |
---|
7373 | if (targets_atom == GDK_NONE) |
---|
7374 | targets_atom = gdk_atom_intern ("TARGETS", FALSE); |
---|
7375 | |
---|
7376 | gtk_selection_convert (list, GDK_SELECTION_PRIMARY, targets_atom, |
---|
7377 | GDK_CURRENT_TIME); |
---|
7378 | } |
---|
7379 | |
---|
7380 | void |
---|
7381 | create_selection_test (void) |
---|
7382 | { |
---|
7383 | static GtkWidget *window = NULL; |
---|
7384 | GtkWidget *button; |
---|
7385 | GtkWidget *vbox; |
---|
7386 | GtkWidget *scrolled_win; |
---|
7387 | GtkWidget *list; |
---|
7388 | GtkWidget *label; |
---|
7389 | |
---|
7390 | if (!window) |
---|
7391 | { |
---|
7392 | window = gtk_dialog_new (); |
---|
7393 | |
---|
7394 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7395 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
7396 | &window); |
---|
7397 | |
---|
7398 | gtk_window_set_title (GTK_WINDOW (window), "Selection Test"); |
---|
7399 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
7400 | |
---|
7401 | /* Create the list */ |
---|
7402 | |
---|
7403 | vbox = gtk_vbox_new (FALSE, 5); |
---|
7404 | gtk_container_set_border_width (GTK_CONTAINER (vbox), 10); |
---|
7405 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, |
---|
7406 | TRUE, TRUE, 0); |
---|
7407 | |
---|
7408 | label = gtk_label_new ("Gets available targets for current selection"); |
---|
7409 | gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); |
---|
7410 | |
---|
7411 | scrolled_win = gtk_scrolled_window_new (NULL, NULL); |
---|
7412 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), |
---|
7413 | GTK_POLICY_AUTOMATIC, |
---|
7414 | GTK_POLICY_AUTOMATIC); |
---|
7415 | gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0); |
---|
7416 | gtk_widget_set_usize (scrolled_win, 100, 200); |
---|
7417 | |
---|
7418 | list = gtk_list_new (); |
---|
7419 | gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), list); |
---|
7420 | |
---|
7421 | gtk_signal_connect (GTK_OBJECT(list), "selection_received", |
---|
7422 | GTK_SIGNAL_FUNC (selection_test_received), NULL); |
---|
7423 | |
---|
7424 | /* .. And create some buttons */ |
---|
7425 | button = gtk_button_new_with_label ("Get Targets"); |
---|
7426 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7427 | button, TRUE, TRUE, 0); |
---|
7428 | |
---|
7429 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
7430 | GTK_SIGNAL_FUNC (selection_test_get_targets), list); |
---|
7431 | |
---|
7432 | button = gtk_button_new_with_label ("Quit"); |
---|
7433 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7434 | button, TRUE, TRUE, 0); |
---|
7435 | |
---|
7436 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
7437 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
7438 | GTK_OBJECT (window)); |
---|
7439 | } |
---|
7440 | |
---|
7441 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7442 | gtk_widget_show_all (window); |
---|
7443 | else |
---|
7444 | gtk_widget_destroy (window); |
---|
7445 | } |
---|
7446 | |
---|
7447 | /* |
---|
7448 | * Gamma Curve |
---|
7449 | */ |
---|
7450 | |
---|
7451 | void |
---|
7452 | create_gamma_curve (void) |
---|
7453 | { |
---|
7454 | static GtkWidget *window = NULL, *curve; |
---|
7455 | static int count = 0; |
---|
7456 | gfloat vec[256]; |
---|
7457 | gint max; |
---|
7458 | gint i; |
---|
7459 | |
---|
7460 | if (!window) |
---|
7461 | { |
---|
7462 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
7463 | gtk_window_set_title (GTK_WINDOW (window), "test"); |
---|
7464 | gtk_container_set_border_width (GTK_CONTAINER (window), 10); |
---|
7465 | |
---|
7466 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7467 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
7468 | &window); |
---|
7469 | |
---|
7470 | curve = gtk_gamma_curve_new (); |
---|
7471 | gtk_container_add (GTK_CONTAINER (window), curve); |
---|
7472 | gtk_widget_show (curve); |
---|
7473 | } |
---|
7474 | |
---|
7475 | max = 127 + (count % 2)*128; |
---|
7476 | gtk_curve_set_range (GTK_CURVE (GTK_GAMMA_CURVE (curve)->curve), |
---|
7477 | 0, max, 0, max); |
---|
7478 | for (i = 0; i < max; ++i) |
---|
7479 | vec[i] = (127 / sqrt (max)) * sqrt (i); |
---|
7480 | gtk_curve_set_vector (GTK_CURVE (GTK_GAMMA_CURVE (curve)->curve), |
---|
7481 | max, vec); |
---|
7482 | |
---|
7483 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7484 | gtk_widget_show (window); |
---|
7485 | else if (count % 4 == 3) |
---|
7486 | { |
---|
7487 | gtk_widget_destroy (window); |
---|
7488 | window = NULL; |
---|
7489 | } |
---|
7490 | |
---|
7491 | ++count; |
---|
7492 | } |
---|
7493 | |
---|
7494 | /* |
---|
7495 | * Test scrolling |
---|
7496 | */ |
---|
7497 | |
---|
7498 | static int scroll_test_pos = 0.0; |
---|
7499 | static GdkGC *scroll_test_gc = NULL; |
---|
7500 | |
---|
7501 | static gint |
---|
7502 | scroll_test_expose (GtkWidget *widget, GdkEventExpose *event, |
---|
7503 | GtkAdjustment *adj) |
---|
7504 | { |
---|
7505 | gint i,j; |
---|
7506 | gint imin, imax, jmin, jmax; |
---|
7507 | |
---|
7508 | imin = (event->area.x) / 10; |
---|
7509 | imax = (event->area.x + event->area.width + 9) / 10; |
---|
7510 | |
---|
7511 | jmin = ((int)adj->value + event->area.y) / 10; |
---|
7512 | jmax = ((int)adj->value + event->area.y + event->area.height + 9) / 10; |
---|
7513 | |
---|
7514 | gdk_window_clear_area (widget->window, |
---|
7515 | event->area.x, event->area.y, |
---|
7516 | event->area.width, event->area.height); |
---|
7517 | |
---|
7518 | for (i=imin; i<imax; i++) |
---|
7519 | for (j=jmin; j<jmax; j++) |
---|
7520 | if ((i+j) % 2) |
---|
7521 | gdk_draw_rectangle (widget->window, |
---|
7522 | widget->style->black_gc, |
---|
7523 | TRUE, |
---|
7524 | 10*i, 10*j - (int)adj->value, 1+i%10, 1+j%10); |
---|
7525 | |
---|
7526 | return TRUE; |
---|
7527 | } |
---|
7528 | |
---|
7529 | static void |
---|
7530 | scroll_test_configure (GtkWidget *widget, GdkEventConfigure *event, |
---|
7531 | GtkAdjustment *adj) |
---|
7532 | { |
---|
7533 | adj->page_increment = 0.9 * widget->allocation.height; |
---|
7534 | adj->page_size = widget->allocation.height; |
---|
7535 | |
---|
7536 | gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed"); |
---|
7537 | } |
---|
7538 | |
---|
7539 | static void |
---|
7540 | scroll_test_adjustment_changed (GtkAdjustment *adj, GtkWidget *widget) |
---|
7541 | { |
---|
7542 | gint source_min = (int)adj->value - scroll_test_pos; |
---|
7543 | gint source_max = source_min + widget->allocation.height; |
---|
7544 | gint dest_min = 0; |
---|
7545 | gint dest_max = widget->allocation.height; |
---|
7546 | GdkRectangle rect; |
---|
7547 | GdkEvent *event; |
---|
7548 | |
---|
7549 | scroll_test_pos = adj->value; |
---|
7550 | |
---|
7551 | if (!GTK_WIDGET_DRAWABLE (widget)) |
---|
7552 | return; |
---|
7553 | |
---|
7554 | if (source_min < 0) |
---|
7555 | { |
---|
7556 | rect.x = 0; |
---|
7557 | rect.y = 0; |
---|
7558 | rect.width = widget->allocation.width; |
---|
7559 | rect.height = -source_min; |
---|
7560 | if (rect.height > widget->allocation.height) |
---|
7561 | rect.height = widget->allocation.height; |
---|
7562 | |
---|
7563 | source_min = 0; |
---|
7564 | dest_min = rect.height; |
---|
7565 | } |
---|
7566 | else |
---|
7567 | { |
---|
7568 | rect.x = 0; |
---|
7569 | rect.y = 2*widget->allocation.height - source_max; |
---|
7570 | if (rect.y < 0) |
---|
7571 | rect.y = 0; |
---|
7572 | rect.width = widget->allocation.width; |
---|
7573 | rect.height = widget->allocation.height - rect.y; |
---|
7574 | |
---|
7575 | source_max = widget->allocation.height; |
---|
7576 | dest_max = rect.y; |
---|
7577 | } |
---|
7578 | |
---|
7579 | if (source_min != source_max) |
---|
7580 | { |
---|
7581 | if (scroll_test_gc == NULL) |
---|
7582 | { |
---|
7583 | scroll_test_gc = gdk_gc_new (widget->window); |
---|
7584 | gdk_gc_set_exposures (scroll_test_gc, TRUE); |
---|
7585 | } |
---|
7586 | |
---|
7587 | gdk_draw_pixmap (widget->window, |
---|
7588 | scroll_test_gc, |
---|
7589 | widget->window, |
---|
7590 | 0, source_min, |
---|
7591 | 0, dest_min, |
---|
7592 | widget->allocation.width, |
---|
7593 | source_max - source_min); |
---|
7594 | |
---|
7595 | /* Make sure graphics expose events are processed before scrolling |
---|
7596 | * again */ |
---|
7597 | |
---|
7598 | while ((event = gdk_event_get_graphics_expose (widget->window)) != NULL) |
---|
7599 | { |
---|
7600 | gtk_widget_event (widget, event); |
---|
7601 | if (event->expose.count == 0) |
---|
7602 | { |
---|
7603 | gdk_event_free (event); |
---|
7604 | break; |
---|
7605 | } |
---|
7606 | gdk_event_free (event); |
---|
7607 | } |
---|
7608 | } |
---|
7609 | |
---|
7610 | if (rect.height != 0) |
---|
7611 | gtk_widget_draw (widget, &rect); |
---|
7612 | } |
---|
7613 | |
---|
7614 | |
---|
7615 | void |
---|
7616 | create_scroll_test (void) |
---|
7617 | { |
---|
7618 | static GtkWidget *window = NULL; |
---|
7619 | GtkWidget *hbox; |
---|
7620 | GtkWidget *drawing_area; |
---|
7621 | GtkWidget *scrollbar; |
---|
7622 | GtkWidget *button; |
---|
7623 | GtkAdjustment *adj; |
---|
7624 | GdkGeometry geometry; |
---|
7625 | GdkWindowHints geometry_mask; |
---|
7626 | |
---|
7627 | if (!window) |
---|
7628 | { |
---|
7629 | window = gtk_dialog_new (); |
---|
7630 | |
---|
7631 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7632 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
7633 | &window); |
---|
7634 | |
---|
7635 | gtk_window_set_title (GTK_WINDOW (window), "Scroll Test"); |
---|
7636 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
7637 | |
---|
7638 | hbox = gtk_hbox_new (FALSE, 0); |
---|
7639 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), hbox, |
---|
7640 | TRUE, TRUE, 0); |
---|
7641 | gtk_widget_show (hbox); |
---|
7642 | |
---|
7643 | drawing_area = gtk_drawing_area_new (); |
---|
7644 | gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200); |
---|
7645 | gtk_box_pack_start (GTK_BOX (hbox), drawing_area, TRUE, TRUE, 0); |
---|
7646 | gtk_widget_show (drawing_area); |
---|
7647 | |
---|
7648 | gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK); |
---|
7649 | |
---|
7650 | adj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 1000.0, 1.0, 180.0, 200.0)); |
---|
7651 | scroll_test_pos = 0.0; |
---|
7652 | |
---|
7653 | scrollbar = gtk_vscrollbar_new (adj); |
---|
7654 | gtk_box_pack_start (GTK_BOX (hbox), scrollbar, FALSE, FALSE, 0); |
---|
7655 | gtk_widget_show (scrollbar); |
---|
7656 | |
---|
7657 | gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event", |
---|
7658 | GTK_SIGNAL_FUNC (scroll_test_expose), adj); |
---|
7659 | gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event", |
---|
7660 | GTK_SIGNAL_FUNC (scroll_test_configure), adj); |
---|
7661 | |
---|
7662 | |
---|
7663 | gtk_signal_connect (GTK_OBJECT (adj), "value_changed", |
---|
7664 | GTK_SIGNAL_FUNC (scroll_test_adjustment_changed), |
---|
7665 | drawing_area); |
---|
7666 | |
---|
7667 | /* .. And create some buttons */ |
---|
7668 | |
---|
7669 | button = gtk_button_new_with_label ("Quit"); |
---|
7670 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7671 | button, TRUE, TRUE, 0); |
---|
7672 | |
---|
7673 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
7674 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
7675 | GTK_OBJECT (window)); |
---|
7676 | gtk_widget_show (button); |
---|
7677 | |
---|
7678 | /* Set up gridded geometry */ |
---|
7679 | |
---|
7680 | geometry_mask = GDK_HINT_MIN_SIZE | |
---|
7681 | GDK_HINT_BASE_SIZE | |
---|
7682 | GDK_HINT_RESIZE_INC; |
---|
7683 | |
---|
7684 | geometry.min_width = 20; |
---|
7685 | geometry.min_height = 20; |
---|
7686 | geometry.base_width = 0; |
---|
7687 | geometry.base_height = 0; |
---|
7688 | geometry.width_inc = 10; |
---|
7689 | geometry.height_inc = 10; |
---|
7690 | |
---|
7691 | gtk_window_set_geometry_hints (GTK_WINDOW (window), |
---|
7692 | drawing_area, &geometry, geometry_mask); |
---|
7693 | } |
---|
7694 | |
---|
7695 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7696 | gtk_widget_show (window); |
---|
7697 | else |
---|
7698 | gtk_widget_destroy (window); |
---|
7699 | } |
---|
7700 | |
---|
7701 | /* |
---|
7702 | * Timeout Test |
---|
7703 | */ |
---|
7704 | |
---|
7705 | static int timer = 0; |
---|
7706 | |
---|
7707 | gint |
---|
7708 | timeout_test (GtkWidget *label) |
---|
7709 | { |
---|
7710 | static int count = 0; |
---|
7711 | static char buffer[32]; |
---|
7712 | |
---|
7713 | sprintf (buffer, "count: %d", ++count); |
---|
7714 | gtk_label_set_text (GTK_LABEL (label), buffer); |
---|
7715 | |
---|
7716 | return TRUE; |
---|
7717 | } |
---|
7718 | |
---|
7719 | void |
---|
7720 | start_timeout_test (GtkWidget *widget, |
---|
7721 | GtkWidget *label) |
---|
7722 | { |
---|
7723 | if (!timer) |
---|
7724 | { |
---|
7725 | timer = gtk_timeout_add (100, (GtkFunction) timeout_test, label); |
---|
7726 | } |
---|
7727 | } |
---|
7728 | |
---|
7729 | void |
---|
7730 | stop_timeout_test (GtkWidget *widget, |
---|
7731 | gpointer data) |
---|
7732 | { |
---|
7733 | if (timer) |
---|
7734 | { |
---|
7735 | gtk_timeout_remove (timer); |
---|
7736 | timer = 0; |
---|
7737 | } |
---|
7738 | } |
---|
7739 | |
---|
7740 | void |
---|
7741 | destroy_timeout_test (GtkWidget *widget, |
---|
7742 | GtkWidget **window) |
---|
7743 | { |
---|
7744 | stop_timeout_test (NULL, NULL); |
---|
7745 | |
---|
7746 | *window = NULL; |
---|
7747 | } |
---|
7748 | |
---|
7749 | void |
---|
7750 | create_timeout_test (void) |
---|
7751 | { |
---|
7752 | static GtkWidget *window = NULL; |
---|
7753 | GtkWidget *button; |
---|
7754 | GtkWidget *label; |
---|
7755 | |
---|
7756 | if (!window) |
---|
7757 | { |
---|
7758 | window = gtk_dialog_new (); |
---|
7759 | |
---|
7760 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7761 | GTK_SIGNAL_FUNC(destroy_timeout_test), |
---|
7762 | &window); |
---|
7763 | |
---|
7764 | gtk_window_set_title (GTK_WINDOW (window), "Timeout Test"); |
---|
7765 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
7766 | |
---|
7767 | label = gtk_label_new ("count: 0"); |
---|
7768 | gtk_misc_set_padding (GTK_MISC (label), 10, 10); |
---|
7769 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), |
---|
7770 | label, TRUE, TRUE, 0); |
---|
7771 | gtk_widget_show (label); |
---|
7772 | |
---|
7773 | button = gtk_button_new_with_label ("close"); |
---|
7774 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
7775 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
7776 | GTK_OBJECT (window)); |
---|
7777 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7778 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7779 | button, TRUE, TRUE, 0); |
---|
7780 | gtk_widget_grab_default (button); |
---|
7781 | gtk_widget_show (button); |
---|
7782 | |
---|
7783 | button = gtk_button_new_with_label ("start"); |
---|
7784 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
7785 | GTK_SIGNAL_FUNC(start_timeout_test), |
---|
7786 | label); |
---|
7787 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7788 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7789 | button, TRUE, TRUE, 0); |
---|
7790 | gtk_widget_show (button); |
---|
7791 | |
---|
7792 | button = gtk_button_new_with_label ("stop"); |
---|
7793 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
7794 | GTK_SIGNAL_FUNC(stop_timeout_test), |
---|
7795 | NULL); |
---|
7796 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7797 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7798 | button, TRUE, TRUE, 0); |
---|
7799 | gtk_widget_show (button); |
---|
7800 | } |
---|
7801 | |
---|
7802 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7803 | gtk_widget_show (window); |
---|
7804 | else |
---|
7805 | gtk_widget_destroy (window); |
---|
7806 | } |
---|
7807 | |
---|
7808 | /* |
---|
7809 | * Idle Test |
---|
7810 | */ |
---|
7811 | |
---|
7812 | static int idle_id = 0; |
---|
7813 | |
---|
7814 | static gint |
---|
7815 | idle_test (GtkWidget *label) |
---|
7816 | { |
---|
7817 | static int count = 0; |
---|
7818 | static char buffer[32]; |
---|
7819 | |
---|
7820 | sprintf (buffer, "count: %d", ++count); |
---|
7821 | gtk_label_set_text (GTK_LABEL (label), buffer); |
---|
7822 | |
---|
7823 | return TRUE; |
---|
7824 | } |
---|
7825 | |
---|
7826 | static void |
---|
7827 | start_idle_test (GtkWidget *widget, |
---|
7828 | GtkWidget *label) |
---|
7829 | { |
---|
7830 | if (!idle_id) |
---|
7831 | { |
---|
7832 | idle_id = gtk_idle_add ((GtkFunction) idle_test, label); |
---|
7833 | } |
---|
7834 | } |
---|
7835 | |
---|
7836 | static void |
---|
7837 | stop_idle_test (GtkWidget *widget, |
---|
7838 | gpointer data) |
---|
7839 | { |
---|
7840 | if (idle_id) |
---|
7841 | { |
---|
7842 | gtk_idle_remove (idle_id); |
---|
7843 | idle_id = 0; |
---|
7844 | } |
---|
7845 | } |
---|
7846 | |
---|
7847 | static void |
---|
7848 | destroy_idle_test (GtkWidget *widget, |
---|
7849 | GtkWidget **window) |
---|
7850 | { |
---|
7851 | stop_idle_test (NULL, NULL); |
---|
7852 | |
---|
7853 | *window = NULL; |
---|
7854 | } |
---|
7855 | |
---|
7856 | static void |
---|
7857 | toggle_idle_container (GtkObject *button, |
---|
7858 | GtkContainer *container) |
---|
7859 | { |
---|
7860 | gtk_container_set_resize_mode (container, GPOINTER_TO_INT (gtk_object_get_user_data (button))); |
---|
7861 | } |
---|
7862 | |
---|
7863 | static void |
---|
7864 | create_idle_test (void) |
---|
7865 | { |
---|
7866 | static GtkWidget *window = NULL; |
---|
7867 | GtkWidget *button; |
---|
7868 | GtkWidget *label; |
---|
7869 | GtkWidget *container; |
---|
7870 | |
---|
7871 | if (!window) |
---|
7872 | { |
---|
7873 | GtkWidget *frame; |
---|
7874 | GtkWidget *box; |
---|
7875 | |
---|
7876 | window = gtk_dialog_new (); |
---|
7877 | |
---|
7878 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
7879 | GTK_SIGNAL_FUNC(destroy_idle_test), |
---|
7880 | &window); |
---|
7881 | |
---|
7882 | gtk_window_set_title (GTK_WINDOW (window), "Idle Test"); |
---|
7883 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
7884 | |
---|
7885 | label = gtk_label_new ("count: 0"); |
---|
7886 | gtk_misc_set_padding (GTK_MISC (label), 10, 10); |
---|
7887 | gtk_widget_show (label); |
---|
7888 | |
---|
7889 | container = |
---|
7890 | gtk_widget_new (GTK_TYPE_HBOX, |
---|
7891 | "GtkWidget::visible", TRUE, |
---|
7892 | /* "GtkContainer::child", gtk_widget_new (GTK_TYPE_HBOX, |
---|
7893 | * "GtkWidget::visible", TRUE, |
---|
7894 | */ |
---|
7895 | "GtkContainer::child", label, |
---|
7896 | /* NULL), */ |
---|
7897 | NULL); |
---|
7898 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), |
---|
7899 | container, TRUE, TRUE, 0); |
---|
7900 | |
---|
7901 | frame = |
---|
7902 | gtk_widget_new (GTK_TYPE_FRAME, |
---|
7903 | "GtkContainer::border_width", 5, |
---|
7904 | "GtkFrame::label", "Label Container", |
---|
7905 | "GtkWidget::visible", TRUE, |
---|
7906 | "GtkWidget::parent", GTK_DIALOG (window)->vbox, |
---|
7907 | NULL); |
---|
7908 | box = |
---|
7909 | gtk_widget_new (GTK_TYPE_VBOX, |
---|
7910 | "GtkWidget::visible", TRUE, |
---|
7911 | "GtkWidget::parent", frame, |
---|
7912 | NULL); |
---|
7913 | button = |
---|
7914 | gtk_widget_new (GTK_TYPE_RADIO_BUTTON, |
---|
7915 | "GtkButton::label", "Resize-Parent", |
---|
7916 | "GtkObject::user_data", (void*)GTK_RESIZE_PARENT, |
---|
7917 | "GtkObject::signal::clicked", toggle_idle_container, container, |
---|
7918 | "GtkWidget::visible", TRUE, |
---|
7919 | "GtkWidget::parent", box, |
---|
7920 | NULL); |
---|
7921 | button = |
---|
7922 | gtk_widget_new (GTK_TYPE_RADIO_BUTTON, |
---|
7923 | "GtkButton::label", "Resize-Queue", |
---|
7924 | "GtkObject::user_data", (void*)GTK_RESIZE_QUEUE, |
---|
7925 | "GtkObject::signal::clicked", toggle_idle_container, container, |
---|
7926 | "GtkRadioButton::group", button, |
---|
7927 | "GtkWidget::visible", TRUE, |
---|
7928 | "GtkWidget::parent", box, |
---|
7929 | NULL); |
---|
7930 | button = |
---|
7931 | gtk_widget_new (GTK_TYPE_RADIO_BUTTON, |
---|
7932 | "GtkButton::label", "Resize-Immediate", |
---|
7933 | "GtkObject::user_data", (void*)GTK_RESIZE_IMMEDIATE, |
---|
7934 | "GtkObject::signal::clicked", toggle_idle_container, container, |
---|
7935 | "GtkRadioButton::group", button, |
---|
7936 | "GtkWidget::visible", TRUE, |
---|
7937 | "GtkWidget::parent", box, |
---|
7938 | NULL); |
---|
7939 | |
---|
7940 | |
---|
7941 | button = gtk_button_new_with_label ("close"); |
---|
7942 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
7943 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
7944 | GTK_OBJECT (window)); |
---|
7945 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7946 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7947 | button, TRUE, TRUE, 0); |
---|
7948 | gtk_widget_grab_default (button); |
---|
7949 | gtk_widget_show (button); |
---|
7950 | |
---|
7951 | button = gtk_button_new_with_label ("start"); |
---|
7952 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
7953 | GTK_SIGNAL_FUNC(start_idle_test), |
---|
7954 | label); |
---|
7955 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7956 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7957 | button, TRUE, TRUE, 0); |
---|
7958 | gtk_widget_show (button); |
---|
7959 | |
---|
7960 | button = gtk_button_new_with_label ("stop"); |
---|
7961 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
7962 | GTK_SIGNAL_FUNC(stop_idle_test), |
---|
7963 | NULL); |
---|
7964 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
7965 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
7966 | button, TRUE, TRUE, 0); |
---|
7967 | gtk_widget_show (button); |
---|
7968 | } |
---|
7969 | |
---|
7970 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
7971 | gtk_widget_show (window); |
---|
7972 | else |
---|
7973 | gtk_widget_destroy (window); |
---|
7974 | } |
---|
7975 | |
---|
7976 | /* |
---|
7977 | * rc file test |
---|
7978 | */ |
---|
7979 | |
---|
7980 | void |
---|
7981 | reload_rc_file (void) |
---|
7982 | { |
---|
7983 | GList *toplevels; |
---|
7984 | |
---|
7985 | if (gtk_rc_reparse_all ()) |
---|
7986 | { |
---|
7987 | toplevels = gdk_window_get_toplevels(); |
---|
7988 | while (toplevels) |
---|
7989 | { |
---|
7990 | GtkWidget *widget; |
---|
7991 | gdk_window_get_user_data (toplevels->data, (gpointer *)&widget); |
---|
7992 | |
---|
7993 | if (widget) |
---|
7994 | gtk_widget_reset_rc_styles (widget); |
---|
7995 | |
---|
7996 | toplevels = toplevels->next; |
---|
7997 | } |
---|
7998 | g_list_free (toplevels); |
---|
7999 | } |
---|
8000 | } |
---|
8001 | |
---|
8002 | void |
---|
8003 | reload_all_rc_files (void) |
---|
8004 | { |
---|
8005 | static GdkAtom atom_rcfiles = GDK_NONE; |
---|
8006 | |
---|
8007 | GdkEventClient sev; |
---|
8008 | int i; |
---|
8009 | |
---|
8010 | if (!atom_rcfiles) |
---|
8011 | atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); |
---|
8012 | |
---|
8013 | for(i = 0; i < 5; i++) |
---|
8014 | sev.data.l[i] = 0; |
---|
8015 | sev.data_format = 32; |
---|
8016 | sev.message_type = atom_rcfiles; |
---|
8017 | gdk_event_send_clientmessage_toall ((GdkEvent *) &sev); |
---|
8018 | } |
---|
8019 | |
---|
8020 | void |
---|
8021 | create_rc_file (void) |
---|
8022 | { |
---|
8023 | static GtkWidget *window = NULL; |
---|
8024 | GtkWidget *button; |
---|
8025 | |
---|
8026 | if (!window) |
---|
8027 | { |
---|
8028 | window = gtk_dialog_new (); |
---|
8029 | |
---|
8030 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
8031 | GTK_SIGNAL_FUNC(destroy_idle_test), |
---|
8032 | &window); |
---|
8033 | |
---|
8034 | gtk_window_set_title (GTK_WINDOW (window), "Reload Rc file"); |
---|
8035 | gtk_container_set_border_width (GTK_CONTAINER (window), 0); |
---|
8036 | |
---|
8037 | button = gtk_button_new_with_label ("Reload"); |
---|
8038 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
8039 | GTK_SIGNAL_FUNC(reload_rc_file), NULL); |
---|
8040 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
8041 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
8042 | button, TRUE, TRUE, 0); |
---|
8043 | gtk_widget_grab_default (button); |
---|
8044 | gtk_widget_show (button); |
---|
8045 | |
---|
8046 | button = gtk_button_new_with_label ("Reload All"); |
---|
8047 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
8048 | GTK_SIGNAL_FUNC(reload_all_rc_files), NULL); |
---|
8049 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
8050 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
8051 | button, TRUE, TRUE, 0); |
---|
8052 | gtk_widget_show (button); |
---|
8053 | |
---|
8054 | button = gtk_button_new_with_label ("Close"); |
---|
8055 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
8056 | GTK_SIGNAL_FUNC(gtk_widget_destroy), |
---|
8057 | GTK_OBJECT (window)); |
---|
8058 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
8059 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), |
---|
8060 | button, TRUE, TRUE, 0); |
---|
8061 | gtk_widget_show (button); |
---|
8062 | |
---|
8063 | } |
---|
8064 | |
---|
8065 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
8066 | gtk_widget_show (window); |
---|
8067 | else |
---|
8068 | gtk_widget_destroy (window); |
---|
8069 | } |
---|
8070 | |
---|
8071 | /* |
---|
8072 | * Test of recursive mainloop |
---|
8073 | */ |
---|
8074 | |
---|
8075 | void |
---|
8076 | mainloop_destroyed (GtkWidget *w, GtkWidget **window) |
---|
8077 | { |
---|
8078 | *window = NULL; |
---|
8079 | gtk_main_quit (); |
---|
8080 | } |
---|
8081 | |
---|
8082 | void |
---|
8083 | create_mainloop (void) |
---|
8084 | { |
---|
8085 | static GtkWidget *window = NULL; |
---|
8086 | GtkWidget *label; |
---|
8087 | GtkWidget *button; |
---|
8088 | |
---|
8089 | if (!window) |
---|
8090 | { |
---|
8091 | window = gtk_dialog_new (); |
---|
8092 | |
---|
8093 | gtk_window_set_title (GTK_WINDOW (window), "Test Main Loop"); |
---|
8094 | |
---|
8095 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
8096 | GTK_SIGNAL_FUNC(mainloop_destroyed), |
---|
8097 | &window); |
---|
8098 | |
---|
8099 | label = gtk_label_new ("In recursive main loop..."); |
---|
8100 | gtk_misc_set_padding (GTK_MISC(label), 20, 20); |
---|
8101 | |
---|
8102 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), label, |
---|
8103 | TRUE, TRUE, 0); |
---|
8104 | gtk_widget_show (label); |
---|
8105 | |
---|
8106 | button = gtk_button_new_with_label ("Leave"); |
---|
8107 | gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), button, |
---|
8108 | FALSE, TRUE, 0); |
---|
8109 | |
---|
8110 | gtk_signal_connect_object (GTK_OBJECT (button), "clicked", |
---|
8111 | GTK_SIGNAL_FUNC (gtk_widget_destroy), |
---|
8112 | GTK_OBJECT (window)); |
---|
8113 | |
---|
8114 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
8115 | gtk_widget_grab_default (button); |
---|
8116 | |
---|
8117 | gtk_widget_show (button); |
---|
8118 | } |
---|
8119 | |
---|
8120 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
8121 | { |
---|
8122 | gtk_widget_show (window); |
---|
8123 | |
---|
8124 | g_print ("create_mainloop: start\n"); |
---|
8125 | gtk_main (); |
---|
8126 | g_print ("create_mainloop: done\n"); |
---|
8127 | } |
---|
8128 | else |
---|
8129 | gtk_widget_destroy (window); |
---|
8130 | } |
---|
8131 | |
---|
8132 | gint |
---|
8133 | layout_expose_handler (GtkWidget *widget, GdkEventExpose *event) |
---|
8134 | { |
---|
8135 | GtkLayout *layout; |
---|
8136 | |
---|
8137 | gint i,j; |
---|
8138 | gint imin, imax, jmin, jmax; |
---|
8139 | |
---|
8140 | layout = GTK_LAYOUT (widget); |
---|
8141 | |
---|
8142 | imin = (layout->xoffset + event->area.x) / 10; |
---|
8143 | imax = (layout->xoffset + event->area.x + event->area.width + 9) / 10; |
---|
8144 | |
---|
8145 | jmin = (layout->yoffset + event->area.y) / 10; |
---|
8146 | jmax = (layout->yoffset + event->area.y + event->area.height + 9) / 10; |
---|
8147 | |
---|
8148 | gdk_window_clear_area (widget->window, |
---|
8149 | event->area.x, event->area.y, |
---|
8150 | event->area.width, event->area.height); |
---|
8151 | |
---|
8152 | for (i=imin; i<imax; i++) |
---|
8153 | for (j=jmin; j<jmax; j++) |
---|
8154 | if ((i+j) % 2) |
---|
8155 | gdk_draw_rectangle (layout->bin_window, |
---|
8156 | widget->style->black_gc, |
---|
8157 | TRUE, |
---|
8158 | 10*i - layout->xoffset, 10*j - layout->yoffset, |
---|
8159 | 1+i%10, 1+j%10); |
---|
8160 | |
---|
8161 | return TRUE; |
---|
8162 | } |
---|
8163 | |
---|
8164 | void create_layout (void) |
---|
8165 | { |
---|
8166 | static GtkWidget *window = NULL; |
---|
8167 | GtkWidget *layout; |
---|
8168 | GtkWidget *scrolledwindow; |
---|
8169 | GtkWidget *button; |
---|
8170 | |
---|
8171 | if (!window) |
---|
8172 | { |
---|
8173 | gchar buf[16]; |
---|
8174 | |
---|
8175 | gint i, j; |
---|
8176 | |
---|
8177 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
8178 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
8179 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), |
---|
8180 | &window); |
---|
8181 | |
---|
8182 | gtk_window_set_title (GTK_WINDOW (window), "Layout"); |
---|
8183 | gtk_widget_set_usize (window, 200, 200); |
---|
8184 | |
---|
8185 | scrolledwindow = gtk_scrolled_window_new (NULL, NULL); |
---|
8186 | |
---|
8187 | gtk_container_add (GTK_CONTAINER (window), scrolledwindow); |
---|
8188 | |
---|
8189 | layout = gtk_layout_new (NULL, NULL); |
---|
8190 | gtk_container_add (GTK_CONTAINER (scrolledwindow), layout); |
---|
8191 | |
---|
8192 | /* We set step sizes here since GtkLayout does not set |
---|
8193 | * them itself. |
---|
8194 | */ |
---|
8195 | GTK_LAYOUT (layout)->hadjustment->step_increment = 10.0; |
---|
8196 | GTK_LAYOUT (layout)->vadjustment->step_increment = 10.0; |
---|
8197 | |
---|
8198 | gtk_widget_set_events (layout, GDK_EXPOSURE_MASK); |
---|
8199 | gtk_signal_connect (GTK_OBJECT (layout), "expose_event", |
---|
8200 | GTK_SIGNAL_FUNC (layout_expose_handler), NULL); |
---|
8201 | |
---|
8202 | gtk_layout_set_size (GTK_LAYOUT (layout), 1600, 128000); |
---|
8203 | |
---|
8204 | for (i=0 ; i < 16 ; i++) |
---|
8205 | for (j=0 ; j < 16 ; j++) |
---|
8206 | { |
---|
8207 | sprintf(buf, "Button %d, %d", i, j); |
---|
8208 | if ((i + j) % 2) |
---|
8209 | button = gtk_button_new_with_label (buf); |
---|
8210 | else |
---|
8211 | button = gtk_label_new (buf); |
---|
8212 | |
---|
8213 | gtk_layout_put (GTK_LAYOUT (layout), button, |
---|
8214 | j*100, i*100); |
---|
8215 | } |
---|
8216 | |
---|
8217 | for (i=16; i < 1280; i++) |
---|
8218 | { |
---|
8219 | sprintf(buf, "Button %d, %d", i, 0); |
---|
8220 | if (i % 2) |
---|
8221 | button = gtk_button_new_with_label (buf); |
---|
8222 | else |
---|
8223 | button = gtk_label_new (buf); |
---|
8224 | |
---|
8225 | gtk_layout_put (GTK_LAYOUT (layout), button, |
---|
8226 | 0, i*100); |
---|
8227 | } |
---|
8228 | } |
---|
8229 | |
---|
8230 | if (!GTK_WIDGET_VISIBLE (window)) |
---|
8231 | gtk_widget_show_all (window); |
---|
8232 | else |
---|
8233 | gtk_widget_destroy (window); |
---|
8234 | } |
---|
8235 | |
---|
8236 | /* |
---|
8237 | * Main Window and Exit |
---|
8238 | */ |
---|
8239 | |
---|
8240 | void |
---|
8241 | do_exit (GtkWidget *widget, GtkWidget *window) |
---|
8242 | { |
---|
8243 | gtk_widget_destroy (window); |
---|
8244 | gtk_main_quit (); |
---|
8245 | } |
---|
8246 | |
---|
8247 | void |
---|
8248 | create_main_window (void) |
---|
8249 | { |
---|
8250 | struct { |
---|
8251 | char *label; |
---|
8252 | void (*func) (); |
---|
8253 | } buttons[] = |
---|
8254 | { |
---|
8255 | { "button box", create_button_box }, |
---|
8256 | { "buttons", create_buttons }, |
---|
8257 | { "check buttons", create_check_buttons }, |
---|
8258 | { "clist", create_clist}, |
---|
8259 | { "color selection", create_color_selection }, |
---|
8260 | { "ctree", create_ctree }, |
---|
8261 | { "cursors", create_cursors }, |
---|
8262 | { "dialog", create_dialog }, |
---|
8263 | /* { "dnd", create_dnd }, */ |
---|
8264 | { "entry", create_entry }, |
---|
8265 | { "event watcher", create_event_watcher }, |
---|
8266 | { "file selection", create_file_selection }, |
---|
8267 | { "font selection", create_font_selection }, |
---|
8268 | { "gamma curve", create_gamma_curve }, |
---|
8269 | { "handle box", create_handle_box }, |
---|
8270 | { "item factory", create_item_factory }, |
---|
8271 | { "labels", create_labels }, |
---|
8272 | { "layout", create_layout }, |
---|
8273 | { "list", create_list }, |
---|
8274 | { "menus", create_menus }, |
---|
8275 | { "modal window", create_modal_window }, |
---|
8276 | { "notebook", create_notebook }, |
---|
8277 | { "panes", create_panes }, |
---|
8278 | { "pixmap", create_pixmap }, |
---|
8279 | { "preview color", create_color_preview }, |
---|
8280 | { "preview gray", create_gray_preview }, |
---|
8281 | { "progress bar", create_progress_bar }, |
---|
8282 | { "radio buttons", create_radio_buttons }, |
---|
8283 | { "range controls", create_range_controls }, |
---|
8284 | { "rc file", create_rc_file }, |
---|
8285 | { "reparent", create_reparent }, |
---|
8286 | { "rulers", create_rulers }, |
---|
8287 | { "saved position", create_saved_position }, |
---|
8288 | { "scrolled windows", create_scrolled_windows }, |
---|
8289 | { "shapes", create_shapes }, |
---|
8290 | { "spinbutton", create_spins }, |
---|
8291 | { "statusbar", create_statusbar }, |
---|
8292 | { "test idle", create_idle_test }, |
---|
8293 | { "test mainloop", create_mainloop }, |
---|
8294 | { "test scrolling", create_scroll_test }, |
---|
8295 | { "test selection", create_selection_test }, |
---|
8296 | { "test timeout", create_timeout_test }, |
---|
8297 | { "text", create_text }, |
---|
8298 | { "toggle buttons", create_toggle_buttons }, |
---|
8299 | { "toolbar", create_toolbar }, |
---|
8300 | { "tooltips", create_tooltips }, |
---|
8301 | { "tree", create_tree_mode_window}, |
---|
8302 | { "WM hints", create_wmhints }, |
---|
8303 | }; |
---|
8304 | int nbuttons = sizeof (buttons) / sizeof (buttons[0]); |
---|
8305 | GtkWidget *window; |
---|
8306 | GtkWidget *box1; |
---|
8307 | GtkWidget *box2; |
---|
8308 | GtkWidget *scrolled_window; |
---|
8309 | GtkWidget *button; |
---|
8310 | GtkWidget *label; |
---|
8311 | gchar buffer[64]; |
---|
8312 | GtkWidget *separator; |
---|
8313 | int i; |
---|
8314 | |
---|
8315 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
8316 | gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, FALSE); |
---|
8317 | gtk_widget_set_name (window, "main window"); |
---|
8318 | gtk_widget_set_usize (window, 200, 400); |
---|
8319 | gtk_widget_set_uposition (window, 20, 20); |
---|
8320 | |
---|
8321 | gtk_signal_connect (GTK_OBJECT (window), "destroy", |
---|
8322 | GTK_SIGNAL_FUNC(gtk_main_quit), |
---|
8323 | NULL); |
---|
8324 | gtk_signal_connect (GTK_OBJECT (window), "delete-event", |
---|
8325 | GTK_SIGNAL_FUNC (gtk_false), |
---|
8326 | NULL); |
---|
8327 | |
---|
8328 | box1 = gtk_vbox_new (FALSE, 0); |
---|
8329 | gtk_container_add (GTK_CONTAINER (window), box1); |
---|
8330 | |
---|
8331 | if (gtk_micro_version > 0) |
---|
8332 | sprintf (buffer, |
---|
8333 | "Gtk+ v%d.%d.%d", |
---|
8334 | gtk_major_version, |
---|
8335 | gtk_minor_version, |
---|
8336 | gtk_micro_version); |
---|
8337 | else |
---|
8338 | sprintf (buffer, |
---|
8339 | "Gtk+ v%d.%d", |
---|
8340 | gtk_major_version, |
---|
8341 | gtk_minor_version); |
---|
8342 | |
---|
8343 | label = gtk_label_new (buffer); |
---|
8344 | gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); |
---|
8345 | |
---|
8346 | scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
---|
8347 | gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10); |
---|
8348 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), |
---|
8349 | GTK_POLICY_AUTOMATIC, |
---|
8350 | GTK_POLICY_AUTOMATIC); |
---|
8351 | gtk_box_pack_start (GTK_BOX (box1), scrolled_window, TRUE, TRUE, 0); |
---|
8352 | |
---|
8353 | box2 = gtk_vbox_new (FALSE, 0); |
---|
8354 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
8355 | gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box2); |
---|
8356 | gtk_container_set_focus_vadjustment (GTK_CONTAINER (box2), |
---|
8357 | gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window))); |
---|
8358 | gtk_widget_show (box2); |
---|
8359 | |
---|
8360 | for (i = 0; i < nbuttons; i++) |
---|
8361 | { |
---|
8362 | button = gtk_button_new_with_label (buttons[i].label); |
---|
8363 | if (buttons[i].func) |
---|
8364 | gtk_signal_connect (GTK_OBJECT (button), |
---|
8365 | "clicked", |
---|
8366 | GTK_SIGNAL_FUNC(buttons[i].func), |
---|
8367 | NULL); |
---|
8368 | else |
---|
8369 | gtk_widget_set_sensitive (button, FALSE); |
---|
8370 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
8371 | } |
---|
8372 | |
---|
8373 | separator = gtk_hseparator_new (); |
---|
8374 | gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); |
---|
8375 | |
---|
8376 | box2 = gtk_vbox_new (FALSE, 10); |
---|
8377 | gtk_container_set_border_width (GTK_CONTAINER (box2), 10); |
---|
8378 | gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); |
---|
8379 | |
---|
8380 | button = gtk_button_new_with_label ("close"); |
---|
8381 | gtk_signal_connect (GTK_OBJECT (button), "clicked", |
---|
8382 | GTK_SIGNAL_FUNC (do_exit), |
---|
8383 | window); |
---|
8384 | gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); |
---|
8385 | GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); |
---|
8386 | gtk_widget_grab_default (button); |
---|
8387 | |
---|
8388 | gtk_widget_show_all (window); |
---|
8389 | } |
---|
8390 | |
---|
8391 | int |
---|
8392 | main (int argc, char *argv[]) |
---|
8393 | { |
---|
8394 | GtkBindingSet *binding_set; |
---|
8395 | struct stat statbuf; |
---|
8396 | |
---|
8397 | srand (time (NULL)); |
---|
8398 | |
---|
8399 | gtk_set_locale (); |
---|
8400 | |
---|
8401 | /* Check to see if we are being run from the correct |
---|
8402 | * directory. |
---|
8403 | */ |
---|
8404 | if (stat("./testgtkrc", &statbuf) < 0) |
---|
8405 | { |
---|
8406 | fprintf (stderr, "*** The testgtk program must be run from within the\n" |
---|
8407 | "*** gtk/ subdirectory of the GTK+ distribution.\n"); |
---|
8408 | exit (1); |
---|
8409 | } |
---|
8410 | |
---|
8411 | gtk_rc_add_default_file ("testgtkrc"); |
---|
8412 | |
---|
8413 | gtk_init (&argc, &argv); |
---|
8414 | |
---|
8415 | gdk_rgb_init (); |
---|
8416 | |
---|
8417 | /* bindings test |
---|
8418 | */ |
---|
8419 | binding_set = gtk_binding_set_by_class (gtk_type_class (GTK_TYPE_WIDGET)); |
---|
8420 | gtk_binding_entry_add_signal (binding_set, |
---|
8421 | '9', GDK_CONTROL_MASK | GDK_RELEASE_MASK, |
---|
8422 | "debug_msg", |
---|
8423 | 1, |
---|
8424 | GTK_TYPE_STRING, "GtkWidgetClass <ctrl><release>9 test"); |
---|
8425 | |
---|
8426 | create_main_window (); |
---|
8427 | |
---|
8428 | gtk_main (); |
---|
8429 | |
---|
8430 | return 0; |
---|
8431 | } |
---|