From 38e574345701c2a8ddf353b59cb1f3b18c19b727 Mon Sep 17 00:00:00 2001 From: wj32 Date: Tue, 15 Nov 2011 09:58:33 +0000 Subject: [PATCH] show less text in panel if it overflows git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4858 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- 2.x/trunk/ProcessHacker/include/phapp.h | 1 + 2.x/trunk/ProcessHacker/sdk/phapppub.h | 1 + 2.x/trunk/ProcessHacker/sysinfo.c | 23 ++++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/2.x/trunk/ProcessHacker/include/phapp.h b/2.x/trunk/ProcessHacker/include/phapp.h index fa486bf25..e94df1025 100644 --- a/2.x/trunk/ProcessHacker/include/phapp.h +++ b/2.x/trunk/ProcessHacker/include/phapp.h @@ -815,6 +815,7 @@ typedef struct _PH_SYSINFO_DRAW_PANEL // Parameters for default draw PPH_STRING Title; PPH_STRING SubTitle; + PPH_STRING SubTitleOverflow; } PH_SYSINFO_DRAW_PANEL, *PPH_SYSINFO_DRAW_PANEL; typedef struct _PH_SYSINFO_SECTION diff --git a/2.x/trunk/ProcessHacker/sdk/phapppub.h b/2.x/trunk/ProcessHacker/sdk/phapppub.h index 7bc48c74e..387f8e2c5 100644 --- a/2.x/trunk/ProcessHacker/sdk/phapppub.h +++ b/2.x/trunk/ProcessHacker/sdk/phapppub.h @@ -828,6 +828,7 @@ typedef struct _PH_SYSINFO_DRAW_PANEL // Parameters for default draw PPH_STRING Title; PPH_STRING SubTitle; + PPH_STRING SubTitleOverflow; } PH_SYSINFO_DRAW_PANEL, *PPH_SYSINFO_DRAW_PANEL; typedef struct _PH_SYSINFO_SECTION diff --git a/2.x/trunk/ProcessHacker/sysinfo.c b/2.x/trunk/ProcessHacker/sysinfo.c index 5645894df..eeb748488 100644 --- a/2.x/trunk/ProcessHacker/sysinfo.c +++ b/2.x/trunk/ProcessHacker/sysinfo.c @@ -1128,6 +1128,7 @@ VOID PhSipDrawPanel( sysInfoDrawPanel.Title = NULL; sysInfoDrawPanel.SubTitle = NULL; + sysInfoDrawPanel.SubTitleOverflow = NULL; Section->Callback(Section, SysInfoGraphDrawPanel, &sysInfoDrawPanel, NULL); @@ -1252,9 +1253,24 @@ VOID PhSipDefaultDrawPanel( if (DrawPanel->SubTitle) { + RECT measureRect; + rect.top += CurrentParameters.MediumFontHeight + PH_SYSINFO_PANEL_PADDING; SelectObject(hdc, CurrentParameters.Font); - DrawText(hdc, DrawPanel->SubTitle->Buffer, DrawPanel->SubTitle->Length / 2, &rect, flags); + + measureRect = rect; + DrawText(hdc, DrawPanel->SubTitle->Buffer, DrawPanel->SubTitle->Length / 2, &measureRect, (flags & ~DT_END_ELLIPSIS) | DT_CALCRECT); + + if (measureRect.right <= rect.right || !DrawPanel->SubTitleOverflow) + { + // Text fits; draw normally. + DrawText(hdc, DrawPanel->SubTitle->Buffer, DrawPanel->SubTitle->Length / 2, &rect, flags); + } + else + { + // Text doesn't fit; draw the alternative text. + DrawText(hdc, DrawPanel->SubTitleOverflow->Buffer, DrawPanel->SubTitleOverflow->Length / 2, &rect, flags); + } } } @@ -2722,6 +2738,11 @@ BOOLEAN PhSipMemorySectionCallback( PhSipFormatSizeWithPrecision(UInt32x32To64(usedPages, PAGE_SIZE), 1)->Buffer, PhSipFormatSizeWithPrecision(UInt32x32To64(totalPages, PAGE_SIZE), 1)->Buffer ); + drawPanel->SubTitleOverflow = PhFormatString( + L"%.0f%%\n%s", + (FLOAT)usedPages * 100 / totalPages, + PhSipFormatSizeWithPrecision(UInt32x32To64(usedPages, PAGE_SIZE), 1)->Buffer + ); } return TRUE; }