File: wx96.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (247 lines) | stat: -rw-r--r-- 10,313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<HTML>
<head><title>wxFileType</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="wxfiletype"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx22.htm#classref"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx95.htm#topic382"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx97.htm#wxfilterinputstream"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>wxFileType</H2>
<P>
This class holds information about a given "file type". File type is the same as
MIME type under Unix, but under Windows it corresponds more to an extension than
to MIME type (in fact, several extensions may correspond to a file type). This
object may be created in several different ways: the program might know the file
extension and wish to find out the corresponding MIME type or, conversely, it
might want to find the right extension for the file to which it writes the
contents of given MIME type. Depending on how it was created some fields may be
unknown so the return value of all the accessors <B>must</B> be checked: FALSE
will be returned if the corresponding information couldn't be found.<P>
The objects of this class are never created by the application code but are
returned by <A HREF="wx147.htm#wxmimetypesmanagergetfiletypefrommimetype">wxMimeTypesManager::GetFileTypeFromMimeType</A> and 
<A HREF="wx147.htm#wxmimetypesmanagergetfiletypefromextension">wxMimeTypesManager::GetFileTypeFromExtension</A> methods.
But it's your responsability to delete the returned pointer when you're done
with it!<P>
A brief remainder about what the MIME types are (see the RFC 1341 for more
information): basicly, it is just a pair category/type (for example,
"text/plain") where the category is a basic indication of what a file is
(examples of categories are "application", "image", "text", "binary"...) and
type is a precise definition of the document format: "plain" in the example
above means just ASCII text without any formatting, while "text/html" is the
HTML document source.<P>
A MIME type may have one or more associated extensions: "text/plain" will
typically correspond to the extension ".txt", but may as well be associated with
".ini" or ".conf".<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
No base class.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/mimetype.h&gt;<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx147.htm#wxmimetypesmanager">wxMimeTypesManager</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#wxfiletypemessageparameters">MessageParameters class</A><BR>
<A HREF="#wxfiletypewxfiletype">wxFileType::wxFileType</A><BR>
<A HREF="#wxfiletypedtor">wxFileType::~wxFileType</A><BR>
<A HREF="#wxfiletypegetmimetype">wxFileType::GetMimeType</A><BR>
<A HREF="#wxfiletypegetextensions">wxFileType::GetExtensions</A><BR>
<A HREF="#wxfiletypegeticon">wxFileType::GetIcon</A><BR>
<A HREF="#wxfiletypegetdescription">wxFileType::GetDescription</A><BR>
<A HREF="#wxfiletypegetopencommand">wxFileType::GetOpenCommand</A><BR>
<A HREF="#wxfiletypegetprintcommand">wxFileType::GetPrintCommand</A><BR>
<A HREF="#wxfiletypeexpandcommand">wxFileType::ExpandCommand</A><BR>
<P>

<HR>
<A NAME="wxfiletypemessageparameters"></A>
<H3>MessageParameters class</H3>
<P>
One of the most common usages of MIME is to encode an e-mail message. The MIME
type of the encoded message is an example of a <I>message parameter</I>. These
parameters are found in the message headers ("Content-XXX"). At the very least,
they must specify the MIME type and the version of MIME used, but almost always
they provide additional information about the message such as the original file
name or the charset (for the text documents).<P>
These parameters may be useful to the program used to open, edit, view or print
the message, so, for example, an e-mail client program will have to pass them to
this program. Because wxFileType itself can not know about these parameters,
it uses MessageParameters class to query them. The default implementation only
requiers the caller to provide the file name (always used by the program to be
called - it must know which file to open) and the MIME type and supposes that
there are no other parameters. If you wish to supply additional parameters, you
must derive your own class from MessageParameters and override GetParamValue()
function, for example:<P>
<PRE>
// provide the message parameters for the MIME type manager
class MailMessageParameters : public wxFileType::MessageParameters
{
public:
   MailMessageParameters(const wxString& filename,
                         const wxString& mimetype)
      : wxFileType::MessageParameters(filename, mimetype)
   {
   }

   virtual wxString GetParamValue(const wxString& name) const
   {
       // parameter names are not case-sensitive
       if ( name.CmpNoCase("charset") == 0 )
           return "US-ASCII";
       else
           return wxFileType::MessageParameters::GetParamValue(name);
   }
};
</PRE>
Now you only need to create an object of this class and pass it to, for example,
<A HREF="wx96.htm#wxfiletypegetopencommand">GetOpenCommand</A> like this:<P>
<PRE>
wxString command;
if ( filetype-&gt;GetOpenCommand(&command,
                              MailMessageParamaters("foo.txt", "text/plain")) )
{
    // the full command for opening the text documents is in 'command'
    // (it might be "notepad foo.txt" under Windows or "cat foo.txt" under Unix)
}
else
{
    // we don't know how to handle such files...
}
</PRE>
<B>Windows:</B> As only the file name is used by the program associated with the
given extension anyhow (but no other message parameters), there is no need to
ever derive from MessageParameters class for a Windows-only program.<P>

<HR>
<A NAME="wxfiletypewxfiletype"></A>
<H3>wxFileType::wxFileType</H3>
<P>
<B></B> <B>wxFileType</B>()<P>
The default constructor is private because you should never create objects of
this type: they are only returned by <A HREF="wx147.htm#wxmimetypesmanager">wxMimeTypesManager</A> methods.<P>

<HR>
<A NAME="wxfiletypedtor"></A>
<H3>wxFileType::~wxFileType</H3>
<P>
<B></B> <B>~wxFileType</B>()<P>
The destructor of this class is not virtual, so it should not be derived from.<P>

<HR>
<A NAME="wxfiletypegetmimetype"></A>
<H3>wxFileType::GetMimeType</H3>
<P>
<B>bool</B> <B>GetMimeType</B>(<B>wxString*</B><I> mimeType</I>)<P>
If the function returns TRUE, the string pointed to by <I>mimeType</I> is filled
with full MIME type specification for this file type: for example, "text/plain".<P>

<HR>
<A NAME="wxfiletypegetextensions"></A>
<H3>wxFileType::GetExtensions</H3>
<P>
<B>bool</B> <B>GetExtensions</B>(<B>wxArrayString&amp;</B><I> extensions</I>)<P>
If the function returns TRUE, the array <I>extensions</I> is filled
with all extensions associated with this file type: for example, it may
contain the following two elements for the MIME type "text/html" (notice the
absence of the leading dot): "html" and "htm".<P>
<B>Windows:</B> This function is currently not implemented: there is no
(efficient) way to retrieve associated extensions from the given MIME type on
this platform, so it will only return TRUE if the wxFileType object was created
by <A HREF="wx147.htm#wxmimetypesmanagergetfiletypefromextension">GetFileTypeFromExtension</A> 
function in the first place.<P>

<HR>
<A NAME="wxfiletypegeticon"></A>
<H3>wxFileType::GetIcon</H3>
<P>
<B>bool</B> <B>GetIcon</B>(<B>wxIcon*</B><I> icon</I>)<P>
If the function returns TRUE, the icon associated with this file type will be
created and assigned to the <I>icon</I> parameter.<P>
<B>Unix:</B> This function always returns FALSE under Unix.<P>

<HR>
<A NAME="wxfiletypegetdescription"></A>
<H3>wxFileType::GetDescription</H3>
<P>
<B>bool</B> <B>GetDescription</B>(<B>wxString*</B><I> desc</I>)<P>
If the function returns TRUE, the string pointed to by <I>desc</I> is filled
with a brief description for this file type: for example, "text document" for
the "text/plain" MIME type.<P>

<HR>
<A NAME="wxfiletypegetopencommand"></A>
<H3>wxFileType::GetOpenCommand</H3>
<P>
<B>bool</B> <B>GetOpenCommand</B>(<B>wxString*</B><I> command</I>, <B>MessageParameters&amp;</B><I> params</I>)<P>
If the function returns TRUE, the string pointed to by <I>command</I> is filled
with the command which must be executed (see <A HREF="wx271.htm#wxexecute">wxExecute</A>) in
order to open the file of the given type. The name of the file is
retrieved from <A HREF="wx96.htm#wxfiletypemessageparameters">MessageParameters</A> class.<P>

<HR>
<A NAME="wxfiletypegetprintcommand"></A>
<H3>wxFileType::GetPrintCommand</H3>
<P>
<B>bool</B> <B>GetPrintCommand</B>(<B>wxString*</B><I> command</I>,<B>MessageParameters&amp;</B><I> params</I>)<P>
If the function returns TRUE, the string pointed to by <I>command</I> is filled
with the command which must be executed (see <A HREF="wx271.htm#wxexecute">wxExecute</A>) in
order to print the file of the given type. The name of the file is
retrieved from <A HREF="wx96.htm#wxfiletypemessageparameters">MessageParameters</A> class.<P>

<HR>
<A NAME="wxfiletypeexpandcommand"></A>
<H3>wxFileType::ExpandCommand</H3>
<P>
<B>static wxString</B> <B>ExpandCommand</B>(<B>const wxString&amp;</B><I> command</I>, <B>MessageParameters&amp;</B><I> params</I>)<P>
This function is primarly intended for GetOpenCommand and GetPrintCommand
usage but may be also used by the application directly if, for example, you want
to use some non default command to open the file.<P>
The function replaces all occurences of<P>


<TABLE>


<TR><TD VALIGN=TOP>
format specificator
</TD>

<TD VALIGN=TOP>
with
</TD></TR>


<TR><TD VALIGN=TOP>
%s
</TD>

<TD VALIGN=TOP>
the full file name
</TD></TR>


<TR><TD VALIGN=TOP>
%t
</TD>

<TD VALIGN=TOP>
the MIME type
</TD></TR>


<TR><TD VALIGN=TOP>
%{param}
</TD>

<TD VALIGN=TOP>
the value of the parameter <I>param</I>
</TD></TR>


</TABLE>
<P>
using the MessageParameters object you pass to it.<P>
If there is no '%s' in the command string (and the string is not empty), it is
assumed that the command reads the data on stdin and so the effect is the same
as "&lt; %s" were appended to the string.<P>
Unlike all other functions of this class, there is no error return for this
function.<P>

</BODY></HTML>