DirectWrite font engine: don't leak the font table buffer
[profile/ivi/qtbase.git] / src / gui / text / qtextdocument.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QTEXTDOCUMENT_H
43 #define QTEXTDOCUMENT_H
44
45 #include <QtCore/qobject.h>
46 #include <QtCore/qsize.h>
47 #include <QtCore/qrect.h>
48 #include <QtCore/qvariant.h>
49 #include <QtGui/qfont.h>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55
56 class QTextFormatCollection;
57 class QTextListFormat;
58 class QRect;
59 class QPainter;
60 class QPagedPaintDevice;
61 class QAbstractTextDocumentLayout;
62 class QPoint;
63 class QTextObject;
64 class QTextFormat;
65 class QTextFrame;
66 class QTextBlock;
67 class QTextCodec;
68 class QUrl;
69 class QVariant;
70 class QRectF;
71 class QTextOption;
72 class QTextCursor;
73
74 template<typename T> class QVector;
75
76 namespace Qt
77 {
78     enum HitTestAccuracy { ExactHit, FuzzyHit };
79     enum WhiteSpaceMode {
80         WhiteSpaceNormal,
81         WhiteSpacePre,
82         WhiteSpaceNoWrap,
83         WhiteSpaceModeUndefined = -1
84     };
85
86     Q_GUI_EXPORT bool mightBeRichText(const QString&);
87     Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode = WhiteSpacePre);
88
89 #ifndef QT_NO_TEXTCODEC
90     Q_GUI_EXPORT QTextCodec *codecForHtml(const QByteArray &ba);
91 #endif
92 }
93
94 class Q_GUI_EXPORT QAbstractUndoItem
95 {
96 public:
97     virtual ~QAbstractUndoItem() = 0;
98     virtual void undo() = 0;
99     virtual void redo() = 0;
100 };
101
102 inline QAbstractUndoItem::~QAbstractUndoItem()
103 {
104 }
105
106 class QTextDocumentPrivate;
107
108 class Q_GUI_EXPORT QTextDocument : public QObject
109 {
110     Q_OBJECT
111
112     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
113     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
114     Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
115     Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
116     Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
117     Q_PROPERTY(QSizeF size READ size)
118     Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
119     Q_PROPERTY(int blockCount READ blockCount)
120     Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
121 #ifndef QT_NO_CSSPARSER
122     Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
123 #endif
124     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
125     Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
126     QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
127
128 public:
129     explicit QTextDocument(QObject *parent = 0);
130     explicit QTextDocument(const QString &text, QObject *parent = 0);
131     ~QTextDocument();
132
133     QTextDocument *clone(QObject *parent = 0) const;
134
135     bool isEmpty() const;
136     virtual void clear();
137
138     void setUndoRedoEnabled(bool enable);
139     bool isUndoRedoEnabled() const;
140
141     bool isUndoAvailable() const;
142     bool isRedoAvailable() const;
143
144     int availableUndoSteps() const;
145     int availableRedoSteps() const;
146
147     int revision() const;
148
149     void setDocumentLayout(QAbstractTextDocumentLayout *layout);
150     QAbstractTextDocumentLayout *documentLayout() const;
151
152     enum MetaInformation {
153         DocumentTitle,
154         DocumentUrl
155     };
156     void setMetaInformation(MetaInformation info, const QString &);
157     QString metaInformation(MetaInformation info) const;
158
159 #ifndef QT_NO_TEXTHTMLPARSER
160     QString toHtml(const QByteArray &encoding = QByteArray()) const;
161     void setHtml(const QString &html);
162 #endif
163
164     QString toPlainText() const;
165     void setPlainText(const QString &text);
166
167     QChar characterAt(int pos) const;
168
169     enum FindFlag
170     {
171         FindBackward        = 0x00001,
172         FindCaseSensitively = 0x00002,
173         FindWholeWords      = 0x00004
174     };
175     Q_DECLARE_FLAGS(FindFlags, FindFlag)
176
177     QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
178     QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
179
180     QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
181     QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
182
183     QTextFrame *frameAt(int pos) const;
184     QTextFrame *rootFrame() const;
185
186     QTextObject *object(int objectIndex) const;
187     QTextObject *objectForFormat(const QTextFormat &) const;
188
189     QTextBlock findBlock(int pos) const;
190     QTextBlock findBlockByNumber(int blockNumber) const;
191     QTextBlock findBlockByLineNumber(int blockNumber) const;
192     QTextBlock begin() const;
193     QTextBlock end() const;
194
195     QTextBlock firstBlock() const;
196     QTextBlock lastBlock() const;
197
198     void setPageSize(const QSizeF &size);
199     QSizeF pageSize() const;
200
201     void setDefaultFont(const QFont &font);
202     QFont defaultFont() const;
203
204     int pageCount() const;
205
206     bool isModified() const;
207
208     void print(QPagedPaintDevice *printer) const;
209
210     enum ResourceType {
211         HtmlResource  = 1,
212         ImageResource = 2,
213         StyleSheetResource = 3,
214
215         UserResource  = 100
216     };
217
218     QVariant resource(int type, const QUrl &name) const;
219     void addResource(int type, const QUrl &name, const QVariant &resource);
220
221     QVector<QTextFormat> allFormats() const;
222
223     void markContentsDirty(int from, int length);
224
225     void setUseDesignMetrics(bool b);
226     bool useDesignMetrics() const;
227
228     void drawContents(QPainter *painter, const QRectF &rect = QRectF());
229
230     void setTextWidth(qreal width);
231     qreal textWidth() const;
232
233     qreal idealWidth() const;
234
235     qreal indentWidth() const;
236     void setIndentWidth(qreal width);
237
238     qreal documentMargin() const;
239     void setDocumentMargin(qreal margin);
240
241     void adjustSize();
242     QSizeF size() const;
243
244     int blockCount() const;
245     int lineCount() const;
246     int characterCount() const;
247
248 #ifndef QT_NO_CSSPARSER
249     void setDefaultStyleSheet(const QString &sheet);
250     QString defaultStyleSheet() const;
251 #endif
252
253     void undo(QTextCursor *cursor);
254     void redo(QTextCursor *cursor);
255
256     enum Stacks {
257         UndoStack = 0x01,
258         RedoStack = 0x02,
259         UndoAndRedoStacks = UndoStack | RedoStack
260     };
261     void clearUndoRedoStacks(Stacks historyToClear = UndoAndRedoStacks);
262
263     int maximumBlockCount() const;
264     void setMaximumBlockCount(int maximum);
265
266     QTextOption defaultTextOption() const;
267     void setDefaultTextOption(const QTextOption &option);
268
269     Qt::CursorMoveStyle defaultCursorMoveStyle() const;
270     void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
271
272 Q_SIGNALS:
273     void contentsChange(int from, int charsRemoves, int charsAdded);
274     void contentsChanged();
275     void undoAvailable(bool);
276     void redoAvailable(bool);
277     void undoCommandAdded();
278     void modificationChanged(bool m);
279     void cursorPositionChanged(const QTextCursor &cursor);
280     void blockCountChanged(int newBlockCount);
281
282     void documentLayoutChanged();
283
284 public Q_SLOTS:
285     void undo();
286     void redo();
287     void appendUndoItem(QAbstractUndoItem *);
288     void setModified(bool m = true);
289
290 protected:
291     virtual QTextObject *createObject(const QTextFormat &f);
292     Q_INVOKABLE virtual QVariant loadResource(int type, const QUrl &name);
293
294     QTextDocument(QTextDocumentPrivate &dd, QObject *parent);
295 public:
296     QTextDocumentPrivate *docHandle() const;
297 private:
298     Q_DISABLE_COPY(QTextDocument)
299     Q_DECLARE_PRIVATE(QTextDocument)
300     friend class QTextObjectPrivate;
301 };
302
303 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags)
304
305 QT_END_NAMESPACE
306
307 QT_END_HEADER
308
309 #endif // QTEXTDOCUMENT_H