Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUi_LayoutLayout.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUi_LayoutLayout.h
19  * @brief       This is the header file for Layout class.
20  *
21  * This header file contains the declaration of Layout class.
22  */
23
24 #pragma once
25
26 #ifndef _FUI_INTERNAL_LAYOUT_LAYOUT_H_
27 #define _FUI_INTERNAL_LAYOUT_LAYOUT_H_
28
29 #include <FOspConfig.h>
30 #include "FUi_LayoutLayoutContainer.h"
31
32 namespace Tizen { namespace Ui { namespace _Layout
33 {
34
35 class ProxyList;
36 class ProxyListNode;
37 class LayoutItemProxy;
38
39 enum LayoutUpdateFlag
40 {
41         UPDATEFLAG_ERROR = 0x10000000,
42         UPDATEFLAG_NO_FLAG = 0x00000000,
43         UPDATEFLAG_NONE_MODE = 0x00000001,
44         UPDATEFLAG_MATCH_PARENT = 0x00000002,
45         UPDATEFLAG_WRAPCONTENT = 0x00000004,
46         UPDATEFLAG_ALIGNMENT = 0x00000008
47 };
48
49 /**
50  * @class       Layout
51  * @brief       This class is the base class of all the Layout classes.
52  * @since 2.0
53  *
54  * The Layout is the base class of all the Layout classes.
55  * The Layout class support common functions.
56  */
57 class _OSP_EXPORT_ Layout
58         : public Tizen::Base::Object
59 {
60 public:
61         /**
62          * This is the destructor for this class.
63          *
64          * @since 2.0
65          */
66         virtual ~Layout(void);
67
68         /**
69          * Gets the proxy of the current container.
70          *
71          * @return      The current container proxy
72          * @since 2.0
73          */
74         LayoutItemProxy* GetContainerProxy(void);
75
76         /**
77          * Sets the specified location and dimension of the layout
78          *
79          * @param[in]   layoutRect      The rectangle value with the specified location and dimension
80          * @since 2.0
81          */
82         void SetLayoutRect(const LayoutRect layoutRect);
83
84         /**
85          * Gets the location and dimension of the layout.
86          *
87          * @return      The rectangle value with the location and dimension of the layout
88          * @since 2.0
89          */
90         LayoutRect GetLayoutRect(void) const;
91
92         /**
93          * Sets the alignment of the specified item.
94          *
95          * @return              An error code
96          * @param[in]   item    The item for which the alignment is set
97          * @param[in]   align   The alignment
98          * @exception   E_SUCCESS               The method was successful.
99          * @exception   E_INVALID_STATE This instance is in an invalid state.
100          * @exception   E_INVALID_ARG   The alignment parameter is invalid.
101          * @since 2.0
102          */
103         result SetItemAlignment(const LayoutItem& item, const ItemAlign align);
104
105         /**
106          * Gets the alignment of the specified item.
107          *
108          * @return              An error code
109          * @param[in]   item    The item to get the alignment
110          * @param[out]  align   The alignment
111          * @exception   E_SUCCESS               The method was successful.
112          * @exception   E_INVALID_STATE This instance is in an invalid state.
113          * @since 2.0
114          */
115         result GetItemAlignment(const LayoutItem& Item, ItemAlign& align) const;
116
117         /**
118          * Sets the margin of the specified item.
119          *
120          * @return              An error code
121          * @param[in]   item    The item for which the margin is set
122          * @param[in]   margin  The margin
123          * @exception   E_SUCCESS               The method was successful.
124          * @exception   E_INVALID_STATE This instance is in an invalid state.
125          * @since 2.0
126          */
127         result SetItemMargin(const LayoutItem& item, const ItemMargin margin);
128
129         /**
130          * Gets the margin of the specified item.
131          *
132          * @return              An error code
133          * @param[in]   item    The item to get the margin
134          * @param[out]  margin  The margin
135          * @exception   E_SUCCESS               The method was successful.
136          * @exception   E_INVALID_STATE This instance is in an invalid state.
137          * @since 2.0
138          */
139         result GetItemMargin(const LayoutItem& item, ItemMargin& margin) const;
140
141         /**
142          * Sets the width of the specified item with the match policy.
143          *
144          * @return              An error code
145          * @param[in]   item            The item for which the width is set
146          * @patam[in]   matchMode       The match policy
147          * @exception   E_SUCCESS               The method was successful.
148          * @exception   E_INVALID_STATE This instance is in an invalid state.
149          * @since 2.0
150          */
151         result SetItemWidthMatchMode(const LayoutItem& item, const LayoutMatchMode matchMode);
152
153         /**
154          * Gets the width of the specified item with the match policy.
155          *
156          * @return              An error code
157          * @param[in]   item            The item to get the match policy of the width
158          * @patam[out]  matchMode       The match policy
159          * @exception   E_SUCCESS               The method was successful.
160          * @exception   E_INVALID_STATE This instance is in an invalid state.
161          * @since 2.0
162          */
163         result GetItemWidthMatchMode(const LayoutItem& item, LayoutMatchMode& matchMode) const;
164
165         /**
166          * Sets the height of the specified item with the match policy.
167          *
168          * @return              An error code
169          * @param[in]   item            The item for which the height is set
170          * @patam[in]   matchMode       The match policy
171          * @exception   E_SUCCESS               The method was successful.
172          * @exception   E_INVALID_STATE This instance is in an invalid state.
173          * @since 2.0
174          */
175         result SetItemHeightMatchMode(const LayoutItem& item, const LayoutMatchMode matchMode);
176
177         /**
178          * Gets the height of the specified item with the match policy.
179          *
180          * @return              An error code
181          * @param[in]   item            The item to get the match policy of the height
182          * @patam[out]  matchMode       The match policy
183          * @exception   E_SUCCESS               The method was successful.
184          * @exception   E_INVALID_STATE This instance is in an invalid state.
185          * @since 2.0
186          */
187         result GetItemHeightMatchMode(const LayoutItem& item, LayoutMatchMode& matchMode) const;
188
189         /**
190          * Updates the all layout.
191          *
192          * @return              An error code
193          * @exception   E_SUCCESS               The method was successful.
194          * @exception   E_INVALID_STATE This instance is in an invalid state.
195          * @since 2.0
196          */
197         result UpdateLayout(void);
198
199         void SetUpdateState(bool state);
200
201         /**
202          * Updates the current layout & all affected layout.
203          *
204          * @return              An error code
205          * @exception   E_SUCCESS               The method was successful.
206          * @exception   E_INVALID_STATE This instance is in an invalid state.
207          * @since 2.0
208          */
209         result PartialUpdateLayout(void);
210
211         /**
212          * Adds the item at the end of the list maintained by the layout.
213          *
214          * @return              An error code
215          * @param[in]   addItem                 The item to add to the list.
216          * @exception   E_SUCCESS               The method was successful.
217          * @exception   E_INVALID_STATE This instance is in an invalid state.
218          * @since 2.0
219          */
220         virtual result AddItem(LayoutItem& addItem);
221
222         /**
223          * Removes the item from the list maintained by the layout.
224          *
225          * @return              An error code
226          * @param[in]   removeItem              The item to remove from list.
227          * @exception   E_SUCCESS               The method was successful.
228          * @exception   E_INVALID_STATE This instance is in an invalid state.
229          * @since 2.0
230          */
231         result RemoveItem(const LayoutItem& removeItem);
232
233         /**
234          *
235          *
236          * @return              An error code
237          * @param[in]   viewPosX        The x coordinate
238          * @param[in]   viewPosY        The y coordinate
239          * @exception   E_SUCCESS               The method was successful.
240          * @exception   E_INVALID_STATE The layout have a item instance that is in an invalid state.
241          * @since 2.0
242          */
243         result OnChangeViewPosition(int viewPosX, int viewPosY);
244
245         /**
246          * Sets the base location and dimension of the specified item.
247          *
248          * @return              An error code
249          * @param[in]   item            The item for which the base location and dimension are set
250          * @patam[in]   baseRect        The rectangle value with the location and dimension
251          * @exception   E_SUCCESS               The method was successful.
252          * @exception   E_INVALID_STATE This instance is in an invalid state.
253          * @since 2.0
254          */
255         result SetItemBaseRect(const LayoutItem& item, const LayoutRect baseRect);
256
257         /**
258          * Gets the base location and dimension of the specified item.
259          *
260          * @return              An error code
261          * @param[in]   item            The item to get the base location and dimension
262          * @patam[out]  baseRect        The rectangle value with the location and dimension
263          * @exception   E_SUCCESS               The method was successful.
264          * @exception   E_INVALID_STATE This instance is in an invalid state.
265          * @since 2.0
266          */
267         result GetItemBaseRect(const LayoutItem& item, LayoutRect& baseRect) const;
268
269         /**
270          * Checks whether the specified item exists in list.
271          *
272          * @return              @c true, if the item exists @n
273          *                              @c false, otherwise
274          * @param[in]   The item to check.
275          * @since 2.0
276          */
277         bool ItemExists(LayoutItem& item);
278
279 protected:
280         /**
281          * This is the default constructor for this class.
282          *
283          * @since 2.0
284          */
285         Layout(void);
286
287         /**
288          * Calculates the bounds of all children for the specified alignment mode.
289          *
290          * @return              An error code
291          * @param[in]   alignMode
292          * @exception   E_SUCCESS               The method was successful.
293          * @exception   E_INVALID_STATE This instance is in an invalid state.
294          * @since 2.0
295          */
296         result CalculateAlignment(const LayoutAlignMode alignMode = BOTH);
297
298         /**
299          * Overrides this method to provide user-specific layouting code.
300          *
301          * @return              An error code
302          * @param[in]   width
303          * @param[in]   height
304          * @param[in]   layoutUpdating
305          * @exception   E_SUCCESS               The method was successful.
306          * @exception   E_INVALID_STATE This instance is in an invalid state.
307          * @since 2.0
308          */
309         virtual result OnLayout(int width, int height, bool layoutUpdating) = 0;
310
311         void SetPartialUpdateFlag(bool flag);
312         void SetItemList(ProxyList* pItemList);
313         ProxyList* GetProxyList(void) const;
314
315 private:
316         /**
317          * This is the copy constructor for this class.
318          *
319          * @since 2.0
320          */
321         Layout(const Layout&);
322
323         /**
324          * This is the substitution operator for this class.
325          *
326          * @since 2.0
327          */
328         Layout& operator =(const Layout&);
329
330         /**
331          * Set the layout container.
332          *
333          * @return              An error code
334          * @param[in]   pContainer
335          * @exception   E_SUCCESS               The method was successful.
336          * @exception   E_INVALID_STATE This instance is in an invalid state.
337          * @since 2.0
338          */
339         result SetContainer(LayoutContainer* pContainer);
340
341         /**
342          * Creates the layout proxy for the specified item.
343          *
344          * @return              The created proxy.
345          * @param[in]   item
346          * @since 2.0
347          */
348         LayoutItemProxy* CreateProxy(LayoutItem& item);
349
350         /**
351          * Set the root layout flag.
352          *
353          * @param[in]   rootCheck
354          * @since 2.0
355          */
356         void SetRootLayout(bool rootCheck);
357
358         /**
359          * Checks the specified item whether it is already in the item list or not.
360          *
361          * @return              An error code
362          * @param[in]   checkItem       The item to check whether it is already in the list or not
363          * @exception   E_SUCCESS               The specified item is not in the item list.
364          * @exception   E_INVALID_STATE This instance is in an invalid state.
365          * @exception   E_INVALID_ARG   The specified item parameter is null.
366          * @since 2.0
367          */
368         result CheckItem(const LayoutItem& checkItem);
369
370         /**
371          * Internal method of UpdateLayout() and PartialUpdateLayout().
372          *
373          * @return              An error code
374          * @exception
375          * @since 2.0
376          */
377         result UpdateLayoutInternal(LayoutUpdateFlag updateFlag);
378
379         /**
380          * Runs the OnLayout() for pLayout.
381          *
382          * @return              An error code
383          * @exception
384          * @since 2.0
385          */
386         result OnLayoutTrigger(Layout& layout, bool layoutUpdating);
387
388         /**
389          * Gets the update flag for parent layout.
390          *
391          * @return              LayoutUpdateFlag
392          * @exception
393          * @since 2.0
394          */
395         LayoutUpdateFlag CheckParentFlag(void);
396
397         /**
398          * Gets the update flag for current layout.
399          *
400          * @return              LayoutUpdateFlag
401          * @exception
402          * @since 2.0
403          */
404         LayoutUpdateFlag CheckCurrentFlag(void);
405
406         /**
407          * Internal method of CheckParentFlag() and CheckCurrentFlag().
408          *
409          * @return              LayoutUpdateFlag
410          * @exception
411          * @since 2.0
412          */
413         LayoutUpdateFlag CheckFlagInternal(LayoutItemProxy& containerProxy);
414
415         /**
416          * Checks whether the layout has the container.
417          *
418          * @return              bool
419          * @exception
420          * @since 2.0
421          */
422         bool HasLayoutContainer(void);
423
424         result DetermineWindowRectToAllItem(void);
425         result OnDetermine(void);
426
427 private:
428         ProxyList* __pProxyList;
429         int __x;
430         int __y;
431         int __width;
432         int __height;
433
434         LayoutItemProxy* __pContainerProxy;
435         bool __rootLayout;
436
437         bool __updateState;
438         bool __partialUpdateState;
439         bool __determineState;
440
441         friend class LayoutContainer;
442 }; // Layout
443
444 }}} // Tizen::Ui::_Layout
445
446 #endif  // _FUI_INTERNAL_LAYOUT_LAYOUT_H_