Add synchronous get_selection API 25/67425/2
authorLi Zhang <li2012.zhang@samsung.com>
Tue, 26 Apr 2016 11:27:35 +0000 (19:27 +0800)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 26 Apr 2016 22:53:35 +0000 (07:53 +0900)
Change-Id: Ice6ec0598604de2acdae262d30dd775ab1b987c6

ism/extras/wayland_immodule/wayland_imcontext.c
ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp
ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp
ism/src/scim_helper.cpp
ism/src/scim_helper.h

index 03e64c4..cd919cf 100644 (file)
@@ -260,6 +260,7 @@ static void
 update_state(WaylandIMContext *imcontext)
 {
     char *surrounding = NULL;
+    char *selection = NULL;
     int cursor_pos;
     Ecore_Evas *ee;
     int canvas_x = 0, canvas_y = 0;
@@ -277,6 +278,13 @@ update_state(WaylandIMContext *imcontext)
             free(surrounding);
     }
 
+    ecore_imf_context_selection_get(imcontext->ctx, &selection);
+    if (imcontext->text_input)
+        wl_text_input_set_selection_text(imcontext->text_input, selection ? selection : "");
+
+    if (selection)
+        free(selection);
+
     if (imcontext->canvas) {
         ee = ecore_evas_ecore_evas_get(imcontext->canvas);
         if (ee)
index 68ff8e5..2946af8 100644 (file)
@@ -989,7 +989,7 @@ private:
         m_send_trans.write_to_socket(client_socket);
     }
 
-    void socket_update_selection(int client, uint32 context, const String& uuid, String text) {
+    void socket_update_selection(int client, uint32 context, String& uuid, String text) {
         LOGD ("client id:%d\n", client);
 
         Socket client_socket(client);
index 270faa9..9cb0222 100644 (file)
@@ -423,6 +423,17 @@ _wsc_im_ctx_bidi_direction(void *data, struct wl_input_method_context *im_ctx, u
     }
 }
 
+static void
+_wsc_im_ctx_selection_text(void *data, struct wl_input_method_context *im_ctx, const char *text)
+{
+    WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+
+    LOGD ("im_context = %p selection text = %s\n", im_ctx, text);
+    if (!wsc_ctx) return;
+
+    g_info_manager->socket_update_selection (text);
+}
+
 static const struct wl_input_method_context_listener wsc_im_context_listener = {
      _wsc_im_ctx_surrounding_text,
      _wsc_im_ctx_reset,
@@ -433,7 +444,8 @@ static const struct wl_input_method_context_listener wsc_im_context_listener = {
      _wsc_im_ctx_return_key_type,
      _wsc_im_ctx_return_key_disabled,
      _wsc_im_ctx_input_panel_data,
-     _wsc_im_ctx_bidi_direction
+     _wsc_im_ctx_bidi_direction,
+     _wsc_im_ctx_selection_text
 };
 
 static void
index b15fb88..c0ad81b 100644 (file)
@@ -142,8 +142,10 @@ public:
     BackEndPointer m_backend;
 
     char* surrounding_text;
+    char* selection_text;
     uint32 cursor_pos;
     bool need_update_surrounding_text;
+    bool need_update_selection_text;
 
     HelperAgentSignalVoid           signal_exit;
     HelperAgentSignalVoid           signal_attach_input_context;
@@ -205,7 +207,9 @@ public:
     HelperAgentSignalUintVoid           signal_check_option_window;
 
 public:
-    HelperAgentImpl (HelperAgent* thiz) : focused_ic ((uint32) -1), thiz (thiz), surrounding_text (NULL), cursor_pos (0), need_update_surrounding_text(false) {
+    HelperAgentImpl (HelperAgent* thiz) : focused_ic ((uint32) -1), thiz (thiz),
+        surrounding_text (NULL), selection_text (NULL), cursor_pos (0),
+        need_update_surrounding_text (false), need_update_selection_text (false) {
     }
 
 
@@ -379,8 +383,7 @@ public:
     {
         LOGD ("");
         String _text;
-        //FIXME
-        //thiz->get_selection (_text);
+        thiz->get_selection (_text);
         text = utf8_mbstowcs (_text);
         return true;
     }
@@ -510,6 +513,8 @@ HelperAgent::~HelperAgent ()
 {
     if (m_impl->surrounding_text != NULL)
         free (m_impl->surrounding_text);
+    if (m_impl->selection_text != NULL)
+        free (m_impl->selection_text);
 
     delete m_impl;
 }
@@ -834,7 +839,7 @@ HelperAgent::filter_event ()
                         free (m_impl->surrounding_text);
                     m_impl->surrounding_text = strdup (text.c_str ());
                     m_impl->cursor_pos = cursor;
-                    LOGD ("%s, %d", m_impl->surrounding_text, m_impl->cursor_pos);
+                    LOGD ("surrounding text: %s, %d", m_impl->surrounding_text, m_impl->cursor_pos);
                     if (m_impl->need_update_surrounding_text) {
                         m_impl->need_update_surrounding_text = false;
                         m_impl->signal_update_surrounding_text (this, ic, text, (int) cursor);
@@ -847,9 +852,18 @@ HelperAgent::filter_event ()
             case ISM_TRANS_CMD_UPDATE_SELECTION:
             {
                 String text;
-                if (m_impl->recv.get_data (text))
-                    m_impl->signal_update_selection (this, ic, text);
-                else
+                if (m_impl->recv.get_data (text)) {
+                    if (m_impl->selection_text != NULL)
+                        free (m_impl->selection_text);
+
+                    m_impl->selection_text = strdup (text.c_str ());
+                    LOGD ("selection text: %s", m_impl->selection_text);
+
+                    if (m_impl->need_update_selection_text) {
+                        m_impl->need_update_selection_text = false;
+                        m_impl->signal_update_selection (this, ic, text);
+                    }
+                } else
                     LOGW ("wrong format of transaction\n");
                 break;
             }
@@ -2021,6 +2035,21 @@ HelperAgent::get_selection (const String &uuid) const
         m_impl->send.put_data (uuid);
         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
     }
+
+    m_impl->need_update_selection_text = true;
+}
+
+/**
+ * @brief Request to get selection text synchronously.
+ *
+ * @param text The selection text.
+ */
+void
+HelperAgent::get_selection (String &text) const
+{
+    LOGD ("");
+    if (m_impl->selection_text)
+        text = m_impl->selection_text;
 }
 
 /**
index 7b51e25..6e73d74 100644 (file)
@@ -580,6 +580,13 @@ public:
     void get_selection       (const String                &uuid) const;
 
     /**
+     * @brief Request to get selection text synchronously.
+     *
+     * @param text The selection text.
+     */
+    void get_selection       (String                      &text) const;
+
+    /**
      * @brief Request to selected text.
      *
      * @param start The start position in text.