Mercurial > geeqie.yaz
annotate src/ui_misc.c @ 101:847e4bc6b54c
Tue Nov 7 15:35:59 2006 John Ellis <johne@verizon.net>
* exif.c: Use new format_raw_exif_offset() function to find Exif in
raw files.
* filelist.c: Add orf and pef to displayed file types.
* format_canon.h, format_fuji.h: Update to new #define format.
* format_fuji.c: Use same offset for Exif as the jpeg image as the
Exif is always embedded in the jpeg and assuming offset of 12 is
just broken.
* format_nikon.h: Update to new #define format, and add pentax here
as finding the jpeg will be same code.
* format_olympus.[ch]: Support Olympus raw files with embedded jpegs,
not all raw files will have a jpeg, but all appear to have Exif tags.
* format_raw.[ch]: Add new camera types, and add a debugging facility
to easily list all tags within tiff files (see format_raw.h to enable).
author | gqview |
---|---|
date | Tue, 07 Nov 2006 21:00:50 +0000 |
parents | 2099ee3f9a8d |
children | 55166d93498d |
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(); | |
88
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
741 |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
742 /* take ownership of tooltips */ |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
743 #ifdef GTK_OBJECT_FLOATING |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
744 /* GTK+ < 2.10 */ |
9 | 745 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
|
746 gtk_object_sink(GTK_OBJECT(tips)); |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
747 #else |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
748 /* GTK+ >= 2.10 */ |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
749 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
|
750 #endif |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
751 |
9 | 752 g_object_set_data(G_OBJECT(tbar), "tooltips", tips); |
753 g_signal_connect(G_OBJECT(tbar), "destroy", | |
754 G_CALLBACK(pref_toolbar_destroy_cb), tips); | |
755 | |
756 gtk_tooltips_enable(tips); | |
757 | |
758 return tbar; | |
759 } | |
760 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
761 GtkWidget *pref_toolbar_button(GtkWidget *toolbar, |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
762 const gchar *stock_id, const gchar *label, gint toggle, |
9 | 763 const gchar *description, |
764 GCallback func, gpointer data) | |
765 { | |
766 GtkWidget *item; | |
767 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
768 if (toggle) |
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 if (stock_id) |
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 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
|
773 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
774 else |
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 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
|
777 } |
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 else |
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 if (stock_id) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
782 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
783 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
|
784 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
785 else |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
786 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
787 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
|
788 } |
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 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
|
791 |
9 | 792 if (label) gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), label); |
793 | |
794 if (func) g_signal_connect(item, "clicked", func, data); | |
795 gtk_container_add(GTK_CONTAINER(toolbar), item); | |
796 gtk_widget_show(item); | |
797 | |
798 if (description) | |
799 { | |
800 GtkTooltips *tips; | |
801 | |
802 tips = g_object_get_data(G_OBJECT(toolbar), "tooltips"); | |
803 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), tips, description, NULL); | |
804 } | |
805 | |
806 return item; | |
807 } | |
808 | |
41
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
809 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
|
810 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
811 if (widget) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
812 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
813 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
|
814 } |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
815 else if (stock_id) |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
816 { |
6281cc38e5ca
Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
817 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
|
818 } |
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 |
9 | 821 GtkWidget *pref_toolbar_spacer(GtkWidget *toolbar) |
822 { | |
823 GtkWidget *item; | |
824 | |
825 item = GTK_WIDGET(gtk_separator_tool_item_new()); | |
826 gtk_container_add(GTK_CONTAINER(toolbar), item); | |
827 gtk_widget_show(item); | |
828 | |
829 return item; | |
830 } | |
831 | |
832 | |
833 /* | |
834 *----------------------------------------------------------------------------- | |
835 * date selection entry | |
836 *----------------------------------------------------------------------------- | |
837 */ | |
838 | |
839 #define DATE_SELECION_KEY "date_selection_data" | |
840 | |
841 | |
842 typedef struct _DateSelection DateSelection; | |
843 struct _DateSelection | |
844 { | |
845 GtkWidget *box; | |
846 | |
847 GtkWidget *spin_d; | |
848 GtkWidget *spin_m; | |
849 GtkWidget *spin_y; | |
850 | |
851 GtkWidget *button; | |
852 | |
853 GtkWidget *window; | |
854 GtkWidget *calendar; | |
855 }; | |
856 | |
857 | |
858 static void date_selection_popup_hide(DateSelection *ds) | |
859 { | |
860 if (!ds->window) return; | |
861 | |
862 if (GTK_WIDGET_HAS_GRAB(ds->window)) | |
863 { | |
864 gtk_grab_remove(ds->window); | |
865 gdk_keyboard_ungrab(GDK_CURRENT_TIME); | |
866 gdk_pointer_ungrab(GDK_CURRENT_TIME); | |
867 } | |
868 | |
869 gtk_widget_hide(ds->window); | |
870 | |
871 gtk_widget_destroy(ds->window); | |
872 ds->window = NULL; | |
873 ds->calendar = NULL; | |
874 | |
875 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ds->button), FALSE); | |
876 } | |
877 | |
878 static gint date_selection_popup_release_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
879 { | |
880 DateSelection *ds = data; | |
881 | |
882 date_selection_popup_hide(ds); | |
883 return TRUE; | |
884 } | |
885 | |
886 static gint date_selection_popup_press_cb(GtkWidget *widget, GdkEventButton *event, gpointer data) | |
887 { | |
888 DateSelection *ds = data; | |
889 gint x, y; | |
890 gint w, h; | |
891 gint xr, yr; | |
892 | |
893 xr = (gint)event->x_root; | |
894 yr = (gint)event->y_root; | |
895 | |
896 gdk_window_get_origin(ds->window->window, &x, &y); | |
897 gdk_drawable_get_size(ds->window->window, &w, &h); | |
898 | |
899 if (xr < x || yr < y || xr > x + w || yr > y + h) | |
900 { | |
901 g_signal_connect(G_OBJECT(ds->window), "button_release_event", | |
902 G_CALLBACK(date_selection_popup_release_cb), ds); | |
903 return TRUE; | |
904 } | |
905 | |
906 return FALSE; | |
907 } | |
908 | |
909 static void date_selection_popup_sync(DateSelection *ds) | |
910 { | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
41
diff
changeset
|
911 guint day, month, year; |
9 | 912 |
913 gtk_calendar_get_date(GTK_CALENDAR(ds->calendar), &year, &month, &day); | |
914 date_selection_set(ds->box, day, month + 1, year); | |
915 } | |
916 | |
917 static gint date_selection_popup_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
918 { | |
919 DateSelection *ds = data; | |
920 | |
921 switch (event->keyval) | |
922 { | |
923 case GDK_Return: | |
924 case GDK_KP_Enter: | |
925 case GDK_Tab: | |
926 case GDK_ISO_Left_Tab: | |
927 date_selection_popup_sync(ds); | |
928 date_selection_popup_hide(ds); | |
929 break; | |
930 case GDK_Escape: | |
931 date_selection_popup_hide(ds); | |
932 break; | |
933 default: | |
934 break; | |
935 } | |
936 | |
937 return FALSE; | |
938 } | |
939 | |
940 static void date_selection_day_cb(GtkWidget *widget, gpointer data) | |
941 { | |
942 DateSelection *ds = data; | |
943 | |
944 date_selection_popup_sync(ds); | |
945 } | |
946 | |
947 static void date_selection_doubleclick_cb(GtkWidget *widget, gpointer data) | |
948 { | |
949 DateSelection *ds = data; | |
950 | |
951 date_selection_popup_hide(ds); | |
952 } | |
953 | |
954 static void date_selection_popup(DateSelection *ds) | |
955 { | |
956 gint x, y; | |
957 gint wx, wy; | |
958 gint day, month, year; | |
959 | |
960 if (ds->window) return; | |
961 | |
962 ds->window = gtk_window_new(GTK_WINDOW_POPUP); | |
963 gtk_window_set_resizable(GTK_WINDOW(ds->window), FALSE); | |
964 g_signal_connect(G_OBJECT(ds->window), "button_press_event", | |
965 G_CALLBACK(date_selection_popup_press_cb), ds); | |
966 g_signal_connect(G_OBJECT(ds->window), "key_press_event", | |
967 G_CALLBACK(date_selection_popup_keypress_cb), ds); | |
968 | |
969 ds->calendar = gtk_calendar_new(); | |
970 gtk_container_add(GTK_CONTAINER(ds->window), ds->calendar); | |
971 gtk_widget_show(ds->calendar); | |
972 | |
973 date_selection_get(ds->box, &day, &month, &year); | |
974 gtk_calendar_select_month(GTK_CALENDAR(ds->calendar), month - 1, year); | |
975 gtk_calendar_select_day(GTK_CALENDAR(ds->calendar), day); | |
976 | |
977 g_signal_connect(G_OBJECT(ds->calendar), "day_selected", | |
978 G_CALLBACK(date_selection_day_cb), ds); | |
979 g_signal_connect(G_OBJECT(ds->calendar), "day_selected_double_click", | |
980 G_CALLBACK(date_selection_doubleclick_cb), ds); | |
981 | |
982 gtk_widget_realize(ds->window); | |
983 | |
984 gdk_window_get_origin(ds->button->window, &wx, &wy); | |
985 | |
986 x = wx + ds->button->allocation.x + ds->button->allocation.width - ds->window->allocation.width; | |
987 y = wy + ds->button->allocation.y + ds->button->allocation.height; | |
988 | |
989 if (y + ds->window->allocation.height > gdk_screen_height()) | |
990 { | |
991 y = wy + ds->button->allocation.y - ds->window->allocation.height; | |
992 } | |
993 if (x < 0) x = 0; | |
994 if (y < 0) y = 0; | |
995 | |
996 gtk_window_move(GTK_WINDOW(ds->window), x, y); | |
997 gtk_widget_show(ds->window); | |
998 | |
999 gtk_widget_grab_focus(ds->calendar); | |
1000 gdk_pointer_grab(ds->window->window, TRUE, | |
1001 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, | |
1002 NULL, NULL, GDK_CURRENT_TIME); | |
1003 gdk_keyboard_grab(ds->window->window, TRUE, GDK_CURRENT_TIME); | |
1004 gtk_grab_add(ds->window); | |
1005 | |
1006 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ds->button), TRUE); | |
1007 } | |
1008 | |
1009 static void date_selection_button_cb(GtkWidget *widget, gpointer data) | |
1010 { | |
1011 DateSelection *ds = data; | |
1012 | |
1013 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ds->button)) == (!ds->window)) | |
1014 { | |
1015 date_selection_popup(ds); | |
1016 } | |
1017 } | |
1018 | |
1019 static void button_size_allocate_cb(GtkWidget *button, GtkAllocation *allocation, gpointer data) | |
1020 { | |
1021 GtkWidget *spin = data; | |
1022 | |
1023 if (allocation->height > spin->requisition.height) | |
1024 { | |
1025 GtkAllocation button_allocation; | |
1026 | |
1027 button_allocation = button->allocation; | |
1028 button_allocation.height = spin->requisition.height; | |
1029 button_allocation.y = spin->allocation.y + | |
1030 (spin->allocation.height - spin->requisition.height) / 2; | |
1031 gtk_widget_size_allocate(button, &button_allocation); | |
1032 } | |
1033 } | |
1034 | |
1035 static void spin_increase(GtkWidget *spin, gint value) | |
1036 { | |
1037 GtkRequisition req; | |
1038 | |
1039 gtk_widget_size_request(spin, &req); | |
1040 gtk_widget_set_size_request(spin, req.width + value, -1); | |
1041 } | |
1042 | |
1043 static void date_selection_destroy_cb(GtkWidget *widget, gpointer data) | |
1044 { | |
1045 DateSelection *ds = data; | |
1046 | |
1047 date_selection_popup_hide(ds); | |
1048 | |
1049 g_free(ds); | |
1050 } | |
1051 | |
1052 GtkWidget *date_selection_new(void) | |
1053 { | |
1054 DateSelection *ds; | |
1055 GtkWidget *arrow; | |
1056 | |
1057 ds = g_new0(DateSelection, 1); | |
1058 | |
1059 ds->box = gtk_hbox_new(FALSE, 2); | |
1060 g_signal_connect(G_OBJECT(ds->box), "destroy", | |
1061 G_CALLBACK(date_selection_destroy_cb), ds); | |
1062 | |
1063 /* FIXME: use option menu with text format of month instead of a spin button */ | |
1064 ds->spin_m = pref_spin_new(ds->box, NULL, NULL, 1, 12, 1, 0, 1, NULL, NULL); | |
1065 ds->spin_d = pref_spin_new(ds->box, NULL, NULL, 1, 31, 1, 0, 1, NULL, NULL); | |
1066 ds->spin_y = pref_spin_new(ds->box, NULL, NULL, 1900, 9999, 1, 0, 1900, NULL, NULL); | |
1067 spin_increase(ds->spin_y, 5); | |
1068 | |
1069 ds->button = gtk_toggle_button_new(); | |
1070 g_signal_connect(G_OBJECT(ds->button), "size_allocate", | |
1071 G_CALLBACK(button_size_allocate_cb), ds->spin_y); | |
1072 | |
1073 arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); | |
1074 gtk_container_add(GTK_CONTAINER(ds->button), arrow); | |
1075 gtk_widget_show(arrow); | |
1076 | |
1077 gtk_box_pack_start(GTK_BOX(ds->box), ds->button, FALSE, FALSE, 0); | |
1078 g_signal_connect(G_OBJECT(ds->button), "clicked", | |
1079 G_CALLBACK(date_selection_button_cb), ds); | |
1080 gtk_widget_show(ds->button); | |
1081 | |
1082 g_object_set_data(G_OBJECT(ds->box), DATE_SELECION_KEY, ds); | |
1083 | |
1084 return ds->box; | |
1085 } | |
1086 | |
1087 void date_selection_set(GtkWidget *widget, gint day, gint month, gint year) | |
1088 { | |
1089 DateSelection *ds; | |
1090 | |
1091 ds = g_object_get_data(G_OBJECT(widget), DATE_SELECION_KEY); | |
1092 if (!ds) return; | |
1093 | |
1094 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ds->spin_d), (gdouble)day); | |
1095 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ds->spin_m), (gdouble)month); | |
1096 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ds->spin_y), (gdouble)year); | |
1097 } | |
1098 | |
1099 | |
1100 void date_selection_get(GtkWidget *widget, gint *day, gint *month, gint *year) | |
1101 { | |
1102 DateSelection *ds; | |
1103 | |
1104 ds = g_object_get_data(G_OBJECT(widget), DATE_SELECION_KEY); | |
1105 if (!ds) return; | |
1106 | |
1107 if (day) *day = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ds->spin_d)); | |
1108 if (month) *month = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ds->spin_m)); | |
1109 if (year) *year = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ds->spin_y)); | |
1110 } | |
1111 | |
1112 void date_selection_time_set(GtkWidget *widget, time_t t) | |
1113 { | |
1114 struct tm *lt; | |
1115 | |
1116 lt = localtime(&t); | |
1117 if (!lt) return; | |
1118 | |
1119 date_selection_set(widget, lt->tm_mday, lt->tm_mon + 1, lt->tm_year + 1900); | |
1120 } | |
1121 | |
1122 time_t date_selection_time_get(GtkWidget *widget) | |
1123 { | |
1124 struct tm lt; | |
1125 gint day = 0; | |
1126 gint month = 0; | |
1127 gint year = 0; | |
1128 | |
1129 date_selection_get(widget, &day, &month ,&year); | |
1130 | |
1131 lt.tm_sec = 0; | |
1132 lt.tm_min = 0; | |
1133 lt.tm_hour = 0; | |
1134 lt.tm_mday = day; | |
1135 lt.tm_mon = month - 1; | |
1136 lt.tm_year = year - 1900; | |
1137 lt.tm_isdst = 0; | |
1138 | |
1139 return mktime(<); | |
1140 } | |
1141 | |
1142 | |
1143 /* | |
1144 *----------------------------------------------------------------------------- | |
1145 * Sizer, without using a GtkPaned | |
1146 *----------------------------------------------------------------------------- | |
1147 */ | |
1148 | |
1149 #define SIZER_DATA_KEY "sizer_data" | |
1150 | |
1151 typedef struct _SizerData SizerData; | |
1152 struct _SizerData | |
1153 { | |
1154 GtkWidget *sizer; | |
1155 GtkWidget *parent; | |
1156 GtkWidget *bounding_widget; | |
1157 SizerPositionType position; | |
1158 | |
1159 gint hsize_min; | |
1160 gint hsize_max; | |
1161 gint vsize_min; | |
1162 gint vsize_max; | |
1163 | |
1164 gint in_drag; | |
1165 gint press_x; | |
1166 gint press_y; | |
1167 gint press_width; | |
1168 gint press_height; | |
1169 | |
1170 gint handle_prelit; | |
1171 }; | |
1172 | |
1173 | |
1174 static gint sizer_default_handle_size(void) | |
1175 { | |
1176 gint handle_size = 5; | |
1177 GtkWidget *paned; | |
1178 GtkStyle *style; | |
1179 | |
1180 paned = gtk_hpaned_new(); | |
1181 | |
1182 style = gtk_rc_get_style(paned); | |
1183 gtk_widget_set_style(paned, style); | |
1184 gtk_widget_style_get(paned, "handle_size", &handle_size, NULL); | |
1185 | |
1186 gtk_widget_destroy(paned); | |
1187 | |
1188 return handle_size; | |
1189 } | |
1190 | |
1191 static gint sizer_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1192 { | |
1193 SizerData *sd = data; | |
1194 gint x, y; | |
1195 gint w, h; | |
1196 | |
1197 if (!sd->in_drag) return FALSE; | |
1198 | |
1199 x = sd->press_x - bevent->x_root; | |
1200 y = sd->press_y - bevent->y_root; | |
1201 | |
1202 w = sd->press_width; | |
1203 h = sd->press_height; | |
1204 | |
1205 if (sd->position & SIZER_POS_LEFT) | |
1206 { | |
1207 w += x; | |
1208 } | |
1209 else if (sd->position & SIZER_POS_RIGHT) | |
1210 { | |
1211 w -= x; | |
1212 } | |
1213 | |
1214 if (sd->position & SIZER_POS_TOP) | |
1215 { | |
1216 h += y; | |
1217 } | |
1218 else if (sd->position & SIZER_POS_BOTTOM) | |
1219 { | |
1220 h -= y; | |
1221 } | |
1222 | |
1223 if (sd->hsize_min >= 0) w = MAX(w, sd->hsize_min); | |
1224 if (sd->vsize_min >= 0) h = MAX(h, sd->vsize_min); | |
1225 | |
1226 if (sd->bounding_widget) | |
1227 { | |
1228 w = CLAMP(w, sd->sizer->allocation.width, sd->bounding_widget->allocation.width); | |
1229 h = CLAMP(h, sd->sizer->allocation.height, sd->bounding_widget->allocation.height); | |
1230 } | |
1231 else | |
1232 { | |
1233 if (w < sd->sizer->allocation.width) w = sd->sizer->allocation.width; | |
1234 if (h < sd->sizer->allocation.height) h = sd->sizer->allocation.height; | |
1235 } | |
1236 | |
1237 if (sd->hsize_max >= 0) w = MIN(w, sd->hsize_max); | |
1238 if (sd->vsize_max >= 0) h = MIN(h, sd->vsize_max); | |
1239 | |
1240 if (w == sd->parent->allocation.width) w = -1; | |
1241 if (h == sd->parent->allocation.height) h = -1; | |
1242 | |
1243 if (w > 0 || h > 0) gtk_widget_set_size_request(sd->parent, w, h); | |
1244 | |
1245 return TRUE; | |
1246 } | |
1247 | |
1248 static gint sizer_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1249 { | |
1250 SizerData *sd = data; | |
1251 | |
1252 if (bevent->button != 1) return FALSE; | |
1253 | |
1254 sd->in_drag = TRUE; | |
1255 sd->press_x = bevent->x_root; | |
1256 sd->press_y = bevent->y_root; | |
1257 | |
1258 sd->press_width = sd->parent->allocation.width; | |
1259 sd->press_height = sd->parent->allocation.height; | |
1260 | |
1261 gdk_pointer_grab(sd->sizer->window, FALSE, | |
1262 GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, | |
1263 NULL, NULL, bevent->time); | |
1264 gtk_grab_add(sd->sizer); | |
1265 | |
1266 return TRUE; | |
1267 } | |
1268 | |
1269 static gint sizer_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1270 { | |
1271 SizerData *sd = data; | |
1272 | |
1273 if (bevent->button != 1) return FALSE; | |
1274 | |
1275 if (gdk_pointer_is_grabbed() && GTK_WIDGET_HAS_GRAB(sd->sizer)) | |
1276 { | |
1277 gtk_grab_remove(sd->sizer); | |
1278 gdk_pointer_ungrab(bevent->time); | |
1279 } | |
1280 | |
1281 sd->in_drag = FALSE; | |
1282 | |
1283 return TRUE; | |
1284 } | |
1285 | |
1286 static void sizer_set_prelight(SizerData *sd, gint prelit) | |
1287 { | |
1288 sd->handle_prelit = prelit; | |
1289 gtk_widget_queue_draw_area(sd->sizer, 0, 0, | |
1290 sd->sizer->allocation.width, sd->sizer->allocation.height); | |
1291 } | |
1292 | |
1293 static gint sizer_enter_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) | |
1294 { | |
1295 SizerData *sd = data; | |
1296 | |
1297 sizer_set_prelight(sd, TRUE); | |
1298 return TRUE; | |
1299 } | |
1300 | |
1301 static gint sizer_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) | |
1302 { | |
1303 SizerData *sd = data; | |
1304 | |
1305 sizer_set_prelight(sd, FALSE); | |
1306 return TRUE; | |
1307 } | |
1308 | |
1309 static gint sizer_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data) | |
1310 { | |
1311 SizerData *sd = data; | |
1312 GdkRectangle clip; | |
1313 GtkOrientation orientation; | |
1314 GtkStateType state; | |
1315 | |
1316 gdk_region_get_clipbox(event->region, &clip); | |
1317 | |
1318 if (sd->position & SIZER_POS_LEFT || sd->position & SIZER_POS_RIGHT) | |
1319 { | |
1320 orientation = GTK_ORIENTATION_VERTICAL; | |
1321 } | |
1322 else | |
1323 { | |
1324 orientation = GTK_ORIENTATION_HORIZONTAL; | |
1325 } | |
1326 | |
1327 if (sd->handle_prelit) | |
1328 { | |
1329 state = GTK_STATE_PRELIGHT; | |
1330 } | |
1331 else | |
1332 { | |
1333 state = widget->state; | |
1334 } | |
1335 | |
1336 gtk_paint_handle(widget->style, widget->window, state, | |
1337 GTK_SHADOW_NONE, &clip, widget, "paned", | |
1338 0, 0, | |
1339 widget->allocation.width, widget->allocation.height, | |
1340 orientation); | |
1341 | |
1342 return TRUE; | |
1343 } | |
1344 | |
1345 static void sizer_realize_cb(GtkWidget *widget, gpointer data) | |
1346 { | |
1347 SizerData *sd = data; | |
1348 GdkCursorType n; | |
1349 | |
1350 n = 0; | |
1351 if (sd->position & SIZER_POS_TOP || sd->position & SIZER_POS_BOTTOM) | |
1352 { | |
1353 n = GDK_SB_V_DOUBLE_ARROW; | |
1354 } | |
1355 if (sd->position & SIZER_POS_LEFT || sd->position & SIZER_POS_RIGHT) | |
1356 { | |
1357 n = (n != 0) ? GDK_FLEUR : GDK_SB_H_DOUBLE_ARROW; | |
1358 } | |
1359 | |
1360 if (n != 0 && widget->window) | |
1361 { | |
1362 GdkCursor *cursor; | |
1363 cursor = gdk_cursor_new(n); | |
1364 gdk_window_set_cursor(widget->window, cursor); | |
1365 gdk_cursor_unref(cursor); | |
1366 } | |
1367 } | |
1368 | |
1369 static void sizer_destroy_cb(GtkWidget *widget, gpointer data) | |
1370 { | |
1371 SizerData *sd = data; | |
1372 | |
1373 g_free(sd); | |
1374 } | |
1375 | |
1376 GtkWidget *sizer_new(GtkWidget *parent, GtkWidget *bounding_widget, | |
1377 SizerPositionType position) | |
1378 { | |
1379 SizerData *sd; | |
1380 gint handle_size; | |
1381 | |
1382 sd = g_new0(SizerData, 1); | |
1383 | |
1384 sd->sizer = gtk_event_box_new(); | |
1385 sd->parent = parent; | |
1386 sd->bounding_widget = bounding_widget; | |
1387 sd->position = position; | |
1388 sd->hsize_min = -1; | |
1389 sd->hsize_max = -1; | |
1390 sd->vsize_min = -1; | |
1391 sd->vsize_max = -1; | |
1392 | |
1393 sd->in_drag = FALSE; | |
1394 sd->handle_prelit = FALSE; | |
1395 | |
1396 g_signal_connect(G_OBJECT(sd->sizer), "destroy", | |
1397 G_CALLBACK(sizer_destroy_cb), sd); | |
1398 | |
1399 g_signal_connect(G_OBJECT(sd->sizer), "motion_notify_event", | |
1400 G_CALLBACK(sizer_motion_cb), sd); | |
1401 g_signal_connect(G_OBJECT(sd->sizer), "button_press_event", | |
1402 G_CALLBACK(sizer_press_cb), sd); | |
1403 g_signal_connect(G_OBJECT(sd->sizer), "button_release_event", | |
1404 G_CALLBACK(sizer_release_cb), sd); | |
1405 | |
1406 g_signal_connect(G_OBJECT(sd->sizer), "enter_notify_event", | |
1407 G_CALLBACK(sizer_enter_cb), sd); | |
1408 g_signal_connect(G_OBJECT(sd->sizer), "leave_notify_event", | |
1409 G_CALLBACK(sizer_leave_cb), sd); | |
1410 | |
1411 gtk_widget_set_events(sd->sizer, GDK_POINTER_MOTION_MASK | | |
1412 GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | | |
1413 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); | |
1414 | |
1415 g_signal_connect(sd->sizer, "realize", | |
1416 G_CALLBACK(sizer_realize_cb), sd); | |
1417 g_signal_connect(sd->sizer, "expose_event", | |
1418 G_CALLBACK(sizer_expose_cb), sd); | |
1419 | |
1420 handle_size = sizer_default_handle_size(); | |
1421 | |
1422 gtk_widget_set_size_request(sd->sizer, handle_size, handle_size); | |
1423 #if 0 | |
1424 /* use this if you add a shadow border to the handle */ | |
1425 gtk_widget_set_size_request(sd->sizer, handle_size + sd->sizer->style->xthickness * 2, | |
1426 handle_size + sd->sizer->style->ythickness * 2); | |
1427 #endif | |
1428 | |
1429 g_object_set_data(G_OBJECT(sd->sizer), SIZER_DATA_KEY,sd); | |
1430 | |
1431 return sd->sizer; | |
1432 } | |
1433 | |
1434 void sizer_set_limits(GtkWidget *sizer, | |
1435 gint hsize_min, gint hsize_max, | |
1436 gint vsize_min, gint vsize_max) | |
1437 { | |
1438 SizerData *sd; | |
1439 | |
1440 sd = g_object_get_data(G_OBJECT(sizer), SIZER_DATA_KEY); | |
1441 if (!sd) return; | |
1442 | |
1443 sd->hsize_min = hsize_min; | |
1444 sd->hsize_max = hsize_max; | |
1445 sd->vsize_min = vsize_min; | |
1446 sd->vsize_max = vsize_max; | |
1447 } | |
1448 | |
1449 | |
1450 /* | |
1451 *----------------------------------------------------------------------------- | |
1452 * storing data in a history list with key,data pairs | |
1453 *----------------------------------------------------------------------------- | |
1454 */ | |
1455 | |
1456 #define PREF_LIST_MARKER_INT "[INT]:" | |
1457 #define PREF_LIST_MARKER_DOUBLE "[DOUBLE]:" | |
1458 #define PREF_LIST_MARKER_STRING "[STRING]:" | |
1459 | |
1460 static GList *pref_list_find(const gchar *group, const gchar *token) | |
1461 { | |
1462 GList *work; | |
1463 gint l; | |
1464 | |
1465 l = strlen(token); | |
1466 | |
1467 work = history_list_get_by_key(group); | |
1468 while (work) | |
1469 { | |
1470 const gchar *text = work->data; | |
1471 | |
1472 if (strncmp(text, token, l) == 0) return work; | |
1473 | |
1474 work = work->next; | |
1475 } | |
1476 | |
1477 return NULL; | |
1478 } | |
1479 | |
1480 static gint pref_list_get(const gchar *group, const gchar *key, const gchar *marker, const gchar **result) | |
1481 { | |
1482 gchar *token; | |
1483 GList *work; | |
1484 gint ret; | |
1485 | |
1486 if (!group || !key || !marker) | |
1487 { | |
1488 *result = NULL; | |
1489 return FALSE; | |
1490 } | |
1491 | |
1492 token = g_strconcat(key, marker, NULL); | |
1493 | |
1494 work = pref_list_find(group, token); | |
1495 if (work) | |
1496 { | |
1497 *result = (const gchar *)work->data + strlen(token); | |
1498 if (strlen(*result) == 0) *result = NULL; | |
1499 ret = TRUE; | |
1500 } | |
1501 else | |
1502 { | |
1503 *result = NULL; | |
1504 ret = FALSE; | |
1505 } | |
1506 | |
1507 g_free(token); | |
1508 | |
1509 return ret; | |
1510 } | |
1511 | |
1512 static void pref_list_set(const gchar *group, const gchar *key, const gchar *marker, const gchar *text) | |
1513 { | |
1514 gchar *token; | |
1515 gchar *path; | |
1516 GList *work; | |
1517 | |
1518 if (!group || !key || !marker) return; | |
1519 | |
1520 token = g_strconcat(key, marker, NULL); | |
1521 path = g_strconcat(token, text, NULL); | |
1522 | |
1523 work = pref_list_find(group, token); | |
1524 if (work) | |
1525 { | |
1526 gchar *old_path = work->data; | |
1527 | |
1528 if (text) | |
1529 { | |
1530 work->data = path; | |
1531 path = NULL; | |
1532 | |
1533 g_free(old_path); | |
1534 } | |
1535 else | |
1536 { | |
1537 history_list_item_remove(group, old_path); | |
1538 } | |
1539 } | |
1540 else if (text) | |
1541 { | |
1542 history_list_add_to_key(group, path, 0); | |
1543 } | |
1544 | |
1545 g_free(path); | |
1546 g_free(token); | |
1547 } | |
1548 | |
1549 void pref_list_int_set(const gchar *group, const gchar *key, gint value) | |
1550 { | |
1551 gchar *text; | |
1552 | |
1553 text = g_strdup_printf("%d", value); | |
1554 pref_list_set(group, key, PREF_LIST_MARKER_INT, text); | |
1555 g_free(text); | |
1556 } | |
1557 | |
1558 gint pref_list_int_get(const gchar *group, const gchar *key, gint *result) | |
1559 { | |
1560 const gchar *text; | |
1561 | |
1562 if (!group || !key) | |
1563 { | |
1564 *result = 0; | |
1565 return FALSE; | |
1566 } | |
1567 | |
1568 if (pref_list_get(group, key, PREF_LIST_MARKER_INT, &text) && text) | |
1569 { | |
1570 *result = (gint)strtol(text, NULL, 10); | |
1571 return TRUE; | |
1572 } | |
1573 | |
1574 *result = 0; | |
1575 return FALSE; | |
1576 } | |
1577 | |
1578 void pref_list_double_set(const gchar *group, const gchar *key, gdouble value) | |
1579 { | |
1580 gchar text[G_ASCII_DTOSTR_BUF_SIZE]; | |
1581 | |
1582 g_ascii_dtostr(text, sizeof(text), value); | |
1583 pref_list_set(group, key, PREF_LIST_MARKER_DOUBLE, text); | |
1584 } | |
1585 | |
1586 gint pref_list_double_get(const gchar *group, const gchar *key, gdouble *result) | |
1587 { | |
1588 const gchar *text; | |
1589 | |
1590 if (!group || !key) | |
1591 { | |
1592 *result = 0; | |
1593 return FALSE; | |
1594 } | |
1595 | |
1596 if (pref_list_get(group, key, PREF_LIST_MARKER_DOUBLE, &text) && text) | |
1597 { | |
1598 *result = g_ascii_strtod(text, NULL); | |
1599 return TRUE; | |
1600 } | |
1601 | |
1602 *result = 0; | |
1603 return FALSE; | |
1604 } | |
1605 | |
1606 void pref_list_string_set(const gchar *group, const gchar *key, const gchar *value) | |
1607 { | |
1608 pref_list_set(group, key, PREF_LIST_MARKER_STRING, value); | |
1609 } | |
1610 | |
1611 gint pref_list_string_get(const gchar *group, const gchar *key, const gchar **result) | |
1612 { | |
1613 return pref_list_get(group, key, PREF_LIST_MARKER_STRING, result); | |
1614 } | |
1615 | |
1616 |