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