]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/fs_mem.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMemoryFSHandler
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 @class wxMemoryFSHandler
11 This wxFileSystem handler can store arbitrary data in memory stream and make
12 them accessible via an URL.
14 It is particularly suitable for storing bitmaps from resources or included XPM
15 files so that they can be used with wxHTML or wxWebView.
17 Filenames are prefixed with @c "memory:", e.g. @c "memory:myfile.html".
26 void MyFrame::OnAbout(wxCommandEvent&)
28 wxFileSystem::AddHandler(new wxMemoryFSHandler);
29 wxMemoryFSHandler::AddFile("logo.png", wxBITMAP(logo), wxBITMAP_TYPE_PNG);
30 wxMemoryFSHandler::AddFile("about.htm",
32 "<img src=\"memory:logo.png\"></body></html>");
34 wxDialog dlg(this, -1, wxString(_("About")));
36 topsizer = new wxBoxSizer(wxVERTICAL);
38 wxWebView* browser = wxWebView::New(&dlg, wxID_ANY, wxWebViewDefaultURLStr,
39 wxDefaultPosition, wxSize(380, 160));
40 browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));
41 browser->LoadURL("memory:about.htm");
43 wxHtmlWindow *browser;
44 browser = new wxHtmlWindow(&dlg, -1, wxDefaultPosition,
45 wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
46 browser->SetBorders(0);
47 browser->LoadPage("memory:about.htm");
48 browser->SetSize(browser->GetInternalRepresentation()->GetWidth(),
49 browser->GetInternalRepresentation()->GetHeight());
51 topsizer->Add(browser, 1, wxALL, 10);
52 topsizer->Add(new wxStaticLine(&dlg, -1), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
53 topsizer->Add(new wxButton(&dlg, wxID_OK, "Ok"),
54 0, wxALL | wxALIGN_RIGHT, 15);
55 dlg.SetAutoLayout(true);
56 dlg.SetSizer(topsizer);
61 wxMemoryFSHandler::RemoveFile("logo.png");
62 wxMemoryFSHandler::RemoveFile("about.htm");
69 @see wxMemoryFSHandler::AddFileWithMimeType
71 class wxMemoryFSHandler
: public wxFileSystemHandler
81 Adds a file to the list of the files stored in memory.
83 Stored data (bitmap, text or raw data) will be copied into private memory
84 stream and available under name @c "memory:" + @e filename.
86 @note you must use a @a type value (aka image format) that wxWidgets
87 can save (e.g. JPG, PNG, see wxImage documentation)!
89 @see AddFileWithMimeType()
91 static void AddFile(const wxString
& filename
, wxImage
& image
, wxBitmapType type
);
92 static void AddFile(const wxString
& filename
, const wxBitmap
& bitmap
, wxBitmapType type
);
97 Like AddFile(), but lets you explicitly specify added file's MIME type.
99 This version should be used whenever you know the MIME type, because it
100 makes accessing the files faster.
106 static void AddFileWithMimeType(const wxString
& filename
,
107 const wxString
& textdata
,
108 const wxString
& mimetype
);
109 static void AddFileWithMimeType(const wxString
& filename
,
110 const void* binarydata
,
112 const wxString
& mimetype
);
116 Removes a file from memory FS and frees the occupied memory.
118 static void RemoveFile(const wxString
& filename
);