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