1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.textobject;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.list;
19 import qt.core.namespace;
20 import qt.core.object;
21 import qt.core.string;
22 import qt.core.typeinfo;
23 import qt.core.vector;
24 import qt.gui.textcursor;
25 import qt.gui.textdocument;
26 import qt.gui.textformat;
27 import qt.gui.textlayout;
28 import qt.gui.textlist;
29 import qt.helpers;
30 version(QT_NO_RAWFONT){}else
31     import qt.gui.glyphrun;
32 
33 extern(C++, class) struct QTextObjectPrivate;
34 /+ class QTextDocument;
35 class QTextDocumentPrivate;
36 class QTextCursor;
37 class QTextBlock;
38 class QTextFragment;
39 class QTextList; +/
40 
41 class /+ Q_GUI_EXPORT +/ QTextObject : QObject
42 {
43     mixin(Q_OBJECT);
44 
45 protected:
46     /+ explicit +/this(QTextDocument doc);
47     mixin(mangleWindows("??1QTextObject@@MEAA@XZ", q{
48     public ~this();
49 	}));
50 
51     final void setFormat(ref const(QTextFormat) format);
52 
53 public:
54     final QTextFormat format() const;
55     final int formatIndex() const;
56 
57     final QTextDocument document() const;
58 
59     final int objectIndex() const;
60 
61     final QTextDocumentPrivate* docHandle() const;
62 
63 protected:
64     this(ref QTextObjectPrivate p, QTextDocument doc);
65 
66 private:
67     /+ Q_DECLARE_PRIVATE(QTextObject) +/
68     /+ Q_DISABLE_COPY(QTextObject) +/
69     /+ friend class QTextDocumentPrivate; +/
70 }
71 
72 extern(C++, class) struct QTextBlockGroupPrivate;
73 class /+ Q_GUI_EXPORT +/ QTextBlockGroup : QTextObject
74 {
75     mixin(Q_OBJECT);
76 
77 protected:
78     /+ explicit +/this(QTextDocument doc);
79     ~this();
80 
81     /+ virtual +/ void blockInserted(ref const(QTextBlock) block);
82     /+ virtual +/ void blockRemoved(ref const(QTextBlock) block);
83     /+ virtual +/ void blockFormatChanged(ref const(QTextBlock) block);
84 
85     final QList!(QTextBlock) blockList() const;
86 
87 protected:
88     this(ref QTextBlockGroupPrivate p, QTextDocument doc);
89 private:
90     /+ Q_DECLARE_PRIVATE(QTextBlockGroup) +/
91     /+ Q_DISABLE_COPY(QTextBlockGroup) +/
92     /+ friend class QTextDocumentPrivate; +/
93 }
94 
95 class /+ Q_GUI_EXPORT +/ QTextFrameLayoutData {
96 public:
97     /+ virtual +/~this();
98 }
99 
100 extern(C++, class) struct QTextFramePrivate;
101 class /+ Q_GUI_EXPORT +/ QTextFrame : QTextObject
102 {
103     mixin(Q_OBJECT);
104 
105 public:
106     /+ explicit +/this(QTextDocument doc);
107     ~this();
108 
109     pragma(inline, true) final void setFrameFormat(ref const(QTextFrameFormat) aformat)
110     { QTextObject.setFormat(aformat); }
111     final QTextFrameFormat frameFormat() const { return QTextObject.format().toFrameFormat(); }
112 
113     final QTextCursor firstCursorPosition() const;
114     final QTextCursor lastCursorPosition() const;
115     final int firstPosition() const;
116     final int lastPosition() const;
117 
118     final QTextFrameLayoutData layoutData() const;
119     final void setLayoutData(QTextFrameLayoutData data);
120 
121     final QList!(QTextFrame) childFrames() const;
122     final QTextFrame parentFrame() const;
123 
124     extern(C++, class) struct /+ Q_GUI_EXPORT +/ iterator {
125     private:
126         QTextFrame f;
127         int b;
128         int e;
129         QTextFrame cf;
130         int cb;
131 
132         /+ friend class QTextFrame; +/
133         /+ friend class QTextTableCell; +/
134         /+ friend class QTextDocumentLayoutPrivate; +/
135         this(QTextFrame frame, int block, int begin, int end);
136     public:
137  // ### Qt 6: inline
138 /+ #if QT_VERSION < QT_VERSION_CHECK(6,0,0) +/
139         @disable this(this);
140         this(ref const(iterator) o)/+ noexcept+/; // = default
141         /+ref iterator operator =(ref const(iterator) o)/+ noexcept+/;+/ // = default
142         /+ iterator(iterator &&other) noexcept // = default
143         { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(iterator)); } +/
144         /+ iterator &operator=(iterator &&other) noexcept // = default
145         { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(iterator)); return *this; } +/
146 /+ #endif +/
147 
148         QTextFrame parentFrame() const { return cast(QTextFrame)f; }
149 
150         QTextFrame currentFrame() const;
151         QTextBlock currentBlock() const;
152 
153         bool atEnd() const { return !cf && cb == e; }
154 
155         /+pragma(inline, true) bool operator ==(ref const(iterator) o) const { return f == o.f && cf == o.cf && cb == o.cb; }+/
156         /+pragma(inline, true) bool operator !=(ref const(iterator) o) const { return f != o.f || cf != o.cf || cb != o.cb; }+/
157         ref iterator opUnary(string op)() if(op == "++");
158         /+pragma(inline, true) iterator operator ++(int) { iterator tmp = this; operator++(); return tmp; }+/
159         ref iterator opUnary(string op)() if(op == "--");
160         /+pragma(inline, true) iterator operator --(int) { iterator tmp = this; operator--(); return tmp; }+/
161     }
162 
163     /+ friend class iterator; +/
164     // more Qt
165     alias Iterator = iterator;
166 
167     final iterator begin() const;
168     final iterator end() const;
169 
170 protected:
171     this(ref QTextFramePrivate p, QTextDocument doc);
172 private:
173     /+ friend class QTextDocumentPrivate; +/
174     /+ Q_DECLARE_PRIVATE(QTextFrame) +/
175     /+ Q_DISABLE_COPY(QTextFrame) +/
176 }
177 /+ Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE); +/
178 
179 class /+ Q_GUI_EXPORT +/ QTextBlockUserData {
180 public:
181     /+ virtual +/~this();
182 }
183 
184 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTextBlock
185 {
186 private:
187     /+ friend class QSyntaxHighlighter; +/
188 public:
189     pragma(inline, true) this(QTextDocumentPrivate* priv, int b)
190     {
191         this.p = priv;
192         this.n = b;
193     }
194     @disable this();
195     /+pragma(inline, true) this()
196     {
197         this.p = null;
198         this.n = 0;
199     }+/
200     @disable this(this);
201     pragma(inline, true) this(ref const(QTextBlock) o)
202     {
203         this.p = cast(QTextDocumentPrivate*)o.p;
204         this.n = o.n;
205     }
206     /+pragma(inline, true) ref QTextBlock operator =(ref const(QTextBlock) o) { p = o.p; n = o.n; return this; }+/
207 
208     bool isValid() const;
209 
210     /+pragma(inline, true) bool operator ==(ref const(QTextBlock) o) const { return p == o.p && n == o.n; }+/
211     /+pragma(inline, true) bool operator !=(ref const(QTextBlock) o) const { return p != o.p || n != o.n; }+/
212     /+pragma(inline, true) bool operator <(ref const(QTextBlock) o) const { return position() < o.position(); }+/
213 
214     int position() const;
215     int length() const;
216     bool contains(int position) const;
217 
218     QTextLayout* layout() const;
219     void clearLayout();
220     QTextBlockFormat blockFormat() const;
221     int blockFormatIndex() const;
222     QTextCharFormat charFormat() const;
223     int charFormatIndex() const;
224 
225     /+ Qt:: +/qt.core.namespace.LayoutDirection textDirection() const;
226 
227     QString text() const;
228 
229     QVector!(QTextLayout.FormatRange) textFormats() const;
230 
231     const(QTextDocument) document() const;
232 
233     QTextList textList() const;
234 
235     QTextBlockUserData userData() const;
236     void setUserData(QTextBlockUserData data);
237 
238     int userState() const;
239     void setUserState(int state);
240 
241     int revision() const;
242     void setRevision(int rev);
243 
244     bool isVisible() const;
245     void setVisible(bool visible);
246 
247     int blockNumber() const;
248     int firstLineNumber() const;
249 
250     void setLineCount(int count);
251     int lineCount() const;
252 
253     extern(C++, class) struct /+ Q_GUI_EXPORT +/ iterator {
254     private:
255         const(QTextDocumentPrivate)* p = null;
256         int b = 0;
257         int e = 0;
258         int n = 0;
259         /+ friend class QTextBlock; +/
260         this(const(QTextDocumentPrivate)* priv, int begin, int end, int f)
261         {
262             this.p = priv;
263             this.b = begin;
264             this.e = end;
265             this.n = f;
266         }
267     public:
268         @disable this();
269         /+this()
270         {
271             this.p = null;
272             this.b = 0;
273             this.e = 0;
274             this.n = 0;
275         }+/
276 /+ #if QT_VERSION < QT_VERSION_CHECK(6,0,0) +/
277         @disable this(this);
278         this(ref const(iterator) o)
279         {
280             this.p = o.p;
281             this.b = o.b;
282             this.e = o.e;
283             this.n = o.n;
284         }
285         /+ iterator &operator=(const iterator &o) = default; +/
286 /+ #endif +/
287 
288         QTextFragment fragment() const;
289 
290         bool atEnd() const { return n == e; }
291 
292         /+pragma(inline, true) bool operator ==(ref const(iterator) o) const { return p == o.p && n == o.n; }+/
293         /+pragma(inline, true) bool operator !=(ref const(iterator) o) const { return p != o.p || n != o.n; }+/
294         ref iterator opUnary(string op)() if(op == "++");
295         /+pragma(inline, true) iterator operator ++(int) { iterator tmp = this; operator++(); return tmp; }+/
296         ref iterator opUnary(string op)() if(op == "--");
297         /+pragma(inline, true) iterator operator --(int) { iterator tmp = this; operator--(); return tmp; }+/
298     }
299 
300     // more Qt
301     alias Iterator = iterator;
302 
303     iterator begin() const;
304     iterator end() const;
305 
306     QTextBlock next() const;
307     QTextBlock previous() const;
308 
309     pragma(inline, true) QTextDocumentPrivate* docHandle() const { return cast(QTextDocumentPrivate*)p; }
310     pragma(inline, true) int fragmentIndex() const { return n; }
311 
312 private:
313     QTextDocumentPrivate* p = null;
314     int n = 0;
315     /+ friend class QTextDocumentPrivate; +/
316     /+ friend class QTextLayout; +/
317 }
318 
319 /+ Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
320 Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE); +/
321 
322 
323 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QTextFragment
324 {
325 public:
326     pragma(inline, true) this(const(QTextDocumentPrivate)* priv, int f, int fe)
327     {
328         this.p = priv;
329         this.n = f;
330         this.ne = fe;
331     }
332     @disable this();
333     /+pragma(inline, true) this()
334     {
335         this.p = null;
336         this.n = 0;
337         this.ne = 0;
338     }+/
339     @disable this(this);
340     pragma(inline, true) this(ref const(QTextFragment) o)
341     {
342         this.p = o.p;
343         this.n = o.n;
344         this.ne = o.ne;
345     }
346     /+pragma(inline, true) ref QTextFragment operator =(ref const(QTextFragment) o) { p = o.p; n = o.n; ne = o.ne; return this; }+/
347 
348     pragma(inline, true) bool isValid() const { return p && n; }
349 
350     /+pragma(inline, true) bool operator ==(ref const(QTextFragment) o) const { return p == o.p && n == o.n; }+/
351     /+pragma(inline, true) bool operator !=(ref const(QTextFragment) o) const { return p != o.p || n != o.n; }+/
352     /+pragma(inline, true) bool operator <(ref const(QTextFragment) o) const { return position() < o.position(); }+/
353 
354     int position() const;
355     int length() const;
356     bool contains(int position) const;
357 
358     QTextCharFormat charFormat() const;
359     int charFormatIndex() const;
360     QString text() const;
361 
362     version(QT_NO_RAWFONT){}else
363     {
364         QList!(QGlyphRun) glyphRuns(int from = -1, int length = -1) const;
365     }
366 
367 private:
368     const(QTextDocumentPrivate)* p = null;
369     int n = 0;
370     int ne = 0;
371 }
372 
373 /+ Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE); +/
374