From 467870d66e0f4e3151cfeb9d93c0522d058f7eb0 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Mon, 7 Jun 2021 19:47:24 +0200 Subject: [PATCH] Add DarkMode Tooltips Fix #9962, close #9963 --- PowerEditor/src/MISC/Common/Common.cpp | 2 + PowerEditor/src/NppDarkMode.cpp | 37 ++++++++++++++++++- PowerEditor/src/NppDarkMode.h | 11 +++++- .../WinControls/FileBrowser/fileBrowser.cpp | 3 ++ .../FunctionList/functionListPanel.cpp | 2 + PowerEditor/src/WinControls/TabBar/TabBar.cpp | 3 ++ .../src/WinControls/ToolBar/ToolBar.cpp | 3 ++ .../src/WinControls/ToolTip/ToolTip.cpp | 3 ++ .../src/WinControls/TreeView/TreeView.cpp | 2 + .../VerticalFileSwitcherListView.cpp | 2 + 10 files changed, 66 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index f72deb52e..2c46bd7d7 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -997,6 +997,8 @@ HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText) return NULL; } + NppDarkMode::setDarkTooltips(hwndTip, NppDarkMode::ToolTipsType::tooltip); + // Associate the tooltip with the tool. TOOLINFO toolInfo = { 0 }; toolInfo.cbSize = sizeof(toolInfo); diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index f220fdbef..01abe6763 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -1038,5 +1038,40 @@ namespace NppDarkMode { autoSubclassAndThemeChildControls(hwndParent, false, true); } -} + void setDarkTooltips(HWND hwnd, ToolTipsType type) + { + if (NppDarkMode::isEnabled()) + { + int msg = NULL; + switch (type) + { + case NppDarkMode::ToolTipsType::toolbar: + msg = TB_GETTOOLTIPS; + break; + case NppDarkMode::ToolTipsType::listview: + msg = LVM_GETTOOLTIPS; + break; + case NppDarkMode::ToolTipsType::treeview: + msg = TVM_GETTOOLTIPS; + break; + default: + msg = NULL; + break; + } + + if (!msg) + { + SetWindowTheme(hwnd, L"DarkMode_Explorer", NULL); + } + else + { + auto hTips = reinterpret_cast(SendMessage(hwnd, msg, NULL, NULL)); + if (hTips != nullptr) + { + SetWindowTheme(hTips, L"DarkMode_Explorer", NULL); + } + } + } + } +} diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index 7a63d675e..588428703 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -20,6 +20,14 @@ namespace NppDarkMode bool enableMenubar = false; bool enableScrollbarHack = false; }; + + enum class ToolTipsType + { + tooltip, + toolbar, + listview, + treeview + }; void initDarkMode(); // pulls options from NppParameters void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent @@ -73,5 +81,6 @@ namespace NppDarkMode void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass = true, bool theme = true); void autoThemeChildControls(HWND hwndParent); -} + void setDarkTooltips(HWND hwnd, ToolTipsType type); +} diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 7516f86d7..81b70eb85 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -105,6 +105,9 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP NppParameters& nppParam = NppParameters::getInstance(); int style = WS_CHILD | WS_VISIBLE | CCS_ADJUSTABLE | TBSTYLE_AUTOSIZE | TBSTYLE_FLAT | TBSTYLE_LIST | TBSTYLE_TRANSPARENT | BTNS_AUTOSIZE | BTNS_SEP | TBSTYLE_TOOLTIPS | TBSTYLE_CUSTOMERASE; _hToolbarMenu = CreateWindowEx(WS_EX_LAYOUTRTL, TOOLBARCLASSNAME, NULL, style, 0, 0, 0, 0, _hSelf, nullptr, _hInst, NULL); + + NppDarkMode::setDarkTooltips(_hToolbarMenu, NppDarkMode::ToolTipsType::toolbar); + TBBUTTON tbButtons[3]; // Add the bmap image into toolbar's imagelist TBADDBITMAP addbmp = { _hInst, 0 }; diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 42fbf13c0..d43643c81 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -771,6 +771,8 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA _hToolbarMenu = CreateWindowEx(0,TOOLBARCLASSNAME,NULL, style, 0,0,0,0,_hSelf,nullptr, _hInst, NULL); + NppDarkMode::setDarkTooltips(_hToolbarMenu, NppDarkMode::ToolTipsType::toolbar); + oldFunclstToolbarProc = reinterpret_cast(::SetWindowLongPtr(_hToolbarMenu, GWLP_WNDPROC, reinterpret_cast(funclstToolbarProc))); TBBUTTON tbButtons[3]; diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index c30021e4c..e198bf97d 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -303,6 +303,9 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult { throw std::runtime_error("TabBarPlus::init : tooltip CreateWindowEx() function return null"); } + + NppDarkMode::setDarkTooltips(_tooltips, NppDarkMode::ToolTipsType::tooltip); + ::SendMessage(_hSelf, TCM_SETTOOLTIPS, reinterpret_cast(_tooltips), 0); if (!_hwndArray[_nbCtrl]) diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index 1ee437709..85a92791d 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -284,6 +284,9 @@ void ToolBar::reset(bool create) NULL, _hInst, 0); + + NppDarkMode::setDarkTooltips(_hSelf, NppDarkMode::ToolTipsType::toolbar); + // Send the TB_BUTTONSTRUCTSIZE message, which is required for // backward compatibility. ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); diff --git a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp index b7251aee1..0b33262ac 100644 --- a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp +++ b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp @@ -18,6 +18,7 @@ #include #include #include "ToolTip.h" +#include "NppDarkMode.h" void ToolTip::init(HINSTANCE hInst, HWND hParent) { @@ -32,6 +33,8 @@ void ToolTip::init(HINSTANCE hInst, HWND hParent) throw std::runtime_error("ToolTip::init : CreateWindowEx() function return null"); } + NppDarkMode::setDarkTooltips(_hSelf, NppDarkMode::ToolTipsType::tooltip); + ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast(this)); _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticWinProc))); } diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.cpp b/PowerEditor/src/WinControls/TreeView/TreeView.cpp index eb1cce9f3..6e1d87471 100644 --- a/PowerEditor/src/WinControls/TreeView/TreeView.cpp +++ b/PowerEditor/src/WinControls/TreeView/TreeView.cpp @@ -37,6 +37,8 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID) _hInst, (LPVOID)0); + NppDarkMode::setDarkTooltips(_hSelf, NppDarkMode::ToolTipsType::treeview); + int itemHeight = NppParameters::getInstance()._dpiManager.scaleY(CY_ITEMHEIGHT); TreeView_SetItemHeight(_hSelf, itemHeight); diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp index f51642152..237304c1f 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp @@ -55,6 +55,8 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST throw std::runtime_error("VerticalFileSwitcherListView::init : CreateWindowEx() function return null"); } + NppDarkMode::setDarkTooltips(_hSelf, NppDarkMode::ToolTipsType::listview); + ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast(this)); _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticProc)));