wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / comctl32 / tests / status.c
blobf7eec88c61376a1edebc37a6a6fe8bbe8dde7b0f
1 /* Unit test suite for status control.
3 * Copyright 2007 Google (Lei Zhang)
4 * Copyright 2007 Alex Arazi
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <windows.h>
22 #include <commctrl.h>
24 #include "wine/test.h"
26 #define SUBCLASS_NAME "MyStatusBar"
28 #define expect(expected,got) ok (expected == got,"Expected %d, got %d\n",expected,got)
29 #define expect_rect(_left,_top,_right,_bottom,got) do { \
30 RECT exp = {abs(got.left - _left), abs(got.top - _top), \
31 abs(got.right - _right), abs(got.bottom - _bottom)}; \
32 ok(exp.left <= 2 && exp.top <= 2 && exp.right <= 2 && exp.bottom <= 2, \
33 "Expected rect (%d,%d)-(%d,%d), got %s\n", _left, _top, _right, _bottom, \
34 wine_dbgstr_rect(&(got))); } while (0)
36 static HINSTANCE hinst;
37 static WNDPROC g_status_wndproc;
38 static RECT g_rcCreated;
39 static HWND g_hMainWnd;
40 static int g_wmsize_count = 0;
41 static INT g_ysize;
42 static INT g_dpisize;
43 static int g_wmdrawitm_ctr;
44 static WNDPROC g_wndproc_saved;
46 static BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
48 static HWND create_status_control(DWORD style, DWORD exstyle)
50 HWND hWndStatus;
52 /* make the control */
53 hWndStatus = CreateWindowExA(exstyle, STATUSCLASSNAMEA, NULL, style,
54 /* placement */
55 0, 0, 300, 20,
56 /* parent, etc */
57 NULL, NULL, hinst, NULL);
58 ok(hWndStatus != NULL, "failed to create status wnd\n");
59 return hWndStatus;
62 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
64 LRESULT ret;
66 if (msg == WM_CREATE)
68 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
69 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
70 GetWindowRect(hwnd, &g_rcCreated);
71 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
72 ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
73 ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
74 } else if (msg == WM_SIZE)
76 g_wmsize_count++;
77 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
79 else
80 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
82 return ret;
85 static void register_subclass(void)
87 WNDCLASSEXA cls;
89 cls.cbSize = sizeof(WNDCLASSEXA);
90 GetClassInfoExA(NULL, STATUSCLASSNAMEA, &cls);
91 g_status_wndproc = cls.lpfnWndProc;
92 cls.lpfnWndProc = create_test_wndproc;
93 cls.lpszClassName = SUBCLASS_NAME;
94 cls.hInstance = NULL;
95 ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
98 static void test_create(void)
100 RECT rc;
101 HWND hwnd;
103 ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
104 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
105 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
106 GetWindowRect(hwnd, &rc);
107 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
108 expect_rect(0, 0, 100, 100, g_rcCreated);
109 expect(0, rc.left);
110 expect(672, rc.right);
111 expect(226, rc.bottom);
112 /* we don't check rc.top as this may depend on user font settings */
113 DestroyWindow(hwnd);
116 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
118 HWND hwndStatus = (HWND)lParam;
119 HDC hdc = GetDC(NULL);
120 static const int sizes[] = { 6, 7, 8, 9, 10, 11, 12, 13, 15, 16,
121 20, 22, 28, 36, 48, 72};
122 DWORD i;
123 INT y;
124 LPSTR facename = (CHAR *)enumlf->elfFullName;
126 /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
127 if (type != TRUETYPE_FONTTYPE)
128 facename = enumlf->elfLogFont.lfFaceName;
130 for (i = 0; i < ARRAY_SIZE(sizes); i++)
132 HFONT hFont;
133 TEXTMETRICA tm;
134 HFONT hCtrlFont;
135 HFONT hOldFont;
136 RECT rcCtrl;
138 enumlf->elfLogFont.lfHeight = sizes[i];
139 hFont = CreateFontIndirectA(&enumlf->elfLogFont);
140 hCtrlFont = (HFONT)SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
141 hOldFont = SelectObject(hdc, hFont);
143 GetClientRect(hwndStatus, &rcCtrl);
144 GetTextMetricsA(hdc, &tm);
145 y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4;
147 ok( (rcCtrl.bottom == max(y, g_ysize)) || (rcCtrl.bottom == max(y, g_dpisize)),
148 "got %d (expected %d or %d) for %s #%d\n",
149 rcCtrl.bottom, max(y, g_ysize), max(y, g_dpisize), facename, sizes[i]);
151 SelectObject(hdc, hOldFont);
152 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
153 DeleteObject(hFont);
155 ReleaseDC(NULL, hdc);
156 return 1;
159 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
161 HDC hdc = GetDC(NULL);
162 enumlf->elfLogFont.lfHeight = 0;
163 EnumFontFamiliesExA(hdc, &enumlf->elfLogFont, (FONTENUMPROCA)check_height_font_enumproc, lParam, 0);
164 ReleaseDC(NULL, hdc);
165 return 1;
168 static void test_height(void)
170 LOGFONTA lf;
171 HFONT hFont, hFontSm;
172 RECT rc1, rc2;
173 HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
174 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
175 HDC hdc;
177 GetClientRect(hwndStatus, &rc1);
178 hFont = CreateFontA(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
179 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
181 g_wmsize_count = 0;
182 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
183 if (!g_wmsize_count)
185 skip("Status control not resized in win95, skipping broken tests.\n");
186 return;
188 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
190 GetClientRect(hwndStatus, &rc2);
191 expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
193 g_wmsize_count = 0;
194 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
195 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
197 GetClientRect(hwndStatus, &rc2);
198 expect_rect(0, 0, 672, 42, rc2);
200 /* minheight < fontsize - no effects*/
201 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 12, 0);
202 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
203 GetClientRect(hwndStatus, &rc2);
204 expect_rect(0, 0, 672, 42, rc2);
206 /* minheight > fontsize - has an effect after WM_SIZE */
207 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 60, 0);
208 GetClientRect(hwndStatus, &rc2);
209 expect_rect(0, 0, 672, 42, rc2);
210 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
211 GetClientRect(hwndStatus, &rc2);
212 expect_rect(0, 0, 672, 62, rc2);
214 /* font changed to smaller than minheight - has an effect */
215 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 30, 0);
216 expect_rect(0, 0, 672, 62, rc2);
217 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
218 GetClientRect(hwndStatus, &rc2);
219 expect_rect(0, 0, 672, 42, rc2);
220 hFontSm = CreateFontA(9, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
221 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
222 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFontSm, TRUE);
223 GetClientRect(hwndStatus, &rc2);
224 expect_rect(0, 0, 672, 32, rc2);
226 /* test the height formula */
227 ZeroMemory(&lf, sizeof(lf));
228 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 0, 0);
229 hdc = GetDC(NULL);
231 /* used only for some fonts (tahoma as example) */
232 g_ysize = GetSystemMetrics(SM_CYSIZE) + 2;
233 if (g_ysize & 1) g_ysize--; /* The min height is always even */
235 g_dpisize = MulDiv(18, GetDeviceCaps(hdc, LOGPIXELSY), 96) + 2;
236 if (g_dpisize & 1) g_dpisize--; /* The min height is always even */
239 trace("dpi=%d (min height: %d or %d) SM_CYSIZE: %d\n",
240 GetDeviceCaps(hdc, LOGPIXELSY), g_ysize, g_dpisize,
241 GetSystemMetrics(SM_CYSIZE));
243 EnumFontFamiliesExA(hdc, &lf, (FONTENUMPROCA)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
244 ReleaseDC(NULL, hdc);
246 DestroyWindow(hwndStatus);
247 DeleteObject(hFont);
248 DeleteObject(hFontSm);
251 static void test_status_control(void)
253 HWND hWndStatus;
254 int r;
255 int nParts[] = {50, 150, -1};
256 int checkParts[] = {0, 0, 0};
257 int borders[] = {0, 0, 0};
258 RECT rc;
259 CHAR charArray[20];
260 HICON hIcon;
261 char ch;
262 char chstr[10] = "Inval id";
263 COLORREF crColor = RGB(0,0,0);
264 WCHAR wbuf[20];
266 hWndStatus = create_status_control(WS_VISIBLE | SBT_TOOLTIPS, 0);
268 /* Divide into parts and set text */
269 r = SendMessageA(hWndStatus, SB_SETPARTS, 3, (LPARAM)nParts);
270 expect(TRUE,r);
271 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_POPOUT|0, (LPARAM)"First");
272 expect(TRUE,r);
273 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW|1, (LPARAM)"Second");
274 expect(TRUE,r);
275 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_NOBORDERS|2, (LPARAM)"Third");
276 expect(TRUE,r);
278 /* Get RECT Information */
279 r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
280 expect(TRUE,r);
281 expect(2,rc.top);
282 /* The rc.bottom test is system dependent
283 expect(22,rc.bottom); */
284 expect(0,rc.left);
285 expect(50,rc.right);
286 r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
287 expect(FALSE,r);
288 r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
289 expect(FALSE,r);
290 /* Get text length and text */
291 r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 0, 0);
292 expect(5,LOWORD(r));
293 expect(SBT_POPOUT,HIWORD(r));
294 r = SendMessageW(hWndStatus, WM_GETTEXTLENGTH, 0, 0);
295 ok(r == 5, "Expected 5, got %d\n", r);
296 r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 1, 0);
297 expect(0,LOWORD(r));
298 expect(SBT_OWNERDRAW,HIWORD(r));
299 r = SendMessageA(hWndStatus, SB_GETTEXTLENGTHA, 2, 0);
300 expect(5,LOWORD(r));
301 expect(SBT_NOBORDERS,HIWORD(r));
302 r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
303 ok(strcmp(charArray,"Third") == 0, "Expected Third, got %s\n", charArray);
304 expect(5,LOWORD(r));
305 expect(SBT_NOBORDERS,HIWORD(r));
307 /* Get parts and borders */
308 r = SendMessageA(hWndStatus, SB_GETPARTS, 3, (LPARAM)checkParts);
309 ok(r == 3, "Expected 3, got %d\n", r);
310 expect(50,checkParts[0]);
311 expect(150,checkParts[1]);
312 expect(-1,checkParts[2]);
313 r = SendMessageA(hWndStatus, SB_GETBORDERS, 0, (LPARAM)borders);
314 ok(r == TRUE, "Expected TRUE, got %d\n", r);
315 expect(0,borders[0]);
316 expect(2,borders[1]);
317 expect(2,borders[2]);
319 /* Test resetting text with different characters */
320 r = SendMessageA(hWndStatus, SB_SETPARTS, 4, (LPARAM)nParts);
321 expect(TRUE,r);
322 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)"First@Again");
323 expect(TRUE,r);
324 r = SendMessageA(hWndStatus, SB_SETTEXTA, 1, (LPARAM)"Invalid\tChars\\7\7");
325 expect(TRUE,r);
326 r = SendMessageA(hWndStatus, SB_SETTEXTA, 2, (LPARAM)"InvalidChars\\n\n");
327 expect(TRUE,r);
328 r = SendMessageW(hWndStatus, SB_SETTEXTW, 3, (LPARAM)L"Non printable\x80");
329 expect(TRUE,r);
331 /* Get text again */
332 r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM) charArray);
333 ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
334 ok(r == 11, "r = %d\n", r);
336 r = SendMessageA(hWndStatus, SB_GETTEXTA, 1, (LPARAM) charArray);
337 ok(strcmp(charArray,"Invalid\tChars\\7 ") == 0, "Expected Invalid\tChars\\7 , got %s\n", charArray);
338 ok(r == 16, "r = %d\n", r);
340 r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
341 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
342 ok(r == 15, "r = %d\n", r);
344 r = SendMessageW(hWndStatus, SB_GETTEXTW, 3, (LPARAM) wbuf);
345 ok(wcscmp(wbuf, L"Non printable\x80") == 0, "got %s\n", wine_dbgstr_w(wbuf));
346 ok(r == 14, "r = %d\n", r);
348 /* test more nonprintable chars */
349 for(ch = 0x00; ch < 0x7F; ch++) {
350 chstr[5] = ch;
351 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)chstr);
352 expect(TRUE,r);
353 r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM)charArray);
354 ok(r == strlen(charArray), "got %d\n", r);
355 /* substitution with single space */
356 if (ch > 0x00 && ch < 0x20 && ch != '\t')
357 chstr[5] = ' ';
358 ok(strcmp(charArray, chstr) == 0, "Expected %s, got %s\n", chstr, charArray);
361 /* Set background color */
362 crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
363 ok(crColor == CLR_DEFAULT ||
364 broken(crColor == RGB(0,0,0)), /* win95 */
365 "Expected 0x%.8x, got 0x%.8x\n", CLR_DEFAULT, crColor);
366 crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
367 ok(crColor == RGB(255,0,0) ||
368 broken(crColor == RGB(0,0,0)), /* win95 */
369 "Expected 0x%.8x, got 0x%.8x\n", RGB(255,0,0), crColor);
371 /* Add an icon to the status bar */
372 hIcon = LoadIconA(NULL, (LPCSTR)IDI_QUESTION);
373 r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
374 ok(r != 0 ||
375 broken(r == 0), /* win95 */
376 "Expected non-zero, got %d\n", r);
377 r = SendMessageA(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
378 ok(r != 0 ||
379 broken(r == 0), /* win95 */
380 "Expected non-zero, got %d\n", r);
381 r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
382 ok(r != 0 ||
383 broken(r == 0), /* win95 */
384 "Expected non-zero, got %d\n", r);
386 /* Set the Unicode format */
387 r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
388 expect(FALSE,r);
389 r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
390 expect(FALSE,r);
391 r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
392 expect(FALSE,r);
393 r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
394 ok(r == TRUE ||
395 broken(r == FALSE), /* win95 */
396 "Expected TRUE, got %d\n", r);
398 /* Reset number of parts */
399 r = SendMessageA(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
400 expect(TRUE,r);
401 r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
402 ok(r == 2, "Expected 2, got %d\n", r);
403 r = SendMessageA(hWndStatus, SB_SETPARTS, 0, 0);
404 expect(FALSE,r);
405 r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
406 ok(r == 2, "Expected 2, got %d\n", r);
408 /* Set the minimum height and get rectangle information again */
409 SendMessageA(hWndStatus, SB_SETMINHEIGHT, 50, 0);
410 r = SendMessageA(hWndStatus, WM_SIZE, 0, 0);
411 expect(0,r);
412 r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
413 expect(TRUE,r);
414 expect(2,rc.top);
415 /* The rc.bottom test is system dependent
416 expect(22,rc.bottom); */
417 expect(0,rc.left);
418 expect(50,rc.right);
419 r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
420 expect(FALSE,r);
421 r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
422 expect(FALSE,r);
424 /* Set the ToolTip text */
425 SendMessageA(hWndStatus, SB_SETTIPTEXTA, 0,(LPARAM) "Tooltip Text");
426 lstrcpyA(charArray, "apple");
427 SendMessageA(hWndStatus, SB_GETTIPTEXTA, MAKEWPARAM (0, 20),(LPARAM) charArray);
428 ok(strcmp(charArray,"Tooltip Text") == 0 ||
429 broken(!strcmp(charArray, "apple")), /* win95 */
430 "Expected Tooltip Text, got %s\n", charArray);
432 /* Make simple */
433 SendMessageA(hWndStatus, SB_SIMPLE, TRUE, 0);
434 r = SendMessageA(hWndStatus, SB_ISSIMPLE, 0, 0);
435 ok(r == TRUE ||
436 broken(r == FALSE), /* win95 */
437 "Expected TRUE, got %d\n", r);
439 DestroyWindow(hWndStatus);
442 static LRESULT WINAPI ownerdraw_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
444 LRESULT ret;
445 if (msg == WM_DRAWITEM)
446 g_wmdrawitm_ctr++;
447 ret = CallWindowProcA(g_wndproc_saved, hwnd, msg, wParam, lParam);
448 return ret;
451 static void test_status_ownerdraw(void)
453 HWND hWndStatus;
454 int r;
455 const char* statustext = "STATUS TEXT";
456 LONG oldstyle;
458 /* subclass the main window and make sure it is visible */
459 g_wndproc_saved = (WNDPROC) SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC,
460 (LONG_PTR)ownerdraw_test_wndproc );
461 ok( g_wndproc_saved != 0, "failed to set the WndProc\n");
462 SetWindowPos( g_hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
463 oldstyle = GetWindowLongA( g_hMainWnd, GWL_STYLE);
464 SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle | WS_VISIBLE);
465 /* create a status child window */
466 ok((hWndStatus = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE, 0, 0, 100, 100,
467 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
468 /* set text */
469 g_wmdrawitm_ctr = 0;
470 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)statustext);
471 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
472 ok( 0 == g_wmdrawitm_ctr, "got %d drawitem messages expected none\n", g_wmdrawitm_ctr);
473 /* set same text, with ownerdraw flag */
474 g_wmdrawitm_ctr = 0;
475 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
476 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
477 ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
478 /* and again */
479 g_wmdrawitm_ctr = 0;
480 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
481 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
482 ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
483 /* clean up */
484 DestroyWindow(hWndStatus);
485 SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle);
486 SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved );
489 static void test_gettext(void)
491 HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
492 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
493 char buf[5];
494 int r;
496 r = SendMessageA(hwndStatus, SB_SETTEXTA, 0, (LPARAM)"Text");
497 expect(TRUE, r);
498 r = SendMessageA(hwndStatus, WM_GETTEXTLENGTH, 0, 0);
499 expect(4, r);
500 /* A size of 0 returns the length of the text */
501 r = SendMessageA(hwndStatus, WM_GETTEXT, 0, 0);
502 ok( r == 4 || broken(r == 2) /* win8 */, "Expected 4 got %d\n", r );
503 /* A size of 1 only stores the NULL terminator */
504 buf[0] = 0xa;
505 r = SendMessageA(hwndStatus, WM_GETTEXT, 1, (LPARAM)buf);
506 ok( r == 0 || broken(r == 4), "Expected 0 got %d\n", r );
507 if (!r) ok(!buf[0], "expected empty buffer\n");
508 /* A size of 2 returns a length 1 */
509 r = SendMessageA(hwndStatus, WM_GETTEXT, 2, (LPARAM)buf);
510 ok( r == 1 || broken(r == 4), "Expected 1 got %d\n", r );
511 r = SendMessageA(hwndStatus, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
512 expect(4, r);
513 ok(!strcmp(buf, "Text"), "expected Text, got %s\n", buf);
514 DestroyWindow(hwndStatus);
517 /* Notify events to parent */
518 static BOOL g_got_dblclk;
519 static BOOL g_got_click;
520 static BOOL g_got_rdblclk;
521 static BOOL g_got_rclick;
523 /* Messages to parent */
524 static BOOL g_got_contextmenu;
526 static LRESULT WINAPI test_notify_parent_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
528 switch(msg)
530 case WM_NOTIFY:
532 NMHDR *hdr = ((LPNMHDR)lParam);
533 switch(hdr->code)
535 case NM_DBLCLK: g_got_dblclk = TRUE; break;
536 case NM_CLICK: g_got_click = TRUE; break;
537 case NM_RDBLCLK: g_got_rdblclk = TRUE; break;
538 case NM_RCLICK: g_got_rclick = TRUE; break;
541 /* Return zero to indicate default processing */
542 return 0;
545 case WM_CONTEXTMENU: g_got_contextmenu = TRUE; return 0;
547 default:
548 return( DefWindowProcA(hwnd, msg, wParam, lParam));
551 return 0;
554 /* Test that WM_NOTIFY messages from the status control works correctly */
555 static void test_notify(void)
557 HWND hwndParent;
558 HWND hwndStatus;
559 ATOM atom;
560 WNDCLASSA wclass = {0};
561 wclass.lpszClassName = "TestNotifyParentClass";
562 wclass.lpfnWndProc = test_notify_parent_proc;
563 atom = RegisterClassA(&wclass);
564 ok(atom, "RegisterClass failed\n");
566 /* create parent */
567 hwndParent = CreateWindowA(wclass.lpszClassName, "parent", WS_OVERLAPPEDWINDOW,
568 CW_USEDEFAULT, 0, 300, 20, NULL, NULL, NULL, NULL);
569 ok(hwndParent != NULL, "Parent creation failed!\n");
571 /* create status bar */
572 hwndStatus = CreateWindowA(STATUSCLASSNAMEA, NULL, WS_VISIBLE | WS_CHILD,
573 0, 0, 300, 20, hwndParent, NULL, NULL, NULL);
574 ok(hwndStatus != NULL, "Status creation failed!\n");
576 /* Send various mouse event, and check that we get them */
577 g_got_dblclk = FALSE;
578 SendMessageA(hwndStatus, WM_LBUTTONDBLCLK, 0, 0);
579 ok(g_got_dblclk, "WM_LBUTTONDBLCLK was not processed correctly!\n");
580 g_got_rdblclk = FALSE;
581 SendMessageA(hwndStatus, WM_RBUTTONDBLCLK, 0, 0);
582 ok(g_got_rdblclk, "WM_RBUTTONDBLCLK was not processed correctly!\n");
583 g_got_click = FALSE;
584 SendMessageA(hwndStatus, WM_LBUTTONUP, 0, 0);
585 ok(g_got_click, "WM_LBUTTONUP was not processed correctly!\n");
587 /* For R-UP, check that we also get the context menu from the default processing */
588 g_got_contextmenu = FALSE;
589 g_got_rclick = FALSE;
590 SendMessageA(hwndStatus, WM_RBUTTONUP, 0, 0);
591 ok(g_got_rclick, "WM_RBUTTONUP was not processed correctly!\n");
592 ok(g_got_contextmenu, "WM_RBUTTONUP did not activate the context menu!\n");
595 static void test_sizegrip(void)
597 HWND hwndStatus;
598 LONG style;
599 RECT rc, rcClient;
600 POINT pt;
601 int width, r;
603 hwndStatus = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP,
604 0, 0, 100, 100, g_hMainWnd, NULL, NULL, NULL);
606 style = GetWindowLongPtrA(g_hMainWnd, GWL_STYLE);
607 width = GetSystemMetrics(SM_CXVSCROLL);
609 GetClientRect(hwndStatus, &rcClient);
611 pt.x = rcClient.right;
612 pt.y = rcClient.top;
613 ClientToScreen(hwndStatus, &pt);
614 rc.left = pt.x - width;
615 rc.right = pt.x;
616 rc.top = pt.y;
618 pt.y = rcClient.bottom;
619 ClientToScreen(hwndStatus, &pt);
620 rc.bottom = pt.y;
622 /* check bounds when not maximized */
623 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
624 expect(HTBOTTOMRIGHT, r);
625 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left - 1, rc.top));
626 expect(HTCLIENT, r);
627 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
628 expect(HTBOTTOMRIGHT, r);
629 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
630 expect(HTBOTTOMRIGHT, r);
631 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom));
632 expect(HTBOTTOMRIGHT, r);
633 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
634 expect(HTBOTTOMRIGHT, r);
635 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom - 1));
636 expect(HTBOTTOMRIGHT, r);
638 /* not maximized and right-to-left */
639 SetWindowLongA(hwndStatus, GWL_EXSTYLE, WS_EX_LAYOUTRTL);
641 pt.x = rcClient.right;
642 ClientToScreen(hwndStatus, &pt);
643 rc.left = pt.x + width;
644 rc.right = pt.x;
646 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
647 expect(HTBOTTOMLEFT, r);
648 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left + 1, rc.top));
649 expect(HTCLIENT, r);
650 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
651 expect(HTBOTTOMLEFT, r);
652 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
653 expect(HTBOTTOMLEFT, r);
654 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom));
655 expect(HTBOTTOMLEFT, r);
656 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
657 expect(HTBOTTOMLEFT, r);
658 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom - 1));
659 expect(HTBOTTOMLEFT, r);
661 /* maximize with left-to-right */
662 SetWindowLongA(g_hMainWnd, GWL_STYLE, style|WS_MAXIMIZE);
663 SetWindowLongA(hwndStatus, GWL_EXSTYLE, 0);
665 GetClientRect(hwndStatus, &rcClient);
667 pt.x = rcClient.right;
668 pt.y = rcClient.top;
669 ClientToScreen(hwndStatus, &pt);
670 rc.left = pt.x - width;
671 rc.right = pt.x;
672 rc.top = pt.y;
674 pt.y = rcClient.bottom;
675 ClientToScreen(hwndStatus, &pt);
676 rc.bottom = pt.y;
678 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
679 expect(HTCLIENT, r);
680 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left - 1, rc.top));
681 expect(HTCLIENT, r);
682 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
683 expect(HTNOWHERE, r);
684 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
685 expect(HTNOWHERE, r);
686 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom));
687 expect(HTNOWHERE, r);
688 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
689 expect(HTNOWHERE, r);
690 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom - 1));
691 expect(HTCLIENT, r);
693 /* maximized with right-to-left */
694 SetWindowLongA(hwndStatus, GWL_EXSTYLE, WS_EX_LAYOUTRTL);
696 pt.x = rcClient.right;
697 ClientToScreen(hwndStatus, &pt);
698 rc.left = pt.x + width;
699 rc.right = pt.x;
701 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top));
702 expect(HTCLIENT, r);
703 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left + 1, rc.top));
704 expect(HTCLIENT, r);
705 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.left, rc.top - 1));
706 expect(HTNOWHERE, r);
707 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom));
708 expect(HTNOWHERE, r);
709 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right - 1, rc.bottom));
710 expect(HTNOWHERE, r);
711 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right, rc.bottom + 1));
712 expect(HTNOWHERE, r);
713 r = SendMessageA(hwndStatus, WM_NCHITTEST, 0, MAKELPARAM(rc.right + 1, rc.bottom - 1));
714 expect(HTCLIENT, r);
716 SetWindowLongA(g_hMainWnd, GWL_STYLE, style);
717 DestroyWindow(hwndStatus);
720 static void init_functions(void)
722 HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
724 #define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
725 X(InitCommonControlsEx);
726 #undef X
729 START_TEST(status)
731 INITCOMMONCONTROLSEX iccex;
733 init_functions();
735 hinst = GetModuleHandleA(NULL);
737 iccex.dwSize = sizeof(iccex);
738 iccex.dwICC = ICC_BAR_CLASSES;
739 pInitCommonControlsEx(&iccex);
741 g_hMainWnd = CreateWindowExA(0, WC_STATICA, "", WS_OVERLAPPEDWINDOW,
742 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
743 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
744 NULL, NULL, GetModuleHandleA(NULL), 0);
746 register_subclass();
748 test_status_control();
749 test_create();
750 test_height();
751 test_status_ownerdraw();
752 test_gettext();
753 test_notify();
754 test_sizegrip();