1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * gimpplugin-context.c
5  *
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 3 of the License, or
9  * (at your option) any later version.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "config.h"
21 
22 #include <gdk-pixbuf/gdk-pixbuf.h>
23 #include <gegl.h>
24 
25 #include "plug-in-types.h"
26 
27 #include "core/gimp.h"
28 
29 #include "pdb/gimppdbcontext.h"
30 
31 #include "gimpplugin.h"
32 #include "gimpplugin-context.h"
33 #include "gimppluginmanager.h"
34 
35 
36 gboolean
gimp_plug_in_context_push(GimpPlugIn * plug_in)37 gimp_plug_in_context_push (GimpPlugIn *plug_in)
38 {
39   GimpPlugInProcFrame *proc_frame;
40   GimpContext         *parent;
41   GimpContext         *context;
42 
43   g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
44 
45   proc_frame = gimp_plug_in_get_proc_frame (plug_in);
46 
47   if (proc_frame->context_stack)
48     parent = proc_frame->context_stack->data;
49   else
50     parent = proc_frame->main_context;
51 
52   context = gimp_pdb_context_new (plug_in->manager->gimp, parent, FALSE);
53 
54   proc_frame->context_stack = g_list_prepend (proc_frame->context_stack,
55                                               context);
56 
57   return TRUE;
58 }
59 
60 gboolean
gimp_plug_in_context_pop(GimpPlugIn * plug_in)61 gimp_plug_in_context_pop (GimpPlugIn *plug_in)
62 {
63   GimpPlugInProcFrame *proc_frame;
64 
65   g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
66 
67   proc_frame = gimp_plug_in_get_proc_frame (plug_in);
68 
69   if (proc_frame->context_stack)
70     {
71       GimpContext *context = proc_frame->context_stack->data;
72 
73       proc_frame->context_stack = g_list_remove (proc_frame->context_stack,
74                                                  context);
75       g_object_unref (context);
76 
77       return TRUE;
78     }
79 
80   return FALSE;
81 }
82