]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msdos/mimetype.h
optimizing for multiple Realize calls in sequence, moving EventHandler push to toolba...
[wxWidgets.git] / include / wx / msdos / mimetype.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/mimetype.h
3 // Purpose: classes and functions to manage MIME types
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 23.09.98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence (part of wxExtra library)
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _MIMETYPE_IMPL_H
13 #define _MIMETYPE_IMPL_H
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "mimetype.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/mimetype.h"
21
22
23 class wxMimeTypesManagerImpl
24 {
25 public :
26 wxMimeTypesManagerImpl() { }
27
28 // load all data into memory - done when it is needed for the first time
29 void Initialize(int mailcapStyles = wxMAILCAP_STANDARD,
30 const wxString& extraDir = wxEmptyString);
31
32 // and delete the data here
33 void ClearData();
34
35 // implement containing class functions
36 wxFileType *GetFileTypeFromExtension(const wxString& ext);
37 wxFileType *GetOrAllocateFileTypeFromExtension(const wxString& ext) ;
38 wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
39
40 size_t EnumAllFileTypes(wxArrayString& mimetypes);
41
42 // this are NOPs under MacOS
43 bool ReadMailcap(const wxString& WXUNUSED(filename), bool WXUNUSED(fallback) = TRUE) { return TRUE; }
44 bool ReadMimeTypes(const wxString& WXUNUSED(filename)) { return TRUE; }
45
46 void AddFallback(const wxFileTypeInfo& ft) { m_fallbacks.Add(ft); }
47
48 // create a new filetype association
49 wxFileType *Associate(const wxFileTypeInfo& ftInfo);
50 // remove association
51 bool Unassociate(wxFileType *ft);
52
53 // create a new filetype with the given name and extension
54 wxFileType *CreateFileType(const wxString& filetype, const wxString& ext);
55
56 private:
57 wxArrayFileTypeInfo m_fallbacks;
58 };
59
60 class wxFileTypeImpl
61 {
62 public:
63 // initialization functions
64 // this is used to construct a list of mimetypes which match;
65 // if built with GetFileTypeFromMimetype index 0 has the exact match and
66 // index 1 the type / * match
67 // if built with GetFileTypeFromExtension, index 0 has the mimetype for
68 // the first extension found, index 1 for the second and so on
69
70 void Init(wxMimeTypesManagerImpl *manager, size_t index)
71 { m_manager = manager; m_index.Add(index); }
72
73 // initialize us with our file type name
74 void SetFileType(const wxString& strFileType)
75 { m_strFileType = strFileType; }
76 void SetExt(const wxString& ext)
77 { m_ext = ext; }
78
79 // implement accessor functions
80 bool GetExtensions(wxArrayString& extensions);
81 bool GetMimeType(wxString *mimeType) const;
82 bool GetMimeTypes(wxArrayString& mimeTypes) const;
83 bool GetIcon(wxIconLocation *iconLoc) const;
84 bool GetDescription(wxString *desc) const;
85 bool GetOpenCommand(wxString *openCmd,
86 const wxFileType::MessageParameters&) const
87 { return GetCommand(openCmd, "open"); }
88 bool GetPrintCommand(wxString *printCmd,
89 const wxFileType::MessageParameters&) const
90 { return GetCommand(printCmd, "print"); }
91
92 size_t GetAllCommands(wxArrayString * verbs, wxArrayString * commands,
93 const wxFileType::MessageParameters& params) const;
94
95 // remove the record for this file type
96 // probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
97 bool Unassociate(wxFileType *ft)
98 {
99 return m_manager->Unassociate(ft);
100 }
101
102 // set an arbitrary command, ask confirmation if it already exists and
103 // overwriteprompt is TRUE
104 bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE);
105 bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
106
107 private:
108 // helper function
109 bool GetCommand(wxString *command, const char *verb) const;
110
111 wxMimeTypesManagerImpl *m_manager;
112 wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
113 wxString m_strFileType, m_ext;
114 };
115
116 #endif
117 //_MIMETYPE_H
118
119 /* vi: set cin tw=80 ts=4 sw=4: */