Merge "fixed tc error in GetEvasFromUiApp" into tizen_2.2
[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->SetOwner(&pImpl->GetPublic());
204         __pPopup->SetPropagatedKeyEventListener(this);
205         
206         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(__pPopup->GetLayoutN()));
207         SysTryReturnResult(NID_WEB_CTRL, pLayout.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
208
209         if (__pEditDate)
210         {
211                 pLayout->SetHorizontalAlignment(*__pEditDate, LAYOUT_HORIZONTAL_ALIGN_LEFT);
212                 pLayout->SetSpacing(*__pEditDate, sideMargin);
213         }
214
215         if (__pEditTime)
216         {
217                 pLayout->SetHorizontalAlignment(*__pEditTime, LAYOUT_HORIZONTAL_ALIGN_LEFT);
218                 pLayout->SetSpacing(*__pEditTime, sideMargin);
219         }
220
221         pLayout->SetHorizontalAlignment(*__pSelectionBtn, LAYOUT_HORIZONTAL_ALIGN_CENTER);
222         pLayout->SetSpacing(*__pSelectionBtn, sideMargin);
223
224         return E_SUCCESS;
225 }
226
227
228 result
229 _InputPickerPopup::Construct(const Color& color, Tizen::Web::Controls::_WebImpl* pImpl)
230 {
231         result r = E_SUCCESS;
232
233         __inputPickerMode = INPUT_MODE_COLOR;
234
235         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
236
237         CalculateColorPickerPopupSize(orientation);
238
239         r = CreatePopup();
240         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
241
242         __pPopup->SetTitleText("Select color");
243
244         std::unique_ptr<ColorPicker> pColorPicker(new (std::nothrow) ColorPicker());
245         SysTryReturnResult(NID_WEB_CTRL, pColorPicker.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
246
247         r = pColorPicker->Construct(Point(0,0));
248         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
249
250         pColorPicker->SetColor(color);
251
252         __pPopup->SetOwner(&pImpl->GetPublic());
253         __pPopup->SetPropagatedKeyEventListener(this);
254         r = __pPopup->AddControl(*pColorPicker);
255         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
256
257         __pColorPicker = pColorPicker.release();
258         r = AddButton(ID_BUTTON_INPUT_COLOR_SELECTION);
259         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
260
261         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(__pPopup->GetLayoutN()));
262         SysTryReturnResult(NID_WEB_CTRL, pLayout.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
263
264         pLayout->SetHorizontalAlignment(*__pColorPicker, LAYOUT_HORIZONTAL_ALIGN_LEFT);
265         pLayout->SetHorizontalAlignment(*__pSelectionBtn, LAYOUT_HORIZONTAL_ALIGN_CENTER);
266
267         int sideMargin = 0;
268         GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
269
270         pLayout->SetSpacing(*__pColorPicker, sideMargin);
271         pLayout->SetSpacing(*__pSelectionBtn, sideMargin);
272
273         return E_SUCCESS;
274
275 }
276
277
278 void
279 _InputPickerPopup::CalculateColorPickerPopupSize(_ControlOrientation orientation)
280 {
281         int sideMargin = 0;
282         Dimension dim;
283
284         GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
285         GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, __popupWidth);
286         GET_SHAPE_CONFIG(MESSAGEBOX::MIN_HEIGHT, orientation, __popupHeight);
287         GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, __btnHeight);
288
289         GET_DIMENSION_CONFIG(COLORPICKER::DEFAULT_SIZE, orientation, dim);
290
291         dim.width += sideMargin;
292         __popupWidth = dim.width;
293         __popupHeight = __popupHeight + dim.height + __btnHeight;
294 }
295
296
297 result
298 _InputPickerPopup::CreatePopup(void)
299 {
300         result r = E_SUCCESS;
301
302         VerticalBoxLayout layout;
303         r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
304         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
305
306         std::unique_ptr<Popup> pPopup(new (std::nothrow) Popup());
307         SysTryReturnResult(NID_WEB_CTRL, pPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
308
309         r = pPopup->Construct(layout, layout, true, Dimension(__popupWidth, __popupHeight));
310         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
311
312         __pPopup = std::move(pPopup);
313
314         return E_SUCCESS;
315 }
316
317
318 result
319 _InputPickerPopup::AddButton(_InputPickerButtonId buttonId)
320 {
321         result r = E_SUCCESS;
322
323         String buttonStr;
324
325         _SystemResource* pSysResource = _SystemResource::GetInstance();
326         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
327
328         buttonStr = pSysResource->GetString("sys_string", "IDS_COM_SK_OK");
329
330         std::unique_ptr<Button> pSelectionBtn(new (std::nothrow) Button());
331         SysTryReturnResult(NID_WEB_CTRL, pSelectionBtn.get(), E_OUT_OF_MEMORY, "Memory Allocation Failed.");
332
333         r = pSelectionBtn->Construct(Rectangle(0, 0, DATE_POPUP_BUTTON_WIDTH, __btnHeight), buttonStr);
334         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
335
336         pSelectionBtn->SetActionId(buttonId);
337         __pPopup->AddControl(*pSelectionBtn);
338         pSelectionBtn->AddActionEventListener(*this);
339
340         __pSelectionBtn =  pSelectionBtn.release();
341
342         return E_SUCCESS;
343 }
344
345
346 void
347 _InputPickerPopup::OnActionPerformed(const Control& source, int actionId)
348 {
349         result r = E_SUCCESS;
350
351         switch(actionId)
352         {
353                 case ID_BUTTON_INPUT_DATE_SELECTION:
354                         r = UpdateDate();
355                         break;
356
357                 case ID_BUTTON_INPUT_COLOR_SELECTION:
358                         UpdateColor();
359                         break;
360
361                 default:
362                         SysAssert(false);
363                         break;
364         }
365
366         r = HidePopup();
367         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
368 }
369
370
371 result
372 _InputPickerPopup::ChangeLayout(_ControlOrientation orientation)
373 {
374         result r = E_SUCCESS;
375
376         if (__inputPickerMode != INPUT_MODE_COLOR) //Change the layout for color only.
377         {
378                 return r;
379         }
380
381         int x = 0;
382         int y = 0;
383         Dimension screenRect = _ControlManager::GetInstance()->GetScreenSize();
384
385         CalculateColorPickerPopupSize(orientation);
386
387         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
388         {
389                 x  = (screenRect.width - __popupWidth) / 2;
390                 y = (screenRect.height - __popupHeight) / 2;
391         }
392         else
393         {
394                 x  = (screenRect.height - __popupWidth) / 2;
395                 y = (screenRect.width - __popupHeight) / 2;
396         }
397
398         r = __pPopup->SetBounds(Rectangle(x, y, __popupWidth, __popupHeight));
399         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
400
401         return E_SUCCESS;
402 }
403
404
405 result
406 _InputPickerPopup::UpdateDate(void)
407 {
408         result r = E_SUCCESS;
409
410         String formattedString;
411         DateTime dateTime;
412
413         std::unique_ptr<DateTimeFormatter> pDateFormatter(DateTimeFormatter::CreateDateFormatterN(DATE_TIME_STYLE_DEFAULT));
414         SysTryReturn(NID_WEB_CTRL, pDateFormatter.get(), GetLastResult(), GetLastResult(),  "[%s] Propagating.", GetErrorMessage(GetLastResult()));
415
416                 switch (__inputType)
417                 {
418                 case EWK_INPUT_TYPE_TIME :
419                         formattedString = L"HH:mm";
420                         pDateFormatter->ApplyPattern(formattedString);
421                         pDateFormatter->Format(__pEditTime->GetTime(), __dateStr);
422                         break;
423
424                 case EWK_INPUT_TYPE_DATETIME :
425                         formattedString = L"yyyy-MM-dd";
426                         pDateFormatter->ApplyPattern(formattedString);
427                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
428
429                         formattedString = L"\'T\'HH:mm\'Z\'";
430                         pDateFormatter->ApplyPattern(formattedString);
431                         pDateFormatter->Format(__pEditTime->GetTime(), __dateStr);
432                         break;
433
434                 case EWK_INPUT_TYPE_DATETIMELOCAL :
435                         formattedString = L"yyyy-MM-dd";
436                         pDateFormatter->ApplyPattern(formattedString);
437                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
438
439                         formattedString = L"\'T\'HH:mm";
440                         pDateFormatter->ApplyPattern(formattedString);
441                         pDateFormatter->Format(__pEditTime->GetTime(), __dateStr);
442                         break;
443
444                 case EWK_INPUT_TYPE_WEEK :
445                         formattedString = L"yyyy-\'W\'ww";
446                         pDateFormatter->ApplyPattern(formattedString);
447                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
448
449                         break;
450
451                 case EWK_INPUT_TYPE_DATE :
452                         formattedString = L"yyyy-MM-dd";
453                         pDateFormatter->ApplyPattern(formattedString);
454                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
455                         break;
456
457                 case EWK_INPUT_TYPE_MONTH :
458                         formattedString = L"yyyy-MM";
459                         pDateFormatter->ApplyPattern(formattedString);
460                         pDateFormatter->Format(__pEditDate->GetDate(), __dateStr);
461                         break;
462
463                 default :
464                         r = E_UNSUPPORTED_OPTION;
465                         SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
466                         return r;
467                 }
468
469         return E_SUCCESS;
470 }
471
472
473 void
474 _InputPickerPopup::UpdateColor(void)
475 {
476         __Color = __pColorPicker->GetColor();
477 }
478
479
480 result
481 _InputPickerPopup::ShowPopup(void)
482 {
483         result r = E_SUCCESS;
484
485         r = __pPopup->SetShowState(true);
486         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
487
488         __isModal = true;
489
490         r = __pPopup->DoModal(__modal);
491         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
492
493         return E_SUCCESS;
494 }
495
496
497 result
498 _InputPickerPopup::HidePopup(void)
499 {
500         result r = E_SUCCESS;
501
502         r = __pPopup->SetShowState(false);
503         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
504
505         __isModal = false;
506
507         r = __pPopup->EndModal(__modal);
508         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
509
510         return E_SUCCESS;
511 }
512
513 bool
514 _InputPickerPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
515 {
516         return true;
517 }
518
519 bool
520 _InputPickerPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
521 {
522         if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
523         {
524                 HidePopup();
525         }
526
527         return true;
528 }
529
530 bool
531 _InputPickerPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
532 {
533         return false;
534 }
535
536 bool
537 _InputPickerPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
538 {
539         return false;
540 }
541
542 bool
543 _InputPickerPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
544 {
545         return false;
546 }
547
548 String
549 _InputPickerPopup::GetDate(void) const
550 {
551         return __dateStr;
552 }
553
554
555 Color
556 _InputPickerPopup::GetColor(void) const
557 {
558         return __Color;
559 }
560
561
562 result
563 _InputPickerPopup::Parse(const String& strDateTime, DateTime & dateTime)
564 {
565         std::unique_ptr<DateTimeFormatter> pDateFormatter(DateTimeFormatter::CreateDateFormatterN(DATE_TIME_STYLE_DEFAULT));
566         SysTryReturn(NID_WEB_CTRL, pDateFormatter.get(), GetLastResult(), GetLastResult(),  "[%s] Propagating.", GetErrorMessage(GetLastResult()));
567
568         int year = 1;
569         int day = 1;
570         int days = 1;
571         int month = 1;
572         int hour = 0;
573         int minute = 0;
574         int week = 0;
575
576         result r = E_SUCCESS;
577
578         String formattedString = L"e";
579         String dayno;
580
581         const wchar_t* pMchar = static_cast< const wchar_t* >(strDateTime.GetPointer());
582         wchar_t* pTmp = static_cast< wchar_t* >(malloc(sizeof(wchar_t) * 10));
583         SysTryReturnResult(NID_WEB_CTRL, pTmp, E_OUT_OF_MEMORY, "Memory allocation failed.");
584
585         switch (__inputType)
586         {
587         case EWK_INPUT_TYPE_TIME :                       //"HH:mm";
588
589                 // hour
590                 wcsncpy(pTmp, pMchar, 2);
591                 pTmp[2] = L'\0';
592                 hour = static_cast< int >(wcstol(pTmp, null, 10));
593
594                 // minute
595                 wcsncpy(pTmp, pMchar + 3, 2);
596                 pTmp[2] = L'\0';
597                 minute = static_cast< int >(wcstol(pTmp, null, 10));
598                 dateTime.SetValue(1, 1, 1, hour,minute);
599                 break;
600
601         case EWK_INPUT_TYPE_DATETIME :                   // "yyyy-MM-ddTHH:mmZ";
602                 //fall through
603         case EWK_INPUT_TYPE_DATETIMELOCAL :
604                 // year
605                 wcsncpy(pTmp, pMchar, 4);
606                 pTmp[4] = L'\0';
607
608                 year = static_cast< int >(wcstol(pTmp, null, 10));
609
610                 // month
611                 wcsncpy(pTmp, pMchar + 5, 2);
612                 pTmp[2] = L'\0';
613
614                 month = static_cast< int >(wcstol(pTmp, null, 10));
615
616                 // day
617                 wcsncpy(pTmp, pMchar + 8, 2);
618                 pTmp[2] = L'\0';
619
620                 day = static_cast< int >(wcstol(pTmp, null, 10));
621
622                 // hour
623                 wcsncpy(pTmp, pMchar + 11, 2);
624                 pTmp[2] = L'\0';
625
626                 hour = static_cast< int >(wcstol(pTmp, null, 10));
627
628                 // minute
629                 wcsncpy(pTmp, pMchar + 14, 2);
630                 pTmp[2] = L'\0';
631                 minute = static_cast< int >(wcstol(pTmp, null, 10));
632                 dateTime.SetValue(year, month, day, hour, minute);
633                 break;
634
635         case EWK_INPUT_TYPE_WEEK :                      //"yyyy-Www";
636
637                 // year
638                 wcsncpy(pTmp, pMchar, 4);
639                 pTmp[4] = L'\0';
640
641                 year = static_cast< int >(wcstol(pTmp, null, 10));
642
643                 // week
644                 wcsncpy(pTmp, pMchar + 6, 2);
645                 pTmp[2] = L'\0';
646                 week = static_cast< int >(wcstol(pTmp, null, 10));
647
648                 dateTime.SetValue(year,1,1);
649                 pDateFormatter->ApplyPattern(formattedString);
650                 pDateFormatter->Format(dateTime, dayno);
651                 Integer::Parse(dayno, day);
652                 days = (week*7) - day;
653
654                 GetDateTimeForWeek(year, days, dateTime);
655                 break;
656
657         case EWK_INPUT_TYPE_DATE :                      //"yyyy-MM-dd"
658                 // year
659                 wcsncpy(pTmp, pMchar, 4);
660                 pTmp[4] = L'\0';
661                 year = static_cast< int >(wcstol(pTmp, null, 10));
662
663                 // month
664                 wcsncpy(pTmp, pMchar + 5, 2);
665                 pTmp[2] = L'\0';
666                 month = static_cast< int >(wcstol(pTmp, null, 10));
667
668                 // day
669                 wcsncpy(pTmp, pMchar + 8, 2);
670                 pTmp[2] = L'\0';
671                 day = static_cast< int >(wcstol(pTmp, null, 10));
672
673                 dateTime.SetValue(year, month, day);
674                 break;
675
676         case EWK_INPUT_TYPE_MONTH :             //"yyyy-MM";
677
678                 // year
679                 wcsncpy(pTmp, pMchar, 4);
680                 pTmp[4] = L'\0';
681                 year = static_cast< int >(wcstol(pTmp, null, 10));
682
683                 // month
684                 wcsncpy(pTmp, pMchar + 5, 2);
685                 pTmp[2] = L'\0';
686                 month = static_cast< int >(wcstol(pTmp, null, 10));
687
688                 dateTime.SetValue(year, month, 1);
689                 break;
690
691         default :
692                 r = E_UNSUPPORTED_OPTION;
693                 SysLogException(NID_WEB_CTRL, r, "[%s] %d is unsupported.", GetErrorMessage(r), __inputType);
694         }
695
696         free(pTmp);
697
698         return r;
699 }
700
701
702 void
703 _InputPickerPopup::GetDateTimeForWeek(int year, int days, DateTime& dateTime)
704 {
705         int monthDays = 0;
706
707         for (int month = 1; month <= 12; month++)
708         {
709                 DateTime::GetDaysInMonth(year, month, monthDays);
710
711                 if (days - monthDays < 0)
712                 {
713                         dateTime.SetValue(year, month, days);
714                         break;
715                 }
716
717                 days -= monthDays;
718         }
719 }
720
721
722 }}} // Tizen::Web::Controls