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