]>
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 // ----------------------------------------------------------------------------
21 #pragma implementation "caret.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/window.h"
33 #include "wx/dcclient.h"
38 // ----------------------------------------------------------------------------
39 // global variables for this module
40 // ----------------------------------------------------------------------------
42 // the blink time (common to all carets for MSW compatibility)
43 static int gs_blinkTime
= 500; // in milliseconds
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 wxCaretTimer::wxCaretTimer(wxCaret
*caret
)
58 void wxCaretTimer::Notify()
63 void wxCaret::OnTimer()
65 // don't blink the caret when we don't have the focus
70 // ----------------------------------------------------------------------------
71 // wxCaret static functions and data
72 // ----------------------------------------------------------------------------
74 int wxCaretBase::GetBlinkTime()
79 void wxCaretBase::SetBlinkTime(int milliseconds
)
81 gs_blinkTime
= milliseconds
;
84 // ----------------------------------------------------------------------------
85 // initialization and destruction
86 // ----------------------------------------------------------------------------
88 void wxCaret::InitGeneric()
103 // ----------------------------------------------------------------------------
104 // showing/hiding/moving the caret (base class interface)
105 // ----------------------------------------------------------------------------
107 void wxCaret::DoShow()
109 m_timer
.Start(GetBlinkTime());
115 void wxCaret::DoHide()
125 void wxCaret::DoMove()
127 if ( IsVisible() && !m_blinkedOut
)
131 //else: will be shown at the correct location next time it blinks
134 // ----------------------------------------------------------------------------
135 // handling the focus
136 // ----------------------------------------------------------------------------
138 void wxCaret::OnSetFocus()
145 void wxCaret::OnKillFocus()
151 // the caret must be shown - otherwise, if it is hidden now, it will
152 // stay so until the focus doesn't return because it won't blink any
154 m_blinkedOut
= FALSE
;
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 void wxCaret::Blink()
166 m_blinkedOut
= !m_blinkedOut
;
171 void wxCaret::Refresh()
175 wxClientDC
dc(GetWindow());
180 // FIXME can't be less efficient than this... we probably should use
181 // backing store for the caret instead of leaving all the burden
182 // of correct refresh logic handling to the user code
185 wxRect
rect(m_x
, m_y
, m_width
+ 1, m_height
+ 1);
186 GetWindow()->Refresh(FALSE
, &rect
);
190 void wxCaret::DoDraw(wxDC
*dc
)
192 dc
->SetPen( *wxBLACK_PEN
);
194 // VZ: Robert's code for I-shaped caret - this is nice but doesn't look
195 // at all the same as the MSW version and I don't know how to indicate
196 // that the window has focus or not with such caret
198 dc
->DrawLine( m_x
, m_y
, m_x
+m_width
, m_y
);
199 dc
->DrawLine( m_x
, m_y
+m_height
, m_x
+m_width
, m_y
+m_height
);
200 dc
->DrawLine( m_x
+(m_width
/2), m_y
, m_x
+(m_width
/2), m_y
+m_height
);
201 // dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height );
204 dc
->SetBrush( *wxBLACK_BRUSH
);
205 dc
->DrawRectangle( m_x
, m_y
, m_width
, m_height
);