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"
27 #include "wx/os2/private.h"
32 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxGDIObject
)
34 // ============================================================================
36 // ============================================================================
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 void wxIconRefData::Free()
45 ::WinFreeFileIcon((HPOINTER
)m_hIcon
);
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
57 wxIcon::wxIcon( const char WXUNUSED(bits
)[],
59 int WXUNUSED(nHeight
) )
64 wxIcon::wxIcon( const wxString
& rIconFile
,
71 // A very poor hack, but we have to have separate icon files from windows
72 // So we have a modified name where replace the last three characters
73 // with os2. Also need the extension.
75 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.length() - 3);
77 sOs2Name
+= wxT("Os2.ico");
89 void wxIcon::CreateIconFromXpm(
93 wxBitmap
vBmp(ppData
);
101 } // end of wxIcon::CreateIconFromXpm
103 void wxIcon::CopyFromBitmap( const wxBitmap
& rBmp
)
105 wxMask
* pMask
= rBmp
.GetMask();
106 HBITMAP hBmp
= NULLHANDLE
;
107 HBITMAP hBmpMask
= NULLHANDLE
;
108 HBITMAP hOldBitmap
= NULLHANDLE
;
116 // We must have a mask for an icon, so even if it's probably incorrect,
117 // do create it (grey is the "standard" transparent colour)
119 pMask
= new wxMask( rBmp
124 BITMAPINFOHEADER2 vHeader
;
125 SIZEL vSize
= {0, 0};
126 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
127 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
128 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
129 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
130 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
131 POINTL vPoint
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()},
132 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
134 POINTL vPointMask
[4] = { {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight() * 2},
135 {0, 0}, {rBmp
.GetWidth(), rBmp
.GetHeight()}
137 POINTERINFO vIconInfo
;
139 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
140 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
142 memset(&vHeader
, '\0', 16);
144 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
145 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
146 vHeader
.cPlanes
= 1L;
147 vHeader
.cBitCount
= 24;
149 hBmp
= ::GpiCreateBitmap( hPSDst
156 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
158 vError
= ::WinGetLastError(vHabmain
);
159 sError
= wxPMErrorToStr(vError
);
161 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
163 vError
= ::WinGetLastError(vHabmain
);
164 sError
= wxPMErrorToStr(vError
);
166 if ((lHits
= ::GpiBitBlt( hPSDst
174 vError
= ::WinGetLastError(vHabmain
);
175 sError
= wxPMErrorToStr(vError
);
177 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
179 vError
= ::WinGetLastError(vHabmain
);
180 sError
= wxPMErrorToStr(vError
);
182 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
184 vError
= ::WinGetLastError(vHabmain
);
185 sError
= wxPMErrorToStr(vError
);
187 vIconInfo
.hbmColor
= hBmp
;
189 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
190 hBmpMask
= ::GpiCreateBitmap( hPSDst
197 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
199 vError
= ::WinGetLastError(vHabmain
);
200 sError
= wxPMErrorToStr(vError
);
202 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
204 vError
= ::WinGetLastError(vHabmain
);
205 sError
= wxPMErrorToStr(vError
);
207 if ((lHits
= ::GpiBitBlt( hPSDst
215 vError
= ::WinGetLastError(vHabmain
);
216 sError
= wxPMErrorToStr(vError
);
218 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
220 vError
= ::WinGetLastError(vHabmain
);
221 sError
= wxPMErrorToStr(vError
);
223 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
225 vError
= ::WinGetLastError(vHabmain
);
226 sError
= wxPMErrorToStr(vError
);
229 vIconInfo
.hbmPointer
= hBmpMask
;
231 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
, &vIconInfo
);
235 wxLogLastError(wxT("WinCreatePointerIndirect"));
236 vError
= ::WinGetLastError(vHabmain
);
237 sError
= wxPMErrorToStr(vError
);
241 SetHICON((WXHICON
)hIcon
);
242 SetSize( rBmp
.GetWidth()
250 // We created the mask, now delete it
254 ::GpiSetBitmap(hPSSrc
, NULL
);
255 ::GpiSetBitmap(hPSDst
, NULL
);
256 ::GpiDestroyPS(hPSSrc
);
257 ::GpiDestroyPS(hPSDst
);
258 ::DevCloseDC(hDCSrc
);
259 ::DevCloseDC(hDCDst
);
260 } // end of wxIcon::CopyFromBitmap
262 bool wxIcon::LoadFile( const wxString
& rFilename
,
267 HPS hPs
= NULLHANDLE
;
271 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
274 return(pHandler
->Load( this