]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dc.cpp
Source cleaning. wxMotif/OS2 adjustements.
[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 8// Copyright: (c) David Webster
65571936 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"
272ebf16
SN
26#if wxUSE_STATUSBAR
27 #include "wx/statusbr.h"
28#endif
0e320a79
DW
29#endif
30
542e68c7 31#include "wx/module.h"
fb46a9a6
DW
32#include "wx/dcprint.h"
33
34#include <string.h>
fb46a9a6
DW
35
36#include "wx/os2/private.h"
0e320a79 37
fb46a9a6 38 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
0e320a79 39
5fd2b2c6 40//
77ffb593 41// wxWidgets uses the Microsoft convention that the origin is the UPPER left.
5fd2b2c6 42// Native OS/2 however in the GPI and PM define the origin as the LOWER left.
77ffb593 43// In order to map OS/2 GPI/PM y coordinates to wxWidgets coordinates we must
5fd2b2c6
DW
44// perform the following transformation:
45//
46// Parent object height: POBJHEIGHT
47// Desried origin: WXORIGINY
48// Object to place's height: OBJHEIGHT
49//
77ffb593 50// To get the OS2 position from the wxWidgets one:
5fd2b2c6
DW
51//
52// OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
53//
54// For OS/2 wxDC's we will always determine m_vRclPaint as the size of the
55// OS/2 Presentation Space associated with the device context. y is the
77ffb593 56// desired application's y coordinate of the origin in wxWidgets space.
5fd2b2c6
DW
57// objy is the height of the object we are going to draw.
58//
59#define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
60
fb46a9a6 61// ---------------------------------------------------------------------------
0e320a79 62// constants
fb46a9a6 63// ---------------------------------------------------------------------------
1408104d 64
fb46a9a6 65static const int VIEWPORT_EXTENT = 1000;
1408104d 66
fb46a9a6
DW
67static const int MM_POINTS = 9;
68static const int MM_METRIC = 10;
1408104d 69
f6bcfd97
BP
70// ---------------------------------------------------------------------------
71// private functions
72// ---------------------------------------------------------------------------
73
74// convert degrees to radians
75static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
76
7e99520b
DW
77int SetTextColor(
78 HPS hPS
79, int nForegroundColour
80)
81{
82 CHARBUNDLE vCbnd;
83
84 vCbnd.lColor = nForegroundColour;
85 ::GpiSetAttrs( hPS // presentation-space handle
86 ,PRIM_CHAR // Char primitive.
87 ,CBB_COLOR // sets color.
88 ,0 //
89 ,&vCbnd // buffer for attributes.
90 );
91 return 0;
92}
93
94int QueryTextBkColor(
95 HPS hPS
96)
97{
98 CHARBUNDLE vCbnd;
99
f44fdfb0
DW
100 ::GpiQueryAttrs( hPS // presentation-space handle
101 ,PRIM_CHAR // Char primitive.
102 ,CBB_BACK_COLOR // Background color.
103 ,&vCbnd // buffer for attributes.
104 );
7e99520b
DW
105 return vCbnd.lBackColor;
106}
107
108
109int SetTextBkColor(
110 HPS hPS
111, int nBackgroundColour
112)
113{
114 CHARBUNDLE vCbnd;
115 int rc;
116
117 rc = QueryTextBkColor(hPS);
118
119 vCbnd.lBackColor = nBackgroundColour;
120 ::GpiSetAttrs(hPS, // presentation-space handle
121 PRIM_CHAR, // Char primitive.
122 CBB_BACK_COLOR, // sets color.
123 0,
124 &vCbnd // buffer for attributes.
125 );
126 return rc;
127}
128
129int SetBkMode(
130 HPS hPS
131, int nBackgroundMode
132)
133{
134 if(nBackgroundMode == wxTRANSPARENT)
135 ::GpiSetBackMix( hPS
136 ,BM_LEAVEALONE
137 );
138 else
139 // the background of the primitive takes over whatever is underneath.
140 ::GpiSetBackMix( hPS
141 ,BM_OVERPAINT
142 );
143 return 0;
144}
145
fb46a9a6
DW
146// ===========================================================================
147// implementation
148// ===========================================================================
1408104d 149
893758d5
DW
150#if wxUSE_DC_CACHEING
151
152/*
153 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
154 * improve it in due course, either using arrays, or simply storing pointers to one
155 * entry for the bitmap, and two for the DCs. -- JACS
156 */
157
158// ---------------------------------------------------------------------------
159// wxDCCacheEntry
160// ---------------------------------------------------------------------------
161
162wxList wxDC::m_svBitmapCache;
163wxList wxDC::m_svDCCache;
164
165wxDCCacheEntry::wxDCCacheEntry(
166 WXHBITMAP hBitmap
167, int nWidth
168, int nHeight
169, int nDepth
170)
171{
172 m_hBitmap = hBitmap;
173 m_hPS = NULLHANDLE;
174 m_nWidth = nWidth;
175 m_nHeight = nHeight;
176 m_nDepth = nDepth;
177} // end of wxDCCacheEntry::wxDCCacheEntry
178
179wxDCCacheEntry::wxDCCacheEntry(
180 HPS hPS
181, int nDepth
182)
183{
184 m_hBitmap = NULLHANDLE;
185 m_hPS = hPS;
186 m_nWidth = 0;
187 m_nHeight = 0;
188 m_nDepth = nDepth;
189} // end of wxDCCacheEntry::wxDCCacheEntry
190
191wxDCCacheEntry::~wxDCCacheEntry()
192{
193 if (m_hBitmap)
194 ::GpiDeleteBitmap(m_hBitmap);
195 if (m_hPS)
196 ::GpiDestroyPS(m_hPS);
197} // end of wxDCCacheEntry::~wxDCCacheEntry
198
199wxDCCacheEntry* wxDC::FindBitmapInCache(
200 HPS hPS
201, int nWidth
202, int nHeight
203)
204{
19193a2c 205 int nDepth = 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
893758d5
DW
206 wxNode* pNode = m_svBitmapCache.First();
207 BITMAPINFOHEADER2 vBmpHdr;
208
209 while(pNode)
210 {
211 wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data();
212
213 if (pEntry->m_nDepth == nDepth)
214 {
215 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
216
217 if (pEntry->m_nWidth < nWidth || pEntry->m_nHeight < nHeight)
218 {
219 ::GpiDeleteBitmap((HBITMAP)pEntry->m_hBitmap);
220 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
221 vBmpHdr.cx = nWidth;
222 vBmpHdr.cy = nHeight;
223 vBmpHdr.cPlanes = 1;
6670f564 224 vBmpHdr.cBitCount = (USHORT)nDepth;
893758d5
DW
225
226 pEntry->m_hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS
227 ,&vBmpHdr
228 ,0L, NULL, NULL
229 );
230 if (!pEntry->m_hBitmap)
231 {
232 wxLogLastError(wxT("CreateCompatibleBitmap"));
233 }
234 pEntry->m_nWidth = nWidth;
235 pEntry->m_nHeight = nHeight;
236 return pEntry;
237 }
238 return pEntry;
239 }
240 pNode = pNode->Next();
241 }
242 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
243 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
244 vBmpHdr.cx = nWidth;
245 vBmpHdr.cy = nHeight;
246 vBmpHdr.cPlanes = 1;
6670f564 247 vBmpHdr.cBitCount = (USHORT)nDepth;
893758d5
DW
248
249 WXHBITMAP hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS
250 ,&vBmpHdr
251 ,0L, NULL, NULL
252 );
253 if (!hBitmap)
254 {
255 wxLogLastError(wxT("CreateCompatibleBitmap"));
256 }
257 wxDCCacheEntry* pEntry = new wxDCCacheEntry( hBitmap
258 ,nWidth
259 ,nHeight
260 ,nDepth
261 );
262 AddToBitmapCache(pEntry);
263 return pEntry;
264} // end of FindBitmapInCache
265
266wxDCCacheEntry* wxDC::FindDCInCache(
267 wxDCCacheEntry* pNotThis
268, HPS hPS
269)
270{
271 int nDepth = 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
272 wxNode* pNode = m_svDCCache.First();
273
274 while(pNode)
275 {
276 wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data();
277
278 //
279 // Don't return the same one as we already have
280 //
281 if (!pNotThis || (pNotThis != pEntry))
282 {
283 if (pEntry->m_nDepth == nDepth)
284 {
285 return pEntry;
286 }
287 }
288 pNode = pNode->Next();
289 }
290 wxDCCacheEntry* pEntry = new wxDCCacheEntry( hPS
291 ,nDepth
292 );
293 AddToDCCache(pEntry);
294 return pEntry;
295} // end of wxDC::FindDCInCache
296
297void wxDC::AddToBitmapCache(
298 wxDCCacheEntry* pEntry
299)
300{
301 m_svBitmapCache.Append(pEntry);
302} // end of wxDC::AddToBitmapCache
303
304void wxDC::AddToDCCache(
305 wxDCCacheEntry* pEntry
306)
307{
308 m_svDCCache.Append(pEntry);
309} // end of wxDC::AddToDCCache
310
311void wxDC::ClearCache()
312{
aad6765c 313 m_svBitmapCache.DeleteContents(true);
893758d5 314 m_svBitmapCache.Clear();
aad6765c
JS
315 m_svBitmapCache.DeleteContents(false);
316 m_svDCCache.DeleteContents(true);
893758d5 317 m_svDCCache.Clear();
aad6765c 318 m_svDCCache.DeleteContents(false);
893758d5
DW
319} // end of wxDC::ClearCache
320
321// Clean up cache at app exit
322class wxDCModule : public wxModule
323{
324public:
aad6765c 325 virtual bool OnInit() { return true; }
893758d5
DW
326 virtual void OnExit() { wxDC::ClearCache(); }
327
328private:
329 DECLARE_DYNAMIC_CLASS(wxDCModule)
330}; // end of CLASS wxDCModule
331
332IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
333
334#endif // ndef for wxUSE_DC_CACHEING
335
fb46a9a6 336// ---------------------------------------------------------------------------
0e320a79 337// wxDC
fb46a9a6 338// ---------------------------------------------------------------------------
0e320a79
DW
339
340wxDC::wxDC(void)
341{
7e99520b 342 m_pCanvas = NULL;
c3d43472 343
7e99520b
DW
344 m_hOldBitmap = 0;
345 m_hOldPen = 0;
346 m_hOldBrush = 0;
347 m_hOldFont = 0;
348 m_hOldPalette = 0;
ce44c50e 349
aad6765c 350 m_bOwnsDC = false;
7e99520b 351 m_hDC = 0;
7e99520b
DW
352 m_hOldPS = NULL;
353 m_hPS = NULL;
aad6765c 354 m_bIsPaintTime = false; // True at Paint Time
2b0ec34b 355
aad6765c 356 wxColour vColor( wxT("BLACK") );
2b0ec34b 357 m_pen.SetColour(vColor);
aad6765c
JS
358
359 vColor.Set( wxT("WHITE") );
2b0ec34b 360 m_brush.SetColour(vColor);
aad6765c 361
e1a688e4 362} // end of wxDC::wxDC
0e320a79
DW
363
364wxDC::~wxDC(void)
365{
e1a688e4
DW
366 if ( m_hDC != 0 )
367 {
368 SelectOldObjects(m_hDC);
369
370 // if we own the HDC, we delete it, otherwise we just release it
371
372 if (m_bOwnsDC)
373 {
374 if(m_hPS)
375 {
376 ::GpiAssociate(m_hPS, NULLHANDLE);
377 ::GpiDestroyPS(m_hPS);
378 }
379 m_hPS = NULLHANDLE;
380 ::DevCloseDC((HDC)m_hDC);
381 }
382 else
383 {
384 //
385 // Just Dissacociate, not destroy if we don't own the DC
386 //
387 if(m_hPS)
388 {
389 ::GpiAssociate(m_hPS, NULLHANDLE);
390 }
391 }
392 }
393} // end of wxDC::~wxDC
0e320a79 394
fb46a9a6
DW
395// This will select current objects out of the DC,
396// which is what you have to do before deleting the
397// DC.
f07bb01b
DW
398void wxDC::SelectOldObjects(
399 WXHDC hPS
400)
0e320a79 401{
f07bb01b 402 if (hPS)
fb46a9a6 403 {
f6bcfd97 404 if (m_hOldBitmap)
fb46a9a6 405 {
f07bb01b 406 ::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap);
f6bcfd97 407 if (m_vSelectedBitmap.Ok())
fb46a9a6 408 {
f6bcfd97 409 m_vSelectedBitmap.SetSelectedInto(NULL);
fb46a9a6
DW
410 }
411 }
f6bcfd97 412 m_hOldBitmap = 0;
f07bb01b
DW
413 //
414 // OS/2 has no other native GDI objects to set in a PS/DC like windows
415 //
f6bcfd97 416 m_hOldPen = 0;
f6bcfd97 417 m_hOldBrush = 0;
f6bcfd97 418 m_hOldFont = 0;
f6bcfd97 419 m_hOldPalette = 0;
fb46a9a6 420 }
0e320a79 421
f6bcfd97
BP
422 m_brush = wxNullBrush;
423 m_pen = wxNullPen;
424 m_palette = wxNullPalette;
425 m_font = wxNullFont;
fb46a9a6 426 m_backgroundBrush = wxNullBrush;
f6bcfd97 427 m_vSelectedBitmap = wxNullBitmap;
e1a688e4 428} // end of wxDC::SelectOldObjects
0e320a79 429
fb46a9a6
DW
430// ---------------------------------------------------------------------------
431// clipping
432// ---------------------------------------------------------------------------
0e320a79 433
fa5593ac
DW
434#define DO_SET_CLIPPING_BOX() \
435{ \
436 RECTL rect; \
437 \
438 ::GpiQueryClipBox(m_hPS, &rect); \
439 \
440 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
441 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
442 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
443 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
fb46a9a6 444}
0e320a79 445
fa5593ac 446void wxDC::DoSetClippingRegion(
5fd2b2c6
DW
447 wxCoord vX
448, wxCoord vY
449, wxCoord vWidth
450, wxCoord vHeight
fa5593ac 451)
0e320a79 452{
fa5593ac
DW
453 RECTL vRect;
454
5fd2b2c6 455 vY = OS2Y(vY,vHeight);
aad6765c 456 m_clipping = true;
5fd2b2c6
DW
457 vRect.xLeft = vX;
458 vRect.yTop = vY + vHeight;
459 vRect.xRight = vX + vWidth;
460 vRect.yBottom = vY;
fa5593ac
DW
461 ::GpiIntersectClipRectangle(m_hPS, &vRect);
462 DO_SET_CLIPPING_BOX()
463} // end of wxDC::DoSetClippingRegion
464
465void wxDC::DoSetClippingRegionAsRegion(
466 const wxRegion& rRegion
467)
0e320a79 468{
fa5593ac
DW
469 wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
470 HRGN hRgnOld;
471
aad6765c 472 m_clipping = true;
fa5593ac
DW
473 ::GpiSetClipRegion( m_hPS
474 ,(HRGN)rRegion.GetHRGN()
475 ,&hRgnOld
476 );
477 DO_SET_CLIPPING_BOX()
478} // end of wxDC::DoSetClippingRegionAsRegion
0e320a79 479
fb46a9a6 480void wxDC::DestroyClippingRegion(void)
0e320a79 481{
fa5593ac
DW
482 if (m_clipping && m_hPS)
483 {
484 HRGN hRgnOld;
485 RECTL vRect;
486
487 // TODO: this should restore the previous clipped region
488 // so that OnPaint processing works correctly, and
489 // the update doesn't get destroyed after the first
490 // DestroyClippingRegion
491 vRect.xLeft = XLOG2DEV(0);
492 vRect.yTop = YLOG2DEV(32000);
493 vRect.xRight = XLOG2DEV(32000);
494 vRect.yBottom = YLOG2DEV(0);
495
496 HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
497
498 ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
499 }
d16b634f 500 ResetClipping();
fa5593ac 501} // end of wxDC::DestroyClippingRegion
0e320a79 502
fb46a9a6
DW
503// ---------------------------------------------------------------------------
504// query capabilities
505// ---------------------------------------------------------------------------
0e320a79 506
fb46a9a6 507bool wxDC::CanDrawBitmap() const
0e320a79 508{
aad6765c 509 return true;
fb46a9a6 510}
0e320a79 511
fb46a9a6 512bool wxDC::CanGetTextExtent() const
0e320a79 513{
f07bb01b 514 LONG lTechnology = 0L;
0e320a79 515
f07bb01b
DW
516 ::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology);
517 return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER);
518} // end of wxDC::CanGetTextExtent
1408104d
DW
519
520int wxDC::GetDepth() const
0e320a79 521{
f07bb01b 522 LONG lArray[CAPS_COLOR_BITCOUNT];
9da48399 523 int nBitsPerPixel = 0;
f07bb01b
DW
524
525 if(::DevQueryCaps( GetHDC()
526 ,CAPS_FAMILY
527 ,CAPS_COLOR_BITCOUNT
528 ,lArray
529 ))
530 {
531 nBitsPerPixel = (int)lArray[CAPS_COLOR_BITCOUNT];
532 }
533 return nBitsPerPixel;
534} // end of wxDC::GetDepth
0e320a79 535
fb46a9a6
DW
536// ---------------------------------------------------------------------------
537// drawing
538// ---------------------------------------------------------------------------
0e320a79 539
1408104d 540void wxDC::Clear()
0e320a79 541{
81039e0d
DW
542 //
543 // If this is a canvas DC then just fill with the background color
544 // Otherwise purge the whole thing
545 //
546 if (m_pCanvas)
547 {
548 RECTL vRect;
549
550 ::GpiQueryClipBox(m_hPS, &vRect);
551 ::WinFillRect(m_hPS, &vRect, ::GpiQueryBackColor(m_hPS));
552 }
553 else
445c7bca 554 ::GpiErase(m_hPS);
5fd2b2c6 555} // end of wxDC::Clear
0e320a79 556
1d0edc0f 557bool wxDC::DoFloodFill(
51c1d535
DW
558 wxCoord vX
559, wxCoord vY
560, const wxColour& rCol
561, int nStyle
562)
0e320a79 563{
51c1d535
DW
564 POINTL vPtlPos;
565 LONG lColor;
566 LONG lOptions;
1d0edc0f 567 LONG lHits;
aad6765c 568 bool bSuccess = false;
51c1d535
DW
569
570 vPtlPos.x = vX; // Loads x-coordinate
5fd2b2c6 571 vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate
51c1d535
DW
572 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
573 lColor = rCol.GetPixel();
574 lOptions = FF_BOUNDARY;
575 if(wxFLOOD_SURFACE == nStyle)
576 lOptions = FF_SURFACE;
577
1d0edc0f 578 if ((lHits = ::GpiFloodFill(m_hPS, lOptions, lColor)) != GPI_ERROR)
aad6765c
JS
579 bSuccess = true;
580
1a0c7d55 581 return bSuccess;
5fd2b2c6 582} // end of wxDC::DoFloodFill
0e320a79 583
51c1d535
DW
584bool wxDC::DoGetPixel(
585 wxCoord vX
586, wxCoord vY
587, wxColour* pCol
588) const
1408104d 589{
51c1d535
DW
590 POINTL vPoint;
591 LONG lColor;
592
593 vPoint.x = vX;
5fd2b2c6 594 vPoint.y = OS2Y(vY,0);
1a0c7d55 595 lColor = ::GpiQueryPel(m_hPS, &vPoint);
5fd2b2c6
DW
596
597 //
598 // return the color of the pixel
599 //
600 if(pCol)
601 pCol->Set( GetRValue(lColor)
602 ,GetGValue(lColor)
603 ,GetBValue(lColor)
604 );
1a0c7d55 605 return true;
5fd2b2c6 606} // end of wxDC::DoGetPixel
0e320a79 607
f07bb01b
DW
608void wxDC::DoCrossHair(
609 wxCoord vX
610, wxCoord vY
611)
0e320a79 612{
5fd2b2c6
DW
613 vY = OS2Y(vY,0);
614
f07bb01b
DW
615 wxCoord vX1 = vX - VIEWPORT_EXTENT;
616 wxCoord vY1 = vY - VIEWPORT_EXTENT;
617 wxCoord vX2 = vX + VIEWPORT_EXTENT;
618 wxCoord vY2 = vY + VIEWPORT_EXTENT;
619 POINTL vPoint[4];
620
621 vPoint[0].x = vX1;
5fd2b2c6 622 vPoint[0].y = vY;
f07bb01b
DW
623
624 vPoint[1].x = vX2;
5fd2b2c6 625 vPoint[1].y = vY;
f07bb01b
DW
626
627 ::GpiMove(m_hPS, &vPoint[0]);
628 ::GpiLine(m_hPS, &vPoint[1]);
629
630 vPoint[2].x = vX;
5fd2b2c6 631 vPoint[2].y = vY1;
f07bb01b
DW
632
633 vPoint[3].x = vX;
5fd2b2c6 634 vPoint[3].y = vY2;
f07bb01b
DW
635
636 ::GpiMove(m_hPS, &vPoint[2]);
637 ::GpiLine(m_hPS, &vPoint[3]);
5fd2b2c6
DW
638 CalcBoundingBox(vX1, vY1);
639 CalcBoundingBox(vX2, vY2);
f07bb01b 640} // end of wxDC::DoCrossHair
1408104d 641
7e99520b
DW
642void wxDC::DoDrawLine(
643 wxCoord vX1
644, wxCoord vY1
645, wxCoord vX2
646, wxCoord vY2
647)
0e320a79 648{
7e99520b 649 POINTL vPoint[2];
d6d749aa 650 COLORREF vColor = 0x00ffffff;
7e99520b 651
d6d749aa
DW
652 //
653 // Might be a memory DC with no Paint rect.
654 //
655 if (!(m_vRclPaint.yTop == 0 &&
656 m_vRclPaint.yBottom == 0 &&
657 m_vRclPaint.xRight == 0 &&
658 m_vRclPaint.xLeft == 0))
659 {
660 vY1 = OS2Y(vY1,0);
661 vY2 = OS2Y(vY2,0);
662 }
1c9a789e
DW
663 else
664 {
665 if (m_vSelectedBitmap != wxNullBitmap)
666 {
667 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
668 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
669 vY1 = OS2Y(vY1,0);
670 vY2 = OS2Y(vY2,0);
671 }
672 }
7e99520b 673 vPoint[0].x = vX1;
5fd2b2c6 674 vPoint[0].y = vY1;
7e99520b 675 vPoint[1].x = vX2;
5fd2b2c6 676 vPoint[1].y = vY2;
d6d749aa
DW
677 if (m_pen.Ok())
678 {
679 vColor = m_pen.GetColour().GetPixel();
680 }
681 ::GpiSetColor(m_hPS, vColor);
7e99520b
DW
682 ::GpiMove(m_hPS, &vPoint[0]);
683 ::GpiLine(m_hPS, &vPoint[1]);
5fd2b2c6
DW
684 CalcBoundingBox(vX1, vY1);
685 CalcBoundingBox(vX2, vY2);
f07bb01b 686} // end of wxDC::DoDrawLine
1408104d 687
51c1d535
DW
688//////////////////////////////////////////////////////////////////////////////
689// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
690// and ending at (x2, y2). The current pen is used for the outline and the
691// current brush for filling the shape. The arc is drawn in an anticlockwise
692// direction from the start point to the end point.
693//////////////////////////////////////////////////////////////////////////////
694void wxDC::DoDrawArc(
695 wxCoord vX1
696, wxCoord vY1
697, wxCoord vX2
698, wxCoord vY2
699, wxCoord vXc
700, wxCoord vYc
701)
1408104d 702{
51c1d535
DW
703 POINTL vPtlPos;
704 POINTL vPtlArc[2]; // Structure for current position
51c1d535
DW
705 double dRadius;
706 double dAngl1;
707 double dAngl2;
708 double dAnglmid;
709 wxCoord vXm;
710 wxCoord vYm;
711 ARCPARAMS vArcp; // Structure for arc parameters
712
713 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
714 return; // Draw point ??
715 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
716 ,(double)(vX1 - vXc)
717 ) +
718 hypot( (double)(vY2 - vYc)
719 ,(double)(vX2 - vXc)
720 )
721 );
722
723 dAngl1 = atan2( (double)(vY1 - vYc)
724 ,(double)(vX1 - vXc)
725 );
726 dAngl2 = atan2( (double)(vY2 - vYc)
727 ,(double)(vX2 - vXc)
728 );
729 if(dAngl2 < dAngl1)
730 dAngl2 += M_PI * 2;
731
732 //
733 // GpiPointArc can't draw full arc
734 //
735 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
736 {
737 //
738 // Medium point
739 //
740 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
9923c37d
DW
741 vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
742 vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
e99762c0
DW
743 DoDrawArc( vX1, vY1
744 ,vXm, vYm
745 ,vXc, vYc
51c1d535 746 );
e99762c0
DW
747 DoDrawArc( vXm, vYm
748 ,vX2, vY2
749 ,vXc, vYc
51c1d535
DW
750 );
751 return;
752 }
753
754 //
755 // Medium point
756 //
757 dAnglmid = (dAngl1 + dAngl2)/2.;
9923c37d
DW
758 vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
759 vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
51c1d535
DW
760
761 //
762 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
763 //
764 vArcp.lR = 0;
765 vArcp.lQ = 1;
766 vArcp.lP = 1;
767 vArcp.lS = 0;
768 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
769
770 vPtlPos.x = vX1; // Loads x-coordinate
771 vPtlPos.y = vY1; // Loads y-coordinate
772 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
e99762c0
DW
773 vPtlArc[0].x = vXm;
774 vPtlArc[0].y = vYm;
51c1d535
DW
775 vPtlArc[1].x = vX2;
776 vPtlArc[1].y = vY2;
77f4f0a7
WS
777#if !(defined(__WATCOMC__) && __WATCOMC__ < 1240 )
778// Open Watcom 1.3 had incomplete headers
779// that's reported and should be fixed for OW 1.4
51c1d535 780 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
6670f564 781#endif
9923c37d
DW
782 CalcBoundingBox( (wxCoord)(vXc - dRadius)
783 ,(wxCoord)(vYc - dRadius)
5fd2b2c6 784 );
9923c37d
DW
785 CalcBoundingBox( (wxCoord)(vXc + dRadius)
786 ,(wxCoord)(vYc + dRadius)
5fd2b2c6 787 );
f07bb01b 788} // end of wxDC::DoDrawArc
1408104d 789
51c1d535
DW
790void wxDC::DoDrawCheckMark(
791 wxCoord vX1
792, wxCoord vY1
793, wxCoord vWidth
794, wxCoord vHeight
795)
f6bcfd97 796{
51c1d535
DW
797 POINTL vPoint[2];
798
5fd2b2c6
DW
799 vY1 = OS2Y(vY1,vHeight);
800
51c1d535
DW
801 vPoint[0].x = vX1;
802 vPoint[0].y = vY1;
803 vPoint[1].x = vX1 + vWidth;
804 vPoint[1].y = vY1 + vHeight;
805
806 ::GpiMove(m_hPS, &vPoint[0]);
807 ::GpiBox( m_hPS // handle to a presentation space
808 ,DRO_OUTLINE // draw the box outline ? or ?
809 ,&vPoint[1] // address of the corner
810 ,0L // horizontal corner radius
811 ,0L // vertical corner radius
812 );
813 if(vWidth > 4 && vHeight > 4)
814 {
815 int nTmp;
816
817 vPoint[0].x += 2; vPoint[0].y += 2;
818 vPoint[1].x -= 2; vPoint[1].y -= 2;
819 ::GpiMove(m_hPS, &vPoint[0]);
820 ::GpiLine(m_hPS, &vPoint[1]);
821 nTmp = vPoint[0].x;
822 vPoint[0].x = vPoint[1].x;
823 vPoint[1].x = nTmp;
824 ::GpiMove(m_hPS, &vPoint[0]);
825 ::GpiLine(m_hPS, &vPoint[1]);
826 }
5fd2b2c6
DW
827 CalcBoundingBox( vX1
828 ,vY1
829 );
830
831 wxCoord vX2 = vX1 + vWidth;
832 wxCoord vY2 = vY1 + vHeight;
833
834 CalcBoundingBox( vX2
835 ,vY2
836 );
f07bb01b 837} // end of wxDC::DoDrawCheckMark
f6bcfd97 838
51c1d535
DW
839void wxDC::DoDrawPoint(
840 wxCoord vX
841, wxCoord vY
842)
1408104d 843{
51c1d535 844 POINTL vPoint;
5fd2b2c6 845 COLORREF vColor = 0x00ffffff;
51c1d535 846
5fd2b2c6
DW
847 if (m_pen.Ok())
848 {
849 vColor = m_pen.GetColour().GetPixel();
850 }
851 ::GpiSetColor(m_hPS, vColor);
51c1d535 852 vPoint.x = vX;
5fd2b2c6 853 vPoint.y = OS2Y(vY,0);
51c1d535 854 ::GpiSetPel(m_hPS, &vPoint);
5fd2b2c6
DW
855 CalcBoundingBox( vX
856 ,vY
857 );
f07bb01b 858} // end of wxDC::DoDrawPoint
1408104d 859
51c1d535
DW
860void wxDC::DoDrawPolygon(
861 int n
862, wxPoint vPoints[]
863, wxCoord vXoffset
864, wxCoord vYoffset
865, int nFillStyle
866)
1408104d 867{
51c1d535
DW
868 ULONG ulCount = 1; // Number of polygons.
869 POLYGON vPlgn; // polygon.
870 ULONG flOptions = 0L; // Drawing options.
871
872//////////////////////////////////////////////////////////////////////////////
873// This contains fields of option bits... to draw boundary lines as well as
874// the area interior.
875//
876// Drawing boundary lines:
877// POLYGON_NOBOUNDARY Does not draw boundary lines.
878// POLYGON_BOUNDARY Draws boundary lines (the default).
879//
880// Construction of the area interior:
881// POLYGON_ALTERNATE Constructs interior in alternate mode
882// (the default).
883// POLYGON_WINDING Constructs interior in winding mode.
884//////////////////////////////////////////////////////////////////////////////
885
886 ULONG flModel = 0L; // Drawing model.
887
888//////////////////////////////////////////////////////////////////////////////
889// Drawing model.
890// POLYGON_INCL Fill is inclusive of bottom right (the default).
891// POLYGON_EXCL Fill is exclusive of bottom right.
892// This is provided to aid migration from other graphics models.
893//////////////////////////////////////////////////////////////////////////////
894
895 LONG lHits = 0L; // Correlation/error indicator.
896 POINTL vPoint;
897 int i;
898 int nIsTRANSPARENT = 0;
899 LONG lBorderColor = 0L;
900 LONG lColor = 0L;
901
902 lBorderColor = m_pen.GetColour().GetPixel();
903 lColor = m_brush.GetColour().GetPixel();
904 if(m_brush.GetStyle() == wxTRANSPARENT)
905 nIsTRANSPARENT = 1;
906
907 vPlgn.ulPoints = n;
908 vPlgn.aPointl = (POINTL*) calloc( n + 1
909 ,sizeof(POINTL)
910 ); // well, new will call malloc
911
912 for(i = 0; i < n; i++)
913 {
5fd2b2c6
DW
914 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
915 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
51c1d535
DW
916 }
917 flModel = POLYGON_BOUNDARY;
918 if(nFillStyle == wxWINDING_RULE)
919 flModel |= POLYGON_WINDING;
920 else
921 flModel |= POLYGON_ALTERNATE;
922
923 vPoint.x = vXoffset;
5fd2b2c6 924 vPoint.y = OS2Y(vYoffset,0);
51c1d535
DW
925
926 ::GpiSetColor(m_hPS, lBorderColor);
927 ::GpiMove(m_hPS, &vPoint);
928 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
929 free(vPlgn.aPointl);
f07bb01b 930} // end of wxDC::DoDrawPolygon
1408104d 931
51c1d535
DW
932void wxDC::DoDrawLines(
933 int n
934, wxPoint vPoints[]
935, wxCoord vXoffset
936, wxCoord vYoffset
937)
1408104d 938{
51c1d535
DW
939 POINTL vPoint;
940
5fd2b2c6
DW
941 if (vXoffset != 0L || vXoffset != 0L)
942 {
943 int i;
944
945 vPoint.x = vPoints[0].x + vXoffset;
946 vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
947 ::GpiMove(m_hPS, &vPoint);
51c1d535 948
5fd2b2c6 949 LONG lBorderColor = m_pen.GetColour().GetPixel();
51c1d535 950
5fd2b2c6
DW
951 ::GpiSetColor(m_hPS, lBorderColor);
952 for(i = 1; i < n; i++)
953 {
954 vPoint.x = vPoints[i].x + vXoffset;
955 vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
956 ::GpiLine(m_hPS, &vPoint);
957 }
958 }
959 else
51c1d535 960 {
5fd2b2c6
DW
961 int i;
962
9da48399
JS
963 CalcBoundingBox( vPoints[0].x
964 ,vPoints[0].y
5fd2b2c6
DW
965 );
966 vPoint.x = vPoints[0].x;
967 vPoint.y = OS2Y(vPoints[0].y,0);
968 ::GpiMove(m_hPS, &vPoint);
969
970 for (i = 0; i < n; i++)
971 {
972 CalcBoundingBox( vPoints[i].x
973 ,vPoints[i].y
974 );
975 vPoint.x = vPoints[i].x;
976 vPoint.y = OS2Y(vPoints[i].y,0);
977 ::GpiLine(m_hPS, &vPoint);
978 }
51c1d535 979 }
f07bb01b 980} // end of wxDC::DoDrawLines
1408104d 981
7e99520b 982void wxDC::DoDrawRectangle(
f44fdfb0 983 wxCoord vX
7e99520b
DW
984, wxCoord vY
985, wxCoord vWidth
986, wxCoord vHeight
987)
1408104d 988{
7e99520b 989 POINTL vPoint[2];
51c1d535
DW
990 LONG lControl;
991 LONG lColor;
992 LONG lBorderColor;
993 int nIsTRANSPARENT = 0;
7e99520b 994
1d0edc0f 995 //
d6d749aa 996 // Might be a memory DC with no Paint rect.
1d0edc0f
DW
997 //
998 if (!(m_vRclPaint.yTop == 0 &&
999 m_vRclPaint.yBottom == 0 &&
1000 m_vRclPaint.xRight == 0 &&
1001 m_vRclPaint.xLeft == 0))
1002 vY = OS2Y(vY,vHeight);
1c9a789e
DW
1003 else
1004 {
1005 if (m_vSelectedBitmap != wxNullBitmap)
1006 {
1007 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1008 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1009 vY = OS2Y(vY,vHeight);
1010 }
1011 }
5fd2b2c6
DW
1012
1013 wxCoord vX2 = vX + vWidth;
1014 wxCoord vY2 = vY + vHeight;
1015
7e99520b 1016 vPoint[0].x = vX;
5fd2b2c6 1017 vPoint[0].y = vY;
ba3e10c9
DW
1018 vPoint[1].x = vX + vWidth - 1;
1019 vPoint[1].y = vY + vHeight - 1;
7e99520b 1020 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
1021 lColor = m_brush.GetColour().GetPixel();
1022 lBorderColor = m_pen.GetColour().GetPixel();
1023 if (m_brush.GetStyle() == wxTRANSPARENT)
1024 nIsTRANSPARENT = 1;
1025 if(lColor == lBorderColor || nIsTRANSPARENT)
1026 {
1027 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1028 if(m_brush.GetStyle() == wxTRANSPARENT)
1029 lControl = DRO_OUTLINE;
1030
70a2c656 1031 ::GpiSetColor(m_hPS, lBorderColor);
51c1d535
DW
1032 ::GpiBox( m_hPS // handle to a presentation space
1033 ,lControl // draw the box outline ? or ?
1034 ,&vPoint[1] // address of the corner
1035 ,0L // horizontal corner radius
1036 ,0L // vertical corner radius
1037 );
1038 }
1039 else
1040 {
1041 lControl = DRO_OUTLINE;
1042 ::GpiSetColor( m_hPS
1043 ,lBorderColor
1044 );
1045 ::GpiBox( m_hPS
1046 ,lControl
1047 ,&vPoint[1]
1048 ,0L
1049 ,0L
1050 );
1051 lControl = DRO_FILL;
1052 ::GpiSetColor( m_hPS
1053 ,lColor
1054 );
8d854fa9 1055 vPoint[0].x = vX + 1;
5fd2b2c6 1056 vPoint[0].y = vY + 1;
ba3e10c9
DW
1057 vPoint[1].x = vX + vWidth - 2;
1058 vPoint[1].y = vY + vHeight - 2;
8d854fa9 1059 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
1060 ::GpiBox( m_hPS
1061 ,lControl
1062 ,&vPoint[1]
1063 ,0L
1064 ,0L
1065 );
1066 }
5fd2b2c6
DW
1067 CalcBoundingBox(vX, vY);
1068 CalcBoundingBox(vX2, vY2);
f07bb01b 1069} // end of wxDC::DoDrawRectangle
1408104d 1070
7e99520b
DW
1071void wxDC::DoDrawRoundedRectangle(
1072 wxCoord vX
1073, wxCoord vY
1074, wxCoord vWidth
1075, wxCoord vHeight
1076, double dRadius
1077)
1408104d 1078{
7e99520b 1079 POINTL vPoint[2];
51c1d535 1080 LONG lControl;
1c9a789e
DW
1081 LONG lColor;
1082 LONG lBorderColor;
1083 int nIsTRANSPARENT = 0;
7e99520b 1084
d6d749aa
DW
1085 //
1086 // Might be a memory DC with no Paint rect.
1087 //
1088 if (!(m_vRclPaint.yTop == 0 &&
1089 m_vRclPaint.yBottom == 0 &&
1090 m_vRclPaint.xRight == 0 &&
1091 m_vRclPaint.xLeft == 0))
1092 vY = OS2Y(vY,vHeight);
1c9a789e
DW
1093 else
1094 {
1095 if (m_vSelectedBitmap != wxNullBitmap)
1096 {
1097 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1098 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
1099 vY = OS2Y(vY,vHeight);
1100 }
1101 }
5fd2b2c6
DW
1102
1103 wxCoord vX2 = (vX + vWidth);
1104 wxCoord vY2 = (vY + vHeight);
1105
7e99520b 1106 vPoint[0].x = vX;
1c9a789e
DW
1107 vPoint[0].y = vY;
1108 vPoint[1].x = vX + vWidth - 1;
1109 vPoint[1].y = vY + vHeight - 1;
7e99520b 1110 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535 1111
1c9a789e
DW
1112 lColor = m_brush.GetColour().GetPixel();
1113 lBorderColor = m_pen.GetColour().GetPixel();
51c1d535
DW
1114 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1115 if (m_brush.GetStyle() == wxTRANSPARENT)
1c9a789e
DW
1116 nIsTRANSPARENT = 1;
1117 if(lColor == lBorderColor || nIsTRANSPARENT)
1118 {
1119 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1120 if(m_brush.GetStyle() == wxTRANSPARENT)
1121 lControl = DRO_OUTLINE;
1122
1123 ::GpiSetColor(m_hPS, lColor);
1124 ::GpiBox( m_hPS // handle to a presentation space
1125 ,lControl // draw the box outline ? or ?
1126 ,&vPoint[1] // address of the corner
1127 ,(LONG)dRadius // horizontal corner radius
1128 ,(LONG)dRadius // vertical corner radius
1129 );
1130 }
1131 else
1132 {
51c1d535 1133 lControl = DRO_OUTLINE;
1c9a789e
DW
1134 ::GpiSetColor( m_hPS
1135 ,lBorderColor
1136 );
1137 ::GpiBox( m_hPS
1138 ,lControl
1139 ,&vPoint[1]
ad6bd870
DW
1140 ,(LONG)dRadius
1141 ,(LONG)dRadius
1c9a789e
DW
1142 );
1143 lControl = DRO_FILL;
1144 ::GpiSetColor( m_hPS
1145 ,lColor
1146 );
1147 vPoint[0].x = vX + 1;
1148 vPoint[0].y = vY + 1;
1149 vPoint[1].x = vX + vWidth - 2;
1150 vPoint[1].y = vY + vHeight - 2;
1151 ::GpiMove(m_hPS, &vPoint[0]);
1152 ::GpiBox( m_hPS
1153 ,lControl
1154 ,&vPoint[1]
ad6bd870
DW
1155 ,(LONG)dRadius
1156 ,(LONG)dRadius
1c9a789e
DW
1157 );
1158 }
1159
5fd2b2c6
DW
1160 CalcBoundingBox(vX, vY);
1161 CalcBoundingBox(vX2, vY2);
f07bb01b 1162} // end of wxDC::DoDrawRoundedRectangle
1408104d 1163
51c1d535
DW
1164// Draw Ellipse within box (x,y) - (x+width, y+height)
1165void wxDC::DoDrawEllipse(
1166 wxCoord vX
1167, wxCoord vY
1168, wxCoord vWidth
1169, wxCoord vHeight
1170)
1408104d 1171{
51c1d535
DW
1172 POINTL vPtlPos; // Structure for current position
1173 FIXED vFxMult; // Multiplier for ellipse
1174 ARCPARAMS vArcp; // Structure for arc parameters
1175
5fd2b2c6
DW
1176 vY = OS2Y(vY,vHeight);
1177
51c1d535
DW
1178 vArcp.lR = 0;
1179 vArcp.lQ = vHeight/2;
1180 vArcp.lP = vWidth/2;
1181 vArcp.lS = 0;
1182 ::GpiSetArcParams( m_hPS
1183 ,&vArcp
1184 ); // Sets parameters to default
1185 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
1186 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1187 ::GpiMove( m_hPS
1188 ,&vPtlPos
1189 ); // Sets current position
1190 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
1191
1192 //
1193 // DRO_FILL, DRO_OTLINEFILL - where to get
1194 //
1195 ::GpiFullArc( m_hPS
1196 ,DRO_OUTLINE
1197 ,vFxMult
1198 ); // Draws full arc with center at current position
5fd2b2c6
DW
1199
1200 wxCoord vX2 = (vX + vWidth);
1201 wxCoord vY2 = (vY + vHeight);
1202
1203 CalcBoundingBox(vX, vY);
1204 CalcBoundingBox(vX2, vY2);
f07bb01b 1205} // end of wxDC::DoDrawEllipse
1408104d 1206
51c1d535
DW
1207void wxDC::DoDrawEllipticArc(
1208 wxCoord vX
1209, wxCoord vY
1210, wxCoord vWidth
1211, wxCoord vHeight
1212, double dSa
1213, double dEa
1214)
1408104d 1215{
51c1d535
DW
1216 POINTL vPtlPos; // Structure for current position
1217 FIXED vFxMult; // Multiplier for ellipse
1218 ARCPARAMS vArcp; // Structure for arc parameters
1219 FIXED vFSa;
1220 FIXED vFSweepa; // Start angle, sweep angle
1221 double dIntPart;
1222 double dFractPart;
51c1d535 1223
5fd2b2c6
DW
1224 vY = OS2Y(vY,vHeight);
1225
51c1d535
DW
1226 dFractPart = modf(dSa,&dIntPart);
1227 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1228 dFractPart = modf(dEa - dSa, &dIntPart);
1229 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1230
1231 //
1232 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1233 //
1234 vArcp.lR = 0;
1235 vArcp.lQ = vHeight/2;
1236 vArcp.lP = vWidth/2;
1237 vArcp.lS = 0;
1238 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
9923c37d
DW
1239 vPtlPos.x = (wxCoord)(vX + vWidth/2 * (1. + cos(DegToRad(dSa)))); // Loads x-coordinate
1240 vPtlPos.y = (wxCoord)(vY + vHeight/2 * (1. + sin(DegToRad(dSa)))); // Loads y-coordinate
51c1d535
DW
1241 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
1242
1243 //
1244 // May be not to the center ?
1245 //
1246 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
1247 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1248 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
1249
1250 //
1251 // DRO_FILL, DRO_OTLINEFILL - where to get
1252 //
1253 ::GpiPartialArc( m_hPS
1254 ,&vPtlPos
1255 ,vFxMult
1256 ,vFSa
1257 ,vFSweepa
1258 );
5fd2b2c6
DW
1259 wxCoord vX2 = (vX + vWidth);
1260 wxCoord vY2 = (vY + vHeight);
1261
1262 CalcBoundingBox(vX, vY);
1263 CalcBoundingBox(vX2, vY2);
f07bb01b 1264} // end of wxDC::DoDrawEllipticArc
1408104d 1265
f07bb01b
DW
1266void wxDC::DoDrawIcon(
1267 const wxIcon& rIcon
1268, wxCoord vX
1269, wxCoord vY
1270)
1408104d 1271{
16ff355b
DW
1272 //
1273 // Need to copy back into a bitmap. ::WinDrawPointer uses device coords
1274 // and I don't feel like figuring those out for scrollable windows so
1275 // just convert to a bitmap then let the DoDrawBitmap routing display it
1276 //
1277 if (rIcon.IsXpm())
1278 {
aad6765c 1279 DoDrawBitmap(rIcon.GetXpmSrc(), vX, vY, true);
16ff355b
DW
1280 }
1281 else
1282 {
1283 wxBitmap vBitmap(rIcon);
1284
aad6765c 1285 DoDrawBitmap(vBitmap, vX, vY, false);
16ff355b 1286 }
5fd2b2c6
DW
1287 CalcBoundingBox(vX, vY);
1288 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
f07bb01b
DW
1289} // end of wxDC::DoDrawIcon
1290
1291void wxDC::DoDrawBitmap(
1292 const wxBitmap& rBmp
1293, wxCoord vX
1294, wxCoord vY
1295, bool bUseMask
1296)
1408104d 1297{
6670f564 1298#if wxUSE_PRINTING_ARCHITECTURE
ba3e10c9 1299 if (!IsKindOf(CLASSINFO(wxPrinterDC)))
6670f564 1300#endif
c354beea
DW
1301 {
1302 HBITMAP hBitmap = (HBITMAP)rBmp.GetHBITMAP();
d0ee33f5 1303 HBITMAP hBitmapOld = NULLHANDLE;
1c9a789e 1304 POINTL vPoint[4];
c354beea 1305
ba3e10c9
DW
1306 vY = OS2Y(vY,rBmp.GetHeight());
1307
ad6bd870
DW
1308 vPoint[0].x = vX;
1309 vPoint[0].y = vY + rBmp.GetHeight();
1310 vPoint[1].x = vX + rBmp.GetWidth();
1311 vPoint[1].y = vY;
1312 vPoint[2].x = 0;
1313 vPoint[2].y = 0;
1314 vPoint[3].x = rBmp.GetWidth();
1315 vPoint[3].y = rBmp.GetHeight();
ba3e10c9
DW
1316 if (bUseMask)
1317 {
1318 wxMask* pMask = rBmp.GetMask();
c354beea 1319
52315bc3 1320 if (pMask)
ba3e10c9 1321 {
52315bc3
DW
1322 //
1323 // Need to imitate ::MaskBlt in windows.
1324 // 1) Extract the bits from from the bitmap.
1325 // 2) Extract the bits from the mask
1326 // 3) Using the mask bits do the following:
1327 // A) If the mask byte is 00 leave the bitmap byte alone
1328 // B) If the mask byte is FF copy the screen color into
1329 // bitmap byte
1330 // 4) Create a new bitmap and set its bits to the above result
1331 // 5) Blit this to the screen PS
1332 //
1333 HBITMAP hMask = (HBITMAP)pMask->GetMaskBitmap();
d6d749aa 1334 HBITMAP hOldMask = NULLHANDLE;
52315bc3
DW
1335 HBITMAP hOldBitmap = NULLHANDLE;
1336 HBITMAP hNewBitmap = NULLHANDLE;
1337 unsigned char* pucBits; // buffer that will contain the bitmap data
1338 unsigned char* pucBitsMask; // buffer that will contain the mask data
1339 unsigned char* pucData; // pointer to use to traverse bitmap data
1340 unsigned char* pucDataMask; // pointer to use to traverse mask data
1341 LONG lHits;
1342 ERRORID vError;
1343 wxString sError;
1344
1345 //
1346 // The usual Memory context creation stuff
1347 //
ba3e10c9
DW
1348 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1349 SIZEL vSize = {0, 0};
52315bc3
DW
1350 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
1351 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
1352
1353 //
1354 // The usual bitmap header stuff
1355 //
1356 BITMAPINFOHEADER2 vHeader;
1357 BITMAPINFO2 vInfo;
1358
1359 memset(&vHeader, '\0', 16);
1360 vHeader.cbFix = 16;
52315bc3
DW
1361
1362 memset(&vInfo, '\0', 16);
1363 vInfo.cbFix = 16;
1364 vInfo.cx = (ULONG)rBmp.GetWidth();
1365 vInfo.cy = (ULONG)rBmp.GetHeight();
1366 vInfo.cPlanes = 1;
1367 vInfo.cBitCount = 24; // Set to desired count going in
1368
1369 //
1370 // Create the buffers for data....all wxBitmaps are 24 bit internally
1371 //
1372 int nBytesPerLine = rBmp.GetWidth() * 3;
1373 int nSizeDWORD = sizeof(DWORD);
1374 int nLineBoundary = nBytesPerLine % nSizeDWORD;
1375 int nPadding = 0;
1376 int i;
1377 int j;
1378 LONG lScans = 0L;
1379 LONG lColor = 0L;
1380
1381 //
1382 // Need to get a background color for mask blitting
1383 //
2590f154 1384 if (IsKindOf(CLASSINFO(wxWindowDC)))
52315bc3 1385 {
d697657f 1386 wxWindowDC* pWindowDC = wxDynamicCast(this, wxWindowDC);
c354beea 1387
d697657f 1388 lColor = pWindowDC->m_pCanvas->GetBackgroundColour().GetPixel();
52315bc3 1389 }
9da48399 1390 else if (GetBrush().Ok())
52315bc3
DW
1391 lColor = GetBrush().GetColour().GetPixel();
1392 else
1393 lColor = m_textBackgroundColour.GetPixel();
1394
1395 //
d6922577 1396 // Bitmap must be in a double-word aligned address so we may
52315bc3
DW
1397 // have some padding to worry about
1398 //
1399 if (nLineBoundary > 0)
1400 {
1401 nPadding = nSizeDWORD - nLineBoundary;
1402 nBytesPerLine += nPadding;
1403 }
1404 pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
1405 pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
1406 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
1407 memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
1408
1409 //
1410 // Extract the bitmap and mask data
1411 //
1412 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
1413 {
1414 vError = ::WinGetLastError(vHabmain);
1415 sError = wxPMErrorToStr(vError);
1416 }
d6d749aa
DW
1417 ::GpiQueryBitmapInfoHeader(hBitmap, &vHeader);
1418 vInfo.cBitCount = 24;
ba3e10c9
DW
1419 if ((lScans = ::GpiQueryBitmapBits( hPS
1420 ,0L
1421 ,(LONG)rBmp.GetHeight()
52315bc3 1422 ,(PBYTE)pucBits
ba3e10c9
DW
1423 ,&vInfo
1424 )) == GPI_ALTERROR)
1425 {
ba3e10c9
DW
1426 vError = ::WinGetLastError(vHabmain);
1427 sError = wxPMErrorToStr(vError);
1428 }
d6d749aa 1429 if ((hOldMask = ::GpiSetBitmap(hPS, hMask)) == HBM_ERROR)
ba3e10c9 1430 {
ba3e10c9
DW
1431 vError = ::WinGetLastError(vHabmain);
1432 sError = wxPMErrorToStr(vError);
1433 }
d6d749aa
DW
1434 ::GpiQueryBitmapInfoHeader(hMask, &vHeader);
1435 vInfo.cBitCount = 24;
52315bc3
DW
1436 if ((lScans = ::GpiQueryBitmapBits( hPS
1437 ,0L
1438 ,(LONG)rBmp.GetHeight()
1439 ,(PBYTE)pucBitsMask
1440 ,&vInfo
1441 )) == GPI_ALTERROR)
ba3e10c9 1442 {
ba3e10c9
DW
1443 vError = ::WinGetLastError(vHabmain);
1444 sError = wxPMErrorToStr(vError);
1445 }
d6d749aa
DW
1446 if (( hMask = ::GpiSetBitmap(hPS, hOldMask)) == HBM_ERROR)
1447 {
1448 vError = ::WinGetLastError(vHabmain);
1449 sError = wxPMErrorToStr(vError);
1450 }
52315bc3
DW
1451
1452 //
1453 // Now set the bytes(bits) according to the mask values
1454 // 3 bytes per pel...must handle one at a time
1455 //
1456 pucData = pucBits;
1457 pucDataMask = pucBitsMask;
1458
d6d749aa
DW
1459 //
1460 // 16 bit kludge really only kinda works. The mask gets applied
1461 // where needed but the original bitmap bits are dorked sometimes
1462 //
1463 bool bpp16 = (wxDisplayDepth() == 16);
1464
52315bc3 1465 for (i = 0; i < rBmp.GetHeight(); i++)
ba3e10c9 1466 {
52315bc3
DW
1467 for (j = 0; j < rBmp.GetWidth(); j++)
1468 {
1469 // Byte 1
d6d749aa
DW
1470 if (bpp16 && *pucDataMask == 0xF8) // 16 bit display gobblygook
1471 pucData++;
1472 else if (*pucDataMask == 0xFF) // leave bitmap byte alone
52315bc3
DW
1473 pucData++;
1474 else
1475 {
16ff355b 1476 *pucData = ((unsigned char)(lColor >> 16));
52315bc3
DW
1477 pucData++;
1478 }
1479 // Byte 2
d6d749aa
DW
1480 if (bpp16 && *(pucDataMask + 1) == 0xFC) // 16 bit display gobblygook
1481 pucData++;
1482 else if (*(pucDataMask + 1) == 0xFF) // leave bitmap byte alone
52315bc3
DW
1483 pucData++;
1484 else
1485 {
16ff355b 1486 *pucData = ((unsigned char)(lColor >> 8));
52315bc3
DW
1487 pucData++;
1488 }
1489
1490 // Byte 3
d6d749aa
DW
1491 if (bpp16 && *(pucDataMask + 2) == 0xF8) // 16 bit display gobblygook
1492 pucData++;
1493 else if (*(pucDataMask + 2) == 0xFF) // leave bitmap byte alone
52315bc3
DW
1494 pucData++;
1495 else
1496 {
16ff355b 1497 *pucData = ((unsigned char)lColor);
52315bc3
DW
1498 pucData++;
1499 }
1500 pucDataMask += 3;
1501 }
1502 for (j = 0; j < nPadding; j++)
1503 {
1504 pucData++;
1505 pucDataMask++;
1506 }
1507 }
52315bc3
DW
1508 //
1509 // Create a new bitmap
1510 //
d6d749aa
DW
1511 vHeader.cx = (ULONG)rBmp.GetWidth();
1512 vHeader.cy = (ULONG)rBmp.GetHeight();
1513 vHeader.cPlanes = 1L;
1514 vHeader.cBitCount = 24;
52315bc3
DW
1515 if ((hNewBitmap = ::GpiCreateBitmap( hPS
1516 ,&vHeader
1517 ,CBM_INIT
1518 ,(PBYTE)pucBits
1519 ,&vInfo
1520 )) == GPI_ERROR)
1521 {
ba3e10c9
DW
1522 vError = ::WinGetLastError(vHabmain);
1523 sError = wxPMErrorToStr(vError);
1524 }
ba3e10c9 1525
52315bc3
DW
1526 //
1527 // Now blit it to the screen PS
1528 //
1529 if ((lHits = ::GpiWCBitBlt( (HPS)GetHPS()
1530 ,hNewBitmap
1531 ,4
1532 ,vPoint
1533 ,ROP_SRCCOPY
1534 ,BBO_IGNORE
1535 )) == GPI_ERROR)
1536 {
ba3e10c9
DW
1537 vError = ::WinGetLastError(vHabmain);
1538 sError = wxPMErrorToStr(vError);
1539 }
52315bc3
DW
1540
1541 //
1542 // Clean up
1543 //
1544 free(pucBits);
1545 free(pucBitsMask);
1546 ::GpiSetBitmap(hPS, NULLHANDLE);
d6d749aa 1547 ::GpiDeleteBitmap(hNewBitmap);
52315bc3
DW
1548 ::GpiDestroyPS(hPS);
1549 ::DevCloseDC(hDC);
ba3e10c9
DW
1550 }
1551 }
1552 else
1553 {
9923c37d
DW
1554 ULONG lOldForeGround = ::GpiQueryColor((HPS)GetHPS());
1555 ULONG lOldBackGround = ::GpiQueryBackColor((HPS)GetHPS());
52315bc3
DW
1556
1557 if (m_textForegroundColour.Ok())
1558 {
1559 ::GpiSetColor( (HPS)GetHPS()
1560 ,m_textForegroundColour.GetPixel()
1561 );
1562 }
1563 if (m_textBackgroundColour.Ok())
1564 {
1565 ::GpiSetBackColor( (HPS)GetHPS()
1566 ,m_textBackgroundColour.GetPixel()
1567 );
1568 }
16ff355b
DW
1569 //
1570 // Need to alter bits in a mono bitmap to match the new
1571 // background-foreground if it is different.
1572 //
1573 if (rBmp.IsMono() &&
1574 ((m_textForegroundColour.GetPixel() != lOldForeGround) ||
1575 (m_textBackgroundColour.GetPixel() != lOldBackGround)))
1576 {
1577 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
1578 SIZEL vSize = {0, 0};
1579 HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
1580 HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
1581
1582 int nBytesPerLine = rBmp.GetWidth() * 3;
1583 int i, j;
1584 LONG lForeGround = m_textForegroundColour.GetPixel();
1585 LONG lBackGround = m_textBackgroundColour.GetPixel();
1586 LONG lScans;
1587 HBITMAP hOldBitmap = NULLHANDLE;
1588 BITMAPINFO2 vInfo;
1589 ERRORID vError;
1590 wxString sError;
1591
1592
1593 memset(&vInfo, '\0', 16);
1594 vInfo.cbFix = 16;
1595 vInfo.cx = (ULONG)rBmp.GetWidth();
1596 vInfo.cy = (ULONG)rBmp.GetHeight();
1597 vInfo.cPlanes = 1;
1598 vInfo.cBitCount = 24;
1599
1600 unsigned char* pucBits; // buffer that will contain the bitmap data
1601 unsigned char* pucData; // pointer to use to traverse bitmap data
1602
1603 pucBits = new unsigned char[nBytesPerLine * rBmp.GetHeight()];
1604 memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
1605
1606 if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
1607 {
1608 vError = ::WinGetLastError(vHabmain);
1609 sError = wxPMErrorToStr(vError);
1610 return;
1611 }
1612 if ((lScans = ::GpiQueryBitmapBits( hPS
1613 ,0L
1614 ,(LONG)rBmp.GetHeight()
1615 ,(PBYTE)pucBits
1616 ,&vInfo
1617 )) == GPI_ALTERROR)
1618 {
1619 vError = ::WinGetLastError(vHabmain);
1620 sError = wxPMErrorToStr(vError);
1621 return;
1622 }
1623 unsigned char cOldRedFore = (unsigned char)(lOldForeGround >> 16);
1624 unsigned char cOldGreenFore = (unsigned char)(lOldForeGround >> 8);
1625 unsigned char cOldBlueFore = (unsigned char)lOldForeGround;
1626
16ff355b
DW
1627 unsigned char cRedFore = (unsigned char)(lForeGround >> 16);
1628 unsigned char cGreenFore = (unsigned char)(lForeGround >> 8);
1629 unsigned char cBlueFore = (unsigned char)lForeGround;
1630
1631 unsigned char cRedBack = (unsigned char)(lBackGround >> 16);
1632 unsigned char cGreenBack = (unsigned char)(lBackGround >> 8);
1633 unsigned char cBlueBack = (unsigned char)lBackGround;
1634
1635 pucData = pucBits;
1636 for (i = 0; i < rBmp.GetHeight(); i++)
1637 {
1638 for (j = 0; j < rBmp.GetWidth(); j++)
1639 {
1640 unsigned char cBmpRed = *pucData;
1641 unsigned char cBmpGreen = *(pucData + 1);
1642 unsigned char cBmpBlue = *(pucData + 2);
1643
1644 if ((cBmpRed == cOldRedFore) &&
1645 (cBmpGreen == cOldGreenFore) &&
1646 (cBmpBlue == cOldBlueFore))
1647 {
29172908 1648 *pucData = cBlueFore;
16ff355b
DW
1649 pucData++;
1650 *pucData = cGreenFore;
1651 pucData++;
29172908 1652 *pucData = cRedFore;
16ff355b
DW
1653 pucData++;
1654 }
1655 else
1656 {
29172908 1657 *pucData = cBlueBack;
16ff355b
DW
1658 pucData++;
1659 *pucData = cGreenBack;
1660 pucData++;
29172908 1661 *pucData = cRedBack;
16ff355b
DW
1662 pucData++;
1663 }
1664 }
1665 }
1666 if ((lScans = ::GpiSetBitmapBits( hPS
1667 ,0L
1668 ,(LONG)rBmp.GetHeight()
1669 ,(PBYTE)pucBits
1670 ,&vInfo
1671 )) == GPI_ALTERROR)
1672 {
1673 vError = ::WinGetLastError(vHabmain);
1674 sError = wxPMErrorToStr(vError);
1675 return;
1676 }
1677 delete [] pucBits;
1678 ::GpiSetBitmap(hPS, NULLHANDLE);
1679 ::GpiDestroyPS(hPS);
1680 ::DevCloseDC(hDC);
1681 }
ba3e10c9
DW
1682 ::GpiWCBitBlt( (HPS)GetHPS()
1683 ,hBitmap
1684 ,4
1685 ,vPoint
1686 ,ROP_SRCCOPY
1687 ,BBO_IGNORE
1688 );
52315bc3 1689 ::GpiSetBitmap((HPS)GetHPS(), hBitmapOld);
16ff355b
DW
1690 ::GpiSetColor((HPS)GetHPS(), lOldForeGround);
1691 ::GpiSetBackColor((HPS)GetHPS(), lOldBackGround);
ba3e10c9 1692 }
c354beea 1693 }
f07bb01b 1694} // end of wxDC::DoDrawBitmap
1408104d 1695
7e99520b
DW
1696void wxDC::DoDrawText(
1697 const wxString& rsText
1698, wxCoord vX
1699, wxCoord vY
1700)
1408104d 1701{
5fd2b2c6
DW
1702 wxCoord vWidth;
1703 wxCoord vHeight;
1704
7e99520b
DW
1705 DrawAnyText( rsText
1706 ,vX
1707 ,vY
1708 );
5fd2b2c6
DW
1709
1710 CalcBoundingBox(vX, vY);
1711 GetTextExtent(rsText, &vWidth, &vHeight);
1712 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1713} // end of wxDC::DoDrawText
1408104d 1714
7e99520b
DW
1715void wxDC::DrawAnyText(
1716 const wxString& rsText
1717, wxCoord vX
1718, wxCoord vY
1719)
f6bcfd97 1720{
7e99520b
DW
1721 int nOldBackground = 0;
1722 POINTL vPtlStart;
1723 LONG lHits;
5fd2b2c6
DW
1724 wxCoord vTextX = 0;
1725 wxCoord vTextY = 0;
f6bcfd97 1726
7e99520b
DW
1727 //
1728 // prepare for drawing the text
1729 //
1730
1731 //
1732 // Set text color attributes
1733 //
1734 if (m_textForegroundColour.Ok())
1735 {
1736 SetTextColor( m_hPS
1737 ,(int)m_textForegroundColour.GetPixel()
1738 );
1739 }
1740
1741 if (m_textBackgroundColour.Ok())
1742 {
1743 nOldBackground = SetTextBkColor( m_hPS
1744 ,(int)m_textBackgroundColour.GetPixel()
1745 );
1746 }
1747 SetBkMode( m_hPS
1748 ,m_backgroundMode
1749 );
5fd2b2c6
DW
1750 GetTextExtent( rsText
1751 ,&vTextX
1752 ,&vTextY
1753 );
7e99520b 1754 vPtlStart.x = vX;
d6d749aa
DW
1755 if (!(m_vRclPaint.yTop == 0 &&
1756 m_vRclPaint.yBottom == 0 &&
1757 m_vRclPaint.xRight == 0 &&
1758 m_vRclPaint.xLeft == 0))
650ff63d
DW
1759 {
1760 //
1761 // Position Text a little differently in the Statusbar from other panels
1762 //
1763 if (m_pCanvas && m_pCanvas->IsKindOf(CLASSINFO(wxStatusBar)))
1764 vPtlStart.y = OS2Y(vY,vTextY);
1765 else
9923c37d 1766 vPtlStart.y = (wxCoord)(OS2Y(vY,vTextY/1.5)); // Full extent is a bit much
650ff63d 1767 }
d6d749aa 1768 else
1c9a789e
DW
1769 {
1770 if (m_vSelectedBitmap != wxNullBitmap)
1771 {
1772 m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
1773 m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
650ff63d
DW
1774 if (m_pCanvas && m_pCanvas->IsKindOf(CLASSINFO(wxStatusBar)))
1775 vPtlStart.y = OS2Y(vY,vTextY);
1776 else
9923c37d 1777 vPtlStart.y = (LONG)(OS2Y(vY,vTextY/1.5));
1c9a789e
DW
1778 }
1779 else
1780 vPtlStart.y = vY;
1781 }
d6d749aa
DW
1782
1783 PCH pzStr = (PCH)rsText.c_str();
7e99520b 1784
d6d749aa
DW
1785 ::GpiMove(m_hPS, &vPtlStart);
1786 lHits = ::GpiCharString( m_hPS
1787 ,rsText.length()
1788 ,pzStr
1789 );
7e99520b
DW
1790 if (lHits != GPI_OK)
1791 {
1792 wxLogLastError(wxT("TextOut"));
1793 }
1794
1795 //
1796 // Restore the old parameters (text foreground colour may be left because
1797 // it never is set to anything else, but background should remain
1798 // transparent even if we just drew an opaque string)
1799 //
1800 if (m_textBackgroundColour.Ok())
1801 SetTextBkColor( m_hPS
1802 ,nOldBackground
1803 );
1804 SetBkMode( m_hPS
1805 ,wxTRANSPARENT
1806 );
1807}
1808
1809void wxDC::DoDrawRotatedText(
1810 const wxString& rsText
1811, wxCoord vX
1812, wxCoord vY
1813, double dAngle
1814)
c8ce6bcc 1815{
7e99520b
DW
1816 if (dAngle == 0.0)
1817 {
1818 DoDrawText( rsText
1819 ,vX
1820 ,vY
1821 );
1822 }
1823
c8ce6bcc
DW
1824 // TODO:
1825 /*
1826 if ( angle == 0.0 )
1827 {
1828 DoDrawText(text, x, y);
1829 }
1830 else
1831 {
1832 LOGFONT lf;
1833 wxFillLogFont(&lf, &m_font);
1834
1835 // GDI wants the angle in tenth of degree
1836 long angle10 = (long)(angle * 10);
1837 lf.lfEscapement = angle10;
1838 lf. lfOrientation = angle10;
1839
1840 HFONT hfont = ::CreateFontIndirect(&lf);
1841 if ( !hfont )
1842 {
1843 wxLogLastError("CreateFont");
1844 }
1845 else
1846 {
1847 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1848
1849 DrawAnyText(text, x, y);
1850
1851 (void)::SelectObject(GetHdc(), hfontOld);
1852 }
1853
1854 // call the bounding box by adding all four vertices of the rectangle
1855 // containing the text to it (simpler and probably not slower than
1856 // determining which of them is really topmost/leftmost/...)
1857 wxCoord w, h;
1858 GetTextExtent(text, &w, &h);
1859
1860 double rad = DegToRad(angle);
1861
1862 // "upper left" and "upper right"
1863 CalcBoundingBox(x, y);
1864 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1865 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1866
1867 // "bottom left" and "bottom right"
1868 x += (wxCoord)(h*sin(rad));
1869 y += (wxCoord)(h*cos(rad));
1870 CalcBoundingBox(x, y);
1871 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1872 }
1873*/
1874}
1875
fb46a9a6
DW
1876// ---------------------------------------------------------------------------
1877// set GDI objects
1878// ---------------------------------------------------------------------------
1408104d 1879
6670f564 1880void wxDC::DoSelectPalette( bool WXUNUSED(bRealize) )
938aa9c4
DW
1881{
1882 //
1883 // Set the old object temporarily, in case the assignment deletes an object
1884 // that's not yet selected out.
1885 //
1886 if (m_hOldPalette)
1887 {
1888 m_hOldPalette = 0;
1889 }
1890
1891 if (m_palette.Ok())
1892 {
1893 HPALETTE hOldPal;
1894
1895 hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1896 if (!m_hOldPalette)
1897 m_hOldPalette = (WXHPALETTE)hOldPal;
1898 }
1899} // end of wxDC::DoSelectPalette
1900
1901void wxDC::InitializePalette()
1902{
1903 if (wxDisplayDepth() <= 8 )
1904 {
1905 //
1906 // Look for any window or parent that has a custom palette. If any has
1907 // one then we need to use it in drawing operations
1908 //
1909 wxWindow* pWin = m_pCanvas->GetAncestorWithCustomPalette();
1910
1911 m_hasCustomPalette = pWin && pWin->HasCustomPalette();
1912 if (m_hasCustomPalette)
1913 {
1914 m_palette = pWin->GetPalette();
1915
1916 //
1917 // turn on PM translation for this palette
1918 //
1919 DoSelectPalette();
1920 }
1921 }
1922} // end of wxDC::InitializePalette
1923
5fd2b2c6
DW
1924void wxDC::SetPalette(
1925 const wxPalette& rPalette
1926)
1408104d 1927{
5fd2b2c6
DW
1928 if (m_hOldFont)
1929 {
1930 m_hOldFont = 0;
1931 }
1932 m_palette = rPalette;
1933 if (!rPalette.Ok())
1934 {
1935 if (m_hOldFont)
1936 {
1937 m_hOldFont = 0;
1938 }
1939 }
1940 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1941 if (!m_hOldPalette)
1942 m_hOldPalette = (WXHPALETTE)hOldPal;
1943} // end of wxDC::SetPalette
1408104d 1944
f6bcfd97
BP
1945void wxDC::SetFont(
1946 const wxFont& rFont
1947)
1408104d 1948{
f6bcfd97
BP
1949 //
1950 // Set the old object temporarily, in case the assignment deletes an object
1951 // that's not yet selected out.
1952 //
1953 if (m_hOldFont)
1954 {
f6bcfd97
BP
1955 m_hOldFont = 0;
1956 }
f6bcfd97 1957 m_font = rFont;
f6bcfd97
BP
1958 if (!rFont.Ok())
1959 {
f6bcfd97
BP
1960 m_hOldFont = 0;
1961 }
1962
e99762c0
DW
1963 m_font.SetPS(m_hPS); // this will realize the font
1964
1965 if (m_font.Ok())
f6bcfd97 1966 {
e99762c0 1967 HFONT hFont = m_font.GetResourceHandle();
f6bcfd97
BP
1968 if (hFont == (HFONT) NULL)
1969 {
1970 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1971 }
1972 if (!m_hOldFont)
1973 m_hOldFont = (WXHFONT) hFont;
1974 }
e99762c0 1975} // end of wxDC::SetFont
1408104d 1976
7e99520b
DW
1977void wxDC::SetPen(
1978 const wxPen& rPen
1979)
1408104d 1980{
7e99520b
DW
1981 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1982
1983 if (m_pen == rPen)
1984 return;
1985 m_pen = rPen;
1986 if (!m_pen.Ok())
1987 return;
1988
26ac77db
DW
1989 if (m_hOldPen)
1990 m_hOldPen = 0L;
1991 m_pen = rPen;
7e99520b 1992
26ac77db 1993 if (!m_pen.Ok())
7e99520b 1994 {
26ac77db
DW
1995 if (m_hOldPen)
1996 {
1997 m_pen.SetPS((HPS)m_hOldPen);
1998 }
1999 m_hOldPen = 0L;
7e99520b 2000 }
51c1d535 2001
26ac77db 2002 if (m_pen.Ok())
51c1d535 2003 {
26ac77db
DW
2004 if (m_pen.GetResourceHandle())
2005 {
2006 m_pen.SetPS(m_hPS);
2007 if (!m_hOldPen)
2008 m_hOldPen = m_pen.GetPS();
2009 }
29172908 2010 ::GpiSetColor(m_hPS, m_pen.GetColour().GetPixel());
51c1d535 2011 }
1408104d 2012}
7e99520b 2013
51c1d535
DW
2014void wxDC::SetBrush(
2015 const wxBrush& rBrush
2016)
1408104d 2017{
15f03b25
DW
2018 wxCHECK_RET( Ok(), wxT("invalid window dc") );
2019
15f03b25
DW
2020 if (m_hOldBrush)
2021 m_hOldBrush = 0L;
2022 m_brush = rBrush;
5fd2b2c6
DW
2023 if (!m_brush.Ok())
2024 if (m_brush == rBrush)
2025 return;
2026 if (!m_brush.Ok())
2027 if (m_hOldBrush)
2028 m_hOldBrush = 0L;
15f03b25
DW
2029
2030 if (!m_brush.Ok())
2031 {
2032 if (m_hOldBrush)
2033 {
2034 m_brush.SetPS((HPS)m_hOldBrush);
2035 }
2036 m_hOldBrush = 0L;
2037 }
2038
2039 if (m_brush.Ok())
2040 {
2041 if (m_brush.GetResourceHandle())
2042 {
2043 m_brush.SetPS(m_hPS);
2044 if (!m_hOldBrush)
5fd2b2c6 2045 m_hOldBrush = (WXHWND)m_brush.GetPS();
15f03b25
DW
2046 }
2047 }
2048} // end of wxDC::SetBrush
1408104d 2049
5fd2b2c6
DW
2050void wxDC::SetBackground(
2051 const wxBrush& rBrush
2052)
1408104d 2053{
5fd2b2c6
DW
2054 m_backgroundBrush = rBrush;
2055 if (!m_backgroundBrush.Ok())
2056 return;
2057 if (m_pCanvas)
2058 {
aad6765c 2059 bool bCustomColours = true;
5fd2b2c6
DW
2060
2061 //
2062 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
2063 // change background colours from the control-panel specified colours.
2064 //
2065 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
2066 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
aad6765c 2067 bCustomColours = false;
5fd2b2c6
DW
2068 if (bCustomColours)
2069 {
2070 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
2071 {
aad6765c 2072 m_pCanvas->SetTransparent(true);
5fd2b2c6
DW
2073 }
2074 else
2075 {
2076 //
2077 // Setting the background brush of a DC
2078 // doesn't affect the window background colour. However,
2079 // I'm leaving in the transparency setting because it's needed by
2080 // various controls (e.g. wxStaticText) to determine whether to draw
2081 // transparently or not. TODO: maybe this should be a new function
2082 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
2083 // parent?
2084 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
2085 //
aad6765c 2086 m_pCanvas->SetTransparent(false);
5fd2b2c6
DW
2087 }
2088 }
2089 }
2090 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
2091 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
2092} // end of wxDC::SetBackground
1408104d 2093
7e99520b
DW
2094void wxDC::SetBackgroundMode(
2095 int nMode
2096)
1408104d 2097{
7e99520b 2098 m_backgroundMode = nMode;
5fd2b2c6 2099} // end of wxDC::SetBackgroundMode
1408104d 2100
5fd2b2c6
DW
2101void wxDC::SetLogicalFunction(
2102 int nFunction
2103)
1408104d 2104{
5fd2b2c6
DW
2105 m_logicalFunction = nFunction;
2106 SetRop((WXHDC)m_hDC);
2107} // wxDC::SetLogicalFunction
1408104d 2108
5fd2b2c6
DW
2109void wxDC::SetRop(
2110 WXHDC hDC
2111)
ce44c50e 2112{
5fd2b2c6 2113 if (!hDC || m_logicalFunction < 0)
ce44c50e
DW
2114 return;
2115
5fd2b2c6 2116 LONG lCRop;
ce44c50e
DW
2117 switch (m_logicalFunction)
2118 {
5fd2b2c6
DW
2119 case wxXOR:
2120 lCRop = FM_XOR;
2121 break;
2122
2123 case wxINVERT:
2124 lCRop = FM_INVERT;
2125 break;
2126
2127 case wxOR_REVERSE:
2128 lCRop = FM_MERGESRCNOT;
2129 break;
2130
2131 case wxAND_REVERSE:
2132 lCRop = FM_NOTMASKSRC;
2133 break;
2134
2135 case wxCLEAR:
2136 lCRop = FM_ONE;
2137 break;
2138
2139 case wxSET:
2140 lCRop = FM_ZERO;
2141 break;
2142
2143 case wxSRC_INVERT:
2144 lCRop = FM_MERGENOTSRC;
2145 break;
2146
2147 case wxOR_INVERT:
2148 lCRop = FM_MERGESRCNOT;
2149 break;
2150
2151 case wxAND:
2152 lCRop = FM_AND;
2153 break;
2154
2155 case wxOR:
2156 lCRop = FM_OR;
2157 break;
2158
2159 case wxAND_INVERT:
2160 lCRop = FM_SUBTRACT;
2161 break;
2162
2163 case wxEQUIV:
2164 case wxNAND:
2165 case wxCOPY:
2166 default:
2167 lCRop = FM_OVERPAINT;
2168 break;
ce44c50e 2169 }
5fd2b2c6
DW
2170 ::GpiSetMix((HPS)hDC, lCRop);
2171} // end of wxDC::SetRop
ce44c50e 2172
6670f564 2173bool wxDC::StartDoc( const wxString& WXUNUSED(rsMessage) )
ce44c50e 2174{
aad6765c
JS
2175 // We might be previewing, so return true to let it continue.
2176 return true;
5fd2b2c6 2177} // end of wxDC::StartDoc
fb46a9a6
DW
2178
2179void wxDC::EndDoc()
2180{
5fd2b2c6 2181} // end of wxDC::EndDoc
fb46a9a6
DW
2182
2183void wxDC::StartPage()
2184{
5fd2b2c6 2185} // end of wxDC::StartPage
fb46a9a6
DW
2186
2187void wxDC::EndPage()
2188{
5fd2b2c6 2189} // end of wxDC::EndPage
fb46a9a6
DW
2190
2191// ---------------------------------------------------------------------------
2192// text metrics
2193// ---------------------------------------------------------------------------
2194
7cdc2f1e 2195wxCoord wxDC::GetCharHeight() const
fb46a9a6 2196{
05a8bfed
DW
2197 FONTMETRICS vFM; // metrics structure
2198
2199 ::GpiQueryFontMetrics( m_hPS
2200 ,sizeof(FONTMETRICS)
2201 ,&vFM
2202 );
2203 return YDEV2LOGREL(vFM.lXHeight);
fb46a9a6
DW
2204}
2205
7cdc2f1e 2206wxCoord wxDC::GetCharWidth() const
fb46a9a6 2207{
05a8bfed
DW
2208 FONTMETRICS vFM; // metrics structure
2209
2210 ::GpiQueryFontMetrics( m_hPS
2211 ,sizeof(FONTMETRICS)
2212 ,&vFM
2213 );
2214 return XDEV2LOGREL(vFM.lAveCharWidth);
7e99520b
DW
2215}
2216
2217void wxDC::DoGetTextExtent(
2218 const wxString& rsString
2219, wxCoord* pvX
2220, wxCoord* pvY
f44fdfb0 2221, wxCoord* pvDescent
7e99520b
DW
2222, wxCoord* pvExternalLeading
2223, wxFont* pTheFont
2224) const
2225{
2226 POINTL avPoint[TXTBOX_COUNT];
2227 POINTL vPtMin;
2228 POINTL vPtMax;
2229 int i;
2230 int l;
2231 FONTMETRICS vFM; // metrics structure
2232 BOOL bRc;
7e99520b
DW
2233 ERRORID vErrorCode; // last error id code
2234 wxFont* pFontToUse = (wxFont*)pTheFont;
2235
0fba44b4 2236 wxChar zMsg[128]; // DEBUG
2c4a8d17
DW
2237 wxString sError;
2238
7e99520b
DW
2239 if (!pFontToUse)
2240 pFontToUse = (wxFont*)&m_font;
2241 l = rsString.length();
fb46a9a6 2242
7e99520b
DW
2243 //
2244 // In world coordinates.
2245 //
2246 bRc = ::GpiQueryTextBox( m_hPS
2247 ,l
0fba44b4 2248 ,(PCH)rsString.c_str()
7e99520b
DW
2249 ,TXTBOX_COUNT // return maximum information
2250 ,avPoint // array of coordinates points
f44fdfb0 2251 );
7e99520b
DW
2252 if(!bRc)
2253 {
2254 vErrorCode = ::WinGetLastError(wxGetInstance());
2c4a8d17
DW
2255 sError = wxPMErrorToStr(vErrorCode);
2256 // DEBUG
0fba44b4
DW
2257 wxSprintf(zMsg, _T("GpiQueryTextBox for %s: failed with Error: %lx - %s"), rsString.c_str(), vErrorCode, sError.c_str());
2258 (void)wxMessageBox( _T("wxWidgets Menu sample")
2c4a8d17
DW
2259 ,zMsg
2260 ,wxICON_INFORMATION
2261 );
7e99520b
DW
2262 }
2263
2264 vPtMin.x = avPoint[0].x;
2265 vPtMax.x = avPoint[0].x;
2266 vPtMin.y = avPoint[0].y;
2267 vPtMax.y = avPoint[0].y;
2268 for (i = 1; i < 4; i++)
2269 {
2270 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
2271 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
2272 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
2273 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
2274 }
2275 ::GpiQueryFontMetrics( m_hPS
2276 ,sizeof(FONTMETRICS)
2277 ,&vFM
2278 );
2279
2280 if (pvX)
2281 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
2282 if (pvY)
2283 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
2284 if (pvDescent)
2285 *pvDescent = vFM.lMaxDescender;
f44fdfb0 2286 if (pvExternalLeading)
7e99520b 2287 *pvExternalLeading = vFM.lExternalLeading;
fb46a9a6
DW
2288}
2289
5fd2b2c6
DW
2290void wxDC::SetMapMode(
2291 int nMode
2292)
fb46a9a6 2293{
5fd2b2c6
DW
2294 int nPixelWidth = 0;
2295 int nPixelHeight = 0;
2296 int nMmWidth = 1;
2297 int nMmHeight = 1;
2298 LONG lArray[CAPS_VERTICAL_RESOLUTION];
fb46a9a6 2299
5fd2b2c6
DW
2300 m_mappingMode = nMode;
2301
2302 if(::DevQueryCaps( m_hDC
2303 ,CAPS_FAMILY
2304 ,CAPS_VERTICAL_RESOLUTION
2305 ,lArray
2306 ))
2307 {
2308 LONG lHorzRes;
2309 LONG lVertRes;
2310
2311 nPixelWidth = lArray[CAPS_WIDTH];
2312 nPixelHeight = lArray[CAPS_HEIGHT];
2313 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2314 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2315 nMmWidth = (lHorzRes/1000) * nPixelWidth;
2316 nMmWidth = (lVertRes/1000) * nPixelHeight;
2317 }
2318 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
2319 {
2320 return;
2321 }
2322
2323 double dMm2pixelsX = nPixelWidth/nMmWidth;
2324 double dMm2pixelsY = nPixelHeight/nMmHeight;
2325
2326 switch (nMode)
2327 {
2328 case wxMM_TWIPS:
2329 m_logicalScaleX = (twips2mm * dMm2pixelsX);
2330 m_logicalScaleY = (twips2mm * dMm2pixelsY);
2331 break;
2332
2333 case wxMM_POINTS:
2334 m_logicalScaleX = (pt2mm * dMm2pixelsX);
2335 m_logicalScaleY = (pt2mm * dMm2pixelsY);
2336 break;
2337
2338 case wxMM_METRIC:
2339 m_logicalScaleX = dMm2pixelsX;
2340 m_logicalScaleY = dMm2pixelsY;
2341 break;
2342
2343 case wxMM_LOMETRIC:
2344 m_logicalScaleX = (dMm2pixelsX/10.0);
2345 m_logicalScaleY = (dMm2pixelsY/10.0);
2346 break;
2347
2348 case wxMM_TEXT:
2349 default:
2350 m_logicalScaleX = 1.0;
2351 m_logicalScaleY = 1.0;
2352 break;
2353 }
2354 SIZEL vSize;
2355 ULONG ulOptions;
2356
2357 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
2358 if (!ulOptions & PU_ARBITRARY)
2359 {
2360 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
2361 ::GpiSetPS(m_hPS, &vSize, ulOptions);
2362 }
74de9ed6
GD
2363 m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
2364 m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
5fd2b2c6
DW
2365 // ????
2366}; // end of wxDC::SetMapMode
2367
77f4f0a7
WS
2368void wxDC::SetUserScale( double dX,
2369 double dY )
fb46a9a6 2370{
5fd2b2c6
DW
2371 m_userScaleX = dX;
2372 m_userScaleY = dY;
fb46a9a6
DW
2373
2374 SetMapMode(m_mappingMode);
5fd2b2c6 2375} // end of wxDC::SetUserScale
fb46a9a6 2376
77f4f0a7
WS
2377void wxDC::SetAxisOrientation( bool bXLeftRight,
2378 bool bYBottomUp )
fb46a9a6 2379{
5fd2b2c6
DW
2380 m_signX = bXLeftRight ? 1 : -1;
2381 m_signY = bYBottomUp ? -1 : 1;
fb46a9a6
DW
2382
2383 SetMapMode(m_mappingMode);
5fd2b2c6 2384} // end of wxDC::SetAxisOrientation
fb46a9a6 2385
5fd2b2c6
DW
2386void wxDC::SetSystemScale(
2387 double dX
2388, double dY
2389)
fb46a9a6 2390{
5fd2b2c6
DW
2391 m_scaleX = dX;
2392 m_scaleY = dY;
fb46a9a6
DW
2393
2394 SetMapMode(m_mappingMode);
5fd2b2c6 2395} // end of wxDC::SetSystemScale
fb46a9a6 2396
5fd2b2c6
DW
2397void wxDC::SetLogicalOrigin(
2398 wxCoord vX
2399, wxCoord vY
2400)
fb46a9a6 2401{
5fd2b2c6
DW
2402 RECTL vRect;
2403
2404 ::GpiQueryPageViewport( m_hPS
2405 ,&vRect
2406 );
2407 vRect.xRight -= vX;
2408 vRect.yTop += vY;
2409 vRect.xLeft = vX;
2410 vRect.yBottom = vY;
2411 ::GpiSetPageViewport( m_hPS
2412 ,&vRect
2413 );
2414}; // end of wxDC::SetLogicalOrigin
fb46a9a6 2415
8d854fa9 2416void wxDC::SetDeviceOrigin(
5fd2b2c6
DW
2417 wxCoord vX
2418, wxCoord vY
8d854fa9 2419)
fb46a9a6 2420{
26ac77db
DW
2421 RECTL vRect;
2422
5fd2b2c6
DW
2423 m_deviceOriginX = vX;
2424 m_deviceOriginY = vY;
26ac77db
DW
2425 ::GpiQueryPageViewport( m_hPS
2426 ,&vRect
2427 );
5fd2b2c6
DW
2428 vRect.xLeft += vX;
2429 vRect.xRight += vX;
2430 vRect.yBottom -= vY;
2431 vRect.yTop -= vY;
26ac77db
DW
2432 ::GpiSetPageViewport( m_hPS
2433 ,&vRect
2434 );
5fd2b2c6 2435}; // end of wxDC::SetDeviceOrigin
fb46a9a6
DW
2436
2437// ---------------------------------------------------------------------------
2438// coordinates transformations
2439// ---------------------------------------------------------------------------
2440
7cdc2f1e 2441wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
fb46a9a6 2442{
f6bcfd97
BP
2443 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
2444}
fb46a9a6 2445
7cdc2f1e 2446wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
fb46a9a6 2447{
aad6765c 2448 // axis orientation is not taken into account for conversion of a distance
74de9ed6 2449 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
f6bcfd97 2450}
fb46a9a6 2451
7cdc2f1e 2452wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
fb46a9a6 2453{
f6bcfd97
BP
2454 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
2455}
fb46a9a6 2456
7cdc2f1e 2457wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
fb46a9a6 2458{
aad6765c 2459 // axis orientation is not taken into account for conversion of a distance
74de9ed6 2460 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
f6bcfd97 2461}
fb46a9a6 2462
7cdc2f1e 2463wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
fb46a9a6 2464{
f6bcfd97
BP
2465 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
2466}
fb46a9a6 2467
7cdc2f1e 2468wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
fb46a9a6 2469{
aad6765c 2470 // axis orientation is not taken into account for conversion of a distance
74de9ed6 2471 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
f6bcfd97 2472}
fb46a9a6 2473
7cdc2f1e 2474wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
fb46a9a6 2475{
f6bcfd97
BP
2476 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
2477}
fb46a9a6 2478
7cdc2f1e 2479wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
fb46a9a6 2480{
aad6765c 2481 // axis orientation is not taken into account for conversion of a distance
74de9ed6 2482 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
f6bcfd97 2483}
fb46a9a6
DW
2484
2485// ---------------------------------------------------------------------------
2486// bit blit
2487// ---------------------------------------------------------------------------
2488
6670f564
WS
2489bool wxDC::DoBlit( wxCoord vXdest,
2490 wxCoord vYdest,
2491 wxCoord vWidth,
2492 wxCoord vHeight,
2493 wxDC* pSource,
2494 wxCoord vXsrc,
2495 wxCoord vYsrc,
2496 int nRop,
2497 bool bUseMask,
2498 wxCoord WXUNUSED(vXsrcMask),
2499 wxCoord WXUNUSED(vYsrcMask) )
fb46a9a6 2500{
5afb9458
DW
2501 wxMask* pMask = NULL;
2502 CHARBUNDLE vCbnd;
2503 COLORREF vOldTextColor;
2504 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
5afb9458
DW
2505
2506 if (bUseMask)
2507 {
2508 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
2509
2510 pMask = rBmp.GetMask();
2511 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
2512 {
aad6765c 2513 bUseMask = false;
5afb9458
DW
2514 }
2515 }
2516
2517 ::GpiQueryAttrs( m_hPS
2518 ,PRIM_CHAR
2519 ,CBB_COLOR
2520 ,&vCbnd
2521 );
2522 vOldTextColor = (COLORREF)vCbnd.lColor;
2523
2524 if (m_textForegroundColour.Ok())
2525 {
2526 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
2527 ::GpiSetAttrs( m_hPS // presentation-space handle
2528 ,PRIM_CHAR // Char primitive.
2529 ,CBB_COLOR // sets color.
2530 ,0
2531 ,&vCbnd // buffer for attributes.
2532 );
2533 }
2534 if (m_textBackgroundColour.Ok())
2535 {
2536 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
2537 }
2538
2539 LONG lRop = ROP_SRCCOPY;
2540
2541 switch (nRop)
2542 {
2543 case wxXOR: lRop = ROP_SRCINVERT; break;
2544 case wxINVERT: lRop = ROP_DSTINVERT; break;
2545 case wxOR_REVERSE: lRop = 0x00DD0228; break;
2546 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
2547 case wxCLEAR: lRop = ROP_ZERO; break;
2548 case wxSET: lRop = ROP_ONE; break;
2549 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
2550 case wxAND: lRop = ROP_SRCAND; break;
2551 case wxOR: lRop = ROP_SRCPAINT; break;
2552 case wxEQUIV: lRop = 0x00990066; break;
2553 case wxNAND: lRop = 0x007700E6; break;
2554 case wxAND_INVERT: lRop = 0x00220326; break;
2555 case wxCOPY: lRop = ROP_SRCCOPY; break;
2556 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
2557 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
2558 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
2559 default:
2560 wxFAIL_MSG( wxT("unsupported logical function") );
aad6765c 2561 return false;
5afb9458
DW
2562 }
2563
2564 bool bSuccess;
b02121c3 2565
5afb9458
DW
2566 if (bUseMask)
2567 {
2568 //
2569 // Blit bitmap with mask
2570 //
2571
2572 //
b02121c3 2573 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
5afb9458 2574 //
b02121c3
DW
2575 HDC hDCMask;
2576 HDC hDCBuffer;
2577 HPS hPSMask;
2578 HPS hPSBuffer;
2579 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
2580 BITMAPINFOHEADER2 vBmpHdr;
893758d5 2581 HBITMAP hBufBitmap;
b02121c3
DW
2582 SIZEL vSize = {0, 0};
2583 LONG rc;
2584
b02121c3
DW
2585 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
2586 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
2587 vBmpHdr.cx = vWidth;
2588 vBmpHdr.cy = vHeight;
2589 vBmpHdr.cPlanes = 1;
2590 vBmpHdr.cBitCount = 24;
2591
893758d5 2592#if wxUSE_DC_CACHEING
893758d5
DW
2593 {
2594 //
2595 // create a temp buffer bitmap and DCs to access it and the mask
2596 //
2597 wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
2598 ,pSource->GetHPS()
2599 );
2600 wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
2601 ,GetHPS()
2602 );
2603 wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
2604 ,vWidth
2605 ,vHeight
2606 );
2607
2608 hPSMask = pDCCacheEntry1->m_hPS;
2609 hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
2610 hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
6670f564 2611 wxUnusedVar(hDCMask);
893758d5 2612 }
6670f564 2613#else
893758d5
DW
2614 {
2615 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2616 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2617 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2618 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2619 hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
2620 }
6670f564 2621#endif
893758d5 2622
b93aba84 2623 POINTL aPoint1[4] = { {0, 0}
aad6765c
JS
2624 ,{vWidth, vHeight}
2625 ,{vXdest, vYdest}
2626 ,{vXdest + vWidth, vYdest + vHeight}
b02121c3 2627 };
b93aba84 2628 POINTL aPoint2[4] = { {0, 0}
aad6765c
JS
2629 ,{vWidth, vHeight}
2630 ,{vXsrc, vYsrc}
2631 ,{vXsrc + vWidth, vYsrc + vHeight}
b02121c3 2632 };
b93aba84 2633 POINTL aPoint3[4] = { {vXdest, vYdest}
aad6765c
JS
2634 ,{vXdest + vWidth, vYdest + vHeight}
2635 ,{vXsrc, vYsrc}
2636 ,{vXsrc + vWidth, vYsrc + vHeight}
23e356de 2637 };
b93aba84 2638 POINTL aPoint4[4] = { {vXdest, vYdest}
aad6765c
JS
2639 ,{vXdest + vWidth, vYdest + vHeight}
2640 ,{0, 0}
2641 ,{vWidth, vHeight}
b02121c3
DW
2642 };
2643 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
2644 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
5afb9458 2645
b02121c3
DW
2646 //
2647 // Copy dest to buffer
2648 //
2649 rc = ::GpiBitBlt( hPSBuffer
2650 ,GetHPS()
2651 ,4L
2652 ,aPoint1
2653 ,ROP_SRCCOPY
2654 ,BBO_IGNORE
2655 );
2656 if (rc == GPI_ERROR)
2657 {
2658 wxLogLastError(wxT("BitBlt"));
2659 }
5afb9458 2660
b02121c3
DW
2661 //
2662 // Copy src to buffer using selected raster op
2663 //
2664 rc = ::GpiBitBlt( hPSBuffer
2665 ,GetHPS()
2666 ,4L
2667 ,aPoint2
2668 ,lRop
2669 ,BBO_IGNORE
2670 );
2671 if (rc == GPI_ERROR)
2672 {
2673 wxLogLastError(wxT("BitBlt"));
2674 }
5afb9458 2675
b02121c3
DW
2676 //
2677 // Set masked area in buffer to BLACK (pixel value 0)
2678 //
2679 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
2680 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
2681
2682 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2683 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2684
2685 rc = ::GpiBitBlt( hPSBuffer
2686 ,hPSMask
2687 ,4L
2688 ,aPoint2
2689 ,ROP_SRCAND
2690 ,BBO_IGNORE
2691 );
2692 if (rc == GPI_ERROR)
2693 {
2694 wxLogLastError(wxT("BitBlt"));
2695 }
5afb9458 2696
b02121c3
DW
2697 //
2698 // Set unmasked area in dest to BLACK
2699 //
2700 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2701 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2702 rc = ::GpiBitBlt( GetHPS()
2703 ,hPSMask
2704 ,4L
23e356de 2705 ,aPoint3
b02121c3
DW
2706 ,ROP_SRCAND
2707 ,BBO_IGNORE
2708 );
2709 if (rc == GPI_ERROR)
2710 {
2711 wxLogLastError(wxT("BitBlt"));
5afb9458 2712 }
b02121c3
DW
2713
2714 //
2715 // Restore colours to original values
2716 //
2717 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
2718 ::GpiSetColor(GetHPS(), vPrevCol);
2719
2720 //
2721 // OR buffer to dest
2722 //
2723 rc = ::GpiBitBlt( GetHPS()
2724 ,hPSMask
2725 ,4L
23e356de 2726 ,aPoint4
b02121c3
DW
2727 ,ROP_SRCPAINT
2728 ,BBO_IGNORE
2729 );
2730 if (rc == GPI_ERROR)
2731 {
aad6765c 2732 bSuccess = false;
b02121c3
DW
2733 wxLogLastError(wxT("BitBlt"));
2734 }
2735
2736 //
2737 // Tidy up temporary DCs and bitmap
2738 //
2739 ::GpiSetBitmap(hPSMask, NULLHANDLE);
2740 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
893758d5 2741#if !wxUSE_DC_CACHEING
b02121c3
DW
2742 ::GpiDestroyPS(hPSMask);
2743 ::GpiDestroyPS(hPSBuffer);
2744 ::DevCloseDC(hDCMask);
2745 ::DevCloseDC(hDCBuffer);
2746 ::GpiDeleteBitmap(hBufBitmap);
893758d5 2747#endif
aad6765c 2748 bSuccess = true;
5afb9458 2749 }
b02121c3
DW
2750 else // no mask, just BitBlt() it
2751 {
b93aba84 2752 POINTL aPoint[4] = { {vXdest, vYdest}
aad6765c
JS
2753 ,{vXdest + vWidth, vYdest + vHeight}
2754 ,{vXsrc, vYsrc}
2755 ,{vXsrc + vWidth, vYsrc + vHeight}
b02121c3
DW
2756 };
2757
5afb9458
DW
2758 bSuccess = (::GpiBitBlt( m_hPS
2759 ,pSource->GetHPS()
2760 ,4L
2761 ,aPoint
2762 ,lRop
2763 ,BBO_IGNORE
2764 ) != GPI_ERROR);
2765 if (!bSuccess )
2766 {
2767 wxLogLastError(wxT("BitBlt"));
2768 }
b02121c3 2769 }
5afb9458
DW
2770 vCbnd.lColor = (LONG)vOldTextColor;
2771 ::GpiSetAttrs( m_hPS // presentation-space handle
2772 ,PRIM_CHAR // Char primitive.
2773 ,CBB_COLOR // sets color.
2774 ,0
2775 ,&vCbnd // buffer for attributes.
2776 );
2777 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
2778 return bSuccess;
fb46a9a6
DW
2779}
2780
5fd2b2c6
DW
2781void wxDC::DoGetSize(
2782 int* pnWidth
2783, int* pnHeight
2784) const
fb46a9a6 2785{
5fd2b2c6
DW
2786 LONG lArray[CAPS_HEIGHT];
2787
2788 if(::DevQueryCaps( m_hDC
2789 ,CAPS_FAMILY
2790 ,CAPS_HEIGHT
2791 ,lArray
2792 ))
2793 {
2794 *pnWidth = lArray[CAPS_WIDTH];
2795 *pnHeight = lArray[CAPS_HEIGHT];
2796 }
2797}; // end of wxDC::DoGetSize(
fb46a9a6 2798
6670f564
WS
2799void wxDC::DoGetSizeMM( int* pnWidth,
2800 int* pnHeight ) const
fb46a9a6 2801{
5fd2b2c6
DW
2802 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2803
2804 if(::DevQueryCaps( m_hDC
2805 ,CAPS_FAMILY
2806 ,CAPS_VERTICAL_RESOLUTION
2807 ,lArray
2808 ))
2809 {
6670f564
WS
2810 if(pnWidth)
2811 {
2812 int nWidth = lArray[CAPS_WIDTH];
2813 int nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2814 *pnWidth = (nHorzRes/1000) * nWidth;
2815 }
5fd2b2c6 2816
6670f564
WS
2817 if(pnHeight)
2818 {
2819 int nHeight = lArray[CAPS_HEIGHT];
2820 int nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2821 *pnHeight = (nVertRes/1000) * nHeight;
2822 }
5fd2b2c6
DW
2823 }
2824}; // end of wxDC::DoGetSizeMM
fb46a9a6
DW
2825
2826wxSize wxDC::GetPPI() const
2827{
5fd2b2c6 2828 LONG lArray[CAPS_VERTICAL_RESOLUTION];
322d45dd
DW
2829 int nWidth = 0;
2830 int nHeight = 0;
fb46a9a6 2831
5fd2b2c6
DW
2832 if(::DevQueryCaps( m_hDC
2833 ,CAPS_FAMILY
2834 ,CAPS_VERTICAL_RESOLUTION
2835 ,lArray
2836 ))
2837 {
2838 int nPelWidth;
2839 int nPelHeight;
2840 int nHorzRes;
2841 int nVertRes;
2842
2843 nPelWidth = lArray[CAPS_WIDTH];
2844 nPelHeight = lArray[CAPS_HEIGHT];
2845 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2846 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
9923c37d
DW
2847 nWidth = (int)((nHorzRes/39.3) * nPelWidth);
2848 nHeight = (int)((nVertRes/39.3) * nPelHeight);
5fd2b2c6 2849 }
6670f564
WS
2850 wxSize ppisize(nWidth, nHeight);
2851 return ppisize;
5fd2b2c6
DW
2852} // end of wxDC::GetPPI
2853
2854void wxDC::SetLogicalScale(
2855 double dX
2856, double dY
2857)
fb46a9a6 2858{
5fd2b2c6
DW
2859 m_logicalScaleX = dX;
2860 m_logicalScaleY = dY;
2861}; // end of wxDC::SetLogicalScale