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