]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
28 #include "wx/os2/private.h"
33 #if !USE_SHARED_LIBRARIES
34 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
35 IMPLEMENT_DYNAMIC_CLASS(wxICOFileHandler
, wxBitmapHandler
)
36 IMPLEMENT_DYNAMIC_CLASS(wxICOResourceHandler
, wxBitmapHandler
)
43 wxIconRefData::wxIconRefData()
45 m_hIcon
= (WXHICON
) NULL
;
48 wxIconRefData::~wxIconRefData()
52 // TODO ::DestroyIcon((HICON) m_hIcon);
59 wxIcon::wxIcon(const char WXUNUSED(bits
)[], int WXUNUSED(width
), int WXUNUSED(height
))
63 wxIcon::wxIcon(const wxString
& icon_file
, long flags
,
64 int desiredWidth
, int desiredHeight
)
67 LoadFile(icon_file
, flags
, desiredWidth
, desiredHeight
);
74 bool wxIcon::LoadFile(const wxString
& filename
, long type
,
75 int desiredWidth
, int desiredHeight
)
79 m_refData
= new wxIconRefData
;
81 wxBitmapHandler
*handler
= FindHandler(type
);
84 return handler
->LoadFile(this, filename
, type
, desiredWidth
, desiredHeight
);
89 void wxIcon::SetHICON(WXHICON ico
)
92 m_refData
= new wxIconRefData
;
94 M_ICONDATA
->m_hIcon
= ico
;
97 bool wxICOFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
98 int desiredWidth
, int desiredHeight
)
103 bool wxICOResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
104 int desiredWidth
, int desiredHeight
)
108 if ( bitmap->IsKindOf(CLASSINFO(wxIcon)) )
110 if (desiredWidth > -1 && desiredHeight > -1)
112 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadImage(wxGetInstance(), name, IMAGE_ICON, desiredWidth, desiredHeight, LR_DEFAULTCOLOR);
116 M_ICONHANDLERDATA->m_hIcon = (WXHICON) ::LoadIcon(wxGetInstance(), name);
120 if (::GetIconInfo((HICON) M_ICONHANDLERDATA->m_hIcon, &info))
122 HBITMAP ms_bitmap = info.hbmMask ;
126 ::GetObject(ms_bitmap, sizeof(BITMAP), (LPSTR) &bm);
127 M_ICONHANDLERDATA->m_width = bm.bmWidth;
128 M_ICONHANDLERDATA->m_height = bm.bmHeight;
131 ::DeleteObject(info.hbmMask) ;
133 ::DeleteObject(info.hbmColor) ;
136 // Override the found values with desired values
137 if (desiredWidth > -1 && desiredHeight > -1)
139 M_ICONHANDLERDATA->m_width = desiredWidth;
140 M_ICONHANDLERDATA->m_height = desiredHeight;
143 M_ICONHANDLERDATA->m_ok = (M_ICONHANDLERDATA->m_hIcon != 0);
144 return M_ICONHANDLERDATA->m_ok;