00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
#ifndef QRICHTEXT_P_H
00045
#define QRICHTEXT_P_H
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
#ifndef QT_H
00060
#include "qstring.h"
00061
#include "qptrlist.h"
00062
#include "qrect.h"
00063
#include "qfontmetrics.h"
00064
#include "qintdict.h"
00065
#include "qmap.h"
00066
#include "qstringlist.h"
00067
#include "qfont.h"
00068
#include "qcolor.h"
00069
#include "qsize.h"
00070
#include "qvaluelist.h"
00071
#include "qvaluestack.h"
00072
#include "qobject.h"
00073
#include "qdict.h"
00074
#include "qtextstream.h"
00075
#include "qpixmap.h"
00076
#include "qstylesheet.h"
00077
#include "qptrvector.h"
00078
#include "qpainter.h"
00079
#include "qlayout.h"
00080
#include "qobject.h"
00081
#include <limits.h>
00082
#include "qcomplextext_p.h"
00083
#include "qapplication.h"
00084
#endif // QT_H
00085
00086
#include <qglobal.h>
00087
#if QT_VERSION >= 0x030200
00088
#define INDIC
00089
#endif
00090
00091
class KoTextParag;
00092
class KoTextString;
00093
class KoTextCursor;
00094
class KoTextCustomItem;
00095
class KoTextFlow;
00096
class KoTextDocument;
00097
00098
class KoTextFormatterBase;
00099
class KoTextIndent;
00100
class KoTextFormat;
00101
class KoTextFormatCollection;
00102
struct KoBidiContext;
00103
00105
class KCommand;
00106
class QDomElement;
00107
class KoZoomHandler;
00108
class KoTextFormatter;
00109
class KoParagVisitor;
00110
class KoTextDocCommand;
00111
#include <qmemarray.h>
00112
#include "koparaglayout.h"
00113
#include "korichtext.h"
00115
00116
00117
00118
class KoTextStringChar
00119 {
00120
friend class KoTextString;
00121
00122
public:
00123
00124 KoTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0; }
00125 ~KoTextStringChar();
00126
00127
QChar c;
00128
#ifdef INDIC
00129
00130
00131 uchar softBreak :1;
00132 uchar whiteSpace :1;
00133 uchar charStop :1;
00134 uchar wordStop :1;
00135
00136
00137
#endif
00138
enum Type { Regular, Custom };
00139 uint lineStart : 1;
00140
#ifndef INDIC
00141
uint rightToLeft : 1;
00142
00143
00144 Type type : 2;
00145
#else
00146
Type type : 1;
00147
#endif
00148
uint startOfRun : 1;
00149
#ifdef INDIC
00150
uint rightToLeft : 1;
00151
#endif
00152
00153
00154 Q_INT8 pixelxadj;
00155
short int pixelwidth;
00156
short int width;
00157
00158
int x;
00159
int height() const;
00160
int ascent() const;
00161
int descent() const;
00162
bool isCustom()
const {
return type == Custom; }
00163
KoTextFormat *format() const;
00164 KoTextCustomItem *customItem() const;
00165
void setFormat(
KoTextFormat *f );
00166
void setCustomItem( KoTextCustomItem *i );
00167
void loseCustomItem();
00168 #ifndef INDIC
00169 KoTextStringChar *clone() const;
00170 #endif
00171 struct CustomData
00172 {
00173
KoTextFormat *format;
00174 KoTextCustomItem *custom;
00175 };
00176
00177
union {
00178
KoTextFormat* format;
00179 CustomData* custom;
00180 } d;
00181
00182
private:
00183 KoTextStringChar &operator=(
const KoTextStringChar & ) {
00184
00185
return *
this;
00186 }
00187 KoTextStringChar(
const KoTextStringChar & );
00188
friend class KoComplexText;
00189
friend class KoTextParag;
00190 };
00191
00192
#if defined(Q_TEMPLATEDLL)
00193
00194
template class QMemArray<KoTextStringChar>;
00195
00196
#endif
00197
00198
class KoTextString
00199 {
00200
public:
00201
00202 KoTextString();
00203 KoTextString(
const KoTextString &s );
00204
virtual ~KoTextString();
00205
00206
QString toString() const;
00207 static
QString toString( const
QMemArray<KoTextStringChar> &data );
00208
QString toReverseString() const;
00209
00210 KoTextStringChar &at(
int i ) const;
00211
int length() const;
00212
00213 #ifndef INDIC
00214
00215 #else
00216
00217 #endif
00218
00219
void insert(
int index, const
QString &s,
KoTextFormat *f );
00220
void insert(
int index, KoTextStringChar *c );
00221
void truncate(
int index );
00222
void remove(
int index,
int len );
00223
void clear();
00224
00225
void setFormat(
int index,
KoTextFormat *f,
bool useCollection );
00226
00227
void setBidi(
bool b ) { bidi = b; }
00228
bool isBidi() const;
00229
bool isRightToLeft() const;
00230
QChar::Direction direction() const;
00231
void setDirection(
QChar::Direction d ) { dir = d; bidiDirty = TRUE; }
00232
00234
void setNeedsSpellCheck(
bool b ) { bNeedsSpellCheck = b; }
00235
bool needsSpellCheck()
const {
return bNeedsSpellCheck; }
00236
00237
QMemArray<KoTextStringChar> subString(
int start = 0,
int len = 0xFFFFFF )
const;
00238
QString mid(
int start = 0,
int len = 0xFFFFFF )
const;
00239
QMemArray<KoTextStringChar> rawData()
const {
return data.copy(); }
00240
00241
void operator=(
const QString &s ) { clear(); insert( 0, s, 0 ); }
00242
void operator+=(
const QString &s );
00243
void prepend(
const QString &s ) { insert( 0, s, 0 ); }
00244
00245
#ifdef INDIC
00246
00247
bool validCursorPosition(
int idx );
00248
int nextCursorPosition(
int idx );
00249
int previousCursorPosition(
int idx );
00250
00251
#endif
00252
private:
00253
void checkBidi() const;
00254
00255
QMemArray<KoTextStringChar> data;
00256 uint bidiDirty : 1;
00257 uint bidi : 1;
00258 uint rightToLeft : 1;
00259 uint dir : 5;
00260 uint bNeedsSpellCheck : 1;
00261 };
00262
00263 inline
bool KoTextString::isBidi()
const
00264
{
00265
if ( bidiDirty )
00266 checkBidi();
00267
return bidi;
00268 }
00269
00270
inline bool KoTextString::isRightToLeft()
const
00271
{
00272
if ( bidiDirty )
00273 checkBidi();
00274
return rightToLeft;
00275 }
00276
00277
inline QChar::Direction KoTextString::direction()
const
00278
{
00279
return (QChar::Direction) dir;
00280 }
00281
00282
00283
00284
#if defined(Q_TEMPLATEDLL)
00285
00286
template class QValueStack<int>;
00287
template class QValueStack<KoTextParag*>;
00288
template class QValueStack<bool>;
00289
00290
#endif
00291
00292
class KoTextCursor
00293 {
00294
public:
00295 KoTextCursor( KoTextDocument *d );
00296 KoTextCursor();
00297 KoTextCursor(
const KoTextCursor &c );
00298 KoTextCursor &operator=(
const KoTextCursor &c );
00299
virtual ~KoTextCursor() {}
00300
00301
bool operator==(
const KoTextCursor &c )
const;
00302
bool operator!=(
const KoTextCursor &c )
const {
return !(*
this == c); }
00303
00304 KoTextDocument *document()
const {
return doc; }
00305
void setDocument( KoTextDocument *d );
00306
00307 KoTextParag *parag() const;
00308
int index() const;
00309
void setParag( KoTextParag *s,
bool restore = TRUE );
00310
00311
void gotoLeft();
00312
void gotoRight();
00313
void gotoNextLetter();
00314
void gotoPreviousLetter();
00315
void gotoUp();
00316
void gotoDown();
00317
void gotoLineEnd();
00318
void gotoLineStart();
00319
void gotoHome();
00320
void gotoEnd();
00321
void gotoPageUp(
int visibleHeight );
00322
void gotoPageDown(
int visibleHeight );
00323
void gotoNextWord();
00324
void gotoPreviousWord();
00325
void gotoWordLeft();
00326
void gotoWordRight();
00327
00328
void insert( const
QString &s,
bool checkNewLine,
QMemArray<KoTextStringChar> *formatting = 0 );
00329
void splitAndInsertEmptyParag(
bool ind = TRUE,
bool updateIds = TRUE );
00330
bool remove();
00331 #ifdef INDIC
00332
bool removePreviousChar();
00333 #endif
00334
void killLine();
00335
void indent();
00336
00337
bool atParagStart() const;
00338
bool atParagEnd() const;
00339
00340
void setIndex(
int i,
bool restore = TRUE );
00341
00342
void checkIndex();
00343
00344
int offsetX()
const {
return ox; }
00345
int offsetY()
const {
return oy; }
00346
00347 KoTextParag *topParag()
const {
return parags.isEmpty() ? string : parags.first(); }
00348
int totalOffsetX() const;
00349
int totalOffsetY() const;
00350
00351
bool place( const
QPoint &pos, KoTextParag *s,
bool link = false,
int *customItemIndex = 0 );
00352
void restoreState();
00353
00354
int x() const;
00355
int y() const;
00356 #ifndef INDIC
00357
00358 #else
00359
void fixCursorPosition();
00360 #endif
00361
int nestedDepth()
const {
return (
int)indices.count(); }
00362
00363
private:
00364
enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
00365
00366
void push();
00367
void pop();
00368
void processNesting( Operation op );
00369
void invalidateNested();
00370
void gotoIntoNested(
const QPoint &globalPos );
00371
00372 KoTextParag *string;
00373 KoTextDocument *doc;
00374
int idx, tmpIndex;
00375
int ox, oy;
00376
QValueStack<int> indices;
00377
QValueStack<KoTextParag*> parags;
00378
QValueStack<int> xOffsets;
00379
QValueStack<int> yOffsets;
00380
QValueStack<bool> nestedStack;
00381
bool nested;
00382
00383 };
00384
00385
00386
00387
class KoTextDocCommand
00388 {
00389
public:
00390
enum Commands { Invalid, Insert, Delete, Format, Alignment, ParagType };
00391
00392 KoTextDocCommand( KoTextDocument *d ) : doc( d ), cursor( d ) {}
00393
virtual ~KoTextDocCommand() {}
00394
virtual Commands type()
const {
return Invalid; };
00395
00396
virtual KoTextCursor *execute( KoTextCursor *c ) = 0;
00397
virtual KoTextCursor *unexecute( KoTextCursor *c ) = 0;
00398
00399
protected:
00400 KoTextDocument *doc;
00401 KoTextCursor cursor;
00402
00403 };
00404
00405
#if defined(Q_TEMPLATEDLL)
00406
00407
template class QPtrList<KoTextDocCommand>;
00408
00409
#endif
00410
00411
class KoTextDocCommandHistory
00412 {
00413
public:
00414 KoTextDocCommandHistory(
int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); }
00415
virtual ~KoTextDocCommandHistory() { clear(); }
00416
00417
void clear() { history.clear(); current = -1; }
00418
00419
void addCommand( KoTextDocCommand *cmd );
00420 KoTextCursor *undo( KoTextCursor *c );
00421 KoTextCursor *redo( KoTextCursor *c );
00422
00423
bool isUndoAvailable();
00424
bool isRedoAvailable();
00425
00426
void setUndoDepth(
int d ) { steps = d; }
00427
int undoDepth()
const {
return steps; }
00428
00429
int historySize()
const {
return history.count(); }
00430
int currentPosition()
const {
return current; }
00431
00432
private:
00433
QPtrList<KoTextDocCommand> history;
00434
int current, steps;
00435
00436 };
00437
00438
00439
00440
class KoTextCustomItem
00441 {
00442
public:
00443 KoTextCustomItem( KoTextDocument *p );
00444
virtual ~KoTextCustomItem();
00445
virtual void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const QColorGroup& cg,
bool selected ) ;
00446
00447
00448
virtual void finalize() {}
00449
00450
void move(
int x,
int y ) { xpos = x; ypos = y; }
00451
int x()
const {
return xpos; }
00452
int y()
const {
return ypos; }
00453
00454
00455
virtual void setFormat(
KoTextFormat * ) { }
00456
00457
00458
00459
enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
00460
virtual Placement placement()
const {
return PlaceInline; }
00461
bool placeInline() {
return placement() == PlaceInline; }
00462
00463
virtual bool ownLine()
const {
return FALSE; }
00464
00465
virtual void resize(
int nwidth ) { width = nwidth; }
00466
virtual void invalidate() {};
00467
00468
virtual bool isNested()
const {
return FALSE; }
00469
virtual int minimumWidth()
const {
return 0; }
00470
virtual int widthHint()
const {
return 0; }
00471
virtual int ascent()
const {
return height; }
00472
00473
virtual QString richText()
const {
return QString::null; }
00474
00475
int width;
00476
int height;
00477
00478
QRect geometry()
const {
return QRect( xpos, ypos, width, height ); }
00479
00480
virtual bool enter( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
bool atEnd = FALSE );
00481
virtual bool enterAt( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
const QPoint & );
00482
virtual bool next( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00483
virtual bool prev( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00484
virtual bool down( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00485
virtual bool up( KoTextCursor *, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00486
00487
void setParagraph( KoTextParag * p ) { parag = p; }
00488 KoTextParag *paragraph()
const {
return parag; }
00489
00490
virtual void pageBreak(
int , KoTextFlow* ) {}
00491
00492 KoTextDocument *parent;
00493
00494
#include "kotextcustomitem.h"
00495
00496
protected:
00497
int xpos;
00498
int ypos;
00499
private:
00500 KoTextParag *parag;
00501 };
00502
00503
#if defined(Q_TEMPLATEDLL)
00504
00505
template class QMap<QString, QString>;
00506
00507
#endif
00508
00509
#if 0
00510
class KoTextImage :
public KoTextCustomItem
00511 {
00512
public:
00513 KoTextImage( KoTextDocument *p,
const QMap<QString, QString> &attr,
const QString& context,
00514
QMimeSourceFactory &factory );
00515
virtual ~KoTextImage();
00516
00517 Placement placement()
const {
return place; }
00518
00519
int widthHint()
const {
return width; }
00520
int minimumWidth()
const {
return width; }
00521
00522
QString richText() const;
00523
00524
void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch, const
QColorGroup& cg,
bool selected );
00525
00526 private:
00527
QRegion* reg;
00528
QPixmap pm;
00529 Placement place;
00530
int tmpwidth, tmpheight;
00531
QMap<
QString, QString> attributes;
00532 QString imgId;
00533
00534 };
00535 #endif
00536
00537 class KoTextHorizontalLine : public KoTextCustomItem
00538 {
00539
public:
00540 KoTextHorizontalLine( KoTextDocument *p,
const QMap<QString, QString> &attr,
const QString& context,
00541
QMimeSourceFactory &factory );
00542
virtual ~KoTextHorizontalLine();
00543
00544
00545
void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const QColorGroup& cg,
bool selected );
00546 QString richText() const;
00547
00548
bool ownLine()
const {
return TRUE; }
00549
00550
private:
00551
int tmpheight;
00552
QColor color;
00553
00554 };
00555
00556
#if defined(Q_TEMPLATEDLL)
00557
00558
template class QPtrList<KoTextCustomItem>;
00559
00560
#endif
00561
00562
class KoTextFlow
00563 {
00564
friend class KoTextDocument;
00565
friend class KoTextTableCell;
00566
00567
public:
00568 KoTextFlow();
00569
virtual ~KoTextFlow();
00570
00571
virtual void setWidth(
int width );
00572
int width()
const {
return w; }
00573
00574
00575
00576
00584
virtual void adjustMargins(
int yp,
int h,
int reqMinWidth,
int& leftMargin,
int& rightMargin,
int& pageWidth, KoTextParag* parag );
00585
00586
virtual void registerFloatingItem( KoTextCustomItem* item );
00587
virtual void unregisterFloatingItem( KoTextCustomItem* item );
00588
00589
00591
virtual int availableHeight() const;
00592 virtual
void drawFloatingItems(
QPainter* p,
int cx,
int cy,
int cw,
int ch, const
QColorGroup& cg,
bool selected );
00593
00594 virtual
int adjustFlow(
int y,
int w,
int h );
00595
00596 virtual
bool isEmpty();
00597
00598
void clear();
00599
00600 private:
00601
int w;
00602
00603
00604
QPtrList<KoTextCustomItem> leftItems;
00605
QPtrList<KoTextCustomItem> rightItems;
00606
00607 };
00608
00609 #ifdef QTEXTTABLE_AVAILABLE
00610 class KoTextTable;
00611
00612 class KoTextTableCell : public
QLayoutItem
00613 {
00614
friend class KoTextTable;
00615
00616
public:
00617 KoTextTableCell( KoTextTable* table,
00618
int row,
int column,
00619
const QMap<QString, QString> &attr,
00620
const QStyleSheetItem* style,
00621
const KoTextFormat& fmt,
const QString& context,
00622
QMimeSourceFactory &factory,
QStyleSheet *sheet,
const QString& doc );
00623 KoTextTableCell( KoTextTable* table,
int row,
int column );
00624
virtual ~KoTextTableCell();
00625
00626
QSize sizeHint() const ;
00627
QSize minimumSize() const ;
00628
QSize maximumSize() const ;
00629
QSizePolicy::ExpandData expanding() const;
00630
bool isEmpty() const;
00631
void setGeometry( const
QRect& ) ;
00632 QRect geometry() const;
00633
00634
bool hasHeightForWidth() const;
00635
int heightForWidth(
int ) const;
00636
00637
void setPainter(
QPainter*,
bool );
00638
00639
int row()
const {
return row_; }
00640
int column()
const {
return col_; }
00641
int rowspan()
const {
return rowspan_; }
00642
int colspan()
const {
return colspan_; }
00643
int stretch()
const {
return stretch_; }
00644
00645 KoTextDocument* richText() const {
return richtext; }
00646 KoTextTable* table()
const {
return parent; }
00647
00648
void draw(
int x,
int y,
int cx,
int cy,
int cw,
int ch,
const QColorGroup& cg,
bool selected );
00649
00650
QBrush *backGround()
const {
return background; }
00651
virtual void invalidate();
00652
00653
int verticalAlignmentOffset() const;
00654
int horizontalAlignmentOffset() const;
00655
00656 private:
00657
QPainter* painter() const;
00658
QRect geom;
00659 KoTextTable* parent;
00660 KoTextDocument* richtext;
00661
int row_;
00662
int col_;
00663
int rowspan_;
00664
int colspan_;
00665
int stretch_;
00666
int maxw;
00667
int minw;
00668
bool hasFixedWidth;
00669
QBrush *background;
00670
int cached_width;
00671
int cached_sizehint;
00672
QMap<
QString, QString> attributes;
00673
int align;
00674 };
00675
00676 #if defined(Q_TEMPLATEDLL)
00677
00678 template class
QPtrList<KoTextTableCell>;
00679 template class
QMap<KoTextCursor*,
int>;
00680
00681 #endif
00682
00683 class KoTextTable: public KoTextCustomItem
00684 {
00685
friend class KoTextTableCell;
00686
00687
public:
00688 KoTextTable( KoTextDocument *p,
const QMap<QString, QString> &attr );
00689
virtual ~KoTextTable();
00690
00691
void setPainter(
QPainter *p,
bool adjust );
00692
void pageBreak(
int y, KoTextFlow* flow );
00693
void draw(
QPainter* p,
int x,
int y,
int cx,
int cy,
int cw,
int ch,
00694
const QColorGroup& cg,
bool selected );
00695
00696
bool noErase()
const {
return TRUE; }
00697
bool ownLine()
const {
return TRUE; }
00698 Placement placement()
const {
return place; }
00699
bool isNested()
const {
return TRUE; }
00700
void resize(
int nwidth );
00701
virtual void invalidate();
00703
00704
virtual bool enter( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
bool atEnd = FALSE );
00705
virtual bool enterAt( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy,
const QPoint &pos );
00706
virtual bool next( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00707
virtual bool prev( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00708
virtual bool down( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00709
virtual bool up( KoTextCursor *c, KoTextDocument *&doc, KoTextParag *¶g,
int &idx,
int &ox,
int &oy );
00710
00711 QString richText() const;
00712
00713
int minimumWidth()
const {
return layout ? layout->minimumSize().width() : 0; }
00714
int widthHint()
const {
return ( layout ? layout->sizeHint().width() : 0 ) + 2 * outerborder; }
00715
00716
QPtrList<KoTextTableCell> tableCells()
const {
return cells; }
00717
00718
QRect geometry()
const {
return layout ? layout->geometry() :
QRect(); }
00719
bool isStretching()
const {
return stretch; }
00720
00721
private:
00722
void format(
int &w );
00723
void addCell( KoTextTableCell* cell );
00724
00725
private:
00726
QGridLayout* layout;
00727
QPtrList<KoTextTableCell> cells;
00728
QPainter* painter;
00729
int cachewidth;
00730
int fixwidth;
00731
int cellpadding;
00732
int cellspacing;
00733
int border;
00734
int outerborder;
00735
int stretch;
00736
int innerborder;
00737
int us_cp, us_ib, us_b, us_ob, us_cs;
00738
QMap<QString, QString> attributes;
00739
QMap<KoTextCursor*, int> currCell;
00740 Placement place;
00741
void adjustCells(
int y ,
int shift );
00742
int pageBreakFor;
00743 };
00744
#endif // QTEXTTABLE_AVAILABLE
00745
00746
00747
00748
class KoTextTableCell;
00749
00750
struct KoTextDocumentSelection
00751 {
00752 KoTextCursor startCursor, endCursor;
00753
bool swapped;
00754 };
00755
00756
00757
00758
00759
class KoTextDocDeleteCommand :
public KoTextDocCommand
00760 {
00761
public:
00762 KoTextDocDeleteCommand( KoTextDocument *d,
int i,
int idx,
const QMemArray<KoTextStringChar> &str );
00763
00764
virtual ~KoTextDocDeleteCommand();
00765
00766 Commands type()
const {
return Delete; }
00767 KoTextCursor *execute( KoTextCursor *c );
00768 KoTextCursor *unexecute( KoTextCursor *c );
00769
00770
protected:
00771
int id, index;
00772 KoTextParag *parag;
00773
QMemArray<KoTextStringChar> text;
00774
00775 };
00776
00777
#if 0
00778
class KoTextDocInsertCommand :
public KoTextDocDeleteCommand
00779 {
00780
public:
00781 KoTextDocInsertCommand( KoTextDocument *d,
int i,
int idx,
const QMemArray<KoTextStringChar> &str )
00782 : KoTextDocDeleteCommand( d, i, idx, str ) {}
00783 KoTextDocInsertCommand( KoTextParag *p,
int idx,
const QMemArray<KoTextStringChar> &str )
00784 : KoTextDocDeleteCommand( p, idx, str ) {}
00785
virtual ~KoTextDocInsertCommand() {}
00786
00787 Commands type()
const {
return Insert; }
00788 KoTextCursor *execute( KoTextCursor *c ) {
return KoTextDocDeleteCommand::unexecute( c ); }
00789 KoTextCursor *unexecute( KoTextCursor *c ) {
return KoTextDocDeleteCommand::execute( c ); }
00790
00791 };
00792
#endif
00793
00794
class KoTextDocFormatCommand :
public KoTextDocCommand
00795 {
00796
public:
00797 KoTextDocFormatCommand( KoTextDocument *d,
int sid,
int sidx,
int eid,
int eidx,
const QMemArray<KoTextStringChar> &old,
const KoTextFormat *f,
int fl );
00798
virtual ~KoTextDocFormatCommand();
00799
00800 Commands type()
const {
return Format; }
00801 KoTextCursor *execute( KoTextCursor *c );
00802 KoTextCursor *unexecute( KoTextCursor *c );
00803
00804
protected:
00805
int startId, startIndex, endId, endIndex;
00806
KoTextFormat *format;
00807
QMemArray<KoTextStringChar> oldFormats;
00808
int flags;
00809
00810 };
00811
00812
class KoTextAlignmentCommand :
public KoTextDocCommand
00813 {
00814
public:
00815 KoTextAlignmentCommand( KoTextDocument *d,
int fParag,
int lParag,
int na,
const QMemArray<int> &oa );
00816
virtual ~KoTextAlignmentCommand() {}
00817
00818 Commands type()
const {
return Alignment; }
00819 KoTextCursor *execute( KoTextCursor *c );
00820 KoTextCursor *unexecute( KoTextCursor *c );
00821
00822
private:
00823
int firstParag, lastParag;
00824
int newAlign;
00825
QMemArray<int> oldAligns;
00826
00827 };
00828
00829
00830
00831
struct KoTextParagSelection
00832 {
00833
int start, end;
00834 };
00835
00836
struct KoTextParagLineStart
00837 {
00838 KoTextParagLineStart() : y( 0 ), baseLine( 0 ), h( 0 ), lineSpacing( 0 ), hyphenated( false )
00839 #ifndef QT_NO_COMPLEXTEXT
00840 , bidicontext( 0 )
00841 #endif
00842 { }
00843 KoTextParagLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ),
00844 lineSpacing( 0 ), hyphenated( false ),
00845 w( 0 )
00846 #ifndef QT_NO_COMPLEXTEXT
00847 , bidicontext( 0 )
00848 #endif
00849 { }
00850
#ifndef QT_NO_COMPLEXTEXT
00851
KoTextParagLineStart( KoBidiContext *c, KoBidiStatus s ) : y(0), baseLine(0), h(0),
00852 lineSpacing( 0 ), hyphenated( false ),
00853 status( s ), bidicontext( c ) {
if ( bidicontext ) bidicontext->ref(); }
00854
#endif
00855
00856
virtual ~KoTextParagLineStart()
00857 {
00858
#ifndef QT_NO_COMPLEXTEXT
00859
if ( bidicontext && bidicontext->deref() )
00860
delete bidicontext;
00861
#endif
00862
}
00863
00864
#ifndef QT_NO_COMPLEXTEXT
00865
void setContext( KoBidiContext *c ) {
00866
if ( c == bidicontext )
00867
return;
00868
if ( bidicontext && bidicontext->deref() )
00869
delete bidicontext;
00870 bidicontext = c;
00871
if ( bidicontext )
00872 bidicontext->ref();
00873 }
00874 KoBidiContext *context()
const {
return bidicontext; }
00875
#endif
00876
00877
public:
00878 ushort y, baseLine, h;
00879
short lineSpacing;
00880
bool hyphenated;
00881
#ifndef QT_NO_COMPLEXTEXT
00882
KoBidiStatus status;
00883
#endif
00884
int w;
00885
00886
private:
00887
#ifndef QT_NO_COMPLEXTEXT
00888
KoBidiContext *bidicontext;
00889
#endif
00890
};
00891
00892
#if defined(Q_TEMPLATEDLL)
00893
00894
template class QMap<int, KoTextParagSelection>;
00895
template class QMap<int, KoTextParagLineStart*>;
00896
00897
#endif
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
class KoTextParag
00908 {
00909
friend class KoTextDocument;
00910
friend class KoTextCursor;
00911
00912
public:
00913 KoTextParag( KoTextDocument *d, KoTextParag *pr = 0, KoTextParag *nx = 0,
bool updateIds = TRUE );
00914
virtual ~KoTextParag();
00915
00916 KoTextString *string() const;
00917 KoTextStringChar *at(
int i ) const;
00918
int leftGap() const;
00919
int length() const;
00920
00921
void setFormat(
KoTextFormat *fm );
00922
KoTextFormat *paragFormat() const;
00923
00924 KoTextDocument *document() const;
00925
00926
QRect rect() const;
00927
void setRect( const
QRect& rect ) { r = rect; }
00928
void setHeight(
int h ) { r.setHeight( h ); }
00929
void setWidth(
int w ) { r.setWidth( w ); }
00930
void show();
00931
void hide();
00932
bool isVisible()
const {
return visible; }
00933
00934
00935
00936
00937 KoTextParag *prev() const;
00938 KoTextParag *next() const;
00939
void setPrev( KoTextParag *s );
00940
void setNext( KoTextParag *s );
00941
00942
void insert(
int index, const QString &s );
00943
void append( const QString &s,
bool reallyAtEnd = FALSE );
00944
void truncate(
int index );
00945
void remove(
int index,
int len );
00946
00947
void invalidate(
int chr );
00948
00949
void move(
int &dy );
00950
void format(
int start = -1,
bool doMove = TRUE );
00951
00952
bool isValid() const;
00953
bool hasChanged() const;
00954
void setChanged(
bool b,
bool recursive = FALSE );
00955
short int lineChanged();
00956
void setLineChanged(
short int line );
00957
00958
int lineHeightOfChar(
int i,
int *bl = 0,
int *y = 0 ) const;
00959 KoTextStringChar *lineStartOfChar(
int i,
int *index = 0,
int *line = 0 ) const;
00960
int lines() const;
00961 KoTextStringChar *lineStartOfLine(
int line,
int *index = 0 ) const;
00962
int lineY(
int l ) const;
00963
int lineBaseLine(
int l ) const;
00964
int lineHeight(
int l ) const;
00965
void lineInfo(
int l,
int &y,
int &h,
int &bl ) const;
00966
00967
void setSelection(
int id,
int start,
int end );
00968
void removeSelection(
int id );
00969
int selectionStart(
int id ) const;
00970
int selectionEnd(
int id ) const;
00971
bool hasSelection(
int id ) const;
00972
bool hasAnySelection() const;
00973
bool fullSelected(
int id ) const;
00974
00975
00976
00977
00978
void setParagId(
int i );
00979
int paragId() const;
00980
00981
00982
00983
00984
void indent(
int *oldIndent = 0,
int *newIndent = 0 );
00985
00986
00987
00988
00989
QMap<
int, KoTextParagLineStart*> &lineStartList();
00990
00991
void setFormat(
int index,
int len, const
KoTextFormat *f,
bool useCollection = TRUE,
int flags = -1 );
00992
00993
void setAlignment( uint a );
00994
void setAlignmentDirect( uint a ) { align = a; }
00995 uint alignment() const;
00996
00997 virtual
void paint(
QPainter &painter, const
QColorGroup &cg, KoTextCursor *cursor,
bool drawSelections,
00998
int clipx,
int clipy,
int clipw,
int cliph );
00999
01000
01001
int topMargin() const;
01002
int bottomMargin() const;
01003
int leftMargin() const;
01004
int firstLineMargin() const;
01005
int rightMargin() const;
01006
int lineSpacing(
int line ) const;
01007
01008
int numberOfSubParagraph() const;
01009
void registerFloatingItem( KoTextCustomItem *i );
01010
void unregisterFloatingItem( KoTextCustomItem *i );
01011
01012
void setFullWidth(
bool b ) { fullWidth = b; }
01013
bool isFullWidth()
const {
return fullWidth; }
01014
01015
#ifdef QTEXTTABLE_AVAILABLE
01016
KoTextTableCell *tableCell()
const {
return tc; }
01017
void setTableCell( KoTextTableCell *c ) { tc = c; }
01018
#endif
01019
01020
01021
01022
int customItems() const;
01023
01024
QBrush *background() const;
01025
01026
void setDocumentRect( const
QRect &r );
01027
int documentWidth() const;
01028
01029
int documentX() const;
01030
int documentY() const;
01031 KoTextFormatCollection *formatCollection() const;
01032
01033 KoTextFormatterBase *formatter() const;
01034
01035
int widthUsed() const;
01036
01037
int nextTabDefault(
int i,
int x );
01038
int nextTab(
int i,
int x );
01039
int *tabArray() const;
01040
void setTabArray(
int *a );
01041
void setTabStops(
int tw );
01042
01043
01044
01045
01046
void setNewLinesAllowed(
bool b );
01047
bool isNewLinesAllowed() const;
01048
01049 QString richText() const;
01050
01051
01052
01053
01054
01055
01056 virtual
void join( KoTextParag *s );
01057 virtual
void copyParagData( KoTextParag *parag );
01058
01059
void setBreakable(
bool b ) { breakable = b; }
01060
bool isBreakable()
const {
return breakable; }
01061
01062
01063
01064
01065
01066
01067
01068
void setMovedDown(
bool b ) { movedDown = b; }
01069
bool wasMovedDown()
const {
return movedDown; }
01070
01071
void setDirection( QChar::Direction d );
01072 QChar::Direction direction() const;
01073
01074
01075
void insertLineStart(
int index, KoTextParagLineStart *ls );
01076
01077 protected:
01078
void drawLabel(
QPainter* p,
int x,
int y,
int w,
int h,
int base, const
QColorGroup& cg );
01079
void drawCursorDefault(
QPainter &painter, KoTextCursor *cursor,
int curx,
int cury,
int curh, const
QColorGroup &cg );
01080
void drawCursor(
QPainter &painter, KoTextCursor *cursor,
int curx,
int cury,
int curh, const
QColorGroup &cg );
01081
01082 #include "kotextparag.h"
01083
01084 private:
01085
QMap<
int, KoTextParagSelection> &selections() const;
01086
QPtrVector<
QStyleSheetItem> &styleSheetItemsVec() const;
01087
QPtrList<KoTextCustomItem> &floatingItems() const;
01088
01089
QMap<
int, KoTextParagLineStart*> lineStarts;
01090
int invalid;
01091
QRect r;
01092 KoTextParag *p, *n;
01093 KoTextDocument *doc;
01094 uint changed : 1;
01095
01096
01097
01098 uint fullWidth : 1;
01099 uint newLinesAllowed : 1;
01100
01101 uint visible : 1;
01102 uint breakable : 1;
01103
01104 uint movedDown : 1;
01105 uint align : 4;
01106
short int m_lineChanged;
01107
int id;
01108
int m_wused;
01109 KoTextString *str;
01110
QMap<
int, KoTextParagSelection> *mSelections;
01111
QPtrList<KoTextCustomItem> *mFloatingItems;
01112
01113
KoTextFormat *defFormat;
01114
01115
int *tArray;
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128 };
01129
01130
01131
01132 class KoTextFormatterBase
01133 {
01134
public:
01135 KoTextFormatterBase();
01136
virtual ~KoTextFormatterBase() {}
01137
virtual bool format( KoTextDocument *doc, KoTextParag *parag,
int start,
const QMap<int, KoTextParagLineStart*> &oldLineStarts,
int& y,
int& widthUsed ) = 0;
01138
virtual int formatVertically( KoTextDocument* doc, KoTextParag* parag );
01139
01140
01141
virtual void postFormat( KoTextParag* parag ) = 0;
01142
01143
bool isWrapEnabled( KoTextParag *p )
const {
if ( !wrapEnabled )
return FALSE;
if ( p && !p->isBreakable() )
return FALSE;
return TRUE;}
01144
int wrapAtColumn()
const {
return wrapColumn;}
01145
virtual void setWrapEnabled(
bool b ) { wrapEnabled = b; }
01146
virtual void setWrapAtColumn(
int c ) { wrapColumn = c; }
01147
virtual void setAllowBreakInWords(
bool b ) { biw = b; }
01148
bool allowBreakInWords()
const {
return biw; }
01149
01150
01151
void setViewFormattingChars(
bool b ) { m_bViewFormattingChars = b; }
01152
bool viewFormattingChars()
const {
return m_bViewFormattingChars; }
01153
01154
bool isBreakable( KoTextString *string,
int pos )
const;
01155
bool isStretchable( KoTextString *string,
int pos )
const;
01156
01157
protected:
01158
01159
01160
01161
01162
#ifndef QT_NO_COMPLEXTEXT
01163
virtual KoTextParagLineStart *bidiReorderLine( KoTextParag *parag, KoTextString *string, KoTextParagLineStart *line, KoTextStringChar *start,
01164 KoTextStringChar *last,
int align,
int space );
01165
#endif
01166
01167
private:
01168
int wrapColumn;
01169
bool wrapEnabled;
01170
bool m_bViewFormattingChars;
01171
bool biw;
01172
bool unused;
01173
01174
#ifdef HAVE_THAI_BREAKS
01175
static QCString *thaiCache;
01176
static KoTextString *cachedString;
01177
static ThBreakIterator *thaiIt;
01178
#endif
01179
};
01180
01181
01182
01183
01184
class KoTextIndent
01185 {
01186
public:
01187 KoTextIndent();
01188
virtual ~KoTextIndent() {}
01189
01190
virtual void indent( KoTextDocument *doc, KoTextParag *parag,
int *oldIndent = 0,
int *newIndent = 0 ) = 0;
01191
01192 };
01193
01194
01195
01196
#if 0
01197
class KoTextPreProcessor
01198 {
01199
public:
01200
enum Ids {
01201 Standard = 0
01202 };
01203
01204 KoTextPreProcessor() {}
01205
virtual ~KoTextPreProcessor() {}
01206
01207
virtual void process( KoTextDocument *doc, KoTextParag *,
int,
bool = TRUE ) = 0;
01208
virtual KoTextFormat *format(
int id ) = 0;
01209
01210 };
01211
#endif
01212
01213
01214
01215
01216
01217
inline int KoTextString::length()
const
01218
{
01219
return data.size();
01220 }
01221
01222
inline void KoTextString::operator+=(
const QString &s )
01223 {
01224 insert( length(), s, 0 );
01225 }
01226
01227
inline int KoTextParag::length()
const
01228
{
01229
return str->length();
01230 }
01231
01232
inline QRect KoTextParag::rect()
const
01233
{
01234
return r;
01235 }
01236
01237
inline KoTextParag *KoTextCursor::parag()
const
01238
{
01239
return string;
01240 }
01241
01242
inline int KoTextCursor::index()
const
01243
{
01244
return idx;
01245 }
01246
01247
inline void KoTextCursor::setParag( KoTextParag *s,
bool restore )
01248 {
01249
if ( restore )
01250 restoreState();
01251 idx = 0;
01252 string = s;
01253 tmpIndex = -1;
01254 }
01255
01256
inline void KoTextCursor::checkIndex()
01257 {
01258
if ( idx >= string->length() )
01259 idx = string->length() - 1;
01260 }
01261
01262
01263
01264
inline KoTextStringChar &KoTextString::at(
int i )
const
01265
{
01266
return data[ i ];
01267 }
01268
01269
inline QString KoTextString::toString()
const
01270
{
01271
return toString( data );
01272 }
01273
01274
01275
01276
inline KoTextStringChar *KoTextParag::at(
int i )
const
01277
{
01278
return &str->at( i );
01279 }
01280
01281
inline bool KoTextParag::isValid()
const
01282
{
01283
return invalid == -1;
01284 }
01285
01286
inline bool KoTextParag::hasChanged()
const
01287
{
01288
return changed;
01289 }
01290
01291
inline short int KoTextParag::lineChanged()
01292 {
01293
return m_lineChanged;
01294 }
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
inline void KoTextParag::append(
const QString &s,
bool reallyAtEnd )
01310 {
01311
if ( reallyAtEnd )
01312 insert( str->length(), s );
01313
else
01314 insert( QMAX( str->length() - 1, 0 ), s );
01315 }
01316
01317
inline KoTextParag *KoTextParag::prev()
const
01318
{
01319
return p;
01320 }
01321
01322
inline KoTextParag *KoTextParag::next()
const
01323
{
01324
return n;
01325 }
01326
01327
inline bool KoTextParag::hasAnySelection()
const
01328
{
01329
return mSelections ? !selections().isEmpty() : FALSE;
01330 }
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
inline void KoTextParag::setParagId(
int i )
01345 {
01346
id = i;
01347 }
01348
01349
inline int KoTextParag::paragId()
const
01350
{
01351
01352
01353
return id;
01354 }
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
inline QMap<int, KoTextParagLineStart*> &KoTextParag::lineStartList()
01367 {
01368
return lineStarts;
01369 }
01370
01371
inline KoTextString *KoTextParag::string()
const
01372
{
01373
return str;
01374 }
01375
01376
inline KoTextDocument *KoTextParag::document()
const
01377
{
01378
return doc;
01379 }
01380
01381
inline void KoTextParag::setAlignment( uint a )
01382 {
01383
if ( a == align )
01384
return;
01385 align = a;
01386 invalidate( 0 );
01387 }
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
inline KoTextFormat *KoTextParag::paragFormat()
const
01401
{
01402
return defFormat;
01403 }
01404
01405
inline void KoTextParag::registerFloatingItem( KoTextCustomItem *i )
01406 {
01407 floatingItems().append( i );
01408 }
01409
01410
inline void KoTextParag::unregisterFloatingItem( KoTextCustomItem *i )
01411 {
01412 floatingItems().removeRef( i );
01413 }
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
inline int KoTextParag::customItems()
const
01426
{
01427
return mFloatingItems ? mFloatingItems->count() : 0;
01428
01429 }
01430
01431
inline QBrush *KoTextParag::background()
const
01432
{
01433
#ifdef QTEXTTABLE_AVAILABLE
01434
return tc ? tc->backGround() : 0;
01435
#endif
01436
return 0;
01437 }
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
inline void KoTextParag::setNewLinesAllowed(
bool b )
01456 {
01457 newLinesAllowed = b;
01458 }
01459
01460
inline bool KoTextParag::isNewLinesAllowed()
const
01461
{
01462
return newLinesAllowed;
01463 }
01464
01465
01466
01467
inline KoTextFormat *KoTextStringChar::format()
const
01468
{
01469
return (type == Regular) ? d.format : d.custom->format;
01470 }
01471
01472
inline KoTextCustomItem *KoTextStringChar::customItem()
const
01473
{
01474
return isCustom() ? d.custom->custom : 0;
01475 }
01476
01477
#endif