]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/icon.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxIcon
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
11 In wxIcon context this value means: "use the screen depth".
13 #define wxICON_SCREEN_DEPTH (-1)
19 An icon is a small rectangular bitmap usually used for denoting a minimized
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.
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
40 An icon allocated to a frame will be deleted when the frame is deleted.
41 For more information please see @ref overview_bitmap.
49 @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
50 wxDC::DrawIcon, wxCursor
52 class wxIcon
: public wxGDIObject
58 Constructs an icon object with no data; an assignment or another member
59 function such as LoadFile() must be called subsequently.
66 wxIcon(const wxIcon
& icon
);
69 Creates an icon from the given data, which can be of arbitrary type.
71 wxIcon(void* data, int type, int width, int height, int depth = -1);
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.
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.
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
90 Specifies an array of pixel values.
92 The width of the image.
94 The height of the image.
97 In wxPerl use Wx::Icon->newBits(bits, width, height, depth = -1);
100 @onlyfor{wxmsw,wxosx}
102 wxIcon(const char bits
[], int width
, int height
);
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:
111 #include "mybitmap.xpm"
113 wxIcon *icon = new wxIcon(mybitmap);
116 A macro, wxICON, is available which creates an icon using an XPM on
117 the appropriate platform, or an icon resource on Windows.
120 wxIcon icon(wxICON(sample));
123 #if defined(__WXGTK__) || defined(__WXMOTIF__)
124 wxIcon icon(sample_xpm);
127 #if defined(__WXMSW__)
128 wxIcon icon("sample");
133 In wxPerl use Wx::Icon->newFromXPM(data).
136 wxIcon(const char* const* bits
);
139 Loads an icon from a file or resource.
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.
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
151 Specifies the desired width of the icon. This parameter only has
152 an effect in Windows where icon resources can contain several icons
155 Specifies the desired height of the icon. This parameter only has
156 an effect in Windows where icon resources can contain several icons
161 wxIcon(const wxString
& name
, wxBitmapType type
= wxICON_DEFAULT_TYPE
,
162 int desiredWidth
= -1, int desiredHeight
= -1);
165 Loads an icon from the specified location.
167 wxIcon(const wxIconLocation
& loc
);
171 See @ref overview_refcount_destruct for more info.
173 If the application omits to delete the icon explicitly, the icon will be
174 destroyed automatically by wxWidgets when the application exits.
177 Do not delete an icon that is selected into a memory device context.
182 Attach a Windows icon handle.
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.
189 @return @true if successful.
195 bool CreateFromHICON(WXHICON icon
);
198 Returns disabled (dimmed) version of the icon.
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.
208 wxIcon
ConvertToDisabled(unsigned char brightness
= 255) const;
211 Copies @a bmp bitmap to this icon.
212 Under MS Windows the bitmap must have mask colour set.
216 void CopyFromBitmap(const wxBitmap
& bmp
);
219 Gets the colour depth of the icon.
220 A value of 1 indicates a monochrome icon.
222 int GetDepth() const;
225 Gets the height of the icon in pixels.
229 int GetHeight() const;
232 Gets the width of the icon in pixels.
236 int GetWidth() const;
239 Returns @true if icon data is present.
241 virtual bool IsOk() const;
244 Loads an icon from a file or resource.
247 Either a filename or a Windows resource name.
248 The meaning of name is determined by the @a type parameter.
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
256 Specifies the desired width of the icon. This parameter only has
257 an effect in Windows where icon resources can contain several icons
260 Specifies the desired height of the icon. This parameter only has
261 an effect in Windows where icon resources can contain several icons
264 @return @true if the operation succeeded, @false otherwise.
266 bool LoadFile(const wxString
& name
, wxBitmapType type
= wxICON_DEFAULT_TYPE
,
267 int desiredWidth
= -1, int desiredHeight
= -1);
270 Sets the depth member (does not affect the icon data).
275 void SetDepth(int depth
);
278 Sets the height member (does not affect the icon data).
281 Icon height in pixels.
283 void SetHeight(int height
);
286 Sets the width member (does not affect the icon data).
289 Icon width in pixels.
291 void SetWidth(int width
);
294 Assignment operator, using @ref overview_refcount.
299 wxIcon
& operator=(const wxIcon
& icon
);