]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/icon.cpp
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"
41 #include "wx/msw/private.h"
43 #if wxUSE_RESOURCE_LOADING_IN_MSW
44 #include "wx/msw/curico.h"
45 #include "wx/msw/curicop.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 void wxIconRefData::Free()
66 #ifndef __WXMICROWIN__
67 ::DestroyIcon((HICON
) m_hIcon
);
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 wxIcon::wxIcon(const char bits
[], int width
, int height
)
80 wxBitmap
bmp(bits
, width
, height
);
84 wxIcon::wxIcon(const wxString
& iconfile
,
90 LoadFile(iconfile
, flags
, desiredWidth
, desiredHeight
);
97 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
99 #ifndef __WXMICROWIN__
101 wxMask
*mask
= bmp
.GetMask();
104 // we must have a mask for an icon, so even if it's probably incorrect,
105 // do create it (grey is the "standard" transparent colour)
106 mask
= new wxMask(bmp
, *wxLIGHT_GREY
);
110 iconInfo
.fIcon
= TRUE
; // we want an icon, not a cursor
111 iconInfo
.hbmMask
= wxInvertMask((HBITMAP
)mask
->GetMaskBitmap());
112 iconInfo
.hbmColor
= GetHbitmapOf(bmp
);
114 // black out the transparent area to preserve background colour, because
115 // Windows blits the original bitmap using SRCINVERT (XOR) after applying
116 // the mask to the dest rect.
118 MemoryHDC dcSrc
, dcDst
;
119 SelectInHDC
selectMask(dcSrc
, (HBITMAP
)mask
->GetMaskBitmap()),
120 selectBitmap(dcDst
, iconInfo
.hbmColor
);
122 if ( !::BitBlt(dcDst
, 0, 0, bmp
.GetWidth(), bmp
.GetHeight(),
123 dcSrc
, 0, 0, SRCAND
) )
125 wxLogLastError(_T("BitBlt"));
129 HICON hicon
= ::CreateIconIndirect(&iconInfo
);
132 wxLogLastError(wxT("CreateIconIndirect"));
136 SetHICON((WXHICON
)hicon
);
137 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
140 if ( !bmp
.GetMask() )
142 // we created the mask, now delete it
146 // delete the inverted mask bitmap we created as well
147 ::DeleteObject(iconInfo
.hbmMask
);
149 // there are some functions in curico.cpp which probably could be used
151 // This probably doesn't work.
152 HBITMAP hBitmap
= (HBITMAP
) bmp
.GetHBITMAP();
153 HICON hIcon
= MakeIconFromBitmap((HINSTANCE
) wxGetInstance(), hBitmap
);
156 SetHICON((WXHICON
)hIcon
);
157 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
160 // wxFAIL_MSG("Bitmap to icon conversion (including use of XPMs for icons) not implemented");
165 void wxIcon::CreateIconFromXpm(const char **data
)
171 bool wxIcon::LoadFile(const wxString
& filename
,
173 int desiredWidth
, int desiredHeight
)
177 wxGDIImageHandler
*handler
= FindHandler(type
);
185 return handler
->Load(this, filename
, type
, desiredWidth
, desiredHeight
);