From e28c2d151b92823e2375d264a66ee4ed61ffd2e9 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 11 Aug 2003 16:33:56 +0000 Subject: [PATCH] wxCaretSuspender only shows the caret if it was visible previously Improved caret handling in wxTextCtrl Restored scrollbar painting in wxUniv git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22773 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/caret.h | 9 +++++++-- src/univ/listbox.cpp | 1 + src/univ/scrolbar.cpp | 1 + src/univ/textctrl.cpp | 34 ++++++++++++++++++++++++++++------ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/wx/caret.h b/include/wx/caret.h index 266f6d278d..f8e547bc38 100644 --- a/include/wx/caret.h +++ b/include/wx/caret.h @@ -212,18 +212,23 @@ public: wxCaretSuspend(wxWindow *win) { m_caret = win->GetCaret(); - if ( m_caret ) + m_show = FALSE; + if ( m_caret && m_caret->IsVisible() ) + { m_caret->Hide(); + m_show = TRUE; + } } ~wxCaretSuspend() { - if ( m_caret ) + if ( m_caret && m_show ) m_caret->Show(); } private: wxCaret *m_caret; + bool m_show; DECLARE_NO_COPY_CLASS(wxCaretSuspend) }; diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index 84cd3a79a1..2b2ec463e3 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -622,6 +622,7 @@ void wxListBox::OnInternalIdle() m_updateCount = 0; } + OnInternalIdle(); } // ---------------------------------------------------------------------------- diff --git a/src/univ/scrolbar.cpp b/src/univ/scrolbar.cpp index 3873aed615..8626070f0d 100644 --- a/src/univ/scrolbar.cpp +++ b/src/univ/scrolbar.cpp @@ -324,6 +324,7 @@ wxScrollArrows::Arrow wxScrollBar::HitTest(const wxPoint& pt) const void wxScrollBar::OnInternalIdle() { UpdateThumb(); + wxControl::OnInternalIdle(); } void wxScrollBar::UpdateThumb() diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index 6e28cbd26c..1ac457b944 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -735,6 +735,9 @@ bool wxTextCtrl::Create(wxWindow *parent, CreateInputHandler(wxINP_HANDLER_TEXTCTRL); + wxSizeEvent sizeEvent(GetSize(), GetId()); + GetEventHandler()->ProcessEvent(sizeEvent); + return TRUE; } @@ -1864,7 +1867,9 @@ wxPoint wxTextCtrl::GetCaretPosition() const // pos may be -1 to show the current position void wxTextCtrl::ShowPosition(wxTextPos pos) { - HideCaret(); + bool showCaret = GetCaret() && GetCaret()->IsVisible(); + if (showCaret) + HideCaret(); if ( IsSingleLine() ) { @@ -1984,7 +1989,8 @@ void wxTextCtrl::ShowPosition(wxTextPos pos) } //else: multiline but no scrollbars, hence nothing to do - ShowCaret(); + if (showCaret) + ShowCaret(); } // ---------------------------------------------------------------------------- @@ -4179,7 +4185,7 @@ void wxTextCtrl::DoDraw(wxControlRenderer *renderer) // show caret first time only: we must show it after drawing the text or // the display can be corrupted when it's hidden - if ( !m_hasCaret && GetCaret() ) + if ( !m_hasCaret && GetCaret() && (FindFocus() == this) ) { ShowCaret(); @@ -4222,7 +4228,10 @@ bool wxTextCtrl::Enable(bool enable) if ( !wxTextCtrlBase::Enable(enable) ) return FALSE; - ShowCaret(enable); + if (FindFocus() == this && GetCaret() && + ((enable && !GetCaret()->IsVisible()) || + (!enable && GetCaret()->IsVisible()))) + ShowCaret(enable); return TRUE; } @@ -4258,7 +4267,9 @@ void wxTextCtrl::ShowCaret(bool show) caret->Move(GetCaretPosition()); // and show it there - caret->Show(show); + if ((show && !caret->IsVisible()) || + (!show && caret->IsVisible())) + caret->Show(show); } } @@ -4902,13 +4913,24 @@ bool wxStdTextCtrlInputHandler::HandleMouseMove(wxInputConsumer *consumer, bool wxStdTextCtrlInputHandler::HandleFocus(wxInputConsumer *consumer, - const wxFocusEvent& WXUNUSED(event)) + const wxFocusEvent& event) { wxTextCtrl *text = wxStaticCast(consumer->GetInputWindow(), wxTextCtrl); // the selection appearance changes depending on whether we have the focus text->RefreshSelection(); + if (event.GetEventType() == wxEVT_SET_FOCUS) + { + if (text->GetCaret() && !text->GetCaret()->IsVisible()) + text->ShowCaret(); + } + else + { + if (text->GetCaret() && text->GetCaret()->IsVisible()) + text->HideCaret(); + } + // never refresh entirely return FALSE; } -- 2.45.2