License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / navigation-frame / navigation-control-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_NAVIGATION_CONTROL_H__
2 #define __DALI_TOOLKIT_INTERNAL_NAVIGATION_CONTROL_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
23 #include <list>
24
25 // INTERNAL INCLUDES
26 #include <dali/dali.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/navigation-frame/navigation-control.h>
29 #include <dali-toolkit/public-api/controls/navigation-frame/page.h>
30 #include <dali-toolkit/internal/controls/navigation-frame/navigation-bar.h>
31 #include <dali-toolkit/public-api/controls/popup/popup.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 class NavigationControl;
40 class Page;
41
42 namespace Internal
43 {
44
45 class NavigationBar;
46
47 /**
48  * NavigationControl implements a controller than manages the navigation of hierarchical contents.
49  * @see Dali::Toolkit::NavigationControl for more details.
50  */
51 class NavigationControl : public ControlImpl
52 {
53 public:
54
55   /**
56    * Create an initialized NavigationControl.
57    * @return A handle to a newly allocated Dali resource
58    */
59   static Toolkit::NavigationControl New();
60
61   /**
62    * @copydoc Dali::Toolkit::NavigationControl::PushItem()
63    */
64   void PushItem( Toolkit::Page page );
65
66   /**
67    * @copydoc Dali::Toolkit::NavigationControl::PopItem()
68    */
69   Toolkit::Page PopItem();
70
71   /**
72    * @copydoc Dali::Toolkit::NavigationControl::GetItemCount()
73    */
74   size_t GetItemCount() const;
75
76   /**
77    * @copydoc Dali::Toolkit::NavigationControl::GetItem()
78    */
79   Toolkit::Page GetItem(std::size_t index) const;
80
81   /**
82    * @copydoc Dali::Toolkit::NavigationControl::GetCurrentItem()
83    */
84   Toolkit::Page GetCurrentItem() const;
85
86   /**
87    * @copydoc Dali::Toolkit::NavigationControl::SetBackground()
88    */
89   void SetBackground( Actor background);
90
91   /**
92    * @copydoc Dali::Toolkit::NavigationControl::CreateNavigationToolBar()
93    */
94   void CreateNavigationToolBar( Toolkit::NaviToolBarStyle toolBarStylePortrait,
95                                 Toolkit::NaviToolBarStyle toolBarStyleLandscape );
96
97   /**
98    * @copydoc Dali::Toolkit::NavigationControl::CreateNavigationTitleBar()
99    */
100   void CreateNavigationTitleBar( Toolkit::NaviTitleBarStyle titleBarStylePortrait,
101                                  Toolkit::NaviTitleBarStyle titleBarStyleLandscape );
102
103   /**
104    * @copydoc Dali::Toolkit::NavigationControl::OrientationChanged()
105    */
106   void OrientationChanged( int angle );
107
108   /**
109    * @copydoc Dali::Toolkit::NavigationControl::SetOrientationRotateAnimation()
110    */
111   void SetOrientationRotateAnimation( float duration, AlphaFunction alphaFunc);
112
113   /**
114    * Retrieve the layer for displaying navigation bar
115    * @return The layer for navigation bar
116    */
117   Layer GetBarLayer() const;
118
119   /**
120    * Performs actions as requested using the action name.
121    * @param[in] object The object on which to perform the action.
122    * @param[in] actionName The action to perform.
123    * @param[in] attributes The attributes with which to perfrom this action.
124    * @return true if action has been accepted by this control
125    */
126   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
127
128 public:
129
130   /**
131    * @copydoc Dali::Toolkit::NavigatinControl::ItemPushedSignal()
132    */
133   Toolkit::NavigationControl::ItemPushedSignalV2& ItemPushedSignal();
134
135   /**
136    * @copydoc Dali::Toolkit::NavigatinControl::ItemPoppedSignal()
137    */
138   Toolkit::NavigationControl::ItemPoppedSignalV2& ItemPoppedSignal();
139
140 private: // override functions from ControlImpl
141
142   /**
143    * @copydoc Toolkit::ControlImpl::OnInitialize()
144    */
145   virtual void OnInitialize();
146
147   /**
148    * From ControlImpl; called after a child has been added to the owning actor.
149    * @param[in] child The child which has been added.
150    */
151   virtual void OnControlChildAdd( Actor& child );
152
153   /**
154    * @copydoc Toolkit::ControlImple::OnStageConnection()
155    */
156   virtual void OnStageConnection();
157
158   /**
159    * @copydoc Toolkit::ControlImpl::OnRelaidOut()
160    */
161   virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
162
163   /**
164    * @copydoc Toolkit::ControlImpl::OnControlSizeSet
165    */
166   virtual void OnControlSizeSet( const Vector3& size );
167
168   /**
169    * @copydoc Toolkit::ControlImpl::OnKeyEvent()
170    */
171   virtual bool OnKeyEvent( const KeyEvent& event );
172
173 protected:
174
175   /**
176    * Constructor.
177    * It initializes the NavigationControl members
178    */
179   NavigationControl();
180
181   /**
182    * A reference counted object may only be deleted by calling Unreference()
183    */
184   virtual ~NavigationControl();
185
186 private:
187
188   // Undefined
189   NavigationControl(const NavigationControl&);
190
191   // Undefined
192   NavigationControl& operator=(const NavigationControl& rhs);
193
194   /**
195    * Create a Layer and add it to the navigation control
196    * @return The newly created layer
197    */
198   Layer CreateLayer();
199
200   /**
201    * Setup the pop up menu which would show when KEY_MENU is pressed
202    * This function is called when pushing/popping item
203    */
204   void SetupPopupMenu();
205
206   /**
207    * Signal handler called when the user touches outside of pop up menu.
208    */
209   void OnPopupTouchedOutside();
210
211 public:
212   std::list< Toolkit::Page >           mUnpushedItems;
213
214 private:
215
216   std::vector< Toolkit::Page > mItemStack;
217   Toolkit::Page                mCurrentItem;
218   Vector2                      mControlSize;
219
220   Layer                        mBackgroundLayer;
221   Layer                        mBarLayer;
222   Layer                        mContentLayer;
223   Layer                        mPopupLayer;
224
225   Actor                        mBackground;
226
227   NavigationBar*               mToolBar;
228   NavigationBar*               mTitleBar;
229
230   int                          mOrientationAngle;
231   float                        mOrientationAnimationDuration;
232   AlphaFunction                mOrientationAnimationAlphaFunc;
233   Vector3                      mItemPositionCoefficient;
234
235   Toolkit::Popup               mPopupMenu;
236
237 private:
238   Toolkit::NavigationControl::ItemPushedSignalV2 mItemPushedSignal;   ///< The signal to notify the item push
239   Toolkit::NavigationControl::ItemPoppedSignalV2 mItemPoppedSignal;   ///< The signal to notify the item pop
240 };
241
242 } // namespace Internal
243
244 // Helpers for public-api forwarding methods
245
246 inline Toolkit::Internal::NavigationControl& GetImpl( Toolkit::NavigationControl& navigationControl )
247 {
248   DALI_ASSERT_ALWAYS( navigationControl );
249
250   Dali::RefObject& handle = navigationControl.GetImplementation();
251
252   return static_cast<Toolkit::Internal::NavigationControl&>( handle );
253 }
254
255 inline const Toolkit::Internal::NavigationControl& GetImpl( const Toolkit::NavigationControl& navigationControl )
256 {
257   DALI_ASSERT_ALWAYS( navigationControl );
258
259   const Dali::RefObject& handle = navigationControl.GetImplementation();
260
261   return static_cast<const Toolkit::Internal::NavigationControl&>( handle );
262 }
263
264 } // namespace Toolkit
265
266 } // namespace Dali
267
268 #endif /* __DALI_TOOLKIT_INTERNAL_NAVIGATION_CONTROL_H__ */