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