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)
42 InputPicker::~InputPicker()
45 if (m_pickerLayout->popup)
46 evas_object_del(m_pickerLayout->popup);
47 delete m_pickerLayout;
51 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
53 if(inputType == EWK_INPUT_TYPE_DATE)
54 ewk_date_popup(inputValue);
55 else if(inputType == EWK_INPUT_TYPE_TIME)
56 ewk_time_popup(inputValue);
57 else if(inputType == EWK_INPUT_TYPE_DATETIME)
58 ewk_datetime_popup(inputValue, false);
59 else if(inputType == EWK_INPUT_TYPE_DATETIMELOCAL)
60 ewk_datetime_popup(inputValue, true);
61 else if(inputType == EWK_INPUT_TYPE_MONTH)
62 ewk_month_popup(inputValue);
63 else if(inputType == EWK_INPUT_TYPE_WEEK)
64 ewk_week_popup(inputValue);
65 else if(inputType == EWK_INPUT_TYPE_COLOR)
66 ewk_color_popup(inputValue);
69 #if ENABLE(TIZEN_DATALIST_ELEMENT)
70 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
72 // FIXME: Show DataList UI.
75 void InputPicker::hideDataList(Ewk_Input_Type inputType)
77 // FIXME: Close DataList UI.
81 #if ENABLE(ELM_COLORPALLETE)
82 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
88 Elm_Object_Item *color_it = static_cast<Elm_Object_Item*>(eventInfo);
89 elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
90 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b , a);
94 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
100 evas_object_color_get(obj, &r, &g, &b, &a);
102 evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
105 void InputPicker::ewk_color_popup(const char* inputValue)
107 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
108 Evas_Object* win = parent;
111 delete m_pickerLayout;
113 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
114 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
117 const char* type = elm_object_widget_type_get(parent);
119 if (!strcmp(type, "win")) {
124 parent = elm_object_parent_widget_get(parent);
130 m_pickerLayout->popup = elm_popup_add(win);
131 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
133 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
134 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","color_picker");
135 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136 evas_object_show(m_pickerLayout->layout);
137 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
139 m_pickerLayout->colorRect = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
140 evas_object_size_hint_weight_set(m_pickerLayout->colorRect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
141 evas_object_show(m_pickerLayout->colorRect);
150 colorR[0] = inputValue[1];
151 colorR[1] = inputValue[2];
152 colorG[0] = inputValue[3];
153 colorG[1] = inputValue[4];
154 colorB[0] = inputValue[5];
155 colorB[1] = inputValue[6];
161 decR = static_cast<int>(strtol(colorR, 0, 16));
162 decG = static_cast<int>(strtol(colorG, 0, 16));
163 decB = static_cast<int>(strtol(colorB, 0, 16));
165 printf("\n<<<<<<<< colorR = [%s], colorG = [%s], colorB = [%s] >>>>>>>>>>\n", colorR, colorG, colorB);
166 printf("\n<<<<<<<< decR = [%d], decG = [%d], decB = [%d] >>>>>>>>>>\n", decR, decG, decB);
168 evas_object_color_set(m_pickerLayout->colorRect, decR, decG, decB, 255);
169 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_rect", m_pickerLayout->colorRect);
170 #if ENABLE(ELM_COLORPALLETE)
171 Evas_Object* colorPalette = elm_colorselector_add(m_pickerLayout->popup);
172 elm_colorselector_mode_set(colorPalette, ELM_COLORSELECTOR_PALETTE);
174 elm_colorselector_palette_color_add(colorPalette, 128, 0, 0, 255);
175 elm_colorselector_palette_color_add(colorPalette, 255, 0, 128, 255);
176 elm_colorselector_palette_color_add(colorPalette, 255, 0, 0, 255);
177 elm_colorselector_palette_color_add(colorPalette, 255, 127, 39, 255);
178 elm_colorselector_palette_color_add(colorPalette, 255, 255, 0, 255);
179 elm_colorselector_palette_color_add(colorPalette, 0, 255, 0, 255);
180 elm_colorselector_palette_color_add(colorPalette, 0, 255, 255, 255);
181 elm_colorselector_palette_color_add(colorPalette, 0, 0, 255, 255);
182 elm_colorselector_palette_color_add(colorPalette, 0, 0, 128, 255);
183 elm_colorselector_palette_color_add(colorPalette, 64, 0, 64, 255);
184 elm_colorselector_palette_color_add(colorPalette, 0, 0, 0, 255);
185 elm_colorselector_palette_color_add(colorPalette, 255, 255, 255, 255);
187 evas_object_size_hint_fill_set(colorPalette, EVAS_HINT_FILL, 0);
188 evas_object_size_hint_weight_set(colorPalette, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
189 evas_object_smart_callback_add(colorPalette, "color,item,selected", _color_palette_changed_cb, m_pickerLayout->colorRect);
190 evas_object_show(colorPalette);
192 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
194 Evas_Object* color1 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
195 evas_object_size_hint_weight_set(color1, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
196 evas_object_color_set(color1, 128, 0, 0, 255);
197 evas_object_event_callback_add(color1, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
198 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color1", color1);
199 evas_object_show(color1);
201 Evas_Object* color2 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
202 evas_object_size_hint_weight_set(color2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
203 evas_object_color_set(color2, 255, 0, 128, 255);
204 evas_object_event_callback_add(color2, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
205 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color2", color2);
206 evas_object_show(color2);
208 Evas_Object* color3 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
209 evas_object_size_hint_weight_set(color3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
210 evas_object_color_set(color3, 255, 0, 0, 255);
211 evas_object_event_callback_add(color3, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
212 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color3", color3);
213 evas_object_show(color3);
215 Evas_Object* color4 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
216 evas_object_size_hint_weight_set(color4, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217 evas_object_color_set(color4, 255, 127, 39, 255);
218 evas_object_event_callback_add(color4, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
219 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color4", color4);
220 evas_object_show(color4);
222 Evas_Object* color5 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
223 evas_object_size_hint_weight_set(color5, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
224 evas_object_color_set(color5, 255, 255, 0, 255);
225 evas_object_event_callback_add(color5, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
226 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color5", color5);
227 evas_object_show(color5);
229 Evas_Object* color6 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
230 evas_object_size_hint_weight_set(color6, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
231 evas_object_color_set(color6, 0, 255, 0, 255);
232 evas_object_event_callback_add(color6, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
233 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color6", color6);
234 evas_object_show(color6);
236 Evas_Object* color7 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
237 evas_object_size_hint_weight_set(color7, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
238 evas_object_color_set(color7, 0, 255, 255, 255);
239 evas_object_event_callback_add(color7, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
240 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color7", color7);
241 evas_object_show(color7);
243 Evas_Object* color8 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
244 evas_object_size_hint_weight_set(color8, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
245 evas_object_color_set(color8, 0, 0, 255, 255);
246 evas_object_event_callback_add(color8, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
247 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color8", color8);
248 evas_object_show(color8);
250 Evas_Object* color9 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
251 evas_object_size_hint_weight_set(color9, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
252 evas_object_color_set(color9, 0, 0, 128, 255);
253 evas_object_event_callback_add(color9, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
254 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color9", color9);
255 evas_object_show(color9);
257 Evas_Object* color10 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
258 evas_object_size_hint_weight_set(color10, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
259 evas_object_color_set(color10, 64, 0, 64, 255);
260 evas_object_event_callback_add(color10, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
261 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color10", color10);
262 evas_object_show(color10);
264 Evas_Object* color11 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
265 evas_object_size_hint_weight_set(color11, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
266 evas_object_color_set(color11, 153, 217, 234, 255);
267 evas_object_event_callback_add(color11, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
268 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color11", color11);
269 evas_object_show(color11);
271 Evas_Object* color12 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
272 evas_object_size_hint_weight_set(color12, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
273 evas_object_color_set(color12, 128, 128, 128, 255);
274 evas_object_event_callback_add(color12, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
275 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color12", color12);
276 evas_object_show(color12);
278 Evas_Object* color13 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
279 evas_object_size_hint_weight_set(color13, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
280 evas_object_color_set(color13, 0, 0, 0, 255);
281 evas_object_event_callback_add(color13, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
282 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color13", color13);
283 evas_object_show(color13);
285 Evas_Object* color14 = evas_object_rectangle_add(evas_object_evas_get(m_pickerLayout->layout));
286 evas_object_size_hint_weight_set(color14, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
287 evas_object_color_set(color14, 255, 255, 255, 255);
288 evas_object_event_callback_add(color14, EVAS_CALLBACK_MOUSE_DOWN, _color_selected_cb, m_pickerLayout->colorRect);
289 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color14", color14);
290 evas_object_show(color14);
292 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
293 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
294 elm_object_text_set(m_pickerLayout->okButton, "OK");
295 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
296 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _color_popup_response_cb, this);
298 evas_object_show(m_pickerLayout->popup);
301 void InputPicker::_color_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
303 InputPicker* inputPicker = static_cast<InputPicker*>(data);
309 evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
311 char selectColor[10];
312 selectColor[10] = '\0';
313 sprintf(selectColor, "#%02x%02x%02x", r, g, b);
315 ewk_view_color_chooser_color_set(inputPicker->m_ewkView, selectColor);
316 ewk_view_color_chooser_close(inputPicker->m_ewkView);
318 if(inputPicker->m_pickerLayout->popup){
319 evas_object_del(inputPicker->m_pickerLayout->popup);
320 inputPicker->m_pickerLayout->popup = 0;
323 delete inputPicker->m_pickerLayout;
324 inputPicker->m_pickerLayout = 0;
327 void InputPicker::ewk_date_popup(const char* inputValue)
329 struct tm* currentTime;
332 currentTime = localtime(&cur_time);
334 Input_Date_Str dateStr;
335 memset(&dateStr, 0, sizeof(Input_Date_Str));
337 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
338 Evas_Object* win = parent;
341 delete m_pickerLayout;
343 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
344 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
346 if (inputValue && strlen(inputValue)) {
347 char tmpinputValue[30] = {0,};
349 sprintf(tmpinputValue, "%s", inputValue);
350 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
351 strcpy(dateStr.mon, strtok(0, "-"));
352 strcpy(dateStr.day, strtok(0, "-"));
354 currentTime->tm_year = atoi(dateStr.year);
355 currentTime->tm_mon = atoi(dateStr.mon);
356 currentTime->tm_mday = atoi(dateStr.day);
358 currentTime->tm_year = currentTime->tm_year - 1900;
359 currentTime->tm_mon = currentTime->tm_mon - 1;
363 const char* type = elm_object_widget_type_get(parent);
365 if (!strcmp(type, "win")) {
370 parent = elm_object_parent_widget_get(parent);
376 m_pickerLayout->popup = elm_popup_add(win);
377 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
379 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
380 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
381 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
383 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
385 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
386 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
388 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
389 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
390 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
391 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
393 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
394 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
395 elm_object_text_set(m_pickerLayout->okButton, "OK");
396 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
397 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _date_popup_response_cb, this);
399 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
400 evas_object_show(m_pickerLayout->popup);
403 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
404 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
407 if (totalDays - 31 < 0) {
408 *remains = totalDays;
412 totalDays = totalDays - 31;
415 if (isLeapYear(year)) {
416 if (totalDays - 29 < 0) {
417 *remains = totalDays;
420 totalDays = totalDays - 29;
422 if (totalDays - 28 < 0) {
423 *remains = totalDays;
426 totalDays = totalDays - 28;
430 if (totalDays - 31 < 0) {
431 *remains = totalDays;
434 totalDays = totalDays - 31;
437 if (totalDays - 30 < 0) {
438 *remains = totalDays;
441 totalDays = totalDays - 30;
444 if (totalDays - 31 < 0) {
445 *remains = totalDays;
448 totalDays = totalDays - 31;
451 if (totalDays - 30 < 0) {
452 *remains = totalDays;
455 totalDays = totalDays - 30;
458 if (totalDays - 31 < 0) {
459 *remains = totalDays;
462 totalDays = totalDays - 31;
465 if (totalDays - 31 < 0) {
466 *remains = totalDays;
469 totalDays = totalDays - 31;
472 if (totalDays - 30 < 0) {
473 *remains = totalDays;
476 totalDays = totalDays - 30;
479 if (totalDays - 31 < 0) {
480 *remains = totalDays;
483 totalDays = totalDays - 31;
486 if (totalDays - 30 < 0) {
487 *remains = totalDays;
490 totalDays = totalDays - 30;
492 *remains = totalDays;
496 void InputPicker::ewk_week_popup(const char* inputValue)
498 struct tm* currentTime;
501 currentTime = localtime(&cur_time);
503 Input_Date_Str dateStr;
504 memset(&dateStr, 0, sizeof(Input_Date_Str));
506 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
507 Evas_Object* win = parent;
510 delete m_pickerLayout;
512 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
513 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
515 if (inputValue && strlen(inputValue)) {
516 char tmpinputValue[30] = {0,};
518 sprintf(tmpinputValue, "%s", inputValue);
519 strcpy(dateStr.year, strtok(tmpinputValue,"-"));
520 const char* week = strstr(inputValue, "W");
523 weekNum = atoi(week + 1);
525 currentTime->tm_year = atoi(dateStr.year);
526 currentTime->tm_year = currentTime->tm_year - 1900;
528 struct tm firtTimeOfyear;
529 memset(&firtTimeOfyear, 0, sizeof(struct tm));
530 firtTimeOfyear.tm_year = currentTime->tm_year;
531 firtTimeOfyear.tm_mon = 0;
532 firtTimeOfyear.tm_mday = 1;
533 mktime(&firtTimeOfyear);
535 char firstWeek[10] = {0, };
536 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
537 int firstWeekCount = atoi(firstWeek);
541 totalDays = weekNum * 7 - firstWeekCount;
544 int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
546 currentTime->tm_mon = month;
547 currentTime->tm_mday = days;
551 const char* type = elm_object_widget_type_get(parent);
553 if (!strcmp(type, "win")) {
558 parent = elm_object_parent_widget_get(parent);
564 m_pickerLayout->popup = elm_popup_add(win);
565 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
567 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
568 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
569 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
571 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
573 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
574 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
576 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_HOUR, EINA_FALSE);
577 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_MINUTE, EINA_FALSE);
578 elm_datetime_field_visible_set(m_pickerLayout->datePicker, ELM_DATETIME_AMPM, EINA_FALSE);
579 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
581 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
582 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
583 elm_object_text_set(m_pickerLayout->okButton, "OK");
584 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
585 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _week_popup_response_cb, this);
587 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
588 evas_object_show(m_pickerLayout->popup);
591 void InputPicker::ewk_time_popup(const char* inputValue)
593 struct tm* currentTime;
596 currentTime = localtime(&cur_time);
598 Input_Date_Str dateStr;
599 memset(&dateStr, 0, sizeof(Input_Date_Str));
601 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
602 Evas_Object* win = parent;
605 delete m_pickerLayout;
607 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
608 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
610 if (inputValue && strlen(inputValue)) {
611 char tmpinputValue[30] = {0,};
613 sprintf(tmpinputValue, "%s", inputValue);
614 strcpy(dateStr.hour, strtok(tmpinputValue,":"));
615 strcpy(dateStr.min, strtok(0, ":"));
617 currentTime->tm_hour = atoi(dateStr.hour);
618 currentTime->tm_min = atoi(dateStr.min);
622 const char* type = elm_object_widget_type_get(parent);
624 if (!strcmp(type, "win")) {
629 parent = elm_object_parent_widget_get(parent);
635 m_pickerLayout->popup = elm_popup_add(win);
636 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
638 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
639 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
640 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
642 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
644 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
645 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
646 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
648 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
650 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
651 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
652 elm_object_text_set(m_pickerLayout->okButton, "OK");
653 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
655 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _time_popup_response_cb, this);
656 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
657 evas_object_show(m_pickerLayout->popup);
660 void InputPicker::ewk_month_popup(const char* inputValue)
662 struct tm* currentTime;
665 currentTime = localtime(&cur_time);
667 Input_Date_Str dateStr;
668 memset(&dateStr, 0, sizeof(Input_Date_Str));
670 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
671 Evas_Object* win = parent;
674 delete m_pickerLayout;
676 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
677 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
679 if (inputValue && strlen(inputValue)) {
680 char tmpInputValue[30] = {0,};
682 sprintf(tmpInputValue, "%s", inputValue);
683 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
684 strcpy(dateStr.mon, strtok(0, "-"));
686 currentTime->tm_year = atoi(dateStr.year);
687 currentTime->tm_mon = atoi(dateStr.mon);
689 currentTime->tm_year = currentTime->tm_year - 1900;
690 currentTime->tm_mon = currentTime->tm_mon - 1;
694 const char* type = elm_object_widget_type_get(parent);
696 if (!strcmp(type, "win")) {
701 parent = elm_object_parent_widget_get(parent);
707 m_pickerLayout->popup = elm_popup_add(win);
709 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
711 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
712 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
714 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
715 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
717 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
719 edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Month (Default format) :");
721 elm_datetime_format_set(m_pickerLayout->datePicker, "%Y -%m");
722 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->datePicker);
724 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
725 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
726 elm_object_text_set(m_pickerLayout->okButton, "OK");
727 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
728 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _month_popup_response_cb, this);
730 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
731 evas_object_show(m_pickerLayout->popup);
734 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
736 struct tm* currentTime;
739 currentTime = localtime(&cur_time);
741 Input_Date_Str dateStr;
742 memset(&dateStr, 0, sizeof(Input_Date_Str));
744 Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
745 Evas_Object* win = parent;
748 delete m_pickerLayout;
750 m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
751 memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
753 m_pickerLayout->datetimeLocal = local;
755 if (inputValue && strlen(inputValue)) {
756 char tmpInputValue[30] = {0, };
758 sprintf(tmpInputValue, "%s", inputValue);
759 strcpy(dateStr.year, strtok(tmpInputValue,"-"));
760 strcpy(dateStr.mon, strtok(0, "-"));
761 strcpy(dateStr.day, strtok(0, "T"));
762 strcpy(dateStr.hour, strtok(0, ":"));
764 if (m_pickerLayout->datetimeLocal)
765 strcpy(dateStr.min, strtok(0, "Z"));
767 strcpy(dateStr.min, strtok(0, ":"));
769 currentTime->tm_year = atoi(dateStr.year);
770 currentTime->tm_mon = atoi(dateStr.mon);
771 currentTime->tm_mday = atoi(dateStr.day);
772 currentTime->tm_hour = atoi(dateStr.hour);
773 currentTime->tm_min = atoi(dateStr.min);
775 currentTime->tm_year = currentTime->tm_year - 1900;
776 currentTime->tm_mon = currentTime->tm_mon - 1;
780 const char* type = elm_object_widget_type_get(parent);
782 if (!strcmp(type, "win")) {
787 parent = elm_object_parent_widget_get(parent);
793 m_pickerLayout->popup = elm_popup_add(win);
794 elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
796 m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
797 elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","datepicker_popup");
798 evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
800 m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
801 elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
803 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_HOUR, EINA_FALSE);
804 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_MINUTE, EINA_FALSE);
805 elm_datetime_field_visible_set(m_pickerLayout->datePicker , ELM_DATETIME_AMPM, EINA_FALSE);
806 elm_object_part_content_set(m_pickerLayout->layout , "elm.swallow.content.date", m_pickerLayout->datePicker);
808 m_pickerLayout->timePicker = elm_datetime_add(m_pickerLayout->layout);
809 elm_datetime_format_set(m_pickerLayout->timePicker, "%H:%M");
810 elm_datetime_value_set(m_pickerLayout->timePicker, currentTime);
811 elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.time", m_pickerLayout->timePicker);
813 m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
814 elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
815 elm_object_text_set(m_pickerLayout->okButton, "OK");
816 elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
818 evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _datetime_popup_response_cb, this);
819 elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
820 evas_object_show(m_pickerLayout->popup);
824 void InputPicker::_date_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
826 struct tm currentTime;
827 memset(¤tTime, 0, sizeof(struct tm));
829 char dateStr[20] = {0, };
831 InputPicker* inputPicker = static_cast<InputPicker*>(data);
833 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
835 date.day = currentTime.tm_mday;
836 date.mon = currentTime.tm_mon;
837 date.year = currentTime.tm_year;
839 if(inputPicker->m_pickerLayout->popup){
840 evas_object_del(inputPicker->m_pickerLayout->popup);
841 inputPicker->m_pickerLayout->popup = 0;
844 date.year = 1900 + date.year;
845 sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
847 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
849 delete inputPicker->m_pickerLayout;
850 inputPicker->m_pickerLayout = 0;
853 void InputPicker::_week_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
855 struct tm currentTime;
856 memset(¤tTime, 0, sizeof(struct tm));
858 char dateStr[20] = {0, };
860 InputPicker* inputPicker = static_cast<InputPicker*>(data);
862 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
864 date.day = currentTime.tm_mday;
865 date.mon = currentTime.tm_mon;
866 date.year = currentTime.tm_year;
867 mktime(¤tTime);
869 if(inputPicker->m_pickerLayout->popup){
870 evas_object_del(inputPicker->m_pickerLayout->popup);
871 inputPicker->m_pickerLayout->popup = 0;
874 struct tm firtTimeOfyear;
875 memset(&firtTimeOfyear, 0, sizeof(struct tm));
876 firtTimeOfyear.tm_year = date.year;
877 firtTimeOfyear.tm_mon = 0;
878 firtTimeOfyear.tm_mday = 1;
879 mktime(&firtTimeOfyear);
881 char firstWeek[10] = {0, };
882 strftime(firstWeek, 10, "%w", &firtTimeOfyear);
883 int firstWeekCount = atoi(firstWeek);
885 char totalDay[10] = {0, };
886 strftime(totalDay, 10, "%j", ¤tTime);
887 int totalDayCount = atoi(totalDay);
889 int weekNum = (totalDayCount + firstWeekCount) / 7;
890 if (totalDayCount + firstWeekCount > weekNum * 7)
893 date.year = 1900 + date.year;
894 sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
896 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
898 delete inputPicker->m_pickerLayout;
899 inputPicker->m_pickerLayout = 0;
902 void InputPicker::_time_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
904 struct tm currentTime;
905 memset(¤tTime, 0, sizeof(struct tm));
907 char dateStr[20] = {0, };
909 InputPicker* inputPicker = static_cast<InputPicker*>(data);
911 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
913 date.hour = currentTime.tm_hour;
914 date.min = currentTime.tm_min;
916 if(inputPicker->m_pickerLayout->popup){
917 evas_object_del(inputPicker->m_pickerLayout->popup);
918 inputPicker->m_pickerLayout->popup = 0;
921 sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
922 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
924 delete inputPicker->m_pickerLayout;
925 inputPicker->m_pickerLayout = 0;
928 void InputPicker::_month_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
930 struct tm currentTime;
931 memset(¤tTime, 0, sizeof(struct tm));
933 char dateStr[20] = {0, };
935 InputPicker* inputPicker = static_cast<InputPicker*>(data);
937 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
939 date.mon = currentTime.tm_mon;
940 date.year = currentTime.tm_year;
942 if(inputPicker->m_pickerLayout->popup){
943 evas_object_del(inputPicker->m_pickerLayout->popup);
944 inputPicker->m_pickerLayout->popup = 0;
947 date.year = 1900 + date.year;
948 sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
950 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
952 delete inputPicker->m_pickerLayout;
953 inputPicker->m_pickerLayout = 0;
956 void InputPicker::_datetime_popup_response_cb(void* data, Evas_Object* obj, void* event_info)
958 struct tm currentTime;
959 memset(¤tTime, 0, sizeof(struct tm));
961 char dateStr[50] = {0, };
963 InputPicker* inputPicker = static_cast<InputPicker*>(data);
965 elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, ¤tTime);
966 date.year = currentTime.tm_year;
967 date.day = currentTime.tm_mday;
968 date.mon = currentTime.tm_mon;
970 elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, ¤tTime);
971 date.hour = currentTime.tm_hour;
972 date.min = currentTime.tm_min;
974 if (inputPicker->m_pickerLayout->popup) {
975 evas_object_del(inputPicker->m_pickerLayout->popup);
976 inputPicker->m_pickerLayout->popup = 0;
979 date.year = 1900 + date.year;
981 if (inputPicker->m_pickerLayout->datetimeLocal)
982 sprintf(dateStr, "%d-%02d-%02dT%02d:%02d" , date.year, date.mon + 1, date.day, date.hour, date.min);
984 sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
986 ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
988 delete inputPicker->m_pickerLayout;
989 inputPicker->m_pickerLayout = 0;
992 } // namespace WebKit
994 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)