]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dc.cpp
true vs TRUE again.
[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"
b9c15d10 25 #include "wx/msgdlg.h"
0e320a79
DW
26#endif
27
fb46a9a6
DW
28#include "wx/dcprint.h"
29
30#include <string.h>
31#include <math.h>
32
33#include "wx/os2/private.h"
0e320a79 34
fb46a9a6 35 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
0e320a79 36
5fd2b2c6
DW
37//
38// wxWindows uses the Microsoft convention that the origin is the UPPER left.
39// Native OS/2 however in the GPI and PM define the origin as the LOWER left.
40// In order to map OS/2 GPI/PM y coordinates to wxWindows coordinates we must
41// perform the following transformation:
42//
43// Parent object height: POBJHEIGHT
44// Desried origin: WXORIGINY
45// Object to place's height: OBJHEIGHT
46//
47// To get the OS2 position from the wxWindows one:
48//
49// OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
50//
51// For OS/2 wxDC's we will always determine m_vRclPaint as the size of the
52// OS/2 Presentation Space associated with the device context. y is the
53// desired application's y coordinate of the origin in wxWindows space.
54// objy is the height of the object we are going to draw.
55//
56#define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
57
fb46a9a6 58// ---------------------------------------------------------------------------
0e320a79 59// constants
fb46a9a6 60// ---------------------------------------------------------------------------
1408104d 61
fb46a9a6 62static const int VIEWPORT_EXTENT = 1000;
1408104d 63
fb46a9a6
DW
64static const int MM_POINTS = 9;
65static const int MM_METRIC = 10;
1408104d 66
f6bcfd97
BP
67// usually this is defined in math.h
68#ifndef M_PI
69 static const double M_PI = 3.14159265358979323846;
70#endif // M_PI
71
72// ---------------------------------------------------------------------------
73// private functions
74// ---------------------------------------------------------------------------
75
76// convert degrees to radians
77static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
78
7e99520b
DW
79int SetTextColor(
80 HPS hPS
81, int nForegroundColour
82)
83{
84 CHARBUNDLE vCbnd;
85
86 vCbnd.lColor = nForegroundColour;
87 ::GpiSetAttrs( hPS // presentation-space handle
88 ,PRIM_CHAR // Char primitive.
89 ,CBB_COLOR // sets color.
90 ,0 //
91 ,&vCbnd // buffer for attributes.
92 );
93 return 0;
94}
95
96int QueryTextBkColor(
97 HPS hPS
98)
99{
100 CHARBUNDLE vCbnd;
101
f44fdfb0
DW
102 ::GpiQueryAttrs( hPS // presentation-space handle
103 ,PRIM_CHAR // Char primitive.
104 ,CBB_BACK_COLOR // Background color.
105 ,&vCbnd // buffer for attributes.
106 );
7e99520b
DW
107 return vCbnd.lBackColor;
108}
109
110
111int SetTextBkColor(
112 HPS hPS
113, int nBackgroundColour
114)
115{
116 CHARBUNDLE vCbnd;
117 int rc;
118
119 rc = QueryTextBkColor(hPS);
120
121 vCbnd.lBackColor = nBackgroundColour;
122 ::GpiSetAttrs(hPS, // presentation-space handle
123 PRIM_CHAR, // Char primitive.
124 CBB_BACK_COLOR, // sets color.
125 0,
126 &vCbnd // buffer for attributes.
127 );
128 return rc;
129}
130
131int SetBkMode(
132 HPS hPS
133, int nBackgroundMode
134)
135{
136 if(nBackgroundMode == wxTRANSPARENT)
137 ::GpiSetBackMix( hPS
138 ,BM_LEAVEALONE
139 );
140 else
141 // the background of the primitive takes over whatever is underneath.
142 ::GpiSetBackMix( hPS
143 ,BM_OVERPAINT
144 );
145 return 0;
146}
147
fb46a9a6
DW
148// ===========================================================================
149// implementation
150// ===========================================================================
1408104d 151
fb46a9a6 152// ---------------------------------------------------------------------------
0e320a79 153// wxDC
fb46a9a6 154// ---------------------------------------------------------------------------
0e320a79
DW
155
156wxDC::wxDC(void)
157{
2b0ec34b
DW
158 wxColour vColor;
159
7e99520b 160 m_pCanvas = NULL;
c3d43472 161
7e99520b
DW
162 m_hOldBitmap = 0;
163 m_hOldPen = 0;
164 m_hOldBrush = 0;
165 m_hOldFont = 0;
166 m_hOldPalette = 0;
ce44c50e 167
7e99520b
DW
168 m_bOwnsDC = FALSE;
169 m_hDC = 0;
7e99520b
DW
170 m_hOldPS = NULL;
171 m_hPS = NULL;
e99762c0 172 m_bIsPaintTime = FALSE; // True at Paint Time
2b0ec34b
DW
173
174 vColor.InitFromName("BLACK");
175 m_pen.SetColour(vColor);
176 vColor.Set("WHITE");
177 m_brush.SetColour(vColor);
e1a688e4 178} // end of wxDC::wxDC
0e320a79
DW
179
180wxDC::~wxDC(void)
181{
e1a688e4
DW
182 if ( m_hDC != 0 )
183 {
184 SelectOldObjects(m_hDC);
185
186 // if we own the HDC, we delete it, otherwise we just release it
187
188 if (m_bOwnsDC)
189 {
190 if(m_hPS)
191 {
192 ::GpiAssociate(m_hPS, NULLHANDLE);
193 ::GpiDestroyPS(m_hPS);
194 }
195 m_hPS = NULLHANDLE;
196 ::DevCloseDC((HDC)m_hDC);
197 }
198 else
199 {
200 //
201 // Just Dissacociate, not destroy if we don't own the DC
202 //
203 if(m_hPS)
204 {
205 ::GpiAssociate(m_hPS, NULLHANDLE);
206 }
207 }
208 }
209} // end of wxDC::~wxDC
0e320a79 210
fb46a9a6
DW
211// This will select current objects out of the DC,
212// which is what you have to do before deleting the
213// DC.
f07bb01b
DW
214void wxDC::SelectOldObjects(
215 WXHDC hPS
216)
0e320a79 217{
f07bb01b 218 if (hPS)
fb46a9a6 219 {
f6bcfd97 220 if (m_hOldBitmap)
fb46a9a6 221 {
f07bb01b 222 ::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap);
f6bcfd97 223 if (m_vSelectedBitmap.Ok())
fb46a9a6 224 {
f6bcfd97 225 m_vSelectedBitmap.SetSelectedInto(NULL);
fb46a9a6
DW
226 }
227 }
f6bcfd97 228 m_hOldBitmap = 0;
f07bb01b
DW
229 //
230 // OS/2 has no other native GDI objects to set in a PS/DC like windows
231 //
f6bcfd97 232 m_hOldPen = 0;
f6bcfd97 233 m_hOldBrush = 0;
f6bcfd97 234 m_hOldFont = 0;
f6bcfd97 235 m_hOldPalette = 0;
fb46a9a6 236 }
0e320a79 237
f6bcfd97
BP
238 m_brush = wxNullBrush;
239 m_pen = wxNullPen;
240 m_palette = wxNullPalette;
241 m_font = wxNullFont;
fb46a9a6 242 m_backgroundBrush = wxNullBrush;
f6bcfd97 243 m_vSelectedBitmap = wxNullBitmap;
e1a688e4 244} // end of wxDC::SelectOldObjects
0e320a79 245
fb46a9a6
DW
246// ---------------------------------------------------------------------------
247// clipping
248// ---------------------------------------------------------------------------
0e320a79 249
fa5593ac
DW
250#define DO_SET_CLIPPING_BOX() \
251{ \
252 RECTL rect; \
253 \
254 ::GpiQueryClipBox(m_hPS, &rect); \
255 \
256 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
257 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
258 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
259 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
fb46a9a6 260}
0e320a79 261
fa5593ac 262void wxDC::DoSetClippingRegion(
5fd2b2c6
DW
263 wxCoord vX
264, wxCoord vY
265, wxCoord vWidth
266, wxCoord vHeight
fa5593ac 267)
0e320a79 268{
fa5593ac
DW
269 RECTL vRect;
270
5fd2b2c6 271 vY = OS2Y(vY,vHeight);
fa5593ac 272 m_clipping = TRUE;
5fd2b2c6
DW
273 vRect.xLeft = vX;
274 vRect.yTop = vY + vHeight;
275 vRect.xRight = vX + vWidth;
276 vRect.yBottom = vY;
fa5593ac
DW
277 ::GpiIntersectClipRectangle(m_hPS, &vRect);
278 DO_SET_CLIPPING_BOX()
279} // end of wxDC::DoSetClippingRegion
280
281void wxDC::DoSetClippingRegionAsRegion(
282 const wxRegion& rRegion
283)
0e320a79 284{
fa5593ac
DW
285 wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
286 HRGN hRgnOld;
287
288 m_clipping = TRUE;
289 ::GpiSetClipRegion( m_hPS
290 ,(HRGN)rRegion.GetHRGN()
291 ,&hRgnOld
292 );
293 DO_SET_CLIPPING_BOX()
294} // end of wxDC::DoSetClippingRegionAsRegion
0e320a79 295
fb46a9a6 296void wxDC::DestroyClippingRegion(void)
0e320a79 297{
fa5593ac
DW
298 if (m_clipping && m_hPS)
299 {
300 HRGN hRgnOld;
301 RECTL vRect;
302
303 // TODO: this should restore the previous clipped region
304 // so that OnPaint processing works correctly, and
305 // the update doesn't get destroyed after the first
306 // DestroyClippingRegion
307 vRect.xLeft = XLOG2DEV(0);
308 vRect.yTop = YLOG2DEV(32000);
309 vRect.xRight = XLOG2DEV(32000);
310 vRect.yBottom = YLOG2DEV(0);
311
312 HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
313
314 ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
315 }
316 m_clipping = FALSE;
317} // end of wxDC::DestroyClippingRegion
0e320a79 318
fb46a9a6
DW
319// ---------------------------------------------------------------------------
320// query capabilities
321// ---------------------------------------------------------------------------
0e320a79 322
fb46a9a6 323bool wxDC::CanDrawBitmap() const
0e320a79 324{
fb46a9a6
DW
325 return TRUE;
326}
0e320a79 327
fb46a9a6 328bool wxDC::CanGetTextExtent() const
0e320a79 329{
f07bb01b 330 LONG lTechnology = 0L;
0e320a79 331
f07bb01b
DW
332 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology);
333 return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER);
334} // end of wxDC::CanGetTextExtent
1408104d
DW
335
336int wxDC::GetDepth() const
0e320a79 337{
f07bb01b
DW
338 LONG lArray[CAPS_COLOR_BITCOUNT];
339 int nBitsPerPixel;
340
341 if(::DevQueryCaps( GetHDC()
342 ,CAPS_FAMILY
343 ,CAPS_COLOR_BITCOUNT
344 ,lArray
345 ))
346 {
347 nBitsPerPixel = (int)lArray[CAPS_COLOR_BITCOUNT];
348 }
349 return nBitsPerPixel;
350} // end of wxDC::GetDepth
0e320a79 351
fb46a9a6
DW
352// ---------------------------------------------------------------------------
353// drawing
354// ---------------------------------------------------------------------------
0e320a79 355
1408104d 356void wxDC::Clear()
0e320a79 357{
445c7bca 358 ::GpiErase(m_hPS);
5fd2b2c6 359} // end of wxDC::Clear
0e320a79 360
51c1d535
DW
361void wxDC::DoFloodFill(
362 wxCoord vX
363, wxCoord vY
364, const wxColour& rCol
365, int nStyle
366)
0e320a79 367{
51c1d535
DW
368 POINTL vPtlPos;
369 LONG lColor;
370 LONG lOptions;
371
372 vPtlPos.x = vX; // Loads x-coordinate
5fd2b2c6 373 vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate
51c1d535
DW
374 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
375 lColor = rCol.GetPixel();
376 lOptions = FF_BOUNDARY;
377 if(wxFLOOD_SURFACE == nStyle)
378 lOptions = FF_SURFACE;
379
380 ::GpiFloodFill(m_hPS, lOptions, lColor);
5fd2b2c6 381} // end of wxDC::DoFloodFill
0e320a79 382
51c1d535
DW
383bool wxDC::DoGetPixel(
384 wxCoord vX
385, wxCoord vY
386, wxColour* pCol
387) const
1408104d 388{
51c1d535
DW
389 POINTL vPoint;
390 LONG lColor;
391
392 vPoint.x = vX;
5fd2b2c6 393 vPoint.y = OS2Y(vY,0);
51c1d535 394 lColor = ::GpiSetPel(m_hPS, &vPoint);
5fd2b2c6
DW
395
396 //
397 // Get the color of the pen
398 //
399 LONG lPencolor = 0x00ffffff;
400
401 if (m_pen.Ok())
402 {
403 lPencolor = m_pen.GetColour().GetPixel();
404 }
405
406 //
407 // return the color of the pixel
408 //
409 if(pCol)
410 pCol->Set( GetRValue(lColor)
411 ,GetGValue(lColor)
412 ,GetBValue(lColor)
413 );
414 return(lColor == lPencolor);
415} // end of wxDC::DoGetPixel
0e320a79 416
f07bb01b
DW
417void wxDC::DoCrossHair(
418 wxCoord vX
419, wxCoord vY
420)
0e320a79 421{
5fd2b2c6
DW
422 vY = OS2Y(vY,0);
423
f07bb01b
DW
424 wxCoord vX1 = vX - VIEWPORT_EXTENT;
425 wxCoord vY1 = vY - VIEWPORT_EXTENT;
426 wxCoord vX2 = vX + VIEWPORT_EXTENT;
427 wxCoord vY2 = vY + VIEWPORT_EXTENT;
428 POINTL vPoint[4];
429
430 vPoint[0].x = vX1;
5fd2b2c6 431 vPoint[0].y = vY;
f07bb01b
DW
432
433 vPoint[1].x = vX2;
5fd2b2c6 434 vPoint[1].y = vY;
f07bb01b
DW
435
436 ::GpiMove(m_hPS, &vPoint[0]);
437 ::GpiLine(m_hPS, &vPoint[1]);
438
439 vPoint[2].x = vX;
5fd2b2c6 440 vPoint[2].y = vY1;
f07bb01b
DW
441
442 vPoint[3].x = vX;
5fd2b2c6 443 vPoint[3].y = vY2;
f07bb01b
DW
444
445 ::GpiMove(m_hPS, &vPoint[2]);
446 ::GpiLine(m_hPS, &vPoint[3]);
5fd2b2c6
DW
447 CalcBoundingBox(vX1, vY1);
448 CalcBoundingBox(vX2, vY2);
f07bb01b 449} // end of wxDC::DoCrossHair
1408104d 450
7e99520b
DW
451void wxDC::DoDrawLine(
452 wxCoord vX1
453, wxCoord vY1
454, wxCoord vX2
455, wxCoord vY2
456)
0e320a79 457{
7e99520b
DW
458 POINTL vPoint[2];
459
5fd2b2c6
DW
460 vY1 = OS2Y(vY1,0);
461 vY2 = OS2Y(vY2,0);
462
7e99520b 463 vPoint[0].x = vX1;
5fd2b2c6 464 vPoint[0].y = vY1;
7e99520b 465 vPoint[1].x = vX2;
5fd2b2c6 466 vPoint[1].y = vY2;
7e99520b
DW
467 ::GpiMove(m_hPS, &vPoint[0]);
468 ::GpiLine(m_hPS, &vPoint[1]);
5fd2b2c6
DW
469 CalcBoundingBox(vX1, vY1);
470 CalcBoundingBox(vX2, vY2);
f07bb01b 471} // end of wxDC::DoDrawLine
1408104d 472
51c1d535
DW
473//////////////////////////////////////////////////////////////////////////////
474// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
475// and ending at (x2, y2). The current pen is used for the outline and the
476// current brush for filling the shape. The arc is drawn in an anticlockwise
477// direction from the start point to the end point.
478//////////////////////////////////////////////////////////////////////////////
479void wxDC::DoDrawArc(
480 wxCoord vX1
481, wxCoord vY1
482, wxCoord vX2
483, wxCoord vY2
484, wxCoord vXc
485, wxCoord vYc
486)
1408104d 487{
51c1d535
DW
488 POINTL vPtlPos;
489 POINTL vPtlArc[2]; // Structure for current position
490 int nDx;
491 int nDy;
492 double dRadius;
493 double dAngl1;
494 double dAngl2;
495 double dAnglmid;
496 wxCoord vXm;
497 wxCoord vYm;
498 ARCPARAMS vArcp; // Structure for arc parameters
499
500 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
501 return; // Draw point ??
502 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
503 ,(double)(vX1 - vXc)
504 ) +
505 hypot( (double)(vY2 - vYc)
506 ,(double)(vX2 - vXc)
507 )
508 );
509
510 dAngl1 = atan2( (double)(vY1 - vYc)
511 ,(double)(vX1 - vXc)
512 );
513 dAngl2 = atan2( (double)(vY2 - vYc)
514 ,(double)(vX2 - vXc)
515 );
516 if(dAngl2 < dAngl1)
517 dAngl2 += M_PI * 2;
518
519 //
520 // GpiPointArc can't draw full arc
521 //
522 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
523 {
524 //
525 // Medium point
526 //
527 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
528 vXm = vXc + dRadius * cos(dAnglmid);
529 vYm = vYc + dRadius * sin(dAnglmid);
e99762c0
DW
530 DoDrawArc( vX1, vY1
531 ,vXm, vYm
532 ,vXc, vYc
51c1d535 533 );
e99762c0
DW
534 DoDrawArc( vXm, vYm
535 ,vX2, vY2
536 ,vXc, vYc
51c1d535
DW
537 );
538 return;
539 }
540
541 //
542 // Medium point
543 //
544 dAnglmid = (dAngl1 + dAngl2)/2.;
545 vXm = vXc + dRadius * cos(dAnglmid);
546 vYm = vYc + dRadius * sin(dAnglmid);
547
548 //
549 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
550 //
551 vArcp.lR = 0;
552 vArcp.lQ = 1;
553 vArcp.lP = 1;
554 vArcp.lS = 0;
555 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
556
557 vPtlPos.x = vX1; // Loads x-coordinate
558 vPtlPos.y = vY1; // Loads y-coordinate
559 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
e99762c0
DW
560 vPtlArc[0].x = vXm;
561 vPtlArc[0].y = vYm;
51c1d535
DW
562 vPtlArc[1].x = vX2;
563 vPtlArc[1].y = vY2;
564 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
5fd2b2c6
DW
565 CalcBoundingBox( (vXc - dRadius)
566 ,(vYc - dRadius)
567 );
568 CalcBoundingBox( (vXc + dRadius)
569 ,(vYc + dRadius)
570 );
f07bb01b 571} // end of wxDC::DoDrawArc
1408104d 572
51c1d535
DW
573void wxDC::DoDrawCheckMark(
574 wxCoord vX1
575, wxCoord vY1
576, wxCoord vWidth
577, wxCoord vHeight
578)
f6bcfd97 579{
51c1d535
DW
580 POINTL vPoint[2];
581
5fd2b2c6
DW
582 vY1 = OS2Y(vY1,vHeight);
583
51c1d535
DW
584 vPoint[0].x = vX1;
585 vPoint[0].y = vY1;
586 vPoint[1].x = vX1 + vWidth;
587 vPoint[1].y = vY1 + vHeight;
588
589 ::GpiMove(m_hPS, &vPoint[0]);
590 ::GpiBox( m_hPS // handle to a presentation space
591 ,DRO_OUTLINE // draw the box outline ? or ?
592 ,&vPoint[1] // address of the corner
593 ,0L // horizontal corner radius
594 ,0L // vertical corner radius
595 );
596 if(vWidth > 4 && vHeight > 4)
597 {
598 int nTmp;
599
600 vPoint[0].x += 2; vPoint[0].y += 2;
601 vPoint[1].x -= 2; vPoint[1].y -= 2;
602 ::GpiMove(m_hPS, &vPoint[0]);
603 ::GpiLine(m_hPS, &vPoint[1]);
604 nTmp = vPoint[0].x;
605 vPoint[0].x = vPoint[1].x;
606 vPoint[1].x = nTmp;
607 ::GpiMove(m_hPS, &vPoint[0]);
608 ::GpiLine(m_hPS, &vPoint[1]);
609 }
5fd2b2c6
DW
610 CalcBoundingBox( vX1
611 ,vY1
612 );
613
614 wxCoord vX2 = vX1 + vWidth;
615 wxCoord vY2 = vY1 + vHeight;
616
617 CalcBoundingBox( vX2
618 ,vY2
619 );
f07bb01b 620} // end of wxDC::DoDrawCheckMark
f6bcfd97 621
51c1d535
DW
622void wxDC::DoDrawPoint(
623 wxCoord vX
624, wxCoord vY
625)
1408104d 626{
51c1d535 627 POINTL vPoint;
5fd2b2c6 628 COLORREF vColor = 0x00ffffff;
51c1d535 629
5fd2b2c6
DW
630 if (m_pen.Ok())
631 {
632 vColor = m_pen.GetColour().GetPixel();
633 }
634 ::GpiSetColor(m_hPS, vColor);
51c1d535 635 vPoint.x = vX;
5fd2b2c6 636 vPoint.y = OS2Y(vY,0);
51c1d535 637 ::GpiSetPel(m_hPS, &vPoint);
5fd2b2c6
DW
638 CalcBoundingBox( vX
639 ,vY
640 );
f07bb01b 641} // end of wxDC::DoDrawPoint
1408104d 642
51c1d535
DW
643void wxDC::DoDrawPolygon(
644 int n
645, wxPoint vPoints[]
646, wxCoord vXoffset
647, wxCoord vYoffset
648, int nFillStyle
649)
1408104d 650{
51c1d535
DW
651 ULONG ulCount = 1; // Number of polygons.
652 POLYGON vPlgn; // polygon.
653 ULONG flOptions = 0L; // Drawing options.
654
655//////////////////////////////////////////////////////////////////////////////
656// This contains fields of option bits... to draw boundary lines as well as
657// the area interior.
658//
659// Drawing boundary lines:
660// POLYGON_NOBOUNDARY Does not draw boundary lines.
661// POLYGON_BOUNDARY Draws boundary lines (the default).
662//
663// Construction of the area interior:
664// POLYGON_ALTERNATE Constructs interior in alternate mode
665// (the default).
666// POLYGON_WINDING Constructs interior in winding mode.
667//////////////////////////////////////////////////////////////////////////////
668
669 ULONG flModel = 0L; // Drawing model.
670
671//////////////////////////////////////////////////////////////////////////////
672// Drawing model.
673// POLYGON_INCL Fill is inclusive of bottom right (the default).
674// POLYGON_EXCL Fill is exclusive of bottom right.
675// This is provided to aid migration from other graphics models.
676//////////////////////////////////////////////////////////////////////////////
677
678 LONG lHits = 0L; // Correlation/error indicator.
679 POINTL vPoint;
680 int i;
681 int nIsTRANSPARENT = 0;
682 LONG lBorderColor = 0L;
683 LONG lColor = 0L;
684
685 lBorderColor = m_pen.GetColour().GetPixel();
686 lColor = m_brush.GetColour().GetPixel();
687 if(m_brush.GetStyle() == wxTRANSPARENT)
688 nIsTRANSPARENT = 1;
689
690 vPlgn.ulPoints = n;
691 vPlgn.aPointl = (POINTL*) calloc( n + 1
692 ,sizeof(POINTL)
693 ); // well, new will call malloc
694
695 for(i = 0; i < n; i++)
696 {
5fd2b2c6
DW
697 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
698 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
51c1d535
DW
699 }
700 flModel = POLYGON_BOUNDARY;
701 if(nFillStyle == wxWINDING_RULE)
702 flModel |= POLYGON_WINDING;
703 else
704 flModel |= POLYGON_ALTERNATE;
705
706 vPoint.x = vXoffset;
5fd2b2c6 707 vPoint.y = OS2Y(vYoffset,0);
51c1d535
DW
708
709 ::GpiSetColor(m_hPS, lBorderColor);
710 ::GpiMove(m_hPS, &vPoint);
711 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
712 free(vPlgn.aPointl);
f07bb01b 713} // end of wxDC::DoDrawPolygon
1408104d 714
51c1d535
DW
715void wxDC::DoDrawLines(
716 int n
717, wxPoint vPoints[]
718, wxCoord vXoffset
719, wxCoord vYoffset
720)
1408104d 721{
51c1d535
DW
722 POINTL vPoint;
723
5fd2b2c6
DW
724 if (vXoffset != 0L || vXoffset != 0L)
725 {
726 int i;
727
728 vPoint.x = vPoints[0].x + vXoffset;
729 vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
730 ::GpiMove(m_hPS, &vPoint);
51c1d535 731
5fd2b2c6 732 LONG lBorderColor = m_pen.GetColour().GetPixel();
51c1d535 733
5fd2b2c6
DW
734 ::GpiSetColor(m_hPS, lBorderColor);
735 for(i = 1; i < n; i++)
736 {
737 vPoint.x = vPoints[i].x + vXoffset;
738 vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
739 ::GpiLine(m_hPS, &vPoint);
740 }
741 }
742 else
51c1d535 743 {
5fd2b2c6
DW
744 int i;
745
746 CalcBoundingBox( vPoints[i].x
747 ,vPoints[i].y
748 );
749 vPoint.x = vPoints[0].x;
750 vPoint.y = OS2Y(vPoints[0].y,0);
751 ::GpiMove(m_hPS, &vPoint);
752
753 for (i = 0; i < n; i++)
754 {
755 CalcBoundingBox( vPoints[i].x
756 ,vPoints[i].y
757 );
758 vPoint.x = vPoints[i].x;
759 vPoint.y = OS2Y(vPoints[i].y,0);
760 ::GpiLine(m_hPS, &vPoint);
761 }
51c1d535 762 }
f07bb01b 763} // end of wxDC::DoDrawLines
1408104d 764
7e99520b 765void wxDC::DoDrawRectangle(
f44fdfb0 766 wxCoord vX
7e99520b
DW
767, wxCoord vY
768, wxCoord vWidth
769, wxCoord vHeight
770)
1408104d 771{
7e99520b 772 POINTL vPoint[2];
51c1d535
DW
773 LONG lControl;
774 LONG lColor;
775 LONG lBorderColor;
776 int nIsTRANSPARENT = 0;
7e99520b 777
5fd2b2c6
DW
778 vY = OS2Y(vY,vHeight);
779
780 wxCoord vX2 = vX + vWidth;
781 wxCoord vY2 = vY + vHeight;
782
7e99520b 783 vPoint[0].x = vX;
5fd2b2c6 784 vPoint[0].y = vY;
f44fdfb0 785 vPoint[1].x = vX + vWidth;
5fd2b2c6 786 vPoint[1].y = vY + vHeight;
7e99520b 787 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
788 lColor = m_brush.GetColour().GetPixel();
789 lBorderColor = m_pen.GetColour().GetPixel();
790 if (m_brush.GetStyle() == wxTRANSPARENT)
791 nIsTRANSPARENT = 1;
792 if(lColor == lBorderColor || nIsTRANSPARENT)
793 {
794 lControl = DRO_OUTLINEFILL; //DRO_FILL;
795 if(m_brush.GetStyle() == wxTRANSPARENT)
796 lControl = DRO_OUTLINE;
797
8d854fa9 798 ::GpiSetColor(m_hPS, lColor);
51c1d535
DW
799 ::GpiBox( m_hPS // handle to a presentation space
800 ,lControl // draw the box outline ? or ?
801 ,&vPoint[1] // address of the corner
802 ,0L // horizontal corner radius
803 ,0L // vertical corner radius
804 );
805 }
806 else
807 {
808 lControl = DRO_OUTLINE;
809 ::GpiSetColor( m_hPS
810 ,lBorderColor
811 );
812 ::GpiBox( m_hPS
813 ,lControl
814 ,&vPoint[1]
815 ,0L
816 ,0L
817 );
818 lControl = DRO_FILL;
819 ::GpiSetColor( m_hPS
820 ,lColor
821 );
8d854fa9 822 vPoint[0].x = vX + 1;
5fd2b2c6 823 vPoint[0].y = vY + 1;
ad7f3189
DW
824 vPoint[1].x = vX + vWidth - 1;
825 vPoint[1].y = vY + vHeight - 1;
8d854fa9 826 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
827 ::GpiBox( m_hPS
828 ,lControl
829 ,&vPoint[1]
830 ,0L
831 ,0L
832 );
833 }
5fd2b2c6
DW
834 CalcBoundingBox(vX, vY);
835 CalcBoundingBox(vX2, vY2);
f07bb01b 836} // end of wxDC::DoDrawRectangle
1408104d 837
7e99520b
DW
838void wxDC::DoDrawRoundedRectangle(
839 wxCoord vX
840, wxCoord vY
841, wxCoord vWidth
842, wxCoord vHeight
843, double dRadius
844)
1408104d 845{
7e99520b 846 POINTL vPoint[2];
51c1d535 847 LONG lControl;
7e99520b 848
5fd2b2c6
DW
849 vY = OS2Y(vY,vHeight);
850
851 wxCoord vX2 = (vX + vWidth);
852 wxCoord vY2 = (vY + vHeight);
853
7e99520b 854 vPoint[0].x = vX;
8d854fa9 855 vPoint[0].y = YLOG2DEV(vY) - vHeight;
7e99520b 856 vPoint[1].x = vX + vWidth;
8d854fa9 857 vPoint[1].y = vY;
7e99520b 858 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
859
860 lControl = DRO_OUTLINEFILL; //DRO_FILL;
861 if (m_brush.GetStyle() == wxTRANSPARENT)
862 lControl = DRO_OUTLINE;
f44fdfb0
DW
863 ::GpiBox( m_hPS // handle to a presentation space
864 ,DRO_OUTLINE // draw the box outline ? or ?
865 ,&vPoint[1] // address of the corner
866 ,(LONG)dRadius // horizontal corner radius
867 ,(LONG)dRadius // vertical corner radius
7e99520b 868 );
5fd2b2c6
DW
869 CalcBoundingBox(vX, vY);
870 CalcBoundingBox(vX2, vY2);
f07bb01b 871} // end of wxDC::DoDrawRoundedRectangle
1408104d 872
51c1d535
DW
873// Draw Ellipse within box (x,y) - (x+width, y+height)
874void wxDC::DoDrawEllipse(
875 wxCoord vX
876, wxCoord vY
877, wxCoord vWidth
878, wxCoord vHeight
879)
1408104d 880{
51c1d535
DW
881 POINTL vPtlPos; // Structure for current position
882 FIXED vFxMult; // Multiplier for ellipse
883 ARCPARAMS vArcp; // Structure for arc parameters
884
5fd2b2c6
DW
885 vY = OS2Y(vY,vHeight);
886
51c1d535
DW
887 vArcp.lR = 0;
888 vArcp.lQ = vHeight/2;
889 vArcp.lP = vWidth/2;
890 vArcp.lS = 0;
891 ::GpiSetArcParams( m_hPS
892 ,&vArcp
893 ); // Sets parameters to default
894 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
895 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
896 ::GpiMove( m_hPS
897 ,&vPtlPos
898 ); // Sets current position
899 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
900
901 //
902 // DRO_FILL, DRO_OTLINEFILL - where to get
903 //
904 ::GpiFullArc( m_hPS
905 ,DRO_OUTLINE
906 ,vFxMult
907 ); // Draws full arc with center at current position
5fd2b2c6
DW
908
909 wxCoord vX2 = (vX + vWidth);
910 wxCoord vY2 = (vY + vHeight);
911
912 CalcBoundingBox(vX, vY);
913 CalcBoundingBox(vX2, vY2);
f07bb01b 914} // end of wxDC::DoDrawEllipse
1408104d 915
51c1d535
DW
916void wxDC::DoDrawEllipticArc(
917 wxCoord vX
918, wxCoord vY
919, wxCoord vWidth
920, wxCoord vHeight
921, double dSa
922, double dEa
923)
1408104d 924{
51c1d535
DW
925 POINTL vPtlPos; // Structure for current position
926 FIXED vFxMult; // Multiplier for ellipse
927 ARCPARAMS vArcp; // Structure for arc parameters
928 FIXED vFSa;
929 FIXED vFSweepa; // Start angle, sweep angle
930 double dIntPart;
931 double dFractPart;
932 double dRadius;
933
5fd2b2c6
DW
934 vY = OS2Y(vY,vHeight);
935
51c1d535
DW
936 dFractPart = modf(dSa,&dIntPart);
937 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
938 dFractPart = modf(dEa - dSa, &dIntPart);
939 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
940
941 //
942 // Ellipse main axis (r,q), (p,s) with center at (0,0)
943 //
944 vArcp.lR = 0;
945 vArcp.lQ = vHeight/2;
946 vArcp.lP = vWidth/2;
947 vArcp.lS = 0;
948 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
949 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
950 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
951 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
952
953 //
954 // May be not to the center ?
955 //
956 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
957 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
958 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
959
960 //
961 // DRO_FILL, DRO_OTLINEFILL - where to get
962 //
963 ::GpiPartialArc( m_hPS
964 ,&vPtlPos
965 ,vFxMult
966 ,vFSa
967 ,vFSweepa
968 );
5fd2b2c6
DW
969 wxCoord vX2 = (vX + vWidth);
970 wxCoord vY2 = (vY + vHeight);
971
972 CalcBoundingBox(vX, vY);
973 CalcBoundingBox(vX2, vY2);
f07bb01b 974} // end of wxDC::DoDrawEllipticArc
1408104d 975
f07bb01b
DW
976void wxDC::DoDrawIcon(
977 const wxIcon& rIcon
978, wxCoord vX
979, wxCoord vY
980)
1408104d 981{
5fd2b2c6 982 vY = OS2Y(vY,rIcon.GetHeight());
f07bb01b
DW
983 wxCHECK_RET( rIcon.Ok(), wxT("invalid icon in DrawIcon") );
984
985 ::WinDrawPointer( GetHPS()
986 ,vX
987 ,vY
988 ,(HPOINTER)GetHiconOf(rIcon)
989 ,DP_NORMAL
990 );
5fd2b2c6
DW
991 CalcBoundingBox(vX, vY);
992 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
f07bb01b
DW
993} // end of wxDC::DoDrawIcon
994
995void wxDC::DoDrawBitmap(
996 const wxBitmap& rBmp
997, wxCoord vX
998, wxCoord vY
999, bool bUseMask
1000)
1408104d 1001{
f07bb01b
DW
1002 POINTL vPoint = {vX, vY};
1003
1004 ::WinDrawBitmap( GetHPS()
1005 ,(HBITMAP)GetHbitmapOf(rBmp)
1006 ,NULL
1007 ,&vPoint
1008 ,0L
1009 ,0L
1010 ,DBM_NORMAL
1011 );
1012} // end of wxDC::DoDrawBitmap
1408104d 1013
7e99520b
DW
1014void wxDC::DoDrawText(
1015 const wxString& rsText
1016, wxCoord vX
1017, wxCoord vY
1018)
1408104d 1019{
5fd2b2c6
DW
1020 wxCoord vWidth;
1021 wxCoord vHeight;
1022
7e99520b
DW
1023 DrawAnyText( rsText
1024 ,vX
1025 ,vY
1026 );
5fd2b2c6
DW
1027
1028 CalcBoundingBox(vX, vY);
1029 GetTextExtent(rsText, &vWidth, &vHeight);
1030 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1031} // end of wxDC::DoDrawText
1408104d 1032
7e99520b
DW
1033void wxDC::DrawAnyText(
1034 const wxString& rsText
1035, wxCoord vX
1036, wxCoord vY
1037)
f6bcfd97 1038{
7e99520b
DW
1039 int nOldBackground = 0;
1040 POINTL vPtlStart;
1041 LONG lHits;
5fd2b2c6
DW
1042 wxCoord vTextX = 0;
1043 wxCoord vTextY = 0;
f6bcfd97 1044
7e99520b
DW
1045 //
1046 // prepare for drawing the text
1047 //
1048
1049 //
1050 // Set text color attributes
1051 //
1052 if (m_textForegroundColour.Ok())
1053 {
1054 SetTextColor( m_hPS
1055 ,(int)m_textForegroundColour.GetPixel()
1056 );
1057 }
1058
1059 if (m_textBackgroundColour.Ok())
1060 {
1061 nOldBackground = SetTextBkColor( m_hPS
1062 ,(int)m_textBackgroundColour.GetPixel()
1063 );
1064 }
1065 SetBkMode( m_hPS
1066 ,m_backgroundMode
1067 );
5fd2b2c6
DW
1068 GetTextExtent( rsText
1069 ,&vTextX
1070 ,&vTextY
1071 );
7e99520b 1072 vPtlStart.x = vX;
5fd2b2c6 1073 vPtlStart.y = OS2Y(vY,vTextY);
7e99520b
DW
1074
1075 lHits = ::GpiCharStringAt( m_hPS
1076 ,&vPtlStart
1077 ,rsText.length()
1078 ,(PCH)rsText.c_str()
1079 );
1080 if (lHits != GPI_OK)
1081 {
1082 wxLogLastError(wxT("TextOut"));
1083 }
1084
1085 //
1086 // Restore the old parameters (text foreground colour may be left because
1087 // it never is set to anything else, but background should remain
1088 // transparent even if we just drew an opaque string)
1089 //
1090 if (m_textBackgroundColour.Ok())
1091 SetTextBkColor( m_hPS
1092 ,nOldBackground
1093 );
1094 SetBkMode( m_hPS
1095 ,wxTRANSPARENT
1096 );
1097}
1098
1099void wxDC::DoDrawRotatedText(
1100 const wxString& rsText
1101, wxCoord vX
1102, wxCoord vY
1103, double dAngle
1104)
c8ce6bcc 1105{
7e99520b
DW
1106 if (dAngle == 0.0)
1107 {
1108 DoDrawText( rsText
1109 ,vX
1110 ,vY
1111 );
1112 }
1113
c8ce6bcc
DW
1114 // TODO:
1115 /*
1116 if ( angle == 0.0 )
1117 {
1118 DoDrawText(text, x, y);
1119 }
1120 else
1121 {
1122 LOGFONT lf;
1123 wxFillLogFont(&lf, &m_font);
1124
1125 // GDI wants the angle in tenth of degree
1126 long angle10 = (long)(angle * 10);
1127 lf.lfEscapement = angle10;
1128 lf. lfOrientation = angle10;
1129
1130 HFONT hfont = ::CreateFontIndirect(&lf);
1131 if ( !hfont )
1132 {
1133 wxLogLastError("CreateFont");
1134 }
1135 else
1136 {
1137 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1138
1139 DrawAnyText(text, x, y);
1140
1141 (void)::SelectObject(GetHdc(), hfontOld);
1142 }
1143
1144 // call the bounding box by adding all four vertices of the rectangle
1145 // containing the text to it (simpler and probably not slower than
1146 // determining which of them is really topmost/leftmost/...)
1147 wxCoord w, h;
1148 GetTextExtent(text, &w, &h);
1149
1150 double rad = DegToRad(angle);
1151
1152 // "upper left" and "upper right"
1153 CalcBoundingBox(x, y);
1154 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1155 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1156
1157 // "bottom left" and "bottom right"
1158 x += (wxCoord)(h*sin(rad));
1159 y += (wxCoord)(h*cos(rad));
1160 CalcBoundingBox(x, y);
1161 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1162 }
1163*/
1164}
1165
fb46a9a6
DW
1166// ---------------------------------------------------------------------------
1167// set GDI objects
1168// ---------------------------------------------------------------------------
1408104d 1169
5fd2b2c6
DW
1170void wxDC::SetPalette(
1171 const wxPalette& rPalette
1172)
1408104d 1173{
5fd2b2c6
DW
1174 if (m_hOldFont)
1175 {
1176 m_hOldFont = 0;
1177 }
1178 m_palette = rPalette;
1179 if (!rPalette.Ok())
1180 {
1181 if (m_hOldFont)
1182 {
1183 m_hOldFont = 0;
1184 }
1185 }
1186 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1187 if (!m_hOldPalette)
1188 m_hOldPalette = (WXHPALETTE)hOldPal;
1189} // end of wxDC::SetPalette
1408104d 1190
f6bcfd97
BP
1191void wxDC::SetFont(
1192 const wxFont& rFont
1193)
1408104d 1194{
f6bcfd97
BP
1195 //
1196 // Set the old object temporarily, in case the assignment deletes an object
1197 // that's not yet selected out.
1198 //
1199 if (m_hOldFont)
1200 {
f6bcfd97
BP
1201 m_hOldFont = 0;
1202 }
f6bcfd97 1203 m_font = rFont;
f6bcfd97
BP
1204 if (!rFont.Ok())
1205 {
f6bcfd97
BP
1206 m_hOldFont = 0;
1207 }
1208
e99762c0
DW
1209 m_font.SetPS(m_hPS); // this will realize the font
1210
1211 if (m_font.Ok())
f6bcfd97 1212 {
e99762c0 1213 HFONT hFont = m_font.GetResourceHandle();
f6bcfd97
BP
1214 if (hFont == (HFONT) NULL)
1215 {
1216 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1217 }
1218 if (!m_hOldFont)
1219 m_hOldFont = (WXHFONT) hFont;
1220 }
e99762c0 1221} // end of wxDC::SetFont
1408104d 1222
7e99520b
DW
1223void wxDC::SetPen(
1224 const wxPen& rPen
1225)
1408104d 1226{
7e99520b
DW
1227 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1228
1229 if (m_pen == rPen)
1230 return;
1231 m_pen = rPen;
1232 if (!m_pen.Ok())
1233 return;
1234
26ac77db
DW
1235 if (m_hOldPen)
1236 m_hOldPen = 0L;
1237 m_pen = rPen;
7e99520b 1238
26ac77db 1239 if (!m_pen.Ok())
7e99520b 1240 {
26ac77db
DW
1241 if (m_hOldPen)
1242 {
1243 m_pen.SetPS((HPS)m_hOldPen);
1244 }
1245 m_hOldPen = 0L;
7e99520b 1246 }
51c1d535 1247
26ac77db 1248 if (m_pen.Ok())
51c1d535 1249 {
26ac77db
DW
1250 if (m_pen.GetResourceHandle())
1251 {
1252 m_pen.SetPS(m_hPS);
1253 if (!m_hOldPen)
1254 m_hOldPen = m_pen.GetPS();
1255 }
51c1d535 1256 }
1408104d 1257}
7e99520b 1258
51c1d535
DW
1259void wxDC::SetBrush(
1260 const wxBrush& rBrush
1261)
1408104d 1262{
15f03b25
DW
1263 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1264
15f03b25
DW
1265 if (m_hOldBrush)
1266 m_hOldBrush = 0L;
1267 m_brush = rBrush;
5fd2b2c6
DW
1268 if (!m_brush.Ok())
1269 if (m_brush == rBrush)
1270 return;
1271 if (!m_brush.Ok())
1272 if (m_hOldBrush)
1273 m_hOldBrush = 0L;
15f03b25
DW
1274
1275 if (!m_brush.Ok())
1276 {
1277 if (m_hOldBrush)
1278 {
1279 m_brush.SetPS((HPS)m_hOldBrush);
1280 }
1281 m_hOldBrush = 0L;
1282 }
1283
1284 if (m_brush.Ok())
1285 {
1286 if (m_brush.GetResourceHandle())
1287 {
1288 m_brush.SetPS(m_hPS);
1289 if (!m_hOldBrush)
5fd2b2c6 1290 m_hOldBrush = (WXHWND)m_brush.GetPS();
15f03b25
DW
1291 }
1292 }
1293} // end of wxDC::SetBrush
1408104d 1294
5fd2b2c6
DW
1295void wxDC::SetBackground(
1296 const wxBrush& rBrush
1297)
1408104d 1298{
5fd2b2c6
DW
1299 m_backgroundBrush = rBrush;
1300 if (!m_backgroundBrush.Ok())
1301 return;
1302 if (m_pCanvas)
1303 {
1304 bool bCustomColours = TRUE;
1305
1306 //
1307 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1308 // change background colours from the control-panel specified colours.
1309 //
1310 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
1311 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
1312 bCustomColours = FALSE;
1313 if (bCustomColours)
1314 {
1315 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
1316 {
1317 m_pCanvas->SetTransparent(TRUE);
1318 }
1319 else
1320 {
1321 //
1322 // Setting the background brush of a DC
1323 // doesn't affect the window background colour. However,
1324 // I'm leaving in the transparency setting because it's needed by
1325 // various controls (e.g. wxStaticText) to determine whether to draw
1326 // transparently or not. TODO: maybe this should be a new function
1327 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1328 // parent?
1329 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1330 //
1331 m_pCanvas->SetTransparent(FALSE);
1332 }
1333 }
1334 }
1335 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
1336 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
1337} // end of wxDC::SetBackground
1408104d 1338
7e99520b
DW
1339void wxDC::SetBackgroundMode(
1340 int nMode
1341)
1408104d 1342{
7e99520b 1343 m_backgroundMode = nMode;
5fd2b2c6 1344} // end of wxDC::SetBackgroundMode
1408104d 1345
5fd2b2c6
DW
1346void wxDC::SetLogicalFunction(
1347 int nFunction
1348)
1408104d 1349{
5fd2b2c6
DW
1350 m_logicalFunction = nFunction;
1351 SetRop((WXHDC)m_hDC);
1352} // wxDC::SetLogicalFunction
1408104d 1353
5fd2b2c6
DW
1354void wxDC::SetRop(
1355 WXHDC hDC
1356)
ce44c50e 1357{
5fd2b2c6 1358 if (!hDC || m_logicalFunction < 0)
ce44c50e
DW
1359 return;
1360
5fd2b2c6 1361 LONG lCRop;
ce44c50e
DW
1362 switch (m_logicalFunction)
1363 {
5fd2b2c6
DW
1364 case wxXOR:
1365 lCRop = FM_XOR;
1366 break;
1367
1368 case wxINVERT:
1369 lCRop = FM_INVERT;
1370 break;
1371
1372 case wxOR_REVERSE:
1373 lCRop = FM_MERGESRCNOT;
1374 break;
1375
1376 case wxAND_REVERSE:
1377 lCRop = FM_NOTMASKSRC;
1378 break;
1379
1380 case wxCLEAR:
1381 lCRop = FM_ONE;
1382 break;
1383
1384 case wxSET:
1385 lCRop = FM_ZERO;
1386 break;
1387
1388 case wxSRC_INVERT:
1389 lCRop = FM_MERGENOTSRC;
1390 break;
1391
1392 case wxOR_INVERT:
1393 lCRop = FM_MERGESRCNOT;
1394 break;
1395
1396 case wxAND:
1397 lCRop = FM_AND;
1398 break;
1399
1400 case wxOR:
1401 lCRop = FM_OR;
1402 break;
1403
1404 case wxAND_INVERT:
1405 lCRop = FM_SUBTRACT;
1406 break;
1407
1408 case wxEQUIV:
1409 case wxNAND:
1410 case wxCOPY:
1411 default:
1412 lCRop = FM_OVERPAINT;
1413 break;
ce44c50e 1414 }
5fd2b2c6
DW
1415 ::GpiSetMix((HPS)hDC, lCRop);
1416} // end of wxDC::SetRop
ce44c50e 1417
5fd2b2c6
DW
1418bool wxDC::StartDoc(
1419 const wxString& rsMessage
1420)
ce44c50e 1421{
fb46a9a6
DW
1422 // We might be previewing, so return TRUE to let it continue.
1423 return TRUE;
5fd2b2c6 1424} // end of wxDC::StartDoc
fb46a9a6
DW
1425
1426void wxDC::EndDoc()
1427{
5fd2b2c6 1428} // end of wxDC::EndDoc
fb46a9a6
DW
1429
1430void wxDC::StartPage()
1431{
5fd2b2c6 1432} // end of wxDC::StartPage
fb46a9a6
DW
1433
1434void wxDC::EndPage()
1435{
5fd2b2c6 1436} // end of wxDC::EndPage
fb46a9a6
DW
1437
1438// ---------------------------------------------------------------------------
1439// text metrics
1440// ---------------------------------------------------------------------------
1441
7cdc2f1e 1442wxCoord wxDC::GetCharHeight() const
fb46a9a6 1443{
05a8bfed
DW
1444 FONTMETRICS vFM; // metrics structure
1445
1446 ::GpiQueryFontMetrics( m_hPS
1447 ,sizeof(FONTMETRICS)
1448 ,&vFM
1449 );
1450 return YDEV2LOGREL(vFM.lXHeight);
fb46a9a6
DW
1451}
1452
7cdc2f1e 1453wxCoord wxDC::GetCharWidth() const
fb46a9a6 1454{
05a8bfed
DW
1455 FONTMETRICS vFM; // metrics structure
1456
1457 ::GpiQueryFontMetrics( m_hPS
1458 ,sizeof(FONTMETRICS)
1459 ,&vFM
1460 );
1461 return XDEV2LOGREL(vFM.lAveCharWidth);
7e99520b
DW
1462}
1463
1464void wxDC::DoGetTextExtent(
1465 const wxString& rsString
1466, wxCoord* pvX
1467, wxCoord* pvY
f44fdfb0 1468, wxCoord* pvDescent
7e99520b
DW
1469, wxCoord* pvExternalLeading
1470, wxFont* pTheFont
1471) const
1472{
1473 POINTL avPoint[TXTBOX_COUNT];
1474 POINTL vPtMin;
1475 POINTL vPtMax;
1476 int i;
1477 int l;
1478 FONTMETRICS vFM; // metrics structure
1479 BOOL bRc;
1480 char* pStr;
1481 ERRORID vErrorCode; // last error id code
1482 wxFont* pFontToUse = (wxFont*)pTheFont;
1483
2c4a8d17
DW
1484 char zMsg[128]; // DEBUG
1485 wxString sError;
1486
7e99520b
DW
1487 if (!pFontToUse)
1488 pFontToUse = (wxFont*)&m_font;
1489 l = rsString.length();
1490 pStr = (PCH) rsString.c_str();
fb46a9a6 1491
7e99520b
DW
1492 //
1493 // In world coordinates.
1494 //
1495 bRc = ::GpiQueryTextBox( m_hPS
1496 ,l
1497 ,pStr
1498 ,TXTBOX_COUNT // return maximum information
1499 ,avPoint // array of coordinates points
f44fdfb0 1500 );
7e99520b
DW
1501 if(!bRc)
1502 {
1503 vErrorCode = ::WinGetLastError(wxGetInstance());
2c4a8d17
DW
1504 sError = wxPMErrorToStr(vErrorCode);
1505 // DEBUG
1506 sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str());
1507 (void)wxMessageBox( "wxWindows Menu sample"
1508 ,zMsg
1509 ,wxICON_INFORMATION
1510 );
7e99520b
DW
1511 }
1512
1513 vPtMin.x = avPoint[0].x;
1514 vPtMax.x = avPoint[0].x;
1515 vPtMin.y = avPoint[0].y;
1516 vPtMax.y = avPoint[0].y;
1517 for (i = 1; i < 4; i++)
1518 {
1519 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1520 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1521 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1522 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1523 }
1524 ::GpiQueryFontMetrics( m_hPS
1525 ,sizeof(FONTMETRICS)
1526 ,&vFM
1527 );
1528
1529 if (pvX)
1530 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1531 if (pvY)
1532 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1533 if (pvDescent)
1534 *pvDescent = vFM.lMaxDescender;
f44fdfb0 1535 if (pvExternalLeading)
7e99520b 1536 *pvExternalLeading = vFM.lExternalLeading;
fb46a9a6
DW
1537}
1538
5fd2b2c6
DW
1539void wxDC::SetMapMode(
1540 int nMode
1541)
fb46a9a6 1542{
5fd2b2c6
DW
1543 int nPixelWidth = 0;
1544 int nPixelHeight = 0;
1545 int nMmWidth = 1;
1546 int nMmHeight = 1;
1547 LONG lArray[CAPS_VERTICAL_RESOLUTION];
fb46a9a6 1548
5fd2b2c6
DW
1549 m_mappingMode = nMode;
1550
1551 if(::DevQueryCaps( m_hDC
1552 ,CAPS_FAMILY
1553 ,CAPS_VERTICAL_RESOLUTION
1554 ,lArray
1555 ))
1556 {
1557 LONG lHorzRes;
1558 LONG lVertRes;
1559
1560 nPixelWidth = lArray[CAPS_WIDTH];
1561 nPixelHeight = lArray[CAPS_HEIGHT];
1562 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
1563 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
1564 nMmWidth = (lHorzRes/1000) * nPixelWidth;
1565 nMmWidth = (lVertRes/1000) * nPixelHeight;
1566 }
1567 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
1568 {
1569 return;
1570 }
1571
1572 double dMm2pixelsX = nPixelWidth/nMmWidth;
1573 double dMm2pixelsY = nPixelHeight/nMmHeight;
1574
1575 switch (nMode)
1576 {
1577 case wxMM_TWIPS:
1578 m_logicalScaleX = (twips2mm * dMm2pixelsX);
1579 m_logicalScaleY = (twips2mm * dMm2pixelsY);
1580 break;
1581
1582 case wxMM_POINTS:
1583 m_logicalScaleX = (pt2mm * dMm2pixelsX);
1584 m_logicalScaleY = (pt2mm * dMm2pixelsY);
1585 break;
1586
1587 case wxMM_METRIC:
1588 m_logicalScaleX = dMm2pixelsX;
1589 m_logicalScaleY = dMm2pixelsY;
1590 break;
1591
1592 case wxMM_LOMETRIC:
1593 m_logicalScaleX = (dMm2pixelsX/10.0);
1594 m_logicalScaleY = (dMm2pixelsY/10.0);
1595 break;
1596
1597 case wxMM_TEXT:
1598 default:
1599 m_logicalScaleX = 1.0;
1600 m_logicalScaleY = 1.0;
1601 break;
1602 }
1603 SIZEL vSize;
1604 ULONG ulOptions;
1605
1606 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
1607 if (!ulOptions & PU_ARBITRARY)
1608 {
1609 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
1610 ::GpiSetPS(m_hPS, &vSize, ulOptions);
1611 }
1612 m_nWindowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT);
1613 m_nWindowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT);
1614 // ????
1615}; // end of wxDC::SetMapMode
1616
1617void wxDC::SetUserScale(
1618 double dX
1619, double dY
1620)
fb46a9a6 1621{
5fd2b2c6
DW
1622 m_userScaleX = dX;
1623 m_userScaleY = dY;
fb46a9a6
DW
1624
1625 SetMapMode(m_mappingMode);
5fd2b2c6 1626} // end of wxDC::SetUserScale
fb46a9a6 1627
5fd2b2c6
DW
1628void wxDC::SetAxisOrientation(
1629 bool bXLeftRight
1630, bool bYBottomUp
1631)
fb46a9a6 1632{
5fd2b2c6
DW
1633 m_signX = bXLeftRight ? 1 : -1;
1634 m_signY = bYBottomUp ? -1 : 1;
fb46a9a6
DW
1635
1636 SetMapMode(m_mappingMode);
5fd2b2c6 1637} // end of wxDC::SetAxisOrientation
fb46a9a6 1638
5fd2b2c6
DW
1639void wxDC::SetSystemScale(
1640 double dX
1641, double dY
1642)
fb46a9a6 1643{
5fd2b2c6
DW
1644 m_scaleX = dX;
1645 m_scaleY = dY;
fb46a9a6
DW
1646
1647 SetMapMode(m_mappingMode);
5fd2b2c6 1648} // end of wxDC::SetSystemScale
fb46a9a6 1649
5fd2b2c6
DW
1650void wxDC::SetLogicalOrigin(
1651 wxCoord vX
1652, wxCoord vY
1653)
fb46a9a6 1654{
5fd2b2c6
DW
1655 RECTL vRect;
1656
1657 ::GpiQueryPageViewport( m_hPS
1658 ,&vRect
1659 );
1660 vRect.xRight -= vX;
1661 vRect.yTop += vY;
1662 vRect.xLeft = vX;
1663 vRect.yBottom = vY;
1664 ::GpiSetPageViewport( m_hPS
1665 ,&vRect
1666 );
1667}; // end of wxDC::SetLogicalOrigin
fb46a9a6 1668
8d854fa9 1669void wxDC::SetDeviceOrigin(
5fd2b2c6
DW
1670 wxCoord vX
1671, wxCoord vY
8d854fa9 1672)
fb46a9a6 1673{
26ac77db
DW
1674 RECTL vRect;
1675
5fd2b2c6
DW
1676 m_deviceOriginX = vX;
1677 m_deviceOriginY = vY;
26ac77db
DW
1678 ::GpiQueryPageViewport( m_hPS
1679 ,&vRect
1680 );
5fd2b2c6
DW
1681 vRect.xLeft += vX;
1682 vRect.xRight += vX;
1683 vRect.yBottom -= vY;
1684 vRect.yTop -= vY;
26ac77db
DW
1685 ::GpiSetPageViewport( m_hPS
1686 ,&vRect
1687 );
5fd2b2c6 1688}; // end of wxDC::SetDeviceOrigin
fb46a9a6
DW
1689
1690// ---------------------------------------------------------------------------
1691// coordinates transformations
1692// ---------------------------------------------------------------------------
1693
7cdc2f1e 1694wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
fb46a9a6 1695{
f6bcfd97
BP
1696 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1697}
fb46a9a6 1698
7cdc2f1e 1699wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
fb46a9a6 1700{
f6bcfd97
BP
1701 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX));
1702}
fb46a9a6 1703
7cdc2f1e 1704wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
fb46a9a6 1705{
f6bcfd97
BP
1706 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
1707}
fb46a9a6 1708
7cdc2f1e 1709wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
fb46a9a6 1710{
f6bcfd97
BP
1711 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY));
1712}
fb46a9a6 1713
7cdc2f1e 1714wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
fb46a9a6 1715{
f6bcfd97
BP
1716 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
1717}
fb46a9a6 1718
7cdc2f1e 1719wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
fb46a9a6 1720{
f6bcfd97
BP
1721 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX);
1722}
fb46a9a6 1723
7cdc2f1e 1724wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
fb46a9a6 1725{
f6bcfd97
BP
1726 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
1727}
fb46a9a6 1728
7cdc2f1e 1729wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
fb46a9a6 1730{
f6bcfd97
BP
1731 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY);
1732}
fb46a9a6
DW
1733
1734// ---------------------------------------------------------------------------
1735// bit blit
1736// ---------------------------------------------------------------------------
1737
5afb9458
DW
1738bool wxDC::DoBlit(
1739 wxCoord vXdest
1740, wxCoord vYdest
1741, wxCoord vWidth
1742, wxCoord vHeight
1743, wxDC* pSource
1744, wxCoord vXsrc
1745, wxCoord vYsrc
1746, int nRop
1747, bool bUseMask
1748)
fb46a9a6 1749{
5afb9458
DW
1750 wxMask* pMask = NULL;
1751 CHARBUNDLE vCbnd;
1752 COLORREF vOldTextColor;
1753 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
5afb9458
DW
1754
1755 if (bUseMask)
1756 {
1757 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
1758
1759 pMask = rBmp.GetMask();
1760 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
1761 {
1762 bUseMask = FALSE;
1763 }
1764 }
1765
1766 ::GpiQueryAttrs( m_hPS
1767 ,PRIM_CHAR
1768 ,CBB_COLOR
1769 ,&vCbnd
1770 );
1771 vOldTextColor = (COLORREF)vCbnd.lColor;
1772
1773 if (m_textForegroundColour.Ok())
1774 {
1775 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
1776 ::GpiSetAttrs( m_hPS // presentation-space handle
1777 ,PRIM_CHAR // Char primitive.
1778 ,CBB_COLOR // sets color.
1779 ,0
1780 ,&vCbnd // buffer for attributes.
1781 );
1782 }
1783 if (m_textBackgroundColour.Ok())
1784 {
1785 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
1786 }
1787
1788 LONG lRop = ROP_SRCCOPY;
1789
1790 switch (nRop)
1791 {
1792 case wxXOR: lRop = ROP_SRCINVERT; break;
1793 case wxINVERT: lRop = ROP_DSTINVERT; break;
1794 case wxOR_REVERSE: lRop = 0x00DD0228; break;
1795 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
1796 case wxCLEAR: lRop = ROP_ZERO; break;
1797 case wxSET: lRop = ROP_ONE; break;
1798 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
1799 case wxAND: lRop = ROP_SRCAND; break;
1800 case wxOR: lRop = ROP_SRCPAINT; break;
1801 case wxEQUIV: lRop = 0x00990066; break;
1802 case wxNAND: lRop = 0x007700E6; break;
1803 case wxAND_INVERT: lRop = 0x00220326; break;
1804 case wxCOPY: lRop = ROP_SRCCOPY; break;
1805 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
1806 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
1807 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
1808 default:
1809 wxFAIL_MSG( wxT("unsupported logical function") );
1810 return FALSE;
1811 }
1812
1813 bool bSuccess;
b02121c3 1814
5afb9458
DW
1815 if (bUseMask)
1816 {
1817 //
1818 // Blit bitmap with mask
1819 //
1820
1821 //
b02121c3 1822 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
5afb9458 1823 //
b02121c3
DW
1824 HDC hDCMask;
1825 HDC hDCBuffer;
1826 HPS hPSMask;
1827 HPS hPSBuffer;
1828 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1829 BITMAPINFOHEADER2 vBmpHdr;
1830 SIZEL vSize = {0, 0};
1831 LONG rc;
1832
1833 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
1834 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
1835 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
1836 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
1837
1838 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
1839 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
1840 vBmpHdr.cx = vWidth;
1841 vBmpHdr.cy = vHeight;
1842 vBmpHdr.cPlanes = 1;
1843 vBmpHdr.cBitCount = 24;
1844
1845 HBITMAP hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
1846 POINTL aPoint1[4] = { 0, 0
1847 ,vWidth, vHeight
1848 ,vXdest, vYdest
1849 ,vXdest + vWidth, vYdest + vHeight
1850 };
1851 POINTL aPoint2[4] = { 0, 0
1852 ,vWidth, vHeight
1853 ,vXsrc, vYsrc
1854 ,vXsrc + vWidth, vYsrc + vHeight
1855 };
1856 POINTL aPoint3[4] = { vXdest, vYdest
23e356de
DW
1857 ,vXdest + vWidth, vYdest + vHeight
1858 ,vXsrc, vYsrc
1859 ,vXsrc + vWidth, vYsrc + vHeight
1860 };
1861 POINTL aPoint4[4] = { vXdest, vYdest
b02121c3
DW
1862 ,vXdest + vWidth, vYdest + vHeight
1863 ,0, 0
1864 ,vWidth, vHeight
1865 };
1866 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
1867 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
5afb9458 1868
b02121c3
DW
1869 //
1870 // Copy dest to buffer
1871 //
1872 rc = ::GpiBitBlt( hPSBuffer
1873 ,GetHPS()
1874 ,4L
1875 ,aPoint1
1876 ,ROP_SRCCOPY
1877 ,BBO_IGNORE
1878 );
1879 if (rc == GPI_ERROR)
1880 {
1881 wxLogLastError(wxT("BitBlt"));
1882 }
5afb9458 1883
b02121c3
DW
1884 //
1885 // Copy src to buffer using selected raster op
1886 //
1887 rc = ::GpiBitBlt( hPSBuffer
1888 ,GetHPS()
1889 ,4L
1890 ,aPoint2
1891 ,lRop
1892 ,BBO_IGNORE
1893 );
1894 if (rc == GPI_ERROR)
1895 {
1896 wxLogLastError(wxT("BitBlt"));
1897 }
5afb9458 1898
b02121c3
DW
1899 //
1900 // Set masked area in buffer to BLACK (pixel value 0)
1901 //
1902 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
1903 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
1904
1905 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
1906 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
1907
1908 rc = ::GpiBitBlt( hPSBuffer
1909 ,hPSMask
1910 ,4L
1911 ,aPoint2
1912 ,ROP_SRCAND
1913 ,BBO_IGNORE
1914 );
1915 if (rc == GPI_ERROR)
1916 {
1917 wxLogLastError(wxT("BitBlt"));
1918 }
5afb9458 1919
b02121c3
DW
1920 //
1921 // Set unmasked area in dest to BLACK
1922 //
1923 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
1924 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
1925 rc = ::GpiBitBlt( GetHPS()
1926 ,hPSMask
1927 ,4L
23e356de 1928 ,aPoint3
b02121c3
DW
1929 ,ROP_SRCAND
1930 ,BBO_IGNORE
1931 );
1932 if (rc == GPI_ERROR)
1933 {
1934 wxLogLastError(wxT("BitBlt"));
5afb9458 1935 }
b02121c3
DW
1936
1937 //
1938 // Restore colours to original values
1939 //
1940 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
1941 ::GpiSetColor(GetHPS(), vPrevCol);
1942
1943 //
1944 // OR buffer to dest
1945 //
1946 rc = ::GpiBitBlt( GetHPS()
1947 ,hPSMask
1948 ,4L
23e356de 1949 ,aPoint4
b02121c3
DW
1950 ,ROP_SRCPAINT
1951 ,BBO_IGNORE
1952 );
1953 if (rc == GPI_ERROR)
1954 {
1955 bSuccess = FALSE;
1956 wxLogLastError(wxT("BitBlt"));
1957 }
1958
1959 //
1960 // Tidy up temporary DCs and bitmap
1961 //
1962 ::GpiSetBitmap(hPSMask, NULLHANDLE);
1963 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
1964 ::GpiDestroyPS(hPSMask);
1965 ::GpiDestroyPS(hPSBuffer);
1966 ::DevCloseDC(hDCMask);
1967 ::DevCloseDC(hDCBuffer);
1968 ::GpiDeleteBitmap(hBufBitmap);
1969 bSuccess = TRUE;
5afb9458 1970 }
b02121c3
DW
1971 else // no mask, just BitBlt() it
1972 {
1973 POINTL aPoint[4] = { vXdest, vYdest
1974 ,vXdest + vWidth, vYdest + vHeight
1975 ,vXsrc, vYsrc
1976 ,vXsrc + vWidth, vYsrc + vHeight
1977 };
1978
5afb9458
DW
1979 bSuccess = (::GpiBitBlt( m_hPS
1980 ,pSource->GetHPS()
1981 ,4L
1982 ,aPoint
1983 ,lRop
1984 ,BBO_IGNORE
1985 ) != GPI_ERROR);
1986 if (!bSuccess )
1987 {
1988 wxLogLastError(wxT("BitBlt"));
1989 }
b02121c3 1990 }
5afb9458
DW
1991 vCbnd.lColor = (LONG)vOldTextColor;
1992 ::GpiSetAttrs( m_hPS // presentation-space handle
1993 ,PRIM_CHAR // Char primitive.
1994 ,CBB_COLOR // sets color.
1995 ,0
1996 ,&vCbnd // buffer for attributes.
1997 );
1998 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
1999 return bSuccess;
fb46a9a6
DW
2000}
2001
5fd2b2c6
DW
2002void wxDC::DoGetSize(
2003 int* pnWidth
2004, int* pnHeight
2005) const
fb46a9a6 2006{
5fd2b2c6
DW
2007 LONG lArray[CAPS_HEIGHT];
2008
2009 if(::DevQueryCaps( m_hDC
2010 ,CAPS_FAMILY
2011 ,CAPS_HEIGHT
2012 ,lArray
2013 ))
2014 {
2015 *pnWidth = lArray[CAPS_WIDTH];
2016 *pnHeight = lArray[CAPS_HEIGHT];
2017 }
2018}; // end of wxDC::DoGetSize(
fb46a9a6 2019
5fd2b2c6
DW
2020void wxDC::DoGetSizeMM(
2021 int* pnWidth
2022, int* pnHeight
2023) const
fb46a9a6 2024{
5fd2b2c6
DW
2025 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2026
2027 if(::DevQueryCaps( m_hDC
2028 ,CAPS_FAMILY
2029 ,CAPS_VERTICAL_RESOLUTION
2030 ,lArray
2031 ))
2032 {
2033 int nWidth;
2034 int nHeight;
2035 int nHorzRes;
2036 int nVertRes;
2037
2038 nWidth = lArray[CAPS_WIDTH];
2039 nHeight = lArray[CAPS_HEIGHT];
2040 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2041 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2042 nWidth = (nHorzRes/1000) * nWidth;
2043 nHeight = (nVertRes/1000) * nHeight;
2044 }
2045}; // end of wxDC::DoGetSizeMM
fb46a9a6
DW
2046
2047wxSize wxDC::GetPPI() const
2048{
5fd2b2c6
DW
2049 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2050 int nWidth;
2051 int nHeight;
fb46a9a6 2052
5fd2b2c6
DW
2053 if(::DevQueryCaps( m_hDC
2054 ,CAPS_FAMILY
2055 ,CAPS_VERTICAL_RESOLUTION
2056 ,lArray
2057 ))
2058 {
2059 int nPelWidth;
2060 int nPelHeight;
2061 int nHorzRes;
2062 int nVertRes;
2063
2064 nPelWidth = lArray[CAPS_WIDTH];
2065 nPelHeight = lArray[CAPS_HEIGHT];
2066 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2067 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2068 nWidth = (nHorzRes/39.3) * nPelWidth;
2069 nHeight = (nVertRes/39.3) * nPelHeight;
2070 }
2071 return (wxSize(nWidth,nHeight));
2072} // end of wxDC::GetPPI
2073
2074void wxDC::SetLogicalScale(
2075 double dX
2076, double dY
2077)
fb46a9a6 2078{
5fd2b2c6
DW
2079 m_logicalScaleX = dX;
2080 m_logicalScaleY = dY;
2081}; // end of wxDC::SetLogicalScale
fb46a9a6
DW
2082
2083#if WXWIN_COMPATIBILITY
2084void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
2085 float *descent, float *externalLeading,
2086 wxFont *theFont, bool use16bit) const
2087{
7cdc2f1e 2088 wxCoord x1, y1, descent1, externalLeading1;
fb46a9a6
DW
2089 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
2090 *x = x1; *y = y1;
2091 if (descent)
2092 *descent = descent1;
2093 if (externalLeading)
2094 *externalLeading = externalLeading1;
2095}
2096#endif
2097