1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program 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
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include "libgimpwidgets/gimpwidgets.h"
30
#include "widgets-types.h"
32
#include "core/gimpcontext.h"
34
#include "pdb/procedural_db.h"
36
#include "gimpmenufactory.h"
37
#include "gimppdbdialog.h"
39
#include "gimp-intl.h"
53
static void gimp_pdb_dialog_class_init (GimpPdbDialogClass *klass);
54
static void gimp_pdb_dialog_init (GimpPdbDialog *dialog,
55
GimpPdbDialogClass *klass);
57
static GObject * gimp_pdb_dialog_constructor (GType type,
59
GObjectConstructParam *params);
60
static void gimp_pdb_dialog_dispose (GObject *object);
61
static void gimp_pdb_dialog_set_property (GObject *object,
66
static void gimp_pdb_dialog_destroy (GtkObject *object);
68
static void gimp_pdb_dialog_response (GtkDialog *dialog,
71
static void gimp_pdb_dialog_context_changed (GimpContext *context,
73
GimpPdbDialog *dialog);
76
static GimpDialogClass *parent_class = NULL;
80
gimp_pdb_dialog_get_type (void)
82
static GType dialog_type = 0;
86
static const GTypeInfo dialog_info =
88
sizeof (GimpPdbDialogClass),
90
(GBaseFinalizeFunc) NULL,
91
(GClassInitFunc) gimp_pdb_dialog_class_init,
92
NULL, /* class_finalize */
93
NULL, /* class_data */
94
sizeof (GimpPdbDialog),
96
(GInstanceInitFunc) gimp_pdb_dialog_init,
99
dialog_type = g_type_register_static (GIMP_TYPE_DIALOG,
102
G_TYPE_FLAG_ABSTRACT);
109
gimp_pdb_dialog_class_init (GimpPdbDialogClass *klass)
111
GObjectClass *object_class = G_OBJECT_CLASS (klass);
112
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
113
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
115
parent_class = g_type_class_peek_parent (klass);
117
object_class->constructor = gimp_pdb_dialog_constructor;
118
object_class->dispose = gimp_pdb_dialog_dispose;
119
object_class->set_property = gimp_pdb_dialog_set_property;
120
object_class->set_property = gimp_pdb_dialog_set_property;
122
gtk_object_class->destroy = gimp_pdb_dialog_destroy;
124
dialog_class->response = gimp_pdb_dialog_response;
126
klass->run_callback = NULL;
128
g_object_class_install_property (object_class, PROP_CONTEXT,
129
g_param_spec_object ("context", NULL, NULL,
132
G_PARAM_CONSTRUCT_ONLY));
134
g_object_class_install_property (object_class, PROP_SELECT_TYPE,
135
g_param_spec_pointer ("select-type",
138
G_PARAM_CONSTRUCT_ONLY));
140
g_object_class_install_property (object_class, PROP_INITIAL_OBJECT,
141
g_param_spec_object ("initial-object",
145
G_PARAM_CONSTRUCT_ONLY));
147
g_object_class_install_property (object_class, PROP_CALLBACK_NAME,
148
g_param_spec_string ("callback-name",
152
G_PARAM_CONSTRUCT_ONLY));
154
g_object_class_install_property (object_class, PROP_MENU_FACTORY,
155
g_param_spec_object ("menu-factory",
157
GIMP_TYPE_MENU_FACTORY,
159
G_PARAM_CONSTRUCT_ONLY));
163
gimp_pdb_dialog_init (GimpPdbDialog *dialog,
164
GimpPdbDialogClass *klass)
166
klass->dialogs = g_list_prepend (klass->dialogs, dialog);
168
gtk_dialog_add_button (GTK_DIALOG (dialog),
169
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
173
gimp_pdb_dialog_constructor (GType type,
175
GObjectConstructParam *params)
178
GimpPdbDialog *dialog;
179
const gchar *signal_name;
181
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
183
dialog = GIMP_PDB_DIALOG (object);
185
g_assert (GIMP_IS_CONTEXT (dialog->caller_context));
186
g_assert (g_type_is_a (dialog->select_type, GIMP_TYPE_OBJECT));
188
dialog->context = gimp_context_new (dialog->caller_context->gimp,
192
gimp_context_set_by_type (dialog->context, dialog->select_type,
193
dialog->initial_object);
195
dialog->initial_object = NULL;
197
signal_name = gimp_context_type_to_signal_name (dialog->select_type);
199
g_signal_connect_object (dialog->context, signal_name,
200
G_CALLBACK (gimp_pdb_dialog_context_changed),
207
gimp_pdb_dialog_dispose (GObject *object)
209
GimpPdbDialogClass *klass = GIMP_PDB_DIALOG_GET_CLASS (object);
211
klass->dialogs = g_list_remove (klass->dialogs, object);
213
G_OBJECT_CLASS (parent_class)->dispose (object);
217
gimp_pdb_dialog_set_property (GObject *object,
222
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
227
dialog->caller_context = GIMP_CONTEXT (g_value_dup_object (value));
229
case PROP_SELECT_TYPE:
230
dialog->select_type = (GType) g_value_get_pointer (value);
232
case PROP_INITIAL_OBJECT:
233
/* don't ref, see constructor */
234
dialog->initial_object = g_value_get_object (value);
236
case PROP_CALLBACK_NAME:
237
if (dialog->callback_name)
238
g_free (dialog->callback_name);
239
dialog->callback_name = g_value_dup_string (value);
241
case PROP_MENU_FACTORY:
242
dialog->menu_factory = (GimpMenuFactory *) g_value_dup_object (value);
245
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
251
gimp_pdb_dialog_destroy (GtkObject *object)
253
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
255
if (dialog->caller_context)
257
g_object_unref (dialog->caller_context);
258
dialog->caller_context = NULL;
263
g_object_unref (dialog->context);
264
dialog->context = NULL;
267
if (dialog->callback_name)
269
g_free (dialog->callback_name);
270
dialog->callback_name = NULL;
273
if (dialog->menu_factory)
275
g_object_unref (dialog->menu_factory);
276
dialog->menu_factory = NULL;
279
GTK_OBJECT_CLASS (parent_class)->destroy (object);
283
gimp_pdb_dialog_response (GtkDialog *gtk_dialog,
286
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (gtk_dialog);
288
gimp_pdb_dialog_run_callback (dialog, TRUE);
289
gtk_widget_destroy (GTK_WIDGET (dialog));
293
gimp_pdb_dialog_run_callback (GimpPdbDialog *dialog,
296
GimpPdbDialogClass *klass = GIMP_PDB_DIALOG_GET_CLASS (dialog);
299
object = gimp_context_get_by_type (dialog->context, dialog->select_type);
302
klass->run_callback &&
303
dialog->callback_name &&
304
! dialog->callback_busy)
306
dialog->callback_busy = TRUE;
308
if (procedural_db_lookup (dialog->caller_context->gimp,
309
dialog->callback_name))
311
Argument *return_vals;
314
return_vals = klass->run_callback (dialog, object, closing,
318
return_vals[0].value.pdb_int != GIMP_PDB_SUCCESS)
320
g_message (_("Unable to run %s callback. "
321
"The corresponding plug-in may have crashed."),
322
g_type_name (G_TYPE_FROM_INSTANCE (dialog)));
326
procedural_db_destroy_args (return_vals, n_return_vals);
329
dialog->callback_busy = FALSE;
334
gimp_pdb_dialog_get_by_callback (GimpPdbDialogClass *klass,
335
const gchar *callback_name)
339
g_return_val_if_fail (GIMP_IS_PDB_DIALOG_CLASS (klass), NULL);
340
g_return_val_if_fail (callback_name != NULL, NULL);
342
for (list = klass->dialogs; list; list = g_list_next (list))
344
GimpPdbDialog *dialog = list->data;
346
if (dialog->callback_name &&
347
! strcmp (callback_name, dialog->callback_name))
355
gimp_pdb_dialogs_check_callback (GimpPdbDialogClass *klass)
359
g_return_if_fail (GIMP_IS_PDB_DIALOG_CLASS (klass));
361
list = klass->dialogs;
365
GimpPdbDialog *dialog = list->data;
367
list = g_list_next (list);
369
if (dialog->caller_context && dialog->callback_name)
371
if (! procedural_db_lookup (dialog->caller_context->gimp,
372
dialog->callback_name))
374
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
381
/* private functions */
384
gimp_pdb_dialog_context_changed (GimpContext *context,
386
GimpPdbDialog *dialog)
389
gimp_pdb_dialog_run_callback (dialog, FALSE);