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-12-29 23:22:01 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <string.h>
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
#include "gui-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
#include "core/gimppattern.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "pdb/procedural_db.h"
|
|
|
|
|
2004-05-10 19:08:51 +08:00
|
|
|
#include "widgets/gimpcontainerbox.h"
|
2001-04-11 09:13:53 +08:00
|
|
|
#include "widgets/gimpdatafactoryview.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2001-04-11 09:13:53 +08:00
|
|
|
|
2004-05-06 15:41:53 +08:00
|
|
|
#include "menus/menus.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "pattern-select.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* local function prototypes */
|
2002-03-13 05:02:10 +08:00
|
|
|
|
2002-11-18 08:04:16 +08:00
|
|
|
static void pattern_select_change_callbacks (PatternSelect *psp,
|
|
|
|
gboolean closing);
|
|
|
|
static void pattern_select_pattern_changed (GimpContext *context,
|
|
|
|
GimpPattern *pattern,
|
|
|
|
PatternSelect *psp);
|
2003-11-06 23:27:05 +08:00
|
|
|
static void pattern_select_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
2002-11-18 08:04:16 +08:00
|
|
|
PatternSelect *psp);
|
1999-10-28 23:05:49 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-23 22:47:50 +08:00
|
|
|
/* List of active dialogs */
|
2001-10-25 21:30:01 +08:00
|
|
|
static GSList *pattern_active_dialogs = NULL;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2001-02-13 02:05:12 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
/* public functions */
|
2001-02-13 02:05:12 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
PatternSelect *
|
2001-10-25 21:30:01 +08:00
|
|
|
pattern_select_new (Gimp *gimp,
|
2004-04-15 07:37:34 +08:00
|
|
|
GimpContext *context,
|
2001-10-25 21:30:01 +08:00
|
|
|
const gchar *title,
|
|
|
|
const gchar *initial_pattern,
|
|
|
|
const gchar *callback_name)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
PatternSelect *psp;
|
2002-03-13 05:02:10 +08:00
|
|
|
GimpPattern *active = NULL;
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2001-10-25 21:30:01 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2004-04-15 07:37:34 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2002-03-13 05:02:10 +08:00
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2002-11-18 08:04:16 +08:00
|
|
|
if (gimp->no_data)
|
|
|
|
{
|
|
|
|
static gboolean first_call = TRUE;
|
|
|
|
|
|
|
|
if (first_call)
|
|
|
|
gimp_data_factory_data_init (gimp->pattern_factory, FALSE);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2002-11-18 08:04:16 +08:00
|
|
|
first_call = FALSE;
|
|
|
|
}
|
1999-10-28 23:05:49 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
if (initial_pattern && strlen (initial_pattern))
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2001-02-06 01:48:50 +08:00
|
|
|
active = (GimpPattern *)
|
2001-10-25 21:30:01 +08:00
|
|
|
gimp_container_get_child_by_name (gimp->pattern_factory->container,
|
2001-02-06 01:48:50 +08:00
|
|
|
initial_pattern);
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
if (! active)
|
2004-04-15 07:37:34 +08:00
|
|
|
active = gimp_context_get_pattern (context);
|
2001-02-13 02:05:12 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
if (! active)
|
|
|
|
return NULL;
|
2001-02-05 01:34:30 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
psp = g_new0 (PatternSelect, 1);
|
|
|
|
|
|
|
|
/* Add to active pattern dialogs list */
|
|
|
|
pattern_active_dialogs = g_slist_append (pattern_active_dialogs, psp);
|
|
|
|
|
|
|
|
psp->context = gimp_context_new (gimp, title, NULL);
|
|
|
|
psp->callback_name = g_strdup (callback_name);
|
|
|
|
|
|
|
|
gimp_context_set_pattern (psp->context, active);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (psp->context, "pattern_changed",
|
2001-07-31 19:33:13 +08:00
|
|
|
G_CALLBACK (pattern_select_pattern_changed),
|
|
|
|
psp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
/* the shell */
|
|
|
|
psp->shell = gimp_dialog_new (title, "pattern_selection",
|
2003-11-06 23:27:05 +08:00
|
|
|
NULL, 0,
|
2002-03-13 05:02:10 +08:00
|
|
|
gimp_standard_help_func,
|
2003-08-22 09:42:57 +08:00
|
|
|
GIMP_HELP_PATTERN_DIALOG,
|
2002-03-13 05:02:10 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
g_signal_connect (psp->shell, "response",
|
|
|
|
G_CALLBACK (pattern_select_response),
|
|
|
|
psp);
|
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
/* the pattern grid */
|
2003-01-11 01:55:53 +08:00
|
|
|
psp->view = gimp_data_factory_view_new (GIMP_VIEW_TYPE_GRID,
|
|
|
|
gimp->pattern_factory,
|
|
|
|
NULL,
|
|
|
|
psp->context,
|
2003-04-08 20:39:02 +08:00
|
|
|
GIMP_PREVIEW_SIZE_MEDIUM, 1,
|
2004-04-22 00:33:17 +08:00
|
|
|
global_menu_factory, "<Patterns>",
|
2004-05-12 00:05:21 +08:00
|
|
|
"/patterns-popup",
|
|
|
|
"patterns");
|
2002-03-13 05:02:10 +08:00
|
|
|
|
2004-05-10 19:08:51 +08:00
|
|
|
gimp_container_box_set_size_request (GIMP_CONTAINER_BOX (GIMP_CONTAINER_EDITOR (psp->view)->view),
|
|
|
|
6 * (GIMP_PREVIEW_SIZE_MEDIUM + 2),
|
|
|
|
6 * (GIMP_PREVIEW_SIZE_MEDIUM + 2));
|
2003-04-08 20:39:02 +08:00
|
|
|
|
2004-05-26 21:39:23 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (psp->view), 12);
|
2002-03-13 05:02:10 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (psp->shell)->vbox), psp->view);
|
|
|
|
gtk_widget_show (psp->view);
|
|
|
|
|
|
|
|
gtk_widget_show (psp->shell);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return psp;
|
|
|
|
}
|
|
|
|
|
1998-10-02 06:09:01 +08:00
|
|
|
void
|
1999-10-27 02:27:27 +08:00
|
|
|
pattern_select_free (PatternSelect *psp)
|
|
|
|
{
|
2001-10-25 21:30:01 +08:00
|
|
|
g_return_if_fail (psp != NULL);
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
gtk_widget_destroy (psp->shell);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* remove from active list */
|
|
|
|
pattern_active_dialogs = g_slist_remove (pattern_active_dialogs, psp);
|
|
|
|
|
|
|
|
if (psp->callback_name)
|
2002-03-13 05:02:10 +08:00
|
|
|
g_free (psp->callback_name);
|
|
|
|
|
|
|
|
if (psp->context)
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (psp->context);
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
g_free (psp);
|
|
|
|
}
|
|
|
|
|
|
|
|
PatternSelect *
|
|
|
|
pattern_select_get_by_callback (const gchar *callback_name)
|
|
|
|
{
|
2004-05-28 17:52:15 +08:00
|
|
|
GSList *list;
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
for (list = pattern_active_dialogs; list; list = g_slist_next (list))
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2004-05-28 17:52:15 +08:00
|
|
|
PatternSelect *psp = list->data;
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
if (psp->callback_name && ! strcmp (callback_name, psp->callback_name))
|
|
|
|
return psp;
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pattern_select_dialogs_check (void)
|
|
|
|
{
|
2004-05-28 17:52:15 +08:00
|
|
|
GSList *list;
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
list = pattern_active_dialogs;
|
|
|
|
|
|
|
|
while (list)
|
|
|
|
{
|
2004-05-28 17:52:15 +08:00
|
|
|
PatternSelect *psp = list->data;
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
list = g_slist_next (list);
|
|
|
|
|
|
|
|
if (psp->callback_name)
|
2003-01-20 20:17:32 +08:00
|
|
|
{
|
2002-11-18 08:04:16 +08:00
|
|
|
if (! procedural_db_lookup (psp->context->gimp, psp->callback_name))
|
2003-11-06 23:27:05 +08:00
|
|
|
pattern_select_response (NULL, GTK_RESPONSE_CLOSE, psp);
|
2002-03-13 05:02:10 +08:00
|
|
|
}
|
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
|
|
|
|
/* private functions */
|
1999-10-27 02:27:27 +08:00
|
|
|
|
1999-10-28 23:05:49 +08:00
|
|
|
static void
|
2001-02-13 02:05:12 +08:00
|
|
|
pattern_select_change_callbacks (PatternSelect *psp,
|
|
|
|
gboolean closing)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-01-20 20:17:32 +08:00
|
|
|
ProcRecord *proc;
|
2001-02-05 01:34:30 +08:00
|
|
|
GimpPattern *pattern;
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static gboolean busy = FALSE;
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2004-05-28 17:52:15 +08:00
|
|
|
if (! psp->callback_name || busy)
|
1998-10-02 06:09:01 +08:00
|
|
|
return;
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
busy = TRUE;
|
2001-02-13 02:05:12 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
pattern = gimp_context_get_pattern (psp->context);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
|
|
|
/* If its still registered run it */
|
2002-03-13 05:02:10 +08:00
|
|
|
proc = procedural_db_lookup (psp->context->gimp, psp->callback_name);
|
1998-10-02 06:09:01 +08:00
|
|
|
|
2002-03-13 05:02:10 +08:00
|
|
|
if (proc && pattern)
|
1998-10-02 06:09:01 +08:00
|
|
|
{
|
2003-08-22 09:42:57 +08:00
|
|
|
Argument *return_vals;
|
2004-05-28 17:52:15 +08:00
|
|
|
gint n_return_vals;
|
2003-01-20 20:17:32 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
return_vals =
|
2001-07-05 03:31:35 +08:00
|
|
|
procedural_db_run_proc (psp->context->gimp,
|
2004-04-15 07:37:34 +08:00
|
|
|
psp->context,
|
2002-03-13 05:02:10 +08:00
|
|
|
psp->callback_name,
|
2004-05-28 17:52:15 +08:00
|
|
|
&n_return_vals,
|
2001-05-21 21:58:46 +08:00
|
|
|
GIMP_PDB_STRING, GIMP_OBJECT (pattern)->name,
|
|
|
|
GIMP_PDB_INT32, pattern->mask->width,
|
|
|
|
GIMP_PDB_INT32, pattern->mask->height,
|
|
|
|
GIMP_PDB_INT32, pattern->mask->bytes,
|
|
|
|
GIMP_PDB_INT32, (pattern->mask->bytes *
|
2002-03-13 05:02:10 +08:00
|
|
|
pattern->mask->height *
|
|
|
|
pattern->mask->width),
|
2001-05-21 21:58:46 +08:00
|
|
|
GIMP_PDB_INT8ARRAY, temp_buf_data (pattern->mask),
|
2002-11-18 08:04:16 +08:00
|
|
|
GIMP_PDB_INT32, closing,
|
2001-05-21 21:58:46 +08:00
|
|
|
GIMP_PDB_END);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
if (!return_vals || return_vals[0].value.pdb_int != GIMP_PDB_SUCCESS)
|
2003-11-14 23:33:40 +08:00
|
|
|
g_message (_("Unable to run pattern callback. "
|
2002-03-12 02:49:24 +08:00
|
|
|
"The corresponding plug-in may have crashed."));
|
2001-02-13 02:05:12 +08:00
|
|
|
|
2002-03-12 02:49:24 +08:00
|
|
|
if (return_vals)
|
2004-05-28 17:52:15 +08:00
|
|
|
procedural_db_destroy_args (return_vals, n_return_vals);
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
2001-02-13 02:05:12 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
busy = FALSE;
|
1998-10-02 06:09:01 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static void
|
|
|
|
pattern_select_pattern_changed (GimpContext *context,
|
2001-02-05 01:34:30 +08:00
|
|
|
GimpPattern *pattern,
|
1999-10-27 02:27:27 +08:00
|
|
|
PatternSelect *psp)
|
|
|
|
{
|
|
|
|
if (pattern)
|
2002-11-18 08:04:16 +08:00
|
|
|
pattern_select_change_callbacks (psp, FALSE);
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-06 23:27:05 +08:00
|
|
|
pattern_select_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
PatternSelect *psp)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
2002-03-13 05:02:10 +08:00
|
|
|
pattern_select_change_callbacks (psp, TRUE);
|
2003-08-22 09:42:57 +08:00
|
|
|
pattern_select_free (psp);
|
1999-10-27 02:27:27 +08:00
|
|
|
}
|