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