1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 :
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Eric D Vaughan (original author)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsGrid_h___
41 : #define nsGrid_h___
42 :
43 : #include "nsStackLayout.h"
44 : #include "nsIGridPart.h"
45 : #include "nsCOMPtr.h"
46 : #include "nsIFrame.h"
47 :
48 : class nsGridRowGroupLayout;
49 : class nsGridRowLayout;
50 : class nsBoxLayoutState;
51 : class nsGridCell;
52 :
53 : //#define DEBUG_grid 1
54 :
55 : /**
56 : * The grid data structure, i.e., the grid cellmap.
57 : */
58 : class nsGrid
59 : {
60 : public:
61 : nsGrid();
62 : ~nsGrid();
63 :
64 : nsGridRow* GetColumnAt(PRInt32 aIndex, bool aIsHorizontal = true);
65 : nsGridRow* GetRowAt(PRInt32 aIndex, bool aIsHorizontal = true);
66 : nsGridCell* GetCellAt(PRInt32 aX, PRInt32 aY);
67 :
68 : void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState);
69 : void RebuildIfNeeded();
70 :
71 : // For all the methods taking an aIsHorizontal parameter:
72 : // * When aIsHorizontal is true, the words "rows" and (for
73 : // GetColumnCount) "columns" refer to their normal meanings.
74 : // * When aIsHorizontal is false, the meanings are flipped.
75 : // FIXME: Maybe eliminate GetColumnCount and change aIsHorizontal to
76 : // aIsRows? (Calling it horizontal doesn't really make sense because
77 : // row groups and columns have vertical orientation, whereas column
78 : // groups and rows are horizontal.)
79 :
80 : nsSize GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
81 : nsSize GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
82 : nsSize GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
83 : nscoord GetRowFlex(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
84 :
85 : nscoord GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
86 : nscoord GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
87 : nscoord GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, bool aIsHorizontal = true);
88 : void GetRowOffsets(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aTop, nscoord& aBottom, bool aIsHorizontal = true);
89 :
90 : void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, bool aIsHorizontal = true);
91 : void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, bool aIsHorizontal = true);
92 : void DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState);
93 : #ifdef DEBUG_grid
94 : void PrintCellMap();
95 : #endif
96 : PRInt32 GetExtraColumnCount(bool aIsHorizontal = true);
97 : PRInt32 GetExtraRowCount(bool aIsHorizontal = true);
98 :
99 : // accessors
100 0 : void SetBox(nsIBox* aBox) { mBox = aBox; }
101 : nsIBox* GetBox() { return mBox; }
102 0 : nsIBox* GetRowsBox() { return mRowsBox; }
103 0 : nsIBox* GetColumnsBox() { return mColumnsBox; }
104 : PRInt32 GetRowCount(PRInt32 aIsHorizontal = true);
105 : PRInt32 GetColumnCount(PRInt32 aIsHorizontal = true);
106 :
107 : static nsIBox* GetScrolledBox(nsIBox* aChild);
108 : static nsIBox* GetScrollBox(nsIBox* aChild);
109 : static nsIGridPart* GetPartFromBox(nsIBox* aBox);
110 : void GetFirstAndLastRow(nsBoxLayoutState& aState,
111 : PRInt32& aFirstIndex,
112 : PRInt32& aLastIndex,
113 : nsGridRow*& aFirstRow,
114 : nsGridRow*& aLastRow,
115 : bool aIsHorizontal);
116 :
117 : private:
118 :
119 : nsMargin GetBoxTotalMargin(nsIBox* aBox, bool aIsHorizontal = true);
120 :
121 : void FreeMap();
122 : void FindRowsAndColumns(nsIBox** aRows, nsIBox** aColumns);
123 : void BuildRows(nsIBox* aBox, PRInt32 aSize, nsGridRow** aColumnsRows, bool aIsHorizontal = true);
124 : nsGridCell* BuildCellMap(PRInt32 aRows, PRInt32 aColumns);
125 : void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount, PRInt32 aColumnCount, bool aIsHorizontal = true);
126 : void CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
127 : void SetLargestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true);
128 : void SetSmallestSize(nsSize& aSize, nscoord aHeight, bool aIsHorizontal = true);
129 : bool IsGrid(nsIBox* aBox);
130 :
131 : // the box that implement the <grid> tag
132 : nsIBox* mBox;
133 :
134 : // an array of row object
135 : nsGridRow* mRows;
136 :
137 : // an array of columns objects.
138 : nsGridRow* mColumns;
139 :
140 : // the first in the <grid> that implements the <rows> tag.
141 : nsIBox* mRowsBox;
142 :
143 : // the first in the <grid> that implements the <columns> tag.
144 : nsIBox* mColumnsBox;
145 :
146 : // a flag that is false tells us to rebuild the who grid
147 : bool mNeedsRebuild;
148 :
149 : // number of rows and columns as defined by the XUL
150 : PRInt32 mRowCount;
151 : PRInt32 mColumnCount;
152 :
153 : // number of rows and columns that are implied but not
154 : // explicitly defined int he XUL
155 : PRInt32 mExtraRowCount;
156 : PRInt32 mExtraColumnCount;
157 :
158 : // x,y array of cells in the rows and columns
159 : nsGridCell* mCellMap;
160 :
161 : // a flag that when true suppresses all other MarkDirties. This
162 : // prevents lots of extra work being done.
163 : bool mMarkingDirty;
164 : };
165 :
166 : #endif
167 :
|