Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / inc / FUi_LayoutTableLayout.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_LayoutTableLayout.h
19  * @brief       This is the header file for TableLayout class.
20  *
21  * This header file contains the declaration of TableLayout class.
22  */
23
24 #pragma once
25
26 #ifndef _FUI_INTERNAL_LAYOUT_TABLE_LAYOUT_H_
27 #define _FUI_INTERNAL_LAYOUT_TABLE_LAYOUT_H_
28
29 #include <FBaseColLinkedList.h>
30 #include "FUi_LayoutLayout.h"
31
32 namespace Tizen { namespace Ui { namespace _Layout
33 {
34
35 struct RowInfo
36 {
37         int y;
38         int height;
39         bool rowCollapsed;
40         bool heightShrinkable;
41         bool heightStretchable;
42         int heightSpacing;
43         int maxHeight;
44         int mergedHeight;
45 };
46
47 struct ColumnInfo
48 {
49         int x;
50         int width;
51         bool columnCollapsed;
52         bool widthShrinkable;
53         bool widthStretchable;
54         int widthSpacing;
55         int maxWidth;
56         int mergedWidth;
57 };
58
59 class _OSP_EXPORT_ TableLayout
60         : public Layout
61 {
62 public:
63         /**
64          * This is the default constructor for this class.
65          *
66          * @since 2.0
67          */
68         TableLayout(void);
69
70         /**
71          * This is the destructor for this class.
72          *
73          * @since 2.0
74          */
75         virtual ~TableLayout(void);
76
77         /**
78          * Creates the instance of TableLayout.
79          *
80          * @since 2.0
81          * @return              The instance of TableLayout.
82          * @exception   E_SUCCESS               The method was successful.
83          * @exception   E_OUT_OF_MEMORY Insufficient memory.
84          */
85         static TableLayout* CreateTableLayoutN(void);
86
87         /**
88          * Creates the table.
89          *
90          * @since 2.0
91          * @return              An error code
92          * @param[in]   row                     The number of rows.
93          * @param[in]   column                  The number of columns.
94          * @param[in]   spacing                 The space.
95          * @exception   E_SUCCESS               The method was successful.
96          * @exception   E_INVALID_STATE This instance is in an invalid state.
97          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
98          * @exception   E_OUT_OF_MEMORY Insufficient memory.
99          */
100         result CreateTable(int row, int column, int spacing = 0);
101
102         /**
103          * Merges from the start cell to the end cell.
104          *
105          * @since 2.0
106          * @return              An error code
107          * @param[in]   startRow                The start row.
108          * @param[in]   startCol                The start column.
109          * @param[in]   endRow                  The end row.
110          * @param[in]   endCol                  The end column.
111          * @exception   E_SUCCESS               The method was successful.
112          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
113          * @exception   E_SYSTEM                A system error occurred.
114          */
115         result Merge(int startRow, int startCol, int endRow, int endCol);
116
117         /**
118          * Unmerges the specified cell.
119          *
120          * @since 2.0
121          * @return              An error code
122          * @param[in]   row                     The target row.
123          * @param[in]   column                  The target column.
124          * @exception   E_SUCCESS               The method was successful.
125          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
126          * @exception   E_INVALID_STATE The target is impossible to unmerge.
127          */
128         result Unmerge(int row, int column);
129
130         /**
131          * Gets the size of merged cell for specified row and column.
132          *
133          * @since 2.0
134          * @return              An error code
135          * @param[in]   row                     The target row.
136          * @param[in]   column                  The target column.
137          * @param[out]  rowSize                 The merged row size.
138          * @param[out]  columnSize              The merged column size.
139          * @exception   E_SUCCESS               The method was successful.
140          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
141          * @exception   E_INVALID_STATE The target is merged by other cell.
142          */
143         result GetMergeSize(int row, int column, int& rowSize, int& columnSize) const;
144
145         /**
146          * Adds the item into the empty cell.
147          *
148          * @since 2.0
149          * @return              An error code
150          * @param[in]   pAddItem                The added item.
151          * @exception   E_SUCCESS               The method was successful.
152          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
153          * @exception   E_INVALID_STATE The target cell has been already occupied.
154          */
155         result AddItem(LayoutItem& addItem);
156
157         /**
158          * Adds the item into the specified cell.
159          *
160          * @since 2.0
161          * @return              An error code
162          * @param[in]   pAddItem                The added item.
163          * @param[in]   row                     The target row.
164          * @param[in]   column                  The target column.
165          * @exception   E_SUCCESS               The method was successful.
166          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
167          * @exception   E_INVALID_STATE The target cell has been already occupied.
168          */
169         result AddItem(LayoutItem& addItem, int row, int column, bool mergedState = false);
170
171         /**
172          * Gets the item of the specified cell.
173          *
174          * @since 2.0
175          * @return              LayoutItem
176          * @param[in]   row                     The target row.
177          * @param[in]   column                  The target column.
178          */
179         LayoutItem* GetItem(int row, int column) const;
180
181         /**
182          * Sets the row and column of specified item.
183          *
184          * @since 2.0
185          * @return              An error code
186          * @param[in]   pItem                   The item to change the position.
187          * @param[in]   row                     The target row.
188          * @param[in]   column                  The target column.
189          * @exception   E_SUCCESS               The method was successful.
190          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
191          * @exception   E_INVALID_STATE The target cell has been already occupied.
192          */
193         result SetItemPosition(const LayoutItem& item, int row, int column);
194
195         /**
196          * Gets the row and column of specified item.
197          *
198          * @since 2.0
199          * @return              An error code
200          * @param[in]   pItem                   The item to change the position.
201          * @param[in]   row                     The row of item.
202          * @param[in]   column                  The column of item.
203          * @exception   E_SUCCESS               The method was successful.
204          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
205          */
206         result GetItemPosition(const LayoutItem& item, int& row, int& column) const;
207
208         /**
209          * Swaps the position between item1 and item2.
210          *
211          * @since 2.0
212          * @return              An error code
213          * @param[in]   pItem1                  The target item 1.
214          * @param[in]   pItem2                  The target item 2.
215          * @exception   E_SUCCESS               The method was successful.
216          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
217          */
218         result SwapItemPosition(LayoutItem& item1, LayoutItem& item2);
219
220         /**
221          * Adds the row to the table.
222          *
223          * @since 2.0
224          * @exception   E_SUCCESS               The method was successful.
225          * @exception   E_OUT_OF_MEMORY Insufficient memory.
226          * @return              void
227          */
228         result AddRow(void);
229
230         /**
231          * Adds the column to the table.
232          *
233          * @since 2.0
234          * @exception   E_SUCCESS               The method was successful.
235          * @exception   E_OUT_OF_MEMORY Insufficient memory.
236          * @return              void
237          */
238         result AddColumn(void);
239
240         /**
241          * Deletes the specified row from the table.
242          *
243          * @since 2.0
244          * @return              An error code
245          * @param[in]   row                     The target row.
246          * @exception   E_SUCCESS               The method was successful.
247          * @exception   E_INVALID_STATE This instance is in an invalid state.
248          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
249          * @exception   E_SYSTEM                A system error occurred.
250          */
251         result DeleteRow(int row);
252
253         /**
254          * Deletes the specified column from the table.
255          *
256          * @since 2.0
257          * @return              An error code
258          * @param[in]   column                  The target column.
259          * @exception   E_SUCCESS               The method was successful.
260          * @exception   E_INVALID_STATE This instance is in an invalid state.
261          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
262          * @exception   E_SYSTEM                A system error occurred.
263          */
264         result DeleteColumn(int column);
265
266         /**
267          * Sets the collapse property for the specified row.
268          *
269          * @since 2.0
270          * @return              An error code
271          * @param[in]   row                     The target row.
272          * @param[in]   collapsed               The collase state.
273          * @exception   E_SUCCESS               The method was successful.
274          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
275          */
276         result SetRowCollapsed(int rowIndex, bool collapsed);
277
278         /**
279          * Checks whether the row is collapsed.
280          *
281          * @since 2.0
282          * @return              @c true, The row is collapsed @n
283                                         @c false, otherwise
284          * @param[in]   row                     The target row.
285          */
286         bool GetRowCollapsed(int rowIndex) const;
287
288         /**
289          * Sets the collapse property for the specified column.
290          *
291          * @since 2.0
292          * @return              An error code
293          * @param[in]   column                  The target column.
294          * @param[in]   collapsed               The collase state.
295          * @exception   E_SUCCESS               The method was successful.
296          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
297          */
298         result SetColumnCollapsed(int column, bool collapsed);
299
300         /**
301          * Checks whether the column is collapsed.
302          *
303          * @since 2.0
304          * @return              @c true, The column is collapsed @n
305                                         @c false, otherwise
306          * @param[in]   column                  The target column.
307          */
308         bool GetColumnCollapsed(int column) const;
309
310         /**
311          * Sets the shrinkable property for the specified row.
312          *
313          * @since 2.0
314          * @return              An error code
315          * @param[in]   row                     The target row.
316          * @param[in]   shrinkable              The shrinkable state.
317          * @exception   E_SUCCESS               The method was successful.
318          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
319          */
320         result SetRowShrinkable(int row, bool shrinkable);
321
322         /**
323          * Checks whether the row is shrinkable.
324          *
325          * @since 2.0
326          * @return              @c true, The row is shrinkable @n
327                                         @c false, otherwise
328          * @param[in]   row                     The target row.
329          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
330          */
331         bool GetRowShrinkable(int row) const;
332
333         /**
334          * Sets the shrinkable property for the specified column.
335          *
336          * @since 2.0
337          * @return              An error code
338          * @param[in]   column                  The target column.
339          * @param[in]   shrinkable              The shrinkable state.
340          * @exception   E_SUCCESS               The method was successful.
341          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
342          */
343         result SetColumnShrinkable(int column, bool shrinkable);
344
345         /**
346          * Checks whether the column is shrinkable.
347          *
348          * @since 2.0
349          * @return              @c true, The column is shrinkable @n
350                                         @c false, otherwise
351          * @param[in]   column                  The target column.
352          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
353          */
354         bool GetColumnShrinkable(int column) const;
355
356         /**
357          * Sets the stretchable property for the specified row.
358          *
359          * @since 2.0
360          * @return              An error code
361          * @param[in]   row                     The target row.
362          * @param[in]   stretchable     The stretchable state.
363          * @exception   E_SUCCESS               The method was successful.
364          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
365          */
366         result SetRowStretchable(int row, bool stretchable);
367
368         /**
369          * Checks whether the row is stretchable.
370          *
371          * @since 2.0
372          * @return              @c true, The row is stretchable @n
373                                         @c false, otherwise
374          * @param[in]   row                     The target row.
375          */
376         bool GetRowStretchable(int row) const;
377
378         /**
379          * Sets the stretchable property for the specified column.
380          *
381          * @since 2.0
382          * @return              An error code
383          * @param[in]   column                  The target column.
384          * @param[in]   stretchable     The stretchable state.
385          * @exception   E_SUCCESS               The method was successful.
386          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
387          */
388         result SetColumnStretchable(int column, bool stretchable);
389
390         /**
391          * Checks whether the column is stretchable.
392          *
393          * @since 2.0
394          * @return              @c true, The column is stretchable @n
395                                         @c false, otherwise
396          * @param[in]   column                  The target column.
397          */
398         bool GetColumnStretchable(int column) const;
399
400         /**
401          * Sets the spacing for the specified row.
402          *
403          * @since 2.0
404          * @return              An error code
405          * @param[in]   row                     The target row.
406          * @param[in]   heightSpacing   The space size.
407          * @exception   E_SUCCESS               The method was successful.
408          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
409          */
410         result SetRowSpacing(int row, int heightSpacing);
411
412         /**
413          * Gets the spacing of the specified row.
414          *
415          * @since 2.0
416          * @return              An error code
417          * @param[in]   row                     The target row.
418          * @param[out]  spacing                 The height space of target row.
419          * @exception   E_SUCCESS               The method was successful.
420          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
421          */
422         result GetRowSpacing(int row, int& spacing) const;
423
424         /**
425          * Sets the spacing for specified column.
426          *
427          * @since 2.0
428          * @return              An error code
429          * @param[in]   column                  The target column.
430          * @param[in]   widthSpacing    The space size.
431          * @exception   E_SUCCESS               The method was successful.
432          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
433          */
434         result SetColumnSpacing(int column, int widthSpacing);
435
436         /**
437          * Gets the spacing of the specified column.
438          *
439          * @since 2.0
440          * @return              An error code
441          * @param[in]   column                  The target column.
442          * @param[out]  spacing                 The width space of target column.
443          * @exception   E_SUCCESS               The method was successful.
444          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
445          */
446         result GetColumnSpacing(int column, int& spacing) const;
447
448         /**
449          * Sets the fill property for specified cell.
450          *
451          * @since 2.0
452          * @return              An error code
453          * @param[in]   row                     The target row.
454          * @param[in]   column                  The target column.
455          * @param[in]   fillWidth               The fill width state.
456          * @param[in]   fillHeight              The fill height state.
457          * @exception   E_SUCCESS               The method was successful.
458          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
459          * @exception   E_SYSTEM                A system error occurred.
460          */
461         result SetFillCell(int row, int column, bool fillWidth, bool fillHeight);
462
463         /**
464          * Checks whether the cell has fill property.
465          *
466          * @since 2.0
467          * @return              An error code
468          * @param[in]   row                     The target row.
469          * @param[in]   column                  The target column.
470          * @param[out]  fillWidth               The fill width state of the target cell.
471          * @param[out]  fillHeight              The fill height state of the target cell.
472          * @exception   E_SUCCESS               The method was successful.
473          * @exception   E_OUT_OF_RANGE  Input Argument value over the max value.
474          * @exception   E_SYSTEM                A system error occurred.
475          */
476         result GetFillCell(int row, int column, bool& fillWidth, bool& fillHeight) const;
477
478 protected:
479         /**
480          * Calculates the position and bounds of all chindren, and applies to the control.
481          *
482          * @return              An error code
483          * @param[in]   width
484          * @param[in]   height
485          * @param[in]   layoutUpdating
486          * @exception   E_SUCCESS               The method was successful.
487          * @exception   E_INVALID_STATE This instance is in an invalid state.
488          * @since 2.0
489          */
490         virtual result OnLayout(int widht, int height, bool updateLayouting);
491
492 private:
493         /**
494          * This is the copy constructor for this class.
495          *
496          * @since 2.0
497          */
498         TableLayout(const TableLayout&);
499
500         /**
501          * This is the substitution operator for this class.
502          *
503          * @since 2.0
504          */
505         TableLayout& operator =(const TableLayout&);
506
507         /**
508          * Calculates the size of the all cell. @n
509          * Used by OnLayout.
510          *
511          * @since 2.0
512          * @return              An error code
513          * @exception   E_SUCCESS               The method was successful.
514          * @exception   E_INVALID_STATE This instance is in an invalid state.
515          */
516         result CalculateSize(void);
517
518         /**
519          * Calculates the size of the all shrinkable cell. @n
520          * Used by OnLayout.
521          *
522          * @since 2.0
523          * @return              An error code
524          * @param[in]   windowRect
525          * @exception   E_SUCCESS               The method was successful.
526          * @exception   E_INVALID_STATE This instance is in an invalid state.
527          * @exception   E_OUT_OF_MEMORY Insufficient memory.
528          */
529         result CalculateShrinkCell(LayoutRect windowRect);
530
531         /**
532          * Calculates the size of the all stretchable cell. @n
533          * Used by OnLayout.
534          *
535          * @since 2.0
536          * @return              An error code
537          * @param[in]   windowRect
538          * @exception   E_SUCCESS               The method was successful.
539          * @exception   E_INVALID_STATE This instance is in an invalid state.
540          * @exception   E_OUT_OF_MEMORY Insufficient memory.
541          */
542         result CalculateStretchCell(LayoutRect windowRect);
543
544         /**
545          * Calculates the size of the merged cell. @n
546          * Used by AdjustTableLayout.
547          *
548          * @since 2.0
549          * @return              An error code
550          * @param[in]   row
551          * @param[in]   column
552          * @param[out]  size
553          * @exception   E_SUCCESS               The method was successful.
554          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
555          */
556         result CalculateMergeCell(int row, int column, LayoutSize& size);
557
558         /**
559          * Calculates the size of item for alignment. @n
560          * Used by AdjustTableLayout.
561          *
562          * @since 2.0
563          * @return              The calculated rect
564          * @param[in]   pItemProxy
565          * @param[in]   cellRect
566          * @param[in]   itemRect
567          * @param[in]   horizonEdge
568          * @param[in]   verticalEdge
569          * @exception   E_SUCCESS               The method was successful.
570          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
571          */
572         LayoutRect CalculateAlign(LayoutItemProxy& itemProxy, const LayoutRect cellRect, const LayoutRect itemRect, const HorizontalAlign horizonEdge, const VerticalAlign verticalEdge);
573
574         /**
575          * Finally, adjusts the size. @n
576          * Used by OnLayout.
577          *
578          * @since 2.0
579          * @return              An error code
580          * @param[in]   windowRect
581          * @param[in]   updateLayouting
582          * @exception   E_SUCCESS               The method was successful.
583          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
584          */
585         result AdjustTableLayout(const LayoutRect windowRect, bool updateLayouting);
586
587         /**
588          * Gets the node of specified cell.
589          *
590          * @since 2.0
591          * @return              The node for row and column
592          * @param[in]   row
593          * @param[in]   column
594          */
595         ProxyListNode* GetNode(int row, int column) const;
596
597         /**
598          * Gets the size of the specified cell.
599          *
600          * @since 2.0
601          * @return              An error code
602          * @param[in]   cellIndex               The target cell index.
603          * @param[out]  rect                    The rect of target cell.
604          * @exception   E_SUCCESS               The method was successful.
605          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
606          */
607         result GetCellSize(int cellIndex, LayoutRect& rect);
608
609         /**
610          * Gets the row number from specified cell ID.
611          *
612          * @since 2.0
613          * @return              The row number
614          * @param[in]   id                              The ID of target cell.
615          */
616         int GetRow(int id) const;
617
618         /**
619          * Gets the column number from specified cell ID.
620          *
621          * @since 2.0
622          * @return              The column number
623          * @param[in]   id                              The ID of target cell.
624          */
625         int GetColumn(int id) const;
626
627         /**
628          * Makes & Gets the cell ID from specified row number and column number.
629          *
630          * @since 2.0
631          * @return              The cell ID
632          * @param[in]   row                             The row number
633          * @param[in]   column                  The column number
634          */
635         int MakeCellID(int row, int column) const;
636
637 // property
638 private:
639         // Table metrics information
640         int __row;
641         int __column;
642         int __maxRow;
643         int __maxColumn;
644
645         // Shrink, Stretch Count
646         int __shrinkRowCount;
647         int __shrinkColumnCount;
648         int __stretchRowCount;
649         int __stretchColumnCount;
650
651         bool __rowShrinkable;
652         bool __columnShrinkable;
653         bool __rowStretchable;
654         bool __columnStretchable;
655
656         // Rows information
657         RowInfo* __pRowInfo;
658         // Columns information
659         ColumnInfo* __pColInfo;
660
661         static const int INVALID_CELL_ID = 0xFFFFFFFF;
662         static const int NOT_MERGED = 0xFFFFFFFE;
663
664         Tizen::Base::Collection::LinkedList __mergedCellList;
665
666         friend class TableItemInfo;
667 }; // TableLayout
668
669 }}} //Tizen::Ui::_Layout
670
671 #endif // _FUI_INTERNAL_LAYOUT_TABLE_LAYOUT_H_