2 * Copyright (C) 2012 Samsung Electronics
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "InputPicker.h"
25 #include <Elementary.h>
29 #include <vconf/vconf.h>
31 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
33 #include <efl_assist.h>
34 extern void* EflAssistHandle;
37 #if OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)
39 static const unsigned maxDatetimeLength = 32;
40 static const unsigned maxDateStringLength = 10;
41 static const char defaultDatetimeFormat[] = "%Y/%m/%d %H:%M";
52 struct Input_Date_Str {
53 char year[maxDateStringLength];
54 char mon[maxDateStringLength];
55 char day[maxDateStringLength];
56 char hour[maxDateStringLength];
57 char min[maxDateStringLength];
58 char sec[maxDateStringLength];
61 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
62 static inline void _picker_back_cb(void* data, Evas_Object* obj, void* event_info)
64 elm_object_signal_emit(obj, "picker,hide", "");
67 static void _edit_start_cb(void* data, Evas_Object* obj, void* event_info)
72 void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
73 webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
74 (*webkit_ea_object_event_callback_add)(obj, EA_CALLBACK_BACK, _picker_back_cb, 0);
77 static void _edit_end_cb(void* data, Evas_Object* obj, void* event_info)
79 // Set focus on 1st popup.
80 Input_Picker_Layout* pickerLayout = (Input_Picker_Layout*)data;
81 elm_object_focus_set(pickerLayout->popup, true);
86 void (*webkit_ea_object_event_callback_del)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func);
87 webkit_ea_object_event_callback_del = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func))dlsym(EflAssistHandle, "ea_object_event_callback_del");
88 (*webkit_ea_object_event_callback_del)(obj, EA_CALLBACK_BACK, _picker_back_cb);
90 #endif // ENABLE(TIZEN_HW_MORE_BACK_KEY)
92 static char* datetimeFormat()
94 char* datetimeFormat = NULL;
95 char* regionFormat = NULL;
96 char* language = NULL;
97 char buf[256] = { 0, };
102 language = getenv("LANGUAGE");
103 setenv("LANGUAGE", "en_US", 1);
105 regionFormat = vconf_get_str(VCONFKEY_REGIONFORMAT);
109 // FIXME: Workaround fix for region format.
110 if (!strncmp("utf-8", regionFormat, 5)) {
111 TIZEN_LOGI("region format is utf-8");
113 regionFormat = strdup("UTF-8");
116 returnValue = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &timeValue);
119 else if(timeValue == VCONFKEY_TIME_FORMAT_12 || timeValue == VCONFKEY_TIME_FORMAT_24)
120 isHour24 = timeValue - 1;
123 snprintf(buf, sizeof(buf), "%s_DTFMT_24HR", regionFormat);
125 snprintf(buf, sizeof(buf), "%s_DTFMT_12HR", regionFormat);
129 datetimeFormat = dgettext("dt_fmt", buf);
131 if(!language || !strcmp(language, ""))
132 unsetenv("LANGUAGE");
134 setenv("LANGUAGE", language, 1);
136 // FIXME: Workaround fix for not supported dt_fmt. Use default format if dt_fmt string is not exist.
137 if (strlen(datetimeFormat) == strlen(buf) && !strncmp(datetimeFormat, buf, strlen(buf))) {
138 TIZEN_LOGI("datetime format: %s", datetimeFormat);
142 return strdup(datetimeFormat);
145 Input_Picker_Layout::Input_Picker_Layout(Evas_Object* ewkView)
152 , dataListEditField(0)
153 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
158 , datetimeLocal(false)
160 evas_object_focus_set(m_ewkView, false);
162 /* FIXME : Workaround. OSP requirement.
163 OSP want to block own touch event while webkit internal picker is running. */
164 evas_object_smart_callback_call(m_ewkView, "input,picker,show", 0);
167 Input_Picker_Layout::~Input_Picker_Layout()
169 /* FIXME : Workaround. OSP requirement.
170 OSP want to block own touch event while webkit internal picker is running. */
171 evas_object_smart_callback_call(m_ewkView, "input,picker,hide", 0);
176 InputPicker::InputPicker(Evas_Object* ewkView)
180 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
181 , m_isColorPickerShown(false)
186 InputPicker::~InputPicker()
188 if (m_pickerLayout) {
189 if (m_pickerLayout->popup)
190 evas_object_del(m_pickerLayout->popup);
191 delete m_pickerLayout;
195 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
197 TIZEN_SECURE_LOGI("input value: %s", inputValue);
199 if(inputType == EWK_INPUT_TYPE_DATE)
200 ewk_date_popup(inputValue);
201 else if(inputType == EWK_INPUT_TYPE_TIME)
202 ewk_time_popup(inputValue);
203 else if(inputType == EWK_INPUT_TYPE_DATETIME)
204 ewk_datetime_popup(inputValue, false);
205 else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
206 ewk_datetime_popup(inputValue, true);
207 else if(inputType == EWK_INPUT_TYPE_MONTH)
208 ewk_month_popup(inputValue);
209 else if(inputType == EWK_INPUT_TYPE_WEEK)
210 ewk_week_popup(inputValue);
213 #if ENABLE(TIZEN_DATALIST_ELEMENT)
214 void InputPicker::_data_list_popup_response_cb(void* data, Evas_Object* obj, void* eventInfo)
216 InputPicker* inputPicker = static_cast<InputPicker*>(data);
217 const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
218 ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
220 if (inputPicker->m_pickerLayout->popup) {
221 evas_object_del(inputPicker->m_pickerLayout->popup);
222 inputPicker->m_pickerLayout->popup = 0;
225 delete inputPicker->m_pickerLayout;
226 inputPicker->m_pickerLayout = 0;
228 inputPicker->m_dataList = 0;
231 void InputPicker::_data_list_popup_response_cancel_cb(void* data, Evas_Object* obj, void* eventInfo)
233 InputPicker* inputPicker = static_cast<InputPicker*>(data);
235 if (inputPicker->m_pickerLayout->popup) {
236 evas_object_del(inputPicker->m_pickerLayout->popup);
237 inputPicker->m_pickerLayout->popup = 0;
240 delete inputPicker->m_pickerLayout;
241 inputPicker->m_pickerLayout = 0;
243 inputPicker->m_dataList = 0;
246 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
248 InputPicker* inputPicker = static_cast<InputPicker*>(data);
249 Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
250 Elm_Object_Item* item = elm_list_first_item_get(obj);
254 if (item == selectedItem)
257 item = elm_list_item_next(item);
263 EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
264 if (listItem && index == listIndex)
265 elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
271 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
273 Evas_Object* entry = static_cast<Evas_Object*>(data);
274 elm_entry_entry_set(entry, "");
277 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
279 Evas_Object* layout = static_cast<Evas_Object*>(data);
281 if (elm_object_focus_get(layout)) {
282 if (elm_entry_is_empty(obj))
283 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
285 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
289 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
291 Evas_Object* layout = static_cast<Evas_Object*>(data);
293 if (!elm_entry_is_empty(obj))
294 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
297 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
299 Evas_Object* layout = static_cast<Evas_Object*>(data);
300 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
303 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
305 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
306 Evas_Object* win = parent;
308 m_dataList = optionList;
313 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
315 /* FIXME: If the entry is in the popup, the parent should be naviframe for uifw limitation. */
316 Evas_Object* naviframe = elm_naviframe_add(m_ewkView);
318 const char* type = elm_object_widget_type_get(parent);
320 if (!strcmp(type, elm_object_widget_type_get(naviframe))) {
325 parent = elm_object_parent_widget_get(parent);
328 evas_object_del(naviframe);
333 m_pickerLayout->popup = elm_popup_add(win);
334 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
336 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
337 if (EflAssistHandle) {
338 void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
339 webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
340 (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _data_list_popup_response_cancel_cb, this);
344 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
345 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
346 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
347 evas_object_show(m_pickerLayout->layout);
348 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
350 Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
353 EINA_LIST_FOREACH(optionList, list, listItem) {
355 elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
357 evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
358 evas_object_show(elmList);
359 elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
361 Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
362 elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
364 m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
365 elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
367 elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
368 elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
369 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
370 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
371 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
373 elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
374 evas_object_show(editFieldLayout);
376 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
377 elm_object_style_set(m_pickerLayout->okButton, "popup");
378 elm_object_text_set(m_pickerLayout->okButton, "OK");
379 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
380 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
381 evas_object_show(m_pickerLayout->popup);
382 evas_object_focus_set(m_pickerLayout->okButton, true);
384 Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
385 elm_object_style_set(cancelButton, "popup");
386 elm_object_text_set(cancelButton, "Cancel");
387 elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
388 evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
389 evas_object_show(cancelButton);
392 void InputPicker::hideDataList(Ewk_Input_Type inputType)
397 if(m_pickerLayout->popup){
398 evas_object_del(m_pickerLayout->popup);
399 m_pickerLayout->popup = 0;
402 delete m_pickerLayout;
409 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
410 void InputPicker::showColorPicker(int r, int g, int b, int)
412 m_isColorPickerShown = true;
413 ewk_color_popup(r, g, b);
416 void InputPicker::hideColorPicker()
418 m_isColorPickerShown = false;
422 if (m_pickerLayout->popup) {
423 evas_object_del(m_pickerLayout->popup);
424 m_pickerLayout->popup = 0;
427 delete m_pickerLayout;
432 #if ENABLE(ELM_COLORPALLETE)
433 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
439 Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
440 elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
441 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
445 void InputPicker::colorKeyDownCallback(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
447 Evas_Event_Key_Down *event = (Evas_Event_Key_Down *)eventInfo;
448 if (!strncmp("Return", event->keyname, 6) || !strncmp("space", event->keyname, 5)) {
449 ColorPopupUserData* colorData = static_cast<ColorPopupUserData*>(data);
450 colorData->inputPicker->_color_selected_cb(data, 0, 0, 0);
454 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
461 ColorPopupUserData* colorData = static_cast<ColorPopupUserData*>(data);
462 evas_object_color_get(colorData->color, &r, &g, &b, &a);
463 evas_object_color_set(colorData->colorRect, r, g, b, a);
464 elm_object_focus_set(colorData->colorAccessObject, true);
467 void InputPicker::addColorRect(const char* part, int r, int g, int b, ColorPopupUserData* colorData)
469 Evas_Object* color = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
470 evas_object_size_hint_weight_set(color, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
471 evas_object_color_set(color, r, g, b, 255);
472 elm_object_part_content_set(m_pickerLayout->layout, part, color);
473 evas_object_show(color);
475 Evas_Object* accessObject = elm_access_object_register(color, m_pickerLayout->layout);
476 elm_object_focus_custom_chain_append(m_pickerLayout->layout, accessObject, NULL);
478 colorData->inputPicker = this;
479 colorData->colorRect = m_pickerLayout->colorRect;
480 colorData->color = color;
481 colorData->colorAccessObject = accessObject;
483 evas_object_event_callback_add(accessObject, EVAS_CALLBACK_KEY_DOWN, colorKeyDownCallback, colorData);
484 evas_object_event_callback_add(color, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, colorData);
487 void InputPicker::ewk_color_popup(int r, int g, int b)
492 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
494 m_pickerLayout->popup = elm_popup_add(elm_object_parent_widget_get(m_ewkView));
495 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
497 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
498 m_pickerLayout->initial_r = r;
499 m_pickerLayout->initial_g = g;
500 m_pickerLayout->initial_b = b;
501 if (EflAssistHandle) {
502 void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
503 webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
504 (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _color_back_cb, this);
508 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
509 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
510 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
511 evas_object_show(m_pickerLayout->layout);
512 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
514 m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
515 evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
516 evas_object_show(m_pickerLayout->colorRect);
518 evas_object_color_set(m_pickerLayout->colorRect, r, g, b, 255);
519 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
520 #if ENABLE(ELM_COLORPALLETE)
521 Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
522 elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
524 elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
525 elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
526 elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
527 elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
528 elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
529 elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
530 elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
531 elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
532 elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
533 elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
534 elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
535 elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
537 evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
538 evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
539 evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
540 evas_object_show(colorPalette);
542 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
544 static ColorPopupUserData color1Data;
545 addColorRect("elm.swallow.color1", 128, 0, 0, &color1Data);
547 static ColorPopupUserData color2Data;
548 addColorRect("elm.swallow.color2", 255, 0, 128, &color2Data);
550 static ColorPopupUserData color3Data;
551 addColorRect("elm.swallow.color3", 255, 0, 0, &color3Data);
553 static ColorPopupUserData color4Data;
554 addColorRect("elm.swallow.color4", 255, 127, 39, &color4Data);
556 static ColorPopupUserData color5Data;
557 addColorRect("elm.swallow.color5", 255, 255, 0, &color5Data);
559 static ColorPopupUserData color6Data;
560 addColorRect("elm.swallow.color6", 0, 255, 0, &color6Data);
562 static ColorPopupUserData color7Data;
563 addColorRect("elm.swallow.color7", 0, 255, 255, &color7Data);
565 static ColorPopupUserData color8Data;
566 addColorRect("elm.swallow.color8", 0, 0, 255, &color8Data);
568 static ColorPopupUserData color9Data;
569 addColorRect("elm.swallow.color9", 0, 0, 128, &color9Data);
571 static ColorPopupUserData color10Data;
572 addColorRect("elm.swallow.color10", 64, 0, 64, &color10Data);
574 static ColorPopupUserData color11Data;
575 addColorRect("elm.swallow.color11", 153, 217, 234, &color11Data);
577 static ColorPopupUserData color12Data;
578 addColorRect("elm.swallow.color12", 128, 128, 128, &color12Data);
580 static ColorPopupUserData color13Data;
581 addColorRect("elm.swallow.color13", 0, 0, 0, &color13Data);
583 static ColorPopupUserData color14Data;
584 addColorRect("elm.swallow.color14", 255, 255, 255, &color14Data);
586 // Set focus on first color rect.
587 if (color1Data.colorAccessObject)
588 elm_object_focus_set(color1Data.colorAccessObject, true);
590 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
591 elm_object_style_set(m_pickerLayout->okButton, "popup");
592 elm_object_text_set(m_pickerLayout->okButton, "OK");
593 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
594 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
596 evas_object_show(m_pickerLayout->popup);
599 void InputPicker::_color_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
601 InputPicker* inputPicker = static_cast<InputPicker*>(data);
607 evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
609 ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
611 inputPicker->hideColorPicker();
614 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
615 void InputPicker::_color_back_cb(void* data, Evas_Object* obj, void* event_info)
617 InputPicker* inputPicker = static_cast<InputPicker*>(data);
619 int r = inputPicker->m_pickerLayout->initial_r;
620 int g = inputPicker->m_pickerLayout->initial_g;
621 int b = inputPicker->m_pickerLayout->initial_b;
623 ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
625 inputPicker->hideColorPicker();
629 void InputPicker::ewk_date_popup(const char* inputValue)
631 struct tm* currentTime;
634 currentTime = localtime(&cur_time);
636 Input_Date_Str dateStr;
637 memset(&dateStr, 0, sizeof(Input_Date_Str));
639 if (inputValue && strlen(inputValue)) {
640 char tmpinputValue[maxDatetimeLength] = { 0, };
642 snprintf(tmpinputValue, maxDatetimeLength, "%s", inputValue);
643 char* token = strtok(tmpinputValue,"-");
645 strncpy(dateStr.year, token, maxDateStringLength);
646 token = strtok(0, "-");
648 strncpy(dateStr.mon, token, maxDateStringLength);
649 token = strtok(0, "-");
651 strncpy(dateStr.day, token, maxDateStringLength);
654 currentTime->tm_year = atoi(dateStr.year);
656 currentTime->tm_mon = atoi(dateStr.mon);
658 currentTime->tm_mday = atoi(dateStr.day);
660 currentTime->tm_year = currentTime->tm_year - 1900;
661 currentTime->tm_mon = currentTime->tm_mon - 1;
664 if (m_pickerLayout) {
665 // Just update the value.
666 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
667 evas_object_focus_set(m_pickerLayout->okButton, true);
671 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
673 createDatetimePopup("Select date", currentTime);
674 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
675 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
676 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
678 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
679 elm_object_style_set(m_pickerLayout->okButton, "popup");
680 elm_object_text_set(m_pickerLayout->okButton, "OK");
681 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
682 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
683 evas_object_focus_set(m_pickerLayout->okButton, true);
685 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
686 evas_object_show(m_pickerLayout->popup);
689 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
690 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
693 if (totalDays - 31 < 0) {
694 *remains = totalDays;
698 totalDays = totalDays - 31;
701 if (isLeapYear(year)) {
702 if (totalDays - 29 < 0) {
703 *remains = totalDays;
706 totalDays = totalDays - 29;
708 if (totalDays - 28 < 0) {
709 *remains = totalDays;
712 totalDays = totalDays - 28;
716 if (totalDays - 31 < 0) {
717 *remains = totalDays;
720 totalDays = totalDays - 31;
723 if (totalDays - 30 < 0) {
724 *remains = totalDays;
727 totalDays = totalDays - 30;
730 if (totalDays - 31 < 0) {
731 *remains = totalDays;
734 totalDays = totalDays - 31;
737 if (totalDays - 30 < 0) {
738 *remains = totalDays;
741 totalDays = totalDays - 30;
744 if (totalDays - 31 < 0) {
745 *remains = totalDays;
748 totalDays = totalDays - 31;
751 if (totalDays - 31 < 0) {
752 *remains = totalDays;
755 totalDays = totalDays - 31;
758 if (totalDays - 30 < 0) {
759 *remains = totalDays;
762 totalDays = totalDays - 30;
765 if (totalDays - 31 < 0) {
766 *remains = totalDays;
769 totalDays = totalDays - 31;
772 if (totalDays - 30 < 0) {
773 *remains = totalDays;
776 totalDays = totalDays - 30;
778 *remains = totalDays;
782 void InputPicker::ewk_week_popup(const char* inputValue)
784 struct tm* currentTime;
787 currentTime = localtime(&cur_time);
789 Input_Date_Str dateStr;
790 memset(&dateStr, 0, sizeof(Input_Date_Str));
792 if (inputValue && strlen(inputValue)) {
793 char tmpinputValue[maxDatetimeLength] = { 0, };
795 snprintf(tmpinputValue, maxDatetimeLength, "%s", inputValue);
796 char* token = strtok(tmpinputValue,"-");
798 strncpy(dateStr.year, token, maxDateStringLength);
799 const char* week = strstr(inputValue, "W");
802 weekNum = atoi(week + 1);
805 currentTime->tm_year = atoi(dateStr.year);
806 currentTime->tm_year = currentTime->tm_year - 1900;
808 struct tm firtTimeOfyear;
809 memset(&firtTimeOfyear, 0, sizeof(struct tm));
810 firtTimeOfyear.tm_year = currentTime->tm_year;
811 firtTimeOfyear.tm_mon = 0;
812 firtTimeOfyear.tm_mday = 1;
813 mktime(&firtTimeOfyear);
815 char firstWeek[10] = {0, };
816 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
817 int firstWeekCount = atoi(firstWeek);
821 totalDays = weekNum * 7 - firstWeekCount;
824 int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
826 currentTime->tm_mon = month;
827 currentTime->tm_mday = days;
830 if (m_pickerLayout) {
831 // Just update the value.
832 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
833 evas_object_focus_set(m_pickerLayout->okButton, true);
837 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
839 createDatetimePopup("Select date", currentTime);
840 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
841 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
842 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
844 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
845 elm_object_style_set(m_pickerLayout->okButton, "popup");
846 elm_object_text_set(m_pickerLayout->okButton, "OK");
847 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
848 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
849 evas_object_focus_set(m_pickerLayout->okButton, true);
851 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
852 evas_object_show(m_pickerLayout->popup);
855 void InputPicker::ewk_time_popup(const char* inputValue)
857 struct tm* currentTime;
860 currentTime = localtime(&cur_time);
862 Input_Date_Str dateStr;
863 memset(&dateStr, 0, sizeof(Input_Date_Str));
865 if (inputValue && strlen(inputValue)) {
866 char tmpinputValue[maxDatetimeLength] = { 0, };
868 snprintf(tmpinputValue, maxDatetimeLength, "%s", inputValue);
869 char* token = strtok(tmpinputValue,":");
871 strncpy(dateStr.hour, token, maxDateStringLength);
872 token = strtok(0, ":");
874 strncpy(dateStr.min, token, maxDateStringLength);
877 currentTime->tm_hour = atoi(dateStr.hour);
879 currentTime->tm_min = atoi(dateStr.min);
882 if (m_pickerLayout) {
883 // Just update the value.
884 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
885 evas_object_focus_set(m_pickerLayout->okButton, true);
889 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
891 createDatetimePopup("Select time", currentTime);
892 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_YEAR, EINA_FALSE);
893 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MONTH, EINA_FALSE);
894 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_DATE, EINA_FALSE);
896 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
897 elm_object_style_set(m_pickerLayout->okButton, "popup");
898 elm_object_text_set(m_pickerLayout->okButton, "OK");
899 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
900 evas_object_focus_set(m_pickerLayout->okButton, true);
902 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
903 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
904 evas_object_show(m_pickerLayout->popup);
907 void InputPicker::ewk_month_popup(const char* inputValue)
909 struct tm* currentTime;
912 currentTime = localtime(&cur_time);
914 Input_Date_Str dateStr;
915 memset(&dateStr, 0, sizeof(Input_Date_Str));
917 if (inputValue && strlen(inputValue)) {
918 char tmpInputValue[maxDatetimeLength] = { 0, };
920 snprintf(tmpInputValue, maxDatetimeLength, "%s", inputValue);
921 char* token = strtok(tmpInputValue,"-");
923 strncpy(dateStr.year, token, maxDateStringLength);
924 token = strtok(0, "-");
926 strncpy(dateStr.mon, token, maxDateStringLength);
929 currentTime->tm_year = atoi(dateStr.year);
931 currentTime->tm_mon = atoi(dateStr.mon);
933 currentTime->tm_year = currentTime->tm_year - 1900;
934 currentTime->tm_mon = currentTime->tm_mon - 1;
937 if (m_pickerLayout) {
938 // Just update the value.
939 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
940 evas_object_focus_set(m_pickerLayout->okButton, true);
944 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
946 createDatetimePopup("Select month", currentTime);
947 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_DATE, EINA_FALSE);
948 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
949 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
950 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
952 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
953 elm_object_style_set(m_pickerLayout->okButton, "popup");
954 elm_object_text_set(m_pickerLayout->okButton, "OK");
955 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
956 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
957 evas_object_focus_set(m_pickerLayout->okButton, true);
959 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
960 evas_object_show(m_pickerLayout->popup);
963 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
965 struct tm* currentTime;
968 currentTime = localtime(&cur_time);
970 Input_Date_Str dateStr;
971 memset(&dateStr, 0, sizeof(Input_Date_Str));
973 if (inputValue && strlen(inputValue)) {
974 char tmpInputValue[maxDatetimeLength] = { 0, };
976 snprintf(tmpInputValue, maxDatetimeLength, "%s", inputValue);
977 char* token = strtok(tmpInputValue,"-");
979 strncpy(dateStr.year, token, maxDateStringLength);
980 token = strtok(0, "-");
982 strncpy(dateStr.mon, token, maxDateStringLength);
983 token = strtok(0, "T");
985 strncpy(dateStr.day, token, maxDateStringLength);
986 token = strtok(0, ":");
988 strncpy(dateStr.hour, token, maxDateStringLength);
991 token = strtok(0, "Z");
993 strncpy(dateStr.min, token, maxDateStringLength);
995 token = strtok(0, ":");
997 strncpy(dateStr.min, token, maxDateStringLength);
1001 currentTime->tm_year = atoi(dateStr.year);
1003 currentTime->tm_mon = atoi(dateStr.mon);
1005 currentTime->tm_mday = atoi(dateStr.day);
1007 currentTime->tm_hour = atoi(dateStr.hour);
1009 currentTime->tm_min = atoi(dateStr.min);
1011 currentTime->tm_year = currentTime->tm_year - 1900;
1012 currentTime->tm_mon = currentTime->tm_mon - 1;
1015 if (m_pickerLayout) {
1016 // Just update the value.
1017 m_pickerLayout->datetimeLocal = local;
1019 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1020 evas_object_focus_set(m_pickerLayout->okButton, true);
1024 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
1026 m_pickerLayout->datetimeLocal = local;
1028 createDatetimePopup("Select datetime", currentTime);
1030 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1031 elm_object_style_set(m_pickerLayout->okButton, "popup");
1032 elm_object_text_set(m_pickerLayout->okButton, "OK");
1033 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1034 evas_object_focus_set(m_pickerLayout->okButton, true);
1036 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1037 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1038 evas_object_show(m_pickerLayout->popup);
1042 void InputPicker::createDatetimePopup(const char* title, struct tm* currentTime)
1044 m_pickerLayout->popup = elm_popup_add(elm_object_parent_widget_get(m_ewkView));
1045 evas_object_size_hint_weight_set(m_pickerLayout->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1046 elm_object_part_text_set(m_pickerLayout->popup, "title,text", title);
1048 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1049 if (EflAssistHandle) {
1050 void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
1051 webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
1052 (*webkit_ea_object_event_callback_add)(m_pickerLayout->popup, EA_CALLBACK_BACK, _popup_back_cb, this);
1056 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
1057 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datetime_popup");
1058 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1060 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
1061 elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.datetime", m_pickerLayout->datePicker);
1063 char* format = datetimeFormat();
1065 elm_datetime_format_set(m_pickerLayout->datePicker, format);
1068 elm_datetime_format_set(m_pickerLayout->datePicker, defaultDatetimeFormat);
1070 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
1072 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1073 evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,start", _edit_start_cb, 0);
1074 evas_object_smart_callback_add(m_pickerLayout->datePicker, "edit,end", _edit_end_cb, m_pickerLayout);
1078 void InputPicker::deletePopupLayout()
1080 if(m_pickerLayout->popup){
1081 evas_object_del(m_pickerLayout->popup);
1082 m_pickerLayout->popup = 0;
1086 void InputPicker::_date_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1088 struct tm currentTime;
1089 memset(¤tTime, 0, sizeof(struct tm));
1091 char dateStr[20] = {0, };
1093 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1095 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1097 date.day = currentTime.tm_mday;
1098 date.mon = currentTime.tm_mon;
1099 date.year = currentTime.tm_year;
1101 date.year = 1900 + date.year;
1102 sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1104 ewk_view_current_target_input_element_value_set(inputPicker->m_ewkView, dateStr);
1105 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1107 inputPicker->deletePopupLayout();
1108 delete inputPicker->m_pickerLayout;
1109 inputPicker->m_pickerLayout = 0;
1112 void InputPicker::_week_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1114 struct tm currentTime;
1115 memset(¤tTime, 0, sizeof(struct tm));
1117 char dateStr[20] = {0, };
1119 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1121 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1123 date.day = currentTime.tm_mday;
1124 date.mon = currentTime.tm_mon;
1125 date.year = currentTime.tm_year;
1126 mktime(¤tTime);
1128 struct tm firtTimeOfyear;
1129 memset(&firtTimeOfyear, 0, sizeof(struct tm));
1130 firtTimeOfyear.tm_year = date.year;
1131 firtTimeOfyear.tm_mon = 0;
1132 firtTimeOfyear.tm_mday = 1;
1133 mktime(&firtTimeOfyear);
1135 char firstWeek[10] = {0, };
1136 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1137 int firstWeekCount = atoi(firstWeek);
1139 char totalDay[10] = {0, };
1140 strftime(totalDay, 10, "%j", ¤tTime);
1141 int totalDayCount = atoi(totalDay);
1143 int weekNum = (totalDayCount + firstWeekCount) / 7;
1144 if (totalDayCount + firstWeekCount > weekNum * 7)
1147 date.year = 1900 + date.year;
1148 sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1150 ewk_view_current_target_input_element_value_set(inputPicker->m_ewkView, dateStr);
1151 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1153 inputPicker->deletePopupLayout();
1154 delete inputPicker->m_pickerLayout;
1155 inputPicker->m_pickerLayout = 0;
1158 void InputPicker::_time_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1160 struct tm currentTime;
1161 memset(¤tTime, 0, sizeof(struct tm));
1163 char dateStr[20] = {0, };
1165 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1167 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1169 date.hour = currentTime.tm_hour;
1170 date.min = currentTime.tm_min;
1172 sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1173 ewk_view_current_target_input_element_value_set(inputPicker->m_ewkView, dateStr);
1174 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1176 inputPicker->deletePopupLayout();
1177 delete inputPicker->m_pickerLayout;
1178 inputPicker->m_pickerLayout = 0;
1181 void InputPicker::_month_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1183 struct tm currentTime;
1184 memset(¤tTime, 0, sizeof(struct tm));
1186 char dateStr[20] = {0, };
1188 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1190 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1192 date.mon = currentTime.tm_mon;
1193 date.year = currentTime.tm_year;
1195 date.year = 1900 + date.year;
1196 sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1198 ewk_view_current_target_input_element_value_set(inputPicker->m_ewkView, dateStr);
1199 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1201 inputPicker->deletePopupLayout();
1202 delete inputPicker->m_pickerLayout;
1203 inputPicker->m_pickerLayout = 0;
1206 void InputPicker::_datetime_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1208 struct tm currentTime;
1209 memset(¤tTime, 0, sizeof(struct tm));
1211 char dateStr[50] = {0, };
1213 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1215 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1216 date.year = currentTime.tm_year;
1217 date.day = currentTime.tm_mday;
1218 date.mon = currentTime.tm_mon;
1219 date.hour = currentTime.tm_hour;
1220 date.min = currentTime.tm_min;
1222 date.year = 1900 + date.year;
1224 if (inputPicker->m_pickerLayout->datetimeLocal)
1225 sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1227 sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1229 ewk_view_current_target_input_element_value_set(inputPicker->m_ewkView, dateStr);
1230 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1232 inputPicker->deletePopupLayout();
1233 delete inputPicker->m_pickerLayout;
1234 inputPicker->m_pickerLayout = 0;
1237 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
1238 void InputPicker::_popup_back_cb(void* data, Evas_Object* obj, void* event_info)
1240 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1242 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1244 if (!inputPicker->m_pickerLayout)
1247 inputPicker->deletePopupLayout();
1248 delete inputPicker->m_pickerLayout;
1249 inputPicker->m_pickerLayout = 0;
1253 } // namespace WebKit
1255 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)