Refactored Button and derived classes, moving state change and transition logic to...
[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 private: // From Button
65
66   /**
67    * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
68    */
69   virtual void OnButtonInitialize();
70
71   /**
72    * @copydoc Toolkit::Internal::Button::OnLabelSet()
73    */
74   virtual void OnLabelSet();
75
76   /**
77    * @copydoc Toolkit::Internal::Button::OnButtonImageSet()
78    */
79   virtual void OnButtonImageSet();
80
81   /**
82    * @copydoc Toolkit::Internal::Button::OnSelectedImageSet()
83    */
84   virtual void OnSelectedImageSet();
85
86   /**
87    * @copydoc Toolkit::Internal::Button::OnBackgroundImage()
88    */
89   virtual void OnBackgroundImageSet();
90
91   /**
92    * @copydoc Toolkit::Internal::Button::OnSelectedBackgroundImageSet()
93    */
94   virtual void OnSelectedBackgroundImageSet();
95
96   /**
97    * @copydoc Toolkit::Internal::Button::OnDisabledImageSet()
98    */
99   virtual void OnDisabledImageSet();
100
101   /**
102    * @copydoc Toolkit::Internal::Button::OnDisabledSelectedImageSet()
103    */
104   virtual void OnDisabledSelectedImageSet();
105
106   /**
107    * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet()
108    */
109   virtual void OnDisabledBackgroundImageSet();
110
111   /**
112    * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor )
113    */
114   virtual void PrepareForTranstionIn( Actor actor );
115
116   /**
117    * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor )
118    */
119   virtual void PrepareForTranstionOut( Actor actor );
120
121   /**
122    * @copydoc Toolkit::Internal::Button::OnTransitionIn( Actor actor )
123    */
124   virtual void OnTransitionIn( Actor actor );
125
126   /**
127    * @copydoc Toolkit::Internal::Button::OnTransitionOut( Actor actor )
128    */
129   virtual void OnTransitionOut( Actor actor );
130
131 private: // From Control
132
133   /**
134    * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
135    */
136   virtual void OnSizeSet( const Vector3& targetSize );
137
138   /**
139    * @copydoc Toolkit::Control::GetNaturalSize
140    */
141   virtual Vector3 GetNaturalSize();
142
143   /**
144    * @copydoc Toolkit::Control::OnSetResizePolicy
145    */
146   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
147
148 private:
149
150   /**
151    * It adds the actor to the root actor and to the fade in animation.
152    * @param[inout] actor The actor.
153    * @param[in] opacity The opacity to fade to
154    */
155   void FadeImageTo( Actor actor, float opacity );
156
157   /**
158    * @brief Custom configuration for size negotiation
159    */
160   void ConfigureSizeNegotiation();
161
162   /**
163    * @brief Configure size negotiation for a given dimension
164    *
165    * @param[in] dimension The dimension to configure
166    * @param[in] images The list of images to configure
167    * @param[in] label The text label to configure
168    */
169   void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label );
170
171 private:
172
173   // Undefined
174   PushButton( const PushButton& );
175
176   // Undefined
177   PushButton& operator=( const PushButton& );
178
179 private:
180
181   Vector3               mSize;                      ///< The button's size.
182 };
183
184 } // namespace Internal
185
186 // Helpers for public-api forwarding methods
187
188 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
189 {
190   DALI_ASSERT_ALWAYS( button );
191
192   Dali::RefObject& handle = button.GetImplementation();
193
194   return static_cast<Toolkit::Internal::PushButton&>( handle );
195 }
196
197 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
198 {
199   DALI_ASSERT_ALWAYS( button );
200
201   const Dali::RefObject& handle = button.GetImplementation();
202
203   return static_cast<const Toolkit::Internal::PushButton&>( handle );
204 }
205
206 } // namespace Toolkit
207
208 } // namespace Dali
209
210 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__