Merge "Revert "RefreshList optimization"" into tizen_2.1
[platform/framework/native/uifw.git] / src / ui / FUi_ControlManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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                FUi_ControlManager.cpp
20  * @brief               This is the implementation file for the _ControlManager class.
21  */
22
23 #include <new>
24 #include <app.h>
25 #include <sensor.h>
26 #include <sensor_accel.h>
27 #include <runtime_info.h>
28 #include <Ecore_X.h>
29 #include <Elementary.h>
30 #include <FBaseInt8.h>
31 #include <FBaseSysLog.h>
32 #include <FGrpRectangle.h>
33 #include <FApp_AppInfo.h>
34 #include <FAppPkg_PackageInfoImpl.h>
35 #include <FGrp_Screen.h>
36 #include <FGrp_FontImpl.h>
37 #include <FSys_SettingInfoImpl.h>
38 #include <FSys_SystemInfoImpl.h>
39 #include "FUi_ControlManager.h"
40 #include "FUi_Control.h"
41 #include "FUi_Window.h"
42 #include "FUi_WindowImpl.h"
43 #include "FUi_EcoreEvas.h"
44 #include "FUi_EcoreEvasMgr.h"
45 #include "FUi_EflWindow.h"
46 #include "FUi_ResourceManager.h"
47 #include "FUi_Clipboard.h"
48 #include "FUi_UiFocusEvent.h"
49 #include "FUi_UiEventManager.h"
50 #include "FUi_TouchManager.h"
51 #include "FUi_TouchLongPressGestureDetector.h"
52 #include "FUi_TouchTapGestureDetector.h"
53 #include "FUi_KeyEventManager.h"
54 #include "FUi_CoordinateSystemUtils.h"
55 #include "FUiAnim_RootVisualElement.h"
56 #include "FUiAnim_AnimationManager.h"
57 #include "FUiAnim_DisplayManager.h"
58 #include "FUi_AccessibilityManager.h"
59 #include "FUiAnim_VisualElement.h"
60 #include "FUiAnim_EflLayer.h"
61 #include "FUiCtrl_FrameImpl.h"
62 #include "FUiCtrl_FormImpl.h"
63 #include "FUiCtrl_Frame.h"
64 #include "FUiCtrl_IndicatorManager.h"
65
66 using namespace Tizen::App;
67 using namespace Tizen::App::Package;
68 using namespace Tizen::Base;
69 using namespace Tizen::Base::Collection;
70 using namespace Tizen::Graphics;
71 using namespace Tizen::Ui;
72 using namespace Tizen::Ui::Animations;
73 using namespace Tizen::Ui::Controls;
74 using namespace Tizen::System;
75
76 namespace {
77
78 _ControlRotation Convert(int rotationDegree)
79 {
80         switch (rotationDegree)
81         {
82                 case 0:
83                         return _CONTROL_ROTATION_0;
84                 case 90:
85                         return _CONTROL_ROTATION_90;
86                 case 180:
87                         return _CONTROL_ROTATION_180;
88                 case 270:
89                         return _CONTROL_ROTATION_270;
90                 default:
91                         return _CONTROL_ROTATION_0;
92         }
93 }
94
95 int Convert(_ControlRotation rotation)
96 {
97         switch (rotation)
98         {
99                 case _CONTROL_ROTATION_0:
100                         return 0;
101                 case _CONTROL_ROTATION_90:
102                         return 90;
103                 case _CONTROL_ROTATION_180:
104                         return 180;
105                 case _CONTROL_ROTATION_270:
106                         return 270;
107         }
108 }
109
110 } // Anonymous
111
112 extern "C"
113 {
114 _OSP_EXPORT_ void
115 _UiPrintControl(const _Control& control, bool printChildren, int level)
116 {
117         const_cast<_Control&>(control).PrintDescription(printChildren, level);
118 }
119
120 _OSP_EXPORT_ void
121 _UiPrintTree(int level)
122 {
123         _ControlManager* pControlManager = _ControlManager::GetInstance();
124         SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
125
126         if (pControlManager->GetWindowCount() == 0)
127         {
128                 return;
129         }
130
131         int count = pControlManager->GetWindowCount();
132         for (int i = 0; i < count; i++)
133         {
134                 _Window* pWindow = pControlManager->GetWindow((count-1) - i);
135                 _UiPrintControl(*pWindow, true, level);
136         }
137 }
138 }
139
140 namespace Tizen { namespace Ui
141 {
142 _ControlManager* _ControlManager::__pInstance = null;
143
144 void
145 _ControlManager::Initialize(void)
146 {
147         static pthread_once_t once_block = PTHREAD_ONCE_INIT;
148
149         if (!__pInstance)
150         {
151                 pthread_once(&once_block, InitInstance);
152         }
153
154         result r = _SettingInfoImpl::AddSettingEventListenerForInternal(*__pInstance);
155         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
156
157         // [ToDo] Is it OK to directly get the device orientation?
158         int degree = app_get_device_orientation();
159         SysLog(NID_UI, "The initial value of device orientation is %d.", degree);
160
161         __pInstance->__screenRotation = ::Convert(degree);
162
163         elm_init(0, null);
164 }
165
166 void
167 _ControlManager::Release(void)
168 {
169         result  r = _SettingInfoImpl::RemoveSettingEventListenerForInternal(*__pInstance);
170         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
171
172         delete __pInstance;
173         __pInstance = null;
174
175         elm_shutdown();
176 }
177
178 _ControlManager*
179 _ControlManager::GetInstance(void)
180 {
181         return __pInstance;
182 }
183
184 void
185 _ControlManager::InitInstance(void)
186 {
187         if (__pInstance)
188         {
189                 return;
190         }
191
192         __pInstance = new (std::nothrow) _ControlManager;
193         SysAssert(__pInstance);
194 }
195
196 _ControlHandle
197 _ControlManager::Register(_Control* pObject)
198 {
199         if (pObject)
200         {
201                 SysLog(NID_UI, "A _Control Registered()");
202         }
203
204         if (pObject == null)
205         {
206                 return _ControlHandle();
207         }
208
209         return __objectManager.Register(*pObject);
210 }
211
212 _Control*
213 _ControlManager::Release(const _ControlHandle& handle)
214 {
215         _Control* pObject = GetObject(handle);
216         if (pObject)
217         {
218                 SysLog(NID_UI, "A _Control Released()");
219         }
220
221         return __objectManager.Unregister(handle);
222 }
223
224 _Control*
225 _ControlManager::GetObject(const _ControlHandle& handle)
226 {
227         return __objectManager.GetObject(handle);
228 }
229
230 const _Control*
231 _ControlManager::GetObject(const _ControlHandle& handle) const
232 {
233         return __objectManager.GetObject(handle);
234 }
235
236 int
237 _ControlManager::GetUsedHandleCount(void) const
238 {
239         return __objectManager.GetObjectCount();
240 }
241
242 result
243 _ControlManager::GetAppCoordinateSystem(bool& isCoordinateSystemLogical, int& logicalCoordinateSystemInt, _BaseScreenSize& logicalBaseScreenSize)
244 {
245         _PackageInfoImpl infoImpl;
246         {
247                 String subAppId(_AppInfo::GetPackageId());
248
249                 result r = infoImpl.Construct(subAppId);
250                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
251         }
252
253         String baseScreenSize(null);
254         String coordinateSystem(null);
255         String logicalCoordinate(null);
256
257         result r = infoImpl.GetUiScalabilityInfo(baseScreenSize, coordinateSystem, logicalCoordinate);
258         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
259
260         if (coordinateSystem.Equals(L"Physical", false))
261         {
262                 isCoordinateSystemLogical = false;
263                 logicalCoordinateSystemInt = 0;
264                 logicalBaseScreenSize = BASE_SCREEN_SIZE_DEFAULT;
265
266                 return E_SUCCESS;
267         }
268
269         //Logical Resolution
270         r = Integer::Parse(logicalCoordinate, logicalCoordinateSystemInt);
271         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
272
273         // BaseScreenSize
274         if (baseScreenSize.Equals(L"Large", false))
275         {
276                 logicalBaseScreenSize = BASE_SCREEN_SIZE_LARGE;
277         }
278         else // temp
279         {
280                 logicalBaseScreenSize = BASE_SCREEN_SIZE_NORMAL;
281         }
282
283         return r;
284 }
285
286 bool
287 _ControlManager::IsCoordinateSystemLogical(void) const
288 {
289         return __isCoordinateSystemLogical;
290 }
291
292 int
293 _ControlManager::GetCoordinateSystem(void) const
294 {
295         return __logicalCoordinateSystem;
296 }
297
298 _BaseScreenSize
299 _ControlManager::GetLogicalBaseScreenSize(void) const
300 {
301         return __logicalBaseScreenSize;
302 }
303
304 _ControlManager::_ControlManager(void) // [ToDo] exception check.
305         : __pWindowList(null)
306         , __isCoordinateSystemLogical(true)
307         , __logicalCoordinateSystem(0)
308         , __logicalBaseScreenSize(BASE_SCREEN_SIZE_NONE)
309         , __pSystemWindowList(null)
310         , __pFocusedControl(null)
311         , __screenRotation(_CONTROL_ROTATION_0)
312         , __orientationStatus(_CONTROL_ROTATION_0)
313         , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
314         , __pCurrentFrame(null)
315         , __pGestureList(null)
316         , __gestureMaxDuration(0)
317         , __touchedWindow(0)
318         , __isDefaultFontChanged(false)
319         , __defaultFontName(L"")
320         , __screenDpi(0)
321 {
322         result r = GetAppCoordinateSystem(__isCoordinateSystemLogical, __logicalCoordinateSystem, __logicalBaseScreenSize);
323         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
324
325         Dimension deviceResolution = CoordinateSystem::GetPhysicalResolution();
326         _BaseScreenSize deviceBaseScreenSize = _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize();
327
328         r = _CoordinateSystem::Initialize(__logicalCoordinateSystem, __logicalBaseScreenSize, deviceResolution, deviceBaseScreenSize);
329         SysAssert(r == E_SUCCESS);
330
331         r = _AnimationManager::CreateInstance();
332         SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
333
334         r = _DisplayManager::CreateInstance();
335         SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
336
337         _EcoreEvas::CreateInstanceN();
338
339         __pWindowList = new (std::nothrow)LinkedListT<_Window*>;
340         SysTryCatch(NID_UI, __pWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
341
342         __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
343         SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
344
345         _UiEventManager::Initialize();
346         _TouchManager::Initialize();
347         _KeyEventManager::Initialize();
348         _IndicatorManager::InitializeInstance();
349         _AccessibilityManager::CreateInstance();
350         InitializeScreenDpi();
351
352         SetLastResult(E_SUCCESS);
353
354         return;
355
356 CATCH:
357         _AnimationManager::ReleaseInstance();
358
359         if (__pWindowList)
360         {
361                 delete __pWindowList;
362                 __pWindowList = null;
363         }
364
365         if (__pGestureList)
366         {
367                 delete __pGestureList;
368                 __pGestureList = null;
369         }
370 }
371
372 _ControlManager::~_ControlManager(void)
373 {
374         _Clipboard::ReleaseInstance();
375
376         if (__pWindowList)
377         {
378                 delete __pWindowList;
379                 __pWindowList = null;
380         }
381
382         if (__pGestureList)
383         {
384                 delete __pGestureList;
385                 __pGestureList = null;
386         }
387
388         DestroyEcoreEvasMgr();
389
390         if (GetUsedHandleCount() != 0)
391         {
392                 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
393         }
394
395
396         _IndicatorManager::ReleaseInstance();
397
398         _DisplayManager::ReleaseInstance();
399
400         _AnimationManager::ReleaseInstance();
401
402         _AccessibilityManager::ReleaseInstance();
403
404         _KeyEventManager::ReleaseInstance();
405         _TouchManager::ReleaseInstance();
406         _UiEventManager::Release();
407 }
408
409 _Window*
410 _ControlManager::GetTopWindow(void) const
411 {
412         ClearLastResult();
413
414         if (GetWindowCount() == 0)
415         {
416                 return null;
417         }
418
419         return GetWindow(GetWindowCount() - 1);
420 }
421
422 _Window*
423 _ControlManager::GetTopVisibleWindow(void) const
424 {
425         ClearLastResult();
426
427         if (GetWindowCount() == 0)
428         {
429                 return null;
430         }
431
432         int count = GetWindowCount();
433         for (int i = 0; i < count; i++)
434         {
435                 _Window* pWindow = GetWindow((count-1) - i);
436
437                 if (pWindow->GetVisibleState() == true)
438                 {
439                         return pWindow;
440                 }
441         }
442
443         return null;
444 }
445
446 _Window*
447 _ControlManager::GetTopVisibleWindowAt(const Point& point) const
448 {
449         ClearLastResult();
450
451         if (GetWindowCount() == 0)
452         {
453                 return null;
454         }
455
456         int count = GetWindowCount();
457         for (int i = 0; i < count; i++)
458         {
459                 _Window* pWindow = GetWindow((count-1) - i);
460
461                 if (pWindow->GetVisibleState() == false)
462                 {
463                         continue;
464                 }
465
466                 Rectangle winBounds = pWindow->GetBounds();
467                 if (winBounds.Contains(point))
468                 {
469                         return pWindow;
470                 }
471         }
472
473         return null;
474 }
475
476 bool
477 _ControlManager::IsWindowOnTop(const _Window& window) const
478 {
479         return GetTopWindow() == &window;
480 }
481
482 bool
483 _ControlManager::IsWindowAttached(const _Window& window) const
484 {
485         return __pWindowList->Contains(const_cast<_Window*>(&window));
486 }
487
488 // Open a window and bring it to top.
489 result
490 _ControlManager::OpenWindow(_Window& window, bool invalidate)
491 {
492         if (dynamic_cast <_Frame*>(&window) != null)
493         {
494                 __pCurrentFrame = &window;
495         }
496
497         result r = ActivateWindow(window);
498         SysTryReturn(NID_UI, r != E_INVALID_OPERATION, r, r, "[%s] Propagating.", GetErrorMessage(r));
499         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
500
501         if (invalidate)
502         {
503                 window.Invalidate(true);
504         }
505
506         return E_SUCCESS;
507 }
508
509 result
510 _ControlManager::ActivateWindow(_Window& window)
511 {
512         ClearLastResult();
513         result r = E_SUCCESS;
514
515         if (IsWindowOnTop(window))
516         {
517                 return E_SUCCESS;
518         }
519
520         if (window.IsActivationEnabled())
521         {
522                 _Window* pTopWindow = GetTopWindow();
523                 if (pTopWindow)
524                 {
525                         pTopWindow->Deactivate();
526                 }
527         }
528
529         if (IsWindowAttached(window))
530         {
531                 r = MoveWindowToTop(window); // [ToDo] excpetion
532                 SysAssert(r == E_SUCCESS);
533
534                 return E_SUCCESS;
535         }
536
537         r = window.GetControlDelegate().OnAttaching(null);
538         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
539
540         r = CallOnAttachingToMainTree(window);
541         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
542
543         r = AttachWindow(window);
544         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
545
546         if (window.IsActivationEnabled())
547         {
548                 window.Activate();
549         }
550
551         if (window.IsOrientationRoot() == false)
552         {
553 #if !defined(WINDOW_BASE_ROTATE)
554                 window.ChangeLayout(GetOrientation());
555
556                 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
557                 if (pEcoreEvas)
558                 {
559                         pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
560                 }
561 #else
562                 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
563                 if (pEcoreEvas)
564                 {
565                         pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
566                 }
567 #endif
568         }
569
570         r = window.GetControlDelegate().OnAttached();
571         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
572
573         r = CallOnAttachedToMainTree(window);
574         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
575
576         return E_SUCCESS;
577 }
578
579 result
580 _ControlManager::CallOnAttachingToMainTree(_Control& control)
581 {
582         result r = E_SUCCESS;
583
584         r = control.GetControlDelegate().OnAttachingToMainTree(null);
585         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
586
587         _Control::ControlList& children = control.GetChildList();
588         _Control* pChild = null;
589
590         for (int index = 0; index < children.GetCount(); index++)
591         {
592                 r = children.GetAt(index, pChild);
593                 if (IsFailed(r))
594                 {
595                         SysAssert(r == E_OUT_OF_RANGE);
596                         SysTryReturn(NID_UI,
597                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
598                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
599                 }
600                 r = CallOnAttachingToMainTree(*pChild);
601                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
602         }
603
604         return r;
605 }
606
607 result
608 _ControlManager::CallOnAttachedToMainTree(_Control& control)
609 {
610         result r = E_SUCCESS;
611
612         _Control* pChild = null;
613         _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
614         pControlList->Construct(control.GetChildList());
615
616         r = control.GetControlDelegate().OnAttachedToMainTree();
617         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
618
619         for (int index = 0; index < pControlList->GetCount(); index++)
620         {
621                 r = pControlList->GetAt(index, pChild);
622                 if (IsFailed(r))
623                 {
624                         SysAssert(r == E_OUT_OF_RANGE);
625                         SysTryReturn(NID_UI,
626                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
627                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
628                 }
629                 r = control.CallOnAttachedToMainTree(*pChild);
630                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
631         }
632
633         delete pControlList;
634
635         return r;
636 }
637
638 result
639 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
640 {
641         result r = E_SUCCESS;
642
643         _Control* pChild = null;
644         _Control::ControlList& children = control.GetChildList();
645
646         r = control.GetControlDelegate().OnDetachingFromMainTree();
647         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
648
649         for (int index = 0; index < children.GetCount(); index++)
650         {
651                 r = children.GetAt(index, pChild);
652                 if (IsFailed(r))
653                 {
654                         SysAssert(r == E_OUT_OF_RANGE);
655                         SysTryReturn(NID_UI,
656                                 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
657                                 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
658                 }
659                 r = CallOnDetachingFromMainTree(*pChild);
660                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
661         }
662
663         return r;
664 }
665
666 result
667 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
668 {
669         ClearLastResult();
670         result r = E_SUCCESS;
671
672         if (IsWindowAttached(window) == false)
673         {
674                 return E_SUCCESS;
675         }
676
677         bool wasWindowOnTop = IsWindowOnTop(window);
678
679         r = CallOnDetachingFromMainTree(window);
680         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
681
682         window.GetControlDelegate().OnDetaching();
683
684         window.Deactivate();
685
686         r = DetachWindow(window);
687         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
688
689         if (wasWindowOnTop)
690         {
691                 _Window* pNewTopWindow = GetTopWindow();
692                 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
693                 {
694                         pNewTopWindow->Activate();
695                 }
696
697                 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
698                 {
699                         __pCurrentFrame = pNewTopWindow;
700                 }
701         }
702
703         return E_SUCCESS;
704 }
705
706 _Window*
707 _ControlManager::GetWindow(int index) const
708 {
709         _Window* pWindow;
710         __pWindowList->GetAt(index, pWindow);
711
712         return pWindow;
713 }
714
715 int
716 _ControlManager::GetWindowCount(void) const
717 {
718         return __pWindowList->GetCount();
719 }
720
721 result
722 _ControlManager::AttachWindow(_Window& window)
723 {
724         _IndicatorManager::GetInstance()->AddWindow(&window);
725
726         return __pWindowList->Add(&window);
727 }
728
729 result
730 _ControlManager::InsertWindowToBottom(_Window& window)
731 {
732         return __pWindowList->InsertAt(&window, 0);
733 }
734
735 result
736 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
737 {
738         int index = 0;
739
740         result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
741         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
742
743         return __pWindowList->InsertAt(&window, index+1);
744 }
745
746 result
747 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
748 {
749         int index = 0;
750
751         result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
752         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
753
754         return __pWindowList->InsertAt(&window, index);
755 }
756
757 result
758 _ControlManager::DetachWindow(_Window& window)
759 {
760         _IndicatorManager::GetInstance()->DeleteWindow(&window);
761
762         return __pWindowList->Remove(&window);
763 }
764
765 void
766 _ControlManager::DetachAllWindows(void)
767 {
768         __pWindowList->RemoveAll();
769 }
770
771 result
772 _ControlManager::MoveWindowToTop(const _Window& window)
773 {
774         result r = __pWindowList->Remove(const_cast<_Window*>(&window));
775         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
776
777         return __pWindowList->Add(const_cast<_Window*>(&window));
778 }
779
780 result
781 _ControlManager::MoveWindowToBottom(const _Window& window)
782 {
783         result r = __pWindowList->Remove(const_cast<_Window*>(&window));
784         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
785
786         return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
787 }
788
789 result
790 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
791 {
792         result r = __pWindowList->Remove(const_cast<_Window*>(&window));
793         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
794
795         int index = 0;
796
797         r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
798         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
799
800         return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
801 }
802
803 result
804 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
805 {
806         result r = __pWindowList->Remove(const_cast<_Window*>(&window));
807         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
808
809         int index = 0;
810
811         r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
812         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
813
814         return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
815 }
816
817 _ControlOrientation
818 _ControlManager::GetOrientation(void) const
819 {
820         return __orientation;
821 }
822
823 void
824 _ControlManager::SetOrientation(_ControlOrientation orientation)
825 {
826         __orientation = orientation;
827 }
828
829 _ControlRotation
830 _ControlManager::GetScreenRotation(void) const
831 {
832         bool autoRotate = true;
833         int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
834
835         if (ret == RUNTIME_INFO_ERROR_NONE)
836         {
837                 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
838         }
839         else
840         {
841                 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
842         }
843
844         SysLog(NID_UI, "[Window Manager Rotation] AUTO_ROTATION = %d", autoRotate);
845
846         if (autoRotate == false)
847         {
848                 return _CONTROL_ROTATION_0;
849         }
850         else
851         {
852 #if defined(WINDOW_BASE_ROTATE)
853 //              int degree = app_get_device_orientation();
854
855                 unsigned long rotationState = 0;
856                 int ret = sf_check_rotation(&rotationState);
857                 int device_rotation = 0;
858
859                 if (ret == 0)
860                 {
861                         switch (rotationState)
862                         {
863                         case ROTATION_EVENT_0:
864                                 device_rotation = 0;
865                                 break;
866                         case ROTATION_EVENT_90:
867                                 device_rotation = 270;
868                                 break;
869                         case ROTATION_EVENT_180:
870                                 device_rotation = 180;
871                                 break;
872                         case ROTATION_EVENT_270:
873                                 device_rotation = 90;
874                                 break;
875                         default:
876                                 break;
877                         }
878
879                         SysLog(NID_UI, "[Window Manager Rotation] device_rotation = %d", device_rotation);
880                 }
881                 else
882                 {
883                         SysLog(NID_UI, "[Window Manager Rotation] device_rotation = error");
884                 }
885
886                 return ::Convert(device_rotation);
887 #else
888                 return __screenRotation;
889 #endif
890         }
891 }
892
893 void
894 _ControlManager::OnScreenRotated(int rotation)
895 {
896         SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
897         __screenRotation = ::Convert(rotation);
898
899         int count = GetWindowCount();
900         for (int i = 0; i < count; i++)
901         {
902                 _Window* pWindow = GetWindow((count-1) - i);
903
904                 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
905
906                 if (pFrame)
907                 {
908                         Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
909                         if (pFrameImpl == null)
910                         {
911                                 continue;
912                         }
913
914                         Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
915                         if (pCurrentFormImpl)
916                         {
917                                 pCurrentFormImpl->UpdateOrientationStatus(true);
918                         }
919                         else
920                         {
921                                 pFrameImpl->UpdateOrientationStatus();
922                         }
923                 }
924         }
925 }
926
927 void
928 _ControlManager::SetTouchedWindow(unsigned int window)
929 {
930         __touchedWindow = window;
931 }
932
933 _Window*
934 _ControlManager::GetTouchedWindow(void) const
935 {
936         ClearLastResult();
937
938         if (GetWindowCount() == 0)
939         {
940                 return null;
941         }
942
943         int count = GetWindowCount();
944         for (int i = 0; i < count; i++)
945         {
946                 _Window* pWindow = GetWindow((count-1) - i);
947
948                 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
949                 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
950
951                 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
952                 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
953
954                 if (win == __touchedWindow)
955                 {
956                         return pWindow;
957                 }
958         }
959
960         return null;
961 }
962
963 void
964 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
965 {
966         __orientationStatus = orientationStatus;
967 }
968
969 _ControlRotation
970 _ControlManager::GetOrientationStatus(void) const
971 {
972         return __orientationStatus;
973 }
974
975 void
976 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
977 {
978         // Non-auto mode
979         // Rotate window
980         // Set window preferred rotation
981
982         _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
983         SysAssert(pEcoreEvas);
984         if (pEcoreEvas == null)
985         {
986                 return;
987         }
988
989         // Rotate root window.
990         _Window* pRootWindow = control.GetRootWindow();
991         if (pRootWindow)
992         {
993                 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
994                 pRootWindow->SetRotation(::Convert(screenRotation));
995         }
996
997 #if !defined(WINDOW_BASE_ROTATE)
998         // Rotate Ownees.
999         int owneeCount = control.GetOwneeCount();
1000         for (int i = 0; i < owneeCount; i++)
1001         {
1002                 _Window* pOwnee = control.GetOwnee(i);
1003                 if (pOwnee)
1004                 {
1005                         pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
1006                 }
1007         }
1008 #endif
1009
1010         if (__orientationStatus != screenRotation)
1011         {
1012                 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1013                 if (pTouchManager)
1014                 {
1015                         pTouchManager->SetTouchCanceled(true);
1016                 }
1017         }
1018 }
1019
1020 void
1021 _ControlManager::OnWindowRotated(int rotation)
1022 {
1023         // For non-ownees
1024         IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
1025         SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1026
1027         while (pEnumerator->MoveNext() == E_SUCCESS)
1028         {
1029                 _Window* pWindow = null;
1030                 pEnumerator->GetCurrent(pWindow);
1031
1032                 if (pWindow->GetOwner() == null)
1033                 {
1034                         void* pUserData = pWindow->GetUserData();
1035                         if (pUserData)
1036                         {
1037                                 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1038                                 pWindowImpl->OnRotated(Convert(rotation));
1039                         }
1040                 }
1041         }
1042
1043         delete pEnumerator;
1044 }
1045
1046 void
1047 _ControlManager::SetFocusedControl(const _Control& control, bool on)
1048 {
1049         if (on)
1050         {
1051                 if (__pFocusedControl == &control)
1052                 {
1053                         return;
1054                 }
1055
1056                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1057                 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1058
1059                 _Control *pPreviousFocusedControl = __pFocusedControl;
1060                 if (pPreviousFocusedControl)
1061                 {
1062                         // [review] make SetFocus() return result and use the returned result here.
1063                         pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1064                         if (GetLastResult() == E_SUCCESS)
1065                         {
1066                                 if (pPreviousFocusedControl)
1067                                 {
1068                                         pPreviousFocusedControl->SetFocusState(false);
1069                                 }
1070                                 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1071                                 _UiEventManager::GetInstance()->SendEvent(event);
1072                         }
1073                 }
1074
1075                 // [review] make SetFocus() return result and use the returned result here.
1076
1077                 if (control.IsNativeObjectFocusable())
1078                 {
1079                         pEcoreEvas->SetFocus(control, true);
1080                 }
1081
1082                 if (GetLastResult() == E_SUCCESS)
1083                 {
1084                         __pFocusedControl = const_cast<_Control*>(&control);
1085                         _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1086                         _UiEventManager::GetInstance()->SendEvent(event);
1087                 }
1088         }
1089         else
1090         {
1091                 if (__pFocusedControl != &control)
1092                 {
1093                         return;
1094                 }
1095
1096                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1097                 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1098
1099                 if (__pFocusedControl)
1100                 {
1101                         // [review] make SetFocus() return result and use the returned result here.
1102                         pEcoreEvas->SetFocus(*__pFocusedControl, false);
1103                         if (GetLastResult() == E_SUCCESS)
1104                         {
1105                                 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1106                                 _UiEventManager::GetInstance()->SendEvent(event);
1107                         }
1108                 }
1109
1110                 _Window* pTopWindow = GetTopWindow();
1111                 if (pTopWindow)
1112                 {
1113                         // [review] make SetFocus() return result and use the returned result here.
1114                         pEcoreEvas->SetFocus(*pTopWindow, true);
1115                         if (GetLastResult() == E_SUCCESS)
1116                         {
1117                                 pTopWindow->SetFocusState(true);
1118                                 _UiFocusEvent event(pTopWindow->GetHandle(), FOCUS_GAINED);
1119                                 _UiEventManager::GetInstance()->SendEvent(event);
1120                         }
1121
1122                         __pFocusedControl = static_cast<_Control*>(pTopWindow);
1123                 }
1124         }
1125 }
1126
1127 // [review] called in ~_Control and virtual OnFocusLost is called.
1128 // _Control::Release() instead of ~_Control.
1129 bool
1130 _ControlManager::TakeFocusFromControl(const _Control& control)
1131 {
1132         if (__pFocusedControl == &control)
1133         {
1134                 _Control *pPreviousFocusedControl = __pFocusedControl;
1135                 __pFocusedControl = null;
1136                 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1137                 _UiEventManager::GetInstance()->SendEvent(event);
1138
1139                 return true;
1140         }
1141
1142         return false;
1143 }
1144
1145 _Control*
1146 _ControlManager::GetFocusedControl(void) const
1147 {
1148         return __pFocusedControl;
1149 }
1150
1151 _Control*
1152 _ControlManager::GetTopmostTouchedControl(const Point& point)
1153 {
1154         _Control* pControl = null;
1155         _Window* pTopWindow = null;
1156
1157         int count = GetWindowCount();
1158         if (count != 0)
1159         {
1160                 for (int i = 0; i < count; i++)
1161                 {
1162                         _Window* pWindow = GetWindow((count-1) - i);
1163
1164                         if (pWindow->GetVisibleState() == false)
1165                         {
1166                                 continue;
1167                         }
1168
1169                         _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1170                         _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1171
1172                         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1173                         Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1174
1175                         Rectangle winDeviceBounds(0, 0, 0, 0);
1176                         ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1177
1178                         Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1179
1180                         Point devicePoint = _CoordinateSystemUtils::Transform(point);
1181                         int x = devicePoint.x;
1182                         int y = devicePoint.y;
1183
1184                         int rootW = 0;
1185                         int rootH = 0;
1186                         ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1187
1188                         int rotation = ecore_evas_rotation_get(pEcoreEvas);
1189                         switch (rotation)
1190                         {
1191                         case 270:
1192                                 devicePoint.x = rootW - y;
1193                                 devicePoint.y = x;
1194                                 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1195                                 winDeviceBounds.y = winDevicePoint.x;
1196                                 break;
1197                         case 180:
1198                                 devicePoint.x = rootW - x;
1199                                 devicePoint.y = rootH - y;
1200                                 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1201                                 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1202                                 break;
1203                         case 90:
1204                                 devicePoint.x = y;
1205                                 devicePoint.y = rootH - x;
1206                                 winDeviceBounds.x = winDevicePoint.y;
1207                                 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1208                                 break;
1209                         default:
1210                                 devicePoint.x = x;
1211                                 devicePoint.y = y;
1212                                 winDeviceBounds.x = winDevicePoint.x;
1213                                 winDeviceBounds.y = winDevicePoint.y;
1214                                 break;
1215                         }
1216
1217                         if (winDeviceBounds.Contains(devicePoint))
1218                         {
1219                                 pTopWindow = pWindow;
1220                                 break;
1221                         }
1222                 }
1223         }
1224
1225         if (pTopWindow != null)
1226         {
1227                 Point winPos(0, 0);
1228                 winPos = pTopWindow->GetPosition();
1229
1230                 Point relPos(point.x - winPos.x, point.y - winPos.y);
1231                 pControl = pTopWindow->GetTopmostChildAt(relPos);
1232                 if (pControl != null)
1233                 {
1234                         if (pControl->GetRootWindow() == pTopWindow)
1235                         {
1236                                 return pControl;
1237                         }
1238                 }
1239         }
1240
1241         return null;
1242 }
1243
1244 // [review] rename __InvXformer
1245 Dimension
1246 _ControlManager::GetScreenSize(void) const
1247 {
1248         return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1249 }
1250
1251 FloatDimension
1252 _ControlManager::GetScreenSizeF(void) const
1253 {
1254         return _CoordinateSystemUtils::InverseTransform(FloatDimension(_Screen::GetWidth(), _Screen::GetHeight()));
1255 }
1256
1257 void
1258 _ControlManager::InitializeScreenDpi()
1259 {
1260         Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.dpi", __screenDpi);
1261 }
1262
1263 int
1264 _ControlManager::GetScreenDpi() const
1265 {
1266         return __screenDpi;
1267 }
1268
1269 _Window*
1270 _ControlManager::GetCurrentFrame(void) const
1271 {
1272         return __pCurrentFrame;
1273 }
1274
1275 result
1276 _ControlManager::SetDefaultFont(const String& appFontName)
1277 {
1278
1279         if(appFontName.Equals(__defaultFontName))
1280         {
1281                 return E_SUCCESS;
1282         }
1283
1284         __isDefaultFontChanged = true;
1285         __defaultFontName = appFontName;
1286         __defaultFontFileName.Clear();
1287
1288         struct _Visitor
1289                 : public _Control::Visitor
1290         {
1291                  virtual _Control::VisitType Visit(_Control& control)
1292                 {
1293                         if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1294                         {
1295                                 control.GetFallbackFont();
1296                                 _IControlDelegate& delegate = control.GetControlDelegate();
1297                                 delegate.OnFontChanged(control.__pFont);
1298                         }
1299                         return _Control::VISIT_DOWNWARD;
1300                 }
1301         };
1302
1303         _Visitor visitor;
1304
1305         int count = GetWindowCount();
1306         for (int j = 0; j < count; j++)
1307         {
1308                 _Window* pWindow = GetWindow((count-1) - j);
1309                 pWindow->Accept(visitor);
1310         }
1311
1312         SetDefaultFontChangeState(false);
1313
1314         return E_SUCCESS;
1315 }
1316
1317 Tizen::Base::String
1318 _ControlManager::GetDefaultFont(void)
1319 {
1320         return __defaultFontName;
1321 }
1322
1323 result
1324 _ControlManager::SetDefaultFontFromFile(const Tizen::Base::String& fileName)
1325 {
1326         if(fileName.Equals(__defaultFontFileName))
1327         {
1328                 return E_SUCCESS;
1329         }
1330
1331         __isDefaultFontChanged = true;
1332         __defaultFontFileName = fileName;
1333         __defaultFontName.Clear();
1334         struct _Visitor
1335                 : public _Control::Visitor
1336         {
1337                  virtual _Control::VisitType Visit(_Control& control)
1338                 {
1339                         if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1340                         {
1341                                 control.GetFallbackFont();
1342                                 _IControlDelegate& delegate = control.GetControlDelegate();
1343                                 delegate.OnFontChanged(control.__pFont);
1344                         }
1345                         return _Control::VISIT_DOWNWARD;
1346                 }
1347         };
1348
1349         _Visitor visitor;
1350
1351         int count = GetWindowCount();
1352         for (int j = 0; j < count; j++)
1353         {
1354                 _Window* pWindow = GetWindow((count-1) - j);
1355                 pWindow->Accept(visitor);
1356         }
1357
1358         SetDefaultFontChangeState(false);
1359
1360         return E_SUCCESS;
1361 }
1362 String
1363 _ControlManager::GetDefaultFontFile(void) const
1364 {
1365         return __defaultFontFileName;
1366 }
1367 bool
1368 _ControlManager::IsDefaultFontChanged(void)
1369 {
1370         return __isDefaultFontChanged;
1371 }
1372
1373 void
1374 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1375 {
1376         __isDefaultFontChanged = isDefaultFontChanged;
1377 }
1378
1379 bool
1380 _ControlManager::IsFrameActivated(void) const
1381 {
1382         _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1383         SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1384
1385         return pFrame->IsActivated();
1386 }
1387
1388 // [review] refactoring
1389 result
1390 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1391 {
1392         ClearLastResult();
1393
1394         SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1395
1396         bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1397         SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1398
1399         result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1400         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1401
1402         switch (gesture.GetDetectorType())
1403         {
1404                 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1405                 {
1406                         _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1407                         SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1408
1409                         if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1410                         {
1411                                 __gestureMaxDuration = pGestureTap->GetTapInterval();
1412                         }
1413                 }
1414                 break;
1415                 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1416                 {
1417                         _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1418                         SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1419
1420                         if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1421                         {
1422                                 __gestureMaxDuration = pGestureLongPress->GetDuration();
1423                         }
1424                 }
1425                 break;
1426                 default:
1427                         break;
1428         }
1429
1430         return E_SUCCESS;
1431 }
1432
1433 result
1434 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1435 {
1436         ClearLastResult();
1437
1438         result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1439         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1440
1441         return E_SUCCESS;
1442 }
1443
1444 IListT <_TouchGestureDetector*>*
1445 _ControlManager::GetGestureDetectorList(void) const
1446 {
1447         return __pGestureList;
1448 }
1449
1450 int
1451 _ControlManager::GetGestureMaxTimeDuration(void) const
1452 {
1453         return __gestureMaxDuration;
1454 }
1455
1456 void
1457 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1458 {
1459         const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1460         const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1461         const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1462
1463          if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1464         {
1465                 _FontImpl::UpdateDefaultFont(key);
1466
1467                 int count = GetWindowCount();
1468
1469                 for(int index = 0; index < count ; index++)
1470                 {
1471                         _Window* pWindow = GetWindow(index);
1472                         pWindow->Invalidate(true);
1473                 }
1474         }
1475
1476         //fixme : check longpress duration key
1477         //if (key == )
1478         {
1479                 if (!__pGestureList || (__pGestureList && (__pGestureList->GetCount() <= 0)))
1480                 {
1481                         return;
1482                 }
1483
1484                 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = __pGestureList->GetEnumeratorN();
1485                 SysTryReturnVoidResult(NID_UI, pEnumerator, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1486
1487                 int duration = static_cast<int>(elm_config_longpress_timeout_get() * 1000);
1488                 if (duration == 0)
1489                 {
1490                         duration = 500;
1491                 }
1492
1493                 while (pEnumerator->MoveNext() == E_SUCCESS)
1494                 {
1495                         _TouchGestureDetector* pGestureDetector = null;
1496                         pEnumerator->GetCurrent(pGestureDetector);
1497
1498                         if (!pGestureDetector)
1499                         {
1500                                 continue;
1501                         }
1502
1503                         if(pGestureDetector->GetDetectorType() == _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS)
1504                         {
1505                                 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(pGestureDetector));
1506                                 SysTryReturnVoidResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1507                                 pGestureLongPress->SetDuration(duration);
1508                         }
1509                 }
1510
1511                 delete pEnumerator;
1512         }
1513 }
1514
1515 }} // Tizen::Ui