// anything with paths
CGContextRef cg = GetNativeContext() ;
cg = NULL ;
+
return new wxMacCGPath() ;
}
CGContextSaveGState( m_cgContext ) ;
wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
+
CGContextTranslateCTM( m_cgContext , 0 , bounds.bottom - bounds.top ) ;
CGContextScaleCTM( m_cgContext , 1 , -1 ) ;
{
// we allow either setting or clearing but not replacing
wxASSERT( m_cgContext == NULL || cg == NULL ) ;
+
if ( cg )
CGContextSaveGState( cg ) ;
m_cgContext = cg ;
wxMacCGPattern() {}
// 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 ; }
class ImagePattern : public wxMacCGPattern
{
public :
- ImagePattern( const wxBitmap* bmp , CGAffineTransform transform )
+ ImagePattern( const wxBitmap* bmp , CGAffineTransform transform )
{
wxASSERT( bmp && bmp->Ok() ) ;
+
Init( (CGImageRef) bmp->CGImageCreate() , transform ) ;
}
Init( image , transform ) ;
}
- virtual void Render( CGContextRef ctxRef )
+ virtual void Render( CGContextRef ctxRef )
{
if (m_image != NULL)
HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image );
#endif
{
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);
CGContextAddLineToPoint(ctxRef, pts[i+1].x, pts[i+1].y);
}
}
}
- virtual void Render( CGContextRef ctxRef )
+ virtual void Render( CGContextRef ctxRef )
{
switch ( m_hatch )
{
case wxBDIAGONAL_HATCH :
{
- CGPoint pts[] = {
+ CGPoint pts[] =
+ {
{ 8.0 , 0.0 } , { 0.0 , 8.0 }
};
StrokeLineSegments( ctxRef , pts , 2 ) ;
case wxCROSSDIAG_HATCH :
{
- CGPoint pts[] = {
+ CGPoint pts[] =
+ {
{ 0.0 , 0.0 } , { 8.0 , 8.0 } ,
{ 8.0 , 0.0 } , { 0.0 , 8.0 }
};
case wxFDIAGONAL_HATCH :
{
- CGPoint pts[] = {
+ CGPoint pts[] =
+ {
{ 0.0 , 0.0 } , { 8.0 , 8.0 }
};
StrokeLineSegments( ctxRef , pts , 2 ) ;
case wxCROSS_HATCH :
{
- CGPoint pts[] = {
+ CGPoint pts[] =
+ {
{ 0.0 , 4.0 } , { 8.0 , 4.0 } ,
{ 4.0 , 0.0 } , { 4.0 , 8.0 } ,
};
case wxHORIZONTAL_HATCH :
{
- CGPoint pts[] = {
+ CGPoint pts[] =
+ {
{ 0.0 , 4.0 } , { 8.0 , 4.0 } ,
};
StrokeLineSegments( ctxRef , pts , 2 ) ;
case wxVERTICAL_HATCH :
{
- CGPoint pts[] = {
+ CGPoint pts[] =
+ {
{ 4.0 , 0.0 } , { 4.0 , 8.0 } ,
};
StrokeLineSegments( ctxRef , pts , 2 ) ;
}
break ;
+
+ default:
+ break;
}
}
m_pen = pen ;
if ( m_cgContext == NULL )
return ;
+
bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
bool stroke = pen.GetStyle() != wxTRANSPARENT ;
// we can benchmark performance, should go into a setting later
CGContextSetShouldAntialias( m_cgContext , false ) ;
#endif
+
if ( fill | stroke )
{
- // setup brushes
+ // set up brushes
m_mode = kCGPathFill ; // just a default
- if ( fill )
- {
- m_mode = kCGPathFill ;
- }
-
if ( stroke )
{
RGBColor col = MAC_WXCOLORREF( pen.GetColour().GetPixel() ) ;
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();
if (penWidth <= 0.0)
penWidth = 0.1;
case wxCAP_ROUND :
cap = kCGLineCapRound ;
break ;
+
case wxCAP_PROJECTING :
cap = kCGLineCapSquare ;
break ;
+
case wxCAP_BUTT :
cap = kCGLineCapButt ;
break ;
+
default :
cap = kCGLineCapButt ;
break ;
case wxJOIN_BEVEL :
join = kCGLineJoinBevel ;
break ;
+
case wxJOIN_MITER :
join = kCGLineJoinMiter ;
break ;
+
case wxJOIN_ROUND :
join = kCGLineJoinRound ;
break ;
+
default :
join = kCGLineJoinMiter ;
break;
}
- CGContextSetLineJoin( m_cgContext , join ) ;
m_mode = kCGPathStroke ;
int count = 0 ;
const float dashed[] = { 19.0 , 9.0 };
const float dotted_dashed[] = { 9.0 , 6.0 , 3.0 , 3.0 };
-
switch ( pen.GetStyle() )
{
case wxSOLID :
}
CGContextSetLineCap( m_cgContext , cap ) ;
+ CGContextSetLineJoin( m_cgContext , join ) ;
delete[] userLengths ;
}
if ( fill && stroke )
- {
m_mode = kCGPathFillStroke ;
- }
}
}
CGContextSetFillPattern( m_cgContext, pattern , alphaArray ) ;
}
}
+
m_mode = kCGPathFill ;
}
- if ( stroke )
- m_mode = kCGPathStroke ;
-
if ( fill && stroke )
m_mode = kCGPathFillStroke ;
+ else if ( stroke )
+ m_mode = kCGPathStroke ;
}
}
m_brush = *wxWHITE_BRUSH;
m_macATSUIStyle = NULL ;
-
m_graphicContext = NULL ;
}
{
wxCHECK_RET( Ok(), wxT("invalid window dc") );
wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
+
wxCoord xx = XLOG2DEVMAC(x);
wxCoord yy = YLOG2DEVMAC(y);
wxCoord w = bmp.GetWidth();
CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
CGRect r = CGRectMake( 00 , 00 , ww , hh ) ;
CGContextSaveGState(cg);
- CGContextTranslateCTM(cg, xx , yy + hh );
+ CGContextTranslateCTM( cg, xx , yy + hh );
CGContextScaleCTM(cg, 1, -1);
PlotIconRefInContext( cg , &r , kAlignNone , kTransformNone ,
NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) ) ;
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);
// 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_clipX2 = xx + ww;
m_clipY2 = yy + hh;
}
+
// TODO as soon as we don't reset the context for each operation anymore
// we have to update the context as well
}
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 )
}
else
{
- /*
+#if 0
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 ) ;
- */
+#endif
+
if ( m_clipping )
{
m_clipX1 = wxMax( m_clipX1 , xx );
void wxDC::DoGetSizeMM( int* width, int* height ) const
{
- int w = 0;
- int h = 0;
+ int w = 0, 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) );
+ if (width)
+ *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 )
{
wxCHECK_RET(Ok(), wxT("Invalid DC"));
+
if ( col != m_textForegroundColour )
{
m_textForegroundColour = col;
void wxDC::SetTextBackground( const wxColour &col )
{
wxCHECK_RET(Ok(), wxT("Invalid DC"));
+
m_textBackgroundColour = col;
}
switch (mode)
{
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;
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;
case wxMM_METRIC:
break;
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;
case wxMM_TEXT:
{
// this is a bit artificial, but we need to force wxDC to think
// the pen has changed
- wxPen pen(GetPen());
+ wxPen pen( GetPen() );
m_pen = wxNullPen;
SetPen(pen);
{
wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") );
+
wxMacPortSaver helper((CGrafPtr)m_macPort) ;
RGBColor colour;
+
+ // NB: GetCPixel is a deprecated QD call, and a slow one at that
GetCPixel(
XLOG2DEVMAC(x) + m_macLocalOriginInPort.x - m_macLocalOrigin.x,
YLOG2DEVMAC(y) + m_macLocalOriginInPort.y - m_macLocalOrigin.y, &colour );
- // Convert from Mac colour to wx
- col->Set( colour.red >> 8,
- colour.green >> 8,
- colour.blue >> 8);
+
+ // convert from Mac colour to wx
+ col->Set( colour.red >> 8, colour.green >> 8, colour.blue >> 8 );
return true ;
}
wxCoord yy2 = YLOG2DEVMAC(y2);
wxCoord xxc = XLOG2DEVMAC(xc);
wxCoord yyc = YLOG2DEVMAC(yc);
+
double dx = xx1 - xxc;
double dy = yy1 - yyc;
double radius = sqrt((double)(dx*dx+dy*dy));
- wxCoord rad = (wxCoord)radius;
+ wxCoord rad = (wxCoord)radius;
double sa, ea;
if (xx1 == xx2 && yy1 == yy2)
{
wxCoord yy = YLOG2DEVMAC(y);
wxCoord ww = m_signX * XLOG2DEVREL(w);
wxCoord hh = m_signY * YLOG2DEVREL(h);
+
// handle -ve width and/or height
- if (ww < 0) { ww = -ww; xx = xx - ww; }
- if (hh < 0) { hh = -hh; yy = yy - hh; }
+ if (ww < 0)
+ {
+ ww = -ww;
+ xx = xx - ww;
+ }
+ if (hh < 0)
+ {
+ hh = -hh;
+ yy = yy - hh;
+ }
bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
{
wxCHECK_RET(Ok(), wxT("Invalid DC"));
+
DoDrawLine( x , y , x + 1 , y + 1 ) ;
}
wxCoord xoffset, wxCoord yoffset)
{
wxCHECK_RET(Ok(), wxT("Invalid DC"));
-
+
if ( m_logicalFunction != wxCOPY )
return ;
}
#endif
-void wxDC::DoDrawPolygon(int n, wxPoint points[],
+void wxDC::DoDrawPolygon( int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
int fillStyle )
{
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 ;
-
if ( m_logicalFunction != wxCOPY )
return ;
+ wxCoord x1, x2 , y1 , y2 ;
x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset);
y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset);
path->CloseSubpath() ;
m_graphicContext->DrawPath( path , fillStyle ) ;
+
delete path ;
}
wxCoord yy = YLOG2DEVMAC(y);
wxCoord ww = m_signX * XLOG2DEVREL(width);
wxCoord hh = m_signY * YLOG2DEVREL(height);
+
// CMB: draw nothing if transformed w or h is 0
if (ww == 0 || hh == 0)
return;
wxCoord yy = YLOG2DEVMAC(y);
wxCoord ww = m_signX * XLOG2DEVREL(width);
wxCoord hh = m_signY * YLOG2DEVREL(height);
+
// CMB: draw nothing if transformed w or h is 0
if (ww == 0 || hh == 0)
return;
{
wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
+
if ( logical_func == wxNO_OP )
return true ;
}
else
{
- /*
+#if 0
CGContextRef cg = (wxMacCGContext*)(source->GetGraphicContext())->GetNativeContext() ;
void *data = CGBitmapContextGetData( cg ) ;
- */
+#endif
+
return false ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
}
double angle)
{
wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
+ wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ;
if ( str.Length() == 0 )
return ;
if ( m_logicalFunction != wxCOPY )
return ;
- wxCHECK_RET( m_macATSUIStyle != NULL , wxT("No valid font set") ) ;
-
OSStatus status = noErr ;
ATSUTextLayout atsuLayout ;
UniCharCount chars = str.Length() ;
UniChar* ubuf = NULL ;
#if SIZEOF_WCHAR_T == 4
- wxMBConvUTF16 converter ;
+ wxMBConvUTF16 converter ;
#if wxUSE_UNICODE
- size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
- ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
- converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
+ size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
+ ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
+ converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
#else
const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
- size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
- ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
- converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
+ size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
+ ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
+ converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
#endif
chars = unicharlen / 2 ;
#else
status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag),
atsuTags, atsuSizes, atsuValues ) ;
}
+
{
CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
ATSUAttributeTag atsuTags[] =
void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
{
wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
+
DoDrawRotatedText( strtext , x , y , 0.0 ) ;
}
bool wxDC::CanGetTextExtent() const
{
wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
+
return true ;
}
wxFont *theFont ) const
{
wxCHECK_RET(Ok(), wxT("Invalid DC"));
+
wxFont formerFont = m_font ;
if ( theFont )
{
UniCharCount chars = str.Length() ;
UniChar* ubuf = NULL ;
#if SIZEOF_WCHAR_T == 4
- wxMBConvUTF16 converter ;
+ wxMBConvUTF16 converter ;
#if wxUSE_UNICODE
- size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
- ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
- converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
+ size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
+ ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
+ converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ) ;
#else
const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
- size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
- ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
- converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
+ size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
+ ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
+ converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ) ;
#endif
chars = unicharlen / 2 ;
#else
{
wxCoord width ;
DoGetTextExtent(wxT("g") , &width , NULL , NULL , NULL , NULL ) ;
+
return width ;
}
{
wxCoord height ;
DoGetTextExtent(wxT("g") , NULL , &height , NULL , NULL , NULL ) ;
+
return height ;
}
{
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 ) ;
CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
else
#endif
{
- RGBColor color;
+ RGBColor color;
GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme(), 32, true, &color );
CGContextSetRGBFillColor( cg, (float) color.red / 65536,
(float) color.green / 65536, (float) color.blue / 65536, 1 );
case kwxMacBrushThemeBackground :
{
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 ( UMAGetSystemVersion() >= 0x1030 )
{
}
break ;
- default:
+ default :
+ wxFAIL_MSG( wxT("unknown brush kind") ) ;
break ;
}
}
sizeof( Fixed ) ,
sizeof( RGBColor ) ,
} ;
- // Boolean kTrue = true ;
- // Boolean kFalse = false ;
-
- // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
+ // Boolean kTrue = true ;
+ // Boolean kFalse = false ;
+ // ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
{
&atsuSize ,