2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <Elementary.h>
24 #include "w-input-keyboard.h"
25 #include "w-input-selector.h"
27 extern InputKeyboardData g_input_keyboard_data;
28 extern App_Data* app_data;
32 bool input_keyboard_init(app_control_h app_control)
35 char *default_text = NULL;
36 char *guide_text = NULL;
37 char *return_key_type = (char *)"SEND";
38 char *max_text_length = NULL;
39 char *cursor_position_set = (char *)"0";
41 input_keyboard_deinit();
43 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_INPUT_DEFAULT_TEXT, &default_text);
44 if (ret == APP_CONTROL_ERROR_NONE) {
45 g_input_keyboard_data.default_text = default_text;
47 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_INPUT_GUIDE_TEXT, &guide_text);
48 if (ret == APP_CONTROL_ERROR_NONE) {
49 g_input_keyboard_data.guide_text = guide_text;
51 ret = app_control_get_extra_data(app_control, "return_key_type", &return_key_type);
52 if (ret == APP_CONTROL_ERROR_NONE) {
53 g_input_keyboard_data.return_key_type = return_key_type;
55 ret = app_control_get_extra_data(app_control, "max_text_length", &max_text_length);
56 if (ret == APP_CONTROL_ERROR_NONE) {
57 g_input_keyboard_data.max_text_length = atoi(max_text_length);
59 ret = app_control_get_extra_data(app_control, "cursor_position_set", &cursor_position_set);
60 if (ret == APP_CONTROL_ERROR_NONE) {
61 g_input_keyboard_data.cursor_position_set = atoi(cursor_position_set);
67 void input_keyboard_deinit(void)
69 if (g_input_keyboard_data.guide_text)
70 free(g_input_keyboard_data.guide_text);
72 if (g_input_keyboard_data.default_text)
73 free(g_input_keyboard_data.default_text);
75 if (g_input_keyboard_data.return_key_type)
76 free(g_input_keyboard_data.return_key_type);
78 g_input_keyboard_data.default_text = NULL;
79 g_input_keyboard_data.guide_text = NULL;
80 g_input_keyboard_data.return_key_type = (char *)"SEND";
81 g_input_keyboard_data.max_text_length = KEYBOARD_EDITOR_CHAR_COUNT_MAX;
82 g_input_keyboard_data.cursor_position_set = 0;
89 app_control_h app_control;
90 int ret = app_control_create(&app_control);
91 if (ret != APP_CONTROL_ERROR_NONE) {
92 PRINTFUNC(DLOG_ERROR, "Can not create app_control : %d", ret);
96 const char *getText = elm_entry_entry_get(entry);
97 LOGD("button key clicked!! : getText = %s", getText);
99 char cursorPosition[512];
100 snprintf(cursorPosition, sizeof(cursorPosition), "%d", elm_entry_cursor_pos_get(entry));
103 app_control_get_caller(app_data->source_app_control, &app_id);
105 app_control_set_app_id(app_control, app_id);
106 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
107 set_source_caller_app_id(app_control);
109 reply_to_sender_by_callback(getText, "keyboard", NULL, cursorPosition);
113 void btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
118 static Eina_Bool custom_back_cb(void *data, Elm_Object_Item *it)
120 _back_to_genlist_for_selector();
124 static void maxlength_cb(void *data, Evas_Object *obj, void *event_info)
126 LOGD("maxlength_cb : size = %d", KEYBOARD_EDITOR_CHAR_COUNT_MAX);
128 const char *guide = _(MAX_TEXT_LENGTH_REACH);
129 snprintf(text, sizeof(text), guide, g_input_keyboard_data.max_text_length);
130 show_popup_toast((const char *)text, false);
133 static void enter_keydown_cb(void *data, Evas_Object *obj, void *event_info)
135 LOGD("enter_keydown_cb");
136 Evas_Object *entry = obj;
140 Ecore_IMF_Context *imf_context = NULL;
141 imf_context = (Ecore_IMF_Context*)elm_entry_imf_context_get(entry);
143 ecore_imf_context_input_panel_hide(imf_context);
145 elm_object_focus_set(entry, EINA_FALSE);
150 void create_fullscreen_editor(void *data)
152 App_Data *ad = (App_Data *)data;
154 Evas_Object *box = elm_box_add(ad->naviframe);
155 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
156 evas_object_show(box);
157 elm_win_resize_object_add(ad->naviframe, box);
159 entry = elm_entry_add(box);
161 static Elm_Entry_Filter_Limit_Size limit_filter_data;
162 limit_filter_data.max_char_count = g_input_keyboard_data.max_text_length;
163 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
164 evas_object_smart_callback_add(entry, "maxlength,reached", maxlength_cb, data);
166 elm_entry_single_line_set(entry, EINA_TRUE);
167 elm_entry_scrollable_set(entry, EINA_TRUE);
168 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
169 elm_object_part_text_set(entry, "elm.guide", g_input_keyboard_data.guide_text);
170 elm_entry_entry_set(entry, g_input_keyboard_data.default_text);
171 elm_entry_cursor_end_set(entry);
172 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
173 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
174 if (g_input_keyboard_data.return_key_type && strcmp(g_input_keyboard_data.return_key_type, "DONE") == 0) {
175 elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
176 evas_object_smart_callback_add(entry, "activated", enter_keydown_cb, ad);
178 if (g_input_keyboard_data.cursor_position_set != 0) {
179 elm_entry_cursor_pos_set(entry, g_input_keyboard_data.cursor_position_set);
181 evas_object_show(entry);
182 elm_box_pack_end(box, entry);
184 Evas_Object *btn = elm_button_add(box);
185 elm_object_text_set(btn, g_input_keyboard_data.return_key_type);
186 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.5);
187 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
188 evas_object_smart_callback_add(btn, "clicked", btn_clicked_cb, NULL);
189 evas_object_show(btn);
190 elm_box_pack_end(box, btn);
191 evas_object_resize(ad->naviframe, 360, 360);
192 evas_object_show(ad->naviframe);
194 const char *item_style = NULL;
196 item_style = "empty";
197 Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, box, item_style);
198 elm_naviframe_item_pop_cb_set(nf_item, custom_back_cb, NULL);
201 static void editfield_focused_cb(void *data, Evas_Object *obj, void *event_info)
203 Evas_Object *editfield = (Evas_Object *)data;
204 elm_object_signal_emit(editfield, "elm,state,focused", "");
206 if (!elm_entry_is_empty(obj))
207 elm_object_signal_emit(editfield, "elm,action,show,button", "");
210 static void editfield_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
212 Evas_Object *editfield = (Evas_Object *)data;
213 elm_object_signal_emit(editfield, "elm,state,unfocused", "");
214 elm_object_signal_emit(editfield, "elm,action,hide,button", "");
217 static Evas_Object *create_multiline_editfield_layout(Evas_Object *parent, void *data)
219 App_Data *ad = (App_Data *)data;
220 Evas_Object *editfield;
222 editfield = elm_layout_add(parent);
223 elm_layout_theme_set(editfield, "layout", "editfield", "multiline");
224 evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, 0.0);
225 evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND, 0.0);
227 entry = elm_entry_add(editfield);
228 static Elm_Entry_Filter_Limit_Size limit_filter_data;
229 limit_filter_data.max_char_count = g_input_keyboard_data.max_text_length;
230 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
231 evas_object_smart_callback_add(entry, "maxlength,reached", maxlength_cb, data);
233 elm_entry_scrollable_set(entry, EINA_TRUE);
234 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
235 elm_object_part_text_set(entry, "elm.guide", g_input_keyboard_data.guide_text);
236 elm_entry_entry_set(entry, g_input_keyboard_data.default_text);
237 elm_entry_cursor_end_set(entry);
238 evas_object_smart_callback_add(entry, "focused", editfield_focused_cb, editfield);
239 evas_object_smart_callback_add(entry, "unfocused", editfield_unfocused_cb, editfield);
240 if (g_input_keyboard_data.return_key_type && strcmp(g_input_keyboard_data.return_key_type, "DONE") == 0) {
241 elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
242 evas_object_smart_callback_add(entry, "activated", enter_keydown_cb, ad);
244 if (g_input_keyboard_data.cursor_position_set != 0) {
245 elm_entry_cursor_pos_set(entry, g_input_keyboard_data.cursor_position_set);
248 evas_object_show(entry);
249 elm_object_part_content_set(editfield, "elm.swallow.content", entry);
254 static Evas_Object *create_editfield_view(void *data)
256 App_Data *ad = (App_Data *)data;
258 Evas_Object *main_scroller, *main_box, *editfield;
260 main_scroller = elm_scroller_add(ad->naviframe);
261 elm_scroller_bounce_set(main_scroller, EINA_FALSE, EINA_TRUE);
262 evas_object_size_hint_weight_set(main_scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
263 evas_object_size_hint_align_set(main_scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
264 evas_object_show(main_scroller);
266 main_box = elm_box_add(main_scroller);
267 evas_object_size_hint_align_set(main_box, EVAS_HINT_FILL, 0.0);
268 evas_object_size_hint_weight_set(main_box, EVAS_HINT_EXPAND, 0.0);
269 evas_object_show(main_box);
271 editfield = create_multiline_editfield_layout(main_box, data);
272 elm_box_pack_end(main_box, editfield);
273 evas_object_show(editfield);
275 Evas_Object *btn = elm_button_add(main_box);
276 elm_object_text_set(btn, "OK");
277 evas_object_size_hint_weight_set(btn, 0.5, 0.5);
278 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
279 evas_object_smart_callback_add(btn, "clicked", btn_clicked_cb, NULL);
280 evas_object_show(btn);
281 elm_box_pack_end(main_box, btn);
283 elm_object_content_set(main_scroller, main_box);
285 evas_object_show(ad->naviframe);
286 const char *item_style = NULL;
288 item_style = "empty";
289 Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, main_scroller, item_style);
290 elm_naviframe_item_pop_cb_set(nf_item, custom_back_cb, NULL);
292 return main_scroller;
295 bool input_keyboard_launch(Evas_Object *window, void *data) {
296 if (window == NULL) {
297 PRINTFUNC(DLOG_ERROR, "Can not get window");
302 create_fullscreen_editor(data);
304 create_editfield_view(data);