[AT-SPI] Rename AccessibleImpl to <Control>Accessible
[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::Button::OnRelayout
132    */
133   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
134
135   /**
136    * This method is called when the button is pressed.
137    */
138   void OnPressed() override;
139
140 private:
141   // Undefined
142   ToggleButton(const ToggleButton&);
143
144   // Undefined
145   ToggleButton& operator=(const ToggleButton&);
146
147 private:
148   Property::Array                    mToggleStates;                  ///< Toggle states, string or map.
149   std::vector<Toolkit::Visual::Base> mToggleVisuals;                 ///< Save all unselected visuals.
150   std::vector<Toolkit::Visual::Base> mToggleSelectedVisuals;         ///< Save all selected visuals.
151   std::vector<Toolkit::Visual::Base> mToggleDisabledVisuals;         ///< Save all disabled unselected visuals.
152   std::vector<Toolkit::Visual::Base> mToggleDisabledSelectedVisuals; ///< Save all disabled selected visuals.
153   std::vector<std::string>           mToggleTooltips;                ///< Toggle tooltips.
154   unsigned int                       mCurrentToggleIndex;            ///< The index of state.
155
156 protected:
157   class ToggleButtonAccessible : public Button::ButtonAccessible
158   {
159   public:
160     using Button::ButtonAccessible::ButtonAccessible;
161
162     /**
163      * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::CalculateStates()
164      */
165     Dali::Accessibility::States CalculateStates() override;
166
167     /**
168      * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::GetDescriptionRaw()
169      */
170     std::string GetDescriptionRaw() const override;
171
172     /**
173      * @copydoc Dali::Toolkit::DevelControl::ControlAccessible::GetDescriptionPropertyIndex()
174      */
175     Property::Index GetDescriptionPropertyIndex() override;
176   };
177
178   void OnStateChange(State newState) override;
179 };
180
181 } // namespace Internal
182
183 // Helpers for public-api forwarding methods
184
185 inline Toolkit::Internal::ToggleButton& GetImplementation(Toolkit::ToggleButton& button)
186 {
187   DALI_ASSERT_ALWAYS(button);
188
189   Dali::RefObject& handle = button.GetImplementation();
190
191   return static_cast<Toolkit::Internal::ToggleButton&>(handle);
192 }
193
194 inline const Toolkit::Internal::ToggleButton& GetImplementation(const Toolkit::ToggleButton& button)
195 {
196   DALI_ASSERT_ALWAYS(button);
197
198   const Dali::RefObject& handle = button.GetImplementation();
199
200   return static_cast<const Toolkit::Internal::ToggleButton&>(handle);
201 }
202
203 } // namespace Toolkit
204
205 } // namespace Dali
206
207 #endif // DALI_TOOLKIT_INTERNAL_TOGGLE_BUTTON_H