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