// Modified by:
// Created: 23.05.99
// RCS-ID: $Id$
-// Copyright: (c) wxWindows team
+// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// headers
// ---------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "caret.h"
#endif
#ifndef WX_PRECOMP
#include "wx/window.h"
+ #include "wx/log.h"
#endif // WX_PRECOMP
#include "wx/caret.h"
+#if wxUSE_CARET
+
#include "wx/msw/private.h"
+// ---------------------------------------------------------------------------
+// macros
+// ---------------------------------------------------------------------------
+
+#define CALL_CARET_API(api, args) \
+ if ( !api args ) \
+ wxLogLastError(_T(#api))
+
// ===========================================================================
// implementation
// ===========================================================================
int blinkTime = ::GetCaretBlinkTime();
if ( !blinkTime )
{
- wxLogLastError("GetCaretBlinkTime");
+ wxLogLastError(wxT("GetCaretBlinkTime"));
}
return blinkTime;
//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(), 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;
{
if ( m_hasCaret )
{
- m_hasCaret = FALSE;
+ 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" );
+ 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()
{
- wxASSERT_MSG( m_hasCaret, "cannot hide non existent caret" );
-
- if ( !::HideCaret(GetWinHwnd(GetWindow())) )
+ if ( m_hasCaret )
{
- wxLogLastError("HideCaret");
+ CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
}
}
void wxCaret::DoMove()
{
- wxASSERT_MSG( m_hasCaret, "cannot move non existent caret" );
+ if ( m_hasCaret )
+ {
+ 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)
+}
- if ( !::SetCaretPos(m_x, m_y) )
+
+// ---------------------------------------------------------------------------
+// resizing the caret
+// ---------------------------------------------------------------------------
+
+void wxCaret::DoSize()
+{
+ if ( m_hasCaret )
{
- wxLogLastError("SetCaretPos");
+ m_hasCaret = false;
+ CALL_CARET_API(DestroyCaret, ());
+ MSWCreateCaret();
+ OnSetFocus();
}
}
+
+#endif