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