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