add patch
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_DateTimePresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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                FUiCtrl_DateTimePresenter.cpp
20  * @brief               This is the implementation file for the _DateTimePresenter class.
21  */
22
23 #include <FSysSettingInfo.h>
24 #include <FBaseErrorDefine.h>
25 #include <FBaseSysLog.h>
26 #include <FGrp_TextTextObject.h>
27 #include <FGrp_CanvasImpl.h>
28 #include <FGrp_BitmapImpl.h>
29 #include "FUi_ResourceManager.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiCtrl_DateTimePresenter.h"
32 #include "FUiCtrl_InputPad.h"
33 #include "FUiCtrl_DateTimeDefine.h"
34 #include "FUiCtrl_DateTimeModel.h"
35 #include "FUiCtrl_DateTimeDisplayBox.h"
36 #include "FUiCtrl_DateTimePicker.h"
37 #include "FUiCtrl_DateTimeUtils.h"
38 #include "FUi_AccessibilityManager.h"
39 #include "FUi_CoordinateSystemUtils.h"
40
41 using namespace Tizen::Ui;
42 using namespace Tizen::Base;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Graphics::_Text;
45 using namespace Tizen::Ui::Animations;
46 using namespace Tizen::System;
47
48 namespace Tizen { namespace Ui { namespace Controls
49 {
50 const int DATETIME_DISPLAY_STRING_MAX_LENGTH = 10;
51
52 _DateTimePresenter::_DateTimePresenter(int pickerStyle, const String& title)
53         : __pView(null)
54         , __pModel(null)
55         , __selectedBoxIndex(0)
56         , __focusedBoxIndex(0)
57         , __pInputPad(null)
58         , __inputPadType(INPUTPAD_STYLE_NORMAL)
59         , __pickerStyle(pickerStyle)
60         , __inputPadEnabled(true)
61         , __outputBoxMaxCount(0)
62         , __year(0)
63         , __month(0)
64         , __day(0)
65         , __hour(0)
66         , __minute(0)
67         , __is24HourNotation(false)
68         , __dtp24HourSet(false)
69         , __isPm(false)
70         , __isPmButtonPressed(false)
71         , __isFocusBoxChanged(false)
72         , __inputComposing(DATETIME_INPUT_END)
73         , __changeFocusCounter(DATE_TIME_CHANGE_FOCUS_COUNTER_MIN)
74         , __title(title)
75         , __pColonBitmap(null)
76         , __pColonDisabledBitmap(null)
77         , __pBgNormalBitmap(null)
78         , __pBgEffectBitmap(null)
79         , __pFont(null)
80         , __pPmBox(null)
81         , __keypadEnabled(false)
82 {
83         for (int i = 0; i < DATETIME_ID_MAX; i++)
84         {
85                 __pDisplayBox[i] = null;
86         }
87
88         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
89         {
90                 __pDisplayBoxNormalBitmap[i] = null;
91                 __pDisplayBoxEffectBitmap[i] = null;
92
93                 __pAmPmNormalBitmap[i] = null;
94                 __pAmPmEffectBitmap[i] = null;
95         }
96 }
97
98 _DateTimePresenter::~_DateTimePresenter(void)
99 {
100         Dispose();
101 }
102
103 void
104 _DateTimePresenter::Dispose(void)
105 {
106         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
107         {
108                 delete __pDisplayBoxNormalBitmap[i];
109                 __pDisplayBoxNormalBitmap[i] = null;
110
111                 delete __pDisplayBoxEffectBitmap[i];
112                 __pDisplayBoxEffectBitmap[i] = null;
113
114                 delete __pAmPmNormalBitmap[i];
115                 __pAmPmNormalBitmap[i] = null;
116
117                 delete __pAmPmEffectBitmap[i];
118                 __pAmPmEffectBitmap[i] = null;
119         }
120
121         delete __pColonBitmap;
122         __pColonBitmap = null;
123
124         delete __pColonDisabledBitmap;
125         __pColonDisabledBitmap = null;
126
127         delete __pBgNormalBitmap;
128         __pBgNormalBitmap = null;
129
130         delete __pBgEffectBitmap;
131         __pBgEffectBitmap = null;
132
133         for (int i = 0; i < DATETIME_ID_MAX; i++)
134         {
135                 delete __pDisplayBox[i];
136                 __pDisplayBox[i] = null;
137         }
138
139         delete __pPmBox;
140         __pPmBox = null;
141
142         if ((__inputPadEnabled) && (__pInputPad != null))
143         {
144                 __pView->DetachChild(*__pInputPad);
145                 delete __pInputPad;
146                 __pInputPad = null;
147         }
148
149         delete __pModel;
150         __pModel = null;
151 }
152
153 result
154 _DateTimePresenter::Construct(_DateTimePicker& view)
155 {
156         result r = E_SUCCESS;
157
158         __pView = &view;
159         _ControlOrientation orientation = __pView->GetOrientation();
160
161         __pFont = __pView->GetDateTimeFont();
162         SysTryReturnResult(NID_UI_CTRL, (__pFont != null), E_SYSTEM, "A system error has occurred. Failed to get the font.");
163
164         LoadResource();
165         UpdateDateTimeOutputConfig();
166
167         FloatRectangle inputPadBounds(0.0f, 0.0f, 0.0f, 0.0f);
168         FloatRectangle pickerBounds(0.0f, 0.0f, 0.0f, 0.0f);
169
170         pickerBounds = __pView->GetBoundsF();
171
172         GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, inputPadBounds.height);
173
174         FloatDimension dim;
175         dim = CoordinateSystem::AlignToDevice(FloatDimension(pickerBounds.width, inputPadBounds.height));
176         inputPadBounds.height = dim.height;
177
178         inputPadBounds.x = 0.0f;
179         inputPadBounds.width = pickerBounds.width;
180         inputPadBounds.y = pickerBounds.height - inputPadBounds.height;
181
182         __pModel = new (std::nothrow) _DateTimeModel;
183         SysTryReturnResult(NID_UI_CTRL, (__pModel != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
184
185         // Load display data for sync with model data
186         UpdateTimeFormat();
187         LoadPickerData();
188
189         if (__inputPadEnabled)
190         {
191                 __pInputPad = new (std::nothrow) _InputPad;
192                 SysTryCatch(NID_UI_CTRL, (__pInputPad != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
193
194                 r = __pInputPad->Construct(inputPadBounds);
195                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
196                                         "[E_SYSTEM] A system error has occurred. Failed to construct the instance of Inputpad.");
197
198                 r = __pView->AttachChild(*__pInputPad);
199                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
200
201                 r = __pInputPad->SetInputPadEventListener(*this);
202                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
203                                         "[E_SYSTEM] A system error has occurred. Failed to set InputPadEventListener to the Inputpad.");
204
205                 __pInputPad->SetInputPadStyle(INPUTPAD_STYLE_NORMAL);
206                 r = GetLastResult();
207                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM,
208                                         "[E_SYSTEM] A system error has occurred. Failed to set InputPadStyle to the Inputpad.");
209
210                 __pInputPad->SetFont(__pFont);
211
212                 if (__pInputPad->IsFocusable())
213                 {
214                         __pInputPad->SetFocusable(false);
215                 }
216
217                 _DateTimeDisplayBox* pDisplayBox = __pDisplayBox[__selectedBoxIndex];
218                 SysTryCatch(NID_UI_CTRL, (pDisplayBox != null), , E_SYSTEM,
219                                         "[E_SYSTEM] A system error has occurred. Failed to get Display box.");
220
221                 SetFocusBoxId(pDisplayBox->GetDisplayBoxId());
222         }
223
224         return r;
225
226 CATCH:
227         Dispose();
228
229         return r;
230 }
231
232 result
233 _DateTimePresenter::SetYear(int year)
234 {
235         result r = E_SUCCESS;
236         int minYear = 0;
237         int maxYear = 0;
238
239         GetYearRange(minYear, maxYear);
240
241         if (year < minYear)
242         {
243                 year = minYear;
244         }
245         else if (year > maxYear)
246         {
247                 year = maxYear;
248         }
249
250         r = __pModel->SetYear(year);
251
252         if (r == E_SUCCESS)
253         {
254                 UpdateDisplayData(DATETIME_ID_YEAR);
255         }
256
257         return r;
258 }
259
260 result
261 _DateTimePresenter::SetMonth(int month)
262 {
263         result r = __pModel->SetMonth(month);
264
265         if (r == E_SUCCESS)
266         {
267                 UpdateDisplayData(DATETIME_ID_MONTH);
268         }
269
270         return r;
271 }
272
273 result
274 _DateTimePresenter::SetDay(int day)
275 {
276         result r = __pModel->SetDay(day);
277
278         if (r == E_SUCCESS)
279         {
280                 UpdateDisplayData(DATETIME_ID_DAY);
281         }
282
283         return r;
284 }
285
286 result
287 _DateTimePresenter::SetHour(int hour)
288 {
289         result r = __pModel->SetHour(hour);
290
291         if (r == E_SUCCESS)
292         {
293                 UpdateDisplayData(DATETIME_ID_HOUR);
294         }
295
296         return r;
297 }
298
299 result
300 _DateTimePresenter::SetMinute(int minute)
301 {
302         result r = __pModel->SetMinute(minute);
303
304         if (r == E_SUCCESS)
305         {
306                 UpdateDisplayData(DATETIME_ID_MINUTE);
307         }
308
309         return r;
310 }
311
312 result
313 _DateTimePresenter::SetYearRange(int minYear, int maxYear)
314 {
315         __pModel->SetMinYear(minYear);
316         __pModel->SetMaxYear(maxYear);
317
318         return E_SUCCESS;
319 }
320
321 int
322 _DateTimePresenter::GetYear(void) const
323 {
324         return __pModel->GetYear();
325 }
326
327 int
328 _DateTimePresenter::GetMonth(void) const
329 {
330         return __pModel->GetMonth();
331 }
332
333 int
334 _DateTimePresenter::GetDay(void) const
335 {
336         return __pModel->GetDay();
337 }
338
339 int
340 _DateTimePresenter::GetHour(void) const
341 {
342         return __pModel->GetHour();
343 }
344
345 int
346 _DateTimePresenter::GetMinute(void) const
347 {
348         return __pModel->GetMinute();
349 }
350
351 result
352 _DateTimePresenter::GetYearRange(int& minYear, int& maxYear) const
353 {
354         return __pModel->GetYearRange(minYear, maxYear);
355 }
356
357 void
358 _DateTimePresenter::Set24HourNotationEnabled(bool enable)
359 {
360         __is24HourNotation = enable;
361         __dtp24HourSet = true;
362
363         UpdateDateTimeOutputConfig();
364 }
365
366 bool
367 _DateTimePresenter::Is24HourNotationEnabled(void) const
368 {
369         return __is24HourNotation;
370 }
371
372 void
373 _DateTimePresenter::SetCurrentDateTime(void)
374 {
375         __pModel->SetCurrentDateTime();
376
377         UpdateDisplayData(DATETIME_ID_YEAR);
378         UpdateDisplayData(DATETIME_ID_MONTH);
379         UpdateDisplayData(DATETIME_ID_DAY);
380         UpdateDisplayData(DATETIME_ID_HOUR);
381         UpdateDisplayData(DATETIME_ID_MINUTE);
382 }
383
384 void
385 _DateTimePresenter::SetDateTime(const DateTime& dateTime)
386 {
387         __pModel->SetDateTime(dateTime);
388
389         UpdateDisplayData(DATETIME_ID_YEAR);
390         UpdateDisplayData(DATETIME_ID_MONTH);
391         UpdateDisplayData(DATETIME_ID_DAY);
392         UpdateDisplayData(DATETIME_ID_HOUR);
393         UpdateDisplayData(DATETIME_ID_MINUTE);
394 }
395
396 DateTime
397 _DateTimePresenter::GetDateTime(void) const
398 {
399         return __pModel->GetDateTime();
400 }
401
402 void
403 _DateTimePresenter::SetFocusBoxId(int boxId)
404 {
405         for (int i = 0; i < __outputBoxMaxCount; i++)
406         {
407                 int displayBoxId = __pDisplayBox[i]->GetDisplayBoxId();
408
409                 if (boxId == displayBoxId)
410                 {
411                         SetFocusBox(i);
412                         return;
413                 }
414         }
415 }
416
417 const _DateTimeDisplayBox*
418 _DateTimePresenter::GetDisplayBox(int index) const
419 {
420         return __pDisplayBox[index];
421 }
422
423 const _DateTimeDisplayBox*
424 _DateTimePresenter::GetAmPmBox(void) const
425 {
426         return __pPmBox;
427 }
428
429 bool
430 _DateTimePresenter::Draw(void)
431 {
432         result r = E_SUCCESS;
433
434         _VisualElement* pVisualElement = null;
435         Canvas* pCanvas = null;
436         Color backgroundColor;
437
438         pVisualElement = __pView->GetDisplayVisualElement();
439         r = GetLastResult();
440         SysTryReturn(NID_UI_CTRL, (pVisualElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
441
442         pCanvas = pVisualElement->GetCanvasN();
443         r = GetLastResult();
444         SysTryReturn(NID_UI_CTRL, (pCanvas != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
445
446         // Draw Background
447         GET_COLOR_CONFIG(DATETIMEPICKER::BG_NORMAL, backgroundColor);
448         __pView->SetBackgroundColor(backgroundColor);
449
450         // Draw DisplayBox Background
451         DrawBackground(*pCanvas);
452
453         if (!__title.IsEmpty())
454         {
455                 DrawTitle(*pCanvas);
456         }
457
458         for (int i = 0; i < __outputBoxMaxCount; i++)
459         {
460                 DrawDateTimeDisplayBox(*pCanvas, i);
461         }
462
463         if ((__pickerStyle & DATETIME_OUTPUT_STYLE_DATE) && (__pickerStyle & DATETIME_OUTPUT_STYLE_TIME))
464         {
465                 DrawDividers(*pCanvas);
466                 DrawColon(*pCanvas);
467                 DrawPm(*pCanvas);
468         }
469         else if (__pickerStyle & DATETIME_OUTPUT_STYLE_TIME)
470         {
471                 DrawColon(*pCanvas);
472                 DrawPm(*pCanvas);
473         }
474
475         if (unlikely(_AccessibilityManager::IsActivated()))
476         {
477                 SetAccessibilityElementText();
478         }
479
480         delete pCanvas;
481
482         return true;
483 }
484
485 result
486 _DateTimePresenter::SetFont(Font* pFont)
487 {
488         result r = E_SUCCESS;
489         float fontSize = 0;
490
491         if (__pView == null)
492         {
493                 return E_SUCCESS;
494         }
495
496         GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, __pView->GetOrientation(), fontSize);
497
498         r = _FontImpl::GetInstance(*pFont)->SetStyle(FONT_STYLE_PLAIN);
499         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
500
501         r = _FontImpl::GetInstance(*pFont)->SetSize(fontSize);
502         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
503
504         for (int i = 0; i < DATETIME_ID_MAX; i++)
505         {
506                 if (__pDisplayBox[i] != null)
507                 {
508                         __pDisplayBox[i]->SetFont(pFont);
509                 }
510         }
511
512         if (__pPmBox != null)
513         {
514                 __pPmBox->SetFont(pFont);
515         }
516
517         if (__pInputPad != null)
518         {
519                 __pInputPad->SetFont(pFont);
520         }
521
522         __pFont = pFont;
523
524         return E_SUCCESS;
525 }
526
527 void
528 _DateTimePresenter::UpdateLocaleDateTimeFormat(void)
529 {
530         UpdateTimeFormat();
531
532         UpdateDateTimeOutputConfig();
533
534         LoadPickerData();
535
536         for (int i = 0; i < __outputBoxMaxCount; i++)
537         {
538                 AdjustDisplayValue(i);
539         }
540
541         return;
542 }
543
544 void
545 _DateTimePresenter::UpdateTimeFormat(void)
546 {
547         if (!__dtp24HourSet)
548         {
549                 String key(L"http://tizen.org/setting/locale.time.format.24hour");
550                 SettingInfo::GetValue(key , __is24HourNotation);
551         }
552
553         return;
554 }
555
556 void
557 _DateTimePresenter::OnChangeLayout(_ControlOrientation orientation)
558 {
559         result r = E_SUCCESS;
560         FloatRectangle inputPadBounds(0.0f, 0.0f, 0.0f, 0.0f);
561         FloatRectangle pickerBounds(0.0f, 0.0f, 0.0f, 0.0f);
562
563         pickerBounds = __pView->GetBoundsF();
564
565         UpdateDateTimeOutputConfig();
566
567         inputPadBounds.x = 0;
568
569         GET_SHAPE_CONFIG(DATETIMEPICKER::INPUTPAD_HEIGHT, orientation, inputPadBounds.height);
570
571         inputPadBounds.width = pickerBounds.width;
572         inputPadBounds.y = pickerBounds.height - inputPadBounds.height;
573
574         if (__pInputPad != null)
575         {
576                 r = __pInputPad->SetBounds(inputPadBounds);
577                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
578         }
579 }
580
581 bool
582 _DateTimePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
583 {
584         if (__pView != &source)
585         {
586                 return false;
587         }
588
589         int touchedAreaId = CalculateTouchArea(touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
590
591         if (touchedAreaId == DATETIME_AREA_OUTPUT_AMPM)
592         {
593                 __isPmButtonPressed = true;
594                 __pView->Invalidate(true);
595                 return true;
596         }
597
598         return true;
599 }
600
601 bool
602 _DateTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
603 {
604         if (__pView != &source)
605         {
606                 return false;
607         }
608
609         return true;
610 }
611
612 bool
613 _DateTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
614 {
615         result r = E_SUCCESS;
616
617         if (__pView != &source)
618         {
619                 return false;
620         }
621
622         int touchedAreaId = CalculateTouchArea(touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
623
624         if (__isPmButtonPressed)
625         {
626                 if (touchedAreaId == DATETIME_AREA_OUTPUT_AMPM)
627                 {
628                         __isPm = (!__isPm);
629                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pView);
630                 }
631
632                 __inputComposing = DATETIME_INPUT_END;
633                 __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
634                 __isPmButtonPressed = false;
635                 AdjustDisplayValue(__selectedBoxIndex);
636                 __pView->Invalidate(true);
637
638                 return true;
639         }
640
641         if ((touchedAreaId == DATETIME_AREA_NONE) || (touchedAreaId == DATETIME_AREA_INPUT) ||
642                 (touchedAreaId == DATETIME_AREA_OUTPUT_AMPM))
643         {
644                 __isPmButtonPressed = false;
645                 __pView->Invalidate(true);
646
647                 return true;
648         }
649
650         int newOutputFocusedIndex = -1;
651
652         if (touchedAreaId == DATETIME_AREA_OUTPUT)
653         {
654                 newOutputFocusedIndex = CalculateTouchOutputArea(touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
655
656                 if (newOutputFocusedIndex == (-1))
657                 {
658                         return true;
659                 }
660
661                 for (int i = 0; i < __outputBoxMaxCount; i++)
662                 {
663                         AdjustDisplayValue(i);
664                 }
665
666                 if (newOutputFocusedIndex != __selectedBoxIndex)
667                 {
668                         __selectedBoxIndex = newOutputFocusedIndex;
669                 }
670
671                 _VisualElement* pVisualElement = null;
672                 Canvas* pCanvas = null;
673
674                 pVisualElement = __pView->GetDisplayVisualElement();
675                 r = GetLastResult();
676                 SysTryReturn(NID_UI_CTRL, (pVisualElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
677
678                 pCanvas = pVisualElement->GetCanvasN();
679                 r = GetLastResult();
680                 SysTryReturn(NID_UI_CTRL, (pCanvas != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
681
682                 DrawDateTimeDisplayBox(*pCanvas, __selectedBoxIndex);
683
684                 delete pCanvas;
685
686                 __inputComposing = DATETIME_INPUT_END;
687                 __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
688
689                 int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
690                 ChangeInputPadStyle(boxId);
691
692                 __pView->Invalidate(true);
693
694                 return true;
695         }
696
697         return true;
698 }
699
700 bool
701 _DateTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
702 {
703         if (__pView != &source)
704         {
705                 return false;
706         }
707
708         __isPmButtonPressed = false;
709         __inputComposing = DATETIME_INPUT_END;
710         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
711
712         __pView->Invalidate(true);
713
714         return true;
715 }
716
717 void
718 _DateTimePresenter::OnInputPadValueChanged(const _Control& source, int inputPadReturnValue)
719 {
720         HandleInputPadValueChange(inputPadReturnValue);
721 }
722
723 void
724 _DateTimePresenter::OnActionPerformed(const _Control& source, int actionId)
725 {
726         HandleSaveCancelAction(actionId);
727 }
728
729 bool
730 _DateTimePresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
731 {
732         if (!__keypadEnabled)
733         {
734                 return false;
735         }
736
737         _KeyCode keyCode = keyInfo.GetKeyCode();
738
739         switch (keyCode)
740         {
741                 case _KEY_RIGHT:
742                 {
743                         if (__pickerStyle != DATETIME_OUTPUT_STYLE_DATE && __focusedBoxIndex < __outputBoxMaxCount)
744                         {
745                                 __focusedBoxIndex++;
746                                 SetFocusBox(__focusedBoxIndex);
747                         }
748                         else if (__pickerStyle == DATETIME_OUTPUT_STYLE_DATE && __focusedBoxIndex < __outputBoxMaxCount-1)
749                         {
750                                 __focusedBoxIndex++;
751                                 SetFocusBox(__focusedBoxIndex);
752                         }
753                         else
754                         {
755                                 return false;
756                         }
757                 }
758                 break;
759                 case _KEY_LEFT:
760                 {
761                         if (__focusedBoxIndex  > 0)
762                         {
763                                 __focusedBoxIndex--;
764                                 SetFocusBox(__focusedBoxIndex);
765                         }
766                         else
767                         {
768                                 return false;
769                         }
770                 }
771                 break;
772                 case _KEY_ENTER:
773                 {
774                         if (__focusedBoxIndex == __outputBoxMaxCount)
775                         {
776                                 __isPmButtonPressed = true;
777                         }
778                 }
779                 break;
780                 case _KEY_0:
781                 case _KEY_NUMPAD_0:
782                         HandleInputPadValueChange(0);
783                         break;
784                 case _KEY_1:
785                 case _KEY_NUMPAD_1:
786                         HandleInputPadValueChange(1);
787                         break;
788                 case _KEY_2:
789                 case _KEY_NUMPAD_2:
790                         HandleInputPadValueChange(2);
791                         break;
792                 case _KEY_3:
793                 case _KEY_NUMPAD_3:
794                         HandleInputPadValueChange(3);
795                         break;
796                 case _KEY_4:
797                 case _KEY_NUMPAD_4:
798                         HandleInputPadValueChange(4);
799                         break;
800                 case _KEY_5:
801                 case _KEY_NUMPAD_5:
802                         HandleInputPadValueChange(5);
803                         break;
804                 case _KEY_6:
805                 case _KEY_NUMPAD_6:
806                         HandleInputPadValueChange(6);
807                         break;
808                 case _KEY_7:
809                 case _KEY_NUMPAD_7:
810                         HandleInputPadValueChange(7);
811                         break;
812                 case _KEY_8:
813                 case _KEY_NUMPAD_8:
814                         HandleInputPadValueChange(8);
815                         break;
816                 case _KEY_9:
817                 case _KEY_NUMPAD_9:
818                         HandleInputPadValueChange(9);
819                         break;
820                 default:
821                         return false;
822         }
823
824         __pView->Invalidate(true);
825         return true;
826 }
827
828 bool
829 _DateTimePresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
830 {
831         _KeyCode keyCode = keyInfo.GetKeyCode();
832
833         if (keyCode == _KEY_ESC || keyCode == _KEY_BACK)
834         {
835                 HandleSaveCancelAction(DATETIME_EVENT_ID_CANCEL);
836                 return true;
837         }
838
839         if (!__keypadEnabled)
840         {
841                 return false;
842         }
843
844         if (__isPmButtonPressed && keyCode == _KEY_ENTER)
845         {
846                 __isPm = (!__isPm);
847                 __isPmButtonPressed = false;
848                 __pView->Invalidate(true);
849         }
850
851         return true;
852 }
853
854 result
855 _DateTimePresenter::DrawFocus(void)
856 {
857         result r = E_SUCCESS;
858         __keypadEnabled = true;
859         SetFocusBox(0);
860
861         __pView->Invalidate(true);
862         return r;
863 }
864
865 result
866 _DateTimePresenter::ReleaseFocus(void)
867 {
868         result r = E_SUCCESS;
869         __keypadEnabled = false;
870
871         if (__pickerStyle != DATETIME_OUTPUT_STYLE_DATE && __focusedBoxIndex == __outputBoxMaxCount)
872         {
873                 __selectedBoxIndex = __outputBoxMaxCount - 1; //minute
874         }
875         else
876         {
877                 __selectedBoxIndex = __focusedBoxIndex;
878         }
879         __focusedBoxIndex = 0;
880
881         __pView->Invalidate(true);
882         return r;
883 }
884
885 void
886 _DateTimePresenter::HandleInputPadValueChange(int inputPadReturnValue)
887 {
888         if ((!__inputPadEnabled) || (inputPadReturnValue == -1))
889         {
890                 return;
891         }
892
893         if ((__keypadEnabled) && (__pickerStyle != DATETIME_OUTPUT_STYLE_DATE) && (__focusedBoxIndex == __outputBoxMaxCount))
894         {
895                 //in case of Am/Pm if keypad enabled, inputpad values need not be handled though in focus
896                 return;
897         }
898
899         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
900         int currentNumber = GetNumberInBox(boxId);
901         int newNumber = 0;
902
903         if (boxId == DATETIME_ID_YEAR)
904         {
905                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SIP, __pView);
906                 __changeFocusCounter++;
907
908                 if (__isFocusBoxChanged)
909                 {
910                         newNumber = inputPadReturnValue;
911                         __isFocusBoxChanged = false;
912                 }
913                 else
914                 {
915                         newNumber = SetFourDigit(currentNumber, inputPadReturnValue);
916                 }
917
918                 __inputComposing = DATETIME_INPUT_BEGIN;
919                 SetNumberInBox(boxId, newNumber);
920
921                 int min = 0;
922                 int max = 0;
923
924                 GetYearRange(min, max);
925
926                 if ((newNumber >= max) || (newNumber > DATETIME_THREE_DIGIT_MAX) || __changeFocusCounter == DATE_TIME_CHANGE_FOCUS_COUNTER_MAX)
927                 {
928                         ChangeFocusBox();
929                 }
930         }
931         else if (boxId == DATETIME_ID_MONTH)
932         {
933                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SIP, __pView);
934
935                 if (__inputComposing == DATETIME_INPUT_BEGIN && __keypadEnabled)
936                 {
937                         currentNumber = GetNumberInBox(boxId);
938                         newNumber = currentNumber * 10 + inputPadReturnValue;
939
940                         if (newNumber > 12)
941                         {
942                                 newNumber = 12;
943                         }
944                         else if (newNumber < 1)
945                         {
946                                 newNumber = 1;
947                         }
948
949                         ChangeFocusBox();
950                 }
951                 else
952                 {
953                         if (inputPadReturnValue == 0)
954                         {
955                                 return;
956                         }
957                         newNumber = inputPadReturnValue;
958                         __inputComposing = DATETIME_INPUT_BEGIN;
959
960                         if (!__keypadEnabled || newNumber > 1)
961                         {
962                                 ChangeFocusBox();
963                         }
964                 }
965
966                 SetNumberInBox(boxId, newNumber);
967         }
968         else
969         {
970                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SIP, __pView);
971                 __changeFocusCounter++;
972
973                 if (__isFocusBoxChanged)
974                 {
975                         newNumber = inputPadReturnValue;
976                         __isFocusBoxChanged = false;
977                 }
978                 else
979                 {
980                         newNumber = SetTwoDigit(currentNumber, inputPadReturnValue);
981                 }
982
983                 __inputComposing = DATETIME_INPUT_BEGIN;
984
985                 SetNumberInBox(boxId, newNumber);
986
987                 if (newNumber > DATETIME_ONE_DIGIT_MAX || __changeFocusCounter == DATE_TIME_CHANGE_FOCUS_COUNTER_MAX / 2)
988                 {
989                         ChangeFocusBox();
990                 }
991         }
992
993         __pView->Invalidate(true);
994 }
995
996 void
997 _DateTimePresenter::HandleSaveCancelAction(int actionId)
998 {
999         result r = E_SUCCESS;
1000
1001         if (__pView == null)
1002         {
1003                 return;
1004         }
1005
1006         if (actionId != DATETIME_EVENT_ID_SAVE && actionId != DATETIME_EVENT_ID_CANCEL )
1007         {
1008                 return;
1009         }
1010
1011         DateTime dateTime;
1012
1013         __inputComposing = DATETIME_INPUT_END;
1014         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
1015         __focusedBoxIndex = 0;
1016         __selectedBoxIndex = 0;
1017
1018         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
1019
1020         SetFocusBoxId(boxId);
1021         __pView->Close();
1022
1023         if (actionId == DATETIME_EVENT_ID_SAVE)
1024         {
1025                 for (int i = 0; i < __outputBoxMaxCount; i++)
1026                 {
1027                         AdjustDisplayValue(i);
1028                 }
1029
1030                 SavePickerData();
1031
1032                 switch (__pickerStyle)
1033                 {
1034                 case DATETIME_OUTPUT_STYLE_DATE:
1035                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
1036                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1037
1038                         r = __pView->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED, dateTime);
1039                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to fire the event for DateTime change saved.");
1040                         break;
1041
1042                 case DATETIME_OUTPUT_STYLE_TIME:
1043                         r = dateTime.SetValue(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1044                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1045
1046                         r = __pView->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED, dateTime);
1047                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to fire the event for DateTime change saved.");
1048                         break;
1049
1050                 case DATETIME_OUTPUT_STYLE_DATETIME:
1051                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1052                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1053
1054                         r = __pView->FireDateTimeChangeEvent(DATETIME_INTERNAL_CHANGE_SAVED, dateTime);
1055                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to fire the event for DateTime change saved.");
1056                         break;
1057
1058                 default:
1059                         break;
1060                 }
1061         }
1062         else if (actionId == DATETIME_EVENT_ID_CANCEL)
1063         {
1064                 LoadPickerData();
1065
1066                 switch (__pickerStyle)
1067                 {
1068                 case DATETIME_OUTPUT_STYLE_DATE:
1069                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
1070                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1071
1072                         r = __pView->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_CANCELED, dateTime);
1073                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to fire the event for DateTime change canceled.");
1074                         break;
1075
1076                 case DATETIME_OUTPUT_STYLE_TIME:
1077                         r = dateTime.SetValue(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1078                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1079
1080                         r = __pView->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_CANCELED, dateTime);
1081                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to fire the event for DateTime change canceled.");
1082                         break;
1083
1084                 case DATETIME_OUTPUT_STYLE_DATETIME:
1085                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1086                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1087
1088                         r = __pView->FireDateTimeChangeEvent(DATETIME_INTERNAL_CHANGE_CANCELED, dateTime);
1089                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to fire the event for DateTime change canceled.");
1090                         break;
1091
1092                 default:
1093                         break;
1094                 }
1095         }
1096 }
1097
1098 void
1099 _DateTimePresenter::UpdateDateTimeOutputConfig(void)
1100 {
1101         _ControlOrientation orientation = __pView->GetOrientation();
1102         _DateTimeDisplayBox* pPmBox = null;
1103         _DateTimeDisplayBox* pDisplayBox[DATETIME_ID_MAX];
1104
1105         FloatRectangle outputAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
1106         FloatRectangle dateBounds(0.0f, 0.0f, 0.0f, 0.0f);
1107         FloatRectangle monthBounds(0.0f, 0.0f, 0.0f, 0.0f);
1108         FloatRectangle yearBounds(0.0f, 0.0f, 0.0f, 0.0f);
1109         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1110         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1111         FloatRectangle amPmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1112
1113         int indexBox = 0;
1114         int boxCount = 0;
1115
1116         float dateTimeDisplayBoxHeight = 0.0f;
1117         float amPmDisplayBoxHeight = 0.0f;
1118
1119         float dateTimeElementY = 0.0f;
1120         float amPmElementY = 0.0f;
1121         float dateElementGapWidth = 0.0f;
1122         float timeOutputMargin = 0.0f;
1123         float timeElementWidth = 0.0f;
1124         float colonWidth = 0.0f;
1125         float colonMargin = 0.0f;
1126         float amPmWidth = 0.0f;
1127         float amPmMargin = 0.0f;
1128
1129         float dividerWidth = 0.0f;
1130         float dividerMargin = 0.0f;
1131
1132         for (indexBox = 0; indexBox < DATETIME_ID_MAX; indexBox++)
1133         {
1134                 pDisplayBox[indexBox] = null;
1135         }
1136
1137         outputAreaBounds = GetOutputArea();
1138         __pView->SetDisplayVisualElementBounds(outputAreaBounds);
1139
1140         GET_SHAPE_CONFIG(DATETIMEPICKER::DATE_ELEMENT_GAP_WIDTH, orientation, dateElementGapWidth);
1141
1142         GET_SHAPE_CONFIG(DATETIMEPICKER::DATE_ELEMENT_WIDTH, orientation, dateBounds.width);
1143         GET_SHAPE_CONFIG(DATETIMEPICKER::MONTH_ELEMENT_WIDTH, orientation, monthBounds.width);
1144         GET_SHAPE_CONFIG(DATETIMEPICKER::YEAR_ELEMENT_WIDTH, orientation, yearBounds.width);
1145
1146         GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, orientation, dateTimeDisplayBoxHeight);
1147         GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, orientation, amPmDisplayBoxHeight);
1148
1149         GET_SHAPE_CONFIG(DATETIMEPICKER::TIME_OUTPUT_MARGIN, orientation, timeOutputMargin);
1150         GET_SHAPE_CONFIG(DATETIMEPICKER::TIME_ELEMENT_WIDTH, orientation, timeElementWidth);
1151
1152         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_WIDTH, orientation, colonWidth);
1153         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_MARGIN, orientation, colonMargin);
1154
1155         GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_WIDTH, orientation, amPmWidth);
1156         GET_SHAPE_CONFIG(DATETIMEPICKER::TIME_AMPM_MARGIN, orientation, amPmMargin);
1157
1158         GET_FIXED_VALUE_CONFIG(DATETIMEPICKER::DIVIDER_WIDTH, orientation, dividerWidth);
1159         GET_SHAPE_CONFIG(DATETIMEPICKER::DIVIDER_MARGIN, orientation, dividerMargin);
1160
1161         hourBounds.width = minuteBounds.width = timeElementWidth;
1162         amPmBounds.width = amPmWidth;
1163
1164         dateBounds.height = monthBounds.height = yearBounds.height = hourBounds.height = minuteBounds.height = dateTimeDisplayBoxHeight;
1165         amPmBounds.height = amPmDisplayBoxHeight;
1166
1167         if (__title.IsEmpty())
1168         {
1169                 dateTimeElementY = (outputAreaBounds.height - dateTimeDisplayBoxHeight) / 2.0f;
1170                 amPmElementY = (outputAreaBounds.height - amPmDisplayBoxHeight) / 2.0f;
1171         }
1172         else
1173         {
1174                 float topMargin = 0.0f;
1175                 float bottomMargin = 0.0f;
1176                 float titleHeight = 0.0f;
1177
1178                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
1179                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
1180                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
1181
1182                 dateTimeElementY = topMargin + titleHeight + bottomMargin;
1183                 amPmElementY = topMargin + titleHeight;
1184         }
1185
1186         dateBounds.y = monthBounds.y = yearBounds.y = hourBounds.y = minuteBounds.y = dateTimeElementY;
1187         amPmBounds.y = amPmElementY;
1188
1189         if (__pickerStyle == DATETIME_OUTPUT_STYLE_DATE || __pickerStyle == DATETIME_OUTPUT_STYLE_DATETIME)
1190         {
1191                 float leftMargin = 0.0f;
1192                 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_OUTPUT_LEFT_MARGIN, orientation, leftMargin);
1193
1194                 _DateTimeUtils dateTimeUtils;
1195                 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
1196
1197                 switch (localeDateFormat)
1198                 {
1199                 case DATE_FORMAT_DDMMYYYY:
1200                         {
1201                                 dateBounds.x = leftMargin;
1202                                 monthBounds.x = dateBounds.x + dateBounds.width + dateElementGapWidth;
1203                                 yearBounds.x = monthBounds.x + monthBounds.width + dateElementGapWidth;
1204                                 hourBounds.x = yearBounds.x + yearBounds.width + (2 * dividerMargin + dividerWidth);
1205
1206                                 // Date
1207                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1208                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1209
1210                                 boxCount++;
1211
1212                                 // Month
1213                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1214                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1215
1216                                 boxCount++;
1217
1218                                 // Year
1219                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1220                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1221
1222                                 boxCount++;
1223                         }
1224                         break;
1225                 case DATE_FORMAT_MMDDYYYY:
1226                         {
1227                                 monthBounds.x = leftMargin;
1228                                 dateBounds.x = monthBounds.x + monthBounds.width + dateElementGapWidth;
1229                                 yearBounds.x = dateBounds.x + dateBounds.width + dateElementGapWidth;
1230                                 hourBounds.x = yearBounds.x + yearBounds.width + (2 * dividerMargin + dividerWidth);
1231
1232                                 // Month
1233                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1234                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1235
1236                                 boxCount++;
1237
1238                                 // Date
1239                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1240                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1241
1242                                 boxCount++;
1243
1244                                 // Year
1245                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1246                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1247
1248                                 boxCount++;
1249                         }
1250                         break;
1251                 case DATE_FORMAT_YYYYMMDD:
1252                         {
1253                                 yearBounds.x = leftMargin;
1254                                 monthBounds.x = yearBounds.x + yearBounds.width + dateElementGapWidth;
1255                                 dateBounds.x = monthBounds.x + monthBounds.width + dateElementGapWidth;
1256                                 hourBounds.x = dateBounds.x + dateBounds.width + (2 * dividerMargin + dividerWidth);
1257
1258                                 // Year
1259                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1260                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1261
1262                                 boxCount++;
1263
1264                                 // Month
1265                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1266                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1267
1268                                 boxCount++;
1269
1270                                 // Date
1271                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1272                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1273
1274                                 boxCount++;
1275                         }
1276                         break;
1277                 case DATE_FORMAT_YYYYDDMM:
1278                         {
1279                                 yearBounds.x = leftMargin;
1280                                 dateBounds.x = yearBounds.x + yearBounds.width + dateElementGapWidth;
1281                                 monthBounds.x = dateBounds.x + dateBounds.width + dateElementGapWidth;
1282                                 hourBounds.x = monthBounds.x + monthBounds.width + (2 * dividerMargin + dividerWidth);
1283
1284                                 // Year
1285                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1286                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1287
1288                                 boxCount++;
1289
1290                                 // Date
1291                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1292                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1293
1294                                 boxCount++;
1295
1296                                 // Month
1297                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1298                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1299
1300                                 boxCount++;
1301                         }
1302                         break;
1303                 }
1304         }
1305
1306         if (__pickerStyle == DATETIME_OUTPUT_STYLE_TIME || __pickerStyle == DATETIME_OUTPUT_STYLE_DATETIME)
1307         {
1308                 if (__pickerStyle == DATETIME_OUTPUT_STYLE_DATETIME)
1309                 {
1310                         minuteBounds.x = hourBounds.x + hourBounds.width + colonWidth + 2 * colonMargin;
1311                         amPmBounds.x = minuteBounds.x + minuteBounds.width + amPmMargin;
1312                 }
1313                 else
1314                 {
1315                         hourBounds.x = timeOutputMargin;
1316                         minuteBounds.x = hourBounds.x + hourBounds.width + colonWidth + 2 * colonMargin;
1317                         amPmBounds.x = minuteBounds.x + minuteBounds.width + amPmMargin;
1318                 }
1319
1320                 // Hour
1321                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(hourBounds, DATETIME_ID_HOUR);
1322                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1323
1324                 boxCount++;
1325
1326                 // Minute
1327                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(minuteBounds, DATETIME_ID_MINUTE);
1328                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1329
1330                 boxCount++;
1331
1332                 // AmPm Button
1333                 if (!__is24HourNotation)
1334                 {
1335                         pPmBox = new (std::nothrow) _DateTimeDisplayBox(amPmBounds, DATETIME_ID_AMPM);
1336                         SysTryCatch(NID_UI_CTRL, (pPmBox != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1337
1338                         pPmBox->SetBackgroundBitmap(__pAmPmNormalBitmap, __pAmPmEffectBitmap);
1339
1340                         delete __pPmBox;
1341                         __pPmBox = pPmBox;
1342                 }
1343         }
1344
1345         __outputBoxMaxCount = boxCount;
1346
1347         for (indexBox = 0; indexBox < DATETIME_ID_MAX; indexBox++)
1348         {
1349                 delete __pDisplayBox[indexBox];
1350
1351                 if (pDisplayBox[indexBox] != null)
1352                 {
1353                         pDisplayBox[indexBox]->SetBackgroundBitmap(__pDisplayBoxNormalBitmap, __pDisplayBoxEffectBitmap);
1354                 }
1355
1356                 __pDisplayBox[indexBox] = pDisplayBox[indexBox];
1357         }
1358
1359         SetFont(__pFont);
1360
1361         return;
1362
1363 CATCH:
1364         for (int i = 0; i < DATETIME_ID_MAX; i++)
1365         {
1366                 delete pDisplayBox[i];
1367                 pDisplayBox[i] = null;
1368         }
1369
1370         return;
1371 }
1372
1373 void
1374 _DateTimePresenter::LoadResource(void)
1375 {
1376         result r = E_SUCCESS;
1377         Color color;
1378         Color replacementColor = Color::GetColor(COLOR_ID_MAGENTA);
1379         Color backgroundColor[DATETIME_STATUS_MAX];
1380         bool isDisplayBoxCustomBitmap[DATETIME_STATUS_MAX];
1381         bool isAmPmCustomBitmap[DATETIME_STATUS_MAX];
1382
1383         Bitmap* pDisplayBoxNormalBitmap[DATETIME_STATUS_MAX];
1384         Bitmap* pAmPmNormalBitmap[DATETIME_STATUS_MAX];
1385         Bitmap* pBgBitmap = null;
1386         Bitmap* pColonBitmap = null;
1387
1388         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1389         {
1390                 pDisplayBoxNormalBitmap[i] = null;
1391                 pAmPmNormalBitmap[i] = null;
1392                 backgroundColor[i] = Color();
1393                 isDisplayBoxCustomBitmap[i] = false;
1394                 isAmPmCustomBitmap[i] = false;
1395         }
1396
1397         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_NORMAL, backgroundColor[DATETIME_STATUS_NORMAL]);
1398         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_PRESSED, backgroundColor[DATETIME_STATUS_SELECTED]);
1399         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED, backgroundColor[DATETIME_STATUS_HIGHLIGHTED]);
1400         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_DISABLED, backgroundColor[DATETIME_STATUS_DISABLED]);
1401
1402         //display area bg
1403         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBgBitmap);
1404         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1405
1406         GET_COLOR_CONFIG(DATETIMEPICKER::DISPLAY_BG_NORMAL, color);
1407         __pBgNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBgBitmap, replacementColor, color);
1408         r = GetLastResult();
1409         SysTryCatch(NID_UI_CTRL, (__pBgNormalBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1410
1411         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::COLON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pColonBitmap);
1412         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1413
1414         GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_NORMAL, color);
1415         __pColonBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pColonBitmap, replacementColor, color);
1416         r = GetLastResult();
1417         SysTryCatch(NID_UI_CTRL, (__pColonBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1418
1419         GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_DISABLED, color);
1420         __pColonDisabledBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pColonBitmap, replacementColor, color);
1421         r = GetLastResult();
1422         SysTryCatch(NID_UI_CTRL, (__pColonDisabledBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1423
1424         //display area bg effect
1425         if (!IS_CUSTOM_BITMAP(DATETIMEPICKER::BG_NORMAL))
1426         {
1427                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgEffectBitmap);
1428                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1429         }
1430
1431         //display box
1432         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_NORMAL]);
1433         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1434
1435         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_SELECTED]);
1436         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1437
1438         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1439         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1440
1441         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_DISABLED]);
1442         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1443
1444         //ampm
1445         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_NORMAL]);
1446         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1447
1448         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_SELECTED]);
1449         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1450
1451         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1452         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1453
1454         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_DISABLED]);
1455         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1456
1457         isDisplayBoxCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_NORMAL);
1458         isDisplayBoxCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_PRESSED);
1459         isDisplayBoxCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_HIGHLIGHTED);
1460         isDisplayBoxCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_DISABLED);
1461
1462         isAmPmCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_NORMAL);
1463         isAmPmCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_PRESSED);
1464         isAmPmCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED);
1465         isAmPmCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_DISABLED);
1466
1467         //displaybox
1468         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1469         {
1470                 if (isDisplayBoxCustomBitmap[i])
1471                 {
1472                         __pDisplayBoxNormalBitmap[i] = pDisplayBoxNormalBitmap[i];
1473                 }
1474                 else
1475                 {
1476                         __pDisplayBoxNormalBitmap[i] = _BitmapImpl::GetColorReplacedBitmapN(*pDisplayBoxNormalBitmap[i], replacementColor, backgroundColor[i]);
1477                         SysTryCatch(NID_UI_CTRL, (__pDisplayBoxNormalBitmap[i] != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1478                 }
1479         }
1480
1481         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_NORMAL])
1482         {
1483                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_NORMAL]);
1484                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1485         }
1486
1487         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_SELECTED])
1488         {
1489                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_SELECTED]);
1490                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1491         }
1492
1493         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_HIGHLIGHTED])
1494         {
1495                 Bitmap* pTempBitmap = null;
1496
1497                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
1498                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1499
1500
1501                 __pDisplayBoxEffectBitmap[DATETIME_STATUS_HIGHLIGHTED] = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), backgroundColor[DATETIME_STATUS_HIGHLIGHTED]);
1502                 SysTryCatch(NID_UI_CTRL, (__pDisplayBoxEffectBitmap[DATETIME_STATUS_HIGHLIGHTED] != null), r = GetLastResult(), GetLastResult(),
1503                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1504
1505                 delete pTempBitmap;
1506         }
1507
1508         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_DISABLED])
1509         {
1510                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_DISABLED]);
1511                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1512         }
1513
1514
1515         //ampm
1516         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1517         {
1518                 if (isAmPmCustomBitmap[i])
1519                 {
1520                         __pAmPmNormalBitmap[i] = pAmPmNormalBitmap[i];
1521                 }
1522                 else
1523                 {
1524                         __pAmPmNormalBitmap[i] = _BitmapImpl::GetColorReplacedBitmapN(*pAmPmNormalBitmap[i], replacementColor, backgroundColor[i]);
1525                         SysTryCatch(NID_UI_CTRL, (__pAmPmNormalBitmap[i] != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1526                 }
1527         }
1528
1529         if (!isAmPmCustomBitmap[DATETIME_STATUS_NORMAL])
1530         {
1531                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_NORMAL]);
1532                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1533         }
1534
1535         if (!isAmPmCustomBitmap[DATETIME_STATUS_SELECTED])
1536         {
1537                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_SELECTED]);
1538                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1539         }
1540
1541         if (!isAmPmCustomBitmap[DATETIME_STATUS_HIGHLIGHTED])
1542         {
1543                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1544                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1545         }
1546
1547         if (!isAmPmCustomBitmap[DATETIME_STATUS_DISABLED])
1548         {
1549                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_DISABLED]);
1550                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1551         }
1552
1553         delete pColonBitmap;
1554         delete pBgBitmap;
1555
1556         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1557         {
1558                 delete pDisplayBoxNormalBitmap[i];
1559                 delete pAmPmNormalBitmap[i];
1560         }
1561
1562         return;
1563
1564 CATCH:
1565         delete pColonBitmap;
1566
1567         delete __pColonBitmap;
1568         __pColonBitmap = null;
1569
1570         delete __pColonDisabledBitmap;
1571         __pColonDisabledBitmap = null;
1572
1573         delete pBgBitmap;
1574
1575         delete __pBgNormalBitmap;
1576         __pBgNormalBitmap = null;
1577
1578         delete __pBgEffectBitmap;
1579         __pBgEffectBitmap = null;
1580
1581         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1582         {
1583                 delete pDisplayBoxNormalBitmap[i];
1584
1585                 delete __pDisplayBoxNormalBitmap[i];
1586                 __pDisplayBoxNormalBitmap[i] = null;
1587
1588                 delete __pDisplayBoxEffectBitmap[i];
1589                 __pDisplayBoxEffectBitmap[i] = null;
1590
1591                 delete pAmPmNormalBitmap[i];
1592
1593                 delete __pAmPmNormalBitmap[i];
1594                 __pAmPmNormalBitmap[i] = null;
1595
1596                 delete __pAmPmEffectBitmap[i];
1597                 __pAmPmEffectBitmap[i] = null;
1598         }
1599
1600         return;
1601 }
1602
1603 void
1604 _DateTimePresenter::DrawColon(Canvas& canvas)
1605 {
1606         result r = E_SUCCESS;
1607         _ControlOrientation orientation = __pView->GetOrientation();
1608
1609         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1610         FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
1611
1612         float colonWidth = 0.0f;
1613         float colonMargin = 0.0f;
1614
1615         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_WIDTH, orientation, colonWidth);
1616         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_MARGIN, orientation, colonMargin);
1617
1618         for (int i = 0; i < __outputBoxMaxCount; i++)
1619         {
1620                 if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_HOUR)
1621                 {
1622                         hourBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
1623                 }
1624         }
1625
1626         colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
1627         colonBounds.y = hourBounds.y;
1628         colonBounds.width = colonWidth;
1629         colonBounds.height = hourBounds.height;
1630
1631         if (__pView->IsEnabled() && __pColonBitmap != null)
1632         {
1633                 r = canvas.DrawBitmap(colonBounds, *__pColonBitmap);
1634                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1635         }
1636         else if (!__pView->IsEnabled() && __pColonDisabledBitmap != null)
1637         {
1638                 r = canvas.DrawBitmap(colonBounds, *__pColonDisabledBitmap);
1639                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1640         }
1641 }
1642
1643 void
1644 _DateTimePresenter::DrawDateTimeDisplayBox(Canvas& canvas, int index)
1645 {
1646         result r = E_SUCCESS;
1647         String text;
1648         int fontSize = 0;
1649         int number = 0;
1650         int boxId = __pDisplayBox[index]->GetDisplayBoxId();
1651         number = GetNumberInBox(boxId);
1652         DateTimePickerStatus status = DATETIME_STATUS_NORMAL;
1653
1654         GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, __pView->GetOrientation(), fontSize);
1655
1656         r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
1657         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1658
1659         if (!__pView->IsEnabled())
1660         {
1661                 status = DATETIME_STATUS_DISABLED;
1662         }
1663         else
1664         {
1665                 if (__keypadEnabled)
1666                 {
1667                         if (index == __focusedBoxIndex)
1668                         {
1669                                 status = DATETIME_STATUS_HIGHLIGHTED;
1670                         }
1671                 }
1672                 else
1673                 {
1674                         if (index == __selectedBoxIndex)
1675                         {
1676                                 status = DATETIME_STATUS_SELECTED;
1677                         }
1678                 }
1679         }
1680
1681         if (boxId == DATETIME_ID_YEAR)
1682         {
1683                 if ((__inputComposing == DATETIME_INPUT_BEGIN) && ((__keypadEnabled && status == DATETIME_STATUS_HIGHLIGHTED)
1684                                 || (!__keypadEnabled && status == DATETIME_STATUS_SELECTED)))
1685                 {
1686                         String length = L"%0d";
1687
1688                         r = length.Insert(__changeFocusCounter,2);
1689                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1690
1691                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, length.GetPointer(), number);
1692                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1693                 }
1694                 else
1695                 {
1696                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%04d", number);
1697                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1698                 }
1699         }
1700         else if (boxId == DATETIME_ID_MONTH)
1701         {
1702                 if (__pInputPad != null)
1703                 {
1704                         text.Clear();
1705                         _DateTimeUtils dateTimeUtils;
1706                         text = dateTimeUtils.GetMonthString(number);
1707                 }
1708                 else
1709                 {
1710                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%02d", number);
1711                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1712                 }
1713         }
1714         else
1715         {
1716                 if ((__inputComposing == DATETIME_INPUT_BEGIN) && ((__keypadEnabled && status == DATETIME_STATUS_HIGHLIGHTED)
1717                                 || (!__keypadEnabled && status == DATETIME_STATUS_SELECTED)))
1718                 {
1719                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%d", number);
1720                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1721                 }
1722                 else
1723                 {
1724                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%02d", number);
1725                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1726                 }
1727         }
1728
1729         __pDisplayBox[index]->SetText(text);
1730         __pDisplayBox[index]->DrawDisplayBox(canvas, status);
1731
1732         return;
1733 }
1734
1735 void
1736 _DateTimePresenter::DrawPm(Canvas& canvas)
1737 {
1738         String text;
1739
1740         if ((__is24HourNotation) || (__pPmBox == null))
1741         {
1742                 return;
1743         }
1744
1745         _DateTimeUtils dateTimeUtils;
1746
1747         if (!__isPm)
1748         {
1749                 dateTimeUtils.GetAmPm(text, AM_TYPE);
1750         }
1751         else
1752         {
1753                 dateTimeUtils.GetAmPm(text, PM_TYPE);
1754         }
1755
1756         __pPmBox->SetText(text);
1757
1758         if (!__pView->IsEnabled())
1759         {
1760                 __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_DISABLED);
1761         }
1762         else if (__isPmButtonPressed)
1763         {
1764                 __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_SELECTED);
1765         }
1766         else
1767         {
1768                 if (__keypadEnabled && __focusedBoxIndex == __outputBoxMaxCount)
1769                 {
1770                         __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_HIGHLIGHTED);
1771                 }
1772                 else
1773                 {
1774                         __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_NORMAL);
1775                 }
1776         }
1777 }
1778
1779 void
1780 _DateTimePresenter::DrawBackground(Canvas& canvas)
1781 {
1782         result r = E_SUCCESS;
1783         FloatRectangle bounds = canvas.GetBoundsF();
1784         Color backgroundColor(0, 0, 0, 0);
1785
1786         GET_COLOR_CONFIG(DATETIMEPICKER::BG_NORMAL, backgroundColor);
1787         canvas.SetBackgroundColor(backgroundColor);
1788         canvas.Clear();
1789
1790         if (__pBgNormalBitmap != null)
1791         {
1792                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgNormalBitmap))
1793                 {
1794                         canvas.DrawNinePatchedBitmap(bounds, *__pBgNormalBitmap);
1795                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1796                 }
1797                 else
1798                 {
1799                         canvas.DrawBitmap(bounds, *__pBgNormalBitmap);
1800                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1801                 }
1802         }
1803
1804         if (__pBgEffectBitmap != null)
1805         {
1806                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgEffectBitmap))
1807                 {
1808                         canvas.DrawNinePatchedBitmap(bounds, *__pBgEffectBitmap);
1809                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1810                 }
1811                 else
1812                 {
1813                         canvas.DrawBitmap(bounds, *__pBgEffectBitmap);
1814                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1815                 }
1816         }
1817
1818         return;
1819 }
1820
1821 void
1822 _DateTimePresenter::DrawTitle(Canvas& canvas)
1823 {
1824         result r = E_SUCCESS;
1825         float marginX = 0.0f;
1826         float marginY = 0.0f;
1827         int fontSize = 0;
1828         Color color(0, 0, 0, 0);
1829         _ControlOrientation orientation = __pView->GetOrientation();
1830
1831         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_LEFT_MARGIN, orientation, marginX);
1832         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, marginY);
1833
1834         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_FONT_SIZE, orientation, fontSize);
1835
1836         r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
1837         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1838
1839         if (__pView->IsEnabled())
1840         {
1841                 GET_COLOR_CONFIG(DATETIMEPICKER::TITLE_NORMAL, color);
1842         }
1843         else
1844         {
1845                 GET_COLOR_CONFIG(DATETIMEPICKER::TITLE_DISABLED, color);
1846         }
1847
1848         canvas.SetForegroundColor(color);
1849         canvas.SetFont(*__pFont);
1850         canvas.DrawText(FloatPoint(marginX, marginY), __title);
1851
1852         return;
1853 }
1854
1855 void
1856 _DateTimePresenter::DrawDividers(Canvas& canvas)
1857 {
1858         result r = E_SUCCESS;
1859         float dividerWidth = 0.0f;
1860         float dividerHeight = 0.0f;
1861         float dividerMargin = 0.0f;
1862         float displayBoxheight = 0.0f;
1863         FloatPoint lineStart(0.0f,0.0f);
1864         FloatPoint lineEnd(0.0f,0.0f);
1865         Color colorHalfLeft;
1866         Color colorHalfRight;
1867
1868         _ControlOrientation orientation = __pView->GetOrientation();
1869
1870         GET_FIXED_VALUE_CONFIG(DATETIMEPICKER::DIVIDER_WIDTH, orientation, dividerWidth);
1871         GET_SHAPE_CONFIG(DATETIMEPICKER::DIVIDER_HEIGHT, orientation, dividerHeight);
1872         GET_SHAPE_CONFIG(DATETIMEPICKER::DIVIDER_MARGIN, orientation, dividerMargin);
1873         GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, orientation, displayBoxheight);
1874
1875         GET_COLOR_CONFIG(DATETIMEPICKER::DIVIDER_LEFT_HALF, colorHalfLeft);
1876         GET_COLOR_CONFIG(DATETIMEPICKER::DIVIDER_RIGHT_HALF, colorHalfRight);
1877
1878         if (__title.IsEmpty())
1879         {
1880                 lineStart.y = (GetOutputArea().height - dividerHeight) / 2.0f;
1881                 lineEnd.y = lineStart.y + dividerHeight;
1882         }
1883         else
1884         {
1885                 float topMargin = 0.0f;
1886                 float bottomMargin = 0.0f;
1887                 float titleHeight = 0.0f;
1888
1889                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
1890                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
1891                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
1892
1893                 lineStart.y = topMargin + titleHeight + bottomMargin + ((displayBoxheight - dividerHeight) / 2.0f);
1894                 lineEnd.y = lineStart.y + dividerHeight;
1895         }
1896
1897         canvas.SetLineWidth(dividerWidth/2.0f);
1898
1899         FloatRectangle lastDateDisplayBoxBounds(0.0f, 0.0f, 0.0f, 0.0f);
1900
1901         _DateTimeUtils dateTimeUtils;
1902         int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
1903
1904         for (int i = 0; i < __outputBoxMaxCount; i++)
1905         {
1906                 switch (localeDateFormat)
1907                 {
1908                         case DATE_FORMAT_DDMMYYYY:
1909                         case DATE_FORMAT_MMDDYYYY:
1910                         {
1911                                 if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_YEAR)
1912                                 {
1913                                         lastDateDisplayBoxBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
1914                                 }
1915                         }
1916                         break;
1917                         case DATE_FORMAT_YYYYMMDD:
1918                         {
1919                                 if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_DAY)
1920                                 {
1921                                         lastDateDisplayBoxBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
1922                                 }
1923                         }
1924                         break;
1925                         case DATE_FORMAT_YYYYDDMM:
1926                         {
1927                                 if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_MONTH)
1928                                 {
1929                                         lastDateDisplayBoxBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
1930                                 }
1931                         }
1932                         break;
1933                 }
1934         }
1935
1936         lineStart.x = lastDateDisplayBoxBounds.x + lastDateDisplayBoxBounds.width + dividerMargin;
1937         lineEnd.x = lineStart.x;
1938
1939         canvas.SetForegroundColor(colorHalfLeft);
1940         r = canvas.DrawLine(lineStart, lineEnd);
1941         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1942
1943         lineStart.x += dividerWidth/2;
1944         lineEnd.x = lineStart.x;
1945
1946         canvas.SetForegroundColor(colorHalfRight);
1947         r = canvas.DrawLine(lineStart, lineEnd);
1948         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1949
1950         return;
1951 }
1952
1953 FloatRectangle
1954 _DateTimePresenter::GetOutputArea(void)
1955 {
1956         _ControlOrientation orientation = __pView->GetOrientation();
1957
1958         FloatRectangle outputArea(0.0f, 0.0f, 0.0f, 0.0f);
1959
1960         GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, orientation, outputArea.x);
1961         GET_SHAPE_CONFIG(DATETIMEPICKER::TOP_MARGIN, orientation, outputArea.y);
1962
1963         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1964         {
1965                 float headerHeight = 0.0f;
1966
1967                 GET_SHAPE_CONFIG(HEADER::HEIGHT, orientation, headerHeight);
1968                 outputArea.y += headerHeight;
1969         }
1970
1971         outputArea.width = __pView->GetBounds().width - 2 * outputArea.x;
1972
1973         GET_SHAPE_CONFIG(DATETIMEPICKER::OUTPUT_AREA_HEIGHT, orientation, outputArea.height);
1974
1975         return outputArea;
1976 }
1977
1978 void
1979 _DateTimePresenter::ChangeInputPadStyle(int boxId)
1980 {
1981         if (!__inputPadEnabled)
1982         {
1983                 return;
1984         }
1985
1986         SysTryReturnVoidResult(NID_UI_CTRL, __pInputPad != null, E_SYSTEM,
1987                                                    "[E_SYSTEM] A system error has occurred. The instance of Inputpad is null.");
1988
1989         _InputPadStyle inputPadType = INPUTPAD_STYLE_NORMAL;
1990         switch (boxId)
1991         {
1992         case DATETIME_ID_MONTH:
1993                 inputPadType = INPUTPAD_STYLE_ALPHA;
1994                 break;
1995
1996         case DATETIME_ID_YEAR:
1997         // fall through intentional
1998         case DATETIME_ID_DAY:
1999         // fall through intentional
2000         case DATETIME_ID_HOUR:
2001         // fall through intentional
2002         case DATETIME_ID_MINUTE:
2003         // fall through intentional
2004         default:
2005                 inputPadType = INPUTPAD_STYLE_NORMAL;
2006                 break;
2007         }
2008
2009         if (__inputPadType == inputPadType)
2010         {
2011                 return;
2012         }
2013         __inputPadType = inputPadType;
2014
2015         __pInputPad->SetInputPadStyle(inputPadType);
2016         result r = GetLastResult();
2017         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
2018 }
2019
2020 int
2021 _DateTimePresenter::CalculateTouchArea(float posX, float posY)
2022 {
2023         _ControlOrientation orientation = __pView->GetOrientation();
2024         FloatRectangle outputArea = GetOutputArea();
2025
2026         float margin = 0.0f;
2027
2028         GET_SHAPE_CONFIG(DATETIMEPICKER::TOP_MARGIN, orientation, margin);
2029
2030         if ((posX < outputArea.x) || (posY < outputArea.y))
2031         {
2032                 return DATETIME_AREA_NONE;
2033         }
2034
2035         int touched = DATETIME_AREA_NONE;
2036
2037         if (posY < outputArea.y + outputArea.height)
2038         {
2039                 float displayBoxHeight = 0.0f;
2040                 float amPmBoxHeight = 0.0f;
2041
2042                 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, orientation, displayBoxHeight);
2043                 GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, orientation, amPmBoxHeight);
2044
2045                 float displayBoxPosY = outputArea.y + ((outputArea.height - displayBoxHeight) / 2.0f);
2046                 float amPmBoxPosY = outputArea.y + ((outputArea.height - amPmBoxHeight) / 2.0f);
2047
2048                 if (__title.IsEmpty())
2049                 {
2050                         displayBoxPosY = outputArea.y + ((outputArea.height - displayBoxHeight) / 2.0f);
2051                         amPmBoxPosY = outputArea.y + ((outputArea.height - amPmBoxHeight) / 2.0f);
2052                 }
2053                 else
2054                 {
2055                         float topMargin = 0.0f;
2056                         float bottomMargin = 0.0f;
2057                         float titleHeight = 0.0f;
2058
2059                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
2060                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
2061                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
2062
2063                         displayBoxPosY = outputArea.y + topMargin + bottomMargin + titleHeight;
2064                         amPmBoxPosY = outputArea.y + topMargin + titleHeight;
2065                 }
2066
2067                 if ((posY >= amPmBoxPosY) && (posY <= amPmBoxPosY + amPmBoxHeight))
2068                 {
2069                         if ((posY >= displayBoxPosY) && (posY <= displayBoxPosY + displayBoxHeight))
2070                         {
2071                                 // output area
2072                                 touched = DATETIME_AREA_OUTPUT;
2073                         }
2074
2075                         if (__pPmBox != null)
2076                         {
2077                                 //am pm area
2078                                 FloatRectangle boxBounds = __pPmBox->GetDisplayBoxBounds();
2079
2080                                 if ((posX >= boxBounds.x) && (posX < boxBounds.x + boxBounds.width))
2081                                 {
2082                                         touched = DATETIME_AREA_OUTPUT_AMPM;
2083                                 }
2084                         }
2085
2086                 }
2087         }
2088         else
2089         {
2090                 touched = DATETIME_AREA_INPUT;
2091         }
2092
2093         return touched;
2094 }
2095
2096 int
2097 _DateTimePresenter::CalculateTouchOutputArea(float posX, float posY)
2098 {
2099         FloatRectangle outputArea = GetOutputArea();
2100         _ControlOrientation orientation = __pView->GetOrientation();
2101
2102         for (int i = 0; i < __outputBoxMaxCount; i++)
2103         {
2104                 FloatRectangle boxBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
2105
2106                 if (__title.IsEmpty())
2107                 {
2108                         boxBounds.y = outputArea.y + ((outputArea.height - boxBounds.height) / 2.0f);
2109                 }
2110                 else
2111                 {
2112                         float topMargin = 0.0f;
2113                         float bottomMargin = 0.0f;
2114                         float titleHeight = 0.0f;
2115
2116                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
2117                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
2118                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
2119
2120                         boxBounds.y = outputArea.y + topMargin + titleHeight + bottomMargin;
2121                 }
2122
2123                 if ((posX >= boxBounds.x) && (posX < boxBounds.x + boxBounds.width)
2124                         && (posY >= boxBounds.y) && (posY < boxBounds.y + boxBounds.height))
2125                 {
2126                         return i;
2127                 }
2128         }
2129
2130         return -1;
2131 }
2132
2133 int
2134 _DateTimePresenter::CalculateTwoDigit(int originalNumber, int number)
2135 {
2136         int twoDigit = (originalNumber * 10) + number;
2137
2138         if (twoDigit == 0)
2139         {
2140                 return twoDigit;
2141         }
2142
2143         if ((twoDigit > 0) && (twoDigit > DATETIME_TWO_DIGIT_MAX))
2144         {
2145                 twoDigit = twoDigit % (DATETIME_TWO_DIGIT_MAX + 1);
2146         }
2147
2148         return twoDigit;
2149 }
2150
2151 int
2152 _DateTimePresenter::CalculateFourDigit(int originalNumber, int number)
2153 {
2154         int fourDigit = (originalNumber * 10) + number;
2155
2156         if (fourDigit == 0)
2157         {
2158                 return fourDigit;
2159         }
2160
2161         if ((fourDigit > 0) && (fourDigit > DATETIME_FOUR_DIGIT_MAX))
2162         {
2163                 fourDigit = fourDigit % (DATETIME_FOUR_DIGIT_MAX + 1);
2164         }
2165         return fourDigit;
2166 }
2167
2168 int
2169 _DateTimePresenter::SetTwoDigit(int originalNumber, int number)
2170 {
2171         int twoDigit = 0;
2172
2173         if ((originalNumber <= DATETIME_ONE_DIGIT_MAX) && (__inputComposing == DATETIME_INPUT_BEGIN))
2174         {
2175                 twoDigit = (originalNumber * 10) + number;
2176         }
2177         else
2178         {
2179                 twoDigit = number;
2180         }
2181         return twoDigit;
2182 }
2183
2184 int
2185 _DateTimePresenter::SetFourDigit(int originalNumber, int number)
2186 {
2187         int fourDigit = 0;
2188         int minYear = 0;
2189         int maxYear = 0;
2190
2191         GetYearRange(minYear, maxYear);
2192         if ((originalNumber <= DATETIME_THREE_DIGIT_MAX) && (__inputComposing == DATETIME_INPUT_BEGIN))
2193         {
2194                 fourDigit = (originalNumber * 10) + number;
2195                 if (fourDigit > maxYear)
2196                 {
2197                         fourDigit = maxYear;
2198                 }
2199         }
2200         else
2201         {
2202                 fourDigit = number;
2203         }
2204
2205         return fourDigit;
2206 }
2207
2208 void
2209 _DateTimePresenter::SetNumberInBox(int boxId, int number)
2210 {
2211         switch (boxId)
2212         {
2213         case DATETIME_ID_YEAR:
2214                 __year = number;
2215                 break;
2216
2217         case DATETIME_ID_MONTH:
2218                 __month = number;
2219                 break;
2220
2221         case DATETIME_ID_DAY:
2222                 __day = number;
2223                 break;
2224
2225         case DATETIME_ID_HOUR:
2226                 __hour = number;
2227                 break;
2228
2229         case DATETIME_ID_MINUTE:
2230                 __minute = number;
2231                 break;
2232
2233         default:
2234                 break;
2235         }
2236 }
2237
2238 int
2239 _DateTimePresenter::GetNumberInBox(int boxId) const
2240 {
2241         int number = 0;
2242
2243         switch (boxId)
2244         {
2245         case DATETIME_ID_YEAR:
2246                 number = __year;
2247                 break;
2248
2249         case DATETIME_ID_MONTH:
2250                 number = __month;
2251                 break;
2252
2253         case DATETIME_ID_DAY:
2254                 number = __day;
2255                 break;
2256
2257         case DATETIME_ID_HOUR:
2258                 number = __hour;
2259                 break;
2260
2261         case DATETIME_ID_MINUTE:
2262                 number = __minute;
2263                 break;
2264
2265         default:
2266                 break;
2267         }
2268
2269         return number;
2270 }
2271
2272 void
2273 _DateTimePresenter::SetFocusBox(int index)
2274 {
2275         if (__keypadEnabled)
2276         {
2277                 __focusedBoxIndex = index;
2278
2279                 if (__focusedBoxIndex < __outputBoxMaxCount)
2280                 {
2281                         __selectedBoxIndex = __focusedBoxIndex;
2282                 }
2283         }
2284
2285         __isFocusBoxChanged = true;
2286         __inputComposing = DATETIME_INPUT_END;
2287         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
2288
2289         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
2290
2291         ChangeInputPadStyle(boxId);
2292 }
2293
2294 void
2295 _DateTimePresenter::LoadPickerData(void)
2296 {
2297         _DateTimeUtils dateTimeUtils;
2298
2299         __year = GetYear();
2300         __month = GetMonth();
2301         __day = GetDay();
2302         __hour = GetHour();
2303
2304         if (!__is24HourNotation)
2305         {
2306                 int max = DATETIME_HOUR_MAX_FOR_24NOTATION;
2307
2308                 if (__hour == DATETIME_HOUR_MIN)
2309                 {
2310                         __hour = __hour + max;
2311                         __isPm = false;
2312                 }
2313                 else if (__hour < max && __hour != DATETIME_HOUR_MIN)
2314                 {
2315                         __isPm = false;
2316                 }
2317                 else if (__hour == max)
2318                 {
2319                         __isPm = true;
2320                 }
2321                 else if (__hour > max && __hour <= DATETIME_HOUR_MAX)
2322                 {
2323                         __hour = __hour - max;
2324                         __isPm = true;
2325                 }
2326                 else if (__hour == DATETIME_HOUR_MAX + 1)
2327                 {
2328                         __hour = max;
2329                         __isPm = false;
2330                 }
2331         }
2332
2333         __minute = GetMinute();
2334 }
2335
2336 void
2337 _DateTimePresenter::SavePickerData(void)
2338 {
2339         SetYear(__year);
2340         SetMonth(__month);
2341         SetDay(__day);
2342
2343         if (!__is24HourNotation)
2344         {
2345                 int maxHour = DATETIME_HOUR_MAX_FOR_24NOTATION;
2346
2347                 if (__isPm)
2348                 {
2349                         if (__hour < maxHour)
2350                         {
2351                                 SetHour(__hour + maxHour);
2352                         }
2353                         else
2354                         {
2355                                 SetHour(__hour);
2356                         }
2357                 }
2358                 else
2359                 {
2360                         if (__hour < maxHour)
2361                         {
2362                                 SetHour(__hour);
2363                         }
2364                         else
2365                         {
2366                                 SetHour(__hour - maxHour);
2367                         }
2368                 }
2369         }
2370         else
2371         {
2372                 SetHour(__hour);
2373         }
2374
2375         SetMinute(__minute);
2376 }
2377
2378 void
2379 _DateTimePresenter::UpdateDisplayData(int boxId)
2380 {
2381         switch (boxId)
2382         {
2383         case DATETIME_ID_YEAR:
2384                 __year = GetYear();
2385                 break;
2386
2387         case DATETIME_ID_MONTH:
2388                 __month = GetMonth();
2389                 break;
2390
2391         case DATETIME_ID_DAY:
2392                 __day = GetDay();
2393                 break;
2394
2395         case DATETIME_ID_HOUR:
2396                 __hour = GetHour();
2397
2398                 if (!__is24HourNotation)
2399                 {
2400                         int maxHour = DATETIME_HOUR_MAX_FOR_24NOTATION;
2401
2402                         if (__hour == DATETIME_HOUR_MIN)
2403                         {
2404                                 __hour = maxHour;
2405                                 __isPm = false;
2406                         }
2407                         else if (__hour < maxHour && __hour != DATETIME_HOUR_MIN)
2408                         {
2409                                 __isPm = false;
2410                         }
2411                         else if (__hour == maxHour)
2412                         {
2413                                 __isPm = true;
2414                         }
2415                         else if (__hour > maxHour && __hour <= DATETIME_HOUR_MAX)
2416                         {
2417                                 __hour = __hour - maxHour;
2418                                 __isPm = true;
2419                         }
2420                         else if (__hour == DATETIME_HOUR_MAX + 1)
2421                         {
2422                                 __hour = __hour - maxHour;
2423                                 __isPm = false;
2424                         }
2425                 }
2426                 break;
2427
2428         case DATETIME_ID_MINUTE:
2429                 __minute = GetMinute();
2430                 break;
2431
2432         default:
2433                 break;
2434         }
2435 }
2436
2437 void
2438 _DateTimePresenter::AdjustValue(int& value, int minValue, int maxValue)
2439 {
2440         if (value < minValue)
2441         {
2442                 value = minValue;
2443         }
2444         else if (maxValue < value)
2445         {
2446                 value = maxValue;
2447         }
2448 }
2449
2450 void
2451 _DateTimePresenter::AdjustDisplayValue(int index)
2452 {
2453         int boxId = __pDisplayBox[index]->GetDisplayBoxId();
2454         _DateTimeUtils dateTimeUtils;
2455         int minValue = 0;
2456         int maxValue = 0;
2457
2458         switch (boxId)
2459         {
2460         case DATETIME_ID_YEAR:
2461                 minValue = 0;
2462                 maxValue = 0;
2463                 GetYearRange(minValue, maxValue);
2464                 AdjustValue(__year, minValue, maxValue);
2465                 break;
2466
2467         case DATETIME_ID_MONTH:
2468                 minValue = DATETIME_MONTH_MIN;
2469                 maxValue = DATETIME_MONTH_MAX;
2470                 AdjustValue(__month, minValue, maxValue);
2471                 break;
2472
2473         case DATETIME_ID_DAY:
2474                 minValue = 1;
2475                 maxValue = dateTimeUtils.CalculateMaxDay(__year, __month);
2476                 AdjustValue(__day, minValue, maxValue);
2477                 break;
2478
2479         case DATETIME_ID_HOUR:
2480                 minValue = DATETIME_HOUR_MIN;
2481                 maxValue = DATETIME_HOUR_MAX;
2482                 if (!__is24HourNotation)
2483                 {
2484                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
2485
2486                         if (__hour == DATETIME_HOUR_MIN)
2487                         {
2488                                 minValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
2489                         }
2490                 }
2491                 AdjustValue(__hour, minValue, maxValue);
2492                 break;
2493
2494         case DATETIME_ID_MINUTE:
2495                 minValue = DATETIME_MINUTE_MIN;
2496                 maxValue = DATETIME_MINUTE_MAX;
2497                 AdjustValue(__minute, minValue, maxValue);
2498                 break;
2499
2500         default:
2501                 break;
2502         }
2503 }
2504
2505 void
2506 _DateTimePresenter::ChangeFocusBox(void)
2507 {
2508         if (__keypadEnabled)
2509         {
2510                 if (__focusedBoxIndex < __outputBoxMaxCount - 1)
2511                 {
2512                         __focusedBoxIndex++;
2513                         __selectedBoxIndex = __focusedBoxIndex;
2514                         int boxId = __pDisplayBox[__focusedBoxIndex]->GetDisplayBoxId();
2515                         ChangeInputPadStyle(boxId);
2516                         __isFocusBoxChanged = true;
2517                 }
2518         }
2519         else
2520         {
2521                 if (__selectedBoxIndex < (__outputBoxMaxCount - 1))
2522                 {
2523                         __selectedBoxIndex++;
2524                         __focusedBoxIndex = __selectedBoxIndex;
2525                         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
2526                         ChangeInputPadStyle(boxId);
2527                         __isFocusBoxChanged = true;
2528                 }
2529         }
2530
2531         for (int i = 0; i < __outputBoxMaxCount; i++)
2532         {
2533                 AdjustDisplayValue(i);
2534         }
2535
2536         __inputComposing = DATETIME_INPUT_END;
2537         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
2538 }
2539
2540 void
2541 _DateTimePresenter::SetAccessibilityElementText(void)
2542 {
2543         for (int index = 0; index < __outputBoxMaxCount; ++index)
2544         {
2545                 if (__pDisplayBox[index]->GetDisplayBoxId() == DATETIME_ID_MONTH)
2546                 {
2547                         int number = GetNumberInBox(__pDisplayBox[index]->GetDisplayBoxId());
2548                         __pView->SetAccessibilityElementText(index, __pInputPad->GetAccessibilityElementMonthName(number-1), false);
2549                 }
2550                 else
2551                 {
2552                         __pView->SetAccessibilityElementText(index, __pDisplayBox[index]->GetText(), false);
2553                 }
2554         }
2555
2556         if (__pPmBox)
2557         {
2558                 __pView->SetAccessibilityElementText(__outputBoxMaxCount, __pPmBox->GetText(), true);
2559         }
2560 }
2561
2562 }}} // Tizen::Ui::Controls