1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#ifndef nsCellMap_h__
|
|
|
|
#define nsCellMap_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
1998-07-11 04:47:29 +04:00
|
|
|
#include "celldata.h"
|
1998-09-15 21:58:24 +04:00
|
|
|
#include "nsVoidArray.h"
|
1998-07-11 04:00:31 +04:00
|
|
|
class nsTableColFrame;
|
|
|
|
class nsTableCellFrame;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-04-15 01:45:28 +04:00
|
|
|
/** nsCellMap is a support class for nsTablePart.
|
|
|
|
* It maintains an Rows x Columns grid onto which the cells of the table are mapped.
|
|
|
|
* This makes processing of rowspan and colspan attributes much easier.
|
|
|
|
* Each cell is represented by a CellData object.
|
|
|
|
*
|
|
|
|
* @see CellData
|
1998-09-01 01:23:28 +04:00
|
|
|
* @see nsTableFrame::AddCellToMap
|
1998-06-17 20:38:24 +04:00
|
|
|
* @see nsTableFrame::GrowCellMap
|
|
|
|
* @see nsTableFrame::BuildCellIntoMap
|
1998-04-15 01:45:28 +04:00
|
|
|
*
|
1998-09-01 01:23:28 +04:00
|
|
|
* mRows is an array of rows. a row cannot be null.
|
|
|
|
* each row is an array of cells. a cell can be null.
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
|
|
|
class nsCellMap
|
|
|
|
{
|
|
|
|
public:
|
1998-09-01 01:23:28 +04:00
|
|
|
/** constructor
|
1999-07-28 12:09:02 +04:00
|
|
|
* @param aNumRows - initial number of rows
|
|
|
|
* @param aNumColumns - initial number of columns
|
1998-09-19 02:37:14 +04:00
|
|
|
*/
|
1999-07-28 12:09:02 +04:00
|
|
|
nsCellMap(PRInt32 aNumRows,
|
|
|
|
PRInt32 aNumCols);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** destructor
|
|
|
|
* NOT VIRTUAL BECAUSE THIS CLASS SHOULD **NEVER** BE SUBCLASSED
|
1999-07-28 12:09:02 +04:00
|
|
|
*/
|
1998-04-14 00:24:54 +04:00
|
|
|
~nsCellMap();
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
/** return the CellData for the cell at (aTableRowIndex, aTableColIndex) */
|
|
|
|
CellData* GetCellAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex) const;
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1999-08-30 04:01:09 +04:00
|
|
|
/** insert a new row into the map
|
|
|
|
makes a blank row and adjusts spans
|
|
|
|
*/
|
|
|
|
void InsertRowIntoMap(PRInt32 aRowIndex);
|
|
|
|
|
|
|
|
/** removes a row from the map and adjusts spans
|
|
|
|
*/
|
|
|
|
void RemoveRowFromMap(PRInt32 aRowIndex);
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
/** append the cellFrame at the end of the row at aRowIndex and return the col index
|
|
|
|
*/
|
|
|
|
PRInt32 AppendCell(nsTableCellFrame* aCellFrame,
|
|
|
|
PRInt32 aRowIndex);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
void RemoveCell(nsTableCellFrame* aCellFrame,
|
|
|
|
PRInt32 aRowIndex);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 GetNextAvailRowIndex();
|
1999-02-11 09:22:33 +03:00
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
PRInt32 GetEffectiveColSpan(nsTableCellFrame* aCell) const;
|
|
|
|
PRInt32 GetEffectiveColSpan(PRInt32 aColIndex,
|
|
|
|
const nsTableCellFrame* aCell) const;
|
1999-08-26 01:49:18 +04:00
|
|
|
|
|
|
|
PRInt32 GetNumCellsOriginatingInRow(PRInt32 aRowIndex) const;
|
|
|
|
PRInt32 GetNumCellsOriginatingInCol(PRInt32 aColIndex) const;
|
1999-02-11 09:22:33 +03:00
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
PRInt32 GetNumCollapsedRows() const;
|
|
|
|
PRBool IsRowCollapsedAt(PRInt32 aRowIndex) const;
|
1999-07-28 12:09:02 +04:00
|
|
|
void SetRowCollapsedAt(PRInt32 aRowIndex,
|
|
|
|
PRBool aValue);
|
1998-09-01 01:23:28 +04:00
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
PRInt32 GetNumCollapsedCols() const;
|
|
|
|
PRBool IsColCollapsedAt(PRInt32 aColIndex) const;
|
1999-07-28 12:09:02 +04:00
|
|
|
void SetColCollapsedAt(PRInt32 aColIndex,
|
|
|
|
PRBool aValue);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-04-15 01:45:28 +04:00
|
|
|
/** return the total number of columns in the table represented by this CellMap */
|
1998-07-11 04:00:31 +04:00
|
|
|
PRInt32 GetColCount() const;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** return the actual number of rows in the table represented by this CellMap */
|
1998-07-11 04:00:31 +04:00
|
|
|
PRInt32 GetRowCount() const;
|
|
|
|
|
1998-09-01 01:23:28 +04:00
|
|
|
/** return the column frame associated with aColIndex */
|
1999-07-28 12:09:02 +04:00
|
|
|
nsTableColFrame* GetColumnFrame(PRInt32 aColIndex) const;
|
1998-09-01 01:23:28 +04:00
|
|
|
|
|
|
|
/** add a column frame to the list of column frames
|
|
|
|
* column frames must be added in order
|
1998-09-19 02:37:14 +04:00
|
|
|
*/
|
1998-07-11 04:00:31 +04:00
|
|
|
void AppendColumnFrame(nsTableColFrame *aColFrame);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
/** empty the column frame cache */
|
|
|
|
void ClearColumnCache();
|
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
// temporary until nsTableFrame::GetCellData uses GetCellFrameAt
|
|
|
|
nsTableCellFrame* GetCellFrameOriginatingAt(PRInt32 aRowX,
|
|
|
|
PRInt32 aColX) const;
|
|
|
|
|
|
|
|
nsTableCellFrame* GetCellInfoAt(PRInt32 aRowX,
|
|
|
|
PRInt32 aColX,
|
|
|
|
PRBool* aOriginates = nsnull,
|
|
|
|
PRInt32* aColSpan = nsnull) const;
|
1998-09-19 02:37:14 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
void AddColsAtEnd(PRUint32 aNumCols);
|
1998-09-19 02:37:14 +04:00
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
PRBool RowIsSpannedInto(PRInt32 aRowIndex) const;
|
|
|
|
PRBool RowHasSpanningCells(PRInt32 aRowIndex) const;
|
|
|
|
PRBool ColIsSpannedInto(PRInt32 aColIndex) const;
|
|
|
|
PRBool ColHasSpanningCells(PRInt32 aColIndex) const;
|
|
|
|
|
1998-09-19 02:37:14 +04:00
|
|
|
/** dump a representation of the cell map to stdout for debugging */
|
1999-07-28 12:09:02 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
void Dump() const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** set the CellMap to (aNumRows x aNumColumns) */
|
|
|
|
void Grow(PRInt32 aNumMapRows,
|
|
|
|
PRInt32 aNumCols);
|
|
|
|
|
1999-09-24 02:44:47 +04:00
|
|
|
/** insert a new entry into the mIsCollapsedRows */
|
|
|
|
void InsertIntoCollapsedRows(PRInt32 aRow);
|
|
|
|
/** remove an entry from mIsCollapsedRows */
|
|
|
|
void RemoveFromCollapsedRows(PRInt32 aRow);
|
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
/** assign aCellData to the cell at (aRow,aColumn) */
|
|
|
|
void SetMapCellAt(CellData& aCellData,
|
|
|
|
PRInt32 aMapRowIndex,
|
|
|
|
PRInt32 aColIndex);
|
|
|
|
|
|
|
|
CellData* GetMapCellAt(PRInt32 aMapRowIndex,
|
|
|
|
PRInt32 aColIndex) const;
|
|
|
|
|
1999-08-19 23:52:37 +04:00
|
|
|
PRInt32 GetNumCellsIn(PRInt32 aColIndex,
|
|
|
|
PRBool aOriginating) const;
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
/** an array containing col array. It can be larger than mRowCount due to
|
|
|
|
* row spans extending beyond the table */
|
|
|
|
nsVoidArray mRows;
|
|
|
|
|
|
|
|
/** an array of col frames. It is as large as mRowCount */
|
|
|
|
nsVoidArray mColFrames;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-08-26 01:49:18 +04:00
|
|
|
/** an array of PRInt32 indexed by row and giving the number of cells originating
|
|
|
|
* in each row. */
|
|
|
|
nsVoidArray mNumCellsOrigInRow;
|
|
|
|
|
|
|
|
/** an array of PRInt32 indexed by col and giving the number of cells originating
|
|
|
|
* in each col. */
|
|
|
|
nsVoidArray mNumCellsOrigInCol;
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
// an array of booleans where the ith element indicates if the ith row is collapsed
|
|
|
|
PRPackedBool* mIsCollapsedRows;
|
1999-09-24 02:44:47 +04:00
|
|
|
PRInt32 mIsCollapsedRowsSize;
|
1999-07-28 12:09:02 +04:00
|
|
|
PRInt32 mNumCollapsedRows;
|
|
|
|
|
1999-09-24 02:44:47 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
// an array of booleans where the ith element indicates if the ith col is collapsed
|
|
|
|
PRPackedBool* mIsCollapsedCols;
|
|
|
|
PRInt32 mNumCollapsedCols;
|
|
|
|
|
|
|
|
/** the number of rows in the table which is <= the number of rows in the cell map
|
|
|
|
* due to row spans extending beyond the end of the table (dead rows) */
|
|
|
|
PRInt32 mRowCount;
|
|
|
|
|
|
|
|
PRInt32 mNextAvailRowIndex;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
/* ----- inline methods ----- */
|
1999-07-28 12:09:02 +04:00
|
|
|
inline CellData* nsCellMap::GetCellAt(PRInt32 aRowIndex,
|
|
|
|
PRInt32 aColIndex) const
|
|
|
|
{
|
1999-08-04 03:17:50 +04:00
|
|
|
if ((0 > aRowIndex) || (aRowIndex >= mRowCount) ||
|
1999-08-26 01:49:18 +04:00
|
|
|
(0 > aColIndex) || (aColIndex >= mNumCellsOrigInCol.Count())) {
|
1999-08-10 06:43:45 +04:00
|
|
|
//bug 9024 tickled this
|
|
|
|
//printf("%s \n", "nsCellMap::GetCellAt called with invalid row or col index"); // XXX look at this when bug 10911 get fixed
|
1999-08-04 03:17:50 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
CellData* result = nsnull;
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aRowIndex));
|
|
|
|
if (row)
|
|
|
|
result = (CellData *)(row->ElementAt(aColIndex));
|
|
|
|
return result;
|
|
|
|
}
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1999-07-28 12:09:02 +04:00
|
|
|
inline CellData* nsCellMap::GetMapCellAt(PRInt32 aMapRowIndex,
|
|
|
|
PRInt32 aColIndex) const
|
1998-06-08 23:57:04 +04:00
|
|
|
{
|
1999-08-04 03:17:50 +04:00
|
|
|
if ((0 > aMapRowIndex) || (aMapRowIndex >= mRows.Count()) ||
|
1999-08-26 01:49:18 +04:00
|
|
|
(0 > aColIndex) || (aColIndex >= mNumCellsOrigInCol.Count())) {
|
1999-08-10 06:43:45 +04:00
|
|
|
//see bug 9024 comments above
|
|
|
|
//printf("%s \n", "nsCellMap::GetMapCellAt called with invalid row or col index"); // XXX look at this when bug 10911 get fixed
|
1999-08-04 03:17:50 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
1999-07-28 12:09:02 +04:00
|
|
|
|
|
|
|
CellData* result = nsnull;
|
|
|
|
nsVoidArray* row = (nsVoidArray *)(mRows.ElementAt(aMapRowIndex));
|
|
|
|
if (row)
|
1998-09-01 01:23:28 +04:00
|
|
|
result = (CellData *)(row->ElementAt(aColIndex));
|
|
|
|
return result;
|
1998-06-08 23:57:04 +04:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
inline PRInt32 nsCellMap::GetColCount() const
|
1998-06-08 23:57:04 +04:00
|
|
|
{
|
1999-08-26 01:49:18 +04:00
|
|
|
return mNumCellsOrigInCol.Count();
|
1998-06-08 23:57:04 +04:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
inline PRInt32 nsCellMap::GetRowCount() const
|
1998-06-08 23:57:04 +04:00
|
|
|
{
|
|
|
|
return mRowCount;
|
|
|
|
}
|
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
inline void nsCellMap::AppendColumnFrame(nsTableColFrame *aColFrame)
|
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
mColFrames.AppendElement(aColFrame);
|
1998-07-11 04:00:31 +04:00
|
|
|
}
|
|
|
|
|
1998-10-14 20:32:45 +04:00
|
|
|
inline void nsCellMap::ClearColumnCache()
|
|
|
|
{
|
1999-07-28 12:09:02 +04:00
|
|
|
mColFrames.Clear();
|
1998-10-14 20:32:45 +04:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:00:31 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|