]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_filesys.i
Gave wxWindow.GetHandle something to do on wxMac, although it won't
[wxWidgets.git] / wxPython / src / _filesys.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _filesys.i
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include "wx/wxPython/pyistream.h"
20 %}
21
22 //---------------------------------------------------------------------------
23 %newgroup
24
25
26 class wxFSFile : public wxObject
27 {
28 public:
29 wxFSFile(wxInputStream *stream, const wxString& loc,
30 const wxString& mimetype, const wxString& anchor,
31 wxDateTime modif);
32 ~wxFSFile();
33
34 wxInputStream *GetStream();
35 const wxString& GetMimeType();
36 const wxString& GetLocation();
37 const wxString& GetAnchor();
38 wxDateTime GetModificationTime();
39 };
40
41
42 //---------------------------------------------------------------------------
43
44 %{
45 class wxPyFileSystemHandler : public wxFileSystemHandler
46 {
47 public:
48 wxPyFileSystemHandler() : wxFileSystemHandler() {}
49
50 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
51 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
52 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
53 DEC_PYCALLBACK_STRING__pure(FindNext);
54
55 wxString GetProtocol(const wxString& location) {
56 return wxFileSystemHandler::GetProtocol(location);
57 }
58
59 wxString GetLeftLocation(const wxString& location) {
60 return wxFileSystemHandler::GetLeftLocation(location);
61 }
62
63 wxString GetAnchor(const wxString& location) {
64 return wxFileSystemHandler::GetAnchor(location);
65 }
66
67 wxString GetRightLocation(const wxString& location) {
68 return wxFileSystemHandler::GetRightLocation(location);
69 }
70
71 wxString GetMimeTypeFromExt(const wxString& location) {
72 return wxFileSystemHandler::GetMimeTypeFromExt(location);
73 }
74
75 PYPRIVATE;
76 };
77
78
79 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
80 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
81 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
82 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
83 %}
84
85
86
87 %name(CPPFileSystemHandler) class wxFileSystemHandler //: public wxObject
88 {
89 public:
90 //wxFileSystemHandler();
91 };
92
93
94
95 %name(FileSystemHandler) class wxPyFileSystemHandler : public wxFileSystemHandler
96 {
97 public:
98 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
99
100 wxPyFileSystemHandler();
101
102 void _setCallbackInfo(PyObject* self, PyObject* _class);
103
104 bool CanOpen(const wxString& location);
105 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
106 wxString FindFirst(const wxString& spec, int flags = 0);
107 wxString FindNext();
108
109 wxString GetProtocol(const wxString& location);
110 wxString GetLeftLocation(const wxString& location);
111 wxString GetAnchor(const wxString& location);
112 wxString GetRightLocation(const wxString& location);
113 wxString GetMimeTypeFromExt(const wxString& location);
114 };
115
116
117 // //---------------------------------------------------------------------------
118
119
120 class wxFileSystem : public wxObject {
121 public:
122 wxFileSystem();
123 ~wxFileSystem();
124
125 void ChangePathTo(const wxString& location, bool is_dir = False);
126 wxString GetPath();
127
128 wxFSFile* OpenFile(const wxString& location);
129
130 wxString FindFirst(const wxString& spec, int flags = 0);
131 wxString FindNext();
132
133 static void AddHandler(wxFileSystemHandler *handler);
134 static void CleanUpHandlers();
135
136 // Returns the file URL for a native path
137 static wxString FileNameToURL(const wxString& filename);
138
139 // Returns the native path for a file URL
140 //static wxFileName URLToFileName(const wxString& url); *** See below
141 };
142
143
144 // Returns the native path for a file URL
145 wxString wxFileSystem_URLToFileName(const wxString& url);
146 %{
147 wxString wxFileSystem_URLToFileName(const wxString& url) {
148 wxFileName fname = wxFileSystem::URLToFileName(url);
149 return fname.GetFullPath();
150 }
151 %}
152
153
154 //---------------------------------------------------------------------------
155
156 class wxInternetFSHandler : public wxFileSystemHandler {
157 public:
158 wxInternetFSHandler();
159 bool CanOpen(const wxString& location);
160 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
161 };
162
163
164 //---------------------------------------------------------------------------
165
166 class wxZipFSHandler : public wxFileSystemHandler {
167 public:
168 wxZipFSHandler();
169
170 bool CanOpen(const wxString& location);
171 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
172 wxString FindFirst(const wxString& spec, int flags = 0);
173 wxString FindNext();
174 };
175
176 //---------------------------------------------------------------------------
177
178 // TODO: Use SWIG's overloading feature to fix this mess?
179
180 // getting the overloaded static AddFile method right
181 %inline %{
182 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
183 wxImage& image,
184 long type) {
185 wxMemoryFSHandler::AddFile(filename, image, type);
186 }
187
188 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
189 const wxBitmap& bitmap,
190 long type) {
191 wxMemoryFSHandler::AddFile(filename, bitmap, type);
192 }
193
194 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
195 PyObject* data) {
196 wxMemoryFSHandler::AddFile(filename,
197 // TODO: Verify data type
198 (void*)PyString_AsString(data),
199 (size_t)PyString_Size(data));
200 }
201 %}
202
203
204 // case switch for overloading
205 %pythoncode {
206 def MemoryFSHandler_AddFile(filename, a, b=''):
207 if isinstance(a, wx.Image):
208 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
209 elif isinstance(a, wx.Bitmap):
210 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
211 elif type(a) == str:
212 __wxMemoryFSHandler_AddFile_Data(filename, a)
213 else: raise TypeError, 'wx.Image, wx.Bitmap or string expected'
214 }
215
216
217 class wxMemoryFSHandler : public wxFileSystemHandler {
218 public:
219 wxMemoryFSHandler();
220
221 // Remove file from memory FS and free occupied memory
222 static void RemoveFile(const wxString& filename);
223
224 // Add a file to the memory FS
225 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
226
227 bool CanOpen(const wxString& location);
228 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
229 wxString FindFirst(const wxString& spec, int flags = 0);
230 virtual wxString FindNext();
231 };
232
233
234 //---------------------------------------------------------------------------
235 %init %{
236 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
237 %}
238 //---------------------------------------------------------------------------