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