some general indentation, spacing and coding style convention paranoia

2007-10-31  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimprectangletool.c: some general indentation, spacing
	and coding style convention paranoia cleanups.

	(gimp_rectangle_tool_get_constraints): set all return values also
	when bailing out early to avoid valgrind warnings about
	uninitialized memory.


svn path=/trunk/; revision=24009
This commit is contained in:
Michael Natterer 2007-10-31 10:36:03 +00:00 committed by Michael Natterer
parent 5a8f89999c
commit ba62d2b9d3
2 changed files with 128 additions and 139 deletions

View File

@ -1,3 +1,12 @@
2007-10-31 Michael Natterer <mitch@gimp.org>
* app/tools/gimprectangletool.c: some general indentation, spacing
and coding style convention paranoia cleanups.
(gimp_rectangle_tool_get_constraints): set all return values also
when bailing out early to avoid valgrind warnings about
uninitialized memory.
2007-10-31 Sven Neumann <sven@gimp.org> 2007-10-31 Sven Neumann <sven@gimp.org>
* configure.in: check for the XFIXES extension. * configure.in: check for the XFIXES extension.

View File

@ -474,7 +474,7 @@ gimp_rectangle_tool_get_press_coords (GimpRectangleTool *rectangle,
} }
/** /**
* gimp_rectangle_tool_pending_size_set_option: * gimp_rectangle_tool_pending_size_set:
* @width_property: Option property to set to pending rectangle width. * @width_property: Option property to set to pending rectangle width.
* @height_property: Option property to set to pending rectangle height. * @height_property: Option property to set to pending rectangle height.
* *
@ -502,7 +502,7 @@ gimp_rectangle_tool_pending_size_set (GimpRectangleTool *rectangle_tool,
} }
/** /**
* gimp_rectangle_tool_constraint_size_set_option: * gimp_rectangle_tool_constraint_size_set:
* @width_property: Option property to set to current constraint width. * @width_property: Option property to set to current constraint width.
* @height_property: Option property to set to current constraint height. * @height_property: Option property to set to current constraint height.
* *
@ -515,17 +515,19 @@ gimp_rectangle_tool_constraint_size_set (GimpRectangleTool *rectangle_tool,
const gchar *width_property, const gchar *width_property,
const gchar *height_property) const gchar *height_property)
{ {
GimpContext *gimp_context;
GimpImage *image;
GimpTool *tool; GimpTool *tool;
GimpContext *context;
GimpImage *image;
gdouble width; gdouble width;
gdouble height; gdouble height;
tool = GIMP_TOOL (rectangle_tool); g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (rectangle_tool));
gimp_context = gimp_get_user_context (tool->tool_info->gimp);
image = gimp_context_get_image (gimp_context);
if (image == NULL) tool = GIMP_TOOL (rectangle_tool);
context = gimp_get_user_context (tool->tool_info->gimp);
image = gimp_context_get_image (context);
if (! image)
{ {
width = 1.0; width = 1.0;
height = 1.0; height = 1.0;
@ -542,7 +544,7 @@ gimp_rectangle_tool_constraint_size_set (GimpRectangleTool *rectangle_tool,
{ {
GimpItem *item = GIMP_ITEM (gimp_image_get_active_layer (image)); GimpItem *item = GIMP_ITEM (gimp_image_get_active_layer (image));
if (item == NULL) if (! item)
{ {
width = 1.0; width = 1.0;
height = 1.0; height = 1.0;
@ -599,6 +601,7 @@ gimp_rectangle_tool_set_property (GObject *object,
case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT: case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT:
gimp_rectangle_tool_set_constraint (rectangle, g_value_get_enum (value)); gimp_rectangle_tool_set_constraint (rectangle, g_value_get_enum (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -633,6 +636,7 @@ gimp_rectangle_tool_get_property (GObject *object,
case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT: case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT:
g_value_set_enum (value, gimp_rectangle_tool_get_constraint (rectangle)); g_value_set_enum (value, gimp_rectangle_tool_get_constraint (rectangle));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -964,7 +968,6 @@ gimp_rectangle_tool_button_release (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
} }
void void
gimp_rectangle_tool_motion (GimpTool *tool, gimp_rectangle_tool_motion (GimpTool *tool,
GimpCoords *coords, GimpCoords *coords,
@ -1100,7 +1103,6 @@ gimp_rectangle_tool_motion (GimpTool *tool,
} }
void void
gimp_rectangle_tool_active_modifier_key (GimpTool *tool, gimp_rectangle_tool_active_modifier_key (GimpTool *tool,
GdkModifierType key, GdkModifierType key,
gboolean press, gboolean press,
@ -1209,7 +1211,8 @@ gimp_rectangle_tool_active_modifier_key (GimpTool *tool,
gimp_rectangle_tool_update_options (rectangle, tool->display); gimp_rectangle_tool_update_options (rectangle, tool->display);
} }
static void swap_ints (gint *i, static void
swap_ints (gint *i,
gint *j) gint *j)
{ {
gint tmp; gint tmp;
@ -1680,13 +1683,10 @@ gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
static void static void
gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool) gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool)
{ {
GimpTool *tool; GimpTool *tool = GIMP_TOOL (draw_tool);
GimpRectangleToolPrivate *private; GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
gint x1, x2, y1, y2; gint x1, x2, y1, y2;
tool = GIMP_TOOL (draw_tool);
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (draw_tool);
x1 = private->x1; x1 = private->x1;
x2 = private->x2; x2 = private->x2;
y1 = private->y1; y1 = private->y1;
@ -1753,17 +1753,13 @@ static void
gimp_rectangle_tool_update_handle_sizes (GimpRectangleTool *rectangle) gimp_rectangle_tool_update_handle_sizes (GimpRectangleTool *rectangle)
{ {
GimpTool *tool = GIMP_TOOL (rectangle); GimpTool *tool = GIMP_TOOL (rectangle);
GimpRectangleToolPrivate *private; GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
GimpRectangleOptions *options;
GimpDisplayShell *shell; GimpDisplayShell *shell;
gint visible_rectangle_width; gint visible_rectangle_width;
gint visible_rectangle_height; gint visible_rectangle_height;
gint rectangle_width; gint rectangle_width;
gint rectangle_height; gint rectangle_height;
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
if (! tool->display) if (! tool->display)
return; return;
@ -1847,7 +1843,7 @@ gimp_rectangle_tool_scale_has_changed (GimpRectangleTool *rectangle_tool)
GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool); GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
GimpDisplayShell *shell; GimpDisplayShell *shell;
if (tool->display == NULL) if (! tool->display)
return TRUE; return TRUE;
shell = GIMP_DISPLAY_SHELL (tool->display->shell); shell = GIMP_DISPLAY_SHELL (tool->display->shell);
@ -2114,13 +2110,12 @@ gimp_rectangle_tool_options_notify (GimpRectangleOptions *options,
GParamSpec *pspec, GParamSpec *pspec,
GimpRectangleTool *rectangle) GimpRectangleTool *rectangle)
{ {
GimpRectangleToolPrivate *private; GimpTool *tool = GIMP_TOOL (rectangle);
GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
GimpRectangleOptionsPrivate *options_private; GimpRectangleOptionsPrivate *options_private;
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options); options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
if (! strcmp (pspec->name, "guide")) if (! strcmp (pspec->name, "guide"))
{ {
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rectangle)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (rectangle));
@ -2132,7 +2127,7 @@ gimp_rectangle_tool_options_notify (GimpRectangleOptions *options,
return; return;
} }
if (! GIMP_TOOL (rectangle)->display) if (! tool->display)
return; return;
if (! strcmp (pspec->name, "x")) if (! strcmp (pspec->name, "x"))
@ -2207,7 +2202,6 @@ gimp_rectangle_tool_options_notify (GimpRectangleOptions *options,
* it's enough to only check e.g. for width. * it's enough to only check e.g. for width.
*/ */
GimpTool *tool = GIMP_TOOL (rectangle);
gint width = private->x2 - private->x1; gint width = private->x2 - private->x1;
gint height = private->y2 - private->y1; gint height = private->y2 - private->y1;
@ -2245,7 +2239,6 @@ gimp_rectangle_tool_options_notify (GimpRectangleOptions *options,
* swaps, so it's enough to only check e.g. for numerator. * swaps, so it's enough to only check e.g. for numerator.
*/ */
GimpTool *tool = GIMP_TOOL (rectangle);
double width = private->x2 - private->x1; double width = private->x2 - private->x1;
double height = private->y2 - private->y1; double height = private->y2 - private->y1;
gdouble new_inverse_ratio = options_private->aspect_denominator / gdouble new_inverse_ratio = options_private->aspect_denominator /
@ -2352,7 +2345,7 @@ static void
gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rectangle) gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rectangle)
{ {
GimpTool *tool = GIMP_TOOL (rectangle); GimpTool *tool = GIMP_TOOL (rectangle);
GimpRectangleToolPrivate *private; GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
GimpDisplay *display = tool->display; GimpDisplay *display = tool->display;
gint width; gint width;
gint height; gint height;
@ -2366,8 +2359,6 @@ gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rectangle)
gint shrunk_y2; gint shrunk_y2;
gboolean shrink_merged; gboolean shrink_merged;
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
if (! display) if (! display)
return; return;
@ -2442,10 +2433,10 @@ gimp_rectangle_tool_coord_on_handle (GimpRectangleTool *rectangle_tool,
GimpCoords *coords, GimpCoords *coords,
GtkAnchorType anchor) GtkAnchorType anchor)
{ {
GimpRectangleToolPrivate *private; GimpTool *tool = GIMP_TOOL (rectangle_tool);
GimpTool *tool; GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpDisplayShell *shell; GimpDisplayShell *shell;
GimpDrawTool *draw_tool;
gint w; gint w;
gint h; gint h;
gint tw; gint tw;
@ -2455,10 +2446,7 @@ gimp_rectangle_tool_coord_on_handle (GimpRectangleTool *rectangle_tool,
gint handle_width = 0; gint handle_width = 0;
gint handle_height = 0; gint handle_height = 0;
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
tool = GIMP_TOOL (rectangle_tool);
shell = GIMP_DISPLAY_SHELL (tool->display->shell); shell = GIMP_DISPLAY_SHELL (tool->display->shell);
draw_tool = GIMP_DRAW_TOOL (rectangle_tool);
w = private->x2 - private->x1; w = private->x2 - private->x1;
h = private->y2 - private->y1; h = private->y2 - private->y1;
tw = w * shell->scale_x; tw = w * shell->scale_x;
@ -2576,17 +2564,14 @@ gimp_rectangle_tool_get_anchor (GimpRectangleToolPrivate *private)
static void static void
gimp_rectangle_tool_update_highlight (GimpRectangleTool *rectangle) gimp_rectangle_tool_update_highlight (GimpRectangleTool *rectangle)
{ {
GimpTool *tool; GimpTool *tool = GIMP_TOOL (rectangle);
GimpRectangleOptions *options; GimpRectangleOptions *options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
GimpDisplayShell *shell; GimpDisplayShell *shell;
gboolean highlight = FALSE; gboolean highlight = FALSE;
tool = GIMP_TOOL (rectangle); if (! tool->display)
if (tool->display == NULL)
return; return;
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
shell = GIMP_DISPLAY_SHELL (tool->display->shell); shell = GIMP_DISPLAY_SHELL (tool->display->shell);
g_object_get (options, "highlight", &highlight, NULL); g_object_get (options, "highlight", &highlight, NULL);
@ -2629,7 +2614,7 @@ gimp_rectangle_tool_get_other_side (GimpRectangleTool *rectangle_tool,
{ {
GimpRectangleToolPrivate *private; GimpRectangleToolPrivate *private;
private = gimp_rectangle_tool_get_private (GIMP_RECTANGLE_TOOL (rectangle_tool)); private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
switch (private->function) switch (private->function)
{ {
@ -2682,7 +2667,7 @@ gimp_rectangle_tool_get_other_side_coord (GimpRectangleTool *rectangle_tool,
const gchar *other_x = NULL; const gchar *other_x = NULL;
const gchar *other_y = NULL; const gchar *other_y = NULL;
gimp_rectangle_tool_get_other_side (GIMP_RECTANGLE_TOOL (rectangle_tool), gimp_rectangle_tool_get_other_side (rectangle_tool,
&other_x, &other_x,
&other_y); &other_y);
if (other_x) if (other_x)
@ -2703,7 +2688,7 @@ gimp_rectangle_tool_set_other_side_coord (GimpRectangleTool *rectangle_tool,
const gchar *other_x = NULL; const gchar *other_x = NULL;
const gchar *other_y = NULL; const gchar *other_y = NULL;
gimp_rectangle_tool_get_other_side (GIMP_RECTANGLE_TOOL (rectangle_tool), gimp_rectangle_tool_get_other_side (rectangle_tool,
&other_x, &other_x,
&other_y); &other_y);
if (other_x) if (other_x)
@ -2882,7 +2867,7 @@ gimp_rectangle_tool_clamp_width (GimpRectangleTool *rectangle_tool,
if (private->x2 < min_x) if (private->x2 < min_x)
private->x2 = min_x; private->x2 = min_x;
if (clamped_sides != NULL) if (clamped_sides)
*clamped_sides |= CLAMPED_LEFT; *clamped_sides |= CLAMPED_LEFT;
} }
@ -2898,7 +2883,7 @@ gimp_rectangle_tool_clamp_width (GimpRectangleTool *rectangle_tool,
if (private->x1 > max_x) if (private->x1 > max_x)
private->x1 = max_x; private->x1 = max_x;
if (clamped_sides != NULL) if (clamped_sides)
*clamped_sides |= CLAMPED_RIGHT; *clamped_sides |= CLAMPED_RIGHT;
} }
} }
@ -2951,7 +2936,7 @@ gimp_rectangle_tool_clamp_height (GimpRectangleTool *rectangle_tool,
if (private->y2 < min_y) if (private->y2 < min_y)
private->y2 = min_y; private->y2 = min_y;
if (clamped_sides != NULL) if (clamped_sides)
*clamped_sides |= CLAMPED_TOP; *clamped_sides |= CLAMPED_TOP;
} }
@ -2967,7 +2952,7 @@ gimp_rectangle_tool_clamp_height (GimpRectangleTool *rectangle_tool,
if (private->y1 > max_y) if (private->y1 > max_y)
private->y1 = max_y; private->y1 = max_y;
if (clamped_sides != NULL) if (clamped_sides)
*clamped_sides |= CLAMPED_BOTTOM; *clamped_sides |= CLAMPED_BOTTOM;
} }
} }
@ -3007,6 +2992,8 @@ gimp_rectangle_tool_keep_inside_horizontally (GimpRectangleTool *rectangle_
gint min_x; gint min_x;
gint max_x; gint max_x;
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE) if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
return; return;
@ -3017,8 +3004,6 @@ gimp_rectangle_tool_keep_inside_horizontally (GimpRectangleTool *rectangle_
NULL, NULL,
constraint); constraint);
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
if (max_x - min_x < private->x2 - private->x1) if (max_x - min_x < private->x2 - private->x1)
{ {
private->x1 = min_x; private->x1 = min_x;
@ -3060,6 +3045,8 @@ gimp_rectangle_tool_keep_inside_vertically (GimpRectangleTool *rectangle_to
gint min_y; gint min_y;
gint max_y; gint max_y;
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE) if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
return; return;
@ -3070,8 +3057,6 @@ gimp_rectangle_tool_keep_inside_vertically (GimpRectangleTool *rectangle_to
&max_y, &max_y,
constraint); constraint);
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
if (max_y - min_y < private->y2 - private->y1) if (max_y - min_y < private->y2 - private->y1)
{ {
private->y1 = min_y; private->y1 = min_y;
@ -3253,9 +3238,7 @@ gimp_rectangle_tool_apply_aspect (GimpRectangleTool *rectangle_tool,
/* Do we have to do anything? */ /* Do we have to do anything? */
if (current_aspect == aspect) if (current_aspect == aspect)
{
return; return;
}
if (options_private->fixed_center) if (options_private->fixed_center)
{ {
@ -3523,15 +3506,12 @@ gimp_rectangle_tool_update_with_coord (GimpRectangleTool *rectangle_tool,
gint new_x, gint new_x,
gint new_y) gint new_y)
{ {
GimpTool *tool; GimpTool *tool = GIMP_TOOL (rectangle_tool);
GimpRectangleToolPrivate *private; GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
GimpRectangleOptions *options; GimpRectangleOptions *options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
GimpRectangleOptionsPrivate *options_private; GimpRectangleOptionsPrivate *options_private;
GimpRectangleConstraint constraint_to_use; GimpRectangleConstraint constraint_to_use;
tool = GIMP_TOOL (rectangle_tool);
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle_tool);
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rectangle_tool);
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options); options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
/* Move the corner or edge the user currently has grabbed. */ /* Move the corner or edge the user currently has grabbed. */
@ -3584,10 +3564,10 @@ gimp_rectangle_tool_update_with_coord (GimpRectangleTool *rectangle_tool,
aspect, aspect,
clamped_sides); clamped_sides);
/* After we have applied aspect, we might have taken the rectangle /* After we have applied aspect, we might have taken the
* outside of constraint, so clamp and apply aspect again. We will get * rectangle outside of constraint, so clamp and apply
* the right result this time, since 'clamped_sides' will be setup * aspect again. We will get the right result this time,
* correctly now. * since 'clamped_sides' will be setup correctly now.
*/ */
gimp_rectangle_tool_clamp (rectangle_tool, gimp_rectangle_tool_clamp (rectangle_tool,
&clamped_sides, &clamped_sides,
@ -3604,8 +3584,8 @@ gimp_rectangle_tool_update_with_coord (GimpRectangleTool *rectangle_tool,
aspect, aspect,
CLAMPED_NONE); CLAMPED_NONE);
/* When fixed ratio is used, we always want the rectangle inside the /* When fixed ratio is used, we always want the
* canvas. * rectangle inside the canvas.
*/ */
gimp_rectangle_tool_keep_inside (rectangle_tool, gimp_rectangle_tool_keep_inside (rectangle_tool,
constraint_to_use); constraint_to_use);
@ -3657,24 +3637,23 @@ gimp_rectangle_tool_get_constraints (GimpRectangleTool *rectangle_tool,
gint *max_y, gint *max_y,
GimpRectangleConstraint constraint) GimpRectangleConstraint constraint)
{ {
GimpTool *tool; GimpTool *tool = GIMP_TOOL (rectangle_tool);
gint min_x_dummy; gint min_x_dummy;
gint min_y_dummy; gint min_y_dummy;
gint max_x_dummy; gint max_x_dummy;
gint max_y_dummy; gint max_y_dummy;
if (min_x == NULL) if (! min_x) min_x = &min_x_dummy;
min_x = &min_x_dummy; if (! min_y) min_y = &min_y_dummy;
if (min_y == NULL) if (! max_x) max_x = &max_x_dummy;
min_y = &min_y_dummy; if (! max_y) max_y = &max_y_dummy;
if (max_x == NULL)
max_x = &max_x_dummy;
if (max_y == NULL)
max_y = &max_y_dummy;
tool = GIMP_TOOL (rectangle_tool); *min_x = 0;
*min_y = 0;
*max_x = 0;
*max_y = 0;
if (tool->display == NULL) if (! tool->display)
return; return;
switch (constraint) switch (constraint)
@ -3724,8 +3703,9 @@ gimp_rectangle_tool_handle_general_clamping (GimpRectangleTool *rectangle_tool)
constraint = gimp_rectangle_tool_get_constraint (rectangle_tool); constraint = gimp_rectangle_tool_get_constraint (rectangle_tool);
/* fixed_aspect takes care of clamping by it self, so just return in case that /* fixed_aspect takes care of clamping by it self, so just return in
* is in use. Also return if no constraints should be enforced. * case that is in use. Also return if no constraints should be
* enforced.
*/ */
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE) if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
return; return;