#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(#api)
+#endif // Win16/32
+
// ===========================================================================
// implementation
// ===========================================================================
//static
void wxCaretBase::SetBlinkTime(int milliseconds)
{
- if ( !::SetCaretBlinkTime(milliseconds) )
- {
- wxLogLastError("SetCaretBlinkTime");
- }
+ CALL_CARET_API(SetCaretBlinkTime, (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(), _T("caret without window cannot be created") );
+ wxASSERT_MSG( IsOk(), _T("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;
{
m_hasCaret = FALSE;
- if ( !::DestroyCaret() )
- {
- wxLogLastError("DestroyCaret");
- }
+ CALL_CARET_API(DestroyCaret, ());
}
}
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(), _T("caret without window cannot be shown") );
+ wxASSERT_MSG( IsOk(), _T("caret of zero size cannot be shown") );
- 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()
{
- wxASSERT_MSG( m_hasCaret, "cannot hide non existent caret" );
-
- if ( !::HideCaret(GetWinHwnd(GetWindow())) )
+ if ( m_hasCaret )
{
- wxLogLastError("HideCaret");
+ CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
}
}
{
if ( m_hasCaret )
{
- if ( !::SetCaretPos(m_x, m_y) )
- {
- wxLogLastError("SetCaretPos");
- }
+ wxWindow *winFocus = wxWindow::FindFocus();
+ wxASSERT_MSG( winFocus == GetWindow(), _T("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)
}