]> git.saurik.com Git - wxWidgets.git/blame - src/os2/bitmap.cpp
added demo for bitmaps of different size
[wxWidgets.git] / src / os2 / bitmap.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: bitmap.cpp
3// Purpose: wxBitmap
f0a56ab0 4// Author: David Webster
0e320a79 5// Modified by:
f0a56ab0 6// Created: 08/08/99
0e320a79 7// RCS-ID: $Id$
f0a56ab0 8// Copyright: (c) David Webster
0e320a79
DW
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
aa213887
SN
12#ifdef __GNUG__
13 #pragma implementation "bitmap.h"
14#endif
15
d88de032
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifndef WX_PRECOMP
20 #include <stdio.h>
21
22 #include "wx/list.h"
23 #include "wx/utils.h"
24 #include "wx/app.h"
25 #include "wx/palette.h"
26 #include "wx/dcmemory.h"
27 #include "wx/bitmap.h"
28 #include "wx/icon.h"
0e320a79
DW
29#endif
30
d88de032 31#include "wx/os2/private.h"
0e320a79
DW
32#include "wx/log.h"
33
3b9e3455
DW
34//#include "wx/msw/dib.h"
35#include "wx/image.h"
36
d88de032
DW
37// ----------------------------------------------------------------------------
38// macros
39// ----------------------------------------------------------------------------
40
0e320a79
DW
41IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
42IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
3b9e3455
DW
43
44IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject)
0e320a79 45
3b9e3455
DW
46// ============================================================================
47// implementation
48// ============================================================================
49
50// ----------------------------------------------------------------------------
51// wxBitmapRefData
52// ----------------------------------------------------------------------------
53
0e320a79
DW
54wxBitmapRefData::wxBitmapRefData()
55{
3b9e3455
DW
56 m_nQuality = 0;
57 m_pSelectedInto = NULL;
58 m_nNumColors = 0;
59 m_pBitmapMask = NULL;
0e320a79
DW
60}
61
3b9e3455 62void wxBitmapRefData::Free()
0e320a79 63{
3b9e3455
DW
64 wxASSERT_MSG( !m_pSelectedInto,
65 wxT("deleting bitmap still selected into wxMemoryDC") );
0e320a79 66
3b9e3455
DW
67 if (m_hBitmap)
68 {
69 if ( !::GpiDeleteBitmap((HBITMAP)m_hBitmap) )
70 {
71 wxLogLastError("GpiDeleteBitmap(hbitmap)");
72 }
73 }
74
75 delete m_pBitmapMask;
76 m_pBitmapMask = NULL;
0e320a79
DW
77}
78
3b9e3455
DW
79// ----------------------------------------------------------------------------
80// wxBitmap creation
81// ----------------------------------------------------------------------------
0e320a79 82
3b9e3455
DW
83// this function should be called from all wxBitmap ctors
84void wxBitmap::Init()
0e320a79 85{
3b9e3455 86 // m_refData = NULL; done in the base class ctor
0e320a79 87
3b9e3455 88 if (wxTheBitmapList)
0e320a79
DW
89 wxTheBitmapList->AddBitmap(this);
90}
91
3b9e3455
DW
92bool wxBitmap::CopyFromIconOrCursor(
93 const wxGDIImage& rIcon
94)
d88de032 95{
3b9e3455 96 wxBitmapRefData* pRefData = new wxBitmapRefData;
d88de032 97
3b9e3455 98 m_refData = pRefData;
d88de032 99
43543d98
DW
100 pRefData->m_nWidth = rIcon.GetWidth();
101 pRefData->m_nHeight = rIcon.GetHeight();
102 pRefData->m_nDepth = wxDisplayDepth();
d88de032 103
43543d98 104 pRefData->m_hBitmap = (WXHBITMAP)rIcon.GetHandle();
3b9e3455 105 // no mask???
43543d98 106 pRefData->m_pBitmapMask = new wxMask();
d88de032 107
3b9e3455 108#if WXWIN_COMPATIBILITY_2
43543d98 109 pRefData->m_bOk = TRUE;
3b9e3455 110#endif // WXWIN_COMPATIBILITY_2
3b9e3455 111 return(TRUE);
0e320a79
DW
112}
113
3b9e3455
DW
114bool wxBitmap::CopyFromCursor(
115 const wxCursor& rCursor
116)
d88de032 117{
3b9e3455 118 UnRef();
d88de032 119
3b9e3455
DW
120 if (!rCursor.Ok())
121 return(FALSE);
43543d98 122 return(CopyFromIconOrCursor(rCursor));
d88de032
DW
123}
124
3b9e3455
DW
125bool wxBitmap::CopyFromIcon(
126 const wxIcon& rIcon
127)
0e320a79 128{
3b9e3455 129 UnRef();
0e320a79 130
3b9e3455
DW
131 if (!rIcon.Ok())
132 return(FALSE);
0e320a79 133
3b9e3455
DW
134#if WXWIN_COMPATIBILITY_2
135 refData->m_ok = TRUE;
136#endif // WXWIN_COMPATIBILITY_2
0e320a79 137
43543d98 138 return CopyFromIconOrCursor(rIcon);
0e320a79
DW
139}
140
3b9e3455 141wxBitmap::~wxBitmap()
d88de032 142{
3b9e3455
DW
143 if (wxTheBitmapList)
144 wxTheBitmapList->DeleteObject(this);
d88de032
DW
145}
146
3b9e3455
DW
147wxBitmap::wxBitmap(
148 const char zBits[]
149, int nTheWidth
150, int nTheHeight
151, int nNoBits
152)
153{
154 Init();
155
156 wxBitmapRefData* pRefData = new wxBitmapRefData;
157 BITMAPINFOHEADER2 vHeader;
158 BITMAPINFO2 vInfo;
159 HDC hDc;
160 HPS hPs;
43543d98 161 DEVOPENSTRUC vDop = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
3b9e3455
DW
162 SIZEL vSize = {0, 0};
163
43543d98 164 wxASSERT(vHabmain != NULL);
3b9e3455
DW
165
166 hDc = ::DevOpenDC(vHabmain, OD_MEMORY, (PSZ)"*", 1L, (PDEVOPENDATA)&vDop, 0L);
167
168 vHeader.cbFix = sizeof(vHeader);
169 vHeader.cx = (USHORT)nTheWidth;
170 vHeader.cy = (USHORT)nTheHeight;
171 vHeader.cPlanes = 1L;
172 vHeader.cBitCount = nNoBits;
173 vHeader.ulCompression = BCA_UNCOMP;
174 vHeader.cxResolution = 0;
175 vHeader.cyResolution = 0;
176 vHeader.cclrUsed = 0;
177 vHeader.cclrImportant = 0;
178 vHeader.usUnits = BRU_METRIC;
179 vHeader.usRecording = BRA_BOTTOMUP;
180 vHeader.usRendering = BRH_NOTHALFTONED;
181 vHeader.cSize1 = 0;
182 vHeader.cSize2 = 0;
183 vHeader.ulColorEncoding = 0;
184 vHeader.ulIdentifier = 0;
185
43543d98 186 hPs = ::GpiCreatePS(vHabmain, hDc, &vSize, GPIA_ASSOC | PU_PELS);
4f72fe4f 187 if (hPs == 0)
3b9e3455
DW
188 {
189 wxLogLastError("GpiCreatePS Failure");
190 }
0e320a79 191
3b9e3455 192 m_refData = pRefData;
0e320a79 193
43543d98
DW
194 pRefData->m_nWidth = nTheWidth;
195 pRefData->m_nHeight = nTheHeight;
196 pRefData->m_nDepth = nNoBits;
197 pRefData->m_nNumColors = 0;
198 pRefData->m_pSelectedInto = NULL;
0e320a79 199
3b9e3455 200 HBITMAP hBmp = ::GpiCreateBitmap(hPs, &vHeader, 0L, NULL, &vInfo);
43543d98 201 if (!hBmp)
3b9e3455
DW
202 {
203 wxLogLastError("CreateBitmap");
204 }
43543d98 205 SetHBITMAP((WXHBITMAP)hBmp);
0e320a79
DW
206}
207
3b9e3455
DW
208// Create from XPM data
209wxBitmap::wxBitmap(
210 char** ppData
211, wxControl* WXUNUSED(pAnItem))
212{
213 Init();
214
43543d98 215 (void)Create( (void *)ppData
3b9e3455
DW
216 ,wxBITMAP_TYPE_XPM_DATA
217 ,0
218 ,0
219 ,0
220 );
221}
222
223wxBitmap::wxBitmap(
224 int nW
225, int nH
226, int nD
227)
228{
229 Init();
230
231 (void)Create( nW
232 ,nH
233 ,nD
234 );
235}
236
237wxBitmap::wxBitmap(
238 void* pData
239, long lType
240, int nWidth
241, int nHeight
242, int nDepth
243)
244{
245 Init();
246
247 (void)Create( pData
248 ,lType
249 ,nWidth
250 ,nHeight
251 ,nDepth
252 );
253}
254
255wxBitmap::wxBitmap(
256 const wxString& rFilename
257, long lType
258)
259{
260 Init();
261
262 LoadFile( rFilename
263 ,(int)lType
264 );
265}
266
267bool wxBitmap::Create(
268 int nW
269, int nH
270, int nD
271)
272{
273 HBITMAP hBmp;
274 BITMAPINFOHEADER2 vHeader;
275 BITMAPINFO2 vInfo;
4f72fe4f
DW
276 HPS hpsScreen;
277 HDC hdcScreen;
43543d98 278 DEVOPENSTRUC vDop = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
3b9e3455 279 SIZEL vSize = {0, 0};
4f72fe4f 280 LONG lBitCount;
3b9e3455 281
43543d98 282 wxASSERT(vHabmain != NULL);
3b9e3455 283
4f72fe4f
DW
284 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
285 hdcScreen = ::GpiQueryDevice(hpsScreen);
43543d98 286 ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitCount);
3b9e3455
DW
287
288 vHeader.cbFix = sizeof(vHeader);
289 vHeader.cx = (USHORT)nW;
290 vHeader.cy = (USHORT)nH;
291 vHeader.cPlanes = (USHORT)nD;
4f72fe4f 292 vHeader.cBitCount = lBitCount;
3b9e3455
DW
293 vHeader.ulCompression = BCA_UNCOMP;
294 vHeader.cxResolution = 0;
295 vHeader.cyResolution = 0;
296 vHeader.cclrUsed = 0;
297 vHeader.cclrImportant = 0;
298 vHeader.usUnits = BRU_METRIC;
299 vHeader.usRecording = BRA_BOTTOMUP;
300 vHeader.usRendering = BRH_NOTHALFTONED;
301 vHeader.cSize1 = 0;
302 vHeader.cSize2 = 0;
303 vHeader.ulColorEncoding = 0;
304 vHeader.ulIdentifier = 0;
305
0e320a79 306 UnRef();
0e320a79
DW
307 m_refData = new wxBitmapRefData;
308
43543d98
DW
309 GetBitmapData()->m_nWidth = nW;
310 GetBitmapData()->m_nHeight = nH;
311 GetBitmapData()->m_nDepth = nD;
0e320a79 312
3b9e3455
DW
313 if (nD > 0)
314 {
4f72fe4f 315 hBmp = ::GpiCreateBitmap(hpsScreen, &vHeader, 0L, NULL, &vInfo);
3b9e3455
DW
316 if (!hBmp)
317 {
318 wxLogLastError("CreateBitmap");
319 }
320 }
321 else
322 {
4f72fe4f
DW
323 LONG lPlanes;
324
43543d98 325 ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
4f72fe4f
DW
326 hBmp = ::GpiCreateBitmap(hpsScreen, &vHeader, 0L, NULL, &vInfo);
327 if (!hBmp)
3b9e3455 328 {
4f72fe4f 329 wxLogLastError("CreateBitmap");
3b9e3455 330 }
43543d98 331 GetBitmapData()->m_nDepth = wxDisplayDepth();
3b9e3455 332 }
4f72fe4f 333 SetHBITMAP((WXHBITMAP)hBmp);
0e320a79 334
3b9e3455 335#if WXWIN_COMPATIBILITY_2
4f72fe4f 336 GetBitmapData()->m_bOk = hBmp != 0;
3b9e3455
DW
337#endif // WXWIN_COMPATIBILITY_2
338
339 return Ok();
0e320a79
DW
340}
341
4f72fe4f
DW
342bool wxBitmap::LoadFile(
343 const wxString& rFilename
344, long lType
345)
0e320a79 346{
4e0f4f97 347 HPS hPs = NULLHANDLE;
8ea3f821 348
0e320a79
DW
349 UnRef();
350
4f72fe4f
DW
351 wxBitmapHandler* pHandler = wxDynamicCast( FindHandler(lType)
352 ,wxBitmapHandler
353 );
0e320a79 354
4f72fe4f 355 if (pHandler)
3b9e3455
DW
356 {
357 m_refData = new wxBitmapRefData;
0e320a79 358
4f72fe4f
DW
359 return(pHandler->LoadFile( this
360 ,rFilename
8ea3f821 361 ,hPs
4f72fe4f
DW
362 ,lType
363 , -1
364 , -1
43543d98 365 ));
0e320a79 366 }
3b9e3455
DW
367 else
368 {
4f72fe4f 369 wxImage vImage;
0e320a79 370
43543d98 371 if (!vImage.LoadFile(rFilename, lType) || !vImage.Ok() )
4f72fe4f 372 return(FALSE);
3b9e3455 373
4f72fe4f
DW
374 *this = vImage.ConvertToBitmap();
375
376 return(TRUE);
3b9e3455 377 }
0e320a79
DW
378}
379
4f72fe4f
DW
380bool wxBitmap::Create(
381 void* pData
382, long lType
383, int nWidth
384, int nHeight
385, int nDepth
386)
0e320a79
DW
387{
388 UnRef();
389
4f72fe4f
DW
390 wxBitmapHandler* pHandler = wxDynamicCast( FindHandler(lType)
391 ,wxBitmapHandler
392 );
0e320a79 393
4f72fe4f 394 if (!pHandler)
3b9e3455
DW
395 {
396 wxLogDebug(wxT("Failed to create bitmap: no bitmap handler for "
43543d98 397 "type %d defined."), lType);
0e320a79 398
4f72fe4f 399 return(FALSE);
0e320a79
DW
400 }
401
3b9e3455
DW
402 m_refData = new wxBitmapRefData;
403
43543d98
DW
404 return(pHandler->Create( this
405 ,pData
406 ,lType
407 ,nWidth
408 ,nHeight
409 ,nDepth
410 ));
0e320a79
DW
411}
412
58b16424 413bool wxBitmap::SaveFile(
4f72fe4f
DW
414 const wxString& rFilename
415, int lType
416, const wxPalette* pPalette
417)
0e320a79 418{
4f72fe4f
DW
419 wxBitmapHandler* pHandler = wxDynamicCast( FindHandler(lType)
420 ,wxBitmapHandler
421 );
0e320a79 422
4f72fe4f 423 if (pHandler)
3b9e3455 424 {
4f72fe4f
DW
425 return pHandler->SaveFile( this
426 ,rFilename
427 ,lType
428 ,pPalette
429 );
3b9e3455
DW
430 }
431 else
432 {
433 // FIXME what about palette? shouldn't we use it?
4f72fe4f
DW
434 wxImage vImage(*this);
435
436 if (!vImage.Ok())
437 return(FALSE);
0e320a79 438
4f72fe4f
DW
439 return(vImage.SaveFile( rFilename
440 ,lType
441 ));
3b9e3455 442 }
0e320a79
DW
443}
444
3b9e3455
DW
445// ----------------------------------------------------------------------------
446// wxBitmap accessors
447// ----------------------------------------------------------------------------
0e320a79 448
4f72fe4f
DW
449void wxBitmap::SetQuality(
450 int nQ
451)
0e320a79 452{
3b9e3455 453 EnsureHasData();
0e320a79 454
4f72fe4f 455 GetBitmapData()->m_nQuality = nQ;
0e320a79
DW
456}
457
3b9e3455 458#if WXWIN_COMPATIBILITY_2
4f72fe4f
DW
459void wxBitmap::SetOk(
460 bool bOk
461)
0e320a79 462{
3b9e3455 463 EnsureHasData();
0e320a79 464
4f72fe4f 465 GetBitmapData()->m_bOk = bOk;
0e320a79 466}
3b9e3455 467#endif // WXWIN_COMPATIBILITY_2
0e320a79 468
4f72fe4f
DW
469void wxBitmap::SetPalette(
470 const wxPalette& rPalette
471)
0e320a79 472{
3b9e3455 473 EnsureHasData();
0e320a79 474
4f72fe4f 475 GetBitmapData()->m_vBitmapPalette = rPalette;
0e320a79
DW
476}
477
4f72fe4f
DW
478void wxBitmap::SetMask(
479 wxMask* pMask
480)
0e320a79 481{
3b9e3455 482 EnsureHasData();
0e320a79 483
4f72fe4f 484 GetBitmapData()->m_pBitmapMask = pMask;
0e320a79
DW
485}
486
4f72fe4f 487// Will try something for OS/2 but not really sure how close
58b16424 488// to the msw intent this is.
4f72fe4f
DW
489wxBitmap wxBitmap::GetBitmapForDC(
490 wxDC& rDc
491) const
d88de032 492{
4f72fe4f
DW
493 wxMemoryDC vMemDC;
494 wxBitmap vTmpBitmap( this->GetWidth()
495 ,this->GetHeight()
496 ,rDc.GetDepth()
497 );
43543d98 498 WXHBITMAP vOldBitmap;
4f72fe4f
DW
499 HPS hMemoryPS;
500 HPS hPs;
501 POINTL vPoint[4];
43543d98 502 SIZEL vSize = {0,0};
d88de032 503
43543d98
DW
504 hMemoryPS = ::GpiCreatePS(vHabmain, (HDC)vMemDC.GetHDC(), &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
505 hPs = ::GpiCreatePS(vHabmain, (HDC)rDc.GetHDC(), &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
d88de032 506
4f72fe4f 507 // TODO: Set the points
3b9e3455 508
43543d98
DW
509 vOldBitmap = (WXHBITMAP)::GpiSetBitmap(hPs, (HBITMAP)vTmpBitmap.GetHBITMAP());
510 ::GpiBitBlt(hPs, hMemoryPS, 4L, vPoint, ROP_SRCCOPY, BBO_IGNORE);
58b16424
DW
511
512 return(vTmpBitmap);
d88de032
DW
513}
514
3b9e3455
DW
515// ----------------------------------------------------------------------------
516// wxMask
517// ----------------------------------------------------------------------------
0e320a79
DW
518
519wxMask::wxMask()
520{
4f72fe4f 521 m_hMaskBitmap = 0;
0e320a79
DW
522}
523
524// Construct a mask from a bitmap and a colour indicating
525// the transparent area
4f72fe4f
DW
526wxMask::wxMask(
527 const wxBitmap& rBitmap
528, const wxColour& rColour
529)
0e320a79 530{
4f72fe4f
DW
531 m_hMaskBitmap = 0;
532 Create( rBitmap
533 ,rColour
534 );
0e320a79
DW
535}
536
537// Construct a mask from a bitmap and a palette index indicating
538// the transparent area
4f72fe4f
DW
539wxMask::wxMask(
540 const wxBitmap& rBitmap
541, int nPaletteIndex
542)
0e320a79 543{
4f72fe4f
DW
544 m_hMaskBitmap = 0;
545 Create( rBitmap
546 ,nPaletteIndex
547 );
0e320a79
DW
548}
549
550// Construct a mask from a mono bitmap (copies the bitmap).
4f72fe4f
DW
551wxMask::wxMask(
552 const wxBitmap& rBitmap
553)
0e320a79 554{
4f72fe4f
DW
555 m_hMaskBitmap = 0;
556 Create(rBitmap);
0e320a79
DW
557}
558
559wxMask::~wxMask()
560{
4f72fe4f
DW
561 if (m_hMaskBitmap)
562 ::GpiDeleteBitmap((HBITMAP)m_hMaskBitmap);
0e320a79
DW
563}
564
565// Create a mask from a mono bitmap (copies the bitmap).
58b16424
DW
566bool wxMask::Create(
567 const wxBitmap& rBitmap
568)
0e320a79 569{
58b16424 570 BITMAPINFOHEADER2 vHeader;
43543d98 571 DEVOPENSTRUC vDop = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
58b16424
DW
572 SIZEL vSize = {0, 0};
573 POINTL vPoint[4];
574
575 if (m_hMaskBitmap)
3b9e3455 576 {
58b16424
DW
577 ::GpiDeleteBitmap((HBITMAP) m_hMaskBitmap);
578 m_hMaskBitmap = 0;
3b9e3455 579 }
58b16424 580 if (!rBitmap.Ok() || rBitmap.GetDepth() != 1)
3b9e3455 581 {
58b16424 582 return(FALSE);
3b9e3455 583 }
58b16424
DW
584 vHeader.cbFix = sizeof(vHeader);
585 vHeader.cx = (USHORT)rBitmap.GetWidth();
586 vHeader.cy = (USHORT)rBitmap.GetHeight();
587 vHeader.cPlanes = 1;
588 vHeader.cBitCount = 1;
589
590 m_hMaskBitmap = (WXHBITMAP) ::GpiCreateBitmap( m_hPs
591 ,&vHeader
592 ,0L
593 ,NULL
594 ,NULL
595 );
596
597 HPS srcPS = ::GpiCreatePS(vHabmain, m_hDc, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
598 ::GpiSetBitmap(srcPS, (HBITMAP)rBitmap.GetHBITMAP());
599 HPS destPS = ::GpiCreatePS(vHabmain, m_hDc, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
600 ::GpiSetBitmap(srcPS, (HBITMAP)m_hMaskBitmap);
601 // TODO: Set the point array
43543d98 602 ::GpiBitBlt(destPS, srcPS, 4L, vPoint, ROP_SRCCOPY , BBO_IGNORE);
58b16424
DW
603
604 ::GpiDestroyPS(srcPS);
605 ::GpiDestroyPS(destPS);
606 return(TRUE);
0e320a79
DW
607}
608
609// Create a mask from a bitmap and a palette index indicating
610// the transparent area
58b16424
DW
611bool wxMask::Create(
612 const wxBitmap& rBitmap
613, int nPaletteIndex
614)
0e320a79 615{
58b16424 616 if (m_hMaskBitmap)
3b9e3455 617 {
58b16424
DW
618 ::GpiDeleteBitmap((HBITMAP) m_hMaskBitmap);
619 m_hMaskBitmap = 0;
3b9e3455 620 }
58b16424 621 if (rBitmap.Ok() && rBitmap.GetPalette()->Ok())
3b9e3455 622 {
43543d98
DW
623 unsigned char cRed;
624 unsigned char cGreen;
625 unsigned char cBlue;
626
58b16424 627 if (rBitmap.GetPalette()->GetRGB( nPaletteIndex
43543d98
DW
628 ,&cRed
629 ,&cGreen
630 ,&cBlue
58b16424 631 ))
3b9e3455 632 {
43543d98
DW
633 wxColour vTransparentColour( cRed
634 ,cGreen
635 ,cBlue
58b16424
DW
636 );
637
638 return (Create( rBitmap
639 ,vTransparentColour
640 ));
3b9e3455
DW
641 }
642 }
58b16424 643 return(FALSE);
0e320a79
DW
644}
645
646// Create a mask from a bitmap and a colour indicating
647// the transparent area
58b16424
DW
648bool wxMask::Create(
649 const wxBitmap& rBitmap
650, const wxColour& rColour
651)
0e320a79 652{
58b16424 653 BITMAPINFOHEADER2 vHeader;
43543d98 654 DEVOPENSTRUC vDop = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
58b16424
DW
655 SIZEL vSize = {0, 0};
656 POINTL vPoint[4];
657
658 if (m_hMaskBitmap)
3b9e3455 659 {
58b16424
DW
660 ::GpiDeleteBitmap((HBITMAP) m_hMaskBitmap);
661 m_hMaskBitmap = 0;
3b9e3455 662 }
58b16424 663 if (!rBitmap.Ok())
3b9e3455 664 {
58b16424 665 return(FALSE);
3b9e3455
DW
666 }
667
668 // scan the bitmap for the transparent colour and set
669 // the corresponding pixels in the mask to BLACK and
670 // the rest to WHITE
58b16424
DW
671 COLORREF vMaskColour = OS2RGB(rColour.Red(), rColour.Green(), rColour.Blue());
672
673 vHeader.cbFix = sizeof(vHeader);
674 vHeader.cx = (USHORT)rBitmap.GetWidth();
675 vHeader.cy = (USHORT)rBitmap.GetHeight();
676 vHeader.cPlanes = 1;
677 vHeader.cBitCount = 1;
678
679 m_hMaskBitmap = (WXHBITMAP) ::GpiCreateBitmap( m_hPs
680 ,&vHeader
681 ,0L
682 ,NULL
683 ,NULL
684 );
43543d98 685
58b16424
DW
686 HPS srcPS = ::GpiCreatePS(vHabmain, m_hDc, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
687 ::GpiSetBitmap(srcPS, (HBITMAP)rBitmap.GetHBITMAP());
688 HPS destPS = ::GpiCreatePS(vHabmain, m_hDc, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
689 ::GpiSetBitmap(srcPS, (HBITMAP)m_hMaskBitmap);
3b9e3455
DW
690
691 // this is not very efficient, but I can't think
692 // of a better way of doing it
58b16424 693 for (int w = 0; w < rBitmap.GetWidth(); w++)
3b9e3455 694 {
58b16424 695 for (int h = 0; h < rBitmap.GetHeight(); h++)
3b9e3455 696 {
58b16424
DW
697 POINTL vPoint;
698
699 vPoint.x = w;
700 vPoint.y = h;
701
43543d98 702 COLORREF col = ::GpiQueryPel(srcPS, &vPoint);
58b16424
DW
703
704 if (col == vMaskColour)
3b9e3455 705 {
58b16424
DW
706 ::GpiSetColor(destPS, CLR_WHITE);
707 ::GpiSetPel(destPS, &vPoint);
3b9e3455
DW
708 }
709 else
710 {
58b16424
DW
711 ::GpiSetColor(destPS, CLR_BLACK);
712 ::GpiSetPel(destPS, &vPoint);
3b9e3455
DW
713 }
714 }
715 }
58b16424
DW
716 ::GpiDestroyPS(srcPS);
717 ::GpiDestroyPS(destPS);
718 return(TRUE);
0e320a79
DW
719}
720
3b9e3455
DW
721// ----------------------------------------------------------------------------
722// wxBitmapHandler
723// ----------------------------------------------------------------------------
0e320a79 724
58b16424
DW
725bool wxBitmapHandler::Create(
726 wxGDIImage* pImage
727, void* pData
728, long lFlags
729, int nWidth
730, int nHeight
731, int nDepth
732)
3b9e3455 733{
58b16424
DW
734 wxBitmap* pBitmap = wxDynamicCast( pImage
735 ,wxBitmap
736 );
3b9e3455 737
58b16424
DW
738 return(pBitmap ? Create( pBitmap
739 ,pData
740 ,nWidth
741 ,nHeight
742 ,nDepth
743 ) : FALSE);
3b9e3455
DW
744}
745
58b16424
DW
746bool wxBitmapHandler::Load(
747 wxGDIImage* pImage
748, const wxString& rName
8ea3f821 749, HPS hPs
58b16424
DW
750, long lFlags
751, int nWidth
752, int nHeight
753)
3b9e3455 754{
43543d98
DW
755 wxBitmap* pBitmap = wxDynamicCast( pImage
756 ,wxBitmap
757 );
3b9e3455 758
58b16424
DW
759 return(pBitmap ? LoadFile( pBitmap
760 ,rName
8ea3f821 761 ,hPs
58b16424
DW
762 ,lFlags
763 ,nWidth
764 ,nHeight
765 ) : FALSE);
3b9e3455
DW
766}
767
58b16424
DW
768bool wxBitmapHandler::Save(
769 wxGDIImage* pImage
770, const wxString& rName
771, int lType
772)
0e320a79 773{
58b16424
DW
774 wxBitmap* pBitmap = wxDynamicCast( pImage
775 ,wxBitmap
776 );
0e320a79 777
58b16424
DW
778 return(pBitmap ? SaveFile( pBitmap
779 ,rName
780 ,lType
781 ) : FALSE);
0e320a79
DW
782}
783
58b16424
DW
784bool wxBitmapHandler::Create(
785 wxBitmap* WXUNUSED(pBitmap)
786, void* WXUNUSED(pData)
787, long WXUNUSED(lType)
788, int WXUNUSED(nWidth)
789, int WXUNUSED(nHeight)
790, int WXUNUSED(nDepth)
791)
0e320a79 792{
58b16424 793 return(FALSE);
0e320a79
DW
794}
795
58b16424
DW
796bool wxBitmapHandler::LoadFile(
797 wxBitmap* WXUNUSED(pBitmap)
798, const wxString& WXUNUSED(rName)
8ea3f821 799, HPS WXUNUSED(hPs)
58b16424
DW
800, long WXUNUSED(lType)
801, int WXUNUSED(nDesiredWidth)
802, int WXUNUSED(nDesiredHeight)
803)
0e320a79 804{
43543d98 805 return(FALSE);
0e320a79
DW
806}
807
58b16424
DW
808bool wxBitmapHandler::SaveFile(
809 wxBitmap* WXUNUSED(pBitmap)
810, const wxString& WXUNUSED(rName)
811, int WXUNUSED(nType)
812, const wxPalette* WXUNUSED(pPalette)
813)
0e320a79 814{
58b16424 815 return(FALSE);
0e320a79 816}
ce44c50e 817