]>
Commit | Line | Data |
---|---|---|
789295bf VZ |
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) wxWindows team | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
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" | |
0c589ad0 | 33 | #include "wx/log.h" |
789295bf VZ |
34 | #endif // WX_PRECOMP |
35 | ||
36 | #include "wx/caret.h" | |
37 | ||
38 | #include "wx/msw/private.h" | |
39 | ||
40 | // =========================================================================== | |
41 | // implementation | |
42 | // =========================================================================== | |
43 | ||
44 | // --------------------------------------------------------------------------- | |
45 | // blink time | |
46 | // --------------------------------------------------------------------------- | |
47 | ||
48 | //static | |
49 | int wxCaretBase::GetBlinkTime() | |
50 | { | |
51 | int blinkTime = ::GetCaretBlinkTime(); | |
52 | if ( !blinkTime ) | |
53 | { | |
54 | wxLogLastError("GetCaretBlinkTime"); | |
55 | } | |
56 | ||
57 | return blinkTime; | |
58 | } | |
59 | ||
60 | //static | |
61 | void wxCaretBase::SetBlinkTime(int milliseconds) | |
62 | { | |
25889d3c JS |
63 | #ifdef __WIN16__ |
64 | ::SetCaretBlinkTime(milliseconds) ; | |
65 | #else | |
789295bf VZ |
66 | if ( !::SetCaretBlinkTime(milliseconds) ) |
67 | { | |
68 | wxLogLastError("SetCaretBlinkTime"); | |
69 | } | |
25889d3c | 70 | #endif |
789295bf VZ |
71 | } |
72 | ||
73 | // --------------------------------------------------------------------------- | |
74 | // creating/destroying the caret | |
75 | // --------------------------------------------------------------------------- | |
76 | ||
77 | bool wxCaret::MSWCreateCaret() | |
78 | { | |
79 | wxASSERT_MSG( GetWindow(), "caret without window cannot be created" ); | |
80 | wxASSERT_MSG( IsOk(), "caret of zero size cannot be created" ); | |
81 | ||
82 | if ( !m_hasCaret ) | |
83 | { | |
25889d3c JS |
84 | #ifdef __WIN16__ |
85 | ::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) ; | |
86 | m_hasCaret = TRUE; | |
87 | #else | |
789295bf VZ |
88 | if ( !::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) ) |
89 | { | |
90 | wxLogLastError("CreateCaret"); | |
91 | } | |
92 | else | |
93 | { | |
94 | m_hasCaret = TRUE; | |
95 | } | |
25889d3c | 96 | #endif |
789295bf VZ |
97 | } |
98 | ||
99 | return m_hasCaret; | |
100 | } | |
101 | ||
102 | void wxCaret::OnSetFocus() | |
103 | { | |
104 | if ( m_countVisible > 0 ) | |
105 | { | |
106 | if ( MSWCreateCaret() ) | |
107 | { | |
108 | // the caret was recreated but it doesn't remember its position and | |
109 | // it's not shown | |
110 | ||
111 | DoMove(); | |
112 | DoShow(); | |
113 | } | |
114 | } | |
115 | //else: caret is invisible, don't waste time creating it | |
116 | } | |
117 | ||
118 | void wxCaret::OnKillFocus() | |
119 | { | |
120 | if ( m_hasCaret ) | |
121 | { | |
122 | m_hasCaret = FALSE; | |
123 | ||
25889d3c JS |
124 | #ifdef __WIN16__ |
125 | ::DestroyCaret() ; | |
126 | #else | |
789295bf VZ |
127 | if ( !::DestroyCaret() ) |
128 | { | |
129 | wxLogLastError("DestroyCaret"); | |
130 | } | |
25889d3c | 131 | #endif |
789295bf VZ |
132 | } |
133 | } | |
134 | ||
135 | // --------------------------------------------------------------------------- | |
136 | // showing/hiding the caret | |
137 | // --------------------------------------------------------------------------- | |
138 | ||
139 | void wxCaret::DoShow() | |
140 | { | |
141 | wxASSERT_MSG( GetWindow(), "caret without window cannot be shown" ); | |
142 | wxASSERT_MSG( IsOk(), "caret of zero size cannot be shown" ); | |
143 | ||
144 | if ( !m_hasCaret ) | |
145 | { | |
146 | (void)MSWCreateCaret(); | |
147 | } | |
148 | ||
25889d3c JS |
149 | #ifdef __WIN16__ |
150 | ::ShowCaret(GetWinHwnd(GetWindow())) ; | |
151 | #else | |
789295bf VZ |
152 | if ( !::ShowCaret(GetWinHwnd(GetWindow())) ) |
153 | { | |
154 | wxLogLastError("ShowCaret"); | |
155 | } | |
25889d3c | 156 | #endif |
789295bf VZ |
157 | } |
158 | ||
159 | void wxCaret::DoHide() | |
160 | { | |
c6eba8f8 | 161 | if ( m_hasCaret ) |
789295bf | 162 | { |
25889d3c JS |
163 | #ifdef __WIN16__ |
164 | ::HideCaret(GetWinHwnd(GetWindow())) ; | |
165 | #else | |
c6eba8f8 VZ |
166 | if ( !::HideCaret(GetWinHwnd(GetWindow())) ) |
167 | { | |
168 | wxLogLastError("HideCaret"); | |
169 | } | |
25889d3c | 170 | #endif |
789295bf VZ |
171 | } |
172 | } | |
173 | ||
174 | // --------------------------------------------------------------------------- | |
175 | // moving the caret | |
176 | // --------------------------------------------------------------------------- | |
177 | ||
178 | void wxCaret::DoMove() | |
179 | { | |
a8f25787 | 180 | if ( m_hasCaret ) |
789295bf | 181 | { |
25889d3c JS |
182 | #ifdef __WIN16__ |
183 | ::SetCaretPos(m_x, m_y) ; | |
184 | #else | |
a8f25787 VZ |
185 | if ( !::SetCaretPos(m_x, m_y) ) |
186 | { | |
187 | wxLogLastError("SetCaretPos"); | |
188 | } | |
25889d3c | 189 | #endif |
789295bf | 190 | } |
a8f25787 | 191 | //else: we don't have caret right now, nothing to do (this does happen) |
789295bf | 192 | } |