]>
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 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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()
165 void wxCaret::OnKillFocus()
171 // the caret must be shown - otherwise, if it is hidden now, it will
172 // stay so until the focus doesn't return because it won't blink any
175 // hide it first if it isn't hidden ...
179 // .. and show it in the new style
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 void wxCaret::Blink()
190 m_blinkedOut
= !m_blinkedOut
;
195 void wxCaret::Refresh()
197 wxClientDC
dcWin(GetWindow());
199 dcMem
.SelectObject(m_bmpUnderCaret
);
202 // restore the old image
203 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
210 if ( m_xOld
== -1 && m_yOld
== -1 )
212 // save the part we're going to overdraw
216 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
217 wxPoint pt
= dcWin
.GetDeviceOrigin();
220 #endif // broken wxGTK wxDC::Blit
221 dcMem
.Blit(0, 0, m_width
, m_height
,
227 //else: we already saved the image below the caret, don't do it any
230 // and draw the caret there
235 void wxCaret::DoDraw(wxDC
*dc
)
237 dc
->SetPen( *wxBLACK_PEN
);
239 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
240 dc
->SetPen(*wxBLACK_PEN
);
242 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
243 // done under wxGTK - no idea why
244 //dc->SetLogicalFunction(wxINVERT);
246 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
249 #endif // wxUSE_CARET