2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
18 * @file FUi_TouchGestureDetectorImpl.cpp
19 * @brief This is the implementation file for %_TouchGestureDetectorImpl class
22 * This file contains the implementation of %_TouchGestureDetectorImpl class.
26 #include <FUiTouchEventInfo.h>
27 #include <FBaseSysLog.h>
28 #include "FUi_TouchGestureDetectorImpl.h"
29 #include "FUi_ITouchEventListener.h"
30 #include "FUi_TouchEventArg.h"
31 #include "FUi_TouchManager.h"
33 using namespace Tizen::Base::Collection;
35 namespace Tizen { namespace Ui
38 _TouchGestureDetectorImpl::_TouchGestureDetectorImpl(TouchGestureDetector* pPublic, _TouchGestureDetector* pCore)
39 : __pPublicGestureEventListenerList(null)
41 __pPublicGestureDetector = pPublic;
42 __pCoreGestureDetector = pCore;
44 __pPublicGestureEventListenerList = new (std::nothrow) LinkedListT<ITouchGestureEventListener*>;
45 SysTryReturnVoidResult(NID_UI, __pPublicGestureEventListenerList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
47 pCore->SetUserData(this);
48 pCore->SetDelegate(*this);
53 _TouchGestureDetectorImpl*
54 _TouchGestureDetectorImpl::CreateInstanceN(TouchGestureDetector* pPublic)
58 _TouchGestureDetector* pCore = null;
59 pCore = new (std::nothrow) _TouchGestureDetector;
60 SysTryReturn(NID_UI, pCore, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
62 _TouchGestureDetectorImpl* pImpl = new (std::nothrow) _TouchGestureDetectorImpl(pPublic, pCore);
63 SysTryCatch(NID_UI, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
75 _TouchGestureDetectorImpl::~_TouchGestureDetectorImpl(void)
77 delete __pPublicGestureEventListenerList;
78 __pPublicGestureEventListenerList = null;
80 delete __pCoreGestureDetector;
81 __pCoreGestureDetector = null;
86 const _TouchGestureDetector&
87 _TouchGestureDetectorImpl::GetCore(void) const
89 return *__pCoreGestureDetector;
92 _TouchGestureDetector&
93 _TouchGestureDetectorImpl::GetCore(void)
95 return *__pCoreGestureDetector;
98 const TouchGestureDetector&
99 _TouchGestureDetectorImpl::GetPublic(void) const
101 return *__pPublicGestureDetector;
104 TouchGestureDetector&
105 _TouchGestureDetectorImpl::GetPublic(void)
107 return *__pPublicGestureDetector;
110 _TouchGestureDetectorImpl*
111 _TouchGestureDetectorImpl::GetInstance(TouchGestureDetector& gestureDetector)
113 return gestureDetector.__pTouchGestureDetectorImpl;
116 const _TouchGestureDetectorImpl*
117 _TouchGestureDetectorImpl::GetInstance(const TouchGestureDetector& gestureDetector)
119 return gestureDetector.__pTouchGestureDetectorImpl;
123 _TouchGestureDetectorImpl::AddGestureEventListener(ITouchGestureEventListener& listener)
125 bool exist = __pPublicGestureEventListenerList->Contains(const_cast<ITouchGestureEventListener*>(&listener));
128 return E_OBJ_ALREADY_EXIST;
131 result r = __pPublicGestureEventListenerList->Add(&listener);
132 SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "%s Propagating", GetErrorMessage(r));
138 _TouchGestureDetectorImpl::RemoveGestureEventListener(ITouchGestureEventListener& listener)
140 result r = __pPublicGestureEventListenerList->Remove(&listener);
141 SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "%s Propagating", GetErrorMessage(r));
146 IListT <ITouchGestureEventListener*>*
147 _TouchGestureDetectorImpl::GetGestureEventListenerList(void) const
149 return __pPublicGestureEventListenerList;
153 _TouchGestureDetectorImpl::SetDetectorState(TouchGestureDetectorState state)
155 GetCore().SetDetectorState(static_cast<_TouchGestureDetectorState>(state));
160 TouchGestureDetectorState
161 _TouchGestureDetectorImpl::GetDetectorState(void) const
165 return static_cast<TouchGestureDetectorState>(GetCore().GetDetectorState());
169 _TouchGestureDetectorImpl::GetControl(void) const
171 _Control* pControl = GetCore().GetControl();
172 SysTryReturn(NID_UI, pControl, null, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
176 _ControlImpl* pControlImpl = static_cast<_ControlImpl*>(pControl->GetUserData());
177 return &(pControlImpl->GetPublic());
181 _TouchGestureDetectorImpl::SetDelayTouchEventEnabled(bool enable)
183 GetCore().SetDelayTouchEventEnabled(enable);
189 _TouchGestureDetectorImpl::IsDelayTouchEventEnabled(void) const
193 return GetCore().IsDelayTouchEventEnabled();
197 _TouchGestureDetectorImpl::SetCancelTouchEventOnSuccessEnabled(bool enable)
199 GetCore().SetCancelTouchEventOnSuccessEnabled(enable);
205 _TouchGestureDetectorImpl::IsCancelTouchEventOnSuccessEnabled(void) const
209 return GetCore().IsCancelTouchEventOnSuccessEnabled();
213 _TouchGestureDetectorImpl::StartOnFailureOf(const TouchGestureDetector& gesture)
215 const _TouchGestureDetectorImpl* pImpl = GetInstance(gesture);
216 SysTryReturnResult(NID_UI, pImpl, E_INVALID_ARG, "[E_INVALID_ARG] This instance is invalid.");
218 result r = GetCore().StartOnFailureOf(pImpl->GetCore());
219 SysTryLog(NID_UI, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
225 _TouchGestureDetectorImpl::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
228 TouchGestureDetector& publicDetector = GetPublic();
229 Control* pControl = static_cast<Control*>(source.GetUserData());
230 _TouchEventArg* pEventArg = null;
234 TouchEventInfo publicTouchInfo;
236 pEventArg = GetTouchEventArgN(*pControl, touchinfo);
237 SysTryReturn(NID_UI, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
239 publicTouchInfo.Construct(*pEventArg);
241 publicDetector.OnTouchPressed(*pControl, publicTouchInfo);
245 _TouchGestureDetector& coreDetector = GetCore();
247 coreDetector.OnTouchPressed(source, touchinfo);
254 _TouchGestureDetectorImpl::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
257 TouchGestureDetector& publicDetector = GetPublic();
258 Control* pControl = static_cast<Control*>(source.GetUserData());
259 _TouchEventArg* pEventArg = null;
263 TouchEventInfo publicTouchInfo;
265 pEventArg = GetTouchEventArgN(*pControl, touchinfo);
266 SysTryReturn(NID_UI, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
268 publicTouchInfo.Construct(*pEventArg);
270 publicDetector.OnTouchMoved(*pControl, publicTouchInfo);
274 _TouchGestureDetector& coreDetector = GetCore();
276 coreDetector.OnTouchMoved(source, touchinfo);
283 _TouchGestureDetectorImpl::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
286 TouchGestureDetector& publicDetector = GetPublic();
287 Control* pControl = static_cast<Control*>(source.GetUserData());
288 _TouchEventArg* pEventArg = null;
292 TouchEventInfo publicTouchInfo;
294 pEventArg = GetTouchEventArgN(*pControl, touchinfo);
295 SysTryReturn(NID_UI, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
297 publicTouchInfo.Construct(*pEventArg);
299 publicDetector.OnTouchReleased(*pControl, publicTouchInfo);
303 _TouchGestureDetector& coreDetector = GetCore();
305 coreDetector.OnTouchReleased(source, touchinfo);
312 _TouchGestureDetectorImpl::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
315 TouchGestureDetector& publicDetector = GetPublic();
316 Control* pControl = static_cast<Control*>(source.GetUserData());
317 _TouchEventArg* pEventArg = null;
321 TouchEventInfo publicTouchInfo;
323 pEventArg = GetTouchEventArgN(*pControl, touchinfo);
324 SysTryReturn(NID_UI, pEventArg, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
326 publicTouchInfo.Construct(*pEventArg);
328 publicDetector.OnTouchCanceled(*pControl, publicTouchInfo);
332 _TouchGestureDetector& coreDetector = GetCore();
333 coreDetector.OnTouchCanceled(source, touchinfo);
341 _TouchGestureDetectorImpl::GetTouchEventArgN(const Control& source, const _TouchInfo& touchInfo)
345 _TouchManager* pTouchManager = _TouchManager::GetInstance();
346 SysTryReturn(NID_UI, pTouchManager, null, E_SYSTEM, "[E_SYSTEM] _TouchManager does not exist.");
348 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(source, touchInfo.GetTouchStatus());
349 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
351 pEventArg->SetTouchPosition(touchInfo.GetPointId(), pTouchManager->GetStartPoint(touchInfo.GetPointId()).x,
352 pTouchManager->GetStartPoint(touchInfo.GetPointId()).y,
353 touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);