[COMCTL32_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / comctl32 / status.c
1 /* Unit test suite for status control.
2 *
3 * Copyright 2007 Google (Lei Zhang)
4 * Copyright 2007 Alex Arazi
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <wine/test.h>
22
23 //#include <windows.h>
24 #include <wingdi.h>
25 #include <winuser.h>
26 #include <commctrl.h>
27
28 #define SUBCLASS_NAME "MyStatusBar"
29
30 #define expect(expected,got) ok (expected == got,"Expected %d, got %d\n",expected,got)
31 #define expect_rect(_left,_top,_right,_bottom,got) do { \
32 RECT exp = {abs(got.left - _left), abs(got.top - _top), \
33 abs(got.right - _right), abs(got.bottom - _bottom)}; \
34 ok(exp.left <= 2 && exp.top <= 2 && exp.right <= 2 && exp.bottom <= 2, \
35 "Expected rect {%d,%d, %d,%d}, got {%d,%d, %d,%d}\n", \
36 _left, _top, _right, _bottom, \
37 (got).left, (got).top, (got).right, (got).bottom); } while (0)
38
39 static HINSTANCE hinst;
40 static WNDPROC g_status_wndproc;
41 static RECT g_rcCreated;
42 static HWND g_hMainWnd;
43 static int g_wmsize_count = 0;
44 static INT g_ysize;
45 static INT g_dpisize;
46 static int g_wmdrawitm_ctr;
47 static WNDPROC g_wndproc_saved;
48
49 static HWND create_status_control(DWORD style, DWORD exstyle)
50 {
51 HWND hWndStatus;
52
53 /* make the control */
54 hWndStatus = CreateWindowExA(exstyle, STATUSCLASSNAMEA, NULL, style,
55 /* placement */
56 0, 0, 300, 20,
57 /* parent, etc */
58 NULL, NULL, hinst, NULL);
59 ok(hWndStatus != NULL, "failed to create status wnd\n");
60 return hWndStatus;
61 }
62
63 static LRESULT WINAPI create_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
64 {
65 LRESULT ret;
66
67 if (msg == WM_CREATE)
68 {
69 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
70 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
71 GetWindowRect(hwnd, &g_rcCreated);
72 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&g_rcCreated, 2);
73 ok(cs->x == g_rcCreated.left, "CREATESTRUCT.x modified\n");
74 ok(cs->y == g_rcCreated.top, "CREATESTRUCT.y modified\n");
75 } else if (msg == WM_SIZE)
76 {
77 g_wmsize_count++;
78 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
79 }
80 else
81 ret = CallWindowProcA(g_status_wndproc, hwnd, msg, wParam, lParam);
82
83 return ret;
84 }
85
86 static void register_subclass(void)
87 {
88 WNDCLASSEXA cls;
89
90 cls.cbSize = sizeof(WNDCLASSEXA);
91 GetClassInfoExA(NULL, STATUSCLASSNAMEA, &cls);
92 g_status_wndproc = cls.lpfnWndProc;
93 cls.lpfnWndProc = create_test_wndproc;
94 cls.lpszClassName = SUBCLASS_NAME;
95 cls.hInstance = NULL;
96 ok(RegisterClassExA(&cls), "RegisterClassEx failed\n");
97 }
98
99 static void test_create(void)
100 {
101 RECT rc;
102 HWND hwnd;
103
104 ok((hwnd = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 100, 100,
105 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
106 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
107 GetWindowRect(hwnd, &rc);
108 MapWindowPoints(HWND_DESKTOP, g_hMainWnd, (LPPOINT)&rc, 2);
109 expect_rect(0, 0, 100, 100, g_rcCreated);
110 expect(0, rc.left);
111 expect(672, rc.right);
112 expect(226, rc.bottom);
113 /* we don't check rc.top as this may depend on user font settings */
114 DestroyWindow(hwnd);
115 }
116
117 static int CALLBACK check_height_font_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
118 {
119 HWND hwndStatus = (HWND)lParam;
120 HDC hdc = GetDC(NULL);
121 static const int sizes[] = { 6, 7, 8, 9, 10, 11, 12, 13, 15, 16,
122 20, 22, 28, 36, 48, 72};
123 DWORD i;
124 INT y;
125 LPSTR facename = (CHAR *)enumlf->elfFullName;
126
127 /* on win9x, enumlf->elfFullName is only valid for truetype fonts */
128 if (type != TRUETYPE_FONTTYPE)
129 facename = enumlf->elfLogFont.lfFaceName;
130
131 for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++)
132 {
133 HFONT hFont;
134 TEXTMETRICA tm;
135 HFONT hCtrlFont;
136 HFONT hOldFont;
137 RECT rcCtrl;
138
139 enumlf->elfLogFont.lfHeight = sizes[i];
140 hFont = CreateFontIndirectA(&enumlf->elfLogFont);
141 hCtrlFont = (HFONT)SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
142 hOldFont = SelectObject(hdc, hFont);
143
144 GetClientRect(hwndStatus, &rcCtrl);
145 GetTextMetricsA(hdc, &tm);
146 y = tm.tmHeight + (tm.tmInternalLeading ? tm.tmInternalLeading : 2) + 4;
147
148 ok( (rcCtrl.bottom == max(y, g_ysize)) || (rcCtrl.bottom == max(y, g_dpisize)),
149 "got %d (expected %d or %d) for %s #%d\n",
150 rcCtrl.bottom, max(y, g_ysize), max(y, g_dpisize), facename, sizes[i]);
151
152 SelectObject(hdc, hOldFont);
153 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hCtrlFont, TRUE);
154 DeleteObject(hFont);
155 }
156 ReleaseDC(NULL, hdc);
157 return 1;
158 }
159
160 static int CALLBACK check_height_family_enumproc(ENUMLOGFONTEXA *enumlf, NEWTEXTMETRICEXA *ntm, DWORD type, LPARAM lParam)
161 {
162 HDC hdc = GetDC(NULL);
163 enumlf->elfLogFont.lfHeight = 0;
164 EnumFontFamiliesExA(hdc, &enumlf->elfLogFont, (FONTENUMPROCA)check_height_font_enumproc, lParam, 0);
165 ReleaseDC(NULL, hdc);
166 return 1;
167 }
168
169 static void test_height(void)
170 {
171 LOGFONTA lf;
172 HFONT hFont, hFontSm;
173 RECT rc1, rc2;
174 HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
175 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
176 HDC hdc;
177
178 GetClientRect(hwndStatus, &rc1);
179 hFont = CreateFontA(32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
180 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
181
182 g_wmsize_count = 0;
183 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
184 if (!g_wmsize_count)
185 {
186 skip("Status control not resized in win95, skipping broken tests.\n");
187 return;
188 }
189 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
190
191 GetClientRect(hwndStatus, &rc2);
192 expect_rect(0, 0, 672, 42, rc2); /* GetTextMetrics returns invalid tmInternalLeading for this font */
193
194 g_wmsize_count = 0;
195 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFont, TRUE);
196 ok(g_wmsize_count > 0, "WM_SETFONT should issue WM_SIZE\n");
197
198 GetClientRect(hwndStatus, &rc2);
199 expect_rect(0, 0, 672, 42, rc2);
200
201 /* minheight < fontsize - no effects*/
202 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 12, 0);
203 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
204 GetClientRect(hwndStatus, &rc2);
205 expect_rect(0, 0, 672, 42, rc2);
206
207 /* minheight > fontsize - has an effect after WM_SIZE */
208 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 60, 0);
209 GetClientRect(hwndStatus, &rc2);
210 expect_rect(0, 0, 672, 42, rc2);
211 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
212 GetClientRect(hwndStatus, &rc2);
213 expect_rect(0, 0, 672, 62, rc2);
214
215 /* font changed to smaller than minheight - has an effect */
216 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 30, 0);
217 expect_rect(0, 0, 672, 62, rc2);
218 SendMessageA(hwndStatus, WM_SIZE, 0, 0);
219 GetClientRect(hwndStatus, &rc2);
220 expect_rect(0, 0, 672, 42, rc2);
221 hFontSm = CreateFontA(9, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
222 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Tahoma");
223 SendMessageA(hwndStatus, WM_SETFONT, (WPARAM)hFontSm, TRUE);
224 GetClientRect(hwndStatus, &rc2);
225 expect_rect(0, 0, 672, 32, rc2);
226
227 /* test the height formula */
228 ZeroMemory(&lf, sizeof(lf));
229 SendMessageA(hwndStatus, SB_SETMINHEIGHT, 0, 0);
230 hdc = GetDC(NULL);
231
232 /* used only for some fonts (tahoma as example) */
233 g_ysize = GetSystemMetrics(SM_CYSIZE) + 2;
234 if (g_ysize & 1) g_ysize--; /* The min height is always even */
235
236 g_dpisize = MulDiv(18, GetDeviceCaps(hdc, LOGPIXELSY), 96) + 2;
237 if (g_dpisize & 1) g_dpisize--; /* The min height is always even */
238
239
240 trace("dpi=%d (min height: %d or %d) SM_CYSIZE: %d\n",
241 GetDeviceCaps(hdc, LOGPIXELSY), g_ysize, g_dpisize,
242 GetSystemMetrics(SM_CYSIZE));
243
244 EnumFontFamiliesExA(hdc, &lf, (FONTENUMPROCA)check_height_family_enumproc, (LPARAM)hwndStatus, 0);
245 ReleaseDC(NULL, hdc);
246
247 DestroyWindow(hwndStatus);
248 DeleteObject(hFont);
249 DeleteObject(hFontSm);
250 }
251
252 static void test_status_control(void)
253 {
254 HWND hWndStatus;
255 int r;
256 int nParts[] = {50, 150, -1};
257 int checkParts[] = {0, 0, 0};
258 int borders[] = {0, 0, 0};
259 RECT rc;
260 CHAR charArray[20];
261 HICON hIcon;
262 char ch;
263 char chstr[10] = "Inval id";
264 COLORREF crColor = RGB(0,0,0);
265
266 hWndStatus = create_status_control(WS_VISIBLE | SBT_TOOLTIPS, 0);
267
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);
277
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 || broken(0x02000005 /* NT4 */), "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));
306
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]);
318
319 /* Test resetting text with different characters */
320 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)"First@Again");
321 expect(TRUE,r);
322 r = SendMessageA(hWndStatus, SB_SETTEXTA, 1, (LPARAM)"Invalid\tChars\\7\7");
323 expect(TRUE,r);
324 r = SendMessageA(hWndStatus, SB_SETTEXTA, 2, (LPARAM)"InvalidChars\\n\n");
325 expect(TRUE,r);
326
327 /* Get text again */
328 r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM) charArray);
329 ok(strcmp(charArray,"First@Again") == 0, "Expected First@Again, got %s\n", charArray);
330 expect(11,LOWORD(r));
331 expect(0,HIWORD(r));
332 r = SendMessageA(hWndStatus, SB_GETTEXTA, 1, (LPARAM) charArray);
333 ok(strcmp(charArray,"Invalid\tChars\\7 ") == 0, "Expected Invalid\tChars\\7 , got %s\n", charArray);
334
335 expect(16,LOWORD(r));
336 expect(0,HIWORD(r));
337 r = SendMessageA(hWndStatus, SB_GETTEXTA, 2, (LPARAM) charArray);
338 ok(strcmp(charArray,"InvalidChars\\n ") == 0, "Expected InvalidChars\\n , got %s\n", charArray);
339
340 expect(15,LOWORD(r));
341 expect(0,HIWORD(r));
342
343 /* test more nonprintable chars */
344 for(ch = 0x00; ch < 0x7F; ch++) {
345 chstr[5] = ch;
346 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)chstr);
347 expect(TRUE,r);
348 r = SendMessageA(hWndStatus, SB_GETTEXTA, 0, (LPARAM)charArray);
349 ok(r == strlen(charArray), "got %d\n", r);
350 /* substitution with single space */
351 if (ch > 0x00 && ch < 0x20 && ch != '\t')
352 chstr[5] = ' ';
353 ok(strcmp(charArray, chstr) == 0, "Expected %s, got %s\n", chstr, charArray);
354 }
355
356 /* Set background color */
357 crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, RGB(255,0,0));
358 ok(crColor == CLR_DEFAULT ||
359 broken(crColor == RGB(0,0,0)), /* win95 */
360 "Expected 0x%.8x, got 0x%.8x\n", CLR_DEFAULT, crColor);
361 crColor = SendMessageA(hWndStatus, SB_SETBKCOLOR , 0, CLR_DEFAULT);
362 ok(crColor == RGB(255,0,0) ||
363 broken(crColor == RGB(0,0,0)), /* win95 */
364 "Expected 0x%.8x, got 0x%.8x\n", RGB(255,0,0), crColor);
365
366 /* Add an icon to the status bar */
367 hIcon = LoadIconA(NULL, (LPCSTR)IDI_QUESTION);
368 r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
369 ok(r != 0 ||
370 broken(r == 0), /* win95 */
371 "Expected non-zero, got %d\n", r);
372 r = SendMessageA(hWndStatus, SB_SETICON, 1, (LPARAM) hIcon);
373 ok(r != 0 ||
374 broken(r == 0), /* win95 */
375 "Expected non-zero, got %d\n", r);
376 r = SendMessageA(hWndStatus, SB_SETICON, 1, 0);
377 ok(r != 0 ||
378 broken(r == 0), /* win95 */
379 "Expected non-zero, got %d\n", r);
380
381 /* Set the Unicode format */
382 r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, FALSE, 0);
383 expect(FALSE,r);
384 r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
385 expect(FALSE,r);
386 r = SendMessageA(hWndStatus, SB_SETUNICODEFORMAT, TRUE, 0);
387 expect(FALSE,r);
388 r = SendMessageA(hWndStatus, SB_GETUNICODEFORMAT, 0, 0);
389 ok(r == TRUE ||
390 broken(r == FALSE), /* win95 */
391 "Expected TRUE, got %d\n", r);
392
393 /* Reset number of parts */
394 r = SendMessageA(hWndStatus, SB_SETPARTS, 2, (LPARAM)nParts);
395 expect(TRUE,r);
396 r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
397 ok(r == 2, "Expected 2, got %d\n", r);
398 r = SendMessageA(hWndStatus, SB_SETPARTS, 0, 0);
399 expect(FALSE,r);
400 r = SendMessageA(hWndStatus, SB_GETPARTS, 0, 0);
401 ok(r == 2, "Expected 2, got %d\n", r);
402
403 /* Set the minimum height and get rectangle information again */
404 SendMessageA(hWndStatus, SB_SETMINHEIGHT, 50, 0);
405 r = SendMessageA(hWndStatus, WM_SIZE, 0, 0);
406 expect(0,r);
407 r = SendMessageA(hWndStatus, SB_GETRECT, 0, (LPARAM)&rc);
408 expect(TRUE,r);
409 expect(2,rc.top);
410 /* The rc.bottom test is system dependent
411 expect(22,rc.bottom); */
412 expect(0,rc.left);
413 expect(50,rc.right);
414 r = SendMessageA(hWndStatus, SB_GETRECT, -1, (LPARAM)&rc);
415 expect(FALSE,r);
416 r = SendMessageA(hWndStatus, SB_GETRECT, 3, (LPARAM)&rc);
417 expect(FALSE,r);
418
419 /* Set the ToolTip text */
420 SendMessageA(hWndStatus, SB_SETTIPTEXTA, 0,(LPARAM) "Tooltip Text");
421 lstrcpyA(charArray, "apple");
422 SendMessageA(hWndStatus, SB_GETTIPTEXTA, MAKEWPARAM (0, 20),(LPARAM) charArray);
423 ok(strcmp(charArray,"Tooltip Text") == 0 ||
424 broken(!strcmp(charArray, "apple")), /* win95 */
425 "Expected Tooltip Text, got %s\n", charArray);
426
427 /* Make simple */
428 SendMessageA(hWndStatus, SB_SIMPLE, TRUE, 0);
429 r = SendMessageA(hWndStatus, SB_ISSIMPLE, 0, 0);
430 ok(r == TRUE ||
431 broken(r == FALSE), /* win95 */
432 "Expected TRUE, got %d\n", r);
433
434 DestroyWindow(hWndStatus);
435 }
436
437 static LRESULT WINAPI ownerdraw_test_wndproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
438 {
439 LRESULT ret;
440 if (msg == WM_DRAWITEM)
441 g_wmdrawitm_ctr++;
442 ret = CallWindowProcA(g_wndproc_saved, hwnd, msg, wParam, lParam);
443 return ret;
444 }
445
446 static void test_status_ownerdraw(void)
447 {
448 HWND hWndStatus;
449 int r;
450 const char* statustext = "STATUS TEXT";
451 LONG oldstyle;
452
453 /* subclass the main window and make sure it is visible */
454 g_wndproc_saved = (WNDPROC) SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC,
455 (LONG_PTR)ownerdraw_test_wndproc );
456 ok( g_wndproc_saved != 0, "failed to set the WndProc\n");
457 SetWindowPos( g_hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
458 oldstyle = GetWindowLongA( g_hMainWnd, GWL_STYLE);
459 SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle | WS_VISIBLE);
460 /* create a status child window */
461 ok((hWndStatus = CreateWindowA(SUBCLASS_NAME, "", WS_CHILD|WS_VISIBLE, 0, 0, 100, 100,
462 g_hMainWnd, NULL, NULL, 0)) != NULL, "CreateWindowA failed\n");
463 /* set text */
464 g_wmdrawitm_ctr = 0;
465 r = SendMessageA(hWndStatus, SB_SETTEXTA, 0, (LPARAM)statustext);
466 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
467 ok( 0 == g_wmdrawitm_ctr, "got %d drawitem messages expected none\n", g_wmdrawitm_ctr);
468 /* set same text, with ownerdraw flag */
469 g_wmdrawitm_ctr = 0;
470 r = SendMessageA(hWndStatus, SB_SETTEXTA, SBT_OWNERDRAW, (LPARAM)statustext);
471 ok( r == TRUE, "Sendmessage returned %d, expected 1\n", r);
472 ok( 1 == g_wmdrawitm_ctr, "got %d drawitem messages expected 1\n", g_wmdrawitm_ctr);
473 /* and again */
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 /* clean up */
479 DestroyWindow(hWndStatus);
480 SetWindowLongA( g_hMainWnd, GWL_STYLE, oldstyle);
481 SetWindowLongPtrA( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved );
482 }
483
484 static void test_gettext(void)
485 {
486 HWND hwndStatus = CreateWindowA(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
487 0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
488 char buf[5];
489 int r;
490
491 r = SendMessageA(hwndStatus, SB_SETTEXTA, 0, (LPARAM)"Text");
492 expect(TRUE, r);
493 r = SendMessageA(hwndStatus, WM_GETTEXTLENGTH, 0, 0);
494 expect(4, r);
495 /* A size of 0 returns the length of the text */
496 r = SendMessageA(hwndStatus, WM_GETTEXT, 0, 0);
497 ok( r == 4 || broken(r == 2) /* win8 */, "Expected 4 got %d\n", r );
498 /* A size of 1 only stores the NULL terminator */
499 buf[0] = 0xa;
500 r = SendMessageA(hwndStatus, WM_GETTEXT, 1, (LPARAM)buf);
501 ok( r == 0 || broken(r == 4), "Expected 0 got %d\n", r );
502 if (!r) ok(!buf[0], "expected empty buffer\n");
503 /* A size of 2 returns a length 1 */
504 r = SendMessageA(hwndStatus, WM_GETTEXT, 2, (LPARAM)buf);
505 ok( r == 1 || broken(r == 4), "Expected 1 got %d\n", r );
506 r = SendMessageA(hwndStatus, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
507 expect(4, r);
508 ok(!strcmp(buf, "Text"), "expected Text, got %s\n", buf);
509 DestroyWindow(hwndStatus);
510 }
511
512 /* Notify events to parent */
513 static BOOL g_got_dblclk;
514 static BOOL g_got_click;
515 static BOOL g_got_rdblclk;
516 static BOOL g_got_rclick;
517
518 /* Messages to parent */
519 static BOOL g_got_contextmenu;
520
521 static LRESULT WINAPI test_notify_parent_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
522 {
523 switch(msg)
524 {
525 case WM_NOTIFY:
526 {
527 NMHDR *hdr = ((LPNMHDR)lParam);
528 switch(hdr->code)
529 {
530 case NM_DBLCLK: g_got_dblclk = TRUE; break;
531 case NM_CLICK: g_got_click = TRUE; break;
532 case NM_RDBLCLK: g_got_rdblclk = TRUE; break;
533 case NM_RCLICK: g_got_rclick = TRUE; break;
534 }
535
536 /* Return zero to indicate default processing */
537 return 0;
538 }
539
540 case WM_CONTEXTMENU: g_got_contextmenu = TRUE; return 0;
541
542 default:
543 return( DefWindowProcA(hwnd, msg, wParam, lParam));
544 }
545
546 return 0;
547 }
548
549 /* Test that WM_NOTIFY messages from the status control works correctly */
550 static void test_notify(void)
551 {
552 HWND hwndParent;
553 HWND hwndStatus;
554 ATOM atom;
555 WNDCLASSA wclass = {0};
556 wclass.lpszClassName = "TestNotifyParentClass";
557 wclass.lpfnWndProc = test_notify_parent_proc;
558 atom = RegisterClassA(&wclass);
559 ok(atom, "RegisterClass failed\n");
560
561 /* create parent */
562 hwndParent = CreateWindowA(wclass.lpszClassName, "parent", WS_OVERLAPPEDWINDOW,
563 CW_USEDEFAULT, 0, 300, 20, NULL, NULL, NULL, NULL);
564 ok(hwndParent != NULL, "Parent creation failed!\n");
565
566 /* create status bar */
567 hwndStatus = CreateWindowA(STATUSCLASSNAMEA, NULL, WS_VISIBLE | WS_CHILD,
568 0, 0, 300, 20, hwndParent, NULL, NULL, NULL);
569 ok(hwndStatus != NULL, "Status creation failed!\n");
570
571 /* Send various mouse event, and check that we get them */
572 g_got_dblclk = FALSE;
573 SendMessageA(hwndStatus, WM_LBUTTONDBLCLK, 0, 0);
574 ok(g_got_dblclk, "WM_LBUTTONDBLCLK was not processed correctly!\n");
575 g_got_rdblclk = FALSE;
576 SendMessageA(hwndStatus, WM_RBUTTONDBLCLK, 0, 0);
577 ok(g_got_rdblclk, "WM_RBUTTONDBLCLK was not processed correctly!\n");
578 g_got_click = FALSE;
579 SendMessageA(hwndStatus, WM_LBUTTONUP, 0, 0);
580 ok(g_got_click, "WM_LBUTTONUP was not processed correctly!\n");
581
582 /* For R-UP, check that we also get the context menu from the default processing */
583 g_got_contextmenu = FALSE;
584 g_got_rclick = FALSE;
585 SendMessageA(hwndStatus, WM_RBUTTONUP, 0, 0);
586 ok(g_got_rclick, "WM_RBUTTONUP was not processed correctly!\n");
587 ok(g_got_contextmenu, "WM_RBUTTONUP did not activate the context menu!\n");
588 }
589
590 START_TEST(status)
591 {
592 hinst = GetModuleHandleA(NULL);
593
594 g_hMainWnd = CreateWindowExA(0, "static", "", WS_OVERLAPPEDWINDOW,
595 CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
596 226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
597 NULL, NULL, GetModuleHandleA(NULL), 0);
598
599 InitCommonControls();
600
601 register_subclass();
602
603 test_status_control();
604 test_create();
605 test_height();
606 test_status_ownerdraw();
607 test_gettext();
608 test_notify();
609 }