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