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