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/textctrl.h"
19 #include "wx/scrolwin.h"
22 #include "wx/richtext/richtextbuffer.h"
24 #if wxCHECK_VERSION(2,7,0)
25 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
27 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
37 #define wxRE_READONLY 0x0010
38 #define wxRE_MULTILINE 0x0020
43 #define wxRICHTEXT_SHIFT_DOWN 0x01
44 #define wxRICHTEXT_CTRL_DOWN 0x02
45 #define wxRICHTEXT_ALT_DOWN 0x04
50 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
51 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
52 #define wxRICHTEXT_DEFAULT_SPACING 3
53 #define wxRICHTEXT_DEFAULT_MARGIN 3
54 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
55 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
56 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
57 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
58 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
59 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
60 // Minimum buffer size before delayed layout kicks in
61 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
62 // Milliseconds before layout occurs after resize
63 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
66 * Forward declarations
70 * wxRichTextItem class declaration
73 // Drawing styles/states
74 #define wxRICHTEXT_SELECTED 0x01
75 #define wxRICHTEXT_TAGGED 0x02
76 // The control is focussed
77 #define wxRICHTEXT_FOCUSSED 0x04
78 // The item itself has the focus
79 #define wxRICHTEXT_IS_FOCUS 0x08
82 * wxRichTextCtrl class declaration
85 class WXDLLIMPEXP_ADV wxRichTextCtrl
:
86 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
87 public wxTextCtrlBase
, wxScrollHelper
89 public wxScrolledWindow
92 DECLARE_CLASS( wxRichTextCtrl
)
99 wxRichTextCtrl( wxWindow
* parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
100 long style
= wxRE_MULTILINE
);
106 bool Create( wxWindow
* parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
107 long style
= wxRE_MULTILINE
);
109 /// Member initialisation
112 ///// wxTextCtrl compatibility
116 virtual wxString
GetValue() const;
117 virtual void SetValue(const wxString
& value
);
119 virtual wxString
GetRange(long from
, long to
) const;
121 virtual int GetLineLength(long lineNo
) const ;
122 virtual wxString
GetLineText(long lineNo
) const ;
123 virtual int GetNumberOfLines() const ;
125 virtual bool IsModified() const ;
126 virtual bool IsEditable() const ;
128 // more readable flag testing methods
129 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE
); }
130 bool IsMultiLine() const { return !IsSingleLine(); }
132 // If the return values from and to are the same, there is no selection.
133 virtual void GetSelection(long* from
, long* to
) const;
135 virtual wxString
GetStringSelection() const;
138 wxString
GetFilename() const { return m_filename
; }
141 void SetFilename(const wxString
& filename
) { m_filename
= filename
; }
143 /// Set the threshold in character positions for doing layout optimization during sizing
144 void SetDelayedLayoutThreshold(long threshold
) { m_delayedLayoutThreshold
= threshold
; }
146 /// Get the threshold in character positions for doing layout optimization during sizing
147 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold
; }
152 virtual void Clear();
153 virtual void Replace(long from
, long to
, const wxString
& value
);
154 virtual void Remove(long from
, long to
);
156 // load/save the controls contents from/to the file
157 virtual bool LoadFile(const wxString
& file
, int type
= wxRICHTEXT_TYPE_ANY
);
158 virtual bool SaveFile(const wxString
& file
= wxEmptyString
, int type
= wxRICHTEXT_TYPE_ANY
);
160 // sets/clears the dirty flag
161 virtual void MarkDirty();
162 virtual void DiscardEdits();
164 // set the max number of characters which may be entered in a single line
166 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
168 // writing text inserts it at the current position, appending always
169 // inserts it at the end
170 virtual void WriteText(const wxString
& text
);
171 virtual void AppendText(const wxString
& text
);
173 // text control under some platforms supports the text styles: these
174 // methods allow to apply the given text style to the given selection or to
175 // set/get the style which will be used for all appended text
176 virtual bool SetStyle(long start
, long end
, const wxTextAttrEx
& style
);
177 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
178 virtual bool GetStyle(long position
, wxTextAttrEx
& style
) const;
179 virtual bool GetStyle(long position
, wxRichTextAttr
& style
) const;
180 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
182 // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
183 virtual const wxTextAttrEx
& GetDefaultStyleEx() const;
185 // translate between the position (which is just an index in the text ctrl
186 // considering all its contents as a single strings) and (x, y) coordinates
187 // which represent column and line.
188 virtual long XYToPosition(long x
, long y
) const;
189 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
191 virtual void ShowPosition(long pos
);
193 // find the character at position given in pixels
195 // NB: pt is in device coords (not adjusted for the client area origin nor
197 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
198 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
200 wxTextCoord
*row
) const;
202 // Clipboard operations
205 virtual void Paste();
206 virtual void DeleteSelection();
208 virtual bool CanCopy() const;
209 virtual bool CanCut() const;
210 virtual bool CanPaste() const;
211 virtual bool CanDeleteSelection() const;
217 virtual bool CanUndo() const;
218 virtual bool CanRedo() const;
221 virtual void SetInsertionPoint(long pos
);
222 virtual void SetInsertionPointEnd();
223 virtual long GetInsertionPoint() const;
224 virtual wxTextPos
GetLastPosition() const;
226 virtual void SetSelection(long from
, long to
);
227 virtual void SelectAll();
228 virtual void SetEditable(bool editable
);
230 /// Call Freeze to prevent refresh
231 virtual void Freeze();
233 /// Call Thaw to refresh
236 /// Call Thaw to refresh
237 virtual bool IsFrozen() const { return m_freezeCount
> 0; }
239 virtual bool HasSelection() const;
241 ///// Functionality specific to wxRichTextCtrl
243 /// Write an image at the current insertion point. Supply optional type to use
244 /// for internal and file storage of the raw data.
245 virtual bool WriteImage(const wxImage
& image
, int bitmapType
= wxBITMAP_TYPE_PNG
);
247 /// Write a bitmap at the current insertion point. Supply optional type to use
248 /// for internal and file storage of the raw data.
249 virtual bool WriteImage(const wxBitmap
& bitmap
, int bitmapType
= wxBITMAP_TYPE_PNG
);
251 /// Load an image from file and write at the current insertion point.
252 virtual bool WriteImage(const wxString
& filename
, int bitmapType
);
254 /// Write an image block at the current insertion point.
255 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
);
257 /// Insert a newline (actually paragraph) at the current insertion point.
258 virtual bool Newline();
260 /// Set basic (overall) style
261 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { GetBuffer().SetBasicStyle(style
); }
262 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { GetBuffer().SetBasicStyle(style
); }
264 /// Get basic (overall) style
265 virtual const wxTextAttrEx
& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
267 /// Begin using a style
268 virtual bool BeginStyle(const wxTextAttrEx
& style
) { return GetBuffer().BeginStyle(style
); }
271 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
274 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
277 bool BeginBold() { return GetBuffer().BeginBold(); }
280 bool EndBold() { return GetBuffer().EndBold(); }
282 /// Begin using italic
283 bool BeginItalic() { return GetBuffer().BeginItalic(); }
286 bool EndItalic() { return GetBuffer().EndItalic(); }
288 /// Begin using underline
289 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
291 /// End using underline
292 bool EndUnderline() { return GetBuffer().EndUnderline(); }
294 /// Begin using point size
295 bool BeginFontSize(int pointSize
) { return GetBuffer().BeginFontSize(pointSize
); }
297 /// End using point size
298 bool EndFontSize() { return GetBuffer().EndFontSize(); }
300 /// Begin using this font
301 bool BeginFont(const wxFont
& font
) { return GetBuffer().BeginFont(font
); }
304 bool EndFont() { return GetBuffer().EndFont(); }
306 /// Begin using this colour
307 bool BeginTextColour(const wxColour
& colour
) { return GetBuffer().BeginTextColour(colour
); }
309 /// End using a colour
310 bool EndTextColour() { return GetBuffer().EndTextColour(); }
312 /// Begin using alignment
313 bool BeginAlignment(wxTextAttrAlignment alignment
) { return GetBuffer().BeginAlignment(alignment
); }
316 bool EndAlignment() { return GetBuffer().EndAlignment(); }
318 /// Begin left indent
319 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0) { return GetBuffer().BeginLeftIndent(leftIndent
, leftSubIndent
); }
322 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
324 /// Begin right indent
325 bool BeginRightIndent(int rightIndent
) { return GetBuffer().BeginRightIndent(rightIndent
); }
328 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
330 /// Begin paragraph spacing
331 bool BeginParagraphSpacing(int before
, int after
) { return GetBuffer().BeginParagraphSpacing(before
, after
); }
333 /// End paragraph spacing
334 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
336 /// Begin line spacing
337 bool BeginLineSpacing(int lineSpacing
) { return GetBuffer().BeginLineSpacing(lineSpacing
); }
340 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
342 /// Begin numbered bullet
343 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
344 { return GetBuffer().BeginNumberedBullet(bulletNumber
, leftIndent
, leftSubIndent
, bulletStyle
); }
346 /// End numbered bullet
347 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
349 /// Begin symbol bullet
350 bool BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
351 { return GetBuffer().BeginSymbolBullet(symbol
, leftIndent
, leftSubIndent
, bulletStyle
); }
353 /// End symbol bullet
354 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
356 /// Begin named character style
357 bool BeginCharacterStyle(const wxString
& characterStyle
) { return GetBuffer().BeginCharacterStyle(characterStyle
); }
359 /// End named character style
360 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
362 /// Begin named paragraph style
363 bool BeginParagraphStyle(const wxString
& paragraphStyle
) { return GetBuffer().BeginParagraphStyle(paragraphStyle
); }
365 /// End named character style
366 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
368 /// Sets the default style to the style under the cursor
369 bool SetDefaultStyleToCursorStyle();
371 /// Clear the selection
372 virtual void SelectNone();
374 /// Get/set the selection range in character positions. -1, -1 means no selection.
375 const wxRichTextRange
& GetSelectionRange() const { return m_selectionRange
; }
376 void SetSelectionRange(const wxRichTextRange
& range
) { m_selectionRange
= range
; }
378 /// Add a new paragraph of text to the end of the buffer
379 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
382 virtual wxRichTextRange
AddImage(const wxImage
& image
);
384 /// Layout the buffer: which we must do before certain operations, such as
385 /// setting the caret position.
386 virtual bool LayoutContent(bool onlyVisibleRect
= false);
388 /// Move the caret to the given character position
389 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
392 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
395 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
398 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
401 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
403 /// Move to the end of the line
404 virtual bool MoveToLineEnd(int flags
= 0);
406 /// Move to the start of the line
407 virtual bool MoveToLineStart(int flags
= 0);
409 /// Move to the end of the paragraph
410 virtual bool MoveToParagraphEnd(int flags
= 0);
412 /// Move to the start of the paragraph
413 virtual bool MoveToParagraphStart(int flags
= 0);
415 /// Move to the start of the buffer
416 virtual bool MoveHome(int flags
= 0);
418 /// Move to the end of the buffer
419 virtual bool MoveEnd(int flags
= 0);
422 virtual bool PageUp(int noPages
= 1, int flags
= 0);
424 /// Move n pages down
425 virtual bool PageDown(int noPages
= 1, int flags
= 0);
427 /// Move n words left
428 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
430 /// Move n words right
431 virtual bool WordRight(int noPages
= 1, int flags
= 0);
433 /// Returns the buffer associated with the control.
434 wxRichTextBuffer
& GetBuffer() { return m_buffer
; }
435 const wxRichTextBuffer
& GetBuffer() const { return m_buffer
; }
437 /// Start batching undo history for commands.
438 virtual bool BeginBatchUndo(const wxString
& cmdName
) { return m_buffer
.BeginBatchUndo(cmdName
); }
440 /// End batching undo history for commands.
441 virtual bool EndBatchUndo() { return m_buffer
.EndBatchUndo(); }
443 /// Are we batching undo history for commands?
444 virtual bool BatchingUndo() const { return m_buffer
.BatchingUndo(); }
446 /// Start suppressing undo history for commands.
447 virtual bool BeginSuppressUndo() { return m_buffer
.BeginSuppressUndo(); }
449 /// End suppressing undo history for commands.
450 virtual bool EndSuppressUndo() { return m_buffer
.EndSuppressUndo(); }
452 /// Are we suppressing undo history for commands?
453 virtual bool SuppressingUndo() const { return m_buffer
.SuppressingUndo(); }
455 /// Test if this whole range has character attributes of the specified kind. If any
456 /// of the attributes are different within the range, the test fails. You
457 /// can use this to implement, for example, bold button updating. style must have
458 /// flags indicating which attributes are of interest.
459 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
461 return GetBuffer().HasCharacterAttributes(range
, style
);
463 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
465 return GetBuffer().HasCharacterAttributes(range
, style
);
468 /// Test if this whole range has paragraph attributes of the specified kind. If any
469 /// of the attributes are different within the range, the test fails. You
470 /// can use this to implement, for example, centering button updating. style must have
471 /// flags indicating which attributes are of interest.
472 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
474 return GetBuffer().HasParagraphAttributes(range
, style
);
476 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
478 return GetBuffer().HasParagraphAttributes(range
, style
);
481 /// Is all of the selection bold?
482 virtual bool IsSelectionBold() const;
484 /// Is all of the selection italics?
485 virtual bool IsSelectionItalics() const;
487 /// Is all of the selection underlined?
488 virtual bool IsSelectionUnderlined() const;
490 /// Is all of the selection aligned according to the specified flag?
491 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
) const;
493 /// Apply bold to the selection
494 virtual bool ApplyBoldToSelection();
496 /// Apply italic to the selection
497 virtual bool ApplyItalicToSelection();
499 /// Apply underline to the selection
500 virtual bool ApplyUnderlineToSelection();
502 /// Apply alignment to the selection
503 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
505 /// Set style sheet, if any.
506 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { GetBuffer().SetStyleSheet(styleSheet
); }
507 wxRichTextStyleSheet
* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
511 void Command(wxCommandEvent
& event
);
512 void OnDropFiles(wxDropFilesEvent
& event
);
514 void OnCut(wxCommandEvent
& event
);
515 void OnCopy(wxCommandEvent
& event
);
516 void OnPaste(wxCommandEvent
& event
);
517 void OnUndo(wxCommandEvent
& event
);
518 void OnRedo(wxCommandEvent
& event
);
519 void OnSelectAll(wxCommandEvent
& event
);
520 void OnClear(wxCommandEvent
& event
);
522 void OnUpdateCut(wxUpdateUIEvent
& event
);
523 void OnUpdateCopy(wxUpdateUIEvent
& event
);
524 void OnUpdatePaste(wxUpdateUIEvent
& event
);
525 void OnUpdateUndo(wxUpdateUIEvent
& event
);
526 void OnUpdateRedo(wxUpdateUIEvent
& event
);
527 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
528 void OnUpdateClear(wxUpdateUIEvent
& event
);
530 // Show a context menu for Rich Edit controls (the standard
531 // EDIT control has one already)
532 void OnContextMenu(wxContextMenuEvent
& event
);
537 void OnPaint(wxPaintEvent
& event
);
538 void OnEraseBackground(wxEraseEvent
& event
);
541 void OnLeftClick(wxMouseEvent
& event
);
544 void OnLeftUp(wxMouseEvent
& event
);
547 void OnMoveMouse(wxMouseEvent
& event
);
549 /// Left-double-click
550 void OnLeftDClick(wxMouseEvent
& event
);
553 void OnMiddleClick(wxMouseEvent
& event
);
556 void OnRightClick(wxMouseEvent
& event
);
559 void OnChar(wxKeyEvent
& event
);
562 void OnSize(wxSizeEvent
& event
);
564 /// Setting/losing focus
565 void OnSetFocus(wxFocusEvent
& event
);
566 void OnKillFocus(wxFocusEvent
& event
);
568 /// Idle-time processing
569 void OnIdle(wxIdleEvent
& event
);
572 void OnScroll(wxScrollWinEvent
& event
);
576 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
577 WX_FORWARD_TO_SCROLL_HELPER()
580 /// Set font, and also default attributes
581 virtual bool SetFont(const wxFont
& font
);
583 /// Set up scrollbars, e.g. after a resize
584 virtual void SetupScrollbars(bool atTop
= false);
586 /// Keyboard navigation
587 virtual bool KeyboardNavigate(int keyCode
, int flags
);
589 /// Paint the background
590 virtual void PaintBackground(wxDC
& dc
);
592 /// Recreate buffer bitmap if necessary
593 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
595 /// Set the selection
596 virtual void DoSetSelection(long from
, long to
, bool scrollCaret
= true);
599 virtual void DoWriteText(const wxString
& value
, bool selectionOnly
= true);
601 /// Send an update event
602 virtual bool SendUpdateEvent();
604 /// Init command event
605 void InitCommandEvent(wxCommandEvent
& event
) const;
607 /// do the window-specific processing after processing the update event
608 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
610 /// Should we inherit colours?
611 virtual bool ShouldInheritColours() const { return false; }
613 /// Position the caret
614 virtual void PositionCaret();
616 /// Extend the selection, returning true if the selection was
617 /// changed. Selections are in caret positions.
618 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
620 /// Scroll into view. This takes a _caret_ position.
621 virtual bool ScrollIntoView(long position
, int keyCode
);
623 /// The caret position is the character position just before the caret.
624 /// A value of -1 means the caret is at the start of the buffer.
625 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
626 long GetCaretPosition() const { return m_caretPosition
; }
628 /// Move caret one visual step forward: this may mean setting a flag
629 /// and keeping the same position if we're going from the end of one line
630 /// to the start of the next, which may be the exact same caret position.
631 void MoveCaretForward(long oldPosition
) ;
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 MoveCaretBack(long oldPosition
) ;
638 /// Get the caret height and position for the given character position
639 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
641 /// Gets the line for the visible caret position. If the caret is
642 /// shown at the very end of the line, it means the next character is actually
643 /// on the following line. So let's get the line we're expecting to find
644 /// if this is the case.
645 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
647 /// Gets the command processor
648 wxCommandProcessor
* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
650 /// Delete content if there is a selection, e.g. when pressing a key.
651 /// Returns the new caret position in newPos, or leaves it if there
653 bool DeleteSelectedContent(long* newPos
= NULL
);
655 /// Transform logical to physical
656 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
658 /// Transform physical to logical
659 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
661 /// Finds the caret position for the next word. Direction
662 /// is 1 (forward) or -1 (backwards).
663 virtual long FindNextWordPosition(int direction
= 1) const;
665 /// Is the given position visible on the screen?
666 bool IsPositionVisible(long pos
) const;
668 /// Returns the first visible position in the current view
669 long GetFirstVisiblePosition() const;
673 virtual wxSize
DoGetBestSize() const ;
678 /// Allows nested Freeze/Thaw
682 wxBitmap m_bufferBitmap
;
685 wxRichTextBuffer m_buffer
;
690 wxMenu
* m_contextMenu
;
692 /// Caret position (1 less than the character position, so -1 is the
693 /// first caret position).
694 long m_caretPosition
;
696 /// Selection range in character positions. -2, -2 means no selection.
697 wxRichTextRange m_selectionRange
;
699 /// Anchor so we know how to extend the selection
700 /// It's a caret position since it's between two characters.
701 long m_selectionAnchor
;
706 /// Are we showing the caret position at the start of a line
707 /// instead of at the end of the previous one?
708 bool m_caretAtLineStart
;
710 /// Are we dragging a selection?
713 /// Start position for drag
716 /// Do we need full layout in idle?
717 bool m_fullLayoutRequired
;
718 wxLongLong m_fullLayoutTime
;
719 long m_fullLayoutSavedPosition
;
721 /// Threshold for doing delayed layout
722 long m_delayedLayoutThreshold
;
726 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
729 class WXDLLIMPEXP_ADV wxRichTextEvent
: public wxNotifyEvent
732 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
733 : wxNotifyEvent(commandType
, winid
),
734 m_itemIndex(-1), m_flags(0)
737 wxRichTextEvent(const wxRichTextEvent
& event
)
738 : wxNotifyEvent(event
),
739 m_itemIndex(event
.m_itemIndex
), m_flags(event
.m_flags
)
742 int GetIndex() const { return m_itemIndex
; }
743 void SetIndex(int n
) { m_itemIndex
= n
; }
745 int GetFlags() const { return m_flags
; }
746 void SetFlags(int flags
) { m_flags
= flags
; }
748 virtual wxEvent
*Clone() const { return new wxRichTextEvent(*this); }
755 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent
)
759 * wxRichTextCtrl event macros
762 BEGIN_DECLARE_EVENT_TYPES()
763 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED
, 2600)
764 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED
, 2601)
765 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, 2602)
766 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, 2603)
767 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, 2604)
768 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, 2605)
769 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RETURN
, 2606)
770 END_DECLARE_EVENT_TYPES()
772 typedef void (wxEvtHandler::*wxRichTextEventFunction
)(wxRichTextEvent
&);
774 #define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
775 #define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
776 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
777 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
778 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
779 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
780 #define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
786 // _WX_RICHTEXTCTRL_H_