]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/caret.cpp
98966be56a2f406e3796b6ef891acb6f86aee7e7
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"
34 #include "wx/window.h"
35 #include "wx/dcclient.h"
40 // ----------------------------------------------------------------------------
41 // global variables for this module
42 // ----------------------------------------------------------------------------
44 // the blink time (common to all carets for MSW compatibility)
45 static int gs_blinkTime
= 500; // in milliseconds
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 wxCaretTimer::wxCaretTimer(wxCaret
*caret
)
60 void wxCaretTimer::Notify()
65 void wxCaret::OnTimer()
67 // don't blink the caret when we don't have the focus
72 // ----------------------------------------------------------------------------
73 // wxCaret static functions and data
74 // ----------------------------------------------------------------------------
76 int wxCaretBase::GetBlinkTime()
81 void wxCaretBase::SetBlinkTime(int milliseconds
)
83 gs_blinkTime
= milliseconds
;
86 // ----------------------------------------------------------------------------
87 // initialization and destruction
88 // ----------------------------------------------------------------------------
90 void wxCaret::InitGeneric()
101 if ( m_timer
.IsRunning() )
106 // ----------------------------------------------------------------------------
107 // showing/hiding/moving the caret (base class interface)
108 // ----------------------------------------------------------------------------
110 void wxCaret::DoShow()
112 int blinkTime
= GetBlinkTime();
114 m_timer
.Start(blinkTime
);
120 void wxCaret::DoHide()
130 void wxCaret::DoMove()
136 // hide it right now and it will be shown the next time it blinks
137 // unless it should be shown all the time in which case just show
138 // it at the new position
139 if ( m_timer
.IsRunning() )
145 //else: will be shown at the correct location when it is shown
148 // ----------------------------------------------------------------------------
149 // handling the focus
150 // ----------------------------------------------------------------------------
152 void wxCaret::OnSetFocus()
159 void wxCaret::OnKillFocus()
165 // the caret must be shown - otherwise, if it is hidden now, it will
166 // stay so until the focus doesn't return because it won't blink any
168 m_blinkedOut
= FALSE
;
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 void wxCaret::Blink()
180 m_blinkedOut
= !m_blinkedOut
;
185 void wxCaret::Refresh()
189 wxClientDC
dc(GetWindow());
194 // FIXME can't be less efficient than this... we probably should use
195 // backing store for the caret instead of leaving all the burden
196 // of correct refresh logic handling to the user code
199 wxRect
rect(m_x
, m_y
, m_width
+ 1, m_height
+ 1);
200 GetWindow()->Refresh(FALSE
, &rect
);
204 void wxCaret::DoDraw(wxDC
*dc
)
206 dc
->SetPen( *wxBLACK_PEN
);
208 // VZ: Robert's code for I-shaped caret - this is nice but doesn't look
209 // at all the same as the MSW version and I don't know how to indicate
210 // that the window has focus or not with such caret
212 dc
->DrawLine( m_x
, m_y
, m_x
+m_width
, m_y
);
213 dc
->DrawLine( m_x
, m_y
+m_height
, m_x
+m_width
, m_y
+m_height
);
214 dc
->DrawLine( m_x
+(m_width
/2), m_y
, m_x
+(m_width
/2), m_y
+m_height
);
215 // dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height );
218 dc
->SetBrush( *wxBLACK_BRUSH
);
219 dc
->DrawRectangle( m_x
, m_y
, m_width
, m_height
);
223 #endif // wxUSE_CARET