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, "labelRelativeAlignment", STRING, LABEL_RELATIVE_ALIGNMENT )
93 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "pressed", SIGNAL_PRESSED )
94 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "released", SIGNAL_RELEASED )
95 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "clicked", SIGNAL_CLICKED )
96 DALI_SIGNAL_REGISTRATION( Toolkit, Button, "stateChanged", SIGNAL_STATE_CHANGED )
99 DALI_ACTION_REGISTRATION( Toolkit, Button, "buttonClick", ACTION_BUTTON_CLICK )
101 DALI_TYPE_REGISTRATION_END()
103 DALI_ENUM_TO_STRING_TABLE_BEGIN( ALIGNMENT )
104 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BEGIN )
105 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, END )
106 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, TOP )
107 DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Internal::Button, BOTTOM )
108 DALI_ENUM_TO_STRING_TABLE_END( ALIGNMENT )
110 const Scripting::StringEnum ALIGNMENT_STRING_TABLE[] =
112 { "BEGIN", Button::BEGIN },
113 { "END", Button::END },
114 { "TOP", Button::TOP },
115 { "BOTTOM", Button::BOTTOM },
118 const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
120 const Property::Index GET_VISUAL_INDEX_FOR_STATE[][Button::STATE_COUNT] =
122 { Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::UNSELECTED_VISUAL },
123 { Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::SELECTED_VISUAL },
124 { Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL },
125 { Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL, Toolkit::Button::Property::DISABLED_SELECTED_VISUAL }
128 } // unnamed namespace
131 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
132 mAutoRepeatingTimer(),
133 mTextLabelAlignment( END ),
134 mAutoRepeating( false ),
135 mTogglableButton( false ),
136 mInitialAutoRepeatingDelay( 0.0f ),
137 mNextAutoRepeatingDelay( 0.0f ),
138 mAnimationTime( 0.0f ),
139 mButtonPressedState( UNPRESSED ),
140 mButtonState( UNSELECTED_STATE ),
141 mPreviousButtonState( mButtonState ),
142 mClickActionPerforming( false )
150 void Button::SetAutoRepeating( bool autoRepeating )
152 mAutoRepeating = autoRepeating;
154 // An autorepeating button can't be a togglable button.
157 mTogglableButton = false;
161 SetSelected( false );
166 bool Button::IsAutoRepeating() const
168 return mAutoRepeating;
171 void Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
173 DALI_ASSERT_DEBUG( initialAutoRepeatingDelay > 0.f );
174 mInitialAutoRepeatingDelay = initialAutoRepeatingDelay;
177 float Button::GetInitialAutoRepeatingDelay() const
179 return mInitialAutoRepeatingDelay;
182 void Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
184 DALI_ASSERT_DEBUG( nextAutoRepeatingDelay > 0.f );
185 mNextAutoRepeatingDelay = nextAutoRepeatingDelay;
188 float Button::GetNextAutoRepeatingDelay() const
190 return mNextAutoRepeatingDelay;
193 void Button::SetTogglableButton( bool togglable )
195 mTogglableButton = togglable;
197 // A toggle button can't be an autorepeating button.
200 mAutoRepeating = false;
204 bool Button::IsTogglableButton() const
206 return mTogglableButton;
209 void Button::SetSelected( bool selected )
211 if( mTogglableButton )
213 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetSelected (%s)\n", (selected?"true":"false") );
215 if ( selected && ( mButtonState != SELECTED_STATE ) )
217 ChangeState( SELECTED_STATE );
219 else if ( !selected && ( mButtonState != UNSELECTED_STATE ) )
221 ChangeState( UNSELECTED_STATE );
226 void Button::SetDisabled( bool disabled )
228 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetDisabled(%s) state(%d)\n", (disabled)?"disabled":"active", mButtonState );
232 if ( mButtonState == SELECTED_STATE )
234 ChangeState( DISABLED_SELECTED_STATE );
236 else if ( mButtonState == UNSELECTED_STATE )
238 ChangeState( DISABLED_UNSELECTED_STATE );
243 if ( mButtonState == DISABLED_SELECTED_STATE )
245 ChangeState( SELECTED_STATE );
247 else if ( mButtonState == DISABLED_UNSELECTED_STATE )
249 ChangeState( UNSELECTED_STATE );
254 bool Button::IsDisabled() const
256 return ( mButtonState == DISABLED_SELECTED_STATE || mButtonState == DISABLED_UNSELECTED_STATE ) ;
259 bool Button::ValidateState( State requestedState )
261 /* Below tables shows allowed state transitions
262 * Match rows in first column to following columns, if true then transition allowed.
263 * eg UNSELECTED_STATE to DISABLED_UNSELECTED_STATE is true so state transition allowed.
265 to| UNSELECTED_STATE | SELECTED_STATE | DISABLED_UNSELECTED_STATE | DISABLED_SELECTED_STATE |*/
267 bool transitionTable[4][4] = { /* UNSELECTED_STATE*/ { false, true, true, false },
268 /* SELECTED_STATE*/ { true, false, false, true },
269 /* DISABLED_UNSELECTED_STATE*/{ true, true, false, false },
270 /* DISABLED_SELECTED_STATE*/ { false, true, false, false }
273 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::ValidateState ReuestedState:%d, CurrentState:%d, result:%s\n",
274 requestedState, mButtonState, (transitionTable[mButtonState][requestedState])?"change-accepted":"change-denied");
276 return transitionTable[mButtonState][requestedState];
279 void Button::PerformFunctionOnVisualsInState( void(Button::*functionPtr)( Property::Index visualIndex), State state )
281 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState BACKROUND visual(%d) for state (%d)\n",
282 GET_VISUAL_INDEX_FOR_STATE[state][BACKGROUND], state );
283 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::PerformFunctionOnVisualsInState FOREGROUND visuals(%d) for state (%d)\n",
284 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 OnStateChange( mButtonState ); // Notify derived buttons
310 PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
311 // If animation supported then visual removal should be performed after any transition animation has completed.
312 PerformFunctionOnVisualsInState( &Button::OnButtonVisualRemoval, mPreviousButtonState ); // Derived button can override OnButtonVisualRemoval
315 Toolkit::Button handle( GetOwner() );
317 mStateChangedSignal.Emit( handle );
320 bool Button::IsSelected() const
322 bool selected = ( mButtonState == SELECTED_STATE ) || ( mButtonState == DISABLED_SELECTED_STATE );
323 return mTogglableButton && selected;
326 void Button::SetLabelText( const std::string& label )
328 Property::Map labelProperty;
329 labelProperty.Insert( "text", label );
330 SetupLabel( labelProperty );
333 std::string Button::GetLabelText() const
335 Toolkit::TextLabel label = Dali::Toolkit::TextLabel::DownCast( mLabel );
338 return label.GetProperty<std::string>( Dali::Toolkit::TextLabel::Property::TEXT );
340 return std::string();
343 void Button::SetupLabel( const Property::Map& properties )
345 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "SetupLabel\n");
347 // If we don't have a label yet, create one.
350 // If we don't have a label, create one and set it up.
351 // Note: The label text is set from the passed in property map after creation.
352 mLabel = Toolkit::TextLabel::New();
353 mLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
354 mLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
355 mLabel.SetParentOrigin( ParentOrigin::TOP_LEFT );
356 mLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
359 mLabel.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map()
360 .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::COLOR )
361 .Add( Toolkit::ColorVisual::Property::MIX_COLOR, Color::RED )
364 ResizePolicy::Type policy = Self().GetResizePolicy( Dimension::ALL_DIMENSIONS );
365 if ( policy == ResizePolicy::USE_NATURAL_SIZE || policy == ResizePolicy::FIT_TO_CHILDREN )
367 mLabel.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
371 // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error
372 //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
374 Self().Add( mLabel );
377 // Set any properties specified for the label by iterating through all property key-value pairs.
378 for( unsigned int i = 0, mapCount = properties.Count(); i < mapCount; ++i )
380 const StringValuePair& propertyPair( properties.GetPair( i ) );
382 // Convert the property string to a property index.
383 Property::Index setPropertyIndex = mLabel.GetPropertyIndex( propertyPair.first );
384 if( setPropertyIndex != Property::INVALID_INDEX )
386 // If the conversion worked, we have a valid property index,
387 // Set the property to the new value.
388 mLabel.SetProperty( setPropertyIndex, propertyPair.second );
395 void Button::SetLabelAlignment( Button::Align labelAlignment)
397 mTextLabelAlignment = labelAlignment;
401 Button::Align Button::GetLabelAlignment()
403 return mTextLabelAlignment;
406 void Button::CreateVisualsForComponent( Property::Index index, const Property::Value& value, const float visualDepth )
408 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent index(%d)\n", index );
409 Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
410 Toolkit::Visual::Base buttonVisual;
412 std::string imageUrl;
413 if( value.Get( imageUrl ) )
415 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using image URL(%d)\n", index );
416 if ( !imageUrl.empty() )
418 buttonVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() );
423 // if its not a string then get a Property::Map from the property if possible.
424 Property::Map *map = value.GetMap();
425 if( map && !map->Empty() ) // Empty map results in current visual removal.
427 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "CreateVisualsForComponent Using Map(%d)\n", index );
428 buttonVisual = visualFactory.CreateVisual( *map );
434 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "RegisterVisual index(%d)\n", index );
435 buttonVisual.SetDepthIndex( visualDepth );
436 // Background Visuals take full size of control
437 RegisterVisual( index, buttonVisual, false );
441 UnregisterVisual( index );
442 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button visual not created or empty map provided (clearing visual).(%d)\n", index);
446 bool Button::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
450 Dali::BaseHandle handle( object );
452 Toolkit::Button button = Toolkit::Button::DownCast( handle );
454 DALI_ASSERT_DEBUG( button );
456 if( 0 == strcmp( actionName.c_str(), ACTION_BUTTON_CLICK ) )
458 ret = GetImplementation( button ).DoClickAction( attributes );
464 bool Button::DoClickAction( const Property::Map& attributes )
466 // Prevents the button signals from doing a recursive loop by sending an action
467 // and re-emitting the signals.
468 if( !mClickActionPerforming )
470 mClickActionPerforming = true;
472 if ( !mTogglableButton )
474 mButtonPressedState = DEPRESSED;
477 mClickActionPerforming = false;
485 void Button::ButtonDown()
487 if( mTogglableButton )
489 if ( mButtonState != SELECTED_STATE )
492 mButtonPressedState = TOGGLE_DEPRESSED;
496 mButtonPressedState = DEPRESSED;
502 mButtonPressedState = DEPRESSED;
505 SetUpTimer( mInitialAutoRepeatingDelay );
509 // The pressed signal should be emitted regardless of toggle mode.
510 Toolkit::Button handle( GetOwner() );
511 mPressedSignal.Emit( handle );
514 void Button::ButtonUp()
516 if( DEPRESSED == mButtonPressedState )
518 bool validButtonAction = false;
520 if( mTogglableButton ) // Button up will change state
522 validButtonAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour
526 Released(); // Button up will result in unselected state
529 mAutoRepeatingTimer.Reset();
531 validButtonAction = true;
534 if ( validButtonAction )
536 // The clicked and released signals should be emitted regardless of toggle mode.
537 Toolkit::Button handle( GetOwner() );
538 mReleasedSignal.Emit( handle );
539 mClickedSignal.Emit( handle );
544 bool Button::OnToggleReleased()
546 SetSelected( !IsSelected() );
547 mButtonPressedState = UNPRESSED;
552 void Button::OnTouchPointLeave()
554 if( DEPRESSED == mButtonPressedState )
556 if( !mTogglableButton )
562 mAutoRepeatingTimer.Reset();
566 mButtonPressedState = UNPRESSED;
568 // The released signal should be emitted regardless of toggle mode.
569 Toolkit::Button handle( GetOwner() );
570 mReleasedSignal.Emit( handle );
574 void Button::OnTouchPointInterrupted()
579 Toolkit::Button::ButtonSignalType& Button::PressedSignal()
581 return mPressedSignal;
584 Toolkit::Button::ButtonSignalType& Button::ReleasedSignal()
586 return mReleasedSignal;
589 Toolkit::Button::ButtonSignalType& Button::ClickedSignal()
591 return mClickedSignal;
594 Toolkit::Button::ButtonSignalType& Button::StateChangedSignal()
596 return mStateChangedSignal;
599 bool Button::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
601 Dali::BaseHandle handle( object );
603 bool connected( true );
604 Toolkit::Button button = Toolkit::Button::DownCast( handle );
606 if( 0 == strcmp( signalName.c_str(), SIGNAL_PRESSED ) )
608 button.PressedSignal().Connect( tracker, functor );
610 else if( 0 == strcmp( signalName.c_str(), SIGNAL_RELEASED ) )
612 button.ReleasedSignal().Connect( tracker, functor );
614 else if( 0 == strcmp( signalName.c_str(), SIGNAL_CLICKED ) )
616 button.ClickedSignal().Connect( tracker, functor );
618 else if( 0 == strcmp( signalName.c_str(), SIGNAL_STATE_CHANGED ) )
620 button.StateChangedSignal().Connect( tracker, functor );
624 // signalName does not match any signal
631 void Button::OnInitialize()
633 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnInitialize\n" );
637 mTapDetector = TapGestureDetector::New();
638 mTapDetector.Attach( self );
639 mTapDetector.DetectedSignal().Connect(this, &Button::OnTap);
641 self.SetKeyboardFocusable( true );
643 self.TouchSignal().Connect( this, &Button::OnTouch );
646 bool Button::OnAccessibilityActivated()
648 return OnKeyboardEnter();
651 bool Button::OnTouch( Actor actor, const TouchData& touch )
654 // Only events are processed when the button is not disabled and the touch event has only
657 if( !IsDisabled() && ( 1 == touch.GetPointCount() ) )
659 switch( touch.GetState( 0 ) )
661 case PointState::DOWN:
671 case PointState::INTERRUPTED:
673 OnTouchPointInterrupted();
676 case PointState::LEAVE:
681 case PointState::MOTION:
682 case PointState::STATIONARY: // FALLTHROUGH
689 else if( 1 < touch.GetPointCount() )
691 OnTouchPointLeave(); // Notification for derived classes.
693 // Sets the button state to the default
694 mButtonPressedState = UNPRESSED;
700 bool Button::OnKeyboardEnter()
702 // When the enter key is pressed, or button is activated, the click action is performed.
703 Property::Map attributes;
704 bool ret = DoClickAction( attributes );
709 void Button::OnStageDisconnection()
711 if( DEPRESSED == mButtonPressedState )
713 if( !mTogglableButton )
719 mAutoRepeatingTimer.Reset();
724 mButtonPressedState = UNPRESSED;
726 Control::OnStageDisconnection(); // Visuals will be set off stage
729 void Button::OnStageConnection( int depth )
731 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnStageConnection ptr(%p) \n", this );
732 PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
733 Control::OnStageConnection( depth ); // Enabled visuals will be put on stage
737 Vector3 Button::GetNaturalSize()
739 Vector3 size = Vector3::ZERO;
741 bool horizontalAlignment = mTextLabelAlignment == BEGIN || mTextLabelAlignment == END; // label and visual side by side
743 // Get natural size of foreground ( largest of the possible visuals )
744 Size largestForegroundVisual;
747 for ( int state = Button::UNSELECTED_STATE; state < Button::STATE_COUNT; state++)
749 Toolkit::Visual::Base visual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[state][FOREGROUND] );
753 visual.GetNaturalSize( visualSize );
754 largestForegroundVisual.width = std::max(largestForegroundVisual.width, visualSize.width );
755 largestForegroundVisual.height = std::max(largestForegroundVisual.height, visualSize.height );
759 // Get horizontal padding total
760 if ( largestForegroundVisual.width > 0 ) // if visual exists
762 size.width += largestForegroundVisual.width + mForegroundPadding.left + mForegroundPadding.right;
764 // Get vertical padding total
765 if ( largestForegroundVisual.height > 0 )
767 size.height += largestForegroundVisual.height + mForegroundPadding.top + mForegroundPadding.bottom;
770 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize visual Size(%f,%f)\n",
771 largestForegroundVisual.width, largestForegroundVisual.height );
773 // Get natural size of label
776 labelSize = Vector2( mLabel.GetNaturalSize());
778 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize labelSize(%f,%f) padding(%f,%f)\n",
779 labelSize.width, labelSize.height, mLabelPadding.left + mLabelPadding.right, mLabelPadding.top + mLabelPadding.bottom);
781 labelSize.width += mLabelPadding.left + mLabelPadding.right;
782 labelSize.height += mLabelPadding.top + mLabelPadding.bottom;
784 // Add label size to height or width depending on alignment position
785 if ( horizontalAlignment )
787 size.width += labelSize.width;
788 size.height = std::max(size.height, labelSize.height );
792 size.height += labelSize.height;
793 size.width = std::max(size.width, labelSize.width );
797 if( size.width < 1 && size.height < 1 )
799 // if no image or label then use Control's natural size
800 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "GetNaturalSize Using control natural size\n");
801 size = Control::GetNaturalSize();
804 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "Button GetNaturalSize (%f,%f)\n", size.width, size.height );
809 void Button::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
811 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnSetResizePolicy\n");
813 if ( policy != ResizePolicy::USE_NATURAL_SIZE || policy != ResizePolicy::FIT_TO_CHILDREN )
817 // todo Can't set Text Label to USE_ASSIGNED_SIZE as causes a relayout in it whilst doing a relayout = error
818 //mLabel.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
825 void Button::OnRelayout( const Vector2& size, RelayoutContainer& container )
827 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout targetSize(%f,%f) ptr(%p) state[%d]\n", size.width, size.height, this, mButtonState );
829 PerformFunctionOnVisualsInState( &Button::SelectRequiredVisual, mButtonState );
831 Toolkit::Visual::Base currentVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][FOREGROUND] );
833 Toolkit::Visual::Base currentBackGroundVisual = GetVisual( GET_VISUAL_INDEX_FOR_STATE[mButtonState][BACKGROUND] );
835 // Sizes and padding set to zero, if not present then values will no effect calculations.
836 Vector2 visualPosition = Vector2::ZERO;
837 Vector2 labelPosition = Vector2::ZERO;
838 Size visualSize = Size::ZERO;
839 Padding foregroundVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f );
840 Padding labelVisualPadding = Padding(0.0f, 0.0f, 0.0f, 0.0f );
844 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Label padding setting padding:%f,%f,%f,%f\n", mLabelPadding.y, mLabelPadding.x, mLabelPadding.width,mLabelPadding.height );
845 labelVisualPadding = mLabelPadding;
850 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Foreground Visual setting padding:%f,%f,%f,%f\n", mForegroundPadding.y, mForegroundPadding.x, mForegroundPadding.width,mForegroundPadding.height );
851 currentVisual.GetNaturalSize( visualSize );
852 foregroundVisualPadding = mForegroundPadding;
855 Toolkit::Align::Type visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
857 Vector2 visualAndPaddingSize = Vector2( ( foregroundVisualPadding.x + visualSize.width + foregroundVisualPadding.y ),
858 ( foregroundVisualPadding.width + visualSize.height + foregroundVisualPadding.height ));
860 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout visualAndPaddingSize(%f,%f)\n", visualAndPaddingSize.width, visualAndPaddingSize.height);
862 switch ( mTextLabelAlignment )
866 visualAnchorPoint = Toolkit::Align::TOP_END;
867 visualPosition.x = foregroundVisualPadding.right;
868 visualPosition.y = foregroundVisualPadding.top;
870 labelPosition.x = labelVisualPadding.x;
871 labelPosition.y = labelVisualPadding.top;
876 visualAnchorPoint = Toolkit::Align::TOP_BEGIN;
877 visualPosition.x = foregroundVisualPadding.left;
878 visualPosition.y = foregroundVisualPadding.top;
880 labelPosition.x = visualAndPaddingSize.width + labelVisualPadding.x;
881 labelPosition.y = labelVisualPadding.top;
886 visualAnchorPoint = Toolkit::Align::BOTTOM_END;
887 visualPosition.x = foregroundVisualPadding.left;
888 visualPosition.y = foregroundVisualPadding.bottom;
890 labelPosition.x = labelVisualPadding.left;
891 labelPosition.y = labelVisualPadding.top;
896 visualAnchorPoint = Toolkit::Align::TOP_END;
897 visualPosition.x = foregroundVisualPadding.left;
898 visualPosition.y = foregroundVisualPadding.top;
900 labelPosition.x = labelVisualPadding.left;
901 labelPosition.y = visualAndPaddingSize.height + labelVisualPadding.top;
906 if ( currentBackGroundVisual )
908 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual bakcground size to(%f,%f)\n", size.width, size.height);
910 Property::Map visualTransform;
912 visualTransform.Add( Toolkit::DevelVisual::Transform::Property::SIZE, size )
913 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4( 0.0f, 0.0f, 1.0f, 1.0f) ); // Use relative size
915 currentBackGroundVisual.SetTransformAndSize( visualTransform, size );
920 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Setting visual size to(%f,%f)\n", visualSize.width, visualSize.height);
922 currentVisual.SetProperty( Toolkit::Visual::DevelProperty::TRANSFORM,
923 Dali::Property::Map()
924 .Add( Toolkit::Visual::DevelProperty::Transform::Property::SIZE, visualSize )
925 .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET, visualPosition )
926 .Add( Toolkit::Visual::DevelProperty::Transform::Property::OFFSET_SIZE_MODE, Vector4(1.0f, 1.0f, 1.0f,1.0f) )
927 .Add( Toolkit::Visual::DevelProperty::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
928 .Add( Toolkit::Visual::DevelProperty::Transform::Property::ANCHOR_POINT, visualAnchorPoint )
934 // When Text visual size can be set, determine the size here.
935 // Text Visual should take all space available after foreground visual size and all padding is considered.
936 // Remaining Space priority, Foreground padding, foreground visual, Text padding then Text visual.
938 Size remainingSpaceForText = Size::ZERO;
939 remainingSpaceForText.width = size.width - visualAndPaddingSize.width - labelVisualPadding.x - labelVisualPadding.y;
940 remainingSpaceForText.height = size.height - visualAndPaddingSize.height - labelVisualPadding.width - labelVisualPadding.height;
942 if ( !currentVisual )
944 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout Only Text\n");
946 // Center Text if no foreground visual
947 Size labelNaturalSize = Vector2( mLabel.GetNaturalSize() );
949 // A Text visual will take up all the remainingSpaceForText, for now TextLabel natural size needed for positioning.
950 labelPosition.x = labelVisualPadding.left + remainingSpaceForText.width*0.5 - labelNaturalSize.width *0.5;
951 labelPosition.y = labelVisualPadding.height + remainingSpaceForText.height*0.5 - labelNaturalSize.height *0.5;
954 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout text Size(%f,%f) text Position(%f,%f) \n", remainingSpaceForText.width, remainingSpaceForText.height, labelPosition.x, labelPosition.y);
956 mLabel.SetPosition( labelPosition.x, labelPosition.y );
957 container.Add( mLabel, remainingSpaceForText ); // Currently a TextLabel is used and size can not be set here.
960 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n");
963 void Button::OnTap(Actor actor, const TapGesture& tap)
965 DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnTap\n" );
968 void Button::SetUpTimer( float delay )
970 mAutoRepeatingTimer = Dali::Timer::New( static_cast<unsigned int>( 1000.f * delay ) );
971 mAutoRepeatingTimer.TickSignal().Connect( this, &Button::AutoRepeatingSlot );
972 mAutoRepeatingTimer.Start();
975 bool Button::AutoRepeatingSlot()
977 bool consumed = false;
980 // Restart the autorepeat timer.
981 SetUpTimer( mNextAutoRepeatingDelay );
985 Toolkit::Button handle( GetOwner() );
988 consumed = mReleasedSignal.Emit( handle );
989 consumed = mClickedSignal.Emit( handle );
990 consumed |= mPressedSignal.Emit( handle );
996 void Button::Pressed()
998 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Pressed\n" );
1000 if( mButtonState == UNSELECTED_STATE )
1002 ChangeState( SELECTED_STATE );
1003 OnPressed(); // Notifies the derived class the button has been pressed.
1007 void Button::Released()
1009 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::Released\n" );
1011 if( mButtonState == SELECTED_STATE && !mTogglableButton )
1013 ChangeState( UNSELECTED_STATE );
1014 OnReleased(); // // Notifies the derived class the button has been released.
1016 mButtonPressedState = UNPRESSED;
1019 void Button::SelectRequiredVisual( Property::Index visualIndex )
1021 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SelectRequiredVisual index(%d) state(%d)\n", visualIndex, mButtonState );
1023 EnableVisual( visualIndex, true );
1026 void Button::RemoveVisual( Property::Index visualIndex )
1028 // Use OnButtonVisualRemoval if want button developer to have the option to override removal.
1029 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::RemoveVisual index(%d) state(%d)\n", visualIndex, mButtonState );
1031 Toolkit::Visual::Base visual = GetVisual( visualIndex );
1035 EnableVisual( visualIndex, false );
1039 void Button::OnButtonVisualRemoval( Property::Index visualIndex )
1041 // Derived Buttons can over ride this to prevent default removal.
1042 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::OnButtonVisualRemoval index(%d)\n", visualIndex );
1043 RemoveVisual( visualIndex );
1046 void Button::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
1048 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1050 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty index[%d]\n", index );
1056 case Toolkit::Button::Property::DISABLED:
1058 GetImplementation( button ).SetDisabled( value.Get< bool >() );
1062 case Toolkit::Button::Property::AUTO_REPEATING:
1064 GetImplementation( button ).SetAutoRepeating( value.Get< bool >() );
1068 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1070 GetImplementation( button ).SetInitialAutoRepeatingDelay( value.Get< float >() );
1074 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1076 GetImplementation( button ).SetNextAutoRepeatingDelay( value.Get< float >() );
1080 case Toolkit::Button::Property::TOGGLABLE:
1082 GetImplementation( button ).SetTogglableButton( value.Get< bool >() );
1086 case Toolkit::Button::Property::SELECTED:
1088 GetImplementation( button ).SetSelected( value.Get< bool >() );
1092 case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE: // Legacy Tizen 3.0
1094 GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
1097 case Toolkit::Button::Property::DISABLED_STATE_IMAGE: // Legacy Tizen 3.0
1099 GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, value, DepthIndex::CONTENT );
1102 case Toolkit::Button::Property::SELECTED_STATE_IMAGE: // Legacy Tizen 3.0
1104 GetImplementation( button ).CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, value, DepthIndex::CONTENT );
1107 case Toolkit::Button::Property::UNSELECTED_VISUAL:
1108 case Toolkit::Button::Property::SELECTED_VISUAL:
1109 case Toolkit::Button::Property::DISABLED_SELECTED_VISUAL:
1110 case Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL:
1112 GetImplementation( button ).CreateVisualsForComponent( index, value, DepthIndex::CONTENT );
1116 case Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL:
1117 case Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL:
1118 case Toolkit::Button::Property::DISABLED_SELECTED_BACKGROUND_VISUAL:
1119 case Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL:
1121 GetImplementation( button ).CreateVisualsForComponent( index , value, DepthIndex::BACKGROUND);
1125 case Toolkit::Button::Property::UNSELECTED_COLOR:
1127 DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::UNSELECTED_COLOR instead use Button::Property::UNSELECTED_BACKGROUND_VISUAL\n", __FUNCTION__);
1128 GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL );
1132 case Toolkit::Button::Property::SELECTED_COLOR:
1134 DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::SELECTED_COLOR instead use Button::Property::SELECTED_BACKGROUND_VISUAL\n", __FUNCTION__);
1135 GetImplementation( button ).SetColor( value.Get< Vector4 >(), Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL );
1139 case Toolkit::Button::Property::LABEL_TEXT:
1141 DALI_LOG_WARNING("[%s] Using deprecated Property Button::Property::LABEL_TEXT instead use Button::Property::LABEL\n", __FUNCTION__);
1142 Property::Map labelTextProperty;
1143 labelTextProperty.Insert( "text", value.Get< std::string >() );
1144 GetImplementation( button ).SetupLabel( labelTextProperty );
1148 case Toolkit::Button::Property::LABEL:
1150 // Get a Property::Map from the property if possible.
1151 Property::Map setPropertyMap;
1152 if( value.Get( setPropertyMap ) )
1154 GetImplementation( button ).SetupLabel( setPropertyMap );
1159 case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
1161 Button::Align labelAlignment(END);
1162 Scripting::GetEnumeration< Button::Align> ( value.Get< std::string >().c_str(),
1163 ALIGNMENT_TABLE, ALIGNMENT_TABLE_COUNT,
1166 GetImplementation( button ).SetLabelAlignment( labelAlignment );
1173 Property::Value Button::GetProperty( BaseObject* object, Property::Index propertyIndex )
1175 Property::Value value;
1177 Toolkit::Button button = Toolkit::Button::DownCast( Dali::BaseHandle( object ) );
1181 switch ( propertyIndex )
1183 case Toolkit::Button::Property::DISABLED:
1185 value = GetImplementation( button ).IsDisabled();
1189 case Toolkit::Button::Property::AUTO_REPEATING:
1191 value = GetImplementation( button ).mAutoRepeating;
1195 case Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY:
1197 value = GetImplementation( button ).mInitialAutoRepeatingDelay;
1201 case Toolkit::Button::Property::NEXT_AUTO_REPEATING_DELAY:
1203 value = GetImplementation( button ).mNextAutoRepeatingDelay;
1207 case Toolkit::Button::Property::TOGGLABLE:
1209 value = GetImplementation( button ).mTogglableButton;
1213 case Toolkit::Button::Property::SELECTED:
1215 value = GetImplementation( button ).IsSelected();
1219 case Toolkit::Button::Property::UNSELECTED_STATE_IMAGE:
1221 value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL );
1225 case Toolkit::Button::Property::SELECTED_STATE_IMAGE:
1227 value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL );
1231 case Toolkit::Button::Property::DISABLED_STATE_IMAGE:
1233 value = GetImplementation( button ).GetUrlForImageVisual( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL );
1237 case Toolkit::Button::Property::UNSELECTED_COLOR:
1239 value = GetImplementation( button ).GetUnselectedColor();
1243 case Toolkit::Button::Property::SELECTED_COLOR:
1245 value = GetImplementation( button ).GetSelectedColor();
1249 case Toolkit::Button::Property::LABEL_TEXT:
1251 value = GetImplementation( button ).GetLabelText();
1255 case Toolkit::Button::Property::LABEL:
1257 Property::Map emptyMap;
1262 case Toolkit::Button::Property::LABEL_STRUT_LENGTH:
1264 value = GetImplementation( button ).GetLabelStrutLength();
1268 case Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT:
1270 const char* alignment = Scripting::GetEnumerationName< Button::Align >( GetImplementation( button ).GetLabelAlignment(),
1271 ALIGNMENT_STRING_TABLE,
1272 ALIGNMENT_STRING_TABLE_COUNT );
1275 value = std::string( alignment );
1286 void Button::SetLabelPadding( const Padding& padding)
1288 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetLabelPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top );
1289 mLabelPadding = Padding( padding.left, padding.right, padding.bottom, padding.top );
1293 Padding Button::GetLabelPadding()
1295 return mLabelPadding;
1298 void Button::SetForegroundPadding( const Padding& padding)
1300 DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetForegroundPadding padding(%f,%f,%f,%f)\n", padding.left, padding.right, padding.bottom, padding.top );
1301 mForegroundPadding = Padding( padding.left, padding.right, padding.bottom, padding.top );
1305 Padding Button::GetForegroundPadding()
1307 return mForegroundPadding;
1310 ////////////////////////////////////////////////////////////////////////
1311 // Legacy functions from Tizen 2.4 and 3.0
1313 // Legacy code needed whilst Color can be set by direct Property setting ( deprecated ) instead of setting a Visual
1314 void Button::SetColor( const Vector4& color, Property::Index visualIndex )
1316 if ( visualIndex == Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL )
1318 mSelectedColor = color;
1322 mUnselectedColor = color;
1326 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
1327 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
1329 CreateVisualsForComponent( visualIndex, map, DepthIndex::BACKGROUND );
1332 const Vector4 Button::GetUnselectedColor() const
1334 return mUnselectedColor;
1337 const Vector4 Button::GetSelectedColor() const
1339 return mSelectedColor;
1342 void Button::SetAnimationTime( float animationTime )
1344 // Used by deprecated API
1345 mAnimationTime = animationTime;
1348 float Button::GetAnimationTime() const
1350 // Used by deprecated API
1351 return mAnimationTime;
1354 void Button::SetLabel( Actor label )
1358 Property::Value value ="";
1359 value = label.GetProperty(Toolkit::TextLabel::Property::TEXT);
1361 SetLabelText( value.Get<std::string>() );
1365 void Button::SetUnselectedImage( const std::string& filename )
1367 if( !filename.empty() )
1369 CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
1373 void Button::SetBackgroundImage( const std::string& filename )
1375 if( !filename.empty() )
1377 CreateVisualsForComponent( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
1381 void Button::SetSelectedImage( const std::string& filename )
1383 if( !filename.empty() )
1385 CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_VISUAL, filename, DepthIndex::CONTENT );
1389 void Button::SetSelectedBackgroundImage( const std::string& filename )
1391 if( !filename.empty() )
1393 CreateVisualsForComponent( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
1397 void Button::SetDisabledBackgroundImage( const std::string& filename )
1399 if( !filename.empty() )
1401 CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL, filename, DepthIndex::BACKGROUND );
1405 void Button::SetDisabledImage( const std::string& filename )
1407 if( !filename.empty() )
1409 CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_UNSELECTED_VISUAL, filename, DepthIndex::CONTENT );
1413 void Button::SetDisabledSelectedImage( const std::string& filename )
1415 if( !filename.empty() )
1417 CreateVisualsForComponent( Toolkit::Button::Property::DISABLED_SELECTED_VISUAL, filename, DepthIndex::CONTENT );
1421 std::string Button::GetUrlForImageVisual( const Property::Index index ) const
1423 Toolkit::Visual::Base visual = GetVisual( index );
1428 Dali::Property::Map retreivedMap;
1429 visual.CreatePropertyMap( retreivedMap );
1430 Property::Value* value = retreivedMap.Find( Toolkit::ImageVisual::Property::URL, Property::STRING );
1433 result = value->Get<std::string>();
1440 // Below functions DEPRECATED_1_0.50 - Return empty Actors
1444 std::string GetUrlFromImage( Image& image )
1446 ResourceImage resourceImage = ResourceImage::DownCast( image );
1448 std::string imageUrl;
1450 if ( resourceImage )
1452 imageUrl = resourceImage.GetUrl();
1460 void Button::SetButtonImage( Image image )
1462 DALI_LOG_WARNING("Button::SetButtonImage @DEPRECATED_1_0.50\n");
1463 SetUnselectedImage( GetUrlFromImage( image ) );
1466 void Button::SetSelectedImage( Image image )
1468 DALI_LOG_WARNING("Button::SetSelectedImage @DEPRECATED_1_0.50\n");
1469 SetSelectedImage( GetUrlFromImage( image ) );
1472 Actor Button::GetButtonImage() const
1474 DALI_LOG_WARNING("Button::GetButtonImage @DEPRECATED_1_0.50\n");
1475 Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::Button::Property::UNSELECTED_VISUAL ) );
1480 Actor Button::GetSelectedImage() const
1482 DALI_LOG_WARNING("Button::GetSelectedImage @DEPRECATED_1_0.50\n");
1483 Actor imageView = Toolkit::ImageView::New( GetUrlForImageVisual( Toolkit::Button::Property::SELECTED_VISUAL ) );
1488 } // namespace Internal
1490 } // namespace Toolkit