From f240b8f49e3e986ec7f4b5aa158137b3aa19b033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Zalewski?= Date: Thu, 17 Jul 2008 17:33:08 +0200 Subject: [PATCH] comctl32: statusbar: Change the height expression to one that seems to be the same as in Windows. --- dlls/comctl32/status.c | 5 +++- dlls/comctl32/tests/status.c | 58 ++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/dlls/comctl32/status.c b/dlls/comctl32/status.c index 1b97b41bdc4..45615eb8e15 100644 --- a/dlls/comctl32/status.c +++ b/dlls/comctl32/status.c @@ -94,6 +94,7 @@ typedef struct #define HORZ_BORDER 0 #define VERT_BORDER 2 #define HORZ_GAP 2 +#define MIN_PANE_HEIGHT 18 static const WCHAR themeClass[] = { 'S','t','a','t','u','s',0 }; @@ -114,9 +115,11 @@ STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr) HTHEME theme; UINT height; TEXTMETRICW tm; + int margin; COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm); - height = tm.tmHeight + 4 + infoPtr->verticalBorder; + margin = (tm.tmInternalLeading ? tm.tmInternalLeading : 2); + height = max(tm.tmHeight + margin + 2*GetSystemMetrics(SM_CYBORDER), MIN_PANE_HEIGHT) + infoPtr->verticalBorder; if ((theme = GetWindowTheme(infoPtr->Self))) { diff --git a/dlls/comctl32/tests/status.c b/dlls/comctl32/tests/status.c index b6c5b7bcb8b..178d3ed11be 100644 --- a/dlls/comctl32/tests/status.c +++ b/dlls/comctl32/tests/status.c @@ -106,12 +106,56 @@ static void test_create() DestroyWindow(hwnd); } -static void test_setfont() +static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam) { + HWND hwndStatus = (HWND)lParam; + HDC hdc = GetDC(NULL); + static const int sizes[] = {8, 9, 10, 12, 16, 22, 28, 36, 48, 72}; + int i; + + trace("Font %s\n", enumlf->elfFullName); + for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++) + { + HFONT hFont; + TEXTMETRIC tm; + HFONT hCtrlFont; + HFONT hOldFont; + RECT rcCtrl; + + enumlf->elfLogFont.lfHeight = sizes[i]; + hFont = CreateFontIndirect(&enumlf->elfLogFont); + hCtrlFont = (HFONT)SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE); + hOldFont = SelectObject(hdc, hFont); + + GetClientRect(hwndStatus, &rcCtrl); + GetTextMetrics(hdc, &tm); + expect(max(tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4, 20), rcCtrl.bottom); + + SelectObject(hdc, hOldFont); + SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE); + DeleteObject(hFont); + } + ReleaseDC(NULL, hdc); + return 1; +} + +static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEX *enumlf, NEWTEXTMETRICEX *ntm, DWORD type, LPARAM lParam) +{ + HDC hdc = GetDC(NULL); + enumlf->elfLogFont.lfHeight = 0; + EnumFontFamiliesEx(hdc, &enumlf->elfLogFont, (FONTENUMPROC)check_height_font_enumproc, lParam, 0); + ReleaseDC(NULL, hdc); + return 1; +} + +static void test_height(void) +{ + LOGFONT lf; HFONT hFont; RECT rc1, rc2; HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE, 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL); + HDC hdc; GetClientRect(hwndStatus, &rc1); hFont = CreateFont(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, @@ -122,7 +166,7 @@ static void test_setfont() ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n"); GetClientRect(hwndStatus, &rc2); - todo_wine expect_rect(0, 0, 672, 42, rc2); + todo_wine expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */ g_wmsize_count = 0; SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE); @@ -131,6 +175,14 @@ static void test_setfont() GetClientRect(hwndStatus, &rc2); todo_wine expect_rect(0, 0, 672, 42, rc2); + /* test the height formula */ + ZeroMemory(&lf, sizeof(lf)); + SendMessage(hwndStatus, SB_SETMINHEIGHT, 0, 0); + hdc = GetDC(NULL); + trace("dpi=%d\n", GetDeviceCaps(hdc, LOGPIXELSY)); + EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)check_height_family_enumproc, (LPARAM)hwndStatus, 0); + ReleaseDC(NULL, hdc); + DestroyWindow(hwndStatus); DeleteObject(hFont); } @@ -294,5 +346,5 @@ START_TEST(status) test_status_control(); test_create(); - test_setfont(); + test_height(); }