]>
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 #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 void wxCaret::DoSize()
155 int countVisible
= m_countVisible
;
156 if (countVisible
> 0)
161 // Change bitmap size
162 m_bmpUnderCaret
= wxBitmap(m_width
, m_height
);
163 if (countVisible
> 0)
165 m_countVisible
= countVisible
;
170 // ----------------------------------------------------------------------------
171 // handling the focus
172 // ----------------------------------------------------------------------------
174 void wxCaret::OnSetFocus()
182 void wxCaret::OnKillFocus()
188 // the caret must be shown - otherwise, if it is hidden now, it will
189 // stay so until the focus doesn't return because it won't blink any
192 // hide it first if it isn't hidden ...
196 // .. and show it in the new style
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void wxCaret::Blink()
207 m_blinkedOut
= !m_blinkedOut
;
212 void wxCaret::Refresh()
214 wxClientDC
dcWin(GetWindow());
216 dcMem
.SelectObject(m_bmpUnderCaret
);
219 // restore the old image
220 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
227 if ( m_xOld
== -1 && m_yOld
== -1 )
229 // save the part we're going to overdraw
233 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
234 wxPoint pt
= dcWin
.GetDeviceOrigin();
237 #endif // broken wxGTK wxDC::Blit
238 dcMem
.Blit(0, 0, m_width
, m_height
,
244 //else: we already saved the image below the caret, don't do it any
247 // and draw the caret there
252 void wxCaret::DoDraw(wxDC
*dc
)
254 dc
->SetPen( *wxBLACK_PEN
);
256 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
257 dc
->SetPen(*wxBLACK_PEN
);
259 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
260 // done under wxGTK - no idea why
261 //dc->SetLogicalFunction(wxINVERT);
263 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
266 #endif // wxUSE_CARET