]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: icon.h | |
3 | // Purpose: interface of wxIcon | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | ||
10 | ||
11 | /** | |
12 | In wxIcon context this value means: "use the screen depth". | |
13 | */ | |
14 | #define wxICON_SCREEN_DEPTH (-1) | |
15 | ||
16 | ||
17 | /** | |
18 | @class wxIcon | |
19 | ||
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. | |
43 | ||
44 | @library{wxcore} | |
45 | @category{gdi} | |
46 | ||
47 | @stdobjects | |
48 | ::wxNullIcon | |
49 | ||
50 | @see @ref overview_bitmap, @ref overview_bitmap_supportedformats, | |
51 | wxDC::DrawIcon, wxCursor | |
52 | */ | |
53 | class wxIcon : public wxBitmap | |
54 | { | |
55 | public: | |
56 | /** | |
57 | Default ctor. | |
58 | ||
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(); | |
63 | ||
64 | /** | |
65 | Copy ctor. | |
66 | */ | |
67 | wxIcon(const wxIcon& icon); | |
68 | ||
69 | /* | |
70 | Creates an icon from the given data, which can be of arbitrary type. | |
71 | ||
72 | wxIcon(void* data, int type, int width, int height, int depth = -1); | |
73 | ||
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 | */ | |
78 | ||
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. | |
83 | ||
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. | |
89 | ||
90 | @param bits | |
91 | Specifies an array of pixel values. | |
92 | @param width | |
93 | Specifies the width of the bitmap. | |
94 | @param height | |
95 | Specifies the height of the bitmap. | |
96 | @param depth | |
97 | Specifies the depth of the bitmap. | |
98 | If this is omitted, then a value of 1 (monochrome bitmap) is used. | |
99 | */ | |
100 | wxIcon(const char bits[], int width, int height, int depth = 1); | |
101 | ||
102 | ||
103 | /** | |
104 | Creates a new icon. A depth of ::wxICON_SCREEN_DEPTH indicates the | |
105 | depth of the current screen or visual. | |
106 | ||
107 | Some platforms only support 1 for monochrome and ::wxICON_SCREEN_DEPTH for | |
108 | the current colour setting. | |
109 | */ | |
110 | wxIcon(int width, int height, int depth = wxICON_SCREEN_DEPTH); | |
111 | ||
112 | /** | |
113 | Creates a bitmap from XPM data. | |
114 | To use this constructor, you must first include an XPM file. | |
115 | For example, assuming that the file mybitmap.xpm contains an XPM array | |
116 | of character pointers called @e mybitmap: | |
117 | ||
118 | @code | |
119 | #include "mybitmap.xpm" | |
120 | ... | |
121 | wxIcon *icon = new wxIcon(mybitmap); | |
122 | @endcode | |
123 | ||
124 | A macro, wxICON, is available which creates an icon using an XPM on | |
125 | the appropriate platform, or an icon resource on Windows. | |
126 | ||
127 | @code | |
128 | wxIcon icon(wxICON(mondrian)); | |
129 | ||
130 | // Equivalent to: | |
131 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
132 | wxIcon icon(mondrian_xpm); | |
133 | #endif | |
134 | ||
135 | #if defined(__WXMSW__) | |
136 | wxIcon icon("mondrian"); | |
137 | #endif | |
138 | @endcode | |
139 | */ | |
140 | wxIcon(const char* const* bits); | |
141 | ||
142 | /** | |
143 | Loads an icon from a file or resource. | |
144 | ||
145 | @param name | |
146 | This can refer to a resource name or a filename under MS Windows and X. | |
147 | Its meaning is determined by the @a type parameter. | |
148 | @param type | |
149 | May be one of the ::wxBitmapType values and indicates which type of | |
150 | bitmap should be loaded. See the note in the class detailed description. | |
151 | Note that the wxICON_DEFAULT_TYPE constant has different value under | |
152 | different wxWidgets ports. See the icon.h header for the value it takes | |
153 | for a specific port. | |
154 | @param desiredWidth | |
155 | Specifies the desired width of the icon. This parameter only has | |
156 | an effect in Windows where icon resources can contain several icons | |
157 | of different sizes. | |
158 | @param desiredHeight | |
159 | Specifies the desired height of the icon. This parameter only has | |
160 | an effect in Windows where icon resources can contain several icons | |
161 | of different sizes. | |
162 | ||
163 | @see LoadFile() | |
164 | */ | |
165 | wxIcon(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE, | |
166 | int desiredWidth = -1, int desiredHeight = -1); | |
167 | ||
168 | /** | |
169 | Loads an icon from the specified location. | |
170 | */ | |
171 | wxIcon(const wxIconLocation& loc); | |
172 | ||
173 | /** | |
174 | Destructor. | |
175 | See @ref overview_refcount_destruct for more info. | |
176 | ||
177 | If the application omits to delete the icon explicitly, the icon will be | |
178 | destroyed automatically by wxWidgets when the application exits. | |
179 | ||
180 | @warning | |
181 | Do not delete an icon that is selected into a memory device context. | |
182 | */ | |
183 | virtual ~wxIcon(); | |
184 | ||
185 | /** | |
186 | Copies @a bmp bitmap to this icon. | |
187 | Under MS Windows the bitmap must have mask colour set. | |
188 | ||
189 | @see LoadFile() | |
190 | */ | |
191 | void CopyFromBitmap(const wxBitmap& bmp); | |
192 | ||
193 | /** | |
194 | Gets the colour depth of the icon. | |
195 | A value of 1 indicates a monochrome icon. | |
196 | */ | |
197 | int GetDepth() const; | |
198 | ||
199 | /** | |
200 | Gets the height of the icon in pixels. | |
201 | ||
202 | @see GetWidth() | |
203 | */ | |
204 | int GetHeight() const; | |
205 | ||
206 | /** | |
207 | Gets the width of the icon in pixels. | |
208 | ||
209 | @see GetHeight() | |
210 | */ | |
211 | int GetWidth() const; | |
212 | ||
213 | /** | |
214 | Returns @true if icon data is present. | |
215 | */ | |
216 | virtual bool IsOk() const; | |
217 | ||
218 | /** | |
219 | Loads an icon from a file or resource. | |
220 | ||
221 | @param name | |
222 | Either a filename or a Windows resource name. | |
223 | The meaning of name is determined by the @a type parameter. | |
224 | @param type | |
225 | One of the ::wxBitmapType values; see the note in the class | |
226 | detailed description. | |
227 | Note that the wxICON_DEFAULT_TYPE constant has different value under | |
228 | different wxWidgets ports. See the icon.h header for the value it takes | |
229 | for a specific port. | |
230 | @param desiredWidth | |
231 | Specifies the desired width of the icon. This parameter only has | |
232 | an effect in Windows where icon resources can contain several icons | |
233 | of different sizes. | |
234 | @param desiredHeight | |
235 | Specifies the desired height of the icon. This parameter only has | |
236 | an effect in Windows where icon resources can contain several icons | |
237 | of different sizes. | |
238 | ||
239 | @return @true if the operation succeeded, @false otherwise. | |
240 | */ | |
241 | bool LoadFile(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE, | |
242 | int desiredWidth = -1, int desiredHeight = -1); | |
243 | ||
244 | /** | |
245 | Sets the depth member (does not affect the icon data). | |
246 | ||
247 | @param depth | |
248 | Icon depth. | |
249 | */ | |
250 | void SetDepth(int depth); | |
251 | ||
252 | /** | |
253 | Sets the height member (does not affect the icon data). | |
254 | ||
255 | @param height | |
256 | Icon height in pixels. | |
257 | */ | |
258 | void SetHeight(int height); | |
259 | ||
260 | /** | |
261 | Sets the width member (does not affect the icon data). | |
262 | ||
263 | @param width | |
264 | Icon width in pixels. | |
265 | */ | |
266 | void SetWidth(int width); | |
267 | ||
268 | /** | |
269 | Assignment operator, using @ref overview_refcount. | |
270 | ||
271 | @param icon | |
272 | Icon to assign. | |
273 | */ | |
274 | wxIcon& operator=(const wxIcon& icon); | |
275 | }; | |
276 | ||
277 | /** | |
278 | An empty wxIcon. | |
279 | */ | |
280 | wxIcon wxNullIcon; | |
281 | ||
282 |