Browse Source

Enhance listview column header in dark mode

Use different approach to make listview header dark.

Close #10106
pull/10036/head
ozone10 3 years ago committed by Don Ho
parent
commit
ae56255be6
  1. 12
      PowerEditor/src/NppDarkMode.cpp
  2. 1
      PowerEditor/src/NppDarkMode.h
  3. 50
      PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp
  4. 36
      PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp
  5. 37
      PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp
  6. 49
      PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp

12
PowerEditor/src/NppDarkMode.cpp

@ -1117,6 +1117,18 @@ namespace NppDarkMode
::SendMessage(hwnd, TB_SETCOLORSCHEME, 0, reinterpret_cast<LPARAM>(&scheme));
}
void setDarkListView(HWND hwnd)
{
bool useDark = NppDarkMode::isEnabled() && NppDarkMode::isExperimentalEnabled();
HWND hHeader = ListView_GetHeader(hwnd);
NppDarkMode::allowDarkModeForWindow(hHeader, useDark);
SetWindowTheme(hHeader, L"ItemsView", nullptr);
NppDarkMode::allowDarkModeForWindow(hwnd, useDark);
SetWindowTheme(hwnd, L"Explorer", nullptr);
}
void setExplorerTheme(HWND hwnd, bool doEnable, bool isTreeView)
{
if (isTreeView)

1
PowerEditor/src/NppDarkMode.h

@ -89,6 +89,7 @@ namespace NppDarkMode
void setDarkScrollBar(HWND hwnd);
void setDarkTooltips(HWND hwnd, ToolTipsType type);
void setDarkLineAbovePanelToolbar(HWND hwnd);
void setDarkListView(HWND hwnd);
void setExplorerTheme(HWND hwnd, bool doEnable, bool isTreeView = false);
}

50
PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp

@ -54,7 +54,7 @@ void ListView::init(HINSTANCE hInst, HWND parent)
throw std::runtime_error("ListView::init : CreateWindowEx() function return null");
}
NppDarkMode::setExplorerTheme(_hSelf, true);
NppDarkMode::setDarkListView(_hSelf);
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(staticProc)));
@ -66,8 +66,7 @@ void ListView::init(HINSTANCE hInst, HWND parent)
if (_columnInfos.size())
{
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
lvColumn.fmt = HDF_OWNERDRAW;
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH;
short i = 0;
for (auto it = _columnInfos.begin(); it != _columnInfos.end(); ++it)
@ -171,30 +170,33 @@ LRESULT ListView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_DRAWITEM:
case WM_NOTIFY:
{
DRAWITEMSTRUCT* pdis = (DRAWITEMSTRUCT*)lParam;
HDITEM hdi;
TCHAR lpBuffer[256];
hdi.mask = HDI_TEXT;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
Header_GetItem(pdis->hwndItem, pdis->itemID, &hdi);
COLORREF textColor = RGB(0, 0, 0);
if (NppDarkMode::isEnabled())
textColor = NppDarkMode::getDarkerTextColor();
SetTextColor(pdis->hDC, textColor);
SetBkMode(pdis->hDC, TRANSPARENT);
switch (reinterpret_cast<LPNMHDR>(lParam)->code)
{
case NM_CUSTOMDRAW:
{
LPNMCUSTOMDRAW nmcd = reinterpret_cast<LPNMCUSTOMDRAW>(lParam);
switch (nmcd->dwDrawStage)
{
case CDDS_PREPAINT:
{
return CDRF_NOTIFYITEMDRAW;
}
::DrawText(pdis->hDC, lpBuffer, lstrlen(lpBuffer), &(pdis->rcItem), DT_SINGLELINE | DT_VCENTER | DT_CENTER);
case CDDS_ITEMPREPAINT:
{
bool isDarkModeSupported = NppDarkMode::isEnabled() && NppDarkMode::isExperimentalEnabled();
SetTextColor(nmcd->hdc, isDarkModeSupported ? NppDarkMode::getDarkerTextColor() : GetSysColor(COLOR_BTNTEXT));
return CDRF_DODEFAULT;
}
break;
}
}
break;
}
}
return TRUE;
break;
}
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}

36
PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp

@ -55,13 +55,13 @@ INT_PTR CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setExplorerTheme(_listView.getHSelf(), true);
NppDarkMode::setDarkListView(_listView.getHSelf());
return TRUE;
}
case WM_NOTIFY:
{
switch (((LPNMHDR)lParam)->code)
switch (reinterpret_cast<LPNMHDR>(lParam)->code)
{
case DMN_CLOSE:
{
@ -119,38 +119,6 @@ INT_PTR CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM
}
break;
case NM_CUSTOMDRAW:
{
static bool becomeDarkMode = false;
static bool becomeLightMode = false;
HWND hHeader = ListView_GetHeader(_listView.getHSelf());
if (NppDarkMode::isEnabled() && reinterpret_cast<LPNMHDR>(lParam)->hwndFrom == hHeader)
{
if (!becomeDarkMode)
{
NppDarkMode::setExplorerTheme(hHeader, false);
becomeDarkMode = true;
}
becomeLightMode = false;
auto nmtbcd = reinterpret_cast<LPNMTBCUSTOMDRAW>(lParam);
SetBkMode(nmtbcd->nmcd.hdc, TRANSPARENT);
FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getBackgroundBrush());
SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW);
}
else
{
if (!becomeLightMode)
{
NppDarkMode::setExplorerTheme(hHeader, true);
becomeLightMode = true;
}
becomeDarkMode = false;
SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_DODEFAULT);
}
}
break;
default:
break;
}

37
PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp

@ -73,48 +73,15 @@ INT_PTR CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam,
case NPPM_INTERNAL_REFRESHDARKMODE:
{
NppDarkMode::setExplorerTheme(_fileListView.getHSelf(), true);
NppDarkMode::setDarkListView(_fileListView.getHSelf());
NppDarkMode::setDarkTooltips(_fileListView.getHSelf(), NppDarkMode::ToolTipsType::listview);
return TRUE;
}
case WM_NOTIFY:
{
LPNMHDR notif = reinterpret_cast<LPNMHDR>(lParam);
switch (notif->code)
switch (reinterpret_cast<LPNMHDR>(lParam)->code)
{
case NM_CUSTOMDRAW:
{
static bool becomeDarkMode = false;
static bool becomeLightMode = false;
HWND hHeader = ListView_GetHeader(_fileListView.getHSelf());
if (NppDarkMode::isEnabled() && (notif->hwndFrom == hHeader))
{
if (!becomeDarkMode)
{
NppDarkMode::setExplorerTheme(hHeader, false);
becomeDarkMode = true;
}
becomeLightMode = false;
auto nmtbcd = reinterpret_cast<LPNMTBCUSTOMDRAW>(notif);
SetBkMode(nmtbcd->nmcd.hdc, TRANSPARENT);
FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getBackgroundBrush());
SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW);
}
else
{
if (!becomeLightMode)
{
NppDarkMode::setExplorerTheme(hHeader, true);
becomeLightMode = true;
}
becomeDarkMode = false;
SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_DODEFAULT);
}
}
break;
case NM_DBLCLK:
{
LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;

49
PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp

@ -55,7 +55,7 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST
throw std::runtime_error("VerticalFileSwitcherListView::init : CreateWindowEx() function return null");
}
NppDarkMode::setExplorerTheme(_hSelf, true);
NppDarkMode::setDarkListView(_hSelf);
NppDarkMode::setDarkTooltips(_hSelf, NppDarkMode::ToolTipsType::listview);
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
@ -86,29 +86,33 @@ LRESULT VerticalFileSwitcherListView::runProc(HWND hwnd, UINT Message, WPARAM wP
{
switch (Message)
{
case WM_DRAWITEM:
case WM_NOTIFY:
{
DRAWITEMSTRUCT* pdis = (DRAWITEMSTRUCT*)lParam;
HDITEM hdi;
TCHAR lpBuffer[256];
hdi.mask = HDI_TEXT;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
Header_GetItem(pdis->hwndItem, pdis->itemID, &hdi);
COLORREF textColor = RGB(0, 0, 0);
if (NppDarkMode::isEnabled())
textColor = NppDarkMode::getDarkerTextColor();
SetTextColor(pdis->hDC, textColor);
SetBkMode(pdis->hDC, TRANSPARENT);
switch (reinterpret_cast<LPNMHDR>(lParam)->code)
{
case NM_CUSTOMDRAW:
{
LPNMCUSTOMDRAW nmcd = reinterpret_cast<LPNMCUSTOMDRAW>(lParam);
switch (nmcd->dwDrawStage)
{
case CDDS_PREPAINT:
{
return CDRF_NOTIFYITEMDRAW;
}
::DrawText(pdis->hDC, lpBuffer, lstrlen(lpBuffer), &(pdis->rcItem), DT_SINGLELINE | DT_VCENTER | DT_LEFT);
case CDDS_ITEMPREPAINT:
{
bool isDarkModeSupported = NppDarkMode::isEnabled() && NppDarkMode::isExperimentalEnabled();
SetTextColor(nmcd->hdc, isDarkModeSupported ? NppDarkMode::getDarkerTextColor() : GetSysColor(COLOR_BTNTEXT));
return CDRF_DODEFAULT;
}
break;
}
}
return TRUE;
break;
}
}
break;
}
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}
@ -380,10 +384,9 @@ void VerticalFileSwitcherListView::insertColumn(const TCHAR *name, int width, in
{
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH;
lvColumn.cx = width;
lvColumn.pszText = (TCHAR *)name;
lvColumn.fmt = HDF_OWNERDRAW;
ListView_InsertColumn(_hSelf, index, &lvColumn); // index is not 0 based but 1 based
}

Loading…
Cancel
Save