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 "button-impl.h"
22 #include <cstring> // for strcmp
23 #include <dali/public-api/events/touch-event.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/devel-api/object/type-registry-helper.h>
26 #include <dali/public-api/actors/image-actor.h>
27 #include <dali/devel-api/scripting/scripting.h>
30 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
33 * Button states and contents
34 * (3) mSelectedContent
35 * (2) mButtonContent (2) mSelectedBackgroundContent
36 * (1) mBackgroundContent (1) mBackgroundContent
37 * < unselected > ----------------------- < selected >
39 * | OnDisabled() | OnDisabled()
41 * < disabled > < disabled-selected >
42 * (2) mDisabledContent (2) mDisabledSelectedContent
43 * (1) mDisabledBackgroundContent (1) mDisabledBackgroundContent
45 * The drawing order of child actors is as follows.
48 * | mButtonContent / mSelectedContent / mDisabledContent / mDisabledSelectedContent
49 * | mSelectedBackgroundContent
50 * Bottom mBackgroundContent / mDisabledBackgroundContent
52 * Some of contents may be missed.
53 * And 2 images - fade-in image and fade-out image - in the same layer can be shown during the transition animation. Fade-in image should be above fade-out image.
70 // empty handle as we cannot create button (but type registered for clicked signal)
74 // Setup properties, signals and actions using the type-registry.
75 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create );
77 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
78 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "auto-repeating", BOOLEAN, AUTO_REPEATING )
79 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initial-auto-repeating-delay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
80 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "next-auto-repeating-delay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
81 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE )
82 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED )
83 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "normal-state-actor", MAP, NORMAL_STATE_ACTOR )
84 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected-state-actor", MAP, SELECTED_STATE_ACTOR )
85 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled-state-actor", MAP, DISABLED_STATE_ACTOR )
86 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label-actor", MAP, LABEL_ACTOR )
88 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
89 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
90 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED )
91 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "state-changed", SIGNAL_STATE_CHANGED )
93 DALI_ACTION_REGISTRATION( Toolkit, Button, "button-click", ACTION_BUTTON_CLICK )
95 DALI_TYPE_REGISTRATION_END()
97 const unsigned int INITIAL_AUTOREPEATING_DELAY( 0.15f );
98 const unsigned int NEXT_AUTOREPEATING_DELAY( 0.05f );
100 } // unnamed namespace
103 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
104 mAutoRepeatingTimer(),
106 mAutoRepeating( false ),
107 mTogglableButton( false ),
109 mInitialAutoRepeatingDelay( INITIAL_AUTOREPEATING_DELAY ),
110 mNextAutoRepeatingDelay( NEXT_AUTOREPEATING_DELAY ),
111 mAnimationTime( 0.0f ),
112 mClickActionPerforming( false ),
114 mPaintState( UnselectedState )
120 if( mAutoRepeatingTimer )
122 mAutoRepeatingTimer.Reset();
126 void Button::SetDisabled( bool disabled )
128 if( disabled != mDisabled )
130 unsigned int backgroundIndex;
131 unsigned int buttonIndex;
133 bool animationStarted = false;
135 mDisabled = disabled;
137 switch( mPaintState )
139 case UnselectedState:
141 buttonIndex = FindChildIndex( mLabel );
142 InsertChild( buttonIndex, mDisabledContent );
144 if( mBackgroundContent )
153 InsertChild( backgroundIndex, mDisabledBackgroundContent );
155 animationStarted = OnDisabled();
157 if( animationStarted )
159 mPaintState = UnselectedDisabledTransition;
163 mPaintState = DisabledUnselectedState;
169 buttonIndex = FindChildIndex( mLabel );
170 InsertChild( buttonIndex, mDisabledSelectedContent );
172 if( mBackgroundContent )
181 InsertChild( backgroundIndex, mDisabledBackgroundContent );
183 animationStarted = OnDisabled();
185 if( animationStarted )
187 mPaintState = SelectedDisabledTransition;
191 mPaintState = DisabledSelectedState;
195 case DisabledUnselectedState:
197 buttonIndex = FindChildIndex( mLabel );
198 InsertChild( buttonIndex, mButtonContent );
200 if( mDisabledBackgroundContent )
209 InsertChild( backgroundIndex, mBackgroundContent );
211 animationStarted = OnDisabled();
213 if( animationStarted )
215 mPaintState = DisabledUnselectedTransition;
219 mPaintState = UnselectedState;
223 case DisabledSelectedState:
225 buttonIndex = FindChildIndex( mLabel );
226 InsertChild( buttonIndex, mSelectedContent );
228 if( mDisabledBackgroundContent )
237 InsertChild( backgroundIndex, mSelectedBackgroundContent );
238 InsertChild( backgroundIndex, mBackgroundContent );
240 animationStarted = OnDisabled();
242 if( animationStarted )
244 mPaintState = DisabledSelectedTransition;
248 mPaintState = SelectedState;
252 case UnselectedSelectedTransition:
254 buttonIndex = FindChildIndex( mLabel );
255 InsertChild( buttonIndex, mDisabledSelectedContent );
257 if( mBackgroundContent )
266 InsertChild( backgroundIndex, mDisabledBackgroundContent );
268 animationStarted = OnDisabled();
270 if( animationStarted )
272 mPaintState = SelectedDisabledTransition;
276 mPaintState = DisabledSelectedState;
280 case SelectedUnselectedTransition:
282 buttonIndex = FindChildIndex( mLabel );
283 InsertChild( buttonIndex, mDisabledContent );
285 if( mBackgroundContent )
294 InsertChild( backgroundIndex, mDisabledBackgroundContent );
296 animationStarted = OnDisabled();
298 if( animationStarted )
300 mPaintState = UnselectedDisabledTransition;
304 mPaintState = DisabledUnselectedState;
308 case UnselectedDisabledTransition:
310 animationStarted = OnDisabled();
312 if( animationStarted )
314 mPaintState = DisabledUnselectedTransition;
318 mPaintState = UnselectedState;
322 case DisabledUnselectedTransition:
324 animationStarted = OnDisabled();
326 if( animationStarted )
328 mPaintState = UnselectedDisabledTransition;
332 mPaintState = DisabledUnselectedState;
336 case SelectedDisabledTransition:
338 animationStarted = OnDisabled();
340 if( animationStarted )
342 mPaintState = DisabledSelectedTransition;
346 mPaintState = SelectedState;
350 case DisabledSelectedTransition:
352 animationStarted = OnDisabled();
354 if( animationStarted )
356 mPaintState = SelectedDisabledTransition;
360 mPaintState = DisabledSelectedState;
368 bool Button::IsDisabled() const
373 void Button::SetAutoRepeating( bool autoRepeating )
375 mAutoRepeating = autoRepeating;
377 // An autorepeating button can't be a togglable button.
380 mTogglableButton = false;
384 // Emit a signal is not wanted, only change the appearance.
385 SetSelected( false, false );
390 bool Button::IsAutoRepeating() const
392 return mAutoRepeating;
395 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
397 DALI_ASSERT_ALWAYS( initialAutoRepeatingDelay > 0.f );
398 mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
401 float Button::GetInitialAutoRepeatingDelay() const
403 return mInitialAutoRepeatingDelay;
406 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
408 DALI_ASSERT_ALWAYS( nextAutoRepeatingDelay > 0.f );
409 mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
412 float Button::GetNextAutoRepeatingDelay() const
414 return mNextAutoRepeatingDelay;
417 void Button::SetTogglableButton( bool togglable )
419 mTogglableButton = togglable;
421 // A togglable button can't be an autorepeating button.
424 mAutoRepeating = false;
428 bool Button::IsTogglableButton() const
430 return mTogglableButton;
433 void Button::SetSelected( bool selected )
435 if( !mDisabled && mTogglableButton && ( selected != mSelected ) )
437 SetSelected( selected, true );
441 void Button::SetSelected( bool selected, bool emitSignal )
443 unsigned int buttonIndex, backgroundIndex;
444 bool animationStarted = false;
446 mSelected = selected;
448 switch( mPaintState )
450 case UnselectedState:
452 buttonIndex = FindChildIndex( mLabel );
453 InsertChild( buttonIndex, mSelectedContent );
455 if( mBackgroundContent )
464 InsertChild( backgroundIndex, mSelectedBackgroundContent );
466 // Notifies the derived class the button has been selected.
467 animationStarted = OnSelected();
469 if( animationStarted )
471 mPaintState = UnselectedSelectedTransition;
475 mPaintState = SelectedState;
481 buttonIndex = FindChildIndex( mLabel );
482 InsertChild( buttonIndex, mButtonContent );
484 // Notifies the derived class the button has been selected.
485 animationStarted = OnSelected();
487 if( animationStarted )
489 mPaintState = SelectedUnselectedTransition;
493 mPaintState = UnselectedState;
497 case UnselectedSelectedTransition:
499 // Notifies the derived class the button has been selected.
500 animationStarted = OnSelected();
502 if( animationStarted )
504 mPaintState = SelectedUnselectedTransition;
508 mPaintState = UnselectedState;
512 case SelectedUnselectedTransition:
514 // Notifies the derived class the button has been selected.
515 animationStarted = OnSelected();
517 if( animationStarted )
519 mPaintState = UnselectedSelectedTransition;
523 mPaintState = SelectedState;
527 case DisabledUnselectedTransition:
529 buttonIndex = FindChildIndex( mLabel );
530 InsertChild( buttonIndex, mSelectedContent );
532 if( mDisabledBackgroundContent )
534 if( mBackgroundContent )
543 else if( mBackgroundContent )
552 InsertChild( backgroundIndex, mSelectedBackgroundContent );
554 // Notifies the derived class the button has been selected.
555 animationStarted = OnSelected();
557 if( animationStarted )
559 mPaintState = UnselectedSelectedTransition;
563 mPaintState = SelectedState;
567 case DisabledSelectedTransition:
569 buttonIndex = FindChildIndex( mLabel );
570 InsertChild( buttonIndex, mButtonContent );
572 // Notifies the derived class the button has been selected.
573 animationStarted = OnSelected();
575 if( animationStarted )
577 mPaintState = SelectedUnselectedTransition;
581 mPaintState = UnselectedState;
593 Toolkit::Button handle( GetOwner() );
596 mStateChangedSignal.Emit( handle );
602 bool Button::IsSelected() const
604 return mTogglableButton && mSelected;
607 void Button::SetAnimationTime( float animationTime )
609 mAnimationTime = animationTime;
612 float Button::GetAnimationTime() const
614 return mAnimationTime;
617 void Button::SetLabel( const std::string& label )
619 Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( label );
620 SetLabel( textLabel );
623 void Button::SetLabel( Actor label )
625 if( mLabel != label )
627 if( mLabel && mLabel.GetParent() )
629 mLabel.GetParent().Remove( mLabel );
633 mLabel.SetPosition( 0.f, 0.f );
635 // label should be the top of the button
636 Self().Add( mLabel );
644 Actor Button::GetLabel() const
649 Actor& Button::GetLabel()
654 void Button::SetButtonImage( Actor image )
658 if( mButtonContent && mButtonContent.GetParent() )
660 Self().Remove( mButtonContent );
663 mButtonContent = image;
665 mButtonContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
666 mButtonContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
667 mButtonContent.SetPosition( 0.f, 0.f );
669 if( mPaintState == UnselectedState )
671 unsigned int index = FindChildIndex( mLabel );
673 Self().Insert( index, mButtonContent );
681 Actor Button::GetButtonImage() const
683 return mButtonContent;
686 Actor& Button::GetButtonImage()
688 return mButtonContent;
691 void Button::SetSelectedImage( Actor image )
695 if( mSelectedContent && mSelectedContent.GetParent() )
697 Self().Remove( mSelectedContent );
700 mSelectedContent = image;
702 mSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
703 mSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
704 mSelectedContent.SetPosition( 0.f, 0.f );
706 if( mPaintState == SelectedState )
708 unsigned int index = FindChildIndex( mLabel );
710 Self().Insert( index, mSelectedContent );
713 OnSelectedImageSet();
718 Actor Button::GetSelectedImage() const
720 return mSelectedContent;
723 Actor& Button::GetSelectedImage()
725 return mSelectedContent;
728 void Button::SetBackgroundImage( Actor image )
732 if( mBackgroundContent && mBackgroundContent.GetParent() )
734 Self().Remove( mBackgroundContent );
737 mBackgroundContent = image;
739 mBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
740 mBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
741 mBackgroundContent.SetPosition( 0.f, 0.f );
743 if( mPaintState == UnselectedState || mPaintState == SelectedState )
745 Self().Insert( 0, mBackgroundContent );
748 OnBackgroundImageSet();
753 Actor Button::GetBackgroundImage() const
755 return mBackgroundContent;
758 Actor& Button::GetBackgroundImage()
760 return mBackgroundContent;
763 void Button::SetSelectedBackgroundImage( Actor image )
767 if( mSelectedBackgroundContent && mSelectedBackgroundContent.GetParent() )
769 Self().Remove( mSelectedBackgroundContent );
772 mSelectedBackgroundContent = image;
774 mSelectedBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
775 mSelectedBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
776 mSelectedBackgroundContent.SetPosition( 0.f, 0.f );
778 if( mPaintState == SelectedState )
780 if( mBackgroundContent )
782 Self().Insert( 1, mSelectedBackgroundContent );
786 Self().Insert( 0, mSelectedBackgroundContent );
790 OnSelectedBackgroundImageSet();
795 Actor Button::GetSelectedBackgroundImage() const
797 return mSelectedBackgroundContent;
800 Actor& Button::GetSelectedBackgroundImage()
802 return mSelectedBackgroundContent;
805 void Button::SetDisabledImage( Actor image )
809 if( mDisabledContent && mDisabledContent.GetParent() )
811 Self().Remove( mDisabledContent );
814 mDisabledContent = image;
816 mDisabledContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
817 mDisabledContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
818 mDisabledContent.SetPosition( 0.f, 0.f );
820 if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
822 unsigned int index = FindChildIndex( mLabel );
824 Self().Insert( index, mDisabledContent );
827 OnDisabledImageSet();
830 Actor Button::GetDisabledImage() const
832 return mDisabledContent;
835 Actor& Button::GetDisabledImage()
837 return mDisabledContent;
840 void Button::SetDisabledSelectedImage( Actor image )
844 if( mDisabledSelectedContent && mDisabledSelectedContent.GetParent() )
846 Self().Remove( mDisabledSelectedContent );
849 mDisabledSelectedContent = image;
851 mDisabledSelectedContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
852 mDisabledSelectedContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
853 mDisabledSelectedContent.SetPosition( 0.f, 0.f );
855 if( mPaintState == DisabledSelectedState )
857 unsigned int index = FindChildIndex( mLabel );
859 Self().Insert( index, mDisabledSelectedContent );
862 OnDisabledSelectedImageSet();
865 Actor Button::GetDisabledSelectedImage() const
867 return mDisabledSelectedContent;
870 Actor& Button::GetDisabledSelectedImage()
872 return mDisabledSelectedContent;
875 void Button::SetDisabledBackgroundImage( Actor image )
879 if( mDisabledBackgroundContent && mDisabledBackgroundContent.GetParent() )
881 Self().Remove( mDisabledBackgroundContent );
884 mDisabledBackgroundContent = image;
886 mDisabledBackgroundContent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
887 mDisabledBackgroundContent.SetParentOrigin( ParentOrigin::TOP_LEFT );
888 mDisabledBackgroundContent.SetPosition( 0.f, 0.f );
890 if( mPaintState == DisabledUnselectedState || mPaintState == DisabledSelectedState )
892 Self().Insert( 0, mDisabledBackgroundContent );
895 OnDisabledBackgroundImageSet();
898 Actor Button::GetDisabledBackgroundImage() const
900 return mDisabledBackgroundContent;
903 Actor& Button::GetDisabledBackgroundImage()
905 return mDisabledBackgroundContent;
908 bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
912 Dali::BaseHandle handle( object );
914 Toolkit::Button button = Toolkit::Button::DownCast( handle );
916 DALI_ASSERT_ALWAYS( button );
918 if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
920 ret = GetImplementation( button ).DoClickAction( attributes );
926 bool Button::DoClickAction( const Property::Map& attributes )
928 // Prevents the button signals from doing a recursive loop by sending an action
929 // and re-emitting the signals.
930 if( !mClickActionPerforming )
932 mClickActionPerforming = true;
936 mClickActionPerforming = false;
944 void Button::UpdatePaintTransitionState()
946 switch( mPaintState )
948 case UnselectedSelectedTransition:
950 RemoveChild( mButtonContent );
951 mPaintState = SelectedState;
954 case SelectedUnselectedTransition:
956 RemoveChild( mSelectedBackgroundContent );
957 RemoveChild( mSelectedContent );
958 mPaintState = UnselectedState;
961 case UnselectedDisabledTransition:
963 RemoveChild( mBackgroundContent );
964 RemoveChild( mButtonContent );
965 mPaintState = DisabledUnselectedState;
968 case DisabledUnselectedTransition:
970 RemoveChild( mDisabledBackgroundContent );
971 RemoveChild( mDisabledContent );
972 mPaintState = UnselectedState;
975 case SelectedDisabledTransition:
977 RemoveChild( mBackgroundContent );
978 RemoveChild( mSelectedBackgroundContent );
979 RemoveChild( mSelectedContent );
980 mPaintState = DisabledSelectedState;
983 case DisabledSelectedTransition:
985 RemoveChild( mDisabledBackgroundContent );
986 RemoveChild( mDisabledSelectedContent );
987 mPaintState = SelectedState;
997 void Button::OnButtonStageDisconnection()
999 if( ButtonDown == mState )
1001 if( !mTogglableButton )
1005 if( mAutoRepeating )
1007 mAutoRepeatingTimer.Reset();
1013 void Button::OnButtonDown()
1015 if( !mTogglableButton )
1017 Toolkit::Button handle( GetOwner() );
1021 if( mAutoRepeating )
1023 SetUpTimer( mInitialAutoRepeatingDelay );
1027 mPressedSignal.Emit( handle );
1031 void Button::OnButtonUp()
1033 if( ButtonDown == mState )
1035 if( mTogglableButton )
1037 SetSelected( !mSelected );
1043 if( mAutoRepeating )
1045 mAutoRepeatingTimer.Reset();
1048 Toolkit::Button handle( GetOwner() );
1051 mReleasedSignal.Emit( handle );
1052 mClickedSignal.Emit( handle );
1057 void Button::OnTouchPointLeave()
1059 if( ButtonDown == mState )
1061 if( !mTogglableButton )
1063 Toolkit::Button handle( GetOwner() );
1067 if( mAutoRepeating )
1069 mAutoRepeatingTimer.Reset();
1073 mReleasedSignal.Emit( handle );
1078 void Button::OnTouchPointInterrupted()
1080 OnTouchPointLeave();
1083 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
1085 return mPressedSignal;
1088 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
1090 return mReleasedSignal;
1093 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
1095 return mClickedSignal;
1098 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
1100 return mStateChangedSignal;
1103 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1105 Dali::BaseHandle handle( object );
1107 bool connected( true );
1108 Toolkit::Button button = Toolkit::Button::DownCast( handle );
1110 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
1112 button.PressedSignal().Connect( tracker, functor );
1114 else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
1116 button.ReleasedSignal().Connect( tracker, functor );
1118 else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
1120 button.ClickedSignal().Connect( tracker, functor );
1122 else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
1124 button.StateChangedSignal().Connect( tracker, functor );
1128 // signalName does not match any signal
1135 bool Button::OnTouchEvent(const TouchEvent& event)
1137 // Only events are processed when the button is not disabled and the touch event has only
1139 if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
1141 switch( event.GetPoint(0).state )
1143 case TouchPoint::Down:
1145 OnButtonDown(); // Notification for derived classes.
1147 // Sets the button state to ButtonDown.
1148 mState = ButtonDown;
1151 case TouchPoint::Up:
1153 OnButtonUp(); // Notification for derived classes.
1155 // Sets the button state to ButtonUp.
1159 case TouchPoint::Interrupted:
1161 OnTouchPointInterrupted(); // Notification for derived classes.
1163 // Sets the button state to the default (ButtonUp).
1167 case TouchPoint::Leave:
1169 OnTouchPointLeave(); // Notification for derived classes.
1171 // Sets the button state to the default (ButtonUp).
1175 case TouchPoint::Motion:
1176 case TouchPoint::Stationary: // FALLTHROUGH
1183 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
1188 else if( 1 < event.GetPointCount() )
1190 OnTouchPointLeave(); // Notification for derived classes.
1192 // Sets the button state to the default (ButtonUp).
1199 void Button::OnInitialize()
1201 Actor self = Self();
1203 mTapDetector = TapGestureDetector::New();
1204 mTapDetector.Attach( self );
1205 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
1207 OnButtonInitialize();
1209 self.SetKeyboardFocusable( true );
1212 bool Button::OnAccessibilityActivated()
1214 return OnKeyboardEnter();
1217 bool Button::OnKeyboardEnter()
1219 // When the enter key is pressed, or button is activated, the click action is performed.
1220 Property::Map attributes;
1221 bool ret = DoClickAction( attributes );
1226 void Button::OnControlStageDisconnection()
1228 OnButtonStageDisconnection(); // Notification for derived classes.
1232 void Button::OnTap(Actor actor, const TapGesture& tap)
1237 void Button::SetUpTimer( float delay )
1239 mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
1240 mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
1241 mAutoRepeatingTimer.Start();
1244 bool Button::AutoRepeatingSlot()
1246 bool consumed = false;
1249 // Restart the autorepeat timer.
1250 SetUpTimer( mNextAutoRepeatingDelay );
1254 Toolkit::Button handle( GetOwner() );
1257 consumed = mReleasedSignal.Emit( handle );
1258 consumed |= mClickedSignal.Emit( handle );
1259 consumed |= mPressedSignal.Emit( handle );
1265 void Button::Pressed()
1267 unsigned int buttonIndex, backgroundIndex;
1268 bool animationStarted = false;
1270 switch( mPaintState )
1272 case UnselectedState:
1274 buttonIndex = FindChildIndex( mLabel );
1275 InsertChild( buttonIndex, mSelectedContent );
1277 if( mBackgroundContent )
1279 backgroundIndex = 1;
1283 backgroundIndex = 0;
1286 InsertChild( backgroundIndex, mSelectedBackgroundContent );
1288 // Notifies the derived class the button has been pressed.
1289 animationStarted = OnPressed();
1291 if( animationStarted )
1293 mPaintState = UnselectedSelectedTransition;
1297 mPaintState = SelectedState;
1301 case SelectedUnselectedTransition:
1303 // Notifies the derived class the button has been pressed.
1304 animationStarted = OnPressed();
1306 if( animationStarted )
1308 mPaintState = UnselectedSelectedTransition;
1312 mPaintState = SelectedState;
1316 case DisabledUnselectedTransition:
1318 buttonIndex = FindChildIndex( mLabel );
1319 InsertChild( buttonIndex, mSelectedContent );
1321 if( mDisabledBackgroundContent )
1323 if( mBackgroundContent )
1325 backgroundIndex = 2;
1329 backgroundIndex = 1;
1332 else if( mBackgroundContent )
1334 backgroundIndex = 1;
1338 backgroundIndex = 0;
1341 InsertChild( backgroundIndex, mSelectedBackgroundContent );
1343 // Notifies the derived class the button has been pressed.
1344 animationStarted = OnPressed();
1346 if( animationStarted )
1348 mPaintState = UnselectedSelectedTransition;
1352 mPaintState = SelectedState;
1361 void Button::Released()
1363 unsigned int buttonIndex;
1364 bool animationStarted = false;
1366 switch( mPaintState )
1370 buttonIndex = FindChildIndex( mLabel );
1371 InsertChild( buttonIndex, mButtonContent );
1373 // Notifies the derived class the button has been released.
1374 animationStarted = OnReleased();
1376 if( animationStarted )
1378 mPaintState = SelectedUnselectedTransition;
1382 mPaintState = UnselectedState;
1386 case UnselectedSelectedTransition:
1388 // Notifies the derived class the button has been released.
1389 animationStarted = OnReleased();
1391 if( animationStarted )
1393 mPaintState = SelectedUnselectedTransition;
1397 mPaintState = UnselectedState;
1401 case DisabledSelectedTransition:
1403 buttonIndex = FindChildIndex( mLabel );
1404 InsertChild( buttonIndex, mButtonContent );
1406 // Notifies the derived class the button has been released.
1407 animationStarted = OnReleased();
1409 if( animationStarted )
1411 mPaintState = SelectedUnselectedTransition;
1415 mPaintState = UnselectedState;
1426 Button::ButtonState Button::GetState()
1431 Button::PaintState Button::GetPaintState()
1436 void Button::InsertChild( unsigned int index, Actor& actor )
1440 Self().Insert( index, actor);
1444 void Button::RemoveChild( Actor& actor )
1446 if( actor && actor.GetParent() )
1448 Self().Remove( actor );
1452 unsigned int Button::FindChildIndex( Actor& actor )
1454 Actor self = Self();
1455 unsigned int childrenNum = self.GetChildCount();
1457 for( unsigned int i = 0; i < childrenNum; i++ )
1459 Actor child = self.GetChildAt( i );
1460 if( child == actor )
1469 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1471 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1477 case Toolkit::Button::Property::DISABLED:
1479 GetImplementation( button ).SetDisabled( value.Get<bool>() );
1483 case Toolkit::Button::Property::AUTO_REPEATING:
1485 GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1489 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1491 GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1495 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1497 GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1501 case Toolkit::Button::Property::TOGGLABLE:
1503 GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1507 case Toolkit::Button::Property::SELECTED:
1509 GetImplementation( button ).SetSelected( value.Get< bool >() );
1513 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1515 GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1519 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1521 GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1525 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1527 GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1531 case Toolkit::Button::Property::LABEL_ACTOR:
1533 GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
1540 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1542 Property::Value value;
1544 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1548 switch ( propertyIndex )
1550 case Toolkit::Button::Property::DISABLED:
1552 value = GetImplementation( button ).mDisabled;
1556 case Toolkit::Button::Property::AUTO_REPEATING:
1558 value = GetImplementation( button ).mAutoRepeating;
1562 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1564 value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1568 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1570 value = GetImplementation( button ).mNextAutoRepeatingDelay;
1574 case Toolkit::Button::Property::TOGGLABLE:
1576 value = GetImplementation( button ).mTogglableButton;
1580 case Toolkit::Button::Property::SELECTED:
1582 value = GetImplementation( button ).mSelected;
1586 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1589 Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map );
1594 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1597 Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
1602 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1605 Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
1610 case Toolkit::Button::Property::LABEL_ACTOR:
1613 Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
1623 } // namespace Internal
1625 } // namespace Toolkit