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