6390ab8191b8116b76c4ea561174b4c638153285
[profile/ivi/isf.git] / ism / demos / isf_layout_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 #include "isf_layout_efl.h"
27
28 static void _rotate_cb (void *data, Evas_Object *obj, void *event_info)
29 {
30     struct appdata *ad = (struct appdata *)data;
31
32     int angle = elm_win_rotation_get (ad->win_main);
33     if (angle == 0) {
34         elm_win_rotation_with_resize_set (ad->win_main, 270);
35     } else if (angle == 270) {
36         elm_win_rotation_with_resize_set (ad->win_main, 0);
37     }
38 }
39
40 static void _input_panel_state_cb (void *data, Ecore_IMF_Context *ctx, int value)
41 {
42     int x, y, w, h;
43
44     if (value == ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
45         ecore_imf_context_input_panel_geometry_get (ctx, &x, &y, &w, &h);
46         printf ("Input panel is shown\n");
47         printf ("x : %d, y : %d, w : %d, h : %d\n", x, y, w, h);
48     } else if (value == ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
49         printf ("Input panel is hidden\n");
50     } else if (value == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW) {
51         printf ("Input panel will be shown\n");
52     }
53 }
54
55 static void _input_panel_resize_cb (void *data, Ecore_IMF_Context *ctx, int value)
56 {
57     int x, y, w, h;
58
59     ecore_imf_context_input_panel_geometry_get (ctx, &x, &y, &w, &h);
60     printf ("[%s] x : %d, y : %d, w : %d, h : %d\n", __func__, x, y, w, h);
61 }
62
63 static void _shift_mode_cb (void *data, Ecore_IMF_Context *ctx, int value)
64 {
65     if (value == ECORE_IMF_INPUT_PANEL_SHIFT_MODE_OFF) {
66         printf ("[%s] Shift Mode : OFF\n", __func__);
67     } else if (value == ECORE_IMF_INPUT_PANEL_SHIFT_MODE_ON) {
68         printf ("[%s] Shift Mode : ON\n", __func__);
69     }
70 }
71
72 static void _language_changed_cb (void *data, Ecore_IMF_Context *ctx, int value)
73 {
74     char *locale;
75
76     ecore_imf_context_input_panel_language_locale_get(ctx, &locale);
77
78     printf ("[%s] language : %s\n", __func__, locale);
79
80     if (locale)
81         free (locale);
82 }
83
84 static void _candidate_panel_state_cb (void *data, Ecore_IMF_Context *ctx, int value)
85 {
86     int x, y, w, h;
87
88     if (value == ECORE_IMF_CANDIDATE_PANEL_SHOW) {
89         ecore_imf_context_candidate_panel_geometry_get (ctx, &x, &y, &w, &h);
90         printf ("Candidate window is shown\n");
91         printf ("[%s] x : %d, y : %d, w : %d, h : %d\n", __func__, x, y, w, h);
92     } else if (value == ECORE_IMF_CANDIDATE_PANEL_HIDE) {
93         printf ("Candidate window is hidden\n");
94     }
95 }
96
97 static void _candidate_panel_geometry_changed_cb (void *data, Ecore_IMF_Context *ctx, int value)
98 {
99     int x, y, w, h;
100
101     ecore_imf_context_candidate_panel_geometry_get (ctx, &x, &y, &w, &h);
102     printf ("[%s] x : %d, y : %d, w : %d, h : %d\n", __func__, x, y, w, h);
103 }
104
105 static void
106 _key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
107 {
108     Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *)event_info;
109     printf("[key down] keyname : '%s', key : '%s', string : '%s', compose : '%s'\n", ev->keyname, ev->key, ev->string, ev->compose);
110 }
111
112 static void
113 _key_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
114 {
115     Evas_Event_Key_Up *ev = (Evas_Event_Key_Up *)event_info;
116     printf("[key up] keyname : '%s', key : '%s', string : '%s', compose : '%s'\n", ev->keyname, ev->key, ev->string, ev->compose);
117 }
118
119 static Evas_Object *_create_ef_layout(Evas_Object *parent, const char *label, const char *guide_text,Elm_Input_Panel_Layout layout)
120 {
121     Evas_Object *ef =  _create_ef(parent,label,guide_text);
122     Ecore_IMF_Context *ic = NULL;
123     Evas_Object *en = elm_object_part_content_get(ef,"elm.swallow.content");
124     elm_entry_input_panel_layout_set (en, layout);
125     evas_object_event_callback_add(en, EVAS_CALLBACK_KEY_DOWN, _key_down_cb, NULL);
126     evas_object_event_callback_add(en, EVAS_CALLBACK_KEY_UP, _key_up_cb, NULL);
127
128     ic = (Ecore_IMF_Context *)elm_entry_imf_context_get (en);
129
130     if (ic != NULL) {
131         ecore_imf_context_input_panel_event_callback_add (ic, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _input_panel_state_cb, NULL);
132         ecore_imf_context_input_panel_event_callback_add (ic, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, _input_panel_resize_cb, NULL);
133         ecore_imf_context_input_panel_event_callback_add (ic, ECORE_IMF_INPUT_PANEL_SHIFT_MODE_EVENT, _shift_mode_cb, NULL);
134         ecore_imf_context_input_panel_event_callback_add (ic, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, _language_changed_cb, NULL);
135
136         ecore_imf_context_input_panel_event_callback_add (ic, ECORE_IMF_CANDIDATE_PANEL_STATE_EVENT, _candidate_panel_state_cb, NULL);
137         ecore_imf_context_input_panel_event_callback_add (ic, ECORE_IMF_CANDIDATE_PANEL_GEOMETRY_EVENT, _candidate_panel_geometry_changed_cb, NULL);
138     }
139
140     return ef;
141 }
142
143 static void add_layout_to_conformant (void *data, Evas_Object *lay_in, const char *title)
144 {
145    Evas_Object *scroller = NULL;
146    Evas_Object *win = NULL;
147    Evas_Object *conform = NULL;
148    struct appdata *ad = NULL;
149
150    ad = (struct appdata *) data;
151
152    win = ad->win_main;
153    // Enabling illume notification property for window
154    elm_win_conformant_set (win, EINA_TRUE);
155
156    // Creating conformant widget
157    conform = elm_conformant_add (win);
158    evas_object_size_hint_weight_set (conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
159    evas_object_show (conform);
160
161    scroller = elm_scroller_add (ad->naviframe);
162
163    elm_scroller_bounce_set (scroller, EINA_FALSE, EINA_TRUE);
164    evas_object_show (scroller);
165
166    elm_object_content_set (scroller, lay_in);
167    elm_object_content_set (conform, scroller);
168    elm_naviframe_item_push (ad->naviframe, title, NULL, NULL, conform, NULL);
169 }
170
171 static Evas_Object * create_inner_layout (void *data)
172 {
173     struct appdata *ad = (struct appdata *)data;
174     Evas_Object *bx = NULL ;
175     Evas_Object *ef = NULL ;
176     Evas_Object *parent = ad->naviframe;
177
178     bx = elm_box_add (parent);
179     evas_object_size_hint_weight_set (bx, EVAS_HINT_EXPAND, 0.0);
180     evas_object_size_hint_align_set (bx, EVAS_HINT_FILL, 0.0);
181     evas_object_show (bx);
182
183     /* Normal Layout */
184     ef = _create_ef_layout (parent, _("NORMAL LAYOUT"), _("click to enter TEXT"), ELM_INPUT_PANEL_LAYOUT_NORMAL);
185     elm_box_pack_end (bx, ef);
186
187     /* Number Layout */
188     ef = _create_ef_layout (parent, _("NUMBER LAYOUT"), _("click to enter NUMBER"), ELM_INPUT_PANEL_LAYOUT_NUMBER);
189     elm_box_pack_end (bx, ef);
190
191     /* Email Layout */
192     ef = _create_ef_layout (parent, _("EMAIL LAYOUT"), _("click to enter EMAIL"), ELM_INPUT_PANEL_LAYOUT_EMAIL);
193     elm_box_pack_end (bx, ef);
194
195     /* URL Layout */
196     ef = _create_ef_layout (parent, _("URL LAYOUT"), _("click to enter URL"), ELM_INPUT_PANEL_LAYOUT_URL);
197     elm_box_pack_end (bx, ef);
198
199     /* Phonenumber Layout */
200     ef = _create_ef_layout (parent, _("PHONENUMBER LAYOUT"), _("click to enter PHONENUMBER"), ELM_INPUT_PANEL_LAYOUT_PHONENUMBER);
201     elm_box_pack_end (bx, ef);
202
203     /* IP Layout */
204     ef = _create_ef_layout (parent, _("IP LAYOUT"), _("click to enter IP"), ELM_INPUT_PANEL_LAYOUT_IP);
205     elm_box_pack_end (bx, ef);
206
207     /* Month Layout */
208     ef = _create_ef_layout (parent, _("MONTH LAYOUT"), _("click to enter MONTH"), ELM_INPUT_PANEL_LAYOUT_MONTH);
209     elm_box_pack_end (bx, ef);
210
211     /* Number Only Layout */
212     ef = _create_ef_layout (parent, _("NUMBERONLY LAYOUT"), _("click to enter NUMBERONLY"), ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
213     elm_box_pack_end (bx, ef);
214
215     /* Click to rotate button */
216     Evas_Object *rotate_btn = elm_button_add(parent);
217     elm_object_text_set(rotate_btn, "rotate");
218     evas_object_smart_callback_add(rotate_btn, "clicked", _rotate_cb, (void *)ad);
219     evas_object_size_hint_weight_set (rotate_btn, EVAS_HINT_EXPAND, 0.0);
220     evas_object_size_hint_align_set (rotate_btn, EVAS_HINT_FILL, 0);
221     evas_object_show (rotate_btn);
222     elm_box_pack_end (bx, rotate_btn);
223
224     return bx;
225 }
226
227 void ise_layout_bt (void *data, Evas_Object *obj, void *event_info)
228 {
229     Evas_Object *lay_inner = create_inner_layout (data);
230     add_layout_to_conformant (data, lay_inner, _("Layout"));
231 }
232
233 /*
234 vi:ts=4:ai:nowrap:expandtab
235 */