X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/837e57436a89516a5fa9f478f401e06bd872c17c..b97d6fb1183ee1317258bea5ed1798546fccaf36:/src/msw/caret.cpp diff --git a/src/msw/caret.cpp b/src/msw/caret.cpp index dec7d89ea5..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,8 +31,20 @@ #include "wx/caret.h" +#if wxUSE_CARET + #include "wx/msw/private.h" +// --------------------------------------------------------------------------- +// macros +// --------------------------------------------------------------------------- + +#define CALL_CARET_API(api, args) \ + if ( !api args ) \ + { \ + wxLogLastError(wxT(#api)); \ + } + // =========================================================================== // implementation // =========================================================================== @@ -51,7 +59,7 @@ int wxCaretBase::GetBlinkTime() int blinkTime = ::GetCaretBlinkTime(); if ( !blinkTime ) { - wxLogLastError("GetCaretBlinkTime"); + wxLogLastError(wxT("GetCaretBlinkTime")); } return blinkTime; @@ -60,14 +68,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 +77,15 @@ 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 ) { -#ifdef __WIN16__ - ::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 + CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0, + m_width, m_height)); + + m_hasCaret = true; } return m_hasCaret; @@ -119,16 +111,9 @@ void wxCaret::OnKillFocus() { if ( m_hasCaret ) { - m_hasCaret = FALSE; + m_hasCaret = false; -#ifdef __WIN16__ - ::DestroyCaret() ; -#else - if ( !::DestroyCaret() ) - { - wxLogLastError("DestroyCaret"); - } -#endif + CALL_CARET_API(DestroyCaret, ()); } } @@ -138,36 +123,32 @@ 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") ); - 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(); + } } -#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 +160,31 @@ 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?") ); + + // 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