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