Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / base / 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 // INTERNAL INCLUDES
22 #include <dali/dali.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali-toolkit/public-api/controls/popup/popup.h>
25 #include <dali-toolkit/internal/controls/popup/popup-style-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 class Button;
34
35 namespace Internal
36 {
37
38 class Popup;
39 class PopupStyle;
40
41 typedef IntrusivePtr<Popup>    PopupPtr;
42 typedef IntrusivePtr<PopupStyle> PopupStylePtr;
43
44 /**
45  * @copydoc Toolkit::Popup
46  */
47 class Popup : public Control
48 {
49 public:
50
51   /**
52    * Create a new Popup.
53    * @return A public handle to the newly allocated Popup.
54    */
55   static Dali::Toolkit::Popup New();
56
57 public:
58
59   /**
60    * Returns number of buttons added to Popup
61    *
62    * @return Number of buttons
63    */
64   size_t GetButtonCount() const;
65
66   /**
67    * @copydoc Toolkit::Popup::SetBackgroundImage
68    */
69   void SetBackgroundImage( Actor image );
70
71   /**
72    * @copydoc Toolkit::Popup::SetButtonAreaImage
73    */
74   void SetButtonAreaImage( Actor image );
75
76   /**
77    * @copydoc Toolkit::Popup::SetTitle( const std::string& text );
78    */
79   void SetTitle( const std::string& text );
80
81   /**
82    * @copydoc Toolkit::Popup::SetTitle( TextView titleActor )
83    */
84   void SetTitle( Toolkit::TextView titleActor );
85
86   /**
87    * @copydoc Toolkit::Popup::GetTitle
88    */
89   Toolkit::TextView 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   /**
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::TouchedOutsideSignalV2& OutsideTouchedSignal();
184
185   /**
186    * @copydoc Dali::Toolkit::Popup::HiddenSignal()
187    */
188   Toolkit::Popup::HiddenSignalV2& 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::OnRelaidOut()
251    */
252   virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
253
254   /**
255    * @copydoc Control::OnKeyEvent()
256    */
257   virtual bool OnKeyEvent(const KeyEvent& event);
258
259   /**
260    * @copydoc Control::GetNaturalSize()
261    */
262   virtual Vector3 GetNaturalSize();
263
264   /**
265    * @copydoc Control::GetHeightForWidth()
266    */
267   float GetHeightForWidth( float width );
268
269   /**
270    * @copydoc Control::GetWidthForHeight()
271    */
272   float GetWidthForHeight( float height );
273
274   /**
275    * @copydoc Control::GetNextKeyboardFocusableActor()
276    */
277   Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
278
279 private:
280
281   // Undefined
282   Popup(const Popup&);
283
284   // Undefined
285   Popup& operator=(const Popup& rhs);
286
287 private:
288
289   struct LayoutInfo
290   {
291     Vector3 mTitleSize;
292     Vector3 mContentSize;
293     Vector3 mButtonBgSize;
294     std::vector<Vector3> mButtonSize;
295   };
296
297 private:
298
299   bool mShowing;                          ///< Popup is showing or not
300
301   Layer mLayer;                           ///< Popup Layer (i.e. Dim backing and PopupBg reside in this)
302   Actor mPopupBg;                         ///< Popup Background (i.e. dialog reside in this)
303   ImageActor mBacking;                    ///< Backing actor (dim effect)
304
305   Actor mPreviousFocusedActor;            ///< Store the previous focused actor to restore the focus when popup hide
306
307   Actor mBackgroundImage;                 ///< Stores the background image.
308   Actor mButtonAreaImage;                 ///< Stores the button background image.
309   Toolkit::TextView mTitle;               ///< Stores the text title.
310   Actor mContent;                         ///< Stores popup's content.
311   Actor mBottomBg;                        ///< bottom button bar background. ImageActor is replaced with Actor due to hidden image.
312   Actor mTailImage;                       ///< Stores the tail image
313
314   ActorContainer mButtons;                ///< Keeps track of the buttons added to this popup.
315   Toolkit::Popup::PopupState mState;      ///< Popup current state.
316   Animation mAnimation;                   ///< The animation instance managing state changing.
317   bool mAlterAddedChild;                  ///< Flag used to control whether children are reparented or not.
318   PopupStylePtr mPopupStyle;              ///< The style to be used for this popup.
319
320   LayoutInfo mLayoutInfo;                 ///< Stores sizes of all popup components.
321
322   Toolkit::Popup::TouchedOutsideSignalV2 mTouchedOutsideSignalV2;
323   Toolkit::Popup::HiddenSignalV2 mHiddenSignalV2;
324
325   Property::Index mPropertyTitle;         ///< Property index for Title.
326   Property::Index mPropertyState;         ///< Property index for popup state.
327 };
328
329 } // namespace Internal
330
331 // Helpers for public-api forwarding methods
332
333 inline Toolkit::Internal::Popup& GetImpl(Toolkit::Popup& pub)
334 {
335   DALI_ASSERT_ALWAYS(pub);
336
337   Dali::RefObject& handle = pub.GetImplementation();
338
339   return static_cast<Toolkit::Internal::Popup&>(handle);
340 }
341
342 inline const Toolkit::Internal::Popup& GetImpl(const Toolkit::Popup& pub)
343 {
344   DALI_ASSERT_ALWAYS(pub);
345
346   const Dali::RefObject& handle = pub.GetImplementation();
347
348   return static_cast<const Toolkit::Internal::Popup&>(handle);
349 }
350
351 } // namespace Toolkit
352
353 } // namespace Dali
354
355 #endif // __DALI_TOOLKIT_INTERNAL_POPUP_H__