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