[dali_1.1.30] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
3
4 /*
5  * Copyright (c) 2014 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
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include "button-impl.h"
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 /**
38  * PushButton implementation class.
39  *
40  * \sa Dali::Toolkit::PushButton
41  */
42 class PushButton : public Button
43 {
44 public:
45
46   /**
47    * Create a new PushButton.
48    * @return A smart-pointer to the newly allocated PushButton.
49    */
50   static Dali::Toolkit::PushButton New();
51
52 protected:
53
54   /**
55    * Construct a new PushButton.
56    */
57   PushButton();
58
59   /**
60    * A reference counted object may only be deleted by calling Unreference()
61    */
62   virtual ~PushButton();
63
64 public:
65
66   // Properties
67
68   /**
69    * Enum for the alignment modes of the icon.
70    */
71   enum IconAlignment
72   {
73     LEFT,
74     RIGHT,
75     TOP,
76     BOTTOM,
77     DEFAULT = RIGHT
78   };
79
80   /**
81    * Called when a property of an object of this type is set.
82    * @param[in] object The object whose property is set.
83    * @param[in] index The property index.
84    * @param[in] value The new property value.
85    */
86   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
87
88   /**
89    * Called to retrieve a property of an object of this type.
90    * @param[in] object The object whose property is to be retrieved.
91    * @param[in] index The property index.
92    * @return The current value of the property.
93    */
94   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
95
96 private: // From Button
97
98   /**
99    * @copydoc Toolkit::Internal::Button::OnInitialize
100    */
101   virtual void OnInitialize();
102
103   /**
104    * @copydoc Toolkit::Internal::Button::OnLabelSet
105    */
106   virtual void OnLabelSet( bool noPadding );
107
108   /**
109    * @copydoc Toolkit::Internal::Button::OnButtonImageSet
110    */
111   virtual void OnButtonImageSet();
112
113   /**
114    * @copydoc Toolkit::Internal::Button::OnSelectedImageSet
115    */
116   virtual void OnSelectedImageSet();
117
118   /**
119    * @copydoc Toolkit::Internal::Button::OnBackgroundImage
120    */
121   virtual void OnBackgroundImageSet();
122
123   /**
124    * @copydoc Toolkit::Internal::Button::OnSelectedBackgroundImageSet
125    */
126   virtual void OnSelectedBackgroundImageSet();
127
128   /**
129    * @copydoc Toolkit::Internal::Button::OnDisabledImageSet
130    */
131   virtual void OnDisabledImageSet();
132
133   /**
134    * @copydoc Toolkit::Internal::Button::OnDisabledSelectedImageSet
135    */
136   virtual void OnDisabledSelectedImageSet();
137
138   /**
139    * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet
140    */
141   virtual void OnDisabledBackgroundImageSet();
142
143   /**
144    * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor )
145    */
146   virtual void PrepareForTranstionIn( Actor actor );
147
148   /**
149    * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor )
150    */
151   virtual void PrepareForTranstionOut( Actor actor );
152
153   /**
154    * @copydoc Toolkit::Internal::Button::OnTransitionIn( Actor actor )
155    */
156   virtual void OnTransitionIn( Actor actor );
157
158   /**
159    * @copydoc Toolkit::Internal::Button::OnTransitionOut( Actor actor )
160    */
161   virtual void OnTransitionOut( Actor actor );
162
163 private: // From Control
164
165   /**
166    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
167    */
168   virtual void OnSizeSet( const Vector3& targetSize );
169
170   /**
171    * @copydoc Toolkit::Control::GetNaturalSize
172    */
173   virtual Vector3 GetNaturalSize();
174
175   /**
176    * @copydoc Toolkit::Control::OnSetResizePolicy
177    */
178   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
179
180 private:
181
182   /**
183    * It adds the actor to the root actor and to the fade in animation.
184    * @param[inout] actor The actor.
185    * @param[in] opacity The opacity to fade to
186    */
187   void FadeImageTo( Actor actor, float opacity );
188
189   /**
190    * @brief Custom configuration for size negotiation
191    */
192   void ConfigureSizeNegotiation();
193
194   /**
195    * @brief Configure size negotiation for a given dimension
196    *
197    * @param[in] dimension The dimension to configure
198    * @param[in] images The list of images to configure
199    * @param[in] label The text label to configure
200    */
201   void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label );
202
203   /**
204    * @brief Sets either the selected or unselected icon.
205    *
206    * @param[in] state The icon state to set
207    * @param[in] iconFilename The filename of the icon
208    */
209   void SetIcon( DecorationState state, const std::string iconFilename );
210
211   /**
212    * @brief Gets either the selected or unselected icon.
213    *
214    * @param[in] state The icon state to get
215    * @return    The filename of the icon
216    */
217   std::string& GetIcon( DecorationState state );
218
219   /**
220    * @brief Sets the alignment mode to use to align the icon to the label.
221    *
222    * @param[in] iconAlignment The alignment mode to use
223    */
224   void SetIconAlignment( const PushButton::IconAlignment iconAlignment );
225
226   /**
227    * @brief Gets the alignment mode used to align the icon to the label.
228    *
229    * @return The alignment mode in use
230    */
231   const PushButton::IconAlignment GetIconAlignment() const;
232
233   /**
234    * @brief Sets the padding for the label.
235    *
236    * @param[in] padding The padding to set
237    */
238   void SetLabelPadding( const Vector4& padding );
239
240   /**
241    * @brief Gets the padding for the label.
242    *
243    * @return The label padding
244    */
245   Vector4 GetLabelPadding();
246
247   /**
248    * @brief Sets the padding for the icon.
249    *
250    * @param[in] padding The padding to set
251    */
252   void SetIconPadding( const Vector4& padding );
253
254   /**
255    * @brief Gets the padding for the icon.
256    *
257    * @return The icon padding
258    */
259   Vector4 GetIconPadding();
260
261 private:
262
263   // Undefined
264   PushButton( const PushButton& );
265
266   // Undefined
267   PushButton& operator=( const PushButton& );
268
269 private:
270
271   std::string    mIconName[ DECORATION_STATES ]; ///< The original filenames for the icons.
272   Padding        mLabelPadding;                  ///< The padding around the label (if present).
273   Padding        mIconPadding;                   ///< The padding around the icon (if present).
274   IconAlignment  mIconAlignment;                 ///< The alignment of the icon against the label.
275   Vector3        mSize;                          ///< The button's size.
276 };
277
278 } // namespace Internal
279
280 // Helpers for public-api forwarding methods
281
282 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
283 {
284   DALI_ASSERT_ALWAYS( button );
285
286   Dali::RefObject& handle = button.GetImplementation();
287
288   return static_cast<Toolkit::Internal::PushButton&>( handle );
289 }
290
291 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
292 {
293   DALI_ASSERT_ALWAYS( button );
294
295   const Dali::RefObject& handle = button.GetImplementation();
296
297   return static_cast<const Toolkit::Internal::PushButton&>( handle );
298 }
299
300 } // namespace Toolkit
301
302 } // namespace Dali
303
304 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__