]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/html/test/test.cpp
mention wxGridBagSizer (closes #10488)
[wxWidgets.git] / samples / html / test / test.cpp
index 0336006f31c2a0fd4f37c76d85ba63b428bafd79..a0655c2d8471a54a1ad7b78709554b2f7d44137d 100644 (file)
@@ -28,6 +28,8 @@
 #include "wx/fs_inet.h"
 #include "wx/filedlg.h"
 #include "wx/utils.h"
+#include "wx/clipbrd.h"
+#include "wx/dataobj.h"
 
 #include "../../sample.xpm"
 
@@ -53,7 +55,12 @@ public:
                                              wxString *WXUNUSED(redirect)) const;
 
 private:
-    DECLARE_NO_COPY_CLASS(MyHtmlWindow)
+    void OnClipboardEvent(wxClipboardTextEvent& event);
+
+#if wxUSE_CLIPBOARD
+    DECLARE_EVENT_TABLE()
+#endif // wxUSE_CLIPBOARD
+    wxDECLARE_NO_COPY_CLASS(MyHtmlWindow);
 };
 
 // Define a new frame type: this is going to be our main frame
@@ -147,6 +154,9 @@ IMPLEMENT_APP(MyApp)
 // `Main program' equivalent: the program execution "starts" here
 bool MyApp::OnInit()
 {
+    if ( !wxApp::OnInit() )
+        return false;
+
 #if wxUSE_SYSTEM_OPTIONS
     wxSystemOptions::SetOption(wxT("no-maskblt"), 1);
 #endif
@@ -315,13 +325,13 @@ void MyFrame::OnHtmlLinkClicked(wxHtmlLinkEvent &event)
 
 void MyFrame::OnHtmlCellHover(wxHtmlCellEvent &event)
 {
-    wxLogMessage(wxT("Mouse moved over cell %d at %d;%d"),
+    wxLogMessage(wxT("Mouse moved over cell %p at %d;%d"),
                  event.GetCell(), event.GetPoint().x, event.GetPoint().y);
 }
 
 void MyFrame::OnHtmlCellClicked(wxHtmlCellEvent &event)
 {
-    wxLogMessage(wxT("Click over cell %d at %d;%d"),
+    wxLogMessage(wxT("Click over cell %p at %d;%d"),
                  event.GetCell(), event.GetPoint().x, event.GetPoint().y);
 
     // if we don't skip the event, OnHtmlLinkClicked won't be called!
@@ -335,3 +345,34 @@ wxHtmlOpeningStatus MyHtmlWindow::OnOpeningURL(wxHtmlURLType WXUNUSED(type),
     GetRelatedFrame()->SetStatusText(url + _T(" lately opened"),1);
     return wxHTML_OPEN;
 }
+
+#if wxUSE_CLIPBOARD
+BEGIN_EVENT_TABLE(MyHtmlWindow, wxHtmlWindow)
+    EVT_TEXT_COPY(wxID_ANY, MyHtmlWindow::OnClipboardEvent)
+END_EVENT_TABLE()
+
+void MyHtmlWindow::OnClipboardEvent(wxClipboardTextEvent& WXUNUSED(event))
+{
+    // explicitly call wxHtmlWindow::CopySelection() method
+    // and show the first 100 characters of the text copied in the status bar
+    if ( CopySelection() )
+    {
+        wxTextDataObject data;
+        if ( wxTheClipboard && wxTheClipboard->Open() && wxTheClipboard->GetData(data) )
+        {
+            const wxString text = data.GetText();
+            const size_t maxTextLength = 100;
+
+            wxLogStatus(wxString::Format(_T("Clipboard: '%s%s'"),
+                        wxString(text, maxTextLength).c_str(),
+                        (text.length() > maxTextLength) ? _T("...")
+                                                        : _T("")));
+            wxTheClipboard->Close();
+
+            return;
+        }
+    }
+
+    wxLogStatus(_T("Clipboard: nothing"));
+}
+#endif // wxUSE_CLIPBOARD