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