wxOS2 with Open Watcom: correct PCH usage, missing headers, warning fixes, source...
[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 = (USHORT)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 = (USHORT)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 bSuccess;
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 = ::GpiQueryPel(m_hPS, &vPoint);
596
597 //
598 // return the color of the pixel
599 //
600 if(pCol)
601 pCol->Set( GetRValue(lColor)
602 ,GetGValue(lColor)
603 ,GetBValue(lColor)
604 );
605 return true;
606 } // end of wxDC::DoGetPixel
607
608 void wxDC::DoCrossHair(
609 wxCoord vX
610 , wxCoord vY
611 )
612 {
613 vY = OS2Y(vY,0);
614
615 wxCoord vX1 = vX - VIEWPORT_EXTENT;
616 wxCoord vY1 = vY - VIEWPORT_EXTENT;
617 wxCoord vX2 = vX + VIEWPORT_EXTENT;
618 wxCoord vY2 = vY + VIEWPORT_EXTENT;
619 POINTL vPoint[4];
620
621 vPoint[0].x = vX1;
622 vPoint[0].y = vY;
623
624 vPoint[1].x = vX2;
625 vPoint[1].y = vY;
626
627 ::GpiMove(m_hPS, &vPoint[0]);
628 ::GpiLine(m_hPS, &vPoint[1]);
629
630 vPoint[2].x = vX;
631 vPoint[2].y = vY1;
632
633 vPoint[3].x = vX;
634 vPoint[3].y = vY2;
635
636 ::GpiMove(m_hPS, &vPoint[2]);
637 ::GpiLine(m_hPS, &vPoint[3]);
638 CalcBoundingBox(vX1, vY1);
639 CalcBoundingBox(vX2, vY2);
640 } // end of wxDC::DoCrossHair
641
642 void wxDC::DoDrawLine(
643 wxCoord vX1
644 , wxCoord vY1
645 , wxCoord vX2
646 , wxCoord vY2
647 )
648 {
649 POINTL vPoint[2];
650 COLORREF vColor = 0x00ffffff;
651
652 //
653 // Might be a memory DC with no Paint rect.
654 //
655 if (!(m_vRclPaint.yTop == 0 &&
656 m_vRclPaint.yBottom == 0 &&
657 m_vRclPaint.xRight == 0 &&
658 m_vRclPaint.xLeft == 0))
659 {
660 vY1 = OS2Y(vY1,0);
661 vY2 = OS2Y(vY2,0);
662 }
663 else
664 {
665 if (m_vSelectedBitmap != wxNullBitmap)
666 {
667 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
668 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
669 vY1 = OS2Y(vY1,0);
670 vY2 = OS2Y(vY2,0);
671 }
672 }
673 vPoint[0].x = vX1;
674 vPoint[0].y = vY1;
675 vPoint[1].x = vX2;
676 vPoint[1].y = vY2;
677 if (m_pen.Ok())
678 {
679 vColor = m_pen.GetColour().GetPixel();
680 }
681 ::GpiSetColor(m_hPS, vColor);
682 ::GpiMove(m_hPS, &vPoint[0]);
683 ::GpiLine(m_hPS, &vPoint[1]);
684 CalcBoundingBox(vX1, vY1);
685 CalcBoundingBox(vX2, vY2);
686 } // end of wxDC::DoDrawLine
687
688 //////////////////////////////////////////////////////////////////////////////
689 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
690 // and ending at (x2, y2). The current pen is used for the outline and the
691 // current brush for filling the shape. The arc is drawn in an anticlockwise
692 // direction from the start point to the end point.
693 //////////////////////////////////////////////////////////////////////////////
694 void wxDC::DoDrawArc(
695 wxCoord vX1
696 , wxCoord vY1
697 , wxCoord vX2
698 , wxCoord vY2
699 , wxCoord vXc
700 , wxCoord vYc
701 )
702 {
703 POINTL vPtlPos;
704 POINTL vPtlArc[2]; // Structure for current position
705 double dRadius;
706 double dAngl1;
707 double dAngl2;
708 double dAnglmid;
709 wxCoord vXm;
710 wxCoord vYm;
711 ARCPARAMS vArcp; // Structure for arc parameters
712
713 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
714 return; // Draw point ??
715 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
716 ,(double)(vX1 - vXc)
717 ) +
718 hypot( (double)(vY2 - vYc)
719 ,(double)(vX2 - vXc)
720 )
721 );
722
723 dAngl1 = atan2( (double)(vY1 - vYc)
724 ,(double)(vX1 - vXc)
725 );
726 dAngl2 = atan2( (double)(vY2 - vYc)
727 ,(double)(vX2 - vXc)
728 );
729 if(dAngl2 < dAngl1)
730 dAngl2 += M_PI * 2;
731
732 //
733 // GpiPointArc can't draw full arc
734 //
735 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
736 {
737 //
738 // Medium point
739 //
740 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
741 vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
742 vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
743 DoDrawArc( vX1, vY1
744 ,vXm, vYm
745 ,vXc, vYc
746 );
747 DoDrawArc( vXm, vYm
748 ,vX2, vY2
749 ,vXc, vYc
750 );
751 return;
752 }
753
754 //
755 // Medium point
756 //
757 dAnglmid = (dAngl1 + dAngl2)/2.;
758 vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
759 vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
760
761 //
762 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
763 //
764 vArcp.lR = 0;
765 vArcp.lQ = 1;
766 vArcp.lP = 1;
767 vArcp.lS = 0;
768 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
769
770 vPtlPos.x = vX1; // Loads x-coordinate
771 vPtlPos.y = vY1; // Loads y-coordinate
772 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
773 vPtlArc[0].x = vXm;
774 vPtlArc[0].y = vYm;
775 vPtlArc[1].x = vX2;
776 vPtlArc[1].y = vY2;
777 #ifndef __WATCOMC__
778 // FIXME: incomplete headers ???
779 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
780 #endif
781 CalcBoundingBox( (wxCoord)(vXc - dRadius)
782 ,(wxCoord)(vYc - dRadius)
783 );
784 CalcBoundingBox( (wxCoord)(vXc + dRadius)
785 ,(wxCoord)(vYc + dRadius)
786 );
787 } // end of wxDC::DoDrawArc
788
789 void wxDC::DoDrawCheckMark(
790 wxCoord vX1
791 , wxCoord vY1
792 , wxCoord vWidth
793 , wxCoord vHeight
794 )
795 {
796 POINTL vPoint[2];
797
798 vY1 = OS2Y(vY1,vHeight);
799
800 vPoint[0].x = vX1;
801 vPoint[0].y = vY1;
802 vPoint[1].x = vX1 + vWidth;
803 vPoint[1].y = vY1 + vHeight;
804
805 ::GpiMove(m_hPS, &vPoint[0]);
806 ::GpiBox( m_hPS // handle to a presentation space
807 ,DRO_OUTLINE // draw the box outline ? or ?
808 ,&vPoint[1] // address of the corner
809 ,0L // horizontal corner radius
810 ,0L // vertical corner radius
811 );
812 if(vWidth > 4 && vHeight > 4)
813 {
814 int nTmp;
815
816 vPoint[0].x += 2; vPoint[0].y += 2;
817 vPoint[1].x -= 2; vPoint[1].y -= 2;
818 ::GpiMove(m_hPS, &vPoint[0]);
819 ::GpiLine(m_hPS, &vPoint[1]);
820 nTmp = vPoint[0].x;
821 vPoint[0].x = vPoint[1].x;
822 vPoint[1].x = nTmp;
823 ::GpiMove(m_hPS, &vPoint[0]);
824 ::GpiLine(m_hPS, &vPoint[1]);
825 }
826 CalcBoundingBox( vX1
827 ,vY1
828 );
829
830 wxCoord vX2 = vX1 + vWidth;
831 wxCoord vY2 = vY1 + vHeight;
832
833 CalcBoundingBox( vX2
834 ,vY2
835 );
836 } // end of wxDC::DoDrawCheckMark
837
838 void wxDC::DoDrawPoint(
839 wxCoord vX
840 , wxCoord vY
841 )
842 {
843 POINTL vPoint;
844 COLORREF vColor = 0x00ffffff;
845
846 if (m_pen.Ok())
847 {
848 vColor = m_pen.GetColour().GetPixel();
849 }
850 ::GpiSetColor(m_hPS, vColor);
851 vPoint.x = vX;
852 vPoint.y = OS2Y(vY,0);
853 ::GpiSetPel(m_hPS, &vPoint);
854 CalcBoundingBox( vX
855 ,vY
856 );
857 } // end of wxDC::DoDrawPoint
858
859 void wxDC::DoDrawPolygon(
860 int n
861 , wxPoint vPoints[]
862 , wxCoord vXoffset
863 , wxCoord vYoffset
864 , int nFillStyle
865 )
866 {
867 ULONG ulCount = 1; // Number of polygons.
868 POLYGON vPlgn; // polygon.
869 ULONG flOptions = 0L; // Drawing options.
870
871 //////////////////////////////////////////////////////////////////////////////
872 // This contains fields of option bits... to draw boundary lines as well as
873 // the area interior.
874 //
875 // Drawing boundary lines:
876 // POLYGON_NOBOUNDARY Does not draw boundary lines.
877 // POLYGON_BOUNDARY Draws boundary lines (the default).
878 //
879 // Construction of the area interior:
880 // POLYGON_ALTERNATE Constructs interior in alternate mode
881 // (the default).
882 // POLYGON_WINDING Constructs interior in winding mode.
883 //////////////////////////////////////////////////////////////////////////////
884
885 ULONG flModel = 0L; // Drawing model.
886
887 //////////////////////////////////////////////////////////////////////////////
888 // Drawing model.
889 // POLYGON_INCL Fill is inclusive of bottom right (the default).
890 // POLYGON_EXCL Fill is exclusive of bottom right.
891 // This is provided to aid migration from other graphics models.
892 //////////////////////////////////////////////////////////////////////////////
893
894 LONG lHits = 0L; // Correlation/error indicator.
895 POINTL vPoint;
896 int i;
897 int nIsTRANSPARENT = 0;
898 LONG lBorderColor = 0L;
899 LONG lColor = 0L;
900
901 lBorderColor = m_pen.GetColour().GetPixel();
902 lColor = m_brush.GetColour().GetPixel();
903 if(m_brush.GetStyle() == wxTRANSPARENT)
904 nIsTRANSPARENT = 1;
905
906 vPlgn.ulPoints = n;
907 vPlgn.aPointl = (POINTL*) calloc( n + 1
908 ,sizeof(POINTL)
909 ); // well, new will call malloc
910
911 for(i = 0; i < n; i++)
912 {
913 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
914 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
915 }
916 flModel = POLYGON_BOUNDARY;
917 if(nFillStyle == wxWINDING_RULE)
918 flModel |= POLYGON_WINDING;
919 else
920 flModel |= POLYGON_ALTERNATE;
921
922 vPoint.x = vXoffset;
923 vPoint.y = OS2Y(vYoffset,0);
924
925 ::GpiSetColor(m_hPS, lBorderColor);
926 ::GpiMove(m_hPS, &vPoint);
927 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
928 free(vPlgn.aPointl);
929 } // end of wxDC::DoDrawPolygon
930
931 void wxDC::DoDrawLines(
932 int n
933 , wxPoint vPoints[]
934 , wxCoord vXoffset
935 , wxCoord vYoffset
936 )
937 {
938 POINTL vPoint;
939
940 if (vXoffset != 0L || vXoffset != 0L)
941 {
942 int i;
943
944 vPoint.x = vPoints[0].x + vXoffset;
945 vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
946 ::GpiMove(m_hPS, &vPoint);
947
948 LONG lBorderColor = m_pen.GetColour().GetPixel();
949
950 ::GpiSetColor(m_hPS, lBorderColor);
951 for(i = 1; i < n; i++)
952 {
953 vPoint.x = vPoints[i].x + vXoffset;
954 vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
955 ::GpiLine(m_hPS, &vPoint);
956 }
957 }
958 else
959 {
960 int i;
961
962 CalcBoundingBox( vPoints[0].x
963 ,vPoints[0].y
964 );
965 vPoint.x = vPoints[0].x;
966 vPoint.y = OS2Y(vPoints[0].y,0);
967 ::GpiMove(m_hPS, &vPoint);
968
969 for (i = 0; i < n; i++)
970 {
971 CalcBoundingBox( vPoints[i].x
972 ,vPoints[i].y
973 );
974 vPoint.x = vPoints[i].x;
975 vPoint.y = OS2Y(vPoints[i].y,0);
976 ::GpiLine(m_hPS, &vPoint);
977 }
978 }
979 } // end of wxDC::DoDrawLines
980
981 void wxDC::DoDrawRectangle(
982 wxCoord vX
983 , wxCoord vY
984 , wxCoord vWidth
985 , wxCoord vHeight
986 )
987 {
988 POINTL vPoint[2];
989 LONG lControl;
990 LONG lColor;
991 LONG lBorderColor;
992 int nIsTRANSPARENT = 0;
993
994 //
995 // Might be a memory DC with no Paint rect.
996 //
997 if (!(m_vRclPaint.yTop == 0 &&
998 m_vRclPaint.yBottom == 0 &&
999 m_vRclPaint.xRight == 0 &&
1000 m_vRclPaint.xLeft == 0))
1001 vY = OS2Y(vY,vHeight);
1002 else
1003 {
1004 if (m_vSelectedBitmap != wxNullBitmap)
1005 {
1006 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1007 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1008 vY = OS2Y(vY,vHeight);
1009 }
1010 }
1011
1012 wxCoord vX2 = vX + vWidth;
1013 wxCoord vY2 = vY + vHeight;
1014
1015 vPoint[0].x = vX;
1016 vPoint[0].y = vY;
1017 vPoint[1].x = vX + vWidth - 1;
1018 vPoint[1].y = vY + vHeight - 1;
1019 ::GpiMove(m_hPS, &vPoint[0]);
1020 lColor = m_brush.GetColour().GetPixel();
1021 lBorderColor = m_pen.GetColour().GetPixel();
1022 if (m_brush.GetStyle() == wxTRANSPARENT)
1023 nIsTRANSPARENT = 1;
1024 if(lColor == lBorderColor || nIsTRANSPARENT)
1025 {
1026 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1027 if(m_brush.GetStyle() == wxTRANSPARENT)
1028 lControl = DRO_OUTLINE;
1029
1030 ::GpiSetColor(m_hPS, lBorderColor);
1031 ::GpiBox( m_hPS // handle to a presentation space
1032 ,lControl // draw the box outline ? or ?
1033 ,&vPoint[1] // address of the corner
1034 ,0L // horizontal corner radius
1035 ,0L // vertical corner radius
1036 );
1037 }
1038 else
1039 {
1040 lControl = DRO_OUTLINE;
1041 ::GpiSetColor( m_hPS
1042 ,lBorderColor
1043 );
1044 ::GpiBox( m_hPS
1045 ,lControl
1046 ,&vPoint[1]
1047 ,0L
1048 ,0L
1049 );
1050 lControl = DRO_FILL;
1051 ::GpiSetColor( m_hPS
1052 ,lColor
1053 );
1054 vPoint[0].x = vX + 1;
1055 vPoint[0].y = vY + 1;
1056 vPoint[1].x = vX + vWidth - 2;
1057 vPoint[1].y = vY + vHeight - 2;
1058 ::GpiMove(m_hPS, &vPoint[0]);
1059 ::GpiBox( m_hPS
1060 ,lControl
1061 ,&vPoint[1]
1062 ,0L
1063 ,0L
1064 );
1065 }
1066 CalcBoundingBox(vX, vY);
1067 CalcBoundingBox(vX2, vY2);
1068 } // end of wxDC::DoDrawRectangle
1069
1070 void wxDC::DoDrawRoundedRectangle(
1071 wxCoord vX
1072 , wxCoord vY
1073 , wxCoord vWidth
1074 , wxCoord vHeight
1075 , double dRadius
1076 )
1077 {
1078 POINTL vPoint[2];
1079 LONG lControl;
1080 LONG lColor;
1081 LONG lBorderColor;
1082 int nIsTRANSPARENT = 0;
1083
1084 //
1085 // Might be a memory DC with no Paint rect.
1086 //
1087 if (!(m_vRclPaint.yTop == 0 &&
1088 m_vRclPaint.yBottom == 0 &&
1089 m_vRclPaint.xRight == 0 &&
1090 m_vRclPaint.xLeft == 0))
1091 vY = OS2Y(vY,vHeight);
1092 else
1093 {
1094 if (m_vSelectedBitmap != wxNullBitmap)
1095 {
1096 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1097 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1098 vY = OS2Y(vY,vHeight);
1099 }
1100 }
1101
1102 wxCoord vX2 = (vX + vWidth);
1103 wxCoord vY2 = (vY + vHeight);
1104
1105 vPoint[0].x = vX;
1106 vPoint[0].y = vY;
1107 vPoint[1].x = vX + vWidth - 1;
1108 vPoint[1].y = vY + vHeight - 1;
1109 ::GpiMove(m_hPS, &vPoint[0]);
1110
1111 lColor = m_brush.GetColour().GetPixel();
1112 lBorderColor = m_pen.GetColour().GetPixel();
1113 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1114 if (m_brush.GetStyle() == wxTRANSPARENT)
1115 nIsTRANSPARENT = 1;
1116 if(lColor == lBorderColor || nIsTRANSPARENT)
1117 {
1118 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1119 if(m_brush.GetStyle() == wxTRANSPARENT)
1120 lControl = DRO_OUTLINE;
1121
1122 ::GpiSetColor(m_hPS, lColor);
1123 ::GpiBox( m_hPS // handle to a presentation space
1124 ,lControl // draw the box outline ? or ?
1125 ,&vPoint[1] // address of the corner
1126 ,(LONG)dRadius // horizontal corner radius
1127 ,(LONG)dRadius // vertical corner radius
1128 );
1129 }
1130 else
1131 {
1132 lControl = DRO_OUTLINE;
1133 ::GpiSetColor( m_hPS
1134 ,lBorderColor
1135 );
1136 ::GpiBox( m_hPS
1137 ,lControl
1138 ,&vPoint[1]
1139 ,(LONG)dRadius
1140 ,(LONG)dRadius
1141 );
1142 lControl = DRO_FILL;
1143 ::GpiSetColor( m_hPS
1144 ,lColor
1145 );
1146 vPoint[0].x = vX + 1;
1147 vPoint[0].y = vY + 1;
1148 vPoint[1].x = vX + vWidth - 2;
1149 vPoint[1].y = vY + vHeight - 2;
1150 ::GpiMove(m_hPS, &vPoint[0]);
1151 ::GpiBox( m_hPS
1152 ,lControl
1153 ,&vPoint[1]
1154 ,(LONG)dRadius
1155 ,(LONG)dRadius
1156 );
1157 }
1158
1159 CalcBoundingBox(vX, vY);
1160 CalcBoundingBox(vX2, vY2);
1161 } // end of wxDC::DoDrawRoundedRectangle
1162
1163 // Draw Ellipse within box (x,y) - (x+width, y+height)
1164 void wxDC::DoDrawEllipse(
1165 wxCoord vX
1166 , wxCoord vY
1167 , wxCoord vWidth
1168 , wxCoord vHeight
1169 )
1170 {
1171 POINTL vPtlPos; // Structure for current position
1172 FIXED vFxMult; // Multiplier for ellipse
1173 ARCPARAMS vArcp; // Structure for arc parameters
1174
1175 vY = OS2Y(vY,vHeight);
1176
1177 vArcp.lR = 0;
1178 vArcp.lQ = vHeight/2;
1179 vArcp.lP = vWidth/2;
1180 vArcp.lS = 0;
1181 ::GpiSetArcParams( m_hPS
1182 ,&vArcp
1183 ); // Sets parameters to default
1184 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
1185 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1186 ::GpiMove( m_hPS
1187 ,&vPtlPos
1188 ); // Sets current position
1189 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
1190
1191 //
1192 // DRO_FILL, DRO_OTLINEFILL - where to get
1193 //
1194 ::GpiFullArc( m_hPS
1195 ,DRO_OUTLINE
1196 ,vFxMult
1197 ); // Draws full arc with center at current position
1198
1199 wxCoord vX2 = (vX + vWidth);
1200 wxCoord vY2 = (vY + vHeight);
1201
1202 CalcBoundingBox(vX, vY);
1203 CalcBoundingBox(vX2, vY2);
1204 } // end of wxDC::DoDrawEllipse
1205
1206 void wxDC::DoDrawEllipticArc(
1207 wxCoord vX
1208 , wxCoord vY
1209 , wxCoord vWidth
1210 , wxCoord vHeight
1211 , double dSa
1212 , double dEa
1213 )
1214 {
1215 POINTL vPtlPos; // Structure for current position
1216 FIXED vFxMult; // Multiplier for ellipse
1217 ARCPARAMS vArcp; // Structure for arc parameters
1218 FIXED vFSa;
1219 FIXED vFSweepa; // Start angle, sweep angle
1220 double dIntPart;
1221 double dFractPart;
1222
1223 vY = OS2Y(vY,vHeight);
1224
1225 dFractPart = modf(dSa,&dIntPart);
1226 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1227 dFractPart = modf(dEa - dSa, &dIntPart);
1228 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1229
1230 //
1231 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1232 //
1233 vArcp.lR = 0;
1234 vArcp.lQ = vHeight/2;
1235 vArcp.lP = vWidth/2;
1236 vArcp.lS = 0;
1237 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
1238 vPtlPos.x = (wxCoord)(vX + vWidth/2 * (1. + cos(DegToRad(dSa)))); // Loads x-coordinate
1239 vPtlPos.y = (wxCoord)(vY + vHeight/2 * (1. + sin(DegToRad(dSa)))); // Loads y-coordinate
1240 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
1241
1242 //
1243 // May be not to the center ?
1244 //
1245 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
1246 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1247 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
1248
1249 //
1250 // DRO_FILL, DRO_OTLINEFILL - where to get
1251 //
1252 ::GpiPartialArc( m_hPS
1253 ,&vPtlPos
1254 ,vFxMult
1255 ,vFSa
1256 ,vFSweepa
1257 );
1258 wxCoord vX2 = (vX + vWidth);
1259 wxCoord vY2 = (vY + vHeight);
1260
1261 CalcBoundingBox(vX, vY);
1262 CalcBoundingBox(vX2, vY2);
1263 } // end of wxDC::DoDrawEllipticArc
1264
1265 void wxDC::DoDrawIcon(
1266 const wxIcon& rIcon
1267 , wxCoord vX
1268 , wxCoord vY
1269 )
1270 {
1271 //
1272 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1273 // and I don't feel like figuring those out for scrollable windows so
1274 // just convert to a bitmap then let the DoDrawBitmap routing display it
1275 //
1276 if (rIcon.IsXpm())
1277 {
1278 DoDrawBitmap(rIcon.GetXpmSrc(), vX, vY, true);
1279 }
1280 else
1281 {
1282 wxBitmap vBitmap(rIcon);
1283
1284 DoDrawBitmap(vBitmap, vX, vY, false);
1285 }
1286 CalcBoundingBox(vX, vY);
1287 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
1288 } // end of wxDC::DoDrawIcon
1289
1290 void wxDC::DoDrawBitmap(
1291 const wxBitmap& rBmp
1292 , wxCoord vX
1293 , wxCoord vY
1294 , bool bUseMask
1295 )
1296 {
1297 #if wxUSE_PRINTING_ARCHITECTURE
1298 if (!IsKindOf(CLASSINFO(wxPrinterDC)))
1299 #endif
1300 {
1301 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
1302 HBITMAP hBitmapOld = NULLHANDLE;
1303 POINTL vPoint[4];
1304
1305 vY = OS2Y(vY,rBmp.GetHeight());
1306
1307 vPoint[0].x = vX;
1308 vPoint[0].y = vY + rBmp.GetHeight();
1309 vPoint[1].x = vX + rBmp.GetWidth();
1310 vPoint[1].y = vY;
1311 vPoint[2].x = 0;
1312 vPoint[2].y = 0;
1313 vPoint[3].x = rBmp.GetWidth();
1314 vPoint[3].y = rBmp.GetHeight();
1315 if (bUseMask)
1316 {
1317 wxMask* pMask = rBmp.GetMask();
1318
1319 if (pMask)
1320 {
1321 //
1322 // Need to imitate ::MaskBlt in windows.
1323 // 1) Extract the bits from from the bitmap.
1324 // 2) Extract the bits from the mask
1325 // 3) Using the mask bits do the following:
1326 // A) If the mask byte is 00 leave the bitmap byte alone
1327 // B) If the mask byte is FF copy the screen color into
1328 // bitmap byte
1329 // 4) Create a new bitmap and set its bits to the above result
1330 // 5) Blit this to the screen PS
1331 //
1332 HBITMAP hMask = (HBITMAP)pMask->GetMaskBitmap();
1333 HBITMAP hOldMask = NULLHANDLE;
1334 HBITMAP hOldBitmap = NULLHANDLE;
1335 HBITMAP hNewBitmap = NULLHANDLE;
1336 unsigned char* pucBits; // buffer that will contain the bitmap data
1337 unsigned char* pucBitsMask; // buffer that will contain the mask data
1338 unsigned char* pucData; // pointer to use to traverse bitmap data
1339 unsigned char* pucDataMask; // pointer to use to traverse mask data
1340 LONG lHits;
1341 ERRORID vError;
1342 wxString sError;
1343
1344 //
1345 // The usual Memory context creation stuff
1346 //
1347 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1348 SIZEL vSize = {0, 0};
1349 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
1350 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
1351
1352 //
1353 // The usual bitmap header stuff
1354 //
1355 BITMAPINFOHEADER2 vHeader;
1356 BITMAPINFO2 vInfo;
1357
1358 memset(&vHeader, '\0', 16);
1359 vHeader.cbFix = 16;
1360
1361 memset(&vInfo, '\0', 16);
1362 vInfo.cbFix = 16;
1363 vInfo.cx = (ULONG)rBmp.GetWidth();
1364 vInfo.cy = (ULONG)rBmp.GetHeight();
1365 vInfo.cPlanes = 1;
1366 vInfo.cBitCount = 24; // Set to desired count going in
1367
1368 //
1369 // Create the buffers for data....all wxBitmaps are 24 bit internally
1370 //
1371 int nBytesPerLine = rBmp.GetWidth() * 3;
1372 int nSizeDWORD = sizeof(DWORD);
1373 int nLineBoundary = nBytesPerLine % nSizeDWORD;
1374 int nPadding = 0;
1375 int i;
1376 int j;
1377 LONG lScans = 0L;
1378 LONG lColor = 0L;
1379
1380 //
1381 // Need to get a background color for mask blitting
1382 //
1383 if (IsKindOf(CLASSINFO(wxWindowDC)))
1384 {
1385 wxWindowDC* pWindowDC = wxDynamicCast(this, wxWindowDC);
1386
1387 lColor = pWindowDC->m_pCanvas->GetBackgroundColour().GetPixel();
1388 }
1389 else if (GetBrush().Ok())
1390 lColor = GetBrush().GetColour().GetPixel();
1391 else
1392 lColor = m_textBackgroundColour.GetPixel();
1393
1394 //
1395 // Bitmap must be in a double-word aligned address so we may
1396 // have some padding to worry about
1397 //
1398 if (nLineBoundary > 0)
1399 {
1400 nPadding = nSizeDWORD - nLineBoundary;
1401 nBytesPerLine += nPadding;
1402 }
1403 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
1404 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
1405 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
1406 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
1407
1408 //
1409 // Extract the bitmap and mask data
1410 //
1411 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
1412 {
1413 vError = ::WinGetLastError(vHabmain);
1414 sError = wxPMErrorToStr(vError);
1415 }
1416 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
1417 vInfo.cBitCount = 24;
1418 if ((lScans = ::GpiQueryBitmapBits( hPS
1419 ,0L
1420 ,(LONG)rBmp.GetHeight()
1421 ,(PBYTE)pucBits
1422 ,&vInfo
1423 )) == GPI_ALTERROR)
1424 {
1425 vError = ::WinGetLastError(vHabmain);
1426 sError = wxPMErrorToStr(vError);
1427 }
1428 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
1429 {
1430 vError = ::WinGetLastError(vHabmain);
1431 sError = wxPMErrorToStr(vError);
1432 }
1433 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
1434 vInfo.cBitCount = 24;
1435 if ((lScans = ::GpiQueryBitmapBits( hPS
1436 ,0L
1437 ,(LONG)rBmp.GetHeight()
1438 ,(PBYTE)pucBitsMask
1439 ,&vInfo
1440 )) == GPI_ALTERROR)
1441 {
1442 vError = ::WinGetLastError(vHabmain);
1443 sError = wxPMErrorToStr(vError);
1444 }
1445 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
1446 {
1447 vError = ::WinGetLastError(vHabmain);
1448 sError = wxPMErrorToStr(vError);
1449 }
1450
1451 //
1452 // Now set the bytes(bits) according to the mask values
1453 // 3 bytes per pel...must handle one at a time
1454 //
1455 pucData = pucBits;
1456 pucDataMask = pucBitsMask;
1457
1458 //
1459 // 16 bit kludge really only kinda works. The mask gets applied
1460 // where needed but the original bitmap bits are dorked sometimes
1461 //
1462 bool bpp16 = (wxDisplayDepth() == 16);
1463
1464 for (i = 0; i < rBmp.GetHeight(); i++)
1465 {
1466 for (j = 0; j < rBmp.GetWidth(); j++)
1467 {
1468 // Byte 1
1469 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
1470 pucData++;
1471 else if (*pucDataMask == 0xFF) // leave bitmap byte alone
1472 pucData++;
1473 else
1474 {
1475 *pucData = ((unsigned char)(lColor >> 16));
1476 pucData++;
1477 }
1478 // Byte 2
1479 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
1480 pucData++;
1481 else if (*(pucDataMask + 1) == 0xFF) // leave bitmap byte alone
1482 pucData++;
1483 else
1484 {
1485 *pucData = ((unsigned char)(lColor >> 8));
1486 pucData++;
1487 }
1488
1489 // Byte 3
1490 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
1491 pucData++;
1492 else if (*(pucDataMask + 2) == 0xFF) // leave bitmap byte alone
1493 pucData++;
1494 else
1495 {
1496 *pucData = ((unsigned char)lColor);
1497 pucData++;
1498 }
1499 pucDataMask += 3;
1500 }
1501 for (j = 0; j < nPadding; j++)
1502 {
1503 pucData++;
1504 pucDataMask++;
1505 }
1506 }
1507 //
1508 // Create a new bitmap
1509 //
1510 vHeader.cx = (ULONG)rBmp.GetWidth();
1511 vHeader.cy = (ULONG)rBmp.GetHeight();
1512 vHeader.cPlanes = 1L;
1513 vHeader.cBitCount = 24;
1514 if ((hNewBitmap = ::GpiCreateBitmap( hPS
1515 ,&vHeader
1516 ,CBM_INIT
1517 ,(PBYTE)pucBits
1518 ,&vInfo
1519 )) == GPI_ERROR)
1520 {
1521 vError = ::WinGetLastError(vHabmain);
1522 sError = wxPMErrorToStr(vError);
1523 }
1524
1525 //
1526 // Now blit it to the screen PS
1527 //
1528 if ((lHits = ::GpiWCBitBlt( (HPS)GetHPS()
1529 ,hNewBitmap
1530 ,4
1531 ,vPoint
1532 ,ROP_SRCCOPY
1533 ,BBO_IGNORE
1534 )) == GPI_ERROR)
1535 {
1536 vError = ::WinGetLastError(vHabmain);
1537 sError = wxPMErrorToStr(vError);
1538 }
1539
1540 //
1541 // Clean up
1542 //
1543 free(pucBits);
1544 free(pucBitsMask);
1545 ::GpiSetBitmap(hPS, NULLHANDLE);
1546 ::GpiDeleteBitmap(hNewBitmap);
1547 ::GpiDestroyPS(hPS);
1548 ::DevCloseDC(hDC);
1549 }
1550 }
1551 else
1552 {
1553 ULONG lOldForeGround = ::GpiQueryColor((HPS)GetHPS());
1554 ULONG lOldBackGround = ::GpiQueryBackColor((HPS)GetHPS());
1555
1556 if (m_textForegroundColour.Ok())
1557 {
1558 ::GpiSetColor( (HPS)GetHPS()
1559 ,m_textForegroundColour.GetPixel()
1560 );
1561 }
1562 if (m_textBackgroundColour.Ok())
1563 {
1564 ::GpiSetBackColor( (HPS)GetHPS()
1565 ,m_textBackgroundColour.GetPixel()
1566 );
1567 }
1568 //
1569 // Need to alter bits in a mono bitmap to match the new
1570 // background-foreground if it is different.
1571 //
1572 if (rBmp.IsMono() &&
1573 ((m_textForegroundColour.GetPixel() != lOldForeGround) ||
1574 (m_textBackgroundColour.GetPixel() != lOldBackGround)))
1575 {
1576 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1577 SIZEL vSize = {0, 0};
1578 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
1579 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
1580
1581 int nBytesPerLine = rBmp.GetWidth() * 3;
1582 int i, j;
1583 LONG lForeGround = m_textForegroundColour.GetPixel();
1584 LONG lBackGround = m_textBackgroundColour.GetPixel();
1585 LONG lScans;
1586 HBITMAP hOldBitmap = NULLHANDLE;
1587 BITMAPINFO2 vInfo;
1588 ERRORID vError;
1589 wxString sError;
1590
1591
1592 memset(&vInfo, '\0', 16);
1593 vInfo.cbFix = 16;
1594 vInfo.cx = (ULONG)rBmp.GetWidth();
1595 vInfo.cy = (ULONG)rBmp.GetHeight();
1596 vInfo.cPlanes = 1;
1597 vInfo.cBitCount = 24;
1598
1599 unsigned char* pucBits; // buffer that will contain the bitmap data
1600 unsigned char* pucData; // pointer to use to traverse bitmap data
1601
1602 pucBits = new unsigned char[nBytesPerLine * rBmp.GetHeight()];
1603 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
1604
1605 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
1606 {
1607 vError = ::WinGetLastError(vHabmain);
1608 sError = wxPMErrorToStr(vError);
1609 return;
1610 }
1611 if ((lScans = ::GpiQueryBitmapBits( hPS
1612 ,0L
1613 ,(LONG)rBmp.GetHeight()
1614 ,(PBYTE)pucBits
1615 ,&vInfo
1616 )) == GPI_ALTERROR)
1617 {
1618 vError = ::WinGetLastError(vHabmain);
1619 sError = wxPMErrorToStr(vError);
1620 return;
1621 }
1622 unsigned char cOldRedFore = (unsigned char)(lOldForeGround >> 16);
1623 unsigned char cOldGreenFore = (unsigned char)(lOldForeGround >> 8);
1624 unsigned char cOldBlueFore = (unsigned char)lOldForeGround;
1625
1626 unsigned char cRedFore = (unsigned char)(lForeGround >> 16);
1627 unsigned char cGreenFore = (unsigned char)(lForeGround >> 8);
1628 unsigned char cBlueFore = (unsigned char)lForeGround;
1629
1630 unsigned char cRedBack = (unsigned char)(lBackGround >> 16);
1631 unsigned char cGreenBack = (unsigned char)(lBackGround >> 8);
1632 unsigned char cBlueBack = (unsigned char)lBackGround;
1633
1634 pucData = pucBits;
1635 for (i = 0; i < rBmp.GetHeight(); i++)
1636 {
1637 for (j = 0; j < rBmp.GetWidth(); j++)
1638 {
1639 unsigned char cBmpRed = *pucData;
1640 unsigned char cBmpGreen = *(pucData + 1);
1641 unsigned char cBmpBlue = *(pucData + 2);
1642
1643 if ((cBmpRed == cOldRedFore) &&
1644 (cBmpGreen == cOldGreenFore) &&
1645 (cBmpBlue == cOldBlueFore))
1646 {
1647 *pucData = cBlueFore;
1648 pucData++;
1649 *pucData = cGreenFore;
1650 pucData++;
1651 *pucData = cRedFore;
1652 pucData++;
1653 }
1654 else
1655 {
1656 *pucData = cBlueBack;
1657 pucData++;
1658 *pucData = cGreenBack;
1659 pucData++;
1660 *pucData = cRedBack;
1661 pucData++;
1662 }
1663 }
1664 }
1665 if ((lScans = ::GpiSetBitmapBits( hPS
1666 ,0L
1667 ,(LONG)rBmp.GetHeight()
1668 ,(PBYTE)pucBits
1669 ,&vInfo
1670 )) == GPI_ALTERROR)
1671 {
1672 vError = ::WinGetLastError(vHabmain);
1673 sError = wxPMErrorToStr(vError);
1674 return;
1675 }
1676 delete [] pucBits;
1677 ::GpiSetBitmap(hPS, NULLHANDLE);
1678 ::GpiDestroyPS(hPS);
1679 ::DevCloseDC(hDC);
1680 }
1681 ::GpiWCBitBlt( (HPS)GetHPS()
1682 ,hBitmap
1683 ,4
1684 ,vPoint
1685 ,ROP_SRCCOPY
1686 ,BBO_IGNORE
1687 );
1688 ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld);
1689 ::GpiSetColor((HPS)GetHPS(), lOldForeGround);
1690 ::GpiSetBackColor((HPS)GetHPS(), lOldBackGround);
1691 }
1692 }
1693 } // end of wxDC::DoDrawBitmap
1694
1695 void wxDC::DoDrawText(
1696 const wxString& rsText
1697 , wxCoord vX
1698 , wxCoord vY
1699 )
1700 {
1701 wxCoord vWidth;
1702 wxCoord vHeight;
1703
1704 DrawAnyText( rsText
1705 ,vX
1706 ,vY
1707 );
1708
1709 CalcBoundingBox(vX, vY);
1710 GetTextExtent(rsText, &vWidth, &vHeight);
1711 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1712 } // end of wxDC::DoDrawText
1713
1714 void wxDC::DrawAnyText(
1715 const wxString& rsText
1716 , wxCoord vX
1717 , wxCoord vY
1718 )
1719 {
1720 int nOldBackground = 0;
1721 POINTL vPtlStart;
1722 LONG lHits;
1723 wxCoord vTextX = 0;
1724 wxCoord vTextY = 0;
1725
1726 //
1727 // prepare for drawing the text
1728 //
1729
1730 //
1731 // Set text color attributes
1732 //
1733 if (m_textForegroundColour.Ok())
1734 {
1735 SetTextColor( m_hPS
1736 ,(int)m_textForegroundColour.GetPixel()
1737 );
1738 }
1739
1740 if (m_textBackgroundColour.Ok())
1741 {
1742 nOldBackground = SetTextBkColor( m_hPS
1743 ,(int)m_textBackgroundColour.GetPixel()
1744 );
1745 }
1746 SetBkMode( m_hPS
1747 ,m_backgroundMode
1748 );
1749 GetTextExtent( rsText
1750 ,&vTextX
1751 ,&vTextY
1752 );
1753 vPtlStart.x = vX;
1754 if (!(m_vRclPaint.yTop == 0 &&
1755 m_vRclPaint.yBottom == 0 &&
1756 m_vRclPaint.xRight == 0 &&
1757 m_vRclPaint.xLeft == 0))
1758 {
1759 //
1760 // Position Text a little differently in the Statusbar from other panels
1761 //
1762 if (m_pCanvas && m_pCanvas->IsKindOf(CLASSINFO(wxStatusBar)))
1763 vPtlStart.y = OS2Y(vY,vTextY);
1764 else
1765 vPtlStart.y = (wxCoord)(OS2Y(vY,vTextY/1.5)); // Full extent is a bit much
1766 }
1767 else
1768 {
1769 if (m_vSelectedBitmap != wxNullBitmap)
1770 {
1771 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1772 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1773 if (m_pCanvas && m_pCanvas->IsKindOf(CLASSINFO(wxStatusBar)))
1774 vPtlStart.y = OS2Y(vY,vTextY);
1775 else
1776 vPtlStart.y = (LONG)(OS2Y(vY,vTextY/1.5));
1777 }
1778 else
1779 vPtlStart.y = vY;
1780 }
1781
1782 PCH pzStr = (PCH)rsText.c_str();
1783
1784 ::GpiMove(m_hPS, &vPtlStart);
1785 lHits = ::GpiCharString( m_hPS
1786 ,rsText.length()
1787 ,pzStr
1788 );
1789 if (lHits != GPI_OK)
1790 {
1791 wxLogLastError(wxT("TextOut"));
1792 }
1793
1794 //
1795 // Restore the old parameters (text foreground colour may be left because
1796 // it never is set to anything else, but background should remain
1797 // transparent even if we just drew an opaque string)
1798 //
1799 if (m_textBackgroundColour.Ok())
1800 SetTextBkColor( m_hPS
1801 ,nOldBackground
1802 );
1803 SetBkMode( m_hPS
1804 ,wxTRANSPARENT
1805 );
1806 }
1807
1808 void wxDC::DoDrawRotatedText(
1809 const wxString& rsText
1810 , wxCoord vX
1811 , wxCoord vY
1812 , double dAngle
1813 )
1814 {
1815 if (dAngle == 0.0)
1816 {
1817 DoDrawText( rsText
1818 ,vX
1819 ,vY
1820 );
1821 }
1822
1823 // TODO:
1824 /*
1825 if ( angle == 0.0 )
1826 {
1827 DoDrawText(text, x, y);
1828 }
1829 else
1830 {
1831 LOGFONT lf;
1832 wxFillLogFont(&lf, &m_font);
1833
1834 // GDI wants the angle in tenth of degree
1835 long angle10 = (long)(angle * 10);
1836 lf.lfEscapement = angle10;
1837 lf. lfOrientation = angle10;
1838
1839 HFONT hfont = ::CreateFontIndirect(&lf);
1840 if ( !hfont )
1841 {
1842 wxLogLastError("CreateFont");
1843 }
1844 else
1845 {
1846 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1847
1848 DrawAnyText(text, x, y);
1849
1850 (void)::SelectObject(GetHdc(), hfontOld);
1851 }
1852
1853 // call the bounding box by adding all four vertices of the rectangle
1854 // containing the text to it (simpler and probably not slower than
1855 // determining which of them is really topmost/leftmost/...)
1856 wxCoord w, h;
1857 GetTextExtent(text, &w, &h);
1858
1859 double rad = DegToRad(angle);
1860
1861 // "upper left" and "upper right"
1862 CalcBoundingBox(x, y);
1863 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1864 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1865
1866 // "bottom left" and "bottom right"
1867 x += (wxCoord)(h*sin(rad));
1868 y += (wxCoord)(h*cos(rad));
1869 CalcBoundingBox(x, y);
1870 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1871 }
1872 */
1873 }
1874
1875 // ---------------------------------------------------------------------------
1876 // set GDI objects
1877 // ---------------------------------------------------------------------------
1878
1879 void wxDC::DoSelectPalette( bool WXUNUSED(bRealize) )
1880 {
1881 //
1882 // Set the old object temporarily, in case the assignment deletes an object
1883 // that's not yet selected out.
1884 //
1885 if (m_hOldPalette)
1886 {
1887 m_hOldPalette = 0;
1888 }
1889
1890 if (m_palette.Ok())
1891 {
1892 HPALETTE hOldPal;
1893
1894 hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1895 if (!m_hOldPalette)
1896 m_hOldPalette = (WXHPALETTE)hOldPal;
1897 }
1898 } // end of wxDC::DoSelectPalette
1899
1900 void wxDC::InitializePalette()
1901 {
1902 if (wxDisplayDepth() <= 8 )
1903 {
1904 //
1905 // Look for any window or parent that has a custom palette. If any has
1906 // one then we need to use it in drawing operations
1907 //
1908 wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette();
1909
1910 m_hasCustomPalette = pWin && pWin->HasCustomPalette();
1911 if (m_hasCustomPalette)
1912 {
1913 m_palette = pWin->GetPalette();
1914
1915 //
1916 // turn on PM translation for this palette
1917 //
1918 DoSelectPalette();
1919 }
1920 }
1921 } // end of wxDC::InitializePalette
1922
1923 void wxDC::SetPalette(
1924 const wxPalette& rPalette
1925 )
1926 {
1927 if (m_hOldFont)
1928 {
1929 m_hOldFont = 0;
1930 }
1931 m_palette = rPalette;
1932 if (!rPalette.Ok())
1933 {
1934 if (m_hOldFont)
1935 {
1936 m_hOldFont = 0;
1937 }
1938 }
1939 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1940 if (!m_hOldPalette)
1941 m_hOldPalette = (WXHPALETTE)hOldPal;
1942 } // end of wxDC::SetPalette
1943
1944 void wxDC::SetFont(
1945 const wxFont& rFont
1946 )
1947 {
1948 //
1949 // Set the old object temporarily, in case the assignment deletes an object
1950 // that's not yet selected out.
1951 //
1952 if (m_hOldFont)
1953 {
1954 m_hOldFont = 0;
1955 }
1956 m_font = rFont;
1957 if (!rFont.Ok())
1958 {
1959 m_hOldFont = 0;
1960 }
1961
1962 m_font.SetPS(m_hPS); // this will realize the font
1963
1964 if (m_font.Ok())
1965 {
1966 HFONT hFont = m_font.GetResourceHandle();
1967 if (hFont == (HFONT) NULL)
1968 {
1969 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1970 }
1971 if (!m_hOldFont)
1972 m_hOldFont = (WXHFONT) hFont;
1973 }
1974 } // end of wxDC::SetFont
1975
1976 void wxDC::SetPen(
1977 const wxPen& rPen
1978 )
1979 {
1980 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1981
1982 if (m_pen == rPen)
1983 return;
1984 m_pen = rPen;
1985 if (!m_pen.Ok())
1986 return;
1987
1988 if (m_hOldPen)
1989 m_hOldPen = 0L;
1990 m_pen = rPen;
1991
1992 if (!m_pen.Ok())
1993 {
1994 if (m_hOldPen)
1995 {
1996 m_pen.SetPS((HPS)m_hOldPen);
1997 }
1998 m_hOldPen = 0L;
1999 }
2000
2001 if (m_pen.Ok())
2002 {
2003 if (m_pen.GetResourceHandle())
2004 {
2005 m_pen.SetPS(m_hPS);
2006 if (!m_hOldPen)
2007 m_hOldPen = m_pen.GetPS();
2008 }
2009 ::GpiSetColor(m_hPS, m_pen.GetColour().GetPixel());
2010 }
2011 }
2012
2013 void wxDC::SetBrush(
2014 const wxBrush& rBrush
2015 )
2016 {
2017 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2018
2019 if (m_hOldBrush)
2020 m_hOldBrush = 0L;
2021 m_brush = rBrush;
2022 if (!m_brush.Ok())
2023 if (m_brush == rBrush)
2024 return;
2025 if (!m_brush.Ok())
2026 if (m_hOldBrush)
2027 m_hOldBrush = 0L;
2028
2029 if (!m_brush.Ok())
2030 {
2031 if (m_hOldBrush)
2032 {
2033 m_brush.SetPS((HPS)m_hOldBrush);
2034 }
2035 m_hOldBrush = 0L;
2036 }
2037
2038 if (m_brush.Ok())
2039 {
2040 if (m_brush.GetResourceHandle())
2041 {
2042 m_brush.SetPS(m_hPS);
2043 if (!m_hOldBrush)
2044 m_hOldBrush = (WXHWND)m_brush.GetPS();
2045 }
2046 }
2047 } // end of wxDC::SetBrush
2048
2049 void wxDC::SetBackground(
2050 const wxBrush& rBrush
2051 )
2052 {
2053 m_backgroundBrush = rBrush;
2054 if (!m_backgroundBrush.Ok())
2055 return;
2056 if (m_pCanvas)
2057 {
2058 bool bCustomColours = true;
2059
2060 //
2061 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
2062 // change background colours from the control-panel specified colours.
2063 //
2064 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
2065 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
2066 bCustomColours = false;
2067 if (bCustomColours)
2068 {
2069 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
2070 {
2071 m_pCanvas->SetTransparent(true);
2072 }
2073 else
2074 {
2075 //
2076 // Setting the background brush of a DC
2077 // doesn't affect the window background colour. However,
2078 // I'm leaving in the transparency setting because it's needed by
2079 // various controls (e.g. wxStaticText) to determine whether to draw
2080 // transparently or not. TODO: maybe this should be a new function
2081 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
2082 // parent?
2083 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
2084 //
2085 m_pCanvas->SetTransparent(false);
2086 }
2087 }
2088 }
2089 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
2090 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
2091 } // end of wxDC::SetBackground
2092
2093 void wxDC::SetBackgroundMode(
2094 int nMode
2095 )
2096 {
2097 m_backgroundMode = nMode;
2098 } // end of wxDC::SetBackgroundMode
2099
2100 void wxDC::SetLogicalFunction(
2101 int nFunction
2102 )
2103 {
2104 m_logicalFunction = nFunction;
2105 SetRop((WXHDC)m_hDC);
2106 } // wxDC::SetLogicalFunction
2107
2108 void wxDC::SetRop(
2109 WXHDC hDC
2110 )
2111 {
2112 if (!hDC || m_logicalFunction < 0)
2113 return;
2114
2115 LONG lCRop;
2116 switch (m_logicalFunction)
2117 {
2118 case wxXOR:
2119 lCRop = FM_XOR;
2120 break;
2121
2122 case wxINVERT:
2123 lCRop = FM_INVERT;
2124 break;
2125
2126 case wxOR_REVERSE:
2127 lCRop = FM_MERGESRCNOT;
2128 break;
2129
2130 case wxAND_REVERSE:
2131 lCRop = FM_NOTMASKSRC;
2132 break;
2133
2134 case wxCLEAR:
2135 lCRop = FM_ONE;
2136 break;
2137
2138 case wxSET:
2139 lCRop = FM_ZERO;
2140 break;
2141
2142 case wxSRC_INVERT:
2143 lCRop = FM_MERGENOTSRC;
2144 break;
2145
2146 case wxOR_INVERT:
2147 lCRop = FM_MERGESRCNOT;
2148 break;
2149
2150 case wxAND:
2151 lCRop = FM_AND;
2152 break;
2153
2154 case wxOR:
2155 lCRop = FM_OR;
2156 break;
2157
2158 case wxAND_INVERT:
2159 lCRop = FM_SUBTRACT;
2160 break;
2161
2162 case wxEQUIV:
2163 case wxNAND:
2164 case wxCOPY:
2165 default:
2166 lCRop = FM_OVERPAINT;
2167 break;
2168 }
2169 ::GpiSetMix((HPS)hDC, lCRop);
2170 } // end of wxDC::SetRop
2171
2172 bool wxDC::StartDoc( const wxString& WXUNUSED(rsMessage) )
2173 {
2174 // We might be previewing, so return true to let it continue.
2175 return true;
2176 } // end of wxDC::StartDoc
2177
2178 void wxDC::EndDoc()
2179 {
2180 } // end of wxDC::EndDoc
2181
2182 void wxDC::StartPage()
2183 {
2184 } // end of wxDC::StartPage
2185
2186 void wxDC::EndPage()
2187 {
2188 } // end of wxDC::EndPage
2189
2190 // ---------------------------------------------------------------------------
2191 // text metrics
2192 // ---------------------------------------------------------------------------
2193
2194 wxCoord wxDC::GetCharHeight() const
2195 {
2196 FONTMETRICS vFM; // metrics structure
2197
2198 ::GpiQueryFontMetrics( m_hPS
2199 ,sizeof(FONTMETRICS)
2200 ,&vFM
2201 );
2202 return YDEV2LOGREL(vFM.lXHeight);
2203 }
2204
2205 wxCoord wxDC::GetCharWidth() const
2206 {
2207 FONTMETRICS vFM; // metrics structure
2208
2209 ::GpiQueryFontMetrics( m_hPS
2210 ,sizeof(FONTMETRICS)
2211 ,&vFM
2212 );
2213 return XDEV2LOGREL(vFM.lAveCharWidth);
2214 }
2215
2216 void wxDC::DoGetTextExtent(
2217 const wxString& rsString
2218 , wxCoord* pvX
2219 , wxCoord* pvY
2220 , wxCoord* pvDescent
2221 , wxCoord* pvExternalLeading
2222 , wxFont* pTheFont
2223 ) const
2224 {
2225 POINTL avPoint[TXTBOX_COUNT];
2226 POINTL vPtMin;
2227 POINTL vPtMax;
2228 int i;
2229 int l;
2230 FONTMETRICS vFM; // metrics structure
2231 BOOL bRc;
2232 ERRORID vErrorCode; // last error id code
2233 wxFont* pFontToUse = (wxFont*)pTheFont;
2234
2235 wxChar zMsg[128]; // DEBUG
2236 wxString sError;
2237
2238 if (!pFontToUse)
2239 pFontToUse = (wxFont*)&m_font;
2240 l = rsString.length();
2241
2242 //
2243 // In world coordinates.
2244 //
2245 bRc = ::GpiQueryTextBox( m_hPS
2246 ,l
2247 ,(PCH)rsString.c_str()
2248 ,TXTBOX_COUNT // return maximum information
2249 ,avPoint // array of coordinates points
2250 );
2251 if(!bRc)
2252 {
2253 vErrorCode = ::WinGetLastError(wxGetInstance());
2254 sError = wxPMErrorToStr(vErrorCode);
2255 // DEBUG
2256 wxSprintf(zMsg, _T("GpiQueryTextBox for %s: failed with Error: %lx - %s"), rsString.c_str(), vErrorCode, sError.c_str());
2257 (void)wxMessageBox( _T("wxWidgets Menu sample")
2258 ,zMsg
2259 ,wxICON_INFORMATION
2260 );
2261 }
2262
2263 vPtMin.x = avPoint[0].x;
2264 vPtMax.x = avPoint[0].x;
2265 vPtMin.y = avPoint[0].y;
2266 vPtMax.y = avPoint[0].y;
2267 for (i = 1; i < 4; i++)
2268 {
2269 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
2270 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
2271 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
2272 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
2273 }
2274 ::GpiQueryFontMetrics( m_hPS
2275 ,sizeof(FONTMETRICS)
2276 ,&vFM
2277 );
2278
2279 if (pvX)
2280 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
2281 if (pvY)
2282 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
2283 if (pvDescent)
2284 *pvDescent = vFM.lMaxDescender;
2285 if (pvExternalLeading)
2286 *pvExternalLeading = vFM.lExternalLeading;
2287 }
2288
2289 void wxDC::SetMapMode(
2290 int nMode
2291 )
2292 {
2293 int nPixelWidth = 0;
2294 int nPixelHeight = 0;
2295 int nMmWidth = 1;
2296 int nMmHeight = 1;
2297 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2298
2299 m_mappingMode = nMode;
2300
2301 if(::DevQueryCaps( m_hDC
2302 ,CAPS_FAMILY
2303 ,CAPS_VERTICAL_RESOLUTION
2304 ,lArray
2305 ))
2306 {
2307 LONG lHorzRes;
2308 LONG lVertRes;
2309
2310 nPixelWidth = lArray[CAPS_WIDTH];
2311 nPixelHeight = lArray[CAPS_HEIGHT];
2312 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2313 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2314 nMmWidth = (lHorzRes/1000) * nPixelWidth;
2315 nMmWidth = (lVertRes/1000) * nPixelHeight;
2316 }
2317 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
2318 {
2319 return;
2320 }
2321
2322 double dMm2pixelsX = nPixelWidth/nMmWidth;
2323 double dMm2pixelsY = nPixelHeight/nMmHeight;
2324
2325 switch (nMode)
2326 {
2327 case wxMM_TWIPS:
2328 m_logicalScaleX = (twips2mm * dMm2pixelsX);
2329 m_logicalScaleY = (twips2mm * dMm2pixelsY);
2330 break;
2331
2332 case wxMM_POINTS:
2333 m_logicalScaleX = (pt2mm * dMm2pixelsX);
2334 m_logicalScaleY = (pt2mm * dMm2pixelsY);
2335 break;
2336
2337 case wxMM_METRIC:
2338 m_logicalScaleX = dMm2pixelsX;
2339 m_logicalScaleY = dMm2pixelsY;
2340 break;
2341
2342 case wxMM_LOMETRIC:
2343 m_logicalScaleX = (dMm2pixelsX/10.0);
2344 m_logicalScaleY = (dMm2pixelsY/10.0);
2345 break;
2346
2347 case wxMM_TEXT:
2348 default:
2349 m_logicalScaleX = 1.0;
2350 m_logicalScaleY = 1.0;
2351 break;
2352 }
2353 SIZEL vSize;
2354 ULONG ulOptions;
2355
2356 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
2357 if (!ulOptions & PU_ARBITRARY)
2358 {
2359 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
2360 ::GpiSetPS(m_hPS, &vSize, ulOptions);
2361 }
2362 m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
2363 m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
2364 // ????
2365 }; // end of wxDC::SetMapMode
2366
2367 void wxDC::SetUserScale(
2368 double dX
2369 , double dY
2370 )
2371 {
2372 m_userScaleX = dX;
2373 m_userScaleY = dY;
2374
2375 SetMapMode(m_mappingMode);
2376 } // end of wxDC::SetUserScale
2377
2378 void wxDC::SetAxisOrientation(
2379 bool bXLeftRight
2380 , bool bYBottomUp
2381 )
2382 {
2383 m_signX = bXLeftRight ? 1 : -1;
2384 m_signY = bYBottomUp ? -1 : 1;
2385
2386 SetMapMode(m_mappingMode);
2387 } // end of wxDC::SetAxisOrientation
2388
2389 void wxDC::SetSystemScale(
2390 double dX
2391 , double dY
2392 )
2393 {
2394 m_scaleX = dX;
2395 m_scaleY = dY;
2396
2397 SetMapMode(m_mappingMode);
2398 } // end of wxDC::SetSystemScale
2399
2400 void wxDC::SetLogicalOrigin(
2401 wxCoord vX
2402 , wxCoord vY
2403 )
2404 {
2405 RECTL vRect;
2406
2407 ::GpiQueryPageViewport( m_hPS
2408 ,&vRect
2409 );
2410 vRect.xRight -= vX;
2411 vRect.yTop += vY;
2412 vRect.xLeft = vX;
2413 vRect.yBottom = vY;
2414 ::GpiSetPageViewport( m_hPS
2415 ,&vRect
2416 );
2417 }; // end of wxDC::SetLogicalOrigin
2418
2419 void wxDC::SetDeviceOrigin(
2420 wxCoord vX
2421 , wxCoord vY
2422 )
2423 {
2424 RECTL vRect;
2425
2426 m_deviceOriginX = vX;
2427 m_deviceOriginY = vY;
2428 ::GpiQueryPageViewport( m_hPS
2429 ,&vRect
2430 );
2431 vRect.xLeft += vX;
2432 vRect.xRight += vX;
2433 vRect.yBottom -= vY;
2434 vRect.yTop -= vY;
2435 ::GpiSetPageViewport( m_hPS
2436 ,&vRect
2437 );
2438 }; // end of wxDC::SetDeviceOrigin
2439
2440 // ---------------------------------------------------------------------------
2441 // coordinates transformations
2442 // ---------------------------------------------------------------------------
2443
2444 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
2445 {
2446 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
2447 }
2448
2449 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
2450 {
2451 // axis orientation is not taken into account for conversion of a distance
2452 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
2453 }
2454
2455 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
2456 {
2457 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
2458 }
2459
2460 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
2461 {
2462 // axis orientation is not taken into account for conversion of a distance
2463 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
2464 }
2465
2466 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
2467 {
2468 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
2469 }
2470
2471 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
2472 {
2473 // axis orientation is not taken into account for conversion of a distance
2474 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
2475 }
2476
2477 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
2478 {
2479 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
2480 }
2481
2482 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
2483 {
2484 // axis orientation is not taken into account for conversion of a distance
2485 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
2486 }
2487
2488 // ---------------------------------------------------------------------------
2489 // bit blit
2490 // ---------------------------------------------------------------------------
2491
2492 bool wxDC::DoBlit( wxCoord vXdest,
2493 wxCoord vYdest,
2494 wxCoord vWidth,
2495 wxCoord vHeight,
2496 wxDC* pSource,
2497 wxCoord vXsrc,
2498 wxCoord vYsrc,
2499 int nRop,
2500 bool bUseMask,
2501 wxCoord WXUNUSED(vXsrcMask),
2502 wxCoord WXUNUSED(vYsrcMask) )
2503 {
2504 wxMask* pMask = NULL;
2505 CHARBUNDLE vCbnd;
2506 COLORREF vOldTextColor;
2507 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
2508
2509 if (bUseMask)
2510 {
2511 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
2512
2513 pMask = rBmp.GetMask();
2514 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
2515 {
2516 bUseMask = false;
2517 }
2518 }
2519
2520 ::GpiQueryAttrs( m_hPS
2521 ,PRIM_CHAR
2522 ,CBB_COLOR
2523 ,&vCbnd
2524 );
2525 vOldTextColor = (COLORREF)vCbnd.lColor;
2526
2527 if (m_textForegroundColour.Ok())
2528 {
2529 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
2530 ::GpiSetAttrs( m_hPS // presentation-space handle
2531 ,PRIM_CHAR // Char primitive.
2532 ,CBB_COLOR // sets color.
2533 ,0
2534 ,&vCbnd // buffer for attributes.
2535 );
2536 }
2537 if (m_textBackgroundColour.Ok())
2538 {
2539 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
2540 }
2541
2542 LONG lRop = ROP_SRCCOPY;
2543
2544 switch (nRop)
2545 {
2546 case wxXOR: lRop = ROP_SRCINVERT; break;
2547 case wxINVERT: lRop = ROP_DSTINVERT; break;
2548 case wxOR_REVERSE: lRop = 0x00DD0228; break;
2549 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
2550 case wxCLEAR: lRop = ROP_ZERO; break;
2551 case wxSET: lRop = ROP_ONE; break;
2552 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
2553 case wxAND: lRop = ROP_SRCAND; break;
2554 case wxOR: lRop = ROP_SRCPAINT; break;
2555 case wxEQUIV: lRop = 0x00990066; break;
2556 case wxNAND: lRop = 0x007700E6; break;
2557 case wxAND_INVERT: lRop = 0x00220326; break;
2558 case wxCOPY: lRop = ROP_SRCCOPY; break;
2559 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
2560 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
2561 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
2562 default:
2563 wxFAIL_MSG( wxT("unsupported logical function") );
2564 return false;
2565 }
2566
2567 bool bSuccess;
2568
2569 if (bUseMask)
2570 {
2571 //
2572 // Blit bitmap with mask
2573 //
2574
2575 //
2576 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2577 //
2578 HDC hDCMask;
2579 HDC hDCBuffer;
2580 HPS hPSMask;
2581 HPS hPSBuffer;
2582 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
2583 BITMAPINFOHEADER2 vBmpHdr;
2584 HBITMAP hBufBitmap;
2585 SIZEL vSize = {0, 0};
2586 LONG rc;
2587
2588 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
2589 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
2590 vBmpHdr.cx = vWidth;
2591 vBmpHdr.cy = vHeight;
2592 vBmpHdr.cPlanes = 1;
2593 vBmpHdr.cBitCount = 24;
2594
2595 #if wxUSE_DC_CACHEING
2596 {
2597 //
2598 // create a temp buffer bitmap and DCs to access it and the mask
2599 //
2600 wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
2601 ,pSource->GetHPS()
2602 );
2603 wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
2604 ,GetHPS()
2605 );
2606 wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
2607 ,vWidth
2608 ,vHeight
2609 );
2610
2611 hPSMask = pDCCacheEntry1->m_hPS;
2612 hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
2613 hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
2614 wxUnusedVar(hDCMask);
2615 }
2616 #else
2617 {
2618 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2619 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2620 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2621 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2622 hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
2623 }
2624 #endif
2625
2626 POINTL aPoint1[4] = { {0, 0}
2627 ,{vWidth, vHeight}
2628 ,{vXdest, vYdest}
2629 ,{vXdest + vWidth, vYdest + vHeight}
2630 };
2631 POINTL aPoint2[4] = { {0, 0}
2632 ,{vWidth, vHeight}
2633 ,{vXsrc, vYsrc}
2634 ,{vXsrc + vWidth, vYsrc + vHeight}
2635 };
2636 POINTL aPoint3[4] = { {vXdest, vYdest}
2637 ,{vXdest + vWidth, vYdest + vHeight}
2638 ,{vXsrc, vYsrc}
2639 ,{vXsrc + vWidth, vYsrc + vHeight}
2640 };
2641 POINTL aPoint4[4] = { {vXdest, vYdest}
2642 ,{vXdest + vWidth, vYdest + vHeight}
2643 ,{0, 0}
2644 ,{vWidth, vHeight}
2645 };
2646 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
2647 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
2648
2649 //
2650 // Copy dest to buffer
2651 //
2652 rc = ::GpiBitBlt( hPSBuffer
2653 ,GetHPS()
2654 ,4L
2655 ,aPoint1
2656 ,ROP_SRCCOPY
2657 ,BBO_IGNORE
2658 );
2659 if (rc == GPI_ERROR)
2660 {
2661 wxLogLastError(wxT("BitBlt"));
2662 }
2663
2664 //
2665 // Copy src to buffer using selected raster op
2666 //
2667 rc = ::GpiBitBlt( hPSBuffer
2668 ,GetHPS()
2669 ,4L
2670 ,aPoint2
2671 ,lRop
2672 ,BBO_IGNORE
2673 );
2674 if (rc == GPI_ERROR)
2675 {
2676 wxLogLastError(wxT("BitBlt"));
2677 }
2678
2679 //
2680 // Set masked area in buffer to BLACK (pixel value 0)
2681 //
2682 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
2683 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
2684
2685 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2686 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2687
2688 rc = ::GpiBitBlt( hPSBuffer
2689 ,hPSMask
2690 ,4L
2691 ,aPoint2
2692 ,ROP_SRCAND
2693 ,BBO_IGNORE
2694 );
2695 if (rc == GPI_ERROR)
2696 {
2697 wxLogLastError(wxT("BitBlt"));
2698 }
2699
2700 //
2701 // Set unmasked area in dest to BLACK
2702 //
2703 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2704 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2705 rc = ::GpiBitBlt( GetHPS()
2706 ,hPSMask
2707 ,4L
2708 ,aPoint3
2709 ,ROP_SRCAND
2710 ,BBO_IGNORE
2711 );
2712 if (rc == GPI_ERROR)
2713 {
2714 wxLogLastError(wxT("BitBlt"));
2715 }
2716
2717 //
2718 // Restore colours to original values
2719 //
2720 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
2721 ::GpiSetColor(GetHPS(), vPrevCol);
2722
2723 //
2724 // OR buffer to dest
2725 //
2726 rc = ::GpiBitBlt( GetHPS()
2727 ,hPSMask
2728 ,4L
2729 ,aPoint4
2730 ,ROP_SRCPAINT
2731 ,BBO_IGNORE
2732 );
2733 if (rc == GPI_ERROR)
2734 {
2735 bSuccess = false;
2736 wxLogLastError(wxT("BitBlt"));
2737 }
2738
2739 //
2740 // Tidy up temporary DCs and bitmap
2741 //
2742 ::GpiSetBitmap(hPSMask, NULLHANDLE);
2743 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
2744 #if !wxUSE_DC_CACHEING
2745 ::GpiDestroyPS(hPSMask);
2746 ::GpiDestroyPS(hPSBuffer);
2747 ::DevCloseDC(hDCMask);
2748 ::DevCloseDC(hDCBuffer);
2749 ::GpiDeleteBitmap(hBufBitmap);
2750 #endif
2751 bSuccess = true;
2752 }
2753 else // no mask, just BitBlt() it
2754 {
2755 POINTL aPoint[4] = { {vXdest, vYdest}
2756 ,{vXdest + vWidth, vYdest + vHeight}
2757 ,{vXsrc, vYsrc}
2758 ,{vXsrc + vWidth, vYsrc + vHeight}
2759 };
2760
2761 bSuccess = (::GpiBitBlt( m_hPS
2762 ,pSource->GetHPS()
2763 ,4L
2764 ,aPoint
2765 ,lRop
2766 ,BBO_IGNORE
2767 ) != GPI_ERROR);
2768 if (!bSuccess )
2769 {
2770 wxLogLastError(wxT("BitBlt"));
2771 }
2772 }
2773 vCbnd.lColor = (LONG)vOldTextColor;
2774 ::GpiSetAttrs( m_hPS // presentation-space handle
2775 ,PRIM_CHAR // Char primitive.
2776 ,CBB_COLOR // sets color.
2777 ,0
2778 ,&vCbnd // buffer for attributes.
2779 );
2780 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
2781 return bSuccess;
2782 }
2783
2784 void wxDC::DoGetSize(
2785 int* pnWidth
2786 , int* pnHeight
2787 ) const
2788 {
2789 LONG lArray[CAPS_HEIGHT];
2790
2791 if(::DevQueryCaps( m_hDC
2792 ,CAPS_FAMILY
2793 ,CAPS_HEIGHT
2794 ,lArray
2795 ))
2796 {
2797 *pnWidth = lArray[CAPS_WIDTH];
2798 *pnHeight = lArray[CAPS_HEIGHT];
2799 }
2800 }; // end of wxDC::DoGetSize(
2801
2802 void wxDC::DoGetSizeMM( int* pnWidth,
2803 int* pnHeight ) const
2804 {
2805 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2806
2807 if(::DevQueryCaps( m_hDC
2808 ,CAPS_FAMILY
2809 ,CAPS_VERTICAL_RESOLUTION
2810 ,lArray
2811 ))
2812 {
2813 if(pnWidth)
2814 {
2815 int nWidth = lArray[CAPS_WIDTH];
2816 int nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2817 *pnWidth = (nHorzRes/1000) * nWidth;
2818 }
2819
2820 if(pnHeight)
2821 {
2822 int nHeight = lArray[CAPS_HEIGHT];
2823 int nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2824 *pnHeight = (nVertRes/1000) * nHeight;
2825 }
2826 }
2827 }; // end of wxDC::DoGetSizeMM
2828
2829 wxSize wxDC::GetPPI() const
2830 {
2831 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2832 int nWidth = 0;
2833 int nHeight = 0;
2834
2835 if(::DevQueryCaps( m_hDC
2836 ,CAPS_FAMILY
2837 ,CAPS_VERTICAL_RESOLUTION
2838 ,lArray
2839 ))
2840 {
2841 int nPelWidth;
2842 int nPelHeight;
2843 int nHorzRes;
2844 int nVertRes;
2845
2846 nPelWidth = lArray[CAPS_WIDTH];
2847 nPelHeight = lArray[CAPS_HEIGHT];
2848 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2849 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2850 nWidth = (int)((nHorzRes/39.3) * nPelWidth);
2851 nHeight = (int)((nVertRes/39.3) * nPelHeight);
2852 }
2853 wxSize ppisize(nWidth, nHeight);
2854 return ppisize;
2855 } // end of wxDC::GetPPI
2856
2857 void wxDC::SetLogicalScale(
2858 double dX
2859 , double dY
2860 )
2861 {
2862 m_logicalScaleX = dX;
2863 m_logicalScaleY = dY;
2864 }; // end of wxDC::SetLogicalScale