- if ( m_macPort )
- {
- ::SetOrigin( 0 , 0 ) ;
- ::ClipRect( &m_macPort->portRect ) ;
- ::PenNormal() ;
- ::SetPort( m_macOrigPort ) ;
- }
- ++m_macCurrentPortId ;
-};
-
-void wxDC::MacSetupPort() const
-{
- m_macPortId = ++m_macCurrentPortId ;
- ::SetPort(m_macPort);
- ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v);
- ::ClipRect(&m_macClipRect);
-
- m_macFontInstalled = false ;
- m_macBrushInstalled = false ;
- m_macPenInstalled = false ;
-}
-
-void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask )
-{
- if (!Ok())
- return;
- MacVerifySetup() ;
-
- long xx1 = XLOG2DEV(x);
- long yy1 = YLOG2DEV(y);
-
- {
- wxBitmapRefData * bmap = (wxBitmapRefData*) ( bmp.GetRefData()) ;
-
- if ( bmap )
- {
- if ( bmap->m_bitmapType == kMacBitmapTypePict )
- {
- Rect bitmaprect = { 0 , 0 , bmap->m_height , bmap->m_width } ;
- ::OffsetRect( &bitmaprect , xx1 , yy1 ) ;
- ::DrawPicture( bmap->m_hPict , &bitmaprect ) ;
- }
- else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
- {
- if ( bmap->m_hBitmap )
- {
- GWorldPtr bmapworld = bmap->m_hBitmap ;
- PixMapHandle bmappixels ;
- RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
- RGBColor black = { 0,0,0} ;
- RGBForeColor( &black ) ;
- RGBBackColor( &white ) ;
- // RGBForeColor( &m_textForegroundColour.GetPixel() ) ;
- // RGBBackColor( &m_textBackgroundColour.GetPixel() ) ;
-
- bmappixels = GetGWorldPixMap( bmapworld ) ;
- if ( LockPixels(bmappixels) )
- {
- Rect source , dest ;
- source.top = 0 ;
- source.left = 0 ;
- source.right = bmap->m_width ;
- source.bottom = bmap->m_height ;
- dest.top = YLOG2DEV(y) ;
- dest.left = XLOG2DEV(x) ;
- dest.bottom = YLOG2DEV(y + bmap->m_height ) ;
- dest.right = XLOG2DEV(x + bmap->m_width ) ;
- // ::ClipRect(&m_macClipRect);
- CopyBits( &GrafPtr( bmapworld )->portBits , &GrafPtr( m_macPort )->portBits ,
- &source, &dest, srcCopy, NULL ) ;
- /*
- if ( m_clipping )
- {
- long x1 = XLOG2DEV(m_clipX1);
- long y1 = YLOG2DEV(m_clipY1);
- long x2 = XLOG2DEV(m_clipX2);
- long y2 = YLOG2DEV(m_clipY2);
-
- Rect clip = { y1 , x1 , y2 , x2 } ;
- ::ClipRect(&clip);
- }
- */
- UnlockPixels( bmappixels ) ;
- }
- m_macPenInstalled = false ;
- m_macBrushInstalled = false ;
- m_macFontInstalled = false ;
- }
- }
- }
- }
-}
-
-void wxDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
-{
- if (!Ok())
- return;
- MacVerifySetup() ;
-
- long xx1 = XLOG2DEV(x);
- long yy1 = YLOG2DEV(y);
-
- {
- wxIconRefData * iconref = (wxIconRefData*) ( icon.GetRefData()) ;
-
- if ( iconref && iconref->m_ok && iconref->m_hIcon )
- {
- Rect bitmaprect = { 0 , 0 , iconref->m_height , iconref->m_width } ;
- OffsetRect( &bitmaprect , xx1 , yy1 ) ;
- PlotCIconHandle( &bitmaprect , atNone , ttNone , iconref->m_hIcon ) ;
- }
- }
-};
-
-void wxDC::DrawPoint( wxPoint& point )
-{
- DrawPoint( point.x, point.y );
-};
-
-void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle )
-{
- int n = list->Number();
- wxPoint *points = new wxPoint[n];
-
- int i = 0;
- for( wxNode *node = list->First(); node; node = node->Next() )
- {
- wxPoint *point = (wxPoint *)node->Data();
- points[i].x = point->x;
- points[i++].y = point->y;
- };
- DrawPolygon( n, points, xoffset, yoffset, fillStyle );
- delete[] points;
-};
-
-void wxDC::DrawLines( wxList *list, long xoffset, long yoffset )
-{
- int n = list->Number();
- wxPoint *points = new wxPoint[n];
-
- int i = 0;
- for( wxNode *node = list->First(); node; node = node->Next() )
- {
- wxPoint *point = (wxPoint *)node->Data();
- points[i].x = point->x;
- points[i++].y = point->y;
- };
- DrawLines( n, points, xoffset, yoffset );
- delete []points;
-};
-
-void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 )
-{
- wxList list;
- list.Append( (wxObject*)new wxPoint(x1, y1) );
- list.Append( (wxObject*)new wxPoint(x2, y2) );
- list.Append( (wxObject*)new wxPoint(x3, y3) );
- DrawSpline(&list);
- wxNode *node = list.First();
- while (node)
- {
- wxPoint *p = (wxPoint*)node->Data();
- delete p;
- node = node->Next();
- };
-};
-
-void wxDC::DrawSpline( int n, wxPoint points[] )
-{
- wxList list;
- for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] );
- DrawSpline( &list );
-};
-
-void wxDC::SetClippingRegion( long x, long y, long width, long height )
-{
- MacVerifySetup() ;
- if( m_clipping )
- {
- m_clipX1 = wxMax( m_clipX1 , x ) ;
- m_clipY1 = wxMax( m_clipY1 ,y );
- m_clipX2 = wxMin( m_clipX2, (x + width));
- m_clipY2 = wxMin( m_clipY2,(y + height));
-
- }
- else
- {
- m_clipping = TRUE;
- m_clipX1 = x;
- m_clipY1 = y;
- m_clipX2 = x + width;
- m_clipY2 = y + height;
- }
-
- long x1 = XLOG2DEV(m_clipX1);
- long y1 = YLOG2DEV(m_clipY1);
- long x2 = XLOG2DEV(m_clipX2);
- long y2 = YLOG2DEV(m_clipY2);
-
- Rect clip = { y1 , x1 , y2 , x2 } ;
-
- ::ClipRect( &clip ) ;
-
-};
-
-void wxDC::DestroyClippingRegion(void)
-{
- MacVerifySetup() ;
- m_clipping = FALSE;
-// Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
- ::ClipRect(&m_macClipRect);
-};
-
-void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const
-{
- if (m_clipping)
- {
- if (x) *x = m_clipX1;
- if (y) *y = m_clipY1;
- if (width) *width = (m_clipX2 - m_clipX1);
- if (height) *height = (m_clipY2 - m_clipY1);
- }
- else
- *x = *y = *width = *height = 0;
-};
-
-void wxDC::GetSize( int* width, int* height ) const
-{
- *width = m_maxX-m_minX;
- *height = m_maxY-m_minY;
-};
-
-void wxDC::GetSizeMM( long* width, long* height ) const
-{
- int w = 0;
- int h = 0;
- GetSize( &w, &h );
- *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
- *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
-};
+ DisposeRgn( (RgnHandle) m_macBoundaryClipRgn ) ;
+ DisposeRgn( (RgnHandle) m_macCurrentClipRgn ) ;
+}
+
+void wxDC::MacSetupPort(wxMacPortStateHelper* help) const
+{
+#ifdef __WXDEBUG__
+ wxASSERT( m_macCurrentPortStateHelper == NULL ) ;
+ m_macCurrentPortStateHelper = help ;
+#endif
+ SetClip( (RgnHandle) m_macCurrentClipRgn);
+ m_macFontInstalled = false ;
+ m_macBrushInstalled = false ;
+ m_macPenInstalled = false ;
+}
+
+void wxDC::MacCleanupPort(wxMacPortStateHelper* help) const
+{
+#ifdef __WXDEBUG__
+ wxASSERT( m_macCurrentPortStateHelper == help ) ;
+ m_macCurrentPortStateHelper = NULL ;
+#endif
+ if( m_macATSUIStyle )
+ {
+ ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle);
+ m_macATSUIStyle = NULL ;
+ }
+ if ( m_macAliasWasEnabled )
+ {
+ SetAntiAliasedTextEnabled(m_macFormerAliasState, m_macFormerAliasSize);
+ m_macAliasWasEnabled = false ;
+ }
+ if ( m_macForegroundPixMap )
+ {
+ Pattern blackColor ;
+ ::PenPat(GetQDGlobalsBlack(&blackColor));
+ DisposePixPat( (PixPatHandle) m_macForegroundPixMap ) ;
+ m_macForegroundPixMap = NULL ;
+ }
+ if ( m_macBackgroundPixMap )
+ {
+ Pattern whiteColor ;
+ ::BackPat(GetQDGlobalsWhite(&whiteColor));
+ DisposePixPat( (PixPatHandle) m_macBackgroundPixMap ) ;
+ m_macBackgroundPixMap = NULL ;
+ }
+}
+
+void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+ wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
+ wxMacPortSetter helper(this) ;
+ wxCoord xx = XLOG2DEVMAC(x);
+ wxCoord yy = YLOG2DEVMAC(y);
+ wxCoord w = bmp.GetWidth();
+ wxCoord h = bmp.GetHeight();
+ wxCoord ww = XLOG2DEVREL(w);
+ wxCoord hh = YLOG2DEVREL(h);
+ // Set up drawing mode
+ short mode = (m_logicalFunction == wxCOPY ? srcCopy :
+ //m_logicalFunction == wxCLEAR ? WHITENESS :
+ //m_logicalFunction == wxSET ? BLACKNESS :
+ m_logicalFunction == wxINVERT ? hilite :
+ //m_logicalFunction == wxAND ? MERGECOPY :
+ m_logicalFunction == wxOR ? srcOr :
+ m_logicalFunction == wxSRC_INVERT ? notSrcCopy :
+ m_logicalFunction == wxXOR ? srcXor :
+ m_logicalFunction == wxOR_REVERSE ? notSrcOr :
+ //m_logicalFunction == wxAND_REVERSE ? SRCERASE :
+ //m_logicalFunction == wxSRC_OR ? srcOr :
+ //m_logicalFunction == wxSRC_AND ? SRCAND :
+ srcCopy );
+ if ( bmp.GetBitmapType() == kMacBitmapTypePict ) {
+ Rect bitmaprect = { 0 , 0 , hh, ww };
+ ::OffsetRect( &bitmaprect, xx, yy ) ;
+ ::DrawPicture( (PicHandle) bmp.GetPict(), &bitmaprect ) ;
+ }
+ else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld )
+ {
+ GWorldPtr bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP() );
+ PixMapHandle bmappixels ;
+ // Set foreground and background colours (for bitmaps depth = 1)
+ if(bmp.GetDepth() == 1)
+ {
+ RGBColor fore = MAC_WXCOLORREF(m_textForegroundColour.GetPixel());
+ RGBColor back = MAC_WXCOLORREF(m_textBackgroundColour.GetPixel());
+ RGBForeColor(&fore);
+ RGBBackColor(&back);
+ }
+ else
+ {
+ RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
+ RGBColor black = { 0,0,0} ;
+ RGBForeColor( &black ) ;
+ RGBBackColor( &white ) ;
+ }
+ bmappixels = GetGWorldPixMap( bmapworld ) ;
+ wxCHECK_RET(LockPixels(bmappixels),
+ wxT("DoDrawBitmap: Unable to lock pixels"));
+ Rect source = { 0, 0, h, w };
+ Rect dest = { yy, xx, yy + hh, xx + ww };
+ if ( useMask && bmp.GetMask() )
+ {
+ if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap()))))
+ {
+ CopyDeepMask
+ (
+ GetPortBitMapForCopyBits(bmapworld),
+ GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())),
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
+ &source, &source, &dest, mode, NULL
+ );
+ UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())));
+ }
+ }
+ else {
+ CopyBits( GetPortBitMapForCopyBits( bmapworld ),
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
+ &source, &dest, mode, NULL ) ;
+ }
+ UnlockPixels( bmappixels ) ;
+ }
+ else if ( bmp.GetBitmapType() == kMacBitmapTypeIcon )
+ {
+ Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ;
+ OffsetRect( &bitmaprect, xx, yy ) ;
+ PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(bmp.GetHICON()) ) ;
+ }
+ m_macPenInstalled = false ;
+ m_macBrushInstalled = false ;
+ m_macFontInstalled = false ;
+}
+
+void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
+{
+ wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
+ wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
+ DoDrawBitmap( icon , x , y , icon.GetMask() != NULL ) ;
+}
+
+void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
+{
+ wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
+ wxCoord xx, yy, ww, hh;
+ xx = XLOG2DEVMAC(x);
+ yy = YLOG2DEVMAC(y);
+ ww = XLOG2DEVREL(width);
+ hh = YLOG2DEVREL(height);
+ SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
+ SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
+ if( m_clipping )
+ {
+ m_clipX1 = wxMax( m_clipX1 , xx );
+ m_clipY1 = wxMax( m_clipY1 , yy );
+ m_clipX2 = wxMin( m_clipX2, (xx + ww));
+ m_clipY2 = wxMin( m_clipY2, (yy + hh));
+ }
+ else
+ {
+ m_clipping = TRUE;
+ m_clipX1 = xx;
+ m_clipY1 = yy;
+ m_clipX2 = xx + ww;
+ m_clipY2 = yy + hh;
+ }
+}
+
+void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
+ if (region.Empty())
+ {
+ DestroyClippingRegion();
+ return;
+ }
+ wxMacPortSetter helper(this) ;
+ wxCoord x, y, w, h;
+ region.GetBox( x, y, w, h );
+ wxCoord xx, yy, ww, hh;
+ xx = XLOG2DEVMAC(x);
+ yy = YLOG2DEVMAC(y);
+ ww = XLOG2DEVREL(w);
+ hh = YLOG2DEVREL(h);
+ // if we have a scaling that we cannot map onto native regions
+ // we must use the box
+ if ( ww != w || hh != h )
+ {
+ wxDC::DoSetClippingRegion( x, y, w, h );
+ }
+ else
+ {
+ CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
+ if ( xx != x || yy != y )
+ {
+ OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
+ }
+ SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
+ if( m_clipping )
+ {
+ m_clipX1 = wxMax( m_clipX1 , xx );
+ m_clipY1 = wxMax( m_clipY1 , yy );
+ m_clipX2 = wxMin( m_clipX2, (xx + ww));
+ m_clipY2 = wxMin( m_clipY2, (yy + hh));
+ }
+ else
+ {
+ m_clipping = TRUE;
+ m_clipX1 = xx;
+ m_clipY1 = yy;
+ m_clipX2 = xx + ww;
+ m_clipY2 = yy + hh;
+ }
+ }
+}
+
+void wxDC::DestroyClippingRegion()
+{
+ wxMacPortSetter helper(this) ;
+ CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
+ m_clipping = FALSE;
+}
+
+void wxDC::DoGetSizeMM( int* width, int* height ) const
+{
+ int w = 0;
+ int h = 0;
+ GetSize( &w, &h );
+ *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
+ *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
+}