1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
5 // Author: Joerg Baumann
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include <wx/filesys.h>
18 #include <wx/fs_inet.h>
19 #include <wx/fs_mem.h>
20 #include <wx/fs_zip.h>
23 //----------------------------------------------------------------------
26 %include my_typemaps.i
28 // Import some definitions of other classes, etc.
34 %pragma(python) code = "import wx"
35 %pragma(python) code = "import string"
37 //---------------------------------------------------------------------------
39 // // typemaps for wxInputStream: Note wxFSFile object has to do the delete
40 // // of wxInputStream *
41 // %typemap(python,in) wxInputStream *stream {
42 // if (PyInstance_Check($source)) {
43 // wxPyInputStream* ptr;
44 // if (SWIG_GetPtrObj($source, (void **) &ptr,"_wxPyInputStream_p")) {
45 // PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
48 // $target = ptr->wxi;
50 // PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
56 // // typemaps for wxInputStream: Note wxFSFile object has to do the delete
57 // // of wxInputStream *
58 // %typemap(python,out) wxInputStream* {
59 // wxPyInputStream * _ptr = NULL;
62 // _ptr = new wxPyInputStream($source);
66 // SWIG_MakePtr(swigptr, _ptr, "_wxPyInputStream_p");
68 // PyObject* classobj = PyDict_GetItemString(wxPython_dict, "wxInputStreamPtr");
70 // Py_INCREF(Py_None);
73 // PyObject* arg = Py_BuildValue("(s)", swigptr);
74 // $target = PyInstance_New(classobj, arg, NULL);
78 // PyObject* one = PyInt_FromLong(1);
79 // PyObject_SetAttrString($target, "thisown", one);
83 // Py_INCREF(Py_None);
92 wxFSFile(wxInputStream *stream, const wxString& loc,
93 const wxString& mimetype, const wxString& anchor,
96 wxInputStream *GetStream();
97 const wxString& GetMimeType();
98 const wxString& GetLocation();
99 const wxString& GetAnchor();
100 wxDateTime GetModificationTime();
105 %typemap(python,in) wxInputStream *stream;
106 %typemap(python,out) wxInputStream *;
109 //---------------------------------------------------------------------------
112 // wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
113 // the callback functions
114 class wxPyFileSystemHandler : public wxFileSystemHandler {
116 wxPyFileSystemHandler() : wxFileSystemHandler() {}
118 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
119 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
120 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
121 DEC_PYCALLBACK_STRING__pure(FindNext);
123 wxString GetProtocol(const wxString& location) {
124 return wxFileSystemHandler::GetProtocol(location);
127 wxString GetLeftLocation(const wxString& location) {
128 return wxFileSystemHandler::GetLeftLocation(location);
131 wxString GetAnchor(const wxString& location) {
132 return wxFileSystemHandler::GetAnchor(location);
135 wxString GetRightLocation(const wxString& location) {
136 return wxFileSystemHandler::GetRightLocation(location);
139 wxString GetMimeTypeFromExt(const wxString& location){
140 return wxFileSystemHandler::GetMimeTypeFromExt(location);
147 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
148 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
149 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
150 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
154 %name(wxCPPFileSystemHandler)class wxFileSystemHandler {
155 wxFileSystemHandler();
158 %name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
160 wxPyFileSystemHandler();
162 void _setSelf(PyObject* self, PyObject* _class);
163 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxFileSystemHandler)"
165 bool CanOpen(const wxString& location);
166 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
167 wxString FindFirst(const wxString& spec, int flags = 0);
170 wxString GetProtocol(const wxString& location);
171 wxString GetLeftLocation(const wxString& location);
172 wxString GetAnchor(const wxString& location);
173 wxString GetRightLocation(const wxString& location) const;
174 wxString GetMimeTypeFromExt(const wxString& location);
177 //---------------------------------------------------------------------------
183 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
186 wxFSFile* OpenFile(const wxString& location);
188 wxString FindFirst(const wxString& spec, int flags = 0);
191 static void AddHandler(wxFileSystemHandler *handler);
192 static void CleanUpHandlers();
195 //---------------------------------------------------------------------------
197 class wxInternetFSHandler : public wxFileSystemHandler {
199 wxInternetFSHandler();
200 bool CanOpen(const wxString& location);
201 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
205 //---------------------------------------------------------------------------
206 class wxZipFSHandler : public wxFileSystemHandler {
210 bool CanOpen(const wxString& location);
211 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
212 wxString FindFirst(const wxString& spec, int flags = 0);
216 //---------------------------------------------------------------------------
218 class wxMemoryFSHandler : public wxFileSystemHandler {
222 // Remove file from memory FS and free occupied memory
223 static void RemoveFile(const wxString& filename);
225 bool CanOpen(const wxString& location);
226 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
227 wxString FindFirst(const wxString& spec, int flags = 0);
228 virtual wxString FindNext();
232 // getting the overloaded static AddFile method right
234 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
237 wxMemoryFSHandler::AddFile(filename, image, type);
240 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
241 const wxBitmap& bitmap,
243 wxMemoryFSHandler::AddFile(filename, bitmap, type);
246 // void __wxMemoryFSHandler_AddFile_wxString(const wxString& filename,
247 // const wxString& textdata) {
248 // wxMemoryFSHandler::AddFile(filename, textdata);
251 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
254 wxMemoryFSHandler::AddFile(filename,
255 (void*)PyString_AsString(data),
256 (size_t)PyString_Size(data));
261 // case switch for overloading
262 %pragma(python) code = "
264 def wxMemoryFSHandler_AddFile(filename, a, b=''):
265 if isinstance(a, wxImage):
266 __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
267 elif isinstance(a, wxBitmap):
268 __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
269 elif type(a) == types.StringType:
270 #__wxMemoryFSHandler_AddFile_wxString(filename, a)
271 __wxMemoryFSHandler_AddFile_Data(filename, a)
272 else: raise TypeError, 'wxImage, wxBitmap or string expected'
276 //---------------------------------------------------------------------------