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