]>
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 void wxIconRefData::Free()
61 #ifndef __WXMICROWIN__
62 ::DestroyIcon((HICON
) m_hIcon
);
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 wxIcon::wxIcon(const char bits
[], int width
, int height
)
75 wxBitmap
bmp(bits
, width
, height
);
79 wxIcon::wxIcon(const wxString
& iconfile
,
85 LoadFile(iconfile
, flags
, desiredWidth
, desiredHeight
);
88 wxIcon::wxIcon(const wxIconLocation
& loc
)
90 // wxICOFileHandler accepts names in the format "filename;index"
91 wxString fullname
= loc
.GetFileName();
94 fullname
<< _T(';') << loc
.GetIndex();
98 LoadFile(fullname
, wxBITMAP_TYPE_ICO
);
105 wxObjectRefData
*wxIcon::CloneRefData(const wxObjectRefData
*dataOrig
) const
107 const wxIconRefData
*
108 data
= wx_static_cast(const wxIconRefData
*, dataOrig
);
112 // we don't have to copy m_hIcon because we're only called from SetHICON()
113 // which overwrites m_hIcon anyhow currently
115 // and if we're called from SetWidth/Height/Depth(), it doesn't make sense
116 // to copy it neither as the handle would be inconsistent with the new size
117 return new wxIconRefData(*data
);
120 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
122 #ifndef __WXMICROWIN__
123 HICON hicon
= wxBitmapToHICON(bmp
);
126 wxLogLastError(wxT("CreateIconIndirect"));
130 SetHICON((WXHICON
)hicon
);
131 SetSize(bmp
.GetWidth(), bmp
.GetHeight());
133 #endif // __WXMICROWIN__
136 void wxIcon::CreateIconFromXpm(const char **data
)
142 bool wxIcon::LoadFile(const wxString
& filename
,
144 int desiredWidth
, int desiredHeight
)
148 wxGDIImageHandler
*handler
= FindHandler(type
);
156 return handler
->Load(this, filename
, type
, desiredWidth
, desiredHeight
);