1 /////////////////////////////////////////////////////////////////////////////
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 // ----------------------------------------------------------------------------
58 const char WXUNUSED(bits
)[]
59 , int WXUNUSED(nWidth
)
60 , int WXUNUSED(nHeight
)
67 const wxString
& rIconFile
75 // A very poor hack, but we have to have separate icon files from windows
76 // So we have a modified name where replace the last three characters
77 // with os2. Also need the extension.
79 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.Length() - 3);
81 sOs2Name
+= "Os2.ico";
93 void wxIcon::CreateIconFromXpm(
97 wxBitmap
vBmp(ppData
);
105 } // end of wxIcon::CreateIconFromXpm
107 void wxIcon::CopyFromBitmap(
111 wxMask
* pMask
= rBmp
.GetMask();
112 HBITMAP hBmp
= NULLHANDLE
;
113 HBITMAP hBmpMask
= NULLHANDLE
;
114 HBITMAP hOldBitmap
= NULLHANDLE
;
122 // We must have a mask for an icon, so even if it's probably incorrect,
123 // do create it (grey is the "standard" transparent colour)
125 pMask
= new wxMask( rBmp
130 BITMAPINFOHEADER2 vHeader
;
131 SIZEL vSize
= {0, 0};
132 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
133 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
134 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
135 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
136 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
137 POINTL vPoint
[4] = { 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight(),
138 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight()
140 POINTL vPointMask
[4] = { 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight() * 2,
141 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight()
144 POINTERINFO vIconInfo
;
146 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
147 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
149 memset(&vHeader
, '\0', 16);
151 vHeader
.cx
= (ULONG
)rBmp
.GetWidth();
152 vHeader
.cy
= (ULONG
)rBmp
.GetHeight();
153 vHeader
.cPlanes
= 1L;
154 vHeader
.cBitCount
= 24;
156 hBmp
= ::GpiCreateBitmap( hPSDst
163 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmp
)) == HBM_ERROR
)
165 vError
= ::WinGetLastError(vHabmain
);
166 sError
= wxPMErrorToStr(vError
);
168 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)rBmp
.GetHBITMAP())) == HBM_ERROR
)
170 vError
= ::WinGetLastError(vHabmain
);
171 sError
= wxPMErrorToStr(vError
);
173 if ((lHits
= ::GpiBitBlt( hPSDst
181 vError
= ::WinGetLastError(vHabmain
);
182 sError
= wxPMErrorToStr(vError
);
184 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
186 vError
= ::WinGetLastError(vHabmain
);
187 sError
= wxPMErrorToStr(vError
);
189 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
191 vError
= ::WinGetLastError(vHabmain
);
192 sError
= wxPMErrorToStr(vError
);
194 vIconInfo
.hbmColor
= hBmp
;
196 vHeader
.cy
= (ULONG
)rBmp
.GetHeight() * 2;
197 hBmpMask
= ::GpiCreateBitmap( hPSDst
204 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, hBmpMask
)) == HBM_ERROR
)
206 vError
= ::WinGetLastError(vHabmain
);
207 sError
= wxPMErrorToStr(vError
);
209 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
)pMask
->GetMaskBitmap())) == HBM_ERROR
)
211 vError
= ::WinGetLastError(vHabmain
);
212 sError
= wxPMErrorToStr(vError
);
214 if ((lHits
= ::GpiBitBlt( hPSDst
222 vError
= ::WinGetLastError(vHabmain
);
223 sError
= wxPMErrorToStr(vError
);
225 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
227 vError
= ::WinGetLastError(vHabmain
);
228 sError
= wxPMErrorToStr(vError
);
230 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
232 vError
= ::WinGetLastError(vHabmain
);
233 sError
= wxPMErrorToStr(vError
);
236 vIconInfo
.hbmPointer
= hBmpMask
;
238 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
244 wxLogLastError(wxT("WinCreatePointerIndirect"));
245 vError
= ::WinGetLastError(vHabmain
);
246 sError
= wxPMErrorToStr(vError
);
250 SetHICON((WXHICON
)hIcon
);
251 SetSize( rBmp
.GetWidth()
259 // We created the mask, now delete it
263 ::GpiSetBitmap(hPSSrc
, NULL
);
264 ::GpiSetBitmap(hPSDst
, NULL
);
265 ::GpiDestroyPS(hPSSrc
);
266 ::GpiDestroyPS(hPSDst
);
267 ::DevCloseDC(hDCSrc
);
268 ::DevCloseDC(hDCDst
);
269 } // end of wxIcon::CopyFromBitmap
271 bool wxIcon::LoadFile(
272 const wxString
& rFilename
278 HPS hPs
= NULLHANDLE
;
282 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
285 return(pHandler
->Load( this