From 3b2b3ac8e0d6544cc7cebb488942c87000efe6da Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sun, 6 Sep 2020 02:58:33 +0200 Subject: [PATCH] + fix: dark mode awareness fixes --- src/DarkMode/DarkMode.h | 2 + src/DarkMode/ListViewUtil.hpp | 79 ++++++++++++++++++- src/Dialogs.c | 111 +++++++++++++-------------- src/Edit.c | 9 +++ src/Styles.c | 139 +++++++++++++++++++++++++++++----- 5 files changed, 265 insertions(+), 75 deletions(-) diff --git a/src/DarkMode/DarkMode.h b/src/DarkMode/DarkMode.h index 350cb3ffa..35d60dfd2 100644 --- a/src/DarkMode/DarkMode.h +++ b/src/DarkMode/DarkMode.h @@ -5,6 +5,8 @@ extern "C" { #endif void InitListView(HWND hListView); + void InitTreeView(HWND hTreeView); + //LRESULT OwnerDrawTextItem(HWND hwnd, WPARAM wParam, LPARAM lParam); DWORD GetWindowsBuildNumber(LPDWORD major, LPDWORD minor); diff --git a/src/DarkMode/ListViewUtil.hpp b/src/DarkMode/ListViewUtil.hpp index f5c79a221..eecf333fa 100644 --- a/src/DarkMode/ListViewUtil.hpp +++ b/src/DarkMode/ListViewUtil.hpp @@ -13,7 +13,7 @@ extern "C" void InitListView(HWND hListView) if (IsDarkModeSupported()) { - SetWindowSubclass(hListView, [](HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR /*uIdSubclass*/, DWORD_PTR dwRefData) -> LRESULT { + SetWindowSubclass(hListView, [](HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR /*uIdSubclass*/, DWORD_PTR dwRefData) -> LRESULT { switch (uMsg) { case WM_NOTIFY: @@ -89,16 +89,91 @@ extern "C" void InitListView(HWND hListView) ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_HEADERDRAGDROP); // Hide focus dots - SendMessage(hListView, WM_CHANGEUISTATE, MAKELONG(UIS_SET, UISF_HIDEFOCUS), 0); + SendMessage(hListView, WM_CHANGEUISTATE, MAKEWPARAM(UIS_SET, UISF_HIDEFOCUS), 0); SetWindowTheme(hHeader, L"ItemsView", nullptr); // DarkMode SetWindowTheme(hListView, L"ItemsView", nullptr); // DarkMode } + +extern "C" void InitTreeView(HWND hTreeView) +{ + if (IsDarkModeSupported()) + { + SetWindowSubclass(hTreeView, [](HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR /*uIdSubclass*/, DWORD_PTR dwRefData) -> LRESULT { + switch (uMsg) + { + case WM_NOTIFY: + { + if (reinterpret_cast(lParam)->code == NM_CUSTOMDRAW) + { + LPNMCUSTOMDRAW nmcd = reinterpret_cast(lParam); + switch (nmcd->dwDrawStage) + { + case CDDS_PREPAINT: + return CDRF_NOTIFYITEMDRAW; + + case CDDS_ITEMPREPAINT: + { + auto info = reinterpret_cast(dwRefData); + SetTextColor(nmcd->hdc, info->headerTextColor); + } + return CDRF_DODEFAULT; + } + } + } + break; + case WM_THEMECHANGED: + { + if (IsDarkModeSupported()) + { + AllowDarkModeForWindow(hWnd, CheckDarkModeEnabled()); + + HTHEME hTheme = OpenThemeData(nullptr, L"ItemsView"); + if (hTheme) + { + COLORREF color; + if (SUCCEEDED(GetThemeColor(hTheme, 0, 0, TMT_TEXTCOLOR, &color))) + { + TreeView_SetTextColor(hWnd, color); + } + if (SUCCEEDED(GetThemeColor(hTheme, 0, 0, TMT_FILLCOLOR, &color))) + { + TreeView_SetBkColor(hWnd, color); + } + CloseThemeData(hTheme); + } + RedrawWindow(hWnd, nullptr, nullptr, RDW_FRAME | RDW_INVALIDATE); + } + } + break; + case WM_DESTROY: + { + auto info = reinterpret_cast(dwRefData); + delete info; + } + break; + } + return DefSubclassProc(hWnd, uMsg, wParam, lParam); + }, 0, reinterpret_cast(new SubclassInfo{})); + } + + TreeView_SetExtendedStyle(hTreeView, TVS_EX_AUTOHSCROLL | TVS_EX_DOUBLEBUFFER | TVS_EX_FADEINOUTEXPANDOS, 0); + + // Hide focus dots + SendMessage(hTreeView, WM_CHANGEUISTATE, MAKEWPARAM(UIS_SET, UISF_HIDEFOCUS), 0); + + SetWindowTheme(hTreeView, L"ItemsView", nullptr); // DarkMode +} + #else extern "C" void InitListView(HWND hListView) { (void)(hListView); } +extern "C" void InitTreeView(HWND hTreeView) { + (void)(hTreeView); +} + #endif diff --git a/src/Dialogs.c b/src/Dialogs.c index 5b43cbb6b..3e64cad79 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -328,8 +328,8 @@ static INT_PTR CALLBACK _InfoBoxLngDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -582,8 +582,8 @@ static INT_PTR CALLBACK CmdLineHelpProc(HWND hwnd, UINT umsg, WPARAM wParam, LPA #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -969,9 +969,9 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam // FillRect(hdc, &rc, g_hbrWndDarkBgrBrush); // } // return TRUE; - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -1211,9 +1211,9 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM l #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -1470,9 +1470,9 @@ static INT_PTR CALLBACK OpenWithDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM return TRUE; #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -1719,8 +1719,8 @@ static INT_PTR CALLBACK FavoritesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARA #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -1926,8 +1926,8 @@ static INT_PTR CALLBACK AddToFavDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPA #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -2118,7 +2118,7 @@ DWORD WINAPI FileMRUIconThread(LPVOID lpParam) { static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) { - static HWND hwndIL = NULL; + static HWND hwndLV = NULL; switch (umsg) { case WM_INITDIALOG: @@ -2143,9 +2143,9 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR } } - hwndIL = GetDlgItem(hwnd, IDC_FILEMRU); - InitWindowCommon(hwndIL, true); - InitListView(hwndIL); // DarkMode + hwndLV = GetDlgItem(hwnd, IDC_FILEMRU); + InitWindowCommon(hwndLV, true); + InitListView(hwndLV); // DarkMode SHFILEINFO shfi; ZeroMemory(&shfi, sizeof(SHFILEINFO)); @@ -2154,7 +2154,7 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR LPICONTHREADINFO lpit = (LPICONTHREADINFO)AllocMem(sizeof(ICONTHREADINFO), HEAP_ZERO_MEMORY); if (lpit) { SetProp(hwnd, L"it", (HANDLE)lpit); - lpit->hwnd = hwndIL; + lpit->hwnd = hwndLV; lpit->hThread = NULL; lpit->hExitThread = CreateEvent(NULL, true, false, NULL); lpit->hTerminatedThread = CreateEvent(NULL, true, true, NULL); @@ -2162,18 +2162,18 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR ResizeDlg_Init(hwnd, Settings.FileMRUDlgSizeX, Settings.FileMRUDlgSizeY, IDC_RESIZEGRIP); - ListView_SetImageList(hwndIL, + ListView_SetImageList(hwndLV, (HIMAGELIST)SHGetFileInfo(L"C:\\", FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO), SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES), LVSIL_SMALL); - ListView_SetImageList(hwndIL, + ListView_SetImageList(hwndLV, (HIMAGELIST)SHGetFileInfo(L"C:\\", FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO), SHGFI_LARGEICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES), LVSIL_NORMAL); - ListView_SetExtendedListViewStyle(hwndIL, /*LVS_EX_FULLROWSELECT|*/ LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP); - ListView_InsertColumn(hwndIL, 0, &lvc); + ListView_SetExtendedListViewStyle(hwndLV, /*LVS_EX_FULLROWSELECT|*/ LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP); + ListView_InsertColumn(hwndLV, 0, &lvc); // Update view SendWMCommand(hwnd, IDC_FILEMRU_UPDATE_VIEW); @@ -2235,7 +2235,7 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR hdwp = DeferCtlPos(hdwp, hwnd, IDC_PRESERVECARET, 0, dy, SWP_NOSIZE); hdwp = DeferCtlPos(hdwp, hwnd, IDC_REMEMBERSEARCHPATTERN, 0, dy, SWP_NOSIZE); EndDeferWindowPos(hdwp); - ListView_SetColumnWidth(hwndIL, 0, LVSCW_AUTOSIZE_USEHEADER); + ListView_SetColumnWidth(hwndLV, 0, LVSCW_AUTOSIZE_USEHEADER); } return TRUE; @@ -2244,9 +2244,9 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR return TRUE; #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -2271,7 +2271,7 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR AllowDarkModeForWindow(hBtn, darkModeEnabled); SendMessage(hBtn, WM_THEMECHANGED, 0, 0); } - SendMessage(hwndIL, WM_THEMECHANGED, 0, 0); + SendMessage(hwndLV, WM_THEMECHANGED, 0, 0); UpdateWindow(hwnd); } @@ -2393,14 +2393,14 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR case LVN_ITEMCHANGED: case LVN_DELETEITEM: { - UINT const cnt = ListView_GetSelectedCount(hwndIL); + UINT const cnt = ListView_GetSelectedCount(hwndLV); DialogEnableControl(hwnd, IDOK, (cnt > 0)); // can't discard current file (myself) int cur = 0; if (!MRU_FindFile(Globals.pFileMRU, Globals.CurrentFile, &cur)) { cur = -1; } - int const item = ListView_GetNextItem(hwndIL, -1, LVNI_ALL | LVNI_SELECTED); + int const item = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED); DialogEnableControl(hwnd, IDC_REMOVE, (cnt > 0) && (cur != item)); } break; @@ -2433,7 +2433,7 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR SetEvent(lpit->hTerminatedThread); lpit->hThread = NULL; - ListView_DeleteAllItems(hwndIL); + ListView_DeleteAllItems(hwndLV); LV_ITEM lvi; ZeroMemory(&lvi, sizeof(LV_ITEM)); @@ -2454,19 +2454,19 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR // SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_SETCARETINDEX,0,false); lvi.iItem = i; lvi.pszText = tch; - ListView_InsertItem(hwndIL, &lvi); + ListView_InsertItem(hwndLV, &lvi); } - UINT const cnt = ListView_GetItemCount(hwndIL); + UINT const cnt = ListView_GetItemCount(hwndLV); if (cnt > 0) { - UINT idx = ListView_GetTopIndex(hwndIL); - ListView_SetColumnWidth(hwndIL, idx, LVSCW_AUTOSIZE_USEHEADER); - ListView_SetItemState(hwndIL, ((cnt > 1) ? idx + 1 : idx), LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); + UINT idx = ListView_GetTopIndex(hwndLV); + ListView_SetColumnWidth(hwndLV, idx, LVSCW_AUTOSIZE_USEHEADER); + ListView_SetItemState(hwndLV, ((cnt > 1) ? idx + 1 : idx), LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); //int cur = 0; //if (!MRU_FindFile(Globals.pFileMRU, Globals.CurrentFile, &cur)) { cur = -1; } - //int const item = ListView_GetNextItem(hwndIL, -1, LVNI_ALL | LVNI_SELECTED); + //int const item = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED); //if ((cur == item) && (cnt > 1)) { - // ListView_SetItemState(hwndIL, idx + 1, LVIS_SELECTED, LVIS_SELECTED); + // ListView_SetItemState(hwndLV, idx + 1, LVIS_SELECTED, LVIS_SELECTED); //} } @@ -2492,16 +2492,16 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR { WCHAR tchFileName[MAX_PATH] = {L'\0'}; - if (ListView_GetSelectedCount(hwndIL)) { + if (ListView_GetSelectedCount(hwndLV)) { LV_ITEM lvi; ZeroMemory(&lvi, sizeof(LV_ITEM)); lvi.mask = LVIF_TEXT; lvi.pszText = tchFileName; lvi.cchTextMax = COUNTOF(tchFileName); - lvi.iItem = ListView_GetNextItem(hwndIL, -1, LVNI_ALL | LVNI_SELECTED); + lvi.iItem = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED); - ListView_GetItem(hwndIL, &lvi); + ListView_GetItem(hwndLV, &lvi); PathUnquoteSpaces(tchFileName); @@ -2541,7 +2541,7 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR } break; case IDC_CLEAR_LIST: - ListView_DeleteAllItems(hwndIL); + ListView_DeleteAllItems(hwndLV); MRU_Empty(Globals.pFileMRU, StrIsNotEmpty(Globals.CurrentFile)); if (Globals.bCanSaveIniFile) { MRU_Save(Globals.pFileMRU); @@ -2615,9 +2615,9 @@ static INT_PTR CALLBACK ChangeNotifyDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, return TRUE; #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -2748,8 +2748,8 @@ static INT_PTR CALLBACK ColumnWrapDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, L #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -2896,8 +2896,8 @@ static INT_PTR CALLBACK WordWrapSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wPa #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -3043,8 +3043,8 @@ static INT_PTR CALLBACK LongLineSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wPa #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -3206,9 +3206,9 @@ static INT_PTR CALLBACK TabSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPA #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -3342,6 +3342,7 @@ static INT_PTR CALLBACK SelectDefEncodingDlgProc(HWND hwnd, UINT umsg, WPARAM wP if (UseDarkMode()) { SetExplorerTheme(GetDlgItem(hwnd, IDOK)); SetExplorerTheme(GetDlgItem(hwnd, IDCANCEL)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_ENCODINGLIST)); //SetExplorerTheme(GetDlgItem(hwnd, IDC_RESIZEGRIP)); } #endif @@ -3372,7 +3373,6 @@ static INT_PTR CALLBACK SelectDefEncodingDlgProc(HWND hwnd, UINT umsg, WPARAM wP CheckDlgButton(hwnd, IDC_NOUNICODEDETECTION, SetBtn(!Settings.SkipUnicodeDetection)); CheckDlgButton(hwnd, IDC_NOANSICPDETECTION, SetBtn(!Settings.SkipANSICodePageDetection)); - CenterDlgInParent(hwnd, NULL); } return TRUE; @@ -3384,9 +3384,10 @@ static INT_PTR CALLBACK SelectDefEncodingDlgProc(HWND hwnd, UINT umsg, WPARAM wP #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORLISTBOX: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -3405,7 +3406,7 @@ static INT_PTR CALLBACK SelectDefEncodingDlgProc(HWND hwnd, UINT umsg, WPARAM wP AllowDarkModeForWindow(hwnd, darkModeEnabled); RefreshTitleBarThemeColor(hwnd); - int const buttons[] = { IDOK, IDCANCEL }; + int const buttons[] = { IDOK, IDCANCEL, IDC_ENCODINGLIST }; for (int id = 0; id < COUNTOF(buttons); ++id) { HWND const hBtn = GetDlgItem(hwnd, buttons[id]); AllowDarkModeForWindow(hBtn, darkModeEnabled); @@ -3607,9 +3608,9 @@ static INT_PTR CALLBACK SelectEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam, #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -3628,7 +3629,7 @@ static INT_PTR CALLBACK SelectEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam, AllowDarkModeForWindow(hwnd, darkModeEnabled); RefreshTitleBarThemeColor(hwnd); - int const buttons[] = { IDOK, IDCANCEL }; + int const buttons[] = { IDOK, IDCANCEL, IDC_RESIZEGRIP }; for (int id = 0; id < COUNTOF(buttons); ++id) { HWND const hBtn = GetDlgItem(hwnd, buttons[id]); AllowDarkModeForWindow(hBtn, darkModeEnabled); @@ -3816,9 +3817,9 @@ static INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wP #ifdef D_NP3_WIN10_DARK_MODE - - case WM_CTLCOLOR: + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -3946,8 +3947,8 @@ static INT_PTR CALLBACK WarnLineEndingDlgProc(HWND hwnd, UINT umsg, WPARAM wPara #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -4090,8 +4091,8 @@ static INT_PTR CALLBACK WarnIndentationDlgProc(HWND hwnd, UINT umsg, WPARAM wPar #ifdef D_NP3_WIN10_DARK_MODE - case WM_CTLCOLOR: case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); diff --git a/src/Edit.c b/src/Edit.c index 3105f7d6b..2292ebdb6 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6565,6 +6565,9 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd,UINT umsg,WPARAM wParam return hBrush; } } + if (UseDarkMode()) { + return SetDarkModeCtlColors((HDC)wParam); + } } return DefWindowProc(hwnd, umsg, wParam, lParam); @@ -7981,6 +7984,7 @@ static INT_PTR CALLBACK EditLinenumDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPA #ifdef D_NP3_WIN10_DARK_MODE case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); @@ -8204,6 +8208,7 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam #ifdef D_NP3_WIN10_DARK_MODE case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { DWORD const dwId = GetWindowLong((HWND)lParam, GWL_ID); @@ -8405,6 +8410,7 @@ static INT_PTR CALLBACK EditAlignDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARA #ifdef D_NP3_WIN10_DARK_MODE case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { @@ -8532,6 +8538,7 @@ static INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd,UINT umsg,WPARAM w #ifdef D_NP3_WIN10_DARK_MODE case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { @@ -8664,6 +8671,7 @@ static INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,L #ifdef D_NP3_WIN10_DARK_MODE case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { @@ -8917,6 +8925,7 @@ static INT_PTR CALLBACK EditSortDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM //case WM_CTLCOLORBTN:(BS_OWNERDRAW) case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { if (UseDarkMode()) { return SetDarkModeCtlColors((HDC)wParam); diff --git a/src/Styles.c b/src/Styles.c index 0cd172839..cb0a8fec0 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -34,6 +34,7 @@ #include "MuiLanguage.h" #include "Notepad3.h" #include "Config/Config.h" +#include "DarkMode/DarkMode.h" #include "SciCall.h" @@ -4030,6 +4031,24 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); SetDialogIconNP3(hwnd); + InitWindowCommon(hwnd, true); + +#ifdef D_NP3_WIN10_DARK_MODE + if (UseDarkMode()) { + SetExplorerTheme(GetDlgItem(hwnd, IDOK)); + SetExplorerTheme(GetDlgItem(hwnd, IDCANCEL)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_STYLEFORE)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_STYLEBACK)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_STYLEFONT)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_PREVIEW)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_STYLEDEFAULT)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_PREVSTYLE)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_NEXTSTYLE)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_IMPORT)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_EXPORT)); + //SetExplorerTheme(GetDlgItem(hwnd, IDC_RESIZEGRIP)); + } +#endif DPI_T const dpi = Scintilla_GetWindowDPI(hwnd); GetLngString(IDS_MUI_STYLEEDIT_HELP, tchTmpBuffer, COUNTOF(tchTmpBuffer)); @@ -4056,6 +4075,8 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar ZeroMemory(&shfi, sizeof(SHFILEINFO)); InitWindowCommon(hwndTV, true); + InitTreeView(hwndTV); + TreeView_SetExtendedStyle(hwndTV, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER); UINT const flagIconSize = (dpi.y >= LargeIconDPI()) ? SHGFI_LARGEICON : SHGFI_SMALLICON; @@ -4200,6 +4221,41 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar } return 0; +#ifdef D_NP3_WIN10_DARK_MODE + + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: { + if (UseDarkMode()) { + return SetDarkModeCtlColors((HDC)wParam); + } + } break; + + case WM_SETTINGCHANGE: + if (IsDarkModeSupported() && IsColorSchemeChangeMessage(lParam)) { + SendMessage(hwnd, WM_THEMECHANGED, 0, 0); + } + break; + + case WM_THEMECHANGED: + if (IsDarkModeSupported()) { + bool const darkModeEnabled = CheckDarkModeEnabled(); + AllowDarkModeForWindow(hwnd, darkModeEnabled); + RefreshTitleBarThemeColor(hwnd); + int const buttons[] = { IDOK, IDCANCEL, IDC_STYLEFORE, IDC_STYLEBACK, IDC_STYLEFONT, IDC_PREVIEW, + IDC_STYLEDEFAULT, IDC_PREVSTYLE, IDC_NEXTSTYLE, IDC_IMPORT, IDC_EXPORT }; + for (int id = 0; id < COUNTOF(buttons); ++id) { + HWND const hBtn = GetDlgItem(hwnd, buttons[id]); + AllowDarkModeForWindow(hBtn, darkModeEnabled); + SendMessage(hBtn, WM_THEMECHANGED, 0, 0); + } + SendMessage(hwndTV, WM_THEMECHANGED, 0, 0); + + UpdateWindow(hwnd); + } + break; +#endif + case WM_ENABLE: // modal child dialog should disable main window too EnableWindow(Globals.hwndMain, (BOOL)wParam); @@ -4758,7 +4814,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR static int cxClient = 0; static int cyClient = 0; - static HWND hwndIL = NULL; + static HWND hwndLV = NULL; static int iInternalDefault = 0; @@ -4769,47 +4825,58 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); SetDialogIconNP3(hwnd); + InitWindowCommon(hwnd, true); + +#ifdef D_NP3_WIN10_DARK_MODE + if (UseDarkMode()) { + SetExplorerTheme(GetDlgItem(hwnd, IDOK)); + SetExplorerTheme(GetDlgItem(hwnd, IDCANCEL)); + //SetExplorerTheme(GetDlgItem(hwnd, IDC_RESIZEGRIP)); + } +#endif + DPI_T const dpi = Scintilla_GetWindowDPI(hwnd); - hwndIL = GetDlgItem(hwnd,IDC_STYLELIST); - InitWindowCommon(hwndIL, false); + hwndLV = GetDlgItem(hwnd,IDC_STYLELIST); + InitWindowCommon(hwndLV, true); + InitListView(hwndLV); SHFILEINFO shfi; ZeroMemory(&shfi, sizeof(SHFILEINFO)); UINT const flagIconSize = (dpi.y >= LargeIconDPI()) ? SHGFI_LARGEICON : SHGFI_SMALLICON; - ListView_SetImageList(hwndIL, + ListView_SetImageList(hwndLV, (HIMAGELIST)SHGetFileInfo(L"C:\\",FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO), flagIconSize | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES), LVSIL_SMALL); - ListView_SetImageList(hwndIL, + ListView_SetImageList(hwndLV, (HIMAGELIST)SHGetFileInfo(L"C:\\",FILE_ATTRIBUTE_DIRECTORY, &shfi,sizeof(SHFILEINFO), SHGFI_LARGEICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES), LVSIL_NORMAL); LVCOLUMN lvc = { LVCF_FMT | LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 }; - ListView_SetExtendedListViewStyle(hwndIL,/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP); - ListView_InsertColumn(hwndIL,0,&lvc); + ListView_SetExtendedListViewStyle(hwndLV,/*LVS_EX_FULLROWSELECT|*/LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP); + ListView_InsertColumn(hwndLV,0,&lvc); // Add lexers for (int i = 0; i < COUNTOF(g_pLexArray); i++) { - Style_AddLexerToListView(hwndIL, g_pLexArray[i]); + Style_AddLexerToListView(hwndLV, g_pLexArray[i]); } - ListView_SetColumnWidth(hwndIL,0,LVSCW_AUTOSIZE_USEHEADER); + ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER); // Select current lexer - int lvItems = ListView_GetItemCount(hwndIL); + int lvItems = ListView_GetItemCount(hwndLV); LVITEM lvi; lvi.mask = LVIF_PARAM; for (int i = 0; i < lvItems; i++) { lvi.iItem = i; - ListView_GetItem(hwndIL,&lvi); + ListView_GetItem(hwndLV,&lvi); if (((PEDITLEXER)lvi.lParam)->resID == _s_selectedLexer->resID) { - ListView_SetItemState(hwndIL,i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); - ListView_EnsureVisible(hwndIL,i,false); + ListView_SetItemState(hwndLV,i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); + ListView_EnsureVisible(hwndLV,i,false); CheckDlgButton(hwnd, IDC_DEFAULTSCHEME, SetBtn(_s_idefaultLexer == i)); break; } @@ -4834,7 +4901,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR SHFILEINFO shfi; ZeroMemory(&shfi, sizeof(SHFILEINFO)); UINT const flagIconSize = (dpi.y >= LargeIconDPI()) ? SHGFI_LARGEICON : SHGFI_SMALLICON; - ListView_SetImageList(hwndIL, + ListView_SetImageList(hwndLV, (HIMAGELIST)SHGetFileInfo(L"C:\\", FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO), flagIconSize | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES), LVSIL_SMALL); @@ -4857,6 +4924,42 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR return !0; +#ifdef D_NP3_WIN10_DARK_MODE + + case WM_CTLCOLORDLG: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: { + if (UseDarkMode()) { + return SetDarkModeCtlColors((HDC)wParam); + } + } break; + + case WM_SETTINGCHANGE: + if (IsDarkModeSupported() && IsColorSchemeChangeMessage(lParam)) { + SendMessage(hwnd, WM_THEMECHANGED, 0, 0); + } + break; + + case WM_THEMECHANGED: + if (IsDarkModeSupported()) { + bool const darkModeEnabled = CheckDarkModeEnabled(); + AllowDarkModeForWindow(hwnd, darkModeEnabled); + RefreshTitleBarThemeColor(hwnd); + int const buttons[] = { IDOK, IDCANCEL }; + for (int id = 0; id < COUNTOF(buttons); ++id) { + HWND const hBtn = GetDlgItem(hwnd, buttons[id]); + AllowDarkModeForWindow(hBtn, darkModeEnabled); + SendMessage(hBtn, WM_THEMECHANGED, 0, 0); + } + SendMessage(hwndLV, WM_THEMECHANGED, 0, 0); + + UpdateWindow(hwnd); + } + break; + +#endif + + case WM_NOTIFY: { if (((LPNMHDR)(lParam))->idFrom == IDC_STYLELIST) { @@ -4870,7 +4973,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR case LVN_ITEMCHANGED: case LVN_DELETEITEM: { - int i = ListView_GetNextItem(hwndIL, -1, LVNI_ALL | LVNI_SELECTED); + int i = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED); CheckDlgButton(hwnd, IDC_DEFAULTSCHEME, SetBtn(iInternalDefault == i)); DialogEnableControl(hwnd, IDC_DEFAULTSCHEME, i != -1); DialogEnableControl(hwnd, IDOK, i != -1); @@ -4888,7 +4991,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR { case IDC_DEFAULTSCHEME: if (IsButtonChecked(hwnd, IDC_DEFAULTSCHEME)) - iInternalDefault = ListView_GetNextItem(hwndIL, -1, LVNI_ALL | LVNI_SELECTED); + iInternalDefault = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED); else iInternalDefault = 0; break; @@ -4898,8 +5001,8 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR { LVITEM lvi; lvi.mask = LVIF_PARAM; - lvi.iItem = ListView_GetNextItem(hwndIL, -1, LVNI_ALL | LVNI_SELECTED); - if (ListView_GetItem(hwndIL, &lvi)) { + lvi.iItem = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED); + if (ListView_GetItem(hwndLV, &lvi)) { _s_selectedLexer = (PEDITLEXER)lvi.lParam; _s_idefaultLexer = iInternalDefault; s_bAutoSelect = IsButtonChecked(hwnd, IDC_AUTOSELECT);