X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6ab069f2b68cd266b31122d6a73a0878fd4760fe..437950ced1672617329ba103d1c322f5d19c0383:/samples/text/text.cpp diff --git a/samples/text/text.cpp b/samples/text/text.cpp index ce77e8de8c..0e4629e22a 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -45,6 +45,10 @@ #include "wx/numdlg.h" #include "wx/tokenzr.h" +#ifndef __WXMSW__ + #include "../sample.xpm" +#endif + //---------------------------------------------------------------------- // class definitions //---------------------------------------------------------------------- @@ -194,6 +198,12 @@ public: } #endif // wxUSE_CLIPBOARD + void OnAddTextLine(wxCommandEvent& WXUNUSED(event)) + { + static int s_n = 0; + m_panel->m_textrich->AppendText(wxString::Format("Line %d\n", ++s_n)); + } + void OnAddTextFreeze( wxCommandEvent& WXUNUSED(event) ) { DoAddText(true); } void OnAddText( wxCommandEvent& WXUNUSED(event) ) @@ -311,20 +321,21 @@ private: void DoAddText(bool freeze) { wxTextCtrl * const text = m_panel->m_textrich; - text->Clear(); if ( freeze ) text->Freeze(); + text->Clear(); + for ( int i = 0; i < 100; i++ ) { text->AppendText(wxString::Format(wxT("Line %i\n"), i)); } + text->SetInsertionPoint(0); + if ( freeze ) text->Thaw(); - - text->SetInsertionPoint(0); } MyPanel *m_panel; @@ -394,6 +405,7 @@ enum // text menu TEXT_ADD_SOME = 400, TEXT_ADD_FREEZE, + TEXT_ADD_LINE, TEXT_MOVE_ENDTEXT, TEXT_MOVE_ENDENTRY, TEXT_SET_EDITABLE, @@ -475,6 +487,7 @@ bool MyApp::OnInit() wxMenu *menuText = new wxMenu; menuText->Append(TEXT_ADD_SOME, _T("&Append some text\tCtrl-A")); menuText->Append(TEXT_ADD_FREEZE, _T("&Append text with freeze/thaw\tShift-Ctrl-A")); + menuText->Append(TEXT_ADD_LINE, _T("Append a new &line\tAlt-Shift-A")); menuText->Append(TEXT_REMOVE, _T("&Remove first 10 characters\tCtrl-Y")); menuText->Append(TEXT_REPLACE, _T("&Replace characters 4 to 8 with ABC\tCtrl-R")); menuText->Append(TEXT_SELECT, _T("&Select characters 4 to 8\tCtrl-I")); @@ -921,6 +934,10 @@ void MyTextCtrl::OnKeyDown(wxKeyEvent& event) wxLogMessage(_T("Selection = '%s' (len = %u)"), sel.c_str(), (unsigned int) sel.length()); + + const wxString text = GetLineText(line); + wxLogMessage(_T("Current line: \"%s\"; length = %lu"), + text.c_str(), text.length()); } break; @@ -1036,7 +1053,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) // a little hack to use the command line argument for encoding testing if ( wxTheApp->argc == 2 ) { - switch ( wxTheApp->argv[1][0] ) + switch ( (wxChar)wxTheApp->argv[1][0] ) { case '2': m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL, @@ -1140,7 +1157,6 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) topSizer->Add( m_log, 1, wxALL | wxEXPAND, 10 ); #endif - SetAutoLayout( true ); SetSizer(topSizer); } @@ -1333,6 +1349,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEXT_SELECT, MyFrame::OnSelectText) EVT_MENU(TEXT_ADD_SOME, MyFrame::OnAddText) EVT_MENU(TEXT_ADD_FREEZE, MyFrame::OnAddTextFreeze) + EVT_MENU(TEXT_ADD_LINE, MyFrame::OnAddTextLine) EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText) EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry) @@ -1356,6 +1373,8 @@ END_EVENT_TABLE() MyFrame::MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h) : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h) ) { + SetIcon(wxICON(sample)); + #if wxUSE_STATUSBAR CreateStatusBar(2); #endif // wxUSE_STATUSBAR @@ -1495,13 +1514,13 @@ void MyFrame::OnIdle( wxIdleEvent& event ) wxString msg; msg.Printf( #ifdef __WXMSW__ - _T("Focus: wxWindow = %p, HWND = %08x"), + _T("Focus: wxWindow = %p, HWND = %p"), #else _T("Focus: wxWindow = %p"), #endif s_windowFocus #ifdef __WXMSW__ - , (unsigned int) s_windowFocus->GetHWND() + , s_windowFocus->GetHWND() #endif ); @@ -1828,10 +1847,9 @@ void RichTextFrame::OnIdle(wxIdleEvent& WXUNUSED(event)) alignment = wxT("left-aligned"); else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED) alignment = wxT("justified"); - msg.Printf(wxT("Facename: %s, wxColour(%d, %d, %d), %s"), - (const wxChar*) facename, + msg.Printf( "Facename: %s, wxColour(%d, %d, %d), %s", facename, attr.GetTextColour().Red(), attr.GetTextColour().Green(), attr.GetTextColour().Blue(), - (const wxChar*) alignment); + alignment ); if (attr.HasFont()) {