Skip to content

Commit

Permalink
Theme fixes and enhancements
Browse files Browse the repository at this point in the history
- Advanced options menu Reset added
  • Loading branch information
DartVanya committed Oct 7, 2024
1 parent aad7eda commit 881c3bf
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 78 deletions.
19 changes: 18 additions & 1 deletion SystemInformer/chdlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ INT_PTR CALLBACK PhChooseNewPageDlgProc(
}

PhSetDialogFocus(WindowHandle, context->ComboBoxHandle);

if (PhEnableThemeSupport)
DestroyWindow(GetDlgItem(WindowHandle, IDC_SIZE_));
PhInitializeWindowTheme(WindowHandle, PhEnableThemeSupport);
}
break;
case WM_DESTROY:
Expand Down Expand Up @@ -560,7 +564,20 @@ INT_PTR CALLBACK PhChooseNewPageDlgProc(

clientRect.top = clientRect.bottom;
clientRect.bottom = clientRect.top + PhGetDpi(50, dpi);
FillRect(hdc, &clientRect, PhEnableThemeSupport ? PhThemeWindowBackgroundBrush : GetSysColorBrush(COLOR_3DFACE));

if (PhEnableThemeSupport)
{
SetDCBrushColor(hdc, RGB(50, 50, 50));
FillRect(hdc, &clientRect, GetStockObject(DC_BRUSH));
clientRect.bottom = clientRect.top + PhGetDpi(2, dpi);
InflateRect(&clientRect, -1, 0);
SetDCBrushColor(hdc, RGB(36, 36, 36));
FillRect(hdc, &clientRect, GetStockObject(DC_BRUSH));
}
else
{
FillRect(hdc, &clientRect, GetSysColorBrush(COLOR_3DFACE));
}

SetWindowLongPtr(WindowHandle, DWLP_MSGRESULT, TRUE);
}
Expand Down
35 changes: 25 additions & 10 deletions SystemInformer/delayhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,34 @@ LRESULT CALLBACK PhStaticWindowHookProcedure(
PAINTSTRUCT ps;
HDC hdc;
HICON iconHandle;
RECT clientRect;

if (!PhGetWindowContext(WindowHandle, SCHAR_MAX))
break;

if (iconHandle = (HICON)(UINT_PTR)CallWindowProc(PhDefaultStaticWindowProcedure, WindowHandle, STM_GETICON, 0, 0)) // Static_GetIcon(WindowHandle, 0)
{
if (hdc = BeginPaint(WindowHandle, &ps))
if (BeginPaint(WindowHandle, &ps))
{
FillRect(hdc, &ps.rcPaint, PhThemeWindowBackgroundBrush);
// Fix artefacts when window moving back from off-screen (Dart Vanya)
hdc = GetDC(WindowHandle);
GetClientRect(WindowHandle, &clientRect);

FillRect(hdc, &clientRect, PhThemeWindowBackgroundBrush);

DrawIconEx(
hdc,
ps.rcPaint.left,
ps.rcPaint.top,
clientRect.left,
clientRect.top,
iconHandle,
ps.rcPaint.right - ps.rcPaint.left,
ps.rcPaint.bottom - ps.rcPaint.top,
clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top,
0,
NULL,
DI_NORMAL
);

ReleaseDC(WindowHandle, hdc);
EndPaint(WindowHandle, &ps);
}
}
Expand Down Expand Up @@ -378,25 +384,32 @@ VOID ThemeWindowStatusBarDrawPart(
{
SetTextColor(bufferDc, RGB(0xff, 0xff, 0xff));
SetDCBrushColor(bufferDc, PhThemeWindowHighlightColor);
blockRect.left -= 3, blockRect.top -= 1;
FillRect(bufferDc, &blockRect, PhGetStockBrush(DC_BRUSH));
//FrameRect(bufferDc, &blockRect, GetSysColorBrush(COLOR_HIGHLIGHT));
blockRect.left += 3, blockRect.top += 1;
}
else
{
RECT separator;
SetTextColor(bufferDc, PhThemeWindowTextColor);
FillRect(bufferDc, &blockRect, PhThemeWindowBackgroundBrush);
//FrameRect(bufferDc, &blockRect, GetSysColorBrush(COLOR_HIGHLIGHT));

separator = blockRect;
separator.left = separator.right - 1;
PhInflateRect(&separator, 0, -1);
SetDCBrushColor(bufferDc, PhThemeWindowHighlightColor);
FillRect(bufferDc, &separator, PhGetStockBrush(DC_BRUSH));
}

blockRect.left += 2;
blockRect.left += 2, blockRect.bottom -= 1;
DrawText(
bufferDc,
text,
(UINT)PhCountStringZ(text),
&blockRect,
DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX
);
blockRect.left -= 2;
blockRect.left -= 2, blockRect.bottom += 1;
}

VOID ThemeWindowRenderStatusBar(
Expand Down Expand Up @@ -448,6 +461,8 @@ VOID ThemeWindowRenderStatusBar(
DrawFrameControl(bufferDc, &sizeGripRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
}

// Top statusbar border will be drawn by bottom tabcontrol border

for (INT i = 0; i < blockCount; i++)
{
ThemeWindowStatusBarDrawPart(Context, WindowHandle, bufferDc, clientRect, i);
Expand Down
26 changes: 26 additions & 0 deletions SystemInformer/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3234,6 +3234,30 @@ INT_PTR CALLBACK PhpOptionsAdvancedDlgProc(
PhDereferenceObject(text);
}
break;
case IDC_RESET:
{
PPH_OPTIONS_ADVANCED_ROOT_NODE* nodes;
ULONG numberOfNodes;
if (!GetSelectedOptionsAdvancedNodes(context, &nodes, &numberOfNodes))
break;
for (ULONG i = 0; i < numberOfNodes; i++)
{
PhSettingFromString(
nodes[i]->Setting->Type,
&nodes[i]->Setting->DefaultValue,
NULL,
PhSystemDpi,
nodes[i]->Setting
);
PhMoveReference(
&nodes[i]->ValueString,
PhSettingToString(nodes[i]->Setting->Type, nodes[i]->Setting)
);
}
TreeNew_NodesStructured(context->TreeNewHandle);
PhApplyTreeNewFilters(&context->TreeFilterSupport);
}
break;
}
}
break;
Expand All @@ -3254,6 +3278,8 @@ INT_PTR CALLBACK PhpOptionsAdvancedDlgProc(
PPH_EMENU_ITEM item;

menu = PhCreateEMenu();
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, IDC_RESET, L"&Reset", NULL, NULL), ULONG_MAX);
PhInsertEMenuItem(menu, PhCreateEMenuSeparator(), ULONG_MAX);
PhInsertEMenuItem(menu, PhCreateEMenuItem(0, IDC_COPY, L"&Copy\bCtrl+C", NULL, NULL), ULONG_MAX);
PhInsertCopyCellEMenuItem(menu, IDC_COPY, context->TreeNewHandle, contextMenuEvent->Column);

Expand Down
2 changes: 2 additions & 0 deletions SystemInformer/sessshad.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ INT_PTR CALLBACK PhpSessionShadowDlgProc(
Button_SetCheck(GetDlgItem(hwndDlg, IDC_SHIFT), hotkey.Y & KBDSHIFT);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_CTRL), hotkey.Y & KBDCTRL);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_ALT), hotkey.Y & KBDALT);

PhInitializeWindowTheme(hwndDlg, PhEnableThemeSupport);
}
break;
case WM_DESTROY:
Expand Down
18 changes: 17 additions & 1 deletion phlib/extlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,23 @@ LRESULT CALLBACK PhpExtendedListViewWndProc(
if (newFont)
SelectFont(customDraw->nmcd.hdc, newFont);

if (colorChanged)
// Fix text readability for hot and selected colored items (Dart Vanya)
BOOLEAN UseThemeTextColor = FALSE;
if (PhEnableThemeSupport)
{
LVITEM item;
item.iItem = (DWORD)customDraw->nmcd.dwItemSpec;
item.mask = LVIF_STATE;
item.stateMask = LVIS_SELECTED;
ListView_GetItem(context->Handle, &item);
UseThemeTextColor = customDraw->nmcd.uItemState & CDIS_HOT || item.state & LVIS_SELECTED;
}

if (UseThemeTextColor)
{
customDraw->clrText = PhThemeWindowTextColor;
}
else if (colorChanged)
{
if (PhGetColorBrightness(customDraw->clrTextBk) > 100) // slightly less than half
customDraw->clrText = RGB(0x00, 0x00, 0x00);
Expand Down
120 changes: 95 additions & 25 deletions phlib/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,14 @@ BOOLEAN CALLBACK PhpThemeWindowEnumChildWindows(

PhInitializeWindowThemeACLUI(WindowHandle);
}
else if (PhEqualStringZ(windowClassName, WC_EDIT, FALSE))
{
// Fix scrollbar on multiline edit (Dart Vanya)
if (GetWindowLongPtr(WindowHandle, GWL_STYLE) & ES_MULTILINE)
{
PhWindowThemeSetDarkMode(WindowHandle, TRUE);
}
}

return TRUE;
}
Expand Down Expand Up @@ -2193,7 +2201,9 @@ LRESULT CALLBACK PhpThemeWindowSubclassProc(
{
HDC hdc = (HDC)wParam;

SetBkMode(hdc, TRANSPARENT);
//SetBkMode(hdc, TRANSPARENT);
// Fix typing in multiline edit (Dart Vanya)
SetBkColor(hdc, PhThemeWindowBackground2Color);
SetTextColor(hdc, PhThemeWindowTextColor);
SetDCBrushColor(hdc, PhThemeWindowBackground2Color);
return (INT_PTR)PhGetStockBrush(DC_BRUSH);
Expand Down Expand Up @@ -2310,12 +2320,19 @@ LRESULT CALLBACK PhpThemeWindowGroupBoxSubclassProc(
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
RECT clientRect;

if (!BeginPaint(WindowHandle, &ps))
break;

ThemeWindowRenderGroupBoxControl(WindowHandle, ps.hdc, &ps.rcPaint, oldWndProc);
// Fix artefacts when window moving back from off-screen (Dart Vanya)
hdc = GetDC(WindowHandle);
GetClientRect(WindowHandle, &clientRect);

ThemeWindowRenderGroupBoxControl(WindowHandle, hdc, &clientRect, oldWndProc);

ReleaseDC(WindowHandle, hdc);
EndPaint(WindowHandle, &ps);
}
goto DefaultWndProc;
Expand Down Expand Up @@ -2392,17 +2409,44 @@ VOID ThemeWindowRenderTabControl(

INT currentSelection = TabCtrl_GetCurSel(WindowHandle);
INT count = TabCtrl_GetItemCount(WindowHandle);
RECT itemRect = { 0 };
//RECT itemRectHighlighted;
//INT itemHighlighted = INT_ERROR;
INT headerBottom;
INT oldTop;

oldTop = clientRect->top;
TabCtrl_GetItemRect(WindowHandle, 0, &itemRect);
clientRect->top += (itemRect.bottom - itemRect.top) * TabCtrl_GetRowCount(WindowHandle) + 2;

SetDCBrushColor(bufferDc, PhThemeWindowBackground2Color);
FrameRect(bufferDc, clientRect, PhGetStockBrush(DC_BRUSH));
headerBottom = clientRect->top;
clientRect->top = oldTop;

TCITEM tabItem;
WCHAR tabHeaderText[MAX_PATH] = L"";

memset(&tabItem, 0, sizeof(TCITEM));

tabItem.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE;
tabItem.dwStateMask = TCIS_BUTTONPRESSED | TCIS_HIGHLIGHTED;
tabItem.cchTextMax = RTL_NUMBER_OF(tabHeaderText);
tabItem.pszText = tabHeaderText;

for (INT i = 0; i < count; i++)
{
RECT itemRect;
if (i == currentSelection)
continue;

TabCtrl_GetItemRect(WindowHandle, i, &itemRect);

PhOffsetRect(&itemRect, 2, 2);
itemRect.bottom += itemRect.bottom + 1 < headerBottom ? 1 : -1;
itemRect.right += itemRect.right + 1 < clientRect->right;

if (PhPtInRect(&itemRect, Context->CursorPos))
{
PhOffsetRect(&itemRect, 2, 2);

//switch (PhpThemeColorMode)
//{
//case 0: // New colors
Expand All @@ -2426,12 +2470,12 @@ VOID ThemeWindowRenderTabControl(
SetDCBrushColor(bufferDc, PhThemeWindowHighlightColor);
FillRect(bufferDc, &itemRect, PhGetStockBrush(DC_BRUSH));

//FrameRect(bufferDc, &itemRect, GetSysColorBrush(COLOR_HIGHLIGHT));
//itemRectHighlighted = itemRect;
//itemHighlighted = i;
//continue;
}
else
{
PhOffsetRect(&itemRect, 2, 2);

//switch (PhpThemeColorMode)
//{
//case 0: // New colors
Expand All @@ -2451,30 +2495,16 @@ VOID ThemeWindowRenderTabControl(
// }
// break;
//case 1: // Old colors
if (currentSelection == i)
{
// SetTextColor(bufferDc, PhThemeWindowTextColor);
SetDCBrushColor(bufferDc, PhThemeWindowBackground2Color);// PhThemeWindowHighlightColor); // PhThemeWindowForegroundColor);
SetDCBrushColor(bufferDc, RGB(49, 49, 49));
FillRect(bufferDc, &itemRect, PhGetStockBrush(DC_BRUSH));
}
else
{
// SetTextColor(bufferDc, PhThemeWindowTextColor);
FillRect(bufferDc, &itemRect, PhThemeWindowBackgroundBrush);
SetDCBrushColor(bufferDc, PhThemeWindowBackground2Color);
FrameRect(bufferDc, &itemRect, PhGetStockBrush(DC_BRUSH));
}
}

{
TCITEM tabItem;
WCHAR tabHeaderText[MAX_PATH] = L"";

memset(&tabItem, 0, sizeof(TCITEM));

tabItem.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE;
tabItem.dwStateMask = TCIS_BUTTONPRESSED | TCIS_HIGHLIGHTED;
tabItem.cchTextMax = RTL_NUMBER_OF(tabHeaderText);
tabItem.pszText = tabHeaderText;

if (TabCtrl_GetItem(WindowHandle, i, &tabItem))
{
DrawText(
Expand All @@ -2487,6 +2517,46 @@ VOID ThemeWindowRenderTabControl(
}
}
}

{
TabCtrl_GetItemRect(WindowHandle, currentSelection, &itemRect);

PhOffsetRect(&itemRect, 2, 2);
itemRect.bottom += itemRect.bottom + 1 < headerBottom ? 1 : -1;
itemRect.right += itemRect.right + 1 < clientRect->right;
PhInflateRect(&itemRect, 1, 1); // draw selected tab slightly bigger
itemRect.bottom -= 1;
SetDCBrushColor(bufferDc, PhPtInRect(&itemRect, Context->CursorPos) ? PhThemeWindowHighlightColor : RGB(0x50, 0x50, 0x50));
FillRect(bufferDc, &itemRect, PhGetStockBrush(DC_BRUSH));

if (TabCtrl_GetItem(WindowHandle, currentSelection, &tabItem))
{
DrawText(
bufferDc,
tabItem.pszText,
(UINT)PhCountStringZ(tabItem.pszText),
&itemRect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX
);
}

//if (itemHighlighted != INT_ERROR)
//{
// SetDCBrushColor(bufferDc, PhThemeWindowHighlightColor);
// FillRect(bufferDc, &itemRectHighlighted, PhGetStockBrush(DC_BRUSH));

// if (TabCtrl_GetItem(WindowHandle, itemHighlighted, &tabItem))
// {
// DrawText(
// bufferDc,
// tabItem.pszText,
// (UINT)PhCountStringZ(tabItem.pszText),
// &itemRectHighlighted,
// DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX
// );
// }
//}
}
}

LRESULT CALLBACK PhpThemeWindowTabControlWndSubclassProc(
Expand Down
Loading

0 comments on commit 881c3bf

Please sign in to comment.