Remove OnControl methods & add up-calls
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / popup / popup-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_POPUP_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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>
26
27 // INTERNAL INCLUDES
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>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 class Popup;
42
43 typedef IntrusivePtr< Popup > PopupPtr;
44
45 /**
46  * @copydoc Toolkit::Popup
47  */
48 class Popup : public Control
49 {
50 public:
51
52   /**
53    * Create a new Popup.
54    * @return A public handle to the newly allocated Popup.
55    */
56   static Dali::Toolkit::Popup New();
57
58 public:
59
60   /**
61    * @copydoc Toolkit::Popup::SetPopupBackgroundImage
62    */
63   void SetPopupBackgroundImage( Actor image );
64
65   /**
66    * @copydoc Toolkit::Popup::GetPopupBackgroundImage
67    */
68   Actor GetPopupBackgroundImage() const;
69
70   /**
71    * @copydoc Toolkit::Popup::SetTitle( Actor titleActor )
72    */
73   void SetTitle( Actor titleActor );
74
75   /**
76    * @copydoc Toolkit::Popup::GetTitle
77    */
78   Actor GetTitle() const;
79
80   /**
81    * @copydoc Toolkit::Popup::SetContent
82    */
83   void SetContent( Actor content );
84
85   /**
86    * @copydoc Toolkit::Popup::GetContent
87    */
88   Actor GetContent() const;
89
90   /**
91    * @copydoc Toolkit::Popup::SetFooter
92    */
93   void SetFooter( Actor control );
94
95   /**
96    * @copydoc Toolkit::Popup::GetFooter
97    */
98   Actor GetFooter() const;
99
100   /**
101    * @copydoc Toolkit::Popup::SetDisplayState
102    */
103   void SetDisplayState( Toolkit::Popup::DisplayState displayState );
104
105   /**
106    * @copydoc Toolkit::Popup::GetDisplayState
107    */
108   Toolkit::Popup::DisplayState GetDisplayState() const;
109
110   /**
111    * @copydoc Toolkit::Popup::SetTailVisibility
112    */
113   void SetTailVisibility( bool visible );
114
115   /**
116    * @copydoc Toolkit::Popup::IsTailVisible
117    */
118   const bool IsTailVisible() const;
119
120   /**
121    * @copydoc Toolkit::Popup::SetTailPosition
122    */
123   void SetTailPosition( Vector3 position );
124
125   /**
126    * @copydoc Toolkit::Popup::GetTailPosition
127    */
128   const Vector3& GetTailPosition() const;
129
130   /**
131    * @copydoc Toolkit::Popup::SetContextualMode
132    */
133   void SetContextualMode( Toolkit::Popup::ContextualMode mode );
134
135   /**
136    * @copydoc Toolkit::Popup::GetContextualMode
137    */
138   Toolkit::Popup::ContextualMode GetContextualMode() const;
139
140   /**
141    * @copydoc Toolkit::Popup::SetAnimationDuration
142    */
143   void SetAnimationDuration( float duration );
144
145   /**
146    * @copydoc Toolkit::Popup::GetAnimationDuration
147    */
148   float GetAnimationDuration() const;
149
150   /**
151    * @copydoc Toolkit::Popup::SetAnimationMode
152    */
153   void SetAnimationMode( Toolkit::Popup::AnimationMode animationMode );
154
155   /**
156    * @copydoc Toolkit::Popup::GetAnimationMode
157    */
158   Toolkit::Popup::AnimationMode GetAnimationMode() const;
159
160   /**
161    * @copydoc Toolkit::Popup::SetAutoHideDelay
162    */
163   void SetAutoHideDelay( int delay );
164
165   /**
166    * @copydoc Toolkit::Popup::GetAutoHideDelay
167    */
168   int GetAutoHideDelay() const;
169
170   /**
171    * @copydoc Toolkit::Popup::SetBackingEnabled
172    */
173   void SetBackingEnabled( bool enabled );
174
175   /**
176    * @copydoc Toolkit::Popup::IsBackingEnabled
177    */
178   const bool IsBackingEnabled() const;
179
180   /**
181    * @copydoc Toolkit::Popup::SetBackingColor
182    */
183   void SetBackingColor( Vector4 color );
184
185   /**
186    * @copydoc Toolkit::Popup::GetBackingColor
187    */
188   const Vector4& GetBackingColor() const;
189
190   /**
191    * @copydoc Toolkit::Popup::SetTailUpImage
192    */
193   void SetTailUpImage( std::string image );
194
195   /**
196    * @copydoc Toolkit::Popup::GetTailUpImage
197    */
198   const std::string& GetTailUpImage() const;
199
200   /**
201    * @copydoc Toolkit::Popup::SetTailDownImage
202    */
203   void SetTailDownImage( std::string image );
204
205   /**
206    * @copydoc Toolkit::Popup::GetTailDownImage
207    */
208   const std::string& GetTailDownImage() const;
209
210   /**
211    * @copydoc Toolkit::Popup::SetTailLeftImage
212    */
213   void SetTailLeftImage( std::string image );
214
215   /**
216    * @copydoc Toolkit::Popup::GetTailLeftImage
217    */
218   const std::string& GetTailLeftImage() const;
219
220   /**
221    * @copydoc Toolkit::Popup::SetTailRightImage
222    */
223   void SetTailRightImage( std::string image );
224
225   /**
226    * @copydoc Toolkit::Popup::GetTailRightImage
227    */
228   const std::string& GetTailRightImage() const;
229
230   /**
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.
235    */
236   static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
237
238   /**
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.
243    */
244   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
245
246 protected:
247
248   /**
249    * Construct a new Popup.
250    */
251   Popup();
252
253   /**
254    * A reference counted object may only be deleted by calling Unreference()
255    */
256   virtual ~Popup();
257
258 private:
259
260   /**
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.
263    */
264   void LayoutPopup();
265
266   /**
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.
269    */
270   void LayoutTail();
271
272   /**
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).
276    */
277   void LayoutContext( const Vector2& size );
278
279   /**
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.
285    */
286   void LayoutAnimation();
287
288   /**
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.
293    */
294   void StartTransitionAnimation( bool transitionIn, bool instantaneous = false );
295
296   /**
297    * @brief Invoked once a display state change has completed.
298    */
299   void DisplayStateChangeComplete();
300
301   /**
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.
305    */
306   bool OnAutoHideTimeReached();
307
308   /**
309    * @brief Create Dimmed Backing (covers all content behind the dialog).
310    *
311    * @return The backing control.
312    */
313   Toolkit::Control CreateBacking();
314
315   /**
316    * @brief Creates the lower area within the popup.
317    */
318   void CreateFooter();
319
320   /**
321    * @brief Sets if the popup allows touch events to pass through or not.
322    *
323    * @param[in] enabled Set to true to make the popup touch-transparent.
324    */
325   void SetTouchTransparent( bool enabled );
326
327   /**
328    * @brief Returns if the popup allows touch events to pass through or not.
329    *
330    * @return True if the popup is touch-transparent.
331    */
332   const bool IsTouchTransparent() const;
333
334   /**
335    * @brief Allows the popup entry animation to be setup from a Property::Map that could
336    * originate, for example, from a JSON file.
337    *
338    * @param[in] map A Property::Map containing a description of an animation
339    */
340   void SetEntryAnimationData( const Property::Map& map );
341
342   /**
343    * @brief Allows the popup exit animation to be setup from a Property::Map that could
344    * originate, for example, from a JSON file.
345    *
346    * @param[in] map A Property::Map containing a description of an animation
347    */
348   void SetExitAnimationData( const Property::Map& map );
349
350 public: // Signals
351
352   /**
353    * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
354    */
355   Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
356
357   /**
358    * @copydoc Dali::Toolkit::Popup::ShowingSignal()
359    */
360   Toolkit::Popup::DisplayStateChangeSignalType& ShowingSignal();
361
362   /**
363    * @copydoc Dali::Toolkit::Popup::ShownSignal()
364    */
365   Toolkit::Popup::DisplayStateChangeSignalType& ShownSignal();
366
367   /**
368    * @copydoc Dali::Toolkit::Popup::HidingSignal()
369    */
370   Toolkit::Popup::DisplayStateChangeSignalType& HidingSignal();
371
372   /**
373    * @copydoc Dali::Toolkit::Popup::HiddenSignal()
374    */
375   Toolkit::Popup::DisplayStateChangeSignalType& HiddenSignal();
376
377   /**
378    * Connects a callback function with the object's signals.
379    * @param[in] object The object providing the signal.
380    * @param[in] tracker Used to disconnect the signal.
381    * @param[in] signalName The signal to connect to.
382    * @param[in] functor A newly allocated FunctorDelegate.
383    * @return True if the signal was connected.
384    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
385    */
386   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
387
388 private:
389
390   /**
391    * Signal occurs when the State animation (transition from hide <-> show) finishes.
392    * @param[in] source The animation that just finished.
393    */
394   void OnDisplayChangeAnimationFinished( Animation& source );
395
396   /**
397    * Signal occurs when the dimmed backing for the Popup is touched.
398    * @param[in] actor The Actor Touched
399    * @param[in] event The Touch Event.
400    * @return Whether to consume event or not.
401    */
402   bool OnBackingTouched(Actor actor, const TouchEvent& event);
403
404   /**
405    * Signal occurs when a mouse wheel event occurs on the dimmed backing.
406    * @param[in] actor The Actor that got the wheel event.
407    * @param[in] event The Wheel Event.
408    * @return Whether to consume event or not.
409    */
410   bool OnBackingWheelEvent(Actor actor, const WheelEvent& event);
411
412   /**
413    * Signal occurs when the dialog has been touched.
414    * @param[in] actor The Actor Touched
415    * @param[in] event The Touch Event.
416    * @return Whether to consume event or not.
417    */
418   bool OnDialogTouched(Actor actor, const TouchEvent& event);
419
420   /**
421    * @copydoc Toolkit::Control::OnInitialize()
422    */
423   virtual void OnInitialize();
424
425   /**
426    * Called whenever the popup layout is re-set up.
427    * Normally due to a change in contents.
428    * Note: This is only done when the popup is shown.
429    */
430   virtual void OnLayoutSetup() {}
431
432   /**
433    * Called when the popup is directly or indirectly parented to the stage.
434    */
435   virtual void OnStageConnection( int depth );
436
437   /**
438    * From Control; called after a child has been added to the owning actor.
439    * @param[in] child The child which has been added.
440    */
441   virtual void OnChildAdd( Actor& child );
442
443   /**
444    * @copydoc Control::OnRelayOut()
445    */
446   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
447
448   /**
449    * @copydoc Control::OnSetResizePolicy()
450    */
451   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
452
453   /**
454    * @copydoc Control::GetNaturalSize()
455    */
456   virtual Vector3 GetNaturalSize();
457
458   /**
459    * @copydoc Control::GetHeightForWidth()
460    */
461   virtual float GetHeightForWidth( float width );
462
463   /**
464    * @copydoc Control::GetWidthForHeight()
465    */
466   virtual float GetWidthForHeight( float height );
467
468   /**
469    * @copydoc Control::OnKeyEvent()
470    */
471   virtual bool OnKeyEvent( const KeyEvent& event );
472
473   /**
474    * @copydoc Control::GetNextKeyboardFocusableActor()
475    */
476   Actor GetNextKeyboardFocusableActor( Actor currentFocusedActor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled );
477
478 private:
479
480   /**
481    * Recursively add any focusable actors or layout containers to the provided vector.
482    * Include the top level actor if it is a layout container.
483    *
484    * @param[in]     parent          The actor to start from
485    * @param[in/out] focusableActors The vector to add focusable actors to
486    */
487   void AddFocusableChildren( Actor parent, std::vector< Actor >& focusableActors );
488
489   /**
490    * Recursively add any focusable actors or layout containers to the provided vector.
491    *
492    * @param[in]     parent          The actor to start from
493    * @param[in/out] focusableActors The vector to add focusable actors to
494    */
495   void AddFocusableChildrenRecursive( Actor parent, std::vector< Actor >& focusableActors );
496
497 private:
498
499   // Undefined.
500   Popup(const Popup&);
501
502   // Undefined.
503   Popup& operator=(const Popup& rhs);
504
505 private:
506
507   Toolkit::Popup::TouchedOutsideSignalType     mTouchedOutsideSignal;
508   Toolkit::Popup::DisplayStateChangeSignalType mShowingSignal;
509   Toolkit::Popup::DisplayStateChangeSignalType mShownSignal;
510   Toolkit::Popup::DisplayStateChangeSignalType mHidingSignal;
511   Toolkit::Popup::DisplayStateChangeSignalType mHiddenSignal;
512
513   Layer mLayer;                                      ///< Popup Layer (i.e. Dim backing and PopupBg reside in this).
514   Toolkit::TableView mPopupLayout;                   ///< Popup Background (i.e. dialog reside in this).
515   Toolkit::Control mBacking;                         ///< Backing actor (dim effect).
516   Actor mPreviousFocusedActor;                       ///< Store the previous focused actor to restore the focus when popup hide.
517   Actor mTailImage;                                  ///< Stores the tail image.
518   Actor mPopupContainer;                             ///< This actor is used to house the background image and the main popup layout.
519   Animation mAnimation;                              ///< The current animation in use used to manage display state changing.
520   bool mAlterAddedChild;                             ///< Flag used to control whether children are reparented or not.
521   bool mLayoutDirty;                                 ///< Set to true whenever any property that would require a layout update is modified.
522   Timer mAutoHideTimer;                              ///< Used to perform an auto-hide of the popup if desired.
523   bool mTouchTransparent;                            ///< Allows all events to pass through the popup.
524
525   // Main Content related properties:
526   Actor mTitle;                                      ///< Stores the text title.
527   Actor mContent;                                    ///< Stores the unselected content.
528   Actor mFooter;                                     ///< Stores the footer content (typically controls).
529
530   // Display related properties.
531   Toolkit::Popup::DisplayState mDisplayState;        ///< The current display state of the popup.
532   bool mTailVisible;                                 ///< True if the popup tail should be visible.
533   Vector3 mTailPosition;                             ///< The position of the tail.
534   Toolkit::Popup::ContextualMode mContextualMode;    ///< Allows the popup to be layed out adjacent to its parent in different directions.
535   float mAnimationDuration;                          ///< The duration of the transition in and out animations.
536   Toolkit::Popup::AnimationMode mAnimationMode;      ///< The animation to use to transition in and out.
537   Dali::AnimationData mEntryAnimationData;           ///< Stores description data that can be used for generating a custom entry animation.
538   Dali::AnimationData mExitAnimationData;            ///< Stores description data that can be used for generating a custom exit animation.
539   unsigned int mAutoHideDelay;                       ///< If set, will auto-hide the popup after a specified amount of time.
540
541   // Style related properties:
542   bool mBackingEnabled;                              ///< True if a dimmed backing will be used.
543   Vector4 mBackingColor;                             ///< The color of the backing.
544   Actor mPopupBackgroundImage;                       ///< Stores the background image.
545   Vector4 mBackgroundOuterBorder;                    ///< Background external border margin size
546   float mMargin;                                     ///< Internal margin for popup contents.
547   std::string mTailUpImage;                          ///< Image used for the tail for the up direction.
548   std::string mTailDownImage;                        ///< Image used for the tail for the down direction.
549   std::string mTailLeftImage;                        ///< Image used for the tail for the left direction.
550   std::string mTailRightImage;                       ///< Image used for the tail for the right direction.
551 };
552
553 } // namespace Internal
554
555 // Helpers for public-api forwarding methods
556
557 inline Toolkit::Internal::Popup& GetImpl( Toolkit::Popup& publicObject )
558 {
559   DALI_ASSERT_ALWAYS( publicObject );
560
561   Dali::RefObject& handle = publicObject.GetImplementation();
562
563   return static_cast<Toolkit::Internal::Popup&>( handle );
564 }
565
566 inline const Toolkit::Internal::Popup& GetImpl( const Toolkit::Popup& publicObject )
567 {
568   DALI_ASSERT_ALWAYS( publicObject );
569
570   const Dali::RefObject& handle = publicObject.GetImplementation();
571
572   return static_cast<const Toolkit::Internal::Popup&>( handle );
573 }
574
575 } // namespace Toolkit
576
577 } // namespace Dali
578
579 #endif // __DALI_TOOLKIT_INTERNAL_POPUP_H__