2007-01-31 21:05:43 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2007-01-31 21:05:43 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-01-31 21:05:43 +00:00
|
|
|
* (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
|
2009-01-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-01-31 21:05:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2007-01-31 21:05:43 +00:00
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpfloatingselundo.h"
|
2007-02-03 21:58:12 +00:00
|
|
|
#include "gimpimage.h"
|
2007-01-31 21:05:43 +00:00
|
|
|
#include "gimplayer.h"
|
|
|
|
#include "gimplayer-floating-sel.h"
|
|
|
|
|
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
static void gimp_floating_sel_undo_constructed (GObject *object);
|
2007-01-31 21:05:43 +00:00
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
static void gimp_floating_sel_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum);
|
2007-01-31 21:05:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpFloatingSelUndo, gimp_floating_sel_undo, GIMP_TYPE_ITEM_UNDO)
|
|
|
|
|
|
|
|
#define parent_class gimp_floating_sel_undo_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_floating_sel_undo_class_init (GimpFloatingSelUndoClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
|
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
object_class->constructed = gimp_floating_sel_undo_constructed;
|
2007-01-31 21:05:43 +00:00
|
|
|
|
|
|
|
undo_class->pop = gimp_floating_sel_undo_pop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_floating_sel_undo_init (GimpFloatingSelUndo *undo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
static void
|
|
|
|
gimp_floating_sel_undo_constructed (GObject *object)
|
2007-01-31 21:05:43 +00:00
|
|
|
{
|
2011-01-12 22:53:58 +01:00
|
|
|
GimpFloatingSelUndo *floating_sel_undo = GIMP_FLOATING_SEL_UNDO (object);
|
2007-02-03 21:58:12 +00:00
|
|
|
GimpLayer *layer;
|
2007-01-31 21:05:43 +00:00
|
|
|
|
2011-01-12 22:53:58 +01:00
|
|
|
if (G_OBJECT_CLASS (parent_class)->constructed)
|
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2007-02-03 21:58:12 +00:00
|
|
|
|
2007-01-31 21:05:43 +00:00
|
|
|
g_assert (GIMP_IS_LAYER (GIMP_ITEM_UNDO (object)->item));
|
|
|
|
|
2007-02-03 21:58:12 +00:00
|
|
|
layer = GIMP_LAYER (GIMP_ITEM_UNDO (object)->item);
|
|
|
|
|
|
|
|
switch (GIMP_UNDO (object)->undo_type)
|
|
|
|
{
|
|
|
|
case GIMP_UNDO_FS_TO_LAYER:
|
2009-01-26 22:47:16 +00:00
|
|
|
floating_sel_undo->drawable = gimp_layer_get_floating_sel_drawable (layer);
|
2007-02-03 21:58:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2007-01-31 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_floating_sel_undo_pop (GimpUndo *undo,
|
|
|
|
GimpUndoMode undo_mode,
|
|
|
|
GimpUndoAccumulator *accum)
|
|
|
|
{
|
|
|
|
GimpFloatingSelUndo *floating_sel_undo = GIMP_FLOATING_SEL_UNDO (undo);
|
|
|
|
GimpLayer *floating_layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
|
|
|
|
|
|
|
|
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
|
|
|
|
|
2007-02-03 21:58:12 +00:00
|
|
|
switch (undo->undo_type)
|
2007-01-31 21:05:43 +00:00
|
|
|
{
|
2007-02-03 21:58:12 +00:00
|
|
|
case GIMP_UNDO_FS_TO_LAYER:
|
|
|
|
if (undo_mode == GIMP_UNDO_MODE_UNDO)
|
|
|
|
{
|
|
|
|
/* Update the preview for the floating sel */
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (floating_layer));
|
|
|
|
|
2008-11-17 00:02:15 +00:00
|
|
|
gimp_layer_set_floating_sel_drawable (floating_layer,
|
|
|
|
floating_sel_undo->drawable);
|
2007-02-03 21:58:12 +00:00
|
|
|
gimp_image_set_active_layer (undo->image, floating_layer);
|
|
|
|
|
2009-01-26 22:47:16 +00:00
|
|
|
gimp_drawable_attach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer),
|
2009-01-26 22:05:07 +00:00
|
|
|
floating_layer);
|
2007-02-03 21:58:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-23 19:31:50 +02:00
|
|
|
gimp_drawable_detach_floating_sel (gimp_layer_get_floating_sel_drawable (floating_layer));
|
2008-11-17 00:02:15 +00:00
|
|
|
gimp_layer_set_floating_sel_drawable (floating_layer, NULL);
|
2007-02-03 21:58:12 +00:00
|
|
|
}
|
|
|
|
|
2009-08-29 12:11:28 +02:00
|
|
|
/* When the floating selection is converted to/from a normal
|
2009-08-29 12:13:28 +02:00
|
|
|
* layer it does something resembling a name change, so emit the
|
2009-08-29 12:11:28 +02:00
|
|
|
* "name-changed" signal
|
|
|
|
*/
|
2007-02-03 21:58:12 +00:00
|
|
|
gimp_object_name_changed (GIMP_OBJECT (floating_layer));
|
|
|
|
|
|
|
|
gimp_drawable_update (GIMP_DRAWABLE (floating_layer),
|
|
|
|
0, 0,
|
2008-11-03 00:09:01 +00:00
|
|
|
gimp_item_get_width (GIMP_ITEM (floating_layer)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (floating_layer)));
|
2007-02-03 21:58:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2007-01-31 21:05:43 +00:00
|
|
|
}
|
2007-02-03 21:58:12 +00:00
|
|
|
}
|