Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / FUi_UiEvent.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_UiEvent.cpp
19  * @brief               This is the implementation file for the _UiEvent class.
20  */
21
22 #include <FBaseResult.h>
23 #include <FBaseSysLog.h>
24 #include <FApp_AppInfo.h>
25 #include "FUi_UiEvent.h"
26 #include "FUi_Control.h"
27 #include "FUi_ControlManager.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::App;
31
32 namespace Tizen { namespace Ui
33 {
34 _UiEvent::_UiEvent(const _UiObjectHandle& destination, const _UiObjectHandle& source, _UiEventRouteType routeType)
35         : __destination(destination)
36         , __source(source)
37         , __originalDestination(destination)
38         , __routeType(routeType)
39         , __accessibilityEvent(false)
40 {
41 }
42
43 _UiEvent::~_UiEvent(void)
44 {
45 }
46
47 _UiEvent::_UiEvent(const _UiEvent& rhs)
48         : __destination(rhs.__destination)
49         , __source(rhs.__source)
50         , __originalDestination(rhs.__originalDestination)
51         , __routeType(rhs.__routeType)
52         , __accessibilityEvent(rhs.__accessibilityEvent)
53 {
54 }
55
56 _UiEvent&
57 _UiEvent::operator =(const _UiEvent& rhs)
58 {
59         if (this != &rhs)
60         {
61                 __destination = rhs.__destination;
62                 __source = rhs.__source;
63                 __originalDestination = rhs.__originalDestination;
64                 __routeType = rhs.__routeType;
65         }
66
67         return *this;
68 }
69
70 _UiObjectHandle
71 _UiEvent::GetDestination(void) const
72 {
73         return __destination;
74 }
75
76 _UiObjectHandle
77 _UiEvent::GetSource(void) const
78 {
79         return __source;
80 }
81
82 void
83 _UiEvent::SetOriginalDestination(const _Control& control)
84 {
85         __originalDestination = control.GetHandle();
86 }
87
88 _UiObjectHandle
89 _UiEvent::GetOriginalDestination(void) const
90 {
91         return __originalDestination;
92 }
93
94 void
95 _UiEvent::SetRouteType(_UiEventRouteType routeType)
96 {
97         __routeType = routeType;
98 }
99
100 _UiEventRouteType
101 _UiEvent::GetRouteType(void) const
102 {
103         return __routeType;
104 }
105
106 result
107 _UiEvent::ProcessPreviewEvent(const _Control& control, bool& isFiltered)
108 {
109         if (!IsEventReceivable(control))
110         {
111                 return E_SUCCESS;
112         }
113
114         return OnPreviewEventProcessing(control, isFiltered);
115 }
116
117 result
118 _UiEvent::ProcessEvent(const _Control& control, bool& isFiltered)
119 {
120         if (!IsEventReceivable(control))
121         {
122                 return E_SUCCESS;
123         }
124
125         bool isInputFiltered = isFiltered;
126         result r = OnEventProcessing(control, isFiltered);
127         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
128
129         if (!isInputFiltered && isFiltered)
130         {
131                 const _Control* pTarget = GetControl(GetDestination());
132                 SysTryReturn(NID_UI, pTarget, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
133
134                 if (IsEventReceivable(*pTarget) && (pTarget != &control))
135                 {
136                         r = OnEventHandled(control);
137                 }
138         }
139
140         return r;
141 }
142
143 result
144 _UiEvent::ProcessListener(const _IUiEventListener& listener, bool& isFiltered)
145 {
146         return OnListenerProcessing(listener, isFiltered);
147 }
148
149 const _Control*
150 _UiEvent::GetControl(const _UiObjectHandle& handle) const
151 {
152         _ControlManager* pControlManager = _ControlManager::GetInstance();
153         SysTryReturn(NID_UI, pControlManager, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
154
155         return pControlManager->GetObject(handle);
156 }
157
158 bool
159 _UiEvent::IsEventReceivable(const _Control& control) const
160 {
161         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
162         {
163                 return true;
164         }
165
166         if (!control.IsEnabled())
167         {
168                 return false;
169         }
170
171         return true;
172 }
173
174 result
175 _UiEvent::OnEventHandled(const _Control& control)
176 {
177         return E_SUCCESS;
178 }
179
180 void
181 _UiEvent::SetAccessibilityEvent(bool set)
182 {
183         __accessibilityEvent = set;
184 }
185
186 bool
187 _UiEvent::GetAccessibilityEvent(void) const
188 {
189         return __accessibilityEvent;
190 }
191
192 }} // Tizen::Ui