// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dc.h"
#endif
+#include "wx/wxprec.h"
+
#include "wx/dc.h"
+
+#if !wxMAC_USE_CORE_GRAPHICS
#include "wx/app.h"
#include "wx/mac/uma.h"
#include "wx/dcmemory.h"
#include "wx/log.h"
#if __MSL__ >= 0x6000
-#include "math.h"
+namespace std {}
using namespace std ;
#endif
#include "wx/mac/private.h"
-#include "ATSUnicode.h"
-#include "TextCommon.h"
-#include "TextEncodingConverter.h"
-#include "FixMath.h"
-#if !USE_SHARED_LIBRARY
+#include <ATSUnicode.h>
+#include <TextCommon.h>
+#include <TextEncodingConverter.h>
+
IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
-#endif
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
-#define mm2inches 0.0393700787402
-#define inches2mm 25.4
-#define mm2twips 56.6929133859
-#define twips2mm 0.0176388888889
-#define mm2pt 2.83464566929
-#define pt2mm 0.352777777778
-#if !defined( __DARWIN__ ) || defined(__MWERKS__)
-#ifndef M_PI
-const double M_PI = 3.14159265358979 ;
-#endif
-#endif
const double RAD2DEG = 180.0 / M_PI;
const short kEmulatedMode = -1 ;
const short kUnsupportedMode = -2 ;
class wxMacFastPortSetter
{
public :
- wxMacFastPortSetter( const wxDC *dc )
+ wxMacFastPortSetter( const wxDC *dc )
{
- wxASSERT( dc->Ok() ) ;
- GetPort( &m_oldPort ) ;
- SetPort( (GrafPtr) dc->m_macPort ) ;
- m_dc = dc ;
- dc->MacSetupPort( NULL ) ;
+ 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( m_oldPort ) ;
- m_dc->MacCleanupPort( NULL ) ;
+ // 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 ;
} ;
typedef wxMacPortSetter wxMacFastPortSetter ;
#endif
-wxMacWindowClipper::wxMacWindowClipper( const wxWindow* win )
+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 )
{
-#if 0
- // this clipping area was set to the parent window's drawing area, lead to problems
- // with MacOSX controls drawing outside their wx' rectangle
- RgnHandle insidergn = NewRgn() ;
- int x = 0 , y = 0;
- wxWindow *parent = win->GetParent() ;
- parent->MacWindowToRootWindow( &x,&y ) ;
- wxSize size = parent->GetSize() ;
- SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() ,
- size.x - parent->MacGetRightBorderSize(),
- size.y - parent->MacGetBottomBorderSize()) ;
- CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , m_newClip ) ;
- SectRgn( m_newClip , insidergn , m_newClip ) ;
- OffsetRgn( m_newClip , x , y ) ;
- SetClip( m_newClip ) ;
- DisposeRgn( insidergn ) ;
-#else
- int x = 0 , y = 0;
- win->MacWindowToRootWindow( &x,&y ) ;
- CopyRgn( (RgnHandle) ((wxWindow*)win)->MacGetVisibleRegion().GetWXHRGN() , m_newClip ) ;
- OffsetRgn( m_newClip , x , y ) ;
+ // 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 ) ;
-#endif
}
}
-wxMacWindowClipper::~wxMacWindowClipper()
+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 ) ;
+}
+
//-----------------------------------------------------------------------------
// Local functions
//-----------------------------------------------------------------------------
wxDC::wxDC()
{
- m_ok = FALSE;
- m_colour = TRUE;
+ m_ok = false;
+ m_colour = true;
m_mm_to_pix_x = mm2pt;
m_mm_to_pix_y = mm2pt;
m_internalDeviceOriginX = 0;
m_userScaleY = 1.0;
m_scaleX = 1.0;
m_scaleY = 1.0;
- m_needComputeScaleX = FALSE;
- m_needComputeScaleY = FALSE;
+ m_needComputeScaleX = false;
+ m_needComputeScaleY = false;
m_macPort = NULL ;
m_macMask = NULL ;
- m_ok = FALSE ;
+ m_ok = false ;
m_macFontInstalled = false ;
m_macBrushInstalled = false ;
m_macPenInstalled = false ;
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
+ // needed to debug possible errors with two active drawing methods at the same time on
// the same DC
m_macCurrentPortStateHelper = NULL ;
#endif
//m_logicalFunction == wxSRC_OR ? srcOr :
//m_logicalFunction == wxSRC_AND ? SRCAND :
srcCopy );
- if ( bmp.GetBitmapType() == kMacBitmapTypePict ) {
- Rect bitmaprect = { 0 , 0 , hh, ww };
- ::OffsetRect( &bitmaprect, xx, yy ) ;
- ::DrawPicture( (PicHandle) bmp.GetPict(), &bitmaprect ) ;
- }
- else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld )
+
+ 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
{
- GWorldPtr bmapworld = MAC_WXHBITMAP( bmp.GetHBITMAP() );
- 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("DoDrawBitmap: Unable to lock pixels"));
- Rect source = { 0, 0, h, w };
- Rect dest = { yy, xx, yy + hh, xx + ww };
- if ( useMask && bmp.GetMask() )
+ RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ;
+ RGBColor black = { 0,0,0} ;
+ RGBForeColor( &black ) ;
+ RGBBackColor( &white ) ;
+ }
+ bmappixels = GetGWorldPixMap( bmapworld ) ;
+ wxCHECK_RET(LockPixels(bmappixels),
+ wxT("DoDrawBitmap: Unable 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))))
{
- if( LockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap()))))
- {
- CopyDeepMask
- (
- GetPortBitMapForCopyBits(bmapworld),
- GetPortBitMapForCopyBits(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())),
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
- &source, &source, &dest, mode, NULL
- );
- UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(bmp.GetMask()->GetMaskBitmap())));
- }
- }
- else {
- CopyBits( GetPortBitMapForCopyBits( bmapworld ),
- GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
- &source, &dest, mode, NULL ) ;
+ CopyDeepMask
+ (
+ GetPortBitMapForCopyBits(bmapworld),
+ GetPortBitMapForCopyBits(MAC_WXHBITMAP(maskworld)),
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
+ &source, &source, &dest, mode, NULL
+ );
+ UnlockPixels(GetGWorldPixMap(MAC_WXHBITMAP(maskworld)));
}
- UnlockPixels( bmappixels ) ;
}
- else if ( bmp.GetBitmapType() == kMacBitmapTypeIcon )
- {
- Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ;
- OffsetRect( &bitmaprect, xx, yy ) ;
- PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(bmp.GetHICON()) ) ;
+ else {
+ CopyBits( GetPortBitMapForCopyBits( bmapworld ),
+ GetPortBitMapForCopyBits( MAC_WXHBITMAP(m_macPort) ),
+ &source, &dest, mode, NULL ) ;
}
+ UnlockPixels( bmappixels ) ;
+
m_macPenInstalled = false ;
m_macBrushInstalled = false ;
m_macFontInstalled = false ;
{
wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon"));
wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon"));
- DoDrawBitmap( icon , x , y , icon.GetMask() != NULL ) ;
+ 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 )
}
else
{
- m_clipping = TRUE;
+ m_clipping = true;
m_clipX1 = xx;
m_clipY1 = yy;
m_clipX2 = xx + ww;
void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion )
{
wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
- if (region.Empty())
- {
- DestroyClippingRegion();
- return;
- }
wxMacFastPortSetter helper(this) ;
wxCoord x, y, w, h;
region.GetBox( x, y, w, h );
}
else
{
- m_clipping = TRUE;
+ m_clipping = true;
m_clipX1 = xx;
m_clipY1 = yy;
m_clipX2 = xx + ww;
{
wxMacFastPortSetter helper(this) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
- m_clipping = FALSE;
+ ResetClipping();
}
void wxDC::DoGetSizeMM( int* width, int* height ) const
}
if (mode != wxMM_TEXT)
{
- m_needComputeScaleX = TRUE;
- m_needComputeScaleY = TRUE;
+ m_needComputeScaleX = true;
+ m_needComputeScaleY = true;
}
}
ComputeScaleAndOrigin();
}
-#if 0
-void wxDC::SetInternalDeviceOrigin( long x, long y )
-{
- m_internalDeviceOriginX = x;
- m_internalDeviceOriginY = y;
- ComputeScaleAndOrigin();
-}
-void wxDC::GetInternalDeviceOrigin( long *x, long *y )
-{
- if (x) *x = m_internalDeviceOriginX;
- if (y) *y = m_internalDeviceOriginY;
-}
-#endif
-
void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
{
m_signX = (xLeftRight ? 1 : -1);
{
// this is a bit artificial, but we need to force wxDC to think
// the pen has changed
- wxPen* pen = & GetPen();
- wxPen tempPen;
- m_pen = tempPen;
- SetPen(* pen);
+ wxPen pen(GetPen());
+ m_pen = wxNullPen;
+ SetPen(pen);
}
}
static double wxConvertWXangleToMACangle(double angle)
{
double newAngle = 90 - angle ;
- if ( newAngle < 0 )
- newAngle += 360 ;
+ while ( newAngle > 360 ) newAngle -= 360 ;
+ while ( newAngle < 0 ) newAngle += 360 ;
return newAngle ;
}
}
wxCoord alpha2 = wxCoord(radius2 - radius1);
wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1));
- if( (xx1 > xx2) || (yy1 > yy2) ) {
- alpha2 *= -1;
- }
+ while( alpha2 < 0 ) alpha2 += 360 ;
+ alpha2 = -alpha2 ;
Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad };
if(m_brush.GetStyle() != wxTRANSPARENT) {
MacInstallBrush();
wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc"));
wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC"));
if ( logical_func == wxNO_OP )
- return TRUE ;
+ return true ;
if (xsrcMask == -1 && ysrcMask == -1)
{
xsrcMask = xsrc; ysrcMask = ysrc;
if ( mode == kUnsupportedMode )
{
wxFAIL_MSG(wxT("unsupported blitting mode" ));
- return FALSE ;
+ return false ;
}
CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ;
PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ;
m_macPenInstalled = false ;
m_macBrushInstalled = false ;
m_macFontInstalled = false ;
- return TRUE;
+ return true;
}
-#ifndef FixedToInt
-// as macro in FixMath.h for 10.3
-inline Fixed IntToFixed( int inInt )
-{
- return (((SInt32) inInt) << 16);
-}
-
-inline int FixedToInt( Fixed inFixed )
-{
- return (((SInt32) inFixed) >> 16);
-}
-#endif
-
void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
double angle)
{
+ // TODO support text background color (only possible by hand, ATSUI does not support it)
wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
- if (angle == 0.0 )
- {
- DrawText(str, x, y);
- return;
- }
-
if ( str.Length() == 0 )
return ;
-
+
wxMacFastPortSetter helper(this) ;
MacInstallFont() ;
- wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
if ( 0 )
{
m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
- SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * font->m_macFontSize));
+ SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * m_font.MacGetFontSize()));
m_macAliasWasEnabled = true ;
}
OSStatus status = noErr ;
ATSUTextLayout atsuLayout ;
UniCharCount chars = str.Length() ;
+ UniChar* ubuf = NULL ;
+#if SIZEOF_WCHAR_T == 4
+ wxMBConvUTF16 converter ;
#if wxUSE_UNICODE
- status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
+ 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 ) ;
- int wlen = wxWcslen( wchar.data() ) ;
- status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) wchar.data() , 0 , wlen , wlen , 1 ,
- &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
+ 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 );
int drawX = XLOG2DEVMAC(x) ;
int drawY = YLOG2DEVMAC(y) ;
-
+
ATSUTextMeasurement textBefore ;
ATSUTextMeasurement textAfter ;
ATSUTextMeasurement ascent ;
ATSUTextMeasurement descent ;
-
-
+
+
if ( abs(iAngle) > 0 )
{
Fixed atsuAngle = IntToFixed( iAngle ) ;
}
status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
&textBefore , &textAfter, &ascent , &descent );
-
+
drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent));
drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent));
status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
::ATSUDisposeTextLayout(atsuLayout);
+#if SIZEOF_WCHAR_T == 4
+ free( ubuf ) ;
+#endif
}
void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
useDrawThemeText = false ;
#endif
MacInstallFont() ;
- if ( 0 )
- {
- m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
- SetAntiAliasedTextEnabled(true, 8);
- m_macAliasWasEnabled = true ;
- }
+
FontInfo fi ;
::GetFontInfo( &fi ) ;
#if TARGET_CARBON
{
::TextMode( srcCopy ) ;
}
- int length = strtext.Length() ;
-
- int laststop = 0 ;
- int i = 0 ;
int line = 0 ;
{
- while( i < length )
- {
- if( strtext[i] == 13 || strtext[i] == 10)
- {
- wxString linetext = strtext.Mid( laststop , i - laststop ) ;
-#if TARGET_CARBON
- if ( useDrawThemeText )
- {
- Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;
- wxMacCFStringHolder mString( linetext ) ;
- if ( m_backgroundMode != wxTRANSPARENT )
- {
- Point bounds={0,0} ;
- Rect background = frame ;
- SInt16 baseline ;
- ::GetThemeTextDimensions( mString,
- kThemeCurrentPortFont,
- kThemeStateActive,
- false,
- &bounds,
- &baseline );
- background.right = background.left + bounds.h ;
- background.bottom = background.top + bounds.v ;
- ::EraseRect( &background ) ;
- }
- ::DrawThemeTextBox( mString,
- kThemeCurrentPortFont,
- kThemeStateActive,
- false,
- &frame,
- teJustLeft,
- nil );
- line++ ;
- }
- else
-#endif
- {
- wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
- ::DrawText( text , 0 , strlen(text) ) ;
- line++ ;
- ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
- }
- laststop = i+1 ;
- }
- i++ ;
- }
- wxString linetext = strtext.Mid( laststop , i - laststop ) ;
+ wxString linetext = strtext ;
#if TARGET_CARBON
if ( useDrawThemeText )
{
Rect frame = { yy + line*(fi.descent + fi.ascent + fi.leading) ,xx , yy + (line+1)*(fi.descent + fi.ascent + fi.leading) , xx + 10000 } ;
- wxMacCFStringHolder mString( linetext ) ;
+ wxMacCFStringHolder mString( linetext , m_font.GetEncoding()) ;
if ( m_backgroundMode != wxTRANSPARENT )
{
Rect background = frame ;
SInt16 baseline ;
::GetThemeTextDimensions( mString,
- kThemeCurrentPortFont,
+ m_font.MacGetThemeFontID() ,
kThemeStateActive,
false,
&bounds,
::EraseRect( &background ) ;
}
::DrawThemeTextBox( mString,
- kThemeCurrentPortFont,
+ m_font.MacGetThemeFontID() ,
kThemeStateActive,
false,
&frame,
else
#endif
{
- wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
+ wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
::DrawText( text , 0 , strlen(text) ) ;
}
}
MacInstallFont() ;
FontInfo fi ;
::GetFontInfo( &fi ) ;
-#if TARGET_CARBON
+#if TARGET_CARBON
bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() )
useGetThemeText = false ;
*descent =YDEV2LOGREL( fi.descent );
if ( externalLeading )
*externalLeading = YDEV2LOGREL( fi.leading ) ;
- int length = strtext.Length() ;
- int laststop = 0 ;
- int i = 0 ;
int curwidth = 0 ;
if ( width )
{
*width = 0 ;
- while( i < length )
- {
- if( strtext[i] == 13 || strtext[i] == 10)
- {
- wxString linetext = strtext.Mid( laststop , i - laststop ) ;
- if ( height )
- *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ;
-#if TARGET_CARBON
- if ( useGetThemeText )
- {
- Point bounds={0,0} ;
- SInt16 baseline ;
- wxMacCFStringHolder mString( linetext ) ;
- ::GetThemeTextDimensions( mString,
- kThemeCurrentPortFont,
- kThemeStateActive,
- false,
- &bounds,
- &baseline );
- curwidth = bounds.h ;
- }
- else
-#endif
- {
- wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
- curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
- }
- if ( curwidth > *width )
- *width = XDEV2LOGREL( curwidth ) ;
- laststop = i+1 ;
- }
- i++ ;
- }
-
- wxString linetext = strtext.Mid( laststop , i - laststop ) ;
-#if TARGET_CARBON
+ wxString linetext = strtext ;
+
if ( useGetThemeText )
{
Point bounds={0,0} ;
SInt16 baseline ;
- wxMacCFStringHolder mString( linetext ) ;
+ wxMacCFStringHolder mString( linetext , m_font.GetEncoding() ) ;
+ ThemeFontID themeFont = m_font.MacGetThemeFontID() ;
::GetThemeTextDimensions( mString,
- kThemeCurrentPortFont,
+ themeFont ,
kThemeStateActive,
false,
&bounds,
curwidth = bounds.h ;
}
else
-#endif
{
- wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
+ wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )
}
}
+
+bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
+{
+ wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
+
+ widths.Empty();
+ widths.Add(0, text.Length());
+
+ if (text.Length() == 0)
+ return false;
+
+ wxMacFastPortSetter helper(this) ;
+ MacInstallFont() ;
+#if TARGET_CARBON
+ bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
+ if ( UMAGetSystemVersion() < 0x1000 || IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() )
+ useGetThemeText = false ;
+
+ if ( useGetThemeText )
+ {
+ // If anybody knows how to do this more efficiently yet still handle
+ // the fractional glyph widths that may be present when using AA
+ // fonts, please change it. Currently it is measuring from the
+ // begining of the string for each succeding substring, which is much
+ // slower than this should be.
+ for (size_t i=0; i<text.Length(); i++)
+ {
+ wxString str(text.Left(i+1));
+ Point bounds = {0,0};
+ SInt16 baseline ;
+ wxMacCFStringHolder mString(str, m_font.GetEncoding());
+ ::GetThemeTextDimensions( mString,
+ m_font.MacGetThemeFontID(),
+ kThemeStateActive,
+ false,
+ &bounds,
+ &baseline );
+ widths[i] = XDEV2LOGREL(bounds.h);
+ }
+ }
+ else
+#endif
+ {
+ wxCharBuffer buff = text.mb_str(wxConvLocal);
+ size_t len = strlen(buff);
+ short* measurements = new short[len+1];
+ MeasureText(len, buff.data(), measurements);
+
+ // Copy to widths, starting at measurements[1]
+ // NOTE: this doesn't take into account any multi-byte characters
+ // in buff, it probabkly should...
+ for (size_t i=0; i<text.Length(); i++)
+ widths[i] = XDEV2LOGREL(measurements[i+1]);
+
+ delete [] measurements;
+ }
+
+ return true;
+}
+
+
+
wxCoord wxDC::GetCharWidth(void) const
{
wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
if ( UMAGetSystemVersion() < 0x1000 || ((wxFont*)&m_font)->GetNoAntiAliasing() )
useGetThemeText = false ;
#endif
- char text[] = "H" ;
+ char text[] = "g" ;
#if TARGET_CARBON
if ( useGetThemeText )
{
SInt16 baseline ;
CFStringRef mString = CFStringCreateWithBytes( NULL , (UInt8*) text , 1 , CFStringGetSystemEncoding(), false ) ;
::GetThemeTextDimensions( mString,
- kThemeCurrentPortFont,
+ m_font.MacGetThemeFontID(),
kThemeStateActive,
false,
&bounds,
wxCHECK_RET(Ok(), wxT("Invalid DC"));
wxMacFastPortSetter helper(this) ;
Rect rect = { -31000 , -31000 , 31000 , 31000 } ;
- if (m_backgroundBrush.GetStyle() != wxTRANSPARENT)
+ if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
{
::PenNormal() ;
- //MacInstallBrush() ;
MacSetupBackgroundForCurrentPort( m_backgroundBrush ) ;
::EraseRect( &rect ) ;
}
// return ;
Pattern blackColor ;
MacSetupBackgroundForCurrentPort(m_backgroundBrush) ;
- wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
- if ( font )
- {
- ::TextFont( font->m_macFontNum ) ;
- ::TextSize( short(m_scaleY * font->m_macFontSize) ) ;
- ::TextFace( font->m_macFontStyle ) ;
- 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 );
- }
- else
+ if ( m_backgroundMode != wxTRANSPARENT )
{
- FontFamilyID fontId ;
- Str255 fontName ;
- SInt16 fontSize ;
- Style fontStyle ;
- GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
- GetFNum( fontName, &fontId );
- ::TextFont( fontId ) ;
- ::TextSize( short(m_scaleY * fontSize) ) ;
- ::TextFace( fontStyle ) ;
- // todo reset after spacing changes - or store the current spacing somewhere
- 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 );
+ 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 );
+
short mode = patCopy ;
// todo :
switch( m_logicalFunction )
}
::PenMode( mode ) ;
OSStatus status = noErr ;
- Fixed atsuSize = IntToFixed( int(m_scaleY * font->m_macFontSize) ) ;
- Style qdStyle = font->m_macFontStyle ;
- ATSUFontID atsuFont = font->m_macATSUFontID ;
- status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ;
- wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ;
+ 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[] =
{
- kATSUFontTag ,
kATSUSizeTag ,
- // kATSUColorTag ,
- // kATSUBaselineClassTag ,
- kATSUVerticalCharacterTag,
- kATSUQDBoldfaceTag ,
- kATSUQDItalicTag ,
- kATSUQDUnderlineTag ,
- kATSUQDCondensedTag ,
- kATSUQDExtendedTag ,
} ;
ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
{
- sizeof( ATSUFontID ) ,
sizeof( Fixed ) ,
- // sizeof( RGBColor ) ,
- // sizeof( BslnBaselineClass ) ,
- sizeof( ATSUVerticalCharacterType),
- sizeof( Boolean ) ,
- sizeof( Boolean ) ,
- sizeof( Boolean ) ,
- sizeof( Boolean ) ,
- sizeof( Boolean ) ,
} ;
- Boolean kTrue = true ;
- Boolean kFalse = false ;
- //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
- ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
+// Boolean kTrue = true ;
+// Boolean kFalse = false ;
+
+// ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
{
- &atsuFont ,
&atsuSize ,
- // &MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ,
- // &kBaselineDefault ,
- &kHorizontal,
- (qdStyle & bold) ? &kTrue : &kFalse ,
- (qdStyle & italic) ? &kTrue : &kFalse ,
- (qdStyle & underline) ? &kTrue : &kFalse ,
- (qdStyle & condense) ? &kTrue : &kFalse ,
- (qdStyle & extend) ? &kTrue : &kFalse ,
} ;
status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
atsuTags, atsuSizes, atsuValues);
- wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
+
+ 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 } ,
+ { { 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
+ { { 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 wxSHORT_DASH: index = 9; break;
case wxDOT_DASH: index = 10; break;
}
- *pattern = gPatterns[index];
+ *pattern = gPatterns[index];
}
void wxDC::MacInstallPen() const
{
wxCHECK_RET(Ok(), wxT("Invalid DC"));
- Pattern blackColor;
+ //Pattern blackColor;
// if ( m_macPenInstalled )
// return ;
RGBColor forecolor = MAC_WXCOLORREF( m_pen.GetColour().GetPixel());
if ( penWidth == 0 )
penWidth = 1 ;
::PenSize(penWidth, penWidth);
-
+
int penStyle = m_pen.GetStyle();
Pattern pat;
if (penStyle == wxUSER_DASH)
- {
+ {
// FIXME: there should be exactly 8 items in the dash
wxDash* dash ;
int number = m_pen.GetDashes(&dash) ;
void wxDC::MacSetupBackgroundForCurrentPort(const wxBrush& background )
{
Pattern whiteColor ;
- switch( background.MacGetBrushKind() )
+ if ( background.Ok() )
{
- case kwxMacBrushTheme :
- {
- ::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ;
- break ;
- }
- case kwxMacBrushThemeBackground :
- {
- Rect extent ;
- ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ;
- ::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ;
- break ;
- }
- case kwxMacBrushColour :
+ switch( background.MacGetBrushKind() )
{
- ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
- int brushStyle = background.GetStyle();
- if (brushStyle == wxSOLID)
- ::BackPat(GetQDGlobalsWhite(&whiteColor));
- else if (IS_HATCH(brushStyle))
+ case kwxMacBrushTheme :
{
- Pattern pat ;
- wxMacGetPattern(brushStyle, &pat);
- ::BackPat(&pat);
+ ::SetThemeBackground( background.MacGetTheme() , wxDisplayDepth() , true ) ;
+ break ;
}
- else
+ case kwxMacBrushThemeBackground :
{
- ::BackPat(GetQDGlobalsWhite(&whiteColor));
+ 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 ;
}
- break ;
}
}
}
{
::PenPat(GetQDGlobalsBlack(&blackColor));
}
- else if (IS_HATCH(brushStyle))
+ else if (m_brush.IsHatch())
{
Pattern pat ;
wxMacGetPattern(brushStyle, &pat);
int height = bitmap->GetHeight() ;
GWorldPtr gw = NULL ;
if ( m_brush.GetStyle() == wxSTIPPLE )
- gw = MAC_WXHBITMAP(bitmap->GetHBITMAP()) ;
+ gw = MAC_WXHBITMAP(bitmap->GetHBITMAP(NULL)) ;
else
- gw = MAC_WXHBITMAP(bitmap->GetMask()->GetMaskBitmap()) ;
+ gw = MAC_WXHBITMAP(bitmap->GetMask()->GetHBITMAP()) ;
PixMapHandle gwpixmaphandle = GetGWorldPixMap( gw ) ;
LockPixels( gwpixmaphandle ) ;
bool isMonochrome = !IsPortColor( gw ) ;
{
return ((wxDC *)this)->YLOG2DEVREL(y);
}
+
+#endif // !wxMAC_USE_CORE_GRAPHICS