1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: Julian Smart
5 // Modified by: 20.11.99 (VZ): don't derive from wxBitmap any more
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "icon.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/bitmap.h"
40 #include "wx/msw/private.h"
42 #if wxUSE_RESOURCE_LOADING_IN_MSW
43 #include "wx/msw/curico.h"
44 #include "wx/msw/curicop.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxIconBase
)
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 void wxIconRefData::Free()
65 ::DestroyIcon((HICON
) m_hIcon
);
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 wxIcon::wxIcon(const char bits
[], int width
, int height
)
77 wxBitmap
bmp(bits
, width
, height
);
81 wxIcon::wxIcon(const wxString
& iconfile
,
87 LoadFile(iconfile
, flags
, desiredWidth
, desiredHeight
);
94 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
97 wxMask
*mask
= bmp
.GetMask();
100 // we must have a mask for an icon, so even if it's probably incorrect,
101 // do create it (grey is the "standard" transparent colour)
102 mask
= new wxMask(bmp
, *wxLIGHT_GREY
);
106 iconInfo
.fIcon
= TRUE
; // we want an icon, not a cursor
107 iconInfo
.hbmMask
= wxInvertMask((HBITMAP
)mask
->GetMaskBitmap());
108 iconInfo
.hbmColor
= GetHbitmapOf(bmp
);
110 /* GRG: black out the transparent area to preserve background
111 * colour, because Windows blits the original bitmap using
112 * SRCINVERT (XOR) after applying the mask to the dest rect.
114 HDC dcSrc
= ::CreateCompatibleDC(NULL
);
115 HDC dcDst
= ::CreateCompatibleDC(NULL
);
116 SelectObject(dcSrc
, (HBITMAP
)mask
->GetMaskBitmap());
117 SelectObject(dcDst
, iconInfo
.hbmColor
);
119 BitBlt(dcDst
, 0, 0, bmp
.GetWidth(), bmp
.GetHeight(), dcSrc
, 0, 0, SRCAND
);
121 SelectObject(dcDst
, NULL
);
122 SelectObject(dcSrc
, NULL
);
126 HICON hicon
= ::CreateIconIndirect(&iconInfo
);
129 wxLogLastError("CreateIconIndirect");
133 SetHICON((WXHICON
)hicon
);
134 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
137 if ( !bmp
.GetMask() )
139 // we created the mask, now delete it
143 // there are some functions in curico.cpp which probably could be used
145 wxFAIL_MSG("not implemented");
149 void wxIcon::CreateIconFromXpm(const char **data
)
155 bool wxIcon::LoadFile(const wxString
& filename
,
157 int desiredWidth
, int desiredHeight
)
161 wxGDIImageHandler
*handler
= FindHandler(type
);
169 return handler
->Load(this, filename
, type
, desiredWidth
, desiredHeight
);