diff --git a/language/np3_es_es/dialogs_es_es.rc b/language/np3_es_es/dialogs_es_es.rc index 2e80bef97..26e1de724 100644 Binary files a/language/np3_es_es/dialogs_es_es.rc and b/language/np3_es_es/dialogs_es_es.rc differ diff --git a/language/np3_es_es/lexer_es_es.rc b/language/np3_es_es/lexer_es_es.rc index 52e859db4..9e3c95da7 100644 Binary files a/language/np3_es_es/lexer_es_es.rc and b/language/np3_es_es/lexer_es_es.rc differ diff --git a/language/np3_es_es/strings_es_es.rc b/language/np3_es_es/strings_es_es.rc index 8dc4b5c48..8ea502708 100644 Binary files a/language/np3_es_es/strings_es_es.rc and b/language/np3_es_es/strings_es_es.rc differ diff --git a/language/np3_fr_fr/dialogs_fr_fr.rc b/language/np3_fr_fr/dialogs_fr_fr.rc index 8cf257820..d8935d22a 100644 Binary files a/language/np3_fr_fr/dialogs_fr_fr.rc and b/language/np3_fr_fr/dialogs_fr_fr.rc differ diff --git a/language/np3_nl_nl/dialogs_nl_nl.rc b/language/np3_nl_nl/dialogs_nl_nl.rc index 3f367f6a6..1a51ced7b 100644 Binary files a/language/np3_nl_nl/dialogs_nl_nl.rc and b/language/np3_nl_nl/dialogs_nl_nl.rc differ diff --git a/scintilla/cppcheck.suppress b/scintilla/cppcheck.suppress index b54604e34..b87b5d1d1 100644 --- a/scintilla/cppcheck.suppress +++ b/scintilla/cppcheck.suppress @@ -5,9 +5,17 @@ // members to initialize or the initialization is complex or has comments. useInitializationList +// These may be interesting but its not clear without examining each instance closely +// Would have to ensure that any_of/all_of has same early/late exits as current code and +// produces same result on empty collections +useStlAlgorithm + // Some non-explicit constructors are used for conversions or are private to lexers noExplicitConstructor +// Document is checking for a change by called methods and cppcheck isn't considering escape +knownConditionTrueFalse:scintilla/src/Document.cxx + // ScintillaDocument is providing an API and there are no consumers of the API inside Scintilla unusedFunction:scintilla/qt/ScintillaEdit/ScintillaDocument.cpp @@ -32,6 +40,7 @@ variableScope:scintilla/lexers/LexLaTeX.cxx copyCtorAndEqOperator:scintilla/lexers/LexLaTeX.cxx variableScope:scintilla/lexers/LexMetapost.cxx variableScope:scintilla/lexers/LexModula.cxx +variableScope:scintilla/lexers/LexMSSQL.cxx variableScope:scintilla/lexers/LexNimrod.cxx variableScope:scintilla/lexers/LexNsis.cxx variableScope:scintilla/lexers/LexOpal.cxx @@ -42,6 +51,7 @@ uninitMemberVar:scintilla/lexers/LexRuby.cxx variableScope:scintilla/lexers/LexSpecman.cxx clarifyCalculation:scintilla/lexers/LexTADS3.cxx invalidscanf:scintilla/lexers/LexTCMD.cxx +knownConditionTrueFalse:scintilla/lexers/LexTCMD.cxx variableScope:scintilla/lexers/LexTeX.cxx variableScope:scintilla/lexers/LexVHDL.cxx diff --git a/scintilla/doc/ScintillaHistory.html b/scintilla/doc/ScintillaHistory.html index 7e2fc7e2e..758f1d839 100644 --- a/scintilla/doc/ScintillaHistory.html +++ b/scintilla/doc/ScintillaHistory.html @@ -571,6 +571,10 @@ Released 2 October 2018.
  • + Improve efficiency of idle wrapping by wrapping in blocks as large as possible while + still remaining responsive. +
  • +
  • C++ lexer fixes evaluation of "#elif". Bug #2045.
  • @@ -578,6 +582,10 @@ Markdown lexer fixes highlighting of non-ASCII characters in links.
  • + SCI_MARKERADD returns -1 for invalid lines as documented instead of 0. + Bug #2051. +
  • +
  • SciTE on Win32 drops menukey feature, makes Del key work again in find and replace strips and disables F5 while command running. Bug #2044. diff --git a/scintilla/src/CaseConvert.cxx b/scintilla/src/CaseConvert.cxx index 6228f89d3..da3be5ecd 100644 --- a/scintilla/src/CaseConvert.cxx +++ b/scintilla/src/CaseConvert.cxx @@ -602,11 +602,11 @@ public: const char *Find(int character) { const std::vector::iterator it = std::lower_bound(characters.begin(), characters.end(), character); if (it == characters.end()) - return 0; + return nullptr; else if (*it == character) return conversions[it - characters.begin()].conversion; else - return 0; + return nullptr; } size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixed, size_t lenMixed) override { size_t lenConverted = 0; @@ -614,7 +614,7 @@ public: unsigned char bytes[UTF8MaxBytes + 1]{}; while (mixedPos < lenMixed) { const unsigned char leadByte = mixed[mixedPos]; - const char *caseConverted = 0; + const char *caseConverted = nullptr; size_t lenMixedChar = 1; if (UTF8IsAscii(leadByte)) { caseConverted = Find(leadByte); @@ -779,7 +779,7 @@ CaseConverter *ConverterForConversion(enum CaseConversion conversion) { case CaseConversionLower: return &caseConvLow; } - return 0; + return nullptr; } } diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx index 9dcedac4d..7fefc8d1b 100644 --- a/scintilla/src/Catalogue.cxx +++ b/scintilla/src/Catalogue.cxx @@ -33,7 +33,7 @@ const LexerModule *Catalogue::Find(int language) { return lm; } } - return 0; + return nullptr; } const LexerModule *Catalogue::Find(const char *languageName) { @@ -45,7 +45,7 @@ const LexerModule *Catalogue::Find(const char *languageName) { } } } - return 0; + return nullptr; } void Catalogue::AddLexerModule(LexerModule *plm) { diff --git a/scintilla/src/CellBuffer.cxx b/scintilla/src/CellBuffer.cxx index 639558a65..1abff92dc 100644 --- a/scintilla/src/CellBuffer.cxx +++ b/scintilla/src/CellBuffer.cxx @@ -138,7 +138,7 @@ class LineVector : public ILineVector { LineStartIndex startsUTF16; LineStartIndex startsUTF32; public: - LineVector() : starts(256), perLine(0) { + LineVector() : starts(256), perLine(nullptr) { Init(); } // Deleted so LineVector objects can not be copied. @@ -650,7 +650,7 @@ bool CellBuffer::SetStyleFor(Sci::Position position, Sci::Position lengthStyle, const char *CellBuffer::DeleteChars(Sci::Position position, Sci::Position deleteLength, bool &startSequence) { // InsertString and DeleteChars are the bottleneck though which all changes occur PLATFORM_ASSERT(deleteLength > 0); - const char *data = 0; + const char *data = nullptr; if (!readOnly) { if (collectingUndo) { // Save into the undo/redo stack, but only the characters - not the formatting @@ -1148,7 +1148,7 @@ void CellBuffer::EndUndoAction() { void CellBuffer::AddUndoAction(Sci::Position token, bool mayCoalesce) { bool startSequence; - uh.AppendAction(containerAction, token, 0, 0, startSequence, mayCoalesce); + uh.AppendAction(containerAction, token, nullptr, 0, startSequence, mayCoalesce); } void CellBuffer::DeleteUndoHistory() { diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index 44f301e90..b5f1091c8 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -84,8 +84,31 @@ int LexInterface::LineEndTypesSupported() { return 0; } +ActionDuration::ActionDuration(double duration_, double minDuration_, double maxDuration_) noexcept : + duration(duration_), minDuration(minDuration_), maxDuration(maxDuration_) { +} + +void ActionDuration::AddSample(size_t numberActions, double durationOfActions) noexcept { + // Only adjust for multiple actions to avoid instability + if (numberActions < 8) + return; + + // Alpha value for exponential smoothing. + // Most recent value contributes 25% to smoothed value. + const double alpha = 0.25; + + const double durationOne = durationOfActions / numberActions; + duration = std::clamp(alpha * durationOne + (1.0 - alpha) * duration, + minDuration, maxDuration); +} + +double ActionDuration::Duration() const noexcept { + return duration; +} + Document::Document(int options) : - cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0, (options & SC_DOCUMENTOPTION_TEXT_LARGE) != 0) { + cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0, (options & SC_DOCUMENTOPTION_TEXT_LARGE) != 0), + durationStyleOneLine(0.00001, 0.000001, 0.0001) { refCount = 0; #ifdef _WIN32 eolMode = SC_EOL_CRLF; @@ -106,7 +129,6 @@ Document::Document(int options) : useTabs = true; tabIndents = true; backspaceUnindents = false; - durationStyleOneLine = 0.00001; matchesValid = false; @@ -300,7 +322,7 @@ int Document::AddMark(Sci::Line line, int markerNum) { NotifyModified(mh); return prev; } else { - return 0; + return -1; } } @@ -2211,30 +2233,11 @@ void Document::EnsureStyledTo(Sci::Position pos) { } void Document::StyleToAdjustingLineDuration(Sci::Position pos) { - // Place bounds on the duration used to avoid glitches spiking it - // and so causing slow styling or non-responsive scrolling - const double minDurationOneLine = 0.000001; - const double maxDurationOneLine = 0.0001; - - // Alpha value for exponential smoothing. - // Most recent value contributes 25% to smoothed value. - const double alpha = 0.25; - const Sci::Line lineFirst = SciLineFromPosition(GetEndStyled()); ElapsedPeriod epStyling; EnsureStyledTo(pos); - const double durationStyling = epStyling.Duration(); const Sci::Line lineLast = SciLineFromPosition(GetEndStyled()); - if (lineLast >= lineFirst + 8) { - // Only adjust for styling multiple lines to avoid instability - const double durationOneLine = durationStyling / (lineLast - lineFirst); - durationStyleOneLine = alpha * durationOneLine + (1.0 - alpha) * durationStyleOneLine; - if (durationStyleOneLine < minDurationOneLine) { - durationStyleOneLine = minDurationOneLine; - } else if (durationStyleOneLine > maxDurationOneLine) { - durationStyleOneLine = maxDurationOneLine; - } - } + durationStyleOneLine.AddSample(lineLast - lineFirst, epStyling.Duration()); } void Document::LexerChanged() { diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index 8bac3c3aa..9e6fcfc27 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -191,6 +191,26 @@ struct RegexError : public std::runtime_error { RegexError() : std::runtime_error("regex failure") {} }; +/** + * The ActionDuration class stores the average time taken for some action such as styling or + * wrapping a line. It is used to decide how many repetitions of that action can be performed + * on idle to maximize efficiency without affecting application responsiveness. + * The duration changes if the time for the action changes. For example, if a simple lexer is + * changed to a complex lexer. Changes are damped and clamped to avoid short periods of easy + * or difficult processing moving the value too far leading to inefficiency or poor user + * experience. + */ + +class ActionDuration { + double duration; + const double minDuration; + const double maxDuration; +public: + ActionDuration(double duration_, double minDuration_, double maxDuration_) noexcept; + void AddSample(size_t numberActions, double durationOfActions) noexcept; + double Duration() const noexcept; +}; + /** */ class Document : PerLine, public IDocument, public ILoader { @@ -261,7 +281,7 @@ public: bool useTabs; bool tabIndents; bool backspaceUnindents; - double durationStyleOneLine; + ActionDuration durationStyleOneLine; std::unique_ptr decorations; diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 309c9acd2..12bc5c11a 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include "Platform.h" @@ -54,6 +55,7 @@ #include "MarginView.h" #include "EditView.h" #include "Editor.h" +#include "ElapsedPeriod.h" using namespace Scintilla; @@ -89,7 +91,7 @@ static bool IsLastStep(const DocModification &mh) { } Timer::Timer() : - ticking(false), ticksToWait(0), tickerID(0) {} + ticking(false), ticksToWait(0), tickerID{} {} Idler::Idler() : state(false), idlerID(0) {} @@ -103,7 +105,7 @@ static inline bool IsAllSpacesOrTabs(const char *s, unsigned int len) { return true; } -Editor::Editor() { +Editor::Editor() : durationWrapOneLine(0.00001, 0.000001, 0.0001) { ctrlID = 0; stylesValid = false; @@ -1536,7 +1538,12 @@ bool Editor::WrapLines(WrapScope ws) { return false; } } else if (ws == WrapScope::wsIdle) { - lineToWrapEnd = lineToWrap + LinesOnScreen() + 100; + // Try to keep time taken by wrapping reasonable so interaction remains smooth. + const double secondsAllowed = 0.01; + const Sci::Line linesInAllowedTime = std::clamp( + static_cast(secondsAllowed / durationWrapOneLine.Duration()), + LinesOnScreen() + 50, 0x10000); + lineToWrapEnd = lineToWrap + linesInAllowedTime; } const Sci::Line lineEndNeedWrap = std::min(wrapPending.end, pdoc->LinesTotal()); lineToWrapEnd = std::min(lineToWrapEnd, lineEndNeedWrap); @@ -1555,6 +1562,8 @@ bool Editor::WrapLines(WrapScope ws) { if (surface) { //Platform::DebugPrintf("Wraplines: scope=%0d need=%0d..%0d perform=%0d..%0d\n", ws, wrapPending.start, wrapPending.end, lineToWrap, lineToWrapEnd); + const Sci::Line linesBeingWrapped = lineToWrapEnd - lineToWrap; + ElapsedPeriod epWrapping; while (lineToWrap < lineToWrapEnd) { if (WrapOneLine(surface, lineToWrap)) { wrapOccurred = true; @@ -1562,6 +1571,7 @@ bool Editor::WrapLines(WrapScope ws) { wrapPending.Wrapped(lineToWrap); lineToWrap++; } + durationWrapOneLine.AddSample(linesBeingWrapped, epWrapping.Duration()); goodTopLine = pcs->DisplayFromDoc(lineDocTop) + std::min( subLineTop, static_cast(pcs->GetHeight(lineDocTop)-1)); @@ -5057,7 +5067,8 @@ Sci::Position Editor::PositionAfterMaxStyling(Sci::Position posMax, bool scrolli // When scrolling, allow less time to ensure responsive const double secondsAllowed = scrolling ? 0.005 : 0.02; - const Sci::Line linesToStyle = std::clamp(static_cast(secondsAllowed / pdoc->durationStyleOneLine), + const Sci::Line linesToStyle = std::clamp( + static_cast(secondsAllowed / pdoc->durationStyleOneLine.Duration()), 10, 0x10000); const Sci::Line stylingMaxLine = std::min( pdoc->SciLineFromPosition(pdoc->GetEndStyled()) + linesToStyle, diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index 5a4de2588..5aeb2d5b3 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/src/Editor.h @@ -250,6 +250,7 @@ protected: // ScintillaBase subclass needs access to much of Editor // Wrapping support WrapPending wrapPending; + ActionDuration durationWrapOneLine; bool convertPastes; diff --git a/scintilla/src/ExternalLexer.cxx b/scintilla/src/ExternalLexer.cxx index dd9a7179e..0326f19de 100644 --- a/scintilla/src/ExternalLexer.cxx +++ b/scintilla/src/ExternalLexer.cxx @@ -65,7 +65,7 @@ LexerLibrary::LexerLibrary(const char *moduleName_) { // Assign a buffer for the lexer name. char lexname[100] = ""; GetLexerName(i, lexname, sizeof(lexname)); - ExternalLexerModule *lex = new ExternalLexerModule(SCLEX_AUTOMATIC, NULL, lexname, NULL); + ExternalLexerModule *lex = new ExternalLexerModule(SCLEX_AUTOMATIC, nullptr, lexname, nullptr); // This is storing a second reference to lex in the Catalogue as well as in modules. // TODO: Should use std::shared_ptr or similar to ensure allocation safety. Catalogue::AddLexerModule(lex); diff --git a/scintilla/src/Indicator.cxx b/scintilla/src/Indicator.cxx index bc3c83a17..5ab0a7813 100644 --- a/scintilla/src/Indicator.cxx +++ b/scintilla/src/Indicator.cxx @@ -60,7 +60,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r const PRectangle rcSquiggle = PixelGridAlign(rc); const int width = std::min(4000, static_cast(rcSquiggle.Width())); - RGBAImage image(width, 3, 1.0, 0); + RGBAImage image(width, 3, 1.0, nullptr); enum { alphaFull = 0xff, alphaSide = 0x2f, alphaSide2=0x5f }; for (int x = 0; x < width; x++) { if (x%2) { @@ -165,7 +165,7 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r IntegerRectangle ircBox(rcBox); // Cap width at 4000 to avoid large allocations when mistakes made const int width = std::min(ircBox.Width(), 4000); - RGBAImage image(width, ircBox.Height(), 1.0, 0); + RGBAImage image(width, ircBox.Height(), 1.0, nullptr); // Draw horizontal lines top and bottom for (int x=0; x= 0) && (line < annotations.Length()) && annotations[line]) return annotations[line].get()+sizeof(AnnotationHeader); else - return 0; + return nullptr; } const unsigned char *LineAnnotation::Styles(Sci::Line line) const { if (annotations.Length() && (line >= 0) && (line < annotations.Length()) && annotations[line] && MultipleStyles(line)) return reinterpret_cast(annotations[line].get() + sizeof(AnnotationHeader) + Length(line)); else - return 0; + return nullptr; } static std::unique_ptrAllocateAnnotation(int length, int style) { diff --git a/scintilla/src/RESearch.cxx b/scintilla/src/RESearch.cxx index d29549ac2..5ce073a44 100644 --- a/scintilla/src/RESearch.cxx +++ b/scintilla/src/RESearch.cxx @@ -445,7 +445,7 @@ const char *RESearch::Compile(const char *pattern, Sci::Position length, bool ca if (!pattern || !length) { if (sta) - return 0; + return nullptr; else return badpat("No previous regular expression"); } @@ -727,7 +727,7 @@ const char *RESearch::Compile(const char *pattern, Sci::Position length, bool ca return badpat((posix ? "Unmatched (" : "Unmatched \\(")); *mp = END; sta = OKP; - return 0; + return nullptr; } /* diff --git a/scintilla/src/ScintillaBase.cxx b/scintilla/src/ScintillaBase.cxx index dfd108f5f..acc9ebe88 100644 --- a/scintilla/src/ScintillaBase.cxx +++ b/scintilla/src/ScintillaBase.cxx @@ -443,12 +443,12 @@ int ScintillaBase::AutoCompleteGetCurrentText(char *buffer) const { const int item = ac.GetSelection(); if (item != -1) { const std::string selected = ac.GetValue(item); - if (buffer != NULL) + if (buffer) memcpy(buffer, selected.c_str(), selected.length()+1); return static_cast(selected.length()); } } - if (buffer != NULL) + if (buffer) *buffer = '\0'; return 0; } @@ -571,7 +571,7 @@ public: } LexState::LexState(Document *pdoc_) : LexInterface(pdoc_) { - lexCurrent = 0; + lexCurrent = nullptr; performingStyle = false; interfaceVersion = lvRelease4; lexLanguage = SCLEX_CONTAINER; @@ -580,7 +580,7 @@ LexState::LexState(Document *pdoc_) : LexInterface(pdoc_) { LexState::~LexState() { if (instance) { instance->Release(); - instance = 0; + instance = nullptr; } } @@ -595,7 +595,7 @@ void LexState::SetLexerModule(const LexerModule *lex) { if (lex != lexCurrent) { if (instance) { instance->Release(); - instance = 0; + instance = nullptr; } interfaceVersion = lvRelease4; lexCurrent = lex; @@ -610,7 +610,7 @@ void LexState::SetLexerModule(const LexerModule *lex) { void LexState::SetLexer(uptr_t wParam) { lexLanguage = static_cast(wParam); if (lexLanguage == SCLEX_CONTAINER) { - SetLexerModule(0); + SetLexerModule(nullptr); } else { const LexerModule *lex = Catalogue::Find(lexLanguage); if (!lex) @@ -632,7 +632,7 @@ const char *LexState::DescribeWordListSets() { if (instance) { return instance->DescribeWordListSets(); } else { - return 0; + return nullptr; } } @@ -653,7 +653,7 @@ void *LexState::PrivateCall(int operation, void *pointer) { if (pdoc && instance) { return instance->PrivateCall(operation, pointer); } else { - return 0; + return nullptr; } } @@ -661,7 +661,7 @@ const char *LexState::PropertyNames() { if (instance) { return instance->PropertyNames(); } else { - return 0; + return nullptr; } } @@ -677,7 +677,7 @@ const char *LexState::DescribeProperty(const char *name) { if (instance) { return instance->DescribeProperty(name); } else { - return 0; + return nullptr; } } @@ -784,7 +784,7 @@ const char *LexState::NameOfStyle(int style) { if (instance) { return instance->NameOfStyle(style); } else { - return 0; + return nullptr; } } @@ -792,7 +792,7 @@ const char *LexState::TagsOfStyle(int style) { if (instance) { return instance->TagsOfStyle(style); } else { - return 0; + return nullptr; } } @@ -800,7 +800,7 @@ const char *LexState::DescriptionOfStyle(int style) { if (instance) { return instance->DescriptionOfStyle(style); } else { - return 0; + return nullptr; } } diff --git a/scintilla/src/Style.cxx b/scintilla/src/Style.cxx index 03f37449a..5fff777a6 100644 --- a/scintilla/src/Style.cxx +++ b/scintilla/src/Style.cxx @@ -77,13 +77,13 @@ void FontMeasurements::ClearMeasurements() { Style::Style() : FontSpecification() { Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), - Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, 0, SC_CHARSET_DEFAULT, + Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, nullptr, SC_CHARSET_DEFAULT, SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); } Style::Style(const Style &source) : FontSpecification(), FontMeasurements() { Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), - 0, 0, 0, + 0, nullptr, 0, SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); fore = source.fore; back = source.back; @@ -107,7 +107,7 @@ Style &Style::operator=(const Style &source) { if (this == &source) return * this; Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), - 0, 0, SC_CHARSET_DEFAULT, + 0, nullptr, SC_CHARSET_DEFAULT, SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); fore = source.fore; back = source.back; diff --git a/scintilla/src/ViewStyle.cxx b/scintilla/src/ViewStyle.cxx index 88a5bd3ac..d4bc636a6 100644 --- a/scintilla/src/ViewStyle.cxx +++ b/scintilla/src/ViewStyle.cxx @@ -643,7 +643,7 @@ FontRealised *ViewStyle::Find(const FontSpecification &fs) { // Should always reach here since map was just set for all styles return it->second.get(); } - return 0; + return nullptr; } void ViewStyle::FindMaxAscentDescent() { diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 6850a59d1..d7a74d838 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -75,8 +75,8 @@ ID2D1Factory *pD2DFactory = nullptr; IDWriteRenderingParams *defaultRenderingParams = nullptr; IDWriteRenderingParams *customClearTypeRenderingParams = nullptr; -static HMODULE hDLLD2D = NULL; -static HMODULE hDLLDWrite = NULL; +static HMODULE hDLLD2D {}; +static HMODULE hDLLDWrite {}; bool LoadD2D() { static bool triedLoadingD2D = false; @@ -156,7 +156,7 @@ struct FormatAndMetrics { FormatAndMetrics(HFONT hfont_, int extraFontFlag_, int characterSet_) : technology(SCWIN_TECH_GDI), hfont(hfont_), #if defined(USE_D2D) - pTextFormat(0), + pTextFormat(nullptr), #endif extraFontFlag(extraFontFlag_), characterSet(characterSet_), yAscent(2), yDescent(1), yInternalLeading(0) { } @@ -168,7 +168,7 @@ struct FormatAndMetrics { FLOAT yDescent_, FLOAT yInternalLeading_) : technology(SCWIN_TECH_DIRECTWRITE), - hfont(0), + hfont{}, pTextFormat(pTextFormat_), extraFontFlag(extraFontFlag_), characterSet(characterSet_), @@ -238,9 +238,9 @@ void SetWindowPointer(HWND hWnd, void *ptr) { } CRITICAL_SECTION crPlatformLock; -HINSTANCE hinstPlatformRes = 0; +HINSTANCE hinstPlatformRes {}; -HCURSOR reverseArrowCursor = NULL; +HCURSOR reverseArrowCursor {}; FormatAndMetrics *FamFromFontID(void *fid) { return static_cast(fid); @@ -332,7 +332,7 @@ public: FontCached *FontCached::first = nullptr; FontCached::FontCached(const FontParameters &fp) : - next(0), usage(0), size(1.0), hash(0) { + next(nullptr), usage(0), size(1.0), hash(0) { SetLogFont(lf, fp.faceName, fp.characterSet, fp.size, fp.weight, fp.italic, fp.extraFontFlag); technology = fp.technology; hash = HashFont(fp); @@ -414,7 +414,7 @@ void FontCached::Release() { } FontID FontCached::FindOrCreate(const FontParameters &fp) { - FontID ret = 0; + FontID ret {}; ::EnterCriticalSection(&crPlatformLock); const int hashFind = HashFont(fp); for (FontCached *cur=first; cur; cur=cur->next) { @@ -453,7 +453,7 @@ void FontCached::ReleaseId(FontID fid_) { ::LeaveCriticalSection(&crPlatformLock); } -Font::Font() noexcept : fid(0) { +Font::Font() noexcept : fid{} { } Font::~Font() { @@ -520,21 +520,22 @@ public: typedef VarBuffer TextPositions; class SurfaceGDI : public Surface { - bool unicodeMode; - HDC hdc; - bool hdcOwned; - HPEN pen; - HPEN penOld; - HBRUSH brush; - HBRUSH brushOld; - HFONT font; - HFONT fontOld; - HBITMAP bitmap; - HBITMAP bitmapOld; - int maxWidthMeasure; - int maxLenText; + bool unicodeMode=false; + HDC hdc{}; + bool hdcOwned=false; + HPEN pen{}; + HPEN penOld{}; + HBRUSH brush{}; + HBRUSH brushOld{}; + HFONT font{}; + HFONT fontOld{}; + HBITMAP bitmap{}; + HBITMAP bitmapOld{}; + int maxWidthMeasure = INT_MAX; + // There appears to be a 16 bit string length limit in GDI on NT. + int maxLenText = 65535; - int codePage; + int codePage = 0; void BrushColor(ColourDesired back); void SetFont(Font &font_); @@ -595,18 +596,7 @@ public: void SetBidiR2L(bool bidiR2L_) override; }; -SurfaceGDI::SurfaceGDI() : - unicodeMode(false), - hdc(0), hdcOwned(false), - pen(0), penOld(0), - brush(0), brushOld(0), - font(0), fontOld(0), - bitmap(0), bitmapOld(0) { - maxWidthMeasure = INT_MAX; - // There appears to be a 16 bit string length limit in GDI on NT. - maxLenText = 65535; - - codePage = 0; +SurfaceGDI::SurfaceGDI() { } SurfaceGDI::~SurfaceGDI() { @@ -1235,7 +1225,7 @@ void SurfaceD2D::SetScale() { } bool SurfaceD2D::Initialised() { - return pRenderTarget != 0; + return pRenderTarget != nullptr; } HRESULT SurfaceD2D::FlushDrawing() { @@ -1381,7 +1371,7 @@ void SurfaceD2D::Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesi if (pRenderTarget) { ID2D1Factory *pFactory = nullptr; pRenderTarget->GetFactory(&pFactory); - ID2D1PathGeometry *geometry=0; + ID2D1PathGeometry *geometry=nullptr; HRESULT hr = pFactory->CreatePathGeometry(&geometry); if (SUCCEEDED(hr)) { ID2D1GeometrySink *sink = nullptr; @@ -2533,7 +2523,7 @@ class ListBoxX : public ListBox { static const Point ImageInset; // Padding around image public: - ListBoxX() : lineHeight(10), fontCopy(0), technology(0), lb(0), unicodeMode(false), + ListBoxX() : lineHeight(10), fontCopy{}, technology(0), lb{}, unicodeMode(false), desiredVisibleRows(9), maxItemCharacters(0), aveCharWidth(8), parent(nullptr), ctrlID(0), delegate(nullptr), @@ -3341,7 +3331,7 @@ bool ListBoxX_Unregister() { } -Menu::Menu() noexcept : mid(0) { +Menu::Menu() noexcept : mid{} { } void Menu::CreatePopUp() { diff --git a/src/Dialogs.c b/src/Dialogs.c index f5a099cf2..3ee32ece5 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2599,6 +2599,21 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) wndpl.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(hwnd, &wndpl); + // corrections in case of aero snapped position + if (SW_NORMAL == wndpl.showCmd) { + RECT rc; + GetWindowRect(hwnd, &rc); + MONITORINFO mi; + GetMonitorInfoFromRect(&rc, &mi); + LONG const width = rc.right - rc.left; + LONG const height = rc.bottom - rc.top; + rc.left -= (mi.rcWork.left - mi.rcMonitor.left); + rc.right = rc.left + width; + rc.top -= (mi.rcWork.top - mi.rcMonitor.top); + rc.bottom = rc.top + height; + wndpl.rcNormalPosition = rc; + } + WININFO wi; wi.x = wndpl.rcNormalPosition.left; wi.y = wndpl.rcNormalPosition.top; @@ -2607,6 +2622,7 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED); wi.zoom = SciCall_GetZoom(); + // set monitor info too GetMonitorInfoFromRect(&(wndpl.rcNormalPosition), hMonitorInfo); return wi; diff --git a/src/Notepad3.c b/src/Notepad3.c index 78ef06b14..ae34ce51c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -871,7 +871,7 @@ void EndWaitCursor() // _InitWindowPosition() // // -static WININFO _InitDefaultWndPos(const int flagsPos) +static WININFO _InitDefaultWndPos(const int flagsPos) { RECT rc; GetWindowRect(GetDesktopWindow(), &rc); @@ -2001,9 +2001,6 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) // Terminate file watching InstallFileWatching(NULL); - // remember window position - s_WinInfo = GetMyWindowPlacement(hwnd, NULL); - DragAcceptFiles(hwnd, true); #ifdef _EXTRA_DRAG_N_DROP_HANDLER_ RevokeDragAndDrop(pDropTarget); @@ -7095,10 +7092,12 @@ void SaveSettings(bool bSaveSettingsNow) CreateIniFile(); - if (!s_bSaveSettings && !bSaveSettingsNow) { + if (!(s_bSaveSettings || bSaveSettingsNow)) { IniSetBool(L"Settings", L"SaveSettings", s_bSaveSettings); return; } + // update window placement + s_WinInfo = GetMyWindowPlacement(Globals.hwndMain, NULL); WCHAR tchMsg[80]; GetLngString(IDS_MUI_SAVINGSETTINGS, tchMsg, COUNTOF(tchMsg)); @@ -7261,7 +7260,6 @@ void SaveSettings(bool bSaveSettingsNow) SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosX); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosY); - SaveIniSection(L"Settings", pIniSection); FreeMem(pIniSection); @@ -7270,11 +7268,6 @@ void SaveSettings(bool bSaveSettingsNow) // Scintilla Styles Style_Save(); - // update window placement - if (bSaveSettingsNow) { - s_WinInfo = GetMyWindowPlacement(Globals.hwndMain, NULL); - } - int ResX = GetSystemMetrics(SM_CXSCREEN); int ResY = GetSystemMetrics(SM_CYSCREEN);