plug-in-commands.c 4.78 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
 */
18

Elliot Lee's avatar
Elliot Lee committed
19
#include "config.h"
Tor Lillqvist's avatar
Tor Lillqvist committed
20

21
#include <gtk/gtk.h>
22

23
#include "libgimpwidgets/gimpwidgets.h"
24

25
#include "gui-types.h"
26

27 28 29 30
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
31

32
#include "plug-in/plug-in-run.h"
33
#include "plug-in/plug-in-proc.h"
34

35 36
#include "widgets/gimpitemfactory.h"

37
#include "display/gimpdisplay.h"
38

39
#include "plug-in-commands.h"
40

41

42 43 44 45 46 47 48 49 50 51 52
#define return_if_no_display(gdisp,data) \
  if (GIMP_IS_DISPLAY (data)) \
    gdisp = data; \
  else if (GIMP_IS_GIMP (data)) \
    gdisp = gimp_context_get_display (gimp_get_user_context (GIMP (data))); \
  else \
    gdisp = NULL; \
  if (! gdisp) \
    return


53 54 55 56
void
plug_in_run_cmd_callback (GtkWidget *widget,
                          gpointer   data,
                          guint      action)
Elliot Lee's avatar
Elliot Lee committed
57
{
58 59 60 61 62
  GtkItemFactory *item_factory;
  Gimp           *gimp;
  ProcRecord     *proc_rec;
  Argument       *args;
  gint            gdisp_ID = -1;
63
  gint            i;
64 65 66 67 68
  gint            argc     = 0; /* calm down a gcc warning.  */

  item_factory = gtk_item_factory_from_widget (widget);

  gimp = GIMP_ITEM_FACTORY (item_factory)->gimp;
Elliot Lee's avatar
Elliot Lee committed
69

70
  proc_rec = (ProcRecord *) data;
Elliot Lee's avatar
Elliot Lee committed
71 72

  /* construct the procedures arguments */
73
  args = g_new0 (Argument, proc_rec->num_args);
Elliot Lee's avatar
Elliot Lee committed
74 75 76 77 78

  /* initialize the argument types */
  for (i = 0; i < proc_rec->num_args; i++)
    args[i].arg_type = proc_rec->args[i].arg_type;

79 80 81 82
  /* initialize the first argument  */
  args[0].value.pdb_int = GIMP_RUN_INTERACTIVE;
  argc = 1;

Elliot Lee's avatar
Elliot Lee committed
83 84
  switch (proc_rec->proc_type)
    {
85
    case GIMP_EXTENSION:
Elliot Lee's avatar
Elliot Lee committed
86 87
      break;

88 89
    case GIMP_PLUGIN:
    case GIMP_TEMPORARY:
90 91 92 93 94 95 96 97 98
      if (proc_rec->num_args >= 2 &&
          proc_rec->args[1].arg_type == GIMP_PDB_IMAGE)
        {
          GimpDisplay *gdisplay;

          gdisplay = gimp_context_get_display (gimp_get_user_context (gimp));

          if (gdisplay)
            {
99 100
              gdisp_ID = gimp_display_get_ID (gdisplay);

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
              args[1].value.pdb_int = gimp_image_get_ID (gdisplay->gimage);
              argc++;

              if (proc_rec->num_args >= 2 &&
                  proc_rec->args[2].arg_type == GIMP_PDB_DRAWABLE)
                {
                  GimpDrawable *drawable;

                  drawable = gimp_image_active_drawable (gdisplay->gimage);

                  if (drawable)
                    {
                      args[2].value.pdb_int =
                        gimp_item_get_ID (GIMP_ITEM (drawable));
                      argc++;
                    }
                  else
                    {
                      g_warning ("Uh-oh, no active drawable for the plug-in!");
                      g_free (args);
                      return;
                    }
                }
            }
          else
            {
              g_warning ("Uh-oh, no active display for the plug-in!");
              g_free (args);
              return;
            }
Elliot Lee's avatar
Elliot Lee committed
131 132 133 134
	}
      break;

    default:
Sven Neumann's avatar
Sven Neumann committed
135
      g_error ("Unknown procedure type.");
136 137
      g_free (args);
      return;
Elliot Lee's avatar
Elliot Lee committed
138 139 140
    }

  /* run the plug-in procedure */
141
  plug_in_run (gimp, proc_rec, args, argc, FALSE, TRUE, gdisp_ID);
Elliot Lee's avatar
Elliot Lee committed
142

143 144 145 146 147 148 149 150
  /* remember only "standard" plug-ins */
  if (proc_rec->proc_type == GIMP_PLUGIN           &&
      proc_rec->num_args >= 2                      &&
      proc_rec->args[1].arg_type == GIMP_PDB_IMAGE &&
      proc_rec->args[2].arg_type == GIMP_PDB_DRAWABLE)
    {
      gimp->last_plug_in = proc_rec;
    }
Elliot Lee's avatar
Elliot Lee committed
151 152 153 154

  g_free (args);
}

155
void
156 157 158
plug_in_repeat_cmd_callback (GtkWidget *widget,
                             gpointer   data,
                             guint      action)
159
{
160 161 162
  GimpDisplay  *gdisp;
  GimpDrawable *drawable;
  gboolean      interactive;
163
  return_if_no_display (gdisp, data);
164

165
  drawable = gimp_image_active_drawable (gdisp->gimage);
166

167 168
  if (! drawable)
    return;
169

170
  interactive = action ? TRUE : FALSE;
171

172
  plug_in_repeat (gdisp->gimage->gimp,
173 174 175 176
                  gimp_display_get_ID (gdisp),
                  gimp_image_get_ID (gdisp->gimage),
                  gimp_item_get_ID (GIMP_ITEM (drawable)),
                  interactive);
177
}