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