]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_mimetype.i
Add KeyEvent method for setting the m_uniChar member
[wxWidgets.git] / wxPython / src / _mimetype.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _joystick.i
3// Purpose: SWIG interface stuff for wxJoystick
4//
5// Author: Robin Dunn
6//
7// Created: 18-June-1999
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19%{
20#include <wx/mimetype.h>
21%}
22
23//---------------------------------------------------------------------------
24
25enum wxMailcapStyle
26{
27 wxMAILCAP_STANDARD = 1,
28 wxMAILCAP_NETSCAPE = 2,
29 wxMAILCAP_KDE = 4,
30 wxMAILCAP_GNOME = 8,
31
32 wxMAILCAP_ALL = 15
33};
34
35
36
37
38// wxFileTypeInfo: static container of information accessed via wxFileType.
39class wxFileTypeInfo
40{
41public:
42 // a normal item
43 wxFileTypeInfo(const wxString& mimeType,
44 const wxString& openCmd,
45 const wxString& printCmd,
46 const wxString& desc);
47
48
49 // the array elements correspond to the parameters of the ctor above in
50 // the same order
1b8c7ba6 51 %Rename(FileTypeInfoSequence,, wxFileTypeInfo(const wxArrayString& sArray));
d14a1e28
RD
52
53 // invalid item - use this to terminate the array passed to
54 // wxMimeTypesManager::AddFallbacks
1b8c7ba6 55 %Rename(NullFileTypeInfo,, wxFileTypeInfo());
d14a1e28
RD
56
57
58 // test if this object can be used
59 bool IsValid() const;
60
61 // set the icon info
62 void SetIcon(const wxString& iconFile, int iconIndex = 0);
63
64 // set the short desc
65 void SetShortDesc(const wxString& shortDesc);
66
67 // get the MIME type
68 const wxString& GetMimeType() const;
69
70 // get the open command
71 const wxString& GetOpenCommand() const;
72
73 // get the print command
74 const wxString& GetPrintCommand() const;
75
76 // get the short description (only used under Win32 so far)
77 const wxString& GetShortDesc() const;
78
79 // get the long, user visible description
80 const wxString& GetDescription() const;
81
82 // get the array of all extensions
83 const wxArrayString& GetExtensions() const;
ace78e27 84 size_t GetExtensionsCount() const;
d14a1e28
RD
85
86 // get the icon info
87 const wxString& GetIconFile() const;
88 int GetIconIndex() const;
89};
90
91
92
93//---------------------------------------------------------------------------
94
95// wxFileType: gives access to all information about the files of given type.
96//
97// This class holds information about a given "file type". File type is the
98// same as MIME type under Unix, but under Windows it corresponds more to an
99// extension than to MIME type (in fact, several extensions may correspond to a
100// file type). This object may be created in many different ways and depending
101// on how it was created some fields may be unknown so the return value of all
102// the accessors *must* be checked!
103class wxFileType
104{
105public:
106
107// // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
108
109// // An object of this class must be passed to Get{Open|Print}Command. The
110// // default implementation is trivial and doesn't know anything at all about
111// // parameters, only filename and MIME type are used (so it's probably ok for
112// // Windows where %{param} is not used anyhow)
113// class MessageParameters
114// {
115// public:
116// // ctors
117// MessageParameters(const wxString& filename=wxPyEmptyString,
118// const wxString& mimetype=wxPyEmptyString);
119
120// // accessors (called by GetOpenCommand)
121// // filename
122// const wxString& GetFileName() const;
123// // mime type
124// const wxString& GetMimeType() const;;
125
126// // override this function in derived class
127// virtual wxString GetParamValue(const wxString& name) const;
128
129// // virtual dtor as in any base class
130// virtual ~MessageParameters();
131// };
132
133
134 // ctor from static data
135 wxFileType(const wxFileTypeInfo& ftInfo);
136 ~wxFileType();
137
138
139 // return the MIME type for this file type
140 %extend {
141 PyObject* GetMimeType() {
142 wxString str;
143 if (self->GetMimeType(&str))
144 return wx2PyString(str);
145 else
146 RETURN_NONE();
147 }
148
149 PyObject* GetMimeTypes() {
150 wxArrayString arr;
151 if (self->GetMimeTypes(arr))
152 return wxArrayString2PyList_helper(arr);
153 else
154 RETURN_NONE();
155 }
156 }
157
158
159 // Get all extensions associated with this file type
160 %extend {
161 PyObject* GetExtensions() {
162 wxArrayString arr;
163 if (self->GetExtensions(arr))
164 return wxArrayString2PyList_helper(arr);
165 else
166 RETURN_NONE();
167 }
168 }
169
170
171 %extend {
172 // Get the icon corresponding to this file type
173 %newobject GetIcon;
174 wxIcon* GetIcon() {
175 wxIconLocation loc;
176 if (self->GetIcon(&loc))
177 return new wxIcon(loc);
178 else
179 return NULL;
180 }
181
182 // Get the icon corresponding to this file type, the name of the file
183 // where this icon resides, and its index in this file if applicable.
184 PyObject* GetIconInfo() {
185 wxIconLocation loc;
186 if (self->GetIcon(&loc)) {
187 wxString iconFile = loc.GetFileName();
188 int iconIndex = -1;
189#ifdef __WXMSW__
190 iconIndex = loc.GetIndex();
191#endif
192 // Make a tuple and put the values in it
6e6b3557 193 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
194 PyObject* tuple = PyTuple_New(3);
195 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(loc),
a72f4631 196 wxT("wxIcon"), true));
d14a1e28
RD
197 PyTuple_SetItem(tuple, 1, wx2PyString(iconFile));
198 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
da32eb53 199 wxPyEndBlockThreads(blocked);
d14a1e28
RD
200 return tuple;
201 }
202 else
203 RETURN_NONE();
204 }
205 }
206
207 %extend {
208 // get a brief file type description ("*.txt" => "text document")
209 PyObject* GetDescription() {
210 wxString str;
211 if (self->GetDescription(&str))
212 return wx2PyString(str);
213 else
214 RETURN_NONE();
215 }
216 }
217
218
219 // get the command to open/execute the file of given type
220 %extend {
221 PyObject* GetOpenCommand(const wxString& filename,
222 const wxString& mimetype=wxPyEmptyString) {
223 wxString str;
224 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
225 return wx2PyString(str);
226 else
227 RETURN_NONE();
228 }
229 }
230
231
232 // get the command to print the file of given type
233 %extend {
234 PyObject* GetPrintCommand(const wxString& filename,
235 const wxString& mimetype=wxPyEmptyString) {
236 wxString str;
237 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
238 return wx2PyString(str);
239 else
240 RETURN_NONE();
241 }
242 }
243
244
245 // Get all commands defined for this file type
246 %extend {
247 PyObject* GetAllCommands(const wxString& filename,
248 const wxString& mimetype=wxPyEmptyString) {
249 wxArrayString verbs;
250 wxArrayString commands;
251 if (self->GetAllCommands(&verbs, &commands,
252 wxFileType::MessageParameters(filename, mimetype))) {
6e6b3557 253 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
254 PyObject* tuple = PyTuple_New(2);
255 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
256 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
da32eb53 257 wxPyEndBlockThreads(blocked);
d14a1e28
RD
258 return tuple;
259 }
260 else
261 RETURN_NONE();
262 }
263 }
264
265
266 // set an arbitrary command, ask confirmation if it already exists and
dd9f7fea 267 // overwriteprompt is True
d14a1e28 268 bool SetCommand(const wxString& cmd, const wxString& verb,
a72f4631 269 bool overwriteprompt = true);
d14a1e28
RD
270
271 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
272
273
274 // remove the association for this filetype from the system MIME database:
275 // notice that it will only work if the association is defined in the user
276 // file/registry part, we will never modify the system-wide settings
277 bool Unassociate();
278
279 // operations
280 // expand a string in the format of GetOpenCommand (which may contain
281 // '%s' and '%t' format specificators for the file name and mime type
282 // and %{param} constructions).
283 %extend {
284 static wxString ExpandCommand(const wxString& command,
285 const wxString& filename,
286 const wxString& mimetype=wxPyEmptyString) {
287 return wxFileType::ExpandCommand(command,
288 wxFileType::MessageParameters(filename, mimetype));
289 }
290 }
291
292};
293
294
295
296//---------------------------------------------------------------------------
297
d14a1e28
RD
298wxMimeTypesManager* const wxTheMimeTypesManager;
299
300
301// wxMimeTypesManager: interface to system MIME database.
302//
303// This class accesses the information about all known MIME types and allows
304// the application to retrieve information (including how to handle data of
305// given type) about them.
306class wxMimeTypesManager
307{
308public:
309 // static helper functions
310 // -----------------------
311
312 // check if the given MIME type is the same as the other one: the
313 // second argument may contain wildcards ('*'), but not the first. If
314 // the types are equal or if the mimeType matches wildcard the function
dd9f7fea 315 // returns True, otherwise it returns False
d14a1e28
RD
316 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
317
318 // ctor
319 wxMimeTypesManager();
320
321 // loads data from standard files according to the mailcap styles
322 // specified: this is a bitwise OR of wxMailcapStyle values
323 //
324 // use the extraDir parameter if you want to look for files in another
325 // directory
326 void Initialize(int mailcapStyle = wxMAILCAP_ALL,
327 const wxString& extraDir = wxPyEmptyString);
328
329 // and this function clears all the data from the manager
330 void ClearData();
331
332 // Database lookup: all functions return a pointer to wxFileType object
333 // whose methods may be used to query it for the information you're
334 // interested in. If the return value is !NULL, caller is responsible for
335 // deleting it.
336 // get file type from file extension
337 %newobject GetFileTypeFromExtension;
338 wxFileType *GetFileTypeFromExtension(const wxString& ext);
339
340 // get file type from MIME type (in format <category>/<format>)
341 %newobject GetFileTypeFromMimeType;
342 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
343
dd9f7fea 344 // other operations: return True if there were no errors or False if there
d6922577 345 // were some unrecognized entries (the good entries are always read anyhow)
d14a1e28
RD
346 //
347
348 // read in additional file (the standard ones are read automatically)
349 // in mailcap format (see mimetype.cpp for description)
350 //
dd9f7fea 351 // 'fallback' parameter may be set to True to avoid overriding the
d14a1e28
RD
352 // settings from other, previously parsed, files by this one: normally,
353 // the files read most recently would override the older files, but with
dd9f7fea 354 // fallback == True this won't happen
a72f4631 355 bool ReadMailcap(const wxString& filename, bool fallback = false);
d14a1e28
RD
356
357 // read in additional file in mime.types format
358 bool ReadMimeTypes(const wxString& filename);
359
360 // enumerate all known MIME types
361 %extend {
362 PyObject* EnumAllFileTypes() {
363 wxArrayString arr;
364 self->EnumAllFileTypes(arr);
365 return wxArrayString2PyList_helper(arr);
366 }
367 }
368
369 // these functions can be used to provide default values for some of the
370 // MIME types inside the program itself (you may also use
dd9f7fea 371 // ReadMailcap(filenameWithDefaultTypes, True /* use as fallback */) to
d14a1e28
RD
372 // achieve the same goal, but this requires having this info in a file).
373 //
374 void AddFallback(const wxFileTypeInfo& ft);
375
376
377 // create or remove associations
378
379 // create a new association using the fields of wxFileTypeInfo (at least
380 // the MIME type and the extension should be set)
381 // if the other fields are empty, the existing values should be left alone
382 %newobject Associate;
383 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
384
385 // undo Associate()
386 bool Unassociate(wxFileType *ft) ;
387
388 ~wxMimeTypesManager();
389};
390
391//---------------------------------------------------------------------------
392
393//---------------------------------------------------------------------------
394//---------------------------------------------------------------------------