]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/icon.cpp
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
32 #include "wx/bitmap.h"
36 #include "wx/msw/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
44 // ============================================================================
46 // ============================================================================
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 void wxIconRefData::Free()
56 #ifndef __WXMICROWIN__
57 ::DestroyIcon((HICON
) m_hIcon
);
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 wxIcon::wxIcon(const char bits
[], int width
, int height
)
70 wxBitmap
bmp(bits
, width
, height
);
74 wxIcon::wxIcon(const wxString
& iconfile
,
80 LoadFile(iconfile
, flags
, desiredWidth
, desiredHeight
);
83 wxIcon::wxIcon(const wxIconLocation
& loc
)
85 // wxICOFileHandler accepts names in the format "filename;index"
86 wxString fullname
= loc
.GetFileName();
89 fullname
<< _T(';') << loc
.GetIndex();
93 LoadFile(fullname
, wxBITMAP_TYPE_ICO
);
100 wxObjectRefData
*wxIcon::CloneRefData(const wxObjectRefData
*dataOrig
) const
102 const wxIconRefData
*
103 data
= wx_static_cast(const wxIconRefData
*, dataOrig
);
107 // we don't have to copy m_hIcon because we're only called from SetHICON()
108 // which overwrites m_hIcon anyhow currently
110 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
111 // to copy it neither as the handle would be inconsistent with the new size
112 return new wxIconRefData(*data
);
115 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
117 #ifndef __WXMICROWIN__
118 HICON hicon
= wxBitmapToHICON(bmp
);
121 wxLogLastError(wxT("CreateIconIndirect"));
125 SetHICON((WXHICON
)hicon
);
126 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
128 #endif // __WXMICROWIN__
131 void wxIcon::CreateIconFromXpm(const char **data
)
137 bool wxIcon::LoadFile(const wxString
& filename
,
139 int desiredWidth
, int desiredHeight
)
143 wxGDIImageHandler
*handler
= FindHandler(type
);
151 return handler
->Load(this, filename
, type
, desiredWidth
, desiredHeight
);