format cleanup; some new comments; minor optimizations

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Surovell
2005-12-09 00:10:27 +00:00
parent 789e2d57b8
commit 75f0a06e5f

View File

@@ -274,6 +274,7 @@ wxGraphicPath* wxMacCGContext::CreatePath()
// anything with paths // anything with paths
CGContextRef cg = GetNativeContext() ; CGContextRef cg = GetNativeContext() ;
cg = NULL ; cg = NULL ;
return new wxMacCGPath() ; return new wxMacCGPath() ;
} }
@@ -289,6 +290,7 @@ CGContextRef wxMacCGContext::GetNativeContext()
CGContextSaveGState( m_cgContext ) ; CGContextSaveGState( m_cgContext ) ;
wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ; wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ; CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ;
CGContextScaleCTM( m_cgContext , 1 , -1 ) ; CGContextScaleCTM( m_cgContext , 1 , -1 ) ;
@@ -304,6 +306,7 @@ void wxMacCGContext::SetNativeContext( CGContextRef cg )
{ {
// we allow either setting or clearing but not replacing // we allow either setting or clearing but not replacing
wxASSERT( m_cgContext == NULL || cg == NULL ) ; wxASSERT( m_cgContext == NULL || cg == NULL ) ;
if ( cg ) if ( cg )
CGContextSaveGState( cg ) ; CGContextSaveGState( cg ) ;
m_cgContext = cg ; m_cgContext = cg ;
@@ -319,7 +322,7 @@ public :
wxMacCGPattern() {} wxMacCGPattern() {}
// is guaranteed to be called only with a non-Null CGContextRef // is guaranteed to be called only with a non-Null CGContextRef
virtual void Render( CGContextRef ctxRef ) = 0 ; virtual void Render( CGContextRef ctxRef ) = 0 ;
operator CGPatternRef() const { return m_patternRef ; } operator CGPatternRef() const { return m_patternRef ; }
@@ -353,9 +356,10 @@ const CGPatternCallbacks wxMacCGPattern::ms_Callbacks = { 0, &wxMacCGPattern::_R
class ImagePattern : public wxMacCGPattern class ImagePattern : public wxMacCGPattern
{ {
public : public :
ImagePattern( const wxBitmap* bmp , CGAffineTransform transform ) ImagePattern( const wxBitmap* bmp , CGAffineTransform transform )
{ {
wxASSERT( bmp && bmp->Ok() ) ; wxASSERT( bmp && bmp->Ok() ) ;
Init( (CGImageRef) bmp->CGImageCreate() , transform ) ; Init( (CGImageRef) bmp->CGImageCreate() , transform ) ;
} }
@@ -368,7 +372,7 @@ public :
Init( image , transform ) ; Init( image , transform ) ;
} }
virtual void Render( CGContextRef ctxRef ) virtual void Render( CGContextRef ctxRef )
{ {
if (m_image != NULL) if (m_image != NULL)
HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image ); HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image );
@@ -420,7 +424,8 @@ public :
#endif #endif
{ {
CGContextBeginPath (ctxRef); CGContextBeginPath (ctxRef);
for (size_t i = 0; i < count; i += 2) { for (size_t i = 0; i < count; i += 2)
{
CGContextMoveToPoint(ctxRef, pts[i].x, pts[i].y); CGContextMoveToPoint(ctxRef, pts[i].x, pts[i].y);
CGContextAddLineToPoint(ctxRef, pts[i+1].x, pts[i+1].y); CGContextAddLineToPoint(ctxRef, pts[i+1].x, pts[i+1].y);
} }
@@ -428,13 +433,14 @@ public :
} }
} }
virtual void Render( CGContextRef ctxRef ) virtual void Render( CGContextRef ctxRef )
{ {
switch ( m_hatch ) switch ( m_hatch )
{ {
case wxBDIAGONAL_HATCH : case wxBDIAGONAL_HATCH :
{ {
CGPoint pts[] = { CGPoint pts[] =
{
{ 8.0 , 0.0 } , { 0.0 , 8.0 } { 8.0 , 0.0 } , { 0.0 , 8.0 }
}; };
StrokeLineSegments( ctxRef , pts , 2 ) ; StrokeLineSegments( ctxRef , pts , 2 ) ;
@@ -443,7 +449,8 @@ public :
case wxCROSSDIAG_HATCH : case wxCROSSDIAG_HATCH :
{ {
CGPoint pts[] = { CGPoint pts[] =
{
{ 0.0 , 0.0 } , { 8.0 , 8.0 } , { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
{ 8.0 , 0.0 } , { 0.0 , 8.0 } { 8.0 , 0.0 } , { 0.0 , 8.0 }
}; };
@@ -453,7 +460,8 @@ public :
case wxFDIAGONAL_HATCH : case wxFDIAGONAL_HATCH :
{ {
CGPoint pts[] = { CGPoint pts[] =
{
{ 0.0 , 0.0 } , { 8.0 , 8.0 } { 0.0 , 0.0 } , { 8.0 , 8.0 }
}; };
StrokeLineSegments( ctxRef , pts , 2 ) ; StrokeLineSegments( ctxRef , pts , 2 ) ;
@@ -462,7 +470,8 @@ public :
case wxCROSS_HATCH : case wxCROSS_HATCH :
{ {
CGPoint pts[] = { CGPoint pts[] =
{
{ 0.0 , 4.0 } , { 8.0 , 4.0 } , { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
{ 4.0 , 0.0 } , { 4.0 , 8.0 } , { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
}; };
@@ -472,7 +481,8 @@ public :
case wxHORIZONTAL_HATCH : case wxHORIZONTAL_HATCH :
{ {
CGPoint pts[] = { CGPoint pts[] =
{
{ 0.0 , 4.0 } , { 8.0 , 4.0 } , { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
}; };
StrokeLineSegments( ctxRef , pts , 2 ) ; StrokeLineSegments( ctxRef , pts , 2 ) ;
@@ -481,12 +491,16 @@ public :
case wxVERTICAL_HATCH : case wxVERTICAL_HATCH :
{ {
CGPoint pts[] = { CGPoint pts[] =
{
{ 4.0 , 0.0 } , { 4.0 , 8.0 } , { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
}; };
StrokeLineSegments( ctxRef , pts , 2 ) ; StrokeLineSegments( ctxRef , pts , 2 ) ;
} }
break ; break ;
default:
break;
} }
} }
@@ -502,6 +516,7 @@ void wxMacCGContext::SetPen( const wxPen &pen )
m_pen = pen ; m_pen = pen ;
if ( m_cgContext == NULL ) if ( m_cgContext == NULL )
return ; return ;
bool fill = m_brush.GetStyle() != wxTRANSPARENT ; bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
bool stroke = pen.GetStyle() != wxTRANSPARENT ; bool stroke = pen.GetStyle() != wxTRANSPARENT ;
@@ -509,22 +524,18 @@ void wxMacCGContext::SetPen( const wxPen &pen )
// we can benchmark performance, should go into a setting later // we can benchmark performance, should go into a setting later
CGContextSetShouldAntialias( m_cgContext , false ) ; CGContextSetShouldAntialias( m_cgContext , false ) ;
#endif #endif
if ( fill | stroke ) if ( fill | stroke )
{ {
// setup brushes // set up brushes
m_mode = kCGPathFill ; // just a default m_mode = kCGPathFill ; // just a default
if ( fill )
{
m_mode = kCGPathFill ;
}
if ( stroke ) if ( stroke )
{ {
RGBColor col = MAC_WXCOLORREF( pen.GetColour().GetPixel() ) ; RGBColor col = MAC_WXCOLORREF( pen.GetColour().GetPixel() ) ;
CGContextSetRGBStrokeColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ; CGContextSetRGBStrokeColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
/* TODO * m_dc->m_scaleX */ // TODO * m_dc->m_scaleX
float penWidth = pen.GetWidth(); float penWidth = pen.GetWidth();
if (penWidth <= 0.0) if (penWidth <= 0.0)
penWidth = 0.1; penWidth = 0.1;
@@ -536,12 +547,15 @@ void wxMacCGContext::SetPen( const wxPen &pen )
case wxCAP_ROUND : case wxCAP_ROUND :
cap = kCGLineCapRound ; cap = kCGLineCapRound ;
break ; break ;
case wxCAP_PROJECTING : case wxCAP_PROJECTING :
cap = kCGLineCapSquare ; cap = kCGLineCapSquare ;
break ; break ;
case wxCAP_BUTT : case wxCAP_BUTT :
cap = kCGLineCapButt ; cap = kCGLineCapButt ;
break ; break ;
default : default :
cap = kCGLineCapButt ; cap = kCGLineCapButt ;
break ; break ;
@@ -553,17 +567,19 @@ void wxMacCGContext::SetPen( const wxPen &pen )
case wxJOIN_BEVEL : case wxJOIN_BEVEL :
join = kCGLineJoinBevel ; join = kCGLineJoinBevel ;
break ; break ;
case wxJOIN_MITER : case wxJOIN_MITER :
join = kCGLineJoinMiter ; join = kCGLineJoinMiter ;
break ; break ;
case wxJOIN_ROUND : case wxJOIN_ROUND :
join = kCGLineJoinRound ; join = kCGLineJoinRound ;
break ; break ;
default : default :
join = kCGLineJoinMiter ; join = kCGLineJoinMiter ;
break; break;
} }
CGContextSetLineJoin( m_cgContext , join ) ;
m_mode = kCGPathStroke ; m_mode = kCGPathStroke ;
int count = 0 ; int count = 0 ;
@@ -578,7 +594,6 @@ void wxMacCGContext::SetPen( const wxPen &pen )
const float dashed[] = { 19.0 , 9.0 }; const float dashed[] = { 19.0 , 9.0 };
const float dotted_dashed[] = { 9.0 , 6.0 , 3.0 , 3.0 }; const float dotted_dashed[] = { 9.0 , 6.0 , 3.0 , 3.0 };
switch ( pen.GetStyle() ) switch ( pen.GetStyle() )
{ {
case wxSOLID : case wxSOLID :
@@ -663,14 +678,13 @@ void wxMacCGContext::SetPen( const wxPen &pen )
} }
CGContextSetLineCap( m_cgContext , cap ) ; CGContextSetLineCap( m_cgContext , cap ) ;
CGContextSetLineJoin( m_cgContext , join ) ;
delete[] userLengths ; delete[] userLengths ;
} }
if ( fill && stroke ) if ( fill && stroke )
{
m_mode = kCGPathFillStroke ; m_mode = kCGPathFillStroke ;
}
} }
} }
@@ -724,14 +738,14 @@ void wxMacCGContext::SetBrush( const wxBrush &brush )
CGContextSetFillPattern( m_cgContext, pattern , alphaArray ) ; CGContextSetFillPattern( m_cgContext, pattern , alphaArray ) ;
} }
} }
m_mode = kCGPathFill ; m_mode = kCGPathFill ;
} }
if ( stroke )
m_mode = kCGPathStroke ;
if ( fill && stroke ) if ( fill && stroke )
m_mode = kCGPathFillStroke ; m_mode = kCGPathFillStroke ;
else if ( stroke )
m_mode = kCGPathStroke ;
} }
} }
@@ -797,7 +811,6 @@ wxDC::wxDC()
m_brush = *wxWHITE_BRUSH; m_brush = *wxWHITE_BRUSH;
m_macATSUIStyle = NULL ; m_macATSUIStyle = NULL ;
m_graphicContext = NULL ; m_graphicContext = NULL ;
} }
@@ -816,6 +829,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
{ {
wxCHECK_RET( Ok(), wxT("invalid window dc") ); wxCHECK_RET( Ok(), wxT("invalid window dc") );
wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
wxCoord xx = XLOG2DEVMAC(x); wxCoord xx = XLOG2DEVMAC(x);
wxCoord yy = YLOG2DEVMAC(y); wxCoord yy = YLOG2DEVMAC(y);
wxCoord w = bmp.GetWidth(); wxCoord w = bmp.GetWidth();
@@ -845,7 +859,7 @@ void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
CGRect r = CGRectMake( 00 , 00 , ww , hh ) ; CGRect r = CGRectMake( 00 , 00 , ww , hh ) ;
CGContextSaveGState(cg); CGContextSaveGState(cg);
CGContextTranslateCTM(cg, xx , yy + hh ); CGContextTranslateCTM( cg, xx , yy + hh );
CGContextScaleCTM(cg, 1, -1); CGContextScaleCTM(cg, 1, -1);
PlotIconRefInContext( cg , &r , kAlignNone , kTransformNone , PlotIconRefInContext( cg , &r , kAlignNone , kTransformNone ,
NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) ) ; NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) ) ;
@@ -855,6 +869,7 @@ void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
{ {
wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC")); wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC"));
wxCoord xx, yy, ww, hh; wxCoord xx, yy, ww, hh;
xx = XLOG2DEVMAC(x); xx = XLOG2DEVMAC(x);
yy = YLOG2DEVMAC(y); yy = YLOG2DEVMAC(y);
@@ -867,6 +882,7 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei
// SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ; // SetRectRgn( (RgnHandle) m_macCurrentClipRgn , xx , yy , xx + ww , yy + hh ) ;
// SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; // SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
if ( m_clipping ) if ( m_clipping )
{ {
m_clipX1 = wxMax( m_clipX1 , xx ); m_clipX1 = wxMax( m_clipX1 , xx );
@@ -882,6 +898,7 @@ void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord hei
m_clipX2 = xx + ww; m_clipX2 = xx + ww;
m_clipY2 = yy + hh; m_clipY2 = yy + hh;
} }
// TODO as soon as we don't reset the context for each operation anymore // TODO as soon as we don't reset the context for each operation anymore
// we have to update the context as well // we have to update the context as well
} }
@@ -902,6 +919,7 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region )
yy = YLOG2DEVMAC(y); yy = YLOG2DEVMAC(y);
ww = XLOG2DEVREL(w); ww = XLOG2DEVREL(w);
hh = YLOG2DEVREL(h); hh = YLOG2DEVREL(h);
// if we have a scaling that we cannot map onto native regions // if we have a scaling that we cannot map onto native regions
// we must use the box // we must use the box
if ( ww != w || hh != h ) if ( ww != w || hh != h )
@@ -910,14 +928,13 @@ void wxDC::DoSetClippingRegionAsRegion( const wxRegion &region )
} }
else else
{ {
/* #if 0
CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ; CopyRgn( (RgnHandle) region.GetWXHRGN() , (RgnHandle) m_macCurrentClipRgn ) ;
if ( xx != x || yy != y ) if ( xx != x || yy != y )
{
OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ; OffsetRgn( (RgnHandle) m_macCurrentClipRgn , xx - x , yy - y ) ;
}
SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; SectRgn( (RgnHandle) m_macCurrentClipRgn , (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
*/ #endif
if ( m_clipping ) if ( m_clipping )
{ {
m_clipX1 = wxMax( m_clipX1 , xx ); m_clipX1 = wxMax( m_clipX1 , xx );
@@ -949,16 +966,19 @@ void wxDC::DestroyClippingRegion()
void wxDC::DoGetSizeMM( int* width, int* height ) const void wxDC::DoGetSizeMM( int* width, int* height ) const
{ {
int w = 0; int w = 0, h = 0;
int h = 0;
GetSize( &w, &h ); GetSize( &w, &h );
*width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); if (width)
*height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); *width = long( double(w) / (m_scaleX * m_mm_to_pix_x) );
if (height)
*height = long( double(h) / (m_scaleY * m_mm_to_pix_y) );
} }
void wxDC::SetTextForeground( const wxColour &col ) void wxDC::SetTextForeground( const wxColour &col )
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
if ( col != m_textForegroundColour ) if ( col != m_textForegroundColour )
{ {
m_textForegroundColour = col; m_textForegroundColour = col;
@@ -969,6 +989,7 @@ void wxDC::SetTextForeground( const wxColour &col )
void wxDC::SetTextBackground( const wxColour &col ) void wxDC::SetTextBackground( const wxColour &col )
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
m_textBackgroundColour = col; m_textBackgroundColour = col;
} }
@@ -977,11 +998,11 @@ void wxDC::SetMapMode( int mode )
switch (mode) switch (mode)
{ {
case wxMM_TWIPS: case wxMM_TWIPS:
SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y );
break; break;
case wxMM_POINTS: case wxMM_POINTS:
SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y );
break; break;
case wxMM_METRIC: case wxMM_METRIC:
@@ -989,7 +1010,7 @@ void wxDC::SetMapMode( int mode )
break; break;
case wxMM_LOMETRIC: case wxMM_LOMETRIC:
SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 );
break; break;
case wxMM_TEXT: case wxMM_TEXT:
@@ -1067,7 +1088,7 @@ void wxDC::ComputeScaleAndOrigin()
{ {
// this is a bit artificial, but we need to force wxDC to think // this is a bit artificial, but we need to force wxDC to think
// the pen has changed // the pen has changed
wxPen pen(GetPen()); wxPen pen( GetPen() );
m_pen = wxNullPen; m_pen = wxNullPen;
SetPen(pen); SetPen(pen);
@@ -1172,15 +1193,17 @@ bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const
{ {
wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
wxMacPortSaver helper((CGrafPtr)m_macPort) ; wxMacPortSaver helper((CGrafPtr)m_macPort) ;
RGBColor colour; RGBColor colour;
// NB: GetCPixel is a deprecated QD call, and a slow one at that
GetCPixel( GetCPixel(
XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x, XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x,
YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour ); YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour );
// Convert from Mac colour to wx
col->Set( colour.red >> 8, // convert from Mac colour to wx
colour.green >> 8, col->Set( colour.red >> 8, colour.green >> 8, colour.blue >> 8 );
colour.blue >> 8);
return true ; return true ;
} }
@@ -1250,10 +1273,11 @@ void wxDC::DoDrawArc( wxCoord x1, wxCoord y1,
wxCoord yy2 = YLOG2DEVMAC(y2); wxCoord yy2 = YLOG2DEVMAC(y2);
wxCoord xxc = XLOG2DEVMAC(xc); wxCoord xxc = XLOG2DEVMAC(xc);
wxCoord yyc = YLOG2DEVMAC(yc); wxCoord yyc = YLOG2DEVMAC(yc);
double dx = xx1 - xxc; double dx = xx1 - xxc;
double dy = yy1 - yyc; double dy = yy1 - yyc;
double radius = sqrt((double)(dx*dx+dy*dy)); double radius = sqrt((double)(dx*dx+dy*dy));
wxCoord rad = (wxCoord)radius; wxCoord rad = (wxCoord)radius;
double sa, ea; double sa, ea;
if (xx1 == xx2 && yy1 == yy2) if (xx1 == xx2 && yy1 == yy2)
{ {
@@ -1301,9 +1325,18 @@ void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
wxCoord yy = YLOG2DEVMAC(y); wxCoord yy = YLOG2DEVMAC(y);
wxCoord ww = m_signX * XLOG2DEVREL(w); wxCoord ww = m_signX * XLOG2DEVREL(w);
wxCoord hh = m_signY * YLOG2DEVREL(h); wxCoord hh = m_signY * YLOG2DEVREL(h);
// handle -ve width and/or height // handle -ve width and/or height
if (ww < 0) { ww = -ww; xx = xx - ww; } if (ww < 0)
if (hh < 0) { hh = -hh; yy = yy - hh; } {
ww = -ww;
xx = xx - ww;
}
if (hh < 0)
{
hh = -hh;
yy = yy - hh;
}
bool fill = m_brush.GetStyle() != wxTRANSPARENT ; bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
@@ -1325,6 +1358,7 @@ void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
DoDrawLine( x , y , x + 1 , y + 1 ) ; DoDrawLine( x , y , x + 1 , y + 1 ) ;
} }
@@ -1332,7 +1366,7 @@ void wxDC::DoDrawLines(int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset) wxCoord xoffset, wxCoord yoffset)
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
if ( m_logicalFunction != wxCOPY ) if ( m_logicalFunction != wxCOPY )
return ; return ;
@@ -1412,18 +1446,18 @@ void wxDC::DoDrawSpline(wxList *points)
} }
#endif #endif
void wxDC::DoDrawPolygon(int n, wxPoint points[], void wxDC::DoDrawPolygon( int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset, wxCoord xoffset, wxCoord yoffset,
int fillStyle ) int fillStyle )
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
wxCoord x1, x2 , y1 , y2 ;
if ( n== 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) ) if ( n <= 0 || (m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT ) )
return ; return ;
if ( m_logicalFunction != wxCOPY ) if ( m_logicalFunction != wxCOPY )
return ; return ;
wxCoord x1, x2 , y1 , y2 ;
x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset); x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset);
y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset); y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset);
@@ -1442,6 +1476,7 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[],
path->CloseSubpath() ; path->CloseSubpath() ;
m_graphicContext->DrawPath( path , fillStyle ) ; m_graphicContext->DrawPath( path , fillStyle ) ;
delete path ; delete path ;
} }
@@ -1456,6 +1491,7 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
wxCoord yy = YLOG2DEVMAC(y); wxCoord yy = YLOG2DEVMAC(y);
wxCoord ww = m_signX * XLOG2DEVREL(width); wxCoord ww = m_signX * XLOG2DEVREL(width);
wxCoord hh = m_signY * YLOG2DEVREL(height); wxCoord hh = m_signY * YLOG2DEVREL(height);
// CMB: draw nothing if transformed w or h is 0 // CMB: draw nothing if transformed w or h is 0
if (ww == 0 || hh == 0) if (ww == 0 || hh == 0)
return; return;
@@ -1493,6 +1529,7 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
wxCoord yy = YLOG2DEVMAC(y); wxCoord yy = YLOG2DEVMAC(y);
wxCoord ww = m_signX * XLOG2DEVREL(width); wxCoord ww = m_signX * XLOG2DEVREL(width);
wxCoord hh = m_signY * YLOG2DEVREL(height); wxCoord hh = m_signY * YLOG2DEVREL(height);
// CMB: draw nothing if transformed w or h is 0 // CMB: draw nothing if transformed w or h is 0
if (ww == 0 || hh == 0) if (ww == 0 || hh == 0)
return; return;
@@ -1563,6 +1600,7 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
{ {
wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc")); wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC")); wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
if ( logical_func == wxNO_OP ) if ( logical_func == wxNO_OP )
return true ; return true ;
@@ -1626,10 +1664,11 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
} }
else else
{ {
/* #if 0
CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ; CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ;
void *data = CGBitmapContextGetData( cg ) ; void *data = CGBitmapContextGetData( cg ) ;
*/ #endif
return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ; return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
} }
@@ -1640,29 +1679,28 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
double angle) double angle)
{ {
wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ;
if ( str.Length() == 0 ) if ( str.Length() == 0 )
return ; return ;
if ( m_logicalFunction != wxCOPY ) if ( m_logicalFunction != wxCOPY )
return ; return ;
wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ;
OSStatus status = noErr ; OSStatus status = noErr ;
ATSUTextLayout atsuLayout ; ATSUTextLayout atsuLayout ;
UniCharCount chars = str.Length() ; UniCharCount chars = str.Length() ;
UniChar* ubuf = NULL ; UniChar* ubuf = NULL ;
#if SIZEOF_WCHAR_T == 4 #if SIZEOF_WCHAR_T == 4
wxMBConvUTF16 converter ; wxMBConvUTF16 converter ;
#if wxUSE_UNICODE #if wxUSE_UNICODE
size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
ubuf = (UniChar*) malloc( unicharlen + 2 ) ; ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ; converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
#else #else
const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
ubuf = (UniChar*) malloc( unicharlen + 2 ) ; ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ; converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
#endif #endif
chars = unicharlen / 2 ; chars = unicharlen / 2 ;
#else #else
@@ -1705,6 +1743,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag), status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),
atsuTags, atsuSizes, atsuValues ) ; atsuTags, atsuSizes, atsuValues ) ;
} }
{ {
CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
ATSUAttributeTag atsuTags[] = ATSUAttributeTag atsuTags[] =
@@ -1782,12 +1821,14 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
{ {
wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC")); wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
DoDrawRotatedText( strtext , x , y , 0.0 ) ; DoDrawRotatedText( strtext , x , y , 0.0 ) ;
} }
bool wxDC::CanGetTextExtent() const bool wxDC::CanGetTextExtent() const
{ {
wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
return true ; return true ;
} }
@@ -1796,6 +1837,7 @@ void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *heigh
wxFont *theFont ) const wxFont *theFont ) const
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
wxFont formerFont = m_font ; wxFont formerFont = m_font ;
if ( theFont ) if ( theFont )
{ {
@@ -1814,16 +1856,16 @@ void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *heigh
UniCharCount chars = str.Length() ; UniCharCount chars = str.Length() ;
UniChar* ubuf = NULL ; UniChar* ubuf = NULL ;
#if SIZEOF_WCHAR_T == 4 #if SIZEOF_WCHAR_T == 4
wxMBConvUTF16 converter ; wxMBConvUTF16 converter ;
#if wxUSE_UNICODE #if wxUSE_UNICODE
size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
ubuf = (UniChar*) malloc( unicharlen + 2 ) ; ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ; converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
#else #else
const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
ubuf = (UniChar*) malloc( unicharlen + 2 ) ; ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ; converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
#endif #endif
chars = unicharlen / 2 ; chars = unicharlen / 2 ;
#else #else
@@ -1934,6 +1976,7 @@ wxCoord wxDC::GetCharWidth(void) const
{ {
wxCoord width ; wxCoord width ;
DoGetTextExtent(wxT("g") , &width , NULL , NULL , NULL , NULL ) ; DoGetTextExtent(wxT("g") , &width , NULL , NULL , NULL , NULL ) ;
return width ; return width ;
} }
@@ -1941,6 +1984,7 @@ wxCoord wxDC::GetCharHeight(void) const
{ {
wxCoord height ; wxCoord height ;
DoGetTextExtent(wxT("g") , NULL , &height , NULL , NULL , NULL ) ; DoGetTextExtent(wxT("g") , NULL , &height , NULL , NULL , NULL ) ;
return height ; return height ;
} }
@@ -1948,7 +1992,7 @@ void wxDC::Clear(void)
{ {
wxCHECK_RET(Ok(), wxT("Invalid DC")); wxCHECK_RET(Ok(), wxT("Invalid DC"));
if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT) if (m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
{ {
HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ; HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
@@ -1966,7 +2010,7 @@ void wxDC::Clear(void)
else else
#endif #endif
{ {
RGBColor color; RGBColor color;
GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme(), 32, true, &color ); GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme(), 32, true, &color );
CGContextSetRGBFillColor( cg, (float) color.red / 65536, CGContextSetRGBFillColor( cg, (float) color.red / 65536,
(float) color.green / 65536, (float) color.blue / 65536, 1 ); (float) color.green / 65536, (float) color.blue / 65536, 1 );
@@ -1982,6 +2026,7 @@ void wxDC::Clear(void)
case kwxMacBrushThemeBackground : case kwxMacBrushThemeBackground :
{ {
wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ; wxFAIL_MSG( wxT("There shouldn't be theme backgrounds under Quartz") ) ;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
if ( UMAGetSystemVersion() >= 0x1030 ) if ( UMAGetSystemVersion() >= 0x1030 )
{ {
@@ -2011,7 +2056,8 @@ void wxDC::Clear(void)
} }
break ; break ;
default: default :
wxFAIL_MSG( wxT("unknown brush kind") ) ;
break ; break ;
} }
} }
@@ -2045,10 +2091,9 @@ void wxDC::MacInstallFont() const
sizeof( Fixed ) , sizeof( Fixed ) ,
sizeof( RGBColor ) , sizeof( RGBColor ) ,
} ; } ;
// Boolean kTrue = true ; // Boolean kTrue = true ;
// Boolean kFalse = false ; // Boolean kFalse = false ;
// ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
// ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] = ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
{ {
&atsuSize , &atsuSize ,