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