Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / ext / filesys / cpp / fshandler.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        ext/filesys/cpp/fshandler.h
3 // Purpose:     C++ classes for Wx::PlFSFile and Wx::PlFileSystemHandler
4 // Author:      Mattia Barbon
5 // Modified by:
6 // Created:     17/04/2002
7 // RCS-ID:      $Id: fshandler.h 2057 2007-06-18 23:03:00Z mbarbon $
8 // Copyright:   (c) 2002, 2004 Mattia Barbon
9 // Licence:     This program is free software; you can redistribute it and/or
10 //              modify it under the same terms as Perl itself
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WXPERL_FS_FSHANDLER_H
14 #define _WXPERL_FS_FSHANDLER_H
15
16 #include <wx/filesys.h>
17 #include "cpp/streams.h"
18 #include "cpp/v_cback.h"
19
20 class wxPlFSFile:public wxFSFile
21 {
22 public:
23     wxPlFSFile( SV* fh, const wxString& loc, const wxString& mimetype,
24                 const wxString& anchor )
25         : wxFSFile( wxPliInputStream_ctor( fh ),
26                     loc, mimetype, anchor, wxDateTime() ) { }
27 };
28
29 class wxPlFileSystemHandler:public wxFileSystemHandler
30 {
31     WXPLI_DECLARE_DYNAMIC_CLASS( wxPlFileSystemHandler );
32     WXPLI_DECLARE_V_CBACK();
33 public:
34     wxPlFileSystemHandler( const char* package )
35         : m_callback( "Wx::PlFileSystemHandler" )
36     {
37         m_callback.SetSelf( wxPli_make_object( this, package ), true );
38     }
39
40     DEC_V_CBACK_BOOL__WXSTRING( CanOpen );
41     DEC_V_CBACK_WXSTRING__WXSTRING_INT( FindFirst );
42     DEC_V_CBACK_WXSTRING__VOID( FindNext );
43     DEC_V_CBACK_WXFSFILEP__WXFILESYSTEM_WXSTRING( OpenFile );
44 };
45
46 WXPLI_IMPLEMENT_DYNAMIC_CLASS( wxPlFileSystemHandler, wxFileSystemHandler );
47
48 DEF_V_CBACK_WXSTRING__VOID_pure( wxPlFileSystemHandler, wxFileSystemHandler,
49                                  FindNext );
50 DEF_V_CBACK_BOOL__WXSTRING_pure( wxPlFileSystemHandler, wxFileSystemHandler,
51                                  CanOpen );
52
53 wxString wxPlFileSystemHandler::FindFirst( const wxString& file, int flags )
54 {
55     dTHX;
56     if( wxPliVirtualCallback_FindCallback( aTHX_ &m_callback, "FindFirst" ) )
57     {
58         SV* ret = wxPliVirtualCallback_CallCallback( aTHX_ &m_callback,
59                                                      G_SCALAR,
60                                                      "Pi", &file, flags );
61         wxString val;
62         WXSTRING_INPUT( val, wxString, ret );
63         SvREFCNT_dec( ret );
64         return val;
65     }
66     return wxEmptyString;
67 }
68
69 #include     <wx/wfstream.h>
70
71 wxFSFile* wxPlFileSystemHandler::OpenFile( wxFileSystem& parent,
72                                            const wxString& name )
73 {
74     dTHX;
75     if( wxPliVirtualCallback_FindCallback( aTHX_ &m_callback, "OpenFile" ) )
76     {
77         SV* fs = wxPli_object_2_sv( aTHX_ sv_newmortal(), &parent );
78         SV* ret = wxPliVirtualCallback_CallCallback( aTHX_ &m_callback,
79                                                      G_SCALAR,
80                                                      "sP", fs, &name );
81         wxFSFile* val = (wxFSFile*)wxPli_sv_2_object( aTHX_ ret,
82                                                       "Wx::FSFile" );
83         sv_setiv( SvRV( fs ), 0 );
84         if( SvROK( ret ) )
85             sv_setiv( SvRV( ret ), 0 );
86         SvREFCNT_dec( ret );
87
88         return val;
89     }
90     return 0;
91 }
92
93 #endif
94
95 // local variables:
96 // mode: c++
97 // end: