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