Gimp/app/widgets/gimppropwidgets.c
Michael Natterer b53aa45a76 Changed GimpViewable preview rendering to have a context to get
2006-08-29  Michael Natterer  <mitch@gimp.org>

	Changed GimpViewable preview rendering to have a context to get
	FG/BG/whatever from. Use the context to enable dynamic FG/BG
	colors in gradients. Fixes bug #127676 and bug #352214. Addresses
	bug #128367 (doesn't fix it because there's no loading/saving and
	no GUI yet).

	* app/core/core-enums.[ch]: added enum GimpGradientColor to enable
	specifying gradient colors in terms of foreground and background.

	* app/core/gimpgradient.[ch]: added color_type members to the
	GimpGradientSegment struct and honor them in
	gimp_gradient_get_color_at(). Added GimpContext parameters to all
	functions which finally call get_color_at().

	* app/core/gimp-gradients.c: use the new method to implement the
	builtin gradients.

	* app/core/gimpviewable.[ch]: added GimpContext parameters to all
	get_preview() and get_pixbuf() functions.

	* app/core/gimpbrush.c
	* app/core/gimpbuffer.c
	* app/core/gimpdrawable-preview.[ch]
	* app/core/gimpgradient.c
	* app/core/gimpimage-preview.[ch]
	* app/core/gimpimagefile.c
	* app/core/gimppalette.c
	* app/core/gimppattern.c
	* app/core/gimpundo.[ch]
	* app/text/gimpfont.c
	* app/vectors/gimpvectors-preview.[ch]: changed ::get_preview()
	and ::get_pixbuf() implementations accordingly.

	* app/core/gimpdrawable-blend.c
	* app/core/gimppalette-import.[ch]
	* app/dialogs/dialogs-constructors.c
	* app/dialogs/palette-import-dialog.c
	* app/dialogs/resize-dialog.c
	* app/display/gimpdisplayshell-layer-select.c
	* app/display/gimpdisplayshell.c
	* app/display/gimpnavigationeditor.c
	* app/paint/gimppaintoptions.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimptexttool.c
	* app/actions/gradient-editor-commands.c
	* app/widgets/gimpaction.c
	* app/widgets/gimpbrusheditor.[ch]
	* app/widgets/gimpbufferview.c
	* app/widgets/gimpcellrendererviewable.c
	* app/widgets/gimpchanneltreeview.c
	* app/widgets/gimpclipboard.c
	* app/widgets/gimpcoloreditor.c
	* app/widgets/gimpcomponenteditor.c
	* app/widgets/gimpcontainerbox.c
	* app/widgets/gimpcontainercombobox.c
	* app/widgets/gimpcontainereditor.c
	* app/widgets/gimpcontainerentry.c
	* app/widgets/gimpcontainergridview.c
	* app/widgets/gimpcontainertreeview.[ch]
	* app/widgets/gimpdataeditor.[ch]
	* app/widgets/gimpdevicestatus.c
	* app/widgets/gimpdnd.[ch]
	* app/widgets/gimpdrawabletreeview.c
	* app/widgets/gimpfiledialog.c
	* app/widgets/gimpgradienteditor.[ch]
	* app/widgets/gimpgradientselect.c
	* app/widgets/gimpitemtreeview.c
	* app/widgets/gimplayertreeview.c
	* app/widgets/gimppaletteeditor.[ch]
	* app/widgets/gimppropwidgets.[ch]
	* app/widgets/gimpselectioneditor.c
	* app/widgets/gimpthumbbox.[ch]
	* app/widgets/gimptoolbox-image-area.c
	* app/widgets/gimptoolbox-indicator-area.c
	* app/widgets/gimptooloptionseditor.c
	* app/widgets/gimpundoeditor.c
	* app/widgets/gimpvectorstreeview.c
	* app/widgets/gimpview-popup.[ch]
	* app/widgets/gimpview.[ch]
	* app/widgets/gimpviewablebutton.c
	* app/widgets/gimpviewabledialog.c
	* app/widgets/gimpviewrenderer.[ch]
	* app/widgets/gimpviewrenderer-frame.c
	* app/widgets/gimpviewrendererbrush.c
	* app/widgets/gimpviewrendererbuffer.c
	* app/widgets/gimpviewrendererdrawable.c
	* app/widgets/gimpviewrenderergradient.c
	* app/widgets/gimpviewrendererimage.c
	* tools/pdbgen/pdb/drawable.pdb
	* tools/pdbgen/pdb/gradient.pdb
	* tools/pdbgen/pdb/gradients.pdb
	* tools/pdbgen/pdb/image.pdb: added tons of GimpContext members
	and parameters, implement GimpDocked::set_context() in many
	widgets. Pass these locally remembered contexts to GimpViewable
	functions. Did some minor cleanups on the way. There are still
	some minor FIXMEs around where the code uses a NULL context (which
	is allowed by the APIs)

	* app/pdb/drawable_cmds.c
	* app/pdb/gradient_cmds.c
	* app/pdb/gradients_cmds.c
	* app/pdb/image_cmds.c: regenerated.
2006-08-29 21:44:51 +00:00

499 lines
14 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* gimppropwidgets.c
* Copyright (C) 2002-2004 Michael Natterer <mitch@gimp.org>
* Sven Neumann <sven@gimp.org>
*
* 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 "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimpviewable.h"
#include "gimpcolorpanel.h"
#include "gimpdnd.h"
#include "gimpview.h"
#include "gimppropwidgets.h"
#include "gimpwidgets-constructors.h"
#include "gimp-intl.h"
/* utility function prototypes */
static void set_param_spec (GObject *object,
GtkWidget *widget,
GParamSpec *param_spec);
static GParamSpec * get_param_spec (GObject *object);
static GParamSpec * find_param_spec (GObject *object,
const gchar *property_name,
const gchar *strloc);
static GParamSpec * check_param_spec (GObject *object,
const gchar *property_name,
GType type,
const gchar *strloc);
static void connect_notify (GObject *config,
const gchar *property_name,
GCallback callback,
gpointer callback_data);
/****************/
/* paint menu */
/****************/
static void gimp_prop_paint_menu_callback (GtkWidget *widget,
GObject *config);
static void gimp_prop_paint_menu_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *menu);
/**
* gimp_prop_paint_mode_menu_new:
* @config: #GimpConfig object to which property is attached.
* @property_name: Name of Enum property.
* @with_behind_mode: Whether to include "Behind" mode in the menu.
*
* Creates a #GimpPaintModeMenu widget to display and set the specified
* Enum property, for which the enum must be #GimpLayerModeEffects.
*
* Return value: The newly created #GimpPaintModeMenu widget.
*
* Since GIMP 2.4
*/
GtkWidget *
gimp_prop_paint_mode_menu_new (GObject *config,
const gchar *property_name,
gboolean with_behind_mode)
{
GParamSpec *param_spec;
GtkWidget *menu;
gint value;
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_ENUM, G_STRFUNC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
menu = gimp_paint_mode_menu_new (with_behind_mode);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (menu),
value,
G_CALLBACK (gimp_prop_paint_menu_callback),
config);
set_param_spec (G_OBJECT (menu), menu, param_spec);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_paint_menu_notify),
menu);
return menu;
}
static void
gimp_prop_paint_menu_callback (GtkWidget *widget,
GObject *config)
{
GParamSpec *param_spec;
gint value;
param_spec = get_param_spec (G_OBJECT (widget));
if (! param_spec)
return;
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value))
{
g_object_set (config,
param_spec->name, value,
NULL);
}
}
static void
gimp_prop_paint_menu_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *menu)
{
gint value;
g_object_get (config,
param_spec->name, &value,
NULL);
g_signal_handlers_block_by_func (menu,
gimp_prop_paint_menu_callback,
config);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (menu), value);
g_signal_handlers_unblock_by_func (menu,
gimp_prop_paint_menu_callback,
config);
}
/******************/
/* color button */
/******************/
static void gimp_prop_color_button_callback (GtkWidget *widget,
GObject *config);
static void gimp_prop_color_button_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *button);
/**
* gimp_prop_color_button_new:
* @config: #GimpConfig object to which property is attached.
* @property_name: Name of #GimpRGB property.
* @title: Title of the #GimpColorPanel that is to be created
* @width: Width of color button.
* @height: Height of color button.
* @type: How transparency is represented.
*
* Creates a #GimpColorPanel to set and display the value of a #GimpRGB
* property. Pressing the button brings up a color selector dialog.
*
* Return value: A new #GimpColorPanel widget.
*
* Since GIMP 2.4
*/
GtkWidget *
gimp_prop_color_button_new (GObject *config,
const gchar *property_name,
const gchar *title,
gint width,
gint height,
GimpColorAreaType type)
{
GParamSpec *param_spec;
GtkWidget *button;
GimpRGB *value;
param_spec = check_param_spec (config, property_name,
GIMP_TYPE_PARAM_RGB, G_STRFUNC);
if (! param_spec)
return NULL;
g_object_get (config,
property_name, &value,
NULL);
button = gimp_color_panel_new (title, value, type, width, height);
g_free (value);
set_param_spec (G_OBJECT (button), button, param_spec);
g_signal_connect (button, "color-changed",
G_CALLBACK (gimp_prop_color_button_callback),
config);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_color_button_notify),
button);
return button;
}
static void
gimp_prop_color_button_callback (GtkWidget *button,
GObject *config)
{
GParamSpec *param_spec;
GimpRGB value;
param_spec = get_param_spec (G_OBJECT (button));
if (! param_spec)
return;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &value);
g_signal_handlers_block_by_func (config,
gimp_prop_color_button_notify,
button);
g_object_set (config,
param_spec->name, &value,
NULL);
g_signal_handlers_unblock_by_func (config,
gimp_prop_color_button_notify,
button);
}
static void
gimp_prop_color_button_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *button)
{
GimpRGB *value;
g_object_get (config,
param_spec->name, &value,
NULL);
g_signal_handlers_block_by_func (button,
gimp_prop_color_button_callback,
config);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (button), value);
g_free (value);
g_signal_handlers_unblock_by_func (button,
gimp_prop_color_button_callback,
config);
}
/*************/
/* view */
/*************/
static void gimp_prop_view_drop (GtkWidget *menu,
gint x,
gint y,
GimpViewable *viewable,
gpointer data);
static void gimp_prop_view_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *view);
/**
* gimp_prop_view_new:
* @config: #GimpConfig object to which property is attached.
* @context: a #Gimpcontext.
* @property_name: Name of #GimpViewable property.
* @size: Width and height of preview display.
*
* Creates a widget to display the value of a #GimpViewable property.
*
* Return value: A new #GimpView widget.
*
* Since GIMP 2.4
*/
GtkWidget *
gimp_prop_view_new (GObject *config,
const gchar *property_name,
GimpContext *context,
gint size)
{
GParamSpec *param_spec;
GtkWidget *view;
GimpViewable *viewable;
param_spec = check_param_spec (config, property_name,
G_TYPE_PARAM_OBJECT, G_STRFUNC);
if (! param_spec)
return NULL;
if (! g_type_is_a (param_spec->value_type, GIMP_TYPE_VIEWABLE))
{
g_warning ("%s: property '%s' of %s is not a GimpViewable",
G_STRFUNC, property_name,
g_type_name (G_TYPE_FROM_INSTANCE (config)));
return NULL;
}
view = gimp_view_new_by_types (context,
GIMP_TYPE_VIEW,
param_spec->value_type,
size, 0, FALSE);
if (! view)
{
g_warning ("%s: cannot create view for type '%s'",
G_STRFUNC, g_type_name (param_spec->value_type));
return NULL;
}
g_object_get (config,
property_name, &viewable,
NULL);
if (viewable)
{
gimp_view_set_viewable (GIMP_VIEW (view), viewable);
g_object_unref (viewable);
}
set_param_spec (G_OBJECT (view), view, param_spec);
gimp_dnd_viewable_dest_add (view, param_spec->value_type,
gimp_prop_view_drop,
config);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_view_notify),
view);
return view;
}
static void
gimp_prop_view_drop (GtkWidget *view,
gint x,
gint y,
GimpViewable *viewable,
gpointer data)
{
GObject *config;
GParamSpec *param_spec;
param_spec = get_param_spec (G_OBJECT (view));
if (! param_spec)
return;
config = G_OBJECT (data);
g_object_set (config,
param_spec->name, viewable,
NULL);
}
static void
gimp_prop_view_notify (GObject *config,
GParamSpec *param_spec,
GtkWidget *view)
{
GimpViewable *viewable;
g_object_get (config,
param_spec->name, &viewable,
NULL);
gimp_view_set_viewable (GIMP_VIEW (view), viewable);
if (viewable)
g_object_unref (viewable);
}
/*******************************/
/* private utility functions */
/*******************************/
static GQuark param_spec_quark = 0;
static void
set_param_spec (GObject *object,
GtkWidget *widget,
GParamSpec *param_spec)
{
if (object)
{
if (! param_spec_quark)
param_spec_quark = g_quark_from_static_string ("gimp-config-param-spec");
g_object_set_qdata (object, param_spec_quark, param_spec);
}
if (widget)
{
const gchar *blurb = g_param_spec_get_blurb (param_spec);
if (blurb)
gimp_help_set_help_data (widget, gettext (blurb), NULL);
}
}
static GParamSpec *
get_param_spec (GObject *object)
{
if (! param_spec_quark)
param_spec_quark = g_quark_from_static_string ("gimp-config-param-spec");
return g_object_get_qdata (object, param_spec_quark);
}
static GParamSpec *
find_param_spec (GObject *object,
const gchar *property_name,
const gchar *strloc)
{
GParamSpec *param_spec;
param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
property_name);
if (! param_spec)
g_warning ("%s: %s has no property named '%s'",
strloc,
g_type_name (G_TYPE_FROM_INSTANCE (object)),
property_name);
return param_spec;
}
static GParamSpec *
check_param_spec (GObject *object,
const gchar *property_name,
GType type,
const gchar *strloc)
{
GParamSpec *param_spec;
param_spec = find_param_spec (object, property_name, strloc);
if (param_spec && ! g_type_is_a (G_TYPE_FROM_INSTANCE (param_spec), type))
{
g_warning ("%s: property '%s' of %s is not a %s",
strloc,
param_spec->name,
g_type_name (param_spec->owner_type),
g_type_name (type));
return NULL;
}
return param_spec;
}
static void
connect_notify (GObject *config,
const gchar *property_name,
GCallback callback,
gpointer callback_data)
{
gchar *notify_name;
notify_name = g_strconcat ("notify::", property_name, NULL);
g_signal_connect_object (config, notify_name, callback, callback_data, 0);
g_free (notify_name);
}