]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/caret.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/caret.cpp
3 // Purpose: generic wxCaret class implementation
4 // Author: Vadim Zeitlin (original code by Robert Roebling)
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "caret.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/window.h"
35 #include "wx/dcclient.h"
36 #include "wx/dcmemory.h"
41 // ----------------------------------------------------------------------------
42 // global variables for this module
43 // ----------------------------------------------------------------------------
45 // the blink time (common to all carets for MSW compatibility)
46 static int gs_blinkTime
= 500; // in milliseconds
48 // ============================================================================
50 // ============================================================================
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 wxCaretTimer::wxCaretTimer(wxCaret
*caret
)
61 void wxCaretTimer::Notify()
66 void wxCaret::OnTimer()
68 // don't blink the caret when we don't have the focus
73 // ----------------------------------------------------------------------------
74 // wxCaret static functions and data
75 // ----------------------------------------------------------------------------
77 int wxCaretBase::GetBlinkTime()
82 void wxCaretBase::SetBlinkTime(int milliseconds
)
84 gs_blinkTime
= milliseconds
;
87 // ----------------------------------------------------------------------------
88 // initialization and destruction
89 // ----------------------------------------------------------------------------
91 void wxCaret::InitGeneric()
98 m_bmpUnderCaret
.Create(m_width
, m_height
);
106 if ( m_timer
.IsRunning() )
111 // ----------------------------------------------------------------------------
112 // showing/hiding/moving the caret (base class interface)
113 // ----------------------------------------------------------------------------
115 void wxCaret::DoShow()
117 int blinkTime
= GetBlinkTime();
119 m_timer
.Start(blinkTime
);
125 void wxCaret::DoHide()
135 void wxCaret::DoMove()
141 // hide it right now and it will be shown the next time it blinks
144 // but if the caret is not blinking, we should blink it back into
145 // visibility manually
146 if ( !m_timer
.IsRunning() )
150 //else: will be shown at the correct location when it is shown
153 // ----------------------------------------------------------------------------
154 // handling the focus
155 // ----------------------------------------------------------------------------
157 void wxCaret::OnSetFocus()
164 void wxCaret::OnKillFocus()
170 // the caret must be shown - otherwise, if it is hidden now, it will
171 // stay so until the focus doesn't return because it won't blink any
174 // hide it first if it isn't hidden ...
178 // .. and show it in the new style
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 void wxCaret::Blink()
189 m_blinkedOut
= !m_blinkedOut
;
194 void wxCaret::Refresh()
196 wxClientDC
dcWin(GetWindow());
198 dcMem
.SelectObject(m_bmpUnderCaret
);
201 // restore the old image
202 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
209 if ( m_xOld
== -1 && m_yOld
== -1 )
211 // save the part we're going to overdraw
212 dcMem
.Blit(0, 0, m_width
, m_height
,
217 //else: we already saved the image below the caret, don't do it any
220 // and draw the caret there
225 void wxCaret::DoDraw(wxDC
*dc
)
227 dc
->SetPen( *wxBLACK_PEN
);
229 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
230 dc
->SetPen(*wxBLACK_PEN
);
232 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
233 // done under wxGTK - no idea why
234 //dc->SetLogicalFunction(wxINVERT);
236 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
239 #endif // wxUSE_CARET