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