]> git.saurik.com Git - wxWidgets.git/blame - include/wx/richtext/richtextbuffer.h
string iterator's operator- should return difference_type, not size_t or unsigned
[wxWidgets.git] / include / wx / richtext / richtextbuffer.h
CommitLineData
5d7836c4 1/////////////////////////////////////////////////////////////////////////////
7fe8059f 2// Name: wx/richtext/richtextbuffer.h
5d7836c4
JS
3// Purpose: Buffer for wxRichTextCtrl
4// Author: Julian Smart
7fe8059f 5// Modified by:
5d7836c4 6// Created: 2005-09-30
7fe8059f 7// RCS-ID: $Id$
5d7836c4
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
b01ca8b6
JS
12#ifndef _WX_RICHTEXTBUFFER_H_
13#define _WX_RICHTEXTBUFFER_H_
14
5d7836c4
JS
15/*
16
17 Data structures
18 ===============
19
20 Data is represented by a hierarchy of objects, all derived from
21 wxRichTextObject.
22
23 The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox.
24 These boxes will allow flexible placement of text boxes on a page, but
59509217
JS
25 for now there is a single box representing the document, and this box is
26 a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph
27 objects, each of which can include text and images.
5d7836c4
JS
28
29 Each object maintains a range (start and end position) measured
30 from the start of the main parent box.
31 A paragraph object knows its range, and a text fragment knows its range
32 too. So, a character or image in a page has a position relative to the
33 start of the document, and a character in an embedded text box has
34 a position relative to that text box. For now, we will not be dealing with
35 embedded objects but it's something to bear in mind for later.
36
59509217
JS
37 Note that internally, a range (5,5) represents a range of one character.
38 In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection
39 as (5,6). A paragraph with one character might have an internal range of (0, 1)
40 since the end of the paragraph takes up one position.
41
5d7836c4
JS
42 Layout
43 ======
44
45 When Layout is called on an object, it is given a size which the object
46 must limit itself to, or one or more flexible directions (vertical
47 or horizontal). So for example a centered paragraph is given the page
48 width to play with (minus any margins), but can extend indefinitely
49 in the vertical direction. The implementation of Layout can then
50 cache the calculated size and position within the parent.
51
5d7836c4
JS
52 */
53
5d7836c4
JS
54/*!
55 * Includes
56 */
57
b01ca8b6 58#include "wx/defs.h"
5d7836c4
JS
59
60#if wxUSE_RICHTEXT
61
b01ca8b6
JS
62#include "wx/list.h"
63#include "wx/textctrl.h"
64#include "wx/bitmap.h"
5d7836c4
JS
65#include "wx/image.h"
66#include "wx/cmdproc.h"
67#include "wx/txtstrm.h"
68
0ca07313
JS
69#if wxUSE_DATAOBJ
70#include "wx/dataobj.h"
71#endif
72
ff76711f
JS
73/*!
74 * Special characters
75 */
76
77extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar;
78
5d7836c4
JS
79/*!
80 * File types
81 */
82
83#define wxRICHTEXT_TYPE_ANY 0
84#define wxRICHTEXT_TYPE_TEXT 1
85#define wxRICHTEXT_TYPE_XML 2
86#define wxRICHTEXT_TYPE_HTML 3
87#define wxRICHTEXT_TYPE_RTF 4
88#define wxRICHTEXT_TYPE_PDF 5
89
90/*!
91 * Forward declarations
92 */
93
3b2cb431
JS
94class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl;
95class WXDLLIMPEXP_RICHTEXT wxRichTextObject;
96class WXDLLIMPEXP_RICHTEXT wxRichTextCacheObject;
97class WXDLLIMPEXP_RICHTEXT wxRichTextObjectList;
98class WXDLLIMPEXP_RICHTEXT wxRichTextLine;
99class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph;
3b2cb431
JS
100class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler;
101class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet;
102class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
38f833b1 103class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition;
d2d0adc7
JS
104class WXDLLIMPEXP_RICHTEXT wxRichTextEvent;
105class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer;
44219ff0 106class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer;
5d7836c4
JS
107
108/*!
109 * Flags determining the available space, passed to Layout
110 */
111
112#define wxRICHTEXT_FIXED_WIDTH 0x01
113#define wxRICHTEXT_FIXED_HEIGHT 0x02
114#define wxRICHTEXT_VARIABLE_WIDTH 0x04
115#define wxRICHTEXT_VARIABLE_HEIGHT 0x08
116
4d551ad5
JS
117// Only lay out the part of the buffer that lies within
118// the rect passed to Layout.
119#define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
120
44219ff0
JS
121/*!
122 * Flags to pass to Draw
123 */
124
125// Ignore paragraph cache optimization, e.g. for printing purposes
126// where one line may be drawn higher (on the next page) compared
127// with the previous line
128#define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01
129
5d7836c4
JS
130/*!
131 * Flags returned from hit-testing
132 */
133
134// The point was not on this object
135#define wxRICHTEXT_HITTEST_NONE 0x01
136// The point was before the position returned from HitTest
137#define wxRICHTEXT_HITTEST_BEFORE 0x02
138// The point was after the position returned from HitTest
139#define wxRICHTEXT_HITTEST_AFTER 0x04
140// The point was on the position returned from HitTest
141#define wxRICHTEXT_HITTEST_ON 0x08
f262b25c
JS
142// The point was on space outside content
143#define wxRICHTEXT_HITTEST_OUTSIDE 0x10
5d7836c4
JS
144
145/*!
146 * Flags for GetRangeSize
147 */
148
149#define wxRICHTEXT_FORMATTED 0x01
150#define wxRICHTEXT_UNFORMATTED 0x02
151
59509217 152/*!
38f833b1 153 * Flags for SetStyle/SetListStyle
59509217
JS
154 */
155
156#define wxRICHTEXT_SETSTYLE_NONE 0x00
157
158// Specifies that this operation should be undoable
159#define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
160
161// Specifies that the style should not be applied if the
162// combined style at this point is already the style in question.
163#define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
164
165// Specifies that the style should only be applied to paragraphs,
166// and not the content. This allows content styling to be
167// preserved independently from that of e.g. a named paragraph style.
168#define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
169
170// Specifies that the style should only be applied to characters,
171// and not the paragraph. This allows content styling to be
172// preserved independently from that of e.g. a named paragraph style.
173#define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
174
38f833b1
JS
175// For SetListStyle only: specifies starting from the given number, otherwise
176// deduces number from existing attributes
177#define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
178
179// For SetListStyle only: specifies the list level for all paragraphs, otherwise
180// the current indentation will be used
181#define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
182
523d2f14
JS
183// Resets the existing style before applying the new style
184#define wxRICHTEXT_SETSTYLE_RESET 0x40
185
aeb6ebe2
JS
186// Removes the given style instead of applying it
187#define wxRICHTEXT_SETSTYLE_REMOVE 0x80
188
fe5aa22c
JS
189/*!
190 * Flags for text insertion
191 */
192
193#define wxRICHTEXT_INSERT_NONE 0x00
194#define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
195
5d7836c4
JS
196/*!
197 * Extra formatting flags not in wxTextAttr
198 */
199
200#define wxTEXT_ATTR_PARA_SPACING_AFTER 0x00000800
201#define wxTEXT_ATTR_PARA_SPACING_BEFORE 0x00001000
202#define wxTEXT_ATTR_LINE_SPACING 0x00002000
203#define wxTEXT_ATTR_CHARACTER_STYLE_NAME 0x00004000
204#define wxTEXT_ATTR_PARAGRAPH_STYLE_NAME 0x00008000
f089713f
JS
205#define wxTEXT_ATTR_LIST_STYLE_NAME 0x00010000
206#define wxTEXT_ATTR_BULLET_STYLE 0x00020000
207#define wxTEXT_ATTR_BULLET_NUMBER 0x00040000
d2d0adc7 208#define wxTEXT_ATTR_BULLET_TEXT 0x00080000
f089713f 209#define wxTEXT_ATTR_BULLET_NAME 0x00100000
d2d0adc7 210#define wxTEXT_ATTR_URL 0x00200000
ea160b2e 211#define wxTEXT_ATTR_PAGE_BREAK 0x00400000
42688aea 212#define wxTEXT_ATTR_EFFECTS 0x00800000
4d6d8bf4 213#define wxTEXT_ATTR_OUTLINE_LEVEL 0x01000000
5d7836c4
JS
214
215/*!
216 * Styles for wxTextAttrEx::SetBulletStyle
217 */
218
d2d0adc7
JS
219#define wxTEXT_ATTR_BULLET_STYLE_NONE 0x00000000
220#define wxTEXT_ATTR_BULLET_STYLE_ARABIC 0x00000001
221#define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER 0x00000002
222#define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER 0x00000004
223#define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER 0x00000008
224#define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER 0x00000010
225#define wxTEXT_ATTR_BULLET_STYLE_SYMBOL 0x00000020
226#define wxTEXT_ATTR_BULLET_STYLE_BITMAP 0x00000040
227#define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES 0x00000080
228#define wxTEXT_ATTR_BULLET_STYLE_PERIOD 0x00000100
229#define wxTEXT_ATTR_BULLET_STYLE_STANDARD 0x00000200
230#define wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS 0x00000400
231#define wxTEXT_ATTR_BULLET_STYLE_OUTLINE 0x00000800
232
233#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT 0x00000000
234#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT 0x00001000
235#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE 0x00002000
5d7836c4 236
42688aea
JS
237/*!
238 * Styles for wxTextAttrEx::SetTextEffects
239 */
240
241#define wxTEXT_ATTR_EFFECT_NONE 0x00000000
242#define wxTEXT_ATTR_EFFECT_CAPITALS 0x00000001
243#define wxTEXT_ATTR_EFFECT_SMALL_CAPITALS 0x00000002
244#define wxTEXT_ATTR_EFFECT_STRIKETHROUGH 0x00000004
245#define wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH 0x00000008
246#define wxTEXT_ATTR_EFFECT_SHADOW 0x00000010
247#define wxTEXT_ATTR_EFFECT_EMBOSS 0x00000020
248#define wxTEXT_ATTR_EFFECT_OUTLINE 0x00000040
249#define wxTEXT_ATTR_EFFECT_ENGRAVE 0x00000080
250#define wxTEXT_ATTR_EFFECT_SUPERSCRIPT 0x00000100
251#define wxTEXT_ATTR_EFFECT_SUBSCRIPT 0x00000200
252
5d7836c4
JS
253/*!
254 * Line spacing values
255 */
256
257#define wxTEXT_ATTR_LINE_SPACING_NORMAL 10
258#define wxTEXT_ATTR_LINE_SPACING_HALF 15
259#define wxTEXT_ATTR_LINE_SPACING_TWICE 20
260
d2d0adc7
JS
261/*!
262 * Character and paragraph combined styles
263 */
264
42688aea 265#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS|wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL)
d2d0adc7
JS
266
267#define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
268 wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
269 wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_TEXT|wxTEXT_ATTR_BULLET_NAME|\
4d6d8bf4 270 wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL)
d2d0adc7
JS
271
272#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
273
5d7836c4
JS
274/*!
275 * wxRichTextRange class declaration
276 * This stores beginning and end positions for a range of data.
277 */
278
3b2cb431 279class WXDLLIMPEXP_RICHTEXT wxRichTextRange
5d7836c4
JS
280{
281public:
282// Constructors
283
284 wxRichTextRange() { m_start = 0; m_end = 0; }
285 wxRichTextRange(long start, long end) { m_start = start; m_end = end; }
286 wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
287 ~wxRichTextRange() {}
288
289 void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; }
38113684 290 bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); }
96c9f0f6 291 bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start && m_end != range.m_end); }
5d7836c4
JS
292 wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); }
293 wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); }
294
295 void SetRange(long start, long end) { m_start = start; m_end = end; }
296
297 void SetStart(long start) { m_start = start; }
298 long GetStart() const { return m_start; }
299
300 void SetEnd(long end) { m_end = end; }
301 long GetEnd() const { return m_end; }
302
303 /// Returns true if this range is completely outside 'range'
304 bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; }
305
306 /// Returns true if this range is completely within 'range'
307 bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; }
308
309 /// Returns true if the given position is within this range. Allow
310 /// for the possibility of an empty range - assume the position
311 /// is within this empty range. NO, I think we should not match with an empty range.
312 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
313 bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; }
314
315 /// Limit this range to be within 'range'
316 bool LimitTo(const wxRichTextRange& range) ;
317
318 /// Gets the length of the range
319 long GetLength() const { return m_end - m_start + 1; }
320
321 /// Swaps the start and end
322 void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; }
323
96c9f0f6
JS
324 /// Convert to internal form: (n, n) is the range of a single character.
325 wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); }
326
327 /// Convert from internal to public API form: (n, n+1) is the range of a single character.
328 wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); }
329
5d7836c4
JS
330protected:
331 long m_start;
332 long m_end;
333};
334
1e967276
JS
335#define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
336#define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
337
5d7836c4
JS
338/*!
339 * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
340 */
341
3b2cb431 342class WXDLLIMPEXP_RICHTEXT wxTextAttrEx: public wxTextAttr
5d7836c4
JS
343{
344public:
345 // ctors
346 wxTextAttrEx(const wxTextAttrEx& attr);
27e20452 347 wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; }
5d7836c4
JS
348 wxTextAttrEx() { Init(); }
349
38f833b1 350 // Initialise this object
5d7836c4
JS
351 void Init();
352
d2d0adc7
JS
353 // Copy
354 void Copy(const wxTextAttrEx& attr);
355
5d7836c4
JS
356 // Assignment from a wxTextAttrEx object
357 void operator= (const wxTextAttrEx& attr);
358
38f833b1 359 // Assignment from a wxTextAttr object
5d7836c4
JS
360 void operator= (const wxTextAttr& attr);
361
38f833b1
JS
362 // Equality test
363 bool operator== (const wxTextAttrEx& attr) const;
364
5d7836c4 365 // setters
4f3c010b
JS
366 void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME); }
367 void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME); }
38f833b1 368 void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
4f3c010b
JS
369 void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER); }
370 void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE); }
371 void SetLineSpacing(int spacing) { m_lineSpacing = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING); }
372 void SetBulletStyle(int style) { m_bulletStyle = style; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_STYLE); }
373 void SetBulletNumber(int n) { m_bulletNumber = n; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NUMBER); }
d2d0adc7 374 void SetBulletText(const wxString& text) { m_bulletText = text; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_TEXT); }
f089713f 375 void SetBulletName(const wxString& name) { m_bulletName = name; SetFlags(GetFlags() | wxTEXT_ATTR_BULLET_NAME); }
59509217 376 void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
d2d0adc7 377 void SetURL(const wxString& url) { m_urlTarget = url; SetFlags(GetFlags() | wxTEXT_ATTR_URL); }
ea160b2e 378 void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); }
42688aea
JS
379 void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); }
380 void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; }
4d6d8bf4 381 void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); }
5d7836c4
JS
382
383 const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
384 const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
38f833b1 385 const wxString& GetListStyleName() const { return m_listStyleName; }
5d7836c4
JS
386 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
387 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
388 int GetLineSpacing() const { return m_lineSpacing; }
389 int GetBulletStyle() const { return m_bulletStyle; }
390 int GetBulletNumber() const { return m_bulletNumber; }
d2d0adc7 391 const wxString& GetBulletText() const { return m_bulletText; }
f089713f 392 const wxString& GetBulletName() const { return m_bulletName; }
59509217 393 const wxString& GetBulletFont() const { return m_bulletFont; }
d2d0adc7 394 const wxString& GetURL() const { return m_urlTarget; }
42688aea
JS
395 int GetTextEffects() const { return m_textEffects; }
396 int GetTextEffectFlags() const { return m_textEffectFlags; }
4d6d8bf4 397 int GetOutlineLevel() const { return m_outlineLevel; }
5d7836c4 398
336d8ae9
VZ
399 bool HasFontWeight() const { return (GetFlags() & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
400 bool HasFontSize() const { return (GetFlags() & wxTEXT_ATTR_FONT_SIZE) != 0; }
401 bool HasFontItalic() const { return (GetFlags() & wxTEXT_ATTR_FONT_ITALIC) != 0; }
402 bool HasFontUnderlined() const { return (GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
403 bool HasFontFaceName() const { return (GetFlags() & wxTEXT_ATTR_FONT_FACE) != 0; }
05b4fddf 404
5d7836c4
JS
405 bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); }
406 bool HasParagraphSpacingBefore() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_BEFORE); }
407 bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); }
07b27480
JS
408 bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) && !m_characterStyleName.IsEmpty(); }
409 bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) && !m_paragraphStyleName.IsEmpty(); }
38f833b1 410 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
5d7836c4
JS
411 bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); }
412 bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); }
d2d0adc7 413 bool HasBulletText() const { return HasFlag(wxTEXT_ATTR_BULLET_TEXT); }
f089713f 414 bool HasBulletName() const { return HasFlag(wxTEXT_ATTR_BULLET_NAME); }
d2d0adc7 415 bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); }
ea160b2e 416 bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); }
42688aea
JS
417 bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); }
418 bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); }
4d6d8bf4 419 bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); }
5d7836c4
JS
420
421 // Is this a character style?
d2d0adc7
JS
422 bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER)); }
423 bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH)); }
5d7836c4
JS
424
425 // returns false if we have any attributes set, true otherwise
426 bool IsDefault() const
427 {
42688aea 428 return (GetFlags() == 0);
5d7836c4 429 }
05b4fddf
JS
430
431 // return the attribute having the valid font and colours: it uses the
432 // attributes set in attr and falls back first to attrDefault and then to
433 // the text control font/colours for those attributes which are not set
434 static wxTextAttrEx CombineEx(const wxTextAttrEx& attr,
435 const wxTextAttrEx& attrDef,
436 const wxTextCtrlBase *text);
437
5d7836c4
JS
438private:
439 // Paragraph styles
440 int m_paragraphSpacingAfter;
441 int m_paragraphSpacingBefore;
442 int m_lineSpacing;
443 int m_bulletStyle;
444 int m_bulletNumber;
42688aea
JS
445 int m_textEffects;
446 int m_textEffectFlags;
4d6d8bf4 447 int m_outlineLevel;
d2d0adc7 448 wxString m_bulletText;
59509217 449 wxString m_bulletFont;
f089713f 450 wxString m_bulletName;
d2d0adc7 451 wxString m_urlTarget;
5d7836c4
JS
452
453 // Character style
454 wxString m_characterStyleName;
455
456 // Paragraph style
457 wxString m_paragraphStyleName;
38f833b1
JS
458
459 // List style
460 wxString m_listStyleName;
5d7836c4
JS
461};
462
463/*!
464 * wxRichTextAttr stores attributes without a wxFont object, so is a much more
465 * efficient way to query styles.
466 */
467
3b2cb431 468class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
5d7836c4
JS
469{
470public:
471 // ctors
472 wxRichTextAttr(const wxTextAttrEx& attr);
d2d0adc7 473 wxRichTextAttr(const wxRichTextAttr& attr);
5d7836c4
JS
474 wxRichTextAttr() { Init(); }
475 wxRichTextAttr(const wxColour& colText,
476 const wxColour& colBack = wxNullColour,
477 wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
478
479 // Initialise this object.
480 void Init();
481
d2d0adc7
JS
482 // Copy
483 void Copy(const wxRichTextAttr& attr);
484
5d7836c4
JS
485 // Assignment from a wxRichTextAttr object.
486 void operator= (const wxRichTextAttr& attr);
487
488 // Assignment from a wxTextAttrEx object.
489 void operator= (const wxTextAttrEx& attr);
490
fe5aa22c
JS
491 // Equality test
492 bool operator== (const wxRichTextAttr& attr) const;
493
5d7836c4
JS
494 // Making a wxTextAttrEx object.
495 operator wxTextAttrEx () const ;
496
5d7836c4
JS
497 // Create font from font attributes.
498 wxFont CreateFont() const;
499
500 // Get attributes from font.
501 bool GetFontAttributes(const wxFont& font);
502
503 // setters
504 void SetTextColour(const wxColour& colText) { m_colText = colText; m_flags |= wxTEXT_ATTR_TEXT_COLOUR; }
505 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; }
506 void SetAlignment(wxTextAttrAlignment alignment) { m_textAlignment = alignment; m_flags |= wxTEXT_ATTR_ALIGNMENT; }
507 void SetTabs(const wxArrayInt& tabs) { m_tabs = tabs; m_flags |= wxTEXT_ATTR_TABS; }
508 void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; }
509 void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; }
510
511 void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags |= wxTEXT_ATTR_FONT_SIZE; }
512 void SetFontStyle(int fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; }
513 void SetFontWeight(int fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; }
514 void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; }
515 void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; }
516
517 void SetFlags(long flags) { m_flags = flags; }
518
ab14c7aa
JS
519 void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; }
520 void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; }
38f833b1 521 void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
ab14c7aa
JS
522 void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; }
523 void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; }
524 void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; }
525 void SetBulletStyle(int style) { m_bulletStyle = style; m_flags |= wxTEXT_ATTR_BULLET_STYLE; }
526 void SetBulletNumber(int n) { m_bulletNumber = n; m_flags |= wxTEXT_ATTR_BULLET_NUMBER; }
d2d0adc7 527 void SetBulletText(const wxString& text) { m_bulletText = text; m_flags |= wxTEXT_ATTR_BULLET_TEXT; }
59509217 528 void SetBulletFont(const wxString& bulletFont) { m_bulletFont = bulletFont; }
d2d0adc7
JS
529 void SetBulletName(const wxString& name) { m_bulletName = name; m_flags |= wxTEXT_ATTR_BULLET_NAME; }
530 void SetURL(const wxString& url) { m_urlTarget = url; m_flags |= wxTEXT_ATTR_URL; }
ea160b2e 531 void SetPageBreak(bool pageBreak = true) { SetFlags(pageBreak ? (GetFlags() | wxTEXT_ATTR_PAGE_BREAK) : (GetFlags() & ~wxTEXT_ATTR_PAGE_BREAK)); }
42688aea
JS
532 void SetTextEffects(int effects) { m_textEffects = effects; SetFlags(GetFlags() | wxTEXT_ATTR_EFFECTS); }
533 void SetTextEffectFlags(int effects) { m_textEffectFlags = effects; }
4d6d8bf4 534 void SetOutlineLevel(int level) { m_outlineLevel = level; SetFlags(GetFlags() | wxTEXT_ATTR_OUTLINE_LEVEL); }
5d7836c4
JS
535
536 const wxColour& GetTextColour() const { return m_colText; }
537 const wxColour& GetBackgroundColour() const { return m_colBack; }
538 wxTextAttrAlignment GetAlignment() const { return m_textAlignment; }
539 const wxArrayInt& GetTabs() const { return m_tabs; }
540 long GetLeftIndent() const { return m_leftIndent; }
541 long GetLeftSubIndent() const { return m_leftSubIndent; }
542 long GetRightIndent() const { return m_rightIndent; }
543 long GetFlags() const { return m_flags; }
544
545 int GetFontSize() const { return m_fontSize; }
546 int GetFontStyle() const { return m_fontStyle; }
547 int GetFontWeight() const { return m_fontWeight; }
548 bool GetFontUnderlined() const { return m_fontUnderlined; }
549 const wxString& GetFontFaceName() const { return m_fontFaceName; }
550
551 const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
552 const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
38f833b1 553 const wxString& GetListStyleName() const { return m_listStyleName; }
5d7836c4
JS
554 int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
555 int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
556 int GetLineSpacing() const { return m_lineSpacing; }
557 int GetBulletStyle() const { return m_bulletStyle; }
558 int GetBulletNumber() const { return m_bulletNumber; }
d2d0adc7 559 const wxString& GetBulletText() const { return m_bulletText; }
59509217 560 const wxString& GetBulletFont() const { return m_bulletFont; }
f089713f 561 const wxString& GetBulletName() const { return m_bulletName; }
d2d0adc7 562 const wxString& GetURL() const { return m_urlTarget; }
42688aea
JS
563 int GetTextEffects() const { return m_textEffects; }
564 int GetTextEffectFlags() const { return m_textEffectFlags; }
4d6d8bf4 565 int GetOutlineLevel() const { return m_outlineLevel; }
5d7836c4
JS
566
567 // accessors
568 bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; }
569 bool HasBackgroundColour() const { return m_colBack.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; }
570 bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) || ((m_flags & wxTEXT_ATTR_ALIGNMENT) != 0) ; }
571 bool HasTabs() const { return (m_flags & wxTEXT_ATTR_TABS) != 0 ; }
572 bool HasLeftIndent() const { return (m_flags & wxTEXT_ATTR_LEFT_INDENT) != 0 ; }
573 bool HasRightIndent() const { return (m_flags & wxTEXT_ATTR_RIGHT_INDENT) != 0 ; }
336d8ae9
VZ
574 bool HasFontWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
575 bool HasFontSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; }
576 bool HasFontItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; }
577 bool HasFontUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
578 bool HasFontFaceName() const { return (m_flags & wxTEXT_ATTR_FONT_FACE) != 0; }
5d7836c4
JS
579 bool HasFont() const { return (m_flags & (wxTEXT_ATTR_FONT)) != 0; }
580
581 bool HasParagraphSpacingAfter() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_AFTER) != 0; }
582 bool HasParagraphSpacingBefore() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) != 0; }
583 bool HasLineSpacing() const { return (m_flags & wxTEXT_ATTR_LINE_SPACING) != 0; }
07b27480
JS
584 bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0 && !m_characterStyleName.IsEmpty(); }
585 bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0 && !m_paragraphStyleName.IsEmpty(); }
38f833b1 586 bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
5d7836c4
JS
587 bool HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; }
588 bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; }
d2d0adc7 589 bool HasBulletText() const { return (m_flags & wxTEXT_ATTR_BULLET_TEXT) != 0; }
f089713f 590 bool HasBulletName() const { return (m_flags & wxTEXT_ATTR_BULLET_NAME) != 0; }
d2d0adc7 591 bool HasURL() const { return HasFlag(wxTEXT_ATTR_URL); }
ea160b2e 592 bool HasPageBreak() const { return HasFlag(wxTEXT_ATTR_PAGE_BREAK); }
42688aea
JS
593 bool HasTextEffects() const { return HasFlag(wxTEXT_ATTR_EFFECTS); }
594 bool HasTextEffect(int effect) const { return HasFlag(wxTEXT_ATTR_EFFECTS) && ((GetTextEffectFlags() & effect) != 0); }
4d6d8bf4 595 bool HasOutlineLevel() const { return HasFlag(wxTEXT_ATTR_OUTLINE_LEVEL); }
5d7836c4
JS
596
597 bool HasFlag(long flag) const { return (m_flags & flag) != 0; }
598
599 // Is this a character style?
d2d0adc7
JS
600 bool IsCharacterStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_CHARACTER)); }
601 bool IsParagraphStyle() const { return (0 != (GetFlags() & wxTEXT_ATTR_PARAGRAPH)); }
5d7836c4
JS
602
603 // returns false if we have any attributes set, true otherwise
604 bool IsDefault() const
605 {
42688aea 606 return GetFlags() == 0;
5d7836c4
JS
607 }
608
336d8ae9
VZ
609 // Merges the given attributes. Does not affect 'this'. If compareWith
610 // is non-NULL, then it will be used to mask out those attributes that are the same in style
611 // and compareWith, for situations where we don't want to explicitly set inherited attributes.
612 bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL);
613
614 // Merges the given attributes and returns the result. Does not affect 'this'. If compareWith
615 // is non-NULL, then it will be used to mask out those attributes that are the same in style
616 // and compareWith, for situations where we don't want to explicitly set inherited attributes.
617 wxRichTextAttr Combine(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL) const;
618
5d7836c4
JS
619private:
620 long m_flags;
621
622 // Paragraph styles
623 wxArrayInt m_tabs; // array of int: tab stops in 1/10 mm
624 int m_leftIndent; // left indent in 1/10 mm
625 int m_leftSubIndent; // left indent for all but the first
626 // line in a paragraph relative to the
627 // first line, in 1/10 mm
628 int m_rightIndent; // right indent in 1/10 mm
629 wxTextAttrAlignment m_textAlignment;
630
631 int m_paragraphSpacingAfter;
632 int m_paragraphSpacingBefore;
633 int m_lineSpacing;
634 int m_bulletStyle;
635 int m_bulletNumber;
42688aea
JS
636 int m_textEffects;
637 int m_textEffectFlags;
4d6d8bf4 638 int m_outlineLevel;
d2d0adc7 639 wxString m_bulletText;
59509217 640 wxString m_bulletFont;
f089713f 641 wxString m_bulletName;
d2d0adc7 642 wxString m_urlTarget;
5d7836c4
JS
643
644 // Character styles
645 wxColour m_colText,
646 m_colBack;
647 int m_fontSize;
648 int m_fontStyle;
649 int m_fontWeight;
650 bool m_fontUnderlined;
651 wxString m_fontFaceName;
652
653 // Character style
654 wxString m_characterStyleName;
655
656 // Paragraph style
657 wxString m_paragraphStyleName;
38f833b1
JS
658
659 // List style
660 wxString m_listStyleName;
5d7836c4
JS
661};
662
5d7836c4
JS
663/*!
664 * wxRichTextObject class declaration
665 * This is the base for drawable objects.
666 */
667
3b2cb431 668class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject
5d7836c4
JS
669{
670 DECLARE_CLASS(wxRichTextObject)
671public:
672// Constructors
673
674 wxRichTextObject(wxRichTextObject* parent = NULL);
d3c7fc99 675 virtual ~wxRichTextObject();
5d7836c4
JS
676
677// Overrideables
678
679 /// Draw the item, within the given range. Some objects may ignore the range (for
680 /// example paragraphs) while others must obey it (lines, to implement wrapping)
681 virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style) = 0;
682
683 /// Lay the item out at the specified position with the given size constraint.
684 /// Layout must set the cached size.
38113684 685 virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0;
5d7836c4
JS
686
687 /// Hit-testing: returns a flag indicating hit test details, plus
688 /// information about position
689 virtual int HitTest(wxDC& WXUNUSED(dc), const wxPoint& WXUNUSED(pt), long& WXUNUSED(textPosition)) { return false; }
690
691 /// Finds the absolute position and row height for the given character position
692 virtual bool FindPosition(wxDC& WXUNUSED(dc), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; }
693
694 /// Get the best size, i.e. the ideal starting size for this object irrespective
695 /// of available space. For a short text string, it will be the size that exactly encloses
696 /// the text. For a longer string, it might use the parent width for example.
697 virtual wxSize GetBestSize() const { return m_size; }
698
699 /// Get the object size for the given range. Returns false if the range
700 /// is invalid for this object.
7f0d9d71 701 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const = 0;
5d7836c4
JS
702
703 /// Do a split, returning an object containing the second part, and setting
704 /// the first part in 'this'.
705 virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; }
706
707 /// Calculate range. By default, guess that the object is 1 unit long.
708 virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); }
709
710 /// Delete range
711 virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; }
712
713 /// Returns true if the object is empty
714 virtual bool IsEmpty() const { return false; }
715
716 /// Get any text in this object for the given range
717 virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; }
718
719 /// Returns true if this object can merge itself with the given one.
720 virtual bool CanMerge(wxRichTextObject* WXUNUSED(object)) const { return false; }
721
722 /// Returns true if this object merged itself with the given one.
723 /// The calling code will then delete the given object.
724 virtual bool Merge(wxRichTextObject* WXUNUSED(object)) { return false; }
725
726 /// Dump to output stream for debugging
727 virtual void Dump(wxTextOutputStream& stream);
728
729// Accessors
730
731 /// Get/set the cached object size as calculated by Layout.
732 virtual wxSize GetCachedSize() const { return m_size; }
733 virtual void SetCachedSize(const wxSize& sz) { m_size = sz; }
734
735 /// Get/set the object position
736 virtual wxPoint GetPosition() const { return m_pos; }
737 virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
738
739 /// Get the rectangle enclosing the object
740 virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
741
742 /// Set the range
743 void SetRange(const wxRichTextRange& range) { m_range = range; }
744
745 /// Get the range
746 const wxRichTextRange& GetRange() const { return m_range; }
747 wxRichTextRange& GetRange() { return m_range; }
748
749 /// Get/set dirty flag (whether the object needs Layout to be called)
750 virtual bool GetDirty() const { return m_dirty; }
751 virtual void SetDirty(bool dirty) { m_dirty = dirty; }
752
753 /// Is this composite?
754 virtual bool IsComposite() const { return false; }
755
756 /// Get/set the parent.
757 virtual wxRichTextObject* GetParent() const { return m_parent; }
758 virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; }
759
760 /// Set the margin around the object
761 virtual void SetMargins(int margin);
762 virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin);
763 virtual int GetLeftMargin() const { return m_leftMargin; }
764 virtual int GetRightMargin() const { return m_rightMargin; }
765 virtual int GetTopMargin() const { return m_topMargin; }
766 virtual int GetBottomMargin() const { return m_bottomMargin; }
767
768 /// Set attributes object
769 void SetAttributes(const wxTextAttrEx& attr) { m_attributes = attr; }
770 const wxTextAttrEx& GetAttributes() const { return m_attributes; }
771 wxTextAttrEx& GetAttributes() { return m_attributes; }
772
773 /// Set/get stored descent
774 void SetDescent(int descent) { m_descent = descent; }
775 int GetDescent() const { return m_descent; }
776
44219ff0
JS
777 /// Gets the containing buffer
778 wxRichTextBuffer* GetBuffer() const;
779
5d7836c4
JS
780// Operations
781
782 /// Clone the object
783 virtual wxRichTextObject* Clone() const { return NULL; }
784
785 /// Copy
786 void Copy(const wxRichTextObject& obj);
787
788 /// Reference-counting allows us to use the same object in multiple
789 /// lists (not yet used)
790 void Reference() { m_refCount ++; }
791 void Dereference();
792
44219ff0
JS
793 /// Convert units in tenths of a millimetre to device units
794 int ConvertTenthsMMToPixels(wxDC& dc, int units);
795 static int ConvertTenthsMMToPixels(int ppi, int units);
5d7836c4
JS
796
797protected:
798 wxSize m_size;
799 wxPoint m_pos;
800 int m_descent; // Descent for this object (if any)
801 bool m_dirty;
802 int m_refCount;
803 wxRichTextObject* m_parent;
804
805 /// The range of this object (start position to end position)
806 wxRichTextRange m_range;
807
808 /// Margins
809 int m_leftMargin;
810 int m_rightMargin;
811 int m_topMargin;
812 int m_bottomMargin;
813
814 /// Attributes
815 wxTextAttrEx m_attributes;
816};
817
3b2cb431 818WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT );
5d7836c4
JS
819
820/*!
821 * wxRichTextCompositeObject class declaration
822 * Objects of this class can contain other objects.
823 */
824
3b2cb431 825class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject
5d7836c4
JS
826{
827 DECLARE_CLASS(wxRichTextCompositeObject)
828public:
829// Constructors
830
831 wxRichTextCompositeObject(wxRichTextObject* parent = NULL);
d3c7fc99 832 virtual ~wxRichTextCompositeObject();
5d7836c4
JS
833
834// Overrideables
835
836 /// Hit-testing: returns a flag indicating hit test details, plus
837 /// information about position
838 virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition);
839
840 /// Finds the absolute position and row height for the given character position
841 virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart);
842
843 /// Calculate range
844 virtual void CalculateRange(long start, long& end);
845
846 /// Delete range
847 virtual bool DeleteRange(const wxRichTextRange& range);
848
849 /// Get any text in this object for the given range
850 virtual wxString GetTextForRange(const wxRichTextRange& range) const;
851
852 /// Dump to output stream for debugging
853 virtual void Dump(wxTextOutputStream& stream);
854
855// Accessors
856
857 /// Get the children
858 wxRichTextObjectList& GetChildren() { return m_children; }
859 const wxRichTextObjectList& GetChildren() const { return m_children; }
860
861 /// Get the child count
862 size_t GetChildCount() const ;
863
864 /// Get the nth child
865 wxRichTextObject* GetChild(size_t n) const ;
866
867 /// Get/set dirty flag
868 virtual bool GetDirty() const { return m_dirty; }
869 virtual void SetDirty(bool dirty) { m_dirty = dirty; }
870
871 /// Is this composite?
872 virtual bool IsComposite() const { return true; }
873
874 /// Returns true if the buffer is empty
875 virtual bool IsEmpty() const { return GetChildCount() == 0; }
876
877// Operations
878
879 /// Copy
880 void Copy(const wxRichTextCompositeObject& obj);
881
0ca07313
JS
882 /// Assignment
883 void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); }
884
5d7836c4
JS
885 /// Append a child, returning the position
886 size_t AppendChild(wxRichTextObject* child) ;
887
888 /// Insert the child in front of the given object, or at the beginning
889 bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ;
890
891 /// Delete the child
892 bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ;
893
894 /// Delete all children
895 bool DeleteChildren() ;
896
897 /// Recursively merge all pieces that can be merged.
898 bool Defragment();
899
900protected:
901 wxRichTextObjectList m_children;
902};
903
904/*!
905 * wxRichTextBox class declaration
906 * This defines a 2D space to lay out objects
907 */
908
3b2cb431 909class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextCompositeObject
5d7836c4
JS
910{
911 DECLARE_DYNAMIC_CLASS(wxRichTextBox)
912public:
913// Constructors
914
915 wxRichTextBox(wxRichTextObject* parent = NULL);
916 wxRichTextBox(const wxRichTextBox& obj): wxRichTextCompositeObject() { Copy(obj); }
917
918// Overrideables
919
920 /// Draw the item
921 virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
922
923 /// Lay the item out
38113684 924 virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
5d7836c4
JS
925
926 /// Get/set the object size for the given range. Returns false if the range
927 /// is invalid for this object.
7f0d9d71 928 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
5d7836c4
JS
929
930// Accessors
931
932// Operations
933
934 /// Clone
935 virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); }
936
937 /// Copy
938 void Copy(const wxRichTextBox& obj);
939
940protected:
941};
942
943/*!
944 * wxRichTextParagraphBox class declaration
945 * This box knows how to lay out paragraphs.
946 */
947
3b2cb431 948class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextBox
5d7836c4
JS
949{
950 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox)
951public:
952// Constructors
953
954 wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL);
0ca07313 955 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextBox() { Init(); Copy(obj); }
5d7836c4
JS
956
957// Overrideables
958
959 /// Draw the item
960 virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
961
962 /// Lay the item out
38113684 963 virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
5d7836c4
JS
964
965 /// Get/set the object size for the given range. Returns false if the range
966 /// is invalid for this object.
7f0d9d71 967 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
5d7836c4
JS
968
969 /// Delete range
970 virtual bool DeleteRange(const wxRichTextRange& range);
971
972 /// Get any text in this object for the given range
973 virtual wxString GetTextForRange(const wxRichTextRange& range) const;
974
975// Accessors
976
977 /// Associate a control with the buffer, for operations that for example require refreshing the window.
978 void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; }
979
980 /// Get the associated control.
981 wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; }
982
0ca07313
JS
983 /// Get/set whether the last paragraph is partial or complete
984 void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
985 bool GetPartialParagraph() const { return m_partialParagraph; }
986
38f833b1
JS
987 /// If this is a buffer, returns the current style sheet. The base layout box
988 /// class doesn't have an associated style sheet.
989 virtual wxRichTextStyleSheet* GetStyleSheet() const { return NULL; }
990
5d7836c4
JS
991// Operations
992
993 /// Initialize the object.
994 void Init();
995
996 /// Clear all children
997 virtual void Clear();
998
999 /// Clear and initialize with one blank paragraph
1000 virtual void Reset();
1001
1002 /// Convenience function to add a paragraph of text
fe5aa22c 1003 virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL);
5d7836c4
JS
1004
1005 /// Convenience function to add an image
fe5aa22c 1006 virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL);
5d7836c4
JS
1007
1008 /// Adds multiple paragraphs, based on newlines.
fe5aa22c 1009 virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL);
5d7836c4
JS
1010
1011 /// Get the line at the given position. If caretPosition is true, the position is
1012 /// a caret position, which is normally a smaller number.
1013 virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const;
1014
1015 /// Get the line at the given y pixel position, or the last line.
1016 virtual wxRichTextLine* GetLineAtYPosition(int y) const;
1017
1018 /// Get the paragraph at the given character or caret position
1019 virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const;
1020
1021 /// Get the line size at the given position
1022 virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const;
1023
1024 /// Given a position, get the number of the visible line (potentially many to a paragraph),
1025 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
1026 /// that indicates whether the caret is being shown at the end of the previous line or at the start
1027 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
1028 /// position.
1029 virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const;
1030
1031 /// Given a line number, get the corresponding wxRichTextLine object.
1032 virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const;
1033
1034 /// Get the leaf object in a paragraph at this position.
1035 /// Given a line number, get the corresponding wxRichTextLine object.
1036 virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const;
1037
1038 /// Get the paragraph by number
7fe8059f 1039 virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
5d7836c4
JS
1040
1041 /// Get the paragraph for a given line
7fe8059f 1042 virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
5d7836c4
JS
1043
1044 /// Get the length of the paragraph
1045 virtual int GetParagraphLength(long paragraphNumber) const;
1046
1047 /// Get the number of paragraphs
1048 virtual int GetParagraphCount() const { return GetChildCount(); }
1049
1050 /// Get the number of visible lines
1051 virtual int GetLineCount() const;
1052
1053 /// Get the text of the paragraph
1054 virtual wxString GetParagraphText(long paragraphNumber) const;
1055
1056 /// Convert zero-based line column and paragraph number to a position.
1057 virtual long XYToPosition(long x, long y) const;
1058
1059 /// Convert zero-based position to line column and paragraph number
1060 virtual bool PositionToXY(long pos, long* x, long* y) const;
1061
1062 /// Set text attributes: character and/or paragraph styles.
59509217
JS
1063 virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1064 virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
5d7836c4 1065
fe5aa22c 1066 /// Get the conbined text attributes for this position.
3966a9f4
JS
1067 virtual bool GetStyle(long position, wxTextAttrEx& style);
1068 virtual bool GetStyle(long position, wxRichTextAttr& style);
5d7836c4 1069
fe5aa22c
JS
1070 /// Get the content (uncombined) attributes for this position.
1071 virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style);
1072 virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
1073
1074 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1075 /// context attributes.
1076 virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true);
1077
59509217
JS
1078 /// Get the combined style for a range - if any attribute is different within the range,
1079 /// that attribute is not present within the flags
1080 virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style);
1081
1082 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1083 /// content.
42688aea 1084 bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes);
59509217 1085
38f833b1
JS
1086 /// Set list style
1087 virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1088 virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1089
1090 /// Clear list for given range
1091 virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
1092
1093 /// Number/renumber any list elements in the given range.
1094 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
dadd4f55 1095 virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
38f833b1
JS
1096 virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1097
1098 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
1099 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
dadd4f55 1100 virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
38f833b1
JS
1101 virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
1102
1103 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
1104 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
1105 virtual bool DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
1106
d2d0adc7
JS
1107 /// Fills in the attributes for numbering a paragraph after previousParagraph.
1108 virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const;
1109
5d7836c4
JS
1110 /// Test if this whole range has character attributes of the specified kind. If any
1111 /// of the attributes are different within the range, the test fails. You
1112 /// can use this to implement, for example, bold button updating. style must have
1113 /// flags indicating which attributes are of interest.
1114 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const;
1115 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
1116
1117 /// Test if this whole range has paragraph attributes of the specified kind. If any
1118 /// of the attributes are different within the range, the test fails. You
1119 /// can use this to implement, for example, centering button updating. style must have
1120 /// flags indicating which attributes are of interest.
1121 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxTextAttrEx& style) const;
1122 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
1123
1124 /// Clone
1125 virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
1126
1127 /// Insert fragment into this box at the given position. If partialParagraph is true,
1128 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1129 /// marker.
0ca07313 1130 virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment);
5d7836c4
JS
1131
1132 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
0ca07313 1133 virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment);
5d7836c4 1134
fe5aa22c
JS
1135 /// Apply the style sheet to the buffer, for example if the styles have changed.
1136 virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
1137
5d7836c4
JS
1138 /// Copy
1139 void Copy(const wxRichTextParagraphLayoutBox& obj);
1140
0ca07313
JS
1141 /// Assignment
1142 void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); }
1143
5d7836c4
JS
1144 /// Calculate ranges
1145 virtual void UpdateRanges() { long end; CalculateRange(0, end); }
1146
1147 /// Get all the text
1148 virtual wxString GetText() const;
1149
1150 /// Set default style for new content. Setting it to a default attribute
1151 /// makes new content take on the 'basic' style.
1152 virtual bool SetDefaultStyle(const wxTextAttrEx& style);
1153
1154 /// Get default style
1155 virtual const wxTextAttrEx& GetDefaultStyle() const { return m_defaultAttributes; }
1156
1157 /// Set basic (overall) style
1158 virtual void SetBasicStyle(const wxTextAttrEx& style) { m_attributes = style; }
4d6d8bf4 1159 virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; }
5d7836c4
JS
1160
1161 /// Get basic (overall) style
1162 virtual const wxTextAttrEx& GetBasicStyle() const { return m_attributes; }
1163
38113684 1164 /// Invalidate the buffer. With no argument, invalidates whole buffer.
1e967276 1165 void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
38113684
JS
1166
1167 /// Get invalid range, rounding to entire paragraphs if argument is true.
1168 wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const;
1169
5d7836c4
JS
1170protected:
1171 wxRichTextCtrl* m_ctrl;
1172 wxTextAttrEx m_defaultAttributes;
38113684
JS
1173
1174 /// The invalidated range that will need full layout
0ca07313 1175 wxRichTextRange m_invalidRange;
5d7836c4
JS
1176
1177 // Is the last paragraph partial or complete?
0ca07313 1178 bool m_partialParagraph;
5d7836c4
JS
1179};
1180
1181/*!
1182 * wxRichTextLine class declaration
1183 * This object represents a line in a paragraph, and stores
1184 * offsets from the start of the paragraph representing the
1185 * start and end positions of the line.
1186 */
1187
3b2cb431 1188class WXDLLIMPEXP_RICHTEXT wxRichTextLine
5d7836c4
JS
1189{
1190public:
1191// Constructors
1192
1193 wxRichTextLine(wxRichTextParagraph* parent);
1e967276 1194 wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); }
5d7836c4
JS
1195 virtual ~wxRichTextLine() {}
1196
1197// Overrideables
1198
1199// Accessors
1200
1201 /// Set the range
1202 void SetRange(const wxRichTextRange& range) { m_range = range; }
1203 void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); }
1204
1205 /// Get the parent paragraph
1206 wxRichTextParagraph* GetParent() { return m_parent; }
1207
1208 /// Get the range
1209 const wxRichTextRange& GetRange() const { return m_range; }
1210 wxRichTextRange& GetRange() { return m_range; }
1211
1e967276
JS
1212 /// Get the absolute range
1213 wxRichTextRange GetAbsoluteRange() const;
1214
5d7836c4
JS
1215 /// Get/set the line size as calculated by Layout.
1216 virtual wxSize GetSize() const { return m_size; }
1217 virtual void SetSize(const wxSize& sz) { m_size = sz; }
1218
1219 /// Get/set the object position relative to the parent
1220 virtual wxPoint GetPosition() const { return m_pos; }
1221 virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
1222
1223 /// Get the absolute object position
1224 virtual wxPoint GetAbsolutePosition() const;
1225
1226 /// Get the rectangle enclosing the line
1227 virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
1228
1229 /// Set/get stored descent
1230 void SetDescent(int descent) { m_descent = descent; }
1231 int GetDescent() const { return m_descent; }
1232
1233// Operations
1234
1235 /// Initialisation
1e967276 1236 void Init(wxRichTextParagraph* parent);
5d7836c4
JS
1237
1238 /// Copy
1239 void Copy(const wxRichTextLine& obj);
1240
1241 /// Clone
1242 virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); }
1243
1244protected:
1245
1246 /// The range of the line (start position to end position)
1e967276 1247 /// This is relative to the parent paragraph.
5d7836c4
JS
1248 wxRichTextRange m_range;
1249
1250 /// Size and position measured relative to top of paragraph
1251 wxPoint m_pos;
1252 wxSize m_size;
1253
1254 /// Maximum descent for this line (location of text baseline)
1255 int m_descent;
1256
1257 // The parent object
1258 wxRichTextParagraph* m_parent;
1259};
1260
3b2cb431 1261WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT );
5d7836c4
JS
1262
1263/*!
1264 * wxRichTextParagraph class declaration
1265 * This object represents a single paragraph (or in a straight text editor, a line).
1266 */
1267
3b2cb431 1268class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextBox
5d7836c4
JS
1269{
1270 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph)
1271public:
1272// Constructors
1273
1274 wxRichTextParagraph(wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
4f32b3cf 1275 wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxTextAttrEx* paraStyle = NULL, wxTextAttrEx* charStyle = NULL);
d3c7fc99 1276 virtual ~wxRichTextParagraph();
0ca07313 1277 wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextBox() { Copy(obj); }
5d7836c4
JS
1278
1279// Overrideables
1280
1281 /// Draw the item
1282 virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
1283
1284 /// Lay the item out
38113684 1285 virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
5d7836c4
JS
1286
1287 /// Get/set the object size for the given range. Returns false if the range
1288 /// is invalid for this object.
7f0d9d71 1289 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
5d7836c4
JS
1290
1291 /// Finds the absolute position and row height for the given character position
1292 virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart);
1293
1294 /// Hit-testing: returns a flag indicating hit test details, plus
1295 /// information about position
1296 virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition);
1297
1298 /// Calculate range
1299 virtual void CalculateRange(long start, long& end);
1300
1301// Accessors
1302
1303 /// Get the cached lines
1304 wxRichTextLineList& GetLines() { return m_cachedLines; }
1305
1306// Operations
1307
1308 /// Copy
1309 void Copy(const wxRichTextParagraph& obj);
1310
1311 /// Clone
1312 virtual wxRichTextObject* Clone() const { return new wxRichTextParagraph(*this); }
1313
1314 /// Clear the cached lines
1315 void ClearLines();
1316
1317// Implementation
1318
1319 /// Apply paragraph styles such as centering to the wrapped lines
fe5aa22c 1320 virtual void ApplyParagraphStyle(const wxTextAttrEx& attr, const wxRect& rect);
5d7836c4
JS
1321
1322 /// Insert text at the given position
1323 virtual bool InsertText(long pos, const wxString& text);
1324
1325 /// Split an object at this position if necessary, and return
1326 /// the previous object, or NULL if inserting at beginning.
1327 virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL);
1328
1329 /// Move content to a list from this point
1330 virtual void MoveToList(wxRichTextObject* obj, wxList& list);
1331
1332 /// Add content back from list
1333 virtual void MoveFromList(wxList& list);
1334
1335 /// Get the plain text searching from the start or end of the range.
1336 /// The resulting string may be shorter than the range given.
1337 bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true);
1338
1339 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1340 /// of the split.
1341 bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition);
1342
1343 /// Find the object at the given position
1344 wxRichTextObject* FindObjectAtPosition(long position);
1345
1346 /// Get the bullet text for this paragraph.
1347 wxString GetBulletText();
1348
1e967276
JS
1349 /// Allocate or reuse a line object
1350 wxRichTextLine* AllocateLine(int pos);
1351
1352 /// Clear remaining unused line objects, if any
1353 bool ClearUnusedLines(int lineCount);
1354
fe5aa22c
JS
1355 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1356 /// retrieve the actual style.
59509217 1357 wxTextAttrEx GetCombinedAttributes(const wxTextAttrEx& contentStyle) const;
fe5aa22c
JS
1358
1359 /// Get combined attributes of the base style and paragraph style.
1360 wxTextAttrEx GetCombinedAttributes() const;
1361
ff76711f
JS
1362 /// Get the first position from pos that has a line break character.
1363 long GetFirstLineBreakPosition(long pos);
1364
cfa3b256
JS
1365 /// Create default tabstop array
1366 static void InitDefaultTabs();
1367
1368 /// Clear default tabstop array
1369 static void ClearDefaultTabs();
1370
1371 /// Get default tabstop array
1372 static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; }
1373
5d7836c4
JS
1374protected:
1375 /// The lines that make up the wrapped paragraph
1376 wxRichTextLineList m_cachedLines;
cfa3b256
JS
1377
1378 /// Default tabstops
1379 static wxArrayInt sm_defaultTabs;
5d7836c4
JS
1380};
1381
1382/*!
1383 * wxRichTextPlainText class declaration
1384 * This object represents a single piece of text.
1385 */
1386
3b2cb431 1387class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject
5d7836c4
JS
1388{
1389 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText)
1390public:
1391// Constructors
1392
1393 wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxTextAttrEx* style = NULL);
0ca07313 1394 wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); }
5d7836c4
JS
1395
1396// Overrideables
1397
1398 /// Draw the item
1399 virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
1400
1401 /// Lay the item out
38113684 1402 virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
5d7836c4
JS
1403
1404 /// Get/set the object size for the given range. Returns false if the range
1405 /// is invalid for this object.
7f0d9d71 1406 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position/* = wxPoint(0,0)*/) const;
5d7836c4
JS
1407
1408 /// Get any text in this object for the given range
1409 virtual wxString GetTextForRange(const wxRichTextRange& range) const;
1410
1411 /// Do a split, returning an object containing the second part, and setting
1412 /// the first part in 'this'.
1413 virtual wxRichTextObject* DoSplit(long pos);
1414
1415 /// Calculate range
1416 virtual void CalculateRange(long start, long& end);
1417
1418 /// Delete range
1419 virtual bool DeleteRange(const wxRichTextRange& range);
1420
1421 /// Returns true if the object is empty
7fe8059f 1422 virtual bool IsEmpty() const { return m_text.empty(); }
5d7836c4
JS
1423
1424 /// Returns true if this object can merge itself with the given one.
1425 virtual bool CanMerge(wxRichTextObject* object) const;
1426
1427 /// Returns true if this object merged itself with the given one.
1428 /// The calling code will then delete the given object.
1429 virtual bool Merge(wxRichTextObject* object);
1430
1431 /// Dump to output stream for debugging
1432 virtual void Dump(wxTextOutputStream& stream);
1433
ff76711f
JS
1434 /// Get the first position from pos that has a line break character.
1435 long GetFirstLineBreakPosition(long pos);
1436
5d7836c4
JS
1437// Accessors
1438
1439 /// Get the text
1440 const wxString& GetText() const { return m_text; }
1441
1442 /// Set the text
1443 void SetText(const wxString& text) { m_text = text; }
1444
1445// Operations
1446
1447 /// Copy
1448 void Copy(const wxRichTextPlainText& obj);
1449
1450 /// Clone
1451 virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); }
7f0d9d71 1452private:
fe5aa22c 1453 bool DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected);
5d7836c4
JS
1454
1455protected:
1456 wxString m_text;
1457};
1458
1459/*!
1460 * wxRichTextImageBlock stores information about an image, in binary in-memory form
1461 */
1462
1463class WXDLLIMPEXP_BASE wxDataInputStream;
1464class WXDLLIMPEXP_BASE wxDataOutputStream;
1465
3b2cb431 1466class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject
5d7836c4
JS
1467{
1468public:
1469 wxRichTextImageBlock();
1470 wxRichTextImageBlock(const wxRichTextImageBlock& block);
d3c7fc99 1471 virtual ~wxRichTextImageBlock();
5d7836c4
JS
1472
1473 void Init();
1474 void Clear();
1475
1476 // Load the original image into a memory block.
1477 // If the image is not a JPEG, we must convert it into a JPEG
1478 // to conserve space.
1479 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1480 // load the image a 2nd time.
7fe8059f 1481 virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true);
5d7836c4
JS
1482
1483 // Make an image block from the wxImage in the given
1484 // format.
1485 virtual bool MakeImageBlock(wxImage& image, int imageType, int quality = 80);
1486
1487 // Write to a file
1488 bool Write(const wxString& filename);
1489
1490 // Write data in hex to a stream
1491 bool WriteHex(wxOutputStream& stream);
1492
1493 // Read data in hex from a stream
1494 bool ReadHex(wxInputStream& stream, int length, int imageType);
1495
1496 // Copy from 'block'
1497 void Copy(const wxRichTextImageBlock& block);
1498
1499 // Load a wxImage from the block
1500 bool Load(wxImage& image);
1501
1502//// Operators
1503 void operator=(const wxRichTextImageBlock& block);
1504
1505//// Accessors
1506
1507 unsigned char* GetData() const { return m_data; }
1508 size_t GetDataSize() const { return m_dataSize; }
1509 int GetImageType() const { return m_imageType; }
1510
1511 void SetData(unsigned char* image) { m_data = image; }
1512 void SetDataSize(size_t size) { m_dataSize = size; }
1513 void SetImageType(int imageType) { m_imageType = imageType; }
1514
b7cacb43
VZ
1515 bool Ok() const { return IsOk(); }
1516 bool IsOk() const { return GetData() != NULL; }
5d7836c4 1517
d2d0adc7
JS
1518 // Gets the extension for the block's type
1519 wxString GetExtension() const;
1520
5d7836c4
JS
1521/// Implementation
1522
d2d0adc7 1523 // Allocate and read from stream as a block of memory
5d7836c4
JS
1524 static unsigned char* ReadBlock(wxInputStream& stream, size_t size);
1525 static unsigned char* ReadBlock(const wxString& filename, size_t size);
1526
1527 // Write memory block to stream
1528 static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size);
1529
1530 // Write memory block to file
1531 static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size);
1532
1533protected:
1534 // Size in bytes of the image stored.
1535 // This is in the raw, original form such as a JPEG file.
1536 unsigned char* m_data;
1537 size_t m_dataSize;
1538 int m_imageType; // wxWin type id
1539};
1540
1541
1542/*!
1543 * wxRichTextImage class declaration
1544 * This object represents an image.
1545 */
1546
3b2cb431 1547class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
5d7836c4
JS
1548{
1549 DECLARE_DYNAMIC_CLASS(wxRichTextImage)
1550public:
1551// Constructors
1552
0ca07313 1553 wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextObject(parent) { }
4f32b3cf
JS
1554 wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL);
1555 wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxTextAttrEx* charStyle = NULL);
0ca07313 1556 wxRichTextImage(const wxRichTextImage& obj): wxRichTextObject() { Copy(obj); }
5d7836c4
JS
1557
1558// Overrideables
1559
1560 /// Draw the item
1561 virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
1562
1563 /// Lay the item out
38113684 1564 virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
5d7836c4
JS
1565
1566 /// Get the object size for the given range. Returns false if the range
1567 /// is invalid for this object.
7f0d9d71 1568 virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
5d7836c4
JS
1569
1570 /// Returns true if the object is empty
1571 virtual bool IsEmpty() const { return !m_image.Ok(); }
1572
1573// Accessors
1574
1575 /// Get the image
1576 const wxImage& GetImage() const { return m_image; }
1577
1578 /// Set the image
1579 void SetImage(const wxImage& image) { m_image = image; }
1580
1581 /// Get the image block containing the raw data
1582 wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; }
1583
1584// Operations
1585
1586 /// Copy
1587 void Copy(const wxRichTextImage& obj);
1588
1589 /// Clone
1590 virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); }
1591
1592 /// Load wxImage from the block
1593 virtual bool LoadFromBlock();
1594
1595 /// Make block from the wxImage
1596 virtual bool MakeBlock();
1597
1598protected:
1599 // TODO: reduce the multiple representations of data
1600 wxImage m_image;
1601 wxBitmap m_bitmap;
1602 wxRichTextImageBlock m_imageBlock;
1603};
1604
1605
1606/*!
1607 * wxRichTextBuffer class declaration
1608 * This is a kind of box, used to represent the whole buffer
1609 */
1610
3b2cb431
JS
1611class WXDLLIMPEXP_RICHTEXT wxRichTextCommand;
1612class WXDLLIMPEXP_RICHTEXT wxRichTextAction;
5d7836c4 1613
3b2cb431 1614class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox
5d7836c4
JS
1615{
1616 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)
1617public:
1618// Constructors
1619
1620 wxRichTextBuffer() { Init(); }
0ca07313 1621 wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
d3c7fc99 1622 virtual ~wxRichTextBuffer() ;
5d7836c4
JS
1623
1624// Accessors
1625
1626 /// Gets the command processor
1627 wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; }
1628
1629 /// Set style sheet, if any.
1630 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
38f833b1
JS
1631 virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
1632
d2d0adc7
JS
1633 /// Set style sheet and notify of the change
1634 bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet);
1635
38f833b1
JS
1636 /// Push style sheet to top of stack
1637 bool PushStyleSheet(wxRichTextStyleSheet* styleSheet);
1638
1639 /// Pop style sheet from top of stack
1640 wxRichTextStyleSheet* PopStyleSheet();
5d7836c4
JS
1641
1642// Operations
1643
1644 /// Initialisation
1645 void Init();
1646
85d8909b
JS
1647 /// Clears the buffer, adds an empty paragraph, and clears the command processor.
1648 virtual void ResetAndClearCommands();
5d7836c4
JS
1649
1650 /// Load a file
1651 virtual bool LoadFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
1652
1653 /// Save a file
1654 virtual bool SaveFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
1655
1656 /// Load from a stream
1657 virtual bool LoadFile(wxInputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
1658
1659 /// Save to a stream
1660 virtual bool SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
1661
d2d0adc7
JS
1662 /// Set the handler flags, controlling loading and saving
1663 void SetHandlerFlags(int flags) { m_handlerFlags = flags; }
1664
1665 /// Get the handler flags, controlling loading and saving
1666 int GetHandlerFlags() const { return m_handlerFlags; }
1667
5d7836c4 1668 /// Convenience function to add a paragraph of text
0ca07313 1669 virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); }
5d7836c4
JS
1670
1671 /// Begin collapsing undo/redo commands. Note that this may not work properly
1672 /// if combining commands that delete or insert content, changing ranges for
1673 /// subsequent actions.
1674 virtual bool BeginBatchUndo(const wxString& cmdName);
1675
1676 /// End collapsing undo/redo commands
1677 virtual bool EndBatchUndo();
1678
1679 /// Collapsing commands?
1680 virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; }
1681
1682 /// Submit immediately, or delay according to whether collapsing is on
1683 virtual bool SubmitAction(wxRichTextAction* action);
1684
1685 /// Get collapsed command
1686 virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; }
1687
1688 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1689 /// differently by each command. If not dealt with by a command implementation, then
1690 /// it will be implemented automatically by not storing the command in the undo history
1691 /// when the action is submitted to the command processor.
1692 virtual bool BeginSuppressUndo();
1693
1694 /// End suppressing undo/redo commands.
1695 virtual bool EndSuppressUndo();
1696
1697 /// Collapsing commands?
1698 virtual bool SuppressingUndo() const { return m_suppressUndo > 0; }
1699
1700 /// Copy the range to the clipboard
1701 virtual bool CopyToClipboard(const wxRichTextRange& range);
1702
1703 /// Paste the clipboard content to the buffer
1704 virtual bool PasteFromClipboard(long position);
1705
1706 /// Can we paste from the clipboard?
1707 virtual bool CanPasteFromClipboard() const;
1708
1709 /// Begin using a style
1710 virtual bool BeginStyle(const wxTextAttrEx& style);
1711
1712 /// End the style
1713 virtual bool EndStyle();
1714
1715 /// End all styles
1716 virtual bool EndAllStyles();
1717
1718 /// Clear the style stack
1719 virtual void ClearStyleStack();
1720
1721 /// Get the size of the style stack, for example to check correct nesting
3b38e2a0 1722 virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); }
5d7836c4
JS
1723
1724 /// Begin using bold
1725 bool BeginBold();
1726
1727 /// End using bold
1728 bool EndBold() { return EndStyle(); }
1729
1730 /// Begin using italic
1731 bool BeginItalic();
1732
1733 /// End using italic
1734 bool EndItalic() { return EndStyle(); }
1735
1736 /// Begin using underline
1737 bool BeginUnderline();
1738
1739 /// End using underline
1740 bool EndUnderline() { return EndStyle(); }
1741
1742 /// Begin using point size
1743 bool BeginFontSize(int pointSize);
1744
1745 /// End using point size
1746 bool EndFontSize() { return EndStyle(); }
1747
1748 /// Begin using this font
1749 bool BeginFont(const wxFont& font);
1750
1751 /// End using a font
1752 bool EndFont() { return EndStyle(); }
1753
1754 /// Begin using this colour
1755 bool BeginTextColour(const wxColour& colour);
1756
1757 /// End using a colour
1758 bool EndTextColour() { return EndStyle(); }
1759
1760 /// Begin using alignment
1761 bool BeginAlignment(wxTextAttrAlignment alignment);
1762
1763 /// End alignment
1764 bool EndAlignment() { return EndStyle(); }
1765
1766 /// Begin left indent
1767 bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0);
1768
1769 /// End left indent
1770 bool EndLeftIndent() { return EndStyle(); }
1771
1772 /// Begin right indent
1773 bool BeginRightIndent(int rightIndent);
1774
1775 /// End right indent
1776 bool EndRightIndent() { return EndStyle(); }
1777
1778 /// Begin paragraph spacing
1779 bool BeginParagraphSpacing(int before, int after);
1780
1781 /// End paragraph spacing
1782 bool EndParagraphSpacing() { return EndStyle(); }
1783
1784 /// Begin line spacing
1785 bool BeginLineSpacing(int lineSpacing);
1786
1787 /// End line spacing
1788 bool EndLineSpacing() { return EndStyle(); }
1789
1790 /// Begin numbered bullet
1791 bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD);
1792
1793 /// End numbered bullet
1794 bool EndNumberedBullet() { return EndStyle(); }
1795
1796 /// Begin symbol bullet
d2d0adc7 1797 bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL);
5d7836c4
JS
1798
1799 /// End symbol bullet
1800 bool EndSymbolBullet() { return EndStyle(); }
1801
f089713f
JS
1802 /// Begin standard bullet
1803 bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD);
1804
1805 /// End standard bullet
1806 bool EndStandardBullet() { return EndStyle(); }
1807
5d7836c4
JS
1808 /// Begin named character style
1809 bool BeginCharacterStyle(const wxString& characterStyle);
1810
1811 /// End named character style
1812 bool EndCharacterStyle() { return EndStyle(); }
1813
1814 /// Begin named paragraph style
1815 bool BeginParagraphStyle(const wxString& paragraphStyle);
1816
1817 /// End named character style
1818 bool EndParagraphStyle() { return EndStyle(); }
f089713f
JS
1819
1820 /// Begin named list style
1821 bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1);
1822
1823 /// End named character style
1824 bool EndListStyle() { return EndStyle(); }
5d7836c4 1825
d2d0adc7
JS
1826 /// Begin URL
1827 bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString);
1828
1829 /// End URL
1830 bool EndURL() { return EndStyle(); }
1831
1832// Event handling
1833
1834 /// Add an event handler
1835 bool AddEventHandler(wxEvtHandler* handler);
1836
1837 /// Remove an event handler
1838 bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false);
1839
1840 /// Clear event handlers
1841 void ClearEventHandlers();
1842
1843 /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
1844 /// otherwise will stop at the first successful one.
1845 bool SendEvent(wxEvent& event, bool sendToAll = true);
1846
5d7836c4
JS
1847// Implementation
1848
1849 /// Copy
0ca07313 1850 void Copy(const wxRichTextBuffer& obj);
5d7836c4
JS
1851
1852 /// Clone
1853 virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
1854
0ca07313
JS
1855 /// Submit command to insert paragraphs
1856 bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0);
1857
5d7836c4 1858 /// Submit command to insert the given text
fe5aa22c 1859 bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
5d7836c4
JS
1860
1861 /// Submit command to insert a newline
fe5aa22c 1862 bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0);
5d7836c4
JS
1863
1864 /// Submit command to insert the given image
fe5aa22c 1865 bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0);
5d7836c4
JS
1866
1867 /// Submit command to delete this range
12cc29c5 1868 bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl);
5d7836c4
JS
1869
1870 /// Mark modified
1871 void Modify(bool modify = true) { m_modified = modify; }
1872 bool IsModified() const { return m_modified; }
1873
fe5aa22c
JS
1874 /// Get the style that is appropriate for a new paragraph at this position.
1875 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1876 /// style.
d8dd53b2 1877 wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const;
fe5aa22c 1878
5d7836c4
JS
1879 /// Dumps contents of buffer for debugging purposes
1880 virtual void Dump();
1881 virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }
1882
1883 /// Returns the file handlers
1884 static wxList& GetHandlers() { return sm_handlers; }
1885
1886 /// Adds a handler to the end
1887 static void AddHandler(wxRichTextFileHandler *handler);
1888
1889 /// Inserts a handler at the front
1890 static void InsertHandler(wxRichTextFileHandler *handler);
1891
1892 /// Removes a handler
1893 static bool RemoveHandler(const wxString& name);
1894
1895 /// Finds a handler by name
1896 static wxRichTextFileHandler *FindHandler(const wxString& name);
1897
1898 /// Finds a handler by extension and type
1899 static wxRichTextFileHandler *FindHandler(const wxString& extension, int imageType);
1900
1901 /// Finds a handler by filename or, if supplied, type
1902 static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, int imageType);
1903
1904 /// Finds a handler by type
1905 static wxRichTextFileHandler *FindHandler(int imageType);
1906
1e967276
JS
1907 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1908 /// will be filled with the file type corresponding to each filter. This can be
1909 /// used to determine the type to pass to LoadFile given a selected filter.
1910 static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL);
5d7836c4
JS
1911
1912 /// Clean up handlers
1913 static void CleanUpHandlers();
1914
1915 /// Initialise the standard handlers
1916 static void InitStandardHandlers();
1917
d2d0adc7
JS
1918 /// Get renderer
1919 static wxRichTextRenderer* GetRenderer() { return sm_renderer; }
1920
1921 /// Set renderer, deleting old one
1922 static void SetRenderer(wxRichTextRenderer* renderer);
1923
1924 /// Minimum margin between bullet and paragraph in 10ths of a mm
1925 static int GetBulletRightMargin() { return sm_bulletRightMargin; }
1926 static void SetBulletRightMargin(int margin) { sm_bulletRightMargin = margin; }
1927
1928 /// Factor to multiply by character height to get a reasonable bullet size
1929 static float GetBulletProportion() { return sm_bulletProportion; }
1930 static void SetBulletProportion(float prop) { sm_bulletProportion = prop; }
44219ff0
JS
1931
1932 /// Scale factor for calculating dimensions
1933 double GetScale() const { return m_scale; }
1934 void SetScale(double scale) { m_scale = scale; }
1935
5d7836c4
JS
1936protected:
1937
1938 /// Command processor
1939 wxCommandProcessor* m_commandProcessor;
1940
1941 /// Has been modified?
1942 bool m_modified;
1943
1944 /// Collapsed command stack
1945 int m_batchedCommandDepth;
1946
1947 /// Name for collapsed command
1948 wxString m_batchedCommandsName;
1949
1950 /// Current collapsed command accumulating actions
1951 wxRichTextCommand* m_batchedCommand;
1952
1953 /// Whether to suppress undo
1954 int m_suppressUndo;
1955
1956 /// Style sheet, if any
1957 wxRichTextStyleSheet* m_styleSheet;
1958
d2d0adc7
JS
1959 /// List of event handlers that will be notified of events
1960 wxList m_eventHandlers;
1961
5d7836c4
JS
1962 /// Stack of attributes for convenience functions
1963 wxList m_attributeStack;
1964
d2d0adc7
JS
1965 /// Flags to be passed to handlers
1966 int m_handlerFlags;
1967
5d7836c4
JS
1968 /// File handlers
1969 static wxList sm_handlers;
d2d0adc7
JS
1970
1971 /// Renderer
1972 static wxRichTextRenderer* sm_renderer;
1973
1974 /// Minimum margin between bullet and paragraph in 10ths of a mm
1975 static int sm_bulletRightMargin;
1976
1977 /// Factor to multiply by character height to get a reasonable bullet size
1978 static float sm_bulletProportion;
44219ff0
JS
1979
1980 /// Scaling factor in use: needed to calculate correct dimensions when printing
1981 double m_scale;
5d7836c4
JS
1982};
1983
1984/*!
1985 * The command identifiers
1986 *
1987 */
1988
1989enum wxRichTextCommandId
1990{
1991 wxRICHTEXT_INSERT,
1992 wxRICHTEXT_DELETE,
1993 wxRICHTEXT_CHANGE_STYLE
1994};
1995
1996/*!
1997 * Command classes for undo/redo
1998 *
1999 */
2000
3b2cb431
JS
2001class WXDLLIMPEXP_RICHTEXT wxRichTextAction;
2002class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand
5d7836c4
JS
2003{
2004public:
2005 // Ctor for one action
2006 wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
7fe8059f 2007 wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
5d7836c4
JS
2008
2009 // Ctor for multiple actions
2010 wxRichTextCommand(const wxString& name);
2011
d3c7fc99 2012 virtual ~wxRichTextCommand();
5d7836c4
JS
2013
2014 bool Do();
2015 bool Undo();
2016
2017 void AddAction(wxRichTextAction* action);
2018 void ClearActions();
2019
2020 wxList& GetActions() { return m_actions; }
2021
2022protected:
2023
2024 wxList m_actions;
2025};
2026
2027/*!
2028 * wxRichTextAction class declaration
2029 * There can be more than one action in a command.
2030 */
2031
3b2cb431 2032class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject
5d7836c4
JS
2033{
2034public:
2035 wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
7fe8059f 2036 wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
5d7836c4 2037
d3c7fc99 2038 virtual ~wxRichTextAction();
5d7836c4
JS
2039
2040 bool Do();
2041 bool Undo();
2042
2043 /// Update the control appearance
ea160b2e
JS
2044 void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false,
2045 wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL);
5d7836c4
JS
2046
2047 /// Replace the buffer paragraphs with the given fragment.
0ca07313 2048 void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment);
5d7836c4
JS
2049
2050 /// Get the fragments
0ca07313
JS
2051 wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; }
2052 wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; }
5d7836c4
JS
2053
2054 /// Set/get the position used for e.g. insertion
2055 void SetPosition(long pos) { m_position = pos; }
2056 long GetPosition() const { return m_position; }
2057
2058 /// Set/get the range for e.g. deletion
2059 void SetRange(const wxRichTextRange& range) { m_range = range; }
2060 const wxRichTextRange& GetRange() const { return m_range; }
2061
2062 /// Get name
2063 const wxString& GetName() const { return m_name; }
2064
2065protected:
2066 // Action name
2067 wxString m_name;
2068
2069 // Buffer
2070 wxRichTextBuffer* m_buffer;
2071
2072 // Control
2073 wxRichTextCtrl* m_ctrl;
2074
2075 // Stores the new paragraphs
0ca07313 2076 wxRichTextParagraphLayoutBox m_newParagraphs;
5d7836c4
JS
2077
2078 // Stores the old paragraphs
0ca07313 2079 wxRichTextParagraphLayoutBox m_oldParagraphs;
5d7836c4
JS
2080
2081 // The affected range
2082 wxRichTextRange m_range;
2083
2084 // The insertion point for this command
2085 long m_position;
2086
2087 // Ignore 1st 'Do' operation because we already did it
2088 bool m_ignoreThis;
2089
2090 // The command identifier
2091 wxRichTextCommandId m_cmdId;
2092};
2093
d2d0adc7
JS
2094/*!
2095 * Handler flags
2096 */
2097
2098// Include style sheet when loading and saving
2099#define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001
2100
2101// Save images to memory file system in HTML handler
2102#define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010
2103
2104// Save images to files in HTML handler
2105#define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020
2106
2107// Save images as inline base64 data in HTML handler
2108#define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040
2109
b774c698
JS
2110// Don't write header and footer (or BODY), so we can include the fragment
2111// in a larger document
2112#define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080
2113
5d7836c4
JS
2114/*!
2115 * wxRichTextFileHandler
2116 * Base class for file handlers
2117 */
2118
3b2cb431 2119class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject
5d7836c4
JS
2120{
2121 DECLARE_CLASS(wxRichTextFileHandler)
2122public:
2123 wxRichTextFileHandler(const wxString& name = wxEmptyString, const wxString& ext = wxEmptyString, int type = 0)
d8dd214c 2124 : m_name(name), m_extension(ext), m_type(type), m_flags(0), m_visible(true)
5d7836c4
JS
2125 { }
2126
2127#if wxUSE_STREAMS
7fe8059f
WS
2128 bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
2129 { return DoLoadFile(buffer, stream); }
2130 bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
2131 { return DoSaveFile(buffer, stream); }
5d7836c4
JS
2132#endif
2133
7fe8059f
WS
2134 bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename);
2135 bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename);
5d7836c4
JS
2136
2137 /// Can we handle this filename (if using files)? By default, checks the extension.
2138 virtual bool CanHandle(const wxString& filename) const;
2139
2140 /// Can we save using this handler?
2141 virtual bool CanSave() const { return false; }
2142
2143 /// Can we load using this handler?
2144 virtual bool CanLoad() const { return false; }
2145
2146 /// Should this handler be visible to the user?
2147 virtual bool IsVisible() const { return m_visible; }
2148 virtual void SetVisible(bool visible) { m_visible = visible; }
2149
b71e9aa4 2150 /// The name of the nandler
5d7836c4
JS
2151 void SetName(const wxString& name) { m_name = name; }
2152 wxString GetName() const { return m_name; }
2153
b71e9aa4 2154 /// The default extension to recognise
5d7836c4
JS
2155 void SetExtension(const wxString& ext) { m_extension = ext; }
2156 wxString GetExtension() const { return m_extension; }
2157
b71e9aa4 2158 /// The handler type
5d7836c4
JS
2159 void SetType(int type) { m_type = type; }
2160 int GetType() const { return m_type; }
2161
d2d0adc7
JS
2162 /// Flags controlling how loading and saving is done
2163 void SetFlags(int flags) { m_flags = flags; }
2164 int GetFlags() const { return m_flags; }
2165
b71e9aa4
JS
2166 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
2167 void SetEncoding(const wxString& encoding) { m_encoding = encoding; }
2168 const wxString& GetEncoding() const { return m_encoding; }
2169
5d7836c4
JS
2170protected:
2171
7fe8059f
WS
2172#if wxUSE_STREAMS
2173 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0;
2174 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0;
2175#endif
2176
5d7836c4 2177 wxString m_name;
b71e9aa4 2178 wxString m_encoding;
5d7836c4
JS
2179 wxString m_extension;
2180 int m_type;
d2d0adc7 2181 int m_flags;
5d7836c4
JS
2182 bool m_visible;
2183};
2184
2185/*!
2186 * wxRichTextPlainTextHandler
2187 * Plain text handler
2188 */
2189
3b2cb431 2190class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler
5d7836c4
JS
2191{
2192 DECLARE_CLASS(wxRichTextPlainTextHandler)
2193public:
2194 wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), const wxString& ext = wxT("txt"), int type = wxRICHTEXT_TYPE_TEXT)
2195 : wxRichTextFileHandler(name, ext, type)
2196 { }
2197
5d7836c4
JS
2198 /// Can we save using this handler?
2199 virtual bool CanSave() const { return true; }
2200
2201 /// Can we load using this handler?
2202 virtual bool CanLoad() const { return true; }
2203
2204protected:
2205
7fe8059f
WS
2206#if wxUSE_STREAMS
2207 virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
2208 virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
2209#endif
2210
5d7836c4
JS
2211};
2212
0ca07313
JS
2213#if wxUSE_DATAOBJ
2214
2215/*!
2216 * The data object for a wxRichTextBuffer
2217 */
2218
d2d0adc7 2219class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple
0ca07313
JS
2220{
2221public:
2222 // ctor doesn't copy the pointer, so it shouldn't go away while this object
2223 // is alive
2224 wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = (wxRichTextBuffer*) NULL);
2225 virtual ~wxRichTextBufferDataObject();
2226
2227 // after a call to this function, the buffer is owned by the caller and it
2228 // is responsible for deleting it
2229 wxRichTextBuffer* GetRichTextBuffer();
2230
2231 // Returns the id for the new data format
2232 static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; }
2233
2234 // base class pure virtuals
2235
2236 virtual wxDataFormat GetPreferredFormat(Direction dir) const;
2237 virtual size_t GetDataSize() const;
2238 virtual bool GetDataHere(void *pBuf) const;
2239 virtual bool SetData(size_t len, const void *buf);
2240
2241 // prevent warnings
2242
2243 virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); }
2244 virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); }
2245 virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); }
2246
2247private:
2248 wxDataFormat m_formatRichTextBuffer; // our custom format
2249 wxRichTextBuffer* m_richTextBuffer; // our data
2250 static const wxChar* ms_richTextBufferFormatId; // our format id
2251};
2252
2253#endif
2254
d2d0adc7
JS
2255/*!
2256 * wxRichTextRenderer isolates common drawing functionality
2257 */
2258
2259class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer: public wxObject
2260{
2261public:
2262 wxRichTextRenderer() {}
2263 virtual ~wxRichTextRenderer() {}
2264
2265 /// Draw a standard bullet, as specified by the value of GetBulletName
2266 virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0;
2267
2268 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2269 virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text) = 0;
2270
2271 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2272 virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect) = 0;
2273
2274 /// Enumerate the standard bullet names currently supported
2275 virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0;
2276};
2277
2278/*!
2279 * wxRichTextStdRenderer: standard renderer
2280 */
2281
2282class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer: public wxRichTextRenderer
2283{
2284public:
2285 wxRichTextStdRenderer() {}
2286
2287 /// Draw a standard bullet, as specified by the value of GetBulletName
2288 virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect);
2289
2290 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2291 virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text);
2292
2293 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2294 virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect);
2295
2296 /// Enumerate the standard bullet names currently supported
2297 virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames);
2298};
2299
5d7836c4
JS
2300/*!
2301 * Utilities
2302 *
2303 */
2304
2305inline bool wxRichTextHasStyle(int flags, int style)
2306{
2307 return ((flags & style) == style);
2308}
2309
2310/// Compare two attribute objects
d2d0adc7
JS
2311WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2);
2312WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxTextAttr& attr1, const wxRichTextAttr& attr2);
5d7836c4
JS
2313
2314/// Compare two attribute objects, but take into account the flags
2315/// specifying attributes of interest.
d2d0adc7
JS
2316WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxTextAttrEx& attr2, int flags);
2317WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxTextAttrEx& attr1, const wxRichTextAttr& attr2, int flags);
5d7836c4
JS
2318
2319/// Apply one style to another
d2d0adc7
JS
2320WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxTextAttrEx& style);
2321WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style);
2322WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL);
8871035d 2323WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL);
59509217 2324
aeb6ebe2
JS
2325// Remove attributes
2326WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style);
2327
42688aea
JS
2328/// Combine two bitlists
2329WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB);
2330
2331/// Compare two bitlists
2332WXDLLIMPEXP_RICHTEXT bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags);
2333
4f32b3cf
JS
2334/// Split into paragraph and character styles
2335WXDLLIMPEXP_RICHTEXT bool wxRichTextSplitParaCharStyles(const wxTextAttrEx& style, wxTextAttrEx& parStyle, wxTextAttrEx& charStyle);
2336
59509217 2337/// Compare tabs
d2d0adc7 2338WXDLLIMPEXP_RICHTEXT bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2);
59509217
JS
2339
2340/// Set the font without changing the font attributes
d2d0adc7 2341WXDLLIMPEXP_RICHTEXT void wxSetFontPreservingStyles(wxTextAttr& attr, const wxFont& font);
59509217
JS
2342
2343/// Convert a decimal to Roman numerals
d2d0adc7 2344WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n);
f1d6804f
RD
2345
2346WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit();
2347
5d7836c4
JS
2348#endif
2349 // wxUSE_RICHTEXT
2350
2351#endif
2352 // _WX_RICHTEXTBUFFER_H_
d2d0adc7 2353