]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/filesys.i
Don't create a bitmap with dimensions <= 0...
[wxWidgets.git] / wxPython / src / filesys.i
CommitLineData
c368d904
RD
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
de20db99
RD
78// PyObject* one = PyInt_FromLong(1);
79// PyObject_SetAttrString($target, "thisown", one);
80// Py_DECREF(one);
c368d904
RD
81// }
82// } else {
83// Py_INCREF(Py_None);
84// $target = Py_None;
85// }
86// }
87
88
89
9416aa89 90class wxFSFile : public wxObject {
c368d904
RD
91public:
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
114class wxPyFileSystemHandler : public wxFileSystemHandler {
115public:
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
147IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
148IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
149IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
150IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
151%}
152
153
9416aa89
RD
154%name(wxCPPFileSystemHandler)class wxFileSystemHandler : public wxObject {
155 wxFileSystemHandler();
c368d904
RD
156}
157
158%name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
159public:
160 wxPyFileSystemHandler();
161
162 void _setSelf(PyObject* self, PyObject* _class);
163 %pragma(python) addtomethod = "__init__:self._setSelf(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
9416aa89 179class wxFileSystem : public wxObject {
c368d904
RD
180public:
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
197class wxInternetFSHandler : public wxFileSystemHandler {
198public:
199 wxInternetFSHandler();
200 bool CanOpen(const wxString& location);
201 wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
202};
203
204
205//---------------------------------------------------------------------------
206class wxZipFSHandler : public wxFileSystemHandler {
207public:
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
218class wxMemoryFSHandler : public wxFileSystemHandler {
219public:
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 %{
234void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
235 wxImage& image,
236 long type) {
237 wxMemoryFSHandler::AddFile(filename, image, type);
238}
239
240void __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
251void __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 = "
263import types
264def 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
9416aa89
RD
276//---------------------------------------------------------------------------
277
278%init %{
279 wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
280%}
281
c368d904 282//---------------------------------------------------------------------------