]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dc.cpp
fixed compilation in Unicode build
[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
51c1d535
DW
560void wxDC::DoFloodFill(
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);
5fd2b2c6 580} // end of wxDC::DoFloodFill
0e320a79 581
51c1d535
DW
582bool wxDC::DoGetPixel(
583 wxCoord vX
584, wxCoord vY
585, wxColour* pCol
586) const
1408104d 587{
51c1d535
DW
588 POINTL vPoint;
589 LONG lColor;
590
591 vPoint.x = vX;
5fd2b2c6 592 vPoint.y = OS2Y(vY,0);
51c1d535 593 lColor = ::GpiSetPel(m_hPS, &vPoint);
5fd2b2c6
DW
594
595 //
596 // Get the color of the pen
597 //
598 LONG lPencolor = 0x00ffffff;
599
600 if (m_pen.Ok())
601 {
602 lPencolor = m_pen.GetColour().GetPixel();
603 }
604
605 //
606 // return the color of the pixel
607 //
608 if(pCol)
609 pCol->Set( GetRValue(lColor)
610 ,GetGValue(lColor)
611 ,GetBValue(lColor)
612 );
613 return(lColor == lPencolor);
614} // end of wxDC::DoGetPixel
0e320a79 615
f07bb01b
DW
616void wxDC::DoCrossHair(
617 wxCoord vX
618, wxCoord vY
619)
0e320a79 620{
5fd2b2c6
DW
621 vY = OS2Y(vY,0);
622
f07bb01b
DW
623 wxCoord vX1 = vX - VIEWPORT_EXTENT;
624 wxCoord vY1 = vY - VIEWPORT_EXTENT;
625 wxCoord vX2 = vX + VIEWPORT_EXTENT;
626 wxCoord vY2 = vY + VIEWPORT_EXTENT;
627 POINTL vPoint[4];
628
629 vPoint[0].x = vX1;
5fd2b2c6 630 vPoint[0].y = vY;
f07bb01b
DW
631
632 vPoint[1].x = vX2;
5fd2b2c6 633 vPoint[1].y = vY;
f07bb01b
DW
634
635 ::GpiMove(m_hPS, &vPoint[0]);
636 ::GpiLine(m_hPS, &vPoint[1]);
637
638 vPoint[2].x = vX;
5fd2b2c6 639 vPoint[2].y = vY1;
f07bb01b
DW
640
641 vPoint[3].x = vX;
5fd2b2c6 642 vPoint[3].y = vY2;
f07bb01b
DW
643
644 ::GpiMove(m_hPS, &vPoint[2]);
645 ::GpiLine(m_hPS, &vPoint[3]);
5fd2b2c6
DW
646 CalcBoundingBox(vX1, vY1);
647 CalcBoundingBox(vX2, vY2);
f07bb01b 648} // end of wxDC::DoCrossHair
1408104d 649
7e99520b
DW
650void wxDC::DoDrawLine(
651 wxCoord vX1
652, wxCoord vY1
653, wxCoord vX2
654, wxCoord vY2
655)
0e320a79 656{
7e99520b
DW
657 POINTL vPoint[2];
658
5fd2b2c6
DW
659 vY1 = OS2Y(vY1,0);
660 vY2 = OS2Y(vY2,0);
661
7e99520b 662 vPoint[0].x = vX1;
5fd2b2c6 663 vPoint[0].y = vY1;
7e99520b 664 vPoint[1].x = vX2;
5fd2b2c6 665 vPoint[1].y = vY2;
7e99520b
DW
666 ::GpiMove(m_hPS, &vPoint[0]);
667 ::GpiLine(m_hPS, &vPoint[1]);
5fd2b2c6
DW
668 CalcBoundingBox(vX1, vY1);
669 CalcBoundingBox(vX2, vY2);
f07bb01b 670} // end of wxDC::DoDrawLine
1408104d 671
51c1d535
DW
672//////////////////////////////////////////////////////////////////////////////
673// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
674// and ending at (x2, y2). The current pen is used for the outline and the
675// current brush for filling the shape. The arc is drawn in an anticlockwise
676// direction from the start point to the end point.
677//////////////////////////////////////////////////////////////////////////////
678void wxDC::DoDrawArc(
679 wxCoord vX1
680, wxCoord vY1
681, wxCoord vX2
682, wxCoord vY2
683, wxCoord vXc
684, wxCoord vYc
685)
1408104d 686{
51c1d535
DW
687 POINTL vPtlPos;
688 POINTL vPtlArc[2]; // Structure for current position
689 int nDx;
690 int nDy;
691 double dRadius;
692 double dAngl1;
693 double dAngl2;
694 double dAnglmid;
695 wxCoord vXm;
696 wxCoord vYm;
697 ARCPARAMS vArcp; // Structure for arc parameters
698
699 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
700 return; // Draw point ??
701 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
702 ,(double)(vX1 - vXc)
703 ) +
704 hypot( (double)(vY2 - vYc)
705 ,(double)(vX2 - vXc)
706 )
707 );
708
709 dAngl1 = atan2( (double)(vY1 - vYc)
710 ,(double)(vX1 - vXc)
711 );
712 dAngl2 = atan2( (double)(vY2 - vYc)
713 ,(double)(vX2 - vXc)
714 );
715 if(dAngl2 < dAngl1)
716 dAngl2 += M_PI * 2;
717
718 //
719 // GpiPointArc can't draw full arc
720 //
721 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
722 {
723 //
724 // Medium point
725 //
726 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
727 vXm = vXc + dRadius * cos(dAnglmid);
728 vYm = vYc + dRadius * sin(dAnglmid);
e99762c0
DW
729 DoDrawArc( vX1, vY1
730 ,vXm, vYm
731 ,vXc, vYc
51c1d535 732 );
e99762c0
DW
733 DoDrawArc( vXm, vYm
734 ,vX2, vY2
735 ,vXc, vYc
51c1d535
DW
736 );
737 return;
738 }
739
740 //
741 // Medium point
742 //
743 dAnglmid = (dAngl1 + dAngl2)/2.;
744 vXm = vXc + dRadius * cos(dAnglmid);
745 vYm = vYc + dRadius * sin(dAnglmid);
746
747 //
748 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
749 //
750 vArcp.lR = 0;
751 vArcp.lQ = 1;
752 vArcp.lP = 1;
753 vArcp.lS = 0;
754 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
755
756 vPtlPos.x = vX1; // Loads x-coordinate
757 vPtlPos.y = vY1; // Loads y-coordinate
758 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
e99762c0
DW
759 vPtlArc[0].x = vXm;
760 vPtlArc[0].y = vYm;
51c1d535
DW
761 vPtlArc[1].x = vX2;
762 vPtlArc[1].y = vY2;
763 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
5fd2b2c6
DW
764 CalcBoundingBox( (vXc - dRadius)
765 ,(vYc - dRadius)
766 );
767 CalcBoundingBox( (vXc + dRadius)
768 ,(vYc + dRadius)
769 );
f07bb01b 770} // end of wxDC::DoDrawArc
1408104d 771
51c1d535
DW
772void wxDC::DoDrawCheckMark(
773 wxCoord vX1
774, wxCoord vY1
775, wxCoord vWidth
776, wxCoord vHeight
777)
f6bcfd97 778{
51c1d535
DW
779 POINTL vPoint[2];
780
5fd2b2c6
DW
781 vY1 = OS2Y(vY1,vHeight);
782
51c1d535
DW
783 vPoint[0].x = vX1;
784 vPoint[0].y = vY1;
785 vPoint[1].x = vX1 + vWidth;
786 vPoint[1].y = vY1 + vHeight;
787
788 ::GpiMove(m_hPS, &vPoint[0]);
789 ::GpiBox( m_hPS // handle to a presentation space
790 ,DRO_OUTLINE // draw the box outline ? or ?
791 ,&vPoint[1] // address of the corner
792 ,0L // horizontal corner radius
793 ,0L // vertical corner radius
794 );
795 if(vWidth > 4 && vHeight > 4)
796 {
797 int nTmp;
798
799 vPoint[0].x += 2; vPoint[0].y += 2;
800 vPoint[1].x -= 2; vPoint[1].y -= 2;
801 ::GpiMove(m_hPS, &vPoint[0]);
802 ::GpiLine(m_hPS, &vPoint[1]);
803 nTmp = vPoint[0].x;
804 vPoint[0].x = vPoint[1].x;
805 vPoint[1].x = nTmp;
806 ::GpiMove(m_hPS, &vPoint[0]);
807 ::GpiLine(m_hPS, &vPoint[1]);
808 }
5fd2b2c6
DW
809 CalcBoundingBox( vX1
810 ,vY1
811 );
812
813 wxCoord vX2 = vX1 + vWidth;
814 wxCoord vY2 = vY1 + vHeight;
815
816 CalcBoundingBox( vX2
817 ,vY2
818 );
f07bb01b 819} // end of wxDC::DoDrawCheckMark
f6bcfd97 820
51c1d535
DW
821void wxDC::DoDrawPoint(
822 wxCoord vX
823, wxCoord vY
824)
1408104d 825{
51c1d535 826 POINTL vPoint;
5fd2b2c6 827 COLORREF vColor = 0x00ffffff;
51c1d535 828
5fd2b2c6
DW
829 if (m_pen.Ok())
830 {
831 vColor = m_pen.GetColour().GetPixel();
832 }
833 ::GpiSetColor(m_hPS, vColor);
51c1d535 834 vPoint.x = vX;
5fd2b2c6 835 vPoint.y = OS2Y(vY,0);
51c1d535 836 ::GpiSetPel(m_hPS, &vPoint);
5fd2b2c6
DW
837 CalcBoundingBox( vX
838 ,vY
839 );
f07bb01b 840} // end of wxDC::DoDrawPoint
1408104d 841
51c1d535
DW
842void wxDC::DoDrawPolygon(
843 int n
844, wxPoint vPoints[]
845, wxCoord vXoffset
846, wxCoord vYoffset
847, int nFillStyle
848)
1408104d 849{
51c1d535
DW
850 ULONG ulCount = 1; // Number of polygons.
851 POLYGON vPlgn; // polygon.
852 ULONG flOptions = 0L; // Drawing options.
853
854//////////////////////////////////////////////////////////////////////////////
855// This contains fields of option bits... to draw boundary lines as well as
856// the area interior.
857//
858// Drawing boundary lines:
859// POLYGON_NOBOUNDARY Does not draw boundary lines.
860// POLYGON_BOUNDARY Draws boundary lines (the default).
861//
862// Construction of the area interior:
863// POLYGON_ALTERNATE Constructs interior in alternate mode
864// (the default).
865// POLYGON_WINDING Constructs interior in winding mode.
866//////////////////////////////////////////////////////////////////////////////
867
868 ULONG flModel = 0L; // Drawing model.
869
870//////////////////////////////////////////////////////////////////////////////
871// Drawing model.
872// POLYGON_INCL Fill is inclusive of bottom right (the default).
873// POLYGON_EXCL Fill is exclusive of bottom right.
874// This is provided to aid migration from other graphics models.
875//////////////////////////////////////////////////////////////////////////////
876
877 LONG lHits = 0L; // Correlation/error indicator.
878 POINTL vPoint;
879 int i;
880 int nIsTRANSPARENT = 0;
881 LONG lBorderColor = 0L;
882 LONG lColor = 0L;
883
884 lBorderColor = m_pen.GetColour().GetPixel();
885 lColor = m_brush.GetColour().GetPixel();
886 if(m_brush.GetStyle() == wxTRANSPARENT)
887 nIsTRANSPARENT = 1;
888
889 vPlgn.ulPoints = n;
890 vPlgn.aPointl = (POINTL*) calloc( n + 1
891 ,sizeof(POINTL)
892 ); // well, new will call malloc
893
894 for(i = 0; i < n; i++)
895 {
5fd2b2c6
DW
896 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
897 vPlgn.aPointl[i].y = OS2Y(vPoints[i].y,0); // +yoffset;
51c1d535
DW
898 }
899 flModel = POLYGON_BOUNDARY;
900 if(nFillStyle == wxWINDING_RULE)
901 flModel |= POLYGON_WINDING;
902 else
903 flModel |= POLYGON_ALTERNATE;
904
905 vPoint.x = vXoffset;
5fd2b2c6 906 vPoint.y = OS2Y(vYoffset,0);
51c1d535
DW
907
908 ::GpiSetColor(m_hPS, lBorderColor);
909 ::GpiMove(m_hPS, &vPoint);
910 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
911 free(vPlgn.aPointl);
f07bb01b 912} // end of wxDC::DoDrawPolygon
1408104d 913
51c1d535
DW
914void wxDC::DoDrawLines(
915 int n
916, wxPoint vPoints[]
917, wxCoord vXoffset
918, wxCoord vYoffset
919)
1408104d 920{
51c1d535
DW
921 POINTL vPoint;
922
5fd2b2c6
DW
923 if (vXoffset != 0L || vXoffset != 0L)
924 {
925 int i;
926
927 vPoint.x = vPoints[0].x + vXoffset;
928 vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
929 ::GpiMove(m_hPS, &vPoint);
51c1d535 930
5fd2b2c6 931 LONG lBorderColor = m_pen.GetColour().GetPixel();
51c1d535 932
5fd2b2c6
DW
933 ::GpiSetColor(m_hPS, lBorderColor);
934 for(i = 1; i < n; i++)
935 {
936 vPoint.x = vPoints[i].x + vXoffset;
937 vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
938 ::GpiLine(m_hPS, &vPoint);
939 }
940 }
941 else
51c1d535 942 {
5fd2b2c6
DW
943 int i;
944
945 CalcBoundingBox( vPoints[i].x
946 ,vPoints[i].y
947 );
948 vPoint.x = vPoints[0].x;
949 vPoint.y = OS2Y(vPoints[0].y,0);
950 ::GpiMove(m_hPS, &vPoint);
951
952 for (i = 0; i < n; i++)
953 {
954 CalcBoundingBox( vPoints[i].x
955 ,vPoints[i].y
956 );
957 vPoint.x = vPoints[i].x;
958 vPoint.y = OS2Y(vPoints[i].y,0);
959 ::GpiLine(m_hPS, &vPoint);
960 }
51c1d535 961 }
f07bb01b 962} // end of wxDC::DoDrawLines
1408104d 963
7e99520b 964void wxDC::DoDrawRectangle(
f44fdfb0 965 wxCoord vX
7e99520b
DW
966, wxCoord vY
967, wxCoord vWidth
968, wxCoord vHeight
969)
1408104d 970{
7e99520b 971 POINTL vPoint[2];
51c1d535
DW
972 LONG lControl;
973 LONG lColor;
974 LONG lBorderColor;
975 int nIsTRANSPARENT = 0;
7e99520b 976
5fd2b2c6
DW
977 vY = OS2Y(vY,vHeight);
978
979 wxCoord vX2 = vX + vWidth;
980 wxCoord vY2 = vY + vHeight;
981
7e99520b 982 vPoint[0].x = vX;
5fd2b2c6 983 vPoint[0].y = vY;
f44fdfb0 984 vPoint[1].x = vX + vWidth;
5fd2b2c6 985 vPoint[1].y = vY + vHeight;
7e99520b 986 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
987 lColor = m_brush.GetColour().GetPixel();
988 lBorderColor = m_pen.GetColour().GetPixel();
989 if (m_brush.GetStyle() == wxTRANSPARENT)
990 nIsTRANSPARENT = 1;
991 if(lColor == lBorderColor || nIsTRANSPARENT)
992 {
993 lControl = DRO_OUTLINEFILL; //DRO_FILL;
994 if(m_brush.GetStyle() == wxTRANSPARENT)
995 lControl = DRO_OUTLINE;
996
8d854fa9 997 ::GpiSetColor(m_hPS, lColor);
51c1d535
DW
998 ::GpiBox( m_hPS // handle to a presentation space
999 ,lControl // draw the box outline ? or ?
1000 ,&vPoint[1] // address of the corner
1001 ,0L // horizontal corner radius
1002 ,0L // vertical corner radius
1003 );
1004 }
1005 else
1006 {
1007 lControl = DRO_OUTLINE;
1008 ::GpiSetColor( m_hPS
1009 ,lBorderColor
1010 );
1011 ::GpiBox( m_hPS
1012 ,lControl
1013 ,&vPoint[1]
1014 ,0L
1015 ,0L
1016 );
1017 lControl = DRO_FILL;
1018 ::GpiSetColor( m_hPS
1019 ,lColor
1020 );
8d854fa9 1021 vPoint[0].x = vX + 1;
5fd2b2c6 1022 vPoint[0].y = vY + 1;
ad7f3189
DW
1023 vPoint[1].x = vX + vWidth - 1;
1024 vPoint[1].y = vY + vHeight - 1;
8d854fa9 1025 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
1026 ::GpiBox( m_hPS
1027 ,lControl
1028 ,&vPoint[1]
1029 ,0L
1030 ,0L
1031 );
1032 }
5fd2b2c6
DW
1033 CalcBoundingBox(vX, vY);
1034 CalcBoundingBox(vX2, vY2);
f07bb01b 1035} // end of wxDC::DoDrawRectangle
1408104d 1036
7e99520b
DW
1037void wxDC::DoDrawRoundedRectangle(
1038 wxCoord vX
1039, wxCoord vY
1040, wxCoord vWidth
1041, wxCoord vHeight
1042, double dRadius
1043)
1408104d 1044{
7e99520b 1045 POINTL vPoint[2];
51c1d535 1046 LONG lControl;
7e99520b 1047
5fd2b2c6
DW
1048 vY = OS2Y(vY,vHeight);
1049
1050 wxCoord vX2 = (vX + vWidth);
1051 wxCoord vY2 = (vY + vHeight);
1052
7e99520b 1053 vPoint[0].x = vX;
8d854fa9 1054 vPoint[0].y = YLOG2DEV(vY) - vHeight;
7e99520b 1055 vPoint[1].x = vX + vWidth;
8d854fa9 1056 vPoint[1].y = vY;
7e99520b 1057 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
1058
1059 lControl = DRO_OUTLINEFILL; //DRO_FILL;
1060 if (m_brush.GetStyle() == wxTRANSPARENT)
1061 lControl = DRO_OUTLINE;
f44fdfb0
DW
1062 ::GpiBox( m_hPS // handle to a presentation space
1063 ,DRO_OUTLINE // draw the box outline ? or ?
1064 ,&vPoint[1] // address of the corner
1065 ,(LONG)dRadius // horizontal corner radius
1066 ,(LONG)dRadius // vertical corner radius
7e99520b 1067 );
5fd2b2c6
DW
1068 CalcBoundingBox(vX, vY);
1069 CalcBoundingBox(vX2, vY2);
f07bb01b 1070} // end of wxDC::DoDrawRoundedRectangle
1408104d 1071
51c1d535
DW
1072// Draw Ellipse within box (x,y) - (x+width, y+height)
1073void wxDC::DoDrawEllipse(
1074 wxCoord vX
1075, wxCoord vY
1076, wxCoord vWidth
1077, wxCoord vHeight
1078)
1408104d 1079{
51c1d535
DW
1080 POINTL vPtlPos; // Structure for current position
1081 FIXED vFxMult; // Multiplier for ellipse
1082 ARCPARAMS vArcp; // Structure for arc parameters
1083
5fd2b2c6
DW
1084 vY = OS2Y(vY,vHeight);
1085
51c1d535
DW
1086 vArcp.lR = 0;
1087 vArcp.lQ = vHeight/2;
1088 vArcp.lP = vWidth/2;
1089 vArcp.lS = 0;
1090 ::GpiSetArcParams( m_hPS
1091 ,&vArcp
1092 ); // Sets parameters to default
1093 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
1094 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1095 ::GpiMove( m_hPS
1096 ,&vPtlPos
1097 ); // Sets current position
1098 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
1099
1100 //
1101 // DRO_FILL, DRO_OTLINEFILL - where to get
1102 //
1103 ::GpiFullArc( m_hPS
1104 ,DRO_OUTLINE
1105 ,vFxMult
1106 ); // Draws full arc with center at current position
5fd2b2c6
DW
1107
1108 wxCoord vX2 = (vX + vWidth);
1109 wxCoord vY2 = (vY + vHeight);
1110
1111 CalcBoundingBox(vX, vY);
1112 CalcBoundingBox(vX2, vY2);
f07bb01b 1113} // end of wxDC::DoDrawEllipse
1408104d 1114
51c1d535
DW
1115void wxDC::DoDrawEllipticArc(
1116 wxCoord vX
1117, wxCoord vY
1118, wxCoord vWidth
1119, wxCoord vHeight
1120, double dSa
1121, double dEa
1122)
1408104d 1123{
51c1d535
DW
1124 POINTL vPtlPos; // Structure for current position
1125 FIXED vFxMult; // Multiplier for ellipse
1126 ARCPARAMS vArcp; // Structure for arc parameters
1127 FIXED vFSa;
1128 FIXED vFSweepa; // Start angle, sweep angle
1129 double dIntPart;
1130 double dFractPart;
1131 double dRadius;
1132
5fd2b2c6
DW
1133 vY = OS2Y(vY,vHeight);
1134
51c1d535
DW
1135 dFractPart = modf(dSa,&dIntPart);
1136 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1137 dFractPart = modf(dEa - dSa, &dIntPart);
1138 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
1139
1140 //
1141 // Ellipse main axis (r,q), (p,s) with center at (0,0)
1142 //
1143 vArcp.lR = 0;
1144 vArcp.lQ = vHeight/2;
1145 vArcp.lP = vWidth/2;
1146 vArcp.lS = 0;
1147 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
1148 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
1149 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
1150 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
1151
1152 //
1153 // May be not to the center ?
1154 //
1155 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
1156 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
1157 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
1158
1159 //
1160 // DRO_FILL, DRO_OTLINEFILL - where to get
1161 //
1162 ::GpiPartialArc( m_hPS
1163 ,&vPtlPos
1164 ,vFxMult
1165 ,vFSa
1166 ,vFSweepa
1167 );
5fd2b2c6
DW
1168 wxCoord vX2 = (vX + vWidth);
1169 wxCoord vY2 = (vY + vHeight);
1170
1171 CalcBoundingBox(vX, vY);
1172 CalcBoundingBox(vX2, vY2);
f07bb01b 1173} // end of wxDC::DoDrawEllipticArc
1408104d 1174
f07bb01b
DW
1175void wxDC::DoDrawIcon(
1176 const wxIcon& rIcon
1177, wxCoord vX
1178, wxCoord vY
1179)
1408104d 1180{
5fd2b2c6 1181 vY = OS2Y(vY,rIcon.GetHeight());
f07bb01b
DW
1182 wxCHECK_RET( rIcon.Ok(), wxT("invalid icon in DrawIcon") );
1183
1184 ::WinDrawPointer( GetHPS()
1185 ,vX
1186 ,vY
1187 ,(HPOINTER)GetHiconOf(rIcon)
1188 ,DP_NORMAL
1189 );
5fd2b2c6
DW
1190 CalcBoundingBox(vX, vY);
1191 CalcBoundingBox(vX + rIcon.GetWidth(), vY + rIcon.GetHeight());
f07bb01b
DW
1192} // end of wxDC::DoDrawIcon
1193
1194void wxDC::DoDrawBitmap(
1195 const wxBitmap& rBmp
1196, wxCoord vX
1197, wxCoord vY
1198, bool bUseMask
1199)
1408104d 1200{
f07bb01b
DW
1201 POINTL vPoint = {vX, vY};
1202
1203 ::WinDrawBitmap( GetHPS()
1204 ,(HBITMAP)GetHbitmapOf(rBmp)
1205 ,NULL
1206 ,&vPoint
1207 ,0L
1208 ,0L
1209 ,DBM_NORMAL
1210 );
1211} // end of wxDC::DoDrawBitmap
1408104d 1212
7e99520b
DW
1213void wxDC::DoDrawText(
1214 const wxString& rsText
1215, wxCoord vX
1216, wxCoord vY
1217)
1408104d 1218{
5fd2b2c6
DW
1219 wxCoord vWidth;
1220 wxCoord vHeight;
1221
7e99520b
DW
1222 DrawAnyText( rsText
1223 ,vX
1224 ,vY
1225 );
5fd2b2c6
DW
1226
1227 CalcBoundingBox(vX, vY);
1228 GetTextExtent(rsText, &vWidth, &vHeight);
1229 CalcBoundingBox((vX + vWidth), (vY + vHeight));
1230} // end of wxDC::DoDrawText
1408104d 1231
7e99520b
DW
1232void wxDC::DrawAnyText(
1233 const wxString& rsText
1234, wxCoord vX
1235, wxCoord vY
1236)
f6bcfd97 1237{
7e99520b
DW
1238 int nOldBackground = 0;
1239 POINTL vPtlStart;
1240 LONG lHits;
5fd2b2c6
DW
1241 wxCoord vTextX = 0;
1242 wxCoord vTextY = 0;
f6bcfd97 1243
7e99520b
DW
1244 //
1245 // prepare for drawing the text
1246 //
1247
1248 //
1249 // Set text color attributes
1250 //
1251 if (m_textForegroundColour.Ok())
1252 {
1253 SetTextColor( m_hPS
1254 ,(int)m_textForegroundColour.GetPixel()
1255 );
1256 }
1257
1258 if (m_textBackgroundColour.Ok())
1259 {
1260 nOldBackground = SetTextBkColor( m_hPS
1261 ,(int)m_textBackgroundColour.GetPixel()
1262 );
1263 }
1264 SetBkMode( m_hPS
1265 ,m_backgroundMode
1266 );
5fd2b2c6
DW
1267 GetTextExtent( rsText
1268 ,&vTextX
1269 ,&vTextY
1270 );
7e99520b 1271 vPtlStart.x = vX;
5fd2b2c6 1272 vPtlStart.y = OS2Y(vY,vTextY);
7e99520b
DW
1273
1274 lHits = ::GpiCharStringAt( m_hPS
1275 ,&vPtlStart
1276 ,rsText.length()
1277 ,(PCH)rsText.c_str()
1278 );
1279 if (lHits != GPI_OK)
1280 {
1281 wxLogLastError(wxT("TextOut"));
1282 }
1283
1284 //
1285 // Restore the old parameters (text foreground colour may be left because
1286 // it never is set to anything else, but background should remain
1287 // transparent even if we just drew an opaque string)
1288 //
1289 if (m_textBackgroundColour.Ok())
1290 SetTextBkColor( m_hPS
1291 ,nOldBackground
1292 );
1293 SetBkMode( m_hPS
1294 ,wxTRANSPARENT
1295 );
1296}
1297
1298void wxDC::DoDrawRotatedText(
1299 const wxString& rsText
1300, wxCoord vX
1301, wxCoord vY
1302, double dAngle
1303)
c8ce6bcc 1304{
7e99520b
DW
1305 if (dAngle == 0.0)
1306 {
1307 DoDrawText( rsText
1308 ,vX
1309 ,vY
1310 );
1311 }
1312
c8ce6bcc
DW
1313 // TODO:
1314 /*
1315 if ( angle == 0.0 )
1316 {
1317 DoDrawText(text, x, y);
1318 }
1319 else
1320 {
1321 LOGFONT lf;
1322 wxFillLogFont(&lf, &m_font);
1323
1324 // GDI wants the angle in tenth of degree
1325 long angle10 = (long)(angle * 10);
1326 lf.lfEscapement = angle10;
1327 lf. lfOrientation = angle10;
1328
1329 HFONT hfont = ::CreateFontIndirect(&lf);
1330 if ( !hfont )
1331 {
1332 wxLogLastError("CreateFont");
1333 }
1334 else
1335 {
1336 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
1337
1338 DrawAnyText(text, x, y);
1339
1340 (void)::SelectObject(GetHdc(), hfontOld);
1341 }
1342
1343 // call the bounding box by adding all four vertices of the rectangle
1344 // containing the text to it (simpler and probably not slower than
1345 // determining which of them is really topmost/leftmost/...)
1346 wxCoord w, h;
1347 GetTextExtent(text, &w, &h);
1348
1349 double rad = DegToRad(angle);
1350
1351 // "upper left" and "upper right"
1352 CalcBoundingBox(x, y);
1353 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
1354 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1355
1356 // "bottom left" and "bottom right"
1357 x += (wxCoord)(h*sin(rad));
1358 y += (wxCoord)(h*cos(rad));
1359 CalcBoundingBox(x, y);
1360 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
1361 }
1362*/
1363}
1364
fb46a9a6
DW
1365// ---------------------------------------------------------------------------
1366// set GDI objects
1367// ---------------------------------------------------------------------------
1408104d 1368
5fd2b2c6
DW
1369void wxDC::SetPalette(
1370 const wxPalette& rPalette
1371)
1408104d 1372{
5fd2b2c6
DW
1373 if (m_hOldFont)
1374 {
1375 m_hOldFont = 0;
1376 }
1377 m_palette = rPalette;
1378 if (!rPalette.Ok())
1379 {
1380 if (m_hOldFont)
1381 {
1382 m_hOldFont = 0;
1383 }
1384 }
1385 HPALETTE hOldPal = ::GpiSelectPalette((HDC) m_hPS, (HPALETTE) m_palette.GetHPALETTE());
1386 if (!m_hOldPalette)
1387 m_hOldPalette = (WXHPALETTE)hOldPal;
1388} // end of wxDC::SetPalette
1408104d 1389
f6bcfd97
BP
1390void wxDC::SetFont(
1391 const wxFont& rFont
1392)
1408104d 1393{
f6bcfd97
BP
1394 //
1395 // Set the old object temporarily, in case the assignment deletes an object
1396 // that's not yet selected out.
1397 //
1398 if (m_hOldFont)
1399 {
f6bcfd97
BP
1400 m_hOldFont = 0;
1401 }
f6bcfd97 1402 m_font = rFont;
f6bcfd97
BP
1403 if (!rFont.Ok())
1404 {
f6bcfd97
BP
1405 m_hOldFont = 0;
1406 }
1407
e99762c0
DW
1408 m_font.SetPS(m_hPS); // this will realize the font
1409
1410 if (m_font.Ok())
f6bcfd97 1411 {
e99762c0 1412 HFONT hFont = m_font.GetResourceHandle();
f6bcfd97
BP
1413 if (hFont == (HFONT) NULL)
1414 {
1415 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
1416 }
1417 if (!m_hOldFont)
1418 m_hOldFont = (WXHFONT) hFont;
1419 }
e99762c0 1420} // end of wxDC::SetFont
1408104d 1421
7e99520b
DW
1422void wxDC::SetPen(
1423 const wxPen& rPen
1424)
1408104d 1425{
7e99520b
DW
1426 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1427
1428 if (m_pen == rPen)
1429 return;
1430 m_pen = rPen;
1431 if (!m_pen.Ok())
1432 return;
1433
26ac77db
DW
1434 if (m_hOldPen)
1435 m_hOldPen = 0L;
1436 m_pen = rPen;
7e99520b 1437
26ac77db 1438 if (!m_pen.Ok())
7e99520b 1439 {
26ac77db
DW
1440 if (m_hOldPen)
1441 {
1442 m_pen.SetPS((HPS)m_hOldPen);
1443 }
1444 m_hOldPen = 0L;
7e99520b 1445 }
51c1d535 1446
26ac77db 1447 if (m_pen.Ok())
51c1d535 1448 {
26ac77db
DW
1449 if (m_pen.GetResourceHandle())
1450 {
1451 m_pen.SetPS(m_hPS);
1452 if (!m_hOldPen)
1453 m_hOldPen = m_pen.GetPS();
1454 }
51c1d535 1455 }
1408104d 1456}
7e99520b 1457
51c1d535
DW
1458void wxDC::SetBrush(
1459 const wxBrush& rBrush
1460)
1408104d 1461{
15f03b25
DW
1462 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1463
15f03b25
DW
1464 if (m_hOldBrush)
1465 m_hOldBrush = 0L;
1466 m_brush = rBrush;
5fd2b2c6
DW
1467 if (!m_brush.Ok())
1468 if (m_brush == rBrush)
1469 return;
1470 if (!m_brush.Ok())
1471 if (m_hOldBrush)
1472 m_hOldBrush = 0L;
15f03b25
DW
1473
1474 if (!m_brush.Ok())
1475 {
1476 if (m_hOldBrush)
1477 {
1478 m_brush.SetPS((HPS)m_hOldBrush);
1479 }
1480 m_hOldBrush = 0L;
1481 }
1482
1483 if (m_brush.Ok())
1484 {
1485 if (m_brush.GetResourceHandle())
1486 {
1487 m_brush.SetPS(m_hPS);
1488 if (!m_hOldBrush)
5fd2b2c6 1489 m_hOldBrush = (WXHWND)m_brush.GetPS();
15f03b25
DW
1490 }
1491 }
1492} // end of wxDC::SetBrush
1408104d 1493
5fd2b2c6
DW
1494void wxDC::SetBackground(
1495 const wxBrush& rBrush
1496)
1408104d 1497{
5fd2b2c6
DW
1498 m_backgroundBrush = rBrush;
1499 if (!m_backgroundBrush.Ok())
1500 return;
1501 if (m_pCanvas)
1502 {
1503 bool bCustomColours = TRUE;
1504
1505 //
1506 // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to
1507 // change background colours from the control-panel specified colours.
1508 //
1509 if (m_pCanvas->IsKindOf(CLASSINFO(wxWindow)) &&
1510 ((m_pCanvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
1511 bCustomColours = FALSE;
1512 if (bCustomColours)
1513 {
1514 if (m_backgroundBrush.GetStyle()==wxTRANSPARENT)
1515 {
1516 m_pCanvas->SetTransparent(TRUE);
1517 }
1518 else
1519 {
1520 //
1521 // Setting the background brush of a DC
1522 // doesn't affect the window background colour. However,
1523 // I'm leaving in the transparency setting because it's needed by
1524 // various controls (e.g. wxStaticText) to determine whether to draw
1525 // transparently or not. TODO: maybe this should be a new function
1526 // wxWindow::SetTransparency(). Should that apply to the child itself, or the
1527 // parent?
1528 // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour());
1529 //
1530 m_pCanvas->SetTransparent(FALSE);
1531 }
1532 }
1533 }
1534 COLORREF vNewColor = m_backgroundBrush.GetColour().GetPixel();
1535 (void)::GpiSetBackColor((HPS)m_hPS, (LONG)vNewColor);
1536} // end of wxDC::SetBackground
1408104d 1537
7e99520b
DW
1538void wxDC::SetBackgroundMode(
1539 int nMode
1540)
1408104d 1541{
7e99520b 1542 m_backgroundMode = nMode;
5fd2b2c6 1543} // end of wxDC::SetBackgroundMode
1408104d 1544
5fd2b2c6
DW
1545void wxDC::SetLogicalFunction(
1546 int nFunction
1547)
1408104d 1548{
5fd2b2c6
DW
1549 m_logicalFunction = nFunction;
1550 SetRop((WXHDC)m_hDC);
1551} // wxDC::SetLogicalFunction
1408104d 1552
5fd2b2c6
DW
1553void wxDC::SetRop(
1554 WXHDC hDC
1555)
ce44c50e 1556{
5fd2b2c6 1557 if (!hDC || m_logicalFunction < 0)
ce44c50e
DW
1558 return;
1559
5fd2b2c6 1560 LONG lCRop;
ce44c50e
DW
1561 switch (m_logicalFunction)
1562 {
5fd2b2c6
DW
1563 case wxXOR:
1564 lCRop = FM_XOR;
1565 break;
1566
1567 case wxINVERT:
1568 lCRop = FM_INVERT;
1569 break;
1570
1571 case wxOR_REVERSE:
1572 lCRop = FM_MERGESRCNOT;
1573 break;
1574
1575 case wxAND_REVERSE:
1576 lCRop = FM_NOTMASKSRC;
1577 break;
1578
1579 case wxCLEAR:
1580 lCRop = FM_ONE;
1581 break;
1582
1583 case wxSET:
1584 lCRop = FM_ZERO;
1585 break;
1586
1587 case wxSRC_INVERT:
1588 lCRop = FM_MERGENOTSRC;
1589 break;
1590
1591 case wxOR_INVERT:
1592 lCRop = FM_MERGESRCNOT;
1593 break;
1594
1595 case wxAND:
1596 lCRop = FM_AND;
1597 break;
1598
1599 case wxOR:
1600 lCRop = FM_OR;
1601 break;
1602
1603 case wxAND_INVERT:
1604 lCRop = FM_SUBTRACT;
1605 break;
1606
1607 case wxEQUIV:
1608 case wxNAND:
1609 case wxCOPY:
1610 default:
1611 lCRop = FM_OVERPAINT;
1612 break;
ce44c50e 1613 }
5fd2b2c6
DW
1614 ::GpiSetMix((HPS)hDC, lCRop);
1615} // end of wxDC::SetRop
ce44c50e 1616
5fd2b2c6
DW
1617bool wxDC::StartDoc(
1618 const wxString& rsMessage
1619)
ce44c50e 1620{
fb46a9a6
DW
1621 // We might be previewing, so return TRUE to let it continue.
1622 return TRUE;
5fd2b2c6 1623} // end of wxDC::StartDoc
fb46a9a6
DW
1624
1625void wxDC::EndDoc()
1626{
5fd2b2c6 1627} // end of wxDC::EndDoc
fb46a9a6
DW
1628
1629void wxDC::StartPage()
1630{
5fd2b2c6 1631} // end of wxDC::StartPage
fb46a9a6
DW
1632
1633void wxDC::EndPage()
1634{
5fd2b2c6 1635} // end of wxDC::EndPage
fb46a9a6
DW
1636
1637// ---------------------------------------------------------------------------
1638// text metrics
1639// ---------------------------------------------------------------------------
1640
7cdc2f1e 1641wxCoord wxDC::GetCharHeight() const
fb46a9a6 1642{
05a8bfed
DW
1643 FONTMETRICS vFM; // metrics structure
1644
1645 ::GpiQueryFontMetrics( m_hPS
1646 ,sizeof(FONTMETRICS)
1647 ,&vFM
1648 );
1649 return YDEV2LOGREL(vFM.lXHeight);
fb46a9a6
DW
1650}
1651
7cdc2f1e 1652wxCoord wxDC::GetCharWidth() const
fb46a9a6 1653{
05a8bfed
DW
1654 FONTMETRICS vFM; // metrics structure
1655
1656 ::GpiQueryFontMetrics( m_hPS
1657 ,sizeof(FONTMETRICS)
1658 ,&vFM
1659 );
1660 return XDEV2LOGREL(vFM.lAveCharWidth);
7e99520b
DW
1661}
1662
1663void wxDC::DoGetTextExtent(
1664 const wxString& rsString
1665, wxCoord* pvX
1666, wxCoord* pvY
f44fdfb0 1667, wxCoord* pvDescent
7e99520b
DW
1668, wxCoord* pvExternalLeading
1669, wxFont* pTheFont
1670) const
1671{
1672 POINTL avPoint[TXTBOX_COUNT];
1673 POINTL vPtMin;
1674 POINTL vPtMax;
1675 int i;
1676 int l;
1677 FONTMETRICS vFM; // metrics structure
1678 BOOL bRc;
1679 char* pStr;
1680 ERRORID vErrorCode; // last error id code
1681 wxFont* pFontToUse = (wxFont*)pTheFont;
1682
2c4a8d17
DW
1683 char zMsg[128]; // DEBUG
1684 wxString sError;
1685
7e99520b
DW
1686 if (!pFontToUse)
1687 pFontToUse = (wxFont*)&m_font;
1688 l = rsString.length();
1689 pStr = (PCH) rsString.c_str();
fb46a9a6 1690
7e99520b
DW
1691 //
1692 // In world coordinates.
1693 //
1694 bRc = ::GpiQueryTextBox( m_hPS
1695 ,l
1696 ,pStr
1697 ,TXTBOX_COUNT // return maximum information
1698 ,avPoint // array of coordinates points
f44fdfb0 1699 );
7e99520b
DW
1700 if(!bRc)
1701 {
1702 vErrorCode = ::WinGetLastError(wxGetInstance());
2c4a8d17
DW
1703 sError = wxPMErrorToStr(vErrorCode);
1704 // DEBUG
1705 sprintf(zMsg, "GpiQueryTextBox for %s: failed with Error: %x - %s", pStr, vErrorCode, sError.c_str());
1706 (void)wxMessageBox( "wxWindows Menu sample"
1707 ,zMsg
1708 ,wxICON_INFORMATION
1709 );
7e99520b
DW
1710 }
1711
1712 vPtMin.x = avPoint[0].x;
1713 vPtMax.x = avPoint[0].x;
1714 vPtMin.y = avPoint[0].y;
1715 vPtMax.y = avPoint[0].y;
1716 for (i = 1; i < 4; i++)
1717 {
1718 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1719 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1720 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1721 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1722 }
1723 ::GpiQueryFontMetrics( m_hPS
1724 ,sizeof(FONTMETRICS)
1725 ,&vFM
1726 );
1727
1728 if (pvX)
1729 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1730 if (pvY)
1731 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1732 if (pvDescent)
1733 *pvDescent = vFM.lMaxDescender;
f44fdfb0 1734 if (pvExternalLeading)
7e99520b 1735 *pvExternalLeading = vFM.lExternalLeading;
fb46a9a6
DW
1736}
1737
5fd2b2c6
DW
1738void wxDC::SetMapMode(
1739 int nMode
1740)
fb46a9a6 1741{
5fd2b2c6
DW
1742 int nPixelWidth = 0;
1743 int nPixelHeight = 0;
1744 int nMmWidth = 1;
1745 int nMmHeight = 1;
1746 LONG lArray[CAPS_VERTICAL_RESOLUTION];
fb46a9a6 1747
5fd2b2c6
DW
1748 m_mappingMode = nMode;
1749
1750 if(::DevQueryCaps( m_hDC
1751 ,CAPS_FAMILY
1752 ,CAPS_VERTICAL_RESOLUTION
1753 ,lArray
1754 ))
1755 {
1756 LONG lHorzRes;
1757 LONG lVertRes;
1758
1759 nPixelWidth = lArray[CAPS_WIDTH];
1760 nPixelHeight = lArray[CAPS_HEIGHT];
1761 lHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
1762 lVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
1763 nMmWidth = (lHorzRes/1000) * nPixelWidth;
1764 nMmWidth = (lVertRes/1000) * nPixelHeight;
1765 }
1766 if ((nPixelWidth == 0) || (nPixelHeight == 0) || (nMmWidth == 0) || (nMmHeight == 0))
1767 {
1768 return;
1769 }
1770
1771 double dMm2pixelsX = nPixelWidth/nMmWidth;
1772 double dMm2pixelsY = nPixelHeight/nMmHeight;
1773
1774 switch (nMode)
1775 {
1776 case wxMM_TWIPS:
1777 m_logicalScaleX = (twips2mm * dMm2pixelsX);
1778 m_logicalScaleY = (twips2mm * dMm2pixelsY);
1779 break;
1780
1781 case wxMM_POINTS:
1782 m_logicalScaleX = (pt2mm * dMm2pixelsX);
1783 m_logicalScaleY = (pt2mm * dMm2pixelsY);
1784 break;
1785
1786 case wxMM_METRIC:
1787 m_logicalScaleX = dMm2pixelsX;
1788 m_logicalScaleY = dMm2pixelsY;
1789 break;
1790
1791 case wxMM_LOMETRIC:
1792 m_logicalScaleX = (dMm2pixelsX/10.0);
1793 m_logicalScaleY = (dMm2pixelsY/10.0);
1794 break;
1795
1796 case wxMM_TEXT:
1797 default:
1798 m_logicalScaleX = 1.0;
1799 m_logicalScaleY = 1.0;
1800 break;
1801 }
1802 SIZEL vSize;
1803 ULONG ulOptions;
1804
1805 ulOptions = ::GpiQueryPS(m_hPS, &vSize);
1806 if (!ulOptions & PU_ARBITRARY)
1807 {
1808 ulOptions = PU_ARBITRARY | GPIF_DEFAULT;
1809 ::GpiSetPS(m_hPS, &vSize, ulOptions);
1810 }
74de9ed6
GD
1811 m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT);
1812 m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT);
5fd2b2c6
DW
1813 // ????
1814}; // end of wxDC::SetMapMode
1815
1816void wxDC::SetUserScale(
1817 double dX
1818, double dY
1819)
fb46a9a6 1820{
5fd2b2c6
DW
1821 m_userScaleX = dX;
1822 m_userScaleY = dY;
fb46a9a6
DW
1823
1824 SetMapMode(m_mappingMode);
5fd2b2c6 1825} // end of wxDC::SetUserScale
fb46a9a6 1826
5fd2b2c6
DW
1827void wxDC::SetAxisOrientation(
1828 bool bXLeftRight
1829, bool bYBottomUp
1830)
fb46a9a6 1831{
5fd2b2c6
DW
1832 m_signX = bXLeftRight ? 1 : -1;
1833 m_signY = bYBottomUp ? -1 : 1;
fb46a9a6
DW
1834
1835 SetMapMode(m_mappingMode);
5fd2b2c6 1836} // end of wxDC::SetAxisOrientation
fb46a9a6 1837
5fd2b2c6
DW
1838void wxDC::SetSystemScale(
1839 double dX
1840, double dY
1841)
fb46a9a6 1842{
5fd2b2c6
DW
1843 m_scaleX = dX;
1844 m_scaleY = dY;
fb46a9a6
DW
1845
1846 SetMapMode(m_mappingMode);
5fd2b2c6 1847} // end of wxDC::SetSystemScale
fb46a9a6 1848
5fd2b2c6
DW
1849void wxDC::SetLogicalOrigin(
1850 wxCoord vX
1851, wxCoord vY
1852)
fb46a9a6 1853{
5fd2b2c6
DW
1854 RECTL vRect;
1855
1856 ::GpiQueryPageViewport( m_hPS
1857 ,&vRect
1858 );
1859 vRect.xRight -= vX;
1860 vRect.yTop += vY;
1861 vRect.xLeft = vX;
1862 vRect.yBottom = vY;
1863 ::GpiSetPageViewport( m_hPS
1864 ,&vRect
1865 );
1866}; // end of wxDC::SetLogicalOrigin
fb46a9a6 1867
8d854fa9 1868void wxDC::SetDeviceOrigin(
5fd2b2c6
DW
1869 wxCoord vX
1870, wxCoord vY
8d854fa9 1871)
fb46a9a6 1872{
26ac77db
DW
1873 RECTL vRect;
1874
5fd2b2c6
DW
1875 m_deviceOriginX = vX;
1876 m_deviceOriginY = vY;
26ac77db
DW
1877 ::GpiQueryPageViewport( m_hPS
1878 ,&vRect
1879 );
5fd2b2c6
DW
1880 vRect.xLeft += vX;
1881 vRect.xRight += vX;
1882 vRect.yBottom -= vY;
1883 vRect.yTop -= vY;
26ac77db
DW
1884 ::GpiSetPageViewport( m_hPS
1885 ,&vRect
1886 );
5fd2b2c6 1887}; // end of wxDC::SetDeviceOrigin
fb46a9a6
DW
1888
1889// ---------------------------------------------------------------------------
1890// coordinates transformations
1891// ---------------------------------------------------------------------------
1892
7cdc2f1e 1893wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
fb46a9a6 1894{
f6bcfd97
BP
1895 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1896}
fb46a9a6 1897
7cdc2f1e 1898wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
fb46a9a6 1899{
74de9ed6
GD
1900 // axis orientation is not taken into account for conversion of a distance
1901 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX));
f6bcfd97 1902}
fb46a9a6 1903
7cdc2f1e 1904wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
fb46a9a6 1905{
f6bcfd97
BP
1906 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
1907}
fb46a9a6 1908
7cdc2f1e 1909wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
fb46a9a6 1910{
74de9ed6
GD
1911 // axis orientation is not taken into account for conversion of a distance
1912 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY));
f6bcfd97 1913}
fb46a9a6 1914
7cdc2f1e 1915wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
fb46a9a6 1916{
f6bcfd97
BP
1917 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
1918}
fb46a9a6 1919
7cdc2f1e 1920wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
fb46a9a6 1921{
74de9ed6
GD
1922 // axis orientation is not taken into account for conversion of a distance
1923 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX);
f6bcfd97 1924}
fb46a9a6 1925
7cdc2f1e 1926wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
fb46a9a6 1927{
f6bcfd97
BP
1928 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
1929}
fb46a9a6 1930
7cdc2f1e 1931wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
fb46a9a6 1932{
74de9ed6
GD
1933 // axis orientation is not taken into account for conversion of a distance
1934 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY);
f6bcfd97 1935}
fb46a9a6
DW
1936
1937// ---------------------------------------------------------------------------
1938// bit blit
1939// ---------------------------------------------------------------------------
1940
5afb9458
DW
1941bool wxDC::DoBlit(
1942 wxCoord vXdest
1943, wxCoord vYdest
1944, wxCoord vWidth
1945, wxCoord vHeight
1946, wxDC* pSource
1947, wxCoord vXsrc
1948, wxCoord vYsrc
1949, int nRop
1950, bool bUseMask
893758d5
DW
1951, wxCoord vXsrcMask
1952, wxCoord vYsrcMask
5afb9458 1953)
fb46a9a6 1954{
5afb9458
DW
1955 wxMask* pMask = NULL;
1956 CHARBUNDLE vCbnd;
1957 COLORREF vOldTextColor;
1958 COLORREF vOldBackground = ::GpiQueryBackColor(m_hPS);
5afb9458
DW
1959
1960 if (bUseMask)
1961 {
1962 const wxBitmap& rBmp = pSource->m_vSelectedBitmap;
1963
1964 pMask = rBmp.GetMask();
1965 if (!(rBmp.Ok() && pMask && pMask->GetMaskBitmap()))
1966 {
1967 bUseMask = FALSE;
1968 }
1969 }
1970
1971 ::GpiQueryAttrs( m_hPS
1972 ,PRIM_CHAR
1973 ,CBB_COLOR
1974 ,&vCbnd
1975 );
1976 vOldTextColor = (COLORREF)vCbnd.lColor;
1977
1978 if (m_textForegroundColour.Ok())
1979 {
1980 vCbnd.lColor = (LONG)m_textForegroundColour.GetPixel();
1981 ::GpiSetAttrs( m_hPS // presentation-space handle
1982 ,PRIM_CHAR // Char primitive.
1983 ,CBB_COLOR // sets color.
1984 ,0
1985 ,&vCbnd // buffer for attributes.
1986 );
1987 }
1988 if (m_textBackgroundColour.Ok())
1989 {
1990 ::GpiSetBackColor(m_hPS, (LONG)m_textBackgroundColour.GetPixel());
1991 }
1992
1993 LONG lRop = ROP_SRCCOPY;
1994
1995 switch (nRop)
1996 {
1997 case wxXOR: lRop = ROP_SRCINVERT; break;
1998 case wxINVERT: lRop = ROP_DSTINVERT; break;
1999 case wxOR_REVERSE: lRop = 0x00DD0228; break;
2000 case wxAND_REVERSE: lRop = ROP_SRCERASE; break;
2001 case wxCLEAR: lRop = ROP_ZERO; break;
2002 case wxSET: lRop = ROP_ONE; break;
2003 case wxOR_INVERT: lRop = ROP_MERGEPAINT; break;
2004 case wxAND: lRop = ROP_SRCAND; break;
2005 case wxOR: lRop = ROP_SRCPAINT; break;
2006 case wxEQUIV: lRop = 0x00990066; break;
2007 case wxNAND: lRop = 0x007700E6; break;
2008 case wxAND_INVERT: lRop = 0x00220326; break;
2009 case wxCOPY: lRop = ROP_SRCCOPY; break;
2010 case wxNO_OP: lRop = ROP_NOTSRCERASE; break;
2011 case wxSRC_INVERT: lRop = ROP_SRCINVERT; break;
2012 case wxNOR: lRop = ROP_NOTSRCCOPY; break;
2013 default:
2014 wxFAIL_MSG( wxT("unsupported logical function") );
2015 return FALSE;
2016 }
2017
2018 bool bSuccess;
b02121c3 2019
5afb9458
DW
2020 if (bUseMask)
2021 {
2022 //
2023 // Blit bitmap with mask
2024 //
2025
2026 //
b02121c3 2027 // Create a temp buffer bitmap and DCs/PSs to access it and the mask
5afb9458 2028 //
b02121c3
DW
2029 HDC hDCMask;
2030 HDC hDCBuffer;
2031 HPS hPSMask;
2032 HPS hPSBuffer;
2033 DEVOPENSTRUC vDOP = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
2034 BITMAPINFOHEADER2 vBmpHdr;
893758d5 2035 HBITMAP hBufBitmap;
b02121c3
DW
2036 SIZEL vSize = {0, 0};
2037 LONG rc;
2038
b02121c3
DW
2039 memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
2040 vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
2041 vBmpHdr.cx = vWidth;
2042 vBmpHdr.cy = vHeight;
2043 vBmpHdr.cPlanes = 1;
2044 vBmpHdr.cBitCount = 24;
2045
893758d5
DW
2046#if wxUSE_DC_CACHEING
2047 if (TRUE)
2048 {
2049 //
2050 // create a temp buffer bitmap and DCs to access it and the mask
2051 //
2052 wxDCCacheEntry* pDCCacheEntry1 = FindDCInCache( NULL
2053 ,pSource->GetHPS()
2054 );
2055 wxDCCacheEntry* pDCCacheEntry2 = FindDCInCache( pDCCacheEntry1
2056 ,GetHPS()
2057 );
2058 wxDCCacheEntry* pBitmapCacheEntry = FindBitmapInCache( GetHPS()
2059 ,vWidth
2060 ,vHeight
2061 );
2062
2063 hPSMask = pDCCacheEntry1->m_hPS;
2064 hDCBuffer = (HDC)pDCCacheEntry2->m_hPS;
2065 hBufBitmap = (HBITMAP)pBitmapCacheEntry->m_hBitmap;
2066 }
2067 else
2068#endif
2069 {
2070 hDCMask = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2071 hDCBuffer = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDOP, NULLHANDLE);
2072 hPSMask = ::GpiCreatePS(vHabmain, hDCMask, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2073 hPSBuffer = ::GpiCreatePS(vHabmain, hDCBuffer, &vSize, PU_PELS | GPIT_MICRO | GPIA_ASSOC);
2074 hBufBitmap = ::GpiCreateBitmap(GetHPS(), &vBmpHdr, 0L, NULL, NULL);
2075 }
2076
b02121c3
DW
2077 POINTL aPoint1[4] = { 0, 0
2078 ,vWidth, vHeight
2079 ,vXdest, vYdest
2080 ,vXdest + vWidth, vYdest + vHeight
2081 };
2082 POINTL aPoint2[4] = { 0, 0
2083 ,vWidth, vHeight
2084 ,vXsrc, vYsrc
2085 ,vXsrc + vWidth, vYsrc + vHeight
2086 };
2087 POINTL aPoint3[4] = { vXdest, vYdest
23e356de
DW
2088 ,vXdest + vWidth, vYdest + vHeight
2089 ,vXsrc, vYsrc
2090 ,vXsrc + vWidth, vYsrc + vHeight
2091 };
2092 POINTL aPoint4[4] = { vXdest, vYdest
b02121c3
DW
2093 ,vXdest + vWidth, vYdest + vHeight
2094 ,0, 0
2095 ,vWidth, vHeight
2096 };
2097 ::GpiSetBitmap(hPSMask, (HBITMAP) pMask->GetMaskBitmap());
2098 ::GpiSetBitmap(hPSBuffer, (HBITMAP) hBufBitmap);
5afb9458 2099
b02121c3
DW
2100 //
2101 // Copy dest to buffer
2102 //
2103 rc = ::GpiBitBlt( hPSBuffer
2104 ,GetHPS()
2105 ,4L
2106 ,aPoint1
2107 ,ROP_SRCCOPY
2108 ,BBO_IGNORE
2109 );
2110 if (rc == GPI_ERROR)
2111 {
2112 wxLogLastError(wxT("BitBlt"));
2113 }
5afb9458 2114
b02121c3
DW
2115 //
2116 // Copy src to buffer using selected raster op
2117 //
2118 rc = ::GpiBitBlt( hPSBuffer
2119 ,GetHPS()
2120 ,4L
2121 ,aPoint2
2122 ,lRop
2123 ,BBO_IGNORE
2124 );
2125 if (rc == GPI_ERROR)
2126 {
2127 wxLogLastError(wxT("BitBlt"));
2128 }
5afb9458 2129
b02121c3
DW
2130 //
2131 // Set masked area in buffer to BLACK (pixel value 0)
2132 //
2133 COLORREF vPrevBkCol = ::GpiQueryBackColor(GetHPS());
2134 COLORREF vPrevCol = ::GpiQueryColor(GetHPS());
2135
2136 ::GpiSetBackColor(GetHPS(), OS2RGB(255, 255, 255));
2137 ::GpiSetColor(GetHPS(), OS2RGB(0, 0, 0));
2138
2139 rc = ::GpiBitBlt( hPSBuffer
2140 ,hPSMask
2141 ,4L
2142 ,aPoint2
2143 ,ROP_SRCAND
2144 ,BBO_IGNORE
2145 );
2146 if (rc == GPI_ERROR)
2147 {
2148 wxLogLastError(wxT("BitBlt"));
2149 }
5afb9458 2150
b02121c3
DW
2151 //
2152 // Set unmasked area in dest to BLACK
2153 //
2154 ::GpiSetBackColor(GetHPS(), OS2RGB(0, 0, 0));
2155 ::GpiSetColor(GetHPS(), OS2RGB(255, 255, 255));
2156 rc = ::GpiBitBlt( GetHPS()
2157 ,hPSMask
2158 ,4L
23e356de 2159 ,aPoint3
b02121c3
DW
2160 ,ROP_SRCAND
2161 ,BBO_IGNORE
2162 );
2163 if (rc == GPI_ERROR)
2164 {
2165 wxLogLastError(wxT("BitBlt"));
5afb9458 2166 }
b02121c3
DW
2167
2168 //
2169 // Restore colours to original values
2170 //
2171 ::GpiSetBackColor(GetHPS(), vPrevBkCol);
2172 ::GpiSetColor(GetHPS(), vPrevCol);
2173
2174 //
2175 // OR buffer to dest
2176 //
2177 rc = ::GpiBitBlt( GetHPS()
2178 ,hPSMask
2179 ,4L
23e356de 2180 ,aPoint4
b02121c3
DW
2181 ,ROP_SRCPAINT
2182 ,BBO_IGNORE
2183 );
2184 if (rc == GPI_ERROR)
2185 {
2186 bSuccess = FALSE;
2187 wxLogLastError(wxT("BitBlt"));
2188 }
2189
2190 //
2191 // Tidy up temporary DCs and bitmap
2192 //
2193 ::GpiSetBitmap(hPSMask, NULLHANDLE);
2194 ::GpiSetBitmap(hPSBuffer, NULLHANDLE);
893758d5 2195#if !wxUSE_DC_CACHEING
b02121c3
DW
2196 ::GpiDestroyPS(hPSMask);
2197 ::GpiDestroyPS(hPSBuffer);
2198 ::DevCloseDC(hDCMask);
2199 ::DevCloseDC(hDCBuffer);
2200 ::GpiDeleteBitmap(hBufBitmap);
893758d5 2201#endif
b02121c3 2202 bSuccess = TRUE;
5afb9458 2203 }
b02121c3
DW
2204 else // no mask, just BitBlt() it
2205 {
2206 POINTL aPoint[4] = { vXdest, vYdest
2207 ,vXdest + vWidth, vYdest + vHeight
2208 ,vXsrc, vYsrc
2209 ,vXsrc + vWidth, vYsrc + vHeight
2210 };
2211
5afb9458
DW
2212 bSuccess = (::GpiBitBlt( m_hPS
2213 ,pSource->GetHPS()
2214 ,4L
2215 ,aPoint
2216 ,lRop
2217 ,BBO_IGNORE
2218 ) != GPI_ERROR);
2219 if (!bSuccess )
2220 {
2221 wxLogLastError(wxT("BitBlt"));
2222 }
b02121c3 2223 }
5afb9458
DW
2224 vCbnd.lColor = (LONG)vOldTextColor;
2225 ::GpiSetAttrs( m_hPS // presentation-space handle
2226 ,PRIM_CHAR // Char primitive.
2227 ,CBB_COLOR // sets color.
2228 ,0
2229 ,&vCbnd // buffer for attributes.
2230 );
2231 ::GpiSetBackColor(m_hPS, (LONG)vOldBackground);
2232 return bSuccess;
fb46a9a6
DW
2233}
2234
5fd2b2c6
DW
2235void wxDC::DoGetSize(
2236 int* pnWidth
2237, int* pnHeight
2238) const
fb46a9a6 2239{
5fd2b2c6
DW
2240 LONG lArray[CAPS_HEIGHT];
2241
2242 if(::DevQueryCaps( m_hDC
2243 ,CAPS_FAMILY
2244 ,CAPS_HEIGHT
2245 ,lArray
2246 ))
2247 {
2248 *pnWidth = lArray[CAPS_WIDTH];
2249 *pnHeight = lArray[CAPS_HEIGHT];
2250 }
2251}; // end of wxDC::DoGetSize(
fb46a9a6 2252
5fd2b2c6
DW
2253void wxDC::DoGetSizeMM(
2254 int* pnWidth
2255, int* pnHeight
2256) const
fb46a9a6 2257{
5fd2b2c6
DW
2258 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2259
2260 if(::DevQueryCaps( m_hDC
2261 ,CAPS_FAMILY
2262 ,CAPS_VERTICAL_RESOLUTION
2263 ,lArray
2264 ))
2265 {
2266 int nWidth;
2267 int nHeight;
2268 int nHorzRes;
2269 int nVertRes;
2270
2271 nWidth = lArray[CAPS_WIDTH];
2272 nHeight = lArray[CAPS_HEIGHT];
2273 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2274 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2275 nWidth = (nHorzRes/1000) * nWidth;
2276 nHeight = (nVertRes/1000) * nHeight;
2277 }
2278}; // end of wxDC::DoGetSizeMM
fb46a9a6
DW
2279
2280wxSize wxDC::GetPPI() const
2281{
5fd2b2c6
DW
2282 LONG lArray[CAPS_VERTICAL_RESOLUTION];
2283 int nWidth;
2284 int nHeight;
fb46a9a6 2285
5fd2b2c6
DW
2286 if(::DevQueryCaps( m_hDC
2287 ,CAPS_FAMILY
2288 ,CAPS_VERTICAL_RESOLUTION
2289 ,lArray
2290 ))
2291 {
2292 int nPelWidth;
2293 int nPelHeight;
2294 int nHorzRes;
2295 int nVertRes;
2296
2297 nPelWidth = lArray[CAPS_WIDTH];
2298 nPelHeight = lArray[CAPS_HEIGHT];
2299 nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter
2300 nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter
2301 nWidth = (nHorzRes/39.3) * nPelWidth;
2302 nHeight = (nVertRes/39.3) * nPelHeight;
2303 }
2304 return (wxSize(nWidth,nHeight));
2305} // end of wxDC::GetPPI
2306
2307void wxDC::SetLogicalScale(
2308 double dX
2309, double dY
2310)
fb46a9a6 2311{
5fd2b2c6
DW
2312 m_logicalScaleX = dX;
2313 m_logicalScaleY = dY;
2314}; // end of wxDC::SetLogicalScale
fb46a9a6
DW
2315
2316#if WXWIN_COMPATIBILITY
2317void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
2318 float *descent, float *externalLeading,
2319 wxFont *theFont, bool use16bit) const
2320{
7cdc2f1e 2321 wxCoord x1, y1, descent1, externalLeading1;
fb46a9a6
DW
2322 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
2323 *x = x1; *y = y1;
2324 if (descent)
2325 *descent = descent1;
2326 if (externalLeading)
2327 *externalLeading = externalLeading1;
2328}
2329#endif
2330