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