X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f7c17f4054a0ea33551262b57061be4847d58ff..bc4a20051ed946dacb546e8cfe96bb264ee19b41:/samples/webview/webview.cpp diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 6e7ab1435a..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,11 @@ 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); + void OnFindOptions(wxCommandEvent& evt); private: wxTextCtrl* m_url; @@ -148,6 +155,15 @@ private: 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; @@ -171,11 +187,16 @@ private: wxMenuItem* m_scroll_page_down; wxMenuItem* m_selection_clear; wxMenuItem* m_selection_delete; + wxMenuItem* m_find; wxInfoBar *m_info; wxStaticText* m_info_text; + wxTextCtrl* m_find_ctrl; + wxToolBar* m_find_toolbar; wxMenuHistoryMap m_histMenuItems; + wxString m_findText; + int m_findFlags, m_findCount; }; class SourceViewDialog : public wxDialog @@ -195,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", + "
Some text about Page 2.
"); + wxMemoryFSHandler::AddFile("page2.htm", + "Page 1 was better.
"); + wxMemoryFSHandler::AddFile("test.css", "h1 {color: red;}"); + WebFrame *frame = new WebFrame(m_url); frame->Show(); @@ -204,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"); @@ -240,6 +279,47 @@ WebFrame::WebFrame(const wxString& url) : m_toolbar->Realize(); + // Set find values. + m_findFlags = wxWEB_VIEW_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()); @@ -250,6 +330,8 @@ WebFrame::WebFrame(const wxString& url) : //We register the wxfs:// protocol for testing purposes m_browser->RegisterHandler(wxSharedPtr