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 PropertyValueContainer& 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 GetImplementation( button ).DoClickAction( attributes );
927 void Button::DoClickAction( const PropertyValueContainer& attributes )
929 // Prevents the button signals from doing a recursive loop by sending an action
930 // and re-emitting the signals.
931 if( !mClickActionPerforming )
933 mClickActionPerforming = true;
937 mClickActionPerforming = false;
941 void Button::UpdatePaintTransitionState()
943 switch( mPaintState )
945 case UnselectedSelectedTransition:
947 RemoveChild( mButtonContent );
948 mPaintState = SelectedState;
951 case SelectedUnselectedTransition:
953 RemoveChild( mSelectedBackgroundContent );
954 RemoveChild( mSelectedContent );
955 mPaintState = UnselectedState;
958 case UnselectedDisabledTransition:
960 RemoveChild( mBackgroundContent );
961 RemoveChild( mButtonContent );
962 mPaintState = DisabledUnselectedState;
965 case DisabledUnselectedTransition:
967 RemoveChild( mDisabledBackgroundContent );
968 RemoveChild( mDisabledContent );
969 mPaintState = UnselectedState;
972 case SelectedDisabledTransition:
974 RemoveChild( mBackgroundContent );
975 RemoveChild( mSelectedBackgroundContent );
976 RemoveChild( mSelectedContent );
977 mPaintState = DisabledSelectedState;
980 case DisabledSelectedTransition:
982 RemoveChild( mDisabledBackgroundContent );
983 RemoveChild( mDisabledSelectedContent );
984 mPaintState = SelectedState;
994 void Button::OnButtonStageDisconnection()
996 if( ButtonDown == mState )
998 if( !mTogglableButton )
1002 if( mAutoRepeating )
1004 mAutoRepeatingTimer.Reset();
1010 void Button::OnButtonDown()
1012 if( !mTogglableButton )
1014 Toolkit::Button handle( GetOwner() );
1018 if( mAutoRepeating )
1020 SetUpTimer( mInitialAutoRepeatingDelay );
1024 mPressedSignal.Emit( handle );
1028 void Button::OnButtonUp()
1030 if( ButtonDown == mState )
1032 if( mTogglableButton )
1034 SetSelected( !mSelected );
1040 if( mAutoRepeating )
1042 mAutoRepeatingTimer.Reset();
1045 Toolkit::Button handle( GetOwner() );
1048 mReleasedSignal.Emit( handle );
1049 mClickedSignal.Emit( handle );
1054 void Button::OnTouchPointLeave()
1056 if( ButtonDown == mState )
1058 if( !mTogglableButton )
1060 Toolkit::Button handle( GetOwner() );
1064 if( mAutoRepeating )
1066 mAutoRepeatingTimer.Reset();
1070 mReleasedSignal.Emit( handle );
1075 void Button::OnTouchPointInterrupted()
1077 OnTouchPointLeave();
1080 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
1082 return mPressedSignal;
1085 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
1087 return mReleasedSignal;
1090 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
1092 return mClickedSignal;
1095 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
1097 return mStateChangedSignal;
1100 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1102 Dali::BaseHandle handle( object );
1104 bool connected( true );
1105 Toolkit::Button button = Toolkit::Button::DownCast( handle );
1107 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
1109 button.PressedSignal().Connect( tracker, functor );
1111 else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
1113 button.ReleasedSignal().Connect( tracker, functor );
1115 else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
1117 button.ClickedSignal().Connect( tracker, functor );
1119 else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
1121 button.StateChangedSignal().Connect( tracker, functor );
1125 // signalName does not match any signal
1132 bool Button::OnTouchEvent(const TouchEvent& event)
1134 // Only events are processed when the button is not disabled and the touch event has only
1136 if( ( !mDisabled ) && ( 1 == event.GetPointCount() ) )
1138 switch( event.GetPoint(0).state )
1140 case TouchPoint::Down:
1142 OnButtonDown(); // Notification for derived classes.
1144 // Sets the button state to ButtonDown.
1145 mState = ButtonDown;
1148 case TouchPoint::Up:
1150 OnButtonUp(); // Notification for derived classes.
1152 // Sets the button state to ButtonUp.
1156 case TouchPoint::Interrupted:
1158 OnTouchPointInterrupted(); // Notification for derived classes.
1160 // Sets the button state to the default (ButtonUp).
1164 case TouchPoint::Leave:
1166 OnTouchPointLeave(); // Notification for derived classes.
1168 // Sets the button state to the default (ButtonUp).
1172 case TouchPoint::Motion:
1173 case TouchPoint::Stationary: // FALLTHROUGH
1180 DALI_ASSERT_ALWAYS( !"Point status unhandled." );
1185 else if( 1 < event.GetPointCount() )
1187 OnTouchPointLeave(); // Notification for derived classes.
1189 // Sets the button state to the default (ButtonUp).
1196 void Button::OnInitialize()
1198 Actor self = Self();
1200 mTapDetector = TapGestureDetector::New();
1201 mTapDetector.Attach( self );
1202 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
1204 OnButtonInitialize();
1206 self.SetDrawMode( DrawMode::OVERLAY );
1207 self.SetKeyboardFocusable( true );
1210 void Button::OnActivated()
1212 // When the button is activated, it performs the click action
1213 PropertyValueContainer attributes;
1214 DoClickAction( attributes );
1217 void Button::OnControlStageDisconnection()
1219 OnButtonStageDisconnection(); // Notification for derived classes.
1223 void Button::OnTap(Actor actor, const TapGesture& tap)
1228 void Button::SetUpTimer( float delay )
1230 mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
1231 mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
1232 mAutoRepeatingTimer.Start();
1235 bool Button::AutoRepeatingSlot()
1237 bool consumed = false;
1240 // Restart the autorepeat timer.
1241 SetUpTimer( mNextAutoRepeatingDelay );
1245 Toolkit::Button handle( GetOwner() );
1248 consumed = mReleasedSignal.Emit( handle );
1249 consumed |= mClickedSignal.Emit( handle );
1250 consumed |= mPressedSignal.Emit( handle );
1256 void Button::Pressed()
1258 unsigned int buttonIndex, backgroundIndex;
1259 bool animationStarted = false;
1261 switch( mPaintState )
1263 case UnselectedState:
1265 buttonIndex = FindChildIndex( mLabel );
1266 InsertChild( buttonIndex, mSelectedContent );
1268 if( mBackgroundContent )
1270 backgroundIndex = 1;
1274 backgroundIndex = 0;
1277 InsertChild( backgroundIndex, mSelectedBackgroundContent );
1279 // Notifies the derived class the button has been pressed.
1280 animationStarted = OnPressed();
1282 if( animationStarted )
1284 mPaintState = UnselectedSelectedTransition;
1288 mPaintState = SelectedState;
1292 case SelectedUnselectedTransition:
1294 // Notifies the derived class the button has been pressed.
1295 animationStarted = OnPressed();
1297 if( animationStarted )
1299 mPaintState = UnselectedSelectedTransition;
1303 mPaintState = SelectedState;
1307 case DisabledUnselectedTransition:
1309 buttonIndex = FindChildIndex( mLabel );
1310 InsertChild( buttonIndex, mSelectedContent );
1312 if( mDisabledBackgroundContent )
1314 if( mBackgroundContent )
1316 backgroundIndex = 2;
1320 backgroundIndex = 1;
1323 else if( mBackgroundContent )
1325 backgroundIndex = 1;
1329 backgroundIndex = 0;
1332 InsertChild( backgroundIndex, mSelectedBackgroundContent );
1334 // Notifies the derived class the button has been pressed.
1335 animationStarted = OnPressed();
1337 if( animationStarted )
1339 mPaintState = UnselectedSelectedTransition;
1343 mPaintState = SelectedState;
1352 void Button::Released()
1354 unsigned int buttonIndex;
1355 bool animationStarted = false;
1357 switch( mPaintState )
1361 buttonIndex = FindChildIndex( mLabel );
1362 InsertChild( buttonIndex, mButtonContent );
1364 // Notifies the derived class the button has been released.
1365 animationStarted = OnReleased();
1367 if( animationStarted )
1369 mPaintState = SelectedUnselectedTransition;
1373 mPaintState = UnselectedState;
1377 case UnselectedSelectedTransition:
1379 // Notifies the derived class the button has been released.
1380 animationStarted = OnReleased();
1382 if( animationStarted )
1384 mPaintState = SelectedUnselectedTransition;
1388 mPaintState = UnselectedState;
1392 case DisabledSelectedTransition:
1394 buttonIndex = FindChildIndex( mLabel );
1395 InsertChild( buttonIndex, mButtonContent );
1397 // Notifies the derived class the button has been released.
1398 animationStarted = OnReleased();
1400 if( animationStarted )
1402 mPaintState = SelectedUnselectedTransition;
1406 mPaintState = UnselectedState;
1417 Button::ButtonState Button::GetState()
1422 Button::PaintState Button::GetPaintState()
1427 void Button::InsertChild( unsigned int index, Actor& actor )
1431 Self().Insert( index, actor);
1435 void Button::RemoveChild( Actor& actor )
1437 if( actor && actor.GetParent() )
1439 Self().Remove( actor );
1443 unsigned int Button::FindChildIndex( Actor& actor )
1445 Actor self = Self();
1446 unsigned int childrenNum = self.GetChildCount();
1448 for( unsigned int i = 0; i < childrenNum; i++ )
1450 Actor child = self.GetChildAt( i );
1451 if( child == actor )
1460 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1462 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1468 case Toolkit::Button::Property::DISABLED:
1470 GetImplementation( button ).SetDisabled( value.Get<bool>() );
1474 case Toolkit::Button::Property::AUTO_REPEATING:
1476 GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1480 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1482 GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1486 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1488 GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1492 case Toolkit::Button::Property::TOGGLABLE:
1494 GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1498 case Toolkit::Button::Property::SELECTED:
1500 GetImplementation( button ).SetSelected( value.Get< bool >() );
1504 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1506 GetImplementation( button ).SetButtonImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1510 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1512 GetImplementation( button ).SetSelectedImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1516 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1518 GetImplementation( button ).SetDisabledImage( Scripting::NewActor( value.Get< Property::Map >() ) );
1522 case Toolkit::Button::Property::LABEL_ACTOR:
1524 GetImplementation( button ).SetLabel( Scripting::NewActor( value.Get< Property::Map >() ) );
1531 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1533 Property::Value value;
1535 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1539 switch ( propertyIndex )
1541 case Toolkit::Button::Property::DISABLED:
1543 value = GetImplementation( button ).mDisabled;
1547 case Toolkit::Button::Property::AUTO_REPEATING:
1549 value = GetImplementation( button ).mAutoRepeating;
1553 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1555 value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1559 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1561 value = GetImplementation( button ).mNextAutoRepeatingDelay;
1565 case Toolkit::Button::Property::TOGGLABLE:
1567 value = GetImplementation( button ).mTogglableButton;
1571 case Toolkit::Button::Property::SELECTED:
1573 value = GetImplementation( button ).mSelected;
1577 case Toolkit::Button::Property::NORMAL_STATE_ACTOR:
1580 Scripting::CreatePropertyMap( GetImplementation( button ).mButtonContent, map );
1585 case Toolkit::Button::Property::SELECTED_STATE_ACTOR:
1588 Scripting::CreatePropertyMap( GetImplementation( button ).mSelectedContent, map );
1593 case Toolkit::Button::Property::DISABLED_STATE_ACTOR:
1596 Scripting::CreatePropertyMap( GetImplementation( button ).mDisabledContent, map );
1601 case Toolkit::Button::Property::LABEL_ACTOR:
1604 Scripting::CreatePropertyMap( GetImplementation( button ).mLabel, map );
1614 } // namespace Internal
1616 } // namespace Toolkit