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