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