]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/htmlwin.cpp
compilation fixed after recent wxHTML changes
[wxWidgets.git] / src / html / htmlwin.cpp
index 5986277c0a928365da79928c35b4c5d203e53682..f4e541e312bad6eb2ccfd508063d6799bb0b09b1 100644 (file)
@@ -32,6 +32,7 @@
 #include "wx/html/htmlwin.h"
 #include "wx/html/htmlproc.h"
 #include "wx/list.h"
+#include "wx/clipbrd.h"
 
 #include "wx/arrimpl.cpp"
 #include "wx/listimpl.cpp"
@@ -634,6 +635,52 @@ bool wxHtmlWindow::IsSelectionEnabled() const
     return false;
 #endif
 }
+    
+
+wxString wxHtmlWindow::SelectionToText()
+{
+    if ( !m_selection )
+        return wxEmptyString;
+
+    wxClientDC dc(this);
+
+    const wxHtmlCell *end = m_selection->GetToCell();
+    wxString text;
+    wxHtmlTerminalCellsInterator i(m_selection->GetFromCell(), end);
+    if ( i )
+    {
+        text << i->ConvertToText(m_selection);
+        ++i;
+    }
+    const wxHtmlCell *prev = *i;
+    while ( i )
+    {
+        if ( prev->GetParent() != i->GetParent() )
+            text << _T('\n');
+        text << i->ConvertToText(*i == end ? m_selection : NULL);
+        prev = *i;
+        ++i;
+    }
+    return text;
+}
+
+void wxHtmlWindow::CopySelection(ClipboardType t)
+{
+#if wxUSE_CLIPBOARD
+    if ( m_selection )
+    {
+        wxTheClipboard->UsePrimarySelection(t == Primary);
+        wxString txt(SelectionToText());
+        if ( wxTheClipboard->Open() )
+        {
+            wxTheClipboard->SetData(new wxTextDataObject(txt));
+            wxTheClipboard->Close();
+            wxLogTrace(_T("wxhtmlselection"),
+                       _("Copied to clipboard:\"%s\""), txt.c_str());
+        }
+    }
+#endif
+}
 
 
 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
@@ -669,11 +716,14 @@ void wxHtmlWindow::OnDraw(wxDC& dc)
     dc.SetBackgroundMode(wxTRANSPARENT);
     GetViewStart(&x, &y);
 
-    wxHtmlRenderingState rstate(m_selection);
+    wxHtmlRenderingInfo rinfo;
+    wxDefaultHtmlRenderingStyle rstyle;
+    rinfo.SetSelection(m_selection);
+    rinfo.SetStyle(&rstyle);
     m_Cell->Draw(dc, 0, 0,
                  y * wxHTML_SCROLL_STEP + rect.GetTop(),
                  y * wxHTML_SCROLL_STEP + rect.GetBottom(),
-                 rstate);
+                 rinfo);
 }
 
 
@@ -720,6 +770,9 @@ void wxHtmlWindow::OnMouseUp(wxMouseEvent& event)
         // did the user move the mouse far enough from starting point?
         if ( m_selection )
         {
+#ifdef __UNIX__
+            CopySelection(Primary);
+#endif
             // we don't want mouse up event that ended selecting to be
             // handled as mouse click and e.g. follow hyperlink:
             return;
@@ -769,17 +822,17 @@ void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
             {
                 if (goingDown)
                 {
-                    m_tmpSelFromCell = m_Cell->FindCellByPos(x, y,
-                                                 wxHTML_FIND_NEAREST_BEFORE);
-#if 0 // FIXME -- needed or not?
+                    m_tmpSelFromCell = m_Cell->FindCellByPos(
+                                         m_tmpSelFromPos.x,m_tmpSelFromPos.y,
+                                         wxHTML_FIND_NEAREST_AFTER);
                     if (!m_tmpSelFromCell)
                         m_tmpSelFromCell = m_Cell->GetFirstTerminal();
-#endif
                 }
                 else
                 {
-                    m_tmpSelFromCell = m_Cell->FindCellByPos(x, y,
-                                                 wxHTML_FIND_NEAREST_AFTER);
+                    m_tmpSelFromCell = m_Cell->FindCellByPos(
+                                         m_tmpSelFromPos.x,m_tmpSelFromPos.y,
+                                         wxHTML_FIND_NEAREST_BEFORE);
                     if (!m_tmpSelFromCell)
                         m_tmpSelFromCell = m_Cell->GetLastTerminal();
                 }
@@ -822,16 +875,22 @@ void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
                 }
                 if ( m_selection )
                 {
-                    if (goingDown)
+                    if ( m_tmpSelFromCell->IsBefore(selcell) )
                     {
                         m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell,
-                                         wxPoint(x,y), selcell);
-                    }
+                                         wxPoint(x,y), selcell);                                    }
                     else
                     {
                         m_selection->Set(wxPoint(x,y), selcell,
                                          m_tmpSelFromPos, m_tmpSelFromCell);
                     }
+                    {
+                        wxClientDC dc(this);
+                        m_selection->GetFromCell()->SetSelectionPrivPos(
+                                dc, m_selection);
+                        m_selection->GetToCell()->SetSelectionPrivPos(
+                                dc, m_selection);
+                    }
                     Refresh(); // FIXME - optimize!
                 }
             }
@@ -871,6 +930,26 @@ void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
     }
 }
 
+#if wxUSE_CLIPBOARD
+void wxHtmlWindow::OnKeyUp(wxKeyEvent& event)
+{
+    if ( event.GetKeyCode() == 'C' && event.ControlDown() )
+    {
+        if ( m_selection )
+            CopySelection();
+    }
+    else
+        event.Skip();
+}
+
+void wxHtmlWindow::OnCopy(wxCommandEvent& event)
+{
+    if ( m_selection )
+        CopySelection();
+}
+#endif
+
+
 
 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject)
 
@@ -883,6 +962,10 @@ BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
     EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp)
     EVT_MOTION(wxHtmlWindow::OnMouseMove)
     EVT_IDLE(wxHtmlWindow::OnIdle)
+#if wxUSE_CLIPBOARD
+    EVT_KEY_UP(wxHtmlWindow::OnKeyUp)
+    EVT_MENU(wxID_COPY, wxHtmlWindow::OnCopy)
+#endif
 END_EVENT_TABLE()