render_text.h Source File (khtml Library)

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

# render_text.h

    00001 /*
    00002  * This file is part of the DOM implementation for KDE.
    00003  *
    00004  * (C) 1999 Lars Knoll (knoll@kde.org)
    00005  * (C) 2000 Dirk Mueller (mueller@kde.org)
    00006  *
    00007  * This library is free software; you can redistribute it and/or
    00008  * modify it under the terms of the GNU Library General Public
    00009  * License as published by the Free Software Foundation; either
    00010  * version 2 of the License, or (at your option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful,
    00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  * Library General Public License for more details.
    00016  *
    00017  * You should have received a copy of the GNU Library General Public License
    00018  * along with this library; see the file COPYING.LIB.  If not, write to
    00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00020  * Boston, MA 02111-1307, USA.
    00021  *
    00022  * $Id: render_text.h,v 1.76.2.3 2003/08/17 14:38:51 mueller Exp $
    00023  */
    00024 #ifndef RENDERTEXT_H
    00025 #define RENDERTEXT_H
    00026
    00027 #include "dom/dom_string.h"
    00028 #include "xml/dom_stringimpl.h"
    00029 #include "xml/dom_textimpl.h"
    00030 #include "rendering/render_object.h"
    00031
    00032 #include <qptrvector.h>
    00033 #include <assert.h>
    00034
    00035 class QPainter;
    00036 class QFontMetrics;
    00037
    00038 namespace khtml
    00039 {
    00040     class RenderText;
    00041     class RenderStyle;
    00042
    00043 class TextSlave
    00044 {
    00045 public:
    00046     TextSlave(int x, int y, int start, int len,
    00047               int baseline, int width,
    00048               bool reversed = false, unsigned toAdd = 0, bool firstLine = false)
    00049     {
    00050         m_x = x;
    00051         m_y = y;
    00052         m_start = start;
    00053         m_len = len;
    00054         m_baseline = baseline;
    00055         m_width = width;
    00056         m_reversed = reversed;
    00057         m_firstLine = firstLine;
    00058         m_toAdd = toAdd;
    00059     }
    00060     void paintDecoration( QPainter *pt, RenderText* p, int _tx, int _ty, int decoration, bool begin, bool end);
    00061     void paintBoxDecorations(QPainter *p, RenderStyle* style, RenderText *parent, int _tx, int _ty, bool begin, bool end);
    00062     void paintSelection(const Font *f, RenderText *text, QPainter *p, RenderStyle* style, int tx, int ty, int startPos, int endPos);
    00063
    00064     // Return before, after (offset set to max), or inside the text, at @p offset
    00065     FindSelectionResult checkSelectionPoint(int _x, int _y, int _tx, int _ty, const Font *f, RenderText *text, int & offset, short lineheight);
    00066
    00072     bool checkVerticalPoint(int _y, int _ty, int _h, int height)
    00073     { if((_ty + m_y > _y + _h) || (_ty + m_y + m_baseline + height < _y)) return false; return true; }
    00074
    00075     int m_start;
    00076     int m_y;
    00077     unsigned short m_len;
    00078     short m_x;
    00079     unsigned short m_baseline;
    00080     unsigned short m_width;
    00081
    00082     bool m_reversed : 1;
    00083     bool m_firstLine : 1;
    00084     unsigned m_toAdd : 14; // for justified text
    00085 private:
    00086     // this is just for QVector::bsearch. Don't use it otherwise
    00087     TextSlave(int _x, int _y)
    00088     {
    00089         m_x = _x;
    00090         m_y = _y;
    00091         m_reversed = false;
    00092     };
    00093     friend class RenderText;
    00094 };
    00095
    00096 class TextSlaveArray : public QPtrVector<TextSlave>
    00097 {
    00098 public:
    00099     TextSlaveArray();
    00100
    00101     TextSlave* first();
    00102
    00103     int   findFirstMatching( Item ) const;
    00104     virtual int compareItems( Item, Item );
    00105 };
    00106
    00107 class RenderText : public RenderObject
    00108 {
    00109     friend class TextSlave;
    00110
    00111 public:
    00112     RenderText(DOM::NodeImpl* node, DOM::DOMStringImpl *_str);
    00113     virtual ~RenderText();
    00114
    00115     virtual const char *renderName() const { return "RenderText"; }
    00116
    00117     virtual void setStyle(RenderStyle *style);
    00118
    00119     virtual bool isRendered() const { return true; }
    00120
    00121     virtual void paint( QPainter *, int x, int y, int w, int h,
    00122                         int tx, int ty);
    00123     virtual void paintObject( QPainter *, int x, int y, int w, int h,
    00124                         int tx, int ty);
    00125
    00126     void deleteSlaves();
    00127
    00128     DOM::DOMString data() const { return str; }
    00129     DOM::DOMStringImpl *string() const { return str; }
    00130
    00131     virtual void layout() {assert(false);}
    00132
    00133     virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty);
    00134
    00135     // Return before, after (offset set to max), or inside the text, at @p offset
    00136     virtual FindSelectionResult checkSelectionPoint( int _x, int _y, int _tx, int _ty,
    00137                                                      DOM::NodeImpl*& node, int & offset );
    00138
    00139     unsigned int length() const { return str->l; }
    00140     QChar *text() const { return str->s; }
    00141     unsigned int stringLength() const { return str->l; } // non virtual implementation of length()
    00142     virtual void position(int x, int y, int from, int len, int width, bool reverse, bool firstLine, int spaceAdd);
    00143
    00144     virtual unsigned int width(unsigned int from, unsigned int len, const Font *f) const;
    00145     virtual unsigned int width(unsigned int from, unsigned int len, bool firstLine = false) const;
    00146     virtual short width() const;
    00147     virtual int height() const;
    00148
    00149     // height of the contents (without paddings, margins and borders)
    00150     virtual short lineHeight( bool firstLine ) const;
    00151     virtual short baselinePosition( bool firstLine ) const;
    00152
    00153     // overrides
    00154     virtual void calcMinMaxWidth();
    00155     virtual short minWidth() const { return m_minWidth; }
    00156     virtual short maxWidth() const { return m_maxWidth; }
    00157
    00158     ushort startMin() const { return m_startMin; }
    00159     ushort endMin() const { return m_endMin; }
    00160
    00161     // returns the minimum x position of all slaves relative to the parent.
    00162     // defaults to 0.
    00163     int minXPos() const;
    00164
    00165     virtual int xPos() const;
    00166     virtual int yPos() const;
    00167
    00168     bool hasReturn() const { return m_hasReturn; }
    00169
    00170     virtual const QFont &font();
    00171     virtual short verticalPositionHint( bool firstLine ) const;
    00172
    00173     bool isFixedWidthFont() const;
    00174
    00175     void setText(DOM::DOMStringImpl *text, bool force=false);
    00176
    00177     virtual SelectionState selectionState() const {return m_selectionState;}
    00178     virtual void setSelectionState(SelectionState s) {m_selectionState = s; }
    00179     virtual void cursorPos(int offset, int &_x, int &_y, int &height);
    00180     virtual bool absolutePosition(int &/*xPos*/, int &/*yPos*/, bool f = false);
    00181     bool posOfChar(int ch, int &x, int &y);
    00182
    00183     virtual short marginLeft() const { return style()->marginLeft().minWidth(0); }
    00184     virtual short marginRight() const { return style()->marginRight().minWidth(0); }
    00185
    00186     virtual int rightmostPosition() const;
    00187
    00188     virtual void repaint();
    00189
    00190     bool hasBreakableChar() const { return m_hasBreakableChar; }
    00191     const QFontMetrics &metrics(bool firstLine) const;
    00192     const Font *htmlFont(bool firstLine) const;
    00193
    00194     DOM::TextImpl *element() const
    00195     { return static_cast<DOM::TextImpl*>(RenderObject::element()); }
    00196
    00197 protected:
    00198     void paintTextOutline(QPainter *p, int tx, int ty, const QRect &prevLine, const QRect &thisLine, const QRect &nextLine);
    00199
    00200     TextSlave * findTextSlave( int offset, int &pos );
    00201
    00202 protected: // members
    00203     TextSlaveArray m_lines;
    00204     DOM::DOMStringImpl *str; //
    00205
    00206     short m_lineHeight;
    00207     short m_minWidth;
    00208     short m_maxWidth;
    00209
    00210     SelectionState m_selectionState : 3 ;
    00211     bool m_hasReturn : 1;
    00212     bool m_hasBreakableChar : 1;
    00213     uint unused : 1;
    00214
    00215     ushort m_startMin : 9;
    00216     ushort m_endMin : 9;
    00217 };
    00218
    00219
    00220 }
    00221 #endif

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