]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/msw/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 license (part of wxExtra library) | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _MIMETYPE_IMPL_H | |
13 | #define _MIMETYPE_IMPL_H | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "mimetype.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_MIMETYPE | |
22 | ||
23 | #include "wx/mimetype.h" | |
24 | ||
25 | // ---------------------------------------------------------------------------- | |
26 | // wxFileTypeImpl is the MSW version of wxFileType, this is a private class | |
27 | // and is never used directly by the application | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | class WXDLLEXPORT wxFileTypeImpl | |
31 | { | |
32 | public: | |
33 | // ctor | |
34 | wxFileTypeImpl() { } | |
35 | ||
36 | // one of these Init() function must be called (ctor can't take any | |
37 | // arguments because it's common) | |
38 | ||
39 | // initialize us with our file type name and extension - in this case | |
40 | // we will read all other data from the registry | |
41 | void Init(const wxString& strFileType, const wxString& ext); | |
42 | ||
43 | // implement accessor functions | |
44 | bool GetExtensions(wxArrayString& extensions); | |
45 | bool GetMimeType(wxString *mimeType) const; | |
46 | bool GetMimeTypes(wxArrayString& mimeTypes) const; | |
47 | bool GetIcon(wxIcon *icon, wxString *sCommand = NULL, int *iIndex = NULL) const; | |
48 | bool GetDescription(wxString *desc) const; | |
49 | bool GetOpenCommand(wxString *openCmd, | |
50 | const wxFileType::MessageParameters& params) const; | |
51 | bool GetPrintCommand(wxString *printCmd, | |
52 | const wxFileType::MessageParameters& params) const; | |
53 | ||
54 | size_t GetAllCommands(wxArrayString * verbs, wxArrayString * commands, | |
55 | const wxFileType::MessageParameters& params) const; | |
56 | ||
57 | bool Unassociate(); | |
58 | ||
59 | // set an arbitrary command, ask confirmation if it already exists and | |
60 | // overwriteprompt is TRUE | |
61 | bool SetCommand(const wxString& cmd, | |
62 | const wxString& verb, | |
63 | bool overwriteprompt = TRUE); | |
64 | ||
65 | bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0); | |
66 | ||
67 | // this is called by Associate | |
68 | bool SetDescription (const wxString& desc); | |
69 | ||
70 | private: | |
71 | // helper function: reads the command corresponding to the specified verb | |
72 | // from the registry (returns an empty string if not found) | |
73 | wxString GetCommand(const wxChar *verb) const; | |
74 | ||
75 | // get the registry path for the given verb | |
76 | wxString GetVerbPath(const wxString& verb) const; | |
77 | ||
78 | // check that the registry key for our extension exists, create it if it | |
79 | // doesn't, return FALSE if this failed | |
80 | bool EnsureExtKeyExists(); | |
81 | ||
82 | wxString m_strFileType, // may be empty | |
83 | m_ext; | |
84 | ||
85 | // these methods are not publicly accessible (as wxMimeTypesManager | |
86 | // doesn't know about them), and should only be called by Unassociate | |
87 | ||
88 | bool RemoveOpenCommand(); | |
89 | bool RemoveCommand(const wxString& verb); | |
90 | bool RemoveMimeType(); | |
91 | bool RemoveDefaultIcon(); | |
92 | bool RemoveDescription(); | |
93 | }; | |
94 | ||
95 | class WXDLLEXPORT wxMimeTypesManagerImpl | |
96 | { | |
97 | public: | |
98 | // nothing to do here, we don't load any data but just go and fetch it from | |
99 | // the registry when asked for | |
100 | wxMimeTypesManagerImpl() { } | |
101 | ||
102 | // implement containing class functions | |
103 | wxFileType *GetFileTypeFromExtension(const wxString& ext); | |
104 | wxFileType *GetOrAllocateFileTypeFromExtension(const wxString& ext); | |
105 | wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); | |
106 | ||
107 | size_t EnumAllFileTypes(wxArrayString& mimetypes); | |
108 | ||
109 | // this are NOPs under Windows | |
110 | bool ReadMailcap(const wxString& WXUNUSED(filename), bool WXUNUSED(fallback) = TRUE) | |
111 | { return TRUE; } | |
112 | bool ReadMimeTypes(const wxString& WXUNUSED(filename)) | |
113 | { return TRUE; } | |
114 | ||
115 | // create a new filetype association | |
116 | wxFileType *Associate(const wxFileTypeInfo& ftInfo); | |
117 | ||
118 | // create a new filetype with the given name and extension | |
119 | wxFileType *CreateFileType(const wxString& filetype, const wxString& ext); | |
120 | }; | |
121 | ||
122 | #endif // wxUSE_MIMETYPE | |
123 | ||
124 | #endif | |
125 | //_MIMETYPE_IMPL_H | |
126 |