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"
31 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
33 // ============================================================================
35 // ============================================================================
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 void wxIconRefData::Free()
44 ::WinFreeFileIcon((HPOINTER
)m_hIcon
);
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
56 wxIcon::wxIcon( const char WXUNUSED(bits
)[],
58 int WXUNUSED(nHeight
) )
63 wxIcon::wxIcon( const wxString
& rIconFile
,
70 // A very poor hack, but we have to have separate icon files from windows
71 // So we have a modified name where replace the last three characters
72 // with os2. Also need the extension.
74 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.length() - 3);
76 sOs2Name
+= wxT("Os2.ico");
88 void wxIcon::CreateIconFromXpm(
92 wxBitmap
vBmp(ppData
);
100 } // end of wxIcon::CreateIconFromXpm
102 void wxIcon::CopyFromBitmap( const wxBitmap
& rBmp
)
104 wxMask
* pMask
= rBmp
.GetMask();
105 HBITMAP hBmp
= NULLHANDLE
;
106 HBITMAP hBmpMask
= NULLHANDLE
;
107 HBITMAP hOldBitmap
= NULLHANDLE
;
115 // We must have a mask for an icon, so even if it's probably incorrect,
116 // do create it (grey is the "standard" transparent colour)
118 pMask
= new wxMask( rBmp
123 BITMAPINFOHEADER2 vHeader
;
124 SIZEL vSize
= {0, 0};
125 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
126 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
127 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
128 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
129 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
130 POINTL vPoint
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()},
131 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
133 POINTL vPointMask
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight() * 2},
134 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
136 POINTERINFO vIconInfo
;
138 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
139 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
141 memset(&vHeader
, '\0', 16);
143 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
144 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
145 vHeader
.cPlanes
= 1L;
146 vHeader
.cBitCount
= 24;
148 hBmp
= ::GpiCreateBitmap( hPSDst
155 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
157 vError
= ::WinGetLastError(vHabmain
);
158 sError
= wxPMErrorToStr(vError
);
160 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
162 vError
= ::WinGetLastError(vHabmain
);
163 sError
= wxPMErrorToStr(vError
);
165 if ((lHits
= ::GpiBitBlt( hPSDst
173 vError
= ::WinGetLastError(vHabmain
);
174 sError
= wxPMErrorToStr(vError
);
176 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
178 vError
= ::WinGetLastError(vHabmain
);
179 sError
= wxPMErrorToStr(vError
);
181 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
183 vError
= ::WinGetLastError(vHabmain
);
184 sError
= wxPMErrorToStr(vError
);
186 vIconInfo
.hbmColor
= hBmp
;
188 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
189 hBmpMask
= ::GpiCreateBitmap( hPSDst
196 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
198 vError
= ::WinGetLastError(vHabmain
);
199 sError
= wxPMErrorToStr(vError
);
201 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
203 vError
= ::WinGetLastError(vHabmain
);
204 sError
= wxPMErrorToStr(vError
);
206 if ((lHits
= ::GpiBitBlt( hPSDst
214 vError
= ::WinGetLastError(vHabmain
);
215 sError
= wxPMErrorToStr(vError
);
217 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
219 vError
= ::WinGetLastError(vHabmain
);
220 sError
= wxPMErrorToStr(vError
);
222 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
224 vError
= ::WinGetLastError(vHabmain
);
225 sError
= wxPMErrorToStr(vError
);
228 vIconInfo
.hbmPointer
= hBmpMask
;
230 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
, &vIconInfo
);
234 wxLogLastError(wxT("WinCreatePointerIndirect"));
235 vError
= ::WinGetLastError(vHabmain
);
236 sError
= wxPMErrorToStr(vError
);
240 SetHICON((WXHICON
)hIcon
);
241 SetSize( rBmp
.GetWidth()
249 // We created the mask, now delete it
253 ::GpiSetBitmap(hPSSrc
, NULL
);
254 ::GpiSetBitmap(hPSDst
, NULL
);
255 ::GpiDestroyPS(hPSSrc
);
256 ::GpiDestroyPS(hPSDst
);
257 ::DevCloseDC(hDCSrc
);
258 ::DevCloseDC(hDCDst
);
259 } // end of wxIcon::CopyFromBitmap
261 bool wxIcon::LoadFile( const wxString
& rFilename
,
266 HPS hPs
= NULLHANDLE
;
270 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
273 return(pHandler
->Load( this