Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / buttons / check-box-button-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/common/dali-vector.h>
22
23 #include <dali-toolkit/public-api/controls/buttons/check-box-button.h>
24
25 #include "button-impl.h"
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 /**
37  * CheckBoxButton implementation class.
38  *
39  * \sa Dali::Toolkit::CheckBoxButton
40  */
41 class CheckBoxButton : public Button
42 {
43 public:
44
45   /**
46    * Create a new CheckBoxButton.
47    * @return A smart-pointer to the newly allocated CheckBoxButton.
48    */
49   static Dali::Toolkit::CheckBoxButton New();
50
51   /**
52    * @copydoc Dali::Toolkit::CheckBoxButton::SetChecked( bool checked )
53    */
54   void SetChecked( bool checked );
55
56   /**
57    * @copydoc Dali::Toolkit::CheckBoxButton::IsChecked()
58    */
59   bool IsChecked() const;
60
61   /**
62    * @copydoc Dali::Toolkit::CheckBoxButton::SetBackgroundImage( Image image )
63    */
64   void SetBackgroundImage( Image image );
65
66   /**
67    * @copydoc Dali::Toolkit::CheckBoxButton::SetBackgroundImage( Actor image )
68    */
69   void SetBackgroundImage( Actor image );
70
71   /**
72    * Used by the painter only.
73    * @return A reference to the background image.
74    */
75   Actor& GetBackgroundImage();
76
77   /**
78    * @copydoc Dali::Toolkit::CheckBoxButton::GetBackgroundImage()
79    */
80   Actor GetBackgroundImage() const;
81
82   /**
83    * @copydoc Dali::Toolkit::CheckBoxButton::SetCheckedImage( Image image )
84    */
85   void SetCheckedImage( Image image );
86
87   /**
88    * @copydoc Dali::Toolkit::CheckBoxButton::SetCheckedImage( Actor image )
89    */
90   void SetCheckedImage( Actor image );
91
92   /**
93    * Used by the painter only.
94    * @return A reference to the checked image.
95    */
96   Actor& GetCheckedImage();
97
98   /**
99    * @copydoc Dali::Toolkit::CheckBoxButton::GetCheckedImage()
100    */
101   Actor GetCheckedImage() const;
102
103   /**
104    * @copydoc Dali::Toolkit::CheckBoxButton::SetDimmedBackgroundImage( Image image )
105    */
106   void SetDimmedBackgroundImage( Image image );
107
108   /**
109    * @copydoc Dali::Toolkit::CheckBoxButton::SetDimmedBackgroundImage( Actor image )
110    */
111   void SetDimmedBackgroundImage( Actor image );
112
113   /**
114    * Used by the painter only.
115    * @return A reference to the dimmed background image.
116    */
117   Actor& GetDimmedBackgroundImage();
118
119   /**
120    * @copydoc Dali::Toolkit::CheckBoxButton::GetDimmedBackgroundImage()
121    */
122   Actor GetDimmedBackgroundImage() const;
123
124   /**
125    * @copydoc Dali::Toolkit::CheckBoxButton::SetDimmedCheckedImage( Image image )
126    */
127   void SetDimmedCheckedImage( Image image );
128
129   /**
130    * @copydoc Dali::Toolkit::CheckBoxButton::SetDimmedCheckedImage( Actor image )
131    */
132   void SetDimmedCheckedImage( Actor image );
133
134   /**
135    * Used by the painter only.
136    * @return A reference to the dimmed checked image.
137    */
138   Actor& GetDimmedCheckedImage();
139
140   /**
141    * @copydoc Dali::Toolkit::CheckBoxButton::GetDimmedCheckedImage()
142    */
143   Actor GetDimmedCheckedImage() const;
144
145   /**
146    * Used by the painter only.
147    * @return A reference to the background image that is fading out.
148    */
149   Actor& GetFadeOutBackgroundImage();
150
151   /**
152    * Used by the painter only.
153    * @return A reference to the checked image that is fading out.
154    */
155   Actor& GetFadeOutCheckedImage();
156
157 protected: // From ControlImpl
158
159   /**
160    * Respond the activate notification.
161    */
162   virtual void OnActivated();
163
164 private:
165
166   /**
167    * Perform the click action to click the button.
168    * @param[in] attributes The attributes to perfrom this action.
169    */
170   void DoClickAction(const PropertyValueContainer& attributes);
171
172 public:
173   /**
174    * Performs actions as requested using the action name.
175    * @param[in] object The object on which to perform the action.
176    * @param[in] actionName The action to perform.
177    * @param[in] attributes The attributes with which to perfrom this action.
178    * @return true if action has been accepted by this control
179    */
180   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
181
182 protected: // From Button
183
184   /**
185    * Registers properties
186    */
187   virtual void OnButtonInitialize();
188
189   /**
190    * Emits signals and notifies the painter accordingly with the set button
191    * properties when the button is released.
192    */
193   virtual void OnButtonUp();
194
195   /**
196    * Sets the push button animation time.
197    * @param animationTime The animation time in seconds.
198    */
199   virtual void OnAnimationTimeSet( float animationTime );
200
201   /**
202    * Retrieves the animation time.
203    * @return The animation time in seconds.
204    */
205   virtual float OnAnimationTimeRequested() const;
206
207 protected:
208
209   /**
210    * Construct a new CheckBoxButton.
211    */
212   CheckBoxButton();
213
214   /**
215    * A reference counted object may only be deleted by calling Unreference()
216    */
217   virtual ~CheckBoxButton();
218
219 private:
220
221   // Undefined
222   CheckBoxButton( const CheckBoxButton& );
223
224   // Undefined
225   CheckBoxButton& operator=( const CheckBoxButton& );
226
227
228 private:
229   bool  mChecked;                 ///< Stores the check state.
230
231   Actor mBackgroundImage;         ///< Stores the background image.
232   Actor mCheckedImage;            ///< Stores the checked image.
233   Actor mDimmedCheckedImage;      ///< Stores the dimmed checked image.
234   Actor mDimmedBackgroundImage;   ///< Stores the dimmed background image.
235   Actor mFadeOutBackgroundImage;  ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
236   Actor mFadeOutCheckedImage;     ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
237
238   // Actions
239   bool mClickActionPerforming;
240
241   // Properties
242   Property::Index mUseFadeAnimationProperty;
243   Property::Index mUseCheckAnimationProperty;
244 };
245
246 } // namespace Internal
247
248 // Helpers for public-api forwarding methods
249
250 inline Toolkit::Internal::CheckBoxButton& GetImplementation( Toolkit::CheckBoxButton& button )
251 {
252   DALI_ASSERT_ALWAYS( button );
253
254   Dali::RefObject& handle = button.GetImplementation();
255
256   return static_cast<Toolkit::Internal::CheckBoxButton&>( handle );
257 }
258
259 inline const Toolkit::Internal::CheckBoxButton& GetImplementation( const Toolkit::CheckBoxButton& button )
260 {
261   DALI_ASSERT_ALWAYS( button );
262
263   const Dali::RefObject& handle = button.GetImplementation();
264
265   return static_cast<const Toolkit::Internal::CheckBoxButton&>( handle );
266 }
267
268 } // namespace Toolkit
269
270 } // namespace Dali
271
272 #endif // __DALI_TOOLKIT_INTERNAL_CHECK_BOX_BUTTON_H__