+ wxASSERT( m_macCurrentPortStateHelper == help ) ;
+ m_macCurrentPortStateHelper = NULL ;
+ 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") ) ;
+ wxMacPortSetter helper(this) ;
+ if (region.Empty())
+ {
+ DestroyClippingRegion();
+ return;
+ }
+ 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::DoGetSize( int* width, int* height ) const
+{
+ *width = m_maxX-m_minX;
+ *height = m_maxY-m_minY;
+}
+
+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) );
+}