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