Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qrichtext_p.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: qrichtext_p.h,v 1.2 2003/07/10 02:40:11 llornkcor Exp $
00003 **
00004 ** Definition of internal rich text classes
00005 **
00006 ** Created : 990124
00007 **
00008 ** Copyright (C) 1999-2002 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QRICHTEXT_P_H
00039 #define QRICHTEXT_P_H
00040 
00041 //
00042 //  W A R N I N G
00043 //  -------------
00044 //
00045 // This file is not part of the Qt API.  It exists for the convenience
00046 // of a number of Qt sources files.  This header file may change from
00047 // version to version without notice, or even be removed.
00048 //
00049 // We mean it.
00050 //
00051 //
00052 
00053 #ifndef QT_H
00054 #include "qstring.h"
00055 #include "qptrlist.h"
00056 #include "qrect.h"
00057 #include "qfontmetrics.h"
00058 #include "qintdict.h"
00059 #include "qmap.h"
00060 #include "qstringlist.h"
00061 #include "qfont.h"
00062 #include "qcolor.h"
00063 #include "qsize.h"
00064 #include "qvaluelist.h"
00065 #include "qvaluestack.h"
00066 #include "qobject.h"
00067 #include "qdict.h"
00068 #include "qpixmap.h"
00069 #include "qstylesheet.h"
00070 #include "qptrvector.h"
00071 #include "qpainter.h"
00072 #include "qlayout.h"
00073 #include "qobject.h"
00074 #include "private/qcomplextext_p.h"
00075 #include "qapplication.h"
00076 #endif // QT_H
00077 
00078 #ifndef QT_NO_RICHTEXT
00079 
00080 class QTextDocument;
00081 class QTextString;
00082 class QTextPreProcessor;
00083 class QTextFormat;
00084 class QTextCursor;
00085 class QTextParagraph;
00086 class QTextFormatter;
00087 class QTextIndent;
00088 class QTextFormatCollection;
00089 class QStyleSheetItem;
00090 #ifndef QT_NO_TEXTCUSTOMITEM
00091 class QTextCustomItem;
00092 #endif
00093 class QTextFlow;
00094 struct QBidiContext;
00095 
00096 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00097 
00098 class Q_EXPORT QTextStringChar
00099 {
00100     friend class QTextString;
00101 
00102 public:
00103     // this is never called, initialize variables in QTextString::insert()!!!
00104     QTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0;}
00105     ~QTextStringChar();
00106 
00107     QChar c;
00108     enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 };
00109     uint lineStart : 1;
00110     uint rightToLeft : 1;
00111     uint hasCursor : 1;
00112     uint canBreak : 1;
00113     Type type : 2;
00114     uint startOfRun : 1;
00115 
00116     int x;
00117     int height() const;
00118     int ascent() const;
00119     int descent() const;
00120     bool isCustom() const { return (type & Custom) != 0; }
00121     QTextFormat *format() const;
00122 #ifndef QT_NO_TEXTCUSTOMITEM
00123     QTextCustomItem *customItem() const;
00124 #endif
00125     void setFormat( QTextFormat *f );
00126 #ifndef QT_NO_TEXTCUSTOMITEM
00127     void setCustomItem( QTextCustomItem *i );
00128 #endif
00129     struct CustomData
00130     {
00131         QTextFormat *format;
00132 #ifndef QT_NO_TEXTCUSTOMITEM
00133         QTextCustomItem *custom;
00134 #endif
00135         QString anchorName;
00136         QString anchorHref;
00137     };
00138 
00139 #ifndef QT_NO_TEXTCUSTOMITEM
00140     void loseCustomItem();
00141 #endif
00142 
00143     union {
00144         QTextFormat* format;
00145         CustomData* custom;
00146     } d;
00147 
00148     bool isAnchor() const { return ( type & Anchor) != 0; }
00149     bool isLink() const { return isAnchor() && !!d.custom->anchorHref; }
00150     QString anchorName() const;
00151     QString anchorHref() const;
00152     void setAnchor( const QString& name, const QString& href );
00153 
00154 private:
00155     QTextStringChar &operator=( const QTextStringChar & ) {
00156         //abort();
00157         return *this;
00158     }
00159     QTextStringChar( const QTextStringChar & ) {
00160     }
00161     friend class QComplexText;
00162     friend class QTextParagraph;
00163 };
00164 
00165 #if defined(Q_TEMPLATEDLL)
00166 // MOC_SKIP_BEGIN
00167 Q_TEMPLATE_EXTERN template class Q_EXPORT QMemArray<QTextStringChar>;
00168 // MOC_SKIP_END
00169 #endif
00170 
00171 class Q_EXPORT QTextString
00172 {
00173 public:
00174 
00175     QTextString();
00176     QTextString( const QTextString &s );
00177     virtual ~QTextString();
00178 
00179     static QString toString( const QMemArray<QTextStringChar> &data, bool fixspaces = TRUE );
00180     QString toString( bool fixspaces = TRUE ) const;
00181 
00182     QTextStringChar &at( int i ) const;
00183 #if defined(Q_STRICT_INLINING_RULES)
00184     // This is for the IRIX MIPSpro o32 ABI - it fails, claiming the
00185     // implementation to be a redefinition.
00186     inline int length() const;
00187 #else
00188     int length() const;
00189 #endif
00190 
00191     int width( int idx ) const;
00192 
00193     void insert( int index, const QString &s, QTextFormat *f );
00194     void insert( int index, const QChar *unicode, int len, QTextFormat *f );
00195     void insert( int index, QTextStringChar *c, bool doAddRefFormat = FALSE );
00196     void truncate( int index );
00197     void remove( int index, int len );
00198     void clear();
00199 
00200     void setFormat( int index, QTextFormat *f, bool useCollection );
00201 
00202     void setBidi( bool b ) { bidi = b; }
00203     bool isBidi() const;
00204     bool isRightToLeft() const;
00205     QChar::Direction direction() const;
00206     void setDirection( QChar::Direction d ) { dir = d; bidiDirty = TRUE; }
00207 
00208     QMemArray<QTextStringChar> subString( int start = 0, int len = 0xFFFFFF ) const;
00209     QMemArray<QTextStringChar> rawData() const { return data.copy(); }
00210 
00211     void operator=( const QString &s ) { clear(); insert( 0, s, 0 ); }
00212     void operator+=( const QString &s ) { insert( length(), s, 0 ); }
00213     void prepend( const QString &s ) { insert( 0, s, 0 ); }
00214 
00215 private:
00216     void checkBidi() const;
00217 
00218     QMemArray<QTextStringChar> data;
00219     uint bidiDirty : 1;
00220     uint bidi : 1; // true when the paragraph has right to left characters
00221     uint rightToLeft : 1;
00222     uint dir : 5;
00223 };
00224 
00225 inline bool QTextString::isBidi() const
00226 {
00227     if ( bidiDirty )
00228         checkBidi();
00229     return bidi;
00230 }
00231 
00232 inline bool QTextString::isRightToLeft() const
00233 {
00234     if ( bidiDirty )
00235         checkBidi();
00236     return rightToLeft;
00237 }
00238 
00239 inline QChar::Direction QTextString::direction() const
00240 {
00241     return (QChar::Direction) dir;
00242 }
00243 
00244 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00245 
00246 #if defined(Q_TEMPLATEDLL)
00247 // MOC_SKIP_BEGIN
00248 Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<int>;
00249 Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<QTextParagraph*>;
00250 Q_TEMPLATE_EXTERN template class Q_EXPORT QValueStack<bool>;
00251 // MOC_SKIP_END
00252 #endif
00253 
00254 class Q_EXPORT QTextCursor
00255 {
00256 public:
00257     QTextCursor( QTextDocument *d = 0 );
00258     QTextCursor( const QTextCursor &c );
00259     QTextCursor &operator=( const QTextCursor &c );
00260     virtual ~QTextCursor() {}
00261 
00262     bool operator==( const QTextCursor &c ) const;
00263     bool operator!=( const QTextCursor &c ) const { return !(*this == c); }
00264 
00265 #if defined(Q_STRICT_INLINING_RULES)
00266     // This is for the IRIX MIPSpro o32 ABI - it fails, claiming the
00267     // implementation to be a redefinition.
00268     inline QTextParagraph *paragraph() const;
00269 #else
00270     QTextParagraph *paragraph() const;
00271 #endif
00272 
00273     void setParagraph( QTextParagraph*p ) { gotoPosition(p, 0 ); }
00274     QTextDocument *document() const;
00275     int index() const;
00276     void setIndex( int index ) { gotoPosition(paragraph(), index ); }
00277 
00278     void gotoPosition( QTextParagraph* p, int index = 0);
00279     void gotoLeft();
00280     void gotoRight();
00281     void gotoNextLetter();
00282     void gotoPreviousLetter();
00283     void gotoUp();
00284     void gotoDown();
00285     void gotoLineEnd();
00286     void gotoLineStart();
00287     void gotoHome();
00288     void gotoEnd();
00289     void gotoPageUp( int visibleHeight );
00290     void gotoPageDown( int visibleHeight );
00291     void gotoNextWord( bool onlySpace = FALSE );
00292     void gotoPreviousWord( bool onlySpace = FALSE );
00293     void gotoWordLeft();
00294     void gotoWordRight();
00295 
00296     void insert( const QString &s, bool checkNewLine, QMemArray<QTextStringChar> *formatting = 0 );
00297     void splitAndInsertEmptyParagraph( bool ind = TRUE, bool updateIds = TRUE );
00298     bool remove();
00299     void indent();
00300 
00301     bool atParagStart();
00302     bool atParagEnd();
00303 
00304     int x() const; // x in current paragraph
00305     int y() const; // y in current paragraph
00306 
00307     int globalX() const;
00308     int globalY() const;
00309 
00310     QTextParagraph *topParagraph() const { return paras.isEmpty() ? para : paras.first(); }
00311     int offsetX() const { return ox; } // inner document  offset
00312     int offsetY() const { return oy; } // inner document offset
00313     int totalOffsetX() const; // total document offset
00314     int totalOffsetY() const; // total document offset
00315 
00316     bool place( const QPoint &pos, QTextParagraph *s ) { return place( pos, s, FALSE ); }
00317     bool place( const QPoint &pos, QTextParagraph *s, bool link );
00318     void restoreState();
00319 
00320 
00321     int nestedDepth() const { return (int)indices.count(); } //### size_t/int cast
00322     void oneUp() { if ( !indices.isEmpty() ) pop(); }
00323     void setValid( bool b ) { valid = b; }
00324     bool isValid() const { return valid; }
00325 
00326 private:
00327     enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
00328 
00329     void push();
00330     void pop();
00331     bool processNesting( Operation op );
00332     void invalidateNested();
00333     void gotoIntoNested( const QPoint &globalPos );
00334 
00335     QTextParagraph *para;
00336     int idx, tmpIndex;
00337     int ox, oy;
00338     QValueStack<int> indices;
00339     QValueStack<QTextParagraph*> paras;
00340     QValueStack<int> xOffsets;
00341     QValueStack<int> yOffsets;
00342     uint valid : 1;
00343 
00344 };
00345 
00346 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00347 
00348 class Q_EXPORT QTextCommand
00349 {
00350 public:
00351     enum Commands { Invalid, Insert, Delete, Format, Style };
00352 
00353     QTextCommand( QTextDocument *d ) : doc( d ), cursor( d ) {}
00354     virtual ~QTextCommand();
00355 
00356     virtual Commands type() const;
00357 
00358     virtual QTextCursor *execute( QTextCursor *c ) = 0;
00359     virtual QTextCursor *unexecute( QTextCursor *c ) = 0;
00360 
00361 protected:
00362     QTextDocument *doc;
00363     QTextCursor cursor;
00364 
00365 };
00366 
00367 #if defined(Q_TEMPLATEDLL)
00368 // MOC_SKIP_BEGIN
00369 Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextCommand>;
00370 // MOC_SKIP_END
00371 #endif
00372 
00373 class Q_EXPORT QTextCommandHistory
00374 {
00375 public:
00376     QTextCommandHistory( int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); }
00377     virtual ~QTextCommandHistory();
00378 
00379     void clear() { history.clear(); current = -1; }
00380 
00381     void addCommand( QTextCommand *cmd );
00382     QTextCursor *undo( QTextCursor *c );
00383     QTextCursor *redo( QTextCursor *c );
00384 
00385     bool isUndoAvailable();
00386     bool isRedoAvailable();
00387 
00388     void setUndoDepth( int d ) { steps = d; }
00389     int undoDepth() const { return steps; }
00390 
00391     int historySize() const { return history.count(); }
00392     int currentPosition() const { return current; }
00393 
00394 private:
00395     QPtrList<QTextCommand> history;
00396     int current, steps;
00397 
00398 };
00399 
00400 inline QTextCommandHistory::~QTextCommandHistory()
00401 {
00402     clear();
00403 }
00404 
00405 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00406 
00407 #ifndef QT_NO_TEXTCUSTOMITEM
00408 class Q_EXPORT QTextCustomItem
00409 {
00410 public:
00411     QTextCustomItem( QTextDocument *p )
00412         :  xpos(0), ypos(-1), width(-1), height(0), parent( p )
00413     {}
00414     virtual ~QTextCustomItem();
00415     virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) = 0;
00416 
00417     virtual void adjustToPainter( QPainter* );
00418 
00419     enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
00420     virtual Placement placement() const;
00421     bool placeInline() { return placement() == PlaceInline; }
00422 
00423     virtual bool ownLine() const;
00424     virtual void resize( int nwidth );
00425     virtual void invalidate();
00426     virtual int ascent() const { return height; }
00427 
00428     virtual bool isNested() const;
00429     virtual int minimumWidth() const;
00430 
00431     virtual QString richText() const;
00432 
00433     int xpos; // used for floating items
00434     int ypos; // used for floating items
00435     int width;
00436     int height;
00437 
00438     QRect geometry() const { return QRect( xpos, ypos, width, height ); }
00439 
00440     virtual bool enter( QTextCursor *, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
00441     virtual bool enterAt( QTextCursor *, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint & );
00442     virtual bool next( QTextCursor *, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00443     virtual bool prev( QTextCursor *, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00444     virtual bool down( QTextCursor *, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00445     virtual bool up( QTextCursor *, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00446 
00447     void setParagraph( QTextParagraph *p ) { parag = p; }
00448     QTextParagraph *paragraph() const { return parag; }
00449 
00450     QTextDocument *parent;
00451     QTextParagraph *parag;
00452 
00453     virtual void pageBreak( int  y, QTextFlow* flow );
00454 };
00455 #endif
00456 
00457 #if defined(Q_TEMPLATEDLL)
00458 // MOC_SKIP_BEGIN
00459 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<QString, QString>;
00460 // MOC_SKIP_END
00461 #endif
00462 
00463 #ifndef QT_NO_TEXTCUSTOMITEM
00464 class Q_EXPORT QTextImage : public QTextCustomItem
00465 {
00466 public:
00467     QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context,
00468                 QMimeSourceFactory &factory );
00469     virtual ~QTextImage();
00470 
00471     Placement placement() const { return place; }
00472     void adjustToPainter( QPainter* );
00473     int minimumWidth() const { return width; }
00474 
00475     QString richText() const;
00476 
00477     void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00478 
00479 private:
00480     QRegion* reg;
00481     QPixmap pm;
00482     Placement place;
00483     int tmpwidth, tmpheight;
00484     QMap<QString, QString> attributes;
00485     QString imgId;
00486 
00487 };
00488 #endif
00489 
00490 #ifndef QT_NO_TEXTCUSTOMITEM
00491 class Q_EXPORT QTextHorizontalLine : public QTextCustomItem
00492 {
00493 public:
00494     QTextHorizontalLine( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context,
00495                          QMimeSourceFactory &factory );
00496     virtual ~QTextHorizontalLine();
00497 
00498     void adjustToPainter( QPainter* );
00499     void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00500     QString richText() const;
00501 
00502     bool ownLine() const { return TRUE; }
00503 
00504 private:
00505     int tmpheight;
00506     QColor color;
00507     bool shade;
00508 
00509 };
00510 #endif
00511 
00512 #ifndef QT_NO_TEXTCUSTOMITEM
00513 #if defined(Q_TEMPLATEDLL)
00514 // MOC_SKIP_BEGIN
00515 Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextCustomItem>;
00516 // MOC_SKIP_END
00517 #endif
00518 #endif
00519 
00520 class Q_EXPORT QTextFlow
00521 {
00522     friend class QTextDocument;
00523 #ifndef QT_NO_TEXTCUSTOMITEM
00524     friend class QTextTableCell;
00525 #endif
00526 
00527 public:
00528     QTextFlow();
00529     virtual ~QTextFlow();
00530 
00531     virtual void setWidth( int width );
00532     int width() const;
00533 
00534     virtual void setPageSize( int ps );
00535     int pageSize() const { return pagesize; }
00536 
00537     virtual int adjustLMargin( int yp, int h, int margin, int space );
00538     virtual int adjustRMargin( int yp, int h, int margin, int space );
00539 
00540 #ifndef QT_NO_TEXTCUSTOMITEM
00541     virtual void registerFloatingItem( QTextCustomItem* item );
00542     virtual void unregisterFloatingItem( QTextCustomItem* item );
00543 #endif
00544     virtual QRect boundingRect() const;
00545     virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00546 
00547     virtual int adjustFlow( int  y, int w, int h ); // adjusts y according to the defined pagesize. Returns the shift.
00548 
00549     virtual bool isEmpty();
00550 
00551     void clear();
00552 
00553 private:
00554     int w;
00555     int pagesize;
00556 
00557 #ifndef QT_NO_TEXTCUSTOMITEM
00558     QPtrList<QTextCustomItem> leftItems;
00559     QPtrList<QTextCustomItem> rightItems;
00560 #endif
00561 };
00562 
00563 inline int QTextFlow::width() const { return w; }
00564 
00565 #ifndef QT_NO_TEXTCUSTOMITEM
00566 class QTextTable;
00567 
00568 class Q_EXPORT QTextTableCell : public QLayoutItem
00569 {
00570     friend class QTextTable;
00571 
00572 public:
00573     QTextTableCell( QTextTable* table,
00574                     int row, int column,
00575                     const QMap<QString, QString> &attr,
00576                     const QStyleSheetItem* style,
00577                     const QTextFormat& fmt, const QString& context,
00578                     QMimeSourceFactory &factory, QStyleSheet *sheet, const QString& doc );
00579     virtual ~QTextTableCell();
00580 
00581     QSize sizeHint() const ;
00582     QSize minimumSize() const ;
00583     QSize maximumSize() const ;
00584     QSizePolicy::ExpandData expanding() const;
00585     bool isEmpty() const;
00586     void setGeometry( const QRect& ) ;
00587     QRect geometry() const;
00588 
00589     bool hasHeightForWidth() const;
00590     int heightForWidth( int ) const;
00591 
00592     void adjustToPainter( QPainter* );
00593 
00594     int row() const { return row_; }
00595     int column() const { return col_; }
00596     int rowspan() const { return rowspan_; }
00597     int colspan() const { return colspan_; }
00598     int stretch() const { return stretch_; }
00599 
00600     QTextDocument* richText()  const { return richtext; }
00601     QTextTable* table() const { return parent; }
00602 
00603     void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00604 
00605     QBrush *backGround() const { return background; }
00606     virtual void invalidate();
00607 
00608     int verticalAlignmentOffset() const;
00609     int horizontalAlignmentOffset() const;
00610 
00611 private:
00612     QRect geom;
00613     QTextTable* parent;
00614     QTextDocument* richtext;
00615     int row_;
00616     int col_;
00617     int rowspan_;
00618     int colspan_;
00619     int stretch_;
00620     int maxw;
00621     int minw;
00622     bool hasFixedWidth;
00623     QBrush *background;
00624     int cached_width;
00625     int cached_sizehint;
00626     QMap<QString, QString> attributes;
00627     int align;
00628 };
00629 #endif
00630 
00631 #if defined(Q_TEMPLATEDLL)
00632 // MOC_SKIP_BEGIN
00633 Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextTableCell>;
00634 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<QTextCursor*, int>;
00635 // MOC_SKIP_END
00636 #endif
00637 
00638 #ifndef QT_NO_TEXTCUSTOMITEM
00639 class Q_EXPORT QTextTable: public QTextCustomItem
00640 {
00641     friend class QTextTableCell;
00642 
00643 public:
00644     QTextTable( QTextDocument *p, const QMap<QString, QString> &attr );
00645     virtual ~QTextTable();
00646 
00647     void adjustToPainter( QPainter *p );
00648     void pageBreak( int  y, QTextFlow* flow );
00649     void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00650                const QColorGroup& cg, bool selected );
00651 
00652     bool noErase() const { return TRUE; }
00653     bool ownLine() const { return TRUE; }
00654     Placement placement() const { return place; }
00655     bool isNested() const { return TRUE; }
00656     void resize( int nwidth );
00657     virtual void invalidate();
00658 
00659     virtual bool enter( QTextCursor *c, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
00660     virtual bool enterAt( QTextCursor *c, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint &pos );
00661     virtual bool next( QTextCursor *c, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00662     virtual bool prev( QTextCursor *c, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00663     virtual bool down( QTextCursor *c, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00664     virtual bool up( QTextCursor *c, QTextDocument *&doc, QTextParagraph *&parag, int &idx, int &ox, int &oy );
00665 
00666     QString richText() const;
00667 
00668     int minimumWidth() const;
00669 
00670     QPtrList<QTextTableCell> tableCells() const { return cells; }
00671 
00672     bool isStretching() const { return stretch; }
00673 
00674 private:
00675     void format( int w );
00676     void addCell( QTextTableCell* cell );
00677 
00678 private:
00679     QGridLayout* layout;
00680     QPtrList<QTextTableCell> cells;
00681     int cachewidth;
00682     int fixwidth;
00683     int cellpadding;
00684     int cellspacing;
00685     int border;
00686     int outerborder;
00687     int stretch;
00688     int innerborder;
00689     int us_cp, us_ib, us_b, us_ob, us_cs;
00690     QMap<QString, QString> attributes;
00691     QMap<QTextCursor*, int> currCell;
00692     Placement place;
00693     void adjustCells( int y , int shift );
00694     int pageBreakFor;
00695 };
00696 #endif
00697 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00698 
00699 #ifndef QT_NO_TEXTCUSTOMITEM
00700 class QTextTableCell;
00701 class QTextParagraph;
00702 #endif
00703 
00704 struct Q_EXPORT QTextDocumentSelection
00705 {
00706     QTextCursor startCursor, endCursor;
00707     bool swapped;
00708     Q_DUMMY_COMPARISON_OPERATOR(QTextDocumentSelection)
00709 };
00710 
00711 #if defined(Q_TEMPLATEDLL)
00712 // MOC_SKIP_BEGIN
00713 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QColor>;
00714 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, bool>;
00715 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextDocumentSelection>;
00716 Q_TEMPLATE_EXTERN template class Q_EXPORT QPtrList<QTextDocument>;
00717 // MOC_SKIP_END
00718 #endif
00719 
00720 class Q_EXPORT QTextDocument : public QObject
00721 {
00722     Q_OBJECT
00723 
00724 #ifndef QT_NO_TEXTCUSTOMITEM
00725     friend class QTextTableCell;
00726 #endif
00727     friend class QTextCursor;
00728     friend class QTextEdit;
00729     friend class QTextParagraph;
00730 
00731 public:
00732     enum SelectionIds {
00733         Standard = 0,
00734         IMSelectionText         = 31998,
00735         IMCompositionText       = 31999, // this must be higher!
00736         Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to
00737         // remove multiple lines with removeSelectedText()
00738     };
00739 
00740     QTextDocument( QTextDocument *p );
00741     QTextDocument( QTextDocument *d, QTextFormatCollection *f );
00742     virtual ~QTextDocument();
00743 
00744     QTextDocument *parent() const { return par; }
00745     QTextParagraph *parentParagraph() const { return parentPar; }
00746 
00747     void setText( const QString &text, const QString &context );
00748     QMap<QString, QString> attributes() const { return attribs; }
00749     void setAttributes( const QMap<QString, QString> &attr ) { attribs = attr; }
00750 
00751     QString text() const;
00752     QString text( int parag ) const;
00753     QString originalText() const;
00754 
00755     int x() const;
00756     int y() const;
00757     int width() const;
00758     int widthUsed() const;
00759     int visibleWidth() const;
00760     int height() const;
00761     void setWidth( int w );
00762     int minimumWidth() const;
00763     bool setMinimumWidth( int needed, int used = -1, QTextParagraph *parag = 0 );
00764 
00765     void setY( int y );
00766     int leftMargin() const;
00767     void setLeftMargin( int lm );
00768     int rightMargin() const;
00769     void setRightMargin( int rm );
00770 
00771     QTextParagraph *firstParagraph() const;
00772     QTextParagraph *lastParagraph() const;
00773     void setFirstParagraph( QTextParagraph *p );
00774     void setLastParagraph( QTextParagraph *p );
00775 
00776     void invalidate();
00777 
00778     void setPreProcessor( QTextPreProcessor *sh );
00779     QTextPreProcessor *preProcessor() const;
00780 
00781     void setFormatter( QTextFormatter *f );
00782     QTextFormatter *formatter() const;
00783 
00784     void setIndent( QTextIndent *i );
00785     QTextIndent *indent() const;
00786 
00787     QColor selectionColor( int id ) const;
00788     bool invertSelectionText( int id ) const;
00789     void setSelectionColor( int id, const QColor &c );
00790     void setInvertSelectionText( int id, bool b );
00791     bool hasSelection( int id, bool visible = FALSE ) const;
00792     void setSelectionStart( int id, const QTextCursor &cursor );
00793     bool setSelectionEnd( int id, const QTextCursor &cursor );
00794     void selectAll( int id );
00795     bool removeSelection( int id );
00796     void selectionStart( int id, int &paragId, int &index );
00797     QTextCursor selectionStartCursor( int id );
00798     QTextCursor selectionEndCursor( int id );
00799     void selectionEnd( int id, int &paragId, int &index );
00800     void setFormat( int id, QTextFormat *f, int flags );
00801     int numSelections() const { return nSelections; }
00802     void addSelection( int id );
00803 
00804     QString selectedText( int id, bool asRichText = FALSE ) const;
00805     void removeSelectedText( int id, QTextCursor *cursor );
00806     void indentSelection( int id );
00807 
00808     QTextParagraph *paragAt( int i ) const;
00809 
00810     void addCommand( QTextCommand *cmd );
00811     QTextCursor *undo( QTextCursor *c = 0 );
00812     QTextCursor *redo( QTextCursor *c  = 0 );
00813     QTextCommandHistory *commands() const { return commandHistory; }
00814 
00815     QTextFormatCollection *formatCollection() const;
00816 
00817     bool find( QTextCursor &cursor, const QString &expr, bool cs, bool wo, bool forward);
00818 
00819     void setTextFormat( Qt::TextFormat f );
00820     Qt::TextFormat textFormat() const;
00821 
00822     bool inSelection( int selId, const QPoint &pos ) const;
00823 
00824     QStyleSheet *styleSheet() const { return sheet_; }
00825 #ifndef QT_NO_MIME
00826     QMimeSourceFactory *mimeSourceFactory() const { return factory_; }
00827 #endif
00828     QString context() const { return contxt; }
00829 
00830     void setStyleSheet( QStyleSheet *s );
00831     void setDefaultFormat( const QFont &font, const QColor &color );
00832 #ifndef QT_NO_MIME
00833     void setMimeSourceFactory( QMimeSourceFactory *f ) { if ( f ) factory_ = f; }
00834 #endif
00835     void setContext( const QString &c ) { if ( !c.isEmpty() ) contxt = c; }
00836 
00837     void setUnderlineLinks( bool b );
00838     bool underlineLinks() const { return underlLinks; }
00839 
00840     void setPaper( QBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; }
00841     QBrush *paper() const { return backBrush; }
00842 
00843     void doLayout( QPainter *p, int w );
00844     void draw( QPainter *p, const QRect& rect, const QColorGroup &cg, const QBrush *paper = 0 );
00845     void eraseParagraphEmptyArea( QTextParagraph *parag, QPainter *p, const QColorGroup &cg );
00846     bool useDoubleBuffer( QTextParagraph *parag, QPainter *p );
00847 
00848     void drawParagraph( QPainter *p, QTextParagraph *parag, int cx, int cy, int cw, int ch,
00849                     QPixmap *&doubleBuffer, const QColorGroup &cg,
00850                     bool drawCursor, QTextCursor *cursor, bool resetChanged = TRUE );
00851     QTextParagraph *draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg,
00852                       bool onlyChanged = FALSE, bool drawCursor = FALSE, QTextCursor *cursor = 0,
00853                       bool resetChanged = TRUE );
00854 
00855 #ifndef QT_NO_TEXTCUSTOMITEM
00856     void registerCustomItem( QTextCustomItem *i, QTextParagraph *p );
00857     void unregisterCustomItem( QTextCustomItem *i, QTextParagraph *p );
00858 #endif
00859 
00860     void setFlow( QTextFlow *f );
00861     void takeFlow();
00862     QTextFlow *flow() const { return flow_; }
00863     bool isPageBreakEnabled() const { return pages; }
00864     void setPageBreakEnabled( bool b ) { pages = b; }
00865 
00866     void setUseFormatCollection( bool b ) { useFC = b; }
00867     bool useFormatCollection() const { return useFC; }
00868 
00869 #ifndef QT_NO_TEXTCUSTOMITEM
00870     QTextTableCell *tableCell() const { return tc; }
00871     void setTableCell( QTextTableCell *c ) { tc = c; }
00872 #endif
00873 
00874     void setPlainText( const QString &text );
00875     void setRichText( const QString &text, const QString &context );
00876     QString richText() const;
00877     QString plainText() const;
00878 
00879     bool focusNextPrevChild( bool next );
00880 
00881     int alignment() const;
00882     void setAlignment( int a );
00883 
00884     int *tabArray() const;
00885     int tabStopWidth() const;
00886     void setTabArray( int *a );
00887     void setTabStops( int tw );
00888 
00889     void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); }
00890     int undoDepth() const { return commandHistory->undoDepth(); }
00891 
00892     int length() const;
00893     void clear( bool createEmptyParag = FALSE );
00894 
00895     virtual QTextParagraph *createParagraph( QTextDocument *d, QTextParagraph *pr = 0, QTextParagraph *nx = 0, bool updateIds = TRUE );
00896     void insertChild( QObject *o ) { QObject::insertChild( o ); }
00897     void removeChild( QObject *o ) { QObject::removeChild( o ); }
00898     void insertChild( QTextDocument *d ) { childList.append( d ); }
00899     void removeChild( QTextDocument *d ) { childList.removeRef( d ); }
00900     QPtrList<QTextDocument> children() const { return childList; }
00901 
00902     bool hasFocusParagraph() const;
00903     QString focusHref() const;
00904     QString focusName() const;
00905 
00906     void invalidateOriginalText() { oTextValid = FALSE; oText = ""; }
00907 
00908 signals:
00909     void minimumWidthChanged( int );
00910 
00911 private:
00912     void init();
00913     QPixmap *bufferPixmap( const QSize &s );
00914     // HTML parser
00915     bool hasPrefix(const QChar* doc, int length, int pos, QChar c);
00916     bool hasPrefix(const QChar* doc, int length, int pos, const QString& s);
00917 #ifndef QT_NO_TEXTCUSTOMITEM
00918     QTextCustomItem* parseTable( const QMap<QString, QString> &attr, const QTextFormat &fmt,
00919                                  const QChar* doc, int length, int& pos, QTextParagraph *curpar );
00920 #endif
00921     bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = FALSE );
00922     bool eat(const QChar* doc, int length, int& pos, QChar c);
00923     QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag);
00924     QString parseCloseTag( const QChar* doc, int length, int& pos );
00925     QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos);
00926     QString parseWord(const QChar* doc, int length, int& pos, bool lower = TRUE);
00927     QChar parseChar(const QChar* doc, int length, int& pos, QStyleSheetItem::WhiteSpaceMode wsm );
00928     void setRichTextInternal( const QString &text, QTextCursor* cursor = 0 );
00929     void setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar );
00930 
00931 private:
00932     struct Q_EXPORT Focus {
00933         QTextParagraph *parag;
00934         int start, len;
00935         QString href;
00936         QString name;
00937     };
00938 
00939     int cx, cy, cw, vw;
00940     QTextParagraph *fParag, *lParag;
00941     QTextPreProcessor *pProcessor;
00942     QMap<int, QColor> selectionColors;
00943     QMap<int, QTextDocumentSelection> selections;
00944     QMap<int, bool> selectionText;
00945     QTextCommandHistory *commandHistory;
00946     QTextFormatter *pFormatter;
00947     QTextIndent *indenter;
00948     QTextFormatCollection *fCollection;
00949     Qt::TextFormat txtFormat;
00950     uint preferRichText : 1;
00951     uint pages : 1;
00952     uint useFC : 1;
00953     uint withoutDoubleBuffer : 1;
00954     uint underlLinks : 1;
00955     uint nextDoubleBuffered : 1;
00956     uint oTextValid : 1;
00957     uint mightHaveCustomItems : 1;
00958     int align;
00959     int nSelections;
00960     QTextFlow *flow_;
00961     QTextDocument *par;
00962     QTextParagraph *parentPar;
00963 #ifndef QT_NO_TEXTCUSTOMITEM
00964     QTextTableCell *tc;
00965 #endif
00966     QBrush *backBrush;
00967     QPixmap *buf_pixmap;
00968     Focus focusIndicator;
00969     int minw;
00970     int wused;
00971     int leftmargin;
00972     int rightmargin;
00973     QTextParagraph *minwParag, *curParag;
00974     QStyleSheet* sheet_;
00975 #ifndef QT_NO_MIME
00976     QMimeSourceFactory* factory_;
00977 #endif
00978     QString contxt;
00979     QMap<QString, QString> attribs;
00980     int *tArray;
00981     int tStopWidth;
00982     int uDepth;
00983     QString oText;
00984     QPtrList<QTextDocument> childList;
00985     QColor linkColor;
00986     double scaleFontsFactor;
00987 
00988     short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm;
00989 #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
00990     QTextDocument( const QTextDocument & );
00991     QTextDocument &operator=( const QTextDocument & );
00992 #endif
00993 };
00994 
00995 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00996 
00997 
00998 class Q_EXPORT QTextDeleteCommand : public QTextCommand
00999 {
01000 public:
01001     QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str,
01002                         const QByteArray& oldStyle );
01003     QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str );
01004     virtual ~QTextDeleteCommand();
01005 
01006     Commands type() const { return Delete; }
01007     QTextCursor *execute( QTextCursor *c );
01008     QTextCursor *unexecute( QTextCursor *c );
01009 
01010 protected:
01011     int id, index;
01012     QTextParagraph *parag;
01013     QMemArray<QTextStringChar> text;
01014     QByteArray styleInformation;
01015 
01016 };
01017 
01018 class Q_EXPORT QTextInsertCommand : public QTextDeleteCommand
01019 {
01020 public:
01021     QTextInsertCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str,
01022                         const QByteArray& oldStyleInfo )
01023         : QTextDeleteCommand( d, i, idx, str, oldStyleInfo ) {}
01024     QTextInsertCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str )
01025         : QTextDeleteCommand( p, idx, str ) {}
01026     virtual ~QTextInsertCommand() {}
01027 
01028     Commands type() const { return Insert; }
01029     QTextCursor *execute( QTextCursor *c ) { return QTextDeleteCommand::unexecute( c ); }
01030     QTextCursor *unexecute( QTextCursor *c ) { return QTextDeleteCommand::execute( c ); }
01031 
01032 };
01033 
01034 class Q_EXPORT QTextFormatCommand : public QTextCommand
01035 {
01036 public:
01037     QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl );
01038     virtual ~QTextFormatCommand();
01039 
01040     Commands type() const { return Format; }
01041     QTextCursor *execute( QTextCursor *c );
01042     QTextCursor *unexecute( QTextCursor *c );
01043 
01044 protected:
01045     int startId, startIndex, endId, endIndex;
01046     QTextFormat *format;
01047     QMemArray<QTextStringChar> oldFormats;
01048     int flags;
01049 
01050 };
01051 
01052 class Q_EXPORT QTextStyleCommand : public QTextCommand
01053 {
01054 public:
01055     QTextStyleCommand( QTextDocument *d, int fParag, int lParag, const QByteArray& beforeChange  );
01056     virtual ~QTextStyleCommand() {}
01057 
01058     Commands type() const { return Style; }
01059     QTextCursor *execute( QTextCursor *c );
01060     QTextCursor *unexecute( QTextCursor *c );
01061 
01062     static QByteArray readStyleInformation(  QTextDocument* d, int fParag, int lParag );
01063     static void writeStyleInformation(  QTextDocument* d, int fParag, const QByteArray& style );
01064 
01065 private:
01066     int firstParag, lastParag;
01067     QByteArray before;
01068     QByteArray after;
01069 };
01070 
01071 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01072 
01073 struct Q_EXPORT QTextParagraphSelection
01074 {
01075     int start, end;
01076     Q_DUMMY_COMPARISON_OPERATOR(QTextParagraphSelection)
01077 };
01078 
01079 struct Q_EXPORT QTextLineStart
01080 {
01081     QTextLineStart() : y( 0 ), baseLine( 0 ), h( 0 )
01082 #ifndef QT_NO_COMPLEXTEXT
01083         , bidicontext( 0 )
01084 #endif
01085     {  }
01086     QTextLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ),
01087         w( 0 )
01088 #ifndef QT_NO_COMPLEXTEXT
01089         , bidicontext( 0 )
01090 #endif
01091     {  }
01092 #ifndef QT_NO_COMPLEXTEXT
01093     QTextLineStart( QBidiContext *c, QBidiStatus s ) : y(0), baseLine(0), h(0),
01094         status( s ), bidicontext( c ) { if ( bidicontext ) bidicontext->ref(); }
01095 #endif
01096 
01097     virtual ~QTextLineStart()
01098     {
01099 #ifndef QT_NO_COMPLEXTEXT
01100         if ( bidicontext && bidicontext->deref() )
01101             delete bidicontext;
01102 #endif
01103     }
01104 
01105 #ifndef QT_NO_COMPLEXTEXT
01106     void setContext( QBidiContext *c ) {
01107         if ( c == bidicontext )
01108             return;
01109         if ( bidicontext && bidicontext->deref() )
01110             delete bidicontext;
01111         bidicontext = c;
01112         if ( bidicontext )
01113             bidicontext->ref();
01114     }
01115     QBidiContext *context() const { return bidicontext; }
01116 #endif
01117 
01118 public:
01119     ushort y, baseLine, h;
01120 #ifndef QT_NO_COMPLEXTEXT
01121     QBidiStatus status;
01122 #endif
01123     int w;
01124 
01125 private:
01126 #ifndef QT_NO_COMPLEXTEXT
01127     QBidiContext *bidicontext;
01128 #endif
01129 };
01130 
01131 #if defined(Q_TEMPLATEDLL)
01132 // MOC_SKIP_BEGIN
01133 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextParagraphSelection>;
01134 Q_TEMPLATE_EXTERN template class Q_EXPORT QMap<int, QTextLineStart*>;
01135 // MOC_SKIP_END
01136 #endif
01137 
01138 class Q_EXPORT QTextParagraphData
01139 {
01140 public:
01141     QTextParagraphData() {}
01142     virtual ~QTextParagraphData();
01143     virtual void join( QTextParagraphData * );
01144 };
01145 
01146 class QTextParagraphPseudoDocument;
01147 
01148 class QSyntaxHighlighter;
01149 
01150 class Q_EXPORT QTextParagraph
01151 {
01152     friend class QTextDocument;
01153     friend class QTextCursor;
01154     friend class QSyntaxHighlighter;
01155 
01156 public:
01157     QTextParagraph( QTextDocument *d, QTextParagraph *pr = 0, QTextParagraph *nx = 0, bool updateIds = TRUE );
01158     virtual ~QTextParagraph();
01159 
01160     QTextString *string() const;
01161     QTextStringChar *at( int i ) const; // maybe remove later
01162     int leftGap() const;
01163     int length() const; // maybe remove later
01164 
01165     void setListStyle( QStyleSheetItem::ListStyle ls ) { lstyle = ls; changed = TRUE; }
01166     QStyleSheetItem::ListStyle listStyle() const { return lstyle; }
01167     void setListItem( bool li );
01168     bool isListItem() const { return litem; }
01169     void setListValue( int v ) { list_val = v; }
01170     int listValue() const { return list_val > 0 ? list_val : -1; }
01171 
01172     void setListDepth( int depth );
01173     int listDepth() const { return ldepth; }
01174 
01175 //     void setFormat( QTextFormat *fm );
01176 //     QTextFormat *paragFormat() const;
01177 
01178 #if defined(Q_STRICT_INLINING_RULES)
01179     // This is for the IRIX MIPSpro o32 ABI - it fails, claiming the
01180     // implementation to be a redefinition.
01181     inline QTextDocument *document() const;
01182 #else
01183     QTextDocument *document() const;
01184 #endif
01185     QTextParagraphPseudoDocument *pseudoDocument() const;
01186 
01187     QRect rect() const;
01188     void setHeight( int h ) { r.setHeight( h ); }
01189     void show();
01190     void hide();
01191     bool isVisible() const { return visible; }
01192 
01193     QTextParagraph *prev() const;
01194     QTextParagraph *next() const;
01195     void setPrev( QTextParagraph *s );
01196     void setNext( QTextParagraph *s );
01197 
01198     void insert( int index, const QString &s );
01199     void insert( int index, const QChar *unicode, int len );
01200     void append( const QString &s, bool reallyAtEnd = FALSE );
01201     void truncate( int index );
01202     void remove( int index, int len );
01203     void join( QTextParagraph *s );
01204 
01205     void invalidate( int chr );
01206 
01207     void move( int &dy );
01208     void format( int start = -1, bool doMove = TRUE );
01209 
01210     bool isValid() const;
01211     bool hasChanged() const;
01212     void setChanged( bool b, bool recursive = FALSE );
01213 
01214     int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const;
01215     QTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const;
01216     int lines() const;
01217     QTextStringChar *lineStartOfLine( int line, int *index = 0 ) const;
01218     int lineY( int l ) const;
01219     int lineBaseLine( int l ) const;
01220     int lineHeight( int l ) const;
01221     void lineInfo( int l, int &y, int &h, int &bl ) const;
01222 
01223     void setSelection( int id, int start, int end );
01224     void removeSelection( int id );
01225     int selectionStart( int id ) const;
01226     int selectionEnd( int id ) const;
01227     bool hasSelection( int id ) const;
01228     bool hasAnySelection() const;
01229     bool fullSelected( int id ) const;
01230 
01231     void setEndState( int s );
01232     int endState() const;
01233 
01234     void setParagId( int i );
01235     int paragId() const;
01236 
01237     bool firstPreProcess() const;
01238     void setFirstPreProcess( bool b );
01239 
01240     void indent( int *oldIndent = 0, int *newIndent = 0 );
01241 
01242     void setExtraData( QTextParagraphData *data );
01243     QTextParagraphData *extraData() const;
01244 
01245     QMap<int, QTextLineStart*> &lineStartList();
01246 
01247     void setFormat( int index, int len, QTextFormat *f, bool useCollection = TRUE, int flags = -1 );
01248 
01249     void setAlignment( int a );
01250     int alignment() const;
01251 
01252     virtual void paint( QPainter &painter, const QColorGroup &cg, QTextCursor *cursor = 0, bool drawSelections = FALSE,
01253                         int clipx = -1, int clipy = -1, int clipw = -1, int cliph = -1 );
01254 
01255     virtual int topMargin() const;
01256     virtual int bottomMargin() const;
01257     virtual int leftMargin() const;
01258     virtual int firstLineMargin() const;
01259     virtual int rightMargin() const;
01260     virtual int lineSpacing() const;
01261 
01262 #ifndef QT_NO_TEXTCUSTOMITEM
01263     void registerFloatingItem( QTextCustomItem *i );
01264     void unregisterFloatingItem( QTextCustomItem *i );
01265 #endif
01266 
01267     void setFullWidth( bool b ) { fullWidth = b; }
01268     bool isFullWidth() const { return fullWidth; }
01269 
01270 #ifndef QT_NO_TEXTCUSTOMITEM
01271     QTextTableCell *tableCell() const;
01272 #endif
01273 
01274     QBrush *background() const;
01275 
01276     int documentWidth() const;
01277     int documentVisibleWidth() const;
01278     int documentX() const;
01279     int documentY() const;
01280     QTextFormatCollection *formatCollection() const;
01281     QTextFormatter *formatter() const;
01282 
01283     virtual int nextTab( int i, int x );
01284     int *tabArray() const;
01285     void setTabArray( int *a );
01286     void setTabStops( int tw );
01287 
01288     void adjustToPainter( QPainter *p );
01289 
01290     void setNewLinesAllowed( bool b );
01291     bool isNewLinesAllowed() const;
01292 
01293     QString richText() const;
01294 
01295     void addCommand( QTextCommand *cmd );
01296     QTextCursor *undo( QTextCursor *c = 0 );
01297     QTextCursor *redo( QTextCursor *c  = 0 );
01298     QTextCommandHistory *commands() const;
01299     virtual void copyParagData( QTextParagraph *parag );
01300 
01301     void setBreakable( bool b ) { breakable = b; }
01302     bool isBreakable() const { return breakable; }
01303 
01304     void setBackgroundColor( const QColor &c );
01305     QColor *backgroundColor() const { return bgcol; }
01306     void clearBackgroundColor();
01307 
01308     void setMovedDown( bool b ) { movedDown = b; }
01309     bool wasMovedDown() const { return movedDown; }
01310 
01311     void setDirection( QChar::Direction d );
01312     QChar::Direction direction() const;
01313     void setPaintDevice( QPaintDevice *pd ) { paintdevice = pd; }
01314 
01315     void readStyleInformation( QDataStream& stream );
01316     void writeStyleInformation( QDataStream& stream ) const;
01317 
01318 protected:
01319     virtual void setColorForSelection( QColor &c, QPainter &p, const QColorGroup& cg, int selection );
01320     virtual void drawLabel( QPainter* p, int x, int y, int w, int h, int base, const QColorGroup& cg );
01321     virtual void drawString( QPainter &painter, const QString &str, int start, int len, int xstart,
01322                              int y, int baseLine, int w, int h, int selection,
01323                              QTextStringChar *formatChar, const QColorGroup& cg,
01324                              bool rightToLeft );
01325 
01326 private:
01327     QMap<int, QTextParagraphSelection> &selections() const;
01328 #ifndef QT_NO_TEXTCUSTOMITEM
01329     QPtrList<QTextCustomItem> &floatingItems() const;
01330 #endif
01331     QBrush backgroundBrush( const QColorGroup&cg ) { if ( bgcol ) return *bgcol; return cg.brush( QColorGroup::Base ); }
01332     void invalidateStyleCache();
01333 
01334     QMap<int, QTextLineStart*> lineStarts;
01335     int invalid;
01336     QRect r;
01337     QTextParagraph *p, *n;
01338     void *docOrPseudo;
01339     uint changed : 1;
01340     uint firstFormat : 1;
01341     uint firstPProcess : 1;
01342     uint needPreProcess : 1;
01343     uint fullWidth : 1;
01344     uint lastInFrame : 1;
01345     uint visible : 1;
01346     uint breakable : 1;
01347     uint movedDown : 1;
01348     uint mightHaveCustomItems : 1;
01349     uint hasdoc : 1;
01350     uint litem : 1; // whether the paragraph is a list item
01351     uint rtext : 1; // whether the paragraph needs rich text margin
01352     int align : 4;
01353     int state, id;
01354     QTextString *str;
01355     QMap<int, QTextParagraphSelection> *mSelections;
01356 #ifndef QT_NO_TEXTCUSTOMITEM
01357     QPtrList<QTextCustomItem> *mFloatingItems;
01358 #endif
01359     QStyleSheetItem::ListStyle lstyle;
01360     short utm, ubm, ulm, urm, uflm, ulinespacing;
01361     int *tArray;
01362     short tabStopWidth;
01363     QTextParagraphData *eData;
01364     short list_val;
01365     QColor *bgcol;
01366     ushort ldepth;
01367     QPaintDevice *paintdevice;
01368 };
01369 
01370 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01371 
01372 class Q_EXPORT QTextFormatter
01373 {
01374 public:
01375     QTextFormatter();
01376     virtual ~QTextFormatter();
01377 
01378     virtual int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts ) = 0;
01379     virtual int formatVertically( QTextDocument* doc, QTextParagraph* parag );
01380 
01381     bool isWrapEnabled( QTextParagraph *p ) const { if ( !wrapEnabled ) return FALSE; if ( p && !p->isBreakable() ) return FALSE; return TRUE;}
01382     int wrapAtColumn() const { return wrapColumn;}
01383     virtual void setWrapEnabled( bool b );
01384     virtual void setWrapAtColumn( int c );
01385     virtual void setAllowBreakInWords( bool b ) { biw = b; }
01386     bool allowBreakInWords() const { return biw; }
01387 
01388     int minimumWidth() const { return thisminw; }
01389     int widthUsed() const { return thiswused; }
01390 
01391     static bool isBreakable( QTextString *string, int pos );
01392 
01393 protected:
01394     virtual QTextLineStart *formatLine( QTextParagraph *parag, QTextString *string, QTextLineStart *line, QTextStringChar *start,
01395                                                QTextStringChar *last, int align = Qt::AlignAuto, int space = 0 );
01396 #ifndef QT_NO_COMPLEXTEXT
01397     virtual QTextLineStart *bidiReorderLine( QTextParagraph *parag, QTextString *string, QTextLineStart *line, QTextStringChar *start,
01398                                                     QTextStringChar *last, int align, int space );
01399 #endif
01400     void insertLineStart( QTextParagraph *parag, int index, QTextLineStart *ls );
01401 
01402     int thisminw;
01403     int thiswused;
01404 
01405 private:
01406     bool wrapEnabled;
01407     int wrapColumn;
01408     bool biw;
01409 
01410 #ifdef HAVE_THAI_BREAKS
01411     static QCString *thaiCache;
01412     static QTextString *cachedString;
01413     static ThBreakIterator *thaiIt;
01414 #endif
01415 };
01416 
01417 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01418 
01419 class Q_EXPORT QTextFormatterBreakInWords : public QTextFormatter
01420 {
01421 public:
01422     QTextFormatterBreakInWords();
01423     virtual ~QTextFormatterBreakInWords() {}
01424 
01425     int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts );
01426 
01427 };
01428 
01429 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01430 
01431 class Q_EXPORT QTextFormatterBreakWords : public QTextFormatter
01432 {
01433 public:
01434     QTextFormatterBreakWords();
01435     virtual ~QTextFormatterBreakWords() {}
01436 
01437     int format( QTextDocument *doc, QTextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts );
01438 
01439 };
01440 
01441 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01442 
01443 class Q_EXPORT QTextIndent
01444 {
01445 public:
01446     QTextIndent();
01447     virtual ~QTextIndent() {}
01448 
01449     virtual void indent( QTextDocument *doc, QTextParagraph *parag, int *oldIndent = 0, int *newIndent = 0 ) = 0;
01450 
01451 };
01452 
01453 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01454 
01455 class Q_EXPORT QTextPreProcessor
01456 {
01457 public:
01458     enum Ids {
01459         Standard = 0
01460     };
01461 
01462     QTextPreProcessor();
01463     virtual ~QTextPreProcessor() {}
01464 
01465     virtual void process( QTextDocument *doc, QTextParagraph *, int, bool = TRUE ) = 0;
01466     virtual QTextFormat *format( int id ) = 0;
01467 
01468 };
01469 
01470 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01471 
01472 class Q_EXPORT QTextFormat
01473 {
01474     friend class QTextFormatCollection;
01475     friend class QTextDocument;
01476 
01477 public:
01478     enum Flags {
01479         NoFlags,
01480         Bold = 1,
01481         Italic = 2,
01482         Underline = 4,
01483         Family = 8,
01484         Size = 16,
01485         Color = 32,
01486         Misspelled = 64,
01487         VAlign = 128,
01488         StrikeOut= 256,
01489         Font = Bold | Italic | Underline | Family | Size | StrikeOut,
01490         Format = Font | Color | Misspelled | VAlign
01491     };
01492 
01493     enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript };
01494 
01495     QTextFormat();
01496     virtual ~QTextFormat();
01497 
01498     QTextFormat( const QStyleSheetItem *s );
01499     QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent = 0 );
01500     QTextFormat( const QTextFormat &fm );
01501     QTextFormat makeTextFormat( const QStyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor ) const;
01502     QTextFormat& operator=( const QTextFormat &fm );
01503     QColor color() const;
01504     QFont font() const;
01505     bool isMisspelled() const;
01506     VerticalAlignment vAlign() const;
01507     int minLeftBearing() const;
01508     int minRightBearing() const;
01509     int width( const QChar &c ) const;
01510     int width( const QString &str, int pos ) const;
01511     int height() const;
01512     int ascent() const;
01513     int descent() const;
01514     int leading() const;
01515     bool useLinkColor() const;
01516 
01517     void setBold( bool b );
01518     void setItalic( bool b );
01519     void setUnderline( bool b );
01520     void setStrikeOut( bool b );
01521     void setFamily( const QString &f );
01522     void setPointSize( int s );
01523     void setFont( const QFont &f );
01524     void setColor( const QColor &c );
01525     void setMisspelled( bool b );
01526     void setVAlign( VerticalAlignment a );
01527 
01528     bool operator==( const QTextFormat &f ) const;
01529     QTextFormatCollection *parent() const;
01530     const QString &key() const;
01531 
01532     static QString getKey( const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign );
01533 
01534     void addRef();
01535     void removeRef();
01536 
01537     QString makeFormatChangeTags( QTextFormat* defaultFormat, QTextFormat *f, const QString& oldAnchorHref, const QString& anchorHref ) const;
01538     QString makeFormatEndTags( QTextFormat* defaultFormat, const QString& anchorHref ) const;
01539 
01540     static void setPainter( QPainter *p );
01541     static QPainter* painter();
01542 
01543     bool fontSizesInPixels() { return usePixelSizes; }
01544 
01545 protected:
01546     virtual void generateKey();
01547 
01548 private:
01549     void update();
01550     static void applyFont( const QFont &f );
01551 
01552 private:
01553     QFont fn;
01554     QColor col;
01555     QFontMetrics fm;
01556     uint missp : 1;
01557     uint linkColor : 1;
01558     uint usePixelSizes : 1;
01559     int leftBearing, rightBearing;
01560     VerticalAlignment ha;
01561     uchar widths[ 256 ];
01562     int hei, asc, dsc;
01563     QTextFormatCollection *collection;
01564     int ref;
01565     QString k;
01566     int logicalFontSize;
01567     int stdSize;
01568     static QPainter *pntr;
01569     static QFontMetrics *pntr_fm;
01570     static int pntr_asc;
01571     static int pntr_hei;
01572     static int pntr_ldg;
01573     static int pntr_dsc;
01574 
01575 };
01576 
01577 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01578 
01579 #if defined(Q_TEMPLATEDLL)
01580 // MOC_SKIP_BEGIN
01581 Q_TEMPLATE_EXTERN template class Q_EXPORT QDict<QTextFormat>;
01582 // MOC_SKIP_END
01583 #endif
01584 
01585 class Q_EXPORT QTextFormatCollection
01586 {
01587     friend class QTextDocument;
01588     friend class QTextFormat;
01589 
01590 public:
01591     QTextFormatCollection();
01592     virtual ~QTextFormatCollection();
01593 
01594     void setDefaultFormat( QTextFormat *f );
01595     QTextFormat *defaultFormat() const;
01596     virtual QTextFormat *format( QTextFormat *f );
01597     virtual QTextFormat *format( QTextFormat *of, QTextFormat *nf, int flags );
01598     virtual QTextFormat *format( const QFont &f, const QColor &c );
01599     virtual void remove( QTextFormat *f );
01600     virtual QTextFormat *createFormat( const QTextFormat &f ) { return new QTextFormat( f ); }
01601     virtual QTextFormat *createFormat( const QFont &f, const QColor &c ) { return new QTextFormat( f, c, this ); }
01602 
01603     void updateDefaultFormat( const QFont &font, const QColor &c, QStyleSheet *sheet );
01604 
01605     QPaintDevice *paintDevice() const { return paintdevice; }
01606     void setPaintDevice( QPaintDevice * );
01607 
01608 private:
01609     void updateKeys();
01610 
01611 private:
01612     QTextFormat *defFormat, *lastFormat, *cachedFormat;
01613     QDict<QTextFormat> cKey;
01614     QTextFormat *cres;
01615     QFont cfont;
01616     QColor ccol;
01617     QString kof, knf;
01618     int cflags;
01619 
01620     QPaintDevice *paintdevice;
01621 };
01622 
01623 class Q_EXPORT QTextParagraphPseudoDocument
01624 {
01625 public:
01626     QTextParagraphPseudoDocument();
01627     ~QTextParagraphPseudoDocument();
01628     QRect docRect;
01629     QTextFormatter *pFormatter;
01630     QTextCommandHistory *commandHistory;
01631     int minw;
01632     int wused;
01633     QTextFormatCollection collection;
01634 };
01635 
01636 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01637 
01638 inline int QTextString::length() const
01639 {
01640     return data.size();
01641 }
01642 
01643 inline int QTextParagraph::length() const
01644 {
01645     return str->length();
01646 }
01647 
01648 inline QRect QTextParagraph::rect() const
01649 {
01650     return r;
01651 }
01652 
01653 inline QTextParagraph *QTextCursor::paragraph() const
01654 {
01655     return para;
01656 }
01657 
01658 inline int QTextCursor::index() const
01659 {
01660     return idx;
01661 }
01662 
01663 
01664 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01665 
01666 inline int QTextDocument::x() const
01667 {
01668     return cx;
01669 }
01670 
01671 inline int QTextDocument::y() const
01672 {
01673     return cy;
01674 }
01675 
01676 inline int QTextDocument::width() const
01677 {
01678     return QMAX( cw, flow_->width() );
01679 }
01680 
01681 inline int QTextDocument::visibleWidth() const
01682 {
01683     return vw;
01684 }
01685 
01686 inline QTextParagraph *QTextDocument::firstParagraph() const
01687 {
01688     return fParag;
01689 }
01690 
01691 inline QTextParagraph *QTextDocument::lastParagraph() const
01692 {
01693     return lParag;
01694 }
01695 
01696 inline void QTextDocument::setFirstParagraph( QTextParagraph *p )
01697 {
01698     fParag = p;
01699 }
01700 
01701 inline void QTextDocument::setLastParagraph( QTextParagraph *p )
01702 {
01703     lParag = p;
01704 }
01705 
01706 inline void QTextDocument::setWidth( int w )
01707 {
01708     cw = QMAX( w, minw );
01709     flow_->setWidth( cw );
01710     vw = w;
01711 }
01712 
01713 inline int QTextDocument::minimumWidth() const
01714 {
01715     return minw;
01716 }
01717 
01718 inline void QTextDocument::setY( int y )
01719 {
01720     cy = y;
01721 }
01722 
01723 inline int QTextDocument::leftMargin() const
01724 {
01725     return leftmargin;
01726 }
01727 
01728 inline void QTextDocument::setLeftMargin( int lm )
01729 {
01730     leftmargin = lm;
01731 }
01732 
01733 inline int QTextDocument::rightMargin() const
01734 {
01735     return rightmargin;
01736 }
01737 
01738 inline void QTextDocument::setRightMargin( int rm )
01739 {
01740     rightmargin = rm;
01741 }
01742 
01743 inline QTextPreProcessor *QTextDocument::preProcessor() const
01744 {
01745     return pProcessor;
01746 }
01747 
01748 inline void QTextDocument::setPreProcessor( QTextPreProcessor * sh )
01749 {
01750     pProcessor = sh;
01751 }
01752 
01753 inline void QTextDocument::setFormatter( QTextFormatter *f )
01754 {
01755     delete pFormatter;
01756     pFormatter = f;
01757 }
01758 
01759 inline QTextFormatter *QTextDocument::formatter() const
01760 {
01761     return pFormatter;
01762 }
01763 
01764 inline void QTextDocument::setIndent( QTextIndent *i )
01765 {
01766     indenter = i;
01767 }
01768 
01769 inline QTextIndent *QTextDocument::indent() const
01770 {
01771     return indenter;
01772 }
01773 
01774 inline QColor QTextDocument::selectionColor( int id ) const
01775 {
01776     return selectionColors[ id ];
01777 }
01778 
01779 inline bool QTextDocument::invertSelectionText( int id ) const
01780 {
01781     return selectionText[ id ];
01782 }
01783 
01784 inline void QTextDocument::setSelectionColor( int id, const QColor &c )
01785 {
01786     selectionColors[ id ] = c;
01787 }
01788 
01789 inline void QTextDocument::setInvertSelectionText( int id, bool b )
01790 {
01791     selectionText[ id ] = b;
01792 }
01793 
01794 inline QTextFormatCollection *QTextDocument::formatCollection() const
01795 {
01796     return fCollection;
01797 }
01798 
01799 inline int QTextDocument::alignment() const
01800 {
01801     return align;
01802 }
01803 
01804 inline void QTextDocument::setAlignment( int a )
01805 {
01806     align = a;
01807 }
01808 
01809 inline int *QTextDocument::tabArray() const
01810 {
01811     return tArray;
01812 }
01813 
01814 inline int QTextDocument::tabStopWidth() const
01815 {
01816     return tStopWidth;
01817 }
01818 
01819 inline void QTextDocument::setTabArray( int *a )
01820 {
01821     tArray = a;
01822 }
01823 
01824 inline void QTextDocument::setTabStops( int tw )
01825 {
01826     tStopWidth = tw;
01827 }
01828 
01829 inline QString QTextDocument::originalText() const
01830 {
01831     if ( oTextValid )
01832         return oText;
01833     return text();
01834 }
01835 
01836 inline void QTextDocument::setFlow( QTextFlow *f )
01837 {
01838     if ( flow_ )
01839         delete flow_;
01840     flow_ = f;
01841 }
01842 
01843 inline void QTextDocument::takeFlow()
01844 {
01845     flow_ = 0;
01846 }
01847 
01848 inline bool QTextDocument::useDoubleBuffer( QTextParagraph *parag, QPainter *p )
01849 {
01850     return ( !parag->document()->parent() || parag->document()->nextDoubleBuffered ) &&
01851         ( !p || !p->device() || p->device()->devType() != QInternal::Printer );
01852 }
01853 
01854 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01855 
01856 inline QColor QTextFormat::color() const
01857 {
01858     return col;
01859 }
01860 
01861 inline QFont QTextFormat::font() const
01862 {
01863     return fn;
01864 }
01865 
01866 inline bool QTextFormat::isMisspelled() const
01867 {
01868     return missp;
01869 }
01870 
01871 inline QTextFormat::VerticalAlignment QTextFormat::vAlign() const
01872 {
01873     return ha;
01874 }
01875 
01876 inline bool QTextFormat::operator==( const QTextFormat &f ) const
01877 {
01878     return k == f.k;
01879 }
01880 
01881 inline QTextFormatCollection *QTextFormat::parent() const
01882 {
01883     return collection;
01884 }
01885 
01886 inline void QTextFormat::addRef()
01887 {
01888     ref++;
01889 }
01890 
01891 inline void QTextFormat::removeRef()
01892 {
01893     ref--;
01894     if ( !collection )
01895         return;
01896     if ( this == collection->defFormat )
01897         return;
01898     if ( ref == 0 )
01899         collection->remove( this );
01900 }
01901 
01902 inline const QString &QTextFormat::key() const
01903 {
01904     return k;
01905 }
01906 
01907 inline bool QTextFormat::useLinkColor() const
01908 {
01909     return linkColor;
01910 }
01911 
01912 
01913 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01914 
01915 inline QTextStringChar &QTextString::at( int i ) const
01916 {
01917     return data[ i ];
01918 }
01919 
01920 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01921 
01922 inline QTextStringChar *QTextParagraph::at( int i ) const
01923 {
01924     return &str->at( i );
01925 }
01926 
01927 inline bool QTextParagraph::isValid() const
01928 {
01929     return invalid == -1;
01930 }
01931 
01932 inline bool QTextParagraph::hasChanged() const
01933 {
01934     return changed;
01935 }
01936 
01937 inline void QTextParagraph::setBackgroundColor( const QColor & c )
01938 {
01939     delete bgcol;
01940     bgcol = new QColor( c );
01941     setChanged( TRUE );
01942 }
01943 
01944 inline void QTextParagraph::clearBackgroundColor()
01945 {
01946     delete bgcol; bgcol = 0; setChanged( TRUE );
01947 }
01948 
01949 inline void QTextParagraph::append( const QString &s, bool reallyAtEnd )
01950 {
01951     if ( reallyAtEnd )
01952         insert( str->length(), s );
01953     else
01954         insert( QMAX( str->length() - 1, 0 ), s );
01955 }
01956 
01957 inline QTextParagraph *QTextParagraph::prev() const
01958 {
01959     return p;
01960 }
01961 
01962 inline QTextParagraph *QTextParagraph::next() const
01963 {
01964     return n;
01965 }
01966 
01967 inline bool QTextParagraph::hasAnySelection() const
01968 {
01969     return mSelections ? !selections().isEmpty() : FALSE;
01970 }
01971 
01972 inline void QTextParagraph::setEndState( int s )
01973 {
01974     if ( s == state )
01975         return;
01976     state = s;
01977 }
01978 
01979 inline int QTextParagraph::endState() const
01980 {
01981     return state;
01982 }
01983 
01984 inline void QTextParagraph::setParagId( int i )
01985 {
01986     id = i;
01987 }
01988 
01989 inline int QTextParagraph::paragId() const
01990 {
01991     if ( id == -1 )
01992         qWarning( "invalid parag id!!!!!!!! (%p)", (void*)this );
01993     return id;
01994 }
01995 
01996 inline bool QTextParagraph::firstPreProcess() const
01997 {
01998     return firstPProcess;
01999 }
02000 
02001 inline void QTextParagraph::setFirstPreProcess( bool b )
02002 {
02003     firstPProcess = b;
02004 }
02005 
02006 inline QMap<int, QTextLineStart*> &QTextParagraph::lineStartList()
02007 {
02008     return lineStarts;
02009 }
02010 
02011 inline QTextString *QTextParagraph::string() const
02012 {
02013     return str;
02014 }
02015 
02016 inline QTextDocument *QTextParagraph::document() const
02017 {
02018     if ( hasdoc )
02019         return (QTextDocument*) docOrPseudo;
02020     return 0;
02021 }
02022 
02023 inline QTextParagraphPseudoDocument *QTextParagraph::pseudoDocument() const
02024 {
02025     if ( hasdoc )
02026         return 0;
02027     return (QTextParagraphPseudoDocument*) docOrPseudo;
02028 }
02029 
02030 
02031 #ifndef QT_NO_TEXTCUSTOMITEM
02032 inline QTextTableCell *QTextParagraph::tableCell() const
02033 {
02034     return hasdoc ? document()->tableCell () : 0;
02035 }
02036 #endif
02037 
02038 inline QTextCommandHistory *QTextParagraph::commands() const
02039 {
02040     return hasdoc ? document()->commands() : pseudoDocument()->commandHistory;
02041 }
02042 
02043 
02044 inline int QTextParagraph::alignment() const
02045 {
02046     return align;
02047 }
02048 
02049 #ifndef QT_NO_TEXTCUSTOMITEM
02050 inline void QTextParagraph::registerFloatingItem( QTextCustomItem *i )
02051 {
02052     floatingItems().append( i );
02053 }
02054 
02055 inline void QTextParagraph::unregisterFloatingItem( QTextCustomItem *i )
02056 {
02057     floatingItems().removeRef( i );
02058 }
02059 #endif
02060 
02061 inline QBrush *QTextParagraph::background() const
02062 {
02063 #ifndef QT_NO_TEXTCUSTOMITEM
02064     return tableCell() ? tableCell()->backGround() : 0;
02065 #else
02066     return 0;
02067 #endif
02068 }
02069 
02070 inline int QTextParagraph::documentWidth() const
02071 {
02072     return hasdoc ? document()->width() : pseudoDocument()->docRect.width();
02073 }
02074 
02075 inline int QTextParagraph::documentVisibleWidth() const
02076 {
02077     return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width();
02078 }
02079 
02080 inline int QTextParagraph::documentX() const
02081 {
02082     return hasdoc ? document()->x() : pseudoDocument()->docRect.x();
02083 }
02084 
02085 inline int QTextParagraph::documentY() const
02086 {
02087     return hasdoc ? document()->y() : pseudoDocument()->docRect.y();
02088 }
02089 
02090 inline void QTextParagraph::setExtraData( QTextParagraphData *data )
02091 {
02092     eData = data;
02093 }
02094 
02095 inline QTextParagraphData *QTextParagraph::extraData() const
02096 {
02097     return eData;
02098 }
02099 
02100 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
02101 
02102 inline void QTextFormatCollection::setDefaultFormat( QTextFormat *f )
02103 {
02104     defFormat = f;
02105 }
02106 
02107 inline QTextFormat *QTextFormatCollection::defaultFormat() const
02108 {
02109     return defFormat;
02110 }
02111 
02112 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
02113 
02114 inline QTextFormat *QTextStringChar::format() const
02115 {
02116     return (type == Regular) ? d.format : d.custom->format;
02117 }
02118 
02119 
02120 #ifndef QT_NO_TEXTCUSTOMITEM
02121 inline QTextCustomItem *QTextStringChar::customItem() const
02122 {
02123     return isCustom() ? d.custom->custom : 0;
02124 }
02125 #endif
02126 
02127 inline int QTextStringChar::height() const
02128 {
02129 #ifndef QT_NO_TEXTCUSTOMITEM
02130     return !isCustom() ? format()->height() : ( customItem()->placement() == QTextCustomItem::PlaceInline ? customItem()->height : 0 );
02131 #else
02132     return format()->height();
02133 #endif
02134 }
02135 
02136 inline int QTextStringChar::ascent() const
02137 {
02138 #ifndef QT_NO_TEXTCUSTOMITEM
02139     return !isCustom() ? format()->ascent() : ( customItem()->placement() == QTextCustomItem::PlaceInline ? customItem()->ascent() : 0 );
02140 #else
02141     return format()->ascent();
02142 #endif
02143 }
02144 
02145 inline int QTextStringChar::descent() const
02146 {
02147 #ifndef QT_NO_TEXTCUSTOMITEM
02148     return !isCustom() ? format()->descent() : 0;
02149 #else
02150     return format()->descent();
02151 #endif
02152 }
02153 
02154 #endif //QT_NO_RICHTEXT
02155 
02156 #endif

Generated on Sat Nov 5 16:17:05 2005 for OPIE by  doxygen 1.4.2