Skip to content

Commit 9def7a6

Browse files
committed
ToolStatus: Fix statusbar height when using custom fonts
1 parent f3ddf06 commit 9def7a6

File tree

3 files changed

+66
-59
lines changed

3 files changed

+66
-59
lines changed

plugins/ToolStatus/main.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ VOID NTAPI LayoutPaddingCallback(
507507
// Adjust the PH client area and exclude the StatusBar width.
508508
layoutPadding->Padding.bottom += statusBarRect.bottom;
509509

510-
InvalidateRect(StatusBarHandle, NULL, TRUE);
510+
//InvalidateRect(StatusBarHandle, NULL, TRUE);
511511
}
512512
}
513513

@@ -1275,31 +1275,33 @@ LRESULT CALLBACK MainWndSubclassProc(
12751275
break;
12761276
case WM_PH_UPDATE_FONT:
12771277
{
1278-
HFONT newFont;
1279-
12801278
// Let Process Hacker perform the default processing.
12811279
CallWindowProc(MainWindowHookProc, hWnd, uMsg, wParam, lParam);
12821280

1283-
if (newFont = ProcessHacker_GetFont())
1284-
{
1285-
if (ToolbarWindowFont) DeleteFont(ToolbarWindowFont);
1286-
ToolbarWindowFont = newFont;
1281+
ToolbarWindowFont = ProcessHacker_GetFont();
1282+
SetWindowFont(ToolBarHandle, ToolbarWindowFont, TRUE);
1283+
SetWindowFont(StatusBarHandle, ToolbarWindowFont, TRUE);
12871284

1288-
SetWindowFont(ToolBarHandle, ToolbarWindowFont, TRUE);
1289-
SetWindowFont(StatusBarHandle, ToolbarWindowFont, TRUE);
1285+
{
1286+
//ULONG toolbarButtonSize = (ULONG)SendMessage(ToolBarHandle, TB_GETBUTTONSIZE, 0, 0);
1287+
LONG toolbarButtonHeight = ToolStatusGetWindowFontSize(ToolBarHandle, ToolbarWindowFont);
1288+
toolbarButtonHeight = __max(22, toolbarButtonHeight); // 22/default toolbar button height
12901289

1291-
{
1292-
//ULONG toolbarButtonSize = (ULONG)SendMessage(ToolBarHandle, TB_GETBUTTONSIZE, 0, 0);
1293-
LONG toolbarButtonHeight = ToolbarGetFontSize();
1294-
toolbarButtonHeight = __max(22, toolbarButtonHeight); // 22/default toolbar button height
1290+
RebarAdjustBandHeightLayout(toolbarButtonHeight);
1291+
SendMessage(ToolBarHandle, TB_SETBUTTONSIZE, 0, MAKELPARAM(0, toolbarButtonHeight));
1292+
}
12951293

1296-
RebarAdjustBandHeightLayout(toolbarButtonHeight);
1297-
SendMessage(ToolBarHandle, TB_SETBUTTONSIZE, 0, MAKELPARAM(0, toolbarButtonHeight));
1298-
}
1294+
{
1295+
LONG statusbarButtonHeight = ToolStatusGetWindowFontSize(StatusBarHandle, ToolbarWindowFont);
1296+
statusbarButtonHeight = __max(23, statusbarButtonHeight); // 23/default statusbar height
12991297

1300-
ToolbarLoadSettings();
1298+
SendMessage(StatusBarHandle, SB_SETMINHEIGHT, statusbarButtonHeight, 0);
1299+
//SendMessage(StatusBarHandle, WM_SIZE, 0, 0); // redraw
1300+
StatusBarUpdate(TRUE);
13011301
}
13021302

1303+
ToolbarLoadSettings();
1304+
13031305
goto DefaultWndProc;
13041306
}
13051307
break;

plugins/ToolStatus/toolbar.c

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,13 @@ VOID RebarLoadSettings(
108108
VOID
109109
)
110110
{
111+
ToolbarWindowFont = ProcessHacker_GetFont();
112+
111113
if (ToolStatusConfig.ToolBarEnabled && !ToolBarImageList)
112114
{
113115
ToolBarImageSize.cx = GetSystemMetrics(SM_CXSMICON);
114116
ToolBarImageSize.cy = GetSystemMetrics(SM_CYSMICON);
115117
ToolBarImageList = PhImageListCreate(ToolBarImageSize.cx, ToolBarImageSize.cy, ILC_MASK | ILC_COLOR32, 0, 0);
116-
117-
HFONT newFont;
118-
119-
if (newFont = ProcessHacker_GetFont())
120-
{
121-
if (ToolbarWindowFont) DeleteFont(ToolbarWindowFont);
122-
ToolbarWindowFont = newFont;
123-
}
124118
}
125119

126120
if (ToolStatusConfig.ToolBarEnabled && !RebarHandle)
@@ -169,7 +163,7 @@ VOID RebarLoadSettings(
169163
// determine the font size and adjust the toolbar height.
170164
{
171165
ULONG toolbarButtonSize = (ULONG)SendMessage(ToolBarHandle, TB_GETBUTTONSIZE, 0, 0);
172-
LONG toolbarButtonHeight = ToolbarGetFontSize();
166+
LONG toolbarButtonHeight = ToolStatusGetWindowFontSize(ToolBarHandle, ToolbarWindowFont);
173167

174168
RebarBandInsert(REBAR_BAND_ID_TOOLBAR, ToolBarHandle, LOWORD(toolbarButtonSize), __max(HIWORD(toolbarButtonSize), toolbarButtonHeight));
175169

@@ -225,6 +219,19 @@ VOID RebarLoadSettings(
225219
// Configure the statusbar font.
226220
SetWindowFont(StatusBarHandle, ToolbarWindowFont, FALSE);
227221

222+
// Determine the font size and adjust the statusbar height.
223+
{
224+
LONG height = ToolStatusGetWindowFontSize(StatusBarHandle, ToolbarWindowFont);
225+
RECT statusBarRect;
226+
227+
GetClientRect(StatusBarHandle, &statusBarRect);
228+
229+
if (statusBarRect.bottom < height)
230+
{
231+
SendMessage(StatusBarHandle, SB_SETMINHEIGHT, height, 0);
232+
}
233+
}
234+
228235
if (StatusBarHandle && PhGetIntegerSetting(L"EnableThemeSupport"))
229236
{
230237
PhInitializeWindowThemeStatusBar(StatusBarHandle);
@@ -458,31 +465,6 @@ PWSTR ToolbarGetText(
458465
return L"ERROR";
459466
}
460467

461-
LONG ToolbarGetFontSize(
462-
VOID
463-
)
464-
{
465-
LONG height = 0;
466-
TEXTMETRIC textMetrics;
467-
HDC hdc;
468-
469-
if (hdc = GetDC(ToolBarHandle))
470-
{
471-
SelectFont(hdc, ToolbarWindowFont);
472-
GetTextMetrics(hdc, &textMetrics);
473-
474-
// Below we try to match the height as calculated by the toolbar, even if it
475-
// involves magic numbers. On Vista and above there seems to be extra padding.
476-
477-
height = textMetrics.tmHeight;
478-
ReleaseDC(ToolBarHandle, hdc);
479-
}
480-
481-
height += 5; // Add magic padding
482-
483-
return height;
484-
}
485-
486468
HBITMAP ToolbarLoadImageFromIcon(
487469
_In_ ULONG Width,
488470
_In_ ULONG Height,
@@ -968,3 +950,29 @@ VOID RebarAdjustBandHeightLayout(
968950
SendMessage(RebarHandle, RB_SETBANDINFO, index, (LPARAM)&rebarBandInfo);
969951
}
970952
}
953+
954+
LONG ToolStatusGetWindowFontSize(
955+
_In_ HWND WindowHandle,
956+
_In_ HFONT WindowFont
957+
)
958+
{
959+
LONG height = 0;
960+
TEXTMETRIC textMetrics;
961+
HDC hdc;
962+
963+
if (hdc = GetDC(WindowHandle))
964+
{
965+
SelectFont(hdc, WindowFont);
966+
GetTextMetrics(hdc, &textMetrics);
967+
968+
// Below we try to match the height as calculated by the toolbar, even if it
969+
// involves magic numbers. On Vista and above there seems to be extra padding.
970+
971+
height = textMetrics.tmHeight;
972+
ReleaseDC(WindowHandle, hdc);
973+
}
974+
975+
height += 5; // Add magic padding
976+
977+
return height;
978+
}

plugins/ToolStatus/toolstatus.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ PWSTR ToolbarGetText(
184184
_In_ INT CommandID
185185
);
186186

187-
LONG ToolbarGetFontSize(
188-
VOID
189-
);
190-
191187
HBITMAP ToolbarGetImage(
192188
_In_ INT CommandID
193189
);
@@ -212,16 +208,17 @@ VOID RebarAdjustBandHeightLayout(
212208
_In_ LONG Height
213209
);
214210

211+
LONG ToolStatusGetWindowFontSize(
212+
_In_ HWND WindowHandle,
213+
_In_ HFONT WindowFont
214+
);
215+
215216
// main.c
216217

217218
HWND GetCurrentTreeNewHandle(
218219
VOID
219220
);
220221

221-
HFONT ToolStatusGetTreeWindowFont(
222-
VOID
223-
);
224-
225222
VOID ShowCustomizeMenu(
226223
_In_ HWND WindowHandle
227224
);

0 commit comments

Comments
 (0)