]>
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 | #include "wx/mimetype.h" | |
22 | ||
23 | ||
24 | class WXDLLEXPORT wxFileTypeImpl | |
25 | { | |
26 | public: | |
27 | // ctor | |
28 | wxFileTypeImpl() { m_info = NULL; } | |
29 | ||
30 | // one of these Init() function must be called (ctor can't take any | |
31 | // arguments because it's common) | |
32 | ||
33 | // initialize us with our file type name and extension - in this case | |
34 | // we will read all other data from the registry | |
35 | void Init(const wxString& strFileType, const wxString& ext); | |
36 | ||
37 | // initialize us with a wxFileTypeInfo object - it contains all the | |
38 | // data | |
39 | void Init(const wxFileTypeInfo& info) | |
40 | { m_info = &info; } | |
41 | ||
42 | // implement accessor functions | |
43 | bool GetExtensions(wxArrayString& extensions); | |
44 | bool GetMimeType(wxString *mimeType) const; | |
45 | bool GetMimeTypes(wxArrayString& mimeTypes) const; | |
46 | bool GetIcon(wxIcon *icon, wxString *sCommand = NULL, int *iIndex = NULL) const; | |
47 | bool GetDescription(wxString *desc) const; | |
48 | bool GetOpenCommand(wxString *openCmd, | |
49 | const wxFileType::MessageParameters& params) const; | |
50 | bool GetPrintCommand(wxString *printCmd, | |
51 | const wxFileType::MessageParameters& params) const; | |
52 | ||
53 | size_t GetAllCommands(wxArrayString * verbs, wxArrayString * commands, | |
54 | const wxFileType::MessageParameters& params) const; | |
55 | ||
56 | bool SetCommand(const wxString& cmd, const wxString& verb, | |
57 | bool overwriteprompt = true); | |
58 | bool SetMimeType(const wxString& mimeType); | |
59 | bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0); | |
60 | ||
61 | bool RemoveCommand(const wxString& verb); | |
62 | bool RemoveMimeType(); | |
63 | bool RemoveDefaultIcon(); | |
64 | ||
65 | private: | |
66 | // helper function: reads the command corresponding to the specified verb | |
67 | // from the registry (returns an empty string if not found) | |
68 | wxString GetCommand(const wxChar *verb) const; | |
69 | ||
70 | // get the registry path for the given verb | |
71 | wxString GetVerbPath(const wxString& verb) const; | |
72 | ||
73 | // check that the registry key for our extension exists, create it if it | |
74 | // doesn't, return FALSE if this failed | |
75 | bool EnsureExtKeyExists(); | |
76 | ||
77 | // we use either m_info or read the data from the registry if m_info == NULL | |
78 | const wxFileTypeInfo *m_info; | |
79 | wxString m_strFileType, // may be empty | |
80 | m_ext; | |
81 | }; | |
82 | ||
83 | class WXDLLEXPORT wxMimeTypesManagerImpl | |
84 | { | |
85 | public: | |
86 | // nothing to do here, we don't load any data but just go and fetch it from | |
87 | // the registry when asked for | |
88 | wxMimeTypesManagerImpl() { } | |
89 | ||
90 | // implement containing class functions | |
91 | wxFileType *GetFileTypeFromExtension(const wxString& ext); | |
92 | wxFileType *GetOrAllocateFileTypeFromExtension(const wxString& ext) ; | |
93 | wxFileType *GetFileTypeFromMimeType(const wxString& mimeType); | |
94 | ||
95 | size_t EnumAllFileTypes(wxArrayString& mimetypes); | |
96 | ||
97 | // this are NOPs under Windows | |
98 | bool ReadMailcap(const wxString& filename, bool fallback = TRUE) | |
99 | { return TRUE; } | |
100 | bool ReadMimeTypes(const wxString& filename) | |
101 | { return TRUE; } | |
102 | ||
103 | void AddFallback(const wxFileTypeInfo& ft) { m_fallbacks.Add(ft); } | |
104 | ||
105 | // create a new filetype with the given name and extension | |
106 | wxFileType *CreateFileType(const wxString& filetype, const wxString& ext); | |
107 | ||
108 | private: | |
109 | wxArrayFileTypeInfo m_fallbacks; | |
110 | }; | |
111 | ||
112 | ||
113 | #endif | |
114 | //_MIMETYPE_IMPL_H | |
115 |