]> git.saurik.com Git - wxWidgets.git/blame - src/os2/icon.cpp
Fix --enable-webview_xxx options names in configure.
[wxWidgets.git] / src / os2 / icon.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
cb7d7375 2// Name: src/os2/icon.cpp
0e320a79 3// Purpose: wxIcon class
fb9010ed 4// Author: David Webster
0e320a79 5// Modified by:
fb9010ed 6// Created: 10/09/99
0e320a79 7// RCS-ID: $Id$
fb9010ed 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
fb9010ed
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
7520f3da 16 #pragma hdrstop
fb9010ed
DW
17#endif
18
923d28da
WS
19#include "wx/icon.h"
20
fb9010ed 21#ifndef WX_PRECOMP
3b9e3455
DW
22 #include "wx/list.h"
23 #include "wx/utils.h"
24 #include "wx/app.h"
6eb280e9 25 #include "wx/log.h"
0e320a79
DW
26#endif
27
fb9010ed
DW
28#include "wx/os2/private.h"
29#include "assert.h"
30
923d28da 31IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
0e320a79 32
3b9e3455
DW
33// ============================================================================
34// implementation
35// ============================================================================
0e320a79 36
3b9e3455
DW
37// ----------------------------------------------------------------------------
38// wxIconRefData
39// ----------------------------------------------------------------------------
0e320a79 40
3b9e3455 41void wxIconRefData::Free()
0e320a79 42{
43543d98
DW
43 if (m_hIcon)
44 ::WinFreeFileIcon((HPOINTER)m_hIcon);
0e320a79
DW
45}
46
3b9e3455
DW
47// ----------------------------------------------------------------------------
48// wxIcon
49// ----------------------------------------------------------------------------
50
0e320a79 51wxIcon::wxIcon()
77f4f0a7 52 :m_bIsXpm(false)
0e320a79
DW
53{
54}
55
77f4f0a7
WS
56wxIcon::wxIcon( const char WXUNUSED(bits)[],
57 int WXUNUSED(nWidth),
58 int WXUNUSED(nHeight) )
59 :m_bIsXpm(false)
0e320a79
DW
60{
61}
62
77f4f0a7 63wxIcon::wxIcon( const wxString& rIconFile,
6b5c2d52 64 wxBitmapType lFlags,
77f4f0a7
WS
65 int nDesiredWidth,
66 int nDesiredHeight )
67 :m_bIsXpm(false)
0e320a79 68{
914589c2
DW
69 //
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.
73 //
cb7d7375 74 wxString sOs2Name = rIconFile.Mid(0, rIconFile.length() - 3);
914589c2 75
0fba44b4 76 sOs2Name += wxT("Os2.ico");
914589c2 77 LoadFile( sOs2Name
3b9e3455
DW
78 ,lFlags
79 ,nDesiredWidth
80 ,nDesiredHeight
81 );
0e320a79
DW
82}
83
84wxIcon::~wxIcon()
85{
86}
87
e45080c1 88void wxIcon::CreateIconFromXpm(const char* const* ppData)
6f38c86f
DW
89{
90 wxBitmap vBmp(ppData);
91
92 CopyFromBitmap(vBmp);
29172908
DW
93 if (GetHICON())
94 {
6670f564 95 m_bIsXpm = true;
29172908
DW
96 m_vXpmSrc = vBmp;
97 }
6f38c86f
DW
98} // end of wxIcon::CreateIconFromXpm
99
6670f564 100void wxIcon::CopyFromBitmap( const wxBitmap& rBmp )
6f38c86f
DW
101{
102 wxMask* pMask = rBmp.GetMask();
16ff355b
DW
103 HBITMAP hBmp = NULLHANDLE;
104 HBITMAP hBmpMask = NULLHANDLE;
52315bc3
DW
105 HBITMAP hOldBitmap = NULLHANDLE;
106 ERRORID vError;
107 wxString sError;
108 LONG lHits;
6f38c86f
DW
109
110 if (!pMask)
111 {
112 //
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)
115 //
116 pMask = new wxMask( rBmp
117 ,*wxLIGHT_GREY
118 );
119 }
120
cb7d7375
WS
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()}
130 };
131 POINTL vPointMask[4] = { {0, 0}, {rBmp.GetWidth(), rBmp.GetHeight() * 2},
132 {0, 0}, {rBmp.GetWidth(), rBmp.GetHeight()}
133 };
134 POINTERINFO vIconInfo;
16ff355b
DW
135
136 memset(&vIconInfo, '\0', sizeof(POINTERINFO));
137 vIconInfo.fPointer = FALSE; // we want an icon, not a pointer
138
139 memset(&vHeader, '\0', 16);
140 vHeader.cbFix = 16;
141 vHeader.cx = (ULONG)rBmp.GetWidth();
142 vHeader.cy = (ULONG)rBmp.GetHeight();
143 vHeader.cPlanes = 1L;
144 vHeader.cBitCount = 24;
145
146 hBmp = ::GpiCreateBitmap( hPSDst
147 ,&vHeader
148 ,0L
149 ,NULL
150 ,NULL
151 );
152
153 if ((hOldBitmap = ::GpiSetBitmap(hPSDst, hBmp)) == HBM_ERROR)
52315bc3
DW
154 {
155 vError = ::WinGetLastError(vHabmain);
156 sError = wxPMErrorToStr(vError);
157 }
16ff355b 158 if ((hOldBitmap = ::GpiSetBitmap(hPSSrc, (HBITMAP)rBmp.GetHBITMAP())) == HBM_ERROR)
52315bc3
DW
159 {
160 vError = ::WinGetLastError(vHabmain);
161 sError = wxPMErrorToStr(vError);
162 }
52315bc3
DW
163 if ((lHits = ::GpiBitBlt( hPSDst
164 ,hPSSrc
165 ,4L
166 ,vPoint
16ff355b
DW
167 ,ROP_SRCCOPY
168 ,BBO_IGNORE
169 )) == GPI_ERROR)
170 {
171 vError = ::WinGetLastError(vHabmain);
172 sError = wxPMErrorToStr(vError);
173 }
174 if ((hOldBitmap = ::GpiSetBitmap(hPSDst, NULLHANDLE)) == HBM_ERROR)
175 {
176 vError = ::WinGetLastError(vHabmain);
177 sError = wxPMErrorToStr(vError);
178 }
179 if ((hOldBitmap = ::GpiSetBitmap(hPSSrc, NULLHANDLE)) == HBM_ERROR)
180 {
181 vError = ::WinGetLastError(vHabmain);
182 sError = wxPMErrorToStr(vError);
183 }
184 vIconInfo.hbmColor = hBmp;
185
29172908 186 vHeader.cy = (ULONG)rBmp.GetHeight() * 2;
16ff355b
DW
187 hBmpMask = ::GpiCreateBitmap( hPSDst
188 ,&vHeader
189 ,0L
190 ,NULL
191 ,NULL
192 );
193
194 if ((hOldBitmap = ::GpiSetBitmap(hPSDst, hBmpMask)) == HBM_ERROR)
195 {
196 vError = ::WinGetLastError(vHabmain);
197 sError = wxPMErrorToStr(vError);
198 }
199 if ((hOldBitmap = ::GpiSetBitmap(hPSSrc, (HBITMAP)pMask->GetMaskBitmap())) == HBM_ERROR)
200 {
201 vError = ::WinGetLastError(vHabmain);
202 sError = wxPMErrorToStr(vError);
203 }
204 if ((lHits = ::GpiBitBlt( hPSDst
205 ,hPSSrc
206 ,4L
207 ,vPointMask
208 ,ROP_SRCCOPY
52315bc3
DW
209 ,BBO_IGNORE
210 )) == GPI_ERROR)
211 {
212 vError = ::WinGetLastError(vHabmain);
213 sError = wxPMErrorToStr(vError);
214 }
215 if ((hOldBitmap = ::GpiSetBitmap(hPSSrc, NULLHANDLE)) == HBM_ERROR)
216 {
217 vError = ::WinGetLastError(vHabmain);
218 sError = wxPMErrorToStr(vError);
219 }
220 if ((hOldBitmap = ::GpiSetBitmap(hPSDst, NULLHANDLE)) == HBM_ERROR)
221 {
222 vError = ::WinGetLastError(vHabmain);
223 sError = wxPMErrorToStr(vError);
224 }
6f38c86f 225
16ff355b 226 vIconInfo.hbmPointer = hBmpMask;
6f38c86f 227
6670f564 228 HICON hIcon = ::WinCreatePointerIndirect( HWND_DESKTOP, &vIconInfo);
6f38c86f
DW
229
230 if (!hIcon)
231 {
232 wxLogLastError(wxT("WinCreatePointerIndirect"));
52315bc3
DW
233 vError = ::WinGetLastError(vHabmain);
234 sError = wxPMErrorToStr(vError);
6f38c86f
DW
235 }
236 else
237 {
238 SetHICON((WXHICON)hIcon);
239 SetSize( rBmp.GetWidth()
240 ,rBmp.GetHeight()
241 );
242 }
243
244 if (!rBmp.GetMask())
245 {
246 //
247 // We created the mask, now delete it
248 //
249 delete pMask;
250 }
16ff355b
DW
251 ::GpiSetBitmap(hPSSrc, NULL);
252 ::GpiSetBitmap(hPSDst, NULL);
253 ::GpiDestroyPS(hPSSrc);
254 ::GpiDestroyPS(hPSDst);
255 ::DevCloseDC(hDCSrc);
256 ::DevCloseDC(hDCDst);
6f38c86f
DW
257} // end of wxIcon::CopyFromBitmap
258
77f4f0a7 259bool wxIcon::LoadFile( const wxString& rFilename,
6b5c2d52 260 wxBitmapType lType,
77f4f0a7
WS
261 int nDesiredWidth,
262 int nDesiredHeight )
fb9010ed 263{
8ea3f821 264 HPS hPs = NULLHANDLE;
3b9e3455
DW
265
266 UnRef();
b41cdbf4
DW
267
268 wxGDIImageHandler* pHandler = FindHandler(lType);
3b9e3455
DW
269
270 if (pHandler)
271 return(pHandler->Load( this
272 ,rFilename
8ea3f821 273 ,hPs
3b9e3455
DW
274 ,lType
275 ,nDesiredWidth
276 ,nDesiredHeight
277 ));
fb9010ed 278 else
77f4f0a7 279 return false;
0e320a79 280}