]>
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) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
37 // ----------------------------------------------------------------------------
38 // global variables for this module
39 // ----------------------------------------------------------------------------
41 // the blink time (common to all carets for MSW compatibility)
42 static int gs_blinkTime
= 500; // in milliseconds
44 // ============================================================================
46 // ============================================================================
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxCaretTimer::wxCaretTimer(wxCaret
*caret
)
57 void wxCaretTimer::Notify()
62 void wxCaret::OnTimer()
64 // don't blink the caret when we don't have the focus
69 // ----------------------------------------------------------------------------
70 // wxCaret static functions and data
71 // ----------------------------------------------------------------------------
73 int wxCaretBase::GetBlinkTime()
78 void wxCaretBase::SetBlinkTime(int milliseconds
)
80 gs_blinkTime
= milliseconds
;
83 // ----------------------------------------------------------------------------
84 // initialization and destruction
85 // ----------------------------------------------------------------------------
87 void wxCaret::InitGeneric()
91 #if wxUSE_OVERLAY == 0
94 m_bmpUnderCaret
.Create(m_width
, m_height
);
103 if ( m_timer
.IsRunning() )
108 // ----------------------------------------------------------------------------
109 // showing/hiding/moving the caret (base class interface)
110 // ----------------------------------------------------------------------------
112 void wxCaret::DoShow()
114 int blinkTime
= GetBlinkTime();
116 m_timer
.Start(blinkTime
);
122 void wxCaret::DoHide()
132 void wxCaret::DoMove()
138 // hide it right now and it will be shown the next time it blinks
141 // but if the caret is not blinking, we should blink it back into
142 // visibility manually
143 if ( !m_timer
.IsRunning() )
147 //else: will be shown at the correct location when it is shown
150 void wxCaret::DoSize()
152 int countVisible
= m_countVisible
;
153 if (countVisible
> 0)
158 #if wxUSE_OVERLAY == 0
159 // Change bitmap size
160 m_bmpUnderCaret
= wxBitmap(m_width
, m_height
);
162 if (countVisible
> 0)
164 m_countVisible
= countVisible
;
169 // ----------------------------------------------------------------------------
170 // handling the focus
171 // ----------------------------------------------------------------------------
173 void wxCaret::OnSetFocus()
181 void wxCaret::OnKillFocus()
187 // the caret must be shown - otherwise, if it is hidden now, it will
188 // stay so until the focus doesn't return because it won't blink any
191 // hide it first if it isn't hidden ...
195 // .. and show it in the new style
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void wxCaret::Blink()
206 m_blinkedOut
= !m_blinkedOut
;
211 void wxCaret::Refresh()
213 wxClientDC
dcWin(GetWindow());
214 // this is the new code, switch to 0 if this gives problems
216 wxDCOverlay
dcOverlay( m_overlay
, &dcWin
, m_x
, m_y
, m_width
, m_height
);
227 dcMem
.SelectObject(m_bmpUnderCaret
);
230 // restore the old image
231 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
238 if ( m_xOld
== -1 && m_yOld
== -1 )
240 // save the part we're going to overdraw
244 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
245 wxPoint pt
= dcWin
.GetDeviceOrigin();
248 #endif // broken wxGTK wxDC::Blit
249 dcMem
.Blit(0, 0, m_width
, m_height
,
255 //else: we already saved the image below the caret, don't do it any
258 // and draw the caret there
264 void wxCaret::DoDraw(wxDC
*dc
)
266 dc
->SetPen( *wxBLACK_PEN
);
268 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
269 dc
->SetPen(*wxBLACK_PEN
);
271 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
272 // done under wxGTK - no idea why
273 //dc->SetLogicalFunction(wxINVERT);
275 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
278 #endif // wxUSE_CARET