virtual void DeleteSelection();
virtual bool HasSelection();
virtual void SelectAll();
+ virtual wxString GetSelectedText();
/** FIXME: hack to work around signals being received too early */
bool m_ready;
virtual void SelectAll();
virtual bool HasSelection();
virtual void DeleteSelection();
+ virtual wxString GetSelectedText();
// ---- IE-specific methods
virtual void DeleteSelection();
virtual bool HasSelection() { return false };
virtual void SelectAll() {};
+ virtual wxString GetSelectedText();
// ---- methods not from the parent (common) interface
- wxString GetSelectedText();
-
wxString RunScript(const wxString& javascript);
bool CanGetPageSource();
virtual void SelectAll() = 0;
virtual bool HasSelection() = 0;
virtual void DeleteSelection() = 0;
+ virtual wxString GetSelectedText() = 0;
// TODO:
- // wxString GetSelection(); // maybe?
- // void SetSelection(...); // maybe?
-
// void EnableJavascript(bool enabled); // maybe?
// wxString RunScript(const wxString& javascript); // maybe?
correct HTML attribute.
*/
virtual void DeleteSelection() = 0;
+
+ /**
+ Returns the currently selected text, if any.
+ */
+ virtual wxString GetSelectedText() = 0;
/**
Returns @true if there is a current selection.
*/
- virtual bool HasSelection = 0;
+ virtual bool HasSelection() = 0;
/**
Selects the entire page.
webkit_web_view_select_all(WEBKIT_WEB_VIEW(web_view));
}
+wxString wxWebViewWebKit::GetSelectedText()
+{
+ WebKitDOMDocument* doc;
+ WebKitDOMDOMWindow* win;
+ WebKitDOMDOMSelection* sel;
+ WebKitDOMRange* range;
+
+ doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
+ win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
+ sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
+ range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel),
+ 0, NULL);
+ return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range)),
+ wxConvUTF8);
+}
// static
wxVisualAttributes
ExecCommand("Delete");
}
+wxString wxWebViewIE::GetSelectedText()
+{
+ IHTMLDocument2* document = GetDocument();
+ IHTMLSelectionObject* selection;
+ wxString selected;
+ HRESULT hr = document->get_selection(&selection);
+ if(SUCCEEDED(hr))
+ {
+ IDispatch* disrange;
+ hr = selection->createRange(&disrange);
+ if(SUCCEEDED(hr))
+ {
+ IHTMLTxtRange* range;
+ hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
+ if(SUCCEEDED(hr))
+ {
+ BSTR text;
+ range->get_text(&text);
+ selected = wxString(text);
+ range->Release();
+ }
+ disrange->Release();
+ }
+ selection->Release();
+ }
+ document->Release();
+ return selected;
+}
+
bool wxWebViewIE::CanExecCommand(wxString command)
{
IHTMLDocument2* document = GetDocument();
CPPUNIT_TEST( HistoryClear );
CPPUNIT_TEST( HistoryList );
CPPUNIT_TEST( Editable );
+ CPPUNIT_TEST( Selection );
CPPUNIT_TEST_SUITE_END();
void Title();
void HistoryClear();
void HistoryList();
void Editable();
+ void Selection();
void LoadUrl(const wxString& url, int times = 1);
wxWebView* m_browser;
CPPUNIT_ASSERT(!m_browser->IsEditable());
}
+void WebTestCase::Selection()
+{
+ m_browser->SetPage("<html><body>Some text</body></html>", "");
+ CPPUNIT_ASSERT(!m_browser->HasSelection());
+
+ m_browser->SelectAll();
+
+ CPPUNIT_ASSERT(m_browser->HasSelection());
+ CPPUNIT_ASSERT_EQUAL("Some text", m_browser->GetSelectedText());
+
+ m_browser->DeleteSelection();
+
+ CPPUNIT_ASSERT(!m_browser->HasSelection());
+}
+
#endif //wxUSE_WEB