diff options
author | Neil <nyamatongwe@gmail.com> | 2021-05-24 19:31:06 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-05-24 19:31:06 +1000 |
commit | 92290868cf9753d2df0d494cb44e2ff62a570b58 (patch) | |
tree | 001e6cfce84372a03997de3138d630751ee8d38a /src/Document.cxx | |
parent | ee1886079d0a5cd350ee8e3379be347943ba93ae (diff) | |
download | scintilla-mirror-92290868cf9753d2df0d494cb44e2ff62a570b58.tar.gz |
Define C++ version of the Scintilla API in ScintillaTypes.h, ScintillaMessages.h
and ScintillaStructures.h using scoped enumerations.
Use these headers instead of Scintilla.h internally.
External definitions go in the Scintilla namespace and internal definitio0ns in
Scintilla::Internal.
Diffstat (limited to 'src/Document.cxx')
-rw-r--r-- | src/Document.cxx | 309 |
1 files changed, 158 insertions, 151 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index c8f474eaa..70a711028 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -26,11 +26,11 @@ #include <regex> #endif -#include "Debugging.h" - +#include "ScintillaTypes.h" #include "ILoader.h" #include "ILexer.h" -#include "Scintilla.h" + +#include "Debugging.h" #include "CharacterType.h" #include "CharacterCategoryMap.h" @@ -49,6 +49,7 @@ #include "ElapsedPeriod.h" using namespace Scintilla; +using namespace Scintilla::Internal; void LexInterface::Colourise(Sci::Position start, Sci::Position end) { if (pdoc && instance && !performingStyle) { @@ -78,11 +79,11 @@ void LexInterface::Colourise(Sci::Position start, Sci::Position end) { } } -int LexInterface::LineEndTypesSupported() { +LineEndType LexInterface::LineEndTypesSupported() { if (instance) { - return instance->LineEndTypesSupported(); + return static_cast<LineEndType>(instance->LineEndTypesSupported()); } - return 0; + return LineEndType::Default; } ActionDuration::ActionDuration(double duration_, double minDuration_, double maxDuration_) noexcept : @@ -111,17 +112,17 @@ size_t ActionDuration::ActionsInAllowedTime(double secondsAllowed) const noexcep return std::lround(secondsAllowed / Duration()); } -Document::Document(int options) : - cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0, (options & SC_DOCUMENTOPTION_TEXT_LARGE) != 0), +Document::Document(DocumentOption options) : + cb((FlagSet(options, DocumentOption::StylesNone)) == 0, (FlagSet(options, DocumentOption::TextLarge)) != 0), durationStyleOneByte(0.000001, 0.0000001, 0.00001) { refCount = 0; #ifdef _WIN32 - eolMode = SC_EOL_CRLF; + eolMode = EndOfLine::CrLf; #else - eolMode = SC_EOL_LF; + eolMode = EndOfLine::Lf; #endif - dbcsCodePage = SC_CP_UTF8; - lineEndBitSet = SC_LINE_END_TYPE_DEFAULT; + dbcsCodePage = CpUtf8; + lineEndBitSet = LineEndType::Default; endStyled = 0; styleClock = 0; enteredModification = 0; @@ -147,7 +148,7 @@ Document::Document(int options) : decorations = DecorationListCreate(IsLarge()); cb.SetPerLine(this); - cb.SetUTF8Substance(SC_CP_UTF8 == dbcsCodePage); + cb.SetUTF8Substance(CpUtf8 == dbcsCodePage); } Document::~Document() { @@ -222,11 +223,11 @@ LineAnnotation *Document::EOLAnnotations() const noexcept { return dynamic_cast<LineAnnotation *>(perLineData[ldEOLAnnotation].get()); } -int Document::LineEndTypesSupported() const { - if ((SC_CP_UTF8 == dbcsCodePage) && pli) +LineEndType Document::LineEndTypesSupported() const { + if ((CpUtf8 == dbcsCodePage) && pli) return pli->LineEndTypesSupported(); else - return 0; + return LineEndType::Default; } bool Document::SetDBCSCodePage(int dbcsCodePage_) { @@ -234,7 +235,7 @@ bool Document::SetDBCSCodePage(int dbcsCodePage_) { dbcsCodePage = dbcsCodePage_; SetCaseFolder(nullptr); cb.SetLineEndTypes(lineEndBitSet & LineEndTypesSupported()); - cb.SetUTF8Substance(SC_CP_UTF8 == dbcsCodePage); + cb.SetUTF8Substance(CpUtf8 == dbcsCodePage); ModifiedAt(0); // Need to restyle whole document return true; } else { @@ -242,10 +243,10 @@ bool Document::SetDBCSCodePage(int dbcsCodePage_) { } } -bool Document::SetLineEndTypesAllowed(int lineEndBitSet_) { +bool Document::SetLineEndTypesAllowed(LineEndType lineEndBitSet_) { if (lineEndBitSet != lineEndBitSet_) { lineEndBitSet = lineEndBitSet_; - const int lineEndBitSetActive = lineEndBitSet & LineEndTypesSupported(); + const LineEndType lineEndBitSetActive = lineEndBitSet & LineEndTypesSupported(); if (lineEndBitSetActive != cb.GetLineEndTypes()) { ModifiedAt(0); cb.SetLineEndTypes(lineEndBitSetActive); @@ -279,36 +280,36 @@ void Document::TentativeUndo() { const Action &action = cb.GetUndoStep(); if (action.at == ActionType::remove) { NotifyModified(DocModification( - SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); + ModificationFlags::BeforeInsert | ModificationFlags::Undo, action)); } else if (action.at == ActionType::container) { - DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_UNDO); + DocModification dm(ModificationFlags::Container | ModificationFlags::Undo); dm.token = action.position; NotifyModified(dm); } else { NotifyModified(DocModification( - SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action)); + ModificationFlags::BeforeDelete | ModificationFlags::Undo, action)); } cb.PerformUndoStep(); if (action.at != ActionType::container) { ModifiedAt(action.position); } - int modFlags = SC_PERFORMED_UNDO; + ModificationFlags modFlags = ModificationFlags::Undo; // With undo, an insertion action becomes a deletion notification if (action.at == ActionType::remove) { - modFlags |= SC_MOD_INSERTTEXT; + modFlags |= ModificationFlags::InsertText; } else if (action.at == ActionType::insert) { - modFlags |= SC_MOD_DELETETEXT; + modFlags |= ModificationFlags::DeleteText; } if (steps > 1) - modFlags |= SC_MULTISTEPUNDOREDO; + modFlags |= ModificationFlags::MultiStepUndoRedo; const Sci::Line linesAdded = LinesTotal() - prevLinesTotal; if (linesAdded != 0) multiLine = true; if (step == steps - 1) { - modFlags |= SC_LASTSTEPINUNDOREDO; + modFlags |= ModificationFlags::LastStepInUndoRedo; if (multiLine) - modFlags |= SC_MULTILINEUNDOREDO; + modFlags |= ModificationFlags::MultilineUndoRedo; } NotifyModified(DocModification(modFlags, action.position, action.lenData, linesAdded, action.data.get())); @@ -335,7 +336,7 @@ Sci::Line Document::MarkerNext(Sci::Line lineStart, int mask) const noexcept { int Document::AddMark(Sci::Line line, int markerNum) { if (line >= 0 && line <= LinesTotal()) { const int prev = Markers()->AddMark(line, markerNum, LinesTotal()); - const DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, nullptr, line); + const DocModification mh(ModificationFlags::ChangeMarker, LineStart(line), 0, 0, nullptr, line); NotifyModified(mh); return prev; } else { @@ -352,19 +353,19 @@ void Document::AddMarkSet(Sci::Line line, int valueSet) { if (m & 1) Markers()->AddMark(line, i, LinesTotal()); } - const DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, nullptr, line); + const DocModification mh(ModificationFlags::ChangeMarker, LineStart(line), 0, 0, nullptr, line); NotifyModified(mh); } void Document::DeleteMark(Sci::Line line, int markerNum) { Markers()->DeleteMark(line, markerNum, false); - const DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, nullptr, line); + const DocModification mh(ModificationFlags::ChangeMarker, LineStart(line), 0, 0, nullptr, line); NotifyModified(mh); } void Document::DeleteMarkFromHandle(int markerHandle) { Markers()->DeleteMarkFromHandle(markerHandle); - DocModification mh(SC_MOD_CHANGEMARKER); + DocModification mh(ModificationFlags::ChangeMarker); mh.line = -1; NotifyModified(mh); } @@ -376,7 +377,7 @@ void Document::DeleteAllMarks(int markerNum) { someChanges = true; } if (someChanges) { - DocModification mh(SC_MOD_CHANGEMARKER); + DocModification mh(ModificationFlags::ChangeMarker); mh.line = -1; NotifyModified(mh); } @@ -407,7 +408,7 @@ Sci_Position SCI_METHOD Document::LineEnd(Sci_Position line) const { return LineStart(line + 1); } else { Sci::Position position = LineStart(line + 1); - if (SC_LINE_END_TYPE_UNICODE == cb.GetLineEndTypes()) { + if (LineEndType::Unicode == cb.GetLineEndTypes()) { const unsigned char bytes[] = { cb.UCharAt(position-3), cb.UCharAt(position-2), @@ -432,7 +433,7 @@ Sci_Position SCI_METHOD Document::LineEnd(Sci_Position line) const { void SCI_METHOD Document::SetErrorStatus(int status) { // Tell the watchers an error has occurred. for (const WatcherWithUserData &watcher : watchers) { - watcher.watcher->NotifyErrorOccurred(this, watcher.userData, status); + watcher.watcher->NotifyErrorOccurred(this, watcher.userData, static_cast<Status>(status)); } } @@ -470,11 +471,11 @@ Sci::Position Document::VCHomePosition(Sci::Position position) const { return startText; } -Sci::Position Document::IndexLineStart(Sci::Line line, int lineCharacterIndex) const noexcept { +Sci::Position Document::IndexLineStart(Sci::Line line, LineCharacterIndexType lineCharacterIndex) const noexcept { return cb.IndexLineStart(line, lineCharacterIndex); } -Sci::Line Document::LineFromPositionIndex(Sci::Position pos, int lineCharacterIndex) const noexcept { +Sci::Line Document::LineFromPositionIndex(Sci::Position pos, LineCharacterIndexType lineCharacterIndex) const noexcept { return cb.LineFromPositionIndex(pos, lineCharacterIndex); } @@ -495,10 +496,10 @@ Sci::Line Document::LineFromPositionAfter(Sci::Line line, Sci::Position length) int SCI_METHOD Document::SetLevel(Sci_Position line, int level) { const int prev = Levels()->SetLevel(line, level, LinesTotal()); if (prev != level) { - DocModification mh(SC_MOD_CHANGEFOLD | SC_MOD_CHANGEMARKER, + DocModification mh(ModificationFlags::ChangeFold | ModificationFlags::ChangeMarker, LineStart(line), 0, 0, nullptr, line); - mh.foldLevelNow = level; - mh.foldLevelPrev = prev; + mh.foldLevelNow = static_cast<FoldLevel>(level); + mh.foldLevelPrev = static_cast<FoldLevel>(prev); NotifyModified(mh); } return prev; @@ -508,35 +509,39 @@ int SCI_METHOD Document::GetLevel(Sci_Position line) const { return Levels()->GetLevel(line); } +FoldLevel Document::GetFoldLevel(Sci_Position line) const { + return static_cast<FoldLevel>(Levels()->GetLevel(line)); +} + void Document::ClearLevels() { Levels()->ClearLevels(); } -static bool IsSubordinate(int levelStart, int levelTry) noexcept { +static bool IsSubordinate(FoldLevel levelStart, FoldLevel levelTry) noexcept { if (LevelIsWhitespace(levelTry)) return true; else return LevelNumber(levelStart) < LevelNumber(levelTry); } -Sci::Line Document::GetLastChild(Sci::Line lineParent, int level, Sci::Line lastLine) { - if (level == -1) - level = LevelNumber(GetLevel(lineParent)); +Sci::Line Document::GetLastChild(Sci::Line lineParent, std::optional<FoldLevel> level, Sci::Line lastLine) { + if (!level) + level = LevelNumberPart(GetFoldLevel(lineParent)); const Sci::Line maxLine = LinesTotal(); const Sci::Line lookLastLine = (lastLine != -1) ? std::min(LinesTotal() - 1, lastLine) : -1; Sci::Line lineMaxSubord = lineParent; while (lineMaxSubord < maxLine - 1) { EnsureStyledTo(LineStart(lineMaxSubord + 2)); - if (!IsSubordinate(level, GetLevel(lineMaxSubord + 1))) + if (!IsSubordinate(*level, GetFoldLevel(lineMaxSubord + 1))) break; - if ((lookLastLine != -1) && (lineMaxSubord >= lookLastLine) && !LevelIsWhitespace(GetLevel(lineMaxSubord))) + if ((lookLastLine != -1) && (lineMaxSubord >= lookLastLine) && !LevelIsWhitespace(GetFoldLevel(lineMaxSubord))) break; lineMaxSubord++; } if (lineMaxSubord > lineParent) { - if (level > LevelNumber(GetLevel(lineMaxSubord + 1))) { + if (level > LevelNumberPart(GetFoldLevel(lineMaxSubord + 1))) { // Have chewed up some whitespace that belongs to a parent so seek back - if (LevelIsWhitespace(GetLevel(lineMaxSubord))) { + if (LevelIsWhitespace(GetFoldLevel(lineMaxSubord))) { lineMaxSubord--; } } @@ -545,16 +550,16 @@ Sci::Line Document::GetLastChild(Sci::Line lineParent, int level, Sci::Line last } Sci::Line Document::GetFoldParent(Sci::Line line) const { - const int level = LevelNumber(GetLevel(line)); + const FoldLevel level = LevelNumberPart(GetFoldLevel(line)); Sci::Line lineLook = line - 1; while ((lineLook > 0) && ( - (!LevelIsHeader(GetLevel(lineLook))) || - (LevelNumber(GetLevel(lineLook)) >= level)) + (!LevelIsHeader(GetFoldLevel(lineLook))) || + (LevelNumberPart(GetFoldLevel(lineLook)) >= level)) ) { lineLook--; } - if (LevelIsHeader(GetLevel(lineLook)) && - (LevelNumber(GetLevel(lineLook)) < level)) { + if (LevelIsHeader(GetFoldLevel(lineLook)) && + (LevelNumberPart(GetFoldLevel(lineLook)) < level)) { return lineLook; } else { return -1; @@ -562,16 +567,16 @@ Sci::Line Document::GetFoldParent(Sci::Line line) const { } void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sci::Line line, Sci::Line lastLine) { - const int level = GetLevel(line); + const FoldLevel level = GetFoldLevel(line); const Sci::Line lookLastLine = std::max(line, lastLine) + 1; Sci::Line lookLine = line; - int lookLineLevel = level; - int lookLineLevelNum = LevelNumber(lookLineLevel); + FoldLevel lookLineLevel = level; + FoldLevel lookLineLevelNum = LevelNumberPart(lookLineLevel); while ((lookLine > 0) && (LevelIsWhitespace(lookLineLevel) || - (LevelIsHeader(lookLineLevel) && (lookLineLevelNum >= LevelNumber(GetLevel(lookLine + 1)))))) { - lookLineLevel = GetLevel(--lookLine); - lookLineLevelNum = LevelNumber(lookLineLevel); + (LevelIsHeader(lookLineLevel) && (lookLineLevelNum >= LevelNumberPart(GetFoldLevel(lookLine + 1)))))) { + lookLineLevel = GetFoldLevel(--lookLine); + lookLineLevelNum = LevelNumberPart(lookLineLevel); } Sci::Line beginFoldBlock = LevelIsHeader(lookLineLevel) ? lookLine : GetFoldParent(lookLine); @@ -580,31 +585,31 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sc return; } - Sci::Line endFoldBlock = GetLastChild(beginFoldBlock, -1, lookLastLine); + Sci::Line endFoldBlock = GetLastChild(beginFoldBlock, {}, lookLastLine); Sci::Line firstChangeableLineBefore = -1; if (endFoldBlock < line) { lookLine = beginFoldBlock - 1; - lookLineLevel = GetLevel(lookLine); - lookLineLevelNum = LevelNumber(lookLineLevel); - while ((lookLine >= 0) && (lookLineLevelNum >= SC_FOLDLEVELBASE)) { + lookLineLevel = GetFoldLevel(lookLine); + lookLineLevelNum = LevelNumberPart(lookLineLevel); + while ((lookLine >= 0) && (lookLineLevelNum >= FoldLevel::Base)) { if (LevelIsHeader(lookLineLevel)) { - if (GetLastChild(lookLine, -1, lookLastLine) == line) { + if (GetLastChild(lookLine, {}, lookLastLine) == line) { beginFoldBlock = lookLine; endFoldBlock = line; firstChangeableLineBefore = line - 1; } } - if ((lookLine > 0) && (lookLineLevelNum == SC_FOLDLEVELBASE) && (LevelNumber(GetLevel(lookLine - 1)) > lookLineLevelNum)) + if ((lookLine > 0) && (lookLineLevelNum == FoldLevel::Base) && (LevelNumberPart(GetFoldLevel(lookLine - 1)) > lookLineLevelNum)) break; - lookLineLevel = GetLevel(--lookLine); - lookLineLevelNum = LevelNumber(lookLineLevel); + lookLineLevel = GetFoldLevel(--lookLine); + lookLineLevelNum = LevelNumberPart(lookLineLevel); } } if (firstChangeableLineBefore == -1) { - for (lookLine = line - 1, lookLineLevel = GetLevel(lookLine), lookLineLevelNum = LevelNumber(lookLineLevel); + for (lookLine = line - 1, lookLineLevel = GetFoldLevel(lookLine), lookLineLevelNum = LevelNumberPart(lookLineLevel); lookLine >= beginFoldBlock; - lookLineLevel = GetLevel(--lookLine), lookLineLevelNum = LevelNumber(lookLineLevel)) { - if (LevelIsWhitespace(lookLineLevel) || (lookLineLevelNum > LevelNumber(level))) { + lookLineLevel = GetFoldLevel(--lookLine), lookLineLevelNum = LevelNumberPart(lookLineLevel)) { + if (LevelIsWhitespace(lookLineLevel) || (lookLineLevelNum > LevelNumberPart(level))) { firstChangeableLineBefore = lookLine; break; } @@ -614,10 +619,10 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sc firstChangeableLineBefore = beginFoldBlock - 1; Sci::Line firstChangeableLineAfter = -1; - for (lookLine = line + 1, lookLineLevel = GetLevel(lookLine), lookLineLevelNum = LevelNumber(lookLineLevel); + for (lookLine = line + 1, lookLineLevel = GetFoldLevel(lookLine), lookLineLevelNum = LevelNumberPart(lookLineLevel); lookLine <= endFoldBlock; - lookLineLevel = GetLevel(++lookLine), lookLineLevelNum = LevelNumber(lookLineLevel)) { - if (LevelIsHeader(lookLineLevel) && (lookLineLevelNum < LevelNumber(GetLevel(lookLine + 1)))) { + lookLineLevel = GetFoldLevel(++lookLine), lookLineLevelNum = LevelNumberPart(lookLineLevel)) { + if (LevelIsHeader(lookLineLevel) && (lookLineLevelNum < LevelNumberPart(GetFoldLevel(lookLine + 1)))) { firstChangeableLineAfter = lookLine; break; } @@ -656,7 +661,7 @@ int Document::LenChar(Sci::Position pos) const noexcept { // Common case: ASCII character return 1; } - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { const int widthCharBytes = UTF8BytesOfLead[leadByte]; unsigned char charBytes[UTF8MaxBytes] = { leadByte, 0, 0, 0 }; for (int b = 1; b < widthCharBytes; b++) { @@ -727,7 +732,7 @@ Sci::Position Document::MovePositionOutsideChar(Sci::Position pos, Sci::Position } if (dbcsCodePage) { - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { const unsigned char ch = cb.UCharAt(pos); // If ch is not a trail byte then pos is valid intercharacter position if (UTF8IsTrailByte(ch)) { @@ -786,7 +791,7 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexc return cb.Length(); if (dbcsCodePage) { - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { if (increment == 1) { // Simple forward movement case so can avoid some checks const unsigned char leadByte = cb.UCharAt(pos); @@ -875,7 +880,7 @@ Document::CharacterExtracted Document::CharacterAfter(Sci::Position position) co // Common case: ASCII character return CharacterExtracted(leadByte, 1); } - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { const int widthCharBytes = UTF8BytesOfLead[leadByte]; unsigned char charBytes[UTF8MaxBytes] = { leadByte, 0, 0, 0 }; for (int b = 1; b<widthCharBytes; b++) @@ -904,7 +909,7 @@ Document::CharacterExtracted Document::CharacterBefore(Sci::Position position) c if (0 == dbcsCodePage) { return CharacterExtracted(previousByte, 1); } - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { if (UTF8IsAscii(previousByte)) { return CharacterExtracted(previousByte, 1); } @@ -983,7 +988,7 @@ int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Positio int bytesInCharacter = 1; const unsigned char leadByte = cb.UCharAt(position); if (dbcsCodePage) { - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { if (UTF8IsAscii(leadByte)) { // Single byte character or invalid character = leadByte; @@ -1176,7 +1181,7 @@ int Document::SafeSegment(const char *text, int length, int lengthSegment) const } lastEncodingAllowedBreak = j; - if (dbcsCodePage == SC_CP_UTF8) { + if (dbcsCodePage == CpUtf8) { j += UTF8BytesOfLead[ch]; } else if (dbcsCodePage) { j += IsDBCSLeadByteNoExcept(ch) ? 2 : 1; @@ -1193,7 +1198,7 @@ int Document::SafeSegment(const char *text, int length, int lengthSegment) const } EncodingFamily Document::CodePageFamily() const noexcept { - if (SC_CP_UTF8 == dbcsCodePage) + if (CpUtf8 == dbcsCodePage) return EncodingFamily::unicode; else if (dbcsCodePage) return EncodingFamily::dbcs; @@ -1232,7 +1237,7 @@ bool Document::DeleteChars(Sci::Position pos, Sci::Position len) { if (!cb.IsReadOnly()) { NotifyModified( DocModification( - SC_MOD_BEFOREDELETE | SC_PERFORMED_USER, + ModificationFlags::BeforeDelete | ModificationFlags::User, pos, len, 0, 0)); const Sci::Line prevLinesTotal = LinesTotal(); @@ -1247,7 +1252,8 @@ bool Document::DeleteChars(Sci::Position pos, Sci::Position len) { ModifiedAt(pos-1); NotifyModified( DocModification( - SC_MOD_DELETETEXT | SC_PERFORMED_USER | (startSequence?SC_STARTACTION:0), + ModificationFlags::DeleteText | ModificationFlags::User | + (startSequence?ModificationFlags::StartAction:ModificationFlags::None), pos, len, LinesTotal() - prevLinesTotal, text)); } @@ -1275,7 +1281,7 @@ Sci::Position Document::InsertString(Sci::Position position, const char *s, Sci: insertion.clear(); NotifyModified( DocModification( - SC_MOD_INSERTCHECK, + ModificationFlags::InsertCheck, position, insertLength, 0, s)); if (insertionSet) { @@ -1284,7 +1290,7 @@ Sci::Position Document::InsertString(Sci::Position position, const char *s, Sci: } NotifyModified( DocModification( - SC_MOD_BEFOREINSERT | SC_PERFORMED_USER, + ModificationFlags::BeforeInsert | ModificationFlags::User, position, insertLength, 0, s)); const Sci::Line prevLinesTotal = LinesTotal(); @@ -1296,7 +1302,8 @@ Sci::Position Document::InsertString(Sci::Position position, const char *s, Sci: ModifiedAt(position); NotifyModified( DocModification( - SC_MOD_INSERTTEXT | SC_PERFORMED_USER | (startSequence?SC_STARTACTION:0), + ModificationFlags::InsertText | ModificationFlags::User | + (startSequence?ModificationFlags::StartAction:ModificationFlags::None), position, insertLength, LinesTotal() - prevLinesTotal, text)); if (insertionSet) { // Free memory as could be large @@ -1316,11 +1323,11 @@ int SCI_METHOD Document::AddData(const char *data, Sci_Position length) { const Sci::Position position = Length(); InsertString(position, data, length); } catch (std::bad_alloc &) { - return SC_STATUS_BADALLOC; + return static_cast<int>(Status::BadAlloc); } catch (...) { - return SC_STATUS_FAILURE; + return static_cast<int>(Status::Failure); } - return 0; + return static_cast<int>(Status::Ok); } void * SCI_METHOD Document::ConvertToDocument() { @@ -1346,9 +1353,9 @@ Sci::Position Document::Undo() { const Action &action = cb.GetUndoStep(); if (action.at == ActionType::remove) { NotifyModified(DocModification( - SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); + ModificationFlags::BeforeInsert | ModificationFlags::Undo, action)); } else if (action.at == ActionType::container) { - DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_UNDO); + DocModification dm(ModificationFlags::Container | ModificationFlags::Undo); dm.token = action.position; NotifyModified(dm); if (!action.mayCoalesce) { @@ -1359,7 +1366,7 @@ Sci::Position Document::Undo() { } } else { NotifyModified(DocModification( - SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action)); + ModificationFlags::BeforeDelete | ModificationFlags::Undo, action)); } cb.PerformUndoStep(); if (action.at != ActionType::container) { @@ -1367,11 +1374,11 @@ Sci::Position Document::Undo() { newPos = action.position; } - int modFlags = SC_PERFORMED_UNDO; + ModificationFlags modFlags = ModificationFlags::Undo; // With undo, an insertion action becomes a deletion notification if (action.at == ActionType::remove) { newPos += action.lenData; - modFlags |= SC_MOD_INSERTTEXT; + modFlags |= ModificationFlags::InsertText; if ((coalescedRemoveLen > 0) && (action.position == prevRemoveActionPos || action.position == (prevRemoveActionPos + prevRemoveActionLen))) { coalescedRemoveLen += action.lenData; @@ -1383,21 +1390,21 @@ Sci::Position Document::Undo() { prevRemoveActionPos = action.position; prevRemoveActionLen = action.lenData; } else if (action.at == ActionType::insert) { - modFlags |= SC_MOD_DELETETEXT; + modFlags |= ModificationFlags::DeleteText; coalescedRemovePos = -1; coalescedRemoveLen = 0; prevRemoveActionPos = -1; prevRemoveActionLen = 0; } if (steps > 1) - modFlags |= SC_MULTISTEPUNDOREDO; + modFlags |= ModificationFlags::MultiStepUndoRedo; const Sci::Line linesAdded = LinesTotal() - prevLinesTotal; if (linesAdded != 0) multiLine = true; if (step == steps - 1) { - modFlags |= SC_LASTSTEPINUNDOREDO; + modFlags |= ModificationFlags::LastStepInUndoRedo; if (multiLine) - modFlags |= SC_MULTILINEUNDOREDO; + modFlags |= ModificationFlags::MultilineUndoRedo; } NotifyModified(DocModification(modFlags, action.position, action.lenData, linesAdded, action.data.get())); @@ -1426,14 +1433,14 @@ Sci::Position Document::Redo() { const Action &action = cb.GetRedoStep(); if (action.at == ActionType::insert) { NotifyModified(DocModification( - SC_MOD_BEFOREINSERT | SC_PERFORMED_REDO, action)); + ModificationFlags::BeforeInsert | ModificationFlags::Redo, action)); } else if (action.at == ActionType::container) { - DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_REDO); + DocModification dm(ModificationFlags::Container | ModificationFlags::Redo); dm.token = action.position; NotifyModified(dm); } else { NotifyModified(DocModification( - SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action)); + ModificationFlags::BeforeDelete | ModificationFlags::Redo, action)); } cb.PerformRedoStep(); if (action.at != ActionType::container) { @@ -1441,22 +1448,22 @@ Sci::Position Document::Redo() { newPos = action.position; } - int modFlags = SC_PERFORMED_REDO; + ModificationFlags modFlags = ModificationFlags::Redo; if (action.at == ActionType::insert) { newPos += action.lenData; - modFlags |= SC_MOD_INSERTTEXT; + modFlags |= ModificationFlags::InsertText; } else if (action.at == ActionType::remove) { - modFlags |= SC_MOD_DELETETEXT; + modFlags |= ModificationFlags::DeleteText; } if (steps > 1) - modFlags |= SC_MULTISTEPUNDOREDO; + modFlags |= ModificationFlags::MultiStepUndoRedo; const Sci::Line linesAdded = LinesTotal() - prevLinesTotal; if (linesAdded != 0) multiLine = true; if (step == steps - 1) { - modFlags |= SC_LASTSTEPINUNDOREDO; + modFlags |= ModificationFlags::LastStepInUndoRedo; if (multiLine) - modFlags |= SC_MULTILINEUNDOREDO; + modFlags |= ModificationFlags::MultilineUndoRedo; } NotifyModified( DocModification(modFlags, action.position, action.lenData, @@ -1645,15 +1652,15 @@ void Document::Indent(bool forwards, Sci::Line lineBottom, Sci::Line lineTop) { // Convert line endings for a piece of text to a particular mode. // Stop at len or when a NUL is found. -std::string Document::TransformLineEnds(const char *s, size_t len, int eolModeWanted) { +std::string Document::TransformLineEnds(const char *s, size_t len, EndOfLine eolModeWanted) { std::string dest; for (size_t i = 0; (i < len) && (s[i]); i++) { if (s[i] == '\n' || s[i] == '\r') { - if (eolModeWanted == SC_EOL_CR) { + if (eolModeWanted == EndOfLine::Cr) { dest.push_back('\r'); - } else if (eolModeWanted == SC_EOL_LF) { + } else if (eolModeWanted == EndOfLine::Lf) { dest.push_back('\n'); - } else { // eolModeWanted == SC_EOL_CRLF + } else { // eolModeWanted == EndOfLine::CrLf dest.push_back('\r'); dest.push_back('\n'); } @@ -1667,25 +1674,25 @@ std::string Document::TransformLineEnds(const char *s, size_t len, int eolModeWa return dest; } -void Document::ConvertLineEnds(int eolModeSet) { +void Document::ConvertLineEnds(EndOfLine eolModeSet) { UndoGroup ug(this); for (Sci::Position pos = 0; pos < Length(); pos++) { if (cb.CharAt(pos) == '\r') { if (cb.CharAt(pos + 1) == '\n') { // CRLF - if (eolModeSet == SC_EOL_CR) { + if (eolModeSet == EndOfLine::Cr) { DeleteChars(pos + 1, 1); // Delete the LF - } else if (eolModeSet == SC_EOL_LF) { + } else if (eolModeSet == EndOfLine::Lf) { DeleteChars(pos, 1); // Delete the CR } else { pos++; } } else { // CR - if (eolModeSet == SC_EOL_CRLF) { + if (eolModeSet == EndOfLine::CrLf) { pos += InsertString(pos + 1, "\n", 1); // Insert LF - } else if (eolModeSet == SC_EOL_LF) { + } else if (eolModeSet == EndOfLine::Lf) { pos += InsertString(pos, "\n", 1); // Insert LF DeleteChars(pos, 1); // Delete CR pos--; @@ -1693,9 +1700,9 @@ void Document::ConvertLineEnds(int eolModeSet) { } } else if (cb.CharAt(pos) == '\n') { // LF - if (eolModeSet == SC_EOL_CRLF) { + if (eolModeSet == EndOfLine::CrLf) { pos += InsertString(pos, "\r", 1); // Insert CR - } else if (eolModeSet == SC_EOL_CR) { + } else if (eolModeSet == EndOfLine::Cr) { pos += InsertString(pos, "\r", 1); // Insert CR DeleteChars(pos, 1); // Delete LF pos--; @@ -1705,9 +1712,9 @@ void Document::ConvertLineEnds(int eolModeSet) { } -int Document::Options() const noexcept { - return (IsLarge() ? SC_DOCUMENTOPTION_TEXT_LARGE : 0) | - (cb.HasStyles() ? 0 : SC_DOCUMENTOPTION_STYLES_NONE); +DocumentOption Document::Options() const noexcept { + return (IsLarge() ? DocumentOption::TextLarge : DocumentOption::Default) | + (cb.HasStyles() ? DocumentOption::Default : DocumentOption::StylesNone); } bool Document::IsWhiteLine(Sci::Line line) const { @@ -1751,7 +1758,7 @@ Sci::Position Document::ParaDown(Sci::Position pos) const { CharacterClass Document::WordCharacterClass(unsigned int ch) const { if (dbcsCodePage && (!UTF8IsAscii(ch))) { - if (SC_CP_UTF8 == dbcsCodePage) { + if (CpUtf8 == dbcsCodePage) { // Use hard coded Unicode class const CharacterCategory cc = charMap.CategoryFor(ch); switch (cc) { @@ -2018,13 +2025,13 @@ Document::CharacterExtracted Document::ExtractCharacter(Sci::Position position) * Has not been tested with backwards DBCS searches yet. */ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, const char *search, - int flags, Sci::Position *length) { + FindOption flags, Sci::Position *length) { if (*length <= 0) return minPos; - const bool caseSensitive = (flags & SCFIND_MATCHCASE) != 0; - const bool word = (flags & SCFIND_WHOLEWORD) != 0; - const bool wordStart = (flags & SCFIND_WORDSTART) != 0; - const bool regExp = (flags & SCFIND_REGEXP) != 0; + const bool caseSensitive = FlagSet(flags, FindOption::MatchCase); + const bool word = FlagSet(flags, FindOption::WholeWord); + const bool wordStart = FlagSet(flags, FindOption::WordStart); + const bool regExp = FlagSet(flags, FindOption::RegExp); if (regExp) { if (!regex) regex = std::unique_ptr<RegexSearchBase>(CreateRegexSearch(&charClass)); @@ -2064,7 +2071,7 @@ Sci::Position Document::FindText(Sci::Position minPos, Sci::Position maxPos, con if (!NextCharacter(pos, increment)) break; } - } else if (SC_CP_UTF8 == dbcsCodePage) { + } else if (CpUtf8 == dbcsCodePage) { constexpr size_t maxFoldingExpansion = 4; std::vector<char> searchThing((lengthFind+1) * UTF8MaxBytes * maxFoldingExpansion + 1); const size_t lenSearch = @@ -2184,15 +2191,15 @@ const char *Document::SubstituteByPosition(const char *text, Sci::Position *leng return nullptr; } -int Document::LineCharacterIndex() const noexcept { +LineCharacterIndexType Document::LineCharacterIndex() const noexcept { return cb.LineCharacterIndex(); } -void Document::AllocateLineCharacterIndex(int lineCharacterIndex) { +void Document::AllocateLineCharacterIndex(LineCharacterIndexType lineCharacterIndex) { return cb.AllocateLineCharacterIndex(lineCharacterIndex); } -void Document::ReleaseLineCharacterIndex(int lineCharacterIndex) { +void Document::ReleaseLineCharacterIndex(LineCharacterIndexType lineCharacterIndex) { return cb.ReleaseLineCharacterIndex(lineCharacterIndex); } @@ -2231,7 +2238,7 @@ bool SCI_METHOD Document::SetStyleFor(Sci_Position length, char style) { enteredStyling++; const Sci::Position prevEndStyled = endStyled; if (cb.SetStyleFor(endStyled, length, style)) { - const DocModification mh(SC_MOD_CHANGESTYLE | SC_PERFORMED_USER, + const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User, prevEndStyled, length); NotifyModified(mh); } @@ -2260,7 +2267,7 @@ bool SCI_METHOD Document::SetStyles(Sci_Position length, const char *styles) { } } if (didChange) { - const DocModification mh(SC_MOD_CHANGESTYLE | SC_PERFORMED_USER, + const DocModification mh(ModificationFlags::ChangeStyle | ModificationFlags::User, startMod, endMod - startMod + 1); NotifyModified(mh); } @@ -2311,7 +2318,7 @@ void Document::SetLexInterface(std::unique_ptr<LexInterface> pLexInterface) noex int SCI_METHOD Document::SetLineState(Sci_Position line, int state) { const int statePrevious = States()->SetLineState(line, state); if (state != statePrevious) { - const DocModification mh(SC_MOD_CHANGELINESTATE, LineStart(line), 0, 0, nullptr, + const DocModification mh(ModificationFlags::ChangeLineState, LineStart(line), 0, 0, nullptr, static_cast<Sci::Line>(line)); NotifyModified(mh); } @@ -2327,7 +2334,7 @@ Sci::Line Document::GetMaxLineState() const noexcept { } void SCI_METHOD Document::ChangeLexerState(Sci_Position start, Sci_Position end) { - const DocModification mh(SC_MOD_LEXERSTATE, start, + const DocModification mh(ModificationFlags::LexerState, start, end-start, 0, 0, 0); NotifyModified(mh); } @@ -2340,20 +2347,20 @@ StyledText Document::MarginStyledText(Sci::Line line) const noexcept { void Document::MarginSetText(Sci::Line line, const char *text) { Margins()->SetText(line, text); - const DocModification mh(SC_MOD_CHANGEMARGIN, LineStart(line), + const DocModification mh(ModificationFlags::ChangeMargin, LineStart(line), 0, 0, 0, line); NotifyModified(mh); } void Document::MarginSetStyle(Sci::Line line, int style) { Margins()->SetStyle(line, style); - NotifyModified(DocModification(SC_MOD_CHANGEMARGIN, LineStart(line), + NotifyModified(DocModification(ModificationFlags::ChangeMargin, LineStart(line), 0, 0, 0, line)); } void Document::MarginSetStyles(Sci::Line line, const unsigned char *styles) { Margins()->SetStyles(line, styles); - NotifyModified(DocModification(SC_MOD_CHANGEMARGIN, LineStart(line), + NotifyModified(DocModification(ModificationFlags::ChangeMargin, LineStart(line), 0, 0, 0, line)); } @@ -2376,7 +2383,7 @@ void Document::AnnotationSetText(Sci::Line line, const char *text) { const Sci::Line linesBefore = AnnotationLines(line); Annotations()->SetText(line, text); const int linesAfter = AnnotationLines(line); - DocModification mh(SC_MOD_CHANGEANNOTATION, LineStart(line), + DocModification mh(ModificationFlags::ChangeAnnotation, LineStart(line), 0, 0, 0, line); mh.annotationLinesAdded = linesAfter - linesBefore; NotifyModified(mh); @@ -2386,7 +2393,7 @@ void Document::AnnotationSetText(Sci::Line line, const char *text) { void Document::AnnotationSetStyle(Sci::Line line, int style) { if (line >= 0 && line < LinesTotal()) { Annotations()->SetStyle(line, style); - const DocModification mh(SC_MOD_CHANGEANNOTATION, LineStart(line), + const DocModification mh(ModificationFlags::ChangeAnnotation, LineStart(line), 0, 0, 0, line); NotifyModified(mh); } @@ -2419,7 +2426,7 @@ StyledText Document::EOLAnnotationStyledText(Sci::Line line) const noexcept { void Document::EOLAnnotationSetText(Sci::Line line, const char *text) { if (line >= 0 && line < LinesTotal()) { EOLAnnotations()->SetText(line, text); - const DocModification mh(SC_MOD_CHANGEEOLANNOTATION, LineStart(line), + const DocModification mh(ModificationFlags::ChangeEOLAnnotation, LineStart(line), 0, 0, 0, line); NotifyModified(mh); } @@ -2428,7 +2435,7 @@ void Document::EOLAnnotationSetText(Sci::Line line, const char *text) { void Document::EOLAnnotationSetStyle(Sci::Line line, int style) { if (line >= 0 && line < LinesTotal()) { EOLAnnotations()->SetStyle(line, style); - const DocModification mh(SC_MOD_CHANGEEOLANNOTATION, LineStart(line), + const DocModification mh(ModificationFlags::ChangeEOLAnnotation, LineStart(line), 0, 0, 0, line); NotifyModified(mh); } @@ -2454,7 +2461,7 @@ void SCI_METHOD Document::DecorationFillRange(Sci_Position position, int value, const FillResult<Sci::Position> fr = decorations->FillRange( position, value, fillLength); if (fr.changed) { - const DocModification mh(SC_MOD_CHANGEINDICATOR | SC_PERFORMED_USER, + const DocModification mh(ModificationFlags::ChangeIndicator | ModificationFlags::User, fr.position, fr.fillLength); NotifyModified(mh); } @@ -2493,9 +2500,9 @@ void Document::NotifySavePoint(bool atSavePoint) { } void Document::NotifyModified(DocModification mh) { - if (mh.modificationType & SC_MOD_INSERTTEXT) { + if (FlagSet(mh.modificationType, ModificationFlags::InsertText)) { decorations->InsertSpace(mh.position, mh.length); - } else if (mh.modificationType & SC_MOD_DELETETEXT) { + } else if (FlagSet(mh.modificationType, ModificationFlags::DeleteText)) { decorations->DeleteRange(mh.position, mh.length); } for (const WatcherWithUserData &watcher : watchers) { @@ -2722,7 +2729,7 @@ public: ~BuiltinRegex() override = default; Sci::Position FindText(Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s, - bool caseSensitive, bool word, bool wordStart, int flags, + bool caseSensitive, bool word, bool wordStart, FindOption flags, Sci::Position *length) override; const char *SubstituteByPosition(Document *doc, const char *text, Sci::Position *length) override; @@ -3144,7 +3151,7 @@ Sci::Position Cxx11RegexFindText(const Document *doc, Sci::Position minPos, Sci: search.Clear(); bool matched = false; - if (SC_CP_UTF8 == doc->dbcsCodePage) { + if (CpUtf8 == doc->dbcsCodePage) { const std::wstring ws = WStringFromUTF8(s); std::wregex regexp; regexp.assign(ws, flagsRe); @@ -3181,11 +3188,11 @@ Sci::Position Cxx11RegexFindText(const Document *doc, Sci::Position minPos, Sci: } Sci::Position BuiltinRegex::FindText(Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *s, - bool caseSensitive, bool, bool, int flags, + bool caseSensitive, bool, bool, FindOption flags, Sci::Position *length) { #ifndef NO_CXX11_REGEX - if (flags & SCFIND_CXX11REGEX) { + if (FlagSet(flags, FindOption::Cxx11RegEx)) { return Cxx11RegexFindText(doc, minPos, maxPos, s, caseSensitive, length, search); } @@ -3193,7 +3200,7 @@ Sci::Position BuiltinRegex::FindText(Document *doc, Sci::Position minPos, Sci::P const RESearchRange resr(doc, minPos, maxPos); - const bool posix = (flags & SCFIND_POSIX) != 0; + const bool posix = FlagSet(flags, FindOption::Posix); const char *errmsg = search.Compile(s, *length, caseSensitive, posix); if (errmsg) { @@ -3320,7 +3327,7 @@ const char *BuiltinRegex::SubstituteByPosition(Document *doc, const char *text, #ifndef SCI_OWNREGEX -RegexSearchBase *Scintilla::CreateRegexSearch(CharClassify *charClassTable) { +RegexSearchBase *Scintilla::Internal::CreateRegexSearch(CharClassify *charClassTable) { return new BuiltinRegex(charClassTable); } |