]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fs_mem.h
respecting more of the toolbar positions (tb_right not yet working), and fixing SetSi...
[wxWidgets.git] / include / wx / fs_mem.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: fs_mem.h
3 // Purpose: in-memory file system
4 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifndef _WX_FS_MEM_H_
10 #define _WX_FS_MEM_H_
11
12 #include "wx/defs.h"
13
14 #if wxUSE_FILESYSTEM
15
16 #include "wx/filesys.h"
17
18 #include "wx/hashmap.h"
19
20 class wxMemoryFSFile;
21 WX_DECLARE_STRING_HASH_MAP(wxMemoryFSFile *, wxMemoryFSHash);
22
23 #if wxUSE_GUI
24 #include "wx/bitmap.h"
25 #endif // wxUSE_GUI
26
27 // ----------------------------------------------------------------------------
28 // wxMemoryFSHandlerBase
29 // ----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_BASE wxMemoryFSHandlerBase : public wxFileSystemHandler
32 {
33 public:
34 wxMemoryFSHandlerBase();
35 virtual ~wxMemoryFSHandlerBase();
36
37 // Add file to list of files stored in memory. Stored data (bitmap, text or
38 // raw data) will be copied into private memory stream and available under
39 // name "memory:" + filename
40 static void AddFile(const wxString& filename, const wxString& textdata);
41 static void AddFile(const wxString& filename, const void *binarydata, size_t size);
42 static void AddFileWithMimeType(const wxString& filename,
43 const wxString& textdata,
44 const wxString& mimetype);
45 static void AddFileWithMimeType(const wxString& filename,
46 const void *binarydata, size_t size,
47 const wxString& mimetype);
48
49 // Remove file from memory FS and free occupied memory
50 static void RemoveFile(const wxString& filename);
51
52 virtual bool CanOpen(const wxString& location);
53 virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
54 virtual wxString FindFirst(const wxString& spec, int flags = 0);
55 virtual wxString FindNext();
56
57 protected:
58 // check that the given file is not already present in m_Hash; logs an
59 // error and returns false if it does exist
60 static bool CheckDoesntExist(const wxString& filename);
61
62 // the hash map indexed by the names of the files stored in the memory FS
63 static wxMemoryFSHash m_Hash;
64
65 // the file name currently being searched for, i.e. the argument of the
66 // last FindFirst() call or empty string if FindFirst() hasn't been called
67 // yet or FindNext() didn't find anything
68 wxString m_findArgument;
69
70 // iterator into m_Hash used by FindFirst/Next(), possibly m_Hash.end() or
71 // even invalid (can only be used when m_findArgument is not empty)
72 wxMemoryFSHash::const_iterator m_findIter;
73 };
74
75 // ----------------------------------------------------------------------------
76 // wxMemoryFSHandler
77 // ----------------------------------------------------------------------------
78
79 #if wxUSE_GUI
80
81 // add GUI-only operations to the base class
82 class WXDLLIMPEXP_CORE wxMemoryFSHandler : public wxMemoryFSHandlerBase
83 {
84 public:
85 // bring the base class versions into the scope, otherwise they would be
86 // inaccessible in wxMemoryFSHandler
87 // (unfortunately "using" can't be used as gcc 2.95 doesn't have it...)
88 static void AddFile(const wxString& filename, const wxString& textdata)
89 {
90 wxMemoryFSHandlerBase::AddFile(filename, textdata);
91 }
92
93 static void AddFile(const wxString& filename,
94 const void *binarydata,
95 size_t size)
96 {
97 wxMemoryFSHandlerBase::AddFile(filename, binarydata, size);
98 }
99 static void AddFileWithMimeType(const wxString& filename,
100 const wxString& textdata,
101 const wxString& mimetype)
102 {
103 wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
104 textdata,
105 mimetype);
106 }
107 static void AddFileWithMimeType(const wxString& filename,
108 const void *binarydata, size_t size,
109 const wxString& mimetype)
110 {
111 wxMemoryFSHandlerBase::AddFileWithMimeType(filename,
112 binarydata, size,
113 mimetype);
114 }
115
116 #if wxUSE_IMAGE
117 static void AddFile(const wxString& filename,
118 const wxImage& image,
119 wxBitmapType type);
120
121 static void AddFile(const wxString& filename,
122 const wxBitmap& bitmap,
123 wxBitmapType type);
124 #endif // wxUSE_IMAGE
125
126 };
127
128 #else // !wxUSE_GUI
129
130 // just the same thing as the base class in wxBase
131 class WXDLLIMPEXP_BASE wxMemoryFSHandler : public wxMemoryFSHandlerBase
132 {
133 };
134
135 #endif // wxUSE_GUI/!wxUSE_GUI
136
137 #endif // wxUSE_FILESYSTEM
138
139 #endif // _WX_FS_MEM_H_
140