a b/src/qtgui/q3richtext_p.h
1
/****************************************************************************
2
**
3
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
4
**
5
** This file is part of the Qt3Support module of the Qt Toolkit.
6
**
7
** This file may be used under the terms of the GNU General Public
8
** License version 2.0 as published by the Free Software Foundation
9
** and appearing in the file LICENSE.GPL included in the packaging of
10
** this file.  Please review the following information to ensure GNU
11
** General Public Licensing requirements will be met:
12
** http://trolltech.com/products/qt/licenses/licensing/opensource/
13
**
14
** If you are unsure which license is appropriate for your use, please
15
** review the following information:
16
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
17
** or contact the sales department at sales@trolltech.com.
18
**
19
** In addition, as a special exception, Trolltech gives you certain
20
** additional rights. These rights are described in the Trolltech GPL
21
** Exception version 1.0, which can be found at
22
** http://www.trolltech.com/products/qt/gplexception/ and in the file
23
** GPL_EXCEPTION.txt in this package.
24
**
25
** In addition, as a special exception, Trolltech, as the sole copyright
26
** holder for Qt Designer, grants users of the Qt/Eclipse Integration
27
** plug-in the right for the Qt/Eclipse Integration to link to
28
** functionality provided by Qt Designer and its related libraries.
29
**
30
** Trolltech reserves all rights not expressly granted herein.
31
** 
32
** Trolltech ASA (c) 2007
33
**
34
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
35
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
36
**
37
****************************************************************************/
38
39
#ifndef Q3RICHTEXT_P_H
40
#define Q3RICHTEXT_P_H
41
42
//
43
//  W A R N I N G
44
//  -------------
45
//
46
// This file is not part of the Qt API.  It exists for the convenience
47
// of a number of Qt sources files.  This header file may change from
48
// version to version without notice, or even be removed.
49
//
50
// We mean it.
51
//
52
53
#include "QtGui/qapplication.h"
54
#include "QtGui/qcolor.h"
55
#include "QtCore/qhash.h"
56
#include "QtGui/qfont.h"
57
#include "QtGui/qfontmetrics.h"
58
#include "QtGui/qlayout.h"
59
#include "QtCore/qmap.h"
60
#include "QtCore/qvector.h"
61
#include "QtCore/qstack.h"
62
#include "QtCore/qlist.h"
63
#include "QtCore/qobject.h"
64
#include "QtGui/qpainter.h"
65
#include "QtGui/qpixmap.h"
66
#include "QtCore/qrect.h"
67
#include "QtCore/qsize.h"
68
#include "QtCore/qstring.h"
69
#include "QtCore/qstringlist.h"
70
#include "Qt3Support/q3stylesheet.h"
71
#include "Qt3Support/q3mimefactory.h"
72
73
#ifndef QT_NO_RICHTEXT
74
75
class Q3TextDocument;
76
class Q3TextString;
77
class Q3TextPreProcessor;
78
class Q3TextFormat;
79
class Q3TextCursor;
80
class Q3TextParagraph;
81
class Q3TextFormatter;
82
class Q3TextIndent;
83
class Q3TextFormatCollection;
84
class Q3StyleSheetItem;
85
#ifndef QT_NO_TEXTCUSTOMITEM
86
class Q3TextCustomItem;
87
#endif
88
class Q3TextFlow;
89
struct QBidiContext;
90
91
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
92
93
class Q_COMPAT_EXPORT Q3TextStringChar
94
{
95
    friend class Q3TextString;
96
97
public:
98
    // this is never called, initialize variables in Q3TextString::insert()!!!
99
    Q3TextStringChar() : nobreak(false), lineStart(0), type(Regular) {p.format=0;}
100
    ~Q3TextStringChar();
101
102
    struct CustomData
103
    {
104
        Q3TextFormat *format;
105
#ifndef QT_NO_TEXTCUSTOMITEM
106
        Q3TextCustomItem *custom;
107
#endif
108
        QString anchorName;
109
        QString anchorHref;
110
    };
111
    enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 };
112
113
    QChar c;
114
    // this is the same struct as in qtextengine_p.h. Don't change!
115
    uchar softBreak      :1;     // Potential linebreak point
116
    uchar whiteSpace     :1;     // A unicode whitespace character, except NBSP, ZWNBSP
117
    uchar charStop       :1;     // Valid cursor position (for left/right arrow)
118
    uchar nobreak        :1;
119
120
    uchar lineStart : 1;
121
    uchar /*Type*/ type : 2;
122
    uchar bidiLevel       :7;
123
    uchar rightToLeft : 1;
124
125
    int x;
126
    union {
127
        Q3TextFormat* format;
128
        CustomData* custom;
129
    } p;
130
131
132
    int height() const;
133
    int ascent() const;
134
    int descent() const;
135
    bool isCustom() const { return (type & Custom) != 0; }
136
    Q3TextFormat *format() const;
137
#ifndef QT_NO_TEXTCUSTOMITEM
138
    Q3TextCustomItem *customItem() const;
139
#endif
140
    void setFormat(Q3TextFormat *f);
141
#ifndef QT_NO_TEXTCUSTOMITEM
142
    void setCustomItem(Q3TextCustomItem *i);
143
#endif
144
145
#ifndef QT_NO_TEXTCUSTOMITEM
146
    void loseCustomItem();
147
#endif
148
149
150
    bool isAnchor() const { return (type & Anchor) != 0; }
151
    bool isLink() const { return isAnchor() && p.custom->anchorHref.count(); }
152
    QString anchorName() const;
153
    QString anchorHref() const;
154
    void setAnchor(const QString& name, const QString& href);
155
156
    Q3TextStringChar(const Q3TextStringChar &) {
157
        Q_ASSERT(false);
158
    }
159
private:
160
    Q3TextStringChar &operator=(const Q3TextStringChar &) {
161
        //abort();
162
        return *this;
163
    }
164
    friend class Q3TextParagraph;
165
};
166
167
Q_DECLARE_TYPEINFO(Q3TextStringChar, Q_PRIMITIVE_TYPE);
168
169
class Q_COMPAT_EXPORT Q3TextString
170
{
171
public:
172
173
    Q3TextString();
174
    Q3TextString(const Q3TextString &s);
175
    virtual ~Q3TextString();
176
177
    static QString toString(const QVector<Q3TextStringChar> &data);
178
    QString toString() const;
179
180
    inline Q3TextStringChar &at(int i) const {
181
        return const_cast<Q3TextString *>(this)->data[i];
182
    }
183
    inline int length() const { return data.size(); }
184
185
    int width(int idx) const;
186
187
    void insert(int index, const QString &s, Q3TextFormat *f);
188
    void insert(int index, const QChar *unicode, int len, Q3TextFormat *f);
189
    void insert(int index, Q3TextStringChar *c, bool doAddRefFormat = false);
190
    void truncate(int index);
191
    void remove(int index, int len);
192
    void clear();
193
194
    void setFormat(int index, Q3TextFormat *f, bool useCollection);
195
196
    void setBidi(bool b) { bidi = b; }
197
    bool isBidi() const;
198
    bool isRightToLeft() const;
199
    QChar::Direction direction() const;
200
    void setDirection(QChar::Direction dr) { rightToLeft = (dr == QChar::DirR); bidiDirty = true; }
201
202
    QVector<Q3TextStringChar> rawData() const { return data; }
203
204
    void operator=(const QString &s) { clear(); insert(0, s, 0); }
205
    void operator+=(const QString &s) { insert(length(), s, 0); }
206
    void prepend(const QString &s) { insert(0, s, 0); }
207
    int appendParagraphs( Q3TextParagraph *start, Q3TextParagraph *end );
208
209
    // return next and previous valid cursor positions.
210
    bool validCursorPosition(int idx);
211
    int nextCursorPosition(int idx);
212
    int previousCursorPosition(int idx);
213
214
private:
215
    void checkBidi() const;
216
217
    QVector<Q3TextStringChar> data;
218
    QString stringCache;
219
    uint bidiDirty : 1;
220
    uint bidi : 1; // true when the paragraph has right to left characters
221
    uint rightToLeft : 1;
222
};
223
224
inline bool Q3TextString::isBidi() const
225
{
226
    if (bidiDirty)
227
        checkBidi();
228
    return bidi;
229
}
230
231
inline bool Q3TextString::isRightToLeft() const
232
{
233
    if (bidiDirty)
234
        checkBidi();
235
    return rightToLeft;
236
}
237
238
inline QString Q3TextString::toString() const
239
{
240
    if (bidiDirty)
241
        checkBidi();
242
    return stringCache;
243
}
244
245
inline QChar::Direction Q3TextString::direction() const
246
{
247
    return rightToLeft ? QChar::DirR : QChar::DirL;
248
}
249
250
inline int Q3TextString::nextCursorPosition(int next)
251
{
252
    if (bidiDirty)
253
        checkBidi();
254
255
    const Q3TextStringChar *c = data.data();
256
    int len = length();
257
258
    if (next < len - 1) {
259
        next++;
260
        while (next < len - 1 && !c[next].charStop)
261
            next++;
262
    }
263
    return next;
264
}
265
266
inline int Q3TextString::previousCursorPosition(int prev)
267
{
268
    if (bidiDirty)
269
        checkBidi();
270
271
    const Q3TextStringChar *c = data.data();
272
273
    if (prev) {
274
        prev--;
275
        while (prev && !c[prev].charStop)
276
            prev--;
277
    }
278
    return prev;
279
}
280
281
inline bool Q3TextString::validCursorPosition(int idx)
282
{
283
    if (bidiDirty)
284
        checkBidi();
285
286
    return (at(idx).charStop);
287
}
288
289
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
290
291
class Q_COMPAT_EXPORT Q3TextCursor
292
{
293
public:
294
    Q3TextCursor(Q3TextDocument * = 0);
295
    Q3TextCursor(const Q3TextCursor &c);
296
    Q3TextCursor &operator=(const Q3TextCursor &c);
297
    virtual ~Q3TextCursor();
298
299
    bool operator==(const Q3TextCursor &c) const;
300
    bool operator!=(const Q3TextCursor &c) const { return !(*this == c); }
301
302
    inline Q3TextParagraph *paragraph() const { return para; }
303
304
    Q3TextDocument *document() const;
305
    int index() const;
306
307
    void gotoPosition(Q3TextParagraph* p, int index = 0);
308
    void setIndex(int index) { gotoPosition(paragraph(), index); }
309
    void setParagraph(Q3TextParagraph*p) { gotoPosition(p, 0); }
310
311
    void gotoLeft();
312
    void gotoRight();
313
    void gotoNextLetter();
314
    void gotoPreviousLetter();
315
    void gotoUp();
316
    void gotoDown();
317
    void gotoLineEnd();
318
    void gotoLineStart();
319
    void gotoHome();
320
    void gotoEnd();
321
    void gotoPageUp(int visibleHeight);
322
    void gotoPageDown(int visibleHeight);
323
    void gotoNextWord(bool onlySpace = false);
324
    void gotoPreviousWord(bool onlySpace = false);
325
    void gotoWordLeft();
326
    void gotoWordRight();
327
328
    void insert(const QString &s, bool checkNewLine, QVector<Q3TextStringChar> *formatting = 0);
329
    void splitAndInsertEmptyParagraph(bool ind = true, bool updateIds = true);
330
    bool remove();
331
    bool removePreviousChar();
332
    void indent();
333
334
    bool atParagStart();
335
    bool atParagEnd();
336
337
    int x() const; // x in current paragraph
338
    int y() const; // y in current paragraph
339
340
    int globalX() const;
341
    int globalY() const;
342
343
    Q3TextParagraph *topParagraph() const { return paras.isEmpty() ? para : paras.first(); }
344
    int offsetX() const { return ox; } // inner document  offset
345
    int offsetY() const { return oy; } // inner document offset
346
    int totalOffsetX() const; // total document offset
347
    int totalOffsetY() const; // total document offset
348
349
    bool place(const QPoint &pos, Q3TextParagraph *s) { return place(pos, s, false); }
350
    bool place(const QPoint &pos, Q3TextParagraph *s, bool link);
351
    void restoreState();
352
353
354
    int nestedDepth() const { return (int)indices.count(); } //### size_t/int cast
355
    void oneUp() { if (!indices.isEmpty()) pop(); }
356
    void setValid(bool b) { valid = b; }
357
    bool isValid() const { return valid; }
358
359
    void fixCursorPosition();
360
private:
361
    enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down };
362
363
    void push();
364
    void pop();
365
    bool processNesting(Operation op);
366
    void invalidateNested();
367
    void gotoIntoNested(const QPoint &globalPos);
368
369
    Q3TextParagraph *para;
370
    int idx, tmpX;
371
    int ox, oy;
372
    QStack<int> indices;
373
    QStack<Q3TextParagraph*> paras;
374
    QStack<int> xOffsets;
375
    QStack<int> yOffsets;
376
    uint valid : 1;
377
378
};
379
380
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
381
382
class Q_COMPAT_EXPORT Q3TextCommand
383
{
384
public:
385
    enum Commands { Invalid, Insert, Delete, Format, Style };
386
387
    Q3TextCommand(Q3TextDocument *dc) : doc(dc), cursor(dc) {}
388
    virtual ~Q3TextCommand();
389
390
    virtual Commands type() const;
391
392
    virtual Q3TextCursor *execute(Q3TextCursor *c) = 0;
393
    virtual Q3TextCursor *unexecute(Q3TextCursor *c) = 0;
394
395
protected:
396
    Q3TextDocument *doc;
397
    Q3TextCursor cursor;
398
399
};
400
401
class Q_COMPAT_EXPORT Q3TextCommandHistory
402
{
403
public:
404
    Q3TextCommandHistory(int s) : current(-1), steps(s) {  }
405
    virtual ~Q3TextCommandHistory(); // ### why is it virtual?
406
407
    void clear();
408
409
    void addCommand(Q3TextCommand *cmd);
410
    Q3TextCursor *undo(Q3TextCursor *c);
411
    Q3TextCursor *redo(Q3TextCursor *c);
412
413
    bool isUndoAvailable();
414
    bool isRedoAvailable();
415
416
    void setUndoDepth(int depth) { steps = depth; }
417
    int undoDepth() const { return steps; }
418
419
    int historySize() const { return history.count(); }
420
    int currentPosition() const { return current; }
421
422
private:
423
    QList<Q3TextCommand *> history;
424
    int current, steps;
425
};
426
427
inline Q3TextCommandHistory::~Q3TextCommandHistory()
428
{
429
    clear();
430
}
431
432
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
433
434
#ifndef QT_NO_TEXTCUSTOMITEM
435
class Q_COMPAT_EXPORT Q3TextCustomItem
436
{
437
public:
438
    Q3TextCustomItem(Q3TextDocument *p)
439
        :  xpos(0), ypos(-1), width(-1), height(0), parent(p)
440
    {}
441
    virtual ~Q3TextCustomItem();
442
    virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
443
                      const QPalette &pal, bool selected) = 0;
444
445
    virtual void adjustToPainter(QPainter*);
446
447
    enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight };
448
    virtual Placement placement() const;
449
    bool placeInline() { return placement() == PlaceInline; }
450
451
    virtual bool ownLine() const;
452
    virtual void resize(int nwidth);
453
    virtual void invalidate();
454
    virtual int ascent() const { return height; }
455
456
    virtual bool isNested() const;
457
    virtual int minimumWidth() const;
458
459
    virtual QString richText() const;
460
461
    int xpos; // used for floating items
462
    int ypos; // used for floating items
463
    int width;
464
    int height;
465
466
    QRect geometry() const { return QRect(xpos, ypos, width, height); }
467
468
    virtual bool enter(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = false);
469
    virtual bool enterAt(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint &);
470
    virtual bool next(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
471
    virtual bool prev(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
472
    virtual bool down(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
473
    virtual bool up(Q3TextCursor *, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
474
475
    void setParagraph(Q3TextParagraph *p) { parag = p; }
476
    Q3TextParagraph *paragraph() const { return parag; }
477
478
    Q3TextDocument *parent;
479
    Q3TextParagraph *parag;
480
481
    virtual void pageBreak(int  y, Q3TextFlow* flow);
482
};
483
#endif
484
485
486
#ifndef QT_NO_TEXTCUSTOMITEM
487
class Q_COMPAT_EXPORT Q3TextImage : public Q3TextCustomItem
488
{
489
public:
490
    Q3TextImage(Q3TextDocument *p, const QMap<QString, QString> &attr, const QString& context,
491
                Q3MimeSourceFactory &factory);
492
    virtual ~Q3TextImage();
493
494
    Placement placement() const { return place; }
495
    void adjustToPainter(QPainter*);
496
    int minimumWidth() const { return width; }
497
498
    QString richText() const;
499
500
    void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
501
               const QPalette &pal, bool selected);
502
503
private:
504
    QRegion* reg;
505
    QPixmap pm;
506
    Placement place;
507
    int tmpwidth, tmpheight;
508
    QMap<QString, QString> attributes;
509
    QString imgId;
510
511
};
512
#endif
513
514
#ifndef QT_NO_TEXTCUSTOMITEM
515
class Q_COMPAT_EXPORT Q3TextHorizontalLine : public Q3TextCustomItem
516
{
517
public:
518
    Q3TextHorizontalLine(Q3TextDocument *p, const QMap<QString, QString> &attr, const QString& context,
519
                         Q3MimeSourceFactory &factory);
520
    virtual ~Q3TextHorizontalLine();
521
522
    void adjustToPainter(QPainter*);
523
    void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
524
              const QPalette &pal, bool selected);
525
    QString richText() const;
526
527
    bool ownLine() const { return true; }
528
529
private:
530
    int tmpheight;
531
    QColor color;
532
    bool shade;
533
534
};
535
#endif
536
537
class Q_COMPAT_EXPORT Q3TextFlow
538
{
539
    friend class Q3TextDocument;
540
#ifndef QT_NO_TEXTCUSTOMITEM
541
    friend class Q3TextTableCell;
542
#endif
543
544
public:
545
    Q3TextFlow();
546
    virtual ~Q3TextFlow();
547
548
    virtual void setWidth(int width);
549
    int width() const;
550
551
    virtual void setPageSize(int ps);
552
    int pageSize() const { return pagesize; }
553
554
    virtual int adjustLMargin(int yp, int h, int margin, int space);
555
    virtual int adjustRMargin(int yp, int h, int margin, int space);
556
557
#ifndef QT_NO_TEXTCUSTOMITEM
558
    virtual void registerFloatingItem(Q3TextCustomItem* item);
559
    virtual void unregisterFloatingItem(Q3TextCustomItem* item);
560
#endif
561
    virtual QRect boundingRect() const;
562
    virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch,
563
                                   const QPalette &pal, bool selected);
564
565
    virtual int adjustFlow(int  y, int w, int h); // adjusts y according to the defined pagesize. Returns the shift.
566
567
    virtual bool isEmpty();
568
569
    void clear();
570
571
private:
572
    int w;
573
    int pagesize;
574
575
#ifndef QT_NO_TEXTCUSTOMITEM
576
    QList<Q3TextCustomItem *> leftItems;
577
    QList<Q3TextCustomItem *> rightItems;
578
#endif
579
};
580
581
inline int Q3TextFlow::width() const { return w; }
582
583
#ifndef QT_NO_TEXTCUSTOMITEM
584
class Q3TextTable;
585
586
class Q_COMPAT_EXPORT Q3TextTableCell : public QLayoutItem
587
{
588
    friend class Q3TextTable;
589
590
public:
591
    Q3TextTableCell(Q3TextTable* table,
592
                    int row, int column,
593
                    const QMap<QString, QString> &attr,
594
                    const Q3StyleSheetItem* style,
595
                    const Q3TextFormat& fmt, const QString& context,
596
                    Q3MimeSourceFactory &factory, Q3StyleSheet *sheet, const QString& doc);
597
    virtual ~Q3TextTableCell();
598
599
    QSize sizeHint() const ;
600
    QSize minimumSize() const ;
601
    QSize maximumSize() const ;
602
    Qt::Orientations expandingDirections() const;
603
    bool isEmpty() const;
604
    void setGeometry(const QRect&) ;
605
    QRect geometry() const;
606
607
    bool hasHeightForWidth() const;
608
    int heightForWidth(int) const;
609
610
    void adjustToPainter(QPainter*);
611
612
    int row() const { return row_; }
613
    int column() const { return col_; }
614
    int rowspan() const { return rowspan_; }
615
    int colspan() const { return colspan_; }
616
    int stretch() const { return stretch_; }
617
618
    Q3TextDocument* richText()  const { return richtext; }
619
    Q3TextTable* table() const { return parent; }
620
621
    void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
622
               const QPalette &cg, bool selected);
623
624
    QBrush *backGround() const { return background; }
625
    virtual void invalidate();
626
627
    int verticalAlignmentOffset() const;
628
    int horizontalAlignmentOffset() const;
629
630
private:
631
    QRect geom;
632
    Q3TextTable* parent;
633
    Q3TextDocument* richtext;
634
    int row_;
635
    int col_;
636
    int rowspan_;
637
    int colspan_;
638
    int stretch_;
639
    int maxw;
640
    int minw;
641
    bool hasFixedWidth;
642
    QBrush *background;
643
    int cached_width;
644
    int cached_sizehint;
645
    QMap<QString, QString> attributes;
646
    int align;
647
};
648
#endif
649
650
651
#ifndef QT_NO_TEXTCUSTOMITEM
652
class Q_COMPAT_EXPORT Q3TextTable: public Q3TextCustomItem
653
{
654
    friend class Q3TextTableCell;
655
656
public:
657
    Q3TextTable(Q3TextDocument *p, const QMap<QString, QString> &attr);
658
    virtual ~Q3TextTable();
659
660
    void adjustToPainter(QPainter *p);
661
    void pageBreak(int  y, Q3TextFlow* flow);
662
    void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch,
663
               const QPalette &pal, bool selected);
664
665
    bool noErase() const { return true; }
666
    bool ownLine() const { return true; }
667
    Placement placement() const { return place; }
668
    bool isNested() const { return true; }
669
    void resize(int nwidth);
670
    virtual void invalidate();
671
672
    virtual bool enter(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy, bool atEnd = false);
673
    virtual bool enterAt(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy, const QPoint &pos);
674
    virtual bool next(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
675
    virtual bool prev(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
676
    virtual bool down(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
677
    virtual bool up(Q3TextCursor *c, Q3TextDocument *&doc, Q3TextParagraph *&parag, int &idx, int &ox, int &oy);
678
679
    QString richText() const;
680
681
    int minimumWidth() const;
682
683
    QList<Q3TextTableCell *> tableCells() const { return cells; }
684
685
    bool isStretching() const { return stretch; }
686
687
private:
688
    void format(int w);
689
    void addCell(Q3TextTableCell* cell);
690
691
private:
692
    QGridLayout* layout;
693
    QList<Q3TextTableCell *> cells;
694
    int cachewidth;
695
    int fixwidth;
696
    int cellpadding;
697
    int cellspacing;
698
    int border;
699
    int outerborder;
700
    int stretch;
701
    int innerborder;
702
    int us_cp, us_ib, us_b, us_ob, us_cs;
703
    int us_fixwidth;
704
    QMap<QString, QString> attributes;
705
    QMap<Q3TextCursor*, int> currCell;
706
    Placement place;
707
    void adjustCells(int y , int shift);
708
    int pageBreakFor;
709
};
710
#endif
711
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
712
713
#ifndef QT_NO_TEXTCUSTOMITEM
714
class Q3TextTableCell;
715
class Q3TextParagraph;
716
#endif
717
718
struct Q_COMPAT_EXPORT Q3TextDocumentSelection
719
{
720
    Q3TextCursor startCursor, endCursor;
721
    bool swapped;
722
    Q_DUMMY_COMPARISON_OPERATOR(Q3TextDocumentSelection)
723
};
724
725
class Q_COMPAT_EXPORT Q3TextDocument : public QObject
726
{
727
    Q_OBJECT
728
729
#ifndef QT_NO_TEXTCUSTOMITEM
730
    friend class Q3TextTableCell;
731
#endif
732
    friend class Q3TextCursor;
733
    friend class Q3TextEdit;
734
    friend class Q3TextParagraph;
735
736
public:
737
    enum SelectionIds {
738
        Standard = 0,
739
        Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to
740
        // remove multiple lines with removeSelectedText()
741
    };
742
743
    Q3TextDocument(Q3TextDocument *p);
744
    virtual ~Q3TextDocument();
745
746
    Q3TextDocument *parent() const { return par; }
747
    Q3TextParagraph *parentParagraph() const { return parentPar; }
748
749
    void setText(const QString &text, const QString &context);
750
    QMap<QString, QString> attributes() const { return attribs; }
751
    void setAttributes(const QMap<QString, QString> &attr) { attribs = attr; }
752
753
    QString text() const;
754
    QString text(int parag) const;
755
    QString originalText() const;
756
757
    int x() const;
758
    int y() const;
759
    int width() const;
760
    int widthUsed() const;
761
    int visibleWidth() const;
762
    int height() const;
763
    void setWidth(int w);
764
    int minimumWidth() const;
765
    bool setMinimumWidth(int needed, int used = -1, Q3TextParagraph *parag = 0);
766
767
    void setY(int y);
768
    int leftMargin() const;
769
    void setLeftMargin(int lm);
770
    int rightMargin() const;
771
    void setRightMargin(int rm);
772
773
    Q3TextParagraph *firstParagraph() const;
774
    Q3TextParagraph *lastParagraph() const;
775
    void setFirstParagraph(Q3TextParagraph *p);
776
    void setLastParagraph(Q3TextParagraph *p);
777
778
    void invalidate();
779
780
    void setPreProcessor(Q3TextPreProcessor *sh);
781
    Q3TextPreProcessor *preProcessor() const;
782
783
    void setFormatter(Q3TextFormatter *f);
784
    Q3TextFormatter *formatter() const;
785
786
    void setIndent(Q3TextIndent *i);
787
    Q3TextIndent *indent() const;
788
789
    QColor selectionColor(int id) const;
790
    QColor selectionTextColor(int id) const;
791
    bool hasSelectionTextColor(int id) const;
792
    void setSelectionColor(int id, const QColor &c);
793
    void setSelectionTextColor(int id, const QColor &b);
794
    bool hasSelection(int id, bool visible = false) const;
795
    void setSelectionStart(int id, const Q3TextCursor &cursor);
796
    bool setSelectionEnd(int id, const Q3TextCursor &cursor);
797
    void selectAll(int id);
798
    bool removeSelection(int id);
799
    void selectionStart(int id, int &paragId, int &index);
800
    Q3TextCursor selectionStartCursor(int id);
801
    Q3TextCursor selectionEndCursor(int id);
802
    void selectionEnd(int id, int &paragId, int &index);
803
    void setFormat(int id, Q3TextFormat *f, int flags);
804
    int numSelections() const { return nSelections; }
805
    void addSelection(int id);
806
807
    QString selectedText(int id, bool asRichText = false) const;
808
    void removeSelectedText(int id, Q3TextCursor *cursor);
809
    void indentSelection(int id);
810
811
    Q3TextParagraph *paragAt(int i) const;
812
813
    void addCommand(Q3TextCommand *cmd);
814
    Q3TextCursor *undo(Q3TextCursor *c = 0);
815
    Q3TextCursor *redo(Q3TextCursor *c  = 0);
816
    Q3TextCommandHistory *commands() const { return commandHistory; }
817
818
    Q3TextFormatCollection *formatCollection() const;
819
820
    bool find(Q3TextCursor &cursor, const QString &expr, bool cs, bool wo, bool forward);
821
822
    void setTextFormat(Qt::TextFormat f);
823
    Qt::TextFormat textFormat() const;
824
825
    bool inSelection(int selId, const QPoint &pos) const;
826
827
    Q3StyleSheet *styleSheet() const { return sheet_; }
828
#ifndef QT_NO_MIME
829
    Q3MimeSourceFactory *mimeSourceFactory() const { return factory_; }
830
#endif
831
    QString context() const { return contxt; }
832
833
    void setStyleSheet(Q3StyleSheet *s);
834
    void setDefaultFormat(const QFont &font, const QColor &color);
835
#ifndef QT_NO_MIME
836
    void setMimeSourceFactory(Q3MimeSourceFactory *f) { if (f) factory_ = f; }
837
#endif
838
    void setContext(const QString &c) { if (!c.isEmpty()) contxt = c; }
839
840
    void setUnderlineLinks(bool b);
841
    bool underlineLinks() const { return underlLinks; }
842
843
    void setPaper(QBrush *brush) { if (backBrush) delete backBrush; backBrush = brush; }
844
    QBrush *paper() const { return backBrush; }
845
846
    void doLayout(QPainter *p, int w);
847
    void draw(QPainter *p, const QRect& rect, const QPalette &pal, const QBrush *paper = 0);
848
849
    void drawParagraph(QPainter *p, Q3TextParagraph *parag, int cx, int cy, int cw, int ch,
850
                    QPixmap *&doubleBuffer, const QPalette &pal,
851
                    bool drawCursor, Q3TextCursor *cursor, bool resetChanged = true);
852
    Q3TextParagraph *draw(QPainter *p, int cx, int cy, int cw, int ch, const QPalette &pal,
853
                      bool onlyChanged = false, bool drawCursor = false, Q3TextCursor *cursor = 0,
854
                      bool resetChanged = true);
855
856
#ifndef QT_NO_TEXTCUSTOMITEM
857
    static Q3TextCustomItem* tag(Q3StyleSheet *sheet, const QString& name,
858
                                 const QMap<QString, QString> &attr,
859
                                 const QString& context,
860
                                 const Q3MimeSourceFactory& factory,
861
                                 bool emptyTag, Q3TextDocument *doc);
862
#endif
863
864
#ifndef QT_NO_TEXTCUSTOMITEM
865
    void registerCustomItem(Q3TextCustomItem *i, Q3TextParagraph *p);
866
    void unregisterCustomItem(Q3TextCustomItem *i, Q3TextParagraph *p);
867
#endif
868
869
    void setFlow(Q3TextFlow *f);
870
    void takeFlow();
871
    Q3TextFlow *flow() const { return flow_; }
872
    bool isPageBreakEnabled() const { return pages; }
873
    void setPageBreakEnabled(bool b) { pages = b; }
874
875
    void setUseFormatCollection(bool b) { useFC = b; }
876
    bool useFormatCollection() const { return useFC; }
877
878
#ifndef QT_NO_TEXTCUSTOMITEM
879
    Q3TextTableCell *tableCell() const { return tc; }
880
    void setTableCell(Q3TextTableCell *c) { tc = c; }
881
#endif
882
883
    void setPlainText(const QString &text);
884
    void setRichText(const QString &text, const QString &context, const Q3TextFormat *initialFormat = 0);
885
    QString richText() const;
886
    QString plainText() const;
887
888
    bool focusNextPrevChild(bool next);
889
890
    int alignment() const;
891
    void setAlignment(int a);
892
893
    int *tabArray() const;
894
    int tabStopWidth() const;
895
    void setTabArray(int *a);
896
    void setTabStops(int tw);
897
898
    void setUndoDepth(int depth) { commandHistory->setUndoDepth(depth); }
899
    int undoDepth() const { return commandHistory->undoDepth(); }
900
901
    int length() const;
902
    void clear(bool createEmptyParag = false);
903
904
    virtual Q3TextParagraph *createParagraph(Q3TextDocument *, Q3TextParagraph *pr = 0, Q3TextParagraph *nx = 0, bool updateIds = true);
905
    void insertChild(Q3TextDocument *dc) { childList.append(dc); }
906
    void removeChild(Q3TextDocument *dc) { childList.removeAll(dc); }
907
    QList<Q3TextDocument *> children() const { return childList; }
908
909
    bool hasFocusParagraph() const;
910
    QString focusHref() const;
911
    QString focusName() const;
912
913
    void invalidateOriginalText() { oTextValid = false; oText = QLatin1String(""); }
914
915
Q_SIGNALS:
916
    void minimumWidthChanged(int);
917
918
private:
919
    Q_DISABLE_COPY(Q3TextDocument)
920
921
    void init();
922
    QPixmap *bufferPixmap(const QSize &s);
923
    // HTML parser
924
    bool hasPrefix(const QChar* doc, int length, int pos, QChar c);
925
    bool hasPrefix(const QChar* doc, int length, int pos, const QString& s);
926
#ifndef QT_NO_TEXTCUSTOMITEM
927
    Q3TextCustomItem* parseTable(const QMap<QString, QString> &attr, const Q3TextFormat &fmt,
928
                                 const QChar* doc, int length, int& pos, Q3TextParagraph *curpar);
929
#endif
930
    bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = false);
931
    bool eat(const QChar* doc, int length, int& pos, QChar c);
932
    QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag);
933
    QString parseCloseTag(const QChar* doc, int length, int& pos);
934
    QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos);
935
    QString parseWord(const QChar* doc, int length, int& pos, bool lower = true);
936
    QChar parseChar(const QChar* doc, int length, int& pos, Q3StyleSheetItem::WhiteSpaceMode wsm);
937
    void setRichTextInternal(const QString &text, Q3TextCursor* cursor = 0, const Q3TextFormat *initialFormat = 0);
938
    void setRichTextMarginsInternal(QList< QVector<Q3StyleSheetItem *> *>& styles, Q3TextParagraph* stylesPar);
939
940
    struct Q_COMPAT_EXPORT Focus {
941
        Q3TextParagraph *parag;
942
        int start, len;
943
        QString href;
944
        QString name;
945
    };
946
947
    int cx, cy, cw, vw;
948
    Q3TextParagraph *fParag, *lParag;
949
    Q3TextPreProcessor *pProcessor;
950
    struct SelectionColor {
951
        QColor background;
952
        QColor text;
953
    };
954
    QMap<int, SelectionColor> selectionColors;
955
    QMap<int, Q3TextDocumentSelection> selections;
956
    Q3TextCommandHistory *commandHistory;
957
    Q3TextFormatter *pFormatter;
958
    Q3TextIndent *indenter;
959
    Q3TextFormatCollection *fCollection;
960
    Qt::TextFormat txtFormat;
961
    uint preferRichText : 1;
962
    uint pages : 1;
963
    uint useFC : 1;
964
    uint withoutDoubleBuffer : 1;
965
    uint underlLinks : 1;
966
    uint nextDoubleBuffered : 1;
967
    uint oTextValid : 1;
968
    uint mightHaveCustomItems : 1;
969
    int align;
970
    int nSelections;
971
    Q3TextFlow *flow_;
972
    Q3TextDocument *par;
973
    Q3TextParagraph *parentPar;
974
#ifndef QT_NO_TEXTCUSTOMITEM
975
    Q3TextTableCell *tc;
976
#endif
977
    QBrush *backBrush;
978
    QPixmap *buf_pixmap;
979
    Focus focusIndicator;
980
    int minw;
981
    int wused;
982
    int leftmargin;
983
    int rightmargin;
984
    Q3TextParagraph *minwParag, *curParag;
985
    Q3StyleSheet* sheet_;
986
#ifndef QT_NO_MIME
987
    Q3MimeSourceFactory* factory_;
988
#endif
989
    QString contxt;
990
    QMap<QString, QString> attribs;
991
    int *tArray;
992
    int tStopWidth;
993
    int uDepth;
994
    QString oText;
995
    QList<Q3TextDocument *> childList;
996
    QColor linkColor, bodyText;
997
    double scaleFontsFactor;
998
999
    short list_tm,list_bm, list_lm, li_tm, li_bm, par_tm, par_bm;
1000
};
1001
1002
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1003
1004
1005
class Q_COMPAT_EXPORT Q3TextDeleteCommand : public Q3TextCommand
1006
{
1007
public:
1008
    Q3TextDeleteCommand(Q3TextDocument *dc, int i, int idx, const QVector<Q3TextStringChar> &str,
1009
                        const QByteArray& oldStyle);
1010
    Q3TextDeleteCommand(Q3TextParagraph *p, int idx, const QVector<Q3TextStringChar> &str);
1011
    virtual ~Q3TextDeleteCommand();
1012
1013
    Commands type() const { return Delete; }
1014
    Q3TextCursor *execute(Q3TextCursor *c);
1015
    Q3TextCursor *unexecute(Q3TextCursor *c);
1016
1017
protected:
1018
    int id, index;
1019
    Q3TextParagraph *parag;
1020
    QVector<Q3TextStringChar> text;
1021
    QByteArray styleInformation;
1022
1023
};
1024
1025
class Q_COMPAT_EXPORT Q3TextInsertCommand : public Q3TextDeleteCommand
1026
{
1027
public:
1028
    Q3TextInsertCommand(Q3TextDocument *dc, int i, int idx, const QVector<Q3TextStringChar> &str,
1029
                        const QByteArray& oldStyleInfo)
1030
        : Q3TextDeleteCommand(dc, i, idx, str, oldStyleInfo) {}
1031
    Q3TextInsertCommand(Q3TextParagraph *p, int idx, const QVector<Q3TextStringChar> &str)
1032
        : Q3TextDeleteCommand(p, idx, str) {}
1033
    virtual ~Q3TextInsertCommand() {}
1034
1035
    Commands type() const { return Insert; }
1036
    Q3TextCursor *execute(Q3TextCursor *c) { return Q3TextDeleteCommand::unexecute(c); }
1037
    Q3TextCursor *unexecute(Q3TextCursor *c) { return Q3TextDeleteCommand::execute(c); }
1038
1039
};
1040
1041
class Q_COMPAT_EXPORT Q3TextFormatCommand : public Q3TextCommand
1042
{
1043
public:
1044
    Q3TextFormatCommand(Q3TextDocument *dc, int sid, int sidx, int eid, int eidx, const QVector<Q3TextStringChar> &old, Q3TextFormat *f, int fl);
1045
    virtual ~Q3TextFormatCommand();
1046
1047
    Commands type() const { return Format; }
1048
    Q3TextCursor *execute(Q3TextCursor *c);
1049
    Q3TextCursor *unexecute(Q3TextCursor *c);
1050
1051
protected:
1052
    int startId, startIndex, endId, endIndex;
1053
    Q3TextFormat *format;
1054
    QVector<Q3TextStringChar> oldFormats;
1055
    int flags;
1056
1057
};
1058
1059
class Q_COMPAT_EXPORT Q3TextStyleCommand : public Q3TextCommand
1060
{
1061
public:
1062
    Q3TextStyleCommand(Q3TextDocument *dc, int fParag, int lParag, const QByteArray& beforeChange );
1063
    virtual ~Q3TextStyleCommand() {}
1064
1065
    Commands type() const { return Style; }
1066
    Q3TextCursor *execute(Q3TextCursor *c);
1067
    Q3TextCursor *unexecute(Q3TextCursor *c);
1068
1069
    static QByteArray readStyleInformation( Q3TextDocument* dc, int fParag, int lParag);
1070
    static void writeStyleInformation( Q3TextDocument* dc, int fParag, const QByteArray& style);
1071
1072
private:
1073
    int firstParag, lastParag;
1074
    QByteArray before;
1075
    QByteArray after;
1076
};
1077
1078
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1079
1080
struct Q_COMPAT_EXPORT Q3TextParagraphSelection
1081
{
1082
    int start, end;
1083
    Q_DUMMY_COMPARISON_OPERATOR(Q3TextParagraphSelection)
1084
};
1085
1086
struct Q_COMPAT_EXPORT QTextLineStart
1087
{
1088
    QTextLineStart() : y(0), baseLine(0), h(0)
1089
    {  }
1090
    QTextLineStart(int y_, int bl, int h_) : y(y_), baseLine(bl), h(h_),
1091
        w(0)
1092
    {  }
1093
1094
public:
1095
    int y, baseLine, h;
1096
    int w;
1097
};
1098
1099
class Q_COMPAT_EXPORT Q3TextParagraphData
1100
{
1101
public:
1102
    Q3TextParagraphData() {}
1103
    virtual ~Q3TextParagraphData();
1104
    virtual void join(Q3TextParagraphData *);
1105
};
1106
1107
class Q3TextParagraphPseudoDocument;
1108
1109
class Q3SyntaxHighlighter;
1110
1111
class Q_COMPAT_EXPORT Q3TextParagraph
1112
{
1113
    friend class Q3TextDocument;
1114
    friend class Q3TextCursor;
1115
    friend class Q3SyntaxHighlighter;
1116
1117
public:
1118
    Q3TextParagraph(Q3TextDocument *dc, Q3TextParagraph *pr = 0, Q3TextParagraph *nx = 0, bool updateIds = true);
1119
    ~Q3TextParagraph();
1120
1121
    Q3TextString *string() const;
1122
    Q3TextStringChar *at(int i) const; // maybe remove later
1123
    int leftGap() const;
1124
    int length() const; // maybe remove later
1125
1126
    void setListStyle(Q3StyleSheetItem::ListStyle ls) { lstyle = ls; changed = true; }
1127
    Q3StyleSheetItem::ListStyle listStyle() const { return (Q3StyleSheetItem::ListStyle)lstyle; }
1128
    void setListItem(bool li);
1129
    bool isListItem() const { return litem; }
1130
    void setListValue(int v) { list_val = v; }
1131
    int listValue() const { return list_val > 0 ? list_val : -1; }
1132
1133
    void setListDepth(int depth);
1134
    int listDepth() const { return ldepth; }
1135
1136
//     void setFormat(Q3TextFormat *fm);
1137
//     Q3TextFormat *paragFormat() const;
1138
1139
    inline Q3TextDocument *document() const {
1140
        if (hasdoc) return (Q3TextDocument*) docOrPseudo;
1141
        return 0;
1142
    }
1143
    Q3TextParagraphPseudoDocument *pseudoDocument() const;
1144
1145
    QRect rect() const;
1146
    void setHeight(int h) { r.setHeight(h); }
1147
    void show();
1148
    void hide();
1149
    bool isVisible() const { return visible; }
1150
1151
    Q3TextParagraph *prev() const;
1152
    Q3TextParagraph *next() const;
1153
    void setPrev(Q3TextParagraph *s);
1154
    void setNext(Q3TextParagraph *s);
1155
1156
    void insert(int index, const QString &s);
1157
    void insert(int index, const QChar *unicode, int len);
1158
    void append(const QString &s, bool reallyAtEnd = false);
1159
    void truncate(int index);
1160
    void remove(int index, int len);
1161
    void join(Q3TextParagraph *s);
1162
1163
    void invalidate(int chr);
1164
1165
    void move(int &dy);
1166
    void format(int start = -1, bool doMove = true);
1167
1168
    bool isValid() const;
1169
    bool hasChanged() const;
1170
    void setChanged(bool b, bool recursive = false);
1171
1172
    int lineHeightOfChar(int i, int *bl = 0, int *y = 0) const;
1173
    Q3TextStringChar *lineStartOfChar(int i, int *index = 0, int *line = 0) const;
1174
    int lines() const;
1175
    Q3TextStringChar *lineStartOfLine(int line, int *index = 0) const;
1176
    int lineY(int l) const;
1177
    int lineBaseLine(int l) const;
1178
    int lineHeight(int l) const;
1179
    void lineInfo(int l, int &y, int &h, int &bl) const;
1180
1181
    void setSelection(int id, int start, int end);
1182
    void removeSelection(int id);
1183
    int selectionStart(int id) const;
1184
    int selectionEnd(int id) const;
1185
    bool hasSelection(int id) const;
1186
    bool hasAnySelection() const;
1187
    bool fullSelected(int id) const;
1188
1189
    void setEndState(int s);
1190
    int endState() const;
1191
1192
    void setParagId(int i);
1193
    int paragId() const;
1194
1195
    bool firstPreProcess() const;
1196
    void setFirstPreProcess(bool b);
1197
1198
    void indent(int *oldIndent = 0, int *newIndent = 0);
1199
1200
    void setExtraData(Q3TextParagraphData *data);
1201
    Q3TextParagraphData *extraData() const;
1202
1203
    QMap<int, QTextLineStart*> &lineStartList();
1204
1205
    void setFormat(int index, int len, Q3TextFormat *f, bool useCollection = true, int flags = -1);
1206
1207
    void setAlignment(int a);
1208
    int alignment() const;
1209
1210
    void paint(QPainter &painter, const QPalette &pal, Q3TextCursor *cursor = 0,
1211
                bool drawSelections = false, int clipx = -1, int clipy = -1,
1212
                int clipw = -1, int cliph = -1);
1213
1214
    int topMargin() const;
1215
    int bottomMargin() const;
1216
    int leftMargin() const;
1217
    int firstLineMargin() const;
1218
    int rightMargin() const;
1219
    int lineSpacing() const;
1220
1221
#ifndef QT_NO_TEXTCUSTOMITEM
1222
    void registerFloatingItem(Q3TextCustomItem *i);
1223
    void unregisterFloatingItem(Q3TextCustomItem *i);
1224
#endif
1225
1226
    void setFullWidth(bool b) { fullWidth = b; }
1227
    bool isFullWidth() const { return fullWidth; }
1228
1229
#ifndef QT_NO_TEXTCUSTOMITEM
1230
    Q3TextTableCell *tableCell() const;
1231
#endif
1232
1233
    QBrush *background() const;
1234
1235
    int documentWidth() const;
1236
    int documentVisibleWidth() const;
1237
    int documentX() const;
1238
    int documentY() const;
1239
    Q3TextFormatCollection *formatCollection() const;
1240
    Q3TextFormatter *formatter() const;
1241
1242
    int nextTab(int i, int x);
1243
    int *tabArray() const;
1244
    void setTabArray(int *a);
1245
    void setTabStops(int tw);
1246
1247
    void adjustToPainter(QPainter *p);
1248
1249
    void setNewLinesAllowed(bool b);
1250
    bool isNewLinesAllowed() const;
1251
1252
    QString richText() const;
1253
1254
    void addCommand(Q3TextCommand *cmd);
1255
    Q3TextCursor *undo(Q3TextCursor *c = 0);
1256
    Q3TextCursor *redo(Q3TextCursor *c  = 0);
1257
    Q3TextCommandHistory *commands() const;
1258
    void copyParagData(Q3TextParagraph *parag);
1259
1260
    void setBreakable(bool b) { breakable = b; }
1261
    bool isBreakable() const { return breakable; }
1262
1263
    void setBackgroundColor(const QColor &c);
1264
    QColor *backgroundColor() const { return bgcol; }
1265
    void clearBackgroundColor();
1266
1267
    void setMovedDown(bool b) { movedDown = b; }
1268
    bool wasMovedDown() const { return movedDown; }
1269
1270
    void setDirection(QChar::Direction);
1271
    QChar::Direction direction() const;
1272
    void setPaintDevice(QPaintDevice *pd) { paintdevice = pd; }
1273
1274
    void readStyleInformation(QDataStream& stream);
1275
    void writeStyleInformation(QDataStream& stream) const;
1276
1277
protected:
1278
    void setColorForSelection(QColor &c, QPainter &p, const QPalette &pal, int selection);
1279
    void drawLabel(QPainter* p, int x, int y, int w, int h, int base, const QPalette &pal);
1280
    void drawString(QPainter &painter, const QString &str, int start, int len, int xstart,
1281
                             int y, int baseLine, int w, int h, bool drawSelections, int fullSelectionWidth,
1282
                             Q3TextStringChar *formatChar, const QPalette &pal,
1283
                             bool rightToLeft);
1284
1285
private:
1286
    QMap<int, Q3TextParagraphSelection> &selections() const;
1287
#ifndef QT_NO_TEXTCUSTOMITEM
1288
    QList<Q3TextCustomItem *> &floatingItems() const;
1289
#endif
1290
    inline QBrush backgroundBrush(const QPalette &pal) {
1291
        if (bgcol)
1292
            return *bgcol;
1293
        return pal.brush(QPalette::Base);
1294
    }
1295
    void invalidateStyleCache();
1296
1297
    QMap<int, QTextLineStart*> lineStarts;
1298
    QRect r;
1299
    Q3TextParagraph *p, *n;
1300
    void *docOrPseudo;
1301
    uint changed : 1;
1302
    uint firstFormat : 1;
1303
    uint firstPProcess : 1;
1304
    uint needPreProcess : 1;
1305
    uint fullWidth : 1;
1306
    uint lastInFrame : 1;
1307
    uint visible : 1;
1308
    uint breakable : 1;
1309
    uint movedDown : 1;
1310
    uint mightHaveCustomItems : 1;
1311
    uint hasdoc : 1;
1312
    uint litem : 1; // whether the paragraph is a list item
1313
    uint rtext : 1; // whether the paragraph needs rich text margin
1314
    signed int align : 5;
1315
    uint /*Q3StyleSheetItem::ListStyle*/ lstyle : 4;
1316
    int invalid;
1317
    int state, id;
1318
    Q3TextString *str;
1319
    QMap<int, Q3TextParagraphSelection> *mSelections;
1320
#ifndef QT_NO_TEXTCUSTOMITEM
1321
    QList<Q3TextCustomItem *> *mFloatingItems;
1322
#endif
1323
    short utm, ubm, ulm, urm, uflm, ulinespacing;
1324
    short tabStopWidth, minwidth;
1325
    int *tArray;
1326
    Q3TextParagraphData *eData;
1327
    short list_val;
1328
    ushort ldepth;
1329
    QColor *bgcol;
1330
    QPaintDevice *paintdevice;
1331
};
1332
1333
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1334
1335
class Q_COMPAT_EXPORT Q3TextFormatter
1336
{
1337
public:
1338
    Q3TextFormatter();
1339
    virtual ~Q3TextFormatter();
1340
1341
    virtual int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts) = 0;
1342
    virtual int formatVertically(Q3TextDocument* doc, Q3TextParagraph* parag);
1343
1344
    bool isWrapEnabled(Q3TextParagraph *p) const { if (!wrapEnabled) return false; if (p && !p->isBreakable()) return false; return true;}
1345
    int wrapAtColumn() const { return wrapColumn;}
1346
    virtual void setWrapEnabled(bool b);
1347
    virtual void setWrapAtColumn(int c);
1348
    virtual void setAllowBreakInWords(bool b) { biw = b; }
1349
    bool allowBreakInWords() const { return biw; }
1350
1351
    int minimumWidth() const { return thisminw; }
1352
    int widthUsed() const { return thiswused; }
1353
1354
protected:
1355
    virtual QTextLineStart *formatLine(Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start,
1356
                                               Q3TextStringChar *last, int align = Qt::AlignAuto, int space = 0);
1357
#ifndef QT_NO_COMPLEXTEXT
1358
    virtual QTextLineStart *bidiReorderLine(Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start,
1359
                                                    Q3TextStringChar *last, int align, int space);
1360
#endif
1361
    void insertLineStart(Q3TextParagraph *parag, int index, QTextLineStart *ls);
1362
1363
    int thisminw;
1364
    int thiswused;
1365
1366
private:
1367
    bool wrapEnabled;
1368
    int wrapColumn;
1369
    bool biw;
1370
};
1371
1372
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1373
1374
class Q_COMPAT_EXPORT Q3TextFormatterBreakInWords : public Q3TextFormatter
1375
{
1376
public:
1377
    Q3TextFormatterBreakInWords();
1378
    virtual ~Q3TextFormatterBreakInWords() {}
1379
1380
    int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
1381
1382
};
1383
1384
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1385
1386
class Q_COMPAT_EXPORT Q3TextFormatterBreakWords : public Q3TextFormatter
1387
{
1388
public:
1389
    Q3TextFormatterBreakWords();
1390
    virtual ~Q3TextFormatterBreakWords() {}
1391
1392
    int format(Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap<int, QTextLineStart*> &oldLineStarts);
1393
1394
};
1395
1396
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1397
1398
class Q_COMPAT_EXPORT Q3TextIndent
1399
{
1400
public:
1401
    Q3TextIndent();
1402
    virtual ~Q3TextIndent() {}
1403
1404
    virtual void indent(Q3TextDocument *doc, Q3TextParagraph *parag, int *oldIndent = 0, int *newIndent = 0) = 0;
1405
1406
};
1407
1408
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1409
1410
class Q_COMPAT_EXPORT Q3TextPreProcessor
1411
{
1412
public:
1413
    enum Ids {
1414
        Standard = 0
1415
    };
1416
1417
    Q3TextPreProcessor();
1418
    virtual ~Q3TextPreProcessor() {}
1419
1420
    virtual void process(Q3TextDocument *doc, Q3TextParagraph *, int, bool = true) = 0;
1421
    virtual Q3TextFormat *format(int id) = 0;
1422
1423
};
1424
1425
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1426
1427
class Q_COMPAT_EXPORT Q3TextFormat
1428
{
1429
    friend class Q3TextFormatCollection;
1430
    friend class Q3TextDocument;
1431
1432
public:
1433
    enum Flags {
1434
        NoFlags,
1435
        Bold = 1,
1436
        Italic = 2,
1437
        Underline = 4,
1438
        Family = 8,
1439
        Size = 16,
1440
        Color = 32,
1441
        Misspelled = 64,
1442
        VAlign = 128,
1443
        StrikeOut= 256,
1444
        Font = Bold | Italic | Underline | Family | Size | StrikeOut,
1445
        Format = Font | Color | Misspelled | VAlign
1446
    };
1447
1448
    enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript };
1449
1450
    Q3TextFormat();
1451
    virtual ~Q3TextFormat();
1452
1453
    Q3TextFormat(const Q3StyleSheetItem *s);
1454
    Q3TextFormat(const QFont &f, const QColor &c, Q3TextFormatCollection *parent = 0);
1455
    Q3TextFormat(const Q3TextFormat &fm);
1456
    Q3TextFormat makeTextFormat(const Q3StyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor) const;
1457
    Q3TextFormat& operator=(const Q3TextFormat &fm);
1458
    QColor color() const;
1459
    QFont font() const;
1460
    QFontMetrics fontMetrics() const { return fm; }
1461
    bool isMisspelled() const;
1462
    VerticalAlignment vAlign() const;
1463
    int minLeftBearing() const;
1464
    int minRightBearing() const;
1465
    int width(const QChar &c) const;
1466
    int width(const QString &str, int pos) const;
1467
    int height() const;
1468
    int ascent() const;
1469
    int descent() const;
1470
    int leading() const;
1471
    bool useLinkColor() const;
1472
1473
    void setBold(bool b);
1474
    void setItalic(bool b);
1475
    void setUnderline(bool b);
1476
    void setStrikeOut(bool b);
1477
    void setFamily(const QString &f);
1478
    void setPointSize(int s);
1479
    void setFont(const QFont &f);
1480
    void setColor(const QColor &c);
1481
    void setMisspelled(bool b);
1482
    void setVAlign(VerticalAlignment a);
1483
1484
    bool operator==(const Q3TextFormat &f) const;
1485
    Q3TextFormatCollection *parent() const;
1486
    const QString &key() const;
1487
1488
    static QString getKey(const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign);
1489
1490
    void addRef();
1491
    void removeRef();
1492
1493
    QString makeFormatChangeTags(Q3TextFormat* defaultFormat, Q3TextFormat *f, const QString& oldAnchorHref, const QString& anchorHref) const;
1494
    QString makeFormatEndTags(Q3TextFormat* defaultFormat, const QString& anchorHref) const;
1495
1496
    static void setPainter(QPainter *p);
1497
    static QPainter* painter();
1498
1499
    bool fontSizesInPixels() { return usePixelSizes; }
1500
1501
protected:
1502
    virtual void generateKey();
1503
1504
private:
1505
    void update();
1506
    static void applyFont(const QFont &f);
1507
1508
private:
1509
    QFont fn;
1510
    QColor col;
1511
    QFontMetrics fm;
1512
    uint missp : 1;
1513
    uint linkColor : 1;
1514
    uint usePixelSizes : 1;
1515
    int leftBearing, rightBearing;
1516
    VerticalAlignment ha;
1517
    uchar widths[256];
1518
    int hei, asc, dsc;
1519
    Q3TextFormatCollection *collection;
1520
    int ref;
1521
    QString k;
1522
    int logicalFontSize;
1523
    int stdSize;
1524
    static QPainter *pntr;
1525
    static QFontMetrics *pntr_fm;
1526
    static int pntr_asc;
1527
    static int pntr_hei;
1528
    static int pntr_ldg;
1529
    static int pntr_dsc;
1530
1531
};
1532
1533
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1534
1535
class Q_COMPAT_EXPORT Q3TextFormatCollection
1536
{
1537
    friend class Q3TextDocument;
1538
    friend class Q3TextFormat;
1539
1540
public:
1541
    Q3TextFormatCollection();
1542
    virtual ~Q3TextFormatCollection();
1543
1544
    void setDefaultFormat(Q3TextFormat *f);
1545
    Q3TextFormat *defaultFormat() const;
1546
    virtual Q3TextFormat *format(Q3TextFormat *f);
1547
    virtual Q3TextFormat *format(Q3TextFormat *of, Q3TextFormat *nf, int flags);
1548
    virtual Q3TextFormat *format(const QFont &f, const QColor &c);
1549
    virtual void remove(Q3TextFormat *f);
1550
    virtual Q3TextFormat *createFormat(const Q3TextFormat &f) { return new Q3TextFormat(f); }
1551
    virtual Q3TextFormat *createFormat(const QFont &f, const QColor &c) { return new Q3TextFormat(f, c, this); }
1552
1553
    void updateDefaultFormat(const QFont &font, const QColor &c, Q3StyleSheet *sheet);
1554
1555
    QPaintDevice *paintDevice() const { return paintdevice; }
1556
    void setPaintDevice(QPaintDevice *);
1557
1558
private:
1559
    void updateKeys();
1560
1561
private:
1562
    Q3TextFormat *defFormat, *lastFormat, *cachedFormat;
1563
    QHash<QString, Q3TextFormat *> cKey;
1564
    Q3TextFormat *cres;
1565
    QFont cfont;
1566
    QColor ccol;
1567
    QString kof, knf;
1568
    int cflags;
1569
1570
    QPaintDevice *paintdevice;
1571
};
1572
1573
class Q_COMPAT_EXPORT Q3TextParagraphPseudoDocument
1574
{
1575
public:
1576
    Q3TextParagraphPseudoDocument();
1577
    ~Q3TextParagraphPseudoDocument();
1578
    QRect docRect;
1579
    Q3TextFormatter *pFormatter;
1580
    Q3TextCommandHistory *commandHistory;
1581
    int minw;
1582
    int wused;
1583
    Q3TextFormatCollection collection;
1584
};
1585
1586
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1587
1588
inline int Q3TextParagraph::length() const
1589
{
1590
    return str->length();
1591
}
1592
1593
inline QRect Q3TextParagraph::rect() const
1594
{
1595
    return r;
1596
}
1597
1598
inline int Q3TextCursor::index() const
1599
{
1600
    return idx;
1601
}
1602
1603
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1604
1605
inline int Q3TextDocument::x() const
1606
{
1607
    return cx;
1608
}
1609
1610
inline int Q3TextDocument::y() const
1611
{
1612
    return cy;
1613
}
1614
1615
inline int Q3TextDocument::width() const
1616
{
1617
    return qMax(cw, flow_->width());
1618
}
1619
1620
inline int Q3TextDocument::visibleWidth() const
1621
{
1622
    return vw;
1623
}
1624
1625
inline Q3TextParagraph *Q3TextDocument::firstParagraph() const
1626
{
1627
    return fParag;
1628
}
1629
1630
inline Q3TextParagraph *Q3TextDocument::lastParagraph() const
1631
{
1632
    return lParag;
1633
}
1634
1635
inline void Q3TextDocument::setFirstParagraph(Q3TextParagraph *p)
1636
{
1637
    fParag = p;
1638
}
1639
1640
inline void Q3TextDocument::setLastParagraph(Q3TextParagraph *p)
1641
{
1642
    lParag = p;
1643
}
1644
1645
inline void Q3TextDocument::setWidth(int w)
1646
{
1647
    cw = qMax(w, minw);
1648
    flow_->setWidth(cw);
1649
    vw = w;
1650
}
1651
1652
inline int Q3TextDocument::minimumWidth() const
1653
{
1654
    return minw;
1655
}
1656
1657
inline void Q3TextDocument::setY(int y)
1658
{
1659
    cy = y;
1660
}
1661
1662
inline int Q3TextDocument::leftMargin() const
1663
{
1664
    return leftmargin;
1665
}
1666
1667
inline void Q3TextDocument::setLeftMargin(int lm)
1668
{
1669
    leftmargin = lm;
1670
}
1671
1672
inline int Q3TextDocument::rightMargin() const
1673
{
1674
    return rightmargin;
1675
}
1676
1677
inline void Q3TextDocument::setRightMargin(int rm)
1678
{
1679
    rightmargin = rm;
1680
}
1681
1682
inline Q3TextPreProcessor *Q3TextDocument::preProcessor() const
1683
{
1684
    return pProcessor;
1685
}
1686
1687
inline void Q3TextDocument::setPreProcessor(Q3TextPreProcessor * sh)
1688
{
1689
    pProcessor = sh;
1690
}
1691
1692
inline void Q3TextDocument::setFormatter(Q3TextFormatter *f)
1693
{
1694
    delete pFormatter;
1695
    pFormatter = f;
1696
}
1697
1698
inline Q3TextFormatter *Q3TextDocument::formatter() const
1699
{
1700
    return pFormatter;
1701
}
1702
1703
inline void Q3TextDocument::setIndent(Q3TextIndent *i)
1704
{
1705
    indenter = i;
1706
}
1707
1708
inline Q3TextIndent *Q3TextDocument::indent() const
1709
{
1710
    return indenter;
1711
}
1712
1713
inline QColor Q3TextDocument::selectionColor(int id) const
1714
{
1715
    const Q3TextDocument *p = this;
1716
    while (p->par)
1717
        p = p->par;
1718
    return p->selectionColors[id].background;
1719
}
1720
1721
inline QColor Q3TextDocument::selectionTextColor(int id) const
1722
{
1723
    const Q3TextDocument *p = this;
1724
    while (p->par)
1725
        p = p->par;
1726
    return p->selectionColors[id].text;
1727
}
1728
1729
inline bool Q3TextDocument::hasSelectionTextColor(int id) const
1730
{
1731
    const Q3TextDocument *p = this;
1732
    while (p->par)
1733
        p = p->par;
1734
    return p->selectionColors.contains(id);
1735
}
1736
1737
inline void Q3TextDocument::setSelectionColor(int id, const QColor &c)
1738
{
1739
    Q3TextDocument *p = this;
1740
    while (p->par)
1741
        p = p->par;
1742
    p->selectionColors[id].background = c;
1743
}
1744
1745
inline void Q3TextDocument::setSelectionTextColor(int id, const QColor &c)
1746
{
1747
    Q3TextDocument *p = this;
1748
    while (p->par)
1749
        p = p->par;
1750
    p->selectionColors[id].text = c;
1751
}
1752
1753
inline Q3TextFormatCollection *Q3TextDocument::formatCollection() const
1754
{
1755
    return fCollection;
1756
}
1757
1758
inline int Q3TextDocument::alignment() const
1759
{
1760
    return align;
1761
}
1762
1763
inline void Q3TextDocument::setAlignment(int a)
1764
{
1765
    align = a;
1766
}
1767
1768
inline int *Q3TextDocument::tabArray() const
1769
{
1770
    return tArray;
1771
}
1772
1773
inline int Q3TextDocument::tabStopWidth() const
1774
{
1775
    return tStopWidth;
1776
}
1777
1778
inline void Q3TextDocument::setTabArray(int *a)
1779
{
1780
    tArray = a;
1781
}
1782
1783
inline void Q3TextDocument::setTabStops(int tw)
1784
{
1785
    tStopWidth = tw;
1786
}
1787
1788
inline QString Q3TextDocument::originalText() const
1789
{
1790
    if (oTextValid)
1791
        return oText;
1792
    return text();
1793
}
1794
1795
inline void Q3TextDocument::setFlow(Q3TextFlow *f)
1796
{
1797
    if (flow_)
1798
        delete flow_;
1799
    flow_ = f;
1800
}
1801
1802
inline void Q3TextDocument::takeFlow()
1803
{
1804
    flow_ = 0;
1805
}
1806
1807
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1808
1809
inline QColor Q3TextFormat::color() const
1810
{
1811
    return col;
1812
}
1813
1814
inline QFont Q3TextFormat::font() const
1815
{
1816
    return fn;
1817
}
1818
1819
inline bool Q3TextFormat::isMisspelled() const
1820
{
1821
    return missp;
1822
}
1823
1824
inline Q3TextFormat::VerticalAlignment Q3TextFormat::vAlign() const
1825
{
1826
    return ha;
1827
}
1828
1829
inline bool Q3TextFormat::operator==(const Q3TextFormat &f) const
1830
{
1831
    return k == f.k;
1832
}
1833
1834
inline Q3TextFormatCollection *Q3TextFormat::parent() const
1835
{
1836
    return collection;
1837
}
1838
1839
inline void Q3TextFormat::addRef()
1840
{
1841
    ref++;
1842
}
1843
1844
inline void Q3TextFormat::removeRef()
1845
{
1846
    ref--;
1847
    if (!collection)
1848
        return;
1849
    if (this == collection->defFormat)
1850
        return;
1851
    if (ref == 0)
1852
        collection->remove(this);
1853
}
1854
1855
inline const QString &Q3TextFormat::key() const
1856
{
1857
    return k;
1858
}
1859
1860
inline bool Q3TextFormat::useLinkColor() const
1861
{
1862
    return linkColor;
1863
}
1864
1865
inline Q3TextStringChar *Q3TextParagraph::at(int i) const
1866
{
1867
    return &str->at(i);
1868
}
1869
1870
inline bool Q3TextParagraph::isValid() const
1871
{
1872
    return invalid == -1;
1873
}
1874
1875
inline bool Q3TextParagraph::hasChanged() const
1876
{
1877
    return changed;
1878
}
1879
1880
inline void Q3TextParagraph::setBackgroundColor(const QColor & c)
1881
{
1882
    delete bgcol;
1883
    bgcol = new QColor(c);
1884
    setChanged(true);
1885
}
1886
1887
inline void Q3TextParagraph::clearBackgroundColor()
1888
{
1889
    delete bgcol; bgcol = 0; setChanged(true);
1890
}
1891
1892
inline void Q3TextParagraph::append(const QString &s, bool reallyAtEnd)
1893
{
1894
    if (reallyAtEnd) {
1895
        insert(str->length(), s);
1896
    } else {
1897
        int str_end = str->length() - 1;
1898
        insert(str_end > 0 ? str_end : 0, s);
1899
    }
1900
}
1901
1902
inline Q3TextParagraph *Q3TextParagraph::prev() const
1903
{
1904
    return p;
1905
}
1906
1907
inline Q3TextParagraph *Q3TextParagraph::next() const
1908
{
1909
    return n;
1910
}
1911
1912
inline bool Q3TextParagraph::hasAnySelection() const
1913
{
1914
    return mSelections ? !selections().isEmpty() : false;
1915
}
1916
1917
inline void Q3TextParagraph::setEndState(int s)
1918
{
1919
    if (s == state)
1920
        return;
1921
    state = s;
1922
}
1923
1924
inline int Q3TextParagraph::endState() const
1925
{
1926
    return state;
1927
}
1928
1929
inline void Q3TextParagraph::setParagId(int i)
1930
{
1931
    id = i;
1932
}
1933
1934
inline int Q3TextParagraph::paragId() const
1935
{
1936
    if (id == -1)
1937
        qWarning("invalid parag id!!!!!!!! (%p)", (void*)this);
1938
    return id;
1939
}
1940
1941
inline bool Q3TextParagraph::firstPreProcess() const
1942
{
1943
    return firstPProcess;
1944
}
1945
1946
inline void Q3TextParagraph::setFirstPreProcess(bool b)
1947
{
1948
    firstPProcess = b;
1949
}
1950
1951
inline QMap<int, QTextLineStart*> &Q3TextParagraph::lineStartList()
1952
{
1953
    return lineStarts;
1954
}
1955
1956
inline Q3TextString *Q3TextParagraph::string() const
1957
{
1958
    return str;
1959
}
1960
1961
inline Q3TextParagraphPseudoDocument *Q3TextParagraph::pseudoDocument() const
1962
{
1963
    if (hasdoc)
1964
        return 0;
1965
    return (Q3TextParagraphPseudoDocument*) docOrPseudo;
1966
}
1967
1968
1969
#ifndef QT_NO_TEXTCUSTOMITEM
1970
inline Q3TextTableCell *Q3TextParagraph::tableCell() const
1971
{
1972
    return hasdoc ? document()->tableCell () : 0;
1973
}
1974
#endif
1975
1976
inline Q3TextCommandHistory *Q3TextParagraph::commands() const
1977
{
1978
    return hasdoc ? document()->commands() : pseudoDocument()->commandHistory;
1979
}
1980
1981
1982
inline int Q3TextParagraph::alignment() const
1983
{
1984
    return align;
1985
}
1986
1987
#ifndef QT_NO_TEXTCUSTOMITEM
1988
inline void Q3TextParagraph::registerFloatingItem(Q3TextCustomItem *i)
1989
{
1990
    floatingItems().append(i);
1991
}
1992
1993
inline void Q3TextParagraph::unregisterFloatingItem(Q3TextCustomItem *i)
1994
{
1995
    floatingItems().removeAll(i);
1996
}
1997
#endif
1998
1999
inline QBrush *Q3TextParagraph::background() const
2000
{
2001
#ifndef QT_NO_TEXTCUSTOMITEM
2002
    return tableCell() ? tableCell()->backGround() : 0;
2003
#else
2004
    return 0;
2005
#endif
2006
}
2007
2008
inline int Q3TextParagraph::documentWidth() const
2009
{
2010
    return hasdoc ? document()->width() : pseudoDocument()->docRect.width();
2011
}
2012
2013
inline int Q3TextParagraph::documentVisibleWidth() const
2014
{
2015
    return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width();
2016
}
2017
2018
inline int Q3TextParagraph::documentX() const
2019
{
2020
    return hasdoc ? document()->x() : pseudoDocument()->docRect.x();
2021
}
2022
2023
inline int Q3TextParagraph::documentY() const
2024
{
2025
    return hasdoc ? document()->y() : pseudoDocument()->docRect.y();
2026
}
2027
2028
inline void Q3TextParagraph::setExtraData(Q3TextParagraphData *data)
2029
{
2030
    eData = data;
2031
}
2032
2033
inline Q3TextParagraphData *Q3TextParagraph::extraData() const
2034
{
2035
    return eData;
2036
}
2037
2038
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2039
2040
inline void Q3TextFormatCollection::setDefaultFormat(Q3TextFormat *f)
2041
{
2042
    defFormat = f;
2043
}
2044
2045
inline Q3TextFormat *Q3TextFormatCollection::defaultFormat() const
2046
{
2047
    return defFormat;
2048
}
2049
2050
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2051
2052
inline Q3TextFormat *Q3TextStringChar::format() const
2053
{
2054
    return (type == Regular) ? p.format : p.custom->format;
2055
}
2056
2057
2058
#ifndef QT_NO_TEXTCUSTOMITEM
2059
inline Q3TextCustomItem *Q3TextStringChar::customItem() const
2060
{
2061
    return isCustom() ? p.custom->custom : 0;
2062
}
2063
#endif
2064
2065
inline int Q3TextStringChar::height() const
2066
{
2067
#ifndef QT_NO_TEXTCUSTOMITEM
2068
    return !isCustom() ? format()->height() : (customItem()->placement() == Q3TextCustomItem::PlaceInline ? customItem()->height : 0);
2069
#else
2070
    return format()->height();
2071
#endif
2072
}
2073
2074
inline int Q3TextStringChar::ascent() const
2075
{
2076
#ifndef QT_NO_TEXTCUSTOMITEM
2077
    return !isCustom() ? format()->ascent() : (customItem()->placement() == Q3TextCustomItem::PlaceInline ? customItem()->ascent() : 0);
2078
#else
2079
    return format()->ascent();
2080
#endif
2081
}
2082
2083
inline int Q3TextStringChar::descent() const
2084
{
2085
#ifndef QT_NO_TEXTCUSTOMITEM
2086
    return !isCustom() ? format()->descent() : 0;
2087
#else
2088
    return format()->descent();
2089
#endif
2090
}
2091
2092
#endif // QT_NO_RICHTEXT
2093
2094
#endif // Q3RICHTEXT_P_H