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