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