New size negotiation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / view / view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_VIEW_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/layer.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali/public-api/common/map-wrapper.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/public-api/controls/view/view.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 class View;
37
38 namespace Internal
39 {
40
41 /**
42  * View is a control to add layers and a background.
43  * @see Dali::Toolkit::View for more details.
44  */
45 class View : public Control
46 {
47 private:
48   typedef std::map<unsigned int,Layer> LayerContainer;
49   typedef std::map<unsigned int,Layer>::iterator LayerIt;
50   typedef std::map<unsigned int,Layer>::const_iterator LayerConstIt;
51
52   /**
53    * Orientation declaration used internally to rotate the view.
54    * The angles associated with each enum value could be changed with the SetOrientationFunction method.
55    */
56   enum Orientation
57   {
58     PORTRAIT,          ///< portrait orientation.
59     LANDSCAPE,         ///< landscape orientation.
60     PORTRAIT_INVERSE,  ///< portrait inverse orientation.
61     LANDSCAPE_INVERSE  ///< landscape inverse orientation.
62   };
63
64 public:
65
66   /**
67    * Create an initialized View.
68    * @param fullscreen If true, the view's size is going to be set with the Dali::Stage size. Otherwise a size must be provided.
69    * @return A handle to a newly allocated Dali resource.
70    */
71   static Toolkit::View New( bool fullscreen );
72
73   /**
74    * @copydoc Dali::Toolkit::View::GetContentLayer()
75    */
76   Layer GetContentLayer( unsigned int index ) const;
77
78   /**
79    * @copydoc Dali::Toolkit::View::AddContentLayer()
80    */
81   unsigned int AddContentLayer( Layer layer );
82
83   /**
84    * @copydoc Dali::Toolkit::View::RemoveContentLayer()
85    */
86   void RemoveContentLayer( Layer layer );
87
88   /**
89    * @copydoc Dali::Toolkit::View::GetBackgroundLayer()
90    */
91   Layer GetBackgroundLayer() const;
92
93   /**
94    * @copydoc Dali::Toolkit::View::SetBackground()
95    */
96   void SetBackground( ImageActor image );
97
98   /**
99    * @copydoc Dali::Toolkit::View::SetOrientationFunction()
100    */
101   void SetOrientationFunction( Degree portrait, Degree landscale, Degree portraitInverse, Degree landscapeInverse );
102
103   /**
104    * @copydoc Dali::Toolkit::View::OrientationChanged()
105    *
106    */
107   void OrientationChanged( Dali::Orientation orientation );
108
109   /**
110    * @copydoc Dali::Toolkit::View::SetAutoRotate()
111    *
112    */
113   void SetAutoRotate( bool enabled );
114
115 public:
116
117   /**
118    * @copydoc Dali::Toolkit::View::AnimationStartedSignalOrientation()
119    */
120   Toolkit::View::OrientationAnimationStartedSignalType& OrientationAnimationStartedSignal();
121
122   /**
123    * Connects a callback function with the object's signals.
124    * @param[in] object The object providing the signal.
125    * @param[in] tracker Used to disconnect the signal.
126    * @param[in] signalName The signal to connect to.
127    * @param[in] functor A newly allocated FunctorDelegate.
128    * @return True if the signal was connected.
129    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
130    */
131   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
132
133 private: // From Control
134
135   /**
136    * @copydoc Toolkit::Control::OnInitialize()
137    */
138   virtual void OnInitialize();
139
140   /**
141    * @copydoc Toolkit::Control::OnRelayout()
142    */
143   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
144
145 private:
146
147
148   /**
149    * Constructor.
150    * It initializes View members.
151    * It initializes orientations as follows: portrait 0, landscape 90, portrait inverse 180, landscape inverse 270.
152    * @param fullscreen If true, the view's size is going to be set with the Dali::Stage size. Otherwise a size must be provided.
153    */
154   View(bool fullscreen);
155
156   /**
157    * A reference counted object may only be deleted by calling Unreference()
158    */
159   virtual ~View();
160
161   /**
162    * Return an orientation for the given angle in degrees.
163    * @param degree angle in degrees.
164    * @return An internal orientation.
165    */
166   View::Orientation DegreeToViewOrientation( Degree degree );
167
168   /**
169    * Find a layer in the layer container. Non const method
170    */
171   LayerIt FindLayer( Layer layer );
172
173 private:
174   int            mOrientation;            ///< Stores the given orientation in degrees.
175   bool           mFullScreen;             ///< Stores if the view is fullscreen or not.
176   LayerContainer mContentLayers;          ///< Layer container.
177   unsigned int   mNextLayerIndex;         ///< Next index to be used when a layer is added.
178   Layer          mBackgroundLayer;        ///< The background layer.
179   Animation      mRotateAnimation;        ///< The animation which rotates the view (and all layers added to it)
180   float          mOrientationFunction[4]; ///< The orientation function used to transform from degrees to the internal orientation.
181   bool           mAutoRotateEnabled;      ///< Whether the view rotates if the OrientationChanged method is called.
182
183   Toolkit::View::OrientationAnimationStartedSignalType mOrientationAnimationStartedSignal;
184 };
185
186 } // namespace Internal
187
188
189 // Helpers for public-api forwarding methods
190
191 inline Toolkit::Internal::View& GetImpl( Toolkit::View& view )
192 {
193   DALI_ASSERT_ALWAYS( view );
194
195   Dali::RefObject& handle = view.GetImplementation();
196
197   return static_cast<Toolkit::Internal::View&>( handle );
198 }
199
200 inline const Toolkit::Internal::View& GetImpl( const Toolkit::View& view )
201 {
202   DALI_ASSERT_ALWAYS( view );
203
204   const Dali::RefObject& handle = view.GetImplementation();
205
206   return static_cast<const Toolkit::Internal::View&>( handle );
207 }
208
209 } // namespace Toolkit
210
211 } // namespace Dali
212
213 #endif // __DALI_TOOLKIT_INTERNAL_VIEW_H__