#ifndef WX_PRECOMP
#include "wx/log.h"
- #include "wx/app.h"
#include "wx/dcmemory.h"
- #include "wx/dcprint.h"
#include "wx/region.h"
- #include "wx/image.h"
#endif
#include "wx/mac/uma.h"
-
#ifdef __MSL__
#if __MSL__ >= 0x6000
#include "math.h"
#include "wx/mac/private.h"
-IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
#ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
#define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
#endif
#endif
-const double RAD2DEG = 180.0 / M_PI;
-const short kEmulatedMode = -1 ;
-const short kUnsupportedMode = -2 ;
-
-extern TECObjectRef s_TECNativeCToUnicode ;
+static const double RAD2DEG = 180.0 / M_PI;
+#ifndef __LP64__
// TODO: update
// The textctrl implementation still needs that (needs what?) for the non-HIView implementation
// minimal implementation only used for appearance drawing < 10.3
+#ifndef wxMAC_USE_CORE_GRAPHICS
wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
m_ph( (GrafPtr) dc->m_macPort )
{
// m_dc->MacCleanupPort(&m_ph) ;
}
+#endif
+
+#endif
+
//-----------------------------------------------------------------------------
// Local functions
//-----------------------------------------------------------------------------
-static inline double dmin(double a, double b) { return a < b ? a : b; }
-static inline double dmax(double a, double b) { return a > b ? a : b; }
static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
//-----------------------------------------------------------------------------
// wxGraphicPath implementation
//-----------------------------------------------------------------------------
+#if !wxUSE_GRAPHICS_CONTEXT
+
+IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
+
wxMacCGPath::wxMacCGPath()
{
m_path = CGPathCreateMutable() ;
CGContextRestoreGState( m_cgContext ) ;
CGContextRestoreGState( m_cgContext ) ;
}
-
+#ifndef __LP64__
if ( m_qdPort )
QDEndCGContext( m_qdPort, &m_cgContext ) ;
+#endif
}
if ( m_cgContext == NULL )
{
Rect bounds ;
+ OSStatus status = noErr;
+#ifndef __LP64__
GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ;
- OSStatus status = QDBeginCGContext((CGrafPtr) m_qdPort , &m_cgContext) ;
+ status = QDBeginCGContext((CGrafPtr) m_qdPort , &m_cgContext) ;
+#endif
CGContextSaveGState( m_cgContext ) ;
wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
class ImagePattern : public wxMacCGPattern
{
public :
- ImagePattern( const wxBitmap* bmp , CGAffineTransform transform )
+ ImagePattern( const wxBitmap* bmp , const CGAffineTransform& transform )
{
wxASSERT( bmp && bmp->Ok() ) ;
}
// ImagePattern takes ownership of CGImageRef passed in
- ImagePattern( CGImageRef image , CGAffineTransform transform )
+ ImagePattern( CGImageRef image , const CGAffineTransform& transform )
{
if ( image )
CFRetain( image ) ;
}
protected :
- void Init( CGImageRef image, CGAffineTransform transform )
+ void Init( CGImageRef image, const CGAffineTransform& transform )
{
m_image = image ;
if ( m_image )
class HatchPattern : public wxMacCGPattern
{
public :
- HatchPattern( int hatchstyle, CGAffineTransform transform )
+ HatchPattern( int hatchstyle, const CGAffineTransform& transform )
{
m_hatch = hatchstyle ;
m_imageBounds = CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
CGContextSetShouldAntialias( m_cgContext , false ) ;
#endif
- if ( fill | stroke )
+ if ( fill || stroke )
{
// set up brushes
m_mode = kCGPathFill ; // just a default
CGContextSetShouldAntialias( m_cgContext , false ) ;
#endif
- if ( fill | stroke )
+ if ( fill || stroke )
{
// setup brushes
m_mode = kCGPathFill ; // just a default
#endif
#endif
- OSStatus status;
- status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
+ ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
&chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
for ( int pos = 0; pos < (int)chars; pos ++ )
}
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::DestroyClippingRegion()
{
-// CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
-
CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
CGContextRestoreGState( cgContext );
CGContextSaveGState( cgContext );
{
wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
- wxMacPortSaver helper((CGrafPtr)m_macPort) ;
RGBColor colour;
-
+#ifndef __LP64__
+ wxMacPortSaver helper((CGrafPtr)m_macPort) ;
// 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 );
-
+#endif
// convert from Mac colour to wx
col->Set( colour.red >> 8, colour.green >> 8, colour.blue >> 8 );
yy = yy - hh;
}
+ int penwidth = m_pen.GetWidth();
+ if ( penwidth == 0 )
+ penwidth = 1 ;
+ if ( m_pen.GetStyle() == wxTRANSPARENT )
+ penwidth = 0 ;
+
+ bool offset = ( penwidth % 2 ) == 1 ;
+
wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->AddRectangle( xx , yy , ww , hh ) ;
+ // if we are offsetting the entire rectangle is moved 0.5, so the border line gets off by 1
+ if ( offset )
+ path->AddRectangle( xx , yy , ww-1 , hh-1 ) ;
+ else
+ path->AddRectangle( xx , yy , ww , hh ) ;
+
m_graphicContext->DrawPath( path ) ;
delete path ;
}
}
else
{
- m_graphicContext->PushState() ;
- m_graphicContext->Translate( xx , yy ) ;
- m_graphicContext->Scale( radius , radius ) ;
- double fw = ww / radius ;
- double fh = hh / radius;
- path->MoveToPoint(fw, fh / 2);
- path->AddArcToPoint(fw, fh, fw / 2, fh, 1);
- path->AddArcToPoint(0, fh, 0, fh / 2, 1);
- path->AddArcToPoint(0, 0, fw / 2, 0, 1);
- path->AddArcToPoint(fw, 0, fw, fh / 2, 1);
+ path->MoveToPoint( xx + ww, yy + hh / 2);
+ path->AddArcToPoint(xx + ww, yy + hh, xx + ww / 2,yy + hh, radius);
+ path->AddArcToPoint(xx , yy + hh, xx , yy + hh / 2, radius);
+ path->AddArcToPoint(xx , yy , xx + ww / 2, yy , radius);
+ path->AddArcToPoint(xx + ww, yy , xx + ww, yy + hh / 2, radius);
path->CloseSubpath();
m_graphicContext->DrawPath( path ) ;
- m_graphicContext->PopState() ;
}
delete path ;
}
{
wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
- wxFont formerFont = m_font ;
if ( theFont )
{
m_graphicContext->SetFont( *theFont ) ;
}
}
+#endif
+
#pragma mark -
// ---------------------------------------------------------------------------
// coordinates transformations
// ---------------------------------------------------------------------------
+/*
+ wxCoord XLOG2DEVMAC(wxCoord x) const
+ {
+ long new_x = x - m_logicalOriginX;
+ if (new_x > 0)
+ return (wxCoord)((double)new_x * m_scaleX + 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x;
+ else
+ return (wxCoord)((double)new_x * m_scaleX - 0.5) * m_signX + m_deviceOriginX + m_macLocalOrigin.x;
+ }
+ wxCoord YLOG2DEVMAC(wxCoord y) const
+ {
+ long new_y = y - m_logicalOriginY;
+ if (new_y > 0)
+ return (wxCoord)((double)new_y * m_scaleY + 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y;
+ else
+ return (wxCoord)((double)new_y * m_scaleY - 0.5) * m_signY + m_deviceOriginY + m_macLocalOrigin.y;
+ }
+*/ // TODO
wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
{
- return ((wxDC *)this)->XDEV2LOG(x);
+ long new_x = x - m_deviceOriginX;
+ if (new_x > 0)
+ return (wxCoord)((double)new_x / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
+ else
+ return (wxCoord)((double)new_x / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
}
wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
{
- return ((wxDC *)this)->YDEV2LOG(y);
+ long new_y = y - m_deviceOriginY;
+ if (new_y > 0)
+ return (wxCoord)((double)new_y / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
+ else
+ return (wxCoord)((double)new_y / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
}
wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
{
- return ((wxDC *)this)->XDEV2LOGREL(x);
+ if (x > 0)
+ return (wxCoord)((double)x / m_scaleX + 0.5);
+ else
+ return (wxCoord)((double)x / m_scaleX - 0.5);
}
wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
{
- return ((wxDC *)this)->YDEV2LOGREL(y);
+ if (y > 0)
+ return (wxCoord)((double)y / m_scaleY + 0.5);
+ else
+ return (wxCoord)((double)y / m_scaleY - 0.5);
}
wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
{
- return ((wxDC *)this)->XLOG2DEV(x);
+ long new_x = x - m_logicalOriginX;
+ if (new_x > 0)
+ return (wxCoord)((double)new_x * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
+ else
+ return (wxCoord)((double)new_x * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
}
wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
{
- return ((wxDC *)this)->YLOG2DEV(y);
+ long new_y = y - m_logicalOriginY;
+ if (new_y > 0)
+ return (wxCoord)((double)new_y * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
+ else
+ return (wxCoord)((double)new_y * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
}
wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
{
- return ((wxDC *)this)->XLOG2DEVREL(x);
+ if (x > 0)
+ return (wxCoord)((double)x * m_scaleX + 0.5);
+ else
+ return (wxCoord)((double)x * m_scaleX - 0.5);
}
wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
{
- return ((wxDC *)this)->YLOG2DEVREL(y);
+ if (y > 0)
+ return (wxCoord)((double)y * m_scaleY + 0.5);
+ else
+ return (wxCoord)((double)y * m_scaleY - 0.5);
}
#endif // wxMAC_USE_CORE_GRAPHICS