1 #ifndef DALI_TOOLKIT_INTERNAL_POPUP_H
2 #define DALI_TOOLKIT_INTERNAL_POPUP_H
5 * Copyright (c) 2021 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/devel-api/animation/animation-data.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali/public-api/animation/animation.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/controls/popup/popup.h>
30 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
31 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
42 typedef IntrusivePtr<Popup> PopupPtr;
45 * @copydoc Toolkit::Popup
47 class Popup : public Control
52 * @return A public handle to the newly allocated Popup.
54 static Dali::Toolkit::Popup New();
58 * @copydoc Toolkit::Popup::SetPopupBackgroundImage
60 void SetPopupBackgroundImage(Actor image);
63 * @copydoc Toolkit::Popup::GetPopupBackgroundImage
65 Actor GetPopupBackgroundImage() const;
68 * @copydoc Toolkit::Popup::SetTitle( Actor titleActor )
70 void SetTitle(Actor titleActor);
73 * @copydoc Toolkit::Popup::GetTitle
75 Actor GetTitle() const;
78 * @copydoc Toolkit::Popup::SetContent
80 void SetContent(Actor content);
83 * @copydoc Toolkit::Popup::GetContent
85 Actor GetContent() const;
88 * @copydoc Toolkit::Popup::SetFooter
90 void SetFooter(Actor control);
93 * @copydoc Toolkit::Popup::GetFooter
95 Actor GetFooter() const;
98 * @copydoc Toolkit::Popup::SetDisplayState
100 void SetDisplayState(Toolkit::Popup::DisplayState displayState);
103 * @copydoc Toolkit::Popup::GetDisplayState
105 Toolkit::Popup::DisplayState GetDisplayState() const;
108 * @copydoc Toolkit::Popup::SetTailVisibility
110 void SetTailVisibility(bool visible);
113 * @copydoc Toolkit::Popup::IsTailVisible
115 const bool IsTailVisible() const;
118 * @copydoc Toolkit::Popup::SetTailPosition
120 void SetTailPosition(Vector3 position);
123 * @copydoc Toolkit::Popup::GetTailPosition
125 const Vector3& GetTailPosition() const;
128 * @copydoc Toolkit::Popup::SetContextualMode
130 void SetContextualMode(Toolkit::Popup::ContextualMode mode);
133 * @copydoc Toolkit::Popup::GetContextualMode
135 Toolkit::Popup::ContextualMode GetContextualMode() const;
138 * @copydoc Toolkit::Popup::SetAnimationDuration
140 void SetAnimationDuration(float duration);
143 * @copydoc Toolkit::Popup::GetAnimationDuration
145 float GetAnimationDuration() const;
148 * @copydoc Toolkit::Popup::SetAnimationMode
150 void SetAnimationMode(Toolkit::Popup::AnimationMode animationMode);
153 * @copydoc Toolkit::Popup::GetAnimationMode
155 Toolkit::Popup::AnimationMode GetAnimationMode() const;
158 * @copydoc Toolkit::Popup::SetAutoHideDelay
160 void SetAutoHideDelay(int delay);
163 * @copydoc Toolkit::Popup::GetAutoHideDelay
165 int GetAutoHideDelay() const;
168 * @copydoc Toolkit::Popup::SetBackingEnabled
170 void SetBackingEnabled(bool enabled);
173 * @copydoc Toolkit::Popup::IsBackingEnabled
175 const bool IsBackingEnabled() const;
178 * @copydoc Toolkit::Popup::SetBackingColor
180 void SetBackingColor(Vector4 color);
183 * @copydoc Toolkit::Popup::GetBackingColor
185 const Vector4& GetBackingColor() const;
188 * @copydoc Toolkit::Popup::SetTailUpImage
190 void SetTailUpImage(std::string image);
193 * @copydoc Toolkit::Popup::GetTailUpImage
195 const std::string& GetTailUpImage() const;
198 * @copydoc Toolkit::Popup::SetTailDownImage
200 void SetTailDownImage(std::string image);
203 * @copydoc Toolkit::Popup::GetTailDownImage
205 const std::string& GetTailDownImage() const;
208 * @copydoc Toolkit::Popup::SetTailLeftImage
210 void SetTailLeftImage(std::string image);
213 * @copydoc Toolkit::Popup::GetTailLeftImage
215 const std::string& GetTailLeftImage() const;
218 * @copydoc Toolkit::Popup::SetTailRightImage
220 void SetTailRightImage(std::string image);
223 * @copydoc Toolkit::Popup::GetTailRightImage
225 const std::string& GetTailRightImage() const;
228 * Called when a property of an object of this type is set.
229 * @param[in] object The object whose property is set.
230 * @param[in] propertyIndex The property index.
231 * @param[in] value The new property value.
233 static void SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value);
236 * Called to retrieve a property of an object of this type.
237 * @param[in] object The object whose property is to be retrieved.
238 * @param[in] propertyIndex The property index.
239 * @return The current value of the property.
241 static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
244 struct AccessibleImpl : public DevelControl::ControlAccessible
246 using DevelControl::ControlAccessible::ControlAccessible;
248 std::string GetNameRaw() const override;
249 Dali::Accessibility::States CalculateStates() override;
253 * Construct a new Popup.
258 * A reference counted object may only be deleted by calling Unreference()
264 * @brief Creates the layout of the popup, to be done just before showing for the first time.
265 * Also calls OnLayoutSetup() to allow derived classes to perform layout at this stage.
270 * @brief Creates or destroys the popup tail based on the current TAIL_DISPLAYED property.
271 * Also uses the TAIL_POSITION property to position it.
276 * @brief Performs any relative positioning required based on the current contextual mode, if set.
277 * If contextual mode is not enabled, this method has no effect.
278 * @param[in] size The Popups current size (can be accessed from within the OnRelayout() method).
280 void LayoutContext(const Vector2& size);
283 * @brief All transition-in animation setup and layout is done here.
284 * Different types of animation mode require different layouts to work,
285 * this function encapsulates anything animation-mode specific.
286 * This is called once for multiple displays/hides of the pops.
287 * It is only re-called when the layout becomes dirty.
289 void LayoutAnimation();
292 * @brief Initiates a transition-in or transition-out animation based
293 * on the current animation settings.
294 * @param[in] transitionIn True to perform a transition-in, false for transition out.
295 * @param[in] instantaneous Optional - If set to true will override the duration to provide an instant animation.
297 void StartTransitionAnimation(bool transitionIn, bool instantaneous = false);
300 * @brief Invoked once a display state change has completed.
302 void DisplayStateChangeComplete();
305 * @brief This is called when the auto-hide timer finishes.
306 * It performs a display-state change to HIDDEN.
307 * @return True as signal is consumed.
309 bool OnAutoHideTimeReached();
312 * @brief Create Dimmed Backing (covers all content behind the dialog).
314 * @return The backing control.
316 Toolkit::Control CreateBacking();
319 * @brief Creates the lower area within the popup.
324 * @brief Sets if the popup allows touch events to pass through or not.
326 * @param[in] enabled Set to true to make the popup touch-transparent.
328 void SetTouchTransparent(bool enabled);
331 * @brief Returns if the popup allows touch events to pass through or not.
333 * @return True if the popup is touch-transparent.
335 const bool IsTouchTransparent() const;
338 * @brief Allows the popup entry animation to be setup from a Property::Map that could
339 * originate, for example, from a JSON file.
341 * @param[in] map A Property::Map containing a description of an animation
343 void SetEntryAnimationData(const Property::Map& map);
346 * @brief Allows the popup exit animation to be setup from a Property::Map that could
347 * originate, for example, from a JSON file.
349 * @param[in] map A Property::Map containing a description of an animation
351 void SetExitAnimationData(const Property::Map& map);
354 * @briefs Updates the popup background's position and size.
356 void UpdateBackgroundPositionAndSize();
360 * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
362 Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
365 * @copydoc Dali::Toolkit::Popup::ShowingSignal()
367 Toolkit::Popup::DisplayStateChangeSignalType& ShowingSignal();
370 * @copydoc Dali::Toolkit::Popup::ShownSignal()
372 Toolkit::Popup::DisplayStateChangeSignalType& ShownSignal();
375 * @copydoc Dali::Toolkit::Popup::HidingSignal()
377 Toolkit::Popup::DisplayStateChangeSignalType& HidingSignal();
380 * @copydoc Dali::Toolkit::Popup::HiddenSignal()
382 Toolkit::Popup::DisplayStateChangeSignalType& HiddenSignal();
385 * Connects a callback function with the object's signals.
386 * @param[in] object The object providing the signal.
387 * @param[in] tracker Used to disconnect the signal.
388 * @param[in] signalName The signal to connect to.
389 * @param[in] functor A newly allocated FunctorDelegate.
390 * @return True if the signal was connected.
391 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
393 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
397 * Signal occurs when the State animation (transition from hide <-> show) finishes.
398 * @param[in] source The animation that just finished.
400 void OnDisplayChangeAnimationFinished(Animation& source);
403 * Signal occurs when the dimmed backing for the Popup is touched.
404 * @param[in] actor The Actor Touched
405 * @param[in] touch The Touch Data.
406 * @return Whether to consume event or not.
408 bool OnBackingTouched(Actor actor, const TouchEvent& touch);
411 * Signal occurs when a mouse wheel event occurs on the dimmed backing.
412 * @param[in] actor The Actor that got the wheel event.
413 * @param[in] event The Wheel Event.
414 * @return Whether to consume event or not.
416 bool OnBackingWheelEvent(Actor actor, const WheelEvent& event);
419 * Signal occurs when the dialog has been touched.
420 * @param[in] actor The Actor Touched
421 * @param[in] touch The Touch Data.
422 * @return Whether to consume event or not.
424 bool OnDialogTouched(Actor actor, const TouchEvent& touch);
427 * @copydoc Toolkit::Control::OnInitialize()
429 void OnInitialize() override;
432 * Called whenever the popup layout is re-set up.
433 * Normally due to a change in contents.
434 * Note: This is only done when the popup is shown.
436 virtual void OnLayoutSetup()
441 * Called when the popup is directly or indirectly parented to the stage.
443 void OnSceneConnection(int depth) override;
446 * From Control; called after a child has been added to the owning actor.
447 * @param[in] child The child which has been added.
449 void OnChildAdd(Actor& child) override;
452 * @copydoc Control::OnRelayOut()
454 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
457 * @copydoc Control::OnSetResizePolicy()
459 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
462 * @copydoc Control::GetNaturalSize()
464 Vector3 GetNaturalSize() override;
467 * @copydoc Control::GetHeightForWidth()
469 float GetHeightForWidth(float width) override;
472 * @copydoc Control::GetWidthForHeight()
474 float GetWidthForHeight(float height) override;
477 * @copydoc Control::OnKeyEvent()
479 bool OnKeyEvent(const KeyEvent& event) override;
482 * @copydoc Control::GetNextKeyboardFocusableActor()
484 Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled);
488 * Recursively add any focusable actors or layout containers to the provided vector.
489 * Include the top level actor if it is a layout container.
491 * @param[in] parent The actor to start from
492 * @param[in/out] focusableActors The vector to add focusable actors to
494 void AddFocusableChildren(Actor parent, std::vector<Actor>& focusableActors);
497 * Recursively add any focusable actors or layout containers to the provided vector.
499 * @param[in] parent The actor to start from
500 * @param[in/out] focusableActors The vector to add focusable actors to
502 void AddFocusableChildrenRecursive(Actor parent, std::vector<Actor>& focusableActors);
505 * Sets up the touch signals connections as required.
506 * @note This must be called after all the members have been created.
515 Popup& operator=(const Popup& rhs);
518 Toolkit::Popup::TouchedOutsideSignalType mTouchedOutsideSignal;
519 Toolkit::Popup::DisplayStateChangeSignalType mShowingSignal;
520 Toolkit::Popup::DisplayStateChangeSignalType mShownSignal;
521 Toolkit::Popup::DisplayStateChangeSignalType mHidingSignal;
522 Toolkit::Popup::DisplayStateChangeSignalType mHiddenSignal;
524 Layer mLayer; ///< Popup Layer (i.e. Dim backing and PopupBg reside in this).
525 Toolkit::TableView mPopupLayout; ///< Popup Background (i.e. dialog reside in this).
526 Toolkit::Control mBacking; ///< Backing actor (dim effect).
527 Actor mPreviousFocusedActor; ///< Store the previous focused actor to restore the focus when popup hide.
528 Actor mTailImage; ///< Stores the tail image.
529 Actor mPopupContainer; ///< This actor is used to house the background image and the main popup layout.
530 Animation mAnimation; ///< The current animation in use used to manage display state changing.
531 bool mAlterAddedChild; ///< Flag used to control whether children are reparented or not.
532 bool mLayoutDirty; ///< Set to true whenever any property that would require a layout update is modified.
533 Timer mAutoHideTimer; ///< Used to perform an auto-hide of the popup if desired.
534 bool mTouchTransparent; ///< Allows all events to pass through the popup.
536 // Main Content related properties:
537 Actor mTitle; ///< Stores the text title.
538 Actor mContent; ///< Stores the unselected content.
539 Actor mFooter; ///< Stores the footer content (typically controls).
541 // Display related properties.
542 Toolkit::Popup::DisplayState mDisplayState; ///< The current display state of the popup.
543 bool mTailVisible; ///< True if the popup tail should be visible.
544 Vector3 mTailPosition; ///< The position of the tail.
545 Toolkit::Popup::ContextualMode mContextualMode; ///< Allows the popup to be layed out adjacent to its parent in different directions.
546 float mAnimationDuration; ///< The duration of the transition in and out animations.
547 Toolkit::Popup::AnimationMode mAnimationMode; ///< The animation to use to transition in and out.
548 Dali::AnimationData mEntryAnimationData; ///< Stores description data that can be used for generating a custom entry animation.
549 Dali::AnimationData mExitAnimationData; ///< Stores description data that can be used for generating a custom exit animation.
550 unsigned int mAutoHideDelay; ///< If set, will auto-hide the popup after a specified amount of time.
552 // Style related properties:
553 bool mBackingEnabled; ///< True if a dimmed backing will be used.
554 Vector4 mBackingColor; ///< The color of the backing.
555 Actor mPopupBackgroundImage; ///< Stores the background image.
556 Rect<int> mBackgroundBorder; ///< Background border.
557 float mMargin; ///< Internal margin for popup contents.
558 std::string mTailUpImage; ///< Image used for the tail for the up direction.
559 std::string mTailDownImage; ///< Image used for the tail for the down direction.
560 std::string mTailLeftImage; ///< Image used for the tail for the left direction.
561 std::string mTailRightImage; ///< Image used for the tail for the right direction.
564 } // namespace Internal
566 // Helpers for public-api forwarding methods
568 inline Toolkit::Internal::Popup& GetImpl(Toolkit::Popup& publicObject)
570 DALI_ASSERT_ALWAYS(publicObject);
572 Dali::RefObject& handle = publicObject.GetImplementation();
574 return static_cast<Toolkit::Internal::Popup&>(handle);
577 inline const Toolkit::Internal::Popup& GetImpl(const Toolkit::Popup& publicObject)
579 DALI_ASSERT_ALWAYS(publicObject);
581 const Dali::RefObject& handle = publicObject.GetImplementation();
583 return static_cast<const Toolkit::Internal::Popup&>(handle);
586 } // namespace Toolkit
590 #endif // DALI_TOOLKIT_INTERNAL_POPUP_H