2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
19 #include "check-box-button-impl.h"
27 #include "check-box-button-default-painter-impl.h"
43 return Toolkit::CheckBoxButton::New();
46 TypeRegistration mType( typeid(Toolkit::CheckBoxButton), typeid(Toolkit::Button), Create );
48 TypeAction a1(mType, Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK, &CheckBoxButton::DoAction);
54 // Helper function used to cast a ButtonPainterPtr to CheckBoxButtonDefaultPainterPtr
55 CheckBoxButtonDefaultPainterPtr GetCheckBoxButtonPainter( ButtonPainterPtr painter )
57 return static_cast<CheckBoxButtonDefaultPainter*>( painter.Get() );
61 Dali::Toolkit::CheckBoxButton CheckBoxButton::New()
63 // Create the implementation, temporarily owned on stack
64 IntrusivePtr< CheckBoxButton > internalCheckBoxButton = new CheckBoxButton();
66 // Pass ownership to CustomActor
67 Dali::Toolkit::CheckBoxButton checkBoxButton( *internalCheckBoxButton );
69 // Second-phase init of the implementation
70 // This can only be done after the CustomActor connection has been made...
71 internalCheckBoxButton->Initialize();
73 return checkBoxButton;
76 void CheckBoxButton::SetChecked( bool checked )
78 if( !mDimmed && ( checked != mChecked ) )
83 Toolkit::CheckBoxButton handle( GetOwner() );
85 // Notifies the painter the checkbox has been checked.
86 GetCheckBoxButtonPainter( mPainter )->Checked( handle );
89 mClickedSignalV2.Emit( handle );
93 bool CheckBoxButton::IsChecked() const
98 void CheckBoxButton::SetBackgroundImage( Image image )
100 SetBackgroundImage( ImageActor::New( image ) );
103 void CheckBoxButton::SetBackgroundImage( Actor image )
105 Toolkit::CheckBoxButton handle( GetOwner() );
106 GetCheckBoxButtonPainter( mPainter )->SetBackgroundImage( handle, image );
109 Actor& CheckBoxButton::GetBackgroundImage()
111 return mBackgroundImage;
114 Actor CheckBoxButton::GetBackgroundImage() const
116 return mBackgroundImage;
119 void CheckBoxButton::SetCheckedImage( Image image )
121 SetCheckedImage( ImageActor::New( image ) );
124 void CheckBoxButton::SetCheckedImage( Actor image )
126 Toolkit::CheckBoxButton handle( GetOwner() );
127 GetCheckBoxButtonPainter( mPainter )->SetCheckedImage( handle, image );
130 Actor& CheckBoxButton::GetCheckedImage()
132 return mCheckedImage;
135 Actor CheckBoxButton::GetCheckedImage() const
137 return mCheckedImage;
140 void CheckBoxButton::SetDimmedBackgroundImage( Image image )
142 SetDimmedBackgroundImage( ImageActor::New( image ) );
145 void CheckBoxButton::SetDimmedBackgroundImage( Actor image )
147 Toolkit::CheckBoxButton handle( GetOwner() );
148 GetCheckBoxButtonPainter( mPainter )->SetDimmedBackgroundImage( handle, image );
151 Actor& CheckBoxButton::GetDimmedBackgroundImage()
153 return mDimmedBackgroundImage;
156 Actor CheckBoxButton::GetDimmedBackgroundImage() const
158 return mDimmedBackgroundImage;
161 void CheckBoxButton::SetDimmedCheckedImage( Image image )
163 SetDimmedCheckedImage( ImageActor::New( image ) );
166 void CheckBoxButton::SetDimmedCheckedImage( Actor image )
168 Toolkit::CheckBoxButton handle( GetOwner() );
169 GetCheckBoxButtonPainter( mPainter )->SetDimmedCheckedImage( handle, image );
172 Actor& CheckBoxButton::GetDimmedCheckedImage()
174 return mDimmedCheckedImage;
177 Actor CheckBoxButton::GetDimmedCheckedImage() const
179 return mDimmedCheckedImage;
182 Actor& CheckBoxButton::GetFadeOutBackgroundImage()
184 return mFadeOutBackgroundImage;
187 Actor& CheckBoxButton::GetFadeOutCheckedImage()
189 return mFadeOutCheckedImage;
192 void CheckBoxButton::OnButtonInitialize()
194 mUseFadeAnimationProperty = Self().RegisterProperty( Toolkit::CheckBoxButton::USE_FADE_ANIMATION_PROPERTY_NAME, false );
195 mUseCheckAnimationProperty = Self().RegisterProperty( Toolkit::CheckBoxButton::USE_CHECK_ANIMATION_PROPERTY_NAME, true );
198 void CheckBoxButton::OnButtonUp()
200 if( ButtonDown == mState )
202 // Stores the state, notifies the painter and emits a signal.
203 SetChecked( !mChecked );
207 void CheckBoxButton::OnAnimationTimeSet( float animationTime )
209 GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime );
212 float CheckBoxButton::OnAnimationTimeRequested() const
214 return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime();
217 void CheckBoxButton::OnActivated()
219 // When the button is activated, it performs the click action
220 std::vector<Property::Value> attributes;
221 DoClickAction(attributes);
224 void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes)
226 // Prevents the button signals from doing a recursive loop by sending an action
227 // and re-emitting the signals.
228 if(!mClickActionPerforming)
230 mClickActionPerforming = true;
231 SetChecked( !mChecked );
232 mClickActionPerforming = false;
236 bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
240 Dali::BaseHandle handle(object);
242 Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle);
244 if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName)
246 GetImplementation(button).DoClickAction(attributes);
253 CheckBoxButton::CheckBoxButton()
256 mClickActionPerforming(false)
258 // Creates specific painter.
259 mPainter = new CheckBoxButtonDefaultPainter();
262 CheckBoxButton::~CheckBoxButton()
267 } // namespace Internal
269 } // namespace Toolkit