]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_mimetype.i
Don't steal VK_RETURN for wxEVT_COMMAND_LIST_ITEM_ACTIVATED if any of
[wxWidgets.git] / wxPython / src / _mimetype.i
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
25 enum 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.
39 class wxFileTypeInfo
40 {
41 public:
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
51 %Rename(FileTypeInfoSequence,, wxFileTypeInfo(const wxArrayString& sArray));
52
53 // invalid item - use this to terminate the array passed to
54 // wxMimeTypesManager::AddFallbacks
55 %Rename(NullFileTypeInfo,, wxFileTypeInfo());
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;
84 size_t GetExtensionsCount() const;
85
86 // get the icon info
87 const wxString& GetIconFile() const;
88 int GetIconIndex() const;
89
90 %property(Description, GetDescription, doc="See `GetDescription`");
91 %property(Extensions, GetExtensions, doc="See `GetExtensions`");
92 %property(ExtensionsCount, GetExtensionsCount, doc="See `GetExtensionsCount`");
93 %property(IconFile, GetIconFile, doc="See `GetIconFile`");
94 %property(IconIndex, GetIconIndex, doc="See `GetIconIndex`");
95 %property(MimeType, GetMimeType, doc="See `GetMimeType`");
96 %property(OpenCommand, GetOpenCommand, doc="See `GetOpenCommand`");
97 %property(PrintCommand, GetPrintCommand, doc="See `GetPrintCommand`");
98 %property(ShortDesc, GetShortDesc, SetShortDesc, doc="See `GetShortDesc` and `SetShortDesc`");
99 };
100
101
102
103 //---------------------------------------------------------------------------
104
105 // wxFileType: gives access to all information about the files of given type.
106 //
107 // This class holds information about a given "file type". File type is the
108 // same as MIME type under Unix, but under Windows it corresponds more to an
109 // extension than to MIME type (in fact, several extensions may correspond to a
110 // file type). This object may be created in many different ways and depending
111 // on how it was created some fields may be unknown so the return value of all
112 // the accessors *must* be checked!
113 class wxFileType
114 {
115 public:
116
117 // // TODO: Make a wxPyMessageParameters with virtual GetParamValue...
118
119 // // An object of this class must be passed to Get{Open|Print}Command. The
120 // // default implementation is trivial and doesn't know anything at all about
121 // // parameters, only filename and MIME type are used (so it's probably ok for
122 // // Windows where %{param} is not used anyhow)
123 // class MessageParameters
124 // {
125 // public:
126 // // ctors
127 // MessageParameters(const wxString& filename=wxPyEmptyString,
128 // const wxString& mimetype=wxPyEmptyString);
129
130 // // accessors (called by GetOpenCommand)
131 // // filename
132 // const wxString& GetFileName() const;
133 // // mime type
134 // const wxString& GetMimeType() const;;
135
136 // // override this function in derived class
137 // virtual wxString GetParamValue(const wxString& name) const;
138
139 // // virtual dtor as in any base class
140 // virtual ~MessageParameters();
141 // };
142
143
144 // ctor from static data
145 wxFileType(const wxFileTypeInfo& ftInfo);
146 ~wxFileType();
147
148
149 // return the MIME type for this file type
150 %extend {
151 PyObject* GetMimeType() {
152 wxString str;
153 if (self->GetMimeType(&str))
154 return wx2PyString(str);
155 else
156 RETURN_NONE();
157 }
158
159 PyObject* GetMimeTypes() {
160 wxArrayString arr;
161 if (self->GetMimeTypes(arr))
162 return wxArrayString2PyList_helper(arr);
163 else
164 RETURN_NONE();
165 }
166 }
167
168
169 // Get all extensions associated with this file type
170 %extend {
171 PyObject* GetExtensions() {
172 wxArrayString arr;
173 if (self->GetExtensions(arr))
174 return wxArrayString2PyList_helper(arr);
175 else
176 RETURN_NONE();
177 }
178 }
179
180
181 %extend {
182 // Get the icon corresponding to this file type
183 %newobject GetIcon;
184 wxIcon* GetIcon() {
185 wxIconLocation loc;
186 if (self->GetIcon(&loc))
187 return new wxIcon(loc);
188 else
189 return NULL;
190 }
191
192 // Get the icon corresponding to this file type, the name of the file
193 // where this icon resides, and its index in this file if applicable.
194 PyObject* GetIconInfo() {
195 wxIconLocation loc;
196 if (self->GetIcon(&loc)) {
197 wxString iconFile = loc.GetFileName();
198 int iconIndex = -1;
199 #ifdef __WXMSW__
200 iconIndex = loc.GetIndex();
201 #endif
202 // Make a tuple and put the values in it
203 wxPyBlock_t blocked = wxPyBeginBlockThreads();
204 PyObject* tuple = PyTuple_New(3);
205 PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(loc),
206 wxT("wxIcon"), true));
207 PyTuple_SetItem(tuple, 1, wx2PyString(iconFile));
208 PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex));
209 wxPyEndBlockThreads(blocked);
210 return tuple;
211 }
212 else
213 RETURN_NONE();
214 }
215 }
216
217 %extend {
218 // get a brief file type description ("*.txt" => "text document")
219 PyObject* GetDescription() {
220 wxString str;
221 if (self->GetDescription(&str))
222 return wx2PyString(str);
223 else
224 RETURN_NONE();
225 }
226 }
227
228
229 // get the command to open/execute the file of given type
230 %extend {
231 PyObject* GetOpenCommand(const wxString& filename,
232 const wxString& mimetype=wxPyEmptyString) {
233 wxString str;
234 if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
235 return wx2PyString(str);
236 else
237 RETURN_NONE();
238 }
239 }
240
241
242 // get the command to print the file of given type
243 %extend {
244 PyObject* GetPrintCommand(const wxString& filename,
245 const wxString& mimetype=wxPyEmptyString) {
246 wxString str;
247 if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype)))
248 return wx2PyString(str);
249 else
250 RETURN_NONE();
251 }
252 }
253
254
255 // Get all commands defined for this file type
256 %extend {
257 PyObject* GetAllCommands(const wxString& filename,
258 const wxString& mimetype=wxPyEmptyString) {
259 wxArrayString verbs;
260 wxArrayString commands;
261 if (self->GetAllCommands(&verbs, &commands,
262 wxFileType::MessageParameters(filename, mimetype))) {
263 wxPyBlock_t blocked = wxPyBeginBlockThreads();
264 PyObject* tuple = PyTuple_New(2);
265 PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs));
266 PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands));
267 wxPyEndBlockThreads(blocked);
268 return tuple;
269 }
270 else
271 RETURN_NONE();
272 }
273 }
274
275
276 // set an arbitrary command, ask confirmation if it already exists and
277 // overwriteprompt is True
278 bool SetCommand(const wxString& cmd, const wxString& verb,
279 bool overwriteprompt = true);
280
281 bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0);
282
283
284 // remove the association for this filetype from the system MIME database:
285 // notice that it will only work if the association is defined in the user
286 // file/registry part, we will never modify the system-wide settings
287 bool Unassociate();
288
289 // operations
290 // expand a string in the format of GetOpenCommand (which may contain
291 // '%s' and '%t' format specificators for the file name and mime type
292 // and %{param} constructions).
293 %extend {
294 static wxString ExpandCommand(const wxString& command,
295 const wxString& filename,
296 const wxString& mimetype=wxPyEmptyString) {
297 return wxFileType::ExpandCommand(command,
298 wxFileType::MessageParameters(filename, mimetype));
299 }
300 }
301
302 %property(AllCommands, GetAllCommands, doc="See `GetAllCommands`");
303 %property(Description, GetDescription, doc="See `GetDescription`");
304 %property(Extensions, GetExtensions, doc="See `GetExtensions`");
305 %property(Icon, GetIcon, doc="See `GetIcon`");
306 %property(IconInfo, GetIconInfo, doc="See `GetIconInfo`");
307 %property(MimeType, GetMimeType, doc="See `GetMimeType`");
308 %property(MimeTypes, GetMimeTypes, doc="See `GetMimeTypes`");
309 %property(OpenCommand, GetOpenCommand, doc="See `GetOpenCommand`");
310 %property(PrintCommand, GetPrintCommand, doc="See `GetPrintCommand`");
311 };
312
313
314
315 //---------------------------------------------------------------------------
316
317 wxMimeTypesManager* const wxTheMimeTypesManager;
318
319
320 // wxMimeTypesManager: interface to system MIME database.
321 //
322 // This class accesses the information about all known MIME types and allows
323 // the application to retrieve information (including how to handle data of
324 // given type) about them.
325 class wxMimeTypesManager
326 {
327 public:
328 // static helper functions
329 // -----------------------
330
331 // check if the given MIME type is the same as the other one: the
332 // second argument may contain wildcards ('*'), but not the first. If
333 // the types are equal or if the mimeType matches wildcard the function
334 // returns True, otherwise it returns False
335 static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
336
337 // ctor
338 wxMimeTypesManager();
339
340 // loads data from standard files according to the mailcap styles
341 // specified: this is a bitwise OR of wxMailcapStyle values
342 //
343 // use the extraDir parameter if you want to look for files in another
344 // directory
345 void Initialize(int mailcapStyle = wxMAILCAP_ALL,
346 const wxString& extraDir = wxPyEmptyString);
347
348 // and this function clears all the data from the manager
349 void ClearData();
350
351 // Database lookup: all functions return a pointer to wxFileType object
352 // whose methods may be used to query it for the information you're
353 // interested in. If the return value is !NULL, caller is responsible for
354 // deleting it.
355 // get file type from file extension
356 %newobject GetFileTypeFromExtension;
357 wxFileType *GetFileTypeFromExtension(const wxString& ext);
358
359 // get file type from MIME type (in format <category>/<format>)
360 %newobject GetFileTypeFromMimeType;
361 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
362
363 // other operations: return True if there were no errors or False if there
364 // were some unrecognized entries (the good entries are always read anyhow)
365 //
366
367 // read in additional file (the standard ones are read automatically)
368 // in mailcap format (see mimetype.cpp for description)
369 //
370 // 'fallback' parameter may be set to True to avoid overriding the
371 // settings from other, previously parsed, files by this one: normally,
372 // the files read most recently would override the older files, but with
373 // fallback == True this won't happen
374 bool ReadMailcap(const wxString& filename, bool fallback = false);
375
376 // read in additional file in mime.types format
377 bool ReadMimeTypes(const wxString& filename);
378
379 // enumerate all known MIME types
380 %extend {
381 PyObject* EnumAllFileTypes() {
382 wxArrayString arr;
383 self->EnumAllFileTypes(arr);
384 return wxArrayString2PyList_helper(arr);
385 }
386 }
387
388 // these functions can be used to provide default values for some of the
389 // MIME types inside the program itself (you may also use
390 // ReadMailcap(filenameWithDefaultTypes, True /* use as fallback */) to
391 // achieve the same goal, but this requires having this info in a file).
392 //
393 void AddFallback(const wxFileTypeInfo& ft);
394
395
396 // create or remove associations
397
398 // create a new association using the fields of wxFileTypeInfo (at least
399 // the MIME type and the extension should be set)
400 // if the other fields are empty, the existing values should be left alone
401 %newobject Associate;
402 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
403
404 // undo Associate()
405 bool Unassociate(wxFileType *ft) ;
406
407 ~wxMimeTypesManager();
408 };
409
410 //---------------------------------------------------------------------------
411
412 //---------------------------------------------------------------------------
413 //---------------------------------------------------------------------------