diff options
author | Jan Arne Petersen <jpetersen@openismus.com> | 2013-01-16 21:26:47 +0100 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2013-02-15 17:00:54 -0500 |
commit | 3489ba9c21d16a1545663b3d0d64b8f10a2a3c17 (patch) | |
tree | f15c7e36335a113674b8bce2f438fc299b39be44 /clients/editor.c | |
parent | adfedc19655bb9677084a47c630aff9e38edbd1f (diff) | |
download | weston-3489ba9c21d16a1545663b3d0d64b8f10a2a3c17.tar.gz |
editor: add support for invoke_action
Call invoke_action request when a currently composed word is clicked.
Signed-off-by: Jan Arne Petersen <jpetersen@openismus.com>
Diffstat (limited to 'clients/editor.c')
-rw-r--r-- | clients/editor.c | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/clients/editor.c b/clients/editor.c index 90ee4cd2..462c4003 100644 --- a/clients/editor.c +++ b/clients/editor.c @@ -633,6 +633,36 @@ text_entry_set_preedit(struct text_entry *entry, widget_schedule_redraw(entry->widget); } +static uint32_t +text_entry_try_invoke_preedit_action(struct text_entry *entry, + int32_t x, int32_t y, + uint32_t button, + enum wl_pointer_button_state state) +{ + int index, trailing; + uint32_t cursor; + + if (!entry->preedit.text) + return 0; + + pango_layout_xy_to_index(entry->layout, + x * PANGO_SCALE, y * PANGO_SCALE, + &index, &trailing); + cursor = index + trailing; + + if (cursor < entry->cursor || + cursor > entry->cursor + strlen(entry->preedit.text)) { + return 0; + } + + if (state == WL_POINTER_BUTTON_STATE_RELEASED) + text_model_invoke_action(entry->model, + button, + cursor - entry->cursor); + + return 1; +} + static void text_entry_set_cursor_position(struct text_entry *entry, int32_t x, int32_t y) @@ -650,11 +680,6 @@ text_entry_set_cursor_position(struct text_entry *entry, text_model_reset(entry->model, entry->serial); - if (entry->preedit.cursor > 0 && - entry->cursor >= (uint32_t)entry->preedit.cursor) { - entry->cursor -= entry->preedit.cursor; - } - text_entry_update_layout(entry); widget_schedule_redraw(entry->widget); @@ -817,19 +842,26 @@ text_entry_button_handler(struct widget *widget, struct rectangle allocation; struct editor *editor; int32_t x, y; + uint32_t result; widget_get_allocation(entry->widget, &allocation); input_get_position(input, &x, &y); + x -= allocation.x + text_offset_left; + y -= allocation.y + text_offset_left; + editor = window_get_user_data(entry->window); + result = text_entry_try_invoke_preedit_action(entry, x, y, button, state); + + if (result) + return; + if (button != BTN_LEFT) { return; } - text_entry_set_cursor_position(entry, - x - allocation.x - text_offset_left, - y - allocation.y - text_offset_left); + text_entry_set_cursor_position(entry, x, y); if (state == WL_POINTER_BUTTON_STATE_PRESSED) { struct wl_seat *seat = input_get_seat(input); @@ -837,9 +869,7 @@ text_entry_button_handler(struct widget *widget, text_entry_activate(entry, seat); editor->active_entry = entry; - text_entry_set_anchor_position(entry, - x - allocation.x - text_offset_left, - y - allocation.y - text_offset_left); + text_entry_set_anchor_position(entry, x, y); widget_set_motion_handler(entry->widget, text_entry_motion_handler); } else { |