Applied GET_REPLACED_BITMAP_CONFIG_N to Colorpicker/EditDate/EditTime
[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_REPLACED_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, buttonNormalBgColor, __pAmPmBgNormalColorReplacementBitmap);
510         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
511
512         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, buttonDisabledBgColor, __pAmPmBgDisabledColorReplacementBitmap);
513         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
514
515         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, buttonPressedColor, __pAmPmBgPressedColorReplacementBitmap);
516         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
517
518         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, buttonHighlightedColor, __pAmPmBgHighlightedColorReplacementBitmap);
519         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
520
521         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, contentNormalBgColor, __pContentBgNormalColorReplacementBitmap);
522         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
523
524         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, contentPressedColor, __pContentBgPressedColorReplacementBitmap);
525         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
526
527         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, contentDisabledBgColor, __pContentBgDisabledColorReplacementBitmap);
528         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
529
530         r = GET_REPLACED_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, contentHighlightedColor, __pContentBgHighlightedColorReplacementBitmap);
531         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
532
533         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectNomralBitmap);
534         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
535
536         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectPressedBitmap);
537         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
538
539         r = GET_BITMAP_CONFIG_N(EDITTIME::BUTTON_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pAmPmBgEffectDisabledBitmap);
540         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
541
542         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectNormalBitmap);
543         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
544
545         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectPressedBitmap);
546         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
547
548         r = GET_BITMAP_CONFIG_N(EDITTIME::CONTENT_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, __pContentBgEffectDisabledBitmap);
549         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
550
551         return r;
552
553 CATCH:
554         delete __pAmPmBgNormalColorReplacementBitmap;
555         __pAmPmBgNormalColorReplacementBitmap = null;
556
557         delete __pAmPmBgPressedColorReplacementBitmap;
558         __pAmPmBgPressedColorReplacementBitmap = null;
559
560         delete __pAmPmBgDisabledColorReplacementBitmap;
561         __pAmPmBgDisabledColorReplacementBitmap = null;
562
563         delete __pAmPmBgHighlightedColorReplacementBitmap;
564         __pAmPmBgHighlightedColorReplacementBitmap = null;
565
566         delete __pContentBgNormalColorReplacementBitmap;
567         __pContentBgNormalColorReplacementBitmap = null;
568
569         delete __pContentBgPressedColorReplacementBitmap;
570         __pContentBgPressedColorReplacementBitmap = null;
571
572         delete __pContentBgDisabledColorReplacementBitmap;
573         __pContentBgDisabledColorReplacementBitmap = null;
574
575         delete __pContentBgHighlightedColorReplacementBitmap;
576         __pContentBgHighlightedColorReplacementBitmap = null;
577
578         delete __pAmPmBgEffectNomralBitmap;
579         __pAmPmBgEffectNomralBitmap = null;
580
581         delete __pAmPmBgEffectPressedBitmap;
582         __pAmPmBgEffectPressedBitmap = null;
583
584         delete __pAmPmBgEffectDisabledBitmap;
585         __pAmPmBgEffectDisabledBitmap = null;
586
587         delete __pContentBgEffectNormalBitmap;
588         __pContentBgEffectNormalBitmap = null;
589
590         delete __pContentBgEffectPressedBitmap;
591         __pContentBgEffectPressedBitmap = null;
592
593         delete __pContentBgEffectDisabledBitmap;
594         __pContentBgEffectDisabledBitmap = null;
595
596         delete __pColonColorReplacementBitmap;
597         __pColonColorReplacementBitmap = null;
598
599         delete __pColonDisabledColorReplacementBitmap;
600         __pColonDisabledColorReplacementBitmap = null;
601
602         return r;
603 }
604
605 result
606 _EditTimePresenter::DrawResourceBitmap(Canvas& canvas, const FloatRectangle& bounds, Bitmap* pBitmap)
607 {
608         result r = E_SUCCESS;
609
610         if (pBitmap == null)
611         {
612                 return r;
613         }
614
615         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
616         {
617                 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
618                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
619         }
620         else
621         {
622                 r = canvas.DrawBitmap(bounds, *pBitmap);
623                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
624         }
625
626         return r;
627 }
628
629 float
630 _EditTimePresenter::GetTimeElementWidth(void) const
631 {
632         FloatRectangle bounds;
633         FloatDimension minSize;
634         bounds = __pEditTime->GetBoundsF();
635
636         float timeElementWidth = 0.0f;
637         float timeElementMinWidth = 0.0f;
638         float editTimeWidth = 0.0f;
639
640         GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_WIDTH, __pEditTime->GetOrientation(), timeElementWidth);
641         GET_SHAPE_CONFIG(EDITTIME::HOUR_MINUTE_MIN_WIDTH, __pEditTime->GetOrientation(), timeElementMinWidth);
642         GET_SHAPE_CONFIG(EDITTIME::WIDTH, __pEditTime->GetOrientation(), editTimeWidth);
643
644         GET_DIMENSION_CONFIG(EDITTIME::MIN_SIZE, __pEditTime->GetOrientation(), minSize);
645
646         if (bounds.width >= editTimeWidth)
647         {
648                 return timeElementWidth;
649         }
650
651         if (bounds.width <= minSize.width)
652         {
653                 timeElementWidth = timeElementMinWidth;
654         }
655         else if (bounds.width < editTimeWidth && bounds.width > minSize.width)
656         {
657                 timeElementWidth = timeElementWidth -
658                                 ((timeElementWidth - timeElementMinWidth) / (editTimeWidth - minSize.width)) * (editTimeWidth - bounds.width);
659         }
660
661         return timeElementWidth;
662 }
663
664 result
665 _EditTimePresenter::InitializeTitleObject(void)
666 {
667         result r = E_SUCCESS;
668
669         Color titleNormalColor;
670
671         GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_NORMAL, titleNormalColor);
672
673         r = __titleObject.Construct();
674         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
675
676         TextSimple* pSimpleText = null;
677
678         pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__title.GetPointer())), __title.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
679         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
680
681         __titleObject.AppendElement(*pSimpleText);
682
683         __titleObject.SetForegroundColor(titleNormalColor, 0, __titleObject.GetTextLength());
684         __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
685         __titleObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
686         __titleObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
687         __titleObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
688         __titleObject.SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
689
690         return r;
691 }
692
693 result
694 _EditTimePresenter::InitializeTextObject(void)
695 {
696         result r = E_SUCCESS;
697
698         r = __textObject.Construct();
699         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
700
701         TextSimple* pSimpleText = new (std::nothrow)TextSimple(null, 0, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
702         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
703                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
704
705         __textObject.AppendElement(*pSimpleText);
706
707         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
708         __textObject.SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
709         __textObject.SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
710         __textObject.SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
711
712         return r;
713 }
714
715 result
716 _EditTimePresenter::Draw(void)
717 {
718         result r = E_SUCCESS;
719
720         if (__isAnimating)
721         {
722                 return E_SUCCESS;
723         }
724
725         Canvas* pCanvas = __pEditTime->GetCanvasN();
726         r = GetLastResult();
727         SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), r, "Failed to get canvas.");
728
729         FloatRectangle colonBounds(0.0f, 0.0f, 0.0f, 0.0f);
730
731         float colonMargin = 0.0f;
732
733         Dimension textArea;
734
735         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
736         pCanvas->Clear();
737
738         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
739         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
740         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
741         bool isCustomBitmap = false;
742         Bitmap* pReplacementBitmap = null;
743         Bitmap* pEffectBitmap = null;
744
745         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
746         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
747
748         if (!__24hours)
749         {
750                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
751
752                 if (!__pEditTime->IsEnabled())
753                 {
754                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_DISABLED);
755                         pReplacementBitmap = __pAmPmBgDisabledColorReplacementBitmap;
756                         pEffectBitmap = __pAmPmBgEffectDisabledBitmap;
757                 }
758                 else if (__selectedId != DATETIME_ID_AMPM)
759                 {
760                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_NORMAL);
761                         pReplacementBitmap = __pAmPmBgNormalColorReplacementBitmap;
762                         pEffectBitmap = __pAmPmBgEffectNomralBitmap;
763                 }
764                 else
765                 {
766                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::BUTTON_BG_PRESSED);
767                         pReplacementBitmap = __pAmPmBgPressedColorReplacementBitmap;
768                         pEffectBitmap = __pAmPmBgEffectPressedBitmap;
769                 }
770         }
771
772         if (GetHour() >= DATETIME_HOUR_MAX_FOR_24NOTATION)
773         {
774                 SetAmEnabled(false);
775         }
776         else
777         {
778                 SetAmEnabled(true);
779         }
780
781         SetTimeConversion();
782
783         GET_SHAPE_CONFIG(EDITTIME::COLON_WIDTH, __pEditTime->GetOrientation(), colonBounds.width);
784         GET_SHAPE_CONFIG(EDITTIME::COLON_MARGIN, __pEditTime->GetOrientation(), colonMargin);
785         GET_SHAPE_CONFIG(EDITTIME::AMPM_HEIGHT, __pEditTime->GetOrientation(), colonBounds.height);
786
787         colonBounds.x = hourBounds.x + hourBounds.width + colonMargin;
788         colonBounds.y = hourBounds.y + (hourBounds.height - colonBounds.height) / 2.0f;
789
790         if (!__title.IsEmpty())
791         {
792                 r = DrawTitle(*pCanvas);
793                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
794         }
795
796         r = DrawText(*pCanvas, hourBounds, __hourString, DATETIME_ID_HOUR);
797         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
798
799         r = DrawText(*pCanvas, minuteBounds, __minuteString, DATETIME_ID_MINUTE);
800         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
801
802         r = DrawColon(*pCanvas, colonBounds);
803         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
804
805         if (!__24hours)
806         {
807                 r = DrawResourceBitmap(*pCanvas, ampmBounds, pReplacementBitmap);
808                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
809
810                 if (!isCustomBitmap)
811                 {
812                         r = DrawResourceBitmap(*pCanvas, ampmBounds, pEffectBitmap);
813                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
814                 }
815
816                 r = DrawText(*pCanvas, ampmBounds, __ampmString, DATETIME_ID_AMPM, __amPmTextSize);
817                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
818         }
819
820 CATCH:
821         delete pCanvas;
822         return r;
823 }
824
825 result
826 _EditTimePresenter::DrawFocus(void)
827 {
828         FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
829
830         Canvas* pCanvas = __pEditTime->GetCanvasN();
831         SysTryReturnResult(NID_UI_CTRL, (pCanvas != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create canvas.");
832
833         if (__focusId == DATETIME_ID_HOUR)
834         {
835                 bounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
836         }
837         else if (__focusId == DATETIME_ID_MINUTE)
838         {
839                 bounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
840         }
841         else if (__focusId == DATETIME_ID_AMPM)
842         {
843                 bounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
844         }
845         result r = E_SUCCESS;
846
847         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pContentBgHighlightedColorReplacementBitmap))
848         {
849                 r = pCanvas->DrawNinePatchedBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
850                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
851         }
852         else
853         {
854                 r = pCanvas->DrawBitmap(bounds, *__pContentBgHighlightedColorReplacementBitmap);
855                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
856         }
857
858         delete pCanvas;
859         return r;
860
861 CATCH:
862         delete pCanvas;
863         return r;
864 }
865
866 result
867 _EditTimePresenter::DrawColon(Canvas& canvas, const FloatRectangle& bounds)
868 {
869         result r = E_SUCCESS;
870
871         if (!__pEditTime->IsEnabled())
872         {
873                 r = DrawResourceBitmap(canvas, bounds, __pColonDisabledColorReplacementBitmap);
874         }
875         else
876         {
877                 r = DrawResourceBitmap(canvas, bounds, __pColonColorReplacementBitmap);
878         }
879
880         return r;
881 }
882
883 result
884 _EditTimePresenter::DrawTitle(Canvas& canvas)
885 {
886         if (!__pEditTime->IsEnabled())
887         {
888                 Color titleDisabledColor;
889                 GET_COLOR_CONFIG(EDITTIME::TITLE_TEXT_DISABLED, titleDisabledColor);
890                 __titleObject.SetForegroundColor(titleDisabledColor, 0, __titleObject.GetTextLength());
891         }
892
893         (_FontImpl::GetInstance(*__pFont))->SetSize(__titleFontSize);
894         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
895         __titleObject.SetFont(__pFont, 0, __titleObject.GetTextLength());
896
897         __titleObject.Draw(*_CanvasImpl::GetInstance(canvas));
898
899         return E_SUCCESS;
900 }
901
902 result
903 _EditTimePresenter::DrawContentBitmap(Canvas& canvas, const FloatRectangle& bounds, _DateTimeId boxId)
904 {
905         result r = E_SUCCESS;
906
907         bool isCustomBitmap = false;
908         Bitmap* pReplacementBitmap = null;
909         Bitmap* pEffectBitmap = null;
910
911         if (!__pEditTime->IsEnabled())
912         {
913                 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_DISABLED);
914                 pReplacementBitmap = __pContentBgDisabledColorReplacementBitmap;
915                 pEffectBitmap = __pContentBgEffectDisabledBitmap;
916         }
917         else if (__selectedId != boxId)
918         {
919                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
920                                 (GetLastSelectedId() == boxId))
921                 {
922                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
923                         pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
924                         pEffectBitmap = __pContentBgEffectPressedBitmap;
925                 }
926                 else
927                 {
928                         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_NORMAL);
929                         pReplacementBitmap = __pContentBgNormalColorReplacementBitmap;
930                         pEffectBitmap = __pContentBgEffectNormalBitmap;
931                 }
932         }
933         else
934         {
935                 isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
936                 pReplacementBitmap = __pContentBgPressedColorReplacementBitmap;
937                 pEffectBitmap = __pContentBgEffectPressedBitmap;
938         }
939
940         r = DrawResourceBitmap(canvas, bounds, pReplacementBitmap);
941         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
942
943         if (!isCustomBitmap)
944         {
945                 r = DrawResourceBitmap(canvas, bounds, pEffectBitmap);
946                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
947         }
948
949         return r;
950 }
951
952 result
953 _EditTimePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const String& text, _DateTimeId boxId, float textSize)
954 {
955         result r = E_SUCCESS;
956
957         Color textColor;
958         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
959
960         if (!__pEditTime->IsEnabled())
961         {
962                 if (boxId == DATETIME_ID_AMPM)
963                 {
964                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_DISABLED, textColor);
965                 }
966                 else
967                 {
968                         GET_COLOR_CONFIG(EDITTIME::TEXT_DISABLED, textColor);
969                 }
970         }
971         else
972         {
973                 GET_COLOR_CONFIG(EDITTIME::TEXT_NORMAL, textColor);
974
975                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated() &&
976                                 (GetLastSelectedId() == boxId))
977                 {
978                         GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
979                         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
980                 }
981
982                 if (boxId == DATETIME_ID_AMPM)
983                 {
984                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_NORMAL, textColor);
985                 }
986
987                 if (boxId > -1 && boxId == __selectedId)
988                 {
989                         if (boxId == DATETIME_ID_AMPM)
990                         {
991                                 GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_PRESSED, textColor);
992                         }
993                         else
994                         {
995                                 GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textColor);
996                                 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
997                         }
998                 }
999         }
1000
1001         if (boxId != DATETIME_ID_AMPM)
1002         {
1003                 DrawContentBitmap(canvas, bounds, boxId);
1004         }
1005
1006         FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
1007         drawAreaBounds = bounds;
1008
1009         TextSimple* pSimpleText = null;
1010         pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1011         SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1012
1013         __textObject.RemoveAll();
1014
1015         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1016         __textObject.AppendElement(*pSimpleText);
1017
1018         if (boxId == DATETIME_ID_AMPM)
1019         {
1020                 (_FontImpl::GetInstance(*__pFont))->SetSize(textSize);
1021         }
1022         if (__isFocused && __focusId == boxId)
1023         {
1024                 if (boxId == DATETIME_ID_AMPM)
1025                 {
1026                         GET_COLOR_CONFIG(EDITTIME::BUTTON_TEXT_HIGHLIGHTED, textColor);
1027                 }
1028                 else
1029                 {
1030                         GET_COLOR_CONFIG(EDITTIME::TEXT_HIGHLIGHTED, textColor);
1031                 }
1032
1033                 DrawFocus();
1034         }
1035
1036         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1037
1038         __textObject.SetForegroundColor(textColor, 0, __textObject.GetTextLength());
1039         __textObject.SetBounds(drawAreaBounds);
1040         __textObject.Draw(*_CanvasImpl::GetInstance(canvas));
1041
1042         return r;
1043 }
1044
1045 _DateTimeId
1046 _EditTimePresenter::GetBoxIdFromPosition(const FloatPoint& point) const
1047 {
1048         _DateTimeId displayBoxId = DATETIME_ID_NONE;
1049
1050         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1051         FloatRectangle hoursBounds(0.0f, 0.0f, 0.0f, 0.0f);
1052         FloatRectangle minutesBounds(0.0f, 0.0f, 0.0f, 0.0f);
1053
1054         if (!__24hours)
1055         {
1056                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1057         }
1058
1059         hoursBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1060         minutesBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1061
1062         if (point.y < hoursBounds.y || point.y > hoursBounds.y + hoursBounds.height)
1063         {
1064                 return displayBoxId;
1065         }
1066
1067         if (hoursBounds.Contains(point))
1068         {
1069                 displayBoxId = DATETIME_ID_HOUR;
1070         }
1071         else if (minutesBounds.Contains(point))
1072         {
1073                 displayBoxId = DATETIME_ID_MINUTE;
1074         }
1075         else if (ampmBounds.Contains(point))
1076         {
1077                 displayBoxId = DATETIME_ID_AMPM;
1078         }
1079
1080         return displayBoxId;
1081 }
1082
1083 void
1084 _EditTimePresenter::SetLastSelectedId(_DateTimeId boxId)
1085 {
1086         __lastSelectedId = boxId;
1087         return;
1088 }
1089
1090 _DateTimeId
1091 _EditTimePresenter::GetLastSelectedId(void) const
1092 {
1093         return __lastSelectedId;
1094 }
1095
1096 void
1097 _EditTimePresenter::SetFocusedElement()
1098 {
1099         if (__isEnterKeyPressed)
1100         {
1101                 __isEnterKeyPressed = false;
1102                 __isFocused = true;
1103         }
1104         if (__focusId == DATETIME_ID_NONE || __focusId == DATETIME_ID_AMPM)
1105         {
1106                 __focusId = DATETIME_ID_HOUR;
1107         }
1108
1109         return;
1110 }
1111
1112 void
1113 _EditTimePresenter::SetFocusState(bool isFocused)
1114 {
1115         __isFocused = isFocused;
1116         return;
1117 }
1118
1119 bool
1120 _EditTimePresenter::OnFocusLost(const _Control &source)
1121 {
1122         if (!__isEnterKeyPressed || __focusId == DATETIME_ID_AMPM)
1123         {
1124                 __focusId = DATETIME_ID_NONE;
1125         }
1126         __isFocused = false;
1127         __pEditTime->Invalidate();
1128         return true;
1129 }
1130
1131 void
1132 _EditTimePresenter::OnFocusModeStateChanged(void)
1133 {
1134         __isFocused = false;
1135         __focusId = DATETIME_ID_NONE;
1136         __pEditTime->Invalidate();
1137         return;
1138 }
1139
1140 bool
1141 _EditTimePresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1142 {
1143         if (!__isFocused)
1144         {
1145                 return false;
1146         }
1147         _KeyCode keyCode = keyInfo.GetKeyCode();
1148
1149         switch (keyCode)
1150         {
1151                 case _KEY_RIGHT:
1152                 {
1153                         __isEnterKeyPressed = false;
1154                         if (__focusId == DATETIME_ID_HOUR)
1155                         {
1156                                 __focusId = DATETIME_ID_MINUTE;
1157                         }
1158                         else if (__focusId == DATETIME_ID_MINUTE)
1159                         {
1160                                 if (!Is24HourNotationEnabled())
1161                                 {
1162                                         __focusId = DATETIME_ID_AMPM;
1163                                 }
1164                         }
1165                         else if (__focusId == DATETIME_ID_AMPM)
1166                         {
1167                                 return false;
1168                         }
1169
1170                         __pEditTime->Invalidate();
1171                         break;
1172                 }
1173                 case _KEY_LEFT:
1174                 {
1175                         __isEnterKeyPressed = false;
1176                         if (__focusId == DATETIME_ID_MINUTE)
1177                         {
1178                                 __focusId = DATETIME_ID_HOUR;
1179                         }
1180                         else if (__focusId == DATETIME_ID_AMPM)
1181                         {
1182                                 __focusId = DATETIME_ID_MINUTE;
1183                         }
1184                         else if (__focusId == DATETIME_ID_HOUR)
1185                         {
1186                                 return false;
1187                         }
1188                         __pEditTime->Invalidate();
1189                         break;
1190                 }
1191
1192                 default:
1193                 {
1194                         return false;
1195                 }
1196         }
1197         return true;
1198 }
1199
1200 bool
1201 _EditTimePresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1202 {
1203         if (!__isFocused)
1204         {
1205                 return false;
1206         }
1207         _KeyCode keyCode = keyInfo.GetKeyCode();
1208
1209         if (__isAnimating)
1210         {
1211                 VisualElement *pEditTimeElement = __pEditTime->GetVisualElement();
1212                 result r = GetLastResult();
1213                 SysTryReturn(NID_UI_CTRL, (pEditTimeElement != null), false, r, "[%s] Propagating.", GetErrorMessage(r));
1214                 pEditTimeElement->RemoveAllAnimations();
1215         }
1216
1217         int minValue = -1;
1218         int maxValue = -1;
1219         int displayValue = -1;
1220
1221         _DateTimeId boxId = DATETIME_ID_HOUR;
1222
1223         switch (keyCode)
1224         {
1225                 case _KEY_ENTER:
1226                 {
1227                         __isEnterKeyPressed = true;
1228                         if (__focusId == DATETIME_ID_HOUR)
1229                         {
1230                                 boxId = DATETIME_ID_HOUR;
1231                                 if (__pEditTime->GetDateTimeBar() != null)
1232                                 {
1233                                         if (!Is24HourNotationEnabled())
1234                                         {
1235                                                 if (GetHour() == 0)
1236                                                 {
1237                                                         minValue = DATETIME_HOUR_MIN + 1;
1238                                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1239                                                         displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1240                                                 }
1241                                                 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
1242                                                 {
1243                                                         minValue = DATETIME_HOUR_MIN + 1;
1244                                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1245                                                         displayValue = __pEditTime->GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
1246                                                 }
1247                                                 else
1248                                                 {
1249                                                         minValue = DATETIME_HOUR_MIN + 1;
1250                                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1251                                                         displayValue = __pEditTime->GetHour();
1252                                                 }
1253                                         }
1254                                         else
1255                                         {
1256                                                 minValue = DATETIME_HOUR_MIN;
1257                                                 maxValue = DATETIME_HOUR_MAX;
1258                                                 displayValue = __pEditTime->GetHour();
1259                                         }
1260
1261                                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1262                                         {
1263                                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1264                                         }
1265                                 }
1266                         }
1267                         else if (__focusId == DATETIME_ID_MINUTE)
1268                         {
1269                                 if (__pEditTime->GetDateTimeBar() != null)
1270                                 {
1271                                         minValue = DATETIME_MINUTE_MIN;
1272                                         maxValue = DATETIME_MINUTE_MAX;
1273                                         displayValue = __pEditTime->GetMinute();
1274
1275                                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1276                                         {
1277                                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1278                                         }
1279                                 }
1280                                 boxId = DATETIME_ID_MINUTE;
1281                         }
1282                         else if (__focusId == DATETIME_ID_AMPM)
1283                         {
1284                                 SetAmEnabled(!GetAmEnabled());
1285                                 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1286                                 boxId = DATETIME_ID_AMPM;
1287
1288                                 __pEditTime->Invalidate();
1289                         }
1290
1291                         if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM))
1292                         {
1293                                 FloatRectangle absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1294
1295                                 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1296                                 bounds = GetDisplayAreaBoundsFromHoursStyle(boxId);
1297                                 bounds.x += absoluteBounds.x;
1298
1299                                 __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1300                                 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1301                                 __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1302                                 __pEditTime->GetDateTimeBar()->Open();
1303                                 UpdateLastSelectedValue(boxId, false);
1304                         }
1305                         break;
1306                 }
1307
1308                 default:
1309                 {
1310                         return false;
1311                 }
1312         }
1313         return true;
1314 }
1315
1316 bool
1317 _EditTimePresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1318 {
1319         SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1320
1321         if (&source != __pEditTime)
1322         {
1323                 return false;
1324         }
1325
1326         __touchMoveHandled = false;
1327
1328         FloatRectangle hourBounds(0.0f, 0.0f, 0.0f, 0.0f);
1329         FloatRectangle minuteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1330         FloatRectangle ampmBounds(0.0f, 0.0f, 0.0f, 0.0f);
1331
1332         hourBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1333         minuteBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1334
1335         if (!__24hours)
1336         {
1337                 ampmBounds = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
1338         }
1339
1340         FloatPoint point = touchinfo.GetCurrentPosition();
1341
1342         _DateTimeId boxId = GetBoxIdFromPosition(point);
1343
1344         int minValue = -1;
1345         int maxValue = -1;
1346         int displayValue = -1;
1347
1348         if (boxId == DATETIME_ID_HOUR)
1349         {
1350                 if (__pEditTime->GetDateTimeBar() != null)
1351                 {
1352                         if (!__24hours)
1353                         {
1354                                 if (GetHour() == 0)
1355                                 {
1356                                         minValue = DATETIME_HOUR_MIN + 1;
1357                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1358                                         displayValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1359                                 }
1360                                 else if (GetHour() > DATETIME_HOUR_MAX_FOR_24NOTATION)
1361                                 {
1362                                         minValue = DATETIME_HOUR_MIN + 1;
1363                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1364                                         displayValue = GetHour() - DATETIME_HOUR_MAX_FOR_24NOTATION;
1365                                 }
1366                                 else
1367                                 {
1368                                         minValue = DATETIME_HOUR_MIN + 1;
1369                                         maxValue = DATETIME_HOUR_MAX_FOR_24NOTATION;
1370                                         displayValue = GetHour();
1371                                 }
1372                         }
1373                         else
1374                         {
1375                                 minValue = DATETIME_HOUR_MIN;
1376                                 maxValue = DATETIME_HOUR_MAX;
1377                                 displayValue = GetHour();
1378                         }
1379
1380                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1381                         {
1382                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1383                         }
1384
1385                         __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1386                 }
1387
1388                 __bounds = hourBounds;
1389         }
1390         else if (boxId == DATETIME_ID_MINUTE)
1391         {
1392                 if (__pEditTime->GetDateTimeBar() != null)
1393                 {
1394                         minValue = DATETIME_MINUTE_MIN;
1395                         maxValue = DATETIME_MINUTE_MAX;
1396                         displayValue = GetMinute();
1397
1398                         if (__pEditTime->GetDateTimeBar()->GetItemCount() > 0)
1399                         {
1400                                 __pEditTime->GetDateTimeBar()->RemoveAllItems();
1401                         }
1402
1403                         __pEditTime->GetDateTimeBar()->SetInitialValue(minValue, maxValue, displayValue, boxId);
1404                 }
1405
1406                 __bounds = minuteBounds;
1407         }
1408         else if (boxId == DATETIME_ID_AMPM)
1409         {
1410                 __selectedId = boxId;
1411                 __bounds = ampmBounds;
1412                 Draw();
1413         }
1414         else
1415         {
1416                 __selectedId = DATETIME_ID_NONE;
1417                 return false;
1418         }
1419
1420         __selectedId = boxId;
1421
1422         return true;
1423 }
1424
1425 bool
1426 _EditTimePresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1427 {
1428         SysTryReturn(NID_UI_CTRL, IsTimePickerEnabled() == true, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime instance is disabled.");
1429
1430         if (&source != __pEditTime)
1431         {
1432                 return false;
1433         }
1434
1435         FloatRectangle bounds = __pEditTime->GetBoundsF();
1436
1437         FloatPoint startPoint(0.0f, 0.0f);
1438
1439         float titleHeight = 0;
1440         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, __pEditTime->GetOrientation(), titleHeight);
1441
1442         __bounds = FloatRectangle(0.0f, titleHeight, bounds.width, bounds.height);
1443
1444         FloatPoint point = touchinfo.GetCurrentPosition();
1445
1446         _DateTimeId boxId = GetBoxIdFromPosition(point);
1447
1448         if ((boxId == GetLastSelectedId() && boxId != DATETIME_ID_AMPM) || boxId != __selectedId || boxId == DATETIME_ID_NONE)
1449         {
1450                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1451                 {
1452                         __pEditTime->GetDateTimeBar()->CloseDateTimeBar();
1453                 }
1454
1455                 __selectedId = DATETIME_ID_NONE;
1456                 SetLastSelectedId(__selectedId);
1457
1458                 Draw();
1459
1460                 return true;
1461         }
1462         UpdateLastSelectedValue(__selectedId, true);
1463         if (GetLastSelectedId() == DATETIME_ID_AMPM)
1464         {
1465                 return true;
1466         }
1467
1468         Draw();
1469
1470         if ((__pEditTime->GetDateTimeBar() != null) && (boxId != DATETIME_ID_AMPM) && (GetLastSelectedId() != DATETIME_ID_NONE))
1471         {
1472                 __pEditTime->SetFocused(true);
1473
1474                 FloatRectangle bounds(0.0f, 0.0f, 0.0f, 0.0f);
1475                 bounds = GetDisplayAreaBoundsFromHoursStyle(GetLastSelectedId());
1476                 FloatRectangle absoluteBounds(0.0f, 0.0f, 0.0f, 0.0f);
1477                 absoluteBounds = __pEditTime->GetAbsoluteBoundsF();
1478                 bounds.x += absoluteBounds.x;
1479
1480                 __pEditTime->GetDateTimeBar()->CalculateArrowBounds(bounds);
1481
1482                 if (__pEditTime->GetDateTimeBar()->IsActivated())
1483                 {
1484                         __pEditTime->GetDateTimeBar()->RemoveAllAnimations();
1485                         __pEditTime->GetDateTimeBar()->Close();
1486                         __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1487                         __pEditTime->GetDateTimeBar()->Open();
1488                 }
1489                 else
1490                 {
1491                         __pEditTime->GetDateTimeBar()->SetVisibleState(true);
1492                         __pEditTime->GetDateTimeBar()->Open();
1493                 }
1494         }
1495
1496         __selectedId = DATETIME_ID_NONE;
1497         return true;
1498 }
1499
1500 void
1501 _EditTimePresenter::UpdateLastSelectedValue(_DateTimeId boxId, bool isTouchPressed)
1502 {
1503         __selectedId = boxId;
1504         SetLastSelectedId(boxId);
1505
1506         __lastSelectedValue = "";
1507
1508         if (GetLastSelectedId() == DATETIME_ID_HOUR)
1509         {
1510                 int hours = GetHour();
1511
1512                 if (!Is24HourNotationEnabled())
1513                 {
1514                         hours = hours % 12;
1515
1516                         if (hours == DATETIME_HOUR_MIN)
1517                         {
1518                                 hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1519                         }
1520                 }
1521                 __lastSelectedValue.Format(10, L"%02d", hours);
1522                 if (isTouchPressed)
1523                 {
1524                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditTime);
1525                 }
1526         }
1527         else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1528         {
1529                 __lastSelectedValue.Format(10, L"%02d", GetMinute());
1530                 if (isTouchPressed)
1531                 {
1532                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditTime);
1533                 }
1534         }
1535         else if (GetLastSelectedId() == DATETIME_ID_AMPM)
1536         {
1537                 SetAmEnabled(!GetAmEnabled());
1538                 __pEditTime->FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1539                 if (isTouchPressed)
1540                 {
1541                         __pEditTime->UpdateAccessibilityElement();
1542                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pEditTime);
1543                 }
1544                 __selectedId = DATETIME_ID_NONE;
1545
1546                 if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1547                 {
1548                         __pEditTime->GetDateTimeBar()->SetVisibleState(false);
1549                         __pEditTime->GetDateTimeBar()->Close();
1550                 }
1551         }
1552
1553         __selectedId = DATETIME_ID_NONE;
1554         __pEditTime->Invalidate();
1555         return;
1556 }
1557
1558 bool
1559 _EditTimePresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1560 {
1561         if (&source != __pEditTime)
1562         {
1563                 return false;
1564         }
1565
1566         __selectedId = DATETIME_ID_NONE;
1567
1568         return true;
1569 }
1570
1571 bool
1572 _EditTimePresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1573 {
1574         if (&source != __pEditTime)
1575         {
1576                 return false;
1577         }
1578
1579         if (__pEditTime->GetDateTimeBar() != null && __pEditTime->GetDateTimeBar()->IsActivated())
1580         {
1581                 return true;
1582         }
1583
1584         return false;
1585 }
1586
1587 void
1588 _EditTimePresenter::OnTouchMoveHandled(const _Control& control)
1589 {
1590         __touchMoveHandled = true;
1591         __selectedId = DATETIME_ID_NONE;
1592
1593         return;
1594 }
1595
1596 void
1597 _EditTimePresenter::OnFontChanged(Font* pFont)
1598 {
1599         __pFont = pFont;
1600
1601         if (__pEditTime->GetDateTimeBar() != null)
1602         {
1603                 __pEditTime->GetDateTimeBar()->SetFont(*pFont);
1604         }
1605
1606         return;
1607 }
1608
1609 void
1610 _EditTimePresenter::OnFontInfoRequested(unsigned long& style, float& size)
1611 {
1612         style = FONT_STYLE_PLAIN;
1613         size = __timeFontSize;
1614
1615         return;
1616 }
1617
1618 result
1619 _EditTimePresenter::Initialize(void)
1620 {
1621         result r = E_SUCCESS;
1622
1623         float titleTimeMargin = 0;
1624         float timeHeight = 0;
1625         float editTimeHeight = 0;
1626
1627         GET_SHAPE_CONFIG(EDITTIME::TEXT_FONT_SIZE, __pEditTime->GetOrientation(), __titleFontSize);
1628         GET_SHAPE_CONFIG(EDITTIME::TIME_FONT_SIZE, __pEditTime->GetOrientation(), __timeFontSize);
1629         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, __pEditTime->GetOrientation(), titleTimeMargin);
1630         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, __pEditTime->GetOrientation(), timeHeight);
1631         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, __pEditTime->GetOrientation(), editTimeHeight);
1632
1633         if (__pEditTime->GetBoundsF().height > editTimeHeight)
1634         {
1635                 editTimeHeight = __pEditTime->GetBoundsF().height;
1636         }
1637
1638         if (!__title.IsEmpty())
1639         {
1640                 SetTitleBounds();
1641                 if (!__isEditTimeInitialized)
1642                 {
1643                         r = InitializeTitleObject();
1644                         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1645                 }
1646
1647                 __titleBounds.y = (editTimeHeight - (__titleBounds.height + titleTimeMargin + timeHeight)) / 2.0f;
1648                 __titleObject.SetBounds(__titleBounds);
1649         }
1650
1651         __pFont = __pEditTime->GetFallbackFont();
1652         r = GetLastResult();
1653         SysTryReturn(NID_UI_CTRL, __pFont != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1654
1655         if (!__isEditTimeInitialized)
1656         {
1657                 r = LoadResource();
1658                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1659
1660                 r = InitializeTextObject();
1661                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1662         }
1663
1664         __isEditTimeInitialized = true;
1665
1666         UpdateTimeFormat();
1667         return r;
1668 }
1669
1670 void
1671 _EditTimePresenter::UpdateTimeFormat(void)
1672 {
1673         if (!__is24hoursSet)
1674         {
1675                 String key(L"http://tizen.org/setting/locale.time.format.24hour");
1676                 SettingInfo::GetValue(key , __24hours);
1677         }
1678
1679         return;
1680 }
1681
1682 void
1683 _EditTimePresenter::Animate(void)
1684 {
1685         SysTryReturnVoidResult(NID_UI_CTRL, !__isAnimating, E_SUCCESS, "Rolling animation is in progress.");
1686         SysAssertf((__pFont != null), "Font instance must not be null.");
1687
1688         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1689
1690         result r = E_SUCCESS;
1691         FloatRectangle rect;
1692         String hourString;
1693         String minuteString;
1694         String newValue;
1695         TextSimple* pOldSimpleText = null;
1696         TextSimple* pNewSimpleText = null;
1697         bool isCustomBitmap = false;
1698
1699         _DateTimeUtils dateTimeUtils;
1700         int hours = GetHour();
1701         if (!Is24HourNotationEnabled())
1702         {
1703                 hours = hours % 12;
1704
1705                 if (hours == DATETIME_HOUR_MIN)
1706                 {
1707                         hours = hours + DATETIME_HOUR_MAX_FOR_24NOTATION;
1708                 }
1709         }
1710         hourString.Format(10, L"%02d", hours);
1711         minuteString.Format(10, L"%02d", GetMinute());
1712
1713         if (GetLastSelectedId() == DATETIME_ID_HOUR)
1714         {
1715                 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(hourString) == false), E_SUCCESS, "[E_SUCCESS] Hour string matched.");
1716
1717                 newValue = hourString;
1718                 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
1719         }
1720         else if (GetLastSelectedId() == DATETIME_ID_MINUTE)
1721         {
1722                 SysTryReturnVoidResult(NID_UI_CTRL, (__lastSelectedValue.Equals(minuteString) == false), E_SUCCESS, "[E_SUCCESS] Minute string matched.");
1723
1724                 newValue = minuteString;
1725                 rect = GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
1726         }
1727
1728         FloatDimension newTextDim;
1729         FloatDimension oldTextDim;
1730         FloatPoint textPoint;
1731         VisualElement* pNewVisualElement = null;
1732         VisualElement* pOldVisualElement = null;
1733         VisualElement* pEditTimeElement = null;
1734         VisualElementPropertyAnimation* pNewBoundsAnimation = null;
1735         VisualElementPropertyAnimation* pOldBoundsAnimation = null;
1736         Canvas *pCanvas = null;
1737         Canvas *pContentCanvas = null;
1738         Color contentBgColor;
1739         Color textNormalColor;
1740         Color textPressedColor;
1741         float contentTextMargin;
1742
1743         GET_COLOR_CONFIG(EDITTIME::CONTENT_BG_PRESSED, contentBgColor);
1744         GET_COLOR_CONFIG(EDITTIME::TEXT_PRESSED, textPressedColor);
1745         GET_SHAPE_CONFIG(EDITDATE::CONTENT_TEXT_MARGIN, __pEditTime->GetOrientation(), contentTextMargin);
1746
1747         __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
1748         __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
1749
1750         if (newTextDim.width > oldTextDim.width)
1751         {
1752                 textPoint.x = (rect.width - newTextDim.width) / 2.0f;
1753         }
1754         else
1755         {
1756                 textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
1757         }
1758
1759         SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditTime->GetBounds().width), E_SUCCESS, "Rolling animation cann't be played.");
1760
1761         __isAnimating = true;
1762
1763         __pContentProvider = new (std::nothrow) VisualElement();
1764         SysTryReturnVoidResult(NID_UI_CTRL, (__pContentProvider != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1765
1766         r = __pContentProvider->Construct();
1767         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1768
1769         __pContentProvider->SetShowState(true);
1770         __pContentProvider->SetClipChildrenEnabled(true);
1771         __pContentProvider->SetImplicitAnimationEnabled(false);
1772
1773         pEditTimeElement = __pEditTime->GetVisualElement();
1774         r = GetLastResult();
1775         SysTryCatch(NID_UI_CTRL, (pEditTimeElement != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1776
1777         pNewVisualElement = new (std::nothrow) VisualElement();
1778         SysTryCatch(NID_UI_CTRL, (pNewVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1779
1780         r = pNewVisualElement->Construct();
1781         if (r != E_SUCCESS)
1782         {
1783                 pNewVisualElement->Destroy();
1784                 pNewVisualElement = null;
1785         }
1786         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1787
1788         pNewVisualElement->SetShowState(true);
1789
1790         pOldVisualElement = new (std::nothrow) VisualElement();
1791         if (pOldVisualElement == null)
1792         {
1793                 pNewVisualElement->Destroy();
1794                 pNewVisualElement = null;
1795         }
1796         SysTryCatch(NID_UI_CTRL, (pOldVisualElement != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1797
1798         r = pOldVisualElement->Construct();
1799         if (r != E_SUCCESS)
1800         {
1801                 pNewVisualElement->Destroy();
1802                 pOldVisualElement->Destroy();
1803                 pNewVisualElement = null;
1804                 pOldVisualElement = null;
1805         }
1806         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1807
1808         pOldVisualElement->SetShowState(true);
1809
1810         __pContentProvider->SetBounds(FloatRectangle((rect.x + contentTextMargin), (rect.y + (contentTextMargin * 2.0f)), (rect.width - (contentTextMargin * 2.0f)), (rect.height - (contentTextMargin * 4.0f))));
1811
1812         pNewVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1813         pOldVisualElement->SetBounds(FloatRectangle(0, 0, __pContentProvider->GetBounds().width, __pContentProvider->GetBounds().height));
1814
1815         pContentCanvas = pEditTimeElement->GetCanvasN(__pContentProvider->GetBounds());
1816         r = GetLastResult();
1817         SysTryCatch(NID_UI_CTRL, (pContentCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1818         pContentCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1819         pContentCanvas->Clear();
1820
1821         pCanvas = pEditTimeElement->GetCanvasN(rect);
1822         r = GetLastResult();
1823         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1824         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1825         pCanvas->Clear();
1826         rect.x = 0.0f;
1827         rect.y = 0.0f;
1828         r = DrawResourceBitmap(*pCanvas, rect, __pContentBgPressedColorReplacementBitmap);
1829         isCustomBitmap = IS_CUSTOM_BITMAP(EDITTIME::CONTENT_BG_PRESSED);
1830
1831         if (!isCustomBitmap)
1832         {
1833                 result res = DrawResourceBitmap(*pCanvas, rect, __pContentBgEffectPressedBitmap);
1834
1835                 if (res != E_SUCCESS)
1836                 {
1837                         SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(res));
1838                 }
1839         }
1840
1841         delete pCanvas;
1842         pCanvas = null;
1843
1844         if (r != E_SUCCESS)
1845         {
1846                 pContentCanvas->SetBackgroundColor(contentBgColor);
1847                 pContentCanvas->Clear();
1848         }
1849
1850         delete pContentCanvas;
1851         pContentCanvas = null;
1852
1853         pEditTimeElement->AttachChild(*__pContentProvider);
1854
1855         __pContentProvider->AttachChild(*pOldVisualElement);
1856         __pContentProvider->AttachChild(*pNewVisualElement);
1857
1858         pNewBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1859         SysTryCatch(NID_UI_CTRL, (pNewBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1860
1861         pNewBoundsAnimation->SetDuration(300);
1862         pNewBoundsAnimation->SetPropertyName("bounds.position");
1863         pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, oldTextDim.height)));
1864         pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x, 0.0f)));
1865
1866         pOldBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1867         SysTryCatch(NID_UI_CTRL, (pOldBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1868
1869         pOldBoundsAnimation->SetDuration(300);
1870         pOldBoundsAnimation->SetPropertyName("bounds.position");
1871         pOldBoundsAnimation->SetStartValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, 0.0f)));
1872         pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x, oldTextDim.height * -1.0f)));
1873
1874         pOldSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__lastSelectedValue.GetPointer())), __lastSelectedValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1875         SysTryCatch(NID_UI_CTRL, (pOldSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1876
1877         pCanvas = pOldVisualElement->GetCanvasN();
1878         r = GetLastResult();
1879         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1880
1881         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1882         pCanvas->Clear();
1883         pCanvas->SetForegroundColor(textPressedColor);
1884
1885         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1886         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1887         __textObject.RemoveAll();
1888         __textObject.AppendElement(*pOldSimpleText);
1889
1890         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1891         __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1892         __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1893         __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1894
1895         delete pCanvas;
1896         pCanvas = null;
1897
1898         pNewSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(newValue.GetPointer())), newValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1899         SysTryCatch(NID_UI_CTRL, (pNewSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1900
1901         pCanvas = pNewVisualElement->GetCanvasN();
1902         r = GetLastResult();
1903         SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
1904
1905         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1906         pCanvas->Clear();
1907         pCanvas->SetForegroundColor(textPressedColor);
1908
1909         (_FontImpl::GetInstance(*__pFont))->SetSize(__timeFontSize);
1910         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
1911         __textObject.RemoveAll();
1912         __textObject.AppendElement(*pNewSimpleText);
1913
1914         __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
1915         __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
1916         __textObject.SetBounds(FloatRectangle(0, 0, pCanvas->GetBounds().width, pCanvas->GetBounds().height));
1917         __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
1918
1919         delete pCanvas;
1920         pCanvas = null;
1921
1922         pOldVisualElement->SetImplicitAnimationEnabled(false);
1923         pNewVisualElement->SetImplicitAnimationEnabled(false);
1924
1925         AnimationTransaction::Begin(__transactionId);
1926         pOldVisualElement->AddAnimation(*pOldBoundsAnimation);
1927         pNewVisualElement->AddAnimation(*pNewBoundsAnimation);
1928         AnimationTransaction::SetCurrentTransactionEventListener(__pEditTime);
1929         AnimationTransaction::Commit();
1930
1931         delete pOldBoundsAnimation;
1932         delete pNewBoundsAnimation;
1933
1934         return;
1935
1936 CATCH:
1937         __isAnimating = false;
1938         __pContentProvider->Destroy();
1939         __pContentProvider = null;
1940
1941         delete pNewBoundsAnimation;
1942         pNewBoundsAnimation = null;
1943
1944         delete pOldBoundsAnimation;
1945         pOldBoundsAnimation = null;
1946
1947         delete pOldSimpleText;
1948         pOldSimpleText = null;
1949
1950         delete pNewSimpleText;
1951         pNewSimpleText = null;
1952
1953         delete pContentCanvas;
1954         pContentCanvas = null;
1955
1956         return;
1957 }
1958
1959 void
1960 _EditTimePresenter::EndTransaction(void)
1961 {
1962         result r = E_SUCCESS;
1963
1964         __isAnimating = false;
1965         VisualElement* pEditTimeElement = __pEditTime->GetVisualElement();
1966         r = GetLastResult();
1967         SysTryReturnVoidResult(NID_UI_CTRL, (pEditTimeElement != null), r, "[%s] Propagating.", GetErrorMessage(r));
1968
1969         if (__pContentProvider != null)
1970         {
1971                 pEditTimeElement->DetachChild(*__pContentProvider);
1972                 __pContentProvider->Destroy();
1973                 __pContentProvider = null;
1974
1975         }
1976
1977         Draw();
1978         __transactionId = 0;
1979         return;
1980 }
1981 }}} // Tizen::Ui::Controls