F:/KPlato/koffice/libs/kotext/KoRichText.h

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

Généré le Wed Nov 22 23:41:08 2006 pour KPlato par  doxygen 1.5.1-p1