Commit c7281b52 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/gui/Makefile.am added font selection GUI to be used through the PDB.

2003-03-28  Sven Neumann  <sven@gimp.org>

	* app/gui/Makefile.am
	* app/gui/font-select.[ch]: added font selection GUI to be used
	through the PDB.

	* app/gui/brush-select.c
	* app/gui/gradient-select.c
	* app/gui/palette-select.c
	* app/gui/pattern-select.c: unified preview and dialog sizes.

	* tools/pdbgen/Makefile.am
	* tools/pdbgen/pdb/font_select.pdb: added new file that provides
	PDB accessors to the font selection GUI.

	* app/pdb/font_select_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimp_pdb.h
	* libgimp/gimpfontselect_pdb.[ch]
	* tools/pdbgen/groups.pl: regenerated.

	* libgimp/Makefile.am
	* libgimp/gimpfontmenu.c
	* libgimp/gimpmenu.[ch]: added a simple font selection widget to
	be used by plug-ins and scripts.

	* plug-ins/script-fu/script-fu-scripts.c: use the new font
	selection widget. Fixes bug #105610.
parent f13f80f0
2003-03-28 Sven Neumann <sven@gimp.org>
* app/gui/Makefile.am
* app/gui/font-select.[ch]: added font selection GUI to be used
through the PDB.
* app/gui/brush-select.c
* app/gui/gradient-select.c
* app/gui/palette-select.c
* app/gui/pattern-select.c: unified preview and dialog sizes.
* tools/pdbgen/Makefile.am
* tools/pdbgen/pdb/font_select.pdb: added new file that provides
PDB accessors to the font selection GUI.
* app/pdb/font_select_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimp_pdb.h
* libgimp/gimpfontselect_pdb.[ch]
* tools/pdbgen/groups.pl: regenerated.
* libgimp/Makefile.am
* libgimp/gimpfontmenu.c
* libgimp/gimpmenu.[ch]: added a simple font selection widget to
be used by plug-ins and scripts.
* plug-ins/script-fu/script-fu-scripts.c: use the new font
selection widget. Fixes bug #105610.
2003-03-28 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-guides.[ch]: added "position" and "push_undo"
......@@ -27,6 +27,8 @@ dialogs_sources = \
file-open-dialog.h \
file-save-dialog.c \
file-save-dialog.h \
font-select.c \
font-select.h \
gradient-select.c \
gradient-select.h \
info-dialog.c \
......
......@@ -154,15 +154,14 @@ brush_select_new (Gimp *gimp,
NULL);
/* The Brush Grid */
bsp->view =
gimp_brush_factory_view_new (GIMP_VIEW_TYPE_GRID,
gimp->brush_factory,
dialogs_edit_brush_func,
bsp->context,
FALSE,
GIMP_PREVIEW_SIZE_EXTRA_SMALL,
5, 5,
global_menu_factory);
bsp->view = gimp_brush_factory_view_new (GIMP_VIEW_TYPE_GRID,
gimp->brush_factory,
dialogs_edit_brush_func,
bsp->context,
FALSE,
GIMP_PREVIEW_SIZE_MEDIUM,
5, 5,
global_menu_factory);
gtk_container_set_border_width (GTK_CONTAINER (bsp->view), 4);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (bsp->shell)->vbox), bsp->view);
......
/* 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 "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_close_callback (GtkWidget *widget,
FontSelect *font_select);
/* list of active dialogs */
static GSList *font_active_dialogs = NULL;
/* public functions */
FontSelect *
font_select_new (Gimp *gimp,
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 (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 (gimp_get_current_context (gimp));
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",
gimp_standard_help_func,
"dialogs/font_selection.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
GTK_STOCK_CLOSE, font_select_close_callback,
font_select, NULL, NULL, TRUE, TRUE,
NULL);
/* The Font List */
font_select->view = gimp_container_tree_view_new (gimp->fonts,
font_select->context,
GIMP_PREVIEW_SIZE_MEDIUM,
FALSE,
5, 8);
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_close_callback (NULL, 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->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.\n"
"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_close_callback (GtkWidget *widget,
FontSelect *font_select)
{
font_select_change_callbacks (font_select, TRUE);
font_select_free (font_select);
}
/* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __FONT_SELECT_H__
#define __FONT_SELECT_H__
typedef struct _FontSelect FontSelect;
struct _FontSelect
{
GimpContext *context;
gchar *callback_name;
GtkWidget *shell;
GtkWidget *view;
};
FontSelect * font_select_new (Gimp *gimp,
const gchar *title,
const gchar *initial_font,
const gchar *callback_name);
void font_select_free (FontSelect *font_select);
FontSelect * font_select_get_by_callback (const gchar *callback_name);
void font_select_dialogs_check (void);
#endif /* __FONT_SELECT_H__ */
......@@ -129,7 +129,7 @@ gradient_select_new (Gimp *gimp,
gimp->gradient_factory,
dialogs_edit_gradient_func,
gsp->context,
GIMP_PREVIEW_SIZE_EXTRA_SMALL,
GIMP_PREVIEW_SIZE_MEDIUM,
6, 6,
global_menu_factory, "<Gradients>");
......
......@@ -131,8 +131,8 @@ palette_select_new (Gimp *gimp,
gimp->palette_factory,
dialogs_edit_palette_func,
psp->context,
32,
5, 3,
GIMP_PREVIEW_SIZE_MEDIUM,
5, 8,
global_menu_factory, "<Palettes>");
gtk_container_set_border_width (GTK_CONTAINER (psp->view), 4);
......
......@@ -127,8 +127,8 @@ pattern_select_new (Gimp *gimp,
gimp->pattern_factory,
NULL,
psp->context,
GIMP_PREVIEW_SIZE_SMALL,
5, 5,
GIMP_PREVIEW_SIZE_MEDIUM,
6, 6,
global_menu_factory, "<Patterns>");
gtk_container_set_border_width (GTK_CONTAINER (psp->view), 4);
......
......@@ -17,6 +17,7 @@ libapppdb_a_SOURCES = \
edit_cmds.c \
fileops_cmds.c \
floating_sel_cmds.c \
font_select_cmds.c \
gimprc_cmds.c \
gradient_select_cmds.c \
gradients_cmds.c \
......@@ -47,7 +48,7 @@ libapppdb_a_SOURCES = \
unit_cmds.c
## This is a truly ugly hack
libapppdb_a_LIBADD = ../gui/pattern-select.o ../gui/brush-select.o
libapppdb_a_LIBADD = ../gui/pattern-select.o ../gui/brush-select.o ../gui/font-select.o
AM_CPPFLAGS = \
-DG_LOG_DOMAIN=\"Gimp-PDB\" \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995-2000 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* NOTE: This file is autogenerated by pdbgen.pl. */
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpbase/gimpbasetypes.h"
#include "pdb-types.h"
#include "gui/gui-types.h"
#include "procedural_db.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "gui/font-select.h"
static ProcRecord fonts_popup_proc;
static ProcRecord fonts_close_popup_proc;
static ProcRecord fonts_set_popup_proc;
void
register_font_select_procs (Gimp *gimp)
{
procedural_db_register (gimp, &fonts_popup_proc);
procedural_db_register (gimp, &fonts_close_popup_proc);
procedural_db_register (gimp, &fonts_set_popup_proc);
}
static Argument *
fonts_popup_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
gchar *font_callback;
gchar *popup_title;
gchar *initial_font;
ProcRecord *proc;
font_callback = (gchar *) args[0].value.pdb_pointer;
if (font_callback == NULL)
success = FALSE;
popup_title = (gchar *) args[1].value.pdb_pointer;
if (popup_title == NULL)
success = FALSE;
initial_font = (gchar *) args[2].value.pdb_pointer;
if (success)
{
if (! gimp->no_interface &&
(proc = procedural_db_lookup (gimp, font_callback)))
{
font_select_new (gimp, popup_title, initial_font, font_callback);
}
else
{
success = FALSE;
}
}
return procedural_db_return_args (&fonts_popup_proc, success);
}
static ProcArg fonts_popup_inargs[] =
{
{
GIMP_PDB_STRING,
"font_callback",
"The callback PDB proc to call when font selection is made"
},
{
GIMP_PDB_STRING,
"popup_title",
"Title to give the font popup window"
},
{
GIMP_PDB_STRING,
"initial_font",
"The name of the font to set as the first selected"
}
};
static ProcRecord fonts_popup_proc =
{
"gimp_fonts_popup",
"Invokes the Gimp font selection.",
"This procedure popups the font selection dialog.",
"Sven Neumann <sven@gimp.org>",
"Sven Neumann",
"2003",
GIMP_INTERNAL,
3,
fonts_popup_inargs,
0,
NULL,
{ { fonts_popup_invoker } }
};
static Argument *
fonts_close_popup_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
gchar *font_callback;
ProcRecord *proc;
FontSelect *font_select;
font_callback = (gchar *) args[0].value.pdb_pointer;
if (font_callback == NULL)
success = FALSE;
if (success)
{
if (! gimp->no_interface &&
(proc = procedural_db_lookup (gimp, font_callback)) &&
(font_select = font_select_get_by_callback (font_callback)))
{
font_select_free (font_select);
}
else
{
success = FALSE;
}
}
return procedural_db_return_args (&fonts_close_popup_proc, success);
}
static ProcArg fonts_close_popup_inargs[] =
{
{
GIMP_PDB_STRING,
"font_callback",
"The name of the callback registered for this popup"
}
};
static ProcRecord fonts_close_popup_proc =
{
"gimp_fonts_close_popup",
"Popdown the Gimp font selection.",
"This procedure closes an opened font selection dialog.",
"Sven Neumann <sven@gimp.org>",
"Sven Neumann",
"2003",
GIMP_INTERNAL,
1,
fonts_close_popup_inargs,
0,
NULL,
{ { fonts_close_popup_invoker } }
};
static Argument *
fonts_set_popup_invoker (Gimp *gimp,
Argument *args)
{
gboolean success = TRUE;
gchar *font_callback;
gchar *font_name;
ProcRecord *proc;
FontSelect *font_select;
font_callback = (gchar *) args[0].value.pdb_pointer;
if (font_callback == NULL)
success = FALSE;
font_name = (gchar *) args[1].value.pdb_pointer;
if (font_name == NULL)
success = FALSE;
if (success)
{
if (! gimp->no_interface &&
(proc = procedural_db_lookup (gimp, font_callback)) &&
(font_select = font_select_get_by_callback (font_callback)))
{
GimpFont *active = (GimpFont *)
gimp_container_get_child_by_name (gimp->fonts, font_name);
success = (active != NULL);
if (success)
{
gimp_context_set_font (font_select->context, active);
}
}
else
success = FALSE;
}
return procedural_db_return_args (&fonts_set_popup_proc, success);
}
static ProcArg fonts_set_popup_inargs[] =
{
{
GIMP_PDB_STRING,
"font_callback",
"The name of the callback registered for this popup"
},
{
GIMP_PDB_STRING,
"font_name",
"The name of the font to set as selected"
}
};
static ProcRecord fonts_set_popup_proc =
{
"gimp_fonts_set_popup",
"Sets the current font selection in a popup.",
"Sets the current font selection in a popup.",
"Sven Neumann <sven@gimp.org>",
"Sven Neumann",
"2003",
GIMP_INTERNAL,
2,
fonts_set_popup_inargs,
0,
NULL,
{ { fonts_set_popup_invoker } }
};
......@@ -40,6 +40,7 @@ void register_drawable_procs (Gimp *gimp);
void register_edit_procs (Gimp *gimp);
void register_fileops_procs (Gimp *gimp);
void register_floating_sel_procs (Gimp *gimp);
void register_font_select_procs (Gimp *gimp);
void register_gimprc_procs (Gimp *gimp);
void register_gradient_select_procs (Gimp *gimp);
void register_gradients_procs (Gimp *gimp);
......@@ -67,7 +68,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 339 procedures registered total */
/* 342 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -88,94 +89,97 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Color"), 0.088);
register_color_procs (gimp);
(* status_callback) (NULL, _("Convert"), 0.124);
(* status_callback) (NULL, _("Convert"), 0.123);
register_convert_procs (gimp);
(* status_callback) (NULL, _("Display procedures"), 0.133);
(* status_callback) (NULL, _("Display procedures"), 0.132);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.145);
(* status_callback) (NULL, _("Drawable procedures"), 0.143);
register_drawable_procs (gimp);
(* status_callback) (NULL, _("Edit procedures"), 0.212);
(* status_callback) (NULL, _("Edit procedures"), 0.211);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.23);
(* status_callback) (NULL, _("File Operations"), 0.228);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.254);
(* status_callback) (NULL, _("Floating selections"), 0.251);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.271);
(* status_callback) (NULL, _("Font UI"), 0.269);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.278);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.283);
(* status_callback) (NULL, _("Gradient UI"), 0.289);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.292);
(* status_callback) (NULL, _("Gradients"), 0.298);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.313);
(* status_callback) (NULL, _("Guide procedures"), 0.319);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.33);
(* status_callback) (NULL, _("Help procedures"), 0.336);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.333);
(* status_callback) (NULL, _("Image"), 0.339);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.519);
(* status_callback) (NULL, _("Layer"), 0.523);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.614);
(* status_callback) (NULL, _("Message procedures"), 0.617);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.62