Apply dark mode on treeview edit controls

- simplify code

Fix #16418, clos #16419
This commit is contained in:
ozone10 2025-04-12 16:41:51 +02:00 committed by Don Ho
parent 1657dbbc53
commit 714eeafc45
2 changed files with 44 additions and 37 deletions

View File

@ -64,43 +64,10 @@ void TreeView::destroy()
_hSelf = NULL; _hSelf = NULL;
} }
LRESULT TreeView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
if (Message == TVM_EXPAND)
{
if (wParam & (TVE_COLLAPSE | TVE_EXPAND))
{
// If TVIS_EXPANDEDONCE flag is set, TVM_EXPAND messages do not generate
// TVN_ITEMEXPANDING or TVN_ITEMEXPANDED notifications.
// To reset the flag, you must send a TVM_EXPAND message
// with the TVE_COLLAPSE and TVE_COLLAPSERESET flags set.
// That in turn removes child items which is unwanted.
// Below is a workaround for that.
TVITEM tvItem{};
tvItem.hItem = reinterpret_cast<HTREEITEM>(lParam);
tvItem.mask = TVIF_STATE | TVIF_HANDLE | TVIF_PARAM;
tvItem.stateMask = TVIS_EXPANDEDONCE;
TreeView_GetItem(_hSelf, &tvItem);
// Check if a flag is set.
if (tvItem.state & TVIS_EXPANDEDONCE)
{
// If the flag is set, then manually notify parent that an item is collapsed/expanded
// so that it can change icon, etc.
NMTREEVIEW nmtv{};
nmtv.hdr.code = TVN_ITEMEXPANDED;
nmtv.hdr.hwndFrom = _hSelf;
nmtv.hdr.idFrom = 0;
nmtv.action = (wParam & TVE_COLLAPSE) ? TVE_COLLAPSE : TVE_EXPAND;
nmtv.itemNew.hItem = tvItem.hItem;
::SendMessage(_hParent, WM_NOTIFY, nmtv.hdr.idFrom, reinterpret_cast<LPARAM>(&nmtv));
}
}
}
return ::DefSubclassProc(hwnd, Message, wParam, lParam);
}
LRESULT TreeView::staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) LRESULT TreeView::staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{ {
auto treeViewData = reinterpret_cast<TreeView*>(dwRefData);
switch (Message) switch (Message)
{ {
case WM_NCDESTROY: case WM_NCDESTROY:
@ -109,10 +76,51 @@ LRESULT TreeView::staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPar
break; break;
} }
case WM_CTLCOLOREDIT:
{
if (NppDarkMode::isEnabled())
{
return NppDarkMode::onCtlColorCtrl(reinterpret_cast<HDC>(wParam));
}
break;
}
case TVM_EXPAND:
{
if (wParam & (TVE_COLLAPSE | TVE_EXPAND))
{
// If TVIS_EXPANDEDONCE flag is set, TVM_EXPAND messages do not generate
// TVN_ITEMEXPANDING or TVN_ITEMEXPANDED notifications.
// To reset the flag, you must send a TVM_EXPAND message
// with the TVE_COLLAPSE and TVE_COLLAPSERESET flags set.
// That in turn removes child items which is unwanted.
// Below is a workaround for that.
TVITEM tvItem{};
tvItem.hItem = reinterpret_cast<HTREEITEM>(lParam);
tvItem.mask = TVIF_STATE | TVIF_HANDLE | TVIF_PARAM;
tvItem.stateMask = TVIS_EXPANDEDONCE;
TreeView_GetItem(treeViewData->_hSelf, &tvItem);
// Check if a flag is set.
if (tvItem.state & TVIS_EXPANDEDONCE)
{
// If the flag is set, then manually notify parent that an item is collapsed/expanded
// so that it can change icon, etc.
NMTREEVIEW nmtv{};
nmtv.hdr.code = TVN_ITEMEXPANDED;
nmtv.hdr.hwndFrom = treeViewData->_hSelf;
nmtv.hdr.idFrom = 0;
nmtv.action = (wParam & TVE_COLLAPSE) ? TVE_COLLAPSE : TVE_EXPAND;
nmtv.itemNew.hItem = tvItem.hItem;
::SendMessage(treeViewData->_hParent, WM_NOTIFY, nmtv.hdr.idFrom, reinterpret_cast<LPARAM>(&nmtv));
}
}
break;
}
default: default:
break; break;
} }
return reinterpret_cast<TreeView*>(dwRefData)->runProc(hwnd, Message, wParam, lParam); return ::DefSubclassProc(hwnd, Message, wParam, lParam);
} }
void TreeView::makeLabelEditable(bool toBeEnabled) void TreeView::makeLabelEditable(bool toBeEnabled)

View File

@ -123,7 +123,6 @@ public:
protected: protected:
HIMAGELIST _hImaLst = nullptr; HIMAGELIST _hImaLst = nullptr;
NppDarkMode::TreeViewStyle _tvStyleType = NppDarkMode::TreeViewStyle::classic; NppDarkMode::TreeViewStyle _tvStyleType = NppDarkMode::TreeViewStyle::classic;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData); static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);