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