]> git.saurik.com Git - wxWidgets.git/blob - src/msw/caret.cpp
1. wxWindow::IsTopLevel() added and documented
[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 // implementation
42 // ===========================================================================
43
44 // ---------------------------------------------------------------------------
45 // blink time
46 // ---------------------------------------------------------------------------
47
48 //static
49 int wxCaretBase::GetBlinkTime()
50 {
51 int blinkTime = ::GetCaretBlinkTime();
52 if ( !blinkTime )
53 {
54 wxLogLastError("GetCaretBlinkTime");
55 }
56
57 return blinkTime;
58 }
59
60 //static
61 void wxCaretBase::SetBlinkTime(int milliseconds)
62 {
63 if ( !::SetCaretBlinkTime(milliseconds) )
64 {
65 wxLogLastError("SetCaretBlinkTime");
66 }
67 }
68
69 // ---------------------------------------------------------------------------
70 // creating/destroying the caret
71 // ---------------------------------------------------------------------------
72
73 bool wxCaret::MSWCreateCaret()
74 {
75 wxASSERT_MSG( GetWindow(), "caret without window cannot be created" );
76 wxASSERT_MSG( IsOk(), "caret of zero size cannot be created" );
77
78 if ( !m_hasCaret )
79 {
80 if ( !::CreateCaret(GetWinHwnd(GetWindow()), 0, m_width, m_height) )
81 {
82 wxLogLastError("CreateCaret");
83 }
84 else
85 {
86 m_hasCaret = TRUE;
87 }
88 }
89
90 return m_hasCaret;
91 }
92
93 void wxCaret::OnSetFocus()
94 {
95 if ( m_countVisible > 0 )
96 {
97 if ( MSWCreateCaret() )
98 {
99 // the caret was recreated but it doesn't remember its position and
100 // it's not shown
101
102 DoMove();
103 DoShow();
104 }
105 }
106 //else: caret is invisible, don't waste time creating it
107 }
108
109 void wxCaret::OnKillFocus()
110 {
111 if ( m_hasCaret )
112 {
113 m_hasCaret = FALSE;
114
115 if ( !::DestroyCaret() )
116 {
117 wxLogLastError("DestroyCaret");
118 }
119 }
120 }
121
122 // ---------------------------------------------------------------------------
123 // showing/hiding the caret
124 // ---------------------------------------------------------------------------
125
126 void wxCaret::DoShow()
127 {
128 wxASSERT_MSG( GetWindow(), "caret without window cannot be shown" );
129 wxASSERT_MSG( IsOk(), "caret of zero size cannot be shown" );
130
131 if ( !m_hasCaret )
132 {
133 (void)MSWCreateCaret();
134 }
135
136 if ( !::ShowCaret(GetWinHwnd(GetWindow())) )
137 {
138 wxLogLastError("ShowCaret");
139 }
140 }
141
142 void wxCaret::DoHide()
143 {
144 if ( m_hasCaret )
145 {
146 if ( !::HideCaret(GetWinHwnd(GetWindow())) )
147 {
148 wxLogLastError("HideCaret");
149 }
150 }
151 }
152
153 // ---------------------------------------------------------------------------
154 // moving the caret
155 // ---------------------------------------------------------------------------
156
157 void wxCaret::DoMove()
158 {
159 if ( m_hasCaret )
160 {
161 if ( !::SetCaretPos(m_x, m_y) )
162 {
163 wxLogLastError("SetCaretPos");
164 }
165 }
166 //else: we don't have caret right now, nothing to do (this does happen)
167 }