diff options
-rw-r--r-- | cocoa/ScintillaCocoa.h | 6 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 66 | ||||
-rwxr-xr-x | gtk/ScintillaGTK.cxx | 62 | ||||
-rwxr-xr-x | gtk/ScintillaGTK.h | 8 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.cpp | 45 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.h | 4 | ||||
-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 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 69 |
22 files changed, 437 insertions, 408 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h index e75efffef..8ea0f410f 100644 --- a/cocoa/ScintillaCocoa.h +++ b/cocoa/ScintillaCocoa.h @@ -121,7 +121,7 @@ protected: void Init(); std::unique_ptr<CaseFolder> CaseFolderForEncoding() override; - std::string CaseMapString(const std::string &s, int caseMapping) override; + std::string CaseMapString(const std::string &s, CaseMapping caseMapping) override; void CancelModes() override; public: @@ -187,14 +187,14 @@ public: static sptr_t DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam); - NSTimer *timers[tickPlatform+1]; + NSTimer *timers[static_cast<size_t>(TickReason::platform)+1]; void TimerFired(NSTimer *timer); void IdleTimerFired(); static void UpdateObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *sci); void ObserverAdd(); void ObserverRemove(); void IdleWork() override; - void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override; + void QueueIdleWork(WorkItems items, Sci::Position upTo) override; ptrdiff_t InsertText(NSString *input, CharacterSource charSource); NSRange PositionsFromCharacters(NSRange rangeCharacters) const; NSRange CharactersFromPositions(NSRange rangePositions) const; diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index e1b11c16a..54b809cd9 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -407,10 +407,8 @@ ScintillaCocoa::ScintillaCocoa(ScintillaView *sciView_, SCIContentView *viewCont scrollTicks = 2000; observer = NULL; layerFindIndicator = NULL; - imeInteraction = imeInline; - for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) { - timers[tr] = nil; - } + imeInteraction = IMEInteraction::internal; + std::fill(timers, std::end(timers), nil); Init(); } @@ -446,8 +444,8 @@ void ScintillaCocoa::Init() { */ void ScintillaCocoa::Finalise() { ObserverRemove(); - for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) { - FineTickerCancel(tr); + for (size_t tr=static_cast<size_t>(TickReason::caret); tr<=static_cast<size_t>(TickReason::platform); tr++) { + FineTickerCancel(static_cast<TickReason>(tr)); } ScintillaBase::Finalise(); } @@ -504,7 +502,7 @@ void ScintillaCocoa::IdleWork() { //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) { +void ScintillaCocoa::QueueIdleWork(WorkItems items, Sci::Position upTo) { Editor::QueueIdleWork(items, upTo); ObserverAdd(); } @@ -626,14 +624,14 @@ std::unique_ptr<CaseFolder> ScintillaCocoa::CaseFolderForEncoding() { /** * Case-fold the given string depending on the specified case mapping type. */ -std::string ScintillaCocoa::CaseMapString(const std::string &s, int caseMapping) { - if ((s.size() == 0) || (caseMapping == cmSame)) +std::string ScintillaCocoa::CaseMapString(const std::string &s, CaseMapping caseMapping) { + if ((s.size() == 0) || (caseMapping == CaseMapping::same)) return s; if (IsUnicodeMode()) { std::string retMapped(s.length() * maxExpansionCaseConversion, 0); size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), - (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + (caseMapping == CaseMapping::upper) ? CaseConversionUpper : CaseConversionLower); retMapped.resize(lenMapped); return retMapped; } @@ -648,10 +646,10 @@ std::string ScintillaCocoa::CaseMapString(const std::string &s, int caseMapping) NSString *sMapped; switch (caseMapping) { - case cmUpper: + case CaseMapping::upper: sMapped = ((__bridge NSString *)cfsVal).uppercaseString; break; - case cmLower: + case CaseMapping::lower: sMapped = ((__bridge NSString *)cfsVal).lowercaseString; break; default: @@ -927,7 +925,7 @@ sptr_t ScintillaCocoa::DefWndProc(unsigned int, uptr_t, sptr_t) { * Handle any ScintillaCocoa-specific ticking or call superclass. */ void ScintillaCocoa::TickFor(TickReason reason) { - if (reason == tickPlatform) { + if (reason == TickReason::platform) { DragScroll(); } else { Editor::TickFor(reason); @@ -940,7 +938,7 @@ void ScintillaCocoa::TickFor(TickReason reason) { * Is a particular timer currently running? */ bool ScintillaCocoa::FineTickerRunning(TickReason reason) { - return timers[reason] != nil; + return timers[static_cast<size_t>(reason)] != nil; } //-------------------------------------------------------------------------------------------------- @@ -958,7 +956,7 @@ void ScintillaCocoa::FineTickerStart(TickReason reason, int millis, int toleranc if (tolerance && [fineTimer respondsToSelector: @selector(setTolerance:)]) { fineTimer.tolerance = tolerance / 1000.0; } - timers[reason] = fineTimer; + timers[static_cast<size_t>(reason)] = fineTimer; [NSRunLoop.currentRunLoop addTimer: fineTimer forMode: NSDefaultRunLoopMode]; [NSRunLoop.currentRunLoop addTimer: fineTimer forMode: NSModalPanelRunLoopMode]; } @@ -969,9 +967,10 @@ void ScintillaCocoa::FineTickerStart(TickReason reason, int millis, int toleranc * Cancel a fine-grained timer. */ void ScintillaCocoa::FineTickerCancel(TickReason reason) { - if (timers[reason]) { - [timers[reason] invalidate]; - timers[reason] = nil; + const size_t reasonIndex = static_cast<size_t>(reason); + if (timers[reasonIndex]) { + [timers[reasonIndex] invalidate]; + timers[reasonIndex] = nil; } } @@ -1046,7 +1045,7 @@ void ScintillaCocoa::Paste(bool forceRectangular) { pdoc->BeginUndoAction(); ClearSelection(false); InsertPasteShape(selectedText.Data(), selectedText.Length(), - selectedText.rectangular ? pasteRectangular : pasteStream); + selectedText.rectangular ? PasteShape::rectangular : PasteShape::stream); pdoc->EndUndoAction(); Redraw(); @@ -1325,9 +1324,9 @@ void ScintillaCocoa::StartDrag() { if (sel.Empty()) return; - inDragDrop = ddDragging; + inDragDrop = DragDrop::dragging; - FineTickerStart(tickPlatform, timer.tickSize, 0); + FineTickerStart(TickReason::platform, timer.tickSize, 0); // Put the data to be dragged on the drag pasteboard. SelectionText selectedText; @@ -1419,12 +1418,12 @@ void ScintillaCocoa::StartDrag() { const bool lastHideSelection = view.hideSelection; view.hideSelection = true; PRectangle imageRect = rcSel; - paintState = painting; + paintState = PaintState::painting; paintingAllText = true; CGContextRef gcsw = sw.GetContext(); CGContextTranslateCTM(gcsw, -client.left, -client.top); Paint(&sw, client); - paintState = notPainting; + paintState = PaintState::notPainting; view.hideSelection = lastHideSelection; SurfaceImpl pixmap; @@ -1488,7 +1487,7 @@ void ScintillaCocoa::StartDrag() { * Called when a drag operation reaches the control which was initiated outside. */ NSDragOperation ScintillaCocoa::DraggingEntered(id <NSDraggingInfo> info) { - FineTickerStart(tickPlatform, timer.tickSize, 0); + FineTickerStart(TickReason::platform, timer.tickSize, 0); return DraggingUpdated(info); } @@ -1529,8 +1528,8 @@ NSDragOperation ScintillaCocoa::DraggingUpdated(id <NSDraggingInfo> info) { void ScintillaCocoa::DraggingExited(id <NSDraggingInfo> info) { #pragma unused(info) SetDragPosition(SelectionPosition(Sci::invalidPosition)); - FineTickerCancel(tickPlatform); - inDragDrop = ddNone; + FineTickerCancel(TickReason::platform); + inDragDrop = DragDrop::none; } //-------------------------------------------------------------------------------------------------- @@ -1703,8 +1702,7 @@ NSRect ScintillaCocoa::FrameForRange(NSRange rangeCharacters) { (pdoc->GetColumn(rangeEnd) == 0); Point ptStart = LocationFromPosition(posRange.location); - const PointEnd peEndRange = static_cast<PointEnd>(peSubLineEnd|peLineEnd); - Point ptEnd = LocationFromPosition(rangeEnd, peEndRange); + Point ptEnd = LocationFromPosition(rangeEnd, PointEnd::endEither); NSRect rect = NSMakeRect(ptStart.x, ptStart.y, ptEnd.x - ptStart.x, @@ -1773,7 +1771,7 @@ bool ScintillaCocoa::HaveMouseCapture() { * Synchronously paint a rectangle of the window. */ bool ScintillaCocoa::SyncPaint(void *gc, PRectangle rc) { - paintState = painting; + paintState = PaintState::painting; rcPaint = rc; PRectangle rcText = GetTextRectangle(); paintingAllText = rcPaint.Contains(rcText); @@ -1787,9 +1785,9 @@ bool ScintillaCocoa::SyncPaint(void *gc, PRectangle rc) { vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); sw->Init(gc, wMain.GetID()); Paint(sw.get(), rc); - const bool succeeded = paintState != paintAbandoned; + const bool succeeded = paintState != PaintState::abandoned; sw->Release(); - paintState = notPainting; + paintState = PaintState::notPainting; if (!succeeded) { NSView *marginView = (__bridge NSView *)(wMargin.GetID()); [marginView setNeedsDisplay: YES]; @@ -2070,9 +2068,9 @@ bool ScintillaCocoa::CanRedo() { //-------------------------------------------------------------------------------------------------- void ScintillaCocoa::TimerFired(NSTimer *timer) { - for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) { + for (size_t tr=static_cast<size_t>(TickReason::caret); tr<=static_cast<size_t>(TickReason::platform); tr++) { if (timers[tr] == timer) { - TickFor(tr); + TickFor(static_cast<TickReason>(tr)); } } } @@ -2504,7 +2502,7 @@ void ScintillaCocoa::ActiveStateChanged(bool isActive) { if (!isActive) { DropCaret(); //SetFocusState( false ); - FineTickerCancel(tickCaret); + FineTickerCancel(TickReason::caret); } else { ShowCaretAtCurrentPosition(); } diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index e3148e9a8..e0ec61245 100755 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -652,8 +652,8 @@ void ScintillaGTK::Init() { caret.period = 0; } - for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { - timers[tr].reason = tr; + for (size_t tr = static_cast<size_t>(TickReason::caret); tr <= static_cast<size_t>(TickReason::dwell); tr++) { + timers[tr].reason = static_cast<TickReason>(tr); timers[tr].scintilla = this; } vs.indicators[SC_INDICATOR_UNKNOWN] = Indicator(INDIC_HIDDEN, ColourDesired(0, 0, 0xff)); @@ -663,8 +663,8 @@ void ScintillaGTK::Init() { } void ScintillaGTK::Finalise() { - for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { - FineTickerCancel(tr); + for (size_t tr = static_cast<size_t>(TickReason::caret); tr <= static_cast<size_t>(TickReason::dwell); tr++) { + FineTickerCancel(static_cast<TickReason>(tr)); } if (accessible) { gtk_accessible_set_widget(GTK_ACCESSIBLE(accessible), nullptr); @@ -676,7 +676,7 @@ void ScintillaGTK::Finalise() { } bool ScintillaGTK::AbandonPaint() { - if ((paintState == painting) && !paintingAllText) { + if ((paintState == PaintState::painting) && !paintingAllText) { repaintFullWindow = true; } return false; @@ -697,7 +697,7 @@ bool ScintillaGTK::DragThreshold(Point ptStart, Point ptNow) { void ScintillaGTK::StartDrag() { PLATFORM_ASSERT(evbtn); dragWasDropped = false; - inDragDrop = ddDragging; + inDragDrop = DragDrop::dragging; GtkTargetList *tl = gtk_target_list_new(clipboardCopyTargets, nClipboardCopyTargets); #if GTK_CHECK_VERSION(3,10,0) gtk_drag_begin_with_coordinates(GTK_WIDGET(PWidget(wMain)), @@ -902,18 +902,20 @@ sptr_t ScintillaGTK::DefWndProc(unsigned int, uptr_t, sptr_t) { } bool ScintillaGTK::FineTickerRunning(TickReason reason) { - return timers[reason].timer != 0; + return timers[static_cast<size_t>(reason)].timer != 0; } void ScintillaGTK::FineTickerStart(TickReason reason, int millis, int /* tolerance */) { FineTickerCancel(reason); - timers[reason].timer = gdk_threads_add_timeout(millis, TimeOut, &timers[reason]); + const size_t reasonIndex = static_cast<size_t>(reason); + timers[reasonIndex].timer = gdk_threads_add_timeout(millis, TimeOut, &timers[reasonIndex]); } void ScintillaGTK::FineTickerCancel(TickReason reason) { - if (timers[reason].timer) { - g_source_remove(timers[reason].timer); - timers[reason].timer = 0; + const size_t reasonIndex = static_cast<size_t>(reason); + if (timers[reasonIndex].timer) { + g_source_remove(timers[reasonIndex].timer); + timers[reasonIndex].timer = 0; } } @@ -975,7 +977,7 @@ bool ScintillaGTK::PaintContains(PRectangle rc) { // This allows optimization when a rectangle is completely in the update region. // It is OK to return false when too difficult to determine as that just performs extra drawing bool contains = true; - if (paintState == painting) { + if (paintState == PaintState::painting) { if (!rcPaint.Contains(rc)) { contains = false; } else if (rgnUpdate) { @@ -1081,7 +1083,7 @@ bool ScintillaGTK::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) { #endif modified = true; } - if (modified && (paintState == painting)) { + if (modified && (paintState == PaintState::painting)) { repaintFullWindow = true; } @@ -1228,14 +1230,14 @@ struct CaseMapper { } -std::string ScintillaGTK::CaseMapString(const std::string &s, int caseMapping) { - if ((s.size() == 0) || (caseMapping == cmSame)) +std::string ScintillaGTK::CaseMapString(const std::string &s, CaseMapping caseMapping) { + if ((s.size() == 0) || (caseMapping == CaseMapping::same)) return s; if (IsUnicodeMode()) { std::string retMapped(s.length() * maxExpansionCaseConversion, 0); const size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), - (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + (caseMapping == CaseMapping::upper) ? CaseConversionUpper : CaseConversionLower); retMapped.resize(lenMapped); return retMapped; } @@ -1243,13 +1245,13 @@ std::string ScintillaGTK::CaseMapString(const std::string &s, int caseMapping) { const char *charSetBuffer = CharacterSetID(); if (!*charSetBuffer) { - CaseMapper mapper(s, caseMapping == cmUpper); + CaseMapper mapper(s, caseMapping == CaseMapping::upper); return std::string(mapper.mapped, strlen(mapper.mapped)); } else { // Change text to UTF-8 std::string sUTF8 = ConvertText(s.c_str(), s.length(), "UTF-8", charSetBuffer, false); - CaseMapper mapper(sUTF8, caseMapping == cmUpper); + CaseMapper mapper(sUTF8, caseMapping == CaseMapping::upper); return ConvertText(mapper.mapped, strlen(mapper.mapped), charSetBuffer, "UTF-8", false); } } @@ -1468,7 +1470,7 @@ void ScintillaGTK::InsertSelection(GtkClipboard *clipBoard, GtkSelectionData *se } InsertPasteShape(selText.Data(), selText.Length(), - selText.rectangular ? pasteRectangular : pasteStream); + selText.rectangular ? PasteShape::rectangular : PasteShape::stream); EnsureCaretVisible(); } else { GdkAtom target = gtk_selection_data_get_target(selectionData); @@ -2504,7 +2506,7 @@ void ScintillaGTK::PreeditChangedWindowedThis() { } void ScintillaGTK::PreeditChanged(GtkIMContext *, ScintillaGTK *sciThis) { - if ((sciThis->imeInteraction == imeInline) || (sciThis->KoreanIME())) { + if ((sciThis->imeInteraction == IMEInteraction::internal) || (sciThis->KoreanIME())) { sciThis->PreeditChangedInlineThis(); } else { sciThis->PreeditChangedWindowedThis(); @@ -2574,7 +2576,7 @@ void ScintillaGTK::Destroy(GObject *object) { gboolean ScintillaGTK::DrawTextThis(cairo_t *cr) { try { - paintState = painting; + paintState = PaintState::painting; repaintFullWindow = false; rcPaint = GetClientRectangle(); @@ -2600,18 +2602,18 @@ gboolean ScintillaGTK::DrawTextThis(cairo_t *cr) { surfaceWindow->Init(cr, PWidget(wText)); Paint(surfaceWindow.get(), rcPaint); surfaceWindow->Release(); - if ((paintState == paintAbandoned) || repaintFullWindow) { + if ((paintState == PaintState::abandoned) || repaintFullWindow) { // Painting area was insufficient to cover new styling or brace highlight positions FullPaint(); } - paintState = notPainting; + paintState = PaintState::notPainting; repaintFullWindow = false; if (rgnUpdate) { cairo_rectangle_list_destroy(rgnUpdate); } rgnUpdate = 0; - paintState = notPainting; + paintState = PaintState::notPainting; } catch (...) { errorStatus = SC_STATUS_FAILURE; } @@ -2672,7 +2674,7 @@ gboolean ScintillaGTK::DrawMain(GtkWidget *widget, cairo_t *cr) { gboolean ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) { try { - paintState = painting; + paintState = PaintState::painting; rcPaint = PRectangle::FromInts( ose->area.x, @@ -2690,11 +2692,11 @@ gboolean ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *os Paint(surfaceWindow.get(), rcPaint); surfaceWindow->Release(); cairo_destroy(cr); - if ((paintState == paintAbandoned) || repaintFullWindow) { + if ((paintState == PaintState::abandoned) || repaintFullWindow) { // Painting area was insufficient to cover new styling or brace highlight positions FullPaint(); } - paintState = notPainting; + paintState = PaintState::notPainting; repaintFullWindow = false; if (rgnUpdate) { @@ -2795,7 +2797,7 @@ gboolean ScintillaGTK::DragMotionThis(GdkDragContext *context, GdkDragAction preferredAction = gdk_drag_context_get_suggested_action(context); const GdkDragAction actions = gdk_drag_context_get_actions(context); const SelectionPosition pos = SPositionFromLocation(npt); - if ((inDragDrop == ddDragging) && (PositionInSelection(pos.Position()))) { + if ((inDragDrop == DragDrop::dragging) && (PositionInSelection(pos.Position()))) { // Avoid dragging selection onto itself as that produces a move // with no real effect but which creates undo actions. preferredAction = static_cast<GdkDragAction>(0); @@ -2833,7 +2835,7 @@ void ScintillaGTK::DragEnd(GtkWidget *widget, GdkDragContext * /*context*/) { sciThis->SetEmptySelection(sciThis->posDrag); sciThis->SetDragPosition(SelectionPosition(Sci::invalidPosition)); //Platform::DebugPrintf("DragEnd %x %d\n", sciThis, sciThis->dragWasDropped); - sciThis->inDragDrop = ddNone; + sciThis->inDragDrop = DragDrop::none; } catch (...) { sciThis->errorStatus = SC_STATUS_FAILURE; } @@ -2921,7 +2923,7 @@ void ScintillaGTK::IdleWork() { styleIdleID = 0; } -void ScintillaGTK::QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) { +void ScintillaGTK::QueueIdleWork(WorkItems items, Sci::Position upTo) { Editor::QueueIdleWork(items, upTo); if (!styleIdleID) { // Only allow one style needed to be queued diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h index 100abd56b..c4437e229 100755 --- a/gtk/ScintillaGTK.h +++ b/gtk/ScintillaGTK.h @@ -102,9 +102,9 @@ private: TickReason reason; ScintillaGTK *scintilla; guint timer; - TimeThunk() noexcept : reason(tickCaret), scintilla(nullptr), timer(0) {} + TimeThunk() noexcept : reason(TickReason::caret), scintilla(nullptr), timer(0) {} }; - TimeThunk timers[tickDwell+1]; + TimeThunk timers[static_cast<size_t>(TickReason::dwell)+1]; bool FineTickerRunning(TickReason reason) override; void FineTickerStart(TickReason reason, int millis, int tolerance) override; void FineTickerCancel(TickReason reason) override; @@ -126,7 +126,7 @@ private: void NotifyURIDropped(const char *list); const char *CharacterSetID() const; std::unique_ptr<CaseFolder> CaseFolderForEncoding() override; - std::string CaseMapString(const std::string &s, int caseMapping) override; + std::string CaseMapString(const std::string &s, CaseMapping caseMapping) override; int KeyDefault(int key, int modifiers) override; void CopyToClipboard(const SelectionText &selectedText) override; void Copy() override; @@ -243,7 +243,7 @@ private: static gboolean IdleCallback(gpointer pSci); static gboolean StyleIdle(gpointer pSci); void IdleWork() override; - void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override; + void QueueIdleWork(WorkItems items, Sci::Position upTo) override; void SetDocPointer(Document *document) override; static void PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis); diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp index 761ff78bb..06314187e 100644 --- a/qt/ScintillaEditBase/ScintillaQt.cpp +++ b/qt/ScintillaEditBase/ScintillaQt.cpp @@ -32,7 +32,7 @@ ScintillaQt::ScintillaQt(QAbstractScrollArea *parent) wMain = scrollArea->viewport(); - imeInteraction = imeInline; + imeInteraction = IMEInteraction::internal; // On OS X drawing text into a pixmap moves it around 1 pixel to // the right compared to drawing it directly onto a window. @@ -41,9 +41,7 @@ ScintillaQt::ScintillaQt(QAbstractScrollArea *parent) Init(); - for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { - timers[tr] = 0; - } + std::fill(timers, std::end(timers), 0); } ScintillaQt::~ScintillaQt() @@ -389,7 +387,7 @@ void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode_) UndoGroup ug(pdoc); ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); InsertPasteShape(selText.Data(), selText.Length(), - isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream)); + isRectangular ? PasteShape::rectangular : (isLine ? PasteShape::line : PasteShape::stream)); EnsureCaretVisible(); } @@ -452,20 +450,20 @@ void ScintillaQt::NotifyURIDropped(const char *uri) bool ScintillaQt::FineTickerRunning(TickReason reason) { - return timers[reason] != 0; + return timers[static_cast<size_t>(reason)] != 0; } void ScintillaQt::FineTickerStart(TickReason reason, int millis, int /* tolerance */) { FineTickerCancel(reason); - timers[reason] = startTimer(millis); + timers[static_cast<size_t>(reason)] = startTimer(millis); } // CancelTimers cleans up all fine-ticker timers and is non-virtual to avoid warnings when // called during destruction. void ScintillaQt::CancelTimers() { - for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { + for (size_t tr = static_cast<size_t>(TickReason::caret); tr <= static_cast<size_t>(TickReason::dwell); tr++) { if (timers[tr]) { killTimer(timers[tr]); timers[tr] = 0; @@ -475,9 +473,10 @@ void ScintillaQt::CancelTimers() void ScintillaQt::FineTickerCancel(TickReason reason) { - if (timers[reason]) { - killTimer(timers[reason]); - timers[reason] = 0; + const size_t reasonIndex = static_cast<size_t>(reason); + if (timers[reasonIndex]) { + killTimer(timers[reasonIndex]); + timers[reasonIndex] = 0; } } @@ -612,15 +611,15 @@ std::unique_ptr<CaseFolder> ScintillaQt::CaseFolderForEncoding() } } -std::string ScintillaQt::CaseMapString(const std::string &s, int caseMapping) +std::string ScintillaQt::CaseMapString(const std::string &s, CaseMapping caseMapping) { - if ((s.size() == 0) || (caseMapping == cmSame)) + if ((s.size() == 0) || (caseMapping == CaseMapping::same)) return s; if (IsUnicodeMode()) { std::string retMapped(s.length() * maxExpansionCaseConversion, 0); size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), - (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + (caseMapping == CaseMapping::upper) ? CaseConversionUpper : CaseConversionLower); retMapped.resize(lenMapped); return retMapped; } @@ -628,7 +627,7 @@ std::string ScintillaQt::CaseMapString(const std::string &s, int caseMapping) QTextCodec *codec = QTextCodec::codecForName(CharacterSetIDOfDocument()); QString text = codec->toUnicode(s.c_str(), static_cast<int>(s.length())); - if (caseMapping == cmUpper) { + if (caseMapping == CaseMapping::upper) { text = text.toUpper(); } else { text = text.toLower(); @@ -653,7 +652,7 @@ bool ScintillaQt::HaveMouseCapture() void ScintillaQt::StartDrag() { - inDragDrop = ddDragging; + inDragDrop = DragDrop::dragging; dropWentOutside = true; if (drag.Length()) { QMimeData *mimeData = new QMimeData; @@ -672,7 +671,7 @@ void ScintillaQt::StartDrag() ClearSelection(); } } - inDragDrop = ddNone; + inDragDrop = DragDrop::none; SetDragPosition(SelectionPosition(Sci::invalidPosition)); } @@ -780,7 +779,7 @@ sptr_t ScintillaQt::DirectFunction( void ScintillaQt::PartialPaint(const PRectangle &rect) { rcPaint = rect; - paintState = painting; + paintState = PaintState::painting; PRectangle rcClient = GetClientRectangle(); paintingAllText = rcPaint.Contains(rcClient); @@ -788,11 +787,11 @@ void ScintillaQt::PartialPaint(const PRectangle &rect) Paint(surfacePaint, rcPaint); surfacePaint->Release(); - if (paintState == paintAbandoned) { + if (paintState == PaintState::abandoned) { // FIXME: Failure to paint the requested rectangle in each // paint event causes flicker on some platforms (Mac?) // Paint rect immediately. - paintState = painting; + paintState = PaintState::painting; paintingAllText = true; AutoSurface surface(this); @@ -803,7 +802,7 @@ void ScintillaQt::PartialPaint(const PRectangle &rect) scrollArea->viewport()->update(); } - paintState = notPainting; + paintState = PaintState::notPainting; } void ScintillaQt::DragEnter(const Point &point) @@ -845,9 +844,9 @@ void ScintillaQt::DropUrls(const QMimeData *data) void ScintillaQt::timerEvent(QTimerEvent *event) { - for (TickReason tr=tickCaret; tr<=tickDwell; tr = static_cast<TickReason>(tr+1)) { + for (size_t tr=static_cast<size_t>(TickReason::caret); tr<=static_cast<size_t>(TickReason::dwell); tr++) { if (timers[tr] == event->timerId()) { - TickFor(tr); + TickFor(static_cast<TickReason>(tr)); } } } diff --git a/qt/ScintillaEditBase/ScintillaQt.h b/qt/ScintillaEditBase/ScintillaQt.h index 64268aa75..72d78f589 100644 --- a/qt/ScintillaEditBase/ScintillaQt.h +++ b/qt/ScintillaEditBase/ScintillaQt.h @@ -123,7 +123,7 @@ private: void NotifyFocus(bool focus) override; void NotifyParent(SCNotification scn) override; void NotifyURIDropped(const char *uri); - int timers[tickDwell+1]; + int timers[static_cast<size_t>(TickReason::dwell)+1]; bool FineTickerRunning(TickReason reason) override; void FineTickerStart(TickReason reason, int millis, int tolerance) override; void CancelTimers(); @@ -138,7 +138,7 @@ private: QString StringFromDocument(const char *s) const; QByteArray BytesForDocument(const QString &text) const; std::unique_ptr<CaseFolder> CaseFolderForEncoding() override; - std::string CaseMapString(const std::string &s, int caseMapping) override; + std::string CaseMapString(const std::string &s, CaseMapping caseMapping) override; void CreateCallTipWindow(PRectangle rc) override; void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override; 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() { diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index bde9ef66b..2b6748fb0 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -409,9 +409,9 @@ class ScintillaWin : std::string EncodeWString(std::wstring_view wsv); sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override; void IdleWork() override; - void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override; + void QueueIdleWork(WorkItems items, Sci::Position upTo) override; bool SetIdle(bool on) override; - UINT_PTR timers[tickDwell+1] {}; + UINT_PTR timers[static_cast<int>(TickReason::dwell)+1] {}; bool FineTickerRunning(TickReason reason) override; void FineTickerStart(TickReason reason, int millis, int tolerance) override; void FineTickerCancel(TickReason reason) override; @@ -432,7 +432,7 @@ class ScintillaWin : void NotifyParent(SCNotification scn) override; void NotifyDoubleClick(Point pt, int modifiers) override; std::unique_ptr<CaseFolder> CaseFolderForEncoding() override; - std::string CaseMapString(const std::string &s, int caseMapping) override; + std::string CaseMapString(const std::string &s, CaseMapping caseMapping) override; void Copy() override; bool CanPaste() override; void Paste() override; @@ -590,7 +590,8 @@ void ScintillaWin::Init() { void ScintillaWin::Finalise() { ScintillaBase::Finalise(); - for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { + for (TickReason tr = TickReason::caret; tr <= TickReason::dwell; + tr = static_cast<TickReason>(static_cast<int>(tr) + 1)) { FineTickerCancel(tr); } SetIdle(false); @@ -713,7 +714,7 @@ bool ScintillaWin::DragThreshold(Point ptStart, Point ptNow) { } void ScintillaWin::StartDrag() { - inDragDrop = ddDragging; + inDragDrop = DragDrop::dragging; DWORD dwEffect = 0; dropWentOutside = true; IDataObject *pDataObject = reinterpret_cast<IDataObject *>(&dob); @@ -730,7 +731,7 @@ void ScintillaWin::StartDrag() { ClearSelection(); } } - inDragDrop = ddNone; + inDragDrop = DragDrop::none; SetDragPosition(SelectionPosition(Sci::invalidPosition)); } @@ -941,7 +942,7 @@ sptr_t ScintillaWin::WndPaint() { // Redirect assertions to debug output and save current state const bool assertsPopup = Platform::ShowAssertionPopUps(false); - paintState = painting; + paintState = PaintState::painting; PAINTSTRUCT ps = {}; // Removed since this interferes with reporting other assertions as it occurs repeatedly @@ -953,7 +954,7 @@ sptr_t ScintillaWin::WndPaint() { const PRectangle rcClient = GetClientRectangle(); paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient); if (!PaintDC(ps.hdc)) { - paintState = paintAbandoned; + paintState = PaintState::abandoned; } if (hRgnUpdate) { ::DeleteRgn(hRgnUpdate); @@ -961,12 +962,12 @@ sptr_t ScintillaWin::WndPaint() { } ::EndPaint(MainHWND(), &ps); - if (paintState == paintAbandoned) { + if (paintState == PaintState::abandoned) { // Painting area was insufficient to cover new styling or brace highlight positions FullPaint(); ::ValidateRect(MainHWND(), nullptr); } - paintState = notPainting; + paintState = PaintState::notPainting; // Restore debug output state Platform::ShowAssertionPopUps(assertsPopup); @@ -1370,7 +1371,7 @@ sptr_t ScintillaWin::GetText(uptr_t wParam, sptr_t lParam) { } Window::Cursor ScintillaWin::ContextCursor(Point pt) { - if (inDragDrop == ddDragging) { + if (inDragDrop == DragDrop::dragging) { return Window::Cursor::up; } else { // Display regular (drag) cursor over selection @@ -1411,7 +1412,7 @@ sptr_t ScintillaWin::ShowContextMenu(unsigned int iMessage, uptr_t wParam, sptr_ void ScintillaWin::SizeWindow() { #if defined(USE_D2D) - if (paintState == notPainting) { + if (paintState == PaintState::notPainting) { DropRenderTarget(); } else { renderTargetValid = false; @@ -1651,7 +1652,7 @@ sptr_t ScintillaWin::IMEMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPa } case WM_IME_STARTCOMPOSITION: - if (KoreanIME() || imeInteraction == imeInline) { + if (KoreanIME() || imeInteraction == IMEInteraction::internal) { return 0; } else { ImeStartComposition(); @@ -1663,14 +1664,14 @@ sptr_t ScintillaWin::IMEMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPa return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam); case WM_IME_COMPOSITION: - if (KoreanIME() || imeInteraction == imeInline) { + if (KoreanIME() || imeInteraction == IMEInteraction::internal) { return HandleCompositionInline(wParam, lParam); } else { return HandleCompositionWindowed(wParam, lParam); } case WM_IME_SETCONTEXT: - if (KoreanIME() || imeInteraction == imeInline) { + if (KoreanIME() || imeInteraction == IMEInteraction::internal) { if (wParam) { LPARAM NoImeWin = lParam; NoImeWin = NoImeWin & (~ISC_SHOWUICOMPOSITIONWINDOW); @@ -1736,7 +1737,7 @@ sptr_t ScintillaWin::EditMessage(unsigned int iMessage, uptr_t wParam, sptr_t lP return 0; } const CHARRANGE *pCR = reinterpret_cast<const CHARRANGE *>(lParam); - sel.selType = Selection::selStream; + sel.selType = Selection::SelTypes::stream; if (pCR->cpMin == 0 && pCR->cpMax == -1) { SetSelection(pCR->cpMin, pdoc->Length()); } else { @@ -2081,23 +2082,25 @@ sptr_t ScintillaWin::DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPa } bool ScintillaWin::FineTickerRunning(TickReason reason) { - return timers[reason] != 0; + return timers[static_cast<size_t>(reason)] != 0; } void ScintillaWin::FineTickerStart(TickReason reason, int millis, int tolerance) { FineTickerCancel(reason); - const UINT_PTR eventID = static_cast<UINT_PTR>(fineTimerStart) + reason; + const UINT_PTR reasonIndex = static_cast<UINT_PTR>(reason); + const UINT_PTR eventID = static_cast<UINT_PTR>(fineTimerStart) + reasonIndex; if (SetCoalescableTimerFn && tolerance) { - timers[reason] = SetCoalescableTimerFn(MainHWND(), eventID, millis, nullptr, tolerance); + timers[reasonIndex] = SetCoalescableTimerFn(MainHWND(), eventID, millis, nullptr, tolerance); } else { - timers[reason] = ::SetTimer(MainHWND(), eventID, millis, nullptr); + timers[reasonIndex] = ::SetTimer(MainHWND(), eventID, millis, nullptr); } } void ScintillaWin::FineTickerCancel(TickReason reason) { - if (timers[reason]) { - ::KillTimer(MainHWND(), timers[reason]); - timers[reason] = 0; + const UINT_PTR reasonIndex = static_cast<UINT_PTR>(reason); + if (timers[reasonIndex]) { + ::KillTimer(MainHWND(), timers[reasonIndex]); + timers[reasonIndex] = 0; } } @@ -2124,7 +2127,7 @@ void ScintillaWin::IdleWork() { Editor::IdleWork(); } -void ScintillaWin::QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) { +void ScintillaWin::QueueIdleWork(WorkItems items, Sci::Position upTo) { Editor::QueueIdleWork(items, upTo); if (!styleIdleInQueue) { if (PostMessage(MainHWND(), SC_WORK_IDLE, 0, 0)) { @@ -2163,7 +2166,7 @@ void ScintillaWin::SetTrackMouseLeaveEvent(bool on) noexcept { } bool ScintillaWin::PaintContains(PRectangle rc) { - if (paintState == painting) { + if (paintState == PaintState::painting) { return BoundsContains(rcPaint, hRgnUpdate, rc); } return true; @@ -2419,20 +2422,20 @@ std::unique_ptr<CaseFolder> ScintillaWin::CaseFolderForEncoding() { } } -std::string ScintillaWin::CaseMapString(const std::string &s, int caseMapping) { - if ((s.size() == 0) || (caseMapping == cmSame)) +std::string ScintillaWin::CaseMapString(const std::string &s, CaseMapping caseMapping) { + if ((s.size() == 0) || (caseMapping == CaseMapping::same)) return s; const UINT cpDoc = CodePageOfDocument(); if (cpDoc == SC_CP_UTF8) { - return CaseConvertString(s, (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + return CaseConvertString(s, (caseMapping == CaseMapping::upper) ? CaseConversionUpper : CaseConversionLower); } // Change text to UTF-16 const std::wstring wsText = StringDecode(s, cpDoc); const DWORD mapFlags = LCMAP_LINGUISTIC_CASING | - ((caseMapping == cmUpper) ? LCMAP_UPPERCASE : LCMAP_LOWERCASE); + ((caseMapping == CaseMapping::upper) ? LCMAP_UPPERCASE : LCMAP_LOWERCASE); // Change case const std::wstring wsConverted = StringMapCase(wsText, mapFlags); @@ -2553,7 +2556,7 @@ void ScintillaWin::Paste() { memBorlandSelection.Unlock(); } } - const PasteShape pasteShape = isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream); + const PasteShape pasteShape = isRectangular ? PasteShape::rectangular : (isLine ? PasteShape::line : PasteShape::stream); // Use CF_UNICODETEXT if available GlobalMemory memUSelection(::GetClipboardData(CF_UNICODETEXT)); @@ -3157,11 +3160,11 @@ void ScintillaWin::FullPaint() { * This paint will not be abandoned. */ void ScintillaWin::FullPaintDC(HDC hdc) { - paintState = painting; + paintState = PaintState::painting; rcPaint = GetClientRectangle(); paintingAllText = true; PaintDC(hdc); - paintState = notPainting; + paintState = PaintState::notPainting; } namespace { @@ -3187,7 +3190,7 @@ bool ScintillaWin::IsCompatibleDC(HDC hOtherDC) noexcept { DWORD ScintillaWin::EffectFromState(DWORD grfKeyState) const noexcept { // These are the Wordpad semantics. DWORD dwEffect; - if (inDragDrop == ddDragging) // Internal defaults to move + if (inDragDrop == DragDrop::dragging) // Internal defaults to move dwEffect = DROPEFFECT_MOVE; else dwEffect = DROPEFFECT_COPY; |