]>
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"
35 #if wxUSE_RESOURCE_LOADING_IN_MSW
36 #include "wx/msw/curico.h"
37 #include "wx/msw/curicop.h"
40 #if !USE_SHARED_LIBRARIES
41 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
42 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxBitmapHandler
)
43 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxBitmapHandler
)
51 wxIconRefData::wxIconRefData(void)
53 m_hIcon
= (WXHICON
) NULL
;
56 wxIconRefData::~wxIconRefData(void)
59 ::DestroyIcon((HICON
) m_hIcon
);
66 wxIcon::wxIcon(const char WXUNUSED(bits
)[], int WXUNUSED(width
), int WXUNUSED(height
))
70 wxIcon::wxIcon(const wxString
& icon_file
, long flags
,
71 int desiredWidth
, int desiredHeight
)
74 LoadFile(icon_file
, flags
, desiredWidth
, desiredHeight
);
81 bool wxIcon::FreeResource(bool force
)
83 if (M_ICONDATA
&& M_ICONDATA
->m_hIcon
)
85 DestroyIcon((HICON
) M_ICONDATA
->m_hIcon
);
86 M_ICONDATA
->m_hIcon
= (WXHICON
) NULL
;
91 bool wxIcon::LoadFile(const wxString
& filename
, long type
,
92 int desiredWidth
, int desiredHeight
)
96 m_refData
= new wxIconRefData
;
98 wxBitmapHandler
*handler
= FindHandler(type
);
101 return handler
->LoadFile(this, filename
, type
, desiredWidth
, desiredHeight
);
106 void wxIcon::SetHICON(WXHICON ico
)
109 m_refData
= new wxIconRefData
;
111 M_ICONDATA
->m_hIcon
= ico
;
114 bool wxICOFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
115 int desiredWidth
, int desiredHeight
)
117 #if wxUSE_RESOURCE_LOADING_IN_MSW
118 if ( bitmap
->IsKindOf(CLASSINFO(wxIcon
)) )
120 wxIcon
*icon
= (wxIcon
*)bitmap
;
121 wxIconRefData
*data
= (wxIconRefData
*)icon
->GetRefData();
122 data
->m_hIcon
= (WXHICON
)ReadIconFile((char *)name
.c_str(), wxGetInstance(),
123 &data
->m_width
, &data
->m_height
);
125 data
->m_ok
= data
->m_hIcon
!= 0;
135 bool wxICOResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
136 int desiredWidth
, int desiredHeight
)
138 if ( bitmap
->IsKindOf(CLASSINFO(wxIcon
)) )
140 #if defined(__WIN32__) && !defined(__SC__)
141 if (desiredWidth
> -1 && desiredHeight
> -1)
143 M_ICONHANDLERDATA
->m_hIcon
= (WXHICON
) ::LoadImage(wxGetInstance(), name
, IMAGE_ICON
, desiredWidth
, desiredHeight
, LR_DEFAULTCOLOR
);
148 M_ICONHANDLERDATA
->m_hIcon
= (WXHICON
) ::LoadIcon(wxGetInstance(), name
);
152 // Win32s doesn't have GetIconInfo function...
153 if (M_ICONHANDLERDATA
->m_hIcon
&& wxGetOsVersion()!=wxWIN32S
)
156 if (::GetIconInfo((HICON
) M_ICONHANDLERDATA
->m_hIcon
, &info
))
158 HBITMAP ms_bitmap
= info
.hbmMask
;
162 ::GetObject(ms_bitmap
, sizeof(BITMAP
), (LPSTR
) &bm
);
163 M_ICONHANDLERDATA
->m_width
= bm
.bmWidth
;
164 M_ICONHANDLERDATA
->m_height
= bm
.bmHeight
;
167 ::DeleteObject(info
.hbmMask
) ;
169 ::DeleteObject(info
.hbmColor
) ;
173 M_ICONHANDLERDATA
->m_width
= 32;
174 M_ICONHANDLERDATA
->m_height
= 32;
176 // Override the found values with desired values
177 if (desiredWidth
> -1 && desiredHeight
> -1)
179 M_ICONHANDLERDATA
->m_width
= desiredWidth
;
180 M_ICONHANDLERDATA
->m_height
= desiredHeight
;
183 M_ICONHANDLERDATA
->m_ok
= (M_ICONHANDLERDATA
->m_hIcon
!= 0);
184 return M_ICONHANDLERDATA
->m_ok
;