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