15eeaf7f84025681ec16094502923ecc6a6f33ea
[framework/osp/web.git] / src / controls / FWebCtrl_InputPickerPopup.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_DateTimeHandler.cpp
20  * @brief               The file contains the definition of _DateTimeHandler class.
21  */
22 #include <FBaseDateTime.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpDimension.h>
25 #include <FGrpRectangle.h>
26 #include <FLclDateTimeFormatter.h>
27 #include <FLclLocale.h>
28 #include <FSystem.h>
29 #include <FUiCtrlButton.h>
30 #include <FUiCtrlEditField.h>
31 #include <FUiCtrlEditDate.h>
32 #include <FUiCtrlEditTime.h>
33 #include <FUiCtrlLabel.h>
34 #include <FUiIActionEventListener.h>
35 #include <FUiLayout.h>
36 #include <FUiVerticalBoxLayout.h>
37 #include <FWebCtrlAuthenticationChallenge.h>
38 #include <FUiCtrl_PopupImpl.h>
39 #include <FUi_ResourceManager.h>
40 #include <FSys_SystemResource.h>
41 #include "FWebCtrl_WebImpl.h"
42 #include "FWebCtrl_InputPickerPopup.h"
43
44
45 using namespace Tizen::Base;
46 using namespace Tizen::Graphics;
47 using namespace Tizen::Web::Controls;
48 using namespace Tizen::Ui::Controls;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Locales;
51 using namespace Tizen::System;
52
53
54 namespace Tizen { namespace Web { namespace Controls
55 {
56
57
58 static const int DATE_POPUP_BUTTON_WIDTH = 250;
59
60
61 _InputPickerPopup::_InputPickerPopup(void)
62         : __pPopup(null)
63         , __pEditDate(null)
64         , __pEditTime(null)
65         , __pSelectionBtn(null)
66         , __modal(0)
67         , __popupHeight(0)
68         , __popupWidth(0)
69         , __btnHeight(0)
70         , __inputType(EWK_INPUT_TYPE_TIME)
71 {
72 }
73
74
75 _InputPickerPopup::~_InputPickerPopup(void)
76 {
77 }
78
79
80 result
81 _InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
82 {
83         result r = E_SUCCESS;
84
85         Dimension dim;
86         int dateHeight = 0;
87         int dateWidth = 0;
88         int sideMargin = 0;
89         DateTime inputDateTime;
90
91         __inputPickerMode = INPUT_MODE_DATE;
92         __inputType = inputType;
93
94         SystemTime::GetCurrentTime(UTC_TIME, inputDateTime);
95
96         if (!strDate.IsEmpty())
97         {
98                 r = Parse(strDate, inputDateTime);
99         }
100
101         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
102
103         GET_SHAPE_CONFIG(EDITDATE::WIDTH, orientation, dateWidth);
104         GET_SHAPE_CONFIG(EDITDATE::HEIGHT, orientation, dateHeight);
105         GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
106         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, __popupWidth);
107         GET_SHAPE_CONFIG(MESSAGEBOX::MIN_HEIGHT, orientation, __popupHeight);
108         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __btnHeight);
109
110         std::unique_ptr<EditDate> pEditDate(new (std::nothrow) EditDate());
111         SysTryReturnResult(NID_WEB_CTRL, pEditDate.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
112
113         std::unique_ptr<EditTime> pEditTime(new (std::nothrow) EditTime());
114         SysTryReturnResult(NID_WEB_CTRL, pEditTime.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
115
116         switch (__inputType)
117         {
118         case EWK_INPUT_TYPE_TIME :
119
120                 __popupHeight = __popupHeight + dateHeight + __btnHeight;
121                 r = CreatePopup();
122                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123
124                 __pPopup->SetTitleText("Select time");
125
126                 r = pEditTime->Construct(Point(0, 0), L"Time (Default format) :");
127                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
128
129                 r = __pPopup->AddControl(*pEditTime);
130                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131                 pEditTime->SetTime(inputDateTime);
132                 __pEditTime = pEditTime.release();
133                 break;
134
135         case EWK_INPUT_TYPE_DATETIME :
136                 //fall through
137
138         case EWK_INPUT_TYPE_DATETIMELOCAL :
139
140                 __popupHeight = __popupHeight + 2*dateHeight + __btnHeight;
141                 r = CreatePopup();
142                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143
144                 __pPopup->SetTitleText("Select datetime");
145
146                 r = pEditDate->Construct(Point(0, 0), L"Date (Default format) :");
147                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
148
149                 r = pEditTime->Construct(Point(0, 0), L"Time (Default format) :");
150                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151
152                 r = __pPopup->AddControl(*pEditTime);
153                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155                 pEditTime->SetTime(inputDateTime);
156                 __pEditTime = pEditTime.release();
157
158                 r = __pPopup->AddControl(*pEditDate);
159                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160
161                 pEditDate->SetDate(inputDateTime);
162                 __pEditDate = pEditDate.release();
163
164                 dateHeight = 2 * dateHeight;
165                 break;
166
167         case EWK_INPUT_TYPE_WEEK :
168                 //fall through
169         case EWK_INPUT_TYPE_DATE :
170                 //fall through
171         case EWK_INPUT_TYPE_MONTH :
172
173                 __popupHeight = __popupHeight + dateHeight + __btnHeight;
174                 r = CreatePopup();
175                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
176                 __pPopup->SetTitleText("Select date");
177
178                 r = pEditDate->Construct(Point(0, 0), L"Date (Default format) :");
179                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
180
181                 r = __pPopup->AddControl(*pEditDate);
182                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
183
184                 pEditDate->SetDate(inputDateTime);
185                 __pEditDate = pEditDate.release();
186                 break;
187
188         default:
189                 r = E_UNSUPPORTED_OPTION;
190                 SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
191                 return r;
192         }
193
194         r = AddButton(ID_BUTTON_INPUT_DATE_SELECTION);
195         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
196
197         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(__pPopup->GetLayoutN()));
198         SysTryReturnResult(NID_WEB_CTRL, pLayout.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
199
200         if (__pEditDate)
201         {
202                 pLayout->SetHorizontalAlignment(*__pEditDate, LAYOUT_HORIZONTAL_ALIGN_LEFT);
203                 pLayout->SetSpacing(*__pEditDate, sideMargin);
204         }
205
206         if (__pEditTime)
207         {
208                 pLayout->SetHorizontalAlignment(*__pEditTime, LAYOUT_HORIZONTAL_ALIGN_LEFT);
209                 pLayout->SetSpacing(*__pEditTime, sideMargin);
210         }
211
212         pLayout->SetHorizontalAlignment(*__pSelectionBtn, LAYOUT_HORIZONTAL_ALIGN_CENTER);
213         pLayout->SetSpacing(*__pSelectionBtn, sideMargin);
214
215         return E_SUCCESS;
216 }
217
218
219 result
220 _InputPickerPopup::Construct(const Color& color)
221 {
222         result r = E_SUCCESS;
223
224         __inputPickerMode = INPUT_MODE_COLOR;
225
226         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
227
228         CalculateColorPickerPopupSize(orientation);
229
230         r = CreatePopup();
231         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
232
233         __pPopup->SetTitleText("Select color");
234
235         std::unique_ptr<ColorPicker> pColorPicker(new (std::nothrow) ColorPicker());
236         SysTryReturnResult(NID_WEB_CTRL, pColorPicker.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
237
238         r = pColorPicker->Construct(Point(0,0));
239         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
240
241         pColorPicker->SetColor(color);
242
243         r = __pPopup->AddControl(*pColorPicker);
244         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
245
246         __pColorPicker = pColorPicker.release();
247         r = AddButton(ID_BUTTON_INPUT_COLOR_SELECTION);
248         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
249
250         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(__pPopup->GetLayoutN()));
251         SysTryReturnResult(NID_WEB_CTRL, pLayout.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
252
253         pLayout->SetHorizontalAlignment(*__pColorPicker, LAYOUT_HORIZONTAL_ALIGN_LEFT);
254         pLayout->SetHorizontalAlignment(*__pSelectionBtn, LAYOUT_HORIZONTAL_ALIGN_CENTER);
255
256         int sideMargin = 0;
257         GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
258
259         pLayout->SetSpacing(*__pColorPicker, sideMargin);
260         pLayout->SetSpacing(*__pSelectionBtn, sideMargin);
261
262         return E_SUCCESS;
263
264 }
265
266
267 void
268 _InputPickerPopup::CalculateColorPickerPopupSize(_ControlOrientation orientation)
269 {
270         int sideMargin = 0;
271         Dimension dim;
272
273         GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
274         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, __popupWidth);
275         GET_SHAPE_CONFIG(MESSAGEBOX::MIN_HEIGHT, orientation, __popupHeight);
276         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __btnHeight);
277
278         GET_DIMENSION_CONFIG(COLORPICKER::DEFAULT_SIZE, orientation, dim);
279
280         dim.width += sideMargin;
281         __popupWidth = dim.width;
282         __popupHeight = __popupHeight + dim.height + __btnHeight;
283 }
284
285
286 result
287 _InputPickerPopup::CreatePopup(void)
288 {
289         result r = E_SUCCESS;
290
291         VerticalBoxLayout layout;
292         r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
293         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
294
295         std::unique_ptr<Popup> pPopup(new (std::nothrow) Popup());
296         SysTryReturnResult(NID_WEB_CTRL, pPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
297
298         r = pPopup->Construct(layout, layout, true, Tizen::Graphics::Dimension(__popupWidth, __popupHeight));
299         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
300
301         __pPopup = std::move(pPopup);
302
303         return E_SUCCESS;
304 }
305
306
307 result
308 _InputPickerPopup::AddButton(_InputPickerButtonId buttonId)
309 {
310         result r = E_SUCCESS;
311
312         String buttonStr;
313         
314         Tizen::System::_SystemResource* pSysResource = Tizen::System::_SystemResource::GetInstance();
315         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
316
317         buttonStr = pSysResource->GetString("sys_string", "IDS_COM_SK_OK");
318
319         std::unique_ptr<Button> pSelectionBtn(new (std::nothrow) Button());
320         SysTryReturnResult(NID_WEB_CTRL, pSelectionBtn.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
321
322         r = pSelectionBtn->Construct(Rectangle(0, 0, DATE_POPUP_BUTTON_WIDTH, __btnHeight), buttonStr);
323         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
324
325         pSelectionBtn->SetActionId(buttonId);
326         __pPopup->AddControl(*pSelectionBtn);
327         pSelectionBtn->AddActionEventListener(*this);
328
329         __pSelectionBtn =  pSelectionBtn.release();
330
331         return E_SUCCESS;
332 }
333
334
335 void
336 _InputPickerPopup::OnActionPerformed(const Control& source, int actionId)
337 {
338         result r = E_SUCCESS;
339
340         switch(actionId)
341         {
342                 case ID_BUTTON_INPUT_DATE_SELECTION:
343                         r = UpdateDate();
344                         break;
345
346                 case ID_BUTTON_INPUT_COLOR_SELECTION:
347                         UpdateColor();
348                         break;
349
350                 default:
351                         SysAssert(false);
352                         break;
353         }
354
355         r = HidePopup();
356         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
357 }
358
359
360 result
361 _InputPickerPopup::ChangeLayout(_ControlOrientation orientation)
362 {
363         result r = E_SUCCESS;
364
365         if (__inputPickerMode != INPUT_MODE_COLOR) //Change the layout for color only.
366         {
367                 return r;
368         }
369
370         int x = 0;
371         int y = 0;
372         Dimension screenRect = _ControlManager::GetInstance()->GetScreenSize();
373
374         CalculateColorPickerPopupSize(orientation);
375
376         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
377         {
378                 x  = (screenRect.width - __popupWidth) / 2;
379                 y = (screenRect.height - __popupHeight) / 2;
380         }
381         else
382         {
383                 x  = (screenRect.height - __popupWidth) / 2;
384                 y = (screenRect.width - __popupHeight) / 2;
385         }
386
387         r = __pPopup->SetBounds(Rectangle(x, y, __popupWidth, __popupHeight));
388         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
389
390         return E_SUCCESS;
391 }
392
393
394 result
395 _InputPickerPopup::UpdateDate(void)
396 {
397         result r = E_SUCCESS;
398
399         String formattedString;
400         DateTime dateTime;
401
402         std::unique_ptr<DateTimeFormatter> pDateFormatter(DateTimeFormatter::CreateDateFormatterN(DATE_TIME_STYLE_DEFAULT));
403         SysTryReturn(NID_WEB_CTRL, pDateFormatter.get(), GetLastResult(), GetLastResult(),  "[%s] Propagating.", GetErrorMessage(GetLastResult()));
404
405                 switch (__inputType)
406                 {
407                 case EWK_INPUT_TYPE_TIME :
408                         formattedString = L"HH:mm";
409                         pDateFormatter->ApplyPattern(formattedString);
410                         pDateFormatter->Format(__pEditTime->GetTime(), __dateStr);
411                         break;
412
413                 case EWK_INPUT_TYPE_DATETIME :
414                         formattedString = L"yyyy-MM-dd";
415                         pDateFormatter->ApplyPattern(formattedString);
416                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
417
418                         formattedString = L"\'T\'HH:mm\'Z\'";
419                         pDateFormatter->ApplyPattern(formattedString);
420                         pDateFormatter->Format(__pEditTime->GetTime(), __dateStr);
421                         break;
422
423                 case EWK_INPUT_TYPE_DATETIMELOCAL :
424                         formattedString = L"yyyy-MM-dd";
425                         pDateFormatter->ApplyPattern(formattedString);
426                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
427
428                         formattedString = L"\'T\'HH:mm";
429                         pDateFormatter->ApplyPattern(formattedString);
430                         pDateFormatter->Format(__pEditTime->GetTime(), __dateStr);
431                         break;
432
433                 case EWK_INPUT_TYPE_WEEK :
434                         formattedString = L"yyyy-\'W\'ww";
435                         pDateFormatter->ApplyPattern(formattedString);
436                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
437
438                         break;
439
440                 case EWK_INPUT_TYPE_DATE :
441                         formattedString = L"yyyy-MM-dd";
442                         pDateFormatter->ApplyPattern(formattedString);
443                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
444                         break;
445
446                 case EWK_INPUT_TYPE_MONTH :
447                         formattedString = L"yyyy-MM";
448                         pDateFormatter->ApplyPattern(formattedString);
449                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
450                         break;
451
452                 default :
453                         r = E_UNSUPPORTED_OPTION;
454                         SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
455                         return r;
456                 }
457
458         return E_SUCCESS;
459 }
460
461
462 void
463 _InputPickerPopup::UpdateColor(void)
464 {
465         __Color = __pColorPicker->GetColor();
466 }
467
468
469 result
470 _InputPickerPopup::ShowPopup(void)
471 {
472         result r = E_SUCCESS;
473
474         r = __pPopup->SetShowState(true);
475         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
476
477         r = __pPopup->DoModal(__modal);
478         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
479
480         return E_SUCCESS;
481 }
482
483
484 result
485 _InputPickerPopup::HidePopup(void)
486 {
487         result r = E_SUCCESS;
488
489         r = __pPopup->SetShowState(false);
490         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
491
492         r = __pPopup->EndModal(__modal);
493         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
494
495         return E_SUCCESS;
496 }
497
498
499 String
500 _InputPickerPopup::GetDate(void) const
501 {
502         return __dateStr;
503 }
504
505
506 Color
507 _InputPickerPopup::GetColor(void) const
508 {
509         return __Color;
510 }
511
512
513 result
514 _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
515 {
516         result r = E_SUCCESS;
517
518         wchar_t* pMchar = (wchar_t*) strDateTime.GetPointer();
519         wchar_t* pTmp = (wchar_t*) malloc(sizeof(wchar_t) * 10);
520         SysTryReturnResult(NID_WEB_CTRL, pTmp, E_OUT_OF_MEMORY, "Memory allocation failed.");
521
522         std::unique_ptr<DateTimeFormatter> pDateFormatter(DateTimeFormatter::CreateDateFormatterN(DATE_TIME_STYLE_DEFAULT));
523         SysTryReturn(NID_WEB_CTRL, pDateFormatter.get(), GetLastResult(), GetLastResult(),  "[%s] Propagating.", GetErrorMessage(GetLastResult()));
524
525         int year = 1;
526         int day = 1;
527         int days = 1;
528         int month = 1;
529         int hour = 0;
530         int minute = 0;
531         int week = 0;
532         String formattedString = L"e";
533         String dayno;
534
535         switch (__inputType)
536         {
537         case EWK_INPUT_TYPE_TIME :                       //"HH:mm";
538
539                 // hour
540                 wcsncpy(pTmp, pMchar, 2);
541                 pTmp[2] = L'\0';
542                 hour = (int) wcstol(pTmp, null, 10);
543
544                 // minute
545                 wcsncpy(pTmp, pMchar + 3, 2);
546                 pTmp[2] = L'\0';
547                 minute = (int) wcstol(pTmp, null, 10);
548                 dateTime.SetValue(1, 1, 1, hour,minute);
549                 break;
550
551         case EWK_INPUT_TYPE_DATETIME :                   // "yyyy-MM-ddTHH:mmZ";
552                 //fall through
553         case EWK_INPUT_TYPE_DATETIMELOCAL :
554                 // year
555                 wcsncpy(pTmp, pMchar, 4);
556                 pTmp[4] = L'\0';
557
558                 year = (int) wcstol(pTmp, null, 10);
559
560                 // month
561                 wcsncpy(pTmp, pMchar + 5, 2);
562                 pTmp[2] = L'\0';
563
564                 month = (int) wcstol(pTmp, null, 10);
565
566                 // day
567                 wcsncpy(pTmp, pMchar + 8, 2);
568                 pTmp[2] = L'\0';
569
570                 day = (int) wcstol(pTmp, null, 10);
571
572                 // hour
573                 wcsncpy(pTmp, pMchar + 11, 2);
574                 pTmp[2] = L'\0';
575
576                 hour = (int) wcstol(pTmp, null, 10);
577
578                 // minute
579                 wcsncpy(pTmp, pMchar + 14, 2);
580                 pTmp[2] = L'\0';
581                 minute = (int) wcstol(pTmp, null, 10);
582                 dateTime.SetValue(year, month, day, hour, minute);
583                 break;
584
585         case EWK_INPUT_TYPE_WEEK :                      //"yyyy-Www";
586
587                 // year
588                 wcsncpy(pTmp, pMchar, 4);
589                 pTmp[4] = L'\0';
590
591                 year = (int) wcstol(pTmp, null, 10);
592
593                 // week
594                 wcsncpy(pTmp, pMchar + 6, 2);
595                 pTmp[2] = L'\0';
596                 week = (int) wcstol(pTmp, null, 10);
597
598                 dateTime.SetValue(year,1,1);
599                 pDateFormatter->ApplyPattern(formattedString);
600                 pDateFormatter->Format(dateTime, dayno);
601                 Integer::Parse(dayno, day);
602                 days = (week*7) - day;
603
604                 GetDateTimeForWeek(year, days, dateTime);
605                 break;
606
607         case EWK_INPUT_TYPE_DATE :                      //"yyyy-MM-dd"
608                 // year
609                 wcsncpy(pTmp, pMchar, 4);
610                 pTmp[4] = L'\0';
611                 year = (int) wcstol(pTmp, null, 10);
612
613                 // month
614                 wcsncpy(pTmp, pMchar + 5, 2);
615                 pTmp[2] = L'\0';
616                 month = (int) wcstol(pTmp, null, 10);
617
618                 // day
619                 wcsncpy(pTmp, pMchar + 8, 2);
620                 pTmp[2] = L'\0';
621                 day = (int) wcstol(pTmp, null, 10);
622
623                 dateTime.SetValue(year, month, day);
624                 break;
625
626         case EWK_INPUT_TYPE_MONTH :             //"yyyy-MM";
627
628                 // year
629                 wcsncpy(pTmp, pMchar, 4);
630                 pTmp[4] = L'\0';
631                 year = (int) wcstol(pTmp, null, 10);
632
633                 // month
634                 wcsncpy(pTmp, pMchar + 5, 2);
635                 pTmp[2] = L'\0';
636                 month = (int) wcstol(pTmp, null, 10);
637
638                 dateTime.SetValue(year, month, 1);
639                 break;
640
641         default :
642                 r = E_UNSUPPORTED_OPTION;
643                 SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
644                 return r;
645         }
646
647         if (pTmp)
648         {
649                 free(pTmp);
650         }
651
652         return E_SUCCESS;
653 }
654
655
656 void
657 _InputPickerPopup::GetDateTimeForWeek(int year, int days, DateTime& dateTime)
658 {
659         int monthDays = 0;
660
661         for (int month = 1; month <= 12; month++)
662         {
663                 DateTime::GetDaysInMonth(year, month, monthDays);
664
665                 if (days - monthDays < 0)
666                 {
667                         dateTime.SetValue(year, month, days);
668                         break;
669                 }
670
671                 days -= monthDays;
672         }
673 }
674
675
676 }}} // Tizen::Web::Controls