]> git.saurik.com Git - wxWidgets.git/blob - src/generic/caret.cpp
1. wxChoice and wxComboBox support client data under MSW
[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/window.h"
33 #include "wx/dcclient.h"
34 #endif //WX_PRECOMP
35
36 #include "wx/caret.h"
37
38 // ----------------------------------------------------------------------------
39 // global variables for this module
40 // ----------------------------------------------------------------------------
41
42 // the blink time (common to all carets for MSW compatibility)
43 static int gs_blinkTime = 500; // in milliseconds
44
45 // ============================================================================
46 // implementation
47 // ============================================================================
48
49 // ----------------------------------------------------------------------------
50 // wxCaret static functions and data
51 // ----------------------------------------------------------------------------
52
53
54 int wxCaretBase::GetBlinkTime()
55 {
56 return gs_blinkTime;
57 }
58
59 void wxCaretBase::SetBlinkTime(int milliseconds)
60 {
61 gs_blinkTime = milliseconds;
62 }
63
64 // ----------------------------------------------------------------------------
65 // initialization and destruction
66 // ----------------------------------------------------------------------------
67
68 void wxCaret::InitGeneric()
69 {
70 }
71
72 wxCaret::~wxCaret()
73 {
74 if ( IsVisible() )
75 {
76 // stop blinking
77 m_timer.Stop();
78 }
79 }
80
81 // ----------------------------------------------------------------------------
82 // showing/hiding/moving the caret (base class interface)
83 // ----------------------------------------------------------------------------
84
85 void wxCaret::DoShow()
86 {
87 m_timer.Start(GetBlinkTime());
88
89 m_blinkedOut = TRUE;
90 Blink();
91 }
92
93 void wxCaret::DoHide()
94 {
95 m_timer.Stop();
96
97 if ( !m_blinkedOut )
98 {
99 Blink();
100 }
101 }
102
103 void wxCaret::DoMove()
104 {
105 if ( IsVisible() && !m_blinkedOut )
106 {
107 Blink();
108 }
109 //else: will be shown at the correct location next time it blinks
110 }
111
112 // ----------------------------------------------------------------------------
113 // drawing the caret
114 // ----------------------------------------------------------------------------
115
116 void wxCaret::Blink()
117 {
118 m_blinkedOut = !m_blinkedOut;
119
120 wxClientDC dc(GetWindow());
121 if ( !m_blinkedOut )
122 {
123 DoDraw(&dc);
124 }
125 else
126 {
127 // FIXME can't be less efficient than this... (+1 needed!)
128 wxRect rect(m_x, m_y, m_width + 1, m_height + 1);
129 GetWindow()->Refresh(FALSE, &rect);
130 }
131 }
132
133 void wxCaret::DoDraw(wxDC *dc)
134 {
135 dc->SetPen( *wxBLACK_PEN );
136 dc->DrawLine( m_x, m_y, m_x+m_width, m_y );
137 dc->DrawLine( m_x, m_y+m_height, m_x+m_width, m_y+m_height );
138 dc->DrawLine( m_x+(m_width/2), m_y, m_x+(m_width/2), m_y+m_height );
139 // dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height );
140 }