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