00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KOTEXTDOCUMENT_H
00022 #define KOTEXTDOCUMENT_H
00023
00024 #include "KoRichText.h"
00025 #include <koffice_export.h>
00026
00027 #include <QPixmap>
00028 #include <Q3MemArray>
00029 #include <Q3PtrList>
00030 #include <Q3ValueList>
00031 #if defined(Q_TEMPLATEDLL)
00032 #ifndef Q_MOC_RUN
00033 template class Q_EXPORT QMap<int, QColor>;
00034 template class Q_EXPORT QMap<int, bool>;
00035 template class Q_EXPORT QMap<int, KoTextDocumentSelection>;
00036 template class Q_EXPORT Q3PtrList<KoTextDocument>;
00037 #endif
00038 #endif
00039
00040 class KoStyleCollection;
00041 class KoXmlWriter;
00042 class KoGenStyles;
00043 class KoTextZoomHandler;
00044 class KoTextFormatCollection;
00045 class KoParagVisitor;
00046 class KoTextFormatter;
00047 class KoTextParag;
00048 class CustomItemsMap;
00049
00050 class KOTEXT_EXPORT KoTextDocument : public QObject
00051 {
00052 Q_OBJECT
00053
00054 friend class KoTextCursor;
00055 friend class KoTextParag;
00056
00057 public:
00059 enum SelectionId {
00060 Standard = 0,
00061 InputMethodPreedit = 1,
00062 HighlightSelection = 2,
00063 Temp = 32000
00064
00065 };
00066
00067
00068
00069
00070 virtual ~KoTextDocument();
00071
00072
00073
00074 void setText( const QString &text, const QString &context );
00075
00076
00077
00078
00079
00080 int x() const;
00081 int y() const;
00082 int width() const;
00083
00084
00085 int height() const;
00086 void setWidth( int w );
00087
00088
00089
00090 void setY( int y );
00091 int leftMargin() const;
00092 void setLeftMargin( int lm );
00093 int rightMargin() const;
00094 void setRightMargin( int rm );
00095
00096 KoTextParag *firstParag() const;
00097 KoTextParag *lastParag() const;
00098 void setFirstParag( KoTextParag *p );
00099 void setLastParag( KoTextParag *p );
00100
00101 void invalidate();
00102
00103
00104
00105
00106 void setFormatter( KoTextFormatterBase *f );
00107 KoTextFormatterBase *formatter() const;
00108
00109 QColor selectionColor( int id ) const;
00110 bool invertSelectionText( int id ) const;
00111 void setSelectionColor( int id, const QColor &c );
00112 void setInvertSelectionText( int id, bool b );
00113 bool hasSelection( int id, bool visible = false ) const;
00114 bool isSelectionSwapped( int id );
00115 void setSelectionStart( int id, KoTextCursor *cursor );
00116 bool setSelectionEnd( int id, KoTextCursor *cursor );
00117 void selectAll( int id );
00118 bool removeSelection( int id );
00119 void selectionStart( int id, int ¶gId, int &index );
00120 KoTextCursor selectionStartCursor( int id );
00121 KoTextCursor selectionEndCursor( int id );
00122 void selectionEnd( int id, int ¶gId, int &index );
00123 void setFormat( int id, const KoTextFormat *f, int flags );
00124 KoTextParag *selectionStart( int id );
00125 KoTextParag *selectionEnd( int id );
00126 int numSelections() const { return nSelections; }
00127 void addSelection( int id );
00128
00129 QString selectedText( int id, bool withCustom = true ) const;
00130
00131 void removeSelectedText( int id, KoTextCursor *cursor );
00132
00133 KoTextParag *paragAt( int i ) const;
00134
00135 void addCommand( KoTextDocCommand *cmd );
00136 KoTextCursor *undo( KoTextCursor *c = 0 );
00137 KoTextCursor *redo( KoTextCursor *c = 0 );
00138 KoTextDocCommandHistory *commands() const { return commandHistory; }
00139
00140 KoTextFormatCollection *formatCollection() const;
00141
00142 bool find( const QString &expr, bool cs, bool wo, bool forward, int *parag, int *index, KoTextCursor *cursor );
00143
00144
00145
00146
00147 bool inSelection( int selId, const QPoint &pos ) const;
00148
00149 void setUnderlineLinks( bool b ) { underlLinks = b; }
00150 bool underlineLinks() const { return underlLinks; }
00151
00152 void setPaper( QBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; }
00153 QBrush *paper() const { return backBrush; }
00154
00155
00156 #if 0 // see KoTextDocument
00157 void draw( QPainter *p, const QRect& rect, const QColorGroup &cg, const QBrush *paper = 0 );
00158 void drawParag( QPainter *p, KoTextParag *parag, int cx, int cy, int cw, int ch,
00159 QPixmap *&doubleBuffer, const QColorGroup &cg,
00160 bool drawCursor, KoTextCursor *cursor, bool resetChanged = true );
00161 KoTextParag *draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg,
00162 bool onlyChanged = false, bool drawCursor = false, KoTextCursor *cursor = 0,
00163 bool resetChanged = true );
00164 #endif
00165
00166
00167
00168 void registerCustomItem( KoTextCustomItem *i, KoTextParag *p );
00169 void unregisterCustomItem( KoTextCustomItem *i, KoTextParag *p );
00170 const Q3PtrList<KoTextCustomItem> & allCustomItems() const { return customItems; }
00171
00172 void setFlow( KoTextFlow *f );
00173 void takeFlow();
00174 KoTextFlow *flow() const { return flow_; }
00175 bool isPageBreakEnabled() const { return m_pageBreakEnabled; }
00176 void setPageBreakEnabled( bool b ) { m_pageBreakEnabled = b; }
00177
00178 void setWithoutDoubleBuffer( bool b ) { withoutDoubleBuffer = b; }
00179 bool isWithoutDoubleBuffer() const { return withoutDoubleBuffer; }
00180
00181 void setUseFormatCollection( bool b ) { useFC = b; }
00182 bool useFormatCollection() const { return useFC; }
00183
00184 #ifdef QTEXTTABLE_AVAILABLE
00185 KoTextTableCell *tableCell() const { return tc; }
00186 void setTableCell( KoTextTableCell *c ) { tc = c; }
00187 #endif
00188
00189 void setPlainText( const QString &text );
00190
00191
00192 QString plainText() const;
00193
00194
00195
00196 int alignment() const;
00197 void setAlignment( int a );
00198
00199 int *tabArray() const;
00200 int tabStopWidth() const;
00201 void setTabArray( int *a );
00202 void setTabStops( int tw );
00203
00204 void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); }
00205 int undoDepth() const { return commandHistory->undoDepth(); }
00206
00207 int length() const;
00208 void clear( bool createEmptyParag = false );
00209
00210 KoTextParag* loadList( const QDomElement& list, KoOasisContext& context, KoTextParag* lastParagraph, KoStyleCollection * styleColl, KoTextParag* nextParagraph );
00211
00212
00213 KoTextParag* loadOasisText( const QDomElement &bodyElem, KoOasisContext& context, KoTextParag* lastParagraph, KoStyleCollection * styleColl, KoTextParag* nextParagraph );
00214
00215 QString copySelection( KoXmlWriter& writer, KoSavingContext& context, int selectionId );
00216
00217 void saveOasisContent( KoXmlWriter& writer, KoSavingContext& context ) const;
00218
00219 virtual KoTextParag *createParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0, bool updateIds = true );
00220
00221
00222 int addMargins() const { return true; }
00223
00224 void informParagraphDeleted( KoTextParag* parag );
00225
00226 signals:
00227
00228
00230 void paragraphDeleted( KoTextParag* parag );
00231
00232 private:
00233 void init();
00234 QPixmap *bufferPixmap( const QSize &s );
00235
00237
00238 public:
00252 KoTextDocument( KoTextZoomHandler *zoomHandler,
00253 KoTextFormatCollection *fc, KoTextFormatter *formatter = 0L,
00254 bool createInitialParag = true );
00255
00258 KoTextZoomHandler * formattingZoomHandler() const { return m_zoomHandler; }
00259
00267 KoTextZoomHandler * paintingZoomHandler() const { return m_zoomHandler; }
00268
00269
00272 bool visitSelection( int selectionId, KoParagVisitor *visitor, bool forward = true );
00273
00276 bool visitDocument( KoParagVisitor *visitor, bool forward = true );
00277
00280 bool visitFromTo( KoTextParag *firstParag, int firstIndex, KoTextParag* lastParag, int lastIndex, KoParagVisitor* visitor, bool forw = true );
00281
00285 bool isDestroying() const { return m_bDestroying; }
00286
00290 enum DrawingFlags {
00291 DrawMisspelledLine = 1,
00292 DrawFormattingChars = 2,
00293 DrawSelections = 4,
00294 DontDrawNoteVariable = 8,
00295 TransparentBackground = 16
00296 };
00299 KoTextParag *drawWYSIWYG( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg,
00300 KoTextZoomHandler* zoomHandler, bool onlyChanged = false,
00301 bool drawCursor = false, KoTextCursor *cursor = 0,
00302 bool resetChanged = true, uint drawingFlags = KoTextDocument::DrawSelections );
00303
00306 void drawParagWYSIWYG( QPainter *p, KoTextParag *parag, int cx, int cy, int cw, int ch,
00307 QPixmap *&doubleBuffer, const QColorGroup &cg,
00308 KoTextZoomHandler* zoomHandler,
00309 bool drawCursor, KoTextCursor *cursor,
00310 bool resetChanged = true,
00311 uint drawingFlags = KoTextDocument::DrawSelections );
00312
00314 bool drawFormattingChars() const { return (m_drawingFlags & DrawFormattingChars); }
00316 bool drawingMissingSpellLine() const { return (m_drawingFlags & DrawMisspelledLine); }
00317
00319 bool dontDrawingNoteVariable() const { return (m_drawingFlags & DontDrawNoteVariable); }
00320
00321 virtual KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc, int id, int index, const Q3MemArray<KoTextStringChar> & str, const CustomItemsMap & customItemsMap, const Q3ValueList<KoParagLayout> & oldParagLayouts );
00322
00323 void emitNewCommand(KCommand *cmd) {
00324 emit newCommand( cmd );
00325 }
00326 void emitRepaintChanged() {
00327 emit repaintChanged();
00328 }
00329 signals:
00335 void newCommand( KCommand *cmd );
00340 void repaintChanged();
00341
00342 protected:
00343 void drawWithoutDoubleBuffer( QPainter *p, const QRect &rect, const QColorGroup &cg,
00344 KoTextZoomHandler* zoomHandler, const QBrush *paper = 0 );
00345
00351 virtual bool loadOasisBodyTag( const QDomElement& , KoOasisContext& ,
00352 KoTextParag* & , KoStyleCollection* ,
00353 KoTextParag* ) {
00354 return false;
00355 }
00356
00364 virtual bool loadSpanTag( const QDomElement& , KoOasisContext& ,
00365 KoTextParag* , uint ,
00366 QString& , KoTextCustomItem* & ) {
00367 return false;
00368 }
00369
00370 private:
00371
00372
00373 KoTextZoomHandler * m_zoomHandler;
00374 bool m_bDestroying;
00375 uint m_drawingFlags;
00376
00378
00379 private:
00380
00381
00382
00383
00384
00385
00386 int cx, cy;
00387 KoTextParag *fParag, *lParag;
00388
00389 QMap<int, QColor> selectionColors;
00390 QMap<int, KoTextDocumentSelection> selections;
00391 QMap<int, bool> selectionText;
00392 KoTextDocCommandHistory *commandHistory;
00393 KoTextFormatterBase *pFormatter;
00394 KoTextFormatCollection *fCollection;
00395
00396
00397 bool m_pageBreakEnabled : 1;
00398 bool useFC : 1;
00399 bool withoutDoubleBuffer : 1;
00400 bool underlLinks : 1;
00401
00402 bool addMargs : 1;
00403 int nSelections;
00404 KoTextFlow *flow_;
00405 Q3PtrList<KoTextCustomItem> customItems;
00406 QBrush *backBrush;
00407 QPixmap *buf_pixmap;
00408
00409
00410 int leftmargin;
00411 int rightmargin;
00412
00413 int align;
00414 int *tArray;
00415 int tStopWidth;
00416 };
00417
00418 inline int KoTextDocument::x() const
00419 {
00420 return cx;
00421 }
00422
00423 inline int KoTextDocument::y() const
00424 {
00425 return cy;
00426 }
00427
00428 inline int KoTextDocument::width() const
00429 {
00430 return flow_->width();
00431
00432 }
00433
00434
00435
00436
00437
00438
00439 inline KoTextParag *KoTextDocument::firstParag() const
00440 {
00441 return fParag;
00442 }
00443
00444 inline KoTextParag *KoTextDocument::lastParag() const
00445 {
00446 return lParag;
00447 }
00448
00449 inline void KoTextDocument::setFirstParag( KoTextParag *p )
00450 {
00451 fParag = p;
00452 }
00453
00454 inline void KoTextDocument::setLastParag( KoTextParag *p )
00455 {
00456 lParag = p;
00457 }
00458
00459 inline void KoTextDocument::setWidth( int w )
00460 {
00461
00462 flow_->setWidth( w );
00463
00464 }
00465
00466
00467
00468
00469
00470
00471 inline void KoTextDocument::setY( int y )
00472 {
00473 cy = y;
00474 }
00475
00476 inline int KoTextDocument::leftMargin() const
00477 {
00478 return leftmargin;
00479 }
00480
00481 inline void KoTextDocument::setLeftMargin( int lm )
00482 {
00483 leftmargin = lm;
00484 }
00485
00486 inline int KoTextDocument::rightMargin() const
00487 {
00488 return rightmargin;
00489 }
00490
00491 inline void KoTextDocument::setRightMargin( int rm )
00492 {
00493 rightmargin = rm;
00494 }
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 inline void KoTextDocument::setFormatter( KoTextFormatterBase *f )
00507 {
00508 delete pFormatter;
00509 pFormatter = f;
00510 }
00511
00512 inline KoTextFormatterBase *KoTextDocument::formatter() const
00513 {
00514 return pFormatter;
00515 }
00516
00517 inline QColor KoTextDocument::selectionColor( int id ) const
00518 {
00519 return selectionColors[ id ];
00520 }
00521
00522 inline bool KoTextDocument::invertSelectionText( int id ) const
00523 {
00524 return selectionText[ id ];
00525 }
00526
00527 inline void KoTextDocument::setSelectionColor( int id, const QColor &c )
00528 {
00529 selectionColors[ id ] = c;
00530 }
00531
00532 inline void KoTextDocument::setInvertSelectionText( int id, bool b )
00533 {
00534 selectionText[ id ] = b;
00535 }
00536
00537 inline KoTextFormatCollection *KoTextDocument::formatCollection() const
00538 {
00539 return fCollection;
00540 }
00541
00542 inline int KoTextDocument::alignment() const
00543 {
00544 return align;
00545 }
00546
00547 inline void KoTextDocument::setAlignment( int a )
00548 {
00549 align = a;
00550 }
00551
00552 inline int *KoTextDocument::tabArray() const
00553 {
00554 return tArray;
00555 }
00556
00557 inline int KoTextDocument::tabStopWidth() const
00558 {
00559 return tStopWidth;
00560 }
00561
00562 inline void KoTextDocument::setTabArray( int *a )
00563 {
00564 tArray = a;
00565 }
00566
00567 inline void KoTextDocument::setTabStops( int tw )
00568 {
00569 tStopWidth = tw;
00570 }
00571
00572
00573
00574
00575
00576
00577
00578
00579 inline void KoTextDocument::setFlow( KoTextFlow *f )
00580 {
00581 if ( flow_ )
00582 delete flow_;
00583 flow_ = f;
00584 }
00585
00586 inline void KoTextDocument::takeFlow()
00587 {
00588 flow_ = 0L;
00589 }
00590
00596 class KoParagVisitor
00597 {
00598 protected:
00600 KoParagVisitor() {}
00601 virtual ~KoParagVisitor() {}
00602 public:
00604 virtual bool visit( KoTextParag *parag, int start, int end ) = 0;
00605 };
00606
00607 class KCommand;
00608 class QDomElement;
00609 class KMacroCommand;
00610
00613 class CustomItemsMap : public QMap<int, KoTextCustomItem *>
00614 {
00615 public:
00616
00618 void insertItems( const KoTextCursor & startCursor, int size );
00619
00621 void deleteAll( KMacroCommand *macroCmd );
00622 };
00623
00624 #endif