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