Merging EditDateTime & DateTimePicker Changes from RSA-master to RSA-tizen2.1
[platform/framework/native/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 == true) && (__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 == true)
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() == true)
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_INPUT)
592         {
593                 __keypadEnabled = false;
594         }
595
596         if (touchedAreaId == DATETIME_AREA_OUTPUT_AMPM)
597         {
598                 __isPmButtonPressed = true;
599                 __pView->Invalidate(true);
600                 return true;
601         }
602
603         return true;
604 }
605
606 bool
607 _DateTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
608 {
609         if (__pView != &source)
610         {
611                 return false;
612         }
613
614         return true;
615 }
616
617 bool
618 _DateTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
619 {
620         result r = E_SUCCESS;
621
622         if (__pView != &source)
623         {
624                 return false;
625         }
626
627         int touchedAreaId = CalculateTouchArea(touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
628
629         if (touchedAreaId != DATETIME_AREA_INPUT)
630         {
631                 __keypadEnabled = false;
632         }
633
634         if (__isPmButtonPressed == true)
635         {
636                 if (touchedAreaId == DATETIME_AREA_OUTPUT_AMPM)
637                 {
638                         __isPm = (!__isPm);
639                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
640                 }
641
642                 __inputComposing = DATETIME_INPUT_END;
643                 __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
644                 __isPmButtonPressed = false;
645                 __pView->Invalidate(true);
646
647                 return true;
648         }
649
650         if ((touchedAreaId == DATETIME_AREA_NONE) || (touchedAreaId == DATETIME_AREA_INPUT) ||
651                 (touchedAreaId == DATETIME_AREA_OUTPUT_AMPM))
652         {
653                 __isPmButtonPressed = false;
654                 __pView->Invalidate(true);
655
656                 return true;
657         }
658
659         int newOutputFocusedIndex = -1;
660
661         if (touchedAreaId == DATETIME_AREA_OUTPUT)
662         {
663                 newOutputFocusedIndex = CalculateTouchOutputArea(touchinfo.GetCurrentPosition().x, touchinfo.GetCurrentPosition().y);
664
665                 if (newOutputFocusedIndex == (-1))
666                 {
667                         return true;
668                 }
669
670                 if (newOutputFocusedIndex == __selectedBoxIndex)
671                 {
672                         for (int i = 0; i < __outputBoxMaxCount; i++)
673                         {
674                                 AdjustDisplayValue(i);
675                         }
676                 }
677                 else
678                 {
679                         __selectedBoxIndex = newOutputFocusedIndex;
680                 }
681
682                 _VisualElement* pVisualElement = null;
683                 Canvas* pCanvas = null;
684
685                 pVisualElement = __pView->GetDisplayVisualElement();
686                 r = GetLastResult();
687                 SysTryReturn(NID_UI_CTRL, (pVisualElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
688
689                 pCanvas = pVisualElement->GetCanvasN();
690                 r = GetLastResult();
691                 SysTryReturn(NID_UI_CTRL, (pCanvas != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
692
693                 DrawDateTimeDisplayBox(*pCanvas, __selectedBoxIndex);
694
695                 delete pCanvas;
696
697                 __inputComposing = DATETIME_INPUT_END;
698                 __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
699
700                 int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
701                 ChangeInputPadStyle(boxId);
702
703                 __pView->Invalidate(true);
704
705                 return true;
706         }
707
708         return true;
709 }
710
711 bool
712 _DateTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
713 {
714         if (__pView != &source)
715         {
716                 return false;
717         }
718
719         __isPmButtonPressed = false;
720         __inputComposing = DATETIME_INPUT_END;
721         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
722
723         __pView->Invalidate(true);
724
725         return true;
726 }
727
728 void
729 _DateTimePresenter::OnInputPadValueChanged(const _Control& source, int inputPadReturnValue)
730 {
731         HandleInputPadValueChange(inputPadReturnValue);
732 }
733
734 void
735 _DateTimePresenter::OnActionPerformed(const _Control& source, int actionId)
736 {
737         HandleSaveCancelAction(actionId);
738 }
739
740 bool
741 _DateTimePresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
742 {
743         int boxId = 0;
744         __keypadEnabled = true;
745
746         _KeyCode keyCode = keyInfo.GetKeyCode();
747
748         if (__focusedBoxIndex < __outputBoxMaxCount)
749         {
750                 boxId = __pDisplayBox[__focusedBoxIndex]->GetDisplayBoxId();
751
752                 if ((keyCode != _KEY_RIGHT) && (keyCode != _KEY_LEFT) && (boxId == DATETIME_ID_MONTH))
753                 {
754                         //month can be changed only with touch on input pad
755                         return true;
756                 }
757         }
758
759         switch (keyCode)
760         {
761                 case _KEY_RIGHT:
762                 {
763                         if (__pickerStyle != DATETIME_OUTPUT_STYLE_DATE && __focusedBoxIndex < __outputBoxMaxCount)
764                         {
765                                 __focusedBoxIndex++;
766                                 SetFocusBox(__focusedBoxIndex);
767                         }
768                         else if (__pickerStyle == DATETIME_OUTPUT_STYLE_DATE && __focusedBoxIndex < __outputBoxMaxCount-1)
769                         {
770                                 __focusedBoxIndex++;
771                                 SetFocusBox(__focusedBoxIndex);
772                         }
773                         else
774                         {
775                                 return false;
776                         }
777                 }
778                 break;
779                 case _KEY_LEFT:
780                 {
781                         if (__focusedBoxIndex  > 0)
782                         {
783                                 __focusedBoxIndex--;
784                                 SetFocusBox(__focusedBoxIndex);
785                         }
786                         else
787                         {
788                                 return false;
789                         }
790                 }
791                 break;
792                 case _KEY_ENTER:
793                 {
794                         if (__focusedBoxIndex == __outputBoxMaxCount)
795                         {
796                                 __isPmButtonPressed = true;
797                         }
798                 }
799                 break;
800                 case _KEY_0:
801                 case _KEY_NUMPAD_0:
802                         HandleInputPadValueChange(0);
803                         break;
804                 case _KEY_1:
805                 case _KEY_NUMPAD_1:
806                         HandleInputPadValueChange(1);
807                         break;
808                 case _KEY_2:
809                 case _KEY_NUMPAD_2:
810                         HandleInputPadValueChange(2);
811                         break;
812                 case _KEY_3:
813                 case _KEY_NUMPAD_3:
814                         HandleInputPadValueChange(3);
815                         break;
816                 case _KEY_4:
817                 case _KEY_NUMPAD_4:
818                         HandleInputPadValueChange(4);
819                         break;
820                 case _KEY_5:
821                 case _KEY_NUMPAD_5:
822                         HandleInputPadValueChange(5);
823                         break;
824                 case _KEY_6:
825                 case _KEY_NUMPAD_6:
826                         HandleInputPadValueChange(6);
827                         break;
828                 case _KEY_7:
829                 case _KEY_NUMPAD_7:
830                         HandleInputPadValueChange(7);
831                         break;
832                 case _KEY_8:
833                 case _KEY_NUMPAD_8:
834                         HandleInputPadValueChange(8);
835                         break;
836                 case _KEY_9:
837                 case _KEY_NUMPAD_9:
838                         HandleInputPadValueChange(9);
839                         break;
840                 default:
841                         return false;
842         }
843
844         __pView->Invalidate(true);
845         return true;
846 }
847
848 bool
849 _DateTimePresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
850 {
851         _KeyCode keyCode = keyInfo.GetKeyCode();
852         if (__isPmButtonPressed == true && keyCode == _KEY_ENTER)
853         {
854                 __isPm = (!__isPm);
855                 __isPmButtonPressed = false;
856                 __pView->Invalidate(true);
857         }
858
859         return true;
860 }
861
862 result
863 _DateTimePresenter::DrawFocus(void)
864 {
865         result r = E_SUCCESS;
866         __keypadEnabled = true;
867         __focusedBoxIndex = __selectedBoxIndex;
868
869         __pView->Invalidate(true);
870         return r;
871 }
872
873 result
874 _DateTimePresenter::ReleaseFocus(void)
875 {
876         result r = E_SUCCESS;
877         __keypadEnabled = false;
878         __focusedBoxIndex = 0;
879         __selectedBoxIndex = 0;
880
881         __pView->Invalidate(true);
882         return r;
883 }
884
885 void
886 _DateTimePresenter::HandleInputPadValueChange(int inputPadReturnValue)
887 {
888         if ((__inputPadEnabled == false) || (inputPadReturnValue == -1))
889         {
890                 return;
891         }
892
893         if ((__keypadEnabled == true) && (__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);
906                 __changeFocusCounter++;
907
908                 if (__isFocusBoxChanged == true)
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);
934                 newNumber = inputPadReturnValue;
935                 __inputComposing = DATETIME_INPUT_BEGIN;
936
937                 SetNumberInBox(boxId, newNumber);
938                 ChangeFocusBox();
939         }
940         else
941         {
942                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_SIP);
943                 __changeFocusCounter++;
944
945                 if (__isFocusBoxChanged == true)
946                 {
947                         newNumber = inputPadReturnValue;
948                         __isFocusBoxChanged = false;
949                 }
950                 else
951                 {
952                         newNumber = SetTwoDigit(currentNumber, inputPadReturnValue);
953                 }
954
955                 __inputComposing = DATETIME_INPUT_BEGIN;
956
957                 SetNumberInBox(boxId, newNumber);
958
959                 if (newNumber > DATETIME_ONE_DIGIT_MAX || __changeFocusCounter == DATE_TIME_CHANGE_FOCUS_COUNTER_MAX / 2)
960                 {
961                         ChangeFocusBox();
962                 }
963         }
964
965         __pView->Invalidate(true);
966 }
967
968 void
969 _DateTimePresenter::HandleSaveCancelAction(int actionId)
970 {
971         result r = E_SUCCESS;
972
973         if (__pView == null)
974         {
975                 return;
976         }
977
978         if (actionId != DATETIME_EVENT_ID_SAVE && actionId != DATETIME_EVENT_ID_CANCEL )
979         {
980                 return;
981         }
982
983         DateTime dateTime;
984
985         __inputComposing = DATETIME_INPUT_END;
986         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
987         __focusedBoxIndex = 0;
988         __selectedBoxIndex = 0;
989
990         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
991
992         SetFocusBoxId(boxId);
993         __pView->Close();
994
995         if (actionId == DATETIME_EVENT_ID_SAVE)
996         {
997                 for (int i = 0; i < __outputBoxMaxCount; i++)
998                 {
999                         AdjustDisplayValue(i);
1000                 }
1001
1002                 SavePickerData();
1003
1004                 switch (__pickerStyle)
1005                 {
1006                 case DATETIME_OUTPUT_STYLE_DATE:
1007                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
1008                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1009
1010                         r = __pView->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED, dateTime);
1011                         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.");
1012                         break;
1013
1014                 case DATETIME_OUTPUT_STYLE_TIME:
1015                         r = dateTime.SetValue(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1016                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1017
1018                         r = __pView->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED, dateTime);
1019                         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.");
1020                         break;
1021
1022                 case DATETIME_OUTPUT_STYLE_DATETIME:
1023                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1024                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1025
1026                         r = __pView->FireDateTimeChangeEvent(DATETIME_INTERNAL_CHANGE_SAVED, dateTime);
1027                         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.");
1028                         break;
1029
1030                 default:
1031                         break;
1032                 }
1033         }
1034         else if (actionId == DATETIME_EVENT_ID_CANCEL)
1035         {
1036                 LoadPickerData();
1037
1038                 switch (__pickerStyle)
1039                 {
1040                 case DATETIME_OUTPUT_STYLE_DATE:
1041                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
1042                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1043
1044                         r = __pView->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_CANCELED, dateTime);
1045                         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.");
1046                         break;
1047
1048                 case DATETIME_OUTPUT_STYLE_TIME:
1049                         r = dateTime.SetValue(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1050                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1051
1052                         r = __pView->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_CANCELED, dateTime);
1053                         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.");
1054                         break;
1055
1056                 case DATETIME_OUTPUT_STYLE_DATETIME:
1057                         r = dateTime.SetValue(GetYear(), GetMonth(), GetDay(), GetHour(), GetMinute(), dateTime.GetSecond());
1058                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1059
1060                         r = __pView->FireDateTimeChangeEvent(DATETIME_INTERNAL_CHANGE_CANCELED, dateTime);
1061                         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.");
1062                         break;
1063
1064                 default:
1065                         break;
1066                 }
1067         }
1068 }
1069
1070 void
1071 _DateTimePresenter::UpdateDateTimeOutputConfig(void)
1072 {
1073         _ControlOrientation orientation = __pView->GetOrientation();
1074         _DateTimeDisplayBox* pPmBox = null;
1075         _DateTimeDisplayBox* pDisplayBox[DATETIME_ID_MAX];
1076
1077         FloatRectangle outputAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
1078         FloatRectangle dateBounds(0.0f, 0.0f, 0.0f, 0.0f);
1079         FloatRectangle monthBounds(0.0f, 0.0f, 0.0f, 0.0f);
1080         FloatRectangle yearBounds(0.0f, 0.0f, 0.0f, 0.0f);
1081         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1082         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1083         FloatRectangle amPmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1084
1085         int indexBox = 0;
1086         int boxCount = 0;
1087
1088         float dateTimeDisplayBoxHeight = 0.0f;
1089         float amPmDisplayBoxHeight = 0.0f;
1090
1091         float dateTimeElementY = 0.0f;
1092         float amPmElementY = 0.0f;
1093         float dateElementGapWidth = 0.0f;
1094         float timeOutputMargin = 0.0f;
1095         float timeElementWidth = 0.0f;
1096         float colonWidth = 0.0f;
1097         float colonMargin = 0.0f;
1098         float amPmWidth = 0.0f;
1099         float amPmMargin = 0.0f;
1100
1101         float dividerWidth = 0.0f;
1102         float dividerMargin = 0.0f;
1103
1104         for (indexBox = 0; indexBox < DATETIME_ID_MAX; indexBox++)
1105         {
1106                 pDisplayBox[indexBox] = null;
1107         }
1108
1109         outputAreaBounds = GetOutputArea();
1110         __pView->SetDisplayVisualElementBounds(outputAreaBounds);
1111
1112         GET_SHAPE_CONFIG(DATETIMEPICKER::DATE_ELEMENT_GAP_WIDTH, orientation, dateElementGapWidth);
1113
1114         GET_SHAPE_CONFIG(DATETIMEPICKER::DATE_ELEMENT_WIDTH, orientation, dateBounds.width);
1115         GET_SHAPE_CONFIG(DATETIMEPICKER::MONTH_ELEMENT_WIDTH, orientation, monthBounds.width);
1116         GET_SHAPE_CONFIG(DATETIMEPICKER::YEAR_ELEMENT_WIDTH, orientation, yearBounds.width);
1117
1118         GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, orientation, dateTimeDisplayBoxHeight);
1119         GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, orientation, amPmDisplayBoxHeight);
1120
1121         GET_SHAPE_CONFIG(DATETIMEPICKER::TIME_OUTPUT_MARGIN, orientation, timeOutputMargin);
1122         GET_SHAPE_CONFIG(DATETIMEPICKER::TIME_ELEMENT_WIDTH, orientation, timeElementWidth);
1123
1124         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_WIDTH, orientation, colonWidth);
1125         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_MARGIN, orientation, colonMargin);
1126
1127         GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_WIDTH, orientation, amPmWidth);
1128         GET_SHAPE_CONFIG(DATETIMEPICKER::TIME_AMPM_MARGIN, orientation, amPmMargin);
1129
1130         GET_FIXED_VALUE_CONFIG(DATETIMEPICKER::DIVIDER_WIDTH, orientation, dividerWidth);
1131         GET_SHAPE_CONFIG(DATETIMEPICKER::DIVIDER_MARGIN, orientation, dividerMargin);
1132
1133         hourBounds.width = minuteBounds.width = timeElementWidth;
1134         amPmBounds.width = amPmWidth;
1135
1136         dateBounds.height = monthBounds.height = yearBounds.height = hourBounds.height = minuteBounds.height = dateTimeDisplayBoxHeight;
1137         amPmBounds.height = amPmDisplayBoxHeight;
1138
1139         if (__title.IsEmpty())
1140         {
1141                 dateTimeElementY = (outputAreaBounds.height - dateTimeDisplayBoxHeight) / 2.0f;
1142                 amPmElementY = (outputAreaBounds.height - amPmDisplayBoxHeight) / 2.0f;
1143         }
1144         else
1145         {
1146                 float topMargin = 0.0f;
1147                 float bottomMargin = 0.0f;
1148                 float titleHeight = 0.0f;
1149
1150                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
1151                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
1152                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
1153
1154                 dateTimeElementY = topMargin + titleHeight + bottomMargin;
1155                 amPmElementY = topMargin + titleHeight;
1156         }
1157
1158         dateBounds.y = monthBounds.y = yearBounds.y = hourBounds.y = minuteBounds.y = dateTimeElementY;
1159         amPmBounds.y = amPmElementY;
1160
1161         if (__pickerStyle == DATETIME_OUTPUT_STYLE_DATE || __pickerStyle == DATETIME_OUTPUT_STYLE_DATETIME)
1162         {
1163                 float leftMargin = 0.0f;
1164                 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_OUTPUT_LEFT_MARGIN, orientation, leftMargin);
1165
1166                 _DateTimeUtils dateTimeUtils;
1167                 int localeDateFormat = dateTimeUtils.GetLocaleDateFormat();
1168
1169                 switch (localeDateFormat)
1170                 {
1171                 case DATE_FORMAT_DDMMYYYY:
1172                         {
1173                                 dateBounds.x = leftMargin;
1174                                 monthBounds.x = dateBounds.x + dateBounds.width + dateElementGapWidth;
1175                                 yearBounds.x = monthBounds.x + monthBounds.width + dateElementGapWidth;
1176                                 hourBounds.x = yearBounds.x + yearBounds.width + (2 * dividerMargin + dividerWidth);
1177
1178                                 // Date
1179                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1180                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1181
1182                                 boxCount++;
1183
1184                                 // Month
1185                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1186                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1187
1188                                 boxCount++;
1189
1190                                 // Year
1191                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1192                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1193
1194                                 boxCount++;
1195                         }
1196                         break;
1197                 case DATE_FORMAT_MMDDYYYY:
1198                         {
1199                                 monthBounds.x = leftMargin;
1200                                 dateBounds.x = monthBounds.x + monthBounds.width + dateElementGapWidth;
1201                                 yearBounds.x = dateBounds.x + dateBounds.width + dateElementGapWidth;
1202                                 hourBounds.x = yearBounds.x + yearBounds.width + (2 * dividerMargin + dividerWidth);
1203
1204                                 // Month
1205                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1206                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1207
1208                                 boxCount++;
1209
1210                                 // Date
1211                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1212                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1213
1214                                 boxCount++;
1215
1216                                 // Year
1217                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1218                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1219
1220                                 boxCount++;
1221                         }
1222                         break;
1223                 case DATE_FORMAT_YYYYMMDD:
1224                         {
1225                                 yearBounds.x = leftMargin;
1226                                 monthBounds.x = yearBounds.x + yearBounds.width + dateElementGapWidth;
1227                                 dateBounds.x = monthBounds.x + monthBounds.width + dateElementGapWidth;
1228                                 hourBounds.x = dateBounds.x + dateBounds.width + (2 * dividerMargin + dividerWidth);
1229
1230                                 // Year
1231                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1232                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1233
1234                                 boxCount++;
1235
1236                                 // Month
1237                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1238                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1239
1240                                 boxCount++;
1241
1242                                 // Date
1243                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1244                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1245
1246                                 boxCount++;
1247                         }
1248                         break;
1249                 case DATE_FORMAT_YYYYDDMM:
1250                         {
1251                                 yearBounds.x = leftMargin;
1252                                 dateBounds.x = yearBounds.x + yearBounds.width + dateElementGapWidth;
1253                                 monthBounds.x = dateBounds.x + dateBounds.width + dateElementGapWidth;
1254                                 hourBounds.x = monthBounds.x + monthBounds.width + (2 * dividerMargin + dividerWidth);
1255
1256                                 // Year
1257                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(yearBounds, DATETIME_ID_YEAR);
1258                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1259
1260                                 boxCount++;
1261
1262                                 // Date
1263                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(dateBounds, DATETIME_ID_DAY);
1264                                 SysTryReturnVoidResult(NID_UI_CTRL, (pDisplayBox[boxCount] != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1265
1266                                 boxCount++;
1267
1268                                 // Month
1269                                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(monthBounds, DATETIME_ID_MONTH);
1270                                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1271
1272                                 boxCount++;
1273                         }
1274                         break;
1275                 }
1276         }
1277
1278         if (__pickerStyle == DATETIME_OUTPUT_STYLE_TIME || __pickerStyle == DATETIME_OUTPUT_STYLE_DATETIME)
1279         {
1280                 if (__pickerStyle == DATETIME_OUTPUT_STYLE_DATETIME)
1281                 {
1282                         minuteBounds.x = hourBounds.x + hourBounds.width + colonWidth + 2 * colonMargin;
1283                         amPmBounds.x = minuteBounds.x + minuteBounds.width + amPmMargin;
1284                 }
1285                 else
1286                 {
1287                         hourBounds.x = timeOutputMargin;
1288                         minuteBounds.x = hourBounds.x + hourBounds.width + colonWidth + 2 * colonMargin;
1289                         amPmBounds.x = minuteBounds.x + minuteBounds.width + amPmMargin;
1290                 }
1291
1292                 // Hour
1293                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(hourBounds, DATETIME_ID_HOUR);
1294                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1295
1296                 boxCount++;
1297
1298                 // Minute
1299                 pDisplayBox[boxCount] = new (std::nothrow) _DateTimeDisplayBox(minuteBounds, DATETIME_ID_MINUTE);
1300                 SysTryCatch(NID_UI_CTRL, (pDisplayBox[boxCount] != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1301
1302                 boxCount++;
1303
1304                 // AmPm Button
1305                 if (__is24HourNotation == false)
1306                 {
1307                         pPmBox = new (std::nothrow) _DateTimeDisplayBox(amPmBounds, DATETIME_ID_AMPM);
1308                         SysTryCatch(NID_UI_CTRL, (pPmBox != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1309
1310                         pPmBox->SetBackgroundBitmap(__pAmPmNormalBitmap, __pAmPmEffectBitmap);
1311
1312                         delete __pPmBox;
1313                         __pPmBox = pPmBox;
1314                 }
1315         }
1316
1317         __outputBoxMaxCount = boxCount;
1318
1319         for (indexBox = 0; indexBox < DATETIME_ID_MAX; indexBox++)
1320         {
1321                 delete __pDisplayBox[indexBox];
1322
1323                 if (pDisplayBox[indexBox] != null)
1324                 {
1325                         pDisplayBox[indexBox]->SetBackgroundBitmap(__pDisplayBoxNormalBitmap, __pDisplayBoxEffectBitmap);
1326                 }
1327
1328                 __pDisplayBox[indexBox] = pDisplayBox[indexBox];
1329         }
1330
1331         SetFont(__pFont);
1332
1333         return;
1334
1335 CATCH:
1336         for (int i = 0; i < DATETIME_ID_MAX; i++)
1337         {
1338                 delete pDisplayBox[i];
1339                 pDisplayBox[i] = null;
1340         }
1341
1342         return;
1343 }
1344
1345 void
1346 _DateTimePresenter::LoadResource(void)
1347 {
1348         result r = E_SUCCESS;
1349         Color color;
1350         Color replacementColor = Color::GetColor(COLOR_ID_MAGENTA);
1351         Color backgroundColor[DATETIME_STATUS_MAX];
1352         bool isDisplayBoxCustomBitmap[DATETIME_STATUS_MAX];
1353         bool isAmPmCustomBitmap[DATETIME_STATUS_MAX];
1354
1355         Bitmap* pDisplayBoxNormalBitmap[DATETIME_STATUS_MAX];
1356         Bitmap* pAmPmNormalBitmap[DATETIME_STATUS_MAX];
1357         Bitmap* pBgBitmap = null;
1358         Bitmap* pColonBitmap = null;
1359
1360         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1361         {
1362                 pDisplayBoxNormalBitmap[i] = null;
1363                 pAmPmNormalBitmap[i] = null;
1364                 backgroundColor[i] = Color();
1365                 isDisplayBoxCustomBitmap[i] = false;
1366                 isAmPmCustomBitmap[i] = false;
1367         }
1368
1369         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_NORMAL, backgroundColor[DATETIME_STATUS_NORMAL]);
1370         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_PRESSED, backgroundColor[DATETIME_STATUS_SELECTED]);
1371         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED, backgroundColor[DATETIME_STATUS_HIGHLIGHTED]);
1372         GET_COLOR_CONFIG(DATETIMEPICKER::AMPM_BG_DISABLED, backgroundColor[DATETIME_STATUS_DISABLED]);
1373
1374         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBgBitmap);
1375         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1376
1377         GET_COLOR_CONFIG(DATETIMEPICKER::DISPLAY_BG_NORMAL, color);
1378         __pBgNormalBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBgBitmap, replacementColor, color);
1379         r = GetLastResult();
1380         SysTryCatch(NID_UI_CTRL, (__pBgNormalBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1381
1382         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::COLON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pColonBitmap);
1383         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1384
1385         GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_NORMAL, color);
1386         __pColonBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pColonBitmap, replacementColor, color);
1387         r = GetLastResult();
1388         SysTryCatch(NID_UI_CTRL, (__pColonBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1389
1390         GET_COLOR_CONFIG(DATETIMEPICKER::TEXT_DISABLED, color);
1391         __pColonDisabledBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pColonBitmap, replacementColor, color);
1392         r = GetLastResult();
1393         SysTryCatch(NID_UI_CTRL, (__pColonDisabledBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1394
1395         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgEffectBitmap);
1396         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1397
1398         //display box
1399         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_NORMAL]);
1400         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1401
1402         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_SELECTED]);
1403         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1404
1405         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1406         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1407
1408         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisplayBoxNormalBitmap[DATETIME_STATUS_DISABLED]);
1409         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1410
1411         //ampm
1412         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_NORMAL]);
1413         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1414
1415         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_SELECTED]);
1416         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1417
1418         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1419         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1420
1421         r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pAmPmNormalBitmap[DATETIME_STATUS_DISABLED]);
1422         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1423
1424         isDisplayBoxCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_NORMAL);
1425         isDisplayBoxCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_PRESSED);
1426         isDisplayBoxCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_HIGHLIGHTED);
1427         isDisplayBoxCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::CONTENT_BG_DISABLED);
1428
1429         isAmPmCustomBitmap[DATETIME_STATUS_NORMAL] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_NORMAL);
1430         isAmPmCustomBitmap[DATETIME_STATUS_SELECTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_PRESSED);
1431         isAmPmCustomBitmap[DATETIME_STATUS_HIGHLIGHTED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_HIGHLIGHTED);
1432         isAmPmCustomBitmap[DATETIME_STATUS_DISABLED] = IS_CUSTOM_BITMAP(DATETIMEPICKER::AMPM_BG_DISABLED);
1433
1434         //displaybox
1435         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1436         {
1437                 if (isDisplayBoxCustomBitmap[i])
1438                 {
1439                         __pDisplayBoxNormalBitmap[i] = pDisplayBoxNormalBitmap[i];
1440                 }
1441                 else
1442                 {
1443                         __pDisplayBoxNormalBitmap[i] = _BitmapImpl::GetColorReplacedBitmapN(*pDisplayBoxNormalBitmap[i], replacementColor, backgroundColor[i]);
1444                         SysTryCatch(NID_UI_CTRL, (__pDisplayBoxNormalBitmap[i] != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1445                 }
1446         }
1447
1448         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_NORMAL])
1449         {
1450                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_NORMAL]);
1451                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1452         }
1453
1454         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_SELECTED])
1455         {
1456                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_SELECTED]);
1457                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1458         }
1459
1460         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_HIGHLIGHTED])
1461         {
1462                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1463                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1464         }
1465
1466         if (!isDisplayBoxCustomBitmap[DATETIME_STATUS_DISABLED])
1467         {
1468                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pDisplayBoxEffectBitmap[DATETIME_STATUS_DISABLED]);
1469                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1470         }
1471
1472
1473         //ampm
1474         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1475         {
1476                 if (isAmPmCustomBitmap[i])
1477                 {
1478                         __pAmPmNormalBitmap[i] = pAmPmNormalBitmap[i];
1479                 }
1480                 else
1481                 {
1482                         __pAmPmNormalBitmap[i] = _BitmapImpl::GetColorReplacedBitmapN(*pAmPmNormalBitmap[i], replacementColor, backgroundColor[i]);
1483                         SysTryCatch(NID_UI_CTRL, (__pAmPmNormalBitmap[i] != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1484                 }
1485         }
1486
1487         if (!isAmPmCustomBitmap[DATETIME_STATUS_NORMAL])
1488         {
1489                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_NORMAL]);
1490                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1491         }
1492
1493         if (!isAmPmCustomBitmap[DATETIME_STATUS_SELECTED])
1494         {
1495                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_SELECTED]);
1496                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1497         }
1498
1499         if (!isAmPmCustomBitmap[DATETIME_STATUS_HIGHLIGHTED])
1500         {
1501                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_HIGHLIGHTED]);
1502                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1503         }
1504
1505         if (!isAmPmCustomBitmap[DATETIME_STATUS_DISABLED])
1506         {
1507                 r = GET_BITMAP_CONFIG_N(DATETIMEPICKER::AMPM_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmEffectBitmap[DATETIME_STATUS_DISABLED]);
1508                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1509         }
1510
1511         delete pColonBitmap;
1512         delete pBgBitmap;
1513
1514         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1515         {
1516                 delete pDisplayBoxNormalBitmap[i];
1517                 delete pAmPmNormalBitmap[i];
1518         }
1519
1520         return;
1521
1522 CATCH:
1523         delete pColonBitmap;
1524
1525         delete __pColonBitmap;
1526         __pColonBitmap = null;
1527
1528         delete __pColonDisabledBitmap;
1529         __pColonDisabledBitmap = null;
1530
1531         delete pBgBitmap;
1532
1533         delete __pBgNormalBitmap;
1534         __pBgNormalBitmap = null;
1535
1536         delete __pBgEffectBitmap;
1537         __pBgEffectBitmap = null;
1538
1539         for (int i = 0; i < DATETIME_STATUS_MAX; i++)
1540         {
1541                 delete pDisplayBoxNormalBitmap[i];
1542
1543                 delete __pDisplayBoxNormalBitmap[i];
1544                 __pDisplayBoxNormalBitmap[i] = null;
1545
1546                 delete __pDisplayBoxEffectBitmap[i];
1547                 __pDisplayBoxEffectBitmap[i] = null;
1548
1549                 delete pAmPmNormalBitmap[i];
1550
1551                 delete __pAmPmNormalBitmap[i];
1552                 __pAmPmNormalBitmap[i] = null;
1553
1554                 delete __pAmPmEffectBitmap[i];
1555                 __pAmPmEffectBitmap[i] = null;
1556         }
1557
1558         return;
1559 }
1560
1561 void
1562 _DateTimePresenter::DrawColon(Canvas& canvas)
1563 {
1564         result r = E_SUCCESS;
1565         _ControlOrientation orientation = __pView->GetOrientation();
1566
1567         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1568         FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
1569
1570         float colonWidth = 0.0f;
1571         float colonMargin = 0.0f;
1572
1573         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_WIDTH, orientation, colonWidth);
1574         GET_SHAPE_CONFIG(DATETIMEPICKER::COLON_MARGIN, orientation, colonMargin);
1575
1576         for (int i = 0; i < __outputBoxMaxCount; i++)
1577         {
1578                 if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_HOUR)
1579                 {
1580                         hourBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
1581                 }
1582         }
1583
1584         colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
1585         colonBounds.y = hourBounds.y;
1586         colonBounds.width = colonWidth;
1587         colonBounds.height = hourBounds.height;
1588
1589         if (__pView->IsEnabled() && __pColonBitmap != null)
1590         {
1591                 r = canvas.DrawBitmap(colonBounds, *__pColonBitmap);
1592                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1593         }
1594         else if (!__pView->IsEnabled() && __pColonDisabledBitmap != null)
1595         {
1596                 r = canvas.DrawBitmap(colonBounds, *__pColonDisabledBitmap);
1597                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1598         }
1599 }
1600
1601 void
1602 _DateTimePresenter::DrawDateTimeDisplayBox(Canvas& canvas, int index)
1603 {
1604         result r = E_SUCCESS;
1605         String text;
1606         int fontSize = 0;
1607         int number = 0;
1608         int boxId = __pDisplayBox[index]->GetDisplayBoxId();
1609         number = GetNumberInBox(boxId);
1610         DateTimePickerStatus status = DATETIME_STATUS_NORMAL;
1611
1612         GET_SHAPE_CONFIG(DATETIMEPICKER::FONT_SIZE, __pView->GetOrientation(), fontSize);
1613
1614         r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
1615         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1616
1617         if (__pView->IsEnabled() == false)
1618         {
1619                 status = DATETIME_STATUS_DISABLED;
1620         }
1621         else
1622         {
1623                 if (__keypadEnabled)
1624                 {
1625                         if (index == __focusedBoxIndex)
1626                         {
1627                                 status = DATETIME_STATUS_HIGHLIGHTED;
1628                         }
1629                 }
1630                 else
1631                 {
1632                         if (index == __selectedBoxIndex)
1633                         {
1634                                 status = DATETIME_STATUS_SELECTED;
1635                         }
1636                 }
1637         }
1638
1639         if (boxId == DATETIME_ID_YEAR)
1640         {
1641                 if ((__inputComposing == DATETIME_INPUT_BEGIN) && ((__keypadEnabled && status == DATETIME_STATUS_HIGHLIGHTED)
1642                                 || (!__keypadEnabled && status == DATETIME_STATUS_SELECTED)))
1643                 {
1644                         String length = L"%0d";
1645
1646                         r = length.Insert(__changeFocusCounter,2);
1647                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1648
1649                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, length.GetPointer(), number);
1650                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1651                 }
1652                 else
1653                 {
1654                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%04d", number);
1655                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1656                 }
1657         }
1658         else if (boxId == DATETIME_ID_MONTH)
1659         {
1660                 if (__pInputPad != null)
1661                 {
1662                         text.Clear();
1663                         _DateTimeUtils dateTimeUtils;
1664                         text = dateTimeUtils.GetMonthString(number);
1665                 }
1666                 else
1667                 {
1668                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%02d", number);
1669                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1670                 }
1671         }
1672         else
1673         {
1674                 if ((__inputComposing == DATETIME_INPUT_BEGIN) && ((__keypadEnabled && status == DATETIME_STATUS_HIGHLIGHTED)
1675                                 || (!__keypadEnabled && status == DATETIME_STATUS_SELECTED)))
1676                 {
1677                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%d", number);
1678                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1679                 }
1680                 else
1681                 {
1682                         r = text.Format(DATETIME_DISPLAY_STRING_MAX_LENGTH, L"%02d", number);
1683                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1684                 }
1685         }
1686
1687         __pDisplayBox[index]->SetText(text);
1688         __pDisplayBox[index]->DrawDisplayBox(canvas, status);
1689
1690         return;
1691 }
1692
1693 void
1694 _DateTimePresenter::DrawPm(Canvas& canvas)
1695 {
1696         String text;
1697
1698         if ((__is24HourNotation == true) || (__pPmBox == null))
1699         {
1700                 return;
1701         }
1702
1703         _DateTimeUtils dateTimeUtils;
1704
1705         if (__isPm == false)
1706         {
1707                 dateTimeUtils.GetAmPm(text, AM_TYPE);
1708         }
1709         else
1710         {
1711                 dateTimeUtils.GetAmPm(text, PM_TYPE);
1712         }
1713
1714         __pPmBox->SetText(text);
1715
1716         if (__pView->IsEnabled() == false)
1717         {
1718                 __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_DISABLED);
1719         }
1720         else if (__isPmButtonPressed == true)
1721         {
1722                 __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_SELECTED);
1723         }
1724         else
1725         {
1726                 if (__keypadEnabled && __focusedBoxIndex == __outputBoxMaxCount)
1727                 {
1728                         __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_HIGHLIGHTED);
1729                 }
1730                 else
1731                 {
1732                         __pPmBox->DrawDisplayBox(canvas, DATETIME_STATUS_NORMAL);
1733                 }
1734         }
1735 }
1736
1737 void
1738 _DateTimePresenter::DrawBackground(Canvas& canvas)
1739 {
1740         result r = E_SUCCESS;
1741         FloatRectangle bounds = canvas.GetBoundsF();
1742         Color backgroundColor(0, 0, 0, 0);
1743
1744         GET_COLOR_CONFIG(DATETIMEPICKER::BG_NORMAL, backgroundColor);
1745         canvas.SetBackgroundColor(backgroundColor);
1746         canvas.Clear();
1747
1748         if (__pBgEffectBitmap)
1749         {
1750                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgEffectBitmap))
1751                 {
1752                         canvas.DrawNinePatchedBitmap(bounds, *__pBgEffectBitmap);
1753                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1754                 }
1755                 else
1756                 {
1757                         canvas.DrawBitmap(bounds, *__pBgEffectBitmap);
1758                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1759                 }
1760         }
1761
1762         if (__pBgNormalBitmap)
1763         {
1764                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgNormalBitmap))
1765                 {
1766                         canvas.DrawNinePatchedBitmap(bounds, *__pBgNormalBitmap);
1767                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1768                 }
1769                 else
1770                 {
1771                         canvas.DrawBitmap(bounds, *__pBgNormalBitmap);
1772                         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1773                 }
1774         }
1775
1776         return;
1777 }
1778
1779 void
1780 _DateTimePresenter::DrawTitle(Canvas& canvas)
1781 {
1782         result r = E_SUCCESS;
1783         float marginX = 0.0f;
1784         float marginY = 0.0f;
1785         int fontSize = 0;
1786         Color color(0, 0, 0, 0);
1787         _ControlOrientation orientation = __pView->GetOrientation();
1788
1789         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_LEFT_MARGIN, orientation, marginX);
1790         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, marginY);
1791
1792         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_FONT_SIZE, orientation, fontSize);
1793
1794         r = _FontImpl::GetInstance(*__pFont)->SetSize(fontSize);
1795         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1796
1797         if (__pView->IsEnabled())
1798         {
1799                 GET_COLOR_CONFIG(DATETIMEPICKER::TITLE_NORMAL, color);
1800         }
1801         else
1802         {
1803                 GET_COLOR_CONFIG(DATETIMEPICKER::TITLE_DISABLED, color);
1804         }
1805
1806         canvas.SetForegroundColor(color);
1807         canvas.SetFont(*__pFont);
1808         canvas.DrawText(FloatPoint(marginX, marginY), __title);
1809
1810         return;
1811 }
1812
1813 void
1814 _DateTimePresenter::DrawDividers(Canvas& canvas)
1815 {
1816         result r = E_SUCCESS;
1817         float dividerWidth = 0.0f;
1818         float dividerHeight = 0.0f;
1819         float dividerMargin = 0.0f;
1820         float displayBoxheight = 0.0f;
1821         FloatPoint lineStart(0.0f,0.0f);
1822         FloatPoint lineEnd(0.0f,0.0f);
1823         Color colorHalfLeft;
1824         Color colorHalfRight;
1825
1826         _ControlOrientation orientation = __pView->GetOrientation();
1827
1828         GET_FIXED_VALUE_CONFIG(DATETIMEPICKER::DIVIDER_WIDTH, orientation, dividerWidth);
1829         GET_SHAPE_CONFIG(DATETIMEPICKER::DIVIDER_HEIGHT, orientation, dividerHeight);
1830         GET_SHAPE_CONFIG(DATETIMEPICKER::DIVIDER_MARGIN, orientation, dividerMargin);
1831         GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, orientation, displayBoxheight);
1832
1833         GET_COLOR_CONFIG(DATETIMEPICKER::DIVIDER_LEFT_HALF, colorHalfLeft);
1834         GET_COLOR_CONFIG(DATETIMEPICKER::DIVIDER_RIGHT_HALF, colorHalfRight);
1835
1836         if (__title.IsEmpty())
1837         {
1838                 lineStart.y = (GetOutputArea().height - dividerHeight) / 2.0f;
1839                 lineEnd.y = lineStart.y + dividerHeight;
1840         }
1841         else
1842         {
1843                 float topMargin = 0.0f;
1844                 float bottomMargin = 0.0f;
1845                 float titleHeight = 0.0f;
1846
1847                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
1848                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
1849                 GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
1850
1851                 lineStart.y = topMargin + titleHeight + bottomMargin + ((displayBoxheight - dividerHeight) / 2.0f);
1852                 lineEnd.y = lineStart.y + dividerHeight;
1853         }
1854
1855         canvas.SetLineWidth(dividerWidth/2.0f);
1856
1857         FloatRectangle yearBounds(0.0f, 0.0f, 0.0f, 0.0f);
1858
1859         for (int i = 0; i < __outputBoxMaxCount; i++)
1860         {
1861                 if (__pDisplayBox[i]->GetDisplayBoxId() == DATETIME_ID_YEAR)
1862                 {
1863                         yearBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
1864                 }
1865         }
1866
1867         lineStart.x = yearBounds.x + yearBounds.width + dividerMargin;
1868         lineEnd.x = lineStart.x;
1869
1870         canvas.SetForegroundColor(colorHalfLeft);
1871         r = canvas.DrawLine(lineStart, lineEnd);
1872         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1873
1874         lineStart.x += dividerWidth/2;
1875         lineEnd.x = lineStart.x;
1876
1877         canvas.SetForegroundColor(colorHalfRight);
1878         r = canvas.DrawLine(lineStart, lineEnd);
1879         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1880
1881         return;
1882 }
1883
1884 FloatRectangle
1885 _DateTimePresenter::GetOutputArea(void)
1886 {
1887         _ControlOrientation orientation = __pView->GetOrientation();
1888
1889         FloatRectangle outputArea(0.0f, 0.0f, 0.0f, 0.0f);
1890
1891         GET_SHAPE_CONFIG(DATETIMEPICKER::LEFT_MARGIN, orientation, outputArea.x);
1892         GET_SHAPE_CONFIG(DATETIMEPICKER::TOP_MARGIN, orientation, outputArea.y);
1893
1894         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
1895         {
1896                 float headerHeight = 0.0f;
1897
1898                 GET_SHAPE_CONFIG(HEADER::HEIGHT, orientation, headerHeight);
1899                 outputArea.y += headerHeight;
1900         }
1901
1902         outputArea.width = __pView->GetBounds().width - 2 * outputArea.x;
1903
1904         GET_SHAPE_CONFIG(DATETIMEPICKER::OUTPUT_AREA_HEIGHT, orientation, outputArea.height);
1905
1906         return outputArea;
1907 }
1908
1909 void
1910 _DateTimePresenter::ChangeInputPadStyle(int boxId)
1911 {
1912         if (__inputPadEnabled == false)
1913         {
1914                 return;
1915         }
1916
1917         SysTryReturnVoidResult(NID_UI_CTRL, __pInputPad != null, E_SYSTEM,
1918                                                    "[E_SYSTEM] A system error has occurred. The instance of Inputpad is null.");
1919
1920         _InputPadStyle inputPadType = INPUTPAD_STYLE_NORMAL;
1921         switch (boxId)
1922         {
1923         case DATETIME_ID_MONTH:
1924                 inputPadType = INPUTPAD_STYLE_ALPHA;
1925                 break;
1926
1927         case DATETIME_ID_YEAR:
1928         // fall through intentional
1929         case DATETIME_ID_DAY:
1930         // fall through intentional
1931         case DATETIME_ID_HOUR:
1932         // fall through intentional
1933         case DATETIME_ID_MINUTE:
1934         // fall through intentional
1935         default:
1936                 inputPadType = INPUTPAD_STYLE_NORMAL;
1937                 break;
1938         }
1939
1940         if (__inputPadType == inputPadType)
1941         {
1942                 return;
1943         }
1944         __inputPadType = inputPadType;
1945
1946         __pInputPad->SetInputPadStyle(inputPadType);
1947         result r = GetLastResult();
1948         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1949 }
1950
1951 int
1952 _DateTimePresenter::CalculateTouchArea(float posX, float posY)
1953 {
1954         _ControlOrientation orientation = __pView->GetOrientation();
1955         FloatRectangle outputArea = GetOutputArea();
1956
1957         float margin = 0.0f;
1958
1959         GET_SHAPE_CONFIG(DATETIMEPICKER::TOP_MARGIN, orientation, margin);
1960
1961         if ((posX < outputArea.x) || (posY < outputArea.y))
1962         {
1963                 return DATETIME_AREA_NONE;
1964         }
1965
1966         int touched = DATETIME_AREA_NONE;
1967
1968         if (posY < outputArea.y + outputArea.height)
1969         {
1970                 float displayBoxHeight = 0.0f;
1971                 float amPmBoxHeight = 0.0f;
1972
1973                 GET_SHAPE_CONFIG(DATETIMEPICKER::DATETIME_DISPLAY_BOX_HEIGHT, orientation, displayBoxHeight);
1974                 GET_SHAPE_CONFIG(DATETIMEPICKER::AMPM_DISPLAY_BOX_HEIGHT, orientation, amPmBoxHeight);
1975
1976                 float displayBoxPosY = outputArea.y + ((outputArea.height - displayBoxHeight) / 2.0f);
1977                 float amPmBoxPosY = outputArea.y + ((outputArea.height - amPmBoxHeight) / 2.0f);
1978
1979                 if (__title.IsEmpty())
1980                 {
1981                         displayBoxPosY = outputArea.y + ((outputArea.height - displayBoxHeight) / 2.0f);
1982                         amPmBoxPosY = outputArea.y + ((outputArea.height - amPmBoxHeight) / 2.0f);
1983                 }
1984                 else
1985                 {
1986                         float topMargin = 0.0f;
1987                         float bottomMargin = 0.0f;
1988                         float titleHeight = 0.0f;
1989
1990                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
1991                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
1992                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
1993
1994                         displayBoxPosY = outputArea.y + topMargin + bottomMargin + titleHeight;
1995                         amPmBoxPosY = outputArea.y + topMargin + titleHeight;
1996                 }
1997
1998                 if ((posY >= amPmBoxPosY) && (posY <= amPmBoxPosY + amPmBoxHeight))
1999                 {
2000                         if ((posY >= displayBoxPosY) && (posY <= displayBoxPosY + displayBoxHeight))
2001                         {
2002                                 // output area
2003                                 touched = DATETIME_AREA_OUTPUT;
2004                         }
2005
2006                         if (__pPmBox != null)
2007                         {
2008                                 //am pm area
2009                                 FloatRectangle boxBounds = __pPmBox->GetDisplayBoxBounds();
2010
2011                                 if ((posX >= boxBounds.x) && (posX < boxBounds.x + boxBounds.width))
2012                                 {
2013                                         touched = DATETIME_AREA_OUTPUT_AMPM;
2014                                 }
2015                         }
2016
2017                 }
2018         }
2019         else
2020         {
2021                 touched = DATETIME_AREA_INPUT;
2022         }
2023
2024         return touched;
2025 }
2026
2027 int
2028 _DateTimePresenter::CalculateTouchOutputArea(float posX, float posY)
2029 {
2030         FloatRectangle outputArea = GetOutputArea();
2031         _ControlOrientation orientation = __pView->GetOrientation();
2032
2033         for (int i = 0; i < __outputBoxMaxCount; i++)
2034         {
2035                 FloatRectangle boxBounds = __pDisplayBox[i]->GetDisplayBoxBounds();
2036
2037                 if (__title.IsEmpty())
2038                 {
2039                         boxBounds.y = outputArea.y + ((outputArea.height - boxBounds.height) / 2.0f);
2040                 }
2041                 else
2042                 {
2043                         float topMargin = 0.0f;
2044                         float bottomMargin = 0.0f;
2045                         float titleHeight = 0.0f;
2046
2047                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_TOP_MARGIN, orientation, topMargin);
2048                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_BOTTOM_MARGIN, orientation, bottomMargin);
2049                         GET_SHAPE_CONFIG(DATETIMEPICKER::TITLE_HEIGHT, orientation, titleHeight);
2050
2051                         boxBounds.y = outputArea.y + topMargin + titleHeight + bottomMargin;
2052                 }
2053
2054                 if ((posX >= boxBounds.x) && (posX < boxBounds.x + boxBounds.width)
2055                         && (posY >= boxBounds.y) && (posY < boxBounds.y + boxBounds.height))
2056                 {
2057                         return i;
2058                 }
2059         }
2060
2061         return -1;
2062 }
2063
2064 int
2065 _DateTimePresenter::CalculateTwoDigit(int originalNumber, int number)
2066 {
2067         int twoDigit = (originalNumber * 10) + number;
2068
2069         if (twoDigit == 0)
2070         {
2071                 return twoDigit;
2072         }
2073
2074         if ((twoDigit > 0) && (twoDigit > DATETIME_TWO_DIGIT_MAX))
2075         {
2076                 twoDigit = twoDigit % (DATETIME_TWO_DIGIT_MAX + 1);
2077         }
2078
2079         return twoDigit;
2080 }
2081
2082 int
2083 _DateTimePresenter::CalculateFourDigit(int originalNumber, int number)
2084 {
2085         int fourDigit = (originalNumber * 10) + number;
2086
2087         if (fourDigit == 0)
2088         {
2089                 return fourDigit;
2090         }
2091
2092         if ((fourDigit > 0) && (fourDigit > DATETIME_FOUR_DIGIT_MAX))
2093         {
2094                 fourDigit = fourDigit % (DATETIME_FOUR_DIGIT_MAX + 1);
2095         }
2096         return fourDigit;
2097 }
2098
2099 int
2100 _DateTimePresenter::SetTwoDigit(int originalNumber, int number)
2101 {
2102         int twoDigit = 0;
2103
2104         if ((originalNumber <= DATETIME_ONE_DIGIT_MAX) && (__inputComposing == DATETIME_INPUT_BEGIN))
2105         {
2106                 twoDigit = (originalNumber * 10) + number;
2107         }
2108         else
2109         {
2110                 twoDigit = number;
2111         }
2112         return twoDigit;
2113 }
2114
2115 int
2116 _DateTimePresenter::SetFourDigit(int originalNumber, int number)
2117 {
2118         int fourDigit = 0;
2119         int minYear = 0;
2120         int maxYear = 0;
2121
2122         GetYearRange(minYear, maxYear);
2123         if ((originalNumber <= DATETIME_THREE_DIGIT_MAX) && (__inputComposing == DATETIME_INPUT_BEGIN))
2124         {
2125                 fourDigit = (originalNumber * 10) + number;
2126                 if (fourDigit > maxYear)
2127                 {
2128                         fourDigit = maxYear;
2129                 }
2130         }
2131         else
2132         {
2133                 fourDigit = number;
2134         }
2135
2136         return fourDigit;
2137 }
2138
2139 void
2140 _DateTimePresenter::SetNumberInBox(int boxId, int number)
2141 {
2142         switch (boxId)
2143         {
2144         case DATETIME_ID_YEAR:
2145                 __year = number;
2146                 break;
2147
2148         case DATETIME_ID_MONTH:
2149                 __month = number;
2150                 break;
2151
2152         case DATETIME_ID_DAY:
2153                 __day = number;
2154                 break;
2155
2156         case DATETIME_ID_HOUR:
2157                 __hour = number;
2158                 break;
2159
2160         case DATETIME_ID_MINUTE:
2161                 __minute = number;
2162                 break;
2163
2164         default:
2165                 break;
2166         }
2167 }
2168
2169 int
2170 _DateTimePresenter::GetNumberInBox(int boxId) const
2171 {
2172         int number = 0;
2173
2174         switch (boxId)
2175         {
2176         case DATETIME_ID_YEAR:
2177                 number = __year;
2178                 break;
2179
2180         case DATETIME_ID_MONTH:
2181                 number = __month;
2182                 break;
2183
2184         case DATETIME_ID_DAY:
2185                 number = __day;
2186                 break;
2187
2188         case DATETIME_ID_HOUR:
2189                 number = __hour;
2190                 break;
2191
2192         case DATETIME_ID_MINUTE:
2193                 number = __minute;
2194                 break;
2195
2196         default:
2197                 break;
2198         }
2199
2200         return number;
2201 }
2202
2203 void
2204 _DateTimePresenter::SetFocusBox(int index)
2205 {
2206         if (__keypadEnabled)
2207         {
2208                 __focusedBoxIndex = index;
2209
2210                 if (__focusedBoxIndex < __outputBoxMaxCount)
2211                 {
2212                         __selectedBoxIndex = __focusedBoxIndex;
2213                 }
2214         }
2215
2216         __isFocusBoxChanged = true;
2217         __inputComposing = DATETIME_INPUT_END;
2218         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
2219
2220         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
2221
2222         ChangeInputPadStyle(boxId);
2223 }
2224
2225 void
2226 _DateTimePresenter::LoadPickerData(void)
2227 {
2228         _DateTimeUtils dateTimeUtils;
2229
2230         __year = GetYear();
2231         __month = GetMonth();
2232         __day = GetDay();
2233         __hour = GetHour();
2234
2235         if (__is24HourNotation == false)
2236         {
2237                 int max = DATETIME_HOUR_MAX_FOR_24NOTATION;
2238
2239                 if (__hour == DATETIME_HOUR_MIN)
2240                 {
2241                         __hour = __hour + max;
2242                         __isPm = false;
2243                 }
2244                 else if (__hour < max && __hour != DATETIME_HOUR_MIN)
2245                 {
2246                         __isPm = false;
2247                 }
2248                 else if (__hour == max)
2249                 {
2250                         __isPm = true;
2251                 }
2252                 else if (__hour > max && __hour <= DATETIME_HOUR_MAX)
2253                 {
2254                         __hour = __hour - max;
2255                         __isPm = true;
2256                 }
2257                 else if (__hour == DATETIME_HOUR_MAX + 1)
2258                 {
2259                         __hour = max;
2260                         __isPm = false;
2261                 }
2262         }
2263
2264         __minute = GetMinute();
2265 }
2266
2267 void
2268 _DateTimePresenter::SavePickerData(void)
2269 {
2270         SetYear(__year);
2271         SetMonth(__month);
2272         SetDay(__day);
2273
2274         if (__is24HourNotation == false)
2275         {
2276                 int maxHour = DATETIME_HOUR_MAX_FOR_24NOTATION;
2277
2278                 if (__isPm == true)
2279                 {
2280                         if (__hour < maxHour)
2281                         {
2282                                 SetHour(__hour + maxHour);
2283                         }
2284                         else
2285                         {
2286                                 SetHour(__hour);
2287                         }
2288                 }
2289                 else
2290                 {
2291                         if (__hour < maxHour)
2292                         {
2293                                 SetHour(__hour);
2294                         }
2295                         else
2296                         {
2297                                 SetHour(__hour - maxHour);
2298                         }
2299                 }
2300         }
2301         else
2302         {
2303                 SetHour(__hour);
2304         }
2305
2306         SetMinute(__minute);
2307 }
2308
2309 void
2310 _DateTimePresenter::UpdateDisplayData(int boxId)
2311 {
2312         switch (boxId)
2313         {
2314         case DATETIME_ID_YEAR:
2315                 __year = GetYear();
2316                 break;
2317
2318         case DATETIME_ID_MONTH:
2319                 __month = GetMonth();
2320                 break;
2321
2322         case DATETIME_ID_DAY:
2323                 __day = GetDay();
2324                 break;
2325
2326         case DATETIME_ID_HOUR:
2327                 __hour = GetHour();
2328
2329                 if (__is24HourNotation == false)
2330                 {
2331                         int maxHour = DATETIME_HOUR_MAX_FOR_24NOTATION;
2332
2333                         if (__hour == DATETIME_HOUR_MIN)
2334                         {
2335                                 __hour = maxHour;
2336                                 __isPm = false;
2337                         }
2338                         else if (__hour < maxHour && __hour != DATETIME_HOUR_MIN)
2339                         {
2340                                 __isPm = false;
2341                         }
2342                         else if (__hour == maxHour)
2343                         {
2344                                 __isPm = true;
2345                         }
2346                         else if (__hour > maxHour && __hour <= DATETIME_HOUR_MAX)
2347                         {
2348                                 __hour = __hour - maxHour;
2349                                 __isPm = true;
2350                         }
2351                         else if (__hour == DATETIME_HOUR_MAX + 1)
2352                         {
2353                                 __hour = __hour - maxHour;
2354                                 __isPm = false;
2355                         }
2356                 }
2357                 break;
2358
2359         case DATETIME_ID_MINUTE:
2360                 __minute = GetMinute();
2361                 break;
2362
2363         default:
2364                 break;
2365         }
2366 }
2367
2368 void
2369 _DateTimePresenter::AdjustValue(int& value, int minValue, int maxValue)
2370 {
2371         if (value < minValue)
2372         {
2373                 value = minValue;
2374         }
2375         else if (maxValue < value)
2376         {
2377                 value = maxValue;
2378         }
2379 }
2380
2381 void
2382 _DateTimePresenter::AdjustDisplayValue(int index)
2383 {
2384         int boxId = __pDisplayBox[index]->GetDisplayBoxId();
2385         _DateTimeUtils dateTimeUtils;
2386         int minValue = 0;
2387         int maxValue = 0;
2388
2389         switch (boxId)
2390         {
2391         case DATETIME_ID_YEAR:
2392                 minValue = 0;
2393                 maxValue = 0;
2394                 GetYearRange(minValue, maxValue);
2395                 AdjustValue(__year, minValue, maxValue);
2396                 break;
2397
2398         case DATETIME_ID_MONTH:
2399                 minValue = DATETIME_MONTH_MIN;
2400                 maxValue = DATETIME_MONTH_MAX;
2401                 AdjustValue(__month, minValue, maxValue);
2402                 break;
2403
2404         case DATETIME_ID_DAY:
2405                 minValue = 1;
2406                 maxValue = dateTimeUtils.CalculateMaxDay(__year, __month);
2407                 AdjustValue(__day, minValue, maxValue);
2408                 break;
2409
2410         case DATETIME_ID_HOUR:
2411                 minValue = DATETIME_HOUR_MIN;
2412                 maxValue = DATETIME_HOUR_MAX;
2413                 if (__is24HourNotation == false)
2414                 {
2415                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
2416
2417                         if (__hour == DATETIME_HOUR_MIN)
2418                         {
2419                                 minValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
2420                         }
2421                 }
2422                 AdjustValue(__hour, minValue, maxValue);
2423                 break;
2424
2425         case DATETIME_ID_MINUTE:
2426                 minValue = DATETIME_MINUTE_MIN;
2427                 maxValue = DATETIME_MINUTE_MAX;
2428                 AdjustValue(__minute, minValue, maxValue);
2429                 break;
2430
2431         default:
2432                 break;
2433         }
2434 }
2435
2436 void
2437 _DateTimePresenter::ChangeFocusBox(void)
2438 {
2439         if (__keypadEnabled)
2440         {
2441                 if (__focusedBoxIndex < __outputBoxMaxCount - 1)
2442                 {
2443                         __focusedBoxIndex++;
2444                         __selectedBoxIndex = __focusedBoxIndex;
2445                         int boxId = __pDisplayBox[__focusedBoxIndex]->GetDisplayBoxId();
2446                         ChangeInputPadStyle(boxId);
2447                         __isFocusBoxChanged = true;
2448                 }
2449         }
2450         else
2451         {
2452                 if (__selectedBoxIndex < (__outputBoxMaxCount - 1))
2453                 {
2454                         __selectedBoxIndex++;
2455                         __focusedBoxIndex = __selectedBoxIndex;
2456                         int boxId = __pDisplayBox[__selectedBoxIndex]->GetDisplayBoxId();
2457                         ChangeInputPadStyle(boxId);
2458                         __isFocusBoxChanged = true;
2459                 }
2460         }
2461
2462         for (int i = 0; i < __outputBoxMaxCount; i++)
2463         {
2464                 AdjustDisplayValue(i);
2465         }
2466
2467         __inputComposing = DATETIME_INPUT_END;
2468         __changeFocusCounter = DATE_TIME_CHANGE_FOCUS_COUNTER_MIN;
2469 }
2470
2471 void
2472 _DateTimePresenter::SetAccessibilityElementText(void)
2473 {
2474         for (int index = 0; index < __outputBoxMaxCount; ++index)
2475         {
2476                 if (__pDisplayBox[index]->GetDisplayBoxId() == DATETIME_ID_MONTH)
2477                 {
2478                         int number = GetNumberInBox(__pDisplayBox[index]->GetDisplayBoxId());
2479                         __pView->SetAccessibilityElementText(index, __pInputPad->GetAccessibilityElementMonthName(number-1), false);
2480                 }
2481                 else
2482                 {
2483                         __pView->SetAccessibilityElementText(index, __pDisplayBox[index]->GetText(), false);
2484                 }
2485         }
2486
2487         if (__pPmBox)
2488         {
2489                 __pView->SetAccessibilityElementText(__outputBoxMaxCount, __pPmBox->GetText(), true);
2490         }
2491 }
2492
2493 }}} // Tizen::Ui::Controls