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

439 lines
14 KiB
C

/* 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.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimplist.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "core/gimpundostack.h"
#include "gimpcontainertreeview.h"
#include "gimpcontainerview.h"
#include "gimphelp-ids.h"
#include "gimpmenufactory.h"
#include "gimpundoeditor.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_VIEW_SIZE
};
static GObject * gimp_undo_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_undo_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_undo_editor_set_image (GimpImageEditor *editor,
GimpImage *image);
static void gimp_undo_editor_fill (GimpUndoEditor *editor);
static void gimp_undo_editor_clear (GimpUndoEditor *editor);
static void gimp_undo_editor_undo_event (GimpImage *image,
GimpUndoEvent event,
GimpUndo *undo,
GimpUndoEditor *editor);
static void gimp_undo_editor_select_item (GimpContainerView *view,
GimpUndo *undo,
gpointer insert_data,
GimpUndoEditor *editor);
G_DEFINE_TYPE (GimpUndoEditor, gimp_undo_editor, GIMP_TYPE_IMAGE_EDITOR)
#define parent_class gimp_undo_editor_parent_class
static void
gimp_undo_editor_class_init (GimpUndoEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpImageEditorClass *image_editor_class = GIMP_IMAGE_EDITOR_CLASS (klass);
object_class->constructor = gimp_undo_editor_constructor;
object_class->set_property = gimp_undo_editor_set_property;
image_editor_class->set_image = gimp_undo_editor_set_image;
g_object_class_install_property (object_class, PROP_VIEW_SIZE,
g_param_spec_enum ("view-size",
NULL, NULL,
GIMP_TYPE_VIEW_SIZE,
GIMP_VIEW_SIZE_LARGE,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_undo_editor_init (GimpUndoEditor *undo_editor)
{
}
static GObject *
gimp_undo_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GimpUndoEditor *undo_editor;
GObject *object;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
undo_editor = GIMP_UNDO_EDITOR (object);
undo_editor->view = gimp_container_tree_view_new (NULL, NULL,
undo_editor->view_size,
1);
gtk_container_add (GTK_CONTAINER (undo_editor), undo_editor->view);
gtk_widget_show (undo_editor->view);
g_signal_connect (undo_editor->view, "select-item",
G_CALLBACK (gimp_undo_editor_select_item),
undo_editor);
undo_editor->undo_button =
gimp_editor_add_action_button (GIMP_EDITOR (undo_editor), "edit",
"edit-undo", NULL);
undo_editor->redo_button =
gimp_editor_add_action_button (GIMP_EDITOR (undo_editor), "edit",
"edit-redo", NULL);
undo_editor->clear_button =
gimp_editor_add_action_button (GIMP_EDITOR (undo_editor), "edit",
"edit-undo-clear", NULL);
return object;
}
static void
gimp_undo_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpUndoEditor *undo_editor = GIMP_UNDO_EDITOR (object);
switch (property_id)
{
case PROP_VIEW_SIZE:
undo_editor->view_size = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_undo_editor_set_image (GimpImageEditor *image_editor,
GimpImage *image)
{
GimpUndoEditor *editor = GIMP_UNDO_EDITOR (image_editor);
if (image_editor->image)
{
gimp_undo_editor_clear (editor);
g_signal_handlers_disconnect_by_func (image_editor->image,
gimp_undo_editor_undo_event,
editor);
}
GIMP_IMAGE_EDITOR_CLASS (parent_class)->set_image (image_editor, image);
if (image_editor->image)
{
if (gimp_image_undo_is_enabled (image_editor->image))
gimp_undo_editor_fill (editor);
g_signal_connect (image_editor->image, "undo-event",
G_CALLBACK (gimp_undo_editor_undo_event),
editor);
}
}
/* public functions */
GtkWidget *
gimp_undo_editor_new (GimpCoreConfig *config,
GimpMenuFactory *menu_factory)
{
g_return_val_if_fail (GIMP_IS_CORE_CONFIG (config), NULL);
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
return g_object_new (GIMP_TYPE_UNDO_EDITOR,
"menu-factory", menu_factory,
"menu-identifier", "<UndoEditor>",
"ui-path", "/undo-editor-popup",
"view-size", config->undo_preview_size,
NULL);
}
/* private functions */
static void
gimp_undo_editor_fill (GimpUndoEditor *editor)
{
GimpImage *image;
GimpUndo *top_undo_item;
GList *list;
image = GIMP_IMAGE_EDITOR (editor)->image;
/* create a container as model for the undo history list */
editor->container = gimp_list_new (GIMP_TYPE_UNDO, FALSE);
editor->base_item = g_object_new (GIMP_TYPE_UNDO,
"image", image,
"name", _("[ Base Image ]"),
NULL);
/* the list prepends its items, so first add the redo items... */
for (list = GIMP_LIST (image->redo_stack->undos)->list;
list;
list = g_list_next (list))
{
gimp_container_add (editor->container, GIMP_OBJECT (list->data));
}
/* ...reverse the list so the redo items are in ascending order... */
gimp_list_reverse (GIMP_LIST (editor->container));
/* ...then add the undo items in descending order... */
for (list = GIMP_LIST (image->undo_stack->undos)->list;
list;
list = g_list_next (list))
{
/* Don't add the topmost item if it is an open undo group,
* it will be added upon closing of the group.
*/
if (list->prev || ! GIMP_IS_UNDO_STACK (list->data) ||
image->pushing_undo_group == GIMP_UNDO_GROUP_NONE)
{
gimp_container_add (editor->container, GIMP_OBJECT (list->data));
}
}
/* ...finally, the first item is the special "base_item" which stands
* for the image with no more undos available to pop
*/
gimp_container_add (editor->container, GIMP_OBJECT (editor->base_item));
/* display the container */
gimp_container_view_set_container (GIMP_CONTAINER_VIEW (editor->view),
editor->container);
top_undo_item = gimp_undo_stack_peek (image->undo_stack);
g_signal_handlers_block_by_func (editor->view,
gimp_undo_editor_select_item,
editor);
/* select the current state of the image */
if (top_undo_item)
{
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (editor->view),
GIMP_VIEWABLE (top_undo_item));
gimp_undo_create_preview (top_undo_item,
gimp_get_user_context (image->gimp),
FALSE);
}
else
{
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (editor->view),
GIMP_VIEWABLE (editor->base_item));
gimp_undo_create_preview (editor->base_item,
gimp_get_user_context (image->gimp),
TRUE);
}
g_signal_handlers_unblock_by_func (editor->view,
gimp_undo_editor_select_item,
editor);
}
static void
gimp_undo_editor_clear (GimpUndoEditor *editor)
{
if (editor->container)
{
gimp_container_view_set_container (GIMP_CONTAINER_VIEW (editor->view),
NULL);
g_object_unref (editor->container);
editor->container = NULL;
}
if (editor->base_item)
{
g_object_unref (editor->base_item);
editor->base_item = NULL;
}
}
static void
gimp_undo_editor_undo_event (GimpImage *image,
GimpUndoEvent event,
GimpUndo *undo,
GimpUndoEditor *editor)
{
GimpUndo *top_undo_item = gimp_undo_stack_peek (image->undo_stack);
switch (event)
{
case GIMP_UNDO_EVENT_UNDO_PUSHED:
g_signal_handlers_block_by_func (editor->view,
gimp_undo_editor_select_item,
editor);
gimp_container_insert (editor->container, GIMP_OBJECT (undo), -1);
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (editor->view),
GIMP_VIEWABLE (undo));
gimp_undo_create_preview (undo,
gimp_get_user_context (image->gimp),
FALSE);
g_signal_handlers_unblock_by_func (editor->view,
gimp_undo_editor_select_item,
editor);
break;
case GIMP_UNDO_EVENT_UNDO_EXPIRED:
case GIMP_UNDO_EVENT_REDO_EXPIRED:
gimp_container_remove (editor->container, GIMP_OBJECT (undo));
break;
case GIMP_UNDO_EVENT_UNDO:
case GIMP_UNDO_EVENT_REDO:
g_signal_handlers_block_by_func (editor->view,
gimp_undo_editor_select_item,
editor);
if (top_undo_item)
{
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (editor->view),
GIMP_VIEWABLE (top_undo_item));
gimp_undo_create_preview (top_undo_item,
gimp_get_user_context (image->gimp),
FALSE);
}
else
{
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (editor->view),
GIMP_VIEWABLE (editor->base_item));
gimp_undo_create_preview (editor->base_item,
gimp_get_user_context (image->gimp),
TRUE);
}
g_signal_handlers_unblock_by_func (editor->view,
gimp_undo_editor_select_item,
editor);
break;
case GIMP_UNDO_EVENT_UNDO_FREE:
if (gimp_image_undo_is_enabled (image))
gimp_undo_editor_clear (editor);
break;
case GIMP_UNDO_EVENT_UNDO_FREEZE:
gimp_undo_editor_clear (editor);
break;
case GIMP_UNDO_EVENT_UNDO_THAW:
gimp_undo_editor_fill (editor);
break;
}
}
static void
gimp_undo_editor_select_item (GimpContainerView *view,
GimpUndo *undo,
gpointer insert_data,
GimpUndoEditor *editor)
{
GimpImage *image;
GimpUndo *top_undo_item;
if (! undo)
return;
image = GIMP_IMAGE_EDITOR (editor)->image;
top_undo_item = gimp_undo_stack_peek (image->undo_stack);
if (undo == editor->base_item)
{
/* the base_item was selected, pop all available undo items
*/
while (top_undo_item != NULL)
{
gimp_image_undo (image);
top_undo_item = gimp_undo_stack_peek (image->undo_stack);
}
}
else if (gimp_container_have (image->undo_stack->undos, GIMP_OBJECT (undo)))
{
/* the selected item is on the undo stack, pop undos until it
* is on top of the undo stack
*/
while (top_undo_item != undo)
{
gimp_image_undo (image);
top_undo_item = gimp_undo_stack_peek (image->undo_stack);
}
}
else if (gimp_container_have (image->redo_stack->undos, GIMP_OBJECT (undo)))
{
/* the selected item is on the redo stack, pop redos until it
* is on top of the undo stack
*/
while (top_undo_item != undo)
{
gimp_image_redo (image);
top_undo_item = gimp_undo_stack_peek (image->undo_stack);
}
}
gimp_image_flush (image);
}