1 #ifndef __DALI_TOOLKIT_INTERNAL_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_POPUP_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/dali.h>
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/popup/popup.h>
24 #include <dali-toolkit/internal/controls/popup/popup-style-impl.h>
40 typedef IntrusivePtr<Popup> PopupPtr;
41 typedef IntrusivePtr<PopupStyle> PopupStylePtr;
44 * @copydoc Toolkit::Popup
46 class Popup : public Control
52 * @return A public handle to the newly allocated Popup.
54 static Dali::Toolkit::Popup New();
59 * Returns number of buttons added to Popup
61 * @return Number of buttons
63 size_t GetButtonCount() const;
66 * @copydoc Toolkit::Popup::SetBackgroundImage
68 void SetBackgroundImage( Actor image );
71 * @copydoc Toolkit::Popup::SetButtonAreaImage
73 void SetButtonAreaImage( Actor image );
76 * @copydoc Toolkit::Popup::SetTitle( const std::string& text );
78 void SetTitle( const std::string& text );
81 * @copydoc Toolkit::Popup::SetTitle( TextView titleActor )
83 void SetTitle( Toolkit::TextView titleActor );
86 * @copydoc Toolkit::Popup::GetTitle
88 Toolkit::TextView GetTitle() const;
91 * @copydoc Toolkit::Popup::AddButton
93 void AddButton( Toolkit::Button button );
96 * @copydoc Toolkit::Popup::SetState( PopupState state )
98 void SetState( Toolkit::Popup::PopupState state );
101 * @copydoc Toolkit::Popup::SetState( PopupState state, float duration )
103 void SetState( Toolkit::Popup::PopupState state, float duration );
106 * @copydoc Toolkit::Popup::GetState( )
108 Toolkit::Popup::PopupState GetState() const;
111 * @copydoc Toolkit::Popup::ShowTail
113 void ShowTail(const Vector3& position);
116 * @copydoc Toolkit::Popup::HideTail
122 * Sets the style of the popup
123 * @param[in] style The style of the popup
125 void SetStyle(PopupStyle& style);
128 * Gets the style of the popup
129 * @return style of the popup
131 PopupStylePtr GetStyle() const;
136 * Construct a new Popup.
137 * @param[in] style of the popup
139 Popup(PopupStyle& style);
142 * A reference counted object may only be deleted by calling Unreference()
149 * Creates and applies the default background image.
151 void SetDefaultBackgroundImage();
155 * (covers all content behind the dialog)
157 void CreateBacking();
161 * (dialog content resides inside this - buttons, title etc.)
166 * Animate Popup by scaling uniformally from 0 to 100% and vice versa (default behaviour)
167 * @param[in] state The desired state to change into.
168 * @param[in] duration The time for this animation to take.
170 void HandleStateChange( Toolkit::Popup::PopupState state, float duration );
173 * Invoked once StateChange has completed.
175 void HandleStateChangeComplete();
180 * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
182 Toolkit::Popup::TouchedOutsideSignalV2& OutsideTouchedSignal();
185 * @copydoc Dali::Toolkit::Popup::HiddenSignal()
187 Toolkit::Popup::HiddenSignalV2& HiddenSignal();
190 * Connects a callback function with the object's signals.
191 * @param[in] object The object providing the signal.
192 * @param[in] tracker Used to disconnect the signal.
193 * @param[in] signalName The signal to connect to.
194 * @param[in] functor A newly allocated FunctorDelegate.
195 * @return True if the signal was connected.
196 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
198 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
203 * Signal occurs when the State animation (transition from hide<->show) finishes
204 * @param[in] source The animation that just finished.
206 void OnStateAnimationFinished( Animation& source );
209 * Signal occurs when the dimmed backing for the Popup is touched.
210 * @param[in] actor The Actor Touched
211 * @param[in] event The Touch Event.
212 * @return Whether to consume event or not.
214 bool OnBackingTouched(Actor actor, const TouchEvent& event);
217 * Signal occurs when the mouse wheel event is occured on dimmed backing for the Popup.
218 * @param[in] actor The Actor got mouse wheel
219 * @param[in] event The Mouse Wheel Event.
220 * @return Whether to consume event or not.
222 bool OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event);
225 * Signal occurs when the dialog has been touched.
226 * @param[in] actor The Actor Touched
227 * @param[in] event The Touch Event.
228 * @return Whether to consume event or not.
230 bool OnDialogTouched(Actor actor, const TouchEvent& event);
233 * @copydoc Toolkit::Control::OnInitialize()
235 virtual void OnInitialize();
238 * @copydoc Dali::CustomActorImpl::OnPropertySet()
240 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
243 * From Control; called after a child has been added to the owning actor.
244 * @param[in] child The child which has been added.
246 virtual void OnControlChildAdd( Actor& child );
249 * @copydoc Control::OnRelaidOut()
251 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
254 * @copydoc Control::OnKeyEvent()
256 virtual bool OnKeyEvent(const KeyEvent& event);
259 * @copydoc Control::GetNaturalSize()
261 virtual Vector3 GetNaturalSize();
264 * @copydoc Control::GetHeightForWidth()
266 float GetHeightForWidth( float width );
269 * @copydoc Control::GetWidthForHeight()
271 float GetWidthForHeight( float height );
274 * @copydoc Control::GetNextKeyboardFocusableActor()
276 Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
284 Popup& operator=(const Popup& rhs);
291 Vector3 mContentSize;
292 Vector3 mButtonBgSize;
293 std::vector<Vector3> mButtonSize;
298 bool mShowing; ///< Popup is showing or not
300 Layer mLayer; ///< Popup Layer (i.e. Dim backing and PopupBg reside in this)
301 Actor mPopupBg; ///< Popup Background (i.e. dialog reside in this)
302 ImageActor mBacking; ///< Backing actor (dim effect)
304 Actor mPreviousFocusedActor; ///< Store the previous focused actor to restore the focus when popup hide
306 Actor mBackgroundImage; ///< Stores the background image.
307 Actor mButtonAreaImage; ///< Stores the button background image.
308 Toolkit::TextView mTitle; ///< Stores the text title.
309 Actor mContent; ///< Stores popup's content.
310 Actor mBottomBg; ///< bottom button bar background. ImageActor is replaced with Actor due to hidden image.
311 Actor mTailImage; ///< Stores the tail image
313 ActorContainer mButtons; ///< Keeps track of the buttons added to this popup.
314 Toolkit::Popup::PopupState mState; ///< Popup current state.
315 Animation mAnimation; ///< The animation instance managing state changing.
316 bool mAlterAddedChild; ///< Flag used to control whether children are reparented or not.
317 PopupStylePtr mPopupStyle; ///< The style to be used for this popup.
319 LayoutInfo mLayoutInfo; ///< Stores sizes of all popup components.
321 Toolkit::Popup::TouchedOutsideSignalV2 mTouchedOutsideSignalV2;
322 Toolkit::Popup::HiddenSignalV2 mHiddenSignalV2;
324 Property::Index mPropertyTitle; ///< Property index for Title.
325 Property::Index mPropertyState; ///< Property index for popup state.
328 } // namespace Internal
330 // Helpers for public-api forwarding methods
332 inline Toolkit::Internal::Popup& GetImpl(Toolkit::Popup& pub)
334 DALI_ASSERT_ALWAYS(pub);
336 Dali::RefObject& handle = pub.GetImplementation();
338 return static_cast<Toolkit::Internal::Popup&>(handle);
341 inline const Toolkit::Internal::Popup& GetImpl(const Toolkit::Popup& pub)
343 DALI_ASSERT_ALWAYS(pub);
345 const Dali::RefObject& handle = pub.GetImplementation();
347 return static_cast<const Toolkit::Internal::Popup&>(handle);
350 } // namespace Toolkit
354 #endif // __DALI_TOOLKIT_INTERNAL_POPUP_H__