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