]> git.saurik.com Git - wxWidgets.git/blame - src/generic/caret.cpp
Did the unmap/map trick for wxFrame::IsIconized().
[wxWidgets.git] / src / generic / caret.cpp
CommitLineData
0290598f 1///////////////////////////////////////////////////////////////////////////////
f6bcfd97
BP
2// Name: generic/caret.cpp
3// Purpose: generic wxCaret class implementation
0290598f
VZ
4// Author: Vadim Zeitlin (original code by Robert Roebling)
5// Modified by:
6// Created: 25.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
e4628635 20#ifdef __GNUG__
f6bcfd97 21 #pragma implementation "caret.h"
0290598f
VZ
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
e179bd65
RR
32 #include "wx/window.h"
33 #include "wx/dcclient.h"
0290598f
VZ
34#endif //WX_PRECOMP
35
36#include "wx/caret.h"
37
38// ----------------------------------------------------------------------------
39// global variables for this module
40// ----------------------------------------------------------------------------
41
42// the blink time (common to all carets for MSW compatibility)
43static int gs_blinkTime = 500; // in milliseconds
44
45// ============================================================================
46// implementation
47// ============================================================================
48
f6bcfd97
BP
49// ----------------------------------------------------------------------------
50// timer stuff
51// ----------------------------------------------------------------------------
52
e4628635
RR
53wxCaretTimer::wxCaretTimer(wxCaret *caret)
54{
55 m_caret = caret;
56}
57
58void wxCaretTimer::Notify()
59{
f6bcfd97
BP
60 m_caret->OnTimer();
61}
62
63void wxCaret::OnTimer()
64{
65 // don't blink the caret when we don't have the focus
66 if ( m_hasFocus )
67 Blink();
e4628635
RR
68}
69
0290598f
VZ
70// ----------------------------------------------------------------------------
71// wxCaret static functions and data
72// ----------------------------------------------------------------------------
73
0290598f
VZ
74int wxCaretBase::GetBlinkTime()
75{
76 return gs_blinkTime;
77}
78
79void wxCaretBase::SetBlinkTime(int milliseconds)
80{
81 gs_blinkTime = milliseconds;
82}
83
84// ----------------------------------------------------------------------------
85// initialization and destruction
86// ----------------------------------------------------------------------------
87
88void wxCaret::InitGeneric()
89{
f6bcfd97
BP
90 m_hasFocus = TRUE;
91 m_blinkedOut = FALSE;
0290598f
VZ
92}
93
94wxCaret::~wxCaret()
95{
96 if ( IsVisible() )
97 {
98 // stop blinking
99 m_timer.Stop();
100 }
101}
102
103// ----------------------------------------------------------------------------
104// showing/hiding/moving the caret (base class interface)
105// ----------------------------------------------------------------------------
106
107void wxCaret::DoShow()
108{
109 m_timer.Start(GetBlinkTime());
110
111 m_blinkedOut = TRUE;
112 Blink();
113}
114
115void wxCaret::DoHide()
116{
117 m_timer.Stop();
118
119 if ( !m_blinkedOut )
120 {
121 Blink();
122 }
123}
124
125void wxCaret::DoMove()
126{
127 if ( IsVisible() && !m_blinkedOut )
128 {
129 Blink();
130 }
131 //else: will be shown at the correct location next time it blinks
132}
133
f6bcfd97
BP
134// ----------------------------------------------------------------------------
135// handling the focus
136// ----------------------------------------------------------------------------
137
138void wxCaret::OnSetFocus()
139{
140 m_hasFocus = TRUE;
141
142 Refresh();
143}
144
145void wxCaret::OnKillFocus()
146{
147 m_hasFocus = FALSE;
148
149 if ( IsVisible() )
150 {
151 // the caret must be shown - otherwise, if it is hidden now, it will
152 // stay so until the focus doesn't return because it won't blink any
153 // more
154 m_blinkedOut = FALSE;
155 }
156
157 Refresh();
158}
159
0290598f
VZ
160// ----------------------------------------------------------------------------
161// drawing the caret
162// ----------------------------------------------------------------------------
163
164void wxCaret::Blink()
165{
166 m_blinkedOut = !m_blinkedOut;
167
f6bcfd97
BP
168 Refresh();
169}
170
171void wxCaret::Refresh()
172{
0290598f
VZ
173 if ( !m_blinkedOut )
174 {
f6bcfd97 175 wxClientDC dc(GetWindow());
0290598f
VZ
176 DoDraw(&dc);
177 }
178 else
179 {
f6bcfd97
BP
180 // FIXME can't be less efficient than this... we probably should use
181 // backing store for the caret instead of leaving all the burden
182 // of correct refresh logic handling to the user code
183
184 // NB: +1 is needed!
0290598f
VZ
185 wxRect rect(m_x, m_y, m_width + 1, m_height + 1);
186 GetWindow()->Refresh(FALSE, &rect);
187 }
188}
189
190void wxCaret::DoDraw(wxDC *dc)
191{
192 dc->SetPen( *wxBLACK_PEN );
f6bcfd97
BP
193
194 // VZ: Robert's code for I-shaped caret - this is nice but doesn't look
195 // at all the same as the MSW version and I don't know how to indicate
196 // that the window has focus or not with such caret
197#if 0
0290598f
VZ
198 dc->DrawLine( m_x, m_y, m_x+m_width, m_y );
199 dc->DrawLine( m_x, m_y+m_height, m_x+m_width, m_y+m_height );
200 dc->DrawLine( m_x+(m_width/2), m_y, m_x+(m_width/2), m_y+m_height );
201// dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height );
f6bcfd97
BP
202#else // 1
203 if ( m_hasFocus )
204 dc->SetBrush( *wxBLACK_BRUSH );
205 dc->DrawRectangle( m_x, m_y, m_width, m_height );
206#endif // 0/1
0290598f 207}