[AT-SPI] Remove SetAccessibilityConstructor()
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / toggle-button-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H
2 #define DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/property-array.h>
24 #include <dali/public-api/object/property-value.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/controls/buttons/toggle-button.h>
28 #include "button-impl.h"
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Internal
35 {
36 /**
37  * ToggleButton implementation class.
38  *
39  * \sa Dali::Toolkit::ToggleButton
40  */
41 class ToggleButton : public Button
42 {
43 public:
44   /**
45    * Create a new ToggleButton.
46    * @return A smart-pointer to the newly allocated ToggleButton.
47    */
48   static Dali::Toolkit::ToggleButton New();
49
50 protected:
51   /**
52    * Construct a new ToggleButton.
53    */
54   ToggleButton();
55
56   /**
57    * A reference counted object may only be deleted by calling Unreference()
58    */
59   virtual ~ToggleButton();
60
61 public:
62   /**
63    * Called when a property of an object of this type is set.
64    * @param[in] object The object whose property is set.
65    * @param[in] index The property index.
66    * @param[in] value The new property value.
67    */
68   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
69
70   /**
71    * Called to retrieve a property of an object of this type.
72    * @param[in] object The object whose property is to be retrieved.
73    * @param[in] index The property index.
74    * @return The current value of the property.
75    */
76   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
77
78 private:
79   /**
80    * Called to create all toggle visuals and save them to mToggleVisuals.
81    * @param[in] states The array store toggle states.
82    * @param[out] visuals The created state visual vector.
83    */
84   void CreateVisualsForAllStates(const Property::Array& states, std::vector<Toolkit::Visual::Base>& visuals);
85
86   /**
87    * Called to set toggle states when TOGGLE_STATES is set in SetProperty function.
88    * @param[in] states The array store toggle states.
89    */
90   void SetToggleStates(const Property::Array& states);
91
92   /**
93    * Called to retrieve toggle states.
94    * @return The toggle states array.
95    */
96   Property::Array GetToggleStates() const;
97
98   /**
99    * Called to set toggle tooltips when TOGGLE_TIPS is set in SetProperty function.
100    * @param[in] tips The array store toggle tips.
101    */
102   void SetToggleTooltips(std::vector<std::string>& tips);
103
104   /**
105    * Called to retrieve toggle tips.
106    * @return The toggle tips array.
107    */
108   const std::vector<std::string>& GetToggleTooltips() const;
109
110   /**
111    * Called to prepare visual for next state.
112    * @param[in] index The property index to set.
113    * @param[in] visual The visual to set.
114    */
115   void PrepareVisual(Property::Index index, Toolkit::Visual::Base& visual);
116
117   /**
118    * Called to relayout visual.
119    * @param[in] index The index of visual to relayout.
120    * @param[in] size The size of control.
121    */
122   void RelayoutVisual(Property::Index index, const Vector2& size);
123
124 private: // From Button
125   /**
126    * @copydoc Toolkit::Internal::Button::OnInitialize
127    */
128   void OnInitialize() override;
129
130   /**
131    * @copydoc Toolkit::Internal::Control::CreateAccessibleObject()
132    */
133   DevelControl::ControlAccessible* CreateAccessibleObject() override;
134
135   /**
136    * @copydoc Toolkit::Internal::Button::OnRelayout
137    */
138   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
139
140   /**
141    * This method is called when the button is pressed.
142    */
143   void OnPressed() override;
144
145 private:
146   // Undefined
147   ToggleButton(const ToggleButton&);
148
149   // Undefined
150   ToggleButton& operator=(const ToggleButton&);
151
152 private:
153   Property::Array                    mToggleStates;                  ///< Toggle states, string or map.
154   std::vector<Toolkit::Visual::Base> mToggleVisuals;                 ///< Save all unselected visuals.
155   std::vector<Toolkit::Visual::Base> mToggleSelectedVisuals;         ///< Save all selected visuals.
156   std::vector<Toolkit::Visual::Base> mToggleDisabledVisuals;         ///< Save all disabled unselected visuals.
157   std::vector<Toolkit::Visual::Base> mToggleDisabledSelectedVisuals; ///< Save all disabled selected visuals.
158   std::vector<std::string>           mToggleTooltips;                ///< Toggle tooltips.
159   unsigned int                       mCurrentToggleIndex;            ///< The index of state.
160
161 protected:
162   class ToggleButtonAccessible : public Button::ButtonAccessible
163   {
164   public:
165     using Button::ButtonAccessible::ButtonAccessible;
166
167     /**
168      * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::CalculateStates()
169      */
170     Dali::Accessibility::States CalculateStates() override;
171
172     /**
173      * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::GetDescriptionRaw()
174      */
175     std::string GetDescriptionRaw() const override;
176
177     /**
178      * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::GetDescriptionPropertyIndex()
179      */
180     Property::Index GetDescriptionPropertyIndex() override;
181   };
182
183   void OnStateChange(State newState) override;
184 };
185
186 } // namespace Internal
187
188 // Helpers for public-api forwarding methods
189
190 inline Toolkit::Internal::ToggleButton& GetImplementation(Toolkit::ToggleButton& button)
191 {
192   DALI_ASSERT_ALWAYS(button);
193
194   Dali::RefObject& handle = button.GetImplementation();
195
196   return static_cast<Toolkit::Internal::ToggleButton&>(handle);
197 }
198
199 inline const Toolkit::Internal::ToggleButton& GetImplementation(const Toolkit::ToggleButton& button)
200 {
201   DALI_ASSERT_ALWAYS(button);
202
203   const Dali::RefObject& handle = button.GetImplementation();
204
205   return static_cast<const Toolkit::Internal::ToggleButton&>(handle);
206 }
207
208 } // namespace Toolkit
209
210 } // namespace Dali
211
212 #endif // DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H