Allow passing the URL to open to webview sample on command line.

This makes it simpler to test the sample with other pages and especially local
HTML files.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72201 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-07-24 20:45:14 +00:00
parent a977376af3
commit 0eb47013cf

View File

@ -27,6 +27,7 @@
#endif
#include "wx/artprov.h"
#include "wx/cmdline.h"
#include "wx/notifmsg.h"
#include "wx/settings.h"
#include "wx/webview.h"
@ -60,14 +61,44 @@ WX_DECLARE_HASH_MAP(int, wxSharedPtr<wxWebViewHistoryItem>,
class WebApp : public wxApp
{
public:
WebApp() :
m_url("http://www.wxwidgets.org")
{
}
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:
WebFrame();
~WebFrame();
WebFrame(const wxString& url);
virtual ~WebFrame();
void UpdateState();
void OnIdle(wxIdleEvent& evt);
@ -156,13 +187,14 @@ bool WebApp::OnInit()
if ( !wxApp::OnInit() )
return false;
WebFrame *frame = new WebFrame();
WebFrame *frame = new WebFrame(m_url);
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);
@ -205,7 +237,7 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
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