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