Skip to content

Commit

Permalink
fix graph automatic theme switching
Browse files Browse the repository at this point in the history
  • Loading branch information
DartVanya committed Dec 12, 2024
1 parent 69e87b9 commit dfd11b5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
2 changes: 1 addition & 1 deletion SystemInformer/chdlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ INT_PTR CALLBACK PhChooseNewPageDlgProc(

if (PhEnableThemeSupport)
{
SetDCBrushColor(hdc, RGB(50, 50, 50));
SetDCBrushColor(hdc, PhMakeColorBrighter(PhThemeWindowBackgroundColor, 7)); // RGB(50, 50, 50)
FillRect(hdc, &clientRect, PhGetStockBrush(DC_BRUSH));
clientRect.bottom = clientRect.top + 1;
SetDCBrushColor(hdc, PhThemeWindowForegroundColor);
Expand Down
3 changes: 3 additions & 0 deletions SystemInformer/mainwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ static NTSTATUS PhMwpReInitializeThemeThread(

PhEnableThemeAcrylicWindowSupport = PhEnableThemeAcrylicWindowSupport && PhEnableThemeSupport && PhIsThemeTransparencyEnabled();

PhSetIntegerSetting(L"GraphColorMode", PhEnableThemeSupport); // HACK switch to dark theme. (dmex)
PhCsGraphColorMode = PhGetIntegerSetting(L"GraphColorMode");

PhReInitializeTheme(PhEnableThemeSupport);

PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackSettingsUpdated), NULL);
Expand Down
11 changes: 6 additions & 5 deletions SystemInformer/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,12 @@ static VOID PhpOptionsNotifyChangeCallback(

if (PhEnableThemeSupport != oldTheme || PhEnableThemeAcrylicWindowSupport != oldAcrylicWindowSupport)
{
if (PhEnableThemeSupport != oldTheme)
{
PhSetIntegerSetting(L"GraphColorMode", PhEnableThemeSupport); // HACK switch to dark theme. (dmex)
PhCsGraphColorMode = PhGetIntegerSetting(L"GraphColorMode");
}

PhReInitializeTheme(PhEnableThemeSupport);
}

Expand Down Expand Up @@ -1735,11 +1741,6 @@ static VOID PhpAdvancedPageSave(
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_PROPAGATE_CPU_USAGE, L"PropagateCpuUsage");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_SHOW_ADVANCED_OPTIONS, L"EnableAdvancedOptions");

if (PhEnableThemeSupport)
{
PhSetIntegerSetting(L"GraphColorMode", 1); // HACK switch to dark theme. (dmex)
}

WriteCurrentUserRun(
ListView_GetCheckState(listViewHandle, PHP_OPTIONS_INDEX_START_ATLOGON) == BST_CHECKED,
ListView_GetCheckState(listViewHandle, PHP_OPTIONS_INDEX_START_HIDDEN) == BST_CHECKED
Expand Down
3 changes: 2 additions & 1 deletion phlib/colorbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ UINT_PTR CALLBACK PhpColorBoxDlgHookProc(

PhCenterWindow(hwndDlg, GetParent(hwndDlg));

PhInitializeWindowThemeEx(hwndDlg, !!context->EnableThemeSupport);
if (context->EnableThemeSupport)
PhInitializeWindowThemeEx(hwndDlg, TRUE);
}
break;
case WM_CTLCOLORBTN:
Expand Down
14 changes: 7 additions & 7 deletions phlib/delayhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -1850,15 +1850,15 @@ HRESULT CALLBACK ThemeTaskDialogCallbackHook(
{
HRESULT result = S_OK;

PTASKDIALOG_CALLBACK_WRAP CallbackData = (PTASKDIALOG_CALLBACK_WRAP)dwRefData;
PTASKDIALOG_CALLBACK_WRAP callbackData = (PTASKDIALOG_CALLBACK_WRAP)dwRefData;

if (uMsg == TDN_DIALOG_CONSTRUCTED) // Called on each new page, including the first one.
{
PhInitializeTaskDialogTheme(hwndDlg, hwndDlg);
}

if (CallbackData->pfCallback)
result = CallbackData->pfCallback(hwndDlg, uMsg, wParam, lParam, CallbackData->lpCallbackData);
if (callbackData->pfCallback)
result = callbackData->pfCallback(hwndDlg, uMsg, wParam, lParam, callbackData->lpCallbackData);

return result;
}
Expand All @@ -1871,12 +1871,12 @@ HRESULT WINAPI PhTaskDialogIndirectHook(
_Out_opt_ BOOL* pfVerificationFlagChecked
)
{
TASKDIALOG_CALLBACK_WRAP CallbackData;
CallbackData.pfCallback = pTaskConfig->pfCallback;
CallbackData.lpCallbackData = pTaskConfig->lpCallbackData;
TASKDIALOG_CALLBACK_WRAP callbackData;
callbackData.pfCallback = pTaskConfig->pfCallback;
callbackData.lpCallbackData = pTaskConfig->lpCallbackData;
TASKDIALOGCONFIG myConfig = *pTaskConfig;
myConfig.pfCallback = ThemeTaskDialogCallbackHook;
myConfig.lpCallbackData = (LONG_PTR)&CallbackData;
myConfig.lpCallbackData = (LONG_PTR)&callbackData;

return DefaultTaskDialogIndirect(&myConfig, pnButton, pnRadioButton, pfVerificationFlagChecked);
}
Expand Down
9 changes: 8 additions & 1 deletion phlib/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <dwmapi.h>
#include <vsstyle.h>
#include <vssym32.h>
#include <richedit.h>

typedef struct _PHP_THEME_WINDOW_TAB_CONTEXT
{
Expand Down Expand Up @@ -739,8 +740,14 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows(

SetWindowPos(WindowHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);

#define EM_SETBKGNDCOLOR (WM_USER + 67)
CHARFORMAT cf = { sizeof(CHARFORMAT) };
cf.dwMask = CFM_COLOR;
cf.dwEffects = enableThemeSupport ? 0 : CFE_AUTOCOLOR;
if (enableThemeSupport) cf.crTextColor = PhThemeWindowTextColor;

SendMessage(WindowHandle, EM_SETBKGNDCOLOR, 0, enableThemeSupport ? PhMakeColorBrighter(PhThemeWindowForegroundColor, 2) : GetSysColor(COLOR_WINDOW)); // RGB(30, 30, 30)
SendMessage(WindowHandle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);

PhWindowThemeSetDarkMode(WindowHandle, enableThemeSupport);
}
else if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE))
Expand Down
9 changes: 5 additions & 4 deletions plugins/ExtendedTools/objprp.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ typedef enum _ET_OBJECT_POOLTYPE {
#define OBJECT_CHILD_HANDLEPROP_WINDOW 1
#define OBJECT_CORRECT_HANDLES_COUNT(real_count) ((ULONG)(real_count) - 1)

#define OBJECT_HANDLES_CONTEXT_TAG (ULONG)'OBJH'
typedef struct _ET_GENERAL_PAGE_CONTEXT
{
WNDPROC OldWndProc;
Expand All @@ -287,7 +288,7 @@ LRESULT CALLBACK EtpGeneralPageWindowSubclassProc(
{
PET_GENERAL_PAGE_CONTEXT context;

if (!(context = PhGetWindowContext(hWnd, 'OBJH')))
if (!(context = PhGetWindowContext(hWnd, OBJECT_HANDLES_CONTEXT_TAG)))
return FALSE;

WNDPROC oldWndProc = context->OldWndProc;
Expand All @@ -303,7 +304,7 @@ LRESULT CALLBACK EtpGeneralPageWindowSubclassProc(
else if (uMsg == WM_NCDESTROY)
{
PhSetWindowProcedure(hWnd, oldWndProc);
PhRemoveWindowContext(hWnd, 'OBJH');
PhRemoveWindowContext(hWnd, OBJECT_HANDLES_CONTEXT_TAG);
PhFree(context);
}

Expand All @@ -312,7 +313,7 @@ LRESULT CALLBACK EtpGeneralPageWindowSubclassProc(

VOID EtHandlePropertiesWindowInitialized(
_In_ PVOID Parameter
)
)
{
static INT EtListViewRowCache[OBJECT_GENERAL_INDEX_MAXIMUM];

Expand Down Expand Up @@ -340,7 +341,7 @@ VOID EtHandlePropertiesWindowInitialized(
PET_GENERAL_PAGE_CONTEXT pageContext = PhAllocateZero(sizeof(ET_GENERAL_PAGE_CONTEXT));
pageContext->OldWndProc = PhGetWindowProcedure(generalPage);
pageContext->ParentWindow = context->ParentWindow;
PhSetWindowContext(generalPage, 'OBJH', pageContext);
PhSetWindowContext(generalPage, OBJECT_HANDLES_CONTEXT_TAG, pageContext);
PhSetWindowProcedure(generalPage, EtpGeneralPageWindowSubclassProc);

EtObjectManagerShowHandlesPage = FALSE;
Expand Down
21 changes: 0 additions & 21 deletions plugins/NetworkTools/whois.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@ VOID RichEditSetText(
_In_ PWSTR Text
)
{
if (PhIsThemeSupportEnabled())
{
CHARFORMAT cf;

memset(&cf, 0, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;

switch (PhGetIntegerSetting(L"GraphColorMode"))
{
case 0: // New colors
cf.crTextColor = RGB(0x0, 0x0, 0x0);
break;
case 1: // Old colors
cf.crTextColor = RGB(0xff, 0xff, 0xff);
break;
}

SendMessage(RichEditHandle, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf);
}

SetFocus(RichEditHandle);
SendMessage(RichEditHandle, WM_SETREDRAW, FALSE, 0);
SendMessage(RichEditHandle, EM_SETSEL, 0, -1); // -2
Expand Down

0 comments on commit dfd11b5

Please sign in to comment.