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>
32 #if OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)
34 Input_Picker_Layout::Input_Picker_Layout(Evas_Object* ewkView)
42 , dataListEditField(0)
43 , datetimeLocal(false)
45 evas_object_focus_set(m_ewkView, false);
46 ewk_view_suspend(m_ewkView);
48 /* FIXME : Workaround. OSP requirement.
49 OSP want to block own touch event while webkit internal picker is running. */
50 evas_object_smart_callback_call(m_ewkView, "input,picker,show", 0);
53 Input_Picker_Layout::~Input_Picker_Layout()
55 /* FIXME : Workaround. OSP requirement.
56 OSP want to block own touch event while webkit internal picker is running. */
57 evas_object_smart_callback_call(m_ewkView, "input,picker,hide", 0);
59 ewk_view_resume(m_ewkView);
64 InputPicker::InputPicker(Evas_Object* ewkView)
68 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
69 , m_isColorPickerShown(false)
74 InputPicker::~InputPicker()
77 if (m_pickerLayout->popup)
78 evas_object_del(m_pickerLayout->popup);
79 delete m_pickerLayout;
83 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
85 if(inputType == EWK_INPUT_TYPE_DATE)
86 ewk_date_popup(inputValue);
87 else if(inputType == EWK_INPUT_TYPE_TIME)
88 ewk_time_popup(inputValue);
89 else if(inputType == EWK_INPUT_TYPE_DATETIME)
90 ewk_datetime_popup(inputValue, false);
91 else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
92 ewk_datetime_popup(inputValue, true);
93 else if(inputType == EWK_INPUT_TYPE_MONTH)
94 ewk_month_popup(inputValue);
95 else if(inputType == EWK_INPUT_TYPE_WEEK)
96 ewk_week_popup(inputValue);
99 #if ENABLE(TIZEN_DATALIST_ELEMENT)
100 void InputPicker::_data_list_popup_response_cb(void* data, Evas_Object* obj, void* eventInfo)
102 InputPicker* inputPicker = static_cast<InputPicker*>(data);
103 const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
104 ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
106 if (inputPicker->m_pickerLayout->popup) {
107 evas_object_del(inputPicker->m_pickerLayout->popup);
108 inputPicker->m_pickerLayout->popup = 0;
111 delete inputPicker->m_pickerLayout;
112 inputPicker->m_pickerLayout = 0;
114 inputPicker->m_dataList = 0;
117 void InputPicker::_data_list_popup_response_cancel_cb(void* data, Evas_Object* obj, void* eventInfo)
119 InputPicker* inputPicker = static_cast<InputPicker*>(data);
121 if (inputPicker->m_pickerLayout->popup) {
122 evas_object_del(inputPicker->m_pickerLayout->popup);
123 inputPicker->m_pickerLayout->popup = 0;
126 delete inputPicker->m_pickerLayout;
127 inputPicker->m_pickerLayout = 0;
129 inputPicker->m_dataList = 0;
132 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
134 InputPicker* inputPicker = static_cast<InputPicker*>(data);
135 Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
136 Elm_Object_Item* item = elm_list_first_item_get(obj);
140 if (item == selectedItem)
143 item = elm_list_item_next(item);
149 EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
150 if (listItem && index == listIndex)
151 elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
157 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
159 Evas_Object* entry = static_cast<Evas_Object*>(data);
160 elm_entry_entry_set(entry, "");
163 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
165 Evas_Object* layout = static_cast<Evas_Object*>(data);
167 if (elm_object_focus_get(layout)) {
168 if (elm_entry_is_empty(obj))
169 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
171 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
175 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
177 Evas_Object* layout = static_cast<Evas_Object*>(data);
179 if (!elm_entry_is_empty(obj))
180 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
183 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
185 Evas_Object* layout = static_cast<Evas_Object*>(data);
186 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
189 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
191 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
192 Evas_Object* win = parent;
194 m_dataList = optionList;
199 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
201 /* FIXME: If the entry is in the popup, the parent should be naviframe for uifw limitation. */
202 Evas_Object* naviframe = elm_naviframe_add(m_ewkView);
204 const char* type = elm_object_widget_type_get(parent);
206 if (!strcmp(type, elm_object_widget_type_get(naviframe))) {
211 parent = elm_object_parent_widget_get(parent);
214 evas_object_del(naviframe);
219 m_pickerLayout->popup = elm_popup_add(win);
220 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
222 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
223 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
224 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
225 evas_object_show(m_pickerLayout->layout);
226 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
228 Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
231 EINA_LIST_FOREACH(optionList, list, listItem) {
233 elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
235 evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
236 evas_object_show(elmList);
237 elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
239 Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
240 elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
242 m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
243 elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
245 elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
246 elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
247 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
248 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
249 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
251 elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
252 evas_object_show(editFieldLayout);
254 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
255 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
256 elm_object_text_set(m_pickerLayout->okButton, "OK");
257 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
258 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
259 evas_object_show(m_pickerLayout->popup);
261 Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
262 elm_object_style_set(cancelButton, "popup_button/default");
263 elm_object_text_set(cancelButton, "Cancel");
264 elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
265 evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
266 evas_object_show(cancelButton);
269 void InputPicker::hideDataList(Ewk_Input_Type inputType)
274 if(m_pickerLayout->popup){
275 evas_object_del(m_pickerLayout->popup);
276 m_pickerLayout->popup = 0;
279 delete m_pickerLayout;
286 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
287 void InputPicker::showColorPicker(int r, int g, int b, int)
289 m_isColorPickerShown = true;
290 ewk_color_popup(r, g, b);
293 void InputPicker::hideColorPicker()
295 m_isColorPickerShown = false;
299 if (m_pickerLayout->popup) {
300 evas_object_del(m_pickerLayout->popup);
301 m_pickerLayout->popup = 0;
304 delete m_pickerLayout;
309 #if ENABLE(ELM_COLORPALLETE)
310 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
316 Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
317 elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
318 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
322 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
328 evas_object_color_get(obj, &r, &g, &b, &a);
330 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
333 void InputPicker::ewk_color_popup(int r, int g, int b)
335 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
336 Evas_Object* win = parent;
341 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
344 const char* type = elm_object_widget_type_get(parent);
346 if (!strcmp(type, "elm_win")) {
351 parent = elm_object_parent_widget_get(parent);
357 m_pickerLayout->popup = elm_popup_add(win);
358 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
360 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
361 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
362 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
363 evas_object_show(m_pickerLayout->layout);
364 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
366 m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
367 evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
368 evas_object_show(m_pickerLayout->colorRect);
370 printf("\n<<<<<<<< r = [%d], g = [%d], b = [%d] >>>>>>>>>>\n", r, g, b);
372 evas_object_color_set(m_pickerLayout->colorRect, r, g, b, 255);
373 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
374 #if ENABLE(ELM_COLORPALLETE)
375 Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
376 elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
378 elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
379 elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
380 elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
381 elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
382 elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
383 elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
384 elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
385 elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
386 elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
387 elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
388 elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
389 elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
391 evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
392 evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
393 evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
394 evas_object_show(colorPalette);
396 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
398 Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
399 evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
400 evas_object_color_set(color1, 128, 0, 0, 255);
401 evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
402 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
403 evas_object_show(color1);
405 Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
406 evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
407 evas_object_color_set(color2, 255, 0, 128, 255);
408 evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
409 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
410 evas_object_show(color2);
412 Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
413 evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
414 evas_object_color_set(color3, 255, 0, 0, 255);
415 evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
416 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
417 evas_object_show(color3);
419 Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
420 evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
421 evas_object_color_set(color4, 255, 127, 39, 255);
422 evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
423 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
424 evas_object_show(color4);
426 Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
427 evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
428 evas_object_color_set(color5, 255, 255, 0, 255);
429 evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
430 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
431 evas_object_show(color5);
433 Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
434 evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
435 evas_object_color_set(color6, 0, 255, 0, 255);
436 evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
437 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
438 evas_object_show(color6);
440 Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
441 evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
442 evas_object_color_set(color7, 0, 255, 255, 255);
443 evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
444 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
445 evas_object_show(color7);
447 Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
448 evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
449 evas_object_color_set(color8, 0, 0, 255, 255);
450 evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
451 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
452 evas_object_show(color8);
454 Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
455 evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
456 evas_object_color_set(color9, 0, 0, 128, 255);
457 evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
458 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
459 evas_object_show(color9);
461 Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
462 evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
463 evas_object_color_set(color10, 64, 0, 64, 255);
464 evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
465 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
466 evas_object_show(color10);
468 Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
469 evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
470 evas_object_color_set(color11, 153, 217, 234, 255);
471 evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
472 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
473 evas_object_show(color11);
475 Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
476 evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
477 evas_object_color_set(color12, 128, 128, 128, 255);
478 evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
479 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
480 evas_object_show(color12);
482 Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
483 evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
484 evas_object_color_set(color13, 0, 0, 0, 255);
485 evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
486 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
487 evas_object_show(color13);
489 Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
490 evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
491 evas_object_color_set(color14, 255, 255, 255, 255);
492 evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
493 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
494 evas_object_show(color14);
496 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
497 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
498 elm_object_text_set(m_pickerLayout->okButton, "OK");
499 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
500 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
502 evas_object_show(m_pickerLayout->popup);
505 void InputPicker::_color_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
507 InputPicker* inputPicker = static_cast<InputPicker*>(data);
513 evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
515 ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
517 inputPicker->hideColorPicker();
520 void InputPicker::ewk_date_popup(const char* inputValue)
522 struct tm* currentTime;
525 currentTime = localtime(&cur_time);
527 Input_Date_Str dateStr;
528 memset(&dateStr, 0, sizeof(Input_Date_Str));
530 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
531 Evas_Object* win = parent;
536 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
538 if (inputValue && strlen(inputValue)) {
539 char tmpinputValue[30] = {0,};
541 sprintf(tmpinputValue, "%s", inputValue);
542 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
543 strcpy(dateStr.mon, strtok(0, "-"));
544 strcpy(dateStr.day, strtok(0, "-"));
546 currentTime->tm_year = atoi(dateStr.year);
547 currentTime->tm_mon = atoi(dateStr.mon);
548 currentTime->tm_mday = atoi(dateStr.day);
550 currentTime->tm_year = currentTime->tm_year - 1900;
551 currentTime->tm_mon = currentTime->tm_mon - 1;
555 const char* type = elm_object_widget_type_get(parent);
557 if (!strcmp(type, "elm_win")) {
562 parent = elm_object_parent_widget_get(parent);
568 m_pickerLayout->popup = elm_popup_add(win);
569 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
571 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
572 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
573 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
575 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
577 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
578 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
580 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
581 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
582 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
583 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
585 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
586 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
587 elm_object_text_set(m_pickerLayout->okButton, "OK");
588 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
589 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
591 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
592 evas_object_show(m_pickerLayout->popup);
595 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
596 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
599 if (totalDays - 31 < 0) {
600 *remains = totalDays;
604 totalDays = totalDays - 31;
607 if (isLeapYear(year)) {
608 if (totalDays - 29 < 0) {
609 *remains = totalDays;
612 totalDays = totalDays - 29;
614 if (totalDays - 28 < 0) {
615 *remains = totalDays;
618 totalDays = totalDays - 28;
622 if (totalDays - 31 < 0) {
623 *remains = totalDays;
626 totalDays = totalDays - 31;
629 if (totalDays - 30 < 0) {
630 *remains = totalDays;
633 totalDays = totalDays - 30;
636 if (totalDays - 31 < 0) {
637 *remains = totalDays;
640 totalDays = totalDays - 31;
643 if (totalDays - 30 < 0) {
644 *remains = totalDays;
647 totalDays = totalDays - 30;
650 if (totalDays - 31 < 0) {
651 *remains = totalDays;
654 totalDays = totalDays - 31;
657 if (totalDays - 31 < 0) {
658 *remains = totalDays;
661 totalDays = totalDays - 31;
664 if (totalDays - 30 < 0) {
665 *remains = totalDays;
668 totalDays = totalDays - 30;
671 if (totalDays - 31 < 0) {
672 *remains = totalDays;
675 totalDays = totalDays - 31;
678 if (totalDays - 30 < 0) {
679 *remains = totalDays;
682 totalDays = totalDays - 30;
684 *remains = totalDays;
688 void InputPicker::ewk_week_popup(const char* inputValue)
690 struct tm* currentTime;
693 currentTime = localtime(&cur_time);
695 Input_Date_Str dateStr;
696 memset(&dateStr, 0, sizeof(Input_Date_Str));
698 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
699 Evas_Object* win = parent;
704 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
706 if (inputValue && strlen(inputValue)) {
707 char tmpinputValue[30] = {0,};
709 sprintf(tmpinputValue, "%s", inputValue);
710 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
711 const char* week = strstr(inputValue, "W");
714 weekNum = atoi(week + 1);
716 currentTime->tm_year = atoi(dateStr.year);
717 currentTime->tm_year = currentTime->tm_year - 1900;
719 struct tm firtTimeOfyear;
720 memset(&firtTimeOfyear, 0, sizeof(struct tm));
721 firtTimeOfyear.tm_year = currentTime->tm_year;
722 firtTimeOfyear.tm_mon = 0;
723 firtTimeOfyear.tm_mday = 1;
724 mktime(&firtTimeOfyear);
726 char firstWeek[10] = {0, };
727 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
728 int firstWeekCount = atoi(firstWeek);
732 totalDays = weekNum * 7 - firstWeekCount;
735 int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
737 currentTime->tm_mon = month;
738 currentTime->tm_mday = days;
742 const char* type = elm_object_widget_type_get(parent);
744 if (!strcmp(type, "elm_win")) {
749 parent = elm_object_parent_widget_get(parent);
755 m_pickerLayout->popup = elm_popup_add(win);
756 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
758 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
759 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
760 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
762 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
764 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
765 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
767 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
768 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
769 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
770 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
772 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
773 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
774 elm_object_text_set(m_pickerLayout->okButton, "OK");
775 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
776 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
778 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
779 evas_object_show(m_pickerLayout->popup);
782 void InputPicker::ewk_time_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 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
793 Evas_Object* win = parent;
798 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
800 if (inputValue && strlen(inputValue)) {
801 char tmpinputValue[30] = {0,};
803 sprintf(tmpinputValue, "%s", inputValue);
804 strcpy(dateStr.hour, strtok(tmpinputValue,":"));
805 strcpy(dateStr.min, strtok(0, ":"));
807 currentTime->tm_hour = atoi(dateStr.hour);
808 currentTime->tm_min = atoi(dateStr.min);
812 const char* type = elm_object_widget_type_get(parent);
814 if (!strcmp(type, "elm_win")) {
819 parent = elm_object_parent_widget_get(parent);
825 m_pickerLayout->popup = elm_popup_add(win);
826 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
828 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
829 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
830 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
832 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
834 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
835 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
836 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
838 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
840 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
841 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
842 elm_object_text_set(m_pickerLayout->okButton, "OK");
843 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
845 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
846 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
847 evas_object_show(m_pickerLayout->popup);
850 void InputPicker::ewk_month_popup(const char* inputValue)
852 struct tm* currentTime;
855 currentTime = localtime(&cur_time);
857 Input_Date_Str dateStr;
858 memset(&dateStr, 0, sizeof(Input_Date_Str));
860 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
861 Evas_Object* win = parent;
866 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
868 if (inputValue && strlen(inputValue)) {
869 char tmpInputValue[30] = {0,};
871 sprintf(tmpInputValue, "%s", inputValue);
872 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
873 strcpy(dateStr.mon, strtok(0, "-"));
875 currentTime->tm_year = atoi(dateStr.year);
876 currentTime->tm_mon = atoi(dateStr.mon);
878 currentTime->tm_year = currentTime->tm_year - 1900;
879 currentTime->tm_mon = currentTime->tm_mon - 1;
883 const char* type = elm_object_widget_type_get(parent);
885 if (!strcmp(type, "elm_win")) {
890 parent = elm_object_parent_widget_get(parent);
896 m_pickerLayout->popup = elm_popup_add(win);
898 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
900 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
901 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
903 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
904 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
906 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
908 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Month (Default format) :");
910 elm_datetime_format_set(m_pickerLayout->datePicker, "%Y %m");
911 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
913 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
914 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
915 elm_object_text_set(m_pickerLayout->okButton, "OK");
916 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
917 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
919 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
920 evas_object_show(m_pickerLayout->popup);
923 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
925 struct tm* currentTime;
928 currentTime = localtime(&cur_time);
930 Input_Date_Str dateStr;
931 memset(&dateStr, 0, sizeof(Input_Date_Str));
933 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
934 Evas_Object* win = parent;
939 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
941 m_pickerLayout->datetimeLocal = local;
943 if (inputValue && strlen(inputValue)) {
944 char tmpInputValue[30] = {0, };
946 sprintf(tmpInputValue, "%s", inputValue);
947 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
948 strcpy(dateStr.mon, strtok(0, "-"));
949 strcpy(dateStr.day, strtok(0, "T"));
950 strcpy(dateStr.hour, strtok(0, ":"));
952 if (m_pickerLayout->datetimeLocal)
953 strcpy(dateStr.min, strtok(0, "Z"));
955 strcpy(dateStr.min, strtok(0, ":"));
957 currentTime->tm_year = atoi(dateStr.year);
958 currentTime->tm_mon = atoi(dateStr.mon);
959 currentTime->tm_mday = atoi(dateStr.day);
960 currentTime->tm_hour = atoi(dateStr.hour);
961 currentTime->tm_min = atoi(dateStr.min);
963 currentTime->tm_year = currentTime->tm_year - 1900;
964 currentTime->tm_mon = currentTime->tm_mon - 1;
968 const char* type = elm_object_widget_type_get(parent);
970 if (!strcmp(type, "elm_win")) {
975 parent = elm_object_parent_widget_get(parent);
981 m_pickerLayout->popup = elm_popup_add(win);
982 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
984 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
985 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
986 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
988 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
989 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
991 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
992 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
993 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
994 elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
996 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
997 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
998 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
999 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
1001 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
1002 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
1003 elm_object_text_set(m_pickerLayout->okButton, "OK");
1004 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1006 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1007 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1008 evas_object_show(m_pickerLayout->popup);
1012 void InputPicker::_date_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1014 struct tm currentTime;
1015 memset(¤tTime, 0, sizeof(struct tm));
1017 char dateStr[20] = {0, };
1019 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1021 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1023 date.day = currentTime.tm_mday;
1024 date.mon = currentTime.tm_mon;
1025 date.year = currentTime.tm_year;
1027 if(inputPicker->m_pickerLayout->popup){
1028 evas_object_del(inputPicker->m_pickerLayout->popup);
1029 inputPicker->m_pickerLayout->popup = 0;
1032 date.year = 1900 + date.year;
1033 sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1035 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1036 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1038 delete inputPicker->m_pickerLayout;
1039 inputPicker->m_pickerLayout = 0;
1042 void InputPicker::_week_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1044 struct tm currentTime;
1045 memset(¤tTime, 0, sizeof(struct tm));
1047 char dateStr[20] = {0, };
1049 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1051 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1053 date.day = currentTime.tm_mday;
1054 date.mon = currentTime.tm_mon;
1055 date.year = currentTime.tm_year;
1056 mktime(¤tTime);
1058 if(inputPicker->m_pickerLayout->popup){
1059 evas_object_del(inputPicker->m_pickerLayout->popup);
1060 inputPicker->m_pickerLayout->popup = 0;
1063 struct tm firtTimeOfyear;
1064 memset(&firtTimeOfyear, 0, sizeof(struct tm));
1065 firtTimeOfyear.tm_year = date.year;
1066 firtTimeOfyear.tm_mon = 0;
1067 firtTimeOfyear.tm_mday = 1;
1068 mktime(&firtTimeOfyear);
1070 char firstWeek[10] = {0, };
1071 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1072 int firstWeekCount = atoi(firstWeek);
1074 char totalDay[10] = {0, };
1075 strftime(totalDay, 10, "%j", ¤tTime);
1076 int totalDayCount = atoi(totalDay);
1078 int weekNum = (totalDayCount + firstWeekCount) / 7;
1079 if (totalDayCount + firstWeekCount > weekNum * 7)
1082 date.year = 1900 + date.year;
1083 sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1085 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1086 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1088 delete inputPicker->m_pickerLayout;
1089 inputPicker->m_pickerLayout = 0;
1092 void InputPicker::_time_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1094 struct tm currentTime;
1095 memset(¤tTime, 0, sizeof(struct tm));
1097 char dateStr[20] = {0, };
1099 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1101 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1103 date.hour = currentTime.tm_hour;
1104 date.min = currentTime.tm_min;
1106 if(inputPicker->m_pickerLayout->popup){
1107 evas_object_del(inputPicker->m_pickerLayout->popup);
1108 inputPicker->m_pickerLayout->popup = 0;
1111 sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1112 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1113 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1115 delete inputPicker->m_pickerLayout;
1116 inputPicker->m_pickerLayout = 0;
1119 void InputPicker::_month_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1121 struct tm currentTime;
1122 memset(¤tTime, 0, sizeof(struct tm));
1124 char dateStr[20] = {0, };
1126 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1128 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1130 date.mon = currentTime.tm_mon;
1131 date.year = currentTime.tm_year;
1133 if(inputPicker->m_pickerLayout->popup){
1134 evas_object_del(inputPicker->m_pickerLayout->popup);
1135 inputPicker->m_pickerLayout->popup = 0;
1138 date.year = 1900 + date.year;
1139 sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1141 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1142 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1144 delete inputPicker->m_pickerLayout;
1145 inputPicker->m_pickerLayout = 0;
1148 void InputPicker::_datetime_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1150 struct tm currentTime;
1151 memset(¤tTime, 0, sizeof(struct tm));
1153 char dateStr[50] = {0, };
1155 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1157 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1158 date.year = currentTime.tm_year;
1159 date.day = currentTime.tm_mday;
1160 date.mon = currentTime.tm_mon;
1162 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1163 date.hour = currentTime.tm_hour;
1164 date.min = currentTime.tm_min;
1166 if (inputPicker->m_pickerLayout->popup) {
1167 evas_object_del(inputPicker->m_pickerLayout->popup);
1168 inputPicker->m_pickerLayout->popup = 0;
1171 date.year = 1900 + date.year;
1173 if (inputPicker->m_pickerLayout->datetimeLocal)
1174 sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1176 sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1178 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1179 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1181 delete inputPicker->m_pickerLayout;
1182 inputPicker->m_pickerLayout = 0;
1185 } // namespace WebKit
1187 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)