X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c3b0c2c3dc1e2a76af69082f63149174525d97d5..ec35ed7c1cddff0638eba60af28e69d1e6ab46a2:/src/cocoa/dc.mm diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 681663b4aa..4b6e74c6af 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -12,6 +12,8 @@ #include "wx/dc.h" #include "wx/log.h" +#include "wx/cocoa/autorelease.h" + #import #import #import @@ -64,35 +66,26 @@ wxDC::~wxDC(void) void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,width,height)]; [m_textForegroundColour.GetNSColor() set]; [bezpath stroke]; [m_brush.GetNSColor() set]; [bezpath fill]; - - [context restoreGraphicsState]; } void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) { - NSGraphicsContext *context = [NSGraphicsContext currentContext]; - [context saveGraphicsState]; - NSBezierPath *bezpath = [NSBezierPath bezierPath]; [bezpath moveToPoint:NSMakePoint(x1,y1)]; [bezpath lineToPoint:NSMakePoint(x2,y2)]; [m_textForegroundColour.GetNSColor() set]; [bezpath stroke]; - - [context restoreGraphicsState]; } void wxDC::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, wxFont *theFont) const { + wxAutoNSAutoreleasePool pool; // FIXME: Cache this so it can be used for DoDrawText wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, "Text system has not been initialized. BAD PROGRAMMER!"); NSAttributedString *attributedString = [[NSAttributedString alloc] @@ -120,6 +113,20 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) [sm_cocoaNSTextStorage setAttributedString:attributedString]; [attributedString release]; + // Set the color (and later font) attributes + NSColor *fgColor = m_textForegroundColour.GetNSColor(); + NSColor *bgColor = m_textBackgroundColour.GetNSColor(); + if(!fgColor) + fgColor = [NSColor clearColor]; + if(!bgColor) + bgColor = [NSColor clearColor]; + NSDictionary *attrDict = [[NSDictionary alloc] initWithObjectsAndKeys: + fgColor, NSForegroundColorAttributeName, + bgColor, NSBackgroundColorAttributeName, + nil]; + [sm_cocoaNSTextStorage addAttributes: attrDict range:NSMakeRange(0,[sm_cocoaNSTextStorage length])]; + [attrDict release]; + NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer]; NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer]; // NOTE: We'll crash trying to get the location of glyphAtIndex:0 if @@ -160,8 +167,8 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) layoutLocation.x = 0.0; layoutLocation.y *= -1.0; layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0]; - // NOTE: That's NSMakePoint, not NSMakePint (working on that though) - [m_textForegroundColour.GetNSColor() set]; + if(m_backgroundMode==wxSOLID) + [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint]; [sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation]; [context restoreGraphicsState]; @@ -347,8 +354,9 @@ void wxDC::Clear() { } -void wxDC::SetBackground(const wxBrush&) +void wxDC::SetBackground(const wxBrush& brush) { + m_backgroundBrush = brush; } void wxDC::SetPalette(const wxPalette&)