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