2 * Copyright (c) 2016 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/devel-api/scripting/enum-helper.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/events/touch-data.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/public-api/size-negotiation/relayout-container.h>
30 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
34 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
37 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
38 #include <dali-toolkit/devel-api/align-enums.h>
39 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
40 #include <dali-toolkit/devel-api/visual-factory/devel-visual-properties.h>
41 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogButtonFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_BUTTON_CONTROL");
62 // empty handle as we cannot create button (but type registered for clicked signal)
66 // Setup properties, signals and actions using the type-registry.
67 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Button, Toolkit::Control, Create )
69 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabled", BOOLEAN, DISABLED )
70 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "autoRepeating", BOOLEAN, AUTO_REPEATING )
71 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "initialAutoRepeatingDelay", FLOAT, INITIAL_AUTO_REPEATING_DELAY )
72 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "nextAutoRepeatingDelay", FLOAT, NEXT_AUTO_REPEATING_DELAY )
73 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "togglable", BOOLEAN, TOGGLABLE )
74 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selected", BOOLEAN, SELECTED )
75 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedStateImage", MAP, UNSELECTED_STATE_IMAGE ) // Deprecated property
76 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedStateImage", MAP, SELECTED_STATE_IMAGE ) // Deprecated property
77 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledStateImage", MAP, DISABLED_STATE_IMAGE ) // Deprecated property
78 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedColor", VECTOR4, UNSELECTED_COLOR ) // Deprecated property
79 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedColor", VECTOR4, SELECTED_COLOR ) // Deprecated property
80 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "label", MAP, LABEL )
81 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelText", STRING, LABEL_TEXT ) // Deprecated property
82 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedVisual", MAP, UNSELECTED_VISUAL )
83 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedVisual", MAP, SELECTED_VISUAL )
84 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedVisual", MAP, DISABLED_SELECTED_VISUAL )
85 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedVisual", MAP, DISABLED_UNSELECTED_VISUAL )
86 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "unselectedBackgroundVisual", MAP, UNSELECTED_BACKGROUND_VISUAL )
87 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "selectedBackgroundVisual", MAP, SELECTED_BACKGROUND_VISUAL )
88 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledUnselectedBackgroundVisual", MAP, DISABLED_UNSELECTED_BACKGROUND_VISUAL )
89 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "disabledSelectedBackgroundVisual", MAP, DISABLED_SELECTED_BACKGROUND_VISUAL )
90 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelStrutLength", INTEGER, LABEL_STRUT_LENGTH )
91 DALI_PROPERTY_REGISTRATION( Toolkit, Button, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT )
94 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
95 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
96 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED )
97 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED )
100 DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK )
102 DALI_TYPE_REGISTRATION_END()
104 DALI_ENUM_TO_STRING_TABLE_BEGIN( ALIGNMENT )
105 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BEGIN )
106 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, END )
107 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, TOP )
108 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BOTTOM )
109 DALI_ENUM_TO_STRING_TABLE_END( ALIGNMENT )
111 const Scripting::StringEnum ALIGNMENT_STRING_TABLE[] =
113 { "BEGIN", Button::BEGIN },
114 { "END", Button::END },
115 { "TOP", Button::TOP },
116 { "BOTTOM", Button::BOTTOM },
119 const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
121 const Property::Index GET_VISUAL_INDEX_FOR_STATE[][Button::STATE_COUNT] =
123 { Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::UNSELECTED_VISUAL },
124 { Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::SELECTED_VISUAL },
125 { Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL },
126 { Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_SELECTED_VISUAL }
129 } // unnamed namespace
132 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
133 mAutoRepeatingTimer(),
134 mForeGroundToLabelStrutLength( 0.0f ),
135 mTextLabelAlignment( END ),
136 mAutoRepeating( false ),
137 mTogglableButton( false ),
138 mInitialAutoRepeatingDelay( 0.0f ),
139 mNextAutoRepeatingDelay( 0.0f ),
140 mAnimationTime( 0.0f ),
141 mButtonPressedState( UNPRESSED ),
142 mButtonState( UNSELECTED_STATE ),
143 mPreviousButtonState( mButtonState ),
144 mClickActionPerforming( false )
152 void Button::SetAutoRepeating( bool autoRepeating )
154 mAutoRepeating = autoRepeating;
156 // An autorepeating button can't be a togglable button.
159 mTogglableButton = false;
163 SetSelected( false );
168 bool Button::IsAutoRepeating() const
170 return mAutoRepeating;
173 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
175 DALI_ASSERT_DEBUG( initialAutoRepeatingDelay > 0.f );
176 mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
179 float Button::GetInitialAutoRepeatingDelay() const
181 return mInitialAutoRepeatingDelay;
184 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
186 DALI_ASSERT_DEBUG( nextAutoRepeatingDelay > 0.f );
187 mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
190 float Button::GetNextAutoRepeatingDelay() const
192 return mNextAutoRepeatingDelay;
195 void Button::SetTogglableButton( bool togglable )
197 mTogglableButton = togglable;
199 // A toggle button can't be an autorepeating button.
202 mAutoRepeating = false;
206 bool Button::IsTogglableButton() const
208 return mTogglableButton;
211 void Button::SetSelected( bool selected )
213 if( mTogglableButton )
215 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetSelected (%s)\n", (selected?"true":"false") );
217 if ( selected && ( mButtonState != SELECTED_STATE ) )
219 ChangeState( SELECTED_STATE );
221 else if ( !selected && ( mButtonState != UNSELECTED_STATE ) )
223 ChangeState( UNSELECTED_STATE );
228 void Button::SetDisabled( bool disabled )
230 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetDisabled(%s) state(%d)\n", (disabled)?"disabled":"active", mButtonState );
234 if ( mButtonState == SELECTED_STATE )
236 ChangeState( DISABLED_SELECTED_STATE );
238 else if ( mButtonState == UNSELECTED_STATE )
240 ChangeState( DISABLED_UNSELECTED_STATE );
245 if ( mButtonState == DISABLED_SELECTED_STATE )
247 ChangeState( SELECTED_STATE );
249 else if ( mButtonState == DISABLED_UNSELECTED_STATE )
251 ChangeState( UNSELECTED_STATE );
256 bool Button::IsDisabled() const
258 return ( mButtonState == DISABLED_SELECTED_STATE || mButtonState == DISABLED_UNSELECTED_STATE ) ;
261 bool Button::ValidateState( State requestedState )
263 /* Below tables shows allowed state transitions
264 * Match rows in first column to following columns, if true then transition allowed.
265 * eg UNSELECTED_STATE to DISABLED_UNSELECTED_STATE is true so state transition allowed.
267 to| UNSELECTED_STATE | SELECTED_STATE | DISABLED_UNSELECTED_STATE | DISABLED_SELECTED_STATE |*/
269 bool transitionTable[4][4] = { /* UNSELECTED_STATE*/ { false, true, true, false },
270 /* SELECTED_STATE*/ { true, false, false, true },
271 /* DISABLED_UNSELECTED_STATE*/{ true, true, false, false },
272 /* DISABLED_SELECTED_STATE*/ { false, true, false, false }
275 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ValidateState ReuestedState:%d, CurrentState:%d, result:%s\n",
276 requestedState, mButtonState, (transitionTable[mButtonState][requestedState])?"change-accepted":"change-denied");
278 return transitionTable[mButtonState][requestedState];
281 void Button::PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state )
283 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState BACKROUND visual(%d) for state (%d)\n", GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND], state );
284 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState FOREGROUND visuals(%d) for state (%d)\n", GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND], state );
286 (this->*functionPtr)( GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND] );
287 (this->*functionPtr)( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
292 void Button::ChangeState( State requestedState )
294 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d)\n", requestedState );
296 // Validate State before changing
297 if ( !ValidateState( requestedState ))
299 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ChangeState ReuestedState(%d) not validated\n", requestedState );
303 // If not on stage the button could have still been set to selected so update state/
304 mPreviousButtonState = mButtonState; // Store previous state for visual removal (used when animations ended)
305 mButtonState = requestedState; // Update current state
307 if ( Self().OnStage() )
309 // Clear existing animation and remove visual being transitioned out before starting a new transition of visuals. ClearTransitionAnimation();
310 OnStateChange( mButtonState ); // Notify derived buttons
311 //// When animations enabled PerformFunctionOnVisualsInState( &Button::TransitionButtonVisualOut, mPreviousButtonState );
312 PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
313 // When animations enabled then call PerformFunctionOnVisualsInState( &Button::TransitionButtonVisualIn, mButtonState );
314 // then StartTransitionAnimation();
315 // and ClearTransitionAnimation();
316 PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
319 Toolkit::Button handle( GetOwner() );
321 mStateChangedSignal.Emit( handle );
324 bool Button::IsSelected() const
326 bool selected = ( mButtonState == SELECTED_STATE ) || ( mButtonState == DISABLED_SELECTED_STATE );
327 return mTogglableButton && selected;
330 void Button::SetAnimationTime( float animationTime )
332 mAnimationTime = animationTime;
335 float Button::GetAnimationTime() const
337 return mAnimationTime;
340 void Button::SetLabelText( const std::string& label )
342 Property::Map labelProperty;
343 labelProperty.Insert( "text", label );
344 SetupLabel( labelProperty );
347 std::string Button::GetLabelText() const
349 Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
352 return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
354 return std::string();
357 void Button::SetupLabel( const Property::Map& properties )
359 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "SetupLabel\n");
361 // If we don't have a label yet, create one.
364 // If we don't have a label, create one and set it up.
365 // Note: The label text is set from the passed in property map after creation.
366 mLabel = Toolkit::TextLabel::New();
367 mLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
368 mLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
369 mLabel.SetParentOrigin( ParentOrigin::TOP_LEFT );
370 mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
373 mLabel.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map()
374 .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::COLOR )
375 .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Color::RED )
378 ResizePolicy::Type policy = Self().GetResizePolicy( Dimension::ALL_DIMENSIONS );
379 if ( policy == ResizePolicy::USE_NATURAL_SIZE || policy == ResizePolicy::FIT_TO_CHILDREN )
381 mLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
385 // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error
386 //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
388 Self().Add( mLabel );
391 // Set any properties specified for the label by iterating through all property key-value pairs.
392 for( unsigned int i = 0, mapCount = properties.Count(); i < mapCount; ++i )
394 const StringValuePair& propertyPair( properties.GetPair( i ) );
396 // Convert the property string to a property index.
397 Property::Index setPropertyIndex = mLabel.GetPropertyIndex( propertyPair.first );
398 if( setPropertyIndex != Property::INVALID_INDEX )
400 // If the conversion worked, we have a valid property index,
401 // Set the property to the new value.
402 mLabel.SetProperty( setPropertyIndex, propertyPair.second );
406 // Notify derived button classes of the change.
412 void Button::SetLabelStrutLength( unsigned int length )
414 mForeGroundToLabelStrutLength = length;
417 void Button::SetLabelAlignment( Button::Align labelAlignment)
419 mTextLabelAlignment = labelAlignment;
423 float Button::GetLabelStrutLength()
425 return mForeGroundToLabelStrutLength;
428 Button::Align Button::GetLabelAlignment()
430 return mTextLabelAlignment;
433 void Button::CreateVisualsForComponent( Property::Index index, const Property::Value& value, const float visualDepth )
435 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent index(%d)\n", index );
436 Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
437 Toolkit::Visual::Base buttonVisual;
439 std::string imageUrl;
440 if( value.Get( imageUrl ) )
442 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index );
443 if ( !imageUrl.empty() )
445 buttonVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() );
450 // if its not a string then get a Property::Map from the property if possible.
451 Property::Map *map = value.GetMap();
452 if( map && !map->Empty() ) // Empty map results in current visual removal.
454 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using Map(%d)\n", index );
455 buttonVisual = visualFactory.CreateVisual( *map );
461 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RegisterVisual index(%d)\n", index );
462 buttonVisual.SetDepthIndex( visualDepth );
463 // Background Visuals take full size of control
464 RegisterVisual( index, buttonVisual, false );
468 UnregisterVisual( index );
469 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button visual not created or empty map provided (clearing visual).(%d)\n", index);
473 const Vector4 Button::GetUnselectedColor() const
475 return mUnselectedColor;
478 const Vector4 Button::GetSelectedColor() const
480 return mSelectedColor;
483 // Legacy code whilst Color can be set by direct Property setting ( deprecated ) instead of setting a Visual
484 void Button::SetColor( const Vector4& color, Property::Index visualIndex )
486 if ( visualIndex == Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL )
488 mSelectedColor = color;
492 mUnselectedColor = color;
496 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
497 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
499 CreateVisualsForComponent( visualIndex, map, DepthIndex::BACKGROUND );
502 bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
506 Dali::BaseHandle handle( object );
508 Toolkit::Button button = Toolkit::Button::DownCast( handle );
510 DALI_ASSERT_DEBUG( button );
512 if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
514 ret = GetImplementation( button ).DoClickAction( attributes );
520 bool Button::DoClickAction( const Property::Map& attributes )
522 // Prevents the button signals from doing a recursive loop by sending an action
523 // and re-emitting the signals.
524 if( !mClickActionPerforming )
526 mClickActionPerforming = true;
528 if ( !mTogglableButton )
530 mButtonPressedState = DEPRESSED;
533 mClickActionPerforming = false;
541 void Button::OnButtonDown()
543 if( mTogglableButton )
545 if ( mButtonState != SELECTED_STATE )
548 mButtonPressedState = TOGGLE_DEPRESSED;
552 mButtonPressedState = DEPRESSED;
558 mButtonPressedState = DEPRESSED;
561 SetUpTimer( mInitialAutoRepeatingDelay );
565 // The pressed signal should be emitted regardless of toggle mode.
566 Toolkit::Button handle( GetOwner() );
567 mPressedSignal.Emit( handle );
570 void Button::OnButtonUp()
572 if( DEPRESSED == mButtonPressedState )
574 if( mTogglableButton )
576 if ( TOGGLE_DEPRESSED != mButtonPressedState )
578 SetSelected( !IsSelected() );
579 mButtonPressedState = UNPRESSED;
587 mAutoRepeatingTimer.Reset();
591 // The clicked and released signals should be emitted regardless of toggle mode.
592 Toolkit::Button handle( GetOwner() );
593 mReleasedSignal.Emit( handle );
594 mClickedSignal.Emit( handle );
598 void Button::OnTouchPointLeave()
600 if( DEPRESSED == mButtonPressedState )
602 if( !mTogglableButton )
608 mAutoRepeatingTimer.Reset();
612 mButtonPressedState = UNPRESSED;
614 // The released signal should be emitted regardless of toggle mode.
615 Toolkit::Button handle( GetOwner() );
616 mReleasedSignal.Emit( handle );
620 void Button::OnTouchPointInterrupted()
625 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
627 return mPressedSignal;
630 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
632 return mReleasedSignal;
635 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
637 return mClickedSignal;
640 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
642 return mStateChangedSignal;
645 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
647 Dali::BaseHandle handle( object );
649 bool connected( true );
650 Toolkit::Button button = Toolkit::Button::DownCast( handle );
652 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
654 button.PressedSignal().Connect( tracker, functor );
656 else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
658 button.ReleasedSignal().Connect( tracker, functor );
660 else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
662 button.ClickedSignal().Connect( tracker, functor );
664 else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
666 button.StateChangedSignal().Connect( tracker, functor );
670 // signalName does not match any signal
677 void Button::OnInitialize()
679 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnInitialize\n" );
683 mTapDetector = TapGestureDetector::New();
684 mTapDetector.Attach( self );
685 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
687 self.SetKeyboardFocusable( true );
689 self.TouchSignal().Connect( this, &Button::OnTouch );
692 bool Button::OnAccessibilityActivated()
694 return OnKeyboardEnter();
697 bool Button::OnTouch( Actor actor, const TouchData& touch )
700 // Only events are processed when the button is not disabled and the touch event has only
703 if( !IsDisabled() && ( 1 == touch.GetPointCount() ) )
705 switch( touch.GetState( 0 ) )
707 case PointState::DOWN:
717 case PointState::INTERRUPTED:
719 OnTouchPointInterrupted();
722 case PointState::LEAVE:
727 case PointState::MOTION:
728 case PointState::STATIONARY: // FALLTHROUGH
735 else if( 1 < touch.GetPointCount() )
737 OnTouchPointLeave(); // Notification for derived classes.
739 // Sets the button state to the default
740 mButtonPressedState = UNPRESSED;
746 bool Button::OnKeyboardEnter()
748 // When the enter key is pressed, or button is activated, the click action is performed.
749 Property::Map attributes;
750 bool ret = DoClickAction( attributes );
755 void Button::OnStageDisconnection()
757 if( DEPRESSED == mButtonPressedState )
759 if( !mTogglableButton )
765 mAutoRepeatingTimer.Reset();
770 mButtonPressedState = UNPRESSED;
772 Control::OnStageDisconnection(); // Visuals will be set off stage
775 void Button::OnStageConnection( int depth )
777 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnStageConnection ptr(%p) \n", this );
778 PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
779 Control::OnStageConnection( depth ); // Enabled visuals will be put on stage
783 Vector3 Button::GetNaturalSize()
785 Vector3 size = Vector3::ZERO;
787 bool horizontalAlignment = mTextLabelAlignment == BEGIN || mTextLabelAlignment == END; // label and visual side by side
789 // Get natural size of foreground ( largest of the possible visuals )
790 Size largestForegroundVisual;
793 for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
795 Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
799 visual.GetNaturalSize( visualSize );
800 largestForegroundVisual.width = std::max(largestForegroundVisual.width, visualSize.width );
801 largestForegroundVisual.height = std::max(largestForegroundVisual.height, visualSize.height );
805 // Get horizontal padding total
806 if ( largestForegroundVisual.width > 0 ) // if visual exists
808 size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right;
810 // Get vertical padding total
811 if ( largestForegroundVisual.height > 0 )
813 size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
816 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
817 largestForegroundVisual.width, largestForegroundVisual.height );
819 // Get natural size of label
822 labelSize = Vector2( mLabel.GetNaturalSize());
824 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize labelSize(%f,%f) padding(%f,%f)\n",
825 labelSize.width, labelSize.height, mLabelPadding.left + mLabelPadding.right, mLabelPadding.top + mLabelPadding.bottom);
827 labelSize.width += mLabelPadding.left + mLabelPadding.right;
828 labelSize.height += mLabelPadding.top + mLabelPadding.bottom;
830 // Add label size to height or width depending on alignment position
831 if ( horizontalAlignment )
833 size.width += labelSize.width;
834 size.height = std::max(size.height, labelSize.height );
838 size.height += labelSize.height;
839 size.width = std::max(size.width, labelSize.width );
843 if( size.width < 1 && size.height < 1 )
845 // if no image or label then use Control's natural size
846 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize Using control natural size\n");
847 size = Control::GetNaturalSize();
850 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button GetNaturalSize (%f,%f)\n", size.width, size.height );
855 void Button::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
857 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnSetResizePolicy\n");
859 if ( policy != ResizePolicy::USE_NATURAL_SIZE || policy != ResizePolicy::FIT_TO_CHILDREN )
863 // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error
864 //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
871 void Button::OnRelayout( const Vector2& size, RelayoutContainer& container )
873 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout targetSize(%f,%f) ptr(%p) state[%d]\n", size.width, size.height, this, mButtonState );
875 PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
877 ResizePolicy::Type widthResizePolicy = Self().GetResizePolicy( Dimension::WIDTH );
878 ResizePolicy::Type heightResizePolicy = Self().GetResizePolicy( Dimension::HEIGHT );
880 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout resize policy: width:%d height:%d\n", heightResizePolicy, widthResizePolicy);
882 Toolkit::Visual::Base currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
884 Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] );
886 // Sizes and padding set to zero, if not present then values will no effect calculations.
887 Vector2 visualPosition = Vector2::ZERO;
888 Vector2 labelPosition = Vector2::ZERO;
889 Size visualSize = Size::ZERO;
890 Padding foregroundVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f );
891 Padding labelVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f );
895 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Label padding setting padding:%f,%f,%f,%f\n", mLabelPadding.y, mLabelPadding.x, mLabelPadding.width,mLabelPadding.height );
896 labelVisualPadding = mLabelPadding;
901 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Foreground Visual setting padding:%f,%f,%f,%f\n", mForegroundPadding.y, mForegroundPadding.x, mForegroundPadding.width,mForegroundPadding.height );
902 currentVisual.GetNaturalSize( visualSize );
903 foregroundVisualPadding = mForegroundPadding;
906 Toolkit::Align::Type visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
908 Vector2 visualAndPaddingSize = Vector2( ( foregroundVisualPadding.x + visualSize.width + foregroundVisualPadding.y ),
909 ( foregroundVisualPadding.width + visualSize.height + foregroundVisualPadding.height ));
911 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout visualAndPaddingSize(%f,%f)\n", visualAndPaddingSize.width, visualAndPaddingSize.height);
913 switch ( mTextLabelAlignment )
917 visualAnchorPoint = Toolkit::Align::TOP_END;
918 visualPosition.x = foregroundVisualPadding.right;
919 visualPosition.y = foregroundVisualPadding.top;
921 labelPosition.x = labelVisualPadding.x;
922 labelPosition.y = labelVisualPadding.top;
927 visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
928 visualPosition.x = foregroundVisualPadding.left;
929 visualPosition.y = foregroundVisualPadding.top;
931 labelPosition.x = visualAndPaddingSize.width + labelVisualPadding.x;
932 labelPosition.y = labelVisualPadding.top;
937 visualAnchorPoint = Toolkit::Align::BOTTOM_END;
938 visualPosition.x = foregroundVisualPadding.left;
939 visualPosition.y = foregroundVisualPadding.bottom;
941 labelPosition.x = labelVisualPadding.left;
942 labelPosition.y = labelVisualPadding.top;
947 visualAnchorPoint = Toolkit::Align::TOP_END;
948 visualPosition.x = foregroundVisualPadding.left;
949 visualPosition.y = foregroundVisualPadding.top;
951 labelPosition.x = labelVisualPadding.left;
952 labelPosition.y = visualAndPaddingSize.height + labelVisualPadding.top;
957 if ( currentBackGroundVisual )
959 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual bakcground size to(%f,%f)\n", size.width, size.height);
961 Property::Map visualTransform;
963 visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, size )
964 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 0.0f, 0.0f, 1.0f, 1.0f) ); // Use relative size
966 currentBackGroundVisual.SetTransformAndSize( visualTransform, size );
971 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual size to(%f,%f)\n", visualSize.width, visualSize.height);
973 currentVisual.SetProperty( Toolkit::Visual::DevelProperty::TRANSFORM,
974 Dali::Property::Map()
975 .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, visualSize )
976 .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, visualPosition )
977 .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4(1.0f, 1.0f, 1.0f,1.0f) )
978 .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
979 .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, visualAnchorPoint )
985 // When Text visual size can be set, determine the size here.
986 // Text Visual should take all space available after foreground visual size and all padding is considered.
987 // Remaining Space priority, Foreground padding, foreground visual, Text padding then Text visual.
989 Size remainingSpaceForText = Size::ZERO;
990 remainingSpaceForText.width = size.width - visualAndPaddingSize.width - labelVisualPadding.x - labelVisualPadding.y;
991 remainingSpaceForText.height = size.height - visualAndPaddingSize.height - labelVisualPadding.width - labelVisualPadding.height;
993 if ( !currentVisual )
995 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Only Text\n");
997 // Center Text if no foreground visual
998 Size labelNaturalSize = Vector2( mLabel.GetNaturalSize() );
1000 // A Text visual will take up all the remainingSpaceForText, for now TextLabel natural size needed for positioning.
1001 labelPosition.x = labelVisualPadding.left + remainingSpaceForText.width*0.5 - labelNaturalSize.width *0.5;
1002 labelPosition.y = labelVisualPadding.height + remainingSpaceForText.height*0.5 - labelNaturalSize.height *0.5;
1005 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size(%f,%f) text Position(%f,%f) \n", remainingSpaceForText.width, remainingSpaceForText.height, labelPosition.x, labelPosition.y);
1007 mLabel.SetPosition( labelPosition.x, labelPosition.y );
1008 container.Add( mLabel, remainingSpaceForText ); // Currently a TextLabel is used and size can not be set here.
1011 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n");
1014 void Button::OnTap(Actor actor, const TapGesture& tap)
1016 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnTap\n" );
1019 void Button::SetUpTimer( float delay )
1021 mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
1022 mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
1023 mAutoRepeatingTimer.Start();
1026 bool Button::AutoRepeatingSlot()
1028 bool consumed = false;
1031 // Restart the autorepeat timer.
1032 SetUpTimer( mNextAutoRepeatingDelay );
1036 Toolkit::Button handle( GetOwner() );
1039 consumed = mReleasedSignal.Emit( handle );
1040 consumed = mClickedSignal.Emit( handle );
1041 consumed |= mPressedSignal.Emit( handle );
1047 void Button::Pressed()
1049 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Pressed\n" );
1051 if( mButtonState == UNSELECTED_STATE )
1053 ClearTransitionAnimation();
1054 ChangeState( SELECTED_STATE );
1055 OnPressed(); // Notifies the derived class the button has been pressed.
1059 void Button::Released()
1061 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Released\n" );
1063 if( mButtonState == SELECTED_STATE && !mTogglableButton )
1065 ClearTransitionAnimation();
1066 ChangeState( UNSELECTED_STATE );
1067 OnReleased(); // // Notifies the derived class the button has been released.
1069 mButtonPressedState = UNPRESSED;
1072 Button::PressState Button::GetPressedState()
1074 return mButtonPressedState;
1077 Button::State Button::GetButtonState()
1079 return mButtonState;
1082 void Button::SelectRequiredVisual( Property::Index visualIndex )
1084 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState );
1086 EnableVisual( visualIndex, true );
1089 void Button::TransitionButtonVisualOut( Property::Index visualIndex )
1091 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionButtonVisualOut index(%d)\n", visualIndex);
1093 // PrepareForTranstionOut and OnTransitionOut needs to be called on visual instead of Actor once animating is possible
1096 void Button::TransitionButtonVisualIn( Property::Index visualIndex )
1098 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionButtonVisualIn index(%d)\n", visualIndex );
1101 void Button::OnTransitionIn( Actor actor )
1103 PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
1106 void Button::RemoveVisual( Property::Index visualIndex )
1108 // Use OnButtonVisualRemoval if want button developer to have the option to override removal.
1109 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::RemoveVisual index(%d) state(%d)\n", visualIndex, mButtonState );
1111 Toolkit::Visual::Base visual = GetVisual( visualIndex );
1115 EnableVisual( visualIndex, false );
1119 void Button::OnButtonVisualRemoval( Property::Index visualIndex )
1121 // Derived Buttons can over ride this to prevent default removal.
1122 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnButtonVisualRemoval index(%d)\n", visualIndex );
1123 RemoveVisual( visualIndex );
1126 void Button::StartTransitionAnimation()
1128 if( mTransitionAnimation )
1130 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::StartTransitionAnimation progress(%f) duration(%f) state(%d) \n",
1131 mTransitionAnimation.GetCurrentProgress(), mTransitionAnimation.GetDuration(),
1132 mTransitionAnimation.GetState());
1133 mTransitionAnimation.Play();
1137 void Button::ClearTransitionAnimation()
1139 if( mTransitionAnimation )
1141 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ClearTransitionAnimation progress(%f) duration(%f) state(%d) \n",
1142 mTransitionAnimation.GetCurrentProgress(), mTransitionAnimation.GetDuration(),
1143 mTransitionAnimation.GetState());
1144 mTransitionAnimation.Clear();
1145 mTransitionAnimation.Reset();
1149 Dali::Animation Button::GetTransitionAnimation()
1151 if( !mTransitionAnimation )
1153 mTransitionAnimation = Dali::Animation::New( GetAnimationTime() );
1154 mTransitionAnimation.FinishedSignal().Connect( this, &Button::TransitionAnimationFinished );
1157 return mTransitionAnimation;
1160 void Button::TransitionAnimationFinished( Dali::Animation& source )
1162 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::TransitionAnimationFinished\n" );
1163 ClearTransitionAnimation();
1164 PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
1167 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1169 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1171 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty index[%d]\n", index );
1177 case Toolkit::Button::Property::DISABLED:
1179 GetImplementation( button ).SetDisabled( value.Get< bool >() );
1183 case Toolkit::Button::Property::AUTO_REPEATING:
1185 GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1189 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1191 GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1195 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1197 GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1201 case Toolkit::Button::Property::TOGGLABLE:
1203 GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1207 case Toolkit::Button::Property::SELECTED:
1209 GetImplementation( button ).SetSelected( value.Get< bool >() );
1213 case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
1215 GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
1218 case Toolkit::Button::Property::DISABLED_STATE_IMAGE: // Legacy Tizen 3.0
1220 GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
1223 case Toolkit::Button::Property::SELECTED_STATE_IMAGE: // Legacy Tizen 3.0
1225 GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT );
1228 case Toolkit::Button::Property::UNSELECTED_VISUAL:
1229 case Toolkit::Button::Property::SELECTED_VISUAL:
1230 case Toolkit::Button::Property::DISABLED_SELECTED_VISUAL:
1231 case Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL:
1233 GetImplementation( button ).CreateVisualsForComponent( index, value, DepthIndex::CONTENT );
1237 case Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL:
1238 case Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL:
1239 case Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL:
1240 case Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL:
1242 GetImplementation( button ).CreateVisualsForComponent( index , value, DepthIndex::BACKGROUND);
1246 case Toolkit::Button::Property::UNSELECTED_COLOR:
1248 DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::UNSELECTED_COLOR instead use Button::Property::UNSELECTED_BACKGROUND_VISUAL\n", __FUNCTION__);
1249 GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL );
1253 case Toolkit::Button::Property::SELECTED_COLOR:
1255 DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::SELECTED_COLOR instead use Button::Property::SELECTED_BACKGROUND_VISUAL\n", __FUNCTION__);
1256 GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL );
1260 case Toolkit::Button::Property::LABEL_TEXT:
1262 DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::LABEL_TEXT instead use Button::Property::LABEL\n", __FUNCTION__);
1263 Property::Map labelTextProperty;
1264 labelTextProperty.Insert( "text", value.Get< std::string >() );
1265 GetImplementation( button ).SetupLabel( labelTextProperty );
1269 case Toolkit::Button::Property::LABEL:
1271 // Get a Property::Map from the property if possible.
1272 Property::Map setPropertyMap;
1273 if( value.Get( setPropertyMap ) )
1275 GetImplementation( button ).SetupLabel( setPropertyMap );
1280 case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
1282 GetImplementation( button ).SetLabelStrutLength( value.Get< int >() );
1286 case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
1288 Button::Align labelAlignment(END);
1289 Scripting::GetEnumeration< Button::Align> ( value.Get< std::string >().c_str(),
1290 ALIGNMENT_TABLE, ALIGNMENT_TABLE_COUNT,
1293 GetImplementation( button ).SetLabelAlignment( labelAlignment );
1300 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1302 Property::Value value;
1304 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1308 switch ( propertyIndex )
1310 case Toolkit::Button::Property::DISABLED:
1312 value = GetImplementation( button ).IsDisabled();
1316 case Toolkit::Button::Property::AUTO_REPEATING:
1318 value = GetImplementation( button ).mAutoRepeating;
1322 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1324 value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1328 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1330 value = GetImplementation( button ).mNextAutoRepeatingDelay;
1334 case Toolkit::Button::Property::TOGGLABLE:
1336 value = GetImplementation( button ).mTogglableButton;
1340 case Toolkit::Button::Property::SELECTED:
1342 value = GetImplementation( button ).IsSelected();
1346 case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
1348 value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL );
1352 case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
1354 value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL );
1358 case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
1360 value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL );
1364 case Toolkit::Button::Property::UNSELECTED_COLOR:
1366 value = GetImplementation( button ).GetUnselectedColor();
1370 case Toolkit::Button::Property::SELECTED_COLOR:
1372 value = GetImplementation( button ).GetSelectedColor();
1376 case Toolkit::Button::Property::LABEL_TEXT:
1378 value = GetImplementation( button ).GetLabelText();
1382 case Toolkit::Button::Property::LABEL:
1384 Property::Map emptyMap;
1389 case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
1391 value = GetImplementation( button ).GetLabelStrutLength();
1395 case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
1397 const char* alignment = Scripting::GetEnumerationName< Button::Align >( GetImplementation( button ).GetLabelAlignment(),
1398 ALIGNMENT_STRING_TABLE,
1399 ALIGNMENT_STRING_TABLE_COUNT );
1402 value = std::string( alignment );
1413 void Button::SetLabelPadding( const Padding& padding)
1415 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetLabelPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top );
1416 mLabelPadding = Padding( padding.left, padding.right, padding.bottom, padding.top );
1420 Padding Button::GetLabelPadding()
1422 return mLabelPadding;
1425 void Button::SetForegroundPadding( const Padding& padding)
1427 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetForegroundPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top );
1428 mForegroundPadding = Padding( padding.left, padding.right, padding.bottom, padding.top );
1432 Padding Button::GetForegroundPadding()
1434 return mForegroundPadding;
1437 ////////////////////////////////////////////////////////////////////////
1438 // Legacy functions from Tizen 2.4 and 3.0
1440 void Button::SetLabel( Actor label )
1444 Property::Value value ="";
1445 value = label.GetProperty(Toolkit::TextLabel::Property::TEXT);
1447 SetLabelText( value.Get<std::string>() );
1451 void Button::SetUnselectedImage( const std::string& filename )
1453 if( !filename.empty() )
1455 CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
1459 void Button::SetBackgroundImage( const std::string& filename )
1461 if( !filename.empty() )
1463 CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
1467 void Button::SetSelectedImage( const std::string& filename )
1469 if( !filename.empty() )
1471 CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT );
1475 void Button::SetSelectedBackgroundImage( const std::string& filename )
1477 if( !filename.empty() )
1479 CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
1483 void Button::SetDisabledBackgroundImage( const std::string& filename )
1485 if( !filename.empty() )
1487 CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
1491 void Button::SetDisabledImage( const std::string& filename )
1493 if( !filename.empty() )
1495 CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
1499 void Button::SetDisabledSelectedImage( const std::string& filename )
1501 if( !filename.empty() )
1503 CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT );
1507 std::string Button::GetUrlForImageVisual( Property::Index index )
1509 Toolkit::Visual::Base visual = GetVisual( index );
1514 Dali::Property::Map retreivedMap;
1515 visual.CreatePropertyMap( retreivedMap );
1516 Property::Value* value = retreivedMap.Find( Toolkit::ImageVisual::Property::URL, Property::STRING );
1519 result = value->Get<std::string>();
1526 // Below functions DEPRECATED_1_0.50 - Return empty Actors
1528 Actor Button::GetButtonImage() const
1530 DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50 Returning empty Actor \n");
1534 Actor Button::GetSelectedImage() const
1536 DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50 Returning empty Actor \n");
1540 } // namespace Internal
1542 } // namespace Toolkit