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);
47 /* FIXME : Workaround. OSP requirement.
48 OSP want to block own touch event while webkit internal picker is running. */
49 evas_object_smart_callback_call(m_ewkView, "input,picker,show", 0);
52 Input_Picker_Layout::~Input_Picker_Layout()
54 /* FIXME : Workaround. OSP requirement.
55 OSP want to block own touch event while webkit internal picker is running. */
56 evas_object_smart_callback_call(m_ewkView, "input,picker,hide", 0);
61 InputPicker::InputPicker(Evas_Object* ewkView)
68 InputPicker::~InputPicker()
71 if (m_pickerLayout->popup)
72 evas_object_del(m_pickerLayout->popup);
73 delete m_pickerLayout;
77 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
79 if(inputType == EWK_INPUT_TYPE_DATE)
80 ewk_date_popup(inputValue);
81 else if(inputType == EWK_INPUT_TYPE_TIME)
82 ewk_time_popup(inputValue);
83 else if(inputType == EWK_INPUT_TYPE_DATETIME)
84 ewk_datetime_popup(inputValue, false);
85 else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
86 ewk_datetime_popup(inputValue, true);
87 else if(inputType == EWK_INPUT_TYPE_MONTH)
88 ewk_month_popup(inputValue);
89 else if(inputType == EWK_INPUT_TYPE_WEEK)
90 ewk_week_popup(inputValue);
93 #if ENABLE(TIZEN_DATALIST_ELEMENT)
94 void InputPicker::_data_list_popup_response_cb(void* data, Evas_Object* obj, void* eventInfo)
96 InputPicker* inputPicker = static_cast<InputPicker*>(data);
97 const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
98 ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
100 if (inputPicker->m_pickerLayout->popup) {
101 evas_object_del(inputPicker->m_pickerLayout->popup);
102 inputPicker->m_pickerLayout->popup = 0;
105 delete inputPicker->m_pickerLayout;
106 inputPicker->m_pickerLayout = 0;
108 inputPicker->m_dataList = 0;
111 void InputPicker::_data_list_popup_response_cancel_cb(void* data, Evas_Object* obj, void* eventInfo)
113 InputPicker* inputPicker = static_cast<InputPicker*>(data);
115 if (inputPicker->m_pickerLayout->popup) {
116 evas_object_del(inputPicker->m_pickerLayout->popup);
117 inputPicker->m_pickerLayout->popup = 0;
120 delete inputPicker->m_pickerLayout;
121 inputPicker->m_pickerLayout = 0;
123 inputPicker->m_dataList = 0;
126 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
128 InputPicker* inputPicker = static_cast<InputPicker*>(data);
129 Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
130 Elm_Object_Item* item = elm_list_first_item_get(obj);
134 if (item == selectedItem)
137 item = elm_list_item_next(item);
143 EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
144 if (listItem && index == listIndex)
145 elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
151 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
153 Evas_Object* entry = static_cast<Evas_Object*>(data);
154 elm_entry_entry_set(entry, "");
157 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
159 Evas_Object* layout = static_cast<Evas_Object*>(data);
161 if (elm_object_focus_get(layout)) {
162 if (elm_entry_is_empty(obj))
163 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
165 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
169 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
171 Evas_Object* layout = static_cast<Evas_Object*>(data);
173 if (!elm_entry_is_empty(obj))
174 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
177 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
179 Evas_Object* layout = static_cast<Evas_Object*>(data);
180 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
183 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
185 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
186 Evas_Object* win = parent;
188 m_dataList = optionList;
193 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
195 // FIXME: If the entry is in the popup, the parent should be naviframe for uifw limitation.
196 Evas_Object* naviframe = elm_naviframe_add(m_ewkView);
198 const char* type = elm_object_widget_type_get(parent);
200 if (!strcmp(type, elm_object_widget_type_get(naviframe))) {
205 parent = elm_object_parent_widget_get(parent);
208 evas_object_del(naviframe);
213 m_pickerLayout->popup = elm_popup_add(win);
214 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
216 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
217 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
218 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219 evas_object_show(m_pickerLayout->layout);
220 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
222 Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
225 EINA_LIST_FOREACH(optionList, list, listItem) {
227 elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
229 evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230 evas_object_show(elmList);
231 elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
233 Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
234 elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
236 m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
237 elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
239 elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
240 elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
241 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
242 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
243 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
245 elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
246 evas_object_show(editFieldLayout);
248 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
249 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
250 elm_object_text_set(m_pickerLayout->okButton, "OK");
251 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
252 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
253 evas_object_show(m_pickerLayout->popup);
255 Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
256 elm_object_style_set(cancelButton, "popup_button/default");
257 elm_object_text_set(cancelButton, "Cancel");
258 elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
259 evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
260 evas_object_show(cancelButton);
263 void InputPicker::hideDataList(Ewk_Input_Type inputType)
268 if(m_pickerLayout->popup){
269 evas_object_del(m_pickerLayout->popup);
270 m_pickerLayout->popup = 0;
273 delete m_pickerLayout;
280 #if ENABLE(TIZEN_INPUT_COLOR_PICKER)
281 void InputPicker::showColorPicker(int r, int g, int b, int)
283 ewk_color_popup(r, g, b);
286 void InputPicker::hideColorPicker()
291 if (m_pickerLayout->popup) {
292 evas_object_del(m_pickerLayout->popup);
293 m_pickerLayout->popup = 0;
296 delete m_pickerLayout;
301 #if ENABLE(ELM_COLORPALLETE)
302 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
308 Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
309 elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
310 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
314 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
320 evas_object_color_get(obj, &r, &g, &b, &a);
322 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
325 void InputPicker::ewk_color_popup(int r, int g, int b)
327 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
328 Evas_Object* win = parent;
333 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
336 const char* type = elm_object_widget_type_get(parent);
338 if (!strcmp(type, "elm_win")) {
343 parent = elm_object_parent_widget_get(parent);
349 m_pickerLayout->popup = elm_popup_add(win);
350 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
352 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
353 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
354 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
355 evas_object_show(m_pickerLayout->layout);
356 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
358 m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
359 evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
360 evas_object_show(m_pickerLayout->colorRect);
362 printf("\n<<<<<<<< r = [%d], g = [%d], b = [%d] >>>>>>>>>>\n", r, g, b);
364 evas_object_color_set(m_pickerLayout->colorRect, r, g, b, 255);
365 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
366 #if ENABLE(ELM_COLORPALLETE)
367 Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
368 elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
370 elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
371 elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
372 elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
373 elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
374 elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
375 elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
376 elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
377 elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
378 elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
379 elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
380 elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
381 elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
383 evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
384 evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
385 evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
386 evas_object_show(colorPalette);
388 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
390 Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
391 evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
392 evas_object_color_set(color1, 128, 0, 0, 255);
393 evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
394 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
395 evas_object_show(color1);
397 Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
398 evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
399 evas_object_color_set(color2, 255, 0, 128, 255);
400 evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
401 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
402 evas_object_show(color2);
404 Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
405 evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
406 evas_object_color_set(color3, 255, 0, 0, 255);
407 evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
408 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
409 evas_object_show(color3);
411 Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
412 evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
413 evas_object_color_set(color4, 255, 127, 39, 255);
414 evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
415 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
416 evas_object_show(color4);
418 Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
419 evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
420 evas_object_color_set(color5, 255, 255, 0, 255);
421 evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
422 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
423 evas_object_show(color5);
425 Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
426 evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
427 evas_object_color_set(color6, 0, 255, 0, 255);
428 evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
429 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
430 evas_object_show(color6);
432 Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
433 evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
434 evas_object_color_set(color7, 0, 255, 255, 255);
435 evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
436 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
437 evas_object_show(color7);
439 Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
440 evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
441 evas_object_color_set(color8, 0, 0, 255, 255);
442 evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
443 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
444 evas_object_show(color8);
446 Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
447 evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
448 evas_object_color_set(color9, 0, 0, 128, 255);
449 evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
450 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
451 evas_object_show(color9);
453 Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
454 evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
455 evas_object_color_set(color10, 64, 0, 64, 255);
456 evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
457 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
458 evas_object_show(color10);
460 Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
461 evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
462 evas_object_color_set(color11, 153, 217, 234, 255);
463 evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
464 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
465 evas_object_show(color11);
467 Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
468 evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
469 evas_object_color_set(color12, 128, 128, 128, 255);
470 evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
471 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
472 evas_object_show(color12);
474 Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
475 evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
476 evas_object_color_set(color13, 0, 0, 0, 255);
477 evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
478 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
479 evas_object_show(color13);
481 Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
482 evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
483 evas_object_color_set(color14, 255, 255, 255, 255);
484 evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
485 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
486 evas_object_show(color14);
488 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
489 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
490 elm_object_text_set(m_pickerLayout->okButton, "OK");
491 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
492 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
494 evas_object_show(m_pickerLayout->popup);
497 void InputPicker::_color_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
499 InputPicker* inputPicker = static_cast<InputPicker*>(data);
505 evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
507 ewk_view_color_picker_color_set(inputPicker->m_ewkView, r, g, b, a);
509 inputPicker->hideColorPicker();
512 void InputPicker::ewk_date_popup(const char* inputValue)
514 struct tm* currentTime;
517 currentTime = localtime(&cur_time);
519 Input_Date_Str dateStr;
520 memset(&dateStr, 0, sizeof(Input_Date_Str));
522 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
523 Evas_Object* win = parent;
528 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
530 if (inputValue && strlen(inputValue)) {
531 char tmpinputValue[30] = {0,};
533 sprintf(tmpinputValue, "%s", inputValue);
534 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
535 strcpy(dateStr.mon, strtok(0, "-"));
536 strcpy(dateStr.day, strtok(0, "-"));
538 currentTime->tm_year = atoi(dateStr.year);
539 currentTime->tm_mon = atoi(dateStr.mon);
540 currentTime->tm_mday = atoi(dateStr.day);
542 currentTime->tm_year = currentTime->tm_year - 1900;
543 currentTime->tm_mon = currentTime->tm_mon - 1;
547 const char* type = elm_object_widget_type_get(parent);
549 if (!strcmp(type, "elm_win")) {
554 parent = elm_object_parent_widget_get(parent);
560 m_pickerLayout->popup = elm_popup_add(win);
561 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
563 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
564 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
565 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
567 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
569 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
570 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
572 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
573 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
574 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
575 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
577 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
578 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
579 elm_object_text_set(m_pickerLayout->okButton, "OK");
580 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
581 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
583 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
584 evas_object_show(m_pickerLayout->popup);
587 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
588 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
591 if (totalDays - 31 < 0) {
592 *remains = totalDays;
596 totalDays = totalDays - 31;
599 if (isLeapYear(year)) {
600 if (totalDays - 29 < 0) {
601 *remains = totalDays;
604 totalDays = totalDays - 29;
606 if (totalDays - 28 < 0) {
607 *remains = totalDays;
610 totalDays = totalDays - 28;
614 if (totalDays - 31 < 0) {
615 *remains = totalDays;
618 totalDays = totalDays - 31;
621 if (totalDays - 30 < 0) {
622 *remains = totalDays;
625 totalDays = totalDays - 30;
628 if (totalDays - 31 < 0) {
629 *remains = totalDays;
632 totalDays = totalDays - 31;
635 if (totalDays - 30 < 0) {
636 *remains = totalDays;
639 totalDays = totalDays - 30;
642 if (totalDays - 31 < 0) {
643 *remains = totalDays;
646 totalDays = totalDays - 31;
649 if (totalDays - 31 < 0) {
650 *remains = totalDays;
653 totalDays = totalDays - 31;
656 if (totalDays - 30 < 0) {
657 *remains = totalDays;
660 totalDays = totalDays - 30;
663 if (totalDays - 31 < 0) {
664 *remains = totalDays;
667 totalDays = totalDays - 31;
670 if (totalDays - 30 < 0) {
671 *remains = totalDays;
674 totalDays = totalDays - 30;
676 *remains = totalDays;
680 void InputPicker::ewk_week_popup(const char* inputValue)
682 struct tm* currentTime;
685 currentTime = localtime(&cur_time);
687 Input_Date_Str dateStr;
688 memset(&dateStr, 0, sizeof(Input_Date_Str));
690 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
691 Evas_Object* win = parent;
696 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
698 if (inputValue && strlen(inputValue)) {
699 char tmpinputValue[30] = {0,};
701 sprintf(tmpinputValue, "%s", inputValue);
702 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
703 const char* week = strstr(inputValue, "W");
706 weekNum = atoi(week + 1);
708 currentTime->tm_year = atoi(dateStr.year);
709 currentTime->tm_year = currentTime->tm_year - 1900;
711 struct tm firtTimeOfyear;
712 memset(&firtTimeOfyear, 0, sizeof(struct tm));
713 firtTimeOfyear.tm_year = currentTime->tm_year;
714 firtTimeOfyear.tm_mon = 0;
715 firtTimeOfyear.tm_mday = 1;
716 mktime(&firtTimeOfyear);
718 char firstWeek[10] = {0, };
719 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
720 int firstWeekCount = atoi(firstWeek);
724 totalDays = weekNum * 7 - firstWeekCount;
727 int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
729 currentTime->tm_mon = month;
730 currentTime->tm_mday = days;
734 const char* type = elm_object_widget_type_get(parent);
736 if (!strcmp(type, "elm_win")) {
741 parent = elm_object_parent_widget_get(parent);
747 m_pickerLayout->popup = elm_popup_add(win);
748 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
750 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
751 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
752 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
754 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
756 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
757 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
759 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
760 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
761 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
762 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
764 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
765 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
766 elm_object_text_set(m_pickerLayout->okButton, "OK");
767 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
768 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
770 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
771 evas_object_show(m_pickerLayout->popup);
774 void InputPicker::ewk_time_popup(const char* inputValue)
776 struct tm* currentTime;
779 currentTime = localtime(&cur_time);
781 Input_Date_Str dateStr;
782 memset(&dateStr, 0, sizeof(Input_Date_Str));
784 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
785 Evas_Object* win = parent;
790 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
792 if (inputValue && strlen(inputValue)) {
793 char tmpinputValue[30] = {0,};
795 sprintf(tmpinputValue, "%s", inputValue);
796 strcpy(dateStr.hour, strtok(tmpinputValue,":"));
797 strcpy(dateStr.min, strtok(0, ":"));
799 currentTime->tm_hour = atoi(dateStr.hour);
800 currentTime->tm_min = atoi(dateStr.min);
804 const char* type = elm_object_widget_type_get(parent);
806 if (!strcmp(type, "elm_win")) {
811 parent = elm_object_parent_widget_get(parent);
817 m_pickerLayout->popup = elm_popup_add(win);
818 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
820 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
821 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
822 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
824 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
826 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
827 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
828 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
830 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
832 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
833 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
834 elm_object_text_set(m_pickerLayout->okButton, "OK");
835 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
837 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
838 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
839 evas_object_show(m_pickerLayout->popup);
842 void InputPicker::ewk_month_popup(const char* inputValue)
844 struct tm* currentTime;
847 currentTime = localtime(&cur_time);
849 Input_Date_Str dateStr;
850 memset(&dateStr, 0, sizeof(Input_Date_Str));
852 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
853 Evas_Object* win = parent;
858 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
860 if (inputValue && strlen(inputValue)) {
861 char tmpInputValue[30] = {0,};
863 sprintf(tmpInputValue, "%s", inputValue);
864 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
865 strcpy(dateStr.mon, strtok(0, "-"));
867 currentTime->tm_year = atoi(dateStr.year);
868 currentTime->tm_mon = atoi(dateStr.mon);
870 currentTime->tm_year = currentTime->tm_year - 1900;
871 currentTime->tm_mon = currentTime->tm_mon - 1;
875 const char* type = elm_object_widget_type_get(parent);
877 if (!strcmp(type, "elm_win")) {
882 parent = elm_object_parent_widget_get(parent);
888 m_pickerLayout->popup = elm_popup_add(win);
890 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
892 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
893 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
895 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
896 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
898 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
900 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Month (Default format) :");
902 elm_datetime_format_set(m_pickerLayout->datePicker, "%Y -%m");
903 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
905 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
906 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
907 elm_object_text_set(m_pickerLayout->okButton, "OK");
908 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
909 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
911 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
912 evas_object_show(m_pickerLayout->popup);
915 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
917 struct tm* currentTime;
920 currentTime = localtime(&cur_time);
922 Input_Date_Str dateStr;
923 memset(&dateStr, 0, sizeof(Input_Date_Str));
925 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
926 Evas_Object* win = parent;
931 m_pickerLayout = new Input_Picker_Layout(m_ewkView);
933 m_pickerLayout->datetimeLocal = local;
935 if (inputValue && strlen(inputValue)) {
936 char tmpInputValue[30] = {0, };
938 sprintf(tmpInputValue, "%s", inputValue);
939 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
940 strcpy(dateStr.mon, strtok(0, "-"));
941 strcpy(dateStr.day, strtok(0, "T"));
942 strcpy(dateStr.hour, strtok(0, ":"));
944 if (m_pickerLayout->datetimeLocal)
945 strcpy(dateStr.min, strtok(0, "Z"));
947 strcpy(dateStr.min, strtok(0, ":"));
949 currentTime->tm_year = atoi(dateStr.year);
950 currentTime->tm_mon = atoi(dateStr.mon);
951 currentTime->tm_mday = atoi(dateStr.day);
952 currentTime->tm_hour = atoi(dateStr.hour);
953 currentTime->tm_min = atoi(dateStr.min);
955 currentTime->tm_year = currentTime->tm_year - 1900;
956 currentTime->tm_mon = currentTime->tm_mon - 1;
960 const char* type = elm_object_widget_type_get(parent);
962 if (!strcmp(type, "elm_win")) {
967 parent = elm_object_parent_widget_get(parent);
973 m_pickerLayout->popup = elm_popup_add(win);
974 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
976 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
977 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
978 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
980 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
981 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
983 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
984 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
985 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
986 elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
988 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
989 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
990 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
991 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
993 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
994 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
995 elm_object_text_set(m_pickerLayout->okButton, "OK");
996 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
998 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
999 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1000 evas_object_show(m_pickerLayout->popup);
1004 void InputPicker::_date_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1006 struct tm currentTime;
1007 memset(¤tTime, 0, sizeof(struct tm));
1009 char dateStr[20] = {0, };
1011 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1013 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1015 date.day = currentTime.tm_mday;
1016 date.mon = currentTime.tm_mon;
1017 date.year = currentTime.tm_year;
1019 if(inputPicker->m_pickerLayout->popup){
1020 evas_object_del(inputPicker->m_pickerLayout->popup);
1021 inputPicker->m_pickerLayout->popup = 0;
1024 date.year = 1900 + date.year;
1025 sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1027 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1029 delete inputPicker->m_pickerLayout;
1030 inputPicker->m_pickerLayout = 0;
1033 void InputPicker::_week_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1035 struct tm currentTime;
1036 memset(¤tTime, 0, sizeof(struct tm));
1038 char dateStr[20] = {0, };
1040 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1042 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1044 date.day = currentTime.tm_mday;
1045 date.mon = currentTime.tm_mon;
1046 date.year = currentTime.tm_year;
1047 mktime(¤tTime);
1049 if(inputPicker->m_pickerLayout->popup){
1050 evas_object_del(inputPicker->m_pickerLayout->popup);
1051 inputPicker->m_pickerLayout->popup = 0;
1054 struct tm firtTimeOfyear;
1055 memset(&firtTimeOfyear, 0, sizeof(struct tm));
1056 firtTimeOfyear.tm_year = date.year;
1057 firtTimeOfyear.tm_mon = 0;
1058 firtTimeOfyear.tm_mday = 1;
1059 mktime(&firtTimeOfyear);
1061 char firstWeek[10] = {0, };
1062 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1063 int firstWeekCount = atoi(firstWeek);
1065 char totalDay[10] = {0, };
1066 strftime(totalDay, 10, "%j", ¤tTime);
1067 int totalDayCount = atoi(totalDay);
1069 int weekNum = (totalDayCount + firstWeekCount) / 7;
1070 if (totalDayCount + firstWeekCount > weekNum * 7)
1073 date.year = 1900 + date.year;
1074 sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1076 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1078 delete inputPicker->m_pickerLayout;
1079 inputPicker->m_pickerLayout = 0;
1082 void InputPicker::_time_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1084 struct tm currentTime;
1085 memset(¤tTime, 0, sizeof(struct tm));
1087 char dateStr[20] = {0, };
1089 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1091 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1093 date.hour = currentTime.tm_hour;
1094 date.min = currentTime.tm_min;
1096 if(inputPicker->m_pickerLayout->popup){
1097 evas_object_del(inputPicker->m_pickerLayout->popup);
1098 inputPicker->m_pickerLayout->popup = 0;
1101 sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1102 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1104 delete inputPicker->m_pickerLayout;
1105 inputPicker->m_pickerLayout = 0;
1108 void InputPicker::_month_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1110 struct tm currentTime;
1111 memset(¤tTime, 0, sizeof(struct tm));
1113 char dateStr[20] = {0, };
1115 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1117 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1119 date.mon = currentTime.tm_mon;
1120 date.year = currentTime.tm_year;
1122 if(inputPicker->m_pickerLayout->popup){
1123 evas_object_del(inputPicker->m_pickerLayout->popup);
1124 inputPicker->m_pickerLayout->popup = 0;
1127 date.year = 1900 + date.year;
1128 sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1130 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1132 delete inputPicker->m_pickerLayout;
1133 inputPicker->m_pickerLayout = 0;
1136 void InputPicker::_datetime_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1138 struct tm currentTime;
1139 memset(¤tTime, 0, sizeof(struct tm));
1141 char dateStr[50] = {0, };
1143 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1145 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1146 date.year = currentTime.tm_year;
1147 date.day = currentTime.tm_mday;
1148 date.mon = currentTime.tm_mon;
1150 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1151 date.hour = currentTime.tm_hour;
1152 date.min = currentTime.tm_min;
1154 if (inputPicker->m_pickerLayout->popup) {
1155 evas_object_del(inputPicker->m_pickerLayout->popup);
1156 inputPicker->m_pickerLayout->popup = 0;
1159 date.year = 1900 + date.year;
1161 if (inputPicker->m_pickerLayout->datetimeLocal)
1162 sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1164 sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1166 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1168 delete inputPicker->m_pickerLayout;
1169 inputPicker->m_pickerLayout = 0;
1172 } // namespace WebKit
1174 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)