]> git.saurik.com Git - wxWidgets.git/blame - src/msw/caret.cpp
<br><br><br> is now handled correctly, e.g. empty lines are inserted (unlike <p>...
[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
49 #define CALL_CARET_API(api, args) if ( !api args ) wxLogLastError(#api)
50#endif // Win16/32
51
789295bf
VZ
52// ===========================================================================
53// implementation
54// ===========================================================================
55
56// ---------------------------------------------------------------------------
57// blink time
58// ---------------------------------------------------------------------------
59
60//static
61int wxCaretBase::GetBlinkTime()
62{
63 int blinkTime = ::GetCaretBlinkTime();
64 if ( !blinkTime )
65 {
66 wxLogLastError("GetCaretBlinkTime");
67 }
68
69 return blinkTime;
70}
71
72//static
73void wxCaretBase::SetBlinkTime(int milliseconds)
74{
e8225073 75 CALL_CARET_API(SetCaretBlinkTime, (milliseconds));
789295bf
VZ
76}
77
78// ---------------------------------------------------------------------------
79// creating/destroying the caret
80// ---------------------------------------------------------------------------
81
82bool wxCaret::MSWCreateCaret()
83{
223d09f6
KB
84 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
85 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
789295bf
VZ
86
87 if ( !m_hasCaret )
88 {
e8225073
VZ
89 CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0,
90 m_width, m_height));
91
25889d3c 92 m_hasCaret = TRUE;
789295bf
VZ
93 }
94
95 return m_hasCaret;
96}
97
98void wxCaret::OnSetFocus()
99{
100 if ( m_countVisible > 0 )
101 {
102 if ( MSWCreateCaret() )
103 {
104 // the caret was recreated but it doesn't remember its position and
105 // it's not shown
106
107 DoMove();
108 DoShow();
109 }
110 }
111 //else: caret is invisible, don't waste time creating it
112}
113
114void wxCaret::OnKillFocus()
115{
116 if ( m_hasCaret )
117 {
118 m_hasCaret = FALSE;
119
e8225073 120 CALL_CARET_API(DestroyCaret, ());
789295bf
VZ
121 }
122}
123
124// ---------------------------------------------------------------------------
125// showing/hiding the caret
126// ---------------------------------------------------------------------------
127
128void wxCaret::DoShow()
129{
223d09f6
KB
130 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
131 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
789295bf 132
e8225073 133 if ( m_hasCaret )
789295bf 134 {
e8225073 135 CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow())));
789295bf 136 }
e8225073 137 //else: will be shown when we get the focus
789295bf
VZ
138}
139
140void wxCaret::DoHide()
141{
c6eba8f8 142 if ( m_hasCaret )
789295bf 143 {
e8225073 144 CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
789295bf
VZ
145 }
146}
147
148// ---------------------------------------------------------------------------
149// moving the caret
150// ---------------------------------------------------------------------------
151
152void wxCaret::DoMove()
153{
a8f25787 154 if ( m_hasCaret )
789295bf 155 {
a17e237f
VZ
156 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
157 wxT("how did we lose focus?") );
e8225073
VZ
158
159 CALL_CARET_API(SetCaretPos, (m_x, m_y));
789295bf 160 }
a8f25787 161 //else: we don't have caret right now, nothing to do (this does happen)
789295bf 162}