Files
gimp/app/widgets/gimpdataeditor.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

610 lines
19 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpdataeditor.c
* Copyright (C) 2002-2004 Michael Natterer <mitch@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 <gdk/gdkkeysyms.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpdata.h"
#include "core/gimpdatafactory.h"
#include "gimpdataeditor.h"
#include "gimpdocked.h"
#include "gimpmenufactory.h"
#include "gimpsessioninfo.h"
#include "gimpuimanager.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_DATA_FACTORY,
PROP_CONTEXT,
PROP_DATA
};
static void gimp_data_editor_docked_iface_init (GimpDockedInterface *iface);
static GObject * gimp_data_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_data_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_data_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_data_editor_dispose (GObject *object);
static void gimp_data_editor_set_context (GimpDocked *docked,
GimpContext *context);
static void gimp_data_editor_set_aux_info (GimpDocked *docked,
GList *aux_info);
static GList * gimp_data_editor_get_aux_info (GimpDocked *docked);
static gchar * gimp_data_editor_get_title (GimpDocked *docked);
static void gimp_data_editor_real_set_data (GimpDataEditor *editor,
GimpData *data);
static void gimp_data_editor_data_changed (GimpContext *context,
GimpData *data,
GimpDataEditor *editor);
static gboolean gimp_data_editor_name_key_press (GtkWidget *widget,
GdkEventKey *kevent,
GimpDataEditor *editor);
static void gimp_data_editor_name_activate (GtkWidget *widget,
GimpDataEditor *editor);
static gboolean gimp_data_editor_name_focus_out (GtkWidget *widget,
GdkEvent *event,
GimpDataEditor *editor);
static void gimp_data_editor_data_name_changed (GimpObject *object,
GimpDataEditor *editor);
static void gimp_data_editor_save_clicked (GtkWidget *widget,
GimpDataEditor *editor);
static void gimp_data_editor_revert_clicked (GtkWidget *widget,
GimpDataEditor *editor);
static void gimp_data_editor_save_dirty (GimpDataEditor *editor);
G_DEFINE_TYPE_WITH_CODE (GimpDataEditor, gimp_data_editor, GIMP_TYPE_EDITOR,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
gimp_data_editor_docked_iface_init))
#define parent_class gimp_data_editor_parent_class
static GimpDockedInterface *parent_docked_iface = NULL;
static void
gimp_data_editor_class_init (GimpDataEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructor = gimp_data_editor_constructor;
object_class->set_property = gimp_data_editor_set_property;
object_class->get_property = gimp_data_editor_get_property;
object_class->dispose = gimp_data_editor_dispose;
klass->set_data = gimp_data_editor_real_set_data;
g_object_class_install_property (object_class, PROP_DATA_FACTORY,
g_param_spec_object ("data-factory",
NULL, NULL,
GIMP_TYPE_DATA_FACTORY,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context",
NULL, NULL,
GIMP_TYPE_CONTEXT,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_DATA,
g_param_spec_object ("data",
NULL, NULL,
GIMP_TYPE_DATA,
GIMP_PARAM_READWRITE));
}
static void
gimp_data_editor_init (GimpDataEditor *editor)
{
editor->data_factory = NULL;
editor->context = NULL;
editor->data = NULL;
editor->data_editable = FALSE;
editor->name_entry = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (editor), editor->name_entry, FALSE, FALSE, 0);
gtk_widget_show (editor->name_entry);
gtk_widget_set_sensitive (editor->name_entry, FALSE);
g_signal_connect (editor->name_entry, "key-press-event",
G_CALLBACK (gimp_data_editor_name_key_press),
editor);
g_signal_connect (editor->name_entry, "activate",
G_CALLBACK (gimp_data_editor_name_activate),
editor);
g_signal_connect (editor->name_entry, "focus-out-event",
G_CALLBACK (gimp_data_editor_name_focus_out),
editor);
}
static void
gimp_data_editor_docked_iface_init (GimpDockedInterface *iface)
{
parent_docked_iface = g_type_interface_peek_parent (iface);
if (! parent_docked_iface)
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
iface->set_context = gimp_data_editor_set_context;
iface->set_aux_info = gimp_data_editor_set_aux_info;
iface->get_aux_info = gimp_data_editor_get_aux_info;
iface->get_title = gimp_data_editor_get_title;
}
static GObject *
gimp_data_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpDataEditor *editor;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_DATA_EDITOR (object);
g_assert (GIMP_IS_DATA_FACTORY (editor->data_factory));
gimp_data_editor_set_edit_active (editor, TRUE);
editor->save_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_SAVE,
_("Save"), NULL,
G_CALLBACK (gimp_data_editor_save_clicked),
NULL,
editor);
editor->revert_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_REVERT_TO_SAVED,
_("Revert"), NULL,
G_CALLBACK (gimp_data_editor_revert_clicked),
NULL,
editor);
/*
* Set insensitive because revert buttons are not yet implemented.
*/
gtk_widget_set_sensitive (editor->revert_button, FALSE);
return object;
}
static void
gimp_data_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
switch (property_id)
{
case PROP_DATA_FACTORY:
editor->data_factory = g_value_get_object (value);
break;
case PROP_CONTEXT:
gimp_docked_set_context (GIMP_DOCKED (object),
g_value_get_object (value));
break;
case PROP_DATA:
gimp_data_editor_set_data (editor, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_data_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
switch (property_id)
{
case PROP_DATA_FACTORY:
g_value_set_object (value, editor->data_factory);
break;
case PROP_CONTEXT:
g_value_set_object (value, editor->context);
break;
case PROP_DATA:
g_value_set_object (value, editor->data);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_data_editor_dispose (GObject *object)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
if (editor->data)
{
/* Save dirty data before we clear out */
gimp_data_editor_save_dirty (editor);
gimp_data_editor_set_data (editor, NULL);
}
if (editor->context)
gimp_docked_set_context (GIMP_DOCKED (editor), NULL);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_data_editor_set_context (GimpDocked *docked,
GimpContext *context)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
if (context == editor->context)
return;
if (parent_docked_iface->set_context)
parent_docked_iface->set_context (docked, context);
if (editor->context)
{
g_signal_handlers_disconnect_by_func (editor->context,
gimp_data_editor_data_changed,
editor);
g_object_unref (editor->context);
}
editor->context = context;
if (editor->context)
{
GType data_type;
GimpData *data;
g_object_ref (editor->context);
data_type = editor->data_factory->container->children_type;
data = GIMP_DATA (gimp_context_get_by_type (editor->context, data_type));
g_signal_connect (editor->context,
gimp_context_type_to_signal_name (data_type),
G_CALLBACK (gimp_data_editor_data_changed),
editor);
gimp_data_editor_data_changed (editor->context, data, editor);
}
}
#define AUX_INFO_EDIT_ACTIVE "edit-active"
#define AUX_INFO_CURRENT_DATA "current-data"
static void
gimp_data_editor_set_aux_info (GimpDocked *docked,
GList *aux_info)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
GList *list;
parent_docked_iface->set_aux_info (docked, aux_info);
for (list = aux_info; list; list = g_list_next (list))
{
GimpSessionInfoAux *aux = list->data;
if (! strcmp (aux->name, AUX_INFO_EDIT_ACTIVE))
{
gboolean edit_active;
edit_active = ! g_ascii_strcasecmp (aux->value, "true");
gimp_data_editor_set_edit_active (editor, edit_active);
}
else if (! strcmp (aux->name, AUX_INFO_CURRENT_DATA))
{
if (! editor->edit_active)
{
GimpData *data;
data = (GimpData *)
gimp_container_get_child_by_name (editor->data_factory->container,
aux->value);
if (data)
gimp_data_editor_set_data (editor, data);
}
}
}
}
static GList *
gimp_data_editor_get_aux_info (GimpDocked *docked)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
GList *aux_info;
GimpSessionInfoAux *aux;
aux_info = parent_docked_iface->get_aux_info (docked);
aux = gimp_session_info_aux_new (AUX_INFO_EDIT_ACTIVE,
editor->edit_active ? "true" : "false");
aux_info = g_list_append (aux_info, aux);
if (editor->data)
{
const gchar *value;
value = gimp_object_get_name (GIMP_OBJECT (editor->data));
aux = gimp_session_info_aux_new (AUX_INFO_CURRENT_DATA, value);
aux_info = g_list_append (aux_info, aux);
}
return aux_info;
}
static gchar *
gimp_data_editor_get_title (GimpDocked *docked)
{
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_GET_CLASS (editor);
if (editor->data_editable)
return g_strdup (editor_class->title);
else
return g_strdup_printf (_("%s (read only)"), editor_class->title);
}
static void
gimp_data_editor_real_set_data (GimpDataEditor *editor,
GimpData *data)
{
gboolean editable;
if (editor->data)
{
g_signal_handlers_disconnect_by_func (editor->data,
gimp_data_editor_data_name_changed,
editor);
g_object_unref (editor->data);
}
editor->data = data;
if (editor->data)
{
g_object_ref (editor->data);
g_signal_connect (editor->data, "name-changed",
G_CALLBACK (gimp_data_editor_data_name_changed),
editor);
gtk_entry_set_text (GTK_ENTRY (editor->name_entry),
gimp_object_get_name (GIMP_OBJECT (editor->data)));
}
else
{
gtk_entry_set_text (GTK_ENTRY (editor->name_entry), "");
}
editable = (editor->data && editor->data->writable);
if (editor->data_editable != editable)
{
editor->data_editable = editable;
gtk_widget_set_sensitive (editor->name_entry, editable);
gimp_docked_title_changed (GIMP_DOCKED (editor));
}
}
void
gimp_data_editor_set_data (GimpDataEditor *editor,
GimpData *data)
{
g_return_if_fail (GIMP_IS_DATA_EDITOR (editor));
g_return_if_fail (data == NULL || GIMP_IS_DATA (data));
g_return_if_fail (data == NULL ||
g_type_is_a (G_TYPE_FROM_INSTANCE (data),
editor->data_factory->container->children_type));
if (editor->data != data)
{
GIMP_DATA_EDITOR_GET_CLASS (editor)->set_data (editor, data);
g_object_notify (G_OBJECT (editor), "data");
if (GIMP_EDITOR (editor)->ui_manager)
gimp_ui_manager_update (GIMP_EDITOR (editor)->ui_manager,
GIMP_EDITOR (editor)->popup_data);
}
}
GimpData *
gimp_data_editor_get_data (GimpDataEditor *editor)
{
g_return_val_if_fail (GIMP_IS_DATA_EDITOR (editor), NULL);
return editor->data;
}
void
gimp_data_editor_set_edit_active (GimpDataEditor *editor,
gboolean edit_active)
{
g_return_if_fail (GIMP_IS_DATA_EDITOR (editor));
if (editor->edit_active != edit_active)
{
editor->edit_active = edit_active;
if (editor->edit_active && editor->context)
{
GType data_type;
GimpData *data;
data_type = editor->data_factory->container->children_type;
data = GIMP_DATA (gimp_context_get_by_type (editor->context,
data_type));
gimp_data_editor_set_data (editor, data);
}
}
}
gboolean
gimp_data_editor_get_edit_active (GimpDataEditor *editor)
{
g_return_val_if_fail (GIMP_IS_DATA_EDITOR (editor), FALSE);
return editor->edit_active;
}
/* private functions */
static void
gimp_data_editor_data_changed (GimpContext *context,
GimpData *data,
GimpDataEditor *editor)
{
if (editor->edit_active)
gimp_data_editor_set_data (editor, data);
}
static gboolean
gimp_data_editor_name_key_press (GtkWidget *widget,
GdkEventKey *kevent,
GimpDataEditor *editor)
{
if (kevent->keyval == GDK_Escape)
{
gtk_entry_set_text (GTK_ENTRY (editor->name_entry),
gimp_object_get_name (GIMP_OBJECT (editor->data)));
return TRUE;
}
return FALSE;
}
static void
gimp_data_editor_name_activate (GtkWidget *widget,
GimpDataEditor *editor)
{
if (editor->data)
{
gchar *new_name;
new_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
new_name = g_strstrip (new_name);
if (strlen (new_name))
{
gimp_object_take_name (GIMP_OBJECT (editor->data), new_name);
}
else
{
gtk_entry_set_text (GTK_ENTRY (widget),
gimp_object_get_name (GIMP_OBJECT (editor->data)));
g_free (new_name);
}
}
}
static gboolean
gimp_data_editor_name_focus_out (GtkWidget *widget,
GdkEvent *event,
GimpDataEditor *editor)
{
gimp_data_editor_name_activate (widget, editor);
return FALSE;
}
static void
gimp_data_editor_data_name_changed (GimpObject *object,
GimpDataEditor *editor)
{
gtk_entry_set_text (GTK_ENTRY (editor->name_entry),
gimp_object_get_name (object));
}
static void
gimp_data_editor_save_clicked (GtkWidget *widget,
GimpDataEditor *editor)
{
gimp_data_editor_save_dirty (editor);
}
static void
gimp_data_editor_revert_clicked (GtkWidget *widget,
GimpDataEditor *editor)
{
g_print ("TODO: implement revert\n");
}
static void
gimp_data_editor_save_dirty (GimpDataEditor *editor)
{
GimpData *data = editor->data;
if (data && data->dirty && data->writable)
gimp_data_factory_data_save_single (editor->data_factory, data);
}