#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"
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);
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",
+ "<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();
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");
//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);
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();
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 );
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();