Commit 1b1299af authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added GError** parameter to GimpPaintCore::start().

2006-09-26  Michael Natterer  <mitch@gimp.org>

	* app/paint/gimppaintcore.[ch]: added GError** parameter to
	GimpPaintCore::start().

	* app/tools/gimppainttool.c (button_press): display the error in
	the statusbar.

	* app/paint/gimppaintcore-stroke.c: pass a NULL error, effectively
	swallowing mssages. Will fix that later.

	* app/paint/gimpbrushcore.c
	* app/paint/gimpclone.c
	* app/paint/gimpsourcecore.c: changed accordingly. Set the error
	instead of calling g_message().

	* app/paint/gimpheal.c
	* app/paint/gimpperspectiveclone.c: implement start() and bail out
	early on indexed drawables instead of showing a g_message() in
	other functions that are called later.

	* app/tools/gimptool.[ch]: added GError** to GimpTool::initialize().

	* app/tools/gimptool.c (gimp_tool_initialize): display the error
	in the statusbar. Keep the external API GError-free.

	* app/tools/gimprectangletool.[ch]: added GError** to
	gimp_rectangle_tool_initialize().

	* app/tools/gimpbrightnesscontrasttool.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcolorizetool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpcurvestool.c
	* app/tools/gimphuesaturationtool.c
	* app/tools/gimpimagemaptool.c
	* app/tools/gimplevelstool.c
	* app/tools/gimpperspectiveclonetool.c
	* app/tools/gimpposterizetool.c
	* app/tools/gimpthresholdtool.c
	* app/tools/gimptransformtool.c: changed accordingly. Set the
	errors in initialize() instead of using gimp_message().

	* app/tools/gimpblendtool.c: implement initialize() and bail out
	early on indexed images instead of showing a gimp_message() in
	button_press().
parent c598fe65
2006-09-26 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore.[ch]: added GError** parameter to
GimpPaintCore::start().
* app/tools/gimppainttool.c (button_press): display the error in
the statusbar.
* app/paint/gimppaintcore-stroke.c: pass a NULL error, effectively
swallowing mssages. Will fix that later.
* app/paint/gimpbrushcore.c
* app/paint/gimpclone.c
* app/paint/gimpsourcecore.c: changed accordingly. Set the error
instead of calling g_message().
* app/paint/gimpheal.c
* app/paint/gimpperspectiveclone.c: implement start() and bail out
early on indexed drawables instead of showing a g_message() in
other functions that are called later.
* app/tools/gimptool.[ch]: added GError** to GimpTool::initialize().
* app/tools/gimptool.c (gimp_tool_initialize): display the error
in the statusbar. Keep the external API GError-free.
* app/tools/gimprectangletool.[ch]: added GError** to
gimp_rectangle_tool_initialize().
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcolorizetool.c
* app/tools/gimpcroptool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimpimagemaptool.c
* app/tools/gimplevelstool.c
* app/tools/gimpperspectiveclonetool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c
* app/tools/gimptransformtool.c: changed accordingly. Set the
errors in initialize() instead of using gimp_message().
* app/tools/gimpblendtool.c: implement initialize() and bail out
early on indexed images instead of showing a gimp_message() in
button_press().
2006-09-26 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore.c: added some missing g_return_if_fail()
......
......@@ -57,7 +57,8 @@ static void gimp_brush_core_finalize (GObject *object);
static gboolean gimp_brush_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
GimpCoords *coords,
GError **error);
static gboolean gimp_brush_core_pre_paint (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
......@@ -320,10 +321,11 @@ gimp_brush_core_post_paint (GimpPaintCore *paint_core,
}
static gboolean
gimp_brush_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
gimp_brush_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error)
{
GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
GimpBrush *brush;
......@@ -335,7 +337,8 @@ gimp_brush_core_start (GimpPaintCore *paint_core,
if (! core->main_brush)
{
g_message (_("No brushes available for use with this tool."));
g_set_error (error, 0, 0,
_("No brushes available for use with this tool."));
return FALSE;
}
......
......@@ -48,7 +48,8 @@
static gboolean gimp_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
GimpCoords *coords,
GError **error);
static void gimp_clone_motion (GimpSourceCore *source_core,
GimpDrawable *drawable,
......@@ -117,15 +118,17 @@ gimp_clone_init (GimpClone *clone)
}
static gboolean
gimp_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
gimp_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error)
{
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
paint_options, coords))
paint_options, coords,
error))
{
return FALSE;
}
......@@ -134,7 +137,8 @@ gimp_clone_start (GimpPaintCore *paint_core,
{
if (! gimp_context_get_pattern (GIMP_CONTEXT (options)))
{
g_message (_("No patterns available for this operation."));
g_set_error (error, 0, 0,
_("No patterns available for this operation."));
return FALSE;
}
}
......
......@@ -49,19 +49,25 @@
*/
static void gimp_heal_motion (GimpSourceCore *source_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
gdouble opacity,
GimpPickable *src_pickable,
PixelRegion *srcPR,
gint src_offset_x,
gint src_offset_y,
TempBuf *paint_area,
gint paint_area_offset_x,
gint paint_area_offset_y,
gint paint_area_width,
gint paint_area_height);
static gboolean gimp_heal_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error);
static void gimp_heal_motion (GimpSourceCore *source_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
gdouble opacity,
GimpPickable *src_pickable,
PixelRegion *srcPR,
gint src_offset_x,
gint src_offset_y,
TempBuf *paint_area,
gint paint_area_offset_x,
gint paint_area_offset_y,
gint paint_area_width,
gint paint_area_height);
G_DEFINE_TYPE (GimpHeal, gimp_heal, GIMP_TYPE_SOURCE_CORE)
......@@ -84,8 +90,11 @@ gimp_heal_register (Gimp *gimp,
static void
gimp_heal_class_init (GimpHealClass *klass)
{
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
GimpSourceCoreClass *source_core_class = GIMP_SOURCE_CORE_CLASS (klass);
paint_core_class->start = gimp_heal_start;
source_core_class->motion = gimp_heal_motion;
}
......@@ -94,6 +103,32 @@ gimp_heal_init (GimpHeal *heal)
{
}
static gboolean
gimp_heal_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error)
{
GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core);
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
paint_options, coords,
error))
{
return FALSE;
}
if (! source_core->set_source && gimp_drawable_is_indexed (drawable))
{
g_set_error (error, 0, 0,
_("Indexed images are not currently supported."));
return FALSE;
}
return TRUE;
}
/*
* Substitute any zeros in the input PixelRegion for ones. This is needed by
* the algorithm to avoid division by zero, and to get a more realistic image
......@@ -365,12 +400,6 @@ gimp_heal_motion (GimpSourceCore *source_core,
PixelRegion destPR;
GimpImageType src_type;
if (gimp_drawable_is_indexed (drawable))
{
g_message (_("Indexed images are not currently supported."));
return;
}
src_type = gimp_pickable_get_image_type (src_pickable);
/* we need the source area with alpha and we modify it, so make a copy */
......
......@@ -51,7 +51,7 @@ gimp_paint_core_stroke (GimpPaintCore *core,
g_return_val_if_fail (strokes != NULL, FALSE);
g_return_val_if_fail (n_strokes > 0, FALSE);
if (gimp_paint_core_start (core, drawable, paint_options, &strokes[0]))
if (gimp_paint_core_start (core, drawable, paint_options, &strokes[0], NULL))
{
gint i;
......@@ -156,7 +156,8 @@ gimp_paint_core_stroke_boundary (GimpPaintCore *core,
n_coords++;
if (initialized ||
gimp_paint_core_start (core, drawable, paint_options, &coords[0]))
gimp_paint_core_start (core, drawable, paint_options, &coords[0],
NULL))
{
gint i;
......@@ -247,7 +248,8 @@ gimp_paint_core_stroke_vectors (GimpPaintCore *core,
if (initialized ||
gimp_paint_core_start (core, drawable, paint_options,
&g_array_index (coords, GimpCoords, 0)))
&g_array_index (coords, GimpCoords, 0),
NULL))
{
initialized = TRUE;
......
......@@ -68,7 +68,8 @@ static void gimp_paint_core_get_property (GObject *object,
static gboolean gimp_paint_core_real_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
GimpCoords *coords,
GError **error);
static gboolean gimp_paint_core_real_pre_paint (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *options,
......@@ -216,7 +217,8 @@ static gboolean
gimp_paint_core_real_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
GimpCoords *coords,
GError **error)
{
return TRUE;
}
......@@ -307,10 +309,11 @@ gimp_paint_core_paint (GimpPaintCore *core,
}
gboolean
gimp_paint_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
gimp_paint_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error)
{
GimpItem *item;
......@@ -319,6 +322,7 @@ gimp_paint_core_start (GimpPaintCore *core,
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
g_return_val_if_fail (coords != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
item = GIMP_ITEM (drawable);
......@@ -326,7 +330,7 @@ gimp_paint_core_start (GimpPaintCore *core,
if (! GIMP_PAINT_CORE_GET_CLASS (core)->start (core, drawable,
paint_options,
coords))
coords, error))
{
return FALSE;
}
......
......@@ -74,7 +74,8 @@ struct _GimpPaintCoreClass
gboolean (* start) (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
GimpCoords *coords,
GError **error);
gboolean (* pre_paint) (GimpPaintCore *core,
GimpDrawable *drawable,
......@@ -118,7 +119,8 @@ void gimp_paint_core_paint (GimpPaintCore *core,
gboolean gimp_paint_core_start (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
GimpCoords *coords,
GError **error);
void gimp_paint_core_finish (GimpPaintCore *core,
GimpDrawable *drawable);
void gimp_paint_core_cancel (GimpPaintCore *core,
......
......@@ -53,6 +53,11 @@
static void gimp_perspective_clone_finalize (GObject *object);
static gboolean gimp_perspective_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error);
static void gimp_perspective_clone_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
......@@ -100,6 +105,7 @@ gimp_perspective_clone_class_init (GimpPerspectiveCloneClass *klass)
object_class->finalize = gimp_perspective_clone_finalize;
paint_core_class->start = gimp_perspective_clone_start;
paint_core_class->paint = gimp_perspective_clone_paint;
source_core_class->get_source = gimp_perspective_clone_get_source;
......@@ -135,6 +141,32 @@ gimp_perspective_clone_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
gimp_perspective_clone_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error)
{
GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core);
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
paint_options, coords,
error))
{
return FALSE;
}
if (! source_core->set_source && gimp_drawable_is_indexed (drawable))
{
g_set_error (error, 0, 0,
_("Indexed images are not currently supported."));
return FALSE;
}
return TRUE;
}
static void
gimp_perspective_clone_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
......@@ -272,12 +304,6 @@ gimp_perspective_clone_get_source (GimpSourceCore *source_core,
gint i, j;
TempBuf *orig;
if (gimp_drawable_is_indexed (drawable))
{
g_message (_("Indexed images are not currently supported."));
return FALSE;
}
src_image = gimp_pickable_get_image (src_pickable);
image = gimp_item_get_image (GIMP_ITEM (drawable));
......
......@@ -60,7 +60,8 @@ static void gimp_source_core_get_property (GObject *object,
static gboolean gimp_source_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords);
GimpCoords *coords,
GError **error);
static void gimp_source_core_paint (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
......@@ -201,16 +202,18 @@ gimp_source_core_get_property (GObject *object,
}
static gboolean
gimp_source_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords)
gimp_source_core_start (GimpPaintCore *paint_core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *coords,
GError **error)
{
GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core);
GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options);
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
paint_options, coords))
paint_options, coords,
error))
{
return FALSE;
}
......@@ -220,7 +223,10 @@ gimp_source_core_start (GimpPaintCore *paint_core,
if (! source_core->set_source && options->use_source)
{
if (! source_core->src_drawable)
return FALSE;
{
g_set_error (error, 0, 0, _("Set a source image first."));
return FALSE;
}
if (options->sample_merged &&
gimp_item_get_image (GIMP_ITEM (source_core->src_drawable)) ==
......
......@@ -51,6 +51,9 @@
/* local function prototypes */
static gboolean gimp_blend_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error);
static void gimp_blend_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
......@@ -114,6 +117,7 @@ gimp_blend_tool_class_init (GimpBlendToolClass *klass)
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
tool_class->initialize = gimp_blend_tool_initialize;
tool_class->button_press = gimp_blend_tool_button_press;
tool_class->button_release = gimp_blend_tool_button_release;
tool_class->motion = gimp_blend_tool_motion;
......@@ -139,6 +143,28 @@ gimp_blend_tool_init (GimpBlendTool *blend_tool)
"context/context-gradient-select-set");
}
static gboolean
gimp_blend_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpDrawable *drawable = gimp_image_active_drawable (display->image);
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
{
return FALSE;
}
if (gimp_drawable_is_indexed (drawable))
{
g_set_error (error, 0, 0,
_("Blend: Invalid for indexed images."));
return FALSE;
}
return TRUE;
}
static void
gimp_blend_tool_button_press (GimpTool *tool,
GimpCoords *coords,
......@@ -152,19 +178,6 @@ gimp_blend_tool_button_press (GimpTool *tool,
drawable = gimp_image_active_drawable (display->image);
switch (gimp_drawable_type (drawable))
{
case GIMP_INDEXED_IMAGE:
case GIMP_INDEXEDA_IMAGE:
gimp_message (display->image->gimp, GIMP_PROGRESS (display),
_("Blend: Invalid for indexed images."));
return;
break;
default:
break;
}
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
blend_tool->mousex = coords->x - off_x;
......
......@@ -27,12 +27,10 @@
#include "base/gimplut.h"
#include "base/lut-funcs.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimpprogress.h"
#include "widgets/gimphelp-ids.h"
......@@ -55,7 +53,8 @@
static void gimp_brightness_contrast_tool_finalize (GObject *object);
static gboolean gimp_brightness_contrast_tool_initialize (GimpTool *tool,
GimpDisplay *display);
GimpDisplay *display,
GError **error);
static void gimp_brightness_contrast_tool_button_press (GimpTool *tool,
GimpCoords *coords,
......@@ -150,8 +149,9 @@ gimp_brightness_contrast_tool_finalize (GObject *object)
}
static gboolean
gimp_brightness_contrast_tool_initialize (GimpTool *tool,
GimpDisplay *display)
gimp_brightness_contrast_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (tool);
GimpDrawable *drawable;
......@@ -163,15 +163,15 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool,
if (gimp_drawable_is_indexed (drawable))
{
gimp_message (display->image->gimp, GIMP_PROGRESS (display),
_("Brightness-Contrast does not operate on indexed layers."));
g_set_error (error, 0, 0,
_("Brightness-Contrast does not operate on indexed layers."));
return FALSE;
}
bc_tool->brightness = 0.0;
bc_tool->contrast = 0.0;
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display);
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
brightness_contrast_update (bc_tool, ALL);
......
......@@ -28,11 +28,9 @@
#include "base/color-balance.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimpprogress.h"
#include "widgets/gimphelp-ids.h"
......@@ -56,7 +54,8 @@
static void gimp_color_balance_tool_finalize (GObject *object);
static gboolean gimp_color_balance_tool_initialize (GimpTool *tool,
GimpDisplay *display);
GimpDisplay *display,
GError **error);
static void gimp_color_balance_tool_map (GimpImageMapTool *im_tool);
static void gimp_color_balance_tool_dialog (GimpImageMapTool *im_tool);
......@@ -142,8 +141,9 @@ gimp_color_balance_tool_finalize (GObject *object)
}
static gboolean
gimp_color_balance_tool_initialize (GimpTool *tool,
GimpDisplay *display)
gimp_color_balance_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (tool);
GimpDrawable *drawable;
......@@ -155,8 +155,8 @@ gimp_color_balance_tool_initialize (GimpTool *tool,
if (! gimp_drawable_is_rgb (drawable))
{
gimp_message (display->image->gimp, GIMP_PROGRESS (display),
_("Color balance operates only on RGB color layers."));
g_set_error (error, 0, 0,
_("Color balance operates only on RGB color layers."));
return FALSE;
}
......@@ -164,7 +164,7 @@ gimp_color_balance_tool_initialize (GimpTool *tool,
cb_tool->transfer_mode = GIMP_MIDTONES;
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display);
GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error);
color_balance_update (cb_tool, ALL);
......
......@@ -28,11 +28,9 @@
#include "base/colorize.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimpprogress.h"
#include "widgets/gimphelp-ids.h"
......@@ -61,7 +59,8 @@
static void gimp_colorize_tool_finalize (GObject *object);
static gboolean gimp_colorize_tool_initialize (GimpTool *tool,
GimpDisplay *display);
GimpDisplay *display,
GError **error);
static void gimp_colorize_tool_map (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_dialog (GimpImageMapTool *im_tool);
......@@ -139,8 +138,9 @@ gimp_colorize_tool_finalize (GObject *object)
}
static gboolean
gimp_colorize_tool_initialize (GimpTool *tool,
GimpDisplay *display)
gimp_colorize_tool_initialize (GimpTool *tool,
GimpDisplay *display,
GError **error)
{
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (tool);
GimpDrawable *drawable;
......@@ -152,14 +152,14 @@ gimp_colorize_tool_initialize (GimpTool *tool,
if (! gimp_drawable_is_rgb (drawable))
{
gimp_message (display->image->gimp, GIMP_PROGRESS (display),
_("Colorize operates only on RGB color layers."));
g_set_error (error, 0, 0,