]>
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 | 73 | // Compatibility |
24777478 | 74 | //#define wxRichTextAttr wxTextAttr |
44cc96a8 JS |
75 | #define wxTextAttrEx wxTextAttr |
76 | ||
a188ac29 | 77 | // Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a |
749414f7 | 78 | // caret reliably without using wxClientDC in case there |
1c13f06e | 79 | // are platform-specific problems with the generic caret. |
749414f7 | 80 | #if defined(__WXGTK__) || defined(__WXMAC__) |
a188ac29 JS |
81 | #define wxRICHTEXT_USE_OWN_CARET 1 |
82 | #else | |
1c13f06e | 83 | #define wxRICHTEXT_USE_OWN_CARET 0 |
a188ac29 | 84 | #endif |
1c13f06e JS |
85 | |
86 | // Switch off for binary compatibility, on for faster drawing | |
5cb0b827 JS |
87 | // Note: this seems to be buggy (overzealous use of extents) so |
88 | // don't use for now | |
89 | #define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0 | |
1c13f06e | 90 | |
ff76711f JS |
91 | /*! |
92 | * Special characters | |
93 | */ | |
94 | ||
95 | extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar; | |
96 | ||
5d7836c4 | 97 | /*! |
f632e27b | 98 | * File types in wxRichText context. |
5d7836c4 | 99 | */ |
d75a69e8 FM |
100 | enum wxRichTextFileType |
101 | { | |
102 | wxRICHTEXT_TYPE_ANY = 0, | |
103 | wxRICHTEXT_TYPE_TEXT, | |
104 | wxRICHTEXT_TYPE_XML, | |
105 | wxRICHTEXT_TYPE_HTML, | |
106 | wxRICHTEXT_TYPE_RTF, | |
107 | wxRICHTEXT_TYPE_PDF | |
108 | }; | |
5d7836c4 JS |
109 | |
110 | /*! | |
111 | * Forward declarations | |
112 | */ | |
113 | ||
b5dbe15d VS |
114 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl; |
115 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject; | |
cdaed652 | 116 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage; |
b5dbe15d VS |
117 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject; |
118 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList; | |
119 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine; | |
120 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph; | |
121 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler; | |
122 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet; | |
b5dbe15d VS |
123 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition; |
124 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent; | |
125 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer; | |
126 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; | |
cdaed652 VZ |
127 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAnchoredObject; |
128 | class wxRichTextFloatCollector; | |
5d7836c4 JS |
129 | |
130 | /*! | |
131 | * Flags determining the available space, passed to Layout | |
132 | */ | |
133 | ||
134 | #define wxRICHTEXT_FIXED_WIDTH 0x01 | |
135 | #define wxRICHTEXT_FIXED_HEIGHT 0x02 | |
136 | #define wxRICHTEXT_VARIABLE_WIDTH 0x04 | |
137 | #define wxRICHTEXT_VARIABLE_HEIGHT 0x08 | |
138 | ||
4d551ad5 JS |
139 | // Only lay out the part of the buffer that lies within |
140 | // the rect passed to Layout. | |
141 | #define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10 | |
142 | ||
44219ff0 JS |
143 | /*! |
144 | * Flags to pass to Draw | |
145 | */ | |
146 | ||
147 | // Ignore paragraph cache optimization, e.g. for printing purposes | |
148 | // where one line may be drawn higher (on the next page) compared | |
149 | // with the previous line | |
150 | #define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01 | |
151 | ||
5d7836c4 JS |
152 | /*! |
153 | * Flags returned from hit-testing | |
154 | */ | |
f632e27b FM |
155 | enum wxRichTextHitTestFlags |
156 | { | |
157 | // The point was not on this object | |
158 | wxRICHTEXT_HITTEST_NONE = 0x01, | |
159 | ||
160 | // The point was before the position returned from HitTest | |
161 | wxRICHTEXT_HITTEST_BEFORE = 0x02, | |
162 | ||
163 | // The point was after the position returned from HitTest | |
164 | wxRICHTEXT_HITTEST_AFTER = 0x04, | |
5d7836c4 | 165 | |
f632e27b FM |
166 | // The point was on the position returned from HitTest |
167 | wxRICHTEXT_HITTEST_ON = 0x08, | |
168 | ||
169 | // The point was on space outside content | |
170 | wxRICHTEXT_HITTEST_OUTSIDE = 0x10 | |
171 | }; | |
5d7836c4 JS |
172 | |
173 | /*! | |
174 | * Flags for GetRangeSize | |
175 | */ | |
176 | ||
177 | #define wxRICHTEXT_FORMATTED 0x01 | |
178 | #define wxRICHTEXT_UNFORMATTED 0x02 | |
2f45f554 | 179 | #define wxRICHTEXT_CACHE_SIZE 0x04 |
4f3d5bc0 | 180 | #define wxRICHTEXT_HEIGHT_ONLY 0x08 |
5d7836c4 | 181 | |
59509217 | 182 | /*! |
38f833b1 | 183 | * Flags for SetStyle/SetListStyle |
59509217 JS |
184 | */ |
185 | ||
186 | #define wxRICHTEXT_SETSTYLE_NONE 0x00 | |
187 | ||
188 | // Specifies that this operation should be undoable | |
189 | #define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01 | |
190 | ||
191 | // Specifies that the style should not be applied if the | |
192 | // combined style at this point is already the style in question. | |
193 | #define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02 | |
194 | ||
195 | // Specifies that the style should only be applied to paragraphs, | |
196 | // and not the content. This allows content styling to be | |
197 | // preserved independently from that of e.g. a named paragraph style. | |
198 | #define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04 | |
199 | ||
200 | // Specifies that the style should only be applied to characters, | |
201 | // and not the paragraph. This allows content styling to be | |
202 | // preserved independently from that of e.g. a named paragraph style. | |
203 | #define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08 | |
204 | ||
38f833b1 JS |
205 | // For SetListStyle only: specifies starting from the given number, otherwise |
206 | // deduces number from existing attributes | |
207 | #define wxRICHTEXT_SETSTYLE_RENUMBER 0x10 | |
208 | ||
209 | // For SetListStyle only: specifies the list level for all paragraphs, otherwise | |
210 | // the current indentation will be used | |
211 | #define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20 | |
212 | ||
523d2f14 JS |
213 | // Resets the existing style before applying the new style |
214 | #define wxRICHTEXT_SETSTYLE_RESET 0x40 | |
215 | ||
aeb6ebe2 JS |
216 | // Removes the given style instead of applying it |
217 | #define wxRICHTEXT_SETSTYLE_REMOVE 0x80 | |
218 | ||
fe5aa22c JS |
219 | /*! |
220 | * Flags for text insertion | |
221 | */ | |
222 | ||
223 | #define wxRICHTEXT_INSERT_NONE 0x00 | |
224 | #define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01 | |
c025e094 | 225 | #define wxRICHTEXT_INSERT_INTERACTIVE 0x02 |
fe5aa22c | 226 | |
6c0ea513 JS |
227 | // A special flag telling the buffer to keep the first paragraph style |
228 | // as-is, when deleting a paragraph marker. In future we might pass a | |
229 | // flag to InsertFragment and DeleteRange to indicate the appropriate mode. | |
230 | #define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000 | |
231 | ||
30bf7630 JS |
232 | /*! |
233 | * Default superscript/subscript font multiplication factor | |
234 | */ | |
235 | ||
236 | #define wxSCRIPT_MUL_FACTOR 1.5 | |
237 | ||
24777478 | 238 | typedef unsigned short wxTextAttrDimensionFlags; |
cdaed652 | 239 | |
24777478 JS |
240 | // Miscelaneous text box flags |
241 | enum wxTextBoxAttrFlags | |
242 | { | |
243 | wxTEXT_BOX_ATTR_FLOAT = 0x00000001, | |
244 | wxTEXT_BOX_ATTR_CLEAR = 0x00000002, | |
245 | wxTEXT_BOX_ATTR_COLLAPSE_BORDERS = 0x00000004 | |
246 | }; | |
cdaed652 | 247 | |
24777478 JS |
248 | // Whether a value is present, used in dimension flags |
249 | enum wxTextAttrValueFlags | |
250 | { | |
251 | wxTEXT_ATTR_VALUE_PRESENT = 0x1000, | |
252 | wxTEXT_ATTR_VALUE_PRESENT_MASK = 0x1000 | |
253 | }; | |
cdaed652 | 254 | |
24777478 JS |
255 | // Units - included in the dimension value |
256 | enum wxTextAttrUnits | |
257 | { | |
258 | wxTEXT_ATTR_UNITS_TENTHS_MM = 0x0001, | |
259 | wxTEXT_ATTR_UNITS_PIXELS = 0x0002, | |
260 | wxTEXT_ATTR_UNITS_PERCENTAGE = 0x0004, | |
261 | wxTEXT_ATTR_UNITS_POINTS = 0x0008, | |
262 | ||
263 | wxTEXT_ATTR_UNITS_MASK = 0x000F | |
264 | }; | |
265 | ||
266 | // Position - included in the dimension flags | |
267 | enum wxTextBoxAttrPosition | |
268 | { | |
269 | wxTEXT_BOX_ATTR_POSITION_STATIC = 0x0000, // Default is static, i.e. as per normal layout | |
270 | wxTEXT_BOX_ATTR_POSITION_RELATIVE = 0x0010, | |
271 | wxTEXT_BOX_ATTR_POSITION_ABSOLUTE = 0x0020, | |
272 | ||
273 | wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0 | |
274 | }; | |
275 | ||
276 | // Dimension, including units and position | |
277 | class WXDLLIMPEXP_CORE wxTextAttrDimension | |
cdaed652 VZ |
278 | { |
279 | public: | |
24777478 JS |
280 | wxTextAttrDimension() { Reset(); } |
281 | wxTextAttrDimension(int value, wxTextAttrDimensionFlags flags = wxTEXT_ATTR_VALUE_PRESENT|wxTEXT_ATTR_UNITS_TENTHS_MM) { m_value = value; m_flags = flags; } | |
282 | ||
283 | void Reset() { m_value = 0; m_flags = 0; } | |
284 | ||
285 | // Partial equality test | |
286 | bool EqPartial(const wxTextAttrDimension& dim) const; | |
287 | ||
288 | // Apply | |
289 | bool Apply(const wxTextAttrDimension& dim, const wxTextAttrDimension* compareWith = NULL); | |
290 | ||
291 | // Collects the attributes that are common to a range of content, building up a note of | |
292 | // which attributes are absent in some objects and which clash in some objects. | |
293 | void CollectCommonAttributes(const wxTextAttrDimension& attr, wxTextAttrDimension& clashingAttr, wxTextAttrDimension& absentAttr); | |
294 | ||
295 | bool operator==(const wxTextAttrDimension& dim) const { return m_value == dim.m_value && m_flags == dim.m_flags; } | |
296 | ||
297 | int GetValue() const { return m_value; } | |
298 | float GetValueMM() const { return float(m_value) / 10.0; } | |
299 | void SetValueMM(float value) { m_value = (int) ((value * 10.0) + 0.5); m_flags |= wxTEXT_ATTR_VALUE_PRESENT; } | |
300 | void SetValue(int value) { m_value = value; m_flags |= wxTEXT_ATTR_VALUE_PRESENT; } | |
301 | void SetValue(int value, wxTextAttrDimensionFlags flags) { m_value = value; m_flags = flags; } | |
302 | ||
303 | wxTextAttrUnits GetUnits() const { return (wxTextAttrUnits) (m_flags & wxTEXT_ATTR_UNITS_MASK); } | |
304 | void SetUnits(wxTextAttrUnits units) { m_flags &= ~wxTEXT_ATTR_UNITS_MASK; m_flags |= units; } | |
305 | ||
306 | wxTextBoxAttrPosition GetPosition() const { return (wxTextBoxAttrPosition) (m_flags & wxTEXT_BOX_ATTR_POSITION_MASK); } | |
307 | void SetPosition(wxTextBoxAttrPosition pos) { m_flags &= ~wxTEXT_BOX_ATTR_POSITION_MASK; m_flags |= pos; } | |
308 | ||
309 | bool IsPresent() const { return (m_flags & wxTEXT_ATTR_VALUE_PRESENT) != 0; } | |
310 | void SetPresent(bool b) { m_flags &= ~wxTEXT_ATTR_VALUE_PRESENT_MASK; m_flags |= (b ? wxTEXT_ATTR_VALUE_PRESENT : 0); } | |
311 | ||
312 | int m_value; | |
313 | wxTextAttrDimensionFlags m_flags; | |
314 | }; | |
ce00f59b | 315 | |
24777478 JS |
316 | class WXDLLIMPEXP_CORE wxTextBoxAttrDimensions |
317 | { | |
318 | public: | |
319 | void Reset() { m_left.Reset(); m_top.Reset(); m_right.Reset(); m_bottom.Reset(); } | |
320 | ||
321 | bool operator==(const wxTextBoxAttrDimensions& dims) const { return m_left == dims.m_left && m_top == dims.m_top && m_right == dims.m_right && m_bottom == dims.m_bottom; } | |
322 | ||
323 | // Partial equality test | |
324 | bool EqPartial(const wxTextBoxAttrDimensions& dims) const; | |
325 | ||
326 | // Apply border to 'this', but not if the same as compareWith | |
327 | bool Apply(const wxTextBoxAttrDimensions& dims, const wxTextBoxAttrDimensions* compareWith = NULL); | |
328 | ||
329 | // Collects the attributes that are common to a range of content, building up a note of | |
330 | // which attributes are absent in some objects and which clash in some objects. | |
331 | void CollectCommonAttributes(const wxTextBoxAttrDimensions& attr, wxTextBoxAttrDimensions& clashingAttr, wxTextBoxAttrDimensions& absentAttr); | |
332 | ||
333 | // Remove specified attributes from this object | |
334 | bool RemoveStyle(const wxTextBoxAttrDimensions& attr); | |
335 | ||
336 | wxTextAttrDimension m_left; | |
337 | wxTextAttrDimension m_top; | |
338 | wxTextAttrDimension m_right; | |
339 | wxTextAttrDimension m_bottom; | |
340 | }; | |
341 | ||
342 | // Border styles | |
343 | enum wxTextBoxAttrBorderStyle | |
344 | { | |
345 | wxTEXT_BOX_ATTR_BORDER_NONE = 0, | |
346 | wxTEXT_BOX_ATTR_BORDER_SOLID = 1, | |
347 | wxTEXT_BOX_ATTR_BORDER_DOTTED = 2, | |
348 | wxTEXT_BOX_ATTR_BORDER_DASHED = 3, | |
349 | wxTEXT_BOX_ATTR_BORDER_DOUBLE = 4, | |
350 | wxTEXT_BOX_ATTR_BORDER_GROOVE = 5, | |
351 | wxTEXT_BOX_ATTR_BORDER_RIDGE = 6, | |
352 | wxTEXT_BOX_ATTR_BORDER_INSET = 7, | |
353 | wxTEXT_BOX_ATTR_BORDER_OUTSET = 8 | |
354 | }; | |
355 | ||
356 | // Border style presence flags | |
357 | enum wxTextBoxAttrBorderFlags | |
358 | { | |
359 | wxTEXT_BOX_ATTR_BORDER_STYLE = 0x0001, | |
360 | wxTEXT_BOX_ATTR_BORDER_COLOUR = 0x0002 | |
361 | }; | |
362 | ||
363 | // Float styles | |
364 | enum wxTextBoxAttrFloatStyle | |
365 | { | |
366 | wxTEXT_BOX_ATTR_FLOAT_NONE = 0, | |
367 | wxTEXT_BOX_ATTR_FLOAT_LEFT = 1, | |
368 | wxTEXT_BOX_ATTR_FLOAT_RIGHT = 2 | |
369 | }; | |
370 | ||
371 | // Clear styles | |
372 | enum wxTextBoxAttrClearStyle | |
373 | { | |
374 | wxTEXT_BOX_ATTR_CLEAR_NONE = 0, | |
375 | wxTEXT_BOX_ATTR_CLEAR_LEFT = 1, | |
376 | wxTEXT_BOX_ATTR_CLEAR_RIGHT = 2, | |
377 | wxTEXT_BOX_ATTR_CLEAR_BOTH = 3 | |
378 | }; | |
379 | ||
380 | // Collapse mode styles. TODO: can they be switched on per side? | |
381 | enum wxTextBoxAttrCollapseMode | |
382 | { | |
383 | wxTEXT_BOX_ATTR_COLLAPSE_NONE = 0, | |
384 | wxTEXT_BOX_ATTR_COLLAPSE_FULL = 1 | |
385 | }; | |
386 | ||
387 | // Border | |
388 | class WXDLLIMPEXP_CORE wxTextBoxAttrBorder | |
389 | { | |
390 | public: | |
391 | wxTextBoxAttrBorder() { Reset(); } | |
392 | ||
393 | bool operator==(const wxTextBoxAttrBorder& border) const | |
394 | { | |
395 | return m_flags == border.m_flags && m_borderStyle == border.m_borderStyle && | |
396 | m_borderColour == border.m_borderColour && m_borderWidth == border.m_borderWidth; | |
397 | } | |
398 | ||
399 | void Reset() { m_borderStyle = 0; m_borderColour = 0; m_flags = 0; m_borderWidth.Reset(); } | |
400 | ||
401 | // Partial equality test | |
402 | bool EqPartial(const wxTextBoxAttrBorder& border) const; | |
cdaed652 | 403 | |
24777478 JS |
404 | // Apply border to 'this', but not if the same as compareWith |
405 | bool Apply(const wxTextBoxAttrBorder& border, const wxTextBoxAttrBorder* compareWith = NULL); | |
406 | ||
407 | // Remove specified attributes from this object | |
408 | bool RemoveStyle(const wxTextBoxAttrBorder& attr); | |
409 | ||
410 | // Collects the attributes that are common to a range of content, building up a note of | |
411 | // which attributes are absent in some objects and which clash in some objects. | |
412 | void CollectCommonAttributes(const wxTextBoxAttrBorder& attr, wxTextBoxAttrBorder& clashingAttr, wxTextBoxAttrBorder& absentAttr); | |
413 | ||
414 | void SetStyle(int style) { m_borderStyle = style; m_flags |= wxTEXT_BOX_ATTR_BORDER_STYLE; } | |
415 | int GetStyle() const { return m_borderStyle; } | |
416 | ||
417 | void SetColour(unsigned long colour) { m_borderColour = colour; m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; } | |
418 | void SetColour(const wxColour& colour) { m_borderColour = colour.GetRGB(); m_flags |= wxTEXT_BOX_ATTR_BORDER_COLOUR; } | |
419 | unsigned long GetColourLong() const { return m_borderColour; } | |
420 | wxColour GetColour() const { return wxColour(m_borderColour); } | |
421 | ||
422 | wxTextAttrDimension& GetWidth() { return m_borderWidth; } | |
423 | const wxTextAttrDimension& GetWidth() const { return m_borderWidth; } | |
424 | void SetWidth(const wxTextAttrDimension& width) { m_borderWidth = width; } | |
425 | ||
426 | bool HasStyle() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_STYLE) == 0; } | |
427 | bool HasColour() const { return (m_flags & wxTEXT_BOX_ATTR_BORDER_COLOUR) == 0; } | |
428 | bool HasWidth() const { return m_borderWidth.IsPresent(); } | |
429 | ||
430 | int GetFlags() const { return m_flags; } | |
431 | void SetFlags(int flags) { m_flags = flags; } | |
432 | void AddFlag(int flag) { m_flags |= flag; } | |
433 | void RemoveFlag(int flag) { m_flags &= ~flag; } | |
434 | ||
435 | int m_borderStyle; | |
436 | unsigned long m_borderColour; | |
437 | wxTextAttrDimension m_borderWidth; | |
438 | int m_flags; | |
439 | }; | |
440 | ||
441 | // Borders | |
442 | class WXDLLIMPEXP_CORE wxTextBoxAttrBorders | |
443 | { | |
444 | public: | |
445 | wxTextBoxAttrBorders() { } | |
ce00f59b | 446 | |
24777478 JS |
447 | bool operator==(const wxTextBoxAttrBorders& borders) const |
448 | { | |
449 | return m_left == borders.m_left && m_right == borders.m_right && | |
450 | m_top == borders.m_top && m_bottom == borders.m_bottom; | |
451 | } | |
cdaed652 | 452 | |
24777478 JS |
453 | // Set style of all borders |
454 | void SetStyle(int style); | |
ce00f59b | 455 | |
24777478 JS |
456 | // Set colour of all borders |
457 | void SetColour(unsigned long colour); | |
458 | void SetColour(const wxColour& colour); | |
cdaed652 | 459 | |
24777478 JS |
460 | // Set width of all borders |
461 | void SetWidth(const wxTextAttrDimension& width); | |
462 | ||
463 | // Reset | |
464 | void Reset() { m_left.Reset(); m_right.Reset(); m_top.Reset(); m_bottom.Reset(); } | |
cdaed652 | 465 | |
24777478 JS |
466 | // Partial equality test |
467 | bool EqPartial(const wxTextBoxAttrBorders& borders) const; | |
cdaed652 | 468 | |
24777478 JS |
469 | // Apply border to 'this', but not if the same as compareWith |
470 | bool Apply(const wxTextBoxAttrBorders& borders, const wxTextBoxAttrBorders* compareWith = NULL); | |
cdaed652 | 471 | |
24777478 JS |
472 | // Remove specified attributes from this object |
473 | bool RemoveStyle(const wxTextBoxAttrBorders& attr); | |
cdaed652 | 474 | |
24777478 JS |
475 | // Collects the attributes that are common to a range of content, building up a note of |
476 | // which attributes are absent in some objects and which clash in some objects. | |
477 | void CollectCommonAttributes(const wxTextBoxAttrBorders& attr, wxTextBoxAttrBorders& clashingAttr, wxTextBoxAttrBorders& absentAttr); | |
cdaed652 | 478 | |
24777478 | 479 | wxTextBoxAttrBorder m_left, m_right, m_top, m_bottom; |
cdaed652 | 480 | |
24777478 JS |
481 | }; |
482 | ||
483 | // ---------------------------------------------------------------------------- | |
484 | // wxTextBoxAttr: a structure containing box attributes | |
485 | // ---------------------------------------------------------------------------- | |
486 | ||
487 | class WXDLLIMPEXP_CORE wxTextBoxAttr | |
488 | { | |
489 | public: | |
490 | // ctors | |
491 | wxTextBoxAttr() { Init(); } | |
492 | wxTextBoxAttr(const wxTextBoxAttr& attr) { Init(); (*this) = attr; } | |
493 | ||
494 | // Initialise this object. | |
495 | void Init() { Reset(); } | |
496 | ||
497 | // Reset this object. | |
498 | void Reset(); | |
499 | ||
500 | // Copy. Unecessary since we let it do a binary copy | |
501 | //void Copy(const wxTextBoxAttr& attr); | |
502 | ||
503 | // Assignment | |
504 | //void operator= (const wxTextBoxAttr& attr); | |
505 | ||
506 | // Equality test | |
507 | bool operator== (const wxTextBoxAttr& attr) const; | |
508 | ||
509 | // Partial equality test | |
510 | bool EqPartial(const wxTextBoxAttr& attr) const; | |
511 | ||
512 | // Merges the given attributes. If compareWith | |
513 | // is non-NULL, then it will be used to mask out those attributes that are the same in style | |
514 | // and compareWith, for situations where we don't want to explicitly set inherited attributes. | |
515 | bool Apply(const wxTextBoxAttr& style, const wxTextBoxAttr* compareWith = NULL); | |
516 | ||
517 | // Collects the attributes that are common to a range of content, building up a note of | |
518 | // which attributes are absent in some objects and which clash in some objects. | |
519 | void CollectCommonAttributes(const wxTextBoxAttr& attr, wxTextBoxAttr& clashingAttr, wxTextBoxAttr& absentAttr); | |
520 | ||
521 | // Remove specified attributes from this object | |
522 | bool RemoveStyle(const wxTextBoxAttr& attr); | |
523 | ||
524 | // Set flags | |
525 | void SetFlags(int flags) { m_flags = flags; } | |
526 | ||
527 | // Get flags | |
528 | int GetFlags() const { return m_flags; } | |
529 | ||
530 | // Is this flag present? | |
531 | bool HasFlag(wxTextBoxAttrFlags flag) const { return (m_flags & flag) != 0; } | |
532 | ||
533 | // Remove this flag | |
534 | void RemoveFlag(wxTextBoxAttrFlags flag) { m_flags &= ~flag; } | |
535 | ||
536 | // Add this flag | |
537 | void AddFlag(wxTextBoxAttrFlags flag) { m_flags |= flag; } | |
538 | ||
539 | // Is this default? I.e. no flags set | |
540 | bool IsDefault() const; | |
541 | ||
542 | // Float mode | |
543 | short int GetFloatMode() const { return m_floatMode; } | |
544 | void SetFloatMode(short int mode) { m_floatMode = mode; m_flags |= wxTEXT_BOX_ATTR_FLOAT; } | |
545 | bool HasFloatMode() const { return HasFlag(wxTEXT_BOX_ATTR_FLOAT); } | |
546 | bool IsFloating() const { return HasFloatMode() && GetFloatMode() != wxTEXT_BOX_ATTR_FLOAT_NONE; } | |
547 | ||
548 | // Whether to wrap text after object | |
549 | short int GetClearMode() const { return m_clearMode; } | |
550 | void SetClearMode(short int mode) { m_clearMode = mode; m_flags |= wxTEXT_BOX_ATTR_CLEAR; } | |
551 | bool HasClearMode() const { return HasFlag(wxTEXT_BOX_ATTR_CLEAR); } | |
552 | ||
553 | // Whether to collapse borders | |
554 | int GetCollapseBorders() const { return m_collapseMode ; } | |
555 | void SetCollapseBorders(int collapse) { m_collapseMode = collapse; m_flags |= wxTEXT_BOX_ATTR_COLLAPSE_BORDERS; } | |
556 | bool HasCollapseBorders() const { return HasFlag(wxTEXT_BOX_ATTR_COLLAPSE_BORDERS); } | |
557 | ||
558 | // Margins | |
559 | ||
560 | wxTextAttrDimension& GetLeftMargin() { return m_margins.m_left; } | |
561 | const wxTextAttrDimension& GetLeftMargin() const { return m_margins.m_left; } | |
562 | ||
563 | wxTextAttrDimension& GetRightMargin() { return m_margins.m_right; } | |
564 | const wxTextAttrDimension& GetRightMargin() const { return m_margins.m_right; } | |
565 | ||
566 | wxTextAttrDimension& GetTopMargin() { return m_margins.m_top; } | |
567 | const wxTextAttrDimension& GetTopMargin() const { return m_margins.m_top; } | |
568 | ||
569 | wxTextAttrDimension& GetBottomMargin() { return m_margins.m_bottom; } | |
570 | const wxTextAttrDimension& GetBottomMargin() const { return m_margins.m_bottom; } | |
571 | ||
572 | // Position | |
573 | ||
574 | wxTextAttrDimension& GetLeft() { return m_position.m_left; } | |
575 | const wxTextAttrDimension& GetLeft() const { return m_position.m_left; } | |
576 | ||
577 | wxTextAttrDimension& GetRight() { return m_position.m_right; } | |
578 | const wxTextAttrDimension& GetRight() const { return m_position.m_right; } | |
579 | ||
580 | wxTextAttrDimension& GetTop() { return m_position.m_top; } | |
581 | const wxTextAttrDimension& GetTop() const { return m_position.m_top; } | |
582 | ||
583 | wxTextAttrDimension& GetBottom() { return m_position.m_bottom; } | |
584 | const wxTextAttrDimension& GetBottom() const { return m_position.m_bottom; } | |
585 | ||
586 | // Padding | |
587 | ||
588 | wxTextAttrDimension& GetLeftPadding() { return m_padding.m_left; } | |
589 | const wxTextAttrDimension& GetLeftPadding() const { return m_padding.m_left; } | |
590 | ||
591 | wxTextAttrDimension& GetRightPadding() { return m_padding.m_right; } | |
592 | const wxTextAttrDimension& GetRightPadding() const { return m_padding.m_right; } | |
593 | ||
594 | wxTextAttrDimension& GetTopPadding() { return m_padding.m_top; } | |
595 | const wxTextAttrDimension& GetTopPadding() const { return m_padding.m_top; } | |
596 | ||
597 | wxTextAttrDimension& GetBottomPadding() { return m_padding.m_bottom; } | |
598 | const wxTextAttrDimension& GetBottomPadding() const { return m_padding.m_bottom; } | |
599 | ||
600 | // Border | |
601 | ||
602 | wxTextBoxAttrBorders& GetBorder() { return m_border; } | |
603 | const wxTextBoxAttrBorders& GetBorder() const { return m_border; } | |
604 | ||
605 | wxTextBoxAttrBorder& GetLeftBorder() { return m_border.m_left; } | |
606 | const wxTextBoxAttrBorder& GetLeftBorder() const { return m_border.m_left; } | |
607 | ||
608 | wxTextBoxAttrBorder& GetTopBorder() { return m_border.m_top; } | |
609 | const wxTextBoxAttrBorder& GetTopBorder() const { return m_border.m_top; } | |
610 | ||
611 | wxTextBoxAttrBorder& GetRightBorder() { return m_border.m_right; } | |
612 | const wxTextBoxAttrBorder& GetRightBorder() const { return m_border.m_right; } | |
613 | ||
614 | wxTextBoxAttrBorder& GetBottomBorder() { return m_border.m_bottom; } | |
615 | const wxTextBoxAttrBorder& GetBottomBorder() const { return m_border.m_bottom; } | |
616 | ||
617 | // Outline | |
618 | ||
619 | wxTextBoxAttrBorders& GetOutline() { return m_outline; } | |
620 | const wxTextBoxAttrBorders& GetOutline() const { return m_outline; } | |
621 | ||
622 | wxTextBoxAttrBorder& GetLeftOutline() { return m_outline.m_left; } | |
623 | const wxTextBoxAttrBorder& GetLeftOutline() const { return m_outline.m_left; } | |
624 | ||
625 | wxTextBoxAttrBorder& GetTopOutline() { return m_outline.m_top; } | |
626 | const wxTextBoxAttrBorder& GetTopOutline() const { return m_outline.m_top; } | |
627 | ||
628 | wxTextBoxAttrBorder& GetRightOutline() { return m_outline.m_right; } | |
629 | const wxTextBoxAttrBorder& GetRightOutline() const { return m_outline.m_right; } | |
630 | ||
631 | wxTextBoxAttrBorder& GetBottomOutline() { return m_outline.m_bottom; } | |
632 | const wxTextBoxAttrBorder& GetBottomOutline() const { return m_outline.m_bottom; } | |
633 | ||
634 | ||
635 | // Width and height | |
636 | ||
637 | wxTextAttrDimension& GetWidth() { return m_width; } | |
638 | const wxTextAttrDimension& GetWidth() const { return m_width; } | |
639 | ||
640 | wxTextAttrDimension& GetHeight() { return m_height; } | |
641 | const wxTextAttrDimension& GetHeight() const { return m_height; } | |
642 | ||
643 | public: | |
644 | ||
645 | int m_flags; | |
646 | ||
647 | wxTextBoxAttrDimensions m_margins; | |
648 | wxTextBoxAttrDimensions m_padding; | |
649 | wxTextBoxAttrDimensions m_position; | |
650 | ||
651 | wxTextAttrDimension m_width; | |
652 | wxTextAttrDimension m_height; | |
653 | ||
654 | wxTextBoxAttrBorders m_border; | |
655 | wxTextBoxAttrBorders m_outline; | |
656 | ||
657 | short int m_floatMode; | |
658 | short int m_clearMode; | |
659 | short int m_collapseMode; | |
660 | }; | |
661 | ||
662 | // ---------------------------------------------------------------------------- | |
663 | // wxRichTextAttr: an enhanced attribute | |
664 | // ---------------------------------------------------------------------------- | |
665 | ||
666 | class WXDLLIMPEXP_RICHTEXT wxRichTextAttr: public wxTextAttr | |
667 | { | |
668 | public: | |
669 | wxRichTextAttr(const wxTextAttr& attr) { wxTextAttr::Copy(attr); } | |
670 | wxRichTextAttr(const wxRichTextAttr& attr) { Copy(attr); } | |
671 | wxRichTextAttr() {} | |
672 | ||
673 | // Copy | |
674 | void Copy(const wxRichTextAttr& attr); | |
675 | ||
676 | // Assignment | |
677 | void operator=(const wxRichTextAttr& attr) { Copy(attr); } | |
678 | void operator=(const wxTextAttr& attr) { wxTextAttr::Copy(attr); } | |
679 | ||
680 | // Equality test | |
681 | bool operator==(const wxRichTextAttr& attr) const; | |
682 | ||
683 | // Partial equality test taking comparison object into account | |
684 | bool EqPartial(const wxRichTextAttr& attr) const; | |
685 | ||
686 | // Merges the given attributes. If compareWith | |
687 | // is non-NULL, then it will be used to mask out those attributes that are the same in style | |
688 | // and compareWith, for situations where we don't want to explicitly set inherited attributes. | |
689 | bool Apply(const wxRichTextAttr& style, const wxRichTextAttr* compareWith = NULL); | |
690 | ||
691 | // Collects the attributes that are common to a range of content, building up a note of | |
692 | // which attributes are absent in some objects and which clash in some objects. | |
693 | void CollectCommonAttributes(const wxRichTextAttr& attr, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr); | |
694 | ||
695 | // Remove specified attributes from this object | |
696 | bool RemoveStyle(const wxRichTextAttr& attr); | |
697 | ||
698 | wxTextBoxAttr& GetTextBoxAttr() { return m_textBoxAttr; } | |
699 | const wxTextBoxAttr& GetTextBoxAttr() const { return m_textBoxAttr; } | |
700 | void SetTextBoxAttr(const wxTextBoxAttr& attr) { m_textBoxAttr = attr; } | |
701 | ||
702 | wxTextBoxAttr m_textBoxAttr; | |
cdaed652 VZ |
703 | }; |
704 | ||
5d7836c4 | 705 | /*! |
44cc96a8 JS |
706 | * wxRichTextFontTable |
707 | * Manages quick access to a pool of fonts for rendering rich text | |
5d7836c4 JS |
708 | */ |
709 | ||
44cc96a8 JS |
710 | class WXDLLIMPEXP_RICHTEXT wxRichTextFontTable: public wxObject |
711 | { | |
712 | public: | |
713 | wxRichTextFontTable(); | |
42688aea | 714 | |
44cc96a8 JS |
715 | wxRichTextFontTable(const wxRichTextFontTable& table); |
716 | virtual ~wxRichTextFontTable(); | |
5d7836c4 | 717 | |
44cc96a8 | 718 | bool IsOk() const { return m_refData != NULL; } |
5d7836c4 | 719 | |
24777478 | 720 | wxFont FindFont(const wxRichTextAttr& fontSpec); |
44cc96a8 | 721 | void Clear(); |
d2d0adc7 | 722 | |
44cc96a8 JS |
723 | void operator= (const wxRichTextFontTable& table); |
724 | bool operator == (const wxRichTextFontTable& table) const; | |
725 | bool operator != (const wxRichTextFontTable& table) const { return !(*this == table); } | |
d2d0adc7 | 726 | |
44cc96a8 | 727 | protected: |
d2d0adc7 | 728 | |
44cc96a8 JS |
729 | DECLARE_DYNAMIC_CLASS(wxRichTextFontTable) |
730 | }; | |
d2d0adc7 | 731 | |
5d7836c4 JS |
732 | /*! |
733 | * wxRichTextRange class declaration | |
734 | * This stores beginning and end positions for a range of data. | |
44cc96a8 | 735 | * TODO: consider renaming wxTextRange and using for all text controls. |
5d7836c4 JS |
736 | */ |
737 | ||
3b2cb431 | 738 | class WXDLLIMPEXP_RICHTEXT wxRichTextRange |
5d7836c4 JS |
739 | { |
740 | public: | |
741 | // Constructors | |
742 | ||
743 | wxRichTextRange() { m_start = 0; m_end = 0; } | |
744 | wxRichTextRange(long start, long end) { m_start = start; m_end = end; } | |
745 | wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } | |
746 | ~wxRichTextRange() {} | |
747 | ||
748 | void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } | |
38113684 | 749 | bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); } |
e0983733 | 750 | bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start || m_end != range.m_end); } |
5d7836c4 JS |
751 | wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); } |
752 | wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); } | |
753 | ||
754 | void SetRange(long start, long end) { m_start = start; m_end = end; } | |
755 | ||
756 | void SetStart(long start) { m_start = start; } | |
757 | long GetStart() const { return m_start; } | |
758 | ||
759 | void SetEnd(long end) { m_end = end; } | |
760 | long GetEnd() const { return m_end; } | |
761 | ||
762 | /// Returns true if this range is completely outside 'range' | |
763 | bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; } | |
764 | ||
765 | /// Returns true if this range is completely within 'range' | |
766 | bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; } | |
767 | ||
768 | /// Returns true if the given position is within this range. Allow | |
769 | /// for the possibility of an empty range - assume the position | |
770 | /// is within this empty range. NO, I think we should not match with an empty range. | |
771 | // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); } | |
772 | bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; } | |
773 | ||
774 | /// Limit this range to be within 'range' | |
775 | bool LimitTo(const wxRichTextRange& range) ; | |
776 | ||
777 | /// Gets the length of the range | |
778 | long GetLength() const { return m_end - m_start + 1; } | |
779 | ||
780 | /// Swaps the start and end | |
781 | void Swap() { long tmp = m_start; m_start = m_end; m_end = tmp; } | |
782 | ||
96c9f0f6 JS |
783 | /// Convert to internal form: (n, n) is the range of a single character. |
784 | wxRichTextRange ToInternal() const { return wxRichTextRange(m_start, m_end-1); } | |
785 | ||
786 | /// Convert from internal to public API form: (n, n+1) is the range of a single character. | |
787 | wxRichTextRange FromInternal() const { return wxRichTextRange(m_start, m_end+1); } | |
788 | ||
5d7836c4 JS |
789 | protected: |
790 | long m_start; | |
791 | long m_end; | |
792 | }; | |
793 | ||
1e967276 JS |
794 | #define wxRICHTEXT_ALL wxRichTextRange(-2, -2) |
795 | #define wxRICHTEXT_NONE wxRichTextRange(-1, -1) | |
796 | ||
5d7836c4 JS |
797 | /*! |
798 | * wxRichTextObject class declaration | |
799 | * This is the base for drawable objects. | |
800 | */ | |
801 | ||
3b2cb431 | 802 | class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject |
5d7836c4 JS |
803 | { |
804 | DECLARE_CLASS(wxRichTextObject) | |
805 | public: | |
806 | // Constructors | |
807 | ||
808 | wxRichTextObject(wxRichTextObject* parent = NULL); | |
d3c7fc99 | 809 | virtual ~wxRichTextObject(); |
5d7836c4 JS |
810 | |
811 | // Overrideables | |
812 | ||
813 | /// Draw the item, within the given range. Some objects may ignore the range (for | |
814 | /// example paragraphs) while others must obey it (lines, to implement wrapping) | |
815 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style) = 0; | |
816 | ||
817 | /// Lay the item out at the specified position with the given size constraint. | |
818 | /// Layout must set the cached size. | |
38113684 | 819 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0; |
5d7836c4 JS |
820 | |
821 | /// Hit-testing: returns a flag indicating hit test details, plus | |
822 | /// information about position | |
823 | virtual int HitTest(wxDC& WXUNUSED(dc), const wxPoint& WXUNUSED(pt), long& WXUNUSED(textPosition)) { return false; } | |
824 | ||
825 | /// Finds the absolute position and row height for the given character position | |
826 | virtual bool FindPosition(wxDC& WXUNUSED(dc), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; } | |
827 | ||
828 | /// Get the best size, i.e. the ideal starting size for this object irrespective | |
829 | /// of available space. For a short text string, it will be the size that exactly encloses | |
830 | /// the text. For a longer string, it might use the parent width for example. | |
831 | virtual wxSize GetBestSize() const { return m_size; } | |
832 | ||
833 | /// Get the object size for the given range. Returns false if the range | |
834 | /// is invalid for this object. | |
31778480 | 835 | 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 |
836 | |
837 | /// Do a split, returning an object containing the second part, and setting | |
838 | /// the first part in 'this'. | |
839 | virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; } | |
840 | ||
841 | /// Calculate range. By default, guess that the object is 1 unit long. | |
842 | virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); } | |
843 | ||
844 | /// Delete range | |
845 | virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; } | |
846 | ||
847 | /// Returns true if the object is empty | |
848 | virtual bool IsEmpty() const { return false; } | |
849 | ||
cdaed652 VZ |
850 | /// Whether this object floatable |
851 | virtual bool IsFloatable() const { return false; } | |
852 | ||
853 | /// Whether this object is currently floating | |
854 | virtual bool IsFloating() const { return false; } | |
855 | ||
856 | /// Whether this object is a place holding one | |
857 | // virtual bool IsPlaceHolding() const { return false; } | |
858 | ||
859 | /// Floating direction | |
24777478 | 860 | virtual int GetFloatDirection() const { return wxTEXT_BOX_ATTR_FLOAT_NONE; } |
cdaed652 | 861 | |
5d7836c4 JS |
862 | /// Get any text in this object for the given range |
863 | virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; } | |
864 | ||
865 | /// Returns true if this object can merge itself with the given one. | |
866 | virtual bool CanMerge(wxRichTextObject* WXUNUSED(object)) const { return false; } | |
867 | ||
868 | /// Returns true if this object merged itself with the given one. | |
869 | /// The calling code will then delete the given object. | |
870 | virtual bool Merge(wxRichTextObject* WXUNUSED(object)) { return false; } | |
871 | ||
872 | /// Dump to output stream for debugging | |
873 | virtual void Dump(wxTextOutputStream& stream); | |
ce00f59b | 874 | |
cdaed652 VZ |
875 | /// Can we edit properties via a GUI? |
876 | virtual bool CanEditProperties() const { return false; } | |
877 | ||
878 | /// Edit properties via a GUI | |
879 | virtual bool EditProperties(wxWindow* WXUNUSED(parent), wxRichTextBuffer* WXUNUSED(buffer)) { return false; } | |
5d7836c4 JS |
880 | |
881 | // Accessors | |
882 | ||
883 | /// Get/set the cached object size as calculated by Layout. | |
884 | virtual wxSize GetCachedSize() const { return m_size; } | |
885 | virtual void SetCachedSize(const wxSize& sz) { m_size = sz; } | |
886 | ||
887 | /// Get/set the object position | |
888 | virtual wxPoint GetPosition() const { return m_pos; } | |
889 | virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } | |
890 | ||
891 | /// Get the rectangle enclosing the object | |
892 | virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); } | |
893 | ||
894 | /// Set the range | |
895 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
896 | ||
897 | /// Get the range | |
898 | const wxRichTextRange& GetRange() const { return m_range; } | |
899 | wxRichTextRange& GetRange() { return m_range; } | |
900 | ||
901 | /// Get/set dirty flag (whether the object needs Layout to be called) | |
902 | virtual bool GetDirty() const { return m_dirty; } | |
903 | virtual void SetDirty(bool dirty) { m_dirty = dirty; } | |
904 | ||
905 | /// Is this composite? | |
906 | virtual bool IsComposite() const { return false; } | |
907 | ||
908 | /// Get/set the parent. | |
909 | virtual wxRichTextObject* GetParent() const { return m_parent; } | |
910 | virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; } | |
911 | ||
912 | /// Set the margin around the object | |
913 | virtual void SetMargins(int margin); | |
914 | virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin); | |
915 | virtual int GetLeftMargin() const { return m_leftMargin; } | |
916 | virtual int GetRightMargin() const { return m_rightMargin; } | |
917 | virtual int GetTopMargin() const { return m_topMargin; } | |
918 | virtual int GetBottomMargin() const { return m_bottomMargin; } | |
919 | ||
920 | /// Set attributes object | |
24777478 JS |
921 | void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; } |
922 | const wxRichTextAttr& GetAttributes() const { return m_attributes; } | |
923 | wxRichTextAttr& GetAttributes() { return m_attributes; } | |
5d7836c4 JS |
924 | |
925 | /// Set/get stored descent | |
926 | void SetDescent(int descent) { m_descent = descent; } | |
927 | int GetDescent() const { return m_descent; } | |
928 | ||
44219ff0 JS |
929 | /// Gets the containing buffer |
930 | wxRichTextBuffer* GetBuffer() const; | |
931 | ||
5d7836c4 JS |
932 | // Operations |
933 | ||
934 | /// Clone the object | |
935 | virtual wxRichTextObject* Clone() const { return NULL; } | |
936 | ||
937 | /// Copy | |
938 | void Copy(const wxRichTextObject& obj); | |
939 | ||
940 | /// Reference-counting allows us to use the same object in multiple | |
941 | /// lists (not yet used) | |
942 | void Reference() { m_refCount ++; } | |
943 | void Dereference(); | |
944 | ||
44219ff0 | 945 | /// Convert units in tenths of a millimetre to device units |
cdaed652 | 946 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; |
44219ff0 | 947 | static int ConvertTenthsMMToPixels(int ppi, int units); |
5d7836c4 | 948 | |
24777478 JS |
949 | /// Convert units in pixels to tenths of a millimetre |
950 | int ConvertPixelsToTenthsMM(wxDC& dc, int pixels) const; | |
951 | static int ConvertPixelsToTenthsMM(int ppi, int pixels); | |
952 | ||
5d7836c4 JS |
953 | protected: |
954 | wxSize m_size; | |
955 | wxPoint m_pos; | |
956 | int m_descent; // Descent for this object (if any) | |
957 | bool m_dirty; | |
958 | int m_refCount; | |
959 | wxRichTextObject* m_parent; | |
960 | ||
961 | /// The range of this object (start position to end position) | |
962 | wxRichTextRange m_range; | |
963 | ||
964 | /// Margins | |
965 | int m_leftMargin; | |
966 | int m_rightMargin; | |
967 | int m_topMargin; | |
968 | int m_bottomMargin; | |
969 | ||
970 | /// Attributes | |
24777478 | 971 | wxRichTextAttr m_attributes; |
5d7836c4 JS |
972 | }; |
973 | ||
3b2cb431 | 974 | WX_DECLARE_LIST_WITH_DECL( wxRichTextObject, wxRichTextObjectList, class WXDLLIMPEXP_RICHTEXT ); |
5d7836c4 JS |
975 | |
976 | /*! | |
977 | * wxRichTextCompositeObject class declaration | |
978 | * Objects of this class can contain other objects. | |
979 | */ | |
980 | ||
3b2cb431 | 981 | class WXDLLIMPEXP_RICHTEXT wxRichTextCompositeObject: public wxRichTextObject |
5d7836c4 JS |
982 | { |
983 | DECLARE_CLASS(wxRichTextCompositeObject) | |
984 | public: | |
985 | // Constructors | |
986 | ||
987 | wxRichTextCompositeObject(wxRichTextObject* parent = NULL); | |
d3c7fc99 | 988 | virtual ~wxRichTextCompositeObject(); |
5d7836c4 JS |
989 | |
990 | // Overrideables | |
991 | ||
992 | /// Hit-testing: returns a flag indicating hit test details, plus | |
993 | /// information about position | |
994 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition); | |
995 | ||
996 | /// Finds the absolute position and row height for the given character position | |
997 | virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); | |
998 | ||
999 | /// Calculate range | |
1000 | virtual void CalculateRange(long start, long& end); | |
1001 | ||
1002 | /// Delete range | |
1003 | virtual bool DeleteRange(const wxRichTextRange& range); | |
1004 | ||
1005 | /// Get any text in this object for the given range | |
1006 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
1007 | ||
1008 | /// Dump to output stream for debugging | |
1009 | virtual void Dump(wxTextOutputStream& stream); | |
1010 | ||
1011 | // Accessors | |
1012 | ||
1013 | /// Get the children | |
1014 | wxRichTextObjectList& GetChildren() { return m_children; } | |
1015 | const wxRichTextObjectList& GetChildren() const { return m_children; } | |
1016 | ||
1017 | /// Get the child count | |
1018 | size_t GetChildCount() const ; | |
1019 | ||
1020 | /// Get the nth child | |
1021 | wxRichTextObject* GetChild(size_t n) const ; | |
1022 | ||
1023 | /// Get/set dirty flag | |
1024 | virtual bool GetDirty() const { return m_dirty; } | |
1025 | virtual void SetDirty(bool dirty) { m_dirty = dirty; } | |
1026 | ||
1027 | /// Is this composite? | |
1028 | virtual bool IsComposite() const { return true; } | |
1029 | ||
1030 | /// Returns true if the buffer is empty | |
1031 | virtual bool IsEmpty() const { return GetChildCount() == 0; } | |
1032 | ||
1033 | // Operations | |
1034 | ||
1035 | /// Copy | |
1036 | void Copy(const wxRichTextCompositeObject& obj); | |
1037 | ||
0ca07313 JS |
1038 | /// Assignment |
1039 | void operator= (const wxRichTextCompositeObject& obj) { Copy(obj); } | |
1040 | ||
5d7836c4 JS |
1041 | /// Append a child, returning the position |
1042 | size_t AppendChild(wxRichTextObject* child) ; | |
1043 | ||
1044 | /// Insert the child in front of the given object, or at the beginning | |
1045 | bool InsertChild(wxRichTextObject* child, wxRichTextObject* inFrontOf) ; | |
1046 | ||
1047 | /// Delete the child | |
1048 | bool RemoveChild(wxRichTextObject* child, bool deleteChild = false) ; | |
1049 | ||
1050 | /// Delete all children | |
1051 | bool DeleteChildren() ; | |
1052 | ||
1053 | /// Recursively merge all pieces that can be merged. | |
109bfc88 | 1054 | bool Defragment(const wxRichTextRange& range = wxRICHTEXT_ALL); |
5d7836c4 JS |
1055 | |
1056 | protected: | |
1057 | wxRichTextObjectList m_children; | |
1058 | }; | |
1059 | ||
1060 | /*! | |
1061 | * wxRichTextBox class declaration | |
1062 | * This defines a 2D space to lay out objects | |
1063 | */ | |
1064 | ||
3b2cb431 | 1065 | class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextCompositeObject |
5d7836c4 JS |
1066 | { |
1067 | DECLARE_DYNAMIC_CLASS(wxRichTextBox) | |
1068 | public: | |
1069 | // Constructors | |
1070 | ||
1071 | wxRichTextBox(wxRichTextObject* parent = NULL); | |
1072 | wxRichTextBox(const wxRichTextBox& obj): wxRichTextCompositeObject() { Copy(obj); } | |
1073 | ||
1074 | // Overrideables | |
1075 | ||
1076 | /// Draw the item | |
1077 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); | |
1078 | ||
1079 | /// Lay the item out | |
38113684 | 1080 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 JS |
1081 | |
1082 | /// Get/set the object size for the given range. Returns false if the range | |
1083 | /// is invalid for this object. | |
31778480 | 1084 | 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 |
1085 | |
1086 | // Accessors | |
1087 | ||
1088 | // Operations | |
1089 | ||
1090 | /// Clone | |
1091 | virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); } | |
1092 | ||
1093 | /// Copy | |
1094 | void Copy(const wxRichTextBox& obj); | |
1095 | ||
1096 | protected: | |
1097 | }; | |
1098 | ||
1099 | /*! | |
1100 | * wxRichTextParagraphBox class declaration | |
1101 | * This box knows how to lay out paragraphs. | |
1102 | */ | |
1103 | ||
3b2cb431 | 1104 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphLayoutBox: public wxRichTextBox |
5d7836c4 JS |
1105 | { |
1106 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox) | |
1107 | public: | |
1108 | // Constructors | |
1109 | ||
1110 | wxRichTextParagraphLayoutBox(wxRichTextObject* parent = NULL); | |
0ca07313 | 1111 | wxRichTextParagraphLayoutBox(const wxRichTextParagraphLayoutBox& obj): wxRichTextBox() { Init(); Copy(obj); } |
cdaed652 | 1112 | ~wxRichTextParagraphLayoutBox(); |
5d7836c4 JS |
1113 | |
1114 | // Overrideables | |
1115 | ||
cdaed652 VZ |
1116 | /// Hit-testing: returns a flag indicating hit test details, plus |
1117 | /// information about position | |
1118 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition); | |
1119 | ||
5d7836c4 JS |
1120 | /// Draw the item |
1121 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); | |
1122 | ||
1123 | /// Lay the item out | |
38113684 | 1124 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 JS |
1125 | |
1126 | /// Get/set the object size for the given range. Returns false if the range | |
1127 | /// is invalid for this object. | |
31778480 | 1128 | 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 |
1129 | |
1130 | /// Delete range | |
1131 | virtual bool DeleteRange(const wxRichTextRange& range); | |
1132 | ||
1133 | /// Get any text in this object for the given range | |
1134 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
1135 | ||
1136 | // Accessors | |
1137 | ||
1138 | /// Associate a control with the buffer, for operations that for example require refreshing the window. | |
1139 | void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_ctrl = ctrl; } | |
1140 | ||
1141 | /// Get the associated control. | |
1142 | wxRichTextCtrl* GetRichTextCtrl() const { return m_ctrl; } | |
1143 | ||
0ca07313 JS |
1144 | /// Get/set whether the last paragraph is partial or complete |
1145 | void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; } | |
1146 | bool GetPartialParagraph() const { return m_partialParagraph; } | |
1147 | ||
38f833b1 JS |
1148 | /// If this is a buffer, returns the current style sheet. The base layout box |
1149 | /// class doesn't have an associated style sheet. | |
1150 | virtual wxRichTextStyleSheet* GetStyleSheet() const { return NULL; } | |
1151 | ||
5d7836c4 | 1152 | // Operations |
cdaed652 VZ |
1153 | /// Draw the floats of this buffer |
1154 | void DrawFloats(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); | |
1155 | ||
1156 | /// Move an anchored object to another paragraph | |
1157 | void MoveAnchoredObjectToParagraph(wxRichTextParagraph* from, wxRichTextParagraph* to, wxRichTextAnchoredObject* obj); | |
5d7836c4 JS |
1158 | |
1159 | /// Initialize the object. | |
1160 | void Init(); | |
1161 | ||
1162 | /// Clear all children | |
1163 | virtual void Clear(); | |
1164 | ||
1165 | /// Clear and initialize with one blank paragraph | |
1166 | virtual void Reset(); | |
1167 | ||
1168 | /// Convenience function to add a paragraph of text | |
24777478 | 1169 | virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 JS |
1170 | |
1171 | /// Convenience function to add an image | |
24777478 | 1172 | virtual wxRichTextRange AddImage(const wxImage& image, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 JS |
1173 | |
1174 | /// Adds multiple paragraphs, based on newlines. | |
24777478 | 1175 | virtual wxRichTextRange AddParagraphs(const wxString& text, wxRichTextAttr* paraStyle = NULL); |
5d7836c4 JS |
1176 | |
1177 | /// Get the line at the given position. If caretPosition is true, the position is | |
1178 | /// a caret position, which is normally a smaller number. | |
1179 | virtual wxRichTextLine* GetLineAtPosition(long pos, bool caretPosition = false) const; | |
1180 | ||
1181 | /// Get the line at the given y pixel position, or the last line. | |
1182 | virtual wxRichTextLine* GetLineAtYPosition(int y) const; | |
1183 | ||
1184 | /// Get the paragraph at the given character or caret position | |
1185 | virtual wxRichTextParagraph* GetParagraphAtPosition(long pos, bool caretPosition = false) const; | |
1186 | ||
1187 | /// Get the line size at the given position | |
1188 | virtual wxSize GetLineSizeAtPosition(long pos, bool caretPosition = false) const; | |
1189 | ||
1190 | /// Given a position, get the number of the visible line (potentially many to a paragraph), | |
1191 | /// starting from zero at the start of the buffer. We also have to pass a bool (startOfLine) | |
1192 | /// that indicates whether the caret is being shown at the end of the previous line or at the start | |
1193 | /// of the next, since the caret can be shown at 2 visible positions for the same underlying | |
1194 | /// position. | |
1195 | virtual long GetVisibleLineNumber(long pos, bool caretPosition = false, bool startOfLine = false) const; | |
1196 | ||
1197 | /// Given a line number, get the corresponding wxRichTextLine object. | |
1198 | virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const; | |
1199 | ||
1200 | /// Get the leaf object in a paragraph at this position. | |
1201 | /// Given a line number, get the corresponding wxRichTextLine object. | |
1202 | virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const; | |
1203 | ||
1204 | /// Get the paragraph by number | |
7fe8059f | 1205 | virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const; |
5d7836c4 JS |
1206 | |
1207 | /// Get the paragraph for a given line | |
7fe8059f | 1208 | virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const; |
5d7836c4 JS |
1209 | |
1210 | /// Get the length of the paragraph | |
1211 | virtual int GetParagraphLength(long paragraphNumber) const; | |
1212 | ||
1213 | /// Get the number of paragraphs | |
42632bce | 1214 | virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); } |
5d7836c4 JS |
1215 | |
1216 | /// Get the number of visible lines | |
1217 | virtual int GetLineCount() const; | |
1218 | ||
1219 | /// Get the text of the paragraph | |
1220 | virtual wxString GetParagraphText(long paragraphNumber) const; | |
1221 | ||
1222 | /// Convert zero-based line column and paragraph number to a position. | |
1223 | virtual long XYToPosition(long x, long y) const; | |
1224 | ||
1225 | /// Convert zero-based position to line column and paragraph number | |
1226 | virtual bool PositionToXY(long pos, long* x, long* y) const; | |
1227 | ||
1228 | /// Set text attributes: character and/or paragraph styles. | |
24777478 | 1229 | virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
5d7836c4 | 1230 | |
cdaed652 | 1231 | /// Set image attribute |
24777478 | 1232 | void SetImageStyle(wxRichTextImage *image, const wxRichTextAttr& textAttr, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); |
cdaed652 | 1233 | |
fe5aa22c | 1234 | /// Get the conbined text attributes for this position. |
24777478 | 1235 | virtual bool GetStyle(long position, wxRichTextAttr& style); |
5d7836c4 | 1236 | |
fe5aa22c | 1237 | /// Get the content (uncombined) attributes for this position. |
24777478 | 1238 | virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); |
fe5aa22c JS |
1239 | |
1240 | /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and | |
1241 | /// context attributes. | |
24777478 | 1242 | virtual bool DoGetStyle(long position, wxRichTextAttr& style, bool combineStyles = true); |
fe5aa22c | 1243 | |
59509217 JS |
1244 | /// Get the combined style for a range - if any attribute is different within the range, |
1245 | /// that attribute is not present within the flags | |
24777478 | 1246 | virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style); |
59509217 JS |
1247 | |
1248 | /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of | |
1249 | /// content. | |
24777478 | 1250 | bool CollectStyle(wxRichTextAttr& currentStyle, const wxRichTextAttr& style, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr); |
59509217 | 1251 | |
38f833b1 JS |
1252 | /// Set list style |
1253 | virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1254 | virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); | |
1255 | ||
1256 | /// Clear list for given range | |
1257 | virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
1258 | ||
1259 | /// Number/renumber any list elements in the given range. | |
1260 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
dadd4f55 | 1261 | virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
38f833b1 JS |
1262 | virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); |
1263 | ||
1264 | /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 | |
1265 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
dadd4f55 | 1266 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
38f833b1 JS |
1267 | virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1); |
1268 | ||
1269 | /// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously | |
1270 | /// def/defName can be NULL/empty to indicate that the existing list style should be used. | |
1271 | 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); | |
1272 | ||
d2d0adc7 | 1273 | /// Fills in the attributes for numbering a paragraph after previousParagraph. |
24777478 | 1274 | virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const; |
d2d0adc7 | 1275 | |
5d7836c4 JS |
1276 | /// Test if this whole range has character attributes of the specified kind. If any |
1277 | /// of the attributes are different within the range, the test fails. You | |
1278 | /// can use this to implement, for example, bold button updating. style must have | |
1279 | /// flags indicating which attributes are of interest. | |
24777478 | 1280 | virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; |
5d7836c4 JS |
1281 | |
1282 | /// Test if this whole range has paragraph attributes of the specified kind. If any | |
1283 | /// of the attributes are different within the range, the test fails. You | |
1284 | /// can use this to implement, for example, centering button updating. style must have | |
1285 | /// flags indicating which attributes are of interest. | |
24777478 | 1286 | virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const; |
5d7836c4 JS |
1287 | |
1288 | /// Clone | |
1289 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); } | |
1290 | ||
1291 | /// Insert fragment into this box at the given position. If partialParagraph is true, | |
1292 | /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph | |
1293 | /// marker. | |
0ca07313 | 1294 | virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 JS |
1295 | |
1296 | /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'. | |
0ca07313 | 1297 | virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 | 1298 | |
fe5aa22c JS |
1299 | /// Apply the style sheet to the buffer, for example if the styles have changed. |
1300 | virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet); | |
1301 | ||
5d7836c4 JS |
1302 | /// Copy |
1303 | void Copy(const wxRichTextParagraphLayoutBox& obj); | |
1304 | ||
0ca07313 JS |
1305 | /// Assignment |
1306 | void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); } | |
1307 | ||
5d7836c4 JS |
1308 | /// Calculate ranges |
1309 | virtual void UpdateRanges() { long end; CalculateRange(0, end); } | |
1310 | ||
1311 | /// Get all the text | |
1312 | virtual wxString GetText() const; | |
1313 | ||
1314 | /// Set default style for new content. Setting it to a default attribute | |
1315 | /// makes new content take on the 'basic' style. | |
24777478 | 1316 | virtual bool SetDefaultStyle(const wxRichTextAttr& style); |
5d7836c4 JS |
1317 | |
1318 | /// Get default style | |
24777478 | 1319 | virtual const wxRichTextAttr& GetDefaultStyle() const { return m_defaultAttributes; } |
5d7836c4 JS |
1320 | |
1321 | /// Set basic (overall) style | |
24777478 | 1322 | virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; } |
5d7836c4 JS |
1323 | |
1324 | /// Get basic (overall) style | |
24777478 | 1325 | virtual const wxRichTextAttr& GetBasicStyle() const { return m_attributes; } |
5d7836c4 | 1326 | |
38113684 | 1327 | /// Invalidate the buffer. With no argument, invalidates whole buffer. |
1e967276 | 1328 | void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL); |
ce00f59b | 1329 | |
cdaed652 VZ |
1330 | /// Gather information about floating objects. If untilObj is non-NULL, |
1331 | /// will stop getting information if the current object is this, since we | |
1332 | /// will collect the rest later. | |
1333 | virtual bool UpdateFloatingObjects(int width, wxRichTextObject* untilObj = NULL); | |
38113684 JS |
1334 | |
1335 | /// Get invalid range, rounding to entire paragraphs if argument is true. | |
1336 | wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const; | |
1337 | ||
cdaed652 VZ |
1338 | /// Get the wxRichTextFloatCollector of this object |
1339 | wxRichTextFloatCollector* GetFloatCollector() { return m_floatCollector; } | |
1340 | ||
5d7836c4 JS |
1341 | protected: |
1342 | wxRichTextCtrl* m_ctrl; | |
24777478 | 1343 | wxRichTextAttr m_defaultAttributes; |
38113684 JS |
1344 | |
1345 | /// The invalidated range that will need full layout | |
0ca07313 | 1346 | wxRichTextRange m_invalidRange; |
5d7836c4 JS |
1347 | |
1348 | // Is the last paragraph partial or complete? | |
0ca07313 | 1349 | bool m_partialParagraph; |
cdaed652 VZ |
1350 | |
1351 | // The floating layout state | |
1352 | wxRichTextFloatCollector* m_floatCollector; | |
5d7836c4 JS |
1353 | }; |
1354 | ||
1355 | /*! | |
1356 | * wxRichTextLine class declaration | |
1357 | * This object represents a line in a paragraph, and stores | |
1358 | * offsets from the start of the paragraph representing the | |
1359 | * start and end positions of the line. | |
1360 | */ | |
1361 | ||
3b2cb431 | 1362 | class WXDLLIMPEXP_RICHTEXT wxRichTextLine |
5d7836c4 JS |
1363 | { |
1364 | public: | |
1365 | // Constructors | |
1366 | ||
1367 | wxRichTextLine(wxRichTextParagraph* parent); | |
1e967276 | 1368 | wxRichTextLine(const wxRichTextLine& obj) { Init( NULL); Copy(obj); } |
5d7836c4 JS |
1369 | virtual ~wxRichTextLine() {} |
1370 | ||
1371 | // Overrideables | |
1372 | ||
1373 | // Accessors | |
1374 | ||
1375 | /// Set the range | |
1376 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
1377 | void SetRange(long from, long to) { m_range = wxRichTextRange(from, to); } | |
1378 | ||
1379 | /// Get the parent paragraph | |
1380 | wxRichTextParagraph* GetParent() { return m_parent; } | |
1381 | ||
1382 | /// Get the range | |
1383 | const wxRichTextRange& GetRange() const { return m_range; } | |
1384 | wxRichTextRange& GetRange() { return m_range; } | |
1385 | ||
1e967276 JS |
1386 | /// Get the absolute range |
1387 | wxRichTextRange GetAbsoluteRange() const; | |
1388 | ||
5d7836c4 JS |
1389 | /// Get/set the line size as calculated by Layout. |
1390 | virtual wxSize GetSize() const { return m_size; } | |
1391 | virtual void SetSize(const wxSize& sz) { m_size = sz; } | |
1392 | ||
1393 | /// Get/set the object position relative to the parent | |
1394 | virtual wxPoint GetPosition() const { return m_pos; } | |
1395 | virtual void SetPosition(const wxPoint& pos) { m_pos = pos; } | |
1396 | ||
1397 | /// Get the absolute object position | |
1398 | virtual wxPoint GetAbsolutePosition() const; | |
1399 | ||
1400 | /// Get the rectangle enclosing the line | |
1401 | virtual wxRect GetRect() const { return wxRect(GetAbsolutePosition(), GetSize()); } | |
1402 | ||
1403 | /// Set/get stored descent | |
1404 | void SetDescent(int descent) { m_descent = descent; } | |
1405 | int GetDescent() const { return m_descent; } | |
1406 | ||
2f45f554 JS |
1407 | #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING |
1408 | wxArrayInt& GetObjectSizes() { return m_objectSizes; } | |
1409 | const wxArrayInt& GetObjectSizes() const { return m_objectSizes; } | |
1410 | #endif | |
1411 | ||
5d7836c4 JS |
1412 | // Operations |
1413 | ||
1414 | /// Initialisation | |
1e967276 | 1415 | void Init(wxRichTextParagraph* parent); |
5d7836c4 JS |
1416 | |
1417 | /// Copy | |
1418 | void Copy(const wxRichTextLine& obj); | |
1419 | ||
1420 | /// Clone | |
1421 | virtual wxRichTextLine* Clone() const { return new wxRichTextLine(*this); } | |
1422 | ||
1423 | protected: | |
1424 | ||
1425 | /// The range of the line (start position to end position) | |
1e967276 | 1426 | /// This is relative to the parent paragraph. |
5d7836c4 JS |
1427 | wxRichTextRange m_range; |
1428 | ||
1429 | /// Size and position measured relative to top of paragraph | |
1430 | wxPoint m_pos; | |
1431 | wxSize m_size; | |
1432 | ||
1433 | /// Maximum descent for this line (location of text baseline) | |
1434 | int m_descent; | |
1435 | ||
1436 | // The parent object | |
1437 | wxRichTextParagraph* m_parent; | |
2f45f554 JS |
1438 | |
1439 | #if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING | |
1440 | wxArrayInt m_objectSizes; | |
1441 | #endif | |
5d7836c4 JS |
1442 | }; |
1443 | ||
3b2cb431 | 1444 | WX_DECLARE_LIST_WITH_DECL( wxRichTextLine, wxRichTextLineList , class WXDLLIMPEXP_RICHTEXT ); |
5d7836c4 JS |
1445 | |
1446 | /*! | |
1447 | * wxRichTextParagraph class declaration | |
1448 | * This object represents a single paragraph (or in a straight text editor, a line). | |
1449 | */ | |
1450 | ||
3b2cb431 | 1451 | class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph: public wxRichTextBox |
5d7836c4 JS |
1452 | { |
1453 | DECLARE_DYNAMIC_CLASS(wxRichTextParagraph) | |
1454 | public: | |
1455 | // Constructors | |
1456 | ||
24777478 JS |
1457 | wxRichTextParagraph(wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL); |
1458 | wxRichTextParagraph(const wxString& text, wxRichTextObject* parent = NULL, wxRichTextAttr* paraStyle = NULL, wxRichTextAttr* charStyle = NULL); | |
d3c7fc99 | 1459 | virtual ~wxRichTextParagraph(); |
0ca07313 | 1460 | wxRichTextParagraph(const wxRichTextParagraph& obj): wxRichTextBox() { Copy(obj); } |
5d7836c4 JS |
1461 | |
1462 | // Overrideables | |
1463 | ||
1464 | /// Draw the item | |
1465 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); | |
1466 | ||
1467 | /// Lay the item out | |
38113684 | 1468 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 JS |
1469 | |
1470 | /// Get/set the object size for the given range. Returns false if the range | |
1471 | /// is invalid for this object. | |
31778480 | 1472 | 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 |
1473 | |
1474 | /// Finds the absolute position and row height for the given character position | |
1475 | virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); | |
1476 | ||
1477 | /// Hit-testing: returns a flag indicating hit test details, plus | |
1478 | /// information about position | |
1479 | virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition); | |
1480 | ||
1481 | /// Calculate range | |
1482 | virtual void CalculateRange(long start, long& end); | |
1483 | ||
1484 | // Accessors | |
1485 | ||
1486 | /// Get the cached lines | |
1487 | wxRichTextLineList& GetLines() { return m_cachedLines; } | |
1488 | ||
1489 | // Operations | |
1490 | ||
1491 | /// Copy | |
1492 | void Copy(const wxRichTextParagraph& obj); | |
1493 | ||
1494 | /// Clone | |
1495 | virtual wxRichTextObject* Clone() const { return new wxRichTextParagraph(*this); } | |
1496 | ||
1497 | /// Clear the cached lines | |
1498 | void ClearLines(); | |
1499 | ||
1500 | // Implementation | |
1501 | ||
1502 | /// Apply paragraph styles such as centering to the wrapped lines | |
24777478 | 1503 | virtual void ApplyParagraphStyle(const wxRichTextAttr& attr, const wxRect& rect, wxDC& dc); |
5d7836c4 JS |
1504 | |
1505 | /// Insert text at the given position | |
1506 | virtual bool InsertText(long pos, const wxString& text); | |
1507 | ||
1508 | /// Split an object at this position if necessary, and return | |
1509 | /// the previous object, or NULL if inserting at beginning. | |
1510 | virtual wxRichTextObject* SplitAt(long pos, wxRichTextObject** previousObject = NULL); | |
1511 | ||
1512 | /// Move content to a list from this point | |
1513 | virtual void MoveToList(wxRichTextObject* obj, wxList& list); | |
1514 | ||
1515 | /// Add content back from list | |
1516 | virtual void MoveFromList(wxList& list); | |
1517 | ||
1518 | /// Get the plain text searching from the start or end of the range. | |
1519 | /// The resulting string may be shorter than the range given. | |
1520 | bool GetContiguousPlainText(wxString& text, const wxRichTextRange& range, bool fromStart = true); | |
1521 | ||
1522 | /// Find a suitable wrap position. wrapPosition is the last position in the line to the left | |
1523 | /// of the split. | |
31778480 | 1524 | bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents); |
5d7836c4 JS |
1525 | |
1526 | /// Find the object at the given position | |
1527 | wxRichTextObject* FindObjectAtPosition(long position); | |
1528 | ||
1529 | /// Get the bullet text for this paragraph. | |
1530 | wxString GetBulletText(); | |
1531 | ||
1e967276 JS |
1532 | /// Allocate or reuse a line object |
1533 | wxRichTextLine* AllocateLine(int pos); | |
1534 | ||
1535 | /// Clear remaining unused line objects, if any | |
1536 | bool ClearUnusedLines(int lineCount); | |
1537 | ||
fe5aa22c JS |
1538 | /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically |
1539 | /// retrieve the actual style. | |
24777478 | 1540 | wxRichTextAttr GetCombinedAttributes(const wxRichTextAttr& contentStyle) const; |
fe5aa22c JS |
1541 | |
1542 | /// Get combined attributes of the base style and paragraph style. | |
24777478 | 1543 | wxRichTextAttr GetCombinedAttributes() const; |
fe5aa22c | 1544 | |
ff76711f JS |
1545 | /// Get the first position from pos that has a line break character. |
1546 | long GetFirstLineBreakPosition(long pos); | |
1547 | ||
cfa3b256 JS |
1548 | /// Create default tabstop array |
1549 | static void InitDefaultTabs(); | |
1550 | ||
1551 | /// Clear default tabstop array | |
1552 | static void ClearDefaultTabs(); | |
1553 | ||
1554 | /// Get default tabstop array | |
1555 | static const wxArrayInt& GetDefaultTabs() { return sm_defaultTabs; } | |
1556 | ||
cdaed652 VZ |
1557 | /// Layout the floats object |
1558 | void LayoutFloat(wxDC& dc, const wxRect& rect, int style, wxRichTextFloatCollector* floatCollector); | |
1559 | ||
5d7836c4 JS |
1560 | protected: |
1561 | /// The lines that make up the wrapped paragraph | |
1562 | wxRichTextLineList m_cachedLines; | |
cfa3b256 JS |
1563 | |
1564 | /// Default tabstops | |
1565 | static wxArrayInt sm_defaultTabs; | |
cdaed652 VZ |
1566 | |
1567 | friend class wxRichTextFloatCollector; | |
5d7836c4 JS |
1568 | }; |
1569 | ||
1570 | /*! | |
1571 | * wxRichTextPlainText class declaration | |
1572 | * This object represents a single piece of text. | |
1573 | */ | |
1574 | ||
3b2cb431 | 1575 | class WXDLLIMPEXP_RICHTEXT wxRichTextPlainText: public wxRichTextObject |
5d7836c4 JS |
1576 | { |
1577 | DECLARE_DYNAMIC_CLASS(wxRichTextPlainText) | |
1578 | public: | |
1579 | // Constructors | |
1580 | ||
24777478 | 1581 | wxRichTextPlainText(const wxString& text = wxEmptyString, wxRichTextObject* parent = NULL, wxRichTextAttr* style = NULL); |
0ca07313 | 1582 | wxRichTextPlainText(const wxRichTextPlainText& obj): wxRichTextObject() { Copy(obj); } |
5d7836c4 JS |
1583 | |
1584 | // Overrideables | |
1585 | ||
1586 | /// Draw the item | |
1587 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); | |
1588 | ||
1589 | /// Lay the item out | |
38113684 | 1590 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 JS |
1591 | |
1592 | /// Get/set the object size for the given range. Returns false if the range | |
1593 | /// is invalid for this object. | |
31778480 | 1594 | 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 |
1595 | |
1596 | /// Get any text in this object for the given range | |
1597 | virtual wxString GetTextForRange(const wxRichTextRange& range) const; | |
1598 | ||
1599 | /// Do a split, returning an object containing the second part, and setting | |
1600 | /// the first part in 'this'. | |
1601 | virtual wxRichTextObject* DoSplit(long pos); | |
1602 | ||
1603 | /// Calculate range | |
1604 | virtual void CalculateRange(long start, long& end); | |
1605 | ||
1606 | /// Delete range | |
1607 | virtual bool DeleteRange(const wxRichTextRange& range); | |
1608 | ||
1609 | /// Returns true if the object is empty | |
7fe8059f | 1610 | virtual bool IsEmpty() const { return m_text.empty(); } |
5d7836c4 JS |
1611 | |
1612 | /// Returns true if this object can merge itself with the given one. | |
1613 | virtual bool CanMerge(wxRichTextObject* object) const; | |
1614 | ||
1615 | /// Returns true if this object merged itself with the given one. | |
1616 | /// The calling code will then delete the given object. | |
1617 | virtual bool Merge(wxRichTextObject* object); | |
1618 | ||
1619 | /// Dump to output stream for debugging | |
1620 | virtual void Dump(wxTextOutputStream& stream); | |
1621 | ||
ff76711f JS |
1622 | /// Get the first position from pos that has a line break character. |
1623 | long GetFirstLineBreakPosition(long pos); | |
1624 | ||
5d7836c4 JS |
1625 | // Accessors |
1626 | ||
1627 | /// Get the text | |
1628 | const wxString& GetText() const { return m_text; } | |
1629 | ||
1630 | /// Set the text | |
1631 | void SetText(const wxString& text) { m_text = text; } | |
1632 | ||
1633 | // Operations | |
1634 | ||
1635 | /// Copy | |
1636 | void Copy(const wxRichTextPlainText& obj); | |
1637 | ||
1638 | /// Clone | |
1639 | virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); } | |
7f0d9d71 | 1640 | private: |
24777478 | 1641 | bool DrawTabbedString(wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected); |
5d7836c4 JS |
1642 | |
1643 | protected: | |
1644 | wxString m_text; | |
1645 | }; | |
1646 | ||
1647 | /*! | |
1648 | * wxRichTextImageBlock stores information about an image, in binary in-memory form | |
1649 | */ | |
1650 | ||
b5dbe15d VS |
1651 | class WXDLLIMPEXP_FWD_BASE wxDataInputStream; |
1652 | class WXDLLIMPEXP_FWD_BASE wxDataOutputStream; | |
5d7836c4 | 1653 | |
3b2cb431 | 1654 | class WXDLLIMPEXP_RICHTEXT wxRichTextImageBlock: public wxObject |
5d7836c4 JS |
1655 | { |
1656 | public: | |
1657 | wxRichTextImageBlock(); | |
1658 | wxRichTextImageBlock(const wxRichTextImageBlock& block); | |
d3c7fc99 | 1659 | virtual ~wxRichTextImageBlock(); |
5d7836c4 JS |
1660 | |
1661 | void Init(); | |
1662 | void Clear(); | |
1663 | ||
1664 | // Load the original image into a memory block. | |
1665 | // If the image is not a JPEG, we must convert it into a JPEG | |
1666 | // to conserve space. | |
1667 | // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to | |
1668 | // load the image a 2nd time. | |
d75a69e8 FM |
1669 | virtual bool MakeImageBlock(const wxString& filename, wxBitmapType imageType, |
1670 | wxImage& image, bool convertToJPEG = true); | |
5d7836c4 JS |
1671 | |
1672 | // Make an image block from the wxImage in the given | |
1673 | // format. | |
d75a69e8 | 1674 | virtual bool MakeImageBlock(wxImage& image, wxBitmapType imageType, int quality = 80); |
ce00f59b | 1675 | |
cdaed652 VZ |
1676 | // Uses a const wxImage for efficiency, but can't set quality (only relevant for JPEG) |
1677 | virtual bool MakeImageBlockDefaultQuality(const wxImage& image, wxBitmapType imageType); | |
1678 | ||
1679 | // Makes the image block | |
1680 | virtual bool DoMakeImageBlock(const wxImage& image, wxBitmapType imageType); | |
5d7836c4 JS |
1681 | |
1682 | // Write to a file | |
1683 | bool Write(const wxString& filename); | |
1684 | ||
1685 | // Write data in hex to a stream | |
1686 | bool WriteHex(wxOutputStream& stream); | |
1687 | ||
1688 | // Read data in hex from a stream | |
d75a69e8 | 1689 | bool ReadHex(wxInputStream& stream, int length, wxBitmapType imageType); |
5d7836c4 JS |
1690 | |
1691 | // Copy from 'block' | |
1692 | void Copy(const wxRichTextImageBlock& block); | |
1693 | ||
1694 | // Load a wxImage from the block | |
1695 | bool Load(wxImage& image); | |
1696 | ||
1697 | //// Operators | |
1698 | void operator=(const wxRichTextImageBlock& block); | |
1699 | ||
1700 | //// Accessors | |
1701 | ||
1702 | unsigned char* GetData() const { return m_data; } | |
1703 | size_t GetDataSize() const { return m_dataSize; } | |
d75a69e8 | 1704 | wxBitmapType GetImageType() const { return m_imageType; } |
5d7836c4 JS |
1705 | |
1706 | void SetData(unsigned char* image) { m_data = image; } | |
1707 | void SetDataSize(size_t size) { m_dataSize = size; } | |
d75a69e8 | 1708 | void SetImageType(wxBitmapType imageType) { m_imageType = imageType; } |
5d7836c4 | 1709 | |
b7cacb43 VZ |
1710 | bool Ok() const { return IsOk(); } |
1711 | bool IsOk() const { return GetData() != NULL; } | |
5d7836c4 | 1712 | |
d2d0adc7 JS |
1713 | // Gets the extension for the block's type |
1714 | wxString GetExtension() const; | |
1715 | ||
5d7836c4 JS |
1716 | /// Implementation |
1717 | ||
d2d0adc7 | 1718 | // Allocate and read from stream as a block of memory |
5d7836c4 JS |
1719 | static unsigned char* ReadBlock(wxInputStream& stream, size_t size); |
1720 | static unsigned char* ReadBlock(const wxString& filename, size_t size); | |
1721 | ||
1722 | // Write memory block to stream | |
1723 | static bool WriteBlock(wxOutputStream& stream, unsigned char* block, size_t size); | |
1724 | ||
1725 | // Write memory block to file | |
1726 | static bool WriteBlock(const wxString& filename, unsigned char* block, size_t size); | |
1727 | ||
1728 | protected: | |
1729 | // Size in bytes of the image stored. | |
1730 | // This is in the raw, original form such as a JPEG file. | |
1731 | unsigned char* m_data; | |
1732 | size_t m_dataSize; | |
d75a69e8 | 1733 | wxBitmapType m_imageType; |
5d7836c4 JS |
1734 | }; |
1735 | ||
cdaed652 VZ |
1736 | /*! |
1737 | * wxRichTextAnchoredObject class declaration | |
1738 | * This object is an abstract one that represent some objects which can floats | |
1739 | */ | |
1740 | class WXDLLIMPEXP_RICHTEXT wxRichTextAnchoredObject: public wxRichTextObject | |
1741 | { | |
1742 | DECLARE_CLASS(wxRichTextAnchoredObject) | |
1743 | public: | |
1744 | // Constructors | |
24777478 | 1745 | wxRichTextAnchoredObject(wxRichTextObject* parent = NULL, const wxRichTextAttr& attr = wxRichTextAttr()); |
cdaed652 VZ |
1746 | wxRichTextAnchoredObject(const wxRichTextAnchoredObject& obj) : wxRichTextObject(obj) /* , m_ph(NULL) */ { Copy(obj); } |
1747 | ~wxRichTextAnchoredObject(); | |
1748 | ||
1749 | // Virtuals | |
1750 | virtual bool IsFloatable() const { return true; } | |
1751 | ||
1752 | /// Whether this object is currently floating | |
24777478 | 1753 | virtual bool IsFloating() const { return GetAttributes().GetTextBoxAttr().IsFloating(); } |
cdaed652 VZ |
1754 | |
1755 | virtual void SetParent(wxRichTextObject* parent); | |
1756 | ||
1757 | // Accessors | |
cdaed652 VZ |
1758 | |
1759 | /// The floating direction | |
24777478 | 1760 | virtual int GetFloatDirection() const { return GetAttributes().GetTextBoxAttr().GetFloatMode(); } |
cdaed652 VZ |
1761 | |
1762 | void operator=(const wxRichTextAnchoredObject&) { wxASSERT("Nobody can reset this object using ="); } | |
1763 | ||
1764 | // Functions | |
1765 | void Copy(const wxRichTextAnchoredObject& obj); | |
1766 | ||
1767 | protected: | |
24777478 | 1768 | |
cdaed652 | 1769 | }; |
5d7836c4 JS |
1770 | |
1771 | /*! | |
1772 | * wxRichTextImage class declaration | |
1773 | * This object represents an image. | |
1774 | */ | |
1775 | ||
cdaed652 | 1776 | class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextAnchoredObject |
5d7836c4 JS |
1777 | { |
1778 | DECLARE_DYNAMIC_CLASS(wxRichTextImage) | |
1779 | public: | |
1780 | // Constructors | |
1781 | ||
cdaed652 | 1782 | wxRichTextImage(wxRichTextObject* parent = NULL): wxRichTextAnchoredObject(parent) { } |
24777478 JS |
1783 | wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL); |
1784 | wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL, wxRichTextAttr* charStyle = NULL); | |
cdaed652 | 1785 | wxRichTextImage(const wxRichTextImage& obj): wxRichTextAnchoredObject(obj) { Copy(obj); } |
5d7836c4 JS |
1786 | |
1787 | // Overrideables | |
1788 | ||
1789 | /// Draw the item | |
1790 | virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style); | |
1791 | ||
1792 | /// Lay the item out | |
38113684 | 1793 | virtual bool Layout(wxDC& dc, const wxRect& rect, int style); |
5d7836c4 JS |
1794 | |
1795 | /// Get the object size for the given range. Returns false if the range | |
1796 | /// is invalid for this object. | |
31778480 | 1797 | 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 |
1798 | |
1799 | /// Returns true if the object is empty | |
cdaed652 VZ |
1800 | virtual bool IsEmpty() const { return !m_imageBlock.Ok(); } |
1801 | ||
1802 | /// Can we edit properties via a GUI? | |
1803 | virtual bool CanEditProperties() const { return true; } | |
1804 | ||
1805 | /// Edit properties via a GUI | |
1806 | virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer); | |
5d7836c4 JS |
1807 | |
1808 | // Accessors | |
1809 | ||
cdaed652 VZ |
1810 | /// Get the image cache (scaled bitmap) |
1811 | const wxBitmap& GetImageCache() const { return m_imageCache; } | |
5d7836c4 | 1812 | |
cdaed652 VZ |
1813 | /// Set the image cache |
1814 | void SetImageCache(const wxBitmap& bitmap) { m_imageCache = bitmap; } | |
1815 | ||
1816 | /// Reset the image cache | |
1817 | void ResetImageCache() { m_imageCache = wxNullBitmap; } | |
5d7836c4 JS |
1818 | |
1819 | /// Get the image block containing the raw data | |
1820 | wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; } | |
1821 | ||
1822 | // Operations | |
1823 | ||
1824 | /// Copy | |
1825 | void Copy(const wxRichTextImage& obj); | |
1826 | ||
1827 | /// Clone | |
1828 | virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); } | |
1829 | ||
cdaed652 VZ |
1830 | /// Create a cached image at the required size |
1831 | virtual bool LoadImageCache(wxDC& dc, bool resetCache = false); | |
5d7836c4 JS |
1832 | |
1833 | protected: | |
5d7836c4 | 1834 | wxRichTextImageBlock m_imageBlock; |
cdaed652 | 1835 | wxBitmap m_imageCache; |
5d7836c4 JS |
1836 | }; |
1837 | ||
1838 | ||
1839 | /*! | |
1840 | * wxRichTextBuffer class declaration | |
1841 | * This is a kind of box, used to represent the whole buffer | |
1842 | */ | |
1843 | ||
b5dbe15d VS |
1844 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCommand; |
1845 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction; | |
5d7836c4 | 1846 | |
3b2cb431 | 1847 | class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox |
5d7836c4 JS |
1848 | { |
1849 | DECLARE_DYNAMIC_CLASS(wxRichTextBuffer) | |
1850 | public: | |
1851 | // Constructors | |
1852 | ||
1853 | wxRichTextBuffer() { Init(); } | |
0ca07313 | 1854 | wxRichTextBuffer(const wxRichTextBuffer& obj): wxRichTextParagraphLayoutBox() { Init(); Copy(obj); } |
d3c7fc99 | 1855 | virtual ~wxRichTextBuffer() ; |
5d7836c4 JS |
1856 | |
1857 | // Accessors | |
1858 | ||
1859 | /// Gets the command processor | |
1860 | wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; } | |
1861 | ||
1862 | /// Set style sheet, if any. | |
1863 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; } | |
38f833b1 JS |
1864 | virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } |
1865 | ||
d2d0adc7 JS |
1866 | /// Set style sheet and notify of the change |
1867 | bool SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet); | |
1868 | ||
38f833b1 JS |
1869 | /// Push style sheet to top of stack |
1870 | bool PushStyleSheet(wxRichTextStyleSheet* styleSheet); | |
1871 | ||
1872 | /// Pop style sheet from top of stack | |
1873 | wxRichTextStyleSheet* PopStyleSheet(); | |
5d7836c4 | 1874 | |
44cc96a8 JS |
1875 | /// Set/get table storing fonts |
1876 | wxRichTextFontTable& GetFontTable() { return m_fontTable; } | |
1877 | const wxRichTextFontTable& GetFontTable() const { return m_fontTable; } | |
1878 | void SetFontTable(const wxRichTextFontTable& table) { m_fontTable = table; } | |
1879 | ||
5d7836c4 JS |
1880 | // Operations |
1881 | ||
1882 | /// Initialisation | |
1883 | void Init(); | |
1884 | ||
85d8909b JS |
1885 | /// Clears the buffer, adds an empty paragraph, and clears the command processor. |
1886 | virtual void ResetAndClearCommands(); | |
5d7836c4 JS |
1887 | |
1888 | /// Load a file | |
d75a69e8 | 1889 | virtual bool LoadFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 JS |
1890 | |
1891 | /// Save a file | |
d75a69e8 | 1892 | virtual bool SaveFile(const wxString& filename, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 JS |
1893 | |
1894 | /// Load from a stream | |
d75a69e8 | 1895 | virtual bool LoadFile(wxInputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 JS |
1896 | |
1897 | /// Save to a stream | |
d75a69e8 | 1898 | virtual bool SaveFile(wxOutputStream& stream, wxRichTextFileType type = wxRICHTEXT_TYPE_ANY); |
5d7836c4 | 1899 | |
d2d0adc7 JS |
1900 | /// Set the handler flags, controlling loading and saving |
1901 | void SetHandlerFlags(int flags) { m_handlerFlags = flags; } | |
1902 | ||
1903 | /// Get the handler flags, controlling loading and saving | |
1904 | int GetHandlerFlags() const { return m_handlerFlags; } | |
1905 | ||
5d7836c4 | 1906 | /// Convenience function to add a paragraph of text |
24777478 | 1907 | virtual wxRichTextRange AddParagraph(const wxString& text, wxRichTextAttr* paraStyle = NULL) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text, paraStyle); } |
5d7836c4 JS |
1908 | |
1909 | /// Begin collapsing undo/redo commands. Note that this may not work properly | |
1910 | /// if combining commands that delete or insert content, changing ranges for | |
1911 | /// subsequent actions. | |
1912 | virtual bool BeginBatchUndo(const wxString& cmdName); | |
1913 | ||
1914 | /// End collapsing undo/redo commands | |
1915 | virtual bool EndBatchUndo(); | |
1916 | ||
1917 | /// Collapsing commands? | |
1918 | virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; } | |
1919 | ||
1920 | /// Submit immediately, or delay according to whether collapsing is on | |
1921 | virtual bool SubmitAction(wxRichTextAction* action); | |
1922 | ||
1923 | /// Get collapsed command | |
1924 | virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; } | |
1925 | ||
1926 | /// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented | |
1927 | /// differently by each command. If not dealt with by a command implementation, then | |
1928 | /// it will be implemented automatically by not storing the command in the undo history | |
1929 | /// when the action is submitted to the command processor. | |
1930 | virtual bool BeginSuppressUndo(); | |
1931 | ||
1932 | /// End suppressing undo/redo commands. | |
1933 | virtual bool EndSuppressUndo(); | |
1934 | ||
1935 | /// Collapsing commands? | |
1936 | virtual bool SuppressingUndo() const { return m_suppressUndo > 0; } | |
1937 | ||
1938 | /// Copy the range to the clipboard | |
1939 | virtual bool CopyToClipboard(const wxRichTextRange& range); | |
1940 | ||
1941 | /// Paste the clipboard content to the buffer | |
1942 | virtual bool PasteFromClipboard(long position); | |
1943 | ||
1944 | /// Can we paste from the clipboard? | |
1945 | virtual bool CanPasteFromClipboard() const; | |
1946 | ||
1947 | /// Begin using a style | |
24777478 | 1948 | virtual bool BeginStyle(const wxRichTextAttr& style); |
5d7836c4 JS |
1949 | |
1950 | /// End the style | |
1951 | virtual bool EndStyle(); | |
1952 | ||
1953 | /// End all styles | |
1954 | virtual bool EndAllStyles(); | |
1955 | ||
1956 | /// Clear the style stack | |
1957 | virtual void ClearStyleStack(); | |
1958 | ||
1959 | /// Get the size of the style stack, for example to check correct nesting | |
3b38e2a0 | 1960 | virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); } |
5d7836c4 JS |
1961 | |
1962 | /// Begin using bold | |
1963 | bool BeginBold(); | |
1964 | ||
1965 | /// End using bold | |
1966 | bool EndBold() { return EndStyle(); } | |
1967 | ||
1968 | /// Begin using italic | |
1969 | bool BeginItalic(); | |
1970 | ||
1971 | /// End using italic | |
1972 | bool EndItalic() { return EndStyle(); } | |
1973 | ||
1974 | /// Begin using underline | |
1975 | bool BeginUnderline(); | |
1976 | ||
1977 | /// End using underline | |
1978 | bool EndUnderline() { return EndStyle(); } | |
1979 | ||
1980 | /// Begin using point size | |
1981 | bool BeginFontSize(int pointSize); | |
1982 | ||
1983 | /// End using point size | |
1984 | bool EndFontSize() { return EndStyle(); } | |
1985 | ||
1986 | /// Begin using this font | |
1987 | bool BeginFont(const wxFont& font); | |
1988 | ||
1989 | /// End using a font | |
1990 | bool EndFont() { return EndStyle(); } | |
1991 | ||
1992 | /// Begin using this colour | |
1993 | bool BeginTextColour(const wxColour& colour); | |
1994 | ||
1995 | /// End using a colour | |
1996 | bool EndTextColour() { return EndStyle(); } | |
1997 | ||
1998 | /// Begin using alignment | |
1999 | bool BeginAlignment(wxTextAttrAlignment alignment); | |
2000 | ||
2001 | /// End alignment | |
2002 | bool EndAlignment() { return EndStyle(); } | |
2003 | ||
2004 | /// Begin left indent | |
2005 | bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0); | |
2006 | ||
2007 | /// End left indent | |
2008 | bool EndLeftIndent() { return EndStyle(); } | |
2009 | ||
2010 | /// Begin right indent | |
2011 | bool BeginRightIndent(int rightIndent); | |
2012 | ||
2013 | /// End right indent | |
2014 | bool EndRightIndent() { return EndStyle(); } | |
2015 | ||
2016 | /// Begin paragraph spacing | |
2017 | bool BeginParagraphSpacing(int before, int after); | |
2018 | ||
2019 | /// End paragraph spacing | |
2020 | bool EndParagraphSpacing() { return EndStyle(); } | |
2021 | ||
2022 | /// Begin line spacing | |
2023 | bool BeginLineSpacing(int lineSpacing); | |
2024 | ||
2025 | /// End line spacing | |
2026 | bool EndLineSpacing() { return EndStyle(); } | |
2027 | ||
2028 | /// Begin numbered bullet | |
2029 | bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD); | |
2030 | ||
2031 | /// End numbered bullet | |
2032 | bool EndNumberedBullet() { return EndStyle(); } | |
2033 | ||
2034 | /// Begin symbol bullet | |
d2d0adc7 | 2035 | bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL); |
5d7836c4 JS |
2036 | |
2037 | /// End symbol bullet | |
2038 | bool EndSymbolBullet() { return EndStyle(); } | |
2039 | ||
f089713f JS |
2040 | /// Begin standard bullet |
2041 | bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD); | |
2042 | ||
2043 | /// End standard bullet | |
2044 | bool EndStandardBullet() { return EndStyle(); } | |
2045 | ||
5d7836c4 JS |
2046 | /// Begin named character style |
2047 | bool BeginCharacterStyle(const wxString& characterStyle); | |
2048 | ||
2049 | /// End named character style | |
2050 | bool EndCharacterStyle() { return EndStyle(); } | |
2051 | ||
2052 | /// Begin named paragraph style | |
2053 | bool BeginParagraphStyle(const wxString& paragraphStyle); | |
2054 | ||
2055 | /// End named character style | |
2056 | bool EndParagraphStyle() { return EndStyle(); } | |
f089713f JS |
2057 | |
2058 | /// Begin named list style | |
2059 | bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1); | |
2060 | ||
2061 | /// End named character style | |
2062 | bool EndListStyle() { return EndStyle(); } | |
5d7836c4 | 2063 | |
d2d0adc7 JS |
2064 | /// Begin URL |
2065 | bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString); | |
2066 | ||
2067 | /// End URL | |
2068 | bool EndURL() { return EndStyle(); } | |
2069 | ||
2070 | // Event handling | |
2071 | ||
2072 | /// Add an event handler | |
2073 | bool AddEventHandler(wxEvtHandler* handler); | |
2074 | ||
2075 | /// Remove an event handler | |
2076 | bool RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler = false); | |
2077 | ||
2078 | /// Clear event handlers | |
2079 | void ClearEventHandlers(); | |
2080 | ||
2081 | /// Send event to event handlers. If sendToAll is true, will send to all event handlers, | |
2082 | /// otherwise will stop at the first successful one. | |
2083 | bool SendEvent(wxEvent& event, bool sendToAll = true); | |
2084 | ||
5d7836c4 JS |
2085 | // Implementation |
2086 | ||
2087 | /// Copy | |
0ca07313 | 2088 | void Copy(const wxRichTextBuffer& obj); |
5d7836c4 JS |
2089 | |
2090 | /// Clone | |
2091 | virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); } | |
2092 | ||
0ca07313 JS |
2093 | /// Submit command to insert paragraphs |
2094 | bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0); | |
2095 | ||
5d7836c4 | 2096 | /// Submit command to insert the given text |
fe5aa22c | 2097 | bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0); |
5d7836c4 JS |
2098 | |
2099 | /// Submit command to insert a newline | |
fe5aa22c | 2100 | bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0); |
5d7836c4 JS |
2101 | |
2102 | /// Submit command to insert the given image | |
24777478 JS |
2103 | bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0, |
2104 | const wxRichTextAttr& textAttr = wxRichTextAttr()); | |
cdaed652 VZ |
2105 | |
2106 | /// Submit command to insert an object | |
2107 | bool InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags); | |
5d7836c4 JS |
2108 | |
2109 | /// Submit command to delete this range | |
12cc29c5 | 2110 | bool DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl); |
5d7836c4 JS |
2111 | |
2112 | /// Mark modified | |
2113 | void Modify(bool modify = true) { m_modified = modify; } | |
2114 | bool IsModified() const { return m_modified; } | |
2115 | ||
fe5aa22c JS |
2116 | /// Get the style that is appropriate for a new paragraph at this position. |
2117 | /// If the previous paragraph has a paragraph style name, look up the next-paragraph | |
2118 | /// style. | |
24777478 | 2119 | wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false, bool lookUpNewParaStyle=false) const; |
fe5aa22c | 2120 | |
5d7836c4 JS |
2121 | /// Dumps contents of buffer for debugging purposes |
2122 | virtual void Dump(); | |
2123 | virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); } | |
2124 | ||
2125 | /// Returns the file handlers | |
2126 | static wxList& GetHandlers() { return sm_handlers; } | |
2127 | ||
2128 | /// Adds a handler to the end | |
2129 | static void AddHandler(wxRichTextFileHandler *handler); | |
2130 | ||
2131 | /// Inserts a handler at the front | |
2132 | static void InsertHandler(wxRichTextFileHandler *handler); | |
2133 | ||
2134 | /// Removes a handler | |
2135 | static bool RemoveHandler(const wxString& name); | |
2136 | ||
2137 | /// Finds a handler by name | |
2138 | static wxRichTextFileHandler *FindHandler(const wxString& name); | |
2139 | ||
2140 | /// Finds a handler by extension and type | |
d75a69e8 | 2141 | static wxRichTextFileHandler *FindHandler(const wxString& extension, wxRichTextFileType imageType); |
5d7836c4 JS |
2142 | |
2143 | /// Finds a handler by filename or, if supplied, type | |
d75a69e8 FM |
2144 | static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, |
2145 | wxRichTextFileType imageType); | |
5d7836c4 JS |
2146 | |
2147 | /// Finds a handler by type | |
d75a69e8 | 2148 | static wxRichTextFileHandler *FindHandler(wxRichTextFileType imageType); |
5d7836c4 | 2149 | |
1e967276 JS |
2150 | /// Gets a wildcard incorporating all visible handlers. If 'types' is present, |
2151 | /// will be filled with the file type corresponding to each filter. This can be | |
2152 | /// used to determine the type to pass to LoadFile given a selected filter. | |
2153 | static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL); | |
5d7836c4 JS |
2154 | |
2155 | /// Clean up handlers | |
2156 | static void CleanUpHandlers(); | |
2157 | ||
2158 | /// Initialise the standard handlers | |
2159 | static void InitStandardHandlers(); | |
2160 | ||
d2d0adc7 JS |
2161 | /// Get renderer |
2162 | static wxRichTextRenderer* GetRenderer() { return sm_renderer; } | |
2163 | ||
2164 | /// Set renderer, deleting old one | |
2165 | static void SetRenderer(wxRichTextRenderer* renderer); | |
2166 | ||
2167 | /// Minimum margin between bullet and paragraph in 10ths of a mm | |
2168 | static int GetBulletRightMargin() { return sm_bulletRightMargin; } | |
2169 | static void SetBulletRightMargin(int margin) { sm_bulletRightMargin = margin; } | |
2170 | ||
2171 | /// Factor to multiply by character height to get a reasonable bullet size | |
2172 | static float GetBulletProportion() { return sm_bulletProportion; } | |
2173 | static void SetBulletProportion(float prop) { sm_bulletProportion = prop; } | |
44219ff0 JS |
2174 | |
2175 | /// Scale factor for calculating dimensions | |
2176 | double GetScale() const { return m_scale; } | |
2177 | void SetScale(double scale) { m_scale = scale; } | |
2178 | ||
5d7836c4 JS |
2179 | protected: |
2180 | ||
2181 | /// Command processor | |
2182 | wxCommandProcessor* m_commandProcessor; | |
2183 | ||
44cc96a8 JS |
2184 | /// Table storing fonts |
2185 | wxRichTextFontTable m_fontTable; | |
2186 | ||
5d7836c4 JS |
2187 | /// Has been modified? |
2188 | bool m_modified; | |
2189 | ||
2190 | /// Collapsed command stack | |
2191 | int m_batchedCommandDepth; | |
2192 | ||
2193 | /// Name for collapsed command | |
2194 | wxString m_batchedCommandsName; | |
2195 | ||
2196 | /// Current collapsed command accumulating actions | |
2197 | wxRichTextCommand* m_batchedCommand; | |
2198 | ||
2199 | /// Whether to suppress undo | |
2200 | int m_suppressUndo; | |
2201 | ||
2202 | /// Style sheet, if any | |
2203 | wxRichTextStyleSheet* m_styleSheet; | |
2204 | ||
d2d0adc7 JS |
2205 | /// List of event handlers that will be notified of events |
2206 | wxList m_eventHandlers; | |
2207 | ||
5d7836c4 JS |
2208 | /// Stack of attributes for convenience functions |
2209 | wxList m_attributeStack; | |
2210 | ||
d2d0adc7 JS |
2211 | /// Flags to be passed to handlers |
2212 | int m_handlerFlags; | |
2213 | ||
5d7836c4 JS |
2214 | /// File handlers |
2215 | static wxList sm_handlers; | |
d2d0adc7 JS |
2216 | |
2217 | /// Renderer | |
2218 | static wxRichTextRenderer* sm_renderer; | |
2219 | ||
2220 | /// Minimum margin between bullet and paragraph in 10ths of a mm | |
2221 | static int sm_bulletRightMargin; | |
2222 | ||
2223 | /// Factor to multiply by character height to get a reasonable bullet size | |
2224 | static float sm_bulletProportion; | |
44219ff0 JS |
2225 | |
2226 | /// Scaling factor in use: needed to calculate correct dimensions when printing | |
2227 | double m_scale; | |
5d7836c4 JS |
2228 | }; |
2229 | ||
2230 | /*! | |
2231 | * The command identifiers | |
2232 | * | |
2233 | */ | |
2234 | ||
2235 | enum wxRichTextCommandId | |
2236 | { | |
2237 | wxRICHTEXT_INSERT, | |
2238 | wxRICHTEXT_DELETE, | |
2239 | wxRICHTEXT_CHANGE_STYLE | |
2240 | }; | |
2241 | ||
2242 | /*! | |
2243 | * Command classes for undo/redo | |
2244 | * | |
2245 | */ | |
2246 | ||
b5dbe15d | 2247 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextAction; |
3b2cb431 | 2248 | class WXDLLIMPEXP_RICHTEXT wxRichTextCommand: public wxCommand |
5d7836c4 JS |
2249 | { |
2250 | public: | |
2251 | // Ctor for one action | |
2252 | wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, | |
7fe8059f | 2253 | wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); |
5d7836c4 JS |
2254 | |
2255 | // Ctor for multiple actions | |
2256 | wxRichTextCommand(const wxString& name); | |
2257 | ||
d3c7fc99 | 2258 | virtual ~wxRichTextCommand(); |
5d7836c4 JS |
2259 | |
2260 | bool Do(); | |
2261 | bool Undo(); | |
2262 | ||
2263 | void AddAction(wxRichTextAction* action); | |
2264 | void ClearActions(); | |
2265 | ||
2266 | wxList& GetActions() { return m_actions; } | |
2267 | ||
2268 | protected: | |
2269 | ||
2270 | wxList m_actions; | |
2271 | }; | |
2272 | ||
2273 | /*! | |
2274 | * wxRichTextAction class declaration | |
2275 | * There can be more than one action in a command. | |
2276 | */ | |
2277 | ||
3b2cb431 | 2278 | class WXDLLIMPEXP_RICHTEXT wxRichTextAction: public wxObject |
5d7836c4 JS |
2279 | { |
2280 | public: | |
2281 | wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, | |
7fe8059f | 2282 | wxRichTextCtrl* ctrl, bool ignoreFirstTime = false); |
5d7836c4 | 2283 | |
d3c7fc99 | 2284 | virtual ~wxRichTextAction(); |
5d7836c4 JS |
2285 | |
2286 | bool Do(); | |
2287 | bool Undo(); | |
2288 | ||
2289 | /// Update the control appearance | |
ea160b2e | 2290 | void UpdateAppearance(long caretPosition, bool sendUpdateEvent = false, |
7051fa41 | 2291 | wxArrayInt* optimizationLineCharPositions = NULL, wxArrayInt* optimizationLineYPositions = NULL, bool isDoCmd = true); |
5d7836c4 JS |
2292 | |
2293 | /// Replace the buffer paragraphs with the given fragment. | |
0ca07313 | 2294 | void ApplyParagraphs(const wxRichTextParagraphLayoutBox& fragment); |
5d7836c4 JS |
2295 | |
2296 | /// Get the fragments | |
0ca07313 JS |
2297 | wxRichTextParagraphLayoutBox& GetNewParagraphs() { return m_newParagraphs; } |
2298 | wxRichTextParagraphLayoutBox& GetOldParagraphs() { return m_oldParagraphs; } | |
5d7836c4 | 2299 | |
7051fa41 JS |
2300 | /// Calculate arrays for refresh optimization |
2301 | void CalculateRefreshOptimizations(wxArrayInt& optimizationLineCharPositions, wxArrayInt& optimizationLineYPositions); | |
2302 | ||
5d7836c4 JS |
2303 | /// Set/get the position used for e.g. insertion |
2304 | void SetPosition(long pos) { m_position = pos; } | |
2305 | long GetPosition() const { return m_position; } | |
2306 | ||
2307 | /// Set/get the range for e.g. deletion | |
2308 | void SetRange(const wxRichTextRange& range) { m_range = range; } | |
2309 | const wxRichTextRange& GetRange() const { return m_range; } | |
2310 | ||
2311 | /// Get name | |
2312 | const wxString& GetName() const { return m_name; } | |
2313 | ||
2314 | protected: | |
2315 | // Action name | |
2316 | wxString m_name; | |
2317 | ||
2318 | // Buffer | |
2319 | wxRichTextBuffer* m_buffer; | |
2320 | ||
2321 | // Control | |
2322 | wxRichTextCtrl* m_ctrl; | |
2323 | ||
2324 | // Stores the new paragraphs | |
0ca07313 | 2325 | wxRichTextParagraphLayoutBox m_newParagraphs; |
5d7836c4 JS |
2326 | |
2327 | // Stores the old paragraphs | |
0ca07313 | 2328 | wxRichTextParagraphLayoutBox m_oldParagraphs; |
5d7836c4 JS |
2329 | |
2330 | // The affected range | |
2331 | wxRichTextRange m_range; | |
2332 | ||
2333 | // The insertion point for this command | |
2334 | long m_position; | |
2335 | ||
2336 | // Ignore 1st 'Do' operation because we already did it | |
2337 | bool m_ignoreThis; | |
2338 | ||
2339 | // The command identifier | |
2340 | wxRichTextCommandId m_cmdId; | |
2341 | }; | |
2342 | ||
d2d0adc7 JS |
2343 | /*! |
2344 | * Handler flags | |
2345 | */ | |
2346 | ||
2347 | // Include style sheet when loading and saving | |
2348 | #define wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET 0x0001 | |
2349 | ||
2350 | // Save images to memory file system in HTML handler | |
2351 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY 0x0010 | |
2352 | ||
2353 | // Save images to files in HTML handler | |
2354 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES 0x0020 | |
2355 | ||
2356 | // Save images as inline base64 data in HTML handler | |
2357 | #define wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 0x0040 | |
2358 | ||
b774c698 JS |
2359 | // Don't write header and footer (or BODY), so we can include the fragment |
2360 | // in a larger document | |
2361 | #define wxRICHTEXT_HANDLER_NO_HEADER_FOOTER 0x0080 | |
2362 | ||
a2beab22 JS |
2363 | // Convert the more common face names to names that will work on the current platform |
2364 | // in a larger document | |
2365 | #define wxRICHTEXT_HANDLER_CONVERT_FACENAMES 0x0100 | |
2366 | ||
5d7836c4 JS |
2367 | /*! |
2368 | * wxRichTextFileHandler | |
2369 | * Base class for file handlers | |
2370 | */ | |
2371 | ||
3b2cb431 | 2372 | class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler: public wxObject |
5d7836c4 JS |
2373 | { |
2374 | DECLARE_CLASS(wxRichTextFileHandler) | |
2375 | public: | |
2376 | wxRichTextFileHandler(const wxString& name = wxEmptyString, const wxString& ext = wxEmptyString, int type = 0) | |
d8dd214c | 2377 | : m_name(name), m_extension(ext), m_type(type), m_flags(0), m_visible(true) |
5d7836c4 JS |
2378 | { } |
2379 | ||
2380 | #if wxUSE_STREAMS | |
7fe8059f WS |
2381 | bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) |
2382 | { return DoLoadFile(buffer, stream); } | |
2383 | bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) | |
2384 | { return DoSaveFile(buffer, stream); } | |
5d7836c4 JS |
2385 | #endif |
2386 | ||
a9b9495b | 2387 | #if wxUSE_FFILE && wxUSE_STREAMS |
fe8b0361 JS |
2388 | virtual bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename); |
2389 | virtual bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename); | |
a9b9495b | 2390 | #endif // wxUSE_STREAMS && wxUSE_STREAMS |
5d7836c4 JS |
2391 | |
2392 | /// Can we handle this filename (if using files)? By default, checks the extension. | |
2393 | virtual bool CanHandle(const wxString& filename) const; | |
2394 | ||
2395 | /// Can we save using this handler? | |
2396 | virtual bool CanSave() const { return false; } | |
2397 | ||
2398 | /// Can we load using this handler? | |
2399 | virtual bool CanLoad() const { return false; } | |
2400 | ||
2401 | /// Should this handler be visible to the user? | |
2402 | virtual bool IsVisible() const { return m_visible; } | |
2403 | virtual void SetVisible(bool visible) { m_visible = visible; } | |
2404 | ||
b71e9aa4 | 2405 | /// The name of the nandler |
5d7836c4 JS |
2406 | void SetName(const wxString& name) { m_name = name; } |
2407 | wxString GetName() const { return m_name; } | |
2408 | ||
b71e9aa4 | 2409 | /// The default extension to recognise |
5d7836c4 JS |
2410 | void SetExtension(const wxString& ext) { m_extension = ext; } |
2411 | wxString GetExtension() const { return m_extension; } | |
2412 | ||
b71e9aa4 | 2413 | /// The handler type |
5d7836c4 JS |
2414 | void SetType(int type) { m_type = type; } |
2415 | int GetType() const { return m_type; } | |
2416 | ||
d2d0adc7 JS |
2417 | /// Flags controlling how loading and saving is done |
2418 | void SetFlags(int flags) { m_flags = flags; } | |
2419 | int GetFlags() const { return m_flags; } | |
2420 | ||
b71e9aa4 JS |
2421 | /// Encoding to use when saving a file. If empty, a suitable encoding is chosen |
2422 | void SetEncoding(const wxString& encoding) { m_encoding = encoding; } | |
2423 | const wxString& GetEncoding() const { return m_encoding; } | |
2424 | ||
5d7836c4 JS |
2425 | protected: |
2426 | ||
7fe8059f WS |
2427 | #if wxUSE_STREAMS |
2428 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0; | |
2429 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0; | |
2430 | #endif | |
2431 | ||
5d7836c4 | 2432 | wxString m_name; |
b71e9aa4 | 2433 | wxString m_encoding; |
5d7836c4 JS |
2434 | wxString m_extension; |
2435 | int m_type; | |
d2d0adc7 | 2436 | int m_flags; |
5d7836c4 JS |
2437 | bool m_visible; |
2438 | }; | |
2439 | ||
2440 | /*! | |
2441 | * wxRichTextPlainTextHandler | |
2442 | * Plain text handler | |
2443 | */ | |
2444 | ||
3b2cb431 | 2445 | class WXDLLIMPEXP_RICHTEXT wxRichTextPlainTextHandler: public wxRichTextFileHandler |
5d7836c4 JS |
2446 | { |
2447 | DECLARE_CLASS(wxRichTextPlainTextHandler) | |
2448 | public: | |
d75a69e8 FM |
2449 | wxRichTextPlainTextHandler(const wxString& name = wxT("Text"), |
2450 | const wxString& ext = wxT("txt"), | |
2451 | wxRichTextFileType type = wxRICHTEXT_TYPE_TEXT) | |
5d7836c4 JS |
2452 | : wxRichTextFileHandler(name, ext, type) |
2453 | { } | |
2454 | ||
5d7836c4 JS |
2455 | /// Can we save using this handler? |
2456 | virtual bool CanSave() const { return true; } | |
2457 | ||
2458 | /// Can we load using this handler? | |
2459 | virtual bool CanLoad() const { return true; } | |
2460 | ||
2461 | protected: | |
2462 | ||
7fe8059f WS |
2463 | #if wxUSE_STREAMS |
2464 | virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); | |
2465 | virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); | |
2466 | #endif | |
2467 | ||
5d7836c4 JS |
2468 | }; |
2469 | ||
0ca07313 JS |
2470 | #if wxUSE_DATAOBJ |
2471 | ||
2472 | /*! | |
2473 | * The data object for a wxRichTextBuffer | |
2474 | */ | |
2475 | ||
d2d0adc7 | 2476 | class WXDLLIMPEXP_RICHTEXT wxRichTextBufferDataObject: public wxDataObjectSimple |
0ca07313 JS |
2477 | { |
2478 | public: | |
2479 | // ctor doesn't copy the pointer, so it shouldn't go away while this object | |
2480 | // is alive | |
d3b9f782 | 2481 | wxRichTextBufferDataObject(wxRichTextBuffer* richTextBuffer = NULL); |
0ca07313 JS |
2482 | virtual ~wxRichTextBufferDataObject(); |
2483 | ||
2484 | // after a call to this function, the buffer is owned by the caller and it | |
2485 | // is responsible for deleting it | |
2486 | wxRichTextBuffer* GetRichTextBuffer(); | |
2487 | ||
2488 | // Returns the id for the new data format | |
2489 | static const wxChar* GetRichTextBufferFormatId() { return ms_richTextBufferFormatId; } | |
2490 | ||
2491 | // base class pure virtuals | |
2492 | ||
2493 | virtual wxDataFormat GetPreferredFormat(Direction dir) const; | |
2494 | virtual size_t GetDataSize() const; | |
2495 | virtual bool GetDataHere(void *pBuf) const; | |
2496 | virtual bool SetData(size_t len, const void *buf); | |
2497 | ||
2498 | // prevent warnings | |
2499 | ||
2500 | virtual size_t GetDataSize(const wxDataFormat&) const { return GetDataSize(); } | |
2501 | virtual bool GetDataHere(const wxDataFormat&, void *buf) const { return GetDataHere(buf); } | |
2502 | virtual bool SetData(const wxDataFormat&, size_t len, const void *buf) { return SetData(len, buf); } | |
2503 | ||
2504 | private: | |
2505 | wxDataFormat m_formatRichTextBuffer; // our custom format | |
2506 | wxRichTextBuffer* m_richTextBuffer; // our data | |
2507 | static const wxChar* ms_richTextBufferFormatId; // our format id | |
2508 | }; | |
2509 | ||
2510 | #endif | |
2511 | ||
d2d0adc7 JS |
2512 | /*! |
2513 | * wxRichTextRenderer isolates common drawing functionality | |
2514 | */ | |
2515 | ||
2516 | class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer: public wxObject | |
2517 | { | |
2518 | public: | |
2519 | wxRichTextRenderer() {} | |
2520 | virtual ~wxRichTextRenderer() {} | |
2521 | ||
2522 | /// Draw a standard bullet, as specified by the value of GetBulletName | |
24777478 | 2523 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0; |
d2d0adc7 JS |
2524 | |
2525 | /// Draw a bullet that can be described by text, such as numbered or symbol bullets | |
24777478 | 2526 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text) = 0; |
d2d0adc7 JS |
2527 | |
2528 | /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName | |
24777478 | 2529 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect) = 0; |
d2d0adc7 JS |
2530 | |
2531 | /// Enumerate the standard bullet names currently supported | |
2532 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0; | |
2533 | }; | |
2534 | ||
2535 | /*! | |
2536 | * wxRichTextStdRenderer: standard renderer | |
2537 | */ | |
2538 | ||
2539 | class WXDLLIMPEXP_RICHTEXT wxRichTextStdRenderer: public wxRichTextRenderer | |
2540 | { | |
2541 | public: | |
2542 | wxRichTextStdRenderer() {} | |
2543 | ||
2544 | /// Draw a standard bullet, as specified by the value of GetBulletName | |
24777478 | 2545 | virtual bool DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect); |
d2d0adc7 JS |
2546 | |
2547 | /// Draw a bullet that can be described by text, such as numbered or symbol bullets | |
24777478 | 2548 | virtual bool DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text); |
d2d0adc7 JS |
2549 | |
2550 | /// Draw a bitmap bullet, where the bullet bitmap is specified by the value of GetBulletName | |
24777478 | 2551 | virtual bool DrawBitmapBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect); |
d2d0adc7 JS |
2552 | |
2553 | /// Enumerate the standard bullet names currently supported | |
2554 | virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames); | |
2555 | }; | |
2556 | ||
5d7836c4 JS |
2557 | /*! |
2558 | * Utilities | |
2559 | * | |
2560 | */ | |
2561 | ||
2562 | inline bool wxRichTextHasStyle(int flags, int style) | |
2563 | { | |
2564 | return ((flags & style) == style); | |
2565 | } | |
2566 | ||
2567 | /// Compare two attribute objects | |
24777478 JS |
2568 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); |
2569 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEq(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); | |
5d7836c4 JS |
2570 | |
2571 | /// Compare two attribute objects, but take into account the flags | |
2572 | /// specifying attributes of interest. | |
24777478 | 2573 | WXDLLIMPEXP_RICHTEXT bool wxTextAttrEqPartial(const wxRichTextAttr& attr1, const wxRichTextAttr& attr2); |
5d7836c4 JS |
2574 | |
2575 | /// Apply one style to another | |
24777478 | 2576 | WXDLLIMPEXP_RICHTEXT bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith = NULL); |
59509217 | 2577 | |
aeb6ebe2 | 2578 | // Remove attributes |
24777478 | 2579 | WXDLLIMPEXP_RICHTEXT bool wxRichTextRemoveStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style); |
aeb6ebe2 | 2580 | |
42688aea JS |
2581 | /// Combine two bitlists |
2582 | WXDLLIMPEXP_RICHTEXT bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB); | |
2583 | ||
2584 | /// Compare two bitlists | |
2585 | WXDLLIMPEXP_RICHTEXT bool wxRichTextBitlistsEqPartial(int valueA, int valueB, int flags); | |
2586 | ||
4f32b3cf | 2587 | /// Split into paragraph and character styles |
24777478 | 2588 | WXDLLIMPEXP_RICHTEXT bool wxRichTextSplitParaCharStyles(const wxRichTextAttr& style, wxRichTextAttr& parStyle, wxRichTextAttr& charStyle); |
4f32b3cf | 2589 | |
59509217 | 2590 | /// Compare tabs |
d2d0adc7 | 2591 | WXDLLIMPEXP_RICHTEXT bool wxRichTextTabsEq(const wxArrayInt& tabs1, const wxArrayInt& tabs2); |
59509217 | 2592 | |
59509217 | 2593 | /// Convert a decimal to Roman numerals |
d2d0adc7 | 2594 | WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n); |
f1d6804f | 2595 | |
24777478 JS |
2596 | // Collects the attributes that are common to a range of content, building up a note of |
2597 | // which attributes are absent in some objects and which clash in some objects. | |
2598 | WXDLLIMPEXP_RICHTEXT void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAttr& attr, wxTextAttr& clashingAttr, wxTextAttr& absentAttr); | |
2599 | ||
f1d6804f RD |
2600 | WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit(); |
2601 | ||
5d7836c4 JS |
2602 | #endif |
2603 | // wxUSE_RICHTEXT | |
2604 | ||
2605 | #endif | |
2606 | // _WX_RICHTEXTBUFFER_H_ | |
d2d0adc7 | 2607 |