]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/webview/webview.cpp
Don't use GetThreadId() in wxMSW code.
[wxWidgets.git] / samples / webview / webview.cpp
index e3db1d0451506fa7b6524265ce66ed247ab0de9a..fc134a949812126756157441f0774b29e0c17412 100644 (file)
 #endif
 
 #include "wx/artprov.h"
 #endif
 
 #include "wx/artprov.h"
+#include "wx/cmdline.h"
 #include "wx/notifmsg.h"
 #include "wx/settings.h"
 #include "wx/webview.h"
 #include "wx/webviewarchivehandler.h"
 #include "wx/notifmsg.h"
 #include "wx/settings.h"
 #include "wx/webview.h"
 #include "wx/webviewarchivehandler.h"
+#include "wx/webviewfshandler.h"
 #include "wx/infobar.h"
 #include "wx/filesys.h"
 #include "wx/fs_arc.h"
 #include "wx/infobar.h"
 #include "wx/filesys.h"
 #include "wx/fs_arc.h"
+#include "wx/fs_mem.h"
 
 #ifndef wxHAS_IMAGES_IN_RESOURCES
     #include "../sample.xpm"
 
 #ifndef wxHAS_IMAGES_IN_RESOURCES
     #include "../sample.xpm"
@@ -60,14 +63,44 @@ WX_DECLARE_HASH_MAP(int, wxSharedPtr<wxWebViewHistoryItem>,
 class WebApp : public wxApp
 {
 public:
 class WebApp : public wxApp
 {
 public:
+    WebApp() :
+        m_url("http://www.wxwidgets.org")
+    {
+    }
+
     virtual bool OnInit();
     virtual bool OnInit();
+
+#if wxUSE_CMDLINE_PARSER
+    virtual void OnInitCmdLine(wxCmdLineParser& parser)
+    {
+        wxApp::OnInitCmdLine(parser);
+
+        parser.AddParam("URL to open",
+                        wxCMD_LINE_VAL_STRING,
+                        wxCMD_LINE_PARAM_OPTIONAL);
+    }
+
+    virtual bool OnCmdLineParsed(wxCmdLineParser& parser)
+    {
+        if ( !wxApp::OnCmdLineParsed(parser) )
+            return false;
+
+        if ( parser.GetParamCount() )
+            m_url = parser.GetParam(0);
+
+        return true;
+    }
+#endif // wxUSE_CMDLINE_PARSER
+
+private:
+    wxString m_url;
 };
 
 class WebFrame : public wxFrame
 {
 public:
 };
 
 class WebFrame : public wxFrame
 {
 public:
-    WebFrame();
-    ~WebFrame();
+    WebFrame(const wxString& url);
+    virtual ~WebFrame();
 
     void UpdateState();
     void OnIdle(wxIdleEvent& evt);
 
     void UpdateState();
     void OnIdle(wxIdleEvent& evt);
@@ -96,11 +129,21 @@ public:
     void OnMode(wxCommandEvent& evt);
     void OnZoomLayout(wxCommandEvent& evt);
     void OnHistory(wxCommandEvent& evt);
     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);
     void OnSelectAll(wxCommandEvent& evt);
     void OnLoadScheme(wxCommandEvent& evt);
     void OnRunScript(wxCommandEvent& evt);
     void OnClearSelection(wxCommandEvent& evt);
     void OnDeleteSelection(wxCommandEvent& evt);
     void OnSelectAll(wxCommandEvent& evt);
     void OnLoadScheme(wxCommandEvent& evt);
+    void OnUseMemoryFS(wxCommandEvent& evt);
+    void OnFind(wxCommandEvent& evt);
+    void OnFindDone(wxCommandEvent& evt);
+    void OnFindText(wxCommandEvent& evt);
+    void OnFindOptions(wxCommandEvent& evt);
+    void OnEnableContextMenu(wxCommandEvent& evt);
 
 private:
     wxTextCtrl* m_url;
 
 private:
     wxTextCtrl* m_url;
@@ -113,6 +156,15 @@ private:
     wxToolBarToolBase* m_toolbar_reload;
     wxToolBarToolBase* m_toolbar_tools;
 
     wxToolBarToolBase* m_toolbar_reload;
     wxToolBarToolBase* m_toolbar_tools;
 
+    wxToolBarToolBase* m_find_toolbar_done;
+    wxToolBarToolBase* m_find_toolbar_next;
+    wxToolBarToolBase* m_find_toolbar_previous;
+    wxToolBarToolBase* m_find_toolbar_options;
+    wxMenuItem* m_find_toolbar_wrap;
+    wxMenuItem* m_find_toolbar_highlight;
+    wxMenuItem* m_find_toolbar_matchcase;
+    wxMenuItem* m_find_toolbar_wholeword;
+
     wxMenu* m_tools_menu;
     wxMenu* m_tools_history_menu;
     wxMenuItem* m_tools_layout;
     wxMenu* m_tools_menu;
     wxMenu* m_tools_history_menu;
     wxMenuItem* m_tools_layout;
@@ -130,13 +182,23 @@ private:
     wxMenuItem* m_edit_undo;
     wxMenuItem* m_edit_redo;
     wxMenuItem* m_edit_mode;
     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;
     wxMenuItem* m_selection_clear;
     wxMenuItem* m_selection_delete;
+    wxMenuItem* m_find;
+    wxMenuItem* m_context_menu;
 
     wxInfoBar *m_info;
     wxStaticText* m_info_text;
 
     wxInfoBar *m_info;
     wxStaticText* m_info_text;
+    wxTextCtrl* m_find_ctrl;
+    wxToolBar* m_find_toolbar;
 
     wxMenuHistoryMap m_histMenuItems;
 
     wxMenuHistoryMap m_histMenuItems;
+    wxString m_findText;
+    int m_findFlags, m_findCount;
 };
 
 class SourceViewDialog : public wxDialog
 };
 
 class SourceViewDialog : public wxDialog
@@ -156,17 +218,36 @@ bool WebApp::OnInit()
     if ( !wxApp::OnInit() )
         return false;
 
     if ( !wxApp::OnInit() )
         return false;
 
-    WebFrame *frame = new WebFrame();
+    //Required for virtual file system archive and memory support
+    wxFileSystem::AddHandler(new wxArchiveFSHandler);
+    wxFileSystem::AddHandler(new wxMemoryFSHandler);
+
+    // Create the memory files
+    wxImage::AddHandler(new wxPNGHandler);
+    wxMemoryFSHandler::AddFile("logo.png", 
+        wxBitmap(wxlogo_xpm), wxBITMAP_TYPE_PNG);
+    wxMemoryFSHandler::AddFile("page1.htm",
+        "<html><head><title>File System Example</title>"
+        "<link rel='stylesheet' type='text/css' href='memory:test.css'>"
+        "</head><body><h1>Page 1</h1>"
+        "<p><img src='memory:logo.png'></p>"
+        "<p>Some text about <a href='memory:page2.htm'>Page 2</a>.</p></body>");
+    wxMemoryFSHandler::AddFile("page2.htm",
+        "<html><head><title>File System Example</title>"
+        "<link rel='stylesheet' type='text/css' href='memory:test.css'>"
+        "</head><body><h1>Page 2</h1>"
+        "<p><a href='memory:page1.htm'>Page 1</a> was better.</p></body>");
+    wxMemoryFSHandler::AddFile("test.css", "h1 {color: red;}");
+
+    WebFrame *frame = new WebFrame(m_url);
     frame->Show();
 
     return true;
 }
 
     frame->Show();
 
     return true;
 }
 
-WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
+WebFrame::WebFrame(const wxString& url) :
+    wxFrame(NULL, wxID_ANY, "wxWebView Sample")
 {
 {
-    //Required from virtual file system archive support
-    wxFileSystem::AddHandler(new wxArchiveFSHandler);
-
     // set the frame icon
     SetIcon(wxICON(sample));
     SetTitle("wxWebView Sample");
     // set the frame icon
     SetIcon(wxICON(sample));
     SetTitle("wxWebView Sample");
@@ -200,16 +281,59 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
 
     m_toolbar->Realize();
 
 
     m_toolbar->Realize();
 
+    // Set find values.
+    m_findFlags = wxWEBVIEW_FIND_DEFAULT;
+    m_findText = wxEmptyString;
+    m_findCount = 0;
+
+    // Create panel for find toolbar.
+    wxPanel* panel = new wxPanel(this);
+    topsizer->Add(panel, wxSizerFlags().Expand());
+
+    // Create sizer for panel.
+    wxBoxSizer* panel_sizer = new wxBoxSizer(wxVERTICAL);
+    panel->SetSizer(panel_sizer);
+
+    // Create the find toolbar.
+    m_find_toolbar = new wxToolBar(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxTB_TEXT|wxTB_HORZ_LAYOUT);
+    m_find_toolbar->Hide();
+    panel_sizer->Add(m_find_toolbar, wxSizerFlags().Expand());
+
+    // Create find control.
+    m_find_ctrl = new wxTextCtrl(m_find_toolbar, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(140,-1), wxTE_PROCESS_ENTER);
+
+
+    //Find options menu
+    wxMenu* findmenu = new wxMenu;
+    m_find_toolbar_wrap = findmenu->AppendCheckItem(wxID_ANY,"Wrap");
+    m_find_toolbar_matchcase = findmenu->AppendCheckItem(wxID_ANY,"Match Case");
+    m_find_toolbar_wholeword = findmenu->AppendCheckItem(wxID_ANY,"Entire Word");
+    m_find_toolbar_highlight = findmenu->AppendCheckItem(wxID_ANY,"Highlight");
+    // Add find toolbar tools.
+    m_find_toolbar->SetToolSeparation(7);
+    m_find_toolbar_done = m_find_toolbar->AddTool(wxID_ANY, "Close", wxArtProvider::GetBitmap(wxART_CROSS_MARK));
+    m_find_toolbar->AddSeparator();
+    m_find_toolbar->AddControl(m_find_ctrl, "Find");
+    m_find_toolbar->AddSeparator();
+    m_find_toolbar_next = m_find_toolbar->AddTool(wxID_ANY, "Next", wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_TOOLBAR, wxSize(16,16)));
+    m_find_toolbar_previous = m_find_toolbar->AddTool(wxID_ANY, "Previous", wxArtProvider::GetBitmap(wxART_GO_UP, wxART_TOOLBAR, wxSize(16,16)));
+    m_find_toolbar->AddSeparator();
+    m_find_toolbar_options = m_find_toolbar->AddTool(wxID_ANY, "Options", wxArtProvider::GetBitmap(wxART_PLUS, wxART_TOOLBAR, wxSize(16,16)), "", wxITEM_DROPDOWN);
+    m_find_toolbar_options->SetDropdownMenu(findmenu);
+    m_find_toolbar->Realize();
+
     // Create the info panel
     m_info = new wxInfoBar(this);
     topsizer->Add(m_info, wxSizerFlags().Expand());
 
     // Create the webview
     // Create the info panel
     m_info = new wxInfoBar(this);
     topsizer->Add(m_info, wxSizerFlags().Expand());
 
     // Create the webview
-    m_browser = wxWebView::New(this, wxID_ANY, "http://www.wxwidgets.org");
+    m_browser = wxWebView::New(this, wxID_ANY, url);
     topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
 
     //We register the wxfs:// protocol for testing purposes
     m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
     topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
 
     //We register the wxfs:// protocol for testing purposes
     m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
+    //And the memory: file system
+    m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
 
     SetSizer(topsizer);
 
 
     SetSizer(topsizer);
 
@@ -235,6 +359,10 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
     m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
     m_tools_menu->AppendSeparator();
 
     m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
     m_tools_menu->AppendSeparator();
 
+    //Find
+    m_find = m_tools_menu->Append(wxID_ANY, _("Find"));
+    m_tools_menu->AppendSeparator();
+
     //History menu
     m_tools_history_menu = new wxMenu();
     wxMenuItem* clearhist =  m_tools_history_menu->Append(wxID_ANY, _("Clear History"));
     //History menu
     m_tools_history_menu = new wxMenu();
     wxMenuItem* clearhist =  m_tools_history_menu->Append(wxID_ANY, _("Clear History"));
@@ -257,6 +385,13 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
     m_tools_menu->AppendSeparator();
     m_tools_menu->AppendSubMenu(editmenu, "Edit");
 
     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
     wxMenuItem* script =  m_tools_menu->Append(wxID_ANY, _("Run Script"));
 
     //Selection menu
@@ -268,12 +403,15 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
     editmenu->AppendSubMenu(selection, "Selection");
 
     wxMenuItem* loadscheme =  m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
     editmenu->AppendSubMenu(selection, "Selection");
 
     wxMenuItem* loadscheme =  m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
+    wxMenuItem* usememoryfs =  m_tools_menu->Append(wxID_ANY, _("Memory File System Example"));
+
+    m_context_menu = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable Context Menu"));
 
     //By default we want to handle navigation and new windows
     m_tools_handle_navigation->Check();
     m_tools_handle_new_window->Check();
     m_tools_enable_history->Check();
 
     //By default we want to handle navigation and new windows
     m_tools_handle_navigation->Check();
     m_tools_handle_new_window->Check();
     m_tools_enable_history->Check();
-    if(!m_browser->CanSetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT))
+    if(!m_browser->CanSetZoomType(wxWEBVIEW_ZOOM_TYPE_LAYOUT))
         m_tools_layout->Enable(false);
 
 
         m_tools_layout->Enable(false);
 
 
@@ -292,18 +430,32 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
     Connect(m_url->GetId(), wxEVT_COMMAND_TEXT_ENTER,
             wxCommandEventHandler(WebFrame::OnUrl), NULL, this );
 
     Connect(m_url->GetId(), wxEVT_COMMAND_TEXT_ENTER,
             wxCommandEventHandler(WebFrame::OnUrl), NULL, this );
 
+    // Connect find toolbar events.
+    Connect(m_find_toolbar_done->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
+            wxCommandEventHandler(WebFrame::OnFindDone), NULL, this );
+    Connect(m_find_toolbar_next->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
+            wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
+    Connect(m_find_toolbar_previous->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
+            wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
+
+    // Connect find control events.
+    Connect(m_find_ctrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
+            wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
+    Connect(m_find_ctrl->GetId(), wxEVT_COMMAND_TEXT_ENTER,
+            wxCommandEventHandler(WebFrame::OnFindText), NULL, this );
+
     // Connect the webview events
     // Connect the webview events
-    Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATING,
+    Connect(m_browser->GetId(), wxEVT_COMMAND_WEBVIEW_NAVIGATING,
             wxWebViewEventHandler(WebFrame::OnNavigationRequest), NULL, this);
             wxWebViewEventHandler(WebFrame::OnNavigationRequest), NULL, this);
-    Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NAVIGATED,
+    Connect(m_browser->GetId(), wxEVT_COMMAND_WEBVIEW_NAVIGATED,
             wxWebViewEventHandler(WebFrame::OnNavigationComplete), NULL, this);
             wxWebViewEventHandler(WebFrame::OnNavigationComplete), NULL, this);
-    Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_LOADED,
+    Connect(m_browser->GetId(), wxEVT_COMMAND_WEBVIEW_LOADED,
             wxWebViewEventHandler(WebFrame::OnDocumentLoaded), NULL, this);
             wxWebViewEventHandler(WebFrame::OnDocumentLoaded), NULL, this);
-    Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_ERROR,
+    Connect(m_browser->GetId(), wxEVT_COMMAND_WEBVIEW_ERROR,
             wxWebViewEventHandler(WebFrame::OnError), NULL, this);
             wxWebViewEventHandler(WebFrame::OnError), NULL, this);
-    Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_NEWWINDOW,
+    Connect(m_browser->GetId(), wxEVT_COMMAND_WEBVIEW_NEWWINDOW,
             wxWebViewEventHandler(WebFrame::OnNewWindow), NULL, this);
             wxWebViewEventHandler(WebFrame::OnNewWindow), NULL, this);
-    Connect(m_browser->GetId(), wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED,
+    Connect(m_browser->GetId(), wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED,
             wxWebViewEventHandler(WebFrame::OnTitleChanged), NULL, this);
 
     // Connect the menu events
             wxWebViewEventHandler(WebFrame::OnTitleChanged), NULL, this);
 
     // Connect the menu events
@@ -339,6 +491,14 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
             wxCommandEventHandler(WebFrame::OnRedo),  NULL, this );
     Connect(m_edit_mode->GetId(), wxEVT_COMMAND_MENU_SELECTED,
             wxCommandEventHandler(WebFrame::OnMode),  NULL, this );
             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,
     Connect(script->GetId(), wxEVT_COMMAND_MENU_SELECTED,
             wxCommandEventHandler(WebFrame::OnRunScript),  NULL, this );
     Connect(m_selection_clear->GetId(), wxEVT_COMMAND_MENU_SELECTED,
@@ -349,6 +509,12 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
             wxCommandEventHandler(WebFrame::OnSelectAll),  NULL, this );
     Connect(loadscheme->GetId(), wxEVT_COMMAND_MENU_SELECTED,
             wxCommandEventHandler(WebFrame::OnLoadScheme),  NULL, this );
             wxCommandEventHandler(WebFrame::OnSelectAll),  NULL, this );
     Connect(loadscheme->GetId(), wxEVT_COMMAND_MENU_SELECTED,
             wxCommandEventHandler(WebFrame::OnLoadScheme),  NULL, this );
+    Connect(usememoryfs->GetId(), wxEVT_COMMAND_MENU_SELECTED,
+            wxCommandEventHandler(WebFrame::OnUseMemoryFS),  NULL, this );
+    Connect(m_find->GetId(), wxEVT_COMMAND_MENU_SELECTED,
+            wxCommandEventHandler(WebFrame::OnFind),  NULL, this );
+    Connect(m_context_menu->GetId(), wxEVT_COMMAND_MENU_SELECTED,
+            wxCommandEventHandler(WebFrame::OnEnableContextMenu), NULL, this );
 
     //Connect the idle events
     Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
 
     //Connect the idle events
     Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(WebFrame::OnIdle), NULL, this);
@@ -494,6 +660,82 @@ void WebFrame::OnLoadScheme(wxCommandEvent& WXUNUSED(evt))
     m_browser->LoadURL(path);
 }
 
     m_browser->LoadURL(path);
 }
 
+void WebFrame::OnUseMemoryFS(wxCommandEvent& WXUNUSED(evt))
+{
+    m_browser->LoadURL("memory:page1.htm");
+}
+
+void WebFrame::OnEnableContextMenu(wxCommandEvent& evt)
+{
+    m_browser->EnableContextMenu(evt.IsChecked());
+}
+
+void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
+{
+    wxString value = m_browser->GetSelectedText();
+    if(value.Len() > 150)
+    {
+        value.Truncate(150);
+    }
+    m_find_ctrl->SetValue(value);
+    if(!m_find_toolbar->IsShown()){
+        m_find_toolbar->Show(true);
+        SendSizeEvent();
+    }
+    m_find_ctrl->SelectAll();
+}
+
+void WebFrame::OnFindDone(wxCommandEvent& WXUNUSED(evt))
+{
+    m_browser->Find("");
+    m_find_toolbar->Show(false);
+    SendSizeEvent();
+}
+
+void WebFrame::OnFindText(wxCommandEvent& evt)
+{
+    int flags = 0;
+
+    if(m_find_toolbar_wrap->IsChecked())
+        flags |= wxWEBVIEW_FIND_WRAP;
+    if(m_find_toolbar_wholeword->IsChecked())
+        flags |= wxWEBVIEW_FIND_ENTIRE_WORD;
+    if(m_find_toolbar_matchcase->IsChecked())
+        flags |= wxWEBVIEW_FIND_MATCH_CASE;
+    if(m_find_toolbar_highlight->IsChecked())
+        flags |= wxWEBVIEW_FIND_HIGHLIGHT_RESULT;
+
+    if(m_find_toolbar_previous->GetId() == evt.GetId())
+        flags |= wxWEBVIEW_FIND_BACKWARDS;
+
+    wxString find_text = m_find_ctrl->GetValue();
+    long count = m_browser->Find(find_text, flags);
+
+    if(m_findText != find_text)
+    {
+        m_findCount = count;
+        m_findText = find_text;
+    }
+
+    if(count != wxNOT_FOUND || find_text.IsEmpty())
+    {
+        m_find_ctrl->SetBackgroundColour(*wxWHITE);
+    }
+    else
+    {
+        m_find_ctrl->SetBackgroundColour(wxColour(255, 101, 101));
+    }
+
+    m_find_ctrl->Refresh();
+
+    //Log the result, note that count is zero indexed.
+    if(count != m_findCount)
+    {
+        count++;
+    }
+    wxLogMessage("Searching for:%s  current match:%i/%i", m_findText.c_str(), count, m_findCount);
+}
+
 /**
   * Callback invoked when there is a request to load a new page (for instance
   * when the user clicks a link)
 /**
   * Callback invoked when there is a request to load a new page (for instance
   * when the user clicks a link)
@@ -592,19 +834,19 @@ void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
     wxWebViewZoom zoom = m_browser->GetZoom();
     switch (zoom)
     {
     wxWebViewZoom zoom = m_browser->GetZoom();
     switch (zoom)
     {
-    case wxWEB_VIEW_ZOOM_TINY:
+    case wxWEBVIEW_ZOOM_TINY:
         m_tools_tiny->Check();
         break;
         m_tools_tiny->Check();
         break;
-    case wxWEB_VIEW_ZOOM_SMALL:
+    case wxWEBVIEW_ZOOM_SMALL:
         m_tools_small->Check();
         break;
         m_tools_small->Check();
         break;
-    case wxWEB_VIEW_ZOOM_MEDIUM:
+    case wxWEBVIEW_ZOOM_MEDIUM:
         m_tools_medium->Check();
         break;
         m_tools_medium->Check();
         break;
-    case wxWEB_VIEW_ZOOM_LARGE:
+    case wxWEBVIEW_ZOOM_LARGE:
         m_tools_large->Check();
         break;
         m_tools_large->Check();
         break;
-    case wxWEB_VIEW_ZOOM_LARGEST:
+    case wxWEBVIEW_ZOOM_LARGEST:
         m_tools_largest->Check();
         break;
     }
         m_tools_largest->Check();
         break;
     }
@@ -619,6 +861,8 @@ void WebFrame::OnToolsClicked(wxCommandEvent& WXUNUSED(evt))
     m_selection_clear->Enable(m_browser->HasSelection());
     m_selection_delete->Enable(m_browser->HasSelection());
 
     m_selection_clear->Enable(m_browser->HasSelection());
     m_selection_delete->Enable(m_browser->HasSelection());
 
+    m_context_menu->Check(m_browser->IsContextMenuEnabled());
+
     //Firstly we clear the existing menu items, then we add the current ones
     wxMenuHistoryMap::const_iterator it;
     for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
     //Firstly we clear the existing menu items, then we add the current ones
     wxMenuHistoryMap::const_iterator it;
     for( it = m_histMenuItems.begin(); it != m_histMenuItems.end(); ++it )
@@ -669,23 +913,23 @@ void WebFrame::OnSetZoom(wxCommandEvent& evt)
 {
     if (evt.GetId() == m_tools_tiny->GetId())
     {
 {
     if (evt.GetId() == m_tools_tiny->GetId())
     {
-        m_browser->SetZoom(wxWEB_VIEW_ZOOM_TINY);
+        m_browser->SetZoom(wxWEBVIEW_ZOOM_TINY);
     }
     else if (evt.GetId() == m_tools_small->GetId())
     {
     }
     else if (evt.GetId() == m_tools_small->GetId())
     {
-        m_browser->SetZoom(wxWEB_VIEW_ZOOM_SMALL);
+        m_browser->SetZoom(wxWEBVIEW_ZOOM_SMALL);
     }
     else if (evt.GetId() == m_tools_medium->GetId())
     {
     }
     else if (evt.GetId() == m_tools_medium->GetId())
     {
-        m_browser->SetZoom(wxWEB_VIEW_ZOOM_MEDIUM);
+        m_browser->SetZoom(wxWEBVIEW_ZOOM_MEDIUM);
     }
     else if (evt.GetId() == m_tools_large->GetId())
     {
     }
     else if (evt.GetId() == m_tools_large->GetId())
     {
-        m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGE);
+        m_browser->SetZoom(wxWEBVIEW_ZOOM_LARGE);
     }
     else if (evt.GetId() == m_tools_largest->GetId())
     {
     }
     else if (evt.GetId() == m_tools_largest->GetId())
     {
-        m_browser->SetZoom(wxWEB_VIEW_ZOOM_LARGEST);
+        m_browser->SetZoom(wxWEBVIEW_ZOOM_LARGEST);
     }
     else
     {
     }
     else
     {
@@ -696,9 +940,9 @@ void WebFrame::OnSetZoom(wxCommandEvent& evt)
 void WebFrame::OnZoomLayout(wxCommandEvent& WXUNUSED(evt))
 {
     if(m_tools_layout->IsChecked())
 void WebFrame::OnZoomLayout(wxCommandEvent& WXUNUSED(evt))
 {
     if(m_tools_layout->IsChecked())
-        m_browser->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_LAYOUT);
+        m_browser->SetZoomType(wxWEBVIEW_ZOOM_TYPE_LAYOUT);
     else
     else
-        m_browser->SetZoomType(wxWEB_VIEW_ZOOM_TYPE_TEXT);
+        m_browser->SetZoomType(wxWEBVIEW_ZOOM_TYPE_TEXT);
 }
 
 void WebFrame::OnHistory(wxCommandEvent& evt)
 }
 
 void WebFrame::OnHistory(wxCommandEvent& evt)
@@ -734,48 +978,30 @@ void WebFrame::OnSelectAll(wxCommandEvent& WXUNUSED(evt))
   * Callback invoked when a loading error occurs
   */
 void WebFrame::OnError(wxWebViewEvent& evt)
   * Callback invoked when a loading error occurs
   */
 void WebFrame::OnError(wxWebViewEvent& evt)
-{
-    wxString errorCategory;
-    switch (evt.GetInt())
-    {
-    case  wxWEB_NAV_ERR_CONNECTION:
-        errorCategory = "wxWEB_NAV_ERR_CONNECTION";
-        break;
-
-    case wxWEB_NAV_ERR_CERTIFICATE:
-        errorCategory = "wxWEB_NAV_ERR_CERTIFICATE";
-        break;
-
-    case wxWEB_NAV_ERR_AUTH:
-        errorCategory = "wxWEB_NAV_ERR_AUTH";
-        break;
-
-    case wxWEB_NAV_ERR_SECURITY:
-        errorCategory = "wxWEB_NAV_ERR_SECURITY";
+{   
+#define WX_ERROR_CASE(type) \
+    case type: \
+        category = #type; \
         break;
 
         break;
 
-    case wxWEB_NAV_ERR_NOT_FOUND:
-        errorCategory = "wxWEB_NAV_ERR_NOT_FOUND";
-        break;
-
-    case wxWEB_NAV_ERR_REQUEST:
-        errorCategory = "wxWEB_NAV_ERR_REQUEST";
-        break;
-
-    case wxWEB_NAV_ERR_USER_CANCELLED:
-        errorCategory = "wxWEB_NAV_ERR_USER_CANCELLED";
-        break;
-
-    case wxWEB_NAV_ERR_OTHER:
-        errorCategory = "wxWEB_NAV_ERR_OTHER";
-        break;
+    wxString category;
+    switch (evt.GetInt())
+    {
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_CONNECTION);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_CERTIFICATE);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_AUTH);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_SECURITY);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_NOT_FOUND);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_REQUEST);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_USER_CANCELLED);
+        WX_ERROR_CASE(wxWEBVIEW_NAV_ERR_OTHER);
     }
 
     }
 
-    wxLogMessage("%s", "Error; url='" + evt.GetURL() + "', error='" + errorCategory + "' (" + evt.GetString() + ")");
+    wxLogMessage("%s", "Error; url='" + evt.GetURL() + "', error='" + category + " (" + evt.GetString() + ")'");
 
     //Show the info bar with an error
     m_info->ShowMessage(_("An error occurred loading ") + evt.GetURL() + "\n" +
 
     //Show the info bar with an error
     m_info->ShowMessage(_("An error occurred loading ") + evt.GetURL() + "\n" +
-    "'" + errorCategory + "' (" + evt.GetString() + ")", wxICON_ERROR);
+    "'" + category + "'", wxICON_ERROR);
 
     UpdateState();
 }
 
     UpdateState();
 }