[Title] Implement input data list picker.
[profile/ivi/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / InputPicker.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include "InputPicker.h"
22
23 #include "ewk_view.h"
24
25 #include <Elementary.h>
26
27 #include <ctime>
28 #include <stdlib.h>
29 #include <string.h>
30
31
32 #if OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)
33
34 namespace WebKit {
35
36 InputPicker::InputPicker(Evas_Object* ewkView)
37     : m_ewkView(ewkView)
38     , m_pickerLayout(0)
39     , m_dataList(0)
40 {
41 }
42
43 InputPicker::~InputPicker()
44 {
45     if (m_pickerLayout) {
46         if (m_pickerLayout->popup)
47             evas_object_del(m_pickerLayout->popup);
48         delete m_pickerLayout;
49     }
50 }
51
52 void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
53 {
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);
68 }
69
70 #if ENABLE(TIZEN_DATALIST_ELEMENT)
71 void InputPicker::_data_list_popup_response_cb(void* data,  Evas_Object* obj, void* eventInfo)
72 {
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);
76
77     if (inputPicker->m_pickerLayout->popup) {
78         evas_object_del(inputPicker->m_pickerLayout->popup);
79         inputPicker->m_pickerLayout->popup = 0;
80     }
81
82     delete inputPicker->m_pickerLayout;
83     inputPicker->m_pickerLayout = 0;
84
85     inputPicker->m_dataList = 0;
86 }
87
88 void InputPicker::_data_list_popup_response_cancel_cb(void* data,  Evas_Object* obj, void* eventInfo)
89 {
90     InputPicker* inputPicker = static_cast<InputPicker*>(data);
91
92     if (inputPicker->m_pickerLayout->popup) {
93         evas_object_del(inputPicker->m_pickerLayout->popup);
94         inputPicker->m_pickerLayout->popup = 0;
95     }
96
97     delete inputPicker->m_pickerLayout;
98     inputPicker->m_pickerLayout = 0;
99
100     inputPicker->m_dataList = 0;
101 }
102
103 void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
104 {
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);
108
109     int index = 0;
110     while (item) {
111         if (item == selectedItem)
112             break;
113         index++;
114         item = elm_list_item_next(item);
115     }
116
117     Eina_List* list = 0;
118     void* listItem = 0;
119     int listIndex = 0;
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));
123
124         listIndex++;
125     }
126 }
127
128 static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
129 {
130     Evas_Object* entry = static_cast<Evas_Object*>(data);
131     elm_entry_entry_set(entry, "");
132 }
133
134 static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
135 {
136     Evas_Object* layout = static_cast<Evas_Object*>(data);
137
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");
141         else
142             elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
143     }
144 }
145
146 static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
147 {
148     Evas_Object* layout = static_cast<Evas_Object*>(data);
149
150     if (!elm_entry_is_empty(obj))
151         elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
152 }
153
154 static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
155 {
156     Evas_Object* layout = static_cast<Evas_Object*>(data);
157     elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
158 }
159
160 void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
161 {
162     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
163     Evas_Object* win = parent;
164
165     m_dataList = optionList;
166
167     if (m_pickerLayout)
168         delete m_pickerLayout;
169
170     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
171     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
172
173     while (parent) {
174         const char* type = elm_object_widget_type_get(parent);
175         if (type) {
176             if (!strcmp(type, "win")) {
177                 win =  parent;
178                 break;
179             }
180         }
181         parent = elm_object_parent_widget_get(parent);
182     }
183
184     if (!win)
185         win = m_ewkView;
186
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);
192
193     Evas_Object* dummyLaout = elm_layout_add(conformant);
194     elm_object_content_set(conformant, dummyLaout);
195
196     m_pickerLayout->popup = elm_popup_add(dummyLaout);
197     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
198
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);
204
205     Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
206     Eina_List* list = 0;
207     void* listItem = 0;
208     EINA_LIST_FOREACH(optionList, list, listItem) {
209         if (listItem)
210             elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
211     }
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);
215
216     Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
217     elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
218
219     m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
220     elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
221
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);
227
228     elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
229     evas_object_show(editFieldLayout);
230
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);
237
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);
244 }
245
246 void InputPicker::hideDataList(Ewk_Input_Type inputType)
247 {
248     if (!m_dataList)
249         return;
250
251     if(m_pickerLayout->popup){
252         evas_object_del(m_pickerLayout->popup);
253         m_pickerLayout->popup = 0;
254     }
255
256     delete m_pickerLayout;
257     m_pickerLayout = 0;
258
259     m_dataList = 0;
260 }
261 #endif
262
263 #if ENABLE(ELM_COLORPALLETE)
264 static void _color_palette_changed_cb(void* data, Evas_Object* obj, void* eventInfo)
265 {
266     int r = 0;
267     int g = 0;
268     int b = 0;
269     int a = 0;
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);
273 }
274 #endif
275
276 void InputPicker::_color_selected_cb(void* data, Evas* evas, Evas_Object* obj, void* eventInfo)
277 {
278     int r = 0;
279     int g = 0;
280     int b = 0;
281     int a = 0;
282     evas_object_color_get(obj, &r, &g, &b, &a);
283
284     evas_object_color_set(static_cast<Evas_Object*>(data), r, g, b, a);
285 }
286
287 void InputPicker::ewk_color_popup(const char* inputValue)
288 {
289     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
290     Evas_Object* win = parent;
291
292     if (m_pickerLayout)
293         delete m_pickerLayout;
294
295     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
296     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
297
298     while (parent) {
299         const char* type = elm_object_widget_type_get(parent);
300         if (type) {
301             if (!strcmp(type, "win")) {
302                 win =  parent;
303                 break;
304             }
305         }
306         parent = elm_object_parent_widget_get(parent);
307     }
308
309     if (!win)
310     win = m_ewkView;
311
312     m_pickerLayout->popup = elm_popup_add(win);
313     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select color");
314
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);
320
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);
324
325     char colorR[3];
326     colorR[2] = '\0';
327     char colorG[3];
328     colorG[2] = '\0';
329     char colorB[3];
330     colorB[2] = '\0';
331
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];
338
339     int decR = 0;
340     int decG = 0;
341     int decB = 0;
342
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));
346
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);
349
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);
355
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);
368
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);
373
374     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.color_palette", colorPalette);
375 #else
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);
382
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);
389
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);
396
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);
403
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);
410
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);
417
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);
424
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);
431
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);
438
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);
445
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);
452
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);
459
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);
466
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);
473 #endif
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);
479
480     evas_object_show(m_pickerLayout->popup);
481 }
482
483 void InputPicker::_color_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
484 {
485     InputPicker* inputPicker = static_cast<InputPicker*>(data);
486
487     int r = 0;
488     int g = 0;
489     int b = 0;
490     int a = 0;
491     evas_object_color_get(inputPicker->m_pickerLayout->colorRect, &r, &g, &b, &a);
492
493     char selectColor[10];
494     selectColor[10] = '\0';
495     sprintf(selectColor, "#%02x%02x%02x", r, g, b);
496
497     ewk_view_color_chooser_color_set(inputPicker->m_ewkView, selectColor);
498     ewk_view_color_chooser_close(inputPicker->m_ewkView);
499
500     if(inputPicker->m_pickerLayout->popup){
501         evas_object_del(inputPicker->m_pickerLayout->popup);
502         inputPicker->m_pickerLayout->popup = 0;
503     }
504
505     delete inputPicker->m_pickerLayout;
506     inputPicker->m_pickerLayout = 0;
507 }
508
509 void InputPicker::ewk_date_popup(const char* inputValue)
510 {
511     struct tm* currentTime;
512     time_t cur_time;
513     time(&cur_time);
514     currentTime = localtime(&cur_time);
515
516     Input_Date_Str dateStr;
517     memset(&dateStr, 0, sizeof(Input_Date_Str));
518
519     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
520     Evas_Object* win = parent;
521
522     if (m_pickerLayout)
523         delete m_pickerLayout;
524
525     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
526     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
527
528     if (inputValue && strlen(inputValue)) {
529         char tmpinputValue[30] = {0,};
530
531         sprintf(tmpinputValue, "%s", inputValue);
532         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
533         strcpy(dateStr.mon, strtok(0, "-"));
534         strcpy(dateStr.day, strtok(0, "-"));
535
536         currentTime->tm_year = atoi(dateStr.year);
537         currentTime->tm_mon = atoi(dateStr.mon);
538         currentTime->tm_mday = atoi(dateStr.day);
539
540         currentTime->tm_year = currentTime->tm_year - 1900;
541         currentTime->tm_mon = currentTime->tm_mon - 1;
542     }
543
544     while (parent) {
545         const char* type = elm_object_widget_type_get(parent);
546         if (type) {
547             if (!strcmp(type, "win")) {
548                 win =  parent;
549                 break;
550             }
551         }
552         parent = elm_object_parent_widget_get(parent);
553     }
554
555     if (!win)
556         win = m_ewkView;
557
558     m_pickerLayout->popup = elm_popup_add(win);
559     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
560
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);
564
565     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
566
567     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
568     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
569
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);
574
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);
580
581     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
582     evas_object_show(m_pickerLayout->popup);
583 }
584
585 #define isLeapYear(year) ((!(year % 4) && (year % 100)) || (!(year % 400) && (year % 1000)))
586 static int _calculateMonthAndDay(int year, int totalDays, int* remains)
587 {
588     // Jan.
589     if (totalDays - 31 < 0) {
590         *remains = totalDays;
591         return 0;
592     }
593
594     totalDays = totalDays - 31;
595
596     // Feb.
597     if (isLeapYear(year)) {
598         if (totalDays - 29 < 0) {
599             *remains = totalDays;
600             return 1;
601         }
602         totalDays = totalDays - 29;
603     } else {
604         if (totalDays - 28 < 0) {
605             *remains = totalDays;
606             return 1;
607         }
608         totalDays = totalDays - 28;
609     }
610
611     // Mar.
612     if (totalDays - 31 < 0) {
613         *remains = totalDays;
614         return 2;
615     }
616     totalDays = totalDays - 31;
617
618     // Apr.
619     if (totalDays - 30 < 0) {
620         *remains = totalDays;
621         return 3;
622     }
623     totalDays = totalDays - 30;
624
625     // May
626     if (totalDays - 31 < 0) {
627         *remains = totalDays;
628         return 4;
629     }
630     totalDays = totalDays - 31;
631
632     // Jun.
633     if (totalDays - 30 < 0) {
634         *remains = totalDays;
635         return 5;
636     }
637     totalDays = totalDays - 30;
638
639     // Jul.
640     if (totalDays - 31 < 0) {
641         *remains = totalDays;
642         return 6;
643     }
644     totalDays = totalDays - 31;
645
646     // Aug.
647     if (totalDays - 31 < 0) {
648         *remains = totalDays;
649         return 7;
650     }
651     totalDays = totalDays - 31;
652
653     // Sept.
654     if (totalDays - 30 < 0) {
655         *remains = totalDays;
656         return 8;
657     }
658     totalDays = totalDays - 30;
659
660     // Oct.
661     if (totalDays - 31 < 0) {
662         *remains = totalDays;
663         return 9;
664     }
665     totalDays = totalDays - 31;
666
667     // Nov.
668     if (totalDays - 30 < 0) {
669         *remains = totalDays;
670         return 10;
671     }
672     totalDays = totalDays - 30;
673
674     *remains = totalDays;
675     return 11;
676 }
677
678 void InputPicker::ewk_week_popup(const char* inputValue)
679 {
680     struct tm* currentTime;
681     time_t cur_time;
682     time(&cur_time);
683     currentTime = localtime(&cur_time);
684
685     Input_Date_Str dateStr;
686     memset(&dateStr, 0, sizeof(Input_Date_Str));
687
688     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
689     Evas_Object* win = parent;
690
691     if (m_pickerLayout)
692         delete m_pickerLayout;
693
694     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
695     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
696
697     if (inputValue && strlen(inputValue)) {
698         char tmpinputValue[30] = {0,};
699
700         sprintf(tmpinputValue, "%s", inputValue);
701         strcpy(dateStr.year, strtok(tmpinputValue,"-"));
702         const char* week = strstr(inputValue, "W");
703         int weekNum = 1;
704         if (week)
705             weekNum = atoi(week + 1);
706
707         currentTime->tm_year = atoi(dateStr.year);
708         currentTime->tm_year = currentTime->tm_year - 1900;
709
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);
716
717         char firstWeek[10] = {0, };
718         strftime(firstWeek, 10, "%w", &firtTimeOfyear);
719         int firstWeekCount = atoi(firstWeek);
720
721         int totalDays = 1;
722
723         totalDays = weekNum * 7 - firstWeekCount;
724
725         int days = 0;
726         int month = _calculateMonthAndDay(currentTime->tm_year, totalDays, &days);
727
728         currentTime->tm_mon = month;
729         currentTime->tm_mday = days;
730     }
731
732     while (parent) {
733         const char* type = elm_object_widget_type_get(parent);
734         if (type) {
735             if (!strcmp(type, "win")) {
736                 win =  parent;
737                 break;
738             }
739         }
740         parent = elm_object_parent_widget_get(parent);
741     }
742
743     if (!win)
744         win = m_ewkView;
745
746     m_pickerLayout->popup = elm_popup_add(win);
747     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select date");
748
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);
752
753     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Date (Default format) :");
754
755     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
756     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
757
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);
762
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);
768
769     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
770     evas_object_show(m_pickerLayout->popup);
771 }
772
773 void InputPicker::ewk_time_popup(const char* inputValue)
774 {
775     struct tm* currentTime;
776     time_t  cur_time;
777     time(&cur_time);
778     currentTime = localtime(&cur_time);
779
780     Input_Date_Str dateStr;
781     memset(&dateStr, 0, sizeof(Input_Date_Str));
782
783     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
784     Evas_Object* win = parent;
785
786     if (m_pickerLayout)
787         delete m_pickerLayout;
788
789     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
790     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
791
792     if (inputValue && strlen(inputValue)) {
793         char tmpinputValue[30] = {0,};
794
795         sprintf(tmpinputValue, "%s", inputValue);
796         strcpy(dateStr.hour, strtok(tmpinputValue,":"));
797         strcpy(dateStr.min, strtok(0, ":"));
798
799         currentTime->tm_hour = atoi(dateStr.hour);
800         currentTime->tm_min = atoi(dateStr.min);
801     }
802
803     while (parent) {
804         const char* type = elm_object_widget_type_get(parent);
805         if (type) {
806             if (!strcmp(type, "win")) {
807                 win =  parent;
808                 break;
809             }
810         }
811         parent = elm_object_parent_widget_get(parent);
812     }
813
814     if (!win)
815         win = m_ewkView;
816
817     m_pickerLayout->popup = elm_popup_add(win);
818     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select time");
819
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);
823
824     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text", "Time (Default format) :");
825
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);
829
830     elm_object_part_content_set(m_pickerLayout->layout, "elm.swallow.content.date", m_pickerLayout->timePicker);
831
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);
836
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);
840 }
841
842 void InputPicker::ewk_month_popup(const char* inputValue)
843 {
844     struct tm* currentTime;
845     time_t  cur_time;
846     time(&cur_time);
847     currentTime = localtime(&cur_time);
848
849     Input_Date_Str dateStr;
850     memset(&dateStr, 0, sizeof(Input_Date_Str));
851
852     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
853     Evas_Object* win = parent;
854
855     if (m_pickerLayout)
856         delete m_pickerLayout;
857
858     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
859     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
860
861     if (inputValue && strlen(inputValue)) {
862         char tmpInputValue[30] = {0,};
863
864         sprintf(tmpInputValue, "%s", inputValue);
865         strcpy(dateStr.year, strtok(tmpInputValue,"-"));
866         strcpy(dateStr.mon, strtok(0, "-"));
867
868         currentTime->tm_year = atoi(dateStr.year);
869         currentTime->tm_mon = atoi(dateStr.mon);
870
871         currentTime->tm_year = currentTime->tm_year - 1900;
872         currentTime->tm_mon = currentTime->tm_mon - 1;
873     }
874
875     while (parent) {
876         const char* type = elm_object_widget_type_get(parent);
877         if (type) {
878             if (!strcmp(type, "win")) {
879                 win =  parent;
880                 break;
881             }
882         }
883         parent = elm_object_parent_widget_get(parent);
884     }
885
886     if (!win)
887         win = m_ewkView;
888
889     m_pickerLayout->popup = elm_popup_add(win);
890
891     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select month");
892
893     m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
894     elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","elm/datepicker");
895
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);
898
899     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
900
901     edje_object_part_text_set(elm_layout_edje_get(m_pickerLayout->layout), "title_text",  "Month (Default format) :");
902
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);
905
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);
911
912     elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
913     evas_object_show(m_pickerLayout->popup);
914 }
915
916 void InputPicker::ewk_datetime_popup(const char* inputValue, bool local)
917 {
918     struct tm* currentTime;
919     time_t  cur_time;
920     time(&cur_time);
921     currentTime = localtime(&cur_time);
922
923     Input_Date_Str dateStr;
924     memset(&dateStr, 0, sizeof(Input_Date_Str));
925
926     Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
927     Evas_Object* win = parent;
928
929     if (m_pickerLayout)
930         delete m_pickerLayout;
931
932     m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
933     memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
934
935     m_pickerLayout->datetimeLocal = local;
936
937     if (inputValue && strlen(inputValue)) {
938         char tmpInputValue[30] = {0, };
939
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, ":"));
945
946         if (m_pickerLayout->datetimeLocal)
947             strcpy(dateStr.min, strtok(0, "Z"));
948         else
949             strcpy(dateStr.min, strtok(0, ":"));
950
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);
956
957         currentTime->tm_year = currentTime->tm_year - 1900;
958         currentTime->tm_mon = currentTime->tm_mon - 1;
959     }
960
961     while (parent) {
962         const char* type = elm_object_widget_type_get(parent);
963         if (type) {
964             if (!strcmp(type, "win")) {
965                 win =  parent;
966                 break;
967             }
968         }
969         parent = elm_object_parent_widget_get(parent);
970     }
971
972     if (!win)
973         win = m_ewkView;
974
975     m_pickerLayout->popup = elm_popup_add(win);
976     elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select datetime");
977
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);
981
982     m_pickerLayout->datePicker = elm_datetime_add(m_pickerLayout->layout);
983     elm_datetime_value_set(m_pickerLayout->datePicker, currentTime);
984
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);
989
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);
994
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);
999
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);
1003
1004 }
1005
1006 void InputPicker::_date_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1007 {
1008     struct tm currentTime;
1009     memset(&currentTime, 0, sizeof(struct tm));
1010     Input_Date date;
1011     char dateStr[20] = {0, };
1012
1013     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1014
1015     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1016
1017     date.day =  currentTime.tm_mday;
1018     date.mon = currentTime.tm_mon;
1019     date.year = currentTime.tm_year;
1020
1021     if(inputPicker->m_pickerLayout->popup){
1022         evas_object_del(inputPicker->m_pickerLayout->popup);
1023         inputPicker->m_pickerLayout->popup = 0;
1024     }
1025
1026     date.year = 1900 + date.year;
1027     sprintf(dateStr, "%d-%02d-%02d" , date.year, date.mon + 1, date.day);
1028
1029     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1030
1031     delete inputPicker->m_pickerLayout;
1032     inputPicker->m_pickerLayout = 0;
1033 }
1034
1035 void InputPicker::_week_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1036 {
1037     struct tm currentTime;
1038     memset(&currentTime, 0, sizeof(struct tm));
1039     Input_Date date;
1040     char dateStr[20] = {0, };
1041
1042     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1043
1044     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1045
1046     date.day =  currentTime.tm_mday;
1047     date.mon = currentTime.tm_mon;
1048     date.year = currentTime.tm_year;
1049     mktime(&currentTime);
1050
1051     if(inputPicker->m_pickerLayout->popup){
1052         evas_object_del(inputPicker->m_pickerLayout->popup);
1053         inputPicker->m_pickerLayout->popup = 0;
1054     }
1055
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);
1062
1063     char firstWeek[10] = {0, };
1064     strftime(firstWeek, 10, "%w", &firtTimeOfyear);
1065     int firstWeekCount = atoi(firstWeek);
1066
1067     char totalDay[10] = {0, };
1068     strftime(totalDay, 10, "%j", &currentTime);
1069     int totalDayCount = atoi(totalDay);
1070
1071     int weekNum = (totalDayCount + firstWeekCount) / 7;
1072     if (totalDayCount + firstWeekCount > weekNum * 7)
1073         weekNum++;
1074
1075     date.year = 1900 + date.year;
1076     sprintf(dateStr, "%d-W%02d" , date.year, weekNum);
1077
1078     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1079
1080     delete inputPicker->m_pickerLayout;
1081     inputPicker->m_pickerLayout = 0;
1082 }
1083
1084 void InputPicker::_time_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1085 {
1086     struct tm currentTime;
1087     memset(&currentTime, 0, sizeof(struct tm));
1088     Input_Date date;
1089     char dateStr[20] = {0, };
1090
1091     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1092
1093     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1094
1095     date.hour =  currentTime.tm_hour;
1096     date.min = currentTime.tm_min;
1097
1098     if(inputPicker->m_pickerLayout->popup){
1099         evas_object_del(inputPicker->m_pickerLayout->popup);
1100         inputPicker->m_pickerLayout->popup = 0;
1101     }
1102
1103     sprintf(dateStr, "%02d:%02d" , date.hour, date.min);
1104     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1105
1106     delete inputPicker->m_pickerLayout;
1107     inputPicker->m_pickerLayout = 0;
1108 }
1109
1110 void InputPicker::_month_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1111 {
1112     struct tm currentTime;
1113     memset(&currentTime, 0, sizeof(struct tm));
1114     Input_Date date;
1115     char dateStr[20] = {0, };
1116
1117     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1118
1119     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1120
1121     date.mon = currentTime.tm_mon;
1122     date.year = currentTime.tm_year;
1123
1124     if(inputPicker->m_pickerLayout->popup){
1125         evas_object_del(inputPicker->m_pickerLayout->popup);
1126         inputPicker->m_pickerLayout->popup = 0;
1127     }
1128
1129     date.year = 1900 + date.year;
1130     sprintf(dateStr, "%02d-%02d" , date.year, date.mon + 1);
1131
1132     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1133
1134     delete inputPicker->m_pickerLayout;
1135     inputPicker->m_pickerLayout = 0;
1136 }
1137
1138 void InputPicker::_datetime_popup_response_cb(void* data,  Evas_Object* obj, void* event_info)
1139 {
1140     struct tm currentTime;
1141     memset(&currentTime, 0, sizeof(struct tm));
1142     Input_Date date;
1143     char dateStr[50] = {0, };
1144
1145     InputPicker* inputPicker = static_cast<InputPicker*>(data);
1146
1147     elm_datetime_value_get(inputPicker->m_pickerLayout->datePicker, &currentTime);
1148     date.year = currentTime.tm_year;
1149     date.day =  currentTime.tm_mday;
1150     date.mon = currentTime.tm_mon;
1151
1152     elm_datetime_value_get(inputPicker->m_pickerLayout->timePicker, &currentTime);
1153     date.hour =  currentTime.tm_hour;
1154     date.min = currentTime.tm_min;
1155
1156     if (inputPicker->m_pickerLayout->popup) {
1157         evas_object_del(inputPicker->m_pickerLayout->popup);
1158         inputPicker->m_pickerLayout->popup = 0;
1159     }
1160
1161     date.year = 1900 + date.year;
1162
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);
1165     else
1166         sprintf(dateStr, "%d-%02d-%02dT%02d:%02dZ" , date.year, date.mon + 1, date.day, date.hour, date.min);
1167
1168     ewk_view_focused_input_element_value_set(inputPicker->m_ewkView, dateStr);
1169
1170     delete inputPicker->m_pickerLayout;
1171     inputPicker->m_pickerLayout = 0;
1172 }
1173
1174 } // namespace WebKit
1175
1176 #endif // OS(TIZEN) && ENABLE(TIZEN_INPUT_TAG_EXTENSION)