20#ifndef KOTEXTDOCUMENT_H
21#define KOTEXTDOCUMENT_H
23#include "KoRichText.h"
24#include <koffice_export.h>
25#if defined(TQ_TEMPLATEDLL)
27template class TQ_EXPORT TQMap<int, TQColor>;
28template class TQ_EXPORT TQMap<int, bool>;
29template class TQ_EXPORT TQMap<int, KoTextDocumentSelection>;
30template class TQ_EXPORT TQPtrList<KoTextDocument>;
38class KoTextFormatCollection;
44class KOTEXT_EXPORT KoTextDocument :
public TQObject
49 friend class KoTextCursor;
50 friend class KoTextParag;
56 InputMethodPreedit = 1,
57 HighlightSelection = 2,
65 virtual ~KoTextDocument();
69 void setText(
const TQString &text,
const TQString &context );
81 void setWidth(
int w );
86 int leftMargin()
const;
87 void setLeftMargin(
int lm );
88 int rightMargin()
const;
89 void setRightMargin(
int rm );
91 KoTextParag *firstParag()
const;
92 KoTextParag *lastParag()
const;
93 void setFirstParag( KoTextParag *p );
94 void setLastParag( KoTextParag *p );
101 void setFormatter( KoTextFormatterBase *f );
102 KoTextFormatterBase *formatter()
const;
104 TQColor selectionColor(
int id )
const;
105 bool invertSelectionText(
int id )
const;
106 void setSelectionColor(
int id,
const TQColor &c );
107 void setInvertSelectionText(
int id,
bool b );
108 bool hasSelection(
int id,
bool visible =
false )
const;
109 bool isSelectionSwapped(
int id );
110 void setSelectionStart(
int id, KoTextCursor *cursor );
111 bool setSelectionEnd(
int id, KoTextCursor *cursor );
113 bool removeSelection(
int id );
114 void selectionStart(
int id,
int ¶gId,
int &index );
115 KoTextCursor selectionStartCursor(
int id );
116 KoTextCursor selectionEndCursor(
int id );
117 void selectionEnd(
int id,
int ¶gId,
int &index );
118 void setFormat(
int id,
const KoTextFormat *f,
int flags );
119 KoTextParag *selectionStart(
int id );
120 KoTextParag *selectionEnd(
int id );
121 int numSelections()
const {
return nSelections; }
122 void addSelection(
int id );
124 TQString selectedText(
int id,
bool withCustom =
true )
const;
126 void removeSelectedText(
int id, KoTextCursor *cursor );
128 KoTextParag *paragAt(
int i )
const;
130 void addCommand( KoTextDocCommand *cmd );
131 KoTextCursor *
undo( KoTextCursor *c = 0 );
132 KoTextCursor *
redo( KoTextCursor *c = 0 );
133 KoTextDocCommandHistory *commands()
const {
return commandHistory; }
135 KoTextFormatCollection *formatCollection()
const;
137 bool find(
const TQString &expr,
bool cs,
bool wo,
bool forward,
int *parag,
int *index, KoTextCursor *cursor );
142 bool inSelection(
int selId,
const TQPoint &pos )
const;
144 void setUnderlineLinks(
bool b ) { underlLinks = b; }
145 bool underlineLinks()
const {
return underlLinks; }
147 void setPaper( TQBrush *brush ) {
if ( backBrush )
delete backBrush; backBrush = brush; }
148 TQBrush *paper()
const {
return backBrush; }
152 void draw( TQPainter *p,
const TQRect& rect,
const TQColorGroup &cg,
const TQBrush *paper = 0 );
153 void drawParag( TQPainter *p, KoTextParag *parag,
int cx,
int cy,
int cw,
int ch,
154 TQPixmap *&doubleBuffer,
const TQColorGroup &cg,
155 bool drawCursor, KoTextCursor *cursor,
bool resetChanged =
true );
156 KoTextParag *draw( TQPainter *p,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup &cg,
157 bool onlyChanged =
false,
bool drawCursor =
false, KoTextCursor *cursor = 0,
158 bool resetChanged =
true );
165 const TQPtrList<KoTextCustomItem> & allCustomItems()
const {
return customItems; }
167 void setFlow( KoTextFlow *f );
169 KoTextFlow *flow()
const {
return flow_; }
170 bool isPageBreakEnabled()
const {
return m_pageBreakEnabled; }
171 void setPageBreakEnabled(
bool b ) { m_pageBreakEnabled = b; }
173 void setWithoutDoubleBuffer(
bool b ) { withoutDoubleBuffer = b; }
174 bool isWithoutDoubleBuffer()
const {
return withoutDoubleBuffer; }
176 void setUseFormatCollection(
bool b ) { useFC = b; }
177 bool useFormatCollection()
const {
return useFC; }
179#ifdef TQTEXTTABLE_AVAILABLE
180 KoTextTableCell *tableCell()
const {
return tc; }
181 void setTableCell( KoTextTableCell *c ) { tc = c; }
184 void setPlainText(
const TQString &text );
187 TQString plainText()
const;
191 int alignment()
const;
192 void setAlignment(
int a );
194 int *tabArray()
const;
195 int tabStopWidth()
const;
196 void setTabArray(
int *a );
197 void setTabStops(
int tw );
199 void setUndoDepth(
int d ) { commandHistory->setUndoDepth( d ); }
200 int undoDepth()
const {
return commandHistory->undoDepth(); }
203 void clear(
bool createEmptyParag =
false );
205 KoTextParag* loadList(
const TQDomElement& list,
KoOasisContext& context, KoTextParag* lastParagraph,
KoStyleCollection * styleColl, KoTextParag* nextParagraph );
208 KoTextParag* loadOasisText(
const TQDomElement &bodyElem,
KoOasisContext& context, KoTextParag* lastParagraph,
KoStyleCollection * styleColl, KoTextParag* nextParagraph );
214 virtual KoTextParag *createParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0,
bool updateIds =
true );
217 int addMargins()
const {
return true; }
219 void informParagraphDeleted( KoTextParag* parag );
225 void paragraphDeleted( KoTextParag* parag );
229 TQPixmap *bufferPixmap(
const TQSize &s );
249 bool createInitialParag =
true );
267 bool visitSelection(
int selectionId,
KoParagVisitor *visitor,
bool forward =
true );
271 bool visitDocument(
KoParagVisitor *visitor,
bool forward =
true );
275 bool visitFromTo( KoTextParag *firstParag,
int firstIndex, KoTextParag* lastParag,
int lastIndex,
KoParagVisitor* visitor,
bool forw =
true );
280 bool isDestroying()
const {
return m_bDestroying; }
286 DrawMisspelledLine = 1,
287 DrawFormattingChars = 2,
289 DontDrawNoteVariable = 8,
290 TransparentBackground = 16
294 KoTextParag *drawWYSIWYG( TQPainter *p,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup &cg,
296 bool drawCursor =
false, KoTextCursor *cursor = 0,
297 bool resetChanged =
true, uint drawingFlags = KoTextDocument::DrawSelections );
301 void drawParagWYSIWYG( TQPainter *p, KoTextParag *parag,
int cx,
int cy,
int cw,
int ch,
302 TQPixmap *&doubleBuffer,
const TQColorGroup &cg,
304 bool drawCursor, KoTextCursor *cursor,
305 bool resetChanged =
true,
306 uint drawingFlags = KoTextDocument::DrawSelections );
309 bool drawFormattingChars()
const {
return (m_drawingFlags & DrawFormattingChars); }
311 bool drawingMissingSpellLine()
const {
return (m_drawingFlags & DrawMisspelledLine); }
314 bool dontDrawingNoteVariable()
const {
return (m_drawingFlags & DontDrawNoteVariable); }
316 virtual KoTextDocCommand *deleteTextCommand( KoTextDocument *textdoc,
int id,
int index,
const TQMemArray<KoTextStringChar> & str,
const CustomItemsMap & customItemsMap,
const TQValueList<KoParagLayout> & oldParagLayouts );
318 void emitNewCommand(
KCommand *cmd) {
319 emit newCommand( cmd );
321 void emitRepaintChanged() {
322 emit repaintChanged();
335 void repaintChanged();
338 void drawWithoutDoubleBuffer( TQPainter *p,
const TQRect &rect,
const TQColorGroup &cg,
346 virtual bool loadOasisBodyTag(
const TQDomElement& ,
KoOasisContext& ,
360 KoTextParag* , uint ,
382 KoTextParag *fParag, *lParag;
384 TQMap<int, TQColor> selectionColors;
385 TQMap<int, KoTextDocumentSelection> selections;
386 TQMap<int, bool> selectionText;
387 KoTextDocCommandHistory *commandHistory;
388 KoTextFormatterBase *pFormatter;
389 KoTextFormatCollection *fCollection;
392 bool m_pageBreakEnabled : 1;
394 bool withoutDoubleBuffer : 1;
395 bool underlLinks : 1;
400 TQPtrList<KoTextCustomItem> customItems;
402 TQPixmap *buf_pixmap;
413inline int KoTextDocument::x()
const
418inline int KoTextDocument::y()
const
423inline int KoTextDocument::width()
const
425 return flow_->width();
434inline KoTextParag *KoTextDocument::firstParag()
const
439inline KoTextParag *KoTextDocument::lastParag()
const
444inline void KoTextDocument::setFirstParag( KoTextParag *p )
449inline void KoTextDocument::setLastParag( KoTextParag *p )
454inline void KoTextDocument::setWidth(
int w )
457 flow_->setWidth( w );
466inline void KoTextDocument::setY(
int y )
471inline int KoTextDocument::leftMargin()
const
476inline void KoTextDocument::setLeftMargin(
int lm )
481inline int KoTextDocument::rightMargin()
const
486inline void KoTextDocument::setRightMargin(
int rm )
501inline void KoTextDocument::setFormatter( KoTextFormatterBase *f )
507inline KoTextFormatterBase *KoTextDocument::formatter()
const
512inline TQColor KoTextDocument::selectionColor(
int id )
const
514 return selectionColors[ id ];
517inline bool KoTextDocument::invertSelectionText(
int id )
const
519 return selectionText[ id ];
522inline void KoTextDocument::setSelectionColor(
int id,
const TQColor &c )
524 selectionColors[ id ] = c;
527inline void KoTextDocument::setInvertSelectionText(
int id,
bool b )
529 selectionText[ id ] = b;
532inline KoTextFormatCollection *KoTextDocument::formatCollection()
const
537inline int KoTextDocument::alignment()
const
542inline void KoTextDocument::setAlignment(
int a )
547inline int *KoTextDocument::tabArray()
const
552inline int KoTextDocument::tabStopWidth()
const
557inline void KoTextDocument::setTabArray(
int *a )
562inline void KoTextDocument::setTabStops(
int tw )
574inline void KoTextDocument::setFlow( KoTextFlow *f )
581inline void KoTextDocument::takeFlow()
599 virtual bool visit( KoTextParag *parag,
int start,
int end ) = 0;
613 void insertItems(
const KoTextCursor & startCursor,
int size );
A CustomItemsMap associates a custom item to an index Used in the undo/redo info for insert/delete te...
Repository of styles used during saving of OASIS/OOo file.
Used during loading of Oasis format (and discarded at the end of the loading).
Base class for "visitors".
KoParagVisitor()
protected since this is an abstract base class
virtual bool visit(KoTextParag *parag, int start, int end)=0
Visit the paragraph parag, from index start to index end.
Used during saving to Oasis format (and discarded at the end of the saving).
TODO rename to KoParagStyleCollection - or should char styles be part of it too?
KoTextCustomItem is the base class for custom items (i.e.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
We implement our own text formatter to implement WYSIWYG: It is heavily based on KoTextFormatterBaseB...
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
A class for writing out XML (to any TQIODevice), with a special attention on performance.
TDEAction * selectAll(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * undo(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * redo(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * find(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)