[PATCH] comctl32: statusbar: WM_SETFONT should change the bar height
Mikołaj Zalewski
mikolaj at zalewski.pl
Wed Jul 16 13:21:09 CDT 2008
---
dlls/comctl32/comctl32.h | 1 +
dlls/comctl32/commctrl.c | 11 +++++++
dlls/comctl32/status.c | 69 ++++++++++++++++++++---------------------
dlls/comctl32/tests/status.c | 63 +++++++++++++++++++++++++++++++++-----
4 files changed, 101 insertions(+), 43 deletions(-)
diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h
index 51320e6..da9243f 100644
--- a/dlls/comctl32/comctl32.h
+++ b/dlls/comctl32/comctl32.h
@@ -148,6 +148,7 @@ HWND COMCTL32_CreateToolTip (HWND);
VOID COMCTL32_RefreshSysColors(void);
void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark, BOOL bHorizontal);
void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground);
+void COMCTL32_GetFontMetrics(HFONT hFont, TEXTMETRICW *ptm);
INT Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen);
INT Str_GetPtrAtoW (LPCSTR lpSrc, LPWSTR lpDest, INT nMaxLen);
BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc);
diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c
index 4ff2075..7ed4fb0 100644
--- a/dlls/comctl32/commctrl.c
+++ b/dlls/comctl32/commctrl.c
@@ -1561,6 +1561,17 @@ void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight
return;
}
+void COMCTL32_GetFontMetrics(HFONT hFont, TEXTMETRICW *ptm)
+{
+ HDC hdc = GetDC(NULL);
+ HFONT hOldFont;
+
+ hOldFont = SelectObject(hdc, hFont);
+ GetTextMetricsW(hdc, ptm);
+ SelectObject(hdc, hOldFont);
+ ReleaseDC(NULL, hdc);
+}
+
/***********************************************************************
* MirrorIcon [COMCTL32.414]
*
diff --git a/dlls/comctl32/status.c b/dlls/comctl32/status.c
index 3744280..aa18696 100644
--- a/dlls/comctl32/status.c
+++ b/dlls/comctl32/status.c
@@ -108,6 +108,35 @@ static inline LPCSTR debugstr_t(LPCWSTR text, BOOL isW)
return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
}
+static UINT
+STATUSBAR_ComputeHeight(STATUS_INFO *infoPtr)
+{
+ HTHEME theme;
+ UINT height;
+ TEXTMETRICW tm;
+
+ COMCTL32_GetFontMetrics(infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont, &tm);
+ height = tm.tmHeight + 4 + infoPtr->verticalBorder;
+
+ if ((theme = GetWindowTheme(infoPtr->Self)))
+ {
+ /* Determine bar height from theme such that the content area is
+ * textHeight pixels large */
+ HDC hdc = GetDC(infoPtr->Self);
+ RECT r;
+ memset (&r, 0, sizeof (r));
+ r.bottom = tm.tmHeight;
+ if (SUCCEEDED(GetThemeBackgroundExtent(theme, hdc, SP_PANE, 0, &r, &r)))
+ {
+ height = r.bottom - r.top;
+ }
+ ReleaseDC(infoPtr->Self, hdc);
+ }
+
+ TRACE(" textHeight=%d+%d, final height=%d\n", tm.tmHeight, tm.tmInternalLeading, height);
+ return height;
+}
+
static void
STATUSBAR_DrawSizeGrip (HTHEME theme, HDC hdc, LPRECT lpRect)
{
@@ -913,8 +942,7 @@ STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
NONCLIENTMETRICSW nclm;
DWORD dwStyle;
RECT rect;
- int len, textHeight = 0;
- HDC hdc;
+ int len;
TRACE("\n");
infoPtr = (STATUS_INFO*)Alloc (sizeof(STATUS_INFO));
@@ -971,17 +999,7 @@ STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
dwStyle &= ~WS_BORDER;
SetWindowLongW (hwnd, GWL_STYLE, dwStyle);
- if ((hdc = GetDC (hwnd))) {
- TEXTMETRICW tm;
- HFONT hOldFont;
-
- hOldFont = SelectObject (hdc, infoPtr->hDefaultFont);
- GetTextMetricsW (hdc, &tm);
- textHeight = tm.tmHeight;
- SelectObject (hdc, hOldFont);
- ReleaseDC (hwnd, hdc);
- }
- TRACE(" textHeight=%d\n", textHeight);
+ infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
if (dwStyle & SBT_TOOLTIPS) {
infoPtr->hwndToolTip =
@@ -1002,28 +1020,6 @@ STATUSBAR_WMCreate (HWND hwnd, const CREATESTRUCTA *lpCreate)
}
}
- if (!(dwStyle & CCS_NORESIZE)) { /* don't resize wnd if it doesn't want it ! */
- HTHEME theme;
- infoPtr->height = textHeight + 4 + infoPtr->verticalBorder;
-
- if ((theme = GetWindowTheme (hwnd)))
- {
- /* Determine bar height from theme such that the content area is
- * textHeight pixels large */
- HDC hdc = GetDC (hwnd);
- RECT r;
- memset (&r, 0, sizeof (r));
- r.bottom = textHeight;
- if (SUCCEEDED(GetThemeBackgroundExtent (theme, hdc, SP_PANE, 0, &r, &r)))
- {
- infoPtr->height = r.bottom - r.top;
- }
- ReleaseDC (hwnd, hdc);
- }
-
- STATUSBAR_SetPartBounds (infoPtr);
- }
-
return 0;
create_fail:
@@ -1099,6 +1095,9 @@ STATUSBAR_WMSetFont (STATUS_INFO *infoPtr, HFONT font, BOOL redraw)
{
infoPtr->hFont = font;
TRACE("%p\n", infoPtr->hFont);
+
+ infoPtr->height = STATUSBAR_ComputeHeight(infoPtr);
+ SendMessageW(infoPtr->Self, WM_SIZE, 0, 0); /* update size */
if (redraw)
InvalidateRect(infoPtr->Self, NULL, FALSE);
diff --git a/dlls/comctl32/tests/status.c b/dlls/comctl32/tests/status.c
index 18501fb..b6c5b7b 100644
--- a/dlls/comctl32/tests/status.c
+++ b/dlls/comctl32/tests/status.c
@@ -24,6 +24,8 @@
#include "wine/test.h"
+#define SUBCLASS_NAME "MyStatusBar"
+
#define expect(expected,got) ok (expected == got,"Expected %d, got %d\n",expected,got)
#define expect_rect(_left,_top,_right,_bottom,got) do { RECT _rcExp = {_left, _top, _right, _bottom}; \
ok(memcmp(&_rcExp, &(got), sizeof(RECT)) == 0, "Expected rect {%d,%d, %d,%d}, got {%d,%d, %d,%d}\n", \
@@ -34,6 +36,7 @@ static HINSTANCE hinst;
static WNDPROC g_status_wndproc;
static RECT g_rcCreated;
static HWND g_hMainWnd;
+static int g_wmsize_count = 0;
static HWND create_status_control(DWORD style, DWORD exstyle)
{
@@ -51,34 +54,46 @@ static HWND create_status_control(DWORD style, DWORD exstyle)
static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
+ LRESULT ret;
+
if (msg == WM_CREATE)
{
CREATESTRUCT *cs = (CREATESTRUCT *)lParam;
- LRESULT ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
+ ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
GetWindowRect(hwnd, &g_rcCreated);
MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
- return ret;
+ } else if (msg == WM_SIZE)
+ {
+ g_wmsize_count++;
+ ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
}
- return CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
+ else
+ ret = CallWindowProc(g_status_wndproc, hwnd, msg, wParam, lParam);
+
+ return ret;
}
-static void test_create()
+static void register_subclass()
{
WNDCLASSEX cls;
- RECT rc;
- HWND hwnd;
cls.cbSize = sizeof(WNDCLASSEX);
GetClassInfoEx(NULL, STATUSCLASSNAME, &cls);
g_status_wndproc = cls.lpfnWndProc;
cls.lpfnWndProc = create_test_wndproc;
- cls.lpszClassName = "MyStatusBar";
+ cls.lpszClassName = SUBCLASS_NAME;
cls.hInstance = NULL;
ok(RegisterClassEx(&cls), "RegisterClassEx failed\n");
+}
- ok((hwnd = CreateWindowA("MyStatusBar", "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
+static void test_create()
+{
+ RECT rc;
+ HWND hwnd;
+
+ ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
GetWindowRect(hwnd, &rc);
@@ -91,6 +106,35 @@ static void test_create()
DestroyWindow(hwnd);
}
+static void test_setfont()
+{
+ HFONT hFont;
+ RECT rc1, rc2;
+ HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
+ 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
+
+ GetClientRect(hwndStatus, &rc1);
+ hFont = CreateFont(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
+ OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
+
+ g_wmsize_count = 0;
+ SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
+ ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
+
+ GetClientRect(hwndStatus, &rc2);
+ todo_wine expect_rect(0, 0, 672, 42, rc2);
+
+ g_wmsize_count = 0;
+ SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
+ ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
+
+ GetClientRect(hwndStatus, &rc2);
+ todo_wine expect_rect(0, 0, 672, 42, rc2);
+
+ DestroyWindow(hwndStatus);
+ DeleteObject(hFont);
+}
+
static void test_status_control(void)
{
HWND hWndStatus;
@@ -246,6 +290,9 @@ START_TEST(status)
InitCommonControls();
+ register_subclass();
+
test_status_control();
test_create();
+ test_setfont();
}
--
1.5.4
--------------060301040001070502000207--
More information about the wine-patches
mailing list