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 #include "wx/textctrl.h"
24 #if !defined(__WXGTK__) && !defined(__WXMAC__)
25 #define wxRICHTEXT_BUFFERED_PAINTING 1
27 #define wxRICHTEXT_BUFFERED_PAINTING 0
30 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition
;
39 #define wxRE_READONLY 0x0010
40 #define wxRE_MULTILINE 0x0020
41 #define wxRE_CENTRE_CARET 0x8000
42 #define wxRE_CENTER_CARET wxRE_CENTRE_CARET
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
: public wxControl
,
90 public wxTextCtrlIface
,
93 DECLARE_CLASS( wxRichTextCtrl
)
100 wxRichTextCtrl( wxWindow
* parent
, wxWindowID id
= -1, const wxString
& value
= wxEmptyString
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
101 long style
= wxRE_MULTILINE
, const wxValidator
& validator
= wxDefaultValidator
, const wxString
& name
= wxTextCtrlNameStr
);
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
, const wxValidator
& validator
= wxDefaultValidator
, const wxString
& name
= wxTextCtrlNameStr
);
111 /// Member initialisation
114 ///// wxTextCtrl compatibility
118 virtual wxString
GetRange(long from
, long to
) const;
120 virtual int GetLineLength(long lineNo
) const ;
121 virtual wxString
GetLineText(long lineNo
) const ;
122 virtual int GetNumberOfLines() const ;
124 virtual bool IsModified() const ;
125 virtual bool IsEditable() const ;
127 // more readable flag testing methods
128 bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE
); }
129 bool IsMultiLine() const { return !IsSingleLine(); }
131 // If the return values from and to are the same, there is no selection.
132 virtual void GetSelection(long* from
, long* to
) const;
134 virtual wxString
GetStringSelection() const;
137 wxString
GetFilename() const { return m_filename
; }
140 void SetFilename(const wxString
& filename
) { m_filename
= filename
; }
142 /// Set the threshold in character positions for doing layout optimization during sizing
143 void SetDelayedLayoutThreshold(long threshold
) { m_delayedLayoutThreshold
= threshold
; }
145 /// Get the threshold in character positions for doing layout optimization during sizing
146 long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold
; }
149 void SetTextCursor(const wxCursor
& cursor
) { m_textCursor
= cursor
; }
152 wxCursor
GetTextCursor() const { return m_textCursor
; }
155 void SetURLCursor(const wxCursor
& cursor
) { m_urlCursor
= cursor
; }
158 wxCursor
GetURLCursor() const { return m_urlCursor
; }
160 /// Are we showing the caret position at the start of a line
161 /// instead of at the end of the previous one?
162 bool GetCaretAtLineStart() const { return m_caretAtLineStart
; }
163 void SetCaretAtLineStart(bool atStart
) { m_caretAtLineStart
= atStart
; }
165 /// Are we dragging a selection?
166 bool GetDragging() const { return m_dragging
; }
167 void SetDragging(bool dragging
) { m_dragging
= dragging
; }
169 /// Get/set drag start position
170 const wxPoint
& GetDragStart() const { return m_dragStart
; }
171 void SetDragStart(const wxPoint
& pt
) { m_dragStart
= pt
; }
173 #if wxRICHTEXT_BUFFERED_PAINTING
174 /// Get the buffer bitmap
175 const wxBitmap
& GetBufferBitmap() const { return m_bufferBitmap
; }
176 wxBitmap
& GetBufferBitmap() { return m_bufferBitmap
; }
179 /// Get/set context menu
180 wxMenu
* GetContextMenu() const { return m_contextMenu
; }
181 void SetContextMenu(wxMenu
* menu
);
183 /// Anchor so we know how to extend the selection
184 /// It's a caret position since it's between two characters.
185 long GetSelectionAnchor() const { return m_selectionAnchor
; }
186 void SetSelectionAnchor(long anchor
) { m_selectionAnchor
= anchor
; }
188 /// The wxRichTextObject object under mouse if any
189 wxRichTextObject
* GetCurrentObject() const { return m_currentObject
; }
190 void SetCurrentObject(wxRichTextObject
* obj
) { m_currentObject
= obj
; }
195 virtual void Clear();
196 virtual void Replace(long from
, long to
, const wxString
& value
);
197 virtual void Remove(long from
, long to
);
199 // load/save the controls contents from/to the file
200 virtual bool DoLoadFile(const wxString
& file
, int fileType
);
201 virtual bool DoSaveFile(const wxString
& file
= wxEmptyString
,
202 int fileType
= wxRICHTEXT_TYPE_ANY
);
204 /// Set the handler flags, controlling loading and saving
205 void SetHandlerFlags(int flags
) { GetBuffer().SetHandlerFlags(flags
); }
207 /// Get the handler flags, controlling loading and saving
208 int GetHandlerFlags() const { return GetBuffer().GetHandlerFlags(); }
210 // sets/clears the dirty flag
211 virtual void MarkDirty();
212 virtual void DiscardEdits();
214 // set the max number of characters which may be entered in a single line
216 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
218 // writing text inserts it at the current position, appending always
219 // inserts it at the end
220 virtual void WriteText(const wxString
& text
);
221 virtual void AppendText(const wxString
& text
);
223 // text control under some platforms supports the text styles: these
224 // methods allow to apply the given text style to the given selection or to
225 // set/get the style which will be used for all appended text
226 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
227 virtual bool SetStyle(long start
, long end
, const wxRichTextAttr
& style
);
228 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
);
229 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
230 virtual bool GetStyle(long position
, wxTextAttr
& style
);
231 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
233 // Set an image style
234 void SetImageStyle(wxRichTextImage
*image
, const wxRichTextAttr
& textAttr
);
236 // get the common set of styles for the range
237 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
);
238 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
);
239 // extended style setting operation with flags including:
240 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
241 // see richtextbuffer.h for more details.
242 virtual bool SetStyleEx(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
244 /// Get the content (uncombined) attributes for this position.
245 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
247 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
248 virtual bool SetDefaultStyle(const wxRichTextAttr
& style
);
250 virtual const wxRichTextAttr
& GetDefaultStyleEx() const;
252 //virtual const wxTextAttr& GetDefaultStyle() const;
255 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
256 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
258 /// Clear list for given range
259 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
261 /// Number/renumber any list elements in the given range
262 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
263 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
264 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
266 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
267 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
268 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
269 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
271 /// Deletes the content in the given range
272 virtual bool Delete(const wxRichTextRange
& range
);
274 // translate between the position (which is just an index in the text ctrl
275 // considering all its contents as a single strings) and (x, y) coordinates
276 // which represent column and line.
277 virtual long XYToPosition(long x
, long y
) const;
278 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
280 virtual void ShowPosition(long pos
);
282 // find the character at position given in pixels
284 // NB: pt is in device coords (not adjusted for the client area origin nor
286 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
287 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
289 wxTextCoord
*row
) const;
291 // Clipboard operations
294 virtual void Paste();
295 virtual void DeleteSelection();
297 virtual bool CanCopy() const;
298 virtual bool CanCut() const;
299 virtual bool CanPaste() const;
300 virtual bool CanDeleteSelection() const;
306 virtual bool CanUndo() const;
307 virtual bool CanRedo() const;
310 virtual void SetInsertionPoint(long pos
);
311 virtual void SetInsertionPointEnd();
312 virtual long GetInsertionPoint() const;
313 virtual wxTextPos
GetLastPosition() const;
315 virtual void SetSelection(long from
, long to
);
316 virtual void SelectAll();
317 virtual void SetEditable(bool editable
);
319 virtual bool HasSelection() const;
321 ///// Functionality specific to wxRichTextCtrl
323 /// Write an image at the current insertion point. Supply optional type to use
324 /// for internal and file storage of the raw data.
325 virtual bool WriteImage(const wxImage
& image
, wxBitmapType bitmapType
= wxBITMAP_TYPE_PNG
,
326 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
328 /// Write a bitmap at the current insertion point. Supply optional type to use
329 /// for internal and file storage of the raw data.
330 virtual bool WriteImage(const wxBitmap
& bitmap
, wxBitmapType bitmapType
= wxBITMAP_TYPE_PNG
,
331 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
333 /// Load an image from file and write at the current insertion point.
334 virtual bool WriteImage(const wxString
& filename
, wxBitmapType bitmapType
,
335 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
337 /// Write an image block at the current insertion point.
338 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
,
339 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
341 /// Insert a newline (actually paragraph) at the current insertion point.
342 virtual bool Newline();
344 /// Insert a line break at the current insertion point.
345 virtual bool LineBreak();
347 /// Set basic (overall) style
348 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { GetBuffer().SetBasicStyle(style
); }
350 /// Get basic (overall) style
351 virtual const wxRichTextAttr
& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
353 virtual bool BeginStyle(const wxRichTextAttr
& style
) { return GetBuffer().BeginStyle(style
); }
356 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
359 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
362 bool BeginBold() { return GetBuffer().BeginBold(); }
365 bool EndBold() { return GetBuffer().EndBold(); }
367 /// Begin using italic
368 bool BeginItalic() { return GetBuffer().BeginItalic(); }
371 bool EndItalic() { return GetBuffer().EndItalic(); }
373 /// Begin using underline
374 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
376 /// End using underline
377 bool EndUnderline() { return GetBuffer().EndUnderline(); }
379 /// Begin using point size
380 bool BeginFontSize(int pointSize
) { return GetBuffer().BeginFontSize(pointSize
); }
382 /// End using point size
383 bool EndFontSize() { return GetBuffer().EndFontSize(); }
385 /// Begin using this font
386 bool BeginFont(const wxFont
& font
) { return GetBuffer().BeginFont(font
); }
389 bool EndFont() { return GetBuffer().EndFont(); }
391 /// Begin using this colour
392 bool BeginTextColour(const wxColour
& colour
) { return GetBuffer().BeginTextColour(colour
); }
394 /// End using a colour
395 bool EndTextColour() { return GetBuffer().EndTextColour(); }
397 /// Begin using alignment
398 bool BeginAlignment(wxTextAttrAlignment alignment
) { return GetBuffer().BeginAlignment(alignment
); }
401 bool EndAlignment() { return GetBuffer().EndAlignment(); }
403 /// Begin left indent
404 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0) { return GetBuffer().BeginLeftIndent(leftIndent
, leftSubIndent
); }
407 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
409 /// Begin right indent
410 bool BeginRightIndent(int rightIndent
) { return GetBuffer().BeginRightIndent(rightIndent
); }
413 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
415 /// Begin paragraph spacing
416 bool BeginParagraphSpacing(int before
, int after
) { return GetBuffer().BeginParagraphSpacing(before
, after
); }
418 /// End paragraph spacing
419 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
421 /// Begin line spacing
422 bool BeginLineSpacing(int lineSpacing
) { return GetBuffer().BeginLineSpacing(lineSpacing
); }
425 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
427 /// Begin numbered bullet
428 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
429 { return GetBuffer().BeginNumberedBullet(bulletNumber
, leftIndent
, leftSubIndent
, bulletStyle
); }
431 /// End numbered bullet
432 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
434 /// Begin symbol bullet
435 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
436 { return GetBuffer().BeginSymbolBullet(symbol
, leftIndent
, leftSubIndent
, bulletStyle
); }
438 /// End symbol bullet
439 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
441 /// Begin standard bullet
442 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
)
443 { return GetBuffer().BeginStandardBullet(bulletName
, leftIndent
, leftSubIndent
, bulletStyle
); }
445 /// End standard bullet
446 bool EndStandardBullet() { return GetBuffer().EndStandardBullet(); }
448 /// Begin named character style
449 bool BeginCharacterStyle(const wxString
& characterStyle
) { return GetBuffer().BeginCharacterStyle(characterStyle
); }
451 /// End named character style
452 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
454 /// Begin named paragraph style
455 bool BeginParagraphStyle(const wxString
& paragraphStyle
) { return GetBuffer().BeginParagraphStyle(paragraphStyle
); }
457 /// End named character style
458 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
460 /// Begin named list style
461 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1) { return GetBuffer().BeginListStyle(listStyle
, level
, number
); }
463 /// End named character style
464 bool EndListStyle() { return GetBuffer().EndListStyle(); }
467 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
) { return GetBuffer().BeginURL(url
, characterStyle
); }
470 bool EndURL() { return GetBuffer().EndURL(); }
472 /// Sets the default style to the style under the cursor
473 bool SetDefaultStyleToCursorStyle();
475 /// Clear the selection
476 virtual void SelectNone();
478 /// Select the word at the given character position
479 virtual bool SelectWord(long position
);
481 /// Get/set the selection range in character positions. -1, -1 means no selection.
482 /// The range is in API convention, i.e. a single character selection is denoted
484 wxRichTextRange
GetSelectionRange() const;
485 void SetSelectionRange(const wxRichTextRange
& range
);
487 /// Get/set the selection range in character positions. -1, -1 means no selection.
488 /// The range is in internal format, i.e. a single character selection is denoted
490 const wxRichTextRange
& GetInternalSelectionRange() const { return m_selectionRange
; }
491 void SetInternalSelectionRange(const wxRichTextRange
& range
) { m_selectionRange
= range
; }
493 /// Add a new paragraph of text to the end of the buffer
494 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
497 virtual wxRichTextRange
AddImage(const wxImage
& image
);
499 /// Layout the buffer: which we must do before certain operations, such as
500 /// setting the caret position.
501 virtual bool LayoutContent(bool onlyVisibleRect
= false);
503 /// Move the caret to the given character position
504 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
507 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
510 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
513 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
516 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
518 /// Move to the end of the line
519 virtual bool MoveToLineEnd(int flags
= 0);
521 /// Move to the start of the line
522 virtual bool MoveToLineStart(int flags
= 0);
524 /// Move to the end of the paragraph
525 virtual bool MoveToParagraphEnd(int flags
= 0);
527 /// Move to the start of the paragraph
528 virtual bool MoveToParagraphStart(int flags
= 0);
530 /// Move to the start of the buffer
531 virtual bool MoveHome(int flags
= 0);
533 /// Move to the end of the buffer
534 virtual bool MoveEnd(int flags
= 0);
537 virtual bool PageUp(int noPages
= 1, int flags
= 0);
539 /// Move n pages down
540 virtual bool PageDown(int noPages
= 1, int flags
= 0);
542 /// Move n words left
543 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
545 /// Move n words right
546 virtual bool WordRight(int noPages
= 1, int flags
= 0);
548 /// Returns the buffer associated with the control.
549 wxRichTextBuffer
& GetBuffer() { return m_buffer
; }
550 const wxRichTextBuffer
& GetBuffer() const { return m_buffer
; }
552 /// Start batching undo history for commands.
553 virtual bool BeginBatchUndo(const wxString
& cmdName
) { return m_buffer
.BeginBatchUndo(cmdName
); }
555 /// End batching undo history for commands.
556 virtual bool EndBatchUndo() { return m_buffer
.EndBatchUndo(); }
558 /// Are we batching undo history for commands?
559 virtual bool BatchingUndo() const { return m_buffer
.BatchingUndo(); }
561 /// Start suppressing undo history for commands.
562 virtual bool BeginSuppressUndo() { return m_buffer
.BeginSuppressUndo(); }
564 /// End suppressing undo history for commands.
565 virtual bool EndSuppressUndo() { return m_buffer
.EndSuppressUndo(); }
567 /// Are we suppressing undo history for commands?
568 virtual bool SuppressingUndo() const { return m_buffer
.SuppressingUndo(); }
570 /// Test if this whole range has character attributes of the specified kind. If any
571 /// of the attributes are different within the range, the test fails. You
572 /// can use this to implement, for example, bold button updating. style must have
573 /// flags indicating which attributes are of interest.
574 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
576 return GetBuffer().HasCharacterAttributes(range
.ToInternal(), style
);
579 /// Test if this whole range has paragraph attributes of the specified kind. If any
580 /// of the attributes are different within the range, the test fails. You
581 /// can use this to implement, for example, centering button updating. style must have
582 /// flags indicating which attributes are of interest.
583 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
585 return GetBuffer().HasParagraphAttributes(range
.ToInternal(), style
);
588 /// Is all of the selection bold?
589 virtual bool IsSelectionBold();
591 /// Is all of the selection italics?
592 virtual bool IsSelectionItalics();
594 /// Is all of the selection underlined?
595 virtual bool IsSelectionUnderlined();
597 /// Is all of the selection aligned according to the specified flag?
598 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
600 /// Apply bold to the selection
601 virtual bool ApplyBoldToSelection();
603 /// Apply italic to the selection
604 virtual bool ApplyItalicToSelection();
606 /// Apply underline to the selection
607 virtual bool ApplyUnderlineToSelection();
609 /// Apply alignment to the selection
610 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
612 /// Apply a named style to the selection
613 virtual bool ApplyStyle(wxRichTextStyleDefinition
* def
);
615 /// Set style sheet, if any
616 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { GetBuffer().SetStyleSheet(styleSheet
); }
617 wxRichTextStyleSheet
* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
619 /// Push style sheet to top of stack
620 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
) { return GetBuffer().PushStyleSheet(styleSheet
); }
622 /// Pop style sheet from top of stack
623 wxRichTextStyleSheet
* PopStyleSheet() { return GetBuffer().PopStyleSheet(); }
625 /// Apply the style sheet to the buffer, for example if the styles have changed.
626 bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
= NULL
);
630 void Command(wxCommandEvent
& event
);
631 void OnDropFiles(wxDropFilesEvent
& event
);
632 void OnCaptureLost(wxMouseCaptureLostEvent
& event
);
633 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
635 void OnCut(wxCommandEvent
& event
);
636 void OnCopy(wxCommandEvent
& event
);
637 void OnPaste(wxCommandEvent
& event
);
638 void OnUndo(wxCommandEvent
& event
);
639 void OnRedo(wxCommandEvent
& event
);
640 void OnSelectAll(wxCommandEvent
& event
);
641 void OnImage(wxCommandEvent
& event
);
642 void OnClear(wxCommandEvent
& event
);
644 void OnUpdateCut(wxUpdateUIEvent
& event
);
645 void OnUpdateCopy(wxUpdateUIEvent
& event
);
646 void OnUpdatePaste(wxUpdateUIEvent
& event
);
647 void OnUpdateUndo(wxUpdateUIEvent
& event
);
648 void OnUpdateRedo(wxUpdateUIEvent
& event
);
649 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
650 void OnUpdateImage(wxUpdateUIEvent
& event
);
651 void OnUpdateClear(wxUpdateUIEvent
& event
);
653 // Show a context menu for Rich Edit controls (the standard
654 // EDIT control has one already)
655 void OnContextMenu(wxContextMenuEvent
& event
);
660 void OnPaint(wxPaintEvent
& event
);
661 void OnEraseBackground(wxEraseEvent
& event
);
664 void OnLeftClick(wxMouseEvent
& event
);
667 void OnLeftUp(wxMouseEvent
& event
);
670 void OnMoveMouse(wxMouseEvent
& event
);
672 /// Left-double-click
673 void OnLeftDClick(wxMouseEvent
& event
);
676 void OnMiddleClick(wxMouseEvent
& event
);
679 void OnRightClick(wxMouseEvent
& event
);
682 void OnChar(wxKeyEvent
& event
);
685 void OnSize(wxSizeEvent
& event
);
687 /// Setting/losing focus
688 void OnSetFocus(wxFocusEvent
& event
);
689 void OnKillFocus(wxFocusEvent
& event
);
691 /// Idle-time processing
692 void OnIdle(wxIdleEvent
& event
);
695 void OnScroll(wxScrollWinEvent
& event
);
697 /// Set font, and also default attributes
698 virtual bool SetFont(const wxFont
& font
);
700 /// Set up scrollbars, e.g. after a resize
701 virtual void SetupScrollbars(bool atTop
= false);
703 /// Keyboard navigation
704 virtual bool KeyboardNavigate(int keyCode
, int flags
);
706 /// Paint the background
707 virtual void PaintBackground(wxDC
& dc
);
709 /// Other user defined painting after everything else (i.e. all text) is painted
710 virtual void PaintAboveContent(wxDC
& WXUNUSED(dc
)) {}
712 #if wxRICHTEXT_BUFFERED_PAINTING
713 /// Recreate buffer bitmap if necessary
714 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
718 virtual void DoWriteText(const wxString
& value
, int flags
= 0);
720 /// Should we inherit colours?
721 virtual bool ShouldInheritColours() const { return false; }
723 /// Position the caret
724 virtual void PositionCaret();
726 /// Extend the selection, returning true if the selection was
727 /// changed. Selections are in caret positions.
728 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
730 /// Scroll into view. This takes a _caret_ position.
731 virtual bool ScrollIntoView(long position
, int keyCode
);
733 /// Refresh the area affected by a selection change
734 bool RefreshForSelectionChange(const wxRichTextRange
& oldSelection
, const wxRichTextRange
& newSelection
);
736 /// The caret position is the character position just before the caret.
737 /// A value of -1 means the caret is at the start of the buffer.
738 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
739 long GetCaretPosition() const { return m_caretPosition
; }
741 /// The adjusted caret position is the character position adjusted to take
742 /// into account whether we're at the start of a paragraph, in which case
743 /// style information should be taken from the next position, not current one.
744 long GetAdjustedCaretPosition(long caretPos
) const;
746 /// Move caret one visual step forward: this may mean setting a flag
747 /// and keeping the same position if we're going from the end of one line
748 /// to the start of the next, which may be the exact same caret position.
749 void MoveCaretForward(long oldPosition
) ;
751 /// Move caret one visual step forward: this may mean setting a flag
752 /// and keeping the same position if we're going from the end of one line
753 /// to the start of the next, which may be the exact same caret position.
754 void MoveCaretBack(long oldPosition
) ;
756 /// Get the caret height and position for the given character position
757 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
759 /// Gets the line for the visible caret position. If the caret is
760 /// shown at the very end of the line, it means the next character is actually
761 /// on the following line. So let's get the line we're expecting to find
762 /// if this is the case.
763 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
765 /// Gets the command processor
766 wxCommandProcessor
* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
768 /// Delete content if there is a selection, e.g. when pressing a key.
769 /// Returns the new caret position in newPos, or leaves it if there
771 bool DeleteSelectedContent(long* newPos
= NULL
);
773 /// Transform logical to physical
774 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
776 /// Transform physical to logical
777 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
779 /// Finds the caret position for the next word. Direction
780 /// is 1 (forward) or -1 (backwards).
781 virtual long FindNextWordPosition(int direction
= 1) const;
783 /// Is the given position visible on the screen?
784 bool IsPositionVisible(long pos
) const;
786 /// Returns the first visible position in the current view
787 long GetFirstVisiblePosition() const;
789 /// Returns the caret position since the default formatting was changed. As
790 /// soon as this position changes, we no longer reflect the default style
791 /// in the UI. A value of -2 means that we should only reflect the style of the
792 /// content under the caret.
793 long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle
; }
795 /// Set the caret position for the default style that the user is selecting.
796 void SetCaretPositionForDefaultStyle(long pos
) { m_caretPositionForDefaultStyle
= pos
; }
798 /// Should the UI reflect the default style chosen by the user, rather than the style under
800 bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle
!= -2; }
802 /// Convenience function that tells the control to start reflecting the default
803 /// style, since the user is changing it.
804 void SetAndShowDefaultStyle(const wxRichTextAttr
& attr
)
806 SetDefaultStyle(attr
);
807 SetCaretPositionForDefaultStyle(GetCaretPosition());
810 /// Get the first visible point in the window
811 wxPoint
GetFirstVisiblePoint() const;
815 /// Font names take a long time to retrieve, so cache them (on demand)
816 static const wxArrayString
& GetAvailableFontNames();
817 static void ClearAvailableFontNames();
819 WX_FORWARD_TO_SCROLL_HELPER()
821 // implement wxTextEntry methods
822 virtual wxString
DoGetValue() const;
825 // implement the wxTextEntry pure virtual method
826 virtual wxWindow
*GetEditableWindow() { return this; }
828 // FIXME: this does not work, it allows this code to compile but will fail
830 #ifndef __WXUNIVERSAL__
832 virtual WXHWND
GetEditHWND() const { return GetHWND(); }
835 virtual WXWidget
GetTextWidget() const { return NULL
; }
838 virtual GtkEditable
*GetEditable() const { return NULL
; }
839 virtual GtkEntry
*GetEntry() const { return NULL
; }
841 #endif // !__WXUNIVERSAL__
846 virtual wxSize
DoGetBestSize() const ;
848 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
850 virtual void DoThaw();
855 #if wxRICHTEXT_BUFFERED_PAINTING
857 wxBitmap m_bufferBitmap
;
861 wxRichTextBuffer m_buffer
;
863 wxMenu
* m_contextMenu
;
865 /// Caret position (1 less than the character position, so -1 is the
866 /// first caret position).
867 long m_caretPosition
;
869 /// Caret position when the default formatting has been changed. As
870 /// soon as this position changes, we no longer reflect the default style
872 long m_caretPositionForDefaultStyle
;
874 /// Selection range in character positions. -2, -2 means no selection.
875 wxRichTextRange m_selectionRange
;
877 /// Anchor so we know how to extend the selection
878 /// It's a caret position since it's between two characters.
879 long m_selectionAnchor
;
884 /// Are we showing the caret position at the start of a line
885 /// instead of at the end of the previous one?
886 bool m_caretAtLineStart
;
888 /// Are we dragging a selection?
891 /// Start position for drag
894 /// Do we need full layout in idle?
895 bool m_fullLayoutRequired
;
896 wxLongLong m_fullLayoutTime
;
897 long m_fullLayoutSavedPosition
;
899 /// Threshold for doing delayed layout
900 long m_delayedLayoutThreshold
;
903 wxCursor m_textCursor
;
904 wxCursor m_urlCursor
;
906 static wxArrayString sm_availableFontNames
;
907 /// The wxRichTextObject object under mouse if any
908 wxRichTextObject
* m_currentObject
;
909 long m_imagePropertyId
;
913 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
916 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent
: public wxNotifyEvent
919 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
920 : wxNotifyEvent(commandType
, winid
),
921 m_flags(0), m_position(-1), m_oldStyleSheet(NULL
), m_newStyleSheet(NULL
),
925 wxRichTextEvent(const wxRichTextEvent
& event
)
926 : wxNotifyEvent(event
),
927 m_flags(event
.m_flags
), m_position(-1),
928 m_oldStyleSheet(event
.m_oldStyleSheet
), m_newStyleSheet(event
.m_newStyleSheet
),
932 long GetPosition() const { return m_position
; }
933 void SetPosition(long pos
) { m_position
= pos
; }
935 int GetFlags() const { return m_flags
; }
936 void SetFlags(int flags
) { m_flags
= flags
; }
938 wxRichTextStyleSheet
* GetOldStyleSheet() const { return m_oldStyleSheet
; }
939 void SetOldStyleSheet(wxRichTextStyleSheet
* sheet
) { m_oldStyleSheet
= sheet
; }
941 wxRichTextStyleSheet
* GetNewStyleSheet() const { return m_newStyleSheet
; }
942 void SetNewStyleSheet(wxRichTextStyleSheet
* sheet
) { m_newStyleSheet
= sheet
; }
944 const wxRichTextRange
& GetRange() const { return m_range
; }
945 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
947 wxChar
GetCharacter() const { return m_char
; }
948 void SetCharacter(wxChar ch
) { m_char
= ch
; }
950 virtual wxEvent
*Clone() const { return new wxRichTextEvent(*this); }
955 wxRichTextStyleSheet
* m_oldStyleSheet
;
956 wxRichTextStyleSheet
* m_newStyleSheet
;
957 wxRichTextRange m_range
;
961 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent
)
965 * wxRichTextCtrl events
967 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, wxRichTextEvent
);
968 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, wxRichTextEvent
);
969 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, wxRichTextEvent
);
970 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, wxRichTextEvent
);
971 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RETURN
, wxRichTextEvent
);
972 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_CHARACTER
, wxRichTextEvent
);
973 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_DELETE
, wxRichTextEvent
);
975 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING
, wxRichTextEvent
);
976 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED
, wxRichTextEvent
);
977 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING
, wxRichTextEvent
);
978 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED
, wxRichTextEvent
);
980 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED
, wxRichTextEvent
);
981 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED
, wxRichTextEvent
);
982 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED
, wxRichTextEvent
);
983 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED
, wxRichTextEvent
);
984 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET
, wxRichTextEvent
);
986 typedef void (wxEvtHandler::*wxRichTextEventFunction
)(wxRichTextEvent
&);
988 #define wxRichTextEventHandler(func) \
989 wxEVENT_HANDLER_CAST(wxRichTextEventFunction, func)
991 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
992 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
993 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
994 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
995 #define EVT_RICHTEXT_RETURN(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, wxRichTextEventHandler( fn ), NULL ),
996 #define EVT_RICHTEXT_CHARACTER(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CHARACTER, id, -1, wxRichTextEventHandler( fn ), NULL ),
997 #define EVT_RICHTEXT_DELETE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_DELETE, id, -1, wxRichTextEventHandler( fn ), NULL ),
999 #define EVT_RICHTEXT_STYLESHEET_CHANGING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, id, -1, wxRichTextEventHandler( fn ), NULL ),
1000 #define EVT_RICHTEXT_STYLESHEET_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1001 #define EVT_RICHTEXT_STYLESHEET_REPLACING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, id, -1, wxRichTextEventHandler( fn ), NULL ),
1002 #define EVT_RICHTEXT_STYLESHEET_REPLACED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1004 #define EVT_RICHTEXT_CONTENT_INSERTED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1005 #define EVT_RICHTEXT_CONTENT_DELETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1006 #define EVT_RICHTEXT_STYLE_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1007 #define EVT_RICHTEXT_SELECTION_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1008 #define EVT_RICHTEXT_BUFFER_RESET(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, id, -1, wxRichTextEventHandler( fn ), NULL ),
1014 // _WX_RICHTEXTCTRL_H_