]> git.saurik.com Git - wxWidgets.git/blob - src/msw/caret.cpp
applied patch 403988 (fixing MDI window menu)
[wxWidgets.git] / src / msw / caret.cpp
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 // 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) \
50 if ( !api args ) \
51 wxLogLastError(_T(#api))
52 #endif // Win16/32
53
54 // ===========================================================================
55 // implementation
56 // ===========================================================================
57
58 // ---------------------------------------------------------------------------
59 // blink time
60 // ---------------------------------------------------------------------------
61
62 //static
63 int wxCaretBase::GetBlinkTime()
64 {
65 int blinkTime = ::GetCaretBlinkTime();
66 if ( !blinkTime )
67 {
68 wxLogLastError(wxT("GetCaretBlinkTime"));
69 }
70
71 return blinkTime;
72 }
73
74 //static
75 void wxCaretBase::SetBlinkTime(int milliseconds)
76 {
77 CALL_CARET_API(SetCaretBlinkTime, (milliseconds));
78 }
79
80 // ---------------------------------------------------------------------------
81 // creating/destroying the caret
82 // ---------------------------------------------------------------------------
83
84 bool wxCaret::MSWCreateCaret()
85 {
86 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be created") );
87 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be created") );
88
89 if ( !m_hasCaret )
90 {
91 CALL_CARET_API(CreateCaret, (GetWinHwnd(GetWindow()), 0,
92 m_width, m_height));
93
94 m_hasCaret = TRUE;
95 }
96
97 return m_hasCaret;
98 }
99
100 void 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
116 void wxCaret::OnKillFocus()
117 {
118 if ( m_hasCaret )
119 {
120 m_hasCaret = FALSE;
121
122 CALL_CARET_API(DestroyCaret, ());
123 }
124 }
125
126 // ---------------------------------------------------------------------------
127 // showing/hiding the caret
128 // ---------------------------------------------------------------------------
129
130 void wxCaret::DoShow()
131 {
132 wxASSERT_MSG( GetWindow(), wxT("caret without window cannot be shown") );
133 wxASSERT_MSG( IsOk(), wxT("caret of zero size cannot be shown") );
134
135 if ( m_hasCaret )
136 {
137 CALL_CARET_API(ShowCaret, (GetWinHwnd(GetWindow())));
138 }
139 //else: will be shown when we get the focus
140 }
141
142 void wxCaret::DoHide()
143 {
144 if ( m_hasCaret )
145 {
146 CALL_CARET_API(HideCaret, (GetWinHwnd(GetWindow())));
147 }
148 }
149
150 // ---------------------------------------------------------------------------
151 // moving the caret
152 // ---------------------------------------------------------------------------
153
154 void wxCaret::DoMove()
155 {
156 if ( m_hasCaret )
157 {
158 wxASSERT_MSG( wxWindow::FindFocus() == GetWindow(),
159 wxT("how did we lose focus?") );
160
161 CALL_CARET_API(SetCaretPos, (m_x, m_y));
162 }
163 //else: we don't have caret right now, nothing to do (this does happen)
164 }
165
166
167 // ---------------------------------------------------------------------------
168 // resizing the caret
169 // ---------------------------------------------------------------------------
170
171 void wxCaret::DoSize()
172 {
173 if ( m_hasCaret )
174 {
175 m_hasCaret = FALSE;
176 CALL_CARET_API(DestroyCaret, ());
177 MSWCreateCaret();
178 DoMove();
179 }
180 }