]>
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)
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/window.h"
30 #include "wx/dcclient.h"
31 #include "wx/dcmemory.h"
36 // ----------------------------------------------------------------------------
37 // global variables for this module
38 // ----------------------------------------------------------------------------
40 // the blink time (common to all carets for MSW compatibility)
41 static int gs_blinkTime
= 500; // in milliseconds
43 // ============================================================================
45 // ============================================================================
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 wxCaretTimer::wxCaretTimer(wxCaret
*caret
)
56 void wxCaretTimer::Notify()
61 void wxCaret::OnTimer()
63 // don't blink the caret when we don't have the focus
68 // ----------------------------------------------------------------------------
69 // wxCaret static functions and data
70 // ----------------------------------------------------------------------------
72 int wxCaretBase::GetBlinkTime()
77 void wxCaretBase::SetBlinkTime(int milliseconds
)
79 gs_blinkTime
= milliseconds
;
82 GtkSettings
*settings
= gtk_settings_get_default();
85 gtk_settings_set_long_property(settings
, "gtk-cursor-blink", gtk_false
, NULL
);
89 gtk_settings_set_long_property(settings
, "gtk-cursor-blink", gtk_true
, NULL
);
90 gtk_settings_set_long_property(settings
, "gtk-cursor-time", milliseconds
, NULL
);
95 // ----------------------------------------------------------------------------
96 // initialization and destruction
97 // ----------------------------------------------------------------------------
99 void wxCaret::InitGeneric()
103 #ifndef wxHAS_CARET_USING_OVERLAYS
106 m_bmpUnderCaret
.Create(m_width
, m_height
);
115 if ( m_timer
.IsRunning() )
120 // ----------------------------------------------------------------------------
121 // showing/hiding/moving the caret (base class interface)
122 // ----------------------------------------------------------------------------
124 void wxCaret::DoShow()
126 int blinkTime
= GetBlinkTime();
128 m_timer
.Start(blinkTime
);
134 void wxCaret::DoHide()
144 void wxCaret::DoMove()
146 #ifdef wxHAS_CARET_USING_OVERLAYS
153 // hide it right now and it will be shown the next time it blinks
156 // but if the caret is not blinking, we should blink it back into
157 // visibility manually
158 if ( !m_timer
.IsRunning() )
162 //else: will be shown at the correct location when it is shown
165 void wxCaret::DoSize()
167 int countVisible
= m_countVisible
;
168 if (countVisible
> 0)
173 #ifdef wxHAS_CARET_USING_OVERLAYS
176 // Change bitmap size
177 m_bmpUnderCaret
= wxBitmap(m_width
, m_height
);
179 if (countVisible
> 0)
181 m_countVisible
= countVisible
;
186 // ----------------------------------------------------------------------------
187 // handling the focus
188 // ----------------------------------------------------------------------------
190 void wxCaret::OnSetFocus()
198 void wxCaret::OnKillFocus()
204 // the caret must be shown - otherwise, if it is hidden now, it will
205 // stay so until the focus doesn't return because it won't blink any
208 // hide it first if it isn't hidden ...
212 // .. and show it in the new style
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 void wxCaret::Blink()
223 m_blinkedOut
= !m_blinkedOut
;
228 void wxCaret::Refresh()
230 wxClientDC
dcWin(GetWindow());
231 // this is the new code, switch to 0 if this gives problems
232 #ifdef wxHAS_CARET_USING_OVERLAYS
233 wxDCOverlay
dcOverlay( m_overlay
, &dcWin
, m_x
, m_y
, m_width
, m_height
);
240 DoDraw( &dcWin
, GetWindow() );
244 dcMem
.SelectObject(m_bmpUnderCaret
);
247 // restore the old image
248 dcWin
.Blit(m_xOld
, m_yOld
, m_width
, m_height
,
255 if ( m_xOld
== -1 && m_yOld
== -1 )
257 // save the part we're going to overdraw
258 dcMem
.Blit(0, 0, m_width
, m_height
,
264 //else: we already saved the image below the caret, don't do it any
267 // and draw the caret there
268 DoDraw(&dcWin
, GetWindow());
273 void wxCaret::DoDraw(wxDC
*dc
, wxWindow
* win
)
275 wxPen
pen(*wxBLACK_PEN
);
276 wxBrush
brush(*wxBLACK_BRUSH
);
279 wxColour
backgroundColour(win
->GetBackgroundColour());
280 if (backgroundColour
.Red() < 100 &&
281 backgroundColour
.Green() < 100 &&
282 backgroundColour
.Blue() < 100)
285 brush
= *wxWHITE_BRUSH
;
289 dc
->SetBrush(m_hasFocus
? brush
: *wxTRANSPARENT_BRUSH
);
291 // VZ: unfortunately, the rectangle comes out a pixel smaller when this is
292 // done under wxGTK - no idea why
293 //dc->SetLogicalFunction(wxINVERT);
295 dc
->DrawRectangle(m_x
, m_y
, m_width
, m_height
);
298 #endif // wxUSE_CARET