Ticket #14623: webviewfs.patch

File webviewfs.patch, 14.3 KB (added by nickmat, 9 years ago)
  • build/bakefiles/files.bkl

     
    33323332    $(WEBVIEW_SRC_PLATFORM)
    33333333    src/common/webview.cpp
    33343334    src/common/webviewarchivehandler.cpp
     3335    src/common/webviewfhhandler.cpp
    33353336</set>
    33363337
    33373338<set var="WEBVIEW_HDR_PLATFORM" hints="files">
     
    33523353    $(WEBVIEW_HDR_PLATFORM)
    33533354    wx/webview.h
    33543355    wx/webviewarchivehandler.h
     3356    wx/webviewfshandler.h
    33553357</set>
    33563358
    33573359<!-- ====================================================================== -->
  • include/wx/webviewfshandler.h

     
     1/////////////////////////////////////////////////////////////////////////////
     2// Name:        webviewfshandler.h
     3// Purpose:     Custom webview handler for virtual file system
     4// Author:      Nick Matthews
     5// Id:          $Id$
     6// Copyright:   (c) 2012 Steven Lamerton
     7// Licence:     wxWindows licence
     8/////////////////////////////////////////////////////////////////////////////
     9
     10// Based on webviewarchivehandler.h file by Steven Lamerton
     11
     12#ifndef _WX_WEB_VIEW_FS_HANDLER_H_
     13#define _WX_WEB_VIEW_FS_HANDLER_H_
     14
     15#include "wx/setup.h"
     16
     17#if wxUSE_WEBVIEW
     18
     19class wxFSFile;
     20class wxFileSystem;
     21
     22#include "wx/webview.h"
     23
     24//Loads from uris such as scheme:example.html
     25
     26class WXDLLIMPEXP_WEBVIEW wxWebViewFSHandler : public wxWebViewHandler
     27{
     28public:
     29    wxWebViewFSHandler(const wxString& scheme);
     30    virtual ~wxWebViewFSHandler();
     31    virtual wxFSFile* GetFile(const wxString &uri);
     32private:
     33    wxFileSystem* m_fileSystem;
     34};
     35
     36#endif // wxUSE_WEBVIEW
     37
     38#endif // _WX_WEB_VIEW_FS_HANDLER_H_
  • include/wx/webviewfshandler.h

  • interface/wx/fs_mem.h

    Property changes on: include/wx/webviewfshandler.h
    ___________________________________________________________________
    Added: svn:keywords
    ## -0,0 +1 ##
    +Author Date Id Rev URL
    \ No newline at end of property
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
     
    1313    them accessible via an URL.
    1414
    1515    It is particularly suitable for storing bitmaps from resources or included XPM
    16     files so that they can be used with wxHTML.
     16    files so that they can be used with wxHTML or wxWebView.
    1717
    1818    Filenames are prefixed with @c "memory:", e.g. @c "memory:myfile.html".
    1919
     
    2626
    2727    void MyFrame::OnAbout(wxCommandEvent&)
    2828    {
    29         wxBusyCursor bcur;
    3029        wxFileSystem::AddHandler(new wxMemoryFSHandler);
    31         wxMemoryFSHandler::AddFile("logo.pcx", wxBITMAP(logo), wxBITMAP_TYPE_PCX);
     30        wxMemoryFSHandler::AddFile("logo.png", wxBITMAP(logo), wxBITMAP_TYPE_PNG);
    3231        wxMemoryFSHandler::AddFile("about.htm",
    3332                                "<html><body>About: "
    34                                 "<img src=\"memory:logo.pcx\"></body></html>");
     33                                "<img src=\"memory:logo.png\"></body></html>");
    3534
    3635        wxDialog dlg(this, -1, wxString(_("About")));
    3736        wxBoxSizer *topsizer;
    38         wxHtmlWindow *html;
    3937        topsizer = new wxBoxSizer(wxVERTICAL);
    40         html = new wxHtmlWindow(&dlg, -1, wxDefaultPosition,
    41                                 wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
    42         html->SetBorders(0);
    43         html->LoadPage("memory:about.htm");
    44         html->SetSize(html->GetInternalRepresentation()->GetWidth(),
    45                     html->GetInternalRepresentation()->GetHeight());
    46         topsizer->Add(html, 1, wxALL, 10);
     38    #ifdef USE_wxWebView
     39        wxWebView* browser = wxWebView::New(&dlg, wxID_ANY, wxWebViewDefaultURLStr,
     40                                 wxDefaultPosition, wxSize(380, 160));
     41        browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
     42        browser->LoadURL("memory:about.htm");
     43    #else // Use wxHtml
     44        wxHtmlWindow *browser;
     45        browser = new wxHtmlWindow(&dlg, -1, wxDefaultPosition,
     46                                   wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
     47        browser->SetBorders(0);
     48        browser->LoadPage("memory:about.htm");
     49        browser->SetSize(browser->GetInternalRepresentation()->GetWidth(),
     50                    browser->GetInternalRepresentation()->GetHeight());
     51    #endif
     52        topsizer->Add(browser, 1, wxALL, 10);
    4753        topsizer->Add(new wxStaticLine(&dlg, -1), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
    4854        topsizer->Add(new wxButton(&dlg, wxID_OK, "Ok"),
    4955                    0, wxALL | wxALIGN_RIGHT, 15);
     
    5359        dlg.Centre();
    5460        dlg.ShowModal();
    5561
    56         wxMemoryFSHandler::RemoveFile("logo.pcx");
     62        wxMemoryFSHandler::RemoveFile("logo.png");
    5763        wxMemoryFSHandler::RemoveFile("about.htm");
    5864    }
    5965    @endcode
  • interface/wx/webview.h

     
    231231    wxFSFile which represents the given url. You can then register your handler
    232232    with RegisterHandler() it will be called for all pages and resources.
    233233
    234     wxWebFileHandler is provided to allow the navigation of pages inside a zip
     234    wxWebViewFSHandler is provided to access the virtual file system encapsulated by
     235    wxFileSystem. The wxMemoryFSHandler documentation gives an example of how this
     236    may be used.
     237
     238    wxWebViewArchiveHandler is provided to allow the navigation of pages inside a zip
    235239    archive. It overrides the @c file scheme and provides support for the
    236240    standard @c file syntax as well as paths to archives of the form
    237241    @c file:///C:/example/docs.zip;protocol=zip/main.htm
     
    607611        @param flags The flags for the search.
    608612        @return If search phrase was not found in combination with the flags
    609613                then @c wxNOT_FOUND is returned. If called for the first time
    610                 with search phrase then the total number of results will be 
     614                with search phrase then the total number of results will be
    611615                returned. Then for every time its called with the same search
    612616                phrase it will return the number of the current match.
    613617        @note This function will restart the search if the flags
    614618              @c wxWEB_VIEW_FIND_ENTIRE_WORD or @c wxWEB_VIEW_FIND_MATCH_CASE
    615619              are changed, since this will require a new search. To reset the
    616               search, for example reseting the highlights call the function 
     620              search, for example reseting the highlights call the function
    617621              with an empty search phrase. This always returns @c wxNOT_FOUND
    618622              on the OSX WebKit backend.
    619623        @since 2.9.5
  • interface/wx/webviewfshandler.h

     
     1/////////////////////////////////////////////////////////////////////////////
     2// Name:        webviewfshandler.h
     3// Purpose:     interface of wxWebViewFSHandler
     4// Author:      wxWidgets team
     5// RCS-ID:      $Id$
     6// Licence:     wxWindows licence
     7/////////////////////////////////////////////////////////////////////////////
     8
     9/**
     10    @class wxWebViewFSHandler
     11
     12    A wxWebView file system handler to support standard wxFileSystem protocols
     13    of the form <code> example:page.htm </code> The handler allows wxWebView to
     14    use wxFileSystem in a similar fashion to its use with wxHtml.
     15
     16    The wxMemoryFSHandler documentation gives an example of how it may be used.
     17
     18    @since 2.9.5
     19    @library{wxwebview}
     20    @category{webview}
     21
     22    @see wxWebView, wxWebViewHandler, wxWebViewArchiveHandler
     23 */
     24class wxWebViewFSHandler : public wxWebViewHandler
     25{
     26public:
     27    /**
     28        Constructor.
     29    */
     30    wxWebViewFSHandler(const wxString& scheme);
     31    virtual wxFSFile* GetFile(const wxString &uri);
     32};
  • interface/wx/webviewfshandler.h

  • samples/webview/webview.cpp

    Property changes on: interface/wx/webviewfshandler.h
    ___________________________________________________________________
    Added: svn:eol-style
    ## -0,0 +1 ##
    +native
    \ No newline at end of property
    Added: svn:keywords
    ## -0,0 +1 ##
    +Author Date Id Rev URL
    \ No newline at end of property
     
    3232#include "wx/settings.h"
    3333#include "wx/webview.h"
    3434#include "wx/webviewarchivehandler.h"
     35#include "wx/webviewfshandler.h"
    3536#include "wx/infobar.h"
    3637#include "wx/filesys.h"
    3738#include "wx/fs_arc.h"
     39#include "wx/fs_mem.h"
    3840
    3941#ifndef wxHAS_IMAGES_IN_RESOURCES
    4042    #include "../sample.xpm"
     
    136138    void OnDeleteSelection(wxCommandEvent& evt);
    137139    void OnSelectAll(wxCommandEvent& evt);
    138140    void OnLoadScheme(wxCommandEvent& evt);
     141    void OnUseMemoryFS(wxCommandEvent& evt);
    139142    void OnFind(wxCommandEvent& evt);
    140143    void OnFindDone(wxCommandEvent& evt);
    141144    void OnFindText(wxCommandEvent& evt);
     
    213216    if ( !wxApp::OnInit() )
    214217        return false;
    215218
     219    //Required for virtual file system archive and memory support
     220    wxFileSystem::AddHandler(new wxArchiveFSHandler);
     221    wxFileSystem::AddHandler(new wxMemoryFSHandler);
     222
     223    // Create the memory files
     224    wxImage::AddHandler(new wxPNGHandler);
     225    wxMemoryFSHandler::AddFile("logo.png",
     226        wxBitmap(wxlogo_xpm), wxBITMAP_TYPE_PNG);
     227    wxMemoryFSHandler::AddFile("page1.htm",
     228        "<html><head><title>File System Example</title>"
     229        "<link rel='stylesheet' type='text/css' href='memory:test.css'>"
     230        "</head><body><h1>Page 1</h1>"
     231        "<p><img src='memory:logo.png'></p>"
     232        "<p>Some text about <a href='memory:page2.htm'>Page 2</a>.</p></body>");
     233    wxMemoryFSHandler::AddFile("page2.htm",
     234        "<html><head><title>File System Example</title>"
     235        "<link rel='stylesheet' type='text/css' href='memory:test.css'>"
     236        "</head><body><h1>Page 2</h1>"
     237        "<p><a href='memory:page1.htm'>Page 1</a> was better.</p></body>");
     238    wxMemoryFSHandler::AddFile("test.css", "h1 {color: red;}");
     239
    216240    WebFrame *frame = new WebFrame(m_url);
    217241    frame->Show();
    218242
     
    222246WebFrame::WebFrame(const wxString& url) :
    223247    wxFrame(NULL, wxID_ANY, "wxWebView Sample")
    224248{
    225     //Required from virtual file system archive support
    226     wxFileSystem::AddHandler(new wxArchiveFSHandler);
    227 
    228249    // set the frame icon
    229250    SetIcon(wxICON(sample));
    230251    SetTitle("wxWebView Sample");
     
    309330
    310331    //We register the wxfs:// protocol for testing purposes
    311332    m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
     333    //And the memory: file system
     334    m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
    312335
    313336    SetSizer(topsizer);
    314337
     
    378401    editmenu->AppendSubMenu(selection, "Selection");
    379402
    380403    wxMenuItem* loadscheme =  m_tools_menu->Append(wxID_ANY, _("Custom Scheme Example"));
     404    wxMenuItem* usememoryfs =  m_tools_menu->Append(wxID_ANY, _("Memory File System Example"));
    381405
    382406    //By default we want to handle navigation and new windows
    383407    m_tools_handle_navigation->Check();
     
    481505            wxCommandEventHandler(WebFrame::OnSelectAll),  NULL, this );
    482506    Connect(loadscheme->GetId(), wxEVT_COMMAND_MENU_SELECTED,
    483507            wxCommandEventHandler(WebFrame::OnLoadScheme),  NULL, this );
     508    Connect(usememoryfs->GetId(), wxEVT_COMMAND_MENU_SELECTED,
     509            wxCommandEventHandler(WebFrame::OnUseMemoryFS),  NULL, this );
    484510    Connect(m_find->GetId(), wxEVT_COMMAND_MENU_SELECTED,
    485511            wxCommandEventHandler(WebFrame::OnFind),  NULL, this );
    486512
     
    628654    m_browser->LoadURL(path);
    629655}
    630656
     657void WebFrame::OnUseMemoryFS(wxCommandEvent& WXUNUSED(evt))
     658{
     659    m_browser->LoadURL("memory:page1.htm");
     660}
     661
    631662void WebFrame::OnFind(wxCommandEvent& WXUNUSED(evt))
    632663{
    633664    wxString value = m_browser->GetSelectedText();
  • src/common/webviewfshandler.cpp

     
     1/////////////////////////////////////////////////////////////////////////////
     2// Name:        webviewfshandler.cpp
     3// Purpose:     Custom webview handler for virtual file system
     4// Author:      Nick Matthews
     5// Id:          $Id$
     6// Copyright:   (c) 2012 Steven Lamerton
     7// Licence:     wxWindows licence
     8/////////////////////////////////////////////////////////////////////////////
     9
     10// For compilers that support precompilation, includes "wx.h".
     11#include "wx/wxprec.h"
     12
     13#if wxUSE_WEBVIEW
     14
     15#if defined(__BORLANDC__)
     16    #pragma hdrstop
     17#endif
     18
     19#include "wx/webviewfshandler.h"
     20#include "wx/filesys.h"
     21
     22wxWebViewFSHandler::wxWebViewFSHandler(const wxString& scheme) :
     23                         wxWebViewHandler(scheme)
     24{
     25    m_fileSystem = new wxFileSystem();
     26}
     27
     28wxWebViewFSHandler::~wxWebViewFSHandler()
     29{
     30    wxDELETE(m_fileSystem);
     31}
     32
     33wxFSFile* wxWebViewFSHandler::GetFile(const wxString &uri)
     34{
     35    return m_fileSystem->OpenFile(uri);
     36}
     37
     38#endif // wxUSE_WEBVIEW
  • src/common/webviewfshandler.cpp