X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e46286351dbfa7ae98e8341e4fc328b134601e87..ad9cd15cb0476cf712cbd69461330c5b8ab270f3:/src/generic/caret.cpp?ds=sidebyside diff --git a/src/generic/caret.cpp b/src/generic/caret.cpp index 2620630941..3371a270cd 100644 --- a/src/generic/caret.cpp +++ b/src/generic/caret.cpp @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: generic/caret.h -// Purpose: generic wxCaret class +// Name: generic/caret.cpp +// Purpose: generic wxCaret class implementation // Author: Vadim Zeitlin (original code by Robert Roebling) // Modified by: // Created: 25.05.99 @@ -18,7 +18,7 @@ // ---------------------------------------------------------------------------- #ifdef __GNUG__ -#pragma implementation "caret.h" + #pragma implementation "caret.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -46,6 +46,10 @@ static int gs_blinkTime = 500; // in milliseconds // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// timer stuff +// ---------------------------------------------------------------------------- + wxCaretTimer::wxCaretTimer(wxCaret *caret) { m_caret = caret; @@ -53,14 +57,20 @@ wxCaretTimer::wxCaretTimer(wxCaret *caret) void wxCaretTimer::Notify() { - m_caret->Blink(); + m_caret->OnTimer(); +} + +void wxCaret::OnTimer() +{ + // don't blink the caret when we don't have the focus + if ( m_hasFocus ) + Blink(); } // ---------------------------------------------------------------------------- // wxCaret static functions and data // ---------------------------------------------------------------------------- - int wxCaretBase::GetBlinkTime() { return gs_blinkTime; @@ -77,6 +87,8 @@ void wxCaretBase::SetBlinkTime(int milliseconds) void wxCaret::InitGeneric() { + m_hasFocus = TRUE; + m_blinkedOut = FALSE; } wxCaret::~wxCaret() @@ -119,6 +131,32 @@ void wxCaret::DoMove() //else: will be shown at the correct location next time it blinks } +// ---------------------------------------------------------------------------- +// handling the focus +// ---------------------------------------------------------------------------- + +void wxCaret::OnSetFocus() +{ + m_hasFocus = TRUE; + + Refresh(); +} + +void wxCaret::OnKillFocus() +{ + m_hasFocus = FALSE; + + if ( IsVisible() ) + { + // the caret must be shown - otherwise, if it is hidden now, it will + // stay so until the focus doesn't return because it won't blink any + // more + m_blinkedOut = FALSE; + } + + Refresh(); +} + // ---------------------------------------------------------------------------- // drawing the caret // ---------------------------------------------------------------------------- @@ -127,14 +165,23 @@ void wxCaret::Blink() { m_blinkedOut = !m_blinkedOut; - wxClientDC dc(GetWindow()); + Refresh(); +} + +void wxCaret::Refresh() +{ if ( !m_blinkedOut ) { + wxClientDC dc(GetWindow()); DoDraw(&dc); } else { - // FIXME can't be less efficient than this... (+1 needed!) + // FIXME can't be less efficient than this... we probably should use + // backing store for the caret instead of leaving all the burden + // of correct refresh logic handling to the user code + + // NB: +1 is needed! wxRect rect(m_x, m_y, m_width + 1, m_height + 1); GetWindow()->Refresh(FALSE, &rect); } @@ -143,8 +190,18 @@ void wxCaret::Blink() void wxCaret::DoDraw(wxDC *dc) { dc->SetPen( *wxBLACK_PEN ); + + // VZ: Robert's code for I-shaped caret - this is nice but doesn't look + // at all the same as the MSW version and I don't know how to indicate + // that the window has focus or not with such caret +#if 0 dc->DrawLine( m_x, m_y, m_x+m_width, m_y ); dc->DrawLine( m_x, m_y+m_height, m_x+m_width, m_y+m_height ); dc->DrawLine( m_x+(m_width/2), m_y, m_x+(m_width/2), m_y+m_height ); // dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height ); +#else // 1 + if ( m_hasFocus ) + dc->SetBrush( *wxBLACK_BRUSH ); + dc->DrawRectangle( m_x, m_y, m_width, m_height ); +#endif // 0/1 }