1 /* LIBGIMP - The GIMP Library
2  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
3  *
4  * gimpquerybox.c
5  * Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 3 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library.  If not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #include "config.h"
23 
24 #include <gegl.h>
25 #include <gtk/gtk.h>
26 
27 #include "libgimpbase/gimpbase.h"
28 
29 #include "gimpwidgetstypes.h"
30 
31 #include "gimpdialog.h"
32 #include "gimppixmap.h"
33 #include "gimpquerybox.h"
34 #include "gimpsizeentry.h"
35 #include "gimpspinbutton.h"
36 #include "gimpwidgets.h"
37 
38 #include "libgimp/libgimp-intl.h"
39 
40 
41 /**
42  * SECTION: gimpquerybox
43  * @title: GimpQueryBox
44  * @short_description: Some simple dialogs to enter a single int,
45  *                     double, string or boolean value.
46  * @see_also: #GimpSizeEntry, #GimpUnitMenu
47  *
48  * These functions provide simple dialogs for entering a single
49  * string, integer, double, boolean or pixel size value.
50  *
51  * They return a pointer to a #GtkDialog which has to be shown with
52  * gtk_widget_show() by the caller.
53  *
54  * The dialogs contain an entry widget for the kind of value they ask
55  * for and "OK" and "Cancel" buttons. On "Cancel", all query boxes
56  * except the boolean one silently destroy themselves. On "OK" the
57  * user defined callback function is called and returns the entered
58  * value.
59  **/
60 
61 
62 /*
63  *  String, integer, double and size query boxes
64  */
65 
66 typedef struct _QueryBox QueryBox;
67 
68 struct _QueryBox
69 {
70   GtkWidget *qbox;
71   GtkWidget *vbox;
72   GtkWidget *entry;
73   GObject   *object;
74   gulong     response_handler;
75   GCallback  callback;
76   gpointer   callback_data;
77 };
78 
79 
80 static QueryBox * create_query_box             (const gchar   *title,
81                                                 GtkWidget     *parent,
82                                                 GimpHelpFunc   help_func,
83                                                 const gchar   *help_id,
84                                                 GCallback      response_callback,
85                                                 const gchar   *icon_name,
86                                                 const gchar   *message,
87                                                 const gchar   *ok_button,
88                                                 const gchar   *cancel_button,
89                                                 GObject       *object,
90                                                 const gchar   *signal,
91                                                 GCallback      callback,
92                                                 gpointer       callback_data);
93 
94 static void       query_box_disconnect         (QueryBox      *query_box);
95 static void       query_box_destroy            (QueryBox      *query_box);
96 
97 static void       string_query_box_response    (GtkWidget     *widget,
98                                                 gint           response_id,
99                                                 QueryBox      *query_box);
100 static void       int_query_box_response       (GtkWidget     *widget,
101                                                 gint           response_id,
102                                                 QueryBox      *query_box);
103 static void       double_query_box_response    (GtkWidget     *widget,
104                                                 gint           response_id,
105                                                 QueryBox      *query_box);
106 static void       size_query_box_response      (GtkWidget     *widget,
107                                                 gint           response_id,
108                                                 QueryBox      *query_box);
109 static void       boolean_query_box_response   (GtkWidget     *widget,
110                                                 gint           response_id,
111                                                 QueryBox      *query_box);
112 
113 static void       query_box_cancel_callback    (QueryBox      *query_box);
114 
115 
116 /*
117  *  create a generic query box without any entry widget
118  */
119 static QueryBox *
create_query_box(const gchar * title,GtkWidget * parent,GimpHelpFunc help_func,const gchar * help_id,GCallback response_callback,const gchar * icon_name,const gchar * message,const gchar * ok_button,const gchar * cancel_button,GObject * object,const gchar * signal,GCallback callback,gpointer callback_data)120 create_query_box (const gchar   *title,
121                   GtkWidget     *parent,
122                   GimpHelpFunc   help_func,
123                   const gchar   *help_id,
124                   GCallback      response_callback,
125                   const gchar   *icon_name,
126                   const gchar   *message,
127                   const gchar   *ok_button,
128                   const gchar   *cancel_button,
129                   GObject       *object,
130                   const gchar   *signal,
131                   GCallback      callback,
132                   gpointer       callback_data)
133 {
134   QueryBox  *query_box;
135   GtkWidget *hbox = NULL;
136   GtkWidget *label;
137 
138   /*  make sure the object / signal passed are valid
139    */
140   g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
141   g_return_val_if_fail (object == NULL || G_IS_OBJECT (object), NULL);
142   g_return_val_if_fail (object == NULL || signal != NULL, NULL);
143 
144   query_box = g_slice_new0 (QueryBox);
145 
146   query_box->qbox = gimp_dialog_new (title, "gimp-query-box",
147                                      parent, 0,
148                                      help_func, help_id,
149 
150                                      cancel_button, GTK_RESPONSE_CANCEL,
151                                      ok_button,     GTK_RESPONSE_OK,
152 
153                                      NULL);
154 
155   gtk_dialog_set_alternative_button_order (GTK_DIALOG (query_box->qbox),
156                                            GTK_RESPONSE_OK,
157                                            GTK_RESPONSE_CANCEL,
158                                            -1);
159 
160   query_box->response_handler =
161     g_signal_connect (query_box->qbox, "response",
162                       G_CALLBACK (response_callback),
163                       query_box);
164 
165   g_signal_connect (query_box->qbox, "destroy",
166                     G_CALLBACK (gtk_widget_destroyed),
167                     &query_box->qbox);
168 
169   /*  if we are associated with an object, connect to the provided signal
170    */
171   if (object)
172     {
173       GClosure *closure;
174 
175       closure = g_cclosure_new_swap (G_CALLBACK (query_box_cancel_callback),
176                                      query_box, NULL);
177       g_object_watch_closure (G_OBJECT (query_box->qbox), closure);
178 
179       g_signal_connect_closure (object, signal, closure, FALSE);
180     }
181 
182   if (icon_name)
183     {
184       GtkWidget *content_area;
185       GtkWidget *image;
186 
187       content_area = gtk_dialog_get_content_area (GTK_DIALOG (query_box->qbox));
188 
189       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
190       gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
191       gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
192       gtk_widget_show (hbox);
193 
194       image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG);
195       gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
196       gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
197       gtk_widget_show (image);
198     }
199 
200   query_box->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
201 
202   g_object_set_data (G_OBJECT (query_box->qbox), "gimp-query-box-vbox",
203                      query_box->vbox);
204 
205   if (hbox)
206     {
207       gtk_box_pack_start (GTK_BOX (hbox), query_box->vbox, FALSE, FALSE, 0);
208     }
209   else
210     {
211       GtkWidget *content_area;
212 
213       content_area = gtk_dialog_get_content_area (GTK_DIALOG (query_box->qbox));
214 
215       gtk_container_set_border_width (GTK_CONTAINER (query_box->vbox), 12);
216       gtk_box_pack_start (GTK_BOX (content_area), query_box->vbox,
217                           TRUE, TRUE, 0);
218     }
219 
220   gtk_widget_show (query_box->vbox);
221 
222   if (message)
223     {
224       label = gtk_label_new (message);
225       gtk_label_set_xalign (GTK_LABEL (label), 0.0);
226       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
227       gtk_box_pack_start (GTK_BOX (query_box->vbox), label, FALSE, FALSE, 0);
228       gtk_widget_show (label);
229     }
230 
231   query_box->entry         = NULL;
232   query_box->object        = object;
233   query_box->callback      = callback;
234   query_box->callback_data = callback_data;
235 
236   return query_box;
237 }
238 
239 /**
240  * gimp_query_string_box:
241  * @title:     The query box dialog's title.
242  * @parent:    The dialog's parent widget.
243  * @help_func: The help function to show this dialog's help page.
244  * @help_id:   A string identifying this dialog's help page.
245  * @message:   A string which will be shown above the dialog's entry widget.
246  * @initial:   The initial value.
247  * @object:    The object this query box is associated with.
248  * @signal:    The object's signal which will cause the query box to be closed.
249  * @callback:  The function which will be called when the user selects "OK".
250  * @data:      The callback's user data.
251  *
252  * Creates a new #GtkDialog that queries the user for a string value.
253  *
254  * Returns: A pointer to the new #GtkDialog.
255  **/
256 GtkWidget *
gimp_query_string_box(const gchar * title,GtkWidget * parent,GimpHelpFunc help_func,const gchar * help_id,const gchar * message,const gchar * initial,GObject * object,const gchar * signal,GimpQueryStringCallback callback,gpointer data)257 gimp_query_string_box (const gchar             *title,
258                        GtkWidget               *parent,
259                        GimpHelpFunc             help_func,
260                        const gchar             *help_id,
261                        const gchar             *message,
262                        const gchar             *initial,
263                        GObject                 *object,
264                        const gchar             *signal,
265                        GimpQueryStringCallback  callback,
266                        gpointer                 data)
267 {
268   QueryBox  *query_box;
269   GtkWidget *entry;
270 
271   query_box = create_query_box (title, parent, help_func, help_id,
272                                 G_CALLBACK (string_query_box_response),
273                                 "dialog-question",
274                                 message,
275                                 _("_OK"), _("_Cancel"),
276                                 object, signal,
277                                 G_CALLBACK (callback), data);
278 
279   if (! query_box)
280     return NULL;
281 
282   entry = gtk_entry_new ();
283   gtk_entry_set_text (GTK_ENTRY (entry), initial ? initial : "");
284   gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
285   gtk_box_pack_start (GTK_BOX (query_box->vbox), entry, FALSE, FALSE, 0);
286   gtk_widget_grab_focus (entry);
287   gtk_widget_show (entry);
288 
289   query_box->entry = entry;
290 
291   return query_box->qbox;
292 }
293 
294 /**
295  * gimp_query_int_box:
296  * @title:     The query box dialog's title.
297  * @parent:    The dialog's parent widget.
298  * @help_func: The help function to show this dialog's help page.
299  * @help_id:   A string identifying this dialog's help page.
300  * @message:   A string which will be shown above the dialog's entry widget.
301  * @initial:   The initial value.
302  * @lower:     The lower boundary of the range of possible values.
303  * @upper:     The upper boundray of the range of possible values.
304  * @object:    The object this query box is associated with.
305  * @signal:    The object's signal which will cause the query box to be closed.
306  * @callback:  The function which will be called when the user selects "OK".
307  * @data:      The callback's user data.
308  *
309  * Creates a new #GtkDialog that queries the user for an integer value.
310  *
311  * Returns: A pointer to the new #GtkDialog.
312  **/
313 GtkWidget *
gimp_query_int_box(const gchar * title,GtkWidget * parent,GimpHelpFunc help_func,const gchar * help_id,const gchar * message,gint initial,gint lower,gint upper,GObject * object,const gchar * signal,GimpQueryIntCallback callback,gpointer data)314 gimp_query_int_box (const gchar          *title,
315                     GtkWidget            *parent,
316                     GimpHelpFunc          help_func,
317                     const gchar          *help_id,
318                     const gchar          *message,
319                     gint                  initial,
320                     gint                  lower,
321                     gint                  upper,
322                     GObject              *object,
323                     const gchar          *signal,
324                     GimpQueryIntCallback  callback,
325                     gpointer              data)
326 {
327   QueryBox      *query_box;
328   GtkWidget     *spinbutton;
329   GtkAdjustment *adjustment;
330 
331   query_box = create_query_box (title, parent, help_func, help_id,
332                                 G_CALLBACK (int_query_box_response),
333                                 "dialog-question",
334                                 message,
335                                 _("_OK"), _("_Cancel"),
336                                 object, signal,
337                                 G_CALLBACK (callback), data);
338 
339   if (! query_box)
340     return NULL;
341 
342   adjustment = (GtkAdjustment *)
343     gtk_adjustment_new (initial, lower, upper, 1, 10, 0);
344   spinbutton = gimp_spin_button_new (adjustment, 1.0, 0);
345   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
346   gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
347   gtk_box_pack_start (GTK_BOX (query_box->vbox), spinbutton, FALSE, FALSE, 0);
348   gtk_widget_grab_focus (spinbutton);
349   gtk_widget_show (spinbutton);
350 
351   query_box->entry = spinbutton;
352 
353   return query_box->qbox;
354 }
355 
356 /**
357  * gimp_query_double_box:
358  * @title:     The query box dialog's title.
359  * @parent:    The dialog's parent widget.
360  * @help_func: The help function to show this dialog's help page.
361  * @help_id:   A string identifying this dialog's help page.
362  * @message:   A string which will be shown above the dialog's entry widget.
363  * @initial:   The initial value.
364  * @lower:     The lower boundary of the range of possible values.
365  * @upper:     The upper boundray of the range of possible values.
366  * @digits:    The number of decimal digits the #GtkSpinButton will provide.
367  * @object:    The object this query box is associated with.
368  * @signal:    The object's signal which will cause the query box to be closed.
369  * @callback:  The function which will be called when the user selects "OK".
370  * @data:      The callback's user data.
371  *
372  * Creates a new #GtkDialog that queries the user for a double value.
373  *
374  * Returns: A pointer to the new #GtkDialog.
375  **/
376 GtkWidget *
gimp_query_double_box(const gchar * title,GtkWidget * parent,GimpHelpFunc help_func,const gchar * help_id,const gchar * message,gdouble initial,gdouble lower,gdouble upper,gint digits,GObject * object,const gchar * signal,GimpQueryDoubleCallback callback,gpointer data)377 gimp_query_double_box (const gchar             *title,
378                        GtkWidget               *parent,
379                        GimpHelpFunc             help_func,
380                        const gchar             *help_id,
381                        const gchar             *message,
382                        gdouble                  initial,
383                        gdouble                  lower,
384                        gdouble                  upper,
385                        gint                     digits,
386                        GObject                 *object,
387                        const gchar             *signal,
388                        GimpQueryDoubleCallback  callback,
389                        gpointer                 data)
390 {
391   QueryBox      *query_box;
392   GtkWidget     *spinbutton;
393   GtkAdjustment *adjustment;
394 
395   query_box = create_query_box (title, parent, help_func, help_id,
396                                 G_CALLBACK (double_query_box_response),
397                                 "dialog-question",
398                                 message,
399                                 _("_OK"), _("_Cancel"),
400                                 object, signal,
401                                 G_CALLBACK (callback), data);
402 
403   if (! query_box)
404     return NULL;
405 
406   adjustment = (GtkAdjustment *)
407     gtk_adjustment_new (initial, lower, upper, 1, 10, 0);
408   spinbutton = gimp_spin_button_new (adjustment, 1.0, 0);
409   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
410   gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
411   gtk_box_pack_start (GTK_BOX (query_box->vbox), spinbutton, FALSE, FALSE, 0);
412   gtk_widget_grab_focus (spinbutton);
413   gtk_widget_show (spinbutton);
414 
415   query_box->entry = spinbutton;
416 
417   return query_box->qbox;
418 }
419 
420 /**
421  * gimp_query_size_box:
422  * @title:       The query box dialog's title.
423  * @parent:      The dialog's parent widget.
424  * @help_func:   The help function to show this dialog's help page.
425  * @help_id:     A string identifying this dialog's help page.
426  * @message:     A string which will be shown above the dialog's entry widget.
427  * @initial:     The initial value.
428  * @lower:       The lower boundary of the range of possible values.
429  * @upper:       The upper boundray of the range of possible values.
430  * @digits:      The number of decimal digits the #GimpSizeEntry provide in
431  *               "pixel" mode.
432  * @unit:        The unit initially shown by the #GimpUnitMenu.
433  * @resolution:  The resolution (in dpi) which will be used for pixel/unit
434  *               calculations.
435  * @dot_for_dot: %TRUE if the #GimpUnitMenu's initial unit should be "pixels".
436  * @object:      The object this query box is associated with.
437  * @signal:      The object's signal which will cause the query box
438  *               to be closed.
439  * @callback:    The function which will be called when the user selects "OK".
440  * @data:        The callback's user data.
441  *
442  * Creates a new #GtkDialog that queries the user for a size using a
443  * #GimpSizeEntry.
444  *
445  * Returns: A pointer to the new #GtkDialog.
446  **/
447 GtkWidget *
gimp_query_size_box(const gchar * title,GtkWidget * parent,GimpHelpFunc help_func,const gchar * help_id,const gchar * message,gdouble initial,gdouble lower,gdouble upper,gint digits,GimpUnit unit,gdouble resolution,gboolean dot_for_dot,GObject * object,const gchar * signal,GimpQuerySizeCallback callback,gpointer data)448 gimp_query_size_box (const gchar           *title,
449                      GtkWidget             *parent,
450                      GimpHelpFunc           help_func,
451                      const gchar           *help_id,
452                      const gchar           *message,
453                      gdouble                initial,
454                      gdouble                lower,
455                      gdouble                upper,
456                      gint                   digits,
457                      GimpUnit               unit,
458                      gdouble                resolution,
459                      gboolean               dot_for_dot,
460                      GObject               *object,
461                      const gchar           *signal,
462                      GimpQuerySizeCallback  callback,
463                      gpointer               data)
464 {
465   QueryBox  *query_box;
466   GtkWidget *sizeentry;
467   GtkWidget *spinbutton;
468 
469   query_box = create_query_box (title, parent, help_func, help_id,
470                                 G_CALLBACK (size_query_box_response),
471                                 "dialog-question",
472                                 message,
473                                 _("_OK"), _("_Cancel"),
474                                 object, signal,
475                                 G_CALLBACK (callback), data);
476 
477   if (! query_box)
478     return NULL;
479 
480   sizeentry = gimp_size_entry_new (1, unit, "%p", TRUE, FALSE, FALSE, 12,
481                                    GIMP_SIZE_ENTRY_UPDATE_SIZE);
482   if (dot_for_dot)
483     gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), GIMP_UNIT_PIXEL);
484   gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
485                                   resolution, FALSE);
486   gimp_size_entry_set_refval_digits (GIMP_SIZE_ENTRY (sizeentry), 0, digits);
487   gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
488                                          lower, upper);
489   gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, initial);
490 
491   spinbutton = gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (sizeentry), 0);
492   gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
493 
494   gtk_box_pack_start (GTK_BOX (query_box->vbox), sizeentry, FALSE, FALSE, 0);
495   gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (sizeentry));
496   gtk_widget_show (sizeentry);
497 
498   query_box->entry = sizeentry;
499 
500   return query_box->qbox;
501 }
502 
503 /**
504  * gimp_query_boolean_box:
505  * @title:        The query box dialog's title.
506  * @parent:       The dialog's parent widget.
507  * @help_func:    The help function to show this dialog's help page.
508  * @help_id:      A string identifying this dialog's help page.
509  * @icon_name:    An icon name to specify an icon to appear on the left
510  *                on the dialog's message.
511  * @message:      A string which will be shown in the query box.
512  * @true_button:  The string to be shown in the dialog's left button.
513  * @false_button: The string to be shown in the dialog's right button.
514  * @object:       The object this query box is associated with.
515  * @signal:       The object's signal which will cause the query box
516  *                to be closed.
517  * @callback:     The function which will be called when the user clicks one
518  *                of the buttons.
519  * @data:         The callback's user data.
520  *
521  * Creates a new #GtkDialog that asks the user to do a boolean decision.
522  *
523  * Returns: A pointer to the new #GtkDialog.
524  **/
525 GtkWidget *
gimp_query_boolean_box(const gchar * title,GtkWidget * parent,GimpHelpFunc help_func,const gchar * help_id,const gchar * icon_name,const gchar * message,const gchar * true_button,const gchar * false_button,GObject * object,const gchar * signal,GimpQueryBooleanCallback callback,gpointer data)526 gimp_query_boolean_box (const gchar              *title,
527                         GtkWidget                *parent,
528                         GimpHelpFunc              help_func,
529                         const gchar              *help_id,
530                         const gchar              *icon_name,
531                         const gchar              *message,
532                         const gchar              *true_button,
533                         const gchar              *false_button,
534                         GObject                  *object,
535                         const gchar              *signal,
536                         GimpQueryBooleanCallback  callback,
537                         gpointer                  data)
538 {
539   QueryBox  *query_box;
540 
541   query_box = create_query_box (title, parent, help_func, help_id,
542                                 G_CALLBACK (boolean_query_box_response),
543                                 icon_name,
544                                 message,
545                                 true_button, false_button,
546                                 object, signal,
547                                 G_CALLBACK (callback), data);
548 
549   if (! query_box)
550     return NULL;
551 
552   return query_box->qbox;
553 }
554 
555 
556 /*
557  *  private functions
558  */
559 
560 static void
query_box_disconnect(QueryBox * query_box)561 query_box_disconnect (QueryBox *query_box)
562 {
563   gtk_widget_set_sensitive (query_box->qbox, FALSE);
564 
565   /*  disconnect the response callback to avoid that it may be run twice  */
566   if (query_box->response_handler)
567     {
568       g_signal_handler_disconnect (query_box->qbox,
569                                    query_box->response_handler);
570 
571       query_box->response_handler = 0;
572     }
573 
574   /*  disconnect, if we are connected to some signal  */
575   if (query_box->object)
576     g_signal_handlers_disconnect_by_func (query_box->object,
577                                           query_box_cancel_callback,
578                                           query_box);
579 }
580 
581 static void
query_box_destroy(QueryBox * query_box)582 query_box_destroy (QueryBox *query_box)
583 {
584   /*  Destroy the box  */
585   if (query_box->qbox)
586     gtk_widget_destroy (query_box->qbox);
587 
588   g_slice_free (QueryBox, query_box);
589 }
590 
591 static void
string_query_box_response(GtkWidget * widget,gint response_id,QueryBox * query_box)592 string_query_box_response (GtkWidget *widget,
593                            gint       response_id,
594                            QueryBox  *query_box)
595 {
596   const gchar *string;
597 
598   query_box_disconnect (query_box);
599 
600   /*  Get the entry data  */
601   string = gtk_entry_get_text (GTK_ENTRY (query_box->entry));
602 
603   /*  Call the user defined callback  */
604   if (response_id == GTK_RESPONSE_OK)
605     (* (GimpQueryStringCallback) query_box->callback) (query_box->qbox,
606                                                        string,
607                                                        query_box->callback_data);
608 
609   query_box_destroy (query_box);
610 }
611 
612 static void
int_query_box_response(GtkWidget * widget,gint response_id,QueryBox * query_box)613 int_query_box_response (GtkWidget *widget,
614                         gint       response_id,
615                         QueryBox  *query_box)
616 {
617   gint value;
618 
619   query_box_disconnect (query_box);
620 
621   /*  Get the spinbutton data  */
622   value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (query_box->entry));
623 
624   /*  Call the user defined callback  */
625   if (response_id == GTK_RESPONSE_OK)
626     (* (GimpQueryIntCallback) query_box->callback) (query_box->qbox,
627                                                     value,
628                                                     query_box->callback_data);
629 
630   query_box_destroy (query_box);
631 }
632 
633 static void
double_query_box_response(GtkWidget * widget,gint response_id,QueryBox * query_box)634 double_query_box_response (GtkWidget *widget,
635                            gint       response_id,
636                            QueryBox  *query_box)
637 {
638   gdouble value;
639 
640   query_box_disconnect (query_box);
641 
642   /*  Get the spinbutton data  */
643   value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (query_box->entry));
644 
645   /*  Call the user defined callback  */
646   if (response_id == GTK_RESPONSE_OK)
647     (* (GimpQueryDoubleCallback) query_box->callback) (query_box->qbox,
648                                                        value,
649                                                        query_box->callback_data);
650 
651   query_box_destroy (query_box);
652 }
653 
654 static void
size_query_box_response(GtkWidget * widget,gint response_id,QueryBox * query_box)655 size_query_box_response (GtkWidget *widget,
656                          gint       response_id,
657                          QueryBox  *query_box)
658 {
659   gdouble  size;
660   GimpUnit unit;
661 
662   query_box_disconnect (query_box);
663 
664   /*  Get the sizeentry data  */
665   size = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (query_box->entry), 0);
666   unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (query_box->entry));
667 
668   /*  Call the user defined callback  */
669   if (response_id == GTK_RESPONSE_OK)
670     (* (GimpQuerySizeCallback) query_box->callback) (query_box->qbox,
671                                                      size,
672                                                      unit,
673                                                      query_box->callback_data);
674 
675   query_box_destroy (query_box);
676 }
677 
678 static void
boolean_query_box_response(GtkWidget * widget,gint response_id,QueryBox * query_box)679 boolean_query_box_response (GtkWidget *widget,
680                             gint       response_id,
681                             QueryBox  *query_box)
682 {
683   query_box_disconnect (query_box);
684 
685   /*  Call the user defined callback  */
686   (* (GimpQueryBooleanCallback) query_box->callback) (query_box->qbox,
687                                                       (response_id ==
688                                                        GTK_RESPONSE_OK),
689                                                       query_box->callback_data);
690 
691   query_box_destroy (query_box);
692 }
693 
694 static void
query_box_cancel_callback(QueryBox * query_box)695 query_box_cancel_callback (QueryBox *query_box)
696 {
697   query_box_disconnect (query_box);
698   query_box_destroy (query_box);
699 }
700