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