Remove unnecessary executable bits
[reactos.git] / modules / rostests / winetests / user32 / menu.c
1 /*
2 * Unit tests for menus
3 *
4 * Copyright 2005 Robert Shearman
5 * Copyright 2007 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #ifndef __REACTOS__
23 #define _WIN32_WINNT 0x0501
24 #endif
25
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <assert.h>
30
31 #define OEMRESOURCE /* For OBM_MNARROW */
32
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37
38 #include "wine/test.h"
39
40 static ATOM atomMenuCheckClass;
41
42 static BOOL (WINAPI *pGetMenuInfo)(HMENU,LPCMENUINFO);
43 static BOOL (WINAPI *pGetMenuBarInfo)(HWND,LONG,LONG,PMENUBARINFO);
44 static UINT (WINAPI *pSendInput)(UINT, INPUT*, size_t);
45 static BOOL (WINAPI *pSetMenuInfo)(HMENU,LPCMENUINFO);
46
47 static void init_function_pointers(void)
48 {
49 HMODULE hdll = GetModuleHandleA("user32");
50
51 #define GET_PROC(func) \
52 p ## func = (void*)GetProcAddress(hdll, #func); \
53 if(!p ## func) \
54 trace("GetProcAddress(%s) failed\n", #func);
55
56 GET_PROC(GetMenuInfo)
57 GET_PROC(GetMenuBarInfo)
58 GET_PROC(SendInput)
59 GET_PROC(SetMenuInfo)
60
61 #undef GET_PROC
62 }
63
64 static BOOL correct_behavior(void)
65 {
66 HMENU hmenu;
67 MENUITEMINFOA info;
68 BOOL rc;
69
70 hmenu = CreateMenu();
71
72 memset(&info, 0, sizeof(MENUITEMINFOA));
73 info.cbSize= sizeof(MENUITEMINFOA);
74 SetLastError(0xdeadbeef);
75 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
76 /* Win9x : 0xdeadbeef
77 * NT4 : ERROR_INVALID_PARAMETER
78 * >= W2K : ERROR_MENU_ITEM_NOT_FOUND
79 */
80 if (!rc && GetLastError() != ERROR_MENU_ITEM_NOT_FOUND)
81 {
82 win_skip("NT4 and below can't handle a bigger MENUITEMINFO struct\n");
83 DestroyMenu(hmenu);
84 return FALSE;
85 }
86
87 DestroyMenu(hmenu);
88 return TRUE;
89 }
90
91 static LRESULT WINAPI menu_check_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
92 {
93 switch (msg)
94 {
95 case WM_ENTERMENULOOP:
96 /* mark window as having entered menu loop */
97 SetWindowLongPtrA(hwnd, GWLP_USERDATA, TRUE);
98 /* exit menu modal loop
99 * ( A SendMessage does not work on NT3.51 here ) */
100 return PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
101 }
102 return DefWindowProcA(hwnd, msg, wparam, lparam);
103 }
104
105 /* The MSVC headers ignore our NONAMELESSUNION requests so we have to define
106 * our own type */
107 typedef struct
108 {
109 DWORD type;
110 union
111 {
112 MOUSEINPUT mi;
113 KEYBDINPUT ki;
114 HARDWAREINPUT hi;
115 } u;
116 } TEST_INPUT;
117
118 /* globals to communicate between test and wndproc */
119
120 static BOOL bMenuVisible;
121 static INT popmenu;
122 static BOOL got_input;
123 static HMENU hMenus[4];
124
125 #define MOD_SIZE 10
126 #define MOD_NRMENUS 8
127
128 /* menu texts with their sizes */
129 static struct {
130 LPCSTR text;
131 SIZE size; /* size of text up to any \t */
132 SIZE sc_size; /* size of the short-cut */
133 } MOD_txtsizes[] = {
134 { "Pinot &Noir" },
135 { "&Merlot\bF4" },
136 { "Shira&z\tAlt+S" },
137 { "" },
138 { NULL }
139 };
140
141 static unsigned int MOD_maxid;
142 static RECT MOD_rc[MOD_NRMENUS];
143 static int MOD_avec, MOD_hic;
144 static int MOD_odheight;
145 static SIZE MODsizes[MOD_NRMENUS]= { {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE},
146 {MOD_SIZE, MOD_SIZE},{MOD_SIZE, MOD_SIZE}};
147 static BOOL MOD_GotDrawItemMsg = FALSE;
148 static int gflag_initmenupopup,
149 gflag_entermenuloop,
150 gflag_initmenu,
151 gflag_enteridle;
152 static WPARAM selectitem_wp;
153 static LPARAM selectitem_lp;
154
155 /* wndproc used by test_menu_ownerdraw() */
156 static LRESULT WINAPI menu_ownerdraw_wnd_proc(HWND hwnd, UINT msg,
157 WPARAM wparam, LPARAM lparam)
158 {
159 static HMENU hmenupopup;
160 switch (msg)
161 {
162 case WM_INITMENUPOPUP:
163 gflag_initmenupopup++;
164 hmenupopup = (HMENU) wparam;
165 break;
166 case WM_ENTERMENULOOP:
167 gflag_entermenuloop++;
168 break;
169 case WM_INITMENU:
170 gflag_initmenu++;
171 break;
172 case WM_MEASUREITEM:
173 {
174 MEASUREITEMSTRUCT* pmis = (MEASUREITEMSTRUCT*)lparam;
175 if (winetest_debug > 1)
176 trace("WM_MEASUREITEM received data %lx size %dx%d\n",
177 pmis->itemData, pmis->itemWidth, pmis->itemHeight);
178 ok( !wparam, "wrong wparam %lx\n", wparam );
179 ok( pmis->CtlType == ODT_MENU, "wrong type %x\n", pmis->CtlType );
180 MOD_odheight = pmis->itemHeight;
181 pmis->itemWidth = MODsizes[pmis->itemData].cx;
182 pmis->itemHeight = MODsizes[pmis->itemData].cy;
183 return TRUE;
184 }
185 case WM_DRAWITEM:
186 {
187 DRAWITEMSTRUCT * pdis;
188 TEXTMETRICA tm;
189 HPEN oldpen;
190 char chrs[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
191 SIZE sz;
192 int i;
193 pdis = (DRAWITEMSTRUCT *) lparam;
194 if (winetest_debug > 1) {
195 RECT rc;
196 GetMenuItemRect( hwnd, (HMENU)pdis->hwndItem, pdis->itemData ,&rc);
197 trace("WM_DRAWITEM received hwnd %p hmenu %p itemdata %ld item %d rc %s itemrc: %s\n",
198 hwnd, pdis->hwndItem, pdis->itemData, pdis->itemID,
199 wine_dbgstr_rect(&pdis->rcItem), wine_dbgstr_rect(&rc));
200 oldpen=SelectObject( pdis->hDC, GetStockObject(
201 pdis->itemState & ODS_SELECTED ? WHITE_PEN :BLACK_PEN));
202 Rectangle( pdis->hDC, pdis->rcItem.left,pdis->rcItem.top,
203 pdis->rcItem.right,pdis->rcItem.bottom );
204 SelectObject( pdis->hDC, oldpen);
205 }
206 ok( !wparam, "wrong wparam %lx\n", wparam );
207 ok( pdis->CtlType == ODT_MENU, "wrong type %x\n", pdis->CtlType );
208 /* calculate widths of some menu texts */
209 if( ! MOD_txtsizes[0].size.cx)
210 for(i = 0; MOD_txtsizes[i].text; i++) {
211 char buf[100], *p;
212 RECT rc={0,0,0,0};
213 strcpy( buf, MOD_txtsizes[i].text);
214 if( ( p = strchr( buf, '\t'))) {
215 *p = '\0';
216 DrawTextA( pdis->hDC, p + 1, -1, &rc,
217 DT_SINGLELINE|DT_CALCRECT);
218 MOD_txtsizes[i].sc_size.cx= rc.right - rc.left;
219 MOD_txtsizes[i].sc_size.cy= rc.bottom - rc.top;
220 }
221 DrawTextA( pdis->hDC, buf, -1, &rc,
222 DT_SINGLELINE|DT_CALCRECT);
223 MOD_txtsizes[i].size.cx= rc.right - rc.left;
224 MOD_txtsizes[i].size.cy= rc.bottom - rc.top;
225 }
226
227 if( pdis->itemData > MOD_maxid) return TRUE;
228 /* store the rectangle */
229 MOD_rc[pdis->itemData] = pdis->rcItem;
230 /* calculate average character width */
231 GetTextExtentPointA( pdis->hDC, chrs, 52, &sz );
232 MOD_avec = (sz.cx + 26)/52;
233 GetTextMetricsA( pdis->hDC, &tm);
234 MOD_hic = tm.tmHeight;
235 MOD_GotDrawItemMsg = TRUE;
236 return TRUE;
237 }
238 case WM_ENTERIDLE:
239 {
240 gflag_enteridle++;
241 ok( lparam || broken(!lparam), /* win9x, nt4 */
242 "Menu window handle is NULL!\n");
243 if( lparam) {
244 HMENU hmenu = (HMENU)SendMessageA( (HWND)lparam, MN_GETHMENU, 0, 0);
245 ok( hmenupopup == hmenu, "MN_GETHMENU returns %p expected %p\n",
246 hmenu, hmenupopup);
247 }
248 PostMessageA(hwnd, WM_CANCELMODE, 0, 0);
249 return TRUE;
250 }
251 case WM_MENUSELECT:
252 selectitem_wp = wparam;
253 selectitem_lp = lparam;
254 break;
255 }
256 return DefWindowProcA(hwnd, msg, wparam, lparam);
257 }
258
259 static void register_menu_check_class(void)
260 {
261 WNDCLASSA wc =
262 {
263 0,
264 menu_check_wnd_proc,
265 0,
266 0,
267 GetModuleHandleA(NULL),
268 NULL,
269 LoadCursorA(NULL, (LPCSTR)IDC_ARROW),
270 (HBRUSH)(COLOR_BTNFACE+1),
271 NULL,
272 "WineMenuCheck",
273 };
274
275 atomMenuCheckClass = RegisterClassA(&wc);
276 }
277
278 static void test_getmenubarinfo(void)
279 {
280 BOOL ret;
281 HMENU hmenu;
282 MENUBARINFO mbi;
283 RECT rcw, rci;
284 HWND hwnd;
285 INT err;
286
287 if (!pGetMenuBarInfo) {
288 win_skip("GetMenuBarInfo is not available\n");
289 return;
290 }
291
292 mbi.cbSize = sizeof(MENUBARINFO);
293
294 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
295 WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
296 NULL, NULL, NULL, NULL);
297 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
298
299 /* no menu: getmenubarinfo should fail */
300 SetLastError(0xdeadbeef);
301 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
302 err = GetLastError();
303 ok(ret == FALSE, "GetMenuBarInfo should not have been successful\n");
304 ok(err == 0xdeadbeef, "err = %d\n", err);
305
306 /* create menubar, no items yet */
307 hmenu = CreateMenu();
308 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
309
310 ret = SetMenu(hwnd, hmenu);
311 ok(ret, "SetMenu failed with error %d\n", GetLastError());
312
313 SetLastError(0xdeadbeef);
314 ret = pGetMenuBarInfo(NULL, OBJID_CLIENT, 0, &mbi);
315 err = GetLastError();
316 ok(!ret, "GetMenuBarInfo succeeded\n");
317 ok(err == ERROR_INVALID_WINDOW_HANDLE, "err = %d\n", err);
318
319 SetLastError(0xdeadbeef);
320 ret = pGetMenuBarInfo(hwnd, OBJID_CLIENT, 0, &mbi);
321 err = GetLastError();
322 ok(!ret, "GetMenuBarInfo succeeded\n");
323 ok(err==ERROR_INVALID_MENU_HANDLE || broken(err==0xdeadbeef) /* NT, W2K, XP */, "err = %d\n", err);
324
325 SetLastError(0xdeadbeef);
326 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, -1, &mbi);
327 err = GetLastError();
328 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
329 ok(err == 0xdeadbeef, "err = %d\n", err);
330
331 mbi.cbSize = 1000;
332 SetLastError(0xdeadbeef);
333 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
334 err = GetLastError();
335 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
336 ok(err == ERROR_INVALID_PARAMETER, "err = %d\n", err);
337 mbi.cbSize = sizeof(MENUBARINFO);
338
339 SetLastError(0xdeadbeef);
340 ret = pGetMenuBarInfo(hwnd, 123, 0, &mbi);
341 err = GetLastError();
342 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
343 ok(err == 0xdeadbeef, "err = %d\n", err);
344
345 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
346 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
347
348 ok(mbi.rcBar.left == 0 && mbi.rcBar.top == 0 && mbi.rcBar.bottom == 0 && mbi.rcBar.right == 0,
349 "rcBar: Expected (0,0)-(0,0), got: %s\n", wine_dbgstr_rect(&mbi.rcBar));
350 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n",
351 mbi.hMenu, hmenu);
352 ok(mbi.fBarFocused == 0, "fBarFocused: Got %d instead of 0.\n", mbi.fBarFocused);
353 ok(mbi.fFocused == 0, "fFocused: Got %d instead of 0.\n", mbi.fFocused);
354
355 /* add some items */
356 ret = AppendMenuA(hmenu, MF_STRING , 100, "item 1");
357 ok(ret, "AppendMenu failed.\n");
358 ret = AppendMenuA(hmenu, MF_STRING , 101, "item 2");
359 ok(ret, "AppendMenu failed.\n");
360 ret = SetMenu(hwnd, hmenu);
361 ok(ret, "SetMenu failed with error %d\n", GetLastError());
362
363 SetLastError(0xdeadbeef);
364 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 200, &mbi);
365 err = GetLastError();
366 ok(ret == FALSE, "GetMenuBarInfo should have failed\n");
367 ok(err == 0xdeadbeef, "err = %d\n", err);
368
369 /* get info for the whole menu */
370 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
371 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
372
373 /* calculate menu rectangle, from window rectangle and the position of the first item */
374 ret = GetWindowRect(hwnd, &rcw);
375 ok(ret, "GetWindowRect failed.\n");
376 ret = GetMenuItemRect(hwnd, hmenu, 0, &rci);
377 ok(ret, "GetMenuItemRect failed.\n");
378 todo_wine ok(mbi.rcBar.left == rci.left && mbi.rcBar.top == rci.top &&
379 mbi.rcBar.bottom == rci.bottom && mbi.rcBar.right == rcw.right - rci.left + rcw.left,
380 "rcBar: Got %s instead of (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mbi.rcBar),
381 rci.left, rci.top, rcw.right - rci.left + rcw.left, rci.bottom);
382 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
383 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
384 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
385
386 /* get info for item nr.2 */
387 ret = pGetMenuBarInfo(hwnd, OBJID_MENU, 2, &mbi);
388 ok(ret, "GetMenuBarInfo failed with error %d\n", GetLastError());
389 ret = GetMenuItemRect(hwnd, hmenu, 1, &rci);
390 ok(ret, "GetMenuItemRect failed.\n");
391 ok(EqualRect(&mbi.rcBar, &rci), "rcBar: Got %s instead of %s\n", wine_dbgstr_rect(&mbi.rcBar),
392 wine_dbgstr_rect(&rci));
393 ok(mbi.hMenu == hmenu, "hMenu: Got %p instead of %p\n", mbi.hMenu, hmenu);
394 ok(mbi.fBarFocused == 0, "fBarFocused: got %d instead of 0\n", mbi.fBarFocused);
395 ok(mbi.fFocused == 0, "fFocused: got %d instead of 0\n", mbi.fFocused);
396
397 DestroyWindow(hwnd);
398 }
399
400 static void test_system_menu(void)
401 {
402 WCHAR testW[] = {'t','e','s','t',0};
403 BOOL ret;
404 HMENU menu;
405 HWND hwnd;
406 MENUITEMINFOA info;
407 MENUITEMINFOW infoW;
408 char buffer[80];
409 char found[0x200];
410 int i, res;
411
412 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
413 WS_SYSMENU | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
414 NULL, NULL, NULL, NULL);
415 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
416 menu = GetSystemMenu( hwnd, FALSE );
417 ok( menu != NULL, "no system menu\n" );
418
419 for (i = 0xf000; i < 0xf200; i++)
420 {
421 memset( &info, 0xcc, sizeof(info) );
422 info.cbSize = sizeof(info);
423 info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
424 info.dwTypeData = buffer;
425 info.cch = sizeof( buffer );
426 ret = GetMenuItemInfoA( menu, i, FALSE, &info );
427 if (ret) trace( "found %x: '%s'\n", i, buffer );
428 switch (i)
429 {
430 case SC_RESTORE:
431 case SC_SIZE:
432 case SC_MOVE:
433 case SC_MINIMIZE:
434 case SC_MAXIMIZE:
435 case SC_CLOSE:
436 ok( ret, "%x menu item not found\n", i );
437 break;
438 case SC_SCREENSAVE+1: /* used for the 'About Wine' entry, don't test */
439 break;
440 default:
441 ok( !ret, "%x menu item found\n", i );
442 break;
443 }
444 found[i - 0xf000] = ret;
445 }
446
447 for (i = 0xf000; i < 0xf200; i++)
448 {
449 res = CheckMenuItem( menu, i, 0 );
450 if (res == -1) ok( !found[i - 0xf000], "could not check existent item %x\n", i );
451 else ok( found[i - 0xf000], "could check non-existent item %x\n", i );
452
453 res = EnableMenuItem( menu, i, 0 );
454 if (res == -1) ok( !found[i - 0xf000], "could not enable existent item %x\n", i );
455 else ok( found[i - 0xf000], "could enable non-existent item %x\n", i );
456
457 res = GetMenuState( menu, i, 0 );
458 if (res == -1) ok( !found[i - 0xf000], "could not get state existent item %x\n", i );
459 else ok( found[i - 0xf000], "could get state of non-existent item %x\n", i );
460
461 if (!found[i - 0xf000]) /* don't remove the existing ones */
462 {
463 ret = RemoveMenu( menu, i, 0 );
464 ok( !ret, "could remove non-existent item %x\n", i );
465 }
466
467 ret = ModifyMenuA( menu, i, 0, i, "test" );
468 if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
469 else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
470 else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
471
472 ret = ModifyMenuW( menu, i, 0, i, testW );
473 if (i == SC_TASKLIST) ok( ret, "failed to modify SC_TASKLIST\n" );
474 else if (!ret) ok( !found[i - 0xf000], "could not modify existent item %x\n", i );
475 else ok( found[i - 0xf000], "could modify non-existent item %x\n", i );
476
477 ret = ModifyMenuA( menu, i, MF_BYPOSITION, i, "test" );
478 ok( !ret, "could modify non-existent item %x\n", i );
479
480 strcpy( buffer, "test" );
481 memset( &info, 0xcc, sizeof(info) );
482 info.cbSize = sizeof(info);
483 info.fMask = MIIM_STRING | MIIM_ID;
484 info.wID = i;
485 info.dwTypeData = buffer;
486 info.cch = strlen( buffer );
487 ret = SetMenuItemInfoA( menu, i, FALSE, &info );
488 if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
489 else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
490 else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
491 ret = SetMenuItemInfoA( menu, i, TRUE, &info );
492 ok( !ret, "could modify non-existent item %x\n", i );
493
494 memset( &infoW, 0xcc, sizeof(infoW) );
495 infoW.cbSize = sizeof(infoW);
496 infoW.fMask = MIIM_STRING | MIIM_ID;
497 infoW.wID = i;
498 infoW.dwTypeData = testW;
499 infoW.cch = lstrlenW( testW );
500 ret = SetMenuItemInfoW( menu, i, FALSE, &infoW );
501 if (i == SC_TASKLIST) ok( ret, "failed to set SC_TASKLIST\n" );
502 else if (!ret) ok( !found[i - 0xf000], "could not set existent item %x\n", i );
503 else ok( found[i - 0xf000], "could set non-existent item %x\n", i );
504 ret = SetMenuItemInfoW( menu, i, TRUE, &infoW );
505 ok( !ret, "could modify non-existent item %x\n", i );
506 }
507
508 /* confirm that SC_TASKLIST still does not exist */
509 for (i = 0xf000; i < 0xf200; i++)
510 {
511 memset( &info, 0xcc, sizeof(info) );
512 info.cbSize = sizeof(info);
513 info.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
514 info.dwTypeData = buffer;
515 info.cch = sizeof( buffer );
516 ret = GetMenuItemInfoA( menu, i, FALSE, &info );
517 switch (i)
518 {
519 case SC_RESTORE:
520 case SC_SIZE:
521 case SC_MOVE:
522 case SC_MINIMIZE:
523 case SC_MAXIMIZE:
524 case SC_CLOSE:
525 ok( ret, "%x menu item not found\n", i );
526 break;
527 case SC_SCREENSAVE+1: /* used for the 'About Wine' entry, don't test */
528 break;
529 default:
530 ok( !ret, "%x menu item found\n", i );
531 break;
532 }
533 }
534
535 /* now a normal (non-system) menu */
536
537 menu = CreateMenu();
538 ok( menu != NULL, "CreateMenu failed with error %d\n", GetLastError() );
539
540 res = CheckMenuItem( menu, SC_TASKLIST, 0 );
541 ok( res == -1, "CheckMenuItem succeeded\n" );
542 res = EnableMenuItem( menu, SC_TASKLIST, 0 );
543 ok( res == -1, "EnableMenuItem succeeded\n" );
544 res = GetMenuState( menu, SC_TASKLIST, 0 );
545 ok( res == -1, "GetMenuState succeeded\n" );
546 ret = RemoveMenu( menu, SC_TASKLIST, 0 );
547 ok( !ret, "RemoveMenu succeeded\n" );
548 ret = ModifyMenuA( menu, SC_TASKLIST, 0, SC_TASKLIST, "test" );
549 ok( ret, "ModifyMenuA failed err %d\n", GetLastError() );
550 ret = ModifyMenuW( menu, SC_TASKLIST, 0, SC_TASKLIST, testW );
551 ok( ret, "ModifyMenuW failed err %d\n", GetLastError() );
552 ret = ModifyMenuA( menu, SC_TASKLIST-1, 0, SC_TASKLIST, "test" );
553 ok( !ret, "ModifyMenu succeeded on SC_TASKLIST-1\n" );
554 strcpy( buffer, "test" );
555 memset( &info, 0xcc, sizeof(info) );
556 info.cbSize = sizeof(info);
557 info.fMask = MIIM_STRING | MIIM_ID;
558 info.wID = SC_TASKLIST;
559 info.dwTypeData = buffer;
560 info.cch = strlen( buffer );
561 ret = SetMenuItemInfoA( menu, SC_TASKLIST, FALSE, &info );
562 ok( ret, "failed to set SC_TASKLIST\n" );
563 ret = SetMenuItemInfoA( menu, SC_TASKLIST+1, FALSE, &info );
564 ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
565 ret = SetMenuItemInfoA( menu, SC_TASKLIST, TRUE, &info );
566 ok( !ret, "succeeded setting by position\n" );
567
568 memset( &infoW, 0xcc, sizeof(infoW) );
569 infoW.cbSize = sizeof(infoW);
570 infoW.fMask = MIIM_STRING | MIIM_ID;
571 infoW.wID = SC_TASKLIST;
572 infoW.dwTypeData = testW;
573 infoW.cch = lstrlenW( testW );
574 ret = SetMenuItemInfoW( menu, SC_TASKLIST, FALSE, &infoW );
575 ok( ret, "failed to set SC_TASKLIST\n" );
576 ret = SetMenuItemInfoW( menu, SC_TASKLIST+1, FALSE, &infoW );
577 ok( !ret, "succeeded setting SC_TASKLIST+1\n" );
578 ret = SetMenuItemInfoW( menu, SC_TASKLIST, TRUE, &infoW );
579 ok( !ret, "succeeded setting by position\n" );
580
581 DestroyMenu( menu );
582 DestroyWindow( hwnd );
583 }
584
585 /* demonstrates that windows locks the menu object so that it is still valid
586 * even after a client calls DestroyMenu on it */
587 static void test_menu_locked_by_window(void)
588 {
589 BOOL ret;
590 HMENU hmenu;
591 HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
592 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
593 NULL, NULL, NULL, NULL);
594 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
595 hmenu = CreateMenu();
596 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
597 ret = InsertMenuA(hmenu, 0, MF_STRING, 0, "&Test");
598 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
599 ret = SetMenu(hwnd, hmenu);
600 ok(ret, "SetMenu failed with error %d\n", GetLastError());
601 ret = DestroyMenu(hmenu);
602 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
603
604 ret = DrawMenuBar(hwnd);
605 ok(ret, "DrawMenuBar failed with error %d\n", GetLastError());
606 ret = IsMenu(GetMenu(hwnd));
607 ok(!ret || broken(ret) /* nt4 */, "Menu handle should have been destroyed\n");
608
609 SendMessageA(hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
610 /* did we process the WM_INITMENU message? */
611 ret = GetWindowLongPtrA(hwnd, GWLP_USERDATA);
612 todo_wine {
613 ok(ret, "WM_INITMENU should have been sent\n");
614 }
615
616 DestroyWindow(hwnd);
617 }
618
619 /* demonstrates that subpopup's are locked
620 * even after a client calls DestroyMenu on it */
621 static LRESULT WINAPI subpopuplocked_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
622 {
623 HWND hwndmenu;
624 switch (msg)
625 {
626 case WM_ENTERIDLE:
627 hwndmenu = GetCapture();
628 if( hwndmenu) {
629 PostMessageA( hwndmenu, WM_KEYDOWN, VK_DOWN, 0);
630 PostMessageA( hwndmenu, WM_KEYDOWN, VK_RIGHT, 0);
631 PostMessageA( hwndmenu, WM_KEYDOWN, VK_RETURN, 0);
632 }
633 }
634 return DefWindowProcA(hwnd, msg, wparam, lparam);
635 }
636
637 static void test_subpopup_locked_by_menu(void)
638 {
639 DWORD gle;
640 BOOL ret;
641 HMENU hmenu, hsubmenu;
642 MENUINFO mi = { sizeof( MENUINFO)};
643 MENUITEMINFOA mii = { sizeof( MENUITEMINFOA)};
644 HWND hwnd;
645 const int itemid = 0x1234567;
646 if( !pGetMenuInfo)
647 {
648 win_skip("GetMenuInfo is not available\n");
649 return;
650 }
651 /* create window, popupmenu with one subpopup */
652 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
653 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
654 NULL, NULL, NULL, NULL);
655 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
656 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR) subpopuplocked_wnd_proc);
657 hmenu = CreatePopupMenu();
658 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
659 hsubmenu = CreatePopupMenu();
660 ok(hsubmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
661 ret = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hsubmenu,
662 "PopUpLockTest");
663 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
664 ret = InsertMenuA(hsubmenu, 0, MF_BYPOSITION | MF_STRING, itemid, "PopUpMenu");
665 ok(ret, "InsertMenu failed with error %d\n", GetLastError());
666 /* first some tests that all this functions properly */
667 mii.fMask = MIIM_SUBMENU;
668 ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
669 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
670 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
671 mi.fMask |= MIM_STYLE;
672 ret = pGetMenuInfo( hsubmenu, &mi);
673 ok( ret , "GetMenuInfo returned 0 with error %d\n", GetLastError());
674 ret = IsMenu( hsubmenu);
675 ok( ret , "Menu handle is not valid\n");
676 SetLastError( 0xdeadbeef);
677 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
678 if( ret == (itemid & 0xffff)) {
679 win_skip("not on 16 bit menu subsystem\n");
680 DestroyMenu( hsubmenu);
681 } else {
682 gle = GetLastError();
683 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
684 ok( gle == 0 ||
685 broken( gle == 0xdeadbeef), /* win2k0 */
686 "Last error is %d\n", gle);
687 /* then destroy the sub-popup */
688 ret = DestroyMenu( hsubmenu);
689 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
690 /* and repeat the tests */
691 mii.fMask = MIIM_SUBMENU;
692 ret = GetMenuItemInfoA( hmenu, 0, TRUE, &mii);
693 ok( ret, "GetMenuItemInfo failed error %d\n", GetLastError());
694 /* GetMenuInfo fails now */
695 ok( mii.hSubMenu == hsubmenu, "submenu is %p\n", mii.hSubMenu);
696 mi.fMask |= MIM_STYLE;
697 ret = pGetMenuInfo( hsubmenu, &mi);
698 ok( !ret , "GetMenuInfo should have failed\n");
699 /* IsMenu says it is not */
700 ret = IsMenu( hsubmenu);
701 ok( !ret , "Menu handle should be invalid\n");
702 /* but TrackPopupMenu still works! */
703 SetLastError( 0xdeadbeef);
704 ret = TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
705 gle = GetLastError();
706 todo_wine {
707 ok( ret == itemid , "TrackPopupMenu returned %d error is %d\n", ret, gle);
708 }
709 ok( gle == 0 ||
710 broken(gle == 0xdeadbeef) || /* wow64 */
711 broken(gle == ERROR_INVALID_PARAMETER), /* win2k0 */
712 "Last error is %d\n", gle);
713 }
714 /* clean up */
715 DestroyMenu( hmenu);
716 DestroyWindow(hwnd);
717 }
718
719 static void test_menu_ownerdraw(void)
720 {
721 int i,j,k;
722 BOOL ret;
723 HMENU hmenu;
724 MENUITEMINFOA mii;
725 LONG leftcol;
726 HWND hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL,
727 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
728 NULL, NULL, NULL, NULL);
729 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
730 if( !hwnd) return;
731 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
732 hmenu = CreatePopupMenu();
733 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
734 if( !hmenu) { DestroyWindow(hwnd);return;}
735 k=0;
736 for( j=0;j<2;j++) /* create columns */
737 for(i=0;i<2;i++) { /* create rows */
738 ret = AppendMenuA( hmenu, MF_OWNERDRAW |
739 (i==0 ? MF_MENUBREAK : 0), k, (LPCSTR)MAKEINTRESOURCE(k));
740 k++;
741 ok( ret, "AppendMenu failed for %d\n", k-1);
742 }
743 MOD_maxid = k-1;
744 assert( k <= sizeof(MOD_rc)/sizeof(RECT));
745 /* display the menu */
746 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
747
748 /* columns have a 4 pixel gap between them */
749 ok( MOD_rc[0].right + 4 == MOD_rc[2].left,
750 "item rectangles are not separated by 4 pixels space\n");
751 /* height should be what the MEASUREITEM message has returned */
752 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
753 "menu item has wrong height: %d should be %d\n",
754 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
755 /* no gaps between the rows */
756 ok( MOD_rc[0].bottom - MOD_rc[1].top == 0,
757 "There should not be a space between the rows, gap is %d\n",
758 MOD_rc[0].bottom - MOD_rc[1].top);
759 /* test the correct value of the item height that was sent
760 * by the WM_MEASUREITEM message */
761 ok( MOD_odheight == HIWORD( GetDialogBaseUnits()) || /* WinNT,2k,XP */
762 MOD_odheight == MOD_hic, /* Win95,98,ME */
763 "Wrong height field in MEASUREITEMSTRUCT, expected %d or %d actual %d\n",
764 HIWORD( GetDialogBaseUnits()), MOD_hic, MOD_odheight);
765 /* test what MF_MENUBREAK did at the first position. Also show
766 * that an MF_SEPARATOR is ignored in the height calculation. */
767 leftcol= MOD_rc[0].left;
768 ModifyMenuA( hmenu, 0, MF_BYCOMMAND| MF_OWNERDRAW| MF_SEPARATOR, 0, 0);
769 /* display the menu */
770 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
771 /* left should be 4 pixels less now */
772 ok( leftcol == MOD_rc[0].left + 4,
773 "columns should be 4 pixels to the left (actual %d).\n",
774 leftcol - MOD_rc[0].left);
775 /* test width */
776 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
777 "width of owner drawn menu item is wrong. Got %d expected %d\n",
778 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
779 /* and height */
780 ok( MOD_rc[0].bottom - MOD_rc[0].top == MOD_SIZE,
781 "Height is incorrect. Got %d expected %d\n",
782 MOD_rc[0].bottom - MOD_rc[0].top, MOD_SIZE);
783
784 /* test owner-drawn callback bitmap */
785 ModifyMenuA( hmenu, 1, MF_BYPOSITION | MFT_BITMAP, 1, (LPCSTR)HBMMENU_CALLBACK );
786 mii.cbSize = sizeof(mii);
787 mii.fMask = MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
788 if (GetMenuItemInfoA( hmenu, 1, TRUE, &mii ))
789 {
790 ok( mii.fType == MFT_BITMAP, "wrong type %x\n", mii.fType );
791 ok( mii.wID == 1, "wrong id %x\n", mii.wID );
792 ok( mii.hbmpItem == HBMMENU_CALLBACK, "wrong data %p\n", mii.hbmpItem );
793 }
794 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
795
796 /* test width/height of an ownerdraw menu bar as well */
797 ret = DestroyMenu(hmenu);
798 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
799 hmenu = CreateMenu();
800 ok(hmenu != NULL, "CreateMenu failed with error %d\n", GetLastError());
801 if( !hmenu) { DestroyWindow(hwnd);return;}
802 MOD_maxid=1;
803 for(i=0;i<2;i++) {
804 ret = AppendMenuA( hmenu, MF_OWNERDRAW, i, 0 );
805 ok( ret, "AppendMenu failed for %d\n", i);
806 }
807 ret = SetMenu( hwnd, hmenu);
808 UpdateWindow( hwnd); /* hack for wine to draw the window + menu */
809 ok(ret, "SetMenu failed with error %d\n", GetLastError());
810 /* test width */
811 ok( MOD_rc[0].right - MOD_rc[0].left == 2 * MOD_avec + MOD_SIZE,
812 "width of owner drawn menu item is wrong. Got %d expected %d\n",
813 MOD_rc[0].right - MOD_rc[0].left , 2*MOD_avec + MOD_SIZE);
814 /* test height */
815 ok( MOD_rc[0].bottom - MOD_rc[0].top == GetSystemMetrics( SM_CYMENU) - 1,
816 "Height of owner drawn menu item is wrong. Got %d expected %d\n",
817 MOD_rc[0].bottom - MOD_rc[0].top, GetSystemMetrics( SM_CYMENU) - 1);
818
819 /* clean up */
820 ret = DestroyMenu(hmenu);
821 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
822 DestroyWindow(hwnd);
823 }
824
825 /* helper for test_menu_bmp_and_string() */
826 static void test_mbs_help( int ispop, int hassub, int mnuopt,
827 HWND hwnd, int arrowwidth, int count, HBITMAP hbmp,
828 SIZE bmpsize, LPCSTR text, SIZE size, SIZE sc_size)
829 {
830 BOOL ret;
831 HMENU hmenu, submenu;
832 MENUITEMINFOA mii={ sizeof( MENUITEMINFOA )};
833 MENUINFO mi;
834 RECT rc;
835 CHAR text_copy[16];
836 int hastab, expect;
837 BOOL failed = FALSE;
838
839 MOD_GotDrawItemMsg = FALSE;
840 mii.fMask = MIIM_FTYPE | MIIM_DATA | MIIM_STATE;
841 mii.fType = 0;
842 /* check the menu item unless MNS_CHECKORBMP is set */
843 mii.fState = (mnuopt != 2 ? MFS_CHECKED : MFS_UNCHECKED);
844 mii.dwItemData =0;
845 MODsizes[0] = bmpsize;
846 hastab = 0;
847 if( text ) {
848 char *p;
849 mii.fMask |= MIIM_STRING;
850 strcpy(text_copy, text);
851 mii.dwTypeData = text_copy; /* structure member declared non-const */
852 if( ( p = strchr( text, '\t'))) {
853 hastab = *(p + 1) ? 2 : 1;
854 }
855 }
856 /* tabs don't make sense in menubars */
857 if(hastab && !ispop) return;
858 if( hbmp) {
859 mii.fMask |= MIIM_BITMAP;
860 mii.hbmpItem = hbmp;
861 }
862 submenu = CreateMenu();
863 ok( submenu != 0, "CreateMenu failed with error %d\n", GetLastError());
864 if( ispop)
865 hmenu = CreatePopupMenu();
866 else
867 hmenu = CreateMenu();
868 ok( hmenu != 0, "Create{Popup}Menu failed with error %d\n", GetLastError());
869 if( hassub) {
870 mii.fMask |= MIIM_SUBMENU;
871 mii.hSubMenu = submenu;
872 }
873 if( mnuopt) {
874 mi.cbSize = sizeof(mi);
875 mi.fMask = MIM_STYLE;
876 pGetMenuInfo( hmenu, &mi);
877 if( mnuopt) mi.dwStyle |= mnuopt == 1 ? MNS_NOCHECK : MNS_CHECKORBMP;
878 ret = pSetMenuInfo( hmenu, &mi);
879 ok( ret, "SetMenuInfo failed with error %d\n", GetLastError());
880 }
881 ret = InsertMenuItemA( hmenu, 0, FALSE, &mii);
882 ok( ret, "InsertMenuItem failed with error %d\n", GetLastError());
883 failed = !ret;
884 if( winetest_debug) {
885 HDC hdc=GetDC(hwnd);
886 RECT rc = {100, 50, 400, 70};
887 char buf[100];
888
889 sprintf( buf,"%d text \"%s\" mnuopt %d", count, text ? text: "(nil)", mnuopt);
890 FillRect( hdc, &rc, (HBRUSH) COLOR_WINDOW);
891 TextOutA( hdc, 10, 50, buf, strlen( buf));
892 ReleaseDC( hwnd, hdc);
893 }
894 if(ispop)
895 TrackPopupMenu( hmenu, TPM_RETURNCMD, 100,100, 0, hwnd, NULL);
896 else {
897 ret = SetMenu( hwnd, hmenu);
898 ok(ret, "SetMenu failed with error %d\n", GetLastError());
899 DrawMenuBar( hwnd);
900 }
901 ret = GetMenuItemRect( hwnd, hmenu, 0, &rc);
902 ok(ret, "GetMenuItemRect failed with error %d\n", GetLastError());
903
904 if (0) /* comment out menu size checks, behavior is different in almost every Windows version */
905 /* the tests should however succeed on win2000, XP and Wine (at least up to 1.1.15) */
906 /* with a variety of dpis and desktop font sizes */
907 {
908 /* check menu width */
909 if( ispop)
910 expect = ( text || hbmp ?
911 4 + (mnuopt != 1 ? GetSystemMetrics(SM_CXMENUCHECK) : 0)
912 : 0) +
913 arrowwidth + MOD_avec + (hbmp ?
914 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ? bmpsize.cx + 2 : GetSystemMetrics( SM_CXMENUSIZE) + 2)
915 : 0) +
916 (text && hastab ? /* TAB space */
917 MOD_avec + ( hastab==2 ? sc_size.cx : 0) : 0) +
918 (text ? 2 + (text[0] ? size.cx :0): 0) ;
919 else
920 expect = !(text || hbmp) ? 0 :
921 ( hbmp ? (text ? 2:0) + bmpsize.cx : 0 ) +
922 (text ? 2 * MOD_avec + (text[0] ? size.cx :0): 0) ;
923 ok( rc.right - rc.left == expect,
924 "menu width wrong, got %d expected %d\n", rc.right - rc.left, expect);
925 failed = failed || !(rc.right - rc.left == expect);
926 /* check menu height */
927 if( ispop)
928 expect = max( ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 : 0),
929 max( (text ? max( 2 + size.cy, MOD_hic + 4) : 0),
930 (hbmp ?
931 ((INT_PTR)hbmp<0||(INT_PTR)hbmp>12 ?
932 bmpsize.cy + 2
933 : GetSystemMetrics( SM_CYMENUSIZE) + 2)
934 : 0)));
935 else
936 expect = ( !(text || hbmp) ? GetSystemMetrics( SM_CYMENUSIZE)/2 :
937 max( GetSystemMetrics( SM_CYMENU) - 1, (hbmp ? bmpsize.cy : 0)));
938 ok( rc.bottom - rc.top == expect,
939 "menu height wrong, got %d expected %d (%d)\n",
940 rc.bottom - rc.top, expect, GetSystemMetrics( SM_CYMENU));
941 failed = failed || !(rc.bottom - rc.top == expect);
942 if( hbmp == HBMMENU_CALLBACK && MOD_GotDrawItemMsg) {
943 /* check the position of the bitmap */
944 /* horizontal */
945 if (!ispop)
946 expect = 3;
947 else if (mnuopt == 0)
948 expect = 4 + GetSystemMetrics(SM_CXMENUCHECK);
949 else if (mnuopt == 1)
950 expect = 4;
951 else /* mnuopt == 2 */
952 expect = 2;
953 ok( expect == MOD_rc[0].left,
954 "bitmap left is %d expected %d\n", MOD_rc[0].left, expect);
955 failed = failed || !(expect == MOD_rc[0].left);
956 /* vertical */
957 expect = (rc.bottom - rc.top - MOD_rc[0].bottom + MOD_rc[0].top) / 2;
958 ok( expect == MOD_rc[0].top,
959 "bitmap top is %d expected %d\n", MOD_rc[0].top, expect);
960 failed = failed || !(expect == MOD_rc[0].top);
961 }
962 }
963 /* if there was a failure, report details */
964 if( failed) {
965 trace("*** count %d %s text \"%s\" bitmap %p bmsize %d,%d textsize %d+%d,%d mnuopt %d hastab %d\n",
966 count, (ispop? "POPUP": "MENUBAR"),text ? text: "(nil)", hbmp, bmpsize.cx, bmpsize.cy,
967 size.cx, size.cy, sc_size.cx, mnuopt, hastab);
968 trace(" check %d,%d arrow %d avechar %d\n",
969 GetSystemMetrics(SM_CXMENUCHECK ),
970 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
971 if( hbmp == HBMMENU_CALLBACK)
972 trace( " rc %s bmp.rc %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(&MOD_rc[0]));
973 }
974 /* clean up */
975 ret = DestroyMenu(submenu);
976 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
977 ret = DestroyMenu(hmenu);
978 ok(ret, "DestroyMenu failed with error %d\n", GetLastError());
979 }
980
981
982 static void test_menu_bmp_and_string(void)
983 {
984 BYTE bmfill[300];
985 HBITMAP hbm_arrow;
986 BITMAP bm;
987 INT arrowwidth;
988 HWND hwnd;
989 HMENU hsysmenu;
990 MENUINFO mi= {sizeof(MENUINFO)};
991 MENUITEMINFOA mii= {sizeof(MENUITEMINFOA)};
992 int count, szidx, txtidx, bmpidx, hassub, mnuopt, ispop;
993 BOOL got;
994
995 if( !pGetMenuInfo)
996 {
997 win_skip("GetMenuInfo is not available\n");
998 return;
999 }
1000
1001 memset( bmfill, 0xcc, sizeof( bmfill));
1002 hwnd = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomMenuCheckClass), NULL, WS_SYSMENU |
1003 WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200,
1004 NULL, NULL, NULL, NULL);
1005 hbm_arrow = LoadBitmapA( 0, (LPCSTR)OBM_MNARROW);
1006 GetObjectA( hbm_arrow, sizeof(bm), &bm);
1007 arrowwidth = bm.bmWidth;
1008 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
1009 if( !hwnd) return;
1010 /* test system menu */
1011 hsysmenu = GetSystemMenu( hwnd, FALSE);
1012 ok( hsysmenu != NULL, "GetSystemMenu failed with error %d\n", GetLastError());
1013 mi.fMask = MIM_STYLE;
1014 mi.dwStyle = 0;
1015 got = pGetMenuInfo( hsysmenu, &mi);
1016 ok( got, "GetMenuInfo failed gle=%d\n", GetLastError());
1017 ok( MNS_CHECKORBMP == mi.dwStyle, "System Menu Style is %08x, without the bit %08x\n",
1018 mi.dwStyle, MNS_CHECKORBMP);
1019 mii.fMask = MIIM_BITMAP;
1020 mii.hbmpItem = NULL;
1021 got = GetMenuItemInfoA( hsysmenu, SC_CLOSE, FALSE, &mii);
1022 ok( got, "GetMenuItemInfoA failed gle=%d\n", GetLastError());
1023 ok( HBMMENU_POPUP_CLOSE == mii.hbmpItem, "Item info did not get the right hbitmap: got %p expected %p\n",
1024 mii.hbmpItem, HBMMENU_POPUP_CLOSE);
1025
1026 memset(&mii, 0x81, sizeof(mii));
1027 mii.cbSize = sizeof(mii);
1028 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE | MIIM_DATA;
1029 mii.dwTypeData = (LPSTR)bmfill;
1030 mii.cch = sizeof(bmfill);
1031 mii.dwItemData = 0x81818181;
1032 got = GetMenuItemInfoA(hsysmenu, SC_RESTORE, FALSE, &mii);
1033 ok(got, "GetMenuItemInfo failed\n");
1034 ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1035 ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1036 ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1037 ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1038 ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1039 ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1040 ok(mii.cch != 0, "cch should not be 0\n");
1041 ok(mii.hbmpItem == HBMMENU_POPUP_RESTORE, "expected HBMMENU_POPUP_RESTORE, got %p\n", mii.hbmpItem);
1042
1043 mii.cbSize = sizeof(mii);
1044 mii.fMask = MIIM_TYPE;
1045 mii.hbmpItem = (HBITMAP)0x81818181;
1046 got = GetMenuItemInfoA(hsysmenu, SC_CLOSE, FALSE, &mii);
1047 ok(got, "GetMenuItemInfo failed\n");
1048 ok((mii.fType & ~(MFT_RIGHTJUSTIFY|MFT_RIGHTORDER)) == MFT_STRING, "expected MFT_STRING, got %#x\n", mii.fType);
1049 ok(mii.fState == MF_ENABLED, "expected MF_ENABLED, got %#x\n", mii.fState);
1050 ok(mii.wID == SC_RESTORE, "expected SC_RESTORE, got %#x\n", mii.wID);
1051 ok(mii.hSubMenu == 0, "expected 0, got %p\n", mii.hSubMenu);
1052 ok(mii.dwItemData == 0, "expected 0, got %#lx\n", mii.dwItemData);
1053 ok(mii.dwTypeData == (LPSTR)bmfill, "expected %p, got %p\n", bmfill, mii.dwTypeData);
1054 ok(mii.cch != 0, "cch should not be 0\n");
1055 ok(mii.hbmpItem == HBMMENU_POPUP_CLOSE, "expected HBMMENU_POPUP_CLOSE, got %p\n", mii.hbmpItem);
1056
1057 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (LONG_PTR)menu_ownerdraw_wnd_proc);
1058
1059 if( winetest_debug)
1060 trace(" check %d,%d arrow %d avechar %d\n",
1061 GetSystemMetrics(SM_CXMENUCHECK ),
1062 GetSystemMetrics(SM_CYMENUCHECK ),arrowwidth, MOD_avec);
1063 count = 0;
1064 MOD_maxid = 0;
1065 for( ispop=1; ispop >= 0; ispop--){
1066 static SIZE bmsizes[]= {
1067 {10,10},{38,38},{1,30},{55,5}};
1068 for( szidx=0; szidx < sizeof( bmsizes) / sizeof( SIZE); szidx++) {
1069 HBITMAP hbm = CreateBitmap( bmsizes[szidx].cx, bmsizes[szidx].cy,1,1,bmfill);
1070 HBITMAP bitmaps[] = { HBMMENU_CALLBACK, hbm, HBMMENU_POPUP_CLOSE, NULL };
1071 ok( hbm != 0, "CreateBitmap failed err %d\n", GetLastError());
1072 for( txtidx = 0; txtidx < sizeof(MOD_txtsizes)/sizeof(MOD_txtsizes[0]); txtidx++) {
1073 for( hassub = 0; hassub < 2 ; hassub++) { /* add submenu item */
1074 for( mnuopt = 0; mnuopt < 3 ; mnuopt++){ /* test MNS_NOCHECK/MNS_CHECKORBMP */
1075 for( bmpidx = 0; bmpidx <sizeof(bitmaps)/sizeof(HBITMAP); bmpidx++) {
1076 /* no need to test NULL bitmaps of several sizes */
1077 if( !bitmaps[bmpidx] && szidx > 0) continue;
1078 /* the HBMMENU_POPUP not to test for menu bars */
1079 if( !ispop &&
1080 bitmaps[bmpidx] >= HBMMENU_POPUP_CLOSE &&
1081 bitmaps[bmpidx] <= HBMMENU_POPUP_MINIMIZE) continue;
1082 if( !ispop && hassub) continue;
1083 test_mbs_help( ispop, hassub, mnuopt,
1084 hwnd, arrowwidth, ++count,
1085 bitmaps[bmpidx],
1086 bmsizes[szidx],
1087 MOD_txtsizes[txtidx].text,
1088 MOD_txtsizes[txtidx].size,
1089 MOD_txtsizes[txtidx].sc_size);
1090 }
1091 }
1092 }
1093 }
1094 DeleteObject( hbm);
1095 }
1096 }
1097 /* clean up */
1098 DestroyWindow(hwnd);
1099 }
1100
1101 static void test_menu_add_string( void )
1102 {
1103 HMENU hmenu;
1104 MENUITEMINFOA info;
1105 BOOL rc;
1106 int ret;
1107
1108 char string[0x80];
1109 char string2[0x80];
1110
1111 char strback[0x80];
1112 WCHAR strbackW[0x80];
1113 static CHAR blah[] = "blah";
1114 static const WCHAR expectedString[] = {'D','u','m','m','y',' ','s','t','r','i','n','g', 0};
1115
1116 hmenu = CreateMenu();
1117
1118 memset( &info, 0, sizeof info );
1119 info.cbSize = sizeof info;
1120 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_ID;
1121 info.dwTypeData = blah;
1122 info.cch = 6;
1123 info.dwItemData = 0;
1124 info.wID = 1;
1125 info.fState = 0;
1126 InsertMenuItemA(hmenu, 0, TRUE, &info );
1127
1128 memset( &info, 0, sizeof info );
1129 info.cbSize = sizeof info;
1130 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1131 info.dwTypeData = string;
1132 info.cch = sizeof string;
1133 string[0] = 0;
1134 GetMenuItemInfoA( hmenu, 0, TRUE, &info );
1135
1136 ok( !strcmp( string, "blah" ), "menu item name differed\n");
1137
1138 /* Test combination of ownerdraw and strings with GetMenuItemString(A/W) */
1139 strcpy(string, "Dummy string");
1140 memset(&info, 0x00, sizeof(info));
1141 info.cbSize= sizeof(MENUITEMINFOA);
1142 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1143 info.fType= MFT_OWNERDRAW;
1144 info.dwTypeData= string;
1145 rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1146 ok (rc, "InsertMenuItem failed\n");
1147
1148 strcpy(string,"Garbage");
1149 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1150 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1151
1152 SetLastError(0xdeadbeef);
1153 ret = GetMenuStringW( hmenu, 0, strbackW, 99, MF_BYPOSITION );
1154 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1155 win_skip("GetMenuStringW is not implemented\n");
1156 else
1157 {
1158 ok (ret, "GetMenuStringW on ownerdraw entry failed\n");
1159 ok (!lstrcmpW( strbackW, expectedString ), "Menu text from Unicode version incorrect\n");
1160 }
1161
1162 /* Just try some invalid parameter tests */
1163 SetLastError(0xdeadbeef);
1164 rc = SetMenuItemInfoA( hmenu, 0, TRUE, NULL );
1165 ret = GetLastError();
1166 ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1167 ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1168
1169 SetLastError(0xdeadbeef);
1170 rc = SetMenuItemInfoA( hmenu, 0, FALSE, NULL );
1171 ret = GetLastError();
1172 ok (!rc, "SetMenuItemInfoA succeeded unexpectedly\n");
1173 ok (ret == ERROR_INVALID_PARAMETER, "Expected 87, got %d\n", ret);
1174
1175 /* Just change ftype to string and see what text is stored */
1176 memset(&info, 0x00, sizeof(info));
1177 info.cbSize= sizeof(MENUITEMINFOA);
1178 info.fMask= MIIM_FTYPE; /* Set string type */
1179 info.fType= MFT_STRING;
1180 info.dwTypeData= (char *)0xdeadbeef;
1181 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1182 ok (rc, "SetMenuItemInfo failed\n");
1183
1184 /* Did we keep the old dwTypeData? */
1185 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1186 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1187
1188 /* Ensure change to bitmap type fails */
1189 memset(&info, 0x00, sizeof(info));
1190 info.cbSize= sizeof(MENUITEMINFOA);
1191 info.fMask= MIIM_FTYPE; /* Set as bitmap type */
1192 info.fType= MFT_BITMAP;
1193 info.dwTypeData= (char *)0xdeadbee2;
1194 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1195 ok (!rc, "SetMenuItemInfo unexpectedly worked\n");
1196
1197 /* Just change ftype back and ensure data hasn't been freed */
1198 info.fType= MFT_OWNERDRAW; /* Set as ownerdraw type */
1199 info.dwTypeData= (char *)0xdeadbee3;
1200 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1201 ok (rc, "SetMenuItemInfo failed\n");
1202
1203 /* Did we keep the old dwTypeData? */
1204 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1205 ok (!strcmp( strback, "Dummy string" ), "Menu text from Ansi version incorrect\n");
1206
1207 /* Just change string value (not type) */
1208 memset(&info, 0x00, sizeof(info));
1209 info.cbSize= sizeof(MENUITEMINFOA);
1210 info.fMask= MIIM_STRING; /* Set typeData */
1211 strcpy(string2, "string2");
1212 info.dwTypeData= string2;
1213 rc = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1214 ok (rc, "SetMenuItemInfo failed\n");
1215
1216 ok (GetMenuStringA( hmenu, 0, strback, 99, MF_BYPOSITION), "GetMenuString on ownerdraw entry failed\n");
1217 ok (!strcmp( strback, "string2" ), "Menu text from Ansi version incorrect\n");
1218
1219 /* crashes with wine 0.9.5 */
1220 memset(&info, 0x00, sizeof(info));
1221 info.cbSize= sizeof(MENUITEMINFOA);
1222 info.fMask= MIIM_FTYPE | MIIM_STRING; /* Set OwnerDraw + typeData */
1223 info.fType= MFT_OWNERDRAW;
1224 rc = InsertMenuItemA( hmenu, 0, TRUE, &info );
1225 ok (rc, "InsertMenuItem failed\n");
1226 ok (!GetMenuStringA( hmenu, 0, NULL, 0, MF_BYPOSITION),
1227 "GetMenuString on ownerdraw entry succeeded.\n");
1228 SetLastError(0xdeadbeef);
1229 ret = GetMenuStringW( hmenu, 0, NULL, 0, MF_BYPOSITION);
1230 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1231 win_skip("GetMenuStringW is not implemented\n");
1232 else
1233 ok (!ret, "GetMenuStringW on ownerdraw entry succeeded.\n");
1234
1235 DestroyMenu( hmenu );
1236 }
1237
1238 /* define building blocks for the menu item info tests */
1239 static int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
1240 {
1241 if (n <= 0) return 0;
1242 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
1243 return *str1 - *str2;
1244 }
1245
1246 static WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
1247 {
1248 WCHAR *p = dst;
1249 while ((*p++ = *src++));
1250 return dst;
1251 }
1252
1253 static void insert_menu_item( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state, UINT id,
1254 HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1255 void *type_data, UINT len, HBITMAP item, BOOL expect )
1256 {
1257 MENUITEMINFOA info;
1258 BOOL ret;
1259
1260 /* magic bitmap handle to test smaller cbSize */
1261 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1262 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1263 else
1264 info.cbSize = sizeof(info);
1265 info.fMask = mask;
1266 info.fType = type;
1267 info.fState = state;
1268 info.wID = id;
1269 info.hSubMenu = submenu;
1270 info.hbmpChecked = checked;
1271 info.hbmpUnchecked = unchecked;
1272 info.dwItemData = data;
1273 info.dwTypeData = type_data;
1274 info.cch = len;
1275 info.hbmpItem = item;
1276 SetLastError( 0xdeadbeef );
1277 if (ansi) ret = InsertMenuItemA( hmenu, 0, TRUE, &info );
1278 else ret = InsertMenuItemW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1279 if (!expect) ok_(__FILE__, line)( !ret, "InsertMenuItem should have failed.\n" );
1280 else ok_(__FILE__, line)( ret, "InsertMenuItem failed, err %u\n", GetLastError());
1281 }
1282
1283 static void check_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1284 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked,
1285 ULONG_PTR data, void *type_data, UINT in_len, UINT out_len,
1286 HBITMAP item, LPCSTR expname, BOOL expect, BOOL expstring )
1287 {
1288 MENUITEMINFOA info;
1289 BOOL ret;
1290 WCHAR buffer[80];
1291
1292 SetLastError( 0xdeadbeef );
1293 memset( &info, 0xcc, sizeof(info) );
1294 info.cbSize = sizeof(info);
1295 info.fMask = mask;
1296 info.dwTypeData = type_data;
1297 info.cch = in_len;
1298
1299 ret = ansi ? GetMenuItemInfoA( hmenu, 0, TRUE, &info ) :
1300 GetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW *)&info );
1301 if (!expect)
1302 {
1303 ok_(__FILE__, line)( !ret, "GetMenuItemInfo should have failed.\n" );
1304 return;
1305 }
1306 ok_(__FILE__, line)( ret, "GetMenuItemInfo failed, err %u\n", GetLastError());
1307 if (mask & MIIM_TYPE)
1308 ok_(__FILE__, line)( info.fType == type || info.fType == LOWORD(type),
1309 "wrong type %x/%x\n", info.fType, type );
1310 if (mask & MIIM_STATE)
1311 ok_(__FILE__, line)( info.fState == state || info.fState == LOWORD(state),
1312 "wrong state %x/%x\n", info.fState, state );
1313 if (mask & MIIM_ID)
1314 ok_(__FILE__, line)( info.wID == id || info.wID == LOWORD(id),
1315 "wrong id %x/%x\n", info.wID, id );
1316 if (mask & MIIM_SUBMENU)
1317 ok_(__FILE__, line)( info.hSubMenu == submenu || (ULONG_PTR)info.hSubMenu == LOWORD(submenu),
1318 "wrong submenu %p/%p\n", info.hSubMenu, submenu );
1319 if (mask & MIIM_CHECKMARKS)
1320 {
1321 ok_(__FILE__, line)( info.hbmpChecked == checked || (ULONG_PTR)info.hbmpChecked == LOWORD(checked),
1322 "wrong bmpchecked %p/%p\n", info.hbmpChecked, checked );
1323 ok_(__FILE__, line)( info.hbmpUnchecked == unchecked || (ULONG_PTR)info.hbmpUnchecked == LOWORD(unchecked),
1324 "wrong bmpunchecked %p/%p\n", info.hbmpUnchecked, unchecked );
1325 }
1326 if (mask & MIIM_DATA)
1327 ok_(__FILE__, line)( info.dwItemData == data || info.dwItemData == LOWORD(data),
1328 "wrong item data %lx/%lx\n", info.dwItemData, data );
1329 if (mask & MIIM_BITMAP)
1330 ok_(__FILE__, line)( info.hbmpItem == item || (ULONG_PTR)info.hbmpItem == LOWORD(item),
1331 "wrong bmpitem %p/%p\n", info.hbmpItem, item );
1332 ok_(__FILE__, line)( info.dwTypeData == type_data || (ULONG_PTR)info.dwTypeData == LOWORD(type_data),
1333 "wrong type data %p/%p\n", info.dwTypeData, type_data );
1334 ok_(__FILE__, line)( info.cch == out_len ||
1335 broken(! ansi && info.cch == 2 * out_len) /* East-Asian */,
1336 "wrong len %x/%x\n", info.cch, out_len );
1337 if (expname)
1338 {
1339 if(ansi)
1340 ok_(__FILE__, line)( !strncmp( expname, info.dwTypeData, out_len ),
1341 "menu item name differed from '%s' '%s'\n", expname, info.dwTypeData );
1342 else
1343 ok_(__FILE__, line)( !strncmpW( (WCHAR *)expname, (WCHAR *)info.dwTypeData, out_len ),
1344 "menu item name wrong\n" );
1345
1346 SetLastError( 0xdeadbeef );
1347 ret = ansi ? GetMenuStringA( hmenu, 0, (char *)buffer, 80, MF_BYPOSITION ) :
1348 GetMenuStringW( hmenu, 0, buffer, 80, MF_BYPOSITION );
1349 if (expstring)
1350 ok_(__FILE__, line)( ret, "GetMenuString failed, err %u\n", GetLastError());
1351 else
1352 ok_(__FILE__, line)( !ret, "GetMenuString should have failed\n" );
1353 }
1354 }
1355
1356 static void modify_menu( int line, HMENU hmenu, BOOL ansi, UINT flags, UINT_PTR id, void *data )
1357 {
1358 BOOL ret;
1359
1360 SetLastError( 0xdeadbeef );
1361 if (ansi) ret = ModifyMenuA( hmenu, 0, flags, id, data );
1362 else ret = ModifyMenuW( hmenu, 0, flags, id, data );
1363 ok_(__FILE__,line)( ret, "ModifyMenuA failed, err %u\n", GetLastError());
1364 }
1365
1366 static void set_menu_item_info( int line, HMENU hmenu, BOOL ansi, UINT mask, UINT type, UINT state,
1367 UINT id, HMENU submenu, HBITMAP checked, HBITMAP unchecked, ULONG_PTR data,
1368 void *type_data, UINT len, HBITMAP item )
1369
1370 {
1371 MENUITEMINFOA info;
1372 BOOL ret;
1373
1374 /* magic bitmap handle to test smaller cbSize */
1375 if (item == (HBITMAP)(ULONG_PTR)0xdeadbeef)
1376 info.cbSize = FIELD_OFFSET(MENUITEMINFOA,hbmpItem);
1377 else
1378 info.cbSize = sizeof(info);
1379 info.fMask = mask;
1380 info.fType = type;
1381 info.fState = state;
1382 info.wID = id;
1383 info.hSubMenu = submenu;
1384 info.hbmpChecked = checked;
1385 info.hbmpUnchecked = unchecked;
1386 info.dwItemData = data;
1387 info.dwTypeData = type_data;
1388 info.cch = len;
1389 info.hbmpItem = item;
1390 SetLastError( 0xdeadbeef );
1391 if (ansi) ret = SetMenuItemInfoA( hmenu, 0, TRUE, &info );
1392 else ret = SetMenuItemInfoW( hmenu, 0, TRUE, (MENUITEMINFOW*)&info );
1393 ok_(__FILE__, line)( ret, "SetMenuItemInfo failed, err %u\n", GetLastError());
1394 }
1395
1396 #define TMII_INSMI( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,eret1 )\
1397 hmenu = CreateMenu();\
1398 submenu = CreateMenu();\
1399 if(ansi)strcpy( string, init );\
1400 else strcpyW( string, init );\
1401 insert_menu_item( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, eret1 )
1402
1403 /* GetMenuItemInfo + GetMenuString */
1404 #define TMII_GMII( c2,l2,\
1405 d3,e3,f3,g3,h3,i3,j3,k3,l3,m3,\
1406 expname, eret2, eret3)\
1407 check_menu_item_info( __LINE__, hmenu, ansi, c2, d3, e3, f3, g3, h3, i3, j3, k3, l2, l3, m3, \
1408 expname, eret2, eret3 )
1409
1410 #define TMII_DONE \
1411 RemoveMenu(hmenu, 0, TRUE );\
1412 DestroyMenu( hmenu );\
1413 DestroyMenu( submenu );
1414
1415 /* modify menu */
1416 #define TMII_MODM( flags, id, data ) \
1417 modify_menu( __LINE__, hmenu, ansi, flags, id, data )
1418
1419 /* SetMenuItemInfo */
1420 #define TMII_SMII( c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1 ) \
1421 set_menu_item_info( __LINE__, hmenu, ansi, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1 )
1422
1423
1424 #define OK 1
1425 #define ER 0
1426
1427
1428 static void test_menu_iteminfo( void )
1429 {
1430 BOOL ansi = TRUE;
1431 char txtA[]="wine";
1432 char initA[]="XYZ";
1433 char emptyA[]="";
1434 WCHAR txtW[]={'W','i','n','e',0};
1435 WCHAR initW[]={'X','Y','Z',0};
1436 WCHAR emptyW[]={0};
1437 void *txt, *init, *empty, *string;
1438 HBITMAP hbm = CreateBitmap(1,1,1,1,NULL);
1439 char stringA[0x80];
1440 HMENU hmenu, submenu;
1441 HBITMAP dummy_hbm = (HBITMAP)(ULONG_PTR)0xdeadbeef;
1442
1443 do {
1444 if( ansi) {txt=txtA;init=initA;empty=emptyA;string=stringA;}
1445 else {txt=txtW;init=initW;empty=emptyW;string=stringA;}
1446 trace( "%s string %p hbm %p txt %p\n", ansi ? "ANSI tests: " : "Unicode tests:", string, hbm, txt);
1447 /* test all combinations of MFT_STRING, MFT_OWNERDRAW and MFT_BITMAP */
1448 /* (since MFT_STRING is zero, there are four of them) */
1449 TMII_INSMI( MIIM_TYPE, MFT_STRING, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1450 TMII_GMII ( MIIM_TYPE, 80,
1451 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1452 txt, OK, OK );
1453 TMII_DONE
1454 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1455 TMII_GMII ( MIIM_TYPE, 80,
1456 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1457 NULL, OK, ER );
1458 TMII_DONE
1459 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1460 TMII_GMII ( MIIM_TYPE, 80,
1461 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1462 NULL, OK, ER );
1463 TMII_DONE
1464 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1465 TMII_GMII ( MIIM_TYPE, 80,
1466 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1467 NULL, OK, ER );
1468 TMII_DONE
1469 /* not enough space for name*/
1470 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1471 TMII_GMII ( MIIM_TYPE, 0,
1472 MFT_STRING, 0, 0, 0, 0, 0, 0, NULL, 4, 0,
1473 NULL, OK, OK );
1474 TMII_DONE
1475 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1476 TMII_GMII ( MIIM_TYPE, 5,
1477 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1478 txt, OK, OK );
1479 TMII_DONE
1480 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1481 TMII_GMII ( MIIM_TYPE, 4,
1482 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 3, 0,
1483 txt, OK, OK );
1484 TMII_DONE
1485 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1486 TMII_GMII ( MIIM_TYPE, 0,
1487 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1488 NULL, OK, ER );
1489 TMII_DONE
1490 /* cannot combine MIIM_TYPE with some other flags */
1491 TMII_INSMI( MIIM_TYPE|MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1492 TMII_DONE
1493 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1494 TMII_GMII ( MIIM_TYPE|MIIM_STRING, 80,
1495 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1496 NULL, ER, OK );
1497 TMII_DONE
1498 TMII_INSMI( MIIM_TYPE|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, ER );
1499 TMII_DONE
1500 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1501 TMII_GMII ( MIIM_TYPE|MIIM_FTYPE, 80,
1502 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1503 NULL, ER, OK );
1504 TMII_DONE
1505 TMII_INSMI( MIIM_TYPE|MIIM_BITMAP, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, 6, hbm, ER );
1506 TMII_DONE
1507 /* but succeeds with some others */
1508 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1509 TMII_GMII ( MIIM_TYPE|MIIM_SUBMENU, 80,
1510 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1511 txt, OK, OK );
1512 TMII_DONE
1513 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1514 TMII_GMII ( MIIM_TYPE|MIIM_STATE, 80,
1515 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1516 txt, OK, OK );
1517 TMII_DONE
1518 TMII_INSMI( MIIM_TYPE|MIIM_ID, MFT_STRING, -1, 888, 0, 0, 0, -1, txt, 6, 0, OK );
1519 TMII_GMII ( MIIM_TYPE|MIIM_ID, 80,
1520 MFT_STRING, 0, 888, 0, 0, 0, 0, string, 4, 0,
1521 txt, OK, OK );
1522 TMII_DONE
1523 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING, -1, -1, 0, 0, 0, 999, txt, 6, 0, OK );
1524 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1525 MFT_STRING, 0, 0, 0, 0, 0, 999, string, 4, 0,
1526 txt, OK, OK );
1527 TMII_DONE
1528 /* to be continued */
1529 /* set text with MIIM_TYPE and retrieve with MIIM_STRING */
1530 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1531 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1532 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1533 txt, OK, OK );
1534 TMII_DONE
1535 /* set text with MIIM_TYPE and retrieve with MIIM_STRING; MFT_OWNERDRAW causes an empty string */
1536 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1537 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1538 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1539 empty, OK, ER );
1540 TMII_DONE
1541 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1542 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1543 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1544 empty, OK, ER );
1545 TMII_DONE
1546 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1547 TMII_GMII ( MIIM_FTYPE, 80,
1548 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, 0,
1549 init, OK, ER );
1550 TMII_DONE
1551 TMII_INSMI( MIIM_TYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1552 TMII_GMII ( 0, 80,
1553 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1554 init, OK, OK );
1555 TMII_DONE
1556 /* contrary to MIIM_TYPE,you can set the text for an owner draw menu */
1557 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1558 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1559 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1560 txt, OK, OK );
1561 TMII_DONE
1562 /* same but retrieve with MIIM_TYPE */
1563 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1564 TMII_GMII ( MIIM_TYPE, 80,
1565 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1566 NULL, OK, OK );
1567 TMII_DONE
1568 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1569 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1570 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 0, 0,
1571 empty, OK, ER );
1572 TMII_DONE
1573 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1574 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1575 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1576 empty, OK, ER );
1577 TMII_DONE
1578 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1579 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1580 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, 0,
1581 NULL, OK, ER );
1582 TMII_DONE
1583
1584 /* How is that with bitmaps? */
1585 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1586 TMII_GMII ( MIIM_TYPE, 80,
1587 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1588 NULL, OK, ER );
1589 TMII_DONE
1590 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1591 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1592 0, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1593 init, OK, ER );
1594 TMII_DONE
1595 /* MIIM_BITMAP does not like MFT_BITMAP */
1596 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, hbm, ER );
1597 TMII_DONE
1598 /* no problem with OWNERDRAWN */
1599 TMII_INSMI( MIIM_BITMAP|MIIM_FTYPE, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1600 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1601 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1602 init, OK, ER );
1603 TMII_DONE
1604 /* setting MFT_BITMAP with MFT_FTYPE fails anyway */
1605 TMII_INSMI( MIIM_FTYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, 0, -1, 0, ER );
1606 TMII_DONE
1607
1608 /* menu with submenu */
1609 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1610 TMII_GMII ( MIIM_SUBMENU, 80,
1611 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1612 init, OK, ER );
1613 TMII_DONE
1614 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, empty, 0, 0, OK );
1615 TMII_GMII ( MIIM_SUBMENU, 80,
1616 0, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1617 init, OK, ER );
1618 TMII_DONE
1619 /* menu with submenu, without MIIM_SUBMENU the submenufield is cleared */
1620 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, submenu, 0, 0, -1, txt, 0, 0, OK );
1621 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1622 MFT_STRING|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 0, 0,
1623 empty, OK, ER );
1624 TMII_GMII ( MIIM_SUBMENU|MIIM_FTYPE, 80,
1625 MFT_SEPARATOR, 0, 0, submenu, 0, 0, 0, string, 80, 0,
1626 empty, OK, ER );
1627 TMII_DONE
1628 /* menu with invalid submenu */
1629 TMII_INSMI( MIIM_SUBMENU|MIIM_FTYPE, MFT_STRING, -1, -1, (HMENU)999, 0, 0, -1, txt, 0, 0, ER );
1630 TMII_DONE
1631 /* Separator */
1632 TMII_INSMI( MIIM_TYPE, MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, txt, 0, 0, OK );
1633 TMII_GMII ( MIIM_TYPE, 80,
1634 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1635 NULL, OK, ER );
1636 TMII_DONE
1637 TMII_INSMI( MIIM_TYPE, MFT_BITMAP|MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, hbm, 6, 0, OK );
1638 TMII_GMII ( MIIM_TYPE, 80,
1639 MFT_BITMAP|MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1640 NULL, OK, ER );
1641 TMII_DONE
1642 /* SEPARATOR and STRING go well together */
1643 /* BITMAP and STRING go well together */
1644 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1645 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1646 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1647 txt, OK, OK );
1648 TMII_DONE
1649 /* BITMAP, SEPARATOR and STRING go well together */
1650 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1651 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, 80,
1652 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, hbm,
1653 txt, OK, OK );
1654 TMII_DONE
1655 /* last two tests, but use MIIM_TYPE to retrieve info */
1656 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1657 TMII_GMII ( MIIM_TYPE, 80,
1658 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1659 NULL, OK, OK );
1660 TMII_DONE
1661 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1662 TMII_GMII ( MIIM_TYPE, 80,
1663 MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1664 NULL, OK, OK );
1665 TMII_DONE
1666 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1667 TMII_GMII ( MIIM_TYPE, 80,
1668 MFT_SEPARATOR|MFT_BITMAP, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1669 NULL, OK, OK );
1670 TMII_DONE
1671 /* same three with MFT_OWNERDRAW */
1672 TMII_INSMI( MIIM_FTYPE|MIIM_STRING, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, 0, OK );
1673 TMII_GMII ( MIIM_TYPE, 80,
1674 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1675 NULL, OK, OK );
1676 TMII_DONE
1677 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1678 TMII_GMII ( MIIM_TYPE, 80,
1679 MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1680 NULL, OK, OK );
1681 TMII_DONE
1682 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1683 TMII_GMII ( MIIM_TYPE, 80,
1684 MFT_SEPARATOR|MFT_BITMAP|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 4, hbm,
1685 NULL, OK, OK );
1686 TMII_DONE
1687
1688 TMII_INSMI( MIIM_STRING|MIIM_FTYPE|MIIM_ID, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1689 TMII_GMII ( MIIM_TYPE, 80,
1690 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1691 NULL, OK, OK );
1692 TMII_DONE
1693 /* test with modifymenu: string is preserved after setting OWNERDRAW */
1694 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1695 TMII_MODM( MFT_OWNERDRAW, -1, (void*)787 );
1696 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_DATA, 80,
1697 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 787, string, 4, 0,
1698 txt, OK, OK );
1699 TMII_DONE
1700 /* same with bitmap: now the text is cleared */
1701 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1702 TMII_MODM( MFT_BITMAP, 545, hbm );
1703 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1704 MFT_BITMAP, 0, 545, 0, 0, 0, 0, string, 0, hbm,
1705 empty, OK, ER );
1706 TMII_DONE
1707 /* start with bitmap: now setting text clears it (though he flag is raised) */
1708 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1709 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1710 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 0, hbm,
1711 empty, OK, ER );
1712 TMII_MODM( MFT_STRING, 545, txt );
1713 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1714 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 4, 0,
1715 txt, OK, OK );
1716 TMII_DONE
1717 /*repeat with text NULL */
1718 TMII_INSMI( MIIM_BITMAP, MFT_STRING, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1719 TMII_MODM( MFT_STRING, 545, NULL );
1720 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1721 MFT_SEPARATOR, 0, 545, 0, 0, 0, 0, string, 0, 0,
1722 empty, OK, ER );
1723 TMII_DONE
1724 /* repeat with text "" */
1725 TMII_INSMI( MIIM_BITMAP, -1 , -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1726 TMII_MODM( MFT_STRING, 545, empty );
1727 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_ID, 80,
1728 MFT_STRING, 0, 545, 0, 0, 0, 0, string, 0, 0,
1729 empty, OK, ER );
1730 TMII_DONE
1731 /* start with bitmap: set ownerdraw */
1732 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, hbm, OK );
1733 TMII_MODM( MFT_OWNERDRAW, -1, (void *)232 );
1734 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP|MIIM_DATA, 80,
1735 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 232, string, 0, hbm,
1736 empty, OK, ER );
1737 TMII_DONE
1738 /* ask nothing */
1739 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, hbm, OK );
1740 TMII_GMII ( 0, 80,
1741 0, 0, 0, 0, 0, 0, 0, string, 80, 0,
1742 init, OK, OK );
1743 TMII_DONE
1744 /* some tests with small cbSize: the hbmpItem is to be ignored */
1745 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1746 TMII_GMII ( MIIM_TYPE, 80,
1747 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1748 NULL, OK, ER );
1749 TMII_DONE
1750 TMII_INSMI( MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, 0, -1, dummy_hbm, OK );
1751 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1752 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, NULL,
1753 init, OK, ER );
1754 TMII_DONE
1755 TMII_INSMI( MIIM_STRING|MIIM_BITMAP, -1, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1756 TMII_GMII ( MIIM_TYPE, 80,
1757 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, NULL,
1758 txt, OK, OK );
1759 TMII_DONE
1760 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1761 TMII_GMII ( MIIM_TYPE, 80,
1762 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1763 NULL, OK, OK );
1764 TMII_DONE
1765 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1766 TMII_GMII ( MIIM_TYPE, 80,
1767 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1768 NULL, OK, OK );
1769 TMII_DONE
1770 TMII_INSMI( MIIM_FTYPE|MIIM_STRING|MIIM_BITMAP, MFT_SEPARATOR|MFT_OWNERDRAW, -1, -1, 0, 0, 0, -1, txt, 6, dummy_hbm, OK );
1771 TMII_GMII ( MIIM_TYPE, 80,
1772 MFT_SEPARATOR|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 4, NULL,
1773 NULL, OK, OK );
1774 TMII_DONE
1775 /* MIIM_TYPE by itself does not get/set the dwItemData for OwnerDrawn menus */
1776 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1777 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1778 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 343, 0, 0, 0,
1779 NULL, OK, ER );
1780 TMII_DONE
1781 TMII_INSMI( MIIM_TYPE|MIIM_DATA, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1782 TMII_GMII ( MIIM_TYPE, 80,
1783 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1784 NULL, OK, ER );
1785 TMII_DONE
1786 TMII_INSMI( MIIM_TYPE, MFT_STRING|MFT_OWNERDRAW, -1, -1, 0, 0, 0, 343, txt, 0, 0, OK );
1787 TMII_GMII ( MIIM_TYPE|MIIM_DATA, 80,
1788 MFT_STRING|MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1789 NULL, OK, ER );
1790 TMII_DONE
1791 /* set a string menu to ownerdraw with MIIM_TYPE */
1792 TMII_INSMI( MIIM_TYPE, MFT_STRING, -2, -2, 0, 0, 0, -2, txt, -2, 0, OK );
1793 TMII_SMII ( MIIM_TYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1794 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1795 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, string, 4, 0,
1796 txt, OK, OK );
1797 TMII_DONE
1798 /* test with modifymenu add submenu */
1799 TMII_INSMI( MIIM_STRING, MFT_STRING, -1, -1, 0, 0, 0, -1, txt, 0, 0, OK );
1800 TMII_MODM( MF_POPUP, (UINT_PTR)submenu, txt );
1801 TMII_GMII ( MIIM_FTYPE|MIIM_STRING|MIIM_SUBMENU, 80,
1802 MFT_STRING, 0, 0, submenu, 0, 0, 0, string, 4, 0,
1803 txt, OK, OK );
1804 TMII_GMII ( MIIM_TYPE, 80,
1805 MFT_STRING, 0, 0, 0, 0, 0, 0, string, 4, 0,
1806 txt, OK, OK );
1807 TMII_DONE
1808 /* MFT_SEPARATOR bit is kept when the text is added */
1809 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1810 TMII_SMII( MIIM_STRING, 0, 0, 0, 0, 0, 0, 0, txt, 0, 0 );
1811 TMII_GMII ( MIIM_STRING|MIIM_FTYPE, 80,
1812 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 4, 0,
1813 txt, OK, OK );
1814 TMII_DONE
1815 /* MFT_SEPARATOR bit is kept when bitmap is added */
1816 TMII_INSMI( MIIM_STRING|MIIM_FTYPE, MFT_STRING, -1, -1, 0, 0, 0, -1, NULL, 0, 0, OK );
1817 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, hbm );
1818 TMII_GMII ( MIIM_BITMAP|MIIM_FTYPE, 80,
1819 MFT_SEPARATOR, 0, 0, 0, 0, 0, 0, string, 80, hbm,
1820 init, OK, ER );
1821 TMII_DONE
1822 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1823 Only the low word of the dwTypeData is used.
1824 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1825 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1826 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1827 TMII_GMII ( MIIM_TYPE, 80,
1828 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1829 NULL, OK, OK );
1830 TMII_DONE
1831 /* Type flags */
1832 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1833 TMII_GMII ( MIIM_TYPE, 80,
1834 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1835 NULL, OK, OK );
1836 TMII_DONE
1837 /* State flags */
1838 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1839 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1840 TMII_GMII ( MIIM_STATE, 80,
1841 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1842 NULL, OK, OK );
1843 TMII_DONE
1844 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1845 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1846 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1847 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1848 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1849 NULL, OK, OK );
1850 TMII_DONE
1851 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1852 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1853 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1854 TMII_GMII ( MIIM_FTYPE, 80,
1855 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1856 NULL, OK, OK );
1857 TMII_GMII ( MIIM_TYPE, 80,
1858 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1859 NULL, OK, OK );
1860 TMII_GMII ( MIIM_FTYPE, 80,
1861 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1862 NULL, OK, OK );
1863 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1864 TMII_GMII ( MIIM_TYPE, 80,
1865 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1866 NULL, OK, OK );
1867 TMII_DONE
1868 /* Bitmaps inserted with MIIM_TYPE and MFT_BITMAP:
1869 Only the low word of the dwTypeData is used.
1870 Use a magic bitmap here (Word 95 uses this to create its MDI menu buttons) */
1871 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_RIGHTJUSTIFY, -1, -1, 0, 0, 0, -1,
1872 (HMENU)MAKELONG(HBMMENU_MBAR_CLOSE, 0x1234), -1, 0, OK );
1873 TMII_GMII ( MIIM_TYPE, 80,
1874 MFT_BITMAP | MFT_RIGHTJUSTIFY, 0, 0, 0, 0, 0, 0, HBMMENU_MBAR_CLOSE, 0, HBMMENU_MBAR_CLOSE,
1875 NULL, OK, OK );
1876 TMII_DONE
1877 /* Type flags */
1878 TMII_INSMI( MIIM_TYPE, MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1879 TMII_GMII ( MIIM_TYPE, 80,
1880 MFT_BITMAP | MFT_MENUBARBREAK | MFT_RADIOCHECK | MFT_RIGHTJUSTIFY | MFT_RIGHTORDER, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1881 NULL, OK, OK );
1882 TMII_DONE
1883 /* State flags */
1884 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1885 TMII_SMII( MIIM_STATE, -1, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 0, 0 );
1886 TMII_GMII ( MIIM_STATE, 80,
1887 0, MFS_CHECKED | MFS_DEFAULT | MFS_GRAYED | MFS_HILITE, 0, 0, 0, 0, 0, 0, 80, 0,
1888 NULL, OK, OK );
1889 TMII_DONE
1890 /* The style MFT_RADIOCHECK cannot be set with MIIM_CHECKMARKS only */
1891 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1892 TMII_SMII( MIIM_CHECKMARKS, MFT_RADIOCHECK, 0, 0, 0, hbm, hbm, 0, 0, 0, 0 );
1893 TMII_GMII ( MIIM_CHECKMARKS | MIIM_TYPE, 80,
1894 MFT_BITMAP, 0, 0, 0, hbm, hbm, 0, hbm, 0, hbm,
1895 NULL, OK, OK );
1896 TMII_DONE
1897 /* MFT_BITMAP is added automatically by GetMenuItemInfo() for MIIM_TYPE */
1898 TMII_INSMI( MIIM_TYPE, MFT_BITMAP, -1, -1, 0, 0, 0, -1, hbm, -1, 0, OK );
1899 TMII_SMII( MIIM_FTYPE, MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, (HBITMAP)0x1234, 0, 0 );
1900 TMII_GMII ( MIIM_FTYPE, 80,
1901 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1902 NULL, OK, OK );
1903 TMII_GMII ( MIIM_TYPE, 80,
1904 MFT_BITMAP | MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, hbm, 0, hbm,
1905 NULL, OK, OK );
1906 TMII_GMII ( MIIM_FTYPE, 80,
1907 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, 0, 80, 0,
1908 NULL, OK, OK );
1909 TMII_SMII( MIIM_BITMAP, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL );
1910 TMII_GMII ( MIIM_TYPE, 80,
1911 MFT_OWNERDRAW, 0, 0, 0, 0, 0, 0, NULL, 0, NULL,
1912 NULL, OK, OK );
1913 TMII_DONE
1914 } while( !(ansi = !ansi) );
1915 DeleteObject( hbm);
1916 }
1917
1918 /*
1919 The following tests try to confirm the algorithm used to return the menu items
1920 when there is a collision between a menu item and a popup menu
1921 */
1922 static void test_menu_search_bycommand( void )
1923 {
1924 HMENU hmenu, hmenuSub, hmenuSub2;
1925 MENUITEMINFOA info;
1926 BOOL rc;
1927 UINT id;
1928 char strback[0x80];
1929 char strIn[0x80];
1930 static CHAR menuitem[] = "MenuItem",
1931 menuitem2[] = "MenuItem 2";
1932
1933 /* Case 1: Menu containing a menu item */
1934 hmenu = CreateMenu();
1935
1936 memset( &info, 0, sizeof info );
1937 info.cbSize = sizeof info;
1938 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
1939 info.fType = MFT_STRING;
1940 strcpy(strIn, "Case 1 MenuItem");
1941 info.dwTypeData = strIn;
1942 info.wID = (UINT) 0x1234;
1943
1944 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
1945 ok (rc, "Inserting the menuitem failed\n");
1946
1947 id = GetMenuItemID(hmenu, 0);
1948 ok (id == 0x1234, "Getting the menuitem id failed(gave %x)\n", id);
1949
1950 /* Confirm the menuitem was given the id supplied (getting by position) */
1951 memset( &info, 0, sizeof info );
1952 strback[0] = 0x00;
1953 info.cbSize = sizeof(MENUITEMINFOA);
1954 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1955 info.dwTypeData = strback;
1956 info.cch = sizeof(strback);
1957
1958 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1959 ok (rc, "Getting the menu items info failed\n");
1960 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1961 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1962
1963 /* Search by id - Should return the item */
1964 memset( &info, 0, sizeof info );
1965 strback[0] = 0x00;
1966 info.cbSize = sizeof(MENUITEMINFOA);
1967 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1968 info.dwTypeData = strback;
1969 info.cch = sizeof(strback);
1970 rc = GetMenuItemInfoA(hmenu, 0x1234, FALSE, &info); /* Get by ID */
1971
1972 ok (rc, "Getting the menu items info failed\n");
1973 ok (info.wID == 0x1234, "IDs differ for the menuitem\n");
1974 ok (!strcmp(info.dwTypeData, "Case 1 MenuItem"), "Returned item has wrong label\n");
1975
1976 DestroyMenu( hmenu );
1977
1978 /* Case 2: Menu containing a popup menu */
1979 hmenu = CreateMenu();
1980 hmenuSub = CreateMenu();
1981
1982 strcpy(strIn, "Case 2 SubMenu");
1983 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, strIn);
1984 ok (rc, "Inserting the popup menu into the main menu failed\n");
1985
1986 id = GetMenuItemID(hmenu, 0);
1987 ok (id == -1, "Getting the menuitem id unexpectedly worked (gave %x)\n", id);
1988
1989 /* Confirm the menuitem itself was given an id the same as the HMENU, (getting by position) */
1990 memset( &info, 0, sizeof info );
1991 strback[0] = 0x00;
1992 info.cbSize = sizeof(MENUITEMINFOA);
1993 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
1994 info.dwTypeData = strback;
1995 info.cch = sizeof(strback);
1996 info.wID = 0xdeadbeef;
1997
1998 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info); /* Get by position */
1999 ok (rc, "Getting the menu items info failed\n");
2000 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the menuitem\n");
2001 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2002
2003 /* Search by id - returns the popup menu itself */
2004 memset( &info, 0, sizeof info );
2005 strback[0] = 0x00;
2006 info.cbSize = sizeof(MENUITEMINFOA);
2007 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2008 info.dwTypeData = strback;
2009 info.cch = sizeof(strback);
2010 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2011
2012 ok (rc, "Getting the menu items info failed\n");
2013 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2014 ok (!strcmp(info.dwTypeData, "Case 2 SubMenu"), "Returned item has wrong label\n");
2015
2016 /*
2017 Now add an item after it with the same id
2018 */
2019 memset( &info, 0, sizeof info );
2020 info.cbSize = sizeof info;
2021 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2022 info.fType = MFT_STRING;
2023 strcpy(strIn, "Case 2 MenuItem 1");
2024 info.dwTypeData = strIn;
2025 info.wID = (UINT_PTR) hmenuSub;
2026 rc = InsertMenuItemA(hmenu, -1, TRUE, &info );
2027 ok (rc, "Inserting the menuitem failed\n");
2028
2029 /* Search by id - returns the item which follows the popup menu */
2030 memset( &info, 0, sizeof info );
2031 strback[0] = 0x00;
2032 info.cbSize = sizeof(MENUITEMINFOA);
2033 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2034 info.dwTypeData = strback;
2035 info.cch = sizeof(strback);
2036 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2037
2038 ok (rc, "Getting the menu items info failed\n");
2039 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2040 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 1"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2041
2042 /*
2043 Now add an item before the popup (with the same id)
2044 */
2045 memset( &info, 0, sizeof info );
2046 info.cbSize = sizeof info;
2047 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2048 info.fType = MFT_STRING;
2049 strcpy(strIn, "Case 2 MenuItem 2");
2050 info.dwTypeData = strIn;
2051 info.wID = (UINT_PTR) hmenuSub;
2052 rc = InsertMenuItemA(hmenu, 0, TRUE, &info );
2053 ok (rc, "Inserting the menuitem failed\n");
2054
2055 /* Search by id - returns the item which precedes the popup menu */
2056 memset( &info, 0, sizeof info );
2057 strback[0] = 0x00;
2058 info.cbSize = sizeof(MENUITEMINFOA);
2059 info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING;
2060 info.dwTypeData = strback;
2061 info.cch = sizeof(strback);
2062 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info); /* Get by ID */
2063
2064 ok (rc, "Getting the menu items info failed\n");
2065 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for the popup menu\n");
2066 ok (!strcmp(info.dwTypeData, "Case 2 MenuItem 2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2067
2068 DestroyMenu( hmenu );
2069 DestroyMenu( hmenuSub );
2070
2071 /*
2072 Case 3: Menu containing a popup menu which in turn
2073 contains 2 items with the same id as the popup itself
2074 */
2075
2076 hmenu = CreateMenu();
2077 hmenuSub = CreateMenu();
2078
2079 memset( &info, 0, sizeof info );
2080 info.cbSize = sizeof info;
2081 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2082 info.fType = MFT_STRING;
2083 info.dwTypeData = menuitem;
2084 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2085
2086 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2087 ok (rc, "Inserting the popup menu into the main menu failed\n");
2088
2089 rc = InsertMenuItemA(hmenuSub, 0, TRUE, &info );
2090 ok (rc, "Inserting the sub menu menuitem failed\n");
2091
2092 memset( &info, 0, sizeof info );
2093 info.cbSize = sizeof info;
2094 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2095 info.fType = MFT_STRING;
2096 info.dwTypeData = menuitem2;
2097 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2098
2099 rc = InsertMenuItemA(hmenuSub, 1, TRUE, &info );
2100 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2101
2102 /* Prove that you can't query the id of a popup directly (By position) */
2103 id = GetMenuItemID(hmenu, 0);
2104 ok (id == -1, "Getting the sub menu id should have failed because it's a popup (gave %x)\n", id);
2105
2106 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2107 memset( &info, 0, sizeof info );
2108 strback[0] = 0x00;
2109 info.cbSize = sizeof(MENUITEMINFOA);
2110 info.fMask = MIIM_STRING | MIIM_ID;
2111 info.dwTypeData = strback;
2112 info.cch = sizeof(strback);
2113
2114 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2115 ok (rc, "Getting the menus info failed\n");
2116 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2117 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2118 DestroyMenu( hmenu );
2119 DestroyMenu( hmenuSub );
2120
2121 /*
2122 Case 4: Menu containing 2 popup menus, the second
2123 contains 2 items with the same id as the first popup menu
2124 */
2125 hmenu = CreateMenu();
2126 hmenuSub = CreateMenu();
2127 hmenuSub2 = CreateMenu();
2128
2129 rc = InsertMenuA(hmenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2130 ok (rc, "Inserting the popup menu into the main menu failed\n");
2131
2132 rc = InsertMenuA(hmenu, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub2, "Submenu2");
2133 ok (rc, "Inserting the popup menu into the main menu failed\n");
2134
2135 memset( &info, 0, sizeof info );
2136 info.cbSize = sizeof info;
2137 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2138 info.fType = MFT_STRING;
2139 info.dwTypeData = menuitem;
2140 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2141
2142 rc = InsertMenuItemA(hmenuSub2, 0, TRUE, &info );
2143 ok (rc, "Inserting the sub menu menuitem failed\n");
2144
2145 memset( &info, 0, sizeof info );
2146 info.cbSize = sizeof info;
2147 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_ID;
2148 info.fType = MFT_STRING;
2149 info.dwTypeData = menuitem2;
2150 info.wID = (UINT_PTR) hmenuSub; /* Enforce id collisions with the hmenu of the popup submenu*/
2151
2152 rc = InsertMenuItemA(hmenuSub2, 1, TRUE, &info );
2153 ok (rc, "Inserting the sub menu menuitem 2 failed\n");
2154
2155 /* Prove getting the item info via ID returns the first item (not the popup or 2nd item)*/
2156 memset( &info, 0, sizeof info );
2157 strback[0] = 0x00;
2158 info.cbSize = sizeof(MENUITEMINFOA);
2159 info.fMask = MIIM_STRING | MIIM_ID;
2160 info.dwTypeData = strback;
2161 info.cch = sizeof(strback);
2162
2163 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub, FALSE, &info);
2164 ok (rc, "Getting the menus info failed\n");
2165 ok (info.wID == (UINT_PTR)hmenuSub, "IDs differ for popup menu\n");
2166 ok (!strcmp(info.dwTypeData, "MenuItem"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2167
2168 memset( &info, 0, sizeof info );
2169 strback[0] = 0x00;
2170 info.cbSize = sizeof(MENUITEMINFOA);
2171 info.fMask = MIIM_STRING | MIIM_ID;
2172 info.dwTypeData = strback;
2173 info.cch = sizeof(strback);
2174
2175 rc = GetMenuItemInfoA(hmenu, (UINT_PTR)hmenuSub2, FALSE, &info);
2176 ok (rc, "Getting the menus info failed\n");
2177 ok (info.wID == (UINT_PTR)hmenuSub2, "IDs differ for popup menu\n");
2178 ok (!strcmp(info.dwTypeData, "Submenu2"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2179
2180 DestroyMenu( hmenu );
2181 DestroyMenu( hmenuSub );
2182 DestroyMenu( hmenuSub2 );
2183
2184
2185 /*
2186 Case 5: Menu containing a popup menu which in turn
2187 contains an item with a different id than the popup menu.
2188 This tests the fallback to a popup menu ID.
2189 */
2190
2191 hmenu = CreateMenu();
2192 hmenuSub = CreateMenu();
2193
2194 rc = AppendMenuA(hmenu, MF_POPUP | MF_STRING, (UINT_PTR)hmenuSub, "Submenu");
2195 ok (rc, "Appending the popup menu to the main menu failed\n");
2196
2197 rc = AppendMenuA(hmenuSub, MF_STRING, 102, "Item");
2198 ok (rc, "Appending the item to the popup menu failed\n");
2199
2200 /* Set the ID for hmenuSub */
2201 info.cbSize = sizeof(info);
2202 info.fMask = MIIM_ID;
2203 info.wID = 101;
2204
2205 rc = SetMenuItemInfoA(hmenu, 0, TRUE, &info);
2206 ok(rc, "Setting the ID for the popup menu failed\n");
2207
2208 /* Check if the ID has been set */
2209 info.wID = 0;
2210 rc = GetMenuItemInfoA(hmenu, 0, TRUE, &info);
2211 ok(rc, "Getting the ID for the popup menu failed\n");
2212 ok(info.wID == 101, "The ID for the popup menu has not been set\n");
2213
2214 /* Prove getting the item info via ID returns the popup menu */
2215 memset( &info, 0, sizeof(info));
2216 strback[0] = 0x00;
2217 info.cbSize = sizeof(MENUITEMINFOA);
2218 info.fMask = MIIM_STRING | MIIM_ID;
2219 info.dwTypeData = strback;
2220 info.cch = sizeof(strback);
2221
2222 rc = GetMenuItemInfoA(hmenu, 101, FALSE, &info);
2223 ok (rc, "Getting the menu info failed\n");
2224 ok (info.wID == 101, "IDs differ\n");
2225 ok (!strcmp(info.dwTypeData, "Submenu"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2226
2227 /* Also look for the menu item */
2228 memset( &info, 0, sizeof(info));
2229 strback[0] = 0x00;
2230 info.cbSize = sizeof(MENUITEMINFOA);
2231 info.fMask = MIIM_STRING | MIIM_ID;
2232 info.dwTypeData = strback;
2233 info.cch = sizeof(strback);
2234
2235 rc = GetMenuItemInfoA(hmenu, 102, FALSE, &info);
2236 ok (rc, "Getting the menu info failed\n");
2237 ok (info.wID == 102, "IDs differ\n");
2238 ok (!strcmp(info.dwTypeData, "Item"), "Returned item has wrong label (%s)\n", info.dwTypeData);
2239
2240 DestroyMenu(hmenu);
2241 DestroyMenu(hmenuSub);
2242 }
2243
2244 struct menu_item_pair_s {
2245 UINT uMenu; /* 1 - top level menu, [0-Menu 1-Enabled 2-Disabled]
2246 * 2 - 2nd level menu, [0-Popup 1-Enabled 2-Disabled]
2247 * 3 - 3rd level menu, [0-Enabled 1-Disabled] */
2248 UINT uItem;
2249 };
2250
2251 static struct menu_mouse_tests_s {
2252 DWORD type;
2253 struct menu_item_pair_s menu_item_pairs[5]; /* for mousing */
2254 WORD wVk[5]; /* keys */
2255 BOOL bMenuVisible;
2256 BOOL _todo_wine;
2257 } menu_tests[] = {
2258 /* for each test, send keys or clicks and check for menu visibility */
2259 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE }, /* test 0 */
2260 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2261 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2262 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2263 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 0}, TRUE, FALSE },
2264 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2265 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2266 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, VK_ESCAPE, 0}, FALSE, FALSE },
2267 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', VK_ESCAPE, 0}, TRUE, FALSE },
2268 { INPUT_KEYBOARD, {{0}}, {VK_ESCAPE, 0}, FALSE, FALSE },
2269 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2270 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2271 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 0}, TRUE, FALSE },
2272 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2273 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2274 { INPUT_KEYBOARD, {{0}}, {'D', 0}, FALSE, FALSE },
2275 { INPUT_KEYBOARD, {{0}}, {VK_MENU, 'M', 'P', 0}, TRUE, FALSE },
2276 { INPUT_KEYBOARD, {{0}}, {'E', 0}, FALSE, FALSE },
2277 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, TRUE, FALSE },
2278 { INPUT_KEYBOARD, {{0}}, {VK_F10, 0}, FALSE, FALSE },
2279
2280 { INPUT_MOUSE, {{1, 2}, {0}}, {0}, TRUE, TRUE }, /* test 20 */
2281 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2282 { INPUT_MOUSE, {{1, 0}, {0}}, {0}, TRUE, TRUE },
2283 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2284 { INPUT_MOUSE, {{1, 0}, {2, 2}, {0}}, {0}, TRUE, TRUE },
2285 { INPUT_MOUSE, {{2, 1}, {0}}, {0}, FALSE, FALSE },
2286 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2287 { INPUT_MOUSE, {{3, 0}, {0}}, {0}, FALSE, FALSE },
2288 { INPUT_MOUSE, {{1, 0}, {2, 0}, {0}}, {0}, TRUE, TRUE },
2289 { INPUT_MOUSE, {{3, 1}, {0}}, {0}, TRUE, TRUE },
2290 { INPUT_MOUSE, {{1, 1}, {0}}, {0}, FALSE, FALSE },
2291 { -1 }
2292 };
2293
2294 static void send_key(WORD wVk)
2295 {
2296 TEST_INPUT i[2];
2297 memset(i, 0, sizeof(i));
2298 i[0].type = i[1].type = INPUT_KEYBOARD;
2299 i[0].u.ki.wVk = i[1].u.ki.wVk = wVk;
2300 i[1].u.ki.dwFlags = KEYEVENTF_KEYUP;
2301 pSendInput(2, (INPUT *) i, sizeof(INPUT));
2302 }
2303
2304 static BOOL click_menu(HANDLE hWnd, struct menu_item_pair_s *mi)
2305 {
2306 HMENU hMenu = hMenus[mi->uMenu];
2307 TEST_INPUT i[3];
2308 MSG msg;
2309 RECT r;
2310 int screen_w = GetSystemMetrics(SM_CXSCREEN);
2311 int screen_h = GetSystemMetrics(SM_CYSCREEN);
2312 BOOL ret = GetMenuItemRect(mi->uMenu > 2 ? NULL : hWnd, hMenu, mi->uItem, &r);
2313 if(!ret) return FALSE;
2314
2315 memset(i, 0, sizeof(i));
2316 i[0].type = i[1].type = i[2].type = INPUT_MOUSE;
2317 i[0].u.mi.dx = i[1].u.mi.dx = i[2].u.mi.dx
2318 = ((r.left + 5) * 65535) / screen_w;
2319 i[0].u.mi.dy = i[1].u.mi.dy = i[2].u.mi.dy
2320 = ((r.top + 5) * 65535) / screen_h;
2321 i[0].u.mi.dwFlags = i[1].u.mi.dwFlags = i[2].u.mi.dwFlags
2322 = MOUSEEVENTF_ABSOLUTE;
2323 i[0].u.mi.dwFlags |= MOUSEEVENTF_MOVE;
2324 i[1].u.mi.dwFlags |= MOUSEEVENTF_LEFTDOWN;
2325 i[2].u.mi.dwFlags |= MOUSEEVENTF_LEFTUP;
2326 ret = pSendInput(3, (INPUT *) i, sizeof(INPUT));
2327
2328 /* hack to prevent mouse message buildup in Wine */
2329 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
2330 return ret;
2331 }
2332
2333 static DWORD WINAPI test_menu_input_thread(LPVOID lpParameter)
2334 {
2335 int i, j;
2336 HANDLE hWnd = lpParameter;
2337
2338 Sleep(500);
2339 /* mixed keyboard/mouse test */
2340 for (i = 0; menu_tests[i].type != -1; i++)
2341 {
2342 BOOL ret = TRUE;
2343 int elapsed = 0;
2344
2345 got_input = i && menu_tests[i-1].bMenuVisible;
2346
2347 if (menu_tests[i].type == INPUT_KEYBOARD)
2348 for (j = 0; menu_tests[i].wVk[j] != 0; j++)
2349 send_key(menu_tests[i].wVk[j]);
2350 else
2351 for (j = 0; menu_tests[i].menu_item_pairs[j].uMenu != 0; j++)
2352 if (!(ret = click_menu(hWnd, &menu_tests[i].menu_item_pairs[j]))) break;
2353
2354 if (!ret)
2355 {
2356 skip( "test %u: failed to send input\n", i );
2357 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2358 return 0;
2359 }
2360 while (menu_tests[i].bMenuVisible != bMenuVisible)
2361 {
2362 if (elapsed > 200)
2363 break;
2364 elapsed += 20;
2365 Sleep(20);
2366 }
2367
2368 if (!got_input)
2369 {
2370 skip( "test %u: didn't receive input\n", i );
2371 PostMessageA( hWnd, WM_CANCELMODE, 0, 0 );
2372 return 0;
2373 }
2374
2375 todo_wine_if (menu_tests[i]._todo_wine)
2376 ok(menu_tests[i].bMenuVisible == bMenuVisible, "test %d\n", i);
2377 }
2378 return 0;
2379 }
2380
2381 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
2382 LPARAM lParam)
2383 {
2384 switch (msg) {
2385 case WM_ENTERMENULOOP:
2386 bMenuVisible = TRUE;
2387 break;
2388 case WM_INITMENUPOPUP:
2389 case WM_UNINITMENUPOPUP:
2390 case WM_EXITMENULOOP:
2391 case WM_MENUSELECT:
2392 break;
2393
2394 case WM_KEYDOWN:
2395 case WM_SYSKEYDOWN:
2396 case WM_MOUSEMOVE:
2397 case WM_LBUTTONDOWN:
2398 case WM_LBUTTONUP:
2399 case WM_NCMOUSEMOVE:
2400 case WM_NCLBUTTONDOWN:
2401 case WM_NCLBUTTONUP:
2402 got_input = TRUE;
2403 /* fall through */
2404 default:
2405 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2406 }
2407
2408 if(pGetMenuBarInfo)
2409 {
2410 MENUBARINFO mbi;
2411 HMENU hmenu;
2412 UINT state;
2413 BOOL br;
2414
2415 mbi.cbSize = sizeof(MENUBARINFO);
2416
2417 /* get info for the menu */
2418 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
2419 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2420 hmenu = GetMenu(hWnd);
2421 ok(!mbi.hwndMenu, "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected NULL\n",
2422 msg, mbi.hwndMenu);
2423 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2424 msg, mbi.hMenu, hmenu);
2425 ok(!bMenuVisible == !mbi.fBarFocused, "msg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2426 msg, mbi.fBarFocused != 0);
2427 ok(!bMenuVisible == !mbi.fFocused, "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n",
2428 msg, mbi.fFocused != 0);
2429
2430 /* get info for the menu's first item */
2431 br = pGetMenuBarInfo(hWnd, OBJID_MENU, 1, &mbi);
2432 ok(br, "msg %x: GetMenuBarInfo failed\n", msg);
2433 state = GetMenuState(hmenu, 0, MF_BYPOSITION);
2434 if (pGetMenuInfo) /* Skip on NT */
2435 {
2436 /* Native returns handle to destroyed window */
2437 todo_wine_if (msg==WM_UNINITMENUPOPUP && popmenu==1)
2438 ok(!mbi.hwndMenu == !popmenu,
2439 "msg %x: GetMenuBarInfo.hwndMenu wrong: %p expected %sNULL\n",
2440 msg, mbi.hwndMenu, popmenu ? "not " : "");
2441 }
2442 ok(mbi.hMenu == hmenu, "msg %x: GetMenuBarInfo got wrong menu: %p expected %p\n",
2443 msg, mbi.hMenu, hmenu);
2444 ok(!bMenuVisible == !mbi.fBarFocused, "nsg %x: GetMenuBarInfo.fBarFocused (%d) is wrong\n",
2445 msg, mbi.fBarFocused != 0);
2446 ok(!(bMenuVisible && (state & MF_HILITE)) == !mbi.fFocused,
2447 "msg %x: GetMenuBarInfo.fFocused (%d) is wrong\n", msg, mbi.fFocused != 0);
2448 }
2449
2450 if (msg == WM_EXITMENULOOP)
2451 bMenuVisible = FALSE;
2452 else if (msg == WM_INITMENUPOPUP)
2453 popmenu++;
2454 else if (msg == WM_UNINITMENUPOPUP)
2455 popmenu--;
2456 return 0;
2457 }
2458
2459 static void test_menu_input(void) {
2460 MSG msg;
2461 WNDCLASSA wclass;
2462 HINSTANCE hInstance = GetModuleHandleA( NULL );
2463 HANDLE hThread, hWnd;
2464 DWORD tid;
2465 ATOM aclass;
2466 POINT orig_pos;
2467
2468 if (!pSendInput)
2469 {
2470 win_skip("SendInput is not available\n");
2471 return;
2472 }
2473
2474 wclass.lpszClassName = "MenuTestClass";
2475 wclass.style = CS_HREDRAW | CS_VREDRAW;
2476 wclass.lpfnWndProc = WndProc;
2477 wclass.hInstance = hInstance;
2478 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
2479 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
2480 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2481 wclass.lpszMenuName = 0;
2482 wclass.cbClsExtra = 0;