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