Merge pull request #3379 from RaiKoHoff/Dev_RC1

Some code cleanup (Scintilla Lib)
This commit is contained in:
Rainer Kottenhoff 2021-04-23 08:58:05 +02:00 committed by GitHub
commit 3e9da8824c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 124 additions and 52 deletions

View File

@ -20,16 +20,22 @@
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> <!-- Vista -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> <!-- 7 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> <!-- 8 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <!-- 8.1 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> <!-- 10 -->
</application>
</compatibility>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>false</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<dpiAwareness>PerMonitorV2,PerMonitor</dpiAwareness>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
<gdiScaling>false</gdiScaling>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

View File

@ -431,6 +431,14 @@ INT_PTR CALLBACK GotoDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
return TRUE;
case WM_DPICHANGED: {
const RECT* rect = (RECT*)lParam;
SetWindowPos(hwnd, NULL, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_INTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);
}
return TRUE;
case WM_GETMINMAXINFO: {
LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
lpmmi->ptMinTrackSize.x = mmiPtMinX;
@ -1724,6 +1732,12 @@ INT_PTR CALLBACK CopyMoveDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam
}
return TRUE;
case WM_DPICHANGED: {
const RECT* rect = (RECT*)lParam;
SetWindowPos(hwnd, NULL, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_INTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);
}
return TRUE;
case WM_GETMINMAXINFO: {
LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
@ -1999,6 +2013,12 @@ INT_PTR CALLBACK OpenWithDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam
}
return TRUE;
case WM_DPICHANGED: {
const RECT* rect = (RECT*)lParam;
SetWindowPos(hwnd, NULL, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_INTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);
}
return TRUE;
case WM_GETMINMAXINFO: {
LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;

View File

@ -835,6 +835,14 @@ CASE_WM_CTLCOLOR_SET:
break;
case WM_DPICHANGED: {
const RECT* rect = (RECT*)lParam;
SetWindowPos(hwnd, NULL, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE | RDW_INTERNALPAINT | RDW_ALLCHILDREN | RDW_UPDATENOW);
}
return TRUE;
case WM_SETFOCUS:
SetFocus(GetDlgItem(hwnd, nIdFocus));
break;
@ -2406,13 +2414,8 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_TOOLBAR:
if (Settings.bShowToolbar) {
ShowWindow(hwndReBar,SW_HIDE);
Settings.bShowToolbar = 0;
} else {
ShowWindow(hwndReBar,SW_SHOW);
Settings.bShowToolbar = 1;
}
Settings.bShowToolbar = !Settings.bShowToolbar;
ShowWindow(hwndReBar, Settings.bShowToolbar ? SW_SHOW : SW_HIDE);
SendWMSize(hwnd);
break;

View File

@ -1825,10 +1825,14 @@ Sci::Position Editor::FormatRange(bool draw, const Sci_RangeToFormat *pfr) {
if (!pfr)
return 0;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
AutoSurface surface(pfr->hdc, this, SC_TECHNOLOGY_DEFAULT, true);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
if (!surface)
return 0;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
AutoSurface surfaceMeasure(pfr->hdcTarget, this, SC_TECHNOLOGY_DEFAULT, true);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
if (!surfaceMeasure) {
return 0;
}

View File

@ -37,13 +37,13 @@ MarginStyle::MarginStyle(int style_, int width_, int mask_) noexcept :
style(style_), width(width_), mask(mask_), sensitive(false), cursor(SC_CURSORREVERSEARROW) {
}
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs, const char *localeName) {
PLATFORM_ASSERT(fs.fontName);
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
sizeZoomed = GetFontSizeZoomed(fs.size, zoomLevel);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
const float deviceHeight = static_cast<float>(surface.DeviceHeightFont(sizeZoomed));
const FontParameters fp(fs.fontName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, fs.weight, fs.italic, fs.extraFontFlag, technology, fs.characterSet, localeName);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
font = Font::Allocate(fp);
ascent = static_cast<unsigned int>(surface.Ascent(font.get()));
@ -282,40 +282,48 @@ void ViewStyle::Init(size_t stylesSize_) {
wrapVisualFlagsLocation = 0;
wrapVisualStartIndent = 0;
wrapIndentMode = SC_WRAPINDENT_FIXED;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
localeName = localeNameDefault;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
}
void ViewStyle::Refresh(Surface &surface, int tabInChars) {
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
if (!fontsValid) {
fontsValid = true;
fonts.clear();
fonts.clear();
// Apply the extra font flag which controls text drawing quality to each style.
for (Style &style : styles) {
style.extraFontFlag = extraFontFlag;
}
// Create a FontRealised object for each unique font in the styles.
CreateAndAddFont(styles[STYLE_DEFAULT]);
for (const Style &style : styles) {
CreateAndAddFont(style);
}
// Ask platform to allocate each unique font.
for (auto &font : fonts) {
font.second->Realise(surface, zoomLevel, technology, font.first, localeName.c_str());
}
// Set the platform font handle and measurements for each style.
for (Style &style : styles) {
const FontRealised *fr = Find(style);
style.Copy(fr->font, *fr);
}
aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
}
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
selbar = Platform::Chrome();
selbarlight = Platform::ChromeHighlight();
// Apply the extra font flag which controls text drawing quality to each style.
for (Style &style : styles) {
style.extraFontFlag = extraFontFlag;
}
// Create a FontRealised object for each unique font in the styles.
CreateAndAddFont(styles[STYLE_DEFAULT]);
for (const Style &style : styles) {
CreateAndAddFont(style);
}
// Ask platform to allocate each unique font.
for (auto &font : fonts) {
font.second->Realise(surface, zoomLevel, technology, font.first, localeName.c_str());
}
// Set the platform font handle and measurements for each style.
for (Style &style : styles) {
const FontRealised *fr = Find(style);
style.Copy(fr->font, *fr);
}
indicatorsDynamic = std::any_of(indicators.cbegin(), indicators.cend(),
[](const Indicator &indicator) noexcept { return indicator.IsDynamic(); });
@ -328,7 +336,9 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
maxAscent += extraAscent;
maxDescent += extraDescent;
lineHeight = maxAscent + maxDescent;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
lineOverlap = std::clamp(lineHeight / 10, 2, lineHeight);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
someStylesProtected = std::any_of(styles.cbegin(), styles.cend(),
[](const Style &style) noexcept { return style.IsProtected(); });
@ -336,9 +346,10 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
someStylesForceCase = std::any_of(styles.cbegin(), styles.cend(),
[](const Style &style) noexcept { return style.caseForce != Style::CaseForce::mixed; });
aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
tabWidth = spaceWidth * tabInChars;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
//~tabWidth = spaceWidth * tabInChars;
tabWidth = aveCharWidth * tabInChars;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
controlCharWidth = 0.0;
if (controlCharSymbol >= 32) {
@ -388,6 +399,7 @@ void ViewStyle::ClearStyles() {
}
}
styles[STYLE_LINENUMBER].back = Platform::Chrome();
// Set call tip fore/back to match the values previously set for call tips
styles[STYLE_CALLTIP].back = ColourDesired(0xff, 0xff, 0xff);
styles[STYLE_CALLTIP].fore = ColourDesired(0x80, 0x80, 0x80);
@ -398,10 +410,12 @@ void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
styles[styleIndex].fontName = fontNames.Save(name);
}
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void ViewStyle::SetFontLocaleName(const char *name) {
fontsValid = false;
localeName = name;
}
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
bool ViewStyle::ProtectionActive() const noexcept {
return someStylesProtected;

View File

@ -37,7 +37,9 @@ public:
FontRealised &operator=(const FontRealised &) = delete;
FontRealised &operator=(FontRealised &&) = delete;
virtual ~FontRealised() noexcept = default;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs, const char *localeName);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
};
enum class IndentView {none, real, lookForward, lookBoth};
@ -96,7 +98,9 @@ public:
std::vector<Indicator> indicators;
bool indicatorsDynamic;
bool indicatorsSetFore;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
bool fontsValid;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
int technology;
int lineHeight;
int lineOverlap;
@ -131,7 +135,9 @@ public:
int fixedColumnWidth; ///< Total width of margins
bool marginInside; ///< true: margin included in text view, false: separate views
int textStart; ///< Starting x position of text within the view
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
int zoomLevel; /// @ 2018-09-06 Changed to a percent value
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
WhiteSpace viewWhitespace;
TabDrawMode tabDrawMode;
int whitespaceSize;
@ -176,7 +182,6 @@ public:
int wrapVisualFlagsLocation;
int wrapVisualStartIndent;
int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
std::string localeName;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<

View File

@ -361,9 +361,8 @@ struct FontDirectWrite : public FontWin {
const std::wstring wsFace = WStringFromUTF8(fp.faceName);
const std::wstring wsLocale = WStringFromUTF8(fp.localeName);
const FLOAT fHeight = static_cast<FLOAT>(fp.size);
DWRITE_FONT_STYLE style = fp.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
DWRITE_FONT_STYLE style = fp.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
std::wstring wsFamily;
DWRITE_FONT_WEIGHT weight = static_cast<DWRITE_FONT_WEIGHT>(fp.weight);
DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL;
@ -379,11 +378,10 @@ struct FontDirectWrite : public FontWin {
// static_cast<DWRITE_FONT_WEIGHT>(fp.weight),
// style,
// DWRITE_FONT_STRETCH_NORMAL, fHeight, wsLocale.c_str(), &pTextFormat);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
if (SUCCEEDED(hr)) {
pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
IDWriteTextLayout *pTextLayout = nullptr;
hr = pIDWriteFactory->CreateTextLayout(L"X", 1, pTextFormat,
100.0f, 100.0f, &pTextLayout);
@ -511,12 +509,14 @@ int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept {
return value;
}
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
BOOL AdjustWindowRectForDpi(LPRECT lpRect, DWORD dwStyle, DWORD dwExStyle, UINT dpi) noexcept {
if (fnAdjustWindowRectExForDpi) {
return fnAdjustWindowRectExForDpi(lpRect, dwStyle, FALSE, dwExStyle, dpi);
}
return ::AdjustWindowRectEx(lpRect, dwStyle, FALSE, dwExStyle);
}
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
class SurfaceGDI : public Surface {
SurfaceMode mode;
@ -554,7 +554,9 @@ public:
~SurfaceGDI() noexcept override;
void Init(WindowID wid) override;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void Init(SurfaceID sid, WindowID wid, bool printing = false) override;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
std::unique_ptr<Surface> AllocatePixMap(int width, int height) override;
void SetMode(SurfaceMode mode_) override;
@ -681,7 +683,9 @@ void SurfaceGDI::Init(WindowID wid) {
logPixelsY = DpiForWindow(wid);
}
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void SurfaceGDI::Init(SurfaceID sid, WindowID wid, bool printing) {
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
Release();
hdc = static_cast<HDC>(sid);
::SetTextAlign(hdc, TA_BASELINE);
@ -1397,7 +1401,9 @@ public:
void SetScale(WindowID wid) noexcept;
void Init(WindowID wid) override;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void Init(SurfaceID sid, WindowID wid, bool printing = false) override;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
std::unique_ptr<Surface> AllocatePixMap(int width, int height) override;
void SetMode(SurfaceMode mode_) override;
@ -1429,7 +1435,9 @@ public:
std::unique_ptr<IScreenLineLayout> Layout(const IScreenLine *screenLine) override;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void DrawTextCommon(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text, int codePageOverride, UINT fuOptions);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
void DrawTextNoClip(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text, ColourAlpha fore, ColourAlpha back) override;
void DrawTextClipped(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text, ColourAlpha fore, ColourAlpha back) override;
@ -1524,11 +1532,13 @@ void SurfaceD2D::Init(WindowID wid) {
SetScale(wid);
}
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void SurfaceD2D::Init(SurfaceID sid, WindowID wid, bool /*printing*/) {
Release();
SetScale(wid); // printing always using GDI
pRenderTarget = static_cast<ID2D1RenderTarget *>(sid);
}
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
std::unique_ptr<Surface> SurfaceD2D::AllocatePixMap(int width, int height) {
return std::make_unique<SurfaceD2D>(pRenderTarget, width, height, mode, logPixelsY);
@ -2378,7 +2388,9 @@ std::unique_ptr<IScreenLineLayout> SurfaceD2D::Layout(const IScreenLine *screenL
return std::make_unique<ScreenLineLayout>(screenLine);
}
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
void SurfaceD2D::DrawTextCommon(PRectangle rc, const Font *font_, XYPOSITION ybase, std::string_view text, int codePageOverride, UINT fuOptions) {
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
SetFont(font_);
// Use Unicode calls
@ -2416,7 +2428,9 @@ void SurfaceD2D::DrawTextNoClip(PRectangle rc, const Font *font_, XYPOSITION yba
if (pRenderTarget) {
FillRectangleAligned(rc, back);
D2DPenColourAlpha(fore);
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
DrawTextCommon(rc, font_, ybase, text, 0, ETO_OPAQUE);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
}
}
@ -2425,7 +2439,9 @@ void SurfaceD2D::DrawTextClipped(PRectangle rc, const Font *font_, XYPOSITION yb
if (pRenderTarget) {
FillRectangleAligned(rc, back);
D2DPenColourAlpha(fore);
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
DrawTextCommon(rc, font_, ybase, text, 0, ETO_OPAQUE | ETO_CLIPPED);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
}
}
@ -2436,7 +2452,9 @@ void SurfaceD2D::DrawTextTransparent(PRectangle rc, const Font *font_, XYPOSITIO
if (ch != ' ') {
if (pRenderTarget) {
D2DPenColourAlpha(fore);
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
DrawTextCommon(rc, font_, ybase, text, 0, 0);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
}
return;
}
@ -3953,7 +3971,9 @@ void Platform_Finalise(bool fromDllMain) noexcept {
if (!fromDllMain) {
ReleaseUnknown(defaultRenderingParams);
ReleaseUnknown(customClearTypeRenderingParams);
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
ReleaseUnknown(gdiInterop);
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
ReleaseUnknown(pIDWriteFactory);
ReleaseUnknown(pD2DFactory);
if (hDLLDWrite) {