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 // implement the wxTextEntry pure virtual method
205 virtual wxWindow
*GetEditableWindow() { return this; }
207 /// Set the handler flags, controlling loading and saving
208 void SetHandlerFlags(int flags
) { GetBuffer().SetHandlerFlags(flags
); }
210 /// Get the handler flags, controlling loading and saving
211 int GetHandlerFlags() const { return GetBuffer().GetHandlerFlags(); }
213 // sets/clears the dirty flag
214 virtual void MarkDirty();
215 virtual void DiscardEdits();
217 // set the max number of characters which may be entered in a single line
219 virtual void SetMaxLength(unsigned long WXUNUSED(len
)) { }
221 // writing text inserts it at the current position, appending always
222 // inserts it at the end
223 virtual void WriteText(const wxString
& text
);
224 virtual void AppendText(const wxString
& text
);
226 // text control under some platforms supports the text styles: these
227 // methods allow to apply the given text style to the given selection or to
228 // set/get the style which will be used for all appended text
229 virtual bool SetStyle(long start
, long end
, const wxTextAttr
& style
);
230 virtual bool SetStyle(long start
, long end
, const wxRichTextAttr
& style
);
231 virtual bool SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
);
232 virtual bool SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
);
233 virtual bool GetStyle(long position
, wxTextAttr
& style
);
234 virtual bool GetStyle(long position
, wxRichTextAttr
& style
);
236 // Set an image style
237 void SetImageStyle(wxRichTextImage
*image
, const wxRichTextAttr
& textAttr
);
239 // get the common set of styles for the range
240 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
);
241 virtual bool GetStyleForRange(const wxRichTextRange
& range
, wxRichTextAttr
& style
);
242 // extended style setting operation with flags including:
243 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
244 // see richtextbuffer.h for more details.
245 virtual bool SetStyleEx(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
247 /// Get the content (uncombined) attributes for this position.
248 virtual bool GetUncombinedStyle(long position
, wxRichTextAttr
& style
);
250 virtual bool SetDefaultStyle(const wxTextAttr
& style
);
251 virtual bool SetDefaultStyle(const wxRichTextAttr
& style
);
253 virtual const wxRichTextAttr
& GetDefaultStyleEx() const;
255 //virtual const wxTextAttr& GetDefaultStyle() const;
258 virtual bool SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
259 virtual bool SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
261 /// Clear list for given range
262 virtual bool ClearListStyle(const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
264 /// Number/renumber any list elements in the given range
265 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
266 virtual bool NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
267 virtual bool NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int startFrom
= 1, int specifiedLevel
= -1);
269 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
270 /// def/defName can be NULL/empty to indicate that the existing list style should be used.
271 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
= NULL
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
272 virtual bool PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
, int specifiedLevel
= -1);
274 /// Deletes the content in the given range
275 virtual bool Delete(const wxRichTextRange
& range
);
277 // translate between the position (which is just an index in the text ctrl
278 // considering all its contents as a single strings) and (x, y) coordinates
279 // which represent column and line.
280 virtual long XYToPosition(long x
, long y
) const;
281 virtual bool PositionToXY(long pos
, long *x
, long *y
) const;
283 virtual void ShowPosition(long pos
);
285 // find the character at position given in pixels
287 // NB: pt is in device coords (not adjusted for the client area origin nor
289 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
, long *pos
) const;
290 virtual wxTextCtrlHitTestResult
HitTest(const wxPoint
& pt
,
292 wxTextCoord
*row
) const;
294 // Clipboard operations
297 virtual void Paste();
298 virtual void DeleteSelection();
300 virtual bool CanCopy() const;
301 virtual bool CanCut() const;
302 virtual bool CanPaste() const;
303 virtual bool CanDeleteSelection() const;
309 virtual bool CanUndo() const;
310 virtual bool CanRedo() const;
313 virtual void SetInsertionPoint(long pos
);
314 virtual void SetInsertionPointEnd();
315 virtual long GetInsertionPoint() const;
316 virtual wxTextPos
GetLastPosition() const;
318 virtual void SetSelection(long from
, long to
);
319 virtual void SelectAll();
320 virtual void SetEditable(bool editable
);
322 virtual bool HasSelection() const;
324 ///// Functionality specific to wxRichTextCtrl
326 /// Write an image at the current insertion point. Supply optional type to use
327 /// for internal and file storage of the raw data.
328 virtual bool WriteImage(const wxImage
& image
, wxBitmapType bitmapType
= wxBITMAP_TYPE_PNG
,
329 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
331 /// Write a bitmap at the current insertion point. Supply optional type to use
332 /// for internal and file storage of the raw data.
333 virtual bool WriteImage(const wxBitmap
& bitmap
, wxBitmapType bitmapType
= wxBITMAP_TYPE_PNG
,
334 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
336 /// Load an image from file and write at the current insertion point.
337 virtual bool WriteImage(const wxString
& filename
, wxBitmapType bitmapType
,
338 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
340 /// Write an image block at the current insertion point.
341 virtual bool WriteImage(const wxRichTextImageBlock
& imageBlock
,
342 const wxRichTextAttr
& textAttr
= wxRichTextAttr());
344 /// Insert a newline (actually paragraph) at the current insertion point.
345 virtual bool Newline();
347 /// Insert a line break at the current insertion point.
348 virtual bool LineBreak();
350 /// Set basic (overall) style
351 virtual void SetBasicStyle(const wxRichTextAttr
& style
) { GetBuffer().SetBasicStyle(style
); }
353 /// Get basic (overall) style
354 virtual const wxRichTextAttr
& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); }
356 virtual bool BeginStyle(const wxRichTextAttr
& style
) { return GetBuffer().BeginStyle(style
); }
359 virtual bool EndStyle() { return GetBuffer().EndStyle(); }
362 virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }
365 bool BeginBold() { return GetBuffer().BeginBold(); }
368 bool EndBold() { return GetBuffer().EndBold(); }
370 /// Begin using italic
371 bool BeginItalic() { return GetBuffer().BeginItalic(); }
374 bool EndItalic() { return GetBuffer().EndItalic(); }
376 /// Begin using underline
377 bool BeginUnderline() { return GetBuffer().BeginUnderline(); }
379 /// End using underline
380 bool EndUnderline() { return GetBuffer().EndUnderline(); }
382 /// Begin using point size
383 bool BeginFontSize(int pointSize
) { return GetBuffer().BeginFontSize(pointSize
); }
385 /// End using point size
386 bool EndFontSize() { return GetBuffer().EndFontSize(); }
388 /// Begin using this font
389 bool BeginFont(const wxFont
& font
) { return GetBuffer().BeginFont(font
); }
392 bool EndFont() { return GetBuffer().EndFont(); }
394 /// Begin using this colour
395 bool BeginTextColour(const wxColour
& colour
) { return GetBuffer().BeginTextColour(colour
); }
397 /// End using a colour
398 bool EndTextColour() { return GetBuffer().EndTextColour(); }
400 /// Begin using alignment
401 bool BeginAlignment(wxTextAttrAlignment alignment
) { return GetBuffer().BeginAlignment(alignment
); }
404 bool EndAlignment() { return GetBuffer().EndAlignment(); }
406 /// Begin left indent
407 bool BeginLeftIndent(int leftIndent
, int leftSubIndent
= 0) { return GetBuffer().BeginLeftIndent(leftIndent
, leftSubIndent
); }
410 bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }
412 /// Begin right indent
413 bool BeginRightIndent(int rightIndent
) { return GetBuffer().BeginRightIndent(rightIndent
); }
416 bool EndRightIndent() { return GetBuffer().EndRightIndent(); }
418 /// Begin paragraph spacing
419 bool BeginParagraphSpacing(int before
, int after
) { return GetBuffer().BeginParagraphSpacing(before
, after
); }
421 /// End paragraph spacing
422 bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }
424 /// Begin line spacing
425 bool BeginLineSpacing(int lineSpacing
) { return GetBuffer().BeginLineSpacing(lineSpacing
); }
428 bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }
430 /// Begin numbered bullet
431 bool BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_ARABIC
|wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
432 { return GetBuffer().BeginNumberedBullet(bulletNumber
, leftIndent
, leftSubIndent
, bulletStyle
); }
434 /// End numbered bullet
435 bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }
437 /// Begin symbol bullet
438 bool BeginSymbolBullet(const wxString
& symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
439 { return GetBuffer().BeginSymbolBullet(symbol
, leftIndent
, leftSubIndent
, bulletStyle
); }
441 /// End symbol bullet
442 bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }
444 /// Begin standard bullet
445 bool BeginStandardBullet(const wxString
& bulletName
, int leftIndent
, int leftSubIndent
, int bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_STANDARD
)
446 { return GetBuffer().BeginStandardBullet(bulletName
, leftIndent
, leftSubIndent
, bulletStyle
); }
448 /// End standard bullet
449 bool EndStandardBullet() { return GetBuffer().EndStandardBullet(); }
451 /// Begin named character style
452 bool BeginCharacterStyle(const wxString
& characterStyle
) { return GetBuffer().BeginCharacterStyle(characterStyle
); }
454 /// End named character style
455 bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }
457 /// Begin named paragraph style
458 bool BeginParagraphStyle(const wxString
& paragraphStyle
) { return GetBuffer().BeginParagraphStyle(paragraphStyle
); }
460 /// End named character style
461 bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }
463 /// Begin named list style
464 bool BeginListStyle(const wxString
& listStyle
, int level
= 1, int number
= 1) { return GetBuffer().BeginListStyle(listStyle
, level
, number
); }
466 /// End named character style
467 bool EndListStyle() { return GetBuffer().EndListStyle(); }
470 bool BeginURL(const wxString
& url
, const wxString
& characterStyle
= wxEmptyString
) { return GetBuffer().BeginURL(url
, characterStyle
); }
473 bool EndURL() { return GetBuffer().EndURL(); }
475 /// Sets the default style to the style under the cursor
476 bool SetDefaultStyleToCursorStyle();
478 /// Clear the selection
479 virtual void SelectNone();
481 /// Select the word at the given character position
482 virtual bool SelectWord(long position
);
484 /// Get/set the selection range in character positions. -1, -1 means no selection.
485 /// The range is in API convention, i.e. a single character selection is denoted
487 wxRichTextRange
GetSelectionRange() const;
488 void SetSelectionRange(const wxRichTextRange
& range
);
490 /// Get/set the selection range in character positions. -1, -1 means no selection.
491 /// The range is in internal format, i.e. a single character selection is denoted
493 const wxRichTextRange
& GetInternalSelectionRange() const { return m_selectionRange
; }
494 void SetInternalSelectionRange(const wxRichTextRange
& range
) { m_selectionRange
= range
; }
496 /// Add a new paragraph of text to the end of the buffer
497 virtual wxRichTextRange
AddParagraph(const wxString
& text
);
500 virtual wxRichTextRange
AddImage(const wxImage
& image
);
502 /// Layout the buffer: which we must do before certain operations, such as
503 /// setting the caret position.
504 virtual bool LayoutContent(bool onlyVisibleRect
= false);
506 /// Move the caret to the given character position
507 virtual bool MoveCaret(long pos
, bool showAtLineStart
= false);
510 virtual bool MoveRight(int noPositions
= 1, int flags
= 0);
513 virtual bool MoveLeft(int noPositions
= 1, int flags
= 0);
516 virtual bool MoveUp(int noLines
= 1, int flags
= 0);
519 virtual bool MoveDown(int noLines
= 1, int flags
= 0);
521 /// Move to the end of the line
522 virtual bool MoveToLineEnd(int flags
= 0);
524 /// Move to the start of the line
525 virtual bool MoveToLineStart(int flags
= 0);
527 /// Move to the end of the paragraph
528 virtual bool MoveToParagraphEnd(int flags
= 0);
530 /// Move to the start of the paragraph
531 virtual bool MoveToParagraphStart(int flags
= 0);
533 /// Move to the start of the buffer
534 virtual bool MoveHome(int flags
= 0);
536 /// Move to the end of the buffer
537 virtual bool MoveEnd(int flags
= 0);
540 virtual bool PageUp(int noPages
= 1, int flags
= 0);
542 /// Move n pages down
543 virtual bool PageDown(int noPages
= 1, int flags
= 0);
545 /// Move n words left
546 virtual bool WordLeft(int noPages
= 1, int flags
= 0);
548 /// Move n words right
549 virtual bool WordRight(int noPages
= 1, int flags
= 0);
551 /// Returns the buffer associated with the control.
552 wxRichTextBuffer
& GetBuffer() { return m_buffer
; }
553 const wxRichTextBuffer
& GetBuffer() const { return m_buffer
; }
555 /// Start batching undo history for commands.
556 virtual bool BeginBatchUndo(const wxString
& cmdName
) { return m_buffer
.BeginBatchUndo(cmdName
); }
558 /// End batching undo history for commands.
559 virtual bool EndBatchUndo() { return m_buffer
.EndBatchUndo(); }
561 /// Are we batching undo history for commands?
562 virtual bool BatchingUndo() const { return m_buffer
.BatchingUndo(); }
564 /// Start suppressing undo history for commands.
565 virtual bool BeginSuppressUndo() { return m_buffer
.BeginSuppressUndo(); }
567 /// End suppressing undo history for commands.
568 virtual bool EndSuppressUndo() { return m_buffer
.EndSuppressUndo(); }
570 /// Are we suppressing undo history for commands?
571 virtual bool SuppressingUndo() const { return m_buffer
.SuppressingUndo(); }
573 /// Test if this whole range has character attributes of the specified kind. If any
574 /// of the attributes are different within the range, the test fails. You
575 /// can use this to implement, for example, bold button updating. style must have
576 /// flags indicating which attributes are of interest.
577 virtual bool HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
579 return GetBuffer().HasCharacterAttributes(range
.ToInternal(), style
);
582 /// Test if this whole range has paragraph attributes of the specified kind. If any
583 /// of the attributes are different within the range, the test fails. You
584 /// can use this to implement, for example, centering button updating. style must have
585 /// flags indicating which attributes are of interest.
586 virtual bool HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
588 return GetBuffer().HasParagraphAttributes(range
.ToInternal(), style
);
591 /// Is all of the selection bold?
592 virtual bool IsSelectionBold();
594 /// Is all of the selection italics?
595 virtual bool IsSelectionItalics();
597 /// Is all of the selection underlined?
598 virtual bool IsSelectionUnderlined();
600 /// Is all of the selection aligned according to the specified flag?
601 virtual bool IsSelectionAligned(wxTextAttrAlignment alignment
);
603 /// Apply bold to the selection
604 virtual bool ApplyBoldToSelection();
606 /// Apply italic to the selection
607 virtual bool ApplyItalicToSelection();
609 /// Apply underline to the selection
610 virtual bool ApplyUnderlineToSelection();
612 /// Apply alignment to the selection
613 virtual bool ApplyAlignmentToSelection(wxTextAttrAlignment alignment
);
615 /// Apply a named style to the selection
616 virtual bool ApplyStyle(wxRichTextStyleDefinition
* def
);
618 /// Set style sheet, if any
619 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
) { GetBuffer().SetStyleSheet(styleSheet
); }
620 wxRichTextStyleSheet
* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
622 /// Push style sheet to top of stack
623 bool PushStyleSheet(wxRichTextStyleSheet
* styleSheet
) { return GetBuffer().PushStyleSheet(styleSheet
); }
625 /// Pop style sheet from top of stack
626 wxRichTextStyleSheet
* PopStyleSheet() { return GetBuffer().PopStyleSheet(); }
628 /// Apply the style sheet to the buffer, for example if the styles have changed.
629 bool ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
= NULL
);
633 void Command(wxCommandEvent
& event
);
634 void OnDropFiles(wxDropFilesEvent
& event
);
635 void OnCaptureLost(wxMouseCaptureLostEvent
& event
);
636 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
638 void OnCut(wxCommandEvent
& event
);
639 void OnCopy(wxCommandEvent
& event
);
640 void OnPaste(wxCommandEvent
& event
);
641 void OnUndo(wxCommandEvent
& event
);
642 void OnRedo(wxCommandEvent
& event
);
643 void OnSelectAll(wxCommandEvent
& event
);
644 void OnImage(wxCommandEvent
& event
);
645 void OnClear(wxCommandEvent
& event
);
647 void OnUpdateCut(wxUpdateUIEvent
& event
);
648 void OnUpdateCopy(wxUpdateUIEvent
& event
);
649 void OnUpdatePaste(wxUpdateUIEvent
& event
);
650 void OnUpdateUndo(wxUpdateUIEvent
& event
);
651 void OnUpdateRedo(wxUpdateUIEvent
& event
);
652 void OnUpdateSelectAll(wxUpdateUIEvent
& event
);
653 void OnUpdateImage(wxUpdateUIEvent
& event
);
654 void OnUpdateClear(wxUpdateUIEvent
& event
);
656 // Show a context menu for Rich Edit controls (the standard
657 // EDIT control has one already)
658 void OnContextMenu(wxContextMenuEvent
& event
);
663 void OnPaint(wxPaintEvent
& event
);
664 void OnEraseBackground(wxEraseEvent
& event
);
667 void OnLeftClick(wxMouseEvent
& event
);
670 void OnLeftUp(wxMouseEvent
& event
);
673 void OnMoveMouse(wxMouseEvent
& event
);
675 /// Left-double-click
676 void OnLeftDClick(wxMouseEvent
& event
);
679 void OnMiddleClick(wxMouseEvent
& event
);
682 void OnRightClick(wxMouseEvent
& event
);
685 void OnChar(wxKeyEvent
& event
);
688 void OnSize(wxSizeEvent
& event
);
690 /// Setting/losing focus
691 void OnSetFocus(wxFocusEvent
& event
);
692 void OnKillFocus(wxFocusEvent
& event
);
694 /// Idle-time processing
695 void OnIdle(wxIdleEvent
& event
);
698 void OnScroll(wxScrollWinEvent
& event
);
700 /// Set font, and also default attributes
701 virtual bool SetFont(const wxFont
& font
);
703 /// Set up scrollbars, e.g. after a resize
704 virtual void SetupScrollbars(bool atTop
= false);
706 /// Keyboard navigation
707 virtual bool KeyboardNavigate(int keyCode
, int flags
);
709 /// Paint the background
710 virtual void PaintBackground(wxDC
& dc
);
712 /// Other user defined painting after everything else (i.e. all text) is painted
713 virtual void PaintAboveContent(wxDC
& WXUNUSED(dc
)) {}
715 #if wxRICHTEXT_BUFFERED_PAINTING
716 /// Recreate buffer bitmap if necessary
717 virtual bool RecreateBuffer(const wxSize
& size
= wxDefaultSize
);
721 virtual void DoWriteText(const wxString
& value
, int flags
= 0);
723 /// Should we inherit colours?
724 virtual bool ShouldInheritColours() const { return false; }
726 /// Position the caret
727 virtual void PositionCaret();
729 /// Extend the selection, returning true if the selection was
730 /// changed. Selections are in caret positions.
731 virtual bool ExtendSelection(long oldPosition
, long newPosition
, int flags
);
733 /// Scroll into view. This takes a _caret_ position.
734 virtual bool ScrollIntoView(long position
, int keyCode
);
736 /// Refresh the area affected by a selection change
737 bool RefreshForSelectionChange(const wxRichTextRange
& oldSelection
, const wxRichTextRange
& newSelection
);
739 /// The caret position is the character position just before the caret.
740 /// A value of -1 means the caret is at the start of the buffer.
741 void SetCaretPosition(long position
, bool showAtLineStart
= false) ;
742 long GetCaretPosition() const { return m_caretPosition
; }
744 /// The adjusted caret position is the character position adjusted to take
745 /// into account whether we're at the start of a paragraph, in which case
746 /// style information should be taken from the next position, not current one.
747 long GetAdjustedCaretPosition(long caretPos
) const;
749 /// Move caret one visual step forward: this may mean setting a flag
750 /// and keeping the same position if we're going from the end of one line
751 /// to the start of the next, which may be the exact same caret position.
752 void MoveCaretForward(long oldPosition
) ;
754 /// Move caret one visual step forward: this may mean setting a flag
755 /// and keeping the same position if we're going from the end of one line
756 /// to the start of the next, which may be the exact same caret position.
757 void MoveCaretBack(long oldPosition
) ;
759 /// Get the caret height and position for the given character position
760 bool GetCaretPositionForIndex(long position
, wxRect
& rect
);
762 /// Gets the line for the visible caret position. If the caret is
763 /// shown at the very end of the line, it means the next character is actually
764 /// on the following line. So let's get the line we're expecting to find
765 /// if this is the case.
766 wxRichTextLine
* GetVisibleLineForCaretPosition(long caretPosition
) const;
768 /// Gets the command processor
769 wxCommandProcessor
* GetCommandProcessor() const { return GetBuffer().GetCommandProcessor(); }
771 /// Delete content if there is a selection, e.g. when pressing a key.
772 /// Returns the new caret position in newPos, or leaves it if there
774 bool DeleteSelectedContent(long* newPos
= NULL
);
776 /// Transform logical to physical
777 wxPoint
GetPhysicalPoint(const wxPoint
& ptLogical
) const;
779 /// Transform physical to logical
780 wxPoint
GetLogicalPoint(const wxPoint
& ptPhysical
) const;
782 /// Finds the caret position for the next word. Direction
783 /// is 1 (forward) or -1 (backwards).
784 virtual long FindNextWordPosition(int direction
= 1) const;
786 /// Is the given position visible on the screen?
787 bool IsPositionVisible(long pos
) const;
789 /// Returns the first visible position in the current view
790 long GetFirstVisiblePosition() const;
792 /// Returns the caret position since the default formatting was changed. As
793 /// soon as this position changes, we no longer reflect the default style
794 /// in the UI. A value of -2 means that we should only reflect the style of the
795 /// content under the caret.
796 long GetCaretPositionForDefaultStyle() const { return m_caretPositionForDefaultStyle
; }
798 /// Set the caret position for the default style that the user is selecting.
799 void SetCaretPositionForDefaultStyle(long pos
) { m_caretPositionForDefaultStyle
= pos
; }
801 /// Should the UI reflect the default style chosen by the user, rather than the style under
803 bool IsDefaultStyleShowing() const { return m_caretPositionForDefaultStyle
!= -2; }
805 /// Convenience function that tells the control to start reflecting the default
806 /// style, since the user is changing it.
807 void SetAndShowDefaultStyle(const wxRichTextAttr
& attr
)
809 SetDefaultStyle(attr
);
810 SetCaretPositionForDefaultStyle(GetCaretPosition());
813 /// Get the first visible point in the window
814 wxPoint
GetFirstVisiblePoint() const;
818 /// Font names take a long time to retrieve, so cache them (on demand)
819 static const wxArrayString
& GetAvailableFontNames();
820 static void ClearAvailableFontNames();
822 WX_FORWARD_TO_SCROLL_HELPER()
824 // implement wxTextEntry methods
825 virtual wxString
DoGetValue() const;
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 wxWindow
*GetEditableWindow() { return this; }
839 virtual GtkEditable
*GetEditable() const { return NULL
; }
840 virtual GtkEntry
*GetEntry() const { return NULL
; }
842 #endif // !__WXUNIVERSAL__
847 virtual wxSize
DoGetBestSize() const ;
849 virtual void DoSetValue(const wxString
& value
, int flags
= 0);
851 virtual void DoThaw();
856 #if wxRICHTEXT_BUFFERED_PAINTING
858 wxBitmap m_bufferBitmap
;
862 wxRichTextBuffer m_buffer
;
864 wxMenu
* m_contextMenu
;
866 /// Caret position (1 less than the character position, so -1 is the
867 /// first caret position).
868 long m_caretPosition
;
870 /// Caret position when the default formatting has been changed. As
871 /// soon as this position changes, we no longer reflect the default style
873 long m_caretPositionForDefaultStyle
;
875 /// Selection range in character positions. -2, -2 means no selection.
876 wxRichTextRange m_selectionRange
;
878 /// Anchor so we know how to extend the selection
879 /// It's a caret position since it's between two characters.
880 long m_selectionAnchor
;
885 /// Are we showing the caret position at the start of a line
886 /// instead of at the end of the previous one?
887 bool m_caretAtLineStart
;
889 /// Are we dragging a selection?
892 /// Start position for drag
895 /// Do we need full layout in idle?
896 bool m_fullLayoutRequired
;
897 wxLongLong m_fullLayoutTime
;
898 long m_fullLayoutSavedPosition
;
900 /// Threshold for doing delayed layout
901 long m_delayedLayoutThreshold
;
904 wxCursor m_textCursor
;
905 wxCursor m_urlCursor
;
907 static wxArrayString sm_availableFontNames
;
908 /// The wxRichTextObject object under mouse if any
909 wxRichTextObject
* m_currentObject
;
910 long m_imagePropertyId
;
914 * wxRichTextEvent - the event class for wxRichTextCtrl notifications
917 class WXDLLIMPEXP_RICHTEXT wxRichTextEvent
: public wxNotifyEvent
920 wxRichTextEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
921 : wxNotifyEvent(commandType
, winid
),
922 m_flags(0), m_position(-1), m_oldStyleSheet(NULL
), m_newStyleSheet(NULL
),
926 wxRichTextEvent(const wxRichTextEvent
& event
)
927 : wxNotifyEvent(event
),
928 m_flags(event
.m_flags
), m_position(-1),
929 m_oldStyleSheet(event
.m_oldStyleSheet
), m_newStyleSheet(event
.m_newStyleSheet
),
933 long GetPosition() const { return m_position
; }
934 void SetPosition(long pos
) { m_position
= pos
; }
936 int GetFlags() const { return m_flags
; }
937 void SetFlags(int flags
) { m_flags
= flags
; }
939 wxRichTextStyleSheet
* GetOldStyleSheet() const { return m_oldStyleSheet
; }
940 void SetOldStyleSheet(wxRichTextStyleSheet
* sheet
) { m_oldStyleSheet
= sheet
; }
942 wxRichTextStyleSheet
* GetNewStyleSheet() const { return m_newStyleSheet
; }
943 void SetNewStyleSheet(wxRichTextStyleSheet
* sheet
) { m_newStyleSheet
= sheet
; }
945 const wxRichTextRange
& GetRange() const { return m_range
; }
946 void SetRange(const wxRichTextRange
& range
) { m_range
= range
; }
948 wxChar
GetCharacter() const { return m_char
; }
949 void SetCharacter(wxChar ch
) { m_char
= ch
; }
951 virtual wxEvent
*Clone() const { return new wxRichTextEvent(*this); }
956 wxRichTextStyleSheet
* m_oldStyleSheet
;
957 wxRichTextStyleSheet
* m_newStyleSheet
;
958 wxRichTextRange m_range
;
962 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent
)
966 * wxRichTextCtrl events
968 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
, wxRichTextEvent
);
969 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
, wxRichTextEvent
);
970 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
, wxRichTextEvent
);
971 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
, wxRichTextEvent
);
972 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_RETURN
, wxRichTextEvent
);
973 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_CHARACTER
, wxRichTextEvent
);
974 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_DELETE
, wxRichTextEvent
);
976 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING
, wxRichTextEvent
);
977 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED
, wxRichTextEvent
);
978 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING
, wxRichTextEvent
);
979 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED
, wxRichTextEvent
);
981 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED
, wxRichTextEvent
);
982 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED
, wxRichTextEvent
);
983 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED
, wxRichTextEvent
);
984 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED
, wxRichTextEvent
);
985 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT
, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET
, wxRichTextEvent
);
987 typedef void (wxEvtHandler::*wxRichTextEventFunction
)(wxRichTextEvent
&);
989 #define wxRichTextEventHandler(func) \
990 wxEVENT_HANDLER_CAST(wxRichTextEventFunction, func)
992 #define EVT_RICHTEXT_LEFT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
993 #define EVT_RICHTEXT_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
994 #define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
995 #define EVT_RICHTEXT_LEFT_DCLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, wxRichTextEventHandler( fn ), NULL ),
996 #define EVT_RICHTEXT_RETURN(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, wxRichTextEventHandler( fn ), NULL ),
997 #define EVT_RICHTEXT_CHARACTER(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CHARACTER, id, -1, wxRichTextEventHandler( fn ), NULL ),
998 #define EVT_RICHTEXT_DELETE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_DELETE, id, -1, wxRichTextEventHandler( fn ), NULL ),
1000 #define EVT_RICHTEXT_STYLESHEET_CHANGING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, id, -1, wxRichTextEventHandler( fn ), NULL ),
1001 #define EVT_RICHTEXT_STYLESHEET_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1002 #define EVT_RICHTEXT_STYLESHEET_REPLACING(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, id, -1, wxRichTextEventHandler( fn ), NULL ),
1003 #define EVT_RICHTEXT_STYLESHEET_REPLACED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1005 #define EVT_RICHTEXT_CONTENT_INSERTED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1006 #define EVT_RICHTEXT_CONTENT_DELETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1007 #define EVT_RICHTEXT_STYLE_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1008 #define EVT_RICHTEXT_SELECTION_CHANGED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, id, -1, wxRichTextEventHandler( fn ), NULL ),
1009 #define EVT_RICHTEXT_BUFFER_RESET(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, id, -1, wxRichTextEventHandler( fn ), NULL ),
1015 // _WX_RICHTEXTCTRL_H_