Git init
[profile/ivi/isf.git] / ism / demos / isf_imcontrol_efl.cpp
1 /*
2  * ISF(Input Service Framework)
3  *
4  * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
5  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6  *
7  * Contact: Shuo Liu <shuo0805.liu@samsung.com>, Jihoon Kim <jihoon48.kim@samsung.com>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation, Inc., 51
21  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24
25 #include "isf_demo_efl.h"
26
27 static Ecore_IMF_Context *imf_context = NULL;
28 static Elm_Genlist_Item_Class itci;
29
30 enum {
31     INPUT_PANEL_GEOMETRY_GET,
32     INPUT_PANEL_SHOW,
33     INPUT_PANEL_HIDE,
34     INPUT_PANEL_IMDATA_SET,
35     INPUT_PANEL_IMDATA_GET,
36     INPUT_PANEL_LAYOUT_SET,
37     INPUT_PANEL_LAYOUT_GET,
38     INPUT_PANEL_PRIVATE_KEY_SET,
39     INPUT_PANEL_KEY_DISABLED_SET,
40     INPUT_PANEL_STATE_GET,
41     INPUT_PANEL_MOVE,
42     CONTROL_PANEL_SHOW,
43     CONTROL_PANEL_HIDE,
44 };
45
46 const char *api_list[]={
47     "PANEL GEOMETRY GET",
48     "INPUT PANEL SHOW",
49     "INPUT PANEL HIDE",
50     "INPUT PANEL IMDATA SET",
51     "INPUT PANEL IMDATA GET",
52     "INPUT PANEL LAYOUT SET",
53     "INPUT PANEL LAYOUT GET",
54     "PANEL PRIVATE KEY SET",
55     "PANEL KEY DISABLED SET",
56     "INPUT PANEL STATE GET",
57     "INPUT PANEL MOVE",
58     "CTRL PANEL SHOW",
59     "CTRL PANEL HIDE",
60 };
61
62 static void test_input_panel_geometry_get (void *data, Evas_Object *obj, void *event_info)
63 {
64     int x, y, w, h;
65     if (imf_context != NULL) {
66         ecore_imf_context_input_panel_geometry_get (imf_context, &x, &y, &w, &h);
67         printf ("x=%d \n", x);
68         printf ("y=%d \n", y);
69         printf ("width=%d \n", w);
70         printf ("height=%d \n", h);
71     }
72 }
73
74 void test_input_panel_show (void *data, Evas_Object *obj, void *event_info)
75 {
76     if (imf_context != NULL) {
77         ecore_imf_context_input_panel_show (imf_context);
78     }
79 }
80
81 void test_input_panel_hide (void *data, Evas_Object *obj, void *event_info)
82 {
83     if (imf_context != NULL) {
84         ecore_imf_context_input_panel_hide (imf_context);
85     }
86 }
87
88 void test_input_panel_imdata_set (void *data, Evas_Object *obj, void *event_info)
89 {
90     // need ISE to deal with the data
91     char buf[256] = "ur imdata";
92     if (imf_context != NULL)
93         ecore_imf_context_input_panel_imdata_set (imf_context, buf, sizeof (buf));
94 }
95
96 void test_input_panel_imdata_get (void *data, Evas_Object *obj, void *event_info)
97 {
98     int len = 256;
99     char* buf = (char*) malloc (len);
100     if (buf != NULL) {
101         memset (buf, '\0', len);
102         if (imf_context != NULL) {
103             ecore_imf_context_input_panel_imdata_get (imf_context, buf, &len);
104             printf ("get imdata  %s, and len is %d ...\n", (char *)buf, len);
105         }
106         free (buf);
107     }
108 }
109
110 void test_input_panel_layout_set (void *data, Evas_Object *obj, void *event_info)
111 {
112     Ecore_IMF_Input_Panel_Layout layout = ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL;
113     if (imf_context != NULL)
114         ecore_imf_context_input_panel_layout_set (imf_context, layout);
115 }
116
117 void test_input_panel_layout_get (void *data, Evas_Object *obj, void *event_info)
118 {
119     Ecore_IMF_Input_Panel_Layout layout;
120     if (imf_context != NULL) {
121         layout = ecore_imf_context_input_panel_layout_get (imf_context);
122         printf ("get layout : %d ...\n", (int)layout);
123     }
124 }
125
126 void test_input_panel_private_key_set (void *data, Evas_Object *obj, void *event_info)
127 {
128     int layout_index = 1;
129
130     if (imf_context != NULL)
131         ecore_imf_context_input_panel_private_key_set (imf_context, layout_index, ECORE_IMF_INPUT_PANEL_KEY_ENTER, NULL, "Go", ECORE_IMF_INPUT_PANEL_KEY_ENTER, NULL);
132 }
133
134 void test_input_panel_key_disabled_set (void *data, Evas_Object *obj, void *event_info)
135 {
136     int layout_index = 1;
137     int key_index    = 1;
138
139     if (imf_context != NULL)
140         ecore_imf_context_input_panel_key_disabled_set (imf_context, layout_index, key_index, EINA_TRUE);
141 }
142
143 void test_input_panel_state_get (void *data, Evas_Object *obj, void *event_info)
144 {
145     Ecore_IMF_Input_Panel_State state;
146
147     if (imf_context != NULL) {
148         state = ecore_imf_context_input_panel_state_get (imf_context);
149         printf ("ise state : %d \n", (int)state);
150     }
151 }
152
153 void test_control_panel_show (void *data, Evas_Object *obj, void *event_info)
154 {
155     if (imf_context != NULL) {
156         ecore_imf_context_control_panel_show (imf_context);
157     }
158 }
159
160 void test_control_panel_hide (void *data, Evas_Object *obj, void *event_info)
161 {
162     if (imf_context != NULL) {
163         ecore_imf_context_control_panel_hide (imf_context);
164     }
165 }
166
167 void test_input_panel_move (void *data, Evas_Object *obj, void *event_info)
168 {
169     if (imf_context != NULL) {
170         ecore_imf_context_input_panel_move (imf_context, 100, 100);
171     }
172 }
173
174 char *gli_label_get (void *data, Evas_Object *obj, const char *part)
175 {
176     int j = (int)data;
177     return strdup (api_list[j]);
178 }
179
180 static void test_api (void *data, Evas_Object *obj, void *event_info)
181 {
182     int j = (int)data;
183     switch (j) {
184     case INPUT_PANEL_GEOMETRY_GET:
185         test_input_panel_geometry_get (NULL, obj, event_info);
186         break;
187     case INPUT_PANEL_SHOW:
188         test_input_panel_show (NULL, obj, event_info);
189         break;
190     case INPUT_PANEL_HIDE:
191         test_input_panel_hide (NULL, obj, event_info);
192         break;
193     case INPUT_PANEL_IMDATA_SET:
194         test_input_panel_imdata_set (NULL,obj, event_info);
195         break;
196     case INPUT_PANEL_IMDATA_GET:
197         test_input_panel_imdata_get (NULL,obj, event_info);
198         break;
199     case INPUT_PANEL_LAYOUT_SET:
200         test_input_panel_layout_set (NULL,obj, event_info);
201         break;
202     case INPUT_PANEL_LAYOUT_GET:
203         test_input_panel_layout_get (NULL,obj, event_info);
204         break;
205     case INPUT_PANEL_PRIVATE_KEY_SET:
206         test_input_panel_private_key_set (NULL, obj, event_info);
207         break;
208     case INPUT_PANEL_KEY_DISABLED_SET:
209         test_input_panel_key_disabled_set (NULL, obj, event_info);
210         break;
211     case INPUT_PANEL_STATE_GET:
212         test_input_panel_state_get (NULL, obj, event_info);
213         break;
214     case INPUT_PANEL_MOVE:
215         test_input_panel_move (NULL, obj, event_info);
216         break;
217     case CONTROL_PANEL_SHOW:
218         test_control_panel_show (NULL, obj, event_info);
219         break;
220     case CONTROL_PANEL_HIDE:
221         test_control_panel_hide (NULL, obj, event_info);
222         break;
223     default:
224         break;
225     }
226 }
227
228 static void _nf_back_event (void *data, Evas_Object *obj, void *event_info)
229 {
230     if (imf_context) {
231         ecore_imf_context_del(imf_context);
232         imf_context = NULL;
233     }
234 }
235
236 static Evas_Object *_create_imcontrolapi_list (Evas_Object *parent)
237 {
238     int i, num;
239
240     Evas_Object *gl = elm_genlist_add (parent);
241
242     itci.item_style     = "default";
243     itci.func.label_get = gli_label_get;
244     itci.func.icon_get  = NULL;
245     itci.func.state_get = NULL;
246     itci.func.del       = NULL;
247
248     num = sizeof (api_list) / sizeof (char *);
249     for (i = 0; i < num; i++) {
250         elm_genlist_item_append (gl, &itci,
251                                  (void *)i/* item data */, NULL/* parent */, ELM_GENLIST_ITEM_NONE, test_api/* func */,
252                                  (void *)i/* func data */);
253     }
254
255     return gl;
256 }
257
258 void imcontrolapi_bt (void *data, Evas_Object *obj, void *event_info)
259 {
260     const char *ctx_id = ecore_imf_context_default_id_get ();
261     if (ctx_id != NULL) {
262         imf_context = ecore_imf_context_add (ctx_id);
263     } else {
264         printf ("Cannot create imf context\n");
265         return;
266     }
267
268     struct appdata *ad = (struct appdata *)data;
269     Evas_Object *gl = NULL;
270
271     gl = _create_imcontrolapi_list (ad->naviframe);
272
273     Elm_Object_Item *navi_it = elm_naviframe_item_push (ad->naviframe, _("isfimcontrol api"), NULL, NULL, gl, NULL);
274
275     Evas_Object *back_btn = elm_object_item_content_part_get (navi_it, ELM_NAVIFRAME_ITEM_PREV_BTN);
276     evas_object_smart_callback_add (back_btn, "clicked", _nf_back_event, ad);
277 }
278
279 /*
280 vi:ts=4:ai:nowrap:expandtab
281 */