X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5701b057fb4b5bf672da2fb19230d179f7f3e251..79630806b65160fe7a433f243a6aa9b55e690aec:/src/msw/caret.cpp diff --git a/src/msw/caret.cpp b/src/msw/caret.cpp index 87e46935a5..f6b34dba8a 100644 --- a/src/msw/caret.cpp +++ b/src/msw/caret.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 23.05.99 // RCS-ID: $Id$ -// Copyright: (c) wxWindows team +// Copyright: (c) wxWidgets team // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -17,7 +17,7 @@ // headers // --------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "caret.h" #endif @@ -35,19 +35,17 @@ #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(_T(#api)) // =========================================================================== // implementation @@ -63,7 +61,7 @@ int wxCaretBase::GetBlinkTime() int blinkTime = ::GetCaretBlinkTime(); if ( !blinkTime ) { - wxLogLastError("GetCaretBlinkTime"); + wxLogLastError(wxT("GetCaretBlinkTime")); } return blinkTime; @@ -81,8 +79,8 @@ void wxCaretBase::SetBlinkTime(int milliseconds) bool wxCaret::MSWCreateCaret() { - wxASSERT_MSG( GetWindow(), _T("caret without window cannot be created") ); - wxASSERT_MSG( IsOk(), _T("caret of zero size cannot be created") ); + wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") ); + wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") ); if ( !m_hasCaret ) { @@ -127,8 +125,19 @@ void wxCaret::OnKillFocus() void wxCaret::DoShow() { - wxASSERT_MSG( GetWindow(), _T("caret without window cannot be shown") ); - wxASSERT_MSG( IsOk(), _T("caret of zero size cannot be shown") ); + 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 ) { @@ -153,10 +162,31 @@ void wxCaret::DoMove() { if ( m_hasCaret ) { - wxWindow *winFocus = wxWindow::FindFocus(); - wxASSERT_MSG( winFocus == GetWindow(), _T("how did we lose focus?") ); + 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) } + + +// --------------------------------------------------------------------------- +// resizing the caret +// --------------------------------------------------------------------------- + +void wxCaret::DoSize() +{ + if ( m_hasCaret ) + { + m_hasCaret = FALSE; + CALL_CARET_API(DestroyCaret, ()); + MSWCreateCaret(); + OnSetFocus(); + } +} + +#endif