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