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)
71 InputPicker::~InputPicker()
74 if (m_pickerLayout->popup)
75 evas_object_del(m_pickerLayout->popup);
76 delete m_pickerLayout;
80 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
82 if(inputType == EWK_INPUT_TYPE_DATE)
83 ewk_date_popup(inputValue);
84 else if(inputType == EWK_INPUT_TYPE_TIME)
85 ewk_time_popup(inputValue);
86 else if(inputType == EWK_INPUT_TYPE_DATETIME)
87 ewk_datetime_popup(inputValue, false);
88 else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
89 ewk_datetime_popup(inputValue, true);
90 else if(inputType == EWK_INPUT_TYPE_MONTH)
91 ewk_month_popup(inputValue);
92 else if(inputType == EWK_INPUT_TYPE_WEEK)
93 ewk_week_popup(inputValue);
96 #if ENABLE(TIZEN_DATALIST_ELEMENT)
97 void InputPicker::_data_list_popup_response_cb(void* data, Evas_Object* obj, void* eventInfo)
99 InputPicker* inputPicker = static_cast<InputPicker*>(data);
100 const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
101 ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
103 if (inputPicker->m_pickerLayout->popup) {
104 evas_object_del(inputPicker->m_pickerLayout->popup);
105 inputPicker->m_pickerLayout->popup = 0;
108 delete inputPicker->m_pickerLayout;
109 inputPicker->m_pickerLayout = 0;
111 inputPicker->m_dataList = 0;
114 void InputPicker::_data_list_popup_response_cancel_cb(void* data, Evas_Object* obj, void* eventInfo)
116 InputPicker* inputPicker = static_cast<InputPicker*>(data);
118 if (inputPicker->m_pickerLayout->popup) {
119 evas_object_del(inputPicker->m_pickerLayout->popup);
120 inputPicker->m_pickerLayout->popup = 0;
123 delete inputPicker->m_pickerLayout;
124 inputPicker->m_pickerLayout = 0;
126 inputPicker->m_dataList = 0;
129 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
131 InputPicker* inputPicker = static_cast<InputPicker*>(data);
132 Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
133 Elm_Object_Item* item = elm_list_first_item_get(obj);
137 if (item == selectedItem)
140 item = elm_list_item_next(item);
146 EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
147 if (listItem && index == listIndex)
148 elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
154 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
156 Evas_Object* entry = static_cast<Evas_Object*>(data);
157 elm_entry_entry_set(entry, "");
160 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
162 Evas_Object* layout = static_cast<Evas_Object*>(data);
164 if (elm_object_focus_get(layout)) {
165 if (elm_entry_is_empty(obj))
166 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
168 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
172 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
174 Evas_Object* layout = static_cast<Evas_Object*>(data);
176 if (!elm_entry_is_empty(obj))
177 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
180 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
182 Evas_Object* layout = static_cast<Evas_Object*>(data);
183 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
186 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
188 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
189 Evas_Object* win = parent;
191 m_dataList = optionList;
196 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
198 /* FIXME: If the entry is in the popup, the parent should be naviframe for uifw limitation. */
199 Evas_Object* naviframe = elm_naviframe_add(m_ewkView);
201 const char* type = elm_object_widget_type_get(parent);
203 if (!strcmp(type, elm_object_widget_type_get(naviframe))) {
208 parent = elm_object_parent_widget_get(parent);
211 evas_object_del(naviframe);
216 m_pickerLayout->popup = elm_popup_add(win);
217 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
219 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
220 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
221 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
222 evas_object_show(m_pickerLayout->layout);
223 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
225 Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
228 EINA_LIST_FOREACH(optionList, list, listItem) {
230 elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
232 evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
233 evas_object_show(elmList);
234 elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
236 Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
237 elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
239 m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
240 elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
242 elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
243 elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
244 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
245 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
246 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
248 elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
249 evas_object_show(editFieldLayout);
251 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
252 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
253 elm_object_text_set(m_pickerLayout->okButton, "OK");
254 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
255 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
256 evas_object_show(m_pickerLayout->popup);
258 Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
259 elm_object_style_set(cancelButton, "popup_button/default");
260 elm_object_text_set(cancelButton, "Cancel");
261 elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
262 evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
263 evas_object_show(cancelButton);
266 void InputPicker::hideDataList(Ewk_Input_Type inputType)
271 if(m_pickerLayout->popup){
272 evas_object_del(m_pickerLayout->popup);
273 m_pickerLayout->popup = 0;
276 delete m_pickerLayout;
283 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
284 void InputPicker::showColorPicker(int r, int g, int b, int)
286 ewk_color_popup(r, g, b);
289 void InputPicker::hideColorPicker()
294 if (m_pickerLayout->popup) {
295 evas_object_del(m_pickerLayout->popup);
296 m_pickerLayout->popup = 0;
299 delete m_pickerLayout;
304 #if ENABLE(ELM_COLORPALLETE)
305 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
311 Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
312 elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
313 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
317 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
323 evas_object_color_get(obj, &r, &g, &b, &a);
325 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
328 void InputPicker::ewk_color_popup(int r, int g, int b)
330 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
331 Evas_Object* win = parent;
336 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
339 const char* type = elm_object_widget_type_get(parent);
341 if (!strcmp(type, "elm_win")) {
346 parent = elm_object_parent_widget_get(parent);
352 m_pickerLayout->popup = elm_popup_add(win);
353 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
355 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
356 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
357 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
358 evas_object_show(m_pickerLayout->layout);
359 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
361 m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
362 evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
363 evas_object_show(m_pickerLayout->colorRect);
365 printf("\n<<<<<<<< r = [%d], g = [%d], b = [%d] >>>>>>>>>>\n", r, g, b);
367 evas_object_color_set(m_pickerLayout->colorRect, r, g, b, 255);
368 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
369 #if ENABLE(ELM_COLORPALLETE)
370 Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
371 elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
373 elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
374 elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
375 elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
376 elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
377 elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
378 elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
379 elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
380 elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
381 elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
382 elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
383 elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
384 elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
386 evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
387 evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
388 evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
389 evas_object_show(colorPalette);
391 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
393 Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
394 evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
395 evas_object_color_set(color1, 128, 0, 0, 255);
396 evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
397 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
398 evas_object_show(color1);
400 Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
401 evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
402 evas_object_color_set(color2, 255, 0, 128, 255);
403 evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
404 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
405 evas_object_show(color2);
407 Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
408 evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
409 evas_object_color_set(color3, 255, 0, 0, 255);
410 evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
411 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
412 evas_object_show(color3);
414 Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
415 evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
416 evas_object_color_set(color4, 255, 127, 39, 255);
417 evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
418 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
419 evas_object_show(color4);
421 Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
422 evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
423 evas_object_color_set(color5, 255, 255, 0, 255);
424 evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
425 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
426 evas_object_show(color5);
428 Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
429 evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
430 evas_object_color_set(color6, 0, 255, 0, 255);
431 evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
432 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
433 evas_object_show(color6);
435 Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
436 evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
437 evas_object_color_set(color7, 0, 255, 255, 255);
438 evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
439 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
440 evas_object_show(color7);
442 Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
443 evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
444 evas_object_color_set(color8, 0, 0, 255, 255);
445 evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
446 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
447 evas_object_show(color8);
449 Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
450 evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
451 evas_object_color_set(color9, 0, 0, 128, 255);
452 evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
453 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
454 evas_object_show(color9);
456 Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
457 evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
458 evas_object_color_set(color10, 64, 0, 64, 255);
459 evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
460 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
461 evas_object_show(color10);
463 Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
464 evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
465 evas_object_color_set(color11, 153, 217, 234, 255);
466 evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
467 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
468 evas_object_show(color11);
470 Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
471 evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
472 evas_object_color_set(color12, 128, 128, 128, 255);
473 evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
474 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
475 evas_object_show(color12);
477 Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
478 evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
479 evas_object_color_set(color13, 0, 0, 0, 255);
480 evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
481 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
482 evas_object_show(color13);
484 Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
485 evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
486 evas_object_color_set(color14, 255, 255, 255, 255);
487 evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
488 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
489 evas_object_show(color14);
491 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
492 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
493 elm_object_text_set(m_pickerLayout->okButton, "OK");
494 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
495 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
497 evas_object_show(m_pickerLayout->popup);
500 void InputPicker::_color_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
502 InputPicker* inputPicker = static_cast<InputPicker*>(data);
508 evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
510 ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
512 inputPicker->hideColorPicker();
515 void InputPicker::ewk_date_popup(const char* inputValue)
517 struct tm* currentTime;
520 currentTime = localtime(&cur_time);
522 Input_Date_Str dateStr;
523 memset(&dateStr, 0, sizeof(Input_Date_Str));
525 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
526 Evas_Object* win = parent;
531 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
533 if (inputValue && strlen(inputValue)) {
534 char tmpinputValue[30] = {0,};
536 sprintf(tmpinputValue, "%s", inputValue);
537 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
538 strcpy(dateStr.mon, strtok(0, "-"));
539 strcpy(dateStr.day, strtok(0, "-"));
541 currentTime->tm_year = atoi(dateStr.year);
542 currentTime->tm_mon = atoi(dateStr.mon);
543 currentTime->tm_mday = atoi(dateStr.day);
545 currentTime->tm_year = currentTime->tm_year - 1900;
546 currentTime->tm_mon = currentTime->tm_mon - 1;
550 const char* type = elm_object_widget_type_get(parent);
552 if (!strcmp(type, "elm_win")) {
557 parent = elm_object_parent_widget_get(parent);
563 m_pickerLayout->popup = elm_popup_add(win);
564 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
566 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
567 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
568 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
570 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
572 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
573 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
575 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
576 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
577 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
578 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
580 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
581 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
582 elm_object_text_set(m_pickerLayout->okButton, "OK");
583 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
584 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
586 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
587 evas_object_show(m_pickerLayout->popup);
590 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
591 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
594 if (totalDays - 31 < 0) {
595 *remains = totalDays;
599 totalDays = totalDays - 31;
602 if (isLeapYear(year)) {
603 if (totalDays - 29 < 0) {
604 *remains = totalDays;
607 totalDays = totalDays - 29;
609 if (totalDays - 28 < 0) {
610 *remains = totalDays;
613 totalDays = totalDays - 28;
617 if (totalDays - 31 < 0) {
618 *remains = totalDays;
621 totalDays = totalDays - 31;
624 if (totalDays - 30 < 0) {
625 *remains = totalDays;
628 totalDays = totalDays - 30;
631 if (totalDays - 31 < 0) {
632 *remains = totalDays;
635 totalDays = totalDays - 31;
638 if (totalDays - 30 < 0) {
639 *remains = totalDays;
642 totalDays = totalDays - 30;
645 if (totalDays - 31 < 0) {
646 *remains = totalDays;
649 totalDays = totalDays - 31;
652 if (totalDays - 31 < 0) {
653 *remains = totalDays;
656 totalDays = totalDays - 31;
659 if (totalDays - 30 < 0) {
660 *remains = totalDays;
663 totalDays = totalDays - 30;
666 if (totalDays - 31 < 0) {
667 *remains = totalDays;
670 totalDays = totalDays - 31;
673 if (totalDays - 30 < 0) {
674 *remains = totalDays;
677 totalDays = totalDays - 30;
679 *remains = totalDays;
683 void InputPicker::ewk_week_popup(const char* inputValue)
685 struct tm* currentTime;
688 currentTime = localtime(&cur_time);
690 Input_Date_Str dateStr;
691 memset(&dateStr, 0, sizeof(Input_Date_Str));
693 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
694 Evas_Object* win = parent;
699 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
701 if (inputValue && strlen(inputValue)) {
702 char tmpinputValue[30] = {0,};
704 sprintf(tmpinputValue, "%s", inputValue);
705 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
706 const char* week = strstr(inputValue, "W");
709 weekNum = atoi(week + 1);
711 currentTime->tm_year = atoi(dateStr.year);
712 currentTime->tm_year = currentTime->tm_year - 1900;
714 struct tm firtTimeOfyear;
715 memset(&firtTimeOfyear, 0, sizeof(struct tm));
716 firtTimeOfyear.tm_year = currentTime->tm_year;
717 firtTimeOfyear.tm_mon = 0;
718 firtTimeOfyear.tm_mday = 1;
719 mktime(&firtTimeOfyear);
721 char firstWeek[10] = {0, };
722 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
723 int firstWeekCount = atoi(firstWeek);
727 totalDays = weekNum * 7 - firstWeekCount;
730 int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
732 currentTime->tm_mon = month;
733 currentTime->tm_mday = days;
737 const char* type = elm_object_widget_type_get(parent);
739 if (!strcmp(type, "elm_win")) {
744 parent = elm_object_parent_widget_get(parent);
750 m_pickerLayout->popup = elm_popup_add(win);
751 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
753 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
754 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
755 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
757 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
759 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
760 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
762 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
763 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
764 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
765 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
767 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
768 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
769 elm_object_text_set(m_pickerLayout->okButton, "OK");
770 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
771 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
773 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
774 evas_object_show(m_pickerLayout->popup);
777 void InputPicker::ewk_time_popup(const char* inputValue)
779 struct tm* currentTime;
782 currentTime = localtime(&cur_time);
784 Input_Date_Str dateStr;
785 memset(&dateStr, 0, sizeof(Input_Date_Str));
787 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
788 Evas_Object* win = parent;
793 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
795 if (inputValue && strlen(inputValue)) {
796 char tmpinputValue[30] = {0,};
798 sprintf(tmpinputValue, "%s", inputValue);
799 strcpy(dateStr.hour, strtok(tmpinputValue,":"));
800 strcpy(dateStr.min, strtok(0, ":"));
802 currentTime->tm_hour = atoi(dateStr.hour);
803 currentTime->tm_min = atoi(dateStr.min);
807 const char* type = elm_object_widget_type_get(parent);
809 if (!strcmp(type, "elm_win")) {
814 parent = elm_object_parent_widget_get(parent);
820 m_pickerLayout->popup = elm_popup_add(win);
821 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
823 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
824 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
825 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
827 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
829 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
830 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
831 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
833 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
835 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
836 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
837 elm_object_text_set(m_pickerLayout->okButton, "OK");
838 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
840 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
841 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
842 evas_object_show(m_pickerLayout->popup);
845 void InputPicker::ewk_month_popup(const char* inputValue)
847 struct tm* currentTime;
850 currentTime = localtime(&cur_time);
852 Input_Date_Str dateStr;
853 memset(&dateStr, 0, sizeof(Input_Date_Str));
855 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
856 Evas_Object* win = parent;
861 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
863 if (inputValue && strlen(inputValue)) {
864 char tmpInputValue[30] = {0,};
866 sprintf(tmpInputValue, "%s", inputValue);
867 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
868 strcpy(dateStr.mon, strtok(0, "-"));
870 currentTime->tm_year = atoi(dateStr.year);
871 currentTime->tm_mon = atoi(dateStr.mon);
873 currentTime->tm_year = currentTime->tm_year - 1900;
874 currentTime->tm_mon = currentTime->tm_mon - 1;
878 const char* type = elm_object_widget_type_get(parent);
880 if (!strcmp(type, "elm_win")) {
885 parent = elm_object_parent_widget_get(parent);
891 m_pickerLayout->popup = elm_popup_add(win);
893 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
895 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
896 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
898 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
899 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
901 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
903 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Month (Default format) :");
905 elm_datetime_format_set(m_pickerLayout->datePicker, "%Y %m");
906 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
908 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
909 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
910 elm_object_text_set(m_pickerLayout->okButton, "OK");
911 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
912 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
914 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
915 evas_object_show(m_pickerLayout->popup);
918 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
920 struct tm* currentTime;
923 currentTime = localtime(&cur_time);
925 Input_Date_Str dateStr;
926 memset(&dateStr, 0, sizeof(Input_Date_Str));
928 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
929 Evas_Object* win = parent;
934 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
936 m_pickerLayout->datetimeLocal = local;
938 if (inputValue && strlen(inputValue)) {
939 char tmpInputValue[30] = {0, };
941 sprintf(tmpInputValue, "%s", inputValue);
942 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
943 strcpy(dateStr.mon, strtok(0, "-"));
944 strcpy(dateStr.day, strtok(0, "T"));
945 strcpy(dateStr.hour, strtok(0, ":"));
947 if (m_pickerLayout->datetimeLocal)
948 strcpy(dateStr.min, strtok(0, "Z"));
950 strcpy(dateStr.min, strtok(0, ":"));
952 currentTime->tm_year = atoi(dateStr.year);
953 currentTime->tm_mon = atoi(dateStr.mon);
954 currentTime->tm_mday = atoi(dateStr.day);
955 currentTime->tm_hour = atoi(dateStr.hour);
956 currentTime->tm_min = atoi(dateStr.min);
958 currentTime->tm_year = currentTime->tm_year - 1900;
959 currentTime->tm_mon = currentTime->tm_mon - 1;
963 const char* type = elm_object_widget_type_get(parent);
965 if (!strcmp(type, "elm_win")) {
970 parent = elm_object_parent_widget_get(parent);
976 m_pickerLayout->popup = elm_popup_add(win);
977 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
979 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
980 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
981 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
983 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
984 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
986 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
987 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
988 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
989 elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
991 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
992 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
993 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
994 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
996 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
997 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
998 elm_object_text_set(m_pickerLayout->okButton, "OK");
999 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1001 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1002 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1003 evas_object_show(m_pickerLayout->popup);
1007 void InputPicker::_date_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1009 struct tm currentTime;
1010 memset(¤tTime, 0, sizeof(struct tm));
1012 char dateStr[20] = {0, };
1014 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1016 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1018 date.day = currentTime.tm_mday;
1019 date.mon = currentTime.tm_mon;
1020 date.year = currentTime.tm_year;
1022 if(inputPicker->m_pickerLayout->popup){
1023 evas_object_del(inputPicker->m_pickerLayout->popup);
1024 inputPicker->m_pickerLayout->popup = 0;
1027 date.year = 1900 + date.year;
1028 sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1030 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1031 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1033 delete inputPicker->m_pickerLayout;
1034 inputPicker->m_pickerLayout = 0;
1037 void InputPicker::_week_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1039 struct tm currentTime;
1040 memset(¤tTime, 0, sizeof(struct tm));
1042 char dateStr[20] = {0, };
1044 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1046 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1048 date.day = currentTime.tm_mday;
1049 date.mon = currentTime.tm_mon;
1050 date.year = currentTime.tm_year;
1051 mktime(¤tTime);
1053 if(inputPicker->m_pickerLayout->popup){
1054 evas_object_del(inputPicker->m_pickerLayout->popup);
1055 inputPicker->m_pickerLayout->popup = 0;
1058 struct tm firtTimeOfyear;
1059 memset(&firtTimeOfyear, 0, sizeof(struct tm));
1060 firtTimeOfyear.tm_year = date.year;
1061 firtTimeOfyear.tm_mon = 0;
1062 firtTimeOfyear.tm_mday = 1;
1063 mktime(&firtTimeOfyear);
1065 char firstWeek[10] = {0, };
1066 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1067 int firstWeekCount = atoi(firstWeek);
1069 char totalDay[10] = {0, };
1070 strftime(totalDay, 10, "%j", ¤tTime);
1071 int totalDayCount = atoi(totalDay);
1073 int weekNum = (totalDayCount + firstWeekCount) / 7;
1074 if (totalDayCount + firstWeekCount > weekNum * 7)
1077 date.year = 1900 + date.year;
1078 sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1080 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1081 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1083 delete inputPicker->m_pickerLayout;
1084 inputPicker->m_pickerLayout = 0;
1087 void InputPicker::_time_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1089 struct tm currentTime;
1090 memset(¤tTime, 0, sizeof(struct tm));
1092 char dateStr[20] = {0, };
1094 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1096 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1098 date.hour = currentTime.tm_hour;
1099 date.min = currentTime.tm_min;
1101 if(inputPicker->m_pickerLayout->popup){
1102 evas_object_del(inputPicker->m_pickerLayout->popup);
1103 inputPicker->m_pickerLayout->popup = 0;
1106 sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1107 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1108 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1110 delete inputPicker->m_pickerLayout;
1111 inputPicker->m_pickerLayout = 0;
1114 void InputPicker::_month_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1116 struct tm currentTime;
1117 memset(¤tTime, 0, sizeof(struct tm));
1119 char dateStr[20] = {0, };
1121 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1123 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1125 date.mon = currentTime.tm_mon;
1126 date.year = currentTime.tm_year;
1128 if(inputPicker->m_pickerLayout->popup){
1129 evas_object_del(inputPicker->m_pickerLayout->popup);
1130 inputPicker->m_pickerLayout->popup = 0;
1133 date.year = 1900 + date.year;
1134 sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1136 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1137 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1139 delete inputPicker->m_pickerLayout;
1140 inputPicker->m_pickerLayout = 0;
1143 void InputPicker::_datetime_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1145 struct tm currentTime;
1146 memset(¤tTime, 0, sizeof(struct tm));
1148 char dateStr[50] = {0, };
1150 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1152 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1153 date.year = currentTime.tm_year;
1154 date.day = currentTime.tm_mday;
1155 date.mon = currentTime.tm_mon;
1157 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1158 date.hour = currentTime.tm_hour;
1159 date.min = currentTime.tm_min;
1161 if (inputPicker->m_pickerLayout->popup) {
1162 evas_object_del(inputPicker->m_pickerLayout->popup);
1163 inputPicker->m_pickerLayout->popup = 0;
1166 date.year = 1900 + date.year;
1168 if (inputPicker->m_pickerLayout->datetimeLocal)
1169 sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1171 sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1173 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1174 ewk_view_command_execute(inputPicker->m_ewkView, "Unselect", 0);
1176 delete inputPicker->m_pickerLayout;
1177 inputPicker->m_pickerLayout = 0;
1180 } // namespace WebKit
1182 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)