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