[dali_1.0.36] Merge branch 'tizen'
[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   virtual Vector3 GetNaturalSize();
143
144 private:
145
146   /**
147    * Starts the transition animation.
148    * PushButton::TransitionAnimationFinished slot is called when the animation finishes.
149    */
150   void StartTransitionAnimation();
151
152   /**
153    * Stops the transition animation.
154    * @param[in] remove If true, removes the fadeout actor from root.
155    */
156   void StopTransitionAnimation( bool remove = true );
157
158   /**
159    * It adds the actor to the root actor and to the fade in animation.
160    * @param[inout] image The actor.
161    * @param[in] opacity The initial opacity.
162    * @param[in] scale The initial scale.
163    */
164   void FadeInImage( Actor& image, float opacity = 0.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) );
165
166   /**
167    * It adds the actor fade out animation and stores it to be removed when the animation finishes.
168    * @param[in] layer Defines if the actor is going to be stored in the mFadeOutBackgroundImage or mFadeOutCheckedImage member.
169    * @param[inout] image The actor.
170    * @param[in] opacity The initial opacity.
171    * @param[in] scale The initial scale.
172    */
173   void FadeOutImage( Actor& image, float opacity = 1.f, Vector3 scale = Vector3( 1.f, 1.f, 1.f ) );
174
175   // slots
176
177   /**
178    * Called when the transition animation finishes.
179    */
180   void TransitionAnimationFinished( Dali::Animation& source );
181
182 private:
183
184   // Undefined
185   PushButton( const PushButton& );
186
187   // Undefined
188   PushButton& operator=( const PushButton& );
189
190 private:
191
192   Animation             mTransitionAnimation;       ///< Animation used in the state transitions.
193   Vector3               mSize;                      ///< The button's size.
194 };
195
196 } // namespace Internal
197
198 // Helpers for public-api forwarding methods
199
200 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
201 {
202   DALI_ASSERT_ALWAYS( button );
203
204   Dali::RefObject& handle = button.GetImplementation();
205
206   return static_cast<Toolkit::Internal::PushButton&>( handle );
207 }
208
209 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
210 {
211   DALI_ASSERT_ALWAYS( button );
212
213   const Dali::RefObject& handle = button.GetImplementation();
214
215   return static_cast<const Toolkit::Internal::PushButton&>( handle );
216 }
217
218 } // namespace Toolkit
219
220 } // namespace Dali
221
222 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__