1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/icon.cpp
3 // Purpose: wxIcon class
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
27 #include "wx/os2/private.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
32 // ============================================================================
34 // ============================================================================
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 void wxIconRefData::Free()
43 ::WinFreeFileIcon((HPOINTER
)m_hIcon
);
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
55 wxIcon::wxIcon( const char WXUNUSED(bits
)[],
57 int WXUNUSED(nHeight
) )
62 wxIcon::wxIcon( const wxString
& rIconFile
,
69 // A very poor hack, but we have to have separate icon files from windows
70 // So we have a modified name where replace the last three characters
71 // with os2. Also need the extension.
73 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.length() - 3);
75 sOs2Name
+= wxT("Os2.ico");
87 void wxIcon::CreateIconFromXpm(const char* const* ppData
)
89 wxBitmap
vBmp(ppData
);
97 } // end of wxIcon::CreateIconFromXpm
99 void wxIcon::CopyFromBitmap( const wxBitmap
& rBmp
)
101 wxMask
* pMask
= rBmp
.GetMask();
102 HBITMAP hBmp
= NULLHANDLE
;
103 HBITMAP hBmpMask
= NULLHANDLE
;
104 HBITMAP hOldBitmap
= NULLHANDLE
;
112 // We must have a mask for an icon, so even if it's probably incorrect,
113 // do create it (grey is the "standard" transparent colour)
115 pMask
= new wxMask( rBmp
120 BITMAPINFOHEADER2 vHeader
;
121 SIZEL vSize
= {0, 0};
122 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
123 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
124 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
125 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
126 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
127 POINTL vPoint
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()},
128 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
130 POINTL vPointMask
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight() * 2},
131 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
133 POINTERINFO vIconInfo
;
135 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
136 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
138 memset(&vHeader
, '\0', 16);
140 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
141 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
142 vHeader
.cPlanes
= 1L;
143 vHeader
.cBitCount
= 24;
145 hBmp
= ::GpiCreateBitmap( hPSDst
152 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
154 vError
= ::WinGetLastError(vHabmain
);
155 sError
= wxPMErrorToStr(vError
);
157 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
159 vError
= ::WinGetLastError(vHabmain
);
160 sError
= wxPMErrorToStr(vError
);
162 if ((lHits
= ::GpiBitBlt( hPSDst
170 vError
= ::WinGetLastError(vHabmain
);
171 sError
= wxPMErrorToStr(vError
);
173 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
175 vError
= ::WinGetLastError(vHabmain
);
176 sError
= wxPMErrorToStr(vError
);
178 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
180 vError
= ::WinGetLastError(vHabmain
);
181 sError
= wxPMErrorToStr(vError
);
183 vIconInfo
.hbmColor
= hBmp
;
185 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
186 hBmpMask
= ::GpiCreateBitmap( hPSDst
193 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
195 vError
= ::WinGetLastError(vHabmain
);
196 sError
= wxPMErrorToStr(vError
);
198 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
200 vError
= ::WinGetLastError(vHabmain
);
201 sError
= wxPMErrorToStr(vError
);
203 if ((lHits
= ::GpiBitBlt( hPSDst
211 vError
= ::WinGetLastError(vHabmain
);
212 sError
= wxPMErrorToStr(vError
);
214 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
216 vError
= ::WinGetLastError(vHabmain
);
217 sError
= wxPMErrorToStr(vError
);
219 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
221 vError
= ::WinGetLastError(vHabmain
);
222 sError
= wxPMErrorToStr(vError
);
225 vIconInfo
.hbmPointer
= hBmpMask
;
227 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
, &vIconInfo
);
231 wxLogLastError(wxT("WinCreatePointerIndirect"));
232 vError
= ::WinGetLastError(vHabmain
);
233 sError
= wxPMErrorToStr(vError
);
237 SetHICON((WXHICON
)hIcon
);
238 SetSize( rBmp
.GetWidth()
246 // We created the mask, now delete it
250 ::GpiSetBitmap(hPSSrc
, NULL
);
251 ::GpiSetBitmap(hPSDst
, NULL
);
252 ::GpiDestroyPS(hPSSrc
);
253 ::GpiDestroyPS(hPSDst
);
254 ::DevCloseDC(hDCSrc
);
255 ::DevCloseDC(hDCDst
);
256 } // end of wxIcon::CopyFromBitmap
258 bool wxIcon::LoadFile( const wxString
& rFilename
,
263 HPS hPs
= NULLHANDLE
;
267 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
270 return(pHandler
->Load( this