]> git.saurik.com Git - wxWidgets.git/blob - src/generic/caret.cpp
Corrected SetItemState() in listctrl
[wxWidgets.git] / src / generic / caret.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: generic/caret.h
3 // Purpose: generic wxCaret class
4 // Author: Vadim Zeitlin (original code by Robert Roebling)
5 // Modified by:
6 // Created: 25.05.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if 0 //def __GNUG__
21 #pragma implementation "caret.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/wx.h"
33 #endif //WX_PRECOMP
34
35 #include "wx/caret.h"
36
37 // ----------------------------------------------------------------------------
38 // global variables for this module
39 // ----------------------------------------------------------------------------
40
41 // the blink time (common to all carets for MSW compatibility)
42 static int gs_blinkTime = 500; // in milliseconds
43
44 // ============================================================================
45 // implementation
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // wxCaret static functions and data
50 // ----------------------------------------------------------------------------
51
52
53 int wxCaretBase::GetBlinkTime()
54 {
55 return gs_blinkTime;
56 }
57
58 void wxCaretBase::SetBlinkTime(int milliseconds)
59 {
60 gs_blinkTime = milliseconds;
61 }
62
63 // ----------------------------------------------------------------------------
64 // initialization and destruction
65 // ----------------------------------------------------------------------------
66
67 void wxCaret::InitGeneric()
68 {
69 }
70
71 wxCaret::~wxCaret()
72 {
73 if ( IsVisible() )
74 {
75 // stop blinking
76 m_timer.Stop();
77 }
78 }
79
80 // ----------------------------------------------------------------------------
81 // showing/hiding/moving the caret (base class interface)
82 // ----------------------------------------------------------------------------
83
84 void wxCaret::DoShow()
85 {
86 m_timer.Start(GetBlinkTime());
87
88 m_blinkedOut = TRUE;
89 Blink();
90 }
91
92 void wxCaret::DoHide()
93 {
94 m_timer.Stop();
95
96 if ( !m_blinkedOut )
97 {
98 Blink();
99 }
100 }
101
102 void wxCaret::DoMove()
103 {
104 if ( IsVisible() && !m_blinkedOut )
105 {
106 Blink();
107 }
108 //else: will be shown at the correct location next time it blinks
109 }
110
111 // ----------------------------------------------------------------------------
112 // drawing the caret
113 // ----------------------------------------------------------------------------
114
115 void wxCaret::Blink()
116 {
117 m_blinkedOut = !m_blinkedOut;
118
119 wxClientDC dc(GetWindow());
120 if ( !m_blinkedOut )
121 {
122 DoDraw(&dc);
123 }
124 else
125 {
126 // FIXME can't be less efficient than this... (+1 needed!)
127 wxRect rect(m_x, m_y, m_width + 1, m_height + 1);
128 GetWindow()->Refresh(FALSE, &rect);
129 }
130 }
131
132 void wxCaret::DoDraw(wxDC *dc)
133 {
134 dc->SetPen( *wxBLACK_PEN );
135 dc->DrawLine( m_x, m_y, m_x+m_width, m_y );
136 dc->DrawLine( m_x, m_y+m_height, m_x+m_width, m_y+m_height );
137 dc->DrawLine( m_x+(m_width/2), m_y, m_x+(m_width/2), m_y+m_height );
138 // dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height );
139 }