]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/caret.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: MSW implementation of wxCaret
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "caret.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/window.h"
38 #include "wx/msw/private.h"
40 // ---------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------
44 // under Win16 the caret APIs are void but under Win32 they may return an
45 // error code which we want to check - this macro does just this
47 #define CALL_CARET_API(api, args) api args
49 #define CALL_CARET_API(api, args) \
51 wxLogLastError(_T(#api))
54 // ===========================================================================
56 // ===========================================================================
58 // ---------------------------------------------------------------------------
60 // ---------------------------------------------------------------------------
63 int wxCaretBase::GetBlinkTime()
65 int blinkTime
= ::GetCaretBlinkTime();
68 wxLogLastError(wxT("GetCaretBlinkTime"));
75 void wxCaretBase::SetBlinkTime(int milliseconds
)
77 CALL_CARET_API(SetCaretBlinkTime
, (milliseconds
));
80 // ---------------------------------------------------------------------------
81 // creating/destroying the caret
82 // ---------------------------------------------------------------------------
84 bool wxCaret::MSWCreateCaret()
86 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
87 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
91 CALL_CARET_API(CreateCaret
, (GetWinHwnd(GetWindow()), 0,
100 void wxCaret::OnSetFocus()
102 if ( m_countVisible
> 0 )
104 if ( MSWCreateCaret() )
106 // the caret was recreated but it doesn't remember its position and
113 //else: caret is invisible, don't waste time creating it
116 void wxCaret::OnKillFocus()
122 CALL_CARET_API(DestroyCaret
, ());
126 // ---------------------------------------------------------------------------
127 // showing/hiding the caret
128 // ---------------------------------------------------------------------------
130 void wxCaret::DoShow()
132 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
133 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
135 // we might not have created the caret yet if we had got the focus first
136 // and the caret was shown later - so do it now if we have the focus but
138 if ( !m_hasCaret
&& (wxWindow::FindFocus() == GetWindow()) )
140 if ( MSWCreateCaret() )
148 CALL_CARET_API(ShowCaret
, (GetWinHwnd(GetWindow())));
150 //else: will be shown when we get the focus
153 void wxCaret::DoHide()
157 CALL_CARET_API(HideCaret
, (GetWinHwnd(GetWindow())));
161 // ---------------------------------------------------------------------------
163 // ---------------------------------------------------------------------------
165 void wxCaret::DoMove()
169 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
170 wxT("how did we lose focus?") );
172 // for compatibility with the generic version, the coordinates are
174 wxPoint pt
= GetWindow()->GetClientAreaOrigin();
175 CALL_CARET_API(SetCaretPos
, (m_x
+ pt
.x
, m_y
+ pt
.y
));
177 //else: we don't have caret right now, nothing to do (this does happen)
181 // ---------------------------------------------------------------------------
182 // resizing the caret
183 // ---------------------------------------------------------------------------
185 void wxCaret::DoSize()
190 CALL_CARET_API(DestroyCaret
, ());