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