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