Fixed N_SE-41397 for DateTimechange
[platform/framework/native/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         pEditTime->SetTouchPressThreshold(_TOUCH_PRESS_THRESHOLD_INSENSITIVE);
139
140         return pEditTime;
141
142 CATCH:
143         delete pEditTime;
144         return null;
145 }
146
147 result
148 _EditTime::CreateDateTimeBar(void)
149 {
150         result r = E_SUCCESS;
151
152         __pDateTimeBar = _DateTimeBar::CreateDateTimeBarN(*this);
153         r = GetLastResult();
154         SysTryReturn(NID_UI_CTRL, (__pDateTimeBar != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
155
156         r = __pDateTimeBar->AddActionEventListener(*this);
157         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
158
159         r = __pDateTimeBar->AddDateTimeChangeEventListener(*this);
160         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
161
162         r =  SettingInfo::AddSettingEventListener(*this);
163         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
164
165         GET_SHAPE_CONFIG(EDITTIME::WIDTH, GetOrientation(), __previousSize.width);
166         GET_SHAPE_CONFIG(EDITTIME::HEIGHT, GetOrientation(), __previousSize.height);
167
168         return r;
169
170 CATCH:
171         delete __pDateTimeBar;
172         return r;
173 }
174
175 result
176 _EditTime::AddTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
177 {
178         if (__pTimeChangeEvent == null)
179         {
180                 __pTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*this);
181                 SysTryReturn(NID_UI_CTRL, (__pTimeChangeEvent != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
182                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
183         }
184
185         result r = __pTimeChangeEvent->AddListener(listener);
186         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
187
188         return E_SUCCESS;
189 }
190
191 result
192 _EditTime::RemoveTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
193 {
194         result r = E_OBJ_NOT_FOUND;
195
196         if (__pTimeChangeEvent)
197         {
198                 r = __pTimeChangeEvent->RemoveListener(listener);
199         }
200
201         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
202
203         return E_SUCCESS;
204 }
205
206 void
207 _EditTime::SetTime(const DateTime& time)
208 {
209         SetProperty("time", Variant(time));
210         return;
211 }
212
213 result
214 _EditTime::SetPropertyTime(const Variant& time)
215 {
216         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
217                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
218
219         __pEditTimePresenter->SetTime(time.ToDateTime());
220
221         UpdateAccessibilityElement();
222         return E_SUCCESS;
223 }
224
225 DateTime
226 _EditTime::GetTime(void) const
227 {
228         Variant time = GetProperty("time");
229
230         return time.ToDateTime();
231 }
232
233 Variant
234 _EditTime::GetPropertyTime(void) const
235 {
236         DateTime time;
237
238         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
239                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
240
241         time = __pEditTimePresenter->GetTime();
242
243         return Variant(time);
244 }
245
246 result
247 _EditTime::SetHour(int hour)
248 {
249         result r = E_SUCCESS;
250
251         SetProperty("hour", Variant(hour));
252
253         r = GetLastResult();
254
255         return r;
256 }
257
258 result
259 _EditTime::SetPropertyHour(const Variant& hour)
260 {
261         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
262                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
263
264         result r = E_SUCCESS;
265
266         r = __pEditTimePresenter->SetHour(hour.ToInt());
267         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
268
269         UpdateAccessibilityElement();
270
271         return r;
272 }
273
274 int
275 _EditTime::GetHour(void) const
276 {
277         Variant hour = GetProperty("hour");
278
279         return hour.ToInt();
280 }
281
282 Variant
283 _EditTime::GetPropertyHour(void) const
284 {
285         int hour = -1;
286
287         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
288                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
289
290         hour = __pEditTimePresenter->GetHour();
291
292         return Variant(hour);
293 }
294
295 result
296 _EditTime::SetMinute(int minute)
297 {
298         result r = E_SUCCESS;
299
300         SetProperty("minute", Variant(minute));
301
302         r = GetLastResult();
303
304         return r;
305 }
306
307 result
308 _EditTime::SetPropertyMinute(const Variant& minute)
309 {
310         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
311                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
312
313         result r = E_SUCCESS;
314
315         r = __pEditTimePresenter->SetMinute(minute.ToInt());
316         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
317
318         UpdateAccessibilityElement();
319
320         return r;
321 }
322
323 int
324 _EditTime::GetMinute(void) const
325 {
326         Variant minute = GetProperty("minute");
327
328         return minute.ToInt();
329 }
330
331 Variant
332 _EditTime::GetPropertyMinute(void) const
333 {
334         int minute = -1;
335
336         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
337                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
338
339         minute = __pEditTimePresenter->GetMinute();
340
341         return Variant(minute);
342 }
343
344 void
345 _EditTime::SetCurrentTime(void)
346 {
347         SysTryReturnVoidResult(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM,
348                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
349
350         __pEditTimePresenter->SetCurrentTime();
351
352         UpdateAccessibilityElement();
353
354         return;
355 }
356
357 void
358 _EditTime::SetTimePickerEnabled(bool enable)
359 {
360         SetProperty("timePickerEnabled", Variant(enable));
361         return;
362 }
363
364 result
365 _EditTime::SetPropertyTimePickerEnabled(const Variant& enable)
366 {
367         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM, E_SYSTEM,
368                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
369
370         __pEditTimePresenter->SetTimePickerEnabled(enable.ToBool());
371
372         return E_SUCCESS;
373 }
374
375 bool
376 _EditTime::IsTimePickerEnabled(void) const
377 {
378         Variant enable = GetProperty("timePickerEnabled");
379
380         return enable.ToBool();
381 }
382
383 Variant
384 _EditTime::GetPropertyTimePickerEnabled(void) const
385 {
386         bool enable = false;
387
388         SysTryReturn(NID_UI_CTRL, (__pEditTimePresenter != null), Variant(), E_SYSTEM,
389                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
390
391         enable = __pEditTimePresenter->IsTimePickerEnabled();
392
393         return Variant(enable);
394 }
395
396 void
397 _EditTime::Set24HourNotationEnabled(bool enable)
398 {
399         SysTryReturnVoidResult(NID_UI_CTRL, (__pEditTimePresenter != null), E_SYSTEM,
400                         "[E_SYSTEM] A system error has occurred. The _EditDatePresenter instance is null.");
401
402         __pEditTimePresenter->Set24HourNotationEnabled(enable);
403         return;
404 }
405
406 bool
407 _EditTime::Is24HourNotationEnabled(void) const
408 {
409         SysAssertf((__pEditTimePresenter != null), "The _EditDatePresenter instance is null.");
410
411         return __pEditTimePresenter->Is24HourNotationEnabled();
412 }
413
414 result
415 _EditTime::CalculateDateTimeBarPosition(void)
416 {
417         result r = E_SUCCESS;
418
419         float dateTimeBarHeight = 0.0f;
420         float arrowHeight = 0.0f;
421         float timeHeight = 0.0f;
422         float timeBarMargin = 0.0f;
423         float textHeight = 0.0f;
424         float titleTimeMargin = 0.0f;
425         float bottomPosition = 0.0f;
426         float timeY = 0.0f;
427
428         FloatRectangle absoluteBounds;
429         FloatRectangle frameBounds;
430         FloatRectangle parentWindowBounds;
431         FloatRectangle titleBounds;
432
433         _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
434         SysTryReturn(NID_UI_CTRL, (pFrame != null), E_SYSTEM, E_SYSTEM,
435                         "[E_SYSTEM] A system error has occurred. Failed to get frame instance.");
436
437         frameBounds = pFrame->GetAbsoluteBoundsF();
438         absoluteBounds = GetAbsoluteBoundsF();
439         parentWindowBounds = GetParentWindowBounds();
440         titleBounds = __pEditTimePresenter->GetTitleBounds();
441
442         GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), dateTimeBarHeight);
443         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, GetOrientation(), arrowHeight);
444         GET_SHAPE_CONFIG(EDITTIME::TIME_HEIGHT, GetOrientation(), timeHeight);
445         GET_SHAPE_CONFIG(EDITTIME::TIME_BAR_MARGIN, GetOrientation(), timeBarMargin);
446         GET_SHAPE_CONFIG(EDITTIME::TITLE_HEIGHT, GetOrientation(), textHeight);
447         GET_SHAPE_CONFIG(EDITTIME::TITLE_TIME_MARGIN, GetOrientation(), titleTimeMargin);
448
449         if (!__title.IsEmpty()) //with title
450         {
451                 timeY = titleBounds.y + textHeight + titleTimeMargin ;
452         }
453         else //without title
454         {
455                 timeY = (absoluteBounds.height - timeHeight) / 2.0f ;
456         }
457
458         bottomPosition = absoluteBounds.y + timeY + timeHeight + timeBarMargin + arrowHeight + dateTimeBarHeight;
459
460         GetDateTimeBar()->SetParentWindowBounds(parentWindowBounds);
461
462         if (bottomPosition > frameBounds.y + parentWindowBounds.y + parentWindowBounds.height) //ALIGN_UP
463         {
464                 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + timeY - timeBarMargin - arrowHeight), DATETIME_BAR_ALIGN_UP);
465                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
466         }
467         else    //ALIGN_DOWN
468         {
469                 r = GetDateTimeBar()->SetPositionAndAlignment(FloatPoint(parentWindowBounds.x, absoluteBounds.y + timeY + timeHeight + timeBarMargin + arrowHeight), DATETIME_BAR_ALIGN_DOWN);
470                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
471         }
472
473         __absoluteBounds = absoluteBounds;
474
475         return r;
476 }
477
478 void
479 _EditTime::OnDraw(void)
480 {
481         if (GetDateTimeBar() != null)
482         {
483                 FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
484
485                 if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
486                 {
487                         CalculateDateTimeBarPosition();
488                 }
489         }
490
491         __pEditTimePresenter->Draw();
492
493         if (unlikely((_AccessibilityManager::IsActivated())))
494         {
495                 UpdateAccessibilityElement();
496         }
497
498         return;
499 }
500
501 void
502 _EditTime::CreateAccessibilityElement(void)
503 {
504         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
505         FloatRectangle hourBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
506         FloatRectangle minuteBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
507         FloatRectangle ampmBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
508
509         pContainer->AddListener(*this);
510         if (__pAccessibilityEditTimeElement == null)
511         {
512                 __pAccessibilityEditTimeElement = new _AccessibilityElement(true);
513                 __pAccessibilityEditTimeElement->SetBounds(GetClientBoundsF());
514                 __pAccessibilityEditTimeElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
515                 __pAccessibilityEditTimeElement->SetName(L"EditTimeText");
516                 pContainer->AddElement(*__pAccessibilityEditTimeElement);
517         }
518
519         if (__pAccessibilityHourElement == null && __pAccessibilityMinuteElement == null)
520         {
521                 String hintText(L"Double tap to edit");
522
523                 __pAccessibilityHourElement = new _AccessibilityElement(true);
524                 __pAccessibilityHourElement->SetBounds(hourBounds);
525                 __pAccessibilityHourElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_HOUR_LC");
526                 __pAccessibilityHourElement->SetHint(hintText);
527                 pContainer->AddElement(*__pAccessibilityHourElement);
528
529                 __pAccessibilityMinuteElement = new _AccessibilityElement(true);
530                 __pAccessibilityMinuteElement->SetBounds(minuteBounds);
531                 __pAccessibilityMinuteElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_MINUTE_LC");
532                 __pAccessibilityMinuteElement->SetHint(hintText);
533                 pContainer->AddElement(*__pAccessibilityMinuteElement);
534
535                 if (Is24HourNotationEnabled() == false)
536                 {
537                         __pAccessibilityAmPmElement = new _AccessibilityElement(true);
538                         __pAccessibilityAmPmElement->SetBounds(ampmBounds);
539                         __pAccessibilityAmPmElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS");
540                         pContainer->AddElement(*__pAccessibilityAmPmElement);
541
542                         __pAccessibilityHourElement->SetBounds(FloatRectangle(hourBounds.x, ampmBounds.y, hourBounds.width, ampmBounds.height));
543                         __pAccessibilityMinuteElement->SetBounds(FloatRectangle(minuteBounds.x, ampmBounds.y, minuteBounds.width, ampmBounds.height));
544                 }
545         }
546 }
547
548 void
549 _EditTime::OnBoundsChanged(void)
550 {
551         FloatDimension newSize = GetSizeF();
552
553         if (newSize.width != __previousSize.width || newSize.height != __previousSize.height)
554         {
555                 __isCalledBoundsChanged = true;
556         }
557
558         __pEditTimePresenter->Initialize();
559
560         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityEditTimeElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime accessibility element must not be null.");
561         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityHourElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Hour accessibility element must not be null.");
562         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityMinuteElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Minute accessibility element must not be null.");
563
564         __pAccessibilityEditTimeElement->SetBounds(GetClientBoundsF());
565
566         FloatRectangle hourBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
567         FloatRectangle minuteBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
568         FloatRectangle ampmBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
569
570         __pAccessibilityHourElement->SetBounds(hourBounds);
571         __pAccessibilityMinuteElement->SetBounds(minuteBounds);
572
573         if (__pAccessibilityAmPmElement)
574         {
575                 __pAccessibilityHourElement->SetBounds(FloatRectangle(hourBounds.x, ampmBounds.y, hourBounds.width, ampmBounds.height));
576                 __pAccessibilityMinuteElement->SetBounds(FloatRectangle(minuteBounds.x, ampmBounds.y, minuteBounds.width, ampmBounds.height));
577                 __pAccessibilityAmPmElement->SetBounds(ampmBounds);
578         }
579
580         return;
581 }
582
583 void
584 _EditTime::OnChangeLayout(_ControlRotation rotation)
585 {
586         if (!__isCalledBoundsChanged && !__isXmlBoundsExist)
587         {
588                 FloatRectangle bounds = GetBoundsF();
589
590                 GET_SHAPE_CONFIG(EDITTIME::WIDTH, GetOrientation(), bounds.width);
591                 GET_SHAPE_CONFIG(EDITTIME::HEIGHT, GetOrientation(), bounds.height);
592
593                 SetBounds(bounds, false);
594         }
595
596         __pEditTimePresenter->Initialize();
597         __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
598
599         if (GetDateTimeBar() != null)
600         {
601                 GetDateTimeBar()->SetVisibleState(false);
602                 GetDateTimeBar()->Close();
603         }
604
605         return;
606 }
607
608 bool
609 _EditTime::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
610 {
611         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
612         if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
613         {
614                 CalculateDateTimeBarPosition();
615         }
616
617         return __pEditTimePresenter->OnTouchPressed(source, touchinfo);
618 }
619
620 bool
621 _EditTime::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
622 {
623         return __pEditTimePresenter->OnTouchReleased(source, touchinfo);
624 }
625
626 bool
627 _EditTime::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
628 {
629         return __pEditTimePresenter->OnTouchCanceled(source, touchinfo);
630 }
631
632 bool
633 _EditTime::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
634 {
635         return __pEditTimePresenter->OnTouchMoved(source, touchinfo);
636 }
637
638 void
639 _EditTime::OnTouchMoveHandled(const _Control& control)
640 {
641         __pEditTimePresenter->OnTouchMoveHandled(control);
642         return;
643 }
644
645 result
646 _EditTime::FireTimeChangeEvent(_DateTimeChangeStatus status)
647 {
648         SysTryReturn(NID_UI_CTRL, (__pTimeChangeEvent != null), E_SYSTEM, E_SYSTEM,
649                         "[E_SYSTEM] A system error has occurred. The _DateTimeChangeEvent instance is null.");
650
651         _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
652         SysTryReturn(NID_UI_CTRL, pDateTimeEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
653                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
654
655         pDateTimeEventArg->SetTime(GetHour(), GetMinute());
656
657         __pTimeChangeEvent->Fire(*pDateTimeEventArg);
658
659         return E_SUCCESS;
660 }
661
662 void
663 _EditTime::OnDateTimeChanged(const _Control& source, int year, int month, int day, int hour, int minute)
664 {
665         __pEditTimePresenter->Animate();
666         __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
667         Invalidate();
668         FireTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
669         return;
670 }
671
672 void
673 _EditTime::OnDateTimeChangeCanceled(const _Control& source)
674 {
675         __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
676         Invalidate();
677         FireTimeChangeEvent(TIME_INTERNAL_CHANGE_CANCELED);
678         return;
679 }
680
681 void
682 _EditTime::OnActionPerformed(const Ui::_Control& source, int actionId)
683 {
684         _DateTimeId boxId = __pEditTimePresenter->GetLastSelectedId();
685
686         if (boxId == DATETIME_ID_HOUR)
687         {
688                 bool amEnable = true;
689                 amEnable = __pEditTimePresenter->GetAmEnabled();
690
691                 int hour = 0;
692                 hour = actionId;
693                 if (amEnable == false && Is24HourNotationEnabled() == false)
694                 {
695                         if (hour < DATETIME_HOUR_MAX_FOR_24NOTATION)
696                         {
697                                 hour += DATETIME_HOUR_MAX_FOR_24NOTATION;
698                         }
699                 }
700                 else if (amEnable == true && Is24HourNotationEnabled() == false)
701                 {
702                         if (hour == DATETIME_HOUR_MAX_FOR_24NOTATION)
703                         {
704                                 hour = DATETIME_HOUR_MIN;
705                         }
706                 }
707                 SetHour(hour);
708         }
709         else if (boxId == DATETIME_ID_MINUTE)
710         {
711                 SetMinute(actionId);
712         }
713
714         Invalidate();
715         return;
716 }
717
718 _DateTimeBar*
719 _EditTime::GetDateTimeBar(void) const
720 {
721         return __pDateTimeBar;
722 }
723
724 void
725 _EditTime::OnFontChanged(Font* pFont)
726 {
727         __pEditTimePresenter->OnFontChanged(pFont);
728
729         return;
730 }
731
732 void
733 _EditTime::OnFontInfoRequested(unsigned long& style, float& size)
734 {
735         __pEditTimePresenter->OnFontInfoRequested(style, size);
736
737         return;
738 }
739
740 void
741 _EditTime::OnSettingChanged(String& key)
742 {
743         if (key.Equals(L"http://tizen.org/setting/locale.time.format.24hour", false))
744         {
745                 __pEditTimePresenter->UpdateTimeFormat();
746                 __pEditTimePresenter->SetLastSelectedId(DATETIME_ID_NONE);
747
748                 if (GetDateTimeBar() != null)
749                 {
750                         GetDateTimeBar()->SetVisibleState(false);
751                         GetDateTimeBar()->Close();
752                 }
753
754                 Invalidate();
755         }
756
757         return;
758 }
759
760 void
761 _EditTime::OnDrawFocus(void)
762 {
763         __pEditTimePresenter->SetFocusState(true);
764         __pEditTimePresenter->SetFocusedElement();
765         __pEditTimePresenter->DrawFocus();
766         return;
767 }
768
769 bool
770 _EditTime::OnKeyPressed(const _Control &source, const _KeyInfo &keyInfo)
771 {
772         _KeyCode keyCode = keyInfo.GetKeyCode();
773
774         switch (keyCode)
775         {
776                 case _KEY_ENTER:
777                 {
778                         FloatRectangle absoluteBounds = GetAbsoluteBoundsF();
779
780                         if (absoluteBounds.y != __absoluteBounds.y || absoluteBounds.height != __absoluteBounds.height)
781                         {
782                                 CalculateDateTimeBarPosition();
783                         }
784                         break;
785                 }
786                 default:
787                 break;
788
789         }
790
791         return __pEditTimePresenter->OnKeyPressed(source, keyInfo);
792 }
793
794 bool
795 _EditTime::OnFocusGained(const _Control &source)
796 {
797         __pEditTimePresenter->SetFocusedElement();
798         return true;
799 }
800
801 bool
802 _EditTime::OnFocusLost(const _Control &source)
803 {
804         return __pEditTimePresenter->OnFocusLost(source);
805 }
806
807 void
808 _EditTime::OnFocusModeStateChanged(void)
809 {
810         __pEditTimePresenter->OnFocusModeStateChanged();
811         return;
812 }
813
814 FloatRectangle
815 _EditTime::GetParentWindowBounds(void) const
816 {
817         _Form* pForm = null;
818         _Window* pwindow = null;
819         _Control* pControlCore = GetParent();
820
821         FloatDimension dateTimeBarSize(0.0f, 0.0f);
822
823         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, GetOrientation(), dateTimeBarSize);
824
825         FloatRectangle parentWindowBounds(0.0f, 0.0f, dateTimeBarSize.width, dateTimeBarSize.height);
826
827         while (true)
828         {
829                 if (pControlCore == null)
830                 {
831                         SysLog(NID_UI_CTRL,"[E_SYSTEM] Parent window not found.");
832
833                         return parentWindowBounds;
834                 }
835
836                 // If the parent is a Frame, then return the Form's bounds.
837                 pForm = dynamic_cast<_Form*>(pControlCore);
838                 if (pForm != null)
839                 {
840                         parentWindowBounds = pForm->GetBoundsF();
841                         break;
842                 }
843
844                 pwindow = dynamic_cast<_Window*>(pControlCore);
845
846                 if (pwindow != null)
847                 {
848                         parentWindowBounds = pwindow->GetBoundsF();
849                         break;
850                 }
851
852                 pControlCore = pControlCore->GetParent();
853         }
854
855         return parentWindowBounds;
856 }
857
858 void
859 _EditTime::SetXmlBoundsExist(bool isXmlBoundsExist)
860 {
861         __isXmlBoundsExist = isXmlBoundsExist;
862 }
863
864 void
865 _EditTime::UpdateAccessibilityElement(void)
866 {
867
868         String string;
869
870         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityEditTimeElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. EditTime accessibility element must not be null.");
871         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityHourElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Hour accessibility element must not be null.");
872         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityMinuteElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Minute accessibility element must not be null.");
873
874         if (__title.IsEmpty() == false)
875         {
876                 string.Append(__title);
877                 string.Append(L", ");
878         }
879
880         String hourString;
881         int hour =  GetHour();
882         int maxHour = DATETIME_HOUR_MAX_FOR_24NOTATION;
883
884         if (Is24HourNotationEnabled() == false && (hour > maxHour))
885         {
886                 hourString.Format(10, L"%02d", hour - DATETIME_HOUR_MAX_FOR_24NOTATION);
887         }
888         else
889         {
890                 hourString.Format(10, L"%02d", hour);
891         }
892
893         string.Append(hourString.GetPointer());
894         string.Append(L":");
895         string.Append(GetMinute());
896         string.Append(L" ");
897
898         FloatRectangle hourBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_HOUR);
899         FloatRectangle minuteBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_MINUTE);
900         FloatRectangle ampmBounds = __pEditTimePresenter->GetDisplayAreaBoundsFromHoursStyle(DATETIME_ID_AMPM);
901
902         if (Is24HourNotationEnabled() == false)
903         {
904                 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
905                 SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
906
907                 if (__pAccessibilityAmPmElement == null)
908                 {
909                         __pAccessibilityAmPmElement = new (std::nothrow) _AccessibilityElement(true);
910                         SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityAmPmElement != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
911
912                         __pAccessibilityAmPmElement->SetBounds(ampmBounds);
913                         __pAccessibilityAmPmElement->SetTraitWithStringId("IDS_TPLATFORM_BODY_BUTTON_T_TTS");
914                         pContainer->AddElement(*__pAccessibilityAmPmElement);
915
916                         __pAccessibilityHourElement->SetBounds(FloatRectangle(hourBounds.x, ampmBounds.y, hourBounds.width, ampmBounds.height));
917                         __pAccessibilityMinuteElement->SetBounds(FloatRectangle(minuteBounds.x, ampmBounds.y, minuteBounds.width, ampmBounds.height));
918                 }
919                 else
920                 {
921                         __pAccessibilityAmPmElement->Activate(true);
922                 }
923
924                 String hintAmPmText(L"Double tap to edit");
925
926                 String amString;
927                 String pmString;
928                 _DateTimeUtils dateTimeUtils;
929                 dateTimeUtils.GetAmPm(amString, AM_TYPE);
930                 dateTimeUtils.GetAmPm(pmString, PM_TYPE);
931
932                 if (__pEditTimePresenter->GetAmEnabled() == true)
933                 {
934                         __pAccessibilityAmPmElement->SetLabel(amString);
935                         string.Append(amString.GetPointer());
936                 }
937                 else
938                 {
939                         __pAccessibilityAmPmElement->SetLabel(pmString);
940                         string.Append(pmString.GetPointer());
941                 }
942
943                 __pAccessibilityAmPmElement->SetHint(hintAmPmText);
944         }
945         else if (__pAccessibilityAmPmElement != null)
946         {
947                 __pAccessibilityAmPmElement->Activate(false);
948         }
949
950         __pAccessibilityEditTimeElement->SetLabel(string);
951
952         __pAccessibilityHourElement->SetLabel(hourString);
953
954         string.Clear();
955         string.Format(10, L"%02d", GetMinute());
956         __pAccessibilityMinuteElement->SetLabel(string);
957
958         return;
959 }
960
961 bool
962 _EditTime::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
963 {
964         return false;
965 }
966
967 bool
968 _EditTime::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
969 {
970         return false;
971 }
972
973 bool
974 _EditTime::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
975 {
976         return false;
977 }
978
979 bool
980 _EditTime::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
981 {
982         return false;
983 }
984
985
986 bool
987 _EditTime::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
988 {
989         return false;
990 }
991
992 bool
993 _EditTime::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
994 {
995         return false;
996 }
997
998 bool
999 _EditTime::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1000 {
1001         String amString;
1002         String pmString;
1003         String labelText;
1004
1005         labelText = element.GetLabel();
1006
1007         _DateTimeUtils dateTimeUtils;
1008         dateTimeUtils.GetAmPm(amString, AM_TYPE);
1009         dateTimeUtils.GetAmPm(pmString, PM_TYPE);
1010
1011         if (labelText == amString || labelText == pmString)
1012         {
1013                 labelText.Append(L" Selected");
1014                 _AccessibilityManager::GetInstance()->ReadContent(labelText);
1015         }
1016
1017         return true;
1018 }
1019
1020 bool
1021 _EditTime::OnAccessibilityValueIncreased(const _AccessibilityContainer&, const _AccessibilityElement&)
1022 {
1023         return false;
1024 }
1025
1026 bool
1027 _EditTime::OnAccessibilityValueDecreased(const _AccessibilityContainer&, const _AccessibilityElement&)
1028 {
1029         return false;
1030 }
1031
1032 }}} // Controls