Add ecore_imf_context_selection_get API to allow Input Method to get the selected...
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 23 Jan 2014 01:44:00 +0000 (10:44 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 23 Jan 2014 01:44:00 +0000 (10:44 +0900)
src/lib/ecore_imf/Ecore_IMF.h
src/lib/ecore_imf/ecore_imf_context.c
src/lib/ecore_imf/ecore_imf_private.h

index ee1c249..2d96a22 100644 (file)
@@ -908,6 +908,20 @@ EAPI void                          ecore_imf_context_use_preedit_set(Ecore_IMF_C
 EAPI void                          ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos), const void *data);
 
 /**
+ * Set the callback to be used on selection_get request.
+ *
+ * This callback will be called when the Input Method Context
+ * module requests the selection context.
+ *
+ * @param ctx An #Ecore_IMF_Context.
+ * @param func The callback to be called.
+ * @param data The data pointer to be passed to @p func
+ * @ingroup Ecore_IMF_Context_Group
+ * @since 1.9.0
+ */
+EAPI void                          ecore_imf_context_retrieve_selection_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text), const void *data);
+
+/**
  * Set the input mode used by the Ecore Input Context.
  *
  * The input mode can be one of the input modes defined in
@@ -1044,6 +1058,28 @@ EAPI void                         *ecore_imf_context_data_get(Ecore_IMF_Context
 EAPI Eina_Bool                     ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos);
 
 /**
+ * Retrieve the selected text.
+ *
+ * This function is implemented by calling the
+ * Ecore_IMF_Context::retrieve_selection_func (
+ * set using #ecore_imf_context_retrieve_selection_callback_set).
+ *
+ * There is no obligation for a widget to respond to the
+ * retrieve_surrounding_func, so input methods must be prepared
+ * to function without context.
+ *
+ * @param ctx An #Ecore_IMF_Context.
+ * @param text Location to store a UTF-8 encoded string of the selected text.
+ *             If the function returns @c EINA_TRUE, then you must free
+ *             the result stored in this location with free().
+ * @return @c EINA_TRUE if selected text was provided; otherwise
+ * @c EINA_FALSE.
+ * @ingroup Ecore_IMF_Context_Module_Group
+ * @since 1.9.0
+ */
+EAPI Eina_Bool                     ecore_imf_context_selection_get(Ecore_IMF_Context *ctx, char **text);
+
+/**
  * Adds ECORE_IMF_EVENT_PREEDIT_START to the event queue.
  *
  * ECORE_IMF_EVENT_PREEDIT_START should be added when a new preedit sequence starts.
index 63c41c8..7b554e6 100644 (file)
@@ -462,6 +462,20 @@ ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, Eina
 }
 
 EAPI void
+ecore_imf_context_retrieve_selection_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text), const void *data)
+{
+   if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
+     {
+        ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
+                         "ecore_imf_context_retrieve_selection_callback_set");
+        return;
+     }
+
+   ctx->retrieve_selection_func = func;
+   ctx->retrieve_selection_data = (void *) data;
+}
+
+EAPI void
 ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode)
 {
    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
@@ -563,6 +577,29 @@ ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *curs
    return result;
 }
 
+EAPI Eina_Bool
+ecore_imf_context_selection_get(Ecore_IMF_Context *ctx, char **text)
+{
+   Eina_Bool result = EINA_FALSE;
+
+   if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
+     {
+        ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
+                         "ecore_imf_context_selection_get");
+        return EINA_FALSE;
+     }
+
+   if (ctx->retrieve_selection_func)
+     {
+        result = ctx->retrieve_selection_func(ctx->retrieve_selection_data, ctx, text);
+        if (!result)
+          {
+             if (text) *text = NULL;
+          }
+     }
+   return result;
+}
+
 static void
 _ecore_imf_event_free_preedit(void *data EINA_UNUSED, void *event)
 {
index 81d71c9..d6bf257 100644 (file)
@@ -56,6 +56,8 @@ struct _Ecore_IMF_Context
    Ecore_IMF_Input_Panel_Lang     input_panel_lang;
    Ecore_IMF_Input_Panel_Return_Key_Type input_panel_return_key_type;
    int                            input_panel_layout_variation;
+   Eina_Bool                    (*retrieve_selection_func)(void *data, Ecore_IMF_Context *ctx, char **text);
+   void                          *retrieve_selection_data;
    Eina_Bool                      allow_prediction : 1;
    Eina_Bool                      input_panel_enabled : 1;
    Eina_Bool                      input_panel_return_key_disabled : 1;