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