Add initial dark mode support for Shortcut Mapper

- Partially implement #11530.
- Minor tweaks for drawAutocompleteColoursFromTheme to avoid double calling.

Close #11531
This commit is contained in:
ozone10 2022-04-13 08:41:53 +02:00 committed by Don Ho
parent d656c19de0
commit 2dbc25f918
8 changed files with 103 additions and 57 deletions

View File

@ -369,7 +369,13 @@ LRESULT Notepad_plus::init(HWND hwnd)
drawTabbarColoursFromStylerArray(); drawTabbarColoursFromStylerArray();
// Autocomplete list and calltip // Autocomplete list and calltip
drawAutocompleteColoursFromTheme(); const Style* pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT);
if (pStyle)
{
NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor);
NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor);
drawAutocompleteColoursFromTheme(pStyle->_fgColor, pStyle->_bgColor);
}
AutoCompletion::drawAutocomplete(_pEditView); AutoCompletion::drawAutocomplete(_pEditView);
AutoCompletion::drawAutocomplete(_pNonEditView); AutoCompletion::drawAutocomplete(_pNonEditView);
@ -5832,40 +5838,33 @@ void Notepad_plus::drawTabbarColoursFromStylerArray()
TabBarPlus::setColour(stInact->_bgColor, TabBarPlus::inactiveBg); TabBarPlus::setColour(stInact->_bgColor, TabBarPlus::inactiveBg);
} }
void Notepad_plus::drawAutocompleteColoursFromTheme() void Notepad_plus::drawAutocompleteColoursFromTheme(COLORREF fgColor, COLORREF bgColor)
{ {
// Update default fg/bg colors in Parameters for both internal/plugins docking dialog int rbv = GetRValue(bgColor);
const Style* pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT); int gbv = GetGValue(bgColor);
if (pStyle) int bbv = GetBValue(bgColor);
{
NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor);
NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor);
int rbv = GetRValue(pStyle->_bgColor); int rfv = GetRValue(fgColor);
int gbv = GetGValue(pStyle->_bgColor); int gfv = GetGValue(fgColor);
int bbv = GetBValue(pStyle->_bgColor); int bfv = GetBValue(fgColor);
int rfv = GetRValue(pStyle->_fgColor); COLORREF bgDarker = RGB(rbv - 20 <= 0 ? 0 : rbv - 20, gbv - 20 <= 0 ? 0 : gbv - 20, bbv - 20 <= 0 ? 0 : bbv - 20);
int gfv = GetGValue(pStyle->_fgColor);
int bfv = GetBValue(pStyle->_fgColor);
COLORREF bgDarker = RGB(rbv - 20 <= 0 ? 0 : rbv - 20, gbv - 20 <= 0 ? 0 : gbv - 20, bbv - 20 <= 0 ? 0 : bbv - 20); if (bgColor == RGB(0, 0, 0)) // if the bg is pure black
bgDarker = RGB(20, 20, 20); // make bgDarker lighter for distinguishing between both
if (pStyle->_bgColor == RGB(0, 0, 0)) // if the bg is pure black COLORREF fgDarker = RGB(rfv - 20 <= 0 ? 0 : rfv - 20, gfv - 20 <= 0 ? 0 : gfv - 20, bfv - 20 <= 0 ? 0 : bfv - 20);
bgDarker = RGB(20, 20, 20); // make bgDarker lighter for distinguishing between both COLORREF fgLigher = RGB(rfv + 20 >= 255 ? 255 : rfv + 20, gfv + 20 >= 255 ? 255 : gfv + 20, bfv + 20 >= 255 ? 255 : bfv + 20);
COLORREF fgDarker = RGB(rfv - 20 <= 0 ? 0 : rfv - 20, gfv - 20 <= 0 ? 0 : gfv - 20, bfv - 20 <= 0 ? 0 : bfv - 20); AutoCompletion::setColour(bgDarker, AutoCompletion::AutocompleteColorIndex::autocompleteBg);
COLORREF fgLigher = RGB(rfv + 20 >= 255 ? 255 : rfv + 20, gfv + 20 >= 255 ? 255 : gfv + 20, bfv + 20 >= 255 ? 255 : bfv + 20); AutoCompletion::setColour(bgColor, AutoCompletion::AutocompleteColorIndex::selectedBg);
AutoCompletion::setColour(fgDarker, AutoCompletion::AutocompleteColorIndex::autocompleteText);
AutoCompletion::setColour(fgColor, AutoCompletion::AutocompleteColorIndex::selectedText);
AutoCompletion::setColour(bgDarker, AutoCompletion::AutocompleteColorIndex::autocompleteBg); AutoCompletion::setColour(bgDarker, AutoCompletion::AutocompleteColorIndex::calltipBg);
AutoCompletion::setColour(pStyle->_bgColor, AutoCompletion::AutocompleteColorIndex::selectedBg); AutoCompletion::setColour(fgDarker, AutoCompletion::AutocompleteColorIndex::calltipText);
AutoCompletion::setColour(fgDarker, AutoCompletion::AutocompleteColorIndex::autocompleteText); AutoCompletion::setColour(fgLigher, AutoCompletion::AutocompleteColorIndex::calltipHighlight);
AutoCompletion::setColour(pStyle->_fgColor, AutoCompletion::AutocompleteColorIndex::selectedText);
AutoCompletion::setColour(bgDarker, AutoCompletion::AutocompleteColorIndex::calltipBg);
AutoCompletion::setColour(fgDarker, AutoCompletion::AutocompleteColorIndex::calltipText);
AutoCompletion::setColour(fgLigher, AutoCompletion::AutocompleteColorIndex::calltipHighlight);
}
} }
void Notepad_plus::drawDocumentMapColoursFromStylerArray() void Notepad_plus::drawDocumentMapColoursFromStylerArray()

View File

@ -585,7 +585,7 @@ private:
Style * getStyleFromName(const TCHAR *styleName); Style * getStyleFromName(const TCHAR *styleName);
bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func
void drawTabbarColoursFromStylerArray(); void drawTabbarColoursFromStylerArray();
void drawAutocompleteColoursFromTheme(); void drawAutocompleteColoursFromTheme(COLORREF fgColor, COLORREF bgColor);
void drawDocumentMapColoursFromStylerArray(); void drawDocumentMapColoursFromStylerArray();
std::vector<generic_string> loadCommandlineParams(const TCHAR * commandLine, const CmdLineParams * pCmdParams) { std::vector<generic_string> loadCommandlineParams(const TCHAR * commandLine, const CmdLineParams * pCmdParams) {

View File

@ -1869,18 +1869,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
drawDocumentMapColoursFromStylerArray(); drawDocumentMapColoursFromStylerArray();
drawAutocompleteColoursFromTheme();
AutoCompletion::drawAutocomplete(_pEditView);
AutoCompletion::drawAutocomplete(_pNonEditView);
// Update default fg/bg colors in Parameters for both internal/plugins docking dialog // Update default fg/bg colors in Parameters for both internal/plugins docking dialog
const Style * pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT); const Style* pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT);
if (pStyle) if (pStyle)
{ {
NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor); NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor);
NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor); NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor);
drawAutocompleteColoursFromTheme(pStyle->_fgColor, pStyle->_bgColor);
} }
AutoCompletion::drawAutocomplete(_pEditView);
AutoCompletion::drawAutocomplete(_pNonEditView);
NppDarkMode::calculateTreeViewStyle(); NppDarkMode::calculateTreeViewStyle();
auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE); auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE);

View File

@ -1698,7 +1698,7 @@ namespace NppDarkMode
} }
} }
BOOL getAutocompleHandleProc(HWND hwnd, LPARAM /*lParam*/) BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM /*lParam*/)
{ {
constexpr size_t classNameLen = 16; constexpr size_t classNameLen = 16;
TCHAR className[classNameLen]{}; TCHAR className[classNameLen]{};
@ -1707,7 +1707,7 @@ namespace NppDarkMode
(wcscmp(className, WC_LISTBOX) == 0)) (wcscmp(className, WC_LISTBOX) == 0))
{ {
NppDarkMode::setDarkScrollBar(hwnd); NppDarkMode::setDarkScrollBar(hwnd);
::EnumChildWindows(hwnd, (WNDENUMPROC)getAutocompleHandleProc, 0); ::EnumChildWindows(hwnd, (WNDENUMPROC)enumAutocompleteProc, 0);
} }
return TRUE; return TRUE;
@ -1716,11 +1716,16 @@ namespace NppDarkMode
// set dark scrollbar for autocomplete list // set dark scrollbar for autocomplete list
void setDarkAutoCompletion() void setDarkAutoCompletion()
{ {
::EnumThreadWindows(::GetCurrentThreadId(), (WNDENUMPROC)getAutocompleHandleProc, 0); ::EnumThreadWindows(::GetCurrentThreadId(), (WNDENUMPROC)enumAutocompleteProc, 0);
} }
LRESULT onCtlColor(HDC hdc) LRESULT onCtlColor(HDC hdc)
{ {
if (!NppDarkMode::isEnabled())
{
return FALSE;
}
::SetTextColor(hdc, NppDarkMode::getTextColor()); ::SetTextColor(hdc, NppDarkMode::getTextColor());
::SetBkColor(hdc, NppDarkMode::getBackgroundColor()); ::SetBkColor(hdc, NppDarkMode::getBackgroundColor());
return reinterpret_cast<LRESULT>(NppDarkMode::getBackgroundBrush()); return reinterpret_cast<LRESULT>(NppDarkMode::getBackgroundBrush());
@ -1728,6 +1733,11 @@ namespace NppDarkMode
LRESULT onCtlColorSofter(HDC hdc) LRESULT onCtlColorSofter(HDC hdc)
{ {
if (!NppDarkMode::isEnabled())
{
return FALSE;
}
::SetTextColor(hdc, NppDarkMode::getTextColor()); ::SetTextColor(hdc, NppDarkMode::getTextColor());
::SetBkColor(hdc, NppDarkMode::getSofterBackgroundColor()); ::SetBkColor(hdc, NppDarkMode::getSofterBackgroundColor());
return reinterpret_cast<LRESULT>(NppDarkMode::getSofterBackgroundBrush()); return reinterpret_cast<LRESULT>(NppDarkMode::getSofterBackgroundBrush());
@ -1735,6 +1745,11 @@ namespace NppDarkMode
LRESULT onCtlColorDarker(HDC hdc) LRESULT onCtlColorDarker(HDC hdc)
{ {
if (!NppDarkMode::isEnabled())
{
return FALSE;
}
::SetTextColor(hdc, NppDarkMode::getTextColor()); ::SetTextColor(hdc, NppDarkMode::getTextColor());
::SetBkColor(hdc, NppDarkMode::getDarkerBackgroundColor()); ::SetBkColor(hdc, NppDarkMode::getDarkerBackgroundColor());
return reinterpret_cast<LRESULT>(NppDarkMode::getDarkerBackgroundBrush()); return reinterpret_cast<LRESULT>(NppDarkMode::getDarkerBackgroundBrush());
@ -1742,6 +1757,11 @@ namespace NppDarkMode
LRESULT onCtlColorError(HDC hdc) LRESULT onCtlColorError(HDC hdc)
{ {
if (!NppDarkMode::isEnabled())
{
return FALSE;
}
::SetTextColor(hdc, NppDarkMode::getTextColor()); ::SetTextColor(hdc, NppDarkMode::getTextColor());
::SetBkColor(hdc, NppDarkMode::getErrorBackgroundColor()); ::SetBkColor(hdc, NppDarkMode::getErrorBackgroundColor());
return reinterpret_cast<LRESULT>(NppDarkMode::getErrorBackgroundBrush()); return reinterpret_cast<LRESULT>(NppDarkMode::getErrorBackgroundBrush());
@ -1749,19 +1769,14 @@ namespace NppDarkMode
LRESULT onCtlColorDarkerBGStaticText(HDC hdc, bool isTextEnabled) LRESULT onCtlColorDarkerBGStaticText(HDC hdc, bool isTextEnabled)
{ {
LRESULT result = FALSE; if (!NppDarkMode::isEnabled())
if (NppDarkMode::isEnabled())
{
::SetTextColor(hdc, isTextEnabled ? NppDarkMode::getTextColor() : NppDarkMode::getDisabledTextColor());
::SetBkColor(hdc, NppDarkMode::getDarkerBackgroundColor());
result = reinterpret_cast<LRESULT>(NppDarkMode::getDarkerBackgroundBrush());
}
else
{ {
::SetTextColor(hdc, ::GetSysColor(isTextEnabled ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT)); ::SetTextColor(hdc, ::GetSysColor(isTextEnabled ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT));
return FALSE;
} }
return result; ::SetTextColor(hdc, isTextEnabled ? NppDarkMode::getTextColor() : NppDarkMode::getDisabledTextColor());
::SetBkColor(hdc, NppDarkMode::getDarkerBackgroundColor());
return reinterpret_cast<LRESULT>(NppDarkMode::getDarkerBackgroundBrush());
} }
} }

View File

@ -165,7 +165,7 @@ namespace NppDarkMode
void setTreeViewStyle(HWND hwnd); void setTreeViewStyle(HWND hwnd);
void setBorder(HWND hwnd, bool border = true); void setBorder(HWND hwnd, bool border = true);
BOOL getAutocompleHandleProc(HWND hwnd, LPARAM lParam); BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM lParam);
void setDarkAutoCompletion(); void setDarkAutoCompletion();
LRESULT onCtlColor(HDC hdc); LRESULT onCtlColor(HDC hdc);

View File

@ -28,10 +28,10 @@ void BabyGridWrapper::init(HINSTANCE hInst, HWND parent, int16_t id)
if (!_isRegistered) if (!_isRegistered)
RegisterGridClass(_hInst); RegisterGridClass(_hInst);
_hSelf = ::CreateWindowEx(WS_EX_CLIENTEDGE, _hSelf = ::CreateWindowEx(0,
babyGridClassName,\ babyGridClassName,\
TEXT(""),\ TEXT(""),\
WS_CHILD | WS_VISIBLE | WS_TABSTOP,\ WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,\
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,\ CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,\
_hParent,\ _hParent,\
reinterpret_cast<HMENU>(id), \ reinterpret_cast<HMENU>(id), \

View File

@ -24,6 +24,7 @@ using namespace std;
void ShortcutMapper::initTabs() void ShortcutMapper::initTabs()
{ {
HWND hTab = _hTabCtrl = ::GetDlgItem(_hSelf, IDC_BABYGRID_TABBAR); HWND hTab = _hTabCtrl = ::GetDlgItem(_hSelf, IDC_BABYGRID_TABBAR);
NppDarkMode::subclassTabControl(hTab);
TCITEM tie; TCITEM tie;
tie.mask = TCIF_TEXT; tie.mask = TCIF_TEXT;
@ -121,6 +122,8 @@ void ShortcutMapper::initBabyGrid()
_babygrid.init(_hInst, _hSelf, IDD_BABYGRID_ID1); _babygrid.init(_hInst, _hSelf, IDD_BABYGRID_ID1);
NppDarkMode::setDarkScrollBar(_babygrid.getHSelf());
_babygrid.setHeaderFont(_hGridFonts.at(GFONT_HEADER)); _babygrid.setHeaderFont(_hGridFonts.at(GFONT_HEADER));
_babygrid.setRowFont(_hGridFonts.at(GFONT_ROWS)); _babygrid.setRowFont(_hGridFonts.at(GFONT_ROWS));
@ -422,6 +425,8 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
_babygrid.display(); _babygrid.display();
goToCenter(); goToCenter();
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
RECT rect; RECT rect;
Window::getClientRect(rect); Window::getClientRect(rect);
_clientWidth = rect.right - rect.left; _clientWidth = rect.right - rect.left;
@ -435,6 +440,33 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
return TRUE; return TRUE;
} }
case WM_CTLCOLOREDIT:
{
return NppDarkMode::onCtlColorSofter(reinterpret_cast<HDC>(wParam));
}
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
{
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam));
}
case WM_PRINTCLIENT:
{
if (NppDarkMode::isEnabled())
{
return TRUE;
}
break;
}
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::autoThemeChildControls(_hSelf);
return TRUE;
}
case WM_GETMINMAXINFO : case WM_GETMINMAXINFO :
{ {
MINMAXINFO* mmi = (MINMAXINFO*)lParam; MINMAXINFO* mmi = (MINMAXINFO*)lParam;

View File

@ -29,11 +29,11 @@ CAPTION "Shortcut mapper"
FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1
BEGIN BEGIN
CONTROL "",IDC_BABYGRID_TABBAR,"SysTabControl32",WS_TABSTOP,4,6,384,12 CONTROL "",IDC_BABYGRID_TABBAR,"SysTabControl32",WS_TABSTOP,4,6,384,12
EDITTEXT IDC_BABYGRID_INFO, 4, 281, 440, 29, ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP EDITTEXT IDC_BABYGRID_INFO,3,281,443,29,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP
RTEXT "Filter :", IDC_BABYGRID_STATIC, 4, 313, 25, 12 RTEXT "Filter :", IDC_BABYGRID_STATIC,4,313,25,12
EDITTEXT IDC_BABYGRID_FILTER, 30, 312, 415, 12, ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER, WS_EX_STATICEDGE EDITTEXT IDC_BABYGRID_FILTER,31,312,415,12,ES_AUTOHSCROLL | ES_WANTRETURN
DEFPUSHBUTTON "Modify",IDM_BABYGRID_MODIFY,118,330,47,14 PUSHBUTTON "Modify",IDM_BABYGRID_MODIFY,118,330,47,14
DEFPUSHBUTTON "Clear",IDM_BABYGRID_CLEAR,172,330,47,14 PUSHBUTTON "Clear",IDM_BABYGRID_CLEAR,172,330,47,14
DEFPUSHBUTTON "Delete",IDM_BABYGRID_DELETE,226,330,47,14 PUSHBUTTON "Delete",IDM_BABYGRID_DELETE,226,330,47,14
DEFPUSHBUTTON "Close",IDOK,280,330,47,14 DEFPUSHBUTTON "Close",IDOK,280,330,47,14
END END