]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "icon.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
32 #include "wx/msw/private.h"
37 #include "..\..\contrib\wxxpm\libxpm.34b\lib\xpm34.h"
40 #if wxUSE_RESOURCE_LOADING_IN_MSW
41 #include "wx/msw/curico.h"
42 #include "wx/msw/curicop.h"
45 #if !USE_SHARED_LIBRARIES
46 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
47 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxBitmapHandler
)
48 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxBitmapHandler
)
56 wxIconRefData::wxIconRefData(void)
58 m_hIcon
= (WXHICON
) NULL
;
61 wxIconRefData::~wxIconRefData(void)
64 ::DestroyIcon((HICON
) m_hIcon
);
71 wxIcon::wxIcon(const char WXUNUSED(bits
)[], int WXUNUSED(width
), int WXUNUSED(height
))
75 wxIcon::wxIcon(const wxString
& icon_file
, long flags
,
76 int desiredWidth
, int desiredHeight
)
79 LoadFile(icon_file
, flags
, desiredWidth
, desiredHeight
);
86 bool wxIcon::FreeResource(bool force
)
88 if (M_ICONDATA
&& M_ICONDATA
->m_hIcon
)
90 DestroyIcon((HICON
) M_ICONDATA
->m_hIcon
);
91 M_ICONDATA
->m_hIcon
= (WXHICON
) NULL
;
96 bool wxIcon::LoadFile(const wxString
& filename
, long type
,
97 int desiredWidth
, int desiredHeight
)
101 m_refData
= new wxIconRefData
;
103 wxBitmapHandler
*handler
= FindHandler(type
);
106 return handler
->LoadFile(this, filename
, type
, desiredWidth
, desiredHeight
);
111 void wxIcon::SetHICON(WXHICON ico
)
114 m_refData
= new wxIconRefData
;
116 M_ICONDATA
->m_hIcon
= ico
;
119 bool wxICOFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
120 int desiredWidth
, int desiredHeight
)
122 #if wxUSE_RESOURCE_LOADING_IN_MSW
123 if ( bitmap
->IsKindOf(CLASSINFO(wxIcon
)) )
125 wxIcon
*icon
= (wxIcon
*)bitmap
;
126 wxIconRefData
*data
= (wxIconRefData
*)icon
->GetRefData();
127 data
->m_hIcon
= (WXHICON
)ReadIconFile((char *)name
.c_str(), wxGetInstance(),
128 &data
->m_width
, &data
->m_height
);
130 data
->m_ok
= data
->m_hIcon
!= 0;
140 bool wxICOResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
141 int desiredWidth
, int desiredHeight
)
143 if ( bitmap
->IsKindOf(CLASSINFO(wxIcon
)) )
145 #if defined(__WIN32__)
146 if (desiredWidth
> -1 && desiredHeight
> -1)
148 M_ICONHANDLERDATA
->m_hIcon
= (WXHICON
) ::LoadImage(wxGetInstance(), name
, IMAGE_ICON
, desiredWidth
, desiredHeight
, LR_DEFAULTCOLOR
);
153 M_ICONHANDLERDATA
->m_hIcon
= (WXHICON
) ::LoadIcon(wxGetInstance(), name
);
157 // Win32s doesn't have GetIconInfo function...
158 if (M_ICONHANDLERDATA
->m_hIcon
&& wxGetOsVersion()!=wxWIN32S
)
161 if (::GetIconInfo((HICON
) M_ICONHANDLERDATA
->m_hIcon
, &info
))
163 HBITMAP ms_bitmap
= info
.hbmMask
;
167 ::GetObject(ms_bitmap
, sizeof(BITMAP
), (LPSTR
) &bm
);
168 M_ICONHANDLERDATA
->m_width
= bm
.bmWidth
;
169 M_ICONHANDLERDATA
->m_height
= bm
.bmHeight
;
172 ::DeleteObject(info
.hbmMask
) ;
174 ::DeleteObject(info
.hbmColor
) ;
178 M_ICONHANDLERDATA
->m_width
= 32;
179 M_ICONHANDLERDATA
->m_height
= 32;
181 M_ICONHANDLERDATA
->m_ok
= (M_ICONHANDLERDATA
->m_hIcon
!= 0);
182 return M_ICONHANDLERDATA
->m_ok
;