]>
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 USE_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
)[], const int WXUNUSED(width
), const int WXUNUSED(height
))
75 wxIcon::wxIcon(const wxString
& icon_file
, const 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
, const 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
, const long flags
,
120 int desiredWidth
, int desiredHeight
)
122 #if USE_RESOURCE_LOADING_IN_MSW
123 if ( bitmap
->IsKindOf(CLASSINFO(wxIcon
)) )
125 wxIcon
*icon
= (wxIcon
*)bitmap
;
127 WXHICON hIcon
= (WXHICON
) ReadIconFile((char *)(const char *)name
, wxGetInstance(), &width
, &height
);
129 ((wxIconRefData
*)icon
->GetRefData())->m_hIcon
= hIcon
;
130 ((wxIconRefData
*)icon
->GetRefData())->m_ok
= (((wxIconRefData
*)icon
->GetRefData())->m_hIcon
!= 0);
131 return ((wxIconRefData
*)icon
->GetRefData())->m_ok
;
140 bool wxICOResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, const 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
);
158 DWORD vers = GetVersion() ;
159 WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s
160 // Win32s doesn't have GetIconInfo function...
161 if (M_ICONHANDLERDATA->m_hIcon && (high&0x8000)==0 )
163 if (M_ICONHANDLERDATA
->m_hIcon
&& wxGetOsVersion()==wxWINDOWS_NT
)
166 if (::GetIconInfo((HICON
) M_ICONHANDLERDATA
->m_hIcon
, &info
))
168 HBITMAP ms_bitmap
= info
.hbmMask
;
172 ::GetObject(ms_bitmap
, sizeof(BITMAP
), (LPSTR
) &bm
);
173 M_ICONHANDLERDATA
->m_width
= bm
.bmWidth
;
174 M_ICONHANDLERDATA
->m_height
= bm
.bmHeight
;
177 ::DeleteObject(info
.hbmMask
) ;
179 ::DeleteObject(info
.hbmColor
) ;
183 M_ICONHANDLERDATA
->m_width
= 32;
184 M_ICONHANDLERDATA
->m_height
= 32;
186 M_ICONHANDLERDATA
->m_ok
= (M_ICONHANDLERDATA
->m_hIcon
!= 0);
187 return M_ICONHANDLERDATA
->m_ok
;