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