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 #include <dali-toolkit/public-api/controls/text-controls/text-label.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   /**
135    * @copydoc Toolkit::Popup::MarkDirtyForRelayout
136    */
137   void MarkDirtyForRelayout();
138
139 protected:
140
141   /**
142    * Construct a new Popup.
143    * @param[in] style of the popup
144    */
145   Popup(PopupStyle& style);
146
147   /**
148    * A reference counted object may only be deleted by calling Unreference()
149    */
150   virtual ~Popup();
151
152 private:
153
154   /**
155    * Creates and applies the default background image.
156    */
157   void SetDefaultBackgroundImage();
158
159   /**
160    * Create Dim Backing
161    * (covers all content behind the dialog)
162    */
163   void CreateBacking();
164
165   /**
166    * Create Dialog
167    * (dialog content resides inside this - buttons, title etc.)
168    */
169   void CreateDialog();
170
171   /**
172    * Animate Popup by scaling uniformally from 0 to 100% and vice versa (default behaviour)
173    * @param[in] state The desired state to change into.
174    * @param[in] duration The time for this animation to take.
175    */
176   void HandleStateChange( Toolkit::Popup::PopupState state, float duration );
177
178   /**
179    * Invoked once StateChange has completed.
180    */
181   void HandleStateChangeComplete();
182
183 public: // Signals
184
185   /**
186    * @copydoc Dali::Toolkit::Popup::OutsideTouchedSignal()
187    */
188   Toolkit::Popup::TouchedOutsideSignalType& OutsideTouchedSignal();
189
190   /**
191    * @copydoc Dali::Toolkit::Popup::HiddenSignal()
192    */
193   Toolkit::Popup::HiddenSignalType& HiddenSignal();
194
195   /**
196    * Connects a callback function with the object's signals.
197    * @param[in] object The object providing the signal.
198    * @param[in] tracker Used to disconnect the signal.
199    * @param[in] signalName The signal to connect to.
200    * @param[in] functor A newly allocated FunctorDelegate.
201    * @return True if the signal was connected.
202    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
203    */
204   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
205
206 private:
207
208   /**
209    * Signal occurs when the State animation (transition from hide<->show) finishes
210    * @param[in] source The animation that just finished.
211    */
212   void OnStateAnimationFinished( Animation& source );
213
214   /**
215    * Signal occurs when the dimmed backing for the Popup is touched.
216    * @param[in] actor The Actor Touched
217    * @param[in] event The Touch Event.
218    * @return Whether to consume event or not.
219    */
220   bool OnBackingTouched(Actor actor, const TouchEvent& event);
221
222   /**
223    * Signal occurs when the mouse wheel event is occured on dimmed backing for the Popup.
224    * @param[in] actor The Actor got mouse wheel
225    * @param[in] event The Mouse Wheel Event.
226    * @return Whether to consume event or not.
227    */
228   bool OnBackingMouseWheelEvent(Actor actor, const MouseWheelEvent& event);
229
230   /**
231    * Signal occurs when the dialog has been touched.
232    * @param[in] actor The Actor Touched
233    * @param[in] event The Touch Event.
234    * @return Whether to consume event or not.
235    */
236   bool OnDialogTouched(Actor actor, const TouchEvent& event);
237
238   /**
239    * @copydoc Toolkit::Control::OnInitialize()
240    */
241   virtual void OnInitialize();
242
243   /**
244    * @copydoc Dali::CustomActorImpl::OnPropertySet()
245    */
246   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
247
248   /**
249    * From Control; called after a child has been added to the owning actor.
250    * @param[in] child The child which has been added.
251    */
252   virtual void OnControlChildAdd( Actor& child );
253
254   /**
255    * @copydoc Control::OnRelayOut()
256    */
257   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
258
259   /**
260    * @copydoc Control::OnSetResizePolicy()
261    */
262   virtual void OnSetResizePolicy( ResizePolicy policy, Dimension dimension );
263
264   /**
265    * @copydoc Control::OnKeyEvent()
266    */
267   virtual bool OnKeyEvent(const KeyEvent& event);
268
269   /**
270    * @copydoc Control::GetNaturalSize()
271    */
272   virtual Vector3 GetNaturalSize();
273
274   /**
275    * @copydoc Control::GetHeightForWidth()
276    */
277   float GetHeightForWidth( float width );
278
279   /**
280    * @copydoc Control::GetWidthForHeight()
281    */
282   float GetWidthForHeight( float height );
283
284   /**
285    * @copydoc Control::GetNextKeyboardFocusableActor()
286    */
287   Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
288
289   /**
290    * Create the root actor for the footer
291    */
292   void CreateFooter();
293
294 private:
295
296   // Undefined
297   Popup(const Popup&);
298
299   // Undefined
300   Popup& operator=(const Popup& rhs);
301
302 private:
303
304   struct LayoutInfo
305   {
306     Vector3 mTitleSize;
307     Vector3 mContentSize;
308     Vector3 mButtonBgSize;
309     std::vector<Vector3> mButtonSize;
310   };
311
312 private:
313
314   bool mShowing;                          ///< Popup is showing or not
315
316   Layer mLayer;                           ///< Popup Layer (i.e. Dim backing and PopupBg reside in this)
317   Toolkit::TableView mPopupLayout;        ///< Popup layout (i.e. dialog reside in this)
318   ImageActor mBacking;                    ///< Backing actor (dim effect)
319
320   Actor mPreviousFocusedActor;            ///< Store the previous focused actor to restore the focus when popup hide
321
322   Actor mBackgroundImage;                 ///< Stores the background image.
323   Actor mButtonAreaImage;                 ///< Stores the button background image.
324   Toolkit::TextLabel mTitle;               ///< Stores the text title.
325   Actor mContent;                         ///< Stores popup's content.
326   Actor mBottomBg;                        ///< bottom button bar background. ImageActor is replaced with Actor due to hidden image.
327   Actor mTailImage;                       ///< Stores the tail image
328
329   ActorContainer mButtons;                ///< Keeps track of the buttons added to this popup.
330   Toolkit::Popup::PopupState mState;      ///< Popup current state.
331   Animation mAnimation;                   ///< The animation instance managing state changing.
332   bool mAlterAddedChild;                  ///< Flag used to control whether children are reparented or not.
333   PopupStylePtr mPopupStyle;              ///< The style to be used for this popup.
334
335   LayoutInfo mLayoutInfo;                 ///< Stores sizes of all popup components.
336
337   Toolkit::Popup::TouchedOutsideSignalType mTouchedOutsideSignal;
338   Toolkit::Popup::HiddenSignalType mHiddenSignal;
339
340   Property::Index mPropertyTitle;         ///< Property index for Title.
341   Property::Index mPropertyState;         ///< Property index for popup state.
342 };
343
344 } // namespace Internal
345
346 // Helpers for public-api forwarding methods
347
348 inline Toolkit::Internal::Popup& GetImpl(Toolkit::Popup& pub)
349 {
350   DALI_ASSERT_ALWAYS(pub);
351
352   Dali::RefObject& handle = pub.GetImplementation();
353
354   return static_cast<Toolkit::Internal::Popup&>(handle);
355 }
356
357 inline const Toolkit::Internal::Popup& GetImpl(const Toolkit::Popup& pub)
358 {
359   DALI_ASSERT_ALWAYS(pub);
360
361   const Dali::RefObject& handle = pub.GetImplementation();
362
363   return static_cast<const Toolkit::Internal::Popup&>(handle);
364 }
365
366 } // namespace Toolkit
367
368 } // namespace Dali
369
370 #endif // __DALI_TOOLKIT_INTERNAL_POPUP_H__