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