+ // Ignore if we are already at the target display state.
+ if( display == ( ( mDisplayState == Toolkit::Popup::SHOWING ) || ( mDisplayState == Toolkit::Popup::SHOWN ) ) )
+ {
+ return;
+ }
+
+ // Convert the bool state to the actual display state to use.
+ mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING;
+
+ if ( display )
+ {
+ // Update the state to indicate the current intent.
+ mDisplayState = Toolkit::Popup::SHOWING;
+
+ // We are displaying so bring the popup layer to the front, and set it visible so it is rendered.
+ mLayer.RaiseToTop();
+ mLayer.SetVisible( true );
+
+ // Set up the layout if this is the first display or the layout has become dirty.
+ if( mLayoutDirty )
+ {
+ // Bake-in any style and layout options to create the Popup layout.
+ LayoutPopup();
+ }
+
+ // Allow the popup to catch events.
+ mPopupLayout.SetSensitive( true );
+
+ // Handle the keyboard focus when popup is shown.
+ Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
+ if( keyboardFocusManager )
+ {
+ mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
+
+ if( Self().IsKeyboardFocusable() )
+ {
+ // Setup the actgor to start focus from.
+ Actor focusActor;
+ if( mContent && mContent.IsKeyboardFocusable() )
+ {
+ // If the content is focusable, move the focus to the content.
+ focusActor = mContent;
+ }
+ else if( mFooter && mFooter.IsKeyboardFocusable() )
+ {
+ // If the footer is focusable, move the focus to the footer.
+ focusActor = mFooter;
+ }
+ else
+ {
+ DALI_LOG_WARNING( "There is no focusable in popup\n" );
+ }
+
+ if( focusActor )
+ {
+ SetKeyInputFocus();
+ keyboardFocusManager.SetCurrentFocusActor( focusActor );
+ }
+ }
+ }
+ }
+ else // Not visible.
+ {
+ mDisplayState = Toolkit::Popup::HIDING;
+ ClearKeyInputFocus();
+
+ // Restore the keyboard focus when popup is hidden.
+ if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
+ {
+ Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
+ if( keyboardFocusManager )
+ {
+ keyboardFocusManager.SetCurrentFocusActor( mPreviousFocusedActor );
+ }
+ }
+ }
+
+ // Perform animation.
+ StartTransitionAnimation( display );
+}
+
+Toolkit::Popup::DisplayState Popup::GetDisplayState() const
+{
+ return mDisplayState;
+}
+
+void Popup::LayoutPopup()
+{
+ mLayoutDirty = false;
+
+ /* When animating in, we want to respect the origin applied to Self().
+ * For example, if zooming, not only will the final result be anchored to the
+ * selected point, but the zoom will originate from this point also.
+ *
+ * EG: ParentOrigin::TOP_LEFT, AnchorPoint::TOP_LEFT :
+ *
+ * -------- --------
+ * |X| |XXX|
+ * |`` Animates |XXX|
+ * | to: |XXX|
+ * | |````
+ * | |
+ */
+ mPopupContainer.SetParentOrigin( Self().GetCurrentParentOrigin() );
+ mPopupContainer.SetAnchorPoint( Self().GetCurrentAnchorPoint() );
+
+ // If there is only a title, use less padding.
+ if( mTitle )
+ {
+ if( !mContent && !mFooter )
+ {
+ mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
+ }
+ else
+ {
+ mTitle.SetPadding( DEFAULT_TITLE_PADDING );
+ }
+ }
+
+ // Allow derived classes to perform any layout they may need to do.
+ OnLayoutSetup();
+
+ // Update background visibility.
+ mPopupContainer.SetVisible( !( !mFooter && mPopupLayout.GetChildCount() == 0 ) );
+
+ // Create / destroy / position the tail as needed.
+ LayoutTail();
+
+ // Setup any layout and initialisation required for the selected animation.
+ LayoutAnimation();
+
+ RelayoutRequest();
+}
+
+void Popup::LayoutTail()
+{
+ // Removes the tail actor.
+ if( mTailImage && mTailImage.GetParent() )
+ {
+ mTailImage.GetParent().Remove( mTailImage );
+ mTailImage.Reset();
+ }
+
+ if( !mTailVisible )
+ {
+ return;
+ }
+
+ const Vector3& position = GetTailPosition();
+ std::string image;
+
+ // depending on position of tail around ParentOrigin, a different tail image is used...
+ if( position.y < Math::MACHINE_EPSILON_1 )
+ {
+ image = mTailUpImage;
+ }
+ else if( position.y > 1.0f - Math::MACHINE_EPSILON_1 )
+ {
+ image = mTailDownImage;
+ }
+ else if( position.x < Math::MACHINE_EPSILON_1 )
+ {
+ image = mTailLeftImage;
+ }
+ else if( position.x > 1.0f - Math::MACHINE_EPSILON_1 )
+ {
+ image = mTailRightImage;
+ }
+
+ if( !image.empty() )
+ {
+ // Adds the tail actor.
+ Image tail = ResourceImage::New( image );
+ mTailImage = Toolkit::ImageView::New( tail );
+ mTailImage.SetName( "tailImage" );
+ const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position;
+ mTailImage.SetParentOrigin( position );
+ mTailImage.SetAnchorPoint( anchorPoint );
+
+ mPopupContainer.Add( mTailImage );
+ }
+}
+
+void Popup::SetContextualMode( Toolkit::Popup::ContextualMode mode )
+{
+ mContextualMode = mode;
+ mLayoutDirty = true;
+}
+
+Toolkit::Popup::ContextualMode Popup::GetContextualMode() const
+{
+ return mContextualMode;
+}
+
+Toolkit::Control Popup::CreateBacking()
+{
+ Toolkit::Control backing = Control::New();
+ backing.SetBackgroundColor( Vector4( mBackingColor.r, mBackingColor.g, mBackingColor.b, 1.0f ) );
+ backing.SetName( "popupBacking" );
+
+ // Must always be positioned top-left of stage, regardless of parent.
+ backing.SetInheritPosition(false);
+ backing.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+ // Always the full size of the stage.
+ backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+ backing.SetSize( Stage::GetCurrent().GetSize() );
+
+ // Catch events.
+ backing.SetSensitive( true );
+
+ // Default to being transparent.
+ backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
+ backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
+ backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
+ return backing;
+}
+
+Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal()
+{
+ return mTouchedOutsideSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShowingSignal()
+{
+ return mShowingSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::ShownSignal()
+{
+ return mShownSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::HidingSignal()
+{
+ return mHidingSignal;
+}
+
+Toolkit::Popup::DisplayStateChangeSignalType& Popup::HiddenSignal()
+{
+ return mHiddenSignal;
+}
+
+void Popup::SetTailVisibility( bool visible )
+{
+ mTailVisible = visible;
+ mLayoutDirty = true;
+}
+
+const bool Popup::IsTailVisible() const
+{
+ return mTailVisible;
+}
+
+void Popup::SetTailPosition( Vector3 position )
+{
+ mTailPosition = position;
+ mLayoutDirty = true;
+}
+
+const Vector3& Popup::GetTailPosition() const
+{
+ return mTailPosition;
+}
+
+void Popup::SetAnimationDuration( float duration )
+{
+ mAnimationDuration = duration;
+ mLayoutDirty = true;
+}
+
+float Popup::GetAnimationDuration() const
+{
+ return mAnimationDuration;
+}
+
+void Popup::SetAnimationMode( Toolkit::Popup::AnimationMode animationMode )
+{
+ mAnimationMode = animationMode;
+ mLayoutDirty = true;
+}
+
+Toolkit::Popup::AnimationMode Popup::GetAnimationMode() const
+{
+ return mAnimationMode;
+}
+
+void Popup::SetEntryAnimationData( const Property::Map& map )
+{
+ mEntryAnimationData.Clear();
+ Scripting::NewAnimation( map, mEntryAnimationData );
+}
+
+void Popup::SetExitAnimationData( const Property::Map& map )
+{
+ mExitAnimationData.Clear();
+ Scripting::NewAnimation( map, mExitAnimationData );
+}
+
+void Popup::SetAutoHideDelay( int delay )
+{
+ mAutoHideDelay = delay;
+}
+
+int Popup::GetAutoHideDelay() const
+{
+ return mAutoHideDelay;
+}
+
+void Popup::SetBackingEnabled( bool enabled )
+{
+ mBackingEnabled = enabled;
+ mLayoutDirty = true;
+}
+
+const bool Popup::IsBackingEnabled() const
+{
+ return mBackingEnabled;
+}
+
+void Popup::SetBackingColor( Vector4 color )
+{
+ mBackingColor = color;
+ mBacking.SetBackgroundColor( Vector4( color.r, color.g, color.b, 1.0f ) );
+ mLayoutDirty = true;
+}
+
+const Vector4& Popup::GetBackingColor() const
+{
+ return mBackingColor;
+}
+
+void Popup::SetTailUpImage( std::string image )
+{
+ mTailUpImage = image;
+ mLayoutDirty = true;
+}
+
+const std::string& Popup::GetTailUpImage() const
+{
+ return mTailUpImage;
+}
+
+void Popup::SetTailDownImage( std::string image )
+{
+ mTailDownImage = image;
+ mLayoutDirty = true;
+}
+
+const std::string& Popup::GetTailDownImage() const
+{
+ return mTailDownImage;
+}
+
+void Popup::SetTailLeftImage( std::string image )
+{
+ mTailLeftImage = image;
+ mLayoutDirty = true;
+}
+
+const std::string& Popup::GetTailLeftImage() const
+{
+ return mTailLeftImage;
+}
+
+void Popup::SetTailRightImage( std::string image )
+{
+ mTailRightImage = image;
+ mLayoutDirty = true;
+}
+
+const std::string& Popup::GetTailRightImage() const
+{
+ return mTailRightImage;
+}
+
+void Popup::SetTouchTransparent( bool enabled )
+{
+ mTouchTransparent = enabled;
+}
+
+const bool Popup::IsTouchTransparent() const
+{
+ return mTouchTransparent;
+}
+
+void Popup::SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
+{
+ Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
+
+ if ( popup )
+ {
+ Popup& popupImpl( GetImpl( popup ) );
+
+ switch ( propertyIndex )
+ {
+ case Toolkit::Popup::Property::TITLE:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetTitle( Scripting::NewActor( valueMap ) );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::CONTENT:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetContent( Scripting::NewActor( valueMap ) );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::FOOTER:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetFooter( Scripting::NewActor( valueMap ) );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::DISPLAY_STATE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Toolkit::Popup::DisplayState displayState( Toolkit::Popup::HIDDEN );
+ if( Scripting::GetEnumeration< Toolkit::Popup::DisplayState >( valueString.c_str(), DisplayStateTable, DisplayStateTableCount, displayState ) )
+ {
+ popupImpl.SetDisplayState( displayState );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
+ {
+ bool valueBool;
+ if( value.Get( valueBool ) )
+ {
+ popupImpl.SetTouchTransparent( valueBool );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_VISIBILITY:
+ {
+ bool valueBool;
+ if( value.Get( valueBool ) )
+ {
+ popupImpl.SetTailVisibility( valueBool );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_POSITION:
+ {
+ Vector3 valueVector3;
+ if( value.Get( valueVector3 ) )
+ {
+ popupImpl.SetTailPosition( valueVector3 );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::CONTEXTUAL_MODE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Toolkit::Popup::ContextualMode contextualMode( Toolkit::Popup::BELOW );
+ if( Scripting::GetEnumeration< Toolkit::Popup::ContextualMode >( valueString.c_str(), ContextualModeTable, ContextualModeTableCount, contextualMode ) )
+ {
+ popupImpl.SetContextualMode( contextualMode );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_DURATION:
+ {
+ float valueFloat;
+ if( value.Get( valueFloat ) )
+ {
+ popupImpl.SetAnimationDuration( valueFloat );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_MODE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Toolkit::Popup::AnimationMode animationMode( Toolkit::Popup::FADE );
+ if( Scripting::GetEnumeration< Toolkit::Popup::AnimationMode >( valueString.c_str(), AnimationModeTable, AnimationModeTableCount, animationMode ) )
+ {
+ popupImpl.SetAnimationMode( animationMode );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::ENTRY_ANIMATION:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetEntryAnimationData( valueMap );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::EXIT_ANIMATION:
+ {
+ Property::Map valueMap;
+ if( value.Get( valueMap ) )
+ {
+ popupImpl.SetExitAnimationData( valueMap );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
+ {
+ int valueInt;
+ if( value.Get( valueInt ) )
+ {
+ popupImpl.SetAutoHideDelay( valueInt );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_ENABLED:
+ {
+ bool valueBool;
+ if( value.Get( valueBool ) )
+ {
+ popupImpl.SetBackingEnabled( valueBool );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_COLOR:
+ {
+ Vector4 valueVector4;
+ if( value.Get( valueVector4 ) )
+ {
+ popupImpl.SetBackingColor( valueVector4 );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ Image image = ResourceImage::New( valueString );
+ if( image )
+ {
+ Toolkit::ImageView actor = Toolkit::ImageView::New( image );
+ popupImpl.SetPopupBackgroundImage( actor );
+ }
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_UP_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailUpImage( valueString );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailDownImage( valueString );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailLeftImage( valueString );
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
+ {
+ std::string valueString;
+ if( value.Get( valueString ) )
+ {
+ popupImpl.SetTailRightImage( valueString );
+ }
+ break;
+ }
+ }
+ }
+}
+
+Property::Value Popup::GetProperty( BaseObject* object, Property::Index propertyIndex )
+{
+ Property::Value value;
+
+ Toolkit::Popup popup = Toolkit::Popup::DownCast( Dali::BaseHandle( object ) );
+
+ if ( popup )
+ {
+ Popup& popupImpl( GetImpl( popup ) );
+
+ switch ( propertyIndex )
+ {
+ case Toolkit::Popup::Property::TITLE:
+ {
+ Property::Map map;
+ Scripting::CreatePropertyMap( popupImpl.GetTitle(), map );
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::CONTENT:
+ {
+ Property::Map map;
+ Scripting::CreatePropertyMap( popupImpl.GetContent(), map );
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::FOOTER:
+ {
+ Property::Map map;
+ Scripting::CreatePropertyMap( popupImpl.GetFooter(), map );
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::DISPLAY_STATE:
+ {
+ value = Scripting::GetLinearEnumerationName< Toolkit::Popup::DisplayState >( popupImpl.GetDisplayState(), DisplayStateTable, DisplayStateTableCount );
+ break;
+ }
+ case Toolkit::Popup::Property::TOUCH_TRANSPARENT:
+ {
+ value = popupImpl.IsTouchTransparent();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_VISIBILITY:
+ {
+ value = popupImpl.IsTailVisible();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_POSITION:
+ {
+ value = popupImpl.GetTailPosition();
+ break;
+ }
+ case Toolkit::Popup::Property::CONTEXTUAL_MODE:
+ {
+ value = Scripting::GetLinearEnumerationName< Toolkit::Popup::ContextualMode >( popupImpl.GetContextualMode(), ContextualModeTable, ContextualModeTableCount );
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_DURATION:
+ {
+ value = popupImpl.GetAnimationDuration();
+ break;
+ }
+ case Toolkit::Popup::Property::ANIMATION_MODE:
+ {
+ value = Scripting::GetLinearEnumerationName< Toolkit::Popup::AnimationMode >( popupImpl.GetAnimationMode(), AnimationModeTable, AnimationModeTableCount );
+ break;
+ }
+ case Toolkit::Popup::Property::ENTRY_ANIMATION:
+ {
+ // Note: Cannot retrieve property map from animation.
+ Property::Map map;
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::EXIT_ANIMATION:
+ {
+ // Note: Cannot retrieve property map from animation.
+ Property::Map map;
+ value = map;
+ break;
+ }
+ case Toolkit::Popup::Property::AUTO_HIDE_DELAY:
+ {
+ value = popupImpl.GetAutoHideDelay();
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_ENABLED:
+ {
+ value = popupImpl.IsBackingEnabled();
+ break;
+ }
+ case Toolkit::Popup::Property::BACKING_COLOR:
+ {
+ value = popupImpl.GetBackingColor();
+ break;
+ }
+ case Toolkit::Popup::Property::POPUP_BACKGROUND_IMAGE:
+ {
+ ResourceImage image = ResourceImage::DownCast( popupImpl.GetPopupBackgroundImage() );
+ if( image )
+ {
+ value = image.GetUrl();
+ }
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_UP_IMAGE:
+ {
+ value = popupImpl.GetTailUpImage();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_DOWN_IMAGE:
+ {
+ value = popupImpl.GetTailDownImage();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_LEFT_IMAGE:
+ {
+ value = popupImpl.GetTailLeftImage();
+ break;
+ }
+ case Toolkit::Popup::Property::TAIL_RIGHT_IMAGE:
+ {
+ value = popupImpl.GetTailRightImage();
+ break;
+ }
+ }
+ }
+
+ return value;
+}
+
+bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+{
+ Dali::BaseHandle handle( object );