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