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