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