diff options
| -rw-r--r-- | src/CallTip.cxx | 8 | ||||
| -rw-r--r-- | src/EditView.cxx | 34 | ||||
| -rw-r--r-- | src/EditView.h | 8 | ||||
| -rw-r--r-- | src/Editor.cxx | 2 | ||||
| -rw-r--r-- | src/Editor.h | 31 | ||||
| -rw-r--r-- | src/MarginView.cxx | 18 | ||||
| -rw-r--r-- | src/MarginView.h | 6 | ||||
| -rw-r--r-- | win32/PlatWin.cxx | 80 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 82 | 
9 files changed, 117 insertions, 152 deletions
| diff --git a/src/CallTip.cxx b/src/CallTip.cxx index c3d1ca767..de2b37c63 100644 --- a/src/CallTip.cxx +++ b/src/CallTip.cxx @@ -12,6 +12,7 @@  #include <stdexcept>  #include <string>  #include <algorithm> +#include <memory>  #include "Platform.h" @@ -258,9 +259,7 @@ PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, co  	clickPlace = 0;  	val = defn;  	codePage = codePage_; -	Surface *surfaceMeasure = Surface::Allocate(technology); -	if (!surfaceMeasure) -		return PRectangle(); +	std::unique_ptr<Surface> surfaceMeasure(Surface::Allocate(technology));  	surfaceMeasure->Init(wParent.GetID());  	surfaceMeasure->SetUnicodeMode(SC_CP_UTF8 == codePage);  	surfaceMeasure->SetDBCSMode(codePage); @@ -279,7 +278,7 @@ PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, co  	rectUp = PRectangle(0,0,0,0);  	rectDown = PRectangle(0,0,0,0);  	offsetMain = insetX;            // changed to right edge of any arrows -	int width = PaintContents(surfaceMeasure, false) + insetX; +	const int width = PaintContents(surfaceMeasure.get(), false) + insetX;  	while ((newline = strchr(look, '\n')) != NULL) {  		look = newline + 1;  		numLines++; @@ -290,7 +289,6 @@ PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, co  	// rectangle is aligned to the right edge of the last arrow encountered in  	// the tip text, else to the tip text left edge.  	int height = lineHeight * numLines - static_cast<int>(surfaceMeasure->InternalLeading(font)) + borderHeight * 2; -	delete surfaceMeasure;  	if (above) {  		return PRectangle(pt.x - offsetMain, pt.y - verticalOffset - height, pt.x + width - offsetMain, pt.y - verticalOffset);  	} else { diff --git a/src/EditView.cxx b/src/EditView.cxx index 50555b0a1..d1ebc345a 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -175,7 +175,6 @@ void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRec  const XYPOSITION epsilon = 0.0001f;	// A small nudge to avoid floating point precision issues  EditView::EditView() { -	ldTabstops = NULL;  	tabWidthMinimumPixels = 2; // needed for calculating tab stops for fractional proportional fonts  	hideSelection = false;  	drawOverstrikeCaret = true; @@ -185,9 +184,6 @@ EditView::EditView() {  	additionalCaretsBlink = true;  	additionalCaretsVisible = true;  	imeCaretBlockOverride = false; -	pixmapLine = 0; -	pixmapIndentGuide = 0; -	pixmapIndentGuideHighlight = 0;  	llc.SetLevel(LineLayoutCache::llcCaret);  	posCache.SetSize(0x400);  	tabArrowHeight = 4; @@ -196,8 +192,6 @@ EditView::EditView() {  }  EditView::~EditView() { -	delete ldTabstops; -	ldTabstops = NULL;  }  bool EditView::SetTwoPhaseDraw(bool twoPhaseDraw) { @@ -219,8 +213,7 @@ bool EditView::LinesOverlap() const {  }  void EditView::ClearAllTabstops() { -	delete ldTabstops; -	ldTabstops = 0; +	ldTabstops.reset();  }  XYPOSITION EditView::NextTabstopPos(Sci::Line line, XYPOSITION x, XYPOSITION tabWidth) const { @@ -231,20 +224,20 @@ XYPOSITION EditView::NextTabstopPos(Sci::Line line, XYPOSITION x, XYPOSITION tab  }  bool EditView::ClearTabstops(Sci::Line line) { -	LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops); +	LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops.get());  	return lt && lt->ClearTabstops(line);  }  bool EditView::AddTabstop(Sci::Line line, int x) {  	if (!ldTabstops) { -		ldTabstops = new LineTabstops(); +		ldTabstops.reset(new LineTabstops());  	} -	LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops); +	LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops.get());  	return lt && lt->AddTabstop(line, x);  }  int EditView::GetNextTabstop(Sci::Line line, int x) const { -	const LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops); +	const LineTabstops *lt = static_cast<LineTabstops *>(ldTabstops.get());  	if (lt) {  		return lt->GetNextTabstop(line, x);  	} else { @@ -268,12 +261,9 @@ void EditView::LinesAddedOrRemoved(Sci::Line lineOfPos, Sci::Line linesAdded) {  void EditView::DropGraphics(bool freeObjects) {  	if (freeObjects) { -		delete pixmapLine; -		pixmapLine = 0; -		delete pixmapIndentGuide; -		pixmapIndentGuide = 0; -		delete pixmapIndentGuideHighlight; -		pixmapIndentGuideHighlight = 0; +		pixmapLine.reset(); +		pixmapIndentGuide.reset(); +		pixmapIndentGuideHighlight.reset();  	} else {  		if (pixmapLine)  			pixmapLine->Release(); @@ -286,11 +276,11 @@ void EditView::DropGraphics(bool freeObjects) {  void EditView::AllocateGraphics(const ViewStyle &vsDraw) {  	if (!pixmapLine) -		pixmapLine = Surface::Allocate(vsDraw.technology); +		pixmapLine.reset(Surface::Allocate(vsDraw.technology));  	if (!pixmapIndentGuide) -		pixmapIndentGuide = Surface::Allocate(vsDraw.technology); +		pixmapIndentGuide.reset(Surface::Allocate(vsDraw.technology));  	if (!pixmapIndentGuideHighlight) -		pixmapIndentGuideHighlight = Surface::Allocate(vsDraw.technology); +		pixmapIndentGuideHighlight.reset(Surface::Allocate(vsDraw.technology));  }  static const char *ControlCharacterString(unsigned char ch) { @@ -1984,7 +1974,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan  		Surface *surface = surfaceWindow;  		if (bufferedDraw) { -			surface = pixmapLine; +			surface = pixmapLine.get();  			PLATFORM_ASSERT(pixmapLine->Initialised());  		}  		surface->SetUnicodeMode(SC_CP_UTF8 == model.pdoc->dbcsCodePage); diff --git a/src/EditView.h b/src/EditView.h index 7a3926aa2..a842ac63a 100644 --- a/src/EditView.h +++ b/src/EditView.h @@ -50,7 +50,7 @@ typedef void (*DrawTabArrowFn)(Surface *surface, PRectangle rcTab, int ymid);  class EditView {  public:  	PrintParameters printParameters; -	PerLine *ldTabstops; +	std::unique_ptr<PerLine> ldTabstops;  	int tabWidthMinimumPixels;  	bool hideSelection; @@ -74,9 +74,9 @@ public:  	bool imeCaretBlockOverride; -	Surface *pixmapLine; -	Surface *pixmapIndentGuide; -	Surface *pixmapIndentGuideHighlight; +	std::unique_ptr<Surface> pixmapLine; +	std::unique_ptr<Surface> pixmapIndentGuide; +	std::unique_ptr<Surface> pixmapIndentGuideHighlight;  	LineLayoutCache llc;  	PositionCache posCache; diff --git a/src/Editor.cxx b/src/Editor.cxx index 5330ea45b..9344b7d94 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1653,7 +1653,7 @@ void Editor::PaintSelMargin(Surface *surfaceWindow, PRectangle &rc) {  	Surface *surface;  	if (view.bufferedDraw) { -		surface = marginView.pixmapSelMargin; +		surface = marginView.pixmapSelMargin.get();  	} else {  		surface = surfaceWindow;  	} diff --git a/src/Editor.h b/src/Editor.h index 9ddb753e6..69c816270 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -602,39 +602,34 @@ public:   */  class AutoSurface {  private: -	Surface *surf; +	std::unique_ptr<Surface> surf;  public: -	AutoSurface(Editor *ed, int technology = -1) : surf(0) { +	AutoSurface(Editor *ed, int technology = -1) {  		if (ed->wMain.GetID()) { -			surf = Surface::Allocate(technology != -1 ? technology : ed->technology); -			if (surf) { -				surf->Init(ed->wMain.GetID()); -				surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); -				surf->SetDBCSMode(ed->CodePage()); -			} +			surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology)); +			surf->Init(ed->wMain.GetID()); +			surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); +			surf->SetDBCSMode(ed->CodePage());  		}  	} -	AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) : surf(0) { +	AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) {  		if (ed->wMain.GetID()) { -			surf = Surface::Allocate(technology != -1 ? technology : ed->technology); -			if (surf) { -				surf->Init(sid, ed->wMain.GetID()); -				surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); -				surf->SetDBCSMode(ed->CodePage()); -			} +			surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology)); +			surf->Init(sid, ed->wMain.GetID()); +			surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); +			surf->SetDBCSMode(ed->CodePage());  		}  	}  	// Deleted so AutoSurface objects can not be copied.  	AutoSurface(const AutoSurface &) = delete;  	void operator=(const AutoSurface &) = delete;  	~AutoSurface() { -		delete surf;  	}  	Surface *operator->() const { -		return surf; +		return surf.get();  	}  	operator Surface *() const { -		return surf; +		return surf.get();  	}  }; diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 27bf1e10d..e371a4891 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -102,21 +102,15 @@ void DrawWrapMarker(Surface *surface, PRectangle rcPlace,  }  MarginView::MarginView() { -	pixmapSelMargin = 0; -	pixmapSelPattern = 0; -	pixmapSelPatternOffset1 = 0;  	wrapMarkerPaddingRight = 3;  	customDrawWrapMarker = NULL;  }  void MarginView::DropGraphics(bool freeObjects) {  	if (freeObjects) { -		delete pixmapSelMargin; -		pixmapSelMargin = 0; -		delete pixmapSelPattern; -		pixmapSelPattern = 0; -		delete pixmapSelPatternOffset1; -		pixmapSelPatternOffset1 = 0; +		pixmapSelMargin.reset(); +		pixmapSelPattern.reset(); +		pixmapSelPatternOffset1.reset();  	} else {  		if (pixmapSelMargin)  			pixmapSelMargin->Release(); @@ -129,11 +123,11 @@ void MarginView::DropGraphics(bool freeObjects) {  void MarginView::AllocateGraphics(const ViewStyle &vsDraw) {  	if (!pixmapSelMargin) -		pixmapSelMargin = Surface::Allocate(vsDraw.technology); +		pixmapSelMargin.reset(Surface::Allocate(vsDraw.technology));  	if (!pixmapSelPattern) -		pixmapSelPattern = Surface::Allocate(vsDraw.technology); +		pixmapSelPattern.reset(Surface::Allocate(vsDraw.technology));  	if (!pixmapSelPatternOffset1) -		pixmapSelPatternOffset1 = Surface::Allocate(vsDraw.technology); +		pixmapSelPatternOffset1.reset(Surface::Allocate(vsDraw.technology));  }  void MarginView::RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw) { diff --git a/src/MarginView.h b/src/MarginView.h index eb136d71e..695126ad9 100644 --- a/src/MarginView.h +++ b/src/MarginView.h @@ -21,9 +21,9 @@ typedef void (*DrawWrapMarkerFn)(Surface *surface, PRectangle rcPlace, bool isEn  */  class MarginView {  public: -	Surface *pixmapSelMargin; -	Surface *pixmapSelPattern; -	Surface *pixmapSelPatternOffset1; +	std::unique_ptr<Surface> pixmapSelMargin; +	std::unique_ptr<Surface> pixmapSelPattern; +	std::unique_ptr<Surface> pixmapSelPatternOffset1;  	// Highlight current folding block  	HighlightDelimiter highlightDelimiter; diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 31e71988a..ee1d2d71c 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -2309,54 +2309,46 @@ void ListBoxX::Draw(DRAWITEMSTRUCT *pDrawItem) {  		// Draw the image, if any  		const RGBAImage *pimage = images.Get(pixId);  		if (pimage) { -			Surface *surfaceItem = Surface::Allocate(technology); -			if (surfaceItem) { -				if (technology == SCWIN_TECH_GDI) { -					surfaceItem->Init(pDrawItem->hDC, pDrawItem->hwndItem); -					const long left = pDrawItem->rcItem.left + static_cast<int>(ItemInset.x + ImageInset.x); -					PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, -						left + images.GetWidth(), pDrawItem->rcItem.bottom); -					surfaceItem->DrawRGBAImage(rcImage, -						pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); -					delete surfaceItem; -					::SetTextAlign(pDrawItem->hDC, TA_TOP); -				} else { +			std::unique_ptr<Surface> surfaceItem(Surface::Allocate(technology)); +			if (technology == SCWIN_TECH_GDI) { +				surfaceItem->Init(pDrawItem->hDC, pDrawItem->hwndItem); +				const long left = pDrawItem->rcItem.left + static_cast<int>(ItemInset.x + ImageInset.x); +				PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, +					left + images.GetWidth(), pDrawItem->rcItem.bottom); +				surfaceItem->DrawRGBAImage(rcImage, +					pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); +				::SetTextAlign(pDrawItem->hDC, TA_TOP); +			} else {  #if defined(USE_D2D) -					D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties( -						D2D1_RENDER_TARGET_TYPE_DEFAULT, -						D2D1::PixelFormat( -							DXGI_FORMAT_B8G8R8A8_UNORM, -							D2D1_ALPHA_MODE_IGNORE), -						0, -						0, -						D2D1_RENDER_TARGET_USAGE_NONE, -						D2D1_FEATURE_LEVEL_DEFAULT -						); -					ID2D1DCRenderTarget *pDCRT = 0; -					HRESULT hr = pD2DFactory->CreateDCRenderTarget(&props, &pDCRT); +				D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties( +					D2D1_RENDER_TARGET_TYPE_DEFAULT, +					D2D1::PixelFormat( +						DXGI_FORMAT_B8G8R8A8_UNORM, +						D2D1_ALPHA_MODE_IGNORE), +					0, +					0, +					D2D1_RENDER_TARGET_USAGE_NONE, +					D2D1_FEATURE_LEVEL_DEFAULT +					); +				ID2D1DCRenderTarget *pDCRT = 0; +				HRESULT hr = pD2DFactory->CreateDCRenderTarget(&props, &pDCRT); +				if (SUCCEEDED(hr)) { +					RECT rcWindow; +					GetClientRect(pDrawItem->hwndItem, &rcWindow); +					hr = pDCRT->BindDC(pDrawItem->hDC, &rcWindow);  					if (SUCCEEDED(hr)) { -						RECT rcWindow; -						GetClientRect(pDrawItem->hwndItem, &rcWindow); -						hr = pDCRT->BindDC(pDrawItem->hDC, &rcWindow); -						if (SUCCEEDED(hr)) { -							surfaceItem->Init(pDCRT, pDrawItem->hwndItem); -							pDCRT->BeginDraw(); -							const long left = pDrawItem->rcItem.left + static_cast<long>(ItemInset.x + ImageInset.x); -							PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, -								left + images.GetWidth(), pDrawItem->rcItem.bottom); -							surfaceItem->DrawRGBAImage(rcImage, -								pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); -							delete surfaceItem; -							pDCRT->EndDraw(); -							pDCRT->Release(); -						} else { -							delete surfaceItem; -						} -					} else { -						delete surfaceItem; +						surfaceItem->Init(pDCRT, pDrawItem->hwndItem); +						pDCRT->BeginDraw(); +						const long left = pDrawItem->rcItem.left + static_cast<long>(ItemInset.x + ImageInset.x); +						PRectangle rcImage = PRectangle::FromInts(left, pDrawItem->rcItem.top, +							left + images.GetWidth(), pDrawItem->rcItem.bottom); +						surfaceItem->DrawRGBAImage(rcImage, +							pimage->GetWidth(), pimage->GetHeight(), pimage->Pixels()); +						pDCRT->EndDraw(); +						pDCRT->Release();  					} -#endif  				} +#endif  			}  		}  	} diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 155ebdb72..cb762e54a 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -3289,57 +3289,53 @@ LRESULT PASCAL ScintillaWin::CTWndProc(  			} else if (iMessage == WM_PAINT) {  				PAINTSTRUCT ps;  				::BeginPaint(hWnd, &ps); -				Surface *surfaceWindow = Surface::Allocate(sciThis->technology); -				if (surfaceWindow) { +				std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(sciThis->technology));  #if defined(USE_D2D) -					ID2D1HwndRenderTarget *pCTRenderTarget = 0; +				ID2D1HwndRenderTarget *pCTRenderTarget = 0;  #endif -					RECT rc; -					GetClientRect(hWnd, &rc); -					// Create a Direct2D render target. -					if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) { -						surfaceWindow->Init(ps.hdc, hWnd); -					} else { +				RECT rc; +				GetClientRect(hWnd, &rc); +				// Create a Direct2D render target. +				if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) { +					surfaceWindow->Init(ps.hdc, hWnd); +				} else {  #if defined(USE_D2D) -						D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp; -						dhrtp.hwnd = hWnd; -						dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); -						dhrtp.presentOptions = (sciThis->technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ? -							D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE; - -						D2D1_RENDER_TARGET_PROPERTIES drtp; -						drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; -						drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN; -						drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; -						drtp.dpiX = 96.0; -						drtp.dpiY = 96.0; -						drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE; -						drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; - -						if (!SUCCEEDED(pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pCTRenderTarget))) { -							surfaceWindow->Release(); -							delete surfaceWindow; -							::EndPaint(hWnd, &ps); -							return 0; -						} -						surfaceWindow->Init(pCTRenderTarget, hWnd); -						pCTRenderTarget->BeginDraw(); -#endif +					D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp; +					dhrtp.hwnd = hWnd; +					dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); +					dhrtp.presentOptions = (sciThis->technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ? +						D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE; + +					D2D1_RENDER_TARGET_PROPERTIES drtp; +					drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; +					drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN; +					drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; +					drtp.dpiX = 96.0; +					drtp.dpiY = 96.0; +					drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE; +					drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; + +					if (!SUCCEEDED(pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pCTRenderTarget))) { +						surfaceWindow->Release(); +						::EndPaint(hWnd, &ps); +						return 0;  					} -					surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage); -					surfaceWindow->SetDBCSMode(sciThis->ct.codePage); -					sciThis->ct.PaintCT(surfaceWindow); +					surfaceWindow->Init(pCTRenderTarget, hWnd); +					pCTRenderTarget->BeginDraw(); +#endif +				} +				surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage); +				surfaceWindow->SetDBCSMode(sciThis->ct.codePage); +				sciThis->ct.PaintCT(surfaceWindow.get());  #if defined(USE_D2D) -					if (pCTRenderTarget) -						pCTRenderTarget->EndDraw(); +				if (pCTRenderTarget) +					pCTRenderTarget->EndDraw();  #endif -					surfaceWindow->Release(); -					delete surfaceWindow; +				surfaceWindow->Release();  #if defined(USE_D2D) -					if (pCTRenderTarget) -						pCTRenderTarget->Release(); +				if (pCTRenderTarget) +					pCTRenderTarget->Release();  #endif -				}  				::EndPaint(hWnd, &ps);  				return 0;  			} else if ((iMessage == WM_NCLBUTTONDOWN) || (iMessage == WM_NCLBUTTONDBLCLK)) { | 
