Changed grab-handle behavior to work inside Popup
[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) 2014 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/animation/animation.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
29 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
30 #include <dali-toolkit/devel-api/controls/popup/popup.h>
31 #include <dali-toolkit/internal/controls/popup/popup-style-impl.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 class Button;
40
41 namespace Internal
42 {
43
44 class Popup;
45 class PopupStyle;
46
47 typedef IntrusivePtr<Popup>    PopupPtr;
48 typedef IntrusivePtr<PopupStyle> PopupStylePtr;
49
50 /**
51  * @copydoc Toolkit::Popup
52  */
53 class Popup : public Control
54 {
55 public:
56
57   /**
58    * Create a new Popup.
59    * @return A public handle to the newly allocated Popup.
60    */
61   static Dali::Toolkit::Popup New();
62
63 public:
64
65   /**
66    * Returns number of buttons added to Popup
67    *
68    * @return Number of buttons
69    */
70   size_t GetButtonCount() const;
71
72   /**
73    * @copydoc Toolkit::Popup::SetBackgroundImage
74    */
75   void SetBackgroundImage( Actor image );
76
77   /**
78    * @copydoc Toolkit::Popup::SetButtonAreaImage
79    */
80   void SetButtonAreaImage( Actor image );
81
82   /**
83    * @copydoc Toolkit::Popup::SetTitle( const std::string& text );
84    */
85   void SetTitle( const std::string& text );
86
87   /**
88    * @copydoc Toolkit::Popup::GetTitle
89    */
90   std::string GetTitle() const;
91
92   /**
93    * @copydoc Toolkit::Popup::AddButton
94    */
95   void AddButton( Toolkit::Button button );
96
97   /**
98    * @copydoc Toolkit::Popup::SetState( PopupState state )
99    */
100   void SetState( Toolkit::Popup::PopupState state );
101
102   /**
103    * @copydoc Toolkit::Popup::SetState( PopupState state, float duration )
104    */
105   void SetState( Toolkit::Popup::PopupState state, float duration );
106
107   /**
108    * @copydoc Toolkit::Popup::GetState( )
109    */
110   Toolkit::Popup::PopupState GetState() const;
111
112   /**
113    * @copydoc Toolkit::Popup::ShowTail
114    */
115   void ShowTail(const Vector3& position);
116
117   /**
118    * @copydoc Toolkit::Popup::HideTail
119    */
120   void HideTail();
121
122   /**
123    * Sets the style of the popup
124    * @param[in] style The style of the popup
125    */
126   void SetStyle(PopupStyle& style);
127
128   /**
129    * Gets the style of the popup
130    * @return style of the popup
131    */
132   PopupStylePtr GetStyle() const;
133
134 protected:
135
136   /**
137    * Construct a new Popup.
138    * @param[in] style of the popup
139    */
140   Popup(PopupStyle& style);
141
142   /**
143    * A reference counted object may only be deleted by calling Unreference()
144    */
145   virtual ~Popup();
146
147 private:
148
149   /**
150    * Creates and applies the default background image.
151    */
152   void SetDefaultBackgroundImage();
153
154   /**
155    * Create Dim Backing
156    * (covers all content behind the dialog)
157    */
158   void CreateBacking();
159
160   /**
161    * Create Dialog
162    * (dialog content resides inside this - buttons, title etc.)
163    */
164   void CreateDialog();
165
166   /**
167    * Animate Popup by scaling uniformally from 0 to 100% and vice versa (default behaviour)
168    * @param[in] state The desired state to change into.
169    * @param[in] duration The time for this animation to take.
170    */
171   void HandleStateChange( Toolkit::Popup::PopupState state, float duration );
172
173   /**
174    * Invoked once StateChange has completed.
175    */
176   void HandleStateChangeComplete();
177
178 public: // Signals
179
180   /**
181    * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
182    */
183   Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
184
185   /**
186    * @copydoc Dali::Toolkit::Popup::HiddenSignal()
187    */
188   Toolkit::Popup::HiddenSignalType& HiddenSignal();
189
190   /**
191    * Connects a callback function with the object's signals.
192    * @param[in] object The object providing the signal.
193    * @param[in] tracker Used to disconnect the signal.
194    * @param[in] signalName The signal to connect to.
195    * @param[in] functor A newly allocated FunctorDelegate.
196    * @return True if the signal was connected.
197    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
198    */
199   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
200
201 private:
202
203   /**
204    * Signal occurs when the State animation (transition from hide<->show) finishes
205    * @param[in] source The animation that just finished.
206    */
207   void OnStateAnimationFinished( Animation& source );
208
209   /**
210    * Signal occurs when the dimmed backing for the Popup is touched.
211    * @param[in] actor The Actor Touched
212    * @param[in] event The Touch Event.
213    * @return Whether to consume event or not.
214    */
215   bool OnBackingTouched(Actor actor, const TouchEvent& event);
216
217   /**
218    * Signal occurs when the mouse wheel event is occured on dimmed backing for the Popup.
219    * @param[in] actor The Actor got mouse wheel
220    * @param[in] event The Mouse Wheel Event.
221    * @return Whether to consume event or not.
222    */
223   bool OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event);
224
225   /**
226    * Signal occurs when the dialog has been touched.
227    * @param[in] actor The Actor Touched
228    * @param[in] event The Touch Event.
229    * @return Whether to consume event or not.
230    */
231   bool OnDialogTouched(Actor actor, const TouchEvent& event);
232
233   /**
234    * @copydoc Toolkit::Control::OnInitialize()
235    */
236   virtual void OnInitialize();
237
238   /**
239    * @copydoc Dali::CustomActorImpl::OnPropertySet()
240    */
241   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
242
243   /**
244    * From Control; called after a child has been added to the owning actor.
245    * @param[in] child The child which has been added.
246    */
247   virtual void OnControlChildAdd( Actor& child );
248
249   /**
250    * @copydoc Control::OnRelayOut()
251    */
252   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
253
254   /**
255    * @copydoc Control::OnSetResizePolicy()
256    */
257   virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
258
259   /**
260    * @copydoc Control::OnKeyEvent()
261    */
262   virtual bool OnKeyEvent(const KeyEvent& event);
263
264   /**
265    * @copydoc Control::GetNaturalSize()
266    */
267   virtual Vector3 GetNaturalSize();
268
269   /**
270    * @copydoc Control::GetHeightForWidth()
271    */
272   float GetHeightForWidth( float width );
273
274   /**
275    * @copydoc Control::GetWidthForHeight()
276    */
277   float GetWidthForHeight( float height );
278
279   /**
280    * @copydoc Control::GetNextKeyboardFocusableActor()
281    */
282   Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
283
284   /**
285    * Create the root actor for the footer
286    */
287   void CreateFooter();
288
289 private:
290
291   // Undefined
292   Popup(const Popup&);
293
294   // Undefined
295   Popup& operator=(const Popup& rhs);
296
297 private:
298
299   struct LayoutInfo
300   {
301     Vector3 mTitleSize;
302     Vector3 mContentSize;
303     Vector3 mButtonBgSize;
304     std::vector<Vector3> mButtonSize;
305   };
306
307 private:
308
309   bool mShowing;                          ///< Popup is showing or not
310
311   Layer mLayer;                           ///< Popup Layer (i.e. Dim backing and PopupBg reside in this)
312   Toolkit::TableView mPopupLayout;        ///< Popup layout (i.e. dialog reside in this)
313   ImageActor mBacking;                    ///< Backing actor (dim effect)
314
315   Actor mPreviousFocusedActor;            ///< Store the previous focused actor to restore the focus when popup hide
316
317   Actor mBackgroundImage;                 ///< Stores the background image.
318   Actor mButtonAreaImage;                 ///< Stores the button background image.
319   Toolkit::TextLabel mTitle;               ///< Stores the text title.
320   Actor mContent;                         ///< Stores popup's content.
321   Actor mBottomBg;                        ///< bottom button bar background. ImageActor is replaced with Actor due to hidden image.
322   Actor mTailImage;                       ///< Stores the tail image
323
324   std::vector< Actor > mButtons;          ///< Keeps track of the buttons added to this popup.
325   Toolkit::Popup::PopupState mState;      ///< Popup current state.
326   Animation mAnimation;                   ///< The animation instance managing state changing.
327   bool mAlterAddedChild;                  ///< Flag used to control whether children are reparented or not.
328   PopupStylePtr mPopupStyle;              ///< The style to be used for this popup.
329
330   LayoutInfo mLayoutInfo;                 ///< Stores sizes of all popup components.
331
332   Toolkit::Popup::TouchedOutsideSignalType mTouchedOutsideSignal;
333   Toolkit::Popup::HiddenSignalType mHiddenSignal;
334
335   Property::Index mPropertyTitle;         ///< Property index for Title.
336   Property::Index mPropertyState;         ///< Property index for popup state.
337 };
338
339 } // namespace Internal
340
341 // Helpers for public-api forwarding methods
342
343 inline Toolkit::Internal::Popup& GetImpl(Toolkit::Popup& pub)
344 {
345   DALI_ASSERT_ALWAYS(pub);
346
347   Dali::RefObject& handle = pub.GetImplementation();
348
349   return static_cast<Toolkit::Internal::Popup&>(handle);
350 }
351
352 inline const Toolkit::Internal::Popup& GetImpl(const Toolkit::Popup& pub)
353 {
354   DALI_ASSERT_ALWAYS(pub);
355
356   const Dali::RefObject& handle = pub.GetImplementation();
357
358   return static_cast<const Toolkit::Internal::Popup&>(handle);
359 }
360
361 } // namespace Toolkit
362
363 } // namespace Dali
364
365 #endif // __DALI_TOOLKIT_INTERNAL_POPUP_H__