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