]> git.saurik.com Git - wxWidgets.git/commitdiff
Set up scrollbars correctly for wxWebView in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 24 Jul 2012 20:45:25 +0000 (20:45 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 24 Jul 2012 20:45:25 +0000 (20:45 +0000)
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

samples/webview/webview.cpp
src/gtk/webview_webkit.cpp

index 3f9e99f00c036a83815f83c3b54655459f6c6ab2..6e7ab1435a387f3696296e7f95f4a62829912409 100644 (file)
@@ -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,
index af8cb032557420f0b527b3dfbbb849644dce86cc..ea5abe7c0a2c388a7a39919e810c754cfd30ae50 100644 (file)
@@ -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),