X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c6eba8f8b204b0d722db0007e3e0d5e2d2d20085..993eebf1bae0a595540cb282342e894f23fbb1ee:/src/msw/caret.cpp diff --git a/src/msw/caret.cpp b/src/msw/caret.cpp index 9d72d6bae0..f1fd767110 100644 --- a/src/msw/caret.cpp +++ b/src/msw/caret.cpp @@ -30,12 +30,27 @@ #ifndef WX_PRECOMP #include "wx/window.h" + #include "wx/log.h" #endif // WX_PRECOMP #include "wx/caret.h" #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(_T(#api)) +#endif // Win16/32 + // =========================================================================== // implementation // =========================================================================== @@ -50,7 +65,7 @@ int wxCaretBase::GetBlinkTime() int blinkTime = ::GetCaretBlinkTime(); if ( !blinkTime ) { - wxLogLastError("GetCaretBlinkTime"); + wxLogLastError(wxT("GetCaretBlinkTime")); } return blinkTime; @@ -59,10 +74,7 @@ int wxCaretBase::GetBlinkTime() //static void wxCaretBase::SetBlinkTime(int milliseconds) { - if ( !::SetCaretBlinkTime(milliseconds) ) - { - wxLogLastError("SetCaretBlinkTime"); - } + CALL_CARET_API(SetCaretBlinkTime, (milliseconds)); } // --------------------------------------------------------------------------- @@ -71,19 +83,15 @@ void wxCaretBase::SetBlinkTime(int milliseconds) bool wxCaret::MSWCreateCaret() { - wxASSERT_MSG( GetWindow(), "caret without window cannot be created" ); - wxASSERT_MSG( IsOk(), "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 ) { - if ( !::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) ) - { - wxLogLastError("CreateCaret"); - } - else - { - m_hasCaret = TRUE; - } + CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0, + m_width, m_height)); + + m_hasCaret = TRUE; } return m_hasCaret; @@ -111,10 +119,7 @@ void wxCaret::OnKillFocus() { m_hasCaret = FALSE; - if ( !::DestroyCaret() ) - { - wxLogLastError("DestroyCaret"); - } + CALL_CARET_API(DestroyCaret, ()); } } @@ -124,28 +129,32 @@ void wxCaret::OnKillFocus() void wxCaret::DoShow() { - wxASSERT_MSG( GetWindow(), "caret without window cannot be shown" ); - wxASSERT_MSG( IsOk(), "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") ); - if ( !m_hasCaret ) + // 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()) ) { - (void)MSWCreateCaret(); + if ( MSWCreateCaret() ) + { + DoMove(); + } } - if ( !::ShowCaret(GetWinHwnd(GetWindow())) ) + if ( m_hasCaret ) { - wxLogLastError("ShowCaret"); + CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow()))); } + //else: will be shown when we get the focus } void wxCaret::DoHide() { if ( m_hasCaret ) { - if ( !::HideCaret(GetWinHwnd(GetWindow())) ) - { - wxLogLastError("HideCaret"); - } + CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow()))); } } @@ -157,10 +166,29 @@ void wxCaret::DoMove() { if ( m_hasCaret ) { - if ( !::SetCaretPos(m_x, m_y) ) - { - wxLogLastError("SetCaretPos"); - } + wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(), + wxT("how did we lose focus?") ); + + // 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(); + DoMove(); + } +}