]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: fs_mem.h | |
3 | // Purpose: interface of wxMemoryFSHandler | |
4 | // Author: wxWidgets team | |
5 | // Licence: wxWindows licence | |
6 | ///////////////////////////////////////////////////////////////////////////// | |
7 | ||
8 | /** | |
9 | @class wxMemoryFSHandler | |
10 | ||
11 | This wxFileSystem handler can store arbitrary data in memory stream and make | |
12 | them accessible via an URL. | |
13 | ||
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. | |
16 | ||
17 | Filenames are prefixed with @c "memory:", e.g. @c "memory:myfile.html". | |
18 | ||
19 | Example: | |
20 | ||
21 | @code | |
22 | #ifndef __WXMSW__ | |
23 | #include "logo.xpm" | |
24 | #endif | |
25 | ||
26 | void MyFrame::OnAbout(wxCommandEvent&) | |
27 | { | |
28 | wxFileSystem::AddHandler(new wxMemoryFSHandler); | |
29 | wxMemoryFSHandler::AddFile("logo.png", wxBITMAP(logo), wxBITMAP_TYPE_PNG); | |
30 | wxMemoryFSHandler::AddFile("about.htm", | |
31 | "<html><body>About: " | |
32 | "<img src=\"memory:logo.png\"></body></html>"); | |
33 | ||
34 | wxDialog dlg(this, -1, wxString(_("About"))); | |
35 | wxBoxSizer *topsizer; | |
36 | topsizer = new wxBoxSizer(wxVERTICAL); | |
37 | #ifdef USE_WEBVIEW | |
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"); | |
42 | #else // Use wxHtml | |
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()); | |
50 | #endif | |
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); | |
57 | topsizer->Fit(&dlg); | |
58 | dlg.Centre(); | |
59 | dlg.ShowModal(); | |
60 | ||
61 | wxMemoryFSHandler::RemoveFile("logo.png"); | |
62 | wxMemoryFSHandler::RemoveFile("about.htm"); | |
63 | } | |
64 | @endcode | |
65 | ||
66 | @library{wxbase} | |
67 | @category{vfs} | |
68 | ||
69 | @see wxMemoryFSHandler::AddFileWithMimeType | |
70 | */ | |
71 | class wxMemoryFSHandler : public wxFileSystemHandler | |
72 | { | |
73 | public: | |
74 | /** | |
75 | Constructor. | |
76 | */ | |
77 | wxMemoryFSHandler(); | |
78 | ||
79 | //@{ | |
80 | /** | |
81 | Adds a file to the list of the files stored in memory. | |
82 | ||
83 | Stored data (bitmap, text or raw data) will be copied into private memory | |
84 | stream and available under name @c "memory:" + @e filename. | |
85 | ||
86 | @note you must use a @a type value (aka image format) that wxWidgets | |
87 | can save (e.g. JPG, PNG, see wxImage documentation)! | |
88 | ||
89 | @see AddFileWithMimeType() | |
90 | */ | |
91 | static void AddFile(const wxString& filename, wxImage& image, wxBitmapType type); | |
92 | static void AddFile(const wxString& filename, const wxBitmap& bitmap, wxBitmapType type); | |
93 | //@} | |
94 | ||
95 | //@{ | |
96 | /** | |
97 | Like AddFile(), but lets you explicitly specify added file's MIME type. | |
98 | ||
99 | This version should be used whenever you know the MIME type, because it | |
100 | makes accessing the files faster. | |
101 | ||
102 | @since 2.8.5 | |
103 | ||
104 | @see AddFile() | |
105 | */ | |
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, | |
111 | size_t size, | |
112 | const wxString& mimetype); | |
113 | //@} | |
114 | ||
115 | /** | |
116 | Removes a file from memory FS and frees the occupied memory. | |
117 | */ | |
118 | static void RemoveFile(const wxString& filename); | |
119 | }; | |
120 |