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(const char* const* ppData
)
90 wxBitmap
vBmp(ppData
);
98 } // end of wxIcon::CreateIconFromXpm
100 void wxIcon::CopyFromBitmap( const wxBitmap
& rBmp
)
102 wxMask
* pMask
= rBmp
.GetMask();
103 HBITMAP hBmp
= NULLHANDLE
;
104 HBITMAP hBmpMask
= NULLHANDLE
;
105 HBITMAP hOldBitmap
= NULLHANDLE
;
113 // We must have a mask for an icon, so even if it's probably incorrect,
114 // do create it (grey is the "standard" transparent colour)
116 pMask
= new wxMask( rBmp
121 BITMAPINFOHEADER2 vHeader
;
122 SIZEL vSize
= {0, 0};
123 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
124 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
125 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
126 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
127 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
128 POINTL vPoint
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()},
129 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
131 POINTL vPointMask
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight() * 2},
132 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
134 POINTERINFO vIconInfo
;
136 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
137 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
139 memset(&vHeader
, '\0', 16);
141 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
142 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
143 vHeader
.cPlanes
= 1L;
144 vHeader
.cBitCount
= 24;
146 hBmp
= ::GpiCreateBitmap( hPSDst
153 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
155 vError
= ::WinGetLastError(vHabmain
);
156 sError
= wxPMErrorToStr(vError
);
158 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
160 vError
= ::WinGetLastError(vHabmain
);
161 sError
= wxPMErrorToStr(vError
);
163 if ((lHits
= ::GpiBitBlt( hPSDst
171 vError
= ::WinGetLastError(vHabmain
);
172 sError
= wxPMErrorToStr(vError
);
174 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
176 vError
= ::WinGetLastError(vHabmain
);
177 sError
= wxPMErrorToStr(vError
);
179 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
181 vError
= ::WinGetLastError(vHabmain
);
182 sError
= wxPMErrorToStr(vError
);
184 vIconInfo
.hbmColor
= hBmp
;
186 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
187 hBmpMask
= ::GpiCreateBitmap( hPSDst
194 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
196 vError
= ::WinGetLastError(vHabmain
);
197 sError
= wxPMErrorToStr(vError
);
199 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
201 vError
= ::WinGetLastError(vHabmain
);
202 sError
= wxPMErrorToStr(vError
);
204 if ((lHits
= ::GpiBitBlt( hPSDst
212 vError
= ::WinGetLastError(vHabmain
);
213 sError
= wxPMErrorToStr(vError
);
215 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
217 vError
= ::WinGetLastError(vHabmain
);
218 sError
= wxPMErrorToStr(vError
);
220 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
222 vError
= ::WinGetLastError(vHabmain
);
223 sError
= wxPMErrorToStr(vError
);
226 vIconInfo
.hbmPointer
= hBmpMask
;
228 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
, &vIconInfo
);
232 wxLogLastError(wxT("WinCreatePointerIndirect"));
233 vError
= ::WinGetLastError(vHabmain
);
234 sError
= wxPMErrorToStr(vError
);
238 SetHICON((WXHICON
)hIcon
);
239 SetSize( rBmp
.GetWidth()
247 // We created the mask, now delete it
251 ::GpiSetBitmap(hPSSrc
, NULL
);
252 ::GpiSetBitmap(hPSDst
, NULL
);
253 ::GpiDestroyPS(hPSSrc
);
254 ::GpiDestroyPS(hPSDst
);
255 ::DevCloseDC(hDCSrc
);
256 ::DevCloseDC(hDCDst
);
257 } // end of wxIcon::CopyFromBitmap
259 bool wxIcon::LoadFile( const wxString
& rFilename
,
264 HPS hPs
= NULLHANDLE
;
268 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
271 return(pHandler
->Load( this