]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/caret.cpp
Unicode fix, it seems
[wxWidgets.git] / src / msw / caret.cpp
... / ...
CommitLineData
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"
33 #include "wx/log.h"
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
49int wxCaretBase::GetBlinkTime()
50{
51 int blinkTime = ::GetCaretBlinkTime();
52 if ( !blinkTime )
53 {
54 wxLogLastError("GetCaretBlinkTime");
55 }
56
57 return blinkTime;
58}
59
60//static
61void wxCaretBase::SetBlinkTime(int milliseconds)
62{
63#ifdef __WIN16__
64 ::SetCaretBlinkTime(milliseconds) ;
65#else
66 if ( !::SetCaretBlinkTime(milliseconds) )
67 {
68 wxLogLastError("SetCaretBlinkTime");
69 }
70#endif
71}
72
73// ---------------------------------------------------------------------------
74// creating/destroying the caret
75// ---------------------------------------------------------------------------
76
77bool wxCaret::MSWCreateCaret()
78{
79 wxASSERT_MSG( GetWindow(), _T("caret without window cannot be created") );
80 wxASSERT_MSG( IsOk(), _T("caret of zero size cannot be created") );
81
82 if ( !m_hasCaret )
83 {
84#ifdef __WIN16__
85 ::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) ;
86 m_hasCaret = TRUE;
87#else
88 if ( !::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) )
89 {
90 wxLogLastError("CreateCaret");
91 }
92 else
93 {
94 m_hasCaret = TRUE;
95 }
96#endif
97 }
98
99 return m_hasCaret;
100}
101
102void 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
118void wxCaret::OnKillFocus()
119{
120 if ( m_hasCaret )
121 {
122 m_hasCaret = FALSE;
123
124#ifdef __WIN16__
125 ::DestroyCaret() ;
126#else
127 if ( !::DestroyCaret() )
128 {
129 wxLogLastError("DestroyCaret");
130 }
131#endif
132 }
133}
134
135// ---------------------------------------------------------------------------
136// showing/hiding the caret
137// ---------------------------------------------------------------------------
138
139void wxCaret::DoShow()
140{
141 wxASSERT_MSG( GetWindow(), _T("caret without window cannot be shown") );
142 wxASSERT_MSG( IsOk(), _T("caret of zero size cannot be shown") );
143
144 if ( !m_hasCaret )
145 {
146 (void)MSWCreateCaret();
147 }
148
149#ifdef __WIN16__
150 ::ShowCaret(GetWinHwnd(GetWindow())) ;
151#else
152 if ( !::ShowCaret(GetWinHwnd(GetWindow())) )
153 {
154 wxLogLastError("ShowCaret");
155 }
156#endif
157}
158
159void wxCaret::DoHide()
160{
161 if ( m_hasCaret )
162 {
163#ifdef __WIN16__
164 ::HideCaret(GetWinHwnd(GetWindow())) ;
165#else
166 if ( !::HideCaret(GetWinHwnd(GetWindow())) )
167 {
168 wxLogLastError("HideCaret");
169 }
170#endif
171 }
172}
173
174// ---------------------------------------------------------------------------
175// moving the caret
176// ---------------------------------------------------------------------------
177
178void wxCaret::DoMove()
179{
180 if ( m_hasCaret )
181 {
182#ifdef __WIN16__
183 ::SetCaretPos(m_x, m_y) ;
184#else
185 if ( !::SetCaretPos(m_x, m_y) )
186 {
187 wxLogLastError("SetCaretPos");
188 }
189#endif
190 }
191 //else: we don't have caret right now, nothing to do (this does happen)
192}