~ubuntu-branches/ubuntu/maverick/wxwidgets2.8/maverick-proposed

« back to all changes in this revision

Viewing changes to src/mac/carbon/graphics.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Filoni
  • Date: 2007-11-06 18:25:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071106182513-809agqds6igh7mqo
Tags: 2.8.6.1-0ubuntu1
* New upstream version, based on the upstream tarball
  wxPython-src-2.8.6.1.tar.bz2, renamed debian to debian-upstream.
* Provide a get-orig-source target to do the repackaging.
* Fix "substvar-source-version-is-deprecated" lintian warnings.
* Remove duplicate Description field in debian/control.
* Add "\" at the end of line 8 in debian/python-wxtools.menu to fix
  "bad-test-in-menu-item" lintian error.
* Provide .xpm icons to fix "menu-icon-not-in-xpm-format" lintian errors,
  changed Icon field in debian/python-wxtools.menu.
* Fix "wrong-name-for-upstream-changelog" lintian warnings.
* Remove "Application;" from Categories field in debian/pycrust.desktop,
  debian/pyshell.desktop, debian/xrced.desktop.
* Switch "Apps" to "Applications" in debian/python-wxtools.menu to fix
  "menu-item-uses-apps-section" lintian warnings.
* Drop the icon extension from debian/pycrust.desktop,
  debian/pyshell.desktop, debian/xrced.desktop.
* Add dpatch support.
* Add "WX_CONFIG" patch.
* debian/rules:
  - added .xpm icons to install-gtk-py-tools target
  - added "docs/changes.txt" to dh_installchangelogs in binary-common target
  - added "\" at the end of "install-examples install-msw-dev
    install-msw-dbg install-headers-msw" line in .PHONY

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:      Stefan Csomor
5
5
// Modified by:
6
6
// Created:     01/02/97
7
 
// RCS-ID:      $Id: graphics.cpp,v 1.35.2.2 2007/03/02 16:53:03 RD Exp $
 
7
// RCS-ID:      $Id: graphics.cpp 49306 2007-10-21 18:16:07Z SC $
8
8
// Copyright:   (c) Stefan Csomor
9
9
// Licence:     wxWindows licence
10
10
/////////////////////////////////////////////////////////////////////////////
20
20
    #include "wx/dcmemory.h"
21
21
    #include "wx/log.h"
22
22
    #include "wx/region.h"
 
23
    #include "wx/image.h"
23
24
#endif
24
25
 
25
26
#include "wx/mac/uma.h"
169
170
    void StrokeLineSegments( CGContextRef ctxRef , const CGPoint pts[] , size_t count )
170
171
    {
171
172
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
172
 
        if ( CGContextStrokeLineSegments!=NULL  )
 
173
        if ( &CGContextStrokeLineSegments!=NULL  )
173
174
        {
174
175
            CGContextStrokeLineSegments( ctxRef , pts , count );
175
176
        }
297
298
{
298
299
    Init();
299
300
 
300
 
    float components[4] = { pen.GetColour().Red() / 255.0 , pen.GetColour().Green() / 255.0 ,
 
301
    CGFloat components[4] = { pen.GetColour().Red() / 255.0 , pen.GetColour().Green() / 255.0 ,
301
302
            pen.GetColour().Blue() / 255.0 , pen.GetColour().Alpha() / 255.0 } ;
302
303
    m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ;
303
304
 
478
479
// Brush
479
480
//
480
481
 
 
482
static const char *gs_stripedback_xpm[] = {
 
483
/* columns rows colors chars-per-pixel */
 
484
"4 4 2 1",
 
485
". c #F0F0F0",
 
486
"X c #ECECEC",
 
487
/* pixels */
 
488
"....",
 
489
"....",
 
490
"XXXX",
 
491
"XXXX"
 
492
};
 
493
 
 
494
wxBitmap gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm  ), -1 ) ;
 
495
 
 
496
wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
 
497
{
 
498
    delete[] m_patternColorComponents;
 
499
}
 
500
 
 
501
void wxMacCoreGraphicsColour::Init()
 
502
{
 
503
    m_isPattern = false;
 
504
    m_patternColorComponents = NULL;
 
505
}
 
506
 
 
507
void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext )
 
508
{
 
509
    if ( m_isPattern )
 
510
    {
 
511
        CGAffineTransform matrix = CGContextGetCTM( cgContext );
 
512
        CGContextSetPatternPhase( cgContext, CGSizeMake(matrix.tx, matrix.ty) );
 
513
        CGContextSetFillColorSpace( cgContext , m_colorSpace );
 
514
        CGContextSetFillPattern( cgContext, m_pattern , m_patternColorComponents );
 
515
    }
 
516
    else
 
517
    {
 
518
        CGContextSetFillColorWithColor( cgContext, m_color );
 
519
    }
 
520
}
 
521
 
 
522
wxMacCoreGraphicsColour::wxMacCoreGraphicsColour() 
 
523
{
 
524
    Init();
 
525
}
 
526
 
 
527
wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush &brush )
 
528
{
 
529
    Init();
 
530
    if ( brush.GetStyle() == wxSOLID )
 
531
    {
 
532
        if ( brush.MacGetBrushKind() == kwxMacBrushTheme )
 
533
        {
 
534
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
 
535
            if ( UMAGetSystemVersion()  >= 0x1040 )
 
536
            {
 
537
                CGColorRef color ;
 
538
                HIThemeBrushCreateCGColor( brush.MacGetTheme(), &color );
 
539
                m_color.Set( color ) ;
 
540
            }
 
541
            else
 
542
#endif
 
543
            {
 
544
                if( brush.MacGetTheme() == kThemeBrushDialogBackgroundActive )
 
545
                {
 
546
                    // striped background is a pattern, we have to emulate it
 
547
                    
 
548
                    m_isPattern = true;
 
549
                    m_patternColorComponents = new CGFloat[1] ;
 
550
                    m_patternColorComponents[0] = 1.0;
 
551
                    m_colorSpace.Set( CGColorSpaceCreatePattern( NULL ) );
 
552
                    m_pattern.Set( *( new ImagePattern( &gs_stripedback_bmp , CGAffineTransformMakeScale( 1,-1 ) ) ) );
 
553
                }
 
554
                else
 
555
                {
 
556
                    // as close as we can get, unfortunately < 10.4 things get difficult
 
557
                    RGBColor color;
 
558
                    GetThemeBrushAsColor( brush.MacGetTheme(), 32, true, &color );
 
559
                    CGFloat components[4] = {  (CGFloat) color.red / 65536,
 
560
                        (CGFloat) color.green / 65536, (CGFloat) color.blue / 65536, 1 } ;
 
561
                    m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ;
 
562
                }
 
563
            }
 
564
        }
 
565
        else
 
566
        {
 
567
            CGFloat components[4] = { brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 ,
 
568
                brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 } ;
 
569
            m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ;
 
570
        }
 
571
    }
 
572
    else if ( brush.IsHatch() )
 
573
    {
 
574
        m_isPattern = true;
 
575
        m_colorSpace.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
 
576
        m_pattern.Set( *( new HatchPattern( brush.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
 
577
 
 
578
        m_patternColorComponents = new CGFloat[4] ;
 
579
        m_patternColorComponents[0] = brush.GetColour().Red() / 255.0;
 
580
        m_patternColorComponents[1] = brush.GetColour().Green() / 255.0;
 
581
        m_patternColorComponents[2] = brush.GetColour().Blue() / 255.0;
 
582
        m_patternColorComponents[3] = brush.GetColour().Alpha() / 255.0;
 
583
    }
 
584
    else
 
585
    {
 
586
        // now brush is a bitmap
 
587
        wxBitmap* bmp = brush.GetStipple();
 
588
        if ( bmp && bmp->Ok() )
 
589
        {
 
590
            m_isPattern = true;
 
591
            m_patternColorComponents = new CGFloat[1] ;
 
592
            m_patternColorComponents[0] = 1.0;
 
593
            m_colorSpace.Set( CGColorSpaceCreatePattern( NULL ) );
 
594
            m_pattern.Set( *( new ImagePattern( bmp , CGAffineTransformMakeScale( 1,-1 ) ) ) );
 
595
        }
 
596
    }
 
597
}
 
598
 
481
599
class wxMacCoreGraphicsBrushData : public wxGraphicsObjectRefData
482
600
{
483
601
public:
498
616
    static void CalculateShadingValues (void *info, const CGFloat *in, CGFloat *out);
499
617
    virtual void Init();
500
618
 
501
 
    wxMacCFRefHolder<CGColorRef> m_color;
502
 
    wxMacCFRefHolder<CGColorSpaceRef> m_colorSpace;
503
 
 
504
 
    bool m_isPattern;
505
 
    wxMacCFRefHolder<CGPatternRef> m_pattern;
506
 
    CGFloat* m_patternColorComponents;
 
619
    wxMacCoreGraphicsColour m_cgColor;
507
620
 
508
621
    bool m_isShading;
509
622
    CGFunctionRef m_gradientFunction;
532
645
    m_isShading = true ;
533
646
}
534
647
 
535
 
wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer* renderer, const wxBrush &brush) : wxGraphicsObjectRefData( renderer )
 
648
wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer* renderer, const wxBrush &brush) : wxGraphicsObjectRefData( renderer ),
 
649
    m_cgColor( brush )
536
650
{
537
651
    Init();
538
652
 
539
 
    if ( brush.GetStyle() == wxSOLID )
540
 
    {
541
 
        if ( brush.MacGetBrushKind() == kwxMacBrushTheme )
542
 
        {
543
 
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
544
 
            if ( HIThemeBrushCreateCGColor != 0 )
545
 
            {
546
 
                CGColorRef color ;
547
 
                HIThemeBrushCreateCGColor( brush.MacGetTheme(), &color );
548
 
                m_color.Set( color ) ;
549
 
            }
550
 
            else
551
 
#endif
552
 
            {
553
 
                // as close as we can get, unfortunately < 10.4 things get difficult
554
 
                RGBColor color;
555
 
                GetThemeBrushAsColor( brush.MacGetTheme(), 32, true, &color );
556
 
                float components[4] = {  (CGFloat) color.red / 65536,
557
 
                    (CGFloat) color.green / 65536, (CGFloat) color.blue / 65536, 1 } ;
558
 
                m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ;
559
 
            }
560
 
        }
561
 
        else
562
 
        {
563
 
            float components[4] = { brush.GetColour().Red() / 255.0 , brush.GetColour().Green() / 255.0 ,
564
 
                brush.GetColour().Blue() / 255.0 , brush.GetColour().Alpha() / 255.0 } ;
565
 
            m_color.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ) ;
566
 
        }
567
 
    }
568
 
    else if ( brush.IsHatch() )
569
 
    {
570
 
        m_isPattern = true;
571
 
        m_colorSpace.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
572
 
        m_pattern.Set( *( new HatchPattern( brush.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
573
 
 
574
 
        m_patternColorComponents = new CGFloat[4] ;
575
 
        m_patternColorComponents[0] = brush.GetColour().Red() / 255.0;
576
 
        m_patternColorComponents[1] = brush.GetColour().Green() / 255.0;
577
 
        m_patternColorComponents[2] = brush.GetColour().Blue() / 255.0;
578
 
        m_patternColorComponents[3] = brush.GetColour().Alpha() / 255.0;
579
 
    }
580
 
    else
581
 
    {
582
 
        // now brush is a bitmap
583
 
        wxBitmap* bmp = brush.GetStipple();
584
 
        if ( bmp && bmp->Ok() )
585
 
        {
586
 
            m_isPattern = true;
587
 
            m_patternColorComponents = new CGFloat[1] ;
588
 
            m_patternColorComponents[0] = 1.0;
589
 
            m_colorSpace.Set( CGColorSpaceCreatePattern( NULL ) );
590
 
            m_pattern.Set( *( new ImagePattern( bmp , CGAffineTransformMakeScale( 1,-1 ) ) ) );
591
 
        }
592
 
    }
593
653
}
594
654
 
595
655
wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
601
661
        CGFunctionRelease(m_gradientFunction);
602
662
 
603
663
    delete[] m_gradientComponents;
604
 
    delete[] m_patternColorComponents;
605
664
}
606
665
 
607
666
void wxMacCoreGraphicsBrushData::Init()
608
667
{
609
 
    m_patternColorComponents = NULL;
610
668
    m_gradientFunction = NULL;
611
669
    m_shading = NULL;
612
 
    m_isPattern = false;
613
670
    m_gradientComponents = NULL;
614
671
    m_isShading = false;
615
672
}
624
681
    }
625
682
    else
626
683
    {
627
 
        if ( m_isPattern )
628
 
        {
629
 
            CGAffineTransform matrix = CGContextGetCTM( cg );
630
 
            CGContextSetPatternPhase( cg, CGSizeMake(matrix.tx, matrix.ty) );
631
 
            CGContextSetFillColorSpace( cg , m_colorSpace );
632
 
            CGContextSetFillPattern( cg, m_pattern , m_patternColorComponents );
633
 
        }
634
 
        else
635
 
        {
636
 
            CGContextSetFillColorWithColor( cg, m_color );
637
 
        }
 
684
        m_cgColor.Apply( cg );
638
685
    }
639
686
}
640
687
 
697
744
 
698
745
    // we need the scale here ...
699
746
 
700
 
    Fixed atsuSize = IntToFixed( int( 1 * font.MacGetFontSize()) );
 
747
    Fixed atsuSize = IntToFixed( int( 1 * font.GetPointSize()) );
701
748
    RGBColor atsuColor = MAC_WXCOLORREF( col.GetPixel() );
702
749
    ATSUAttributeTag atsuTags[] =
703
750
    {
853
900
{
854
901
    const CGAffineTransform* tm = (CGAffineTransform*) t->GetNativeMatrix();
855
902
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
856
 
    if ( CGAffineTransformEqualToTransform!=NULL )
 
903
    if ( &CGAffineTransformEqualToTransform!=NULL )
857
904
    {
858
905
        return CGAffineTransformEqualToTransform(m_matrix, *((CGAffineTransform*) t->GetNativeMatrix()));
859
906
    }
1107
1154
bool wxMacCoreGraphicsPathData::Contains( wxDouble x, wxDouble y, int fillStyle) const
1108
1155
{
1109
1156
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1110
 
    if ( CGPathContainsPoint!=NULL )
 
1157
    if ( &CGPathContainsPoint!=NULL )
1111
1158
    {
1112
1159
        return CGPathContainsPoint( m_path, NULL, CGPointMake(x,y), fillStyle == wxODDEVEN_RULE );
1113
1160
    }
1263
1310
 
1264
1311
IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext, wxGraphicsContext)
1265
1312
 
 
1313
class wxQuartzOffsetHelper
 
1314
{
 
1315
public :
 
1316
    wxQuartzOffsetHelper( CGContextRef cg , bool offset )
 
1317
    {
 
1318
        m_cg = cg;
 
1319
        m_offset = offset;
 
1320
        if ( m_offset )
 
1321
            CGContextTranslateCTM( m_cg, 0.5, 0.5 );
 
1322
    }
 
1323
    ~wxQuartzOffsetHelper( )
 
1324
    {
 
1325
        if ( m_offset )
 
1326
            CGContextTranslateCTM( m_cg, -0.5, -0.5 );
 
1327
    }
 
1328
public :
 
1329
    CGContextRef m_cg;
 
1330
    bool m_offset;
 
1331
} ;
 
1332
 
1266
1333
void wxMacCoreGraphicsContext::Init()
1267
1334
{
1268
1335
    m_cgContext = NULL;
1320
1387
{
1321
1388
    if ( !m_cgContext )
1322
1389
    {
1323
 
        OSStatus status = QDBeginCGContext( GetWindowPort( m_windowRef ) , &m_cgContext );
 
1390
        OSStatus status = 
 
1391
#ifndef __LP64__
 
1392
            QDBeginCGContext( GetWindowPort( m_windowRef ) , &m_cgContext );
 
1393
#else
 
1394
            paramErr;
 
1395
#endif
1324
1396
        wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") );
1325
1397
 
1326
1398
        CGContextConcatCTM( m_cgContext, m_windowTransform );
1447
1519
 
1448
1520
    EnsureIsValid();
1449
1521
 
1450
 
    bool offset = ShouldOffset();
1451
 
    if ( offset )
1452
 
        CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );
 
1522
    wxQuartzOffsetHelper helper( m_cgContext , ShouldOffset() );
1453
1523
 
1454
1524
    ((wxMacCoreGraphicsPenData*)m_pen.GetRefData())->Apply(this);
1455
1525
    CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1456
1526
    CGContextStrokePath( m_cgContext );
1457
 
 
1458
 
    if ( offset )
1459
 
        CGContextTranslateCTM( m_cgContext, -0.5, -0.5 );
1460
1527
}
1461
1528
 
1462
1529
void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath &path , int fillStyle )
1502
1569
    if ( !m_pen.IsNull() )
1503
1570
        ((wxMacCoreGraphicsPenData*)m_pen.GetRefData())->Apply(this);
1504
1571
 
1505
 
    bool offset = ShouldOffset();
1506
 
 
1507
 
    if ( offset )
1508
 
        CGContextTranslateCTM( m_cgContext, 0.5, 0.5 );
 
1572
    wxQuartzOffsetHelper helper( m_cgContext , ShouldOffset() );
1509
1573
 
1510
1574
    CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1511
1575
    CGContextDrawPath( m_cgContext , mode );
1512
 
 
1513
 
    if ( offset )
1514
 
        CGContextTranslateCTM( m_cgContext, -0.5, -0.5 );
1515
1576
}
1516
1577
 
1517
1578
void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath &path , int fillStyle )
1551
1612
        CGContextRestoreGState( m_cgContext );
1552
1613
        CGContextRestoreGState( m_cgContext );
1553
1614
        if ( m_releaseContext )
 
1615
        {
 
1616
#ifndef __LP64__
1554
1617
            QDEndCGContext( GetWindowPort( m_windowRef ) , &m_cgContext);
 
1618
#endif
 
1619
        }
1555
1620
        else
1556
1621
            CGContextRelease(m_cgContext);
1557
1622
    }
1786
1851
{
1787
1852
    wxCHECK_RET( !m_font.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1788
1853
 
 
1854
    if ( width )
 
1855
        *width = 0;
 
1856
    if ( height )
 
1857
        *height = 0;
 
1858
    if ( descent )
 
1859
        *descent = 0;
 
1860
    if ( externalLeading )
 
1861
        *externalLeading = 0;
 
1862
        
 
1863
    if (str.empty())
 
1864
        return;
 
1865
 
1789
1866
    OSStatus status = noErr;
1790
1867
 
1791
1868
    ATSUTextLayout atsuLayout;