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