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