Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUi_LayoutLinearLayout.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_LayoutLinearLayout.h
19  * @brief       This is the header file for LinearLayout class.
20  *
21  * This header file contains the declaration of LinearLayout class.
22  */
23
24 #pragma once
25
26 #ifndef _FUI_INTERNAL_LAYOUT_LINEAR_LAYOUT_H_
27 #define _FUI_INTERNAL_LAYOUT_LINEAR_LAYOUT_H_
28
29 #include "FUi_LayoutLayout.h"
30
31 namespace Tizen { namespace Ui { namespace _Layout
32 {
33
34 /**
35  * @class       LinearLayout
36  * @brief       .
37  * @since 2.0
38  *
39  * .
40  */
41 class _OSP_EXPORT_ LinearLayout
42         : public Layout
43 {
44 public:
45         /**
46          * This is the default constructor for this class.
47          *
48          * @since 2.0
49          */
50         LinearLayout(void);
51
52         /**
53          * This is the destructor for this class.
54          *
55          * @since 2.0
56          */
57         virtual ~LinearLayout(void);
58
59         /**
60          * Creates the instance of LinearLayout.
61          *
62          * @since 2.0
63          * @return              The instance of LinearLayout.
64          * @exception   E_SUCCESS               The method was successful.
65          * @exception   E_OUT_OF_MEMORY Insufficient memory.
66          */
67         static LinearLayout* CreateLinearLayoutN(void);
68
69         /**
70          * Checks whether the arguments are valid, and sets the arguments.
71          *
72          * @since 2.0
73          * @return              An error code
74          * @param[in]   orientation     The orientation of the linear layout.
75          * @param[in]   direction               The direction in which the children are attached.
76          * @exception   E_SUCCESS               The method was successful.
77          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
78          */
79         result Initialize(const LinearLayoutOrientation orientation, const LinearLayoutDirection direction);
80
81         /**
82          * Adds the item to the list according to the index.
83          *
84          * @since 2.0
85          * @return              An error code
86          * @param[in]   addItem                 The added item.
87          * @param[in]   index                   The index of list.
88          * @exception   E_SUCCESS               The method was successful.
89          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
90          * @exception   E_INVALID_STATE This instance is in an invalid state.
91          */
92         result AddItemToIndex(LayoutItem& addItem, int index);
93
94         /**
95          * Moves the item according to the index.
96          *
97          * @since 2.0
98          * @return              An error code
99          * @param[in]   item                    The item of list.
100          * @param[in]   index                   The index of list.
101          * @exception   E_SUCCESS               The method was successful.
102          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
103          * @exception   E_INVALID_STATE This instance is in an invalid state.
104          */
105         result MoveItem(LayoutItem& item, int index);
106
107         /**
108          * Swaps the targetItem and the destItem.
109          *
110          * @since 2.0
111          * @return              An error code
112          * @param[in]   targetItem              The target item.
113          * @param[in]   destItem                The destination item.
114          * @exception   E_SUCCESS               The method was successful.
115          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
116          */
117         result SwapItem(LayoutItem& targetItem, LayoutItem& destItem);
118
119         /**
120          * Gets the item count of layout.
121          *
122          * @since 2.0
123          * @return              The item count of layout.
124          * @exception   E_INVALID_STATE This instance is in an invalid state.
125          */
126         int GetItemCount(void) const;
127
128         /**
129          * Gets the index of the specified item.
130          *
131          * @since 2.0
132          * @return              An error code
133          * @param[in]   item                    The layout item.
134          * @param[out]  index                   The index of item.
135          * @exception   E_SUCCESS               The method was successful.
136          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
137          */
138         result GetItemIndex(LayoutItem& item, int& index) const;
139
140         /**
141          * Sets the orientation.
142          *
143          * @since 2.0
144          * @return              An error code
145          * @param[in]   orientation     The orientation of linear layout.
146          * @exception   E_SUCCESS               The method was successful.
147          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
148          */
149         result SetOrientation(const LinearLayoutOrientation orientation);
150
151         /**
152          * Gets the orientation.
153          *
154          * @since 2.0
155          * @return              An error code
156          * @param[out]  orientation     The orientation of linear layout.
157          * @exception   E_SUCCESS               The method was successful.
158          * @exception   E_INVALID_STATE This instance is in an invalid state.
159          */
160         result GetOrientation(LinearLayoutOrientation& orientation) const;
161
162         /**
163          * Sets the direction.
164          *
165          * @since 2.0
166          * @return              An error code
167          * @param[in]   direction               The direction in which the children are attached.
168          * @exception   E_SUCCESS               The method was successful.
169          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
170          */
171         result SetDirection(const LinearLayoutDirection direction);
172
173         /**
174          * Gets the direction.
175          *
176          * @since 2.0
177          * @return              An error code
178          * @param[out]  direction               The direction in which the children are attached.
179          * @exception   E_SUCCESS               The method was successful.
180          * @exception   E_INVALID_STATE This instance is in an invalid state.
181          */
182         result GetDirection(LinearLayoutDirection& direction) const;
183
184         /**
185          * Sets the weight for specified item.
186          *
187          * @since 2.0
188          * @return              An error code
189          * @param[in]   item                    The target item.
190          * @param[in]   weight                  The weight that indicates how much extra space the control occupies in proportion to it.
191          * @exception   E_SUCCESS               The method was successful.
192          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
193          * @exception   E_INVALID_STATE This instance is in an invalid state.
194          */
195         result SetItemWeight(LayoutItem& item, const float weight);
196
197         /**
198          * Gets the weight for specified item.
199          *
200          * @since 2.0
201          * @return              An error code
202          * @param[out]  item                    The target item.
203          * @param[out]  weight                  The weight of target item.
204          * @exception   E_SUCCESS               The method was successful.
205          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
206          * @exception   E_INVALID_STATE This instance is in an invalid state.
207          */
208         result GetItemWeight(const LayoutItem& item, float& weight) const;
209
210         /**
211          * Sets the spacing for specified item.
212          *
213          * @since 2.0
214          * @return              An error code
215          * @param[in]   item                    The target item.
216          * @param[in]   spacing                 The space.
217          * @exception   E_SUCCESS               The method was successful.
218          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
219          * @exception   E_INVALID_STATE This instance is in an invalid state.
220          */
221         result SetItemSpacing(LayoutItem& item, int spacing);
222
223         /**
224          * Gets the spacing for specified item.
225          *
226          * @since 2.0
227          * @return              An error code
228          * @param[in]   item                    The target item.
229          * @param[out]  spacing                 The space of target item.
230          * @exception   E_SUCCESS               The method was successful.
231          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
232          * @exception   E_INVALID_STATE This instance is in an invalid state.
233          */
234         result GetItemSpacing(const LayoutItem& item, int& spacing) const;
235
236 protected:
237         /**
238          * Calculates the position and bounds of all chindren, and applies to the control.
239          *
240          * @return              An error code
241          * @param[in]   width
242          * @param[in]   height
243          * @param[in]   layoutUpdating
244          * @exception   E_SUCCESS               The method was successful.
245          * @exception   E_INVALID_STATE This instance is in an invalid state.
246          * @since 2.0
247          */
248         virtual result OnLayout(int width, int height, bool layoutUpdating);
249
250 private:
251         /**
252          * This is the copy constructor for this class.
253          *
254          * @since 2.0
255          */
256         LinearLayout(const LinearLayout&);
257
258         /**
259          * This is the substitution operator for this class.
260          *
261          * @since 2.0
262          */
263         LinearLayout& operator =(const LinearLayout&);
264
265         /**
266          * Calculates the size & position of all children. @n
267          * Wrapper method of CalcHorizontalPosSize and CalcVerticalPosSize. @n
268          * Used by OnLayout.
269          *
270          * @since 2.0
271          * @return              An error code
272          * @param[out]  rightBound
273          * @param[out]  bottomBounds
274          * @exception   E_SUCCESS               The method was successful.
275          * @exception   E_INVALID_STATE This instance is in an invalid state.
276          */
277         result CalculatePositionSize(int& rightBound, int& bottomBound);
278
279         /**
280          * If orientation is horizontal, Calculates the size & position of all children. @n
281          * Used by CalcPosSize.
282          *
283          * @since 2.0
284          * @return              An error code
285          * @param[out]  rightBound
286          * @param[out]  bottomBound
287          * @exception   E_SUCCESS               The method was successful.
288          * @exception   E_INVALID_STATE This instance is in an invalid state.
289          */
290         result CalculateHorizontalPositionSize(int& rightBound, int& bottomBound);
291
292         /**
293          * If orientation is vertical, Calculates the size & position of all children. @n
294          * Used by CalcPosSize.
295          *
296          * @since 2.0
297          * @return              An error code
298          * @param[out]  rightBound
299          * @param[out]  bottomBound
300          * @exception   E_SUCCESS               The method was successful.
301          * @exception   E_INVALID_STATE This instance is in an invalid state.
302          */
303         result CalculateVerticalPositonSize(int& rightBound, int& bottomBound);
304
305         /**
306          * Calculates the bound in empty space according to weight. @n
307          * Used by OnLayout.
308          *
309          * @since 2.0
310          * @return              An error code
311          * @param[out]  rightBound
312          * @param[out]  bottomBound
313          * @exception   E_SUCCESS               The method was successful.
314          * @exception   E_INVALID_STATE This instance is in an invalid state.
315          */
316         result CalculateWeight(int& rightBound, int& bottomBound);
317
318         /**
319          * If orientation is horizontal, Calculates the bound in empty space according to weight. @n
320          * Used by CalcWeight.
321          * @since 2.0
322          * @return              An error code
323          * @param[out]  emptySpace
324          * @exception   E_SUCCESS               The method was successful.
325          * @exception   E_INVALID_STATE This instance is in an invalid state.
326          */
327         result CalculateHorizontalWeight(int& emptySpace);
328
329         /**
330          * If orientation is vertical, Calculates the bound in empty space according to weight. @n
331          * Used by CalcWeight.
332          * @since 2.0
333          * @return              An error code
334          * @param[in]   emptySpace
335          * @exception   E_SUCCESS               The method was successful.
336          * @exception   E_INVALID_STATE This instance is in an invalid state.
337          */
338         result CalculateVerticalWeight(int& emptySpace);
339
340         /**
341          * Checks whether container is wrap content mode, and calculate size. @n
342          * Used by OnLayout.
343          * @since 2.0
344          * @return              An error code
345          * @param[in]   rightBound
346          * @param[in]   bottomBound
347          * @param[in]   layoutUpdating
348          * @exception   E_SUCCESS               The method was successful.
349          * @exception   E_INVALID_STATE This instance is in an invalid state.
350          */
351         result CalculateWrapContent(LayoutItemProxy& containerProxy, int rightBound, int bottomBound, bool layoutUpdating);
352
353         /**
354          * Checks whether container is match parent mode, and calculate size. @n
355          * Used by OnLayout.
356          * @since 2.0
357          * @return              An error code
358          * @exception   E_SUCCESS               The method was successful.
359          * @exception   E_INVALID_STATE This instance is in an invalid state.
360          */
361         result CalculateMatchParent(void);
362
363         /**
364          * Corrects the bounds according to orientation. @n
365          * Used by OnLayout.
366          * @since 2.0
367          * @return              An error code
368          * @exception   E_SUCCESS               The method was successful.
369          * @exception   E_INVALID_STATE This instance is in an invalid state.
370          */
371         result CalculateCorrectedAlignment(void);
372
373 private:
374         LinearLayoutOrientation __orientation;
375         LinearLayoutDirection __direction;
376         float __weightSum;
377 }; // LinearLayout
378
379 }}} // Tizen::Ui::_Layout
380
381 #endif //_FUI_INTERNAL_LAYOUT_LINEAR_LAYOUT_H_