diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/EditModel.cxx | 2 | ||||
-rw-r--r-- | src/EditModel.h | 2 | ||||
-rw-r--r-- | src/EditView.cxx | 101 | ||||
-rw-r--r-- | src/EditView.h | 25 | ||||
-rw-r--r-- | src/Editor.cxx | 333 | ||||
-rw-r--r-- | src/Editor.h | 67 | ||||
-rw-r--r-- | src/Geometry.h | 6 | ||||
-rw-r--r-- | src/MarginView.cxx | 4 | ||||
-rw-r--r-- | src/PositionCache.cxx | 6 | ||||
-rw-r--r-- | src/PositionCache.h | 9 | ||||
-rw-r--r-- | src/Selection.cxx | 8 | ||||
-rw-r--r-- | src/Selection.h | 4 | ||||
-rw-r--r-- | src/Style.cxx | 8 | ||||
-rw-r--r-- | src/Style.h | 6 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 4 |
15 files changed, 306 insertions, 279 deletions
diff --git a/src/EditModel.cxx b/src/EditModel.cxx index a75cd4c41..58b9306a2 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -66,7 +66,7 @@ EditModel::EditModel() : braces{} { bracesMatchStyle = STYLE_BRACEBAD; highlightGuideColumn = 0; primarySelection = true; - imeInteraction = imeWindowed; + imeInteraction = IMEInteraction::windowed; bidirectional = Bidirectional::bidiDisabled; foldFlags = 0; foldDisplayTextStyle = SC_FOLDDISPLAYTEXT_HIDDEN; diff --git a/src/EditModel.h b/src/EditModel.h index 56d341abb..f81ecb0c1 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -36,7 +36,7 @@ public: Selection sel; bool primarySelection; - enum IMEInteraction { imeWindowed, imeInline } imeInteraction; + enum class IMEInteraction { windowed, internal } imeInteraction; enum class CharacterSource { directInput, tentativeInput, imeResult }; enum class Bidirectional { bidiDisabled, bidiL2R, bidiR2L } bidirectional; diff --git a/src/EditView.cxx b/src/EditView.cxx index 6ba480123..16614de48 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -123,15 +123,15 @@ int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, cons void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase, std::string_view text, DrawPhase phase) { const Font *fontText = style.font.get(); - if (phase & drawBack) { - if (phase & drawText) { + if (FlagSet(phase, DrawPhase::back)) { + if (FlagSet(phase, DrawPhase::text)) { // Drawing both surface->DrawTextNoClip(rc, fontText, ybase, text, style.fore, style.back); } else { surface->FillRectangle(rc, style.back); } - } else if (phase & drawText) { + } else if (FlagSet(phase, DrawPhase::text)) { surface->DrawTextTransparent(rc, fontText, ybase, text, style.fore); } } @@ -174,7 +174,7 @@ EditView::EditView() { hideSelection = false; drawOverstrikeCaret = true; bufferedDraw = true; - phasesDraw = phasesTwo; + phasesDraw = PhasesDraw::two; lineWidthMaxSeen = 0; additionalCaretsBlink = true; additionalCaretsVisible = true; @@ -190,7 +190,7 @@ EditView::~EditView() { } bool EditView::SetTwoPhaseDraw(bool twoPhaseDraw) noexcept { - const PhasesDraw phasesDrawNew = twoPhaseDraw ? phasesTwo : phasesOne; + const PhasesDraw phasesDrawNew = twoPhaseDraw ? PhasesDraw::two : PhasesDraw::one; const bool redraw = phasesDraw != phasesDrawNew; phasesDraw = phasesDrawNew; return redraw; @@ -204,7 +204,7 @@ bool EditView::SetPhasesDraw(int phases) noexcept { } bool EditView::LinesOverlap() const noexcept { - return phasesDraw == phasesMultiple; + return phasesDraw == PhasesDraw::multiple; } void EditView::ClearAllTabstops() noexcept { @@ -347,15 +347,15 @@ constexpr XYPOSITION epsilon = 0.0001f; // A small nudge to avoid floating point * This only affects ASCII characters and is provided for languages with case-insensitive * ASCII keywords where the user wishes to view keywords in a preferred case. */ -inline char CaseForce(Style::ecaseForced caseForce, char chDoc, char chPrevious) { +inline char CaseForce(Style::CaseForce caseForce, char chDoc, char chPrevious) { switch (caseForce) { - case Style::caseMixed: + case Style::CaseForce::mixed: return chDoc; - case Style::caseLower: + case Style::CaseForce::lower: return MakeLowerCase(chDoc); - case Style::caseUpper: + case Style::CaseForce::upper: return MakeUpperCase(chDoc); - case Style::caseCamel: + case Style::CaseForce::camel: default: // default should not occur, included to avoid warnings if (IsUpperOrLowerCase(chDoc) && !IsUpperOrLowerCase(chPrevious)) { return MakeUpperCase(chDoc); @@ -635,7 +635,7 @@ Point EditView::LocationFromPosition(Surface *surface, const EditModel &model, S return pt; Sci::Line lineDoc = model.pdoc->SciLineFromPosition(pos.Position()); Sci::Position posLineStart = model.pdoc->LineStart(lineDoc); - if ((pe & peLineEnd) && (lineDoc > 0) && (pos.Position() == posLineStart)) { + if (FlagSet(pe, PointEnd::lineEnd) && (lineDoc > 0) && (pos.Position() == posLineStart)) { // Want point at end of first line lineDoc--; posLineStart = model.pdoc->LineStart(lineDoc); @@ -1016,7 +1016,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle } else { surface->FillRectangle(rcSegment, textBack); } - DrawTextBlob(surface, vsDraw, rcSegment, ctrlChar, textBack, textFore, phasesDraw == phasesOne); + DrawTextBlob(surface, vsDraw, rcSegment, ctrlChar, textBack, textFore, phasesDraw == PhasesDraw::one); if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && (alpha != SC_ALPHA_NOALPHA)) { SimpleAlphaRectangle(surface, rcSegment, SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection), alpha); } @@ -1236,7 +1236,7 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con } } - if (phase & drawBack) { + if (FlagSet(phase, DrawPhase::back)) { surface->FillRectangle(rcSegment, textBack); // Fill Remainder of the line @@ -1248,8 +1248,8 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con FillLineRemainder(surface, model, vsDraw, ll, line, rcRemainder, subLine); } - if (phase & drawText) { - if (phasesDraw != phasesOne) { + if (FlagSet(phase, DrawPhase::text)) { + if (phasesDraw != PhasesDraw::one) { surface->DrawTextTransparent(rcSegment, fontText, rcSegment.top + vsDraw.maxAscent, foldDisplayText, textFore); @@ -1260,7 +1260,7 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con } } - if (phase & drawIndicatorsFore) { + if (FlagSet(phase, DrawPhase::indicatorsFore)) { if (model.foldDisplayTextStyle == SC_FOLDDISPLAYTEXT_BOXED) { surface->PenColour(textFore); PRectangle rcBox = rcSegment; @@ -1278,7 +1278,7 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con } } - if (phase & drawSelectionTranslucent) { + if (FlagSet(phase, DrawPhase::selectionTranslucent)) { if (eolInSelection && vsDraw.selColours.back.isSet && (line < model.pdoc->LinesTotal() - 1) && alpha != SC_ALPHA_NOALPHA) { SimpleAlphaRectangle(surface, rcSegment, SelectionBackground(vsDraw, eolInSelection == 1, model.primarySelection), alpha); } @@ -1331,7 +1331,7 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c } } - if (phase & drawBack) { + if (FlagSet(phase, DrawPhase::back)) { surface->FillRectangle(rcSegment, textBack); // Fill Remainder of the line @@ -1343,8 +1343,8 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c FillLineRemainder(surface, model, vsDraw, ll, line, rcRemainder, subLine); } - if (phase & drawText) { - if (phasesDraw != phasesOne) { + if (FlagSet(phase, DrawPhase::text)) { + if (phasesDraw != PhasesDraw::one) { surface->DrawTextTransparent(rcSegment, fontText, rcSegment.top + vsDraw.maxAscent, eolAnnotationText, textFore); @@ -1355,7 +1355,7 @@ void EditView::DrawEOLAnnotationText(Surface *surface, const EditModel &model, c } } - if (phase & drawIndicatorsFore) { + if (FlagSet(phase, DrawPhase::indicatorsFore)) { if (vsDraw.eolAnnotationVisible == EOLANNOTATION_BOXED ) { surface->PenColour(textFore); PRectangle rcBox = rcSegment; @@ -1385,7 +1385,7 @@ void EditView::DrawAnnotation(Surface *surface, const EditModel &model, const Vi const int annotationLine = subLine - ll->lines; const StyledText stAnnotation = model.pdoc->AnnotationStyledText(line); if (stAnnotation.text && ValidStyledText(vsDraw, vsDraw.annotationStyleOffset, stAnnotation)) { - if (phase & drawBack) { + if (FlagSet(phase, DrawPhase::back)) { surface->FillRectangle(rcSegment, vsDraw.styles[0].back); } rcSegment.left = static_cast<XYPOSITION>(xStart); @@ -1410,14 +1410,14 @@ void EditView::DrawAnnotation(Surface *surface, const EditModel &model, const Vi lineInAnnotation++; } PRectangle rcText = rcSegment; - if ((phase & drawBack) && AnnotationBoxedOrIndented(vsDraw.annotationVisible)) { + if ((FlagSet(phase, DrawPhase::back)) && AnnotationBoxedOrIndented(vsDraw.annotationVisible)) { surface->FillRectangle(rcText, vsDraw.styles[stAnnotation.StyleAt(start) + vsDraw.annotationStyleOffset].back); rcText.left += vsDraw.spaceWidth; } DrawStyledText(surface, vsDraw, vsDraw.annotationStyleOffset, rcText, stAnnotation, start, lengthAnnotation, phase); - if ((phase & drawBack) && (vsDraw.annotationVisible == ANNOTATION_BOXED)) { + if ((FlagSet(phase, DrawPhase::back)) && (vsDraw.annotationVisible == ANNOTATION_BOXED)) { surface->PenColour(vsDraw.styles[vsDraw.annotationStyleOffset].fore); const IntegerRectangle ircSegment(rcSegment); surface->MoveTo(ircSegment.left, ircSegment.top); @@ -1869,7 +1869,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi // Foreground drawing loop BreakFinder bfFore(ll, &model.sel, lineRange, posLineStart, xStartVisible, - (((phasesDraw == phasesOne) && selBackDrawn) || vsDraw.selColours.fore.isSet), model.pdoc, &model.reprs, &vsDraw); + (((phasesDraw == PhasesDraw::one) && selBackDrawn) || vsDraw.selColours.fore.isSet), model.pdoc, &model.reprs, &vsDraw); while (bfFore.More()) { @@ -1927,7 +1927,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi if (ts.representation) { if (ll->chars[i] == '\t') { // Tab display - if (phasesDraw == phasesOne) { + if (phasesDraw == PhasesDraw::one) { if (drawWhitespaceBackground && vsDraw.WhiteSpaceVisible(inIndentation)) textBack = vsDraw.whitespaceColours.back; surface->FillRectangle(rcSegment, textBack); @@ -1970,14 +1970,14 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi cc, textBack, textFore); } else { DrawTextBlob(surface, vsDraw, rcSegment, ts.representation->stringRep, - textBack, textFore, phasesDraw == phasesOne); + textBack, textFore, phasesDraw == PhasesDraw::one); } } } else { // Normal text display if (vsDraw.styles[styleMain].visible) { const std::string_view text(&ll->chars[ts.start], i - ts.start + 1); - if (phasesDraw != phasesOne) { + if (phasesDraw != PhasesDraw::one) { surface->DrawTextTransparent(rcSegment, textFont, rcSegment.top + vsDraw.maxAscent, text, textFore); } else { @@ -1994,7 +1994,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi textFore = vsDraw.whitespaceColours.fore; if (vsDraw.WhiteSpaceVisible(inIndentation)) { const XYPOSITION xmid = (ll->positions[cpos + ts.start] + ll->positions[cpos + ts.start + 1]) / 2; - if ((phasesDraw == phasesOne) && drawWhitespaceBackground) { + if ((phasesDraw == PhasesDraw::one) && drawWhitespaceBackground) { textBack = vsDraw.whitespaceColours.back; const PRectangle rcSpace( ll->positions[cpos + ts.start] + xStart - static_cast<XYPOSITION>(subLineStart), @@ -2120,26 +2120,27 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl const XYACCUMULATOR subLineStart = ll->positions[lineRange.start]; if ((ll->wrapIndent != 0) && (subLine > 0)) { - if (phase & drawBack) { + if (FlagSet(phase, DrawPhase::back)) { DrawWrapIndentAndMarker(surface, vsDraw, ll, xStart, rcLine, background, customDrawWrapMarker, model.caret.active); } xStart += static_cast<int>(ll->wrapIndent); } - if (phasesDraw != phasesOne) { - if (phase & drawBack) { + if (phasesDraw != PhasesDraw::one) { + if (FlagSet(phase, DrawPhase::back)) { DrawBackground(surface, model, vsDraw, ll, rcLine, lineRange, posLineStart, xStart, subLine, background); - DrawFoldDisplayText(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, subLineStart, drawBack); - DrawEOLAnnotationText(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, subLineStart, drawBack); - phase = static_cast<DrawPhase>(phase & ~drawBack); // Remove drawBack to not draw again in DrawFoldDisplayText + DrawFoldDisplayText(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, subLineStart, DrawPhase::back); + DrawEOLAnnotationText(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, subLineStart, DrawPhase::back); + // Remove drawBack to not draw again in DrawFoldDisplayText + phase = static_cast<DrawPhase>(static_cast<int>(phase) & ~static_cast<int>(DrawPhase::back)); DrawEOL(surface, model, vsDraw, ll, rcLine, line, lineRange.end, xStart, subLine, subLineStart, background); if (vsDraw.IsLineFrameOpaque(model.caret.active, ll->containsCaret)) DrawCaretLineFramed(surface, vsDraw, ll, rcLine, subLine); } - if (phase & drawIndicatorsBack) { + if (FlagSet(phase, DrawPhase::indicatorsBack)) { DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRangeIncludingEnd.end, true, tabWidthMinimumPixels); DrawEdgeLine(surface, vsDraw, ll, rcLine, lineRange, xStart); @@ -2147,16 +2148,16 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl } } - if (phase & drawText) { + if (FlagSet(phase, DrawPhase::text)) { DrawForeground(surface, model, vsDraw, ll, lineVisible, rcLine, lineRange, posLineStart, xStart, subLine, background); } - if (phase & drawIndentationGuides) { + if (FlagSet(phase, DrawPhase::indentationGuides)) { DrawIndentGuidesOverEmpty(surface, model, vsDraw, ll, line, lineVisible, rcLine, xStart, subLine); } - if (phase & drawIndicatorsFore) { + if (FlagSet(phase, DrawPhase::indicatorsFore)) { DrawIndicators(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, lineRangeIncludingEnd.end, false, tabWidthMinimumPixels); } @@ -2164,7 +2165,7 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl DrawFoldDisplayText(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, subLineStart, phase); DrawEOLAnnotationText(surface, model, vsDraw, ll, line, xStart, rcLine, subLine, subLineStart, phase); - if (phasesDraw == phasesOne) { + if (phasesDraw == PhasesDraw::one) { DrawEOL(surface, model, vsDraw, ll, rcLine, line, lineRange.end, xStart, subLine, subLineStart, background); if (vsDraw.IsLineFrameOpaque(model.caret.active, ll->containsCaret)) @@ -2173,11 +2174,11 @@ void EditView::DrawLine(Surface *surface, const EditModel &model, const ViewStyl DrawMarkUnderline(surface, model, vsDraw, line, rcLine); } - if (!hideSelection && (phase & drawSelectionTranslucent)) { + if (!hideSelection && FlagSet(phase, DrawPhase::selectionTranslucent)) { DrawTranslucentSelection(surface, model, vsDraw, ll, line, rcLine, subLine, lineRange, xStart, tabWidthMinimumPixels); } - if (phase & drawLineTranslucent) { + if (FlagSet(phase, DrawPhase::lineTranslucent)) { DrawTranslucentLineState(surface, model, vsDraw, ll, line, rcLine, subLine); } } @@ -2264,12 +2265,12 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan Sci::Line lineDocPrevious = -1; // Used to avoid laying out one document line multiple times AutoLineLayout ll(llc, nullptr); std::vector<DrawPhase> phases; - if ((phasesDraw == phasesMultiple) && !bufferedDraw) { - for (DrawPhase phase = drawBack; phase <= drawCarets; phase = static_cast<DrawPhase>(phase * 2)) { + if ((phasesDraw == PhasesDraw::multiple) && !bufferedDraw) { + for (DrawPhase phase = DrawPhase::back; phase <= DrawPhase::carets; phase = static_cast<DrawPhase>(static_cast<int>(phase) * 2)) { phases.push_back(phase); } } else { - phases.push_back(drawAll); + phases.push_back(DrawPhase::all); } for (const DrawPhase &phase : phases) { int ypos = 0; @@ -2314,7 +2315,7 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan ll->SetBracesHighlight(rangeLine, model.braces, static_cast<char>(model.bracesMatchStyle), static_cast<int>(model.highlightGuideColumn * vsDraw.spaceWidth), bracesIgnoreStyle); - if (leftTextOverlap && (bufferedDraw || ((phasesDraw < phasesMultiple) && (phase & drawBack)))) { + if (leftTextOverlap && (bufferedDraw || ((phasesDraw < PhasesDraw::multiple) && (FlagSet(phase, DrawPhase::back))))) { // Clear the left margin PRectangle rcSpacer = rcLine; rcSpacer.right = rcSpacer.left; @@ -2334,11 +2335,11 @@ void EditView::PaintText(Surface *surfaceWindow, const EditModel &model, PRectan // Restore the previous styles for the brace highlights in case layout is in cache. ll->RestoreBracesHighlight(rangeLine, model.braces, bracesIgnoreStyle); - if (phase & drawFoldLines) { + if (FlagSet(phase, DrawPhase::foldLines)) { DrawFoldLines(surface, model, vsDraw, lineDoc, rcLine); } - if (phase & drawCarets) { + if (FlagSet(phase, DrawPhase::carets)) { DrawCarets(surface, model, vsDraw, ll, lineDoc, xStart, rcLine, subLine); } @@ -2608,7 +2609,7 @@ Sci::Position EditView::FormatRange(bool draw, const Sci_RangeToFormat *pfr, Sur if (draw) { rcLine.top = static_cast<XYPOSITION>(ypos); rcLine.bottom = static_cast<XYPOSITION>(ypos + vsPrint.lineHeight); - DrawLine(surface, model, vsPrint, &ll, lineDoc, visibleLine, xStart, rcLine, iwl, drawAll); + DrawLine(surface, model, vsPrint, &ll, lineDoc, visibleLine, xStart, rcLine, iwl, DrawPhase::all); } ypos += vsPrint.lineHeight; } diff --git a/src/EditView.h b/src/EditView.h index eb4cbf849..11fe5c659 100644 --- a/src/EditView.h +++ b/src/EditView.h @@ -20,17 +20,18 @@ struct PrintParameters { /** * The view may be drawn in separate phases. */ -enum DrawPhase { - drawBack = 0x1, - drawIndicatorsBack = 0x2, - drawText = 0x4, - drawIndentationGuides = 0x8, - drawIndicatorsFore = 0x10, - drawSelectionTranslucent = 0x20, - drawLineTranslucent = 0x40, - drawFoldLines = 0x80, - drawCarets = 0x100, - drawAll = 0x1FF +enum class DrawPhase { + none = 0x0, + back = 0x1, + indicatorsBack = 0x2, + text = 0x4, + indentationGuides = 0x8, + indicatorsFore = 0x10, + selectionTranslucent = 0x20, + lineTranslucent = 0x40, + foldLines = 0x80, + carets = 0x100, + all = 0x1FF }; bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st) noexcept; @@ -64,7 +65,7 @@ public: * In multiPhaseDraw mode, drawing is performed in multiple phases with each phase drawing * one feature over the whole drawing area, instead of within one line. This allows text to * overlap from one line to the next. */ - enum PhasesDraw { phasesOne, phasesTwo, phasesMultiple }; + enum class PhasesDraw { one, two, multiple }; PhasesDraw phasesDraw; int lineWidthMaxSeen; diff --git a/src/Editor.cxx b/src/Editor.cxx index 28159fd57..2001eafaf 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -133,7 +133,7 @@ Editor::Editor() : durationWrapOneLine(0.00001, 0.000001, 0.0001) { dwelling = false; ptMouseLast.x = 0; ptMouseLast.y = 0; - inDragDrop = ddNone; + inDragDrop = DragDrop::none; dropWentOutside = false; posDrop = SelectionPosition(Sci::invalidPosition); hotSpotClickPos = INVALID_POSITION; @@ -177,7 +177,7 @@ Editor::Editor() : durationWrapOneLine(0.00001, 0.000001, 0.0001) { needUpdateUI = 0; ContainerNeedsUpdate(SC_UPDATE_CONTENT); - paintState = notPainting; + paintState = PaintState::notPainting; paintAbandonedByStyling = false; paintingAllText = false; willRedrawAll = false; @@ -459,10 +459,10 @@ void Editor::SetTopLine(Sci::Line topLineNew) { * @return true if calling code should stop drawing. */ bool Editor::AbandonPaint() { - if ((paintState == painting) && !paintingAllText) { - paintState = paintAbandoned; + if ((paintState == PaintState::painting) && !paintingAllText) { + paintState = PaintState::abandoned; } - return paintState == paintAbandoned; + return paintState == PaintState::abandoned; } void Editor::RedrawRect(PRectangle rc) { @@ -585,7 +585,7 @@ void Editor::SetRectangularRange() { if (sel.IsRectangular()) { const int xAnchor = XFromPosition(sel.Rectangular().anchor); int xCaret = XFromPosition(sel.Rectangular().caret); - if (sel.selType == Selection::selThin) { + if (sel.selType == Selection::SelTypes::thin) { xCaret = xAnchor; } const Sci::Line lineAnchorRect = @@ -610,7 +610,7 @@ void Editor::SetRectangularRange() { void Editor::ThinRectangularRange() { if (sel.IsRectangular()) { - sel.selType = Selection::selThin; + sel.selType = Selection::SelTypes::thin; if (sel.Rectangular().caret < sel.Rectangular().anchor) { sel.Rectangular() = SelectionRange(sel.Range(sel.Count()-1).caret, sel.Range(0).anchor); } else { @@ -666,7 +666,7 @@ void Editor::SetSelection(SelectionPosition currentPos_, SelectionPosition ancho anchor_ = ClampPositionIntoDocument(anchor_); const Sci::Line currentLine = pdoc->SciLineFromPosition(currentPos_.Position()); SelectionRange rangeNew(currentPos_, anchor_); - if (sel.selType == Selection::selLines) { + if (sel.selType == Selection::SelTypes::lines) { rangeNew = LineSelectionRange(currentPos_, anchor_); } if (sel.Count() > 1 || !(sel.RangeMain() == rangeNew)) { @@ -680,7 +680,7 @@ void Editor::SetSelection(SelectionPosition currentPos_, SelectionPosition ancho if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } - QueueIdleWork(WorkNeeded::workUpdateUI); + QueueIdleWork(WorkItems::updateUI); } void Editor::SetSelection(Sci::Position currentPos_, Sci::Position anchor_) { @@ -698,7 +698,7 @@ void Editor::SetSelection(SelectionPosition currentPos_) { sel.Rectangular() = SelectionRange(SelectionPosition(currentPos_), sel.Rectangular().anchor); SetRectangularRange(); - } else if (sel.selType == Selection::selLines) { + } else if (sel.selType == Selection::SelTypes::lines) { sel.RangeMain() = LineSelectionRange(currentPos_, sel.RangeMain().anchor); } else { sel.RangeMain() = @@ -710,7 +710,7 @@ void Editor::SetSelection(SelectionPosition currentPos_) { if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } - QueueIdleWork(WorkNeeded::workUpdateUI); + QueueIdleWork(WorkItems::updateUI); } void Editor::SetSelection(int currentPos_) { @@ -732,7 +732,7 @@ void Editor::SetEmptySelection(SelectionPosition currentPos_) { if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } - QueueIdleWork(WorkNeeded::workUpdateUI); + QueueIdleWork(WorkItems::updateUI); } void Editor::SetEmptySelection(Sci::Position currentPos_) { @@ -858,7 +858,7 @@ void Editor::MovedCaret(SelectionPosition newPos, SelectionPosition previousPos, } } const XYScrollPosition newXY = XYScrollToMakeVisible( - SelectionRange(posDrag.IsValid() ? posDrag : newPos), xysDefault, policies); + SelectionRange(posDrag.IsValid() ? posDrag : newPos), XYScrollOptions::all, policies); if (previousPos.IsValid() && (newXY.xOffset == xOffset)) { // simple vertical scroll then invalidate ScrollTo(newXY.topLine); @@ -873,36 +873,36 @@ void Editor::MovedCaret(SelectionPosition newPos, SelectionPosition previousPos, ClaimSelection(); SetHoverIndicatorPosition(sel.MainCaret()); - QueueIdleWork(WorkNeeded::workUpdateUI); + QueueIdleWork(WorkItems::updateUI); if (marginView.highlightDelimiter.NeedsDrawing(currentLine)) { RedrawSelMargin(); } } -void Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, bool ensureVisible) { +void Editor::MovePositionTo(SelectionPosition newPos, Selection::SelTypes selt, bool ensureVisible) { const SelectionPosition spCaret = ((sel.Count() == 1) && sel.Empty()) ? sel.Last() : SelectionPosition(INVALID_POSITION); const Sci::Position delta = newPos.Position() - sel.MainCaret(); newPos = ClampPositionIntoDocument(newPos); newPos = MovePositionOutsideChar(newPos, delta); - if (!multipleSelection && sel.IsRectangular() && (selt == Selection::selStream)) { + if (!multipleSelection && sel.IsRectangular() && (selt == Selection::SelTypes::stream)) { // Can't turn into multiple selection so clear additional selections InvalidateSelection(SelectionRange(newPos), true); sel.DropAdditionalRanges(); } - if (!sel.IsRectangular() && (selt == Selection::selRectangle)) { + if (!sel.IsRectangular() && (selt == Selection::SelTypes::rectangle)) { // Switching to rectangular InvalidateSelection(sel.RangeMain(), false); SelectionRange rangeMain = sel.RangeMain(); sel.Clear(); sel.Rectangular() = rangeMain; } - if (selt != Selection::noSel) { + if (selt != Selection::SelTypes::none) { sel.selType = selt; } - if (selt != Selection::noSel || sel.MoveExtends()) { + if (selt != Selection::SelTypes::none || sel.MoveExtends()) { SetSelection(newPos); } else { SetEmptySelection(newPos); @@ -911,7 +911,7 @@ void Editor::MovePositionTo(SelectionPosition newPos, Selection::selTypes selt, MovedCaret(newPos, spCaret, ensureVisible, caretPolicies); } -void Editor::MovePositionTo(Sci::Position newPos, Selection::selTypes selt, bool ensureVisible) { +void Editor::MovePositionTo(Sci::Position newPos, Selection::SelTypes selt, bool ensureVisible) { MovePositionTo(SelectionPosition(newPos), selt, ensureVisible); } @@ -959,7 +959,7 @@ void Editor::ScrollTo(Sci::Line line, bool moveThumb) { // Try to optimise small scrolls #ifndef UNDER_CE const Sci::Line linesToMove = topLine - topLineNew; - const bool performBlit = (std::abs(linesToMove) <= 10) && (paintState == notPainting); + const bool performBlit = (std::abs(linesToMove) <= 10) && (paintState == PaintState::notPainting); willRedrawAll = !performBlit; #endif SetTopLine(topLineNew); @@ -1091,13 +1091,13 @@ void Editor::MoveCaretInsideView(bool ensureVisible) { MovePositionTo(SPositionFromLocation( Point::FromInts(lastXChosen - xOffset, static_cast<int>(rcClient.top)), false, false, UserVirtualSpace()), - Selection::noSel, ensureVisible); + Selection::SelTypes::none, ensureVisible); } else if ((pt.y + vs.lineHeight - 1) > rcClient.bottom) { const ptrdiff_t yOfLastLineFullyDisplayed = static_cast<ptrdiff_t>(rcClient.top) + (LinesOnScreen() - 1) * vs.lineHeight; MovePositionTo(SPositionFromLocation( Point::FromInts(lastXChosen - xOffset, static_cast<int>(rcClient.top + yOfLastLineFullyDisplayed)), false, false, UserVirtualSpace()), - Selection::noSel, ensureVisible); + Selection::SelTypes::none, ensureVisible); } } @@ -1166,7 +1166,8 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } // Vertical positioning - if ((options & xysVertical) && (pt.y < rcClient.top || ptBottomCaret.y >= rcClient.bottom || (policies.y.policy & CARET_STRICT) != 0)) { + if (FlagSet(options, XYScrollOptions::vertical) && + (pt.y < rcClient.top || ptBottomCaret.y >= rcClient.bottom || (policies.y.policy & CARET_STRICT) != 0)) { const Sci::Line lineCaret = DisplayFromPosition(range.caret.Position()); const Sci::Line linesOnScreen = LinesOnScreen(); const Sci::Line halfScreen = std::max(linesOnScreen - 1, static_cast<Sci::Line>(2)) / 2; @@ -1181,7 +1182,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran Sci::Line yMoveT, yMoveB; if (bStrict) { Sci::Line yMarginT, yMarginB; - if (!(options & xysUseMargin)) { + if (!FlagSet(options, XYScrollOptions::useMargin)) { // In drag mode, avoid moves // otherwise, a double click will select several lines. yMarginT = yMarginB = 0; @@ -1267,7 +1268,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } // Horizontal positioning - if ((options & xysHorizontal) && !Wrapping()) { + if (FlagSet(options, XYScrollOptions::horizontal) && !Wrapping()) { const int halfScreen = std::max(static_cast<int>(rcClient.Width()) - 4, 4) / 2; const bool bSlop = (policies.x.policy & CARET_SLOP) != 0; const bool bStrict = (policies.x.policy & CARET_STRICT) != 0; @@ -1278,7 +1279,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran int xMoveL, xMoveR; if (bStrict) { int xMarginL, xMarginR; - if (!(options & xysUseMargin)) { + if (!FlagSet(options, XYScrollOptions::useMargin)) { // In drag mode, avoid moves unless very near of the margin // otherwise, a simple click will select text. xMarginL = xMarginR = 2; @@ -1415,12 +1416,22 @@ void Editor::SetXYScroll(XYScrollPosition newXY) { } void Editor::ScrollRange(SelectionRange range) { - SetXYScroll(XYScrollToMakeVisible(range, xysDefault, caretPolicies)); + SetXYScroll(XYScrollToMakeVisible(range, XYScrollOptions::all, caretPolicies)); +} + +namespace { + +constexpr XYScrollOptions operator|(XYScrollOptions a, XYScrollOptions b) noexcept { + return static_cast<XYScrollOptions>(static_cast<int>(a) | static_cast<int>(b)); +} + } void Editor::EnsureCaretVisible(bool useMargin, bool vert, bool horiz) { SetXYScroll(XYScrollToMakeVisible(SelectionRange(posDrag.IsValid() ? posDrag : sel.RangeMain().caret), - static_cast<XYScrollOptions>((useMargin?xysUseMargin:0)|(vert?xysVertical:0)|(horiz?xysHorizontal:0)), + (useMargin?XYScrollOptions::useMargin:XYScrollOptions::none)| + (vert?XYScrollOptions::vertical:XYScrollOptions::none)| + (horiz?XYScrollOptions::horizontal:XYScrollOptions::none), caretPolicies)); } @@ -1428,20 +1439,20 @@ void Editor::ShowCaretAtCurrentPosition() { if (hasFocus) { caret.active = true; caret.on = true; - FineTickerCancel(tickCaret); + FineTickerCancel(TickReason::caret); if (caret.period > 0) - FineTickerStart(tickCaret, caret.period, caret.period/10); + FineTickerStart(TickReason::caret, caret.period, caret.period/10); } else { caret.active = false; caret.on = false; - FineTickerCancel(tickCaret); + FineTickerCancel(TickReason::caret); } InvalidateCaret(); } void Editor::DropCaret() { caret.active = false; - FineTickerCancel(tickCaret); + FineTickerCancel(TickReason::caret); InvalidateCaret(); } @@ -1449,9 +1460,9 @@ void Editor::CaretSetPeriod(int period) { if (caret.period != period) { caret.period = period; caret.on = true; - FineTickerCancel(tickCaret); + FineTickerCancel(TickReason::caret); if ((caret.active) && (caret.period > 0)) - FineTickerStart(tickCaret, caret.period, caret.period/10); + FineTickerStart(TickReason::caret, caret.period, caret.period/10); InvalidateCaret(); } } @@ -1729,7 +1740,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { AllocateGraphics(); RefreshStyleData(); - if (paintState == paintAbandoned) + if (paintState == PaintState::abandoned) return; // Scroll bars may have changed so need redraw RefreshPixMaps(surfaceWindow); @@ -1766,7 +1777,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { if (!view.bufferedDraw) surfaceWindow->SetClip(rcArea); - if (paintState != paintAbandoned) { + if (paintState != PaintState::abandoned) { if (vs.marginInside) { PaintSelMargin(surfaceWindow, rcArea); PRectangle rcRightMargin = rcClient; @@ -1784,7 +1795,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { } } - if (paintState == paintAbandoned) { + if (paintState == PaintState::abandoned) { // Either styling or NotifyUpdateUI noticed that painting is needed // outside the current painting rectangle //Platform::DebugPrintf("Abandoning paint\n"); @@ -1802,8 +1813,8 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { if (horizontalScrollBarVisible && trackLineWidth && (view.lineWidthMaxSeen > scrollWidth)) { scrollWidth = view.lineWidthMaxSeen; - if (!FineTickerRunning(tickWiden)) { - FineTickerStart(tickWiden, 50, 5); + if (!FineTickerRunning(TickReason::widen)) { + FineTickerStart(TickReason::widen, 50, 5); } } @@ -2079,10 +2090,10 @@ void Editor::InsertPasteShape(const char *text, Sci::Position len, PasteShape sh len = convertedText.length(); text = convertedText.c_str(); } - if (shape == pasteRectangular) { + if (shape == PasteShape::rectangular) { PasteRectangular(sel.Start(), text, len); } else { - if (shape == pasteLine) { + if (shape == PasteShape::line) { const Sci::Position insertPos = pdoc->LineStart(pdoc->LineFromPosition(sel.MainCaret())); Sci::Position lengthInserted = pdoc->InsertString(insertPos, text, len); @@ -2572,11 +2583,11 @@ constexpr Sci::Position MovePositionForDeletion(Sci::Position position, Sci::Pos void Editor::NotifyModified(Document *, DocModification mh, void *) { ContainerNeedsUpdate(SC_UPDATE_CONTENT); - if (paintState == painting) { + if (paintState == PaintState::painting) { CheckForChangeOutsidePaint(Range(mh.position, mh.position + mh.length)); } if (mh.modificationType & SC_MOD_CHANGELINESTATE) { - if (paintState == painting) { + if (paintState == PaintState::painting) { CheckForChangeOutsidePaint( Range(pdoc->LineStart(mh.line), pdoc->LineStart(mh.line + 1))); @@ -2589,7 +2600,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { Redraw(); } if (mh.modificationType & SC_MOD_LEXERSTATE) { - if (paintState == painting) { + if (paintState == PaintState::painting) { CheckForChangeOutsidePaint( Range(mh.position, mh.position + mh.length)); } else { @@ -2600,7 +2611,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { if (mh.modificationType & SC_MOD_CHANGESTYLE) { pdoc->IncrementStyleClock(); } - if (paintState == notPainting) { + if (paintState == PaintState::notPainting) { const Sci::Line lineDocTop = pcs->DocFromDisplay(topLine); if (mh.position < pdoc->LineStart(lineDocTop)) { // Styling performed before this view @@ -2682,16 +2693,16 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { } } - if (paintState == notPainting && !CanDeferToLastStep(mh)) { + if (paintState == PaintState::notPainting && !CanDeferToLastStep(mh)) { if (SynchronousStylingToVisible()) { - QueueIdleWork(WorkNeeded::workStyle, pdoc->Length()); + QueueIdleWork(WorkItems::style, pdoc->Length()); } Redraw(); } } else { - if (paintState == notPainting && mh.length && !CanEliminate(mh)) { + if (paintState == PaintState::notPainting && mh.length && !CanEliminate(mh)) { if (SynchronousStylingToVisible()) { - QueueIdleWork(WorkNeeded::workStyle, mh.position + mh.length); + QueueIdleWork(WorkItems::style, mh.position + mh.length); } InvalidateRange(mh.position, mh.position + mh.length); } @@ -2703,7 +2714,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { } if ((mh.modificationType & SC_MOD_CHANGEMARKER) || (mh.modificationType & SC_MOD_CHANGEMARGIN)) { - if ((!willRedrawAll) && ((paintState == notPainting) || !PaintContainsMargin())) { + if ((!willRedrawAll) && ((paintState == PaintState::notPainting) || !PaintContainsMargin())) { if (mh.modificationType & SC_MOD_CHANGEFOLD) { // Fold changes can affect the drawing of following lines so redraw whole margin RedrawSelMargin(marginView.highlightDelimiter.isEnabled ? -1 : mh.line - 1, true); @@ -2893,7 +2904,7 @@ void Editor::ContainerNeedsUpdate(int flags) noexcept { * If stuttered = true and not already at first/last row, move to first/last row of window. * If stuttered = true and already at first/last row, scroll as normal. */ -void Editor::PageMove(int direction, Selection::selTypes selt, bool stuttered) { +void Editor::PageMove(int direction, Selection::SelTypes selt, bool stuttered) { Sci::Line topLineNew; SelectionPosition newPos; @@ -2935,7 +2946,7 @@ void Editor::PageMove(int direction, Selection::selTypes selt, bool stuttered) { } } -void Editor::ChangeCaseOfSelection(int caseMapping) { +void Editor::ChangeCaseOfSelection(CaseMapping caseMapping) { UndoGroup ug(pdoc); for (size_t r=0; r<sel.Count(); r++) { SelectionRange current = sel.Range(r); @@ -3175,19 +3186,19 @@ SelectionPosition Editor::PositionUpOrDown(SelectionPosition spStart, int direct return posNew; } -void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) { - if ((selt == Selection::noSel) && sel.MoveExtends()) { - selt = !sel.IsRectangular() ? Selection::selStream : Selection::selRectangle; +void Editor::CursorUpOrDown(int direction, Selection::SelTypes selt) { + if ((selt == Selection::SelTypes::none) && sel.MoveExtends()) { + selt = !sel.IsRectangular() ? Selection::SelTypes::stream : Selection::SelTypes::rectangle; } SelectionPosition caretToUse = sel.Range(sel.Main()).caret; if (sel.IsRectangular()) { - if (selt == Selection::noSel) { + if (selt == Selection::SelTypes::none) { caretToUse = (direction > 0) ? sel.Limits().end : sel.Limits().start; } else { caretToUse = sel.Rectangular().caret; } } - if (selt == Selection::selRectangle) { + if (selt == Selection::SelTypes::rectangle) { const SelectionRange rangeBase = sel.IsRectangular() ? sel.Rectangular() : sel.RangeMain(); if (!sel.IsRectangular()) { InvalidateWholeSelection(); @@ -3195,11 +3206,11 @@ void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) { } const SelectionPosition posNew = MovePositionSoVisible( PositionUpOrDown(caretToUse, direction, lastXChosen), direction); - sel.selType = Selection::selRectangle; + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular() = SelectionRange(posNew, rangeBase.anchor); SetRectangularRange(); MovedCaret(posNew, caretToUse, true, caretPolicies); - } else if (sel.selType == Selection::selLines && sel.MoveExtends()) { + } else if (sel.selType == Selection::SelTypes::lines && sel.MoveExtends()) { // Calculate new caret position and call SetSelection(), which will ensure whole lines are selected. const SelectionPosition posNew = MovePositionSoVisible( PositionUpOrDown(caretToUse, direction, -1), direction); @@ -3209,13 +3220,13 @@ void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) { if (!additionalSelectionTyping || (sel.IsRectangular())) { sel.DropAdditionalRanges(); } - sel.selType = Selection::selStream; + sel.selType = Selection::SelTypes::stream; for (size_t r = 0; r < sel.Count(); r++) { const int lastX = (r == sel.Main()) ? lastXChosen : -1; const SelectionPosition spCaretNow = sel.Range(r).caret; const SelectionPosition posNew = MovePositionSoVisible( PositionUpOrDown(spCaretNow, direction, lastX), direction); - sel.Range(r) = selt == Selection::selStream ? + sel.Range(r) = selt == Selection::SelTypes::stream ? SelectionRange(posNew, sel.Range(r).anchor) : SelectionRange(posNew); } sel.RemoveDuplicates(); @@ -3223,7 +3234,7 @@ void Editor::CursorUpOrDown(int direction, Selection::selTypes selt) { } } -void Editor::ParaUpOrDown(int direction, Selection::selTypes selt) { +void Editor::ParaUpOrDown(int direction, Selection::SelTypes selt) { Sci::Line lineDoc; const Sci::Position savedPos = sel.MainCaret(); do { @@ -3231,7 +3242,7 @@ void Editor::ParaUpOrDown(int direction, Selection::selTypes selt) { lineDoc = pdoc->SciLineFromPosition(sel.MainCaret()); if (direction > 0) { if (sel.MainCaret() >= pdoc->Length() && !pcs->GetVisible(lineDoc)) { - if (selt == Selection::noSel) { + if (selt == Selection::SelTypes::none) { MovePositionTo(SelectionPosition(pdoc->LineEndPosition(savedPos))); } break; @@ -3382,7 +3393,7 @@ Sci::Position Editor::LineEndWrapPosition(Sci::Position position) { } int Editor::HorizontalMove(unsigned int iMessage) { - if (sel.selType == Selection::selLines) { + if (sel.selType == Selection::SelTypes::lines) { return 0; // horizontal moves with line selection have no effect } if (sel.MoveExtends()) { @@ -3437,7 +3448,7 @@ int Editor::HorizontalMove(unsigned int iMessage) { } const int directionMove = (spCaret < rangeBase.caret) ? -1 : 1; spCaret = MovePositionSoVisible(spCaret, directionMove); - sel.selType = Selection::selRectangle; + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular() = SelectionRange(spCaret, rangeBase.anchor); SetRectangularRange(); } else if (sel.IsRectangular()) { @@ -3455,7 +3466,7 @@ int Editor::HorizontalMove(unsigned int iMessage) { selAtLimit = SelectionPosition(pdoc->LineEndPosition(selAtLimit.Position())); break; } - sel.selType = Selection::selStream; + sel.selType = Selection::SelTypes::stream; sel.SetSelection(SelectionRange(selAtLimit)); } else { if (!additionalSelectionTyping) { @@ -3699,38 +3710,38 @@ int Editor::DelWordOrLine(unsigned int iMessage) { int Editor::KeyCommand(unsigned int iMessage) { switch (iMessage) { case SCI_LINEDOWN: - CursorUpOrDown(1, Selection::noSel); + CursorUpOrDown(1, Selection::SelTypes::none); break; case SCI_LINEDOWNEXTEND: - CursorUpOrDown(1, Selection::selStream); + CursorUpOrDown(1, Selection::SelTypes::stream); break; case SCI_LINEDOWNRECTEXTEND: - CursorUpOrDown(1, Selection::selRectangle); + CursorUpOrDown(1, Selection::SelTypes::rectangle); break; case SCI_PARADOWN: - ParaUpOrDown(1, Selection::noSel); + ParaUpOrDown(1, Selection::SelTypes::none); break; case SCI_PARADOWNEXTEND: - ParaUpOrDown(1, Selection::selStream); + ParaUpOrDown(1, Selection::SelTypes::stream); break; case SCI_LINESCROLLDOWN: ScrollTo(topLine + 1); MoveCaretInsideView(false); break; case SCI_LINEUP: - CursorUpOrDown(-1, Selection::noSel); + CursorUpOrDown(-1, Selection::SelTypes::none); break; case SCI_LINEUPEXTEND: - CursorUpOrDown(-1, Selection::selStream); + CursorUpOrDown(-1, Selection::SelTypes::stream); break; case SCI_LINEUPRECTEXTEND: - CursorUpOrDown(-1, Selection::selRectangle); + CursorUpOrDown(-1, Selection::SelTypes::rectangle); break; case SCI_PARAUP: - ParaUpOrDown(-1, Selection::noSel); + ParaUpOrDown(-1, Selection::SelTypes::none); break; case SCI_PARAUPEXTEND: - ParaUpOrDown(-1, Selection::selStream); + ParaUpOrDown(-1, Selection::SelTypes::stream); break; case SCI_LINESCROLLUP: ScrollTo(topLine - 1); @@ -3783,7 +3794,7 @@ int Editor::KeyCommand(unsigned int iMessage) { SetLastXChosen(); break; case SCI_DOCUMENTSTARTEXTEND: - MovePositionTo(0, Selection::selStream); + MovePositionTo(0, Selection::SelTypes::stream); SetLastXChosen(); break; case SCI_DOCUMENTEND: @@ -3791,38 +3802,38 @@ int Editor::KeyCommand(unsigned int iMessage) { SetLastXChosen(); break; case SCI_DOCUMENTENDEXTEND: - MovePositionTo(pdoc->Length(), Selection::selStream); + MovePositionTo(pdoc->Length(), Selection::SelTypes::stream); SetLastXChosen(); break; case SCI_STUTTEREDPAGEUP: - PageMove(-1, Selection::noSel, true); + PageMove(-1, Selection::SelTypes::none, true); break; case SCI_STUTTEREDPAGEUPEXTEND: - PageMove(-1, Selection::selStream, true); + PageMove(-1, Selection::SelTypes::stream, true); break; case SCI_STUTTEREDPAGEDOWN: - PageMove(1, Selection::noSel, true); + PageMove(1, Selection::SelTypes::none, true); break; case SCI_STUTTEREDPAGEDOWNEXTEND: - PageMove(1, Selection::selStream, true); + PageMove(1, Selection::SelTypes::stream, true); break; case SCI_PAGEUP: PageMove(-1); break; case SCI_PAGEUPEXTEND: - PageMove(-1, Selection::selStream); + PageMove(-1, Selection::SelTypes::stream); break; case SCI_PAGEUPRECTEXTEND: - PageMove(-1, Selection::selRectangle); + PageMove(-1, Selection::SelTypes::rectangle); break; case SCI_PAGEDOWN: PageMove(1); break; case SCI_PAGEDOWNEXTEND: - PageMove(1, Selection::selStream); + PageMove(1, Selection::SelTypes::stream); break; case SCI_PAGEDOWNRECTEXTEND: - PageMove(1, Selection::selRectangle); + PageMove(1, Selection::SelTypes::rectangle); break; case SCI_EDITTOGGLEOVERTYPE: inOverstrike = !inOverstrike; @@ -3934,10 +3945,10 @@ int Editor::KeyCommand(unsigned int iMessage) { Duplicate(false); break; case SCI_LOWERCASE: - ChangeCaseOfSelection(cmLower); + ChangeCaseOfSelection(CaseMapping::lower); break; case SCI_UPPERCASE: - ChangeCaseOfSelection(cmUpper); + ChangeCaseOfSelection(CaseMapping::upper); break; case SCI_SCROLLTOSTART: ScrollTo(0); @@ -4145,16 +4156,18 @@ Sci::Position Editor::SearchText( return pos; } -std::string Editor::CaseMapString(const std::string &s, int caseMapping) { +std::string Editor::CaseMapString(const std::string &s, CaseMapping caseMapping) { std::string ret(s); for (char &ch : ret) { switch (caseMapping) { - case cmUpper: + case CaseMapping::upper: ch = MakeUpperCase(ch); break; - case cmLower: + case CaseMapping::lower: ch = MakeLowerCase(ch); break; + default: // no action + break; } } return ret; @@ -4231,11 +4244,11 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { } else { std::string text; std::vector<SelectionRange> rangesInOrder = sel.RangesCopy(); - if (sel.selType == Selection::selRectangle) + if (sel.selType == Selection::SelTypes::rectangle) std::sort(rangesInOrder.begin(), rangesInOrder.end()); for (const SelectionRange ¤t : rangesInOrder) { text.append(RangeText(current.Start().Position(), current.End().Position())); - if (sel.selType == Selection::selRectangle) { + if (sel.selType == Selection::SelTypes::rectangle) { if (pdoc->eolMode != SC_EOL_LF) text.push_back('\r'); if (pdoc->eolMode != SC_EOL_CR) @@ -4243,7 +4256,7 @@ void Editor::CopySelectionRange(SelectionText *ss, bool allowLineCopy) { } } ss->Copy(text, pdoc->dbcsCodePage, - vs.styles[STYLE_DEFAULT].characterSet, sel.IsRectangular(), sel.selType == Selection::selLines); + vs.styles[STYLE_DEFAULT].characterSet, sel.IsRectangular(), sel.selType == Selection::SelTypes::lines); } } @@ -4277,9 +4290,9 @@ void Editor::SetDragPosition(SelectionPosition newPos) { MovedCaret(newPos, posDrag, true, dragCaretPolicies); caret.on = true; - FineTickerCancel(tickCaret); + FineTickerCancel(TickReason::caret); if ((caret.active) && (caret.period > 0) && (newPos.Position() < 0)) - FineTickerStart(tickCaret, caret.period, caret.period/10); + FineTickerStart(TickReason::caret, caret.period, caret.period/10); InvalidateCaret(); posDrag = newPos; InvalidateCaret(); @@ -4307,7 +4320,7 @@ void Editor::StartDrag() { void Editor::DropAt(SelectionPosition position, const char *value, size_t lengthValue, bool moving, bool rectangular) { //Platform::DebugPrintf("DropAt %d %d\n", inDragDrop, position); - if (inDragDrop == ddDragging) + if (inDragDrop == DragDrop::dragging) dropWentOutside = false; const bool positionWasInSelection = PositionInSelection(position.Position()); @@ -4315,7 +4328,7 @@ void Editor::DropAt(SelectionPosition position, const char *value, size_t length const bool positionOnEdgeOfSelection = (position == SelectionStart()) || (position == SelectionEnd()); - if ((inDragDrop != ddDragging) || !(positionWasInSelection) || + if ((inDragDrop != DragDrop::dragging) || !(positionWasInSelection) || (positionOnEdgeOfSelection && !moving)) { const SelectionPosition selStart = SelectionStart(); @@ -4324,9 +4337,9 @@ void Editor::DropAt(SelectionPosition position, const char *value, size_t length UndoGroup ug(pdoc); SelectionPosition positionAfterDeletion = position; - if ((inDragDrop == ddDragging) && moving) { + if ((inDragDrop == DragDrop::dragging) && moving) { // Remove dragged out text - if (rectangular || sel.selType == Selection::selLines) { + if (rectangular || sel.selType == Selection::SelTypes::lines) { for (size_t r=0; r<sel.Count(); r++) { if (position >= sel.Range(r).Start()) { if (position > sel.Range(r).End()) { @@ -4362,7 +4375,7 @@ void Editor::DropAt(SelectionPosition position, const char *value, size_t length SetSelection(posAfterInsertion, position); } } - } else if (inDragDrop == ddDragging) { + } else if (inDragDrop == DragDrop::dragging) { SetEmptySelection(position); } } @@ -4505,7 +4518,7 @@ void Editor::DwellEnd(bool mouseMoved) { dwelling = false; NotifyDwelling(ptMouseLast, dwelling); } - FineTickerCancel(tickDwell); + FineTickerCancel(TickReason::dwell); } void Editor::MouseLeave() { @@ -4533,7 +4546,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie newPos = MovePositionOutsideChar(newPos, sel.MainCaret() - newPos.Position()); SelectionPosition newCharPos = SPositionFromLocation(pt, false, true, false); newCharPos = MovePositionOutsideChar(newCharPos, -1); - inDragDrop = ddNone; + inDragDrop = DragDrop::none; sel.SetMoveExtends(false); if (NotifyMarginClick(pt, modifiers)) @@ -4555,7 +4568,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie if ((curTime < (lastClickTime+Platform::DoubleClickTime())) && Close(pt, lastClick, doubleClickCloseThreshold)) { //Platform::DebugPrintf("Double click %d %d = %d\n", curTime, lastClickTime, curTime - lastClickTime); SetMouseCapture(true); - FineTickerStart(tickScroll, 100, 10); + FineTickerStart(TickReason::scroll, 100, 10); if (!ctrl || !multipleSelection || (selectionUnit != TextUnit::character && selectionUnit != TextUnit::word)) SetEmptySelection(newPos.Position()); bool doubleClick = false; @@ -4631,7 +4644,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie InvalidateWholeSelection(); sel.Clear(); } - sel.selType = Selection::selStream; + sel.selType = Selection::SelTypes::stream; if (!shift) { // Single click in margin: select wholeLine or only subLine if word wrap is enabled lineAnchorPos = newPos.Position(); @@ -4645,7 +4658,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie lineAnchorPos = sel.MainAnchor(); // Reset selection type if there is an empty selection. // This ensures that we don't end up stuck in previous selection mode, which is no longer valid. - // Otherwise, if there's a non empty selection, reset selection type only if it differs from subLine and wholeLine. + // Otherwise, if there's a non empty selection, reset selection type only if it differs from selSubLine and selWholeLine. // This ensures that we continue selecting in the same selection mode. if (sel.Empty() || (selectionUnit != TextUnit::subLine && selectionUnit != TextUnit::wholeLine)) selectionUnit = (Wrapping() && (marginOptions & SC_MARGINOPTION_SUBLINESELECT)) ? TextUnit::subLine : TextUnit::wholeLine; @@ -4654,7 +4667,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie SetDragPosition(SelectionPosition(Sci::invalidPosition)); SetMouseCapture(true); - FineTickerStart(tickScroll, 100, 10); + FineTickerStart(TickReason::scroll, 100, 10); } else { if (PointIsHotspot(pt)) { NotifyHotSpotClicked(newCharPos.Position(), modifiers); @@ -4662,13 +4675,13 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie } if (!shift) { if (PointInSelection(pt) && !SelectionEmpty()) - inDragDrop = ddInitial; + inDragDrop = DragDrop::initial; else - inDragDrop = ddNone; + inDragDrop = DragDrop::none; } SetMouseCapture(true); - FineTickerStart(tickScroll, 100, 10); - if (inDragDrop != ddInitial) { + FineTickerStart(TickReason::scroll, 100, 10); + if (inDragDrop != DragDrop::initial) { SetDragPosition(SelectionPosition(Sci::invalidPosition)); if (!shift) { if (ctrl && multipleSelection) { @@ -4679,9 +4692,9 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie InvalidateSelection(SelectionRange(newPos), true); if (sel.Count() > 1) Redraw(); - if ((sel.Count() > 1) || (sel.selType != Selection::selStream)) + if ((sel.Count() > 1) || (sel.selType != Selection::SelTypes::stream)) sel.Clear(); - sel.selType = alt ? Selection::selRectangle : Selection::selStream; + sel.selType = alt ? Selection::SelTypes::rectangle : Selection::SelTypes::stream; SetSelection(newPos, newPos); } } @@ -4689,7 +4702,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie if (shift) anchorCurrent = sel.IsRectangular() ? sel.Rectangular().anchor : sel.RangeMain().anchor; - sel.selType = alt ? Selection::selRectangle : Selection::selStream; + sel.selType = alt ? Selection::SelTypes::rectangle : Selection::SelTypes::stream; selectionUnit = TextUnit::character; originalAnchorPos = sel.MainCaret(); sel.Rectangular() = SelectionRange(newPos, anchorCurrent); @@ -4786,10 +4799,10 @@ void Editor::ButtonMoveWithModifiers(Point pt, unsigned int, int modifiers) { AllowVirtualSpace(virtualSpaceOptions, sel.IsRectangular())); movePos = MovePositionOutsideChar(movePos, sel.MainCaret() - movePos.Position()); - if (inDragDrop == ddInitial) { + if (inDragDrop == DragDrop::initial) { if (DragThreshold(ptMouseLast, pt)) { SetMouseCapture(false); - FineTickerCancel(tickScroll); + FineTickerCancel(TickReason::scroll); SetDragPosition(movePos); CopySelectionRange(&drag); StartDrag(); @@ -4802,7 +4815,7 @@ void Editor::ButtonMoveWithModifiers(Point pt, unsigned int, int modifiers) { const Point ptOrigin = GetVisibleOriginInMain(); rcClient.Move(0, -ptOrigin.y); if ((dwellDelay < SC_TIME_FOREVER) && rcClient.Contains(pt)) { - FineTickerStart(tickDwell, dwellDelay, dwellDelay/10); + FineTickerStart(TickReason::dwell, dwellDelay, dwellDelay/10); } //Platform::DebugPrintf("Move %d %d\n", pt.x, pt.y); if (HaveMouseCapture()) { @@ -4818,8 +4831,8 @@ void Editor::ButtonMoveWithModifiers(Point pt, unsigned int, int modifiers) { SetDragPosition(movePos); } else { if (selectionUnit == TextUnit::character) { - if (sel.selType == Selection::selStream && (modifiers & SCI_ALT) && mouseSelectionRectangularSwitch) { - sel.selType = Selection::selRectangle; + if (sel.selType == Selection::SelTypes::stream && (modifiers & SCI_ALT) && mouseSelectionRectangularSwitch) { + sel.selType = Selection::SelTypes::rectangle; } if (sel.IsRectangular()) { sel.Rectangular() = SelectionRange(movePos, sel.Rectangular().anchor); @@ -4869,7 +4882,7 @@ void Editor::ButtonMoveWithModifiers(Point pt, unsigned int, int modifiers) { SetHotSpotRange(nullptr); if (hotSpotClickPos != INVALID_POSITION && PositionFromLocation(pt, true, true) != hotSpotClickPos) { - if (inDragDrop == ddNone) { + if (inDragDrop == DragDrop::none) { DisplayCursor(Window::Cursor::text); } hotSpotClickPos = INVALID_POSITION; @@ -4911,8 +4924,8 @@ void Editor::ButtonUpWithModifiers(Point pt, unsigned int curTime, int modifiers if (hoverIndicatorPos != INVALID_POSITION) InvalidateRange(newPos.Position(), newPos.Position() + 1); newPos = MovePositionOutsideChar(newPos, sel.MainCaret() - newPos.Position()); - if (inDragDrop == ddInitial) { - inDragDrop = ddNone; + if (inDragDrop == DragDrop::initial) { + inDragDrop = DragDrop::none; SetEmptySelection(newPos); selectionUnit = TextUnit::character; originalAnchorPos = sel.MainCaret(); @@ -4932,9 +4945,9 @@ void Editor::ButtonUpWithModifiers(Point pt, unsigned int curTime, int modifiers } ptMouseLast = pt; SetMouseCapture(false); - FineTickerCancel(tickScroll); + FineTickerCancel(TickReason::scroll); NotifyIndicatorClick(false, newPos.Position(), 0); - if (inDragDrop == ddDragging) { + if (inDragDrop == DragDrop::dragging) { const SelectionPosition selStart = SelectionStart(); const SelectionPosition selEnd = SelectionEnd(); if (selStart < selEnd) { @@ -4984,10 +4997,10 @@ void Editor::ButtonUpWithModifiers(Point pt, unsigned int curTime, int modifiers lastClickTime = curTime; lastClick = pt; lastXChosen = static_cast<int>(pt.x) + xOffset; - if (sel.selType == Selection::selStream) { + if (sel.selType == Selection::SelTypes::stream) { SetLastXChosen(); } - inDragDrop = ddNone; + inDragDrop = DragDrop::none; EnsureCaretVisible(false); } } @@ -5018,27 +5031,27 @@ bool Editor::Idle() { void Editor::TickFor(TickReason reason) { switch (reason) { - case tickCaret: + case TickReason::caret: caret.on = !caret.on; if (caret.active) { InvalidateCaret(); } break; - case tickScroll: + case TickReason::scroll: // Auto scroll ButtonMoveWithModifiers(ptMouseLast, 0, 0); break; - case tickWiden: + case TickReason::widen: SetScrollBars(); - FineTickerCancel(tickWiden); + FineTickerCancel(TickReason::widen); break; - case tickDwell: + case TickReason::dwell: if ((!HaveMouseCapture()) && (ptMouseLast.y >= 0)) { dwelling = true; NotifyDwelling(ptMouseLast, dwelling); } - FineTickerCancel(tickDwell); + FineTickerCancel(TickReason::dwell); break; default: // tickPlatform handled by subclass @@ -5166,14 +5179,14 @@ void Editor::IdleStyling() { void Editor::IdleWork() { // Style the line after the modification as this allows modifications that change just the // line of the modification to heal instead of propagating to the rest of the window. - if (workNeeded.items & WorkNeeded::workStyle) { + if (FlagSet(workNeeded.items, WorkItems::style)) { StyleToPositionInView(pdoc->LineStart(pdoc->LineFromPosition(workNeeded.upTo) + 2)); } NotifyUpdateUI(); workNeeded.Reset(); } -void Editor::QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) { +void Editor::QueueIdleWork(WorkItems items, Sci::Position upTo) { workNeeded.Need(items, upTo); } @@ -5201,7 +5214,7 @@ bool Editor::PaintContainsMargin() { } void Editor::CheckForChangeOutsidePaint(Range r) { - if (paintState == painting && !paintingAllText) { + if (paintState == PaintState::painting && !paintingAllText) { //Platform::DebugPrintf("Checking range in paint %d-%d\n", r.start, r.end); if (!r.Valid()) return; @@ -5235,7 +5248,7 @@ void Editor::SetBraceHighlight(Sci::Position pos0, Sci::Position pos1, int match braces[1] = pos1; } bracesMatchStyle = matchStyle; - if (paintState == notPainting) { + if (paintState == PaintState::notPainting) { Redraw(); } } @@ -5717,7 +5730,7 @@ void Editor::StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam vs.styles[wParam].underline = lParam != 0; break; case SCI_STYLESETCASE: - vs.styles[wParam].caseForce = static_cast<Style::ecaseForced>(lParam); + vs.styles[wParam].caseForce = static_cast<Style::CaseForce>(lParam); break; case SCI_STYLESETCHARACTERSET: vs.styles[wParam].characterSet = static_cast<int>(lParam); @@ -5967,7 +5980,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { nStart = nEnd; // Remove selection InvalidateSelection(SelectionRange(nStart, nEnd)); sel.Clear(); - sel.selType = Selection::selStream; + sel.selType = Selection::SelTypes::stream; SetSelection(nEnd, nStart); EnsureCaretVisible(); } @@ -6571,7 +6584,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { #endif case SCI_GETPHASESDRAW: - return view.phasesDraw; + return static_cast<sptr_t>(view.phasesDraw); case SCI_SETPHASESDRAW: if (view.SetPhasesDraw(static_cast<int>(wParam))) @@ -6888,7 +6901,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_GETIMEINTERACTION: - return imeInteraction; + return static_cast<sptr_t>(imeInteraction); case SCI_SETBIDIRECTIONAL: // SCI_SETBIDIRECTIONAL is implemented on platform subclasses if they support bidirectional text. @@ -7797,44 +7810,44 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return 0; case SCI_SELECTIONISRECTANGLE: - return sel.selType == Selection::selRectangle ? 1 : 0; + return sel.selType == Selection::SelTypes::rectangle ? 1 : 0; case SCI_SETSELECTIONMODE: { switch (wParam) { case SC_SEL_STREAM: - sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::selStream)); - sel.selType = Selection::selStream; + sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::SelTypes::stream)); + sel.selType = Selection::SelTypes::stream; break; case SC_SEL_RECTANGLE: - sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::selRectangle)); - sel.selType = Selection::selRectangle; + sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::SelTypes::rectangle)); + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular() = sel.RangeMain(); // adjust current selection break; case SC_SEL_LINES: - sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::selLines)); - sel.selType = Selection::selLines; + sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::SelTypes::lines)); + sel.selType = Selection::SelTypes::lines; SetSelection(sel.RangeMain().caret, sel.RangeMain().anchor); // adjust current selection break; case SC_SEL_THIN: - sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::selThin)); - sel.selType = Selection::selThin; + sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::SelTypes::thin)); + sel.selType = Selection::SelTypes::thin; break; default: - sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::selStream)); - sel.selType = Selection::selStream; + sel.SetMoveExtends(!sel.MoveExtends() || (sel.selType != Selection::SelTypes::stream)); + sel.selType = Selection::SelTypes::stream; } InvalidateWholeSelection(); break; } case SCI_GETSELECTIONMODE: switch (sel.selType) { - case Selection::selStream: + case Selection::SelTypes::stream: return SC_SEL_STREAM; - case Selection::selRectangle: + case Selection::SelTypes::rectangle: return SC_SEL_RECTANGLE; - case Selection::selLines: + case Selection::SelTypes::lines: return SC_SEL_LINES; - case Selection::selThin: + case Selection::SelTypes::thin: return SC_SEL_THIN; default: // ?! return SC_SEL_STREAM; @@ -8281,7 +8294,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_SETRECTANGULARSELECTIONCARET: if (!sel.IsRectangular()) sel.Clear(); - sel.selType = Selection::selRectangle; + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular().caret.SetPosition(static_cast<Sci::Position>(wParam)); SetRectangularRange(); Redraw(); @@ -8293,7 +8306,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_SETRECTANGULARSELECTIONANCHOR: if (!sel.IsRectangular()) sel.Clear(); - sel.selType = Selection::selRectangle; + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular().anchor.SetPosition(static_cast<Sci::Position>(wParam)); SetRectangularRange(); Redraw(); @@ -8305,7 +8318,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE: if (!sel.IsRectangular()) sel.Clear(); - sel.selType = Selection::selRectangle; + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular().caret.SetVirtualSpace(static_cast<Sci::Position>(wParam)); SetRectangularRange(); Redraw(); @@ -8317,7 +8330,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE: if (!sel.IsRectangular()) sel.Clear(); - sel.selType = Selection::selRectangle; + sel.selType = Selection::SelTypes::rectangle; sel.Rectangular().anchor.SetVirtualSpace(static_cast<Sci::Position>(wParam)); SetRectangularRange(); Redraw(); diff --git a/src/Editor.h b/src/Editor.h index 87a904bf1..fc3a84ecd 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -37,25 +37,27 @@ public: * accumulate needed styling range and other work items in * WorkNeeded to avoid unnecessary work inside paint handler */ + +enum class WorkItems { + none = 0, + style = 1, + updateUI = 2 +}; + class WorkNeeded { public: - enum workItems { - workNone=0, - workStyle=1, - workUpdateUI=2 - }; - enum workItems items; + enum WorkItems items; Sci::Position upTo; - WorkNeeded() noexcept : items(workNone), upTo(0) {} + WorkNeeded() noexcept : items(WorkItems::none), upTo(0) {} void Reset() noexcept { - items = workNone; + items = WorkItems::none; upTo = 0; } - void Need(workItems items_, Sci::Position pos) noexcept { - if ((items_ & workStyle) && (upTo < pos)) + void Need(WorkItems items_, Sci::Position pos) noexcept { + if (FlagSet(items_, WorkItems::style) && (upTo < pos)) upTo = pos; - items = static_cast<workItems>(items | items_); + items = static_cast<WorkItems>(static_cast<int>(items) | static_cast<int>(items_)); } }; @@ -155,6 +157,14 @@ struct CaretPolicies { CaretPolicy y; }; +enum class XYScrollOptions { + none = 0x0, + useMargin = 0x1, + vertical = 0x2, + horizontal = 0x4, + all = useMargin | vertical | horizontal +}; + /** */ class Editor : public EditModel, public DocWatcher { @@ -212,7 +222,7 @@ protected: // ScintillaBase subclass needs access to much of Editor bool dwelling; enum class TextUnit { character, word, subLine, wholeLine } selectionUnit; Point ptMouseLast; - enum { ddNone, ddInitial, ddDragging } inDragDrop; + enum class DragDrop { none, initial, dragging } inDragDrop; bool dropWentOutside; SelectionPosition posDrop; Sci::Position hotSpotClickPos; @@ -230,7 +240,7 @@ protected: // ScintillaBase subclass needs access to much of Editor int needUpdateUI; - enum { notPainting, painting, paintAbandoned } paintState; + enum class PaintState { notPainting, painting, abandoned } paintState; bool paintAbandonedByStyling; PRectangle rcPaint; bool paintingAllText; @@ -290,8 +300,8 @@ protected: // ScintillaBase subclass needs access to much of Editor Sci::Line LinesToScroll() const; Sci::Line MaxScrollPos() const; SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const; - Point LocationFromPosition(SelectionPosition pos, PointEnd pe=peDefault); - Point LocationFromPosition(Sci::Position pos, PointEnd pe=peDefault); + Point LocationFromPosition(SelectionPosition pos, PointEnd pe=PointEnd::start); + Point LocationFromPosition(Sci::Position pos, PointEnd pe=PointEnd::start); int XFromPosition(SelectionPosition sp); SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true); Sci::Position PositionFromLocation(Point pt, bool canReturnInvalid = false, bool charPosition = false); @@ -334,8 +344,8 @@ protected: // ScintillaBase subclass needs access to much of Editor SelectionPosition MovePositionOutsideChar(SelectionPosition pos, Sci::Position moveDir, bool checkLineEnd=true) const; void MovedCaret(SelectionPosition newPos, SelectionPosition previousPos, bool ensureVisible, CaretPolicies policies); - void MovePositionTo(SelectionPosition newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true); - void MovePositionTo(Sci::Position newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true); + void MovePositionTo(SelectionPosition newPos, Selection::SelTypes selt=Selection::SelTypes::none, bool ensureVisible=true); + void MovePositionTo(Sci::Position newPos, Selection::SelTypes selt=Selection::SelTypes::none, bool ensureVisible=true); SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir); SelectionPosition MovePositionSoVisible(Sci::Position pos, int moveDir); Point PointMainCaret(); @@ -359,11 +369,6 @@ protected: // ScintillaBase subclass needs access to much of Editor return (xOffset == other.xOffset) && (topLine == other.topLine); } }; - enum XYScrollOptions { - xysUseMargin=0x1, - xysVertical=0x2, - xysHorizontal=0x4, - xysDefault=xysUseMargin|xysVertical|xysHorizontal}; XYScrollPosition XYScrollToMakeVisible(const SelectionRange &range, const XYScrollOptions options, CaretPolicies policies); void SetXYScroll(XYScrollPosition newXY); @@ -404,7 +409,7 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual void InsertCharacter(std::string_view sv, CharacterSource charSource); void ClearBeforeTentativeStart(); void InsertPaste(const char *text, Sci::Position len); - enum PasteShape { pasteStream=0, pasteRectangular = 1, pasteLine = 2 }; + enum class PasteShape { stream=0, rectangular = 1, line = 2 }; void InsertPasteShape(const char *text, Sci::Position len, PasteShape shape); void ClearSelection(bool retainMultipleSelections = false); void ClearAll(); @@ -456,18 +461,18 @@ protected: // ScintillaBase subclass needs access to much of Editor void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam); void ContainerNeedsUpdate(int flags) noexcept; - void PageMove(int direction, Selection::selTypes selt=Selection::noSel, bool stuttered = false); - enum { cmSame, cmUpper, cmLower }; - virtual std::string CaseMapString(const std::string &s, int caseMapping); - void ChangeCaseOfSelection(int caseMapping); + void PageMove(int direction, Selection::SelTypes selt=Selection::SelTypes::none, bool stuttered = false); + enum class CaseMapping { same, upper, lower }; + virtual std::string CaseMapString(const std::string &s, CaseMapping caseMapping); + void ChangeCaseOfSelection(CaseMapping caseMapping); void LineTranspose(); void LineReverse(); void Duplicate(bool forLine); virtual void CancelModes(); void NewLine(); SelectionPosition PositionUpOrDown(SelectionPosition spStart, int direction, int lastX); - void CursorUpOrDown(int direction, Selection::selTypes selt); - void ParaUpOrDown(int direction, Selection::selTypes selt); + void CursorUpOrDown(int direction, Selection::SelTypes selt); + void ParaUpOrDown(int direction, Selection::SelTypes selt); Range RangeDisplayLine(Sci::Line lineVisible); Sci::Position StartEndDisplayLine(Sci::Position pos, bool start); Sci::Position VCHomeDisplayPosition(Sci::Position position); @@ -515,7 +520,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void ButtonUpWithModifiers(Point pt, unsigned int curTime, int modifiers); bool Idle(); - enum TickReason { tickCaret, tickScroll, tickWiden, tickDwell, tickPlatform }; + enum class TickReason { caret, scroll, widen, dwell, platform }; virtual void TickFor(TickReason reason); virtual bool FineTickerRunning(TickReason reason); virtual void FineTickerStart(TickReason reason, int millis, int tolerance); @@ -535,7 +540,7 @@ protected: // ScintillaBase subclass needs access to much of Editor } void IdleStyling(); virtual void IdleWork(); - virtual void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo=0); + virtual void QueueIdleWork(WorkItems items, Sci::Position upTo=0); virtual int SupportsFeature(int feature); virtual bool PaintContains(PRectangle rc); diff --git a/src/Geometry.h b/src/Geometry.h index cee76498e..35702a468 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -13,6 +13,12 @@ namespace Scintilla { typedef float XYPOSITION; typedef double XYACCUMULATOR; +// Test if an enum class value has the bit flag(s) of test set. +template <typename T> +constexpr bool FlagSet(T value, T test) { + return (static_cast<int>(value) & static_cast<int>(test)) == static_cast<int>(test); +} + /** * A geometric point class. * Point is similar to the Win32 POINT and GTK+ GdkPoint types. diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 4d52d6036..fbe3488c0 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -401,7 +401,7 @@ void MarginView::PaintMargin(Surface *surface, Sci::Line topLine, PRectangle rc, const XYPOSITION xpos = rcNumber.right - width - vs.marginNumberPadding; rcNumber.left = xpos; DrawTextNoClipPhase(surface, rcNumber, vs.styles[STYLE_LINENUMBER], - rcNumber.top + vs.maxAscent, sNumber, drawAll); + rcNumber.top + vs.maxAscent, sNumber, DrawPhase::all); } else if (vs.wrapVisualFlags & SC_WRAPVISUALFLAG_MARGIN) { PRectangle rcWrapMarker = rcMarker; rcWrapMarker.right -= wrapMarkerPaddingRight; @@ -424,7 +424,7 @@ void MarginView::PaintMargin(Surface *surface, Sci::Line topLine, PRectangle rc, rcText.left = rcText.right - width - 3; } DrawStyledText(surface, vs, vs.marginStyleOffset, rcText, - stMargin, 0, stMargin.length, drawAll); + stMargin, 0, stMargin.length, DrawPhase::all); } else { // if we're displaying annotation lines, colour the margin to match the associated document line const int annotationLines = model.pdoc->AnnotationLines(lineDoc); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 7801e4fbb..418a4fef9 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -161,7 +161,7 @@ int LineLayout::SubLineFromPosition(int posInLine, PointEnd pe) const noexcept { } for (int line = 0; line < lines; line++) { - if (pe & peSubLineEnd) { + if (FlagSet(pe, PointEnd::subLineEnd)) { // Return subline not start of next if (lineStarts[line + 1] <= posInLine + 1) return line; @@ -276,9 +276,9 @@ Point LineLayout::PointFromPosition(int posInLine, int lineHeight, PointEnd pe) pt.x = positions[posInLine] - positions[rangeSubLine.start]; if (rangeSubLine.start != 0) // Wrapped lines may be indented pt.x += wrapIndent; - if (pe & peSubLineEnd) // Return end of first subline not start of next + if (FlagSet(pe, PointEnd::subLineEnd)) // Return end of first subline not start of next break; - } else if ((pe & peLineEnd) && (subLine == (lines-1))) { + } else if (FlagSet(pe, PointEnd::lineEnd) && (subLine == (lines-1))) { pt.x = positions[numCharsInLine] - positions[rangeSubLine.start]; if (rangeSubLine.start != 0) // Wrapped lines may be indented pt.x += wrapIndent; diff --git a/src/PositionCache.h b/src/PositionCache.h index 8968092e7..0fb51dc38 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -38,10 +38,11 @@ public: // There are two points for some positions and this enumeration // can choose between the end of the first line or subline // and the start of the next line or subline. -enum PointEnd { - peDefault = 0x0, - peLineEnd = 0x1, - peSubLineEnd = 0x2 +enum class PointEnd { + start = 0x0, + lineEnd = 0x1, + subLineEnd = 0x2, + endEither = lineEnd | subLineEnd, }; class BidiData { diff --git a/src/Selection.cxx b/src/Selection.cxx index cc92ff49b..7f2361f08 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -192,7 +192,7 @@ void SelectionRange::MinimizeVirtualSpace() noexcept { } } -Selection::Selection() : mainRange(0), moveExtends(false), tentativeMain(false), selType(selStream) { +Selection::Selection() : mainRange(0), moveExtends(false), tentativeMain(false), selType(SelTypes::stream) { AddSelection(SelectionRange(SelectionPosition(0))); } @@ -200,7 +200,7 @@ Selection::~Selection() { } bool Selection::IsRectangular() const noexcept { - return (selType == selRectangle) || (selType == selThin); + return (selType == SelTypes::rectangle) || (selType == SelTypes::thin); } Sci::Position Selection::MainCaret() const noexcept { @@ -312,7 +312,7 @@ void Selection::MovePositions(bool insertion, Sci::Position startChange, Sci::Po for (SelectionRange &range : ranges) { range.MoveForInsertDelete(insertion, startChange, length); } - if (selType == selRectangle) { + if (selType == SelTypes::rectangle) { rangeRectangular.MoveForInsertDelete(insertion, startChange, length); } } @@ -423,7 +423,7 @@ void Selection::Clear() { ranges.clear(); ranges.emplace_back(); mainRange = ranges.size() - 1; - selType = selStream; + selType = SelTypes::stream; moveExtends = false; ranges[mainRange].Reset(); rangeRectangular.Reset(); diff --git a/src/Selection.h b/src/Selection.h index c5c7993cf..1ad4fa7c0 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -141,8 +141,8 @@ class Selection { bool moveExtends; bool tentativeMain; public: - enum selTypes { noSel, selStream, selRectangle, selLines, selThin }; - selTypes selType; + enum class SelTypes { none, stream, rectangle, lines, thin }; + SelTypes selType; Selection(); ~Selection(); diff --git a/src/Style.cxx b/src/Style.cxx index fc96cfcfd..83224c736 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -61,13 +61,13 @@ void FontMeasurements::ClearMeasurements() noexcept { Style::Style() : FontSpecification() { Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, nullptr, SC_CHARSET_DEFAULT, - SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); + SC_WEIGHT_NORMAL, false, false, false, CaseForce::mixed, true, true, false); } Style::Style(const Style &source) noexcept : FontSpecification(), FontMeasurements() { Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), 0, nullptr, 0, - SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); + SC_WEIGHT_NORMAL, false, false, false, CaseForce::mixed, true, true, false); fore = source.fore; back = source.back; characterSet = source.characterSet; @@ -91,7 +91,7 @@ Style &Style::operator=(const Style &source) noexcept { return * this; Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), 0, nullptr, SC_CHARSET_DEFAULT, - SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); + SC_WEIGHT_NORMAL, false, false, false, CaseForce::mixed, true, true, false); fore = source.fore; back = source.back; characterSet = source.characterSet; @@ -110,7 +110,7 @@ Style &Style::operator=(const Style &source) noexcept { void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_, const char *fontName_, int characterSet_, int weight_, bool italic_, bool eolFilled_, - bool underline_, ecaseForced caseForce_, + bool underline_, CaseForce caseForce_, bool visible_, bool changeable_, bool hotspot_) noexcept { fore = fore_; back = back_; diff --git a/src/Style.h b/src/Style.h index 769386359..d9bf96d88 100644 --- a/src/Style.h +++ b/src/Style.h @@ -48,8 +48,8 @@ public: ColourDesired back; bool eolFilled; bool underline; - enum ecaseForced {caseMixed, caseUpper, caseLower, caseCamel}; - ecaseForced caseForce; + enum class CaseForce {mixed, upper, lower, camel}; + CaseForce caseForce; bool visible; bool changeable; bool hotspot; @@ -66,7 +66,7 @@ public: int size_, const char *fontName_, int characterSet_, int weight_, bool italic_, bool eolFilled_, - bool underline_, ecaseForced caseForce_, + bool underline_, CaseForce caseForce_, bool visible_, bool changeable_, bool hotspot_) noexcept; void ClearTo(const Style &source) noexcept; void Copy(std::shared_ptr<Font> font_, const FontMeasurements &fm_) noexcept; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index e30e1fd18..d1f866906 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -337,7 +337,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) { [](const Style &style) noexcept { return style.IsProtected(); }); someStylesForceCase = std::any_of(styles.cbegin(), styles.cend(), - [](const Style &style) noexcept { return style.caseForce != Style::caseMixed; }); + [](const Style &style) noexcept { return style.caseForce != Style::CaseForce::mixed; }); aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth; spaceWidth = styles[STYLE_DEFAULT].spaceWidth; @@ -378,7 +378,7 @@ void ViewStyle::ResetDefaultStyle() { ColourDesired(0xff,0xff,0xff), Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, fontNames.Save(Platform::DefaultFont()), SC_CHARSET_DEFAULT, - SC_WEIGHT_NORMAL, false, false, false, Style::caseMixed, true, true, false); + SC_WEIGHT_NORMAL, false, false, false, Style::CaseForce::mixed, true, true, false); } void ViewStyle::ClearStyles() { |