Debian Codegraph @

src/gutenprintui2/ui-utils.c

raw symbols SCIP
1 /*
2 *
3 * Main window code for Print plug-in for the GIMP.
4 *
5 * Copyright 1997-2000 Michael Sweet ([email protected]),
6 * Robert Krawitz ([email protected]), Steve Miller ([email protected])
7 * and Michael Natterer ([email protected])
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <gutenprint/gutenprint-intl-internal.h>
28 #include <gutenprintui2/gutenprintui.h>
29 #include "gutenprintui-internal.h"
30
31 #include <stdio.h>
32 #include <string.h>
33
34 static void default_errfunc(void *data, const char *buffer, size_t bytes);
35 static gchar *image_filename;
36 static stp_outfunc_t the_errfunc = default_errfunc;
37 static void *the_errdata = NULL;
38 static get_thumbnail_func_t thumbnail_func;
39 static void *thumbnail_private_data;
40
41 /*****************************************************************\
42 * *
43 * The following from libgimp/gimpdialog.c *
44 * *
45 \*****************************************************************/
46
47 typedef void (*StpuiBasicCallback) (GObject *object,
48 gpointer user_data);
49
50 /* local callbacks of dialog_new () */
51 #pragma GCC diagnostic push
52 #pragma GCC diagnostic ignored "-Wpedantic"
53 static gint
54 dialog_delete_callback (GtkWidget *widget,
55 GdkEvent *event,
56 gpointer data)
57 {
58 StpuiBasicCallback cancel_callback;
59 GtkWidget *cancel_widget;
60 (void)event;
61
62 cancel_callback =
63 (StpuiBasicCallback) g_object_get_data (G_OBJECT (widget),
64 "dialog_cancel_callback");
65 cancel_widget =
66 (GtkWidget*) g_object_get_data (G_OBJECT (widget),
67 "dialog_cancel_widget");
68
69 /* the cancel callback has to destroy the dialog */
70 if (cancel_callback)
71 (* cancel_callback) (G_OBJECT(cancel_widget), data);
72
73 return TRUE;
74 }
75 #pragma GCC diagnostic pop
76
77 /**
78 * dialog_create_action_areav:
79 * @dialog: The #GtkDialog you want to create the action_area for.
80 * @args: A @va_list as obtained with va_start() describing the action_area
81 * buttons.
82 *
83 */
84 #pragma GCC diagnostic push
85 #pragma GCC diagnostic ignored "-Wpedantic"
86 static void
87 dialog_create_action_areav (GtkDialog *dialog,
88 va_list args)
89 {
90 GtkWidget *hbbox = NULL;
91 GtkWidget *button;
92
93 /* action area variables */
94 const gchar *label;
95 GtkSignalFunc callback;
96 gpointer data;
97 GObject *slot_object;
98 GtkWidget **widget_ptr;
99 gboolean default_action;
100 gboolean connect_delete;
101
102 gboolean delete_connected = FALSE;
103
104 g_return_if_fail (dialog != NULL);
105 g_return_if_fail (GTK_IS_DIALOG (dialog));
106
107 /* prepare the action_area */
108 label = va_arg (args, const gchar *);
109
110 if (label)
111 {
112 gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 2);
113 gtk_box_set_homogeneous (GTK_BOX (dialog->action_area), FALSE);
114
115 hbbox = gtk_hbutton_box_new ();
116 gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4);
117 gtk_box_pack_end (GTK_BOX (dialog->action_area), hbbox, FALSE, FALSE, 0);
118 gtk_widget_show (hbbox);
119 }
120
121 /* the action_area buttons */
122 while (label)
123 {
124 callback = va_arg (args, GtkSignalFunc);
125 data = va_arg (args, gpointer);
126 slot_object = va_arg (args, GObject *);
127 widget_ptr = va_arg (args, GtkWidget **);
128 default_action = va_arg (args, gboolean);
129 connect_delete = va_arg (args, gboolean);
130
131 button = gtk_button_new_with_label (label);
132 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
133 gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0);
134
135 if (slot_object == (GObject *) 1)
136 slot_object = G_OBJECT (dialog);
137
138 if (data == NULL)
139 data = dialog;
140
141 if (callback)
142 {
143 if (slot_object)
144 g_signal_connect_object (G_OBJECT (button), "clicked",
145 G_CALLBACK (callback),
146 slot_object, G_CONNECT_SWAPPED);
147 else
148 g_signal_connect (G_OBJECT (button), "clicked",
149 G_CALLBACK (callback),
150 data);
151 }
152
153 if (widget_ptr)
154 *widget_ptr = button;
155
156 if (connect_delete && callback && !delete_connected)
157 {
158 gtk_object_set_data (GTK_OBJECT (dialog),
159 "dialog_cancel_callback",
160 (gpointer) callback);
161 gtk_object_set_data (GTK_OBJECT (dialog),
162 "dialog_cancel_widget",
163 slot_object ? slot_object : G_OBJECT (button));
164
165 /* catch the WM delete event */
166 g_signal_connect (G_OBJECT (dialog), "delete_event",
167 G_CALLBACK (dialog_delete_callback),
168 data);
169
170 delete_connected = TRUE;
171 }
172
173 if (default_action)
174 gtk_widget_grab_default (button);
175 gtk_widget_show (button);
176
177 label = va_arg (args, gchar *);
178 }
179 }
180 #pragma GCC diagnostic pop
181
182 /**
183 * dialog_new:
184 * @title: The dialog's title which will be set with gtk_window_set_title().
185 * @position: The dialog's initial position which will be set with
186 * gtk_window_set_position().
187 * @resizable: Is the dialog resizable?, ...
188 * @allow_grow: ... it't @allow_grow flag and ...
189 * @auto_shrink: ... it's @auto_shrink flag which will all be set with
190 * gtk_window_set_policy().
191 * @...: A #NULL terminated @va_list destribing the action_area buttons.
192 *
193 * This function simply packs the action_area arguments passed in "..."
194 * into a @va_list variable and passes everything to dialog_newv().
195 *
196 * For a description of the format of the @va_list describing the
197 * action_area buttons see dialog_create_action_areav().
198 *
199 * Returns: A #GtkDialog.
200 *
201 */
202 GtkWidget *
203 stpui_dialog_new (const gchar *title,
204 GtkWindowPosition position,
205 gboolean resizable,
206
207 /* specify action area buttons as va_list:
208 * const gchar *label,
209 * GtkSignalFunc callback,
210 * gpointer data,
211 * GObject *slot_object,
212 * GtkWidget **widget_ptr,
213 * gboolean default_action,
214 * gboolean connect_delete,
215 */
216
217 ...)
218 {
219 GtkWidget *dialog;
220 va_list args;
221
222 g_return_val_if_fail (title != NULL, NULL);
223
224 va_start (args, resizable);
225
226 dialog = gtk_dialog_new ();
227 gtk_window_set_title (GTK_WINDOW (dialog), title);
228 gtk_window_set_position (GTK_WINDOW (dialog), position);
229 gtk_window_set_resizable (GTK_WINDOW (dialog), resizable);
230
231 /* prepare the action_area */
232 dialog_create_action_areav (GTK_DIALOG (dialog), args);
233
234 va_end (args);
235
236 return dialog;
237 }
238
239 /*****************************************************************\
240 * *
241 * The following from libgimp/gimpwidgets.c *
242 * *
243 \*****************************************************************/
244
245 /**
246 * option_menu_new:
247 * @menu_only: #TRUE if the function should return a #GtkMenu only.
248 * @...: A #NULL terminated @va_list describing the menu items.
249 *
250 * Returns: A #GtkOptionMenu or a #GtkMenu (depending on @menu_only).
251 **/
252 GtkWidget *
253 stpui_option_menu_new(gboolean menu_only,
254
255 /* specify menu items as va_list:
256 * const gchar *label,
257 * GtkSignalFunc callback,
258 * gpointer data,
259 * gpointer user_data,
260 * GtkWidget **widget_ptr,
261 * gboolean active
262 */
263
264 ...)
265 {
266 GtkWidget *menu;
267 GtkWidget *menuitem;
268
269 /* menu item variables */
270 const gchar *label;
271 GtkSignalFunc callback;
272 gpointer data;
273 gpointer user_data;
274 GtkWidget **widget_ptr;
275 gboolean active;
276
277 va_list args;
278 gint i;
279 gint initial_index;
280
281 menu = gtk_menu_new ();
282
283 /* create the menu items */
284 initial_index = 0;
285
286 va_start (args, menu_only);
287 label = va_arg (args, const gchar *);
288
289 for (i = 0; label; i++)
290 {
291 callback = va_arg (args, GtkSignalFunc);
292 data = va_arg (args, gpointer);
293 user_data = va_arg (args, gpointer);
294 widget_ptr = va_arg (args, GtkWidget **);
295 active = va_arg (args, gboolean);
296
297 if (strcmp (label, "---"))
298 {
299 menuitem = gtk_menu_item_new_with_label (label);
300
301 g_signal_connect (G_OBJECT (menuitem), "activate",
302 callback,
303 data);
304
305 if (user_data)
306 gtk_object_set_user_data (GTK_OBJECT (menuitem), user_data);
307 }
308 else
309 {
310 menuitem = gtk_menu_item_new ();
311
312 gtk_widget_set_sensitive (menuitem, FALSE);
313 }
314
315 gtk_menu_append (GTK_MENU (menu), menuitem);
316
317 if (widget_ptr)
318 *widget_ptr = menuitem;
319
320 gtk_widget_show (menuitem);
321
322 /* remember the initial menu item */
323 if (active)
324 initial_index = i;
325
326 label = va_arg (args, const gchar *);
327 }
328 va_end (args);
329
330 if (! menu_only)
331 {
332 GtkWidget *optionmenu;
333
334 optionmenu = gtk_option_menu_new ();
335 gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
336
337 /* select the initial menu item */
338 gtk_option_menu_set_history (GTK_OPTION_MENU (optionmenu), initial_index);
339
340 return optionmenu;
341 }
342
343 return menu;
344 }
345
346 /*****************************************************************\
347 * *
348 * The following from libgimp/gimpwidgets.c *
349 * *
350 \*****************************************************************/
351
352 /**
353 * spin_button_new:
354 * @adjustment: Returns the spinbutton's #GtkAdjustment.
355 * @value: The initial value of the spinbutton.
356 * @lower: The lower boundary.
357 * @upper: The uppper boundary.
358 * @step_increment: The spinbutton's step increment.
359 * @page_increment: The spinbutton's page increment (mouse button 2).
360 * @page_size: The spinbutton's page size.
361 * @climb_rate: The spinbutton's climb rate.
362 * @digits: The spinbutton's number of decimal digits.
363 *
364 * This function is a shortcut for gtk_adjustment_new() and a subsequent
365 * gtk_spin_button_new() and does some more initialisation stuff like
366 * setting a standard minimun horizontal size.
367 *
368 * Returns: A #GtkSpinbutton and it's #GtkAdjustment.
369 **/
370 static GtkWidget *
371 spin_button_new (GtkObject **adjustment, /* return value */
372 gfloat value,
373 gfloat lower,
374 gfloat upper,
375 gfloat step_increment,
376 gfloat page_increment,
377 gfloat page_size,
378 gfloat climb_rate,
379 guint digits)
380 {
381 GtkWidget *spinbutton;
382
383 *adjustment = gtk_adjustment_new (value, lower, upper,
384 step_increment, page_increment, page_size);
385
386 spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (*adjustment),
387 climb_rate, digits);
388 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
389 gtk_widget_set_usize (spinbutton, 75, -1);
390
391 return spinbutton;
392 }
393
394 static void
395 scale_entry_unconstrained_adjustment_callback (GtkAdjustment *adjustment,
396 GtkAdjustment *other_adj)
397 {
398 g_signal_handlers_block_matched (G_OBJECT (other_adj),
399 G_SIGNAL_MATCH_DATA,
400 0,
401 0,
402 NULL,
403 NULL,
404 adjustment);
405
406 gtk_adjustment_set_value (other_adj, adjustment->value);
407
408 g_signal_handlers_unblock_matched (G_OBJECT (other_adj),
409 G_SIGNAL_MATCH_DATA,
410 0,
411 0,
412 NULL,
413 NULL,
414 adjustment);
415 }
416
417 /**
418 * scale_entry_new:
419 * @table: The #GtkTable the widgets will be attached to.
420 * @column: The column to start with.
421 * @row: The row to attach the widgets.
422 * @text: The text for the #GtkLabel which will appear
423 * left of the #GtkHScale.
424 * @scale_usize: The minimum horizontal size of the #GtkHScale.
425 * @spinbutton_usize: The minimum horizontal size of the #GtkSpinButton.
426 * @value: The initial value.
427 * @lower: The lower boundary.
428 * @upper: The upper boundary.
429 * @step_increment: The step increment.
430 * @page_increment: The page increment.
431 * @digits: The number of decimal digits.
432 * @constrain: #TRUE if the range of possible values of the
433 * #GtkSpinButton should be the same as of the #GtkHScale.
434 * @unconstrained_lower: The spinbutton's lower boundary
435 * if @constrain == #FALSE.
436 * @unconstrained_upper: The spinbutton's upper boundary
437 * if @constrain == #FALSE.
438 * @tooltip: A tooltip message for the scale and the spinbutton.
439 *
440 * This function creates a #GtkLabel, a #GtkHScale and a #GtkSpinButton and
441 * attaches them to a 3-column #GtkTable.
442 *
443 * Returns: The #GtkSpinButton's #GtkAdjustment.
444 **/
445 GtkObject *
446 stpui_scale_entry_new(GtkTable *table,
447 gint column,
448 gint row,
449 const gchar *text,
450 gint scale_usize,
451 gint spinbutton_usize,
452 gfloat value,
453 gfloat lower,
454 gfloat upper,
455 gfloat step_increment,
456 gfloat page_increment,
457 guint digits,
458 gboolean constrain,
459 gfloat unconstrained_lower,
460 gfloat unconstrained_upper,
461 const gchar *tooltip)
462 {
463 GtkWidget *label;
464 GtkWidget *scale;
465 GtkWidget *spinbutton;
466 GtkObject *adjustment;
467 GtkObject *return_adj;
468
469 label = gtk_label_new (text);
470 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
471 gtk_table_attach (GTK_TABLE (table), label,
472 column + 1, column + 2, row, row + 1,
473 GTK_FILL, GTK_FILL, 0, 0);
474 gtk_widget_show (label);
475
476 if (! constrain &&
477 unconstrained_lower <= lower &&
478 unconstrained_upper >= upper)
479 {
480 GtkObject *constrained_adj;
481
482 constrained_adj = gtk_adjustment_new (value, lower, upper,
483 step_increment, page_increment,
484 0.0);
485
486 spinbutton = spin_button_new (&adjustment, value,
487 unconstrained_lower,
488 unconstrained_upper,
489 step_increment, page_increment, 0.0,
490 1.0, digits);
491
492 g_signal_connect
493 (G_OBJECT (constrained_adj), "value_changed",
494 G_CALLBACK (scale_entry_unconstrained_adjustment_callback),
495 adjustment);
496
497 g_signal_connect
498 (G_OBJECT (adjustment), "value_changed",
499 G_CALLBACK (scale_entry_unconstrained_adjustment_callback),
500 constrained_adj);
501
502 return_adj = adjustment;
503
504 adjustment = constrained_adj;
505 }
506 else
507 {
508 spinbutton = spin_button_new (&adjustment, value, lower, upper,
509 step_increment, page_increment, 0.0,
510 1.0, digits);
511
512 return_adj = adjustment;
513 }
514
515 if (spinbutton_usize > 0)
516 gtk_widget_set_usize (spinbutton, spinbutton_usize, -1);
517
518 scale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
519 if (scale_usize > 0)
520 gtk_widget_set_usize (scale, scale_usize, -1);
521 gtk_scale_set_digits (GTK_SCALE (scale), digits);
522 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
523 gtk_table_attach (GTK_TABLE (table), scale,
524 column + 2, column + 3, row, row + 1,
525 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
526 gtk_widget_show (scale);
527
528 gtk_table_attach (GTK_TABLE (table), spinbutton,
529 column + 3, column + 4, row, row + 1,
530 GTK_SHRINK, GTK_SHRINK, 0, 0);
531 gtk_widget_show (spinbutton);
532
533 if (tooltip)
534 {
535 stpui_set_help_data (scale, tooltip);
536 stpui_set_help_data (spinbutton, tooltip);
537 }
538
539 gtk_object_set_data (GTK_OBJECT (return_adj), "label", label);
540 gtk_object_set_data (GTK_OBJECT (return_adj), "scale", scale);
541 gtk_object_set_data (GTK_OBJECT (return_adj), "spinbutton", spinbutton);
542
543 return return_adj;
544 }
545
546 /**
547 * table_attach_aligned:
548 * @table: The #GtkTable the widgets will be attached to.
549 * @column: The column to start with.
550 * @row: The row to attach the eidgets.
551 * @label_text: The text for the #GtkLabel which will be attached left of the
552 * widget.
553 * @xalign: The horizontal alignment of the #GtkLabel.
554 * @yalign: The vertival alignment of the #GtkLabel.
555 * @widget: The #GtkWidget to attach right of the label.
556 * @colspan: The number of columns the widget will use.
557 * @left_align: #TRUE if the widget should be left-aligned.
558 *
559 * Note that the @label_text can be #NULL and that the widget will be attached
560 * starting at (@column + 1) in this case, too.
561 **/
562 void
563 stpui_table_attach_aligned (GtkTable *table,
564 gint column,
565 gint row,
566 const gchar *label_text,
567 gfloat xalign,
568 gfloat yalign,
569 GtkWidget *widget,
570 gint colspan,
571 gboolean left_align)
572 {
573 if (label_text)
574 {
575 GtkWidget *label;
576
577 label = gtk_label_new (label_text);
578 gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
579 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
580 gtk_table_attach (table, label, column, column + 1, row, row + 1,
581 GTK_FILL, GTK_FILL, 0, 0);
582 gtk_widget_show (label);
583 }
584
585 gtk_widget_show (widget);
586 if (left_align)
587 {
588 GtkWidget *alignment;
589
590 alignment = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
591 gtk_container_add (GTK_CONTAINER (alignment), widget);
592
593 widget = alignment;
594 }
595
596 gtk_table_attach (table, widget, column + 1, column + 1 + colspan,
597 row, row + 1,
598 GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
599
600 gtk_widget_show (widget);
601 }
602
603 /*****************************************************************\
604 * *
605 * The following borrowed from libgimp/gimphelpui.c *
606 * *
607 \*****************************************************************/
608
609 static GtkTooltips * tool_tips = NULL;
610
611 /**
612 * stpui_help_init:
613 *
614 * This function initializes GIMP's help system.
615 *
616 * Currently it only creates a #GtkTooltips object with gtk_tooltips_new()
617 * which will be used by help_stpui_set_help_data().
618 **/
619 void
620 stpui_help_init (void)
621 {
622 tool_tips = gtk_tooltips_new ();
623 }
624
625 /**
626 * stpui_help_free:
627 *
628 * This function frees the memory used by the #GtkTooltips created by
629 * stpui_help_init().
630 **/
631 void
632 stpui_help_free (void)
633 {
634 gtk_object_destroy (GTK_OBJECT (tool_tips));
635 gtk_object_unref (GTK_OBJECT (tool_tips));
636 }
637
638 /**
639 * help_enable_tooltips:
640 *
641 * This function calls gtk_tooltips_enable().
642 **/
643 void
644 stpui_enable_help (void)
645 {
646 gtk_tooltips_enable (tool_tips);
647 }
648
649 /**
650 * help_disable_tooltips:
651 *
652 * This function calls gtk_tooltips_disable().
653 **/
654
655 void
656 stpui_disable_help (void)
657 {
658 gtk_tooltips_disable (tool_tips);
659 }
660
661 void
662 stpui_set_help_data (GtkWidget *widget, const gchar *tooltip)
663 {
664 g_return_if_fail (widget != NULL);
665 g_return_if_fail (GTK_IS_WIDGET (widget));
666
667 if (tooltip)
668 {
669 gtk_tooltips_set_tip (tool_tips, widget, tooltip, NULL);
670 }
671 }
672
673 /*****************************************************************\
674 * *
675 * The below is new code *
676 * *
677 \*****************************************************************/
678
679
680 void
681 stpui_set_image_filename(const char *name)
682 {
683 if (name && name == image_filename)
684 return;
685 if (image_filename)
686 g_free(image_filename);
687 if (name)
688 image_filename = g_strdup(name);
689 else
690 image_filename = g_strdup("");
691 }
692
693 const char *
694 stpui_get_image_filename(void)
695 {
696 stpui_set_image_filename(image_filename);
697 return(image_filename);
698 }
699
700 static void
701 default_errfunc(void *data, const char *buffer, size_t bytes)
702 {
703 fwrite(buffer, 1, bytes, data ? data : stderr);
704 }
705
706 void
707 stpui_set_errfunc(stp_outfunc_t wfunc)
708 {
709 the_errfunc = wfunc;
710 }
711
712 stp_outfunc_t
713 stpui_get_errfunc(void)
714 {
715 return the_errfunc;
716 }
717
718 void
719 stpui_set_errdata(void *errdata)
720 {
721 the_errdata = errdata;
722 }
723
724 void *
725 stpui_get_errdata(void)
726 {
727 return the_errdata;
728 }
729
730 void
731 stpui_set_thumbnail_func(get_thumbnail_func_t func)
732 {
733 thumbnail_func = func;
734 }
735
736 get_thumbnail_func_t
737 stpui_get_thumbnail_func(void)
738 {
739 return thumbnail_func;
740 }
741
742 void
743 stpui_set_thumbnail_data(void *data)
744 {
745 thumbnail_private_data = data;
746 }
747
748 void *
749 stpui_get_thumbnail_data(void)
750 {
751 return thumbnail_private_data;
752 }
753
754 GtkWidget *
755 stpui_create_entry(GtkWidget *table, int hpos, int vpos, const char *text,
756 const char *help, GCallback callback)
757 {
758 GtkWidget *entry = gtk_entry_new();
759 gtk_widget_set_usize(entry, 60, 0);
760 stpui_table_attach_aligned(GTK_TABLE(table), hpos, vpos, text,
761 0.0, 0.5, entry, 1, TRUE);
762 stpui_set_help_data(entry, help);
763 g_signal_connect(G_OBJECT(entry), "activate",
764 G_CALLBACK(callback), NULL);
765 return entry;
766 }
767
768 GSList *
769 stpui_create_radio_button(radio_group_t *radio, GSList *group,
770 GtkWidget *table, int hpos, int vpos,
771 GCallback callback)
772 {
773 radio->button = gtk_radio_button_new_with_label(group, gettext(radio->name));
774 group = gtk_radio_button_group(GTK_RADIO_BUTTON(radio->button));
775 stpui_table_attach_aligned(GTK_TABLE(table), hpos, vpos, NULL, 0.5, 0.5,
776 radio->button, 1, FALSE);
777 stpui_set_help_data(radio->button, gettext(radio->help));
778 g_signal_connect(G_OBJECT(radio->button), "toggled",
779 G_CALLBACK(callback), cast_safe(radio->value));
780 return group;
781 }
782
783 void
784 stpui_set_adjustment_tooltip (GtkObject *adj, const gchar *tip)
785 {
786 stpui_set_help_data (GTK_WIDGET (SCALE_ENTRY_SCALE (adj)), tip);
787 stpui_set_help_data (GTK_WIDGET (SCALE_ENTRY_SPINBUTTON (adj)), tip);
788 }
789
790 static GtkWidget *
791 table_label(GtkTable *table, gint column, gint row)
792 {
793 GList *children = table->children;;
794 while (children)
795 {
796 GtkTableChild *child = (GtkTableChild *)children->data;
797 if (child->left_attach == column + 1 && child->top_attach == row)
798 return child->widget;
799 children = children->next;
800 }
801 return NULL;
802 }
803
804 void
805 stpui_create_new_combo(option_t *option, GtkWidget *table,
806 int hpos, int vpos, gboolean is_optional)
807 {
808 GtkWidget *event_box = gtk_event_box_new();
809 GtkWidget *combo = gtk_combo_new();
810 (void)is_optional;
811
812 option->checkbox = gtk_check_button_new();
813 gtk_table_attach(GTK_TABLE(table), option->checkbox,
814 hpos, hpos + 1, vpos, vpos + 1,
815 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
816
817 option->info.list.combo = combo;
818 gtk_container_add(GTK_CONTAINER(event_box), combo);
819 gtk_widget_show(combo);
820 gtk_widget_show(event_box);
821 stpui_set_help_data(event_box, gettext(option->fast_desc->help));
822 stpui_table_attach_aligned
823 (GTK_TABLE(table), hpos + 1, vpos, gettext(option->fast_desc->text),
824 0.0, 0.5, event_box, 2, TRUE);
825 option->info.list.label = table_label(GTK_TABLE(table), hpos, vpos);
826 }
827
828 const char *
829 stpui_combo_get_name(GtkWidget *combo,
830 const stp_string_list_t *options)
831 {
832 if (options)
833 {
834 gint i;
835 gint num_options = stp_string_list_count(options);
836 const gchar *text = (gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)));
837
838 if (text == NULL)
839 return (NULL);
840
841 if (num_options == 0)
842 return ((const char *)text);
843
844 for (i = 0; i < num_options; i ++)
845 if (strcmp(stp_string_list_param(options, i)->text, text) == 0)
846 return (stp_string_list_param(options, i)->name);
847 }
848 return (NULL);
849 }
850
851 void
852 stpui_create_scale_entry(option_t *opt,
853 GtkTable *table,
854 gint column,
855 gint row,
856 const gchar *text,
857 gint scale_usize,
858 gint spinbutton_usize,
859 gfloat value,
860 gfloat lower,
861 gfloat upper,
862 gfloat step_increment,
863 gfloat page_increment,
864 guint digits,
865 gboolean constrain,
866 gfloat unconstrained_lower,
867 gfloat unconstrained_upper,
868 const gchar *tooltip,
869 gboolean is_optional)
870 {
871 (void)is_optional;
872 opt->checkbox = gtk_check_button_new();
873 gtk_table_attach(GTK_TABLE(table), opt->checkbox,
874 column, column + 1, row, row + 1,
875 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
876 opt->info.flt.adjustment =
877 stpui_scale_entry_new(table, column, row, text, scale_usize,
878 spinbutton_usize, value, lower, upper,
879 step_increment, page_increment, digits, constrain,
880 unconstrained_lower, unconstrained_upper, tooltip);
881 }