Commit 7a63a798 authored by Manish Singh's avatar Manish Singh Committed by Manish Singh
Browse files

new formal widget based on gimpfontmenu.[ch].

2005-06-04  Manish Singh  <yosh@gimp.org>

        * libgimp/gimpfontselectbutton.[ch]: new formal widget based on
        gimpfontmenu.[ch].

        * libgimp/gimpuimarshal.list: needed for new signal in above.

        * libgimp/gimpfontmenu.[ch]: deprecate, and thinly wrap around
        new GimpFontSelectButton for compatibility.

        * libgimp/gimpuitypes.h: add GimpFontSelectButton, as well
        as types for the future SelectButtons.

        * libgimp/gimpui.h
        * libgimp/Makefile.am: hook in the new widget.

        * plug-ins/common/film.c
        * plug-ins/script-fu/script-fu-interface.c: use new API.
parent f1731986
2005-06-04 Manish Singh <yosh@gimp.org>
* libgimp/gimpfontselectbutton.[ch]: new formal widget based on
gimpfontmenu.[ch].
* libgimp/gimpuimarshal.list: needed for new signal in above.
* libgimp/gimpfontmenu.[ch]: deprecate, and thinly wrap around
new GimpFontSelectButton for compatibility.
* libgimp/gimpuitypes.h: add GimpFontSelectButton, as well
as types for the future SelectButtons.
* libgimp/gimpui.h
* libgimp/Makefile.am: hook in the new widget.
* plug-ins/common/film.c
* plug-ins/script-fu/script-fu-interface.c: use new API.
2005-06-05 Sven Neumann <sven@gimp.org>
* app/widgets/gimpdocked.[ch]
......
......@@ -8,3 +8,5 @@ _libs
*.la
gimpenums.c
gimpenums.c.tail
gimpuimarshal.h
gimpuimarshal.c
......@@ -222,18 +222,11 @@ libgimp_2_0_la_built_sources = \
libgimp_2_0_la_extra_sources = gimpenums.c.tail
EXTRA_DIST = \
COPYING \
makefile.msc \
gimp.def \
gimpui.def \
$(libgimp_2_0_la_extra_sources)
libgimp_2_0_la_SOURCES = \
$(libgimp_2_0_la_sources) \
$(libgimp_2_0_la_built_sources)
libgimpui_2_0_la_SOURCES = \
libgimpui_2_0_la_sources = \
gimpui.c \
gimpui.h \
gimpuitypes.h \
......@@ -247,6 +240,8 @@ libgimpui_2_0_la_SOURCES = \
gimpdrawablepreview.h \
gimpfontmenu.c \
gimpfontmenu.h \
gimpfontselectbutton.c \
gimpfontselectbutton.h \
gimpgradientmenu.c \
gimpgradientmenu.h \
gimppalettemenu.c \
......@@ -264,6 +259,16 @@ libgimpui_2_0_la_SOURCES = \
gimpexport.c \
gimpexport.h
libgimpui_2_0_la_built_sources = \
gimpuimarshal.c \
gimpuimarshal.h
libgimpui_2_0_la_extra_sources = gimpuimarshal.list
libgimpui_2_0_la_SOURCES = \
$(libgimpui_2_0_la_sources) \
$(libgimpui_2_0_la_built_sources)
gimpinclude_HEADERS = \
gimp.h \
gimpcompat.h \
......@@ -300,6 +305,7 @@ gimpinclude_HEADERS = \
gimpbrushmenu.h \
gimpdrawablepreview.h \
gimpfontmenu.h \
gimpfontselectbutton.h \
gimpgradientmenu.h \
gimppalettemenu.h \
gimppatternmenu.h \
......@@ -328,6 +334,14 @@ libgimpui_2_0_la_LIBADD = $(libgimp) $(libgimpwidgets) $(libgimpcolor) \
libgimpui_2_0_la_DEPENDENCIES = $(gimpui_def) $(libgimp) $(libgimpwidgets) $(libgimpbase)
EXTRA_DIST = \
COPYING \
makefile.msc \
gimp.def \
gimpui.def \
$(libgimp_2_0_la_extra_sources) \
$(libgimpui_2_0_la_extra_sources)
install-data-local: install-ms-lib install-libtool-import-lib
uninstall-local: uninstall-ms-lib uninstall-libtool-import-lib
......@@ -336,7 +350,7 @@ uninstall-local: uninstall-ms-lib uninstall-libtool-import-lib
# rules to generate built sources
#
# setup autogeneration dependencies
gen_sources = xgen-cec
gen_sources = xgen-cec xgen-umh xgen-umc
CLEANFILES = $(gen_sources)
$(srcdir)/gimpenums.c: $(srcdir)/gimpenums.h $(srcdir)/gimpenums.c.tail $(GIMP_MKENUMS)
......@@ -353,3 +367,14 @@ $(srcdir)/gimpenums.c: $(srcdir)/gimpenums.h $(srcdir)/gimpenums.c.tail $(GIMP_M
&& cat $(srcdir)/gimpenums.c.tail >> xgen-cec \
&& cp xgen-cec $(@F) \
&& rm -f xgen-cec
$(srcdir)/gimpuimarshal.h: $(srcdir)/gimpuimarshal.list
$(GLIB_GENMARSHAL) --prefix=_gimpui_marshal $(srcdir)/gimpuimarshal.list --header >> xgen-umh \
&& (cmp -s xgen-umh $(@F) || cp xgen-umh $(@F)) \
&& rm -f xgen-umh xgen-umh~
$(srcdir)/gimpuimarshal.c: $(srcdir)/gimpuimarshal.h
echo "#include \"gimpuimarshal.h\"" >> xgen-umc \
&& $(GLIB_GENMARSHAL) --prefix=_gimpui_marshal $(srcdir)/gimpuimarshal.list --body >> xgen-umc \
&& cp xgen-umc $(@F) \
&& rm -f xgen-umc xgen-umc~
......@@ -25,49 +25,20 @@
#include "gimp.h"
#include "gimpui.h"
#include "libgimp-intl.h"
typedef struct _CompatCallbackData CompatCallbackData;
#define FONT_SELECT_DATA_KEY "gimp-font-select-data"
typedef struct _FontSelect FontSelect;
struct _FontSelect
struct _CompatCallbackData
{
gchar *title;
GimpRunFontCallback callback;
gpointer data;
GtkWidget *button;
GtkWidget *label;
gchar *font_name; /* Local copy */
const gchar *temp_font_callback;
GimpRunFontCallback callback;
gpointer data;
};
/* local function prototypes */
static void gimp_font_select_widget_callback (const gchar *name,
gboolean closing,
gpointer data);
static void gimp_font_select_widget_clicked (GtkWidget *widget,
FontSelect *font_sel);
static void gimp_font_select_widget_destroy (GtkWidget *widget,
FontSelect *font_sel);
static void gimp_font_select_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection,
guint info,
guint time);
static const GtkTargetEntry target = { "application/x-gimp-font-name", 0 };
static void compat_callback (GimpFontSelectButton *font_button,
const gchar *font_name,
gboolean dialog_closing,
gpointer data);
/**
......@@ -90,59 +61,22 @@ gimp_font_select_widget_new (const gchar *title,
GimpRunFontCallback callback,
gpointer data)
{
FontSelect *font_sel;
GtkWidget *hbox;
GtkWidget *image;
GtkWidget *font_button;
CompatCallbackData *compat_data;
g_return_val_if_fail (callback != NULL, NULL);
if (! title)
title = _("Font Selection");
font_sel = g_new0 (FontSelect, 1);
font_sel->title = g_strdup (title);
font_sel->callback = callback;
font_sel->data = data;
font_button = gimp_font_select_button_new (title, font_name);
font_sel->font_name = g_strdup (font_name);
compat_data = g_new (CompatCallbackData, 1);
compat_data->callback = callback;
compat_data->data = data;
font_sel->button = gtk_button_new ();
g_signal_connect_data (font_button, "font-set",
G_CALLBACK (compat_callback),
compat_data, (GClosureNotify) g_free, 0);
g_signal_connect (font_sel->button, "clicked",
G_CALLBACK (gimp_font_select_widget_clicked),
font_sel);
g_signal_connect (font_sel->button, "destroy",
G_CALLBACK (gimp_font_select_widget_destroy),
font_sel);
gtk_drag_dest_set (GTK_WIDGET (font_sel->button),
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP,
&target, 1,
GDK_ACTION_COPY);
g_signal_connect (font_sel->button, "drag-data-received",
G_CALLBACK (gimp_font_select_drag_data_received),
NULL);
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (font_sel->button), hbox);
gtk_widget_show (hbox);
image = gtk_image_new_from_stock (GIMP_STOCK_FONT, GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
font_sel->label = gtk_label_new (font_name);
gtk_box_pack_start (GTK_BOX (hbox), font_sel->label, TRUE, TRUE, 4);
gtk_widget_show (font_sel->label);
g_object_set_data (G_OBJECT (font_sel->button),
FONT_SELECT_DATA_KEY, font_sel);
return font_sel->button;
return font_button;
}
/**
......@@ -154,17 +88,9 @@ gimp_font_select_widget_new (const gchar *title,
void
gimp_font_select_widget_close (GtkWidget *widget)
{
FontSelect *font_sel;
font_sel = g_object_get_data (G_OBJECT (widget), FONT_SELECT_DATA_KEY);
g_return_if_fail (font_sel != NULL);
g_return_if_fail (widget != NULL);
if (font_sel->temp_font_callback)
{
gimp_font_select_destroy (font_sel->temp_font_callback);
font_sel->temp_font_callback = NULL;
}
gimp_font_select_button_close_popup (GIMP_FONT_SELECT_BUTTON (widget));
}
/**
......@@ -180,95 +106,19 @@ void
gimp_font_select_widget_set (GtkWidget *widget,
const gchar *font_name)
{
FontSelect *font_sel;
font_sel = g_object_get_data (G_OBJECT (widget), FONT_SELECT_DATA_KEY);
g_return_if_fail (font_sel != NULL);
g_return_if_fail (widget != NULL);
if (font_sel->temp_font_callback)
gimp_fonts_set_popup (font_sel->temp_font_callback, font_name);
else
gimp_font_select_widget_callback (font_name, FALSE, font_sel);
}
/* private functions */
static void
gimp_font_select_widget_callback (const gchar *name,
gboolean closing,
gpointer data)
{
FontSelect *font_sel = (FontSelect *) data;
g_free (font_sel->font_name);
font_sel->font_name = g_strdup (name);
gtk_label_set_text (GTK_LABEL (font_sel->label), name);
if (font_sel->callback)
font_sel->callback (name, closing, font_sel->data);
if (closing)
font_sel->temp_font_callback = NULL;
}
static void
gimp_font_select_widget_clicked (GtkWidget *widget,
FontSelect *font_sel)
{
if (font_sel->temp_font_callback)
{
/* calling gimp_fonts_set_popup() raises the dialog */
gimp_fonts_set_popup (font_sel->temp_font_callback, font_sel->font_name);
}
else
{
font_sel->temp_font_callback =
gimp_font_select_new (font_sel->title,
font_sel->font_name,
gimp_font_select_widget_callback,
font_sel);
}
gimp_font_select_button_set_font_name (GIMP_FONT_SELECT_BUTTON (widget),
font_name);
}
static void
gimp_font_select_widget_destroy (GtkWidget *widget,
FontSelect *font_sel)
compat_callback (GimpFontSelectButton *font_button,
const gchar *font_name,
gboolean dialog_closing,
gpointer data)
{
if (font_sel->temp_font_callback)
{
gimp_font_select_destroy (font_sel->temp_font_callback);
font_sel->temp_font_callback = NULL;
}
g_free (font_sel->title);
g_free (font_sel->font_name);
g_free (font_sel);
}
static void
gimp_font_select_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection,
guint info,
guint time)
{
gchar *name;
if ((selection->format != 8) || (selection->length < 1))
{
g_warning ("Received invalid font data!");
return;
}
name = g_strndup (selection->data, selection->length);
if (g_utf8_validate (name, -1, NULL))
gimp_font_select_widget_set (widget, name);
CompatCallbackData *compat_data = data;
g_free (name);
compat_data->callback (font_name, dialog_closing, compat_data->data);
}
......@@ -22,6 +22,12 @@
#ifndef __GIMP_FONT_MENU_H__
#define __GIMP_FONT_MENU_H__
/* These functions are deprecated and should not be used in newly
* written code.
*/
#ifndef GIMP_DISABLE_DEPRECATED
G_BEGIN_DECLS
......@@ -37,4 +43,6 @@ void gimp_font_select_widget_set (GtkWidget *widget,
G_END_DECLS
#endif /* GIMP_DISABLE_DEPRECATED */
#endif /* __GIMP_FONT_MENU_H__ */
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpfontmenu.c
* gimpfontselectbutton.c
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
*
* This library is free software; you can redistribute it and/or
......@@ -24,39 +24,54 @@
#include "gimp.h"
#include "gimpui.h"
#include "gimpuimarshal.h"
#include "libgimp-intl.h"
#define FONT_SELECT_DATA_KEY "gimp-font-select-data"
#define GIMP_FONT_SELECT_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIMP_TYPE_FONT_SELECT_BUTTON, GimpFontSelectButtonPrivate))
typedef struct _FontSelect FontSelect;
struct _FontSelect
struct _GimpFontSelectButtonPrivate
{
gchar *title;
GimpRunFontCallback callback;
gpointer data;
gchar *font_name; /* Local copy */
GtkWidget *button;
GtkWidget *inside;
GtkWidget *label;
gchar *font_name; /* Local copy */
const gchar *temp_font_callback;
};
enum
{
FONT_SET,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_TITLE,
PROP_FONT_NAME
};
/* local function prototypes */
static void gimp_font_select_widget_callback (const gchar *name,
static void gimp_font_select_button_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_font_select_button_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_font_select_button_destroy (GtkObject *object);
static void gimp_font_select_button_clicked (GtkButton *button);
static void gimp_font_select_button_callback (const gchar *name,
gboolean closing,
gpointer data);
static void gimp_font_select_widget_clicked (GtkWidget *widget,
FontSelect *font_sel);
static void gimp_font_select_widget_destroy (GtkWidget *widget,
FontSelect *font_sel);
static void gimp_font_select_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
......@@ -66,12 +81,109 @@ static void gimp_font_select_drag_data_received (GtkWidget *widget,
guint info,
guint time);
static GtkWidget * gimp_font_select_button_create_inside (GimpFontSelectButton *font_button);
static const GtkTargetEntry target = { "application/x-gimp-font-name", 0 };
static guint font_button_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(GimpFontSelectButton,
gimp_font_select_button,
GTK_TYPE_BUTTON);
static void
gimp_font_select_button_class_init (GimpFontSelectButtonClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
gobject_class->set_property = gimp_font_select_button_set_property;
gobject_class->get_property = gimp_font_select_button_get_property;
object_class->destroy = gimp_font_select_button_destroy;
widget_class->drag_data_received = gimp_font_select_drag_data_received;
button_class->clicked = gimp_font_select_button_clicked;
klass->font_set = NULL;
/**
* GimpFontSelectButton:title:
*
* The title to be used for the font selection dialog.
*
* Since: GIMP 2.4
*/
g_object_class_install_property (gobject_class, PROP_TITLE,
g_param_spec_string ("title", NULL, NULL,
_("Font Selection"),
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
/**
* GimpFontSelectButton:font-name:
*
* The name of the currently selected font.
*
* Since: 2.4
*/
g_object_class_install_property (gobject_class, PROP_FONT_NAME,
g_param_spec_string ("font-name", NULL, NULL,
_("Sans"),
G_PARAM_READWRITE));
/**
* GimpFontSelectButton::font-set:
* @widget: the object which received the signal.
* @font_name: the name of the currently selected font.
* @dialog_closing: whether the dialog was closed or not.
*
* The ::font-set signal is emitted when the user selects a font.
*
* Since: 2.4
*/
font_button_signals[FONT_SET] =
g_signal_new ("font-set",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpFontSelectButtonClass, font_set),
NULL, NULL,
_gimpui_marshal_VOID__STRING_BOOLEAN,
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
g_type_class_add_private (object_class, sizeof (GimpFontSelectButtonPrivate));
}
static void
gimp_font_select_button_init (GimpFontSelectButton *font_button)
{
font_button->priv = GIMP_FONT_SELECT_BUTTON_GET_PRIVATE (font_button);
font_button->priv->title = g_strdup(_("Font Selection"));
font_button->priv->font_name = g_strdup(_("Sans"));
font_button->priv->temp_font_callback = NULL;
font_button->priv->inside =
gimp_font_select_button_create_inside (font_button);
gtk_container_add (GTK_CONTAINER (font_button), font_button->priv->inside);
gtk_drag_dest_set (GTK_WIDGET (font_button),
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP,
&target, 1,
GDK_ACTION_COPY);
}
/**
* gimp_font_select_widget_new:
* gimp_font_select_button_new:
* @title: Title of the dialog to use or %NULL means to use the default
* title.
* @font_name: Initial font name.
......@@ -85,167 +197,189 @@ static const GtkTargetEntry target = { "application/x-gimp-font-name", 0 };
* Returns: A #GtkWidget that you can use in your UI.
*/
GtkWidget *
gimp_font_select_widget_new (const gchar *title,
const gchar *font_name,
GimpRunFontCallback callback,
gpointer data)
gimp_font_select_button_new (const gchar *title,
const gchar *font_name)
{
FontSelect *font_sel;
GtkWidget *hbox;
GtkWidget *image;
g_return_val_if_fail (callback != NULL, NULL);
if (! title)
title = _("Font Selection");
font_sel = g_new0 (FontSelect, 1);
font_sel->title = g_strdup (title);
font_sel->callback = callback;
font_sel->data = data;
font_sel->font_name = g_strdup (font_name);
font_sel->button = gtk_button_new ();
g_signal_connect (font_sel->button, "clicked",
G_CALLBACK (gimp_font_select_widget_clicked),
font_sel);
g_signal_connect (font_sel->button, "destroy",
G_CALLBACK (gimp_font_select_widget_destroy),
font_sel);
gtk_drag_dest_set (GTK_WIDGET (font_sel->button),
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP,
&target, 1,
GDK_ACTION_COPY);
g_signal_connect (font_sel->button, "drag-data-received",
G_CALLBACK (gimp_font_select_drag_data_received),
NULL);
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (font_sel->button), hbox);
gtk_widget_show (hbox);