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