1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextbuffer.h
3 // Purpose: Buffer for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTBUFFER_H_
13 #define _WX_RICHTEXTBUFFER_H_
20 Data is represented by a hierarchy of objects, all derived from
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.
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.
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.
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.
63 #include "wx/textctrl.h"
64 #include "wx/bitmap.h"
66 #include "wx/cmdproc.h"
67 #include "wx/txtstrm.h"
70 #include "wx/dataobj.h"
74 #define wxRichTextAttr wxTextAttr
75 #define wxTextAttrEx wxTextAttr
77 // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a
78 // caret reliably without using wxClientDC in case there
79 // are platform-specific problems with the generic caret.
80 #if defined(__WXGTK__) || defined(__WXMAC__)
81 #define wxRICHTEXT_USE_OWN_CARET 1
83 #define wxRICHTEXT_USE_OWN_CARET 0
86 // Switch off for binary compatibility, on for faster drawing
87 // Note: this seems to be buggy (overzealous use of extents) so
89 #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0
95 extern WXDLLIMPEXP_RICHTEXT
const wxChar wxRichTextLineBreakChar
;
98 * File types in wxRichText context.
100 enum wxRichTextFileType
102 wxRICHTEXT_TYPE_ANY
= 0,
103 wxRICHTEXT_TYPE_TEXT
,
105 wxRICHTEXT_TYPE_HTML
,
111 * Forward declarations
114 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl
;
115 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject
;
116 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage
;
117 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject
;
118 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList
;
119 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine
;
120 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph
;
121 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler
;
122 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet
;
123 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition
;
124 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent
;
125 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer
;
126 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer
;
127 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAnchoredObject
;
128 class wxRichTextFloatCollector
;
131 * Flags determining the available space, passed to Layout
134 #define wxRICHTEXT_FIXED_WIDTH 0x01
135 #define wxRICHTEXT_FIXED_HEIGHT 0x02
136 #define wxRICHTEXT_VARIABLE_WIDTH 0x04
137 #define wxRICHTEXT_VARIABLE_HEIGHT 0x08
139 // Only lay out the part of the buffer that lies within
140 // the rect passed to Layout.
141 #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10
144 * Flags to pass to Draw
147 // Ignore paragraph cache optimization, e.g. for printing purposes
148 // where one line may be drawn higher (on the next page) compared
149 // with the previous line
150 #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01
153 * Flags returned from hit-testing
155 enum wxRichTextHitTestFlags
157 // The point was not on this object
158 wxRICHTEXT_HITTEST_NONE
= 0x01,
160 // The point was before the position returned from HitTest
161 wxRICHTEXT_HITTEST_BEFORE
= 0x02,
163 // The point was after the position returned from HitTest
164 wxRICHTEXT_HITTEST_AFTER
= 0x04,
166 // The point was on the position returned from HitTest
167 wxRICHTEXT_HITTEST_ON
= 0x08,
169 // The point was on space outside content
170 wxRICHTEXT_HITTEST_OUTSIDE
= 0x10
174 * Flags for GetRangeSize
177 #define wxRICHTEXT_FORMATTED 0x01
178 #define wxRICHTEXT_UNFORMATTED 0x02
179 #define wxRICHTEXT_CACHE_SIZE 0x04
180 #define wxRICHTEXT_HEIGHT_ONLY 0x08
183 * Flags for SetStyle/SetListStyle
186 #define wxRICHTEXT_SETSTYLE_NONE 0x00
188 // Specifies that this operation should be undoable
189 #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01
191 // Specifies that the style should not be applied if the
192 // combined style at this point is already the style in question.
193 #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02
195 // Specifies that the style should only be applied to paragraphs,
196 // and not the content. This allows content styling to be
197 // preserved independently from that of e.g. a named paragraph style.
198 #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04
200 // Specifies that the style should only be applied to characters,
201 // and not the paragraph. This allows content styling to be
202 // preserved independently from that of e.g. a named paragraph style.
203 #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
205 // For SetListStyle only: specifies starting from the given number, otherwise
206 // deduces number from existing attributes
207 #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
209 // For SetListStyle only: specifies the list level for all paragraphs, otherwise
210 // the current indentation will be used
211 #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
213 // Resets the existing style before applying the new style
214 #define wxRICHTEXT_SETSTYLE_RESET 0x40
216 // Removes the given style instead of applying it
217 #define wxRICHTEXT_SETSTYLE_REMOVE 0x80
220 * Flags for text insertion
223 #define wxRICHTEXT_INSERT_NONE 0x00
224 #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
225 #define wxRICHTEXT_INSERT_INTERACTIVE 0x02
227 // A special flag telling the buffer to keep the first paragraph style
228 // as-is, when deleting a paragraph marker. In future we might pass a
229 // flag to InsertFragment and DeleteRange to indicate the appropriate mode.
230 #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000
233 * Default superscript/subscript font multiplication factor
236 #define wxSCRIPT_MUL_FACTOR 1.5
238 // Image align/floating
239 #define wxRICHTEXT_LEFT 0x00
240 #define wxRICHTEXT_CENTRE 0x01
241 #define wxRICHTEXT_RIGHT 0x02
243 #define wxRICHTEXT_FLOAT_NONE 0x00
244 #define wxRICHTEXT_FLOAT_LEFT 0x01
245 #define wxRICHTEXT_FLOAT_RIGHT 0x02
247 // Image width/height scale
248 #define wxRICHTEXT_PX 0x00
249 #define wxRICHTEXT_MM 0x01
252 * wxRichTextAnchoredObjectAttr class declaration
254 class WXDLLIMPEXP_RICHTEXT wxRichTextAnchoredObjectAttr
257 wxRichTextAnchoredObjectAttr() { Init(); }
258 wxRichTextAnchoredObjectAttr(const wxRichTextAnchoredObjectAttr
& attr
) { Copy(attr
); }
262 void operator= (const wxRichTextAnchoredObjectAttr
& attr
) { Copy(attr
); }
263 void Copy(const wxRichTextAnchoredObjectAttr
& attr
);
265 /// Is this anchored? TODO: difference between anchored and floating?
266 bool IsAnchored() const { return m_floating
!= wxRICHTEXT_FLOAT_NONE
; }
268 /// Is this floating?
269 bool IsFloating() const { return m_floating
!= wxRICHTEXT_FLOAT_NONE
; }
270 void SetFloatingMode(int floating
) { m_floating
= floating
; }
272 int GetAlignment() const { return m_align
; }
273 void SetAlignment(int align
) { m_align
= align
; }
275 int GetOffset() const { return m_offset
; }
276 void SetOffset(int offset
) { m_offset
= offset
; }
278 int GetUnitsOffset() const { return m_unitsOffset
; }
279 void SetUnitsOffset(int offset
) { m_unitsOffset
= offset
; }
281 int GetUnitsW() const { return m_unitsW
; }
282 void SetUnitsW(int u
) { m_unitsW
= u
; }
284 int GetUnitsH() const { return m_unitsH
; }
285 void SetUnitsH(int u
) { m_unitsH
= u
; }
287 int GetWidth() const { return m_width
; }
288 void SetWidth(int w
) { m_width
= w
; }
290 int GetHeight() const { return m_height
; }
291 void SetHeight(int h
) { m_height
= h
; }
297 int m_unitsW
, m_unitsH
;
298 int m_width
, m_height
;
302 * wxRichTextFontTable
303 * Manages quick access to a pool of fonts for rendering rich text
306 class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable
: public wxObject
309 wxRichTextFontTable();
311 wxRichTextFontTable(const wxRichTextFontTable
& table
);
312 virtual ~wxRichTextFontTable();
314 bool IsOk() const { return m_refData
!= NULL
; }
316 wxFont
FindFont(const wxTextAttr
& fontSpec
);
319 void operator= (const wxRichTextFontTable
& table
);
320 bool operator == (const wxRichTextFontTable
& table
) const;
321 bool operator != (const wxRichTextFontTable
& table
) const { return !(*this == table
); }
325 DECLARE_DYNAMIC_CLASS(wxRichTextFontTable
)
329 * wxRichTextRange class declaration
330 * This stores beginning and end positions for a range of data.
331 * TODO: consider renaming wxTextRange and using for all text controls.
334 class WXDLLIMPEXP_RICHTEXT wxRichTextRange
339 wxRichTextRange() { m_start
= 0; m_end
= 0; }
340 wxRichTextRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
341 wxRichTextRange(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
342 ~wxRichTextRange() {}
344 void operator =(const wxRichTextRange
& range
) { m_start
= range
.m_start
; m_end
= range
.m_end
; }
345 bool operator ==(const wxRichTextRange
& range
) const { return (m_start
== range
.m_start
&& m_end
== range
.m_end
); }
346 bool operator !=(const wxRichTextRange
& range
) const { return (m_start
!= range
.m_start
|| m_end
!= range
.m_end
); }
347 wxRichTextRange
operator -(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
- range
.m_start
, m_end
- range
.m_end
); }
348 wxRichTextRange
operator +(const wxRichTextRange
& range
) const { return wxRichTextRange(m_start
+ range
.m_start
, m_end
+ range
.m_end
); }
350 void SetRange(long start
, long end
) { m_start
= start
; m_end
= end
; }
352 void SetStart(long start
) { m_start
= start
; }
353 long GetStart() const { return m_start
; }
355 void SetEnd(long end
) { m_end
= end
; }
356 long GetEnd() const { return m_end
; }
358 /// Returns true if this range is completely outside 'range'
359 bool IsOutside(const wxRichTextRange
& range
) const { return range
.m_start
> m_end
|| range
.m_end
< m_start
; }
361 /// Returns true if this range is completely within 'range'
362 bool IsWithin(const wxRichTextRange
& range
) const { return m_start
>= range
.m_start
&& m_end
<= range
.m_end
; }
364 /// Returns true if the given position is within this range. Allow
365 /// for the possibility of an empty range - assume the position
366 /// is within this empty range. NO, I think we should not match with an empty range.
367 // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); }
368 bool Contains(long pos
) const { return pos
>= m_start
&& pos
<= m_end
; }
370 /// Limit this range to be within 'range'
371 bool LimitTo(const wxRichTextRange
& range
) ;
373 /// Gets the length of the range
374 long GetLength() const { return m_end
- m_start
+ 1; }
376 /// Swaps the start and end
377 void Swap() { long tmp
= m_start
; m_start
= m_end
; m_end
= tmp
; }
379 /// Convert to internal form: (n, n) is the range of a single character.
380 wxRichTextRange
ToInternal() const { return wxRichTextRange(m_start
, m_end
-1); }
382 /// Convert from internal to public API form: (n, n+1) is the range of a single character.
383 wxRichTextRange
FromInternal() const { return wxRichTextRange(m_start
, m_end
+1); }
390 #define wxRICHTEXT_ALL wxRichTextRange(-2, -2)
391 #define wxRICHTEXT_NONE wxRichTextRange(-1, -1)
394 * wxRichTextObject class declaration
395 * This is the base for drawable objects.
398 class WXDLLIMPEXP_RICHTEXT wxRichTextObject
: public wxObject
400 DECLARE_CLASS(wxRichTextObject
)
404 wxRichTextObject(wxRichTextObject
* parent
= NULL
);
405 virtual ~wxRichTextObject();
409 /// Draw the item, within the given range. Some objects may ignore the range (for
410 /// example paragraphs) while others must obey it (lines, to implement wrapping)
411 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
) = 0;
413 /// Lay the item out at the specified position with the given size constraint.
414 /// Layout must set the cached size.
415 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
) = 0;
417 /// Hit-testing: returns a flag indicating hit test details, plus
418 /// information about position
419 virtual int HitTest(wxDC
& WXUNUSED(dc
), const wxPoint
& WXUNUSED(pt
), long& WXUNUSED(textPosition
)) { return false; }
421 /// Finds the absolute position and row height for the given character position
422 virtual bool FindPosition(wxDC
& WXUNUSED(dc
), long WXUNUSED(index
), wxPoint
& WXUNUSED(pt
), int* WXUNUSED(height
), bool WXUNUSED(forceLineStart
)) { return false; }
424 /// Get the best size, i.e. the ideal starting size for this object irrespective
425 /// of available space. For a short text string, it will be the size that exactly encloses
426 /// the text. For a longer string, it might use the parent width for example.
427 virtual wxSize
GetBestSize() const { return m_size
; }
429 /// Get the object size for the given range. Returns false if the range
430 /// is invalid for this object.
431 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const = 0;
433 /// Do a split, returning an object containing the second part, and setting
434 /// the first part in 'this'.
435 virtual wxRichTextObject
* DoSplit(long WXUNUSED(pos
)) { return NULL
; }
437 /// Calculate range. By default, guess that the object is 1 unit long.
438 virtual void CalculateRange(long start
, long& end
) { end
= start
; m_range
.SetRange(start
, end
); }
441 virtual bool DeleteRange(const wxRichTextRange
& WXUNUSED(range
)) { return false; }
443 /// Returns true if the object is empty
444 virtual bool IsEmpty() const { return false; }
446 /// Whether this object floatable
447 virtual bool IsFloatable() const { return false; }
449 /// Whether this object is currently floating
450 virtual bool IsFloating() const { return false; }
452 /// Whether this object is a place holding one
453 // virtual bool IsPlaceHolding() const { return false; }
455 /// Floating direction
456 virtual int GetFloatDirection() const { return wxRICHTEXT_FLOAT_NONE
; }
458 /// Get any text in this object for the given range
459 virtual wxString
GetTextForRange(const wxRichTextRange
& WXUNUSED(range
)) const { return wxEmptyString
; }
461 /// Returns true if this object can merge itself with the given one.
462 virtual bool CanMerge(wxRichTextObject
* WXUNUSED(object
)) const { return false; }
464 /// Returns true if this object merged itself with the given one.
465 /// The calling code will then delete the given object.
466 virtual bool Merge(wxRichTextObject
* WXUNUSED(object
)) { return false; }
468 /// Dump to output stream for debugging
469 virtual void Dump(wxTextOutputStream
& stream
);
471 /// Can we edit properties via a GUI?
472 virtual bool CanEditProperties() const { return false; }
474 /// Edit properties via a GUI
475 virtual bool EditProperties(wxWindow
* WXUNUSED(parent
), wxRichTextBuffer
* WXUNUSED(buffer
)) { return false; }
479 /// Get/set the cached object size as calculated by Layout.
480 virtual wxSize
GetCachedSize() const { return m_size
; }
481 virtual void SetCachedSize(const wxSize
& sz
) { m_size
= sz
; }
483 /// Get/set the object position
484 virtual wxPoint
GetPosition() const { return m_pos
; }
485 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
487 /// Get the rectangle enclosing the object
488 virtual wxRect
GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
491 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
494 const wxRichTextRange
& GetRange() const { return m_range
; }
495 wxRichTextRange
& GetRange() { return m_range
; }
497 /// Get/set dirty flag (whether the object needs Layout to be called)
498 virtual bool GetDirty() const { return m_dirty
; }
499 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
501 /// Is this composite?
502 virtual bool IsComposite() const { return false; }
504 /// Get/set the parent.
505 virtual wxRichTextObject
* GetParent() const { return m_parent
; }
506 virtual void SetParent(wxRichTextObject
* parent
) { m_parent
= parent
; }
508 /// Set the margin around the object
509 virtual void SetMargins(int margin
);
510 virtual void SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
);
511 virtual int GetLeftMargin() const { return m_leftMargin
; }
512 virtual int GetRightMargin() const { return m_rightMargin
; }
513 virtual int GetTopMargin() const { return m_topMargin
; }
514 virtual int GetBottomMargin() const { return m_bottomMargin
; }
516 /// Set attributes object
517 void SetAttributes(const wxTextAttr
& attr
) { m_attributes
= attr
; }
518 const wxTextAttr
& GetAttributes() const { return m_attributes
; }
519 wxTextAttr
& GetAttributes() { return m_attributes
; }
521 /// Set/get stored descent
522 void SetDescent(int descent
) { m_descent
= descent
; }
523 int GetDescent() const { return m_descent
; }
525 /// Gets the containing buffer
526 wxRichTextBuffer
* GetBuffer() const;
531 virtual wxRichTextObject
* Clone() const { return NULL
; }
534 void Copy(const wxRichTextObject
& obj
);
536 /// Reference-counting allows us to use the same object in multiple
537 /// lists (not yet used)
538 void Reference() { m_refCount
++; }
541 /// Convert units in tenths of a millimetre to device units
542 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
543 static int ConvertTenthsMMToPixels(int ppi
, int units
);
548 int m_descent
; // Descent for this object (if any)
551 wxRichTextObject
* m_parent
;
553 /// The range of this object (start position to end position)
554 wxRichTextRange m_range
;
563 wxTextAttr m_attributes
;
566 WX_DECLARE_LIST_WITH_DECL( wxRichTextObject
, wxRichTextObjectList
, class WXDLLIMPEXP_RICHTEXT
);
569 * wxRichTextCompositeObject class declaration
570 * Objects of this class can contain other objects.
573 class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject
: public wxRichTextObject
575 DECLARE_CLASS(wxRichTextCompositeObject
)
579 wxRichTextCompositeObject(wxRichTextObject
* parent
= NULL
);
580 virtual ~wxRichTextCompositeObject();
584 /// Hit-testing: returns a flag indicating hit test details, plus
585 /// information about position
586 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
588 /// Finds the absolute position and row height for the given character position
589 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
592 virtual void CalculateRange(long start
, long& end
);
595 virtual bool DeleteRange(const wxRichTextRange
& range
);
597 /// Get any text in this object for the given range
598 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
600 /// Dump to output stream for debugging
601 virtual void Dump(wxTextOutputStream
& stream
);
606 wxRichTextObjectList
& GetChildren() { return m_children
; }
607 const wxRichTextObjectList
& GetChildren() const { return m_children
; }
609 /// Get the child count
610 size_t GetChildCount() const ;
612 /// Get the nth child
613 wxRichTextObject
* GetChild(size_t n
) const ;
615 /// Get/set dirty flag
616 virtual bool GetDirty() const { return m_dirty
; }
617 virtual void SetDirty(bool dirty
) { m_dirty
= dirty
; }
619 /// Is this composite?
620 virtual bool IsComposite() const { return true; }
622 /// Returns true if the buffer is empty
623 virtual bool IsEmpty() const { return GetChildCount() == 0; }
628 void Copy(const wxRichTextCompositeObject
& obj
);
631 void operator= (const wxRichTextCompositeObject
& obj
) { Copy(obj
); }
633 /// Append a child, returning the position
634 size_t AppendChild(wxRichTextObject
* child
) ;
636 /// Insert the child in front of the given object, or at the beginning
637 bool InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
) ;
640 bool RemoveChild(wxRichTextObject
* child
, bool deleteChild
= false) ;
642 /// Delete all children
643 bool DeleteChildren() ;
645 /// Recursively merge all pieces that can be merged.
646 bool Defragment(const wxRichTextRange
& range
= wxRICHTEXT_ALL
);
649 wxRichTextObjectList m_children
;
653 * wxRichTextBox class declaration
654 * This defines a 2D space to lay out objects
657 class WXDLLIMPEXP_RICHTEXT wxRichTextBox
: public wxRichTextCompositeObject
659 DECLARE_DYNAMIC_CLASS(wxRichTextBox
)
663 wxRichTextBox(wxRichTextObject
* parent
= NULL
);
664 wxRichTextBox(const wxRichTextBox
& obj
): wxRichTextCompositeObject() { Copy(obj
); }
669 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
672 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
674 /// Get/set the object size for the given range. Returns false if the range
675 /// is invalid for this object.
676 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
683 virtual wxRichTextObject
* Clone() const { return new wxRichTextBox(*this); }
686 void Copy(const wxRichTextBox
& obj
);
692 * wxRichTextParagraphBox class declaration
693 * This box knows how to lay out paragraphs.
696 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox
: public wxRichTextBox
698 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
)
702 wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
= NULL
);
703 wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox
& obj
): wxRichTextBox() { Init(); Copy(obj
); }
704 ~wxRichTextParagraphLayoutBox();
708 /// Hit-testing: returns a flag indicating hit test details, plus
709 /// information about position
710 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
713 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
716 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
718 /// Get/set the object size for the given range. Returns false if the range
719 /// is invalid for this object.
720 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
723 virtual bool DeleteRange(const wxRichTextRange
& range
);
725 /// Get any text in this object for the given range
726 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
730 /// Associate a control with the buffer, for operations that for example require refreshing the window.
731 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
) { m_ctrl
= ctrl
; }
733 /// Get the associated control.
734 wxRichTextCtrl
* GetRichTextCtrl() const { return m_ctrl
; }
736 /// Get/set whether the last paragraph is partial or complete
737 void SetPartialParagraph(bool partialPara
) { m_partialParagraph
= partialPara
; }
738 bool GetPartialParagraph() const { return m_partialParagraph
; }
740 /// If this is a buffer, returns the current style sheet. The base layout box
741 /// class doesn't have an associated style sheet.
742 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return NULL
; }
745 /// Draw the floats of this buffer
746 void DrawFloats(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
748 /// Move an anchored object to another paragraph
749 void MoveAnchoredObjectToParagraph(wxRichTextParagraph
* from
, wxRichTextParagraph
* to
, wxRichTextAnchoredObject
* obj
);
751 /// Initialize the object.
754 /// Clear all children
755 virtual void Clear();
757 /// Clear and initialize with one blank paragraph
758 virtual void Reset();
760 /// Convenience function to add a paragraph of text
761 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxTextAttr
* paraStyle
= NULL
);
763 /// Convenience function to add an image
764 virtual wxRichTextRange
AddImage(const wxImage
& image
, wxTextAttr
* paraStyle
= NULL
);
766 /// Adds multiple paragraphs, based on newlines.
767 virtual wxRichTextRange
AddParagraphs(const wxString
& text
, wxTextAttr
* paraStyle
= NULL
);
769 /// Get the line at the given position. If caretPosition is true, the position is
770 /// a caret position, which is normally a smaller number.
771 virtual wxRichTextLine
* GetLineAtPosition(long pos
, bool caretPosition
= false) const;
773 /// Get the line at the given y pixel position, or the last line.
774 virtual wxRichTextLine
* GetLineAtYPosition(int y
) const;
776 /// Get the paragraph at the given character or caret position
777 virtual wxRichTextParagraph
* GetParagraphAtPosition(long pos
, bool caretPosition
= false) const;
779 /// Get the line size at the given position
780 virtual wxSize
GetLineSizeAtPosition(long pos
, bool caretPosition
= false) const;
782 /// Given a position, get the number of the visible line (potentially many to a paragraph),
783 /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine)
784 /// that indicates whether the caret is being shown at the end of the previous line or at the start
785 /// of the next, since the caret can be shown at 2 visible positions for the same underlying
787 virtual long GetVisibleLineNumber(long pos
, bool caretPosition
= false, bool startOfLine
= false) const;
789 /// Given a line number, get the corresponding wxRichTextLine object.
790 virtual wxRichTextLine
* GetLineForVisibleLineNumber(long lineNumber
) const;
792 /// Get the leaf object in a paragraph at this position.
793 /// Given a line number, get the corresponding wxRichTextLine object.
794 virtual wxRichTextObject
* GetLeafObjectAtPosition(long position
) const;
796 /// Get the paragraph by number
797 virtual wxRichTextParagraph
* GetParagraphAtLine(long paragraphNumber
) const;
799 /// Get the paragraph for a given line
800 virtual wxRichTextParagraph
* GetParagraphForLine(wxRichTextLine
* line
) const;
802 /// Get the length of the paragraph
803 virtual int GetParagraphLength(long paragraphNumber
) const;
805 /// Get the number of paragraphs
806 virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); }
808 /// Get the number of visible lines
809 virtual int GetLineCount() const;
811 /// Get the text of the paragraph
812 virtual wxString
GetParagraphText(long paragraphNumber
) const;
814 /// Convert zero-based line column and paragraph number to a position.
815 virtual long XYToPosition(long x
, long y
) const;
817 /// Convert zero-based position to line column and paragraph number
818 virtual bool PositionToXY(long pos
, long* x
, long* y
) const;
820 /// Set text attributes: character and/or paragraph styles.
821 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
823 /// Set image attribute
824 void SetImageStyle(wxRichTextImage
*image
, const wxRichTextAnchoredObjectAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
826 /// Get the conbined text attributes for this position.
827 virtual bool GetStyle(long position
, wxTextAttr
& style
);
829 /// Get the content (uncombined) attributes for this position.
830 virtual bool GetUncombinedStyle(long position
, wxTextAttr
& style
);
832 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
833 /// context attributes.
834 virtual bool DoGetStyle(long position
, wxTextAttr
& style
, bool combineStyles
= true);
836 /// Get the combined style for a range - if any attribute is different within the range,
837 /// that attribute is not present within the flags
838 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
);
840 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
842 bool CollectStyle(wxTextAttr
& currentStyle
, const wxTextAttr
& style
, long& multipleStyleAttributes
, int& multipleTextEffectAttributes
, int& absentStyleAttributes
, int& absentTextEffectAttributes
);
845 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
846 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
848 /// Clear list for given range
849 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
851 /// Number/renumber any list elements in the given range.
852 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
853 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
854 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
856 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
857 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
858 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
859 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
861 /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
862 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
863 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);
865 /// Fills in the attributes for numbering a paragraph after previousParagraph.
866 virtual bool FindNextParagraphNumber(wxRichTextParagraph
* previousParagraph
, wxTextAttr
& attr
) const;
868 /// Test if this whole range has character attributes of the specified kind. If any
869 /// of the attributes are different within the range, the test fails. You
870 /// can use this to implement, for example, bold button updating. style must have
871 /// flags indicating which attributes are of interest.
872 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttr
& style
) const;
874 /// Test if this whole range has paragraph attributes of the specified kind. If any
875 /// of the attributes are different within the range, the test fails. You
876 /// can use this to implement, for example, centering button updating. style must have
877 /// flags indicating which attributes are of interest.
878 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttr
& style
) const;
881 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
883 /// Insert fragment into this box at the given position. If partialParagraph is true,
884 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
886 virtual bool InsertFragment(long position
, wxRichTextParagraphLayoutBox
& fragment
);
888 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
889 virtual bool CopyFragment(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
& fragment
);
891 /// Apply the style sheet to the buffer, for example if the styles have changed.
892 virtual bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
);
895 void Copy(const wxRichTextParagraphLayoutBox
& obj
);
898 void operator= (const wxRichTextParagraphLayoutBox
& obj
) { Copy(obj
); }
901 virtual void UpdateRanges() { long end
; CalculateRange(0, end
); }
904 virtual wxString
GetText() const;
906 /// Set default style for new content. Setting it to a default attribute
907 /// makes new content take on the 'basic' style.
908 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
910 /// Get default style
911 virtual const wxTextAttr
& GetDefaultStyle() const { return m_defaultAttributes
; }
913 /// Set basic (overall) style
914 virtual void SetBasicStyle(const wxTextAttr
& style
) { m_attributes
= style
; }
916 /// Get basic (overall) style
917 virtual const wxTextAttr
& GetBasicStyle() const { return m_attributes
; }
919 /// Invalidate the buffer. With no argument, invalidates whole buffer.
920 void Invalidate(const wxRichTextRange
& invalidRange
= wxRICHTEXT_ALL
);
922 /// Gather information about floating objects. If untilObj is non-NULL,
923 /// will stop getting information if the current object is this, since we
924 /// will collect the rest later.
925 virtual bool UpdateFloatingObjects(int width
, wxRichTextObject
* untilObj
= NULL
);
927 /// Get invalid range, rounding to entire paragraphs if argument is true.
928 wxRichTextRange
GetInvalidRange(bool wholeParagraphs
= false) const;
930 /// Get the wxRichTextFloatCollector of this object
931 wxRichTextFloatCollector
* GetFloatCollector() { return m_floatCollector
; }
934 wxRichTextCtrl
* m_ctrl
;
935 wxTextAttr m_defaultAttributes
;
937 /// The invalidated range that will need full layout
938 wxRichTextRange m_invalidRange
;
940 // Is the last paragraph partial or complete?
941 bool m_partialParagraph
;
943 // The floating layout state
944 wxRichTextFloatCollector
* m_floatCollector
;
948 * wxRichTextLine class declaration
949 * This object represents a line in a paragraph, and stores
950 * offsets from the start of the paragraph representing the
951 * start and end positions of the line.
954 class WXDLLIMPEXP_RICHTEXT wxRichTextLine
959 wxRichTextLine(wxRichTextParagraph
* parent
);
960 wxRichTextLine(const wxRichTextLine
& obj
) { Init( NULL
); Copy(obj
); }
961 virtual ~wxRichTextLine() {}
968 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
969 void SetRange(long from
, long to
) { m_range
= wxRichTextRange(from
, to
); }
971 /// Get the parent paragraph
972 wxRichTextParagraph
* GetParent() { return m_parent
; }
975 const wxRichTextRange
& GetRange() const { return m_range
; }
976 wxRichTextRange
& GetRange() { return m_range
; }
978 /// Get the absolute range
979 wxRichTextRange
GetAbsoluteRange() const;
981 /// Get/set the line size as calculated by Layout.
982 virtual wxSize
GetSize() const { return m_size
; }
983 virtual void SetSize(const wxSize
& sz
) { m_size
= sz
; }
985 /// Get/set the object position relative to the parent
986 virtual wxPoint
GetPosition() const { return m_pos
; }
987 virtual void SetPosition(const wxPoint
& pos
) { m_pos
= pos
; }
989 /// Get the absolute object position
990 virtual wxPoint
GetAbsolutePosition() const;
992 /// Get the rectangle enclosing the line
993 virtual wxRect
GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); }
995 /// Set/get stored descent
996 void SetDescent(int descent
) { m_descent
= descent
; }
997 int GetDescent() const { return m_descent
; }
999 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
1000 wxArrayInt
& GetObjectSizes() { return m_objectSizes
; }
1001 const wxArrayInt
& GetObjectSizes() const { return m_objectSizes
; }
1007 void Init(wxRichTextParagraph
* parent
);
1010 void Copy(const wxRichTextLine
& obj
);
1013 virtual wxRichTextLine
* Clone() const { return new wxRichTextLine(*this); }
1017 /// The range of the line (start position to end position)
1018 /// This is relative to the parent paragraph.
1019 wxRichTextRange m_range
;
1021 /// Size and position measured relative to top of paragraph
1025 /// Maximum descent for this line (location of text baseline)
1028 // The parent object
1029 wxRichTextParagraph
* m_parent
;
1031 #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING
1032 wxArrayInt m_objectSizes
;
1036 WX_DECLARE_LIST_WITH_DECL( wxRichTextLine
, wxRichTextLineList
, class WXDLLIMPEXP_RICHTEXT
);
1039 * wxRichTextParagraph class declaration
1040 * This object represents a single paragraph (or in a straight text editor, a line).
1043 class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph
: public wxRichTextBox
1045 DECLARE_DYNAMIC_CLASS(wxRichTextParagraph
)
1049 wxRichTextParagraph(wxRichTextObject
* parent
= NULL
, wxTextAttr
* style
= NULL
);
1050 wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
= NULL
, wxTextAttr
* paraStyle
= NULL
, wxTextAttr
* charStyle
= NULL
);
1051 virtual ~wxRichTextParagraph();
1052 wxRichTextParagraph(const wxRichTextParagraph
& obj
): wxRichTextBox() { Copy(obj
); }
1057 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1059 /// Lay the item out
1060 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1062 /// Get/set the object size for the given range. Returns false if the range
1063 /// is invalid for this object.
1064 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1066 /// Finds the absolute position and row height for the given character position
1067 virtual bool FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
);
1069 /// Hit-testing: returns a flag indicating hit test details, plus
1070 /// information about position
1071 virtual int HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
);
1074 virtual void CalculateRange(long start
, long& end
);
1078 /// Get the cached lines
1079 wxRichTextLineList
& GetLines() { return m_cachedLines
; }
1084 void Copy(const wxRichTextParagraph
& obj
);
1087 virtual wxRichTextObject
* Clone() const { return new wxRichTextParagraph(*this); }
1089 /// Clear the cached lines
1094 /// Apply paragraph styles such as centering to the wrapped lines
1095 virtual void ApplyParagraphStyle(const wxTextAttr
& attr
, const wxRect
& rect
, wxDC
& dc
);
1097 /// Insert text at the given position
1098 virtual bool InsertText(long pos
, const wxString
& text
);
1100 /// Split an object at this position if necessary, and return
1101 /// the previous object, or NULL if inserting at beginning.
1102 virtual wxRichTextObject
* SplitAt(long pos
, wxRichTextObject
** previousObject
= NULL
);
1104 /// Move content to a list from this point
1105 virtual void MoveToList(wxRichTextObject
* obj
, wxList
& list
);
1107 /// Add content back from list
1108 virtual void MoveFromList(wxList
& list
);
1110 /// Get the plain text searching from the start or end of the range.
1111 /// The resulting string may be shorter than the range given.
1112 bool GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
= true);
1114 /// Find a suitable wrap position. wrapPosition is the last position in the line to the left
1116 bool FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
, wxArrayInt
* partialExtents
);
1118 /// Find the object at the given position
1119 wxRichTextObject
* FindObjectAtPosition(long position
);
1121 /// Get the bullet text for this paragraph.
1122 wxString
GetBulletText();
1124 /// Allocate or reuse a line object
1125 wxRichTextLine
* AllocateLine(int pos
);
1127 /// Clear remaining unused line objects, if any
1128 bool ClearUnusedLines(int lineCount
);
1130 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
1131 /// retrieve the actual style.
1132 wxTextAttr
GetCombinedAttributes(const wxTextAttr
& contentStyle
) const;
1134 /// Get combined attributes of the base style and paragraph style.
1135 wxTextAttr
GetCombinedAttributes() const;
1137 /// Get the first position from pos that has a line break character.
1138 long GetFirstLineBreakPosition(long pos
);
1140 /// Create default tabstop array
1141 static void InitDefaultTabs();
1143 /// Clear default tabstop array
1144 static void ClearDefaultTabs();
1146 /// Get default tabstop array
1147 static const wxArrayInt
& GetDefaultTabs() { return sm_defaultTabs
; }
1149 /// Layout the floats object
1150 void LayoutFloat(wxDC
& dc
, const wxRect
& rect
, int style
, wxRichTextFloatCollector
* floatCollector
);
1153 /// The lines that make up the wrapped paragraph
1154 wxRichTextLineList m_cachedLines
;
1156 /// Default tabstops
1157 static wxArrayInt sm_defaultTabs
;
1159 friend class wxRichTextFloatCollector
;
1163 * wxRichTextPlainText class declaration
1164 * This object represents a single piece of text.
1167 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText
: public wxRichTextObject
1169 DECLARE_DYNAMIC_CLASS(wxRichTextPlainText
)
1173 wxRichTextPlainText(const wxString
& text
= wxEmptyString
, wxRichTextObject
* parent
= NULL
, wxTextAttr
* style
= NULL
);
1174 wxRichTextPlainText(const wxRichTextPlainText
& obj
): wxRichTextObject() { Copy(obj
); }
1179 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1181 /// Lay the item out
1182 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1184 /// Get/set the object size for the given range. Returns false if the range
1185 /// is invalid for this object.
1186 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1188 /// Get any text in this object for the given range
1189 virtual wxString
GetTextForRange(const wxRichTextRange
& range
) const;
1191 /// Do a split, returning an object containing the second part, and setting
1192 /// the first part in 'this'.
1193 virtual wxRichTextObject
* DoSplit(long pos
);
1196 virtual void CalculateRange(long start
, long& end
);
1199 virtual bool DeleteRange(const wxRichTextRange
& range
);
1201 /// Returns true if the object is empty
1202 virtual bool IsEmpty() const { return m_text
.empty(); }
1204 /// Returns true if this object can merge itself with the given one.
1205 virtual bool CanMerge(wxRichTextObject
* object
) const;
1207 /// Returns true if this object merged itself with the given one.
1208 /// The calling code will then delete the given object.
1209 virtual bool Merge(wxRichTextObject
* object
);
1211 /// Dump to output stream for debugging
1212 virtual void Dump(wxTextOutputStream
& stream
);
1214 /// Get the first position from pos that has a line break character.
1215 long GetFirstLineBreakPosition(long pos
);
1220 const wxString
& GetText() const { return m_text
; }
1223 void SetText(const wxString
& text
) { m_text
= text
; }
1228 void Copy(const wxRichTextPlainText
& obj
);
1231 virtual wxRichTextObject
* Clone() const { return new wxRichTextPlainText(*this); }
1233 bool DrawTabbedString(wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
, wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
);
1240 * wxRichTextImageBlock stores information about an image, in binary in-memory form
1243 class WXDLLIMPEXP_FWD_BASE wxDataInputStream
;
1244 class WXDLLIMPEXP_FWD_BASE wxDataOutputStream
;
1246 class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock
: public wxObject
1249 wxRichTextImageBlock();
1250 wxRichTextImageBlock(const wxRichTextImageBlock
& block
);
1251 virtual ~wxRichTextImageBlock();
1256 // Load the original image into a memory block.
1257 // If the image is not a JPEG, we must convert it into a JPEG
1258 // to conserve space.
1259 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
1260 // load the image a 2nd time.
1261 virtual bool MakeImageBlock(const wxString
& filename
, wxBitmapType imageType
,
1262 wxImage
& image
, bool convertToJPEG
= true);
1264 // Make an image block from the wxImage in the given
1266 virtual bool MakeImageBlock(wxImage
& image
, wxBitmapType imageType
, int quality
= 80);
1268 // Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG)
1269 virtual bool MakeImageBlockDefaultQuality(const wxImage
& image
, wxBitmapType imageType
);
1271 // Makes the image block
1272 virtual bool DoMakeImageBlock(const wxImage
& image
, wxBitmapType imageType
);
1275 bool Write(const wxString
& filename
);
1277 // Write data in hex to a stream
1278 bool WriteHex(wxOutputStream
& stream
);
1280 // Read data in hex from a stream
1281 bool ReadHex(wxInputStream
& stream
, int length
, wxBitmapType imageType
);
1283 // Copy from 'block'
1284 void Copy(const wxRichTextImageBlock
& block
);
1286 // Load a wxImage from the block
1287 bool Load(wxImage
& image
);
1290 void operator=(const wxRichTextImageBlock
& block
);
1294 unsigned char* GetData() const { return m_data
; }
1295 size_t GetDataSize() const { return m_dataSize
; }
1296 wxBitmapType
GetImageType() const { return m_imageType
; }
1298 void SetData(unsigned char* image
) { m_data
= image
; }
1299 void SetDataSize(size_t size
) { m_dataSize
= size
; }
1300 void SetImageType(wxBitmapType imageType
) { m_imageType
= imageType
; }
1302 bool Ok() const { return IsOk(); }
1303 bool IsOk() const { return GetData() != NULL
; }
1305 // Gets the extension for the block's type
1306 wxString
GetExtension() const;
1310 // Allocate and read from stream as a block of memory
1311 static unsigned char* ReadBlock(wxInputStream
& stream
, size_t size
);
1312 static unsigned char* ReadBlock(const wxString
& filename
, size_t size
);
1314 // Write memory block to stream
1315 static bool WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
);
1317 // Write memory block to file
1318 static bool WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
);
1321 // Size in bytes of the image stored.
1322 // This is in the raw, original form such as a JPEG file.
1323 unsigned char* m_data
;
1325 wxBitmapType m_imageType
;
1329 * wxRichTextAnchoredObject class declaration
1330 * This object is an abstract one that represent some objects which can floats
1332 class WXDLLIMPEXP_RICHTEXT wxRichTextAnchoredObject
: public wxRichTextObject
1334 DECLARE_CLASS(wxRichTextAnchoredObject
)
1337 wxRichTextAnchoredObject(wxRichTextObject
* parent
= NULL
, const wxRichTextAnchoredObjectAttr
& attr
= wxRichTextAnchoredObjectAttr());
1338 wxRichTextAnchoredObject(const wxRichTextAnchoredObject
& obj
) : wxRichTextObject(obj
) /* , m_ph(NULL) */ { Copy(obj
); }
1339 ~wxRichTextAnchoredObject();
1342 virtual bool IsFloatable() const { return true; }
1344 /// Whether this object is currently floating
1345 virtual bool IsFloating() const { return m_anchoredAttr
.m_floating
!= wxRICHTEXT_FLOAT_NONE
; }
1347 virtual void SetParent(wxRichTextObject
* parent
);
1350 const wxRichTextAnchoredObjectAttr
& GetAnchoredAttr() const { return m_anchoredAttr
; }
1351 void SetAnchoredAttr(const wxRichTextAnchoredObjectAttr
& attr
);
1353 /// The floating direction
1354 virtual int GetFloatDirection() const { return m_anchoredAttr
.m_floating
; }
1356 void operator=(const wxRichTextAnchoredObject
&) { wxASSERT("Nobody can reset this object using ="); }
1359 void Copy(const wxRichTextAnchoredObject
& obj
);
1362 wxRichTextAnchoredObjectAttr m_anchoredAttr
;
1366 * wxRichTextImage class declaration
1367 * This object represents an image.
1370 class WXDLLIMPEXP_RICHTEXT wxRichTextImage
: public wxRichTextAnchoredObject
1372 DECLARE_DYNAMIC_CLASS(wxRichTextImage
)
1376 wxRichTextImage(wxRichTextObject
* parent
= NULL
): wxRichTextAnchoredObject(parent
) { }
1377 wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
= NULL
, wxTextAttr
* charStyle
= NULL
);
1378 wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
= NULL
, wxTextAttr
* charStyle
= NULL
);
1379 wxRichTextImage(const wxRichTextImage
& obj
): wxRichTextAnchoredObject(obj
) { Copy(obj
); }
1384 virtual bool Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
);
1386 /// Lay the item out
1387 virtual bool Layout(wxDC
& dc
, const wxRect
& rect
, int style
);
1389 /// Get the object size for the given range. Returns false if the range
1390 /// is invalid for this object.
1391 virtual bool GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
= wxPoint(0,0), wxArrayInt
* partialExtents
= NULL
) const;
1393 /// Returns true if the object is empty
1394 virtual bool IsEmpty() const { return !m_imageBlock
.Ok(); }
1396 /// Can we edit properties via a GUI?
1397 virtual bool CanEditProperties() const { return true; }
1399 /// Edit properties via a GUI
1400 virtual bool EditProperties(wxWindow
* parent
, wxRichTextBuffer
* buffer
);
1404 /// Get the image cache (scaled bitmap)
1405 const wxBitmap
& GetImageCache() const { return m_imageCache
; }
1407 /// Set the image cache
1408 void SetImageCache(const wxBitmap
& bitmap
) { m_imageCache
= bitmap
; }
1410 /// Reset the image cache
1411 void ResetImageCache() { m_imageCache
= wxNullBitmap
; }
1413 /// Get the image block containing the raw data
1414 wxRichTextImageBlock
& GetImageBlock() { return m_imageBlock
; }
1419 void Copy(const wxRichTextImage
& obj
);
1422 virtual wxRichTextObject
* Clone() const { return new wxRichTextImage(*this); }
1424 /// Create a cached image at the required size
1425 virtual bool LoadImageCache(wxDC
& dc
, bool resetCache
= false);
1428 wxRichTextImageBlock m_imageBlock
;
1429 wxBitmap m_imageCache
;
1434 * wxRichTextBuffer class declaration
1435 * This is a kind of box, used to represent the whole buffer
1438 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand
;
1439 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction
;
1441 class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer
: public wxRichTextParagraphLayoutBox
1443 DECLARE_DYNAMIC_CLASS(wxRichTextBuffer
)
1447 wxRichTextBuffer() { Init(); }
1448 wxRichTextBuffer(const wxRichTextBuffer
& obj
): wxRichTextParagraphLayoutBox() { Init(); Copy(obj
); }
1449 virtual ~wxRichTextBuffer() ;
1453 /// Gets the command processor
1454 wxCommandProcessor
* GetCommandProcessor() const { return m_commandProcessor
; }
1456 /// Set style sheet, if any.
1457 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { m_styleSheet
= styleSheet
; }
1458 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
1460 /// Set style sheet and notify of the change
1461 bool SetStyleSheetAndNotify(wxRichTextStyleSheet
* sheet
);
1463 /// Push style sheet to top of stack
1464 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
);
1466 /// Pop style sheet from top of stack
1467 wxRichTextStyleSheet
* PopStyleSheet();
1469 /// Set/get table storing fonts
1470 wxRichTextFontTable
& GetFontTable() { return m_fontTable
; }
1471 const wxRichTextFontTable
& GetFontTable() const { return m_fontTable
; }
1472 void SetFontTable(const wxRichTextFontTable
& table
) { m_fontTable
= table
; }
1479 /// Clears the buffer, adds an empty paragraph, and clears the command processor.
1480 virtual void ResetAndClearCommands();
1483 virtual bool LoadFile(const wxString
& filename
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1486 virtual bool SaveFile(const wxString
& filename
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1488 /// Load from a stream
1489 virtual bool LoadFile(wxInputStream
& stream
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1491 /// Save to a stream
1492 virtual bool SaveFile(wxOutputStream
& stream
, wxRichTextFileType type
= wxRICHTEXT_TYPE_ANY
);
1494 /// Set the handler flags, controlling loading and saving
1495 void SetHandlerFlags(int flags
) { m_handlerFlags
= flags
; }
1497 /// Get the handler flags, controlling loading and saving
1498 int GetHandlerFlags() const { return m_handlerFlags
; }
1500 /// Convenience function to add a paragraph of text
1501 virtual wxRichTextRange
AddParagraph(const wxString
& text
, wxTextAttr
* paraStyle
= NULL
) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text
, paraStyle
); }
1503 /// Begin collapsing undo/redo commands. Note that this may not work properly
1504 /// if combining commands that delete or insert content, changing ranges for
1505 /// subsequent actions.
1506 virtual bool BeginBatchUndo(const wxString
& cmdName
);
1508 /// End collapsing undo/redo commands
1509 virtual bool EndBatchUndo();
1511 /// Collapsing commands?
1512 virtual bool BatchingUndo() const { return m_batchedCommandDepth
> 0; }
1514 /// Submit immediately, or delay according to whether collapsing is on
1515 virtual bool SubmitAction(wxRichTextAction
* action
);
1517 /// Get collapsed command
1518 virtual wxRichTextCommand
* GetBatchedCommand() const { return m_batchedCommand
; }
1520 /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
1521 /// differently by each command. If not dealt with by a command implementation, then
1522 /// it will be implemented automatically by not storing the command in the undo history
1523 /// when the action is submitted to the command processor.
1524 virtual bool BeginSuppressUndo();
1526 /// End suppressing undo/redo commands.
1527 virtual bool EndSuppressUndo();
1529 /// Collapsing commands?
1530 virtual bool SuppressingUndo() const { return m_suppressUndo
> 0; }
1532 /// Copy the range to the clipboard
1533 virtual bool CopyToClipboard(const wxRichTextRange
& range
);
1535 /// Paste the clipboard content to the buffer
1536 virtual bool PasteFromClipboard(long position
);
1538 /// Can we paste from the clipboard?
1539 virtual bool CanPasteFromClipboard() const;
1541 /// Begin using a style
1542 virtual bool BeginStyle(const wxTextAttr
& style
);
1545 virtual bool EndStyle();
1548 virtual bool EndAllStyles();
1550 /// Clear the style stack
1551 virtual void ClearStyleStack();
1553 /// Get the size of the style stack, for example to check correct nesting
1554 virtual size_t GetStyleStackSize() const { return m_attributeStack
.GetCount(); }
1556 /// Begin using bold
1560 bool EndBold() { return EndStyle(); }
1562 /// Begin using italic
1565 /// End using italic
1566 bool EndItalic() { return EndStyle(); }
1568 /// Begin using underline
1569 bool BeginUnderline();
1571 /// End using underline
1572 bool EndUnderline() { return EndStyle(); }
1574 /// Begin using point size
1575 bool BeginFontSize(int pointSize
);
1577 /// End using point size
1578 bool EndFontSize() { return EndStyle(); }
1580 /// Begin using this font
1581 bool BeginFont(const wxFont
& font
);
1583 /// End using a font
1584 bool EndFont() { return EndStyle(); }
1586 /// Begin using this colour
1587 bool BeginTextColour(const wxColour
& colour
);
1589 /// End using a colour
1590 bool EndTextColour() { return EndStyle(); }
1592 /// Begin using alignment
1593 bool BeginAlignment(wxTextAttrAlignment alignment
);
1596 bool EndAlignment() { return EndStyle(); }
1598 /// Begin left indent
1599 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0);
1602 bool EndLeftIndent() { return EndStyle(); }
1604 /// Begin right indent
1605 bool BeginRightIndent(int rightIndent
);
1607 /// End right indent
1608 bool EndRightIndent() { return EndStyle(); }
1610 /// Begin paragraph spacing
1611 bool BeginParagraphSpacing(int before
, int after
);
1613 /// End paragraph spacing
1614 bool EndParagraphSpacing() { return EndStyle(); }
1616 /// Begin line spacing
1617 bool BeginLineSpacing(int lineSpacing
);
1619 /// End line spacing
1620 bool EndLineSpacing() { return EndStyle(); }
1622 /// Begin numbered bullet
1623 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
);
1625 /// End numbered bullet
1626 bool EndNumberedBullet() { return EndStyle(); }
1628 /// Begin symbol bullet
1629 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
);
1631 /// End symbol bullet
1632 bool EndSymbolBullet() { return EndStyle(); }
1634 /// Begin standard bullet
1635 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
);
1637 /// End standard bullet
1638 bool EndStandardBullet() { return EndStyle(); }
1640 /// Begin named character style
1641 bool BeginCharacterStyle(const wxString
& characterStyle
);
1643 /// End named character style
1644 bool EndCharacterStyle() { return EndStyle(); }
1646 /// Begin named paragraph style
1647 bool BeginParagraphStyle(const wxString
& paragraphStyle
);
1649 /// End named character style
1650 bool EndParagraphStyle() { return EndStyle(); }
1652 /// Begin named list style
1653 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1);
1655 /// End named character style
1656 bool EndListStyle() { return EndStyle(); }
1659 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
);
1662 bool EndURL() { return EndStyle(); }
1666 /// Add an event handler
1667 bool AddEventHandler(wxEvtHandler
* handler
);
1669 /// Remove an event handler
1670 bool RemoveEventHandler(wxEvtHandler
* handler
, bool deleteHandler
= false);
1672 /// Clear event handlers
1673 void ClearEventHandlers();
1675 /// Send event to event handlers. If sendToAll is true, will send to all event handlers,
1676 /// otherwise will stop at the first successful one.
1677 bool SendEvent(wxEvent
& event
, bool sendToAll
= true);
1682 void Copy(const wxRichTextBuffer
& obj
);
1685 virtual wxRichTextObject
* Clone() const { return new wxRichTextBuffer(*this); }
1687 /// Submit command to insert paragraphs
1688 bool InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1690 /// Submit command to insert the given text
1691 bool InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1693 /// Submit command to insert a newline
1694 bool InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
= 0);
1696 /// Submit command to insert the given image
1697 bool InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
, int flags
= 0, const wxRichTextAnchoredObjectAttr
& floatAttr
= wxRichTextAnchoredObjectAttr());
1699 /// Submit command to insert an object
1700 bool InsertObjectWithUndo(long pos
, wxRichTextObject
*object
, wxRichTextCtrl
* ctrl
, int flags
);
1702 /// Submit command to delete this range
1703 bool DeleteRangeWithUndo(const wxRichTextRange
& range
, wxRichTextCtrl
* ctrl
);
1706 void Modify(bool modify
= true) { m_modified
= modify
; }
1707 bool IsModified() const { return m_modified
; }
1709 /// Get the style that is appropriate for a new paragraph at this position.
1710 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
1712 wxTextAttr
GetStyleForNewParagraph(long pos
, bool caretPosition
= false, bool lookUpNewParaStyle
=false) const;
1714 /// Dumps contents of buffer for debugging purposes
1715 virtual void Dump();
1716 virtual void Dump(wxTextOutputStream
& stream
) { wxRichTextParagraphLayoutBox::Dump(stream
); }
1718 /// Returns the file handlers
1719 static wxList
& GetHandlers() { return sm_handlers
; }
1721 /// Adds a handler to the end
1722 static void AddHandler(wxRichTextFileHandler
*handler
);
1724 /// Inserts a handler at the front
1725 static void InsertHandler(wxRichTextFileHandler
*handler
);
1727 /// Removes a handler
1728 static bool RemoveHandler(const wxString
& name
);
1730 /// Finds a handler by name
1731 static wxRichTextFileHandler
*FindHandler(const wxString
& name
);
1733 /// Finds a handler by extension and type
1734 static wxRichTextFileHandler
*FindHandler(const wxString
& extension
, wxRichTextFileType imageType
);
1736 /// Finds a handler by filename or, if supplied, type
1737 static wxRichTextFileHandler
*FindHandlerFilenameOrType(const wxString
& filename
,
1738 wxRichTextFileType imageType
);
1740 /// Finds a handler by type
1741 static wxRichTextFileHandler
*FindHandler(wxRichTextFileType imageType
);
1743 /// Gets a wildcard incorporating all visible handlers. If 'types' is present,
1744 /// will be filled with the file type corresponding to each filter. This can be
1745 /// used to determine the type to pass to LoadFile given a selected filter.
1746 static wxString
GetExtWildcard(bool combine
= false, bool save
= false, wxArrayInt
* types
= NULL
);
1748 /// Clean up handlers
1749 static void CleanUpHandlers();
1751 /// Initialise the standard handlers
1752 static void InitStandardHandlers();
1755 static wxRichTextRenderer
* GetRenderer() { return sm_renderer
; }
1757 /// Set renderer, deleting old one
1758 static void SetRenderer(wxRichTextRenderer
* renderer
);
1760 /// Minimum margin between bullet and paragraph in 10ths of a mm
1761 static int GetBulletRightMargin() { return sm_bulletRightMargin
; }
1762 static void SetBulletRightMargin(int margin
) { sm_bulletRightMargin
= margin
; }
1764 /// Factor to multiply by character height to get a reasonable bullet size
1765 static float GetBulletProportion() { return sm_bulletProportion
; }
1766 static void SetBulletProportion(float prop
) { sm_bulletProportion
= prop
; }
1768 /// Scale factor for calculating dimensions
1769 double GetScale() const { return m_scale
; }
1770 void SetScale(double scale
) { m_scale
= scale
; }
1774 /// Command processor
1775 wxCommandProcessor
* m_commandProcessor
;
1777 /// Table storing fonts
1778 wxRichTextFontTable m_fontTable
;
1780 /// Has been modified?
1783 /// Collapsed command stack
1784 int m_batchedCommandDepth
;
1786 /// Name for collapsed command
1787 wxString m_batchedCommandsName
;
1789 /// Current collapsed command accumulating actions
1790 wxRichTextCommand
* m_batchedCommand
;
1792 /// Whether to suppress undo
1795 /// Style sheet, if any
1796 wxRichTextStyleSheet
* m_styleSheet
;
1798 /// List of event handlers that will be notified of events
1799 wxList m_eventHandlers
;
1801 /// Stack of attributes for convenience functions
1802 wxList m_attributeStack
;
1804 /// Flags to be passed to handlers
1808 static wxList sm_handlers
;
1811 static wxRichTextRenderer
* sm_renderer
;
1813 /// Minimum margin between bullet and paragraph in 10ths of a mm
1814 static int sm_bulletRightMargin
;
1816 /// Factor to multiply by character height to get a reasonable bullet size
1817 static float sm_bulletProportion
;
1819 /// Scaling factor in use: needed to calculate correct dimensions when printing
1824 * The command identifiers
1828 enum wxRichTextCommandId
1832 wxRICHTEXT_CHANGE_STYLE
1836 * Command classes for undo/redo
1840 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction
;
1841 class WXDLLIMPEXP_RICHTEXT wxRichTextCommand
: public wxCommand
1844 // Ctor for one action
1845 wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1846 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1848 // Ctor for multiple actions
1849 wxRichTextCommand(const wxString
& name
);
1851 virtual ~wxRichTextCommand();
1856 void AddAction(wxRichTextAction
* action
);
1857 void ClearActions();
1859 wxList
& GetActions() { return m_actions
; }
1867 * wxRichTextAction class declaration
1868 * There can be more than one action in a command.
1871 class WXDLLIMPEXP_RICHTEXT wxRichTextAction
: public wxObject
1874 wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
1875 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
= false);
1877 virtual ~wxRichTextAction();
1882 /// Update the control appearance
1883 void UpdateAppearance(long caretPosition
, bool sendUpdateEvent
= false,
1884 wxArrayInt
* optimizationLineCharPositions
= NULL
, wxArrayInt
* optimizationLineYPositions
= NULL
, bool isDoCmd
= true);
1886 /// Replace the buffer paragraphs with the given fragment.
1887 void ApplyParagraphs(const wxRichTextParagraphLayoutBox
& fragment
);
1889 /// Get the fragments
1890 wxRichTextParagraphLayoutBox
& GetNewParagraphs() { return m_newParagraphs
; }
1891 wxRichTextParagraphLayoutBox
& GetOldParagraphs() { return m_oldParagraphs
; }
1893 /// Calculate arrays for refresh optimization
1894 void CalculateRefreshOptimizations(wxArrayInt
& optimizationLineCharPositions
, wxArrayInt
& optimizationLineYPositions
);
1896 /// Set/get the position used for e.g. insertion
1897 void SetPosition(long pos
) { m_position
= pos
; }
1898 long GetPosition() const { return m_position
; }
1900 /// Set/get the range for e.g. deletion
1901 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
1902 const wxRichTextRange
& GetRange() const { return m_range
; }
1905 const wxString
& GetName() const { return m_name
; }
1912 wxRichTextBuffer
* m_buffer
;
1915 wxRichTextCtrl
* m_ctrl
;
1917 // Stores the new paragraphs
1918 wxRichTextParagraphLayoutBox m_newParagraphs
;
1920 // Stores the old paragraphs
1921 wxRichTextParagraphLayoutBox m_oldParagraphs
;
1923 // The affected range
1924 wxRichTextRange m_range
;
1926 // The insertion point for this command
1929 // Ignore 1st 'Do' operation because we already did it
1932 // The command identifier
1933 wxRichTextCommandId m_cmdId
;
1940 // Include style sheet when loading and saving
1941 #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001
1943 // Save images to memory file system in HTML handler
1944 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010
1946 // Save images to files in HTML handler
1947 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020
1949 // Save images as inline base64 data in HTML handler
1950 #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040
1952 // Don't write header and footer (or BODY), so we can include the fragment
1953 // in a larger document
1954 #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080
1956 // Convert the more common face names to names that will work on the current platform
1957 // in a larger document
1958 #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100
1961 * wxRichTextFileHandler
1962 * Base class for file handlers
1965 class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler
: public wxObject
1967 DECLARE_CLASS(wxRichTextFileHandler
)
1969 wxRichTextFileHandler(const wxString
& name
= wxEmptyString
, const wxString
& ext
= wxEmptyString
, int type
= 0)
1970 : m_name(name
), m_extension(ext
), m_type(type
), m_flags(0), m_visible(true)
1974 bool LoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
1975 { return DoLoadFile(buffer
, stream
); }
1976 bool SaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
1977 { return DoSaveFile(buffer
, stream
); }
1980 #if wxUSE_FFILE && wxUSE_STREAMS
1981 virtual bool LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
1982 virtual bool SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
);
1983 #endif // wxUSE_STREAMS && wxUSE_STREAMS
1985 /// Can we handle this filename (if using files)? By default, checks the extension.
1986 virtual bool CanHandle(const wxString
& filename
) const;
1988 /// Can we save using this handler?
1989 virtual bool CanSave() const { return false; }
1991 /// Can we load using this handler?
1992 virtual bool CanLoad() const { return false; }
1994 /// Should this handler be visible to the user?
1995 virtual bool IsVisible() const { return m_visible
; }
1996 virtual void SetVisible(bool visible
) { m_visible
= visible
; }
1998 /// The name of the nandler
1999 void SetName(const wxString
& name
) { m_name
= name
; }
2000 wxString
GetName() const { return m_name
; }
2002 /// The default extension to recognise
2003 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
2004 wxString
GetExtension() const { return m_extension
; }
2006 /// The handler type
2007 void SetType(int type
) { m_type
= type
; }
2008 int GetType() const { return m_type
; }
2010 /// Flags controlling how loading and saving is done
2011 void SetFlags(int flags
) { m_flags
= flags
; }
2012 int GetFlags() const { return m_flags
; }
2014 /// Encoding to use when saving a file. If empty, a suitable encoding is chosen
2015 void SetEncoding(const wxString
& encoding
) { m_encoding
= encoding
; }
2016 const wxString
& GetEncoding() const { return m_encoding
; }
2021 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
) = 0;
2022 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
) = 0;
2026 wxString m_encoding
;
2027 wxString m_extension
;
2034 * wxRichTextPlainTextHandler
2035 * Plain text handler
2038 class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler
: public wxRichTextFileHandler
2040 DECLARE_CLASS(wxRichTextPlainTextHandler
)
2042 wxRichTextPlainTextHandler(const wxString
& name
= wxT("Text"),
2043 const wxString
& ext
= wxT("txt"),
2044 wxRichTextFileType type
= wxRICHTEXT_TYPE_TEXT
)
2045 : wxRichTextFileHandler(name
, ext
, type
)
2048 /// Can we save using this handler?
2049 virtual bool CanSave() const { return true; }
2051 /// Can we load using this handler?
2052 virtual bool CanLoad() const { return true; }
2057 virtual bool DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
);
2058 virtual bool DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
);
2066 * The data object for a wxRichTextBuffer
2069 class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject
: public wxDataObjectSimple
2072 // ctor doesn't copy the pointer, so it shouldn't go away while this object
2074 wxRichTextBufferDataObject(wxRichTextBuffer
* richTextBuffer
= NULL
);
2075 virtual ~wxRichTextBufferDataObject();
2077 // after a call to this function, the buffer is owned by the caller and it
2078 // is responsible for deleting it
2079 wxRichTextBuffer
* GetRichTextBuffer();
2081 // Returns the id for the new data format
2082 static const wxChar
* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId
; }
2084 // base class pure virtuals
2086 virtual wxDataFormat
GetPreferredFormat(Direction dir
) const;
2087 virtual size_t GetDataSize() const;
2088 virtual bool GetDataHere(void *pBuf
) const;
2089 virtual bool SetData(size_t len
, const void *buf
);
2093 virtual size_t GetDataSize(const wxDataFormat
&) const { return GetDataSize(); }
2094 virtual bool GetDataHere(const wxDataFormat
&, void *buf
) const { return GetDataHere(buf
); }
2095 virtual bool SetData(const wxDataFormat
&, size_t len
, const void *buf
) { return SetData(len
, buf
); }
2098 wxDataFormat m_formatRichTextBuffer
; // our custom format
2099 wxRichTextBuffer
* m_richTextBuffer
; // our data
2100 static const wxChar
* ms_richTextBufferFormatId
; // our format id
2106 * wxRichTextRenderer isolates common drawing functionality
2109 class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer
: public wxObject
2112 wxRichTextRenderer() {}
2113 virtual ~wxRichTextRenderer() {}
2115 /// Draw a standard bullet, as specified by the value of GetBulletName
2116 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
) = 0;
2118 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2119 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
, const wxString
& text
) = 0;
2121 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2122 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
) = 0;
2124 /// Enumerate the standard bullet names currently supported
2125 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
) = 0;
2129 * wxRichTextStdRenderer: standard renderer
2132 class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer
: public wxRichTextRenderer
2135 wxRichTextStdRenderer() {}
2137 /// Draw a standard bullet, as specified by the value of GetBulletName
2138 virtual bool DrawStandardBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
);
2140 /// Draw a bullet that can be described by text, such as numbered or symbol bullets
2141 virtual bool DrawTextBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
, const wxString
& text
);
2143 /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName
2144 virtual bool DrawBitmapBullet(wxRichTextParagraph
* paragraph
, wxDC
& dc
, const wxTextAttr
& attr
, const wxRect
& rect
);
2146 /// Enumerate the standard bullet names currently supported
2147 virtual bool EnumerateStandardBulletNames(wxArrayString
& bulletNames
);
2155 inline bool wxRichTextHasStyle(int flags
, int style
)
2157 return ((flags
& style
) == style
);
2160 /// Compare two attribute objects
2161 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxTextAttr
& attr1
, const wxTextAttr
& attr2
);
2162 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEq(const wxTextAttr
& attr1
, const wxTextAttr
& attr2
);
2164 /// Compare two attribute objects, but take into account the flags
2165 /// specifying attributes of interest.
2166 WXDLLIMPEXP_RICHTEXT
bool wxTextAttrEqPartial(const wxTextAttr
& attr1
, const wxTextAttr
& attr2
, int flags
);
2168 /// Apply one style to another
2169 WXDLLIMPEXP_RICHTEXT
bool wxRichTextApplyStyle(wxTextAttr
& destStyle
, const wxTextAttr
& style
, wxTextAttr
* compareWith
= NULL
);
2171 // Remove attributes
2172 WXDLLIMPEXP_RICHTEXT
bool wxRichTextRemoveStyle(wxTextAttr
& destStyle
, const wxTextAttr
& style
);
2174 /// Combine two bitlists
2175 WXDLLIMPEXP_RICHTEXT
bool wxRichTextCombineBitlists(int& valueA
, int valueB
, int& flagsA
, int flagsB
);
2177 /// Compare two bitlists
2178 WXDLLIMPEXP_RICHTEXT
bool wxRichTextBitlistsEqPartial(int valueA
, int valueB
, int flags
);
2180 /// Split into paragraph and character styles
2181 WXDLLIMPEXP_RICHTEXT
bool wxRichTextSplitParaCharStyles(const wxTextAttr
& style
, wxTextAttr
& parStyle
, wxTextAttr
& charStyle
);
2184 WXDLLIMPEXP_RICHTEXT
bool wxRichTextTabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
);
2186 /// Convert a decimal to Roman numerals
2187 WXDLLIMPEXP_RICHTEXT wxString
wxRichTextDecimalToRoman(long n
);
2189 WXDLLIMPEXP_RICHTEXT
void wxRichTextModuleInit();
2195 // _WX_RICHTEXTBUFFER_H_