]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextctrl.h
20072812450b392a8eaccd62c1d9a7d08bb316bb
[wxWidgets.git] / include / wx / richtext / richtextctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextctrl.h
3 // Purpose: A rich edit control
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2005-09-30
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_RICHTEXTCTRL_H_
13 #define _WX_RICHTEXTCTRL_H_
14
15 #include "wx/richtext/richtextbuffer.h"
16
17 #if wxUSE_RICHTEXT
18
19 #include "wx/scrolwin.h"
20 #include "wx/caret.h"
21
22 #include "wx/textctrl.h"
23
24 #if wxUSE_DRAG_AND_DROP
25 #include "wx/dnd.h"
26 #endif
27
28 #if !defined(__WXGTK__) && !defined(__WXMAC__)
29 #define wxRICHTEXT_BUFFERED_PAINTING 1
30 #else
31 #define wxRICHTEXT_BUFFERED_PAINTING 0
32 #endif
33
34 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition;
35
36 /*
37 * Styles and flags
38 */
39
40 /**
41 Styles
42 */
43
44 #define wxRE_READONLY 0x0010
45 #define wxRE_MULTILINE 0x0020
46 #define wxRE_CENTRE_CARET 0x8000
47 #define wxRE_CENTER_CARET wxRE_CENTRE_CARET
48
49 /**
50 Flags
51 */
52
53 #define wxRICHTEXT_SHIFT_DOWN 0x01
54 #define wxRICHTEXT_CTRL_DOWN 0x02
55 #define wxRICHTEXT_ALT_DOWN 0x04
56
57 /**
58 Extra flags
59 */
60
61 // Don't draw guide lines around boxes and tables
62 #define wxRICHTEXT_EX_NO_GUIDELINES 0x00000100
63
64
65 /*
66 Defaults
67 */
68
69 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
70 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
71 #define wxRICHTEXT_DEFAULT_SPACING 3
72 #define wxRICHTEXT_DEFAULT_MARGIN 3
73 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
74 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
75 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
76 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
77 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
78 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
79 // Minimum buffer size before delayed layout kicks in
80 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
81 // Milliseconds before layout occurs after resize
82 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
83
84 /* Identifiers
85 */
86 #define wxID_RICHTEXT_PROPERTIES1 (wxID_HIGHEST + 1)
87 #define wxID_RICHTEXT_PROPERTIES2 (wxID_HIGHEST + 2)
88 #define wxID_RICHTEXT_PROPERTIES3 (wxID_HIGHEST + 3)
89
90 /*
91 Normal selection occurs initially and as user drags within one container.
92 Common ancestor selection occurs when the user starts dragging across containers
93 that have a common ancestor, for example the cells in a table.
94 */
95
96 enum wxRichTextCtrlSelectionState
97 {
98 wxRichTextCtrlSelectionState_Normal,
99 wxRichTextCtrlSelectionState_CommonAncestor
100 };
101
102 /**
103 @class wxRichTextContextMenuPropertiesInfo
104
105 wxRichTextContextMenuPropertiesInfo keeps track of objects that appear in the context menu,
106 whose properties are available to be edited.
107 */
108
109 class WXDLLIMPEXP_RICHTEXT wxRichTextContextMenuPropertiesInfo
110 {
111 public:
112 /**
113 Constructor.
114 */
115 wxRichTextContextMenuPropertiesInfo() { Init(); }
116
117 // Operations
118
119 /**
120 Initialisation.
121 */
122 void Init() {}
123
124 /**
125 Adds an item.
126 */
127 bool AddItem(const wxString& label, wxRichTextObject* obj);
128
129 /**
130 Returns the number of menu items that were added.
131 */
132 int AddMenuItems(wxMenu* menu, int startCmd = wxID_RICHTEXT_PROPERTIES1) const;
133
134 /**
135 Adds appropriate menu items for the current container and clicked on object
136 (and container's parent, if appropriate).
137 */
138 int AddItems(wxRichTextCtrl* ctrl, wxRichTextObject* container, wxRichTextObject* obj);
139
140 /**
141 Clears the items.
142 */
143 void Clear() { m_objects.Clear(); m_labels.Clear(); }
144
145 // Accessors
146
147 /**
148 Returns the nth label.
149 */
150 wxString GetLabel(int n) const { return m_labels[n]; }
151
152 /**
153 Returns the nth object.
154 */
155 wxRichTextObject* GetObject(int n) const { return m_objects[n]; }
156
157 /**
158 Returns the array of objects.
159 */
160 wxRichTextObjectPtrArray& GetObjects() { return m_objects; }
161
162 /**
163 Returns the array of objects.
164 */
165 const wxRichTextObjectPtrArray& GetObjects() const { return m_objects; }
166
167 /**
168 Returns the array of labels.
169 */
170 wxArrayString& GetLabels() { return m_labels; }
171
172 /**
173 Returns the array of labels.
174 */
175 const wxArrayString& GetLabels() const { return m_labels; }
176
177 /**
178 Returns the number of items.
179 */
180 int GetCount() const { return m_objects.GetCount(); }
181
182 wxRichTextObjectPtrArray m_objects;
183 wxArrayString m_labels;
184 };
185
186 /**
187 @class wxRichTextCtrl
188
189 wxRichTextCtrl provides a generic, ground-up implementation of a text control
190 capable of showing multiple styles and images.
191
192 wxRichTextCtrl sends notification events: see wxRichTextEvent.
193
194 It also sends the standard wxTextCtrl events @c wxEVT_COMMAND_TEXT_ENTER and
195 @c wxEVT_COMMAND_TEXT_UPDATED, and wxTextUrlEvent when URL content is clicked.
196
197 For more information, see the @ref overview_richtextctrl.
198
199 @beginStyleTable
200 @style{wxRE_CENTRE_CARET}
201 The control will try to keep the caret line centred vertically while editing.
202 wxRE_CENTER_CARET is a synonym for this style.
203 @style{wxRE_MULTILINE}
204 The control will be multiline (mandatory).
205 @style{wxRE_READONLY}
206 The control will not be editable.
207 @endStyleTable
208
209 @library{wxrichtext}
210 @category{richtext}
211 @appearance{richtextctrl.png}
212
213 */
214
215 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxControl,
216 public wxTextCtrlIface,
217 public wxScrollHelper
218 {
219 DECLARE_DYNAMIC_CLASS( wxRichTextCtrl )
220 DECLARE_EVENT_TABLE()
221
222 public:
223 // Constructors
224
225 /**
226 Default constructor.
227 */
228 wxRichTextCtrl( );
229
230 /**
231 Constructor, creating and showing a rich text control.
232
233 @param parent
234 Parent window. Must not be @NULL.
235 @param id
236 Window identifier. The value @c wxID_ANY indicates a default value.
237 @param value
238 Default string.
239 @param pos
240 Window position.
241 @param size
242 Window size.
243 @param style
244 Window style.
245 @param validator
246 Window validator.
247 @param name
248 Window name.
249
250 @see Create(), wxValidator
251 */
252 wxRichTextCtrl( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
253 long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
254
255 /**
256 Destructor.
257 */
258 virtual ~wxRichTextCtrl( );
259
260 // Operations
261
262 /**
263 Creates the underlying window.
264 */
265 bool Create( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
266 long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr );
267
268 /**
269 Initialises the members of the control.
270 */
271 void Init();
272
273 // Accessors
274
275 /**
276 Gets the text for the given range.
277 The end point of range is specified as the last character position of
278 the span of text, plus one.
279 */
280 virtual wxString GetRange(long from, long to) const;
281
282 /**
283 Returns the length of the specified line in characters.
284 */
285 virtual int GetLineLength(long lineNo) const ;
286
287 /**
288 Returns the text for the given line.
289 */
290 virtual wxString GetLineText(long lineNo) const ;
291
292 /**
293 Returns the number of lines in the buffer.
294 */
295 virtual int GetNumberOfLines() const ;
296
297 /**
298 Returns @true if the buffer has been modified.
299 */
300 virtual bool IsModified() const ;
301
302 /**
303 Returns @true if the control is editable.
304 */
305 virtual bool IsEditable() const ;
306
307 /**
308 Returns @true if the control is single-line.
309 Currently wxRichTextCtrl does not support single-line editing.
310 */
311 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE); }
312
313 /**
314 Returns @true if the control is multiline.
315 */
316 bool IsMultiLine() const { return !IsSingleLine(); }
317
318 //@{
319 /**
320 Returns the range of the current selection.
321 The end point of range is specified as the last character position of the span
322 of text, plus one.
323 If the return values @a from and @a to are the same, there is no selection.
324 */
325 virtual void GetSelection(long* from, long* to) const;
326 const wxRichTextSelection& GetSelection() const { return m_selection; }
327 wxRichTextSelection& GetSelection() { return m_selection; }
328 //@}
329
330 /**
331 Returns the text within the current selection range, if any.
332 */
333 virtual wxString GetStringSelection() const;
334
335 /**
336 Gets the current filename associated with the control.
337 */
338 wxString GetFilename() const { return m_filename; }
339
340 /**
341 Sets the current filename.
342 */
343 void SetFilename(const wxString& filename) { m_filename = filename; }
344
345 /**
346 Sets the size of the buffer beyond which layout is delayed during resizing.
347 This optimizes sizing for large buffers. The default is 20000.
348 */
349 void SetDelayedLayoutThreshold(long threshold) { m_delayedLayoutThreshold = threshold; }
350
351 /**
352 Gets the size of the buffer beyond which layout is delayed during resizing.
353 This optimizes sizing for large buffers. The default is 20000.
354 */
355 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold; }
356
357 /**
358 Gets the flag indicating that full layout is required.
359 */
360 bool GetFullLayoutRequired() const { return m_fullLayoutRequired; }
361
362 /**
363 Sets the flag indicating that full layout is required.
364 */
365 void SetFullLayoutRequired(bool b) { m_fullLayoutRequired = b; }
366
367 /**
368 Returns the last time full layout was performed.
369 */
370 wxLongLong GetFullLayoutTime() const { return m_fullLayoutTime; }
371
372 /**
373 Sets the last time full layout was performed.
374 */
375 void SetFullLayoutTime(wxLongLong t) { m_fullLayoutTime = t; }
376
377 /**
378 Returns the position that should be shown when full (delayed) layout is performed.
379 */
380 long GetFullLayoutSavedPosition() const { return m_fullLayoutSavedPosition; }
381
382 /**
383 Sets the position that should be shown when full (delayed) layout is performed.
384 */
385 void SetFullLayoutSavedPosition(long p) { m_fullLayoutSavedPosition = p; }
386
387 /**
388 Forces any pending layout due to delayed, partial layout when the control
389 was resized.
390 */
391 void ForceDelayedLayout();
392
393 /**
394 Sets the text (normal) cursor.
395 */
396 void SetTextCursor(const wxCursor& cursor ) { m_textCursor = cursor; }
397
398 /**
399 Returns the text (normal) cursor.
400 */
401 wxCursor GetTextCursor() const { return m_textCursor; }
402
403 /**
404 Sets the cursor to be used over URLs.
405 */
406 void SetURLCursor(const wxCursor& cursor ) { m_urlCursor = cursor; }
407
408 /**
409 Returns the cursor to be used over URLs.
410 */
411 wxCursor GetURLCursor() const { return m_urlCursor; }
412
413 /**
414 Returns @true if we are showing the caret position at the start of a line
415 instead of at the end of the previous one.
416 */
417 bool GetCaretAtLineStart() const { return m_caretAtLineStart; }
418
419 /**
420 Sets a flag to remember that we are showing the caret position at the start of a line
421 instead of at the end of the previous one.
422 */
423 void SetCaretAtLineStart(bool atStart) { m_caretAtLineStart = atStart; }
424
425 /**
426 Returns @true if we are dragging a selection.
427 */
428 bool GetDragging() const { return m_dragging; }
429
430 /**
431 Sets a flag to remember if we are dragging a selection.
432 */
433 void SetDragging(bool dragging) { m_dragging = dragging; }
434
435 #if wxUSE_DRAG_AND_DROP
436 /**
437 Are we trying to start Drag'n'Drop?
438 */
439 bool GetPreDrag() const { return m_preDrag; }
440
441 /**
442 Set if we're trying to start Drag'n'Drop
443 */
444 void SetPreDrag(bool pd) { m_preDrag = pd; }
445
446 /**
447 Get the possible Drag'n'Drop start point
448 */
449 const wxPoint GetDragStartPoint() const { return m_dragStartPoint; }
450
451 /**
452 Set the possible Drag'n'Drop start point
453 */
454 void SetDragStartPoint(wxPoint sp) { m_dragStartPoint = sp; }
455
456 #if wxUSE_DATETIME
457 /**
458 Get the possible Drag'n'Drop start time
459 */
460 const wxDateTime GetDragStartTime() const { return m_dragStartTime; }
461
462 /**
463 Set the possible Drag'n'Drop start time
464 */
465 void SetDragStartTime(wxDateTime st) { m_dragStartTime = st; }
466 #endif // wxUSE_DATETIME
467
468 #endif // wxUSE_DRAG_AND_DROP
469
470 #if wxRICHTEXT_BUFFERED_PAINTING
471 //@{
472 /**
473 Returns the buffer bitmap if using buffered painting.
474 */
475 const wxBitmap& GetBufferBitmap() const { return m_bufferBitmap; }
476 wxBitmap& GetBufferBitmap() { return m_bufferBitmap; }
477 //@}
478 #endif
479
480 /**
481 Returns the current context menu.
482 */
483 wxMenu* GetContextMenu() const { return m_contextMenu; }
484
485 /**
486 Sets the current context menu.
487 */
488 void SetContextMenu(wxMenu* menu);
489
490 /**
491 Returns an anchor so we know how to extend the selection.
492 It's a caret position since it's between two characters.
493 */
494 long GetSelectionAnchor() const { return m_selectionAnchor; }
495
496 /**
497 Sets an anchor so we know how to extend the selection.
498 It's a caret position since it's between two characters.
499 */
500 void SetSelectionAnchor(long anchor) { m_selectionAnchor = anchor; }
501
502 /**
503 Returns the anchor object if selecting multiple containers.
504 */
505 wxRichTextObject* GetSelectionAnchorObject() const { return m_selectionAnchorObject; }
506
507 /**
508 Sets the anchor object if selecting multiple containers.
509 */
510 void SetSelectionAnchorObject(wxRichTextObject* anchor) { m_selectionAnchorObject = anchor; }
511
512 //@{
513 /**
514 Returns an object that stores information about context menu property item(s),
515 in order to communicate between the context menu event handler and the code
516 that responds to it. The wxRichTextContextMenuPropertiesInfo stores one
517 item for each object that could respond to a property-editing event. If
518 objects are nested, several might be editable.
519 */
520 wxRichTextContextMenuPropertiesInfo& GetContextMenuPropertiesInfo() { return m_contextMenuPropertiesInfo; }
521 const wxRichTextContextMenuPropertiesInfo& GetContextMenuPropertiesInfo() const { return m_contextMenuPropertiesInfo; }
522 //@}
523
524 /**
525 Returns the wxRichTextObject object that currently has the editing focus.
526 If there are no composite objects, this will be the top-level buffer.
527 */
528 wxRichTextParagraphLayoutBox* GetFocusObject() const { return m_focusObject; }
529
530 /**
531 Sets m_focusObject without making any alterations.
532 */
533 void StoreFocusObject(wxRichTextParagraphLayoutBox* obj) { m_focusObject = obj; }
534
535 /**
536 Sets the wxRichTextObject object that currently has the editing focus.
537 */
538 bool SetFocusObject(wxRichTextParagraphLayoutBox* obj, bool setCaretPosition = true);
539
540 // Operations
541
542 /**
543 Invalidates the whole buffer to trigger painting later.
544 */
545 void Invalidate() { GetBuffer().Invalidate(wxRICHTEXT_ALL); }
546
547 /**
548 Clears the buffer content, leaving a single empty paragraph. Cannot be undone.
549 */
550 virtual void Clear();
551
552 /**
553 Replaces the content in the specified range with the string specified by
554 @a value.
555 */
556 virtual void Replace(long from, long to, const wxString& value);
557
558 /**
559 Removes the content in the specified range.
560 */
561 virtual void Remove(long from, long to);
562
563 #ifdef DOXYGEN
564 /**
565 Loads content into the control's buffer using the given type.
566
567 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
568 the filename extension.
569
570 This function looks for a suitable wxRichTextFileHandler object.
571 */
572 bool LoadFile(const wxString& file,
573 int type = wxRICHTEXT_TYPE_ANY);
574 #endif
575
576 /**
577 Helper function for LoadFile(). Loads content into the control's buffer using the given type.
578
579 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
580 the filename extension.
581
582 This function looks for a suitable wxRichTextFileHandler object.
583 */
584 virtual bool DoLoadFile(const wxString& file, int fileType);
585
586 #ifdef DOXYGEN
587 /**
588 Saves the buffer content using the given type.
589
590 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
591 the filename extension.
592
593 This function looks for a suitable wxRichTextFileHandler object.
594 */
595 bool SaveFile(const wxString& file = wxEmptyString,
596 int type = wxRICHTEXT_TYPE_ANY);
597 #endif
598
599 /**
600 Helper function for SaveFile(). Saves the buffer content using the given type.
601
602 If the specified type is wxRICHTEXT_TYPE_ANY, the type is deduced from
603 the filename extension.
604
605 This function looks for a suitable wxRichTextFileHandler object.
606 */
607 virtual bool DoSaveFile(const wxString& file = wxEmptyString,
608 int fileType = wxRICHTEXT_TYPE_ANY);
609
610 /**
611 Sets flags that change the behaviour of loading or saving.
612
613 See the documentation for each handler class to see what flags are
614 relevant for each handler.
615 */
616 void SetHandlerFlags(int flags) { GetBuffer().SetHandlerFlags(flags); }
617
618 /**
619 Returns flags that change the behaviour of loading or saving.
620 See the documentation for each handler class to see what flags are
621 relevant for each handler.
622 */
623 int GetHandlerFlags() const { return GetBuffer().GetHandlerFlags(); }
624
625 /**
626 Marks the buffer as modified.
627 */
628 virtual void MarkDirty();
629
630 /**
631 Sets the buffer's modified status to @false, and clears the buffer's command
632 history.
633 */
634 virtual void DiscardEdits();
635
636 /**
637 Sets the maximum number of characters that may be entered in a single line
638 text control. For compatibility only; currently does nothing.
639 */
640 virtual void SetMaxLength(unsigned long WXUNUSED(len)) { }
641
642 /**
643 Writes text at the current position.
644 */
645 virtual void WriteText(const wxString& text);
646
647 /**
648 Sets the insertion point to the end of the buffer and writes the text.
649 */
650 virtual void AppendText(const wxString& text);
651
652 //@{
653 /**
654 Gets the attributes at the given position.
655 This function gets the combined style - that is, the style you see on the
656 screen as a result of combining base style, paragraph style and character
657 style attributes.
658
659 To get the character or paragraph style alone, use GetUncombinedStyle().
660
661 @beginWxPerlOnly
662 In wxPerl this method is implemented as GetStyle(@a position)
663 returning a 2-element list (ok, attr).
664 @endWxPerlOnly
665 */
666 virtual bool GetStyle(long position, wxTextAttr& style);
667 virtual bool GetStyle(long position, wxRichTextAttr& style);
668 virtual bool GetStyle(long position, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container);
669 //@}
670
671 //@{
672 /**
673 Sets the attributes for the given range.
674 The end point of range is specified as the last character position of the span
675 of text, plus one.
676
677 So, for example, to set the style for a character at position 5, use the range
678 (5,6).
679 */
680 virtual bool SetStyle(long start, long end, const wxTextAttr& style);
681 virtual bool SetStyle(long start, long end, const wxRichTextAttr& style);
682 virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttr& style);
683 virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style);
684 //@}
685
686 /**
687 Sets the attributes for a single object
688 */
689 virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr);
690
691 //@{
692 /**
693 Gets the attributes common to the specified range.
694 Attributes that differ in value within the range will not be included
695 in @a style flags.
696
697 @beginWxPerlOnly
698 In wxPerl this method is implemented as GetStyleForRange(@a position)
699 returning a 2-element list (ok, attr).
700 @endWxPerlOnly
701 */
702 virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttr& style);
703 virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style);
704 virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container);
705 //@}
706
707 /**
708 Sets the attributes for the given range, passing flags to determine how the
709 attributes are set.
710
711 The end point of range is specified as the last character position of the span
712 of text, plus one. So, for example, to set the style for a character at
713 position 5, use the range (5,6).
714
715 @a flags may contain a bit list of the following values:
716 - wxRICHTEXT_SETSTYLE_NONE: no style flag.
717 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
718 undoable.
719 - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
720 if the combined style at this point is already the style in question.
721 - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
722 applied to paragraphs, and not the content.
723 This allows content styling to be preserved independently from that
724 of e.g. a named paragraph style.
725 - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
726 applied to characters, and not the paragraph.
727 This allows content styling to be preserved independently from that
728 of e.g. a named paragraph style.
729 - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
730 the new style.
731 - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style. Only the style flags
732 are used in this operation.
733 */
734 virtual bool SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
735
736 //@{
737 /**
738 Gets the attributes at the given position.
739 This function gets the @e uncombined style - that is, the attributes associated
740 with the paragraph or character content, and not necessarily the combined
741 attributes you see on the screen.
742 To get the combined attributes, use GetStyle().
743
744 If you specify (any) paragraph attribute in @e style's flags, this function
745 will fetch the paragraph attributes.
746 Otherwise, it will return the character attributes.
747
748 @beginWxPerlOnly
749 In wxPerl this method is implemented as GetUncombinedStyle(@a position)
750 returning a 2-element list (ok, attr).
751 @endWxPerlOnly
752 */
753 virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
754 virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container);
755 //@}
756
757 //@{
758 /**
759 Sets the current default style, which can be used to change how subsequently
760 inserted text is displayed.
761 */
762 virtual bool SetDefaultStyle(const wxTextAttr& style);
763 virtual bool SetDefaultStyle(const wxRichTextAttr& style);
764 //@}
765
766 /**
767 Returns the current default style, which can be used to change how subsequently
768 inserted text is displayed.
769 */
770 virtual const wxRichTextAttr& GetDefaultStyleEx() const;
771
772 //virtual const wxTextAttr& GetDefaultStyle() const;
773
774 //@{
775 /**
776 Sets the list attributes for the given range, passing flags to determine how
777 the attributes are set.
778
779 Either the style definition or the name of the style definition (in the current
780 sheet) can be passed.
781 @a flags is a bit list of the following:
782 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
783 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
784 @a startFrom, otherwise existing attributes are used.
785 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
786 as the level for all paragraphs, otherwise the current indentation will be used.
787
788 @see NumberList(), PromoteList(), ClearListStyle().
789 */
790 virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
791 virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
792 //@}
793
794 /**
795 Clears the list style from the given range, clearing list-related attributes
796 and applying any named paragraph style associated with each paragraph.
797
798 @a flags is a bit list of the following:
799 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
800
801 @see SetListStyle(), PromoteList(), NumberList().
802 */
803 virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
804
805 //@{
806 /**
807 Numbers the paragraphs in the given range.
808 Pass flags to determine how the attributes are set.
809
810 Either the style definition or the name of the style definition (in the current
811 sheet) can be passed.
812
813 @a flags is a bit list of the following:
814 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
815 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
816 @a startFrom, otherwise existing attributes are used.
817 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
818 as the level for all paragraphs, otherwise the current indentation will be used.
819
820 @see SetListStyle(), PromoteList(), ClearListStyle().
821 */
822 virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
823 virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
824 //@}
825
826 //@{
827 /**
828 Promotes or demotes the paragraphs in the given range.
829 A positive @a promoteBy produces a smaller indent, and a negative number
830 produces a larger indent. Pass flags to determine how the attributes are set.
831 Either the style definition or the name of the style definition (in the current
832 sheet) can be passed.
833
834 @a flags is a bit list of the following:
835 - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
836 - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
837 @a startFrom, otherwise existing attributes are used.
838 - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
839 as the level for all paragraphs, otherwise the current indentation will be used.
840
841 @see SetListStyle(), @see SetListStyle(), ClearListStyle().
842 */
843 virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
844 virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
845 //@}
846
847 /**
848 Sets the properties for the given range, passing flags to determine how the
849 attributes are set. You can merge properties or replace them.
850
851 The end point of range is specified as the last character position of the span
852 of text, plus one. So, for example, to set the properties for a character at
853 position 5, use the range (5,6).
854
855 @a flags may contain a bit list of the following values:
856 - wxRICHTEXT_SETSPROPERTIES_NONE: no flag.
857 - wxRICHTEXT_SETPROPERTIES_WITH_UNDO: specifies that this operation should be
858 undoable.
859 - wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY: specifies that the properties should only be
860 applied to paragraphs, and not the content.
861 - wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY: specifies that the properties should only be
862 applied to characters, and not the paragraph.
863 - wxRICHTEXT_SETPROPERTIES_RESET: resets (clears) the existing properties before applying
864 the new properties.
865 - wxRICHTEXT_SETPROPERTIES_REMOVE: removes the specified properties.
866 */
867 virtual bool SetProperties(const wxRichTextRange& range, const wxRichTextProperties& properties, int flags = wxRICHTEXT_SETPROPERTIES_WITH_UNDO);
868
869 /**
870 Deletes the content within the given range.
871 */
872 virtual bool Delete(const wxRichTextRange& range);
873
874 /**
875 Translates from column and line number to position.
876 */
877 virtual long XYToPosition(long x, long y) const;
878
879 /**
880 Converts a text position to zero-based column and line numbers.
881 */
882 virtual bool PositionToXY(long pos, long *x, long *y) const;
883
884 /**
885 Scrolls the buffer so that the given position is in view.
886 */
887 virtual void ShowPosition(long pos);
888
889 //@{
890 /**
891 Finds the character at the given position in pixels.
892 @a pt is in device coords (not adjusted for the client area origin nor for
893 scrolling).
894 */
895 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const;
896 virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt,
897 wxTextCoord *col,
898 wxTextCoord *row) const;
899
900 /**
901 Finds the container at the given point, which is in screen coordinates.
902 */
903 wxRichTextParagraphLayoutBox* FindContainerAtPoint(const wxPoint pt, long& position, int& hit, wxRichTextObject* hitObj, int flags = 0);
904 //@}
905
906 #if wxUSE_DRAG_AND_DROP
907 /**
908 Does the 'drop' of Drag'n'Drop.
909 */
910 void OnDrop(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxDragResult def, wxDataObject* DataObj);
911 #endif
912
913 // Clipboard operations
914
915 /**
916 Copies the selected content (if any) to the clipboard.
917 */
918 virtual void Copy();
919
920 /**
921 Copies the selected content (if any) to the clipboard and deletes the selection.
922 This is undoable.
923 */
924 virtual void Cut();
925
926 /**
927 Pastes content from the clipboard to the buffer.
928 */
929 virtual void Paste();
930
931 /**
932 Deletes the content in the selection, if any. This is undoable.
933 */
934 virtual void DeleteSelection();
935
936 /**
937 Returns @true if selected content can be copied to the clipboard.
938 */
939 virtual bool CanCopy() const;
940
941 /**
942 Returns @true if selected content can be copied to the clipboard and deleted.
943 */
944 virtual bool CanCut() const;
945
946 /**
947 Returns @true if the clipboard content can be pasted to the buffer.
948 */
949 virtual bool CanPaste() const;
950
951 /**
952 Returns @true if selected content can be deleted.
953 */
954 virtual bool CanDeleteSelection() const;
955
956 /**
957 Undoes the command at the top of the command history, if there is one.
958 */
959 virtual void Undo();
960
961 /**
962 Redoes the current command.
963 */
964 virtual void Redo();
965
966 /**
967 Returns @true if there is a command in the command history that can be undone.
968 */
969 virtual bool CanUndo() const;
970
971 /**
972 Returns @true if there is a command in the command history that can be redone.
973 */
974 virtual bool CanRedo() const;
975
976 /**
977 Sets the insertion point and causes the current editing style to be taken from
978 the new position (unlike wxRichTextCtrl::SetCaretPosition).
979 */
980 virtual void SetInsertionPoint(long pos);
981
982 /**
983 Sets the insertion point to the end of the text control.
984 */
985 virtual void SetInsertionPointEnd();
986
987 /**
988 Returns the current insertion point.
989 */
990 virtual long GetInsertionPoint() const;
991
992 /**
993 Returns the last position in the buffer.
994 */
995 virtual wxTextPos GetLastPosition() const;
996
997 //@{
998 /**
999 Sets the selection to the given range.
1000 The end point of range is specified as the last character position of the span
1001 of text, plus one.
1002
1003 So, for example, to set the selection for a character at position 5, use the
1004 range (5,6).
1005 */
1006 virtual void SetSelection(long from, long to);
1007 void SetSelection(const wxRichTextSelection& sel) { m_selection = sel; }
1008 //@}
1009
1010
1011 /**
1012 Selects all the text in the buffer.
1013 */
1014 virtual void SelectAll();
1015
1016 /**
1017 Makes the control editable, or not.
1018 */
1019 virtual void SetEditable(bool editable);
1020
1021 /**
1022 Returns @true if there is a selection and the object containing the selection
1023 was the same as the current focus object.
1024 */
1025 virtual bool HasSelection() const;
1026
1027 /**
1028 Returns @true if there was a selection, whether or not the current focus object
1029 is the same as the selection's container object.
1030 */
1031 virtual bool HasUnfocusedSelection() const;
1032
1033 //@{
1034 /**
1035 Write a bitmap or image at the current insertion point.
1036 Supply an optional type to use for internal and file storage of the raw data.
1037 */
1038 virtual bool WriteImage(const wxImage& image, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG,
1039 const wxRichTextAttr& textAttr = wxRichTextAttr());
1040
1041 virtual bool WriteImage(const wxBitmap& bitmap, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG,
1042 const wxRichTextAttr& textAttr = wxRichTextAttr());
1043 //@}
1044
1045 /**
1046 Loads an image from a file and writes it at the current insertion point.
1047 */
1048 virtual bool WriteImage(const wxString& filename, wxBitmapType bitmapType,
1049 const wxRichTextAttr& textAttr = wxRichTextAttr());
1050
1051 /**
1052 Writes an image block at the current insertion point.
1053 */
1054 virtual bool WriteImage(const wxRichTextImageBlock& imageBlock,
1055 const wxRichTextAttr& textAttr = wxRichTextAttr());
1056
1057 /**
1058 Write a text box at the current insertion point, returning the text box.
1059 You can then call SetFocusObject() to set the focus to the new object.
1060 */
1061 virtual wxRichTextBox* WriteTextBox(const wxRichTextAttr& textAttr = wxRichTextAttr());
1062
1063 /**
1064 Write a table at the current insertion point, returning the table.
1065 You can then call SetFocusObject() to set the focus to the new object.
1066 */
1067 virtual wxRichTextTable* WriteTable(int rows, int cols, const wxRichTextAttr& tableAttr = wxRichTextAttr(), const wxRichTextAttr& cellAttr = wxRichTextAttr());
1068
1069 /**
1070 Inserts a new paragraph at the current insertion point. @see LineBreak().
1071 */
1072 virtual bool Newline();
1073
1074 /**
1075 Inserts a line break at the current insertion point.
1076
1077 A line break forces wrapping within a paragraph, and can be introduced by
1078 using this function, by appending the wxChar value @b wxRichTextLineBreakChar
1079 to text content, or by typing Shift-Return.
1080 */
1081 virtual bool LineBreak();
1082
1083 /**
1084 Sets the basic (overall) style.
1085
1086 This is the style of the whole buffer before further styles are applied,
1087 unlike the default style, which only affects the style currently being
1088 applied (for example, setting the default style to bold will cause
1089 subsequently inserted text to be bold).
1090 */
1091 virtual void SetBasicStyle(const wxRichTextAttr& style) { GetBuffer().SetBasicStyle(style); }
1092
1093 /**
1094 Gets the basic (overall) style.
1095
1096 This is the style of the whole buffer before further styles are applied,
1097 unlike the default style, which only affects the style currently being
1098 applied (for example, setting the default style to bold will cause
1099 subsequently inserted text to be bold).
1100 */
1101 virtual const wxRichTextAttr& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
1102
1103 /**
1104 Begins applying a style.
1105 */
1106 virtual bool BeginStyle(const wxRichTextAttr& style) { return GetBuffer().BeginStyle(style); }
1107
1108 /**
1109 Ends the current style.
1110 */
1111 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
1112
1113 /**
1114 Ends application of all styles in the current style stack.
1115 */
1116 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
1117
1118 /**
1119 Begins using bold.
1120 */
1121 bool BeginBold() { return GetBuffer().BeginBold(); }
1122
1123 /**
1124 Ends using bold.
1125 */
1126 bool EndBold() { return GetBuffer().EndBold(); }
1127
1128 /**
1129 Begins using italic.
1130 */
1131 bool BeginItalic() { return GetBuffer().BeginItalic(); }
1132
1133 /**
1134 Ends using italic.
1135 */
1136 bool EndItalic() { return GetBuffer().EndItalic(); }
1137
1138 /**
1139 Begins using underlining.
1140 */
1141 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
1142
1143 /**
1144 End applying underlining.
1145 */
1146 bool EndUnderline() { return GetBuffer().EndUnderline(); }
1147
1148 /**
1149 Begins using the given point size.
1150 */
1151 bool BeginFontSize(int pointSize) { return GetBuffer().BeginFontSize(pointSize); }
1152
1153 /**
1154 Ends using a point size.
1155 */
1156 bool EndFontSize() { return GetBuffer().EndFontSize(); }
1157
1158 /**
1159 Begins using this font.
1160 */
1161 bool BeginFont(const wxFont& font) { return GetBuffer().BeginFont(font); }
1162
1163 /**
1164 Ends using a font.
1165 */
1166 bool EndFont() { return GetBuffer().EndFont(); }
1167
1168 /**
1169 Begins using this colour.
1170 */
1171 bool BeginTextColour(const wxColour& colour) { return GetBuffer().BeginTextColour(colour); }
1172
1173 /**
1174 Ends applying a text colour.
1175 */
1176 bool EndTextColour() { return GetBuffer().EndTextColour(); }
1177
1178 /**
1179 Begins using alignment.
1180 For alignment values, see wxTextAttr.
1181 */
1182 bool BeginAlignment(wxTextAttrAlignment alignment) { return GetBuffer().BeginAlignment(alignment); }
1183
1184 /**
1185 Ends alignment.
1186 */
1187 bool EndAlignment() { return GetBuffer().EndAlignment(); }
1188
1189 /**
1190 Begins applying a left indent and subindent in tenths of a millimetre.
1191 The subindent is an offset from the left edge of the paragraph, and is
1192 used for all but the first line in a paragraph. A positive value will
1193 cause the first line to appear to the left of the subsequent lines, and
1194 a negative value will cause the first line to be indented to the right
1195 of the subsequent lines.
1196
1197 wxRichTextBuffer uses indentation to render a bulleted item. The
1198 content of the paragraph, including the first line, starts at the
1199 @a leftIndent plus the @a leftSubIndent.
1200
1201 @param leftIndent
1202 The distance between the margin and the bullet.
1203 @param leftSubIndent
1204 The distance between the left edge of the bullet and the left edge
1205 of the actual paragraph.
1206 */
1207 bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0) { return GetBuffer().BeginLeftIndent(leftIndent, leftSubIndent); }
1208
1209 /**
1210 Ends left indent.
1211 */
1212 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
1213
1214 /**
1215 Begins a right indent, specified in tenths of a millimetre.
1216 */
1217 bool BeginRightIndent(int rightIndent) { return GetBuffer().BeginRightIndent(rightIndent); }
1218
1219 /**
1220 Ends right indent.
1221 */
1222 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
1223
1224 /**
1225 Begins paragraph spacing; pass the before-paragraph and after-paragraph spacing
1226 in tenths of a millimetre.
1227 */
1228 bool BeginParagraphSpacing(int before, int after) { return GetBuffer().BeginParagraphSpacing(before, after); }
1229
1230 /**
1231 Ends paragraph spacing.
1232 */
1233 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
1234
1235 /**
1236 Begins appling line spacing. @e spacing is a multiple, where 10 means
1237 single-spacing, 15 means 1.5 spacing, and 20 means double spacing.
1238
1239 The ::wxTextAttrLineSpacing constants are defined for convenience.
1240 */
1241 bool BeginLineSpacing(int lineSpacing) { return GetBuffer().BeginLineSpacing(lineSpacing); }
1242
1243 /**
1244 Ends line spacing.
1245 */
1246 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
1247
1248 /**
1249 Begins a numbered bullet.
1250
1251 This call will be needed for each item in the list, and the
1252 application should take care of incrementing the numbering.
1253
1254 @a bulletNumber is a number, usually starting with 1.
1255 @a leftIndent and @a leftSubIndent are values in tenths of a millimetre.
1256 @a bulletStyle is a bitlist of the ::wxTextAttrBulletStyle values.
1257
1258 wxRichTextBuffer uses indentation to render a bulleted item.
1259 The left indent is the distance between the margin and the bullet.
1260 The content of the paragraph, including the first line, starts
1261 at leftMargin + leftSubIndent.
1262 So the distance between the left edge of the bullet and the
1263 left of the actual paragraph is leftSubIndent.
1264 */
1265 bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD)
1266 { return GetBuffer().BeginNumberedBullet(bulletNumber, leftIndent, leftSubIndent, bulletStyle); }
1267
1268 /**
1269 Ends application of a numbered bullet.
1270 */
1271 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
1272
1273 /**
1274 Begins applying a symbol bullet, using a character from the current font.
1275 See BeginNumberedBullet() for an explanation of how indentation is used
1276 to render the bulleted paragraph.
1277 */
1278 bool BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL)
1279 { return GetBuffer().BeginSymbolBullet(symbol, leftIndent, leftSubIndent, bulletStyle); }
1280
1281 /**
1282 Ends applying a symbol bullet.
1283 */
1284 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
1285
1286 /**
1287 Begins applying a symbol bullet.
1288 */
1289 bool BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_STANDARD)
1290 { return GetBuffer().BeginStandardBullet(bulletName, leftIndent, leftSubIndent, bulletStyle); }
1291
1292 /**
1293 Begins applying a standard bullet.
1294 */
1295 bool EndStandardBullet() { return GetBuffer().EndStandardBullet(); }
1296
1297 /**
1298 Begins using the named character style.
1299 */
1300 bool BeginCharacterStyle(const wxString& characterStyle) { return GetBuffer().BeginCharacterStyle(characterStyle); }
1301
1302 /**
1303 Ends application of a named character style.
1304 */
1305 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
1306
1307 /**
1308 Begins applying the named paragraph style.
1309 */
1310 bool BeginParagraphStyle(const wxString& paragraphStyle) { return GetBuffer().BeginParagraphStyle(paragraphStyle); }
1311
1312 /**
1313 Ends application of a named paragraph style.
1314 */
1315 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
1316
1317 /**
1318 Begins using a specified list style.
1319 Optionally, you can also pass a level and a number.
1320 */
1321 bool BeginListStyle(const wxString& listStyle, int level = 1, int number = 1) { return GetBuffer().BeginListStyle(listStyle, level, number); }
1322
1323 /**
1324 Ends using a specified list style.
1325 */
1326 bool EndListStyle() { return GetBuffer().EndListStyle(); }
1327
1328 /**
1329 Begins applying wxTEXT_ATTR_URL to the content.
1330
1331 Pass a URL and optionally, a character style to apply, since it is common
1332 to mark a URL with a familiar style such as blue text with underlining.
1333 */
1334 bool BeginURL(const wxString& url, const wxString& characterStyle = wxEmptyString) { return GetBuffer().BeginURL(url, characterStyle); }
1335
1336 /**
1337 Ends applying a URL.
1338 */
1339 bool EndURL() { return GetBuffer().EndURL(); }
1340
1341 /**
1342 Sets the default style to the style under the cursor.
1343 */
1344 bool SetDefaultStyleToCursorStyle();
1345
1346 /**
1347 Cancels any selection.
1348 */
1349 virtual void SelectNone();
1350
1351 /**
1352 Selects the word at the given character position.
1353 */
1354 virtual bool SelectWord(long position);
1355
1356 /**
1357 Returns the selection range in character positions. -1, -1 means no selection.
1358
1359 The range is in API convention, i.e. a single character selection is denoted
1360 by (n, n+1)
1361 */
1362 wxRichTextRange GetSelectionRange() const;
1363
1364 /**
1365 Sets the selection to the given range.
1366 The end point of range is specified as the last character position of the span
1367 of text, plus one.
1368
1369 So, for example, to set the selection for a character at position 5, use the
1370 range (5,6).
1371 */
1372 void SetSelectionRange(const wxRichTextRange& range);
1373
1374 /**
1375 Returns the selection range in character positions. -2, -2 means no selection
1376 -1, -1 means select everything.
1377 The range is in internal format, i.e. a single character selection is denoted
1378 by (n, n)
1379 */
1380 wxRichTextRange GetInternalSelectionRange() const { return m_selection.GetRange(); }
1381
1382 /**
1383 Sets the selection range in character positions. -2, -2 means no selection
1384 -1, -1 means select everything.
1385 The range is in internal format, i.e. a single character selection is denoted
1386 by (n, n)
1387 */
1388 void SetInternalSelectionRange(const wxRichTextRange& range) { m_selection.Set(range, GetFocusObject()); }
1389
1390 /**
1391 Adds a new paragraph of text to the end of the buffer.
1392 */
1393 virtual wxRichTextRange AddParagraph(const wxString& text);
1394
1395 /**
1396 Adds an image to the control's buffer.
1397 */
1398 virtual wxRichTextRange AddImage(const wxImage& image);
1399
1400 /**
1401 Lays out the buffer, which must be done before certain operations, such as
1402 setting the caret position.
1403 This function should not normally be required by the application.
1404 */
1405 virtual bool LayoutContent(bool onlyVisibleRect = false);
1406
1407 /**
1408 Move the caret to the given character position.
1409
1410 Please note that this does not update the current editing style
1411 from the new position; to do that, call wxRichTextCtrl::SetInsertionPoint instead.
1412 */
1413 virtual bool MoveCaret(long pos, bool showAtLineStart = false, wxRichTextParagraphLayoutBox* container = NULL);
1414
1415 /**
1416 Moves right.
1417 */
1418 virtual bool MoveRight(int noPositions = 1, int flags = 0);
1419
1420 /**
1421 Moves left.
1422 */
1423 virtual bool MoveLeft(int noPositions = 1, int flags = 0);
1424
1425 /**
1426 Moves to the start of the paragraph.
1427 */
1428 virtual bool MoveUp(int noLines = 1, int flags = 0);
1429
1430 /**
1431 Moves the caret down.
1432 */
1433 virtual bool MoveDown(int noLines = 1, int flags = 0);
1434
1435 /**
1436 Moves to the end of the line.
1437 */
1438 virtual bool MoveToLineEnd(int flags = 0);
1439
1440 /**
1441 Moves to the start of the line.
1442 */
1443 virtual bool MoveToLineStart(int flags = 0);
1444
1445 /**
1446 Moves to the end of the paragraph.
1447 */
1448 virtual bool MoveToParagraphEnd(int flags = 0);
1449
1450 /**
1451 Moves to the start of the paragraph.
1452 */
1453 virtual bool MoveToParagraphStart(int flags = 0);
1454
1455 /**
1456 Moves to the start of the buffer.
1457 */
1458 virtual bool MoveHome(int flags = 0);
1459
1460 /**
1461 Moves to the end of the buffer.
1462 */
1463 virtual bool MoveEnd(int flags = 0);
1464
1465 /**
1466 Moves one or more pages up.
1467 */
1468 virtual bool PageUp(int noPages = 1, int flags = 0);
1469
1470 /**
1471 Moves one or more pages down.
1472 */
1473 virtual bool PageDown(int noPages = 1, int flags = 0);
1474
1475 /**
1476 Moves a number of words to the left.
1477 */
1478 virtual bool WordLeft(int noPages = 1, int flags = 0);
1479
1480 /**
1481 Move a nuber of words to the right.
1482 */
1483 virtual bool WordRight(int noPages = 1, int flags = 0);
1484
1485 //@{
1486 /**
1487 Returns the buffer associated with the control.
1488 */
1489 wxRichTextBuffer& GetBuffer() { return m_buffer; }
1490 const wxRichTextBuffer& GetBuffer() const { return m_buffer; }
1491 //@}
1492
1493 /**
1494 Starts batching undo history for commands.
1495 */
1496 virtual bool BeginBatchUndo(const wxString& cmdName) { return m_buffer.BeginBatchUndo(cmdName); }
1497
1498 /**
1499 Ends batching undo command history.
1500 */
1501 virtual bool EndBatchUndo() { return m_buffer.EndBatchUndo(); }
1502
1503 /**
1504 Returns @true if undo commands are being batched.
1505 */
1506 virtual bool BatchingUndo() const { return m_buffer.BatchingUndo(); }
1507
1508 /**
1509 Starts suppressing undo history for commands.
1510 */
1511 virtual bool BeginSuppressUndo() { return m_buffer.BeginSuppressUndo(); }
1512
1513 /**
1514 Ends suppressing undo command history.
1515 */
1516 virtual bool EndSuppressUndo() { return m_buffer.EndSuppressUndo(); }
1517
1518 /**
1519 Returns @true if undo history suppression is on.
1520 */
1521 virtual bool SuppressingUndo() const { return m_buffer.SuppressingUndo(); }
1522
1523 /**
1524 Test if this whole range has character attributes of the specified kind.
1525 If any of the attributes are different within the range, the test fails.
1526
1527 You can use this to implement, for example, bold button updating.
1528 @a style must have flags indicating which attributes are of interest.
1529 */
1530 virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
1531 {
1532 return GetBuffer().HasCharacterAttributes(range.ToInternal(), style);
1533 }
1534
1535 /**
1536 Test if this whole range has paragraph attributes of the specified kind.
1537 If any of the attributes are different within the range, the test fails.
1538 You can use this to implement, for example, centering button updating.
1539 @a style must have flags indicating which attributes are of interest.
1540 */
1541 virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const
1542 {
1543 return GetBuffer().HasParagraphAttributes(range.ToInternal(), style);
1544 }
1545
1546 /**
1547 Returns @true if all of the selection, or the content at the caret position, is bold.
1548 */
1549 virtual bool IsSelectionBold();
1550
1551 /**
1552 Returns @true if all of the selection, or the content at the caret position, is italic.
1553 */
1554 virtual bool IsSelectionItalics();
1555
1556 /**
1557 Returns @true if all of the selection, or the content at the caret position, is underlined.
1558 */
1559 virtual bool IsSelectionUnderlined();
1560
1561 /**
1562 Returns @true if all of the selection, or the content at the current caret position, has the supplied wxTextAttrEffects flag(s).
1563 */
1564 virtual bool DoesSelectionHaveTextEffectFlag(int flag);
1565
1566 /**
1567 Returns @true if all of the selection, or the content at the caret position, is aligned according to the specified flag.
1568 */
1569 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment);
1570
1571 /**
1572 Apples bold to the selection or default style (undoable).
1573 */
1574 virtual bool ApplyBoldToSelection();
1575
1576 /**
1577 Applies italic to the selection or default style (undoable).
1578 */
1579 virtual bool ApplyItalicToSelection();
1580
1581 /**
1582 Applies underline to the selection or default style (undoable).
1583 */
1584 virtual bool ApplyUnderlineToSelection();
1585
1586 /**
1587 Applies one or more wxTextAttrEffects flags to the selection (undoable).
1588 If there is no selection, it is applied to the default style.
1589 */
1590 virtual bool ApplyTextEffectToSelection(int flags);
1591
1592 /**
1593 Applies the given alignment to the selection or the default style (undoable).
1594 For alignment values, see wxTextAttr.
1595 */
1596 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment);
1597
1598 /**
1599 Applies the style sheet to the buffer, matching paragraph styles in the sheet
1600 against named styles in the buffer.
1601
1602 This might be useful if the styles have changed.
1603 If @a sheet is @NULL, the sheet set with SetStyleSheet() is used.
1604 Currently this applies paragraph styles only.
1605 */
1606 virtual bool ApplyStyle(wxRichTextStyleDefinition* def);
1607
1608 /**
1609 Sets the style sheet associated with the control.
1610 A style sheet allows named character and paragraph styles to be applied.
1611 */
1612 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { GetBuffer().SetStyleSheet(styleSheet); }
1613
1614 /**
1615 Returns the style sheet associated with the control, if any.
1616 A style sheet allows named character and paragraph styles to be applied.
1617 */
1618 wxRichTextStyleSheet* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
1619
1620 /**
1621 Push the style sheet to top of stack.
1622 */
1623 bool PushStyleSheet(wxRichTextStyleSheet* styleSheet) { return GetBuffer().PushStyleSheet(styleSheet); }
1624
1625 /**
1626 Pops the style sheet from top of stack.
1627 */
1628 wxRichTextStyleSheet* PopStyleSheet() { return GetBuffer().PopStyleSheet(); }
1629
1630 /**
1631 Applies the style sheet to the buffer, for example if the styles have changed.
1632 */
1633 bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet = NULL);
1634
1635 /**
1636 Shows the given context menu, optionally adding appropriate property-editing commands for the current position in the object hierarchy.
1637 */
1638 virtual bool ShowContextMenu(wxMenu* menu, const wxPoint& pt, bool addPropertyCommands = true);
1639
1640 /**
1641 Prepares the context menu, optionally adding appropriate property-editing commands.
1642 Returns the number of property commands added.
1643 */
1644 virtual int PrepareContextMenu(wxMenu* menu, const wxPoint& pt, bool addPropertyCommands = true);
1645
1646 /**
1647 Returns @true if we can edit the object's properties via a GUI.
1648 */
1649 virtual bool CanEditProperties(wxRichTextObject* obj) const { return obj->CanEditProperties(); }
1650
1651 /**
1652 Edits the object's properties via a GUI.
1653 */
1654 virtual bool EditProperties(wxRichTextObject* obj, wxWindow* parent) { return obj->EditProperties(parent, & GetBuffer()); }
1655
1656 /**
1657 Gets the object's properties menu label.
1658 */
1659 virtual wxString GetPropertiesMenuLabel(wxRichTextObject* obj) { return obj->GetPropertiesMenuLabel(); }
1660
1661 // Command handlers
1662
1663 /**
1664 Sends the event to the control.
1665 */
1666 void Command(wxCommandEvent& event);
1667
1668 /**
1669 Loads the first dropped file.
1670 */
1671 void OnDropFiles(wxDropFilesEvent& event);
1672
1673 void OnCaptureLost(wxMouseCaptureLostEvent& event);
1674 void OnSysColourChanged(wxSysColourChangedEvent& event);
1675
1676 /**
1677 Standard handler for the wxID_CUT command.
1678 */
1679 void OnCut(wxCommandEvent& event);
1680
1681 /**
1682 Standard handler for the wxID_COPY command.
1683 */
1684 void OnCopy(wxCommandEvent& event);
1685
1686 /**
1687 Standard handler for the wxID_PASTE command.
1688 */
1689 void OnPaste(wxCommandEvent& event);
1690
1691 /**
1692 Standard handler for the wxID_UNDO command.
1693 */
1694 void OnUndo(wxCommandEvent& event);
1695
1696 /**
1697 Standard handler for the wxID_REDO command.
1698 */
1699 void OnRedo(wxCommandEvent& event);
1700
1701 /**
1702 Standard handler for the wxID_SELECTALL command.
1703 */
1704 void OnSelectAll(wxCommandEvent& event);
1705
1706 /**
1707 Standard handler for property commands.
1708 */
1709 void OnProperties(wxCommandEvent& event);
1710
1711 /**
1712 Standard handler for the wxID_CLEAR command.
1713 */
1714 void OnClear(wxCommandEvent& event);
1715
1716 /**
1717 Standard update handler for the wxID_CUT command.
1718 */
1719 void OnUpdateCut(wxUpdateUIEvent& event);
1720
1721 /**
1722 Standard update handler for the wxID_COPY command.
1723 */
1724 void OnUpdateCopy(wxUpdateUIEvent& event);
1725
1726 /**
1727 Standard update handler for the wxID_PASTE command.
1728 */
1729 void OnUpdatePaste(wxUpdateUIEvent& event);
1730
1731 /**
1732 Standard update handler for the wxID_UNDO command.
1733 */
1734 void OnUpdateUndo(wxUpdateUIEvent& event);
1735
1736 /**
1737 Standard update handler for the wxID_REDO command.
1738 */
1739 void OnUpdateRedo(wxUpdateUIEvent& event);
1740
1741 /**
1742 Standard update handler for the wxID_SELECTALL command.
1743 */
1744 void OnUpdateSelectAll(wxUpdateUIEvent& event);
1745
1746 /**
1747 Standard update handler for property commands.
1748 */
1749
1750 void OnUpdateProperties(wxUpdateUIEvent& event);
1751
1752 /**
1753 Standard update handler for the wxID_CLEAR command.
1754 */
1755 void OnUpdateClear(wxUpdateUIEvent& event);
1756
1757 /**
1758 Shows a standard context menu with undo, redo, cut, copy, paste, clear, and
1759 select all commands.
1760 */
1761 void OnContextMenu(wxContextMenuEvent& event);
1762
1763 // Event handlers
1764
1765 // Painting
1766 void OnPaint(wxPaintEvent& event);
1767 void OnEraseBackground(wxEraseEvent& event);
1768
1769 // Left-click
1770 void OnLeftClick(wxMouseEvent& event);
1771
1772 // Left-up
1773 void OnLeftUp(wxMouseEvent& event);
1774
1775 // Motion
1776 void OnMoveMouse(wxMouseEvent& event);
1777
1778 // Left-double-click
1779 void OnLeftDClick(wxMouseEvent& event);
1780
1781 // Middle-click
1782 void OnMiddleClick(wxMouseEvent& event);
1783
1784 // Right-click
1785 void OnRightClick(wxMouseEvent& event);
1786
1787 // Key press
1788 void OnChar(wxKeyEvent& event);
1789
1790 // Sizing
1791 void OnSize(wxSizeEvent& event);
1792
1793 // Setting/losing focus
1794 void OnSetFocus(wxFocusEvent& event);
1795 void OnKillFocus(wxFocusEvent& event);
1796
1797 // Idle-time processing
1798 void OnIdle(wxIdleEvent& event);
1799
1800 // Scrolling
1801 void OnScroll(wxScrollWinEvent& event);
1802
1803 /**
1804 Sets the font, and also the basic and default attributes
1805 (see wxRichTextCtrl::SetDefaultStyle).
1806 */
1807 virtual bool SetFont(const wxFont& font);
1808
1809 /**
1810 A helper function setting up scrollbars, for example after a resize.
1811 */
1812 virtual void SetupScrollbars(bool atTop = false);
1813
1814 /**
1815 Helper function implementing keyboard navigation.
1816 */
1817 virtual bool KeyboardNavigate(int keyCode, int flags);
1818
1819 /**
1820 Paints the background.
1821 */
1822 virtual void PaintBackground(wxDC& dc);
1823
1824 /**
1825 Other user defined painting after everything else (i.e. all text) is painted.
1826
1827 @since 2.9.1
1828 */
1829 virtual void PaintAboveContent(wxDC& WXUNUSED(dc)) {}
1830
1831 #if wxRICHTEXT_BUFFERED_PAINTING
1832 /**
1833 Recreates the buffer bitmap if necessary.
1834 */
1835 virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
1836 #endif
1837
1838 // Write text
1839 virtual void DoWriteText(const wxString& value, int flags = 0);
1840
1841 // Should we inherit colours?
1842 virtual bool ShouldInheritColours() const { return false; }
1843
1844 /**
1845 Internal function to position the visible caret according to the current caret
1846 position.
1847 */
1848 virtual void PositionCaret(wxRichTextParagraphLayoutBox* container = NULL);
1849
1850 /**
1851 Helper function for extending the selection, returning @true if the selection
1852 was changed. Selections are in caret positions.
1853 */
1854 virtual bool ExtendSelection(long oldPosition, long newPosition, int flags);
1855
1856 /**
1857 Scrolls @a position into view. This function takes a caret position.
1858 */
1859 virtual bool ScrollIntoView(long position, int keyCode);
1860
1861 /**
1862 Refreshes the area affected by a selection change.
1863 */
1864 bool RefreshForSelectionChange(const wxRichTextSelection& oldSelection, const wxRichTextSelection& newSelection);
1865
1866 /**
1867 Sets the caret position.
1868
1869 The caret position is the character position just before the caret.
1870 A value of -1 means the caret is at the start of the buffer.
1871 Please note that this does not update the current editing style
1872 from the new position or cause the actual caret to be refreshed; to do that,
1873 call wxRichTextCtrl::SetInsertionPoint instead.
1874 */
1875 void SetCaretPosition(long position, bool showAtLineStart = false) ;
1876
1877 /**
1878 Returns the current caret position.
1879 */
1880 long GetCaretPosition() const { return m_caretPosition; }
1881
1882 /**
1883 The adjusted caret position is the character position adjusted to take
1884 into account whether we're at the start of a paragraph, in which case
1885 style information should be taken from the next position, not current one.
1886 */
1887 long GetAdjustedCaretPosition(long caretPos) const;
1888
1889 /**
1890 Move the caret one visual step forward: this may mean setting a flag
1891 and keeping the same position if we're going from the end of one line
1892 to the start of the next, which may be the exact same caret position.
1893 */
1894 void MoveCaretForward(long oldPosition) ;
1895
1896 /**
1897 Move the caret one visual step forward: this may mean setting a flag
1898 and keeping the same position if we're going from the end of one line
1899 to the start of the next, which may be the exact same caret position.
1900 */
1901 void MoveCaretBack(long oldPosition) ;
1902
1903 /**
1904 Returns the caret height and position for the given character position.
1905 If container is null, the current focus object will be used.
1906
1907 @beginWxPerlOnly
1908 In wxPerl this method is implemented as
1909 GetCaretPositionForIndex(@a position) returning a
1910 2-element list (ok, rect).
1911 @endWxPerlOnly
1912 */
1913 bool GetCaretPositionForIndex(long position, wxRect& rect, wxRichTextParagraphLayoutBox* container = NULL);
1914
1915 /**
1916 Internal helper function returning the line for the visible caret position.
1917 If the caret is shown at the very end of the line, it means the next character
1918 is actually on the following line.
1919 So this function gets the line we're expecting to find if this is the case.
1920 */
1921 wxRichTextLine* GetVisibleLineForCaretPosition(long caretPosition) const;
1922
1923 /**
1924 Gets the command processor associated with the control's buffer.
1925 */
1926 wxCommandProcessor* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
1927
1928 /**
1929 Deletes content if there is a selection, e.g. when pressing a key.
1930 Returns the new caret position in @e newPos, or leaves it if there
1931 was no action. This is undoable.
1932
1933 @beginWxPerlOnly
1934 In wxPerl this method takes no arguments and returns a 2-element
1935 list (ok, newPos).
1936 @endWxPerlOnly
1937 */
1938 bool DeleteSelectedContent(long* newPos= NULL);
1939
1940 /**
1941 Transforms logical (unscrolled) position to physical window position.
1942 */
1943 wxPoint GetPhysicalPoint(const wxPoint& ptLogical) const;
1944
1945 /**
1946 Transforms physical window position to logical (unscrolled) position.
1947 */
1948 wxPoint GetLogicalPoint(const wxPoint& ptPhysical) const;
1949
1950 /**
1951 Helper function for finding the caret position for the next word.
1952 Direction is 1 (forward) or -1 (backwards).
1953 */
1954 virtual long FindNextWordPosition(int direction = 1) const;
1955
1956 /**
1957 Returns @true if the given position is visible on the screen.
1958 */
1959 bool IsPositionVisible(long pos) const;
1960
1961 /**
1962 Returns the first visible position in the current view.
1963 */
1964 long GetFirstVisiblePosition() const;
1965
1966 /**
1967 Returns the caret position since the default formatting was changed. As
1968 soon as this position changes, we no longer reflect the default style
1969 in the UI. A value of -2 means that we should only reflect the style of the
1970 content under the caret.
1971 */
1972 long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle; }
1973
1974 /**
1975 Set the caret position for the default style that the user is selecting.
1976 */
1977 void SetCaretPositionForDefaultStyle(long pos) { m_caretPositionForDefaultStyle = pos; }
1978
1979 /**
1980 Returns @true if the user has recently set the default style without moving
1981 the caret, and therefore the UI needs to reflect the default style and not
1982 the style at the caret.
1983
1984 Below is an example of code that uses this function to determine whether the UI
1985 should show that the current style is bold.
1986
1987 @see SetAndShowDefaultStyle().
1988 */
1989 bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle != -2; }
1990
1991 /**
1992 Sets @a attr as the default style and tells the control that the UI should
1993 reflect this attribute until the user moves the caret.
1994
1995 @see IsDefaultStyleShowing().
1996 */
1997 void SetAndShowDefaultStyle(const wxRichTextAttr& attr)
1998 {
1999 SetDefaultStyle(attr);
2000 SetCaretPositionForDefaultStyle(GetCaretPosition());
2001 }
2002
2003 /**
2004 Returns the first visible point in the window.
2005 */
2006 wxPoint GetFirstVisiblePoint() const;
2007
2008 #ifdef DOXYGEN
2009 /**
2010 Returns the content of the entire control as a string.
2011 */
2012 virtual wxString GetValue() const;
2013
2014 /**
2015 Replaces existing content with the given text.
2016 */
2017 virtual void SetValue(const wxString& value);
2018
2019 /**
2020 Call this function to prevent refresh and allow fast updates, and then Thaw() to
2021 refresh the control.
2022 */
2023 void Freeze();
2024
2025 /**
2026 Call this function to end a Freeze and refresh the display.
2027 */
2028 void Thaw();
2029
2030 /**
2031 Returns @true if Freeze has been called without a Thaw.
2032 */
2033 bool IsFrozen() const;
2034
2035 #endif
2036
2037 // Implementation
2038
2039 /**
2040 Sets up the caret for the given position and container, after a mouse click.
2041 */
2042 bool SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox* container, long position, int hitTestFlags, bool extendSelection = false);
2043
2044 /**
2045 Find the caret position for the combination of hit-test flags and character position.
2046 Returns the caret position and also an indication of where to place the caret (caretLineStart)
2047 since this is ambiguous (same position used for end of line and start of next).
2048 */
2049 long FindCaretPositionForCharacterPosition(long position, int hitTestFlags, wxRichTextParagraphLayoutBox* container,
2050 bool& caretLineStart);
2051
2052 /**
2053 Processes mouse movement in order to change the cursor
2054 */
2055 virtual bool ProcessMouseMovement(wxRichTextParagraphLayoutBox* container, wxRichTextObject* obj, long position, const wxPoint& pos);
2056
2057 /**
2058 Font names take a long time to retrieve, so cache them (on demand).
2059 */
2060 static const wxArrayString& GetAvailableFontNames();
2061
2062 /**
2063 Clears the cache of available font names.
2064 */
2065 static void ClearAvailableFontNames();
2066
2067 WX_FORWARD_TO_SCROLL_HELPER()
2068
2069 // implement wxTextEntry methods
2070 virtual wxString DoGetValue() const;
2071
2072 protected:
2073 // implement the wxTextEntry pure virtual method
2074 virtual wxWindow *GetEditableWindow() { return this; }
2075
2076 // margins functions
2077 virtual bool DoSetMargins(const wxPoint& pt);
2078 virtual wxPoint DoGetMargins() const;
2079
2080 // FIXME: this does not work, it allows this code to compile but will fail
2081 // during run-time
2082 #ifndef __WXUNIVERSAL__
2083 #ifdef __WXMSW__
2084 virtual WXHWND GetEditHWND() const { return GetHWND(); }
2085 #endif
2086 #ifdef __WXMOTIF__
2087 virtual WXWidget GetTextWidget() const { return NULL; }
2088 #endif
2089 #ifdef __WXGTK20__
2090 virtual GtkEditable *GetEditable() const { return NULL; }
2091 virtual GtkEntry *GetEntry() const { return NULL; }
2092 #endif
2093 #endif // !__WXUNIVERSAL__
2094
2095 // Overrides
2096 protected:
2097
2098 /**
2099 Currently this simply returns @c wxSize(10, 10).
2100 */
2101 virtual wxSize DoGetBestSize() const ;
2102
2103 virtual void DoSetValue(const wxString& value, int flags = 0);
2104
2105 virtual void DoThaw();
2106
2107
2108 // Data members
2109 protected:
2110 #if wxRICHTEXT_BUFFERED_PAINTING
2111 /// Buffer bitmap
2112 wxBitmap m_bufferBitmap;
2113 #endif
2114
2115 /// Text buffer
2116 wxRichTextBuffer m_buffer;
2117
2118 wxMenu* m_contextMenu;
2119
2120 /// Caret position (1 less than the character position, so -1 is the
2121 /// first caret position).
2122 long m_caretPosition;
2123
2124 /// Caret position when the default formatting has been changed. As
2125 /// soon as this position changes, we no longer reflect the default style
2126 /// in the UI.
2127 long m_caretPositionForDefaultStyle;
2128
2129 /// Selection range in character positions. -2, -2 means no selection.
2130 wxRichTextSelection m_selection;
2131
2132 wxRichTextCtrlSelectionState m_selectionState;
2133
2134 /// Anchor so we know how to extend the selection
2135 /// It's a caret position since it's between two characters.
2136 long m_selectionAnchor;
2137
2138 /// Anchor object if selecting multiple container objects, such as grid cells.
2139 wxRichTextObject* m_selectionAnchorObject;
2140
2141 /// Are we editable?
2142 bool m_editable;
2143
2144 /// Are we showing the caret position at the start of a line
2145 /// instead of at the end of the previous one?
2146 bool m_caretAtLineStart;
2147
2148 /// Are we dragging (i.e. extending) a selection?
2149 bool m_dragging;
2150
2151 #if wxUSE_DRAG_AND_DROP
2152 /// Are we trying to start Drag'n'Drop?
2153 bool m_preDrag;
2154
2155 /// Initial position when starting Drag'n'Drop
2156 wxPoint m_dragStartPoint;
2157
2158 #if wxUSE_DATETIME
2159 /// Initial time when starting Drag'n'Drop
2160 wxDateTime m_dragStartTime;
2161 #endif // wxUSE_DATETIME
2162 #endif // wxUSE_DRAG_AND_DROP
2163
2164 /// Do we need full layout in idle?
2165 bool m_fullLayoutRequired;
2166 wxLongLong m_fullLayoutTime;
2167 long m_fullLayoutSavedPosition;
2168
2169 /// Threshold for doing delayed layout
2170 long m_delayedLayoutThreshold;
2171
2172 /// Cursors
2173 wxCursor m_textCursor;
2174 wxCursor m_urlCursor;
2175
2176 static wxArrayString sm_availableFontNames;
2177
2178 wxRichTextContextMenuPropertiesInfo m_contextMenuPropertiesInfo;
2179
2180 /// The object that currently has the editing focus
2181 wxRichTextParagraphLayoutBox* m_focusObject;
2182 };
2183
2184 #if wxUSE_DRAG_AND_DROP
2185 class WXDLLIMPEXP_RICHTEXT wxRichTextDropSource : public wxDropSource
2186 {
2187 public:
2188 wxRichTextDropSource(wxDataObject& data, wxRichTextCtrl* tc)
2189 : wxDropSource(data, tc), m_rtc(tc) {}
2190
2191 protected:
2192 bool GiveFeedback(wxDragResult effect);
2193
2194 wxRichTextCtrl* m_rtc;
2195 };
2196
2197 class WXDLLIMPEXP_RICHTEXT wxRichTextDropTarget : public wxDropTarget
2198 {
2199 public:
2200 wxRichTextDropTarget(wxRichTextCtrl* tc)
2201 : wxDropTarget(new wxRichTextBufferDataObject(new wxRichTextBuffer)), m_rtc(tc) {}
2202
2203 virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
2204 {
2205 if ( !GetData() )
2206 return wxDragNone;
2207 m_rtc->OnDrop(x, y, def, m_dataObject);
2208 return def;
2209 }
2210
2211 protected:
2212 wxRichTextCtrl* m_rtc;
2213 };
2214 #endif // wxUSE_DRAG_AND_DROP
2215
2216 /**
2217 @class wxRichTextEvent
2218
2219 This is the event class for wxRichTextCtrl notifications.
2220
2221 @beginEventTable{wxRichTextEvent}
2222 @event{EVT_RICHTEXT_LEFT_CLICK(id, func)}
2223 Process a @c wxEVT_COMMAND_RICHTEXT_LEFT_CLICK event, generated when the user
2224 releases the left mouse button over an object.
2225 @event{EVT_RICHTEXT_RIGHT_CLICK(id, func)}
2226 Process a @c wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK event, generated when the user
2227 releases the right mouse button over an object.
2228 @event{EVT_RICHTEXT_MIDDLE_CLICK(id, func)}
2229 Process a @c wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK event, generated when the user
2230 releases the middle mouse button over an object.
2231 @event{EVT_RICHTEXT_LEFT_DCLICK(id, func)}
2232 Process a @c wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK event, generated when the user
2233 double-clicks an object.
2234 @event{EVT_RICHTEXT_RETURN(id, func)}
2235 Process a @c wxEVT_COMMAND_RICHTEXT_RETURN event, generated when the user
2236 presses the return key. Valid event functions: GetFlags, GetPosition.
2237 @event{EVT_RICHTEXT_CHARACTER(id, func)}
2238 Process a @c wxEVT_COMMAND_RICHTEXT_CHARACTER event, generated when the user
2239 presses a character key. Valid event functions: GetFlags, GetPosition, GetCharacter.
2240 @event{EVT_RICHTEXT_DELETE(id, func)}
2241 Process a @c wxEVT_COMMAND_RICHTEXT_DELETE event, generated when the user
2242 presses the backspace or delete key. Valid event functions: GetFlags, GetPosition.
2243 @event{EVT_RICHTEXT_RETURN(id, func)}
2244 Process a @c wxEVT_COMMAND_RICHTEXT_RETURN event, generated when the user
2245 presses the return key. Valid event functions: GetFlags, GetPosition.
2246 @event{EVT_RICHTEXT_STYLE_CHANGED(id, func)}
2247 Process a @c wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED event, generated when
2248 styling has been applied to the control. Valid event functions: GetPosition, GetRange.
2249 @event{EVT_RICHTEXT_STYLESHEET_CHANGED(id, func)}
2250 Process a @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING event, generated
2251 when the control's stylesheet has changed, for example the user added,
2252 edited or deleted a style. Valid event functions: GetRange, GetPosition.
2253 @event{EVT_RICHTEXT_STYLESHEET_REPLACING(id, func)}
2254 Process a @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING event, generated
2255 when the control's stylesheet is about to be replaced, for example when
2256 a file is loaded into the control.
2257 Valid event functions: Veto, GetOldStyleSheet, GetNewStyleSheet.
2258 @event{EVT_RICHTEXT_STYLESHEET_REPLACED(id, func)}
2259 Process a @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED event, generated
2260 when the control's stylesheet has been replaced, for example when a file
2261 is loaded into the control.
2262 Valid event functions: GetOldStyleSheet, GetNewStyleSheet.
2263 @event{EVT_RICHTEXT_CONTENT_INSERTED(id, func)}
2264 Process a @c wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED event, generated when
2265 content has been inserted into the control.
2266 Valid event functions: GetPosition, GetRange.
2267 @event{EVT_RICHTEXT_CONTENT_DELETED(id, func)}
2268 Process a @c wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED event, generated when
2269 content has been deleted from the control.
2270 Valid event functions: GetPosition, GetRange.
2271 @event{EVT_RICHTEXT_BUFFER_RESET(id, func)}
2272 Process a @c wxEVT_COMMAND_RICHTEXT_BUFFER_RESET event, generated when the
2273 buffer has been reset by deleting all content.
2274 You can use this to set a default style for the first new paragraph.
2275 @event{EVT_RICHTEXT_SELECTION_CHANGED(id, func)}
2276 Process a @c wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED event, generated when the
2277 selection range has changed.
2278 @event{EVT_RICHTEXT_FOCUS_OBJECT_CHANGED(id, func)}
2279 Process a @c wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED event, generated when the
2280 current focus object has changed.
2281 @endEventTable
2282
2283 @library{wxrichtext}
2284 @category{events,richtext}
2285 */
2286
2287 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent : public wxNotifyEvent
2288 {
2289 public:
2290 /**
2291 Constructor.
2292
2293 @param commandType
2294 The type of the event.
2295 @param id
2296 Window identifier. The value @c wxID_ANY indicates a default value.
2297 */
2298 wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
2299 : wxNotifyEvent(commandType, winid),
2300 m_flags(0), m_position(-1), m_oldStyleSheet(NULL), m_newStyleSheet(NULL),
2301 m_char((wxChar) 0), m_container(NULL), m_oldContainer(NULL)
2302 { }
2303
2304 /**
2305 Copy constructor.
2306 */
2307 wxRichTextEvent(const wxRichTextEvent& event)
2308 : wxNotifyEvent(event),
2309 m_flags(event.m_flags), m_position(-1),
2310 m_oldStyleSheet(event.m_oldStyleSheet), m_newStyleSheet(event.m_newStyleSheet),
2311 m_char((wxChar) 0), m_container(event.m_container), m_oldContainer(event.m_oldContainer)
2312 { }
2313
2314 /**
2315 Returns the buffer position at which the event occured.
2316 */
2317 long GetPosition() const { return m_position; }
2318
2319 /**
2320 Sets the buffer position variable.
2321 */
2322 void SetPosition(long pos) { m_position = pos; }
2323
2324 /**
2325 Returns flags indicating modifier keys pressed.
2326
2327 Possible values are @c wxRICHTEXT_CTRL_DOWN, @c wxRICHTEXT_SHIFT_DOWN, and @c wxRICHTEXT_ALT_DOWN.
2328 */
2329 int GetFlags() const { return m_flags; }
2330
2331 /**
2332 Sets flags indicating modifier keys pressed.
2333
2334 Possible values are @c wxRICHTEXT_CTRL_DOWN, @c wxRICHTEXT_SHIFT_DOWN, and @c wxRICHTEXT_ALT_DOWN.
2335 */
2336 void SetFlags(int flags) { m_flags = flags; }
2337
2338 /**
2339 Returns the old style sheet.
2340
2341 Can be used in a @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
2342 @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
2343 */
2344 wxRichTextStyleSheet* GetOldStyleSheet() const { return m_oldStyleSheet; }
2345
2346 /**
2347 Sets the old style sheet variable.
2348 */
2349 void SetOldStyleSheet(wxRichTextStyleSheet* sheet) { m_oldStyleSheet = sheet; }
2350
2351 /**
2352 Returns the new style sheet.
2353
2354 Can be used in a @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING or
2355 @c wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED event handler.
2356 */
2357 wxRichTextStyleSheet* GetNewStyleSheet() const { return m_newStyleSheet; }
2358
2359 /**
2360 Sets the new style sheet variable.
2361 */
2362 void SetNewStyleSheet(wxRichTextStyleSheet* sheet) { m_newStyleSheet = sheet; }
2363
2364 /**
2365 Gets the range for the current operation.
2366 */
2367 const wxRichTextRange& GetRange() const { return m_range; }
2368
2369 /**
2370 Sets the range variable.
2371 */
2372 void SetRange(const wxRichTextRange& range) { m_range = range; }
2373
2374 /**
2375 Returns the character pressed, within a @c wxEVT_COMMAND_RICHTEXT_CHARACTER event.
2376 */
2377 wxChar GetCharacter() const { return m_char; }
2378
2379 /**
2380 Sets the character variable.
2381 */
2382 void SetCharacter(wxChar ch) { m_char = ch; }
2383
2384 /**
2385 Returns the container for which the event is relevant.
2386 */
2387 wxRichTextParagraphLayoutBox* GetContainer() const { return m_container; }
2388
2389 /**
2390 Sets the container for which the event is relevant.
2391 */
2392 void SetContainer(wxRichTextParagraphLayoutBox* container) { m_container = container; }
2393
2394 /**
2395 Returns the old container, for a focus change event.
2396 */
2397 wxRichTextParagraphLayoutBox* GetOldContainer() const { return m_oldContainer; }
2398
2399 /**
2400 Sets the old container, for a focus change event.
2401 */
2402 void SetOldContainer(wxRichTextParagraphLayoutBox* container) { m_oldContainer = container; }
2403
2404 virtual wxEvent *Clone() const { return new wxRichTextEvent(*this); }
2405
2406 protected:
2407 int m_flags;
2408 long m_position;
2409 wxRichTextStyleSheet* m_oldStyleSheet;
2410 wxRichTextStyleSheet* m_newStyleSheet;
2411 wxRichTextRange m_range;
2412 wxChar m_char;
2413 wxRichTextParagraphLayoutBox* m_container;
2414 wxRichTextParagraphLayoutBox* m_oldContainer;
2415
2416 private:
2417 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent)
2418 };
2419
2420 /*!
2421 * wxRichTextCtrl events
2422 */
2423 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, wxRichTextEvent );
2424 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, wxRichTextEvent );
2425 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, wxRichTextEvent );
2426 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, wxRichTextEvent );
2427 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RETURN, wxRichTextEvent );
2428 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CHARACTER, wxRichTextEvent );
2429 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_DELETE, wxRichTextEvent );
2430
2431 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, wxRichTextEvent );
2432 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, wxRichTextEvent );
2433 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, wxRichTextEvent );
2434 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, wxRichTextEvent );
2435
2436 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, wxRichTextEvent );
2437 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, wxRichTextEvent );
2438 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, wxRichTextEvent );
2439 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_PROPERTIES_CHANGED, wxRichTextEvent );
2440 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, wxRichTextEvent );
2441 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, wxRichTextEvent );
2442 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED, wxRichTextEvent );
2443
2444 typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);
2445
2446 #define wxRichTextEventHandler(func) \
2447 wxEVENT_HANDLER_CAST(wxRichTextEventFunction, func)
2448
2449 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
2450 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
2451 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
2452 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
2453 #define EVT_RICHTEXT_RETURN(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, wxRichTextEventHandler( fn ), NULL ),
2454 #define EVT_RICHTEXT_CHARACTER(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CHARACTER, id, -1, wxRichTextEventHandler( fn ), NULL ),
2455 #define EVT_RICHTEXT_DELETE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_DELETE, id, -1, wxRichTextEventHandler( fn ), NULL ),
2456
2457 #define EVT_RICHTEXT_STYLESHEET_CHANGING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, id, -1, wxRichTextEventHandler( fn ), NULL ),
2458 #define EVT_RICHTEXT_STYLESHEET_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2459 #define EVT_RICHTEXT_STYLESHEET_REPLACING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, id, -1, wxRichTextEventHandler( fn ), NULL ),
2460 #define EVT_RICHTEXT_STYLESHEET_REPLACED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2461
2462 #define EVT_RICHTEXT_CONTENT_INSERTED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2463 #define EVT_RICHTEXT_CONTENT_DELETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2464 #define EVT_RICHTEXT_STYLE_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2465 #define EVT_RICHTEXT_PROPERTIES_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_PROPERTIES_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2466 #define EVT_RICHTEXT_SELECTION_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2467 #define EVT_RICHTEXT_BUFFER_RESET(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, id, -1, wxRichTextEventHandler( fn ), NULL ),
2468 #define EVT_RICHTEXT_FOCUS_OBJECT_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
2469
2470 #endif
2471 // wxUSE_RICHTEXT
2472
2473 #endif
2474 // _WX_RICHTEXTCTRL_H_