]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/icon.cpp
d1c390da8fb9c984a5ad45999311485b96c3280c
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 // ----------------------------------------------------------------------------
57 const char WXUNUSED(bits
)[]
58 , int WXUNUSED(nWidth
)
59 , int WXUNUSED(nHeight
)
65 const wxString
& rIconFile
72 // A very poor hack, but we have to have separate icon files from windows
73 // So we have a modified name where replace the last three characters
74 // with os2. Also need the extension.
76 wxString sOs2Name
= rIconFile
.Mid(0, rIconFile
.Length() - 3);
78 sOs2Name
+= "Os2.ico";
90 void wxIcon::CreateIconFromXpm(
94 wxBitmap
vBmp(ppData
);
97 } // end of wxIcon::CreateIconFromXpm
99 void wxIcon::CopyFromBitmap(
103 wxMask
* pMask
= rBmp
.GetMask();
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 POINTERINFO vIconInfo
;
122 memset(&vIconInfo
, '\0', sizeof(POINTERINFO
));
123 vIconInfo
.fPointer
= FALSE
; // we want an icon, not a pointer
124 vIconInfo
.hbmPointer
= (HBITMAP
) pMask
->GetMaskBitmap();
125 vIconInfo
.hbmColor
= GetHbitmapOf(rBmp
);
127 SIZEL vSize
= {0, 0};
128 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
129 HDC hDCSrc
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
130 HDC hDCDst
= ::DevOpenDC(vHabmain
, OD_MEMORY
, "*", 5L, (PDEVOPENDATA
)&vDop
, NULLHANDLE
);
131 HPS hPSSrc
= ::GpiCreatePS(vHabmain
, hDCSrc
, &vSize
, PU_PELS
| GPIA_ASSOC
);
132 HPS hPSDst
= ::GpiCreatePS(vHabmain
, hDCDst
, &vSize
, PU_PELS
| GPIA_ASSOC
);
133 POINTL vPoint
[4] = { 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight(),
134 0, 0, rBmp
.GetWidth(), rBmp
.GetHeight()
136 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, (HBITMAP
) pMask
->GetMaskBitmap())) == HBM_ERROR
)
138 vError
= ::WinGetLastError(vHabmain
);
139 sError
= wxPMErrorToStr(vError
);
141 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, (HBITMAP
) vIconInfo
.hbmColor
)) == HBM_ERROR
)
143 vError
= ::WinGetLastError(vHabmain
);
144 sError
= wxPMErrorToStr(vError
);
146 ::GpiSetBitmapId(hPSDst
, (HBITMAP
) vIconInfo
.hbmColor
, 1L);
147 if ((lHits
= ::GpiBitBlt( hPSDst
155 vError
= ::WinGetLastError(vHabmain
);
156 sError
= wxPMErrorToStr(vError
);
158 if ((hOldBitmap
= ::GpiSetBitmap(hPSSrc
, NULLHANDLE
)) == HBM_ERROR
)
160 vError
= ::WinGetLastError(vHabmain
);
161 sError
= wxPMErrorToStr(vError
);
163 if ((hOldBitmap
= ::GpiSetBitmap(hPSDst
, NULLHANDLE
)) == HBM_ERROR
)
165 vError
= ::WinGetLastError(vHabmain
);
166 sError
= wxPMErrorToStr(vError
);
169 ::GpiSetBitmap(hPSSrc
, NULL
);
170 ::GpiSetBitmap(hPSDst
, NULL
);
171 ::GpiDestroyPS(hPSSrc
);
172 ::GpiDestroyPS(hPSDst
);
173 ::DevCloseDC(hDCSrc
);
174 ::DevCloseDC(hDCDst
);
176 HICON hIcon
= ::WinCreatePointerIndirect( HWND_DESKTOP
182 wxLogLastError(wxT("WinCreatePointerIndirect"));
183 vError
= ::WinGetLastError(vHabmain
);
184 sError
= wxPMErrorToStr(vError
);
188 SetHICON((WXHICON
)hIcon
);
189 SetSize( rBmp
.GetWidth()
197 // We created the mask, now delete it
201 } // end of wxIcon::CopyFromBitmap
203 bool wxIcon::LoadFile(
204 const wxString
& rFilename
210 HPS hPs
= NULLHANDLE
;
214 wxGDIImageHandler
* pHandler
= FindHandler(lType
);
217 return(pHandler
->Load( this