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