X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/66ac04006071ae2043c483ae93f8d4fa6888f33f..e0dec8753abaf97e006ea1185bfb6775b28df0a8:/samples/webview/webview.cpp diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 6c0773b6fe..b15b1d8119 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -32,9 +32,11 @@ #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/fs_mem.h" #ifndef wxHAS_IMAGES_IN_RESOURCES #include "../sample.xpm" @@ -136,6 +138,7 @@ public: 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); @@ -213,6 +216,27 @@ bool WebApp::OnInit() if ( !wxApp::OnInit() ) return false; + //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", + "File System Example" + "" + "

Page 1

" + "

" + "

Some text about Page 2.

"); + wxMemoryFSHandler::AddFile("page2.htm", + "File System Example" + "" + "

Page 2

" + "

Page 1 was better.

"); + wxMemoryFSHandler::AddFile("test.css", "h1 {color: red;}"); + WebFrame *frame = new WebFrame(m_url); frame->Show(); @@ -222,9 +246,6 @@ bool WebApp::OnInit() 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"); @@ -309,6 +330,8 @@ WebFrame::WebFrame(const wxString& url) : //We register the wxfs:// protocol for testing purposes m_browser->RegisterHandler(wxSharedPtr(new wxWebViewArchiveHandler("wxfs"))); + //And the memory: file system + m_browser->RegisterHandler(wxSharedPtr(new wxWebViewFSHandler("memory"))); SetSizer(topsizer); @@ -378,6 +401,7 @@ WebFrame::WebFrame(const wxString& url) : 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")); //By default we want to handle navigation and new windows m_tools_handle_navigation->Check(); @@ -481,6 +505,8 @@ WebFrame::WebFrame(const wxString& url) : 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 ); @@ -628,6 +654,11 @@ void WebFrame::OnLoadScheme(wxCommandEvent& WXUNUSED(evt)) m_browser->LoadURL(path); } +void WebFrame::OnUseMemoryFS(wxCommandEvent& WXUNUSED(evt)) +{ + m_browser->LoadURL("memory:page1.htm"); +} + void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt)) { wxString value = m_browser->GetSelectedText();