]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/icon.tex
Added first batch of docs and notes for wxPython.
[wxWidgets.git] / docs / latex / wx / icon.tex
1 \section{\class{wxIcon}}\label{wxicon}
2
3 An icon is a small rectangular bitmap usually used for denoting a
4 minimized application. It differs from a wxBitmap in always
5 having a mask associated with it for transparent drawing. On some platforms,
6 icons and bitmaps are implemented identically, since there is no real distinction between
7 a wxBitmap with a mask and an icon; and there is no specific icon format on
8 some platforms (X-based applications usually standardize on XPMs for small bitmaps
9 and icons). However, some platforms (such as Windows) make the distinction, so
10 a separate class is provided.
11
12 \wxheading{Remarks}
13
14 It is usually desirable to associate a pertinent icon with a frame. Icons
15 can also be used for other purposes, for example with \helpref{wxTreeCtrl}{wxtreectrl}
16 and \helpref{wxListCtrl}{wxlistctrl}.
17
18 Icons have different formats on different platforms.
19 Therefore, separate icons will usually be created for the different
20 environments. Platform-specific methods for creating a {\bf wxIcon}\rtfsp
21 structure are catered for, and this is an occasion where conditional
22 compilation will probably be required.
23
24 Note that a new icon must be created for every time the icon is to be
25 used for a new window. In Windows, the icon will not be
26 reloaded if it has already been used. An icon allocated to a frame will
27 be deleted when the frame is deleted.
28
29 For more information please see \helpref{Bitmap and icon overview}{wxbitmapoverview}.
30
31 \wxheading{Derived from}
32
33 \helpref{wxBitmap}{wxbitmap}\\
34 \helpref{wxGDIObject}{wxgdiobject}\\
35 \helpref{wxObject}{wxobject}
36
37 \wxheading{Include files}
38
39 <wx/icon.h>
40
41 \wxheading{See also}
42
43 \helpref{Bitmap and icon overview}{wxbitmapoverview}, \helpref{supported bitmap file formats}{supportedbitmapformats},
44 \helpref{wxDC::DrawIcon}{wxdcdrawicon}, \helpref{wxCursor}{wxcursor}
45
46 \latexignore{\rtfignore{\wxheading{Members}}}
47
48 \membersection{wxIcon::wxIcon}\label{wxiconconstr}
49
50 \func{}{wxIcon}{\void}
51
52 Default constructor.
53
54 \func{}{wxIcon}{\param{const wxIcon\& }{icon}}
55
56 Copy constructor.
57
58 \func{}{wxIcon}{\param{void*}{ data}, \param{int}{ type}, \param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
59
60 Creates an icon from the given data, which can be of arbitrary type.
61
62 \func{}{wxIcon}{\param{const char}{ bits[]}, \param{int}{ width}, \param{int}{ height}\\
63 \param{int}{ depth = 1}}
64
65 Creates an icon from an array of bits.
66
67 \func{}{wxIcon}{\param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
68
69 Creates a new icon.
70
71 \func{}{wxIcon}{\param{const char**}{ bits}}
72
73 Creates an icon from XPM data.
74
75 \func{}{wxIcon}{\param{const wxString\& }{name}, \param{long}{ type},
76 \param{int}{ desiredWidth = -1}, \param{int}{ desiredHeight = -1}}
77
78 Loads an icon from a file or resource.
79
80 \wxheading{Parameters}
81
82 \docparam{bits}{Specifies an array of pixel values.}
83
84 \docparam{width}{Specifies the width of the icon.}
85
86 \docparam{height}{Specifies the height of the icon.}
87
88 \docparam{desiredWidth}{Specifies the desired width of the icon. This
89 parameter only has an effect in Windows (32-bit) where icon resources can contain
90 several icons of different sizes.}
91
92 \docparam{desiredWidth}{Specifies the desired height of the icon. This
93 parameter only has an effect in Windows (32-bit) where icon resources can contain
94 several icons of different sizes.}
95
96 \docparam{depth}{Specifies the depth of the icon. If this is omitted, the display depth of the
97 screen is used.}
98
99 \docparam{name}{This can refer to a resource name under MS Windows, or a filename under MS Windows and X.
100 Its meaning is determined by the {\it flags} parameter.}
101
102 \docparam{type}{May be one of the following:
103
104 \twocolwidtha{5cm}
105 \begin{twocollist}
106 \twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_ICO}}}{Load a Windows icon file.}
107 \twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_ICO\_RESOURCE}}}{Load a Windows icon from the resource database.}
108 \twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_GIF}}}{Load a GIF bitmap file.}
109 \twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_XBM}}}{Load an X bitmap file.}
110 \twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_XPM}}}{Load an XPM bitmap file.}
111 %\twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_RESOURCE}}}{Load a Windows resource name.}
112 \end{twocollist}
113
114 The validity of these flags depends on the platform and wxWindows configuration.
115 If all possible wxWindows settings are used, the Windows platform supports ICO file, ICO resource,
116 XPM data, and XPM file. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
117 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.}
118
119 \wxheading{Remarks}
120
121 The first form constructs an icon object with no data; an assignment or another member function such as Create
122 or LoadFile must be called subsequently.
123
124 The second and third forms provide copy constructors. Note that these do not copy the
125 icon data, but instead a pointer to the data, keeping a reference count. They are therefore
126 very efficient operations.
127
128 The fourth form constructs an icon from data whose type and value depends on
129 the value of the {\it type} argument.
130
131 The fifth form constructs a (usually monochrome) icon from an array of pixel values, under both
132 X and Windows.
133
134 The sixth form constructs a new icon.
135
136 The seventh form constructs an icon from pixmap (XPM) data, if wxWindows has been configured
137 to incorporate this feature.
138
139 To use this constructor, you must first include an XPM file. For
140 example, assuming that the file {\tt mybitmap.xpm} contains an XPM array
141 of character pointers called mybitmap:
142
143 \begin{verbatim}
144 #include "mybitmap.xpm"
145
146 ...
147
148 wxIcon *icon = new wxIcon(mybitmap);
149 \end{verbatim}
150
151 A macro, wxICON, is available which creates an icon using an XPM
152 on the appropriate platform, or an icon resource on Windows.
153
154 \begin{verbatim}
155 wxIcon icon(wxICON(mondrian));
156
157 // Equivalent to:
158
159 #if defined(__WXGTK__) || defined(__WXMOTIF__)
160 wxIcon icon(mondrian_xpm);
161 #endif
162
163 #if defined(__WXMSW__)
164 wxIcon icon("mondrian");
165 #endif
166 \end{verbatim}
167
168 The eighth form constructs an icon from a file or resource. {\it name} can refer
169 to a resource name under MS Windows, or a filename under MS Windows and X.
170
171 Under Windows, {\it type} defaults to wxBITMAP\_TYPE\_ICO\_RESOURCE.
172 Under X, {\it type} defaults to wxBITMAP\_TYPE\_XPM.
173
174 \wxheading{See also}
175
176 \helpref{wxIcon::LoadFile}{wxiconloadfile}
177
178 \membersection{wxIcon::\destruct{wxIcon}}
179
180 \func{}{\destruct{wxIcon}}{\void}
181
182 Destroys the wxIcon object and possibly the underlying icon data.
183 Because reference counting is used, the icon may not actually be
184 destroyed at this point - only when the reference count is zero will the
185 data be deleted.
186
187 If the application omits to delete the icon explicitly, the icon will be
188 destroyed automatically by wxWindows when the application exits.
189
190 Do not delete an icon that is selected into a memory device context.
191
192 \membersection{wxIcon::GetDepth}
193
194 \constfunc{int}{GetDepth}{\void}
195
196 Gets the colour depth of the icon. A value of 1 indicates a
197 monochrome icon.
198
199 \membersection{wxIcon::GetHeight}\label{wxicongetheight}
200
201 \constfunc{int}{GetHeight}{\void}
202
203 Gets the height of the icon in pixels.
204
205 \membersection{wxIcon::GetWidth}\label{wxicongetwidth}
206
207 \constfunc{int}{GetWidth}{\void}
208
209 Gets the width of the icon in pixels.
210
211 \wxheading{See also}
212
213 \helpref{wxIcon::GetHeight}{wxicongetheight}
214
215 \membersection{wxIcon::LoadFile}\label{wxiconloadfile}
216
217 \func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type}}
218
219 Loads an icon from a file or resource.
220
221 \wxheading{Parameters}
222
223 \docparam{name}{Either a filename or a Windows resource name.
224 The meaning of {\it name} is determined by the {\it type} parameter.}
225
226 \docparam{type}{One of the following values:
227
228 \twocolwidtha{5cm}
229 \begin{twocollist}
230 \twocolitem{{\bf wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file.}
231 \twocolitem{{\bf wxBITMAP\_TYPE\_ICO\_RESOURCE}}{Load a Windows icon from the resource database.}
232 \twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
233 \twocolitem{{\bf wxBITMAP\_TYPE\_XBM}}{Load an X bitmap file.}
234 \twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Load an XPM bitmap file.}
235 \end{twocollist}
236
237 The validity of these flags depends on the platform and wxWindows configuration.}
238
239 \wxheading{Return value}
240
241 TRUE if the operation succeeded, FALSE otherwise.
242
243 \wxheading{See also}
244
245 \helpref{wxIcon::wxIcon}{wxiconconstr}
246
247 \membersection{wxIcon::Ok}\label{wxiconok}
248
249 \constfunc{bool}{Ok}{\void}
250
251 Returns TRUE if icon data is present.
252
253 \begin{comment}
254 \membersection{wxIcon::SaveFile}\label{wxiconsavefile}
255
256 \func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}, \param{wxPalette* }{palette = NULL}}
257
258 Saves an icon in the named file.
259
260 \wxheading{Parameters}
261
262 \docparam{name}{A filename. The meaning of {\it name} is determined by the {\it type} parameter.}
263
264 \docparam{type}{One of the following values:
265
266 \twocolwidtha{5cm}
267 \begin{twocollist}
268 \twocolitem{{\bf wxBITMAP\_TYPE\_ICO}}{Save a Windows icon file.}
269 %\twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Save a GIF icon file.}
270 %\twocolitem{{\bf wxBITMAP\_TYPE\_XBM}}{Save an X bitmap file.}
271 \twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Save an XPM bitmap file.}
272 \end{twocollist}
273
274 The validity of these flags depends on the platform and wxWindows configuration.}
275
276 \docparam{palette}{An optional palette used for saving the icon.}
277
278 \wxheading{Return value}
279
280 TRUE if the operation succeeded, FALSE otherwise.
281
282 \wxheading{Remarks}
283
284 Depending on how wxWindows has been configured, not all formats may be available.
285
286 \wxheading{See also}
287
288 \helpref{wxIcon::LoadFile}{wxiconloadfile}
289 \end{comment}
290
291 \membersection{wxIcon::SetDepth}\label{wxiconsetdepth}
292
293 \func{void}{SetDepth}{\param{int }{depth}}
294
295 Sets the depth member (does not affect the icon data).
296
297 \wxheading{Parameters}
298
299 \docparam{depth}{Icon depth.}
300
301 \membersection{wxIcon::SetHeight}\label{wxiconsetheight}
302
303 \func{void}{SetHeight}{\param{int }{height}}
304
305 Sets the height member (does not affect the icon data).
306
307 \wxheading{Parameters}
308
309 \docparam{height}{Icon height in pixels.}
310
311 \membersection{wxIcon::SetOk}
312
313 \func{void}{SetOk}{\param{int }{isOk}}
314
315 Sets the validity member (does not affect the icon data).
316
317 \wxheading{Parameters}
318
319 \docparam{isOk}{Validity flag.}
320
321 \membersection{wxIcon::SetWidth}
322
323 \func{void}{SetWidth}{\param{int }{width}}
324
325 Sets the width member (does not affect the icon data).
326
327 \wxheading{Parameters}
328
329 \docparam{width}{Icon width in pixels.}
330
331 \membersection{wxIcon::operator $=$}
332
333 \func{wxIcon\& }{operator $=$}{\param{const wxIcon\& }{icon}}
334
335 Assignment operator. This operator does not copy any data, but instead
336 passes a pointer to the data in {\it icon} and increments a reference
337 counter. It is a fast operation.
338
339 \wxheading{Parameters}
340
341 \docparam{icon}{Icon to assign.}
342
343 \wxheading{Return value}
344
345 Returns 'this' object.
346
347 \membersection{wxIcon::operator $==$}
348
349 \func{bool}{operator $==$}{\param{const wxIcon\& }{icon}}
350
351 Equality operator. This operator tests whether the internal data pointers are
352 equal (a fast test).
353
354 \wxheading{Parameters}
355
356 \docparam{icon}{Icon to compare with 'this'}
357
358 \wxheading{Return value}
359
360 Returns TRUE if the icons were effectively equal, FALSE otherwise.
361
362 \membersection{wxIcon::operator $!=$}
363
364 \func{bool}{operator $!=$}{\param{const wxIcon\& }{icon}}
365
366 Inequality operator. This operator tests whether the internal data pointers are
367 unequal (a fast test).
368
369 \wxheading{Parameters}
370
371 \docparam{icon}{Icon to compare with 'this'}
372
373 \wxheading{Return value}
374
375 Returns TRUE if the icons were unequal, FALSE otherwise.
376
377