]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: fs_mem.h | |
3 | // Purpose: interface of wxMemoryFSHandler | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxMemoryFSHandler | |
11 | @wxheader{fs_mem.h} | |
12 | ||
13 | This wxFileSystem handler can store arbitrary data in memory stream and make | |
14 | them accessible via an URL. | |
15 | ||
16 | It is particularly suitable for storing bitmaps from resources or included XPM | |
17 | files so that they can be used with wxHTML. | |
18 | ||
19 | Filenames are prefixed with @c "memory:", e.g. @c "memory:myfile.html". | |
20 | ||
21 | Example: | |
22 | ||
23 | @code | |
24 | #ifndef __WXMSW__ | |
25 | #include "logo.xpm" | |
26 | #endif | |
27 | ||
28 | void MyFrame::OnAbout(wxCommandEvent&) | |
29 | { | |
30 | wxBusyCursor bcur; | |
31 | wxFileSystem::AddHandler(new wxMemoryFSHandler); | |
32 | wxMemoryFSHandler::AddFile("logo.pcx", wxBITMAP(logo), wxBITMAP_TYPE_PCX); | |
33 | wxMemoryFSHandler::AddFile("about.htm", | |
34 | "<html><body>About: " | |
35 | "<img src=\"memory:logo.pcx\"></body></html>"); | |
36 | ||
37 | wxDialog dlg(this, -1, wxString(_("About"))); | |
38 | wxBoxSizer *topsizer; | |
39 | wxHtmlWindow *html; | |
40 | topsizer = new wxBoxSizer(wxVERTICAL); | |
41 | html = new wxHtmlWindow(&dlg, -1, wxDefaultPosition, | |
42 | wxSize(380, 160), wxHW_SCROLLBAR_NEVER); | |
43 | html->SetBorders(0); | |
44 | html->LoadPage("memory:about.htm"); | |
45 | html->SetSize(html->GetInternalRepresentation()->GetWidth(), | |
46 | html->GetInternalRepresentation()->GetHeight()); | |
47 | topsizer->Add(html, 1, wxALL, 10); | |
48 | topsizer->Add(new wxStaticLine(&dlg, -1), 0, wxEXPAND | wxLEFT | wxRIGHT, 10); | |
49 | topsizer->Add(new wxButton(&dlg, wxID_OK, "Ok"), | |
50 | 0, wxALL | wxALIGN_RIGHT, 15); | |
51 | dlg.SetAutoLayout(true); | |
52 | dlg.SetSizer(topsizer); | |
53 | topsizer->Fit(&dlg); | |
54 | dlg.Centre(); | |
55 | dlg.ShowModal(); | |
56 | ||
57 | wxMemoryFSHandler::RemoveFile("logo.pcx"); | |
58 | wxMemoryFSHandler::RemoveFile("about.htm"); | |
59 | } | |
60 | @endcode | |
61 | ||
62 | @library{wxbase} | |
63 | @category{vfs} | |
64 | ||
65 | @see wxMemoryFSHandler::AddFileWithMimeType | |
66 | */ | |
67 | class wxMemoryFSHandler : public wxFileSystemHandler | |
68 | { | |
69 | public: | |
70 | /** | |
71 | Constructor. | |
72 | */ | |
73 | wxMemoryFSHandler(); | |
74 | ||
75 | //@{ | |
76 | /** | |
77 | Adds a file to the list of the files stored in memory. | |
78 | ||
79 | Stored data (bitmap, text or raw data) will be copied into private memory | |
80 | stream and available under name @c "memory:" + @e filename. | |
81 | ||
82 | @note you must use a @a type value (aka image format) that wxWidgets | |
83 | can save (e.g. JPG, PNG, see wxImage documentation)! | |
84 | ||
85 | @see AddFileWithMimeType() | |
86 | */ | |
87 | static void AddFile(const wxString& filename, wxImage& image, wxBitmapType type); | |
88 | static void AddFile(const wxString& filename, const wxBitmap& bitmap, wxBitmapType type); | |
89 | //@} | |
90 | ||
91 | //@{ | |
92 | /** | |
93 | Like AddFile(), but lets you explicitly specify added file's MIME type. | |
94 | ||
95 | This version should be used whenever you know the MIME type, because it | |
96 | makes accessing the files faster. | |
97 | ||
98 | @since 2.8.5 | |
99 | ||
100 | @see AddFile() | |
101 | */ | |
102 | static void AddFileWithMimeType(const wxString& filename, | |
103 | const wxString& textdata, | |
104 | const wxString& mimetype); | |
105 | static void AddFileWithMimeType(const wxString& filename, | |
106 | const void* binarydata, | |
107 | size_t size, | |
108 | const wxString& mimetype); | |
109 | //@} | |
110 | ||
111 | /** | |
112 | Removes a file from memory FS and frees the occupied memory. | |
113 | */ | |
114 | static void RemoveFile(const wxString& filename); | |
115 | }; | |
116 |