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