Mercurial > geeqie.yaz
annotate src/ui_misc.c @ 701:28af4b6dd9ef
Use G_DIR_SEPARATOR instead of '/' where applicable.
author | zas_ |
---|---|
date | Tue, 20 May 2008 22:00:14 +0000 |
parents | 985fdfebd89e |
children | c414002a1f27 |
rev | line source |
---|---|
9 | 1 /* |
2 * (SLIK) SimpLIstic sKin functions | |
3 * (C) 2004 John Ellis | |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 #ifdef HAVE_CONFIG_H | |
14 # include "config.h" | |
15 #endif | |
16 #include "intl.h" | |
17 | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
22 #include <gtk/gtk.h> | |
23 #include <gdk/gdkkeysyms.h> | |
24 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
25 #include "main.h" |
9 | 26 #include "ui_misc.h" |
27 | |
28 #include "ui_bookmark.h" | |
29 | |
30 | |
31 /* | |
32 *----------------------------------------------------------------------------- | |
33 * widget and layout utilities | |
34 *----------------------------------------------------------------------------- | |
35 */ | |
36 | |
37 GtkWidget *pref_box_new(GtkWidget *parent_box, gint fill, | |
38 GtkOrientation orientation, gint padding) | |
39 { | |
40 GtkWidget *box; | |
41 | |
42 if (orientation == GTK_ORIENTATION_HORIZONTAL) | |
43 { | |
44 box = gtk_hbox_new(FALSE, padding); | |
45 } | |
46 else | |
47 { | |
48 box = gtk_vbox_new(FALSE, padding); | |
49 } | |
50 | |
51 gtk_box_pack_start(GTK_BOX(parent_box), box, fill, fill, 0); | |
52 gtk_widget_show(box); | |
53 | |
54 return box; | |
55 } | |
56 | |
57 GtkWidget *pref_group_new(GtkWidget *parent_box, gint fill, | |
58 const gchar *text, GtkOrientation orientation) | |
59 { | |
60 GtkWidget *box; | |
61 GtkWidget *vbox; | |
62 GtkWidget *hbox; | |
63 GtkWidget *label; | |
64 | |
65 vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
66 | |
67 /* add additional spacing if necessary */ | |
68 if (GTK_IS_VBOX(parent_box) && GTK_BOX(parent_box)->children != NULL) | |
69 { | |
70 pref_spacer(vbox, PREF_PAD_GROUP - PREF_PAD_GAP); | |
71 } | |
72 | |
73 gtk_box_pack_start(GTK_BOX(parent_box), vbox, fill, fill, 0); | |
74 gtk_widget_show(vbox); | |
75 | |
76 label = gtk_label_new(text); | |
77 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
78 pref_label_bold(label, TRUE, FALSE); | |
79 | |
80 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
81 gtk_widget_show(label); | |
82 | |
83 hbox = gtk_hbox_new(FALSE, PREF_PAD_INDENT); | |
84 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); | |
85 gtk_widget_show(hbox); | |
86 | |
87 /* indent using empty box */ | |
88 pref_spacer(hbox, 0); | |
89 | |
90 if (orientation == GTK_ORIENTATION_HORIZONTAL) | |
91 { | |
92 box = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
93 } | |
94 else | |
95 { | |
96 box = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
97 } | |
98 gtk_box_pack_start(GTK_BOX(hbox), box, TRUE, TRUE, 0); | |
99 gtk_widget_show(box); | |
100 | |
101 g_object_set_data(G_OBJECT(box), "pref_group", vbox); | |
102 | |
103 return box; | |
104 } | |
105 | |
106 GtkWidget *pref_group_parent(GtkWidget *child) | |
107 { | |
108 GtkWidget *parent; | |
109 | |
110 parent = child; | |
111 while (parent) | |
112 { | |
113 GtkWidget *group; | |
114 | |
115 group = g_object_get_data(G_OBJECT(parent), "pref_group"); | |
116 if (group && GTK_IS_WIDGET(group)) return group; | |
117 | |
118 parent = gtk_widget_get_parent(parent); | |
119 } | |
120 | |
121 return child; | |
122 } | |
123 | |
124 GtkWidget *pref_frame_new(GtkWidget *parent_box, gint fill, | |
125 const gchar *text, | |
126 GtkOrientation orientation, gint padding) | |
127 { | |
128 GtkWidget *box; | |
129 GtkWidget *frame = NULL; | |
130 | |
131 frame = gtk_frame_new(text); | |
132 gtk_box_pack_start(GTK_BOX(parent_box), frame, fill, fill, 0); | |
133 gtk_widget_show(frame); | |
134 | |
135 if (orientation == GTK_ORIENTATION_HORIZONTAL) | |
136 { | |
137 box = gtk_hbox_new(FALSE, padding); | |
138 } | |
139 else | |
140 { | |
141 box = gtk_vbox_new(FALSE, padding); | |
142 } | |
143 gtk_container_add(GTK_CONTAINER(frame), box); | |
144 gtk_container_set_border_width(GTK_CONTAINER(box), PREF_PAD_BORDER); | |
145 gtk_widget_show(box); | |
146 | |
147 return box; | |
148 } | |
149 | |
150 GtkWidget *pref_spacer(GtkWidget *parent_box, gint padding) | |
151 { | |
152 GtkWidget *spacer; | |
153 | |
154 spacer = gtk_hbox_new(FALSE, 0); | |
155 gtk_box_pack_start(GTK_BOX(parent_box), spacer, FALSE, FALSE, padding / 2); | |
156 gtk_widget_show(spacer); | |
157 | |
158 return spacer; | |
159 } | |
160 | |
161 GtkWidget *pref_line(GtkWidget *parent_box, gint padding) | |
162 { | |
163 GtkWidget *spacer; | |
164 | |
165 if (GTK_IS_HBOX(parent_box)) | |
166 { | |
167 spacer = gtk_vseparator_new(); | |
168 } | |
169 else | |
170 { | |
171 spacer = gtk_hseparator_new(); | |
172 } | |
173 | |
174 gtk_box_pack_start(GTK_BOX(parent_box), spacer, FALSE, FALSE, padding / 2); | |
175 gtk_widget_show(spacer); | |
176 | |
177 return spacer; | |
178 } | |
179 | |
180 GtkWidget *pref_label_new(GtkWidget *parent_box, const gchar *text) | |
181 { | |
182 GtkWidget *label; | |
183 | |
184 label = gtk_label_new(text); | |
185 gtk_box_pack_start(GTK_BOX(parent_box), label, FALSE, FALSE, 0); | |
186 gtk_widget_show(label); | |
187 | |
188 return label; | |
189 } | |
190 | |
191 GtkWidget *pref_label_new_mnemonic(GtkWidget *parent_box, const gchar *text, GtkWidget *widget) | |
192 { | |
193 GtkWidget *label; | |
194 | |
195 label = gtk_label_new_with_mnemonic(text); | |
196 gtk_label_set_mnemonic_widget(GTK_LABEL(label), widget); | |
197 gtk_box_pack_start(GTK_BOX(parent_box), label, FALSE, FALSE, 0); | |
198 gtk_widget_show(label); | |
199 | |
200 return label; | |
201 } | |
202 | |
203 void pref_label_bold(GtkWidget *label, gint bold, gint increase_size) | |
204 { | |
205 PangoAttrList *pal; | |
206 PangoAttribute *pa; | |
207 | |
208 if (!bold && !increase_size) return; | |
209 | |
210 pal = pango_attr_list_new(); | |
211 | |
212 if (bold) | |
213 { | |
214 pa = pango_attr_weight_new(PANGO_WEIGHT_BOLD); | |
215 pa->start_index = 0; | |
216 pa->end_index = G_MAXINT; | |
217 pango_attr_list_insert(pal, pa); | |
218 } | |
219 | |
220 if (increase_size) | |
221 { | |
222 pa = pango_attr_scale_new(PANGO_SCALE_LARGE); | |
223 pa->start_index = 0; | |
224 pa->end_index = G_MAXINT; | |
225 pango_attr_list_insert(pal, pa); | |
226 } | |
227 | |
228 gtk_label_set_attributes(GTK_LABEL(label), pal); | |
229 pango_attr_list_unref(pal); | |
230 } | |
231 | |
232 GtkWidget *pref_button_new(GtkWidget *parent_box, const gchar *stock_id, | |
233 const gchar *text, gint hide_stock_text, | |
234 GCallback func, gpointer data) | |
235 { | |
236 GtkWidget *button; | |
237 | |
238 if (stock_id && !text && !hide_stock_text) | |
239 { | |
240 button = gtk_button_new_from_stock(stock_id); | |
241 } | |
242 else | |
243 { | |
244 GtkWidget *image = NULL; | |
245 GtkWidget *label = NULL; | |
246 | |
247 button = gtk_button_new(); | |
248 | |
249 if (stock_id) image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON); | |
250 if (text) | |
251 { | |
252 label = gtk_label_new_with_mnemonic(text); | |
253 gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5); | |
254 gtk_label_set_mnemonic_widget(GTK_LABEL(label), button); | |
255 } | |
256 | |
257 if (image && label) | |
258 { | |
259 GtkWidget *align; | |
260 GtkWidget *hbox; | |
261 | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
475
diff
changeset
|
262 hbox = gtk_hbox_new(FALSE, PREF_PAD_BUTTON_ICON_GAP); |
9 | 263 |
264 align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); | |
265 gtk_container_add(GTK_CONTAINER(button), align); | |
266 gtk_widget_show(align); | |
267 | |
268 gtk_container_add(GTK_CONTAINER(align), hbox); | |
269 gtk_widget_show(hbox); | |
270 | |
271 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | |
272 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
273 } | |
274 else | |
275 { | |
276 if (image) | |
277 { | |
278 gtk_container_add(GTK_CONTAINER(button), image); | |
279 } | |
280 else if (label) | |
281 { | |
282 gtk_container_add(GTK_CONTAINER(button), label); | |
283 } | |
284 } | |
285 | |
286 if (image) gtk_widget_show(image); | |
287 if (label) gtk_widget_show(label); | |
288 } | |
289 | |
290 if (func) g_signal_connect(G_OBJECT(button), "clicked", func, data); | |
291 | |
292 if (parent_box) | |
293 { | |
294 gtk_box_pack_start(GTK_BOX(parent_box), button, FALSE, FALSE, 0); | |
295 gtk_widget_show(button); | |
296 } | |
297 | |
298 return button; | |
299 } | |
300 | |
301 static GtkWidget *real_pref_checkbox_new(GtkWidget *parent_box, const gchar *text, gint mnemonic_text, | |
302 gint active, GCallback func, gpointer data) | |
303 { | |
304 GtkWidget *button; | |
305 | |
306 if (mnemonic_text) | |
307 { | |
308 button = gtk_check_button_new_with_mnemonic(text); | |
309 } | |
310 else | |
311 { | |
312 button = gtk_check_button_new_with_label(text); | |
313 } | |
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); | |
315 if (func) g_signal_connect(G_OBJECT(button), "clicked", func, data); | |
316 | |
317 gtk_box_pack_start(GTK_BOX(parent_box), button, FALSE, FALSE, 0); | |
318 gtk_widget_show(button); | |
319 | |
320 return button; | |
321 } | |
322 | |
323 GtkWidget *pref_checkbox_new(GtkWidget *parent_box, const gchar *text, gint active, | |
324 GCallback func, gpointer data) | |
325 { | |
326 return real_pref_checkbox_new(parent_box, text, FALSE, active, func, data); | |
327 } | |
328 | |
329 GtkWidget *pref_checkbox_new_mnemonic(GtkWidget *parent_box, const gchar *text, gint active, | |
330 GCallback func, gpointer data) | |
331 { | |
332 return real_pref_checkbox_new(parent_box, text, TRUE, active, func, data); | |
333 } | |
334 | |
335 static void pref_checkbox_int_cb(GtkWidget *widget, gpointer data) | |
336 { | |
337 gint *result = data; | |
338 | |
339 *result = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
340 } | |
341 | |
342 GtkWidget *pref_checkbox_new_int(GtkWidget *parent_box, const gchar *text, gint active, | |
343 gint *result) | |
344 { | |
345 GtkWidget *button; | |
346 | |
347 button = pref_checkbox_new(parent_box, text, active, | |
348 G_CALLBACK(pref_checkbox_int_cb), result); | |
349 *result = active; | |
350 | |
351 return button; | |
352 } | |
353 | |
354 static void pref_checkbox_link_sensitivity_cb(GtkWidget *button, gpointer data) | |
355 { | |
356 GtkWidget *widget = data; | |
357 | |
358 gtk_widget_set_sensitive(widget, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))); | |
359 } | |
360 | |
361 void pref_checkbox_link_sensitivity(GtkWidget *button, GtkWidget *widget) | |
362 { | |
363 g_signal_connect(G_OBJECT(button), "toggled", | |
364 G_CALLBACK(pref_checkbox_link_sensitivity_cb), widget); | |
365 | |
366 pref_checkbox_link_sensitivity_cb(button, widget); | |
367 } | |
368 | |
369 static void pref_checkbox_link_sensitivity_swap_cb(GtkWidget *button, gpointer data) | |
370 { | |
371 GtkWidget *widget = data; | |
372 | |
373 gtk_widget_set_sensitive(widget, !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))); | |
374 } | |
375 | |
376 void pref_checkbox_link_sensitivity_swap(GtkWidget *button, GtkWidget *widget) | |
377 { | |
378 g_signal_connect(G_OBJECT(button), "toggled", | |
379 G_CALLBACK(pref_checkbox_link_sensitivity_swap_cb), widget); | |
380 | |
381 pref_checkbox_link_sensitivity_swap_cb(button, widget); | |
382 } | |
383 | |
384 static GtkWidget *real_pref_radiobutton_new(GtkWidget *parent_box, GtkWidget *sibling, | |
385 const gchar *text, gint mnemonic_text, gint active, | |
386 GCallback func, gpointer data) | |
387 { | |
388 GtkWidget *button; | |
389 GSList* group; | |
390 | |
391 if (sibling) | |
392 { | |
393 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(sibling)); | |
394 } | |
395 else | |
396 { | |
397 group = NULL; | |
398 } | |
399 | |
400 if (mnemonic_text) | |
401 { | |
402 button = gtk_radio_button_new_with_mnemonic(group, text); | |
403 } | |
404 else | |
405 { | |
406 button = gtk_radio_button_new_with_label(group, text); | |
407 } | |
408 | |
409 if (active) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); | |
410 if (func) g_signal_connect(G_OBJECT(button), "clicked", func, data); | |
411 | |
412 gtk_box_pack_start(GTK_BOX(parent_box), button, FALSE, FALSE, 0); | |
413 gtk_widget_show(button); | |
414 | |
415 return button; | |
416 } | |
417 | |
418 GtkWidget *pref_radiobutton_new(GtkWidget *parent_box, GtkWidget *sibling, | |
419 const gchar *text, gint active, | |
420 GCallback func, gpointer data) | |
421 { | |
422 return real_pref_radiobutton_new(parent_box, sibling, text, FALSE, active, func, data); | |
423 } | |
424 | |
425 GtkWidget *pref_radiobutton_new_mnemonic(GtkWidget *parent_box, GtkWidget *sibling, | |
426 const gchar *text, gint active, | |
427 GCallback func, gpointer data) | |
428 { | |
429 return real_pref_radiobutton_new(parent_box, sibling, text, TRUE, active, func, data); | |
430 } | |
431 | |
432 #define PREF_RADIO_VALUE_KEY "pref_radio_value" | |
433 | |
434 static void pref_radiobutton_int_cb(GtkWidget *widget, gpointer data) | |
435 { | |
436 gint *result = data; | |
437 | |
438 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
439 { | |
440 *result = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), PREF_RADIO_VALUE_KEY)); | |
441 } | |
442 } | |
443 | |
444 GtkWidget *pref_radiobutton_new_int(GtkWidget *parent_box, GtkWidget *sibling, | |
445 const gchar *text, gint active, | |
446 gint *result, gint value, | |
447 GCallback func, gpointer data) | |
448 { | |
449 GtkWidget *button; | |
450 | |
451 button = pref_radiobutton_new(parent_box, sibling, text, active, | |
452 G_CALLBACK(pref_radiobutton_int_cb), result); | |
453 g_object_set_data(G_OBJECT(button), PREF_RADIO_VALUE_KEY, GINT_TO_POINTER(value)); | |
454 if (active) *result = value; | |
455 | |
456 return button; | |
457 } | |
458 | |
459 static GtkWidget *real_pref_spin_new(GtkWidget *parent_box, const gchar *text, const gchar *suffix, | |
460 gint mnemonic_text, | |
461 gdouble min, gdouble max, gdouble step, gint digits, | |
462 gdouble value, | |
463 GCallback func, gpointer data) | |
464 { | |
465 GtkWidget *spin; | |
466 GtkWidget *box; | |
467 GtkWidget *label; | |
468 | |
469 box = pref_box_new(parent_box, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
470 | |
471 spin = gtk_spin_button_new_with_range(min, max, step); | |
472 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), digits); | |
473 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), value); | |
474 | |
475 if (func) | |
476 { | |
477 g_signal_connect(G_OBJECT(spin), "value_changed", G_CALLBACK(func), data); | |
478 } | |
479 | |
480 if (text) | |
481 { | |
482 if (mnemonic_text) | |
483 { | |
484 label = pref_label_new_mnemonic(box, text, spin); | |
485 } | |
486 else | |
487 { | |
488 label = pref_label_new(box, text); | |
489 } | |
490 pref_link_sensitivity(label, spin); | |
491 } | |
492 | |
493 gtk_box_pack_start(GTK_BOX(box), spin, FALSE, FALSE, 0); | |
494 gtk_widget_show(spin); | |
495 | |
496 /* perhaps this should only be PREF_PAD_GAP distance from spinbutton ? */ | |
497 if (suffix) | |
498 { | |
499 label = pref_label_new(box, suffix); | |
500 pref_link_sensitivity(label, spin); | |
501 } | |
502 | |
503 return spin; | |
504 } | |
505 | |
506 GtkWidget *pref_spin_new(GtkWidget *parent_box, const gchar *text, const gchar *suffix, | |
507 gdouble min, gdouble max, gdouble step, gint digits, | |
508 gdouble value, | |
509 GCallback func, gpointer data) | |
510 { | |
511 return real_pref_spin_new(parent_box, text, suffix, FALSE, | |
512 min, max, step, digits, value, func, data); | |
513 } | |
514 | |
515 GtkWidget *pref_spin_new_mnemonic(GtkWidget *parent_box, const gchar *text, const gchar *suffix, | |
516 gdouble min, gdouble max, gdouble step, gint digits, | |
517 gdouble value, | |
518 GCallback func, gpointer data) | |
519 { | |
520 return real_pref_spin_new(parent_box, text, suffix, TRUE, | |
521 min, max, step, digits, value, func, data); | |
522 } | |
523 | |
524 static void pref_spin_int_cb(GtkWidget *widget, gpointer data) | |
525 { | |
526 gint *var = data; | |
527 *var = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); | |
528 } | |
529 | |
530 GtkWidget *pref_spin_new_int(GtkWidget *parent_box, const gchar *text, const gchar *suffix, | |
531 gint min, gint max, gint step, | |
532 gint value, gint *value_var) | |
533 { | |
534 *value_var = value; | |
535 return pref_spin_new(parent_box, text, suffix, | |
536 (gdouble)min, (gdouble)max, (gdouble)step, 0, | |
537 value, | |
538 G_CALLBACK(pref_spin_int_cb), value_var); | |
539 } | |
540 | |
541 #if 0 | |
542 void pref_spin_set_blocking(GtkWidget *spin, gdouble value, gpointer block_data) | |
543 { | |
544 g_signal_handlers_block_matched(G_OBJECT(spin), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, block_data); | |
545 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), value); | |
546 g_signal_handlers_unblock_matched(G_OBJECT(spin), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, block_data); | |
547 } | |
548 #endif | |
549 | |
550 static void pref_link_sensitivity_cb(GtkWidget *watch, GtkStateType prev_state, gpointer data) | |
551 { | |
552 GtkWidget *widget = data; | |
553 | |
554 gtk_widget_set_sensitive(widget, GTK_WIDGET_IS_SENSITIVE(watch)); | |
555 } | |
556 | |
557 void pref_link_sensitivity(GtkWidget *widget, GtkWidget *watch) | |
558 { | |
559 g_signal_connect(G_OBJECT(watch), "state_changed", | |
560 G_CALLBACK(pref_link_sensitivity_cb), widget); | |
561 } | |
562 | |
563 void pref_signal_block_data(GtkWidget *widget, gpointer data) | |
564 { | |
565 g_signal_handlers_block_matched(widget, G_SIGNAL_MATCH_DATA, | |
566 0, 0, NULL, NULL, data); | |
567 } | |
568 | |
569 void pref_signal_unblock_data(GtkWidget *widget, gpointer data) | |
570 { | |
571 g_signal_handlers_unblock_matched(widget, G_SIGNAL_MATCH_DATA, | |
572 0, 0, NULL, NULL, data); | |
573 } | |
574 | |
575 GtkWidget *pref_table_new(GtkWidget *parent_box, gint columns, gint rows, | |
576 gint homogenious, gint fill) | |
577 { | |
578 GtkWidget *table; | |
579 | |
580 table = gtk_table_new(rows, columns, homogenious); | |
581 gtk_table_set_row_spacings(GTK_TABLE(table), PREF_PAD_GAP); | |
582 gtk_table_set_col_spacings(GTK_TABLE(table), PREF_PAD_SPACE); | |
583 | |
584 if (parent_box) | |
585 { | |
586 gtk_box_pack_start(GTK_BOX(parent_box), table, fill, fill, 0); | |
587 gtk_widget_show(table); | |
588 } | |
589 | |
590 return table; | |
591 } | |
592 | |
593 GtkWidget *pref_table_box(GtkWidget *table, gint column, gint row, | |
594 GtkOrientation orientation, const gchar *text) | |
595 { | |
596 GtkWidget *box; | |
597 GtkWidget *shell; | |
598 | |
599 if (text) | |
600 { | |
601 shell = gtk_vbox_new(FALSE, 0); | |
602 box = pref_group_new(shell, TRUE, text, orientation); | |
603 } | |
604 else | |
605 { | |
606 if (orientation == GTK_ORIENTATION_HORIZONTAL) | |
607 { | |
608 box = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
609 } | |
610 else | |
611 { | |
612 box = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
613 } | |
614 shell = box; | |
615 } | |
616 | |
617 gtk_table_attach(GTK_TABLE(table), shell, column, column + 1, row, row + 1, | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
618 GTK_EXPAND | GTK_FILL, 0, 0, 0); |
9 | 619 |
620 gtk_widget_show(shell); | |
621 | |
622 return box; | |
623 } | |
624 | |
625 GtkWidget *pref_table_label(GtkWidget *table, gint column, gint row, | |
626 const gchar *text, gfloat alignment) | |
627 { | |
628 GtkWidget *label; | |
629 GtkWidget *align; | |
630 | |
631 align = gtk_alignment_new(alignment, 0.50, 0.0, 0.0); | |
632 gtk_table_attach(GTK_TABLE(table), align, column, column + 1, row, row + 1, | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
633 GTK_FILL, 0, 0, 0); |
9 | 634 gtk_widget_show(align); |
635 label = gtk_label_new(text); | |
636 gtk_container_add(GTK_CONTAINER(align), label); | |
637 gtk_widget_show(label); | |
638 | |
639 return label; | |
640 } | |
641 | |
642 GtkWidget *pref_table_button(GtkWidget *table, gint column, gint row, | |
643 const gchar *stock_id, const gchar *text, gint hide_stock_text, | |
644 GCallback func, gpointer data) | |
645 { | |
646 GtkWidget *button; | |
647 | |
648 button = pref_button_new(NULL, stock_id, text, hide_stock_text, func, data); | |
649 gtk_table_attach(GTK_TABLE(table), button, column, column + 1, row, row + 1, | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
650 GTK_FILL, 0, 0, 0); |
9 | 651 gtk_widget_show(button); |
652 | |
653 return button; | |
654 } | |
655 | |
656 #if 0 | |
657 static GtkWidget *pref_table_checkbox(GtkWidget *table, gint column, gint row, | |
658 const gchar *text, gint active, | |
659 GCallback func, gpointer data) | |
660 { | |
661 GtkWidget *button; | |
662 | |
663 button = gtk_check_button_new_with_label(text); | |
664 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); | |
665 if (func) g_signal_connect(G_OBJECT(button), "clicked", func, data); | |
666 | |
667 gtk_table_attach(GTK_TABLE(table), button, column, column + 1, row, row + 1, | |
668 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
669 gtk_widget_show(button); | |
670 | |
671 return button; | |
672 } | |
673 #endif | |
674 | |
675 GtkWidget *pref_table_spin(GtkWidget *table, gint column, gint row, | |
676 const gchar *text, const gchar *suffix, | |
677 gdouble min, gdouble max, gdouble step, gint digits, | |
678 gdouble value, | |
679 GCallback func, gpointer data) | |
680 { | |
681 GtkWidget *spin; | |
682 GtkWidget *box; | |
683 GtkWidget *label; | |
684 | |
685 spin = gtk_spin_button_new_with_range(min, max, step); | |
686 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), digits); | |
687 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), value); | |
688 if (func) | |
689 { | |
690 g_signal_connect(G_OBJECT(spin), "value_changed", G_CALLBACK(func), data); | |
691 } | |
692 | |
693 if (text) | |
694 { | |
695 label = pref_table_label(table, column, row, text, 1.0); | |
696 pref_link_sensitivity(label, spin); | |
697 column++; | |
698 } | |
699 | |
700 if (suffix) | |
701 { | |
702 box = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
703 gtk_box_pack_start(GTK_BOX(box), spin, FALSE, FALSE, 0); | |
704 gtk_widget_show(spin); | |
705 | |
706 label = pref_label_new(box, suffix); | |
707 pref_link_sensitivity(label, spin); | |
708 } | |
709 else | |
710 { | |
711 box = spin; | |
712 } | |
713 | |
714 gtk_table_attach(GTK_TABLE(table), box, column, column + 1, row, row + 1, | |
715 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); | |
716 gtk_widget_show(box); | |
717 | |
718 return spin; | |
719 } | |
720 | |
721 static void pref_toolbar_destroy_cb(GtkWidget *widget, gpointer data) | |
722 { | |
723 GtkTooltips *tips = data; | |
724 | |
725 g_object_unref(G_OBJECT(tips)); | |
726 } | |
727 | |
728 GtkWidget *pref_toolbar_new(GtkWidget *parent_box, GtkToolbarStyle style) | |
729 { | |
730 GtkWidget *tbar; | |
731 GtkTooltips *tips; | |
732 | |
733 tbar = gtk_toolbar_new(); | |
734 gtk_toolbar_set_style(GTK_TOOLBAR(tbar), style); | |
735 | |
736 if (parent_box) | |
737 { | |
738 gtk_box_pack_start(GTK_BOX(parent_box), tbar, FALSE, FALSE, 0); | |
739 gtk_widget_show(tbar); | |
740 } | |
741 | |
742 tips = gtk_tooltips_new(); | |
88
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
743 |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
744 /* take ownership of tooltips */ |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
745 #ifdef GTK_OBJECT_FLOATING |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
746 /* GTK+ < 2.10 */ |
9 | 747 g_object_ref(G_OBJECT(tips)); |
88
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
748 gtk_object_sink(GTK_OBJECT(tips)); |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
749 #else |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
750 /* GTK+ >= 2.10 */ |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
751 g_object_ref_sink(G_OBJECT(tips)); |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
752 #endif |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
753 |
9 | 754 g_object_set_data(G_OBJECT(tbar), "tooltips", tips); |
755 g_signal_connect(G_OBJECT(tbar), "destroy", | |
756 G_CALLBACK(pref_toolbar_destroy_cb), tips); | |
757 | |
758 gtk_tooltips_enable(tips); | |
759 | |
760 return tbar; | |
761 } | |
762 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
763 GtkWidget *pref_toolbar_button(GtkWidget *toolbar, |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
764 const gchar *stock_id, const gchar *label, gint toggle, |
9 | 765 const gchar *description, |
766 GCallback func, gpointer data) | |
767 { | |
768 GtkWidget *item; | |
769 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
770 if (toggle) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
771 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
772 if (stock_id) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
773 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
774 item = GTK_WIDGET(gtk_toggle_tool_button_new_from_stock(stock_id)); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
775 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
776 else |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
777 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
778 item = GTK_WIDGET(gtk_toggle_tool_button_new()); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
779 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
780 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
781 else |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
782 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
783 if (stock_id) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
784 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
785 item = GTK_WIDGET(gtk_tool_button_new_from_stock(stock_id)); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
786 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
787 else |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
788 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
789 item = GTK_WIDGET(gtk_tool_button_new(NULL, NULL)); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
790 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
791 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
792 gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item), TRUE); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
793 |
9 | 794 if (label) gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), label); |
795 | |
796 if (func) g_signal_connect(item, "clicked", func, data); | |
797 gtk_container_add(GTK_CONTAINER(toolbar), item); | |
798 gtk_widget_show(item); | |
799 | |
800 if (description) | |
801 { | |
802 GtkTooltips *tips; | |
803 | |
804 tips = g_object_get_data(G_OBJECT(toolbar), "tooltips"); | |
805 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), tips, description, NULL); | |
806 } | |
807 | |
808 return item; | |
809 } | |
810 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
811 void pref_toolbar_button_set_icon(GtkWidget *button, GtkWidget *widget, const gchar *stock_id) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
812 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
813 if (widget) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
814 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
815 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), widget); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
816 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
817 else if (stock_id) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
818 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
819 gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(button), stock_id); |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
820 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
821 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
822 |
9 | 823 GtkWidget *pref_toolbar_spacer(GtkWidget *toolbar) |
824 { | |
825 GtkWidget *item; | |
826 | |
827 item = GTK_WIDGET(gtk_separator_tool_item_new()); | |
828 gtk_container_add(GTK_CONTAINER(toolbar), item); | |
829 gtk_widget_show(item); | |
830 | |
831 return item; | |
832 } | |
833 | |
834 | |
835 /* | |
836 *----------------------------------------------------------------------------- | |
837 * date selection entry | |
838 *----------------------------------------------------------------------------- | |
839 */ | |
840 | |
841 #define DATE_SELECION_KEY "date_selection_data" | |
842 | |
843 | |
844 typedef struct _DateSelection DateSelection; | |
845 struct _DateSelection | |
846 { | |
847 GtkWidget *box; | |
848 | |
849 GtkWidget *spin_d; | |
850 GtkWidget *spin_m; | |
851 GtkWidget *spin_y; | |
852 | |
853 GtkWidget *button; | |
854 | |
855 GtkWidget *window; | |
856 GtkWidget *calendar; | |
857 }; | |
858 | |
859 | |
860 static void date_selection_popup_hide(DateSelection *ds) | |
861 { | |
862 if (!ds->window) return; | |
863 | |
864 if (GTK_WIDGET_HAS_GRAB(ds->window)) | |
865 { | |
866 gtk_grab_remove(ds->window); | |
867 gdk_keyboard_ungrab(GDK_CURRENT_TIME); | |
868 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
869 } | |
870 | |
871 gtk_widget_hide(ds->window); | |
872 | |
873 gtk_widget_destroy(ds->window); | |
874 ds->window = NULL; | |
875 ds->calendar = NULL; | |
876 | |
877 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ds->button), FALSE); | |
878 } | |
879 | |
880 static gint date_selection_popup_release_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
881 { | |
882 DateSelection *ds = data; | |
883 | |
884 date_selection_popup_hide(ds); | |
885 return TRUE; | |
886 } | |
887 | |
888 static gint date_selection_popup_press_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
889 { | |
890 DateSelection *ds = data; | |
891 gint x, y; | |
892 gint w, h; | |
893 gint xr, yr; | |
894 | |
895 xr = (gint)event->x_root; | |
896 yr = (gint)event->y_root; | |
897 | |
898 gdk_window_get_origin(ds->window->window, &x, &y); | |
899 gdk_drawable_get_size(ds->window->window, &w, &h); | |
900 | |
901 if (xr < x || yr < y || xr > x + w || yr > y + h) | |
902 { | |
903 g_signal_connect(G_OBJECT(ds->window), "button_release_event", | |
904 G_CALLBACK(date_selection_popup_release_cb), ds); | |
905 return TRUE; | |
906 } | |
907 | |
908 return FALSE; | |
909 } | |
910 | |
911 static void date_selection_popup_sync(DateSelection *ds) | |
912 { | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
41
diff
changeset
|
913 guint day, month, year; |
9 | 914 |
915 gtk_calendar_get_date(GTK_CALENDAR(ds->calendar), &year, &month, &day); | |
916 date_selection_set(ds->box, day, month + 1, year); | |
917 } | |
918 | |
919 static gint date_selection_popup_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
920 { | |
921 DateSelection *ds = data; | |
922 | |
923 switch (event->keyval) | |
924 { | |
925 case GDK_Return: | |
926 case GDK_KP_Enter: | |
927 case GDK_Tab: | |
928 case GDK_ISO_Left_Tab: | |
929 date_selection_popup_sync(ds); | |
930 date_selection_popup_hide(ds); | |
931 break; | |
932 case GDK_Escape: | |
933 date_selection_popup_hide(ds); | |
934 break; | |
935 default: | |
936 break; | |
937 } | |
938 | |
939 return FALSE; | |
940 } | |
941 | |
942 static void date_selection_day_cb(GtkWidget *widget, gpointer data) | |
943 { | |
944 DateSelection *ds = data; | |
945 | |
946 date_selection_popup_sync(ds); | |
947 } | |
948 | |
949 static void date_selection_doubleclick_cb(GtkWidget *widget, gpointer data) | |
950 { | |
951 DateSelection *ds = data; | |
952 | |
953 date_selection_popup_hide(ds); | |
954 } | |
955 | |
956 static void date_selection_popup(DateSelection *ds) | |
957 { | |
958 gint x, y; | |
959 gint wx, wy; | |
960 gint day, month, year; | |
961 | |
962 if (ds->window) return; | |
963 | |
964 ds->window = gtk_window_new(GTK_WINDOW_POPUP); | |
965 gtk_window_set_resizable(GTK_WINDOW(ds->window), FALSE); | |
966 g_signal_connect(G_OBJECT(ds->window), "button_press_event", | |
967 G_CALLBACK(date_selection_popup_press_cb), ds); | |
968 g_signal_connect(G_OBJECT(ds->window), "key_press_event", | |
969 G_CALLBACK(date_selection_popup_keypress_cb), ds); | |
970 | |
971 ds->calendar = gtk_calendar_new(); | |
972 gtk_container_add(GTK_CONTAINER(ds->window), ds->calendar); | |
973 gtk_widget_show(ds->calendar); | |
974 | |
975 date_selection_get(ds->box, &day, &month, &year); | |
976 gtk_calendar_select_month(GTK_CALENDAR(ds->calendar), month - 1, year); | |
977 gtk_calendar_select_day(GTK_CALENDAR(ds->calendar), day); | |
978 | |
979 g_signal_connect(G_OBJECT(ds->calendar), "day_selected", | |
980 G_CALLBACK(date_selection_day_cb), ds); | |
981 g_signal_connect(G_OBJECT(ds->calendar), "day_selected_double_click", | |
982 G_CALLBACK(date_selection_doubleclick_cb), ds); | |
983 | |
984 gtk_widget_realize(ds->window); | |
985 | |
986 gdk_window_get_origin(ds->button->window, &wx, &wy); | |
987 | |
988 x = wx + ds->button->allocation.x + ds->button->allocation.width - ds->window->allocation.width; | |
989 y = wy + ds->button->allocation.y + ds->button->allocation.height; | |
990 | |
991 if (y + ds->window->allocation.height > gdk_screen_height()) | |
992 { | |
993 y = wy + ds->button->allocation.y - ds->window->allocation.height; | |
994 } | |
995 if (x < 0) x = 0; | |
996 if (y < 0) y = 0; | |
997 | |
998 gtk_window_move(GTK_WINDOW(ds->window), x, y); | |
999 gtk_widget_show(ds->window); | |
1000 | |
1001 gtk_widget_grab_focus(ds->calendar); | |
1002 gdk_pointer_grab(ds->window->window, TRUE, | |
1003 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, | |
1004 NULL, NULL, GDK_CURRENT_TIME); | |
1005 gdk_keyboard_grab(ds->window->window, TRUE, GDK_CURRENT_TIME); | |
1006 gtk_grab_add(ds->window); | |
1007 | |
1008 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ds->button), TRUE); | |
1009 } | |
1010 | |
1011 static void date_selection_button_cb(GtkWidget *widget, gpointer data) | |
1012 { | |
1013 DateSelection *ds = data; | |
1014 | |
1015 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ds->button)) == (!ds->window)) | |
1016 { | |
1017 date_selection_popup(ds); | |
1018 } | |
1019 } | |
1020 | |
1021 static void button_size_allocate_cb(GtkWidget *button, GtkAllocation *allocation, gpointer data) | |
1022 { | |
1023 GtkWidget *spin = data; | |
1024 | |
1025 if (allocation->height > spin->requisition.height) | |
1026 { | |
1027 GtkAllocation button_allocation; | |
1028 | |
1029 button_allocation = button->allocation; | |
1030 button_allocation.height = spin->requisition.height; | |
1031 button_allocation.y = spin->allocation.y + | |
1032 (spin->allocation.height - spin->requisition.height) / 2; | |
1033 gtk_widget_size_allocate(button, &button_allocation); | |
1034 } | |
1035 } | |
1036 | |
1037 static void spin_increase(GtkWidget *spin, gint value) | |
1038 { | |
1039 GtkRequisition req; | |
1040 | |
1041 gtk_widget_size_request(spin, &req); | |
1042 gtk_widget_set_size_request(spin, req.width + value, -1); | |
1043 } | |
1044 | |
1045 static void date_selection_destroy_cb(GtkWidget *widget, gpointer data) | |
1046 { | |
1047 DateSelection *ds = data; | |
1048 | |
1049 date_selection_popup_hide(ds); | |
1050 | |
1051 g_free(ds); | |
1052 } | |
1053 | |
1054 GtkWidget *date_selection_new(void) | |
1055 { | |
1056 DateSelection *ds; | |
1057 GtkWidget *arrow; | |
1058 | |
1059 ds = g_new0(DateSelection, 1); | |
1060 | |
1061 ds->box = gtk_hbox_new(FALSE, 2); | |
1062 g_signal_connect(G_OBJECT(ds->box), "destroy", | |
1063 G_CALLBACK(date_selection_destroy_cb), ds); | |
1064 | |
1065 /* FIXME: use option menu with text format of month instead of a spin button */ | |
1066 ds->spin_m = pref_spin_new(ds->box, NULL, NULL, 1, 12, 1, 0, 1, NULL, NULL); | |
1067 ds->spin_d = pref_spin_new(ds->box, NULL, NULL, 1, 31, 1, 0, 1, NULL, NULL); | |
1068 ds->spin_y = pref_spin_new(ds->box, NULL, NULL, 1900, 9999, 1, 0, 1900, NULL, NULL); | |
1069 spin_increase(ds->spin_y, 5); | |
1070 | |
1071 ds->button = gtk_toggle_button_new(); | |
1072 g_signal_connect(G_OBJECT(ds->button), "size_allocate", | |
1073 G_CALLBACK(button_size_allocate_cb), ds->spin_y); | |
1074 | |
1075 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); | |
1076 gtk_container_add(GTK_CONTAINER(ds->button), arrow); | |
1077 gtk_widget_show(arrow); | |
1078 | |
1079 gtk_box_pack_start(GTK_BOX(ds->box), ds->button, FALSE, FALSE, 0); | |
1080 g_signal_connect(G_OBJECT(ds->button), "clicked", | |
1081 G_CALLBACK(date_selection_button_cb), ds); | |
1082 gtk_widget_show(ds->button); | |
1083 | |
1084 g_object_set_data(G_OBJECT(ds->box), DATE_SELECION_KEY, ds); | |
1085 | |
1086 return ds->box; | |
1087 } | |
442 | 1088 |
9 | 1089 void date_selection_set(GtkWidget *widget, gint day, gint month, gint year) |
1090 { | |
1091 DateSelection *ds; | |
1092 | |
1093 ds = g_object_get_data(G_OBJECT(widget), DATE_SELECION_KEY); | |
1094 if (!ds) return; | |
1095 | |
1096 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ds->spin_d), (gdouble)day); | |
1097 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ds->spin_m), (gdouble)month); | |
1098 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ds->spin_y), (gdouble)year); | |
1099 } | |
1100 | |
1101 | |
1102 void date_selection_get(GtkWidget *widget, gint *day, gint *month, gint *year) | |
1103 { | |
1104 DateSelection *ds; | |
1105 | |
1106 ds = g_object_get_data(G_OBJECT(widget), DATE_SELECION_KEY); | |
1107 if (!ds) return; | |
1108 | |
1109 if (day) *day = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ds->spin_d)); | |
1110 if (month) *month = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ds->spin_m)); | |
1111 if (year) *year = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ds->spin_y)); | |
1112 } | |
442 | 1113 |
9 | 1114 void date_selection_time_set(GtkWidget *widget, time_t t) |
1115 { | |
1116 struct tm *lt; | |
1117 | |
1118 lt = localtime(&t); | |
1119 if (!lt) return; | |
1120 | |
1121 date_selection_set(widget, lt->tm_mday, lt->tm_mon + 1, lt->tm_year + 1900); | |
1122 } | |
1123 | |
1124 time_t date_selection_time_get(GtkWidget *widget) | |
1125 { | |
1126 struct tm lt; | |
1127 gint day = 0; | |
1128 gint month = 0; | |
1129 gint year = 0; | |
1130 | |
1131 date_selection_get(widget, &day, &month ,&year); | |
1132 | |
1133 lt.tm_sec = 0; | |
1134 lt.tm_min = 0; | |
1135 lt.tm_hour = 0; | |
1136 lt.tm_mday = day; | |
1137 lt.tm_mon = month - 1; | |
1138 lt.tm_year = year - 1900; | |
1139 lt.tm_isdst = 0; | |
1140 | |
1141 return mktime(<); | |
1142 } | |
1143 | |
1144 | |
1145 /* | |
1146 *----------------------------------------------------------------------------- | |
1147 * Sizer, without using a GtkPaned | |
1148 *----------------------------------------------------------------------------- | |
1149 */ | |
1150 | |
1151 #define SIZER_DATA_KEY "sizer_data" | |
1152 | |
1153 typedef struct _SizerData SizerData; | |
1154 struct _SizerData | |
1155 { | |
1156 GtkWidget *sizer; | |
1157 GtkWidget *parent; | |
1158 GtkWidget *bounding_widget; | |
1159 SizerPositionType position; | |
1160 | |
1161 gint hsize_min; | |
1162 gint hsize_max; | |
1163 gint vsize_min; | |
1164 gint vsize_max; | |
1165 | |
1166 gint in_drag; | |
1167 gint press_x; | |
1168 gint press_y; | |
1169 gint press_width; | |
1170 gint press_height; | |
1171 | |
1172 gint handle_prelit; | |
1173 }; | |
1174 | |
1175 | |
1176 static gint sizer_default_handle_size(void) | |
1177 { | |
1178 gint handle_size = 5; | |
1179 GtkWidget *paned; | |
1180 GtkStyle *style; | |
1181 | |
1182 paned = gtk_hpaned_new(); | |
1183 | |
1184 style = gtk_rc_get_style(paned); | |
1185 gtk_widget_set_style(paned, style); | |
1186 gtk_widget_style_get(paned, "handle_size", &handle_size, NULL); | |
1187 | |
1188 gtk_widget_destroy(paned); | |
1189 | |
1190 return handle_size; | |
1191 } | |
1192 | |
1193 static gint sizer_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1194 { | |
1195 SizerData *sd = data; | |
1196 gint x, y; | |
1197 gint w, h; | |
1198 | |
1199 if (!sd->in_drag) return FALSE; | |
1200 | |
1201 x = sd->press_x - bevent->x_root; | |
1202 y = sd->press_y - bevent->y_root; | |
1203 | |
1204 w = sd->press_width; | |
1205 h = sd->press_height; | |
1206 | |
1207 if (sd->position & SIZER_POS_LEFT) | |
1208 { | |
1209 w += x; | |
1210 } | |
1211 else if (sd->position & SIZER_POS_RIGHT) | |
1212 { | |
1213 w -= x; | |
1214 } | |
1215 | |
1216 if (sd->position & SIZER_POS_TOP) | |
1217 { | |
1218 h += y; | |
1219 } | |
1220 else if (sd->position & SIZER_POS_BOTTOM) | |
1221 { | |
1222 h -= y; | |
1223 } | |
1224 | |
1225 if (sd->hsize_min >= 0) w = MAX(w, sd->hsize_min); | |
1226 if (sd->vsize_min >= 0) h = MAX(h, sd->vsize_min); | |
1227 | |
1228 if (sd->bounding_widget) | |
1229 { | |
1230 w = CLAMP(w, sd->sizer->allocation.width, sd->bounding_widget->allocation.width); | |
1231 h = CLAMP(h, sd->sizer->allocation.height, sd->bounding_widget->allocation.height); | |
1232 } | |
1233 else | |
1234 { | |
1235 if (w < sd->sizer->allocation.width) w = sd->sizer->allocation.width; | |
1236 if (h < sd->sizer->allocation.height) h = sd->sizer->allocation.height; | |
1237 } | |
1238 | |
1239 if (sd->hsize_max >= 0) w = MIN(w, sd->hsize_max); | |
1240 if (sd->vsize_max >= 0) h = MIN(h, sd->vsize_max); | |
1241 | |
1242 if (w == sd->parent->allocation.width) w = -1; | |
1243 if (h == sd->parent->allocation.height) h = -1; | |
1244 | |
1245 if (w > 0 || h > 0) gtk_widget_set_size_request(sd->parent, w, h); | |
1246 | |
1247 return TRUE; | |
1248 } | |
1249 | |
1250 static gint sizer_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1251 { | |
1252 SizerData *sd = data; | |
1253 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
1254 if (bevent->button != MOUSE_BUTTON_LEFT) return FALSE; |
9 | 1255 |
1256 sd->in_drag = TRUE; | |
1257 sd->press_x = bevent->x_root; | |
1258 sd->press_y = bevent->y_root; | |
1259 | |
1260 sd->press_width = sd->parent->allocation.width; | |
1261 sd->press_height = sd->parent->allocation.height; | |
1262 | |
1263 gdk_pointer_grab(sd->sizer->window, FALSE, | |
1264 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, | |
1265 NULL, NULL, bevent->time); | |
1266 gtk_grab_add(sd->sizer); | |
1267 | |
1268 return TRUE; | |
1269 } | |
1270 | |
1271 static gint sizer_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1272 { | |
1273 SizerData *sd = data; | |
1274 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
1275 if (bevent->button != MOUSE_BUTTON_LEFT) return FALSE; |
9 | 1276 |
1277 if (gdk_pointer_is_grabbed() && GTK_WIDGET_HAS_GRAB(sd->sizer)) | |
1278 { | |
1279 gtk_grab_remove(sd->sizer); | |
1280 gdk_pointer_ungrab(bevent->time); | |
1281 } | |
1282 | |
1283 sd->in_drag = FALSE; | |
1284 | |
1285 return TRUE; | |
1286 } | |
1287 | |
1288 static void sizer_set_prelight(SizerData *sd, gint prelit) | |
1289 { | |
1290 sd->handle_prelit = prelit; | |
1291 gtk_widget_queue_draw_area(sd->sizer, 0, 0, | |
1292 sd->sizer->allocation.width, sd->sizer->allocation.height); | |
1293 } | |
1294 | |
1295 static gint sizer_enter_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) | |
1296 { | |
1297 SizerData *sd = data; | |
1298 | |
1299 sizer_set_prelight(sd, TRUE); | |
1300 return TRUE; | |
1301 } | |
1302 | |
1303 static gint sizer_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) | |
1304 { | |
1305 SizerData *sd = data; | |
1306 | |
1307 sizer_set_prelight(sd, FALSE); | |
1308 return TRUE; | |
1309 } | |
1310 | |
1311 static gint sizer_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data) | |
1312 { | |
1313 SizerData *sd = data; | |
1314 GdkRectangle clip; | |
1315 GtkOrientation orientation; | |
1316 GtkStateType state; | |
1317 | |
1318 gdk_region_get_clipbox(event->region, &clip); | |
1319 | |
1320 if (sd->position & SIZER_POS_LEFT || sd->position & SIZER_POS_RIGHT) | |
1321 { | |
1322 orientation = GTK_ORIENTATION_VERTICAL; | |
1323 } | |
1324 else | |
1325 { | |
1326 orientation = GTK_ORIENTATION_HORIZONTAL; | |
1327 } | |
1328 | |
1329 if (sd->handle_prelit) | |
1330 { | |
1331 state = GTK_STATE_PRELIGHT; | |
1332 } | |
1333 else | |
1334 { | |
1335 state = widget->state; | |
1336 } | |
1337 | |
1338 gtk_paint_handle(widget->style, widget->window, state, | |
1339 GTK_SHADOW_NONE, &clip, widget, "paned", | |
1340 0, 0, | |
1341 widget->allocation.width, widget->allocation.height, | |
1342 orientation); | |
1343 | |
1344 return TRUE; | |
1345 } | |
1346 | |
1347 static void sizer_realize_cb(GtkWidget *widget, gpointer data) | |
1348 { | |
1349 SizerData *sd = data; | |
1350 GdkCursorType n; | |
1351 | |
1352 n = 0; | |
1353 if (sd->position & SIZER_POS_TOP || sd->position & SIZER_POS_BOTTOM) | |
1354 { | |
1355 n = GDK_SB_V_DOUBLE_ARROW; | |
1356 } | |
1357 if (sd->position & SIZER_POS_LEFT || sd->position & SIZER_POS_RIGHT) | |
1358 { | |
1359 n = (n != 0) ? GDK_FLEUR : GDK_SB_H_DOUBLE_ARROW; | |
1360 } | |
1361 | |
1362 if (n != 0 && widget->window) | |
1363 { | |
1364 GdkCursor *cursor; | |
1365 cursor = gdk_cursor_new(n); | |
1366 gdk_window_set_cursor(widget->window, cursor); | |
1367 gdk_cursor_unref(cursor); | |
1368 } | |
1369 } | |
1370 | |
1371 static void sizer_destroy_cb(GtkWidget *widget, gpointer data) | |
1372 { | |
1373 SizerData *sd = data; | |
1374 | |
1375 g_free(sd); | |
1376 } | |
1377 | |
1378 GtkWidget *sizer_new(GtkWidget *parent, GtkWidget *bounding_widget, | |
1379 SizerPositionType position) | |
1380 { | |
1381 SizerData *sd; | |
1382 gint handle_size; | |
1383 | |
1384 sd = g_new0(SizerData, 1); | |
1385 | |
1386 sd->sizer = gtk_event_box_new(); | |
1387 sd->parent = parent; | |
1388 sd->bounding_widget = bounding_widget; | |
1389 sd->position = position; | |
1390 sd->hsize_min = -1; | |
1391 sd->hsize_max = -1; | |
1392 sd->vsize_min = -1; | |
1393 sd->vsize_max = -1; | |
1394 | |
1395 sd->in_drag = FALSE; | |
1396 sd->handle_prelit = FALSE; | |
1397 | |
1398 g_signal_connect(G_OBJECT(sd->sizer), "destroy", | |
1399 G_CALLBACK(sizer_destroy_cb), sd); | |
1400 | |
1401 g_signal_connect(G_OBJECT(sd->sizer), "motion_notify_event", | |
1402 G_CALLBACK(sizer_motion_cb), sd); | |
1403 g_signal_connect(G_OBJECT(sd->sizer), "button_press_event", | |
1404 G_CALLBACK(sizer_press_cb), sd); | |
1405 g_signal_connect(G_OBJECT(sd->sizer), "button_release_event", | |
1406 G_CALLBACK(sizer_release_cb), sd); | |
1407 | |
1408 g_signal_connect(G_OBJECT(sd->sizer), "enter_notify_event", | |
1409 G_CALLBACK(sizer_enter_cb), sd); | |
1410 g_signal_connect(G_OBJECT(sd->sizer), "leave_notify_event", | |
1411 G_CALLBACK(sizer_leave_cb), sd); | |
1412 | |
1413 gtk_widget_set_events(sd->sizer, GDK_POINTER_MOTION_MASK | | |
1414 GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | | |
1415 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); | |
1416 | |
1417 g_signal_connect(sd->sizer, "realize", | |
1418 G_CALLBACK(sizer_realize_cb), sd); | |
1419 g_signal_connect(sd->sizer, "expose_event", | |
1420 G_CALLBACK(sizer_expose_cb), sd); | |
1421 | |
1422 handle_size = sizer_default_handle_size(); | |
1423 | |
1424 gtk_widget_set_size_request(sd->sizer, handle_size, handle_size); | |
1425 #if 0 | |
1426 /* use this if you add a shadow border to the handle */ | |
1427 gtk_widget_set_size_request(sd->sizer, handle_size + sd->sizer->style->xthickness * 2, | |
1428 handle_size + sd->sizer->style->ythickness * 2); | |
1429 #endif | |
1430 | |
1431 g_object_set_data(G_OBJECT(sd->sizer), SIZER_DATA_KEY,sd); | |
1432 | |
1433 return sd->sizer; | |
1434 } | |
1435 | |
1436 void sizer_set_limits(GtkWidget *sizer, | |
1437 gint hsize_min, gint hsize_max, | |
1438 gint vsize_min, gint vsize_max) | |
1439 { | |
1440 SizerData *sd; | |
1441 | |
1442 sd = g_object_get_data(G_OBJECT(sizer), SIZER_DATA_KEY); | |
1443 if (!sd) return; | |
1444 | |
1445 sd->hsize_min = hsize_min; | |
1446 sd->hsize_max = hsize_max; | |
1447 sd->vsize_min = vsize_min; | |
1448 sd->vsize_max = vsize_max; | |
1449 } | |
1450 | |
1451 | |
1452 /* | |
1453 *----------------------------------------------------------------------------- | |
1454 * storing data in a history list with key,data pairs | |
1455 *----------------------------------------------------------------------------- | |
1456 */ | |
1457 | |
1458 #define PREF_LIST_MARKER_INT "[INT]:" | |
1459 #define PREF_LIST_MARKER_DOUBLE "[DOUBLE]:" | |
1460 #define PREF_LIST_MARKER_STRING "[STRING]:" | |
1461 | |
1462 static GList *pref_list_find(const gchar *group, const gchar *token) | |
1463 { | |
1464 GList *work; | |
1465 gint l; | |
1466 | |
1467 l = strlen(token); | |
1468 | |
1469 work = history_list_get_by_key(group); | |
1470 while (work) | |
1471 { | |
1472 const gchar *text = work->data; | |
1473 | |
1474 if (strncmp(text, token, l) == 0) return work; | |
1475 | |
1476 work = work->next; | |
1477 } | |
1478 | |
1479 return NULL; | |
1480 } | |
1481 | |
1482 static gint pref_list_get(const gchar *group, const gchar *key, const gchar *marker, const gchar **result) | |
1483 { | |
1484 gchar *token; | |
1485 GList *work; | |
1486 gint ret; | |
1487 | |
1488 if (!group || !key || !marker) | |
1489 { | |
1490 *result = NULL; | |
1491 return FALSE; | |
1492 } | |
1493 | |
1494 token = g_strconcat(key, marker, NULL); | |
1495 | |
1496 work = pref_list_find(group, token); | |
1497 if (work) | |
1498 { | |
1499 *result = (const gchar *)work->data + strlen(token); | |
1500 if (strlen(*result) == 0) *result = NULL; | |
1501 ret = TRUE; | |
1502 } | |
1503 else | |
1504 { | |
1505 *result = NULL; | |
1506 ret = FALSE; | |
1507 } | |
1508 | |
1509 g_free(token); | |
1510 | |
442 | 1511 return ret; |
9 | 1512 } |
1513 | |
1514 static void pref_list_set(const gchar *group, const gchar *key, const gchar *marker, const gchar *text) | |
1515 { | |
1516 gchar *token; | |
1517 gchar *path; | |
1518 GList *work; | |
1519 | |
1520 if (!group || !key || !marker) return; | |
1521 | |
1522 token = g_strconcat(key, marker, NULL); | |
1523 path = g_strconcat(token, text, NULL); | |
1524 | |
1525 work = pref_list_find(group, token); | |
1526 if (work) | |
1527 { | |
1528 gchar *old_path = work->data; | |
1529 | |
1530 if (text) | |
1531 { | |
1532 work->data = path; | |
1533 path = NULL; | |
1534 | |
1535 g_free(old_path); | |
1536 } | |
1537 else | |
1538 { | |
1539 history_list_item_remove(group, old_path); | |
1540 } | |
1541 } | |
1542 else if (text) | |
1543 { | |
1544 history_list_add_to_key(group, path, 0); | |
1545 } | |
1546 | |
1547 g_free(path); | |
1548 g_free(token); | |
1549 } | |
1550 | |
1551 void pref_list_int_set(const gchar *group, const gchar *key, gint value) | |
1552 { | |
1553 gchar *text; | |
1554 | |
1555 text = g_strdup_printf("%d", value); | |
1556 pref_list_set(group, key, PREF_LIST_MARKER_INT, text); | |
1557 g_free(text); | |
1558 } | |
1559 | |
1560 gint pref_list_int_get(const gchar *group, const gchar *key, gint *result) | |
1561 { | |
1562 const gchar *text; | |
1563 | |
1564 if (!group || !key) | |
1565 { | |
1566 *result = 0; | |
1567 return FALSE; | |
1568 } | |
1569 | |
1570 if (pref_list_get(group, key, PREF_LIST_MARKER_INT, &text) && text) | |
1571 { | |
1572 *result = (gint)strtol(text, NULL, 10); | |
1573 return TRUE; | |
1574 } | |
1575 | |
1576 *result = 0; | |
1577 return FALSE; | |
1578 } | |
1579 | |
1580 void pref_list_double_set(const gchar *group, const gchar *key, gdouble value) | |
1581 { | |
1582 gchar text[G_ASCII_DTOSTR_BUF_SIZE]; | |
1583 | |
1584 g_ascii_dtostr(text, sizeof(text), value); | |
1585 pref_list_set(group, key, PREF_LIST_MARKER_DOUBLE, text); | |
1586 } | |
1587 | |
1588 gint pref_list_double_get(const gchar *group, const gchar *key, gdouble *result) | |
1589 { | |
1590 const gchar *text; | |
1591 | |
1592 if (!group || !key) | |
1593 { | |
1594 *result = 0; | |
1595 return FALSE; | |
1596 } | |
1597 | |
1598 if (pref_list_get(group, key, PREF_LIST_MARKER_DOUBLE, &text) && text) | |
1599 { | |
1600 *result = g_ascii_strtod(text, NULL); | |
1601 return TRUE; | |
1602 } | |
1603 | |
1604 *result = 0; | |
1605 return FALSE; | |
1606 } | |
1607 | |
1608 void pref_list_string_set(const gchar *group, const gchar *key, const gchar *value) | |
1609 { | |
1610 pref_list_set(group, key, PREF_LIST_MARKER_STRING, value); | |
1611 } | |
1612 | |
1613 gint pref_list_string_get(const gchar *group, const gchar *key, const gchar **result) | |
1614 { | |
1615 return pref_list_get(group, key, PREF_LIST_MARKER_STRING, result); | |
1616 } | |
1617 | |
1618 | |
339
de1c2cd06fce
Rename user_specified_window_background and window_background_color
zas_
parents:
208
diff
changeset
|
1619 void pref_color_button_set_cb(GtkWidget *widget, gpointer data) |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1620 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1621 GdkColor *color = data; |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1622 |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1623 gtk_color_button_get_color(GTK_COLOR_BUTTON(widget), color); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1624 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1625 |
339
de1c2cd06fce
Rename user_specified_window_background and window_background_color
zas_
parents:
208
diff
changeset
|
1626 GtkWidget *pref_color_button_new(GtkWidget *parent_box, |
de1c2cd06fce
Rename user_specified_window_background and window_background_color
zas_
parents:
208
diff
changeset
|
1627 const gchar *title, const GdkColor *color, |
de1c2cd06fce
Rename user_specified_window_background and window_background_color
zas_
parents:
208
diff
changeset
|
1628 GCallback func, gpointer data) |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1629 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1630 GtkWidget *button; |
442 | 1631 |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1632 if (color) |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1633 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1634 button = gtk_color_button_new_with_color(color); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1635 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1636 else |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1637 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1638 button = gtk_color_button_new(); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1639 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1640 |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1641 if (func) g_signal_connect(G_OBJECT(button), "color-set", func, data); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1642 |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1643 if (title) |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1644 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1645 GtkWidget *label; |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1646 GtkWidget *hbox; |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1647 |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1648 gtk_color_button_set_title(GTK_COLOR_BUTTON(button), title); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1649 label = gtk_label_new(title); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1650 |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1651 hbox = gtk_hbox_new(TRUE, 0); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1652 gtk_box_pack_start(GTK_BOX(parent_box), hbox, TRUE, TRUE, 0); |
442 | 1653 |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1654 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1655 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1656 |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1657 gtk_widget_show_all(hbox); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1658 } |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1659 else |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1660 { |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1661 gtk_widget_show(button); |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1662 } |
442 | 1663 |
208
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1664 return button; |
fa0e05f985c3
set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents:
113
diff
changeset
|
1665 } |