GUI Enhancement: StylerDlg & URLCtrl
- prefer SystemParametersInfo fonts over DEFAULT_GUI_FONT - optimize dark mode - fix override warnings Fix #13705, close #13706
This commit is contained in:
parent
781709a022
commit
776a3fb945
|
@ -1809,18 +1809,6 @@ bool NppParameters::isInFontList(const generic_string& fontName2Search) const
|
|||
return false;
|
||||
}
|
||||
|
||||
HFONT NppParameters::getDefaultUIFont()
|
||||
{
|
||||
static HFONT g_defaultMessageFont = []() {
|
||||
NONCLIENTMETRICS ncm{};
|
||||
ncm.cbSize = sizeof(NONCLIENTMETRICS);
|
||||
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
|
||||
|
||||
return CreateFontIndirect(&ncm.lfMessageFont);
|
||||
}();
|
||||
return g_defaultMessageFont;
|
||||
}
|
||||
|
||||
LOGFONT NppParameters::getDefaultGUIFont(DefaultFontType type)
|
||||
{
|
||||
LOGFONT lf{};
|
||||
|
@ -1842,12 +1830,6 @@ LOGFONT NppParameters::getDefaultGUIFont(DefaultFontType type)
|
|||
break;
|
||||
}
|
||||
|
||||
case DefaultFontType::message:
|
||||
{
|
||||
lf = ncm.lfMessageFont;
|
||||
break;
|
||||
}
|
||||
|
||||
case DefaultFontType::caption:
|
||||
{
|
||||
lf = ncm.lfCaptionFont;
|
||||
|
@ -1860,16 +1842,15 @@ LOGFONT NppParameters::getDefaultGUIFont(DefaultFontType type)
|
|||
break;
|
||||
}
|
||||
|
||||
// case DefaultFontType::none
|
||||
// case DefaultFontType::message:
|
||||
default:
|
||||
{
|
||||
auto hf = static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT));
|
||||
::GetObject(hf, sizeof(LOGFONT), &lf);
|
||||
lf = ncm.lfMessageFont;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else // should not happen, fallback
|
||||
{
|
||||
auto hf = static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT));
|
||||
::GetObject(hf, sizeof(LOGFONT), &lf);
|
||||
|
|
|
@ -1525,8 +1525,7 @@ public:
|
|||
bool isInFontList(const generic_string& fontName2Search) const;
|
||||
const std::vector<generic_string>& getFontList() const { return _fontlist; }
|
||||
|
||||
HFONT getDefaultUIFont();
|
||||
enum class DefaultFontType { none, menu, status, message, caption, smcaption };
|
||||
enum class DefaultFontType { menu, status, message, caption, smcaption };
|
||||
static LOGFONT getDefaultGUIFont(DefaultFontType type = DefaultFontType::message);
|
||||
|
||||
int getNbUserLang() const {return _nbUserLang;}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "URLCtrl.h"
|
||||
#include "NppDarkMode.h"
|
||||
#include "Parameters.h"
|
||||
|
||||
|
||||
void URLCtrl::create(HWND itemHandle, const TCHAR * link, COLORREF linkColor)
|
||||
|
@ -157,20 +158,16 @@ LRESULT URLCtrl::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
::SetBkColor(hdc, getCtrlBgColor(GetParent(hwnd))); ///*::GetSysColor(COLOR_3DFACE)*/);
|
||||
|
||||
// Create an underline font
|
||||
if (_hfUnderlined == nullptr)
|
||||
{
|
||||
// Get the default GUI font
|
||||
LOGFONT lf{};
|
||||
HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
|
||||
// Create an underline font
|
||||
if (_hfUnderlined == nullptr)
|
||||
{
|
||||
// Get the default GUI font
|
||||
LOGFONT lf{ NppParameters::getDefaultGUIFont() };
|
||||
lf.lfUnderline = TRUE;
|
||||
|
||||
// Add UNDERLINE attribute
|
||||
GetObject(hf, sizeof lf, &lf);
|
||||
lf.lfUnderline = TRUE;
|
||||
|
||||
// Create a new font
|
||||
_hfUnderlined = ::CreateFontIndirect(&lf);
|
||||
}
|
||||
// Create a new font
|
||||
_hfUnderlined = ::CreateFontIndirect(&lf);
|
||||
}
|
||||
|
||||
HANDLE hOld = SelectObject(hdc, _hfUnderlined);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class URLCtrl : public Window {
|
|||
public:
|
||||
void create(HWND itemHandle, const TCHAR * link, COLORREF linkColor = RGB(0,0,255));
|
||||
void create(HWND itemHandle, int cmd, HWND msgDest = NULL);
|
||||
void destroy();
|
||||
void destroy() override;
|
||||
private:
|
||||
HCURSOR& loadHandCursor();
|
||||
void action();
|
||||
|
|
|
@ -31,10 +31,10 @@ LRESULT CALLBACK ColourStaticTextHooker::colourStaticProc(HWND hwnd, UINT Messag
|
|||
{
|
||||
case WM_PAINT:
|
||||
{
|
||||
RECT rect;
|
||||
RECT rect{};
|
||||
::GetClientRect(hwnd, &rect);
|
||||
|
||||
PAINTSTRUCT ps;
|
||||
PAINTSTRUCT ps{};
|
||||
HDC hdc = ::BeginPaint(hwnd, &ps);
|
||||
|
||||
::SetTextColor(hdc, _colour);
|
||||
|
@ -45,17 +45,17 @@ LRESULT CALLBACK ColourStaticTextHooker::colourStaticProc(HWND hwnd, UINT Messag
|
|||
}
|
||||
|
||||
// Get the default GUI font
|
||||
HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
|
||||
LOGFONT lf{ NppParameters::getDefaultGUIFont() };
|
||||
HFONT hf = ::CreateFontIndirect(&lf);
|
||||
|
||||
HANDLE hOld = SelectObject(hdc, hf);
|
||||
|
||||
// Draw the text!
|
||||
TCHAR text[MAX_PATH];
|
||||
TCHAR text[MAX_PATH]{};
|
||||
::GetWindowText(hwnd, text, MAX_PATH);
|
||||
::DrawText(hdc, text, -1, &rect, DT_LEFT);
|
||||
|
||||
::SelectObject(hdc, hOld);
|
||||
|
||||
::DeleteObject(::SelectObject(hdc, hOld));
|
||||
::EndPaint(hwnd, &ps);
|
||||
|
||||
return TRUE;
|
||||
|
@ -159,44 +159,30 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
|
|||
|
||||
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
|
||||
|
||||
goToCenter();
|
||||
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_CTLCOLOREDIT:
|
||||
{
|
||||
if (NppDarkMode::isEnabled())
|
||||
auto hdcStatic = reinterpret_cast<HDC>(wParam);
|
||||
auto dlgCtrlID = ::GetDlgCtrlID(reinterpret_cast<HWND>(lParam));
|
||||
if (dlgCtrlID == IDC_USER_EXT_EDIT || dlgCtrlID == IDC_USER_KEYWORDS_EDIT)
|
||||
{
|
||||
HWND hwnd = reinterpret_cast<HWND>(lParam);
|
||||
if (hwnd == ::GetDlgItem(_hSelf, IDC_USER_EXT_EDIT) || hwnd == ::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_EDIT))
|
||||
{
|
||||
return NppDarkMode::onCtlColorSofter(reinterpret_cast<HDC>(wParam));
|
||||
}
|
||||
else
|
||||
{
|
||||
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
|
||||
}
|
||||
return NppDarkMode::onCtlColorSofter(hdcStatic);
|
||||
}
|
||||
break;
|
||||
return NppDarkMode::onCtlColor(hdcStatic);
|
||||
}
|
||||
|
||||
case WM_CTLCOLORLISTBOX:
|
||||
{
|
||||
if (NppDarkMode::isEnabled())
|
||||
{
|
||||
return NppDarkMode::onCtlColorListbox(wParam, lParam);
|
||||
}
|
||||
break;
|
||||
return NppDarkMode::onCtlColorListbox(wParam, lParam);
|
||||
}
|
||||
|
||||
case WM_CTLCOLORDLG:
|
||||
{
|
||||
if (NppDarkMode::isEnabled())
|
||||
{
|
||||
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam));
|
||||
}
|
||||
break;
|
||||
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam));
|
||||
}
|
||||
|
||||
case WM_CTLCOLORSTATIC:
|
||||
|
@ -240,15 +226,11 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
|
|||
return NppDarkMode::onCtlColorDarkerBGStaticText(hdcStatic, isTextEnabled);
|
||||
}
|
||||
|
||||
if (NppDarkMode::isEnabled())
|
||||
if (dlgCtrlID == IDC_DEF_EXT_EDIT || dlgCtrlID == IDC_DEF_KEYWORDS_EDIT)
|
||||
{
|
||||
if (dlgCtrlID == IDC_DEF_EXT_EDIT || dlgCtrlID == IDC_DEF_KEYWORDS_EDIT)
|
||||
{
|
||||
return NppDarkMode::onCtlColor(hdcStatic);
|
||||
}
|
||||
return NppDarkMode::onCtlColorDarker(hdcStatic);
|
||||
return NppDarkMode::onCtlColor(hdcStatic);
|
||||
}
|
||||
return FALSE;
|
||||
return NppDarkMode::onCtlColorDarker(hdcStatic);
|
||||
}
|
||||
|
||||
case WM_PRINTCLIENT:
|
||||
|
@ -697,8 +679,8 @@ void WordStyleDlg::updateFontSize()
|
|||
|
||||
if (iFontSizeSel != 0)
|
||||
{
|
||||
const size_t intStrLen = 3;
|
||||
TCHAR intStr[intStrLen];
|
||||
constexpr size_t intStrLen = 3;
|
||||
TCHAR intStr[intStrLen]{};
|
||||
|
||||
auto lbTextLen = ::SendMessage(_hFontSizeCombo, CB_GETLBTEXTLEN, iFontSizeSel, 0);
|
||||
if (static_cast<size_t>(lbTextLen) >= intStrLen)
|
||||
|
@ -710,7 +692,7 @@ void WordStyleDlg::updateFontSize()
|
|||
style._fontSize = STYLE_NOT_USED;
|
||||
else
|
||||
{
|
||||
TCHAR *finStr;
|
||||
TCHAR *finStr = nullptr;
|
||||
style._fontSize = wcstol(intStr, &finStr, 10);
|
||||
if (*finStr != '\0')
|
||||
style._fontSize = STYLE_NOT_USED;
|
||||
|
@ -722,8 +704,8 @@ void WordStyleDlg::updateFontSize()
|
|||
|
||||
void WordStyleDlg::updateExtension()
|
||||
{
|
||||
const int NB_MAX = 256;
|
||||
TCHAR ext[NB_MAX];
|
||||
constexpr int NB_MAX = 256;
|
||||
TCHAR ext[NB_MAX]{};
|
||||
::SendDlgItemMessage(_hSelf, IDC_USER_EXT_EDIT, WM_GETTEXT, NB_MAX, reinterpret_cast<LPARAM>(ext));
|
||||
_lsArray.getLexerFromIndex(_currentLexerIndex - 1).setLexerUserExt(ext);
|
||||
}
|
||||
|
@ -795,7 +777,7 @@ void WordStyleDlg::switchToTheme()
|
|||
|
||||
if (_isThemeDirty)
|
||||
{
|
||||
TCHAR themeFileName[MAX_PATH];
|
||||
TCHAR themeFileName[MAX_PATH]{};
|
||||
wcscpy_s(themeFileName, prevThemeName.c_str());
|
||||
PathStripPath(themeFileName);
|
||||
PathRemoveExtension(themeFileName);
|
||||
|
@ -1077,24 +1059,21 @@ void WordStyleDlg::setVisualFromStyleList()
|
|||
InvalidateRect(_hBgColourStaticText, NULL, FALSE);
|
||||
|
||||
//-- font name
|
||||
LRESULT iFontName;
|
||||
LRESULT iFontName = 0;
|
||||
if (!style._fontName.empty())
|
||||
{
|
||||
iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, reinterpret_cast<LPARAM>(style._fontName.c_str()));
|
||||
if (iFontName == CB_ERR)
|
||||
iFontName = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
iFontName = 0;
|
||||
}
|
||||
|
||||
::SendMessage(_hFontNameCombo, CB_SETCURSEL, iFontName, 0);
|
||||
::EnableWindow(_hFontNameCombo, style._isFontEnabled);
|
||||
InvalidateRect(_hFontNameStaticText, NULL, FALSE);
|
||||
|
||||
//-- font size
|
||||
const size_t intStrLen = 3;
|
||||
TCHAR intStr[intStrLen];
|
||||
constexpr size_t intStrLen = 3;
|
||||
TCHAR intStr[intStrLen]{};
|
||||
LRESULT iFontSize = 0;
|
||||
if (style._fontSize != STYLE_NOT_USED && style._fontSize < 100) // style._fontSize has only 2 digits
|
||||
{
|
||||
|
|
|
@ -61,11 +61,7 @@ class WordStyleDlg : public StaticDialog
|
|||
public :
|
||||
WordStyleDlg() = default;
|
||||
|
||||
void init(HINSTANCE hInst, HWND parent) {
|
||||
Window::init(hInst, parent);
|
||||
};
|
||||
|
||||
virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true);
|
||||
void create(int dialogID, bool isRTL = false, bool msgDestParent = true) override;
|
||||
|
||||
void doDialog(bool isRTL = false) {
|
||||
if (!isCreated())
|
||||
|
@ -87,13 +83,13 @@ public :
|
|||
_gOverride2restored = (NppParameters::getInstance()).getGlobalOverrideStyle();
|
||||
};
|
||||
|
||||
virtual void redraw(bool forceUpdate = false) const {
|
||||
_pFgColour->redraw(forceUpdate);
|
||||
void redraw(bool forceUpdate = false) const override {
|
||||
_pFgColour->redraw(forceUpdate);
|
||||
_pBgColour->redraw(forceUpdate);
|
||||
::InvalidateRect(_hStyleInfoStaticText, NULL, TRUE);
|
||||
::UpdateWindow(_hStyleInfoStaticText);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
void restoreGlobalOverrideValues() {
|
||||
GlobalOverride & gOverride = (NppParameters::getInstance()).getGlobalOverrideStyle();
|
||||
gOverride = _gOverride2restored;
|
||||
|
@ -151,7 +147,7 @@ private :
|
|||
bool _isShownGOCtrls = false;
|
||||
|
||||
|
||||
intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
|
||||
intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) override;
|
||||
|
||||
|
||||
Style & getCurrentStyler() {
|
||||
|
|
|
@ -49,10 +49,16 @@ void StatusBar::init(HINSTANCE, HWND)
|
|||
struct StatusBarSubclassInfo
|
||||
{
|
||||
HTHEME hTheme = nullptr;
|
||||
HFONT _hFont = nullptr;
|
||||
|
||||
StatusBarSubclassInfo() = default;
|
||||
StatusBarSubclassInfo(const HFONT& hFont)
|
||||
: _hFont(hFont) {}
|
||||
|
||||
~StatusBarSubclassInfo()
|
||||
{
|
||||
closeTheme();
|
||||
destroyFont();
|
||||
}
|
||||
|
||||
bool ensureTheme(HWND hwnd)
|
||||
|
@ -72,6 +78,21 @@ struct StatusBarSubclassInfo
|
|||
hTheme = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void setFont(const HFONT& hFont)
|
||||
{
|
||||
destroyFont();
|
||||
_hFont = hFont;
|
||||
}
|
||||
|
||||
void destroyFont()
|
||||
{
|
||||
if (_hFont != nullptr)
|
||||
{
|
||||
::DeleteObject(_hFont);
|
||||
_hFont = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -80,8 +101,6 @@ constexpr UINT_PTR g_statusBarSubclassID = 42;
|
|||
|
||||
LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(uIdSubclass);
|
||||
|
||||
StatusBarSubclassInfo* pStatusBarInfo = reinterpret_cast<StatusBarSubclassInfo*>(dwRefData);
|
||||
|
||||
switch (uMsg)
|
||||
|
@ -90,10 +109,10 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
{
|
||||
if (!NppDarkMode::isEnabled())
|
||||
{
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
RECT rc;
|
||||
RECT rc{};
|
||||
GetClientRect(hWnd, &rc);
|
||||
FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush());
|
||||
return TRUE;
|
||||
|
@ -103,28 +122,28 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
{
|
||||
if (!NppDarkMode::isEnabled())
|
||||
{
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
struct {
|
||||
int horizontal;
|
||||
int vertical;
|
||||
int between;
|
||||
} borders = {};
|
||||
int horizontal = 0;
|
||||
int vertical = 0;
|
||||
int between = 0;
|
||||
} borders{};
|
||||
|
||||
SendMessage(hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
|
||||
|
||||
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
|
||||
const auto style = ::GetWindowLongPtr(hWnd, GWL_STYLE);
|
||||
bool isSizeGrip = style & SBARS_SIZEGRIP;
|
||||
|
||||
PAINTSTRUCT ps;
|
||||
PAINTSTRUCT ps{};
|
||||
HDC hdc = BeginPaint(hWnd, &ps);
|
||||
|
||||
auto holdPen = static_cast<HPEN>(::SelectObject(hdc, NppDarkMode::getEdgePen()));
|
||||
|
||||
HFONT holdFont = (HFONT)::SelectObject(hdc, NppParameters::getInstance().getDefaultUIFont());
|
||||
auto holdFont = static_cast<HFONT>(::SelectObject(hdc, pStatusBarInfo->_hFont));
|
||||
|
||||
RECT rcClient;
|
||||
RECT rcClient{};
|
||||
GetClientRect(hWnd, &rcClient);
|
||||
|
||||
FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush());
|
||||
|
@ -133,9 +152,9 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
std::wstring str;
|
||||
for (int i = 0; i < nParts; ++i)
|
||||
{
|
||||
RECT rcPart = {};
|
||||
RECT rcPart{};
|
||||
SendMessage(hWnd, SB_GETRECT, i, (LPARAM)&rcPart);
|
||||
RECT rcIntersect = {};
|
||||
RECT rcIntersect{};
|
||||
if (!IntersectRect(&rcIntersect, &rcPart, &ps.rcPaint))
|
||||
{
|
||||
continue;
|
||||
|
@ -200,7 +219,7 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
if (isSizeGrip)
|
||||
{
|
||||
pStatusBarInfo->ensureTheme(hWnd);
|
||||
SIZE gripSize = {};
|
||||
SIZE gripSize{};
|
||||
GetThemePartSize(pStatusBarInfo->hTheme, hdc, SP_GRIPPER, 0, &rcClient, TS_DRAW, &gripSize);
|
||||
RECT rc = rcClient;
|
||||
rc.left = rc.right - gripSize.cx;
|
||||
|
@ -212,16 +231,22 @@ LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
::SelectObject(hdc, holdPen);
|
||||
|
||||
EndPaint(hWnd, &ps);
|
||||
return FALSE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_NCDESTROY:
|
||||
RemoveWindowSubclass(hWnd, StatusBarSubclass, g_statusBarSubclassID);
|
||||
{
|
||||
::RemoveWindowSubclass(hWnd, StatusBarSubclass, uIdSubclass);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_THEMECHANGED:
|
||||
{
|
||||
pStatusBarInfo->closeTheme();
|
||||
LOGFONT lf{ NppParameters::getDefaultGUIFont(NppParameters::DefaultFontType::status) };
|
||||
pStatusBarInfo->setFont(::CreateFontIndirect(&lf));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
@ -244,7 +269,8 @@ void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts)
|
|||
if (!_hSelf)
|
||||
throw std::runtime_error("StatusBar::init : CreateWindowEx() function return null");
|
||||
|
||||
StatusBarSubclassInfo* pStatusBarInfo = new StatusBarSubclassInfo();
|
||||
LOGFONT lf{ NppParameters::getDefaultGUIFont(NppParameters::DefaultFontType::status) };
|
||||
StatusBarSubclassInfo* pStatusBarInfo = new StatusBarSubclassInfo(::CreateFontIndirect(&lf));
|
||||
_pStatusBarInfo = pStatusBarInfo;
|
||||
|
||||
SetWindowSubclass(_hSelf, StatusBarSubclass, g_statusBarSubclassID, reinterpret_cast<DWORD_PTR>(pStatusBarInfo));
|
||||
|
@ -257,7 +283,7 @@ void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts)
|
|||
if (_partWidthArray.size())
|
||||
_lpParts = new int[_partWidthArray.size()];
|
||||
|
||||
RECT rc;
|
||||
RECT rc{};
|
||||
::GetClientRect(_hParent, &rc);
|
||||
adjustParts(rc.right);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue