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