]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_filesys.i
fixed crash in <sub/sup> handling (bug #1545152)
[wxWidgets.git] / wxPython / src / _filesys.i
CommitLineData
c368d904 1/////////////////////////////////////////////////////////////////////////////
d14a1e28 2// Name: _filesys.i
c368d904
RD
3// Purpose: SWIG definitions of the wxFileSystem family of classes
4//
d14a1e28 5// Author: Robin Dunn
c368d904
RD
6//
7// Created: 25-Sept-2000
8// RCS-ID: $Id$
d14a1e28 9// Copyright: (c) 2003 by Total Control Software
c368d904
RD
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
d14a1e28 13// Not a %module
c368d904 14
c368d904 15
d14a1e28 16//---------------------------------------------------------------------------
c368d904 17
d14a1e28
RD
18%{
19#include "wx/wxPython/pyistream.h"
20%}
c368d904
RD
21
22//---------------------------------------------------------------------------
d14a1e28 23%newgroup
c368d904 24
c368d904 25
d14a1e28
RD
26class wxFSFile : public wxObject
27{
c368d904 28public:
e2e2649f 29 %typemap(out) wxFSFile*; // turn off this typemap
d02ea46c 30
c368d904
RD
31 wxFSFile(wxInputStream *stream, const wxString& loc,
32 const wxString& mimetype, const wxString& anchor,
33 wxDateTime modif);
e2e2649f
RD
34
35 // Turn it back on.
36 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); }
37
38 ~wxFSFile();
c368d904
RD
39
40 wxInputStream *GetStream();
41 const wxString& GetMimeType();
42 const wxString& GetLocation();
43 const wxString& GetAnchor();
44 wxDateTime GetModificationTime();
45};
46
47
c368d904
RD
48//---------------------------------------------------------------------------
49
50%{
d14a1e28
RD
51class wxPyFileSystemHandler : public wxFileSystemHandler
52{
c368d904
RD
53public:
54 wxPyFileSystemHandler() : wxFileSystemHandler() {}
55
56 DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
57 DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
58 DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
59 DEC_PYCALLBACK_STRING__pure(FindNext);
60
61 wxString GetProtocol(const wxString& location) {
62 return wxFileSystemHandler::GetProtocol(location);
63 }
64
65 wxString GetLeftLocation(const wxString& location) {
66 return wxFileSystemHandler::GetLeftLocation(location);
67 }
68
69 wxString GetAnchor(const wxString& location) {
70 return wxFileSystemHandler::GetAnchor(location);
71 }
72
73 wxString GetRightLocation(const wxString& location) {
74 return wxFileSystemHandler::GetRightLocation(location);
75 }
76
e9159fe8 77 wxString GetMimeTypeFromExt(const wxString& location) {
c368d904
RD
78 return wxFileSystemHandler::GetMimeTypeFromExt(location);
79 }
80
81 PYPRIVATE;
82};
83
84
85IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
86IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
87IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
88IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
89%}
90
91
c368d904 92
1b8c7ba6
RD
93%rename(CPPFileSystemHandler) wxFileSystemHandler;
94class wxFileSystemHandler //: public wxObject
d14a1e28
RD
95{
96public:
97 //wxFileSystemHandler();
cdd7b180 98 ~wxFileSystemHandler();
d14a1e28
RD
99};
100
101
102
1b8c7ba6
RD
103%rename(FileSystemHandler) wxPyFileSystemHandler;
104class wxPyFileSystemHandler : public wxFileSystemHandler
d14a1e28 105{
c368d904 106public:
2b9048c5 107 %pythonAppend wxPyFileSystemHandler "self._setCallbackInfo(self, FileSystemHandler)";
e2e2649f 108
c368d904
RD
109 wxPyFileSystemHandler();
110
0122b7e3 111 void _setCallbackInfo(PyObject* self, PyObject* _class);
c368d904
RD
112
113 bool CanOpen(const wxString& location);
b87bfdb7 114 %newobject OpenFile;
c368d904
RD
115 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
116 wxString FindFirst(const wxString& spec, int flags = 0);
117 wxString FindNext();
118
119 wxString GetProtocol(const wxString& location);
120 wxString GetLeftLocation(const wxString& location);
121 wxString GetAnchor(const wxString& location);
d14a1e28 122 wxString GetRightLocation(const wxString& location);
c368d904
RD
123 wxString GetMimeTypeFromExt(const wxString& location);
124};
125
d14a1e28
RD
126
127// //---------------------------------------------------------------------------
128
c368d904 129
9416aa89 130class wxFileSystem : public wxObject {
c368d904
RD
131public:
132 wxFileSystem();
d14a1e28 133 ~wxFileSystem();
c368d904 134
a72f4631 135 void ChangePathTo(const wxString& location, bool is_dir = false);
c368d904
RD
136 wxString GetPath();
137
b87bfdb7 138 %newobject OpenFile;
c368d904
RD
139 wxFSFile* OpenFile(const wxString& location);
140
141 wxString FindFirst(const wxString& spec, int flags = 0);
142 wxString FindNext();
143
cdd7b180 144 %disownarg(wxFileSystemHandler *handler);
c368d904 145 static void AddHandler(wxFileSystemHandler *handler);
cdd7b180 146 %cleardisown(wxFileSystemHandler *handler);
e2e2649f 147
c368d904 148 static void CleanUpHandlers();
1e4a197e 149
dd116e73
RD
150 // Returns the file URL for a native path
151 static wxString FileNameToURL(const wxString& filename);
1e4a197e 152
dd116e73 153 // Returns the native path for a file URL
7e6581d4
RD
154 //static wxFileName URLToFileName(const wxString& url);
155 %extend {
156 static wxString URLToFileName(const wxString& url) {
157 wxFileName fname = wxFileSystem::URLToFileName(url);
158 return fname.GetFullPath();
159 }
e2e2649f 160 }
c368d904
RD
161};
162
dd116e73 163
d14a1e28 164
c368d904
RD
165//---------------------------------------------------------------------------
166
167class wxInternetFSHandler : public wxFileSystemHandler {
168public:
169 wxInternetFSHandler();
170 bool CanOpen(const wxString& location);
b87bfdb7 171 %newobject OpenFile;
c368d904
RD
172 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
173};
174
175
176//---------------------------------------------------------------------------
d14a1e28 177
c368d904
RD
178class wxZipFSHandler : public wxFileSystemHandler {
179public:
180 wxZipFSHandler();
181
182 bool CanOpen(const wxString& location);
b87bfdb7 183 %newobject OpenFile;
c368d904
RD
184 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
185 wxString FindFirst(const wxString& spec, int flags = 0);
186 wxString FindNext();
187};
188
189//---------------------------------------------------------------------------
190
d14a1e28 191// TODO: Use SWIG's overloading feature to fix this mess?
c368d904
RD
192
193// getting the overloaded static AddFile method right
194%inline %{
d14a1e28
RD
195 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
196 wxImage& image,
197 long type) {
198 wxMemoryFSHandler::AddFile(filename, image, type);
199 }
c368d904 200
d14a1e28
RD
201 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
202 const wxBitmap& bitmap,
203 long type) {
204 wxMemoryFSHandler::AddFile(filename, bitmap, type);
205 }
c368d904 206
d14a1e28
RD
207 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
208 PyObject* data) {
7e6581d4
RD
209 if (! PyString_Check(data)) {
210 wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError,
211 "Expected string object"));
212 return;
213 }
214
6e6b3557 215 wxPyBlock_t blocked = wxPyBeginBlockThreads();
7e6581d4
RD
216 void* ptr = (void*)PyString_AsString(data);
217 size_t size = PyString_Size(data);
218 wxPyEndBlockThreads(blocked);
219
220 wxMemoryFSHandler::AddFile(filename, ptr, size);
d14a1e28 221 }
c368d904
RD
222%}
223
224
225// case switch for overloading
d14a1e28 226%pythoncode {
7e6581d4
RD
227def MemoryFSHandler_AddFile(filename, dataItem, imgType=-1):
228 """
229 Add 'file' to the memory filesystem. The dataItem parameter can
230 either be a `wx.Bitmap`, `wx.Image` or a string that can contain
231 arbitrary data. If a bitmap or image is used then the imgType
232 parameter should specify what kind of image file it should be
233 written as, wx.BITMAP_TYPE_PNG, etc.
234 """
235 if isinstance(dataItem, wx.Image):
236 __wxMemoryFSHandler_AddFile_wxImage(filename, dataItem, imgType)
237 elif isinstance(dataItem, wx.Bitmap):
238 __wxMemoryFSHandler_AddFile_wxBitmap(filename, dataItem, imgType)
239 elif type(dataItem) == str:
240 __wxMemoryFSHandler_AddFile_Data(filename, dataItem)
241 else:
242 raise TypeError, 'wx.Image, wx.Bitmap or string expected'
d14a1e28 243}
c368d904
RD
244
245
d14a1e28
RD
246class wxMemoryFSHandler : public wxFileSystemHandler {
247public:
248 wxMemoryFSHandler();
249
250 // Remove file from memory FS and free occupied memory
251 static void RemoveFile(const wxString& filename);
252
253 // Add a file to the memory FS
254 %pythoncode { AddFile = staticmethod(MemoryFSHandler_AddFile) }
e2e2649f 255
d14a1e28 256 bool CanOpen(const wxString& location);
b87bfdb7 257 %newobject OpenFile;
d14a1e28
RD
258 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
259 wxString FindFirst(const wxString& spec, int flags = 0);
260 virtual wxString FindNext();
261};
9416aa89 262
d14a1e28
RD
263
264//---------------------------------------------------------------------------
9416aa89
RD
265%init %{
266 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
267%}
c368d904 268//---------------------------------------------------------------------------