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