X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ddc8c2e3abd656601dfba93ea1eab42aeeaededf..aa9a4ae1a54ab701d1e12d8a9bddf1ddd81a9a1a:/samples/text/text.cpp diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 43a2a663e3..26e87442e6 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -57,12 +57,14 @@ class MyTextCtrl : public wxTextCtrl public: MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, int style = 0) - : wxTextCtrl(parent, id, value, pos, size, style) { } + : wxTextCtrl(parent, id, value, pos, size, style) { m_hasCapture = FALSE; } void OnKeyDown(wxKeyEvent& event); void OnKeyUp(wxKeyEvent& event); void OnChar(wxKeyEvent& event); + bool m_hasCapture; + private: static inline wxChar GetChar(bool on, wxChar c) { return on ? c : _T('-'); } void LogEvent(const wxChar *name, wxKeyEvent& event) const; @@ -124,6 +126,7 @@ public: void OnMoveToEndOfEntry( wxCommandEvent &event ) { m_panel->DoMoveToEndOfEntry(); } + void OnLogClear(wxCommandEvent& event); void OnFileLoad(wxCommandEvent& event); void OnIdle( wxIdleEvent& event ); @@ -149,6 +152,7 @@ enum TEXT_QUIT = 100, TEXT_ABOUT, TEXT_LOAD, + TEXT_CLEAR, // clipboard menu TEXT_CLIPBOARD_COPY = 200, @@ -171,6 +175,8 @@ bool MyApp::OnInit() frame->SetSizeHints( 500, 400 ); wxMenu *file_menu = new wxMenu; + file_menu->Append(TEXT_CLEAR, "&Clear the log\tCtrl-C", + "Clear the log window contents"); file_menu->Append(TEXT_LOAD, "&Load file\tCtrl-O", "Load the sample file into text control"); file_menu->AppendSeparator(); @@ -358,6 +364,8 @@ void MyTextCtrl::OnChar(wxKeyEvent& event) { LogEvent( _T("Char"), event); +/* How are we supposed to test wxTE_PROCESS_TAB with this code? + if ( event.KeyCode() == WXK_TAB ) { WriteText("\t"); @@ -366,6 +374,8 @@ void MyTextCtrl::OnChar(wxKeyEvent& event) { event.Skip(); } +*/ + event.Skip(); } void MyTextCtrl::OnKeyUp(wxKeyEvent& event) @@ -407,6 +417,21 @@ void MyTextCtrl::OnKeyDown(wxKeyEvent& event) // go to position 10 SetInsertionPoint(10); break; + + case WXK_F4: + if (!m_hasCapture) + { + wxLogDebug( wxT("Now capturing mouse and events.") ); + m_hasCapture = TRUE; + CaptureMouse(); + } + else + { + wxLogDebug( wxT("Stopped capturing mouse and events.") ); + m_hasCapture = TRUE; + ReleaseMouse(); + } + break; } LogEvent( _("Key down"), event); @@ -459,7 +484,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_multitext->WriteText( "Prepended. " ); #if wxUSE_TOOLTIPS - m_multitext->SetToolTip("Press F1 here."); + m_multitext->SetToolTip("Press F1 here for statitics, F4 for capture and uncapture mouse."); #endif m_tab = new MyTextCtrl( this, -1, "Multiline, allow processing.", @@ -500,7 +525,7 @@ void MyPanel::DoPasteFromClipboard() { *m_log << "Clipboard supports requested format.\n"; - if (wxTheClipboard->GetData( &data )) + if (wxTheClipboard->GetData( data )) { *m_log << "Successfully retrieved data from the clipboard.\n"; *m_multitext << data.GetText() << "\n"; @@ -522,6 +547,11 @@ void MyPanel::DoPasteFromClipboard() void MyPanel::DoCopyToClipboard() { + // On X11, we want to get the data from the primary selection instead + // of the normal clipboard (which isn't normal under X11 at all). This + // call has no effect under MSW. + wxTheClipboard->UsePrimarySelection(); + wxString text( m_multitext->GetLineText(0) ); if (text.IsEmpty()) @@ -580,6 +610,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEXT_QUIT, MyFrame::OnQuit) EVT_MENU(TEXT_ABOUT, MyFrame::OnAbout) EVT_MENU(TEXT_LOAD, MyFrame::OnFileLoad) + EVT_MENU(TEXT_CLEAR, MyFrame::OnLogClear) #if wxUSE_TOOLTIPS EVT_MENU(TEXT_TOOLTIPS_SETDELAY, MyFrame::OnSetTooltipDelay) @@ -612,6 +643,9 @@ void MyFrame::OnQuit (wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) { + SetSize(40, 40, 200, 200); + return; + wxBeginBusyCursor(); wxMessageDialog dialog(this, @@ -662,6 +696,11 @@ void MyFrame::OnToggleTooltips(wxCommandEvent& event) } #endif // tooltips +void MyFrame::OnLogClear(wxCommandEvent& WXUNUSED(event)) +{ + m_panel->m_log->Clear(); +} + void MyFrame::OnFileLoad(wxCommandEvent& event) { if ( m_panel->m_multitext->LoadFile("text.rc") )