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