From aac6399324495f2dffe8b52c1f4bcfbe931bc3ff Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 2 May 2017 10:35:33 +1000 Subject: For Cocoa, use unique_ptr for drawing surfaces and don't check for allocation failure as that throws an exception. --- cocoa/ScintillaCocoa.mm | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'cocoa/ScintillaCocoa.mm') diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 505afd4c7..5c89ed765 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -1086,15 +1086,12 @@ void ScintillaCocoa::Paste(bool forceRectangular) void ScintillaCocoa::CTPaint(void* gc, NSRect rc) { #pragma unused(rc) - Surface *surfaceWindow = Surface::Allocate(SC_TECHNOLOGY_DEFAULT); - if (surfaceWindow) { - surfaceWindow->Init(gc, wMain.GetID()); - surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ct.codePage); - surfaceWindow->SetDBCSMode(ct.codePage); - ct.PaintCT(surfaceWindow); - surfaceWindow->Release(); - delete surfaceWindow; - } + std::unique_ptr surfaceWindow(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + surfaceWindow->Init(gc, wMain.GetID()); + surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ct.codePage); + surfaceWindow->SetDBCSMode(ct.codePage); + ct.PaintCT(surfaceWindow.get()); + surfaceWindow->Release(); } @interface CallTipView : NSControl { @@ -1815,23 +1812,18 @@ bool ScintillaCocoa::SyncPaint(void* gc, PRectangle rc) rcPaint = rc; PRectangle rcText = GetTextRectangle(); paintingAllText = rcPaint.Contains(rcText); - bool succeeded = true; - Surface *sw = Surface::Allocate(SC_TECHNOLOGY_DEFAULT); - if (sw) - { - CGContextSetAllowsAntialiasing((CGContextRef)gc, - vs.extraFontFlag != SC_EFF_QUALITY_NON_ANTIALIASED); - CGContextSetAllowsFontSmoothing((CGContextRef)gc, - vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); - CGContextSetAllowsFontSubpixelPositioning((CGContextRef)gc, - vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT || - vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); - sw->Init(gc, wMain.GetID()); - Paint(sw, rc); - succeeded = paintState != paintAbandoned; - sw->Release(); - delete sw; - } + std::unique_ptr sw(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + CGContextSetAllowsAntialiasing((CGContextRef)gc, + vs.extraFontFlag != SC_EFF_QUALITY_NON_ANTIALIASED); + CGContextSetAllowsFontSmoothing((CGContextRef)gc, + vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); + CGContextSetAllowsFontSubpixelPositioning((CGContextRef)gc, + vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT || + vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); + sw->Init(gc, wMain.GetID()); + Paint(sw.get(), rc); + const bool succeeded = paintState != paintAbandoned; + sw->Release(); paintState = notPainting; if (!succeeded) { -- cgit v1.2.3