1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/icon.cpp
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 // ----------------------------------------------------------------------------
58 wxIcon::wxIcon( const char WXUNUSED(bits
)[],
60 int WXUNUSED(nHeight
) )
65 wxIcon::wxIcon( const wxString
& rIconFile
,
72 // A very poor hack, but we have to have separate icon files from windows
73 // So we have a modified name where replace the last three characters
74 // with os2. Also need the extension.
76 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.length() - 3);
78 sOs2Name
+= wxT("Os2.ico");
90 void wxIcon::CreateIconFromXpm(
94 wxBitmap
vBmp(ppData
);
102 } // end of wxIcon::CreateIconFromXpm
104 void wxIcon::CopyFromBitmap( const wxBitmap
& rBmp
)
106 wxMask
* pMask
= rBmp
.GetMask();
107 HBITMAP hBmp
= NULLHANDLE
;
108 HBITMAP hBmpMask
= NULLHANDLE
;
109 HBITMAP hOldBitmap
= NULLHANDLE
;
117 // We must have a mask for an icon, so even if it's probably incorrect,
118 // do create it (grey is the "standard" transparent colour)
120 pMask
= new wxMask( rBmp
125 BITMAPINFOHEADER2 vHeader
;
126 SIZEL vSize
= {0, 0};
127 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
128 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
129 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
130 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
131 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
132 POINTL vPoint
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()},
133 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
135 POINTL vPointMask
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight() * 2},
136 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
138 POINTERINFO vIconInfo
;
140 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
141 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
143 memset(&vHeader
, '\0', 16);
145 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
146 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
147 vHeader
.cPlanes
= 1L;
148 vHeader
.cBitCount
= 24;
150 hBmp
= ::GpiCreateBitmap( hPSDst
157 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
159 vError
= ::WinGetLastError(vHabmain
);
160 sError
= wxPMErrorToStr(vError
);
162 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
164 vError
= ::WinGetLastError(vHabmain
);
165 sError
= wxPMErrorToStr(vError
);
167 if ((lHits
= ::GpiBitBlt( hPSDst
175 vError
= ::WinGetLastError(vHabmain
);
176 sError
= wxPMErrorToStr(vError
);
178 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
180 vError
= ::WinGetLastError(vHabmain
);
181 sError
= wxPMErrorToStr(vError
);
183 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
185 vError
= ::WinGetLastError(vHabmain
);
186 sError
= wxPMErrorToStr(vError
);
188 vIconInfo
.hbmColor
= hBmp
;
190 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
191 hBmpMask
= ::GpiCreateBitmap( hPSDst
198 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
200 vError
= ::WinGetLastError(vHabmain
);
201 sError
= wxPMErrorToStr(vError
);
203 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
205 vError
= ::WinGetLastError(vHabmain
);
206 sError
= wxPMErrorToStr(vError
);
208 if ((lHits
= ::GpiBitBlt( hPSDst
216 vError
= ::WinGetLastError(vHabmain
);
217 sError
= wxPMErrorToStr(vError
);
219 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
221 vError
= ::WinGetLastError(vHabmain
);
222 sError
= wxPMErrorToStr(vError
);
224 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
226 vError
= ::WinGetLastError(vHabmain
);
227 sError
= wxPMErrorToStr(vError
);
230 vIconInfo
.hbmPointer
= hBmpMask
;
232 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
, &vIconInfo
);
236 wxLogLastError(wxT("WinCreatePointerIndirect"));
237 vError
= ::WinGetLastError(vHabmain
);
238 sError
= wxPMErrorToStr(vError
);
242 SetHICON((WXHICON
)hIcon
);
243 SetSize( rBmp
.GetWidth()
251 // We created the mask, now delete it
255 ::GpiSetBitmap(hPSSrc
, NULL
);
256 ::GpiSetBitmap(hPSDst
, NULL
);
257 ::GpiDestroyPS(hPSSrc
);
258 ::GpiDestroyPS(hPSDst
);
259 ::DevCloseDC(hDCSrc
);
260 ::DevCloseDC(hDCDst
);
261 } // end of wxIcon::CopyFromBitmap
263 bool wxIcon::LoadFile( const wxString
& rFilename
,
268 HPS hPs
= NULLHANDLE
;
272 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
275 return(pHandler
->Load( this