2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: fs_mem.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxMemoryFSHandler
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxMemoryFSHandler
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-05-10 05:44:43 -04:00
|
|
|
This wxFileSystem handler can store arbitrary data in memory stream and make
|
|
|
|
them accessible via an URL.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-05-10 05:44:43 -04:00
|
|
|
It is particularly suitable for storing bitmaps from resources or included XPM
|
2012-09-11 05:26:58 -04:00
|
|
|
files so that they can be used with wxHTML or wxWebView.
|
2008-05-10 05:44:43 -04:00
|
|
|
|
|
|
|
Filenames are prefixed with @c "memory:", e.g. @c "memory:myfile.html".
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Example:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
#ifndef __WXMSW__
|
|
|
|
#include "logo.xpm"
|
|
|
|
#endif
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
wxFileSystem::AddHandler(new wxMemoryFSHandler);
|
2012-09-11 05:26:58 -04:00
|
|
|
wxMemoryFSHandler::AddFile("logo.png", wxBITMAP(logo), wxBITMAP_TYPE_PNG);
|
2008-03-08 09:43:31 -05:00
|
|
|
wxMemoryFSHandler::AddFile("about.htm",
|
2008-05-10 05:44:43 -04:00
|
|
|
"<html><body>About: "
|
2012-09-11 05:26:58 -04:00
|
|
|
"<img src=\"memory:logo.png\"></body></html>");
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxDialog dlg(this, -1, wxString(_("About")));
|
|
|
|
wxBoxSizer *topsizer;
|
|
|
|
topsizer = new wxBoxSizer(wxVERTICAL);
|
2012-09-11 05:26:58 -04:00
|
|
|
#ifdef USE_WEBVIEW
|
|
|
|
wxWebView* browser = wxWebView::New(&dlg, wxID_ANY, wxWebViewDefaultURLStr,
|
|
|
|
wxDefaultPosition, wxSize(380, 160));
|
|
|
|
browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
|
|
|
|
browser->LoadURL("memory:about.htm");
|
|
|
|
#else // Use wxHtml
|
|
|
|
wxHtmlWindow *browser;
|
|
|
|
browser = new wxHtmlWindow(&dlg, -1, wxDefaultPosition,
|
|
|
|
wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
|
|
|
|
browser->SetBorders(0);
|
|
|
|
browser->LoadPage("memory:about.htm");
|
|
|
|
browser->SetSize(browser->GetInternalRepresentation()->GetWidth(),
|
|
|
|
browser->GetInternalRepresentation()->GetHeight());
|
|
|
|
#endif
|
|
|
|
topsizer->Add(browser, 1, wxALL, 10);
|
2008-05-10 05:44:43 -04:00
|
|
|
topsizer->Add(new wxStaticLine(&dlg, -1), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
|
|
|
|
topsizer->Add(new wxButton(&dlg, wxID_OK, "Ok"),
|
|
|
|
0, wxALL | wxALIGN_RIGHT, 15);
|
|
|
|
dlg.SetAutoLayout(true);
|
2008-03-08 08:52:38 -05:00
|
|
|
dlg.SetSizer(topsizer);
|
2008-05-10 05:44:43 -04:00
|
|
|
topsizer->Fit(&dlg);
|
2008-03-08 08:52:38 -05:00
|
|
|
dlg.Centre();
|
|
|
|
dlg.ShowModal();
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2012-09-11 05:26:58 -04:00
|
|
|
wxMemoryFSHandler::RemoveFile("logo.png");
|
2008-03-08 08:52:38 -05:00
|
|
|
wxMemoryFSHandler::RemoveFile("about.htm");
|
|
|
|
}
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-05-10 05:44:43 -04:00
|
|
|
@category{vfs}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxMemoryFSHandler::AddFileWithMimeType
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxMemoryFSHandler : public wxFileSystemHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxMemoryFSHandler();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-05-10 05:44:43 -04:00
|
|
|
Adds a file to the list of the files stored in memory.
|
|
|
|
|
|
|
|
Stored data (bitmap, text or raw data) will be copied into private memory
|
|
|
|
stream and available under name @c "memory:" + @e filename.
|
|
|
|
|
2021-12-16 15:54:43 -05:00
|
|
|
When using the overload taking @c wxString data, if the string contains
|
|
|
|
only Latin-1 characters (which includes strings created using
|
|
|
|
wxString::From8BitData()), its data is used as is. Otherwise, the UTF-8
|
|
|
|
representation of the string is stored as the data associated with the
|
|
|
|
given @a filename.
|
2021-12-16 15:47:26 -05:00
|
|
|
|
2008-05-10 05:44:43 -04:00
|
|
|
@note you must use a @a type value (aka image format) that wxWidgets
|
|
|
|
can save (e.g. JPG, PNG, see wxImage documentation)!
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see AddFileWithMimeType()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-05-10 05:44:43 -04:00
|
|
|
static void AddFile(const wxString& filename, wxImage& image, wxBitmapType type);
|
|
|
|
static void AddFile(const wxString& filename, const wxBitmap& bitmap, wxBitmapType type);
|
2016-08-10 22:22:34 -04:00
|
|
|
static void AddFile(const wxString& filename, const wxString& textdata);
|
|
|
|
static void AddFile(const wxString& filename, const void *binarydata, size_t size);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-05-10 05:44:43 -04:00
|
|
|
Like AddFile(), but lets you explicitly specify added file's MIME type.
|
|
|
|
|
|
|
|
This version should be used whenever you know the MIME type, because it
|
|
|
|
makes accessing the files faster.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-21 06:34:23 -04:00
|
|
|
@since 2.8.5
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see AddFile()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
static void AddFileWithMimeType(const wxString& filename,
|
|
|
|
const wxString& textdata,
|
|
|
|
const wxString& mimetype);
|
2008-03-08 09:43:31 -05:00
|
|
|
static void AddFileWithMimeType(const wxString& filename,
|
|
|
|
const void* binarydata,
|
|
|
|
size_t size,
|
|
|
|
const wxString& mimetype);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
2008-05-10 05:44:43 -04:00
|
|
|
Removes a file from memory FS and frees the occupied memory.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
static void RemoveFile(const wxString& filename);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|