]> git.saurik.com Git - wxWidgets.git/blob - src/msw/caret.cpp
final sweep over docs - replace & with \&
[wxWidgets.git] / src / msw / caret.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/caret.cpp
3 // Purpose: MSW implementation of wxCaret
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 23.05.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "caret.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/window.h"
33 #include "wx/log.h"
34 #endif // WX_PRECOMP
35
36 #include "wx/caret.h"
37
38 #if wxUSE_CARET
39
40 #include "wx/msw/private.h"
41
42 // ---------------------------------------------------------------------------
43 // macros
44 // ---------------------------------------------------------------------------
45
46 #define CALL_CARET_API(api, args) \
47 if ( !api args ) \
48 wxLogLastError(_T(#api))
49
50 // ===========================================================================
51 // implementation
52 // ===========================================================================
53
54 // ---------------------------------------------------------------------------
55 // blink time
56 // ---------------------------------------------------------------------------
57
58 //static
59 int wxCaretBase::GetBlinkTime()
60 {
61 int blinkTime = ::GetCaretBlinkTime();
62 if ( !blinkTime )
63 {
64 wxLogLastError(wxT("GetCaretBlinkTime"));
65 }
66
67 return blinkTime;
68 }
69
70 //static
71 void wxCaretBase::SetBlinkTime(int milliseconds)
72 {
73 CALL_CARET_API(SetCaretBlinkTime, (milliseconds));
74 }
75
76 // ---------------------------------------------------------------------------
77 // creating/destroying the caret
78 // ---------------------------------------------------------------------------
79
80 bool wxCaret::MSWCreateCaret()
81 {
82 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
83 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
84
85 if ( !m_hasCaret )
86 {
87 CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0,
88 m_width, m_height));
89
90 m_hasCaret = true;
91 }
92
93 return m_hasCaret;
94 }
95
96 void wxCaret::OnSetFocus()
97 {
98 if ( m_countVisible > 0 )
99 {
100 if ( MSWCreateCaret() )
101 {
102 // the caret was recreated but it doesn't remember its position and
103 // it's not shown
104
105 DoMove();
106 DoShow();
107 }
108 }
109 //else: caret is invisible, don't waste time creating it
110 }
111
112 void wxCaret::OnKillFocus()
113 {
114 if ( m_hasCaret )
115 {
116 m_hasCaret = false;
117
118 CALL_CARET_API(DestroyCaret, ());
119 }
120 }
121
122 // ---------------------------------------------------------------------------
123 // showing/hiding the caret
124 // ---------------------------------------------------------------------------
125
126 void wxCaret::DoShow()
127 {
128 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
129 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
130
131 // we might not have created the caret yet if we had got the focus first
132 // and the caret was shown later - so do it now if we have the focus but
133 // not the caret
134 if ( !m_hasCaret && (wxWindow::FindFocus() == GetWindow()) )
135 {
136 if ( MSWCreateCaret() )
137 {
138 DoMove();
139 }
140 }
141
142 if ( m_hasCaret )
143 {
144 CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow())));
145 }
146 //else: will be shown when we get the focus
147 }
148
149 void wxCaret::DoHide()
150 {
151 if ( m_hasCaret )
152 {
153 CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
154 }
155 }
156
157 // ---------------------------------------------------------------------------
158 // moving the caret
159 // ---------------------------------------------------------------------------
160
161 void wxCaret::DoMove()
162 {
163 if ( m_hasCaret )
164 {
165 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
166 wxT("how did we lose focus?") );
167
168 // for compatibility with the generic version, the coordinates are
169 // client ones
170 wxPoint pt = GetWindow()->GetClientAreaOrigin();
171 CALL_CARET_API(SetCaretPos, (m_x + pt.x, m_y + pt.y));
172 }
173 //else: we don't have caret right now, nothing to do (this does happen)
174 }
175
176
177 // ---------------------------------------------------------------------------
178 // resizing the caret
179 // ---------------------------------------------------------------------------
180
181 void wxCaret::DoSize()
182 {
183 if ( m_hasCaret )
184 {
185 m_hasCaret = false;
186 CALL_CARET_API(DestroyCaret, ());
187 MSWCreateCaret();
188 OnSetFocus();
189 }
190 }
191
192 #endif