1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* gimppluginprocframe.c
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include <glib-object.h>
27
#include "plug-in-types.h"
29
#include "core/gimpcontext.h"
30
#include "core/gimpprogress.h"
32
#include "gimpplugin.h"
33
#include "gimpplugin-cleanup.h"
34
#include "gimpplugin-progress.h"
35
#include "gimppluginprocedure.h"
38
/* public functions */
41
gimp_plug_in_proc_frame_new (GimpContext *context,
42
GimpProgress *progress,
43
GimpPlugInProcedure *procedure)
45
GimpPlugInProcFrame *proc_frame;
47
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
48
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
49
g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (procedure), NULL);
51
proc_frame = g_new0 (GimpPlugInProcFrame, 1);
53
proc_frame->ref_count = 1;
55
gimp_plug_in_proc_frame_init (proc_frame, context, progress, procedure);
61
gimp_plug_in_proc_frame_init (GimpPlugInProcFrame *proc_frame,
63
GimpProgress *progress,
64
GimpPlugInProcedure *procedure)
66
g_return_if_fail (proc_frame != NULL);
67
g_return_if_fail (GIMP_IS_CONTEXT (context));
68
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
69
g_return_if_fail (procedure == NULL ||
70
GIMP_IS_PLUG_IN_PROCEDURE (procedure));
72
proc_frame->main_context = g_object_ref (context);
73
proc_frame->context_stack = NULL;
74
proc_frame->procedure = GIMP_PROCEDURE (procedure);
75
proc_frame->main_loop = NULL;
76
proc_frame->return_vals = NULL;
77
proc_frame->progress = progress ? g_object_ref (progress) : NULL;
78
proc_frame->progress_created = FALSE;
79
proc_frame->progress_cancel_id = 0;
82
gimp_plug_in_progress_attach (progress);
86
gimp_plug_in_proc_frame_dispose (GimpPlugInProcFrame *proc_frame,
89
g_return_if_fail (proc_frame != NULL);
90
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
92
if (proc_frame->progress)
94
gimp_plug_in_progress_end (plug_in, proc_frame);
96
if (proc_frame->progress)
98
g_object_unref (proc_frame->progress);
99
proc_frame->progress = NULL;
103
if (proc_frame->context_stack)
105
g_list_foreach (proc_frame->context_stack, (GFunc) g_object_unref, NULL);
106
g_list_free (proc_frame->context_stack);
107
proc_frame->context_stack = NULL;
110
if (proc_frame->main_context)
112
g_object_unref (proc_frame->main_context);
113
proc_frame->main_context = NULL;
116
if (proc_frame->return_vals)
118
g_value_array_free (proc_frame->return_vals);
119
proc_frame->return_vals = NULL;
122
if (proc_frame->main_loop)
124
g_main_loop_unref (proc_frame->main_loop);
125
proc_frame->main_loop = NULL;
128
if (proc_frame->cleanups)
129
gimp_plug_in_cleanup (plug_in, proc_frame);
132
GimpPlugInProcFrame *
133
gimp_plug_in_proc_frame_ref (GimpPlugInProcFrame *proc_frame)
135
g_return_val_if_fail (proc_frame != NULL, NULL);
137
proc_frame->ref_count++;
143
gimp_plug_in_proc_frame_unref (GimpPlugInProcFrame *proc_frame,
146
g_return_if_fail (proc_frame != NULL);
147
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
149
proc_frame->ref_count--;
151
if (proc_frame->ref_count < 1)
153
gimp_plug_in_proc_frame_dispose (proc_frame, plug_in);
159
gimp_plug_in_proc_frame_get_return_vals (GimpPlugInProcFrame *proc_frame)
161
GValueArray *return_vals;
163
g_return_val_if_fail (proc_frame != NULL, NULL);
165
if (proc_frame->return_vals)
167
if (proc_frame->return_vals->n_values >=
168
proc_frame->procedure->num_values + 1)
170
return_vals = proc_frame->return_vals;
174
/* Allocate new return values of the correct size. */
175
return_vals = gimp_procedure_get_return_values (proc_frame->procedure,
178
/* Copy all of the arguments we can. */
179
memcpy (return_vals->values, proc_frame->return_vals->values,
180
sizeof (GValue) * proc_frame->return_vals->n_values);
182
/* Free the old arguments. */
183
g_free (proc_frame->return_vals->values);
184
proc_frame->return_vals->values = 0;
185
proc_frame->return_vals->n_values = 0;
186
g_value_array_free (proc_frame->return_vals);
189
/* We have consumed any saved values, so clear them. */
190
proc_frame->return_vals = NULL;
194
/* Just return a dummy set of values. */
195
return_vals = gimp_procedure_get_return_values (proc_frame->procedure,