mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-23 04:51:44 +00:00
18d9161eea
2004-04-15 Michael Natterer <mitch@gimp.org> Get rid of the "current_context" which was in fact just a bunch of global variables. Instead, pass the needed context all the way from the GUI and the PDB to the core. This is a prerequisite for macro recording and generally helps separating the various subsystems from each other. Work in progress... * app/core/gimp.[ch]: removed member "current_context" and gimp_[get|set]_current_context(). * app/core/gimp-edit.[ch] * app/core/gimpdrawable-blend.[ch] * app/core/gimpdrawable-bucket-fill.[ch] * app/core/gimpdrawable-offset.[ch] * app/core/gimpdrawable-transform.[ch] * app/core/gimpimage-crop.[ch] * app/core/gimpimage-flip.[ch] * app/core/gimpimage-merge.[ch] * app/core/gimpimage-resize.[ch] * app/core/gimpimage-rotate.[ch] * app/core/gimpimage.[ch] * app/core/gimpimagefile.[ch] * app/core/gimpitem-linked.[ch] * app/core/gimpitem.[ch] * app/core/gimplayer.[ch] * app/core/gimpselection.[ch] * app/core/gimptemplate.[ch] * app/file/file-open.[ch] * app/file/file-save.[ch] * app/pdb/procedural_db.[ch] * app/text/gimptext-compat.[ch] * app/text/gimptextlayer-transform.[ch] * app/gui/brush-select.[ch] * app/gui/font-select.[ch] * app/gui/gradient-select.[ch] * app/gui/palette-select.[ch] * app/gui/pattern-select.[ch]: added tons of "GimpContext *context" parameters and use the passed context instead of gimp_get_current_context(). * app/app_procs.c * app/batch.c * app/core/gimpchannel.c * app/core/gimpdrawable.c * app/paint/gimperaser.c * app/paint/gimppaintbrush.c * app/plug-in/plug-in-message.c * app/plug-in/plug-ins.c * app/text/gimptextlayer.c * app/tools/gimpblendtool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpcroptool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpfliptool.c * app/tools/gimpinktool.c * app/tools/gimptransformtool.c * app/vectors/gimpvectors.c * app/gui/convert-dialog.c * app/gui/drawable-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/offset-dialog.c * app/gui/select-commands.c * app/gui/vectors-commands.c * app/widgets/gimpdnd.c * app/widgets/gimpdocumentview.c * app/widgets/gimphelp.c * app/widgets/gimpthumbbox.c: pass gimp_get_user_context() or GIMP_CONTEXT(tool_options) or whatever is the right context to the changed core functions. * tools/pdbgen/app.pl: pass "GimpContext *context" to all generated PDB invokers. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/font_select.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/paint_tools.pdb * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/palette_select.pdb * tools/pdbgen/pdb/palettes.pdb * tools/pdbgen/pdb/paths.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/text_tool.pdb * tools/pdbgen/pdb/transform_tools.pdb: pass the new context parameter to the changed core functions. * app/pdb/*_cmds.c: regenerated.
264 lines
7.4 KiB
C
264 lines
7.4 KiB
C
/* The GIMP -- an image manipulation program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
* Copyright (C) 1998 Andy Thomas (alt@picnic.demon.co.uk)
|
|
*
|
|
* 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
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
#include "gui-types.h"
|
|
|
|
#include "core/gimp.h"
|
|
#include "core/gimpcontainer.h"
|
|
#include "core/gimpcontext.h"
|
|
#include "text/gimpfont.h"
|
|
|
|
#include "pdb/procedural_db.h"
|
|
|
|
#include "widgets/gimpcontainertreeview.h"
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
#include "dialogs-constructors.h"
|
|
#include "menus.h"
|
|
#include "font-select.h"
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
static void font_select_change_callbacks (FontSelect *font_select,
|
|
gboolean closing);
|
|
static void font_select_font_changed (GimpContext *context,
|
|
GimpFont *font,
|
|
FontSelect *font_select);
|
|
static void font_select_response (GtkWidget *widget,
|
|
gint response_id,
|
|
FontSelect *font_select);
|
|
|
|
|
|
/* list of active dialogs */
|
|
static GSList *font_active_dialogs = NULL;
|
|
|
|
|
|
/* public functions */
|
|
|
|
FontSelect *
|
|
font_select_new (Gimp *gimp,
|
|
GimpContext *context,
|
|
const gchar *title,
|
|
const gchar *initial_font,
|
|
const gchar *callback_name)
|
|
{
|
|
FontSelect *font_select;
|
|
GimpFont *active = NULL;
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
g_return_val_if_fail (title != NULL, NULL);
|
|
|
|
if (initial_font && strlen (initial_font))
|
|
{
|
|
active = (GimpFont *)
|
|
gimp_container_get_child_by_name (gimp->fonts, initial_font);
|
|
}
|
|
|
|
if (! active)
|
|
active = gimp_context_get_font (context);
|
|
|
|
if (! active)
|
|
return NULL;
|
|
|
|
font_select = g_new0 (FontSelect, 1);
|
|
|
|
/* Add to active font dialogs list */
|
|
font_active_dialogs = g_slist_append (font_active_dialogs, font_select);
|
|
|
|
font_select->context = gimp_context_new (gimp, title, NULL);
|
|
font_select->callback_name = g_strdup (callback_name);
|
|
|
|
gimp_context_set_font (font_select->context, active);
|
|
|
|
g_signal_connect (font_select->context, "font_changed",
|
|
G_CALLBACK (font_select_font_changed),
|
|
font_select);
|
|
|
|
/* the shell */
|
|
font_select->shell = gimp_dialog_new (title, "font_selection",
|
|
NULL, 0,
|
|
gimp_standard_help_func,
|
|
GIMP_HELP_FONT_DIALOG,
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (font_select->shell, "response",
|
|
G_CALLBACK (font_select_response),
|
|
font_select);
|
|
|
|
/* The Font List */
|
|
font_select->view = gimp_container_tree_view_new (gimp->fonts,
|
|
font_select->context,
|
|
GIMP_PREVIEW_SIZE_MEDIUM, 1,
|
|
FALSE);
|
|
|
|
gimp_container_view_set_size_request (GIMP_CONTAINER_VIEW (font_select->view),
|
|
5 * (GIMP_PREVIEW_SIZE_MEDIUM + 2),
|
|
5 * (GIMP_PREVIEW_SIZE_MEDIUM + 2));
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (font_select->view), 4);
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (font_select->shell)->vbox),
|
|
font_select->view);
|
|
gtk_widget_show (font_select->view);
|
|
|
|
gtk_widget_show (font_select->shell);
|
|
|
|
return font_select;
|
|
}
|
|
|
|
void
|
|
font_select_free (FontSelect *font_select)
|
|
{
|
|
g_return_if_fail (font_select != NULL);
|
|
|
|
gtk_widget_destroy (font_select->shell);
|
|
|
|
/* remove from active list */
|
|
font_active_dialogs = g_slist_remove (font_active_dialogs, font_select);
|
|
|
|
if (font_select->callback_name)
|
|
g_free (font_select->callback_name);
|
|
|
|
if (font_select->context)
|
|
g_object_unref (font_select->context);
|
|
|
|
g_free (font_select);
|
|
}
|
|
|
|
FontSelect *
|
|
font_select_get_by_callback (const gchar *callback_name)
|
|
{
|
|
GSList *list;
|
|
FontSelect *font_select;
|
|
|
|
for (list = font_active_dialogs; list; list = g_slist_next (list))
|
|
{
|
|
font_select = (FontSelect *) list->data;
|
|
|
|
if (font_select->callback_name && !
|
|
strcmp (callback_name, font_select->callback_name))
|
|
return font_select;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void
|
|
font_select_dialogs_check (void)
|
|
{
|
|
FontSelect *font_select;
|
|
GSList *list;
|
|
|
|
list = font_active_dialogs;
|
|
|
|
while (list)
|
|
{
|
|
font_select = (FontSelect *) list->data;
|
|
|
|
list = g_slist_next (list);
|
|
|
|
if (font_select->callback_name)
|
|
{
|
|
if (! procedural_db_lookup (font_select->context->gimp,
|
|
font_select->callback_name))
|
|
font_select_response (NULL, GTK_RESPONSE_CLOSE, font_select);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* private functions */
|
|
|
|
static void
|
|
font_select_change_callbacks (FontSelect *font_select,
|
|
gboolean closing)
|
|
{
|
|
ProcRecord *proc;
|
|
GimpFont *font;
|
|
|
|
static gboolean busy = FALSE;
|
|
|
|
if (! (font_select && font_select->callback_name) || busy)
|
|
return;
|
|
|
|
busy = TRUE;
|
|
|
|
font = gimp_context_get_font (font_select->context);
|
|
|
|
/* If its still registered run it */
|
|
proc = procedural_db_lookup (font_select->context->gimp,
|
|
font_select->callback_name);
|
|
|
|
if (proc && font)
|
|
{
|
|
Argument *return_vals;
|
|
gint nreturn_vals;
|
|
|
|
return_vals =
|
|
procedural_db_run_proc (font_select->context->gimp,
|
|
font_select->context,
|
|
font_select->callback_name,
|
|
&nreturn_vals,
|
|
GIMP_PDB_STRING, GIMP_OBJECT (font)->name,
|
|
GIMP_PDB_INT32, closing,
|
|
GIMP_PDB_END);
|
|
|
|
if (!return_vals || return_vals[0].value.pdb_int != GIMP_PDB_SUCCESS)
|
|
g_message (_("Unable to run font callback. "
|
|
"The corresponding plug-in may have crashed."));
|
|
|
|
if (return_vals)
|
|
procedural_db_destroy_args (return_vals, nreturn_vals);
|
|
}
|
|
|
|
busy = FALSE;
|
|
}
|
|
|
|
static void
|
|
font_select_font_changed (GimpContext *context,
|
|
GimpFont *font,
|
|
FontSelect *font_select)
|
|
{
|
|
if (font)
|
|
font_select_change_callbacks (font_select, FALSE);
|
|
}
|
|
|
|
static void
|
|
font_select_response (GtkWidget *widget,
|
|
gint response_id,
|
|
FontSelect *font_select)
|
|
{
|
|
font_select_change_callbacks (font_select, TRUE);
|
|
font_select_free (font_select);
|
|
}
|