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 #if !defined(__WXGTK__) && !defined(__WXMAC__)
33 #define wxRICHTEXT_BUFFERED_PAINTING 1
35 #define wxRICHTEXT_BUFFERED_PAINTING 0
38 class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition
;
47 #define wxRE_READONLY 0x0010
48 #define wxRE_MULTILINE 0x0020
53 #define wxRICHTEXT_SHIFT_DOWN 0x01
54 #define wxRICHTEXT_CTRL_DOWN 0x02
55 #define wxRICHTEXT_ALT_DOWN 0x04
60 #define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
61 #define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)
62 #define wxRICHTEXT_DEFAULT_SPACING 3
63 #define wxRICHTEXT_DEFAULT_MARGIN 3
64 #define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
65 #define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
66 #define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
67 #define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
68 #define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
69 #define wxRICHTEXT_DEFAULT_CARET_WIDTH 2
70 // Minimum buffer size before delayed layout kicks in
71 #define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000
72 // Milliseconds before layout occurs after resize
73 #define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
76 * Forward declarations
80 * wxRichTextItem class declaration
83 // Drawing styles/states
84 #define wxRICHTEXT_SELECTED 0x01
85 #define wxRICHTEXT_TAGGED 0x02
86 // The control is focussed
87 #define wxRICHTEXT_FOCUSSED 0x04
88 // The item itself has the focus
89 #define wxRICHTEXT_IS_FOCUS 0x08
92 * wxRichTextCtrl class declaration
95 class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl
:
96 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
97 public wxTextCtrlBase
, public wxScrollHelper
99 public wxScrolledWindow
102 DECLARE_CLASS( wxRichTextCtrl
)
103 DECLARE_EVENT_TABLE()
109 wxRichTextCtrl( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
110 long style
= wxRE_MULTILINE
);
111 virtual ~wxRichTextCtrl( );
116 bool Create( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
117 long style
= wxRE_MULTILINE
);
119 /// Member initialisation
122 ///// wxTextCtrl compatibility
126 virtual wxString
GetValue() const;
127 virtual void SetValue(const wxString
& value
);
129 virtual wxString
GetRange(long from
, long to
) const;
131 virtual int GetLineLength(long lineNo
) const ;
132 virtual wxString
GetLineText(long lineNo
) const ;
133 virtual int GetNumberOfLines() const ;
135 virtual bool IsModified() const ;
136 virtual bool IsEditable() const ;
138 // more readable flag testing methods
139 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE
); }
140 bool IsMultiLine() const { return !IsSingleLine(); }
142 // If the return values from and to are the same, there is no selection.
143 virtual void GetSelection(long* from
, long* to
) const;
145 virtual wxString
GetStringSelection() const;
148 wxString
GetFilename() const { return m_filename
; }
151 void SetFilename(const wxString
& filename
) { m_filename
= filename
; }
153 /// Set the threshold in character positions for doing layout optimization during sizing
154 void SetDelayedLayoutThreshold(long threshold
) { m_delayedLayoutThreshold
= threshold
; }
156 /// Get the threshold in character positions for doing layout optimization during sizing
157 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold
; }
162 virtual void Clear();
163 virtual void Replace(long from
, long to
, const wxString
& value
);
164 virtual void Remove(long from
, long to
);
166 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
167 bool LoadFile(const wxString
& file
, int fileType
= wxRICHTEXT_TYPE_ANY
);
168 bool SaveFile(const wxString
& file
= wxEmptyString
, int fileType
= wxRICHTEXT_TYPE_ANY
);
171 // load/save the controls contents from/to the file
172 virtual bool DoLoadFile(const wxString
& file
, int fileType
);
173 virtual bool DoSaveFile(const wxString
& file
= wxEmptyString
, int fileType
= wxRICHTEXT_TYPE_ANY
);
175 // sets/clears the dirty flag
176 virtual void MarkDirty();
177 virtual void DiscardEdits();
179 // set the max number of characters which may be entered in a single line
181 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
183 // writing text inserts it at the current position, appending always
184 // inserts it at the end
185 virtual void WriteText(const wxString
& text
);
186 virtual void AppendText(const wxString
& text
);
188 // text control under some platforms supports the text styles: these
189 // methods allow to apply the given text style to the given selection or to
190 // set/get the style which will be used for all appended text
191 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
192 virtual bool SetStyle(long start
, long end
, const wxTextAttrEx
& style
);
193 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
194 virtual bool GetStyle(long position
, wxTextAttr
& style
);
195 virtual bool GetStyle(long position
, wxTextAttrEx
& style
);
196 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
198 // extended style setting operation with flags including:
199 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
200 // see richtextbuffer.h for more details.
201 virtual bool SetStyleEx(long start
, long end
, const wxTextAttrEx
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
202 virtual bool SetStyleEx(const wxRichTextRange
& range
, const wxTextAttrEx
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
203 virtual bool SetStyleEx(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
205 /// Get the content (uncombined) attributes for this position.
206 virtual bool GetUncombinedStyle(long position
, wxTextAttr
& style
);
207 virtual bool GetUncombinedStyle(long position
, wxTextAttrEx
& style
);
208 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
210 virtual bool SetDefaultStyle(const wxTextAttrEx
& style
);
211 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
213 // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
214 virtual const wxTextAttrEx
& GetDefaultStyleEx() const;
215 virtual const wxTextAttr
& GetDefaultStyle() const;
217 // translate between the position (which is just an index in the text ctrl
218 // considering all its contents as a single strings) and (x, y) coordinates
219 // which represent column and line.
220 virtual long XYToPosition(long x
, long y
) const;
221 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
223 virtual void ShowPosition(long pos
);
225 // find the character at position given in pixels
227 // NB: pt is in device coords (not adjusted for the client area origin nor
229 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
230 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
232 wxTextCoord
*row
) const;
234 // Clipboard operations
237 virtual void Paste();
238 virtual void DeleteSelection();
240 virtual bool CanCopy() const;
241 virtual bool CanCut() const;
242 virtual bool CanPaste() const;
243 virtual bool CanDeleteSelection() const;
249 virtual bool CanUndo() const;
250 virtual bool CanRedo() const;
253 virtual void SetInsertionPoint(long pos
);
254 virtual void SetInsertionPointEnd();
255 virtual long GetInsertionPoint() const;
256 virtual wxTextPos
GetLastPosition() const;
258 virtual void SetSelection(long from
, long to
);
259 virtual void SelectAll();
260 virtual void SetEditable(bool editable
);
262 /// Call Freeze to prevent refresh
263 virtual void Freeze();
265 /// Call Thaw to refresh
268 /// Call Thaw to refresh
269 virtual bool IsFrozen() const { return m_freezeCount
> 0; }
271 virtual bool HasSelection() const;
273 ///// Functionality specific to wxRichTextCtrl
275 /// Write an image at the current insertion point. Supply optional type to use
276 /// for internal and file storage of the raw data.
277 virtual bool WriteImage(const wxImage
& image
, int bitmapType
= wxBITMAP_TYPE_PNG
);
279 /// Write a bitmap at the current insertion point. Supply optional type to use
280 /// for internal and file storage of the raw data.
281 virtual bool WriteImage(const wxBitmap
& bitmap
, int bitmapType
= wxBITMAP_TYPE_PNG
);
283 /// Load an image from file and write at the current insertion point.
284 virtual bool WriteImage(const wxString
& filename
, int bitmapType
);
286 /// Write an image block at the current insertion point.
287 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
);
289 /// Insert a newline (actually paragraph) at the current insertion point.
290 virtual bool Newline();
292 /// Set basic (overall) style
293 virtual void SetBasicStyle(const wxTextAttrEx
& style
) { GetBuffer().SetBasicStyle(style
); }
294 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { GetBuffer().SetBasicStyle(style
); }
296 /// Get basic (overall) style
297 virtual const wxTextAttrEx
& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
299 /// Begin using a style
300 virtual bool BeginStyle(const wxTextAttrEx
& style
) { return GetBuffer().BeginStyle(style
); }
303 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
306 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
309 bool BeginBold() { return GetBuffer().BeginBold(); }
312 bool EndBold() { return GetBuffer().EndBold(); }
314 /// Begin using italic
315 bool BeginItalic() { return GetBuffer().BeginItalic(); }
318 bool EndItalic() { return GetBuffer().EndItalic(); }
320 /// Begin using underline
321 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
323 /// End using underline
324 bool EndUnderline() { return GetBuffer().EndUnderline(); }
326 /// Begin using point size
327 bool BeginFontSize(int pointSize
) { return GetBuffer().BeginFontSize(pointSize
); }
329 /// End using point size
330 bool EndFontSize() { return GetBuffer().EndFontSize(); }
332 /// Begin using this font
333 bool BeginFont(const wxFont
& font
) { return GetBuffer().BeginFont(font
); }
336 bool EndFont() { return GetBuffer().EndFont(); }
338 /// Begin using this colour
339 bool BeginTextColour(const wxColour
& colour
) { return GetBuffer().BeginTextColour(colour
); }
341 /// End using a colour
342 bool EndTextColour() { return GetBuffer().EndTextColour(); }
344 /// Begin using alignment
345 bool BeginAlignment(wxTextAttrAlignment alignment
) { return GetBuffer().BeginAlignment(alignment
); }
348 bool EndAlignment() { return GetBuffer().EndAlignment(); }
350 /// Begin left indent
351 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0) { return GetBuffer().BeginLeftIndent(leftIndent
, leftSubIndent
); }
354 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
356 /// Begin right indent
357 bool BeginRightIndent(int rightIndent
) { return GetBuffer().BeginRightIndent(rightIndent
); }
360 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
362 /// Begin paragraph spacing
363 bool BeginParagraphSpacing(int before
, int after
) { return GetBuffer().BeginParagraphSpacing(before
, after
); }
365 /// End paragraph spacing
366 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
368 /// Begin line spacing
369 bool BeginLineSpacing(int lineSpacing
) { return GetBuffer().BeginLineSpacing(lineSpacing
); }
372 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
374 /// Begin numbered bullet
375 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
376 { return GetBuffer().BeginNumberedBullet(bulletNumber
, leftIndent
, leftSubIndent
, bulletStyle
); }
378 /// End numbered bullet
379 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
381 /// Begin symbol bullet
382 bool BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
383 { return GetBuffer().BeginSymbolBullet(symbol
, leftIndent
, leftSubIndent
, bulletStyle
); }
385 /// End symbol bullet
386 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
388 /// Begin named character style
389 bool BeginCharacterStyle(const wxString
& characterStyle
) { return GetBuffer().BeginCharacterStyle(characterStyle
); }
391 /// End named character style
392 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
394 /// Begin named paragraph style
395 bool BeginParagraphStyle(const wxString
& paragraphStyle
) { return GetBuffer().BeginParagraphStyle(paragraphStyle
); }
397 /// End named character style
398 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
400 /// Sets the default style to the style under the cursor
401 bool SetDefaultStyleToCursorStyle();
403 /// Clear the selection
404 virtual void SelectNone();
406 /// Select the word at the given character position
407 virtual bool SelectWord(long position
);
409 /// Get/set the selection range in character positions. -1, -1 means no selection.
410 /// The range is in API convention, i.e. a single character selection is denoted
412 wxRichTextRange
GetSelectionRange() const;
413 void SetSelectionRange(const wxRichTextRange
& range
);
415 /// Get/set the selection range in character positions. -1, -1 means no selection.
416 /// The range is in internal format, i.e. a single character selection is denoted
418 const wxRichTextRange
& GetInternalSelectionRange() const { return m_selectionRange
; }
419 void SetInternalSelectionRange(const wxRichTextRange
& range
) { m_selectionRange
= range
; }
421 /// Add a new paragraph of text to the end of the buffer
422 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
425 virtual wxRichTextRange
AddImage(const wxImage
& image
);
427 /// Layout the buffer: which we must do before certain operations, such as
428 /// setting the caret position.
429 virtual bool LayoutContent(bool onlyVisibleRect
= false);
431 /// Move the caret to the given character position
432 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
435 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
438 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
441 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
444 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
446 /// Move to the end of the line
447 virtual bool MoveToLineEnd(int flags
= 0);
449 /// Move to the start of the line
450 virtual bool MoveToLineStart(int flags
= 0);
452 /// Move to the end of the paragraph
453 virtual bool MoveToParagraphEnd(int flags
= 0);
455 /// Move to the start of the paragraph
456 virtual bool MoveToParagraphStart(int flags
= 0);
458 /// Move to the start of the buffer
459 virtual bool MoveHome(int flags
= 0);
461 /// Move to the end of the buffer
462 virtual bool MoveEnd(int flags
= 0);
465 virtual bool PageUp(int noPages
= 1, int flags
= 0);
467 /// Move n pages down
468 virtual bool PageDown(int noPages
= 1, int flags
= 0);
470 /// Move n words left
471 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
473 /// Move n words right
474 virtual bool WordRight(int noPages
= 1, int flags
= 0);
476 /// Returns the buffer associated with the control.
477 wxRichTextBuffer
& GetBuffer() { return m_buffer
; }
478 const wxRichTextBuffer
& GetBuffer() const { return m_buffer
; }
480 /// Start batching undo history for commands.
481 virtual bool BeginBatchUndo(const wxString
& cmdName
) { return m_buffer
.BeginBatchUndo(cmdName
); }
483 /// End batching undo history for commands.
484 virtual bool EndBatchUndo() { return m_buffer
.EndBatchUndo(); }
486 /// Are we batching undo history for commands?
487 virtual bool BatchingUndo() const { return m_buffer
.BatchingUndo(); }
489 /// Start suppressing undo history for commands.
490 virtual bool BeginSuppressUndo() { return m_buffer
.BeginSuppressUndo(); }
492 /// End suppressing undo history for commands.
493 virtual bool EndSuppressUndo() { return m_buffer
.EndSuppressUndo(); }
495 /// Are we suppressing undo history for commands?
496 virtual bool SuppressingUndo() const { return m_buffer
.SuppressingUndo(); }
498 /// Test if this whole range has character attributes of the specified kind. If any
499 /// of the attributes are different within the range, the test fails. You
500 /// can use this to implement, for example, bold button updating. style must have
501 /// flags indicating which attributes are of interest.
502 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
504 return GetBuffer().HasCharacterAttributes(range
, style
);
506 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
508 return GetBuffer().HasCharacterAttributes(range
, style
);
511 /// Test if this whole range has paragraph attributes of the specified kind. If any
512 /// of the attributes are different within the range, the test fails. You
513 /// can use this to implement, for example, centering button updating. style must have
514 /// flags indicating which attributes are of interest.
515 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
517 return GetBuffer().HasParagraphAttributes(range
, style
);
519 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
521 return GetBuffer().HasParagraphAttributes(range
, style
);
524 /// Is all of the selection bold?
525 virtual bool IsSelectionBold();
527 /// Is all of the selection italics?
528 virtual bool IsSelectionItalics();
530 /// Is all of the selection underlined?
531 virtual bool IsSelectionUnderlined();
533 /// Is all of the selection aligned according to the specified flag?
534 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
536 /// Apply bold to the selection
537 virtual bool ApplyBoldToSelection();
539 /// Apply italic to the selection
540 virtual bool ApplyItalicToSelection();
542 /// Apply underline to the selection
543 virtual bool ApplyUnderlineToSelection();
545 /// Apply alignment to the selection
546 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
548 /// Apply a named style to the selection
549 virtual void ApplyStyle(wxRichTextStyleDefinition
* def
);
551 /// Set style sheet, if any.
552 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { GetBuffer().SetStyleSheet(styleSheet
); }
553 wxRichTextStyleSheet
* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
555 /// Apply the style sheet to the buffer, for example if the styles have changed.
556 bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
= NULL
);
560 void Command(wxCommandEvent
& event
);
561 void OnDropFiles(wxDropFilesEvent
& event
);
563 void OnCut(wxCommandEvent
& event
);
564 void OnCopy(wxCommandEvent
& event
);
565 void OnPaste(wxCommandEvent
& event
);
566 void OnUndo(wxCommandEvent
& event
);
567 void OnRedo(wxCommandEvent
& event
);
568 void OnSelectAll(wxCommandEvent
& event
);
569 void OnClear(wxCommandEvent
& event
);
571 void OnUpdateCut(wxUpdateUIEvent
& event
);
572 void OnUpdateCopy(wxUpdateUIEvent
& event
);
573 void OnUpdatePaste(wxUpdateUIEvent
& event
);
574 void OnUpdateUndo(wxUpdateUIEvent
& event
);
575 void OnUpdateRedo(wxUpdateUIEvent
& event
);
576 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
577 void OnUpdateClear(wxUpdateUIEvent
& event
);
579 // Show a context menu for Rich Edit controls (the standard
580 // EDIT control has one already)
581 void OnContextMenu(wxContextMenuEvent
& event
);
586 void OnPaint(wxPaintEvent
& event
);
587 void OnEraseBackground(wxEraseEvent
& event
);
590 void OnLeftClick(wxMouseEvent
& event
);
593 void OnLeftUp(wxMouseEvent
& event
);
596 void OnMoveMouse(wxMouseEvent
& event
);
598 /// Left-double-click
599 void OnLeftDClick(wxMouseEvent
& event
);
602 void OnMiddleClick(wxMouseEvent
& event
);
605 void OnRightClick(wxMouseEvent
& event
);
608 void OnChar(wxKeyEvent
& event
);
611 void OnSize(wxSizeEvent
& event
);
613 /// Setting/losing focus
614 void OnSetFocus(wxFocusEvent
& event
);
615 void OnKillFocus(wxFocusEvent
& event
);
617 /// Idle-time processing
618 void OnIdle(wxIdleEvent
& event
);
621 void OnScroll(wxScrollWinEvent
& event
);
623 /// Set font, and also default attributes
624 virtual bool SetFont(const wxFont
& font
);
626 /// Set up scrollbars, e.g. after a resize
627 virtual void SetupScrollbars(bool atTop
= false);
629 /// Keyboard navigation
630 virtual bool KeyboardNavigate(int keyCode
, int flags
);
632 /// Paint the background
633 virtual void PaintBackground(wxDC
& dc
);
635 #if wxRICHTEXT_BUFFERED_PAINTING
636 /// Recreate buffer bitmap if necessary
637 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
640 /// Set the selection
641 virtual void DoSetSelection(long from
, long to
, bool scrollCaret
= true);
644 virtual void DoWriteText(const wxString
& value
, bool selectionOnly
= true);
646 /// Send an update event
647 virtual bool SendUpdateEvent();
649 /// Init command event
650 void InitCommandEvent(wxCommandEvent
& event
) const;
652 /// do the window-specific processing after processing the update event
653 // (duplicated code from wxTextCtrlBase)
654 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
655 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
);
658 /// Should we inherit colours?
659 virtual bool ShouldInheritColours() const { return false; }
661 /// Position the caret
662 virtual void PositionCaret();
664 /// Extend the selection, returning true if the selection was
665 /// changed. Selections are in caret positions.
666 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
668 /// Scroll into view. This takes a _caret_ position.
669 virtual bool ScrollIntoView(long position
, int keyCode
);
671 /// The caret position is the character position just before the caret.
672 /// A value of -1 means the caret is at the start of the buffer.
673 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
674 long GetCaretPosition() const { return m_caretPosition
; }
676 /// The adjusted caret position is the character position adjusted to take
677 /// into account whether we're at the start of a paragraph, in which case
678 /// style information should be taken from the next position, not current one.
679 long GetAdjustedCaretPosition(long caretPos
) const;
681 /// Move caret one visual step forward: this may mean setting a flag
682 /// and keeping the same position if we're going from the end of one line
683 /// to the start of the next, which may be the exact same caret position.
684 void MoveCaretForward(long oldPosition
) ;
686 /// Move caret one visual step forward: this may mean setting a flag
687 /// and keeping the same position if we're going from the end of one line
688 /// to the start of the next, which may be the exact same caret position.
689 void MoveCaretBack(long oldPosition
) ;
691 /// Get the caret height and position for the given character position
692 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
694 /// Gets the line for the visible caret position. If the caret is
695 /// shown at the very end of the line, it means the next character is actually
696 /// on the following line. So let's get the line we're expecting to find
697 /// if this is the case.
698 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
700 /// Gets the command processor
701 wxCommandProcessor
* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
703 /// Delete content if there is a selection, e.g. when pressing a key.
704 /// Returns the new caret position in newPos, or leaves it if there
706 bool DeleteSelectedContent(long* newPos
= NULL
);
708 /// Transform logical to physical
709 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
711 /// Transform physical to logical
712 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
714 /// Finds the caret position for the next word. Direction
715 /// is 1 (forward) or -1 (backwards).
716 virtual long FindNextWordPosition(int direction
= 1) const;
718 /// Is the given position visible on the screen?
719 bool IsPositionVisible(long pos
) const;
721 /// Returns the first visible position in the current view
722 long GetFirstVisiblePosition() const;
724 /// Returns the caret position since the default formatting was changed. As
725 /// soon as this position changes, we no longer reflect the default style
726 /// in the UI. A value of -2 means that we should only reflect the style of the
727 /// content under the caret.
728 long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle
; }
730 /// Set the caret position for the default style that the user is selecting.
731 void SetCaretPositionForDefaultStyle(long pos
) { m_caretPositionForDefaultStyle
= pos
; }
733 /// Should the UI reflect the default style chosen by the user, rather than the style under
735 bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle
!= -2; }
737 /// Convenience function that tells the control to start reflecting the default
738 /// style, since the user is changing it.
739 void SetAndShowDefaultStyle(const wxRichTextAttr
& attr
)
741 SetDefaultStyle(attr
);
742 SetCaretPositionForDefaultStyle(GetCaretPosition());
747 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
748 WX_FORWARD_TO_SCROLL_HELPER()
754 virtual wxSize
DoGetBestSize() const ;
759 /// Allows nested Freeze/Thaw
762 #if wxRICHTEXT_BUFFERED_PAINTING
764 wxBitmap m_bufferBitmap
;
768 wxRichTextBuffer m_buffer
;
770 #if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
775 wxMenu
* m_contextMenu
;
777 /// Caret position (1 less than the character position, so -1 is the
778 /// first caret position).
779 long m_caretPosition
;
781 /// Caret position when the default formatting has been changed. As
782 /// soon as this position changes, we no longer reflect the default style
784 long m_caretPositionForDefaultStyle
;
786 /// Selection range in character positions. -2, -2 means no selection.
787 wxRichTextRange m_selectionRange
;
789 /// Anchor so we know how to extend the selection
790 /// It's a caret position since it's between two characters.
791 long m_selectionAnchor
;
796 /// Are we showing the caret position at the start of a line
797 /// instead of at the end of the previous one?
798 bool m_caretAtLineStart
;
800 /// Are we dragging a selection?
803 /// Start position for drag
806 /// Do we need full layout in idle?
807 bool m_fullLayoutRequired
;
808 wxLongLong m_fullLayoutTime
;
809 long m_fullLayoutSavedPosition
;
811 /// Threshold for doing delayed layout
812 long m_delayedLayoutThreshold
;
816 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
819 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent
: public wxNotifyEvent
822 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
823 : wxNotifyEvent(commandType
, winid
),
824 m_itemIndex(-1), m_flags(0)
827 wxRichTextEvent(const wxRichTextEvent
& event
)
828 : wxNotifyEvent(event
),
829 m_itemIndex(event
.m_itemIndex
), m_flags(event
.m_flags
)
832 int GetIndex() const { return m_itemIndex
; }
833 void SetIndex(int n
) { m_itemIndex
= n
; }
835 int GetFlags() const { return m_flags
; }
836 void SetFlags(int flags
) { m_flags
= flags
; }
838 virtual wxEvent
*Clone() const { return new wxRichTextEvent(*this); }
845 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent
)
849 * wxRichTextCtrl event macros
852 BEGIN_DECLARE_EVENT_TYPES()
853 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED
, 2600)
854 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED
, 2601)
855 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, 2602)
856 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, 2603)
857 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, 2604)
858 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, 2605)
859 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RETURN
, 2606)
860 END_DECLARE_EVENT_TYPES()
862 typedef void (wxEvtHandler::*wxRichTextEventFunction
)(wxRichTextEvent
&);
864 #define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
865 #define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
866 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
867 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
868 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
869 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
870 #define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
876 // _WX_RICHTEXTCTRL_H_