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