Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUiTouchEventInfo.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                        FUiTouchEventInfo.cpp
19  * @brief               This is the implementation file for TouchEventInfo class
20  * @version             2.0
21  *
22  * This file contains the implementation of TouchEventInfo class.
23  *
24  */
25
26 #include <FBaseResult.h>
27 #include <FUiTouchEventInfo.h>
28 #include "FUi_TouchEventInfoImpl.h"
29 #include "FUi_TouchEventArg.h"
30 #include "FUi_TouchManager.h"
31
32 using namespace Tizen::Base::Runtime;
33 using namespace Tizen::Graphics;
34
35 namespace Tizen { namespace Ui
36 {
37
38 TouchEventInfo::TouchEventInfo(void)
39         : __pTouchEventInfoImpl(null)
40 {
41 }
42
43 TouchEventInfo::~TouchEventInfo(void)
44 {
45         delete __pTouchEventInfoImpl;
46         __pTouchEventInfoImpl = null;
47 }
48
49 result
50 TouchEventInfo::Construct(const IEventArg& eventArg)
51 {
52         SysAssertf(__pTouchEventInfoImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
53
54         const _TouchEventArg* pTouchArg = dynamic_cast <const _TouchEventArg*>(&eventArg);
55         SysTryReturnResult(NID_UI, pTouchArg, E_INVALID_ARG, "[E_INVALID_ARG] pTouchArg is invalid.");
56
57         _TouchEventInfoImpl* pImpl = _TouchEventInfoImpl::CreateInstanceN(this);
58         result r = GetLastResult();
59         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
60
61         __pTouchEventInfoImpl = pImpl;
62
63         _TouchInfo touchInfo(pTouchArg->GetPointId(), pTouchArg->GetTouchStatus(), pTouchArg->GetCurrentPosition(), pTouchArg->IsFlicked(), 0);
64         Point startPosition = pTouchArg->GetStartPosition();
65
66         __pTouchEventInfoImpl->SetTouchEventInfo(touchInfo, startPosition);
67
68         return E_SUCCESS;
69 }
70
71 unsigned long
72 TouchEventInfo::GetPointId(void) const
73 {
74         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
75
76         return __pTouchEventInfoImpl->GetPointId();
77 }
78
79
80 Point
81 TouchEventInfo::GetStartPosition(void) const
82 {
83         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
84
85         return __pTouchEventInfoImpl->GetStartPosition();
86 }
87
88 Point
89 TouchEventInfo::GetCurrentPosition(void) const
90 {
91         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
92
93         return __pTouchEventInfoImpl->GetCurrentPosition();
94 }
95
96
97 TouchStatus
98 TouchEventInfo::GetTouchStatus(void) const
99 {
100         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
101
102         TouchStatus status = TOUCH_PRESSED;
103
104         switch (__pTouchEventInfoImpl->GetTouchStatus())
105         {
106         case _TOUCH_PRESSED:
107                 status = TOUCH_PRESSED;
108                 break;
109         case _TOUCH_LONG_PRESSED:
110                 status = TOUCH_LONG_PRESSED;
111                 break;
112         case _TOUCH_RELEASED:
113                 status = TOUCH_RELEASED;
114                 break;
115         case _TOUCH_MOVED:
116                 status = TOUCH_MOVED;
117                 break;
118         case _TOUCH_DOUBLE_PRESSED:
119                 status = TOUCH_DOUBLE_PRESSED;
120                 break;
121         case _TOUCH_FOCUS_IN:
122                 status = TOUCH_FOCUS_IN;
123                 break;
124         case _TOUCH_FOCUS_OUT:
125                 status = TOUCH_FOCUS_OUT;
126                 break;
127         case _TOUCH_CANCELED:
128                 status = TOUCH_CANCELED;
129                 break;
130         default:
131                 break;
132         }
133
134         return status;
135 }
136
137 bool
138 TouchEventInfo::IsFlicked(void) const
139 {
140         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
141
142         return __pTouchEventInfoImpl->IsFlicked();
143 }
144
145 }} //Tizen::Ui