X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d7dcb9399059d0c9719e2bb96f503d3adafa6730..386c70583a2c03548aad922205906e58555a302d:/samples/text/text.cpp?ds=sidebyside diff --git a/samples/text/text.cpp b/samples/text/text.cpp index a0472525f5..dece7ff5a5 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -129,6 +129,11 @@ public: { m_panel->DoCopyToClipboard(); } #endif // wxUSE_CLIPBOARD + void OnAddTextFreeze( wxCommandEvent& event ) + { DoAddText(true); } + void OnAddText( wxCommandEvent& event ) + { DoAddText(false); } + void OnMoveToEndOfText( wxCommandEvent &event ) { m_panel->DoMoveToEndOfText(); } void OnMoveToEndOfEntry( wxCommandEvent &event ) @@ -144,6 +149,21 @@ public: void OnIdle( wxIdleEvent& event ); private: + void DoAddText(bool freeze) + { + wxTextCtrl *text = m_panel->m_textrich; + if ( freeze ) + text->Freeze(); + + for ( int i = 0; i < 100; i++ ) + text->AppendText(wxString::Format("Line %i\n", i)); + + text->SetInsertionPoint(0); + + if ( freeze ) + text->Thaw(); + } + MyPanel *m_panel; DECLARE_EVENT_TABLE() @@ -176,7 +196,9 @@ enum TEXT_TOOLTIPS_ENABLE, // text menu - TEXT_MOVE_ENDTEXT = 400, + TEXT_ADD_SOME = 400, + TEXT_ADD_FREEZE, + TEXT_MOVE_ENDTEXT, TEXT_MOVE_ENDENTRY, TEXT_SET_EDITABLE, TEXT_SET_ENABLED @@ -186,7 +208,7 @@ bool MyApp::OnInit() { // Create the main frame window MyFrame *frame = new MyFrame((wxFrame *) NULL, - "Text wxWindows sample", 50, 50, 660, 420); + "Text wxWindows sample", 50, 50, 700, 420); frame->SetSizeHints( 500, 400 ); wxMenu *file_menu = new wxMenu; @@ -224,6 +246,8 @@ bool MyApp::OnInit() #endif // wxUSE_CLIPBOARD wxMenu *menuText = new wxMenu; + menuText->Append(TEXT_ADD_SOME, "&Append some text\tCtrl-A"); + menuText->Append(TEXT_ADD_FREEZE, "&Append text with freeze/thaw\tShift-Ctrl-A"); menuText->Append(TEXT_MOVE_ENDTEXT, "Move cursor to the end of &text"); menuText->Append(TEXT_MOVE_ENDENTRY, "Move cursor to the end of &entry"); menuText->Append(TEXT_SET_EDITABLE, "Toggle &editable state", "", TRUE); @@ -643,10 +667,23 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) "and a very very very very very " "very very very long line to test" "wxHSCROLL style", - wxPoint(450, 10), wxSize(200, 230), + wxPoint(450, 10), wxSize(230, 230), wxTE_RICH | wxTE_MULTILINE | wxHSCROLL); - m_textrich->SetForegroundColour(wxColour(0, 255, 255)); - m_textrich->SetBackgroundColour(*wxBLUE); + + m_textrich->SetStyle(0, 10, *wxRED); + m_textrich->SetStyle(10, 20, *wxBLUE); + m_textrich->SetStyle(30, 40, + wxTextAttr(*wxGREEN, wxNullColour, *wxITALIC_FONT)); + m_textrich->SetDefaultStyle(wxTextAttr()); + m_textrich->AppendText(_T("\n\nFirst 10 characters should be in red\n")); + m_textrich->AppendText(_T("Next 10 characters should be in blue\n")); + m_textrich->AppendText(_T("Next 10 characters should be normal\n")); + m_textrich->AppendText(_T("And the next 10 characters should be green and italic\n")); + m_textrich->SetDefaultStyle(wxTextAttr(*wxCYAN, *wxBLUE)); + m_textrich->AppendText(_T("This text should be cyan on blue\n")); + m_textrich->SetDefaultStyle(*wxBLUE); + m_textrich->AppendText(_T("And this should be in blue and the text you ") + _T("type should be in blue as well")); } void MyPanel::OnSize( wxSizeEvent &event ) @@ -778,6 +815,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEXT_CLIPBOARD_COPY, MyFrame::OnCopyToClipboard) #endif // wxUSE_CLIPBOARD + EVT_MENU(TEXT_ADD_SOME, MyFrame::OnAddText) + EVT_MENU(TEXT_ADD_FREEZE, MyFrame::OnAddTextFreeze) EVT_MENU(TEXT_MOVE_ENDTEXT, MyFrame::OnMoveToEndOfText) EVT_MENU(TEXT_MOVE_ENDENTRY, MyFrame::OnMoveToEndOfEntry)