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