Merge "Clean log messages in TableView code" into tizen_2.2
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_EditTimePresenter.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_EditTimePresenter.cpp
20  * @brief               This is the implementation file for the _EditTimePresenter class.
21  */
22
23 #include <FSysSettingInfo.h>
24 #include <FGrpColor.h>
25 #include <FUiAnimAnimationTransaction.h>
26 #include <FUiAnimVisualElementPropertyAnimation.h>
27 #include <FGrp_BitmapImpl.h>
28 #include <FGrp_TextTextObject.h>
29 #include <FGrp_TextTextSimple.h>
30 #include <FGrp_FontImpl.h>
31 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_ResourceManager.h"
33 #include "FUiAnim_VisualElement.h"
34 #include "FUiCtrl_EditTimePresenter.h"
35 #include "FUiCtrl_EditTime.h"
36 #include "FUiCtrl_DateTimeModel.h"
37 #include "FUiCtrl_DateTimeUtils.h"
38
39
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Base;
42 using namespace Tizen::Graphics::_Text;
43 using namespace Tizen::Ui::Animations;
44 using namespace Tizen::System;
45
46 namespace Tizen { namespace Ui { namespace Controls
47 {
48 _EditTimePresenter::_EditTimePresenter(const String& title)
49         : __pEditDateTimeModel(null)
50         , __pEditTime(null)
51         , __bounds(FloatRectangle())
52         , __titleBounds(FloatRectangle())
53         , __ampmString(String())
54         , __hourString(String())
55         , __minuteString(String())
56         , __title(title)
57         , __24hours(false)
58         , __is24hoursSet(false)
59         , __amEnable(true)
60         , __timePickerEnabled(true)
61         , __selectedId(DATETIME_ID_NONE)
62         , __lastSelectedId(DATETIME_ID_NONE)
63         , __focusId(DATETIME_ID_NONE)
64         , __touchMoveHandled(false)
65         , __pAmPmBgNormalColorReplacementBitmap(null)
66         , __pAmPmBgDisabledColorReplacementBitmap(null)
67         , __pAmPmBgPressedColorReplacementBitmap(null)
68         , __pAmPmBgHighlightedColorReplacementBitmap(null)
69         , __pAmPmBgEffectNomralBitmap(null)
70         , __pAmPmBgEffectPressedBitmap(null)
71         , __pAmPmBgEffectDisabledBitmap(null)
72         , __pColonColorReplacementBitmap(null)
73         , __pColonDisabledColorReplacementBitmap(null)
74         , __pContentBgNormalColorReplacementBitmap(null)
75         , __pContentBgDisabledColorReplacementBitmap(null)
76         , __pContentBgPressedColorReplacementBitmap(null)
77         , __pContentBgHighlightedColorReplacementBitmap(null)
78         , __pContentBgEffectNormalBitmap(null)
79         , __pContentBgEffectPressedBitmap(null)
80         , __pContentBgEffectDisabledBitmap(null)
81         , __pContentProvider(null)
82         , __textObject()
83         , __pFont(null)
84         , __titleObject()
85         , __amPmTextSize(0.0f)
86         , __titleFontSize(0.0f)
87         , __timeFontSize(0.0f)
88         , __isAnimating(false)
89         , __isEditTimeInitialized(false)
90         , __isEnterKeyPressed(false)
91         , __isFocused(false)
92         , __transactionId(0)
93 {
94 }
95
96 _EditTimePresenter::~_EditTimePresenter(void)
97 {
98         __textObject.RemoveAll();
99         __titleObject.RemoveAll();
100
101         delete __pEditDateTimeModel;
102         __pEditDateTimeModel = null;
103
104         delete __pAmPmBgNormalColorReplacementBitmap;
105         __pAmPmBgNormalColorReplacementBitmap = null;
106
107         delete __pAmPmBgDisabledColorReplacementBitmap;
108         __pAmPmBgDisabledColorReplacementBitmap = null;
109
110         delete __pAmPmBgPressedColorReplacementBitmap;
111         __pAmPmBgPressedColorReplacementBitmap = null;
112
113         delete __pAmPmBgHighlightedColorReplacementBitmap;
114         __pAmPmBgHighlightedColorReplacementBitmap = null;
115
116         delete __pAmPmBgEffectNomralBitmap;
117         __pAmPmBgEffectNomralBitmap = null;
118
119         delete __pAmPmBgEffectPressedBitmap;
120         __pAmPmBgEffectPressedBitmap = null;
121
122         delete __pAmPmBgEffectDisabledBitmap;
123         __pAmPmBgEffectDisabledBitmap = null;
124
125         delete __pColonColorReplacementBitmap;
126         __pColonColorReplacementBitmap = null;
127
128         delete __pColonDisabledColorReplacementBitmap;
129         __pColonDisabledColorReplacementBitmap = null;
130
131         delete __pContentBgNormalColorReplacementBitmap;
132         __pContentBgNormalColorReplacementBitmap = null;
133
134         delete __pContentBgDisabledColorReplacementBitmap;
135         __pContentBgDisabledColorReplacementBitmap = null;
136
137         delete __pContentBgPressedColorReplacementBitmap;
138         __pContentBgPressedColorReplacementBitmap = null;
139
140         delete __pContentBgHighlightedColorReplacementBitmap;
141         __pContentBgHighlightedColorReplacementBitmap = null;
142
143         delete __pContentBgEffectNormalBitmap;
144         __pContentBgEffectNormalBitmap = null;
145
146         delete __pContentBgEffectPressedBitmap;
147         __pContentBgEffectPressedBitmap = null;
148
149         delete __pContentBgEffectDisabledBitmap;
150         __pContentBgEffectDisabledBitmap = null;
151
152         if (__transactionId != 0)
153         {
154                 AnimationTransaction::Stop(__transactionId);
155         }
156
157         if (__pContentProvider != null)
158         {
159                 __pEditTime->GetVisualElement()->DetachChild(__pContentProvider);
160                 __pContentProvider->Destroy();
161                 __pContentProvider = null;
162         }
163 }
164
165 _EditTimePresenter*
166 _EditTimePresenter::CreateInstanceN(const _EditTime& editTime, const String& title)
167 {
168         _EditTimePresenter* pEditTimePresenter = new (std::nothrow) _EditTimePresenter(title);
169         SysTryReturn(NID_UI_CTRL, pEditTimePresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
170
171         pEditTimePresenter->__pEditTime = const_cast <_EditTime*>(&editTime);
172
173         pEditTimePresenter->__pEditDateTimeModel = new (std::nothrow) _DateTimeModel;
174         SysTryCatch(NID_UI_CTRL, pEditTimePresenter->__pEditDateTimeModel, , E_OUT_OF_MEMORY,
175                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
176
177         return pEditTimePresenter;
178
179 CATCH:
180         delete pEditTimePresenter;
181         return null;
182 }
183
184 DateTime
185 _EditTimePresenter::GetTime(void) const
186 {
187         DateTime time;
188         time.SetValue(DATETIME_YEAR_MIN, DATETIME_MONTH_MIN, DATETIME_DAY_MIN, GetHour(), GetMinute(), 0);
189
190         return time;
191 }
192
193 int
194 _EditTimePresenter::GetHour(void) const
195 {
196         return __pEditDateTimeModel->GetHour();
197 }
198
199 int
200 _EditTimePresenter::GetMinute(void) const
201 {
202         return __pEditDateTimeModel->GetMinute();
203 }
204
205 void
206 _EditTimePresenter::SetTime(const DateTime& time)
207 {
208         __pEditDateTimeModel->SetDateTime(time);
209 }
210
211 void
212 _EditTimePresenter::SetCurrentTime(void)
213 {
214         __pEditDateTimeModel->SetCurrentDateTime();
215         return;
216 }
217
218 result
219 _EditTimePresenter::SetHour(int hour)
220 {
221         return __pEditDateTimeModel->SetHour(hour);
222 }
223
224 result
225 _EditTimePresenter::SetMinute(int minute)
226 {
227         return __pEditDateTimeModel->SetMinute(minute);
228 }
229
230 void
231 _EditTimePresenter::SetTimePickerEnabled(bool enable)
232 {
233         __timePickerEnabled = enable;
234         return;
235 }
236
237 bool
238 _EditTimePresenter::IsTimePickerEnabled(void) const
239 {
240         return __timePickerEnabled;
241 }
242
243 void
244 _EditTimePresenter::Set24HourNotationEnabled(bool enable)
245 {
246         __24hours = enable;
247         __is24hoursSet = true;
248         return;
249 }
250
251 bool
252 _EditTimePresenter::Is24HourNotationEnabled(void) const
253 {
254         return __24hours;
255 }
256
257 void
258 _EditTimePresenter::SetTimeConversion(void)
259 {
260         int hour = GetHour();
261         int minute = GetMinute();
262
263         if (!__24hours)
264         {
265                 int max = DATETIME_HOUR_MAX_FOR_24NOTATION;
266
267                 if (hour > max)
268                 {
269                         __hourString.Format(10, L"%02d", hour - max);
270                 }
271                 else if (hour == DATETIME_HOUR_MIN)
272                 {
273                         __hourString.Format(10, L"%02d", hour + DATETIME_HOUR_MAX_FOR_24NOTATION);
274                 }
275                 else
276                 {
277                         __hourString.Format(10, L"%02d", hour);
278                 }
279
280                 __minuteString.Format(10, L"%02d", minute);
281         }
282         else
283         {
284                 __hourString.Format(10, L"%02d", hour);
285                 __minuteString.Format(10, L"%02d", minute);
286         }
287
288         return;
289 }
290
291 void
292 _EditTimePresenter::SetAmEnabled(bool amEnable)
293 {
294         String textAm;
295         String textPm;
296
297         _DateTimeUtils dateTimeUtils;
298         dateTimeUtils.GetAmPm(textAm, AM_TYPE);
299         dateTimeUtils.GetAmPm(textPm, PM_TYPE);
300
301         __amEnable = amEnable;
302         int hour = GetHour();
303
304         if (__amEnable)
305         {
306                 __ampmString = textAm;
307                 if (hour >= DATETIME_HOUR_MAX_FOR_24NOTATION)
308                 {
309                         SetHour(hour - DATETIME_HOUR_MAX_FOR_24NOTATION);
310                 }
311         }
312         else
313         {
314                 __ampmString = textPm;
315                 if (hour < DATETIME_HOUR_MAX_FOR_24NOTATION)
316                 {
317                         SetHour(hour + DATETIME_HOUR_MAX_FOR_24NOTATION);
318                 }
319         }
320
321         return;
322 }
323
324 bool
325 _EditTimePresenter::GetAmEnabled(void) const
326 {
327         return __amEnable;
328 }
329
330 FloatRectangle
331 _EditTimePresenter::GetDisplayAreaBoundsFromHoursStyle(_DateTimeId displayBoxId) const
332 {
333         SysTryReturn(NID_UI_CTRL, displayBoxId >= DATETIME_ID_HOUR && displayBoxId <= DATETIME_ID_AMPM, FloatRectangle(),
334                         E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] displayBoxId is out of range.");
335
336         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
337
338         float editTimeHeight = 0.0f;
339         float colonWidth = 0.0f;
340         float timeAmPmMargin = 0.0f;
341         float colonMargin = 0.0f;
342         float timeElementWidth = 0.0f;
343         float amPmHeight = 0.0f;
344         float timeHeight = 0.0f;
345         float titleTimeMargin = 0.0f;
346         float leftMargin = 0.0f;
347
348         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
349         GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonWidth);
350         GET_SHAPE_CONFIG(EDITTIME::TIME_AMPM_MARGIN, __pEditTime->GetOrientation(), timeAmPmMargin);
351         GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
352         GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), amPmHeight);
353         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
354         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
355
356         GET_SHAPE_CONFIG(EDITTIME::TIME_TEXT_LEFT_MARGIN, __pEditTime->GetOrientation(), leftMargin);
357
358         if (__pEditTime->GetBoundsF().height > editTimeHeight)
359         {
360                 editTimeHeight = __pEditTime->GetBoundsF().height;
361         }
362
363         bounds.y = (editTimeHeight - timeHeight) / 2.0f;
364
365         if (!__title.IsEmpty())
366         {
367                 if (displayBoxId == DATETIME_ID_AMPM)
368                 {
369                         bounds.y = __titleBounds.y + __titleBounds.height;
370                 }
371                 else
372                 {
373                         bounds.y = __titleBounds.y + __titleBounds.height + titleTimeMargin;
374                 }
375         }
376
377         bounds.x = leftMargin;
378         bounds.height = timeHeight;
379
380         timeElementWidth = GetTimeElementWidth();
381
382         if (displayBoxId == DATETIME_ID_HOUR)
383         {
384                 bounds.width = timeElementWidth;
385         }
386         else if (displayBoxId == DATETIME_ID_MINUTE)
387         {
388                 bounds.x = bounds.x + timeElementWidth + colonWidth + (2.0f * colonMargin);
389                 bounds.width = timeElementWidth;
390         }
391         else if (displayBoxId == DATETIME_ID_AMPM)
392         {
393                 bounds.x = leftMargin + (2.0f * timeElementWidth) + colonWidth + (2.0f * colonMargin) + timeAmPmMargin;
394
395                 if (__title.IsEmpty())
396                 {
397                         bounds.y = (editTimeHeight - amPmHeight) / 2.0f;
398                 }
399
400                 GET_SHAPE_CONFIG(EDITTIME::AMPM_WIDTH, __pEditTime->GetOrientation(), bounds.width);
401                 bounds.height = amPmHeight;
402         }
403
404         return bounds;
405 }
406
407 float
408 _EditTimePresenter::GetTextWidth(_DateTimeId boxId) const
409 {
410         result r = E_SUCCESS;
411         FloatDimension dim;
412         TextObject dateObject;
413         String hourString;
414         String minuteString;
415
416         hourString.Format(10, L"%02d", GetHour());
417         minuteString.Format(10, L"%02d", GetMinute());
418
419         r = dateObject.Construct();
420         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
421
422         TextSimple* pSimpleText = null;
423
424         if (boxId == DATETIME_ID_HOUR)
425         {
426                 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(hourString.GetPointer())), hourString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
427         }
428         else if (boxId == DATETIME_ID_MINUTE)
429         {
430                 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(minuteString.GetPointer())), minuteString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
431         }
432
433         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), dim.width, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
434
435         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
436
437         dateObject.AppendElement(*pSimpleText);
438         dateObject.SetFont(__pFont, 0, dateObject.GetTextLength());
439         dim = dateObject.GetTextExtentF(0, dateObject.GetTextLength());
440
441         dateObject.RemoveAll();
442         return dim.width;
443 }
444
445 void
446 _EditTimePresenter::SetTitleBounds(void)
447 {
448         GET_SHAPE_CONFIG(EDITTIME::TITLE_TEXT_LEFT_MARGIN, __pEditTime->GetOrientation(), __titleBounds.x);
449         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), __titleBounds.height);
450
451         __titleBounds.width = __pEditTime->GetBoundsF().width - __titleBounds.x;
452         return;
453 }
454
455 FloatRectangle
456 _EditTimePresenter::GetTitleBounds(void) const
457 {
458         return __titleBounds;
459 }
460
461 result
462 _EditTimePresenter::LoadResource(void)
463 {
464         result r = E_SUCCESS;
465
466         Color buttonNormalBgColor;
467         Color buttonDisabledBgColor;
468         Color buttonPressedColor;
469         Color buttonHighlightedColor;
470         Color contentNormalBgColor;
471         Color contentDisabledBgColor;
472         Color contentPressedColor;
473         Color contentHighlightedColor;
474         Color colonTextColor;
475         Color colonTextDisabledColor;
476         Bitmap* pTempBitmap = null;
477
478         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_NORMAL, buttonNormalBgColor);
479         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_PRESSED, buttonPressedColor);
480         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_DISABLED, buttonDisabledBgColor);
481         GET_COLOR_CONFIG(EDITTIME::BUTTON_BG_HIGHLIGHTED, buttonHighlightedColor);
482
483         GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_NORMAL, contentNormalBgColor);
484         GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_DISABLED, contentDisabledBgColor);
485         GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentPressedColor);
486         GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_HIGHLIGHTED, contentHighlightedColor);
487
488         GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, colonTextColor);
489         GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, colonTextDisabledColor);
490
491         GET_SHAPE_CONFIG(EDITTIME::AMPM_FONT_SIZE, __pEditTime->GetOrientation(), __amPmTextSize);
492
493         r = GET_BITMAP_CONFIG_N(EDITTIME::COLON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
494         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
495
496         __pColonColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA),
497                                                                               colonTextColor);
498         SysTryCatch(NID_UI_CTRL, (__pColonColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
499                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
500
501         __pColonDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA),
502                         colonTextDisabledColor);
503         SysTryCatch(NID_UI_CTRL, (__pColonDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
504                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
505
506         delete pTempBitmap;
507         pTempBitmap = null;
508
509         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
510         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
511
512         __pAmPmBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonNormalBgColor);
513         SysTryCatch(NID_UI_CTRL, (__pAmPmBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
514                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
515
516         delete pTempBitmap;
517         pTempBitmap = null;
518
519         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
520         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
521
522         __pAmPmBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonDisabledBgColor);
523         SysTryCatch(NID_UI_CTRL, (__pAmPmBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
524                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
525
526         delete pTempBitmap;
527         pTempBitmap = null;
528
529         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
530         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
531
532         __pAmPmBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonPressedColor);
533         SysTryCatch(NID_UI_CTRL, (__pAmPmBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
534                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
535
536         delete pTempBitmap;
537         pTempBitmap = null;
538
539         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
540         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
541
542         __pAmPmBgHighlightedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), buttonHighlightedColor);
543         SysTryCatch(NID_UI_CTRL, (__pAmPmBgHighlightedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
544                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
545
546         delete pTempBitmap;
547         pTempBitmap = null;
548
549         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
550         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
551
552         __pContentBgNormalColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentNormalBgColor);
553         SysTryCatch(NID_UI_CTRL, (__pContentBgNormalColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
554                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
555
556         delete pTempBitmap;
557         pTempBitmap = null;
558
559         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
560         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
561
562         __pContentBgPressedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentPressedColor);
563         SysTryCatch(NID_UI_CTRL, (__pContentBgPressedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
564                                 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
565
566         delete pTempBitmap;
567         pTempBitmap = null;
568
569         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
570         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
571
572         __pContentBgDisabledColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentDisabledBgColor);
573         SysTryCatch(NID_UI_CTRL, (__pContentBgDisabledColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
574                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
575
576         delete pTempBitmap;
577         pTempBitmap = null;
578
579         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
580         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
581
582         __pContentBgHighlightedColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), contentHighlightedColor);
583         SysTryCatch(NID_UI_CTRL, (__pContentBgHighlightedColorReplacementBitmap != null), r = GetLastResult(), GetLastResult(),
584                                         "[%s] Propagating.", GetErrorMessage(GetLastResult()));
585
586         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectNomralBitmap);
587         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
588
589         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectPressedBitmap);
590         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
591
592         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectDisabledBitmap);
593         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
594
595         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
596         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
597
598         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
599         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
600
601         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
602         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
603
604
605         delete pTempBitmap;
606         pTempBitmap = null;
607
608         return r;
609
610 CATCH:
611         delete pTempBitmap;
612         pTempBitmap = null;
613
614         delete __pAmPmBgNormalColorReplacementBitmap;
615         __pAmPmBgNormalColorReplacementBitmap = null;
616
617         delete __pAmPmBgPressedColorReplacementBitmap;
618         __pAmPmBgPressedColorReplacementBitmap = null;
619
620         delete __pAmPmBgDisabledColorReplacementBitmap;
621         __pAmPmBgDisabledColorReplacementBitmap = null;
622
623         delete __pAmPmBgHighlightedColorReplacementBitmap;
624         __pAmPmBgHighlightedColorReplacementBitmap = null;
625
626         delete __pContentBgNormalColorReplacementBitmap;
627         __pContentBgNormalColorReplacementBitmap = null;
628
629         delete __pContentBgPressedColorReplacementBitmap;
630         __pContentBgPressedColorReplacementBitmap = null;
631
632         delete __pContentBgDisabledColorReplacementBitmap;
633         __pContentBgDisabledColorReplacementBitmap = null;
634
635         delete __pContentBgHighlightedColorReplacementBitmap;
636         __pContentBgHighlightedColorReplacementBitmap = null;
637
638         delete __pAmPmBgEffectNomralBitmap;
639         __pAmPmBgEffectNomralBitmap = null;
640
641         delete __pAmPmBgEffectPressedBitmap;
642         __pAmPmBgEffectPressedBitmap = null;
643
644         delete __pAmPmBgEffectDisabledBitmap;
645         __pAmPmBgEffectDisabledBitmap = null;
646
647         delete __pContentBgEffectNormalBitmap;
648         __pContentBgEffectNormalBitmap = null;
649
650         delete __pContentBgEffectPressedBitmap;
651         __pContentBgEffectPressedBitmap = null;
652
653         delete __pContentBgEffectDisabledBitmap;
654         __pContentBgEffectDisabledBitmap = null;
655
656         delete __pColonColorReplacementBitmap;
657         __pColonColorReplacementBitmap = null;
658
659         delete __pColonDisabledColorReplacementBitmap;
660         __pColonDisabledColorReplacementBitmap = null;
661
662         return r;
663 }
664
665 result
666 _EditTimePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
667 {
668         result r = E_SUCCESS;
669
670         if (pBitmap == null)
671         {
672                 return r;
673         }
674
675         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
676         {
677                 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
678                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
679         }
680         else
681         {
682                 r = canvas.DrawBitmap(bounds, *pBitmap);
683                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
684         }
685
686         return r;
687 }
688
689 float
690 _EditTimePresenter::GetTimeElementWidth(void) const
691 {
692         FloatRectangle bounds;
693         FloatDimension minSize;
694         bounds = __pEditTime->GetBoundsF();
695
696         float timeElementWidth = 0.0f;
697         float timeElementMinWidth = 0.0f;
698         float editTimeWidth = 0.0f;
699
700         GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_WIDTH, __pEditTime->GetOrientation(), timeElementWidth);
701         GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_MIN_WIDTH, __pEditTime->GetOrientation(), timeElementMinWidth);
702         GET_SHAPE_CONFIG(EDITTIME::WIDTH, __pEditTime->GetOrientation(), editTimeWidth);
703
704         GET_DIMENSION_CONFIG(EDITTIME::MIN_SIZE, __pEditTime->GetOrientation(), minSize);
705
706         if (bounds.width >= editTimeWidth)
707         {
708                 return timeElementWidth;
709         }
710
711         if (bounds.width <= minSize.width)
712         {
713                 timeElementWidth = timeElementMinWidth;
714         }
715         else if (bounds.width < editTimeWidth && bounds.width > minSize.width)
716         {
717                 timeElementWidth = timeElementWidth -
718                                 ((timeElementWidth - timeElementMinWidth) / (editTimeWidth - minSize.width)) * (editTimeWidth - bounds.width);
719         }
720
721         return timeElementWidth;
722 }
723
724 result
725 _EditTimePresenter::InitializeTitleObject(void)
726 {
727         result r = E_SUCCESS;
728
729         Color titleNormalColor;
730
731         GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_NORMAL, titleNormalColor);
732
733         r = __titleObject.Construct();
734         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
735
736         TextSimple* pSimpleText = null;
737
738         pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
739         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
740
741         __titleObject.AppendElement(*pSimpleText);
742
743         __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
744         __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
745         __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
746         __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
747         __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
748         __titleObject.SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
749
750         return r;
751 }
752
753 result
754 _EditTimePresenter::InitializeTextObject(void)
755 {
756         result r = E_SUCCESS;
757
758         r = __textObject.Construct();
759         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
760
761         TextSimple* pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
762         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
763                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
764
765         __textObject.AppendElement(*pSimpleText);
766
767         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
768         __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
769         __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
770         __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
771
772         return r;
773 }
774
775 result
776 _EditTimePresenter::Draw(void)
777 {
778         result r = E_SUCCESS;
779
780         if (__isAnimating)
781         {
782                 return E_SUCCESS;
783         }
784
785         Canvas* pCanvas = __pEditTime->GetCanvasN();
786         r = GetLastResult();
787         SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), r, "Failed to get canvas.");
788
789         FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
790
791         float colonMargin = 0.0f;
792
793         Dimension textArea;
794
795         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
796         pCanvas->Clear();
797
798         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
799         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
800         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
801         bool isCustomBitmap = false;
802         Bitmap* pReplacementBitmap = null;
803         Bitmap* pEffectBitmap = null;
804
805         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
806         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
807
808         if (!__24hours)
809         {
810                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
811
812                 if (!__pEditTime->IsEnabled())
813                 {
814                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_DISABLED);
815                         pReplacementBitmap = __pAmPmBgDisabledColorReplacementBitmap;
816                         pEffectBitmap = __pAmPmBgEffectDisabledBitmap;
817                 }
818                 else if (__selectedId != DATETIME_ID_AMPM)
819                 {
820                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_NORMAL);
821                         pReplacementBitmap = __pAmPmBgNormalColorReplacementBitmap;
822                         pEffectBitmap = __pAmPmBgEffectNomralBitmap;
823                 }
824                 else
825                 {
826                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_PRESSED);
827                         pReplacementBitmap = __pAmPmBgPressedColorReplacementBitmap;
828                         pEffectBitmap = __pAmPmBgEffectPressedBitmap;
829                 }
830         }
831
832         if (GetHour() >= DATETIME_HOUR_MAX_FOR_24NOTATION)
833         {
834                 SetAmEnabled(false);
835         }
836         else
837         {
838                 SetAmEnabled(true);
839         }
840
841         SetTimeConversion();
842
843         GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonBounds.width);
844         GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
845         GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), colonBounds.height);
846
847         colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
848         colonBounds.y = hourBounds.y + (hourBounds.height - colonBounds.height) / 2.0f;
849
850         if (!__title.IsEmpty())
851         {
852                 r = DrawTitle(*pCanvas);
853                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
854         }
855
856         r = DrawText(*pCanvas, hourBounds, __hourString, DATETIME_ID_HOUR);
857         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
858
859         r = DrawText(*pCanvas, minuteBounds, __minuteString, DATETIME_ID_MINUTE);
860         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
861
862         r = DrawColon(*pCanvas, colonBounds);
863         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
864
865         if (!__24hours)
866         {
867                 r = DrawResourceBitmap(*pCanvas, ampmBounds, pReplacementBitmap);
868                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
869
870                 if (!isCustomBitmap)
871                 {
872                         r = DrawResourceBitmap(*pCanvas, ampmBounds, pEffectBitmap);
873                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
874                 }
875
876                 r = DrawText(*pCanvas, ampmBounds, __ampmString, DATETIME_ID_AMPM, __amPmTextSize);
877                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
878         }
879
880 CATCH:
881         delete pCanvas;
882         return r;
883 }
884
885 result
886 _EditTimePresenter::DrawFocus(void)
887 {
888         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
889
890         Canvas* pCanvas = __pEditTime->GetCanvasN();
891         SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
892
893         if (__focusId == DATETIME_ID_HOUR)
894         {
895                 bounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
896         }
897         else if (__focusId == DATETIME_ID_MINUTE)
898         {
899                 bounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
900         }
901         else if (__focusId == DATETIME_ID_AMPM)
902         {
903                 bounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
904         }
905         result r = E_SUCCESS;
906
907         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pContentBgHighlightedColorReplacementBitmap))
908         {
909                 r = pCanvas->DrawNinePatchedBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
910                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
911         }
912         else
913         {
914                 r = pCanvas->DrawBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
915                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
916         }
917
918         delete pCanvas;
919         return r;
920
921 CATCH:
922         delete pCanvas;
923         return r;
924 }
925
926 result
927 _EditTimePresenter::DrawColon(Canvas& canvas, const FloatRectangle& bounds)
928 {
929         result r = E_SUCCESS;
930
931         if (!__pEditTime->IsEnabled())
932         {
933                 r = DrawResourceBitmap(canvas, bounds, __pColonDisabledColorReplacementBitmap);
934         }
935         else
936         {
937                 r = DrawResourceBitmap(canvas, bounds, __pColonColorReplacementBitmap);
938         }
939
940         return r;
941 }
942
943 result
944 _EditTimePresenter::DrawTitle(Canvas& canvas)
945 {
946         if (!__pEditTime->IsEnabled())
947         {
948                 Color titleDisabledColor;
949                 GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_DISABLED, titleDisabledColor);
950                 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
951         }
952
953         (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
954         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
955         __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
956
957         __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
958
959         return E_SUCCESS;
960 }
961
962 result
963 _EditTimePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
964 {
965         result r = E_SUCCESS;
966
967         bool isCustomBitmap = false;
968         Bitmap* pReplacementBitmap = null;
969         Bitmap* pEffectBitmap = null;
970
971         if (!__pEditTime->IsEnabled())
972         {
973                 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
974                 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
975                 pEffectBitmap = __pContentBgEffectDisabledBitmap;
976         }
977         else if (__selectedId != boxId)
978         {
979                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
980                                 (GetLastSelectedId() == boxId))
981                 {
982                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
983                         pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
984                         pEffectBitmap = __pContentBgEffectPressedBitmap;
985                 }
986                 else
987                 {
988                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
989                         pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
990                         pEffectBitmap = __pContentBgEffectNormalBitmap;
991                 }
992         }
993         else
994         {
995                 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
996                 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
997                 pEffectBitmap = __pContentBgEffectPressedBitmap;
998         }
999
1000         r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
1001         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1002
1003         if (!isCustomBitmap)
1004         {
1005                 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
1006                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1007         }
1008
1009         return r;
1010 }
1011
1012 result
1013 _EditTimePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId, float textSize)
1014 {
1015         result r = E_SUCCESS;
1016
1017         Color textColor;
1018         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1019
1020         if (!__pEditTime->IsEnabled())
1021         {
1022                 if (boxId == DATETIME_ID_AMPM)
1023                 {
1024                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_DISABLED, textColor);
1025                 }
1026                 else
1027                 {
1028                         GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, textColor);
1029                 }
1030         }
1031         else
1032         {
1033                 GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, textColor);
1034
1035                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
1036                                 (GetLastSelectedId() == boxId))
1037                 {
1038                         GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
1039                         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1040                 }
1041
1042                 if (boxId == DATETIME_ID_AMPM)
1043                 {
1044                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_NORMAL, textColor);
1045                 }
1046
1047                 if (boxId > -1 && boxId == __selectedId)
1048                 {
1049                         if (boxId == DATETIME_ID_AMPM)
1050                         {
1051                                 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_PRESSED, textColor);
1052                         }
1053                         else
1054                         {
1055                                 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
1056                                 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
1057                         }
1058                 }
1059         }
1060
1061         if (boxId != DATETIME_ID_AMPM)
1062         {
1063                 DrawContentBitmap(canvas, bounds, boxId);
1064         }
1065
1066         FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
1067         drawAreaBounds = bounds;
1068
1069         TextSimple* pSimpleText = null;
1070         pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1071         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1072
1073         __textObject.RemoveAll();
1074
1075         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1076         __textObject.AppendElement(*pSimpleText);
1077
1078         if (boxId == DATETIME_ID_AMPM)
1079         {
1080                 (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
1081         }
1082         if (__isFocused && __focusId == boxId)
1083         {
1084                 if (boxId == DATETIME_ID_AMPM)
1085                 {
1086                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_HIGHLIGHTED, textColor);
1087                 }
1088                 else
1089                 {
1090                         GET_COLOR_CONFIG(EDITTIME::TEXT_HIGHLIGHTED, textColor);
1091                 }
1092
1093                 DrawFocus();
1094         }
1095
1096         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1097
1098         __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
1099         __textObject.SetBounds(drawAreaBounds);
1100         __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
1101
1102         return r;
1103 }
1104
1105 _DateTimeId
1106 _EditTimePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
1107 {
1108         _DateTimeId displayBoxId = DATETIME_ID_NONE;
1109
1110         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1111         FloatRectangle hoursBounds(0.0f, 0.0f, 0.0f, 0.0f);
1112         FloatRectangle minutesBounds(0.0f, 0.0f, 0.0f, 0.0f);
1113
1114         if (!__24hours)
1115         {
1116                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1117         }
1118
1119         hoursBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1120         minutesBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1121
1122         if (point.y < hoursBounds.y || point.y > hoursBounds.y + hoursBounds.height)
1123         {
1124                 return displayBoxId;
1125         }
1126
1127         if (hoursBounds.Contains(point))
1128         {
1129                 displayBoxId = DATETIME_ID_HOUR;
1130         }
1131         else if (minutesBounds.Contains(point))
1132         {
1133                 displayBoxId = DATETIME_ID_MINUTE;
1134         }
1135         else if (ampmBounds.Contains(point))
1136         {
1137                 displayBoxId = DATETIME_ID_AMPM;
1138         }
1139
1140         return displayBoxId;
1141 }
1142
1143 void
1144 _EditTimePresenter::SetLastSelectedId(_DateTimeId boxId)
1145 {
1146         __lastSelectedId = boxId;
1147         return;
1148 }
1149
1150 _DateTimeId
1151 _EditTimePresenter::GetLastSelectedId(void) const
1152 {
1153         return __lastSelectedId;
1154 }
1155
1156 void
1157 _EditTimePresenter::SetFocusedElement()
1158 {
1159         if (__isEnterKeyPressed)
1160         {
1161                 __isEnterKeyPressed = false;
1162                 __isFocused = true;
1163         }
1164         if (__focusId == DATETIME_ID_NONE || __focusId == DATETIME_ID_AMPM)
1165         {
1166                 __focusId = DATETIME_ID_HOUR;
1167         }
1168
1169         return;
1170 }
1171
1172 void
1173 _EditTimePresenter::SetFocusState(bool isFocused)
1174 {
1175         __isFocused = isFocused;
1176         return;
1177 }
1178
1179 bool
1180 _EditTimePresenter::OnFocusLost(const _Control &source)
1181 {
1182         if (!__isEnterKeyPressed || __focusId == DATETIME_ID_AMPM)
1183         {
1184                 __focusId = DATETIME_ID_NONE;
1185         }
1186         __isFocused = false;
1187         __pEditTime->Invalidate();
1188         return true;
1189 }
1190
1191 void
1192 _EditTimePresenter::OnFocusModeStateChanged(void)
1193 {
1194         __isFocused = false;
1195         __focusId = DATETIME_ID_NONE;
1196         __pEditTime->Invalidate();
1197         return;
1198 }
1199
1200 bool
1201 _EditTimePresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1202 {
1203         if (!__isFocused)
1204         {
1205                 return false;
1206         }
1207         _KeyCode keyCode = keyInfo.GetKeyCode();
1208
1209         switch (keyCode)
1210         {
1211                 case _KEY_RIGHT:
1212                 {
1213                         __isEnterKeyPressed = false;
1214                         if (__focusId == DATETIME_ID_HOUR)
1215                         {
1216                                 __focusId = DATETIME_ID_MINUTE;
1217                         }
1218                         else if (__focusId == DATETIME_ID_MINUTE)
1219                         {
1220                                 if (!Is24HourNotationEnabled())
1221                                 {
1222                                         __focusId = DATETIME_ID_AMPM;
1223                                 }
1224                         }
1225                         else if (__focusId == DATETIME_ID_AMPM)
1226                         {
1227                                 return false;
1228                         }
1229
1230                         __pEditTime->Invalidate();
1231                         break;
1232                 }
1233                 case _KEY_LEFT:
1234                 {
1235                         __isEnterKeyPressed = false;
1236                         if (__focusId == DATETIME_ID_MINUTE)
1237                         {
1238                                 __focusId = DATETIME_ID_HOUR;
1239                         }
1240                         else if (__focusId == DATETIME_ID_AMPM)
1241                         {
1242                                 __focusId = DATETIME_ID_MINUTE;
1243                         }
1244                         else if (__focusId == DATETIME_ID_HOUR)
1245                         {
1246                                 return false;
1247                         }
1248                         __pEditTime->Invalidate();
1249                         break;
1250                 }
1251
1252                 default:
1253                 {
1254                         return false;
1255                 }
1256         }
1257         return true;
1258 }
1259
1260 bool
1261 _EditTimePresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1262 {
1263         if (!__isFocused)
1264         {
1265                 return false;
1266         }
1267         _KeyCode keyCode = keyInfo.GetKeyCode();
1268
1269         if (__isAnimating)
1270         {
1271                 VisualElement *pEditTimeElement = __pEditTime->GetVisualElement();
1272                 result r = GetLastResult();
1273                 SysTryReturn(NID_UI_CTRL, (pEditTimeElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
1274                 pEditTimeElement->RemoveAllAnimations();
1275         }
1276
1277         int minValue = -1;
1278         int maxValue = -1;
1279         int displayValue = -1;
1280
1281         _DateTimeId boxId = DATETIME_ID_HOUR;
1282
1283         switch (keyCode)
1284         {
1285                 case _KEY_ENTER:
1286                 {
1287                         __isEnterKeyPressed = true;
1288                         if (__focusId == DATETIME_ID_HOUR)
1289                         {
1290                                 boxId = DATETIME_ID_HOUR;
1291                                 if (__pEditTime->GetDateTimeBar() != null)
1292                                 {
1293                                         if (!Is24HourNotationEnabled())
1294                                         {
1295                                                 if (GetHour() == 0)
1296                                                 {
1297                                                         minValue = DATETIME_HOUR_MIN + 1;
1298                                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1299                                                         displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1300                                                 }
1301                                                 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
1302                                                 {
1303                                                         minValue = DATETIME_HOUR_MIN + 1;
1304                                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1305                                                         displayValue = __pEditTime->GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
1306                                                 }
1307                                                 else
1308                                                 {
1309                                                         minValue = DATETIME_HOUR_MIN + 1;
1310                                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1311                                                         displayValue = __pEditTime->GetHour();
1312                                                 }
1313                                         }
1314                                         else
1315                                         {
1316                                                 minValue = DATETIME_HOUR_MIN;
1317                                                 maxValue = DATETIME_HOUR_MAX;
1318                                                 displayValue = __pEditTime->GetHour();
1319                                         }
1320
1321                                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1322                                         {
1323                                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1324                                         }
1325                                 }
1326                         }
1327                         else if (__focusId == DATETIME_ID_MINUTE)
1328                         {
1329                                 if (__pEditTime->GetDateTimeBar() != null)
1330                                 {
1331                                         minValue = DATETIME_MINUTE_MIN;
1332                                         maxValue = DATETIME_MINUTE_MAX;
1333                                         displayValue = __pEditTime->GetMinute();
1334
1335                                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1336                                         {
1337                                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1338                                         }
1339                                 }
1340                                 boxId = DATETIME_ID_MINUTE;
1341                         }
1342                         else if (__focusId == DATETIME_ID_AMPM)
1343                         {
1344                                 SetAmEnabled(!GetAmEnabled());
1345                                 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1346                                 boxId = DATETIME_ID_AMPM;
1347
1348                                 __pEditTime->Invalidate();
1349                         }
1350
1351                         if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM))
1352                         {
1353                                 FloatRectangle absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1354
1355                                 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1356                                 bounds = GetDisplayAreaBoundsFromHoursStyle(boxId);
1357                                 bounds.x += absoluteBounds.x;
1358
1359                                 __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1360                                 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1361                                 __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1362                                 __pEditTime->GetDateTimeBar()->Open();
1363                                 UpdateLastSelectedValue(boxId, false);
1364                         }
1365                         break;
1366                 }
1367
1368                 default:
1369                 {
1370                         return false;
1371                 }
1372         }
1373         return true;
1374 }
1375
1376 bool
1377 _EditTimePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1378 {
1379         SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1380
1381         if (&source != __pEditTime)
1382         {
1383                 return false;
1384         }
1385
1386         __touchMoveHandled = false;
1387
1388         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1389         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1390         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1391
1392         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1393         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1394
1395         if (!__24hours)
1396         {
1397                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1398         }
1399
1400         FloatPoint point = touchinfo.GetCurrentPosition();
1401
1402         _DateTimeId boxId = GetBoxIdFromPosition(point);
1403
1404         int minValue = -1;
1405         int maxValue = -1;
1406         int displayValue = -1;
1407
1408         if (boxId == DATETIME_ID_HOUR)
1409         {
1410                 if (__pEditTime->GetDateTimeBar() != null)
1411                 {
1412                         if (!__24hours)
1413                         {
1414                                 if (GetHour() == 0)
1415                                 {
1416                                         minValue = DATETIME_HOUR_MIN + 1;
1417                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1418                                         displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1419                                 }
1420                                 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
1421                                 {
1422                                         minValue = DATETIME_HOUR_MIN + 1;
1423                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1424                                         displayValue = GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
1425                                 }
1426                                 else
1427                                 {
1428                                         minValue = DATETIME_HOUR_MIN + 1;
1429                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1430                                         displayValue = GetHour();
1431                                 }
1432                         }
1433                         else
1434                         {
1435                                 minValue = DATETIME_HOUR_MIN;
1436                                 maxValue = DATETIME_HOUR_MAX;
1437                                 displayValue = GetHour();
1438                         }
1439
1440                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1441                         {
1442                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1443                         }
1444
1445                         __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1446                 }
1447
1448                 __bounds = hourBounds;
1449         }
1450         else if (boxId == DATETIME_ID_MINUTE)
1451         {
1452                 if (__pEditTime->GetDateTimeBar() != null)
1453                 {
1454                         minValue = DATETIME_MINUTE_MIN;
1455                         maxValue = DATETIME_MINUTE_MAX;
1456                         displayValue = GetMinute();
1457
1458                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1459                         {
1460                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1461                         }
1462
1463                         __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1464                 }
1465
1466                 __bounds = minuteBounds;
1467         }
1468         else if (boxId == DATETIME_ID_AMPM)
1469         {
1470                 __selectedId = boxId;
1471                 __bounds = ampmBounds;
1472                 Draw();
1473         }
1474         else
1475         {
1476                 __selectedId = DATETIME_ID_NONE;
1477                 return false;
1478         }
1479
1480         __selectedId = boxId;
1481
1482         return true;
1483 }
1484
1485 bool
1486 _EditTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1487 {
1488         SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1489
1490         if (&source != __pEditTime)
1491         {
1492                 return false;
1493         }
1494
1495         FloatRectangle bounds = __pEditTime->GetBoundsF();
1496
1497         FloatPoint startPoint(0.0f, 0.0f);
1498
1499         float titleHeight = 0;
1500         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), titleHeight);
1501
1502         __bounds = FloatRectangle(0.0f, titleHeight, bounds.width, bounds.height);
1503
1504         FloatPoint point = touchinfo.GetCurrentPosition();
1505
1506         _DateTimeId boxId = GetBoxIdFromPosition(point);
1507
1508         if ((boxId == GetLastSelectedId() && boxId != DATETIME_ID_AMPM) || boxId != __selectedId || boxId == DATETIME_ID_NONE)
1509         {
1510                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1511                 {
1512                         __pEditTime->GetDateTimeBar()->CloseDateTimeBar();
1513                 }
1514
1515                 __selectedId = DATETIME_ID_NONE;
1516                 SetLastSelectedId(__selectedId);
1517
1518                 Draw();
1519
1520                 return true;
1521         }
1522         UpdateLastSelectedValue(__selectedId, true);
1523         if (GetLastSelectedId() == DATETIME_ID_AMPM)
1524         {
1525                 return true;
1526         }
1527
1528         Draw();
1529
1530         if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM) && (GetLastSelectedId() != DATETIME_ID_NONE))
1531         {
1532                 __pEditTime->SetFocused(true);
1533
1534                 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1535                 bounds = GetDisplayAreaBoundsFromHoursStyle(GetLastSelectedId());
1536                 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1537                 absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1538                 bounds.x += absoluteBounds.x;
1539
1540                 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1541
1542                 if (__pEditTime->GetDateTimeBar()->IsActivated())
1543                 {
1544                         __pEditTime->GetDateTimeBar()->RemoveAllAnimations();
1545                         __pEditTime->GetDateTimeBar()->Close();
1546                         __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1547                         __pEditTime->GetDateTimeBar()->Open();
1548                 }
1549                 else
1550                 {
1551                         __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1552                         __pEditTime->GetDateTimeBar()->Open();
1553                 }
1554         }
1555
1556         __selectedId = DATETIME_ID_NONE;
1557         return true;
1558 }
1559
1560 void
1561 _EditTimePresenter::UpdateLastSelectedValue(_DateTimeId boxId, bool isTouchPressed)
1562 {
1563         __selectedId = boxId;
1564         SetLastSelectedId(boxId);
1565
1566         __lastSelectedValue = "";
1567
1568         if (GetLastSelectedId() == DATETIME_ID_HOUR)
1569         {
1570                 int hours = GetHour();
1571
1572                 if (!Is24HourNotationEnabled())
1573                 {
1574                         hours = hours % 12;
1575
1576                         if (hours == DATETIME_HOUR_MIN)
1577                         {
1578                                 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1579                         }
1580                 }
1581                 __lastSelectedValue.Format(10, L"%02d", hours);
1582                 if (isTouchPressed)
1583                 {
1584                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditTime);
1585                 }
1586         }
1587         else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1588         {
1589                 __lastSelectedValue.Format(10, L"%02d", GetMinute());
1590                 if (isTouchPressed)
1591                 {
1592                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditTime);
1593                 }
1594         }
1595         else if (GetLastSelectedId() == DATETIME_ID_AMPM)
1596         {
1597                 SetAmEnabled(!GetAmEnabled());
1598                 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1599                 if (isTouchPressed)
1600                 {
1601                         __pEditTime->UpdateAccessibilityElement();
1602                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditTime);
1603                 }
1604                 __selectedId = DATETIME_ID_NONE;
1605
1606                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1607                 {
1608                         __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1609                         __pEditTime->GetDateTimeBar()->Close();
1610                 }
1611         }
1612
1613         __selectedId = DATETIME_ID_NONE;
1614         __pEditTime->Invalidate();
1615         return;
1616 }
1617
1618 bool
1619 _EditTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1620 {
1621         if (&source != __pEditTime)
1622         {
1623                 return false;
1624         }
1625
1626         __selectedId = DATETIME_ID_NONE;
1627
1628         return true;
1629 }
1630
1631 bool
1632 _EditTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1633 {
1634         if (&source != __pEditTime)
1635         {
1636                 return false;
1637         }
1638
1639         if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1640         {
1641                 return true;
1642         }
1643
1644         return false;
1645 }
1646
1647 void
1648 _EditTimePresenter::OnTouchMoveHandled(const _Control& control)
1649 {
1650         __touchMoveHandled = true;
1651         __selectedId = DATETIME_ID_NONE;
1652
1653         return;
1654 }
1655
1656 void
1657 _EditTimePresenter::OnFontChanged(Font* pFont)
1658 {
1659         __pFont = pFont;
1660
1661         if (__pEditTime->GetDateTimeBar() != null)
1662         {
1663                 __pEditTime->GetDateTimeBar()->SetFont(*pFont);
1664         }
1665
1666         return;
1667 }
1668
1669 void
1670 _EditTimePresenter::OnFontInfoRequested(unsigned long& style, float& size)
1671 {
1672         style = FONT_STYLE_PLAIN;
1673         size = __timeFontSize;
1674
1675         return;
1676 }
1677
1678 result
1679 _EditTimePresenter::Initialize(void)
1680 {
1681         result r = E_SUCCESS;
1682
1683         float titleTimeMargin = 0;
1684         float timeHeight = 0;
1685         float editTimeHeight = 0;
1686
1687         GET_SHAPE_CONFIG(EDITTIME::TEXT_FONT_SIZE, __pEditTime->GetOrientation(), __titleFontSize);
1688         GET_SHAPE_CONFIG(EDITTIME::TIME_FONT_SIZE, __pEditTime->GetOrientation(), __timeFontSize);
1689         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
1690         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
1691         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
1692
1693         if (__pEditTime->GetBoundsF().height > editTimeHeight)
1694         {
1695                 editTimeHeight = __pEditTime->GetBoundsF().height;
1696         }
1697
1698         if (!__title.IsEmpty())
1699         {
1700                 SetTitleBounds();
1701                 if (!__isEditTimeInitialized)
1702                 {
1703                         r = InitializeTitleObject();
1704                         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1705                 }
1706
1707                 __titleBounds.y = (editTimeHeight - (__titleBounds.height + titleTimeMargin + timeHeight)) / 2.0f;
1708                 __titleObject.SetBounds(__titleBounds);
1709         }
1710
1711         __pFont = __pEditTime->GetFallbackFont();
1712         r = GetLastResult();
1713         SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1714
1715         if (!__isEditTimeInitialized)
1716         {
1717                 r = LoadResource();
1718                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1719
1720                 r = InitializeTextObject();
1721                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1722         }
1723
1724         __isEditTimeInitialized = true;
1725
1726         UpdateTimeFormat();
1727         return r;
1728 }
1729
1730 void
1731 _EditTimePresenter::UpdateTimeFormat(void)
1732 {
1733         if (!__is24hoursSet)
1734         {
1735                 String key(L"http://tizen.org/setting/locale.time.format.24hour");
1736                 SettingInfo::GetValue(key , __24hours);
1737         }
1738
1739         return;
1740 }
1741
1742 void
1743 _EditTimePresenter::Animate(void)
1744 {
1745         SysTryReturnVoidResult(NID_UI_CTRL, !__isAnimating, E_SUCCESS, "Rolling animation is in progress.");
1746         SysAssertf((__pFont != null), "Font instance must not be null.");
1747
1748         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1749
1750         result r = E_SUCCESS;
1751         FloatRectangle rect;
1752         String hourString;
1753         String minuteString;
1754         String newValue;
1755         TextSimple* pOldSimpleText = null;
1756         TextSimple* pNewSimpleText = null;
1757         bool isCustomBitmap = false;
1758
1759         _DateTimeUtils dateTimeUtils;
1760         int hours = GetHour();
1761         if (!Is24HourNotationEnabled())
1762         {
1763                 hours = hours % 12;
1764
1765                 if (hours == DATETIME_HOUR_MIN)
1766                 {
1767                         hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1768                 }
1769         }
1770         hourString.Format(10, L"%02d", hours);
1771         minuteString.Format(10, L"%02d", GetMinute());
1772
1773         if (GetLastSelectedId() == DATETIME_ID_HOUR)
1774         {
1775                 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(hourString) == false), E_SUCCESS, "[E_SUCCESS] Hour string matched.");
1776
1777                 newValue = hourString;
1778                 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1779         }
1780         else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1781         {
1782                 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(minuteString) == false), E_SUCCESS, "[E_SUCCESS] Minute string matched.");
1783
1784                 newValue = minuteString;
1785                 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1786         }
1787
1788         FloatDimension newTextDim;
1789         FloatDimension oldTextDim;
1790         FloatPoint textPoint;
1791         VisualElement* pNewVisualElement = null;
1792         VisualElement* pOldVisualElement = null;
1793         VisualElement* pEditTimeElement = null;
1794         VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1795         VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1796         Canvas *pCanvas = null;
1797         Canvas *pContentCanvas = null;
1798         Color contentBgColor;
1799         Color textNormalColor;
1800         Color textPressedColor;
1801         float contentTextMargin;
1802
1803         GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1804         GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1805         GET_SHAPE_CONFIG(EDITDATE::CONTENT_TEXT_MARGIN, __pEditTime->GetOrientation(), contentTextMargin);
1806
1807         __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1808         __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1809
1810         if (newTextDim.width > oldTextDim.width)
1811         {
1812                 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1813         }
1814         else
1815         {
1816                 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1817         }
1818
1819         SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditTime->GetBounds().width), E_SUCCESS, "Rolling animation cann't be played.");
1820
1821         __isAnimating = true;
1822
1823         __pContentProvider = new (std::nothrow) VisualElement();
1824         SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1825
1826         r = __pContentProvider->Construct();
1827         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1828
1829         __pContentProvider->SetShowState(true);
1830         __pContentProvider->SetClipChildrenEnabled(true);
1831         __pContentProvider->SetImplicitAnimationEnabled(false);
1832
1833         pEditTimeElement = __pEditTime->GetVisualElement();
1834         r = GetLastResult();
1835         SysTryCatch(NID_UI_CTRL, (pEditTimeElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1836
1837         pNewVisualElement = new (std::nothrow) VisualElement();
1838         SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1839
1840         r = pNewVisualElement->Construct();
1841         if (r != E_SUCCESS)
1842         {
1843                 pNewVisualElement->Destroy();
1844                 pNewVisualElement = null;
1845         }
1846         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1847
1848         pNewVisualElement->SetShowState(true);
1849
1850         pOldVisualElement = new (std::nothrow) VisualElement();
1851         if (pOldVisualElement == null)
1852         {
1853                 pNewVisualElement->Destroy();
1854                 pNewVisualElement = null;
1855         }
1856         SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1857
1858         r = pOldVisualElement->Construct();
1859         if (r != E_SUCCESS)
1860         {
1861                 pNewVisualElement->Destroy();
1862                 pOldVisualElement->Destroy();
1863                 pNewVisualElement = null;
1864                 pOldVisualElement = null;
1865         }
1866         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1867
1868         pOldVisualElement->SetShowState(true);
1869
1870         __pContentProvider->SetBounds(FloatRectangle((rect.x + contentTextMargin), (rect.y + (contentTextMargin * 2.0f)), (rect.width - (contentTextMargin * 2.0f)), (rect.height - (contentTextMargin * 4.0f))));
1871
1872         pNewVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1873         pOldVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1874
1875         pContentCanvas = pEditTimeElement->GetCanvasN(__pContentProvider->GetBounds());
1876         r = GetLastResult();
1877         SysTryCatch(NID_UI_CTRL, (pContentCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1878         pContentCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1879         pContentCanvas->Clear();
1880
1881         pCanvas = pEditTimeElement->GetCanvasN(rect);
1882         r = GetLastResult();
1883         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1884         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1885         pCanvas->Clear();
1886         rect.x = 0.0f;
1887         rect.y = 0.0f;
1888         r = DrawResourceBitmap(*pCanvas, rect, __pContentBgPressedColorReplacementBitmap);
1889         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
1890
1891         if (!isCustomBitmap)
1892         {
1893                 result res = DrawResourceBitmap(*pCanvas, rect, __pContentBgEffectPressedBitmap);
1894
1895                 if (res != E_SUCCESS)
1896                 {
1897                         SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(res));
1898                 }
1899         }
1900
1901         delete pCanvas;
1902         pCanvas = null;
1903
1904         if (r != E_SUCCESS)
1905         {
1906                 pContentCanvas->SetBackgroundColor(contentBgColor);
1907                 pContentCanvas->Clear();
1908         }
1909
1910         delete pContentCanvas;
1911         pContentCanvas = null;
1912
1913         pEditTimeElement->AttachChild(*__pContentProvider);
1914
1915         __pContentProvider->AttachChild(*pOldVisualElement);
1916         __pContentProvider->AttachChild(*pNewVisualElement);
1917
1918         pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1919         SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1920
1921         pNewBoundsAnimation->SetDuration(300);
1922         pNewBoundsAnimation->SetPropertyName("bounds.position");
1923         pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, oldTextDim.height)));
1924         pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, 0.0f)));
1925
1926         pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1927         SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1928
1929         pOldBoundsAnimation->SetDuration(300);
1930         pOldBoundsAnimation->SetPropertyName("bounds.position");
1931         pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, 0.0f)));
1932         pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, oldTextDim.height * -1.0f)));
1933
1934         pOldSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__lastSelectedValue.GetPointer())), __lastSelectedValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1935         SysTryCatch(NID_UI_CTRL, (pOldSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1936
1937         pCanvas = pOldVisualElement->GetCanvasN();
1938         r = GetLastResult();
1939         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1940
1941         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1942         pCanvas->Clear();
1943         pCanvas->SetForegroundColor(textPressedColor);
1944
1945         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1946         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1947         __textObject.RemoveAll();
1948         __textObject.AppendElement(*pOldSimpleText);
1949
1950         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1951         __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1952         __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1953         __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1954
1955         delete pCanvas;
1956         pCanvas = null;
1957
1958         pNewSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(newValue.GetPointer())), newValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1959         SysTryCatch(NID_UI_CTRL, (pNewSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1960
1961         pCanvas = pNewVisualElement->GetCanvasN();
1962         r = GetLastResult();
1963         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1964
1965         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1966         pCanvas->Clear();
1967         pCanvas->SetForegroundColor(textPressedColor);
1968
1969         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1970         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1971         __textObject.RemoveAll();
1972         __textObject.AppendElement(*pNewSimpleText);
1973
1974         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1975         __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1976         __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1977         __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1978
1979         delete pCanvas;
1980         pCanvas = null;
1981
1982         pOldVisualElement->SetImplicitAnimationEnabled(false);
1983         pNewVisualElement->SetImplicitAnimationEnabled(false);
1984
1985         AnimationTransaction::Begin(__transactionId);
1986         pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1987         pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1988         AnimationTransaction::SetCurrentTransactionEventListener(__pEditTime);
1989         AnimationTransaction::Commit();
1990
1991         delete pOldBoundsAnimation;
1992         delete pNewBoundsAnimation;
1993
1994         return;
1995
1996 CATCH:
1997         __isAnimating = false;
1998         __pContentProvider->Destroy();
1999         __pContentProvider = null;
2000
2001         delete pNewBoundsAnimation;
2002         pNewBoundsAnimation = null;
2003
2004         delete pOldBoundsAnimation;
2005         pOldBoundsAnimation = null;
2006
2007         delete pOldSimpleText;
2008         pOldSimpleText = null;
2009
2010         delete pNewSimpleText;
2011         pNewSimpleText = null;
2012
2013         delete pContentCanvas;
2014         pContentCanvas = null;
2015
2016         return;
2017 }
2018
2019 void
2020 _EditTimePresenter::EndTransaction(void)
2021 {
2022         result r = E_SUCCESS;
2023
2024         __isAnimating = false;
2025         VisualElement* pEditTimeElement = __pEditTime->GetVisualElement();
2026         r = GetLastResult();
2027         SysTryReturnVoidResult(NID_UI_CTRL, (pEditTimeElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
2028
2029         if (__pContentProvider != null)
2030         {
2031                 pEditTimeElement->DetachChild(*__pContentProvider);
2032                 __pContentProvider->Destroy();
2033                 __pContentProvider = null;
2034
2035         }
2036
2037         Draw();
2038         __transactionId = 0;
2039         return;
2040 }
2041 }}} // Tizen::Ui::Controls