X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0290598f588681eb631c0a952a26c7637b8482d0..2063a4a0cab1161dbda7c1dc52f6996436765ce4:/samples/caret/caret.cpp diff --git a/samples/caret/caret.cpp b/samples/caret/caret.cpp index 00df1d0b0d..5e41c55f79 100644 --- a/samples/caret/caret.cpp +++ b/samples/caret/caret.cpp @@ -9,18 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "caret.cpp" - #pragma interface "caret.cpp" -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include @@ -87,7 +75,7 @@ public: MyCanvas( wxWindow *parent ); ~MyCanvas(); - char& CharAt(int x, int y) { return *(m_text + x + m_xChars * y); } + wxChar& CharAt(int x, int y) { return *(m_text + x + m_xChars * y); } // caret movement void Home() { m_xCaret = 0; } @@ -105,7 +93,6 @@ public: void OnChar( wxKeyEvent &event ); private: - wxCaret m_caret; wxFont m_font; // the margin around the text (looks nicer) @@ -121,7 +108,7 @@ private: int m_xChars, m_yChars; // the text - char *m_text; + wxChar *m_text; DECLARE_DYNAMIC_CLASS(MyCanvas) DECLARE_EVENT_TABLE() @@ -265,6 +252,8 @@ MyCanvas::MyCanvas( wxWindow *parent ) wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER ) { + m_text = (wxChar *)NULL; + SetBackgroundColour(* wxWHITE); m_font = *wxNORMAL_FONT; @@ -274,16 +263,15 @@ MyCanvas::MyCanvas( wxWindow *parent ) m_heightChar = dc.GetCharHeight(); m_widthChar = dc.GetCharWidth(); - m_caret.Create( this, m_widthChar, m_heightChar ); + wxCaret *caret = new wxCaret(this, m_widthChar, m_heightChar); + SetCaret(caret); m_xCaret = m_yCaret = m_xChars = m_yChars = 0; m_xMargin = m_yMargin = 5; - m_caret.Move(m_xMargin, m_yMargin); - m_caret.Show(); - - m_text = (char *)NULL; + caret->Move(m_xMargin, m_yMargin); + caret->Show(); } MyCanvas::~MyCanvas() @@ -301,12 +289,17 @@ void MyCanvas::OnSize( wxSizeEvent &event ) m_yChars = 1; free(m_text); - m_text = (char *)calloc(m_xChars * m_yChars, sizeof(char)); + m_text = (wxChar *)calloc(m_xChars * m_yChars, sizeof(wxChar)); - wxString msg; - msg.Printf("Panel size is (%d, %d)", m_xChars, m_yChars); + wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - ((wxFrame *)GetParent())->SetStatusText(msg, 1); + if ( frame && frame->GetStatusBar() ) + { + wxString msg; + msg.Printf(_T("Panel size is (%d, %d)"), m_xChars, m_yChars); + + frame->SetStatusText(msg, 1); + } event.Skip(); } @@ -324,9 +317,9 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) for ( int x = 0; x < m_xChars; x++ ) { - char ch = CharAt(x, y); + wxChar ch = CharAt(x, y); if ( !ch ) - ch = ' '; + ch = _T(' '); line += ch; } @@ -368,9 +361,9 @@ void MyCanvas::OnChar( wxKeyEvent &event ) break; default: - if ( isprint(event.KeyCode()) ) + if ( wxIsprint(event.KeyCode()) ) { - CharAt(m_xCaret, m_yCaret) = (char)event.KeyCode(); + CharAt(m_xCaret, m_yCaret) = (wxChar)event.KeyCode(); NextChar(); } else @@ -380,10 +373,10 @@ void MyCanvas::OnChar( wxKeyEvent &event ) } } - wxLogStatus("Caret is at (%d, %d)", m_xCaret, m_yCaret); + wxLogStatus(_T("Caret is at (%d, %d)"), m_xCaret, m_yCaret); - m_caret.Move(m_xMargin + m_xCaret * m_widthChar, - m_yMargin + m_yCaret * m_heightChar); + GetCaret()->Move(m_xMargin + m_xCaret * m_widthChar, + m_yMargin + m_yCaret * m_heightChar); Refresh(); }