0adee2dfee25ed1b4e47d4db0a6c7d1c1cacabdd
[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 Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali-toolkit/dali-toolkit.h>
22
23 namespace Dali
24 {
25
26 namespace Toolkit
27 {
28
29 class DummyControlImpl;
30
31 /**
32  * Control does not have a New method so use this dummy class for the handle.
33  */
34 class DummyControl : public Control
35 {
36 public:
37
38   DummyControl()
39   : mCustomSlot1Called(false)
40   {
41   }
42
43   DummyControl(const DummyControl& control)
44   : Control( control ),
45     mCustomSlot1Called(false)
46   {
47   }
48
49   virtual ~DummyControl()
50   {
51   }
52
53   static DummyControl New( bool override = false );
54
55   static DummyControl DownCast( BaseHandle handle )
56   {
57     return Control::DownCast<DummyControl, DummyControlImpl>(handle);
58   }
59
60   DummyControl& operator=(const DummyControl& control)
61   {
62     Control::operator=( control );
63     return *this;
64   }
65
66   // Used to test signal connections
67   void CustomSlot1( Actor actor, const Vector3& value )
68   {
69     mCustomSlot1Called = true;
70     mCustomSlot1Value = value;
71   }
72
73 public:
74
75   bool mCustomSlot1Called;
76   Vector3 mCustomSlot1Value;
77
78 public: // Not intended for application developers
79
80   DummyControl( DummyControlImpl& implementation );
81   DummyControl( Dali::Internal::CustomActor* internal );
82 };
83
84 /**
85  * Cannot create an instance of ControlImpl, so use this dummy class for the implementation.
86  * This class does not override any of ControlImpl's behaviour.
87  */
88 class DummyControlImpl : public ControlImpl
89 {
90 public:
91
92   static DummyControl New()
93   {
94     IntrusivePtr< DummyControlImpl > impl = new DummyControlImpl;
95     DummyControl control( *impl );
96     impl->Initialize();
97     return control;
98   }
99
100 public:
101   void EnableGestureDetection(Gesture::Type type) { ControlImpl::EnableGestureDetection(type); }
102   void DisableGestureDetection(Gesture::Type type) { ControlImpl::DisableGestureDetection(type); }
103   PinchGestureDetector GetPinchGestureDetector() const { return ControlImpl::GetPinchGestureDetector(); }
104   PanGestureDetector GetPanGestureDetector() const { return ControlImpl::GetPanGestureDetector(); }
105   TapGestureDetector GetTapGestureDetector() const { return ControlImpl::GetTapGestureDetector(); }
106   LongPressGestureDetector GetLongPressGestureDetector() const { return ControlImpl::GetLongPressGestureDetector(); }
107
108 protected:
109
110   DummyControlImpl()
111   : ControlImpl(true)
112   {
113   }
114
115   virtual ~DummyControlImpl()
116   {
117   }
118 };
119
120 /**
121  * Cannot create an instance of ControlImpl, so use this dummy class for the implementation.
122  * This class DOES override ControlImpl's behaviour.
123  */
124 class DummyControlImplOverride : public DummyControlImpl
125 {
126 public:
127
128   static DummyControl New()
129   {
130     IntrusivePtr< DummyControlImplOverride > impl = new DummyControlImplOverride;
131     DummyControl control( *impl );
132     impl->Initialize();
133     return control;
134   }
135
136 private:
137
138   DummyControlImplOverride()
139   : DummyControlImpl(),
140     initializeCalled(false),
141     themeChangeCalled(false),
142     fontChangeCalled( 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 OnThemeChange( StyleManager styleManager ) { themeChangeCalled = true }
167   virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange ) { fontChangeCalled = true;}
168   virtual void OnPinch(PinchGesture pinch) { pinchCalled = true; }
169   virtual void OnPan(PanGesture pan) { panCalled = true; }
170   virtual void OnTap(TapGesture tap) { tapCalled = true; }
171   virtual void OnLongPress(LongPressGesture longPress) { longPressCalled = true; }
172
173 private: // From CustomActorImpl
174
175   virtual void OnStageConnection() { stageConnectionCalled = true; }
176   virtual void OnStageDisconnection() { stageDisconnectionCalled = true; }
177   virtual void OnChildAdd(Actor& child) { childAddCalled = true; }
178   virtual void OnChildRemove(Actor& child) { childRemoveCalled = true; }
179   virtual void OnSizeSet(const Vector3& targetSize) { sizeSetCalled = true; }
180   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) { sizeAnimationCalled = true; }
181   virtual bool OnTouchEvent(const TouchEvent& event) { touchEventCalled = true; return false; }
182   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { mouseWheelEventCalled = true; return false; }
183   virtual bool OnKeyEvent(const KeyEvent& event) { keyEventCalled = true; return false;}
184   virtual void OnKeyInputFocusGained() { keyInputFocusGained = true; }
185   virtual void OnKeyInputFocusLost() { keyInputFocusLost = true; }
186
187 public:
188
189   bool initializeCalled;
190   bool themeChangeCalled;
191   bool fontChangeCalled;
192   bool pinchCalled;
193   bool panCalled;
194   bool tapCalled;
195   bool longPressCalled;
196   bool stageConnectionCalled;
197   bool stageDisconnectionCalled;
198   bool childAddCalled;
199   bool childRemoveCalled;
200   bool sizeSetCalled;
201   bool sizeAnimationCalled;
202   bool touchEventCalled;
203   bool mouseWheelEventCalled;
204   bool keyEventCalled;
205   bool keyInputFocusGained;
206   bool keyInputFocusLost;
207 };
208
209 DummyControl DummyControl::New( bool override )
210 {
211   DummyControl control;
212
213   if (override)
214   {
215     control = DummyControlImplOverride::New();
216   }
217   else
218   {
219     control = DummyControlImpl::New();
220   }
221
222   return control;
223 }
224
225 DummyControl::DummyControl( DummyControlImpl& implementation )
226 : Control( implementation )
227 {
228 }
229
230 DummyControl::DummyControl( Dali::Internal::CustomActor* internal )
231 : Control( internal )
232 {
233   VerifyCustomActorPointer<DummyControlImpl>(internal);
234 }
235
236 } // namespace Toolkit
237
238 } // namespace Dali
239
240 #endif // __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__