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