]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/filesys.i
d&d implementation and checklistbox enabled
[wxWidgets.git] / wxPython / src / filesys.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filesys.i
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
4 //
5 // Author: Joerg Baumann
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module filesys
14
15 %{
16 #include "helpers.h"
17 #include <wx/filesys.h>
18 #include <wx/fs_inet.h>
19 #include <wx/fs_mem.h>
20 #include <wx/fs_zip.h>
21 %}
22
23 //----------------------------------------------------------------------
24
25 %include typemaps.i
26 %include my_typemaps.i
27
28 // Import some definitions of other classes, etc.
29 %import _defs.i
30 %import utils.i
31 %import image.i
32 %import streams.i
33
34 %pragma(python) code = "import wx"
35 %pragma(python) code = "import string"
36
37 //---------------------------------------------------------------------------
38
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.");
46 // return NULL;
47 // }
48 // $target = ptr->wxi;
49 // } else {
50 // PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p.");
51 // return NULL;
52 // }
53 // }
54
55
56 // // typemaps for wxInputStream: Note wxFSFile object has to do the delete
57 // // of wxInputStream *
58 // %typemap(python,out) wxInputStream* {
59 // wxPyInputStream * _ptr = NULL;
60
61 // if ($source) {
62 // _ptr = new wxPyInputStream($source);
63 // }
64 // if (_ptr) {
65 // char swigptr[64];
66 // SWIG_MakePtr(swigptr, _ptr, "_wxPyInputStream_p");
67
68 // PyObject* classobj = PyDict_GetItemString(wxPython_dict, "wxInputStreamPtr");
69 // if (! classobj) {
70 // Py_INCREF(Py_None);
71 // $target = Py_None;
72 // } else {
73 // PyObject* arg = Py_BuildValue("(s)", swigptr);
74 // $target = PyInstance_New(classobj, arg, NULL);
75 // Py_DECREF(arg);
76
77 // // set ThisOwn
78 // PyObject* one = PyInt_FromLong(1);
79 // PyObject_SetAttrString($target, "thisown", one);
80 // Py_DECREF(one);
81 // }
82 // } else {
83 // Py_INCREF(Py_None);
84 // $target = Py_None;
85 // }
86 // }
87
88
89
90 class wxFSFile : public wxObject {
91 public:
92 wxFSFile(wxInputStream *stream, const wxString& loc,
93 const wxString& mimetype, const wxString& anchor,
94 wxDateTime modif);
95
96 wxInputStream *GetStream();
97 const wxString& GetMimeType();
98 const wxString& GetLocation();
99 const wxString& GetAnchor();
100 wxDateTime GetModificationTime();
101 };
102
103
104 // clear typemaps
105 %typemap(python,in) wxInputStream *stream;
106 %typemap(python,out) wxInputStream *;
107
108
109 //---------------------------------------------------------------------------
110
111 %{
112 // wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
113 // the callback functions
114 class wxPyFileSystemHandler : public wxFileSystemHandler {
115 public:
116 wxPyFileSystemHandler() : wxFileSystemHandler() {}
117
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);
122
123 wxString GetProtocol(const wxString& location) {
124 return wxFileSystemHandler::GetProtocol(location);
125 }
126
127 wxString GetLeftLocation(const wxString& location) {
128 return wxFileSystemHandler::GetLeftLocation(location);
129 }
130
131 wxString GetAnchor(const wxString& location) {
132 return wxFileSystemHandler::GetAnchor(location);
133 }
134
135 wxString GetRightLocation(const wxString& location) {
136 return wxFileSystemHandler::GetRightLocation(location);
137 }
138
139 wxString GetMimeTypeFromExt(const wxString& location){
140 return wxFileSystemHandler::GetMimeTypeFromExt(location);
141 }
142
143 PYPRIVATE;
144 };
145
146
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);
151 %}
152
153
154 %name(wxCPPFileSystemHandler)class wxFileSystemHandler : public wxObject {
155 wxFileSystemHandler();
156 }
157
158 %name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
159 public:
160 wxPyFileSystemHandler();
161
162 void _setCallbackInfo(PyObject* self, PyObject* _class);
163 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileSystemHandler)"
164
165 bool CanOpen(const wxString& location);
166 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
167 wxString FindFirst(const wxString& spec, int flags = 0);
168 wxString FindNext();
169
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);
175 };
176
177 //---------------------------------------------------------------------------
178
179 class wxFileSystem : public wxObject {
180 public:
181 wxFileSystem();
182
183 void ChangePathTo(const wxString& location, bool is_dir = FALSE);
184 wxString GetPath();
185
186 wxFSFile* OpenFile(const wxString& location);
187
188 wxString FindFirst(const wxString& spec, int flags = 0);
189 wxString FindNext();
190
191 static void AddHandler(wxFileSystemHandler *handler);
192 static void CleanUpHandlers();
193 };
194
195 //---------------------------------------------------------------------------
196
197 class wxInternetFSHandler : public wxFileSystemHandler {
198 public:
199 wxInternetFSHandler();
200 bool CanOpen(const wxString& location);
201 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
202 };
203
204
205 //---------------------------------------------------------------------------
206 class wxZipFSHandler : public wxFileSystemHandler {
207 public:
208 wxZipFSHandler();
209
210 bool CanOpen(const wxString& location);
211 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
212 wxString FindFirst(const wxString& spec, int flags = 0);
213 wxString FindNext();
214 };
215
216 //---------------------------------------------------------------------------
217
218 class wxMemoryFSHandler : public wxFileSystemHandler {
219 public:
220 wxMemoryFSHandler();
221
222 // Remove file from memory FS and free occupied memory
223 static void RemoveFile(const wxString& filename);
224
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();
229 };
230
231
232 // getting the overloaded static AddFile method right
233 %inline %{
234 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
235 wxImage& image,
236 long type) {
237 wxMemoryFSHandler::AddFile(filename, image, type);
238 }
239
240 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
241 const wxBitmap& bitmap,
242 long type) {
243 wxMemoryFSHandler::AddFile(filename, bitmap, type);
244 }
245
246 // void __wxMemoryFSHandler_AddFile_wxString(const wxString& filename,
247 // const wxString& textdata) {
248 // wxMemoryFSHandler::AddFile(filename, textdata);
249 // }
250
251 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
252 PyObject* data) {
253
254 wxMemoryFSHandler::AddFile(filename,
255 (void*)PyString_AsString(data),
256 (size_t)PyString_Size(data));
257 }
258 %}
259
260
261 // case switch for overloading
262 %pragma(python) code = "
263 import types
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'
273 "
274
275
276 //---------------------------------------------------------------------------
277
278 %init %{
279 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
280 %}
281
282 //---------------------------------------------------------------------------