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