]>
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"
33 #include "wx/bitmap.h"
37 #include "wx/msw/private.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 void wxIconRefData::Free()
57 #ifndef __WXMICROWIN__
58 ::DestroyIcon((HICON
) m_hIcon
);
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 wxIcon::wxIcon(const char bits
[], int width
, int height
)
71 wxBitmap
bmp(bits
, width
, height
);
75 wxIcon::wxIcon(const wxString
& iconfile
,
81 LoadFile(iconfile
, flags
, desiredWidth
, desiredHeight
);
84 wxIcon::wxIcon(const wxIconLocation
& loc
)
86 // wxICOFileHandler accepts names in the format "filename;index"
87 wxString fullname
= loc
.GetFileName();
90 fullname
<< _T(';') << loc
.GetIndex();
94 LoadFile(fullname
, wxBITMAP_TYPE_ICO
);
101 wxObjectRefData
*wxIcon::CloneRefData(const wxObjectRefData
*dataOrig
) const
103 const wxIconRefData
*
104 data
= wx_static_cast(const wxIconRefData
*, dataOrig
);
108 // we don't have to copy m_hIcon because we're only called from SetHICON()
109 // which overwrites m_hIcon anyhow currently
111 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
112 // to copy it neither as the handle would be inconsistent with the new size
113 return new wxIconRefData(*data
);
116 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
118 #ifndef __WXMICROWIN__
119 HICON hicon
= wxBitmapToHICON(bmp
);
122 wxLogLastError(wxT("CreateIconIndirect"));
126 SetHICON((WXHICON
)hicon
);
127 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
129 #endif // __WXMICROWIN__
132 void wxIcon::CreateIconFromXpm(const char **data
)
138 bool wxIcon::LoadFile(const wxString
& filename
,
140 int desiredWidth
, int desiredHeight
)
144 wxGDIImageHandler
*handler
= FindHandler(type
);
152 return handler
->Load(this, filename
, type
, desiredWidth
, desiredHeight
);