2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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"
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/object/type-registry.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( !mDisabled && ( checked != mChecked ) )
83 Toolkit::CheckBoxButton handle( GetOwner() );
85 // Notifies the painter the checkbox has been checked.
86 GetCheckBoxButtonPainter( mPainter )->Checked( handle );
88 // Raise state changed signal
89 mStateChangedSignal.Emit( handle, mChecked );
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::SetDisabledBackgroundImage( Image image )
142 SetDisabledBackgroundImage( ImageActor::New( image ) );
145 void CheckBoxButton::SetDisabledBackgroundImage( Actor image )
147 Toolkit::CheckBoxButton handle( GetOwner() );
148 GetCheckBoxButtonPainter( mPainter )->SetDisabledBackgroundImage( handle, image );
151 Actor& CheckBoxButton::GetDisabledBackgroundImage()
153 return mDisabledBackgroundImage;
156 Actor CheckBoxButton::GetDisabledBackgroundImage() const
158 return mDisabledBackgroundImage;
161 void CheckBoxButton::SetDisabledCheckedImage( Image image )
163 SetDisabledCheckedImage( ImageActor::New( image ) );
166 void CheckBoxButton::SetDisabledCheckedImage( Actor image )
168 Toolkit::CheckBoxButton handle( GetOwner() );
169 GetCheckBoxButtonPainter( mPainter )->SetDisabledCheckedImage( handle, image );
172 Actor& CheckBoxButton::GetDisabledCheckedImage()
174 return mDisabledCheckedImage;
177 Actor CheckBoxButton::GetDisabledCheckedImage() const
179 return mDisabledCheckedImage;
182 Actor& CheckBoxButton::GetFadeOutBackgroundImage()
184 return mFadeOutBackgroundImage;
187 Actor& CheckBoxButton::GetFadeOutCheckedImage()
189 return mFadeOutCheckedImage;
192 void CheckBoxButton::OnButtonInitialize()
196 void CheckBoxButton::OnButtonUp()
198 if( ButtonDown == mState )
200 // Stores the state, notifies the painter and emits a signal.
201 SetChecked( !mChecked );
205 void CheckBoxButton::OnAnimationTimeSet( float animationTime )
207 GetCheckBoxButtonPainter( mPainter )->SetAnimationTime( animationTime );
210 float CheckBoxButton::OnAnimationTimeRequested() const
212 return GetCheckBoxButtonPainter( mPainter )->GetAnimationTime();
215 void CheckBoxButton::OnActivated()
217 // When the button is activated, it performs the click action
218 PropertyValueContainer attributes;
219 DoClickAction(attributes);
222 void CheckBoxButton::DoClickAction(const PropertyValueContainer& attributes)
224 // Prevents the button signals from doing a recursive loop by sending an action
225 // and re-emitting the signals.
226 if(!mClickActionPerforming)
228 mClickActionPerforming = true;
229 SetChecked( !mChecked );
230 mClickActionPerforming = false;
234 bool CheckBoxButton::DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes)
238 Dali::BaseHandle handle(object);
240 Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::DownCast(handle);
242 if(Toolkit::CheckBoxButton::ACTION_CHECK_BOX_BUTTON_CLICK == actionName)
244 GetImplementation(button).DoClickAction(attributes);
251 CheckBoxButton::CheckBoxButton()
254 mClickActionPerforming(false)
256 // Creates specific painter.
257 mPainter = new CheckBoxButtonDefaultPainter();
260 CheckBoxButton::~CheckBoxButton()
265 } // namespace Internal
267 } // namespace Toolkit