X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cfb76a19a4aeb25f245196ff5d4cae8a33fa6802..917b00857982f2ca7247a9785c11a6a1d7e01943:/src/msw/caret.cpp diff --git a/src/msw/caret.cpp b/src/msw/caret.cpp index cacc6801f5..4252a732f1 100644 --- a/src/msw/caret.cpp +++ b/src/msw/caret.cpp @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: msw/caret.cpp +// Name: src/msw/caret.cpp // Purpose: MSW implementation of wxCaret // Author: Vadim Zeitlin // Modified by: // Created: 23.05.99 // RCS-ID: $Id$ -// Copyright: (c) wxWindows team +// Copyright: (c) wxWidgets team // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -17,10 +17,6 @@ // headers // --------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "caret.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -35,19 +31,19 @@ #include "wx/caret.h" +#if wxUSE_CARET + #include "wx/msw/private.h" // --------------------------------------------------------------------------- // macros // --------------------------------------------------------------------------- -// under Win16 the caret APIs are void but under Win32 they may return an -// error code which we want to check - this macro does just this -#ifdef __WIN16__ - #define CALL_CARET_API(api, args) api args -#else // Win32 - #define CALL_CARET_API(api, args) if ( !api args ) wxLogLastError(#api) -#endif // Win16/32 +#define CALL_CARET_API(api, args) \ + if ( !api args ) \ + { \ + wxLogLastError(wxT(#api)); \ + } // =========================================================================== // implementation @@ -63,7 +59,7 @@ int wxCaretBase::GetBlinkTime() int blinkTime = ::GetCaretBlinkTime(); if ( !blinkTime ) { - wxLogLastError("GetCaretBlinkTime"); + wxLogLastError(wxT("GetCaretBlinkTime")); } return blinkTime; @@ -89,7 +85,7 @@ bool wxCaret::MSWCreateCaret() CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0, m_width, m_height)); - m_hasCaret = TRUE; + m_hasCaret = true; } return m_hasCaret; @@ -115,7 +111,7 @@ void wxCaret::OnKillFocus() { if ( m_hasCaret ) { - m_hasCaret = FALSE; + m_hasCaret = false; CALL_CARET_API(DestroyCaret, ()); } @@ -130,6 +126,17 @@ void wxCaret::DoShow() wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") ); wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") ); + // we might not have created the caret yet if we had got the focus first + // and the caret was shown later - so do it now if we have the focus but + // not the caret + if ( !m_hasCaret && (wxWindow::FindFocus() == GetWindow()) ) + { + if ( MSWCreateCaret() ) + { + DoMove(); + } + } + if ( m_hasCaret ) { CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow()))); @@ -156,7 +163,10 @@ void wxCaret::DoMove() wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(), wxT("how did we lose focus?") ); - CALL_CARET_API(SetCaretPos, (m_x, m_y)); + // for compatibility with the generic version, the coordinates are + // client ones + wxPoint pt = GetWindow()->GetClientAreaOrigin(); + CALL_CARET_API(SetCaretPos, (m_x + pt.x, m_y + pt.y)); } //else: we don't have caret right now, nothing to do (this does happen) } @@ -170,9 +180,11 @@ void wxCaret::DoSize() { if ( m_hasCaret ) { - m_hasCaret = FALSE; + m_hasCaret = false; CALL_CARET_API(DestroyCaret, ()); MSWCreateCaret(); - DoMove(); + OnSetFocus(); } } + +#endif