1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextctrl.h
3 // Purpose: A rich edit control
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTCTRL_H_
13 #define _WX_RICHTEXTCTRL_H_
15 #include "wx/richtext/richtextbuffer.h"
19 #include "wx/scrolwin.h"
22 #if wxCHECK_VERSION(2,7,0)
23 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
25 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
28 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
29 #include "wx/textctrl.h"
39 #define wxRE_READONLY 0x0010
40 #define wxRE_MULTILINE 0x0020
45 #define wxRICHTEXT_SHIFT_DOWN 0x01
46 #define wxRICHTEXT_CTRL_DOWN 0x02
47 #define wxRICHTEXT_ALT_DOWN 0x04
52 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
53 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
54 #define wxRICHTEXT_DEFAULT_SPACING 3
55 #define wxRICHTEXT_DEFAULT_MARGIN 3
56 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
57 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
58 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
59 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
60 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
61 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
62 // Minimum buffer size before delayed layout kicks in
63 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
64 // Milliseconds before layout occurs after resize
65 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
68 * Forward declarations
72 * wxRichTextItem class declaration
75 // Drawing styles/states
76 #define wxRICHTEXT_SELECTED 0x01
77 #define wxRICHTEXT_TAGGED 0x02
78 // The control is focussed
79 #define wxRICHTEXT_FOCUSSED 0x04
80 // The item itself has the focus
81 #define wxRICHTEXT_IS_FOCUS 0x08
84 * wxRichTextCtrl class declaration
87 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl
:
88 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
89 public wxTextCtrlBase
, wxScrollHelper
91 public wxScrolledWindow
94 DECLARE_CLASS( wxRichTextCtrl
)
101 wxRichTextCtrl( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
102 long style
= wxRE_MULTILINE
);
103 virtual ~wxRichTextCtrl( );
108 bool Create( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
109 long style
= wxRE_MULTILINE
);
111 /// Member initialisation
114 ///// wxTextCtrl compatibility
118 virtual wxString
GetValue() const;
119 virtual void SetValue(const wxString
& value
);
121 virtual wxString
GetRange(long from
, long to
) const;
123 virtual int GetLineLength(long lineNo
) const ;
124 virtual wxString
GetLineText(long lineNo
) const ;
125 virtual int GetNumberOfLines() const ;
127 virtual bool IsModified() const ;
128 virtual bool IsEditable() const ;
130 // more readable flag testing methods
131 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE
); }
132 bool IsMultiLine() const { return !IsSingleLine(); }
134 // If the return values from and to are the same, there is no selection.
135 virtual void GetSelection(long* from
, long* to
) const;
137 virtual wxString
GetStringSelection() const;
140 wxString
GetFilename() const { return m_filename
; }
143 void SetFilename(const wxString
& filename
) { m_filename
= filename
; }
145 /// Set the threshold in character positions for doing layout optimization during sizing
146 void SetDelayedLayoutThreshold(long threshold
) { m_delayedLayoutThreshold
= threshold
; }
148 /// Get the threshold in character positions for doing layout optimization during sizing
149 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold
; }
154 virtual void Clear();
155 virtual void Replace(long from
, long to
, const wxString
& value
);
156 virtual void Remove(long from
, long to
);
158 // load/save the controls contents from/to the file
159 virtual bool LoadFile(const wxString
& file
, int type
= wxRICHTEXT_TYPE_ANY
);
160 virtual bool SaveFile(const wxString
& file
= wxEmptyString
, int type
= wxRICHTEXT_TYPE_ANY
);
162 // sets/clears the dirty flag
163 virtual void MarkDirty();
164 virtual void DiscardEdits();
166 // set the max number of characters which may be entered in a single line
168 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
170 // writing text inserts it at the current position, appending always
171 // inserts it at the end
172 virtual void WriteText(const wxString
& text
);
173 virtual void AppendText(const wxString
& text
);
175 // text control under some platforms supports the text styles: these
176 // methods allow to apply the given text style to the given selection or to
177 // set/get the style which will be used for all appended text
178 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
179 virtual bool SetStyle(long start
, long end
, const wxTextAttrEx
& style
);
180 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
181 virtual bool GetStyle(long position
, wxTextAttr
& style
) const;
182 virtual bool GetStyle(long position
, wxTextAttrEx
& style
) const;
183 virtual bool GetStyle(long position
, wxRichTextAttr
& style
) const;
184 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
185 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
187 // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
188 virtual const wxTextAttrEx
& GetDefaultStyleEx() const;
189 virtual const wxTextAttr
& GetDefaultStyle() const;
191 // translate between the position (which is just an index in the text ctrl
192 // considering all its contents as a single strings) and (x, y) coordinates
193 // which represent column and line.
194 virtual long XYToPosition(long x
, long y
) const;
195 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
197 virtual void ShowPosition(long pos
);
199 // find the character at position given in pixels
201 // NB: pt is in device coords (not adjusted for the client area origin nor
203 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
204 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
206 wxTextCoord
*row
) const;
208 // Clipboard operations
211 virtual void Paste();
212 virtual void DeleteSelection();
214 virtual bool CanCopy() const;
215 virtual bool CanCut() const;
216 virtual bool CanPaste() const;
217 virtual bool CanDeleteSelection() const;
223 virtual bool CanUndo() const;
224 virtual bool CanRedo() const;
227 virtual void SetInsertionPoint(long pos
);
228 virtual void SetInsertionPointEnd();
229 virtual long GetInsertionPoint() const;
230 virtual wxTextPos
GetLastPosition() const;
232 virtual void SetSelection(long from
, long to
);
233 virtual void SelectAll();
234 virtual void SetEditable(bool editable
);
236 /// Call Freeze to prevent refresh
237 virtual void Freeze();
239 /// Call Thaw to refresh
242 /// Call Thaw to refresh
243 virtual bool IsFrozen() const { return m_freezeCount
> 0; }
245 virtual bool HasSelection() const;
247 ///// Functionality specific to wxRichTextCtrl
249 /// Write an image at the current insertion point. Supply optional type to use
250 /// for internal and file storage of the raw data.
251 virtual bool WriteImage(const wxImage
& image
, int bitmapType
= wxBITMAP_TYPE_PNG
);
253 /// Write a bitmap at the current insertion point. Supply optional type to use
254 /// for internal and file storage of the raw data.
255 virtual bool WriteImage(const wxBitmap
& bitmap
, int bitmapType
= wxBITMAP_TYPE_PNG
);
257 /// Load an image from file and write at the current insertion point.
258 virtual bool WriteImage(const wxString
& filename
, int bitmapType
);
260 /// Write an image block at the current insertion point.
261 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
);
263 /// Insert a newline (actually paragraph) at the current insertion point.
264 virtual bool Newline();
266 /// Set basic (overall) style
267 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { GetBuffer().SetBasicStyle(style
); }
268 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { GetBuffer().SetBasicStyle(style
); }
270 /// Get basic (overall) style
271 virtual const wxTextAttrEx
& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
273 /// Begin using a style
274 virtual bool BeginStyle(const wxTextAttrEx
& style
) { return GetBuffer().BeginStyle(style
); }
277 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
280 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
283 bool BeginBold() { return GetBuffer().BeginBold(); }
286 bool EndBold() { return GetBuffer().EndBold(); }
288 /// Begin using italic
289 bool BeginItalic() { return GetBuffer().BeginItalic(); }
292 bool EndItalic() { return GetBuffer().EndItalic(); }
294 /// Begin using underline
295 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
297 /// End using underline
298 bool EndUnderline() { return GetBuffer().EndUnderline(); }
300 /// Begin using point size
301 bool BeginFontSize(int pointSize
) { return GetBuffer().BeginFontSize(pointSize
); }
303 /// End using point size
304 bool EndFontSize() { return GetBuffer().EndFontSize(); }
306 /// Begin using this font
307 bool BeginFont(const wxFont
& font
) { return GetBuffer().BeginFont(font
); }
310 bool EndFont() { return GetBuffer().EndFont(); }
312 /// Begin using this colour
313 bool BeginTextColour(const wxColour
& colour
) { return GetBuffer().BeginTextColour(colour
); }
315 /// End using a colour
316 bool EndTextColour() { return GetBuffer().EndTextColour(); }
318 /// Begin using alignment
319 bool BeginAlignment(wxTextAttrAlignment alignment
) { return GetBuffer().BeginAlignment(alignment
); }
322 bool EndAlignment() { return GetBuffer().EndAlignment(); }
324 /// Begin left indent
325 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0) { return GetBuffer().BeginLeftIndent(leftIndent
, leftSubIndent
); }
328 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
330 /// Begin right indent
331 bool BeginRightIndent(int rightIndent
) { return GetBuffer().BeginRightIndent(rightIndent
); }
334 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
336 /// Begin paragraph spacing
337 bool BeginParagraphSpacing(int before
, int after
) { return GetBuffer().BeginParagraphSpacing(before
, after
); }
339 /// End paragraph spacing
340 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
342 /// Begin line spacing
343 bool BeginLineSpacing(int lineSpacing
) { return GetBuffer().BeginLineSpacing(lineSpacing
); }
346 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
348 /// Begin numbered bullet
349 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
350 { return GetBuffer().BeginNumberedBullet(bulletNumber
, leftIndent
, leftSubIndent
, bulletStyle
); }
352 /// End numbered bullet
353 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
355 /// Begin symbol bullet
356 bool BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
357 { return GetBuffer().BeginSymbolBullet(symbol
, leftIndent
, leftSubIndent
, bulletStyle
); }
359 /// End symbol bullet
360 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
362 /// Begin named character style
363 bool BeginCharacterStyle(const wxString
& characterStyle
) { return GetBuffer().BeginCharacterStyle(characterStyle
); }
365 /// End named character style
366 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
368 /// Begin named paragraph style
369 bool BeginParagraphStyle(const wxString
& paragraphStyle
) { return GetBuffer().BeginParagraphStyle(paragraphStyle
); }
371 /// End named character style
372 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
374 /// Sets the default style to the style under the cursor
375 bool SetDefaultStyleToCursorStyle();
377 /// Clear the selection
378 virtual void SelectNone();
380 /// Get/set the selection range in character positions. -1, -1 means no selection.
381 const wxRichTextRange
& GetSelectionRange() const { return m_selectionRange
; }
382 void SetSelectionRange(const wxRichTextRange
& range
) { m_selectionRange
= range
; }
384 /// Add a new paragraph of text to the end of the buffer
385 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
388 virtual wxRichTextRange
AddImage(const wxImage
& image
);
390 /// Layout the buffer: which we must do before certain operations, such as
391 /// setting the caret position.
392 virtual bool LayoutContent(bool onlyVisibleRect
= false);
394 /// Move the caret to the given character position
395 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
398 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
401 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
404 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
407 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
409 /// Move to the end of the line
410 virtual bool MoveToLineEnd(int flags
= 0);
412 /// Move to the start of the line
413 virtual bool MoveToLineStart(int flags
= 0);
415 /// Move to the end of the paragraph
416 virtual bool MoveToParagraphEnd(int flags
= 0);
418 /// Move to the start of the paragraph
419 virtual bool MoveToParagraphStart(int flags
= 0);
421 /// Move to the start of the buffer
422 virtual bool MoveHome(int flags
= 0);
424 /// Move to the end of the buffer
425 virtual bool MoveEnd(int flags
= 0);
428 virtual bool PageUp(int noPages
= 1, int flags
= 0);
430 /// Move n pages down
431 virtual bool PageDown(int noPages
= 1, int flags
= 0);
433 /// Move n words left
434 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
436 /// Move n words right
437 virtual bool WordRight(int noPages
= 1, int flags
= 0);
439 /// Returns the buffer associated with the control.
440 wxRichTextBuffer
& GetBuffer() { return m_buffer
; }
441 const wxRichTextBuffer
& GetBuffer() const { return m_buffer
; }
443 /// Start batching undo history for commands.
444 virtual bool BeginBatchUndo(const wxString
& cmdName
) { return m_buffer
.BeginBatchUndo(cmdName
); }
446 /// End batching undo history for commands.
447 virtual bool EndBatchUndo() { return m_buffer
.EndBatchUndo(); }
449 /// Are we batching undo history for commands?
450 virtual bool BatchingUndo() const { return m_buffer
.BatchingUndo(); }
452 /// Start suppressing undo history for commands.
453 virtual bool BeginSuppressUndo() { return m_buffer
.BeginSuppressUndo(); }
455 /// End suppressing undo history for commands.
456 virtual bool EndSuppressUndo() { return m_buffer
.EndSuppressUndo(); }
458 /// Are we suppressing undo history for commands?
459 virtual bool SuppressingUndo() const { return m_buffer
.SuppressingUndo(); }
461 /// Test if this whole range has character attributes of the specified kind. If any
462 /// of the attributes are different within the range, the test fails. You
463 /// can use this to implement, for example, bold button updating. style must have
464 /// flags indicating which attributes are of interest.
465 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
467 return GetBuffer().HasCharacterAttributes(range
, style
);
469 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
471 return GetBuffer().HasCharacterAttributes(range
, style
);
474 /// Test if this whole range has paragraph attributes of the specified kind. If any
475 /// of the attributes are different within the range, the test fails. You
476 /// can use this to implement, for example, centering button updating. style must have
477 /// flags indicating which attributes are of interest.
478 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
480 return GetBuffer().HasParagraphAttributes(range
, style
);
482 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
484 return GetBuffer().HasParagraphAttributes(range
, style
);
487 /// Is all of the selection bold?
488 virtual bool IsSelectionBold() const;
490 /// Is all of the selection italics?
491 virtual bool IsSelectionItalics() const;
493 /// Is all of the selection underlined?
494 virtual bool IsSelectionUnderlined() const;
496 /// Is all of the selection aligned according to the specified flag?
497 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
) const;
499 /// Apply bold to the selection
500 virtual bool ApplyBoldToSelection();
502 /// Apply italic to the selection
503 virtual bool ApplyItalicToSelection();
505 /// Apply underline to the selection
506 virtual bool ApplyUnderlineToSelection();
508 /// Apply alignment to the selection
509 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
511 /// Set style sheet, if any.
512 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { GetBuffer().SetStyleSheet(styleSheet
); }
513 wxRichTextStyleSheet
* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
517 void Command(wxCommandEvent
& event
);
518 void OnDropFiles(wxDropFilesEvent
& event
);
520 void OnCut(wxCommandEvent
& event
);
521 void OnCopy(wxCommandEvent
& event
);
522 void OnPaste(wxCommandEvent
& event
);
523 void OnUndo(wxCommandEvent
& event
);
524 void OnRedo(wxCommandEvent
& event
);
525 void OnSelectAll(wxCommandEvent
& event
);
526 void OnClear(wxCommandEvent
& event
);
528 void OnUpdateCut(wxUpdateUIEvent
& event
);
529 void OnUpdateCopy(wxUpdateUIEvent
& event
);
530 void OnUpdatePaste(wxUpdateUIEvent
& event
);
531 void OnUpdateUndo(wxUpdateUIEvent
& event
);
532 void OnUpdateRedo(wxUpdateUIEvent
& event
);
533 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
534 void OnUpdateClear(wxUpdateUIEvent
& event
);
536 // Show a context menu for Rich Edit controls (the standard
537 // EDIT control has one already)
538 void OnContextMenu(wxContextMenuEvent
& event
);
543 void OnPaint(wxPaintEvent
& event
);
544 void OnEraseBackground(wxEraseEvent
& event
);
547 void OnLeftClick(wxMouseEvent
& event
);
550 void OnLeftUp(wxMouseEvent
& event
);
553 void OnMoveMouse(wxMouseEvent
& event
);
555 /// Left-double-click
556 void OnLeftDClick(wxMouseEvent
& event
);
559 void OnMiddleClick(wxMouseEvent
& event
);
562 void OnRightClick(wxMouseEvent
& event
);
565 void OnChar(wxKeyEvent
& event
);
568 void OnSize(wxSizeEvent
& event
);
570 /// Setting/losing focus
571 void OnSetFocus(wxFocusEvent
& event
);
572 void OnKillFocus(wxFocusEvent
& event
);
574 /// Idle-time processing
575 void OnIdle(wxIdleEvent
& event
);
578 void OnScroll(wxScrollWinEvent
& event
);
582 /// Set font, and also default attributes
583 virtual bool SetFont(const wxFont
& font
);
585 /// Set up scrollbars, e.g. after a resize
586 virtual void SetupScrollbars(bool atTop
= false);
588 /// Keyboard navigation
589 virtual bool KeyboardNavigate(int keyCode
, int flags
);
591 /// Paint the background
592 virtual void PaintBackground(wxDC
& dc
);
594 /// Recreate buffer bitmap if necessary
595 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
597 /// Set the selection
598 virtual void DoSetSelection(long from
, long to
, bool scrollCaret
= true);
601 virtual void DoWriteText(const wxString
& value
, bool selectionOnly
= true);
603 /// Send an update event
604 virtual bool SendUpdateEvent();
606 /// Init command event
607 void InitCommandEvent(wxCommandEvent
& event
) const;
609 /// do the window-specific processing after processing the update event
610 // (duplicated code from wxTextCtrlBase)
611 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
612 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
615 /// Should we inherit colours?
616 virtual bool ShouldInheritColours() const { return false; }
618 /// Position the caret
619 virtual void PositionCaret();
621 /// Extend the selection, returning true if the selection was
622 /// changed. Selections are in caret positions.
623 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
625 /// Scroll into view. This takes a _caret_ position.
626 virtual bool ScrollIntoView(long position
, int keyCode
);
628 /// The caret position is the character position just before the caret.
629 /// A value of -1 means the caret is at the start of the buffer.
630 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
631 long GetCaretPosition() const { return m_caretPosition
; }
633 /// Move caret one visual step forward: this may mean setting a flag
634 /// and keeping the same position if we're going from the end of one line
635 /// to the start of the next, which may be the exact same caret position.
636 void MoveCaretForward(long oldPosition
) ;
638 /// Move caret one visual step forward: this may mean setting a flag
639 /// and keeping the same position if we're going from the end of one line
640 /// to the start of the next, which may be the exact same caret position.
641 void MoveCaretBack(long oldPosition
) ;
643 /// Get the caret height and position for the given character position
644 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
646 /// Gets the line for the visible caret position. If the caret is
647 /// shown at the very end of the line, it means the next character is actually
648 /// on the following line. So let's get the line we're expecting to find
649 /// if this is the case.
650 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
652 /// Gets the command processor
653 wxCommandProcessor
* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
655 /// Delete content if there is a selection, e.g. when pressing a key.
656 /// Returns the new caret position in newPos, or leaves it if there
658 bool DeleteSelectedContent(long* newPos
= NULL
);
660 /// Transform logical to physical
661 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
663 /// Transform physical to logical
664 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
666 /// Finds the caret position for the next word. Direction
667 /// is 1 (forward) or -1 (backwards).
668 virtual long FindNextWordPosition(int direction
= 1) const;
670 /// Is the given position visible on the screen?
671 bool IsPositionVisible(long pos
) const;
673 /// Returns the first visible position in the current view
674 long GetFirstVisiblePosition() const;
676 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
677 WX_FORWARD_TO_SCROLL_HELPER()
683 virtual wxSize
DoGetBestSize() const ;
688 /// Allows nested Freeze/Thaw
692 wxBitmap m_bufferBitmap
;
695 wxRichTextBuffer m_buffer
;
700 wxMenu
* m_contextMenu
;
702 /// Caret position (1 less than the character position, so -1 is the
703 /// first caret position).
704 long m_caretPosition
;
706 /// Selection range in character positions. -2, -2 means no selection.
707 wxRichTextRange m_selectionRange
;
709 /// Anchor so we know how to extend the selection
710 /// It's a caret position since it's between two characters.
711 long m_selectionAnchor
;
716 /// Are we showing the caret position at the start of a line
717 /// instead of at the end of the previous one?
718 bool m_caretAtLineStart
;
720 /// Are we dragging a selection?
723 /// Start position for drag
726 /// Do we need full layout in idle?
727 bool m_fullLayoutRequired
;
728 wxLongLong m_fullLayoutTime
;
729 long m_fullLayoutSavedPosition
;
731 /// Threshold for doing delayed layout
732 long m_delayedLayoutThreshold
;
736 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
739 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent
: public wxNotifyEvent
742 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
743 : wxNotifyEvent(commandType
, winid
),
744 m_itemIndex(-1), m_flags(0)
747 wxRichTextEvent(const wxRichTextEvent
& event
)
748 : wxNotifyEvent(event
),
749 m_itemIndex(event
.m_itemIndex
), m_flags(event
.m_flags
)
752 int GetIndex() const { return m_itemIndex
; }
753 void SetIndex(int n
) { m_itemIndex
= n
; }
755 int GetFlags() const { return m_flags
; }
756 void SetFlags(int flags
) { m_flags
= flags
; }
758 virtual wxEvent
*Clone() const { return new wxRichTextEvent(*this); }
765 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent
)
769 * wxRichTextCtrl event macros
772 BEGIN_DECLARE_EVENT_TYPES()
773 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED
, 2600)
774 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED
, 2601)
775 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, 2602)
776 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, 2603)
777 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, 2604)
778 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, 2605)
779 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RETURN
, 2606)
780 END_DECLARE_EVENT_TYPES()
782 typedef void (wxEvtHandler::*wxRichTextEventFunction
)(wxRichTextEvent
&);
784 #define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
785 #define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
786 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
787 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
788 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
789 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
790 #define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
796 // _WX_RICHTEXTCTRL_H_