]> git.saurik.com Git - wxWidgets.git/blame - src/msw/caret.cpp
OS/2 updates for statusbar processing
[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
e8225073 135 if ( m_hasCaret )
789295bf 136 {
e8225073 137 CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow())));
789295bf 138 }
e8225073 139 //else: will be shown when we get the focus
789295bf
VZ
140}
141
142void wxCaret::DoHide()
143{
c6eba8f8 144 if ( m_hasCaret )
789295bf 145 {
e8225073 146 CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
789295bf
VZ
147 }
148}
149
150// ---------------------------------------------------------------------------
151// moving the caret
152// ---------------------------------------------------------------------------
153
154void wxCaret::DoMove()
155{
a8f25787 156 if ( m_hasCaret )
789295bf 157 {
a17e237f
VZ
158 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
159 wxT("how did we lose focus?") );
e8225073
VZ
160
161 CALL_CARET_API(SetCaretPos, (m_x, m_y));
789295bf 162 }
a8f25787 163 //else: we don't have caret right now, nothing to do (this does happen)
789295bf 164}
cfb76a19
RD
165
166
167// ---------------------------------------------------------------------------
168// resizing the caret
169// ---------------------------------------------------------------------------
170
171void wxCaret::DoSize()
172{
173 if ( m_hasCaret )
174 {
175 m_hasCaret = FALSE;
176 CALL_CARET_API(DestroyCaret, ());
177 MSWCreateCaret();
178 DoMove();
179 }
180}