]>
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"
40 #include "wx/msw/private.h"
42 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
46 // under Win16 the caret APIs are void but under Win32 they may return an
47 // error code which we want to check - this macro does just this
49 #define CALL_CARET_API(api, args) api args
51 #define CALL_CARET_API(api, args) \
53 wxLogLastError(_T(#api))
56 // ===========================================================================
58 // ===========================================================================
60 // ---------------------------------------------------------------------------
62 // ---------------------------------------------------------------------------
65 int wxCaretBase::GetBlinkTime()
67 int blinkTime
= ::GetCaretBlinkTime();
70 wxLogLastError(wxT("GetCaretBlinkTime"));
77 void wxCaretBase::SetBlinkTime(int milliseconds
)
79 CALL_CARET_API(SetCaretBlinkTime
, (milliseconds
));
82 // ---------------------------------------------------------------------------
83 // creating/destroying the caret
84 // ---------------------------------------------------------------------------
86 bool wxCaret::MSWCreateCaret()
88 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
89 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
93 CALL_CARET_API(CreateCaret
, (GetWinHwnd(GetWindow()), 0,
102 void wxCaret::OnSetFocus()
104 if ( m_countVisible
> 0 )
106 if ( MSWCreateCaret() )
108 // the caret was recreated but it doesn't remember its position and
115 //else: caret is invisible, don't waste time creating it
118 void wxCaret::OnKillFocus()
124 CALL_CARET_API(DestroyCaret
, ());
128 // ---------------------------------------------------------------------------
129 // showing/hiding the caret
130 // ---------------------------------------------------------------------------
132 void wxCaret::DoShow()
134 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
135 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
137 // we might not have created the caret yet if we had got the focus first
138 // and the caret was shown later - so do it now if we have the focus but
140 if ( !m_hasCaret
&& (wxWindow::FindFocus() == GetWindow()) )
142 if ( MSWCreateCaret() )
150 CALL_CARET_API(ShowCaret
, (GetWinHwnd(GetWindow())));
152 //else: will be shown when we get the focus
155 void wxCaret::DoHide()
159 CALL_CARET_API(HideCaret
, (GetWinHwnd(GetWindow())));
163 // ---------------------------------------------------------------------------
165 // ---------------------------------------------------------------------------
167 void wxCaret::DoMove()
171 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
172 wxT("how did we lose focus?") );
174 // for compatibility with the generic version, the coordinates are
176 wxPoint pt
= GetWindow()->GetClientAreaOrigin();
177 CALL_CARET_API(SetCaretPos
, (m_x
+ pt
.x
, m_y
+ pt
.y
));
179 //else: we don't have caret right now, nothing to do (this does happen)
183 // ---------------------------------------------------------------------------
184 // resizing the caret
185 // ---------------------------------------------------------------------------
187 void wxCaret::DoSize()
192 CALL_CARET_API(DestroyCaret
, ());