00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef RENDER_TABLE_H
00028 #define RENDER_TABLE_H
00029
00030 #include <qcolor.h>
00031 #include <qptrvector.h>
00032
00033 #include "render_box.h"
00034 #include "render_flow.h"
00035 #include "render_style.h"
00036 #include "misc/khtmllayout.h"
00037
00038 namespace DOM {
00039 class DOMString;
00040 };
00041
00042 namespace khtml {
00043
00044 class RenderTable;
00045 class RenderTableSection;
00046 class RenderTableRow;
00047 class RenderTableCell;
00048 class RenderTableCol;
00049 class TableLayout;
00050
00051 class RenderTable : public RenderFlow
00052 {
00053 public:
00054 enum Rules {
00055 None = 0x00,
00056 RGroups = 0x01,
00057 CGroups = 0x02,
00058 Groups = 0x03,
00059 Rows = 0x05,
00060 Cols = 0x0a,
00061 All = 0x0f
00062 };
00063 enum Frame {
00064 Void = 0x00,
00065 Above = 0x01,
00066 Below = 0x02,
00067 Lhs = 0x04,
00068 Rhs = 0x08,
00069 Hsides = 0x03,
00070 Vsides = 0x0c,
00071 Box = 0x0f
00072 };
00073
00074 RenderTable(DOM::NodeImpl* node);
00075 ~RenderTable();
00076
00077 virtual const char *renderName() const { return "RenderTable"; }
00078
00079 virtual void setStyle(RenderStyle *style);
00080
00081 virtual bool isRendered() const { return true; }
00082 virtual bool isTable() const { return true; }
00083
00084 int getColumnPos(int col) const
00085 { return columnPos[col]; }
00086
00087 int cellSpacing() const { return spacing; }
00088
00089 Rules getRules() const { return rules; }
00090
00091 const QColor &bgColor() const { return style()->backgroundColor(); }
00092
00093 uint cellPadding() const { return padding; }
00094 void setCellPadding( uint p ) { padding = p; }
00095
00096
00097 virtual void addChild(RenderObject *child, RenderObject *beforeChild = 0);
00098 virtual void paint( QPainter *, int x, int y, int w, int h,
00099 int tx, int ty);
00100 virtual void layout();
00101 virtual void calcMinMaxWidth();
00102 virtual void close();
00103
00104 virtual void setCellWidths( );
00105
00106 virtual void position(int x, int y, int from, int len, int width, bool reverse, bool firstLine, int);
00107
00108 virtual void calcWidth();
00109
00110 virtual int borderTopExtra();
00111 virtual int borderBottomExtra();
00112
00113 #ifndef NDEBUG
00114 virtual void dump(QTextStream *stream, QString ind = "") const;
00115 #endif
00116 struct ColumnStruct {
00117 enum {
00118 WidthUndefined = 0xffff
00119 };
00120 ColumnStruct() {
00121 span = 1;
00122 width = WidthUndefined;
00123 }
00124 ushort span;
00125 ushort width;
00126 };
00127
00128 QMemArray<int> columnPos;
00129 QMemArray<ColumnStruct> columns;
00130
00131 void splitColumn( int pos, int firstSpan );
00132 void appendColumn( int span );
00133 int numEffCols() const { return columns.size(); }
00134 int spanOfEffCol( int effCol ) const { return columns[effCol].span; }
00135 int colToEffCol( int col ) const {
00136 int c = 0;
00137 int i = 0;
00138 while ( c < col && i < (int)columns.size() ) {
00139 c += columns[i].span;
00140 i++;
00141 }
00142 return i;
00143 }
00144 int effColToCol( int effCol ) const {
00145 int c = 0;
00146 for ( int i = 0; i < effCol; i++ )
00147 c += columns[i].span;
00148 return c;
00149 }
00150
00151 int bordersAndSpacing() const {
00152 return borderLeft() + borderRight() + (numEffCols()+1) * cellSpacing();
00153 }
00154
00155 RenderTableCol *colElement( int col );
00156
00157 void setNeedSectionRecalc() { needSectionRecalc = true; }
00158
00159 virtual RenderObject* removeChildNode(RenderObject* child);
00160
00161 protected:
00162
00163 void recalcSections();
00164
00165 friend class AutoTableLayout;
00166 friend class FixedTableLayout;
00167
00168 RenderFlow *tCaption;
00169 RenderTableSection *head;
00170 RenderTableSection *foot;
00171 RenderTableSection *firstBody;
00172
00173 TableLayout *tableLayout;
00174
00175 Frame frame : 4;
00176 Rules rules : 4;
00177
00178 bool has_col_elems : 1;
00179 uint spacing : 11;
00180 uint padding : 11;
00181 uint needSectionRecalc : 1;
00182 };
00183
00184
00185
00186 class RenderTableSection : public RenderBox
00187 {
00188 public:
00189 RenderTableSection(DOM::NodeImpl* node);
00190 ~RenderTableSection();
00191 virtual void detach();
00192
00193 virtual void setStyle(RenderStyle *style);
00194
00195 virtual const char *renderName() const { return "RenderTableSection"; }
00196
00197
00198 virtual void addChild(RenderObject *child, RenderObject *beforeChild = 0);
00199 virtual bool isTableSection() const { return true; }
00200
00201 virtual short lineHeight(bool) const { return 0; }
00202 virtual void position(int, int, int, int, int, bool, bool, int) {}
00203
00204 #ifndef NDEBUG
00205 virtual void dump(QTextStream *stream, QString ind = "") const;
00206 #endif
00207
00208 void addCell( RenderTableCell *cell );
00209
00210 void setCellWidths();
00211 void calcRowHeight();
00212 int layoutRows( int height );
00213
00214 RenderTable *table() const { return static_cast<RenderTable *>(parent()); }
00215
00216 typedef QMemArray<RenderTableCell *> Row;
00217 struct RowStruct {
00218 Row *row;
00219 int baseLine;
00220 Length height;
00221 };
00222
00223 RenderTableCell *&cellAt( int row, int col ) {
00224 return (*(grid[row].row))[col];
00225 }
00226 RenderTableCell *cellAt( int row, int col ) const {
00227 return (*(grid[row].row))[col];
00228 }
00229
00230 virtual void paint( QPainter *, int x, int y, int w, int h,
00231 int tx, int ty);
00232
00233 int numRows() const { return grid.size(); }
00234 int getBaseline(int row) {return grid[row].baseLine;}
00235
00236 void setNeedCellRecalc() {
00237 needCellRecalc = true;
00238 table()->setNeedSectionRecalc();
00239 }
00240
00241 virtual RenderObject* removeChildNode(RenderObject* child);
00242
00243
00244
00245 QMemArray<RowStruct> grid;
00246 QMemArray<int> rowPos;
00247
00248 ushort cCol : 15;
00249 short cRow : 16;
00250 bool needCellRecalc : 1;
00251
00252 void recalcCells();
00253 protected:
00254 void ensureRows( int numRows );
00255 void clearGrid();
00256 };
00257
00258
00259
00260 class RenderTableRow : public RenderContainer
00261 {
00262 public:
00263 RenderTableRow(DOM::NodeImpl* node);
00264
00265 virtual void detach();
00266
00267 virtual void setStyle( RenderStyle* );
00268 virtual const char *renderName() const { return "RenderTableRow"; }
00269
00270 virtual bool isTableRow() const { return true; }
00271
00272
00273 virtual void addChild(RenderObject *child, RenderObject *beforeChild = 0);
00274 virtual RenderObject* removeChildNode(RenderObject* child);
00275
00276 virtual short lineHeight( bool ) const { return 0; }
00277 virtual void position(int, int, int, int, int, bool, bool, int) {}
00278
00279 virtual void layout();
00280
00281 RenderTable *table() const { return static_cast<RenderTable *>(parent()->parent()); }
00282 RenderTableSection *section() const { return static_cast<RenderTableSection *>(parent()); }
00283
00284 #ifndef NDEBUG
00285 virtual void dump(QTextStream *stream, QString ind = "") const;
00286 #endif
00287 };
00288
00289
00290
00291 class RenderTableCell : public RenderFlow
00292 {
00293 public:
00294 RenderTableCell(DOM::NodeImpl* node);
00295
00296 virtual void detach();
00297
00298 virtual const char *renderName() const { return "RenderTableCell"; }
00299 virtual bool isTableCell() const { return true; }
00300
00301
00302 long cellIndex() const { return 0; }
00303 void setCellIndex( long ) { }
00304
00305 unsigned short colSpan() const { return cSpan; }
00306 void setColSpan( unsigned short c ) { cSpan = c; }
00307
00308 unsigned short rowSpan() const { return rSpan; }
00309 void setRowSpan( unsigned short r ) { rSpan = r; }
00310
00311 bool noWrap() const { return nWrap; }
00312 void setNoWrap(bool nw) { nWrap = nw; }
00313
00314 int col() const { return _col; }
00315 void setCol(int col) { _col = col; }
00316 int row() const { return _row; }
00317 void setRow(int r) { _row = r; }
00318
00319
00320 virtual void calcMinMaxWidth();
00321 virtual void calcWidth();
00322 virtual void setWidth( int width );
00323 virtual void setStyle( RenderStyle *style );
00324
00325 virtual void updateFromElement();
00326
00327 void setCellTopExtra(int p) { _topExtra = p; }
00328 void setCellBottomExtra(int p) { _bottomExtra = p; }
00329
00330 virtual void paint( QPainter* p, int x, int y,
00331 int w, int h, int tx, int ty);
00332
00333 virtual void close();
00334
00335
00336 virtual int yPos() const { return m_y + _topExtra; }
00337
00338 virtual void repaintRectangle(int x, int y, int w, int h, bool f=false);
00339 virtual bool absolutePosition(int &xPos, int &yPos, bool f = false);
00340
00341 virtual short baselinePosition( bool = false ) const;
00342
00343 RenderTable *table() const { return static_cast<RenderTable *>(parent()->parent()->parent()); }
00344 RenderTableSection *section() const { return static_cast<RenderTableSection *>(parent()->parent()); }
00345
00346 #ifndef NDEBUG
00347 virtual void dump(QTextStream *stream, QString ind = "") const;
00348 #endif
00349
00350 bool widthChanged() {
00351 bool retval = m_widthChanged;
00352 m_widthChanged = false;
00353 return retval;
00354 }
00355
00356 protected:
00357 virtual void paintBoxDecorations(QPainter *p,int _x, int _y,
00358 int _w, int _h, int _tx, int _ty);
00359 virtual int borderTopExtra() { return _topExtra; }
00360 virtual int borderBottomExtra() { return _bottomExtra; }
00361
00362 short _row;
00363 short _col;
00364 ushort rSpan;
00365 ushort cSpan;
00366 int _topExtra : 31;
00367 bool nWrap : 1;
00368 int _bottomExtra : 31;
00369 bool m_widthChanged : 1;
00370 };
00371
00372
00373
00374
00375 class RenderTableCol : public RenderContainer
00376 {
00377 public:
00378 RenderTableCol(DOM::NodeImpl* node);
00379
00380 virtual const char *renderName() const { return "RenderTableCol"; }
00381
00382 long span() const { return _span; }
00383 void setSpan( long s ) { _span = s; }
00384
00385 virtual void addChild(RenderObject *child, RenderObject *beforeChild = 0);
00386
00387 virtual bool isTableCol() const { return true; }
00388
00389 virtual short lineHeight( bool ) const { return 0; }
00390 virtual void position(int, int, int, int, int, bool, bool, int) {}
00391 virtual void layout() {}
00392
00393 virtual void updateFromElement();
00394
00395 #ifndef NDEBUG
00396 virtual void dump(QTextStream *stream, QString ind = "") const;
00397 #endif
00398
00399 protected:
00400 short _span;
00401 };
00402
00403 };
00404 #endif
00405