source: trunk/src/user32/winmenu.cpp@ 1499

Last change on this file since 1499 was 1499, checked in by sandervl, 26 years ago

EB's bugfixes

File size: 40.7 KB
Line 
1/* $Id: winmenu.cpp,v 1.12 1999-10-28 19:09:17 sandervl Exp $ */
2
3/*
4 * Win32 menu API functions for OS/2
5 *
6 * Copyright 1998 Sander van Leeuwen
7 * Copyright 1998 Patrick Haller
8 *
9 * Parts ported from Wine:
10 * Copyright 1993 Martin Ayotte
11 * Copyright 1994 Alexandre Julliard
12 * Copyright 1997 Morten Welinder
13 *
14 *
15 * TODO: Set/GetMenu(Item)Info only partially implemented
16 * TODO: Memory leak when deleting submenus
17 * TODO: Check error nrs
18 *
19 * Project Odin Software License can be found in LICENSE.TXT
20 *
21 */
22#include <os2win.h>
23#include <odin.h>
24#include <odinwrap.h>
25#include <stdlib.h>
26#include <string.h>
27#include <win32wbase.h>
28#include "oslibmenu.h"
29#include "oslibwin.h"
30#include "winmenudef.h"
31
32ODINDEBUGCHANNEL(USER32)
33
34BOOL ODIN_INTERNAL ODIN_InsertMenuA(HMENU,UINT,UINT,UINT,LPCSTR);
35BOOL ODIN_INTERNAL ODIN_InsertMenuW(HMENU,UINT,UINT,UINT,LPCWSTR);
36BOOL ODIN_INTERNAL ODIN_InsertMenuItemA(HMENU,UINT,BOOL,const MENUITEMINFOA*);
37BOOL ODIN_INTERNAL ODIN_InsertMenuItemW(HMENU,UINT,BOOL,const MENUITEMINFOW*);
38BOOL ODIN_INTERNAL ODIN_AppendMenuA(HMENU,UINT,UINT,LPCSTR);
39BOOL ODIN_INTERNAL ODIN_AppendMenuW(HMENU,UINT,UINT,LPCWSTR);
40HMENU ODIN_INTERNAL ODIN_CreateMenu(void);
41HMENU ODIN_INTERNAL ODIN_CreatePopupMenu(void);
42BOOL ODIN_INTERNAL ODIN_DestroyMenu(HMENU);
43
44//@@@PH: experiment with WINE LoadMenuIndirect code
45#include <heapstring.h>
46#define MENU_ITEM_TYPE(flags) \
47 ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
48
49#define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
50#define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
51
52/**********************************************************************
53 * MENU_ParseResource
54 *
55 * Parse a standard menu resource and add items to the menu.
56 * Return a pointer to the end of the resource.
57 */
58static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu)
59{
60 WORD flags, id = 0;
61 LPCSTR str;
62
63 do
64 {
65 flags = GET_WORD(res);
66 res += sizeof(WORD);
67 if (!(flags & MF_POPUP))
68 {
69 id = GET_WORD(res);
70 res += sizeof(WORD);
71 }
72 if (!IS_STRING_ITEM(flags))
73 dprintf(("USER32: WinMenu: MENU_ParseResource: not a string item %04x\n", flags ));
74 str = res;
75
76 res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
77 if (flags & MF_POPUP)
78 {
79 HMENU hSubMenu = ODIN_CreatePopupMenu();
80 if (!hSubMenu) return NULL;
81 if (!(res = MENU_ParseResource( res, hSubMenu)))
82 return NULL;
83 ODIN_AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
84 }
85 else /* Not a popup */
86 {
87 ODIN_AppendMenuW( hMenu, flags, id, *(LPCWSTR)str ? (LPCWSTR)str : NULL );
88 }
89 } while (!(flags & MF_END));
90 return res;
91}
92
93
94/**********************************************************************
95 * MENUEX_ParseResource
96 *
97 * Parse an extended menu resource and add items to the menu.
98 * Return a pointer to the end of the resource.
99 */
100static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
101{
102 WORD resinfo;
103
104 do {
105 MENUITEMINFOW mii;
106
107 mii.cbSize = sizeof(mii);
108 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
109 mii.fType = GET_DWORD(res);
110 res += sizeof(DWORD);
111 mii.fState = GET_DWORD(res);
112 res += sizeof(DWORD);
113 mii.wID = GET_DWORD(res);
114 res += sizeof(DWORD);
115 resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte. */
116 res += sizeof(WORD);
117
118 /* Align the text on a word boundary. */
119 res += (~((int)res - 1)) & 1;
120 mii.dwTypeData = (LPWSTR) res;
121 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
122 /* Align the following fields on a dword boundary. */
123 res += (~((int)res - 1)) & 3;
124
125 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
126 {
127 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(), 0, mii.dwTypeData);
128
129 dprintf(("USER32:WinMenu:MENUEX_ParseResource Menu item: [%08x,%08x,%04x,%04x,%s]\n",
130 mii.fType, mii.fState, mii.wID, resinfo, newstr));
131 HeapFree( GetProcessHeap(), 0, newstr );
132 }
133
134 if (resinfo & 1) { /* Pop-up? */
135 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
136 res += sizeof(DWORD);
137 mii.hSubMenu = ODIN_CreatePopupMenu();
138 if (!mii.hSubMenu)
139 return NULL;
140 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
141 DestroyMenu(mii.hSubMenu);
142 return NULL;
143 }
144 mii.fMask |= MIIM_SUBMENU;
145 mii.fType |= MF_POPUP;
146 }
147 ODIN_InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
148 }
149 while (!(resinfo & MF_END));
150
151 return res;
152}
153/**********************************************************************
154 * myLoadMenuIndirect
155 */
156HMENU myLoadMenuIndirect(LPCVOID pMenuTemplate)
157{
158 HMENU hMenu;
159 WORD version,
160 offset;
161 LPCSTR p = (LPCSTR)pMenuTemplate;
162
163 version = GET_WORD(p);
164 p += sizeof(WORD);
165
166 switch (version)
167 {
168 case 0:
169 offset = GET_WORD(p);
170 p += sizeof(WORD) + offset;
171 if (!(hMenu = ODIN_CreateMenu()))
172 return 0;
173 if (!MENU_ParseResource( p, hMenu))
174 {
175 DestroyMenu( hMenu );
176 return 0;
177 }
178 return hMenu;
179
180 case 1:
181 offset = GET_WORD(p);
182 p += sizeof(WORD) + offset;
183 if (!(hMenu = ODIN_CreateMenu()))
184 return 0;
185 if (!MENUEX_ParseResource( p, hMenu))
186 {
187 ODIN_DestroyMenu( hMenu );
188 return 0;
189 }
190 return hMenu;
191
192 default:
193 dprintf(("USER32: LoadMenuIndirectA: version %d not supported.\n", version));
194 return 0;
195 }
196}
197//******************************************************************************
198//******************************************************************************
199void SetInternalMenuInfo(HMENU hMenu)
200{
201 LPPOPUPMENU lpMenuInfo;
202
203 lpMenuInfo = (LPPOPUPMENU)malloc(sizeof(*lpMenuInfo));
204 memset(lpMenuInfo, 0, sizeof(*lpMenuInfo));
205 OSLibWinSetWindowULong(hMenu, OSLIB_QWL_USER, (ULONG)lpMenuInfo);
206}
207//******************************************************************************
208//******************************************************************************
209LPPOPUPMENU GetInternalMenuInfo(HMENU hMenu)
210{
211 return (LPPOPUPMENU)OSLibWinGetWindowULong(hMenu, OSLIB_QWL_USER);
212}
213//******************************************************************************
214//******************************************************************************
215void DeleteInternalMenuInfo(HMENU hMenu)
216{
217 LPPOPUPMENU lpMenuInfo;
218
219 lpMenuInfo = (LPPOPUPMENU)OSLibWinGetWindowULong(hMenu, OSLIB_QWL_USER);
220 if(lpMenuInfo) {
221 free(lpMenuInfo);
222 OSLibWinSetWindowULong(hMenu, OSLIB_QWL_USER, 0);
223 }
224}
225//******************************************************************************
226//******************************************************************************
227ODINFUNCTION0(HMENU, CreateMenu)
228{
229 HMENU hMenu;
230
231 dprintf(("USER32: CreateMenu\n"));
232
233 hMenu = OSLibWinCreateEmptyMenu();
234 if(hMenu) {
235 SetInternalMenuInfo(hMenu);
236 }
237 else SetLastError(ERROR_INVALID_PARAMETER); //wrong error
238
239 return hMenu;
240}
241//******************************************************************************
242//******************************************************************************
243ODINFUNCTION0(HMENU, CreatePopupMenu)
244{
245 HMENU hMenu;
246
247 dprintf(("USER32: CreatePopupMenu\n"));
248
249 hMenu = OSLibWinCreateEmptyPopupMenu();
250 if(hMenu) {
251 SetInternalMenuInfo(hMenu);
252 }
253 else SetLastError(ERROR_INVALID_PARAMETER); //wrong error
254
255 return hMenu;
256}
257//******************************************************************************
258//******************************************************************************
259ODINFUNCTION2(HMENU, LoadMenuA,
260 HINSTANCE, hinst,
261 LPCSTR, lpszMenu)
262{
263 Win32Resource *winres;
264 HMENU hMenu;
265
266 winres = (Win32Resource *)FindResourceA(hinst, lpszMenu, RT_MENUA);
267 if(winres)
268 {
269 hMenu = myLoadMenuIndirect((MENUITEMTEMPLATEHEADER *)winres->lockResource());
270 if(hMenu) {
271 SetInternalMenuInfo(hMenu);
272 }
273 else SetLastError(ERROR_INVALID_PARAMETER);
274
275 delete winres;
276 return hMenu;
277 }
278 return 0;
279}
280//******************************************************************************
281//******************************************************************************
282ODINFUNCTION2(HMENU, LoadMenuW,
283 HINSTANCE, hinst,
284 LPCWSTR, lpszMenu)
285{
286 Win32Resource *winres;
287 HMENU hMenu;
288
289 winres = (Win32Resource *)FindResourceW(hinst, lpszMenu, RT_MENUW);
290 if(winres) {
291 hMenu = myLoadMenuIndirect((MENUITEMTEMPLATEHEADER *)winres->lockResource());
292 if(hMenu) {
293 SetInternalMenuInfo(hMenu);
294 }
295 else SetLastError(ERROR_INVALID_PARAMETER);
296
297 delete winres;
298 return hMenu;
299 }
300 return 0;
301}
302//******************************************************************************
303//NOTE: menutemplate strings are always in Unicode format
304//******************************************************************************
305ODINFUNCTION1(HMENU, LoadMenuIndirectW,
306 const MENUITEMTEMPLATEHEADER *, menuTemplate)
307{
308 HMENU hMenu;
309
310 hMenu = O32_LoadMenuIndirect(menuTemplate);
311 if(hMenu) {
312 SetInternalMenuInfo(hMenu);
313 }
314 else SetLastError(ERROR_INVALID_PARAMETER);
315
316 return (HMENU)hMenu;
317}
318//******************************************************************************
319//******************************************************************************
320ODINFUNCTION1(BOOL, DestroyMenu,
321 HMENU, hMenu)
322{
323 if(hMenu == 0)
324 {
325 SetLastError(ERROR_INVALID_PARAMETER);
326 return 0;
327 }
328 DeleteInternalMenuInfo(hMenu);
329 return O32_DestroyMenu(hMenu);
330}
331//******************************************************************************
332//******************************************************************************
333ODINFUNCTION1(HMENU, GetMenu,
334 HWND, hwnd)
335{
336 Win32BaseWindow *window;
337
338 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
339 if(!window)
340 {
341 dprintf(("GetMenu, window %x not found", hwnd));
342 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
343 return 0;
344 }
345
346 return window->GetMenu();
347}
348//******************************************************************************
349//******************************************************************************
350ODINFUNCTION2(BOOL, SetMenu,
351 HWND, hwnd,
352 HMENU, hMenu)
353{
354 Win32BaseWindow *window;
355
356 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
357 if(!window)
358 {
359 dprintf(("SetMenu, window %x not found", hwnd));
360 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
361 return 0;
362 }
363
364 window->SetMenu(hMenu);
365 return TRUE;
366}
367//******************************************************************************
368//******************************************************************************
369ODINFUNCTION0(DWORD, GetMenuCheckMarkDimensions)
370{
371 return O32_GetMenuCheckMarkDimensions();
372}
373//******************************************************************************
374//******************************************************************************
375ODINFUNCTION1(int, GetMenuItemCount,
376 HMENU, hMenu)
377{
378 if(hMenu == 0)
379 {
380 SetLastError(ERROR_INVALID_PARAMETER);
381 return 0;
382 }
383 return OSLibGetMenuItemCount(hMenu);
384}
385//******************************************************************************
386//******************************************************************************
387ODINFUNCTION2(UINT, GetMenuItemID,
388 HMENU, hMenu,
389 int, nPos)
390{
391 if(hMenu == 0)
392 {
393 SetLastError(ERROR_INVALID_PARAMETER);
394 return 0;
395 }
396 return O32_GetMenuItemID(hMenu, nPos);
397}
398//******************************************************************************
399//******************************************************************************
400ODINFUNCTION3(UINT, GetMenuState,
401 HMENU, hMenu,
402 UINT, arg2,
403 UINT, arg3)
404{
405 if(hMenu == 0)
406 {
407 SetLastError(ERROR_INVALID_PARAMETER);
408 return 0;
409 }
410
411 return O32_GetMenuState(hMenu, arg2, arg3);
412}
413//******************************************************************************
414//******************************************************************************
415ODINFUNCTION5(int, GetMenuStringA,
416 HMENU, hMenu,
417 UINT, arg2,
418 LPSTR, arg3,
419 int, arg4,
420 UINT, arg5)
421{
422 if(hMenu == 0)
423 {
424 SetLastError(ERROR_INVALID_PARAMETER);
425 return 0;
426 }
427
428 return O32_GetMenuString(hMenu, arg2, arg3, arg4, arg5);
429}
430//******************************************************************************
431//******************************************************************************
432ODINFUNCTION5(int, GetMenuStringW,
433 HMENU, hMenu,
434 UINT, idItem,
435 LPWSTR,lpsz,
436 int, cchMax,
437 UINT, fuFlags)
438{
439 char *astring = (char *)malloc(cchMax);
440 int rc;
441
442 rc = ODIN_GetMenuStringA(hMenu, idItem, astring, cchMax, fuFlags);
443 free(astring);
444 if(rc)
445 {
446 dprintf(("USER32: OS2GetMenuStringW %s\n", astring));
447 AsciiToUnicode(astring, lpsz);
448 }
449 else lpsz[0] = 0;
450
451 return(rc);
452}
453//******************************************************************************
454//******************************************************************************
455ODINFUNCTION5(BOOL, SetMenuItemBitmaps,
456 HMENU, hMenu,
457 UINT, arg2,
458 UINT, arg3,
459 HBITMAP, arg4,
460 HBITMAP, arg5)
461{
462 dprintf(("USER32: SetMenuItemBitmaps\n"));
463 if(hMenu == 0)
464 {
465 SetLastError(ERROR_INVALID_PARAMETER);
466 return 0;
467 }
468 return O32_SetMenuItemBitmaps(hMenu, arg2, arg3, arg4, arg5);
469}
470//******************************************************************************
471//******************************************************************************
472ODINFUNCTION2(HMENU, GetSubMenu,
473 HWND, hMenu,
474 int, arg2)
475{
476 if(hMenu == 0)
477 {
478 SetLastError(ERROR_INVALID_PARAMETER);
479 return 0;
480 }
481
482 return O32_GetSubMenu(hMenu, arg2);
483}
484//******************************************************************************
485//******************************************************************************
486ODINFUNCTION2(HMENU, GetSystemMenu,
487 HWND, hSystemWindow,
488 BOOL, bRevert)
489{
490 Win32BaseWindow *window;
491
492 window = Win32BaseWindow::GetWindowFromHandle(hSystemWindow);
493 if(!window)
494 {
495 dprintf(("GetSystemMenu, window %x not found", hSystemWindow));
496 return 0;
497 }
498
499 return O32_GetSystemMenu(window->getOS2FrameWindowHandle(), bRevert);
500}
501//******************************************************************************
502//******************************************************************************
503ODINFUNCTION1(BOOL, IsMenu,
504 HMENU, hMenu)
505{
506 dprintf(("USER32: IsMenu\n"));
507 return O32_IsMenu(hMenu);
508}
509//******************************************************************************
510//******************************************************************************
511ODINFUNCTION7(BOOL, TrackPopupMenu,
512 HMENU, hMenu,
513 UINT, arg2,
514 int, arg3,
515 int, arg4,
516 int, arg5,
517 HWND, arg6,
518 const RECT *, arg7)
519{
520 Win32BaseWindow *window;
521
522 window = Win32BaseWindow::GetWindowFromHandle(arg6);
523 if(!window)
524 {
525 dprintf(("TrackPopupMenu, window %x not found", arg6));
526 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
527 return 0;
528 }
529 dprintf(("USER32: TrackPopupMenu\n"));
530 if(hMenu == 0)
531 {
532 SetLastError(ERROR_INVALID_PARAMETER);
533 return 0;
534 }
535 return O32_TrackPopupMenu(hMenu, arg2, arg3, arg4, arg5, window->getOS2WindowHandle(),
536 arg7);
537}
538//******************************************************************************
539//******************************************************************************
540ODINFUNCTION6(BOOL, TrackPopupMenuEx,
541 HMENU, hMenu,
542 UINT, flags,
543 int, X,
544 int, Y,
545 HWND, hwnd,
546 LPTPMPARAMS, lpPM)
547{
548 RECT *rect = NULL;
549 Win32BaseWindow *window;
550
551 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
552 if(!window)
553 {
554 dprintf(("TrackPopupMenu, window %x not found", hwnd));
555 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
556 return 0;
557 }
558
559 dprintf(("USER32: TrackPopupMenuEx, not completely implemented\n"));
560 if(lpPM->cbSize != 0)
561 rect = &lpPM->rcExclude;
562
563 if(hMenu == 0)
564 {
565 SetLastError(ERROR_INVALID_PARAMETER);
566 return 0;
567 }
568 return O32_TrackPopupMenu(hMenu, flags, X, Y, 0, window->getOS2WindowHandle(), rect);
569}
570//******************************************************************************
571//******************************************************************************
572ODINFUNCTION4(BOOL, AppendMenuA,
573 HMENU, hMenu,
574 UINT, uFlags,
575 UINT, id,
576 LPCSTR, lpNewItem)
577{
578 return ODIN_InsertMenuA( hMenu, -1, uFlags | MF_BYPOSITION, id, lpNewItem );
579}
580//******************************************************************************
581//******************************************************************************
582ODINFUNCTION4(BOOL, AppendMenuW,
583 HMENU, hMenu,
584 UINT, uFlags,
585 UINT, id,
586 LPCWSTR, lpNewItem)
587{
588 return ODIN_InsertMenuW( hMenu, -1, uFlags | MF_BYPOSITION, id, lpNewItem );
589}
590//******************************************************************************
591//******************************************************************************
592ODINFUNCTION3(DWORD, CheckMenuItem,
593 HMENU, hMenu,
594 UINT, arg2,
595 UINT, arg3)
596{
597 dprintf(("USER32: OS2CheckMenuItem\n"));
598 if(hMenu == 0)
599 {
600 SetLastError(ERROR_INVALID_PARAMETER);
601 return 0;
602 }
603 return O32_CheckMenuItem(hMenu, arg2, arg3);
604}
605//******************************************************************************
606//******************************************************************************
607ODINFUNCTION3(BOOL,EnableMenuItem,HMENU,hMenu,
608 UINT, uIDEnableItem,
609 UINT, uEnable)
610{
611 if(hMenu == 0)
612 {
613 SetLastError(ERROR_INVALID_PARAMETER);
614 return 0;
615 }
616
617 return O32_EnableMenuItem(hMenu,
618 uIDEnableItem,
619 uEnable);
620}
621//******************************************************************************
622//******************************************************************************
623ODINFUNCTION5(BOOL, ModifyMenuA,
624 HMENU, hMenu,
625 UINT, arg2,
626 UINT, arg3,
627 UINT, arg4,
628 LPCSTR, arg5)
629{
630 dprintf(("USER32: OS2ModifyMenuA\n"));
631 if(hMenu == 0)
632 {
633 SetLastError(ERROR_INVALID_PARAMETER);
634 return 0;
635 }
636 return O32_ModifyMenu(hMenu, arg2, arg3, arg4, arg5);
637}
638//******************************************************************************
639//******************************************************************************
640ODINFUNCTION5(BOOL, ModifyMenuW,
641 HMENU, hMenu,
642 UINT, arg2,
643 UINT, arg3,
644 UINT, arg4,
645 LPCWSTR, arg5)
646{
647 BOOL rc;
648 char *astring = NULL;
649
650 if(hMenu == 0)
651 {
652 SetLastError(ERROR_INVALID_PARAMETER);
653 return 0;
654 }
655
656 if(IS_STRING_ITEM(arg3) && HIWORD(arg5) != 0)
657 astring = UnicodeToAsciiString((LPWSTR)arg5);
658 else
659 astring = (char *) arg5;
660
661 rc = ODIN_ModifyMenuA(hMenu, arg2, arg3, arg4, astring);
662 if(IS_STRING_ITEM(arg3) && HIWORD(arg5) != 0)
663 FreeAsciiString(astring);
664
665 return(rc);
666}
667//******************************************************************************
668//******************************************************************************
669ODINFUNCTION3(BOOL, RemoveMenu,
670 HMENU, hMenu,
671 UINT, arg2,
672 UINT, arg3)
673{
674 dprintf(("USER32: OS2RemoveMenu\n"));
675 if(hMenu == 0)
676 {
677 SetLastError(ERROR_INVALID_PARAMETER);
678 return 0;
679 }
680
681 return O32_RemoveMenu(hMenu, arg2, arg3);
682}
683//******************************************************************************
684//******************************************************************************
685ODINFUNCTION3(BOOL, DeleteMenu,
686 HMENU, hMenu,
687 UINT, arg2,
688 UINT, arg3)
689{
690 dprintf(("USER32: OS2DeleteMenu\n"));
691 if(hMenu == 0)
692 {
693 SetLastError(ERROR_INVALID_PARAMETER);
694 return 0;
695 }
696
697 return O32_DeleteMenu(hMenu, arg2, arg3);
698}
699//******************************************************************************
700//******************************************************************************
701ODINFUNCTION4(BOOL, HiliteMenuItem,
702 HWND, hMenu,
703 HMENU, arg2,
704 UINT, arg3,
705 UINT, arg4)
706{
707 dprintf(("USER32: OS2HiliteMenuItem\n"));
708 if(hMenu == 0)
709 {
710 SetLastError(ERROR_INVALID_PARAMETER);
711 return 0;
712 }
713
714 return O32_HiliteMenuItem(hMenu, arg2, arg3, arg4);
715}
716//******************************************************************************
717//******************************************************************************
718ODINFUNCTION5(BOOL, InsertMenuA,
719 HMENU, hMenu,
720 UINT, pos,
721 UINT, flags,
722 UINT, id,
723 LPCSTR, str)
724{
725 dprintf(("USER32: InsertMenuA %x %d %x %d %s", hMenu, pos, flags, id, str));
726 if(hMenu == 0)
727 {
728 SetLastError(ERROR_INVALID_PARAMETER);
729 return 0;
730 }
731
732 if(!str || *str == NULL) {
733 flags |= MF_SEPARATOR;
734 }
735 return O32_InsertMenu(hMenu, pos, flags, id, str);
736}
737//******************************************************************************
738//******************************************************************************
739ODINFUNCTION5(BOOL, InsertMenuW,
740 HMENU, hMenu,
741 UINT, arg2,
742 UINT, arg3,
743 UINT, arg4,
744 LPCWSTR, arg5)
745{
746 BOOL rc;
747 char *astring = NULL;
748
749 if(IS_STRING_ITEM(arg3) && HIWORD(arg5) != 0)
750 astring = UnicodeToAsciiString((LPWSTR)arg5);
751 else
752 astring = (char *) arg5;
753
754 rc = ODIN_InsertMenuA(hMenu, arg2, arg3, arg4, astring);
755
756 if(IS_STRING_ITEM(arg3) && HIWORD(arg5) != 0)
757 FreeAsciiString(astring);
758
759 return(rc);
760}
761//******************************************************************************
762//******************************************************************************
763ODINFUNCTION2(BOOL, SetMenuContextHelpId,
764 HMENU, hMenu,
765 DWORD, dwContextHelpId)
766{
767 POPUPMENU *menu;
768
769 menu = GetInternalMenuInfo(hMenu);
770 if(menu == NULL) {
771 dprintf(("USER32: SetMenuContextHelpId(%x) No POPUPMENU structure found!", hMenu));
772 SetLastError(ERROR_INVALID_PARAMETER);
773 return FALSE;
774 }
775 dprintf(("USER32: SetMenuContextHelpId %x %d", hMenu, dwContextHelpId));
776 menu->dwContextHelpID = dwContextHelpId;
777 return(TRUE);
778}
779//******************************************************************************
780//******************************************************************************
781ODINFUNCTION1(DWORD, GetMenuContextHelpId,
782 HMENU, hMenu)
783{
784 POPUPMENU *menu;
785
786 menu = GetInternalMenuInfo(hMenu);
787 if(menu == NULL) {
788 dprintf(("USER32: GetMenuContextHelpId(%x) No POPUPMENU structure found!", hMenu));
789 SetLastError(ERROR_INVALID_PARAMETER);
790 return 0;
791 }
792 dprintf(("USER32: GetMenuContextHelpId %x %d", hMenu, menu->dwContextHelpID));
793 return menu->dwContextHelpID;
794}
795//******************************************************************************
796//******************************************************************************
797ODINFUNCTION5(BOOL, CheckMenuRadioItem,
798 HMENU, hMenu,
799 UINT, idFirst,
800 UINT, idLast,
801 UINT, idCheck,
802 UINT, uFlags)
803{
804 dprintf(("USER32: OS2CheckMenuRadioItem, not implemented\n"));
805 return(TRUE);
806}
807//******************************************************************************
808//******************************************************************************
809ODINFUNCTION5(BOOL, ChangeMenuA,
810 HMENU, hMenu,
811 UINT, pos,
812 LPCSTR, data,
813 UINT, id,
814 UINT, flags)
815{
816 dprintf(("USER32: ChangeMenuA flags %X\n", flags));
817
818 if (flags & MF_APPEND) return ODIN_AppendMenuA(hMenu, flags & ~MF_APPEND,
819 id, data );
820 if (flags & MF_DELETE) return ODIN_DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
821 if (flags & MF_CHANGE) return ODIN_ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
822 id, data );
823 if (flags & MF_REMOVE) return ODIN_RemoveMenu(hMenu,
824 flags & MF_BYPOSITION ? pos : id,
825 flags & ~MF_REMOVE );
826 /* Default: MF_INSERT */
827 return InsertMenuA( hMenu, pos, flags, id, data );
828}
829//******************************************************************************
830//******************************************************************************
831ODINFUNCTION5(BOOL, ChangeMenuW,
832 HMENU, hMenu,
833 UINT, pos,
834 LPCWSTR, data,
835 UINT, id,
836 UINT, flags)
837{
838 dprintf(("USER32: ChangeMenuW flags %X\n", flags));
839
840 if (flags & MF_APPEND) return ODIN_AppendMenuW(hMenu, flags & ~MF_APPEND,
841 id, data );
842 if (flags & MF_DELETE) return ODIN_DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
843 if (flags & MF_CHANGE) return ODIN_ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
844 id, data );
845 if (flags & MF_REMOVE) return ODIN_RemoveMenu(hMenu,
846 flags & MF_BYPOSITION ? pos : id,
847 flags & ~MF_REMOVE );
848 /* Default: MF_INSERT */
849 return InsertMenuW(hMenu, pos, flags, id, data);
850}
851//******************************************************************************
852//******************************************************************************
853ODINFUNCTION4(BOOL, SetMenuItemInfoA,
854 HMENU, hMenu,
855 UINT, par1,
856 BOOL, par2,
857 const MENUITEMINFOA *, lpmii)
858{
859 dprintf(("USER32: SetMenuItemInfoA faked %x", hMenu));
860
861 if (!hMenu) {
862 SetLastError(ERROR_INVALID_PARAMETER);
863 return FALSE;
864 }
865 return TRUE;
866}
867/*****************************************************************************
868 * Function : SetMenuItemInfoW
869 * Purpose : The SetMenuItemInfo function changes information about a menu item.
870 * Parameters:
871 * Variables :
872 * Result : If the function succeeds, the return value is TRUE.
873 * If the function fails, the return value is FALSE. To get extended
874 * error information, use the GetLastError function.
875 * Remark :
876 * Status : UNTESTED STUB
877 *
878 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
879 *****************************************************************************/
880
881ODINFUNCTION4(BOOL, SetMenuItemInfoW,
882 HMENU, hMenu,
883 UINT, uItem,
884 BOOL, fByPosition,
885 const MENUITEMINFOW *, lpmmi)
886{
887 dprintf(("USER32:SetMenuItemInfoW (%08xh,%08xh,%08xh,%08x) not implemented.\n",
888 hMenu,
889 uItem,
890 fByPosition,
891 lpmmi));
892
893 return (SetMenuItemInfoA(hMenu,
894 uItem,
895 fByPosition,
896 (const MENUITEMINFOA *)lpmmi));
897}
898/*****************************************************************************
899 * Function : GetMenuDefaultItem
900 * Purpose : TheGetMenuDefaultItem function determines the default menu item
901 * on the specified menu.
902 * Parameters:
903 * Variables :
904 * Result : If the function succeeds, the return value is the identifier or
905 * position of the menu item.
906 * If the function fails, the return value is - 1.
907 * Remark :
908 * Status : UNTESTED STUB
909 *
910 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
911 *****************************************************************************/
912
913ODINFUNCTION3(UINT, GetMenuDefaultItem,
914 HMENU, hMenu,
915 UINT, fByPos,
916 UINT, gmdiFlags)
917{
918 dprintf(("USER32:GetMenuDefaultItem (%08xh,%u,%08x) not implemented.\n",
919 hMenu,
920 fByPos,
921 gmdiFlags));
922
923 return (-1);
924}
925//******************************************************************************
926//******************************************************************************
927ODINFUNCTION3(BOOL, SetMenuDefaultItem,
928 HMENU, hMenu,
929 UINT, uItem,
930 UINT, fByPos)
931{
932 dprintf(("USER32: SetMenuDefaultItem, faked\n"));
933 return(TRUE);
934}
935//******************************************************************************
936//******************************************************************************
937BOOL GetMenuItemInfoAW(HMENU hMenu, UINT uItem, BOOL byPos, MENUITEMINFOA *lpmii, BOOL unicode)
938{
939 if(byPos) {
940 uItem = GetMenuItemID(hMenu, uItem);
941 }
942 if(ODIN_GetMenuState(hMenu, uItem, MF_BYCOMMAND) == -1) {
943 //item doesn't exist
944 dprintf(("USER32: GetMenuItemInfoAW %x item %d doesn't exist", hMenu, uItem));
945 SetLastError(ERROR_INVALID_PARAMETER);
946 return FALSE;
947 }
948 if (lpmii->fMask & MIIM_TYPE)
949 {
950 lpmii->fType = ODIN_GetMenuState(hMenu, uItem, MF_BYCOMMAND); //not correct
951// lpmii->fType = menu->fType;
952 if (unicode) {
953 lpmii->cch = ODIN_GetMenuStringW(hMenu, uItem, (LPWSTR)lpmii->dwTypeData, lpmii->cch, MF_BYCOMMAND);
954 }
955 else {
956 lpmii->cch = ODIN_GetMenuStringA(hMenu, uItem, (LPSTR)lpmii->dwTypeData, lpmii->cch, MF_BYCOMMAND);
957 }
958//TODO:
959#if 0
960 switch (MENU_ITEM_TYPE(menu->fType)) {
961 case MF_STRING:
962 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
963 if (unicode) {
964 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
965 lpmii->cch = lstrlenW((LPWSTR)menu->text);
966 }
967 else {
968 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
969 lpmii->cch = lstrlenA(menu->text);
970 }
971 }
972 break;
973 case MF_OWNERDRAW:
974 case MF_BITMAP:
975 lpmii->dwTypeData = menu->text;
976 /* fall through */
977 default:
978 lpmii->cch = 0;
979 }
980#endif
981 }
982
983 if (lpmii->fMask & MIIM_STRING) {
984 if (unicode) {
985 lpmii->cch = ODIN_GetMenuStringW(hMenu, uItem, (LPWSTR)lpmii->dwTypeData, lpmii->cch, MF_BYCOMMAND);
986 }
987 else {
988 lpmii->cch = ODIN_GetMenuStringA(hMenu, uItem, (LPSTR)lpmii->dwTypeData, lpmii->cch, MF_BYCOMMAND);
989 }
990 }
991
992//TODO:
993#if 0
994 if (lpmii->fMask & MIIM_FTYPE)
995 lpmii->fType = menu->fType;
996
997 if (lpmii->fMask & MIIM_BITMAP)
998 lpmii->hbmpItem = menu->hbmpItem;
999#endif
1000
1001 if (lpmii->fMask & MIIM_STATE)
1002 lpmii->fState = ODIN_GetMenuState(hMenu, uItem, MF_BYCOMMAND);
1003
1004 if (lpmii->fMask & MIIM_ID)
1005 lpmii->wID = uItem;
1006
1007//TODO:
1008#if 1
1009 lpmii->hSubMenu = 0;
1010 lpmii->hbmpChecked = 0;
1011 lpmii->hbmpUnchecked = 0;
1012 lpmii->dwItemData = 0;
1013#else
1014 if (lpmii->fMask & MIIM_SUBMENU)
1015 lpmii->hSubMenu = ODIN_GetSubMenu(hMenu, uItem); //need index, not id
1016
1017 if (lpmii->fMask & MIIM_CHECKMARKS) {
1018 lpmii->hbmpChecked = menu->hCheckBit;
1019 lpmii->hbmpUnchecked = menu->hUnCheckBit;
1020 }
1021 if (lpmii->fMask & MIIM_DATA)
1022 lpmii->dwItemData = menu->dwItemData;
1023#endif
1024
1025 return(FALSE);
1026}
1027//******************************************************************************
1028//******************************************************************************
1029ODINFUNCTION4(BOOL, GetMenuItemInfoA,
1030 HMENU, hMenu,
1031 UINT, uItem,
1032 BOOL, byPos,
1033 MENUITEMINFOA *, lpMenuItemInfo)
1034{
1035 return GetMenuItemInfoAW(hMenu, uItem, byPos, lpMenuItemInfo, FALSE);
1036}
1037/*****************************************************************************
1038 * Function : GetMenuItemInfoW
1039 * Purpose : The GetMenuItemInfo function retrieves information about a menu item.
1040 * Parameters:
1041 * Variables :
1042 * Result : If the function succeeds, the return value is TRUE.
1043 * If the function fails, the return value is FALSE. To get extended
1044 * error information, use the GetLastError function.
1045 * Remark :
1046 * Status : UNTESTED STUB
1047 *
1048 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1049 *****************************************************************************/
1050
1051ODINFUNCTION4(BOOL, GetMenuItemInfoW,
1052 HMENU, hMenu,
1053 UINT, uItem,
1054 BOOL, byPos,
1055 MENUITEMINFOW *, lpMenuItemInfo)
1056{
1057 return GetMenuItemInfoAW(hMenu, uItem, byPos, (MENUITEMINFOA*)lpMenuItemInfo, TRUE);
1058}
1059/*****************************************************************************
1060 * Function : GetMenuItemRect
1061 * Purpose : The GetMenuItemRect function retrieves the bounding rectangle
1062 * for the specified menu item.
1063 * Parameters:
1064 * Variables :
1065 * Result : If the function succeeds, the return value is TRUE.
1066 * If the function fails, the return value is FALSE. To get
1067 * extended error information, use the GetLastError function.
1068 * Remark :
1069 * Status : UNTESTED STUB
1070 *
1071 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1072 *****************************************************************************/
1073
1074ODINFUNCTION4(BOOL, GetMenuItemRect,
1075 HWND, hWnd,
1076 HMENU, hMenu,
1077 UINT, uItem,
1078 LPRECT, lprcItem)
1079{
1080 dprintf(("USER32:GetMenuItemRect (%08xh,%08xh,%08xh,%08x) not implemented.\n",
1081 hWnd,
1082 hMenu,
1083 uItem,
1084 lprcItem));
1085
1086 return (FALSE);
1087}
1088/*****************************************************************************
1089 * Function : InsertMenuItemA
1090 * Purpose : The InsertMenuItem function inserts a new menu item at the specified
1091 * position in a menu bar or pop-up menu.
1092 * Parameters:
1093 * Variables :
1094 * Result : If the function succeeds, the return value is TRUE.
1095 * If the function fails, the return value is FALSE. To get extended
1096 * error information, use the GetLastError function.
1097 * Remark :
1098 * Status : UNTESTED STUB
1099 *
1100 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1101 *****************************************************************************/
1102
1103ODINFUNCTION4(BOOL, InsertMenuItemA,
1104 HMENU, hMenu,
1105 UINT, uItem,
1106 BOOL, fByPosition,
1107 const MENUITEMINFOA*, lpmii)
1108{
1109 dprintf(("USER32:InsertMenuItemA (%08xh,%08xh,%u,%08x) not correctly implemented.\n",
1110 hMenu,
1111 uItem,
1112 fByPosition,
1113 lpmii));
1114
1115 if(fByPosition) {
1116 return ODIN_InsertMenuA(hMenu, uItem, lpmii->fType | MF_BYPOSITION, (lpmii->fType & MF_POPUP) ? lpmii->hSubMenu : lpmii->wID, lpmii->dwTypeData);
1117 }
1118 else return ODIN_InsertMenuA(hMenu, uItem, lpmii->fType | MF_BYCOMMAND, (lpmii->fType & MF_POPUP) ? lpmii->hSubMenu : lpmii->wID, lpmii->dwTypeData);
1119}
1120
1121
1122/*****************************************************************************
1123 * Function : InsertMenuItemW
1124 * Purpose : The InsertMenuItem function inserts a new menu item at the specified
1125 * position in a menu bar or pop-up menu.
1126 * Parameters:
1127 * Variables :
1128 * Result : If the function succeeds, the return value is TRUE.
1129 * If the function fails, the return value is FALSE. To get extended
1130 * error information, use the GetLastError function.
1131 * Remark :
1132 * Status : UNTESTED STUB
1133 *
1134 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1135 *****************************************************************************/
1136
1137ODINFUNCTION4(BOOL, InsertMenuItemW,
1138 HMENU, hMenu,
1139 UINT, uItem,
1140 BOOL, fByPosition,
1141 const MENUITEMINFOW *, lpmii)
1142{
1143 dprintf(("USER32:InsertMenuItemW (%08xh,%08xh,%u,%08x) not correctly implemented.\n",
1144 hMenu,
1145 uItem,
1146 fByPosition,
1147 lpmii));
1148
1149 if(fByPosition) {
1150 return ODIN_InsertMenuW(hMenu, uItem, lpmii->fType | MF_BYPOSITION, (lpmii->fType & MF_POPUP) ? lpmii->hSubMenu : lpmii->wID, lpmii->dwTypeData);
1151 }
1152 else return ODIN_InsertMenuW(hMenu, uItem, lpmii->fType | MF_BYCOMMAND, (lpmii->fType & MF_POPUP) ? lpmii->hSubMenu : lpmii->wID, lpmii->dwTypeData);
1153}
1154/*****************************************************************************
1155 * Function : MenuItemFromPoint
1156 * Purpose : TheMenuItemFromPoint function determines which menu item, if
1157 * any, is at the specified location.
1158 * Parameters:
1159 * Variables :
1160 * Result : Returns the zero-based position of the menu item at the specified
1161 * location or -1 if no menu item is at the specified location.
1162 * Remark :
1163 * Status : UNTESTED STUB
1164 *
1165 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1166 *****************************************************************************/
1167
1168ODINFUNCTION3(UINT, MenuItemFromPoint,
1169 HWND, hWnd,
1170 HMENU, hMenu,
1171 POINT, ptScreen)
1172{
1173 dprintf(("USER32:MenuItemFromPoint (%08xh,%08xh,%u) not implemented.\n",
1174 hWnd,
1175 hMenu,
1176 ptScreen));
1177
1178 return (-1);
1179}
1180
1181
1182/*****************************************************************************
1183 * Function : GetMenuInfo
1184 * Parameters:
1185 * Variables :
1186 * Result :
1187 * Remark :
1188 * Status : UNTESTED STUB win98/NT5.0
1189 *
1190 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1191 *****************************************************************************/
1192
1193ODINFUNCTION2(BOOL, GetMenuInfo,
1194 HMENU, hMenu,
1195 LPMENUINFO, lpmi)
1196{
1197 POPUPMENU *menu;
1198
1199 menu = GetInternalMenuInfo(hMenu);
1200 if(menu == NULL) {
1201 dprintf(("USER32: GetMenuInfo(%08xh,%08xh) No POPUPMENU structure found!", hMenu, lpmi));
1202 SetLastError(ERROR_INVALID_PARAMETER);
1203 return FALSE;
1204 }
1205 dprintf(("USER32: GetMenuInfo(%08xh,%08xh)", hMenu, lpmi));
1206
1207 if (lpmi)
1208 {
1209 if (lpmi->fMask & MIM_BACKGROUND)
1210 lpmi->hbrBack = menu->hbrBack;
1211
1212 if (lpmi->fMask & MIM_HELPID)
1213 lpmi->dwContextHelpID = menu->dwContextHelpID;
1214
1215 if (lpmi->fMask & MIM_MAXHEIGHT)
1216 lpmi->cyMax = menu->cyMax;
1217
1218 if (lpmi->fMask & MIM_MENUDATA)
1219 lpmi->dwMenuData = menu->dwMenuData;
1220
1221 if (lpmi->fMask & MIM_STYLE)
1222 lpmi->dwStyle = menu->dwStyle;
1223
1224 return TRUE;
1225 }
1226 SetLastError(ERROR_INVALID_PARAMETER);
1227 return FALSE;
1228}
1229/*****************************************************************************
1230 * Function : SetMenuInfo
1231 * Purpose :
1232 * Parameters:
1233 * Variables :
1234 * Result :
1235 * Remark :
1236 * FIXME
1237 * MIM_APPLYTOSUBMENUS
1238 * actually use the items to draw the menu
1239 * Status : UNTESTED STUB win98/NT5.0
1240 *
1241 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
1242 *****************************************************************************/
1243
1244ODINFUNCTION2(BOOL, SetMenuInfo,
1245 HMENU, hMenu,
1246 LPCMENUINFO, lpmi)
1247{
1248 POPUPMENU *menu;
1249
1250 menu = GetInternalMenuInfo(hMenu);
1251 if(menu == NULL) {
1252 dprintf(("USER32: SetMenuInfo(%08xh,%08xh) No POPUPMENU structure found!", hMenu, lpmi));
1253 SetLastError(ERROR_INVALID_PARAMETER);
1254 return FALSE;
1255 }
1256
1257 dprintf(("USER32: SetMenuInfo(%08xh,%08xh)", hMenu, lpmi));
1258
1259 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)))
1260 {
1261 if (lpmi->fMask & MIM_BACKGROUND)
1262 menu->hbrBack = lpmi->hbrBack;
1263
1264 if (lpmi->fMask & MIM_HELPID)
1265 menu->dwContextHelpID = lpmi->dwContextHelpID;
1266
1267 if (lpmi->fMask & MIM_MAXHEIGHT)
1268 menu->cyMax = lpmi->cyMax;
1269
1270 if (lpmi->fMask & MIM_MENUDATA)
1271 menu->dwMenuData = lpmi->dwMenuData;
1272
1273 if (lpmi->fMask & MIM_STYLE)
1274 menu->dwStyle = lpmi->dwStyle;
1275
1276 return TRUE;
1277 }
1278 SetLastError(ERROR_INVALID_PARAMETER);
1279 return FALSE;
1280}
1281//******************************************************************************
1282//******************************************************************************
1283
Note: See TracBrowser for help on using the repository browser.