app: make gimp_selection_tool_start_edit() much easier to use correctly

- Add a "display" parameter and ignore tool->display
- Require the tool to be inactive, not active when calling it

This exactly matches all its use cases, which is "delegate to
GimpEditSelection tool if we are not doing anything ourselves", and
enables removing all delegate_button_press() functions because they
became one-liners after adapting to this change.
This commit is contained in:
Michael Natterer 2011-06-03 09:46:10 +02:00
parent 52cd1b9043
commit d27b7a985c
5 changed files with 38 additions and 102 deletions

View File

@ -515,32 +515,6 @@ gimp_free_select_tool_is_point_grabbed (GimpFreeSelectTool *fst)
return priv->grabbed_segment_index != INVALID_INDEX;
}
static void
gimp_free_select_tool_start (GimpFreeSelectTool *fst,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpTool *tool = GIMP_TOOL (fst);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (fst);
GimpFreeSelectToolPrivate *priv = GET_PRIVATE (fst);
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
gimp_tool_control_activate (tool->control);
tool->display = display;
gimp_draw_tool_start (draw_tool, display);
/* We want to apply the selection operation that was current when
* the tool was started, so we save this information */
priv->operation_at_start = options->operation;
gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fst),
coords);
}
static void
gimp_free_select_tool_fit_segment (GimpFreeSelectTool *fst,
GimpVector2 *dest_points,
@ -963,36 +937,6 @@ gimp_free_select_tool_prepare_for_move (GimpFreeSelectTool *fst)
}
}
static gboolean
gimp_free_select_tool_delegate_button_press (GimpFreeSelectTool *fst,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpTool *tool = GIMP_TOOL (fst);
gboolean button_press_delegated = FALSE;
/* Only consider delegating if the tool is not active */
if (tool->display == NULL)
{
tool->display = display;
gimp_tool_control_activate (tool->control);
button_press_delegated =
gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fst), coords);
if (! button_press_delegated)
{
/* Nope, the selection mask edit stuff was not interested, reset
* the situation
*/
gimp_tool_control_halt (tool->control);
tool->display = NULL;
}
}
return button_press_delegated;
}
static void
gimp_free_select_tool_update_motion (GimpFreeSelectTool *fst,
gdouble new_x,
@ -1259,28 +1203,36 @@ gimp_free_select_tool_button_press (GimpTool *tool,
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
GimpFreeSelectTool *fst = GIMP_FREE_SELECT_TOOL (tool);
GimpFreeSelectToolPrivate *priv = GET_PRIVATE (fst);
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
/* First of all handle delegation to the selection mask edit logic
* if appropriate
*/
if (gimp_free_select_tool_delegate_button_press (fst,
coords,
display))
if (tool->display && tool->display != display)
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
if (tool->display == NULL)
{
return;
/* First of all handle delegation to the selection mask edit logic
* if appropriate.
*/
if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (fst),
display, coords))
{
return;
}
tool->display = display;
gimp_draw_tool_start (draw_tool, display);
/* We want to apply the selection operation that was current when
* the tool was started, so we save this information
*/
priv->operation_at_start = options->operation;
}
gimp_tool_control_activate (tool->control);
gimp_draw_tool_pause (draw_tool);
if (display != tool->display)
{
gimp_free_select_tool_start (fst,
coords,
display);
}
if (gimp_free_select_tool_is_point_grabbed (fst))
{
gimp_free_select_tool_prepare_for_move (fst);

View File

@ -343,27 +343,6 @@ gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool)
gimp_rectangle_tool_draw (draw_tool, stroke_group);
}
static gboolean
gimp_rectangle_select_tool_delegate_button_press (GimpRectangleSelectTool *rect_sel_tool,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpTool *tool = GIMP_TOOL (rect_sel_tool);
gboolean button_press_delegated = FALSE;
GimpDisplay *old_display = tool->display;
tool->display = display;
gimp_tool_control_activate (tool->control);
button_press_delegated =
gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (tool), coords);
gimp_tool_control_halt (tool->control);
tool->display = old_display;
return button_press_delegated;
}
static void
gimp_rectangle_select_tool_button_press (GimpTool *tool,
const GimpCoords *coords,
@ -388,9 +367,8 @@ gimp_rectangle_select_tool_button_press (GimpTool *tool,
gimp_rectangle_tool_cancel (GIMP_RECTANGLE_TOOL (tool));
}
if (gimp_rectangle_select_tool_delegate_button_press (rect_sel_tool,
coords,
display))
if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (tool),
display, coords))
{
/* In some cases we want to finish the rectangle select tool
* and hand over responsability to the selection tool

View File

@ -152,12 +152,15 @@ gimp_region_select_tool_button_press (GimpTool *tool,
region_sel->y = coords->y;
region_sel->saved_threshold = options->threshold;
if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (region_sel),
display, coords))
{
return;
}
gimp_tool_control_activate (tool->control);
tool->display = display;
if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (region_sel), coords))
return;
gimp_tool_push_status (tool, display,
_("Move the mouse to change threshold"));

View File

@ -391,32 +391,34 @@ gimp_selection_tool_cursor_update (GimpTool *tool,
gboolean
gimp_selection_tool_start_edit (GimpSelectionTool *sel_tool,
GimpDisplay *display,
const GimpCoords *coords)
{
GimpTool *tool;
g_return_val_if_fail (GIMP_IS_SELECTION_TOOL (sel_tool), FALSE);
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
g_return_val_if_fail (coords != NULL, FALSE);
tool = GIMP_TOOL (sel_tool);
g_return_val_if_fail (GIMP_IS_DISPLAY (tool->display), FALSE);
g_return_val_if_fail (gimp_tool_control_is_active (tool->control), FALSE);
g_return_val_if_fail (gimp_tool_control_is_active (tool->control) == FALSE,
FALSE);
switch (sel_tool->function)
{
case SELECTION_MOVE_MASK:
gimp_edit_selection_tool_start (tool, tool->display, coords,
gimp_edit_selection_tool_start (tool, display, coords,
GIMP_TRANSLATE_MODE_MASK, FALSE);
return TRUE;
case SELECTION_MOVE:
gimp_edit_selection_tool_start (tool, tool->display, coords,
gimp_edit_selection_tool_start (tool, display, coords,
GIMP_TRANSLATE_MODE_MASK_TO_LAYER, FALSE);
return TRUE;
case SELECTION_MOVE_COPY:
gimp_edit_selection_tool_start (tool, tool->display, coords,
gimp_edit_selection_tool_start (tool, display, coords,
GIMP_TRANSLATE_MODE_MASK_COPY_TO_LAYER,
FALSE);
return TRUE;

View File

@ -55,6 +55,7 @@ GType gimp_selection_tool_get_type (void) G_GNUC_CONST;
/* protected function */
gboolean gimp_selection_tool_start_edit (GimpSelectionTool *sel_tool,
GimpDisplay *display,
const GimpCoords *coords);