From 63a65070911908802c27b52173c3306e93dd63bf Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Sat, 9 Jul 2011 14:31:29 +0000 Subject: [PATCH] Add start of selection api, support for HasSelection, SelectAll and DeleteSelection along with documentation. Implement for IE and WebKitGTK and add stubs for OSX WebKit. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/webview_webkit.h | 5 +++++ include/wx/msw/webview_ie.h | 6 ++++++ include/wx/osx/webview_webkit.h | 9 +++++++-- include/wx/webview.h | 4 ++++ interface/wx/webview.h | 21 +++++++++++++++++++++ src/gtk/webview_webkit.cpp | 16 ++++++++++++++++ src/msw/webview_ie.cpp | 20 ++++++++++++++++++++ src/osx/webview_webkit.mm | 8 ++++++++ 8 files changed, 87 insertions(+), 2 deletions(-) diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index a52d8c06e4..3e4e0f7c88 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -138,6 +138,11 @@ public: virtual void SetEditable(bool enable = true); virtual bool IsEditable(); + //Selection + virtual void DeleteSelection(); + virtual bool HasSelection(); + virtual void SelectAll(); + /** FIXME: hack to work around signals being received too early */ bool m_ready; diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index 3ca29ebaa4..2a8163c111 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -97,6 +97,12 @@ public: virtual void SetEditable(bool enable = true); virtual bool IsEditable(); + //Selection + virtual void SelectAll(); + virtual bool HasSelection(); + virtual void DeleteSelection(); + + // ---- IE-specific methods // FIXME: I seem to be able to access remote webpages even in offline mode... diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index ef41abb7fb..37fbf22acc 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -99,8 +99,13 @@ public: virtual void Paste(); //Editing functions - void SetEditable(bool enable = true); - bool IsEditable(); + virtual void SetEditable(bool enable = true); + virtual bool IsEditable(); + + //Selection + virtual void DeleteSelection(); + virtual bool HasSelection() { return false }; + virtual void SelectAll() {}; // ---- methods not from the parent (common) interface wxString GetSelectedText(); diff --git a/include/wx/webview.h b/include/wx/webview.h index 8e938ea9ee..ea241d606c 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -284,6 +284,10 @@ public: virtual void SetEditable(bool enable = true) = 0; virtual bool IsEditable() = 0; + virtual void SelectAll() = 0; + virtual bool HasSelection() = 0; + virtual void DeleteSelection() = 0; + // TODO: // wxString GetSelection(); // maybe? // void SetSelection(...); // maybe? diff --git a/interface/wx/webview.h b/interface/wx/webview.h index e28d43ba85..5927871edd 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -381,6 +381,27 @@ public: Loads a history item. */ virtual void LoadHistoryItem(wxSharedPtr item) = 0; + + /** + @name Selection + */ + + /** + Deletes the current selection. Note that for @c wxWEB_VIEW_BACKEND_WEBKIT + the selection must be editable, either through SetEditable or the + correct HTML attribute. + */ + virtual void DeleteSelection() = 0; + + /** + Returns @true if there is a current selection. + */ + virtual bool HasSelection = 0; + + /** + Selects the entire page. + */ + virtual void SelectAll() = 0; /** @name Undo / Redo diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index 9db8e7b24a..dd9a375a75 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -712,6 +712,22 @@ bool wxWebViewWebKit::IsEditable() return webkit_web_view_get_editable(WEBKIT_WEB_VIEW(web_view)); } +void wxWebViewWebKit::DeleteSelection() +{ + webkit_web_view_delete_selection(WEBKIT_WEB_VIEW(web_view)); +} + +bool wxWebViewWebKit::HasSelection() +{ + return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(web_view)); +} + +void wxWebViewWebKit::SelectAll() +{ + webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view)); +} + + // static wxVisualAttributes wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 2d04aba3e4..3e0ce6c5e2 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -564,6 +564,26 @@ bool wxWebViewIE::IsEditable() return false; } +void wxWebViewIE::SelectAll() +{ + ExecCommand("SelectAll"); +} + +bool wxWebViewIE::HasSelection() +{ + IHTMLDocument2* document = GetDocument(); + IHTMLSelectionObject* selection; + document->get_selection(&selection); + BSTR type; + selection->get_type(&type); + return wxString(type) != "None"; +} + +void wxWebViewIE::DeleteSelection() +{ + ExecCommand("Delete"); +} + bool wxWebViewIE::CanExecCommand(wxString command) { IHTMLDocument2* document = GetDocument(); diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index b33f48a684..9ba00d6c63 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -980,6 +980,14 @@ void wxWebViewWebKit::Paste() [(WebView*)m_webView paste]; } +void wxWebViewWebKit::DeleteSelection() +{ + if ( !m_webView ) + return; + + [(WebView*)m_webView deleteSelection]; +} + //------------------------------------------------------------ // Listener interfaces //------------------------------------------------------------ -- 2.45.2