// under Quartz then content is transformed into a CGImageRef representing the same data
// which can be transferred to the GPU by the OS for fast rendering
-#if wxMAC_USE_CORE_GRAPHICS
- #define wxMAC_USE_PREMULTIPLIED_ALPHA 1
- static const int kBestByteAlignement = 16;
- static const int kMaskBytesPerPixel = 1;
-#else
-#define wxMAC_USE_PREMULTIPLIED_ALPHA 0
- static const int kBestByteAlignement = 4;
- static const int kMaskBytesPerPixel = 4;
-#endif
+#define wxMAC_USE_PREMULTIPLIED_ALPHA 1
+static const int kBestByteAlignement = 16;
+static const int kMaskBytesPerPixel = 1;
static int GetBestBytesPerRow( int rawBytes )
{
if ( forceType == 0 )
{
- // NOTE : For testing Panther behaviour under higher
- // Systems make this always be false
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- // as soon as it is supported, it's a better default
- forceType = kControlContentCGImageRef;
- }
- else if ( bmap->HasNativeSize() )
- {
- forceType = kControlContentIconRef;
- }
+ forceType = kControlContentCGImageRef;
}
if ( forceType == kControlContentIconRef )
m_iconRef = NULL ;
m_pictHandle = NULL ;
m_hBitmap = NULL ;
-#if! wxMAC_USE_CORE_GRAPHICS
- m_hMaskBitmap = NULL;
- m_maskBytesPerRow = 0 ;
-#endif
m_rawAccessCount = 0 ;
m_hasAlpha = false;
m_memBuf.UngetWriteBuf( size ) ;
m_hBitmap = NULL ;
-#if !wxMAC_USE_CORE_GRAPHICS
- Rect rect = { 0 , 0 , m_height , m_width } ;
- verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
- (char*) data , m_bytesPerRow ) ) ;
- wxASSERT_MSG( m_hBitmap , wxT("Unable to create GWorld context") ) ;
-#else
m_hBitmap = CGBitmapContextCreate((char*) data, m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst );
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
CGContextTranslateCTM( m_hBitmap, 0, m_height );
CGContextScaleCTM( m_hBitmap, 1, -1 );
-#endif
+
m_ok = ( m_hBitmap != NULL ) ;
return m_ok ;
return ;
m_hasAlpha = use ;
-#if wxMAC_USE_CORE_GRAPHICS
+
CGContextRelease( m_hBitmap );
m_hBitmap = CGBitmapContextCreate((char*) m_memBuf.GetData(), m_width, m_height, 8, m_bytesPerRow, wxMacGetGenericRGBColorSpace(), m_hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst );
wxASSERT_MSG( m_hBitmap , wxT("Unable to create CGBitmapContext context") ) ;
CGContextTranslateCTM( m_hBitmap, 0, m_height );
CGContextScaleCTM( m_hBitmap, 1, -1 );
-#else
- if ( m_hasAlpha )
- {
- wxASSERT( m_hMaskBitmap == NULL ) ;
-
- int width = GetWidth() ;
- int height = GetHeight() ;
- m_maskBytesPerRow = GetBestBytesPerRow( width * kMaskBytesPerPixel );
- size_t size = height * m_maskBytesPerRow ;
- unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ;
- wxASSERT( data != NULL ) ;
-
- memset( data , 0 , size ) ;
- Rect rect = { 0 , 0 , height , width } ;
-
- verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
- (char*) data , m_maskBytesPerRow ) ) ;
- wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ;
-
- m_maskMemBuf.UngetWriteBuf(size) ;
-
-
- UpdateAlphaMask() ;
- }
- else
- {
- DisposeGWorld( m_hMaskBitmap ) ;
- m_hMaskBitmap = NULL ;
- m_maskBytesPerRow = 0 ;
- }
-#endif
}
void *wxBitmapRefData::GetRawAccess() const
wxASSERT( m_rawAccessCount == 1 ) ;
--m_rawAccessCount ;
-
-#if !wxMAC_USE_CORE_GRAPHICS
- UpdateAlphaMask() ;
-#endif
}
bool wxBitmapRefData::HasNativeSize()
{
// Create Icon Family Handle
- IconFamilyHandle iconFamily = NULL ;
-
- if ( UMAGetSystemVersion() < 0x1040 )
- {
- iconFamily = (IconFamilyHandle) NewHandle( 8 ) ;
- (**iconFamily).resourceType = kIconFamilyType ;
- (**iconFamily).resourceSize = sizeof(OSType) + sizeof(Size);
- }
- else
- {
- iconFamily = (IconFamilyHandle) NewHandle( 0 ) ;
- }
+ IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle( 0 );
int w = GetWidth() ;
int h = GetHeight() ;
switch (sz)
{
case 128:
-#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if ( UMAGetSystemVersion() >= 0x1050 )
{
dataType = kIconServices128PixelDataARGB ;
break;
case 48:
-#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if ( UMAGetSystemVersion() >= 0x1050 )
{
dataType = kIconServices48PixelDataARGB ;
break;
case 32:
-#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if ( UMAGetSystemVersion() >= 0x1050 )
{
dataType = kIconServices32PixelDataARGB ;
break;
case 16:
-#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if ( UMAGetSystemVersion() >= 0x1050 )
{
dataType = kIconServices16PixelDataARGB ;
if ( dataType != 0 )
{
-#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if ( maskType == 0 && UMAGetSystemVersion() >= 0x1050 )
{
size_t datasize = sz * sz * 4 ;
*dest++ = b ;
if ( mask )
- {
*maskdest++ = 0xFF - *masksource++ ;
-#if !wxMAC_USE_CORE_GRAPHICS
- masksource++ ;
- masksource++ ;
- masksource++ ;
-#endif
- }
else if ( hasAlpha )
*maskdest++ = a ;
else
{
if ( m_pictHandle == NULL )
{
-#if !wxMAC_USE_CORE_GRAPHICS
- CGrafPtr origPort = NULL ;
- GDHandle origDev = NULL ;
- GWorldPtr wp = NULL ;
- GWorldPtr mask = NULL ;
- int height = GetHeight() ;
- int width = GetWidth() ;
-
- Rect rect = { 0 , 0 , height , width } ;
- RgnHandle clipRgn = NULL ;
-
- GetGWorld( &origPort , &origDev ) ;
- wp = GetHBITMAP( &mask ) ;
-
- if ( mask )
- {
- GWorldPtr monoworld ;
- clipRgn = NewRgn() ;
- OSStatus err = NewGWorld( &monoworld , 1 , &rect , NULL , NULL , 0 ) ;
- verify_noerr(err) ;
- LockPixels( GetGWorldPixMap( monoworld ) ) ;
- LockPixels( GetGWorldPixMap( mask ) ) ;
- SetGWorld( monoworld , NULL ) ;
-
- RGBColor white = { 0xffff , 0xffff , 0xffff } ;
- RGBColor black = { 0x0000 , 0x0000 , 0x0000 } ;
- RGBForeColor( &black ) ;
- RGBBackColor( &white ) ;
-
- CopyBits(GetPortBitMapForCopyBits(mask),
- GetPortBitMapForCopyBits(monoworld),
- &rect,
- &rect,
- srcCopy, NULL);
- BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( monoworld ) ) ;
-
- UnlockPixels( GetGWorldPixMap( monoworld ) ) ;
- UnlockPixels( GetGWorldPixMap( mask ) ) ;
- DisposeGWorld( monoworld ) ;
- }
-
- SetGWorld( wp , NULL ) ;
- Rect portRect ;
- GetPortBounds( wp , &portRect ) ;
- m_pictHandle = OpenPicture(&portRect);
-
- if (m_pictHandle)
- {
- RGBColor white = { 0xffff , 0xffff , 0xffff } ;
- RGBColor black = { 0x0000 , 0x0000 , 0x0000 } ;
-
- RGBForeColor( &black ) ;
- RGBBackColor( &white ) ;
-
- if ( clipRgn )
- SetClip( clipRgn ) ;
-
- LockPixels( GetGWorldPixMap( wp ) ) ;
- CopyBits(GetPortBitMapForCopyBits(wp),
- GetPortBitMapForCopyBits(wp),
- &portRect,
- &portRect,
- srcCopy,clipRgn);
- UnlockPixels( GetGWorldPixMap( wp ) ) ;
- ClosePicture();
- }
-
- SetGWorld( origPort , origDev ) ;
- if ( clipRgn )
- DisposeRgn( clipRgn ) ;
-#else
#ifndef __LP64__
GraphicsExportComponent exporter = 0;
OSStatus err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypePicture, &exporter);
}
CloseComponent( exporter );
}
-#endif
#endif
}
CGImageRef image ;
if ( m_rawAccessCount > 0 || m_cgImageRef == NULL )
{
-#if wxMAC_USE_CORE_GRAPHICS
- if ( UMAGetSystemVersion() >= 0x1040 && m_depth != 1 && m_bitmapMask == NULL )
+ if ( m_depth != 1 && m_bitmapMask == NULL )
{
if ( m_bitmapMask )
{
image = CGBitmapContextCreateImage( m_hBitmap );
}
else
-#endif
{
size_t imageSize = m_height * m_bytesPerRow ;
void * dataBuffer = m_memBuf.GetData() ;
return image ;
}
-#if wxMAC_USE_CORE_GRAPHICS
CGContextRef wxBitmapRefData::GetBitmapContext() const
{
return m_hBitmap;
}
-#else
-GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const
-{
- wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
- if ( mask )
- {
- *mask = NULL ;
- if ( m_bitmapMask )
- {
- *mask = (GWorldPtr) m_bitmapMask->GetHBITMAP() ;
- }
- else if ( m_hasAlpha )
- {
- if ( m_rawAccessCount > 0 )
- UpdateAlphaMask() ;
- *mask = m_hMaskBitmap ;
- }
- }
-
- return m_hBitmap ;
-}
-#endif
-
-#if !wxMAC_USE_CORE_GRAPHICS
-void wxBitmapRefData::UpdateAlphaMask() const
-{
- if ( m_hasAlpha )
- {
- unsigned char *sourcemask = (unsigned char *) GetRawAccess() ;
- unsigned char *destalphabase = (unsigned char *) m_maskMemBuf.GetData() ;
-
- int h = GetHeight() ;
- int w = GetWidth() ;
-
- for ( int y = 0 ; y < h ; ++y , destalphabase += m_maskBytesPerRow )
- {
- unsigned char* destalpha = destalphabase ;
-
- for ( int x = 0 ; x < w ; ++x , sourcemask += 4 )
- {
- // we must have 24 bit depth for non quartz smooth alpha
- *destalpha++ = 255 ;
- *destalpha++ = 255 - *sourcemask ;
- *destalpha++ = 255 - *sourcemask ;
- *destalpha++ = 255 - *sourcemask ;
- }
- }
- }
-}
-#endif
void wxBitmapRefData::Free()
{
if ( m_hBitmap )
{
-#if !wxMAC_USE_CORE_GRAPHICS
- DisposeGWorld( MAC_WXHBITMAP(m_hBitmap) ) ;
-#else
CGContextRelease(m_hBitmap);
-#endif
m_hBitmap = NULL ;
}
-#if !wxMAC_USE_CORE_GRAPHICS
- if ( m_hMaskBitmap )
- {
- DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ;
- m_hMaskBitmap = NULL ;
- }
-#endif
if (m_bitmapMask)
{
delete m_bitmapMask;
}
else if ( r == MASK_RED && g == MASK_GREEN && b == MASK_BLUE )
b = MASK_BLUE_REPLACEMENT ;
-#if !wxMAC_USE_CORE_GRAPHICS
- maskp++ ;
- maskp++ ;
- maskp++ ;
-#endif
}
else if ( hasAlpha )
{
WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
{
-#if !wxMAC_USE_CORE_GRAPHICS
- return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((GWorldPtr*)mask));
-#else
wxUnusedVar(mask);
return WXHBITMAP(M_BITMAPDATA->GetBitmapContext());
-#endif
}
// ----------------------------------------------------------------------------
{
if ( m_maskBitmap )
{
-#if wxMAC_USE_CORE_GRAPHICS
CGContextRelease( (CGContextRef) m_maskBitmap );
-#else
- DisposeGWorld( (GWorldPtr)m_maskBitmap ) ;
-#endif
m_maskBitmap = NULL ;
}
}
{
if ( m_maskBitmap )
{
-#if wxMAC_USE_CORE_GRAPHICS
CGContextRelease( (CGContextRef) m_maskBitmap );
-#else
- DisposeGWorld( (GWorldPtr)m_maskBitmap ) ;
-#endif
m_maskBitmap = NULL ;
}
-#if wxMAC_USE_CORE_GRAPHICS
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
// from MouseTracking sample :
// Ironically, due to a bug in CGImageCreateWithMask, you cannot use
kCGImageAlphaNone );
CGColorSpaceRelease( colorspace );
wxASSERT_MSG( m_maskBitmap , wxT("Unable to create CGBitmapContext context") ) ;
-#else
- Rect rect = { 0 , 0 , m_height , m_width } ;
-
- OSStatus err = NewGWorldFromPtr(
- (GWorldPtr*) &m_maskBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
- (char*) m_memBuf.GetData() , m_bytesPerRow ) ;
- verify_noerr( err ) ;
-#endif
}
// Create a mask from a mono bitmap (copies the bitmap).
b = *srcdata++ ;
if ( ( r + g + b ) > 0x10 )
- {
- *destdata++ = 0xFF ;
-#if !wxMAC_USE_CORE_GRAPHICS
- *destdata++ = 0xFF ;
*destdata++ = 0xFF ;
- *destdata++ = 0xFF ;
-#endif
- }
else
- {
- *destdata++ = 0x00 ;
-#if !wxMAC_USE_CORE_GRAPHICS
- *destdata++ = 0x00 ;
- *destdata++ = 0x00 ;
*destdata++ = 0x00 ;
-#endif
- }
}
}
b = *srcdata++ ;
if ( colour == wxColour( r , g , b ) )
- {
- *destdata++ = 0xFF ;
-#if !wxMAC_USE_CORE_GRAPHICS
*destdata++ = 0xFF ;
- *destdata++ = 0xFF ;
- *destdata++ = 0xFF ;
-#endif
- }
else
- {
- *destdata++ = 0x00 ;
-#if !wxMAC_USE_CORE_GRAPHICS
- *destdata++ = 0x00 ;
*destdata++ = 0x00 ;
- *destdata++ = 0x00 ;
-#endif
- }
}
}
else
#endif
{
-#if wxMAC_USE_CORE_GRAPHICS
wxClientDC dc(const_cast<wxButton*>(this));
wxCoord width, height ;
dc.GetTextExtent( m_label , &width, &height);
bounds.h = width;
bounds.v = height;
-#else
- wxMacWindowStateSaver sv( this );
- ::TextFont( m_font.MacGetFontNum() );
- ::TextSize( (short)(m_font.MacGetFontSize()) );
- ::TextFace( m_font.MacGetFontStyle() );
-
- err = GetThemeTextDimensions(
- (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
- kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
- verify_noerr( err );
-#endif
}
wBtn = bounds.h + sz.y;
lbHeight = metric ;
{
-#if wxMAC_USE_CORE_GRAPHICS
wxClientDC dc(const_cast<wxChoice*>(this));
-#else
- wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ;
- if ( m_font.Ok() )
- {
- ::TextFont( m_font.MacGetFontNum() ) ;
- ::TextSize( m_font.MacGetFontSize() ) ;
- ::TextFace( m_font.MacGetFontStyle() ) ;
- }
- else
- {
- ::TextFont( kFontIDMonaco ) ;
- ::TextSize( 9 ) ;
- ::TextFace( 0 ) ;
- }
-#endif
+
// Find the widest line
for(unsigned int i = 0; i < GetCount(); i++)
{
wxString str(GetString(i));
-#if wxMAC_USE_CORE_GRAPHICS
+
wxCoord width, height ;
dc.GetTextExtent( str , &width, &height);
wLine = width ;
-#else
-#if wxUSE_UNICODE
- Point bounds = { 0, 0 } ;
- SInt16 baseline ;
-
- ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) ,
- kThemeCurrentPortFont,
- kThemeStateActive,
- false,
- &bounds,
- &baseline );
-
- wLine = bounds.h ;
-#else
- wLine = ::TextWidth( str.c_str() , 0 , str.length() ) ;
-#endif
-#endif
+
lbWidth = wxMax( lbWidth, wLine ) ;
}
// Add room for the popup arrow
lbWidth += 2 * lbHeight ;
-#if wxMAC_USE_CORE_GRAPHICS
+
wxCoord width, height ;
dc.GetTextExtent( wxT("X"), &width, &height);
int cx = width ;
lbHeight += 4;
-#else
- // And just a bit more
- int cx = ::TextWidth( "X" , 0 , 1 ) ;
-#endif
+
lbWidth += cx ;
}
bool wxClipboard::IsSupported( const wxDataFormat &dataFormat )
{
+ wxLogTrace(TRACE_CLIPBOARD, wxT("Checking if format %s is available"),
+ dataFormat.GetId().c_str());
+
if ( m_data )
return m_data->IsSupported( dataFormat );
return wxDataObject::IsFormatInPasteboard( m_pasteboard, dataFormat );
if (gDataBrowserTableViewItemNotificationUPP == NULL)
{
gDataBrowserTableViewItemNotificationUPP =
-#if TARGET_API_MAC_OSX
(DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
-#else
- NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
-#endif
}
DataBrowserCallbacks callbacks;
break;
case wxDF_BITMAP:
-#if wxMAC_USE_CORE_GRAPHICS
m_format = (long) CFStringCreateCopy( NULL, CFSTR("public.tiff") );
-#else
- m_format = (long) CFStringCreateCopy( NULL, CFSTR("com.apple.pict") );
-#endif
break;
case wxDF_METAFILE:
-#if wxMAC_USE_CORE_GRAPHICS
m_format = (long) CFStringCreateCopy( NULL, CFSTR("com.adobe.pdf") );
-#else
- m_format = (long) CFStringCreateCopy( NULL, CFSTR("com.apple.pict") );
-#endif
break;
case wxDF_FILENAME:
{
m_type = wxDF_TEXT;
}
-#if wxMAC_USE_CORE_GRAPHICS
else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.tiff") ) )
{
m_type = wxDF_BITMAP;
{
m_type = wxDF_METAFILE;
}
-#else
- else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("com.apple.pict") ) )
- {
- m_type = wxDF_METAFILE;
- }
-#endif
else if ( UTTypeConformsTo( (CFStringRef)format, CFSTR("public.file-url") ) )
{
m_type = wxDF_FILENAME;
if (m_bitmap.Ok())
{
-#if wxMAC_USE_CORE_GRAPHICS
SetBitmap( rBitmap );
-#else
- m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
- m_pictCreated = false;
-#endif
}
}
wxBitmapDataObjectBase::SetBitmap( rBitmap );
if (m_bitmap.Ok())
{
-#if wxMAC_USE_CORE_GRAPHICS
CGImageRef cgImageRef = (CGImageRef) m_bitmap.CGImageCreate();
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( UMAGetSystemVersion() >= 0x1040 )
+
+ CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
+ CGImageDestinationRef destination = CGImageDestinationCreateWithData( data , kUTTypeTIFF , 1 , NULL );
+ if ( destination )
{
- CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
- CGImageDestinationRef destination = CGImageDestinationCreateWithData( data , kUTTypeTIFF , 1 , NULL );
- if ( destination )
- {
- CGImageDestinationAddImage( destination, cgImageRef, NULL );
- CGImageDestinationFinalize( destination );
- CFRelease( destination );
- }
- m_pictHandle = NewHandle(CFDataGetLength(data));
- if ( m_pictHandle )
- {
- memcpy( *(Handle)m_pictHandle, (const char *)CFDataGetBytePtr(data), CFDataGetLength(data) );
- }
- CFRelease( data );
+ CGImageDestinationAddImage( destination, cgImageRef, NULL );
+ CGImageDestinationFinalize( destination );
+ CFRelease( destination );
}
- else
-#endif
-#ifndef __LP64__
+ m_pictHandle = NewHandle(CFDataGetLength(data));
+ if ( m_pictHandle )
{
- // export as TIFF
- GraphicsExportComponent exporter = 0;
- OSStatus err = OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeTIFF, &exporter);
- if (noErr == err)
- {
- m_pictHandle = NewHandle(0);
- if ( m_pictHandle )
- {
- err = GraphicsExportSetInputCGImage( exporter, cgImageRef);
- err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle);
- err = GraphicsExportDoExport(exporter, NULL);
- }
- CloseComponent( exporter );
- }
+ memcpy( *(Handle)m_pictHandle, (const char *)CFDataGetBytePtr(data), CFDataGetLength(data) );
}
-#endif
+ CFRelease( data );
+
CGImageRelease(cgImageRef);
-#else
- m_pictHandle = m_bitmap.GetBitmapData()->GetPictHandle();
- m_pictCreated = false;
-#endif
}
}
{
if (m_pictHandle != NULL)
{
-#if wxMAC_USE_CORE_GRAPHICS
DisposeHandle( (Handle) m_pictHandle );
-#else
- if (m_pictCreated)
- KillPicture( (PicHandle)m_pictHandle );
-#endif
m_pictHandle = NULL;
}
m_pictCreated = false;
if ((pBuf == NULL) || (nSize == 0))
return false;
-#if wxMAC_USE_CORE_GRAPHICS
Handle picHandle = NewHandle( nSize );
memcpy( *picHandle, pBuf, nSize );
m_pictHandle = picHandle;
CGImageRef cgImageRef = 0;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) pBuf, nSize, kCFAllocatorNull);
- CGImageSourceRef source = CGImageSourceCreateWithData( data, NULL );
- if ( source )
- {
- cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
- }
- CFRelease( source );
- CFRelease( data );
- }
- else
-#endif
-#ifndef __LP64__
+
+ CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) pBuf, nSize, kCFAllocatorNull);
+ CGImageSourceRef source = CGImageSourceCreateWithData( data, NULL );
+ if ( source )
{
- // import from TIFF
- GraphicsImportComponent importer = 0;
- OSStatus err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypeTIFF, &importer);
- if (noErr == err)
- {
- if ( picHandle )
- {
- ComponentResult result = GraphicsImportSetDataHandle(importer, picHandle);
- if ( result == noErr )
- {
- Rect frame;
- GraphicsImportGetNaturalBounds( importer, &frame );
- GraphicsImportCreateCGImage( importer, &cgImageRef, kGraphicsImportCreateCGImageUsingCurrentSettings );
- }
- }
- CloseComponent( importer );
- }
+ cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
}
-#endif
+ CFRelease( source );
+ CFRelease( data );
+
if ( cgImageRef )
{
m_bitmap.Create( CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
CGImageRelease(cgImageRef);
cgImageRef = NULL;
}
-#else
- PicHandle picHandle = (PicHandle)NewHandle( nSize );
- memcpy( *picHandle, pBuf, nSize );
- m_pictHandle = picHandle;
- // ownership is transferred to the bitmap
- m_pictCreated = false;
-#ifndef __LP64__
- Rect frame;
- wxMacGetPictureBounds( picHandle, &frame );
-#if wxUSE_METAFILE
- wxMetafile mf;
- mf.SetHMETAFILE( (WXHMETAFILE)m_pictHandle );
-#endif
- wxMemoryDC mdc;
- m_bitmap.Create( frame.right - frame.left, frame.bottom - frame.top );
- mdc.SelectObject( m_bitmap );
-#if wxUSE_METAFILE
- mf.Play( &mdc );
-#endif
- mdc.SelectObject( wxNullBitmap );
-#endif
-#endif
return m_bitmap.Ok();
}
#include "wx/wxprec.h"
-#include "wx/dc.h"
-
-#if !wxMAC_USE_CORE_GRAPHICS
-
-#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
- namespace std {}
- using namespace std ;
- #endif
-#endif
-
-#include "wx/mac/private.h"
-#ifndef __DARWIN__
-#include <ATSUnicode.h>
-#include <TextCommon.h>
-#include <TextEncodingConverter.h>
-#endif
-
-
-// set to 0 if problems arise
-#define wxMAC_EXPERIMENTAL_DC 1
-
-
-IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
-
-//-----------------------------------------------------------------------------
-// constants
-//-----------------------------------------------------------------------------
-
-const double RAD2DEG = 180.0 / M_PI;
-const short kEmulatedMode = -1 ;
-const short kUnsupportedMode = -2 ;
-
-wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) :
- m_ph( (GrafPtr) dc->m_macPort )
-{
- wxASSERT( dc->Ok() ) ;
- m_dc = dc ;
- dc->MacSetupPort(&m_ph) ;
-}
-
-wxMacPortSetter::~wxMacPortSetter()
-{
- m_dc->MacCleanupPort(&m_ph) ;
-}
-
-#if wxMAC_EXPERIMENTAL_DC
-class wxMacFastPortSetter
-{
-public :
- wxMacFastPortSetter( const wxDC *dc )
- {
- wxASSERT( dc->Ok() ) ;
- m_swapped = QDSwapPort( (GrafPtr) dc->m_macPort , &m_oldPort ) ;
- m_clipRgn = NewRgn() ;
- GetClip( m_clipRgn ) ;
- m_dc = dc ;
- dc->MacSetupPort( NULL ) ;
- }
-
- ~wxMacFastPortSetter()
- {
- // SetPort( (GrafPtr) m_dc->m_macPort ) ;
- SetClip( m_clipRgn ) ;
- if ( m_swapped )
- SetPort( m_oldPort ) ;
- m_dc->MacCleanupPort( NULL ) ;
- DisposeRgn( m_clipRgn ) ;
- }
-
-private :
- bool m_swapped ;
- RgnHandle m_clipRgn ;
- GrafPtr m_oldPort ;
- const wxDC* m_dc ;
-} ;
-
-#else
-typedef wxMacPortSetter wxMacFastPortSetter ;
-#endif
-
-wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win ) :
- wxMacPortSaver( (GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) )
-{
- m_newPort =(GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ;
- m_formerClip = NewRgn() ;
- m_newClip = NewRgn() ;
- GetClip( m_formerClip ) ;
-
- if ( win )
- {
- // guard against half constructed objects, this just leads to a empty clip
- if ( win->GetPeer() )
- {
- int x = 0 , y = 0;
- win->MacWindowToRootWindow( &x, &y ) ;
-
- // get area including focus rect
- CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion(true).GetWXHRGN() , m_newClip ) ;
- if ( !EmptyRgn( m_newClip ) )
- OffsetRgn( m_newClip , x , y ) ;
- }
-
- SetClip( m_newClip ) ;
- }
-}
-
-wxMacWindowClipper::~wxMacWindowClipper()
-{
- SetPort( m_newPort ) ;
- SetClip( m_formerClip ) ;
- DisposeRgn( m_newClip ) ;
- DisposeRgn( m_formerClip ) ;
-}
-
-wxMacWindowStateSaver::wxMacWindowStateSaver( const wxWindow* win ) :
- wxMacWindowClipper( win )
-{
- // the port is already set at this point
- m_newPort = (GrafPtr) GetWindowPort((WindowRef) win->MacGetTopLevelWindowRef()) ;
- GetThemeDrawingState( &m_themeDrawingState ) ;
-}
-
-wxMacWindowStateSaver::~wxMacWindowStateSaver()
-{
- SetPort( m_newPort ) ;
- SetThemeDrawingState( m_themeDrawingState , true ) ;
-}
-
-//-----------------------------------------------------------------------------
-// wxDC
-//-----------------------------------------------------------------------------
-// this function emulates all wx colour manipulations, used to verify the implementation
-// by setting the mode in the blitting functions to kEmulatedMode
-void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor ) ;
-
-void wxMacCalculateColour( int logical_func , const RGBColor &srcColor , RGBColor &dstColor )
-{
- switch ( logical_func )
- {
- case wxAND: // src AND dst
- dstColor.red = dstColor.red & srcColor.red ;
- dstColor.green = dstColor.green & srcColor.green ;
- dstColor.blue = dstColor.blue & srcColor.blue ;
- break ;
-
- case wxAND_INVERT: // (NOT src) AND dst
- dstColor.red = dstColor.red & ~srcColor.red ;
- dstColor.green = dstColor.green & ~srcColor.green ;
- dstColor.blue = dstColor.blue & ~srcColor.blue ;
- break ;
-
- case wxAND_REVERSE:// src AND (NOT dst)
- dstColor.red = ~dstColor.red & srcColor.red ;
- dstColor.green = ~dstColor.green & srcColor.green ;
- dstColor.blue = ~dstColor.blue & srcColor.blue ;
- break ;
-
- case wxCLEAR: // 0
- dstColor.red = 0 ;
- dstColor.green = 0 ;
- dstColor.blue = 0 ;
- break ;
-
- case wxCOPY: // src
- dstColor.red = srcColor.red ;
- dstColor.green = srcColor.green ;
- dstColor.blue = srcColor.blue ;
- break ;
-
- case wxEQUIV: // (NOT src) XOR dst
- dstColor.red = dstColor.red ^ ~srcColor.red ;
- dstColor.green = dstColor.green ^ ~srcColor.green ;
- dstColor.blue = dstColor.blue ^ ~srcColor.blue ;
- break ;
-
- case wxINVERT: // NOT dst
- dstColor.red = ~dstColor.red ;
- dstColor.green = ~dstColor.green ;
- dstColor.blue = ~dstColor.blue ;
- break ;
-
- case wxNAND: // (NOT src) OR (NOT dst)
- dstColor.red = ~dstColor.red | ~srcColor.red ;
- dstColor.green = ~dstColor.green | ~srcColor.green ;
- dstColor.blue = ~dstColor.blue | ~srcColor.blue ;
- break ;
-
- case wxNOR: // (NOT src) AND (NOT dst)
- dstColor.red = ~dstColor.red & ~srcColor.red ;
- dstColor.green = ~dstColor.green & ~srcColor.green ;
- dstColor.blue = ~dstColor.blue & ~srcColor.blue ;
- break ;
-
- case wxOR: // src OR dst
- dstColor.red = dstColor.red | srcColor.red ;
- dstColor.green = dstColor.green | srcColor.green ;
- dstColor.blue = dstColor.blue | srcColor.blue ;
- break ;
-
- case wxOR_INVERT: // (NOT src) OR dst
- dstColor.red = dstColor.red | ~srcColor.red ;
- dstColor.green = dstColor.green | ~srcColor.green ;
- dstColor.blue = dstColor.blue | ~srcColor.blue ;
- break ;
-
- case wxOR_REVERSE: // src OR (NOT dst)
- dstColor.red = ~dstColor.red | srcColor.red ;
- dstColor.green = ~dstColor.green | srcColor.green ;
- dstColor.blue = ~dstColor.blue | srcColor.blue ;
- break ;
-
- case wxSET: // 1
- dstColor.red = 0xFFFF ;
- dstColor.green = 0xFFFF ;
- dstColor.blue = 0xFFFF ;
- break ;
-
- case wxSRC_INVERT: // (NOT src)
- dstColor.red = ~srcColor.red ;
- dstColor.green = ~srcColor.green ;
- dstColor.blue = ~srcColor.blue ;
- break ;
-
- case wxXOR: // src XOR dst
- dstColor.red = dstColor.red ^ srcColor.red ;
- dstColor.green = dstColor.green ^ srcColor.green ;
- dstColor.blue = dstColor.blue ^ srcColor.blue ;
- break ;
-
- case wxNO_OP: // dst
- default:
- break ;
- }
-}
-
-wxDC::wxDC()
-{
- m_ok = false;
- m_colour = true;
- m_macPort = NULL ;
- m_macMask = NULL ;
- m_macFontInstalled = false ;
- m_macBrushInstalled = false ;
- m_macPenInstalled = false ;
- m_macBoundaryClipRgn = NewRgn() ;
- m_macCurrentClipRgn = NewRgn() ;
- SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
- SetRectRgn( (RgnHandle) m_macCurrentClipRgn , -32000 , -32000 , 32000 , 32000 ) ;
- m_pen = *wxBLACK_PEN;
- m_font = *wxNORMAL_FONT;
- m_brush = *wxWHITE_BRUSH;
-
-#ifdef __WXDEBUG__
- // needed to debug possible errors with two active drawing methods at the same time on
- // the same DC
- m_macCurrentPortStateHelper = NULL ;
-#endif
-
- m_macATSUIStyle = NULL ;
- m_macAliasWasEnabled = false;
- m_macForegroundPixMap = NULL ;
- m_macBackgroundPixMap = NULL ;
-}
-
-wxDC::~wxDC(void)
-{
- 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);
-
-#if ! wxMAC_EXPERIMENTAL_DC
- m_macFontInstalled = false ;
- m_macBrushInstalled = false ;
- m_macPenInstalled = false ;
-#endif
-}
-
-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("wxDC::DoDrawBitmap - invalid DC") );
- wxCHECK_RET( bmp.Ok(), wxT("wxDC::DoDrawBitmap - invalid bitmap") );
-
- wxMacFastPortSetter 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 );
-
- GWorldPtr maskworld = NULL ;
- GWorldPtr bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP((WXHBITMAP*)&maskworld) );
- 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("wxDC::DoDrawBitmap - failed to lock pixels"));
-
- Rect source = { 0, 0, h, w };
- Rect dest = { yy, xx, yy + hh, xx + ww };
- if ( useMask && maskworld )
- {
- if ( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld))))
- {
- CopyDeepMask
- (
- GetPortBitMapForCopyBits(bmapworld),
- GetPortBitMapForCopyBits(MAC_WXHBITMAP(maskworld)),
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
- &source, &source, &dest, mode, NULL
- );
- UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld)));
- }
- }
- else
- {
- CopyBits( GetPortBitMapForCopyBits( bmapworld ),
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
- &source, &dest, mode, NULL ) ;
- }
- UnlockPixels( bmappixels ) ;
-
- m_macPenInstalled = false ;
- m_macBrushInstalled = false ;
- m_macFontInstalled = false ;
-}
-
-void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawIcon - invalid DC"));
- wxCHECK_RET(icon.Ok(), wxT("wxDC::DoDrawIcon - invalid icon"));
-
- wxMacFastPortSetter helper(this) ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- wxCoord yy = YLOG2DEVMAC(y);
- wxCoord w = icon.GetWidth();
- wxCoord h = icon.GetHeight();
- wxCoord ww = XLOG2DEVREL(w);
- wxCoord hh = YLOG2DEVREL(h);
-
- Rect r = { yy , xx, yy + hh, xx + ww } ;
- PlotIconRef( &r , kAlignNone , kTransformNone , 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);
- 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("wxDC::DoSetClippingRegionAsRegion - invalid DC"));
-
- wxMacFastPortSetter 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()
-{
- wxMacFastPortSetter helper(this) ;
-
- CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
- ResetClipping();
-}
-
-void wxDC::DoGetSizeMM( int* width, int* height ) const
-{
- int w = 0, h = 0;
-
- GetSize( &w, &h );
- 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("wxDC::SetTextForeground - invalid DC"));
-
- m_textForegroundColour = col;
- m_macFontInstalled = false ;
-}
-
-void wxDC::SetTextBackground( const wxColour &col )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::SetTextBackground - invalid DC"));
-
- m_textBackgroundColour = col;
- m_macFontInstalled = false ;
-}
-
-wxSize wxDC::GetPPI() const
-{
- return wxSize(72, 72);
-}
-
-int wxDC::GetDepth() const
-{
- if ( IsPortColor( (CGrafPtr) m_macPort ) )
- return ( (**GetPortPixMap( (CGrafPtr) m_macPort)).pixelSize ) ;
-
- return 1 ;
-}
-
-void wxDC::SetPalette( const wxPalette& palette )
-{
-}
-
-void wxDC::SetBackgroundMode( int mode )
-{
- m_backgroundMode = mode ;
-}
-
-void wxDC::SetFont( const wxFont &font )
-{
- m_font = font;
- m_macFontInstalled = false ;
-}
-
-void wxDC::SetPen( const wxPen &pen )
-{
- if ( m_pen == pen )
- return ;
-
- m_pen = pen;
- m_macPenInstalled = false ;
-}
-
-void wxDC::SetBrush( const wxBrush &brush )
-{
- if (m_brush == brush)
- return;
-
- m_brush = brush;
- m_macBrushInstalled = false ;
-}
-
-void wxDC::SetBackground( const wxBrush &brush )
-{
- if (m_backgroundBrush == brush)
- return;
-
- m_backgroundBrush = brush;
- if (m_backgroundBrush.Ok())
- m_macBrushInstalled = false ;
-}
-
-void wxDC::SetLogicalFunction( int function )
-{
- if (m_logicalFunction == function)
- return;
-
- m_logicalFunction = function ;
- m_macFontInstalled = false ;
- m_macBrushInstalled = false ;
- m_macPenInstalled = false ;
-}
-
-extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
- const wxColour & col, int style);
-
-bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
- const wxColour& col, int style)
-{
- return wxDoFloodFill(this, x, y, col, style);
-}
-
-bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const
-{
- wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel - invalid DC") );
-
- wxMacFastPortSetter helper(this) ;
-
- // NOTE: Get/SetCPixel are slow!
- RGBColor colour;
- GetCPixel( XLOG2DEVMAC(x), YLOG2DEVMAC(y), &colour );
-
- // convert from Mac colour to wx
- *col = colour;
-
- return true ;
-}
-
-void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLine - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen() ;
- wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
- m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2;
- wxCoord xx1 = XLOG2DEVMAC(x1) - offset;
- wxCoord yy1 = YLOG2DEVMAC(y1) - offset;
- wxCoord xx2 = XLOG2DEVMAC(x2) - offset;
- wxCoord yy2 = YLOG2DEVMAC(y2) - offset;
-
- if ((m_pen.GetCap() == wxCAP_ROUND) &&
- (m_pen.GetWidth() <= 1))
- {
- // Implement LAST_NOT for MAC at least for
- // orthogonal lines. RR.
- if (xx1 == xx2)
- {
- if (yy1 < yy2)
- yy2--;
- if (yy1 > yy2)
- yy2++;
- }
-
- if (yy1 == yy2)
- {
- if (xx1 < xx2)
- xx2--;
- if (xx1 > xx2)
- xx2++;
- }
- }
-
- ::MoveTo(xx1, yy1);
- ::LineTo(xx2, yy2);
- }
-}
-
-void wxDC::DoCrossHair( wxCoord x, wxCoord y )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoCrossHair - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- int w = 0, h = 0;
-
- GetSize( &w, &h );
- wxCoord xx = XLOG2DEVMAC(x);
- wxCoord yy = YLOG2DEVMAC(y);
-
- MacInstallPen();
- ::MoveTo( XLOG2DEVMAC(0), yy );
- ::LineTo( XLOG2DEVMAC(w), yy );
- ::MoveTo( xx, YLOG2DEVMAC(0) );
- ::LineTo( xx, YLOG2DEVMAC(h) );
- CalcBoundingBox(x, y);
- CalcBoundingBox(x + w, y + h);
- }
-}
-
-/*
-* To draw arcs properly the angles need to be converted from the WX style:
-* Angles start on the +ve X axis and go anti-clockwise (As you would draw on
-* a normal axis on paper).
-* TO
-* the Mac style:
-* Angles start on the +ve y axis and go clockwise.
-*/
-
-static double wxConvertWXangleToMACangle(double angle)
-{
- double newAngle = 90 - angle ;
-
- while ( newAngle > 360 )
- newAngle -= 360 ;
- while ( newAngle < 0 )
- newAngle += 360 ;
-
- return newAngle ;
-}
-
-void wxDC::DoDrawArc( wxCoord x1, wxCoord y1,
- wxCoord x2, wxCoord y2,
- wxCoord xc, wxCoord yc )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
-
- wxCoord xx1 = XLOG2DEVMAC(x1);
- wxCoord yy1 = YLOG2DEVMAC(y1);
- wxCoord xx2 = XLOG2DEVMAC(x2);
- 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;
- double radius1, radius2;
-
- if (xx1 == xx2 && yy1 == yy2)
- {
- radius1 = 0.0;
- radius2 = 360.0;
- }
- else if (radius == 0.0)
- {
- radius1 = radius2 = 0.0;
- }
- else
- {
- radius1 = (xx1 - xxc == 0) ?
- (yy1 - yyc < 0) ? 90.0 : -90.0 :
- -atan2(double(yy1 - yyc), double(xx1 - xxc)) * RAD2DEG;
- radius2 = (xx2 - xxc == 0) ?
- (yy2 - yyc < 0) ? 90.0 : -90.0 :
- -atan2(double(yy2 - yyc), double(xx2 - xxc)) * RAD2DEG;
- }
-
- wxCoord alpha2 = wxCoord(radius2 - radius1);
- wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1));
- while ( alpha2 < 0 )
- alpha2 += 360 ;
- alpha2 = -alpha2 ;
- Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad };
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- MacInstallBrush();
- PaintArc(&r, alpha1, alpha2);
- }
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen();
- FrameArc(&r, alpha1, alpha2);
- }
-}
-
-void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
- double sa, double ea )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc - invalid DC"));
- wxMacFastPortSetter helper(this) ;
- Rect r;
-
- // Order important Mac in opposite direction to wx
- // we have to make sure that the filling is always counter-clockwise
- double angle = sa - ea;
- if ( angle > 0 )
- angle -= 360 ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
- }
-
- sa = wxConvertWXangleToMACangle(sa);
- r.top = yy;
- r.left = xx;
- r.bottom = yy + hh;
- r.right = xx + ww;
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- MacInstallBrush();
- PaintArc(&r, (short)sa, (short)angle);
- }
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen();
- FrameArc(&r, (short)sa, (short)angle);
- }
-}
-
-void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPoint - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- wxCoord xx1 = XLOG2DEVMAC(x);
- wxCoord yy1 = YLOG2DEVMAC(y);
- RGBColor pencolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
-
- // NOTE: Get/SetCPixel are slow!
- ::SetCPixel( xx1, yy1, &pencolor) ;
- CalcBoundingBox(x, y);
- }
-}
-
-void wxDC::DoDrawLines(int n, wxPoint points[],
- wxCoord xoffset, wxCoord yoffset)
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawLines - invalid DC"));
-
- if (m_pen.GetStyle() == wxTRANSPARENT)
- return;
-
- wxMacFastPortSetter helper(this) ;
-
- MacInstallPen() ;
- wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 :
- m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ;
-
- wxCoord x1, x2 , y1 , y2 ;
- x1 = XLOG2DEVMAC(points[0].x + xoffset);
- y1 = YLOG2DEVMAC(points[0].y + yoffset);
-
- ::MoveTo( x1 - offset, y1 - offset );
- for (int i = 0; i < n-1; i++)
- {
- x2 = XLOG2DEVMAC(points[i + 1].x + xoffset);
- y2 = YLOG2DEVMAC(points[i + 1].y + yoffset);
- ::LineTo( x2 - offset, y2 - offset );
- }
-}
-
-void wxDC::DoDrawPolygon(int n, wxPoint points[],
- wxCoord xoffset, wxCoord yoffset,
- int fillStyle )
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawPolygon - invalid DC"));
-
- if ( m_brush.GetStyle() == wxTRANSPARENT && m_pen.GetStyle() == wxTRANSPARENT )
- return ;
-
- wxMacFastPortSetter helper(this) ;
-
- wxCoord x1, x2 , y1 , y2 ;
- PolyHandle polygon = OpenPoly();
- x2 = x1 = XLOG2DEVMAC(points[0].x + xoffset);
- y2 = y1 = YLOG2DEVMAC(points[0].y + yoffset);
-
- ::MoveTo(x1, y1);
- for (int i = 1; i < n; i++)
- {
- x2 = XLOG2DEVMAC(points[i].x + xoffset);
- y2 = YLOG2DEVMAC(points[i].y + yoffset);
- ::LineTo(x2, y2);
- }
-
- // close the polyline if necessary
- if ( x1 != x2 || y1 != y2 )
- ::LineTo( x1, y1 ) ;
- ClosePoly();
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- MacInstallBrush();
- ::PaintPoly( polygon );
- }
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen() ;
- ::FramePoly( polygon ) ;
- }
-
- KillPoly( polygon );
-}
-
-void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRectangle - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
-
- // CMB: handle -ve width and/or height
- if (ww < 0)
- {
- ww = -ww;
- xx = xx - ww;
- }
-
- if (hh < 0)
- {
- hh = -hh;
- yy = yy - hh;
- }
-
- Rect rect = { yy , xx , yy + hh , xx + ww } ;
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- MacInstallBrush() ;
- ::PaintRect( &rect ) ;
- }
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen() ;
- ::FrameRect( &rect ) ;
- }
-}
-
-void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
- wxCoord width, wxCoord height,
- double radius)
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawRoundedRectangle - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
- if (radius < 0.0)
- radius = - radius * ((width < height) ? width : height);
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
-
- // CMB: handle -ve width and/or height
- if (ww < 0)
- {
- ww = -ww;
- xx = xx - ww;
- }
-
- if (hh < 0)
- {
- hh = -hh;
- yy = yy - hh;
- }
-
- Rect rect = { yy , xx , yy + hh , xx + ww } ;
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- MacInstallBrush() ;
- ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
- }
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen() ;
- ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ;
- }
-}
-
-void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllipse - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
-
- // CMB: handle -ve width and/or height
- if (ww < 0)
- {
- ww = -ww;
- xx = xx - ww;
- }
-
- if (hh < 0)
- {
- hh = -hh;
- yy = yy - hh;
- }
-
- Rect rect = { yy , xx , yy + hh , xx + ww } ;
-
- if (m_brush.GetStyle() != wxTRANSPARENT)
- {
- MacInstallBrush() ;
- ::PaintOval( &rect ) ;
- }
-
- if (m_pen.GetStyle() != wxTRANSPARENT)
- {
- MacInstallPen() ;
- ::FrameOval( &rect ) ;
- }
-}
-
-bool wxDC::CanDrawBitmap(void) const
-{
- return true ;
-}
-
-bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord dstWidth, wxCoord dstHeight,
- wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask,
- wxCoord xsrcMask, wxCoord ysrcMask )
-{
- return DoStretchBlit( xdest, ydest, dstWidth, dstHeight,
- source, xsrc, ysrc, dstWidth, dstHeight,
- logical_func, useMask,
- xsrcMask, ysrcMask );
-}
-
-bool wxDC::DoStretchBlit(wxCoord xdest, wxCoord ydest,
- wxCoord dstWidth, wxCoord dstHeight,
- wxDC *source,
- wxCoord xsrc, wxCoord ysrc,
- wxCoord srcWidth, wxCoord srcHeight,
- int logical_func, bool useMask,
- wxCoord xsrcMask, wxCoord ysrcMask)
-{
- wxCHECK_MSG(Ok(), false, wxT("wxDC::DoStretchBlit - invalid DC"));
- wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoStretchBlit - invalid source DC"));
-
- if ( logical_func == wxNO_OP )
- return true ;
-
- if (xsrcMask == -1 && ysrcMask == -1)
- {
- xsrcMask = xsrc;
- ysrcMask = ysrc;
- }
-
- // correct the parameter in case this dc does not have a mask at all
- if ( useMask && !source->m_macMask )
- useMask = false ;
-
- Rect srcrect , dstrect ;
- srcrect.top = source->YLOG2DEVMAC(ysrc) ;
- srcrect.left = source->XLOG2DEVMAC(xsrc) ;
- srcrect.right = source->XLOG2DEVMAC(xsrc + srcWidth ) ;
- srcrect.bottom = source->YLOG2DEVMAC(ysrc + srcHeight) ;
- dstrect.top = YLOG2DEVMAC(ydest) ;
- dstrect.left = XLOG2DEVMAC(xdest) ;
- dstrect.bottom = YLOG2DEVMAC(ydest + dstHeight ) ;
- dstrect.right = XLOG2DEVMAC(xdest + dstWidth ) ;
- short mode = kUnsupportedMode ;
- bool invertDestinationFirst = false ;
-
- switch ( logical_func )
- {
- case wxAND: // src AND dst
- mode = adMin ; // ok
- break ;
-
- case wxAND_INVERT: // (NOT src) AND dst
- mode = notSrcOr ; // ok
- break ;
-
- case wxAND_REVERSE:// src AND (NOT dst)
- invertDestinationFirst = true ;
- mode = srcOr ;
- break ;
-
- case wxCLEAR: // 0
- mode = kEmulatedMode ;
- break ;
-
- case wxCOPY: // src
- mode = srcCopy ; // ok
- break ;
-
- case wxEQUIV: // (NOT src) XOR dst
- mode = srcXor ; // ok
- break ;
-
- case wxINVERT: // NOT dst
- mode = kEmulatedMode ; //or hilite ;
- break ;
-
- case wxNAND: // (NOT src) OR (NOT dst)
- invertDestinationFirst = true ;
- mode = srcBic ;
- break ;
-
- case wxNOR: // (NOT src) AND (NOT dst)
- invertDestinationFirst = true ;
- mode = notSrcOr ;
- break ;
-
- case wxNO_OP: // dst
- mode = kEmulatedMode ; // this has already been handled upon entry
- break ;
-
- case wxOR: // src OR dst
- mode = notSrcBic ;
- break ;
-
- case wxOR_INVERT: // (NOT src) OR dst
- mode = srcBic ;
- break ;
-
- case wxOR_REVERSE: // src OR (NOT dst)
- invertDestinationFirst = true ;
- mode = notSrcBic ;
- break ;
-
- case wxSET: // 1
- mode = kEmulatedMode ;
- break ;
-
- case wxSRC_INVERT: // (NOT src)
- mode = notSrcCopy ; // ok
- break ;
-
- case wxXOR: // src XOR dst
- mode = notSrcXor ; // ok
- break ;
-
- default :
- break ;
- }
-
- if ( mode == kUnsupportedMode )
- {
- wxFAIL_MSG(wxT("unsupported blitting mode" ));
-
- return false ;
- }
-
- CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ;
- PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ;
- if ( LockPixels(bmappixels) )
- {
- wxMacFastPortSetter helper(this) ;
-
- if ( source->GetDepth() == 1 )
- {
- RGBForeColor( &MAC_WXCOLORREF(m_textForegroundColour.GetPixel()) ) ;
- RGBBackColor( &MAC_WXCOLORREF(m_textBackgroundColour.GetPixel()) ) ;
- }
- else
- {
- // the modes need this, otherwise we'll end up having really nice colors...
- RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF } ;
- RGBColor black = { 0, 0, 0 } ;
-
- RGBForeColor( &black ) ;
- RGBBackColor( &white ) ;
- }
-
- if ( useMask && source->m_macMask )
- {
- if ( mode == srcCopy )
- {
- if ( LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) )
- {
- CopyMask( GetPortBitMapForCopyBits( sourcePort ) ,
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(source->m_macMask) ) ,
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
- &srcrect, &srcrect , &dstrect ) ;
- UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
- }
- }
- else
- {
- RgnHandle clipRgn = NewRgn() ;
- LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
- BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
- UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(source->m_macMask) ) ) ;
- OffsetRgn( clipRgn , -srcrect.left + dstrect.left, -srcrect.top + dstrect.top ) ;
-
- if ( mode == kEmulatedMode )
- {
- Pattern pat ;
-
- ::PenPat(GetQDGlobalsBlack(&pat));
- if ( logical_func == wxSET )
- {
- RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
- ::RGBForeColor( &col ) ;
- ::PaintRgn( clipRgn ) ;
- }
- else if ( logical_func == wxCLEAR )
- {
- RGBColor col= { 0x0000, 0x0000, 0x0000 } ;
- ::RGBForeColor( &col ) ;
- ::PaintRgn( clipRgn ) ;
- }
- else if ( logical_func == wxINVERT )
- {
- MacInvertRgn( clipRgn ) ;
- }
- else
- {
- for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
- {
- for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
- {
- Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
- Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
- if ( PtInRgn( dstPoint , clipRgn ) )
- {
- RGBColor srcColor, dstColor ;
-
- // NOTE: Get/SetCPixel are slow!
- SetPort( (GrafPtr) sourcePort ) ;
- GetCPixel( srcPoint.h , srcPoint.v , &srcColor ) ;
- SetPort( (GrafPtr) m_macPort ) ;
- GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
- wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
- SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
- }
- }
- }
- }
- }
- else
- {
- if ( invertDestinationFirst )
- MacInvertRgn( clipRgn ) ;
-
- CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
- &srcrect, &dstrect, mode, clipRgn ) ;
- }
-
- DisposeRgn( clipRgn ) ;
- }
- }
- else
- {
- RgnHandle clipRgn = NewRgn() ;
- SetRectRgn( clipRgn , dstrect.left , dstrect.top , dstrect.right , dstrect.bottom ) ;
-
- if ( mode == kEmulatedMode )
- {
- Pattern pat ;
-
- ::PenPat(GetQDGlobalsBlack(&pat));
- if ( logical_func == wxSET )
- {
- RGBColor col= { 0xFFFF, 0xFFFF, 0xFFFF } ;
- ::RGBForeColor( &col ) ;
- ::PaintRgn( clipRgn ) ;
- }
- else if ( logical_func == wxCLEAR )
- {
- RGBColor col = { 0x0000, 0x0000, 0x0000 } ;
-
- ::RGBForeColor( &col ) ;
- ::PaintRgn( clipRgn ) ;
- }
- else if ( logical_func == wxINVERT )
- {
- MacInvertRgn( clipRgn ) ;
- }
- else
- {
- for ( int y = 0 ; y < srcrect.right - srcrect.left ; ++y )
- {
- for ( int x = 0 ; x < srcrect.bottom - srcrect.top ; ++x )
- {
- Point dstPoint = { dstrect.top + y , dstrect.left + x } ;
- Point srcPoint = { srcrect.top + y , srcrect.left + x } ;
- {
- RGBColor srcColor, dstColor ;
-
- // NOTE: Get/SetCPixel are slow!
- SetPort( (GrafPtr) sourcePort ) ;
- GetCPixel( srcPoint.h , srcPoint.v , &srcColor) ;
- SetPort( (GrafPtr) m_macPort ) ;
- GetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
- wxMacCalculateColour( logical_func , srcColor , dstColor ) ;
- SetCPixel( dstPoint.h , dstPoint.v , &dstColor ) ;
- }
- }
- }
- }
- }
- else
- {
- if ( invertDestinationFirst )
- MacInvertRgn( clipRgn ) ;
-
- CopyBits( GetPortBitMapForCopyBits( sourcePort ) ,
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ) ,
- &srcrect, &dstrect, mode, NULL ) ;
- }
-
- DisposeRgn( clipRgn ) ;
- }
-
- UnlockPixels( bmappixels ) ;
- }
-
- m_macPenInstalled = false ;
- m_macBrushInstalled = false ;
- m_macFontInstalled = false ;
-
- return true;
-}
-
-void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
- double angle)
-{
- wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText - invalid DC") );
-
- if ( str.empty() )
- return ;
-
- wxMacFastPortSetter helper(this) ;
- MacInstallFont() ;
-
- OSStatus status = noErr ;
- ATSUTextLayout atsuLayout ;
-
- wxMacUniCharBuffer unibuf( str ) ;
- UniCharCount chars = unibuf.GetChars() ;
-
- status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
-
- wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
-
- status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
- wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
-
- int iAngle = int( angle );
- int drawX = XLOG2DEVMAC(x) ;
- int drawY = YLOG2DEVMAC(y) ;
-
- ATSUTextMeasurement textBefore, textAfter ;
- ATSUTextMeasurement ascent, descent ;
-
- ATSLineLayoutOptions layoutOptions = kATSLineNoLayoutOptions ;
-
- if (m_font.GetNoAntiAliasing())
- {
- layoutOptions |= kATSLineNoAntiAliasing ;
- }
-
- Fixed atsuAngle = IntToFixed( iAngle ) ;
-
- ATSUAttributeTag atsuTags[] =
- {
- kATSULineLayoutOptionsTag ,
- kATSULineRotationTag ,
- } ;
-
- ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- sizeof( ATSLineLayoutOptions ) ,
- sizeof( Fixed ) ,
- } ;
-
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- &layoutOptions ,
- &atsuAngle ,
- } ;
-
- status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag) - ( abs(iAngle) > 0.001 ? 0 : 1),
- atsuTags, atsuSizes, atsuValues ) ;
-
- status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- &textBefore , &textAfter, &ascent , &descent );
- wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
-
- if ( m_backgroundMode == wxSOLID )
- {
- // background painting must be done by hand, cannot be done by ATSUI
- wxCoord x2 , y2 ;
- PolyHandle polygon = OpenPoly();
-
- ::MoveTo(drawX, drawY);
-
- x2 = (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) ;
- y2 = (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ;
- ::LineTo(x2, y2);
-
- x2 = (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ;
- y2 = (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ;
- ::LineTo(x2, y2);
-
- x2 = (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ;
- y2 = (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ;
- ::LineTo(x2, y2);
-
- ::LineTo( drawX, drawY) ;
- ClosePoly();
-
- ::ErasePoly( polygon );
- KillPoly( polygon );
- }
-
- drawX += (int)(sin(angle / RAD2DEG) * FixedToInt(ascent));
- drawY += (int)(cos(angle / RAD2DEG) * FixedToInt(ascent));
- status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- IntToFixed(drawX) , IntToFixed(drawY) );
-
- wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );
-
- Rect rect ;
- status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- IntToFixed(drawX) , IntToFixed(drawY) , &rect );
- wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
-
- OffsetRect( &rect , -m_deviceLocalOriginX , -m_deviceLocalOriginY ) ;
- CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
- CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
- ::ATSUDisposeTextLayout(atsuLayout);
-}
-
-void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
-{
- DoDrawRotatedText( strtext , x , y , 0) ;
-}
-
-bool wxDC::CanGetTextExtent() const
-{
- wxCHECK_MSG(Ok(), false, wxT("wxDC::CanGetTextExtent - invalid DC"));
-
- return true ;
-}
-
-
-void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
- wxCoord *descent, wxCoord *externalLeading ,
- const wxFont *theFont ) const
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoGetTextExtent - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
- wxFont formerFont = m_font ;
- if ( theFont )
- {
- // work around the constness
- *((wxFont*)(&m_font)) = *theFont ;
- }
-
- MacInstallFont() ;
-
- OSStatus status = noErr ;
- ATSUTextLayout atsuLayout ;
-
- wxMacUniCharBuffer unibuf( str ) ;
- UniCharCount chars = unibuf.GetChars() ;
-
- status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
-
- wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
-
- status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
- wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
-
- ATSLineLayoutOptions layoutOptions = kATSLineNoLayoutOptions ;
-
- if (m_font.GetNoAntiAliasing())
- {
- layoutOptions |= kATSLineNoAntiAliasing ;
- }
-
- ATSUAttributeTag atsuTags[] =
- {
- kATSULineLayoutOptionsTag ,
- } ;
-
- ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- sizeof( ATSLineLayoutOptions ) ,
- } ;
-
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- &layoutOptions ,
- } ;
-
- status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
- atsuTags, atsuSizes, atsuValues ) ;
-
- ATSUTextMeasurement textBefore, textAfter ;
- ATSUTextMeasurement textAscent, textDescent ;
-
- status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- &textBefore , &textAfter, &textAscent , &textDescent );
-
- if ( height )
- *height = YDEV2LOGREL( FixedToInt(textAscent + textDescent) ) ;
- if ( descent )
- *descent =YDEV2LOGREL( FixedToInt(textDescent) );
- if ( externalLeading )
- *externalLeading = 0 ;
- if ( width )
- *width = XDEV2LOGREL( FixedToInt(textAfter - textBefore) ) ;
-
- ::ATSUDisposeTextLayout(atsuLayout);
-
-
- if ( theFont )
- {
- // work around the constness
- *((wxFont*)(&m_font)) = formerFont ;
- m_macFontInstalled = false ;
- }
-}
-
-bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
-{
- wxCHECK_MSG(Ok(), false, wxT("wxDC::DoGetPartialTextExtents - invalid DC"));
-
- widths.Empty();
- widths.Add(0, text.length());
-
- if (text.length() == 0)
- return false;
-
- wxMacFastPortSetter helper(this) ;
- MacInstallFont() ;
-
- OSStatus status = noErr ;
- ATSUTextLayout atsuLayout ;
-
- wxMacUniCharBuffer unibuf( text ) ;
- UniCharCount chars = unibuf.GetChars() ;
-
- status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
-
- wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
-
- status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
- wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
-
- ATSLineLayoutOptions layoutOptions = kATSLineNoLayoutOptions ;
-
- if (m_font.GetNoAntiAliasing())
- {
- layoutOptions |= kATSLineNoAntiAliasing ;
- }
-
- ATSUAttributeTag atsuTags[] =
- {
- kATSULineLayoutOptionsTag ,
- } ;
-
- ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- sizeof( ATSLineLayoutOptions ) ,
- } ;
-
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- &layoutOptions ,
- } ;
-
- status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
- atsuTags, atsuSizes, atsuValues ) ;
-
- for ( int pos = 0; pos < (int)chars ; pos ++ )
- {
- unsigned long actualNumberOfBounds = 0;
- ATSTrapezoid glyphBounds;
-
- // We get a single bound, since the text should only require one. If it requires more, there is an issue
- OSStatus result;
- result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1,
- kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds );
- if (result != noErr || actualNumberOfBounds != 1 )
- return false;
-
- widths[pos] = XDEV2LOGREL(FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ));
- }
-
- ::ATSUDisposeTextLayout(atsuLayout);
-
- return true;
-}
-
-wxCoord wxDC::GetCharWidth(void) const
-{
- wxCoord width = 0 ;
- DoGetTextExtent( wxT("g"), &width , NULL , NULL , NULL , NULL ) ;
- return width ;
-}
-
-wxCoord wxDC::GetCharHeight(void) const
-{
- wxCoord height ;
- DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ) ;
- return height ;
-}
-
-void wxDC::Clear(void)
-{
- wxCHECK_RET(Ok(), wxT("wxDC::Clear - invalid DC"));
-
- wxMacFastPortSetter helper(this) ;
- Rect rect = { -31000 , -31000 , 31000 , 31000 } ;
-
- if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
- {
- ::PenNormal() ;
- MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
- ::EraseRect( &rect ) ;
- }
-}
-
-void wxDC::MacInstallFont() const
-{
- wxCHECK_RET(Ok(), wxT("Invalid DC"));
-
- // if ( m_macFontInstalled )
- // return ;
-
- Pattern blackColor ;
- MacSetupBackgroundForCurrentPort(m_backgroundBrush) ;
- if ( m_backgroundMode != wxTRANSPARENT )
- {
- Pattern whiteColor ;
- ::BackPat(GetQDGlobalsWhite(&whiteColor));
- }
-
- wxASSERT( m_font.Ok() ) ;
-
- ::TextFont( m_font.MacGetFontNum() ) ;
- ::TextSize( (short)(m_scaleY * m_font.MacGetFontSize()) ) ;
- ::TextFace( m_font.MacGetFontStyle() ) ;
- m_macFontInstalled = true ;
- m_macBrushInstalled = false ;
- m_macPenInstalled = false ;
- RGBColor forecolor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel());
- RGBColor backcolor = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel());
- ::RGBForeColor( &forecolor );
- ::RGBBackColor( &backcolor );
-
- // TODO:
- short mode = patCopy ;
- switch ( m_logicalFunction )
- {
- case wxCOPY: // src
- mode = patCopy ;
- break ;
-
- case wxINVERT: // NOT dst
- ::PenPat(GetQDGlobalsBlack(&blackColor));
- mode = patXor ;
- break ;
-
- case wxXOR: // src XOR dst
- mode = patXor ;
- break ;
-
- case wxOR_REVERSE: // src OR (NOT dst)
- mode = notPatOr ;
- break ;
-
- case wxSRC_INVERT: // (NOT src)
- mode = notPatCopy ;
- break ;
-
- case wxAND: // src AND dst
- mode = adMin ;
- break ;
-
- // TODO: unsupported
- case wxCLEAR: // 0
- case wxAND_REVERSE:// src AND (NOT dst)
- case wxAND_INVERT: // (NOT src) AND dst
- case wxNO_OP: // dst
- case wxNOR: // (NOT src) AND (NOT dst)
- case wxEQUIV: // (NOT src) XOR dst
- case wxOR_INVERT: // (NOT src) OR dst
- case wxNAND: // (NOT src) OR (NOT dst)
- case wxOR: // src OR dst
- case wxSET: // 1
- // case wxSRC_OR: // source _bitmap_ OR destination
- // case wxSRC_AND: // source _bitmap_ AND destination
- break ;
-
- default:
- break ;
- }
-
- ::PenMode( mode ) ;
- OSStatus status = noErr ;
- status = ATSUCreateAndCopyStyle( (ATSUStyle) m_font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ;
- wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
-
- Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ;
- ATSUAttributeTag atsuTags[] =
- {
- kATSUSizeTag ,
- } ;
- ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- sizeof( Fixed ) ,
- } ;
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
- {
- &atsuSize ,
- } ;
-
- status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
- atsuTags, atsuSizes, atsuValues);
-
- wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ) ;
-}
-
-Pattern gPatterns[] =
-{
- // hatch patterns
- { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } } ,
- { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } } ,
- { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } } ,
- { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } } ,
- { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } } ,
- { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } } ,
- { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } } ,
-
- // dash patterns
- { { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } } , // DOT
- { { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } } , // LONG_DASH
- { { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } } , // SHORT_DASH
- { { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } } , // DOT_DASH
-} ;
-
-static void wxMacGetPattern(int penStyle, Pattern *pattern)
-{
- int index = 0; // solid pattern by default
- switch (penStyle)
- {
- // hatches
- case wxBDIAGONAL_HATCH: index = 1; break;
- case wxFDIAGONAL_HATCH: index = 2; break;
- case wxCROSS_HATCH: index = 3; break;
- case wxHORIZONTAL_HATCH: index = 4; break;
- case wxVERTICAL_HATCH: index = 5; break;
- case wxCROSSDIAG_HATCH: index = 6; break;
-
- // dashes
- case wxDOT: index = 7; break;
- case wxLONG_DASH: index = 8; break;
- case wxSHORT_DASH: index = 9; break;
- case wxDOT_DASH: index = 10; break;
-
- default:
- break;
- }
-
- *pattern = gPatterns[index];
-}
-
-void wxDC::MacInstallPen() const
-{
- wxCHECK_RET(Ok(), wxT("wxDC::MacInstallPen - invalid DC"));
-
- //Pattern blackColor;
- // if ( m_macPenInstalled )
- // return ;
-
- RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
- RGBColor backcolor = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel());
- ::RGBForeColor( &forecolor );
- ::RGBBackColor( &backcolor );
- ::PenNormal() ;
-
- // null means only one pixel, at whatever resolution
- int penWidth = (int) (m_pen.GetWidth() * m_scaleX) ;
- if ( penWidth == 0 )
- penWidth = 1 ;
- ::PenSize(penWidth, penWidth);
-
- Pattern pat;
- int penStyle = m_pen.GetStyle();
- if (penStyle == wxUSER_DASH)
- {
- // FIXME: there should be exactly 8 items in the dash
- wxDash* dash ;
- int number = m_pen.GetDashes(&dash) ;
- int index = 0;
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = dash[index] ;
- if (index < number - 1)
- index++;
- }
- }
- else
- {
- wxMacGetPattern(penStyle, &pat);
- }
- ::PenPat(&pat);
-
- // TODO:
- short mode = patCopy ;
- switch ( m_logicalFunction )
- {
- case wxCOPY: // only foreground color, leave background (thus not patCopy)
- mode = patOr ;
- break ;
-
- case wxINVERT: // NOT dst
- // ::PenPat(GetQDGlobalsBlack(&blackColor));
- mode = patXor ;
- break ;
-
- case wxXOR: // src XOR dst
- mode = patXor ;
- break ;
-
- case wxOR_REVERSE: // src OR (NOT dst)
- mode = notPatOr ;
- break ;
-
- case wxSRC_INVERT: // (NOT src)
- mode = notPatCopy ;
- break ;
-
- case wxAND: // src AND dst
- mode = adMin ;
- break ;
-
- // TODO: unsupported
- case wxCLEAR: // 0
- case wxAND_REVERSE:// src AND (NOT dst)
- case wxAND_INVERT: // (NOT src) AND dst
- case wxNO_OP: // dst
- case wxNOR: // (NOT src) AND (NOT dst)
- case wxEQUIV: // (NOT src) XOR dst
- case wxOR_INVERT: // (NOT src) OR dst
- case wxNAND: // (NOT src) OR (NOT dst)
- case wxOR: // src OR dst
- case wxSET: // 1
- // case wxSRC_OR: // source _bitmap_ OR destination
- // case wxSRC_AND: // source _bitmap_ AND destination
- break ;
-
- default:
- break ;
- }
-
- ::PenMode( mode ) ;
- m_macPenInstalled = true ;
- m_macBrushInstalled = false ;
- m_macFontInstalled = false ;
-}
-
-void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background )
-{
- Pattern whiteColor ;
-
- if ( background.Ok() )
- {
- switch ( background.MacGetBrushKind() )
- {
- case kwxMacBrushTheme :
- ::SetThemeBackground( background.MacGetTheme() , wxDisplayDepth() , true ) ;
- break ;
-
- case kwxMacBrushThemeBackground :
- {
- Rect extent ;
- ThemeBackgroundKind bg = background.MacGetThemeBackground( &extent ) ;
- ::ApplyThemeBackground( bg , &extent, kThemeStateActive , wxDisplayDepth() , true ) ;
- }
- break ;
-
- case kwxMacBrushColour :
- {
- ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
- int brushStyle = background.GetStyle();
- if (brushStyle == wxSOLID)
- ::BackPat(GetQDGlobalsWhite(&whiteColor));
- else if (background.IsHatch())
- {
- Pattern pat ;
- wxMacGetPattern(brushStyle, &pat);
- ::BackPat(&pat);
- }
- else
- {
- ::BackPat(GetQDGlobalsWhite(&whiteColor));
- }
- }
- break ;
-
- default:
- break ;
- }
- }
-}
-
-void wxDC::MacInstallBrush() const
-{
- wxCHECK_RET(Ok(), wxT("Invalid DC"));
-
- // if ( m_macBrushInstalled )
- // return ;
-
- Pattern blackColor ;
- bool backgroundTransparent = (GetBackgroundMode() == wxTRANSPARENT) ;
- ::RGBForeColor( &MAC_WXCOLORREF( m_brush.GetColour().GetPixel()) );
- ::RGBBackColor( &MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) );
-
- int brushStyle = m_brush.GetStyle();
- if (brushStyle == wxSOLID)
- {
- switch ( m_brush.MacGetBrushKind() )
- {
- case kwxMacBrushTheme :
- {
- Pattern whiteColor ;
- ::BackPat(GetQDGlobalsWhite(&whiteColor));
- ::SetThemePen( m_brush.MacGetTheme() , wxDisplayDepth() , true ) ;
- }
- break ;
-
- default :
- ::PenPat(GetQDGlobalsBlack(&blackColor));
- break ;
-
- }
- }
- else if (m_brush.IsHatch())
- {
- Pattern pat ;
-
- wxMacGetPattern(brushStyle, &pat);
- ::PenPat(&pat);
- }
- else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )
- {
- // we force this in order to be compliant with wxMSW
- backgroundTransparent = false ;
-
- // for these the text fore (and back for MASK_OPAQUE) colors are used
- wxBitmap* bitmap = m_brush.GetStipple() ;
- int width = bitmap->GetWidth() ;
- int height = bitmap->GetHeight() ;
- GWorldPtr gw = NULL ;
-
- if ( m_brush.GetStyle() == wxSTIPPLE )
- gw = MAC_WXHBITMAP(bitmap->GetHBITMAP(NULL)) ;
- else
- gw = MAC_WXHBITMAP(bitmap->GetMask()->GetHBITMAP()) ;
-
- PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ;
- LockPixels( gwpixmaphandle ) ;
- bool isMonochrome = !IsPortColor( gw ) ;
- if ( !isMonochrome )
- {
- if ( (**gwpixmaphandle).pixelSize == 1 )
- isMonochrome = true ;
- }
-
- if ( isMonochrome && width == 8 && height == 8 )
- {
- ::RGBForeColor( &MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) );
- ::RGBForeColor( &MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) );
- BitMap* gwbitmap = (BitMap*) *gwpixmaphandle ; // since the color depth is 1 it is a BitMap
- UInt8 *gwbits = (UInt8*) gwbitmap->baseAddr ;
- int alignment = gwbitmap->rowBytes & 0x7FFF ;
- Pattern pat ;
-
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = gwbits[i * alignment + 0] ;
- }
-
- UnlockPixels( GetGWorldPixMap( gw ) ) ;
- ::PenPat( &pat ) ;
- }
- else
- {
- // this will be the code to handle power of 2 patterns, we will have to arrive at a nice
- // caching scheme before putting this into production
- Handle image;
- long imageSize;
-
- PixPatHandle pixpat = NewPixPat() ;
- CopyPixMap(gwpixmaphandle, (**pixpat).patMap);
- imageSize = GetPixRowBytes((**pixpat).patMap) *
- ((**(**pixpat).patMap).bounds.bottom -
- (**(**pixpat).patMap).bounds.top);
- PtrToHand( (**gwpixmaphandle).baseAddr, &image, imageSize );
- (**pixpat).patData = image;
-
- if ( isMonochrome )
- {
- CTabHandle ctable = ((**((**pixpat).patMap)).pmTable) ;
- ColorSpecPtr ctspec = (ColorSpecPtr) &(**ctable).ctTable ;
- if ( ctspec[0].rgb.red == 0x0000 )
- {
- ctspec[1].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
- ctspec[0].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
- }
- else
- {
- ctspec[0].rgb = MAC_WXCOLORREF( m_textBackgroundColour.GetPixel()) ;
- ctspec[1].rgb = MAC_WXCOLORREF( m_textForegroundColour.GetPixel()) ;
- }
- ::CTabChanged( ctable ) ;
- }
-
- ::PenPixPat(pixpat);
- m_macForegroundPixMap = pixpat ;
- }
-
- UnlockPixels( gwpixmaphandle ) ;
- }
- else
- {
- ::PenPat(GetQDGlobalsBlack(&blackColor));
- }
-
- short mode = patCopy ;
- switch ( m_logicalFunction )
- {
- case wxCOPY: // src
- if ( backgroundTransparent )
- mode = patOr ;
- else
- mode = patCopy ;
- break ;
-
- case wxINVERT: // NOT dst
- if ( !backgroundTransparent )
- ::PenPat(GetQDGlobalsBlack(&blackColor));
- mode = patXor ;
- break ;
-
- case wxXOR: // src XOR dst
- mode = patXor ;
- break ;
-
- case wxOR_REVERSE: // src OR (NOT dst)
- mode = notPatOr ;
- break ;
-
- case wxSRC_INVERT: // (NOT src)
- mode = notPatCopy ;
- break ;
-
- case wxAND: // src AND dst
- mode = adMin ;
- break ;
-
- // TODO: unsupported
- case wxCLEAR: // 0
- case wxAND_REVERSE:// src AND (NOT dst)
- case wxAND_INVERT: // (NOT src) AND dst
- case wxNO_OP: // dst
- case wxNOR: // (NOT src) AND (NOT dst)
- case wxEQUIV: // (NOT src) XOR dst
- case wxOR_INVERT: // (NOT src) OR dst
- case wxNAND: // (NOT src) OR (NOT dst)
- case wxOR: // src OR dst
- case wxSET: // 1
- // case wxSRC_OR: // source _bitmap_ OR destination
- // case wxSRC_AND: // source _bitmap_ AND destination
- break ;
-
- default:
- break ;
- }
-
- ::PenMode( mode ) ;
- m_macBrushInstalled = true ;
- m_macPenInstalled = false ;
- m_macFontInstalled = false ;
-}
-
-#endif // !wxMAC_USE_CORE_GRAPHICS
+// TODO REMOVE
\ No newline at end of file
#include "wx/dc.h"
-#if wxMAC_USE_CORE_GRAPHICS
-
#ifndef WX_PRECOMP
#include "wx/log.h"
#include "wx/dcmemory.h"
#include "wx/mac/private.h"
-
-#ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
-#define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
-#endif
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
-typedef float CGFloat ;
-#endif
-
-//-----------------------------------------------------------------------------
-// constants
-//-----------------------------------------------------------------------------
-
-#if !defined( __DARWIN__ ) || defined(__MWERKS__)
-#ifndef M_PI
-const double M_PI = 3.14159265358979 ;
-#endif
-#endif
-
-static const double RAD2DEG = 180.0 / M_PI;
-
#ifndef __LP64__
// TODO: update
SetThemeDrawingState( m_themeDrawingState , true ) ;
}
-// 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 )
-{
- wxASSERT( dc->Ok() ) ;
- m_dc = dc ;
-
-// dc->MacSetupPort(&m_ph) ;
-}
-
-wxMacPortSetter::~wxMacPortSetter()
-{
-// m_dc->MacCleanupPort(&m_ph) ;
-}
-
-#endif
-
-#endif
-
-//-----------------------------------------------------------------------------
-// Local functions
-//-----------------------------------------------------------------------------
-
-static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
-
-//-----------------------------------------------------------------------------
-// device context implementation
-//
-// more and more of the dc functionality should be implemented by calling
-// the appropricate wxMacCGContext, but we will have to do that step by step
-// also coordinate conversions should be moved to native matrix ops
-//-----------------------------------------------------------------------------
-
-// we always stock two context states, one at entry, to be able to preserve the
-// state we were called with, the other one after changing to HI Graphics orientation
-// (this one is used for getting back clippings etc)
-
-//-----------------------------------------------------------------------------
-// wxGraphicPath implementation
-//-----------------------------------------------------------------------------
-
-#if !wxUSE_GRAPHICS_CONTEXT
-
-IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
-
-wxMacCGPath::wxMacCGPath()
-{
- m_path = CGPathCreateMutable() ;
-}
-
-wxMacCGPath::~wxMacCGPath()
-{
- CGPathRelease( m_path ) ;
-}
-
-// opens (starts) a new subpath
-void wxMacCGPath::MoveToPoint( wxCoord x1 , wxCoord y1 )
-{
- CGPathMoveToPoint( m_path , NULL , x1 , y1 ) ;
-}
-
-void wxMacCGPath::AddLineToPoint( wxCoord x1 , wxCoord y1 )
-{
- CGPathAddLineToPoint( m_path , NULL , x1 , y1 ) ;
-}
-
-void wxMacCGPath::AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 )
-{
- CGPathAddQuadCurveToPoint( m_path , NULL , cx1 , cy1 , x1 , y1 );
-}
-
-void wxMacCGPath::AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
-{
- CGRect cgRect = { { x , y } , { w , h } } ;
- CGPathAddRect( m_path , NULL , cgRect ) ;
-}
-
-void wxMacCGPath::AddCircle( wxCoord x, wxCoord y , wxCoord r )
-{
- CGPathAddArc( m_path , NULL , x , y , r , 0.0 , 2 * M_PI , true ) ;
-}
-
-// closes the current subpath
-void wxMacCGPath::CloseSubpath()
-{
- CGPathCloseSubpath( m_path ) ;
-}
-
-CGPathRef wxMacCGPath::GetPath() const
-{
- return m_path ;
-}
-
-void wxMacCGPath::AddArcToPoint( wxCoord x1, wxCoord y1 , wxCoord x2, wxCoord y2, wxCoord r )
-{
- CGPathAddArcToPoint( m_path, NULL , x1, y1, x2, y2, r);
-}
-
-void wxMacCGPath::AddArc( wxCoord x, wxCoord y, wxCoord r, double startAngle, double endAngle, bool clockwise )
-{
- CGPathAddArc( m_path, NULL , x, y, r, startAngle, endAngle, clockwise);
-}
-
-//-----------------------------------------------------------------------------
-// wxGraphicContext implementation
-//-----------------------------------------------------------------------------
-
-wxMacCGContext::wxMacCGContext( CGrafPtr port )
-{
- m_qdPort = port ;
- m_cgContext = NULL ;
- m_mode = kCGPathFill;
- m_macATSUIStyle = NULL ;
-}
-
-wxMacCGContext::wxMacCGContext( CGContextRef cgcontext )
-{
- m_qdPort = NULL ;
- m_cgContext = cgcontext ;
- m_mode = kCGPathFill;
- m_macATSUIStyle = NULL ;
- CGContextSaveGState( m_cgContext ) ;
- CGContextSaveGState( m_cgContext ) ;
-}
-
-wxMacCGContext::wxMacCGContext()
-{
- m_qdPort = NULL ;
- m_cgContext = NULL ;
- m_mode = kCGPathFill;
- m_macATSUIStyle = NULL ;
-}
-
-wxMacCGContext::~wxMacCGContext()
-{
- if ( m_cgContext )
- {
- CGContextSynchronize( m_cgContext ) ;
- CGContextRestoreGState( m_cgContext ) ;
- CGContextRestoreGState( m_cgContext ) ;
- }
-#ifndef __LP64__
- if ( m_qdPort )
- QDEndCGContext( m_qdPort, &m_cgContext ) ;
-#endif
-}
-
-
-void wxMacCGContext::Clip( const wxRegion ®ion )
-{
-// ClipCGContextToRegion ( m_cgContext, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ) ;
-}
-
-void wxMacCGContext::StrokePath( const wxGraphicPath *p )
-{
- const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ;
-
- int width = m_pen.GetWidth();
- if ( width == 0 )
- width = 1 ;
- if ( m_pen.GetStyle() == wxTRANSPARENT )
- width = 0 ;
-
- bool offset = ( width % 2 ) == 1 ;
-
- if ( offset )
- CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );
-
- CGContextAddPath( m_cgContext , path->GetPath() ) ;
- CGContextStrokePath( m_cgContext ) ;
-
- if ( offset )
- CGContextTranslateCTM( m_cgContext, -0.5, -0.5 );
-}
-
-void wxMacCGContext::DrawPath( const wxGraphicPath *p , int fillStyle )
-{
- const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ;
- CGPathDrawingMode mode = m_mode ;
-
- if ( fillStyle == wxODDEVEN_RULE )
- {
- if ( mode == kCGPathFill )
- mode = kCGPathEOFill ;
- else if ( mode == kCGPathFillStroke )
- mode = kCGPathEOFillStroke ;
- }
-
- int width = m_pen.GetWidth();
- if ( width == 0 )
- width = 1 ;
- if ( m_pen.GetStyle() == wxTRANSPARENT )
- width = 0 ;
-
- bool offset = ( width % 2 ) == 1 ;
-
- if ( offset )
- CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );
-
- CGContextAddPath( m_cgContext , path->GetPath() ) ;
- CGContextDrawPath( m_cgContext , mode ) ;
-
- if ( offset )
- CGContextTranslateCTM( m_cgContext, -0.5, -0.5 );
-}
-
-void wxMacCGContext::FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle )
-{
- const wxMacCGPath* path = dynamic_cast< const wxMacCGPath*>( p ) ;
- CGContextSaveGState( m_cgContext ) ;
-
- RGBColor col = MAC_WXCOLORREF( fillColor.GetPixel() ) ;
- CGContextSetRGBFillColor( m_cgContext , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
- CGPathDrawingMode mode = kCGPathFill ;
-
- if ( fillStyle == wxODDEVEN_RULE )
- mode = kCGPathEOFill ;
-
- CGContextBeginPath( m_cgContext ) ;
- CGContextAddPath( m_cgContext , path->GetPath() ) ;
- CGContextClosePath( m_cgContext ) ;
- CGContextDrawPath( m_cgContext , mode ) ;
-
- CGContextRestoreGState( m_cgContext ) ;
-}
-
-wxGraphicPath* wxMacCGContext::CreatePath()
-{
- // make sure that we now have a real cgref, before doing
- // anything with paths
- CGContextRef cg = GetNativeContext() ;
- cg = NULL ;
-
- return new wxMacCGPath() ;
-}
-
-// in case we only got a QDPort only create a cgref now
-
-CGContextRef wxMacCGContext::GetNativeContext()
-{
- if ( m_cgContext == NULL )
- {
- Rect bounds ;
- OSStatus status = noErr;
-#ifndef __LP64__
- GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ;
- status = QDBeginCGContext((CGrafPtr) m_qdPort , &m_cgContext) ;
-#endif
- 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 ) ;
-
- CGContextSaveGState( m_cgContext ) ;
- SetPen( m_pen ) ;
- SetBrush( m_brush ) ;
- }
-
- return m_cgContext ;
-}
-
-void wxMacCGContext::SetNativeContext( CGContextRef cg )
-{
- // we allow either setting or clearing but not replacing
- wxASSERT( m_cgContext == NULL || cg == NULL ) ;
-
- if ( cg )
- CGContextSaveGState( cg ) ;
- m_cgContext = cg ;
-}
-
-void wxMacCGContext::Translate( wxCoord dx , wxCoord dy )
-{
- CGContextTranslateCTM( m_cgContext, dx, dy );
-}
-
-void wxMacCGContext::Scale( wxCoord xScale , wxCoord yScale )
-{
- CGContextScaleCTM( m_cgContext , xScale , yScale ) ;
-}
-
-void wxMacCGContext::DrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, wxCoord w, wxCoord h )
-{
- CGImageRef image = (CGImageRef)( bmp.CGImageCreate() ) ;
- HIRect r = CGRectMake( 0 , 0 , w , h );
-
- CGContextSaveGState( m_cgContext );
- CGContextTranslateCTM( m_cgContext, x , y + h );
- CGContextScaleCTM( m_cgContext, 1, -1 );
-
- // in case image is a mask, set the foreground color
- CGContextSetRGBFillColor( m_cgContext , m_textForegroundColor.Red() / 255.0 , m_textForegroundColor.Green() / 255.0 ,
- m_textForegroundColor.Blue() / 255.0 , m_textForegroundColor.Alpha() / 255.0 ) ;
- CGContextDrawImage( m_cgContext, r, image );
- CGContextRestoreGState( m_cgContext );
-
- CGImageRelease( image ) ;
-}
-
-void wxMacCGContext::DrawIcon( const wxIcon &icon, wxCoord x, wxCoord y, wxCoord w, wxCoord h )
-{
- CGRect r = CGRectMake( 0 , 0 , w , h ) ;
- CGContextSaveGState( m_cgContext );
- CGContextTranslateCTM( m_cgContext, x , y + h );
- CGContextScaleCTM( m_cgContext, 1, -1 );
- PlotIconRefInContext( m_cgContext , &r , kAlignNone , kTransformNone ,
- NULL , kPlotIconRefNormalFlags , MAC_WXHICON( icon.GetHICON() ) ) ;
- CGContextRestoreGState( m_cgContext ) ;
-}
-
-void wxMacCGContext::PushState()
-{
- CGContextSaveGState( m_cgContext );
-}
-
-void wxMacCGContext::PopState()
-{
- CGContextRestoreGState( m_cgContext );
-}
-
-void wxMacCGContext::SetTextColor( const wxColour &col )
-{
- m_textForegroundColor = col ;
-}
-
-#pragma mark -
-#pragma mark wxMacCGPattern, ImagePattern, HatchPattern classes
-
-// CGPattern wrapper class: always allocate on heap, never call destructor
-
-class wxMacCGPattern
-{
-public :
- wxMacCGPattern() {}
-
- // is guaranteed to be called only with a non-Null CGContextRef
- virtual void Render( CGContextRef ctxRef ) = 0 ;
-
- operator CGPatternRef() const { return m_patternRef ; }
-
-protected :
- virtual ~wxMacCGPattern()
- {
- // as this is called only when the m_patternRef is been released;
- // don't release it again
- }
-
- static void _Render( void *info, CGContextRef ctxRef )
- {
- wxMacCGPattern* self = (wxMacCGPattern*) info ;
- if ( self && ctxRef )
- self->Render( ctxRef ) ;
- }
-
- static void _Dispose( void *info )
- {
- wxMacCGPattern* self = (wxMacCGPattern*) info ;
- delete self ;
- }
-
- CGPatternRef m_patternRef ;
-
- static const CGPatternCallbacks ms_Callbacks ;
-} ;
-
-const CGPatternCallbacks wxMacCGPattern::ms_Callbacks = { 0, &wxMacCGPattern::_Render, &wxMacCGPattern::_Dispose };
-
-class ImagePattern : public wxMacCGPattern
-{
-public :
- ImagePattern( const wxBitmap* bmp , const CGAffineTransform& transform )
- {
- wxASSERT( bmp && bmp->Ok() ) ;
-
- Init( (CGImageRef) bmp->CGImageCreate() , transform ) ;
- }
-
- // ImagePattern takes ownership of CGImageRef passed in
- ImagePattern( CGImageRef image , const CGAffineTransform& transform )
- {
- if ( image )
- CFRetain( image ) ;
-
- Init( image , transform ) ;
- }
-
- virtual void Render( CGContextRef ctxRef )
- {
- if (m_image != NULL)
- HIViewDrawCGImage( ctxRef, &m_imageBounds, m_image );
- }
-
-protected :
- void Init( CGImageRef image, const CGAffineTransform& transform )
- {
- m_image = image ;
- if ( m_image )
- {
- m_imageBounds = CGRectMake( 0.0, 0.0, (CGFloat)CGImageGetWidth( m_image ), (CGFloat)CGImageGetHeight( m_image ) ) ;
- m_patternRef = CGPatternCreate(
- this , m_imageBounds, transform ,
- m_imageBounds.size.width, m_imageBounds.size.height,
- kCGPatternTilingNoDistortion, true , &wxMacCGPattern::ms_Callbacks ) ;
- }
- }
-
- virtual ~ImagePattern()
- {
- if ( m_image )
- CGImageRelease( m_image ) ;
- }
-
- CGImageRef m_image ;
- CGRect m_imageBounds ;
-} ;
-
-class HatchPattern : public wxMacCGPattern
-{
-public :
- HatchPattern( int hatchstyle, const CGAffineTransform& transform )
- {
- m_hatch = hatchstyle ;
- m_imageBounds = CGRectMake( 0.0, 0.0, 8.0 , 8.0 ) ;
- m_patternRef = CGPatternCreate(
- this , m_imageBounds, transform ,
- m_imageBounds.size.width, m_imageBounds.size.height,
- kCGPatternTilingNoDistortion, false , &wxMacCGPattern::ms_Callbacks ) ;
- }
-
- void StrokeLineSegments( CGContextRef ctxRef , const CGPoint pts[] , size_t count )
- {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- CGContextStrokeLineSegments( ctxRef , pts , count ) ;
- }
- else
-#endif
- {
- CGContextBeginPath( ctxRef );
- 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);
- }
- CGContextStrokePath(ctxRef);
- }
- }
-
- virtual void Render( CGContextRef ctxRef )
- {
- switch ( m_hatch )
- {
- case wxBDIAGONAL_HATCH :
- {
- CGPoint pts[] =
- {
- { 8.0 , 0.0 } , { 0.0 , 8.0 }
- };
- StrokeLineSegments( ctxRef , pts , 2 ) ;
- }
- break ;
-
- case wxCROSSDIAG_HATCH :
- {
- CGPoint pts[] =
- {
- { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
- { 8.0 , 0.0 } , { 0.0 , 8.0 }
- };
- StrokeLineSegments( ctxRef , pts , 4 ) ;
- }
- break ;
-
- case wxFDIAGONAL_HATCH :
- {
- CGPoint pts[] =
- {
- { 0.0 , 0.0 } , { 8.0 , 8.0 }
- };
- StrokeLineSegments( ctxRef , pts , 2 ) ;
- }
- break ;
-
- case wxCROSS_HATCH :
- {
- CGPoint pts[] =
- {
- { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
- { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
- };
- StrokeLineSegments( ctxRef , pts , 4 ) ;
- }
- break ;
-
- case wxHORIZONTAL_HATCH :
- {
- CGPoint pts[] =
- {
- { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
- };
- StrokeLineSegments( ctxRef , pts , 2 ) ;
- }
- break ;
-
- case wxVERTICAL_HATCH :
- {
- CGPoint pts[] =
- {
- { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
- };
- StrokeLineSegments( ctxRef , pts , 2 ) ;
- }
- break ;
-
- default:
- break;
- }
- }
-
-protected :
- virtual ~HatchPattern() {}
-
- CGRect m_imageBounds ;
- int m_hatch ;
-};
-
-#pragma mark -
-
-void wxMacCGContext::SetPen( const wxPen &pen )
-{
- m_pen = pen ;
- if ( m_cgContext == NULL )
- return ;
-
- bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
- bool stroke = pen.GetStyle() != wxTRANSPARENT ;
-
-#if 0
- // we can benchmark performance; should go into a setting eventually
- CGContextSetShouldAntialias( m_cgContext , false ) ;
#endif
-
- if ( fill || stroke )
- {
- // set up brushes
- m_mode = kCGPathFill ; // just a default
-
- if ( stroke )
- {
- CGContextSetRGBStrokeColor( m_cgContext , pen.GetColour().Red() / 255.0 , pen.GetColour().Green() / 255.0 ,
- pen.GetColour().Blue() / 255.0 , pen.GetColour().Alpha() / 255.0 ) ;
-
- // TODO: * m_dc->m_scaleX
- CGFloat penWidth = pen.GetWidth();
- if (penWidth <= 0.0)
- penWidth = 0.1;
- CGContextSetLineWidth( m_cgContext , penWidth ) ;
-
- CGLineCap cap ;
- switch ( pen.GetCap() )
- {
- case wxCAP_ROUND :
- cap = kCGLineCapRound ;
- break ;
-
- case wxCAP_PROJECTING :
- cap = kCGLineCapSquare ;
- break ;
-
- case wxCAP_BUTT :
- cap = kCGLineCapButt ;
- break ;
-
- default :
- cap = kCGLineCapButt ;
- break ;
- }
-
- CGLineJoin join ;
- switch ( pen.GetJoin() )
- {
- case wxJOIN_BEVEL :
- join = kCGLineJoinBevel ;
- break ;
-
- case wxJOIN_MITER :
- join = kCGLineJoinMiter ;
- break ;
-
- case wxJOIN_ROUND :
- join = kCGLineJoinRound ;
- break ;
-
- default :
- join = kCGLineJoinMiter ;
- break;
- }
-
- m_mode = kCGPathStroke ;
- int count = 0 ;
-
- const CGFloat *lengths = NULL ;
- CGFloat *userLengths = NULL ;
-
- const CGFloat dashUnit = penWidth < 1.0 ? 1.0 : penWidth;
-
- const CGFloat dotted[] = { dashUnit , dashUnit + 2.0 };
- const CGFloat short_dashed[] = { 9.0 , 6.0 };
- const CGFloat dashed[] = { 19.0 , 9.0 };
- const CGFloat dotted_dashed[] = { 9.0 , 6.0 , 3.0 , 3.0 };
-
- switch ( pen.GetStyle() )
- {
- case wxSOLID :
- break ;
-
- case wxDOT :
- lengths = dotted ;
- count = WXSIZEOF(dotted);
- break ;
-
- case wxLONG_DASH :
- lengths = dashed ;
- count = WXSIZEOF(dashed) ;
- break ;
-
- case wxSHORT_DASH :
- lengths = short_dashed ;
- count = WXSIZEOF(short_dashed) ;
- break ;
-
- case wxDOT_DASH :
- lengths = dotted_dashed ;
- count = WXSIZEOF(dotted_dashed);
- break ;
-
- case wxUSER_DASH :
- wxDash *dashes ;
- count = pen.GetDashes( &dashes ) ;
- if ((dashes != NULL) && (count > 0))
- {
- userLengths = new CGFloat[count] ;
- for ( int i = 0 ; i < count ; ++i )
- {
- userLengths[i] = dashes[i] * dashUnit ;
-
- if ( i % 2 == 1 && userLengths[i] < dashUnit + 2.0 )
- userLengths[i] = dashUnit + 2.0 ;
- else if ( i % 2 == 0 && userLengths[i] < dashUnit )
- userLengths[i] = dashUnit ;
- }
- }
- lengths = userLengths ;
- break ;
-
- case wxSTIPPLE :
- {
- CGFloat alphaArray[1] = { 1.0 } ;
- wxBitmap* bmp = pen.GetStipple() ;
- if ( bmp && bmp->Ok() )
- {
- wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( NULL ) ) ;
- CGContextSetStrokeColorSpace( m_cgContext , patternSpace ) ;
- wxMacCFRefHolder<CGPatternRef> pattern( *( new ImagePattern( bmp , CGContextGetCTM( m_cgContext ) ) ) );
- CGContextSetStrokePattern( m_cgContext, pattern , alphaArray ) ;
- }
- }
- break ;
-
- default :
- {
- wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
- CGContextSetStrokeColorSpace( m_cgContext , patternSpace ) ;
- wxMacCFRefHolder<CGPatternRef> pattern( *( new HatchPattern( pen.GetStyle() , CGContextGetCTM( m_cgContext ) ) ) );
-
- CGFloat colorArray[4] = { pen.GetColour().Red() / 255.0 , pen.GetColour().Green() / 255.0 ,
- pen.GetColour().Blue() / 255.0 , pen.GetColour().Alpha() / 255.0 } ;
-
- CGContextSetStrokePattern( m_cgContext, pattern , colorArray ) ;
- }
- break ;
- }
-
- if ((lengths != NULL) && (count > 0))
- {
- CGContextSetLineDash( m_cgContext , 0 , lengths , count ) ;
- // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
- cap = kCGLineCapButt ;
- }
- else
- {
- CGContextSetLineDash( m_cgContext , 0 , NULL , 0 ) ;
- }
-
- CGContextSetLineCap( m_cgContext , cap ) ;
- CGContextSetLineJoin( m_cgContext , join ) ;
-
- delete[] userLengths ;
- }
-
- if ( fill && stroke )
- m_mode = kCGPathFillStroke ;
- }
-}
-
-void wxMacCGContext::SetBrush( const wxBrush &brush )
-{
- m_brush = brush ;
- if ( m_cgContext == NULL )
- return ;
-
- bool fill = brush.GetStyle() != wxTRANSPARENT ;
- bool stroke = m_pen.GetStyle() != wxTRANSPARENT ;
-
-#if 0
- // we can benchmark performance, should go into a setting later
- CGContextSetShouldAntialias( m_cgContext , false ) ;
-#endif
-
- if ( fill || stroke )
- {
- // setup brushes
- m_mode = kCGPathFill ; // just a default
-
- if ( fill )
- {
- if ( brush.GetStyle() == wxSOLID )
- {
- CGContextSetRGBFillColor( m_cgContext , brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 ,
- brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 ) ;
- }
- else if ( brush.IsHatch() )
- {
- wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) ) ;
- CGContextSetFillColorSpace( m_cgContext , patternSpace ) ;
- wxMacCFRefHolder<CGPatternRef> pattern( *( new HatchPattern( brush.GetStyle() , CGContextGetCTM( m_cgContext ) ) ) );
-
- CGFloat colorArray[4] = { brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 ,
- brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 } ;
-
- CGContextSetFillPattern( m_cgContext, pattern , colorArray ) ;
- }
- else
- {
- // now brush is a bitmap
- CGFloat alphaArray[1] = { 1.0 } ;
- wxBitmap* bmp = brush.GetStipple() ;
- if ( bmp && bmp->Ok() )
- {
- wxMacCFRefHolder<CGColorSpaceRef> patternSpace( CGColorSpaceCreatePattern( NULL ) ) ;
- CGContextSetFillColorSpace( m_cgContext , patternSpace ) ;
- wxMacCFRefHolder<CGPatternRef> pattern( *( new ImagePattern( bmp , CGContextGetCTM( m_cgContext ) ) ) );
- CGContextSetFillPattern( m_cgContext, pattern , alphaArray ) ;
- }
- }
-
- m_mode = kCGPathFill ;
- }
-
- if ( fill && stroke )
- m_mode = kCGPathFillStroke ;
- else if ( stroke )
- m_mode = kCGPathStroke ;
- }
-}
-
-void wxMacCGContext::DrawText( const wxString &str, wxCoord x, wxCoord y, double angle )
-{
- OSStatus status = noErr ;
- ATSUTextLayout atsuLayout ;
- UniCharCount chars = str.length() ;
- UniChar* ubuf = NULL ;
-
-#if SIZEOF_WCHAR_T == 4
- 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 ) ;
-#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 ) ;
-#endif
- chars = unicharlen / 2 ;
-#else
-#if wxUSE_UNICODE
- ubuf = (UniChar*) str.wc_str() ;
-#else
- wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
- chars = wxWcslen( wchar.data() ) ;
- ubuf = (UniChar*) wchar.data() ;
-#endif
-#endif
-
- status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
-
- wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
-
- status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
- wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
-
- int iAngle = int( angle );
- if ( abs(iAngle) > 0 )
- {
- Fixed atsuAngle = IntToFixed( iAngle ) ;
- ATSUAttributeTag atsuTags[] =
- {
- kATSULineRotationTag ,
- } ;
- ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
- {
- sizeof( Fixed ) ,
- } ;
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
- {
- &atsuAngle ,
- } ;
- status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag),
- atsuTags, atsuSizes, atsuValues ) ;
- }
-
- {
- ATSUAttributeTag atsuTags[] =
- {
- kATSUCGContextTag ,
- } ;
- ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
- {
- sizeof( CGContextRef ) ,
- } ;
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
- {
- &m_cgContext ,
- } ;
- status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag),
- atsuTags, atsuSizes, atsuValues ) ;
- }
-
- ATSUTextMeasurement textBefore, textAfter ;
- ATSUTextMeasurement ascent, descent ;
-
- status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- &textBefore , &textAfter, &ascent , &descent );
-
- wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
-
- Rect rect ;
-/*
- // TODO
- if ( m_backgroundMode == wxSOLID )
- {
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->MoveToPoint( drawX , drawY ) ;
- path->AddLineToPoint(
- (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) ,
- (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ) ;
- path->AddLineToPoint(
- (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
- (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
- path->AddLineToPoint(
- (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
- (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
-
- m_graphicContext->FillPath( path , m_textBackgroundColour ) ;
- delete path ;
- }
-*/
- x += (int)(sin(angle / RAD2DEG) * FixedToInt(ascent));
- y += (int)(cos(angle / RAD2DEG) * FixedToInt(ascent));
-
- status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- IntToFixed(x) , IntToFixed(y) , &rect );
- wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") );
-
- CGContextSaveGState(m_cgContext);
- CGContextTranslateCTM(m_cgContext, x, y);
- CGContextScaleCTM(m_cgContext, 1, -1);
- status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- IntToFixed(0) , IntToFixed(0) );
-
- wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );
-
- CGContextRestoreGState(m_cgContext) ;
-
- ::ATSUDisposeTextLayout(atsuLayout);
-
-#if SIZEOF_WCHAR_T == 4
- free( ubuf ) ;
-#endif
-}
-
-void wxMacCGContext::GetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
- wxCoord *descent, wxCoord *externalLeading ) const
-{
- wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoGetTextExtent - no valid font set") ) ;
-
- OSStatus status = noErr ;
-
- ATSUTextLayout atsuLayout ;
- UniCharCount chars = str.length() ;
- UniChar* ubuf = NULL ;
-
-#if SIZEOF_WCHAR_T == 4
- 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 ) ;
-#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 ) ;
-#endif
- chars = unicharlen / 2 ;
-#else
-#if wxUSE_UNICODE
- ubuf = (UniChar*) str.wc_str() ;
-#else
- wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
- chars = wxWcslen( wchar.data() ) ;
- ubuf = (UniChar*) wchar.data() ;
-#endif
-#endif
-
- status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
-
- wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
-
- ATSUTextMeasurement textBefore, textAfter ;
- ATSUTextMeasurement textAscent, textDescent ;
-
- status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- &textBefore , &textAfter, &textAscent , &textDescent );
-
- if ( height )
- *height = FixedToInt(textAscent + textDescent) ;
- if ( descent )
- *descent = FixedToInt(textDescent) ;
- if ( externalLeading )
- *externalLeading = 0 ;
- if ( width )
- *width = FixedToInt(textAfter - textBefore) ;
-
- ::ATSUDisposeTextLayout(atsuLayout);
-}
-
-void wxMacCGContext::GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
-{
- widths.Empty();
- widths.Add(0, text.length());
-
- if (text.empty())
- return ;
-
- ATSUTextLayout atsuLayout ;
- UniCharCount chars = text.length() ;
- UniChar* ubuf = NULL ;
-
-#if SIZEOF_WCHAR_T == 4
- wxMBConvUTF16 converter ;
-#if wxUSE_UNICODE
- size_t unicharlen = converter.WC2MB( NULL , text.wc_str() , 0 ) ;
- ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
- converter.WC2MB( (char*) ubuf , text.wc_str(), unicharlen + 2 ) ;
-#else
- const wxWCharBuffer wchar = text.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 ) ;
-#endif
- chars = unicharlen / 2 ;
-#else
-#if wxUSE_UNICODE
- ubuf = (UniChar*) text.wc_str() ;
-#else
- wxWCharBuffer wchar = text.wc_str( wxConvLocal ) ;
- chars = wxWcslen( wchar.data() ) ;
- ubuf = (UniChar*) wchar.data() ;
-#endif
-#endif
-
- ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
-
- for ( int pos = 0; pos < (int)chars; pos ++ )
- {
- unsigned long actualNumberOfBounds = 0;
- ATSTrapezoid glyphBounds;
-
- // We get a single bound, since the text should only require one. If it requires more, there is an issue
- OSStatus result;
- result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1,
- kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds );
- if (result != noErr || actualNumberOfBounds != 1 )
- return ;
-
- widths[pos] = FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x );
- //unsigned char uch = s[i];
- }
-
- ::ATSUDisposeTextLayout(atsuLayout);
-}
-
-void wxMacCGContext::SetFont( const wxFont &font )
-{
- if ( m_macATSUIStyle )
- {
- ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle);
- m_macATSUIStyle = NULL ;
- }
-
- if ( font.Ok() )
- {
- OSStatus status ;
-
- status = ATSUCreateAndCopyStyle( (ATSUStyle) font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ;
-
- wxASSERT_MSG( status == noErr, wxT("couldn't create ATSU style") ) ;
-
- // we need the scale here ...
-
- Fixed atsuSize = IntToFixed( int( /*m_scaleY*/ 1 * font.MacGetFontSize()) ) ;
- RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColor.GetPixel() ) ;
- ATSUAttributeTag atsuTags[] =
- {
- kATSUSizeTag ,
- kATSUColorTag ,
- } ;
- ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
- {
- sizeof( Fixed ) ,
- sizeof( RGBColor ) ,
- } ;
- ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
- {
- &atsuSize ,
- &atsuColor ,
- } ;
-
- status = ::ATSUSetAttributes(
- (ATSUStyle)m_macATSUIStyle, sizeof(atsuTags) / sizeof(ATSUAttributeTag) ,
- atsuTags, atsuSizes, atsuValues);
-
- wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ) ;
- }
-}
-
-
-#pragma mark -
-
-wxDC::wxDC()
-{
- m_ok = false ;
- m_colour = true;
- m_mm_to_pix_x = mm2pt;
- m_mm_to_pix_y = mm2pt;
-
- m_externalDeviceOriginX = 0;
- m_externalDeviceOriginY = 0;
- m_logicalScaleX = 1.0;
- m_logicalScaleY = 1.0;
- m_userScaleX = 1.0;
- m_userScaleY = 1.0;
- m_scaleX = 1.0;
- m_scaleY = 1.0;
- m_needComputeScaleX =
- m_needComputeScaleY = false;
-
- m_macPort = 0 ;
- m_macLocalOrigin.x =
- m_macLocalOrigin.y = 0 ;
-
- m_pen = *wxBLACK_PEN;
- m_font = *wxNORMAL_FONT;
- m_brush = *wxWHITE_BRUSH;
-
- m_macATSUIStyle = NULL ;
- m_graphicContext = NULL ;
-}
-
-wxDC::~wxDC()
-{
- if ( m_macATSUIStyle )
- {
- ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle);
- m_macATSUIStyle = NULL ;
- }
-
- delete m_graphicContext ;
-}
-
-void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid DC") );
- wxCHECK_RET( bmp.Ok(), wxT("wxDC(cg)::DoDrawBitmap - invalid bitmap") );
-
- wxCoord xx = XLOG2DEVMAC(x);
- wxCoord yy = YLOG2DEVMAC(y);
- wxCoord w = bmp.GetWidth();
- wxCoord h = bmp.GetHeight();
- wxCoord ww = XLOG2DEVREL(w);
- wxCoord hh = YLOG2DEVREL(h);
-
- if ( bmp.GetDepth()==1 )
- {
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->AddRectangle( xx , yy , ww , hh ) ;
- m_graphicContext->FillPath( path , m_textBackgroundColour, wxODDEVEN_RULE) ;
- delete path;
- m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ;
- }
- else
- {
- m_graphicContext->DrawBitmap( bmp, xx , yy , ww , hh ) ;
- }
-}
-
-void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid DC") );
- wxCHECK_RET( icon.Ok(), wxT("wxDC(cg)::DoDrawIcon - invalid icon") );
-
- wxCoord xx = XLOG2DEVMAC(x);
- wxCoord yy = YLOG2DEVMAC(y);
- wxCoord w = icon.GetWidth();
- wxCoord h = icon.GetHeight();
- wxCoord ww = XLOG2DEVREL(w);
- wxCoord hh = YLOG2DEVREL(h);
-
- m_graphicContext->DrawIcon( icon , xx, yy, ww, hh ) ;
-}
-
-void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegion - invalid DC") );
-
- wxCoord xx, yy, ww, hh;
- xx = XLOG2DEVMAC(x);
- yy = YLOG2DEVMAC(y);
- ww = XLOG2DEVREL(width);
- hh = YLOG2DEVREL(height);
-
- CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
- CGRect clipRect = CGRectMake( xx , yy , ww, hh ) ;
- CGContextClipToRect( cgContext , clipRect ) ;
-
-// 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;
- }
-
- // TODO: as soon as we don't reset the context for each operation anymore
- // we have to update the context as well
-}
-
-void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoSetClippingRegionAsRegion - invalid DC") );
-
- 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
- {
- 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()
-{
- CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
- CGContextRestoreGState( cgContext );
- CGContextSaveGState( cgContext );
-
- m_graphicContext->SetPen( m_pen ) ;
- m_graphicContext->SetBrush( m_brush ) ;
-
- m_clipping = false;
-}
-
-void wxDC::DoGetSizeMM( int* width, int* height ) const
-{
- int w = 0, h = 0;
-
- GetSize( &w, &h );
- 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("wxDC(cg)::SetTextForeground - invalid DC") );
-
- if ( col != m_textForegroundColour )
- {
- m_textForegroundColour = col;
- m_graphicContext->SetTextColor( col );
- // in the current implementation the font contains the text color
- m_graphicContext->SetFont(m_font);
- }
-}
-
-void wxDC::SetTextBackground( const wxColour &col )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::SetTextBackground - invalid DC") );
-
- m_textBackgroundColour = col;
-}
-
-void wxDC::SetMapMode( int mode )
-{
- switch (mode)
- {
- case wxMM_TWIPS:
- 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 );
- break;
-
- case wxMM_METRIC:
- SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
- break;
-
- case wxMM_LOMETRIC:
- SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 );
- break;
-
- case wxMM_TEXT:
- default:
- SetLogicalScale( 1.0, 1.0 );
- break;
- }
-
- if (mode != wxMM_TEXT)
- {
- m_needComputeScaleX =
- m_needComputeScaleY = true;
- }
-}
-
-void wxDC::SetUserScale( double x, double y )
-{
- // allow negative ? -> no
- m_userScaleX = x;
- m_userScaleY = y;
- ComputeScaleAndOrigin();
-}
-
-void wxDC::SetLogicalScale( double x, double y )
-{
- // allow negative ?
- m_logicalScaleX = x;
- m_logicalScaleY = y;
- ComputeScaleAndOrigin();
-}
-
-void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
-{
- m_logicalOriginX = x * m_signX; // is this still correct ?
- m_logicalOriginY = y * m_signY;
- ComputeScaleAndOrigin();
-}
-
-void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
-{
- m_externalDeviceOriginX = x;
- m_externalDeviceOriginY = y;
- ComputeScaleAndOrigin();
-}
-
-void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
-{
- m_signX = (xLeftRight ? 1 : -1);
- m_signY = (yBottomUp ? -1 : 1);
- ComputeScaleAndOrigin();
-}
-
-wxSize wxDC::GetPPI() const
-{
- return wxSize(72, 72);
-}
-
-int wxDC::GetDepth() const
-{
- return 32;
-}
-
-void wxDC::ComputeScaleAndOrigin()
-{
- // CMB: copy scale to see if it changes
- double origScaleX = m_scaleX;
- double origScaleY = m_scaleY;
- m_scaleX = m_logicalScaleX * m_userScaleX;
- m_scaleY = m_logicalScaleY * m_userScaleY;
- m_deviceOriginX = m_externalDeviceOriginX;
- m_deviceOriginY = m_externalDeviceOriginY;
-
- // CMB: if scale has changed call SetPen to recalulate the line width
- if (m_scaleX != origScaleX || m_scaleY != origScaleY)
- {
- // this is a bit artificial, but we need to force wxDC to think
- // the pen has changed
- wxPen pen( GetPen() );
-
- m_pen = wxNullPen;
- SetPen( pen );
- }
-}
-
-void wxDC::SetPalette( const wxPalette& palette )
-{
-}
-
-void wxDC::SetBackgroundMode( int mode )
-{
- m_backgroundMode = mode ;
-}
-
-void wxDC::SetFont( const wxFont &font )
-{
- m_font = font;
- if ( m_graphicContext )
- m_graphicContext->SetFont( font ) ;
-}
-
-void wxDC::SetPen( const wxPen &pen )
-{
- if ( m_pen == pen )
- return ;
-
- m_pen = pen;
- if ( m_graphicContext )
- {
- if ( m_pen.GetStyle() == wxSOLID || m_pen.GetStyle() == wxTRANSPARENT )
- {
- m_graphicContext->SetPen( m_pen ) ;
- }
- else
- {
- // we have to compensate for moved device origins etc. otherwise patterned pens are standing still
- // eg when using a wxScrollWindow and scrolling around
- int origX = XLOG2DEVMAC( 0 ) ;
- int origY = YLOG2DEVMAC( 0 ) ;
- m_graphicContext->Translate( origX , origY ) ;
- m_graphicContext->SetPen( m_pen ) ;
- m_graphicContext->Translate( -origX , -origY ) ;
- }
- }
-}
-
-void wxDC::SetBrush( const wxBrush &brush )
-{
- if (m_brush == brush)
- return;
-
- m_brush = brush;
- if ( m_graphicContext )
- {
- if ( brush.GetStyle() == wxSOLID || brush.GetStyle() == wxTRANSPARENT )
- {
- m_graphicContext->SetBrush( m_brush ) ;
- }
- else
- {
- // we have to compensate for moved device origins etc. otherwise patterned brushes are standing still
- // eg when using a wxScrollWindow and scrolling around
- int origX = XLOG2DEVMAC(0) ;
- int origY = YLOG2DEVMAC(0) ;
- m_graphicContext->Translate( origX , origY ) ;
- m_graphicContext->SetBrush( m_brush ) ;
- m_graphicContext->Translate( -origX , -origY ) ;
- }
- }
-}
-
-void wxDC::SetBackground( const wxBrush &brush )
-{
- if (m_backgroundBrush == brush)
- return;
-
- m_backgroundBrush = brush;
- if (!m_backgroundBrush.Ok())
- return;
-}
-
-void wxDC::SetLogicalFunction( int function )
-{
- if (m_logicalFunction == function)
- return;
-
- m_logicalFunction = function ;
-#if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
- CGContextRef cgContext = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
- if ( m_logicalFunction == wxCOPY )
- CGContextSetBlendMode( cgContext, kCGBlendModeNormal ) ;
- else if ( m_logicalFunction == wxINVERT )
- CGContextSetBlendMode( cgContext, kCGBlendModeExclusion ) ;
- else
- CGContextSetBlendMode( cgContext, kCGBlendModeNormal ) ;
-#endif
-}
-
-extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
- const wxColour & col, int style);
-
-bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
- const wxColour& col, int style)
-{
- return wxDoFloodFill(this, x, y, col, style);
-}
-
-bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const
-{
- wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPixel - invalid DC") );
-
- 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 = colour;
-
- return true ;
-}
-
-void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLine - invalid DC") );
-
-#if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
- if ( m_logicalFunction != wxCOPY )
- return ;
-#endif
-
- wxCoord xx1 = XLOG2DEVMAC(x1) ;
- wxCoord yy1 = YLOG2DEVMAC(y1) ;
- wxCoord xx2 = XLOG2DEVMAC(x2) ;
- wxCoord yy2 = YLOG2DEVMAC(y2) ;
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->MoveToPoint( xx1, yy1 ) ;
- path->AddLineToPoint( xx2 , yy2 ) ;
- path->CloseSubpath() ;
- m_graphicContext->StrokePath( path ) ;
- delete path ;
-
- CalcBoundingBox(x1, y1);
- CalcBoundingBox(x2, y2);
-}
-
-void wxDC::DoCrossHair( wxCoord x, wxCoord y )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoCrossHair - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- int w = 0, h = 0;
-
- GetSize( &w, &h );
- wxCoord xx = XLOG2DEVMAC(x);
- wxCoord yy = YLOG2DEVMAC(y);
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->MoveToPoint( XLOG2DEVMAC(0), yy ) ;
- path->AddLineToPoint( XLOG2DEVMAC(w), yy ) ;
- path->CloseSubpath() ;
- path->MoveToPoint( xx, YLOG2DEVMAC(0) ) ;
- path->AddLineToPoint( xx, YLOG2DEVMAC(h) ) ;
- path->CloseSubpath() ;
- m_graphicContext->StrokePath( path ) ;
- delete path ;
-
- CalcBoundingBox(x, y);
- CalcBoundingBox(x + w, y + h);
-}
-
-void wxDC::DoDrawArc( wxCoord x1, wxCoord y1,
- wxCoord x2, wxCoord y2,
- wxCoord xc, wxCoord yc )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawArc - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- wxCoord xx1 = XLOG2DEVMAC(x1);
- wxCoord yy1 = YLOG2DEVMAC(y1);
- wxCoord xx2 = XLOG2DEVMAC(x2);
- 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;
- double sa, ea;
- if (xx1 == xx2 && yy1 == yy2)
- {
- sa = 0.0;
- ea = 360.0;
- }
- else if (radius == 0.0)
- {
- sa = ea = 0.0;
- }
- else
- {
- sa = (xx1 - xxc == 0) ?
- (yy1 - yyc < 0) ? 90.0 : -90.0 :
- -atan2(double(yy1 - yyc), double(xx1 - xxc)) * RAD2DEG;
- ea = (xx2 - xxc == 0) ?
- (yy2 - yyc < 0) ? 90.0 : -90.0 :
- -atan2(double(yy2 - yyc), double(xx2 - xxc)) * RAD2DEG;
- }
-
- bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- m_graphicContext->PushState() ;
- m_graphicContext->Translate( xxc, yyc ) ;
- m_graphicContext->Scale( 1, -1 ) ;
- if ( fill )
- path->MoveToPoint( 0, 0 ) ;
- path->AddArc( 0, 0, rad , DegToRad(sa) , DegToRad(ea), false ) ;
- if ( fill )
- path->AddLineToPoint( 0, 0 ) ;
- m_graphicContext->DrawPath( path ) ;
- m_graphicContext->PopState() ;
- delete path ;
-}
-
-void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h,
- double sa, double ea )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipticArc - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
- }
-
- bool fill = m_brush.GetStyle() != wxTRANSPARENT ;
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- m_graphicContext->PushState() ;
- m_graphicContext->Translate( xx + ww / 2, yy + hh / 2 ) ;
- m_graphicContext->Scale( 1 * ww / 2 , -1 * hh / 2 ) ;
- if ( fill )
- path->MoveToPoint( 0, 0 ) ;
- path->AddArc( 0, 0, 1 , DegToRad(sa) , DegToRad(ea), false ) ;
- if ( fill )
- path->AddLineToPoint( 0, 0 ) ;
- m_graphicContext->DrawPath( path ) ;
- m_graphicContext->PopState() ;
- delete path ;
-}
-
-void wxDC::DoDrawPoint( wxCoord x, wxCoord y )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPoint - invalid DC") );
-
- DoDrawLine( x , y , x + 1 , y + 1 ) ;
-}
-
-void wxDC::DoDrawLines(int n, wxPoint points[],
- wxCoord xoffset, wxCoord yoffset)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawLines - invalid DC") );
-
-#if !wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
- if ( m_logicalFunction != wxCOPY )
- return ;
-#endif
-
- wxCoord x1, x2 , y1 , y2 ;
- x1 = XLOG2DEVMAC(points[0].x + xoffset);
- y1 = YLOG2DEVMAC(points[0].y + yoffset);
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->MoveToPoint( x1 , y1 ) ;
- for (int i = 1; i < n; i++)
- {
- x2 = XLOG2DEVMAC(points[i].x + xoffset);
- y2 = YLOG2DEVMAC(points[i].y + yoffset);
-
- path->AddLineToPoint( x2 , y2 ) ;
- }
-
- m_graphicContext->StrokePath( path ) ;
- delete path ;
-}
-
-#if wxUSE_SPLINES
-void wxDC::DoDrawSpline(wxList *points)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawSpline - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
-
- wxList::compatibility_iterator node = points->GetFirst();
- if (node == wxList::compatibility_iterator())
- // empty list
- return;
-
- wxPoint *p = (wxPoint *)node->GetData();
-
- wxCoord x1 = p->x;
- wxCoord y1 = p->y;
-
- node = node->GetNext();
- p = (wxPoint *)node->GetData();
-
- wxCoord x2 = p->x;
- wxCoord y2 = p->y;
- wxCoord cx1 = ( x1 + x2 ) / 2;
- wxCoord cy1 = ( y1 + y2 ) / 2;
-
- path->MoveToPoint( XLOG2DEVMAC( x1 ) , YLOG2DEVMAC( y1 ) ) ;
- path->AddLineToPoint( XLOG2DEVMAC( cx1 ) , YLOG2DEVMAC( cy1 ) ) ;
-
-#if !wxUSE_STL
- while ((node = node->GetNext()) != NULL)
-#else
- while ((node = node->GetNext()))
-#endif // !wxUSE_STL
- {
- p = (wxPoint *)node->GetData();
- x1 = x2;
- y1 = y2;
- x2 = p->x;
- y2 = p->y;
- wxCoord cx4 = (x1 + x2) / 2;
- wxCoord cy4 = (y1 + y2) / 2;
-
- path->AddQuadCurveToPoint(
- XLOG2DEVMAC( x1 ) , YLOG2DEVMAC( y1 ) ,
- XLOG2DEVMAC( cx4 ) , YLOG2DEVMAC( cy4 ) ) ;
-
- cx1 = cx4;
- cy1 = cy4;
- }
-
- path->AddLineToPoint( XLOG2DEVMAC( x2 ) , YLOG2DEVMAC( y2 ) ) ;
-
- m_graphicContext->StrokePath( path ) ;
- delete path ;
-}
-#endif
-
-void wxDC::DoDrawPolygon( int n, wxPoint points[],
- wxCoord xoffset, wxCoord yoffset,
- int fillStyle )
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawPolygon - invalid DC") );
-
- 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);
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- path->MoveToPoint( x1 , y1 ) ;
- for (int i = 1; i < n; i++)
- {
- x2 = XLOG2DEVMAC(points[i].x + xoffset);
- y2 = YLOG2DEVMAC(points[i].y + yoffset);
-
- path->AddLineToPoint( x2 , y2 ) ;
- }
-
- if ( x1 != x2 || y1 != y2 )
- path->AddLineToPoint( x1, y1 ) ;
-
- path->CloseSubpath() ;
- m_graphicContext->DrawPath( path , fillStyle ) ;
-
- delete path ;
-}
-
-void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRectangle - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
-
- // CMB: handle -ve width and/or height
- if (ww < 0)
- {
- ww = -ww;
- xx = xx - ww;
- }
- if (hh < 0)
- {
- hh = -hh;
- 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() ;
- // 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 ;
-}
-
-void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y,
- wxCoord width, wxCoord height,
- double radius)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRoundedRectangle - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- if (radius < 0.0)
- radius = - radius * ((width < height) ? width : height);
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
-
- // CMB: handle -ve width and/or height
- if (ww < 0)
- {
- ww = -ww;
- xx = xx - ww;
- }
- if (hh < 0)
- {
- hh = -hh;
- yy = yy - hh;
- }
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- if ( radius == 0)
- {
- path->AddRectangle( xx , yy , ww , hh ) ;
- m_graphicContext->DrawPath( path ) ;
- }
- else
- {
- 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 ) ;
- }
- delete path ;
-}
-
-void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawEllipse - invalid DC") );
-
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- wxCoord xx = XLOG2DEVMAC(x);
- 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;
-
- // CMB: handle -ve width and/or height
- if (ww < 0)
- {
- ww = -ww;
- xx = xx - ww;
- }
- if (hh < 0)
- {
- hh = -hh;
- yy = yy - hh;
- }
-
- wxGraphicPath* path = m_graphicContext->CreatePath() ;
- m_graphicContext->PushState() ;
- m_graphicContext->Translate(xx + ww / 2, yy + hh / 2);
- m_graphicContext->Scale(ww / 2 , hh / 2);
- path->AddArc( 0, 0, 1, 0 , 2 * M_PI , false ) ;
- m_graphicContext->DrawPath( path ) ;
- m_graphicContext->PopState() ;
- delete path ;
-}
-
-bool wxDC::CanDrawBitmap() const
-{
- return true ;
-}
-
-bool wxDC::DoBlit(
- wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
- wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask,
- wxCoord xsrcMask, wxCoord ysrcMask )
-{
- return DoStretchBlit( xdest, ydest, width, height,
- source, xsrc, ysrc, width, height,
- logical_func, useMask,
- xsrcMask, ysrcMask );
-}
-
-bool wxDC::DoStretchBlit(wxCoord xdest, wxCoord ydest,
- wxCoord dstWidth, wxCoord dstHeight,
- wxDC *source,
- wxCoord xsrc, wxCoord ysrc,
- wxCoord srcWidth, wxCoord srcHeight,
- int logical_func = wxCOPY, bool useMask = false,
- wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
-{
- wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoStretchBlit - invalid DC") );
- wxCHECK_MSG( source->Ok(), false, wxT("wxDC(cg)::DoStretchBlit - invalid source DC") );
-
- if ( logical_func == wxNO_OP )
- return true ;
-
- if (xsrcMask == -1 && ysrcMask == -1)
- {
- xsrcMask = xsrc;
- ysrcMask = ysrc;
- }
-
- wxCoord yysrc = source->YLOG2DEVMAC(ysrc) ;
- wxCoord xxsrc = source->XLOG2DEVMAC(xsrc) ;
- wxCoord wwsrc = source->XLOG2DEVREL(srcWidth) ;
- wxCoord hhsrc = source->YLOG2DEVREL(srcHeight) ;
-
- wxCoord yydest = YLOG2DEVMAC(ydest) ;
- wxCoord xxdest = XLOG2DEVMAC(xdest) ;
- wxCoord wwdest = XLOG2DEVREL(dstWidth) ;
- wxCoord hhdest = YLOG2DEVREL(dstHeight) ;
-
- wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source) ;
- if ( memdc && logical_func == wxCOPY )
- {
- wxBitmap blit = memdc->GetSelectedObject() ;
-
- wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ) ;
-
- wxCoord bmpwidth = blit.GetWidth();
- wxCoord bmpheight = blit.GetHeight();
-
- if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc )
- {
- wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ) ;
- hhsrc = wxMin( hhsrc , bmpheight - yysrc ) ;
- if ( wwsrc > 0 && hhsrc > 0 )
- {
- if ( xxsrc >= 0 && yysrc >= 0 )
- {
- wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ) ;
- // TODO we perhaps could add a DrawSubBitmap call to dc for performance reasons
- blit = blit.GetSubBitmap( subrect ) ;
- }
- else
- {
- // in this case we'd probably have to adjust the different coordinates, but
- // we have to find out proper contract first
- blit = wxNullBitmap ;
- }
- }
- else
- {
- blit = wxNullBitmap ;
- }
- }
-
- if ( blit.Ok() )
- {
- m_graphicContext->DrawBitmap( blit, xxdest , yydest , wwdest , hhdest ) ;
- }
- }
- else
- {
- wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts, and only with wxCOPY logical operation.") ) ;
- return false ;
- }
-
- return true;
-}
-
-void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
- double angle)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawRotatedText - invalid DC") );
-// wxCHECK_RET( m_macATSUIStyle != NULL, wxT("wxDC(cg)::DoDrawRotatedText - no valid font set") );
-
- if ( str.length() == 0 )
- return ;
- if ( m_logicalFunction != wxCOPY )
- return ;
-
- int drawX = XLOG2DEVMAC(x) ;
- int drawY = YLOG2DEVMAC(y) ;
-
- m_graphicContext->DrawText( str, drawX ,drawY , angle ) ;
-}
-
-void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoDrawText - invalid DC") );
-
- DoDrawRotatedText( strtext , x , y , 0.0 ) ;
-}
-
-bool wxDC::CanGetTextExtent() const
-{
- wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::CanGetTextExtent - invalid DC") );
-
- return true ;
-}
-
-void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
- wxCoord *descent, wxCoord *externalLeading ,
- const wxFont *theFont ) const
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::DoGetTextExtent - invalid DC") );
-
- if ( theFont )
- {
- m_graphicContext->SetFont( *theFont ) ;
- }
-
- wxCoord h , d , e , w ;
-
- m_graphicContext->GetTextExtent( str, &w, &h, &d, &e ) ;
-
- if ( height )
- *height = YDEV2LOGREL( h ) ;
- if ( descent )
- *descent =YDEV2LOGREL( d);
- if ( externalLeading )
- *externalLeading = YDEV2LOGREL( e);
- if ( width )
- *width = XDEV2LOGREL( w ) ;
-
- if ( theFont )
- {
- m_graphicContext->SetFont( m_font ) ;
- }
-}
-
-bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
-{
- wxCHECK_MSG( Ok(), false, wxT("wxDC(cg)::DoGetPartialTextExtents - invalid DC") );
-
- m_graphicContext->GetPartialTextExtents( text, widths ) ;
- for ( size_t i = 0 ; i < widths.GetCount() ; ++i )
- widths[i] = XDEV2LOGREL( widths[i] );
-
- return true;
-}
-
-wxCoord wxDC::GetCharWidth(void) const
-{
- wxCoord width ;
- DoGetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL ) ;
-
- return width ;
-}
-
-wxCoord wxDC::GetCharHeight(void) const
-{
- wxCoord height ;
- DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ) ;
-
- return height ;
-}
-
-void wxDC::Clear(void)
-{
- wxCHECK_RET( Ok(), wxT("wxDC(cg)::Clear - invalid DC") );
-
- if (m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
- {
- HIRect rect = CGRectMake( -10000 , -10000 , 20000 , 20000 ) ;
- CGContextRef cg = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
- switch ( m_backgroundBrush.MacGetBrushKind() )
- {
- case kwxMacBrushTheme :
- {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( HIThemeSetFill != 0 )
- {
- HIThemeSetFill( m_backgroundBrush.MacGetTheme(), NULL, cg, kHIThemeOrientationNormal );
- CGContextFillRect(cg, rect);
-
- }
- else
-#endif
- {
- RGBColor color;
- GetThemeBrushAsColor( m_backgroundBrush.MacGetTheme(), 32, true, &color );
- CGContextSetRGBFillColor( cg, (CGFloat) color.red / 65536,
- (CGFloat) color.green / 65536, (CGFloat) color.blue / 65536, 1 );
- CGContextFillRect( cg, rect );
- }
-
- // reset to normal value
- RGBColor col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
- CGContextSetRGBFillColor( cg, col.red / 65536.0, col.green / 65536.0, col.blue / 65536.0, 1.0 );
- }
- break ;
-
- 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
- HIThemeBackgroundDrawInfo drawInfo ;
- drawInfo.version = 0 ;
- drawInfo.state = kThemeStateActive ;
- drawInfo.kind = m_backgroundBrush.MacGetThemeBackground( NULL ) ;
- if ( drawInfo.kind == kThemeBackgroundMetal )
- {
- HIThemeDrawBackground( &rect, &drawInfo, cg, kHIThemeOrientationNormal ) ;
- HIThemeApplyBackground( &rect, &drawInfo, cg, kHIThemeOrientationNormal ) ;
- }
-#endif
- }
- break ;
-
- case kwxMacBrushColour :
- {
- // FIXME: doesn't correctly render stippled brushes !!
- // FIXME: should this be replaced by ::SetBrush() ??
-
- RGBColor col = MAC_WXCOLORREF( m_backgroundBrush.GetColour().GetPixel()) ;
- CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
- CGContextFillRect(cg, rect);
-
- // reset to normal value
- col = MAC_WXCOLORREF( GetBrush().GetColour().GetPixel() ) ;
- CGContextSetRGBFillColor( cg , col.red / 65536.0 , col.green / 65536.0 , col.blue / 65536.0 , 1.0 ) ;
- }
- break ;
-
- default :
- wxFAIL_MSG( wxT("unknown brush kind") ) ;
- break ;
- }
- }
-}
-
-#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;
- }
-
-wxCoord wxDC::DeviceToLogicalX(wxCoord x) const
-{
- return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX;
-}
-
-wxCoord wxDC::DeviceToLogicalY(wxCoord y) const
-{
- return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY;
-}
-
-wxCoord wxDC::DeviceToLogicalXRel(wxCoord x) const
-{
- return wxRound((double)(x) / m_scaleX);
-}
-
-wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const
-{
- return wxRound((double)(y) / m_scaleY);
-}
-
-wxCoord wxDC::LogicalToDeviceX(wxCoord x) const
-{
- return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX;
-}
-
-wxCoord wxDC::LogicalToDeviceY(wxCoord y) const
-{
- return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY;
-}
-
-wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const
-{
- return wxRound((double)(x) * m_scaleX);
-}
-
-wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const
-{
- return wxRound((double)(y) * m_scaleY);
-}
-*/ // TODO
-#endif // wxMAC_USE_CORE_GRAPHICS
static wxBrush MacGetBackgroundBrush( wxWindow* window )
{
wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
-
-#if !TARGET_API_MAC_OSX
- // transparency cannot be handled by the OS when not using composited windows
- wxWindow* parent = window->GetParent() ;
-
- // if we have some 'pseudo' transparency
- if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
- {
- // walk up until we find something
- while ( parent != NULL )
- {
- if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
- {
- // if we have any other colours in the hierarchy
- bkdBrush.SetColour( parent->GetBackgroundColour() ) ;
- break ;
- }
-
- if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
- {
- bkdBrush = parent->MacGetBackgroundBrush() ;
- break ;
- }
-
- if ( parent->IsKindOf( CLASSINFO( wxNotebook ) )
-#if wxUSE_TAB_DIALOG
- || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )
-#endif // wxUSE_TAB_DIALOG
- )
- {
- Rect extent = { 0 , 0 , 0 , 0 } ;
- int x , y ;
- x = y = 0 ;
- wxSize size = parent->GetSize() ;
- parent->MacClientToRootWindow( &x , &y ) ;
- extent.left = x ;
- extent.top = y ;
- extent.top-- ;
- extent.right = x + size.x ;
- extent.bottom = y + size.y ;
- bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
- break ;
- }
-
- parent = parent->GetParent() ;
- }
- }
-
- if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
- {
- // if we did not find something, use a default
- bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
- }
-#endif
-
return bkdBrush ;
}
wxWindowDC::wxWindowDC()
{
m_window = NULL ;
-#if wxMAC_USE_CORE_GRAPHICS
m_release = false;
-#endif
}
wxWindowDC::wxWindowDC(wxWindow *window)
m_ok = true ;
-#if wxMAC_USE_CORE_GRAPHICS
m_window->GetSize( &m_width , &m_height);
CGContextRef cg = (CGContextRef) window->MacGetCGContextRef();
m_release = false;
SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
}
SetClippingRegion( 0 , 0 , m_width , m_height ) ;
-#else
- int x , y ;
- x = y = 0 ;
- window->MacWindowToRootWindow( &x , &y ) ;
- m_deviceLocalOriginX = x;
- m_deviceLocalOriginY = y;
- m_macPort = UMAGetWindowPort( (WindowRef) rootwindow->MacGetWindowRef() ) ;
-
- CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
- OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ;
- CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
-#endif
+
SetBackground(MacGetBackgroundBrush(window));
SetFont( window->GetFont() ) ;
wxWindowDC::~wxWindowDC()
{
-#if wxMAC_USE_CORE_GRAPHICS
if ( m_release )
{
// this must not necessarily be the current context, we must restore the state of the
CGContextRef cg = (CGContextRef) m_window->MacGetCGContextRef();
CGContextRestoreGState(cg);
}
-#endif
}
void wxWindowDC::DoGetSize( int* width, int* height ) const
{
-#if wxMAC_USE_CORE_GRAPHICS
if ( width )
*width = m_width;
if ( height )
*height = m_height;
-#else
- wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
- m_window->GetSize(width, height);
-#endif
}
wxBitmap wxWindowDC::DoGetAsBitmap(const wxRect *subrect) const
m_window = NULL ;
}
-#if wxMAC_USE_CORE_GRAPHICS
wxClientDC::wxClientDC(wxWindow *window) :
wxWindowDC( window )
{
SetDeviceOrigin( origin.x, origin.y );
SetClippingRegion( 0 , 0 , m_width , m_height ) ;
}
-#else
-wxClientDC::wxClientDC(wxWindow *window)
-{
- wxCHECK_RET( window, _T("invalid window in wxClientDC") );
- m_window = window ;
- wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
- if (!rootwindow)
- return;
-
- WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
- wxPoint origin = window->GetClientAreaOrigin() ;
- wxSize size = window->GetClientSize() ;
- int x , y ;
- x = origin.x ;
- y = origin.y ;
- window->MacWindowToRootWindow( &x , &y ) ;
- m_macPort = UMAGetWindowPort( windowref ) ;
- m_ok = true ;
-
- m_deviceLocalOriginX = x ;
- m_deviceLocalOriginY = y ;
- SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
- SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
- OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
- OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ;
- CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
-
- SetBackground(MacGetBackgroundBrush(window));
- SetFont( window->GetFont() ) ;
-}
-#endif
wxClientDC::~wxClientDC()
{
}
-#if !wxMAC_USE_CORE_GRAPHICS
-void wxClientDC::DoGetSize(int *width, int *height) const
-{
- wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
-
- m_window->GetClientSize( width, height );
-}
-#endif
-
/*
* wxPaintDC
*/
m_window = NULL ;
}
-#if wxMAC_USE_CORE_GRAPHICS
wxPaintDC::wxPaintDC(wxWindow *window) :
wxWindowDC( window )
{
SetDeviceOrigin( origin.x, origin.y );
SetClippingRegion( 0 , 0 , m_width , m_height ) ;
}
-#else
-wxPaintDC::wxPaintDC(wxWindow *window)
-{
- m_window = window ;
- wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
- WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
- wxPoint origin = window->GetClientAreaOrigin() ;
- wxSize size = window->GetClientSize() ;
- int x , y ;
- x = origin.x ;
- y = origin.y ;
- window->MacWindowToRootWindow( &x , &y ) ;
- m_macPort = UMAGetWindowPort( windowref ) ;
- m_ok = true ;
-
-#if wxMAC_USE_CORE_GRAPHICS
- if ( window->MacGetCGContextRef() )
- {
- m_graphicContext = new wxMacCGContext( (CGContextRef) window->MacGetCGContextRef() ) ;
- m_graphicContext->SetPen( m_pen ) ;
- m_graphicContext->SetBrush( m_brush ) ;
- SetClippingRegion( 0 , 0 , size.x , size.y ) ;
- SetBackground(MacGetBackgroundBrush(window));
- }
- else
- {
- wxLogDebug(wxT("You cannot create a wxPaintDC outside an OS-draw event") ) ;
- m_graphicContext = NULL ;
- }
- // there is no out-of-order drawing on OSX
-#else
- m_deviceLocalOriginX = x ;
- m_deviceLocalOriginY = y ;
- SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
- SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
- OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
- SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
- OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ;
- CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
- SetBackground(MacGetBackgroundBrush(window));
-#endif
-
- SetFont( window->GetFont() ) ;
-}
-#endif
wxPaintDC::~wxPaintDC()
{
}
-
-#if !wxMAC_USE_CORE_GRAPHICS
-void wxPaintDC::DoGetSize(int *width, int *height) const
-{
- wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
-
- m_window->GetClientSize( width, height );
-}
-#endif
{
if ( m_selected.Ok() )
{
-#if wxMAC_USE_CORE_GRAPHICS
m_selected.EndRawAccess() ;
delete m_graphicContext ;
m_graphicContext = NULL ;
-#else
-// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
-#endif
}
}
{
if ( m_selected.Ok() )
{
-#if wxMAC_USE_CORE_GRAPHICS
m_selected.EndRawAccess() ;
delete m_graphicContext ;
m_graphicContext = NULL ;
-#else
-// TODO: UnlockPixels( GetGWorldPixMap(MAC_WXHBITMAP(m_selected.GetHBITMAP())) );
-#endif
}
m_selected = bitmap;
if (m_selected.Ok())
{
-#if wxMAC_USE_CORE_GRAPHICS
if ( m_selected.GetDepth() != 1 )
m_selected.UseAlpha() ;
m_selected.BeginRawAccess() ;
SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
}
m_ok = (m_graphicContext != NULL) ;
-
-#else
- m_macPort = m_selected.GetHBITMAP( &m_macMask ) ;
- m_ok = (m_macPort != NULL) ;
- if (m_ok)
- {
- LockPixels( GetGWorldPixMap( (CGrafPtr) m_macPort ) ) ;
- SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , 0 , 0 , m_selected.GetWidth() , m_selected.GetHeight() ) ;
- CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
- }
-#endif
}
else
{
virtual void GetSize( int *w , int *h) const ;
virtual wxSize GetPPI() const ;
private :
-#if !wxMAC_USE_CORE_GRAPHICS
- GrafPtr m_macPrintFormerPort ;
-#endif
wxCoord m_maxX ;
wxCoord m_maxY ;
wxSize m_ppi ;
wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data )
{
-#if !wxMAC_USE_CORE_GRAPHICS
- ::GetPort( & m_macPrintFormerPort ) ;
-#endif
m_err = noErr ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) data->GetNativeData() ;
wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC()
{
-#if !wxMAC_USE_CORE_GRAPHICS
- // nothing to release from print data, as wxPrinterDC has all data in its wxPrintData member
- ::SetPort( m_macPrintFormerPort ) ;
-#endif
}
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().GetNativeData() ;
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4 && wxMAC_USE_CORE_GRAPHICS
- {
- CFStringRef s[1] = { kPMGraphicsContextCoreGraphics };
- CFArrayRef graphicsContextsArray = CFArrayCreate(NULL, (const void**)s, 1, &kCFTypeArrayCallBacks);
- PMSessionSetDocumentFormatGeneration(native->m_macPrintSession, kPMDocumentFormatPDF, graphicsContextsArray, NULL);
- CFRelease(graphicsContextsArray);
- }
-#endif
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 && wxMAC_USE_CORE_GRAPHICS
m_err = PMSessionBeginCGDocument(native->m_macPrintSession,
native->m_macPrintSettings,
native->m_macPageFormat);
-#else
- m_err = PMSessionBeginDocument(native->m_macPrintSession,
- native->m_macPrintSettings,
- native->m_macPageFormat);
-
-#endif
if ( m_err != noErr )
return false;
native->m_macPageFormat,
nil);
-#if wxMAC_USE_CORE_GRAPHICS
CGContextRef pageContext;
-#endif
+
if ( m_err == noErr )
{
-#if wxMAC_USE_CORE_GRAPHICS
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
m_err = PMSessionGetCGGraphicsContext(native->m_macPrintSession,
&pageContext );
-
-#else
- m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
- kPMGraphicsContextCoreGraphics,
- (void**) &pageContext );
-#endif
-#else
- m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
- kPMGraphicsContextQuickdraw,
- (void**) &dc->m_macPort );
-#endif
}
if ( m_err != noErr )
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( !m_err )
{
-#if wxMAC_USE_CORE_GRAPHICS
PMRect paperRect ;
PMGetAdjustedPaperRect( native->m_macPageFormat , &paperRect ) ;
// make sure (0,0) is at the upper left of the printable area (wx conventions)
// Core Graphics initially has the lower left of the paper as 0,0
CGContextTranslateCTM( pageContext , -paperRect.left , paperRect.bottom ) ;
CGContextScaleCTM( pageContext , 1 , -1 ) ;
-#else
- dc->SetDeviceLocalOrigin( (wxCoord) rPage.left, (wxCoord) rPage.top );
-#endif
}
// since this is a non-critical error, we set the flag back
m_err = noErr ;
}
-#if wxMAC_USE_CORE_GRAPHICS
dc->SetGraphicsContext( wxGraphicsContext::CreateFromNative( pageContext ) );
-#endif
}
void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
{
PMSessionEndDocument(native->m_macPrintSession);
}
-#if wxMAC_USE_CORE_GRAPHICS
// the cg context we got when starting the page isn't valid anymore, so replace it
dc->SetGraphicsContext( wxGraphicsContext::Create() );
-#endif
}
void wxMacCarbonPrinterDC::GetSize( int *w , int *h) const
m_mm_to_pix_x = mm2inches * sz.x;
m_mm_to_pix_y = mm2inches * sz.y;
}
-#if wxMAC_USE_CORE_GRAPHICS
// we need at least a measuring context because people start measuring before a page
// gets printed at all
SetGraphicsContext( wxGraphicsContext::Create() );
-#endif
}
}
m_font = *wxNORMAL_FONT;
m_brush = *wxTRANSPARENT_BRUSH;
m_backgroundBrush = *wxWHITE_BRUSH;
-#if !wxMAC_USE_CORE_GRAPHICS
- m_macFontInstalled = false ;
- m_macBrushInstalled = false ;
- m_macPenInstalled = false ;
-#endif
m_nativePrinterDC->StartPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
// Create a DC representing the whole screen
wxScreenDC::wxScreenDC()
{
-#if wxMAC_USE_CORE_GRAPHICS
CGRect cgbounds ;
cgbounds = CGDisplayBounds(CGMainDisplayID());
Rect bounds;
SetGraphicsContext( wxGraphicsContext::CreateFromNativeWindow( m_overlayWindow ) );
m_width = (wxCoord)cgbounds.size.width;
m_height = (wxCoord)cgbounds.size.height;
-#else
- m_macPort = CreateNewPort() ;
- GrafPtr port ;
- GetPort( &port ) ;
- SetPort( (GrafPtr) m_macPort ) ;
- Point pt = { 0,0 } ;
- LocalToGlobal( &pt ) ;
- SetPort( port ) ;
- m_deviceLocalOriginX = -pt.h ;
- m_deviceLocalOriginY = -pt.v ;
-
- BitMap screenBits;
- GetQDGlobalsScreenBits( &screenBits );
- m_minX = screenBits.bounds.left ;
-
- SInt16 height ;
- GetThemeMenuBarHeight( &height ) ;
- m_minY = screenBits.bounds.top + height ;
-
- m_maxX = screenBits.bounds.right ;
- m_maxY = screenBits.bounds.bottom ;
-
- MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
- OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ;
- CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
-#endif
m_ok = true ;
}
wxScreenDC::~wxScreenDC()
{
-#if wxMAC_USE_CORE_GRAPHICS
delete m_graphicContext;
m_graphicContext = NULL;
DisposeWindow((WindowRef) m_overlayWindow );
-#else
- if ( m_macPort )
- DisposePort( (CGrafPtr) m_macPort ) ;
-#endif
}
if (numFilters < 2)
dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension;
-#if TARGET_API_MAC_OSX
if (!(m_windowStyle & wxFD_OVERWRITE_PROMPT))
dialogCreateOptions.optionFlags |= kNavDontConfirmReplacement;
-#endif
err = ::NavCreatePutFileDialog(
&dialogCreateOptions,
#include "wx/wxprec.h"
-#if wxUSE_GRAPHICS_CONTEXT && wxMAC_USE_CORE_GRAPHICS
-
#include "wx/graphics.h"
#ifndef WX_PRECOMP
#include "wx/mac/private.h"
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
typedef float CGFloat;
#endif
-#ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 1
-#else
- #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
-#endif
-#endif
//-----------------------------------------------------------------------------
// constants
void StrokeLineSegments( CGContextRef ctxRef , const CGPoint pts[] , size_t count )
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( CGContextStrokeLineSegments!=NULL )
- {
- CGContextStrokeLineSegments( ctxRef , pts , count );
- }
- else
-#endif
- {
- CGContextBeginPath( ctxRef );
- 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);
- }
- CGContextStrokePath(ctxRef);
- }
+ CGContextStrokeLineSegments( ctxRef , pts , count );
}
virtual void Render( CGContextRef ctxRef )
{
if ( brush.MacGetBrushKind() == kwxMacBrushTheme )
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- CGColorRef color ;
- HIThemeBrushCreateCGColor( brush.MacGetTheme(), &color );
- m_color.Set( color ) ;
- }
- else
-#endif
- {
- if( brush.MacGetTheme() == kThemeBrushDialogBackgroundActive )
- {
- // striped background is a pattern, we have to emulate it
-
- m_isPattern = true;
- m_patternColorComponents = new CGFloat[1] ;
- m_patternColorComponents[0] = 1.0;
- m_colorSpace.Set( CGColorSpaceCreatePattern( NULL ) );
- m_pattern.Set( *( new ImagePattern( &gs_stripedback_bmp , CGAffineTransformMakeScale( 1,-1 ) ) ) );
- }
- else
- {
- // as close as we can get, unfortunately < 10.4 things get difficult
- RGBColor color;
- GetThemeBrushAsColor( brush.MacGetTheme(), 32, true, &color );
- CGFloat components[4] = { (CGFloat) color.red / 65536,
- (CGFloat) color.green / 65536, (CGFloat) color.blue / 65536, 1 } ;
- m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ;
- }
- }
+ CGColorRef color ;
+ HIThemeBrushCreateCGColor( brush.MacGetTheme(), &color );
+ m_color.Set( color ) ;
}
else
{
// returns true if the elements of the transformation matrix are equal ?
bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData* t) const
{
- const CGAffineTransform* tm = (CGAffineTransform*) t->GetNativeMatrix();
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( CGAffineTransformEqualToTransform!=NULL )
- {
- return CGAffineTransformEqualToTransform(m_matrix, *((CGAffineTransform*) t->GetNativeMatrix()));
- }
- else
-#endif
- {
- return (
- m_matrix.a == tm->a &&
- m_matrix.b == tm->b &&
- m_matrix.c == tm->c &&
- m_matrix.d == tm->d &&
- m_matrix.tx == tm->tx &&
- m_matrix.ty == tm->ty ) ;
- }
+ return CGAffineTransformEqualToTransform(m_matrix, *((CGAffineTransform*) t->GetNativeMatrix()));
}
// return true if this is the identity matrix
bool wxMacCoreGraphicsPathData::Contains( wxDouble x, wxDouble y, int fillStyle) const
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( CGPathContainsPoint!=NULL )
- {
- return CGPathContainsPoint( m_path, NULL, CGPointMake(x,y), fillStyle == wxODDEVEN_RULE );
- }
- else
-#endif
- {
- // TODO : implementation for 10.3
- CGRect bounds = CGPathGetBoundingBox( m_path ) ;
- return CGRectContainsPoint( bounds, CGPointMake(x,y) ) == 1;
- }
+ return CGPathContainsPoint( m_path, NULL, CGPointMake(x,y), fillStyle == wxODDEVEN_RULE );
}
//
if ( function == wxCOPY )
{
retval = true;
-#if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
- if ( CGContextSetBlendMode != NULL )
- {
- CGContextSetBlendMode( m_cgContext, kCGBlendModeNormal );
- CGContextSetShouldAntialias( m_cgContext, true );
- }
-#endif
+ CGContextSetBlendMode( m_cgContext, kCGBlendModeNormal );
}
else if ( function == wxINVERT || function == wxXOR )
{
-#if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
- if ( CGContextSetBlendMode != NULL )
- {
- // change color to white
- CGContextSetBlendMode( m_cgContext, kCGBlendModeExclusion );
- CGContextSetShouldAntialias( m_cgContext, false );
- retval = true;
- }
-#endif
+ // change color to white
+ CGContextSetBlendMode( m_cgContext, kCGBlendModeExclusion );
+ CGContextSetShouldAntialias( m_cgContext, false );
+ retval = true;
}
if (retval)
return wxNullGraphicsFont;
}
-
-
-#endif // wxMAC_USE_CORE_GRAPHICS
int wLine;
{
-#if wxMAC_USE_CORE_GRAPHICS
wxClientDC dc(const_cast<wxListBox*>(this));
dc.SetFont(GetFont());
-#else
- wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef)MacGetTopLevelWindowRef() ) );
- // TODO: clean this up
- if ( m_font.Ok() )
- {
- ::TextFont( m_font.MacGetFontNum() );
- ::TextSize( m_font.MacGetFontSize() );
- ::TextFace( m_font.MacGetFontStyle() );
- }
- else
- {
- ::TextFont( kFontIDMonaco );
- ::TextSize( 9 );
- ::TextFace( 0 );
- }
-#endif
// Find the widest line
for (unsigned int i = 0; i < GetCount(); i++)
{
wxString str( GetString( i ) );
-#if wxMAC_USE_CORE_GRAPHICS
+
wxCoord width, height ;
dc.GetTextExtent( str , &width, &height);
wLine = width ;
-#else
-#if wxUSE_UNICODE
- Point bounds = {0, 0};
- SInt16 baseline;
-
- // NB: what if m_font.Ok() == false ???
- ::GetThemeTextDimensions(
- wxMacCFStringHolder( str, m_font.GetEncoding() ),
- kThemeCurrentPortFont,
- kThemeStateActive,
- false,
- &bounds,
- &baseline );
- wLine = bounds.h;
-#else
- wLine = ::TextWidth( str.c_str(), 0, str.length() );
-#endif
-#endif
lbWidth = wxMax( lbWidth, wLine );
}
// And just a bit more
int cy = 12;
-#if wxMAC_USE_CORE_GRAPHICS
+
wxCoord width, height ;
dc.GetTextExtent( wxT("XX") , &width, &height);
int cx = width ;
-#else
- int cx = ::TextWidth( "XX", 0, 1 );
-#endif
lbWidth += cx;
// don't make the listbox too tall (limit height to around 10 items)
if ( style & wxLC_VRULES )
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
verify_noerr( DataBrowserChangeAttributes(m_controlRef, kDataBrowserAttributeListViewDrawColumnDividers, kDataBrowserAttributeNone) );
-#endif
}
verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite ) );
MenuBarHandle menubar = NULL ;
-#if TARGET_API_MAC_OSX
menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ;
-#else
- menubar = NewHandleClear( 12 ) ;
- (*menubar)[3] = 0x0a ;
-#endif
::SetMenuBar( menubar ) ;
DisposeMenuBar( menubar ) ;
// Add About/Preferences separator only on OS X
// KH/RN: Separator is always present on 10.3 but not on 10.2
// However, the change from 10.2 to 10.3 suggests it is preferred
-#if TARGET_API_MAC_OSX
InsertMenuItemTextWithCFString( appleMenu,
CFSTR(""), 0, kMenuItemAttrSeparator, 0);
-#endif
InsertMenuItemTextWithCFString( appleMenu,
CFSTR("About..."), 0, 0, 0);
MacInsertMenu( appleMenu , 0 ) ;
}
-#if TARGET_API_MAC_OSX
if ( !wxIsMainThread() )
{
CFStringRef defaultButtonTitle = NULL;
resultbutton = buttonId[exitButton];
}
else
-#endif
{
short result;
{
int resultV = wxNOT_FOUND;
-#if TARGET_API_MAC_OSX
const int countPages = GetPageCount();
// we have to convert from Client to Window relative coordinates
if ( outPart >= 1 && outPart <= countPages )
resultV = outPart - 1 ;
-#endif // TARGET_API_MAC_OSX
if (flags != NULL)
{
m_peer->SetTabEnabled( ii + 1, true ) ;
}
-#if wxMAC_USE_CORE_GRAPHICS
Refresh();
-#else
- Rect bounds;
- m_peer->GetRectInWindowCoords( &bounds ) ;
- InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds );
-#endif
}
wxRect wxNotebook::GetPageRect() const
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
#endif
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( PMSetDuplex!=NULL )
+ PMDuplexMode mode = 0 ;
+ switch( data.GetDuplex() )
{
- PMDuplexMode mode = 0 ;
- switch( data.GetDuplex() )
- {
- case wxDUPLEX_HORIZONTAL :
- mode = kPMDuplexNoTumble ;
- break ;
- case wxDUPLEX_VERTICAL :
- mode = kPMDuplexTumble ;
- break ;
- case wxDUPLEX_SIMPLEX :
- default :
- mode = kPMDuplexNone ;
- break ;
- }
- PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ;
+ case wxDUPLEX_HORIZONTAL :
+ mode = kPMDuplexNoTumble ;
+ break ;
+ case wxDUPLEX_VERTICAL :
+ mode = kPMDuplexTumble ;
+ break ;
+ case wxDUPLEX_SIMPLEX :
+ default :
+ mode = kPMDuplexNone ;
+ break ;
}
-#endif
+ PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ;
+
// PMQualityMode not yet accessible via API
// todo paperSize
if ( err == noErr )
data.SetColour( !(color == kPMBlackAndWhite) ) ;
#endif
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( PMGetDuplex!=NULL )
+ PMDuplexMode mode = 0 ;
+ PMGetDuplex( (PMPrintSettings) m_macPrintSettings, &mode ) ;
+ switch( mode )
{
- PMDuplexMode mode = 0 ;
- PMGetDuplex( (PMPrintSettings) m_macPrintSettings, &mode ) ;
- switch( mode )
- {
- case kPMDuplexNoTumble :
- data.SetDuplex(wxDUPLEX_HORIZONTAL);
- break ;
- case kPMDuplexTumble :
- data.SetDuplex(wxDUPLEX_VERTICAL);
- break ;
- case kPMDuplexNone :
- default :
- data.SetDuplex(wxDUPLEX_SIMPLEX);
- break ;
- }
+ case kPMDuplexNoTumble :
+ data.SetDuplex(wxDUPLEX_HORIZONTAL);
+ break ;
+ case kPMDuplexTumble :
+ data.SetDuplex(wxDUPLEX_VERTICAL);
+ break ;
+ case kPMDuplexNone :
+ default :
+ data.SetDuplex(wxDUPLEX_SIMPLEX);
+ break ;
}
-#endif
// PMQualityMode not yet accessible via API
PMPaper paper ;
}
else
{
-#if !wxMAC_USE_CORE_GRAPHICS
- GrafPtr thePort ;
- GetPort( &thePort ) ;
-#endif
wxSafeYield(win,true);
-#if !wxMAC_USE_CORE_GRAPHICS
- SetPort( thePort ) ;
-#endif
dc->StartPage();
keepGoing = printout->OnPrintPage(pn);
dc->EndPage();
wxHeaderSortIconType sortArrow,
wxHeaderButtonParams* params )
{
-#if !wxMAC_USE_CORE_GRAPHICS
- const wxCoord x = dc.LogicalToDeviceX(rect.x);
- const wxCoord y = dc.LogicalToDeviceY(rect.y);
- const wxCoord w = dc.LogicalToDeviceXRel(rect.width);
- const wxCoord h = dc.LogicalToDeviceYRel(rect.height);
-#else
- // now the wxGCDC is using native transformations
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
-#endif
dc.SetBrush( *wxTRANSPARENT_BRUSH );
{
CGContextRef cgContext;
-#if wxMAC_USE_CORE_GRAPHICS
cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
-#else
- Rect bounds;
-
- GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
- QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-
- CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
- CGContextScaleCTM( cgContext, 1, -1 );
-
- HIShapeRef shape = HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn );
- if ( shape != 0 )
- {
- HIShapeReplacePathInCGContext( shape , cgContext );
- CFRelease( shape );
- CGContextClip( cgContext );
- }
- HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
-#endif
{
HIThemeButtonDrawInfo drawInfo;
CGContextRestoreGState( cgContext );
}
}
-
-#if wxMAC_USE_CORE_GRAPHICS
-#else
- QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-#endif
}
// Reserve room for the arrows before writing the label, and turn off the
const wxRect& rect,
int flags )
{
-#if !wxMAC_USE_CORE_GRAPHICS
- const wxCoord x = dc.LogicalToDeviceX(rect.x);
- const wxCoord y = dc.LogicalToDeviceY(rect.y);
- const wxCoord w = dc.LogicalToDeviceXRel(rect.width);
- const wxCoord h = dc.LogicalToDeviceYRel(rect.height);
-#else
// now the wxGCDC is using native transformations
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
-#endif
dc.SetBrush( *wxTRANSPARENT_BRUSH );
{
CGContextRef cgContext;
-#if wxMAC_USE_CORE_GRAPHICS
cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
-#else
- Rect bounds;
-
- GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
- QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
- CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
- CGContextScaleCTM( cgContext, 1, -1 );
+ HIThemeButtonDrawInfo drawInfo;
+ HIRect labelRect;
- HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext );
- CGContextClip( cgContext );
- HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
-#endif
-
- {
- HIThemeButtonDrawInfo drawInfo;
- HIRect labelRect;
-
- memset( &drawInfo, 0, sizeof(drawInfo) );
- drawInfo.version = 0;
- drawInfo.kind = kThemeDisclosureButton;
- drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
- // Apple mailing list posts say to use the arrow adornment constants, but those don't work.
- // We need to set the value using the 'old' DrawThemeButton constants instead.
- drawInfo.value = (flags & wxCONTROL_EXPANDED) ? kThemeDisclosureDown : kThemeDisclosureRight;
- drawInfo.adornment = kThemeAdornmentNone;
-
- HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
-
- }
-
-#if wxMAC_USE_CORE_GRAPHICS
-#else
- QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-#endif
+ memset( &drawInfo, 0, sizeof(drawInfo) );
+ drawInfo.version = 0;
+ drawInfo.kind = kThemeDisclosureButton;
+ drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
+ // Apple mailing list posts say to use the arrow adornment constants, but those don't work.
+ // We need to set the value using the 'old' DrawThemeButton constants instead.
+ drawInfo.value = (flags & wxCONTROL_EXPANDED) ? kThemeDisclosureDown : kThemeDisclosureRight;
+ drawInfo.adornment = kThemeAdornmentNone;
+
+ HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
}
}
else
splitterRect = CGRectMake( 0, position, size.x, height );
-#if !wxMAC_USE_CORE_GRAPHICS
- HIViewConvertRect(
- &splitterRect,
- (HIViewRef) win->GetHandle(),
- (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
-#endif
-
// under compositing we should only draw when called by the OS, otherwise just issue a redraw command
// strange redraw errors occur if we don't do this
{
CGContextRef cgContext;
-#if wxMAC_USE_CORE_GRAPHICS
cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
-#else
- Rect bounds;
- GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
- QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
- CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
- CGContextScaleCTM( cgContext, 1, -1 );
-#endif
HIThemeSplitterDrawInfo drawInfo;
drawInfo.version = 0;
drawInfo.state = kThemeStateActive;
drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal );
-
-#if wxMAC_USE_CORE_GRAPHICS
-#else
- QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-#endif
}
}
int kind,
int adornment)
{
-#if !wxMAC_USE_CORE_GRAPHICS
- const wxCoord x = dc.LogicalToDeviceX(rect.x);
- const wxCoord y = dc.LogicalToDeviceY(rect.y);
- const wxCoord w = dc.LogicalToDeviceXRel(rect.width);
- const wxCoord h = dc.LogicalToDeviceYRel(rect.height);
-#else
// now the wxGCDC is using native transformations
const wxCoord x = rect.x;
const wxCoord y = rect.y;
const wxCoord w = rect.width;
const wxCoord h = rect.height;
-#endif
dc.SetBrush( *wxTRANSPARENT_BRUSH );
else
{
CGContextRef cgContext;
-
-#if wxMAC_USE_CORE_GRAPHICS
cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
-#else
- Rect bounds;
-
- GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
- QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-
- CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
- CGContextScaleCTM( cgContext, 1, -1 );
-
- HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext );
- CGContextClip( cgContext );
- HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
-#endif
-
- {
- HIThemeButtonDrawInfo drawInfo;
- HIRect labelRect;
-
- memset( &drawInfo, 0, sizeof(drawInfo) );
- drawInfo.version = 0;
- drawInfo.kind = kind;
- drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
- drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff;
- if (flags & wxCONTROL_UNDETERMINED)
- drawInfo.value = kThemeButtonMixed;
- drawInfo.adornment = adornment;
- HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
- }
+ HIThemeButtonDrawInfo drawInfo;
+ HIRect labelRect;
-#if wxMAC_USE_CORE_GRAPHICS
-#else
- QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-#endif
+ memset( &drawInfo, 0, sizeof(drawInfo) );
+ drawInfo.version = 0;
+ drawInfo.kind = kind;
+ drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
+ drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff;
+ if (flags & wxCONTROL_UNDETERMINED)
+ drawInfo.value = kThemeButtonMixed;
+ drawInfo.adornment = adornment;
+
+ HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
}
}
return;
}
-#if wxMAC_USE_CORE_GRAPHICS
- {
- CGRect cgrect = CGRectMake( rect.x , rect.y , rect.width, rect.height ) ;
+ CGRect cgrect = CGRectMake( rect.x , rect.y , rect.width, rect.height ) ;
- HIThemeFrameDrawInfo info ;
- memset( &info, 0 , sizeof(info) ) ;
+ HIThemeFrameDrawInfo info ;
+ memset( &info, 0 , sizeof(info) ) ;
- info.version = 0 ;
- info.kind = 0 ;
- info.state = kThemeStateActive;
- info.isFocused = true ;
+ info.version = 0 ;
+ info.kind = 0 ;
+ info.state = kThemeStateActive;
+ info.isFocused = true ;
- CGContextRef cgContext = (CGContextRef) win->MacGetCGContextRef() ;
- wxASSERT( cgContext ) ;
+ CGContextRef cgContext = (CGContextRef) win->MacGetCGContextRef() ;
+ wxASSERT( cgContext ) ;
- HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
- }
-#else
- // FIXME: not yet working for !wxMAC_USE_CORE_GRAPHICS
- {
- Rect r;
- r.left = rect.x; r.top = rect.y; r.right = rect.GetRight(); r.bottom = rect.GetBottom();
- wxTopLevelWindowMac* top = win->MacGetTopLevelWindow();
- if ( top )
- {
- wxPoint pt(0, 0) ;
- wxMacControl::Convert( &pt , win->GetPeer() , top->GetPeer() ) ;
- OffsetRect( &r , pt.x , pt.y ) ;
- }
-
- DrawThemeFocusRect( &r , true ) ;
- }
-#endif
+ HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
}
static const EventTypeSpec eventList[] =
{
{ kEventClassSearchField, kEventSearchFieldCancelClicked } ,
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
{ kEventClassSearchField, kEventSearchFieldSearchClicked } ,
-#endif
};
class wxMacSearchFieldControl : public wxMacUnicodeTextControl
const Rect* bounds,
CFStringRef WXUNUSED(crf))
{
- OptionBits attributes = 0;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- attributes = kHISearchFieldAttributesSearchIcon;
- }
-#endif
+ OptionBits attributes = kHISearchFieldAttributesSearchIcon;
+
HIRect hibounds = { { bounds->left, bounds->top }, { bounds->right-bounds->left, bounds->bottom-bounds->top } };
verify_noerr( HISearchFieldCreate(
&hibounds,
// search field options
void wxMacSearchFieldControl::ShowSearchButton( bool show )
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if ( UMAGetSystemVersion() >= 0x1040 )
+ OptionBits set = 0;
+ OptionBits clear = 0;
+ if ( show )
{
- OptionBits set = 0;
- OptionBits clear = 0;
- if ( show )
- {
- set |= kHISearchFieldAttributesSearchIcon;
- }
- else
- {
- clear |= kHISearchFieldAttributesSearchIcon;
- }
- HISearchFieldChangeAttributes( m_controlRef, set, clear );
+ set |= kHISearchFieldAttributesSearchIcon;
}
-#endif
+ else
+ {
+ clear |= kHISearchFieldAttributesSearchIcon;
+ }
+ HISearchFieldChangeAttributes( m_controlRef, set, clear );
}
bool wxMacSearchFieldControl::IsSearchButtonVisible() const
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
OptionBits attributes = 0;
verify_noerr( HISearchFieldGetAttributes( m_controlRef, &attributes ) );
return ( attributes & kHISearchFieldAttributesSearchIcon ) != 0;
-#else
- return false;
-#endif
}
void wxMacSearchFieldControl::ShowCancelButton( bool show )
case kEventSearchFieldCancelClicked :
thisWindow->MacSearchFieldCancelHit( handler , event ) ;
break ;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
case kEventSearchFieldSearchClicked :
thisWindow->MacSearchFieldSearchHit( handler , event ) ;
break ;
-#endif
}
return result ;
else
#endif
{
- #if wxMAC_USE_CORE_GRAPHICS
wxClientDC dc(const_cast<wxStaticText*>(this));
wxCoord width, height ;
dc.GetTextExtent( m_label , &width, &height);
bounds.h = width;
bounds.v = height;
- #else
- wxMacWindowStateSaver sv( this );
- ::TextFont( m_font.MacGetFontNum() );
- ::TextSize( (short)(m_font.MacGetFontSize()) );
- ::TextFace( m_font.MacGetFontStyle() );
-
- err = GetThemeTextDimensions(
- (!m_label.empty() ? (CFStringRef)str : CFSTR(" ")),
- kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline );
- verify_noerr( err );
- #endif
}
if ( m_label.empty() )
// wxMutex implementation
// ----------------------------------------------------------------------------
-#if TARGET_API_MAC_OSX
#define wxUSE_MAC_SEMAPHORE_MUTEX 0
#define wxUSE_MAC_CRITICAL_REGION_MUTEX 1
#define wxUSE_MAC_PTHREADS_MUTEX 0
-#else
-#define wxUSE_MAC_SEMAPHORE_MUTEX 0
-#define wxUSE_MAC_CRITICAL_REGION_MUTEX 1
-#define wxUSE_MAC_PTHREADS_MUTEX 0
-#endif
#if wxUSE_MAC_PTHREADS_MUTEX
void wxThread::Yield()
{
-#if TARGET_API_MAC_OSX
CFRunLoopRunInMode( kCFRunLoopDefaultMode , 0 , true ) ;
-#endif
MPYield();
}
if ( m_controlHandle != NULL )
{
-#if TARGET_API_MAC_OSX
if ( enable )
EnableControl( m_controlHandle );
else
DisableControl( m_controlHandle );
-#else
- if ( enable )
- ActivateControl( m_controlHandle );
- else
- DeactivateControl( m_controlHandle );
-#endif
}
}
bool drawMetalTheme = MacGetTopLevelWindow()->MacGetMetalAppearance();
-#if wxMAC_USE_CORE_GRAPHICS
if ( !drawMetalTheme )
{
HIThemePlacardDrawInfo info;
// leave the background as it is (striped or metal)
}
-#else
-
- const bool drawBorder = true;
-
- if (drawBorder)
- {
- wxMacPortSetter helper( &dc );
-
- if ( !drawMetalTheme )
- {
- Rect toolbarrect = { dc.YLOG2DEVMAC(0), dc.XLOG2DEVMAC(0),
- dc.YLOG2DEVMAC(h), dc.XLOG2DEVMAC(w) };
-
-#if 0
- if ( toolbarrect.left < 0 )
- toolbarrect.left = 0;
- if ( toolbarrect.top < 0 )
- toolbarrect.top = 0;
-#endif
-
- UMADrawThemePlacard( &toolbarrect, IsEnabled() ? kThemeStateActive : kThemeStateInactive );
- }
- else
- {
-#if TARGET_API_MAC_OSX
- HIRect hiToolbarrect = CGRectMake(
- dc.YLOG2DEVMAC(0), dc.XLOG2DEVMAC(0),
- dc.YLOG2DEVREL(h), dc.XLOG2DEVREL(w) );
- CGContextRef cgContext;
- Rect bounds;
-
- GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
- QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-
- CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
- CGContextScaleCTM( cgContext, 1, -1 );
-
- HIThemeBackgroundDrawInfo drawInfo;
- drawInfo.version = 0;
- drawInfo.state = kThemeStateActive;
- drawInfo.kind = kThemeBackgroundMetal;
- HIThemeApplyBackground( &hiToolbarrect, &drawInfo, cgContext, kHIThemeOrientationNormal );
-
-#ifndef __LP64__
- QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
-#endif
-#endif
- }
- }
-#endif
-
event.Skip();
}
{
EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ;
Point clickLocation = windowMouseLocation ;
-#if TARGET_API_MAC_OSX
+
HIPoint hiPoint ;
hiPoint.x = clickLocation.h ;
hiPoint.y = clickLocation.v ;
HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ;
clickLocation.h = (int)hiPoint.x ;
clickLocation.v = (int)hiPoint.y ;
-#endif // TARGET_API_MAC_OSX
HandleControlClick( control , clickLocation , modifiers , (ControlActionUPP ) -1 ) ;
result = noErr ;
}
#endif
-#if TARGET_API_MAC_OSX
if ( m_macWindow != NULL )
{
MacSetUnifiedAppearance( true ) ;
}
-#endif
HIViewRef growBoxRef = 0 ;
err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
wxTopLevelWindowBase::SetExtraStyle( exStyle ) ;
-#if TARGET_API_MAC_OSX
if ( m_macWindow != NULL )
{
bool metal = GetExtraStyle() & wxFRAME_EX_METAL ;
MacSetMetalAppearance( metal ) ;
}
}
-#endif
}
bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style)
void wxTopLevelWindowMac::MacSetMetalAppearance( bool set )
{
-#if TARGET_API_MAC_OSX
if ( MacGetUnifiedAppearance() )
MacSetUnifiedAppearance( false ) ;
MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes ,
set ? kWindowNoAttributes : kWindowMetalAttribute ) ;
-#endif
}
bool wxTopLevelWindowMac::MacGetMetalAppearance() const
{
-#if TARGET_API_MAC_OSX
return MacGetWindowAttributes() & kWindowMetalAttribute ;
-#else
- return false;
-#endif
}
void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set )
{
-#if TARGET_API_MAC_OSX
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- if ( MacGetMetalAppearance() )
- MacSetMetalAppearance( false ) ;
-
- MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes ,
- set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ;
-
- // For some reason, Tiger uses white as the background color for this appearance,
- // while most apps using it use the typical striped background. Restore that behavior
- // for wx.
- // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
- // though)
- SetBackgroundColour( wxSYS_COLOUR_WINDOW ) ;
- }
-#endif
+ if ( MacGetMetalAppearance() )
+ MacSetMetalAppearance( false ) ;
+
+ MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes ,
+ set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ;
+
+ // For some reason, Tiger uses white as the background color for this appearance,
+ // while most apps using it use the typical striped background. Restore that behavior
+ // for wx.
+ // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
+ // though)
+ SetBackgroundColour( wxSYS_COLOUR_WINDOW ) ;
}
bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
{
-#if TARGET_API_MAC_OSX
- if ( UMAGetSystemVersion() >= 0x1040 )
- return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
- else
-#endif
- return false;
+ return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ;
}
void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear )
{
GetControlBounds( theControl , bounds ) ;
-#if TARGET_API_MAC_OSX
WindowRef tlwref = GetControlOwner( theControl ) ;
wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ;
OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ;
}
-#endif
return bounds ;
}
if ( data == NULL )
return NULL;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if( &CGDataProviderCreateWithCFData != NULL )
- {
- return CGDataProviderCreateWithCFData( data );
- }
-#endif
-
- // make sure we keep it until done
- CFRetain( data );
- CGDataProviderRef provider = CGDataProviderCreateWithData( (void*) data , CFDataGetBytePtr( data ) ,
- CFDataGetLength( data ), UMAReleaseCFDataProviderCallback );
- // if provider couldn't be created, release the data again
- if ( provider == NULL )
- CFRelease( data );
- return provider;
+ return CGDataProviderCreateWithCFData( data );
}
CGDataConsumerRef UMACGDataConsumerCreateWithCFData( CFMutableDataRef data )
if ( data == NULL )
return NULL;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if( &CGDataConsumerCreateWithCFData != NULL )
- {
- return CGDataConsumerCreateWithCFData( data );
- }
-#endif
- // make sure we keep it until done
- CFRetain( data );
- CGDataConsumerCallbacks callbacks;
- callbacks.putBytes = UMAPutBytesCFRefCallback;
- callbacks.releaseConsumer = UMAReleaseCFDataConsumerCallback;
- CGDataConsumerRef consumer = CGDataConsumerCreate( data , &callbacks );
- // if consumer couldn't be created, release the data again
- if ( consumer == NULL )
- CFRelease( data );
- return consumer;
+ return CGDataConsumerCreateWithCFData( data );
}
#endif // wxUSE_GUI
#endif
#if wxUSE_GUI
-#if TARGET_API_MAC_OSX
#include <CoreServices/CoreServices.h>
-#else
- #include <DriverServices.h>
- #include <Multiprocessing.h>
-#endif
-
-#ifdef __DARWIN__
#include <Carbon/Carbon.h>
-#else
- #include <ATSUnicode.h>
- #include <TextCommon.h>
- #include <TextEncodingConverter.h>
-#endif
-
-#include "wx/mac/private/timer.h"
+ #include "wx/mac/private/timer.h"
#endif // wxUSE_GUI
#include "wx/evtloop.h"
void wxGetMousePosition( int* x, int* y )
{
Point pt;
-#if wxMAC_USE_CORE_GRAPHICS
GetGlobalMouse(&pt);
-#else
- GetMouse( &pt );
- LocalToGlobal( &pt );
-#endif
*x = pt.h;
*y = pt.v;
};
// Returns depth of screen
int wxDisplayDepth()
{
- int theDepth = 8;
-#if wxMAC_USE_CORE_GRAPHICS
- theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
-#else
+ int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
Rect globRect;
SetRect(&globRect, -32760, -32760, 32760, 32760);
GDHandle theMaxDevice;
theMaxDevice = GetMaxDevice(&globRect);
if (theMaxDevice != NULL)
theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
-#endif
+
return theDepth;
}
// Get size of display
void wxDisplaySize(int *width, int *height)
{
-#if wxMAC_USE_CORE_GRAPHICS
// TODO adapt for multi-displays
CGRect bounds = CGDisplayBounds(CGMainDisplayID());
if ( width )
*width = (int)bounds.size.width ;
if ( height )
*height = (int)bounds.size.height;
-#else
- BitMap screenBits;
- GetQDGlobalsScreenBits( &screenBits );
-
- if (width != NULL)
- *width = screenBits.bounds.right - screenBits.bounds.left;
-
- if (height != NULL)
- *height = screenBits.bounds.bottom - screenBits.bounds.top;
-#endif
}
void wxDisplaySizeMM(int *width, int *height)
OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
{
-#if TARGET_API_MAC_OSX
return SendEventToEventTargetWithOptions( event,
HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
-#else
- #pragma unused(inOptions)
- return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) );
-#endif
}
OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
columnDesc.propertyDesc.propertyType = colType;
columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
-#endif
verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
if (genericRGBColorSpace == NULL)
{
- if ( UMAGetSystemVersion() >= 0x1040 )
- {
- genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
- }
- else
- {
- CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
-
- if (genericRGBProfile)
- {
- genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) );
-
- wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") );
-
- // we opened the profile so it is up to us to close it
- CMCloseProfile(genericRGBProfile);
- }
- }
+ genericRGBColorSpace.Set( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
}
return genericRGBColorSpace;
void wxMacGlobalToLocal( WindowRef window , Point*pt )
{
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
HIPoint p = CGPointMake( pt->h, pt->v );
HIViewRef contentView ;
// TODO check toolbar offset
HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView );
pt->h = p.x;
pt->v = p.y;
-#else
- QDGlobalToLocalPoint( GetWindowPort(window), pt ) ;
-#endif
}
void wxMacLocalToGlobal( WindowRef window , Point*pt )
{
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
HIPoint p = CGPointMake( pt->h, pt->v );
HIViewRef contentView ;
// TODO check toolbar offset
HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL );
pt->h = p.x;
pt->v = p.y;
-#else
- QDLocalToGlobalPoint( GetWindowPort(window), pt ) ;
-#endif
}
#endif // wxUSE_GUI
#endif
{
-#if wxMAC_USE_CORE_GRAPHICS
bool created = false ;
CGContextRef cgContext = NULL ;
OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
CGContextClearRect( cgContext, bounds );
}
-
-#endif
if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
result = noErr ;
-#if wxMAC_USE_CORE_GRAPHICS
thisWindow->MacSetCGContextRef( NULL ) ;
}
if ( created )
CGContextRelease( cgContext ) ;
-#endif
}
if ( allocatedRgn )
m_peer = NULL ;
m_frozenness = 0 ;
m_macAlpha = 255 ;
-
-#if wxMAC_USE_CORE_GRAPHICS
m_cgContextRef = NULL ;
-#endif
// as all windows are created with WS_VISIBLE style...
m_isShown = true;
if ( IsTopLevel() )
return ;
-#if wxMAC_USE_CORE_GRAPHICS
if ( MacHasScrollBarCorner() )
{
Rect rect ;
CGContextFillRect( cgContext, cgrect );
CGContextRestoreGState( cgContext );
}
-#endif
}
void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
m_peer->GetRect( &rect ) ;
InsetRect( &rect, -1 , -1 ) ;
-#if wxMAC_USE_CORE_GRAPHICS
{
CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
rect.bottom - rect.top ) ;
}
#endif
}
- #else
- {
- wxTopLevelWindowMac* top = MacGetTopLevelWindow();
- if ( top )
- {
- wxPoint pt(0, 0) ;
- wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
- OffsetRect( &rect , pt.x , pt.y ) ;
- }
-
- if ( HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
- DrawThemeEditTextFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
- else if ( HasFlag(wxSIMPLE_BORDER) )
- DrawThemeListBoxFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
-
- if ( hasFocus )
- DrawThemeFocusRect( &rect , true ) ;
- // TODO REMOVE
- /*
- if ( hasBothScrollbars ) // hasBothScrollbars is not declared
- {
- // GetThemeStandaloneGrowBoxBounds
- // DrawThemeStandaloneNoGrowBox
- }
- */
- }
-#endif
}
void wxWindowMac::RemoveChild( wxWindowBase *child )
if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
{
-#if wxMAC_USE_CORE_GRAPHICS
GetParent()->Refresh() ;
-#else
wxMacWindowStateSaver sv( this ) ;
Rect rect ;
// we have to invalidate things, we cannot simple redraw
MacInvalidateBorders() ;
}
-#endif
}
event.Skip();
eventNc.SetEventObject( child );
if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
{
-#if wxMAC_USE_CORE_GRAPHICS
child->MacPaintBorders(0, 0) ;
-#else
- {
- wxWindowDC dc(this) ;
- dc.SetClippingRegion(wxRegion(updatergn));
- wxMacPortSetter helper(&dc) ;
- child->MacPaintBorders(0, 0) ;
- }
-#endif
}
}
}
bool wxWindowMac::SetTransparent(wxByte alpha)
{
-#if wxMAC_USE_CORE_GRAPHICS
SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
if ( alpha != m_macAlpha )
Refresh() ;
}
return true ;
-#else
- return false ;
-#endif
}
bool wxWindowMac::CanSetTransparent()
{
-#if wxMAC_USE_CORE_GRAPHICS
return true ;
-#else
- return false ;
-#endif
}
wxByte wxWindowMac::GetTransparent() const