]>
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 #ifndef wxHAS_CARET_USING_OVERLAYS
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()
134 #ifdef wxHAS_CARET_USING_OVERLAYS
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 #ifdef wxHAS_CARET_USING_OVERLAYS
164 // Change bitmap size
165 m_bmpUnderCaret
= wxBitmap(m_width
, m_height
);
167 if (countVisible
> 0)
169 m_countVisible
= countVisible
;
174 // ----------------------------------------------------------------------------
175 // handling the focus
176 // ----------------------------------------------------------------------------
178 void wxCaret::OnSetFocus()
186 void wxCaret::OnKillFocus()
192 // the caret must be shown - otherwise, if it is hidden now, it will
193 // stay so until the focus doesn't return because it won't blink any
196 // hide it first if it isn't hidden ...
200 // .. and show it in the new style
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 void wxCaret::Blink()
211 m_blinkedOut
= !m_blinkedOut
;
216 void wxCaret::Refresh()
218 wxClientDC
dcWin(GetWindow());
219 // this is the new code, switch to 0 if this gives problems
220 #ifdef wxHAS_CARET_USING_OVERLAYS
221 wxDCOverlay
dcOverlay( m_overlay
, &dcWin
, m_x
, m_y
, m_width
, m_height
);
228 DoDraw( &dcWin
, GetWindow() );
232 dcMem
.SelectObject(m_bmpUnderCaret
);
235 // restore the old image
236 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
243 if ( m_xOld
== -1 && m_yOld
== -1 )
245 // save the part we're going to overdraw
246 dcMem
.Blit(0, 0, m_width
, m_height
,
252 //else: we already saved the image below the caret, don't do it any
255 // and draw the caret there
256 DoDraw(&dcWin
, GetWindow());
261 void wxCaret::DoDraw(wxDC
*dc
, wxWindow
* win
)
263 wxPen
pen(*wxBLACK_PEN
);
264 wxBrush
brush(*wxBLACK_BRUSH
);
267 wxColour
backgroundColour(win
->GetBackgroundColour());
268 if (backgroundColour
.Red() < 100 &&
269 backgroundColour
.Green() < 100 &&
270 backgroundColour
.Blue() < 100)
273 brush
= *wxWHITE_BRUSH
;
277 dc
->SetBrush(m_hasFocus
? brush
: *wxTRANSPARENT_BRUSH
);
279 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
280 // done under wxGTK - no idea why
281 //dc->SetLogicalFunction(wxINVERT);
283 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
286 #endif // wxUSE_CARET