Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[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/dali-vector.h>
23 #include <dali/public-api/animation/animation.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
27 #include "button-impl.h"
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * PushButton implementation class.
40  *
41  * \sa Dali::Toolkit::PushButton
42  */
43 class PushButton : public Button
44 {
45 public:
46
47   /**
48    * Create a new PushButton.
49    * @return A smart-pointer to the newly allocated PushButton.
50    */
51   static Dali::Toolkit::PushButton New();
52
53 protected:
54
55   /**
56    * Construct a new PushButton.
57    */
58   PushButton();
59
60   /**
61    * A reference counted object may only be deleted by calling Unreference()
62    */
63   virtual ~PushButton();
64
65 private: // From Button
66
67   /**
68    * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
69    */
70   virtual void OnButtonInitialize();
71
72   /**
73    * @copydoc Toolkit::Internal::Button::OnLabelSet()
74    */
75   virtual void OnLabelSet();
76
77   /**
78    * @copydoc Toolkit::Internal::Button::OnButtonImageSet()
79    */
80   virtual void OnButtonImageSet();
81
82   /**
83    * @copydoc Toolkit::Internal::Button::OnSelectedImageSet()
84    */
85   virtual void OnSelectedImageSet();
86
87   /**
88    * @copydoc Toolkit::Internal::Button::OnBackgroundImage()
89    */
90   virtual void OnBackgroundImageSet();
91
92   /**
93    * @copydoc Toolkit::Internal::Button::OnSelectedBackgroundImageSet()
94    */
95   virtual void OnSelectedBackgroundImageSet();
96
97   /**
98    * @copydoc Toolkit::Internal::Button::OnDisabledImageSet()
99    */
100   virtual void OnDisabledImageSet();
101
102   /**
103    * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet()
104    */
105   virtual void OnDisabledBackgroundImageSet();
106
107   /**
108    * @copydoc Toolkit::Internal::Button::OnSelected()
109    */
110   virtual bool OnSelected();
111
112   /**
113    * @copydoc Toolkit::Internal::Button::OnDisabled()
114    */
115   virtual bool OnDisabled();
116
117   /**
118    * @copydoc Toolkit::Internal::Button::OnPressed()
119    */
120   virtual bool OnPressed();
121
122   /**
123    * @copydoc Toolkit::Internal::Button::OnReleased()
124    */
125   virtual bool OnReleased();
126
127   /**
128    * @copydoc Toolkit::Internal::Button::StopAllAnimations()
129    */
130   virtual void StopAllAnimations();
131
132 private: // From Control
133
134   /**
135    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
136    */
137   virtual void OnControlSizeSet( const Vector3& targetSize );
138
139   /**
140    * @copydoc Toolkit::Control::GetNaturalSize
141    */
142   Vector3 GetNaturalSize();
143
144   /**
145    * @copydoc Toolkit::Control::OnSetResizePolicy
146    */
147   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
148
149 private:
150
151   /**
152    * Starts the transition animation.
153    * PushButton::TransitionAnimationFinished slot is called when the animation finishes.
154    */
155   void StartTransitionAnimation();
156
157   /**
158    * Stops the transition animation.
159    * @param[in] remove If true, removes the fadeout actor from root.
160    */
161   void StopTransitionAnimation( bool remove = true );
162
163   /**
164    * It adds the actor to the root actor and to the fade in animation.
165    * @param[inout] image The actor.
166    * @param[in] opacity The initial opacity.
167    * @param[in] scale The initial scale.
168    */
169   void FadeInImage( Actor& image, float opacity = 0.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) );
170
171   /**
172    * It adds the actor fade out animation and stores it to be removed when the animation finishes.
173    * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
174    * @param[inout] image The actor.
175    * @param[in] opacity The initial opacity.
176    * @param[in] scale The initial scale.
177    */
178   void FadeOutImage( Actor& image, float opacity = 1.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) );
179
180   /**
181    * @brief Custom configuration for size negotiation
182    */
183   void ConfigureSizeNegotiation();
184
185   /**
186    * @brief Configure size negotiation for a given dimension
187    *
188    * @param[in] dimension The dimension to configure
189    * @param[in] images The list of images to configure
190    * @param[in] label The text label to configure
191    */
192   void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const ActorContainer& images, Actor& label );
193
194   // slots
195
196   /**
197    * Called when the transition animation finishes.
198    */
199   void TransitionAnimationFinished( Dali::Animation& source );
200
201 private:
202
203   // Undefined
204   PushButton( const PushButton& );
205
206   // Undefined
207   PushButton& operator=( const PushButton& );
208
209 private:
210
211   Animation             mTransitionAnimation;       ///< Animation used in the state transitions.
212   Vector3               mSize;                      ///< The button's size.
213 };
214
215 } // namespace Internal
216
217 // Helpers for public-api forwarding methods
218
219 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
220 {
221   DALI_ASSERT_ALWAYS( button );
222
223   Dali::RefObject& handle = button.GetImplementation();
224
225   return static_cast<Toolkit::Internal::PushButton&>( handle );
226 }
227
228 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
229 {
230   DALI_ASSERT_ALWAYS( button );
231
232   const Dali::RefObject& handle = button.GetImplementation();
233
234   return static_cast<const Toolkit::Internal::PushButton&>( handle );
235 }
236
237 } // namespace Toolkit
238
239 } // namespace Dali
240
241 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__