]> git.saurik.com Git - wxWidgets.git/blob - src/generic/caret.cpp
Added GSocket/wxSocket alias to socket.h to prevent us from using GSocket
[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 #ifdef __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 wxCaretTimer::wxCaretTimer(wxCaret *caret)
50 {
51 m_caret = caret;
52 }
53
54 void wxCaretTimer::Notify()
55 {
56 m_caret->Blink();
57 }
58
59 // ----------------------------------------------------------------------------
60 // wxCaret static functions and data
61 // ----------------------------------------------------------------------------
62
63
64 int wxCaretBase::GetBlinkTime()
65 {
66 return gs_blinkTime;
67 }
68
69 void wxCaretBase::SetBlinkTime(int milliseconds)
70 {
71 gs_blinkTime = milliseconds;
72 }
73
74 // ----------------------------------------------------------------------------
75 // initialization and destruction
76 // ----------------------------------------------------------------------------
77
78 void wxCaret::InitGeneric()
79 {
80 }
81
82 wxCaret::~wxCaret()
83 {
84 if ( IsVisible() )
85 {
86 // stop blinking
87 m_timer.Stop();
88 }
89 }
90
91 // ----------------------------------------------------------------------------
92 // showing/hiding/moving the caret (base class interface)
93 // ----------------------------------------------------------------------------
94
95 void wxCaret::DoShow()
96 {
97 m_timer.Start(GetBlinkTime());
98
99 m_blinkedOut = TRUE;
100 Blink();
101 }
102
103 void wxCaret::DoHide()
104 {
105 m_timer.Stop();
106
107 if ( !m_blinkedOut )
108 {
109 Blink();
110 }
111 }
112
113 void wxCaret::DoMove()
114 {
115 if ( IsVisible() && !m_blinkedOut )
116 {
117 Blink();
118 }
119 //else: will be shown at the correct location next time it blinks
120 }
121
122 // ----------------------------------------------------------------------------
123 // drawing the caret
124 // ----------------------------------------------------------------------------
125
126 void wxCaret::Blink()
127 {
128 m_blinkedOut = !m_blinkedOut;
129
130 wxClientDC dc(GetWindow());
131 if ( !m_blinkedOut )
132 {
133 DoDraw(&dc);
134 }
135 else
136 {
137 // FIXME can't be less efficient than this... (+1 needed!)
138 wxRect rect(m_x, m_y, m_width + 1, m_height + 1);
139 GetWindow()->Refresh(FALSE, &rect);
140 }
141 }
142
143 void wxCaret::DoDraw(wxDC *dc)
144 {
145 dc->SetPen( *wxBLACK_PEN );
146 dc->DrawLine( m_x, m_y, m_x+m_width, m_y );
147 dc->DrawLine( m_x, m_y+m_height, m_x+m_width, m_y+m_height );
148 dc->DrawLine( m_x+(m_width/2), m_y, m_x+(m_width/2), m_y+m_height );
149 // dc->DrawLine( m_x+(m_width/2)+1, m_y, m_x+(m_width/2)+1, m_y+m_height );
150 }