2011-10-12 17:13:41 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpitem-exclusive.c
|
|
|
|
* Copyright (C) 2011 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 3 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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2011-10-12 17:13:41 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2011-10-12 17:13:41 +08:00
|
|
|
#include <gegl.h>
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "gimpcontext.h"
|
2021-02-12 01:08:19 +08:00
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpimage.h"
|
2011-10-12 17:13:41 +08:00
|
|
|
#include "gimpimage-undo.h"
|
|
|
|
#include "gimpimage-undo-push.h"
|
|
|
|
#include "gimpitem.h"
|
|
|
|
#include "gimpitem-exclusive.h"
|
|
|
|
#include "gimpitemstack.h"
|
|
|
|
#include "gimpitemtree.h"
|
|
|
|
#include "gimpundostack.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2021-02-11 23:17:36 +08:00
|
|
|
static GList * gimp_item_exclusive_get_ancestry (GimpItem *item);
|
|
|
|
static void gimp_item_exclusive_get_lists (GimpItem *item,
|
|
|
|
GimpItemIsEnabledFunc is_enabled,
|
|
|
|
GimpItemCanSetFunc can_set,
|
|
|
|
GimpItemIsPropLocked is_prop_locked,
|
2021-02-12 01:08:19 +08:00
|
|
|
gboolean only_selected,
|
2021-02-11 23:17:36 +08:00
|
|
|
GList **on,
|
|
|
|
GList **off);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_item_toggle_exclusive_visible (GimpItem *item,
|
2021-02-12 01:08:19 +08:00
|
|
|
gboolean only_selected,
|
2011-10-12 17:13:41 +08:00
|
|
|
GimpContext *context)
|
|
|
|
{
|
2021-02-11 23:17:36 +08:00
|
|
|
gimp_item_toggle_exclusive (item,
|
|
|
|
(GimpItemIsEnabledFunc) gimp_item_is_visible,
|
|
|
|
(GimpItemSetFunc) gimp_item_set_visible,
|
|
|
|
NULL,
|
2022-02-16 04:08:07 +08:00
|
|
|
(GimpItemIsPropLocked) gimp_item_get_lock_visibility,
|
2021-02-11 23:17:36 +08:00
|
|
|
(GimpItemUndoPush) gimp_image_undo_push_item_visibility,
|
|
|
|
_("Set Item Exclusive Visibility"),
|
|
|
|
GIMP_UNDO_GROUP_ITEM_VISIBILITY,
|
2021-02-12 01:08:19 +08:00
|
|
|
only_selected, context);
|
2021-02-11 23:17:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_item_toggle_exclusive (GimpItem *item,
|
|
|
|
GimpItemIsEnabledFunc is_enabled,
|
|
|
|
GimpItemSetFunc set_prop,
|
|
|
|
GimpItemCanSetFunc can_set,
|
|
|
|
GimpItemIsPropLocked is_prop_locked,
|
|
|
|
GimpItemUndoPush undo_push,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
GimpUndoType group_undo_type,
|
2021-02-12 01:08:19 +08:00
|
|
|
gboolean only_selected,
|
2021-02-11 23:17:36 +08:00
|
|
|
GimpContext *context)
|
|
|
|
{
|
2022-02-16 04:08:07 +08:00
|
|
|
GList *ancestry;
|
|
|
|
GList *on;
|
|
|
|
GList *off;
|
|
|
|
GList *list;
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_ITEM (item));
|
|
|
|
g_return_if_fail (gimp_item_is_attached (item));
|
2021-02-11 23:17:36 +08:00
|
|
|
g_return_if_fail (undo_desc != NULL);
|
|
|
|
g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
|
2011-10-12 17:13:41 +08:00
|
|
|
|
2011-11-17 05:38:39 +08:00
|
|
|
ancestry = gimp_item_exclusive_get_ancestry (item);
|
2021-02-12 01:08:19 +08:00
|
|
|
gimp_item_exclusive_get_lists (item, is_enabled, can_set, is_prop_locked,
|
|
|
|
only_selected, &on, &off);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
2021-02-11 23:17:36 +08:00
|
|
|
if (on || off || (! is_enabled (item) && (can_set == NULL || can_set (item))))
|
2011-10-12 17:13:41 +08:00
|
|
|
{
|
|
|
|
GimpImage *image = gimp_item_get_image (item);
|
|
|
|
GimpUndo *undo;
|
2011-11-17 05:38:39 +08:00
|
|
|
gboolean push_undo = TRUE;
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_UNDO_STACK,
|
2021-02-11 23:17:36 +08:00
|
|
|
group_undo_type);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
2021-02-11 23:17:36 +08:00
|
|
|
/* Use the undo description as the undo object key, as we should
|
|
|
|
* assume that a same undo description means the same exclusive
|
|
|
|
* action.
|
|
|
|
*/
|
|
|
|
if (undo && (g_object_get_data (G_OBJECT (undo), undo_desc) ==
|
2011-10-12 17:13:41 +08:00
|
|
|
(gpointer) item))
|
|
|
|
push_undo = FALSE;
|
|
|
|
|
|
|
|
if (push_undo)
|
|
|
|
{
|
|
|
|
if (gimp_image_undo_group_start (image,
|
2021-02-11 23:17:36 +08:00
|
|
|
group_undo_type,
|
|
|
|
undo_desc))
|
2011-10-12 17:13:41 +08:00
|
|
|
{
|
|
|
|
undo = gimp_image_undo_can_compress (image, GIMP_TYPE_UNDO_STACK,
|
2021-02-11 23:17:36 +08:00
|
|
|
group_undo_type);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
if (undo)
|
2021-02-11 23:17:36 +08:00
|
|
|
g_object_set_data (G_OBJECT (undo), undo_desc, (gpointer) item);
|
2011-10-12 17:13:41 +08:00
|
|
|
}
|
|
|
|
|
2011-11-17 05:38:39 +08:00
|
|
|
for (list = ancestry; list; list = g_list_next (list))
|
2021-02-11 23:17:36 +08:00
|
|
|
undo_push (image, NULL, list->data);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
for (list = on; list; list = g_list_next (list))
|
2021-02-11 23:17:36 +08:00
|
|
|
undo_push (image, NULL, list->data);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
for (list = off; list; list = g_list_next (list))
|
2021-02-11 23:17:36 +08:00
|
|
|
undo_push (image, NULL, list->data);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
gimp_image_undo_group_end (image);
|
|
|
|
}
|
2021-02-11 23:17:36 +08:00
|
|
|
else if (context)
|
2011-10-12 17:13:41 +08:00
|
|
|
{
|
|
|
|
gimp_undo_refresh_preview (undo, context);
|
|
|
|
}
|
|
|
|
|
2011-11-17 05:38:39 +08:00
|
|
|
for (list = ancestry; list; list = g_list_next (list))
|
2021-02-11 23:17:36 +08:00
|
|
|
set_prop (list->data, TRUE, FALSE);
|
2011-10-12 17:13:41 +08:00
|
|
|
|
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
for (list = on; list; list = g_list_next (list))
|
2021-02-11 23:17:36 +08:00
|
|
|
set_prop (list->data, FALSE, FALSE);
|
2011-10-12 17:13:41 +08:00
|
|
|
}
|
|
|
|
else if (off)
|
|
|
|
{
|
|
|
|
for (list = off; list; list = g_list_next (list))
|
2021-02-11 23:17:36 +08:00
|
|
|
set_prop (list->data, TRUE, FALSE);
|
2011-10-12 17:13:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (on);
|
|
|
|
g_list_free (off);
|
|
|
|
}
|
2012-02-07 21:06:12 +08:00
|
|
|
|
|
|
|
g_list_free (ancestry);
|
2011-10-12 17:13:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2011-11-17 05:38:39 +08:00
|
|
|
static GList *
|
|
|
|
gimp_item_exclusive_get_ancestry (GimpItem *item)
|
|
|
|
{
|
|
|
|
GimpViewable *parent;
|
|
|
|
GList *ancestry = NULL;
|
|
|
|
|
|
|
|
for (parent = GIMP_VIEWABLE (item);
|
|
|
|
parent;
|
|
|
|
parent = gimp_viewable_get_parent (parent))
|
|
|
|
{
|
|
|
|
ancestry = g_list_prepend (ancestry, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ancestry;
|
|
|
|
}
|
|
|
|
|
2011-10-12 17:13:41 +08:00
|
|
|
static void
|
2021-02-11 23:17:36 +08:00
|
|
|
gimp_item_exclusive_get_lists (GimpItem *item,
|
|
|
|
GimpItemIsEnabledFunc is_enabled,
|
|
|
|
GimpItemCanSetFunc can_set,
|
|
|
|
GimpItemIsPropLocked is_prop_locked,
|
2021-02-12 01:08:19 +08:00
|
|
|
gboolean only_selected,
|
2021-02-11 23:17:36 +08:00
|
|
|
GList **on,
|
|
|
|
GList **off)
|
2011-10-12 17:13:41 +08:00
|
|
|
{
|
2021-02-12 01:08:19 +08:00
|
|
|
GimpImage *image = NULL;
|
2011-10-12 17:13:41 +08:00
|
|
|
GimpItemTree *tree;
|
|
|
|
GList *items;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
*on = NULL;
|
|
|
|
*off = NULL;
|
|
|
|
|
|
|
|
tree = gimp_item_get_tree (item);
|
|
|
|
|
|
|
|
items = gimp_item_stack_get_item_list (GIMP_ITEM_STACK (tree->container));
|
|
|
|
|
2021-02-12 01:08:19 +08:00
|
|
|
if (only_selected)
|
|
|
|
image = gimp_item_get_image (item);
|
|
|
|
|
2011-10-12 17:13:41 +08:00
|
|
|
for (list = items; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpItem *other = list->data;
|
|
|
|
|
2021-02-12 01:08:19 +08:00
|
|
|
if (other != item &&
|
2017-12-24 06:57:12 +08:00
|
|
|
/* Don't include item with visibility locks. */
|
2021-02-12 01:08:19 +08:00
|
|
|
(is_prop_locked == NULL || ! is_prop_locked (other)) &&
|
2021-02-11 23:17:36 +08:00
|
|
|
/* Don't include item which can be changed. */
|
2021-02-12 01:08:19 +08:00
|
|
|
(can_set == NULL || can_set (other)) &&
|
|
|
|
/* Do we care only about selected drawables? */
|
|
|
|
(! only_selected || gimp_image_is_selected_drawable (image,
|
|
|
|
GIMP_DRAWABLE (other))) &&
|
2022-02-16 04:28:10 +08:00
|
|
|
/* We are only interested in same level items unless
|
|
|
|
* @only_selected is TRUE. */
|
|
|
|
(only_selected ||
|
|
|
|
gimp_viewable_get_parent (GIMP_VIEWABLE (other)) ==
|
|
|
|
gimp_viewable_get_parent (GIMP_VIEWABLE (item))))
|
2011-10-12 17:13:41 +08:00
|
|
|
{
|
2021-02-11 23:17:36 +08:00
|
|
|
if (is_enabled (other))
|
2017-12-24 06:57:12 +08:00
|
|
|
*on = g_list_prepend (*on, other);
|
|
|
|
else
|
|
|
|
*off = g_list_prepend (*off, other);
|
2011-10-12 17:13:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (items);
|
|
|
|
}
|