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