diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index 07d71e2310..a52d8c06e4 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -134,6 +134,10 @@ public: virtual void Undo(); virtual void Redo(); + //Editing functions + virtual void SetEditable(bool enable = true); + virtual bool IsEditable(); + /** 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 2907de503d..3ca29ebaa4 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -93,6 +93,10 @@ public: virtual void Undo(); virtual void Redo(); + //Editing functions + virtual void SetEditable(bool enable = true); + virtual bool IsEditable(); + // ---- 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 5a068d9b8f..ef41abb7fb 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -97,6 +97,10 @@ public: virtual void Cut(); virtual void Copy(); virtual void Paste(); + + //Editing functions + void SetEditable(bool enable = true); + bool IsEditable(); // ---- methods not from the parent (common) interface wxString GetSelectedText(); @@ -108,9 +112,6 @@ public: void SetScrollPos(int pos); int GetScrollPos(); - void MakeEditable(bool enable = true); - bool IsEditable(); - wxString GetSelection(); bool CanIncreaseTextSize(); diff --git a/include/wx/webview.h b/include/wx/webview.h index fe010713fa..8e938ea9ee 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -281,13 +281,13 @@ public: SetPage(stream.GetString(), baseUrl); } + virtual void SetEditable(bool enable = true) = 0; + virtual bool IsEditable() = 0; + // TODO: // wxString GetSelection(); // maybe? // void SetSelection(...); // maybe? - // void MakeEditable(bool enable = true); // maybe? - // bool IsEditable(); // maybe? - // void EnableJavascript(bool enabled); // maybe? // wxString RunScript(const wxString& javascript); // maybe? diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 2e5e3dbdbb..e28d43ba85 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -229,7 +229,12 @@ public: /** Returns whether the web control is currently busy (e.g. loading a page). */ - virtual bool IsBusy() = 0; + virtual bool IsBusy() = 0; + + /** + Returns whether the web control is currently editable + */ + virtual bool IsEditable() = 0; /** Load a web page from a URL @@ -251,6 +256,13 @@ public: @param flags A bit array that may optionally contain reload options. */ virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0; + + /** + Set the editable property of the web control. Enabling allows the user + to edit the page even if the @c contenteditable attribute is not set. + The exact capabilities vary with the backend being used. + */ + virtual void SetEditable(bool enable = true) = 0; /** Set the displayed page source to the contents of the given string. diff --git a/samples/web/web.cpp b/samples/web/web.cpp index 1130e5aff4..8ca5102760 100644 --- a/samples/web/web.cpp +++ b/samples/web/web.cpp @@ -76,6 +76,7 @@ public: void OnPaste(wxCommandEvent& evt); void OnUndo(wxCommandEvent& evt); void OnRedo(wxCommandEvent& evt); + void OnMode(wxCommandEvent& evt); private: wxTextCtrl* m_url; @@ -102,6 +103,7 @@ private: wxMenuItem* m_edit_paste; wxMenuItem* m_edit_undo; wxMenuItem* m_edit_redo; + wxMenuItem* m_edit_mode; wxTimer* m_timer; int m_animation_angle; @@ -213,6 +215,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") editmenu->AppendSeparator(); m_edit_undo = editmenu->Append(wxID_ANY, _("Undo")); m_edit_redo = editmenu->Append(wxID_ANY, _("Redo")); + editmenu->AppendSeparator(); + m_edit_mode = editmenu->AppendCheckItem(wxID_ANY, _("Edit Mode")); m_tools_menu->AppendSeparator(); m_tools_menu->AppendSubMenu(editmenu, "Edit"); @@ -279,6 +283,8 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") wxCommandEventHandler(WebFrame::OnUndo), NULL, this ); Connect(m_edit_redo->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WebFrame::OnRedo), NULL, this ); + Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnMode), NULL, this ); } void WebFrame::OnAnimationTimer(wxTimerEvent& evt) @@ -428,6 +434,12 @@ void WebFrame::OnRedo(wxCommandEvent& evt) m_browser->Redo(); } +void WebFrame::OnMode(wxCommandEvent& evt) +{ + m_browser->SetEditable(m_edit_mode->IsChecked()); +} + + /** * Callback invoked when there is a request to load a new page (for instance * when the user clicks a link) diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index d4f0c20071..9db8e7b24a 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -702,6 +702,16 @@ bool wxWebViewWebKit::IsBusy() */ } +void wxWebViewWebKit::SetEditable(bool enable) +{ + webkit_web_view_set_editable(WEBKIT_WEB_VIEW(web_view), enable); +} + +bool wxWebViewWebKit::IsEditable() +{ + return webkit_web_view_get_editable(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 9451961d8b..2d04aba3e4 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -544,6 +544,26 @@ void wxWebViewIE::Redo() ExecCommand("Redo"); } +void wxWebViewIE::SetEditable(bool enable) +{ + IHTMLDocument2* document = GetDocument(); + if( enable ) + document->put_designMode(SysAllocString(L"On")); + else + document->put_designMode(SysAllocString(L"Off")); +} + +bool wxWebViewIE::IsEditable() +{ + IHTMLDocument2* document = GetDocument(); + BSTR mode; + document->get_designMode(&mode); + if(wxString(mode) == "On") + return true; + else + return false; +} + bool wxWebViewIE::CanExecCommand(wxString command) { IHTMLDocument2* document = GetDocument(); diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index cfac4c777a..b33f48a684 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -660,7 +660,7 @@ void wxWebViewWebKit::Print() [op runOperation]; } -void wxWebViewWebKit::MakeEditable(bool enable) +void wxWebViewWebKit::SetEditable(bool enable) { if ( !m_webView ) return; diff --git a/tests/controls/webtest.cpp b/tests/controls/webtest.cpp index 23663a2232..d4cd6f341a 100644 --- a/tests/controls/webtest.cpp +++ b/tests/controls/webtest.cpp @@ -40,6 +40,7 @@ private: CPPUNIT_TEST( HistoryEnable ); CPPUNIT_TEST( HistoryClear ); CPPUNIT_TEST( HistoryList ); + CPPUNIT_TEST( Editable ); CPPUNIT_TEST_SUITE_END(); void Title(); @@ -48,6 +49,7 @@ private: void HistoryEnable(); void HistoryClear(); void HistoryList(); + void Editable(); void LoadUrl(const wxString& url, int times = 1); wxWebView* m_browser; @@ -166,4 +168,17 @@ void WebTestCase::HistoryList() CPPUNIT_ASSERT_EQUAL(2, m_browser->GetBackwardHistory().size()); } +void WebTestCase::Editable() +{ + CPPUNIT_ASSERT(!m_browser->IsEditable()); + + m_browser->SetEditable(true); + + CPPUNIT_ASSERT(m_browser->IsEditable()); + + m_browser->SetEditable(false); + + CPPUNIT_ASSERT(!m_browser->IsEditable()); +} + #endif //wxUSE_WEB