modify license, permission and remove ^M char
[platform/framework/native/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 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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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 #include "FUi_CoordinateSystemUtils.h"
32
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::Graphics;
35
36 namespace Tizen { namespace Ui
37 {
38
39 TouchEventInfo::TouchEventInfo(void)
40         : __pTouchEventInfoImpl(null)
41 {
42 }
43
44 TouchEventInfo::~TouchEventInfo(void)
45 {
46         delete __pTouchEventInfoImpl;
47         __pTouchEventInfoImpl = null;
48 }
49
50 result
51 TouchEventInfo::Construct(const IEventArg& eventArg)
52 {
53         SysAssertf(__pTouchEventInfoImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
54
55         const _TouchEventArg* pTouchArg = dynamic_cast <const _TouchEventArg*>(&eventArg);
56         SysTryReturnResult(NID_UI, pTouchArg, E_INVALID_ARG, "[E_INVALID_ARG] pTouchArg is invalid.");
57
58         _TouchEventInfoImpl* pImpl = _TouchEventInfoImpl::CreateInstanceN(this);
59         result r = GetLastResult();
60         SysTryReturn(NID_UI, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
61
62         __pTouchEventInfoImpl = pImpl;
63
64         _TouchInfo touchInfo(pTouchArg->GetPointId(), pTouchArg->GetTouchStatus(), pTouchArg->GetCurrentPosition(), pTouchArg->IsFlicked(), 0);
65         Point startPosition = _CoordinateSystemUtils::ConvertToInteger(pTouchArg->GetStartPosition());
66
67         __pTouchEventInfoImpl->SetTouchEventInfo(touchInfo, startPosition);
68
69         return E_SUCCESS;
70 }
71
72 unsigned long
73 TouchEventInfo::GetPointId(void) const
74 {
75         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
76
77         return __pTouchEventInfoImpl->GetPointId();
78 }
79
80
81 Point
82 TouchEventInfo::GetStartPosition(void) const
83 {
84         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
85
86         return __pTouchEventInfoImpl->GetStartPosition();
87 }
88
89 FloatPoint
90 TouchEventInfo::GetStartPositionF(void) const
91 {
92         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
93
94         return __pTouchEventInfoImpl->GetStartPositionF();
95 }
96
97 Point
98 TouchEventInfo::GetCurrentPosition(void) const
99 {
100         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
101
102         return __pTouchEventInfoImpl->GetCurrentPosition();
103 }
104
105 FloatPoint
106 TouchEventInfo::GetCurrentPositionF(void) const
107 {
108         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
109
110         return __pTouchEventInfoImpl->GetCurrentPositionF();
111 }
112
113
114 TouchStatus
115 TouchEventInfo::GetTouchStatus(void) const
116 {
117         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
118
119         TouchStatus status = TOUCH_PRESSED;
120
121         switch (__pTouchEventInfoImpl->GetTouchStatus())
122         {
123         case _TOUCH_PRESSED:
124                 status = TOUCH_PRESSED;
125                 break;
126         case _TOUCH_LONG_PRESSED:
127                 status = TOUCH_LONG_PRESSED;
128                 break;
129         case _TOUCH_RELEASED:
130                 status = TOUCH_RELEASED;
131                 break;
132         case _TOUCH_MOVED:
133                 status = TOUCH_MOVED;
134                 break;
135         case _TOUCH_DOUBLE_PRESSED:
136                 status = TOUCH_DOUBLE_PRESSED;
137                 break;
138         case _TOUCH_FOCUS_IN:
139                 status = TOUCH_FOCUS_IN;
140                 break;
141         case _TOUCH_FOCUS_OUT:
142                 status = TOUCH_FOCUS_OUT;
143                 break;
144         case _TOUCH_CANCELED:
145                 status = TOUCH_CANCELED;
146                 break;
147         default:
148                 break;
149         }
150
151         return status;
152 }
153
154 bool
155 TouchEventInfo::IsFlicked(void) const
156 {
157         SysAssertf(__pTouchEventInfoImpl != null, "Not yet constructed. Construct() should be called before used.");
158
159         return __pTouchEventInfoImpl->IsFlicked();
160 }
161
162 }} //Tizen::Ui