]> git.saurik.com Git - wxWidgets.git/blame - src/msw/caret.cpp
better <HR> tag handling in wxHTML
[wxWidgets.git] / src / msw / caret.cpp
CommitLineData
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
e8225073
VZ
40// ---------------------------------------------------------------------------
41// macros
42// ---------------------------------------------------------------------------
43
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
46#ifdef __WIN16__
47 #define CALL_CARET_API(api, args) api args
48#else // Win32
f6bcfd97
BP
49 #define CALL_CARET_API(api, args) \
50 if ( !api args ) \
51 wxLogLastError(_T(#api))
e8225073
VZ
52#endif // Win16/32
53
789295bf
VZ
54// ===========================================================================
55// implementation
56// ===========================================================================
57
58// ---------------------------------------------------------------------------
59// blink time
60// ---------------------------------------------------------------------------
61
62//static
63int wxCaretBase::GetBlinkTime()
64{
65 int blinkTime = ::GetCaretBlinkTime();
66 if ( !blinkTime )
67 {
f6bcfd97 68 wxLogLastError(wxT("GetCaretBlinkTime"));
789295bf
VZ
69 }
70
71 return blinkTime;
72}
73
74//static
75void wxCaretBase::SetBlinkTime(int milliseconds)
76{
e8225073 77 CALL_CARET_API(SetCaretBlinkTime, (milliseconds));
789295bf
VZ
78}
79
80// ---------------------------------------------------------------------------
81// creating/destroying the caret
82// ---------------------------------------------------------------------------
83
84bool wxCaret::MSWCreateCaret()
85{
223d09f6
KB
86 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
87 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
789295bf
VZ
88
89 if ( !m_hasCaret )
90 {
e8225073
VZ
91 CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0,
92 m_width, m_height));
93
25889d3c 94 m_hasCaret = TRUE;
789295bf
VZ
95 }
96
97 return m_hasCaret;
98}
99
100void wxCaret::OnSetFocus()
101{
102 if ( m_countVisible > 0 )
103 {
104 if ( MSWCreateCaret() )
105 {
106 // the caret was recreated but it doesn't remember its position and
107 // it's not shown
108
109 DoMove();
110 DoShow();
111 }
112 }
113 //else: caret is invisible, don't waste time creating it
114}
115
116void wxCaret::OnKillFocus()
117{
118 if ( m_hasCaret )
119 {
120 m_hasCaret = FALSE;
121
e8225073 122 CALL_CARET_API(DestroyCaret, ());
789295bf
VZ
123 }
124}
125
126// ---------------------------------------------------------------------------
127// showing/hiding the caret
128// ---------------------------------------------------------------------------
129
130void wxCaret::DoShow()
131{
223d09f6
KB
132 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
133 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
789295bf 134
1e6feb95
VZ
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
137 // not the caret
138 if ( !m_hasCaret && (wxWindow::FindFocus() == GetWindow()) )
139 {
140 if ( MSWCreateCaret() )
141 {
142 DoMove();
143 }
144 }
145
e8225073 146 if ( m_hasCaret )
789295bf 147 {
e8225073 148 CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow())));
789295bf 149 }
e8225073 150 //else: will be shown when we get the focus
789295bf
VZ
151}
152
153void wxCaret::DoHide()
154{
c6eba8f8 155 if ( m_hasCaret )
789295bf 156 {
e8225073 157 CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
789295bf
VZ
158 }
159}
160
161// ---------------------------------------------------------------------------
162// moving the caret
163// ---------------------------------------------------------------------------
164
165void wxCaret::DoMove()
166{
a8f25787 167 if ( m_hasCaret )
789295bf 168 {
a17e237f
VZ
169 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
170 wxT("how did we lose focus?") );
e8225073 171
1e6feb95
VZ
172 // for compatibility with the generic version, the coordinates are
173 // client ones
174 wxPoint pt = GetWindow()->GetClientAreaOrigin();
175 CALL_CARET_API(SetCaretPos, (m_x + pt.x, m_y + pt.y));
789295bf 176 }
a8f25787 177 //else: we don't have caret right now, nothing to do (this does happen)
789295bf 178}
cfb76a19
RD
179
180
181// ---------------------------------------------------------------------------
182// resizing the caret
183// ---------------------------------------------------------------------------
184
185void wxCaret::DoSize()
186{
187 if ( m_hasCaret )
188 {
189 m_hasCaret = FALSE;
190 CALL_CARET_API(DestroyCaret, ());
191 MSWCreateCaret();
192 DoMove();
193 }
194}