From: Vadim Zeitlin Date: Tue, 24 Jul 2012 20:45:25 +0000 (+0000) Subject: Set up scrollbars correctly for wxWebView in wxGTK. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1f7c17f4054a0ea33551262b57061be4847d58ff?ds=inline Set up scrollbars correctly for wxWebView in wxGTK. This allows Scroll{Lines,Pages}() methods inherited from wxWindow to work with it. Add a test of using them to the sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72203 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 3f9e99f00c..6e7ab1435a 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -127,6 +127,10 @@ public: void OnMode(wxCommandEvent& evt); void OnZoomLayout(wxCommandEvent& evt); void OnHistory(wxCommandEvent& evt); + void OnScrollLineUp(wxCommandEvent&) { m_browser->LineUp(); } + void OnScrollLineDown(wxCommandEvent&) { m_browser->LineDown(); } + void OnScrollPageUp(wxCommandEvent&) { m_browser->PageUp(); } + void OnScrollPageDown(wxCommandEvent&) { m_browser->PageDown(); } void OnRunScript(wxCommandEvent& evt); void OnClearSelection(wxCommandEvent& evt); void OnDeleteSelection(wxCommandEvent& evt); @@ -161,6 +165,10 @@ private: wxMenuItem* m_edit_undo; wxMenuItem* m_edit_redo; wxMenuItem* m_edit_mode; + wxMenuItem* m_scroll_line_up; + wxMenuItem* m_scroll_line_down; + wxMenuItem* m_scroll_page_up; + wxMenuItem* m_scroll_page_down; wxMenuItem* m_selection_clear; wxMenuItem* m_selection_delete; @@ -289,6 +297,13 @@ WebFrame::WebFrame(const wxString& url) : m_tools_menu->AppendSeparator(); m_tools_menu->AppendSubMenu(editmenu, "Edit"); + wxMenu* scroll_menu = new wxMenu; + m_scroll_line_up = scroll_menu->Append(wxID_ANY, "Line &up"); + m_scroll_line_down = scroll_menu->Append(wxID_ANY, "Line &down"); + m_scroll_page_up = scroll_menu->Append(wxID_ANY, "Page u&p"); + m_scroll_page_down = scroll_menu->Append(wxID_ANY, "Page d&own"); + m_tools_menu->AppendSubMenu(scroll_menu, "Scroll"); + wxMenuItem* script = m_tools_menu->Append(wxID_ANY, _("Run Script")); //Selection menu @@ -371,6 +386,14 @@ WebFrame::WebFrame(const wxString& url) : wxCommandEventHandler(WebFrame::OnRedo), NULL, this ); Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WebFrame::OnMode), NULL, this ); + Connect(m_scroll_line_up->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnScrollLineUp), NULL, this ); + Connect(m_scroll_line_down->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnScrollLineDown), NULL, this ); + Connect(m_scroll_page_up->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnScrollPageUp), NULL, this ); + Connect(m_scroll_page_down->GetId(), wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(WebFrame::OnScrollPageDown), NULL, this ); Connect(script->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WebFrame::OnRunScript), NULL, this ); Connect(m_selection_clear->GetId(), wxEVT_COMMAND_MENU_SELECTED, diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index af8cb03255..ea5abe7c0a 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -401,6 +401,10 @@ bool wxWebViewWebKit::Create(wxWindow *parent, m_busy = false; m_guard = false; + // We currently unconditionally impose scrolling in both directions as it's + // necessary to show arbitrary pages. + style |= wxHSCROLL | wxVSCROLL; + if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { @@ -408,13 +412,9 @@ bool wxWebViewWebKit::Create(wxWindow *parent, return false; } - m_widget = gtk_scrolled_window_new(NULL, NULL); - g_object_ref(m_widget); m_web_view = WEBKIT_WEB_VIEW(webkit_web_view_new()); - - /* Place the WebKitWebView in the GtkScrolledWindow */ - gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_web_view)); - gtk_widget_show(GTK_WIDGET(m_web_view)); + GTKCreateScrolledWindowWith(GTK_WIDGET(m_web_view)); + g_object_ref(m_widget); g_signal_connect_after(m_web_view, "navigation-policy-decision-requested", G_CALLBACK(wxgtk_webview_webkit_navigation),