1997-11-25 06:05:25 +08:00
|
|
|
/* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-07-16 20:49:04 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "config.h"
|
1999-03-07 20:56:03 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-07-16 20:49:04 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
1999-10-04 00:54:17 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "gui-types.h"
|
2000-07-16 20:49:04 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpitem.h"
|
1999-10-04 00:54:17 +08:00
|
|
|
|
2003-01-30 19:20:12 +08:00
|
|
|
#include "plug-in/plug-in-run.h"
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "plug-in/plug-in-proc.h"
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2003-01-30 19:20:12 +08:00
|
|
|
#include "widgets/gimpitemfactory.h"
|
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "plug-in-commands.h"
|
2000-05-08 06:04:51 +08:00
|
|
|
|
2000-02-24 04:25:24 +08:00
|
|
|
|
2002-12-11 00:38:16 +08:00
|
|
|
#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
|
|
|
|
|
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
void
|
|
|
|
plug_in_run_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-01-30 19:20:12 +08:00
|
|
|
GtkItemFactory *item_factory;
|
|
|
|
Gimp *gimp;
|
|
|
|
GimpDisplay *gdisplay;
|
|
|
|
ProcRecord *proc_rec;
|
|
|
|
Argument *args;
|
|
|
|
gint i;
|
|
|
|
gint gdisp_ID = -1;
|
|
|
|
gint argc = 0; /* calm down a gcc warning. */
|
|
|
|
|
|
|
|
item_factory = gtk_item_factory_from_widget (widget);
|
|
|
|
|
|
|
|
gimp = GIMP_ITEM_FACTORY (item_factory)->gimp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* get the active gdisplay */
|
2003-01-30 19:20:12 +08:00
|
|
|
gdisplay = gimp_context_get_display (gimp_get_user_context (gimp));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
proc_rec = (ProcRecord *) data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* construct the procedures arguments */
|
2000-07-16 20:49:04 +08:00
|
|
|
args = g_new0 (Argument, proc_rec->num_args);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* initialize the argument types */
|
|
|
|
for (i = 0; i < proc_rec->num_args; i++)
|
|
|
|
args[i].arg_type = proc_rec->args[i].arg_type;
|
|
|
|
|
|
|
|
switch (proc_rec->proc_type)
|
|
|
|
{
|
2001-05-21 21:58:46 +08:00
|
|
|
case GIMP_EXTENSION:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* initialize the first argument */
|
2001-12-19 08:13:16 +08:00
|
|
|
args[0].value.pdb_int = GIMP_RUN_INTERACTIVE;
|
1998-10-22 03:10:14 +08:00
|
|
|
argc = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
case GIMP_PLUGIN:
|
1997-11-25 06:05:25 +08:00
|
|
|
if (gdisplay)
|
|
|
|
{
|
2002-03-21 01:46:13 +08:00
|
|
|
gdisp_ID = gimp_display_get_ID (gdisplay);
|
1998-06-14 12:33:27 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* initialize the first 3 plug-in arguments */
|
2001-12-19 08:13:16 +08:00
|
|
|
args[0].value.pdb_int = GIMP_RUN_INTERACTIVE;
|
2001-04-13 22:50:43 +08:00
|
|
|
args[1].value.pdb_int = gimp_image_get_ID (gdisplay->gimage);
|
2002-02-26 01:58:50 +08:00
|
|
|
args[2].value.pdb_int = gimp_item_get_ID (GIMP_ITEM (gimp_image_active_drawable (gdisplay->gimage)));
|
1998-10-22 03:10:14 +08:00
|
|
|
argc = 3;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-06-06 07:41:45 +08:00
|
|
|
g_warning ("Uh-oh, no active gdisplay for the plug-in!");
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (args);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
case GIMP_TEMPORARY:
|
2001-12-19 08:13:16 +08:00
|
|
|
args[0].value.pdb_int = GIMP_RUN_INTERACTIVE;
|
1998-10-25 04:11:17 +08:00
|
|
|
argc = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
if (proc_rec->num_args >= 3 &&
|
2001-05-21 21:58:46 +08:00
|
|
|
proc_rec->args[1].arg_type == GIMP_PDB_IMAGE &&
|
|
|
|
proc_rec->args[2].arg_type == GIMP_PDB_DRAWABLE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (gdisplay)
|
|
|
|
{
|
1998-06-14 12:33:27 +08:00
|
|
|
gdisp_ID = gdisplay->ID;
|
|
|
|
|
2001-04-13 22:50:43 +08:00
|
|
|
args[1].value.pdb_int = gimp_image_get_ID (gdisplay->gimage);
|
2002-02-26 01:58:50 +08:00
|
|
|
args[2].value.pdb_int = gimp_item_get_ID (GIMP_ITEM (gimp_image_active_drawable (gdisplay->gimage)));
|
1998-10-22 03:10:14 +08:00
|
|
|
argc = 3;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-06-06 07:41:45 +08:00
|
|
|
g_warning ("Uh-oh, no active gdisplay for the temporary procedure!");
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (args);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-09-23 19:49:16 +08:00
|
|
|
g_error ("Unknown procedure type.");
|
1998-10-22 03:10:14 +08:00
|
|
|
g_free (args);
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* run the plug-in procedure */
|
2003-01-30 19:20:12 +08:00
|
|
|
plug_in_run (gimp, proc_rec, args, argc, FALSE, TRUE, gdisp_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
if (proc_rec->proc_type == GIMP_PLUGIN)
|
2003-02-11 20:07:31 +08:00
|
|
|
gimp->last_plug_in = proc_rec;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
g_free (args);
|
|
|
|
}
|
|
|
|
|
1999-05-04 03:22:58 +08:00
|
|
|
void
|
2002-03-21 01:46:13 +08:00
|
|
|
plug_in_repeat_cmd_callback (GtkWidget *widget,
|
|
|
|
gpointer data,
|
|
|
|
guint action)
|
2001-05-17 02:09:45 +08:00
|
|
|
{
|
2002-03-21 01:46:13 +08:00
|
|
|
GimpDisplay *gdisp;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
gboolean interactive;
|
2002-12-11 00:38:16 +08:00
|
|
|
return_if_no_display (gdisp, data);
|
2001-05-17 02:09:45 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
2001-10-24 23:56:33 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
if (! drawable)
|
|
|
|
return;
|
2001-05-17 02:09:45 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
interactive = action ? TRUE : FALSE;
|
2001-05-17 02:09:45 +08:00
|
|
|
|
2002-12-14 23:55:26 +08:00
|
|
|
plug_in_repeat (gdisp->gimage->gimp,
|
2002-03-21 01:46:13 +08:00
|
|
|
gimp_display_get_ID (gdisp),
|
|
|
|
gimp_image_get_ID (gdisp->gimage),
|
|
|
|
gimp_item_get_ID (GIMP_ITEM (drawable)),
|
|
|
|
interactive);
|
2001-05-17 02:09:45 +08:00
|
|
|
}
|