]>
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()
94 m_bmpUnderCaret
.Create(m_width
, m_height
);
102 if ( m_timer
.IsRunning() )
107 // ----------------------------------------------------------------------------
108 // showing/hiding/moving the caret (base class interface)
109 // ----------------------------------------------------------------------------
111 void wxCaret::DoShow()
113 int blinkTime
= GetBlinkTime();
115 m_timer
.Start(blinkTime
);
121 void wxCaret::DoHide()
131 void wxCaret::DoMove()
137 // hide it right now and it will be shown the next time it blinks
140 // but if the caret is not blinking, we should blink it back into
141 // visibility manually
142 if ( !m_timer
.IsRunning() )
146 //else: will be shown at the correct location when it is shown
149 void wxCaret::DoSize()
151 int countVisible
= m_countVisible
;
152 if (countVisible
> 0)
157 // Change bitmap size
158 m_bmpUnderCaret
= wxBitmap(m_width
, m_height
);
159 if (countVisible
> 0)
161 m_countVisible
= countVisible
;
166 // ----------------------------------------------------------------------------
167 // handling the focus
168 // ----------------------------------------------------------------------------
170 void wxCaret::OnSetFocus()
178 void wxCaret::OnKillFocus()
184 // the caret must be shown - otherwise, if it is hidden now, it will
185 // stay so until the focus doesn't return because it won't blink any
188 // hide it first if it isn't hidden ...
192 // .. and show it in the new style
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void wxCaret::Blink()
203 m_blinkedOut
= !m_blinkedOut
;
208 void wxCaret::Refresh()
210 wxClientDC
dcWin(GetWindow());
212 dcMem
.SelectObject(m_bmpUnderCaret
);
215 // restore the old image
216 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
223 if ( m_xOld
== -1 && m_yOld
== -1 )
225 // save the part we're going to overdraw
229 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
230 wxPoint pt
= dcWin
.GetDeviceOrigin();
233 #endif // broken wxGTK wxDC::Blit
234 dcMem
.Blit(0, 0, m_width
, m_height
,
240 //else: we already saved the image below the caret, don't do it any
243 // and draw the caret there
248 void wxCaret::DoDraw(wxDC
*dc
)
250 dc
->SetPen( *wxBLACK_PEN
);
252 dc
->SetBrush(*(m_hasFocus
? wxBLACK_BRUSH
: wxTRANSPARENT_BRUSH
));
253 dc
->SetPen(*wxBLACK_PEN
);
255 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
256 // done under wxGTK - no idea why
257 //dc->SetLogicalFunction(wxINVERT);
259 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
262 #endif // wxUSE_CARET