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