From 01a088f9947295e4e427a70394359ef0fd776cc0 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sat, 13 Apr 2024 17:07:56 +0200 Subject: [PATCH] Use new dpi manager scaled default fonts ref #14959 Close #14991 --- PowerEditor/src/Parameters.cpp | 49 ------------------- PowerEditor/src/Parameters.h | 3 -- .../src/ScintillaComponent/FindReplaceDlg.cpp | 2 - .../ScintillaComponent/UserDefineDialog.cpp | 3 -- .../WinControls/DockingWnd/DockingCont.cpp | 10 ++-- .../FunctionList/functionListPanel.cpp | 2 +- .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 5 +- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 22 +++++++-- 8 files changed, 25 insertions(+), 71 deletions(-) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 16e41fd66..06b691501 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -1899,55 +1899,6 @@ bool NppParameters::isInFontList(const std::wstring& fontName2Search) const return false; } -LOGFONT NppParameters::getDefaultGUIFont(DefaultFontType type) -{ - LOGFONT lf{}; - NONCLIENTMETRICS ncm{}; - ncm.cbSize = sizeof(NONCLIENTMETRICS); - if (::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0) != FALSE) - { - switch (type) - { - case DefaultFontType::menu: - { - lf = ncm.lfMenuFont; - break; - } - - case DefaultFontType::status: - { - lf = ncm.lfStatusFont; - break; - } - - case DefaultFontType::caption: - { - lf = ncm.lfCaptionFont; - break; - } - - case DefaultFontType::smcaption: - { - lf = ncm.lfSmCaptionFont; - break; - } - - // case DefaultFontType::message: - default: - { - lf = ncm.lfMessageFont; - break; - } - } - } - else // should not happen, fallback - { - auto hf = static_cast(::GetStockObject(DEFAULT_GUI_FONT)); - ::GetObject(hf, sizeof(LOGFONT), &lf); - } - return lf; -} - void NppParameters::getLangKeywordsFromXmlTree() { TiXmlNode *root = diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 3466ece4e..df34aade8 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1546,9 +1546,6 @@ public: bool isInFontList(const std::wstring& fontName2Search) const; const std::vector& getFontList() const { return _fontlist; } - enum class DefaultFontType { menu, status, message, caption, smcaption }; - static LOGFONT getDefaultGUIFont(DefaultFontType type = DefaultFontType::message); - int getNbUserLang() const {return _nbUserLang;} UserLangContainer & getULCFromIndex(size_t i) {return *_userLangArray[i];}; UserLangContainer * getULCFromName(const TCHAR *userLangName); diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 808d7cdb9..94fcb3467 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -300,8 +300,6 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent, bool t getClientRect(rect); _tab.init(_hInst, _hSelf, false, true); NppDarkMode::subclassTabControl(_tab.getHSelf()); - int tabDpiDynamicalHeight = dpiManager.scaleY(13); - _tab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight); const TCHAR *find = TEXT("Find"); const TCHAR *replace = TEXT("Replace"); diff --git a/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp b/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp index 973c63388..a09e3a766 100644 --- a/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp +++ b/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp @@ -1005,9 +1005,6 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA _ctrlTab.init(_hInst, _hSelf, false); NppDarkMode::subclassTabControl(_ctrlTab.getHSelf()); - int tabDpiDynamicalHeight = nppParam._dpiManager.scaleY(13); - _ctrlTab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight); - _folderStyleDlg.init(_hInst, _hSelf); _folderStyleDlg.create(IDD_FOLDER_STYLE_DLG); _folderStyleDlg.display(); diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp index 87e98d408..b460c9661 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp @@ -123,11 +123,11 @@ void DockingCont::doDialog(bool willBeShown, bool isFloating) ::ShowWindow(_hCaption, SW_SHOW); } - //If you want defualt GUI font - LOGFONT lfTab{ NppParameters::getDefaultGUIFont() }; + //If you want default GUI font + LOGFONT lfTab{ DPIManagerV2::getDefaultGUIFontForDpi(_hParent) }; _hFont = ::CreateFontIndirect(&lfTab); - LOGFONT lfCaption{ NppParameters::getDefaultGUIFont(NppParameters::DefaultFontType::smcaption) }; + LOGFONT lfCaption{ DPIManagerV2::getDefaultGUIFontForDpi(_hParent, DPIManagerV2::FontType::smcaption) }; _hFontCaption = ::CreateFontIndirect(&lfCaption); } @@ -578,7 +578,7 @@ void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct) rc.right = rc.bottom - rc.top; rc.bottom += 14; - LOGFONT lf{ NppParameters::getDefaultGUIFont(NppParameters::DefaultFontType::smcaption) }; + LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(_hParent, DPIManagerV2::FontType::smcaption) }; lf.lfEscapement = 900; hFont = ::CreateFontIndirect(&lf); if (hFont == nullptr) @@ -612,7 +612,7 @@ void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct) { if (_hFont == nullptr) { - LOGFONT lf{ NppParameters::getDefaultGUIFont() }; + LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(_hParent) }; _hFont = ::CreateFontIndirect(&lf); } auto hOld = static_cast(::SelectObject(hDc, _hFont)); diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 7c23e0abc..960e58e5c 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -898,7 +898,7 @@ intptr_t CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LP if (_hFontSearchEdit == nullptr) { - LOGFONT lf{ NppParameters::getDefaultGUIFont() }; + LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(_hParent) }; _hFontSearchEdit = ::CreateFontIndirect(&lf); } diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index f9288499d..8f2ebf772 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -133,9 +133,6 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL, bool msgDestParent) NppDarkMode::subclassTabControl(_tab.getHSelf()); DPIManager& dpiManager = NppParameters::getInstance()._dpiManager; - int tabDpiDynamicalHeight = dpiManager.scaleY(13); - _tab.setFont(TEXT("Tahoma"), tabDpiDynamicalHeight); - const TCHAR *available = TEXT("Available"); const TCHAR *updates = TEXT("Updates"); const TCHAR *installed = TEXT("Installed"); @@ -150,7 +147,7 @@ void PluginsAdminDlg::create(int dialogID, bool isRTL, bool msgDestParent) getMappedChildRect(IDC_PLUGINADM_EDIT, rcDesc); const long margeX = ::GetSystemMetrics(SM_CXEDGE); - const long margeY = tabDpiDynamicalHeight; + const long margeY = dpiManager.scaleY(13); rect.bottom = rcDesc.bottom + margeY; _tab.reSizeTo(rect); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 3eb5f87e8..72e98657f 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -73,6 +73,16 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin { throw std::runtime_error("TabBar::init : CreateWindowEx() function return null"); } + + if (_hFont == nullptr) + { + const UINT dpi = DPIManagerV2::getDpiForWindow(_hParent); + LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(dpi) }; + lf.lfHeight = DPIManagerV2::scaleFont(8, dpi); + _hFont = ::CreateFontIndirect(&lf); + ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast(_hFont), 0); + } + } @@ -337,13 +347,17 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast(this)); _tabBarDefaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(TabBarPlus_Proc))); - auto& dpiManager = NppParameters::getInstance()._dpiManager; - - LOGFONT lf{ NppParameters::getDefaultGUIFont() }; + const UINT dpi = DPIManagerV2::getDpiForWindow(_hParent); + LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(dpi) }; LOGFONT lfVer{ lf }; + if (_hFont != nullptr) + { + ::DeleteObject(_hFont); + _hFont = nullptr; + } _hFont = ::CreateFontIndirect(&lf); lf.lfWeight = FW_HEAVY; - lf.lfHeight = -(dpiManager.pointsToPixels(10)); + lf.lfHeight = DPIManagerV2::scaleFont(10, dpi); _hLargeFont = ::CreateFontIndirect(&lf); lfVer.lfEscapement = 900;