License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / control / dummy-control.h
1 #ifndef __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__
2 #define __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/dali-toolkit.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 class DummyControlImpl;
31
32 /**
33  * Control does not have a New method so use this dummy class for the handle.
34  */
35 class DummyControl : public Control
36 {
37 public:
38
39   DummyControl()
40   : mCustomSlot1Called(false)
41   {
42   }
43
44   DummyControl(const DummyControl& control)
45   : Control( control ),
46     mCustomSlot1Called(false)
47   {
48   }
49
50   virtual ~DummyControl()
51   {
52   }
53
54   static DummyControl New( bool override = false );
55
56   static DummyControl DownCast( BaseHandle handle )
57   {
58     return Control::DownCast<DummyControl, DummyControlImpl>(handle);
59   }
60
61   DummyControl& operator=(const DummyControl& control)
62   {
63     Control::operator=( control );
64     return *this;
65   }
66
67   // Used to test signal connections
68   void CustomSlot1( Actor actor, const Vector3& value )
69   {
70     mCustomSlot1Called = true;
71     mCustomSlot1Value = value;
72   }
73
74 public:
75
76   bool mCustomSlot1Called;
77   Vector3 mCustomSlot1Value;
78
79 public: // Not intended for application developers
80
81   DummyControl( DummyControlImpl& implementation );
82   DummyControl( Dali::Internal::CustomActor* internal );
83 };
84
85 /**
86  * Cannot create an instance of ControlImpl, so use this dummy class for the implementation.
87  * This class does not override any of ControlImpl's behaviour.
88  */
89 class DummyControlImpl : public ControlImpl
90 {
91 public:
92
93   static DummyControl New()
94   {
95     IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
96     DummyControl control( *impl );
97     impl->Initialize();
98     return control;
99   }
100
101 public:
102   void EnableGestureDetection(Gesture::Type type) { ControlImpl::EnableGestureDetection(type); }
103   void DisableGestureDetection(Gesture::Type type) { ControlImpl::DisableGestureDetection(type); }
104   PinchGestureDetector GetPinchGestureDetector() const { return ControlImpl::GetPinchGestureDetector(); }
105   PanGestureDetector GetPanGestureDetector() const { return ControlImpl::GetPanGestureDetector(); }
106   TapGestureDetector GetTapGestureDetector() const { return ControlImpl::GetTapGestureDetector(); }
107   LongPressGestureDetector GetLongPressGestureDetector() const { return ControlImpl::GetLongPressGestureDetector(); }
108
109 protected:
110
111   DummyControlImpl()
112   : ControlImpl(true)
113   {
114   }
115
116   virtual ~DummyControlImpl()
117   {
118   }
119 };
120
121 /**
122  * Cannot create an instance of ControlImpl, so use this dummy class for the implementation.
123  * This class DOES override ControlImpl's behaviour.
124  */
125 class DummyControlImplOverride : public DummyControlImpl
126 {
127 public:
128
129   static DummyControl New()
130   {
131     IntrusivePtr< DummyControlImplOverride > impl = new DummyControlImplOverride;
132     DummyControl control( *impl );
133     impl->Initialize();
134     return control;
135   }
136
137 private:
138
139   DummyControlImplOverride()
140   : DummyControlImpl(),
141     initializeCalled(false),
142     styleChangeCalled(false),
143     pinchCalled(false),
144     panCalled(false),
145     tapCalled(false),
146     longPressCalled(false),
147     stageConnectionCalled(false),
148     stageDisconnectionCalled(false),
149     childAddCalled(false),
150     childRemoveCalled(false),
151     sizeSetCalled(false),
152     sizeAnimationCalled(false),
153     touchEventCalled(false),
154     mouseWheelEventCalled(false),
155     keyEventCalled(false),
156     keyInputFocusGained(false),
157     keyInputFocusLost(false)
158   {
159   }
160
161   virtual ~DummyControlImplOverride() { }
162
163 private: // From ControlImpl
164
165   virtual void OnInitialize() { initializeCalled = true; }
166   virtual void OnStyleChange(StyleChange change) { styleChangeCalled = true;}
167   virtual void OnPinch(PinchGesture pinch) { pinchCalled = true; }
168   virtual void OnPan(PanGesture pan) { panCalled = true; }
169   virtual void OnTap(TapGesture tap) { tapCalled = true; }
170   virtual void OnLongPress(LongPressGesture longPress) { longPressCalled = true; }
171
172 private: // From CustomActorImpl
173
174   virtual void OnStageConnection() { stageConnectionCalled = true; }
175   virtual void OnStageDisconnection() { stageDisconnectionCalled = true; }
176   virtual void OnChildAdd(Actor& child) { childAddCalled = true; }
177   virtual void OnChildRemove(Actor& child) { childRemoveCalled = true; }
178   virtual void OnSizeSet(const Vector3& targetSize) { sizeSetCalled = true; }
179   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) { sizeAnimationCalled = true; }
180   virtual bool OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
181   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { mouseWheelEventCalled = true; return false; }
182   virtual bool OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
183   virtual void OnKeyInputFocusGained() { keyInputFocusGained = true; }
184   virtual void OnKeyInputFocusLost() { keyInputFocusLost = true; }
185
186 public:
187
188   bool initializeCalled;
189   bool styleChangeCalled;
190   bool pinchCalled;
191   bool panCalled;
192   bool tapCalled;
193   bool longPressCalled;
194   bool stageConnectionCalled;
195   bool stageDisconnectionCalled;
196   bool childAddCalled;
197   bool childRemoveCalled;
198   bool sizeSetCalled;
199   bool sizeAnimationCalled;
200   bool touchEventCalled;
201   bool mouseWheelEventCalled;
202   bool keyEventCalled;
203   bool keyInputFocusGained;
204   bool keyInputFocusLost;
205 };
206
207 DummyControl DummyControl::New( bool override )
208 {
209   DummyControl control;
210
211   if (override)
212   {
213     control = DummyControlImplOverride::New();
214   }
215   else
216   {
217     control = DummyControlImpl::New();
218   }
219
220   return control;
221 }
222
223 DummyControl::DummyControl( DummyControlImpl& implementation )
224 : Control( implementation )
225 {
226 }
227
228 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
229 : Control( internal )
230 {
231   VerifyCustomActorPointer<DummyControlImpl>(internal);
232 }
233
234 } // namespace Toolkit
235
236 } // namespace Dali
237
238 #endif // __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__