]> git.saurik.com Git - wxWidgets.git/blame - src/msw/caret.cpp
Quiet cooperation between MSW and wxGL.
[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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
789295bf
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
789295bf
VZ
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
adf9e099
VZ
38#if wxUSE_CARET
39
789295bf
VZ
40#include "wx/msw/private.h"
41
e8225073
VZ
42// ---------------------------------------------------------------------------
43// macros
44// ---------------------------------------------------------------------------
45
3a5bcc4d 46#define CALL_CARET_API(api, args) \
f6bcfd97
BP
47 if ( !api args ) \
48 wxLogLastError(_T(#api))
e8225073 49
789295bf
VZ
50// ===========================================================================
51// implementation
52// ===========================================================================
53
54// ---------------------------------------------------------------------------
55// blink time
56// ---------------------------------------------------------------------------
57
58//static
59int wxCaretBase::GetBlinkTime()
60{
61 int blinkTime = ::GetCaretBlinkTime();
62 if ( !blinkTime )
63 {
f6bcfd97 64 wxLogLastError(wxT("GetCaretBlinkTime"));
789295bf
VZ
65 }
66
67 return blinkTime;
68}
69
70//static
71void wxCaretBase::SetBlinkTime(int milliseconds)
72{
e8225073 73 CALL_CARET_API(SetCaretBlinkTime, (milliseconds));
789295bf
VZ
74}
75
76// ---------------------------------------------------------------------------
77// creating/destroying the caret
78// ---------------------------------------------------------------------------
79
80bool wxCaret::MSWCreateCaret()
81{
223d09f6
KB
82 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
83 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
789295bf
VZ
84
85 if ( !m_hasCaret )
86 {
e8225073
VZ
87 CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0,
88 m_width, m_height));
89
02b7b6b0 90 m_hasCaret = true;
789295bf
VZ
91 }
92
93 return m_hasCaret;
94}
95
96void 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
112void wxCaret::OnKillFocus()
113{
114 if ( m_hasCaret )
115 {
02b7b6b0 116 m_hasCaret = false;
789295bf 117
e8225073 118 CALL_CARET_API(DestroyCaret, ());
789295bf
VZ
119 }
120}
121
122// ---------------------------------------------------------------------------
123// showing/hiding the caret
124// ---------------------------------------------------------------------------
125
126void wxCaret::DoShow()
127{
223d09f6
KB
128 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
129 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
789295bf 130
1e6feb95
VZ
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
e8225073 142 if ( m_hasCaret )
789295bf 143 {
e8225073 144 CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow())));
789295bf 145 }
e8225073 146 //else: will be shown when we get the focus
789295bf
VZ
147}
148
149void wxCaret::DoHide()
150{
c6eba8f8 151 if ( m_hasCaret )
789295bf 152 {
e8225073 153 CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
789295bf
VZ
154 }
155}
156
157// ---------------------------------------------------------------------------
158// moving the caret
159// ---------------------------------------------------------------------------
160
161void wxCaret::DoMove()
162{
a8f25787 163 if ( m_hasCaret )
789295bf 164 {
a17e237f
VZ
165 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
166 wxT("how did we lose focus?") );
e8225073 167
1e6feb95
VZ
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));
789295bf 172 }
a8f25787 173 //else: we don't have caret right now, nothing to do (this does happen)
789295bf 174}
cfb76a19
RD
175
176
177// ---------------------------------------------------------------------------
178// resizing the caret
179// ---------------------------------------------------------------------------
180
181void wxCaret::DoSize()
182{
183 if ( m_hasCaret )
184 {
02b7b6b0 185 m_hasCaret = false;
cfb76a19
RD
186 CALL_CARET_API(DestroyCaret, ());
187 MSWCreateCaret();
fa06b433 188 OnSetFocus();
cfb76a19
RD
189 }
190}
adf9e099
VZ
191
192#endif