Merge "N_SE-36611, N_SE-36661 : add virtual specific keycode, DCM-1518 : remove reset...
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_EditTime.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_EditTime.cpp
20  * @brief               This is the implementation file for the _EditTime class.
21  */
22
23 #include <FSysSettingInfo.h>
24 #include "FUi_CoordinateSystemUtils.h"
25 #include "FUi_AccessibilityContainer.h"
26 #include "FUi_AccessibilityElement.h"
27 #include "FUi_ResourceManager.h"
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiCtrl_EditTime.h"
30 #include "FUiCtrl_EditTimePresenter.h"
31 #include "FUiCtrl_Form.h"
32 #include "FUiCtrl_Frame.h"
33 #include "FUiCtrl_DateTimeUtils.h"
34 #include "FUiCtrl_DateTimeDefine.h"
35
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Base;
39 using namespace Tizen::System;
40
41 namespace Tizen { namespace Ui { namespace Controls
42 {
43
44 IMPLEMENT_PROPERTY(_EditTime);
45
46 _EditTime::_EditTime(void)
47         : __pEditTimePresenter(null)
48         , __pTimeChangeEvent(null)
49         , __pDateTimeBar(null)
50         , __absoluteBounds(FloatRectangle())
51         , __previousSize(0.0f, 0.0f)
52         , __title()
53         , __pAccessibilityEditTimeElement(null)
54         , __pAccessibilityHourElement(null)
55         , __pAccessibilityMinuteElement(null)
56         , __pAccessibilityAmPmElement(null)
57         , __isCalledBoundsChanged(false)
58         , __isXmlBoundsExist(false)
59 {
60 }
61
62 _EditTime::~_EditTime(void)
63 {
64         SettingInfo::RemoveSettingEventListener(*this);
65
66         delete __pDateTimeBar;
67         __pDateTimeBar = null;
68
69         delete __pEditTimePresenter;
70         __pEditTimePresenter = null;
71
72         if (__pTimeChangeEvent != null)
73         {
74                 delete __pTimeChangeEvent;
75                 __pTimeChangeEvent = null;
76         }
77
78         if (__pAccessibilityEditTimeElement)
79         {
80                 __pAccessibilityEditTimeElement->Activate(false);
81                 __pAccessibilityEditTimeElement = null;
82         }
83         if (__pAccessibilityHourElement)
84         {
85                 __pAccessibilityHourElement->Activate(false);
86                 __pAccessibilityHourElement = null;
87         }
88         if (__pAccessibilityMinuteElement)
89         {
90                 __pAccessibilityMinuteElement->Activate(false);
91                 __pAccessibilityMinuteElement = null;
92         }
93         if (__pAccessibilityAmPmElement)
94         {
95                 __pAccessibilityAmPmElement->Activate(false);
96                 __pAccessibilityAmPmElement = null;
97         }
98 }
99
100 _EditTime*
101 _EditTime::CreateEditTimeN(const String& title)
102 {
103         result r = E_SUCCESS;
104
105         _AccessibilityContainer* pContainer = null;
106
107         _EditTime* pEditTime = new (std::nothrow) _EditTime;
108         SysTryReturn(NID_UI_CTRL, pEditTime, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
109
110         pEditTime->GetVisualElement()->SetSurfaceOpaque(false);
111
112         pEditTime->__pEditTimePresenter = _EditTimePresenter::CreateInstanceN(*pEditTime, title);
113         r = GetLastResult();
114         SysTryCatch(NID_UI_CTRL, pEditTime->__pEditTimePresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
115
116         r = pEditTime->CreateDateTimeBar();
117         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
118
119         pEditTime->__pEditTimePresenter->Initialize();
120         r = GetLastResult();
121         SysTryCatch(NID_UI_CTRL, pEditTime->__pEditTimePresenter, , r, "[%s] Propagating.", GetErrorMessage(r));
122
123         pEditTime->__pEditTimePresenter->SetCurrentTime();
124
125         if (title.IsEmpty() != true)
126         {
127                 pEditTime->__title = title;
128         }
129
130         pContainer = pEditTime->GetAccessibilityContainer();
131         if (pContainer)
132         {
133                 pContainer->Activate(true);
134                 pEditTime->CreateAccessibilityElement();
135         }
136
137         pEditTime->AcquireHandle();
138
139         return pEditTime;
140
141 CATCH:
142         delete pEditTime;
143         return null;
144 }
145
146 result
147 _EditTime::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(EDITTIME::WIDTH, GetOrientation(), __previousSize.width);
165         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, GetOrientation(), __previousSize.height);
166
167         return r;
168
169 CATCH:
170         delete __pDateTimeBar;
171         return r;
172 }
173
174 result
175 _EditTime::AddTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
176 {
177         if (__pTimeChangeEvent == null)
178         {
179                 __pTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*this);
180                 SysTryReturn(NID_UI_CTRL, (__pTimeChangeEvent != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
181                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
182         }
183
184         result r = __pTimeChangeEvent->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 _EditTime::RemoveTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
192 {
193         result r = E_OBJ_NOT_FOUND;
194
195         if (__pTimeChangeEvent)
196         {
197                 r = __pTimeChangeEvent->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 _EditTime::SetTime(const DateTime& time)
207 {
208         SetProperty("time", Variant(time));
209         return;
210 }
211
212 result
213 _EditTime::SetPropertyTime(const Variant& time)
214 {
215         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
216                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
217
218         __pEditTimePresenter->SetTime(time.ToDateTime());
219
220         UpdateAccessibilityElement();
221         return E_SUCCESS;
222 }
223
224 DateTime
225 _EditTime::GetTime(void) const
226 {
227         Variant time = GetProperty("time");
228
229         return time.ToDateTime();
230 }
231
232 Variant
233 _EditTime::GetPropertyTime(void) const
234 {
235         DateTime time;
236
237         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
238                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
239
240         time = __pEditTimePresenter->GetTime();
241
242         return Variant(time);
243 }
244
245 result
246 _EditTime::SetHour(int hour)
247 {
248         result r = E_SUCCESS;
249
250         SetProperty("hour", Variant(hour));
251
252         r = GetLastResult();
253
254         return r;
255 }
256
257 result
258 _EditTime::SetPropertyHour(const Variant& hour)
259 {
260         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
261                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
262
263         result r = E_SUCCESS;
264
265         r = __pEditTimePresenter->SetHour(hour.ToInt());
266         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
267
268         UpdateAccessibilityElement();
269
270         return r;
271 }
272
273 int
274 _EditTime::GetHour(void) const
275 {
276         Variant hour = GetProperty("hour");
277
278         return hour.ToInt();
279 }
280
281 Variant
282 _EditTime::GetPropertyHour(void) const
283 {
284         int hour = -1;
285
286         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
287                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
288
289         hour = __pEditTimePresenter->GetHour();
290
291         return Variant(hour);
292 }
293
294 result
295 _EditTime::SetMinute(int minute)
296 {
297         result r = E_SUCCESS;
298
299         SetProperty("minute", Variant(minute));
300
301         r = GetLastResult();
302
303         return r;
304 }
305
306 result
307 _EditTime::SetPropertyMinute(const Variant& minute)
308 {
309         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
310                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
311
312         result r = E_SUCCESS;
313
314         r = __pEditTimePresenter->SetMinute(minute.ToInt());
315         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
316
317         UpdateAccessibilityElement();
318
319         return r;
320 }
321
322 int
323 _EditTime::GetMinute(void) const
324 {
325         Variant minute = GetProperty("minute");
326
327         return minute.ToInt();
328 }
329
330 Variant
331 _EditTime::GetPropertyMinute(void) const
332 {
333         int minute = -1;
334
335         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
336                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
337
338         minute = __pEditTimePresenter->GetMinute();
339
340         return Variant(minute);
341 }
342
343 void
344 _EditTime::SetCurrentTime(void)
345 {
346         SysTryReturnVoidResult(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM,
347                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
348
349         __pEditTimePresenter->SetCurrentTime();
350
351         UpdateAccessibilityElement();
352
353         return;
354 }
355
356 void
357 _EditTime::SetTimePickerEnabled(bool enable)
358 {
359         SetProperty("timePickerEnabled", Variant(enable));
360         return;
361 }
362
363 result
364 _EditTime::SetPropertyTimePickerEnabled(const Variant& enable)
365 {
366         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
367                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
368
369         __pEditTimePresenter->SetTimePickerEnabled(enable.ToBool());
370
371         return E_SUCCESS;
372 }
373
374 bool
375 _EditTime::IsTimePickerEnabled(void) const
376 {
377         Variant enable = GetProperty("timePickerEnabled");
378
379         return enable.ToBool();
380 }
381
382 Variant
383 _EditTime::GetPropertyTimePickerEnabled(void) const
384 {
385         bool enable = false;
386
387         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
388                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
389
390         enable = __pEditTimePresenter->IsTimePickerEnabled();
391
392         return Variant(enable);
393 }
394
395 void
396 _EditTime::Set24HourNotationEnabled(bool enable)
397 {
398         SysTryReturnVoidResult(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM,
399                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
400
401         __pEditTimePresenter->Set24HourNotationEnabled(enable);
402         return;
403 }
404
405 bool
406 _EditTime::Is24HourNotationEnabled(void) const
407 {
408         SysAssertf((__pEditTimePresenter != null), "The _EditDatePresenter instance is null.");
409
410         return __pEditTimePresenter->Is24HourNotationEnabled();
411 }
412
413 result
414 _EditTime::CalculateDateTimeBarPosition(void)
415 {
416         result r = E_SUCCESS;
417
418         float dateTimeBarHeight = 0.0f;
419         float arrowHeight = 0.0f;
420         float timeHeight = 0.0f;
421         float timeBarMargin = 0.0f;
422         float textHeight = 0.0f;
423         float titleTimeMargin = 0.0f;
424         float bottomPosition = 0.0f;
425         float timeY = 0.0f;
426
427         FloatRectangle absoluteBounds;
428         FloatRectangle frameBounds;
429         FloatRectangle parentWindowBounds;
430         FloatRectangle titleBounds;
431
432         _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
433         SysTryReturn(NID_UI_CTRL, (pFrame != null), E_SYSTEM, E_SYSTEM,
434                         "[E_SYSTEM] A system error has occurred. Failed to get frame instance.");
435
436         frameBounds = pFrame->GetAbsoluteBoundsF();
437         absoluteBounds = GetAbsoluteBoundsF();
438         parentWindowBounds = GetParentWindowBounds();
439         titleBounds = __pEditTimePresenter->GetTitleBounds();
440
441         GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), dateTimeBarHeight);
442         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, GetOrientation(), arrowHeight);
443         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, GetOrientation(), timeHeight);
444         GET_SHAPE_CONFIG(EDITTIME::TIME_BAR_MARGIN, GetOrientation(), timeBarMargin);
445         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, GetOrientation(), textHeight);
446         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, GetOrientation(), titleTimeMargin);
447
448         if (!__title.IsEmpty()) //with title
449         {
450                 timeY = titleBounds.y + textHeight + titleTimeMargin ;
451         }
452         else //without title
453         {
454                 timeY = (absoluteBounds.height - timeHeight) / 2.0f ;
455         }
456
457         bottomPosition = absoluteBounds.y + timeY + timeHeight + timeBarMargin + arrowHeight + dateTimeBarHeight;
458
459         GetDateTimeBar()->SetParentWindowBounds(parentWindowBounds);
460
461         if (bottomPosition > frameBounds.y + parentWindowBounds.y + parentWindowBounds.height) //ALIGN_UP
462         {
463                 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + timeY - timeBarMargin - arrowHeight), DATETIME_BAR_ALIGN_UP);
464                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
465         }
466         else    //ALIGN_DOWN
467         {
468                 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + timeY + timeHeight + timeBarMargin + arrowHeight), DATETIME_BAR_ALIGN_DOWN);
469                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
470         }
471
472         __absoluteBounds = absoluteBounds;
473
474         return r;
475 }
476
477 void
478 _EditTime::OnDraw(void)
479 {
480         if (GetDateTimeBar() != null)
481         {
482                 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
483
484                 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
485                 {
486                         CalculateDateTimeBarPosition();
487                 }
488         }
489
490         __pEditTimePresenter->Draw();
491
492         if(unlikely((_AccessibilityManager::IsActivated())))
493         {
494                 UpdateAccessibilityElement();
495         }
496
497         return;
498 }
499
500 void
501 _EditTime::CreateAccessibilityElement(void)
502 {
503         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
504         FloatRectangle hourBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
505         FloatRectangle minuteBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
506         FloatRectangle ampmBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
507
508         pContainer->AddListener(*this);
509         if (__pAccessibilityEditTimeElement == null)
510         {
511                 __pAccessibilityEditTimeElement = new _AccessibilityElement(true);
512                 __pAccessibilityEditTimeElement->SetBounds(GetClientBoundsF());
513                 __pAccessibilityEditTimeElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
514                 __pAccessibilityEditTimeElement->SetName(L"EditTimeText");
515                 pContainer->AddElement(*__pAccessibilityEditTimeElement);
516         }
517
518         if (__pAccessibilityHourElement == null && __pAccessibilityMinuteElement == null)
519         {
520                 String hintText(L"Double tap to edit");
521
522                 __pAccessibilityHourElement = new _AccessibilityElement(true);
523                 __pAccessibilityHourElement->SetBounds(hourBounds);
524                 __pAccessibilityHourElement->SetTrait(ACCESSIBILITY_TRAITS_HOUR);
525                 __pAccessibilityHourElement->SetHint(hintText);
526                 pContainer->AddElement(*__pAccessibilityHourElement);
527
528                 __pAccessibilityMinuteElement = new _AccessibilityElement(true);
529                 __pAccessibilityMinuteElement->SetBounds(minuteBounds);
530                 __pAccessibilityMinuteElement->SetTrait(ACCESSIBILITY_TRAITS_MINUTE);
531                 __pAccessibilityMinuteElement->SetHint(hintText);
532                 pContainer->AddElement(*__pAccessibilityMinuteElement);
533
534                 if (Is24HourNotationEnabled() == false)
535                 {
536                         __pAccessibilityAmPmElement = new _AccessibilityElement(true);
537                         __pAccessibilityAmPmElement->SetBounds(ampmBounds);
538                         __pAccessibilityAmPmElement->SetTrait(ACCESSIBILITY_TRAITS_BUTTON);
539                         pContainer->AddElement(*__pAccessibilityAmPmElement);
540
541                         __pAccessibilityHourElement->SetBounds(FloatRectangle(hourBounds.x, ampmBounds.y, hourBounds.width, ampmBounds.height));
542                         __pAccessibilityMinuteElement->SetBounds(FloatRectangle(minuteBounds.x, ampmBounds.y, minuteBounds.width, ampmBounds.height));
543                 }
544         }
545 }
546
547 void
548 _EditTime::OnBoundsChanged(void)
549 {
550         FloatDimension newSize = GetSizeF();
551
552         if (newSize.width != __previousSize.width || newSize.height != __previousSize.height)
553         {
554                 __isCalledBoundsChanged = true;
555         }
556
557         __pEditTimePresenter->Initialize();
558
559         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityEditTimeElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime accessibility element must not be null.");
560         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityHourElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Hour accessibility element must not be null.");
561         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityMinuteElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Minute accessibility element must not be null.");
562
563         __pAccessibilityEditTimeElement->SetBounds(GetClientBoundsF());
564
565         FloatRectangle hourBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
566         FloatRectangle minuteBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
567         FloatRectangle ampmBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
568
569         __pAccessibilityHourElement->SetBounds(hourBounds);
570         __pAccessibilityMinuteElement->SetBounds(minuteBounds);
571
572         if (__pAccessibilityAmPmElement)
573         {
574                 __pAccessibilityHourElement->SetBounds(FloatRectangle(hourBounds.x, ampmBounds.y, hourBounds.width, ampmBounds.height));
575                 __pAccessibilityMinuteElement->SetBounds(FloatRectangle(minuteBounds.x, ampmBounds.y, minuteBounds.width, ampmBounds.height));
576                 __pAccessibilityAmPmElement->SetBounds(ampmBounds);
577         }
578
579         return;
580 }
581
582 void
583 _EditTime::OnChangeLayout(_ControlOrientation orientation)
584 {
585         if (!__isCalledBoundsChanged && !__isXmlBoundsExist)
586         {
587                 FloatRectangle bounds = GetBoundsF();
588
589                 GET_SHAPE_CONFIG(EDITTIME::WIDTH, GetOrientation(), bounds.width);
590                 GET_SHAPE_CONFIG(EDITTIME::HEIGHT, GetOrientation(), bounds.height);
591
592                 SetBounds(bounds, false);
593         }
594
595         __pEditTimePresenter->Initialize();
596         __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
597
598         if (GetDateTimeBar() != null)
599         {
600                 GetDateTimeBar()->SetVisibleState(false);
601                 GetDateTimeBar()->Close();
602         }
603
604         return;
605 }
606
607 bool
608 _EditTime::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
609 {
610         SetFocused(true);
611
612         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
613         if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
614         {
615                 CalculateDateTimeBarPosition();
616         }
617
618         return __pEditTimePresenter->OnTouchPressed(source, touchinfo);
619 }
620
621 bool
622 _EditTime::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
623 {
624         return __pEditTimePresenter->OnTouchReleased(source, touchinfo);
625 }
626
627 bool
628 _EditTime::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
629 {
630         return __pEditTimePresenter->OnTouchCanceled(source, touchinfo);
631 }
632
633 bool
634 _EditTime::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
635 {
636         return __pEditTimePresenter->OnTouchMoved(source, touchinfo);
637 }
638
639 void
640 _EditTime::OnTouchMoveHandled(const _Control& control)
641 {
642         __pEditTimePresenter->OnTouchMoveHandled(control);
643         return;
644 }
645
646 result
647 _EditTime::FireTimeChangeEvent(_DateTimeChangeStatus status)
648 {
649         SysTryReturn(NID_UI_CTRL, (__pTimeChangeEvent != null), E_SYSTEM, E_SYSTEM,
650                         "[E_SYSTEM] A system error has occurred. The _DateTimeChangeEvent instance is null.");
651
652         _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
653         SysTryReturn(NID_UI_CTRL, pDateTimeEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
654                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
655
656         pDateTimeEventArg->SetTime(GetHour(), GetMinute());
657
658         __pTimeChangeEvent->Fire(*pDateTimeEventArg);
659
660         return E_SUCCESS;
661 }
662
663 void
664 _EditTime::OnDateTimeChanged(const _Control& source, int year, int month, int day, int hour, int minute)
665 {
666         __pEditTimePresenter->Animate();
667         __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
668         Invalidate();
669         FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
670         return;
671 }
672
673 void
674 _EditTime::OnDateTimeChangeCanceled(const _Control& source)
675 {
676         __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
677         Invalidate();
678         FireTimeChangeEvent(TIME_INTERNAL_CHANGE_CANCELED);
679         return;
680 }
681
682 void
683 _EditTime::OnActionPerformed(const Ui::_Control& source, int actionId)
684 {
685         _DateTimeId boxId = __pEditTimePresenter->GetLastSelectedId();
686
687         if (boxId == DATETIME_ID_HOUR)
688         {
689                 bool amEnable = true;
690                 amEnable = __pEditTimePresenter->GetAmEnabled();
691
692                 int hour = 0;
693                 hour = actionId;
694                 if (amEnable == false && Is24HourNotationEnabled() == false)
695                 {
696                         if (hour < DATETIME_HOUR_MAX_FOR_24NOTATION)
697                         {
698                                 hour += DATETIME_HOUR_MAX_FOR_24NOTATION;
699                         }
700                 }
701                 else if (amEnable == true && Is24HourNotationEnabled() == false)
702                 {
703                         if (hour == DATETIME_HOUR_MAX_FOR_24NOTATION)
704                         {
705                                 hour = DATETIME_HOUR_MIN;
706                         }
707                 }
708                 SetHour(hour);
709         }
710         else if (boxId == DATETIME_ID_MINUTE)
711         {
712                 SetMinute(actionId);
713         }
714
715         Invalidate();
716         return;
717 }
718
719 _DateTimeBar*
720 _EditTime::GetDateTimeBar(void) const
721 {
722         return __pDateTimeBar;
723 }
724
725 void
726 _EditTime::OnFontChanged(Font* pFont)
727 {
728         __pEditTimePresenter->OnFontChanged(pFont);
729
730         return;
731 }
732
733 void
734 _EditTime::OnFontInfoRequested(unsigned long& style, float& size)
735 {
736         __pEditTimePresenter->OnFontInfoRequested(style, size);
737
738         return;
739 }
740
741 void
742 _EditTime::OnSettingChanged(String& key)
743 {
744         if (key.Equals(L"http://tizen.org/setting/locale.time.format.24hour", false))
745         {
746                 __pEditTimePresenter->UpdateTimeFormat();
747                 __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
748
749                 if (GetDateTimeBar() != null)
750                 {
751                         GetDateTimeBar()->SetVisibleState(false);
752                         GetDateTimeBar()->Close();
753                 }
754
755                 Invalidate();
756         }
757
758         return;
759 }
760
761 FloatRectangle
762 _EditTime::GetParentWindowBounds(void) const
763 {
764         _Form* pForm = null;
765         _Window* pwindow = null;
766         _Control* pControlCore = GetParent();
767
768         FloatDimension dateTimeBarSize(0.0f, 0.0f);
769
770         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, GetOrientation(), dateTimeBarSize);
771
772         FloatRectangle parentWindowBounds(0.0f, 0.0f, dateTimeBarSize.width, dateTimeBarSize.height);
773
774         while (true)
775         {
776                 if (pControlCore == null)
777                 {
778                         SysLog(NID_UI_CTRL,"[E_SYSTEM] Parent window not found.");
779
780                         return parentWindowBounds;
781                 }
782
783                 // If the parent is a Frame, then return the Form's bounds.
784                 pForm = dynamic_cast<_Form*>(pControlCore);
785                 if (pForm != null)
786                 {
787                         parentWindowBounds = pForm->GetBoundsF();
788                         break;
789                 }
790
791                 pwindow = dynamic_cast<_Window*>(pControlCore);
792
793                 if (pwindow != null)
794                 {
795                         parentWindowBounds = pwindow->GetBoundsF();
796                         break;
797                 }
798
799                 pControlCore = pControlCore->GetParent();
800         }
801
802         return parentWindowBounds;
803 }
804
805 void
806 _EditTime::SetXmlBoundsExist(bool isXmlBoundsExist)
807 {
808         __isXmlBoundsExist = isXmlBoundsExist;
809 }
810
811 void
812 _EditTime::UpdateAccessibilityElement(void)
813 {
814
815         String string;
816
817         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityEditTimeElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime accessibility element must not be null.");
818         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityHourElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Hour accessibility element must not be null.");
819         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityMinuteElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Minute accessibility element must not be null.");
820
821         if (__title.IsEmpty() == false)
822         {
823                 string.Append(__title);
824                 string.Append(L", ");
825         }
826
827         String hourString;
828         int hour =  GetHour();
829         int maxHour = DATETIME_HOUR_MAX_FOR_24NOTATION;
830
831         if (Is24HourNotationEnabled() == false && (hour > maxHour))
832         {
833                 hourString.Format(10, L"%02d", hour - DATETIME_HOUR_MAX_FOR_24NOTATION);
834         }
835         else
836         {
837                 hourString.Format(10, L"%02d", hour);
838         }
839
840         string.Append(hourString.GetPointer());
841         string.Append(L":");
842         string.Append(GetMinute());
843         string.Append(L" ");
844
845         FloatRectangle hourBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
846         FloatRectangle minuteBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
847         FloatRectangle ampmBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
848
849         if (Is24HourNotationEnabled() == false)
850         {
851                 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
852                 SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
853
854                 if (__pAccessibilityAmPmElement == null)
855                 {
856                         __pAccessibilityAmPmElement = new (std::nothrow) _AccessibilityElement(true);
857                         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityAmPmElement != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
858
859                         __pAccessibilityAmPmElement->SetBounds(ampmBounds);
860                         __pAccessibilityAmPmElement->SetTrait(ACCESSIBILITY_TRAITS_BUTTON);
861                         pContainer->AddElement(*__pAccessibilityAmPmElement);
862
863                         __pAccessibilityHourElement->SetBounds(FloatRectangle(hourBounds.x, ampmBounds.y, hourBounds.width, ampmBounds.height));
864                         __pAccessibilityMinuteElement->SetBounds(FloatRectangle(minuteBounds.x, ampmBounds.y, minuteBounds.width, ampmBounds.height));
865                 }
866                 else
867                 {
868                         __pAccessibilityAmPmElement->Activate(true);
869                 }
870
871                 String hintAmPmText(L"Double tap to change to ");
872
873                 String amString;
874                 String pmString;
875                 _DateTimeUtils dateTimeUtils;
876                 dateTimeUtils.GetAmPm(amString, AM_TYPE);
877                 dateTimeUtils.GetAmPm(pmString, PM_TYPE);
878
879                 if (__pEditTimePresenter->GetAmEnabled() == true)
880                 {
881                         __pAccessibilityAmPmElement->SetLabel(amString);
882                         hintAmPmText.Append(pmString.GetPointer());
883                         string.Append(amString.GetPointer());
884                 }
885                 else
886                 {
887                         __pAccessibilityAmPmElement->SetLabel(pmString);
888                         hintAmPmText.Append(amString.GetPointer());
889                         string.Append(pmString.GetPointer());
890                 }
891
892                 __pAccessibilityAmPmElement->SetHint(hintAmPmText);
893         }
894         else if (__pAccessibilityAmPmElement != null)
895         {
896                 __pAccessibilityAmPmElement->Activate(false);
897         }
898
899         __pAccessibilityEditTimeElement->SetLabel(string);
900
901         __pAccessibilityHourElement->SetLabel(hourString);
902
903         string.Clear();
904         string.Format(10, L"%02d", GetMinute());
905         __pAccessibilityMinuteElement->SetLabel(string);
906
907         return;
908 }
909
910 bool
911 _EditTime::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
912 {
913         return false;
914 }
915
916 bool
917 _EditTime::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
918 {
919         return false;
920 }
921
922 bool
923 _EditTime::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
924 {
925         return false;
926 }
927
928 bool
929 _EditTime::OnAccessibilityReadedElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
930 {
931         return false;
932 }
933
934
935 bool
936 _EditTime::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
937 {
938         return false;
939 }
940
941 bool
942 _EditTime::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
943 {
944         return false;
945 }
946
947 bool
948 _EditTime::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
949 {
950         String amString;
951         String pmString;
952         String labelText;
953
954         labelText = element.GetLabel();
955
956         _DateTimeUtils dateTimeUtils;
957         dateTimeUtils.GetAmPm(amString, AM_TYPE);
958         dateTimeUtils.GetAmPm(pmString, PM_TYPE);
959
960         if (labelText == amString || labelText == pmString)
961         {
962                 labelText.Append(L" Selected");
963                 _AccessibilityManager::GetInstance()->ReadContent(labelText);
964         }
965
966         return true;
967 }
968
969 bool
970 _EditTime::OnAccessibilityValueIncreased(const _AccessibilityContainer&, const _AccessibilityElement&)
971 {
972         return false;
973 }
974
975 bool
976 _EditTime::OnAccessibilityValueDecreased(const _AccessibilityContainer&, const _AccessibilityElement&)
977 {
978         return false;
979 }
980
981 }}} // Controls