X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/25889d3c43f537fea00a2b7d6df7bd7e63e113f8..790ad94f70002941240d4877d1a4b7b1ef4c9aed:/src/msw/caret.cpp diff --git a/src/msw/caret.cpp b/src/msw/caret.cpp index 17ef55cb21..cacc6801f5 100644 --- a/src/msw/caret.cpp +++ b/src/msw/caret.cpp @@ -37,6 +37,18 @@ #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 + // =========================================================================== // implementation // =========================================================================== @@ -60,14 +72,7 @@ int wxCaretBase::GetBlinkTime() //static void wxCaretBase::SetBlinkTime(int milliseconds) { -#ifdef __WIN16__ - ::SetCaretBlinkTime(milliseconds) ; -#else - if ( !::SetCaretBlinkTime(milliseconds) ) - { - wxLogLastError("SetCaretBlinkTime"); - } -#endif + CALL_CARET_API(SetCaretBlinkTime, (milliseconds)); } // --------------------------------------------------------------------------- @@ -76,24 +81,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 ) { -#ifdef __WIN16__ - ::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) ; + CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0, + m_width, m_height)); + m_hasCaret = TRUE; -#else - if ( !::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) ) - { - wxLogLastError("CreateCaret"); - } - else - { - m_hasCaret = TRUE; - } -#endif } return m_hasCaret; @@ -121,14 +117,7 @@ void wxCaret::OnKillFocus() { m_hasCaret = FALSE; -#ifdef __WIN16__ - ::DestroyCaret() ; -#else - if ( !::DestroyCaret() ) - { - wxLogLastError("DestroyCaret"); - } -#endif + CALL_CARET_API(DestroyCaret, ()); } } @@ -138,36 +127,21 @@ 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" ); - - if ( !m_hasCaret ) - { - (void)MSWCreateCaret(); - } + wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") ); + wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") ); -#ifdef __WIN16__ - ::ShowCaret(GetWinHwnd(GetWindow())) ; -#else - if ( !::ShowCaret(GetWinHwnd(GetWindow())) ) + if ( m_hasCaret ) { - wxLogLastError("ShowCaret"); + CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow()))); } -#endif + //else: will be shown when we get the focus } void wxCaret::DoHide() { if ( m_hasCaret ) { -#ifdef __WIN16__ - ::HideCaret(GetWinHwnd(GetWindow())) ; -#else - if ( !::HideCaret(GetWinHwnd(GetWindow())) ) - { - wxLogLastError("HideCaret"); - } -#endif + CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow()))); } } @@ -179,14 +153,26 @@ void wxCaret::DoMove() { if ( m_hasCaret ) { -#ifdef __WIN16__ - ::SetCaretPos(m_x, m_y) ; -#else - if ( !::SetCaretPos(m_x, m_y) ) - { - wxLogLastError("SetCaretPos"); - } -#endif + wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(), + wxT("how did we lose focus?") ); + + CALL_CARET_API(SetCaretPos, (m_x, m_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(); + } +}