aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CallTip.cxx8
-rw-r--r--src/EditView.cxx34
-rw-r--r--src/EditView.h8
-rw-r--r--src/Editor.cxx2
-rw-r--r--src/Editor.h31
-rw-r--r--src/MarginView.cxx18
-rw-r--r--src/MarginView.h6
7 files changed, 42 insertions, 65 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;