1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
5
* Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
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 2 of the License, or (at your option) any later version.
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.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#include "libgimpbase/gimpbase.h"
29
#include "gimpwidgetstypes.h"
31
#include "gimpdialog.h"
32
#include "gimppixmap.h"
33
#include "gimpquerybox.h"
34
#include "gimpsizeentry.h"
35
#include "gimpwidgets.h"
37
#include "libgimp/libgimp-intl.h"
41
* String, integer, double and size query boxes
44
typedef struct _QueryBox QueryBox;
52
gulong response_handler;
54
gpointer callback_data;
58
static QueryBox * create_query_box (const gchar *title,
60
GimpHelpFunc help_func,
62
GCallback response_callback,
63
const gchar *stock_id,
65
const gchar *ok_button,
66
const gchar *cancel_button,
70
gpointer callback_data);
72
static void query_box_disconnect (QueryBox *query_box);
74
static void string_query_box_response (GtkWidget *widget,
77
static void int_query_box_response (GtkWidget *widget,
80
static void double_query_box_response (GtkWidget *widget,
83
static void size_query_box_response (GtkWidget *widget,
86
static void boolean_query_box_response (GtkWidget *widget,
90
static void query_box_cancel_callback (QueryBox *query_box);
94
* create a generic query box without any entry widget
97
create_query_box (const gchar *title,
99
GimpHelpFunc help_func,
100
const gchar *help_id,
101
GCallback response_callback,
102
const gchar *stock_id,
103
const gchar *message,
104
const gchar *ok_button,
105
const gchar *cancel_button,
109
gpointer callback_data)
112
GtkWidget *hbox = NULL;
115
/* make sure the object / signal passed are valid
117
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
118
g_return_val_if_fail (object == NULL || G_IS_OBJECT (object), NULL);
119
g_return_val_if_fail (object == NULL || signal != NULL, NULL);
121
query_box = g_new0 (QueryBox, 1);
123
query_box->qbox = gimp_dialog_new (title, "gimp-query-box",
127
cancel_button, GTK_RESPONSE_CANCEL,
128
ok_button, GTK_RESPONSE_OK,
132
query_box->response_handler =
133
g_signal_connect (query_box->qbox, "response",
134
G_CALLBACK (response_callback),
137
g_signal_connect (query_box->qbox, "destroy",
138
G_CALLBACK (gtk_widget_destroyed),
141
/* if we are associated with an object, connect to the provided signal
147
closure = g_cclosure_new_swap (G_CALLBACK (query_box_cancel_callback),
149
g_object_watch_closure (G_OBJECT (query_box->qbox), closure);
151
g_signal_connect_closure (object, signal, closure, FALSE);
158
hbox = gtk_hbox_new (FALSE, 12);
159
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
160
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (query_box->qbox)->vbox),
162
gtk_widget_show (hbox);
164
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_DIALOG);
165
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
166
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
167
gtk_widget_show (image);
170
query_box->vbox = gtk_vbox_new (FALSE, 12);
172
g_object_set_data (G_OBJECT (query_box->qbox), "gimp-query-box-vbox",
177
gtk_box_pack_start (GTK_BOX (hbox), query_box->vbox, FALSE, FALSE, 0);
181
gtk_container_set_border_width (GTK_CONTAINER (query_box->vbox), 12);
182
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (query_box->qbox)->vbox),
186
gtk_widget_show (query_box->vbox);
190
label = gtk_label_new (message);
191
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
192
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
193
gtk_box_pack_start (GTK_BOX (query_box->vbox), label, FALSE, FALSE, 0);
194
gtk_widget_show (label);
197
query_box->entry = NULL;
198
query_box->object = object;
199
query_box->callback = callback;
200
query_box->callback_data = callback_data;
206
* gimp_query_string_box:
207
* @title: The query box dialog's title.
208
* @parent: The dialog's parent widget.
209
* @help_func: The help function to show this dialog's help page.
210
* @help_id: A string identifying this dialog's help page.
211
* @message: A string which will be shown above the dialog's entry widget.
212
* @initial: The initial value.
213
* @object: The object this query box is associated with.
214
* @signal: The object's signal which will cause the query box to be closed.
215
* @callback: The function which will be called when the user selects "OK".
216
* @data: The callback's user data.
218
* Creates a new #GtkDialog that queries the user for a string value.
220
* Returns: A pointer to the new #GtkDialog.
223
gimp_query_string_box (const gchar *title,
225
GimpHelpFunc help_func,
226
const gchar *help_id,
227
const gchar *message,
228
const gchar *initial,
231
GimpQueryStringCallback callback,
237
query_box = create_query_box (title, parent, help_func, help_id,
238
G_CALLBACK (string_query_box_response),
239
GTK_STOCK_DIALOG_QUESTION,
241
GTK_STOCK_OK, GTK_STOCK_CANCEL,
243
G_CALLBACK (callback), data);
248
entry = gtk_entry_new ();
249
gtk_entry_set_text (GTK_ENTRY (entry), initial ? initial : "");
250
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
251
gtk_box_pack_start (GTK_BOX (query_box->vbox), entry, FALSE, FALSE, 0);
252
gtk_widget_grab_focus (entry);
253
gtk_widget_show (entry);
255
query_box->entry = entry;
257
return query_box->qbox;
261
* gimp_query_int_box:
262
* @title: The query box dialog's title.
263
* @parent: The dialog's parent widget.
264
* @help_func: The help function to show this dialog's help page.
265
* @help_id: A string identifying this dialog's help page.
266
* @message: A string which will be shown above the dialog's entry widget.
267
* @initial: The initial value.
268
* @lower: The lower boundary of the range of possible values.
269
* @upper: The upper boundray of the range of possible values.
270
* @object: The object this query box is associated with.
271
* @signal: The object's signal which will cause the query box to be closed.
272
* @callback: The function which will be called when the user selects "OK".
273
* @data: The callback's user data.
275
* Creates a new #GtkDialog that queries the user for an integer value.
277
* Returns: A pointer to the new #GtkDialog.
280
gimp_query_int_box (const gchar *title,
282
GimpHelpFunc help_func,
283
const gchar *help_id,
284
const gchar *message,
290
GimpQueryIntCallback callback,
294
GtkWidget *spinbutton;
295
GtkObject *adjustment;
297
query_box = create_query_box (title, parent, help_func, help_id,
298
G_CALLBACK (int_query_box_response),
299
GTK_STOCK_DIALOG_QUESTION,
301
GTK_STOCK_OK, GTK_STOCK_CANCEL,
303
G_CALLBACK (callback), data);
308
spinbutton = gimp_spin_button_new (&adjustment,
309
initial, lower, upper, 1, 10, 0,
311
gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
312
gtk_box_pack_start (GTK_BOX (query_box->vbox), spinbutton, FALSE, FALSE, 0);
313
gtk_widget_grab_focus (spinbutton);
314
gtk_widget_show (spinbutton);
316
query_box->entry = spinbutton;
318
return query_box->qbox;
322
* gimp_query_double_box:
323
* @title: The query box dialog's title.
324
* @parent: The dialog's parent widget.
325
* @help_func: The help function to show this dialog's help page.
326
* @help_id: A string identifying this dialog's help page.
327
* @message: A string which will be shown above the dialog's entry widget.
328
* @initial: The initial value.
329
* @lower: The lower boundary of the range of possible values.
330
* @upper: The upper boundray of the range of possible values.
331
* @digits: The number of decimal digits the #GtkSpinButton will provide.
332
* @object: The object this query box is associated with.
333
* @signal: The object's signal which will cause the query box to be closed.
334
* @callback: The function which will be called when the user selects "OK".
335
* @data: The callback's user data.
337
* Creates a new #GtkDialog that queries the user for a double value.
339
* Returns: A pointer to the new #GtkDialog.
342
gimp_query_double_box (const gchar *title,
344
GimpHelpFunc help_func,
345
const gchar *help_id,
346
const gchar *message,
353
GimpQueryDoubleCallback callback,
357
GtkWidget *spinbutton;
358
GtkObject *adjustment;
360
query_box = create_query_box (title, parent, help_func, help_id,
361
G_CALLBACK (double_query_box_response),
362
GTK_STOCK_DIALOG_QUESTION,
364
GTK_STOCK_OK, GTK_STOCK_CANCEL,
366
G_CALLBACK (callback), data);
371
spinbutton = gimp_spin_button_new (&adjustment,
372
initial, lower, upper, 1, 10, 0,
374
gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
375
gtk_box_pack_start (GTK_BOX (query_box->vbox), spinbutton, FALSE, FALSE, 0);
376
gtk_widget_grab_focus (spinbutton);
377
gtk_widget_show (spinbutton);
379
query_box->entry = spinbutton;
381
return query_box->qbox;
385
* gimp_query_size_box:
386
* @title: The query box dialog's title.
387
* @parent: The dialog's parent widget.
388
* @help_func: The help function to show this dialog's help page.
389
* @help_id: A string identifying this dialog's help page.
390
* @message: A string which will be shown above the dialog's entry widget.
391
* @initial: The initial value.
392
* @lower: The lower boundary of the range of possible values.
393
* @upper: The upper boundray of the range of possible values.
394
* @digits: The number of decimal digits the #GimpSizeEntry provide in
396
* @unit: The unit initially shown by the #GimpUnitMenu.
397
* @resolution: The resolution (in dpi) which will be used for pixel/unit
399
* @dot_for_dot: %TRUE if the #GimpUnitMenu's initial unit should be "pixels".
400
* @object: The object this query box is associated with.
401
* @signal: The object's signal which will cause the query box
403
* @callback: The function which will be called when the user selects "OK".
404
* @data: The callback's user data.
406
* Creates a new #GtkDialog that queries the user for a size using a
409
* Returns: A pointer to the new #GtkDialog.
412
gimp_query_size_box (const gchar *title,
414
GimpHelpFunc help_func,
415
const gchar *help_id,
416
const gchar *message,
423
gboolean dot_for_dot,
426
GimpQuerySizeCallback callback,
430
GtkWidget *sizeentry;
431
GtkWidget *spinbutton;
433
query_box = create_query_box (title, parent, help_func, help_id,
434
G_CALLBACK (size_query_box_response),
435
GTK_STOCK_DIALOG_QUESTION,
437
GTK_STOCK_OK, GTK_STOCK_CANCEL,
439
G_CALLBACK (callback), data);
444
sizeentry = gimp_size_entry_new (1, unit, "%p", TRUE, FALSE, FALSE, 12,
445
GIMP_SIZE_ENTRY_UPDATE_SIZE);
447
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (sizeentry), GIMP_UNIT_PIXEL);
448
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (sizeentry), 0,
450
gimp_size_entry_set_refval_digits (GIMP_SIZE_ENTRY (sizeentry), 0, digits);
451
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (sizeentry), 0,
453
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (sizeentry), 0, initial);
455
spinbutton = gimp_size_entry_get_help_widget (GIMP_SIZE_ENTRY (sizeentry), 0);
456
gtk_entry_set_activates_default (GTK_ENTRY (spinbutton), TRUE);
458
gtk_box_pack_start (GTK_BOX (query_box->vbox), sizeentry, FALSE, FALSE, 0);
459
gimp_size_entry_grab_focus (GIMP_SIZE_ENTRY (sizeentry));
460
gtk_widget_show (sizeentry);
462
query_box->entry = sizeentry;
464
return query_box->qbox;
468
* gimp_query_boolean_box:
469
* @title: The query box dialog's title.
470
* @parent: The dialog's parent widget.
471
* @help_func: The help function to show this dialog's help page.
472
* @help_id: A string identifying this dialog's help page.
473
* @stock_id: A stock_id to specify an icon to appear on the left
474
* on the dialog's message.
475
* @message: A string which will be shown in the query box.
476
* @true_button: The string to be shown in the dialog's left button.
477
* @false_button: The string to be shown in the dialog's right button.
478
* @object: The object this query box is associated with.
479
* @signal: The object's signal which will cause the query box
481
* @callback: The function which will be called when the user clicks one
483
* @data: The callback's user data.
485
* Creates a new #GtkDialog that asks the user to do a boolean decision.
487
* Returns: A pointer to the new #GtkDialog.
490
gimp_query_boolean_box (const gchar *title,
492
GimpHelpFunc help_func,
493
const gchar *help_id,
494
const gchar *stock_id,
495
const gchar *message,
496
const gchar *true_button,
497
const gchar *false_button,
500
GimpQueryBooleanCallback callback,
505
query_box = create_query_box (title, parent, help_func, help_id,
506
G_CALLBACK (boolean_query_box_response),
509
true_button, false_button,
511
G_CALLBACK (callback), data);
516
return query_box->qbox;
525
query_box_disconnect (QueryBox *query_box)
527
gtk_widget_set_sensitive (query_box->qbox, FALSE);
529
/* disconnect the response callback to avoid that it may be run twice */
530
if (query_box->response_handler)
532
g_signal_handler_disconnect (query_box->qbox,
533
query_box->response_handler);
535
query_box->response_handler = 0;
538
/* disconnect, if we are connected to some signal */
539
if (query_box->object)
540
g_signal_handlers_disconnect_by_func (query_box->object,
541
query_box_cancel_callback,
546
string_query_box_response (GtkWidget *widget,
552
query_box_disconnect (query_box);
554
/* Get the entry data */
555
string = gtk_entry_get_text (GTK_ENTRY (query_box->entry));
557
/* Call the user defined callback */
558
if (response_id == GTK_RESPONSE_OK)
559
(* (GimpQueryStringCallback) query_box->callback) (query_box->qbox,
561
query_box->callback_data);
563
/* Destroy the box */
565
gtk_widget_destroy (query_box->qbox);
571
int_query_box_response (GtkWidget *widget,
577
query_box_disconnect (query_box);
579
/* Get the spinbutton data */
580
value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (query_box->entry));
582
/* Call the user defined callback */
583
if (response_id == GTK_RESPONSE_OK)
584
(* (GimpQueryIntCallback) query_box->callback) (query_box->qbox,
586
query_box->callback_data);
588
/* Destroy the box */
590
gtk_widget_destroy (query_box->qbox);
596
double_query_box_response (GtkWidget *widget,
602
query_box_disconnect (query_box);
604
/* Get the spinbutton data */
605
value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (query_box->entry));
607
/* Call the user defined callback */
608
if (response_id == GTK_RESPONSE_OK)
609
(* (GimpQueryDoubleCallback) query_box->callback) (query_box->qbox,
611
query_box->callback_data);
613
/* Destroy the box */
615
gtk_widget_destroy (query_box->qbox);
621
size_query_box_response (GtkWidget *widget,
628
query_box_disconnect (query_box);
630
/* Get the sizeentry data */
631
size = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (query_box->entry), 0);
632
unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (query_box->entry));
634
/* Call the user defined callback */
635
if (response_id == GTK_RESPONSE_OK)
636
(* (GimpQuerySizeCallback) query_box->callback) (query_box->qbox,
639
query_box->callback_data);
641
/* Destroy the box */
643
gtk_widget_destroy (query_box->qbox);
649
boolean_query_box_response (GtkWidget *widget,
653
query_box_disconnect (query_box);
655
/* Call the user defined callback */
656
(* (GimpQueryBooleanCallback) query_box->callback) (query_box->qbox,
659
query_box->callback_data);
661
/* Destroy the box */
663
gtk_widget_destroy (query_box->qbox);
669
query_box_cancel_callback (QueryBox *query_box)
671
query_box_disconnect (query_box);
673
/* Destroy the box */
675
gtk_widget_destroy (query_box->qbox);