prevent fix
[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 <FSys_SystemResource.h>
39 #include <FUi_ResourceManager.h>
40 #include "FWebCtrl_WebImpl.h"
41 #include "FWebCtrl_InputPickerPopup.h"
42
43
44 using namespace Tizen::Base;
45 using namespace Tizen::Graphics;
46 using namespace Tizen::Locales;
47 using namespace Tizen::System;
48 using namespace Tizen::Ui;
49 using namespace Tizen::Ui::Controls;
50
51
52 namespace Tizen { namespace Web { namespace Controls
53 {
54
55
56 static const int DATE_POPUP_BUTTON_WIDTH = 250;
57
58
59 _InputPickerPopup::_InputPickerPopup(void)
60         : __pPopup(null)
61         , __pEditDate(null)
62         , __pEditTime(null)
63         , __pSelectionBtn(null)
64         , __modal(0)
65         , __popupHeight(0)
66         , __popupWidth(0)
67         , __btnHeight(0)
68         , __inputType(EWK_INPUT_TYPE_TIME)
69 {
70 }
71
72
73 _InputPickerPopup::~_InputPickerPopup(void)
74 {
75 }
76
77
78 result
79 _InputPickerPopup::Construct(const String& strDate, Ewk_Input_Type inputType)
80 {
81         result r = E_SUCCESS;
82
83         Dimension dim;
84         int dateHeight = 0;
85         int dateWidth = 0;
86         int sideMargin = 0;
87         DateTime inputDateTime;
88
89         __inputPickerMode = INPUT_MODE_DATE;
90         __inputType = inputType;
91
92         SystemTime::GetCurrentTime(UTC_TIME, inputDateTime);
93
94         if (!strDate.IsEmpty())
95         {
96                 r = Parse(strDate, inputDateTime);
97         }
98
99         _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
100
101         GET_SHAPE_CONFIG(EDITDATE::WIDTH, orientation, dateWidth);
102         GET_SHAPE_CONFIG(EDITDATE::HEIGHT, orientation, dateHeight);
103         GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
104         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, __popupWidth);
105         GET_SHAPE_CONFIG(MESSAGEBOX::MIN_HEIGHT, orientation, __popupHeight);
106         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __btnHeight);
107
108         __popupWidth -= 2*sideMargin;
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, 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         _SystemResource* pSysResource = _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         std::unique_ptr<DateTimeFormatter> pDateFormatter(DateTimeFormatter::CreateDateFormatterN(DATE_TIME_STYLE_DEFAULT));
517         SysTryReturn(NID_WEB_CTRL, pDateFormatter.get(), GetLastResult(), GetLastResult(),  "[%s] Propagating.", GetErrorMessage(GetLastResult()));
518
519         int year = 1;
520         int day = 1;
521         int days = 1;
522         int month = 1;
523         int hour = 0;
524         int minute = 0;
525         int week = 0;
526
527         result r = E_SUCCESS;
528
529         String formattedString = L"e";
530         String dayno;
531
532         const wchar_t* pMchar = static_cast< const wchar_t* >(strDateTime.GetPointer());
533         wchar_t* pTmp = static_cast< wchar_t* >(malloc(sizeof(wchar_t) * 10));
534         SysTryReturnResult(NID_WEB_CTRL, pTmp, E_OUT_OF_MEMORY, "Memory allocation failed.");
535
536         switch (__inputType)
537         {
538         case EWK_INPUT_TYPE_TIME :                       //"HH:mm";
539
540                 // hour
541                 wcsncpy(pTmp, pMchar, 2);
542                 pTmp[2] = L'\0';
543                 hour = static_cast< int >(wcstol(pTmp, null, 10));
544
545                 // minute
546                 wcsncpy(pTmp, pMchar + 3, 2);
547                 pTmp[2] = L'\0';
548                 minute = static_cast< int >(wcstol(pTmp, null, 10));
549                 dateTime.SetValue(1, 1, 1, hour,minute);
550                 break;
551
552         case EWK_INPUT_TYPE_DATETIME :                   // "yyyy-MM-ddTHH:mmZ";
553                 //fall through
554         case EWK_INPUT_TYPE_DATETIMELOCAL :
555                 // year
556                 wcsncpy(pTmp, pMchar, 4);
557                 pTmp[4] = L'\0';
558
559                 year = static_cast< int >(wcstol(pTmp, null, 10));
560
561                 // month
562                 wcsncpy(pTmp, pMchar + 5, 2);
563                 pTmp[2] = L'\0';
564
565                 month = static_cast< int >(wcstol(pTmp, null, 10));
566
567                 // day
568                 wcsncpy(pTmp, pMchar + 8, 2);
569                 pTmp[2] = L'\0';
570
571                 day = static_cast< int >(wcstol(pTmp, null, 10));
572
573                 // hour
574                 wcsncpy(pTmp, pMchar + 11, 2);
575                 pTmp[2] = L'\0';
576
577                 hour = static_cast< int >(wcstol(pTmp, null, 10));
578
579                 // minute
580                 wcsncpy(pTmp, pMchar + 14, 2);
581                 pTmp[2] = L'\0';
582                 minute = static_cast< int >(wcstol(pTmp, null, 10));
583                 dateTime.SetValue(year, month, day, hour, minute);
584                 break;
585
586         case EWK_INPUT_TYPE_WEEK :                      //"yyyy-Www";
587
588                 // year
589                 wcsncpy(pTmp, pMchar, 4);
590                 pTmp[4] = L'\0';
591
592                 year = static_cast< int >(wcstol(pTmp, null, 10));
593
594                 // week
595                 wcsncpy(pTmp, pMchar + 6, 2);
596                 pTmp[2] = L'\0';
597                 week = static_cast< int >(wcstol(pTmp, null, 10));
598
599                 dateTime.SetValue(year,1,1);
600                 pDateFormatter->ApplyPattern(formattedString);
601                 pDateFormatter->Format(dateTime, dayno);
602                 Integer::Parse(dayno, day);
603                 days = (week*7) - day;
604
605                 GetDateTimeForWeek(year, days, dateTime);
606                 break;
607
608         case EWK_INPUT_TYPE_DATE :                      //"yyyy-MM-dd"
609                 // year
610                 wcsncpy(pTmp, pMchar, 4);
611                 pTmp[4] = L'\0';
612                 year = static_cast< int >(wcstol(pTmp, null, 10));
613
614                 // month
615                 wcsncpy(pTmp, pMchar + 5, 2);
616                 pTmp[2] = L'\0';
617                 month = static_cast< int >(wcstol(pTmp, null, 10));
618
619                 // day
620                 wcsncpy(pTmp, pMchar + 8, 2);
621                 pTmp[2] = L'\0';
622                 day = static_cast< int >(wcstol(pTmp, null, 10));
623
624                 dateTime.SetValue(year, month, day);
625                 break;
626
627         case EWK_INPUT_TYPE_MONTH :             //"yyyy-MM";
628
629                 // year
630                 wcsncpy(pTmp, pMchar, 4);
631                 pTmp[4] = L'\0';
632                 year = static_cast< int >(wcstol(pTmp, null, 10));
633
634                 // month
635                 wcsncpy(pTmp, pMchar + 5, 2);
636                 pTmp[2] = L'\0';
637                 month = static_cast< int >(wcstol(pTmp, null, 10));
638
639                 dateTime.SetValue(year, month, 1);
640                 break;
641
642         default :
643                 r = E_UNSUPPORTED_OPTION;
644                 SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
645         }
646
647         free(pTmp);
648
649         return r;
650 }
651
652
653 void
654 _InputPickerPopup::GetDateTimeForWeek(int year, int days, DateTime& dateTime)
655 {
656         int monthDays = 0;
657
658         for (int month = 1; month <= 12; month++)
659         {
660                 DateTime::GetDaysInMonth(year, month, monthDays);
661
662                 if (days - monthDays < 0)
663                 {
664                         dateTime.SetValue(year, month, days);
665                         break;
666                 }
667
668                 days -= monthDays;
669         }
670 }
671
672
673 }}} // Tizen::Web::Controls