]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/text/text.cpp
Changed stopat to stopafter in CountColours
[wxWidgets.git] / samples / text / text.cpp
index 4d26e23e961bc83345ec2b56a547d6b32f2f9114..d592388bf4480386dd284a16f62b7e6e5b9bdf0a 100644 (file)
@@ -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();
@@ -334,13 +340,13 @@ void MyTextCtrl::LogEvent(const wxChar *name, wxKeyEvent& event) const
             case WXK_NUMPAD_SUBTRACT: key = "NUMPAD_SUBTRACT"; break;
             case WXK_NUMPAD_DECIMAL: key = "NUMPAD_DECIMAL"; break;
 
-           default:
+            default:
             {
                if ( wxIsprint((int)keycode) )
                    key.Printf( _T("'%c'") , (char)keycode);
                else
-                  key.Printf( _T("unknown (%ld)"), keycode);
-           }
+                   key.Printf( _T("unknown (%ld)"), keycode);
+            }
         }
     }
 
@@ -411,6 +417,25 @@ 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;
+
+        case WXK_F5:
+            // insert a blank line
+            WriteText("\n");
     }
 
     LogEvent( _("Key down"), event);
@@ -463,7 +488,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 <TAB> processing.",
@@ -526,6 +551,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())
@@ -584,6 +614,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)
@@ -666,6 +697,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") )