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