Added wxDF_HTML
[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
571 vPtlPos.x = vX; // Loads x-coordinate
572 vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate
573 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
574 lColor = rCol.GetPixel();
575 lOptions = FF_BOUNDARY;
576 if(wxFLOOD_SURFACE == nStyle)
577 lOptions = FF_SURFACE;
578
579 ::GpiFloodFill(m_hPS, lOptions, lColor);
580
581 return TRUE;
582 } // end of wxDC::DoFloodFill
583
584 bool wxDC::DoGetPixel(
585 wxCoord vX
586 , wxCoord vY
587 , wxColour* pCol
588 ) const
589 {
590 POINTL vPoint;
591 LONG lColor;
592
593 vPoint.x = vX;
594 vPoint.y = OS2Y(vY,0);
595 lColor = ::GpiSetPel(m_hPS, &vPoint);
596
597 //
598 // Get the color of the pen
599 //
600 LONG lPencolor = 0x00ffffff;
601
602 if (m_pen.Ok())
603 {
604 lPencolor = m_pen.GetColour().GetPixel();
605 }
606
607 //
608 // return the color of the pixel
609 //
610 if(pCol)
611 pCol->Set( GetRValue(lColor)
612 ,GetGValue(lColor)
613 ,GetBValue(lColor)
614 );
615 return(lColor == lPencolor);
616 } // end of wxDC::DoGetPixel
617
618 void wxDC::DoCrossHair(
619 wxCoord vX
620 , wxCoord vY
621 )
622 {
623 vY = OS2Y(vY,0);
624
625 wxCoord vX1 = vX - VIEWPORT_EXTENT;
626 wxCoord vY1 = vY - VIEWPORT_EXTENT;
627 wxCoord vX2 = vX + VIEWPORT_EXTENT;
628 wxCoord vY2 = vY + VIEWPORT_EXTENT;
629 POINTL vPoint[4];
630
631 vPoint[0].x = vX1;
632 vPoint[0].y = vY;
633
634 vPoint[1].x = vX2;
635 vPoint[1].y = vY;
636
637 ::GpiMove(m_hPS, &vPoint[0]);
638 ::GpiLine(m_hPS, &vPoint[1]);
639
640 vPoint[2].x = vX;
641 vPoint[2].y = vY1;
642
643 vPoint[3].x = vX;
644 vPoint[3].y = vY2;
645
646 ::GpiMove(m_hPS, &vPoint[2]);
647 ::GpiLine(m_hPS, &vPoint[3]);
648 CalcBoundingBox(vX1, vY1);
649 CalcBoundingBox(vX2, vY2);
650 } // end of wxDC::DoCrossHair
651
652 void wxDC::DoDrawLine(
653 wxCoord vX1
654 , wxCoord vY1
655 , wxCoord vX2
656 , wxCoord vY2
657 )
658 {
659 POINTL vPoint[2];
660
661 vY1 = OS2Y(vY1,0);
662 vY2 = OS2Y(vY2,0);
663
664 vPoint[0].x = vX1;
665 vPoint[0].y = vY1;
666 vPoint[1].x = vX2;
667 vPoint[1].y = vY2;
668 ::GpiMove(m_hPS, &vPoint[0]);
669 ::GpiLine(m_hPS, &vPoint[1]);
670 CalcBoundingBox(vX1, vY1);
671 CalcBoundingBox(vX2, vY2);
672 } // end of wxDC::DoDrawLine
673
674 //////////////////////////////////////////////////////////////////////////////
675 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
676 // and ending at (x2, y2). The current pen is used for the outline and the
677 // current brush for filling the shape. The arc is drawn in an anticlockwise
678 // direction from the start point to the end point.
679 //////////////////////////////////////////////////////////////////////////////
680 void wxDC::DoDrawArc(
681 wxCoord vX1
682 , wxCoord vY1
683 , wxCoord vX2
684 , wxCoord vY2
685 , wxCoord vXc
686 , wxCoord vYc
687 )
688 {
689 POINTL vPtlPos;
690 POINTL vPtlArc[2]; // Structure for current position
691 int nDx;
692 int nDy;
693 double dRadius;
694 double dAngl1;
695 double dAngl2;
696 double dAnglmid;
697 wxCoord vXm;
698 wxCoord vYm;
699 ARCPARAMS vArcp; // Structure for arc parameters
700
701 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
702 return; // Draw point ??
703 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
704 ,(double)(vX1 - vXc)
705 ) +
706 hypot( (double)(vY2 - vYc)
707 ,(double)(vX2 - vXc)
708 )
709 );
710
711 dAngl1 = atan2( (double)(vY1 - vYc)
712 ,(double)(vX1 - vXc)
713 );
714 dAngl2 = atan2( (double)(vY2 - vYc)
715 ,(double)(vX2 - vXc)
716 );
717 if(dAngl2 < dAngl1)
718 dAngl2 += M_PI * 2;
719
720 //
721 // GpiPointArc can't draw full arc
722 //
723 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
724 {
725 //
726 // Medium point
727 //
728 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
729 vXm = vXc + dRadius * cos(dAnglmid);
730 vYm = vYc + dRadius * sin(dAnglmid);
731 DoDrawArc( vX1, vY1
732 ,vXm, vYm
733 ,vXc, vYc
734 );
735 DoDrawArc( vXm, vYm
736 ,vX2, vY2
737 ,vXc, vYc
738 );
739 return;
740 }
741
742 //
743 // Medium point
744 //
745 dAnglmid = (dAngl1 + dAngl2)/2.;
746 vXm = vXc + dRadius * cos(dAnglmid);
747 vYm = vYc + dRadius * sin(dAnglmid);
748
749 //
750 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
751 //
752 vArcp.lR = 0;
753 vArcp.lQ = 1;
754 vArcp.lP = 1;
755 vArcp.lS = 0;
756 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
757
758 vPtlPos.x = vX1; // Loads x-coordinate
759 vPtlPos.y = vY1; // Loads y-coordinate
760 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
761 vPtlArc[0].x = vXm;
762 vPtlArc[0].y = vYm;
763 vPtlArc[1].x = vX2;
764 vPtlArc[1].y = vY2;
765 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
766 CalcBoundingBox( (vXc - dRadius)
767 ,(vYc - dRadius)
768 );
769 CalcBoundingBox( (vXc + dRadius)
770 ,(vYc + dRadius)
771 );
772 } // end of wxDC::DoDrawArc
773
774 void wxDC::DoDrawCheckMark(
775 wxCoord vX1
776 , wxCoord vY1
777 , wxCoord vWidth
778 , wxCoord vHeight
779 )
780 {
781 POINTL vPoint[2];
782
783 vY1 = OS2Y(vY1,vHeight);
784
785 vPoint[0].x = vX1;
786 vPoint[0].y = vY1;
787 vPoint[1].x = vX1 + vWidth;
788 vPoint[1].y = vY1 + vHeight;
789
790 ::GpiMove(m_hPS, &vPoint[0]);
791 ::GpiBox( m_hPS // handle to a presentation space
792 ,DRO_OUTLINE // draw the box outline ? or ?
793 ,&vPoint[1] // address of the corner
794 ,0L // horizontal corner radius
795 ,0L // vertical corner radius
796 );
797 if(vWidth > 4 && vHeight > 4)
798 {
799 int nTmp;
800
801 vPoint[0].x += 2; vPoint[0].y += 2;
802 vPoint[1].x -= 2; vPoint[1].y -= 2;
803 ::GpiMove(m_hPS, &vPoint[0]);
804 ::GpiLine(m_hPS, &vPoint[1]);
805 nTmp = vPoint[0].x;
806 vPoint[0].x = vPoint[1].x;
807 vPoint[1].x = nTmp;
808 ::GpiMove(m_hPS, &vPoint[0]);
809 ::GpiLine(m_hPS, &vPoint[1]);
810 }
811 CalcBoundingBox( vX1
812 ,vY1
813 );
814
815 wxCoord vX2 = vX1 + vWidth;
816 wxCoord vY2 = vY1 + vHeight;
817
818 CalcBoundingBox( vX2
819 ,vY2
820 );
821 } // end of wxDC::DoDrawCheckMark
822
823 void wxDC::DoDrawPoint(
824 wxCoord vX
825 , wxCoord vY
826 )
827 {
828 POINTL vPoint;
829 COLORREF vColor = 0x00ffffff;
830
831 if (m_pen.Ok())
832 {
833 vColor = m_pen.GetColour().GetPixel();
834 }
835 ::GpiSetColor(m_hPS, vColor);
836 vPoint.x = vX;
837 vPoint.y = OS2Y(vY,0);
838 ::GpiSetPel(m_hPS, &vPoint);
839 CalcBoundingBox( vX
840 ,vY
841 );
842 } // end of wxDC::DoDrawPoint
843
844 void wxDC::DoDrawPolygon(
845 int n
846 , wxPoint vPoints[]
847 , wxCoord vXoffset
848 , wxCoord vYoffset
849 , int nFillStyle
850 )
851 {
852 ULONG ulCount = 1; // Number of polygons.
853 POLYGON vPlgn; // polygon.
854 ULONG flOptions = 0L; // Drawing options.
855
856 //////////////////////////////////////////////////////////////////////////////
857 // This contains fields of option bits... to draw boundary lines as well as
858 // the area interior.
859 //
860 // Drawing boundary lines:
861 // POLYGON_NOBOUNDARY Does not draw boundary lines.
862 // POLYGON_BOUNDARY Draws boundary lines (the default).
863 //
864 // Construction of the area interior:
865 // POLYGON_ALTERNATE Constructs interior in alternate mode
866 // (the default).
867 // POLYGON_WINDING Constructs interior in winding mode.
868 //////////////////////////////////////////////////////////////////////////////
869
870 ULONG flModel = 0L; // Drawing model.
871
872 //////////////////////////////////////////////////////////////////////////////
873 // Drawing model.
874 // POLYGON_INCL Fill is inclusive of bottom right (the default).
875 // POLYGON_EXCL Fill is exclusive of bottom right.
876 // This is provided to aid migration from other graphics models.
877 //////////////////////////////////////////////////////////////////////////////
878
879 LONG lHits = 0L; // Correlation/error indicator.
880 POINTL vPoint;
881 int i;
882 int nIsTRANSPARENT = 0;
883 LONG lBorderColor = 0L;
884 LONG lColor = 0L;
885
886 lBorderColor = m_pen.GetColour().GetPixel();
887 lColor = m_brush.GetColour().GetPixel();
888 if(m_brush.GetStyle() == wxTRANSPARENT)
889 nIsTRANSPARENT = 1;
890
891 vPlgn.ulPoints = n;
892 vPlgn.aPointl = (POINTL*) calloc( n + 1
893 ,sizeof(POINTL)
894 ); // well, new will call malloc
895
896 for(i = 0; i < n; i++)
897 {
898 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
899 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
900 }
901 flModel = POLYGON_BOUNDARY;
902 if(nFillStyle == wxWINDING_RULE)
903 flModel |= POLYGON_WINDING;
904 else
905 flModel |= POLYGON_ALTERNATE;
906
907 vPoint.x = vXoffset;
908 vPoint.y = OS2Y(vYoffset,0);
909
910 ::GpiSetColor(m_hPS, lBorderColor);
911 ::GpiMove(m_hPS, &vPoint);
912 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
913 free(vPlgn.aPointl);
914 } // end of wxDC::DoDrawPolygon
915
916 void wxDC::DoDrawLines(
917 int n
918 , wxPoint vPoints[]
919 , wxCoord vXoffset
920 , wxCoord vYoffset
921 )
922 {
923 POINTL vPoint;
924
925 if (vXoffset != 0L || vXoffset != 0L)
926 {
927 int i;
928
929 vPoint.x = vPoints[0].x + vXoffset;
930 vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
931 ::GpiMove(m_hPS, &vPoint);
932
933 LONG lBorderColor = m_pen.GetColour().GetPixel();
934
935 ::GpiSetColor(m_hPS, lBorderColor);
936 for(i = 1; i < n; i++)
937 {
938 vPoint.x = vPoints[i].x + vXoffset;
939 vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
940 ::GpiLine(m_hPS, &vPoint);
941 }
942 }
943 else
944 {
945 int i;
946
947 CalcBoundingBox( vPoints[i].x
948 ,vPoints[i].y
949 );
950 vPoint.x = vPoints[0].x;
951 vPoint.y = OS2Y(vPoints[0].y,0);
952 ::GpiMove(m_hPS, &vPoint);
953
954 for (i = 0; i < n; i++)
955 {
956 CalcBoundingBox( vPoints[i].x
957 ,vPoints[i].y
958 );
959 vPoint.x = vPoints[i].x;
960 vPoint.y = OS2Y(vPoints[i].y,0);
961 ::GpiLine(m_hPS, &vPoint);
962 }
963 }
964 } // end of wxDC::DoDrawLines
965
966 void wxDC::DoDrawRectangle(
967 wxCoord vX
968 , wxCoord vY
969 , wxCoord vWidth
970 , wxCoord vHeight
971 )
972 {
973 POINTL vPoint[2];
974 LONG lControl;
975 LONG lColor;
976 LONG lBorderColor;
977 int nIsTRANSPARENT = 0;
978
979 vY = OS2Y(vY,vHeight);
980
981 wxCoord vX2 = vX + vWidth;
982 wxCoord vY2 = vY + vHeight;
983
984 vPoint[0].x = vX;
985 vPoint[0].y = vY;
986 vPoint[1].x = vX + vWidth;
987 vPoint[1].y = vY + vHeight;
988 ::GpiMove(m_hPS, &vPoint[0]);
989 lColor = m_brush.GetColour().GetPixel();
990 lBorderColor = m_pen.GetColour().GetPixel();
991 if (m_brush.GetStyle() == wxTRANSPARENT)
992 nIsTRANSPARENT = 1;
993 if(lColor == lBorderColor || nIsTRANSPARENT)
994 {
995 lControl = DRO_OUTLINEFILL; //DRO_FILL;
996 if(m_brush.GetStyle() == wxTRANSPARENT)
997 lControl = DRO_OUTLINE;
998
999 ::GpiSetColor(m_hPS, lColor);
1000 ::GpiBox( m_hPS // handle to a presentation space
1001 ,lControl // draw the box outline ? or ?
1002 ,&vPoint[1] // address of the corner
1003 ,0L // horizontal corner radius
1004 ,0L // vertical corner radius
1005 );
1006 }
1007 else
1008 {
1009 lControl = DRO_OUTLINE;
1010 ::GpiSetColor( m_hPS
1011 ,lBorderColor
1012 );
1013 ::GpiBox( m_hPS
1014 ,lControl
1015 ,&vPoint[1]
1016 ,0L
1017 ,0L
1018 );
1019 lControl = DRO_FILL;
1020 ::GpiSetColor( m_hPS
1021 ,lColor
1022 );
1023 vPoint[0].x = vX + 1;
1024 vPoint[0].y = vY + 1;
1025 vPoint[1].x = vX + vWidth - 1;
1026 vPoint[1].y = vY + vHeight - 1;
1027 ::GpiMove(m_hPS, &vPoint[0]);
1028 ::GpiBox( m_hPS
1029 ,lControl
1030 ,&vPoint[1]
1031 ,0L
1032 ,0L
1033 );
1034 }
1035 CalcBoundingBox(vX, vY);
1036 CalcBoundingBox(vX2, vY2);
1037 } // end of wxDC::DoDrawRectangle
1038
1039 void wxDC::DoDrawRoundedRectangle(
1040 wxCoord vX
1041 , wxCoord vY
1042 , wxCoord vWidth
1043 , wxCoord vHeight
1044 , double dRadius
1045 )
1046 {
1047 POINTL vPoint[2];
1048 LONG lControl;
1049
1050 vY = OS2Y(vY,vHeight);
1051
1052 wxCoord vX2 = (vX + vWidth);
1053 wxCoord vY2 = (vY + vHeight);
1054
1055 vPoint[0].x = vX;
1056 vPoint[0].y = YLOG2DEV(vY) - vHeight;
1057 vPoint[1].x = vX + vWidth;
1058 vPoint[1].y = vY;
1059 ::GpiMove(m_hPS, &vPoint[0]);
1060
1061 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1062 if (m_brush.GetStyle() == wxTRANSPARENT)
1063 lControl = DRO_OUTLINE;
1064 ::GpiBox( m_hPS // handle to a presentation space
1065 ,DRO_OUTLINE // draw the box outline ? or ?
1066 ,&vPoint[1] // address of the corner
1067 ,(LONG)dRadius // horizontal corner radius
1068 ,(LONG)dRadius // vertical corner radius
1069 );
1070 CalcBoundingBox(vX, vY);
1071 CalcBoundingBox(vX2, vY2);
1072 } // end of wxDC::DoDrawRoundedRectangle
1073
1074 // Draw Ellipse within box (x,y) - (x+width, y+height)
1075 void wxDC::DoDrawEllipse(
1076 wxCoord vX
1077 , wxCoord vY
1078 , wxCoord vWidth
1079 , wxCoord vHeight
1080 )
1081 {
1082 POINTL vPtlPos; // Structure for current position
1083 FIXED vFxMult; // Multiplier for ellipse
1084 ARCPARAMS vArcp; // Structure for arc parameters
1085
1086 vY = OS2Y(vY,vHeight);
1087
1088 vArcp.lR = 0;
1089 vArcp.lQ = vHeight/2;
1090 vArcp.lP = vWidth/2;
1091 vArcp.lS = 0;
1092 ::GpiSetArcParams( m_hPS
1093 ,&vArcp
1094 ); // Sets parameters to default
1095 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
1096 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1097 ::GpiMove( m_hPS
1098 ,&vPtlPos
1099 ); // Sets current position
1100 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
1101
1102 //
1103 // DRO_FILL, DRO_OTLINEFILL - where to get
1104 //
1105 ::GpiFullArc( m_hPS
1106 ,DRO_OUTLINE
1107 ,vFxMult
1108 ); // Draws full arc with center at current position
1109
1110 wxCoord vX2 = (vX + vWidth);
1111 wxCoord vY2 = (vY + vHeight);
1112
1113 CalcBoundingBox(vX, vY);
1114 CalcBoundingBox(vX2, vY2);
1115 } // end of wxDC::DoDrawEllipse
1116
1117 void wxDC::DoDrawEllipticArc(
1118 wxCoord vX
1119 , wxCoord vY
1120 , wxCoord vWidth
1121 , wxCoord vHeight
1122 , double dSa
1123 , double dEa
1124 )
1125 {
1126 POINTL vPtlPos; // Structure for current position
1127 FIXED vFxMult; // Multiplier for ellipse
1128 ARCPARAMS vArcp; // Structure for arc parameters
1129 FIXED vFSa;
1130 FIXED vFSweepa; // Start angle, sweep angle
1131 double dIntPart;
1132 double dFractPart;
1133 double dRadius;
1134
1135 vY = OS2Y(vY,vHeight);
1136
1137 dFractPart = modf(dSa,&dIntPart);
1138 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1139 dFractPart = modf(dEa - dSa, &dIntPart);
1140 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1141
1142 //
1143 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1144 //
1145 vArcp.lR = 0;
1146 vArcp.lQ = vHeight/2;
1147 vArcp.lP = vWidth/2;
1148 vArcp.lS = 0;
1149 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
1150 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
1151 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
1152 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
1153
1154 //
1155 // May be not to the center ?
1156 //
1157 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
1158 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1159 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
1160
1161 //
1162 // DRO_FILL, DRO_OTLINEFILL - where to get
1163 //
1164 ::GpiPartialArc( m_hPS
1165 ,&vPtlPos
1166 ,vFxMult
1167 ,vFSa
1168 ,vFSweepa
1169 );
1170 wxCoord vX2 = (vX + vWidth);
1171 wxCoord vY2 = (vY + vHeight);
1172
1173 CalcBoundingBox(vX, vY);
1174 CalcBoundingBox(vX2, vY2);
1175 } // end of wxDC::DoDrawEllipticArc
1176
1177 void wxDC::DoDrawIcon(
1178 const wxIcon& rIcon
1179 , wxCoord vX
1180 , wxCoord vY
1181 )
1182 {
1183 vY = OS2Y(vY,rIcon.GetHeight());
1184 wxCHECK_RET( rIcon.Ok(), wxT("invalid icon in DrawIcon") );
1185
1186 ::WinDrawPointer( GetHPS()
1187 ,vX
1188 ,vY
1189 ,(HPOINTER)GetHiconOf(rIcon)
1190 ,DP_NORMAL
1191 );
1192 CalcBoundingBox(vX, vY);
1193 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
1194 } // end of wxDC::DoDrawIcon
1195
1196 void wxDC::DoDrawBitmap(
1197 const wxBitmap& rBmp
1198 , wxCoord vX
1199 , wxCoord vY
1200 , bool bUseMask
1201 )
1202 {
1203 POINTL vPoint = {vX, vY};
1204
1205 ::WinDrawBitmap( GetHPS()
1206 ,(HBITMAP)GetHbitmapOf(rBmp)
1207 ,NULL
1208 ,&vPoint
1209 ,0L
1210 ,0L
1211 ,DBM_NORMAL
1212 );
1213 } // end of wxDC::DoDrawBitmap
1214
1215 void wxDC::DoDrawText(
1216 const wxString& rsText
1217 , wxCoord vX
1218 , wxCoord vY
1219 )
1220 {
1221 wxCoord vWidth;
1222 wxCoord vHeight;
1223
1224 DrawAnyText( rsText
1225 ,vX
1226 ,vY
1227 );
1228
1229 CalcBoundingBox(vX, vY);
1230 GetTextExtent(rsText, &vWidth, &vHeight);
1231 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1232 } // end of wxDC::DoDrawText
1233
1234 void wxDC::DrawAnyText(
1235 const wxString& rsText
1236 , wxCoord vX
1237 , wxCoord vY
1238 )
1239 {
1240 int nOldBackground = 0;
1241 POINTL vPtlStart;
1242 LONG lHits;
1243 wxCoord vTextX = 0;
1244 wxCoord vTextY = 0;
1245
1246 //
1247 // prepare for drawing the text
1248 //
1249
1250 //
1251 // Set text color attributes
1252 //
1253 if (m_textForegroundColour.Ok())
1254 {
1255 SetTextColor( m_hPS
1256 ,(int)m_textForegroundColour.GetPixel()
1257 );
1258 }
1259
1260 if (m_textBackgroundColour.Ok())
1261 {
1262 nOldBackground = SetTextBkColor( m_hPS
1263 ,(int)m_textBackgroundColour.GetPixel()
1264 );
1265 }
1266 SetBkMode( m_hPS
1267 ,m_backgroundMode
1268 );
1269 GetTextExtent( rsText
1270 ,&vTextX
1271 ,&vTextY
1272 );
1273 vPtlStart.x = vX;
1274 vPtlStart.y = OS2Y(vY,vTextY);
1275
1276 lHits = ::GpiCharStringAt( m_hPS
1277 ,&vPtlStart
1278 ,rsText.length()
1279 ,(PCH)rsText.c_str()
1280 );
1281 if (lHits != GPI_OK)
1282 {
1283 wxLogLastError(wxT("TextOut"));
1284 }
1285
1286 //
1287 // Restore the old parameters (text foreground colour may be left because
1288 // it never is set to anything else, but background should remain
1289 // transparent even if we just drew an opaque string)
1290 //
1291 if (m_textBackgroundColour.Ok())
1292 SetTextBkColor( m_hPS
1293 ,nOldBackground
1294 );
1295 SetBkMode( m_hPS
1296 ,wxTRANSPARENT
1297 );
1298 }
1299
1300 void wxDC::DoDrawRotatedText(
1301 const wxString& rsText
1302 , wxCoord vX
1303 , wxCoord vY
1304 , double dAngle
1305 )
1306 {
1307 if (dAngle == 0.0)
1308 {
1309 DoDrawText( rsText
1310 ,vX
1311 ,vY
1312 );
1313 }
1314
1315 // TODO:
1316 /*
1317 if ( angle == 0.0 )
1318 {
1319 DoDrawText(text, x, y);
1320 }
1321 else
1322 {
1323 LOGFONT lf;
1324 wxFillLogFont(&lf, &m_font);
1325
1326 // GDI wants the angle in tenth of degree
1327 long angle10 = (long)(angle * 10);
1328 lf.lfEscapement = angle10;
1329 lf. lfOrientation = angle10;
1330
1331 HFONT hfont = ::CreateFontIndirect(&lf);
1332 if ( !hfont )
1333 {
1334 wxLogLastError("CreateFont");
1335 }
1336 else
1337 {
1338 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1339
1340 DrawAnyText(text, x, y);
1341
1342 (void)::SelectObject(GetHdc(), hfontOld);
1343 }
1344
1345 // call the bounding box by adding all four vertices of the rectangle
1346 // containing the text to it (simpler and probably not slower than
1347 // determining which of them is really topmost/leftmost/...)
1348 wxCoord w, h;
1349 GetTextExtent(text, &w, &h);
1350
1351 double rad = DegToRad(angle);
1352
1353 // "upper left" and "upper right"
1354 CalcBoundingBox(x, y);
1355 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1356 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1357
1358 // "bottom left" and "bottom right"
1359 x += (wxCoord)(h*sin(rad));
1360 y += (wxCoord)(h*cos(rad));
1361 CalcBoundingBox(x, y);
1362 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1363 }
1364 */
1365 }
1366
1367 // ---------------------------------------------------------------------------
1368 // set GDI objects
1369 // ---------------------------------------------------------------------------
1370
1371 void wxDC::DoSelectPalette(
1372 bool bRealize
1373 )
1374 {
1375 //
1376 // Set the old object temporarily, in case the assignment deletes an object
1377 // that's not yet selected out.
1378 //
1379 if (m_hOldPalette)
1380 {
1381 m_hOldPalette = 0;
1382 }
1383
1384 if (m_palette.Ok())
1385 {
1386 HPALETTE hOldPal;
1387
1388 hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1389 if (!m_hOldPalette)
1390 m_hOldPalette = (WXHPALETTE)hOldPal;
1391 }
1392 } // end of wxDC::DoSelectPalette
1393
1394 void wxDC::InitializePalette()
1395 {
1396 if (wxDisplayDepth() <= 8 )
1397 {
1398 //
1399 // Look for any window or parent that has a custom palette. If any has
1400 // one then we need to use it in drawing operations
1401 //
1402 wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette();
1403
1404 m_hasCustomPalette = pWin && pWin->HasCustomPalette();
1405 if (m_hasCustomPalette)
1406 {
1407 m_palette = pWin->GetPalette();
1408
1409 //
1410 // turn on PM translation for this palette
1411 //
1412 DoSelectPalette();
1413 }
1414 }
1415 } // end of wxDC::InitializePalette
1416
1417 void wxDC::SetPalette(
1418 const wxPalette& rPalette
1419 )
1420 {
1421 if (m_hOldFont)
1422 {
1423 m_hOldFont = 0;
1424 }
1425 m_palette = rPalette;
1426 if (!rPalette.Ok())
1427 {
1428 if (m_hOldFont)
1429 {
1430 m_hOldFont = 0;
1431 }
1432 }
1433 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1434 if (!m_hOldPalette)
1435 m_hOldPalette = (WXHPALETTE)hOldPal;
1436 } // end of wxDC::SetPalette
1437
1438 void wxDC::SetFont(
1439 const wxFont& rFont
1440 )
1441 {
1442 //
1443 // Set the old object temporarily, in case the assignment deletes an object
1444 // that's not yet selected out.
1445 //
1446 if (m_hOldFont)
1447 {
1448 m_hOldFont = 0;
1449 }
1450 m_font = rFont;
1451 if (!rFont.Ok())
1452 {
1453 m_hOldFont = 0;
1454 }
1455
1456 m_font.SetPS(m_hPS); // this will realize the font
1457
1458 if (m_font.Ok())
1459 {
1460 HFONT hFont = m_font.GetResourceHandle();
1461 if (hFont == (HFONT) NULL)
1462 {
1463 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1464 }
1465 if (!m_hOldFont)
1466 m_hOldFont = (WXHFONT) hFont;
1467 }
1468 } // end of wxDC::SetFont
1469
1470 void wxDC::SetPen(
1471 const wxPen& rPen
1472 )
1473 {
1474 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1475
1476 if (m_pen == rPen)
1477 return;
1478 m_pen = rPen;
1479 if (!m_pen.Ok())
1480 return;
1481
1482 if (m_hOldPen)
1483 m_hOldPen = 0L;
1484 m_pen = rPen;
1485
1486 if (!m_pen.Ok())
1487 {
1488 if (m_hOldPen)
1489 {
1490 m_pen.SetPS((HPS)m_hOldPen);
1491 }
1492 m_hOldPen = 0L;
1493 }
1494
1495 if (m_pen.Ok())
1496 {
1497 if (m_pen.GetResourceHandle())
1498 {
1499 m_pen.SetPS(m_hPS);
1500 if (!m_hOldPen)
1501 m_hOldPen = m_pen.GetPS();
1502 }
1503 }
1504 }
1505
1506 void wxDC::SetBrush(
1507 const wxBrush& rBrush
1508 )
1509 {
1510 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1511
1512 if (m_hOldBrush)
1513 m_hOldBrush = 0L;
1514 m_brush = rBrush;
1515 if (!m_brush.Ok())
1516 if (m_brush == rBrush)
1517 return;
1518 if (!m_brush.Ok())
1519 if (m_hOldBrush)
1520 m_hOldBrush = 0L;
1521
1522 if (!m_brush.Ok())
1523 {
1524 if (m_hOldBrush)
1525 {
1526 m_brush.SetPS((HPS)m_hOldBrush);
1527 }
1528 m_hOldBrush = 0L;
1529 }
1530
1531 if (m_brush.Ok())
1532 {
1533 if (m_brush.GetResourceHandle())
1534 {
1535 m_brush.SetPS(m_hPS);
1536 if (!m_hOldBrush)
1537 m_hOldBrush = (WXHWND)m_brush.GetPS();
1538 }
1539 }
1540 } // end of wxDC::SetBrush
1541
1542 void wxDC::SetBackground(
1543 const wxBrush& rBrush
1544 )
1545 {
1546 m_backgroundBrush = rBrush;
1547 if (!m_backgroundBrush.Ok())
1548 return;
1549 if (m_pCanvas)
1550 {
1551 bool bCustomColours = TRUE;
1552
1553 //
1554 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1555 // change background colours from the control-panel specified colours.
1556 //
1557 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
1558 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
1559 bCustomColours = FALSE;
1560 if (bCustomColours)
1561 {
1562 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
1563 {
1564 m_pCanvas->SetTransparent(TRUE);
1565 }
1566 else
1567 {
1568 //
1569 // Setting the background brush of a DC
1570 // doesn't affect the window background colour. However,
1571 // I'm leaving in the transparency setting because it's needed by
1572 // various controls (e.g. wxStaticText) to determine whether to draw
1573 // transparently or not. TODO: maybe this should be a new function
1574 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1575 // parent?
1576 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1577 //
1578 m_pCanvas->SetTransparent(FALSE);
1579 }
1580 }
1581 }
1582 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
1583 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
1584 } // end of wxDC::SetBackground
1585
1586 void wxDC::SetBackgroundMode(
1587 int nMode
1588 )
1589 {
1590 m_backgroundMode = nMode;
1591 } // end of wxDC::SetBackgroundMode
1592
1593 void wxDC::SetLogicalFunction(
1594 int nFunction
1595 )
1596 {
1597 m_logicalFunction = nFunction;
1598 SetRop((WXHDC)m_hDC);
1599 } // wxDC::SetLogicalFunction
1600
1601 void wxDC::SetRop(
1602 WXHDC hDC
1603 )
1604 {
1605 if (!hDC || m_logicalFunction < 0)
1606 return;
1607
1608 LONG lCRop;
1609 switch (m_logicalFunction)
1610 {
1611 case wxXOR:
1612 lCRop = FM_XOR;
1613 break;
1614
1615 case wxINVERT:
1616 lCRop = FM_INVERT;
1617 break;
1618
1619 case wxOR_REVERSE:
1620 lCRop = FM_MERGESRCNOT;
1621 break;
1622
1623 case wxAND_REVERSE:
1624 lCRop = FM_NOTMASKSRC;
1625 break;
1626
1627 case wxCLEAR:
1628 lCRop = FM_ONE;
1629 break;
1630
1631 case wxSET:
1632 lCRop = FM_ZERO;
1633 break;
1634
1635 case wxSRC_INVERT:
1636 lCRop = FM_MERGENOTSRC;
1637 break;
1638
1639 case wxOR_INVERT:
1640 lCRop = FM_MERGESRCNOT;
1641 break;
1642
1643 case wxAND:
1644 lCRop = FM_AND;
1645 break;
1646
1647 case wxOR:
1648 lCRop = FM_OR;
1649 break;
1650
1651 case wxAND_INVERT:
1652 lCRop = FM_SUBTRACT;
1653 break;
1654
1655 case wxEQUIV:
1656 case wxNAND:
1657 case wxCOPY:
1658 default:
1659 lCRop = FM_OVERPAINT;
1660 break;
1661 }
1662 ::GpiSetMix((HPS)hDC, lCRop);
1663 } // end of wxDC::SetRop
1664
1665 bool wxDC::StartDoc(
1666 const wxString& rsMessage
1667 )
1668 {
1669 // We might be previewing, so return TRUE to let it continue.
1670 return TRUE;
1671 } // end of wxDC::StartDoc
1672
1673 void wxDC::EndDoc()
1674 {
1675 } // end of wxDC::EndDoc
1676
1677 void wxDC::StartPage()
1678 {
1679 } // end of wxDC::StartPage
1680
1681 void wxDC::EndPage()
1682 {
1683 } // end of wxDC::EndPage
1684
1685 // ---------------------------------------------------------------------------
1686 // text metrics
1687 // ---------------------------------------------------------------------------
1688
1689 wxCoord wxDC::GetCharHeight() const
1690 {
1691 FONTMETRICS vFM; // metrics structure
1692
1693 ::GpiQueryFontMetrics( m_hPS
1694 ,sizeof(FONTMETRICS)
1695 ,&vFM
1696 );
1697 return YDEV2LOGREL(vFM.lXHeight);
1698 }
1699
1700 wxCoord wxDC::GetCharWidth() const
1701 {
1702 FONTMETRICS vFM; // metrics structure
1703
1704 ::GpiQueryFontMetrics( m_hPS
1705 ,sizeof(FONTMETRICS)
1706 ,&vFM
1707 );
1708 return XDEV2LOGREL(vFM.lAveCharWidth);
1709 }
1710
1711 void wxDC::DoGetTextExtent(
1712 const wxString& rsString
1713 , wxCoord* pvX
1714 , wxCoord* pvY
1715 , wxCoord* pvDescent
1716 , wxCoord* pvExternalLeading
1717 , wxFont* pTheFont
1718 ) const
1719 {
1720 POINTL avPoint[TXTBOX_COUNT];
1721 POINTL vPtMin;
1722 POINTL vPtMax;
1723 int i;
1724 int l;
1725 FONTMETRICS vFM; // metrics structure
1726 BOOL bRc;
1727 char* pStr;
1728 ERRORID vErrorCode; // last error id code
1729 wxFont* pFontToUse = (wxFont*)pTheFont;
1730
1731 char zMsg[128]; // DEBUG
1732 wxString sError;
1733
1734 if (!pFontToUse)
1735 pFontToUse = (wxFont*)&m_font;
1736 l = rsString.length();
1737 pStr = (PCH) rsString.c_str();
1738
1739 //
1740 // In world coordinates.
1741 //
1742 bRc = ::GpiQueryTextBox( m_hPS
1743 ,l
1744 ,pStr
1745 ,TXTBOX_COUNT // return maximum information
1746 ,avPoint // array of coordinates points
1747 );
1748 if(!bRc)
1749 {
1750 vErrorCode = ::WinGetLastError(wxGetInstance());
1751 sError = wxPMErrorToStr(vErrorCode);
1752 // DEBUG
1753 sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str());
1754 (void)wxMessageBox( "wxWindows Menu sample"
1755 ,zMsg
1756 ,wxICON_INFORMATION
1757 );
1758 }
1759
1760 vPtMin.x = avPoint[0].x;
1761 vPtMax.x = avPoint[0].x;
1762 vPtMin.y = avPoint[0].y;
1763 vPtMax.y = avPoint[0].y;
1764 for (i = 1; i < 4; i++)
1765 {
1766 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1767 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1768 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1769 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1770 }
1771 ::GpiQueryFontMetrics( m_hPS
1772 ,sizeof(FONTMETRICS)
1773 ,&vFM
1774 );
1775
1776 if (pvX)
1777 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1778 if (pvY)
1779 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1780 if (pvDescent)
1781 *pvDescent = vFM.lMaxDescender;
1782 if (pvExternalLeading)
1783 *pvExternalLeading = vFM.lExternalLeading;
1784 }
1785
1786 void wxDC::SetMapMode(
1787 int nMode
1788 )
1789 {
1790 int nPixelWidth = 0;
1791 int nPixelHeight = 0;
1792 int nMmWidth = 1;
1793 int nMmHeight = 1;
1794 LONG lArray[CAPS_VERTICAL_RESOLUTION];
1795
1796 m_mappingMode = nMode;
1797
1798 if(::DevQueryCaps( m_hDC
1799 ,CAPS_FAMILY
1800 ,CAPS_VERTICAL_RESOLUTION
1801 ,lArray
1802 ))
1803 {
1804 LONG lHorzRes;
1805 LONG lVertRes;
1806
1807 nPixelWidth = lArray[CAPS_WIDTH];
1808 nPixelHeight = lArray[CAPS_HEIGHT];
1809 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
1810 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
1811 nMmWidth = (lHorzRes/1000) * nPixelWidth;
1812 nMmWidth = (lVertRes/1000) * nPixelHeight;
1813 }
1814 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
1815 {
1816 return;
1817 }
1818
1819 double dMm2pixelsX = nPixelWidth/nMmWidth;
1820 double dMm2pixelsY = nPixelHeight/nMmHeight;
1821
1822 switch (nMode)
1823 {
1824 case wxMM_TWIPS:
1825 m_logicalScaleX = (twips2mm * dMm2pixelsX);
1826 m_logicalScaleY = (twips2mm * dMm2pixelsY);
1827 break;
1828
1829 case wxMM_POINTS:
1830 m_logicalScaleX = (pt2mm * dMm2pixelsX);
1831 m_logicalScaleY = (pt2mm * dMm2pixelsY);
1832 break;
1833
1834 case wxMM_METRIC:
1835 m_logicalScaleX = dMm2pixelsX;
1836 m_logicalScaleY = dMm2pixelsY;
1837 break;
1838
1839 case wxMM_LOMETRIC:
1840 m_logicalScaleX = (dMm2pixelsX/10.0);
1841 m_logicalScaleY = (dMm2pixelsY/10.0);
1842 break;
1843
1844 case wxMM_TEXT:
1845 default:
1846 m_logicalScaleX = 1.0;
1847 m_logicalScaleY = 1.0;
1848 break;
1849 }
1850 SIZEL vSize;
1851 ULONG ulOptions;
1852
1853 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
1854 if (!ulOptions & PU_ARBITRARY)
1855 {
1856 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
1857 ::GpiSetPS(m_hPS, &vSize, ulOptions);
1858 }
1859 m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
1860 m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
1861 // ????
1862 }; // end of wxDC::SetMapMode
1863
1864 void wxDC::SetUserScale(
1865 double dX
1866 , double dY
1867 )
1868 {
1869 m_userScaleX = dX;
1870 m_userScaleY = dY;
1871
1872 SetMapMode(m_mappingMode);
1873 } // end of wxDC::SetUserScale
1874
1875 void wxDC::SetAxisOrientation(
1876 bool bXLeftRight
1877 , bool bYBottomUp
1878 )
1879 {
1880 m_signX = bXLeftRight ? 1 : -1;
1881 m_signY = bYBottomUp ? -1 : 1;
1882
1883 SetMapMode(m_mappingMode);
1884 } // end of wxDC::SetAxisOrientation
1885
1886 void wxDC::SetSystemScale(
1887 double dX
1888 , double dY
1889 )
1890 {
1891 m_scaleX = dX;
1892 m_scaleY = dY;
1893
1894 SetMapMode(m_mappingMode);
1895 } // end of wxDC::SetSystemScale
1896
1897 void wxDC::SetLogicalOrigin(
1898 wxCoord vX
1899 , wxCoord vY
1900 )
1901 {
1902 RECTL vRect;
1903
1904 ::GpiQueryPageViewport( m_hPS
1905 ,&vRect
1906 );
1907 vRect.xRight -= vX;
1908 vRect.yTop += vY;
1909 vRect.xLeft = vX;
1910 vRect.yBottom = vY;
1911 ::GpiSetPageViewport( m_hPS
1912 ,&vRect
1913 );
1914 }; // end of wxDC::SetLogicalOrigin
1915
1916 void wxDC::SetDeviceOrigin(
1917 wxCoord vX
1918 , wxCoord vY
1919 )
1920 {
1921 RECTL vRect;
1922
1923 m_deviceOriginX = vX;
1924 m_deviceOriginY = vY;
1925 ::GpiQueryPageViewport( m_hPS
1926 ,&vRect
1927 );
1928 vRect.xLeft += vX;
1929 vRect.xRight += vX;
1930 vRect.yBottom -= vY;
1931 vRect.yTop -= vY;
1932 ::GpiSetPageViewport( m_hPS
1933 ,&vRect
1934 );
1935 }; // end of wxDC::SetDeviceOrigin
1936
1937 // ---------------------------------------------------------------------------
1938 // coordinates transformations
1939 // ---------------------------------------------------------------------------
1940
1941 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
1942 {
1943 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1944 }
1945
1946 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
1947 {
1948 // axis orientation is not taken into account for conversion of a distance
1949 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
1950 }
1951
1952 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
1953 {
1954 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
1955 }
1956
1957 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
1958 {
1959 // axis orientation is not taken into account for conversion of a distance
1960 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
1961 }
1962
1963 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
1964 {
1965 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
1966 }
1967
1968 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
1969 {
1970 // axis orientation is not taken into account for conversion of a distance
1971 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
1972 }
1973
1974 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
1975 {
1976 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
1977 }
1978
1979 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
1980 {
1981 // axis orientation is not taken into account for conversion of a distance
1982 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
1983 }
1984
1985 // ---------------------------------------------------------------------------
1986 // bit blit
1987 // ---------------------------------------------------------------------------
1988
1989 bool wxDC::DoBlit(
1990 wxCoord vXdest
1991 , wxCoord vYdest
1992 , wxCoord vWidth
1993 , wxCoord vHeight
1994 , wxDC* pSource
1995 , wxCoord vXsrc
1996 , wxCoord vYsrc
1997 , int nRop
1998 , bool bUseMask
1999 , wxCoord vXsrcMask
2000 , wxCoord vYsrcMask
2001 )
2002 {
2003 wxMask* pMask = NULL;
2004 CHARBUNDLE vCbnd;
2005 COLORREF vOldTextColor;
2006 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
2007
2008 if (bUseMask)
2009 {
2010 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
2011
2012 pMask = rBmp.GetMask();
2013 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
2014 {
2015 bUseMask = FALSE;
2016 }
2017 }
2018
2019 ::GpiQueryAttrs( m_hPS
2020 ,PRIM_CHAR
2021 ,CBB_COLOR
2022 ,&vCbnd
2023 );
2024 vOldTextColor = (COLORREF)vCbnd.lColor;
2025
2026 if (m_textForegroundColour.Ok())
2027 {
2028 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
2029 ::GpiSetAttrs( m_hPS // presentation-space handle
2030 ,PRIM_CHAR // Char primitive.
2031 ,CBB_COLOR // sets color.
2032 ,0
2033 ,&vCbnd // buffer for attributes.
2034 );
2035 }
2036 if (m_textBackgroundColour.Ok())
2037 {
2038 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
2039 }
2040
2041 LONG lRop = ROP_SRCCOPY;
2042
2043 switch (nRop)
2044 {
2045 case wxXOR: lRop = ROP_SRCINVERT; break;
2046 case wxINVERT: lRop = ROP_DSTINVERT; break;
2047 case wxOR_REVERSE: lRop = 0x00DD0228; break;
2048 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
2049 case wxCLEAR: lRop = ROP_ZERO; break;
2050 case wxSET: lRop = ROP_ONE; break;
2051 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
2052 case wxAND: lRop = ROP_SRCAND; break;
2053 case wxOR: lRop = ROP_SRCPAINT; break;
2054 case wxEQUIV: lRop = 0x00990066; break;
2055 case wxNAND: lRop = 0x007700E6; break;
2056 case wxAND_INVERT: lRop = 0x00220326; break;
2057 case wxCOPY: lRop = ROP_SRCCOPY; break;
2058 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
2059 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
2060 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
2061 default:
2062 wxFAIL_MSG( wxT("unsupported logical function") );
2063 return FALSE;
2064 }
2065
2066 bool bSuccess;
2067
2068 if (bUseMask)
2069 {
2070 //
2071 // Blit bitmap with mask
2072 //
2073
2074 //
2075 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
2076 //
2077 HDC hDCMask;
2078 HDC hDCBuffer;
2079 HPS hPSMask;
2080 HPS hPSBuffer;
2081 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
2082 BITMAPINFOHEADER2 vBmpHdr;
2083 HBITMAP hBufBitmap;
2084 SIZEL vSize = {0, 0};
2085 LONG rc;
2086
2087 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
2088 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
2089 vBmpHdr.cx = vWidth;
2090 vBmpHdr.cy = vHeight;
2091 vBmpHdr.cPlanes = 1;
2092 vBmpHdr.cBitCount = 24;
2093
2094 #if wxUSE_DC_CACHEING
2095 if (TRUE)
2096 {
2097 //
2098 // create a temp buffer bitmap and DCs to access it and the mask
2099 //
2100 wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
2101 ,pSource->GetHPS()
2102 );
2103 wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
2104 ,GetHPS()
2105 );
2106 wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
2107 ,vWidth
2108 ,vHeight
2109 );
2110
2111 hPSMask = pDCCacheEntry1->m_hPS;
2112 hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
2113 hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
2114 }
2115 else
2116 #endif
2117 {
2118 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2119 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2120 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2121 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2122 hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
2123 }
2124
2125 POINTL aPoint1[4] = { 0, 0
2126 ,vWidth, vHeight
2127 ,vXdest, vYdest
2128 ,vXdest + vWidth, vYdest + vHeight
2129 };
2130 POINTL aPoint2[4] = { 0, 0
2131 ,vWidth, vHeight
2132 ,vXsrc, vYsrc
2133 ,vXsrc + vWidth, vYsrc + vHeight
2134 };
2135 POINTL aPoint3[4] = { vXdest, vYdest
2136 ,vXdest + vWidth, vYdest + vHeight
2137 ,vXsrc, vYsrc
2138 ,vXsrc + vWidth, vYsrc + vHeight
2139 };
2140 POINTL aPoint4[4] = { vXdest, vYdest
2141 ,vXdest + vWidth, vYdest + vHeight
2142 ,0, 0
2143 ,vWidth, vHeight
2144 };
2145 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
2146 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
2147
2148 //
2149 // Copy dest to buffer
2150 //
2151 rc = ::GpiBitBlt( hPSBuffer
2152 ,GetHPS()
2153 ,4L
2154 ,aPoint1
2155 ,ROP_SRCCOPY
2156 ,BBO_IGNORE
2157 );
2158 if (rc == GPI_ERROR)
2159 {
2160 wxLogLastError(wxT("BitBlt"));
2161 }
2162
2163 //
2164 // Copy src to buffer using selected raster op
2165 //
2166 rc = ::GpiBitBlt( hPSBuffer
2167 ,GetHPS()
2168 ,4L
2169 ,aPoint2
2170 ,lRop
2171 ,BBO_IGNORE
2172 );
2173 if (rc == GPI_ERROR)
2174 {
2175 wxLogLastError(wxT("BitBlt"));
2176 }
2177
2178 //
2179 // Set masked area in buffer to BLACK (pixel value 0)
2180 //
2181 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
2182 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
2183
2184 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2185 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2186
2187 rc = ::GpiBitBlt( hPSBuffer
2188 ,hPSMask
2189 ,4L
2190 ,aPoint2
2191 ,ROP_SRCAND
2192 ,BBO_IGNORE
2193 );
2194 if (rc == GPI_ERROR)
2195 {
2196 wxLogLastError(wxT("BitBlt"));
2197 }
2198
2199 //
2200 // Set unmasked area in dest to BLACK
2201 //
2202 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2203 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2204 rc = ::GpiBitBlt( GetHPS()
2205 ,hPSMask
2206 ,4L
2207 ,aPoint3
2208 ,ROP_SRCAND
2209 ,BBO_IGNORE
2210 );
2211 if (rc == GPI_ERROR)
2212 {
2213 wxLogLastError(wxT("BitBlt"));
2214 }
2215
2216 //
2217 // Restore colours to original values
2218 //
2219 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
2220 ::GpiSetColor(GetHPS(), vPrevCol);
2221
2222 //
2223 // OR buffer to dest
2224 //
2225 rc = ::GpiBitBlt( GetHPS()
2226 ,hPSMask
2227 ,4L
2228 ,aPoint4
2229 ,ROP_SRCPAINT
2230 ,BBO_IGNORE
2231 );
2232 if (rc == GPI_ERROR)
2233 {
2234 bSuccess = FALSE;
2235 wxLogLastError(wxT("BitBlt"));
2236 }
2237
2238 //
2239 // Tidy up temporary DCs and bitmap
2240 //
2241 ::GpiSetBitmap(hPSMask, NULLHANDLE);
2242 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
2243 #if !wxUSE_DC_CACHEING
2244 ::GpiDestroyPS(hPSMask);
2245 ::GpiDestroyPS(hPSBuffer);
2246 ::DevCloseDC(hDCMask);
2247 ::DevCloseDC(hDCBuffer);
2248 ::GpiDeleteBitmap(hBufBitmap);
2249 #endif
2250 bSuccess = TRUE;
2251 }
2252 else // no mask, just BitBlt() it
2253 {
2254 POINTL aPoint[4] = { vXdest, vYdest
2255 ,vXdest + vWidth, vYdest + vHeight
2256 ,vXsrc, vYsrc
2257 ,vXsrc + vWidth, vYsrc + vHeight
2258 };
2259
2260 bSuccess = (::GpiBitBlt( m_hPS
2261 ,pSource->GetHPS()
2262 ,4L
2263 ,aPoint
2264 ,lRop
2265 ,BBO_IGNORE
2266 ) != GPI_ERROR);
2267 if (!bSuccess )
2268 {
2269 wxLogLastError(wxT("BitBlt"));
2270 }
2271 }
2272 vCbnd.lColor = (LONG)vOldTextColor;
2273 ::GpiSetAttrs( m_hPS // presentation-space handle
2274 ,PRIM_CHAR // Char primitive.
2275 ,CBB_COLOR // sets color.
2276 ,0
2277 ,&vCbnd // buffer for attributes.
2278 );
2279 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
2280 return bSuccess;
2281 }
2282
2283 void wxDC::DoGetSize(
2284 int* pnWidth
2285 , int* pnHeight
2286 ) const
2287 {
2288 LONG lArray[CAPS_HEIGHT];
2289
2290 if(::DevQueryCaps( m_hDC
2291 ,CAPS_FAMILY
2292 ,CAPS_HEIGHT
2293 ,lArray
2294 ))
2295 {
2296 *pnWidth = lArray[CAPS_WIDTH];
2297 *pnHeight = lArray[CAPS_HEIGHT];
2298 }
2299 }; // end of wxDC::DoGetSize(
2300
2301 void wxDC::DoGetSizeMM(
2302 int* pnWidth
2303 , int* pnHeight
2304 ) const
2305 {
2306 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2307
2308 if(::DevQueryCaps( m_hDC
2309 ,CAPS_FAMILY
2310 ,CAPS_VERTICAL_RESOLUTION
2311 ,lArray
2312 ))
2313 {
2314 int nWidth;
2315 int nHeight;
2316 int nHorzRes;
2317 int nVertRes;
2318
2319 nWidth = lArray[CAPS_WIDTH];
2320 nHeight = lArray[CAPS_HEIGHT];
2321 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2322 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2323 nWidth = (nHorzRes/1000) * nWidth;
2324 nHeight = (nVertRes/1000) * nHeight;
2325 }
2326 }; // end of wxDC::DoGetSizeMM
2327
2328 wxSize wxDC::GetPPI() const
2329 {
2330 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2331 int nWidth;
2332 int nHeight;
2333
2334 if(::DevQueryCaps( m_hDC
2335 ,CAPS_FAMILY
2336 ,CAPS_VERTICAL_RESOLUTION
2337 ,lArray
2338 ))
2339 {
2340 int nPelWidth;
2341 int nPelHeight;
2342 int nHorzRes;
2343 int nVertRes;
2344
2345 nPelWidth = lArray[CAPS_WIDTH];
2346 nPelHeight = lArray[CAPS_HEIGHT];
2347 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2348 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2349 nWidth = (nHorzRes/39.3) * nPelWidth;
2350 nHeight = (nVertRes/39.3) * nPelHeight;
2351 }
2352 return (wxSize(nWidth,nHeight));
2353 } // end of wxDC::GetPPI
2354
2355 void wxDC::SetLogicalScale(
2356 double dX
2357 , double dY
2358 )
2359 {
2360 m_logicalScaleX = dX;
2361 m_logicalScaleY = dY;
2362 }; // end of wxDC::SetLogicalScale
2363
2364 #if WXWIN_COMPATIBILITY
2365 void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
2366 float *descent, float *externalLeading,
2367 wxFont *theFont, bool use16bit) const
2368 {
2369 wxCoord x1, y1, descent1, externalLeading1;
2370 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
2371 *x = x1; *y = y1;
2372 if (descent)
2373 *descent = descent1;
2374 if (externalLeading)
2375 *externalLeading = externalLeading1;
2376 }
2377 #endif
2378