1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richeditctrl.cpp
3 // Purpose: A rich edit control
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/richtext/richtextctrl.h"
22 #include "wx/richtext/richtextstyles.h"
26 #include "wx/settings.h"
29 #include "wx/textfile.h"
31 #include "wx/filename.h"
32 #include "wx/dcbuffer.h"
33 #include "wx/arrimpl.cpp"
34 #include "wx/fontenum.h"
36 // DLL options compatibility check:
38 WX_CHECK_BUILD_OPTIONS("wxRichTextCtrl")
40 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
)
41 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
)
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RETURN
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_CHARACTER
)
46 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_DELETE
)
48 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING
)
49 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED
)
50 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING
)
51 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED
)
53 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED
)
54 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED
)
55 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED
)
56 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED
)
57 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_BUFFER_RESET
)
59 #if wxRICHTEXT_USE_OWN_CARET
64 * This implements a non-flashing cursor in case there
65 * are platform-specific problems with the generic caret.
66 * wxRICHTEXT_USE_OWN_CARET is set in richtextbuffer.h.
69 class wxRichTextCaret
: public wxCaret
74 // default - use Create()
75 wxRichTextCaret() { Init(); }
76 // creates a block caret associated with the given window
77 wxRichTextCaret(wxRichTextCtrl
*window
, int width
, int height
)
78 : wxCaret(window
, width
, height
) { Init(); m_richTextCtrl
= window
; }
79 wxRichTextCaret(wxRichTextCtrl
*window
, const wxSize
& size
)
80 : wxCaret(window
, size
) { Init(); m_richTextCtrl
= window
; }
82 virtual ~wxRichTextCaret();
87 // called by wxWindow (not using the event tables)
88 virtual void OnSetFocus();
89 virtual void OnKillFocus();
91 // draw the caret on the given DC
92 void DoDraw(wxDC
*dc
);
94 // get the visible count
95 int GetVisibleCount() const { return m_countVisible
; }
97 // delay repositioning
98 bool GetNeedsUpdate() const { return m_needsUpdate
; }
99 void SetNeedsUpdate(bool needsUpdate
= true ) { m_needsUpdate
= needsUpdate
; }
102 virtual void DoShow();
103 virtual void DoHide();
104 virtual void DoMove();
105 virtual void DoSize();
115 bool m_hasFocus
; // true => our window has focus
116 bool m_needsUpdate
; // must be repositioned
118 wxRichTextCtrl
* m_richTextCtrl
;
122 IMPLEMENT_CLASS( wxRichTextCtrl
, wxControl
)
124 IMPLEMENT_CLASS( wxRichTextEvent
, wxNotifyEvent
)
126 BEGIN_EVENT_TABLE( wxRichTextCtrl
, wxControl
)
127 EVT_PAINT(wxRichTextCtrl::OnPaint
)
128 EVT_ERASE_BACKGROUND(wxRichTextCtrl::OnEraseBackground
)
129 EVT_IDLE(wxRichTextCtrl::OnIdle
)
130 EVT_SCROLLWIN(wxRichTextCtrl::OnScroll
)
131 EVT_LEFT_DOWN(wxRichTextCtrl::OnLeftClick
)
132 EVT_MOTION(wxRichTextCtrl::OnMoveMouse
)
133 EVT_LEFT_UP(wxRichTextCtrl::OnLeftUp
)
134 EVT_RIGHT_DOWN(wxRichTextCtrl::OnRightClick
)
135 EVT_MIDDLE_DOWN(wxRichTextCtrl::OnMiddleClick
)
136 EVT_LEFT_DCLICK(wxRichTextCtrl::OnLeftDClick
)
137 EVT_CHAR(wxRichTextCtrl::OnChar
)
138 EVT_SIZE(wxRichTextCtrl::OnSize
)
139 EVT_SET_FOCUS(wxRichTextCtrl::OnSetFocus
)
140 EVT_KILL_FOCUS(wxRichTextCtrl::OnKillFocus
)
141 EVT_MOUSE_CAPTURE_LOST(wxRichTextCtrl::OnCaptureLost
)
142 EVT_CONTEXT_MENU(wxRichTextCtrl::OnContextMenu
)
143 EVT_SYS_COLOUR_CHANGED(wxRichTextCtrl::OnSysColourChanged
)
145 EVT_MENU(wxID_UNDO
, wxRichTextCtrl::OnUndo
)
146 EVT_UPDATE_UI(wxID_UNDO
, wxRichTextCtrl::OnUpdateUndo
)
148 EVT_MENU(wxID_REDO
, wxRichTextCtrl::OnRedo
)
149 EVT_UPDATE_UI(wxID_REDO
, wxRichTextCtrl::OnUpdateRedo
)
151 EVT_MENU(wxID_COPY
, wxRichTextCtrl::OnCopy
)
152 EVT_UPDATE_UI(wxID_COPY
, wxRichTextCtrl::OnUpdateCopy
)
154 EVT_MENU(wxID_PASTE
, wxRichTextCtrl::OnPaste
)
155 EVT_UPDATE_UI(wxID_PASTE
, wxRichTextCtrl::OnUpdatePaste
)
157 EVT_MENU(wxID_CUT
, wxRichTextCtrl::OnCut
)
158 EVT_UPDATE_UI(wxID_CUT
, wxRichTextCtrl::OnUpdateCut
)
160 EVT_MENU(wxID_CLEAR
, wxRichTextCtrl::OnClear
)
161 EVT_UPDATE_UI(wxID_CLEAR
, wxRichTextCtrl::OnUpdateClear
)
163 EVT_MENU(wxID_SELECTALL
, wxRichTextCtrl::OnSelectAll
)
164 EVT_UPDATE_UI(wxID_SELECTALL
, wxRichTextCtrl::OnUpdateSelectAll
)
171 wxArrayString
wxRichTextCtrl::sm_availableFontNames
;
173 wxRichTextCtrl::wxRichTextCtrl()
174 : wxScrollHelper(this)
179 wxRichTextCtrl::wxRichTextCtrl(wxWindow
* parent
,
181 const wxString
& value
,
185 const wxValidator
& validator
,
186 const wxString
& name
)
187 : wxScrollHelper(this)
190 Create(parent
, id
, value
, pos
, size
, style
, validator
, name
);
194 bool wxRichTextCtrl::Create( wxWindow
* parent
, wxWindowID id
, const wxString
& value
, const wxPoint
& pos
, const wxSize
& size
, long style
,
195 const wxValidator
& validator
, const wxString
& name
)
197 if (!wxControl::Create(parent
, id
, pos
, size
,
198 style
|wxFULL_REPAINT_ON_RESIZE
,
204 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
207 if (style
& wxTE_READONLY
)
210 // The base attributes must all have default values
211 wxTextAttr attributes
;
212 attributes
.SetFont(GetFont());
213 attributes
.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
214 attributes
.SetAlignment(wxTEXT_ALIGNMENT_LEFT
);
215 attributes
.SetLineSpacing(10);
216 attributes
.SetParagraphSpacingAfter(10);
217 attributes
.SetParagraphSpacingBefore(0);
218 attributes
.SetTextEffects(0);
219 attributes
.SetTextEffectFlags(wxTEXT_ATTR_EFFECT_STRIKETHROUGH
|wxTEXT_ATTR_EFFECT_CAPITALS
);
221 SetBasicStyle(attributes
);
223 // The default attributes will be merged with base attributes, so
224 // can be empty to begin with
225 wxTextAttr defaultAttributes
;
226 SetDefaultStyle(defaultAttributes
);
228 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
229 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
232 GetBuffer().SetRichTextCtrl(this);
234 #if wxRICHTEXT_USE_OWN_CARET
235 SetCaret(new wxRichTextCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH
, 16));
237 SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH
, 16));
240 // Tell the sizers to use the given or best size
241 SetInitialSize(size
);
243 #if wxRICHTEXT_BUFFERED_PAINTING
245 RecreateBuffer(size
);
248 m_textCursor
= wxCursor(wxCURSOR_IBEAM
);
249 m_urlCursor
= wxCursor(wxCURSOR_HAND
);
251 SetCursor(m_textCursor
);
253 if (!value
.IsEmpty())
256 GetBuffer().AddEventHandler(this);
261 wxRichTextCtrl::~wxRichTextCtrl()
263 GetBuffer().RemoveEventHandler(this);
265 delete m_contextMenu
;
268 /// Member initialisation
269 void wxRichTextCtrl::Init()
271 m_contextMenu
= NULL
;
273 m_caretPosition
= -1;
274 m_selectionRange
.SetRange(-2, -2);
275 m_selectionAnchor
= -2;
277 m_caretAtLineStart
= false;
279 m_fullLayoutRequired
= false;
280 m_fullLayoutTime
= 0;
281 m_fullLayoutSavedPosition
= 0;
282 m_delayedLayoutThreshold
= wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD
;
283 m_caretPositionForDefaultStyle
= -2;
286 void wxRichTextCtrl::DoThaw()
288 if (GetBuffer().GetDirty())
296 void wxRichTextCtrl::Clear()
298 m_buffer
.ResetAndClearCommands();
299 m_buffer
.SetDirty(true);
300 m_caretPosition
= -1;
301 m_caretPositionForDefaultStyle
= -2;
302 m_caretAtLineStart
= false;
303 m_selectionRange
.SetRange(-2, -2);
313 wxTextCtrl::SendTextUpdatedEvent(this);
317 void wxRichTextCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
319 #if !wxRICHTEXT_USE_OWN_CARET
320 if (GetCaret() && !IsFrozen())
325 #if wxRICHTEXT_BUFFERED_PAINTING
326 wxBufferedPaintDC
dc(this, m_bufferBitmap
);
336 dc
.SetFont(GetFont());
338 // Paint the background
341 // wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
343 wxRect
drawingArea(GetUpdateRegion().GetBox());
344 drawingArea
.SetPosition(GetLogicalPoint(drawingArea
.GetPosition()));
346 wxRect
availableSpace(GetClientSize());
347 if (GetBuffer().GetDirty())
349 GetBuffer().Layout(dc
, availableSpace
, wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
);
350 GetBuffer().SetDirty(false);
354 GetBuffer().Draw(dc
, GetBuffer().GetRange(), GetInternalSelectionRange(), drawingArea
, 0 /* descent */, 0 /* flags */);
355 #if wxRICHTEXT_USE_OWN_CARET
356 if (GetCaret()->IsVisible())
358 ((wxRichTextCaret
*) GetCaret())->DoDraw(& dc
);
363 #if !wxRICHTEXT_USE_OWN_CARET
370 // Empty implementation, to prevent flicker
371 void wxRichTextCtrl::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
375 void wxRichTextCtrl::OnSetFocus(wxFocusEvent
& WXUNUSED(event
))
379 #if !wxRICHTEXT_USE_OWN_CARET
385 #if defined(__WXGTK__) && !wxRICHTEXT_USE_OWN_CARET
386 // Work around dropouts when control is focused
394 void wxRichTextCtrl::OnKillFocus(wxFocusEvent
& WXUNUSED(event
))
399 #if defined(__WXGTK__) && !wxRICHTEXT_USE_OWN_CARET
400 // Work around dropouts when control is focused
408 void wxRichTextCtrl::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
414 void wxRichTextCtrl::OnLeftClick(wxMouseEvent
& event
)
420 dc
.SetFont(GetFont());
423 int hit
= GetBuffer().HitTest(dc
, event
.GetLogicalPosition(dc
), position
);
425 if (hit
!= wxRICHTEXT_HITTEST_NONE
)
427 m_dragStart
= event
.GetLogicalPosition(dc
);
431 bool caretAtLineStart
= false;
433 if (hit
& wxRICHTEXT_HITTEST_BEFORE
)
435 // If we're at the start of a line (but not first in para)
436 // then we should keep the caret showing at the start of the line
437 // by showing the m_caretAtLineStart flag.
438 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(position
);
439 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(position
);
441 if (line
&& para
&& line
->GetAbsoluteRange().GetStart() == position
&& para
->GetRange().GetStart() != position
)
442 caretAtLineStart
= true;
446 long oldCaretPos
= m_caretPosition
;
448 MoveCaret(position
, caretAtLineStart
);
450 if (event
.ShiftDown())
452 if (m_selectionRange
.GetStart() == -2)
453 ExtendSelection(oldCaretPos
, m_caretPosition
, wxRICHTEXT_SHIFT_DOWN
);
455 ExtendSelection(m_caretPosition
, m_caretPosition
, wxRICHTEXT_SHIFT_DOWN
);
465 void wxRichTextCtrl::OnLeftUp(wxMouseEvent
& event
)
470 if (GetCapture() == this)
473 // See if we clicked on a URL
476 dc
.SetFont(GetFont());
479 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
480 int hit
= GetBuffer().HitTest(dc
, logicalPt
, position
);
482 if ((hit
!= wxRICHTEXT_HITTEST_NONE
) && !(hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
484 wxRichTextEvent
cmdEvent(
485 wxEVT_COMMAND_RICHTEXT_LEFT_CLICK
,
487 cmdEvent
.SetEventObject(this);
488 cmdEvent
.SetPosition(m_caretPosition
+1);
490 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
493 if (GetStyle(position
, attr
))
495 if (attr
.HasFlag(wxTEXT_ATTR_URL
))
497 wxString urlTarget
= attr
.GetURL();
498 if (!urlTarget
.IsEmpty())
500 wxMouseEvent
mouseEvent(event
);
502 long startPos
= 0, endPos
= 0;
503 wxRichTextObject
* obj
= GetBuffer().GetLeafObjectAtPosition(position
);
506 startPos
= obj
->GetRange().GetStart();
507 endPos
= obj
->GetRange().GetEnd();
510 wxTextUrlEvent
urlEvent(GetId(), mouseEvent
, startPos
, endPos
);
511 InitCommandEvent(urlEvent
);
513 urlEvent
.SetString(urlTarget
);
515 GetEventHandler()->ProcessEvent(urlEvent
);
525 void wxRichTextCtrl::OnMoveMouse(wxMouseEvent
& event
)
529 dc
.SetFont(GetFont());
532 wxPoint logicalPt
= event
.GetLogicalPosition(dc
);
533 int hit
= GetBuffer().HitTest(dc
, logicalPt
, position
);
535 // See if we need to change the cursor
538 if (hit
!= wxRICHTEXT_HITTEST_NONE
&& !(hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
541 if (GetStyle(position
, attr
))
543 if (attr
.HasFlag(wxTEXT_ATTR_URL
))
545 SetCursor(m_urlCursor
);
547 else if (!attr
.HasFlag(wxTEXT_ATTR_URL
))
549 SetCursor(m_textCursor
);
554 SetCursor(m_textCursor
);
557 if (!event
.Dragging())
563 if (m_dragging
&& hit
!= wxRICHTEXT_HITTEST_NONE
)
565 // TODO: test closeness
567 bool caretAtLineStart
= false;
569 if (hit
& wxRICHTEXT_HITTEST_BEFORE
)
571 // If we're at the start of a line (but not first in para)
572 // then we should keep the caret showing at the start of the line
573 // by showing the m_caretAtLineStart flag.
574 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(position
);
575 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(position
);
577 if (line
&& para
&& line
->GetAbsoluteRange().GetStart() == position
&& para
->GetRange().GetStart() != position
)
578 caretAtLineStart
= true;
582 if (m_caretPosition
!= position
)
584 ExtendSelection(m_caretPosition
, position
, wxRICHTEXT_SHIFT_DOWN
);
586 MoveCaret(position
, caretAtLineStart
);
592 void wxRichTextCtrl::OnRightClick(wxMouseEvent
& event
)
596 wxRichTextEvent
cmdEvent(
597 wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK
,
599 cmdEvent
.SetEventObject(this);
600 cmdEvent
.SetPosition(m_caretPosition
+1);
602 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
606 /// Left-double-click
607 void wxRichTextCtrl::OnLeftDClick(wxMouseEvent
& WXUNUSED(event
))
609 wxRichTextEvent
cmdEvent(
610 wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK
,
612 cmdEvent
.SetEventObject(this);
613 cmdEvent
.SetPosition(m_caretPosition
+1);
615 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
617 SelectWord(GetCaretPosition()+1);
622 void wxRichTextCtrl::OnMiddleClick(wxMouseEvent
& event
)
624 wxRichTextEvent
cmdEvent(
625 wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK
,
627 cmdEvent
.SetEventObject(this);
628 cmdEvent
.SetPosition(m_caretPosition
+1);
630 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
635 void wxRichTextCtrl::OnChar(wxKeyEvent
& event
)
639 flags
|= wxRICHTEXT_CTRL_DOWN
;
640 if (event
.ShiftDown())
641 flags
|= wxRICHTEXT_SHIFT_DOWN
;
643 flags
|= wxRICHTEXT_ALT_DOWN
;
645 if (event
.GetKeyCode() == WXK_LEFT
||
646 event
.GetKeyCode() == WXK_RIGHT
||
647 event
.GetKeyCode() == WXK_UP
||
648 event
.GetKeyCode() == WXK_DOWN
||
649 event
.GetKeyCode() == WXK_HOME
||
650 event
.GetKeyCode() == WXK_PAGEUP
||
651 event
.GetKeyCode() == WXK_PAGEDOWN
||
652 event
.GetKeyCode() == WXK_END
||
654 event
.GetKeyCode() == WXK_NUMPAD_LEFT
||
655 event
.GetKeyCode() == WXK_NUMPAD_RIGHT
||
656 event
.GetKeyCode() == WXK_NUMPAD_UP
||
657 event
.GetKeyCode() == WXK_NUMPAD_DOWN
||
658 event
.GetKeyCode() == WXK_NUMPAD_HOME
||
659 event
.GetKeyCode() == WXK_NUMPAD_PAGEUP
||
660 event
.GetKeyCode() == WXK_NUMPAD_PAGEDOWN
||
661 event
.GetKeyCode() == WXK_NUMPAD_END
)
663 KeyboardNavigate(event
.GetKeyCode(), flags
);
667 // all the other keys modify the controls contents which shouldn't be
668 // possible if we're read-only
675 if (event
.GetKeyCode() == WXK_RETURN
)
677 SetDefaultStyleToCursorStyle();
678 BeginBatchUndo(_("Insert Text"));
680 long newPos
= m_caretPosition
;
682 DeleteSelectedContent(& newPos
);
684 if (event
.ShiftDown())
687 text
= wxRichTextLineBreakChar
;
688 GetBuffer().InsertTextWithUndo(newPos
+1, text
, this);
691 GetBuffer().InsertNewlineWithUndo(newPos
+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
|wxRICHTEXT_INSERT_INTERACTIVE
);
695 ScrollIntoView(m_caretPosition
, WXK_RIGHT
);
697 wxRichTextEvent
cmdEvent(
698 wxEVT_COMMAND_RICHTEXT_RETURN
,
700 cmdEvent
.SetEventObject(this);
701 cmdEvent
.SetFlags(flags
);
702 cmdEvent
.SetPosition(newPos
+1);
704 if (!GetEventHandler()->ProcessEvent(cmdEvent
))
706 // Generate conventional event
707 wxCommandEvent
textEvent(wxEVT_COMMAND_TEXT_ENTER
, GetId());
708 InitCommandEvent(textEvent
);
710 GetEventHandler()->ProcessEvent(textEvent
);
714 else if (event
.GetKeyCode() == WXK_BACK
)
716 BeginBatchUndo(_("Delete Text"));
718 // Submit range in character positions, which are greater than caret positions,
719 // so subtract 1 for deleted character and add 1 for conversion to character position.
720 if (m_caretPosition
> -1 && !HasSelection())
722 bool processed
= false;
725 long pos
= wxRichTextCtrl::FindNextWordPosition(-1);
726 if (pos
!= -1 && (pos
< m_caretPosition
))
728 GetBuffer().DeleteRangeWithUndo(wxRichTextRange(pos
+1, m_caretPosition
), this);
734 GetBuffer().DeleteRangeWithUndo(wxRichTextRange(m_caretPosition
, m_caretPosition
), this);
737 DeleteSelectedContent();
741 if (GetLastPosition() == -1)
745 m_caretPosition
= -1;
749 ScrollIntoView(m_caretPosition
, WXK_LEFT
);
751 wxRichTextEvent
cmdEvent(
752 wxEVT_COMMAND_RICHTEXT_DELETE
,
754 cmdEvent
.SetEventObject(this);
755 cmdEvent
.SetFlags(flags
);
756 cmdEvent
.SetPosition(m_caretPosition
+1);
757 GetEventHandler()->ProcessEvent(cmdEvent
);
761 else if (event
.GetKeyCode() == WXK_DELETE
)
763 BeginBatchUndo(_("Delete Text"));
765 // Submit range in character positions, which are greater than caret positions,
766 if (m_caretPosition
< GetBuffer().GetRange().GetEnd()+1 && !HasSelection())
768 GetBuffer().DeleteRangeWithUndo(wxRichTextRange(m_caretPosition
+1, m_caretPosition
+1), this);
771 DeleteSelectedContent();
775 if (GetLastPosition() == -1)
779 m_caretPosition
= -1;
783 wxRichTextEvent
cmdEvent(
784 wxEVT_COMMAND_RICHTEXT_DELETE
,
786 cmdEvent
.SetEventObject(this);
787 cmdEvent
.SetFlags(flags
);
788 cmdEvent
.SetPosition(m_caretPosition
+1);
789 GetEventHandler()->ProcessEvent(cmdEvent
);
795 long keycode
= event
.GetKeyCode();
868 case WXK_NUMPAD_SPACE
:
870 case WXK_NUMPAD_ENTER
:
875 case WXK_NUMPAD_HOME
:
876 case WXK_NUMPAD_LEFT
:
878 case WXK_NUMPAD_RIGHT
:
879 case WXK_NUMPAD_DOWN
:
880 case WXK_NUMPAD_PAGEUP
:
881 case WXK_NUMPAD_PAGEDOWN
:
883 case WXK_NUMPAD_BEGIN
:
884 case WXK_NUMPAD_INSERT
:
885 case WXK_NUMPAD_DELETE
:
886 case WXK_NUMPAD_EQUAL
:
887 case WXK_NUMPAD_MULTIPLY
:
889 case WXK_NUMPAD_SEPARATOR
:
890 case WXK_NUMPAD_SUBTRACT
:
891 case WXK_NUMPAD_DECIMAL
:
892 case WXK_WINDOWS_LEFT
:
900 if (event
.CmdDown() || event
.AltDown())
906 wxRichTextEvent
cmdEvent(
907 wxEVT_COMMAND_RICHTEXT_CHARACTER
,
909 cmdEvent
.SetEventObject(this);
910 cmdEvent
.SetFlags(flags
);
912 cmdEvent
.SetCharacter(event
.GetUnicodeKey());
914 cmdEvent
.SetCharacter((wxChar
) keycode
);
916 cmdEvent
.SetPosition(m_caretPosition
+1);
918 if (keycode
== wxT('\t'))
920 // See if we need to promote or demote the selection or paragraph at the cursor
921 // position, instead of inserting a tab.
922 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
923 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(pos
);
924 if (para
&& para
->GetRange().GetStart() == pos
&& para
->GetAttributes().HasListStyleName())
926 wxRichTextRange range
;
928 range
= GetSelectionRange();
930 range
= para
->GetRange().FromInternal();
932 int promoteBy
= event
.ShiftDown() ? 1 : -1;
934 PromoteList(promoteBy
, range
, NULL
);
936 GetEventHandler()->ProcessEvent(cmdEvent
);
942 SetDefaultStyleToCursorStyle();
943 BeginBatchUndo(_("Insert Text"));
945 long newPos
= m_caretPosition
;
946 DeleteSelectedContent(& newPos
);
949 wxString str
= event
.GetUnicodeKey();
951 wxString str
= (wxChar
) event
.GetKeyCode();
953 GetBuffer().InsertTextWithUndo(newPos
+1, str
, this, 0);
957 ScrollIntoView(m_caretPosition
, WXK_RIGHT
);
959 GetEventHandler()->ProcessEvent(cmdEvent
);
967 /// Delete content if there is a selection, e.g. when pressing a key.
968 bool wxRichTextCtrl::DeleteSelectedContent(long* newPos
)
972 long pos
= m_selectionRange
.GetStart();
973 GetBuffer().DeleteRangeWithUndo(m_selectionRange
, this);
974 m_selectionRange
.SetRange(-2, -2);
984 /// Keyboard navigation
988 Left: left one character
989 Right: right one character
992 Ctrl-Left: left one word
993 Ctrl-Right: right one word
994 Ctrl-Up: previous paragraph start
995 Ctrl-Down: next start of paragraph
998 Ctrl-Home: start of document
999 Ctrl-End: end of document
1000 Page-Up: Up a screen
1001 Page-Down: Down a screen
1005 Ctrl-Alt-PgUp: Start of window
1006 Ctrl-Alt-PgDn: End of window
1007 F8: Start selection mode
1008 Esc: End selection mode
1010 Adding Shift does the above but starts/extends selection.
1015 bool wxRichTextCtrl::KeyboardNavigate(int keyCode
, int flags
)
1017 bool success
= false;
1019 if (keyCode
== WXK_RIGHT
|| keyCode
== WXK_NUMPAD_RIGHT
)
1021 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1022 success
= WordRight(1, flags
);
1024 success
= MoveRight(1, flags
);
1026 else if (keyCode
== WXK_LEFT
|| keyCode
== WXK_NUMPAD_LEFT
)
1028 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1029 success
= WordLeft(1, flags
);
1031 success
= MoveLeft(1, flags
);
1033 else if (keyCode
== WXK_UP
|| keyCode
== WXK_NUMPAD_UP
)
1035 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1036 success
= MoveToParagraphStart(flags
);
1038 success
= MoveUp(1, flags
);
1040 else if (keyCode
== WXK_DOWN
|| keyCode
== WXK_NUMPAD_DOWN
)
1042 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1043 success
= MoveToParagraphEnd(flags
);
1045 success
= MoveDown(1, flags
);
1047 else if (keyCode
== WXK_PAGEUP
|| keyCode
== WXK_NUMPAD_PAGEUP
)
1049 success
= PageUp(1, flags
);
1051 else if (keyCode
== WXK_PAGEDOWN
|| keyCode
== WXK_NUMPAD_PAGEDOWN
)
1053 success
= PageDown(1, flags
);
1055 else if (keyCode
== WXK_HOME
|| keyCode
== WXK_NUMPAD_HOME
)
1057 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1058 success
= MoveHome(flags
);
1060 success
= MoveToLineStart(flags
);
1062 else if (keyCode
== WXK_END
|| keyCode
== WXK_NUMPAD_END
)
1064 if (flags
& wxRICHTEXT_CTRL_DOWN
)
1065 success
= MoveEnd(flags
);
1067 success
= MoveToLineEnd(flags
);
1072 ScrollIntoView(m_caretPosition
, keyCode
);
1078 /// Extend the selection. Selections are in caret positions.
1079 bool wxRichTextCtrl::ExtendSelection(long oldPos
, long newPos
, int flags
)
1081 if (flags
& wxRICHTEXT_SHIFT_DOWN
)
1083 wxRichTextRange oldSelection
= m_selectionRange
;
1085 // If not currently selecting, start selecting
1086 if (m_selectionRange
.GetStart() == -2)
1088 m_selectionAnchor
= oldPos
;
1090 if (oldPos
> newPos
)
1091 m_selectionRange
.SetRange(newPos
+1, oldPos
);
1093 m_selectionRange
.SetRange(oldPos
+1, newPos
);
1097 // Always ensure that the selection range start is greater than
1099 if (newPos
> m_selectionAnchor
)
1100 m_selectionRange
.SetRange(m_selectionAnchor
+1, newPos
);
1102 m_selectionRange
.SetRange(newPos
+1, m_selectionAnchor
);
1105 RefreshForSelectionChange(oldSelection
, m_selectionRange
);
1107 if (m_selectionRange
.GetStart() > m_selectionRange
.GetEnd())
1109 wxLogDebug(wxT("Strange selection range"));
1118 /// Scroll into view, returning true if we scrolled.
1119 /// This takes a _caret_ position.
1120 bool wxRichTextCtrl::ScrollIntoView(long position
, int keyCode
)
1122 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(position
);
1128 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
1130 int startXUnits
, startYUnits
;
1131 GetViewStart(& startXUnits
, & startYUnits
);
1132 int startY
= startYUnits
* ppuY
;
1135 GetVirtualSize(& sx
, & sy
);
1141 wxRect rect
= line
->GetRect();
1143 bool scrolled
= false;
1145 wxSize clientSize
= GetClientSize();
1148 if (keyCode
== WXK_DOWN
|| keyCode
== WXK_NUMPAD_DOWN
||
1149 keyCode
== WXK_RIGHT
|| keyCode
== WXK_NUMPAD_RIGHT
||
1150 keyCode
== WXK_END
|| keyCode
== WXK_NUMPAD_END
||
1151 keyCode
== WXK_PAGEDOWN
|| keyCode
== WXK_NUMPAD_PAGEDOWN
)
1153 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ startY
))
1155 // Make it scroll so this item is at the bottom
1157 int y
= rect
.y
- (clientSize
.y
- rect
.height
);
1158 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1160 // If we're still off the screen, scroll another line down
1161 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ (yUnits
*ppuY
)))
1164 if (startYUnits
!= yUnits
)
1166 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1170 else if (rect
.y
< startY
)
1172 // Make it scroll so this item is at the top
1175 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1177 if (startYUnits
!= yUnits
)
1179 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1185 else if (keyCode
== WXK_UP
|| keyCode
== WXK_NUMPAD_UP
||
1186 keyCode
== WXK_LEFT
|| keyCode
== WXK_NUMPAD_LEFT
||
1187 keyCode
== WXK_HOME
|| keyCode
== WXK_NUMPAD_HOME
||
1188 keyCode
== WXK_PAGEUP
|| keyCode
== WXK_NUMPAD_PAGEUP
)
1190 if (rect
.y
< startY
)
1192 // Make it scroll so this item is at the top
1195 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1197 if (startYUnits
!= yUnits
)
1199 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1203 else if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ startY
))
1205 // Make it scroll so this item is at the bottom
1207 int y
= rect
.y
- (clientSize
.y
- rect
.height
);
1208 int yUnits
= (int) (0.5 + ((float) y
)/(float) ppuY
);
1210 // If we're still off the screen, scroll another line down
1211 if ((rect
.y
+ rect
.height
) > (clientSize
.y
+ (yUnits
*ppuY
)))
1214 if (startYUnits
!= yUnits
)
1216 SetScrollbars(ppuX
, ppuY
, sxUnits
, syUnits
, 0, yUnits
);
1222 #if !wxRICHTEXT_USE_OWN_CARET
1230 /// Is the given position visible on the screen?
1231 bool wxRichTextCtrl::IsPositionVisible(long pos
) const
1233 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(pos
-1);
1239 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
1242 GetViewStart(& startX
, & startY
);
1244 startY
= startY
* ppuY
;
1246 wxRect rect
= line
->GetRect();
1247 wxSize clientSize
= GetClientSize();
1249 return (rect
.GetBottom() > startY
) && (rect
.GetTop() < (startY
+ clientSize
.y
));
1252 void wxRichTextCtrl::SetCaretPosition(long position
, bool showAtLineStart
)
1254 m_caretPosition
= position
;
1255 m_caretAtLineStart
= showAtLineStart
;
1258 /// Move caret one visual step forward: this may mean setting a flag
1259 /// and keeping the same position if we're going from the end of one line
1260 /// to the start of the next, which may be the exact same caret position.
1261 void wxRichTextCtrl::MoveCaretForward(long oldPosition
)
1263 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(oldPosition
);
1265 // Only do the check if we're not at the end of the paragraph (where things work OK
1267 if (para
&& (oldPosition
!= para
->GetRange().GetEnd() - 1))
1269 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(oldPosition
);
1273 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1275 // We're at the end of a line. See whether we need to
1276 // stay at the same actual caret position but change visual
1277 // position, or not.
1278 if (oldPosition
== lineRange
.GetEnd())
1280 if (m_caretAtLineStart
)
1282 // We're already at the start of the line, so actually move on now.
1283 m_caretPosition
= oldPosition
+ 1;
1284 m_caretAtLineStart
= false;
1288 // We're showing at the end of the line, so keep to
1289 // the same position but indicate that we're to show
1290 // at the start of the next line.
1291 m_caretPosition
= oldPosition
;
1292 m_caretAtLineStart
= true;
1301 /// Move caret one visual step backward: this may mean setting a flag
1302 /// and keeping the same position if we're going from the end of one line
1303 /// to the start of the next, which may be the exact same caret position.
1304 void wxRichTextCtrl::MoveCaretBack(long oldPosition
)
1306 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(oldPosition
);
1308 // Only do the check if we're not at the start of the paragraph (where things work OK
1310 if (para
&& (oldPosition
!= para
->GetRange().GetStart()))
1312 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(oldPosition
);
1316 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1318 // We're at the start of a line. See whether we need to
1319 // stay at the same actual caret position but change visual
1320 // position, or not.
1321 if (oldPosition
== lineRange
.GetStart())
1323 m_caretPosition
= oldPosition
-1;
1324 m_caretAtLineStart
= true;
1327 else if (oldPosition
== lineRange
.GetEnd())
1329 if (m_caretAtLineStart
)
1331 // We're at the start of the line, so keep the same caret position
1332 // but clear the start-of-line flag.
1333 m_caretPosition
= oldPosition
;
1334 m_caretAtLineStart
= false;
1338 // We're showing at the end of the line, so go back
1339 // to the previous character position.
1340 m_caretPosition
= oldPosition
- 1;
1350 bool wxRichTextCtrl::MoveRight(int noPositions
, int flags
)
1352 long endPos
= GetBuffer().GetRange().GetEnd();
1354 if (m_caretPosition
+ noPositions
< endPos
)
1356 long oldPos
= m_caretPosition
;
1357 long newPos
= m_caretPosition
+ noPositions
;
1359 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1363 // Determine by looking at oldPos and m_caretPosition whether
1364 // we moved from the end of a line to the start of the next line, in which case
1365 // we want to adjust the caret position such that it is positioned at the
1366 // start of the next line, rather than jumping past the first character of the
1368 if (noPositions
== 1 && !extendSel
)
1369 MoveCaretForward(oldPos
);
1371 SetCaretPosition(newPos
);
1382 bool wxRichTextCtrl::MoveLeft(int noPositions
, int flags
)
1386 if (m_caretPosition
> startPos
- noPositions
+ 1)
1388 long oldPos
= m_caretPosition
;
1389 long newPos
= m_caretPosition
- noPositions
;
1390 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1394 if (noPositions
== 1 && !extendSel
)
1395 MoveCaretBack(oldPos
);
1397 SetCaretPosition(newPos
);
1408 bool wxRichTextCtrl::MoveUp(int noLines
, int flags
)
1410 return MoveDown(- noLines
, flags
);
1414 bool wxRichTextCtrl::MoveDown(int noLines
, int flags
)
1419 long lineNumber
= GetBuffer().GetVisibleLineNumber(m_caretPosition
, true, m_caretAtLineStart
);
1420 wxPoint pt
= GetCaret()->GetPosition();
1421 long newLine
= lineNumber
+ noLines
;
1423 if (lineNumber
!= -1)
1427 long lastLine
= GetBuffer().GetVisibleLineNumber(GetBuffer().GetRange().GetEnd());
1429 if (newLine
> lastLine
)
1439 wxRichTextLine
* lineObj
= GetBuffer().GetLineForVisibleLineNumber(newLine
);
1442 pt
.y
= lineObj
->GetAbsolutePosition().y
+ 2;
1448 wxClientDC
dc(this);
1450 dc
.SetFont(GetFont());
1452 int hitTest
= GetBuffer().HitTest(dc
, pt
, newPos
);
1454 if (hitTest
!= wxRICHTEXT_HITTEST_NONE
)
1456 // If end of previous line, and hitTest is wxRICHTEXT_HITTEST_BEFORE,
1457 // we want to be at the end of the last line but with m_caretAtLineStart set to true,
1458 // so we view the caret at the start of the line.
1459 bool caretLineStart
= false;
1460 if (hitTest
& wxRICHTEXT_HITTEST_BEFORE
)
1462 wxRichTextLine
* thisLine
= GetBuffer().GetLineAtPosition(newPos
-1);
1463 wxRichTextRange lineRange
;
1465 lineRange
= thisLine
->GetAbsoluteRange();
1467 if (thisLine
&& (newPos
-1) == lineRange
.GetEnd())
1470 caretLineStart
= true;
1474 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(newPos
);
1475 if (para
&& para
->GetRange().GetStart() == newPos
)
1480 long newSelEnd
= newPos
;
1482 bool extendSel
= ExtendSelection(m_caretPosition
, newSelEnd
, flags
);
1486 SetCaretPosition(newPos
, caretLineStart
);
1495 /// Move to the end of the paragraph
1496 bool wxRichTextCtrl::MoveToParagraphEnd(int flags
)
1498 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(m_caretPosition
, true);
1501 long newPos
= para
->GetRange().GetEnd() - 1;
1502 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1506 SetCaretPosition(newPos
);
1515 /// Move to the start of the paragraph
1516 bool wxRichTextCtrl::MoveToParagraphStart(int flags
)
1518 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(m_caretPosition
, true);
1521 long newPos
= para
->GetRange().GetStart() - 1;
1522 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1526 SetCaretPosition(newPos
);
1535 /// Move to the end of the line
1536 bool wxRichTextCtrl::MoveToLineEnd(int flags
)
1538 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
1542 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1543 long newPos
= lineRange
.GetEnd();
1544 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1548 SetCaretPosition(newPos
);
1557 /// Move to the start of the line
1558 bool wxRichTextCtrl::MoveToLineStart(int flags
)
1560 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
1563 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1564 long newPos
= lineRange
.GetStart()-1;
1566 bool extendSel
= ExtendSelection(m_caretPosition
, newPos
, flags
);
1570 wxRichTextParagraph
* para
= GetBuffer().GetParagraphForLine(line
);
1572 SetCaretPosition(newPos
, para
->GetRange().GetStart() != lineRange
.GetStart());
1581 /// Move to the start of the buffer
1582 bool wxRichTextCtrl::MoveHome(int flags
)
1584 if (m_caretPosition
!= -1)
1586 bool extendSel
= ExtendSelection(m_caretPosition
, -1, flags
);
1590 SetCaretPosition(-1);
1599 /// Move to the end of the buffer
1600 bool wxRichTextCtrl::MoveEnd(int flags
)
1602 long endPos
= GetBuffer().GetRange().GetEnd()-1;
1604 if (m_caretPosition
!= endPos
)
1606 bool extendSel
= ExtendSelection(m_caretPosition
, endPos
, flags
);
1610 SetCaretPosition(endPos
);
1619 /// Move noPages pages up
1620 bool wxRichTextCtrl::PageUp(int noPages
, int flags
)
1622 return PageDown(- noPages
, flags
);
1625 /// Move noPages pages down
1626 bool wxRichTextCtrl::PageDown(int noPages
, int flags
)
1628 // Calculate which line occurs noPages * screen height further down.
1629 wxRichTextLine
* line
= GetVisibleLineForCaretPosition(m_caretPosition
);
1632 wxSize clientSize
= GetClientSize();
1633 int newY
= line
->GetAbsolutePosition().y
+ noPages
*clientSize
.y
;
1635 wxRichTextLine
* newLine
= GetBuffer().GetLineAtYPosition(newY
);
1638 wxRichTextRange lineRange
= newLine
->GetAbsoluteRange();
1639 long pos
= lineRange
.GetStart()-1;
1640 if (pos
!= m_caretPosition
)
1642 wxRichTextParagraph
* para
= GetBuffer().GetParagraphForLine(newLine
);
1644 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
1648 SetCaretPosition(pos
, para
->GetRange().GetStart() != lineRange
.GetStart());
1659 static bool wxRichTextCtrlIsWhitespace(const wxString
& str
)
1661 return str
== wxT(" ") || str
== wxT("\t");
1664 // Finds the caret position for the next word
1665 long wxRichTextCtrl::FindNextWordPosition(int direction
) const
1667 long endPos
= GetBuffer().GetRange().GetEnd();
1671 long i
= m_caretPosition
+1+direction
; // +1 for conversion to character pos
1673 // First skip current text to space
1674 while (i
< endPos
&& i
> -1)
1676 // i is in character, not caret positions
1677 wxString text
= GetBuffer().GetTextForRange(wxRichTextRange(i
, i
));
1678 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(i
, false);
1679 if (line
&& (i
== line
->GetAbsoluteRange().GetEnd()))
1683 else if (!wxRichTextCtrlIsWhitespace(text
) && !text
.empty())
1690 while (i
< endPos
&& i
> -1)
1692 // i is in character, not caret positions
1693 wxString text
= GetBuffer().GetTextForRange(wxRichTextRange(i
, i
));
1694 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(i
, false);
1695 if (line
&& (i
== line
->GetAbsoluteRange().GetEnd()))
1696 return wxMax(-1, i
);
1698 if (text
.empty()) // End of paragraph, or maybe an image
1699 return wxMax(-1, i
- 1);
1700 else if (wxRichTextCtrlIsWhitespace(text
) || text
.empty())
1704 // Convert to caret position
1705 return wxMax(-1, i
- 1);
1714 long i
= m_caretPosition
;
1716 // First skip white space
1717 while (i
< endPos
&& i
> -1)
1719 // i is in character, not caret positions
1720 wxString text
= GetBuffer().GetTextForRange(wxRichTextRange(i
, i
));
1721 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(i
, false);
1723 if (text
.empty() || (line
&& (i
== line
->GetAbsoluteRange().GetStart()))) // End of paragraph, or maybe an image
1725 else if (wxRichTextCtrlIsWhitespace(text
) || text
.empty())
1730 // Next skip current text to space
1731 while (i
< endPos
&& i
> -1)
1733 // i is in character, not caret positions
1734 wxString text
= GetBuffer().GetTextForRange(wxRichTextRange(i
, i
));
1735 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(i
, false);
1736 if (line
&& line
->GetAbsoluteRange().GetStart() == i
)
1739 if (!wxRichTextCtrlIsWhitespace(text
) /* && !text.empty() */)
1752 /// Move n words left
1753 bool wxRichTextCtrl::WordLeft(int WXUNUSED(n
), int flags
)
1755 long pos
= FindNextWordPosition(-1);
1756 if (pos
!= m_caretPosition
)
1758 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(pos
, true);
1760 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
1764 SetCaretPosition(pos
, para
->GetRange().GetStart() != pos
);
1773 /// Move n words right
1774 bool wxRichTextCtrl::WordRight(int WXUNUSED(n
), int flags
)
1776 long pos
= FindNextWordPosition(1);
1777 if (pos
!= m_caretPosition
)
1779 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(pos
, true);
1781 bool extendSel
= ExtendSelection(m_caretPosition
, pos
, flags
);
1785 SetCaretPosition(pos
, para
->GetRange().GetStart() != pos
);
1795 void wxRichTextCtrl::OnSize(wxSizeEvent
& event
)
1797 // Only do sizing optimization for large buffers
1798 if (GetBuffer().GetRange().GetEnd() > m_delayedLayoutThreshold
)
1800 m_fullLayoutRequired
= true;
1801 m_fullLayoutTime
= wxGetLocalTimeMillis();
1802 m_fullLayoutSavedPosition
= GetFirstVisiblePosition();
1803 LayoutContent(true /* onlyVisibleRect */);
1806 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
1808 #if wxRICHTEXT_BUFFERED_PAINTING
1816 /// Idle-time processing
1817 void wxRichTextCtrl::OnIdle(wxIdleEvent
& event
)
1819 #if wxRICHTEXT_USE_OWN_CARET
1820 if (((wxRichTextCaret
*) GetCaret())->GetNeedsUpdate())
1822 ((wxRichTextCaret
*) GetCaret())->SetNeedsUpdate(false);
1828 const int layoutInterval
= wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL
;
1830 if (m_fullLayoutRequired
&& (wxGetLocalTimeMillis() > (m_fullLayoutTime
+ layoutInterval
)))
1832 m_fullLayoutRequired
= false;
1833 m_fullLayoutTime
= 0;
1834 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
1835 ShowPosition(m_fullLayoutSavedPosition
);
1839 if (m_caretPositionForDefaultStyle
!= -2)
1841 // If the caret position has changed, no longer reflect the default style
1843 if (GetCaretPosition() != m_caretPositionForDefaultStyle
)
1844 m_caretPositionForDefaultStyle
= -2;
1851 void wxRichTextCtrl::OnScroll(wxScrollWinEvent
& event
)
1853 #if wxRICHTEXT_USE_OWN_CARET
1854 if (!((wxRichTextCaret
*) GetCaret())->GetNeedsUpdate())
1857 ((wxRichTextCaret
*) GetCaret())->SetNeedsUpdate();
1864 /// Set up scrollbars, e.g. after a resize
1865 void wxRichTextCtrl::SetupScrollbars(bool atTop
)
1870 if (GetBuffer().IsEmpty())
1872 SetScrollbars(0, 0, 0, 0, 0, 0);
1876 // TODO: reimplement scrolling so we scroll by line, not by fixed number
1877 // of pixels. See e.g. wxVScrolledWindow for ideas.
1878 int pixelsPerUnit
= 5;
1879 wxSize clientSize
= GetClientSize();
1881 int maxHeight
= GetBuffer().GetCachedSize().y
;
1883 // Round up so we have at least maxHeight pixels
1884 int unitsY
= (int) (((float)maxHeight
/(float)pixelsPerUnit
) + 0.5);
1886 int startX
= 0, startY
= 0;
1888 GetViewStart(& startX
, & startY
);
1890 int maxPositionX
= 0;
1891 int maxPositionY
= (int) ((((float)(wxMax((unitsY
*pixelsPerUnit
) - clientSize
.y
, 0)))/((float)pixelsPerUnit
)) + 0.5);
1893 int newStartX
= wxMin(maxPositionX
, startX
);
1894 int newStartY
= wxMin(maxPositionY
, startY
);
1896 int oldPPUX
, oldPPUY
;
1897 int oldStartX
, oldStartY
;
1898 int oldVirtualSizeX
= 0, oldVirtualSizeY
= 0;
1899 GetScrollPixelsPerUnit(& oldPPUX
, & oldPPUY
);
1900 GetViewStart(& oldStartX
, & oldStartY
);
1901 GetVirtualSize(& oldVirtualSizeX
, & oldVirtualSizeY
);
1903 oldVirtualSizeY
/= oldPPUY
;
1905 if (oldPPUX
== 0 && oldPPUY
== pixelsPerUnit
&& oldVirtualSizeY
== unitsY
&& oldStartX
== newStartX
&& oldStartY
== newStartY
)
1908 // Don't set scrollbars if there were none before, and there will be none now.
1909 if (oldPPUY
!= 0 && (oldVirtualSizeY
< clientSize
.y
) && (unitsY
*pixelsPerUnit
< clientSize
.y
))
1912 // Move to previous scroll position if
1914 SetScrollbars(0, pixelsPerUnit
, 0, unitsY
, newStartX
, newStartY
);
1917 /// Paint the background
1918 void wxRichTextCtrl::PaintBackground(wxDC
& dc
)
1920 wxColour backgroundColour
= GetBackgroundColour();
1921 if (!backgroundColour
.Ok())
1922 backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1924 // Clear the background
1925 dc
.SetBrush(wxBrush(backgroundColour
));
1926 dc
.SetPen(*wxTRANSPARENT_PEN
);
1927 wxRect
windowRect(GetClientSize());
1928 windowRect
.x
-= 2; windowRect
.y
-= 2;
1929 windowRect
.width
+= 4; windowRect
.height
+= 4;
1931 // We need to shift the rectangle to take into account
1932 // scrolling. Converting device to logical coordinates.
1933 CalcUnscrolledPosition(windowRect
.x
, windowRect
.y
, & windowRect
.x
, & windowRect
.y
);
1934 dc
.DrawRectangle(windowRect
);
1937 #if wxRICHTEXT_BUFFERED_PAINTING
1938 /// Recreate buffer bitmap if necessary
1939 bool wxRichTextCtrl::RecreateBuffer(const wxSize
& size
)
1942 if (sz
== wxDefaultSize
)
1943 sz
= GetClientSize();
1945 if (sz
.x
< 1 || sz
.y
< 1)
1948 if (!m_bufferBitmap
.Ok() || m_bufferBitmap
.GetWidth() < sz
.x
|| m_bufferBitmap
.GetHeight() < sz
.y
)
1949 m_bufferBitmap
= wxBitmap(sz
.x
, sz
.y
);
1950 return m_bufferBitmap
.Ok();
1954 // ----------------------------------------------------------------------------
1955 // file IO functions
1956 // ----------------------------------------------------------------------------
1958 bool wxRichTextCtrl::DoLoadFile(const wxString
& filename
, int fileType
)
1960 bool success
= GetBuffer().LoadFile(filename
, fileType
);
1962 m_filename
= filename
;
1965 SetInsertionPoint(0);
1968 SetupScrollbars(true);
1970 wxTextCtrl::SendTextUpdatedEvent(this);
1976 wxLogError(_("File couldn't be loaded."));
1982 bool wxRichTextCtrl::DoSaveFile(const wxString
& filename
, int fileType
)
1984 if (GetBuffer().SaveFile(filename
, fileType
))
1986 m_filename
= filename
;
1993 wxLogError(_("The text couldn't be saved."));
1998 // ----------------------------------------------------------------------------
1999 // wxRichTextCtrl specific functionality
2000 // ----------------------------------------------------------------------------
2002 /// Add a new paragraph of text to the end of the buffer
2003 wxRichTextRange
wxRichTextCtrl::AddParagraph(const wxString
& text
)
2005 wxRichTextRange range
= GetBuffer().AddParagraph(text
);
2011 wxRichTextRange
wxRichTextCtrl::AddImage(const wxImage
& image
)
2013 wxRichTextRange range
= GetBuffer().AddImage(image
);
2018 // ----------------------------------------------------------------------------
2019 // selection and ranges
2020 // ----------------------------------------------------------------------------
2022 void wxRichTextCtrl::SelectAll()
2024 SetSelection(0, GetLastPosition()+1);
2025 m_selectionAnchor
= -1;
2029 void wxRichTextCtrl::SelectNone()
2031 if (!(GetSelectionRange() == wxRichTextRange(-2, -2)))
2033 wxRichTextRange oldSelection
= m_selectionRange
;
2035 m_selectionRange
= wxRichTextRange(-2, -2);
2037 RefreshForSelectionChange(oldSelection
, m_selectionRange
);
2039 m_selectionAnchor
= -2;
2042 static bool wxIsWordDelimiter(const wxString
& text
)
2044 return !text
.IsEmpty() && !wxIsalnum(text
[0]);
2047 /// Select the word at the given character position
2048 bool wxRichTextCtrl::SelectWord(long position
)
2050 if (position
< 0 || position
> GetBuffer().GetRange().GetEnd())
2053 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(position
);
2057 if (position
== para
->GetRange().GetEnd())
2060 long positionStart
= position
;
2061 long positionEnd
= position
;
2063 for (positionStart
= position
; positionStart
>= para
->GetRange().GetStart(); positionStart
--)
2065 wxString text
= GetBuffer().GetTextForRange(wxRichTextRange(positionStart
, positionStart
));
2066 if (wxIsWordDelimiter(text
))
2072 if (positionStart
< para
->GetRange().GetStart())
2073 positionStart
= para
->GetRange().GetStart();
2075 for (positionEnd
= position
; positionEnd
< para
->GetRange().GetEnd(); positionEnd
++)
2077 wxString text
= GetBuffer().GetTextForRange(wxRichTextRange(positionEnd
, positionEnd
));
2078 if (wxIsWordDelimiter(text
))
2084 if (positionEnd
>= para
->GetRange().GetEnd())
2085 positionEnd
= para
->GetRange().GetEnd();
2087 if (positionEnd
< positionStart
)
2090 SetSelection(positionStart
, positionEnd
+1);
2092 if (positionStart
>= 0)
2094 MoveCaret(positionStart
-1, true);
2100 wxString
wxRichTextCtrl::GetStringSelection() const
2103 GetSelection(&from
, &to
);
2105 return GetRange(from
, to
);
2108 // ----------------------------------------------------------------------------
2110 // ----------------------------------------------------------------------------
2112 wxTextCtrlHitTestResult
2113 wxRichTextCtrl::HitTest(const wxPoint
& pt
, wxTextCoord
*x
, wxTextCoord
*y
) const
2115 // implement in terms of the other overload as the native ports typically
2116 // can get the position and not (x, y) pair directly (although wxUniv
2117 // directly gets x and y -- and so overrides this method as well)
2119 wxTextCtrlHitTestResult rc
= HitTest(pt
, &pos
);
2121 if ( rc
!= wxTE_HT_UNKNOWN
)
2123 PositionToXY(pos
, x
, y
);
2129 wxTextCtrlHitTestResult
2130 wxRichTextCtrl::HitTest(const wxPoint
& pt
,
2133 wxClientDC
dc((wxRichTextCtrl
*) this);
2134 ((wxRichTextCtrl
*)this)->PrepareDC(dc
);
2136 // Buffer uses logical position (relative to start of buffer)
2138 wxPoint pt2
= GetLogicalPoint(pt
);
2140 int hit
= ((wxRichTextCtrl
*)this)->GetBuffer().HitTest(dc
, pt2
, *pos
);
2142 if ((hit
& wxRICHTEXT_HITTEST_BEFORE
) && (hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
2143 return wxTE_HT_BEFORE
;
2144 else if ((hit
& wxRICHTEXT_HITTEST_AFTER
) && (hit
& wxRICHTEXT_HITTEST_OUTSIDE
))
2145 return wxTE_HT_BEYOND
;
2146 else if (hit
& (wxRICHTEXT_HITTEST_BEFORE
|wxRICHTEXT_HITTEST_AFTER
))
2147 return wxTE_HT_ON_TEXT
;
2149 return wxTE_HT_UNKNOWN
;
2152 // ----------------------------------------------------------------------------
2153 // set/get the controls text
2154 // ----------------------------------------------------------------------------
2156 wxString
wxRichTextCtrl::GetValue() const
2158 return GetBuffer().GetText();
2161 wxString
wxRichTextCtrl::GetRange(long from
, long to
) const
2163 // Public API for range is different from internals
2164 return GetBuffer().GetTextForRange(wxRichTextRange(from
, to
-1));
2167 void wxRichTextCtrl::DoSetValue(const wxString
& value
, int flags
)
2169 // Don't call Clear here, since it always sends a text updated event
2170 m_buffer
.ResetAndClearCommands();
2171 m_buffer
.SetDirty(true);
2172 m_caretPosition
= -1;
2173 m_caretPositionForDefaultStyle
= -2;
2174 m_caretAtLineStart
= false;
2175 m_selectionRange
.SetRange(-2, -2);
2185 if (!value
.IsEmpty())
2187 // Remove empty paragraph
2188 GetBuffer().Clear();
2189 DoWriteText(value
, flags
);
2191 // for compatibility, don't move the cursor when doing SetValue()
2192 SetInsertionPoint(0);
2196 // still send an event for consistency
2197 if (flags
& SetValue_SendEvent
)
2198 wxTextCtrl::SendTextUpdatedEvent(this);
2203 void wxRichTextCtrl::WriteText(const wxString
& value
)
2208 void wxRichTextCtrl::DoWriteText(const wxString
& value
, int flags
)
2210 wxString valueUnix
= wxTextFile::Translate(value
, wxTextFileType_Unix
);
2212 SetDefaultStyleToCursorStyle();
2213 GetBuffer().InsertTextWithUndo(m_caretPosition
+1, valueUnix
, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
2215 if ( flags
& SetValue_SendEvent
)
2216 wxTextCtrl::SendTextUpdatedEvent(this);
2219 void wxRichTextCtrl::AppendText(const wxString
& text
)
2221 SetInsertionPointEnd();
2226 /// Write an image at the current insertion point
2227 bool wxRichTextCtrl::WriteImage(const wxImage
& image
, int bitmapType
)
2229 wxRichTextImageBlock imageBlock
;
2231 wxImage image2
= image
;
2232 if (imageBlock
.MakeImageBlock(image2
, bitmapType
))
2233 return WriteImage(imageBlock
);
2238 bool wxRichTextCtrl::WriteImage(const wxString
& filename
, int bitmapType
)
2240 wxRichTextImageBlock imageBlock
;
2243 if (imageBlock
.MakeImageBlock(filename
, bitmapType
, image
, false))
2244 return WriteImage(imageBlock
);
2249 bool wxRichTextCtrl::WriteImage(const wxRichTextImageBlock
& imageBlock
)
2251 return GetBuffer().InsertImageWithUndo(m_caretPosition
+1, imageBlock
, this);
2254 bool wxRichTextCtrl::WriteImage(const wxBitmap
& bitmap
, int bitmapType
)
2258 wxRichTextImageBlock imageBlock
;
2260 wxImage image
= bitmap
.ConvertToImage();
2261 if (image
.Ok() && imageBlock
.MakeImageBlock(image
, bitmapType
))
2262 return WriteImage(imageBlock
);
2268 /// Insert a newline (actually paragraph) at the current insertion point.
2269 bool wxRichTextCtrl::Newline()
2271 return GetBuffer().InsertNewlineWithUndo(m_caretPosition
+1, this);
2274 /// Insert a line break at the current insertion point.
2275 bool wxRichTextCtrl::LineBreak()
2278 text
= wxRichTextLineBreakChar
;
2279 return GetBuffer().InsertTextWithUndo(m_caretPosition
+1, text
, this);
2282 // ----------------------------------------------------------------------------
2283 // Clipboard operations
2284 // ----------------------------------------------------------------------------
2286 void wxRichTextCtrl::Copy()
2290 wxRichTextRange range
= GetInternalSelectionRange();
2291 GetBuffer().CopyToClipboard(range
);
2295 void wxRichTextCtrl::Cut()
2299 wxRichTextRange range
= GetInternalSelectionRange();
2300 GetBuffer().CopyToClipboard(range
);
2302 DeleteSelectedContent();
2308 void wxRichTextCtrl::Paste()
2312 SetDefaultStyleToCursorStyle();
2313 BeginBatchUndo(_("Paste"));
2315 long newPos
= m_caretPosition
;
2316 DeleteSelectedContent(& newPos
);
2318 GetBuffer().PasteFromClipboard(newPos
);
2324 void wxRichTextCtrl::DeleteSelection()
2326 if (CanDeleteSelection())
2328 DeleteSelectedContent();
2332 bool wxRichTextCtrl::HasSelection() const
2334 return m_selectionRange
.GetStart() != -2 && m_selectionRange
.GetEnd() != -2;
2337 bool wxRichTextCtrl::CanCopy() const
2339 // Can copy if there's a selection
2340 return HasSelection();
2343 bool wxRichTextCtrl::CanCut() const
2345 return HasSelection() && IsEditable();
2348 bool wxRichTextCtrl::CanPaste() const
2350 if ( !IsEditable() )
2353 return GetBuffer().CanPasteFromClipboard();
2356 bool wxRichTextCtrl::CanDeleteSelection() const
2358 return HasSelection() && IsEditable();
2362 // ----------------------------------------------------------------------------
2364 // ----------------------------------------------------------------------------
2366 void wxRichTextCtrl::SetEditable(bool editable
)
2368 m_editable
= editable
;
2371 void wxRichTextCtrl::SetInsertionPoint(long pos
)
2375 m_caretPosition
= pos
- 1;
2380 void wxRichTextCtrl::SetInsertionPointEnd()
2382 long pos
= GetLastPosition();
2383 SetInsertionPoint(pos
);
2386 long wxRichTextCtrl::GetInsertionPoint() const
2388 return m_caretPosition
+1;
2391 wxTextPos
wxRichTextCtrl::GetLastPosition() const
2393 return GetBuffer().GetRange().GetEnd();
2396 // If the return values from and to are the same, there is no
2398 void wxRichTextCtrl::GetSelection(long* from
, long* to
) const
2400 *from
= m_selectionRange
.GetStart();
2401 *to
= m_selectionRange
.GetEnd();
2402 if ((*to
) != -1 && (*to
) != -2)
2406 bool wxRichTextCtrl::IsEditable() const
2411 // ----------------------------------------------------------------------------
2413 // ----------------------------------------------------------------------------
2415 void wxRichTextCtrl::SetSelection(long from
, long to
)
2417 // if from and to are both -1, it means (in wxWidgets) that all text should
2419 if ( (from
== -1) && (to
== -1) )
2422 to
= GetLastPosition()+1;
2425 DoSetSelection(from
, to
);
2428 void wxRichTextCtrl::DoSetSelection(long from
, long to
, bool WXUNUSED(scrollCaret
))
2436 wxRichTextRange oldSelection
= m_selectionRange
;
2437 m_selectionAnchor
= from
;
2438 m_selectionRange
.SetRange(from
, to
-1);
2440 m_caretPosition
= from
-1;
2442 RefreshForSelectionChange(oldSelection
, m_selectionRange
);
2447 // ----------------------------------------------------------------------------
2449 // ----------------------------------------------------------------------------
2451 void wxRichTextCtrl::Replace(long WXUNUSED(from
), long WXUNUSED(to
),
2452 const wxString
& value
)
2454 BeginBatchUndo(_("Replace"));
2456 DeleteSelectedContent();
2458 DoWriteText(value
, SetValue_SelectionOnly
);
2463 void wxRichTextCtrl::Remove(long from
, long to
)
2467 GetBuffer().DeleteRangeWithUndo(wxRichTextRange(from
, to
-1), this);
2474 bool wxRichTextCtrl::IsModified() const
2476 return m_buffer
.IsModified();
2479 void wxRichTextCtrl::MarkDirty()
2481 m_buffer
.Modify(true);
2484 void wxRichTextCtrl::DiscardEdits()
2486 m_caretPositionForDefaultStyle
= -2;
2487 m_buffer
.Modify(false);
2488 m_buffer
.GetCommandProcessor()->ClearCommands();
2491 int wxRichTextCtrl::GetNumberOfLines() const
2493 return GetBuffer().GetParagraphCount();
2496 // ----------------------------------------------------------------------------
2497 // Positions <-> coords
2498 // ----------------------------------------------------------------------------
2500 long wxRichTextCtrl::XYToPosition(long x
, long y
) const
2502 return GetBuffer().XYToPosition(x
, y
);
2505 bool wxRichTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
2507 return GetBuffer().PositionToXY(pos
, x
, y
);
2510 // ----------------------------------------------------------------------------
2512 // ----------------------------------------------------------------------------
2514 void wxRichTextCtrl::ShowPosition(long pos
)
2516 if (!IsPositionVisible(pos
))
2517 ScrollIntoView(pos
-1, WXK_DOWN
);
2520 int wxRichTextCtrl::GetLineLength(long lineNo
) const
2522 return GetBuffer().GetParagraphLength(lineNo
);
2525 wxString
wxRichTextCtrl::GetLineText(long lineNo
) const
2527 return GetBuffer().GetParagraphText(lineNo
);
2530 // ----------------------------------------------------------------------------
2532 // ----------------------------------------------------------------------------
2534 void wxRichTextCtrl::Undo()
2538 GetCommandProcessor()->Undo();
2542 void wxRichTextCtrl::Redo()
2546 GetCommandProcessor()->Redo();
2550 bool wxRichTextCtrl::CanUndo() const
2552 return GetCommandProcessor()->CanUndo();
2555 bool wxRichTextCtrl::CanRedo() const
2557 return GetCommandProcessor()->CanRedo();
2560 // ----------------------------------------------------------------------------
2561 // implementation details
2562 // ----------------------------------------------------------------------------
2564 void wxRichTextCtrl::Command(wxCommandEvent
& event
)
2566 SetValue(event
.GetString());
2567 GetEventHandler()->ProcessEvent(event
);
2570 void wxRichTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
2572 // By default, load the first file into the text window.
2573 if (event
.GetNumberOfFiles() > 0)
2575 LoadFile(event
.GetFiles()[0]);
2579 wxSize
wxRichTextCtrl::DoGetBestSize() const
2581 return wxSize(10, 10);
2584 // ----------------------------------------------------------------------------
2585 // standard handlers for standard edit menu events
2586 // ----------------------------------------------------------------------------
2588 void wxRichTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
2593 void wxRichTextCtrl::OnClear(wxCommandEvent
& WXUNUSED(event
))
2598 void wxRichTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
2603 void wxRichTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
2608 void wxRichTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
2613 void wxRichTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
2618 void wxRichTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
2620 event
.Enable( CanCut() );
2623 void wxRichTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
2625 event
.Enable( CanCopy() );
2628 void wxRichTextCtrl::OnUpdateClear(wxUpdateUIEvent
& event
)
2630 event
.Enable( CanDeleteSelection() );
2633 void wxRichTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
2635 event
.Enable( CanPaste() );
2638 void wxRichTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
2640 event
.Enable( CanUndo() );
2641 event
.SetText( GetCommandProcessor()->GetUndoMenuLabel() );
2644 void wxRichTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
2646 event
.Enable( CanRedo() );
2647 event
.SetText( GetCommandProcessor()->GetRedoMenuLabel() );
2650 void wxRichTextCtrl::OnSelectAll(wxCommandEvent
& WXUNUSED(event
))
2655 void wxRichTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent
& event
)
2657 event
.Enable(GetLastPosition() > 0);
2660 void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent
& event
)
2662 if (event
.GetEventObject() != this)
2670 m_contextMenu
= new wxMenu
;
2671 m_contextMenu
->Append(wxID_UNDO
, _("&Undo"));
2672 m_contextMenu
->Append(wxID_REDO
, _("&Redo"));
2673 m_contextMenu
->AppendSeparator();
2674 m_contextMenu
->Append(wxID_CUT
, _("Cu&t"));
2675 m_contextMenu
->Append(wxID_COPY
, _("&Copy"));
2676 m_contextMenu
->Append(wxID_PASTE
, _("&Paste"));
2677 m_contextMenu
->Append(wxID_CLEAR
, _("&Delete"));
2678 m_contextMenu
->AppendSeparator();
2679 m_contextMenu
->Append(wxID_SELECTALL
, _("Select &All"));
2681 PopupMenu(m_contextMenu
);
2685 bool wxRichTextCtrl::SetStyle(long start
, long end
, const wxTextAttr
& style
)
2687 return GetBuffer().SetStyle(wxRichTextRange(start
, end
-1), wxTextAttr(style
));
2690 bool wxRichTextCtrl::SetStyle(const wxRichTextRange
& range
, const wxTextAttr
& style
)
2692 return GetBuffer().SetStyle(range
.ToInternal(), style
);
2695 // extended style setting operation with flags including:
2696 // wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY.
2697 // see richtextbuffer.h for more details.
2699 bool wxRichTextCtrl::SetStyleEx(const wxRichTextRange
& range
, const wxTextAttr
& style
, int flags
)
2701 return GetBuffer().SetStyle(range
.ToInternal(), style
, flags
);
2704 bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr
& style
)
2706 return GetBuffer().SetDefaultStyle(wxTextAttr(style
));
2709 const wxTextAttr
& wxRichTextCtrl::GetDefaultStyle() const
2711 return GetBuffer().GetDefaultStyle();
2714 bool wxRichTextCtrl::GetStyle(long position
, wxTextAttr
& style
)
2716 return GetBuffer().GetStyle(position
, style
);
2719 // get the common set of styles for the range
2720 bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange
& range
, wxTextAttr
& style
)
2722 return GetBuffer().GetStyleForRange(range
.ToInternal(), style
);
2725 /// Get the content (uncombined) attributes for this position.
2726 bool wxRichTextCtrl::GetUncombinedStyle(long position
, wxTextAttr
& style
)
2728 return GetBuffer().GetUncombinedStyle(position
, style
);
2731 /// Set font, and also the buffer attributes
2732 bool wxRichTextCtrl::SetFont(const wxFont
& font
)
2734 wxControl::SetFont(font
);
2736 wxTextAttr attr
= GetBuffer().GetAttributes();
2738 GetBuffer().SetBasicStyle(attr
);
2740 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
2746 /// Transform logical to physical
2747 wxPoint
wxRichTextCtrl::GetPhysicalPoint(const wxPoint
& ptLogical
) const
2750 CalcScrolledPosition(ptLogical
.x
, ptLogical
.y
, & pt
.x
, & pt
.y
);
2755 /// Transform physical to logical
2756 wxPoint
wxRichTextCtrl::GetLogicalPoint(const wxPoint
& ptPhysical
) const
2759 CalcUnscrolledPosition(ptPhysical
.x
, ptPhysical
.y
, & pt
.x
, & pt
.y
);
2764 /// Position the caret
2765 void wxRichTextCtrl::PositionCaret()
2770 //wxLogDebug(wxT("PositionCaret"));
2773 if (GetCaretPositionForIndex(GetCaretPosition(), caretRect
))
2775 wxPoint newPt
= caretRect
.GetPosition();
2776 wxSize newSz
= caretRect
.GetSize();
2777 wxPoint pt
= GetPhysicalPoint(newPt
);
2778 if (GetCaret()->GetPosition() != pt
|| GetCaret()->GetSize() != newSz
)
2781 if (GetCaret()->GetSize() != newSz
)
2782 GetCaret()->SetSize(newSz
);
2783 GetCaret()->Move(pt
);
2789 /// Get the caret height and position for the given character position
2790 bool wxRichTextCtrl::GetCaretPositionForIndex(long position
, wxRect
& rect
)
2792 wxClientDC
dc(this);
2793 dc
.SetFont(GetFont());
2800 if (GetBuffer().FindPosition(dc
, position
, pt
, & height
, m_caretAtLineStart
))
2802 // Caret height can't be zero
2804 height
= dc
.GetCharHeight();
2806 rect
= wxRect(pt
, wxSize(wxRICHTEXT_DEFAULT_CARET_WIDTH
, height
));
2813 /// Gets the line for the visible caret position. If the caret is
2814 /// shown at the very end of the line, it means the next character is actually
2815 /// on the following line. So let's get the line we're expecting to find
2816 /// if this is the case.
2817 wxRichTextLine
* wxRichTextCtrl::GetVisibleLineForCaretPosition(long caretPosition
) const
2819 wxRichTextLine
* line
= GetBuffer().GetLineAtPosition(caretPosition
, true);
2820 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(caretPosition
, true);
2823 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2824 if (caretPosition
== lineRange
.GetStart()-1 &&
2825 (para
->GetRange().GetStart() != lineRange
.GetStart()))
2827 if (!m_caretAtLineStart
)
2828 line
= GetBuffer().GetLineAtPosition(caretPosition
-1, true);
2835 /// Move the caret to the given character position
2836 bool wxRichTextCtrl::MoveCaret(long pos
, bool showAtLineStart
)
2838 if (GetBuffer().GetDirty())
2841 if (pos
<= GetBuffer().GetRange().GetEnd())
2843 SetCaretPosition(pos
, showAtLineStart
);
2853 /// Layout the buffer: which we must do before certain operations, such as
2854 /// setting the caret position.
2855 bool wxRichTextCtrl::LayoutContent(bool onlyVisibleRect
)
2857 if (GetBuffer().GetDirty() || onlyVisibleRect
)
2859 wxRect
availableSpace(GetClientSize());
2860 if (availableSpace
.width
== 0)
2861 availableSpace
.width
= 10;
2862 if (availableSpace
.height
== 0)
2863 availableSpace
.height
= 10;
2865 int flags
= wxRICHTEXT_FIXED_WIDTH
|wxRICHTEXT_VARIABLE_HEIGHT
;
2866 if (onlyVisibleRect
)
2868 flags
|= wxRICHTEXT_LAYOUT_SPECIFIED_RECT
;
2869 availableSpace
.SetPosition(GetLogicalPoint(wxPoint(0, 0)));
2872 wxClientDC
dc(this);
2873 dc
.SetFont(GetFont());
2877 GetBuffer().Defragment();
2878 GetBuffer().UpdateRanges(); // If items were deleted, ranges need recalculation
2879 GetBuffer().Layout(dc
, availableSpace
, flags
);
2880 GetBuffer().SetDirty(false);
2889 /// Is all of the selection bold?
2890 bool wxRichTextCtrl::IsSelectionBold()
2895 wxRichTextRange range
= GetSelectionRange();
2896 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
2897 attr
.SetFontWeight(wxBOLD
);
2899 return HasCharacterAttributes(range
, attr
);
2903 // If no selection, then we need to combine current style with default style
2904 // to see what the effect would be if we started typing.
2906 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
2908 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
2909 if (GetStyle(pos
, attr
))
2911 if (IsDefaultStyleShowing())
2912 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
2913 return attr
.GetFontWeight() == wxBOLD
;
2919 /// Is all of the selection italics?
2920 bool wxRichTextCtrl::IsSelectionItalics()
2924 wxRichTextRange range
= GetSelectionRange();
2926 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
2927 attr
.SetFontStyle(wxITALIC
);
2929 return HasCharacterAttributes(range
, attr
);
2933 // If no selection, then we need to combine current style with default style
2934 // to see what the effect would be if we started typing.
2936 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
2938 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
2939 if (GetStyle(pos
, attr
))
2941 if (IsDefaultStyleShowing())
2942 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
2943 return attr
.GetFontStyle() == wxITALIC
;
2949 /// Is all of the selection underlined?
2950 bool wxRichTextCtrl::IsSelectionUnderlined()
2954 wxRichTextRange range
= GetSelectionRange();
2956 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
2957 attr
.SetFontUnderlined(true);
2959 return HasCharacterAttributes(range
, attr
);
2963 // If no selection, then we need to combine current style with default style
2964 // to see what the effect would be if we started typing.
2966 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
2967 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
2969 if (GetStyle(pos
, attr
))
2971 if (IsDefaultStyleShowing())
2972 wxRichTextApplyStyle(attr
, GetDefaultStyleEx());
2973 return attr
.GetFontUnderlined();
2979 /// Apply bold to the selection
2980 bool wxRichTextCtrl::ApplyBoldToSelection()
2983 attr
.SetFlags(wxTEXT_ATTR_FONT_WEIGHT
);
2984 attr
.SetFontWeight(IsSelectionBold() ? wxNORMAL
: wxBOLD
);
2987 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
2990 wxRichTextAttr current
= GetDefaultStyleEx();
2991 current
.Apply(attr
);
2992 SetAndShowDefaultStyle(current
);
2997 /// Apply italic to the selection
2998 bool wxRichTextCtrl::ApplyItalicToSelection()
3001 attr
.SetFlags(wxTEXT_ATTR_FONT_ITALIC
);
3002 attr
.SetFontStyle(IsSelectionItalics() ? wxNORMAL
: wxITALIC
);
3005 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3008 wxRichTextAttr current
= GetDefaultStyleEx();
3009 current
.Apply(attr
);
3010 SetAndShowDefaultStyle(current
);
3015 /// Apply underline to the selection
3016 bool wxRichTextCtrl::ApplyUnderlineToSelection()
3019 attr
.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE
);
3020 attr
.SetFontUnderlined(!IsSelectionUnderlined());
3023 return SetStyleEx(GetSelectionRange(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
);
3026 wxRichTextAttr current
= GetDefaultStyleEx();
3027 current
.Apply(attr
);
3028 SetAndShowDefaultStyle(current
);
3033 /// Is all of the selection aligned according to the specified flag?
3034 bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment
)
3036 wxRichTextRange range
;
3038 range
= GetSelectionRange();
3040 range
= wxRichTextRange(GetCaretPosition()+1, GetCaretPosition()+2);
3043 attr
.SetAlignment(alignment
);
3045 return HasParagraphAttributes(range
, attr
);
3048 /// Apply alignment to the selection
3049 bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment
)
3052 attr
.SetAlignment(alignment
);
3054 return SetStyle(GetSelectionRange(), attr
);
3057 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(GetCaretPosition()+1);
3059 return SetStyleEx(para
->GetRange().FromInternal(), attr
, wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
);
3064 /// Apply a named style to the selection
3065 bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition
* def
)
3067 // Flags are defined within each definition, so only certain
3068 // attributes are applied.
3069 wxTextAttr
attr(GetStyleSheet() ? def
->GetStyleMergedWithBase(GetStyleSheet()) : def
->GetStyle());
3071 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
|wxRICHTEXT_SETSTYLE_RESET
;
3073 if (def
->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition
)))
3075 flags
|= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
;
3077 wxRichTextRange range
;
3080 range
= GetSelectionRange();
3083 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3084 range
= wxRichTextRange(pos
, pos
+1);
3087 return SetListStyle(range
, (wxRichTextListStyleDefinition
*) def
, flags
);
3090 // Make sure the attr has the style name
3091 if (def
->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition
)))
3093 attr
.SetParagraphStyleName(def
->GetName());
3095 // If applying a paragraph style, we only want the paragraph nodes to adopt these
3096 // attributes, and not the leaf nodes. This will allow the content (e.g. text)
3097 // to change its style independently.
3098 flags
|= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
;
3101 attr
.SetCharacterStyleName(def
->GetName());
3104 return SetStyleEx(GetSelectionRange(), attr
, flags
);
3107 wxRichTextAttr current
= GetDefaultStyleEx();
3108 current
.Apply(attr
);
3109 SetAndShowDefaultStyle(current
);
3114 /// Apply the style sheet to the buffer, for example if the styles have changed.
3115 bool wxRichTextCtrl::ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
)
3118 styleSheet
= GetBuffer().GetStyleSheet();
3122 if (GetBuffer().ApplyStyleSheet(styleSheet
))
3124 GetBuffer().Invalidate(wxRICHTEXT_ALL
);
3132 /// Sets the default style to the style under the cursor
3133 bool wxRichTextCtrl::SetDefaultStyleToCursorStyle()
3136 attr
.SetFlags(wxTEXT_ATTR_CHARACTER
);
3138 // If at the start of a paragraph, use the next position.
3139 long pos
= GetAdjustedCaretPosition(GetCaretPosition());
3141 if (GetUncombinedStyle(pos
, attr
))
3143 SetDefaultStyle(attr
);
3150 /// Returns the first visible position in the current view
3151 long wxRichTextCtrl::GetFirstVisiblePosition() const
3153 wxRichTextLine
* line
= GetBuffer().GetLineAtYPosition(GetLogicalPoint(wxPoint(0, 0)).y
);
3155 return line
->GetAbsoluteRange().GetStart();
3160 /// Get the first visible point in the window
3161 wxPoint
wxRichTextCtrl::GetFirstVisiblePoint() const
3164 int startXUnits
, startYUnits
;
3166 GetScrollPixelsPerUnit(& ppuX
, & ppuY
);
3167 GetViewStart(& startXUnits
, & startYUnits
);
3169 return wxPoint(startXUnits
* ppuX
, startYUnits
* ppuY
);
3172 /// The adjusted caret position is the character position adjusted to take
3173 /// into account whether we're at the start of a paragraph, in which case
3174 /// style information should be taken from the next position, not current one.
3175 long wxRichTextCtrl::GetAdjustedCaretPosition(long caretPos
) const
3177 wxRichTextParagraph
* para
= GetBuffer().GetParagraphAtPosition(caretPos
+1);
3179 if (para
&& (caretPos
+1 == para
->GetRange().GetStart()))
3184 /// Get/set the selection range in character positions. -1, -1 means no selection.
3185 /// The range is in API convention, i.e. a single character selection is denoted
3187 wxRichTextRange
wxRichTextCtrl::GetSelectionRange() const
3189 wxRichTextRange range
= GetInternalSelectionRange();
3190 if (range
!= wxRichTextRange(-2,-2) && range
!= wxRichTextRange(-1,-1))
3191 range
.SetEnd(range
.GetEnd() + 1);
3195 void wxRichTextCtrl::SetSelectionRange(const wxRichTextRange
& range
)
3197 wxRichTextRange
range1(range
);
3198 if (range1
!= wxRichTextRange(-2,-2) && range1
!= wxRichTextRange(-1,-1) )
3199 range1
.SetEnd(range1
.GetEnd() - 1);
3201 wxASSERT( range1
.GetStart() > range1
.GetEnd() );
3203 SetInternalSelectionRange(range1
);
3207 bool wxRichTextCtrl::SetListStyle(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int startFrom
, int specifiedLevel
)
3209 return GetBuffer().SetListStyle(range
.ToInternal(), def
, flags
, startFrom
, specifiedLevel
);
3212 bool wxRichTextCtrl::SetListStyle(const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int startFrom
, int specifiedLevel
)
3214 return GetBuffer().SetListStyle(range
.ToInternal(), defName
, flags
, startFrom
, specifiedLevel
);
3217 /// Clear list for given range
3218 bool wxRichTextCtrl::ClearListStyle(const wxRichTextRange
& range
, int flags
)
3220 return GetBuffer().ClearListStyle(range
.ToInternal(), flags
);
3223 /// Number/renumber any list elements in the given range
3224 bool wxRichTextCtrl::NumberList(const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int startFrom
, int specifiedLevel
)
3226 return GetBuffer().NumberList(range
.ToInternal(), def
, flags
, startFrom
, specifiedLevel
);
3229 bool wxRichTextCtrl::NumberList(const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int startFrom
, int specifiedLevel
)
3231 return GetBuffer().NumberList(range
.ToInternal(), defName
, flags
, startFrom
, specifiedLevel
);
3234 /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
3235 bool wxRichTextCtrl::PromoteList(int promoteBy
, const wxRichTextRange
& range
, wxRichTextListStyleDefinition
* def
, int flags
, int specifiedLevel
)
3237 return GetBuffer().PromoteList(promoteBy
, range
.ToInternal(), def
, flags
, specifiedLevel
);
3240 bool wxRichTextCtrl::PromoteList(int promoteBy
, const wxRichTextRange
& range
, const wxString
& defName
, int flags
, int specifiedLevel
)
3242 return GetBuffer().PromoteList(promoteBy
, range
.ToInternal(), defName
, flags
, specifiedLevel
);
3245 /// Deletes the content in the given range
3246 bool wxRichTextCtrl::Delete(const wxRichTextRange
& range
)
3248 return GetBuffer().DeleteRangeWithUndo(range
.ToInternal(), this);
3251 const wxArrayString
& wxRichTextCtrl::GetAvailableFontNames()
3253 if (sm_availableFontNames
.GetCount() == 0)
3255 sm_availableFontNames
= wxFontEnumerator::GetFacenames();
3256 sm_availableFontNames
.Sort();
3258 return sm_availableFontNames
;
3261 void wxRichTextCtrl::ClearAvailableFontNames()
3263 sm_availableFontNames
.Clear();
3266 void wxRichTextCtrl::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
3268 //wxLogDebug(wxT("wxRichTextCtrl::OnSysColourChanged"));
3270 wxTextAttrEx basicStyle
= GetBasicStyle();
3271 basicStyle
.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
));
3272 SetBasicStyle(basicStyle
);
3273 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
3278 // Refresh the area affected by a selection change
3279 bool wxRichTextCtrl::RefreshForSelectionChange(const wxRichTextRange
& oldSelection
, const wxRichTextRange
& newSelection
)
3281 // Calculate the refresh rectangle - just the affected lines
3282 long firstPos
, lastPos
;
3283 if (oldSelection
.GetStart() == -2 && newSelection
.GetStart() != -2)
3285 firstPos
= newSelection
.GetStart();
3286 lastPos
= newSelection
.GetEnd();
3288 else if (oldSelection
.GetStart() != -2 && newSelection
.GetStart() == -2)
3290 firstPos
= oldSelection
.GetStart();
3291 lastPos
= oldSelection
.GetEnd();
3293 else if (oldSelection
.GetStart() == -2 && newSelection
.GetStart() == -2)
3299 firstPos
= wxMin(oldSelection
.GetStart(), newSelection
.GetStart());
3300 lastPos
= wxMax(oldSelection
.GetEnd(), newSelection
.GetEnd());
3303 wxRichTextLine
* firstLine
= GetBuffer().GetLineAtPosition(firstPos
);
3304 wxRichTextLine
* lastLine
= GetBuffer().GetLineAtPosition(lastPos
);
3306 if (firstLine
&& lastLine
)
3308 wxSize clientSize
= GetClientSize();
3309 wxPoint pt1
= GetPhysicalPoint(firstLine
->GetAbsolutePosition());
3310 wxPoint pt2
= GetPhysicalPoint(lastLine
->GetAbsolutePosition()) + wxPoint(0, lastLine
->GetSize().y
);
3313 pt1
.y
= wxMax(0, pt1
.y
);
3315 pt2
.y
= wxMin(clientSize
.y
, pt2
.y
);
3317 wxRect
rect(pt1
, wxSize(clientSize
.x
, pt2
.y
- pt1
.y
));
3318 RefreshRect(rect
, false);
3326 #if wxRICHTEXT_USE_OWN_CARET
3328 // ----------------------------------------------------------------------------
3329 // initialization and destruction
3330 // ----------------------------------------------------------------------------
3332 void wxRichTextCaret::Init()
3338 m_richTextCtrl
= NULL
;
3339 m_needsUpdate
= false;
3342 wxRichTextCaret::~wxRichTextCaret()
3346 // ----------------------------------------------------------------------------
3347 // showing/hiding/moving the caret (base class interface)
3348 // ----------------------------------------------------------------------------
3350 void wxRichTextCaret::DoShow()
3355 void wxRichTextCaret::DoHide()
3360 void wxRichTextCaret::DoMove()
3366 if (m_xOld
!= -1 && m_yOld
!= -1)
3370 wxRect
rect(GetPosition(), GetSize());
3371 m_richTextCtrl
->RefreshRect(rect
, false);
3380 void wxRichTextCaret::DoSize()
3382 int countVisible
= m_countVisible
;
3383 if (countVisible
> 0)
3389 if (countVisible
> 0)
3391 m_countVisible
= countVisible
;
3396 // ----------------------------------------------------------------------------
3397 // handling the focus
3398 // ----------------------------------------------------------------------------
3400 void wxRichTextCaret::OnSetFocus()
3408 void wxRichTextCaret::OnKillFocus()
3413 // ----------------------------------------------------------------------------
3414 // drawing the caret
3415 // ----------------------------------------------------------------------------
3417 void wxRichTextCaret::Refresh()
3421 wxRect
rect(GetPosition(), GetSize());
3422 m_richTextCtrl
->RefreshRect(rect
, false);
3426 void wxRichTextCaret::DoDraw(wxDC
*dc
)
3428 dc
->SetPen( *wxBLACK_PEN
);
3430 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
3431 dc
->SetPen(*wxBLACK_PEN
);
3433 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
3434 // done under wxGTK - no idea why
3435 //dc->SetLogicalFunction(wxINVERT);
3437 wxPoint
pt(m_x
, m_y
);
3441 pt
= m_richTextCtrl
->GetLogicalPoint(pt
);
3443 dc
->DrawRectangle(pt
.x
, pt
.y
, m_width
, m_height
);
3446 // wxRICHTEXT_USE_OWN_CARET