From ec6600a0b3dab3ccd3e99fb1096031e375e72a07 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 20 Aug 2009 17:05:23 +0200 Subject: [PATCH] Refuse to edit locked drawables Check whether the drawable to edit is locked in GimpTool::initialize() and bail out with an appropriate error if it is. This currently prevents cloning from locked drawables, will fix that later. --- app/tools/gimpblendtool.c | 7 +++++++ app/tools/gimpbrightnesscontrasttool.c | 4 +--- app/tools/gimpbucketfilltool.c | 27 +++++++++++++++++++++++++ app/tools/gimpcolorbalancetool.c | 4 +--- app/tools/gimpcolorizetool.c | 5 ++++- app/tools/gimpcurvestool.c | 5 ++++- app/tools/gimpdesaturatetool.c | 5 ++++- app/tools/gimpgegltool.c | 4 +--- app/tools/gimphuesaturationtool.c | 4 +--- app/tools/gimpimagemaptool.c | 12 +++++++++-- app/tools/gimplevelstool.c | 5 ++++- app/tools/gimppainttool.c | 28 ++++++++++++++++++++++++++ app/tools/gimpperspectiveclonetool.c | 5 +++++ app/tools/gimpposterizetool.c | 5 ++++- app/tools/gimpthresholdtool.c | 5 ++++- app/tools/gimptransformtool.c | 18 ++++++++++++++++- 16 files changed, 122 insertions(+), 21 deletions(-) diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c index e41d9193d5..6643f0ebdc 100644 --- a/app/tools/gimpblendtool.c +++ b/app/tools/gimpblendtool.c @@ -167,6 +167,13 @@ gimp_blend_tool_initialize (GimpTool *tool, return FALSE; } + if (gimp_item_get_lock_content (GIMP_ITEM (drawable))) + { + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("The active layer's pixels are locked.")); + return FALSE; + } + return TRUE; } diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c index a2424ed59a..c10421f551 100644 --- a/app/tools/gimpbrightnesscontrasttool.c +++ b/app/tools/gimpbrightnesscontrasttool.c @@ -188,9 +188,7 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (bc_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); - - return TRUE; + return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); } static GeglNode * diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c index e93d8154df..2af8f8d288 100644 --- a/app/tools/gimpbucketfilltool.c +++ b/app/tools/gimpbucketfilltool.c @@ -26,6 +26,7 @@ #include "core/gimp.h" #include "core/gimpdrawable-bucket-fill.h" +#include "core/gimperror.h" #include "core/gimpimage.h" #include "core/gimpitem.h" #include "core/gimppickable.h" @@ -43,6 +44,9 @@ /* local function prototypes */ +static gboolean gimp_bucket_fill_tool_initialize (GimpTool *tool, + GimpDisplay *display, + GError **error); static void gimp_bucket_fill_tool_button_release (GimpTool *tool, const GimpCoords *coords, guint32 time, @@ -91,6 +95,7 @@ gimp_bucket_fill_tool_class_init (GimpBucketFillToolClass *klass) { GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass); + tool_class->initialize = gimp_bucket_fill_tool_initialize; tool_class->button_release = gimp_bucket_fill_tool_button_release; tool_class->modifier_key = gimp_bucket_fill_tool_modifier_key; tool_class->cursor_update = gimp_bucket_fill_tool_cursor_update; @@ -111,6 +116,28 @@ gimp_bucket_fill_tool_init (GimpBucketFillTool *bucket_fill_tool) "context/context-pattern-select-set"); } +static gboolean +gimp_bucket_fill_tool_initialize (GimpTool *tool, + GimpDisplay *display, + GError **error) +{ + GimpDrawable *drawable = gimp_image_get_active_drawable (display->image); + + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } + + if (gimp_item_get_lock_content (GIMP_ITEM (drawable))) + { + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("The active layer's pixels are locked.")); + return FALSE; + } + + return TRUE; +} + static void gimp_bucket_fill_tool_button_release (GimpTool *tool, const GimpCoords *coords, diff --git a/app/tools/gimpcolorbalancetool.c b/app/tools/gimpcolorbalancetool.c index 32820598cd..07ab627779 100644 --- a/app/tools/gimpcolorbalancetool.c +++ b/app/tools/gimpcolorbalancetool.c @@ -166,9 +166,7 @@ gimp_color_balance_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (cb_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); - - return TRUE; + return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); } static GeglNode * diff --git a/app/tools/gimpcolorizetool.c b/app/tools/gimpcolorizetool.c index 0ac50105b0..c797d62a95 100644 --- a/app/tools/gimpcolorizetool.c +++ b/app/tools/gimpcolorizetool.c @@ -159,7 +159,10 @@ gimp_colorize_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (col_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool)); diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c index d17bff4c30..87e3d8a4e6 100644 --- a/app/tools/gimpcurvestool.c +++ b/app/tools/gimpcurvestool.c @@ -224,7 +224,10 @@ gimp_curves_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (c_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } /* always pick colors */ gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), diff --git a/app/tools/gimpdesaturatetool.c b/app/tools/gimpdesaturatetool.c index 2c65b10568..e1add99b94 100644 --- a/app/tools/gimpdesaturatetool.c +++ b/app/tools/gimpdesaturatetool.c @@ -128,7 +128,10 @@ gimp_desaturate_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (desaturate_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (desaturate_tool->button), desaturate_tool->config->mode); diff --git a/app/tools/gimpgegltool.c b/app/tools/gimpgegltool.c index 3c1e91e67c..b63507f09c 100644 --- a/app/tools/gimpgegltool.c +++ b/app/tools/gimpgegltool.c @@ -162,9 +162,7 @@ gimp_gegl_tool_initialize (GimpTool *tool, if (g_tool->config) gimp_config_reset (GIMP_CONFIG (g_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); - - return TRUE; + return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); } static GeglNode * diff --git a/app/tools/gimphuesaturationtool.c b/app/tools/gimphuesaturationtool.c index 066b46789d..b27bc8cae6 100644 --- a/app/tools/gimphuesaturationtool.c +++ b/app/tools/gimphuesaturationtool.c @@ -174,9 +174,7 @@ gimp_hue_saturation_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (hs_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); - - return TRUE; + return GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); } static GeglNode * diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c index cfcb9ce3b7..32c35c462e 100644 --- a/app/tools/gimpimagemaptool.c +++ b/app/tools/gimpimagemaptool.c @@ -33,6 +33,7 @@ #include "core/gimp.h" #include "core/gimpdrawable.h" +#include "core/gimperror.h" #include "core/gimpimage.h" #include "core/gimpimage-pick-color.h" #include "core/gimpimagemap.h" @@ -266,6 +267,15 @@ gimp_image_map_tool_initialize (GimpTool *tool, GimpToolInfo *tool_info = tool->tool_info; GimpDrawable *drawable; + drawable = gimp_image_get_active_drawable (display->image); + + if (gimp_item_get_lock_content (GIMP_ITEM (drawable))) + { + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("The active layer's pixels are locked.")); + return FALSE; + } + /* set display so the dialog can be hidden on display destruction */ tool->display = display; @@ -334,8 +344,6 @@ gimp_image_map_tool_initialize (GimpTool *tool, image_map_tool, 0); } - drawable = gimp_image_get_active_drawable (display->image); - gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (image_map_tool->shell), GIMP_VIEWABLE (drawable), GIMP_CONTEXT (tool_info->tool_options)); diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c index a7428387f6..4ee84d80f2 100644 --- a/app/tools/gimplevelstool.c +++ b/app/tools/gimplevelstool.c @@ -235,7 +235,10 @@ gimp_levels_tool_initialize (GimpTool *tool, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l_tool->active_picker), FALSE); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (l_tool->channel_menu), levels_menu_sensitivity, drawable, NULL); diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c index 3458ed3bce..34ad4fdd40 100644 --- a/app/tools/gimppainttool.c +++ b/app/tools/gimppainttool.c @@ -27,6 +27,7 @@ #include "core/gimp.h" #include "core/gimp-utils.h" #include "core/gimpdrawable.h" +#include "core/gimperror.h" #include "core/gimpimage.h" #include "core/gimppaintinfo.h" #include "core/gimpprojection.h" @@ -58,6 +59,9 @@ static GObject * gimp_paint_tool_constructor (GType type, GObjectConstructParam *params); static void gimp_paint_tool_finalize (GObject *object); +static gboolean gimp_paint_tool_initialize (GimpTool *tool, + GimpDisplay *display, + GError **error); static void gimp_paint_tool_control (GimpTool *tool, GimpToolAction action, GimpDisplay *display); @@ -111,6 +115,7 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass) object_class->constructor = gimp_paint_tool_constructor; object_class->finalize = gimp_paint_tool_finalize; + tool_class->initialize = gimp_paint_tool_initialize; tool_class->control = gimp_paint_tool_control; tool_class->button_press = gimp_paint_tool_button_press; tool_class->button_release = gimp_paint_tool_button_release; @@ -216,6 +221,29 @@ gimp_paint_tool_enable_color_picker (GimpPaintTool *tool, GIMP_COLOR_TOOL (tool)->pick_mode = mode; } +static gboolean +gimp_paint_tool_initialize (GimpTool *tool, + GimpDisplay *display, + GError **error) +{ + GimpDrawable *drawable = gimp_image_get_active_drawable (display->image); + + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } + + if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) && + gimp_item_get_lock_content (GIMP_ITEM (drawable))) + { + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("The active layer's pixels are locked.")); + return FALSE; + } + + return TRUE; +} + static void gimp_paint_tool_control (GimpTool *tool, GimpToolAction action, diff --git a/app/tools/gimpperspectiveclonetool.c b/app/tools/gimpperspectiveclonetool.c index 51338bf436..1235459cef 100644 --- a/app/tools/gimpperspectiveclonetool.c +++ b/app/tools/gimpperspectiveclonetool.c @@ -216,6 +216,11 @@ gimp_perspective_clone_tool_initialize (GimpTool *tool, { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } + if (display != tool->display) { gint i; diff --git a/app/tools/gimpposterizetool.c b/app/tools/gimpposterizetool.c index 8a504cc218..f75f6fcc2b 100644 --- a/app/tools/gimpposterizetool.c +++ b/app/tools/gimpposterizetool.c @@ -154,7 +154,10 @@ gimp_posterize_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (posterize_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } gtk_adjustment_set_value (posterize_tool->levels_data, posterize_tool->config->levels); diff --git a/app/tools/gimpthresholdtool.c b/app/tools/gimpthresholdtool.c index 64044aa31f..ba781aab89 100644 --- a/app/tools/gimpthresholdtool.c +++ b/app/tools/gimpthresholdtool.c @@ -164,7 +164,10 @@ gimp_threshold_tool_initialize (GimpTool *tool, gimp_config_reset (GIMP_CONFIG (t_tool->config)); - GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error); + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } gimp_drawable_calculate_histogram (drawable, t_tool->histogram); gimp_histogram_view_set_histogram (t_tool->histogram_box->view, diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c index 2a8adfce9c..5afe407bc1 100644 --- a/app/tools/gimptransformtool.c +++ b/app/tools/gimptransformtool.c @@ -35,6 +35,7 @@ #include "core/gimp.h" #include "core/gimpcontext.h" #include "core/gimpdrawable-transform.h" +#include "core/gimperror.h" #include "core/gimpimage.h" #include "core/gimpimage-undo.h" #include "core/gimpimage-undo-push.h" @@ -333,6 +334,21 @@ gimp_transform_tool_initialize (GimpTool *tool, GError **error) { GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool); + GimpDrawable *drawable; + + drawable = gimp_image_get_active_drawable (display->image); + + if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) + { + return FALSE; + } + + if (gimp_item_get_lock_content (GIMP_ITEM (drawable))) + { + g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, + _("The active layer's pixels are locked.")); + return FALSE; + } if (display != tool->display) { @@ -340,7 +356,7 @@ gimp_transform_tool_initialize (GimpTool *tool, /* Set the pointer to the active display */ tool->display = display; - tool->drawable = gimp_image_get_active_drawable (display->image); + tool->drawable = drawable; /* Initialize the transform tool dialog */ if (! tr_tool->dialog)