lib Library API Documentation

korichtext.h

00001 
00008 /****************************************************************************
00009 **
00010 ** Definition of internal rich text classes
00011 **
00012 ** Created : 990124
00013 **
00014 ** Copyright (C) 1999-2000 Trolltech AS.  All rights reserved.
00015 **
00016 ** This file is part of the kernel module of the Qt GUI Toolkit.
00017 **
00018 ** This file may be distributed under the terms of the Q Public License
00019 ** as defined by Trolltech AS of Norway and appearing in the file
00020 ** LICENSE.QPL included in the packaging of this file.
00021 **
00022 ** This file may be distributed and/or modified under the terms of the
00023 ** GNU General Public License version 2 as publish by the Free Software
00024 ** Foundation and appearing in the file LICENSE.GPL included in the
00025 ** packaging of this file.
00026 **
00027 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00028 ** licenses may use this file in accordance with the Qt Commercial License
00029 ** Agreement provided with the Software.
00030 **
00031 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00032 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00033 **
00034 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00035 **   information about Qt Commercial License Agreements.
00036 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00037 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00038 **
00039 ** Contact info@trolltech.com if any conditions of this licensing are
00040 ** not clear to you.
00041 **
00042 **********************************************************************/
00043 
00044 #ifndef QRICHTEXT_P_H
00045 #define QRICHTEXT_P_H
00046 
00047 //
00048 //  W A R N I N G
00049 //  -------------
00050 //
00051 // This file is not part of the Qt API.  It exists for the convenience
00052 // of a number of Qt sources files.  This header file may change from
00053 // version to version without notice, or even be removed.
00054 //
00055 // We mean it.
00056 //
00057 //
00058 
00059 #ifndef QT_H
00060 #include "qstring.h"
00061 #include "qptrlist.h"
00062 #include "qrect.h"
00063 #include "qfontmetrics.h"
00064 #include "qintdict.h"
00065 #include "qmap.h"
00066 #include "qstringlist.h"
00067 #include "qfont.h"
00068 #include "qcolor.h"
00069 #include "qsize.h"
00070 #include "qvaluelist.h"
00071 #include "qvaluestack.h"
00072 #include "qobject.h"
00073 #include "qdict.h"
00074 #include "qtextstream.h"
00075 #include "qpixmap.h"
00076 #include "qstylesheet.h"
00077 #include "qptrvector.h"
00078 #include "qpainter.h"
00079 #include "qlayout.h"
00080 #include "qobject.h"
00081 #include <limits.h>
00082 #include "qcomplextext_p.h"
00083 #include "qapplication.h"
00084 #endif // QT_H
00085 
00086 #include <koffice_export.h>
00087 class KoXmlWriter;
00088 class KoGenStyles;
00089 class KoTextParag;
00090 class KoTextString;
00091 class KoTextCursor;
00092 class KoTextCustomItem;
00093 class KoTextFlow;
00094 class KoTextDocument;
00095 //class KoTextPreProcessor;
00096 class KoTextFormatterBase;
00097 class KoTextFormat;
00098 class KoTextFormatCollection;
00099 struct KoBidiContext;
00100 
00102 class KCommand;
00103 class QDomElement;
00104 class KoZoomHandler;
00105 class KoTextFormatter;
00106 class KoParagVisitor;
00107 class KoTextDocCommand;
00108 class KoXmlWriter;
00109 class KoSavingContext;
00110 
00111 #include <qmemarray.h>
00112 #include "koparaglayout.h"
00114 
00115 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00116 
00117 class KOTEXT_EXPORT KoTextStringChar
00118 {
00119     friend class KoTextString;
00120 
00121 public:
00122     // this is never called, initialize variables in KoTextString::insert()!!!
00123     KoTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0; }
00124     ~KoTextStringChar();
00125 
00126     QChar c;
00127 
00128     // this is the same struct as in qtextengine_p.h. Don't change!
00129     uchar softBreak      :1;     // Potential linebreak point
00130     uchar whiteSpace     :1;     // A unicode whitespace character, except NBSP, ZWNBSP
00131     uchar charStop       :1;     // Valid cursor position (for left/right arrow)
00132     uchar wordStop       :1;     // Valid cursor position (for ctrl + left/right arrow) (TODO: use)
00133     //uchar nobreak        :1;
00134 
00135     enum Type { Regular, Custom };
00136     uint lineStart : 1;
00137     Type type : 1;
00138     uint startOfRun : 1;
00139     uint rightToLeft : 1;
00140 
00141     // --- added for WYSIWYG ---
00142     Q_INT8 pixelxadj; // adjustment to apply to lu2pixel(x)
00143     short int pixelwidth; // width in pixels
00144     short int width; // width in LU
00145 
00146     int x;
00147     int height() const;
00148     int ascent() const;
00149     int descent() const;
00150     bool isCustom() const { return type == Custom; }
00151     KoTextFormat *format() const;
00152     KoTextCustomItem *customItem() const;
00153     void setFormat( KoTextFormat *f,bool setFormatAgain=TRUE );
00154     void setCustomItem( KoTextCustomItem *i );
00155     void loseCustomItem();
00156     struct CustomData
00157     {
00158     KoTextFormat *format;
00159     KoTextCustomItem *custom;
00160     };
00161 
00162     union {
00163     KoTextFormat* format;
00164     CustomData* custom;
00165     } d;
00166 
00167 private:
00168     KoTextStringChar &operator=( const KoTextStringChar & ) {
00169     //abort();
00170     return *this;
00171     }
00172     KoTextStringChar( const KoTextStringChar & ); // copy-constructor, forbidden
00173     friend class KoComplexText;
00174     friend class KoTextParag;
00175 };
00176 
00177 #if defined(Q_TEMPLATEDLL)
00178 // MOC_SKIP_BEGIN
00179 template class QMemArray<KoTextStringChar>;
00180 // MOC_SKIP_END
00181 #endif
00182 
00183 class KOTEXT_EXPORT KoTextString
00184 {
00185 public:
00186 
00187     KoTextString();
00188     KoTextString( const KoTextString &s );
00189     virtual ~KoTextString();
00190 
00191     QString toString() const;
00192     static QString toString( const QMemArray<KoTextStringChar> &data );
00193     QString toReverseString() const;
00194 
00195     QString stringToSpellCheck();
00196 
00197     KoTextStringChar &at( int i ) const;
00198     int length() const;
00199 
00200     //int width( int idx ) const; // moved to KoTextFormat
00201 
00202     void insert( int index, const QString &s, KoTextFormat *f );
00203     void insert( int index, KoTextStringChar *c );
00204     void truncate( int index );
00205     void remove( int index, int len );
00206     void clear();
00207 
00208     void setFormat( int index, KoTextFormat *f, bool useCollection, bool setFormatAgain = FALSE );
00209 
00210     void setBidi( bool b ) { bidi = b; }
00211     bool isBidi() const;
00212     bool isRightToLeft() const;
00213     QChar::Direction direction() const;
00214     void setDirection( QChar::Direction d ) { dir = d; bidiDirty = TRUE; }
00215 
00217     void setNeedsSpellCheck( bool b ) { bNeedsSpellCheck = b; }
00218     bool needsSpellCheck() const { return bNeedsSpellCheck; }
00219 
00220     QMemArray<KoTextStringChar> subString( int start = 0, int len = 0xFFFFFF ) const;
00221     QString mid( int start = 0, int len = 0xFFFFFF ) const; // kotext addition
00222     QMemArray<KoTextStringChar> rawData() const { return data.copy(); }
00223 
00224     void operator=( const QString &s ) { clear(); insert( 0, s, 0 ); }
00225     void operator+=( const QString &s );
00226     void prepend( const QString &s ) { insert( 0, s, 0 ); }
00227 
00228     // return next and previous valid cursor positions.
00229     bool validCursorPosition( int idx );
00230     int nextCursorPosition( int idx );
00231     int previousCursorPosition( int idx );
00232 
00233 private:
00234     void checkBidi() const;
00235 
00236     QMemArray<KoTextStringChar> data;
00237     uint bidiDirty : 1;
00238     uint bidi : 1; // true when the paragraph has right to left characters
00239     uint rightToLeft : 1;
00240     uint dir : 5;
00241     uint bNeedsSpellCheck : 1;
00242 };
00243 
00244 inline bool KoTextString::isBidi() const
00245 {
00246     if ( bidiDirty )
00247     checkBidi();
00248     return bidi;
00249 }
00250 
00251 inline bool KoTextString::isRightToLeft() const
00252 {
00253     if ( bidiDirty )
00254     checkBidi();
00255     return rightToLeft;
00256 }
00257 
00258 inline QChar::Direction KoTextString::direction() const
00259 {
00260     return (QChar::Direction) dir;
00261 }
00262 
00263 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00264 
00265 #if defined(Q_TEMPLATEDLL)
00266 // MOC_SKIP_BEGIN
00267 template class QValueStack<int>;
00268 template class QValueStack<KoTextParag*>;
00269 template class QValueStack<bool>;
00270 // MOC_SKIP_END
00271 #endif
00272 
00273 class KOTEXT_EXPORT KoTextCursor
00274 {
00275 public:
00276     KoTextCursor( KoTextDocument *d );
00277     KoTextCursor();
00278     KoTextCursor( const KoTextCursor &c );
00279     KoTextCursor &operator=( const KoTextCursor &c );
00280     virtual ~KoTextCursor() {}
00281 
00282     bool operator==( const KoTextCursor &c ) const;
00283     bool operator!=( const KoTextCursor &c ) const { return !(*this == c); }
00284 
00285     KoTextDocument *document() const { return doc; }
00286     void setDocument( KoTextDocument *d );
00287 
00288     KoTextParag *parag() const;
00289     int index() const;
00290     void setParag( KoTextParag *s, bool restore = TRUE );
00291 
00292     void gotoLeft();
00293     void gotoRight();
00294     void gotoNextLetter();
00295     void gotoPreviousLetter();
00296     void gotoUp();
00297     void gotoDown();
00298     void gotoLineEnd();
00299     void gotoLineStart();
00300     void gotoHome();
00301     void gotoEnd();
00302     void gotoPageUp( int visibleHeight );
00303     void gotoPageDown( int visibleHeight );
00304     void gotoNextWord();
00305     void gotoPreviousWord();
00306     void gotoWordLeft();
00307     void gotoWordRight();
00308 
00309     void insert( const QString &s, bool checkNewLine, QMemArray<KoTextStringChar> *formatting = 0 );
00310     void splitAndInsertEmptyParag( bool ind = TRUE, bool updateIds = TRUE );
00311     bool remove();
00312     bool removePreviousChar();
00313     void killLine();
00314     //void indent();
00315 
00316     bool atParagStart() const;
00317     bool atParagEnd() const;
00318 
00319     void setIndex( int i, bool restore = TRUE );
00320 
00321     //void checkIndex();
00322 
00323     //int offsetX() const { return ox; }
00324     //int offsetY() const { return oy; }
00325 
00326     bool place( const QPoint &pos, KoTextParag *s, bool link = false, int *customItemIndex = 0 );
00327 
00328     int x() const;
00329     int y() const;
00330     void fixCursorPosition();
00331 
00332 private:
00333     KoTextParag *string;
00334     KoTextDocument *doc;
00335     int idx, tmpIndex;
00336     //int ox, oy;
00337 };
00338 
00339 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00340 
00341 class KoTextDocCommand
00342 {
00343 public:
00344     enum Commands { Invalid, Insert, Delete, Format, Alignment, ParagType };
00345 
00346     KoTextDocCommand( KoTextDocument *d ) : doc( d ), cursor( d ) {}
00347     virtual ~KoTextDocCommand() {}
00348     virtual Commands type() const { return Invalid; };
00349 
00350     virtual KoTextCursor *execute( KoTextCursor *c ) = 0;
00351     virtual KoTextCursor *unexecute( KoTextCursor *c ) = 0;
00352 
00353 protected:
00354     KoTextDocument *doc;
00355     KoTextCursor cursor;
00356 
00357 };
00358 
00359 #if defined(Q_TEMPLATEDLL)
00360 // MOC_SKIP_BEGIN
00361 template class QPtrList<KoTextDocCommand>;
00362 // MOC_SKIP_END
00363 #endif
00364 
00365 class KoTextDocCommandHistory
00366 {
00367 public:
00368     KoTextDocCommandHistory( int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); }
00369     virtual ~KoTextDocCommandHistory() { clear(); }
00370 
00371     void clear() { history.clear(); current = -1; }
00372 
00373     void addCommand( KoTextDocCommand *cmd );
00374     KoTextCursor *undo( KoTextCursor *c );
00375     KoTextCursor *redo( KoTextCursor *c );
00376 
00377     bool isUndoAvailable();
00378     bool isRedoAvailable();
00379 
00380     void setUndoDepth( int d ) { steps = d; }
00381     int undoDepth() const { return steps; }
00382 
00383     int historySize() const { return history.count(); }
00384     int currentPosition() const { return current; }
00385 
00386 private:
00387     QPtrList<KoTextDocCommand> history;
00388     int current, steps;
00389 
00390 };
00391 
00392 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00393 
00394 class KOTEXT_EXPORT KoTextCustomItem
00395 {
00396 public:
00397     KoTextCustomItem( KoTextDocument *p );
00398     virtual ~KoTextCustomItem();
00399     virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) /* = 0*/;
00400 
00401     // Called after the item's paragraph has been formatted
00402     virtual void finalize() {}
00403 
00404     void move( int x, int y ) { xpos = x; ypos = y; }
00405     int x() const { return xpos; }
00406     int y() const { return ypos; }
00407 
00408     // Called when the format of the character is being changed, see KoTextStringChar::setFormat
00409     virtual void setFormat( KoTextFormat * ) { }
00410 
00411     //virtual void setPainter( QPainter*, bool adjust );
00412 
00413     enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
00414     virtual Placement placement() const { return PlaceInline; }
00415     bool placeInline() { return placement() == PlaceInline; }
00416 
00417     virtual bool ownLine() const { return FALSE; }
00418     // Called for "ownline" items
00419     virtual void resize( int nwidth ) { width = nwidth; }
00420     virtual void invalidate() {};
00421 
00422     virtual bool isNested() const { return FALSE; }
00423     virtual int minimumWidth() const { return 0; }
00424     virtual int widthHint() const { return 0; }
00425     virtual int ascent() const { return height; }
00426 
00427     virtual QString richText() const { return QString::null; }
00428 
00429     int width;
00430     int height;
00431 
00432     QRect geometry() const { return QRect( xpos, ypos, width, height ); }
00433 
00434     virtual bool enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
00435     virtual bool enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, const QPoint & );
00436     virtual bool next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00437     virtual bool prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00438     virtual bool down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00439     virtual bool up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00440 
00441     void setParagraph( KoTextParag * p ) { parag = p; }
00442     KoTextParag *paragraph() const { return parag; }
00443 
00444     virtual void pageBreak( int /*y*/, KoTextFlow* /*flow*/ ) {}
00445 
00446     KoTextDocument *parent;
00447 
00448 #include "kotextcustomitem.h"
00449 
00450 protected:
00451     int xpos;
00452     int ypos;
00453 private:
00454     KoTextParag *parag;
00455 };
00456 
00457 #if defined(Q_TEMPLATEDLL)
00458 // MOC_SKIP_BEGIN
00459 template class QMap<QString, QString>;
00460 // MOC_SKIP_END
00461 #endif
00462 
00463 #if 0
00464 class KoTextImage : public KoTextCustomItem
00465 {
00466 public:
00467     KoTextImage( KoTextDocument *p, const QMap<QString, QString> &attr, const QString& context,
00468         QMimeSourceFactory &factory );
00469     virtual ~KoTextImage();
00470 
00471     Placement placement() const { return place; }
00472     //void setPainter( QPainter*, bool );
00473     int widthHint() const { return width; }
00474     int minimumWidth() const { return width; }
00475 
00476     QString richText() const;
00477 
00478     void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00479 
00480 private:
00481     QRegion* reg;
00482     QPixmap pm;
00483     Placement place;
00484     int tmpwidth, tmpheight;
00485     QMap<QString, QString> attributes;
00486     QString imgId;
00487 
00488 };
00489 #endif
00490 
00491 class KoTextHorizontalLine : public KoTextCustomItem
00492 {
00493 public:
00494     KoTextHorizontalLine( KoTextDocument *p, const QMap<QString, QString> &attr, const QString& context,
00495              QMimeSourceFactory &factory );
00496     virtual ~KoTextHorizontalLine();
00497 
00498     //void setPainter( QPainter*, bool );
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 
00508 };
00509 
00510 #if defined(Q_TEMPLATEDLL)
00511 // MOC_SKIP_BEGIN
00512 template class QPtrList<KoTextCustomItem>;
00513 // MOC_SKIP_END
00514 #endif
00515 
00516 class KOTEXT_EXPORT KoTextFlow
00517 {
00518     friend class KoTextDocument;
00519     friend class KoTextTableCell;
00520 
00521 public:
00522     KoTextFlow();
00523     virtual ~KoTextFlow();
00524 
00525     // Called by KoTextDocument::setWidth()
00526     virtual void setWidth( int width );
00527 
00528     // This is the value returned by KoTextDocument::width()
00529     int width() const { return w; }
00530 
00531     //virtual void setPageSize( int ps );
00532     //int pageSize() const { return pagesize; }
00533 
00541     virtual void adjustMargins( int yp, int h, int reqMinWidth, int& leftMargin, int& rightMargin, int& pageWidth, KoTextParag* parag );
00542 
00543     virtual void registerFloatingItem( KoTextCustomItem* item );
00544     virtual void unregisterFloatingItem( KoTextCustomItem* item );
00545     //virtual QRect boundingRect() const;
00546 
00548     virtual int availableHeight() const;
00549     virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00550 
00551     virtual int adjustFlow( int y, int w, int h ); // adjusts y according to the defined pagesize. Returns the shift.
00552 
00553     virtual bool isEmpty();
00554 
00555     void clear();
00556 
00557 private:
00558     int w;
00559     //int pagesize;
00560 
00561     QPtrList<KoTextCustomItem> leftItems;
00562     QPtrList<KoTextCustomItem> rightItems;
00563 
00564 };
00565 
00566 #ifdef QTEXTTABLE_AVAILABLE
00567 class KoTextTable;
00568 
00569 class KoTextTableCell : public QLayoutItem
00570 {
00571     friend class KoTextTable;
00572 
00573 public:
00574     KoTextTableCell( KoTextTable* table,
00575             int row, int column,
00576             const QMap<QString, QString> &attr,
00577             const QStyleSheetItem* style,
00578             const KoTextFormat& fmt, const QString& context,
00579             QMimeSourceFactory &factory, QStyleSheet *sheet, const QString& doc );
00580     KoTextTableCell( KoTextTable* table, int row, int column );
00581     virtual ~KoTextTableCell();
00582 
00583     QSize sizeHint() const ;
00584     QSize minimumSize() const ;
00585     QSize maximumSize() const ;
00586     QSizePolicy::ExpandData expanding() const;
00587     bool isEmpty() const;
00588     void setGeometry( const QRect& ) ;
00589     QRect geometry() const;
00590 
00591     bool hasHeightForWidth() const;
00592     int heightForWidth( int ) const;
00593 
00594     void setPainter( QPainter*, bool );
00595 
00596     int row() const { return row_; }
00597     int column() const { return col_; }
00598     int rowspan() const { return rowspan_; }
00599     int colspan() const { return colspan_; }
00600     int stretch() const { return stretch_; }
00601 
00602     KoTextDocument* richText()  const { return richtext; }
00603     KoTextTable* table() const { return parent; }
00604 
00605     void draw( int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected );
00606 
00607     QBrush *backGround() const { return background; }
00608     virtual void invalidate();
00609 
00610     int verticalAlignmentOffset() const;
00611     int horizontalAlignmentOffset() const;
00612 
00613 private:
00614     QPainter* painter() const;
00615     QRect geom;
00616     KoTextTable* parent;
00617     KoTextDocument* richtext;
00618     int row_;
00619     int col_;
00620     int rowspan_;
00621     int colspan_;
00622     int stretch_;
00623     int maxw;
00624     int minw;
00625     bool hasFixedWidth;
00626     QBrush *background;
00627     int cached_width;
00628     int cached_sizehint;
00629     QMap<QString, QString> attributes;
00630     int align;
00631 };
00632 
00633 #if defined(Q_TEMPLATEDLL)
00634 // MOC_SKIP_BEGIN
00635 template class QPtrList<KoTextTableCell>;
00636 template class QMap<KoTextCursor*, int>;
00637 // MOC_SKIP_END
00638 #endif
00639 
00640 class KoTextTable: public KoTextCustomItem
00641 {
00642     friend class KoTextTableCell;
00643 
00644 public:
00645     KoTextTable( KoTextDocument *p, const QMap<QString, QString> &attr );
00646     virtual ~KoTextTable();
00647 
00648     void setPainter( QPainter *p, bool adjust );
00649     void pageBreak( int  y, KoTextFlow* flow );
00650     void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
00651            const QColorGroup& cg, bool selected );
00652 
00653     bool noErase() const { return TRUE; }
00654     bool ownLine() const { return TRUE; }
00655     Placement placement() const { return place; }
00656     bool isNested() const { return TRUE; }
00657     void resize( int nwidth );
00658     virtual void invalidate();
00660 
00661     virtual bool enter( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, bool atEnd = FALSE );
00662     virtual bool enterAt( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy, const QPoint &pos );
00663     virtual bool next( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00664     virtual bool prev( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00665     virtual bool down( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00666     virtual bool up( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *&parag, int &idx, int &ox, int &oy );
00667 
00668     QString richText() const;
00669 
00670     int minimumWidth() const { return layout ? layout->minimumSize().width() : 0; }
00671     int widthHint() const { return ( layout ? layout->sizeHint().width() : 0 ) + 2 * outerborder; }
00672 
00673     QPtrList<KoTextTableCell> tableCells() const { return cells; }
00674 
00675     QRect geometry() const { return layout ? layout->geometry() : QRect(); }
00676     bool isStretching() const { return stretch; }
00677 
00678 private:
00679     void format( int &w );
00680     void addCell( KoTextTableCell* cell );
00681 
00682 private:
00683     QGridLayout* layout;
00684     QPtrList<KoTextTableCell> cells;
00685     QPainter* painter;
00686     int cachewidth;
00687     int fixwidth;
00688     int cellpadding;
00689     int cellspacing;
00690     int border;
00691     int outerborder;
00692     int stretch;
00693     int innerborder;
00694     int us_cp, us_ib, us_b, us_ob, us_cs;
00695     QMap<QString, QString> attributes;
00696     QMap<KoTextCursor*, int> currCell;
00697     Placement place;
00698     void adjustCells( int y , int shift );
00699     int pageBreakFor;
00700 };
00701 #endif // QTEXTTABLE_AVAILABLE
00702 
00703 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00704 
00705 class KoTextTableCell;
00706 
00707 struct KoTextDocumentSelection
00708 {
00709     KoTextCursor startCursor, endCursor;
00710     bool swapped;
00711 };
00712 
00713 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00714 
00715 
00716 class KOTEXT_EXPORT KoTextDocDeleteCommand : public KoTextDocCommand
00717 {
00718 public:
00719     KoTextDocDeleteCommand( KoTextDocument *d, int i, int idx, const QMemArray<KoTextStringChar> &str );
00720     //KoTextDocDeleteCommand( KoTextParag *p, int idx, const QMemArray<KoTextStringChar> &str );
00721     virtual ~KoTextDocDeleteCommand();
00722 
00723     Commands type() const { return Delete; }
00724     KoTextCursor *execute( KoTextCursor *c );
00725     KoTextCursor *unexecute( KoTextCursor *c );
00726 
00727 protected:
00728     int id, index;
00729     KoTextParag *parag;
00730     QMemArray<KoTextStringChar> text;
00731 
00732 };
00733 
00734 #if 0
00735 class KoTextDocInsertCommand : public KoTextDocDeleteCommand
00736 {
00737 public:
00738     KoTextDocInsertCommand( KoTextDocument *d, int i, int idx, const QMemArray<KoTextStringChar> &str )
00739     : KoTextDocDeleteCommand( d, i, idx, str ) {}
00740     KoTextDocInsertCommand( KoTextParag *p, int idx, const QMemArray<KoTextStringChar> &str )
00741     : KoTextDocDeleteCommand( p, idx, str ) {}
00742     virtual ~KoTextDocInsertCommand() {}
00743 
00744     Commands type() const { return Insert; }
00745     KoTextCursor *execute( KoTextCursor *c ) { return KoTextDocDeleteCommand::unexecute( c ); }
00746     KoTextCursor *unexecute( KoTextCursor *c ) { return KoTextDocDeleteCommand::execute( c ); }
00747 
00748 };
00749 #endif
00750 
00751 class KoTextDocFormatCommand : public KoTextDocCommand
00752 {
00753 public:
00754     KoTextDocFormatCommand( KoTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<KoTextStringChar> &old, const KoTextFormat *f, int fl );
00755     virtual ~KoTextDocFormatCommand();
00756 
00757     Commands type() const { return Format; }
00758     KoTextCursor *execute( KoTextCursor *c );
00759     KoTextCursor *unexecute( KoTextCursor *c );
00760 
00761 protected:
00762     int startId, startIndex, endId, endIndex;
00763     KoTextFormat *format;
00764     QMemArray<KoTextStringChar> oldFormats;
00765     int flags;
00766 
00767 };
00768 
00769 class KoTextAlignmentCommand : public KoTextDocCommand
00770 {
00771 public:
00772     KoTextAlignmentCommand( KoTextDocument *d, int fParag, int lParag, int na, const QMemArray<int> &oa );
00773     virtual ~KoTextAlignmentCommand() {}
00774 
00775     Commands type() const { return Alignment; }
00776     KoTextCursor *execute( KoTextCursor *c );
00777     KoTextCursor *unexecute( KoTextCursor *c );
00778 
00779 private:
00780     int firstParag, lastParag;
00781     int newAlign;
00782     QMemArray<int> oldAligns;
00783 
00784 };
00785 
00786 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00787 
00788 struct KoTextParagLineStart
00789 {
00790     KoTextParagLineStart() : y( 0 ), baseLine( 0 ), h( 0 ), lineSpacing( 0 ), hyphenated( false )
00791 #ifndef QT_NO_COMPLEXTEXT
00792     , bidicontext( 0 )
00793 #endif
00794     {  }
00795     KoTextParagLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ),
00796                                                               lineSpacing( 0 ), hyphenated( false ),
00797     w( 0 )
00798 #ifndef QT_NO_COMPLEXTEXT
00799     , bidicontext( 0 )
00800 #endif
00801     {  }
00802 #ifndef QT_NO_COMPLEXTEXT
00803     KoTextParagLineStart( KoBidiContext *c, KoBidiStatus s ) : y(0), baseLine(0), h(0),
00804                                                                lineSpacing( 0 ), hyphenated( false ),
00805     status( s ), bidicontext( c ) { if ( bidicontext ) bidicontext->ref(); }
00806 #endif
00807 
00808     virtual ~KoTextParagLineStart()
00809     {
00810 #ifndef QT_NO_COMPLEXTEXT
00811     if ( bidicontext && bidicontext->deref() )
00812         delete bidicontext;
00813 #endif
00814     }
00815 
00816 #ifndef QT_NO_COMPLEXTEXT
00817     void setContext( KoBidiContext *c ) {
00818     if ( c == bidicontext )
00819         return;
00820     if ( bidicontext && bidicontext->deref() )
00821         delete bidicontext;
00822     bidicontext = c;
00823     if ( bidicontext )
00824         bidicontext->ref();
00825     }
00826     KoBidiContext *context() const { return bidicontext; }
00827 #endif
00828 
00829 public:
00830     ushort y, baseLine, h;
00831     short lineSpacing;
00832     bool hyphenated;
00833 #ifndef QT_NO_COMPLEXTEXT
00834     KoBidiStatus status;
00835 #endif
00836     int w;
00837 
00838 private:
00839 #ifndef QT_NO_COMPLEXTEXT
00840     KoBidiContext *bidicontext;
00841 #endif
00842 };
00843 
00844 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00845 
00846 class KOTEXT_EXPORT KoTextFormatterBase
00847 {
00848 public:
00849     KoTextFormatterBase();
00850     virtual ~KoTextFormatterBase() {}
00851     virtual bool format( KoTextDocument *doc, KoTextParag *parag, int start, const QMap<int, KoTextParagLineStart*> &oldLineStarts, int& y, int& widthUsed ) = 0;
00852     virtual int formatVertically( KoTextDocument* doc, KoTextParag* parag );
00853 
00854     // Called after formatting a paragraph
00855     virtual void postFormat( KoTextParag* parag ) = 0;
00856 
00857     int wrapAtColumn() const { return wrapColumn;}
00858     //virtual void setWrapEnabled( bool b ) { wrapEnabled = b; }
00859     virtual void setWrapAtColumn( int c ) { wrapColumn = c; }
00860     virtual void setAllowBreakInWords( bool b ) { biw = b; }
00861     bool allowBreakInWords() const { return biw; }
00862 
00863     // This setting is passed to KoTextParag::fixParagWidth by postFormat()
00864     void setViewFormattingChars( bool b ) { m_bViewFormattingChars = b; }
00865     bool viewFormattingChars() const { return m_bViewFormattingChars; }
00866 
00867     /*virtual*/ bool isBreakable( KoTextString *string, int pos ) const;
00868     /*virtual*/ bool isStretchable( KoTextString *string, int pos ) const;
00869 
00870 protected:
00871     //virtual KoTextParagLineStart *formatLine( KoTextParag *parag, KoTextString *string, KoTextParagLineStart *line, KoTextStringChar *start,
00872     //                         KoTextStringChar *last, int align = AlignAuto, int space = 0 );
00873     //KoTextStringChar
00874 
00875 #ifndef QT_NO_COMPLEXTEXT
00876     virtual KoTextParagLineStart *bidiReorderLine( KoTextParag *parag, KoTextString *string, KoTextParagLineStart *line, KoTextStringChar *start,
00877                             KoTextStringChar *last, int align, int space );
00878 #endif
00879 
00880 private:
00881     int wrapColumn;
00882     //bool wrapEnabled;
00883     bool m_bViewFormattingChars;
00884     bool biw;
00885     bool unused; // for future extensions
00886 
00887 #ifdef HAVE_THAI_BREAKS
00888     static QCString *thaiCache;
00889     static KoTextString *cachedString;
00890     static ThBreakIterator *thaiIt;
00891 #endif
00892 };
00893 
00894 
00895 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00896 
00897 inline int KoTextString::length() const
00898 {
00899     return data.size();
00900 }
00901 
00902 inline void KoTextString::operator+=( const QString &s )
00903 {
00904     insert( length(), s, 0 );
00905 }
00906 
00907 inline KoTextParag *KoTextCursor::parag() const
00908 {
00909     return string;
00910 }
00911 
00912 inline int KoTextCursor::index() const
00913 {
00914     return idx;
00915 }
00916 
00917 inline void KoTextCursor::setParag( KoTextParag *s, bool /*restore*/ )
00918 {
00919     idx = 0;
00920     string = s;
00921     tmpIndex = -1;
00922 }
00923 
00924 //inline void KoTextCursor::checkIndex()
00925 //{
00926 //    if ( idx >= string->length() )
00927 //  idx = string->length() - 1;
00928 //}
00929 
00930 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00931 
00932 inline KoTextStringChar &KoTextString::at( int i ) const
00933 {
00934     return data[ i ];
00935 }
00936 
00937 inline QString KoTextString::toString() const
00938 {
00939     return toString( data );
00940 }
00941 
00942 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00943 
00944 inline KoTextFormat *KoTextStringChar::format() const
00945 {
00946     return (type == Regular) ? d.format : d.custom->format;
00947 }
00948 
00949 inline KoTextCustomItem *KoTextStringChar::customItem() const
00950 {
00951     return isCustom() ? d.custom->custom : 0;
00952 }
00953 
00954 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:05 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003