2003-11-06 23:27:05 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2000-01-05 23:47:06 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpdialog.c
|
2003-11-06 23:27:05 +08:00
|
|
|
* Copyright (C) 2000-2003 Michael Natterer <mitch@gimp.org>
|
2000-01-05 23:47:06 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2000-02-26 11:41:06 +08:00
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2003-11-06 23:27:05 +08:00
|
|
|
*
|
2000-02-26 11:41:06 +08:00
|
|
|
* This library is distributed in the hope that it will be useful
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-01-05 23:47:06 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-05-31 07:38:46 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-05-31 07:38:46 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2000-05-31 07:38:46 +08:00
|
|
|
#include "gimpdialog.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gimphelpui.h"
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2003-11-21 22:19:15 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2004-07-09 05:57:05 +08:00
|
|
|
PROP_HELP_FUNC,
|
|
|
|
PROP_HELP_ID
|
2003-11-21 22:19:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-07-09 05:57:05 +08:00
|
|
|
static GObject * gimp_dialog_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
2005-01-07 06:19:35 +08:00
|
|
|
static void gimp_dialog_dispose (GObject *object);
|
2003-11-21 22:19:15 +08:00
|
|
|
static void gimp_dialog_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_dialog_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2006-01-08 01:47:24 +08:00
|
|
|
static void gimp_dialog_hide (GtkWidget *widget);
|
2002-11-18 08:04:16 +08:00
|
|
|
static gboolean gimp_dialog_delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event);
|
2003-03-20 23:49:48 +08:00
|
|
|
static void gimp_dialog_close (GtkDialog *dialog);
|
2006-01-03 20:40:13 +08:00
|
|
|
|
2004-10-05 00:21:52 +08:00
|
|
|
static void gimp_dialog_help (GObject *dialog);
|
2006-01-03 20:40:13 +08:00
|
|
|
static void gimp_dialog_response (GtkDialog *dialog,
|
|
|
|
gint response_id);
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpDialog, gimp_dialog, GTK_TYPE_DIALOG)
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_dialog_parent_class
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static gboolean show_help_button = TRUE;
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dialog_class_init (GimpDialogClass *klass)
|
|
|
|
{
|
2004-07-09 05:57:05 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2004-07-09 05:57:05 +08:00
|
|
|
object_class->constructor = gimp_dialog_constructor;
|
2005-01-07 06:19:35 +08:00
|
|
|
object_class->dispose = gimp_dialog_dispose;
|
2003-11-21 22:19:15 +08:00
|
|
|
object_class->set_property = gimp_dialog_set_property;
|
|
|
|
object_class->get_property = gimp_dialog_get_property;
|
|
|
|
|
2006-01-08 01:47:24 +08:00
|
|
|
widget_class->hide = gimp_dialog_hide;
|
2001-09-21 18:47:19 +08:00
|
|
|
widget_class->delete_event = gimp_dialog_delete_event;
|
2003-03-20 23:49:48 +08:00
|
|
|
|
|
|
|
dialog_class->close = gimp_dialog_close;
|
2003-11-21 22:19:15 +08:00
|
|
|
|
2004-07-09 06:56:29 +08:00
|
|
|
/**
|
|
|
|
* GimpDialog::help-func:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
2004-07-09 05:57:05 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_HELP_FUNC,
|
|
|
|
g_param_spec_pointer ("help-func", NULL, NULL,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-07-09 05:57:05 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2004-07-09 06:56:29 +08:00
|
|
|
/**
|
|
|
|
* GimpDialog::help-id:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
2004-07-09 05:57:05 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_HELP_ID,
|
|
|
|
g_param_spec_string ("help-id", NULL, NULL,
|
2003-11-21 22:19:15 +08:00
|
|
|
NULL,
|
2006-01-31 00:10:56 +08:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-07-09 05:57:05 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_init (GimpDialog *dialog)
|
|
|
|
{
|
|
|
|
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
|
2006-01-03 20:40:13 +08:00
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (gimp_dialog_response),
|
|
|
|
NULL);
|
2005-12-21 04:35:23 +08:00
|
|
|
}
|
|
|
|
|
2004-07-09 05:57:05 +08:00
|
|
|
static GObject *
|
|
|
|
gimp_dialog_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
GimpHelpFunc help_func;
|
|
|
|
const gchar *help_id;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
help_func = g_object_get_data (object, "gimp-dialog-help-func");
|
|
|
|
help_id = g_object_get_data (object, "gimp-dialog-help-id");
|
|
|
|
|
|
|
|
if (help_func)
|
|
|
|
gimp_help_connect (GTK_WIDGET (object), help_func, help_id, object);
|
|
|
|
|
2004-10-05 00:21:52 +08:00
|
|
|
if (show_help_button && help_func && help_id)
|
|
|
|
{
|
|
|
|
GtkDialog *dialog = GTK_DIALOG (object);
|
|
|
|
GtkWidget *button = gtk_button_new_from_stock (GTK_STOCK_HELP);
|
|
|
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (dialog->action_area), button, FALSE, TRUE, 0);
|
|
|
|
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area),
|
|
|
|
button, TRUE);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect_object (button, "clicked",
|
|
|
|
G_CALLBACK (gimp_dialog_help),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
g_object_set_data (object, "gimp-dialog-help-button", button);
|
|
|
|
}
|
|
|
|
|
2004-07-09 05:57:05 +08:00
|
|
|
return object;
|
2003-11-21 22:19:15 +08:00
|
|
|
}
|
|
|
|
|
2005-01-07 06:19:35 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = NULL;
|
|
|
|
|
|
|
|
if (g_main_depth () == 0)
|
|
|
|
{
|
|
|
|
display = gtk_widget_get_display (GTK_WIDGET (object));
|
|
|
|
g_object_ref (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
|
|
|
|
if (display)
|
|
|
|
{
|
|
|
|
gdk_display_flush (display);
|
|
|
|
g_object_unref (display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-21 22:19:15 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2004-07-09 05:57:05 +08:00
|
|
|
case PROP_HELP_FUNC:
|
|
|
|
g_object_set_data (object, "gimp-dialog-help-func",
|
|
|
|
g_value_get_pointer (value));
|
|
|
|
break;
|
|
|
|
case PROP_HELP_ID:
|
|
|
|
g_object_set_data_full (object, "gimp-dialog-help-id",
|
|
|
|
g_value_dup_string (value),
|
|
|
|
(GDestroyNotify) g_free);
|
2003-11-21 22:19:15 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_dialog_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2004-07-09 05:57:05 +08:00
|
|
|
case PROP_HELP_FUNC:
|
|
|
|
g_value_set_pointer (value, g_object_get_data (object,
|
|
|
|
"gimp-dialog-help-func"));
|
|
|
|
break;
|
|
|
|
case PROP_HELP_ID:
|
|
|
|
g_value_set_string (value, g_object_get_data (object,
|
|
|
|
"gimp-dialog-help-id"));
|
2003-11-21 22:19:15 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2001-09-21 18:47:19 +08:00
|
|
|
}
|
|
|
|
|
2006-01-08 01:47:24 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_hide (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
/* set focus to NULL so focus_out callbacks are invoked synchronously */
|
|
|
|
gtk_window_set_focus (GTK_WINDOW (widget), NULL);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->hide (widget);
|
|
|
|
}
|
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_dialog_delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-03-20 23:49:48 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_close (GtkDialog *dialog)
|
|
|
|
{
|
|
|
|
/* Synthesize delete_event to close dialog. */
|
|
|
|
|
|
|
|
GtkWidget *widget = GTK_WIDGET (dialog);
|
|
|
|
|
|
|
|
if (widget->window)
|
|
|
|
{
|
2004-12-15 08:12:27 +08:00
|
|
|
GdkEvent *event = gdk_event_new (GDK_DELETE);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-03-20 23:49:48 +08:00
|
|
|
event->any.window = g_object_ref (widget->window);
|
|
|
|
event->any.send_event = TRUE;
|
|
|
|
|
|
|
|
gtk_main_do_event (event);
|
|
|
|
gdk_event_free (event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-05 00:21:52 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_help (GObject *dialog)
|
|
|
|
{
|
|
|
|
GimpHelpFunc help_func = g_object_get_data (dialog, "gimp-dialog-help-func");
|
|
|
|
|
|
|
|
if (help_func)
|
|
|
|
help_func (g_object_get_data (dialog, "gimp-dialog-help-id"), dialog);
|
|
|
|
}
|
|
|
|
|
2006-01-03 20:40:13 +08:00
|
|
|
static void
|
|
|
|
gimp_dialog_response (GtkDialog *dialog,
|
|
|
|
gint response_id)
|
|
|
|
{
|
|
|
|
GList *children;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area));
|
|
|
|
|
|
|
|
for (list = children; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GtkWidget *widget = list->data;
|
|
|
|
|
|
|
|
if (gtk_dialog_get_response_for_widget (dialog, widget) == response_id)
|
|
|
|
{
|
2006-01-03 20:45:45 +08:00
|
|
|
if (! GTK_IS_BUTTON (widget) ||
|
2006-01-03 20:46:23 +08:00
|
|
|
gtk_button_get_focus_on_click (GTK_BUTTON (widget)))
|
2006-01-03 20:45:45 +08:00
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
}
|
|
|
|
|
2006-01-03 20:40:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
}
|
|
|
|
|
2004-02-29 05:33:03 +08:00
|
|
|
|
2000-02-26 22:28:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_dialog_new:
|
2001-07-31 01:17:36 +08:00
|
|
|
* @title: The dialog's title which will be set with
|
|
|
|
* gtk_window_set_title().
|
2003-11-06 23:27:05 +08:00
|
|
|
* @role: The dialog's @role which will be set with
|
|
|
|
* gtk_window_set_role().
|
|
|
|
* @parent: The @parent widget of this dialog.
|
|
|
|
* @flags: The @flags (see the #GtkDialog documentation).
|
2001-07-31 01:17:36 +08:00
|
|
|
* @help_func: The function which will be called if the user presses "F1".
|
2003-08-24 03:35:05 +08:00
|
|
|
* @help_id: The help_id which will be passed to @help_func.
|
2003-02-07 05:17:12 +08:00
|
|
|
* @...: A %NULL-terminated @va_list destribing the
|
2001-07-31 01:17:36 +08:00
|
|
|
* action_area buttons.
|
2000-02-26 22:28:08 +08:00
|
|
|
*
|
2003-11-06 23:27:05 +08:00
|
|
|
* Creates a new @GimpDialog widget.
|
|
|
|
*
|
2000-02-26 22:28:08 +08:00
|
|
|
* This function simply packs the action_area arguments passed in "..."
|
2003-11-06 23:27:05 +08:00
|
|
|
* into a @va_list variable and passes everything to gimp_dialog_new_valist().
|
2000-02-26 22:28:08 +08:00
|
|
|
*
|
|
|
|
* For a description of the format of the @va_list describing the
|
2003-11-06 23:27:05 +08:00
|
|
|
* action_area buttons see gtk_dialog_new_with_buttons().
|
2000-02-26 22:28:08 +08:00
|
|
|
*
|
2001-09-21 18:47:19 +08:00
|
|
|
* Returns: A #GimpDialog.
|
2001-07-31 01:17:36 +08:00
|
|
|
**/
|
2000-01-05 23:47:06 +08:00
|
|
|
GtkWidget *
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_dialog_new (const gchar *title,
|
|
|
|
const gchar *role,
|
|
|
|
GtkWidget *parent,
|
|
|
|
GtkDialogFlags flags,
|
|
|
|
GimpHelpFunc help_func,
|
|
|
|
const gchar *help_id,
|
|
|
|
...)
|
2000-01-05 23:47:06 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
va_list args;
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
|
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
|
|
|
g_return_val_if_fail (role != NULL, NULL);
|
|
|
|
|
|
|
|
va_start (args, help_id);
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
dialog = gimp_dialog_new_valist (title, role,
|
|
|
|
parent, flags,
|
|
|
|
help_func, help_id,
|
|
|
|
args);
|
2000-01-05 23:47:06 +08:00
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2000-02-26 22:28:08 +08:00
|
|
|
/**
|
2003-11-06 23:27:05 +08:00
|
|
|
* gimp_dialog_new_valist:
|
2001-07-31 01:17:36 +08:00
|
|
|
* @title: The dialog's title which will be set with
|
|
|
|
* gtk_window_set_title().
|
2003-11-06 23:27:05 +08:00
|
|
|
* @role: The dialog's @role which will be set with
|
|
|
|
* gtk_window_set_role().
|
2004-02-28 20:37:49 +08:00
|
|
|
* @parent: The @parent widget of this dialog or %NULL.
|
2003-11-06 23:27:05 +08:00
|
|
|
* @flags: The @flags (see the #GtkDialog documentation).
|
2001-07-31 01:17:36 +08:00
|
|
|
* @help_func: The function which will be called if the user presses "F1".
|
2003-08-24 03:35:05 +08:00
|
|
|
* @help_id: The help_id which will be passed to @help_func.
|
2003-11-06 23:37:33 +08:00
|
|
|
* @args: A @va_list destribing the action_area buttons.
|
2000-02-26 22:28:08 +08:00
|
|
|
*
|
2004-02-29 05:33:03 +08:00
|
|
|
* Creates a new @GimpDialog widget. If a GtkWindow is specified as
|
|
|
|
* @parent then the dialog will be made transient for this window.
|
2000-02-26 22:28:08 +08:00
|
|
|
*
|
2003-11-06 23:27:05 +08:00
|
|
|
* For a description of the format of the @va_list describing the
|
|
|
|
* action_area buttons see gtk_dialog_new_with_buttons().
|
2000-02-26 22:28:08 +08:00
|
|
|
*
|
2001-09-21 18:47:19 +08:00
|
|
|
* Returns: A #GimpDialog.
|
2001-08-01 07:28:56 +08:00
|
|
|
**/
|
2000-01-05 23:47:06 +08:00
|
|
|
GtkWidget *
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_dialog_new_valist (const gchar *title,
|
|
|
|
const gchar *role,
|
|
|
|
GtkWidget *parent,
|
|
|
|
GtkDialogFlags flags,
|
|
|
|
GimpHelpFunc help_func,
|
|
|
|
const gchar *help_id,
|
|
|
|
va_list args)
|
2000-01-05 23:47:06 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
2003-11-06 23:27:05 +08:00
|
|
|
g_return_val_if_fail (role != NULL, NULL);
|
2004-02-28 20:37:49 +08:00
|
|
|
g_return_val_if_fail (parent == NULL || GTK_IS_WIDGET (parent), NULL);
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
dialog = g_object_new (GIMP_TYPE_DIALOG,
|
2004-07-09 05:57:05 +08:00
|
|
|
"title", title,
|
|
|
|
"role", role,
|
|
|
|
"modal", (flags & GTK_DIALOG_MODAL),
|
|
|
|
"help-func", help_func,
|
|
|
|
"help-id", help_id,
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL);
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WINDOW (parent))
|
|
|
|
{
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
|
|
|
GTK_WINDOW (parent));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-08 23:32:38 +08:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (dialog),
|
|
|
|
gtk_widget_get_screen (parent));
|
2003-11-06 23:27:05 +08:00
|
|
|
}
|
2002-01-26 02:34:33 +08:00
|
|
|
|
2004-02-29 05:33:03 +08:00
|
|
|
if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
|
|
|
|
g_signal_connect_object (parent, "destroy",
|
|
|
|
G_CALLBACK (gimp_dialog_close),
|
|
|
|
dialog, G_CONNECT_SWAPPED);
|
|
|
|
}
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_dialog_add_buttons_valist (GIMP_DIALOG (dialog), args);
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return dialog;
|
2000-01-05 23:47:06 +08:00
|
|
|
}
|
|
|
|
|
2006-07-20 05:41:46 +08:00
|
|
|
/**
|
|
|
|
* gimp_dialog_add_button:
|
|
|
|
* @dialog: The @dialog to add a button to.
|
|
|
|
* @button_text: text of button, or stock ID.
|
|
|
|
* @response_id: response ID for the button.
|
|
|
|
*
|
|
|
|
* This function is essentially the same as gtk_dialog_add_button()
|
|
|
|
* except it ensures there is only one help button and automatically
|
|
|
|
* sets the RESPONSE_OK widget as the default response.
|
|
|
|
*
|
|
|
|
* Return value: the button widget that was added.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_dialog_add_button (GimpDialog *dialog,
|
|
|
|
const gchar *button_text,
|
|
|
|
gint response_id)
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
/* hide the automatically added help button if another one is added */
|
|
|
|
if (response_id == GTK_RESPONSE_HELP)
|
|
|
|
{
|
|
|
|
GtkWidget *help_button = g_object_get_data (G_OBJECT (dialog),
|
|
|
|
"gimp-dialog-help-button");
|
|
|
|
if (help_button)
|
|
|
|
gtk_widget_hide (help_button);
|
|
|
|
}
|
|
|
|
|
|
|
|
button = gtk_dialog_add_button (GTK_DIALOG (dialog), button_text,
|
|
|
|
response_id);
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-08-09 23:44:40 +08:00
|
|
|
* gimp_dialog_add_buttons:
|
2006-07-20 05:41:46 +08:00
|
|
|
* @dialog: The @dialog to add buttons to.
|
|
|
|
* @Varargs: button_text-response_id pairs.
|
|
|
|
*
|
|
|
|
* This function is essentially the same as gtk_dialog_add_buttons()
|
|
|
|
* except it calls gimp_dialog_add_button() instead of gtk_dialog_add_button()
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_dialog_add_buttons (GimpDialog *dialog,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, dialog);
|
|
|
|
|
|
|
|
gimp_dialog_add_buttons_valist (dialog, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2003-11-06 23:37:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_dialog_add_buttons_valist:
|
|
|
|
* @dialog: The @dialog to add buttons to.
|
|
|
|
* @args: The buttons as va_list.
|
|
|
|
*
|
2006-07-20 05:41:46 +08:00
|
|
|
* This function is essentially the same as gimp_dialog_add_buttons()
|
2003-11-06 23:37:33 +08:00
|
|
|
* except it takes a va_list instead of '...'
|
|
|
|
**/
|
2000-01-05 23:47:06 +08:00
|
|
|
void
|
2003-11-06 23:27:05 +08:00
|
|
|
gimp_dialog_add_buttons_valist (GimpDialog *dialog,
|
|
|
|
va_list args)
|
2000-01-05 23:47:06 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
const gchar *button_text;
|
|
|
|
gint response_id;
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DIALOG (dialog));
|
2000-01-05 23:47:06 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
while ((button_text = va_arg (args, const gchar *)))
|
2000-01-05 23:47:06 +08:00
|
|
|
{
|
2003-11-06 23:27:05 +08:00
|
|
|
response_id = va_arg (args, gint);
|
2000-01-07 00:40:17 +08:00
|
|
|
|
2006-07-20 05:41:46 +08:00
|
|
|
gimp_dialog_add_button (dialog, button_text, response_id);
|
2000-01-05 23:47:06 +08:00
|
|
|
}
|
|
|
|
}
|
2003-11-12 02:11:56 +08:00
|
|
|
|
2004-10-05 00:21:52 +08:00
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkDialog *dialog;
|
|
|
|
gint response_id;
|
|
|
|
GMainLoop *loop;
|
|
|
|
gboolean destroyed;
|
|
|
|
} RunInfo;
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_shutdown_loop (RunInfo *ri)
|
|
|
|
{
|
|
|
|
if (g_main_loop_is_running (ri->loop))
|
|
|
|
g_main_loop_quit (ri->loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_unmap_handler (GtkDialog *dialog,
|
|
|
|
RunInfo *ri)
|
|
|
|
{
|
|
|
|
run_shutdown_loop (ri);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_response_handler (GtkDialog *dialog,
|
|
|
|
gint response_id,
|
|
|
|
RunInfo *ri)
|
|
|
|
{
|
|
|
|
ri->response_id = response_id;
|
|
|
|
|
|
|
|
run_shutdown_loop (ri);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
run_delete_handler (GtkDialog *dialog,
|
|
|
|
GdkEventAny *event,
|
|
|
|
RunInfo *ri)
|
|
|
|
{
|
|
|
|
run_shutdown_loop (ri);
|
|
|
|
|
|
|
|
return TRUE; /* Do not destroy */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_destroy_handler (GtkDialog *dialog,
|
|
|
|
RunInfo *ri)
|
|
|
|
{
|
|
|
|
/* shutdown_loop will be called by run_unmap_handler */
|
|
|
|
|
|
|
|
ri->destroyed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_dialog_run:
|
|
|
|
* @dialog: a #GimpDialog
|
|
|
|
*
|
|
|
|
* This function does exactly the same as gtk_dialog_run() except it
|
|
|
|
* does not make the dialog modal while the #GMainLoop is running.
|
|
|
|
*
|
|
|
|
* Return value: response ID
|
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gimp_dialog_run (GimpDialog *dialog)
|
|
|
|
{
|
|
|
|
RunInfo ri = { NULL, GTK_RESPONSE_NONE, NULL };
|
|
|
|
gulong response_handler;
|
|
|
|
gulong unmap_handler;
|
|
|
|
gulong destroy_handler;
|
|
|
|
gulong delete_handler;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DIALOG (dialog), -1);
|
|
|
|
|
|
|
|
g_object_ref (dialog);
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
|
|
|
|
2003-11-12 03:36:40 +08:00
|
|
|
response_handler = g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (run_response_handler),
|
|
|
|
&ri);
|
|
|
|
unmap_handler = g_signal_connect (dialog, "unmap",
|
|
|
|
G_CALLBACK (run_unmap_handler),
|
|
|
|
&ri);
|
2005-05-27 21:05:26 +08:00
|
|
|
delete_handler = g_signal_connect (dialog, "delete-event",
|
2003-11-12 03:36:40 +08:00
|
|
|
G_CALLBACK (run_delete_handler),
|
|
|
|
&ri);
|
|
|
|
destroy_handler = g_signal_connect (dialog, "destroy",
|
|
|
|
G_CALLBACK (run_destroy_handler),
|
|
|
|
&ri);
|
2003-11-12 02:11:56 +08:00
|
|
|
|
|
|
|
ri.loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
GDK_THREADS_LEAVE ();
|
|
|
|
g_main_loop_run (ri.loop);
|
|
|
|
GDK_THREADS_ENTER ();
|
|
|
|
|
|
|
|
g_main_loop_unref (ri.loop);
|
|
|
|
|
2003-11-12 03:36:40 +08:00
|
|
|
ri.loop = NULL;
|
2003-11-12 02:11:56 +08:00
|
|
|
ri.destroyed = FALSE;
|
|
|
|
|
|
|
|
if (!ri.destroyed)
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (dialog, response_handler);
|
|
|
|
g_signal_handler_disconnect (dialog, unmap_handler);
|
|
|
|
g_signal_handler_disconnect (dialog, delete_handler);
|
|
|
|
g_signal_handler_disconnect (dialog, destroy_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (dialog);
|
|
|
|
|
|
|
|
return ri.response_id;
|
|
|
|
}
|
2004-10-05 00:21:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_dialogs_show_help_button:
|
|
|
|
* @show: whether a help button should be added when creating a GimpDialog
|
|
|
|
*
|
|
|
|
* This function is for internal use only.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.2
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_dialogs_show_help_button (gboolean show)
|
|
|
|
{
|
|
|
|
show_help_button = show ? TRUE : FALSE;
|
|
|
|
}
|