1 #ifndef __DALI_TOOLKIT_INTERNAL_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_POPUP_H__
5 * Copyright (c) 2016 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/public-api/controls/table-view/table-view.h>
30 #include <dali-toolkit/devel-api/controls/popup/popup.h>
43 typedef IntrusivePtr< Popup > PopupPtr;
46 * @copydoc Toolkit::Popup
48 class Popup : public Control
54 * @return A public handle to the newly allocated Popup.
56 static Dali::Toolkit::Popup New();
61 * @copydoc Toolkit::Popup::SetPopupBackgroundImage
63 void SetPopupBackgroundImage( Actor image );
66 * @copydoc Toolkit::Popup::GetPopupBackgroundImage
68 Actor GetPopupBackgroundImage() const;
71 * @copydoc Toolkit::Popup::SetTitle( Actor titleActor )
73 void SetTitle( Actor titleActor );
76 * @copydoc Toolkit::Popup::GetTitle
78 Actor GetTitle() const;
81 * @copydoc Toolkit::Popup::SetContent
83 void SetContent( Actor content );
86 * @copydoc Toolkit::Popup::GetContent
88 Actor GetContent() const;
91 * @copydoc Toolkit::Popup::SetFooter
93 void SetFooter( Actor control );
96 * @copydoc Toolkit::Popup::GetFooter
98 Actor GetFooter() const;
101 * @copydoc Toolkit::Popup::SetDisplayState
103 void SetDisplayState( Toolkit::Popup::DisplayState displayState );
106 * @copydoc Toolkit::Popup::GetDisplayState
108 Toolkit::Popup::DisplayState GetDisplayState() const;
111 * @copydoc Toolkit::Popup::SetTailVisibility
113 void SetTailVisibility( bool visible );
116 * @copydoc Toolkit::Popup::IsTailVisible
118 const bool IsTailVisible() const;
121 * @copydoc Toolkit::Popup::SetTailPosition
123 void SetTailPosition( Vector3 position );
126 * @copydoc Toolkit::Popup::GetTailPosition
128 const Vector3& GetTailPosition() const;
131 * @copydoc Toolkit::Popup::SetContextualMode
133 void SetContextualMode( Toolkit::Popup::ContextualMode mode );
136 * @copydoc Toolkit::Popup::GetContextualMode
138 Toolkit::Popup::ContextualMode GetContextualMode() const;
141 * @copydoc Toolkit::Popup::SetAnimationDuration
143 void SetAnimationDuration( float duration );
146 * @copydoc Toolkit::Popup::GetAnimationDuration
148 float GetAnimationDuration() const;
151 * @copydoc Toolkit::Popup::SetAnimationMode
153 void SetAnimationMode( Toolkit::Popup::AnimationMode animationMode );
156 * @copydoc Toolkit::Popup::GetAnimationMode
158 Toolkit::Popup::AnimationMode GetAnimationMode() const;
161 * @copydoc Toolkit::Popup::SetAutoHideDelay
163 void SetAutoHideDelay( int delay );
166 * @copydoc Toolkit::Popup::GetAutoHideDelay
168 int GetAutoHideDelay() const;
171 * @copydoc Toolkit::Popup::SetBackingEnabled
173 void SetBackingEnabled( bool enabled );
176 * @copydoc Toolkit::Popup::IsBackingEnabled
178 const bool IsBackingEnabled() const;
181 * @copydoc Toolkit::Popup::SetBackingColor
183 void SetBackingColor( Vector4 color );
186 * @copydoc Toolkit::Popup::GetBackingColor
188 const Vector4& GetBackingColor() const;
191 * @copydoc Toolkit::Popup::SetTailUpImage
193 void SetTailUpImage( std::string image );
196 * @copydoc Toolkit::Popup::GetTailUpImage
198 const std::string& GetTailUpImage() const;
201 * @copydoc Toolkit::Popup::SetTailDownImage
203 void SetTailDownImage( std::string image );
206 * @copydoc Toolkit::Popup::GetTailDownImage
208 const std::string& GetTailDownImage() const;
211 * @copydoc Toolkit::Popup::SetTailLeftImage
213 void SetTailLeftImage( std::string image );
216 * @copydoc Toolkit::Popup::GetTailLeftImage
218 const std::string& GetTailLeftImage() const;
221 * @copydoc Toolkit::Popup::SetTailRightImage
223 void SetTailRightImage( std::string image );
226 * @copydoc Toolkit::Popup::GetTailRightImage
228 const std::string& GetTailRightImage() const;
231 * Called when a property of an object of this type is set.
232 * @param[in] object The object whose property is set.
233 * @param[in] propertyIndex The property index.
234 * @param[in] value The new property value.
236 static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
239 * Called to retrieve a property of an object of this type.
240 * @param[in] object The object whose property is to be retrieved.
241 * @param[in] propertyIndex The property index.
242 * @return The current value of the property.
244 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
249 * Construct a new Popup.
254 * A reference counted object may only be deleted by calling Unreference()
261 * @brief Creates the layout of the popup, to be done just before showing for the first time.
262 * Also calls OnLayoutSetup() to allow derived classes to perform layout at this stage.
267 * @brief Creates or destroys the popup tail based on the current TAIL_DISPLAYED property.
268 * Also uses the TAIL_POSITION property to position it.
273 * @brief Performs any relative positioning required based on the current contextual mode, if set.
274 * If contextual mode is not enabled, this method has no effect.
275 * @param[in] size The Popups current size (can be accessed from within the OnRelayout() method).
277 void LayoutContext( const Vector2& size );
280 * @brief All transition-in animation setup and layout is done here.
281 * Different types of animation mode require different layouts to work,
282 * this function encapsulates anything animation-mode specific.
283 * This is called once for multiple displays/hides of the pops.
284 * It is only re-called when the layout becomes dirty.
286 void LayoutAnimation();
289 * @brief Initiates a transition-in or transition-out animation based
290 * on the current animation settings.
291 * @param[in] transitionIn True to perform a transition-in, false for transition out.
292 * @param[in] instantaneous Optional - If set to true will override the duration to provide an instant animation.
294 void StartTransitionAnimation( bool transitionIn, bool instantaneous = false );
297 * @brief Invoked once a display state change has completed.
299 void DisplayStateChangeComplete();
302 * @brief This is called when the auto-hide timer finishes.
303 * It performs a display-state change to HIDDEN.
304 * @return True as signal is consumed.
306 bool OnAutoHideTimeReached();
309 * @brief Create Dimmed Backing (covers all content behind the dialog).
311 * @return The backing control.
313 Toolkit::Control CreateBacking();
316 * @brief Creates the lower area within the popup.
321 * @brief Sets if the popup allows touch events to pass through or not.
323 * @param[in] enabled Set to true to make the popup touch-transparent.
325 void SetTouchTransparent( bool enabled );
328 * @brief Returns if the popup allows touch events to pass through or not.
330 * @return True if the popup is touch-transparent.
332 const bool IsTouchTransparent() const;
335 * @brief Allows the popup entry animation to be setup from a Property::Map that could
336 * originate, for example, from a JSON file.
338 * @param[in] map A Property::Map containing a description of an animation
340 void SetEntryAnimationData( const Property::Map& map );
343 * @brief Allows the popup exit animation to be setup from a Property::Map that could
344 * originate, for example, from a JSON file.
346 * @param[in] map A Property::Map containing a description of an animation
348 void SetExitAnimationData( const Property::Map& map );
351 * @briefs Updates the popup background's position and size.
353 void UpdateBackgroundPositionAndSize();
358 * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
360 Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
363 * @copydoc Dali::Toolkit::Popup::ShowingSignal()
365 Toolkit::Popup::DisplayStateChangeSignalType& ShowingSignal();
368 * @copydoc Dali::Toolkit::Popup::ShownSignal()
370 Toolkit::Popup::DisplayStateChangeSignalType& ShownSignal();
373 * @copydoc Dali::Toolkit::Popup::HidingSignal()
375 Toolkit::Popup::DisplayStateChangeSignalType& HidingSignal();
378 * @copydoc Dali::Toolkit::Popup::HiddenSignal()
380 Toolkit::Popup::DisplayStateChangeSignalType& HiddenSignal();
383 * Connects a callback function with the object's signals.
384 * @param[in] object The object providing the signal.
385 * @param[in] tracker Used to disconnect the signal.
386 * @param[in] signalName The signal to connect to.
387 * @param[in] functor A newly allocated FunctorDelegate.
388 * @return True if the signal was connected.
389 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
391 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
396 * Signal occurs when the State animation (transition from hide <-> show) finishes.
397 * @param[in] source The animation that just finished.
399 void OnDisplayChangeAnimationFinished( Animation& source );
402 * Signal occurs when the dimmed backing for the Popup is touched.
403 * @param[in] actor The Actor Touched
404 * @param[in] touch The Touch Data.
405 * @return Whether to consume event or not.
407 bool OnBackingTouched(Actor actor, const TouchData& touch);
410 * Signal occurs when a mouse wheel event occurs on the dimmed backing.
411 * @param[in] actor The Actor that got the wheel event.
412 * @param[in] event The Wheel Event.
413 * @return Whether to consume event or not.
415 bool OnBackingWheelEvent(Actor actor, const WheelEvent& event);
418 * Signal occurs when the dialog has been touched.
419 * @param[in] actor The Actor Touched
420 * @param[in] touch The Touch Data.
421 * @return Whether to consume event or not.
423 bool OnDialogTouched( Actor actor, const TouchData& touch );
426 * @copydoc Toolkit::Control::OnInitialize()
428 virtual void OnInitialize();
431 * Called whenever the popup layout is re-set up.
432 * Normally due to a change in contents.
433 * Note: This is only done when the popup is shown.
435 virtual void OnLayoutSetup() {}
438 * Called when the popup is directly or indirectly parented to the stage.
440 virtual void OnStageConnection( int depth );
443 * From Control; called after a child has been added to the owning actor.
444 * @param[in] child The child which has been added.
446 virtual void OnChildAdd( Actor& child );
449 * @copydoc Control::OnRelayOut()
451 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
454 * @copydoc Control::OnSetResizePolicy()
456 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
459 * @copydoc Control::GetNaturalSize()
461 virtual Vector3 GetNaturalSize();
464 * @copydoc Control::GetHeightForWidth()
466 virtual float GetHeightForWidth( float width );
469 * @copydoc Control::GetWidthForHeight()
471 virtual float GetWidthForHeight( float height );
474 * @copydoc Control::OnKeyEvent()
476 virtual bool OnKeyEvent( const KeyEvent& event );
479 * @copydoc Control::GetNextKeyboardFocusableActor()
481 Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
486 * Recursively add any focusable actors or layout containers to the provided vector.
487 * Include the top level actor if it is a layout container.
489 * @param[in] parent The actor to start from
490 * @param[in/out] focusableActors The vector to add focusable actors to
492 void AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors );
495 * Recursively add any focusable actors or layout containers to the provided vector.
497 * @param[in] parent The actor to start from
498 * @param[in/out] focusableActors The vector to add focusable actors to
500 void AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors );
508 Popup& operator=(const Popup& rhs);
512 Toolkit::Popup::TouchedOutsideSignalType mTouchedOutsideSignal;
513 Toolkit::Popup::DisplayStateChangeSignalType mShowingSignal;
514 Toolkit::Popup::DisplayStateChangeSignalType mShownSignal;
515 Toolkit::Popup::DisplayStateChangeSignalType mHidingSignal;
516 Toolkit::Popup::DisplayStateChangeSignalType mHiddenSignal;
518 Layer mLayer; ///< Popup Layer (i.e. Dim backing and PopupBg reside in this).
519 Toolkit::TableView mPopupLayout; ///< Popup Background (i.e. dialog reside in this).
520 Toolkit::Control mBacking; ///< Backing actor (dim effect).
521 Actor mPreviousFocusedActor; ///< Store the previous focused actor to restore the focus when popup hide.
522 Actor mTailImage; ///< Stores the tail image.
523 Actor mPopupContainer; ///< This actor is used to house the background image and the main popup layout.
524 Animation mAnimation; ///< The current animation in use used to manage display state changing.
525 bool mAlterAddedChild; ///< Flag used to control whether children are reparented or not.
526 bool mLayoutDirty; ///< Set to true whenever any property that would require a layout update is modified.
527 Timer mAutoHideTimer; ///< Used to perform an auto-hide of the popup if desired.
528 bool mTouchTransparent; ///< Allows all events to pass through the popup.
530 // Main Content related properties:
531 Actor mTitle; ///< Stores the text title.
532 Actor mContent; ///< Stores the unselected content.
533 Actor mFooter; ///< Stores the footer content (typically controls).
535 // Display related properties.
536 Toolkit::Popup::DisplayState mDisplayState; ///< The current display state of the popup.
537 bool mTailVisible; ///< True if the popup tail should be visible.
538 Vector3 mTailPosition; ///< The position of the tail.
539 Toolkit::Popup::ContextualMode mContextualMode; ///< Allows the popup to be layed out adjacent to its parent in different directions.
540 float mAnimationDuration; ///< The duration of the transition in and out animations.
541 Toolkit::Popup::AnimationMode mAnimationMode; ///< The animation to use to transition in and out.
542 Dali::AnimationData mEntryAnimationData; ///< Stores description data that can be used for generating a custom entry animation.
543 Dali::AnimationData mExitAnimationData; ///< Stores description data that can be used for generating a custom exit animation.
544 unsigned int mAutoHideDelay; ///< If set, will auto-hide the popup after a specified amount of time.
546 // Style related properties:
547 bool mBackingEnabled; ///< True if a dimmed backing will be used.
548 Vector4 mBackingColor; ///< The color of the backing.
549 Actor mPopupBackgroundImage; ///< Stores the background image.
550 Rect<int> mBackgroundBorder; ///< Background border.
551 float mMargin; ///< Internal margin for popup contents.
552 std::string mTailUpImage; ///< Image used for the tail for the up direction.
553 std::string mTailDownImage; ///< Image used for the tail for the down direction.
554 std::string mTailLeftImage; ///< Image used for the tail for the left direction.
555 std::string mTailRightImage; ///< Image used for the tail for the right direction.
558 } // namespace Internal
560 // Helpers for public-api forwarding methods
562 inline Toolkit::Internal::Popup& GetImpl( Toolkit::Popup& publicObject )
564 DALI_ASSERT_ALWAYS( publicObject );
566 Dali::RefObject& handle = publicObject.GetImplementation();
568 return static_cast<Toolkit::Internal::Popup&>( handle );
571 inline const Toolkit::Internal::Popup& GetImpl( const Toolkit::Popup& publicObject )
573 DALI_ASSERT_ALWAYS( publicObject );
575 const Dali::RefObject& handle = publicObject.GetImplementation();
577 return static_cast<const Toolkit::Internal::Popup&>( handle );
580 } // namespace Toolkit
584 #endif // __DALI_TOOLKIT_INTERNAL_POPUP_H__