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