render_table.h Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# render_table.h

    00001 /*
    00002  * This file is part of the DOM implementation for KDE.
    00003  *
    00004  * Copyright (C) 1997 Martin Jones (mjones@kde.org)
    00005  *           (C) 1997 Torben Weis (weis@kde.org)
    00006  *           (C) 1998 Waldo Bastian (bastian@kde.org)
    00007  *           (C) 1999 Lars Knoll (knoll@kde.org)
    00008  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    00009  *
    00010  * This library is free software; you can redistribute it and/or
    00011  * modify it under the terms of the GNU Library General Public
    00012  * License as published by the Free Software Foundation; either
    00013  * version 2 of the License, or (at your option) any later version.
    00014  *
    00015  * This library is distributed in the hope that it will be useful,
    00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018  * Library General Public License for more details.
    00019  *
    00020  * You should have received a copy of the GNU Library General Public License
    00021  * along with this library; see the file COPYING.LIB.  If not, write to
    00022  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00023  * Boston, MA 02111-1307, USA.
    00024  *
    00025  * $Id: render_table.h,v 1.79.2.3 2003/08/17 14:38:51 mueller Exp $
    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     // overrides
    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; // the calculated position of the column
    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     // overrides
    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     // this gets a cell grid data structure. changing the number of
    00244     // columns is done by the table
    00245     QMemArray<RowStruct> grid;
    00246     QMemArray<int> rowPos;
    00247
    00248     signed short cRow : 16;
    00249     ushort cCol : 15;
    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     // overrides
    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     // ### FIX these two...
    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     // overrides
    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     // lie position to outside observers
    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     signed int _topExtra : 31;
    00367     bool nWrap : 1;
    00368     signed 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

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:44 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001