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