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