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)
36 InputPicker::InputPicker(Evas_Object* ewkView)
43 InputPicker::~InputPicker()
46 if (m_pickerLayout->popup)
47 evas_object_del(m_pickerLayout->popup);
48 delete m_pickerLayout;
52 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
54 if(inputType == EWK_INPUT_TYPE_DATE)
55 ewk_date_popup(inputValue);
56 else if(inputType == EWK_INPUT_TYPE_TIME)
57 ewk_time_popup(inputValue);
58 else if(inputType == EWK_INPUT_TYPE_DATETIME)
59 ewk_datetime_popup(inputValue, false);
60 else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
61 ewk_datetime_popup(inputValue, true);
62 else if(inputType == EWK_INPUT_TYPE_MONTH)
63 ewk_month_popup(inputValue);
64 else if(inputType == EWK_INPUT_TYPE_WEEK)
65 ewk_week_popup(inputValue);
66 else if(inputType == EWK_INPUT_TYPE_COLOR)
67 ewk_color_popup(inputValue);
70 #if ENABLE(TIZEN_DATALIST_ELEMENT)
71 void InputPicker::_data_list_popup_response_cb(void* data, Evas_Object* obj, void* eventInfo)
73 InputPicker* inputPicker = static_cast<InputPicker*>(data);
74 const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
75 ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
77 if (inputPicker->m_pickerLayout->popup) {
78 evas_object_del(inputPicker->m_pickerLayout->popup);
79 inputPicker->m_pickerLayout->popup = 0;
82 delete inputPicker->m_pickerLayout;
83 inputPicker->m_pickerLayout = 0;
85 inputPicker->m_dataList = 0;
88 void InputPicker::_data_list_popup_response_cancel_cb(void* data, Evas_Object* obj, void* eventInfo)
90 InputPicker* inputPicker = static_cast<InputPicker*>(data);
92 if (inputPicker->m_pickerLayout->popup) {
93 evas_object_del(inputPicker->m_pickerLayout->popup);
94 inputPicker->m_pickerLayout->popup = 0;
97 delete inputPicker->m_pickerLayout;
98 inputPicker->m_pickerLayout = 0;
100 inputPicker->m_dataList = 0;
103 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
105 InputPicker* inputPicker = static_cast<InputPicker*>(data);
106 Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
107 Elm_Object_Item* item = elm_list_first_item_get(obj);
111 if (item == selectedItem)
114 item = elm_list_item_next(item);
120 EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
121 if (listItem && index == listIndex)
122 elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
128 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
130 Evas_Object* entry = static_cast<Evas_Object*>(data);
131 elm_entry_entry_set(entry, "");
134 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
136 Evas_Object* layout = static_cast<Evas_Object*>(data);
138 if (elm_object_focus_get(layout)) {
139 if (elm_entry_is_empty(obj))
140 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
142 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
146 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
148 Evas_Object* layout = static_cast<Evas_Object*>(data);
150 if (!elm_entry_is_empty(obj))
151 elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
154 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
156 Evas_Object* layout = static_cast<Evas_Object*>(data);
157 elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
160 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
162 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
163 Evas_Object* win = parent;
165 m_dataList = optionList;
168 delete m_pickerLayout;
170 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
171 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
174 const char* type = elm_object_widget_type_get(parent);
176 if (!strcmp(type, "win")) {
181 parent = elm_object_parent_widget_get(parent);
187 Evas_Object* conformant = elm_conformant_add(win);
188 elm_win_resize_object_add(win, conformant);
189 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
190 evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
191 evas_object_show(conformant);
193 Evas_Object* dummyLaout = elm_layout_add(conformant);
194 elm_object_content_set(conformant, dummyLaout);
196 m_pickerLayout->popup = elm_popup_add(dummyLaout);
197 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
199 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
200 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
201 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
202 evas_object_show(m_pickerLayout->layout);
203 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
205 Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
208 EINA_LIST_FOREACH(optionList, list, listItem) {
210 elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
212 evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
213 evas_object_show(elmList);
214 elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
216 Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
217 elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
219 m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
220 elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
222 elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
223 elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
224 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
225 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
226 evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
228 elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
229 evas_object_show(editFieldLayout);
231 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
232 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
233 elm_object_text_set(m_pickerLayout->okButton, "OK");
234 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
235 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
236 evas_object_show(m_pickerLayout->popup);
238 Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
239 elm_object_style_set(cancelButton, "popup_button/default");
240 elm_object_text_set(cancelButton, "Cancel");
241 elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
242 evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
243 evas_object_show(cancelButton);
246 void InputPicker::hideDataList(Ewk_Input_Type inputType)
251 if(m_pickerLayout->popup){
252 evas_object_del(m_pickerLayout->popup);
253 m_pickerLayout->popup = 0;
256 delete m_pickerLayout;
263 #if ENABLE(ELM_COLORPALLETE)
264 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
270 Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
271 elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
272 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
276 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
282 evas_object_color_get(obj, &r, &g, &b, &a);
284 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
287 void InputPicker::ewk_color_popup(const char* inputValue)
289 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
290 Evas_Object* win = parent;
293 delete m_pickerLayout;
295 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
296 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
299 const char* type = elm_object_widget_type_get(parent);
301 if (!strcmp(type, "win")) {
306 parent = elm_object_parent_widget_get(parent);
312 m_pickerLayout->popup = elm_popup_add(win);
313 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
315 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
316 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
317 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
318 evas_object_show(m_pickerLayout->layout);
319 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
321 m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
322 evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
323 evas_object_show(m_pickerLayout->colorRect);
332 colorR[0] = inputValue[1];
333 colorR[1] = inputValue[2];
334 colorG[0] = inputValue[3];
335 colorG[1] = inputValue[4];
336 colorB[0] = inputValue[5];
337 colorB[1] = inputValue[6];
343 decR = static_cast<int>(strtol(colorR, 0, 16));
344 decG = static_cast<int>(strtol(colorG, 0, 16));
345 decB = static_cast<int>(strtol(colorB, 0, 16));
347 printf("\n<<<<<<<< colorR = [%s], colorG = [%s], colorB = [%s] >>>>>>>>>>\n", colorR, colorG, colorB);
348 printf("\n<<<<<<<< decR = [%d], decG = [%d], decB = [%d] >>>>>>>>>>\n", decR, decG, decB);
350 evas_object_color_set(m_pickerLayout->colorRect, decR, decG, decB, 255);
351 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
352 #if ENABLE(ELM_COLORPALLETE)
353 Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
354 elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
356 elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
357 elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
358 elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
359 elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
360 elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
361 elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
362 elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
363 elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
364 elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
365 elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
366 elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
367 elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
369 evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
370 evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
371 evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
372 evas_object_show(colorPalette);
374 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
376 Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
377 evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
378 evas_object_color_set(color1, 128, 0, 0, 255);
379 evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
380 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
381 evas_object_show(color1);
383 Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
384 evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
385 evas_object_color_set(color2, 255, 0, 128, 255);
386 evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
387 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
388 evas_object_show(color2);
390 Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
391 evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
392 evas_object_color_set(color3, 255, 0, 0, 255);
393 evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
394 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
395 evas_object_show(color3);
397 Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
398 evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
399 evas_object_color_set(color4, 255, 127, 39, 255);
400 evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
401 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
402 evas_object_show(color4);
404 Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
405 evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
406 evas_object_color_set(color5, 255, 255, 0, 255);
407 evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
408 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
409 evas_object_show(color5);
411 Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
412 evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
413 evas_object_color_set(color6, 0, 255, 0, 255);
414 evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
415 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
416 evas_object_show(color6);
418 Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
419 evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
420 evas_object_color_set(color7, 0, 255, 255, 255);
421 evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
422 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
423 evas_object_show(color7);
425 Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
426 evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
427 evas_object_color_set(color8, 0, 0, 255, 255);
428 evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
429 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
430 evas_object_show(color8);
432 Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
433 evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
434 evas_object_color_set(color9, 0, 0, 128, 255);
435 evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
436 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
437 evas_object_show(color9);
439 Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
440 evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
441 evas_object_color_set(color10, 64, 0, 64, 255);
442 evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
443 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
444 evas_object_show(color10);
446 Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
447 evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
448 evas_object_color_set(color11, 153, 217, 234, 255);
449 evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
450 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
451 evas_object_show(color11);
453 Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
454 evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
455 evas_object_color_set(color12, 128, 128, 128, 255);
456 evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
457 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
458 evas_object_show(color12);
460 Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
461 evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
462 evas_object_color_set(color13, 0, 0, 0, 255);
463 evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
464 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
465 evas_object_show(color13);
467 Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
468 evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
469 evas_object_color_set(color14, 255, 255, 255, 255);
470 evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
471 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
472 evas_object_show(color14);
474 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
475 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
476 elm_object_text_set(m_pickerLayout->okButton, "OK");
477 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
478 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
480 evas_object_show(m_pickerLayout->popup);
483 void InputPicker::_color_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
485 InputPicker* inputPicker = static_cast<InputPicker*>(data);
491 evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
493 char selectColor[10];
494 selectColor[10] = '\0';
495 sprintf(selectColor, "#%02x%02x%02x", r, g, b);
497 ewk_view_color_chooser_color_set(inputPicker->m_ewkView, selectColor);
498 ewk_view_color_chooser_close(inputPicker->m_ewkView);
500 if(inputPicker->m_pickerLayout->popup){
501 evas_object_del(inputPicker->m_pickerLayout->popup);
502 inputPicker->m_pickerLayout->popup = 0;
505 delete inputPicker->m_pickerLayout;
506 inputPicker->m_pickerLayout = 0;
509 void InputPicker::ewk_date_popup(const char* inputValue)
511 struct tm* currentTime;
514 currentTime = localtime(&cur_time);
516 Input_Date_Str dateStr;
517 memset(&dateStr, 0, sizeof(Input_Date_Str));
519 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
520 Evas_Object* win = parent;
523 delete m_pickerLayout;
525 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
526 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
528 if (inputValue && strlen(inputValue)) {
529 char tmpinputValue[30] = {0,};
531 sprintf(tmpinputValue, "%s", inputValue);
532 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
533 strcpy(dateStr.mon, strtok(0, "-"));
534 strcpy(dateStr.day, strtok(0, "-"));
536 currentTime->tm_year = atoi(dateStr.year);
537 currentTime->tm_mon = atoi(dateStr.mon);
538 currentTime->tm_mday = atoi(dateStr.day);
540 currentTime->tm_year = currentTime->tm_year - 1900;
541 currentTime->tm_mon = currentTime->tm_mon - 1;
545 const char* type = elm_object_widget_type_get(parent);
547 if (!strcmp(type, "win")) {
552 parent = elm_object_parent_widget_get(parent);
558 m_pickerLayout->popup = elm_popup_add(win);
559 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
561 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
562 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
563 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
565 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
567 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
568 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
570 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
571 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
572 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
573 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
575 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
576 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
577 elm_object_text_set(m_pickerLayout->okButton, "OK");
578 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
579 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
581 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
582 evas_object_show(m_pickerLayout->popup);
585 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
586 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
589 if (totalDays - 31 < 0) {
590 *remains = totalDays;
594 totalDays = totalDays - 31;
597 if (isLeapYear(year)) {
598 if (totalDays - 29 < 0) {
599 *remains = totalDays;
602 totalDays = totalDays - 29;
604 if (totalDays - 28 < 0) {
605 *remains = totalDays;
608 totalDays = totalDays - 28;
612 if (totalDays - 31 < 0) {
613 *remains = totalDays;
616 totalDays = totalDays - 31;
619 if (totalDays - 30 < 0) {
620 *remains = totalDays;
623 totalDays = totalDays - 30;
626 if (totalDays - 31 < 0) {
627 *remains = totalDays;
630 totalDays = totalDays - 31;
633 if (totalDays - 30 < 0) {
634 *remains = totalDays;
637 totalDays = totalDays - 30;
640 if (totalDays - 31 < 0) {
641 *remains = totalDays;
644 totalDays = totalDays - 31;
647 if (totalDays - 31 < 0) {
648 *remains = totalDays;
651 totalDays = totalDays - 31;
654 if (totalDays - 30 < 0) {
655 *remains = totalDays;
658 totalDays = totalDays - 30;
661 if (totalDays - 31 < 0) {
662 *remains = totalDays;
665 totalDays = totalDays - 31;
668 if (totalDays - 30 < 0) {
669 *remains = totalDays;
672 totalDays = totalDays - 30;
674 *remains = totalDays;
678 void InputPicker::ewk_week_popup(const char* inputValue)
680 struct tm* currentTime;
683 currentTime = localtime(&cur_time);
685 Input_Date_Str dateStr;
686 memset(&dateStr, 0, sizeof(Input_Date_Str));
688 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
689 Evas_Object* win = parent;
692 delete m_pickerLayout;
694 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
695 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
697 if (inputValue && strlen(inputValue)) {
698 char tmpinputValue[30] = {0,};
700 sprintf(tmpinputValue, "%s", inputValue);
701 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
702 const char* week = strstr(inputValue, "W");
705 weekNum = atoi(week + 1);
707 currentTime->tm_year = atoi(dateStr.year);
708 currentTime->tm_year = currentTime->tm_year - 1900;
710 struct tm firtTimeOfyear;
711 memset(&firtTimeOfyear, 0, sizeof(struct tm));
712 firtTimeOfyear.tm_year = currentTime->tm_year;
713 firtTimeOfyear.tm_mon = 0;
714 firtTimeOfyear.tm_mday = 1;
715 mktime(&firtTimeOfyear);
717 char firstWeek[10] = {0, };
718 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
719 int firstWeekCount = atoi(firstWeek);
723 totalDays = weekNum * 7 - firstWeekCount;
726 int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
728 currentTime->tm_mon = month;
729 currentTime->tm_mday = days;
733 const char* type = elm_object_widget_type_get(parent);
735 if (!strcmp(type, "win")) {
740 parent = elm_object_parent_widget_get(parent);
746 m_pickerLayout->popup = elm_popup_add(win);
747 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
749 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
750 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
751 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
753 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
755 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
756 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
758 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
759 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
760 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
761 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
763 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
764 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
765 elm_object_text_set(m_pickerLayout->okButton, "OK");
766 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
767 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
769 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
770 evas_object_show(m_pickerLayout->popup);
773 void InputPicker::ewk_time_popup(const char* inputValue)
775 struct tm* currentTime;
778 currentTime = localtime(&cur_time);
780 Input_Date_Str dateStr;
781 memset(&dateStr, 0, sizeof(Input_Date_Str));
783 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
784 Evas_Object* win = parent;
787 delete m_pickerLayout;
789 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
790 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
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, "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;
856 delete m_pickerLayout;
858 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
859 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
861 if (inputValue && strlen(inputValue)) {
862 char tmpInputValue[30] = {0,};
864 sprintf(tmpInputValue, "%s", inputValue);
865 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
866 strcpy(dateStr.mon, strtok(0, "-"));
868 currentTime->tm_year = atoi(dateStr.year);
869 currentTime->tm_mon = atoi(dateStr.mon);
871 currentTime->tm_year = currentTime->tm_year - 1900;
872 currentTime->tm_mon = currentTime->tm_mon - 1;
876 const char* type = elm_object_widget_type_get(parent);
878 if (!strcmp(type, "win")) {
883 parent = elm_object_parent_widget_get(parent);
889 m_pickerLayout->popup = elm_popup_add(win);
891 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
893 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
894 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
896 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
897 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
899 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
901 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Month (Default format) :");
903 elm_datetime_format_set(m_pickerLayout->datePicker, "%Y -%m");
904 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
906 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
907 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
908 elm_object_text_set(m_pickerLayout->okButton, "OK");
909 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
910 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
912 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
913 evas_object_show(m_pickerLayout->popup);
916 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
918 struct tm* currentTime;
921 currentTime = localtime(&cur_time);
923 Input_Date_Str dateStr;
924 memset(&dateStr, 0, sizeof(Input_Date_Str));
926 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
927 Evas_Object* win = parent;
930 delete m_pickerLayout;
932 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
933 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
935 m_pickerLayout->datetimeLocal = local;
937 if (inputValue && strlen(inputValue)) {
938 char tmpInputValue[30] = {0, };
940 sprintf(tmpInputValue, "%s", inputValue);
941 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
942 strcpy(dateStr.mon, strtok(0, "-"));
943 strcpy(dateStr.day, strtok(0, "T"));
944 strcpy(dateStr.hour, strtok(0, ":"));
946 if (m_pickerLayout->datetimeLocal)
947 strcpy(dateStr.min, strtok(0, "Z"));
949 strcpy(dateStr.min, strtok(0, ":"));
951 currentTime->tm_year = atoi(dateStr.year);
952 currentTime->tm_mon = atoi(dateStr.mon);
953 currentTime->tm_mday = atoi(dateStr.day);
954 currentTime->tm_hour = atoi(dateStr.hour);
955 currentTime->tm_min = atoi(dateStr.min);
957 currentTime->tm_year = currentTime->tm_year - 1900;
958 currentTime->tm_mon = currentTime->tm_mon - 1;
962 const char* type = elm_object_widget_type_get(parent);
964 if (!strcmp(type, "win")) {
969 parent = elm_object_parent_widget_get(parent);
975 m_pickerLayout->popup = elm_popup_add(win);
976 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
978 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
979 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
980 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
982 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
983 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
985 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
986 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
987 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
988 elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
990 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
991 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
992 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
993 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
995 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
996 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
997 elm_object_text_set(m_pickerLayout->okButton, "OK");
998 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
1000 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
1001 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
1002 evas_object_show(m_pickerLayout->popup);
1006 void InputPicker::_date_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1008 struct tm currentTime;
1009 memset(¤tTime, 0, sizeof(struct tm));
1011 char dateStr[20] = {0, };
1013 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1015 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1017 date.day = currentTime.tm_mday;
1018 date.mon = currentTime.tm_mon;
1019 date.year = currentTime.tm_year;
1021 if(inputPicker->m_pickerLayout->popup){
1022 evas_object_del(inputPicker->m_pickerLayout->popup);
1023 inputPicker->m_pickerLayout->popup = 0;
1026 date.year = 1900 + date.year;
1027 sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1029 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1031 delete inputPicker->m_pickerLayout;
1032 inputPicker->m_pickerLayout = 0;
1035 void InputPicker::_week_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1037 struct tm currentTime;
1038 memset(¤tTime, 0, sizeof(struct tm));
1040 char dateStr[20] = {0, };
1042 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1044 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1046 date.day = currentTime.tm_mday;
1047 date.mon = currentTime.tm_mon;
1048 date.year = currentTime.tm_year;
1049 mktime(¤tTime);
1051 if(inputPicker->m_pickerLayout->popup){
1052 evas_object_del(inputPicker->m_pickerLayout->popup);
1053 inputPicker->m_pickerLayout->popup = 0;
1056 struct tm firtTimeOfyear;
1057 memset(&firtTimeOfyear, 0, sizeof(struct tm));
1058 firtTimeOfyear.tm_year = date.year;
1059 firtTimeOfyear.tm_mon = 0;
1060 firtTimeOfyear.tm_mday = 1;
1061 mktime(&firtTimeOfyear);
1063 char firstWeek[10] = {0, };
1064 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1065 int firstWeekCount = atoi(firstWeek);
1067 char totalDay[10] = {0, };
1068 strftime(totalDay, 10, "%j", ¤tTime);
1069 int totalDayCount = atoi(totalDay);
1071 int weekNum = (totalDayCount + firstWeekCount) / 7;
1072 if (totalDayCount + firstWeekCount > weekNum * 7)
1075 date.year = 1900 + date.year;
1076 sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1078 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1080 delete inputPicker->m_pickerLayout;
1081 inputPicker->m_pickerLayout = 0;
1084 void InputPicker::_time_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1086 struct tm currentTime;
1087 memset(¤tTime, 0, sizeof(struct tm));
1089 char dateStr[20] = {0, };
1091 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1093 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1095 date.hour = currentTime.tm_hour;
1096 date.min = currentTime.tm_min;
1098 if(inputPicker->m_pickerLayout->popup){
1099 evas_object_del(inputPicker->m_pickerLayout->popup);
1100 inputPicker->m_pickerLayout->popup = 0;
1103 sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1104 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1106 delete inputPicker->m_pickerLayout;
1107 inputPicker->m_pickerLayout = 0;
1110 void InputPicker::_month_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1112 struct tm currentTime;
1113 memset(¤tTime, 0, sizeof(struct tm));
1115 char dateStr[20] = {0, };
1117 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1119 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1121 date.mon = currentTime.tm_mon;
1122 date.year = currentTime.tm_year;
1124 if(inputPicker->m_pickerLayout->popup){
1125 evas_object_del(inputPicker->m_pickerLayout->popup);
1126 inputPicker->m_pickerLayout->popup = 0;
1129 date.year = 1900 + date.year;
1130 sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1132 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1134 delete inputPicker->m_pickerLayout;
1135 inputPicker->m_pickerLayout = 0;
1138 void InputPicker::_datetime_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
1140 struct tm currentTime;
1141 memset(¤tTime, 0, sizeof(struct tm));
1143 char dateStr[50] = {0, };
1145 InputPicker* inputPicker = static_cast<InputPicker*>(data);
1147 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
1148 date.year = currentTime.tm_year;
1149 date.day = currentTime.tm_mday;
1150 date.mon = currentTime.tm_mon;
1152 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
1153 date.hour = currentTime.tm_hour;
1154 date.min = currentTime.tm_min;
1156 if (inputPicker->m_pickerLayout->popup) {
1157 evas_object_del(inputPicker->m_pickerLayout->popup);
1158 inputPicker->m_pickerLayout->popup = 0;
1161 date.year = 1900 + date.year;
1163 if (inputPicker->m_pickerLayout->datetimeLocal)
1164 sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
1166 sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1168 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1170 delete inputPicker->m_pickerLayout;
1171 inputPicker->m_pickerLayout = 0;
1174 } // namespace WebKit
1176 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)