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