]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: icon.h | |
e54c96f1 | 3 | // Purpose: interface of wxIcon |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
cbea3ec6 FM |
9 | |
10 | ||
11 | /** | |
12 | In wxIcon context this value means: "use the screen depth". | |
13 | */ | |
14 | #define wxICON_SCREEN_DEPTH (-1) | |
15 | ||
16 | ||
23324ae1 FM |
17 | /** |
18 | @class wxIcon | |
7c913512 | 19 | |
cbea3ec6 FM |
20 | An icon is a small rectangular bitmap usually used for denoting a minimized |
21 | application. | |
22 | ||
23 | It differs from a wxBitmap in always having a mask associated with it for | |
24 | transparent drawing. On some platforms, icons and bitmaps are implemented | |
25 | identically, since there is no real distinction between a wxBitmap with a | |
26 | mask and an icon; and there is no specific icon format on some platforms | |
27 | (X-based applications usually standardize on XPMs for small bitmaps and icons). | |
28 | However, some platforms (such as Windows) make the distinction, so a | |
29 | separate class is provided. | |
30 | ||
31 | @remarks | |
32 | It is usually desirable to associate a pertinent icon with a frame. | |
33 | Icons can also be used for other purposes, for example with wxTreeCtrl and wxListCtrl. | |
34 | Icons have different formats on different platforms therefore separate icons | |
35 | will usually be created for the different environments. | |
36 | Platform-specific methods for creating a wxIcon structure are catered for, | |
37 | and this is an occasion where conditional compilation will probably be required. | |
38 | Note that a new icon must be created for every time the icon is to be used | |
39 | for a new window. In Windows, the icon will not be reloaded if it has already | |
40 | been used. | |
41 | An icon allocated to a frame will be deleted when the frame is deleted. | |
42 | For more information please see @ref overview_bitmap. | |
7c913512 | 43 | |
23324ae1 FM |
44 | @library{wxcore} |
45 | @category{gdi} | |
7c913512 | 46 | |
23324ae1 | 47 | @stdobjects |
65874118 | 48 | ::wxNullIcon |
7c913512 | 49 | |
cbea3ec6 FM |
50 | @see @ref overview_bitmap, @ref overview_bitmap_supportedformats, |
51 | wxDC::DrawIcon, wxCursor | |
23324ae1 | 52 | */ |
6f9921e1 | 53 | class wxIcon : public wxGDIObject |
23324ae1 FM |
54 | { |
55 | public: | |
23324ae1 | 56 | /** |
cbea3ec6 | 57 | Default ctor. |
3c4f71cc | 58 | |
cbea3ec6 FM |
59 | Constructs an icon object with no data; an assignment or another member |
60 | function such as LoadFile() must be called subsequently. | |
61 | */ | |
62 | wxIcon(); | |
3c4f71cc | 63 | |
cbea3ec6 FM |
64 | /** |
65 | Copy ctor. | |
66 | */ | |
67 | wxIcon(const wxIcon& icon); | |
3c4f71cc | 68 | |
cbea3ec6 FM |
69 | /* |
70 | Creates an icon from the given data, which can be of arbitrary type. | |
3c4f71cc | 71 | |
cbea3ec6 | 72 | wxIcon(void* data, int type, int width, int height, int depth = -1); |
3c4f71cc | 73 | |
cbea3ec6 FM |
74 | NOTE: this ctor is not implemented by all ports, is somewhat useless |
75 | without further description of the "data" supported formats and | |
76 | uses 'int type' instead of wxBitmapType, so don't document it. | |
77 | */ | |
3c4f71cc | 78 | |
cbea3ec6 FM |
79 | /** |
80 | Creates an icon from an array of bits. | |
81 | You should only use this function for monochrome bitmaps (depth 1) in | |
82 | portable programs: in this case the bits parameter should contain an XBM image. | |
3c4f71cc | 83 | |
cbea3ec6 FM |
84 | For other bit depths, the behaviour is platform dependent: under Windows, |
85 | the data is passed without any changes to the underlying CreateBitmap() API. | |
86 | Under other platforms, only monochrome bitmaps may be created using this | |
87 | constructor and wxImage should be used for creating colour bitmaps from | |
88 | static data. | |
3c4f71cc | 89 | |
cbea3ec6 FM |
90 | @param bits |
91 | Specifies an array of pixel values. | |
92 | @param width | |
a44f3b5a | 93 | The width of the image. |
cbea3ec6 | 94 | @param height |
a44f3b5a | 95 | The height of the image. |
3c4f71cc | 96 | |
1058f652 MB |
97 | @beginWxPerlOnly |
98 | In wxPerl use Wx::Icon->newBits(bits, width, height, depth = -1); | |
99 | @endWxPerlOnly | |
100 | ||
0f6c9085 | 101 | @onlyfor{wxmsw,wxosx} |
cbea3ec6 | 102 | */ |
a44f3b5a | 103 | wxIcon(const char bits[], int width, int height); |
3c4f71cc | 104 | |
cbea3ec6 FM |
105 | /** |
106 | Creates a bitmap from XPM data. | |
107 | To use this constructor, you must first include an XPM file. | |
108 | For example, assuming that the file mybitmap.xpm contains an XPM array | |
109 | of character pointers called @e mybitmap: | |
110 | ||
111 | @code | |
112 | #include "mybitmap.xpm" | |
113 | ... | |
114 | wxIcon *icon = new wxIcon(mybitmap); | |
115 | @endcode | |
116 | ||
117 | A macro, wxICON, is available which creates an icon using an XPM on | |
118 | the appropriate platform, or an icon resource on Windows. | |
119 | ||
120 | @code | |
3cb332c1 | 121 | wxIcon icon(wxICON(sample)); |
cbea3ec6 FM |
122 | |
123 | // Equivalent to: | |
124 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
3cb332c1 | 125 | wxIcon icon(sample_xpm); |
cbea3ec6 FM |
126 | #endif |
127 | ||
128 | #if defined(__WXMSW__) | |
3cb332c1 | 129 | wxIcon icon("sample"); |
cbea3ec6 FM |
130 | #endif |
131 | @endcode | |
1058f652 MB |
132 | |
133 | @beginWxPerlOnly | |
134 | In wxPerl use Wx::Icon->newFromXPM(data). | |
135 | @endWxPerlOnly | |
cbea3ec6 FM |
136 | */ |
137 | wxIcon(const char* const* bits); | |
3c4f71cc | 138 | |
cbea3ec6 FM |
139 | /** |
140 | Loads an icon from a file or resource. | |
3c4f71cc | 141 | |
cbea3ec6 FM |
142 | @param name |
143 | This can refer to a resource name or a filename under MS Windows and X. | |
144 | Its meaning is determined by the @a type parameter. | |
145 | @param type | |
146 | May be one of the ::wxBitmapType values and indicates which type of | |
147 | bitmap should be loaded. See the note in the class detailed description. | |
148 | Note that the wxICON_DEFAULT_TYPE constant has different value under | |
149 | different wxWidgets ports. See the icon.h header for the value it takes | |
150 | for a specific port. | |
151 | @param desiredWidth | |
152 | Specifies the desired width of the icon. This parameter only has | |
153 | an effect in Windows where icon resources can contain several icons | |
154 | of different sizes. | |
155 | @param desiredHeight | |
156 | Specifies the desired height of the icon. This parameter only has | |
157 | an effect in Windows where icon resources can contain several icons | |
158 | of different sizes. | |
159 | ||
160 | @see LoadFile() | |
161 | */ | |
162 | wxIcon(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE, | |
163 | int desiredWidth = -1, int desiredHeight = -1); | |
3c4f71cc | 164 | |
cbea3ec6 FM |
165 | /** |
166 | Loads an icon from the specified location. | |
23324ae1 | 167 | */ |
7c913512 | 168 | wxIcon(const wxIconLocation& loc); |
23324ae1 FM |
169 | |
170 | /** | |
171 | Destructor. | |
cbea3ec6 FM |
172 | See @ref overview_refcount_destruct for more info. |
173 | ||
23324ae1 FM |
174 | If the application omits to delete the icon explicitly, the icon will be |
175 | destroyed automatically by wxWidgets when the application exits. | |
cbea3ec6 FM |
176 | |
177 | @warning | |
23324ae1 FM |
178 | Do not delete an icon that is selected into a memory device context. |
179 | */ | |
adaaa686 | 180 | virtual ~wxIcon(); |
23324ae1 | 181 | |
198c264d | 182 | /** |
cda337fb VZ |
183 | Returns disabled (dimmed) version of the icon. |
184 | ||
185 | This method is available in wxIcon only under wxMSW, other ports only | |
186 | have it in wxBitmap. You can always use wxImage::ConvertToDisabled() | |
187 | and create the icon from wxImage manually however. | |
188 | ||
189 | @onlyfor{wxmsw} | |
190 | ||
198c264d JS |
191 | @since 2.9.0 |
192 | */ | |
193 | wxIcon ConvertToDisabled(unsigned char brightness = 255) const; | |
194 | ||
23324ae1 | 195 | /** |
cbea3ec6 FM |
196 | Copies @a bmp bitmap to this icon. |
197 | Under MS Windows the bitmap must have mask colour set. | |
3c4f71cc | 198 | |
cbea3ec6 | 199 | @see LoadFile() |
23324ae1 FM |
200 | */ |
201 | void CopyFromBitmap(const wxBitmap& bmp); | |
202 | ||
203 | /** | |
cbea3ec6 FM |
204 | Gets the colour depth of the icon. |
205 | A value of 1 indicates a monochrome icon. | |
23324ae1 | 206 | */ |
328f5751 | 207 | int GetDepth() const; |
23324ae1 FM |
208 | |
209 | /** | |
210 | Gets the height of the icon in pixels. | |
cbea3ec6 FM |
211 | |
212 | @see GetWidth() | |
23324ae1 | 213 | */ |
328f5751 | 214 | int GetHeight() const; |
23324ae1 FM |
215 | |
216 | /** | |
217 | Gets the width of the icon in pixels. | |
3c4f71cc | 218 | |
4cc4bfaf | 219 | @see GetHeight() |
23324ae1 | 220 | */ |
328f5751 | 221 | int GetWidth() const; |
23324ae1 FM |
222 | |
223 | /** | |
224 | Returns @true if icon data is present. | |
225 | */ | |
0004982c | 226 | virtual bool IsOk() const; |
23324ae1 FM |
227 | |
228 | /** | |
229 | Loads an icon from a file or resource. | |
3c4f71cc | 230 | |
7c913512 | 231 | @param name |
4cc4bfaf | 232 | Either a filename or a Windows resource name. |
cbea3ec6 | 233 | The meaning of name is determined by the @a type parameter. |
7c913512 | 234 | @param type |
cbea3ec6 FM |
235 | One of the ::wxBitmapType values; see the note in the class |
236 | detailed description. | |
237 | Note that the wxICON_DEFAULT_TYPE constant has different value under | |
238 | different wxWidgets ports. See the icon.h header for the value it takes | |
239 | for a specific port. | |
240 | @param desiredWidth | |
241 | Specifies the desired width of the icon. This parameter only has | |
242 | an effect in Windows where icon resources can contain several icons | |
243 | of different sizes. | |
244 | @param desiredHeight | |
245 | Specifies the desired height of the icon. This parameter only has | |
246 | an effect in Windows where icon resources can contain several icons | |
247 | of different sizes. | |
3c4f71cc | 248 | |
d29a9a8a | 249 | @return @true if the operation succeeded, @false otherwise. |
23324ae1 | 250 | */ |
cbea3ec6 FM |
251 | bool LoadFile(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE, |
252 | int desiredWidth = -1, int desiredHeight = -1); | |
23324ae1 FM |
253 | |
254 | /** | |
255 | Sets the depth member (does not affect the icon data). | |
3c4f71cc | 256 | |
7c913512 | 257 | @param depth |
4cc4bfaf | 258 | Icon depth. |
23324ae1 FM |
259 | */ |
260 | void SetDepth(int depth); | |
261 | ||
262 | /** | |
263 | Sets the height member (does not affect the icon data). | |
3c4f71cc | 264 | |
7c913512 | 265 | @param height |
4cc4bfaf | 266 | Icon height in pixels. |
23324ae1 FM |
267 | */ |
268 | void SetHeight(int height); | |
269 | ||
270 | /** | |
271 | Sets the width member (does not affect the icon data). | |
3c4f71cc | 272 | |
7c913512 | 273 | @param width |
4cc4bfaf | 274 | Icon width in pixels. |
23324ae1 FM |
275 | */ |
276 | void SetWidth(int width); | |
277 | ||
278 | /** | |
cbea3ec6 | 279 | Assignment operator, using @ref overview_refcount. |
3c4f71cc | 280 | |
7c913512 | 281 | @param icon |
4cc4bfaf | 282 | Icon to assign. |
23324ae1 | 283 | */ |
43c48e1e | 284 | wxIcon& operator=(const wxIcon& icon); |
23324ae1 | 285 | }; |
e54c96f1 | 286 | |
e54c96f1 | 287 | /** |
65874118 | 288 | An empty wxIcon. |
e54c96f1 FM |
289 | */ |
290 | wxIcon wxNullIcon; | |
291 | ||
292 |