[dali_1.2.52] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / dummy-control.h
1 #ifndef __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__
2 #define __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__
3
4 /*
5  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
25 #include <functional>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 class DummyControlImpl;
34 class TransitionData;
35
36 namespace Visual
37 {
38 class Base;
39 }
40
41 /**
42  * Control does not have a New method so use this dummy class for the handle.
43  */
44 class DummyControl : public Control
45 {
46 public:
47   enum PropertyRange
48   {
49     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
50     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property index
51   };
52
53   struct Property
54   {
55     enum Type
56     {
57       TEST_VISUAL = PROPERTY_START_INDEX,
58       TEST_VISUAL2,
59       FOREGROUND_VISUAL,
60       FOCUS_VISUAL,
61       LABEL_VISUAL
62     };
63   };
64
65   DummyControl();
66   DummyControl(const DummyControl& control);
67   ~DummyControl();
68
69   static DummyControl New( bool override = false );
70
71   static DummyControl DownCast( BaseHandle handle );
72
73
74   DummyControl& operator=(const DummyControl& control);
75
76 public: // Not intended for application developers
77
78   DummyControl( DummyControlImpl& implementation );
79   DummyControl( Dali::Internal::CustomActor* internal );
80 };
81
82 /**
83  * Cannot create an instance of Internal::Control, so use this dummy class for the implementation.
84  * This class does not override any of Internal::Control's behaviour.
85  */
86 class DummyControlImpl : public Toolkit::Internal::Control
87 {
88 public:
89
90   static DummyControl New();
91
92 public:
93   inline void EnableGestureDetection(Gesture::Type type) { Internal::Control::EnableGestureDetection(type); }
94   inline void DisableGestureDetection(Gesture::Type type) { Internal::Control::DisableGestureDetection(type); }
95   inline PinchGestureDetector GetPinchGestureDetector() const { return Internal::Control::GetPinchGestureDetector(); }
96   inline PanGestureDetector GetPanGestureDetector() const { return Internal::Control::GetPanGestureDetector(); }
97   inline TapGestureDetector GetTapGestureDetector() const { return Internal::Control::GetTapGestureDetector(); }
98   inline LongPressGestureDetector GetLongPressGestureDetector() const { return Internal::Control::GetLongPressGestureDetector(); }
99
100   void RegisterVisual( Property::Index index, Toolkit::Visual::Base visual);
101   void RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled );
102   void UnregisterVisual( Property::Index index );
103   void EnableVisual( Property::Index index, bool enabled );
104   bool IsVisualEnabled( Property::Index index );
105   int GetVisualCount();
106   Toolkit::Visual::Base GetVisual( Property::Index index );
107   Animation CreateTransition( const Toolkit::TransitionData& transition );
108
109   static void SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
110
111   static Property::Value GetProperty( BaseObject* object, Dali::Property::Index propertyIndex );
112
113   // Used to test signal connections
114   void CustomSlot1( Actor actor );
115
116   bool mCustomSlot1Called;
117   typedef std::vector<Property::Index> VisualIndices;
118   VisualIndices mRegisteredVisualIndices;
119
120 protected:
121
122   DummyControlImpl();
123
124   virtual ~DummyControlImpl();
125 };
126
127 namespace Impl
128 {
129
130 /**
131  * Cannot create an instance of Internal::Control, so use this dummy class for the implementation.
132  * This class DOES override Internal::Control's behaviour.
133  */
134 class DummyControl : public Toolkit::DummyControlImpl
135 {
136 public:
137
138   typedef std::function<void( Size )> RelayoutCallbackFunc;
139
140   static Toolkit::DummyControl New();
141
142   void SetLayout( Property::Index visualIndex, Property::Map& map );
143
144   void SetRelayoutCallback( RelayoutCallbackFunc callback );
145
146 private:
147
148   DummyControl();
149
150   virtual ~DummyControl();
151
152 private: // From Internal::Control
153
154   virtual void OnInitialize();
155   virtual bool OnAccessibilityActivated();
156   virtual bool OnAccessibilityTouch( const TouchEvent& touchEvent );
157   virtual bool OnAccessibilityValueChange( bool isIncrease );
158
159   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
160   virtual void OnPinch(const PinchGesture& pinch);
161   virtual void OnPan(const PanGesture& pan);
162   virtual void OnTap(const TapGesture& tap);
163   virtual void OnLongPress(const LongPressGesture& longPress);
164
165 private: // From CustomActorImpl
166
167   virtual void OnStageConnection( int depth );
168   virtual void OnStageDisconnection();
169   virtual void OnChildAdd(Actor& child);
170   virtual void OnChildRemove(Actor& child);
171   virtual void OnSizeSet(const Vector3& targetSize);
172   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
173   virtual bool OnTouchEvent(const TouchEvent& event);
174   virtual bool OnHoverEvent(const HoverEvent& event);
175   virtual bool OnWheelEvent(const WheelEvent& event);
176   virtual bool OnKeyEvent(const KeyEvent& event);
177   virtual void OnKeyInputFocusGained();
178   virtual void OnKeyInputFocusLost();
179   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
180
181   DALI_INTERNAL DummyControl( const DummyControl& );
182   DALI_INTERNAL DummyControl& operator=( const DummyControl& );
183
184 public:
185
186   bool initializeCalled;
187   bool activatedCalled;
188   bool onAccTouchedCalled;
189   bool onAccValueChangeCalled;
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 hoverEventCalled;
204   bool wheelEventCalled;
205   bool keyEventCalled;
206   bool keyInputFocusGained;
207   bool keyInputFocusLost;
208
209   Property::Map mLayouts;
210   RelayoutCallbackFunc mRelayoutCallback;
211
212 };
213
214 } // namespace Impl
215
216 } // namespace Toolkit
217
218 } // namespace Dali
219
220 #endif // __DALI_TOOLKIT_TEST_DUMMY_CONTROL_H__