]>
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
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
31 #include "wx/bitmap.h"
35 #include "wx/msw/private.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
43 // ============================================================================
45 // ============================================================================
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 void wxIconRefData::Free()
55 #ifndef __WXMICROWIN__
56 ::DestroyIcon((HICON
) m_hIcon
);
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 wxIcon::wxIcon(const char bits
[], int width
, int height
)
69 wxBitmap
bmp(bits
, width
, height
);
73 wxIcon::wxIcon(const wxString
& iconfile
,
79 LoadFile(iconfile
, type
, desiredWidth
, desiredHeight
);
82 wxIcon::wxIcon(const wxIconLocation
& loc
)
84 // wxICOFileHandler accepts names in the format "filename;index"
85 wxString fullname
= loc
.GetFileName();
88 fullname
<< wxT(';') << loc
.GetIndex();
92 LoadFile(fullname
, wxBITMAP_TYPE_ICO
);
99 wxObjectRefData
*wxIcon::CloneRefData(const wxObjectRefData
*dataOrig
) const
101 const wxIconRefData
*
102 data
= static_cast<const wxIconRefData
*>(dataOrig
);
106 // we don't have to copy m_hIcon because we're only called from SetHICON()
107 // which overwrites m_hIcon anyhow currently
109 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
110 // to copy it neither as the handle would be inconsistent with the new size
111 return new wxIconRefData(*data
);
114 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
116 #ifndef __WXMICROWIN__
117 HICON hicon
= wxBitmapToHICON(bmp
);
120 wxLogLastError(wxT("CreateIconIndirect"));
124 SetHICON((WXHICON
)hicon
);
125 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
127 #endif // __WXMICROWIN__
130 void wxIcon::CreateIconFromXpm(const char* const* data
)
136 bool wxIcon::LoadFile(const wxString
& filename
,
138 int desiredWidth
, int desiredHeight
)
142 wxGDIImageHandler
*handler
= FindHandler(type
);
146 // load via wxBitmap which, in turn, uses wxImage allowing us to
147 // support more formats
149 if ( !bmp
.LoadFile(filename
, type
) )
156 return handler
->Load(this, filename
, type
, desiredWidth
, desiredHeight
);
159 bool wxIcon::CreateFromHICON(WXHICON icon
)
165 SetSize(wxGetHiconSize(icon
));