Back to index

lightning-sunbird  0.9+nobinonly
nsGrid.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code.
00017  *
00018  * The Initial Developer of the Original Code is 
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Eric D Vaughan (original author)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef nsGrid_h___
00041 #define nsGrid_h___
00042 
00043 #include "nsStackLayout.h"
00044 #include "nsIGridPart.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsIFrame.h"
00047 
00048 class nsGridRowGroupLayout;
00049 class nsGridRowLayout;
00050 class nsBoxLayoutState;
00051 class nsGridCell;
00052 
00053 //#define DEBUG_grid 1
00054 
00055 class nsGrid
00056 {
00057 public:
00058   nsGrid();
00059   ~nsGrid();
00060 
00061   nsGridRow* GetColumnAt(PRInt32 aIndex, PRBool aIsHorizontal = PR_TRUE);
00062   nsGridRow* GetRowAt(PRInt32 aIndex, PRBool aIsHorizontal = PR_TRUE);
00063   nsGridCell* GetCellAt(PRInt32 aX, PRInt32 aY);
00064 
00065   void NeedsRebuild(nsBoxLayoutState& aBoxLayoutState);
00066   void RebuildIfNeeded();
00067 
00068   nsresult GetPrefRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsHorizontal = PR_TRUE);
00069   nsresult GetMinRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsHorizontal = PR_TRUE);
00070   nsresult GetMaxRowSize(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nsSize& aSize, PRBool aIsHorizontal = PR_TRUE);
00071   nsresult GetRowFlex(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aSize, PRBool aIsHorizontal = PR_TRUE);
00072 
00073   nsresult GetPrefRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsHorizontal = PR_TRUE);
00074   nsresult GetMinRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsHorizontal = PR_TRUE);
00075   nsresult GetMaxRowHeight(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, nscoord& aHeight, PRBool aIsHorizontal = PR_TRUE);
00076   void GetRowOffsets(nsBoxLayoutState& aState, PRInt32 aIndex, nscoord& aTop, nscoord& aBottom, PRBool aIsHorizontal = PR_TRUE);
00077 
00078   void RowChildIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aRowIndex, PRInt32 aColumnIndex, PRBool aIsHorizontal = PR_TRUE);
00079   void RowIsDirty(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsHorizontal = PR_TRUE);
00080   void RowAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsHorizontal = PR_TRUE);
00081   void CellAddedOrRemoved(nsBoxLayoutState& aBoxLayoutState, PRInt32 aIndex, PRBool aIsHorizontal = PR_TRUE);
00082   void DirtyRows(nsIBox* aRowBox, nsBoxLayoutState& aState);
00083 #ifdef DEBUG_grid
00084   void PrintCellMap();
00085 #endif
00086   PRInt32 GetExtraColumnCount(PRBool aIsHorizontal = PR_TRUE);
00087   PRInt32 GetExtraRowCount(PRBool aIsHorizontal = PR_TRUE);
00088 
00089 // accessors
00090   void SetBox(nsIBox* aBox) { mBox = aBox; }
00091   nsIBox* GetBox() { return mBox; }
00092   nsIBox* GetRowBox() { return mRowBox; }
00093   nsIBox* GetColumnBox() { return mColumnBox; }
00094   nsGridRow* GetColumns();
00095   nsGridRow* GetRows();
00096   PRInt32 GetRowCount(PRInt32 aIsHorizontal = PR_TRUE);
00097   PRInt32 GetColumnCount(PRInt32 aIsHorizontal = PR_TRUE);
00098 
00099   static nsIBox* GetScrolledBox(nsIBox* aChild);
00100   static nsIBox* GetScrollBox(nsIBox* aChild);
00101   void GetFirstAndLastRow(nsBoxLayoutState& aState, 
00102                           PRInt32& aFirstIndex, 
00103                           PRInt32& aLastIndex, 
00104                           nsGridRow*& aFirstRow,
00105                           nsGridRow*& aLastRow,
00106                           PRBool aIsHorizontal);
00107 
00108 private:
00109   void GetPartFromBox(nsIBox* aBox, nsIGridPart** aPart);
00110   void GetBoxTotalMargin(nsIBox* aBox, nsMargin& aMargin, PRBool aIsHorizontal = PR_TRUE);
00111 
00112   void FreeMap();
00113   void FindRowsAndColumns(nsIBox** aRows, nsIBox** aColumns);
00114   void BuildRows(nsIBox* aBox, PRBool aSize, nsGridRow** aColumnsRows, PRBool aIsHorizontal = PR_TRUE);
00115   void BuildCellMap(PRInt32 aRows, PRInt32 aColumns, nsGridCell** aCells);
00116   void PopulateCellMap(nsGridRow* aRows, nsGridRow* aColumns, PRInt32 aRowCount, PRInt32 aColumnCount, PRBool aIsHorizontal = PR_TRUE);
00117   void CountRowsColumns(nsIBox* aBox, PRInt32& aRowCount, PRInt32& aComputedColumnCount);
00118   void SetLargestSize(nsSize& aSize, nscoord aHeight, PRBool aIsHorizontal = PR_TRUE);
00119   void SetSmallestSize(nsSize& aSize, nscoord aHeight, PRBool aIsHorizontal = PR_TRUE);
00120   PRBool IsGrid(nsIBox* aBox);
00121 
00122   // the box that implement the <grid> tag
00123   nsIBox* mBox;
00124 
00125   // an array of row object
00126   nsGridRow* mRows;
00127 
00128   // an array of columns objects.
00129   nsGridRow* mColumns;
00130 
00131   // the first in the <grid> that implements the <rows> tag.
00132   nsIBox* mRowBox;
00133 
00134   // the first in the <grid> that implements the <columns> tag.
00135   nsIBox* mColumnBox;
00136 
00137   // a flag that is false tells us to rebuild the who grid
00138   PRBool mNeedsRebuild;
00139 
00140   // number of rows and columns as defined by the XUL
00141   PRInt32 mRowCount;
00142   PRInt32 mColumnCount;
00143 
00144   // number of rows and columns that are implied but not 
00145   // explicitly defined int he XUL
00146   PRInt32 mExtraRowCount;
00147   PRInt32 mExtraColumnCount;
00148 
00149   // x,y array of cells in the rows and columns
00150   nsGridCell* mCellMap;
00151 
00152   // a flag that when true suppresses all other MarkDirties. This
00153   // prevents lots of extra work being done.
00154   PRBool mMarkingDirty;
00155 };
00156 
00157 #endif
00158