Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUi_ControlImpl.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  * @file                FUi_ControlImpl.cpp
19  * @brief               This is the implementation file for _ControlImpl class.
20  */
21
22 #include <FBaseColArrayListT.h>
23 #include <FBaseColLinkedListT.h>
24 #include <FBaseRtIEventListener.h>
25 #include <FBaseRtITimerEventListener.h>
26 #include <FUiIDragDropEventListener.h>
27 #include <FUiAccessibilityContainer.h>
28 #include <FUiAnimControlAnimator.h>
29 #include <FUiTouchGestureDetector.h>
30 #include <FApp_AppInfo.h>
31 #include <FBaseSysLog.h>
32 #include <FBase_Log.h>
33 #include "FUi_ControlImpl.h"
34 #include "FUi_ContainerImpl.h"
35 #include "FUi_Control.h"
36 #include "FUi_ControlManager.h"
37 #include "FUi_ControlImplManager.h"
38 #include "FUi_UiEventManager.h"
39 #include "FUi_UiNotificationEvent.h"
40 #include "FUi_UiTouchEvent.h"
41 #include "FUi_TouchManager.h"
42 #include "FUi_TouchEventArg.h"
43 #include "FUi_ITouchLongPressGestureEventListener.h"
44 #include "FUi_TouchFlickGestureDetector.h"
45 #include "FUi_TouchGestureDetectorImpl.h"
46 #include "FUi_AccessibilityContainerImpl.h"
47 #include "FUi_ResourceManager.h"
48 #if defined(MULTI_WINDOW)
49 #include "FUi_WindowImpl.h"
50 #endif
51 #include "FUiAnim_VisualElement.h"
52 #include "FUiAnim_VisualElementImpl.h"
53
54 //#define _TC_PASS
55
56 using namespace Tizen::Base;
57 using namespace Tizen::Base::Collection;
58 using namespace Tizen::Base::Runtime;
59 using namespace Tizen::Graphics;
60 using namespace Tizen::Ui::Animations;
61 using namespace Tizen::App;
62 using namespace Tizen::Base::Utility;
63
64 namespace Tizen { namespace Ui {
65
66 _ControlImpl::SizeInfo::~SizeInfo(void)
67 {
68 }
69
70 Dimension
71 _ControlImpl::SizeInfo::GetDefaultMinimumSize(_ControlOrientation orientation) const
72 {
73         return Dimension(0, 0);
74 }
75
76 Dimension
77 _ControlImpl::SizeInfo::GetDefaultMaximumSize(_ControlOrientation orientation) const
78 {
79         return Dimension(_Control::MAX_LENGTH, _Control::MAX_LENGTH);
80 }
81
82 Dimension
83 _ControlImpl::SizeInfo::GetMinimumSizeLimit(_ControlOrientation orientation) const
84 {
85         return Dimension(0, 0);
86 }
87
88 Dimension
89 _ControlImpl::SizeInfo::GetMaximumSizeLimit(_ControlOrientation orientation) const
90 {
91         return Dimension(_Control::MAX_LENGTH, _Control::MAX_LENGTH);
92 }
93
94 result
95 _ControlImpl::SizeInfo::CheckInitialSizeValid(const Dimension& size, _ControlOrientation orientation) const
96 {
97         ClearLastResult();
98
99         const Dimension minSize = GetDefaultMinimumSize(orientation);
100         const Dimension maxSize = GetDefaultMaximumSize(orientation);
101
102         SysTryReturn(NID_UI,
103                 (minSize.width <= size.width) && (size.width <= maxSize.width), E_INVALID_ARG,
104                 E_INVALID_ARG, "[E_INVALID_ARG] The width %d is out of width range(%d ~ %d).",
105                 size.width, minSize.width, maxSize.width);
106
107         SysTryReturn(NID_UI,
108                 (minSize.height <= size.height) && (size.height <= maxSize.height), E_INVALID_ARG,
109                 E_INVALID_ARG, "[E_INVALID_ARG] The height %d is out of height range(%d ~ %d).",
110                 size.height, minSize.height, maxSize.height);
111
112         return E_SUCCESS;
113 }
114
115 const _ControlImpl::SizeInfo&
116 _ControlImpl::GetFullScreenSizeInfo(void)
117 {
118         class FullScreenSizeInfo : public _ControlImpl::SizeInfo
119         {
120         public:
121                 virtual Dimension GetDefaultMinimumSize(_ControlOrientation orientation) const
122                 {
123                         return GetScreenSize();
124                 }
125
126                 virtual Dimension GetDefaultMaximumSize(_ControlOrientation orientation) const
127                 {
128                         return GetScreenSize();
129                 }
130
131                 virtual Dimension GetMinimumSizeLimit(_ControlOrientation orientation) const
132                 {
133                         return GetScreenSize();
134                 }
135
136                 virtual Dimension GetMaximumSizeLimit(_ControlOrientation orientation) const
137                 {
138                         return GetScreenSize();
139                 }
140
141         private:
142                 Dimension GetScreenSize(void) const
143                 {
144                         _ControlManager* pMgr = _ControlManager::GetInstance();
145                         SysTryReturn(NID_UI, pMgr, Dimension(0, 0), E_SYSTEM, "[E_SYSTEM] Failed to get control manager.");
146                         return pMgr->GetScreenSize();
147                 }
148         };
149
150         static FullScreenSizeInfo sizeInfo;
151         return sizeInfo;
152 }
153
154 // [ToDo] How to turn-off callback while initializing: Reset/Set delegate?
155 result
156 _ControlImpl::InitializeBoundsProperties(const SizeInfo& sizeInfo, _ControlOrientation orientation)
157 {
158         result r = E_SUCCESS;
159
160         bool resizable = IsResizable();
161         SetResizable(true);
162
163         r = SetMinimumSize(sizeInfo.GetDefaultMinimumSize(orientation));
164         SysTryReturn(NID_UI,
165                 r == E_SUCCESS, E_SYSTEM,
166                 E_SYSTEM, "[E_SYSTEM] Failed to initialize default minimum size.");
167
168         r = SetMaximumSize(sizeInfo.GetDefaultMaximumSize(orientation));
169         SysTryReturn(NID_UI,
170                 r == E_SUCCESS, E_SYSTEM,
171                 E_SYSTEM, "[E_SYSTEM] Failed to initialize default maximum size.");
172
173         SetResizable(resizable);
174
175         return E_SUCCESS;
176 }
177
178 result
179 _ControlImpl::InitializeBoundsProperties(const SizeInfo& sizeInfo, const Tizen::Graphics::Rectangle& bounds, _ControlOrientation orientation)
180 {
181         result r = InitializeBoundsProperties(sizeInfo, orientation);
182         if (IsFailed(r))
183         {
184                 return r;
185         }
186
187         bool movable = IsMovable();
188         bool resizable = IsResizable();
189         SetMovable(true);
190         SetResizable(true);
191
192         r = SetBounds(bounds);
193
194         SetMovable(movable);
195         SetResizable(resizable);
196
197         return r;
198 }
199
200 result
201 _ControlImpl::InitializeBoundsProperties(const SizeInfo& sizeInfo, const Tizen::Graphics::Dimension& size, _ControlOrientation orientation)
202 {
203         return InitializeBoundsProperties(sizeInfo, Rectangle(0, 0, size.width, size.height), orientation);
204 }
205
206 _ControlImpl*
207 _ControlImpl::CreateControlImplN(Control& control)
208 {
209         ClearLastResult();
210         result r = E_SUCCESS;
211
212         _Control* pCore = _Control::CreateControlN();
213         r = GetLastResult();
214         SysTryReturn(NID_UI, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
215
216         _ControlImpl* pImpl = new (std::nothrow) _ControlImpl(&control, pCore);
217         r = CheckConstruction(pCore, pImpl);
218         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
219
220         return pImpl;
221 }
222
223 _ControlImpl*
224 _ControlImpl::GetInstance(Control& control)
225 {
226         return static_cast <_ControlImpl*> (control._pControlImpl);
227 }
228
229 const _ControlImpl*
230 _ControlImpl::GetInstance(const Control& control)
231 {
232         return static_cast <const _ControlImpl*> (control._pControlImpl);
233 }
234
235 result
236 _ControlImpl::CheckConstruction(_Control* pCore, _ControlImpl* pImpl)
237 {
238         if (pImpl == null)
239         {
240                 delete pCore;
241                 pCore = null;
242                 SysLogException(NID_UI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
243                 return E_OUT_OF_MEMORY;
244         }
245
246         result r = GetLastResult();
247         if (IsFailed(r))
248         {
249                 delete pImpl;
250                 pImpl = null;
251                 SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
252                 return r;
253         }
254
255         return E_SUCCESS;
256 }
257
258 const Tizen::Base::String _USER_EVENT = L"UserEvent";
259 const Tizen::Base::String _REQUEST_REDRAW_EVENT = L"RequestRedrawEvent";
260 const Tizen::Base::String _KEYBOARD_INSERTED_EVENT = L"KeyboardInsertedEvent";
261 const int keyPressTimer = 500;
262 const int doublePressTime = 330;
263 const int doublePressMoveAllowance = 10;
264
265 class _UserEventInfo
266         : public Tizen::Base::Object
267 {
268 public:
269         _UserEventInfo(RequestId requestId, const IList* pArgs)
270                 : __requestId(requestId)
271                 , __pArgs(const_cast <IList*>(pArgs))
272         {
273         }
274         virtual ~_UserEventInfo(void) {}
275
276         RequestId GetRequestId(void) const
277         {
278                 return __requestId;
279         }
280
281         IList* GetArgs(void)
282         {
283                 return __pArgs;
284         }
285
286 private:
287         _UserEventInfo(const _UserEventInfo& rhs);
288         _UserEventInfo& operator =(const _UserEventInfo& rhs);
289
290 private:
291         RequestId __requestId;
292         IList* __pArgs;
293 };
294
295 class _ControlImpl::CoreKeyEvent
296 {
297 public:
298         CoreKeyEvent(_ControlImpl& impl)
299                 : __impl(impl)
300                 , __core(impl.GetCore())
301                 , __public(impl.GetPublic())
302         {
303         }
304
305         ~CoreKeyEvent(void)
306         {
307         }
308
309 private:
310         bool IsPublicKey(_KeyCode keyCode)
311         {
312                 bool isPublicKey = false;
313
314                 if (keyCode <= _KEY_HARDWARE_MAX)
315                 {
316                         isPublicKey = true;
317                 }
318
319                 return isPublicKey;
320         }
321
322         result FirePublicListener(IKeyEventListener& listener, KeyState keyState, KeyCode keyCode)
323         {
324                 result r = E_SUCCESS;
325
326                 switch (keyState)
327                 {
328                         case KEY_PRESSED:
329                                 listener.OnKeyPressed(__public, keyCode);
330                                 break;
331                         case KEY_RELEASED:
332                                 listener.OnKeyReleased(__public, keyCode);
333                                 break;
334                         case KEY_LONGPRESSED:
335                                 listener.OnKeyLongPressed(__public, keyCode);
336                                 break;
337                         default:
338                                 SysAssert(0);
339                                 r = E_SYSTEM;
340                                 break;
341                 }
342
343                 return r;
344         }
345
346 public:
347         bool ProcessListener(KeyState keyState, _KeyCode keyCode)
348         {
349                 bool filterd = false;
350
351                 // 1. Public
352                 if (IsPublicKey(keyCode))
353                 {
354                         IEnumeratorT <IEventListener*>* pEnumerator = __impl.__pPublicKeyEventListeners->GetEnumeratorN();
355                         if (pEnumerator)
356                         {
357                                 while (pEnumerator->MoveNext() == E_SUCCESS)
358                                 {
359                                         IEventListener* pListener = null;
360                                         pEnumerator->GetCurrent(pListener);
361
362                                         IKeyEventListener* pKeyEventListener = dynamic_cast <IKeyEventListener*>(pListener);
363                                         if (pKeyEventListener)
364                                         {
365                                                 FirePublicListener(*pKeyEventListener, keyState, (KeyCode)keyCode);
366                                         }
367                                 }
368                                 delete pEnumerator;
369                         }
370                 }
371
372                 if (__impl.IsInputEventConsumed())
373                 {
374                         __impl.ResetInputEventConsumed();
375
376                         filterd = true;
377                         return filterd;
378                 }
379
380                 // 2. Default
381                 if (IsPublicKey(keyCode))
382                 {
383                         IKeyEventListener* pDefaultListener = __impl.GetDefaultKeyEventListener();
384                         if (pDefaultListener)
385                         {
386                                 FirePublicListener(*pDefaultListener, keyState, (KeyCode)keyCode);
387
388                                 if (__impl.IsInputEventConsumed())
389                                 {
390                                         __impl.ResetInputEventConsumed();
391
392                                         filterd = true;
393                                         return filterd;
394                                 }
395                         }
396                 }
397
398                 return filterd;
399         }
400
401 private:
402         CoreKeyEvent(const CoreKeyEvent& rhs);
403         CoreKeyEvent& operator =(const CoreKeyEvent& rhs);
404
405 private:
406         _ControlImpl& __impl;
407         _Control& __core;
408         Control& __public;
409 };
410
411 class _ControlImpl::CoreTouchEvent
412 {
413 public:
414         CoreTouchEvent(_ControlImpl& impl)
415                 : __impl(impl)
416                 , __core(impl.GetCore())
417                 , __public(impl.GetPublic())
418                 , __oldPreviousPressedTime(0)
419                 , __previousPressedTime(0)
420                 , __currentPressedTime(0)
421                 , __previousPressedPoint(0, 0)
422                 , __currentPressedPoint(0, 0)
423
424         {
425                 __pTouchManager = _TouchManager::GetInstance();
426                 SysTryReturnVoidResult(NID_UI, __pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
427         }
428
429         ~CoreTouchEvent(void)
430         {
431         }
432
433
434 private:
435         _TouchEventArg* GetTouchEventArgN(const _TouchInfo& touchInfo)
436         {
437                 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(__public, touchInfo.GetTouchStatus());
438                 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
439
440                 Point startPoint(__pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - __core.GetAbsoluteBounds().x,
441                                 __pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - __core.GetAbsoluteBounds().y);
442
443                 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
444                 touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
445
446                 int xDistance = 0;
447                 int yDistance = 0;
448                 __impl.__pFlickGestureDetector->GetDistance(xDistance, yDistance);
449
450                 if (xDistance != 0 || yDistance != 0)
451                 {
452                         pEventArg->SetFlickedStatus(true);
453                 }
454                 else
455                 {
456                         pEventArg->SetFlickedStatus(false);
457                 }
458
459                 return pEventArg;
460         }
461
462         result FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
463         {
464                 result r = E_SUCCESS;
465
466                 switch (touchEventInfo.GetTouchStatus())
467                 {
468                         case TOUCH_PRESSED:
469                                 listener.OnTouchPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
470                                 break;
471                         case TOUCH_LONG_PRESSED:
472                                 listener.OnTouchLongPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
473                                 break;
474                         case TOUCH_RELEASED:
475                                 listener.OnTouchReleased(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
476                                 break;
477                         case TOUCH_MOVED:
478                                 listener.OnTouchMoved(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
479                                 break;
480                         case TOUCH_DOUBLE_PRESSED:
481                                 listener.OnTouchDoublePressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
482                                 break;
483                         case TOUCH_FOCUS_IN:
484                                 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
485                                 break;
486                         case TOUCH_FOCUS_OUT:
487                                 listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
488                                 break;
489                         case TOUCH_CANCELED:
490                                 listener.OnTouchCanceled(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
491                                 break;
492                         default:
493                                 SysAssert(0);
494                                 r = E_SYSTEM;
495                                 break;
496                         }
497
498                 return r;
499         }
500
501         result FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
502         {
503                 result r = E_SUCCESS;
504
505                 _ControlManager* pControlManager = _ControlManager::GetInstance();
506                 SysTryReturn(NID_UI, pControlManager, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
507
508                 _TouchManager* pTouchManager = _TouchManager::GetInstance();
509                 SysTryReturn(NID_UI, pTouchManager, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
510
511                 Point screenPoint(pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x, pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
512
513                 _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
514                 SysTryReturn(NID_UI, pTouchedControl, E_INVALID_CONDITION, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
515
516                 if (__pTouchManager->GetFocusedControlSource() != pTouchedControl)
517                 {
518                         if (&(__core) != pTouchedControl)
519                         {
520                                 if (__pTouchManager->GetFocusedControlSource() == &(__core))
521                                 {
522                                         listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
523                                 }
524                         }
525                         else
526                         {
527                                 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
528                         }
529
530                         __pTouchManager->SetFocusedControlSource(*pTouchedControl);
531                 }
532
533                 return r;
534         }
535
536 public:
537         result ProcessDragListener(const _TouchInfo& touchInfo)
538         {
539                 if (!__core.IsDragEnabled())
540                 {
541                         return E_INVALID_CONDITION;
542                 }
543
544                 result r = E_SUCCESS;
545
546                 IEnumeratorT <IEventListener*>* pDragEnumerator = __impl.__pPublicDragDropEventListeners->GetEnumeratorN();
547                 if (pDragEnumerator)
548                 {
549                         while (pDragEnumerator->MoveNext() == E_SUCCESS)
550                         {
551                                 IEventListener* pDragListener = null;
552                                 pDragEnumerator->GetCurrent(pDragListener);
553
554                                 if (pDragListener != null)
555                                 {
556                                         IDragDropEventListener* pDragDropEventListener = dynamic_cast <IDragDropEventListener*>(pDragListener);
557                                         if (pDragDropEventListener != null)
558                                         {
559                                                 pDragDropEventListener->OnTouchDragged(__public, touchInfo.GetCurrentPosition(), touchInfo.GetCurrentPosition());
560                                         }
561                                 }
562                         }
563                         delete pDragEnumerator;
564                 }
565
566                 return r;
567         }
568
569         result ProcessDropListener(const _TouchInfo& touchInfo)
570         {
571                 if (!__core.IsDropEnabled())
572                 {
573                         return E_INVALID_CONDITION;
574                 }
575
576                 result r = E_SUCCESS;
577
578                 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
579                 if (pDraggedControl != null)
580                 {
581                         IEnumeratorT<IEventListener*>* pDropEnumerator = __impl.__pPublicDragDropEventListeners->GetEnumeratorN();
582                         if (pDropEnumerator)
583                         {
584                                 while (pDropEnumerator->MoveNext() == E_SUCCESS)
585                                 {
586                                         IEventListener* pDropListener = null;
587                                         pDropEnumerator->GetCurrent(pDropListener);
588
589                                         if (pDropListener != null)
590                                         {
591                                                 IDragDropEventListener* pDropEventListener = dynamic_cast <IDragDropEventListener*>(pDropListener);
592                                                 if (pDropEventListener != null)
593                                                 {
594                                                         pDropEventListener->OnTouchDropped(__public, __pTouchManager->GetStartPoint(touchInfo.GetPointId()), touchInfo.GetCurrentPosition());
595                                                 }
596                                         }
597                                 }
598
599                                 delete pDropEnumerator;
600                         }
601                 }
602
603                 return r;
604         }
605
606         result ProcessDropListenerToTopControl(const _TouchInfo& touchInfo)
607         {
608                 result r = E_SUCCESS;
609                 Point pt(__pTouchManager->GetScreenPoint(touchInfo.GetPointId()).x, __pTouchManager->GetScreenPoint(touchInfo.GetPointId()).y);
610
611                 _Control* pCapturedControl = __pTouchManager->GetCapturedControl();
612                 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
613                 if (!pDraggedControl || pCapturedControl)
614                 {
615                         r = E_SUCCESS;
616                         return r;
617                 }
618
619                 _Control* pTopmostTouchedSource = __core.GetTopmostChildAt(pt);
620                 if (!pTopmostTouchedSource)
621                 {
622                         r = E_SUCCESS;
623                         return r;
624                 }
625
626                 if (!pTopmostTouchedSource->IsDragEnabled())
627                 {
628                         return E_INVALID_CONDITION;
629                 }
630
631                 TouchEventInfo publicTouchInfo;
632
633                 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
634                 SysTryReturn(NID_UI, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
635
636                 publicTouchInfo.Construct(*pEventArg);
637
638                 if (pTopmostTouchedSource != pDraggedControl)
639                 {
640                         _ControlImpl* pTopmostTouchedTarget = static_cast <_ControlImpl*>(pTopmostTouchedSource->GetUserData());
641                         SysTryCatch(NID_UI, pTopmostTouchedTarget, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
642
643                         IEnumeratorT <Runtime::IEventListener*>* pDropEnumerator =
644                                 pTopmostTouchedTarget->GetDragDropEventListener()->GetEnumeratorN();
645
646                         if (pDropEnumerator)
647                         {
648                                 while (pDropEnumerator->MoveNext() == E_SUCCESS)
649                                 {
650                                         IEventListener* pDropListener = null;
651                                         pDropEnumerator->GetCurrent(pDropListener);
652
653                                         if (pDropListener != null)
654                                         {
655                                                 IDragDropEventListener* pDropEventListener = dynamic_cast <IDragDropEventListener*>(pDropListener);
656                                                 if (pDropEventListener != null)
657                                                 {
658                                                         pDropEventListener->OnTouchDropped(pTopmostTouchedTarget->GetPublic(),
659                                                                 publicTouchInfo.GetStartPosition(), touchInfo.GetCurrentPosition());
660                                                 }
661                                         }
662                                 }
663                                 delete pDropEnumerator;
664                         }
665
666                         IEnumeratorT <Runtime::IEventListener*>* pEnumerator =
667                                 pTopmostTouchedTarget->GetTouchEventListener()->GetEnumeratorN();
668
669                         if (pEnumerator)
670                         {
671                                 while (pEnumerator->MoveNext() == E_SUCCESS)
672                                 {
673                                         Runtime::IEventListener* pListener = null;
674                                         pEnumerator->GetCurrent(pListener);
675
676                                         if (pListener != null)
677                                         {
678                                                 ITouchEventListener* pPublicListener = dynamic_cast <ITouchEventListener*>(pListener);
679                                                 SysAssert(pPublicListener);
680
681                                                 pPublicListener->OnTouchReleased(pTopmostTouchedTarget->GetPublic(), touchInfo.GetCurrentPosition(), publicTouchInfo);
682                                         }
683                                 }
684                                 delete pEnumerator;
685                         }
686
687                         if (pTopmostTouchedTarget->IsInputEventConsumed())
688                         {
689                                 pTopmostTouchedTarget->ResetInputEventConsumed();
690                         }
691
692                         // 2. Default
693                         ITouchEventListener* pDefaultListener = pTopmostTouchedTarget->GetDefaultTouchEventListener();
694                         if (pDefaultListener)
695                         {
696                                 pDefaultListener->OnTouchReleased(pTopmostTouchedTarget->GetPublic(), touchInfo.GetCurrentPosition(), publicTouchInfo);
697
698                                 if (pTopmostTouchedTarget->IsInputEventConsumed())
699                                 {
700                                         pTopmostTouchedTarget->ResetInputEventConsumed();
701                                 }
702                         }
703
704                         // 3. Impl
705                         if (pTopmostTouchedTarget->OnTouchReleased(*pTopmostTouchedTarget, touchInfo))
706                         {
707                                 if (pEventArg)
708                                 {
709                                         delete pEventArg;
710                                         pEventArg = null;
711                                 }
712
713                                 return r;
714                         }
715
716                         // 4. Core
717                         pTopmostTouchedSource->OnTouchReleased(*pTopmostTouchedSource, touchInfo);
718                 }
719
720                 if (pEventArg)
721                 {
722                         delete pEventArg;
723                         pEventArg = null;
724                 }
725
726                 return r;
727
728         CATCH:
729                 if (pEventArg)
730                 {
731                         delete pEventArg;
732                         pEventArg = null;
733                 }
734
735                 return r;
736         }
737
738         bool ProcessListener(const _TouchInfo& touchInfo)
739         {
740                 bool filterd = false;
741
742                 TouchEventInfo publicTouchInfo;
743
744                 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
745                 SysTryReturn(NID_UI, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
746
747                 publicTouchInfo.Construct(*pEventArg);
748
749                 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
750
751                 // 1. Public
752                 IEnumeratorT<IEventListener*>* pEnumerator = __impl.__pPublicTouchEventListeners->GetEnumeratorN();
753                 if (pEnumerator)
754                 {
755                         while (pEnumerator->MoveNext() == E_SUCCESS)
756                         {
757                                 IEventListener* pListener = null;
758                                 pEnumerator->GetCurrent(pListener);
759
760                                 ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
761                                 if (pTouchEventListener)
762                                 {
763                                         FirePublicListener(*pTouchEventListener, publicTouchInfo);
764
765                                         if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
766                                         {
767                                                 if (pDraggedControl == null)    //if exist dragged control, don't send focus event
768                                                 {
769                                                         FireFocusListener(*pTouchEventListener, publicTouchInfo);
770                                                 }
771                                         }
772                                         else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
773                                         {
774                                                 FireFocusListener(*pTouchEventListener, publicTouchInfo);
775                                         }
776                                 }
777                                 else
778                                 {
779                                         SysAssert(pTouchEventListener);
780                                 }
781                         }
782                         delete pEnumerator;
783                 }
784
785                 if (__impl.IsInputEventConsumed())
786                 {
787                         __impl.ResetInputEventConsumed();
788
789                         if (pEventArg)
790                         {
791                                 delete pEventArg;
792                                 pEventArg = null;
793                         }
794
795                         filterd = true;
796                         return filterd;
797                 }
798
799                 // 2. Default
800                 ITouchEventListener* pDefaultListener = __impl.GetDefaultTouchEventListener();
801                 if (pDefaultListener)
802                 {
803                         FirePublicListener(*pDefaultListener, publicTouchInfo);
804
805                         if (__impl.IsInputEventConsumed())
806                         {
807                                 __impl.ResetInputEventConsumed();
808
809                                 if (pEventArg)
810                                 {
811                                         delete pEventArg;
812                                         pEventArg = null;
813                                 }
814
815                                 filterd = true;
816                                 return filterd;
817                         }
818                 }
819
820                 delete pEventArg;
821
822                 return filterd;
823         }
824
825         bool ProcessDoublePress(const _TouchInfo& touchinfo, bool& isFiltered)
826         {
827                 if (__pTouchManager->GetPointCount() == 1)
828                 {
829                         __oldPreviousPressedTime = __previousPressedTime;
830                         __previousPressedTime = __currentPressedTime;
831                         __currentPressedTime = touchinfo.GetTimeStamp();
832                         __previousPressedPoint.x = __currentPressedPoint.x;
833                         __previousPressedPoint.y = __currentPressedPoint.y;
834                         __currentPressedPoint.x = touchinfo.GetCurrentPosition().x;
835                         __currentPressedPoint.y = touchinfo.GetCurrentPosition().y;
836
837                         if (Math::Abs(__previousPressedTime - __currentPressedTime) < doublePressTime)
838                         {
839                                 if (Math::Abs(__previousPressedTime - __oldPreviousPressedTime) > doublePressTime)
840                                 {
841                                         if (Math::Abs(__previousPressedPoint.x - __currentPressedPoint.x) < doublePressMoveAllowance
842                                                 && Math::Abs(__previousPressedPoint.y - __currentPressedPoint.y) < doublePressMoveAllowance )
843                                         {
844                                                 _TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, __pTouchManager->GetPosition(0), false, 0);
845
846                                                 SysTryReturn(NID_UI, __impl.__pCoreTouchEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
847                                                 isFiltered = __impl.__pCoreTouchEvent->ProcessListener(touchInfo);
848
849                                                 return true;
850                                         }
851                                 }
852                         }
853                 }
854
855                 return false;
856         }
857
858 private:
859         CoreTouchEvent(const CoreTouchEvent& rhs);
860         CoreTouchEvent& operator =(const CoreTouchEvent& rhs);
861
862 private:
863         _ControlImpl& __impl;
864         _Control& __core;
865         Control& __public;
866         _TouchManager* __pTouchManager;
867         unsigned int __oldPreviousPressedTime;
868         unsigned int __previousPressedTime;
869         unsigned int __currentPressedTime;
870         Point __previousPressedPoint;
871         Point __currentPressedPoint;
872 };
873
874 class _ControlImpl::CoreFocusEvent
875 {
876 public:
877         CoreFocusEvent(_ControlImpl& impl)
878                 : __impl(impl)
879                 , __core(impl.GetCore())
880                 , __public(impl.GetPublic())
881         {
882         }
883
884         ~CoreFocusEvent(void)
885         {
886         }
887
888 private:
889         result FirePublicListener(IFocusEventListener& listener, FocusStatus focusState)
890         {
891                 result r = E_SUCCESS;
892
893                 switch (focusState)
894                 {
895                         case FOCUS_GAINED:
896                                 listener.OnFocusGained(__public);
897                                 break;
898                         case FOCUS_LOST:
899                                 listener.OnFocusLost(__public);
900                                 break;
901                         default:
902                                 SysAssert(0);
903                                 r = E_SYSTEM;
904                                 break;
905                 }
906
907                 return r;
908         }
909
910 public:
911         bool ProcessListener(FocusStatus focusState)
912         {
913                 bool filterd = false;
914
915                 // 1. Public
916                 IEnumeratorT <IEventListener*>* pEnumerator = __impl.__pPublicFocusEventListeners->GetEnumeratorN();
917                 if (pEnumerator)
918                 {
919                         while (pEnumerator->MoveNext() == E_SUCCESS)
920                         {
921                                 Runtime::IEventListener* pListener = null;
922                                 pEnumerator->GetCurrent(pListener);
923                                 IFocusEventListener* pFocusEventListener = dynamic_cast <IFocusEventListener*>(pListener);
924                                 if (pFocusEventListener)
925                                 {
926                                         FirePublicListener(*pFocusEventListener, focusState);
927                                 }
928                         }
929
930                         delete pEnumerator;
931                 }
932
933                 return filterd;
934         }
935
936 private:
937         CoreFocusEvent(const CoreFocusEvent& rhs);
938         CoreFocusEvent& operator =(const CoreFocusEvent& rhs);
939
940 private:
941         _ControlImpl& __impl;
942         _Control& __core;
943         Control& __public;
944 };
945
946 class _ControlImpl::CoreGestureEvent
947 {
948 public:
949         CoreGestureEvent(_ControlImpl& impl)
950                 : __impl(impl)
951                 , __core(impl.GetCore())
952                 , __public(impl.GetPublic())
953         {
954         }
955
956         ~CoreGestureEvent(void)
957         {
958         }
959
960 public:
961         bool ProcessListener(_TouchGestureDetectorType gestureType)
962         {
963                 bool filterd = false;
964
965                 _TouchManager* pTouchManager = _TouchManager::GetInstance();
966                 SysTryReturn(NID_UI, pTouchManager, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
967
968                 switch (gestureType)
969                 {
970                         case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
971                         {
972                                 _TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, pTouchManager->GetPosition(0), false, 0);
973
974                                 SysTryReturn(NID_UI, __impl.__pCoreTouchEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
975                                 filterd = __impl.__pCoreTouchEvent->ProcessListener(touchInfo);
976                         }
977                         break;
978                         case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
979                         {
980                                 _TouchInfo touchInfo(0, _TOUCH_LONG_PRESSED, pTouchManager->GetPosition(0), false, 0);
981
982                                 SysTryReturn(NID_UI, __impl.__pCoreTouchEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
983                                 filterd = __impl.__pCoreTouchEvent->ProcessListener(touchInfo);
984                         }
985                         break;
986                         default:
987                                 SysAssert(0);
988                                 break;
989                         }
990
991                 return filterd;
992         }
993
994 private:
995         CoreGestureEvent(const CoreGestureEvent& rhs);
996         CoreGestureEvent& operator =(const CoreGestureEvent& rhs);
997
998 private:
999         _ControlImpl& __impl;
1000         _Control& __core;
1001         Control& __public;
1002 };
1003
1004 class _ControlImpl::CoreEventListener
1005         : public _IFocusEventListener
1006         , public _INotificationEventListener
1007         , public _ITouchLongPressGestureEventListener
1008         , virtual public Tizen::Base::Runtime::IEventListener
1009         , virtual public _IUiEventListener
1010         , virtual public _ITouchGestureEventListener
1011 {
1012 public:
1013         CoreEventListener(_ControlImpl& impl)
1014                 : __impl(impl)
1015                 , __core(impl.GetCore())
1016                 , __public(impl.GetPublic())
1017                 , __isKeyPressed(false)
1018                 , __pKeyInfo(null)
1019         {
1020                 __pTouchManager = _TouchManager::GetInstance();
1021                 SysTryReturnVoidResult(NID_UI, __pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1022
1023                 return;
1024         }
1025
1026         virtual ~CoreEventListener(void)
1027         {
1028         }
1029
1030         virtual bool OnFocusGained(const _Control& source)
1031         {
1032                 SysTryReturn(NID_UI, __impl.__pCoreFocusEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1033
1034                 bool isFiltered = false;
1035
1036                 isFiltered = __impl.__pCoreFocusEvent->ProcessListener(FOCUS_GAINED);
1037                 if (isFiltered)
1038                 {
1039                         return true;
1040                 }
1041
1042                 // 2. Impl
1043                 isFiltered = __impl.OnFocusGained(__impl);
1044                 if (isFiltered)
1045                 {
1046                         return true;
1047                 }
1048
1049                 // 3. Core
1050                 isFiltered = __core.OnFocusGained(source);
1051
1052                 return isFiltered;
1053         }
1054
1055         virtual bool OnFocusLost(const _Control& source)
1056         {
1057                 SysTryReturn(NID_UI, __impl.__pCoreFocusEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1058
1059                 bool isFiltered = false;
1060
1061                 isFiltered = __impl.__pCoreFocusEvent->ProcessListener(FOCUS_LOST);
1062                 if (isFiltered)
1063                 {
1064                         return true;
1065                 }
1066
1067                 // 2. Impl
1068                 isFiltered = __impl.OnFocusLost(__impl);
1069                 if (isFiltered)
1070                 {
1071                         return true;
1072                 }
1073
1074                 // 3. Core
1075                 isFiltered = __core.OnFocusLost(source);
1076
1077                 return isFiltered;
1078         }
1079
1080         virtual bool OnNotifiedN(const _Control& source, Tizen::Base::Collection::IList* pArgs)
1081         {
1082                 if (__impl.SendNotification(__impl, pArgs))
1083                 {
1084                         return true;
1085                 }
1086
1087                 if (&source == &__core)
1088                 {
1089                         if (ProcessTouchModeChangedListener(source, pArgs))
1090                         {
1091                                 pArgs->RemoveAll(true);
1092                                 delete pArgs;
1093                                 return true;
1094                         }
1095                 }
1096
1097                 // 1. Impl
1098                 if (__impl.OnNotifiedN(__impl, pArgs))
1099                 {
1100                         return true;
1101                 }
1102
1103                 // 2. Core
1104                 return __core.OnNotifiedN(source, pArgs);
1105         }
1106
1107         virtual bool OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
1108         {
1109                 SysTryReturn(NID_UI, __impl.__pCoreGestureEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1110                 bool isFiltered = false;
1111
1112                 isFiltered = __impl.__pCoreGestureEvent->ProcessListener(_TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS);
1113
1114                 return isFiltered;
1115         }
1116
1117         virtual bool OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
1118         {
1119                 return false;
1120         }
1121
1122         bool ProcessTouchModeChangedListener(const _Control& source, Tizen::Base::Collection::IList* pArgs)
1123         {
1124                 IEnumeratorT<IEventListener*>* pEnumerator = __impl.__pPublicTouchModeChangedEventListeners->GetEnumeratorN();
1125                 bool isFiltered = false;
1126
1127                 if (pEnumerator)
1128                 {
1129                         while(pEnumerator->MoveNext() == E_SUCCESS)
1130                         {
1131                                 IEventListener* pEventListener = null;
1132                                 pEnumerator->GetCurrent(pEventListener);
1133
1134                                 if (!pEventListener)
1135                                 {
1136                                         continue;
1137                                 }
1138
1139                                 String* pString = dynamic_cast<String*>(pArgs->GetAt(0));
1140                                 if (pString && (*pString == _KEYBOARD_INSERTED_EVENT))
1141                                 {
1142                                         Boolean* pIsTouchMode = dynamic_cast<Boolean*>(pArgs->GetAt(1));
1143                                         ITouchModeChangedEventListener* pTouchModeListener = dynamic_cast<ITouchModeChangedEventListener*>(pEventListener);
1144                                         if (pTouchModeListener && pIsTouchMode)
1145                                         {
1146                                                 pTouchModeListener->OnTouchModeChanged(__impl.GetPublic(), pIsTouchMode->ToBool()) ;
1147                                                 isFiltered = true;
1148                                         }
1149                                 }
1150                         }
1151                         delete pEnumerator;
1152                 }
1153
1154                 return isFiltered;
1155         }
1156
1157 private:
1158         CoreEventListener(const CoreEventListener& rhs);
1159         CoreEventListener& operator =(const CoreEventListener& rhs);
1160
1161 private:
1162         _ControlImpl& __impl;
1163         _Control& __core;
1164         Control& __public;
1165         _TouchManager* __pTouchManager;
1166         bool __isKeyPressed;
1167         _KeyInfo* __pKeyInfo;
1168 };
1169
1170 class _ControlImpl::_PropagatedTouchEventListener
1171         :       public _IPropagatedTouchEventListener
1172 {
1173 public:
1174         _PropagatedTouchEventListener(_ControlImpl& impl)
1175         : __impl(impl)
1176         , __core(impl.GetCore())
1177         , __public(impl.GetPublic())
1178         {
1179         }
1180
1181         virtual ~_PropagatedTouchEventListener()
1182         {
1183         }
1184
1185         _TouchEventArg* GetTouchEventArgN(const _TouchInfo& touchInfo)
1186         {
1187                 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(__public, touchInfo.GetTouchStatus());
1188                 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
1189
1190                 _TouchManager* __pTouchManager = _TouchManager::GetInstance();
1191                 SysTryReturn(NID_UI, __pTouchManager, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] __pTouchManager == null.");
1192
1193                 Point startPoint(__pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - __core.GetAbsoluteBounds().x,
1194                                 __pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - __core.GetAbsoluteBounds().y);
1195
1196                 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
1197                 touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
1198
1199                 int xDistance = 0;
1200                 int yDistance = 0;
1201                 __impl.__pFlickGestureDetector->GetDistance(xDistance, yDistance);
1202
1203                 if (xDistance != 0 || yDistance != 0)
1204                 {
1205                         pEventArg->SetFlickedStatus(true);
1206                 }
1207                 else
1208                 {
1209                         pEventArg->SetFlickedStatus(false);
1210                 }
1211
1212                 return pEventArg;
1213         }
1214
1215         virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
1216         {
1217                 return __impl.CallOnTouchPressed(source, touchInfo);
1218         }
1219
1220         virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
1221         {
1222                 return __impl.CallOnTouchReleased(source, touchInfo);
1223         }
1224
1225         virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
1226         {
1227                 return __impl.CallOnTouchMoved(source, touchInfo);
1228         }
1229
1230         virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
1231         {
1232                 return __impl.CallOnTouchCanceled(source, touchInfo);
1233         }
1234
1235         virtual void OnTouchPressHandled(const _Control& source)
1236         {
1237                 __impl.OnTouchPressHandled(source);
1238         }
1239
1240         virtual void OnTouchReleaseHandled(const _Control& source)
1241         {
1242                 __impl.OnTouchReleaseHandled(source);
1243         }
1244
1245         virtual void OnTouchMoveHandled(const _Control& source)
1246         {
1247                 __impl.OnTouchMoveHandled(source);
1248         }
1249
1250         virtual void OnTouchCancelHandled(const _Control& source)
1251         {
1252                 __impl.OnTouchCancelHandled(source);
1253         }
1254
1255 private:
1256         _ControlImpl& __impl;
1257         _Control& __core;
1258         Control& __public;
1259 };
1260
1261 class _ControlImpl::_PropagatedKeyEventListener
1262         : public _IPropagatedKeyEventListener
1263         , public ITimerEventListener
1264 {
1265 public:
1266         _PropagatedKeyEventListener(_ControlImpl& impl)
1267         : __impl(impl)
1268         , __core(impl.GetCore())
1269         , __public(impl.GetPublic())
1270         , __pTimer(null)
1271         , __isKeyPressed(false)
1272         , __pKeyInfo(null)
1273         {
1274         }
1275
1276         virtual ~_PropagatedKeyEventListener()
1277         {
1278                 if (__pTimer != null)
1279                 {
1280                         __pTimer->Cancel();
1281
1282                         delete __pTimer;
1283                         __pTimer = null;
1284                 }
1285         }
1286
1287         void OnTimerExpired(Timer& timer)
1288         {
1289                 if (__isKeyPressed)
1290                 {
1291                         SysTryReturnVoidResult(NID_UI, __impl.__pCoreKeyEvent, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1292
1293                         __impl.__pCoreKeyEvent->ProcessListener(KEY_LONGPRESSED, __pKeyInfo->GetKeyCode());
1294                 }
1295         }
1296
1297         virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1298         {
1299                 SysTryReturn(NID_UI, __impl.__pCoreKeyEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1300
1301                 bool isFiltered = false;
1302
1303                 if (&source == &__core)
1304                 {
1305                         if (!__isKeyPressed)
1306                         {
1307                                 __pTimer = new (std::nothrow) Timer;
1308                                 SysTryReturn(NID_UI, __pTimer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1309
1310                                 result r = __pTimer->Construct(*this);
1311                                 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1312
1313                                 r = __pTimer->Start(keyPressTimer);
1314                                 if (r == E_SUCCESS)
1315                                 {
1316                                         __isKeyPressed = true;
1317                                         __pKeyInfo = const_cast<_KeyInfo*>(&keyInfo);
1318                                 }
1319                         }
1320
1321                         isFiltered = __impl.__pCoreKeyEvent->ProcessListener(KEY_PRESSED, keyInfo.GetKeyCode());
1322                         if (isFiltered)
1323                         {
1324                                 return true;
1325                         }
1326                 }
1327
1328                 // 3. Impl
1329                 isFiltered = __impl.OnKeyPressed(__impl, keyInfo);
1330                 if (isFiltered)
1331                 {
1332                         return true;
1333                 }
1334
1335                 // 4. Core
1336                 isFiltered = __core.OnKeyPressed(source, keyInfo);
1337
1338                 return isFiltered;
1339         }
1340
1341         virtual bool OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1342         {
1343                 SysTryReturn(NID_UI, __impl.__pCoreKeyEvent, false, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1344
1345                 bool isFiltered = false;
1346
1347                 if (&source == &__core)
1348                 {
1349                         __isKeyPressed = false;
1350                         __pKeyInfo = null;
1351
1352                         if (__pTimer != null)
1353                         {
1354                                 __pTimer->Cancel();
1355
1356                                 delete __pTimer;
1357                                 __pTimer = null;
1358                         }
1359
1360                         isFiltered = __impl.__pCoreKeyEvent->ProcessListener(KEY_RELEASED, keyInfo.GetKeyCode());
1361                         if (isFiltered)
1362                         {
1363                                 return true;
1364                         }
1365                 }
1366
1367                 // 3. Impl
1368                 isFiltered = __impl.OnKeyReleased(__impl, keyInfo);
1369                 if (isFiltered)
1370                 {
1371                         return true;
1372                 }
1373
1374                 // 4. Core
1375                 isFiltered = __core.OnKeyReleased(source, keyInfo);
1376
1377                 return isFiltered;
1378         }
1379
1380 private:
1381         _ControlImpl& __impl;
1382         _Control& __core;
1383         Control& __public;
1384
1385         Tizen::Base::Runtime::Timer* __pTimer;
1386         bool __isKeyPressed;
1387         _KeyInfo* __pKeyInfo;
1388 };
1389
1390 Rectangle
1391 _ControlImpl::GetErrorBounds(void)
1392 {
1393         return Rectangle(0, 0, -1, -1);
1394 }
1395
1396 CompositeMode
1397 _ControlImpl::GetErrorCompositeMode(void)
1398 {
1399         return COMPOSITE_MODE_ALPHA_BLENDING;
1400 }
1401
1402 Color
1403 _ControlImpl::GetErrorChromaKeyColor(void)
1404 {
1405         return Color::GetColor(COLOR_ID_MAGENTA);
1406 }
1407
1408 Dimension
1409 _ControlImpl::GetErrorMinimumSize(void)
1410 {
1411         return Dimension(-1, -1);
1412 }
1413
1414 Dimension
1415 _ControlImpl::GetErrorMaximumSize(void)
1416 {
1417         return Dimension(-1, -1);
1418 }
1419
1420 const char*
1421 _ControlImpl::GetPublicClassName(void) const
1422 {
1423         return "Tizen::Ui::Control";
1424 }
1425
1426 const Control&
1427 _ControlImpl::GetPublic(void) const
1428 {
1429         return *__pControlPublic;
1430 }
1431
1432 Control&
1433 _ControlImpl::GetPublic(void)
1434 {
1435         return *__pControlPublic;
1436 }
1437
1438 const _Control&
1439 _ControlImpl::GetCore(void) const
1440 {
1441         return *__pControlCore;
1442 }
1443
1444 _Control&
1445 _ControlImpl::GetCore(void)
1446 {
1447         return *__pControlCore;
1448 }
1449
1450 result
1451 _ControlImpl::AddFocusEventListener(IFocusEventListener& listener)
1452 {
1453         ClearLastResult();
1454         SysTryReturn(NID_UI,
1455                                 __pPublicFocusEventListeners->Add(const_cast <IFocusEventListener*>(&listener)) == E_SUCCESS, E_SYSTEM,
1456                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1457
1458         return E_SUCCESS;
1459 }
1460
1461 result
1462 _ControlImpl::AddKeyEventListener(IKeyEventListener& listener)
1463 {
1464         ClearLastResult();
1465         SysTryReturn(NID_UI,
1466                                 __pPublicKeyEventListeners->Add(const_cast <IKeyEventListener*>(&listener)) == E_SUCCESS, E_SYSTEM,
1467                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1468
1469         return E_SUCCESS;
1470 }
1471
1472 result
1473 _ControlImpl::AddTouchEventListener(ITouchEventListener& listener)
1474 {
1475         SysAssert(__pControlCore && __pCoreEventListener && __pLongPressGestureDetector && __pFlickGestureDetector);
1476
1477         ClearLastResult();
1478         SysTryReturn(NID_UI,
1479                                 __pPublicTouchEventListeners->Add(const_cast <ITouchEventListener*>(&listener)) == E_SUCCESS, E_SYSTEM,
1480                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1481
1482         // Firt time, enable gesture.
1483         if (__pPublicTouchEventListeners->GetCount() == 1)
1484         {
1485                 result r = E_SUCCESS;
1486
1487                 r = __pControlCore->AddGestureDetector(*__pLongPressGestureDetector);
1488                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1489
1490                 r = __pLongPressGestureDetector->AddGestureListener(*__pCoreEventListener);
1491                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1492
1493                 r = __pControlCore->AddGestureDetector(*__pFlickGestureDetector);
1494                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1495
1496                 r = __pFlickGestureDetector->AddGestureListener(*__pCoreEventListener);
1497                 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1498         }
1499
1500         return E_SUCCESS;
1501 }
1502
1503 Tizen::Base::Collection::LinkedListT <Tizen::Base::Runtime::IEventListener*>*
1504 _ControlImpl::GetTouchEventListener(void) const
1505 {
1506         return __pPublicTouchEventListeners;
1507 }
1508
1509 result
1510 _ControlImpl::AddDragDropEventListener(IDragDropEventListener& listener)
1511 {
1512         ClearLastResult();
1513         SysTryReturn(NID_UI,
1514                                 __pPublicDragDropEventListeners->Add(const_cast <IDragDropEventListener*>(&listener)) == E_SUCCESS, E_SYSTEM,
1515                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1516
1517         return E_SUCCESS;
1518 }
1519
1520 Tizen::Base::Collection::LinkedListT <Tizen::Base::Runtime::IEventListener*>*
1521 _ControlImpl::GetDragDropEventListener(void) const
1522 {
1523         return __pPublicDragDropEventListeners;
1524 }
1525
1526 result
1527 _ControlImpl::AddTouchModeChangedEventListener(ITouchModeChangedEventListener& listener)
1528 {
1529         ClearLastResult();
1530         SysTryReturn(NID_UI,
1531                                 __pPublicTouchModeChangedEventListeners->Add(
1532                                         const_cast <ITouchModeChangedEventListener*>(&listener)) == E_SUCCESS, E_SYSTEM,
1533                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1534
1535         return E_SUCCESS;
1536 }
1537
1538 result
1539 _ControlImpl::RemoveFocusEventListener(IFocusEventListener& listener)
1540 {
1541         ClearLastResult();
1542         SysTryReturn(NID_UI,
1543                                 __pPublicFocusEventListeners->Remove(&listener) == E_SUCCESS, E_SYSTEM,
1544                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1545
1546         return E_SUCCESS;
1547 }
1548
1549 result
1550 _ControlImpl::RemoveKeyEventListener(IKeyEventListener& listener)
1551 {
1552         ClearLastResult();
1553         SysTryReturn(NID_UI,
1554                                 __pPublicKeyEventListeners->Remove(&listener) == E_SUCCESS, E_SYSTEM,
1555                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1556
1557         return E_SUCCESS;
1558 }
1559
1560 result
1561 _ControlImpl::RemoveTouchEventListener(ITouchEventListener& listener)
1562 {
1563         ClearLastResult();
1564         SysTryReturn(NID_UI,
1565                                 __pPublicTouchEventListeners->Remove(&listener) == E_SUCCESS, E_SYSTEM,
1566                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1567
1568         // [ToDo] if the number of touch event listers becomes 0, disable gesture recognition.
1569
1570         return E_SUCCESS;
1571 }
1572
1573 result
1574 _ControlImpl::RemoveDragDropEventListener(IDragDropEventListener& listener)
1575 {
1576         ClearLastResult();
1577         SysTryReturn(NID_UI,
1578                                 __pPublicDragDropEventListeners->Remove(&listener) == E_SUCCESS, E_SYSTEM,
1579                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1580
1581         return E_SUCCESS;
1582 }
1583
1584 result
1585 _ControlImpl::RemoveTouchModeChangedEventListener(ITouchModeChangedEventListener& listener)
1586 {
1587         ClearLastResult();
1588         SysTryReturn(NID_UI,
1589                                 __pPublicTouchModeChangedEventListeners->Remove(&listener) == E_SUCCESS, E_SYSTEM,
1590                                 E_SYSTEM, "[E_SYSTEM] System error occurred.");
1591
1592         return E_SUCCESS;
1593 }
1594
1595 result
1596 _ControlImpl::AddGestureDetector(const TouchGestureDetector& gestureDetector)
1597 {
1598         SysTryReturn(NID_UI,
1599                                 __pPublicGestureDetectors->Add(
1600                                                 const_cast <TouchGestureDetector*>(&gestureDetector)) == E_SUCCESS, E_SYSTEM,
1601                                         E_SYSTEM, "[E_SYSTEM] System error occurred.");
1602
1603         const _TouchGestureDetectorImpl* pImpl = _TouchGestureDetectorImpl::GetInstance(gestureDetector);
1604         SysTryReturn(NID_UI, pImpl, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1605
1606         result r = GetCore().AddGestureDetector(pImpl->GetCore());
1607         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1608
1609         return E_SUCCESS;
1610 }
1611
1612 result
1613 _ControlImpl::RemoveGestureDetector(const TouchGestureDetector& gestureDetector)
1614 {
1615         SysTryReturn(NID_UI,
1616                                 __pPublicGestureDetectors->Remove(
1617                                                 const_cast <TouchGestureDetector*>(&gestureDetector)) == E_SUCCESS, E_SYSTEM,
1618                                         E_SYSTEM, "[E_SYSTEM] System error occurred.");
1619
1620         const _TouchGestureDetectorImpl* pImpl = _TouchGestureDetectorImpl::GetInstance(gestureDetector);
1621         SysTryReturn(NID_UI, pImpl, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1622
1623         result r = GetCore().RemoveGestureDetector(pImpl->GetCore());
1624         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1625
1626         return r;
1627 }
1628
1629 IListT<TouchGestureDetector*>*
1630 _ControlImpl::GetGestureDetectorList(void) const
1631 {
1632         return __pPublicGestureDetectors;
1633 }
1634
1635 bool
1636 _ControlImpl::IsMovable(void) const
1637 {
1638         return GetCore().IsMovable();
1639 }
1640
1641 bool
1642 _ControlImpl::IsResizable(void) const
1643 {
1644         return GetCore().IsResizable();
1645 }
1646
1647 Dimension
1648 _ControlImpl::GetContentSize(void) const
1649 {
1650         return GetCore().GetContentSize();
1651 }
1652
1653 HitTestResult
1654 _ControlImpl::HitTest(const Tizen::Graphics::FloatPoint& point)
1655 {
1656         return GetCore().HitTest(point);
1657 }
1658
1659 String
1660 _ControlImpl::GetDescription(void) const
1661 {
1662         String description(L"");
1663
1664         description.Format(LOG_LEN_MAX, L"0x%x(0x%x, %s) fgColor(0x%x) fontSize(%d) ", this, __pControlPublic, GetPublicClassName(), __foregroundColor.GetRGB32(), __fontSize);
1665
1666         if (__pControlAnimator)
1667         {
1668                 description.Append(L"ControlAnimator(");
1669                 description.Append((int)__pControlAnimator);
1670                 description.Append(L") ");
1671         }
1672
1673         if (__pCustomVisualElement)
1674         {
1675                 description.Append(L"CustomVisualElement(");
1676                 description.Append((int)__pCustomVisualElement);
1677                 description.Append(L") ");
1678         }
1679
1680         if (__pBuilderPortraitBounds)
1681         {
1682                 description.Append(L"PortraitBounds(");
1683                 description.Append(__pBuilderPortraitBounds->x);
1684                 description.Append(L" ");
1685                 description.Append(__pBuilderPortraitBounds->y);
1686                 description.Append(L" ");
1687                 description.Append(__pBuilderPortraitBounds->width);
1688                 description.Append(L" ");
1689                 description.Append(__pBuilderPortraitBounds->height);
1690                 description.Append(L") ");
1691         }
1692
1693         if (__pBuilderLandscapeBounds)
1694         {
1695                 description.Append(L"LandscapeBounds(");
1696                 description.Append(__pBuilderLandscapeBounds->x);
1697                 description.Append(L" ");
1698                 description.Append(__pBuilderLandscapeBounds->y);
1699                 description.Append(L" ");
1700                 description.Append(__pBuilderLandscapeBounds->width);
1701                 description.Append(L" ");
1702                 description.Append(__pBuilderLandscapeBounds->height);
1703                 description.Append(L") ");
1704         }
1705
1706         if (__pPublicGestureDetectors->GetCount() > 0 )
1707         {
1708                 IEnumeratorT<TouchGestureDetector*>* pEnumerator = __pPublicGestureDetectors->GetEnumeratorN();
1709                 if (pEnumerator)
1710                 {
1711                         description.Append(L"TouchGestureDetector(");
1712
1713                         while (pEnumerator->MoveNext() == E_SUCCESS)
1714                         {
1715                                 TouchGestureDetector* pTouchGestureDetector = null;
1716                                 pEnumerator->GetCurrent(pTouchGestureDetector);
1717                                 if (pTouchGestureDetector)
1718                                 {
1719                                         description.Append((int)pTouchGestureDetector);
1720                                         description.Append(L" ");
1721                                 }
1722                         }
1723
1724                         description.Append(L") ");
1725
1726                         delete pEnumerator;
1727                 }
1728         }
1729
1730         if (__pPublicFocusEventListeners->GetCount() > 0 )
1731         {
1732                 IEnumeratorT<IEventListener*>* pEnumerator = __pPublicFocusEventListeners->GetEnumeratorN();
1733                 if (pEnumerator)
1734                 {
1735                         description.Append(L"FocusListener(");
1736
1737                         while (pEnumerator->MoveNext() == E_SUCCESS)
1738                         {
1739                                 IEventListener* pListener = null;
1740                                 pEnumerator->GetCurrent(pListener);
1741                                 if (pListener)
1742                                 {
1743                                         description.Append((int)pListener);
1744                                         description.Append(L" ");
1745                                 }
1746                         }
1747
1748                         description.Append(L") ");
1749
1750                         delete pEnumerator;
1751                 }
1752         }
1753
1754         if (__pPublicKeyEventListeners->GetCount() > 0 )
1755         {
1756                 IEnumeratorT<IEventListener*>* pEnumerator = __pPublicKeyEventListeners->GetEnumeratorN();
1757                 if (pEnumerator)
1758                 {
1759                         description.Append(L"KeyListener(");
1760
1761                         while (pEnumerator->MoveNext() == E_SUCCESS)
1762                         {
1763                                 IEventListener* pListener = null;
1764                                 pEnumerator->GetCurrent(pListener);
1765                                 if (pListener)
1766                                 {
1767                                         description.Append((int)pListener);
1768                                         description.Append(L" ");
1769                                 }
1770                         }
1771
1772                         description.Append(L") ");
1773
1774                         delete pEnumerator;
1775                 }
1776         }
1777
1778         if (__pPublicTouchEventListeners->GetCount() > 0 )
1779         {
1780                 IEnumeratorT<IEventListener*>* pEnumerator = __pPublicTouchEventListeners->GetEnumeratorN();
1781                 if (pEnumerator)
1782                 {
1783                         description.Append(L"TouchListener(");
1784
1785                         while (pEnumerator->MoveNext() == E_SUCCESS)
1786                         {
1787                                 IEventListener* pListener = null;
1788                                 pEnumerator->GetCurrent(pListener);
1789                                 if (pListener)
1790                                 {
1791                                         description.Append((int)pListener);
1792                                         description.Append(L" ");
1793                                 }
1794                         }
1795
1796                         description.Append(L") ");
1797
1798                         delete pEnumerator;
1799                 }
1800         }
1801
1802         if (__pPublicDragDropEventListeners->GetCount() > 0 )
1803         {
1804                 IEnumeratorT<IEventListener*>* pEnumerator = __pPublicDragDropEventListeners->GetEnumeratorN();
1805                 if (pEnumerator)
1806                 {
1807                         description.Append(L"DragDropListener(");
1808
1809                         while (pEnumerator->MoveNext() == E_SUCCESS)
1810                         {
1811                                 IEventListener* pListener = null;
1812                                 pEnumerator->GetCurrent(pListener);
1813                                 if (pListener)
1814                                 {
1815                                         description.Append((int)pListener);
1816                                         description.Append(L" ");
1817                                 }
1818                         }
1819
1820                         description.Append(L") ");
1821
1822                         delete pEnumerator;
1823                 }
1824         }
1825
1826         if (__pPublicTouchModeChangedEventListeners->GetCount() > 0 )
1827         {
1828                 IEnumeratorT<IEventListener*>* pEnumerator = __pPublicTouchModeChangedEventListeners->GetEnumeratorN();
1829                 if (pEnumerator)
1830                 {
1831                         description.Append(L"TouchModeListener(");
1832
1833                         while (pEnumerator->MoveNext() == E_SUCCESS)
1834                         {
1835                                 IEventListener* pListener = null;
1836                                 pEnumerator->GetCurrent(pListener);
1837                                 if (pListener)
1838                                 {
1839                                         description.Append((int)pListener);
1840                                         description.Append(L" ");
1841                                 }
1842                         }
1843
1844                         description.Append(L") ");
1845
1846                         delete pEnumerator;
1847                 }
1848         }
1849
1850         return description;
1851 }
1852
1853 void
1854 _ControlImpl::OnDraw(void)
1855 {
1856         GetCore().OnDraw();
1857 }
1858
1859 Tizen::Graphics::Canvas*
1860 _ControlImpl::OnCanvasRequestedN(const Tizen::Graphics::Dimension& size)
1861 {
1862         return GetCore().OnCanvasRequestedN(size);
1863 }
1864
1865 Tizen::Graphics::Bitmap*
1866 _ControlImpl::OnCapturedBitmapRequestedN(void)
1867 {
1868
1869         return GetCore().OnCapturedBitmapRequestedN();
1870 }
1871
1872 result
1873 _ControlImpl::OnAttaching(const _Control* pParent)
1874 {
1875         return GetCore().OnAttaching(pParent);
1876 }
1877
1878 result
1879 _ControlImpl::OnAttached(void)
1880 {
1881         return GetCore().OnAttached();
1882 }
1883
1884 result
1885 _ControlImpl::OnAttachingToMainTree(const _Control* pParent)
1886 {
1887         return GetCore().OnAttachingToMainTree(pParent);
1888 }
1889
1890 result
1891 _ControlImpl::OnAttachedToMainTree(void)
1892 {
1893         result r = E_SUCCESS;
1894         result returnResultPublic = E_SUCCESS;
1895         result returnResultCore = E_SUCCESS;
1896
1897         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
1898         {
1899                 GetCore().SetDrawWhenVisible(false);
1900                 GetCore().SetTerminatingOrder(true);
1901         }
1902
1903         returnResultPublic = GetPublic().OnInitializing();
1904         returnResultCore = GetCore().OnAttachedToMainTree();
1905
1906         if (IsFailed(returnResultPublic) || IsFailed(returnResultCore))
1907         {
1908                 _ContainerImpl* pParent = GetParent();
1909                 SysTryReturn(NID_UI, pParent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1910
1911                 r = pParent->RemoveChild(this, false);
1912                 SysAssert(r == E_SUCCESS);
1913
1914                 SysTryReturn(NID_UI, returnResultPublic == E_SUCCESS, returnResultPublic, returnResultPublic, "[%s] propagated.", GetErrorMessage(returnResultPublic));
1915                 SysTryReturn(NID_UI, returnResultCore == E_SUCCESS, returnResultCore, returnResultCore, "[%s] propagated.", GetErrorMessage(returnResultCore));
1916         }
1917
1918         return returnResultPublic;
1919 }
1920
1921 result
1922 _ControlImpl::OnDetachingFromMainTree(void)
1923 {
1924         GetPublic().OnTerminating();
1925         return GetCore().OnDetachingFromMainTree();
1926 }
1927
1928 void
1929 _ControlImpl::OnAttachingFailed(const _Control& parent)
1930 {
1931         GetCore().OnAttachingFailed(parent);
1932 }
1933
1934 result
1935 _ControlImpl::OnDetaching(void)
1936 {
1937         return E_SUCCESS;
1938 }
1939
1940 result
1941 _ControlImpl::OnBoundsChanging(const Rectangle& bounds)
1942 {
1943         __oldBounds = GetBounds();
1944
1945         return GetCore().OnBoundsChanging(bounds);
1946 }
1947
1948 void
1949 _ControlImpl::OnBoundsChanged(void)
1950 {
1951         GetCore().OnBoundsChanged();
1952 }
1953
1954 void
1955 _ControlImpl::OnEvaluateSize(Dimension& evaluatedSize)
1956 {
1957         GetCore().OnEvaluateSize(evaluatedSize);
1958 }
1959
1960 void
1961 _ControlImpl::OnParentBoundsChanged(const _Control& parent)
1962 {
1963         GetCore().OnParentBoundsChanged(parent);
1964 }
1965
1966 void
1967 _ControlImpl::OnChildAttached(const _Control& child)
1968 {
1969         GetCore().OnChildAttached(child);
1970 }
1971
1972 void
1973 _ControlImpl::OnChildDetaching(const _Control& child)
1974 {
1975         GetCore().OnChildDetaching(child);
1976 }
1977
1978 void
1979 _ControlImpl::OnChildDetached(const _Control& child)
1980 {
1981         GetCore().OnChildDetached(child);
1982 }
1983
1984 void
1985 _ControlImpl::OnChildBoundsChanged(const _Control& child)
1986 {
1987         GetCore().OnChildBoundsChanged(child);
1988 }
1989
1990 void
1991 _ControlImpl::OnChildVisibleStateChanged(const _Control& child)
1992 {
1993         GetCore().OnChildVisibleStateChanged(child);
1994 }
1995
1996 void
1997 _ControlImpl::OnChangeLayout(_ControlOrientation orientation)
1998 {
1999         result r = E_SUCCESS;
2000
2001         if (IsAttachedToMainTree())
2002         {
2003                 Rectangle builderBounds;
2004                 bool exist = GetBuilderBounds(orientation, builderBounds);
2005                 if (exist)
2006                 {
2007                         bool movable = IsMovable();
2008                         bool resizable = IsResizable();
2009
2010                         SetMovable(true);
2011                         SetResizable(true);
2012
2013                         r = SetBounds(builderBounds);
2014                         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Failed to set bounds of %s.", GetPublicClassName());
2015                         builderBounds.x = 0;
2016                         builderBounds.y = 0;
2017                         SetClientBounds(builderBounds);
2018
2019                         SetMovable(movable);
2020                         SetResizable(resizable);
2021
2022                 }
2023         }
2024
2025         GetCore().OnChangeLayout(orientation);
2026 }
2027
2028 void
2029 _ControlImpl::OnZOrderChanging(_ControlZOrderUpdate zOrderUpdate)
2030 {
2031         GetCore().OnZOrderChanging(zOrderUpdate);
2032 }
2033
2034 void
2035 _ControlImpl::OnVisibleStateChanging(void)
2036 {
2037         GetCore().OnVisibleStateChanging();
2038 }
2039
2040 void
2041 _ControlImpl::OnVisibleStateChanged(void)
2042 {
2043         _TouchManager* pTouchManager = _TouchManager::GetInstance();
2044         if (pTouchManager)
2045         {
2046                 if ((_TouchManager::GetInstance()->IsTouchAllowed() == true) && (GetPublic().GetShowState() == false))
2047                 {
2048                         _ControlManager* pControlManager = _ControlManager::GetInstance();
2049                         SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] _ControlManager does not exist.");
2050
2051                         bool gestureDetecting = false;
2052
2053                         IListT<_TouchGestureDetector*>* pGestureList = GetCore().GetGestureDetectorList();
2054                         if (pGestureList)
2055                         {
2056                                 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = pGestureList->GetEnumeratorN();
2057                                 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2058
2059                                 while (pEnumerator->MoveNext() == E_SUCCESS)
2060                                 {
2061                                         _TouchGestureDetector* pGestureDetector = null;
2062                                         pEnumerator->GetCurrent(pGestureDetector);
2063                                         if (pGestureDetector)
2064                                         {
2065                                                 gestureDetecting = true;
2066                                                 break;
2067                                         }
2068                                 }
2069
2070                                 delete pEnumerator;
2071                         }
2072
2073                         if (!gestureDetecting)
2074                         {
2075                         pTouchManager->SetTouchCanceled(true);
2076                 }
2077         }
2078         }
2079
2080         GetCore().OnVisibleStateChanged();
2081 }
2082
2083 void
2084 _ControlImpl::OnAncestorVisibleStateChanged(const _Control& control)
2085 {
2086         GetCore().OnAncestorVisibleStateChanged(control);
2087 }
2088
2089 void
2090 _ControlImpl::OnAncestorEnableStateChanged(const _Control& control)
2091 {
2092         GetCore().OnAncestorEnableStateChanged(control);
2093 }
2094
2095 void
2096 _ControlImpl::OnTouchPressHandled(const _Control& control)
2097 {
2098         GetCore().OnTouchPressHandled(control);
2099 }
2100
2101 void
2102 _ControlImpl::OnTouchReleaseHandled(const _Control& control)
2103 {
2104         GetCore().OnTouchReleaseHandled(control);
2105 }
2106
2107 void
2108 _ControlImpl::OnTouchMoveHandled(const _Control& control)
2109 {
2110         GetCore().OnTouchMoveHandled(control);
2111 }
2112
2113 void
2114 _ControlImpl::OnFontChanged(Font* pFont)
2115 {
2116         GetCore().OnFontChanged(pFont);
2117 }
2118
2119 void
2120 _ControlImpl::OnFontInfoRequested(unsigned long& style, int& size)
2121 {
2122         GetCore().OnFontInfoRequested(style, size);
2123 }
2124 void
2125 _ControlImpl::OnTouchCancelHandled(const _Control& control)
2126 {
2127         GetCore().OnTouchCancelHandled(control);
2128 }
2129
2130 bool
2131 _ControlImpl::OnKeyPressed(const _ControlImpl& source, const _KeyInfo& keyInfo)
2132 {
2133         return false;
2134 }
2135
2136 bool
2137 _ControlImpl::OnKeyReleased(const _ControlImpl& source, const _KeyInfo& keyInfo)
2138 {
2139         return false;
2140 }
2141
2142 bool
2143 _ControlImpl::CallOnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2144 {
2145         bool isFiltered = false;
2146
2147         if (source.IsDelayedTouchEventEnabled())
2148         {
2149                 if (&source == &GetCore())
2150                 {
2151                         const_cast<_Control&>(source).AddTouchInfo(touchinfo);
2152                 }
2153
2154                 return false;
2155         }
2156
2157         GetCore().SetEventReceivable(true);
2158
2159         LinkedListT <Tizen::Base::Runtime::IEventListener*>* pList = GetTouchEventListener();
2160         if (pList && pList->GetCount() > 0)
2161         {
2162                 bool returnValue = __pCoreTouchEvent->ProcessDoublePress(touchinfo, isFiltered);
2163                 if (returnValue)
2164                 {
2165                         return false;
2166                 }
2167         }
2168
2169         if (&source == &GetCore())
2170         {
2171                 isFiltered = __pCoreTouchEvent->ProcessListener(touchinfo);
2172                 if (isFiltered)
2173                 {
2174                         return true;
2175                 }
2176
2177                 __pCoreTouchEvent->ProcessDragListener(touchinfo);
2178         }
2179
2180         _TouchManager* __pTouchManager =  _TouchManager::GetInstance();
2181         SysTryReturn(NID_UI, __pTouchManager, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] __pTouchManager == null.");
2182
2183         if (!GetCore().IsEventReceivable())
2184         {
2185                 __pTouchManager->ResetTouchInfo();
2186                 isFiltered = true;
2187                 return true;
2188         }
2189
2190         if (!__pTouchManager->IsTouchAllowed())
2191         {
2192                 return true;
2193         }
2194
2195         // 3. Impl
2196         isFiltered = OnTouchPressed(*this, touchinfo);
2197         if (isFiltered)
2198         {
2199                 return true;
2200         }
2201
2202         // 4. Core
2203         isFiltered = GetCore().OnTouchPressed(source, touchinfo);
2204
2205         return isFiltered;
2206
2207 }
2208
2209 bool
2210 _ControlImpl::CallOnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2211 {
2212         bool isFiltered = false;
2213
2214         if (source.IsDelayedTouchEventEnabled())
2215         {
2216                 if (&source == &GetCore())
2217                 {
2218                         const_cast<_Control&>(source).AddTouchInfo(touchinfo);
2219                 }
2220
2221                 return false;
2222         }
2223
2224         if (&source == &GetCore())
2225         {
2226                 isFiltered = __pCoreTouchEvent->ProcessListener(touchinfo);
2227                 if (isFiltered)
2228                 {
2229                         return true;
2230                 }
2231
2232                 __pCoreTouchEvent->ProcessDropListener(touchinfo);
2233         }
2234
2235         _TouchManager* __pTouchManager =  _TouchManager::GetInstance();
2236         SysTryReturn(NID_UI, __pTouchManager, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] __pTouchManager == null.");
2237
2238         if (!__pTouchManager->IsTouchAllowed())
2239         {
2240                 return true;
2241         }
2242
2243         // 3. Impl
2244         isFiltered = OnTouchReleased(*this, touchinfo);
2245         if (isFiltered)
2246         {
2247                 return true;
2248         }
2249
2250         //send drop event to topmost touched control
2251         __pCoreTouchEvent->ProcessDropListenerToTopControl(touchinfo);
2252
2253         // 4. Core
2254         isFiltered = GetCore().OnTouchReleased(source, touchinfo);
2255
2256         return isFiltered;
2257 }
2258
2259 bool
2260 _ControlImpl::CallOnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
2261 {
2262         bool isFiltered = false;
2263
2264         if (source.IsDelayedTouchEventEnabled())
2265         {
2266                 if (&source == &GetCore())
2267                 {
2268                         const_cast<_Control&>(source).AddTouchInfo(touchinfo);
2269                 }
2270
2271                 return false;
2272         }
2273
2274         if (&source == &GetCore())
2275         {
2276                 isFiltered = __pCoreTouchEvent->ProcessListener(touchinfo);
2277                 if (isFiltered)
2278                 {
2279                         return true;
2280                 }
2281         }
2282
2283         _TouchManager* __pTouchManager =  _TouchManager::GetInstance();
2284         SysTryReturn(NID_UI, __pTouchManager, false, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] __pTouchManager == null.");
2285
2286         if (!__pTouchManager->IsTouchAllowed())
2287         {
2288                 return true;
2289         }
2290
2291         // 3. Impl
2292         isFiltered = OnTouchMoved(*this, touchinfo);
2293         if (isFiltered)
2294         {
2295                 return true;
2296         }
2297
2298         // 4. Core
2299         isFiltered = GetCore().OnTouchMoved(source, touchinfo);
2300
2301         return isFiltered;
2302 }
2303
2304 bool
2305 _ControlImpl::CallOnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
2306 {
2307         bool isFiltered = false;
2308
2309         __pCoreTouchEvent->ProcessDropListener(touchinfo);
2310         __pCoreTouchEvent->ProcessDropListenerToTopControl(touchinfo);
2311
2312         if (&source == &GetCore())
2313         {
2314                 isFiltered = __pCoreTouchEvent->ProcessListener(touchinfo);
2315                 if (isFiltered)
2316                 {
2317                         return true;
2318                 }
2319         }
2320
2321         // 3. Impl
2322         isFiltered = OnTouchCanceled(*this, touchinfo);
2323         if (isFiltered)
2324         {
2325                 return true;
2326         }
2327
2328         // 4. Core
2329         isFiltered = GetCore().OnTouchCanceled(source, touchinfo);
2330
2331         return isFiltered;
2332 }
2333
2334 bool
2335 _ControlImpl::OnTouchPressed(const _ControlImpl& source, const _TouchInfo& touchinfo)
2336 {
2337         return false;
2338 }
2339
2340 bool
2341 _ControlImpl::OnTouchCanceled(const _ControlImpl& source, const _TouchInfo& touchinfo)
2342 {
2343         return false;
2344 }
2345
2346 bool
2347 _ControlImpl::OnTouchReleased(const _ControlImpl& source, const _TouchInfo& touchinfo)
2348 {
2349         return false;
2350 }
2351
2352 bool
2353 _ControlImpl::OnTouchMoved(const _ControlImpl& source, const _TouchInfo& touchinfo)
2354 {
2355         return false;
2356 }
2357
2358 bool
2359 _ControlImpl::OnFocusGained(const _ControlImpl& source)
2360 {
2361         return false;
2362 }
2363
2364 bool
2365 _ControlImpl::OnFocusLost(const _ControlImpl& source)
2366 {
2367         return false;
2368 }
2369
2370 bool
2371 _ControlImpl::OnNotifiedN(const _ControlImpl& source, Tizen::Base::Collection::IList* pArgs)
2372 {
2373         return false;
2374 }
2375
2376 void
2377 _ControlImpl::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
2378 {
2379         GetPublic().OnUserEventReceivedN(requestId, pArgs);
2380 }
2381
2382 bool
2383 _ControlImpl::SendNotification(const _ControlImpl& source, Tizen::Base::Collection::IList* pArgs)
2384 {
2385         _ControlImpl& impl = const_cast <_ControlImpl&>(source);
2386
2387         Tizen::Base::String* pString = dynamic_cast <Tizen::Base::String*>(pArgs->GetAt(0));
2388         if (pString)
2389         {
2390                 if (*pString == _USER_EVENT)
2391                 {
2392                         _UserEventInfo* pUserEventInfo = dynamic_cast <_UserEventInfo*>(pArgs->GetAt(1));
2393                         if (pUserEventInfo)
2394                         {
2395                                 impl.OnUserEventReceivedN(pUserEventInfo->GetRequestId(), pUserEventInfo->GetArgs());
2396                         }
2397                         pArgs->RemoveAll(true);
2398                         delete pArgs;
2399
2400                         return true;
2401                 }
2402                 else if (*pString == _REQUEST_REDRAW_EVENT)
2403                 {
2404                         impl.Draw();
2405
2406                         Boolean* pBoolean = dynamic_cast <Boolean*>(pArgs->GetAt(1));
2407                         if (pBoolean && pBoolean->ToBool())
2408                         {
2409                                 impl.Show();
2410                         }
2411                         pArgs->RemoveAll(true);
2412                         delete pArgs;
2413
2414                         return true;
2415                 }
2416         }
2417
2418         return false;
2419 }
2420
2421 result
2422 _ControlImpl::Draw(bool recursive)
2423 {
2424         SysTryReturn(NID_UI,
2425                                 IsAttachedToMainTree(), E_INVALID_OPERATION,
2426                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] The control should be attached to the main tree.");
2427
2428         GetCore().Draw(recursive);
2429
2430         return E_SUCCESS;
2431 }
2432
2433 result
2434 _ControlImpl::Show(void)
2435 {
2436         SysTryReturn(NID_UI,
2437                                 GetParent() || IsAttachedToMainTree(), E_INVALID_OPERATION,
2438                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2439
2440         GetCore().Show();
2441
2442         return E_SUCCESS;
2443 }
2444
2445 void
2446 _ControlImpl::Invalidate(bool recursive)
2447 {
2448         SysTryReturnVoidResult(NID_UI,
2449                                 IsAttachedToMainTree(),
2450                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] The control should be attached to the main tree.");
2451
2452         GetCore().Invalidate(recursive);
2453 }
2454
2455 void
2456 _ControlImpl::Invalidate(const Rectangle& rect)
2457 {
2458         SysTryReturnVoidResult(NID_UI,
2459                                 IsAttachedToMainTree(),
2460                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] The control should be attached to the main tree.");
2461
2462         GetCore().Invalidate(rect);
2463 }
2464
2465 void
2466 _ControlImpl::RequestRedraw(bool show) const
2467 {
2468         ClearLastResult();
2469
2470         ArrayList* pEventArgs = new (std::nothrow) ArrayList;
2471         SysTryReturnVoidResult(NID_UI, pEventArgs, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2472
2473         pEventArgs->Construct();
2474
2475         Tizen::Base::String* pString = new (std::nothrow) Tizen::Base::String(_REQUEST_REDRAW_EVENT);
2476         SysTryReturnVoidResult(NID_UI, pString, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2477
2478         // Index 0 : Type
2479         pEventArgs->Add(*pString);
2480
2481         Boolean* pBoolean = new (std::nothrow) Boolean(show);
2482         SysTryReturnVoidResult(NID_UI, pBoolean, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2483
2484         // Index 1 : User Data
2485         pEventArgs->Add(*pBoolean);
2486
2487         _UiEventManager* pEventManager = _UiEventManager::GetInstance();
2488         SysTryReturnVoidResult(NID_UI, pEventManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2489
2490         _UiNotificationEvent event(GetCore().GetHandle(), pEventArgs);
2491
2492         result r = pEventManager->PostEvent(event);
2493         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2494 }
2495
2496 void
2497 _ControlImpl::SendUserEvent(RequestId requestId, const IList* pArgs) const
2498 {
2499         ClearLastResult();
2500
2501         ArrayList* pEventArgs = new (std::nothrow) ArrayList;
2502         SysTryReturnVoidResult(NID_UI, pEventArgs, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2503
2504         pEventArgs->Construct();
2505
2506         Tizen::Base::String* pString = new (std::nothrow) Tizen::Base::String(_USER_EVENT);
2507         SysTryReturnVoidResult(NID_UI, pString, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2508
2509         // Index 0 : Type
2510         pEventArgs->Add(*pString);
2511
2512         _UserEventInfo* pUserEventInfo = new (std::nothrow) _UserEventInfo(requestId, pArgs);
2513         SysTryReturnVoidResult(NID_UI, pUserEventInfo, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
2514
2515         // Index 1 : User Data
2516         pEventArgs->Add(*pUserEventInfo);
2517
2518         _UiEventManager* pEventManager = _UiEventManager::GetInstance();
2519         SysTryReturnVoidResult(NID_UI, pEventManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2520
2521         _UiNotificationEvent event(GetCore().GetHandle(), pEventArgs);
2522
2523         result r = pEventManager->PostEvent(event);
2524         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2525 }
2526
2527 bool
2528 _ControlImpl::Contains(const Point& point) const
2529 {
2530         return GetCore().Contains(point);
2531 }
2532
2533 void
2534 _ControlImpl::ConsumeInputEvent(void)
2535 {
2536         ClearLastResult();
2537         __inputEventConsumed = true;
2538 }
2539
2540 bool
2541 _ControlImpl::IsInputEventConsumed(void) const
2542 {
2543         ClearLastResult();
2544         return __inputEventConsumed;
2545 }
2546
2547 void
2548 _ControlImpl::ResetInputEventConsumed(void)
2549 {
2550         ClearLastResult();
2551         __inputEventConsumed = false;
2552 }
2553
2554 Tizen::Base::String
2555 _ControlImpl::GetName(void) const
2556 {
2557         return GetCore().GetName();
2558 }
2559
2560 void
2561 _ControlImpl::SetName(const Tizen::Base::String& name)
2562 {
2563         GetCore().SetName(name);
2564 }
2565
2566 _ContainerImpl*
2567 _ControlImpl::GetParent(void) const
2568 {
2569         ClearLastResult();
2570
2571         _Control* pParent = GetCore().GetParent();
2572         if (pParent == null)
2573         {
2574                 return null;
2575         }
2576
2577         void* pData = pParent->GetUserData();
2578         if (pData == null)
2579         {
2580                 return null; // This is for the _ControlManager::__pRoot.
2581         }
2582
2583         _ContainerImpl* pParentImpl = static_cast <_ContainerImpl*>(pData);
2584         return pParentImpl;
2585 }
2586
2587 Canvas*
2588 _ControlImpl::GetCanvasN(void) const
2589 {
2590         SysTryReturn(NID_UI,
2591                                 GetParent() || IsAttachedToMainTree(), null,
2592                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2593
2594         Canvas* pCanvas = GetCore().GetCanvasN();
2595         result r = GetLastResult();
2596         if (IsFailed(r))
2597         {
2598                 if (r == E_OPERATION_FAILED)
2599                 {
2600                         SetLastResult(E_INVALID_OPERATION);
2601                 }
2602                 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2603         }
2604         else
2605         {
2606                 if (pCanvas)
2607                 {
2608                         pCanvas->SetBackgroundColor(GetBackgroundColor());
2609                         pCanvas->SetForegroundColor(GetForegroundColor());
2610                 }
2611         }
2612
2613         return pCanvas;
2614 }
2615
2616 Canvas*
2617 _ControlImpl::GetCanvasN(const Rectangle& bounds) const
2618 {
2619         SysTryReturn(NID_UI,
2620                                 GetParent() || IsAttachedToMainTree(), null,
2621                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2622
2623         Canvas* pCanvas = GetCore().GetCanvasN(bounds);
2624         result r = GetLastResult();
2625         if (IsFailed(r))
2626         {
2627                 if (r == E_OPERATION_FAILED)
2628                 {
2629                         SetLastResult(E_INVALID_OPERATION);
2630                 }
2631                 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2632         }
2633         else
2634         {
2635                 if (pCanvas)
2636                 {
2637                         pCanvas->SetBackgroundColor(GetBackgroundColor());
2638                         pCanvas->SetForegroundColor(GetForegroundColor());
2639                 }
2640         }
2641
2642         return pCanvas;
2643 }
2644
2645 Canvas*
2646 _ControlImpl::GetClientCanvasN(void) const
2647 {
2648         SysTryReturn(NID_UI,
2649                                 GetParent() || IsAttachedToMainTree(), null,
2650                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2651
2652         Canvas* pCanvas = GetCore().GetClientCanvasN();
2653         result r = GetLastResult();
2654         if (IsFailed(r))
2655         {
2656                 if (r == E_OPERATION_FAILED)
2657                 {
2658                         SetLastResult(E_INVALID_OPERATION);
2659                 }
2660                 SysLog(NID_UI_CTRL, "[%s] Propagated", GetErrorMessage(GetLastResult()));
2661         }
2662         else
2663         {
2664                 if (pCanvas)
2665                 {
2666                         pCanvas->SetBackgroundColor(GetBackgroundColor());
2667                         pCanvas->SetForegroundColor(GetForegroundColor());
2668                 }
2669         }
2670
2671         return pCanvas;
2672 }
2673
2674 bool
2675 _ControlImpl::IsAttachedToMainTree(void) const
2676 {
2677         return GetCore().IsAttachedToMainTree();
2678 }
2679
2680 bool
2681 _ControlImpl::IsInTouchMode(void) const
2682 {
2683         ClearLastResult();
2684         // [ToDo]
2685         return true;
2686 }
2687
2688 bool
2689 _ControlImpl::IsFocusable(void) const
2690 {
2691         return GetCore().IsFocusable();
2692 }
2693
2694 result
2695 _ControlImpl::SetFocusable(bool focusable)
2696 {
2697         // [ToDo] Focusable is simple flag. Make this method do not check belows.
2698         SysTryReturn(NID_UI,
2699                                 __focusableChangable, E_INVALID_OPERATION,
2700                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] The control can't chage it's focusable property.");
2701
2702         SysTryReturn(NID_UI,
2703                                 IsAttachedToMainTree(), E_SYSTEM,
2704                                 E_SYSTEM, "[E_SYSTEM] This control should be attached to the main tree.");
2705
2706         SysTryReturn(NID_UI,
2707                                 focusable || GetCore().GetFocused() != &this->GetCore(), E_INVALID_OPERATION,
2708                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This already focused control cannot be unfocusable.");
2709
2710         GetCore().SetFocusable(focusable);
2711         return E_SUCCESS;
2712 }
2713
2714 bool
2715 _ControlImpl::IsFocused(void) const
2716 {
2717         return GetCore().IsFocused();
2718 }
2719
2720 result
2721 _ControlImpl::SetFocused(void)
2722 {
2723         return GetCore().SetFocused();
2724 }
2725
2726 void
2727 _ControlImpl::SetFocusableChangable(bool focusableChangable)
2728 {
2729         __focusableChangable = focusableChangable;
2730 }
2731
2732 result
2733 _ControlImpl::SetFont(const String& fontName)
2734 {
2735         result r = GetCore().SetFont(fontName);
2736         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2737         return E_SUCCESS;
2738 }
2739
2740 Tizen::Base::String
2741 _ControlImpl::GetFont(void) const
2742 {
2743         return GetCore().GetFont();
2744 }
2745
2746 bool
2747 _ControlImpl::IsEnabled(void) const
2748 {
2749         return GetCore().IsEnabled();
2750 }
2751
2752 bool
2753 _ControlImpl::GetEnableState(void) const
2754 {
2755         return GetCore().GetEnableState();
2756 }
2757
2758 void
2759 _ControlImpl::SetEnableState(bool enableState)
2760 {
2761         GetCore().SetEnableState(enableState);
2762 }
2763
2764 bool
2765 _ControlImpl::IsInputEnabled(void) const
2766 {
2767         return GetCore().IsInputEnabled();
2768 }
2769
2770 bool
2771 _ControlImpl::GetInputEnableState(void) const
2772 {
2773         return GetCore().GetInputEnableState();
2774 }
2775
2776 void
2777 _ControlImpl::SetInputEnableState(bool inputEnableState)
2778 {
2779         GetCore().SetInputEnableState(inputEnableState);
2780 }
2781
2782 bool
2783 _ControlImpl::IsVisible(void) const
2784 {
2785         // [ToDo] Change the default visible state to false and test.
2786         return GetCore().IsVisible();
2787 }
2788
2789 bool
2790 _ControlImpl::GetVisibleState(void) const
2791 {
2792         return GetCore().GetVisibleState();
2793 }
2794
2795 result
2796 _ControlImpl::SetVisibleState(bool visibleState)
2797 {
2798 #ifdef _TC_PASS
2799         SysTryReturn(NID_UI,
2800                                 GetParent() || IsAttachedToMainTree(), E_INVALID_OPERATION,
2801                                 E_INVALID_OPERATION, "[E_INVALID_OPERATION] This control should have a parent or be attached to the main tree.");
2802 #endif
2803         GetCore().SetVisibleState(visibleState);
2804
2805         return E_SUCCESS;
2806 }
2807
2808 bool
2809 _ControlImpl::IsLayoutable(void) const
2810 {
2811         return GetCore().IsLayoutable();
2812 }
2813
2814 bool
2815 _ControlImpl::IsClipToParent(void) const
2816 {
2817         return GetCore().IsClipToParent();
2818 }
2819
2820 result
2821 _ControlImpl::SetClipToParent(bool clipToParent)
2822 {
2823         result r = GetCore().SetClipToParent(clipToParent);
2824         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
2825
2826         return E_SUCCESS;
2827 }
2828
2829 bool
2830 _ControlImpl::IsDragEnabled(void) const
2831 {
2832         return GetCore().IsDragEnabled();
2833 }
2834
2835 bool
2836 _ControlImpl::IsDropEnabled(void) const
2837 {
2838         return GetCore().IsDropEnabled();
2839 }
2840
2841 void
2842 _ControlImpl::SetDragEnabled(bool enabled)
2843 {
2844         ClearLastResult();
2845         GetCore().SetDragEnabled(enabled);
2846 }
2847
2848 void
2849 _ControlImpl::SetDropEnabled(bool enabled)
2850 {
2851         ClearLastResult();
2852         GetCore().SetDropEnabled(enabled);
2853 }
2854
2855 Rectangle
2856 _ControlImpl::GetBounds(void) const
2857 {
2858         return GetCore().GetBounds();
2859 }
2860
2861 Point
2862 _ControlImpl::GetPosition(void) const
2863 {
2864         return GetCore().GetPosition();
2865 }
2866
2867 Dimension
2868 _ControlImpl::GetSize(void) const
2869 {
2870         return GetCore().GetSize();
2871 }
2872
2873 result
2874 _ControlImpl::SetBounds(const Rectangle& bounds, bool callBoundsChangeCallbacks)
2875 {
2876         Rectangle builderBounds;
2877         _ControlOrientation controlOrientation = _CONTROL_ORIENTATION_PORTRAIT;
2878         bool exist = GetBuilderBounds(controlOrientation, builderBounds);
2879         if (exist)
2880         {
2881                 if (IsAttachedToMainTree())
2882                 {
2883                         _ControlImplManager* pControlImplManager = _ControlImplManager::GetInstance();
2884                         OrientationStatus orientation = pControlImplManager->GetFormOrientationStatus(this);
2885
2886                         if (orientation == ORIENTATION_STATUS_LANDSCAPE
2887                                 || orientation == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
2888                         {
2889                                 SetBuilderBounds(_CONTROL_ORIENTATION_LANDSCAPE, bounds);
2890                         }
2891                         else
2892                         {
2893                                 SetBuilderBounds(_CONTROL_ORIENTATION_PORTRAIT, bounds);
2894                         }
2895                 }
2896                 else
2897                 {
2898                         SetBuilderBounds(_CONTROL_ORIENTATION_PORTRAIT, bounds);
2899                         SetBuilderBounds(_CONTROL_ORIENTATION_LANDSCAPE, bounds);
2900                 }
2901         }
2902         return GetCore().SetBounds(bounds, callBoundsChangeCallbacks);
2903 }
2904
2905 result
2906 _ControlImpl::SetBoundsAndUpdateLayout(const Tizen::Graphics::Rectangle& bounds)
2907 {
2908         result r = E_SUCCESS;
2909         r = GetCore().SetBounds(bounds);
2910
2911         GetCore().UpdateLayout();
2912
2913         return r;
2914 }
2915
2916 result
2917 _ControlImpl::SetPosition(const Point& position)
2918 {
2919         return GetCore().SetPosition(position);
2920 }
2921
2922 result
2923 _ControlImpl::SetSize(const Dimension& size)
2924 {
2925         return GetCore().SetSize(size);
2926 }
2927
2928 Dimension
2929 _ControlImpl::GetMinimumSize(void) const
2930 {
2931         return GetCore().GetMinimumSize();
2932 }
2933
2934 Dimension
2935 _ControlImpl::GetMaximumSize(void) const
2936 {
2937         return GetCore().GetMaximumSize();
2938 }
2939
2940 result
2941 _ControlImpl::SetMinimumSize(const Dimension& newMinSize)
2942 {
2943         return GetCore().SetMinimumSize(newMinSize);
2944 }
2945
2946 result
2947 _ControlImpl::SetMaximumSize(const Dimension& newMaxSize)
2948 {
2949         return GetCore().SetMaximumSize(newMaxSize);
2950 }
2951
2952 Point
2953 _ControlImpl::ConvertToControlPosition(const Point& screenPosition) const
2954 {
2955         return GetCore().ConvertToControlPosition(screenPosition);
2956 }
2957
2958 Point
2959 _ControlImpl::ConvertToScreenPosition(const Point& controlPosition) const
2960 {
2961         return GetCore().ConvertToScreenPosition(controlPosition);
2962 }
2963
2964 // [ToDo] Must provide a static method.
2965 Dimension
2966 _ControlImpl::GetMinimumSizeLimit(void) const
2967 {
2968         ClearLastResult();
2969         return Dimension(0, 0);
2970 }
2971
2972 // [ToDo] Must provide a static method.
2973 Dimension
2974 _ControlImpl::GetMaximumSizeLimit(void) const
2975 {
2976         ClearLastResult();
2977         return Dimension(_Control::MAX_LENGTH, _Control::MAX_LENGTH);
2978 }
2979
2980 Rectangle
2981 _ControlImpl::GetClientBounds(void) const
2982 {
2983         return GetCore().GetClientBounds();
2984 }
2985
2986 Rectangle
2987 _ControlImpl::GetAbsoluteBounds(void) const
2988 {
2989         return GetCore().GetAbsoluteBounds();
2990 }
2991
2992 result
2993 _ControlImpl::SetClientBounds(const Rectangle& bounds)
2994 {
2995         return GetCore().SetClientBounds(bounds);
2996 }
2997
2998 Color
2999 _ControlImpl::GetBackgroundColor(void) const
3000 {
3001         return GetCore().GetBackgroundColor();
3002 }
3003
3004 bool
3005 _ControlImpl::IsOpaque(void) const
3006 {
3007         return false;
3008 }
3009
3010 void
3011 _ControlImpl::SetBackgroundColor(const Color& color)
3012 {
3013         if (!IsOpaque())
3014         {
3015                 GetCore().SetBackgroundColor(color);
3016         }
3017         else
3018         {
3019                 byte r, g, b, a;
3020                 color.GetColorComponents(r, g, b, a);
3021                 GetCore().SetBackgroundColor(Color(r*a/ 255, g*a/255, b*a/ 255, 255));
3022         }
3023 }
3024
3025 Color
3026 _ControlImpl::GetForegroundColor(void) const
3027 {
3028         ClearLastResult();
3029         return __foregroundColor;
3030 }
3031
3032 void
3033 _ControlImpl::SetForegroundColor(const Color& color)
3034 {
3035         ClearLastResult();
3036         __foregroundColor = color;
3037 }
3038
3039 int
3040 _ControlImpl::GetFontSize(void) const
3041 {
3042         ClearLastResult();
3043         return __fontSize;
3044 }
3045
3046 void
3047 _ControlImpl::SetFontSize(int fontSize)
3048 {
3049         ClearLastResult();
3050         __fontSize = fontSize;
3051 }
3052
3053 ITouchEventListener*
3054 _ControlImpl::GetDefaultTouchEventListener(void) const
3055 {
3056         ClearLastResult();
3057         return __pDefaultTouchEventListener;
3058 }
3059
3060 IKeyEventListener*
3061 _ControlImpl::GetDefaultKeyEventListener(void) const
3062 {
3063         ClearLastResult();
3064         return __pDefaultKeyEventListener;
3065 }
3066
3067 void
3068 _ControlImpl::SetDefaultKeyEventListener(IKeyEventListener* pDefaultListener)
3069 {
3070         ClearLastResult();
3071         __pDefaultKeyEventListener = pDefaultListener;
3072 }
3073
3074 void
3075 _ControlImpl::SetDefaultTouchEventListener(ITouchEventListener* pDefaultListener)
3076 {
3077         ClearLastResult();
3078         __pDefaultTouchEventListener = pDefaultListener;
3079 }
3080
3081 CompositeMode
3082 _ControlImpl::GetCompositeMode(void) const
3083 {
3084         ClearLastResult();
3085         return COMPOSITE_MODE_ALPHA_BLENDING;
3086 }
3087
3088 result
3089 _ControlImpl::SetCompositeMode(CompositeMode compositeMode)
3090 {
3091         ClearLastResult();
3092
3093         if (compositeMode == COMPOSITE_MODE_ALPHA_BLENDING)
3094         {
3095                 return E_SUCCESS;
3096         }
3097
3098         SysLogException(NID_UI, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
3099         return E_UNSUPPORTED_OPERATION;
3100 }
3101
3102 result
3103 _ControlImpl::SetChromaKeyColor(Color chromaKeyColor)
3104 {
3105         SysLogException(NID_UI, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
3106         return E_UNSUPPORTED_OPERATION;
3107 }
3108
3109 Color
3110 _ControlImpl::GetChromaKeyColor(void) const
3111 {
3112         static const Color errorColor(0, 0, 0, 0);
3113         SysLogException(NID_UI, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
3114         return errorColor;
3115 }
3116
3117 Animations::ControlAnimator*
3118 _ControlImpl::GetControlAnimator(void) const
3119 {
3120         ClearLastResult();
3121
3122         if ((IsMovable() == false) && (IsResizable() == false))
3123         {
3124                 SysLog(NID_UI, "Control is not animatable.\n");
3125                 return null;
3126         }
3127
3128         if (__pControlAnimator == null)
3129         {
3130                 ControlAnimator* pControlAnimator = new (std::nothrow) ControlAnimator();
3131                 SysTryReturn(NID_UI, (pControlAnimator != null), null, E_OUT_OF_MEMORY, "Unable to create ControlAnimator instance.\n");
3132
3133                 // [ToDo] Check if the Open API can return E_SYSTEM.
3134                 result r = pControlAnimator->Construct(*__pControlPublic);
3135                 if (IsFailed(r))
3136                 {
3137                         delete pControlAnimator;
3138                         SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] Failed to create control animator.");
3139                         return null;
3140                 }
3141
3142                 (const_cast <_ControlImpl*>(this))->__pControlAnimator = pControlAnimator;
3143         }
3144
3145         return __pControlAnimator;
3146 }
3147
3148 VisualElement*
3149 _ControlImpl::GetVisualElement(void) const
3150 {
3151         return GetCore().GetVisualElement();
3152 }
3153
3154 void
3155 _ControlImpl::SetMultiTouchEnabled(bool enabled)
3156 {
3157         GetCore().SetMultiTouchEnabled(enabled);
3158 }
3159
3160 bool
3161 _ControlImpl::IsMultiTouchEnabled(void) const
3162 {
3163         return GetCore().IsMultiTouchEnabled();
3164 }
3165
3166 _ControlImpl::PublicEventListenerList*
3167 _ControlImpl::CreatePublicEventListenerListN(void) const
3168 {
3169         PublicEventListenerList* pListenerList = new (std::nothrow) PublicEventListenerList;
3170         SysTryReturn(NID_UI, pListenerList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3171
3172         return pListenerList;
3173 }
3174
3175 bool
3176 _ControlImpl::HasCore(void) const
3177 {
3178         return __pControlCore != null;
3179 }
3180
3181 result
3182 _ControlImpl::SetCore(_Control& core)
3183 {
3184         result r = E_SUCCESS;
3185
3186         __pControlCore = &core;
3187         __pControlCore->SetControlDelegate(*this);
3188         __pControlCore->SetUserData(this);
3189
3190         __pCoreEventListener = new (std::nothrow) CoreEventListener(*this);
3191         SysTryCatch(NID_UI, __pCoreEventListener, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3192
3193         __pControlCore->SetEventListener<_UI_EVENT_FOCUS>(__pCoreEventListener);
3194         __pControlCore->SetEventListener<_UI_EVENT_NOTIFICAITON>(__pCoreEventListener);
3195
3196         __pPropagatedTouchEventListener = new (std::nothrow) _PropagatedTouchEventListener(*this);
3197         SysTryCatch(NID_UI, __pPropagatedTouchEventListener, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3198
3199         __pControlCore->SetPropagatedTouchEventListener(__pPropagatedTouchEventListener);
3200
3201         __pPropagatedKeyEventListener = new (std::nothrow) _PropagatedKeyEventListener(*this);
3202         SysTryCatch(NID_UI, __pPropagatedKeyEventListener, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3203
3204         __pControlCore->SetPropagatedKeyEventListener(__pPropagatedKeyEventListener);
3205
3206         return E_SUCCESS;
3207
3208 CATCH:
3209         ResetCore();
3210         SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
3211         return r;
3212 }
3213
3214 void
3215 _ControlImpl::ResetCore(bool deallocate)
3216 {
3217         if (__pControlCore == null)
3218         {
3219                 return;
3220         }
3221
3222         __pControlCore->ResetEventListeners();
3223         __pControlCore->SetUserData(null);
3224         __pControlCore->ResetControlDelegate();
3225
3226         __pFlickGestureDetector->RemoveGestureListener(*__pCoreEventListener);
3227         __pControlCore->RemoveGestureDetector(*__pFlickGestureDetector);
3228
3229         __pLongPressGestureDetector->RemoveGestureListener(*__pCoreEventListener);
3230         __pControlCore->RemoveGestureDetector(*__pLongPressGestureDetector);
3231
3232         __pControlCore->SetPropagatedTouchEventListener(null);
3233         __pControlCore->SetPropagatedKeyEventListener(null);
3234
3235         if (deallocate)
3236         {
3237                 delete __pControlCore;
3238         }
3239         __pControlCore = null;
3240
3241         delete __pCoreEventListener;
3242         __pCoreEventListener = null;
3243
3244         delete __pPropagatedTouchEventListener;
3245         __pPropagatedTouchEventListener = null;
3246
3247         delete __pPropagatedKeyEventListener;
3248         __pPropagatedKeyEventListener = null;
3249 }
3250
3251 void
3252 _ControlImpl::Dispose(bool deallocateCore)
3253 {
3254         if(GetVisualElement() && __pCustomVisualElement)
3255         {
3256                 GetVisualElement()->DetachChild( *__pCustomVisualElement);
3257         }
3258         __pCustomVisualElement = null;
3259         // Reset core
3260         ResetCore(deallocateCore);
3261
3262         // Release core events
3263         delete __pCoreKeyEvent;
3264         __pCoreKeyEvent = null;
3265         delete __pCoreTouchEvent;
3266         __pCoreTouchEvent = null;
3267         delete __pCoreFocusEvent;
3268         __pCoreFocusEvent = null;
3269         delete __pCoreGestureEvent;
3270         __pCoreGestureEvent = null;
3271
3272         // Relese public event listeners
3273         delete __pPublicFocusEventListeners;
3274         __pPublicFocusEventListeners = null;
3275         delete __pPublicKeyEventListeners;
3276         __pPublicKeyEventListeners = null;
3277         delete __pPublicTouchEventListeners;
3278         __pPublicTouchEventListeners = null;
3279         delete __pPublicDragDropEventListeners;
3280         __pPublicDragDropEventListeners = null;
3281         delete __pPublicTouchModeChangedEventListeners;
3282         __pPublicTouchModeChangedEventListeners = null;
3283
3284         // Release builder bounds
3285         delete __pBuilderPortraitBounds;
3286         __pBuilderPortraitBounds = null;
3287         delete __pBuilderLandscapeBounds;
3288         __pBuilderLandscapeBounds = null;
3289
3290         // Release aninator
3291         delete __pControlAnimator;
3292         __pControlAnimator = null;
3293
3294         delete __pPublicGestureDetectors;
3295         __pPublicGestureDetectors = null;
3296
3297         delete __pFlickGestureDetector;
3298         __pFlickGestureDetector = null;
3299
3300         delete __pLongPressGestureDetector;
3301         __pLongPressGestureDetector = null;
3302
3303         delete __pAccessibilityContainerImpl;
3304         __pAccessibilityContainerImpl = null;
3305 }
3306
3307 _ControlImpl::~_ControlImpl(void)
3308 {
3309         Dispose(true);
3310 }
3311
3312 _ControlImpl::_ControlImpl(Control* pPublic, _Control* pCore)
3313         : __pControlPublic(pPublic)
3314         , __pControlCore(null)
3315         , __pControlAnimator(null)
3316         , __pCustomVisualElement(null)
3317         , __pPublicFocusEventListeners(null)
3318         , __pPublicKeyEventListeners(null)
3319         , __pPublicTouchEventListeners(null)
3320         , __pPublicDragDropEventListeners(null)
3321         , __pPublicTouchModeChangedEventListeners(null)
3322         , __pDefaultKeyEventListener(null)
3323         , __pDefaultTouchEventListener(null)
3324         , __foregroundColor(Color(0, 0, 0, 0))
3325         , __fontSize(0)
3326         , __inputEventConsumed(false)
3327         , __focusableChangable(true)
3328         , __pCoreEventListener(null)
3329         , __pCoreKeyEvent(null)
3330         , __pCoreTouchEvent(null)
3331         , __pCoreFocusEvent(null)
3332         , __pCoreGestureEvent(null)
3333         , __pBuilderPortraitBounds(null)
3334         , __pBuilderLandscapeBounds(null)
3335         , __pFlickGestureDetector(null)
3336         , __pLongPressGestureDetector(null)
3337         , __pPublicGestureDetectors(null)
3338         , __pAccessibilityContainerImpl(null)
3339 {
3340         ClearLastResult();
3341         result r = E_SUCCESS;
3342
3343         SysAssert(__pControlPublic);
3344         SysAssert(pCore);
3345
3346         // Set core
3347         r = SetCore(*pCore);
3348         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3349
3350         // Core event listeners: [ToDo: mklove.kang] Check exceptions because the constructors can fail.
3351         __pCoreKeyEvent = new (std::nothrow) CoreKeyEvent(*this);
3352         SysTryCatch(NID_UI, __pCoreKeyEvent, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3353
3354         __pCoreTouchEvent = new (std::nothrow) CoreTouchEvent(*this);
3355         SysTryCatch(NID_UI, __pCoreTouchEvent, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3356
3357         __pCoreFocusEvent = new (std::nothrow) CoreFocusEvent(*this);
3358         SysTryCatch(NID_UI, __pCoreFocusEvent, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3359
3360         __pCoreGestureEvent = new (std::nothrow) CoreGestureEvent(*this);
3361         SysTryCatch(NID_UI, __pCoreGestureEvent, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3362
3363         __pFlickGestureDetector = new (std::nothrow) _TouchFlickGestureDetector;
3364         SysTryCatch(NID_UI, __pFlickGestureDetector, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3365
3366         __pLongPressGestureDetector = new (std::nothrow) _TouchLongPressGestureDetector;
3367         SysTryCatch(NID_UI, __pLongPressGestureDetector, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3368
3369         // Public listeners
3370         __pPublicFocusEventListeners = CreatePublicEventListenerListN();
3371         r = GetLastResult();
3372         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3373
3374         __pPublicKeyEventListeners = CreatePublicEventListenerListN();
3375         r = GetLastResult();
3376         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3377
3378         __pPublicTouchEventListeners = CreatePublicEventListenerListN();
3379         r = GetLastResult();
3380         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3381
3382         __pPublicDragDropEventListeners = CreatePublicEventListenerListN();
3383         r = GetLastResult();
3384         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3385
3386         __pPublicTouchModeChangedEventListeners = CreatePublicEventListenerListN();
3387         r = GetLastResult();
3388         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3389
3390         __pPublicGestureDetectors = new (std::nothrow) LinkedListT<TouchGestureDetector*>;
3391         r = GetLastResult();
3392         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3393
3394         r = _ResourceManager::GetInstance()->GetColor(L"DEFAULTCOLORTABLE::foreground", __foregroundColor);
3395         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3396
3397         // Check
3398         SysAssert(r == E_SUCCESS);
3399
3400         return;
3401
3402 CATCH:
3403         Dispose(true); // [ToDo] Is it OK?
3404 }
3405
3406 _Layout::LayoutContainer&
3407 _ControlImpl::GetLayoutContainer(void) const
3408 {
3409         return GetCore().GetLayoutContainer();
3410 }
3411
3412 result
3413 _ControlImpl::SetBuilderBounds(_ControlOrientation orientation, const Rectangle& bounds)
3414 {
3415         ClearLastResult();
3416
3417         if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
3418         {
3419                 if (__pBuilderPortraitBounds == null)
3420                 {
3421                         __pBuilderPortraitBounds = new (std::nothrow) Rectangle(0, 0, 0, 0);
3422
3423                         SysTryReturn(NID_UI,
3424                                                 __pBuilderPortraitBounds, E_OUT_OF_MEMORY,
3425                                                 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3426                 }
3427
3428                 *__pBuilderPortraitBounds = bounds;
3429                 return E_SUCCESS;
3430         }
3431         else if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
3432         {
3433                 if (__pBuilderLandscapeBounds == null)
3434                 {
3435                         __pBuilderLandscapeBounds = new (std::nothrow) Rectangle(0, 0, 0, 0);
3436
3437                         SysTryReturn(NID_UI,
3438                                                 __pBuilderLandscapeBounds, E_OUT_OF_MEMORY,
3439                                                 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
3440                 }
3441
3442                 *__pBuilderLandscapeBounds = bounds;
3443                 return E_SUCCESS;
3444         }
3445
3446         SysAssert(false);
3447         return E_SYSTEM;
3448 }
3449
3450 bool
3451 _ControlImpl::GetBuilderBounds(_ControlOrientation orientation, Rectangle& bounds) const
3452 {
3453         ClearLastResult();
3454
3455         if (orientation == _CONTROL_ORIENTATION_PORTRAIT && __pBuilderPortraitBounds)
3456         {
3457                 bounds = *__pBuilderPortraitBounds;
3458                 return true;
3459         }
3460         else if (orientation == _CONTROL_ORIENTATION_LANDSCAPE && __pBuilderLandscapeBounds)
3461         {
3462                 bounds = *__pBuilderLandscapeBounds;
3463                 return true;
3464         }
3465
3466         return false;
3467 }
3468
3469 Bitmap*
3470 _ControlImpl::GetCapturedBitmapN(void) const
3471 {
3472         return GetCore().GetCapturedBitmapN(true);
3473 }
3474
3475 Rectangle
3476 _ControlImpl::GetInvalidatedBounds(void) const
3477 {
3478         return GetCore().GetInvalidatedBounds();
3479 }
3480
3481 result
3482 _ControlImpl::GenerateKeyEvent(KeyState keyState, _KeyCode keyCode)
3483 {
3484         result r = E_SUCCESS;
3485
3486         SysTryReturn(NID_UI, keyState == KEY_LONGPRESSED,
3487                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] keyState is invalid.\n");
3488
3489         SysTryReturn(NID_UI, __pCoreKeyEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
3490
3491         __pCoreKeyEvent->ProcessListener(keyState, keyCode);
3492
3493         return r;
3494 }
3495
3496 result
3497 _ControlImpl::GenerateTouchEvent(const _TouchInfo& touchInfo)
3498 {
3499         result r = E_SUCCESS;
3500
3501         _TouchStatus touchStatus = touchInfo.GetTouchStatus();
3502
3503         SysTryReturn(NID_UI, (touchStatus == _TOUCH_LONG_PRESSED) || (touchStatus == _TOUCH_DOUBLE_PRESSED),
3504                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] touchStatus is invalid.\n");
3505
3506         SysTryReturn(NID_UI, __pCoreTouchEvent, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
3507
3508         __pCoreTouchEvent->ProcessListener(touchInfo);
3509
3510         return r;
3511 }
3512
3513 void
3514 _ControlImpl::SetMovable(bool movable)
3515 {
3516         GetCore().SetMovable(movable);
3517 }
3518
3519 void
3520 _ControlImpl::SetResizable(bool resizable)
3521 {
3522         GetCore().SetResizable(resizable);
3523 }
3524
3525 AccessibilityContainer*
3526 _ControlImpl::GetAccessibilityContainer(void)
3527 {
3528         if(__pAccessibilityContainerImpl == null)
3529         {
3530                 AccessibilityContainer* pContainer = _AccessibilityContainerImpl::CreateAccessibilityContainerN(*this);
3531                 if(pContainer)
3532                 {
3533                         __pAccessibilityContainerImpl = _AccessibilityContainerImpl::GetInstance(*pContainer);
3534                         return pContainer;
3535                 }
3536                 else
3537                         return null;
3538         }
3539         else
3540         {
3541                 return &(__pAccessibilityContainerImpl->GetPublic());
3542         }
3543 }
3544
3545 }} // Tizen::Ui