Allow dynamic dark/light mode change for tooltips

Fix #10059, close #10060
This commit is contained in:
ozone10 2021-06-23 17:27:44 +02:00 committed by Don Ho
parent f27e561379
commit 219cec8000
9 changed files with 41 additions and 28 deletions

View File

@ -7554,6 +7554,9 @@ void Notepad_plus::refreshDarkMode()
::SendMessage(_pFileSwitcherPanel->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
}
::SendMessage(_mainDocTab.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
::SendMessage(_subDocTab.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
SendMessage(_findReplaceDlg.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
SendMessage(_incrementFindDlg.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
RedrawWindow(_pPublicInterface->getHSelf(), nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN);

View File

@ -1044,25 +1044,16 @@ namespace NppDarkMode
bool useDark = NppDarkMode::isExperimentalEnabled() && NppDarkMode::isEnabled();
NppDarkMode::allowDarkModeForWindow(hwnd, useDark);
NppDarkMode::setTitleBarThemeColor(hwnd, useDark);
SetWindowTheme(hwnd, useDark ? L"Explorer" : nullptr, nullptr);
if (useDark)
{
SetWindowTheme(hwnd, L"Explorer", nullptr);
}
else
{
SetWindowTheme(hwnd, nullptr, nullptr);
}
NppDarkMode::setTitleBarThemeColor(hwnd, useDark);
}
void setDarkTooltips(HWND hwnd, ToolTipsType type)
{
if (NppDarkMode::isEnabled())
UINT msg = 0;
switch (type)
{
UINT msg = 0;
switch (type)
{
case NppDarkMode::ToolTipsType::toolbar:
msg = TB_GETTOOLTIPS;
break;
@ -1072,22 +1063,24 @@ namespace NppDarkMode
case NppDarkMode::ToolTipsType::treeview:
msg = TVM_GETTOOLTIPS;
break;
case NppDarkMode::ToolTipsType::tabbar:
msg = TCM_GETTOOLTIPS;
break;
default:
msg = 0;
break;
}
}
if (!msg)
if (msg == 0)
{
SetWindowTheme(hwnd, NppDarkMode::isEnabled() ? L"DarkMode_Explorer" : nullptr, nullptr);
}
else
{
auto hTips = reinterpret_cast<HWND>(::SendMessage(hwnd, msg, 0, 0));
if (hTips != nullptr)
{
SetWindowTheme(hwnd, L"DarkMode_Explorer", NULL);
}
else
{
auto hTips = reinterpret_cast<HWND>(SendMessage(hwnd, msg, 0, 0));
if (hTips != nullptr)
{
SetWindowTheme(hTips, L"DarkMode_Explorer", NULL);
}
SetWindowTheme(hTips, NppDarkMode::isEnabled() ? L"DarkMode_Explorer" : nullptr, nullptr);
}
}
}

View File

@ -26,7 +26,8 @@ namespace NppDarkMode
tooltip,
toolbar,
listview,
treeview
treeview,
tabbar
};
void initDarkMode(); // pulls options from NppParameters

View File

@ -878,6 +878,9 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setDarkTooltips(_shiftTrickUpTip, NppDarkMode::ToolTipsType::tooltip);
NppDarkMode::setDarkTooltips(_2ButtonsTip, NppDarkMode::ToolTipsType::tooltip);
NppDarkMode::setDarkTooltips(_filterTip, NppDarkMode::ToolTipsType::tooltip);
NppDarkMode::autoThemeChildControls(_hSelf);
return TRUE;
}

View File

@ -23,7 +23,6 @@
#include "RunDlg.h"
#include "ReadDirectoryChanges.h"
#include "menuCmdID.h"
#include "Parameters.h"
#define CX_BITMAP 16
#define CY_BITMAP 16
@ -172,8 +171,11 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setDarkTooltips(_hToolbarMenu, NppDarkMode::ToolTipsType::toolbar);
NppDarkMode::setDarkLineAbovePanelToolbar(_hToolbarMenu);
NppDarkMode::setExplorerTheme(_treeView.getHSelf(), true);
NppDarkMode::setDarkTooltips(_treeView.getHSelf(), NppDarkMode::ToolTipsType::treeview);
return TRUE;
}

View File

@ -893,8 +893,11 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setDarkTooltips(_hToolbarMenu, NppDarkMode::ToolTipsType::toolbar);
NppDarkMode::setDarkLineAbovePanelToolbar(_hToolbarMenu);
NppDarkMode::setExplorerTheme(_treeView.getHSelf(), true);
NppDarkMode::setDarkTooltips(_treeView.getHSelf(), NppDarkMode::ToolTipsType::treeview);
return TRUE;
}
@ -927,7 +930,7 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA
}
switch (LOWORD(wParam))
{
{
case IDC_SORTBUTTON_FUNCLIST:
{
sortOrUnsort();

View File

@ -100,7 +100,9 @@ INT_PTR CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setDarkLineAbovePanelToolbar(_hToolbarMenu);
NppDarkMode::setExplorerTheme(_treeView.getHSelf(), true);
NppDarkMode::setDarkTooltips(_treeView.getHSelf(), NppDarkMode::ToolTipsType::treeview);
return TRUE;
}

View File

@ -19,7 +19,6 @@
#include <stdexcept>
#include "TabBar.h"
#include "Parameters.h"
#include "NppDarkMode.h"
#define IDC_DRAG_TAB 1404
#define IDC_DRAG_INTERDIT_TAB 1405
@ -467,6 +466,12 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara
return TRUE;
}
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setDarkTooltips(hwnd, NppDarkMode::ToolTipsType::tabbar);
return TRUE;
}
case WM_MOUSEWHEEL:
{
// ..............................................................................

View File

@ -74,6 +74,7 @@ INT_PTR CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam,
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setExplorerTheme(_fileListView.getHSelf(), true);
NppDarkMode::setDarkTooltips(_fileListView.getHSelf(), NppDarkMode::ToolTipsType::listview);
return TRUE;
}