jihoon pushed a commit to branch master.

commit af31393a09251e7a42897fdaca893600d5221e03
Author: Jihoon Kim <[email protected]>
Date:   Sat Apr 13 17:11:32 2013 +0900

    ecore_imf: Add ecore_imf_context_input_panel_event_callback_call, clear API
---
 ChangeLog                             |  1 +
 NEWS                                  |  1 +
 src/lib/ecore_imf/Ecore_IMF.h         | 22 +++++++++
 src/lib/ecore_imf/ecore_imf_context.c | 92 ++++++++++++++++++++++++++++++++---
 src/lib/ecore_imf/ecore_imf_private.h |  9 ++++
 5 files changed, 119 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index da95d22..674f65d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2013-04-13  Jihoon Kim
 
         * Ecore_IMF: Add ecore_imf_input_panel_hide () API
+        * Ecore_IMF: Add ecore_imf_context_input_panel_event_callback_call, 
clear API
 
 2013-04-10  Rafael Antognolli
 
diff --git a/NEWS b/NEWS
index 8b0a81b..f49c5a2 100644
--- a/NEWS
+++ b/NEWS
@@ -93,6 +93,7 @@ Additions:
     * ecore_imf: 
      - Add ecore_imf_context_input_panel_layout_variation_set/get API
      - Add ecore_imf_input_panel_hide API
+     - Add ecore_imf_context_input_panel_event_callback_call, clear API
     * Add edje_object_part_text_input_panel_layout_variation_set/get API
     * Evil:
      - Add mkdtemp.
diff --git a/src/lib/ecore_imf/Ecore_IMF.h b/src/lib/ecore_imf/Ecore_IMF.h
index 2eb81fd..7e740c7 100644
--- a/src/lib/ecore_imf/Ecore_IMF.h
+++ b/src/lib/ecore_imf/Ecore_IMF.h
@@ -1475,6 +1475,28 @@ EAPI void                          
ecore_imf_context_input_panel_event_callback_
 EAPI void                          
ecore_imf_context_input_panel_event_callback_del(Ecore_IMF_Context *ctx, 
Ecore_IMF_Input_Panel_Event type, void (*func) (void *data, Ecore_IMF_Context 
*ctx, int value));
 
 /**
+ * Call a given input panel callback on the context @p ctx.
+ *
+ * @param ctx Ecore_IMF_Context.
+ * @param type The type of event that will trigger the callback
+ * @param value the event value
+ * @ingroup Ecore_IMF_Context_Group
+ * @since 1.8.0
+ */
+EAPI void                          
ecore_imf_context_input_panel_event_callback_call(Ecore_IMF_Context *ctx, 
Ecore_IMF_Input_Panel_Event type, int value);
+
+/**
+ * Delete all input panel callback on the context @p ctx.
+ *
+ * Delete all input panel callback to be registered by 
ecore_imf_context_input_panel_event_callback_add()
+ *
+ * @param ctx Ecore_IMF_Context.
+ * @ingroup Ecore_IMF_Context_Group
+ * @since 1.8.0
+ */
+EAPI void                          
ecore_imf_context_input_panel_event_callback_clear(Ecore_IMF_Context *ctx);
+
+/**
  * Get the current language locale of the input panel.
  *
  * ex) fr_FR
diff --git a/src/lib/ecore_imf/ecore_imf_context.c 
b/src/lib/ecore_imf/ecore_imf_context.c
index 7c8318e..f1e8821 100644
--- a/src/lib/ecore_imf/ecore_imf_context.c
+++ b/src/lib/ecore_imf/ecore_imf_context.c
@@ -190,6 +190,12 @@ ecore_imf_context_del(Ecore_IMF_Context *ctx)
            free(fn);
      }
 
+   if (ctx->input_panel_callbacks)
+     {
+        EINA_LIST_FREE(ctx->input_panel_callbacks, fn)
+           free(fn);
+     }
+
    ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE);
    free(ctx);
 }
@@ -268,7 +274,6 @@ ecore_imf_context_hide(Ecore_IMF_Context *ctx)
         return;
      }
 
-   show_req_ctx = NULL;
    if (ctx->klass->hide) ctx->klass->hide(ctx);
 }
 
@@ -792,7 +797,6 @@ ecore_imf_context_input_panel_hide(Ecore_IMF_Context *ctx)
         return;
      }
 
-   show_req_ctx = NULL;
    if (ctx->klass->hide) ctx->klass->hide(ctx);
 }
 
@@ -1060,6 +1064,8 @@ 
ecore_imf_context_input_panel_event_callback_add(Ecore_IMF_Context *ctx,
                                                  void (*func) (void *data, 
Ecore_IMF_Context *ctx, int value),
                                                  const void *data)
 {
+   Ecore_IMF_Input_Panel_Callback_Node *fn = NULL;
+
    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
      {
         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
@@ -1067,8 +1073,16 @@ 
ecore_imf_context_input_panel_event_callback_add(Ecore_IMF_Context *ctx,
         return;
      }
 
-   if (ctx->klass->input_panel_event_callback_add)
-     ctx->klass->input_panel_event_callback_add(ctx, type, func, (void *)data);
+   if (!func) return;
+
+   fn = calloc(1, sizeof (Ecore_IMF_Input_Panel_Callback_Node));
+   if (!fn) return;
+
+   fn->func = func;
+   fn->data = data;
+   fn->type = type;
+
+   ctx->input_panel_callbacks = eina_list_append(ctx->input_panel_callbacks, 
fn);
 }
 
 EAPI void
@@ -1076,6 +1090,10 @@ 
ecore_imf_context_input_panel_event_callback_del(Ecore_IMF_Context *ctx,
                                                  Ecore_IMF_Input_Panel_Event 
type,
                                                  void (*func) (void *data, 
Ecore_IMF_Context *ctx, int value))
 {
+   Eina_List *l = NULL;
+   Eina_List *l_next = NULL;
+   Ecore_IMF_Input_Panel_Callback_Node *fn = NULL;
+
    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
      {
         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
@@ -1083,8 +1101,70 @@ 
ecore_imf_context_input_panel_event_callback_del(Ecore_IMF_Context *ctx,
         return;
      }
 
-   if (ctx->klass->input_panel_event_callback_del)
-     ctx->klass->input_panel_event_callback_del(ctx, type, func);
+   if (!func) return;
+   if (!ctx->input_panel_callbacks) return;
+
+   EINA_LIST_FOREACH_SAFE(ctx->input_panel_callbacks, l, l_next, fn)
+     {
+        if ((fn) && (fn->func == func) && (fn->type == type))
+          {
+             free(fn);
+             ctx->input_panel_callbacks = 
eina_list_remove_list(ctx->input_panel_callbacks, l);
+             return;
+          }
+     }
+}
+
+EAPI void
+ecore_imf_context_input_panel_event_callback_call(Ecore_IMF_Context *ctx, 
Ecore_IMF_Input_Panel_Event type, int value)
+{
+   Ecore_IMF_Input_Panel_Callback_Node *fn = NULL;
+   Eina_List *l = NULL;
+
+   if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
+     {
+        ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
+                         "ecore_imf_context_input_panel_event_callback_call");
+        return;
+     }
+
+   EINA_LIST_FOREACH(ctx->input_panel_callbacks, l, fn)
+     {
+        if ((fn) && (fn->type == type) && (fn->func))
+          {
+             fn->func(fn->data, ctx, value);
+             if (type == ECORE_IMF_INPUT_PANEL_STATE_EVENT &&
+                 value == ECORE_IMF_INPUT_PANEL_STATE_HIDE &&
+                 show_req_ctx == ctx)
+               show_req_ctx = NULL;
+          }
+     }
+}
+
+EAPI void
+ecore_imf_context_input_panel_event_callback_clear(Ecore_IMF_Context *ctx)
+{
+   Ecore_IMF_Input_Panel_Callback_Node *fn = NULL;
+   Eina_List *l = NULL;
+
+   if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
+     {
+        ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
+                         "ecore_imf_context_input_panel_event_callback_clear");
+        return;
+     }
+
+   for (l = ctx->input_panel_callbacks; l;)
+     {
+        fn = (Ecore_IMF_Input_Panel_Callback_Node *)l->data;
+
+        if (fn)
+          {
+             ctx->input_panel_callbacks = 
eina_list_remove(ctx->input_panel_callbacks, fn);
+             free (fn);
+          }
+        l = l->next;
+     }
 }
 
 EAPI void
diff --git a/src/lib/ecore_imf/ecore_imf_private.h 
b/src/lib/ecore_imf/ecore_imf_private.h
index 7452bd7..b63500a 100644
--- a/src/lib/ecore_imf/ecore_imf_private.h
+++ b/src/lib/ecore_imf/ecore_imf_private.h
@@ -36,6 +36,7 @@ extern int _ecore_imf_log_dom;
 
 typedef struct _Ecore_IMF_Module Ecore_IMF_Module;
 typedef struct _Ecore_IMF_Func_Node Ecore_IMF_Func_Node;
+typedef struct _Ecore_IMF_Input_Panel_Callback_Node 
Ecore_IMF_Input_Panel_Callback_Node;
 
 struct _Ecore_IMF_Context
 {
@@ -49,6 +50,7 @@ struct _Ecore_IMF_Context
    Eina_Bool                    (*retrieve_surrounding_func)(void *data, 
Ecore_IMF_Context *ctx, char **text, int *cursor_pos);
    void                          *retrieve_surrounding_data;
    Eina_List                     *callbacks;
+   Eina_List                     *input_panel_callbacks;
    Ecore_IMF_Autocapital_Type     autocapital_type;
    Ecore_IMF_Input_Panel_Layout   input_panel_layout;
    Ecore_IMF_Input_Panel_Lang     input_panel_lang;
@@ -74,6 +76,13 @@ struct _Ecore_IMF_Func_Node
    Ecore_IMF_Callback_Type type;
 };
 
+struct _Ecore_IMF_Input_Panel_Callback_Node
+{
+   void (*func) ();
+   const void *data;
+   Ecore_IMF_Input_Panel_Event type;
+};
+
 void               ecore_imf_module_init(void);
 void               ecore_imf_module_shutdown(void);
 Eina_List         *ecore_imf_module_available_get(void);

-- 

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter

Reply via email to