From e9bcb4cf6ead0f7066de2e2eb14a4a5ad5f04a05 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 17 Aug 2012 19:52:56 +0100 Subject: [PATCH] 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. --- clutter/clutter-text.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index cb9cf4a0a..74b3d4d67 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -1814,12 +1814,14 @@ clutter_text_press (ClutterActor *actor, gfloat x, y; gint index_; - /* we'll steal keyfocus if we need it */ - if (priv->editable || priv->selectable) - clutter_actor_grab_key_focus (actor); - else + /* if a ClutterText is just used for display purposes, then we + * should ignore the events we receive + */ + if (!priv->editable) return CLUTTER_EVENT_PROPAGATE; + clutter_actor_grab_key_focus (actor); + /* if the actor is empty we just reset everything and not * set up the dragging of the selection since there's nothing * to select @@ -1836,15 +1838,15 @@ clutter_text_press (ClutterActor *actor, res = clutter_actor_transform_stage_point (actor, x, y, &x, &y); if (res) { - gint offset; const char *text; + int offset; index_ = clutter_text_coords_to_position (self, x, y); text = clutter_text_buffer_get_text (get_buffer (self)); offset = bytes_to_offset (text, index_); /* 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 * 2: select the current word @@ -1858,19 +1860,26 @@ clutter_text_press (ClutterActor *actor, { clutter_text_set_positions (self, offset, offset); } - else if (click_count == 2) + else if (priv->selectable && click_count == 2) { clutter_text_select_word (self); } - else if (click_count == 3) + else if (priv->selectable && click_count == 3) { clutter_text_select_line (self); } } else - clutter_text_set_positions (self, offset, offset); + { + /* touch events do not have click count */ + 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 */ priv->in_select_drag = TRUE;