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