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