]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dc.cpp
OW pedantic warning fix.
[wxWidgets.git] / src / os2 / dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.cpp
3 // Purpose: wxDC class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/14/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/window.h"
17 #include "wx/dc.h"
18 #include "wx/utils.h"
19 #include "wx/dialog.h"
20 #include "wx/app.h"
21 #include "wx/bitmap.h"
22 #include "wx/dcmemory.h"
23 #include "wx/log.h"
24 #include "wx/icon.h"
25 #include "wx/msgdlg.h"
26 #if wxUSE_STATUSBAR
27 #include "wx/statusbr.h"
28 #endif
29 #endif
30
31 #include "wx/module.h"
32 #include "wx/dcprint.h"
33
34 #include <string.h>
35
36 #include "wx/os2/private.h"
37
38 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
39
40 //
41 // wxWidgets uses the Microsoft convention that the origin is the UPPER left.
42 // Native OS/2 however in the GPI and PM define the origin as the LOWER left.
43 // In order to map OS/2 GPI/PM y coordinates to wxWidgets coordinates we must
44 // perform the following transformation:
45 //
46 // Parent object height: POBJHEIGHT
47 // Desried origin: WXORIGINY
48 // Object to place's height: OBJHEIGHT
49 //
50 // To get the OS2 position from the wxWidgets one:
51 //
52 // OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
53 //
54 // For OS/2 wxDC's we will always determine m_vRclPaint as the size of the
55 // OS/2 Presentation Space associated with the device context. y is the
56 // desired application's y coordinate of the origin in wxWidgets space.
57 // objy is the height of the object we are going to draw.
58 //
59 #define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
60
61 // ---------------------------------------------------------------------------
62 // constants
63 // ---------------------------------------------------------------------------
64
65 static const int VIEWPORT_EXTENT = 1000;
66
67 static const int MM_POINTS = 9;
68 static const int MM_METRIC = 10;
69
70 // ---------------------------------------------------------------------------
71 // private functions
72 // ---------------------------------------------------------------------------
73
74 // convert degrees to radians
75 static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
76
77 int SetTextColor(
78 HPS hPS
79 , int nForegroundColour
80 )
81 {
82 CHARBUNDLE vCbnd;
83
84 vCbnd.lColor = nForegroundColour;
85 ::GpiSetAttrs( hPS // presentation-space handle
86 ,PRIM_CHAR // Char primitive.
87 ,CBB_COLOR // sets color.
88 ,0 //
89 ,&vCbnd // buffer for attributes.
90 );
91 return 0;
92 }
93
94 int QueryTextBkColor(
95 HPS hPS
96 )
97 {
98 CHARBUNDLE vCbnd;
99
100 ::GpiQueryAttrs( hPS // presentation-space handle
101 ,PRIM_CHAR // Char primitive.
102 ,CBB_BACK_COLOR // Background color.
103 ,&vCbnd // buffer for attributes.
104 );
105 return vCbnd.lBackColor;
106 }
107
108
109 int SetTextBkColor(
110 HPS hPS
111 , int nBackgroundColour
112 )
113 {
114 CHARBUNDLE vCbnd;
115 int rc;
116
117 rc = QueryTextBkColor(hPS);
118
119 vCbnd.lBackColor = nBackgroundColour;
120 ::GpiSetAttrs(hPS, // presentation-space handle
121 PRIM_CHAR, // Char primitive.
122 CBB_BACK_COLOR, // sets color.
123 0,
124 &vCbnd // buffer for attributes.
125 );
126 return rc;
127 }
128
129 int SetBkMode(
130 HPS hPS
131 , int nBackgroundMode
132 )
133 {
134 if(nBackgroundMode == wxTRANSPARENT)
135 ::GpiSetBackMix( hPS
136 ,BM_LEAVEALONE
137 );
138 else
139 // the background of the primitive takes over whatever is underneath.
140 ::GpiSetBackMix( hPS
141 ,BM_OVERPAINT
142 );
143 return 0;
144 }
145
146 // ===========================================================================
147 // implementation
148 // ===========================================================================
149
150 #if wxUSE_DC_CACHEING
151
152 /*
153 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
154 * improve it in due course, either using arrays, or simply storing pointers to one
155 * entry for the bitmap, and two for the DCs. -- JACS
156 */
157
158 // ---------------------------------------------------------------------------
159 // wxDCCacheEntry
160 // ---------------------------------------------------------------------------
161
162 wxList wxDC::m_svBitmapCache;
163 wxList wxDC::m_svDCCache;
164
165 wxDCCacheEntry::wxDCCacheEntry(
166 WXHBITMAP hBitmap
167 , int nWidth
168 , int nHeight
169 , int nDepth
170 )
171 {
172 m_hBitmap = hBitmap;
173 m_hPS = NULLHANDLE;
174 m_nWidth = nWidth;
175 m_nHeight = nHeight;
176 m_nDepth = nDepth;
177 } // end of wxDCCacheEntry::wxDCCacheEntry
178
179 wxDCCacheEntry::wxDCCacheEntry(
180 HPS hPS
181 , int nDepth
182 )
183 {
184 m_hBitmap = NULLHANDLE;
185 m_hPS = hPS;
186 m_nWidth = 0;
187 m_nHeight = 0;
188 m_nDepth = nDepth;
189 } // end of wxDCCacheEntry::wxDCCacheEntry
190
191 wxDCCacheEntry::~wxDCCacheEntry()
192 {
193 if (m_hBitmap)
194 ::GpiDeleteBitmap(m_hBitmap);
195 if (m_hPS)
196 ::GpiDestroyPS(m_hPS);
197 } // end of wxDCCacheEntry::~wxDCCacheEntry
198
199 wxDCCacheEntry* wxDC::FindBitmapInCache(
200 HPS hPS
201 , int nWidth
202 , int nHeight
203 )
204 {
205 int nDepth = 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
206 wxNode* pNode = m_svBitmapCache.First();
207 BITMAPINFOHEADER2 vBmpHdr;
208
209 while(pNode)
210 {
211 wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data();
212
213 if (pEntry->m_nDepth == nDepth)
214 {
215 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
216
217 if (pEntry->m_nWidth < nWidth || pEntry->m_nHeight < nHeight)
218 {
219 ::GpiDeleteBitmap((HBITMAP)pEntry->m_hBitmap);
220 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
221 vBmpHdr.cx = nWidth;
222 vBmpHdr.cy = nHeight;
223 vBmpHdr.cPlanes = 1;
224 vBmpHdr.cBitCount = nDepth;
225
226 pEntry->m_hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS
227 ,&vBmpHdr
228 ,0L, NULL, NULL
229 );
230 if (!pEntry->m_hBitmap)
231 {
232 wxLogLastError(wxT("CreateCompatibleBitmap"));
233 }
234 pEntry->m_nWidth = nWidth;
235 pEntry->m_nHeight = nHeight;
236 return pEntry;
237 }
238 return pEntry;
239 }
240 pNode = pNode->Next();
241 }
242 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
243 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
244 vBmpHdr.cx = nWidth;
245 vBmpHdr.cy = nHeight;
246 vBmpHdr.cPlanes = 1;
247 vBmpHdr.cBitCount = nDepth;
248
249 WXHBITMAP hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS
250 ,&vBmpHdr
251 ,0L, NULL, NULL
252 );
253 if (!hBitmap)
254 {
255 wxLogLastError(wxT("CreateCompatibleBitmap"));
256 }
257 wxDCCacheEntry* pEntry = new wxDCCacheEntry( hBitmap
258 ,nWidth
259 ,nHeight
260 ,nDepth
261 );
262 AddToBitmapCache(pEntry);
263 return pEntry;
264 } // end of FindBitmapInCache
265
266 wxDCCacheEntry* wxDC::FindDCInCache(
267 wxDCCacheEntry* pNotThis
268 , HPS hPS
269 )
270 {
271 int nDepth = 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
272 wxNode* pNode = m_svDCCache.First();
273
274 while(pNode)
275 {
276 wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data();
277
278 //
279 // Don't return the same one as we already have
280 //
281 if (!pNotThis || (pNotThis != pEntry))
282 {
283 if (pEntry->m_nDepth == nDepth)
284 {
285 return pEntry;
286 }
287 }
288 pNode = pNode->Next();
289 }
290 wxDCCacheEntry* pEntry = new wxDCCacheEntry( hPS
291 ,nDepth
292 );
293 AddToDCCache(pEntry);
294 return pEntry;
295 } // end of wxDC::FindDCInCache
296
297 void wxDC::AddToBitmapCache(
298 wxDCCacheEntry* pEntry
299 )
300 {
301 m_svBitmapCache.Append(pEntry);
302 } // end of wxDC::AddToBitmapCache
303
304 void wxDC::AddToDCCache(
305 wxDCCacheEntry* pEntry
306 )
307 {
308 m_svDCCache.Append(pEntry);
309 } // end of wxDC::AddToDCCache
310
311 void wxDC::ClearCache()
312 {
313 m_svBitmapCache.DeleteContents(true);
314 m_svBitmapCache.Clear();
315 m_svBitmapCache.DeleteContents(false);
316 m_svDCCache.DeleteContents(true);
317 m_svDCCache.Clear();
318 m_svDCCache.DeleteContents(false);
319 } // end of wxDC::ClearCache
320
321 // Clean up cache at app exit
322 class wxDCModule : public wxModule
323 {
324 public:
325 virtual bool OnInit() { return true; }
326 virtual void OnExit() { wxDC::ClearCache(); }
327
328 private:
329 DECLARE_DYNAMIC_CLASS(wxDCModule)
330 }; // end of CLASS wxDCModule
331
332 IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
333
334 #endif // ndef for wxUSE_DC_CACHEING
335
336 // ---------------------------------------------------------------------------
337 // wxDC
338 // ---------------------------------------------------------------------------
339
340 wxDC::wxDC(void)
341 {
342 m_pCanvas = NULL;
343
344 m_hOldBitmap = 0;
345 m_hOldPen = 0;
346 m_hOldBrush = 0;
347 m_hOldFont = 0;
348 m_hOldPalette = 0;
349
350 m_bOwnsDC = false;
351 m_hDC = 0;
352 m_hOldPS = NULL;
353 m_hPS = NULL;
354 m_bIsPaintTime = false; // True at Paint Time
355
356 wxColour vColor( wxT("BLACK") );
357 m_pen.SetColour(vColor);
358
359 vColor.Set( wxT("WHITE") );
360 m_brush.SetColour(vColor);
361
362 } // end of wxDC::wxDC
363
364 wxDC::~wxDC(void)
365 {
366 if ( m_hDC != 0 )
367 {
368 SelectOldObjects(m_hDC);
369
370 // if we own the HDC, we delete it, otherwise we just release it
371
372 if (m_bOwnsDC)
373 {
374 if(m_hPS)
375 {
376 ::GpiAssociate(m_hPS, NULLHANDLE);
377 ::GpiDestroyPS(m_hPS);
378 }
379 m_hPS = NULLHANDLE;
380 ::DevCloseDC((HDC)m_hDC);
381 }
382 else
383 {
384 //
385 // Just Dissacociate, not destroy if we don't own the DC
386 //
387 if(m_hPS)
388 {
389 ::GpiAssociate(m_hPS, NULLHANDLE);
390 }
391 }
392 }
393 } // end of wxDC::~wxDC
394
395 // This will select current objects out of the DC,
396 // which is what you have to do before deleting the
397 // DC.
398 void wxDC::SelectOldObjects(
399 WXHDC hPS
400 )
401 {
402 if (hPS)
403 {
404 if (m_hOldBitmap)
405 {
406 ::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap);
407 if (m_vSelectedBitmap.Ok())
408 {
409 m_vSelectedBitmap.SetSelectedInto(NULL);
410 }
411 }
412 m_hOldBitmap = 0;
413 //
414 // OS/2 has no other native GDI objects to set in a PS/DC like windows
415 //
416 m_hOldPen = 0;
417 m_hOldBrush = 0;
418 m_hOldFont = 0;
419 m_hOldPalette = 0;
420 }
421
422 m_brush = wxNullBrush;
423 m_pen = wxNullPen;
424 m_palette = wxNullPalette;
425 m_font = wxNullFont;
426 m_backgroundBrush = wxNullBrush;
427 m_vSelectedBitmap = wxNullBitmap;
428 } // end of wxDC::SelectOldObjects
429
430 // ---------------------------------------------------------------------------
431 // clipping
432 // ---------------------------------------------------------------------------
433
434 #define DO_SET_CLIPPING_BOX() \
435 { \
436 RECTL rect; \
437 \
438 ::GpiQueryClipBox(m_hPS, &rect); \
439 \
440 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
441 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
442 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
443 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
444 }
445
446 void wxDC::DoSetClippingRegion(
447 wxCoord vX
448 , wxCoord vY
449 , wxCoord vWidth
450 , wxCoord vHeight
451 )
452 {
453 RECTL vRect;
454
455 vY = OS2Y(vY,vHeight);
456 m_clipping = true;
457 vRect.xLeft = vX;
458 vRect.yTop = vY + vHeight;
459 vRect.xRight = vX + vWidth;
460 vRect.yBottom = vY;
461 ::GpiIntersectClipRectangle(m_hPS, &vRect);
462 DO_SET_CLIPPING_BOX()
463 } // end of wxDC::DoSetClippingRegion
464
465 void wxDC::DoSetClippingRegionAsRegion(
466 const wxRegion& rRegion
467 )
468 {
469 wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
470 HRGN hRgnOld;
471
472 m_clipping = true;
473 ::GpiSetClipRegion( m_hPS
474 ,(HRGN)rRegion.GetHRGN()
475 ,&hRgnOld
476 );
477 DO_SET_CLIPPING_BOX()
478 } // end of wxDC::DoSetClippingRegionAsRegion
479
480 void wxDC::DestroyClippingRegion(void)
481 {
482 if (m_clipping && m_hPS)
483 {
484 HRGN hRgnOld;
485 RECTL vRect;
486
487 // TODO: this should restore the previous clipped region
488 // so that OnPaint processing works correctly, and
489 // the update doesn't get destroyed after the first
490 // DestroyClippingRegion
491 vRect.xLeft = XLOG2DEV(0);
492 vRect.yTop = YLOG2DEV(32000);
493 vRect.xRight = XLOG2DEV(32000);
494 vRect.yBottom = YLOG2DEV(0);
495
496 HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
497
498 ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
499 }
500 ResetClipping();
501 } // end of wxDC::DestroyClippingRegion
502
503 // ---------------------------------------------------------------------------
504 // query capabilities
505 // ---------------------------------------------------------------------------
506
507 bool wxDC::CanDrawBitmap() const
508 {
509 return true;
510 }
511
512 bool wxDC::CanGetTextExtent() const
513 {
514 LONG lTechnology = 0L;
515
516 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology);
517 return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER);
518 } // end of wxDC::CanGetTextExtent
519
520 int wxDC::GetDepth() const
521 {
522 LONG lArray[CAPS_COLOR_BITCOUNT];
523 int nBitsPerPixel = 0;
524
525 if(::DevQueryCaps( GetHDC()
526 ,CAPS_FAMILY
527 ,CAPS_COLOR_BITCOUNT
528 ,lArray
529 ))
530 {
531 nBitsPerPixel = (int)lArray[CAPS_COLOR_BITCOUNT];
532 }
533 return nBitsPerPixel;
534 } // end of wxDC::GetDepth
535
536 // ---------------------------------------------------------------------------
537 // drawing
538 // ---------------------------------------------------------------------------
539
540 void wxDC::Clear()
541 {
542 //
543 // If this is a canvas DC then just fill with the background color
544 // Otherwise purge the whole thing
545 //
546 if (m_pCanvas)
547 {
548 RECTL vRect;
549
550 ::GpiQueryClipBox(m_hPS, &vRect);
551 ::WinFillRect(m_hPS, &vRect, ::GpiQueryBackColor(m_hPS));
552 }
553 else
554 ::GpiErase(m_hPS);
555 } // end of wxDC::Clear
556
557 bool wxDC::DoFloodFill(
558 wxCoord vX
559 , wxCoord vY
560 , const wxColour& rCol
561 , int nStyle
562 )
563 {
564 POINTL vPtlPos;
565 LONG lColor;
566 LONG lOptions;
567 LONG lHits;
568 bool bSuccess = false;
569
570 vPtlPos.x = vX; // Loads x-coordinate
571 vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate
572 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
573 lColor = rCol.GetPixel();
574 lOptions = FF_BOUNDARY;
575 if(wxFLOOD_SURFACE == nStyle)
576 lOptions = FF_SURFACE;
577
578 if ((lHits = ::GpiFloodFill(m_hPS, lOptions, lColor)) != GPI_ERROR)
579 bSuccess = true;
580
581 return true;
582 } // end of wxDC::DoFloodFill
583
584 bool wxDC::DoGetPixel(
585 wxCoord vX
586 , wxCoord vY
587 , wxColour* pCol
588 ) const
589 {
590 POINTL vPoint;
591 LONG lColor;
592
593 vPoint.x = vX;
594 vPoint.y = OS2Y(vY,0);
595 lColor = ::GpiSetPel(m_hPS, &vPoint);
596
597 //
598 // Get the color of the pen
599 //
600 LONG lPencolor = 0x00ffffff;
601
602 if (m_pen.Ok())
603 {
604 lPencolor = m_pen.GetColour().GetPixel();
605 }
606
607 //
608 // return the color of the pixel
609 //
610 if(pCol)
611 pCol->Set( GetRValue(lColor)
612 ,GetGValue(lColor)
613 ,GetBValue(lColor)
614 );
615 return(lColor == lPencolor);
616 } // end of wxDC::DoGetPixel
617
618 void wxDC::DoCrossHair(
619 wxCoord vX
620 , wxCoord vY
621 )
622 {
623 vY = OS2Y(vY,0);
624
625 wxCoord vX1 = vX - VIEWPORT_EXTENT;
626 wxCoord vY1 = vY - VIEWPORT_EXTENT;
627 wxCoord vX2 = vX + VIEWPORT_EXTENT;
628 wxCoord vY2 = vY + VIEWPORT_EXTENT;
629 POINTL vPoint[4];
630
631 vPoint[0].x = vX1;
632 vPoint[0].y = vY;
633
634 vPoint[1].x = vX2;
635 vPoint[1].y = vY;
636
637 ::GpiMove(m_hPS, &vPoint[0]);
638 ::GpiLine(m_hPS, &vPoint[1]);
639
640 vPoint[2].x = vX;
641 vPoint[2].y = vY1;
642
643 vPoint[3].x = vX;
644 vPoint[3].y = vY2;
645
646 ::GpiMove(m_hPS, &vPoint[2]);
647 ::GpiLine(m_hPS, &vPoint[3]);
648 CalcBoundingBox(vX1, vY1);
649 CalcBoundingBox(vX2, vY2);
650 } // end of wxDC::DoCrossHair
651
652 void wxDC::DoDrawLine(
653 wxCoord vX1
654 , wxCoord vY1
655 , wxCoord vX2
656 , wxCoord vY2
657 )
658 {
659 POINTL vPoint[2];
660 COLORREF vColor = 0x00ffffff;
661
662 //
663 // Might be a memory DC with no Paint rect.
664 //
665 if (!(m_vRclPaint.yTop == 0 &&
666 m_vRclPaint.yBottom == 0 &&
667 m_vRclPaint.xRight == 0 &&
668 m_vRclPaint.xLeft == 0))
669 {
670 vY1 = OS2Y(vY1,0);
671 vY2 = OS2Y(vY2,0);
672 }
673 else
674 {
675 if (m_vSelectedBitmap != wxNullBitmap)
676 {
677 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
678 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
679 vY1 = OS2Y(vY1,0);
680 vY2 = OS2Y(vY2,0);
681 }
682 }
683 vPoint[0].x = vX1;
684 vPoint[0].y = vY1;
685 vPoint[1].x = vX2;
686 vPoint[1].y = vY2;
687 if (m_pen.Ok())
688 {
689 vColor = m_pen.GetColour().GetPixel();
690 }
691 ::GpiSetColor(m_hPS, vColor);
692 ::GpiMove(m_hPS, &vPoint[0]);
693 ::GpiLine(m_hPS, &vPoint[1]);
694 CalcBoundingBox(vX1, vY1);
695 CalcBoundingBox(vX2, vY2);
696 } // end of wxDC::DoDrawLine
697
698 //////////////////////////////////////////////////////////////////////////////
699 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
700 // and ending at (x2, y2). The current pen is used for the outline and the
701 // current brush for filling the shape. The arc is drawn in an anticlockwise
702 // direction from the start point to the end point.
703 //////////////////////////////////////////////////////////////////////////////
704 void wxDC::DoDrawArc(
705 wxCoord vX1
706 , wxCoord vY1
707 , wxCoord vX2
708 , wxCoord vY2
709 , wxCoord vXc
710 , wxCoord vYc
711 )
712 {
713 POINTL vPtlPos;
714 POINTL vPtlArc[2]; // Structure for current position
715 double dRadius;
716 double dAngl1;
717 double dAngl2;
718 double dAnglmid;
719 wxCoord vXm;
720 wxCoord vYm;
721 ARCPARAMS vArcp; // Structure for arc parameters
722
723 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
724 return; // Draw point ??
725 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
726 ,(double)(vX1 - vXc)
727 ) +
728 hypot( (double)(vY2 - vYc)
729 ,(double)(vX2 - vXc)
730 )
731 );
732
733 dAngl1 = atan2( (double)(vY1 - vYc)
734 ,(double)(vX1 - vXc)
735 );
736 dAngl2 = atan2( (double)(vY2 - vYc)
737 ,(double)(vX2 - vXc)
738 );
739 if(dAngl2 < dAngl1)
740 dAngl2 += M_PI * 2;
741
742 //
743 // GpiPointArc can't draw full arc
744 //
745 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
746 {
747 //
748 // Medium point
749 //
750 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
751 vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
752 vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
753 DoDrawArc( vX1, vY1
754 ,vXm, vYm
755 ,vXc, vYc
756 );
757 DoDrawArc( vXm, vYm
758 ,vX2, vY2
759 ,vXc, vYc
760 );
761 return;
762 }
763
764 //
765 // Medium point
766 //
767 dAnglmid = (dAngl1 + dAngl2)/2.;
768 vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
769 vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
770
771 //
772 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
773 //
774 vArcp.lR = 0;
775 vArcp.lQ = 1;
776 vArcp.lP = 1;
777 vArcp.lS = 0;
778 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
779
780 vPtlPos.x = vX1; // Loads x-coordinate
781 vPtlPos.y = vY1; // Loads y-coordinate
782 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
783 vPtlArc[0].x = vXm;
784 vPtlArc[0].y = vYm;
785 vPtlArc[1].x = vX2;
786 vPtlArc[1].y = vY2;
787 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
788 CalcBoundingBox( (wxCoord)(vXc - dRadius)
789 ,(wxCoord)(vYc - dRadius)
790 );
791 CalcBoundingBox( (wxCoord)(vXc + dRadius)
792 ,(wxCoord)(vYc + dRadius)
793 );
794 } // end of wxDC::DoDrawArc
795
796 void wxDC::DoDrawCheckMark(
797 wxCoord vX1
798 , wxCoord vY1
799 , wxCoord vWidth
800 , wxCoord vHeight
801 )
802 {
803 POINTL vPoint[2];
804
805 vY1 = OS2Y(vY1,vHeight);
806
807 vPoint[0].x = vX1;
808 vPoint[0].y = vY1;
809 vPoint[1].x = vX1 + vWidth;
810 vPoint[1].y = vY1 + vHeight;
811
812 ::GpiMove(m_hPS, &vPoint[0]);
813 ::GpiBox( m_hPS // handle to a presentation space
814 ,DRO_OUTLINE // draw the box outline ? or ?
815 ,&vPoint[1] // address of the corner
816 ,0L // horizontal corner radius
817 ,0L // vertical corner radius
818 );
819 if(vWidth > 4 && vHeight > 4)
820 {
821 int nTmp;
822
823 vPoint[0].x += 2; vPoint[0].y += 2;
824 vPoint[1].x -= 2; vPoint[1].y -= 2;
825 ::GpiMove(m_hPS, &vPoint[0]);
826 ::GpiLine(m_hPS, &vPoint[1]);
827 nTmp = vPoint[0].x;
828 vPoint[0].x = vPoint[1].x;
829 vPoint[1].x = nTmp;
830 ::GpiMove(m_hPS, &vPoint[0]);
831 ::GpiLine(m_hPS, &vPoint[1]);
832 }
833 CalcBoundingBox( vX1
834 ,vY1
835 );
836
837 wxCoord vX2 = vX1 + vWidth;
838 wxCoord vY2 = vY1 + vHeight;
839
840 CalcBoundingBox( vX2
841 ,vY2
842 );
843 } // end of wxDC::DoDrawCheckMark
844
845 void wxDC::DoDrawPoint(
846 wxCoord vX
847 , wxCoord vY
848 )
849 {
850 POINTL vPoint;
851 COLORREF vColor = 0x00ffffff;
852
853 if (m_pen.Ok())
854 {
855 vColor = m_pen.GetColour().GetPixel();
856 }
857 ::GpiSetColor(m_hPS, vColor);
858 vPoint.x = vX;
859 vPoint.y = OS2Y(vY,0);
860 ::GpiSetPel(m_hPS, &vPoint);
861 CalcBoundingBox( vX
862 ,vY
863 );
864 } // end of wxDC::DoDrawPoint
865
866 void wxDC::DoDrawPolygon(
867 int n
868 , wxPoint vPoints[]
869 , wxCoord vXoffset
870 , wxCoord vYoffset
871 , int nFillStyle
872 )
873 {
874 ULONG ulCount = 1; // Number of polygons.
875 POLYGON vPlgn; // polygon.
876 ULONG flOptions = 0L; // Drawing options.
877
878 //////////////////////////////////////////////////////////////////////////////
879 // This contains fields of option bits... to draw boundary lines as well as
880 // the area interior.
881 //
882 // Drawing boundary lines:
883 // POLYGON_NOBOUNDARY Does not draw boundary lines.
884 // POLYGON_BOUNDARY Draws boundary lines (the default).
885 //
886 // Construction of the area interior:
887 // POLYGON_ALTERNATE Constructs interior in alternate mode
888 // (the default).
889 // POLYGON_WINDING Constructs interior in winding mode.
890 //////////////////////////////////////////////////////////////////////////////
891
892 ULONG flModel = 0L; // Drawing model.
893
894 //////////////////////////////////////////////////////////////////////////////
895 // Drawing model.
896 // POLYGON_INCL Fill is inclusive of bottom right (the default).
897 // POLYGON_EXCL Fill is exclusive of bottom right.
898 // This is provided to aid migration from other graphics models.
899 //////////////////////////////////////////////////////////////////////////////
900
901 LONG lHits = 0L; // Correlation/error indicator.
902 POINTL vPoint;
903 int i;
904 int nIsTRANSPARENT = 0;
905 LONG lBorderColor = 0L;
906 LONG lColor = 0L;
907
908 lBorderColor = m_pen.GetColour().GetPixel();
909 lColor = m_brush.GetColour().GetPixel();
910 if(m_brush.GetStyle() == wxTRANSPARENT)
911 nIsTRANSPARENT = 1;
912
913 vPlgn.ulPoints = n;
914 vPlgn.aPointl = (POINTL*) calloc( n + 1
915 ,sizeof(POINTL)
916 ); // well, new will call malloc
917
918 for(i = 0; i < n; i++)
919 {
920 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
921 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
922 }
923 flModel = POLYGON_BOUNDARY;
924 if(nFillStyle == wxWINDING_RULE)
925 flModel |= POLYGON_WINDING;
926 else
927 flModel |= POLYGON_ALTERNATE;
928
929 vPoint.x = vXoffset;
930 vPoint.y = OS2Y(vYoffset,0);
931
932 ::GpiSetColor(m_hPS, lBorderColor);
933 ::GpiMove(m_hPS, &vPoint);
934 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
935 free(vPlgn.aPointl);
936 } // end of wxDC::DoDrawPolygon
937
938 void wxDC::DoDrawLines(
939 int n
940 , wxPoint vPoints[]
941 , wxCoord vXoffset
942 , wxCoord vYoffset
943 )
944 {
945 POINTL vPoint;
946
947 if (vXoffset != 0L || vXoffset != 0L)
948 {
949 int i;
950
951 vPoint.x = vPoints[0].x + vXoffset;
952 vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
953 ::GpiMove(m_hPS, &vPoint);
954
955 LONG lBorderColor = m_pen.GetColour().GetPixel();
956
957 ::GpiSetColor(m_hPS, lBorderColor);
958 for(i = 1; i < n; i++)
959 {
960 vPoint.x = vPoints[i].x + vXoffset;
961 vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
962 ::GpiLine(m_hPS, &vPoint);
963 }
964 }
965 else
966 {
967 int i;
968
969 CalcBoundingBox( vPoints[0].x
970 ,vPoints[0].y
971 );
972 vPoint.x = vPoints[0].x;
973 vPoint.y = OS2Y(vPoints[0].y,0);
974 ::GpiMove(m_hPS, &vPoint);
975
976 for (i = 0; i < n; i++)
977 {
978 CalcBoundingBox( vPoints[i].x
979 ,vPoints[i].y
980 );
981 vPoint.x = vPoints[i].x;
982 vPoint.y = OS2Y(vPoints[i].y,0);
983 ::GpiLine(m_hPS, &vPoint);
984 }
985 }
986 } // end of wxDC::DoDrawLines
987
988 void wxDC::DoDrawRectangle(
989 wxCoord vX
990 , wxCoord vY
991 , wxCoord vWidth
992 , wxCoord vHeight
993 )
994 {
995 POINTL vPoint[2];
996 LONG lControl;
997 LONG lColor;
998 LONG lBorderColor;
999 int nIsTRANSPARENT = 0;
1000
1001 //
1002 // Might be a memory DC with no Paint rect.
1003 //
1004 if (!(m_vRclPaint.yTop == 0 &&
1005 m_vRclPaint.yBottom == 0 &&
1006 m_vRclPaint.xRight == 0 &&
1007 m_vRclPaint.xLeft == 0))
1008 vY = OS2Y(vY,vHeight);
1009 else
1010 {
1011 if (m_vSelectedBitmap != wxNullBitmap)
1012 {
1013 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1014 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1015 vY = OS2Y(vY,vHeight);
1016 }
1017 }
1018
1019 wxCoord vX2 = vX + vWidth;
1020 wxCoord vY2 = vY + vHeight;
1021
1022 vPoint[0].x = vX;
1023 vPoint[0].y = vY;
1024 vPoint[1].x = vX + vWidth - 1;
1025 vPoint[1].y = vY + vHeight - 1;
1026 ::GpiMove(m_hPS, &vPoint[0]);
1027 lColor = m_brush.GetColour().GetPixel();
1028 lBorderColor = m_pen.GetColour().GetPixel();
1029 if (m_brush.GetStyle() == wxTRANSPARENT)
1030 nIsTRANSPARENT = 1;
1031 if(lColor == lBorderColor || nIsTRANSPARENT)
1032 {
1033 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1034 if(m_brush.GetStyle() == wxTRANSPARENT)
1035 lControl = DRO_OUTLINE;
1036
1037 ::GpiSetColor(m_hPS, lBorderColor);
1038 ::GpiBox( m_hPS // handle to a presentation space
1039 ,lControl // draw the box outline ? or ?
1040 ,&vPoint[1] // address of the corner
1041 ,0L // horizontal corner radius
1042 ,0L // vertical corner radius
1043 );
1044 }
1045 else
1046 {
1047 lControl = DRO_OUTLINE;
1048 ::GpiSetColor( m_hPS
1049 ,lBorderColor
1050 );
1051 ::GpiBox( m_hPS
1052 ,lControl
1053 ,&vPoint[1]
1054 ,0L
1055 ,0L
1056 );
1057 lControl = DRO_FILL;
1058 ::GpiSetColor( m_hPS
1059 ,lColor
1060 );
1061 vPoint[0].x = vX + 1;
1062 vPoint[0].y = vY + 1;
1063 vPoint[1].x = vX + vWidth - 2;
1064 vPoint[1].y = vY + vHeight - 2;
1065 ::GpiMove(m_hPS, &vPoint[0]);
1066 ::GpiBox( m_hPS
1067 ,lControl
1068 ,&vPoint[1]
1069 ,0L
1070 ,0L
1071 );
1072 }
1073 CalcBoundingBox(vX, vY);
1074 CalcBoundingBox(vX2, vY2);
1075 } // end of wxDC::DoDrawRectangle
1076
1077 void wxDC::DoDrawRoundedRectangle(
1078 wxCoord vX
1079 , wxCoord vY
1080 , wxCoord vWidth
1081 , wxCoord vHeight
1082 , double dRadius
1083 )
1084 {
1085 POINTL vPoint[2];
1086 LONG lControl;
1087 LONG lColor;
1088 LONG lBorderColor;
1089 int nIsTRANSPARENT = 0;
1090
1091 //
1092 // Might be a memory DC with no Paint rect.
1093 //
1094 if (!(m_vRclPaint.yTop == 0 &&
1095 m_vRclPaint.yBottom == 0 &&
1096 m_vRclPaint.xRight == 0 &&
1097 m_vRclPaint.xLeft == 0))
1098 vY = OS2Y(vY,vHeight);
1099 else
1100 {
1101 if (m_vSelectedBitmap != wxNullBitmap)
1102 {
1103 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1104 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1105 vY = OS2Y(vY,vHeight);
1106 }
1107 }
1108
1109 wxCoord vX2 = (vX + vWidth);
1110 wxCoord vY2 = (vY + vHeight);
1111
1112 vPoint[0].x = vX;
1113 vPoint[0].y = vY;
1114 vPoint[1].x = vX + vWidth - 1;
1115 vPoint[1].y = vY + vHeight - 1;
1116 ::GpiMove(m_hPS, &vPoint[0]);
1117
1118 lColor = m_brush.GetColour().GetPixel();
1119 lBorderColor = m_pen.GetColour().GetPixel();
1120 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1121 if (m_brush.GetStyle() == wxTRANSPARENT)
1122 nIsTRANSPARENT = 1;
1123 if(lColor == lBorderColor || nIsTRANSPARENT)
1124 {
1125 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1126 if(m_brush.GetStyle() == wxTRANSPARENT)
1127 lControl = DRO_OUTLINE;
1128
1129 ::GpiSetColor(m_hPS, lColor);
1130 ::GpiBox( m_hPS // handle to a presentation space
1131 ,lControl // draw the box outline ? or ?
1132 ,&vPoint[1] // address of the corner
1133 ,(LONG)dRadius // horizontal corner radius
1134 ,(LONG)dRadius // vertical corner radius
1135 );
1136 }
1137 else
1138 {
1139 lControl = DRO_OUTLINE;
1140 ::GpiSetColor( m_hPS
1141 ,lBorderColor
1142 );
1143 ::GpiBox( m_hPS
1144 ,lControl
1145 ,&vPoint[1]
1146 ,(LONG)dRadius
1147 ,(LONG)dRadius
1148 );
1149 lControl = DRO_FILL;
1150 ::GpiSetColor( m_hPS
1151 ,lColor
1152 );
1153 vPoint[0].x = vX + 1;
1154 vPoint[0].y = vY + 1;
1155 vPoint[1].x = vX + vWidth - 2;
1156 vPoint[1].y = vY + vHeight - 2;
1157 ::GpiMove(m_hPS, &vPoint[0]);
1158 ::GpiBox( m_hPS
1159 ,lControl
1160 ,&vPoint[1]
1161 ,(LONG)dRadius
1162 ,(LONG)dRadius
1163 );
1164 }
1165
1166 CalcBoundingBox(vX, vY);
1167 CalcBoundingBox(vX2, vY2);
1168 } // end of wxDC::DoDrawRoundedRectangle
1169
1170 // Draw Ellipse within box (x,y) - (x+width, y+height)
1171 void wxDC::DoDrawEllipse(
1172 wxCoord vX
1173 , wxCoord vY
1174 , wxCoord vWidth
1175 , wxCoord vHeight
1176 )
1177 {
1178 POINTL vPtlPos; // Structure for current position
1179 FIXED vFxMult; // Multiplier for ellipse
1180 ARCPARAMS vArcp; // Structure for arc parameters
1181
1182 vY = OS2Y(vY,vHeight);
1183
1184 vArcp.lR = 0;
1185 vArcp.lQ = vHeight/2;
1186 vArcp.lP = vWidth/2;
1187 vArcp.lS = 0;
1188 ::GpiSetArcParams( m_hPS
1189 ,&vArcp
1190 ); // Sets parameters to default
1191 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
1192 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1193 ::GpiMove( m_hPS
1194 ,&vPtlPos
1195 ); // Sets current position
1196 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
1197
1198 //
1199 // DRO_FILL, DRO_OTLINEFILL - where to get
1200 //
1201 ::GpiFullArc( m_hPS
1202 ,DRO_OUTLINE
1203 ,vFxMult
1204 ); // Draws full arc with center at current position
1205
1206 wxCoord vX2 = (vX + vWidth);
1207 wxCoord vY2 = (vY + vHeight);
1208
1209 CalcBoundingBox(vX, vY);
1210 CalcBoundingBox(vX2, vY2);
1211 } // end of wxDC::DoDrawEllipse
1212
1213 void wxDC::DoDrawEllipticArc(
1214 wxCoord vX
1215 , wxCoord vY
1216 , wxCoord vWidth
1217 , wxCoord vHeight
1218 , double dSa
1219 , double dEa
1220 )
1221 {
1222 POINTL vPtlPos; // Structure for current position
1223 FIXED vFxMult; // Multiplier for ellipse
1224 ARCPARAMS vArcp; // Structure for arc parameters
1225 FIXED vFSa;
1226 FIXED vFSweepa; // Start angle, sweep angle
1227 double dIntPart;
1228 double dFractPart;
1229
1230 vY = OS2Y(vY,vHeight);
1231
1232 dFractPart = modf(dSa,&dIntPart);
1233 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1234 dFractPart = modf(dEa - dSa, &dIntPart);
1235 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1236
1237 //
1238 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1239 //
1240 vArcp.lR = 0;
1241 vArcp.lQ = vHeight/2;
1242 vArcp.lP = vWidth/2;
1243 vArcp.lS = 0;
1244 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
1245 vPtlPos.x = (wxCoord)(vX + vWidth/2 * (1. + cos(DegToRad(dSa)))); // Loads x-coordinate
1246 vPtlPos.y = (wxCoord)(vY + vHeight/2 * (1. + sin(DegToRad(dSa)))); // Loads y-coordinate
1247 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
1248
1249 //
1250 // May be not to the center ?
1251 //
1252 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
1253 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1254 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
1255
1256 //
1257 // DRO_FILL, DRO_OTLINEFILL - where to get
1258 //
1259 ::GpiPartialArc( m_hPS
1260 ,&vPtlPos
1261 ,vFxMult
1262 ,vFSa
1263 ,vFSweepa
1264 );
1265 wxCoord vX2 = (vX + vWidth);
1266 wxCoord vY2 = (vY + vHeight);
1267
1268 CalcBoundingBox(vX, vY);
1269 CalcBoundingBox(vX2, vY2);
1270 } // end of wxDC::DoDrawEllipticArc
1271
1272 void wxDC::DoDrawIcon(
1273 const wxIcon& rIcon
1274 , wxCoord vX
1275 , wxCoord vY
1276 )
1277 {
1278 //
1279 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1280 // and I don't feel like figuring those out for scrollable windows so
1281 // just convert to a bitmap then let the DoDrawBitmap routing display it
1282 //
1283 if (rIcon.IsXpm())
1284 {
1285 DoDrawBitmap(rIcon.GetXpmSrc(), vX, vY, true);
1286 }
1287 else
1288 {
1289 wxBitmap vBitmap(rIcon);
1290
1291 DoDrawBitmap(vBitmap, vX, vY, false);
1292 }
1293 CalcBoundingBox(vX, vY);
1294 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
1295 } // end of wxDC::DoDrawIcon
1296
1297 void wxDC::DoDrawBitmap(
1298 const wxBitmap& rBmp
1299 , wxCoord vX
1300 , wxCoord vY
1301 , bool bUseMask
1302 )
1303 {
1304 if (!IsKindOf(CLASSINFO(wxPrinterDC)))
1305 {
1306 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
1307 HBITMAP hBitmapOld = NULLHANDLE;;
1308 POINTL vPoint[4];
1309
1310 vY = OS2Y(vY,rBmp.GetHeight());
1311
1312 vPoint[0].x = vX;
1313 vPoint[0].y = vY + rBmp.GetHeight();
1314 vPoint[1].x = vX + rBmp.GetWidth();
1315 vPoint[1].y = vY;
1316 vPoint[2].x = 0;
1317 vPoint[2].y = 0;
1318 vPoint[3].x = rBmp.GetWidth();
1319 vPoint[3].y = rBmp.GetHeight();
1320 if (bUseMask)
1321 {
1322 wxMask* pMask = rBmp.GetMask();
1323
1324 if (pMask)
1325 {
1326 //
1327 // Need to imitate ::MaskBlt in windows.
1328 // 1) Extract the bits from from the bitmap.
1329 // 2) Extract the bits from the mask
1330 // 3) Using the mask bits do the following:
1331 // A) If the mask byte is 00 leave the bitmap byte alone
1332 // B) If the mask byte is FF copy the screen color into
1333 // bitmap byte
1334 // 4) Create a new bitmap and set its bits to the above result
1335 // 5) Blit this to the screen PS
1336 //
1337 HBITMAP hMask = (HBITMAP)pMask->GetMaskBitmap();
1338 HBITMAP hOldMask = NULLHANDLE;
1339 HBITMAP hOldBitmap = NULLHANDLE;
1340 HBITMAP hNewBitmap = NULLHANDLE;
1341 unsigned char* pucBits; // buffer that will contain the bitmap data
1342 unsigned char* pucBitsMask; // buffer that will contain the mask data
1343 unsigned char* pucData; // pointer to use to traverse bitmap data
1344 unsigned char* pucDataMask; // pointer to use to traverse mask data
1345 LONG lHits;
1346 ERRORID vError;
1347 wxString sError;
1348
1349 //
1350 // The usual Memory context creation stuff
1351 //
1352 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1353 SIZEL vSize = {0, 0};
1354 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
1355 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
1356
1357 //
1358 // The usual bitmap header stuff
1359 //
1360 BITMAPINFOHEADER2 vHeader;
1361 BITMAPINFO2 vInfo;
1362
1363 memset(&vHeader, '\0', 16);
1364 vHeader.cbFix = 16;
1365
1366 memset(&vInfo, '\0', 16);
1367 vInfo.cbFix = 16;
1368 vInfo.cx = (ULONG)rBmp.GetWidth();
1369 vInfo.cy = (ULONG)rBmp.GetHeight();
1370 vInfo.cPlanes = 1;
1371 vInfo.cBitCount = 24; // Set to desired count going in
1372
1373 //
1374 // Create the buffers for data....all wxBitmaps are 24 bit internally
1375 //
1376 int nBytesPerLine = rBmp.GetWidth() * 3;
1377 int nSizeDWORD = sizeof(DWORD);
1378 int nLineBoundary = nBytesPerLine % nSizeDWORD;
1379 int nPadding = 0;
1380 int i;
1381 int j;
1382 LONG lScans = 0L;
1383 LONG lColor = 0L;
1384
1385 //
1386 // Need to get a background color for mask blitting
1387 //
1388 if (IsKindOf(CLASSINFO(wxWindowDC)))
1389 {
1390 wxWindowDC* pWindowDC = wxDynamicCast(this, wxWindowDC);
1391
1392 lColor = pWindowDC->m_pCanvas->GetBackgroundColour().GetPixel();
1393 }
1394 else if (GetBrush().Ok())
1395 lColor = GetBrush().GetColour().GetPixel();
1396 else
1397 lColor = m_textBackgroundColour.GetPixel();
1398
1399 //
1400 // Bitmap must be ina double-word alligned address so we may
1401 // have some padding to worry about
1402 //
1403 if (nLineBoundary > 0)
1404 {
1405 nPadding = nSizeDWORD - nLineBoundary;
1406 nBytesPerLine += nPadding;
1407 }
1408 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
1409 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
1410 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
1411 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
1412
1413 //
1414 // Extract the bitmap and mask data
1415 //
1416 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
1417 {
1418 vError = ::WinGetLastError(vHabmain);
1419 sError = wxPMErrorToStr(vError);
1420 }
1421 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
1422 vInfo.cBitCount = 24;
1423 if ((lScans = ::GpiQueryBitmapBits( hPS
1424 ,0L
1425 ,(LONG)rBmp.GetHeight()
1426 ,(PBYTE)pucBits
1427 ,&vInfo
1428 )) == GPI_ALTERROR)
1429 {
1430 vError = ::WinGetLastError(vHabmain);
1431 sError = wxPMErrorToStr(vError);
1432 }
1433 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
1434 {
1435 vError = ::WinGetLastError(vHabmain);
1436 sError = wxPMErrorToStr(vError);
1437 }
1438 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
1439 vInfo.cBitCount = 24;
1440 if ((lScans = ::GpiQueryBitmapBits( hPS
1441 ,0L
1442 ,(LONG)rBmp.GetHeight()
1443 ,(PBYTE)pucBitsMask
1444 ,&vInfo
1445 )) == GPI_ALTERROR)
1446 {
1447 vError = ::WinGetLastError(vHabmain);
1448 sError = wxPMErrorToStr(vError);
1449 }
1450 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
1451 {
1452 vError = ::WinGetLastError(vHabmain);
1453 sError = wxPMErrorToStr(vError);
1454 }
1455
1456 //
1457 // Now set the bytes(bits) according to the mask values
1458 // 3 bytes per pel...must handle one at a time
1459 //
1460 pucData = pucBits;
1461 pucDataMask = pucBitsMask;
1462
1463 //
1464 // 16 bit kludge really only kinda works. The mask gets applied
1465 // where needed but the original bitmap bits are dorked sometimes
1466 //
1467 bool bpp16 = (wxDisplayDepth() == 16);
1468
1469 for (i = 0; i < rBmp.GetHeight(); i++)
1470 {
1471 for (j = 0; j < rBmp.GetWidth(); j++)
1472 {
1473 // Byte 1
1474 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
1475 pucData++;
1476 else if (*pucDataMask == 0xFF) // leave bitmap byte alone
1477 pucData++;
1478 else
1479 {
1480 *pucData = ((unsigned char)(lColor >> 16));
1481 pucData++;
1482 }
1483 // Byte 2
1484 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
1485 pucData++;
1486 else if (*(pucDataMask + 1) == 0xFF) // leave bitmap byte alone
1487 pucData++;
1488 else
1489 {
1490 *pucData = ((unsigned char)(lColor >> 8));
1491 pucData++;
1492 }
1493
1494 // Byte 3
1495 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
1496 pucData++;
1497 else if (*(pucDataMask + 2) == 0xFF) // leave bitmap byte alone
1498 pucData++;
1499 else
1500 {
1501 *pucData = ((unsigned char)lColor);
1502 pucData++;
1503 }
1504 pucDataMask += 3;
1505 }
1506 for (j = 0; j < nPadding; j++)
1507 {
1508 pucData++;
1509 pucDataMask++;
1510 }
1511 }
1512 //
1513 // Create a new bitmap
1514 //
1515 vHeader.cx = (ULONG)rBmp.GetWidth();
1516 vHeader.cy = (ULONG)rBmp.GetHeight();
1517 vHeader.cPlanes = 1L;
1518 vHeader.cBitCount = 24;
1519 if ((hNewBitmap = ::GpiCreateBitmap( hPS
1520 ,&vHeader
1521 ,CBM_INIT
1522 ,(PBYTE)pucBits
1523 ,&vInfo
1524 )) == GPI_ERROR)
1525 {
1526 vError = ::WinGetLastError(vHabmain);
1527 sError = wxPMErrorToStr(vError);
1528 }
1529
1530 //
1531 // Now blit it to the screen PS
1532 //
1533 if ((lHits = ::GpiWCBitBlt( (HPS)GetHPS()
1534 ,hNewBitmap
1535 ,4
1536 ,vPoint
1537 ,ROP_SRCCOPY
1538 ,BBO_IGNORE
1539 )) == GPI_ERROR)
1540 {
1541 vError = ::WinGetLastError(vHabmain);
1542 sError = wxPMErrorToStr(vError);
1543 }
1544
1545 //
1546 // Clean up
1547 //
1548 free(pucBits);
1549 free(pucBitsMask);
1550 ::GpiSetBitmap(hPS, NULLHANDLE);
1551 ::GpiDeleteBitmap(hNewBitmap);
1552 ::GpiDestroyPS(hPS);
1553 ::DevCloseDC(hDC);
1554 }
1555 }
1556 else
1557 {
1558 ULONG lOldForeGround = ::GpiQueryColor((HPS)GetHPS());
1559 ULONG lOldBackGround = ::GpiQueryBackColor((HPS)GetHPS());
1560
1561 if (m_textForegroundColour.Ok())
1562 {
1563 ::GpiSetColor( (HPS)GetHPS()
1564 ,m_textForegroundColour.GetPixel()
1565 );
1566 }
1567 if (m_textBackgroundColour.Ok())
1568 {
1569 ::GpiSetBackColor( (HPS)GetHPS()
1570 ,m_textBackgroundColour.GetPixel()
1571 );
1572 }
1573 //
1574 // Need to alter bits in a mono bitmap to match the new
1575 // background-foreground if it is different.
1576 //
1577 if (rBmp.IsMono() &&
1578 ((m_textForegroundColour.GetPixel() != lOldForeGround) ||
1579 (m_textBackgroundColour.GetPixel() != lOldBackGround)))
1580 {
1581 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1582 SIZEL vSize = {0, 0};
1583 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
1584 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
1585
1586 int nBytesPerLine = rBmp.GetWidth() * 3;
1587 int i, j;
1588 LONG lForeGround = m_textForegroundColour.GetPixel();
1589 LONG lBackGround = m_textBackgroundColour.GetPixel();
1590 LONG lScans;
1591 HBITMAP hOldBitmap = NULLHANDLE;
1592 BITMAPINFO2 vInfo;
1593 ERRORID vError;
1594 wxString sError;
1595
1596
1597 memset(&vInfo, '\0', 16);
1598 vInfo.cbFix = 16;
1599 vInfo.cx = (ULONG)rBmp.GetWidth();
1600 vInfo.cy = (ULONG)rBmp.GetHeight();
1601 vInfo.cPlanes = 1;
1602 vInfo.cBitCount = 24;
1603
1604 unsigned char* pucBits; // buffer that will contain the bitmap data
1605 unsigned char* pucData; // pointer to use to traverse bitmap data
1606
1607 pucBits = new unsigned char[nBytesPerLine * rBmp.GetHeight()];
1608 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
1609
1610 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
1611 {
1612 vError = ::WinGetLastError(vHabmain);
1613 sError = wxPMErrorToStr(vError);
1614 return;
1615 }
1616 if ((lScans = ::GpiQueryBitmapBits( hPS
1617 ,0L
1618 ,(LONG)rBmp.GetHeight()
1619 ,(PBYTE)pucBits
1620 ,&vInfo
1621 )) == GPI_ALTERROR)
1622 {
1623 vError = ::WinGetLastError(vHabmain);
1624 sError = wxPMErrorToStr(vError);
1625 return;
1626 }
1627 unsigned char cOldRedFore = (unsigned char)(lOldForeGround >> 16);
1628 unsigned char cOldGreenFore = (unsigned char)(lOldForeGround >> 8);
1629 unsigned char cOldBlueFore = (unsigned char)lOldForeGround;
1630
1631 unsigned char cRedFore = (unsigned char)(lForeGround >> 16);
1632 unsigned char cGreenFore = (unsigned char)(lForeGround >> 8);
1633 unsigned char cBlueFore = (unsigned char)lForeGround;
1634
1635 unsigned char cRedBack = (unsigned char)(lBackGround >> 16);
1636 unsigned char cGreenBack = (unsigned char)(lBackGround >> 8);
1637 unsigned char cBlueBack = (unsigned char)lBackGround;
1638
1639 pucData = pucBits;
1640 for (i = 0; i < rBmp.GetHeight(); i++)
1641 {
1642 for (j = 0; j < rBmp.GetWidth(); j++)
1643 {
1644 unsigned char cBmpRed = *pucData;
1645 unsigned char cBmpGreen = *(pucData + 1);
1646 unsigned char cBmpBlue = *(pucData + 2);
1647
1648 if ((cBmpRed == cOldRedFore) &&
1649 (cBmpGreen == cOldGreenFore) &&
1650 (cBmpBlue == cOldBlueFore))
1651 {
1652 *pucData = cBlueFore;
1653 pucData++;
1654 *pucData = cGreenFore;
1655 pucData++;
1656 *pucData = cRedFore;
1657 pucData++;
1658 }
1659 else
1660 {
1661 *pucData = cBlueBack;
1662 pucData++;
1663 *pucData = cGreenBack;
1664 pucData++;
1665 *pucData = cRedBack;
1666 pucData++;
1667 }
1668 }
1669 }
1670 if ((lScans = ::GpiSetBitmapBits( hPS
1671 ,0L
1672 ,(LONG)rBmp.GetHeight()
1673 ,(PBYTE)pucBits
1674 ,&vInfo
1675 )) == GPI_ALTERROR)
1676 {
1677 vError = ::WinGetLastError(vHabmain);
1678 sError = wxPMErrorToStr(vError);
1679 return;
1680 }
1681 delete [] pucBits;
1682 ::GpiSetBitmap(hPS, NULLHANDLE);
1683 ::GpiDestroyPS(hPS);
1684 ::DevCloseDC(hDC);
1685 }
1686 ::GpiWCBitBlt( (HPS)GetHPS()
1687 ,hBitmap
1688 ,4
1689 ,vPoint
1690 ,ROP_SRCCOPY
1691 ,BBO_IGNORE
1692 );
1693 ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld);
1694 ::GpiSetColor((HPS)GetHPS(), lOldForeGround);
1695 ::GpiSetBackColor((HPS)GetHPS(), lOldBackGround);
1696 }
1697 }
1698 } // end of wxDC::DoDrawBitmap
1699
1700 void wxDC::DoDrawText(
1701 const wxString& rsText
1702 , wxCoord vX
1703 , wxCoord vY
1704 )
1705 {
1706 wxCoord vWidth;
1707 wxCoord vHeight;
1708
1709 DrawAnyText( rsText
1710 ,vX
1711 ,vY
1712 );
1713
1714 CalcBoundingBox(vX, vY);
1715 GetTextExtent(rsText, &vWidth, &vHeight);
1716 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1717 } // end of wxDC::DoDrawText
1718
1719 void wxDC::DrawAnyText(
1720 const wxString& rsText
1721 , wxCoord vX
1722 , wxCoord vY
1723 )
1724 {
1725 int nOldBackground = 0;
1726 POINTL vPtlStart;
1727 LONG lHits;
1728 wxCoord vTextX = 0;
1729 wxCoord vTextY = 0;
1730
1731 //
1732 // prepare for drawing the text
1733 //
1734
1735 //
1736 // Set text color attributes
1737 //
1738 if (m_textForegroundColour.Ok())
1739 {
1740 SetTextColor( m_hPS
1741 ,(int)m_textForegroundColour.GetPixel()
1742 );
1743 }
1744
1745 if (m_textBackgroundColour.Ok())
1746 {
1747 nOldBackground = SetTextBkColor( m_hPS
1748 ,(int)m_textBackgroundColour.GetPixel()
1749 );
1750 }
1751 SetBkMode( m_hPS
1752 ,m_backgroundMode
1753 );
1754 GetTextExtent( rsText
1755 ,&vTextX
1756 ,&vTextY
1757 );
1758 vPtlStart.x = vX;
1759 if (!(m_vRclPaint.yTop == 0 &&
1760 m_vRclPaint.yBottom == 0 &&
1761 m_vRclPaint.xRight == 0 &&
1762 m_vRclPaint.xLeft == 0))
1763 {
1764 //
1765 // Position Text a little differently in the Statusbar from other panels
1766 //
1767 if (m_pCanvas && m_pCanvas->IsKindOf(CLASSINFO(wxStatusBar)))
1768 vPtlStart.y = OS2Y(vY,vTextY);
1769 else
1770 vPtlStart.y = (wxCoord)(OS2Y(vY,vTextY/1.5)); // Full extent is a bit much
1771 }
1772 else
1773 {
1774 if (m_vSelectedBitmap != wxNullBitmap)
1775 {
1776 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1777 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1778 if (m_pCanvas && m_pCanvas->IsKindOf(CLASSINFO(wxStatusBar)))
1779 vPtlStart.y = OS2Y(vY,vTextY);
1780 else
1781 vPtlStart.y = (LONG)(OS2Y(vY,vTextY/1.5));
1782 }
1783 else
1784 vPtlStart.y = vY;
1785 }
1786
1787 PCH pzStr = (PCH)rsText.c_str();
1788
1789 ::GpiMove(m_hPS, &vPtlStart);
1790 lHits = ::GpiCharString( m_hPS
1791 ,rsText.length()
1792 ,pzStr
1793 );
1794 if (lHits != GPI_OK)
1795 {
1796 wxLogLastError(wxT("TextOut"));
1797 }
1798
1799 //
1800 // Restore the old parameters (text foreground colour may be left because
1801 // it never is set to anything else, but background should remain
1802 // transparent even if we just drew an opaque string)
1803 //
1804 if (m_textBackgroundColour.Ok())
1805 SetTextBkColor( m_hPS
1806 ,nOldBackground
1807 );
1808 SetBkMode( m_hPS
1809 ,wxTRANSPARENT
1810 );
1811 }
1812
1813 void wxDC::DoDrawRotatedText(
1814 const wxString& rsText
1815 , wxCoord vX
1816 , wxCoord vY
1817 , double dAngle
1818 )
1819 {
1820 if (dAngle == 0.0)
1821 {
1822 DoDrawText( rsText
1823 ,vX
1824 ,vY
1825 );
1826 }
1827
1828 // TODO:
1829 /*
1830 if ( angle == 0.0 )
1831 {
1832 DoDrawText(text, x, y);
1833 }
1834 else
1835 {
1836 LOGFONT lf;
1837 wxFillLogFont(&lf, &m_font);
1838
1839 // GDI wants the angle in tenth of degree
1840 long angle10 = (long)(angle * 10);
1841 lf.lfEscapement = angle10;
1842 lf. lfOrientation = angle10;
1843
1844 HFONT hfont = ::CreateFontIndirect(&lf);
1845 if ( !hfont )
1846 {
1847 wxLogLastError("CreateFont");
1848 }
1849 else
1850 {
1851 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1852
1853 DrawAnyText(text, x, y);
1854
1855 (void)::SelectObject(GetHdc(), hfontOld);
1856 }
1857
1858 // call the bounding box by adding all four vertices of the rectangle
1859 // containing the text to it (simpler and probably not slower than
1860 // determining which of them is really topmost/leftmost/...)
1861 wxCoord w, h;
1862 GetTextExtent(text, &w, &h);
1863
1864 double rad = DegToRad(angle);
1865
1866 // "upper left" and "upper right"
1867 CalcBoundingBox(x, y);
1868 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1869 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1870
1871 // "bottom left" and "bottom right"
1872 x += (wxCoord)(h*sin(rad));
1873 y += (wxCoord)(h*cos(rad));
1874 CalcBoundingBox(x, y);
1875 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1876 }
1877 */
1878 }
1879
1880 // ---------------------------------------------------------------------------
1881 // set GDI objects
1882 // ---------------------------------------------------------------------------
1883
1884 void wxDC::DoSelectPalette(
1885 bool bRealize
1886 )
1887 {
1888 //
1889 // Set the old object temporarily, in case the assignment deletes an object
1890 // that's not yet selected out.
1891 //
1892 if (m_hOldPalette)
1893 {
1894 m_hOldPalette = 0;
1895 }
1896
1897 if (m_palette.Ok())
1898 {
1899 HPALETTE hOldPal;
1900
1901 hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1902 if (!m_hOldPalette)
1903 m_hOldPalette = (WXHPALETTE)hOldPal;
1904 }
1905 } // end of wxDC::DoSelectPalette
1906
1907 void wxDC::InitializePalette()
1908 {
1909 if (wxDisplayDepth() <= 8 )
1910 {
1911 //
1912 // Look for any window or parent that has a custom palette. If any has
1913 // one then we need to use it in drawing operations
1914 //
1915 wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette();
1916
1917 m_hasCustomPalette = pWin && pWin->HasCustomPalette();
1918 if (m_hasCustomPalette)
1919 {
1920 m_palette = pWin->GetPalette();
1921
1922 //
1923 // turn on PM translation for this palette
1924 //
1925 DoSelectPalette();
1926 }
1927 }
1928 } // end of wxDC::InitializePalette
1929
1930 void wxDC::SetPalette(
1931 const wxPalette& rPalette
1932 )
1933 {
1934 if (m_hOldFont)
1935 {
1936 m_hOldFont = 0;
1937 }
1938 m_palette = rPalette;
1939 if (!rPalette.Ok())
1940 {
1941 if (m_hOldFont)
1942 {
1943 m_hOldFont = 0;
1944 }
1945 }
1946 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1947 if (!m_hOldPalette)
1948 m_hOldPalette = (WXHPALETTE)hOldPal;
1949 } // end of wxDC::SetPalette
1950
1951 void wxDC::SetFont(
1952 const wxFont& rFont
1953 )
1954 {
1955 //
1956 // Set the old object temporarily, in case the assignment deletes an object
1957 // that's not yet selected out.
1958 //
1959 if (m_hOldFont)
1960 {
1961 m_hOldFont = 0;
1962 }
1963 m_font = rFont;
1964 if (!rFont.Ok())
1965 {
1966 m_hOldFont = 0;
1967 }
1968
1969 m_font.SetPS(m_hPS); // this will realize the font
1970
1971 if (m_font.Ok())
1972 {
1973 HFONT hFont = m_font.GetResourceHandle();
1974 if (hFont == (HFONT) NULL)
1975 {
1976 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1977 }
1978 if (!m_hOldFont)
1979 m_hOldFont = (WXHFONT) hFont;
1980 }
1981 } // end of wxDC::SetFont
1982
1983 void wxDC::SetPen(
1984 const wxPen& rPen
1985 )
1986 {
1987 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1988
1989 if (m_pen == rPen)
1990 return;
1991 m_pen = rPen;
1992 if (!m_pen.Ok())
1993 return;
1994
1995 if (m_hOldPen)
1996 m_hOldPen = 0L;
1997 m_pen = rPen;
1998
1999 if (!m_pen.Ok())
2000 {
2001 if (m_hOldPen)
2002 {
2003 m_pen.SetPS((HPS)m_hOldPen);
2004 }
2005 m_hOldPen = 0L;
2006 }
2007
2008 if (m_pen.Ok())
2009 {
2010 if (m_pen.GetResourceHandle())
2011 {
2012 m_pen.SetPS(m_hPS);
2013 if (!m_hOldPen)
2014 m_hOldPen = m_pen.GetPS();
2015 }
2016 ::GpiSetColor(m_hPS, m_pen.GetColour().GetPixel());
2017 }
2018 }
2019
2020 void wxDC::SetBrush(
2021 const wxBrush& rBrush
2022 )
2023 {
2024 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2025
2026 if (m_hOldBrush)
2027 m_hOldBrush = 0L;
2028 m_brush = rBrush;
2029 if (!m_brush.Ok())
2030 if (m_brush == rBrush)
2031 return;
2032 if (!m_brush.Ok())
2033 if (m_hOldBrush)
2034 m_hOldBrush = 0L;
2035
2036 if (!m_brush.Ok())
2037 {
2038 if (m_hOldBrush)
2039 {
2040 m_brush.SetPS((HPS)m_hOldBrush);
2041 }
2042 m_hOldBrush = 0L;
2043 }
2044
2045 if (m_brush.Ok())
2046 {
2047 if (m_brush.GetResourceHandle())
2048 {
2049 m_brush.SetPS(m_hPS);
2050 if (!m_hOldBrush)
2051 m_hOldBrush = (WXHWND)m_brush.GetPS();
2052 }
2053 }
2054 } // end of wxDC::SetBrush
2055
2056 void wxDC::SetBackground(
2057 const wxBrush& rBrush
2058 )
2059 {
2060 m_backgroundBrush = rBrush;
2061 if (!m_backgroundBrush.Ok())
2062 return;
2063 if (m_pCanvas)
2064 {
2065 bool bCustomColours = true;
2066
2067 //
2068 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
2069 // change background colours from the control-panel specified colours.
2070 //
2071 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
2072 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
2073 bCustomColours = false;
2074 if (bCustomColours)
2075 {
2076 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
2077 {
2078 m_pCanvas->SetTransparent(true);
2079 }
2080 else
2081 {
2082 //
2083 // Setting the background brush of a DC
2084 // doesn't affect the window background colour. However,
2085 // I'm leaving in the transparency setting because it's needed by
2086 // various controls (e.g. wxStaticText) to determine whether to draw
2087 // transparently or not. TODO: maybe this should be a new function
2088 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
2089 // parent?
2090 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
2091 //
2092 m_pCanvas->SetTransparent(false);
2093 }
2094 }
2095 }
2096 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
2097 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
2098 } // end of wxDC::SetBackground
2099
2100 void wxDC::SetBackgroundMode(
2101 int nMode
2102 )
2103 {
2104 m_backgroundMode = nMode;
2105 } // end of wxDC::SetBackgroundMode
2106
2107 void wxDC::SetLogicalFunction(
2108 int nFunction
2109 )
2110 {
2111 m_logicalFunction = nFunction;
2112 SetRop((WXHDC)m_hDC);
2113 } // wxDC::SetLogicalFunction
2114
2115 void wxDC::SetRop(
2116 WXHDC hDC
2117 )
2118 {
2119 if (!hDC || m_logicalFunction < 0)
2120 return;
2121
2122 LONG lCRop;
2123 switch (m_logicalFunction)
2124 {
2125 case wxXOR:
2126 lCRop = FM_XOR;
2127 break;
2128
2129 case wxINVERT:
2130 lCRop = FM_INVERT;
2131 break;
2132
2133 case wxOR_REVERSE:
2134 lCRop = FM_MERGESRCNOT;
2135 break;
2136
2137 case wxAND_REVERSE:
2138 lCRop = FM_NOTMASKSRC;
2139 break;
2140
2141 case wxCLEAR:
2142 lCRop = FM_ONE;
2143 break;
2144
2145 case wxSET:
2146 lCRop = FM_ZERO;
2147 break;
2148
2149 case wxSRC_INVERT:
2150 lCRop = FM_MERGENOTSRC;
2151 break;
2152
2153 case wxOR_INVERT:
2154 lCRop = FM_MERGESRCNOT;
2155 break;
2156
2157 case wxAND:
2158 lCRop = FM_AND;
2159 break;
2160
2161 case wxOR:
2162 lCRop = FM_OR;
2163 break;
2164
2165 case wxAND_INVERT:
2166 lCRop = FM_SUBTRACT;
2167 break;
2168
2169 case wxEQUIV:
2170 case wxNAND:
2171 case wxCOPY:
2172 default:
2173 lCRop = FM_OVERPAINT;
2174 break;
2175 }
2176 ::GpiSetMix((HPS)hDC, lCRop);
2177 } // end of wxDC::SetRop
2178
2179 bool wxDC::StartDoc(
2180 const wxString& rsMessage
2181 )
2182 {
2183 // We might be previewing, so return true to let it continue.
2184 return true;
2185 } // end of wxDC::StartDoc
2186
2187 void wxDC::EndDoc()
2188 {
2189 } // end of wxDC::EndDoc
2190
2191 void wxDC::StartPage()
2192 {
2193 } // end of wxDC::StartPage
2194
2195 void wxDC::EndPage()
2196 {
2197 } // end of wxDC::EndPage
2198
2199 // ---------------------------------------------------------------------------
2200 // text metrics
2201 // ---------------------------------------------------------------------------
2202
2203 wxCoord wxDC::GetCharHeight() const
2204 {
2205 FONTMETRICS vFM; // metrics structure
2206
2207 ::GpiQueryFontMetrics( m_hPS
2208 ,sizeof(FONTMETRICS)
2209 ,&vFM
2210 );
2211 return YDEV2LOGREL(vFM.lXHeight);
2212 }
2213
2214 wxCoord wxDC::GetCharWidth() const
2215 {
2216 FONTMETRICS vFM; // metrics structure
2217
2218 ::GpiQueryFontMetrics( m_hPS
2219 ,sizeof(FONTMETRICS)
2220 ,&vFM
2221 );
2222 return XDEV2LOGREL(vFM.lAveCharWidth);
2223 }
2224
2225 void wxDC::DoGetTextExtent(
2226 const wxString& rsString
2227 , wxCoord* pvX
2228 , wxCoord* pvY
2229 , wxCoord* pvDescent
2230 , wxCoord* pvExternalLeading
2231 , wxFont* pTheFont
2232 ) const
2233 {
2234 POINTL avPoint[TXTBOX_COUNT];
2235 POINTL vPtMin;
2236 POINTL vPtMax;
2237 int i;
2238 int l;
2239 FONTMETRICS vFM; // metrics structure
2240 BOOL bRc;
2241 char* pStr;
2242 ERRORID vErrorCode; // last error id code
2243 wxFont* pFontToUse = (wxFont*)pTheFont;
2244
2245 char zMsg[128]; // DEBUG
2246 wxString sError;
2247
2248 if (!pFontToUse)
2249 pFontToUse = (wxFont*)&m_font;
2250 l = rsString.length();
2251 pStr = (PCH) rsString.c_str();
2252
2253 //
2254 // In world coordinates.
2255 //
2256 bRc = ::GpiQueryTextBox( m_hPS
2257 ,l
2258 ,pStr
2259 ,TXTBOX_COUNT // return maximum information
2260 ,avPoint // array of coordinates points
2261 );
2262 if(!bRc)
2263 {
2264 vErrorCode = ::WinGetLastError(wxGetInstance());
2265 sError = wxPMErrorToStr(vErrorCode);
2266 // DEBUG
2267 sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %lx - %s", pStr, vErrorCode, sError.c_str());
2268 (void)wxMessageBox( "wxWidgets Menu sample"
2269 ,zMsg
2270 ,wxICON_INFORMATION
2271 );
2272 }
2273
2274 vPtMin.x = avPoint[0].x;
2275 vPtMax.x = avPoint[0].x;
2276 vPtMin.y = avPoint[0].y;
2277 vPtMax.y = avPoint[0].y;
2278 for (i = 1; i < 4; i++)
2279 {
2280 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
2281 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
2282 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
2283 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
2284 }
2285 ::GpiQueryFontMetrics( m_hPS
2286 ,sizeof(FONTMETRICS)
2287 ,&vFM
2288 );
2289
2290 if (pvX)
2291 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
2292 if (pvY)
2293 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
2294 if (pvDescent)
2295 *pvDescent = vFM.lMaxDescender;
2296 if (pvExternalLeading)
2297 *pvExternalLeading = vFM.lExternalLeading;
2298 }
2299
2300 void wxDC::SetMapMode(
2301 int nMode
2302 )
2303 {
2304 int nPixelWidth = 0;
2305 int nPixelHeight = 0;
2306 int nMmWidth = 1;
2307 int nMmHeight = 1;
2308 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2309
2310 m_mappingMode = nMode;
2311
2312 if(::DevQueryCaps( m_hDC
2313 ,CAPS_FAMILY
2314 ,CAPS_VERTICAL_RESOLUTION
2315 ,lArray
2316 ))
2317 {
2318 LONG lHorzRes;
2319 LONG lVertRes;
2320
2321 nPixelWidth = lArray[CAPS_WIDTH];
2322 nPixelHeight = lArray[CAPS_HEIGHT];
2323 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2324 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2325 nMmWidth = (lHorzRes/1000) * nPixelWidth;
2326 nMmWidth = (lVertRes/1000) * nPixelHeight;
2327 }
2328 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
2329 {
2330 return;
2331 }
2332
2333 double dMm2pixelsX = nPixelWidth/nMmWidth;
2334 double dMm2pixelsY = nPixelHeight/nMmHeight;
2335
2336 switch (nMode)
2337 {
2338 case wxMM_TWIPS:
2339 m_logicalScaleX = (twips2mm * dMm2pixelsX);
2340 m_logicalScaleY = (twips2mm * dMm2pixelsY);
2341 break;
2342
2343 case wxMM_POINTS:
2344 m_logicalScaleX = (pt2mm * dMm2pixelsX);
2345 m_logicalScaleY = (pt2mm * dMm2pixelsY);
2346 break;
2347
2348 case wxMM_METRIC:
2349 m_logicalScaleX = dMm2pixelsX;
2350 m_logicalScaleY = dMm2pixelsY;
2351 break;
2352
2353 case wxMM_LOMETRIC:
2354 m_logicalScaleX = (dMm2pixelsX/10.0);
2355 m_logicalScaleY = (dMm2pixelsY/10.0);
2356 break;
2357
2358 case wxMM_TEXT:
2359 default:
2360 m_logicalScaleX = 1.0;
2361 m_logicalScaleY = 1.0;
2362 break;
2363 }
2364 SIZEL vSize;
2365 ULONG ulOptions;
2366
2367 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
2368 if (!ulOptions & PU_ARBITRARY)
2369 {
2370 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
2371 ::GpiSetPS(m_hPS, &vSize, ulOptions);
2372 }
2373 m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
2374 m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
2375 // ????
2376 }; // end of wxDC::SetMapMode
2377
2378 void wxDC::SetUserScale(
2379 double dX
2380 , double dY
2381 )
2382 {
2383 m_userScaleX = dX;
2384 m_userScaleY = dY;
2385
2386 SetMapMode(m_mappingMode);
2387 } // end of wxDC::SetUserScale
2388
2389 void wxDC::SetAxisOrientation(
2390 bool bXLeftRight
2391 , bool bYBottomUp
2392 )
2393 {
2394 m_signX = bXLeftRight ? 1 : -1;
2395 m_signY = bYBottomUp ? -1 : 1;
2396
2397 SetMapMode(m_mappingMode);
2398 } // end of wxDC::SetAxisOrientation
2399
2400 void wxDC::SetSystemScale(
2401 double dX
2402 , double dY
2403 )
2404 {
2405 m_scaleX = dX;
2406 m_scaleY = dY;
2407
2408 SetMapMode(m_mappingMode);
2409 } // end of wxDC::SetSystemScale
2410
2411 void wxDC::SetLogicalOrigin(
2412 wxCoord vX
2413 , wxCoord vY
2414 )
2415 {
2416 RECTL vRect;
2417
2418 ::GpiQueryPageViewport( m_hPS
2419 ,&vRect
2420 );
2421 vRect.xRight -= vX;
2422 vRect.yTop += vY;
2423 vRect.xLeft = vX;
2424 vRect.yBottom = vY;
2425 ::GpiSetPageViewport( m_hPS
2426 ,&vRect
2427 );
2428 }; // end of wxDC::SetLogicalOrigin
2429
2430 void wxDC::SetDeviceOrigin(
2431 wxCoord vX
2432 , wxCoord vY
2433 )
2434 {
2435 RECTL vRect;
2436
2437 m_deviceOriginX = vX;
2438 m_deviceOriginY = vY;
2439 ::GpiQueryPageViewport( m_hPS
2440 ,&vRect
2441 );
2442 vRect.xLeft += vX;
2443 vRect.xRight += vX;
2444 vRect.yBottom -= vY;
2445 vRect.yTop -= vY;
2446 ::GpiSetPageViewport( m_hPS
2447 ,&vRect
2448 );
2449 }; // end of wxDC::SetDeviceOrigin
2450
2451 // ---------------------------------------------------------------------------
2452 // coordinates transformations
2453 // ---------------------------------------------------------------------------
2454
2455 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
2456 {
2457 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
2458 }
2459
2460 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
2461 {
2462 // axis orientation is not taken into account for conversion of a distance
2463 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
2464 }
2465
2466 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
2467 {
2468 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
2469 }
2470
2471 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
2472 {
2473 // axis orientation is not taken into account for conversion of a distance
2474 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
2475 }
2476
2477 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
2478 {
2479 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
2480 }
2481
2482 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
2483 {
2484 // axis orientation is not taken into account for conversion of a distance
2485 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
2486 }
2487
2488 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
2489 {
2490 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
2491 }
2492
2493 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
2494 {
2495 // axis orientation is not taken into account for conversion of a distance
2496 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
2497 }
2498
2499 // ---------------------------------------------------------------------------
2500 // bit blit
2501 // ---------------------------------------------------------------------------
2502
2503 bool wxDC::DoBlit(
2504 wxCoord vXdest
2505 , wxCoord vYdest
2506 , wxCoord vWidth
2507 , wxCoord vHeight
2508 , wxDC* pSource
2509 , wxCoord vXsrc
2510 , wxCoord vYsrc
2511 , int nRop
2512 , bool bUseMask
2513 , wxCoord vXsrcMask
2514 , wxCoord vYsrcMask
2515 )
2516 {
2517 wxMask* pMask = NULL;
2518 CHARBUNDLE vCbnd;
2519 COLORREF vOldTextColor;
2520 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
2521
2522 if (bUseMask)
2523 {
2524 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
2525
2526 pMask = rBmp.GetMask();
2527 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
2528 {
2529 bUseMask = false;
2530 }
2531 }
2532
2533 ::GpiQueryAttrs( m_hPS
2534 ,PRIM_CHAR
2535 ,CBB_COLOR
2536 ,&vCbnd
2537 );
2538 vOldTextColor = (COLORREF)vCbnd.lColor;
2539
2540 if (m_textForegroundColour.Ok())
2541 {
2542 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
2543 ::GpiSetAttrs( m_hPS // presentation-space handle
2544 ,PRIM_CHAR // Char primitive.
2545 ,CBB_COLOR // sets color.
2546 ,0
2547 ,&vCbnd // buffer for attributes.
2548 );
2549 }
2550 if (m_textBackgroundColour.Ok())
2551 {
2552 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
2553 }
2554
2555 LONG lRop = ROP_SRCCOPY;
2556
2557 switch (nRop)
2558 {
2559 case wxXOR: lRop = ROP_SRCINVERT; break;
2560 case wxINVERT: lRop = ROP_DSTINVERT; break;
2561 case wxOR_REVERSE: lRop = 0x00DD0228; break;
2562 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
2563 case wxCLEAR: lRop = ROP_ZERO; break;
2564 case wxSET: lRop = ROP_ONE; break;
2565 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
2566 case wxAND: lRop = ROP_SRCAND; break;
2567 case wxOR: lRop = ROP_SRCPAINT; break;
2568 case wxEQUIV: lRop = 0x00990066; break;
2569 case wxNAND: lRop = 0x007700E6; break;
2570 case wxAND_INVERT: lRop = 0x00220326; break;
2571 case wxCOPY: lRop = ROP_SRCCOPY; break;
2572 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
2573 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
2574 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
2575 default:
2576 wxFAIL_MSG( wxT("unsupported logical function") );
2577 return false;
2578 }
2579
2580 bool bSuccess;
2581
2582 if (bUseMask)
2583 {
2584 //
2585 // Blit bitmap with mask
2586 //
2587
2588 //
2589 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2590 //
2591 HDC hDCMask;
2592 HDC hDCBuffer;
2593 HPS hPSMask;
2594 HPS hPSBuffer;
2595 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
2596 BITMAPINFOHEADER2 vBmpHdr;
2597 HBITMAP hBufBitmap;
2598 SIZEL vSize = {0, 0};
2599 LONG rc;
2600
2601 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
2602 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
2603 vBmpHdr.cx = vWidth;
2604 vBmpHdr.cy = vHeight;
2605 vBmpHdr.cPlanes = 1;
2606 vBmpHdr.cBitCount = 24;
2607
2608 #if wxUSE_DC_CACHEING
2609 if (true)
2610 {
2611 //
2612 // create a temp buffer bitmap and DCs to access it and the mask
2613 //
2614 wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
2615 ,pSource->GetHPS()
2616 );
2617 wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
2618 ,GetHPS()
2619 );
2620 wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
2621 ,vWidth
2622 ,vHeight
2623 );
2624
2625 hPSMask = pDCCacheEntry1->m_hPS;
2626 hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
2627 hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
2628 }
2629 else
2630 #endif
2631 {
2632 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2633 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2634 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2635 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2636 hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
2637 }
2638
2639 POINTL aPoint1[4] = { {0, 0}
2640 ,{vWidth, vHeight}
2641 ,{vXdest, vYdest}
2642 ,{vXdest + vWidth, vYdest + vHeight}
2643 };
2644 POINTL aPoint2[4] = { {0, 0}
2645 ,{vWidth, vHeight}
2646 ,{vXsrc, vYsrc}
2647 ,{vXsrc + vWidth, vYsrc + vHeight}
2648 };
2649 POINTL aPoint3[4] = { {vXdest, vYdest}
2650 ,{vXdest + vWidth, vYdest + vHeight}
2651 ,{vXsrc, vYsrc}
2652 ,{vXsrc + vWidth, vYsrc + vHeight}
2653 };
2654 POINTL aPoint4[4] = { {vXdest, vYdest}
2655 ,{vXdest + vWidth, vYdest + vHeight}
2656 ,{0, 0}
2657 ,{vWidth, vHeight}
2658 };
2659 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
2660 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
2661
2662 //
2663 // Copy dest to buffer
2664 //
2665 rc = ::GpiBitBlt( hPSBuffer
2666 ,GetHPS()
2667 ,4L
2668 ,aPoint1
2669 ,ROP_SRCCOPY
2670 ,BBO_IGNORE
2671 );
2672 if (rc == GPI_ERROR)
2673 {
2674 wxLogLastError(wxT("BitBlt"));
2675 }
2676
2677 //
2678 // Copy src to buffer using selected raster op
2679 //
2680 rc = ::GpiBitBlt( hPSBuffer
2681 ,GetHPS()
2682 ,4L
2683 ,aPoint2
2684 ,lRop
2685 ,BBO_IGNORE
2686 );
2687 if (rc == GPI_ERROR)
2688 {
2689 wxLogLastError(wxT("BitBlt"));
2690 }
2691
2692 //
2693 // Set masked area in buffer to BLACK (pixel value 0)
2694 //
2695 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
2696 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
2697
2698 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2699 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2700
2701 rc = ::GpiBitBlt( hPSBuffer
2702 ,hPSMask
2703 ,4L
2704 ,aPoint2
2705 ,ROP_SRCAND
2706 ,BBO_IGNORE
2707 );
2708 if (rc == GPI_ERROR)
2709 {
2710 wxLogLastError(wxT("BitBlt"));
2711 }
2712
2713 //
2714 // Set unmasked area in dest to BLACK
2715 //
2716 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2717 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2718 rc = ::GpiBitBlt( GetHPS()
2719 ,hPSMask
2720 ,4L
2721 ,aPoint3
2722 ,ROP_SRCAND
2723 ,BBO_IGNORE
2724 );
2725 if (rc == GPI_ERROR)
2726 {
2727 wxLogLastError(wxT("BitBlt"));
2728 }
2729
2730 //
2731 // Restore colours to original values
2732 //
2733 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
2734 ::GpiSetColor(GetHPS(), vPrevCol);
2735
2736 //
2737 // OR buffer to dest
2738 //
2739 rc = ::GpiBitBlt( GetHPS()
2740 ,hPSMask
2741 ,4L
2742 ,aPoint4
2743 ,ROP_SRCPAINT
2744 ,BBO_IGNORE
2745 );
2746 if (rc == GPI_ERROR)
2747 {
2748 bSuccess = false;
2749 wxLogLastError(wxT("BitBlt"));
2750 }
2751
2752 //
2753 // Tidy up temporary DCs and bitmap
2754 //
2755 ::GpiSetBitmap(hPSMask, NULLHANDLE);
2756 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
2757 #if !wxUSE_DC_CACHEING
2758 ::GpiDestroyPS(hPSMask);
2759 ::GpiDestroyPS(hPSBuffer);
2760 ::DevCloseDC(hDCMask);
2761 ::DevCloseDC(hDCBuffer);
2762 ::GpiDeleteBitmap(hBufBitmap);
2763 #endif
2764 bSuccess = true;
2765 }
2766 else // no mask, just BitBlt() it
2767 {
2768 POINTL aPoint[4] = { {vXdest, vYdest}
2769 ,{vXdest + vWidth, vYdest + vHeight}
2770 ,{vXsrc, vYsrc}
2771 ,{vXsrc + vWidth, vYsrc + vHeight}
2772 };
2773
2774 bSuccess = (::GpiBitBlt( m_hPS
2775 ,pSource->GetHPS()
2776 ,4L
2777 ,aPoint
2778 ,lRop
2779 ,BBO_IGNORE
2780 ) != GPI_ERROR);
2781 if (!bSuccess )
2782 {
2783 wxLogLastError(wxT("BitBlt"));
2784 }
2785 }
2786 vCbnd.lColor = (LONG)vOldTextColor;
2787 ::GpiSetAttrs( m_hPS // presentation-space handle
2788 ,PRIM_CHAR // Char primitive.
2789 ,CBB_COLOR // sets color.
2790 ,0
2791 ,&vCbnd // buffer for attributes.
2792 );
2793 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
2794 return bSuccess;
2795 }
2796
2797 void wxDC::DoGetSize(
2798 int* pnWidth
2799 , int* pnHeight
2800 ) const
2801 {
2802 LONG lArray[CAPS_HEIGHT];
2803
2804 if(::DevQueryCaps( m_hDC
2805 ,CAPS_FAMILY
2806 ,CAPS_HEIGHT
2807 ,lArray
2808 ))
2809 {
2810 *pnWidth = lArray[CAPS_WIDTH];
2811 *pnHeight = lArray[CAPS_HEIGHT];
2812 }
2813 }; // end of wxDC::DoGetSize(
2814
2815 void wxDC::DoGetSizeMM(
2816 int* pnWidth
2817 , int* pnHeight
2818 ) const
2819 {
2820 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2821
2822 if(::DevQueryCaps( m_hDC
2823 ,CAPS_FAMILY
2824 ,CAPS_VERTICAL_RESOLUTION
2825 ,lArray
2826 ))
2827 {
2828 int nWidth;
2829 int nHeight;
2830 int nHorzRes;
2831 int nVertRes;
2832
2833 nWidth = lArray[CAPS_WIDTH];
2834 nHeight = lArray[CAPS_HEIGHT];
2835 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2836 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2837 nWidth = (nHorzRes/1000) * nWidth;
2838 nHeight = (nVertRes/1000) * nHeight;
2839 }
2840 }; // end of wxDC::DoGetSizeMM
2841
2842 wxSize wxDC::GetPPI() const
2843 {
2844 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2845 int nWidth = 0;
2846 int nHeight = 0;
2847
2848 if(::DevQueryCaps( m_hDC
2849 ,CAPS_FAMILY
2850 ,CAPS_VERTICAL_RESOLUTION
2851 ,lArray
2852 ))
2853 {
2854 int nPelWidth;
2855 int nPelHeight;
2856 int nHorzRes;
2857 int nVertRes;
2858
2859 nPelWidth = lArray[CAPS_WIDTH];
2860 nPelHeight = lArray[CAPS_HEIGHT];
2861 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2862 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2863 nWidth = (int)((nHorzRes/39.3) * nPelWidth);
2864 nHeight = (int)((nVertRes/39.3) * nPelHeight);
2865 }
2866 return (wxSize(nWidth,nHeight));
2867 } // end of wxDC::GetPPI
2868
2869 void wxDC::SetLogicalScale(
2870 double dX
2871 , double dY
2872 )
2873 {
2874 m_logicalScaleX = dX;
2875 m_logicalScaleY = dY;
2876 }; // end of wxDC::SetLogicalScale
2877
2878
2879