aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2022-03-12 10:24:52 +1100
committerNeil <nyamatongwe@gmail.com>2022-03-12 10:24:52 +1100
commit73ae9e3d2ad7fddbe8945deb0647dd7597d58c0a (patch)
tree3cb9fa0661146e7ae93beeb9aedca4e05df3f98b /src
parent149197611993b19d4abae1012c52d7fec4fcaa2d (diff)
downloadscintilla-mirror-73ae9e3d2ad7fddbe8945deb0647dd7597d58c0a.tar.gz
Feature [feature-requests:#1432] Move some surface creation out of headers and
make virtual to allow customisation by platform layers.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx20
-rw-r--r--src/Editor.h18
2 files changed, 26 insertions, 12 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index f048a5030..bbac4862a 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -5687,6 +5687,26 @@ int Editor::CodePage() const noexcept {
return 0;
}
+std::unique_ptr<Surface> Editor::CreateMeasurementSurface() const {
+ if (!wMain.GetID()) {
+ return {};
+ }
+ std::unique_ptr<Surface> surf = Surface::Allocate(technology);
+ surf->Init(wMain.GetID());
+ surf->SetMode(CurrentSurfaceMode());
+ return surf;
+}
+
+std::unique_ptr<Surface> Editor::CreateDrawingSurface(SurfaceID sid, std::optional<Scintilla::Technology> technologyOpt) const {
+ if (!wMain.GetID()) {
+ return {};
+ }
+ std::unique_ptr<Surface> surf = Surface::Allocate(technologyOpt ? *technologyOpt : technology);
+ surf->Init(sid, wMain.GetID());
+ surf->SetMode(CurrentSurfaceMode());
+ return surf;
+}
+
Sci::Line Editor::WrapCount(Sci::Line line) {
AutoSurface surface(this);
std::shared_ptr<LineLayout> ll = view.RetrieveLineLayout(line, *this);
diff --git a/src/Editor.h b/src/Editor.h
index fd140a800..a430a23d4 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -592,6 +592,8 @@ protected: // ScintillaBase subclass needs access to much of Editor
virtual bool ValidCodePage(int /* codePage */) const { return true; }
virtual std::string UTF8FromEncoded(std::string_view encoded) const = 0;
virtual std::string EncodedFromUTF8(std::string_view utf8) const = 0;
+ virtual std::unique_ptr<Surface> CreateMeasurementSurface() const;
+ virtual std::unique_ptr<Surface> CreateDrawingSurface(SurfaceID sid, std::optional<Scintilla::Technology> technologyOpt = {}) const;
Sci::Line WrapCount(Sci::Line line);
void AddStyledText(const char *buffer, Sci::Position appendLength);
@@ -684,19 +686,11 @@ class AutoSurface {
private:
std::unique_ptr<Surface> surf;
public:
- AutoSurface(const Editor *ed) {
- if (ed->wMain.GetID()) {
- surf = Surface::Allocate(ed->technology);
- surf->Init(ed->wMain.GetID());
- surf->SetMode(ed->CurrentSurfaceMode());
- }
+ AutoSurface(const Editor *ed) :
+ surf(ed->CreateMeasurementSurface()) {
}
- AutoSurface(SurfaceID sid, Editor *ed, std::optional<Scintilla::Technology> technology = {}) {
- if (ed->wMain.GetID()) {
- surf = Surface::Allocate(technology ? *technology : ed->technology);
- surf->Init(sid, ed->wMain.GetID());
- surf->SetMode(ed->CurrentSurfaceMode());
- }
+ AutoSurface(SurfaceID sid, Editor *ed, std::optional<Scintilla::Technology> technology = {}) :
+ surf(ed->CreateDrawingSurface(sid, technology)) {
}
// Deleted so AutoSurface objects can not be copied.
AutoSurface(const AutoSurface &) = delete;