X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/697e0cdd12c2723397deafab25055b39cc75b77f..d15040492413b54a530b5a291b26750f3d265d23:/samples/caret/caret.cpp diff --git a/samples/caret/caret.cpp b/samples/caret/caret.cpp index d62a84c1c9..f023d9e6f8 100644 --- a/samples/caret/caret.cpp +++ b/samples/caret/caret.cpp @@ -10,7 +10,7 @@ ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". -#include +#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -19,9 +19,9 @@ // for all others, include the necessary headers (this file is usually all you // need because it includes almost all + #include "wx/wx.h" - #include + #include "wx/log.h" #endif #include "wx/caret.h" @@ -30,7 +30,7 @@ // ressources // ---------------------------------------------------------------------------- // the application icon -#if defined(__WXGTK__) || defined(__WXMOTIF__) +#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) #include "mondrian.xpm" #endif @@ -358,6 +358,7 @@ void MyCanvas::OnSize( wxSizeEvent &event ) // would use GetUpdateRegion() and iterate over rectangles it contains void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) { + wxCaretSuspend cs(this); wxPaintDC dc( this ); PrepareDC( dc ); dc.Clear(); @@ -382,8 +383,6 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) void MyCanvas::OnChar( wxKeyEvent &event ) { - bool refresh = FALSE; - switch ( event.KeyCode() ) { case WXK_LEFT: @@ -418,10 +417,17 @@ void MyCanvas::OnChar( wxKeyEvent &event ) default: if ( !event.AltDown() && wxIsprint(event.KeyCode()) ) { - CharAt(m_xCaret, m_yCaret) = (wxChar)event.KeyCode(); - NextChar(); + wxChar ch = (wxChar)event.KeyCode(); + CharAt(m_xCaret, m_yCaret) = ch; + + wxCaretSuspend cs(this); + wxClientDC dc(this); + dc.SetFont(m_font); + dc.SetBackgroundMode(wxSOLID); // overwrite old value + dc.DrawText(ch, m_xMargin + m_xCaret * m_widthChar, + m_yMargin + m_yCaret * m_heightChar ); - refresh = TRUE; + NextChar(); } else { @@ -430,8 +436,5 @@ void MyCanvas::OnChar( wxKeyEvent &event ) } DoMoveCaret(); - - if ( refresh ) - Refresh(); }