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