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