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 1
25 #define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
28 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
29 #include "wx/textctrl.h"
32 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition
;
41 #define wxRE_READONLY 0x0010
42 #define wxRE_MULTILINE 0x0020
47 #define wxRICHTEXT_SHIFT_DOWN 0x01
48 #define wxRICHTEXT_CTRL_DOWN 0x02
49 #define wxRICHTEXT_ALT_DOWN 0x04
54 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
55 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
56 #define wxRICHTEXT_DEFAULT_SPACING 3
57 #define wxRICHTEXT_DEFAULT_MARGIN 3
58 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
59 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
60 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
61 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
62 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
63 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
64 // Minimum buffer size before delayed layout kicks in
65 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
66 // Milliseconds before layout occurs after resize
67 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
70 * Forward declarations
74 * wxRichTextItem class declaration
77 // Drawing styles/states
78 #define wxRICHTEXT_SELECTED 0x01
79 #define wxRICHTEXT_TAGGED 0x02
80 // The control is focussed
81 #define wxRICHTEXT_FOCUSSED 0x04
82 // The item itself has the focus
83 #define wxRICHTEXT_IS_FOCUS 0x08
86 * wxRichTextCtrl class declaration
89 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl
:
90 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
91 public wxTextCtrlBase
, public wxScrollHelper
93 public wxScrolledWindow
96 DECLARE_CLASS( wxRichTextCtrl
)
103 wxRichTextCtrl( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
104 long style
= wxRE_MULTILINE
);
105 virtual ~wxRichTextCtrl( );
110 bool Create( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
111 long style
= wxRE_MULTILINE
);
113 /// Member initialisation
116 ///// wxTextCtrl compatibility
120 virtual wxString
GetValue() const;
121 virtual void SetValue(const wxString
& value
);
123 virtual wxString
GetRange(long from
, long to
) const;
125 virtual int GetLineLength(long lineNo
) const ;
126 virtual wxString
GetLineText(long lineNo
) const ;
127 virtual int GetNumberOfLines() const ;
129 virtual bool IsModified() const ;
130 virtual bool IsEditable() const ;
132 // more readable flag testing methods
133 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE
); }
134 bool IsMultiLine() const { return !IsSingleLine(); }
136 // If the return values from and to are the same, there is no selection.
137 virtual void GetSelection(long* from
, long* to
) const;
139 virtual wxString
GetStringSelection() const;
142 wxString
GetFilename() const { return m_filename
; }
145 void SetFilename(const wxString
& filename
) { m_filename
= filename
; }
147 /// Set the threshold in character positions for doing layout optimization during sizing
148 void SetDelayedLayoutThreshold(long threshold
) { m_delayedLayoutThreshold
= threshold
; }
150 /// Get the threshold in character positions for doing layout optimization during sizing
151 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold
; }
156 virtual void Clear();
157 virtual void Replace(long from
, long to
, const wxString
& value
);
158 virtual void Remove(long from
, long to
);
160 // load/save the controls contents from/to the file
161 virtual bool LoadFile(const wxString
& file
) { return LoadFile(file
, wxRICHTEXT_TYPE_ANY
); }
162 virtual bool LoadFile(const wxString
& file
, int type
);
163 virtual bool SaveFile(const wxString
& file
= wxEmptyString
) { return SaveFile(file
, wxRICHTEXT_TYPE_ANY
); }
164 virtual bool SaveFile(const wxString
& file
, int type
);
166 // sets/clears the dirty flag
167 virtual void MarkDirty();
168 virtual void DiscardEdits();
170 // set the max number of characters which may be entered in a single line
172 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
174 // writing text inserts it at the current position, appending always
175 // inserts it at the end
176 virtual void WriteText(const wxString
& text
);
177 virtual void AppendText(const wxString
& text
);
179 // text control under some platforms supports the text styles: these
180 // methods allow to apply the given text style to the given selection or to
181 // set/get the style which will be used for all appended text
182 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
183 virtual bool SetStyle(long start
, long end
, const wxTextAttrEx
& style
);
184 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
185 virtual bool GetStyle(long position
, wxTextAttr
& style
);
186 virtual bool GetStyle(long position
, wxTextAttrEx
& style
);
187 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
188 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
189 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
191 // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
192 virtual const wxTextAttrEx
& GetDefaultStyleEx() const;
193 virtual const wxTextAttr
& GetDefaultStyle() const;
195 // translate between the position (which is just an index in the text ctrl
196 // considering all its contents as a single strings) and (x, y) coordinates
197 // which represent column and line.
198 virtual long XYToPosition(long x
, long y
) const;
199 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
201 virtual void ShowPosition(long pos
);
203 // find the character at position given in pixels
205 // NB: pt is in device coords (not adjusted for the client area origin nor
207 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
208 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
210 wxTextCoord
*row
) const;
212 // Clipboard operations
215 virtual void Paste();
216 virtual void DeleteSelection();
218 virtual bool CanCopy() const;
219 virtual bool CanCut() const;
220 virtual bool CanPaste() const;
221 virtual bool CanDeleteSelection() const;
227 virtual bool CanUndo() const;
228 virtual bool CanRedo() const;
231 virtual void SetInsertionPoint(long pos
);
232 virtual void SetInsertionPointEnd();
233 virtual long GetInsertionPoint() const;
234 virtual wxTextPos
GetLastPosition() const;
236 virtual void SetSelection(long from
, long to
);
237 virtual void SelectAll();
238 virtual void SetEditable(bool editable
);
240 /// Call Freeze to prevent refresh
241 virtual void Freeze();
243 /// Call Thaw to refresh
246 /// Call Thaw to refresh
247 virtual bool IsFrozen() const { return m_freezeCount
> 0; }
249 virtual bool HasSelection() const;
251 ///// Functionality specific to wxRichTextCtrl
253 /// Write an image 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 wxImage
& image
, int bitmapType
= wxBITMAP_TYPE_PNG
);
257 /// Write a bitmap at the current insertion point. Supply optional type to use
258 /// for internal and file storage of the raw data.
259 virtual bool WriteImage(const wxBitmap
& bitmap
, int bitmapType
= wxBITMAP_TYPE_PNG
);
261 /// Load an image from file and write at the current insertion point.
262 virtual bool WriteImage(const wxString
& filename
, int bitmapType
);
264 /// Write an image block at the current insertion point.
265 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
);
267 /// Insert a newline (actually paragraph) at the current insertion point.
268 virtual bool Newline();
270 /// Set basic (overall) style
271 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { GetBuffer().SetBasicStyle(style
); }
272 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { GetBuffer().SetBasicStyle(style
); }
274 /// Get basic (overall) style
275 virtual const wxTextAttrEx
& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
277 /// Begin using a style
278 virtual bool BeginStyle(const wxTextAttrEx
& style
) { return GetBuffer().BeginStyle(style
); }
281 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
284 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
287 bool BeginBold() { return GetBuffer().BeginBold(); }
290 bool EndBold() { return GetBuffer().EndBold(); }
292 /// Begin using italic
293 bool BeginItalic() { return GetBuffer().BeginItalic(); }
296 bool EndItalic() { return GetBuffer().EndItalic(); }
298 /// Begin using underline
299 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
301 /// End using underline
302 bool EndUnderline() { return GetBuffer().EndUnderline(); }
304 /// Begin using point size
305 bool BeginFontSize(int pointSize
) { return GetBuffer().BeginFontSize(pointSize
); }
307 /// End using point size
308 bool EndFontSize() { return GetBuffer().EndFontSize(); }
310 /// Begin using this font
311 bool BeginFont(const wxFont
& font
) { return GetBuffer().BeginFont(font
); }
314 bool EndFont() { return GetBuffer().EndFont(); }
316 /// Begin using this colour
317 bool BeginTextColour(const wxColour
& colour
) { return GetBuffer().BeginTextColour(colour
); }
319 /// End using a colour
320 bool EndTextColour() { return GetBuffer().EndTextColour(); }
322 /// Begin using alignment
323 bool BeginAlignment(wxTextAttrAlignment alignment
) { return GetBuffer().BeginAlignment(alignment
); }
326 bool EndAlignment() { return GetBuffer().EndAlignment(); }
328 /// Begin left indent
329 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0) { return GetBuffer().BeginLeftIndent(leftIndent
, leftSubIndent
); }
332 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
334 /// Begin right indent
335 bool BeginRightIndent(int rightIndent
) { return GetBuffer().BeginRightIndent(rightIndent
); }
338 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
340 /// Begin paragraph spacing
341 bool BeginParagraphSpacing(int before
, int after
) { return GetBuffer().BeginParagraphSpacing(before
, after
); }
343 /// End paragraph spacing
344 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
346 /// Begin line spacing
347 bool BeginLineSpacing(int lineSpacing
) { return GetBuffer().BeginLineSpacing(lineSpacing
); }
350 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
352 /// Begin numbered bullet
353 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
354 { return GetBuffer().BeginNumberedBullet(bulletNumber
, leftIndent
, leftSubIndent
, bulletStyle
); }
356 /// End numbered bullet
357 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
359 /// Begin symbol bullet
360 bool BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
361 { return GetBuffer().BeginSymbolBullet(symbol
, leftIndent
, leftSubIndent
, bulletStyle
); }
363 /// End symbol bullet
364 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
366 /// Begin named character style
367 bool BeginCharacterStyle(const wxString
& characterStyle
) { return GetBuffer().BeginCharacterStyle(characterStyle
); }
369 /// End named character style
370 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
372 /// Begin named paragraph style
373 bool BeginParagraphStyle(const wxString
& paragraphStyle
) { return GetBuffer().BeginParagraphStyle(paragraphStyle
); }
375 /// End named character style
376 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
378 /// Sets the default style to the style under the cursor
379 bool SetDefaultStyleToCursorStyle();
381 /// Clear the selection
382 virtual void SelectNone();
384 /// Get/set the selection range in character positions. -1, -1 means no selection.
385 /// The range is in API convention, i.e. a single character selection is denoted
387 wxRichTextRange
GetSelectionRange() const;
388 void SetSelectionRange(const wxRichTextRange
& range
);
390 /// Get/set the selection range in character positions. -1, -1 means no selection.
391 /// The range is in internal format, i.e. a single character selection is denoted
393 const wxRichTextRange
& GetInternalSelectionRange() const { return m_selectionRange
; }
394 void SetInternalSelectionRange(const wxRichTextRange
& range
) { m_selectionRange
= range
; }
396 /// Add a new paragraph of text to the end of the buffer
397 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
400 virtual wxRichTextRange
AddImage(const wxImage
& image
);
402 /// Layout the buffer: which we must do before certain operations, such as
403 /// setting the caret position.
404 virtual bool LayoutContent(bool onlyVisibleRect
= false);
406 /// Move the caret to the given character position
407 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
410 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
413 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
416 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
419 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
421 /// Move to the end of the line
422 virtual bool MoveToLineEnd(int flags
= 0);
424 /// Move to the start of the line
425 virtual bool MoveToLineStart(int flags
= 0);
427 /// Move to the end of the paragraph
428 virtual bool MoveToParagraphEnd(int flags
= 0);
430 /// Move to the start of the paragraph
431 virtual bool MoveToParagraphStart(int flags
= 0);
433 /// Move to the start of the buffer
434 virtual bool MoveHome(int flags
= 0);
436 /// Move to the end of the buffer
437 virtual bool MoveEnd(int flags
= 0);
440 virtual bool PageUp(int noPages
= 1, int flags
= 0);
442 /// Move n pages down
443 virtual bool PageDown(int noPages
= 1, int flags
= 0);
445 /// Move n words left
446 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
448 /// Move n words right
449 virtual bool WordRight(int noPages
= 1, int flags
= 0);
451 /// Returns the buffer associated with the control.
452 wxRichTextBuffer
& GetBuffer() { return m_buffer
; }
453 const wxRichTextBuffer
& GetBuffer() const { return m_buffer
; }
455 /// Start batching undo history for commands.
456 virtual bool BeginBatchUndo(const wxString
& cmdName
) { return m_buffer
.BeginBatchUndo(cmdName
); }
458 /// End batching undo history for commands.
459 virtual bool EndBatchUndo() { return m_buffer
.EndBatchUndo(); }
461 /// Are we batching undo history for commands?
462 virtual bool BatchingUndo() const { return m_buffer
.BatchingUndo(); }
464 /// Start suppressing undo history for commands.
465 virtual bool BeginSuppressUndo() { return m_buffer
.BeginSuppressUndo(); }
467 /// End suppressing undo history for commands.
468 virtual bool EndSuppressUndo() { return m_buffer
.EndSuppressUndo(); }
470 /// Are we suppressing undo history for commands?
471 virtual bool SuppressingUndo() const { return m_buffer
.SuppressingUndo(); }
473 /// Test if this whole range has character attributes of the specified kind. If any
474 /// of the attributes are different within the range, the test fails. You
475 /// can use this to implement, for example, bold button updating. style must have
476 /// flags indicating which attributes are of interest.
477 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
479 return GetBuffer().HasCharacterAttributes(range
, style
);
481 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
483 return GetBuffer().HasCharacterAttributes(range
, style
);
486 /// Test if this whole range has paragraph attributes of the specified kind. If any
487 /// of the attributes are different within the range, the test fails. You
488 /// can use this to implement, for example, centering button updating. style must have
489 /// flags indicating which attributes are of interest.
490 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
492 return GetBuffer().HasParagraphAttributes(range
, style
);
494 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
496 return GetBuffer().HasParagraphAttributes(range
, style
);
499 /// Is all of the selection bold?
500 virtual bool IsSelectionBold();
502 /// Is all of the selection italics?
503 virtual bool IsSelectionItalics();
505 /// Is all of the selection underlined?
506 virtual bool IsSelectionUnderlined();
508 /// Is all of the selection aligned according to the specified flag?
509 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
511 /// Apply bold to the selection
512 virtual bool ApplyBoldToSelection();
514 /// Apply italic to the selection
515 virtual bool ApplyItalicToSelection();
517 /// Apply underline to the selection
518 virtual bool ApplyUnderlineToSelection();
520 /// Apply alignment to the selection
521 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
523 /// Apply a named style to the selection
524 virtual void ApplyStyle(wxRichTextStyleDefinition
* def
);
526 /// Set style sheet, if any.
527 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { GetBuffer().SetStyleSheet(styleSheet
); }
528 wxRichTextStyleSheet
* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
532 void Command(wxCommandEvent
& event
);
533 void OnDropFiles(wxDropFilesEvent
& event
);
535 void OnCut(wxCommandEvent
& event
);
536 void OnCopy(wxCommandEvent
& event
);
537 void OnPaste(wxCommandEvent
& event
);
538 void OnUndo(wxCommandEvent
& event
);
539 void OnRedo(wxCommandEvent
& event
);
540 void OnSelectAll(wxCommandEvent
& event
);
541 void OnClear(wxCommandEvent
& event
);
543 void OnUpdateCut(wxUpdateUIEvent
& event
);
544 void OnUpdateCopy(wxUpdateUIEvent
& event
);
545 void OnUpdatePaste(wxUpdateUIEvent
& event
);
546 void OnUpdateUndo(wxUpdateUIEvent
& event
);
547 void OnUpdateRedo(wxUpdateUIEvent
& event
);
548 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
549 void OnUpdateClear(wxUpdateUIEvent
& event
);
551 // Show a context menu for Rich Edit controls (the standard
552 // EDIT control has one already)
553 void OnContextMenu(wxContextMenuEvent
& event
);
558 void OnPaint(wxPaintEvent
& event
);
559 void OnEraseBackground(wxEraseEvent
& event
);
562 void OnLeftClick(wxMouseEvent
& event
);
565 void OnLeftUp(wxMouseEvent
& event
);
568 void OnMoveMouse(wxMouseEvent
& event
);
570 /// Left-double-click
571 void OnLeftDClick(wxMouseEvent
& event
);
574 void OnMiddleClick(wxMouseEvent
& event
);
577 void OnRightClick(wxMouseEvent
& event
);
580 void OnChar(wxKeyEvent
& event
);
583 void OnSize(wxSizeEvent
& event
);
585 /// Setting/losing focus
586 void OnSetFocus(wxFocusEvent
& event
);
587 void OnKillFocus(wxFocusEvent
& event
);
589 /// Idle-time processing
590 void OnIdle(wxIdleEvent
& event
);
593 void OnScroll(wxScrollWinEvent
& event
);
597 /// Set font, and also default attributes
598 virtual bool SetFont(const wxFont
& font
);
600 /// Set up scrollbars, e.g. after a resize
601 virtual void SetupScrollbars(bool atTop
= false);
603 /// Keyboard navigation
604 virtual bool KeyboardNavigate(int keyCode
, int flags
);
606 /// Paint the background
607 virtual void PaintBackground(wxDC
& dc
);
609 /// Recreate buffer bitmap if necessary
610 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
612 /// Set the selection
613 virtual void DoSetSelection(long from
, long to
, bool scrollCaret
= true);
616 virtual void DoWriteText(const wxString
& value
, bool selectionOnly
= true);
618 /// Send an update event
619 virtual bool SendUpdateEvent();
621 /// Init command event
622 void InitCommandEvent(wxCommandEvent
& event
) const;
624 /// do the window-specific processing after processing the update event
625 // (duplicated code from wxTextCtrlBase)
626 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
627 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
630 /// Should we inherit colours?
631 virtual bool ShouldInheritColours() const { return false; }
633 /// Position the caret
634 virtual void PositionCaret();
636 /// Extend the selection, returning true if the selection was
637 /// changed. Selections are in caret positions.
638 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
640 /// Scroll into view. This takes a _caret_ position.
641 virtual bool ScrollIntoView(long position
, int keyCode
);
643 /// The caret position is the character position just before the caret.
644 /// A value of -1 means the caret is at the start of the buffer.
645 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
646 long GetCaretPosition() const { return m_caretPosition
; }
648 /// The adjusted caret position is the character position adjusted to take
649 /// into account whether we're at the start of a paragraph, in which case
650 /// style information should be taken from the next position, not current one.
651 long GetAdjustedCaretPosition(long caretPos
) const;
653 /// Move caret one visual step forward: this may mean setting a flag
654 /// and keeping the same position if we're going from the end of one line
655 /// to the start of the next, which may be the exact same caret position.
656 void MoveCaretForward(long oldPosition
) ;
658 /// Move caret one visual step forward: this may mean setting a flag
659 /// and keeping the same position if we're going from the end of one line
660 /// to the start of the next, which may be the exact same caret position.
661 void MoveCaretBack(long oldPosition
) ;
663 /// Get the caret height and position for the given character position
664 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
666 /// Gets the line for the visible caret position. If the caret is
667 /// shown at the very end of the line, it means the next character is actually
668 /// on the following line. So let's get the line we're expecting to find
669 /// if this is the case.
670 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
672 /// Gets the command processor
673 wxCommandProcessor
* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
675 /// Delete content if there is a selection, e.g. when pressing a key.
676 /// Returns the new caret position in newPos, or leaves it if there
678 bool DeleteSelectedContent(long* newPos
= NULL
);
680 /// Transform logical to physical
681 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
683 /// Transform physical to logical
684 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
686 /// Finds the caret position for the next word. Direction
687 /// is 1 (forward) or -1 (backwards).
688 virtual long FindNextWordPosition(int direction
= 1) const;
690 /// Is the given position visible on the screen?
691 bool IsPositionVisible(long pos
) const;
693 /// Returns the first visible position in the current view
694 long GetFirstVisiblePosition() const;
696 /// Returns the caret position since the default formatting was changed. As
697 /// soon as this position changes, we no longer reflect the default style
698 /// in the UI. A value of -2 means that we should only reflect the style of the
699 /// content under the caret.
700 long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle
; }
702 /// Set the caret position for the default style that the user is selecting.
703 void SetCaretPositionForDefaultStyle(long pos
) { m_caretPositionForDefaultStyle
= pos
; }
705 /// Should the UI reflect the default style chosen by the user, rather than the style under
707 bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle
!= -2; }
709 /// Convenience function that tells the control to start reflecting the default
710 /// style, since the user is changing it.
711 void SetAndShowDefaultStyle(const wxRichTextAttr
& attr
)
713 SetDefaultStyle(attr
);
714 SetCaretPositionForDefaultStyle(GetCaretPosition());
717 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
718 WX_FORWARD_TO_SCROLL_HELPER()
724 virtual wxSize
DoGetBestSize() const ;
729 /// Allows nested Freeze/Thaw
733 wxBitmap m_bufferBitmap
;
736 wxRichTextBuffer m_buffer
;
741 wxMenu
* m_contextMenu
;
743 /// Caret position (1 less than the character position, so -1 is the
744 /// first caret position).
745 long m_caretPosition
;
747 /// Caret position when the default formatting has been changed. As
748 /// soon as this position changes, we no longer reflect the default style
750 long m_caretPositionForDefaultStyle
;
752 /// Selection range in character positions. -2, -2 means no selection.
753 wxRichTextRange m_selectionRange
;
755 /// Anchor so we know how to extend the selection
756 /// It's a caret position since it's between two characters.
757 long m_selectionAnchor
;
762 /// Are we showing the caret position at the start of a line
763 /// instead of at the end of the previous one?
764 bool m_caretAtLineStart
;
766 /// Are we dragging a selection?
769 /// Start position for drag
772 /// Do we need full layout in idle?
773 bool m_fullLayoutRequired
;
774 wxLongLong m_fullLayoutTime
;
775 long m_fullLayoutSavedPosition
;
777 /// Threshold for doing delayed layout
778 long m_delayedLayoutThreshold
;
782 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
785 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent
: public wxNotifyEvent
788 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
789 : wxNotifyEvent(commandType
, winid
),
790 m_itemIndex(-1), m_flags(0)
793 wxRichTextEvent(const wxRichTextEvent
& event
)
794 : wxNotifyEvent(event
),
795 m_itemIndex(event
.m_itemIndex
), m_flags(event
.m_flags
)
798 int GetIndex() const { return m_itemIndex
; }
799 void SetIndex(int n
) { m_itemIndex
= n
; }
801 int GetFlags() const { return m_flags
; }
802 void SetFlags(int flags
) { m_flags
= flags
; }
804 virtual wxEvent
*Clone() const { return new wxRichTextEvent(*this); }
811 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent
)
815 * wxRichTextCtrl event macros
818 BEGIN_DECLARE_EVENT_TYPES()
819 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED
, 2600)
820 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED
, 2601)
821 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, 2602)
822 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, 2603)
823 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, 2604)
824 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, 2605)
825 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RETURN
, 2606)
826 END_DECLARE_EVENT_TYPES()
828 typedef void (wxEvtHandler::*wxRichTextEventFunction
)(wxRichTextEvent
&);
830 #define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
831 #define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
832 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
833 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
834 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
835 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
836 #define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
842 // _WX_RICHTEXTCTRL_H_