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 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
35 // ============================================================================
37 // ============================================================================
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 void wxIconRefData::Free()
46 ::WinFreeFileIcon((HPOINTER
)m_hIcon
);
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
59 const char WXUNUSED(bits
)[]
60 , int WXUNUSED(nWidth
)
61 , int WXUNUSED(nHeight
)
68 const wxString
& rIconFile
76 // A very poor hack, but we have to have separate icon files from windows
77 // So we have a modified name where replace the last three characters
78 // with os2. Also need the extension.
80 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.Length() - 3);
82 sOs2Name
+= "Os2.ico";
94 void wxIcon::CreateIconFromXpm(
98 wxBitmap
vBmp(ppData
);
100 CopyFromBitmap(vBmp
);
106 } // end of wxIcon::CreateIconFromXpm
108 void wxIcon::CopyFromBitmap(
112 wxMask
* pMask
= rBmp
.GetMask();
113 HBITMAP hBmp
= NULLHANDLE
;
114 HBITMAP hBmpMask
= NULLHANDLE
;
115 HBITMAP hOldBitmap
= NULLHANDLE
;
123 // We must have a mask for an icon, so even if it's probably incorrect,
124 // do create it (grey is the "standard" transparent colour)
126 pMask
= new wxMask( rBmp
131 BITMAPINFOHEADER2 vHeader
;
132 SIZEL vSize
= {0, 0};
133 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
134 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
135 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
136 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
137 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
138 POINTL vPoint
[4] = { 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight(),
139 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight()
141 POINTL vPointMask
[4] = { 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight() * 2,
142 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight()
145 POINTERINFO vIconInfo
;
147 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
148 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
150 memset(&vHeader
, '\0', 16);
152 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
153 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
154 vHeader
.cPlanes
= 1L;
155 vHeader
.cBitCount
= 24;
157 hBmp
= ::GpiCreateBitmap( hPSDst
164 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
166 vError
= ::WinGetLastError(vHabmain
);
167 sError
= wxPMErrorToStr(vError
);
169 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
171 vError
= ::WinGetLastError(vHabmain
);
172 sError
= wxPMErrorToStr(vError
);
174 if ((lHits
= ::GpiBitBlt( hPSDst
182 vError
= ::WinGetLastError(vHabmain
);
183 sError
= wxPMErrorToStr(vError
);
185 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
187 vError
= ::WinGetLastError(vHabmain
);
188 sError
= wxPMErrorToStr(vError
);
190 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
192 vError
= ::WinGetLastError(vHabmain
);
193 sError
= wxPMErrorToStr(vError
);
195 vIconInfo
.hbmColor
= hBmp
;
197 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
198 hBmpMask
= ::GpiCreateBitmap( hPSDst
205 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
207 vError
= ::WinGetLastError(vHabmain
);
208 sError
= wxPMErrorToStr(vError
);
210 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
212 vError
= ::WinGetLastError(vHabmain
);
213 sError
= wxPMErrorToStr(vError
);
215 if ((lHits
= ::GpiBitBlt( hPSDst
223 vError
= ::WinGetLastError(vHabmain
);
224 sError
= wxPMErrorToStr(vError
);
226 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
228 vError
= ::WinGetLastError(vHabmain
);
229 sError
= wxPMErrorToStr(vError
);
231 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
233 vError
= ::WinGetLastError(vHabmain
);
234 sError
= wxPMErrorToStr(vError
);
237 vIconInfo
.hbmPointer
= hBmpMask
;
239 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
245 wxLogLastError(wxT("WinCreatePointerIndirect"));
246 vError
= ::WinGetLastError(vHabmain
);
247 sError
= wxPMErrorToStr(vError
);
251 SetHICON((WXHICON
)hIcon
);
252 SetSize( rBmp
.GetWidth()
260 // We created the mask, now delete it
264 ::GpiSetBitmap(hPSSrc
, NULL
);
265 ::GpiSetBitmap(hPSDst
, NULL
);
266 ::GpiDestroyPS(hPSSrc
);
267 ::GpiDestroyPS(hPSDst
);
268 ::DevCloseDC(hDCSrc
);
269 ::DevCloseDC(hDCDst
);
270 } // end of wxIcon::CopyFromBitmap
272 bool wxIcon::LoadFile(
273 const wxString
& rFilename
279 HPS hPs
= NULLHANDLE
;
283 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
286 return(pHandler
->Load( this