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