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