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