]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/caret.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/caret.cpp
3 // Purpose: generic wxCaret class implementation
4 // Author: Vadim Zeitlin (original code by Robert Roebling)
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
37 // ----------------------------------------------------------------------------
38 // global variables for this module
39 // ----------------------------------------------------------------------------
41 // the blink time (common to all carets for MSW compatibility)
42 static int gs_blinkTime
= 500; // in milliseconds
44 // ============================================================================
46 // ============================================================================
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxCaretTimer::wxCaretTimer(wxCaret
*caret
)
57 void wxCaretTimer::Notify()
62 void wxCaret::OnTimer()
64 // don't blink the caret when we don't have the focus
69 // ----------------------------------------------------------------------------
70 // wxCaret static functions and data
71 // ----------------------------------------------------------------------------
73 int wxCaretBase::GetBlinkTime()
78 void wxCaretBase::SetBlinkTime(int milliseconds
)
80 gs_blinkTime
= milliseconds
;
83 GtkSettings
*settings
= gtk_settings_get_default();
86 gtk_settings_set_long_property(settings
, "gtk-cursor-blink", gtk_false
, NULL
);
90 gtk_settings_set_long_property(settings
, "gtk-cursor-blink", gtk_true
, NULL
);
91 gtk_settings_set_long_property(settings
, "gtk-cursor-time", milliseconds
, NULL
);
96 // ----------------------------------------------------------------------------
97 // initialization and destruction
98 // ----------------------------------------------------------------------------
100 void wxCaret::InitGeneric()
104 #ifndef wxHAS_CARET_USING_OVERLAYS
107 m_bmpUnderCaret
.Create(m_width
, m_height
);
116 if ( m_timer
.IsRunning() )
121 // ----------------------------------------------------------------------------
122 // showing/hiding/moving the caret (base class interface)
123 // ----------------------------------------------------------------------------
125 void wxCaret::DoShow()
127 int blinkTime
= GetBlinkTime();
129 m_timer
.Start(blinkTime
);
135 void wxCaret::DoHide()
145 void wxCaret::DoMove()
147 #ifdef wxHAS_CARET_USING_OVERLAYS
154 // hide it right now and it will be shown the next time it blinks
157 // but if the caret is not blinking, we should blink it back into
158 // visibility manually
159 if ( !m_timer
.IsRunning() )
163 //else: will be shown at the correct location when it is shown
166 void wxCaret::DoSize()
168 int countVisible
= m_countVisible
;
169 if (countVisible
> 0)
174 #ifdef wxHAS_CARET_USING_OVERLAYS
177 // Change bitmap size
178 m_bmpUnderCaret
= wxBitmap(m_width
, m_height
);
180 if (countVisible
> 0)
182 m_countVisible
= countVisible
;
187 // ----------------------------------------------------------------------------
188 // handling the focus
189 // ----------------------------------------------------------------------------
191 void wxCaret::OnSetFocus()
199 void wxCaret::OnKillFocus()
205 // the caret must be shown - otherwise, if it is hidden now, it will
206 // stay so until the focus doesn't return because it won't blink any
209 // hide it first if it isn't hidden ...
213 // .. and show it in the new style
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 void wxCaret::Blink()
224 m_blinkedOut
= !m_blinkedOut
;
229 void wxCaret::Refresh()
231 wxClientDC
dcWin(GetWindow());
232 // this is the new code, switch to 0 if this gives problems
233 #ifdef wxHAS_CARET_USING_OVERLAYS
234 wxDCOverlay
dcOverlay( m_overlay
, &dcWin
, m_x
, m_y
, m_width
, m_height
);
241 DoDraw( &dcWin
, GetWindow() );
245 dcMem
.SelectObject(m_bmpUnderCaret
);
248 // restore the old image
249 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
256 if ( m_xOld
== -1 && m_yOld
== -1 )
258 // save the part we're going to overdraw
259 dcMem
.Blit(0, 0, m_width
, m_height
,
265 //else: we already saved the image below the caret, don't do it any
268 // and draw the caret there
269 DoDraw(&dcWin
, GetWindow());
274 void wxCaret::DoDraw(wxDC
*dc
, wxWindow
* win
)
276 wxPen
pen(*wxBLACK_PEN
);
277 wxBrush
brush(*wxBLACK_BRUSH
);
280 wxColour
backgroundColour(win
->GetBackgroundColour());
281 if (backgroundColour
.Red() < 100 &&
282 backgroundColour
.Green() < 100 &&
283 backgroundColour
.Blue() < 100)
286 brush
= *wxWHITE_BRUSH
;
290 dc
->SetBrush(m_hasFocus
? brush
: *wxTRANSPARENT_BRUSH
);
292 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
293 // done under wxGTK - no idea why
294 //dc->SetLogicalFunction(wxINVERT);
296 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
299 #endif // wxUSE_CARET