1 #ifndef DALI_TOOLKIT_INTERNAL_POPUP_H
2 #define DALI_TOOLKIT_INTERNAL_POPUP_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/public-api/adaptor-framework/timer.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali/devel-api/animation/animation-data.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
30 #include <dali-toolkit/devel-api/controls/popup/popup.h>
31 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
44 typedef IntrusivePtr< Popup > PopupPtr;
47 * @copydoc Toolkit::Popup
49 class Popup : public Control
55 * @return A public handle to the newly allocated Popup.
57 static Dali::Toolkit::Popup New();
62 * @copydoc Toolkit::Popup::SetPopupBackgroundImage
64 void SetPopupBackgroundImage( Actor image );
67 * @copydoc Toolkit::Popup::GetPopupBackgroundImage
69 Actor GetPopupBackgroundImage() const;
72 * @copydoc Toolkit::Popup::SetTitle( Actor titleActor )
74 void SetTitle( Actor titleActor );
77 * @copydoc Toolkit::Popup::GetTitle
79 Actor GetTitle() const;
82 * @copydoc Toolkit::Popup::SetContent
84 void SetContent( Actor content );
87 * @copydoc Toolkit::Popup::GetContent
89 Actor GetContent() const;
92 * @copydoc Toolkit::Popup::SetFooter
94 void SetFooter( Actor control );
97 * @copydoc Toolkit::Popup::GetFooter
99 Actor GetFooter() const;
102 * @copydoc Toolkit::Popup::SetDisplayState
104 void SetDisplayState( Toolkit::Popup::DisplayState displayState );
107 * @copydoc Toolkit::Popup::GetDisplayState
109 Toolkit::Popup::DisplayState GetDisplayState() const;
112 * @copydoc Toolkit::Popup::SetTailVisibility
114 void SetTailVisibility( bool visible );
117 * @copydoc Toolkit::Popup::IsTailVisible
119 const bool IsTailVisible() const;
122 * @copydoc Toolkit::Popup::SetTailPosition
124 void SetTailPosition( Vector3 position );
127 * @copydoc Toolkit::Popup::GetTailPosition
129 const Vector3& GetTailPosition() const;
132 * @copydoc Toolkit::Popup::SetContextualMode
134 void SetContextualMode( Toolkit::Popup::ContextualMode mode );
137 * @copydoc Toolkit::Popup::GetContextualMode
139 Toolkit::Popup::ContextualMode GetContextualMode() const;
142 * @copydoc Toolkit::Popup::SetAnimationDuration
144 void SetAnimationDuration( float duration );
147 * @copydoc Toolkit::Popup::GetAnimationDuration
149 float GetAnimationDuration() const;
152 * @copydoc Toolkit::Popup::SetAnimationMode
154 void SetAnimationMode( Toolkit::Popup::AnimationMode animationMode );
157 * @copydoc Toolkit::Popup::GetAnimationMode
159 Toolkit::Popup::AnimationMode GetAnimationMode() const;
162 * @copydoc Toolkit::Popup::SetAutoHideDelay
164 void SetAutoHideDelay( int delay );
167 * @copydoc Toolkit::Popup::GetAutoHideDelay
169 int GetAutoHideDelay() const;
172 * @copydoc Toolkit::Popup::SetBackingEnabled
174 void SetBackingEnabled( bool enabled );
177 * @copydoc Toolkit::Popup::IsBackingEnabled
179 const bool IsBackingEnabled() const;
182 * @copydoc Toolkit::Popup::SetBackingColor
184 void SetBackingColor( Vector4 color );
187 * @copydoc Toolkit::Popup::GetBackingColor
189 const Vector4& GetBackingColor() const;
192 * @copydoc Toolkit::Popup::SetTailUpImage
194 void SetTailUpImage( std::string image );
197 * @copydoc Toolkit::Popup::GetTailUpImage
199 const std::string& GetTailUpImage() const;
202 * @copydoc Toolkit::Popup::SetTailDownImage
204 void SetTailDownImage( std::string image );
207 * @copydoc Toolkit::Popup::GetTailDownImage
209 const std::string& GetTailDownImage() const;
212 * @copydoc Toolkit::Popup::SetTailLeftImage
214 void SetTailLeftImage( std::string image );
217 * @copydoc Toolkit::Popup::GetTailLeftImage
219 const std::string& GetTailLeftImage() const;
222 * @copydoc Toolkit::Popup::SetTailRightImage
224 void SetTailRightImage( std::string image );
227 * @copydoc Toolkit::Popup::GetTailRightImage
229 const std::string& GetTailRightImage() const;
232 * Called when a property of an object of this type is set.
233 * @param[in] object The object whose property is set.
234 * @param[in] propertyIndex The property index.
235 * @param[in] value The new property value.
237 static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
240 * Called to retrieve a property of an object of this type.
241 * @param[in] object The object whose property is to be retrieved.
242 * @param[in] propertyIndex The property index.
243 * @return The current value of the property.
245 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
248 struct AccessibleImpl : public Control::Impl::AccessibleImpl
250 using Control::Impl::AccessibleImpl::AccessibleImpl;
252 Dali::Accessibility::States CalculateStates() override;
256 * Construct a new Popup.
261 * A reference counted object may only be deleted by calling Unreference()
268 * @brief Creates the layout of the popup, to be done just before showing for the first time.
269 * Also calls OnLayoutSetup() to allow derived classes to perform layout at this stage.
274 * @brief Creates or destroys the popup tail based on the current TAIL_DISPLAYED property.
275 * Also uses the TAIL_POSITION property to position it.
280 * @brief Performs any relative positioning required based on the current contextual mode, if set.
281 * If contextual mode is not enabled, this method has no effect.
282 * @param[in] size The Popups current size (can be accessed from within the OnRelayout() method).
284 void LayoutContext( const Vector2& size );
287 * @brief All transition-in animation setup and layout is done here.
288 * Different types of animation mode require different layouts to work,
289 * this function encapsulates anything animation-mode specific.
290 * This is called once for multiple displays/hides of the pops.
291 * It is only re-called when the layout becomes dirty.
293 void LayoutAnimation();
296 * @brief Initiates a transition-in or transition-out animation based
297 * on the current animation settings.
298 * @param[in] transitionIn True to perform a transition-in, false for transition out.
299 * @param[in] instantaneous Optional - If set to true will override the duration to provide an instant animation.
301 void StartTransitionAnimation( bool transitionIn, bool instantaneous = false );
304 * @brief Invoked once a display state change has completed.
306 void DisplayStateChangeComplete();
309 * @brief This is called when the auto-hide timer finishes.
310 * It performs a display-state change to HIDDEN.
311 * @return True as signal is consumed.
313 bool OnAutoHideTimeReached();
316 * @brief Create Dimmed Backing (covers all content behind the dialog).
318 * @return The backing control.
320 Toolkit::Control CreateBacking();
323 * @brief Creates the lower area within the popup.
328 * @brief Sets if the popup allows touch events to pass through or not.
330 * @param[in] enabled Set to true to make the popup touch-transparent.
332 void SetTouchTransparent( bool enabled );
335 * @brief Returns if the popup allows touch events to pass through or not.
337 * @return True if the popup is touch-transparent.
339 const bool IsTouchTransparent() const;
342 * @brief Allows the popup entry animation to be setup from a Property::Map that could
343 * originate, for example, from a JSON file.
345 * @param[in] map A Property::Map containing a description of an animation
347 void SetEntryAnimationData( const Property::Map& map );
350 * @brief Allows the popup exit animation to be setup from a Property::Map that could
351 * originate, for example, from a JSON file.
353 * @param[in] map A Property::Map containing a description of an animation
355 void SetExitAnimationData( const Property::Map& map );
358 * @briefs Updates the popup background's position and size.
360 void UpdateBackgroundPositionAndSize();
365 * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
367 Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
370 * @copydoc Dali::Toolkit::Popup::ShowingSignal()
372 Toolkit::Popup::DisplayStateChangeSignalType& ShowingSignal();
375 * @copydoc Dali::Toolkit::Popup::ShownSignal()
377 Toolkit::Popup::DisplayStateChangeSignalType& ShownSignal();
380 * @copydoc Dali::Toolkit::Popup::HidingSignal()
382 Toolkit::Popup::DisplayStateChangeSignalType& HidingSignal();
385 * @copydoc Dali::Toolkit::Popup::HiddenSignal()
387 Toolkit::Popup::DisplayStateChangeSignalType& HiddenSignal();
390 * Connects a callback function with the object's signals.
391 * @param[in] object The object providing the signal.
392 * @param[in] tracker Used to disconnect the signal.
393 * @param[in] signalName The signal to connect to.
394 * @param[in] functor A newly allocated FunctorDelegate.
395 * @return True if the signal was connected.
396 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
398 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
403 * Signal occurs when the State animation (transition from hide <-> show) finishes.
404 * @param[in] source The animation that just finished.
406 void OnDisplayChangeAnimationFinished( Animation& source );
409 * Signal occurs when the dimmed backing for the Popup is touched.
410 * @param[in] actor The Actor Touched
411 * @param[in] touch The Touch Data.
412 * @return Whether to consume event or not.
414 bool OnBackingTouched(Actor actor, const TouchEvent& touch);
417 * Signal occurs when a mouse wheel event occurs on the dimmed backing.
418 * @param[in] actor The Actor that got the wheel event.
419 * @param[in] event The Wheel Event.
420 * @return Whether to consume event or not.
422 bool OnBackingWheelEvent(Actor actor, const WheelEvent& event);
425 * Signal occurs when the dialog has been touched.
426 * @param[in] actor The Actor Touched
427 * @param[in] touch The Touch Data.
428 * @return Whether to consume event or not.
430 bool OnDialogTouched( Actor actor, const TouchEvent& touch );
433 * @copydoc Toolkit::Control::OnInitialize()
435 void OnInitialize() override;
438 * Called whenever the popup layout is re-set up.
439 * Normally due to a change in contents.
440 * Note: This is only done when the popup is shown.
442 virtual void OnLayoutSetup() {}
445 * Called when the popup is directly or indirectly parented to the stage.
447 void OnSceneConnection( int depth ) override;
450 * From Control; called after a child has been added to the owning actor.
451 * @param[in] child The child which has been added.
453 void OnChildAdd( Actor& child ) override;
456 * @copydoc Control::OnRelayOut()
458 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
461 * @copydoc Control::OnSetResizePolicy()
463 void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) override;
466 * @copydoc Control::GetNaturalSize()
468 Vector3 GetNaturalSize() override;
471 * @copydoc Control::GetHeightForWidth()
473 float GetHeightForWidth( float width ) override;
476 * @copydoc Control::GetWidthForHeight()
478 float GetWidthForHeight( float height ) override;
481 * @copydoc Control::OnKeyEvent()
483 bool OnKeyEvent( const KeyEvent& event ) override;
486 * @copydoc Control::GetNextKeyboardFocusableActor()
488 Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
493 * Recursively add any focusable actors or layout containers to the provided vector.
494 * Include the top level actor if it is a layout container.
496 * @param[in] parent The actor to start from
497 * @param[in/out] focusableActors The vector to add focusable actors to
499 void AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors );
502 * Recursively add any focusable actors or layout containers to the provided vector.
504 * @param[in] parent The actor to start from
505 * @param[in/out] focusableActors The vector to add focusable actors to
507 void AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors );
510 * Sets up the touch signals connections as required.
511 * @note This must be called after all the members have been created.
521 Popup& operator=(const Popup& rhs);
525 Toolkit::Popup::TouchedOutsideSignalType mTouchedOutsideSignal;
526 Toolkit::Popup::DisplayStateChangeSignalType mShowingSignal;
527 Toolkit::Popup::DisplayStateChangeSignalType mShownSignal;
528 Toolkit::Popup::DisplayStateChangeSignalType mHidingSignal;
529 Toolkit::Popup::DisplayStateChangeSignalType mHiddenSignal;
531 Layer mLayer; ///< Popup Layer (i.e. Dim backing and PopupBg reside in this).
532 Toolkit::TableView mPopupLayout; ///< Popup Background (i.e. dialog reside in this).
533 Toolkit::Control mBacking; ///< Backing actor (dim effect).
534 Actor mPreviousFocusedActor; ///< Store the previous focused actor to restore the focus when popup hide.
535 Actor mTailImage; ///< Stores the tail image.
536 Actor mPopupContainer; ///< This actor is used to house the background image and the main popup layout.
537 Animation mAnimation; ///< The current animation in use used to manage display state changing.
538 bool mAlterAddedChild; ///< Flag used to control whether children are reparented or not.
539 bool mLayoutDirty; ///< Set to true whenever any property that would require a layout update is modified.
540 Timer mAutoHideTimer; ///< Used to perform an auto-hide of the popup if desired.
541 bool mTouchTransparent; ///< Allows all events to pass through the popup.
543 // Main Content related properties:
544 Actor mTitle; ///< Stores the text title.
545 Actor mContent; ///< Stores the unselected content.
546 Actor mFooter; ///< Stores the footer content (typically controls).
548 // Display related properties.
549 Toolkit::Popup::DisplayState mDisplayState; ///< The current display state of the popup.
550 bool mTailVisible; ///< True if the popup tail should be visible.
551 Vector3 mTailPosition; ///< The position of the tail.
552 Toolkit::Popup::ContextualMode mContextualMode; ///< Allows the popup to be layed out adjacent to its parent in different directions.
553 float mAnimationDuration; ///< The duration of the transition in and out animations.
554 Toolkit::Popup::AnimationMode mAnimationMode; ///< The animation to use to transition in and out.
555 Dali::AnimationData mEntryAnimationData; ///< Stores description data that can be used for generating a custom entry animation.
556 Dali::AnimationData mExitAnimationData; ///< Stores description data that can be used for generating a custom exit animation.
557 unsigned int mAutoHideDelay; ///< If set, will auto-hide the popup after a specified amount of time.
559 // Style related properties:
560 bool mBackingEnabled; ///< True if a dimmed backing will be used.
561 Vector4 mBackingColor; ///< The color of the backing.
562 Actor mPopupBackgroundImage; ///< Stores the background image.
563 Rect<int> mBackgroundBorder; ///< Background border.
564 float mMargin; ///< Internal margin for popup contents.
565 std::string mTailUpImage; ///< Image used for the tail for the up direction.
566 std::string mTailDownImage; ///< Image used for the tail for the down direction.
567 std::string mTailLeftImage; ///< Image used for the tail for the left direction.
568 std::string mTailRightImage; ///< Image used for the tail for the right direction.
571 } // namespace Internal
573 // Helpers for public-api forwarding methods
575 inline Toolkit::Internal::Popup& GetImpl( Toolkit::Popup& publicObject )
577 DALI_ASSERT_ALWAYS( publicObject );
579 Dali::RefObject& handle = publicObject.GetImplementation();
581 return static_cast<Toolkit::Internal::Popup&>( handle );
584 inline const Toolkit::Internal::Popup& GetImpl( const Toolkit::Popup& publicObject )
586 DALI_ASSERT_ALWAYS( publicObject );
588 const Dali::RefObject& handle = publicObject.GetImplementation();
590 return static_cast<const Toolkit::Internal::Popup&>( handle );
593 } // namespace Toolkit
597 #endif // DALI_TOOLKIT_INTERNAL_POPUP_H