1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG definitions of the wxFileSystem family of classes
 
   5 // Author:      Joerg Baumann and Robin Dunn
 
   7 // Created:     25-Sept-2000
 
   9 // Copyright:   (c) 2000 by Joerg Baumann
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  17 #include "pyistream.h"
 
  18 #include <wx/filesys.h>
 
  19 #include <wx/fs_inet.h>
 
  20 #include <wx/fs_mem.h>
 
  21 #include <wx/fs_zip.h>
 
  24 //----------------------------------------------------------------------
 
  27 %include my_typemaps.i
 
  29 // Import some definitions of other classes, etc.
 
  35 %pragma(python) code = "import wx"
 
  36 %pragma(python) code = "import string"
 
  38 //---------------------------------------------------------------------------
 
  41 class wxFSFile : public wxObject {
 
  43     wxFSFile(wxInputStream *stream, const wxString& loc,
 
  44              const wxString& mimetype, const wxString& anchor,
 
  47     wxInputStream *GetStream();
 
  48     const wxString& GetMimeType();
 
  49     const wxString& GetLocation();
 
  50     const wxString& GetAnchor();
 
  51     wxDateTime GetModificationTime();
 
  56 %typemap(python,in)  wxInputStream *stream;
 
  57 %typemap(python,out) wxInputStream *;
 
  60 //---------------------------------------------------------------------------
 
  63 // wxPyFileSystemHandler will be the Python class wxFileSystemHandler and handling
 
  64 // the callback functions
 
  65 class wxPyFileSystemHandler : public wxFileSystemHandler {
 
  67     wxPyFileSystemHandler() : wxFileSystemHandler() {}
 
  69     DEC_PYCALLBACK_BOOL_STRING_pure(CanOpen);
 
  70     DEC_PYCALLBACK_FSF_FSSTRING_pure(OpenFile);
 
  71     DEC_PYCALLBACK_STRING_STRINGINT_pure(FindFirst);
 
  72     DEC_PYCALLBACK_STRING__pure(FindNext);
 
  74     wxString GetProtocol(const wxString& location) {
 
  75         return wxFileSystemHandler::GetProtocol(location);
 
  78     wxString GetLeftLocation(const wxString& location) {
 
  79         return wxFileSystemHandler::GetLeftLocation(location);
 
  82     wxString GetAnchor(const wxString& location) {
 
  83         return wxFileSystemHandler::GetAnchor(location);
 
  86     wxString GetRightLocation(const wxString& location) {
 
  87         return wxFileSystemHandler::GetRightLocation(location);
 
  90     wxString GetMimeTypeFromExt(const wxString& location) {
 
  91         return wxFileSystemHandler::GetMimeTypeFromExt(location);
 
  98 IMP_PYCALLBACK_BOOL_STRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, CanOpen);
 
  99 IMP_PYCALLBACK_FSF_FSSTRING_pure(wxPyFileSystemHandler, wxFileSystemHandler, OpenFile);
 
 100 IMP_PYCALLBACK_STRING_STRINGINT_pure(wxPyFileSystemHandler, wxFileSystemHandler, FindFirst);
 
 101 IMP_PYCALLBACK_STRING__pure(wxPyFileSystemHandler, wxFileSystemHandler, FindNext);
 
 105 %name(wxCPPFileSystemHandler)class wxFileSystemHandler : public wxObject {
 
 106     wxFileSystemHandler();
 
 109 %name(wxFileSystemHandler)class wxPyFileSystemHandler : public wxFileSystemHandler {
 
 111     wxPyFileSystemHandler();
 
 113     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 114     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFileSystemHandler)"
 
 116     bool CanOpen(const wxString& location);
 
 117     wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
 
 118     wxString FindFirst(const wxString& spec, int flags = 0);
 
 121     wxString GetProtocol(const wxString& location);
 
 122     wxString GetLeftLocation(const wxString& location);
 
 123     wxString GetAnchor(const wxString& location);
 
 124     wxString GetRightLocation(const wxString& location) const;
 
 125     wxString GetMimeTypeFromExt(const wxString& location);
 
 128 //---------------------------------------------------------------------------
 
 130 class wxFileSystem : public wxObject {
 
 134     void ChangePathTo(const wxString& location, bool is_dir = FALSE);
 
 137     wxFSFile* OpenFile(const wxString& location);
 
 139     wxString FindFirst(const wxString& spec, int flags = 0);
 
 142     static void AddHandler(wxFileSystemHandler *handler);
 
 143     static void CleanUpHandlers();
 
 146 //---------------------------------------------------------------------------
 
 148 class wxInternetFSHandler : public wxFileSystemHandler {
 
 150     wxInternetFSHandler();
 
 151     bool CanOpen(const wxString& location);
 
 152     wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
 
 156 //---------------------------------------------------------------------------
 
 157 class wxZipFSHandler : public wxFileSystemHandler {
 
 161     bool CanOpen(const wxString& location);
 
 162     wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
 
 163     wxString FindFirst(const wxString& spec, int flags = 0);
 
 167 //---------------------------------------------------------------------------
 
 169 class wxMemoryFSHandler : public wxFileSystemHandler {
 
 173     // Remove file from memory FS and free occupied memory
 
 174     static void RemoveFile(const wxString& filename);
 
 176     bool CanOpen(const wxString& location);
 
 177     wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location);
 
 178     wxString FindFirst(const wxString& spec, int flags = 0);
 
 179     virtual wxString FindNext();
 
 183 // getting the overloaded static AddFile method right
 
 185 void __wxMemoryFSHandler_AddFile_wxImage(const wxString& filename,
 
 188     wxMemoryFSHandler::AddFile(filename, image, type);
 
 191 void __wxMemoryFSHandler_AddFile_wxBitmap(const wxString& filename,
 
 192                                           const wxBitmap& bitmap,
 
 194     wxMemoryFSHandler::AddFile(filename, bitmap, type);
 
 197 void __wxMemoryFSHandler_AddFile_Data(const wxString& filename,
 
 200     wxMemoryFSHandler::AddFile(filename,
 
 201                                // TODO:  Verify data type
 
 202                                (void*)PyString_AsString(data),
 
 203                                (size_t)PyString_Size(data));
 
 208 // case switch for overloading
 
 209 %pragma(python) code = "
 
 211 def wxMemoryFSHandler_AddFile(filename, a, b=''):
 
 212     if isinstance(a, wxImage):
 
 213         __wxMemoryFSHandler_AddFile_wxImage(filename, a, b)
 
 214     elif isinstance(a, wxBitmap):
 
 215         __wxMemoryFSHandler_AddFile_wxBitmap(filename, a, b)
 
 216     elif type(a) == types.StringType:
 
 217         #__wxMemoryFSHandler_AddFile_wxString(filename, a)
 
 218         __wxMemoryFSHandler_AddFile_Data(filename, a)
 
 219     else: raise TypeError, 'wxImage, wxBitmap or string expected'
 
 223 //---------------------------------------------------------------------------
 
 226     wxPyPtrTypeMap_Add("wxFileSystemHandler", "wxPyFileSystemHandler");
 
 229 //---------------------------------------------------------------------------