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