43#include <tqstringlist.h>
46#include <tqvaluelist.h>
48#include <tqstylesheet.h>
50#include "KoComplexText.h"
52#include <koffice_export.h>
62class KoTextFormatterBase;
64class KoTextFormatCollection;
73class KoTextDocCommand;
77#include <tqmemarray.h>
78#include "KoParagLayout.h"
83class KOTEXT_EXPORT KoTextStringChar
85 friend class KoTextString;
89 KoTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0; }
101 enum Type { Regular, Custom };
105 uint rightToLeft : 1;
109 short int pixelwidth;
116 bool isCustom()
const {
return type == Custom; }
119 void setFormat(
KoTextFormat *f,
bool setFormatAgain=
true );
121 void loseCustomItem();
134 KoTextStringChar &operator=(
const KoTextStringChar & ) {
138 KoTextStringChar(
const KoTextStringChar & );
139 friend class KoComplexText;
140 friend class KoTextParag;
143#if defined(TQ_TEMPLATEDLL)
145template class TQMemArray<KoTextStringChar>;
149class KOTEXT_EXPORT KoTextString
154 KoTextString(
const KoTextString &s );
155 virtual ~KoTextString();
157 TQString toString()
const;
158 static TQString toString(
const TQMemArray<KoTextStringChar> &data );
159 TQString toReverseString()
const;
161 TQString stringToSpellCheck();
163 KoTextStringChar &at(
int i )
const;
168 void insert(
int index,
const TQString &s,
KoTextFormat *f );
169 void insert(
int index, KoTextStringChar *c );
170 void truncate(
int index );
171 void remove(
int index,
int len );
174 void setFormat(
int index,
KoTextFormat *f,
bool useCollection,
bool setFormatAgain =
false );
176 void setBidi(
bool b ) { bidi = b; }
178 bool isRightToLeft()
const;
179 TQChar::Direction direction()
const;
180 void setDirection( TQChar::Direction d ) { dir = d; bidiDirty =
true; }
183 void setNeedsSpellCheck(
bool b ) { bNeedsSpellCheck = b; }
184 bool needsSpellCheck()
const {
return bNeedsSpellCheck; }
186 TQMemArray<KoTextStringChar> subString(
int start = 0,
int len = 0xFFFFFF )
const;
187 TQString mid(
int start = 0,
int len = 0xFFFFFF )
const;
188 TQMemArray<KoTextStringChar> rawData()
const {
return data.copy(); }
190 void operator=(
const TQString &s ) {
clear(); insert( 0, s, 0 ); }
191 void operator+=(
const TQString &s );
192 void prepend(
const TQString &s ) { insert( 0, s, 0 ); }
195 bool validCursorPosition(
int idx );
196 int nextCursorPosition(
int idx );
197 int previousCursorPosition(
int idx );
200 void checkBidi()
const;
202 TQMemArray<KoTextStringChar> data;
205 uint rightToLeft : 1;
207 uint bNeedsSpellCheck : 1;
210inline bool KoTextString::isBidi()
const
217inline bool KoTextString::isRightToLeft()
const
224inline TQChar::Direction KoTextString::direction()
const
226 return (TQChar::Direction) dir;
231class KOTEXT_EXPORT KoTextCursor
234 KoTextCursor( KoTextDocument *d );
236 KoTextCursor(
const KoTextCursor &c );
237 KoTextCursor &operator=(
const KoTextCursor &c );
238 virtual ~KoTextCursor() {}
240 bool operator==(
const KoTextCursor &c )
const;
241 bool operator!=(
const KoTextCursor &c )
const {
return !(*
this == c); }
243 KoTextDocument *document()
const {
return doc; }
244 void setDocument( KoTextDocument *d );
246 KoTextParag *parag()
const;
248 void setParag( KoTextParag *s,
bool restore =
true );
252 void gotoNextLetter();
253 void gotoPreviousLetter();
257 void gotoLineStart();
260 void gotoPageUp(
int visibleHeight );
261 void gotoPageDown(
int visibleHeight );
263 void gotoPreviousWord();
265 void gotoWordRight();
267 void insert(
const TQString &s,
bool checkNewLine, TQMemArray<KoTextStringChar> *formatting = 0 );
268 void splitAndInsertEmptyParag(
bool ind =
true,
bool updateIds =
true );
270 bool removePreviousChar();
274 bool atParagStart()
const;
275 bool atParagEnd()
const;
277 void setIndex(
int i,
bool restore =
true );
284 bool place(
const TQPoint &pos, KoTextParag *s,
bool link =
false,
int *customItemIndex = 0 );
288 void fixCursorPosition();
299class KoTextDocCommand
302 enum Commands {
Invalid, Insert, Delete, Format, Alignment, ParagType };
304 KoTextDocCommand( KoTextDocument *d ) : doc( d ), cursor( d ) {}
305 virtual ~KoTextDocCommand() {}
306 virtual Commands type()
const {
return Invalid; };
308 virtual KoTextCursor *execute( KoTextCursor *c ) = 0;
309 virtual KoTextCursor *unexecute( KoTextCursor *c ) = 0;
317#if defined(TQ_TEMPLATEDLL)
319template class TQPtrList<KoTextDocCommand>;
323class KoTextDocCommandHistory
326 KoTextDocCommandHistory(
int s ) : current( -1 ), steps( s ) { history.setAutoDelete(
true ); }
327 virtual ~KoTextDocCommandHistory() {
clear(); }
329 void clear() { history.clear(); current = -1; }
331 void addCommand( KoTextDocCommand *cmd );
332 KoTextCursor *
undo( KoTextCursor *c );
333 KoTextCursor *
redo( KoTextCursor *c );
335 bool isUndoAvailable();
336 bool isRedoAvailable();
338 void setUndoDepth(
int d ) { steps = d; }
339 int undoDepth()
const {
return steps; }
341 int historySize()
const {
return history.count(); }
342 int currentPosition()
const {
return current; }
345 TQPtrList<KoTextDocCommand> history;
352#include "KoTextCustomItem.h"
354#if defined(TQ_TEMPLATEDLL)
356template class TQMap<TQString, TQString>;
364 KoTextImage( KoTextDocument *p,
const TQMap<TQString, TQString> &attr,
const TQString& context,
365 TQMimeSourceFactory &factory );
366 virtual ~KoTextImage();
368 Placement placement()
const {
return place; }
370 int widthHint()
const {
return width; }
371 int minimumWidth()
const {
return width; }
373 TQString richText()
const;
375 void draw( TQPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected );
381 int tmpwidth, tmpheight;
382 TQMap<TQString, TQString> attributes;
391 KoTextHorizontalLine( KoTextDocument *p,
const TQMap<TQString, TQString> &attr,
const TQString& context,
392 TQMimeSourceFactory &factory );
393 virtual ~KoTextHorizontalLine();
396 void draw(TQPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected );
397 TQString richText()
const;
399 bool ownLine()
const {
return true; }
407#if defined(TQ_TEMPLATEDLL)
409template class TQPtrList<KoTextCustomItem>;
413class KOTEXT_EXPORT KoTextFlow
415 friend class KoTextDocument;
416 friend class KoTextTableCell;
420 virtual ~KoTextFlow();
423 virtual void setWidth(
int width );
426 int width()
const {
return w; }
438 virtual void adjustMargins(
int yp,
int h,
int reqMinWidth,
int& leftMargin,
int& rightMargin,
int& pageWidth, KoTextParag* parag );
445 virtual int availableHeight()
const;
446 virtual void drawFloatingItems(TQPainter* p,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected );
448 virtual int adjustFlow(
int y,
int w,
int h );
450 virtual bool isEmpty();
458 TQPtrList<KoTextCustomItem> leftItems;
459 TQPtrList<KoTextCustomItem> rightItems;
463#ifdef TQTEXTTABLE_AVAILABLE
466class KoTextTableCell :
public TQLayoutItem
468 friend class KoTextTable;
471 KoTextTableCell( KoTextTable* table,
473 const TQMap<TQString, TQString> &attr,
474 const TQStyleSheetItem* style,
476 TQMimeSourceFactory &factory, TQStyleSheet *sheet,
const TQString& doc );
477 KoTextTableCell( KoTextTable* table,
int row,
int column );
478 virtual ~KoTextTableCell();
480 TQSize sizeHint()
const ;
481 TQSize minimumSize()
const ;
482 TQSize maximumSize()
const ;
483 TQSizePolicy::ExpandData expanding()
const;
484 bool isEmpty()
const;
485 void setGeometry(
const TQRect& ) ;
486 TQRect geometry()
const;
488 bool hasHeightForWidth()
const;
489 int heightForWidth(
int )
const;
491 void setPainter( TQPainter*,
bool );
493 int row()
const {
return row_; }
494 int column()
const {
return col_; }
495 int rowspan()
const {
return rowspan_; }
496 int colspan()
const {
return colspan_; }
497 int stretch()
const {
return stretch_; }
499 KoTextDocument* richText()
const {
return richtext; }
500 KoTextTable* table()
const {
return parent; }
502 void draw(
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const TQColorGroup& cg,
bool selected );
504 TQBrush *backGround()
const {
return background; }
505 virtual void invalidate();
507 int verticalAlignmentOffset()
const;
508 int horizontalAlignmentOffset()
const;
511 TQPainter* painter()
const;
514 KoTextDocument* richtext;
526 TQMap<TQString, TQString> attributes;
530#if defined(TQ_TEMPLATEDLL)
532template class TQPtrList<KoTextTableCell>;
533template class TQMap<KoTextCursor*, int>;
539 friend class KoTextTableCell;
542 KoTextTable( KoTextDocument *p,
const TQMap<TQString, TQString> &attr );
543 virtual ~KoTextTable();
545 void setPainter( TQPainter *p,
bool adjust );
546 void pageBreak(
int y, KoTextFlow* flow );
547 void draw( TQPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
548 const TQColorGroup& cg,
bool selected );
550 bool noErase()
const {
return true; }
551 bool ownLine()
const {
return true; }
552 Placement placement()
const {
return place; }
553 bool isNested()
const {
return true; }
554 void resize(
int nwidth );
555 virtual void invalidate();
558 virtual bool enter( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
bool atEnd =
false );
559 virtual bool enterAt( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
const TQPoint &pos );
560 virtual bool next( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
561 virtual bool prev( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
562 virtual bool down( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
563 virtual bool up( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
565 TQString richText()
const;
567 int minimumWidth()
const {
return layout ? layout->minimumSize().width() : 0; }
568 int widthHint()
const {
return ( layout ? layout->sizeHint().width() : 0 ) + 2 * outerborder; }
570 TQPtrList<KoTextTableCell> tableCells()
const {
return cells; }
572 TQRect geometry()
const {
return layout ? layout->geometry() : TQRect(); }
573 bool isStretching()
const {
return stretch; }
576 void format(
int &w );
577 void addCell( KoTextTableCell* cell );
580 TQGridLayout* layout;
581 TQPtrList<KoTextTableCell> cells;
591 int us_cp, us_ib, us_b, us_ob, us_cs;
592 TQMap<TQString, TQString> attributes;
593 TQMap<KoTextCursor*, int> currCell;
595 void adjustCells(
int y ,
int shift );
602class KoTextTableCell;
604struct KoTextDocumentSelection
606 KoTextCursor startCursor, endCursor;
613class KOTEXT_EXPORT KoTextDocDeleteCommand :
public KoTextDocCommand
616 KoTextDocDeleteCommand( KoTextDocument *d,
int i,
int idx,
const TQMemArray<KoTextStringChar> &str );
618 virtual ~KoTextDocDeleteCommand();
620 Commands type()
const {
return Delete; }
621 KoTextCursor *execute( KoTextCursor *c );
622 KoTextCursor *unexecute( KoTextCursor *c );
627 TQMemArray<KoTextStringChar> text;
632class KoTextDocInsertCommand :
public KoTextDocDeleteCommand
635 KoTextDocInsertCommand( KoTextDocument *d,
int i,
int idx,
const TQMemArray<KoTextStringChar> &str )
636 : KoTextDocDeleteCommand( d, i, idx, str ) {}
637 KoTextDocInsertCommand( KoTextParag *p,
int idx,
const TQMemArray<KoTextStringChar> &str )
638 : KoTextDocDeleteCommand( p, idx, str ) {}
639 virtual ~KoTextDocInsertCommand() {}
641 Commands type()
const {
return Insert; }
642 KoTextCursor *execute( KoTextCursor *c ) {
return KoTextDocDeleteCommand::unexecute( c ); }
643 KoTextCursor *unexecute( KoTextCursor *c ) {
return KoTextDocDeleteCommand::execute( c ); }
648class KoTextDocFormatCommand :
public KoTextDocCommand
651 KoTextDocFormatCommand( KoTextDocument *d,
int sid,
int sidx,
int eid,
int eidx,
const TQMemArray<KoTextStringChar> &old,
const KoTextFormat *f,
int fl );
652 virtual ~KoTextDocFormatCommand();
654 Commands type()
const {
return Format; }
655 KoTextCursor *execute( KoTextCursor *c );
656 KoTextCursor *unexecute( KoTextCursor *c );
659 int startId, startIndex, endId, endIndex;
661 TQMemArray<KoTextStringChar> oldFormats;
666class KoTextAlignmentCommand :
public KoTextDocCommand
669 KoTextAlignmentCommand( KoTextDocument *d,
int fParag,
int lParag,
int na,
const TQMemArray<int> &oa );
670 virtual ~KoTextAlignmentCommand() {}
672 Commands type()
const {
return Alignment; }
673 KoTextCursor *execute( KoTextCursor *c );
674 KoTextCursor *unexecute( KoTextCursor *c );
677 int firstParag, lastParag;
679 TQMemArray<int> oldAligns;
685struct KoTextParagLineStart
687 KoTextParagLineStart() : y( 0 ), baseLine( 0 ), h( 0 ), lineSpacing( 0 ), hyphenated( false )
688#ifndef TQT_NO_COMPLEXTEXT
692 KoTextParagLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ),
693 lineSpacing( 0 ), hyphenated( false ),
695#ifndef TQT_NO_COMPLEXTEXT
699#ifndef TQT_NO_COMPLEXTEXT
700 KoTextParagLineStart( KoBidiContext *c, KoBidiStatus s ) : y(0), baseLine(0), h(0),
701 lineSpacing( 0 ), hyphenated( false ),
702 status( s ), bidicontext( c ) {
if ( bidicontext ) bidicontext->ref(); }
705 virtual ~KoTextParagLineStart()
707#ifndef TQT_NO_COMPLEXTEXT
708 if ( bidicontext && bidicontext->deref() )
713#ifndef TQT_NO_COMPLEXTEXT
714 void setContext( KoBidiContext *c ) {
715 if ( c == bidicontext )
717 if ( bidicontext && bidicontext->deref() )
723 KoBidiContext *context()
const {
return bidicontext; }
727 ushort y, baseLine, h;
730#ifndef TQT_NO_COMPLEXTEXT
736#ifndef TQT_NO_COMPLEXTEXT
737 KoBidiContext *bidicontext;
743class KOTEXT_EXPORT KoTextFormatterBase
746 KoTextFormatterBase();
747 virtual ~KoTextFormatterBase() {}
748 virtual bool format( KoTextDocument *doc, KoTextParag *parag,
int start,
const TQMap<int, KoTextParagLineStart*> &oldLineStarts,
int& y,
int& widthUsed ) = 0;
749 virtual int formatVertically( KoTextDocument* doc, KoTextParag* parag );
752 virtual void postFormat( KoTextParag* parag ) = 0;
754 int wrapAtColumn()
const {
return wrapColumn;}
756 virtual void setWrapAtColumn(
int c ) { wrapColumn = c; }
757 virtual void setAllowBreakInWords(
bool b ) { biw = b; }
758 bool allowBreakInWords()
const {
return biw; }
761 void setViewFormattingChars(
bool b ) { m_bViewFormattingChars = b; }
762 bool viewFormattingChars()
const {
return m_bViewFormattingChars; }
764 bool isBreakable( KoTextString *
string,
int pos )
const;
765 bool isStretchable( KoTextString *
string,
int pos )
const;
772#ifndef TQT_NO_COMPLEXTEXT
773 virtual KoTextParagLineStart *bidiReorderLine( KoTextParag *parag, KoTextString *
string, KoTextParagLineStart *line, KoTextStringChar *start,
774 KoTextStringChar *last,
int align,
int space );
780 bool m_bViewFormattingChars;
784#ifdef HAVE_THAI_BREAKS
785 static TQCString *thaiCache;
786 static KoTextString *cachedString;
787 static ThBreakIterator *thaiIt;
794inline int KoTextString::length()
const
799inline void KoTextString::operator+=(
const TQString &s )
801 insert( length(), s, 0 );
804inline KoTextParag *KoTextCursor::parag()
const
809inline int KoTextCursor::index()
const
814inline void KoTextCursor::setParag( KoTextParag *s,
bool )
829inline KoTextStringChar &KoTextString::at(
int i )
const
834inline TQString KoTextString::toString()
const
836 return toString( data );
843 return (type == Regular) ? d.format : d.custom->format;
848 return isCustom() ? d.custom->custom : 0;
Repository of styles used during saving of OASIS/OOo file.
Base class for "visitors".
Used during saving to Oasis format (and discarded at the end of the saving).
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 * next(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 * up(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)
@ Invalid
invalid property type