]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/fs_mem.h
support for iPhone callbacks
[wxWidgets.git] / interface / wx / fs_mem.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: fs_mem.h
e54c96f1 3// Purpose: interface of wxMemoryFSHandler
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxMemoryFSHandler
7c913512 11
ea6a2ccb
FM
12 This wxFileSystem handler can store arbitrary data in memory stream and make
13 them accessible via an URL.
7c913512 14
ea6a2ccb 15 It is particularly suitable for storing bitmaps from resources or included XPM
0bfd90b3 16 files so that they can be used with wxHTML or wxWebView.
ea6a2ccb
FM
17
18 Filenames are prefixed with @c "memory:", e.g. @c "memory:myfile.html".
7c913512 19
23324ae1 20 Example:
7c913512 21
23324ae1
FM
22 @code
23 #ifndef __WXMSW__
24 #include "logo.xpm"
25 #endif
7c913512 26
23324ae1
FM
27 void MyFrame::OnAbout(wxCommandEvent&)
28 {
23324ae1 29 wxFileSystem::AddHandler(new wxMemoryFSHandler);
0bfd90b3 30 wxMemoryFSHandler::AddFile("logo.png", wxBITMAP(logo), wxBITMAP_TYPE_PNG);
7c913512 31 wxMemoryFSHandler::AddFile("about.htm",
ea6a2ccb 32 "<html><body>About: "
0bfd90b3 33 "<img src=\"memory:logo.png\"></body></html>");
7c913512 34
23324ae1
FM
35 wxDialog dlg(this, -1, wxString(_("About")));
36 wxBoxSizer *topsizer;
23324ae1 37 topsizer = new wxBoxSizer(wxVERTICAL);
0bfd90b3
SL
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);
ea6a2ccb
FM
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);
23324ae1 57 dlg.SetSizer(topsizer);
ea6a2ccb 58 topsizer->Fit(&dlg);
23324ae1
FM
59 dlg.Centre();
60 dlg.ShowModal();
7c913512 61
0bfd90b3 62 wxMemoryFSHandler::RemoveFile("logo.png");
23324ae1
FM
63 wxMemoryFSHandler::RemoveFile("about.htm");
64 }
65 @endcode
7c913512 66
23324ae1 67 @library{wxbase}
ea6a2ccb 68 @category{vfs}
7c913512 69
e54c96f1 70 @see wxMemoryFSHandler::AddFileWithMimeType
23324ae1
FM
71*/
72class wxMemoryFSHandler : public wxFileSystemHandler
73{
74public:
75 /**
76 Constructor.
77 */
78 wxMemoryFSHandler();
79
80 //@{
81 /**
ea6a2ccb
FM
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)!
3c4f71cc 89
4cc4bfaf 90 @see AddFileWithMimeType()
23324ae1 91 */
ea6a2ccb
FM
92 static void AddFile(const wxString& filename, wxImage& image, wxBitmapType type);
93 static void AddFile(const wxString& filename, const wxBitmap& bitmap, wxBitmapType type);
23324ae1
FM
94 //@}
95
96 //@{
97 /**
ea6a2ccb
FM
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.
3c4f71cc 102
1e24c2af 103 @since 2.8.5
3c4f71cc 104
4cc4bfaf 105 @see AddFile()
23324ae1
FM
106 */
107 static void AddFileWithMimeType(const wxString& filename,
108 const wxString& textdata,
109 const wxString& mimetype);
7c913512
FM
110 static void AddFileWithMimeType(const wxString& filename,
111 const void* binarydata,
112 size_t size,
113 const wxString& mimetype);
23324ae1
FM
114 //@}
115
116 /**
ea6a2ccb 117 Removes a file from memory FS and frees the occupied memory.
23324ae1
FM
118 */
119 static void RemoveFile(const wxString& filename);
120};
e54c96f1 121