text: Clean up button press handling

Event handling should only apply to editable ClutterText actors, but we
also have the :selectable property to care about.

The button/touch press should position the cursor inside an editable
ClutterText; the :selectable property should be used to allow selecting
the text, either through pointer or touch dragging, via the keyboard, or
by multiple pointer clicks. If neither of these two conditions are met,
the ClutterText should just propagate the event handling further.
This commit is contained in:
Emmanuele Bassi 2012-08-17 19:52:56 +01:00
parent aeb7c6926b
commit e9bcb4cf6e

View File

@ -1814,12 +1814,14 @@ clutter_text_press (ClutterActor *actor,
gfloat x, y; gfloat x, y;
gint index_; gint index_;
/* we'll steal keyfocus if we need it */ /* if a ClutterText is just used for display purposes, then we
if (priv->editable || priv->selectable) * should ignore the events we receive
clutter_actor_grab_key_focus (actor); */
else if (!priv->editable)
return CLUTTER_EVENT_PROPAGATE; return CLUTTER_EVENT_PROPAGATE;
clutter_actor_grab_key_focus (actor);
/* if the actor is empty we just reset everything and not /* if the actor is empty we just reset everything and not
* set up the dragging of the selection since there's nothing * set up the dragging of the selection since there's nothing
* to select * to select
@ -1836,15 +1838,15 @@ clutter_text_press (ClutterActor *actor,
res = clutter_actor_transform_stage_point (actor, x, y, &x, &y); res = clutter_actor_transform_stage_point (actor, x, y, &x, &y);
if (res) if (res)
{ {
gint offset;
const char *text; const char *text;
int offset;
index_ = clutter_text_coords_to_position (self, x, y); index_ = clutter_text_coords_to_position (self, x, y);
text = clutter_text_buffer_get_text (get_buffer (self)); text = clutter_text_buffer_get_text (get_buffer (self));
offset = bytes_to_offset (text, index_); offset = bytes_to_offset (text, index_);
/* what we select depends on the number of button clicks we /* what we select depends on the number of button clicks we
* receive: * receive, and whether we are selectable:
* *
* 1: just position the cursor and the selection * 1: just position the cursor and the selection
* 2: select the current word * 2: select the current word
@ -1858,18 +1860,25 @@ clutter_text_press (ClutterActor *actor,
{ {
clutter_text_set_positions (self, offset, offset); clutter_text_set_positions (self, offset, offset);
} }
else if (click_count == 2) else if (priv->selectable && click_count == 2)
{ {
clutter_text_select_word (self); clutter_text_select_word (self);
} }
else if (click_count == 3) else if (priv->selectable && click_count == 3)
{ {
clutter_text_select_line (self); clutter_text_select_line (self);
} }
} }
else else
{
/* touch events do not have click count */
clutter_text_set_positions (self, offset, offset); clutter_text_set_positions (self, offset, offset);
} }
}
/* we don't need to go any further if we're not selectable */
if (!priv->selectable)
return CLUTTER_EVENT_STOP;
/* grab the pointer */ /* grab the pointer */
priv->in_select_drag = TRUE; priv->in_select_drag = TRUE;