Filling out wxDC
[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 #endif
26
27 #include "wx/dcprint.h"
28
29 #include <string.h>
30 #include <math.h>
31
32 #include "wx/os2/private.h"
33
34 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
35
36 // ---------------------------------------------------------------------------
37 // constants
38 // ---------------------------------------------------------------------------
39
40 static const int VIEWPORT_EXTENT = 1000;
41
42 static const int MM_POINTS = 9;
43 static const int MM_METRIC = 10;
44
45 // usually this is defined in math.h
46 #ifndef M_PI
47 static const double M_PI = 3.14159265358979323846;
48 #endif // M_PI
49
50 // ---------------------------------------------------------------------------
51 // private functions
52 // ---------------------------------------------------------------------------
53
54 // convert degrees to radians
55 static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
56
57 int SetTextColor(
58 HPS hPS
59 , int nForegroundColour
60 )
61 {
62 CHARBUNDLE vCbnd;
63
64 vCbnd.lColor = nForegroundColour;
65 ::GpiSetAttrs( hPS // presentation-space handle
66 ,PRIM_CHAR // Char primitive.
67 ,CBB_COLOR // sets color.
68 ,0 //
69 ,&vCbnd // buffer for attributes.
70 );
71 return 0;
72 }
73
74 int QueryTextBkColor(
75 HPS hPS
76 )
77 {
78 CHARBUNDLE vCbnd;
79
80 ::GpiQueryAttrs( hPS // presentation-space handle
81 ,PRIM_CHAR // Char primitive.
82 ,CBB_BACK_COLOR // Background color.
83 ,&vCbnd // buffer for attributes.
84 );
85 return vCbnd.lBackColor;
86 }
87
88
89 int SetTextBkColor(
90 HPS hPS
91 , int nBackgroundColour
92 )
93 {
94 CHARBUNDLE vCbnd;
95 int rc;
96
97 rc = QueryTextBkColor(hPS);
98
99 vCbnd.lBackColor = nBackgroundColour;
100 ::GpiSetAttrs(hPS, // presentation-space handle
101 PRIM_CHAR, // Char primitive.
102 CBB_BACK_COLOR, // sets color.
103 0,
104 &vCbnd // buffer for attributes.
105 );
106 return rc;
107 }
108
109 int SetBkMode(
110 HPS hPS
111 , int nBackgroundMode
112 )
113 {
114 if(nBackgroundMode == wxTRANSPARENT)
115 ::GpiSetBackMix( hPS
116 ,BM_LEAVEALONE
117 );
118 else
119 // the background of the primitive takes over whatever is underneath.
120 ::GpiSetBackMix( hPS
121 ,BM_OVERPAINT
122 );
123 return 0;
124 }
125
126 // ===========================================================================
127 // implementation
128 // ===========================================================================
129
130 // ---------------------------------------------------------------------------
131 // wxDC
132 // ---------------------------------------------------------------------------
133
134 wxDC::wxDC(void)
135 {
136 m_pCanvas = NULL;
137
138 m_hOldBitmap = 0;
139 m_hOldPen = 0;
140 m_hOldBrush = 0;
141 m_hOldFont = 0;
142 m_hOldPalette = 0;
143
144 m_bOwnsDC = FALSE;
145 m_hDC = 0;
146 m_nDCCount = 0;
147 m_hOldPS = NULL;
148 m_hPS = NULL;
149 m_bIsPaintTime = FALSE; // True at Paint Time
150 m_brush.GetColour().Set("WHITE");
151 }
152
153 wxDC::~wxDC(void)
154 {
155 }
156
157 // This will select current objects out of the DC,
158 // which is what you have to do before deleting the
159 // DC.
160 void wxDC::SelectOldObjects(
161 WXHDC hPS
162 )
163 {
164 if (hPS)
165 {
166 if (m_hOldBitmap)
167 {
168 ::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap);
169 if (m_vSelectedBitmap.Ok())
170 {
171 m_vSelectedBitmap.SetSelectedInto(NULL);
172 }
173 }
174 m_hOldBitmap = 0;
175 //
176 // OS/2 has no other native GDI objects to set in a PS/DC like windows
177 //
178 m_hOldPen = 0;
179 m_hOldBrush = 0;
180 m_hOldFont = 0;
181 m_hOldPalette = 0;
182 }
183
184 m_brush = wxNullBrush;
185 m_pen = wxNullPen;
186 m_palette = wxNullPalette;
187 m_font = wxNullFont;
188 m_backgroundBrush = wxNullBrush;
189 m_vSelectedBitmap = wxNullBitmap;
190 }
191
192 // ---------------------------------------------------------------------------
193 // clipping
194 // ---------------------------------------------------------------------------
195
196 #define DO_SET_CLIPPING_BOX() \
197 { \
198 RECTL rect; \
199 \
200 ::GpiQueryClipBox(m_hPS, &rect); \
201 \
202 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
203 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
204 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
205 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
206 }
207
208 void wxDC::DoSetClippingRegion(
209 wxCoord x
210 , wxCoord y
211 , wxCoord width
212 , wxCoord height
213 )
214 {
215 RECTL vRect;
216
217 m_clipping = TRUE;
218 vRect.xLeft = XLOG2DEV(x);
219 vRect.yTop = YLOG2DEV(m_vRclPaint.yTop - y);
220 vRect.xRight = XLOG2DEV(x + width);
221 vRect.yBottom = YLOG2DEV(m_vRclPaint.yTop - (y + height));
222 ::GpiIntersectClipRectangle(m_hPS, &vRect);
223 DO_SET_CLIPPING_BOX()
224 } // end of wxDC::DoSetClippingRegion
225
226 void wxDC::DoSetClippingRegionAsRegion(
227 const wxRegion& rRegion
228 )
229 {
230 wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
231 HRGN hRgnOld;
232
233 m_clipping = TRUE;
234 ::GpiSetClipRegion( m_hPS
235 ,(HRGN)rRegion.GetHRGN()
236 ,&hRgnOld
237 );
238 DO_SET_CLIPPING_BOX()
239 } // end of wxDC::DoSetClippingRegionAsRegion
240
241 void wxDC::DestroyClippingRegion(void)
242 {
243 if (m_clipping && m_hPS)
244 {
245 HRGN hRgnOld;
246 RECTL vRect;
247
248 // TODO: this should restore the previous clipped region
249 // so that OnPaint processing works correctly, and
250 // the update doesn't get destroyed after the first
251 // DestroyClippingRegion
252 vRect.xLeft = XLOG2DEV(0);
253 vRect.yTop = YLOG2DEV(32000);
254 vRect.xRight = XLOG2DEV(32000);
255 vRect.yBottom = YLOG2DEV(0);
256
257 HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
258
259 ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
260 }
261 m_clipping = FALSE;
262 } // end of wxDC::DestroyClippingRegion
263
264 // ---------------------------------------------------------------------------
265 // query capabilities
266 // ---------------------------------------------------------------------------
267
268 bool wxDC::CanDrawBitmap() const
269 {
270 return TRUE;
271 }
272
273 bool wxDC::CanGetTextExtent() const
274 {
275 LONG lTechnology = 0L;
276
277 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology);
278 return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER);
279 } // end of wxDC::CanGetTextExtent
280
281 int wxDC::GetDepth() const
282 {
283 LONG lArray[CAPS_COLOR_BITCOUNT];
284 int nBitsPerPixel;
285
286 if(::DevQueryCaps( GetHDC()
287 ,CAPS_FAMILY
288 ,CAPS_COLOR_BITCOUNT
289 ,lArray
290 ))
291 {
292 nBitsPerPixel = (int)lArray[CAPS_COLOR_BITCOUNT];
293 }
294 return nBitsPerPixel;
295 } // end of wxDC::GetDepth
296
297 // ---------------------------------------------------------------------------
298 // drawing
299 // ---------------------------------------------------------------------------
300
301 void wxDC::Clear()
302 {
303 ::GpiErase(m_hPS);
304 }
305
306 void wxDC::DoFloodFill(
307 wxCoord vX
308 , wxCoord vY
309 , const wxColour& rCol
310 , int nStyle
311 )
312 {
313 POINTL vPtlPos;
314 LONG lColor;
315 LONG lOptions;
316
317 vPtlPos.x = vX; // Loads x-coordinate
318 vPtlPos.y = vY; // Loads y-coordinate
319 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
320 lColor = rCol.GetPixel();
321 lOptions = FF_BOUNDARY;
322 if(wxFLOOD_SURFACE == nStyle)
323 lOptions = FF_SURFACE;
324
325 ::GpiFloodFill(m_hPS, lOptions, lColor);
326 }
327
328 bool wxDC::DoGetPixel(
329 wxCoord vX
330 , wxCoord vY
331 , wxColour* pCol
332 ) const
333 {
334 POINTL vPoint;
335 LONG lColor;
336
337 vPoint.x = vX;
338 vPoint.y = vY;
339 lColor = ::GpiSetPel(m_hPS, &vPoint);
340 pCol->Set((unsigned long)lColor);
341 if(lColor>= 0)
342 return(TRUE);
343 else
344 return(FALSE);
345 }
346
347 void wxDC::DoCrossHair(
348 wxCoord vX
349 , wxCoord vY
350 )
351 {
352 wxCoord vX1 = vX - VIEWPORT_EXTENT;
353 wxCoord vY1 = vY - VIEWPORT_EXTENT;
354 wxCoord vX2 = vX + VIEWPORT_EXTENT;
355 wxCoord vY2 = vY + VIEWPORT_EXTENT;
356 POINTL vPoint[4];
357
358 vPoint[0].x = vX1;
359 vPoint[0].y = m_vRclPaint.yTop - vY;
360
361 vPoint[1].x = vX2;
362 vPoint[1].y = m_vRclPaint.yTop - vY;
363
364 ::GpiMove(m_hPS, &vPoint[0]);
365 ::GpiLine(m_hPS, &vPoint[1]);
366
367 vPoint[2].x = vX;
368 vPoint[2].y = m_vRclPaint.yTop - vY1;
369
370 vPoint[3].x = vX;
371 vPoint[3].y = m_vRclPaint.yTop - vY2;
372
373 ::GpiMove(m_hPS, &vPoint[2]);
374 ::GpiLine(m_hPS, &vPoint[3]);
375 } // end of wxDC::DoCrossHair
376
377 void wxDC::DoDrawLine(
378 wxCoord vX1
379 , wxCoord vY1
380 , wxCoord vX2
381 , wxCoord vY2
382 )
383 {
384 POINTL vPoint[2];
385
386 vPoint[0].x = vX1;
387 vPoint[0].y = m_vRclPaint.yTop - vY1;
388 vPoint[1].x = vX2;
389 vPoint[1].y = m_vRclPaint.yTop - vY2;
390 ::GpiMove(m_hPS, &vPoint[0]);
391 ::GpiLine(m_hPS, &vPoint[1]);
392 } // end of wxDC::DoDrawLine
393
394 //////////////////////////////////////////////////////////////////////////////
395 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
396 // and ending at (x2, y2). The current pen is used for the outline and the
397 // current brush for filling the shape. The arc is drawn in an anticlockwise
398 // direction from the start point to the end point.
399 //////////////////////////////////////////////////////////////////////////////
400 void wxDC::DoDrawArc(
401 wxCoord vX1
402 , wxCoord vY1
403 , wxCoord vX2
404 , wxCoord vY2
405 , wxCoord vXc
406 , wxCoord vYc
407 )
408 {
409 POINTL vPtlPos;
410 POINTL vPtlArc[2]; // Structure for current position
411 int nDx;
412 int nDy;
413 double dRadius;
414 double dAngl1;
415 double dAngl2;
416 double dAnglmid;
417 wxCoord vXm;
418 wxCoord vYm;
419 ARCPARAMS vArcp; // Structure for arc parameters
420
421 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
422 return; // Draw point ??
423 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
424 ,(double)(vX1 - vXc)
425 ) +
426 hypot( (double)(vY2 - vYc)
427 ,(double)(vX2 - vXc)
428 )
429 );
430
431 dAngl1 = atan2( (double)(vY1 - vYc)
432 ,(double)(vX1 - vXc)
433 );
434 dAngl2 = atan2( (double)(vY2 - vYc)
435 ,(double)(vX2 - vXc)
436 );
437 if(dAngl2 < dAngl1)
438 dAngl2 += M_PI * 2;
439
440 //
441 // GpiPointArc can't draw full arc
442 //
443 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
444 {
445 //
446 // Medium point
447 //
448 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
449 vXm = vXc + dRadius * cos(dAnglmid);
450 vYm = vYc + dRadius * sin(dAnglmid);
451 DoDrawArc( vX1, vY1
452 ,vXm, vYm
453 ,vXc, vYc
454 );
455 DoDrawArc( vXm, vYm
456 ,vX2, vY2
457 ,vXc, vYc
458 );
459 return;
460 }
461
462 //
463 // Medium point
464 //
465 dAnglmid = (dAngl1 + dAngl2)/2.;
466 vXm = vXc + dRadius * cos(dAnglmid);
467 vYm = vYc + dRadius * sin(dAnglmid);
468
469 //
470 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
471 //
472 vArcp.lR = 0;
473 vArcp.lQ = 1;
474 vArcp.lP = 1;
475 vArcp.lS = 0;
476 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
477
478 vPtlPos.x = vX1; // Loads x-coordinate
479 vPtlPos.y = vY1; // Loads y-coordinate
480 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
481 vPtlArc[0].x = vXm;
482 vPtlArc[0].y = vYm;
483 vPtlArc[1].x = vX2;
484 vPtlArc[1].y = vY2;
485 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
486 } // end of wxDC::DoDrawArc
487
488 void wxDC::DoDrawCheckMark(
489 wxCoord vX1
490 , wxCoord vY1
491 , wxCoord vWidth
492 , wxCoord vHeight
493 )
494 {
495 POINTL vPoint[2];
496
497 vPoint[0].x = vX1;
498 vPoint[0].y = vY1;
499 vPoint[1].x = vX1 + vWidth;
500 vPoint[1].y = vY1 + vHeight;
501
502 ::GpiMove(m_hPS, &vPoint[0]);
503 ::GpiBox( m_hPS // handle to a presentation space
504 ,DRO_OUTLINE // draw the box outline ? or ?
505 ,&vPoint[1] // address of the corner
506 ,0L // horizontal corner radius
507 ,0L // vertical corner radius
508 );
509 if(vWidth > 4 && vHeight > 4)
510 {
511 int nTmp;
512
513 vPoint[0].x += 2; vPoint[0].y += 2;
514 vPoint[1].x -= 2; vPoint[1].y -= 2;
515 ::GpiMove(m_hPS, &vPoint[0]);
516 ::GpiLine(m_hPS, &vPoint[1]);
517 nTmp = vPoint[0].x;
518 vPoint[0].x = vPoint[1].x;
519 vPoint[1].x = nTmp;
520 ::GpiMove(m_hPS, &vPoint[0]);
521 ::GpiLine(m_hPS, &vPoint[1]);
522 }
523 } // end of wxDC::DoDrawCheckMark
524
525 void wxDC::DoDrawPoint(
526 wxCoord vX
527 , wxCoord vY
528 )
529 {
530 POINTL vPoint;
531
532 vPoint.x = vX;
533 vPoint.y = m_vRclPaint.yTop - vY;
534 ::GpiSetPel(m_hPS, &vPoint);
535 } // end of wxDC::DoDrawPoint
536
537 void wxDC::DoDrawPolygon(
538 int n
539 , wxPoint vPoints[]
540 , wxCoord vXoffset
541 , wxCoord vYoffset
542 , int nFillStyle
543 )
544 {
545 ULONG ulCount = 1; // Number of polygons.
546 POLYGON vPlgn; // polygon.
547 ULONG flOptions = 0L; // Drawing options.
548
549 //////////////////////////////////////////////////////////////////////////////
550 // This contains fields of option bits... to draw boundary lines as well as
551 // the area interior.
552 //
553 // Drawing boundary lines:
554 // POLYGON_NOBOUNDARY Does not draw boundary lines.
555 // POLYGON_BOUNDARY Draws boundary lines (the default).
556 //
557 // Construction of the area interior:
558 // POLYGON_ALTERNATE Constructs interior in alternate mode
559 // (the default).
560 // POLYGON_WINDING Constructs interior in winding mode.
561 //////////////////////////////////////////////////////////////////////////////
562
563 ULONG flModel = 0L; // Drawing model.
564
565 //////////////////////////////////////////////////////////////////////////////
566 // Drawing model.
567 // POLYGON_INCL Fill is inclusive of bottom right (the default).
568 // POLYGON_EXCL Fill is exclusive of bottom right.
569 // This is provided to aid migration from other graphics models.
570 //////////////////////////////////////////////////////////////////////////////
571
572 LONG lHits = 0L; // Correlation/error indicator.
573 POINTL vPoint;
574 int i;
575 int nIsTRANSPARENT = 0;
576 LONG lBorderColor = 0L;
577 LONG lColor = 0L;
578
579 lBorderColor = m_pen.GetColour().GetPixel();
580 lColor = m_brush.GetColour().GetPixel();
581 if(m_brush.GetStyle() == wxTRANSPARENT)
582 nIsTRANSPARENT = 1;
583
584 vPlgn.ulPoints = n;
585 vPlgn.aPointl = (POINTL*) calloc( n + 1
586 ,sizeof(POINTL)
587 ); // well, new will call malloc
588
589 for(i = 0; i < n; i++)
590 {
591 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
592 vPlgn.aPointl[i].y = vPoints[i].y; // +yoffset;
593 }
594 flModel = POLYGON_BOUNDARY;
595 if(nFillStyle == wxWINDING_RULE)
596 flModel |= POLYGON_WINDING;
597 else
598 flModel |= POLYGON_ALTERNATE;
599
600 vPoint.x = vXoffset;
601 vPoint.y = vYoffset;
602
603 ::GpiSetColor(m_hPS, lBorderColor);
604 ::GpiMove(m_hPS, &vPoint);
605 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
606 free(vPlgn.aPointl);
607 } // end of wxDC::DoDrawPolygon
608
609 void wxDC::DoDrawLines(
610 int n
611 , wxPoint vPoints[]
612 , wxCoord vXoffset
613 , wxCoord vYoffset
614 )
615 {
616 int i;
617 POINTL vPoint;
618
619 vPoint.x = vPoints[0].x + vXoffset;
620 vPoint.y = vPoints[0].y + vYoffset;
621 ::GpiMove(m_hPS, &vPoint);
622
623 LONG lBorderColor = m_pen.GetColour().GetPixel();
624
625 ::GpiSetColor(m_hPS, lBorderColor);
626 for(i = 1; i < n; i++)
627 {
628 vPoint.x = vPoints[0].x + vXoffset;
629 vPoint.y = vPoints[0].y + vYoffset;
630 ::GpiLine(m_hPS, &vPoint);
631 }
632 } // end of wxDC::DoDrawLines
633
634 void wxDC::DoDrawRectangle(
635 wxCoord vX
636 , wxCoord vY
637 , wxCoord vWidth
638 , wxCoord vHeight
639 )
640 {
641 POINTL vPoint[2];
642 LONG lControl;
643 LONG lColor;
644 LONG lBorderColor;
645 int nIsTRANSPARENT = 0;
646
647 vPoint[0].x = vX;
648 vPoint[0].y = m_vRclPaint.yTop - (vY + vHeight);
649 vPoint[1].x = vX + vWidth;
650 vPoint[1].y = m_vRclPaint.yTop - vY;
651 ::GpiMove(m_hPS, &vPoint[0]);
652 lColor = m_brush.GetColour().GetPixel();
653 lBorderColor = m_pen.GetColour().GetPixel();
654 if (m_brush.GetStyle() == wxTRANSPARENT)
655 nIsTRANSPARENT = 1;
656 if(lColor == lBorderColor || nIsTRANSPARENT)
657 {
658 lControl = DRO_OUTLINEFILL; //DRO_FILL;
659 if(m_brush.GetStyle() == wxTRANSPARENT)
660 lControl = DRO_OUTLINE;
661
662 ::GpiSetColor(m_hPS, lColor);
663 ::GpiBox( m_hPS // handle to a presentation space
664 ,lControl // draw the box outline ? or ?
665 ,&vPoint[1] // address of the corner
666 ,0L // horizontal corner radius
667 ,0L // vertical corner radius
668 );
669 }
670 else
671 {
672 lControl = DRO_OUTLINE;
673 ::GpiSetColor( m_hPS
674 ,lBorderColor
675 );
676 ::GpiBox( m_hPS
677 ,lControl
678 ,&vPoint[1]
679 ,0L
680 ,0L
681 );
682 lControl = DRO_FILL;
683 ::GpiSetColor( m_hPS
684 ,lColor
685 );
686 vPoint[0].x = vX + 1;
687 vPoint[0].y = m_vRclPaint.yTop - (vY + vHeight) + 1;
688 vPoint[1].x = vX + vWidth - 2;
689 vPoint[1].y = m_vRclPaint.yTop - (vY + 2);
690 ::GpiMove(m_hPS, &vPoint[0]);
691 ::GpiBox( m_hPS
692 ,lControl
693 ,&vPoint[1]
694 ,0L
695 ,0L
696 );
697 }
698 } // end of wxDC::DoDrawRectangle
699
700 void wxDC::DoDrawRoundedRectangle(
701 wxCoord vX
702 , wxCoord vY
703 , wxCoord vWidth
704 , wxCoord vHeight
705 , double dRadius
706 )
707 {
708 POINTL vPoint[2];
709 LONG lControl;
710
711 vPoint[0].x = vX;
712 vPoint[0].y = YLOG2DEV(vY) - vHeight;
713 vPoint[1].x = vX + vWidth;
714 vPoint[1].y = vY;
715 ::GpiMove(m_hPS, &vPoint[0]);
716
717 lControl = DRO_OUTLINEFILL; //DRO_FILL;
718 if (m_brush.GetStyle() == wxTRANSPARENT)
719 lControl = DRO_OUTLINE;
720 ::GpiBox( m_hPS // handle to a presentation space
721 ,DRO_OUTLINE // draw the box outline ? or ?
722 ,&vPoint[1] // address of the corner
723 ,(LONG)dRadius // horizontal corner radius
724 ,(LONG)dRadius // vertical corner radius
725 );
726 } // end of wxDC::DoDrawRoundedRectangle
727
728 // Draw Ellipse within box (x,y) - (x+width, y+height)
729 void wxDC::DoDrawEllipse(
730 wxCoord vX
731 , wxCoord vY
732 , wxCoord vWidth
733 , wxCoord vHeight
734 )
735 {
736 POINTL vPtlPos; // Structure for current position
737 FIXED vFxMult; // Multiplier for ellipse
738 ARCPARAMS vArcp; // Structure for arc parameters
739
740 vArcp.lR = 0;
741 vArcp.lQ = vHeight/2;
742 vArcp.lP = vWidth/2;
743 vArcp.lS = 0;
744 ::GpiSetArcParams( m_hPS
745 ,&vArcp
746 ); // Sets parameters to default
747 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
748 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
749 ::GpiMove( m_hPS
750 ,&vPtlPos
751 ); // Sets current position
752 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
753
754 //
755 // DRO_FILL, DRO_OTLINEFILL - where to get
756 //
757 ::GpiFullArc( m_hPS
758 ,DRO_OUTLINE
759 ,vFxMult
760 ); // Draws full arc with center at current position
761 } // end of wxDC::DoDrawEllipse
762
763 void wxDC::DoDrawEllipticArc(
764 wxCoord vX
765 , wxCoord vY
766 , wxCoord vWidth
767 , wxCoord vHeight
768 , double dSa
769 , double dEa
770 )
771 {
772 POINTL vPtlPos; // Structure for current position
773 FIXED vFxMult; // Multiplier for ellipse
774 ARCPARAMS vArcp; // Structure for arc parameters
775 FIXED vFSa;
776 FIXED vFSweepa; // Start angle, sweep angle
777 double dIntPart;
778 double dFractPart;
779 double dRadius;
780
781 dFractPart = modf(dSa,&dIntPart);
782 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
783 dFractPart = modf(dEa - dSa, &dIntPart);
784 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
785
786 //
787 // Ellipse main axis (r,q), (p,s) with center at (0,0)
788 //
789 vArcp.lR = 0;
790 vArcp.lQ = vHeight/2;
791 vArcp.lP = vWidth/2;
792 vArcp.lS = 0;
793 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
794 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
795 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
796 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
797
798 //
799 // May be not to the center ?
800 //
801 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
802 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
803 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
804
805 //
806 // DRO_FILL, DRO_OTLINEFILL - where to get
807 //
808 ::GpiPartialArc( m_hPS
809 ,&vPtlPos
810 ,vFxMult
811 ,vFSa
812 ,vFSweepa
813 );
814 } // end of wxDC::DoDrawEllipticArc
815
816 void wxDC::DoDrawIcon(
817 const wxIcon& rIcon
818 , wxCoord vX
819 , wxCoord vY
820 )
821 {
822 wxCHECK_RET( rIcon.Ok(), wxT("invalid icon in DrawIcon") );
823
824 ::WinDrawPointer( GetHPS()
825 ,vX
826 ,vY
827 ,(HPOINTER)GetHiconOf(rIcon)
828 ,DP_NORMAL
829 );
830 } // end of wxDC::DoDrawIcon
831
832 void wxDC::DoDrawBitmap(
833 const wxBitmap& rBmp
834 , wxCoord vX
835 , wxCoord vY
836 , bool bUseMask
837 )
838 {
839 POINTL vPoint = {vX, vY};
840
841 ::WinDrawBitmap( GetHPS()
842 ,(HBITMAP)GetHbitmapOf(rBmp)
843 ,NULL
844 ,&vPoint
845 ,0L
846 ,0L
847 ,DBM_NORMAL
848 );
849 } // end of wxDC::DoDrawBitmap
850
851 void wxDC::DoDrawText(
852 const wxString& rsText
853 , wxCoord vX
854 , wxCoord vY
855 )
856 {
857 DrawAnyText( rsText
858 ,vX
859 ,vY
860 );
861 }
862
863 void wxDC::DrawAnyText(
864 const wxString& rsText
865 , wxCoord vX
866 , wxCoord vY
867 )
868 {
869 int nOldBackground = 0;
870 POINTL vPtlStart;
871 LONG lHits;
872
873 //
874 // prepare for drawing the text
875 //
876
877 //
878 // Set text color attributes
879 //
880 if (m_textForegroundColour.Ok())
881 {
882 SetTextColor( m_hPS
883 ,(int)m_textForegroundColour.GetPixel()
884 );
885 }
886
887 if (m_textBackgroundColour.Ok())
888 {
889 nOldBackground = SetTextBkColor( m_hPS
890 ,(int)m_textBackgroundColour.GetPixel()
891 );
892 }
893 SetBkMode( m_hPS
894 ,m_backgroundMode
895 );
896 vPtlStart.x = vX;
897 vPtlStart.y = vY;
898
899 lHits = ::GpiCharStringAt( m_hPS
900 ,&vPtlStart
901 ,rsText.length()
902 ,(PCH)rsText.c_str()
903 );
904 if (lHits != GPI_OK)
905 {
906 wxLogLastError(wxT("TextOut"));
907 }
908
909 //
910 // Restore the old parameters (text foreground colour may be left because
911 // it never is set to anything else, but background should remain
912 // transparent even if we just drew an opaque string)
913 //
914 if (m_textBackgroundColour.Ok())
915 SetTextBkColor( m_hPS
916 ,nOldBackground
917 );
918 SetBkMode( m_hPS
919 ,wxTRANSPARENT
920 );
921 }
922
923 void wxDC::DoDrawRotatedText(
924 const wxString& rsText
925 , wxCoord vX
926 , wxCoord vY
927 , double dAngle
928 )
929 {
930 if (dAngle == 0.0)
931 {
932 DoDrawText( rsText
933 ,vX
934 ,vY
935 );
936 }
937
938 // TODO:
939 /*
940 if ( angle == 0.0 )
941 {
942 DoDrawText(text, x, y);
943 }
944 else
945 {
946 LOGFONT lf;
947 wxFillLogFont(&lf, &m_font);
948
949 // GDI wants the angle in tenth of degree
950 long angle10 = (long)(angle * 10);
951 lf.lfEscapement = angle10;
952 lf. lfOrientation = angle10;
953
954 HFONT hfont = ::CreateFontIndirect(&lf);
955 if ( !hfont )
956 {
957 wxLogLastError("CreateFont");
958 }
959 else
960 {
961 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
962
963 DrawAnyText(text, x, y);
964
965 (void)::SelectObject(GetHdc(), hfontOld);
966 }
967
968 // call the bounding box by adding all four vertices of the rectangle
969 // containing the text to it (simpler and probably not slower than
970 // determining which of them is really topmost/leftmost/...)
971 wxCoord w, h;
972 GetTextExtent(text, &w, &h);
973
974 double rad = DegToRad(angle);
975
976 // "upper left" and "upper right"
977 CalcBoundingBox(x, y);
978 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
979 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
980
981 // "bottom left" and "bottom right"
982 x += (wxCoord)(h*sin(rad));
983 y += (wxCoord)(h*cos(rad));
984 CalcBoundingBox(x, y);
985 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
986 }
987 */
988 }
989
990 // ---------------------------------------------------------------------------
991 // set GDI objects
992 // ---------------------------------------------------------------------------
993
994 void wxDC::SetPalette(const wxPalette& palette)
995 {
996 // TODO
997 }
998
999 void wxDC::SetFont(
1000 const wxFont& rFont
1001 )
1002 {
1003 //
1004 // Set the old object temporarily, in case the assignment deletes an object
1005 // that's not yet selected out.
1006 //
1007 if (m_hOldFont)
1008 {
1009 m_hOldFont = 0;
1010 }
1011 m_font = rFont;
1012 if (!rFont.Ok())
1013 {
1014 m_hOldFont = 0;
1015 }
1016
1017 m_font.SetPS(m_hPS); // this will realize the font
1018
1019 if (m_font.Ok())
1020 {
1021 HFONT hFont = m_font.GetResourceHandle();
1022 if (hFont == (HFONT) NULL)
1023 {
1024 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1025 }
1026 if (!m_hOldFont)
1027 m_hOldFont = (WXHFONT) hFont;
1028 }
1029 } // end of wxDC::SetFont
1030
1031 void wxDC::SetPen(
1032 const wxPen& rPen
1033 )
1034 {
1035 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1036
1037 if (m_pen == rPen)
1038 return;
1039 m_pen = rPen;
1040 if (!m_pen.Ok())
1041 return;
1042
1043 if (m_hOldPen)
1044 m_hOldPen = 0L;
1045 m_pen = rPen;
1046
1047 if (!m_pen.Ok())
1048 {
1049 if (m_hOldPen)
1050 {
1051 m_pen.SetPS((HPS)m_hOldPen);
1052 }
1053 m_hOldPen = 0L;
1054 }
1055
1056 if (m_pen.Ok())
1057 {
1058 if (m_pen.GetResourceHandle())
1059 {
1060 m_pen.SetPS(m_hPS);
1061 if (!m_hOldPen)
1062 m_hOldPen = m_pen.GetPS();
1063 }
1064 }
1065 }
1066
1067 void wxDC::SetBrush(
1068 const wxBrush& rBrush
1069 )
1070 {
1071 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1072
1073 if (m_brush == rBrush)
1074 return;
1075 m_brush = rBrush;
1076 if (!m_brush.Ok())
1077 return;
1078
1079 if (m_hOldBrush)
1080 m_hOldBrush = 0L;
1081 m_brush = rBrush;
1082
1083 if (!m_brush.Ok())
1084 {
1085 if (m_hOldBrush)
1086 {
1087 m_brush.SetPS((HPS)m_hOldBrush);
1088 }
1089 m_hOldBrush = 0L;
1090 }
1091
1092 if (m_brush.Ok())
1093 {
1094 if (m_brush.GetResourceHandle())
1095 {
1096 m_brush.SetPS(m_hPS);
1097 if (!m_hOldBrush)
1098 m_hOldBrush = m_brush.GetPS();
1099 }
1100 }
1101 } // end of wxDC::SetBrush
1102
1103 void wxDC::SetBackground(const wxBrush& brush)
1104 {
1105 // TODO
1106 }
1107
1108 void wxDC::SetBackgroundMode(
1109 int nMode
1110 )
1111 {
1112 m_backgroundMode = nMode;
1113 }
1114
1115 void wxDC::SetLogicalFunction(int function)
1116 {
1117 // TODO
1118 }
1119
1120 void wxDC::SetRop(WXHDC dc)
1121 {
1122 if (!dc || m_logicalFunction < 0)
1123 return;
1124
1125 int c_rop;
1126 // These may be wrong
1127 switch (m_logicalFunction)
1128 {
1129 // TODO: Figure this stuff out
1130 // case wxXOR: c_rop = R2_XORPEN; break;
1131 // case wxXOR: c_rop = R2_NOTXORPEN; break;
1132 // case wxINVERT: c_rop = R2_NOT; break;
1133 // case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break;
1134 // case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break;
1135 // case wxCLEAR: c_rop = R2_WHITE; break;
1136 // case wxSET: c_rop = R2_BLACK; break;
1137 // case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break;
1138 // case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break;
1139 // case wxAND: c_rop = R2_MASKPEN; break;
1140 // case wxOR: c_rop = R2_MERGEPEN; break;
1141 // case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break;
1142 // case wxEQUIV:
1143 // case wxNAND:
1144 // case wxCOPY:
1145 default:
1146 // c_rop = R2_COPYPEN;
1147 break;
1148 }
1149 // SetROP2((HDC) dc, c_rop);
1150 }
1151
1152 bool wxDC::StartDoc(const wxString& message)
1153 {
1154 // We might be previewing, so return TRUE to let it continue.
1155 return TRUE;
1156 }
1157
1158 void wxDC::EndDoc()
1159 {
1160 }
1161
1162 void wxDC::StartPage()
1163 {
1164 }
1165
1166 void wxDC::EndPage()
1167 {
1168 }
1169
1170 // ---------------------------------------------------------------------------
1171 // text metrics
1172 // ---------------------------------------------------------------------------
1173
1174 wxCoord wxDC::GetCharHeight() const
1175 {
1176 FONTMETRICS vFM; // metrics structure
1177
1178 ::GpiQueryFontMetrics( m_hPS
1179 ,sizeof(FONTMETRICS)
1180 ,&vFM
1181 );
1182 return YDEV2LOGREL(vFM.lXHeight);
1183 }
1184
1185 wxCoord wxDC::GetCharWidth() const
1186 {
1187 FONTMETRICS vFM; // metrics structure
1188
1189 ::GpiQueryFontMetrics( m_hPS
1190 ,sizeof(FONTMETRICS)
1191 ,&vFM
1192 );
1193 return XDEV2LOGREL(vFM.lAveCharWidth);
1194 }
1195
1196 void wxDC::DoGetTextExtent(
1197 const wxString& rsString
1198 , wxCoord* pvX
1199 , wxCoord* pvY
1200 , wxCoord* pvDescent
1201 , wxCoord* pvExternalLeading
1202 , wxFont* pTheFont
1203 ) const
1204 {
1205 POINTL avPoint[TXTBOX_COUNT];
1206 POINTL vPtMin;
1207 POINTL vPtMax;
1208 int i;
1209 int l;
1210 FONTMETRICS vFM; // metrics structure
1211 BOOL bRc;
1212 char* pStr;
1213 ERRORID vErrorCode; // last error id code
1214 wxFont* pFontToUse = (wxFont*)pTheFont;
1215
1216 char zMsg[128]; // DEBUG
1217 wxString sError;
1218
1219 if (!pFontToUse)
1220 pFontToUse = (wxFont*)&m_font;
1221 l = rsString.length();
1222 pStr = (PCH) rsString.c_str();
1223
1224 //
1225 // In world coordinates.
1226 //
1227 bRc = ::GpiQueryTextBox( m_hPS
1228 ,l
1229 ,pStr
1230 ,TXTBOX_COUNT // return maximum information
1231 ,avPoint // array of coordinates points
1232 );
1233 if(!bRc)
1234 {
1235 vErrorCode = ::WinGetLastError(wxGetInstance());
1236 sError = wxPMErrorToStr(vErrorCode);
1237 // DEBUG
1238 sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str());
1239 (void)wxMessageBox( "wxWindows Menu sample"
1240 ,zMsg
1241 ,wxICON_INFORMATION
1242 );
1243 }
1244
1245 vPtMin.x = avPoint[0].x;
1246 vPtMax.x = avPoint[0].x;
1247 vPtMin.y = avPoint[0].y;
1248 vPtMax.y = avPoint[0].y;
1249 for (i = 1; i < 4; i++)
1250 {
1251 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1252 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1253 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1254 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1255 }
1256 ::GpiQueryFontMetrics( m_hPS
1257 ,sizeof(FONTMETRICS)
1258 ,&vFM
1259 );
1260
1261 if (pvX)
1262 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1263 if (pvY)
1264 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1265 if (pvDescent)
1266 *pvDescent = vFM.lMaxDescender;
1267 if (pvExternalLeading)
1268 *pvExternalLeading = vFM.lExternalLeading;
1269 }
1270
1271 void wxDC::SetMapMode( int mode )
1272 {
1273 // TODO:
1274 };
1275
1276 void wxDC::SetUserScale(double x, double y)
1277 {
1278 m_userScaleX = x;
1279 m_userScaleY = y;
1280
1281 SetMapMode(m_mappingMode);
1282 }
1283
1284 void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1285 {
1286 m_signX = xLeftRight ? 1 : -1;
1287 m_signY = yBottomUp ? -1 : 1;
1288
1289 SetMapMode(m_mappingMode);
1290 }
1291
1292 void wxDC::SetSystemScale(double x, double y)
1293 {
1294 m_scaleX = x;
1295 m_scaleY = y;
1296
1297 SetMapMode(m_mappingMode);
1298 }
1299
1300 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
1301 {
1302 // TODO:
1303 };
1304
1305 void wxDC::SetDeviceOrigin(
1306 wxCoord x
1307 , wxCoord y
1308 )
1309 {
1310 RECTL vRect;
1311
1312 m_deviceOriginX = x;
1313 m_deviceOriginY = y;
1314 ::GpiQueryPageViewport( m_hPS
1315 ,&vRect
1316 );
1317 vRect.xLeft += x;
1318 vRect.xRight += x;
1319 vRect.yBottom -= y;
1320 vRect.yTop -= y;
1321 ::GpiSetPageViewport( m_hPS
1322 ,&vRect
1323 );
1324 };
1325
1326 // ---------------------------------------------------------------------------
1327 // coordinates transformations
1328 // ---------------------------------------------------------------------------
1329
1330 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
1331 {
1332 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1333 }
1334
1335 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
1336 {
1337 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX));
1338 }
1339
1340 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
1341 {
1342 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
1343 }
1344
1345 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
1346 {
1347 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY));
1348 }
1349
1350 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
1351 {
1352 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
1353 }
1354
1355 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
1356 {
1357 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX);
1358 }
1359
1360 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
1361 {
1362 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
1363 }
1364
1365 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
1366 {
1367 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY);
1368 }
1369
1370 // ---------------------------------------------------------------------------
1371 // bit blit
1372 // ---------------------------------------------------------------------------
1373
1374 bool wxDC::DoBlit(
1375 wxCoord vXdest
1376 , wxCoord vYdest
1377 , wxCoord vWidth
1378 , wxCoord vHeight
1379 , wxDC* pSource
1380 , wxCoord vXsrc
1381 , wxCoord vYsrc
1382 , int nRop
1383 , bool bUseMask
1384 )
1385 {
1386 wxMask* pMask = NULL;
1387 CHARBUNDLE vCbnd;
1388 COLORREF vOldTextColor;
1389 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
1390
1391 if (bUseMask)
1392 {
1393 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
1394
1395 pMask = rBmp.GetMask();
1396 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
1397 {
1398 bUseMask = FALSE;
1399 }
1400 }
1401
1402 ::GpiQueryAttrs( m_hPS
1403 ,PRIM_CHAR
1404 ,CBB_COLOR
1405 ,&vCbnd
1406 );
1407 vOldTextColor = (COLORREF)vCbnd.lColor;
1408
1409 if (m_textForegroundColour.Ok())
1410 {
1411 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
1412 ::GpiSetAttrs( m_hPS // presentation-space handle
1413 ,PRIM_CHAR // Char primitive.
1414 ,CBB_COLOR // sets color.
1415 ,0
1416 ,&vCbnd // buffer for attributes.
1417 );
1418 }
1419 if (m_textBackgroundColour.Ok())
1420 {
1421 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
1422 }
1423
1424 LONG lRop = ROP_SRCCOPY;
1425
1426 switch (nRop)
1427 {
1428 case wxXOR: lRop = ROP_SRCINVERT; break;
1429 case wxINVERT: lRop = ROP_DSTINVERT; break;
1430 case wxOR_REVERSE: lRop = 0x00DD0228; break;
1431 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
1432 case wxCLEAR: lRop = ROP_ZERO; break;
1433 case wxSET: lRop = ROP_ONE; break;
1434 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
1435 case wxAND: lRop = ROP_SRCAND; break;
1436 case wxOR: lRop = ROP_SRCPAINT; break;
1437 case wxEQUIV: lRop = 0x00990066; break;
1438 case wxNAND: lRop = 0x007700E6; break;
1439 case wxAND_INVERT: lRop = 0x00220326; break;
1440 case wxCOPY: lRop = ROP_SRCCOPY; break;
1441 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
1442 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
1443 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
1444 default:
1445 wxFAIL_MSG( wxT("unsupported logical function") );
1446 return FALSE;
1447 }
1448
1449 bool bSuccess;
1450
1451 if (bUseMask)
1452 {
1453 //
1454 // Blit bitmap with mask
1455 //
1456
1457 //
1458 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
1459 //
1460 HDC hDCMask;
1461 HDC hDCBuffer;
1462 HPS hPSMask;
1463 HPS hPSBuffer;
1464 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1465 BITMAPINFOHEADER2 vBmpHdr;
1466 SIZEL vSize = {0, 0};
1467 LONG rc;
1468
1469 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
1470 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
1471 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
1472 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
1473
1474 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
1475 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
1476 vBmpHdr.cx = vWidth;
1477 vBmpHdr.cy = vHeight;
1478 vBmpHdr.cPlanes = 1;
1479 vBmpHdr.cBitCount = 24;
1480
1481 HBITMAP hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
1482 POINTL aPoint1[4] = { 0, 0
1483 ,vWidth, vHeight
1484 ,vXdest, vYdest
1485 ,vXdest + vWidth, vYdest + vHeight
1486 };
1487 POINTL aPoint2[4] = { 0, 0
1488 ,vWidth, vHeight
1489 ,vXsrc, vYsrc
1490 ,vXsrc + vWidth, vYsrc + vHeight
1491 };
1492 POINTL aPoint3[4] = { vXdest, vYdest
1493 ,vXdest + vWidth, vYdest + vHeight
1494 ,vXsrc, vYsrc
1495 ,vXsrc + vWidth, vYsrc + vHeight
1496 };
1497 POINTL aPoint4[4] = { vXdest, vYdest
1498 ,vXdest + vWidth, vYdest + vHeight
1499 ,0, 0
1500 ,vWidth, vHeight
1501 };
1502 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
1503 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
1504
1505 //
1506 // Copy dest to buffer
1507 //
1508 rc = ::GpiBitBlt( hPSBuffer
1509 ,GetHPS()
1510 ,4L
1511 ,aPoint1
1512 ,ROP_SRCCOPY
1513 ,BBO_IGNORE
1514 );
1515 if (rc == GPI_ERROR)
1516 {
1517 wxLogLastError(wxT("BitBlt"));
1518 }
1519
1520 //
1521 // Copy src to buffer using selected raster op
1522 //
1523 rc = ::GpiBitBlt( hPSBuffer
1524 ,GetHPS()
1525 ,4L
1526 ,aPoint2
1527 ,lRop
1528 ,BBO_IGNORE
1529 );
1530 if (rc == GPI_ERROR)
1531 {
1532 wxLogLastError(wxT("BitBlt"));
1533 }
1534
1535 //
1536 // Set masked area in buffer to BLACK (pixel value 0)
1537 //
1538 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
1539 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
1540
1541 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
1542 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
1543
1544 rc = ::GpiBitBlt( hPSBuffer
1545 ,hPSMask
1546 ,4L
1547 ,aPoint2
1548 ,ROP_SRCAND
1549 ,BBO_IGNORE
1550 );
1551 if (rc == GPI_ERROR)
1552 {
1553 wxLogLastError(wxT("BitBlt"));
1554 }
1555
1556 //
1557 // Set unmasked area in dest to BLACK
1558 //
1559 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
1560 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
1561 rc = ::GpiBitBlt( GetHPS()
1562 ,hPSMask
1563 ,4L
1564 ,aPoint3
1565 ,ROP_SRCAND
1566 ,BBO_IGNORE
1567 );
1568 if (rc == GPI_ERROR)
1569 {
1570 wxLogLastError(wxT("BitBlt"));
1571 }
1572
1573 //
1574 // Restore colours to original values
1575 //
1576 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
1577 ::GpiSetColor(GetHPS(), vPrevCol);
1578
1579 //
1580 // OR buffer to dest
1581 //
1582 rc = ::GpiBitBlt( GetHPS()
1583 ,hPSMask
1584 ,4L
1585 ,aPoint4
1586 ,ROP_SRCPAINT
1587 ,BBO_IGNORE
1588 );
1589 if (rc == GPI_ERROR)
1590 {
1591 bSuccess = FALSE;
1592 wxLogLastError(wxT("BitBlt"));
1593 }
1594
1595 //
1596 // Tidy up temporary DCs and bitmap
1597 //
1598 ::GpiSetBitmap(hPSMask, NULLHANDLE);
1599 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
1600 ::GpiDestroyPS(hPSMask);
1601 ::GpiDestroyPS(hPSBuffer);
1602 ::DevCloseDC(hDCMask);
1603 ::DevCloseDC(hDCBuffer);
1604 ::GpiDeleteBitmap(hBufBitmap);
1605 bSuccess = TRUE;
1606 }
1607 else // no mask, just BitBlt() it
1608 {
1609 POINTL aPoint[4] = { vXdest, vYdest
1610 ,vXdest + vWidth, vYdest + vHeight
1611 ,vXsrc, vYsrc
1612 ,vXsrc + vWidth, vYsrc + vHeight
1613 };
1614
1615 bSuccess = (::GpiBitBlt( m_hPS
1616 ,pSource->GetHPS()
1617 ,4L
1618 ,aPoint
1619 ,lRop
1620 ,BBO_IGNORE
1621 ) != GPI_ERROR);
1622 if (!bSuccess )
1623 {
1624 wxLogLastError(wxT("BitBlt"));
1625 }
1626 }
1627 vCbnd.lColor = (LONG)vOldTextColor;
1628 ::GpiSetAttrs( m_hPS // presentation-space handle
1629 ,PRIM_CHAR // Char primitive.
1630 ,CBB_COLOR // sets color.
1631 ,0
1632 ,&vCbnd // buffer for attributes.
1633 );
1634 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
1635 return bSuccess;
1636 }
1637
1638 void wxDC::DoGetSize( int* width, int* height ) const
1639 {
1640 // TODO:
1641 };
1642
1643 void wxDC::DoGetSizeMM( int* width, int* height ) const
1644 {
1645 // TODO:
1646 };
1647
1648 wxSize wxDC::GetPPI() const
1649 {
1650 int x = 1;
1651 int y = 1;
1652 // TODO:
1653 return (wxSize(x,y));
1654 }
1655
1656 void wxDC::SetLogicalScale( double x, double y )
1657 {
1658 // TODO:
1659 };
1660
1661 #if WXWIN_COMPATIBILITY
1662 void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
1663 float *descent, float *externalLeading,
1664 wxFont *theFont, bool use16bit) const
1665 {
1666 wxCoord x1, y1, descent1, externalLeading1;
1667 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
1668 *x = x1; *y = y1;
1669 if (descent)
1670 *descent = descent1;
1671 if (externalLeading)
1672 *externalLeading = externalLeading1;
1673 }
1674 #endif
1675