lib

KoRichText.h

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