diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 7c67cb23e3..76e578e49f 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -128,6 +128,11 @@ public: virtual void SetSelection(long from, long to); virtual void SetEditable(bool editable); + // Caret handling (Windows only) + + bool ShowNativeCaret(bool show = true); + bool HideNativeCaret() { return ShowNativeCaret(false); } + // Implementation from now on // -------------------------- @@ -184,6 +189,10 @@ public: // EDIT control has one already) void OnRightClick(wxMouseEvent& event); + // be sure the caret remains invisible if the user + // called HideNativeCaret() before + void OnSetFocus(wxFocusEvent& event); + protected: // common part of all ctors void Init(); @@ -245,6 +254,8 @@ private: DECLARE_DYNAMIC_CLASS(wxTextCtrl) wxMenu* m_privateContextMenu; + + bool m_isNativeCaretShown; }; #endif diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 81fce2b330..276df78633 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -144,6 +144,8 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) #ifdef __WIN16__ EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground) #endif + + EVT_SET_FOCUS(wxTextCtrl::OnSetFocus) END_EVENT_TABLE() // ============================================================================ @@ -162,6 +164,7 @@ void wxTextCtrl::Init() m_privateContextMenu = NULL; m_suppressNextUpdate = FALSE; + m_isNativeCaretShown = true; } wxTextCtrl::~wxTextCtrl() @@ -1240,6 +1243,27 @@ bool wxTextCtrl::CanRedo() const return ::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0; } +// ---------------------------------------------------------------------------- +// caret handling (Windows only) +// ---------------------------------------------------------------------------- + +bool wxTextCtrl::ShowNativeCaret(bool show) +{ + if ( show != m_isNativeCaretShown ) + { + if ( !(show ? ::ShowCaret(GetHwnd()) : ::HideCaret(GetHwnd())) ) + { + // not an error, may simply indicate that it's not shown/hidden + // yet (i.e. it had been hidden/showh 2 times before) + return false; + } + + m_isNativeCaretShown = show; + } + + return true; +} + // ---------------------------------------------------------------------------- // implemenation details // ---------------------------------------------------------------------------- @@ -1711,6 +1735,15 @@ void wxTextCtrl::OnRightClick(wxMouseEvent& event) event.Skip(); } +void wxTextCtrl::OnSetFocus(wxFocusEvent& event) +{ + // be sure the caret remains invisible if the user had hidden it + if ( !m_isNativeCaretShown ) + { + ::HideCaret(GetHwnd()); + } +} + // the rest of the file only deals with the rich edit controls #if wxUSE_RICHEDIT