1 /* Unit test suite for combo boxes.
3 * Copyright 2007 Mikolaj Zalewski
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_LEAN_AND_MEAN
27 #include "wine/test.h"
31 #define expect_eq(expr, value, type, fmt); { type val = expr; ok(val == (value), #expr " expected " #fmt " got " #fmt "\n", (value), val); }
32 #define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
33 r.bottom == _bottom && r.right == _right, "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", \
34 r.left, r.top, r.right, r.bottom, _left, _top, _right, _bottom);
36 static HWND build_combo(DWORD style)
38 return CreateWindow("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, NULL, NULL, 0);
41 static int font_height(HFONT hFont)
47 hDC = CreateCompatibleDC(NULL);
48 hFontOld = SelectObject(hDC, hFont);
49 GetTextMetrics(hDC, &tm);
50 SelectObject(hDC, hFontOld);
56 static INT CALLBACK is_font_installed_proc(const LOGFONT *elf, const TEXTMETRIC *tm, DWORD type, LPARAM lParam)
61 static int is_font_installed(const char *name)
63 HDC hdc = GetDC(NULL);
64 BOOL ret = !EnumFontFamilies(hdc, name, is_font_installed_proc, 0);
69 static void test_setfont(DWORD style)
71 HWND hCombo = build_combo(style);
72 HFONT hFont1 = CreateFont(10, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
73 HFONT hFont2 = CreateFont(8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
77 trace("Style %x\n", style);
78 GetClientRect(hCombo, &r);
79 expect_rect(r, 0, 0, 100, 24);
80 SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
81 MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
82 todo_wine expect_rect(r, 5, 5, 105, 105);
84 if (!is_font_installed("Marlett"))
86 skip("Marlett font not available\n");
90 if (font_height(hFont1) == 10 && font_height(hFont2) == 8)
92 SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
93 GetClientRect(hCombo, &r);
94 expect_rect(r, 0, 0, 100, 18);
95 SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
96 MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
97 todo_wine expect_rect(r, 5, 5, 105, 99);
99 SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont2, FALSE);
100 GetClientRect(hCombo, &r);
101 expect_rect(r, 0, 0, 100, 16);
102 SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
103 MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
104 todo_wine expect_rect(r, 5, 5, 105, 97);
106 SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
107 GetClientRect(hCombo, &r);
108 expect_rect(r, 0, 0, 100, 18);
109 SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
110 MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
111 todo_wine expect_rect(r, 5, 5, 105, 99);
114 skip("Invalid Marlett font heights\n");
116 for (i = 1; i < 30; i++)
118 HFONT hFont = CreateFont(i, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
119 int height = font_height(hFont);
121 SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont, FALSE);
122 GetClientRect(hCombo, &r);
123 expect_eq(r.bottom - r.top, height + 8, int, "%d");
124 SendMessage(hCombo, WM_SETFONT, 0, FALSE);
128 DestroyWindow(hCombo);
129 DeleteObject(hFont1);
130 DeleteObject(hFont2);
135 hMainWnd = CreateWindow("static", "Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
136 ShowWindow(hMainWnd, SW_SHOW);
138 test_setfont(CBS_DROPDOWN);
139 test_setfont(CBS_DROPDOWNLIST);
140 DestroyWindow(hMainWnd);