Merging EditDateTime & DateTimePicker Changes from RSA-master to RSA-tizen2.1
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_EditDate.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_EditDate.cpp
20  * @brief               This is the implementation file for the _EditDate class.
21  */
22
23 #include <FSysSettingInfo.h>
24 #include "FUi_AccessibilityContainer.h"
25 #include "FUi_AccessibilityElement.h"
26 #include "FUi_ResourceManager.h"
27 #include "FUiAnim_VisualElement.h"
28 #include "FUiCtrl_EditDate.h"
29 #include "FUiCtrl_EditDatePresenter.h"
30 #include "FUiCtrl_Form.h"
31 #include "FUiCtrl_Frame.h"
32 #include "FUiCtrl_DateTimeUtils.h"
33 #include "FUi_CoordinateSystemUtils.h"
34
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Ui;
39 using namespace Tizen::System;
40
41 namespace Tizen { namespace Ui { namespace Controls
42 {
43
44 IMPLEMENT_PROPERTY(_EditDate);
45
46 _EditDate::_EditDate(void)
47         : __pEditDatePresenter(null)
48         , __pDateChangeEvent(null)
49         , __pDateTimeBar(null)
50         , __absoluteBounds(FloatRectangle())
51         , __previousSize(0.0f, 0.0f)
52         , __title()
53         , __pAccessibilityEditDateElement(null)
54         , __pAccessibilityYearElement(null)
55         , __pAccessibilityMonthElement(null)
56         , __pAccessibilityDayElement(null)
57         , __isCalledBoundsChanged(false)
58         , __isXmlBoundsExist(false)
59 {
60 }
61
62 _EditDate::~_EditDate(void)
63 {
64         SettingInfo::RemoveSettingEventListener(*this);
65
66         delete __pDateTimeBar;
67         __pDateTimeBar = null;
68
69         delete __pEditDatePresenter;
70         __pEditDatePresenter = null;
71
72         if (__pDateChangeEvent != null)
73         {
74                 delete __pDateChangeEvent;
75                 __pDateChangeEvent = null;
76         }
77
78         if (__pAccessibilityEditDateElement)
79         {
80                 __pAccessibilityEditDateElement->Activate(false);
81                 __pAccessibilityEditDateElement = null;
82         }
83         if (__pAccessibilityYearElement)
84         {
85                 __pAccessibilityYearElement->Activate(false);
86                 __pAccessibilityYearElement = null;
87         }
88         if (__pAccessibilityMonthElement)
89         {
90                 __pAccessibilityMonthElement->Activate(false);
91                 __pAccessibilityMonthElement = null;
92         }
93         if (__pAccessibilityDayElement)
94         {
95                 __pAccessibilityDayElement->Activate(false);
96                 __pAccessibilityDayElement = null;
97         }
98 }
99
100 _EditDate*
101 _EditDate::CreateEditDateN(const String& title)
102 {
103         result r = E_SUCCESS;
104
105         _AccessibilityContainer* pContainer = null;
106
107         _EditDate* pEditDate = new (std::nothrow) _EditDate;
108         SysTryReturn(NID_UI_CTRL, pEditDate, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
109
110         pEditDate->GetVisualElement()->SetSurfaceOpaque(false);
111
112         pEditDate->__pEditDatePresenter = _EditDatePresenter::CreateInstanceN(*pEditDate, title);
113
114         r = pEditDate->CreateDateTimeBar();
115         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
116
117         pEditDate->__pEditDatePresenter->Initialize();
118         r = GetLastResult();
119         SysTryCatch(NID_UI_CTRL, pEditDate->__pEditDatePresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
120
121         pEditDate->__pEditDatePresenter->SetCurrentDate();
122
123         if (title.IsEmpty() != true)
124         {
125                 pEditDate->__title = title;
126         }
127
128         pContainer = pEditDate->GetAccessibilityContainer();
129
130         if (pContainer)
131         {
132                 pContainer->Activate(true);
133                 pEditDate->CreateAccessibilityElement();
134         }
135
136         pEditDate->AcquireHandle();
137         pEditDate->SetTouchPressThreshold(_TOUCH_PRESS_THRESHOLD_INSENSITIVE);
138
139         return pEditDate;
140
141 CATCH:
142         delete pEditDate;
143         return null;
144 }
145
146 result
147 _EditDate::CreateDateTimeBar(void)
148 {
149         result r = E_SUCCESS;
150
151         __pDateTimeBar = _DateTimeBar::CreateDateTimeBarN(*this);
152         r = GetLastResult();
153         SysTryReturn(NID_UI_CTRL, (__pDateTimeBar != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155         r = __pDateTimeBar->AddActionEventListener(*this);
156         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
157
158         r = __pDateTimeBar->AddDateTimeChangeEventListener(*this);
159         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
160
161         r = SettingInfo::AddSettingEventListener(*this);
162         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
163
164         GET_SHAPE_CONFIG(EDITDATE::WIDTH, GetOrientation(), __previousSize.width);
165         GET_SHAPE_CONFIG(EDITDATE::HEIGHT, GetOrientation(), __previousSize.height);
166
167         return r;
168
169 CATCH:
170         delete __pDateTimeBar;
171         return r;
172 }
173
174 result
175 _EditDate::AddDateChangeEventListener(const _IDateTimeChangeEventListener& listener)
176 {
177         if (__pDateChangeEvent == null)
178         {
179                 __pDateChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*this);
180                 SysTryReturn(NID_UI_CTRL, (__pDateChangeEvent != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
181                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
182         }
183
184         result r = __pDateChangeEvent->AddListener(listener);
185         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
186
187         return E_SUCCESS;
188 }
189
190 result
191 _EditDate::RemoveDateChangeEventListener(const _IDateTimeChangeEventListener& listener)
192 {
193         result r = E_OBJ_NOT_FOUND;
194
195         if (__pDateChangeEvent)
196         {
197                 r = __pDateChangeEvent->RemoveListener(listener);
198         }
199
200         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
201
202         return E_SUCCESS;
203 }
204
205 void
206 _EditDate::SetDate(const DateTime& date)
207 {
208         SetProperty("date", Variant(date));
209         return;
210 }
211
212 result
213 _EditDate::SetPropertyDate(const Variant& date)
214 {
215         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
216                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
217
218         __pEditDatePresenter->SetDate(date.ToDateTime());
219
220         UpdateAccessibilityElement();
221         return E_SUCCESS;
222 }
223
224 DateTime
225 _EditDate::GetDate(void) const
226 {
227         Variant date = GetProperty("date");
228
229         return date.ToDateTime();
230 }
231
232 Variant
233 _EditDate::GetPropertyDate(void) const
234 {
235         DateTime date;
236
237         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
238                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
239
240         date = __pEditDatePresenter->GetDate();
241
242         return Variant(date);
243 }
244
245 result
246 _EditDate::SetDay(int day)
247 {
248         result r = E_SUCCESS;
249
250         SetProperty("day", Variant(day));
251
252         r = GetLastResult();
253
254         return r;
255 }
256
257 result
258 _EditDate::SetPropertyDay(const Variant& day)
259 {
260         result r = E_SUCCESS;
261
262         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
263                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
264
265         r = __pEditDatePresenter->SetDay(day.ToInt());
266
267         if (r == E_SUCCESS)
268         {
269                 UpdateAccessibilityElement();
270         }
271
272         return r;
273 }
274
275 int
276 _EditDate::GetDay(void) const
277 {
278         Variant day = GetProperty("day");
279
280         return day.ToInt();
281 }
282
283 Variant
284 _EditDate::GetPropertyDay(void) const
285 {
286         int day = -1;
287
288         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
289                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
290
291         day = __pEditDatePresenter->GetDay();
292
293         return Variant(day);
294 }
295
296 result
297 _EditDate::SetMonth(int month)
298 {
299         result r = E_SUCCESS;
300
301         SetProperty("month", Variant(month));
302
303         r = GetLastResult();
304
305         return r;
306 }
307
308 result
309 _EditDate::SetPropertyMonth(const Variant& month)
310 {
311         result r = E_SUCCESS;
312
313         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
314                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
315
316         int day;
317         int maxValue = -1;
318
319         _DateTimeUtils dateTimeUtils;
320
321         maxValue = dateTimeUtils.CalculateMaxDay(GetYear(), month.ToInt());
322         day = __pEditDatePresenter->GetDay();
323
324         if (day > maxValue)
325         {
326                 __pEditDatePresenter->SetDay(maxValue);
327         }
328
329         r = __pEditDatePresenter->SetMonth(month.ToInt());
330
331         if (r == E_SUCCESS)
332         {
333                 UpdateAccessibilityElement();
334         }
335
336         return r;
337 }
338
339 int
340 _EditDate::GetMonth(void) const
341 {
342         Variant month = GetProperty("month");
343
344         return month.ToInt();
345 }
346
347 Variant
348 _EditDate::GetPropertyMonth(void) const
349 {
350         int month = -1;
351
352         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
353                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
354
355         month = __pEditDatePresenter->GetMonth();
356
357         return Variant(month);
358 }
359
360 result
361 _EditDate::SetYear(int year)
362 {
363         result r = E_SUCCESS;
364
365         SetProperty("year", Variant(year));
366
367         r = GetLastResult();
368
369         return r;
370 }
371
372 result
373 _EditDate::SetPropertyYear(const Variant& year)
374 {
375         result r = E_SUCCESS;
376
377         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
378                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
379
380         int day;
381         int maxValue = -1;
382
383         _DateTimeUtils dateTimeUtils;
384
385         maxValue = dateTimeUtils.CalculateMaxDay(year.ToInt(), GetMonth());
386         day = __pEditDatePresenter->GetDay();
387
388         if (day > maxValue)
389         {
390                 __pEditDatePresenter->SetDay(maxValue);
391         }
392
393         r = __pEditDatePresenter->SetYear(year.ToInt());
394
395         if (r == E_SUCCESS)
396         {
397                 UpdateAccessibilityElement();
398         }
399
400         return r;
401 }
402
403 int
404 _EditDate::GetYear(void) const
405 {
406         Variant year = GetProperty("year");
407
408         return year.ToInt();
409 }
410
411 Variant
412 _EditDate::GetPropertyYear(void) const
413 {
414         int year = -1;
415
416         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
417                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
418
419         year = __pEditDatePresenter->GetYear();
420
421         return Variant(year);
422 }
423
424 void
425 _EditDate::SetCurrentDate(void)
426 {
427         SysTryReturnVoidResult(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM,
428                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
429
430         __pEditDatePresenter->SetCurrentDate();
431
432         UpdateAccessibilityElement();
433
434         return;
435 }
436
437 void
438 _EditDate::SetDatePickerEnabled(bool enable)
439 {
440         SetProperty("datePickerEnabled", Variant(enable));
441         return;
442 }
443
444 result
445 _EditDate::SetPropertyDatePickerEnabled(const Variant& enable)
446 {
447         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
448                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
449
450         __pEditDatePresenter->SetDatePickerEnabled(enable.ToBool());
451
452         return E_SUCCESS;
453 }
454
455 bool
456 _EditDate::IsDatePickerEnabled(void) const
457 {
458         Variant enable = GetProperty("datePickerEnabled");
459
460         return enable.ToBool();
461 }
462
463 Variant
464 _EditDate::GetPropertyDatePickerEnabled(void) const
465 {
466         bool enable = false;
467
468         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
469                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
470
471         enable = __pEditDatePresenter->IsDatePickerEnabled();
472
473         return Variant(enable);
474 }
475
476 result
477 _EditDate::SetYearRange(int minYear, int maxYear)
478 {
479         result r = E_SUCCESS;
480
481         SysTryReturn(NID_UI_CTRL, (maxYear >= DATETIME_YEAR_MIN && maxYear <= DATETIME_YEAR_MAX), E_INVALID_ARG, E_INVALID_ARG,
482                         "[E_INVALID_ARG] maxYear(%d) must be greater than or equal to %d and less than or equal to %d.",
483                         maxYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
484
485         SysTryReturn(NID_UI_CTRL, (minYear >= DATETIME_YEAR_MIN && minYear <= DATETIME_YEAR_MAX), E_INVALID_ARG, E_INVALID_ARG,
486                         "[E_INVALID_ARG] minYear(%d) must be greater than or equal to %d and less than or equal to %d.",
487                         minYear, DATETIME_YEAR_MIN, DATETIME_YEAR_MAX);
488
489         SysTryReturn(NID_UI_CTRL, (maxYear >= minYear), E_INVALID_ARG, E_INVALID_ARG,
490                         "[E_INVALID_ARG] maxYear(%d) must be greater than or equal to minYear(%d).", maxYear, minYear);
491
492         Variant oldMinYear = GetPropertyMinYearRange();
493
494         r = SetPropertyMinYearRange(Variant(minYear));
495         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
496
497         r = SetPropertyMaxYearRange(Variant(maxYear));
498
499         if (IsFailed(r))
500         {
501                 SetPropertyMinYearRange(oldMinYear);
502         }
503
504         return r;
505 }
506
507 result
508 _EditDate::SetMinYearRange(int minYear)
509 {
510         result r = E_SUCCESS;
511
512         r = SetProperty("minYearRange", Variant(minYear));
513
514         return r;
515 }
516
517 result
518 _EditDate::SetMaxYearRange(int maxYear)
519 {
520         result r = E_SUCCESS;
521
522         r = SetProperty("maxYearRange", Variant(maxYear));
523
524         return r;
525 }
526
527 result
528 _EditDate::SetPropertyMinYearRange(const Variant& minYear)
529 {
530         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
531                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
532
533         return __pEditDatePresenter->SetMinYear(minYear.ToInt());
534 }
535
536 result
537 _EditDate::SetPropertyMaxYearRange(const Variant& maxYear)
538 {
539         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), E_SYSTEM, E_SYSTEM,
540                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
541
542         return __pEditDatePresenter->SetMaxYear(maxYear.ToInt());
543 }
544
545 result
546 _EditDate::GetYearRange(int& minYear, int& maxYear) const
547 {
548         result r = E_SUCCESS;
549
550         minYear = GetMinYearRange();
551         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
552         maxYear = GetMaxYearRange();
553         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
554
555         return r;
556 }
557
558 int
559 _EditDate::GetMinYearRange(void) const
560 {
561         Variant minYear = GetProperty("minYearRange");
562
563         return minYear.ToInt();
564 }
565
566 int
567 _EditDate::GetMaxYearRange(void) const
568 {
569         Variant maxYear = GetProperty("maxYearRange");
570
571         return maxYear.ToInt();
572 }
573
574 Variant
575 _EditDate::GetPropertyMinYearRange(void) const
576 {
577         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
578                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
579
580         int minYear = 0;
581
582         minYear = __pEditDatePresenter->GetMinYear();
583
584         return Variant(minYear);
585 }
586
587 Variant
588 _EditDate::GetPropertyMaxYearRange(void) const
589 {
590         SysTryReturn(NID_UI_CTRL, (__pEditDatePresenter != null), Variant(), E_SYSTEM,
591                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
592
593         int maxYear = 0;
594
595         maxYear = __pEditDatePresenter->GetMaxYear();
596
597         return Variant(maxYear);
598 }
599
600 result
601 _EditDate::CalculateDateTimeBarPosition(void)
602 {
603         result r = E_SUCCESS;
604
605         float dateTimeBarHeight = 0.0f;
606         float arrowHeight = 0.0f;
607         float dateHeight = 0.0f;
608         float dateBarMargin = 0.0f;
609         float textHeight = 0.0f;
610         float titleDateMargin = 0.0f;
611         float bottomPosition = 0.0f;
612         float dateY = 0.0f;
613
614         FloatRectangle absoluteBounds;
615         FloatRectangle frameBounds;
616         FloatRectangle parentWindowBounds;
617         FloatRectangle titleBounds;
618
619         _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
620         SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM, E_SYSTEM,
621                         "[E_SYSTEM] A system error has occurred. Failed to get frame instance.");
622
623         absoluteBounds = GetAbsoluteBoundsF();
624         frameBounds = pFrame->GetAbsoluteBoundsF();
625         parentWindowBounds = GetParentWindowBounds();
626         titleBounds = __pEditDatePresenter->GetTitleBounds();
627
628         GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), dateTimeBarHeight);
629         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, GetOrientation(), arrowHeight);
630         GET_SHAPE_CONFIG(EDITDATE::DATE_HEIGHT, GetOrientation(), dateHeight);
631         GET_SHAPE_CONFIG(EDITDATE::DATE_BAR_MARGIN, GetOrientation(), dateBarMargin);
632         GET_SHAPE_CONFIG(EDITDATE::TITLE_HEIGHT, GetOrientation(), textHeight);
633         GET_SHAPE_CONFIG(EDITDATE::TITLE_DATE_MARGIN, GetOrientation(), titleDateMargin);
634
635         if (!__title.IsEmpty()) //with title
636         {
637                 dateY = titleBounds.y + textHeight + titleDateMargin ;
638         }
639         else //without title
640         {
641                 dateY = (absoluteBounds.height - dateHeight) / 2.0f ;
642         }
643
644         bottomPosition = absoluteBounds.y + dateY + dateHeight + dateBarMargin + arrowHeight + dateTimeBarHeight;
645
646         GetDateTimeBar()->SetParentWindowBounds(parentWindowBounds);
647
648         if (bottomPosition > frameBounds.y + parentWindowBounds.y + parentWindowBounds.height)
649         {
650                 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + dateY - dateBarMargin - arrowHeight), DATETIME_BAR_ALIGN_UP);
651                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
652         }
653         else
654         {
655                 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + dateY + dateHeight + dateBarMargin + arrowHeight), DATETIME_BAR_ALIGN_DOWN);
656                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
657         }
658
659         __absoluteBounds = absoluteBounds;
660
661         return r;
662 }
663
664 void
665 _EditDate::OnDraw(void)
666 {
667         if (GetDateTimeBar() != null)
668         {
669                 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
670
671                 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
672                 {
673                         CalculateDateTimeBarPosition();
674                 }
675         }
676
677         __pEditDatePresenter->Draw();
678         return;
679 }
680
681 void
682 _EditDate::CreateAccessibilityElement(void)
683 {
684         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
685
686         FloatRectangle dayBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY);
687         FloatRectangle monthBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH);
688         FloatRectangle yearBounds = __pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR);
689
690         if (__pAccessibilityEditDateElement == null)
691         {
692                 __pAccessibilityEditDateElement = new _AccessibilityElement(true);
693                 __pAccessibilityEditDateElement->SetBounds(GetClientBoundsF());
694                 __pAccessibilityEditDateElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
695                 __pAccessibilityEditDateElement->SetName("EditDateText");
696                 pContainer->AddElement(*__pAccessibilityEditDateElement);
697         }
698
699         if (__pAccessibilityYearElement == null && __pAccessibilityMonthElement == null && __pAccessibilityDayElement == null)
700         {
701                 String hintText(L"Double tap to edit");
702
703                 __pAccessibilityYearElement = new _AccessibilityElement(true);
704                 __pAccessibilityYearElement->SetBounds(yearBounds);
705                 __pAccessibilityYearElement->SetTrait(ACCESSIBILITY_TRAITS_YEAR);
706                 __pAccessibilityYearElement->SetHint(hintText);
707
708                 __pAccessibilityMonthElement = new _AccessibilityElement(true);
709                 __pAccessibilityMonthElement->SetBounds(monthBounds);
710                 __pAccessibilityMonthElement->SetTrait(ACCESSIBILITY_TRAITS_MONTH);
711                 __pAccessibilityMonthElement->SetHint(hintText);
712
713                 __pAccessibilityDayElement = new _AccessibilityElement(true);
714                 __pAccessibilityDayElement->SetBounds(dayBounds);
715                 __pAccessibilityDayElement->SetTrait(ACCESSIBILITY_TRAITS_DAY);
716                 __pAccessibilityDayElement->SetHint(hintText);
717
718                 _DateTimeUtils dateTimeUtils;
719                 int localeDateFormat =  dateTimeUtils.GetLocaleDateFormat();
720
721                 switch (localeDateFormat)
722                 {
723                 case DATE_FORMAT_DDMMYYYY:
724                         pContainer->AddElement(*__pAccessibilityDayElement);
725                         pContainer->AddElement(*__pAccessibilityMonthElement);
726                         pContainer->AddElement(*__pAccessibilityYearElement);
727                         break;
728                 case DATE_FORMAT_MMDDYYYY:
729                         pContainer->AddElement(*__pAccessibilityMonthElement);
730                         pContainer->AddElement(*__pAccessibilityDayElement);
731                         pContainer->AddElement(*__pAccessibilityYearElement);
732                         break;
733                 case DATE_FORMAT_YYYYMMDD:
734                         pContainer->AddElement(*__pAccessibilityYearElement);
735                         pContainer->AddElement(*__pAccessibilityMonthElement);
736                         pContainer->AddElement(*__pAccessibilityDayElement);
737                         break;
738                 case DATE_FORMAT_YYYYDDMM:
739                         pContainer->AddElement(*__pAccessibilityYearElement);
740                         pContainer->AddElement(*__pAccessibilityDayElement);
741                         pContainer->AddElement(*__pAccessibilityMonthElement);
742                         break;
743                 default:
744                         break;
745                 }
746                 UpdateAccessibilityElement();
747         }
748 }
749
750 void
751 _EditDate::OnBoundsChanged(void)
752 {
753         FloatDimension newSize = GetSizeF();
754
755         if (newSize.width != __previousSize.width || newSize.height != __previousSize.height)
756         {
757                 __isCalledBoundsChanged = true;
758         }
759
760         __pEditDatePresenter->Initialize();
761
762         if (__pAccessibilityEditDateElement)
763         {
764                 __pAccessibilityEditDateElement->SetBounds(GetClientBoundsF());
765         }
766         if (__pAccessibilityYearElement)
767         {
768                 __pAccessibilityYearElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_YEAR));
769         }
770         if (__pAccessibilityMonthElement)
771         {
772                 __pAccessibilityMonthElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_MONTH));
773         }
774         if (__pAccessibilityDayElement)
775         {
776                 __pAccessibilityDayElement->SetBounds(__pEditDatePresenter->GetDateAreaBounds(DATETIME_ID_DAY));
777         }
778
779         return;
780 }
781
782 void
783 _EditDate::OnChangeLayout(_ControlOrientation orientation)
784 {
785         if (!__isCalledBoundsChanged && !__isXmlBoundsExist)
786         {
787                 FloatRectangle bounds = GetBoundsF();
788
789                 GET_SHAPE_CONFIG(EDITDATE::WIDTH, GetOrientation(), bounds.width);
790                 GET_SHAPE_CONFIG(EDITDATE::HEIGHT, GetOrientation(), bounds.height);
791
792                 SetBounds(bounds, false);
793         }
794
795         __pEditDatePresenter->Initialize();
796         __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
797
798         if (GetDateTimeBar() != null)
799         {
800                 GetDateTimeBar()->SetVisibleState(false);
801                 GetDateTimeBar()->Close();
802         }
803
804         return;
805 }
806
807 bool
808 _EditDate::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
809 {
810         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
811
812         if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
813         {
814                 CalculateDateTimeBarPosition();
815         }
816
817         return __pEditDatePresenter->OnTouchPressed(source, touchinfo);
818 }
819
820 bool
821 _EditDate::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
822 {
823         return __pEditDatePresenter->OnTouchReleased(source, touchinfo);
824 }
825
826 bool
827 _EditDate::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
828 {
829         return __pEditDatePresenter->OnTouchCanceled(source, touchinfo);
830 }
831
832 bool
833 _EditDate::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
834 {
835         return __pEditDatePresenter->OnTouchMoved(source, touchinfo);
836 }
837
838 void
839 _EditDate::OnTouchMoveHandled(const _Control& control)
840 {
841         __pEditDatePresenter->OnTouchMoveHandled(control);
842         return;
843 }
844
845 result
846 _EditDate::FireDateChangeEvent(_DateTimeChangeStatus status)
847 {
848         SysTryReturn(NID_UI_CTRL, (__pDateChangeEvent != null), E_INVALID_STATE, E_INVALID_STATE,
849                         "[E_INVALID_STATE] The _DateChangeEvent instance is null.");
850
851         _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
852         SysTryReturn(NID_UI_CTRL, pDateTimeEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
853
854         pDateTimeEventArg->SetDate(GetYear(), GetMonth(), GetDay());
855
856         __pDateChangeEvent->Fire(*pDateTimeEventArg);
857
858         return E_SUCCESS;
859 }
860
861 void
862 _EditDate::OnDateTimeChanged(const _Control& source, int year, int month, int day, int hour, int minute)
863 {
864         __pEditDatePresenter->Animate();
865         __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
866         Invalidate();
867         FireDateChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
868         return;
869 }
870
871 void
872 _EditDate::OnDateTimeChangeCanceled(const _Control& source)
873 {
874         __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
875         Invalidate();
876         FireDateChangeEvent(DATE_INTERNAL_CHANGE_CANCELED);
877         return;
878 }
879
880 void
881 _EditDate::OnActionPerformed(const Ui::_Control& source, int actionId)
882 {
883         _DateTimeId boxId = __pEditDatePresenter->GetLastSelectedId();
884
885         if (boxId == DATETIME_ID_YEAR)
886         {
887                 SetYear(actionId);
888                 AdjustDay(actionId, GetMonth());
889         }
890         else if (boxId == DATETIME_ID_MONTH)
891         {
892                 SetMonth(actionId);
893                 AdjustDay(GetYear(), actionId);
894         }
895         else if (boxId == DATETIME_ID_DAY)
896         {
897                 SetDay(actionId);
898         }
899
900         Invalidate();
901
902         return;
903 }
904
905 void
906 _EditDate::AdjustDay(int year, int month)
907 {
908         _DateTimeUtils dateTimeUtils;
909         int maxValue = dateTimeUtils.CalculateMaxDay(year, month);
910
911         if (GetDay() > maxValue)
912         {
913                 SetDay(maxValue);
914         }
915
916         return;
917 }
918
919 _DateTimeBar*
920 _EditDate::GetDateTimeBar(void) const
921 {
922         return __pDateTimeBar;
923 }
924
925 void
926 _EditDate::OnFontChanged(Font* pFont)
927 {
928     __pEditDatePresenter->OnFontChanged(pFont);
929
930     return;
931 }
932
933 void
934 _EditDate::OnFontInfoRequested(unsigned long& style, float& size)
935 {
936     __pEditDatePresenter->OnFontInfoRequested(style, size);
937
938     return;
939 }
940
941 void
942 _EditDate::OnSettingChanged(String& key)
943 {
944         if (key.Equals(L"http://tizen.org/setting/locale.date.format", false))
945         {
946                 __pEditDatePresenter->Initialize();
947                 __pEditDatePresenter->SetLastSelectedId(DATETIME_ID_NONE);
948
949                 if (GetDateTimeBar() != null)
950                 {
951                         GetDateTimeBar()->SetVisibleState(false);
952                         GetDateTimeBar()->Close();
953                 }
954
955                 Invalidate();
956         }
957
958         return;
959 }
960
961 bool
962 _EditDate::OnKeyPressed(const _Control &source, const _KeyInfo &keyInfo)
963 {
964         _KeyCode keyCode = keyInfo.GetKeyCode();
965
966         switch (keyCode)
967         {
968                 case _KEY_ENTER:
969                 {
970
971                         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
972
973                         if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
974                         {
975                                 CalculateDateTimeBarPosition();
976                         }
977                         break;
978                 }
979                 default:
980                         break;
981
982         }
983
984         return __pEditDatePresenter->OnKeyPressed(source, keyInfo);
985 }
986
987 bool
988 _EditDate::OnFocusGained(const _Control &source)
989 {
990         __pEditDatePresenter->SetFocusedElement();
991         return true;
992 }
993
994 bool
995 _EditDate::OnFocusLost(const _Control &source)
996 {
997         __pEditDatePresenter->OnFocusLost(source);
998         return true;
999 }
1000
1001 void
1002 _EditDate::OnDrawFocus(void)
1003 {
1004         __pEditDatePresenter->SetFocusState(true);
1005         __pEditDatePresenter->DrawFocus();
1006         return;
1007 }
1008
1009 FloatRectangle
1010 _EditDate::GetParentWindowBounds(void) const
1011 {
1012         _Form* pForm = null;
1013         _Window* pwindow = null;
1014         _Control* pControlCore = GetParent();
1015
1016         FloatDimension dateTimeBarSize(0.0f, 0.0f);
1017         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, GetOrientation(), dateTimeBarSize);
1018         FloatRectangle parentWindowBounds(0.0f, 0.0f, dateTimeBarSize.width, dateTimeBarSize.height);
1019
1020         while (true)
1021         {
1022                 if (pControlCore == null)
1023                 {
1024                         SysLog(NID_UI_CTRL,"[E_SYSTEM] Parent window not found.");
1025
1026                         return parentWindowBounds;
1027                 }
1028
1029                 // If the parent is a Frame, then return the Form's bounds.
1030                 pForm = dynamic_cast<_Form*>(pControlCore);
1031                 if (pForm != null)
1032                 {
1033                         parentWindowBounds = pForm->GetBoundsF();
1034                         break;
1035                 }
1036
1037                 pwindow = dynamic_cast<_Window*>(pControlCore);
1038
1039                 if (pwindow != null)
1040                 {
1041                         parentWindowBounds = pwindow->GetBoundsF();
1042                         break;
1043                 }
1044
1045                 pControlCore = pControlCore->GetParent();
1046         }
1047
1048         return parentWindowBounds;
1049 }
1050
1051 void
1052 _EditDate::UpdateAccessibilityElement(void)
1053 {
1054         String string;
1055         String yearString;
1056         String dayString;
1057         String space(L" ");
1058
1059         if (__pAccessibilityEditDateElement == null)
1060         {
1061                 return;
1062         }
1063
1064         if (__title.IsEmpty() == false)
1065         {
1066                 string.Append(__title);
1067                 string.Append(L", ");
1068         }
1069
1070         yearString.Append(GetYear());
1071         dayString.Append(GetDay());
1072         String monthString = GetDateTimeBar()->GetMonthValue(GetMonth()).GetPointer();
1073
1074         _DateTimeUtils dateTimeUtils;
1075         int localeDateFormat =  dateTimeUtils.GetLocaleDateFormat();
1076
1077         switch (localeDateFormat)
1078         {
1079         case DATE_FORMAT_DDMMYYYY:
1080                 string.Append(dayString.GetPointer());
1081                 string.Append(space.GetPointer());
1082                 string.Append(monthString.GetPointer());
1083                 string.Append(space.GetPointer());
1084                 string.Append(yearString.GetPointer());
1085                 break;
1086         case DATE_FORMAT_MMDDYYYY:
1087                 string.Append(monthString.GetPointer());
1088                 string.Append(space.GetPointer());
1089                 string.Append(dayString.GetPointer());
1090                 string.Append(space.GetPointer());
1091                 string.Append(yearString.GetPointer());
1092                 break;
1093         case DATE_FORMAT_YYYYMMDD:
1094                 string.Append(yearString.GetPointer());
1095                 string.Append(space.GetPointer());
1096                 string.Append(monthString.GetPointer());
1097                 string.Append(space.GetPointer());
1098                 string.Append(dayString.GetPointer());
1099                 break;
1100         case DATE_FORMAT_YYYYDDMM:
1101                 string.Append(yearString.GetPointer());
1102                 string.Append(space.GetPointer());
1103                 string.Append(dayString.GetPointer());
1104                 string.Append(space.GetPointer());
1105                 string.Append(monthString.GetPointer());
1106                 break;
1107         default:
1108                 break;
1109         }
1110
1111         __pAccessibilityEditDateElement->SetLabel(string);
1112         __pAccessibilityDayElement->SetLabel(dayString);
1113         __pAccessibilityMonthElement->SetLabel(monthString);
1114         __pAccessibilityYearElement->SetLabel(yearString);
1115         return;
1116 }
1117
1118 void
1119 _EditDate::SetXmlBoundsExist(bool isXmlBoundsExist)
1120 {
1121         __isXmlBoundsExist = isXmlBoundsExist;
1122 }
1123
1124 }}}  // Tizen::Ui::Controls