Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / ext / richtext / XS / RichTextFileHandler.xsp
1 #############################################################################
2 ## Name:        ext/richtext/XS/RichTextFileHandler.xsp
3 ## Purpose:     XS++ for Wx::RichTextFileHandler
4 ## Author:      Mattia Barbon
5 ## Modified by:
6 ## Created:     03/09/2007
7 ## RCS-ID:      $Id: RichTextFileHandler.xsp 2229 2007-09-05 22:21:15Z mbarbon $
8 ## Copyright:   (c) 2007 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 #include <wx/event.h>
14 #include <wx/richtext/richtextbuffer.h>
15
16 %module{Wx};
17
18 %file{cpp/filehandler.h};
19 %{
20
21 #include "cpp/v_cback.h"
22 #include "cpp/streams.h"
23
24 #define DEF_V_CBACK_BOOL__WXRICHTEXTBUFFER_WXINPUTSTREAM( CLASS, BASE, METHOD )\
25     bool CLASS::METHOD( wxRichTextBuffer* p1, wxInputStream& p2 )            \
26     {                                                                        \
27         dTHX;                                                                \
28         if( wxPliFCback( aTHX_ &m_callback, #METHOD ) )                      \
29         {                                                                    \
30             wxAutoSV stream( aTHX_ sv_newmortal() );                         \
31             wxPli_stream_2_sv( aTHX_ stream, &p2, "Wx::InputStream" );       \
32             wxAutoSV ret( aTHX_ wxPliCCback( aTHX_ &m_callback,              \
33                                              G_SCALAR,                       \
34                                              "Qs", p1, (SV*)stream ) );      \
35             return SvTRUE( ret );                                            \
36         } else                                                               \
37             return false;                                                    \
38     }
39
40 #define DEF_V_CBACK_BOOL__WXRICHTEXTBUFFER_WXOUTPUTSTREAM( CLASS, BASE, METHOD )\
41     bool CLASS::METHOD( wxRichTextBuffer* p1, wxOutputStream& p2 )           \
42     {                                                                        \
43         dTHX;                                                                \
44         if( wxPliFCback( aTHX_ &m_callback, #METHOD ) )                      \
45         {                                                                    \
46             wxAutoSV stream( aTHX_ sv_newmortal() );                         \
47             wxPli_stream_2_sv( aTHX_ stream, &p2, "Wx::OutputStream" );      \
48             wxAutoSV ret( aTHX_ wxPliCCback( aTHX_ &m_callback,              \
49                                              G_SCALAR,                       \
50                                              "Qs", p1, (SV*)stream ) );      \
51             return SvTRUE( ret );                                            \
52         } else                                                               \
53             return false;                                                    \
54     }
55
56 class wxPlRichTextFileHandler : public wxRichTextFileHandler
57 {
58     WXPLI_DECLARE_V_CBACK();
59 public:
60     wxPlRichTextFileHandler( const char* package,
61                              const wxString& name = wxEmptyString,
62                              const wxString& ext = wxEmptyString,
63                              int type = 0 )
64       : wxRichTextFileHandler( name, ext, type ),
65         m_callback( "Wx::RichTextFileHandler" )
66     {
67         m_callback.SetSelf( wxPli_make_object( this, package ), true );
68     }
69
70     bool base_CanHandle( const wxString& filename )
71         { return wxRichTextFileHandler::CanHandle( filename ); }
72     bool base_CanLoad()
73         { return wxRichTextFileHandler::CanLoad(); }
74     bool base_CanSave()
75         { return wxRichTextFileHandler::CanSave(); }
76
77     DEC_V_CBACK_BOOL__WXSTRING( CanHandle );
78     DEC_V_CBACK_BOOL__VOID( CanLoad );
79     DEC_V_CBACK_BOOL__VOID( CanSave );
80
81     bool DoLoadFile( wxRichTextBuffer *buffer, wxInputStream& stream );
82     bool DoSaveFile( wxRichTextBuffer *buffer, wxOutputStream& stream );
83 };
84
85 DEF_V_CBACK_BOOL__WXSTRING( wxPlRichTextFileHandler,
86                             wxRichTextFileHandler, CanHandle );
87 DEF_V_CBACK_BOOL__VOID( wxPlRichTextFileHandler,
88                         wxRichTextFileHandler, CanLoad );
89 DEF_V_CBACK_BOOL__VOID( wxPlRichTextFileHandler,
90                         wxRichTextFileHandler, CanSave );
91 DEF_V_CBACK_BOOL__WXRICHTEXTBUFFER_WXINPUTSTREAM( wxPlRichTextFileHandler,
92                                                   wxRichTextFileHandler,
93                                                   DoLoadFile );
94 DEF_V_CBACK_BOOL__WXRICHTEXTBUFFER_WXOUTPUTSTREAM( wxPlRichTextFileHandler,
95                                                    wxRichTextFileHandler,
96                                                    DoSaveFile );
97 %}
98 %file{-};
99
100 #include "cpp/filehandler.h"
101
102 %name{Wx::RichTextFileHandler} class wxRichTextFileHandler
103 {
104     bool CanHandle( const wxString& filename ) const;
105     bool CanLoad() const;
106     bool CanSave() const;
107
108     bool LoadFile( wxRichTextBuffer* buffer, SV* fh )
109         %code{% wxInputStream* stream = wxPliInputStream_ctor( fh );
110                 RETVAL = THIS->LoadFile( buffer, *stream );
111                 delete stream;
112                 %};
113     bool SaveFile( wxRichTextBuffer* buffer, SV* fh )
114         %code{% wxOutputStream* stream = wxPliOutputStream_ctor( fh );
115                 RETVAL = THIS->SaveFile( buffer, *stream );
116                 delete stream;
117                 %};
118
119     void SetName( const wxString& name );
120     wxString GetName() const;
121     void SetExtension( const wxString& ext );
122     wxString GetExtension() const;
123     void SetType( int type );
124     int GetType();
125     void SetEncoding( const wxString& encoding );
126     wxString GetEncoding() const;
127     bool IsVisible() const;
128     void SetVisible( bool visible );
129 };
130
131 %name{Wx::PlRichTextFileHandler} class wxPlRichTextFileHandler
132 {
133     wxPlRichTextFilehandler( const wxString& name = wxEmptyString,
134                              const wxString& ext = wxEmptyString,
135                              int type = 0 )
136         %code{% RETVAL = new wxPlRichTextFileHandler( CLASS, name, ext, type );
137                 %};
138
139     %name{CanHandle} bool base_CanHandle( const wxString& filename ) const;
140     %name{CanLoad} bool base_CanLoad() const;
141     %name{CanSave} bool base_CanSave() const;
142 };
143
144 #include <wx/richtext/richtextxml.h>
145
146 %typemap{wxRichTextXMLHandler*}{simple};
147
148 %name{Wx::RichTextXMLHandler} class wxRichTextXMLHandler
149 {
150     wxRichTextXMLHandler( const wxString& name = wxT("XML"),
151                           const wxString& ext = wxT("xml"),
152                           int type = wxRICHTEXT_TYPE_XML );
153 };
154
155 #if WXPERL_W_VERSION_GE( 2, 8, 3 )
156
157 #include <wx/richtext/richtexthtml.h>
158
159 %typemap{wxRichTextHTMLHandler*}{simple};
160
161 %name{Wx::RichTextHTMLHandler} class wxRichTextHTMLHandler
162 {
163     wxRichTextHTMLHandler( const wxString& name = wxT("HTML"),
164                            const wxString& ext = wxT("html"),
165                            int type = wxRICHTEXT_TYPE_HTML );
166
167     void ClearTemporaryImageLocations();
168 %{
169 bool
170 wxRichTextHTMLHandler::DeleteTemporaryImages( ... )
171   CASE: items == 2
172     INPUT:
173     CODE:
174       int flags = SvIV( ST(1) );
175       wxArrayString imageLocations;
176       wxPli_av_2_arraystring( aTHX_ ST(2), &imageLocations );
177       RETVAL = THIS->DeleteTemporaryImages( flags, imageLocations );
178     OUTPUT: RETVAL
179   CASE:
180     CODE:
181       RETVAL = THIS->DeleteTemporaryImages();
182     OUTPUT:RETVAL
183
184 void
185 wxRichTextHTMLHandler::GetFontSizeMapping()
186   PPCODE:
187     PUTBACK;
188     wxPli_intarray_push( aTHX_ THIS->GetFontSizeMapping() );
189     SPAGAIN;
190
191 void
192 wxRichTextHTMLHandler::GetTemporaryImageLocations()
193   PPCODE:
194     PUTBACK;
195     wxPli_stringarray_push( aTHX_ THIS->GetTemporaryImageLocations() );
196     SPAGAIN;
197
198 %}
199
200     const wxString& GetTempDir() const;
201     void SetFileCounter( int counter );
202     void SetFontSizeMapping( const wxArrayInt& fontSizeMapping );
203     void SetTempDir( const wxString& tempDir );
204     void SetTemporaryImageLocations( const wxArrayString& locations );
205 };
206
207 #endif