Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / XS / MimeTypes.xsp
1 #############################################################################
2 ## Name:        XS/MimeTypes.xsp
3 ## Purpose:     XS++ for wxMimeTypesManager and related classes
4 ## Author:      Mattia Barbon
5 ## Modified by:
6 ## Created:     28/03/2005
7 ## RCS-ID:      $Id: MimeTypes.xsp 2564 2009-05-17 13:02:16Z mbarbon $
8 ## Copyright:   (c) 2005-2009 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 %module{Wx};
14
15 %{
16 #if wxUSE_MIMETYPE
17 #include <wx/mimetype.h>
18 %}
19         
20 %typemap{wxMimeTypesManager*}{simple};
21 %typemap{wxFileType*}{simple};
22 %typemap{wxIconLocation*}{simple};
23 %typemap{wxFileTypeInfo*}{simple};
24 %typemap{const wxFileTypeInfo*}{parsed}{%wxFileTypeInfo*%};
25
26 #if WXPERL_W_VERSION_GE( 2, 5, 2 )
27
28 %name{Wx::IconLocation} class wxIconLocation
29 {
30     bool IsOk() const;
31 };
32
33 #endif
34
35 %name{Wx::FileTypeInfo} class wxFileTypeInfo
36 {
37     bool IsValid() const;
38     void SetIcon( const wxString& iconFile, int iconIndex = 0 );
39     void SetShortDesc( const wxString& shortDesc );
40
41     const wxString& GetMimeType() const;
42     const wxString& GetOpenCommand() const;
43     const wxString& GetPrintCommand() const;
44     const wxString& GetShortDesc() const;
45     const wxString& GetDescription() const;
46     int GetExtensionsCount() const;
47     const wxString& GetIconFile();
48     int GetIconIndex() const;
49 };
50
51 %{
52 wxFileTypeInfo*
53 wxFileTypeInfo::new( strings )
54     wxArrayString strings
55
56 void
57 wxFileTypeInfo::GetExtensions()
58   PPCODE:
59     const wxArrayString& extensions = THIS->GetExtensions();
60     PUTBACK;
61     wxPli_stringarray_push( aTHX_ extensions );
62     SPAGAIN;
63
64 %}
65
66 %name{Wx::FileType} class wxFileType
67 {
68 };
69
70 %{
71 void
72 wxFileType::GetMimeTypes()
73   PREINIT:
74     wxArrayString mimeTypes;
75   PPCODE:
76     bool ok = THIS->GetMimeTypes( mimeTypes );
77     if( ok )
78     {
79         PUTBACK;
80         wxPli_stringarray_push( aTHX_ mimeTypes );
81         SPAGAIN;
82     }
83     else
84         XSRETURN_EMPTY;
85
86 void
87 wxFileType::GetMimeType()
88   PREINIT:
89     wxString mimeType;
90   PPCODE:
91     bool ok = THIS->GetMimeType( &mimeType );
92     if( ok )
93     {
94         XPUSHs( wxPli_wxString_2_sv( aTHX_ mimeType, sv_newmortal() ) );
95     }
96     else
97         XSRETURN_EMPTY;
98
99 void
100 wxFileType::GetExtensions()
101   PREINIT:
102     wxArrayString extensions;
103   PPCODE:
104     bool ok = THIS->GetExtensions( extensions );
105     if( ok )
106     {
107         PUTBACK;
108         wxPli_stringarray_push( aTHX_ extensions );
109         SPAGAIN;
110     }
111     else
112         XSRETURN_EMPTY;
113
114 void
115 wxFileType::GetIcon()
116   PREINIT:
117 #if WXPERL_W_VERSION_GE( 2, 5, 2 )
118     wxIconLocation iconLoc;
119 #else
120     wxIcon iconLoc;
121 #endif
122   PPCODE:
123     bool ok = THIS->GetIcon( &iconLoc );
124     if( ok )
125     {
126 #if WXPERL_W_VERSION_GE( 2, 5, 2 )
127         XPUSHs( wxPli_non_object_2_sv( aTHX_ sv_newmortal(),
128                                        new wxIconLocation( iconLoc ),
129                                        "Wx::IconLocation" ) );
130 #else
131         XPUSHs( wxPli_non_object_2_sv( aTHX_ sv_newmortal(),
132                                        new wxIcon( iconLoc ),
133                                        "Wx::Icon" ) );
134 #endif
135     }
136     else
137         XSRETURN_EMPTY;
138
139 void
140 wxFileType::GetDescription()
141   PREINIT:
142     wxString desc;
143   PPCODE:
144     bool ok = THIS->GetDescription( &desc );
145     if( ok )
146     {
147         XPUSHs( wxPli_wxString_2_sv( aTHX_ desc, sv_newmortal() ) );
148     }
149     else
150         XSRETURN_EMPTY;
151
152 void
153 wxFileType::GetOpenCommand( file, mimeType = wxEmptyString )
154     wxString file
155     wxString mimeType
156   PREINIT:
157     wxString command;
158   PPCODE:
159     bool ok = THIS->GetOpenCommand( &command,
160                                     wxFileType::MessageParameters
161                                         ( file, mimeType ) );
162     if( ok )
163         XPUSHs( wxPli_wxString_2_sv( aTHX_ command, sv_newmortal() ) );
164     else
165         XSRETURN_EMPTY;
166
167 void
168 wxFileType::GetPrintCommand( file, mimeType = wxEmptyString )
169     wxString file
170     wxString mimeType
171   PREINIT:
172     wxString command;
173   PPCODE:
174     bool ok = THIS->GetPrintCommand( &command,
175                                      wxFileType::MessageParameters
176                                          ( file, mimeType ) );
177     if( ok )
178         XPUSHs( wxPli_wxString_2_sv( aTHX_ command, sv_newmortal() ) );
179     else
180         XSRETURN_EMPTY;
181
182 %}
183
184 %name{Wx::MimeTypesManager} class wxMimeTypesManager
185 {
186     wxMimeTypesManager();
187
188 %{
189 static void
190 wxMimeTypesManager::CLONE()
191   CODE:
192     wxPli_thread_sv_clone( aTHX_ CLASS, (wxPliCloneSV)wxPli_detach_object );
193 %}
194     ## // thread OK
195     ~wxMimeTypesManager()
196         %code{% wxPli_thread_sv_unregister( aTHX_ "Wx::MimeTypesManager", THIS, ST(0) );
197                 delete THIS;
198                 %};
199
200     void AddFallbacks( const wxFileTypeInfo *fallbacks );
201     wxFileType* GetFileTypeFromExtension( const wxString& extension );
202     wxFileType* GetFileTypeFromMimeType( const wxString& mimeType );
203     bool IsOfType( const wxString& mimeType, const wxString& wildcard );
204 #if WXPERL_W_VERSION_LT( 2, 9, 0 )
205     bool ReadMailcap( const wxString& filename, bool fallback = false );
206     bool ReadMimeTypes( const wxString& filename );
207 #endif
208 };
209
210 %{
211 #endif // wxUSE_MIMETYPE
212 %}