- 3d buffers produce sounds
[wine/hacks.git] / dlls / shell32 / shlmenu.c
blob6ddd6e738884813f9e88f405e266e0a31f258559
1 /*
2 * see www.geocities.com/SiliconValley/4942/filemenu.html
4 * Copyright 1999, 2000 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <string.h>
23 #include "winreg.h"
24 #include "shlobj.h"
25 #include "undocshell.h"
26 #include "shlwapi.h"
27 #include "heap.h"
28 #include "shell32_main.h"
29 #include "shlguid.h"
31 #include "pidl.h"
32 #include "wine/debug.h"
34 static BOOL FileMenu_AppendItemA(HMENU hMenu, LPCSTR lpText, UINT uID, int icon,
35 HMENU hMenuPopup, int nItemHeight);
37 typedef struct
39 BOOL bInitialized;
40 BOOL bFixedItems;
41 /* create */
42 COLORREF crBorderColor;
43 int nBorderWidth;
44 HBITMAP hBorderBmp;
46 /* insert using pidl */
47 LPITEMIDLIST pidl;
48 UINT uID;
49 UINT uFlags;
50 UINT uEnumFlags;
51 LPFNFMCALLBACK lpfnCallback;
52 } FMINFO, *LPFMINFO;
54 typedef struct
55 { int cchItemText;
56 int iIconIndex;
57 HMENU hMenu;
58 char szItemText[1];
59 } FMITEM, * LPFMITEM;
61 static BOOL bAbortInit;
63 #define CCH_MAXITEMTEXT 256
65 WINE_DEFAULT_DEBUG_CHANNEL(shell);
67 LPFMINFO FM_GetMenuInfo(HMENU hmenu)
68 { MENUINFO MenuInfo;
69 LPFMINFO menudata;
71 MenuInfo.cbSize = sizeof(MENUINFO);
72 MenuInfo.fMask = MIM_MENUDATA;
74 if (! GetMenuInfo(hmenu, &MenuInfo))
75 return NULL;
77 menudata = (LPFMINFO)MenuInfo.dwMenuData;
79 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
81 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
82 return 0;
85 return menudata;
88 /*************************************************************************
89 * FM_SetMenuParameter [internal]
92 static LPFMINFO FM_SetMenuParameter(
93 HMENU hmenu,
94 UINT uID,
95 LPCITEMIDLIST pidl,
96 UINT uFlags,
97 UINT uEnumFlags,
98 LPFNFMCALLBACK lpfnCallback)
100 LPFMINFO menudata;
102 TRACE("\n");
104 menudata = FM_GetMenuInfo(hmenu);
106 if ( menudata->pidl)
107 { SHFree(menudata->pidl);
110 menudata->uID = uID;
111 menudata->pidl = ILClone(pidl);
112 menudata->uFlags = uFlags;
113 menudata->uEnumFlags = uEnumFlags;
114 menudata->lpfnCallback = lpfnCallback;
116 return menudata;
119 /*************************************************************************
120 * FM_InitMenuPopup [internal]
123 static int FM_InitMenuPopup(HMENU hmenu, LPITEMIDLIST pAlternatePidl)
124 { IShellFolder *lpsf, *lpsf2;
125 ULONG ulItemAttr = SFGAO_FOLDER;
126 UINT uID, uFlags, uEnumFlags;
127 LPFNFMCALLBACK lpfnCallback;
128 LPITEMIDLIST pidl;
129 char sTemp[MAX_PATH];
130 int NumberOfItems = 0, iIcon;
131 MENUINFO MenuInfo;
132 LPFMINFO menudata;
134 TRACE("%p %p\n", hmenu, pAlternatePidl);
136 MenuInfo.cbSize = sizeof(MENUINFO);
137 MenuInfo.fMask = MIM_MENUDATA;
139 if (! GetMenuInfo(hmenu, &MenuInfo))
140 return FALSE;
142 menudata = (LPFMINFO)MenuInfo.dwMenuData;
144 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
146 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
147 return 0;
150 if (menudata->bInitialized)
151 return 0;
153 pidl = ((pAlternatePidl) ? pAlternatePidl : menudata->pidl);
154 if (!pidl)
155 return 0;
157 uID = menudata->uID;
158 uFlags = menudata->uFlags;
159 uEnumFlags = menudata->uEnumFlags;
160 lpfnCallback = menudata->lpfnCallback;
161 menudata->bInitialized = FALSE;
163 SetMenuInfo(hmenu, &MenuInfo);
165 if (SUCCEEDED (SHGetDesktopFolder(&lpsf)))
167 if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
169 IEnumIDList *lpe = NULL;
171 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe )))
174 LPITEMIDLIST pidlTemp = NULL;
175 ULONG ulFetched;
177 while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)))
179 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulItemAttr)))
181 ILGetDisplayName( pidlTemp, sTemp);
182 if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon)))
183 iIcon = FM_BLANK_ICON;
184 if ( SFGAO_FOLDER & ulItemAttr)
186 LPFMINFO lpFmMi;
187 MENUINFO MenuInfo;
188 HMENU hMenuPopup = CreatePopupMenu();
190 lpFmMi = (LPFMINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
192 lpFmMi->pidl = ILCombine(pidl, pidlTemp);
193 lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
195 MenuInfo.cbSize = sizeof(MENUINFO);
196 MenuInfo.fMask = MIM_MENUDATA;
197 MenuInfo.dwMenuData = (DWORD) lpFmMi;
198 SetMenuInfo (hMenuPopup, &MenuInfo);
200 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT);
202 else
204 ((LPSTR)PathFindExtensionA(sTemp))[0] = 0x00;
205 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
209 if (lpfnCallback)
211 TRACE("enter callback\n");
212 lpfnCallback ( pidl, pidlTemp);
213 TRACE("leave callback\n");
216 NumberOfItems++;
218 IEnumIDList_Release (lpe);
220 IShellFolder_Release(lpsf2);
222 IShellFolder_Release(lpsf);
225 if ( GetMenuItemCount (hmenu) == 0 )
226 { FileMenu_AppendItemA (hmenu, "(empty)", uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
227 NumberOfItems++;
230 menudata->bInitialized = TRUE;
231 SetMenuInfo(hmenu, &MenuInfo);
233 return NumberOfItems;
235 /*************************************************************************
236 * FileMenu_Create [SHELL32.114]
238 * NOTES
239 * for non-root menus values are
240 * (ffffffff,00000000,00000000,00000000,00000000)
242 HMENU WINAPI FileMenu_Create (
243 COLORREF crBorderColor,
244 int nBorderWidth,
245 HBITMAP hBorderBmp,
246 int nSelHeight,
247 UINT uFlags)
249 MENUINFO MenuInfo;
250 LPFMINFO menudata;
252 HMENU hMenu = CreatePopupMenu();
254 TRACE("0x%08lx 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
255 crBorderColor, nBorderWidth, hBorderBmp, nSelHeight, uFlags, hMenu);
257 menudata = (LPFMINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
258 menudata->crBorderColor = crBorderColor;
259 menudata->nBorderWidth = nBorderWidth;
260 menudata->hBorderBmp = hBorderBmp;
262 MenuInfo.cbSize = sizeof(MENUINFO);
263 MenuInfo.fMask = MIM_MENUDATA;
264 MenuInfo.dwMenuData = (DWORD) menudata;
265 SetMenuInfo (hMenu, &MenuInfo);
267 return hMenu;
270 /*************************************************************************
271 * FileMenu_Destroy [SHELL32.118]
273 * NOTES
274 * exported by name
276 void WINAPI FileMenu_Destroy (HMENU hmenu)
278 LPFMINFO menudata;
280 TRACE("%p\n", hmenu);
282 FileMenu_DeleteAllItems (hmenu);
284 menudata = FM_GetMenuInfo(hmenu);
286 if ( menudata->pidl)
287 { SHFree( menudata->pidl);
289 HeapFree(GetProcessHeap(), 0, menudata);
291 DestroyMenu (hmenu);
294 /*************************************************************************
295 * FileMenu_AppendItem [SHELL32.115]
298 static BOOL FileMenu_AppendItemA(
299 HMENU hMenu,
300 LPCSTR lpText,
301 UINT uID,
302 int icon,
303 HMENU hMenuPopup,
304 int nItemHeight)
306 LPSTR lpszText = (LPSTR)lpText;
307 MENUITEMINFOA mii;
308 LPFMITEM myItem;
309 LPFMINFO menudata;
310 MENUINFO MenuInfo;
313 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
314 hMenu, (lpszText!=FM_SEPARATOR) ? lpText: NULL,
315 uID, icon, hMenuPopup, nItemHeight);
317 ZeroMemory (&mii, sizeof(MENUITEMINFOA));
319 mii.cbSize = sizeof(MENUITEMINFOA);
321 if (lpText != FM_SEPARATOR)
322 { int len = strlen (lpText);
323 myItem = (LPFMITEM) SHAlloc( sizeof(FMITEM) + len);
324 strcpy (myItem->szItemText, lpText);
325 myItem->cchItemText = len;
326 myItem->iIconIndex = icon;
327 myItem->hMenu = hMenu;
328 mii.fMask = MIIM_DATA;
329 mii.dwItemData = (DWORD) myItem;
332 if ( hMenuPopup )
333 { /* sub menu */
334 mii.fMask |= MIIM_TYPE | MIIM_SUBMENU;
335 mii.fType = MFT_OWNERDRAW;
336 mii.hSubMenu = hMenuPopup;
338 else if (lpText == FM_SEPARATOR )
339 { mii.fMask |= MIIM_ID | MIIM_TYPE;
340 mii.fType = MFT_SEPARATOR;
342 else
343 { /* normal item */
344 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
345 mii.fState = MFS_ENABLED | MFS_DEFAULT;
346 mii.fType = MFT_OWNERDRAW;
348 mii.wID = uID;
350 InsertMenuItemA (hMenu, (UINT)-1, TRUE, &mii);
352 /* set bFixedItems to true */
353 MenuInfo.cbSize = sizeof(MENUINFO);
354 MenuInfo.fMask = MIM_MENUDATA;
356 if (! GetMenuInfo(hMenu, &MenuInfo))
357 return FALSE;
359 menudata = (LPFMINFO)MenuInfo.dwMenuData;
360 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
362 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
363 return 0;
366 menudata->bFixedItems = TRUE;
367 SetMenuInfo(hMenu, &MenuInfo);
369 return TRUE;
373 /**********************************************************************/
375 BOOL WINAPI FileMenu_AppendItemAW(
376 HMENU hMenu,
377 LPCVOID lpText,
378 UINT uID,
379 int icon,
380 HMENU hMenuPopup,
381 int nItemHeight)
383 BOOL ret;
384 LPSTR lpszText=NULL;
386 if (SHELL_OsIsUnicode() && (lpText!=FM_SEPARATOR))
387 lpszText = HEAP_strdupWtoA ( GetProcessHeap(),0, lpText);
389 ret = FileMenu_AppendItemA(hMenu, (lpszText) ? lpszText : lpText, uID, icon, hMenuPopup, nItemHeight);
391 if (lpszText)
392 HeapFree( GetProcessHeap(), 0, lpszText );
394 return ret;
396 /*************************************************************************
397 * FileMenu_InsertUsingPidl [SHELL32.110]
399 * NOTES
400 * uEnumFlags any SHCONTF flag
402 int WINAPI FileMenu_InsertUsingPidl (
403 HMENU hmenu,
404 UINT uID,
405 LPCITEMIDLIST pidl,
406 UINT uFlags,
407 UINT uEnumFlags,
408 LPFNFMCALLBACK lpfnCallback)
410 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
411 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
413 pdump (pidl);
415 bAbortInit = FALSE;
417 FM_SetMenuParameter(hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
419 return FM_InitMenuPopup(hmenu, NULL);
422 /*************************************************************************
423 * FileMenu_ReplaceUsingPidl [SHELL32.113]
425 * FIXME: the static items are deleted but wont be refreshed
427 int WINAPI FileMenu_ReplaceUsingPidl(
428 HMENU hmenu,
429 UINT uID,
430 LPCITEMIDLIST pidl,
431 UINT uEnumFlags,
432 LPFNFMCALLBACK lpfnCallback)
434 TRACE("%p 0x%08x %p 0x%08x %p\n",
435 hmenu, uID, pidl, uEnumFlags, lpfnCallback);
437 FileMenu_DeleteAllItems (hmenu);
439 FM_SetMenuParameter(hmenu, uID, pidl, 0, uEnumFlags, lpfnCallback);
441 return FM_InitMenuPopup(hmenu, NULL);
444 /*************************************************************************
445 * FileMenu_Invalidate [SHELL32.111]
447 void WINAPI FileMenu_Invalidate (HMENU hMenu)
449 FIXME("%p\n",hMenu);
452 /*************************************************************************
453 * FileMenu_FindSubMenuByPidl [SHELL32.106]
455 HMENU WINAPI FileMenu_FindSubMenuByPidl(
456 HMENU hMenu,
457 LPCITEMIDLIST pidl)
459 FIXME("%p %p\n",hMenu, pidl);
460 return 0;
463 /*************************************************************************
464 * FileMenu_AppendFilesForPidl [SHELL32.124]
466 int WINAPI FileMenu_AppendFilesForPidl(
467 HMENU hmenu,
468 LPCITEMIDLIST pidl,
469 BOOL bAddSeperator)
471 LPFMINFO menudata;
473 menudata = FM_GetMenuInfo(hmenu);
475 menudata->bInitialized = FALSE;
477 FM_InitMenuPopup(hmenu, pidl);
479 if (bAddSeperator)
480 FileMenu_AppendItemA (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
482 TRACE("%p %p 0x%08x\n",hmenu, pidl,bAddSeperator);
484 return 0;
486 /*************************************************************************
487 * FileMenu_AddFilesForPidl [SHELL32.125]
489 * NOTES
490 * uEnumFlags any SHCONTF flag
492 int WINAPI FileMenu_AddFilesForPidl (
493 HMENU hmenu,
494 UINT uReserved,
495 UINT uID,
496 LPCITEMIDLIST pidl,
497 UINT uFlags,
498 UINT uEnumFlags,
499 LPFNFMCALLBACK lpfnCallback)
501 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
502 hmenu, uReserved, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
504 return FileMenu_InsertUsingPidl ( hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
509 /*************************************************************************
510 * FileMenu_TrackPopupMenuEx [SHELL32.116]
512 BOOL WINAPI FileMenu_TrackPopupMenuEx (
513 HMENU hMenu,
514 UINT uFlags,
515 int x,
516 int y,
517 HWND hWnd,
518 LPTPMPARAMS lptpm)
520 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
521 hMenu, uFlags, x, y, hWnd, lptpm);
522 return TrackPopupMenuEx(hMenu, uFlags, x, y, hWnd, lptpm);
525 /*************************************************************************
526 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
528 BOOL WINAPI FileMenu_GetLastSelectedItemPidls(
529 UINT uReserved,
530 LPCITEMIDLIST *ppidlFolder,
531 LPCITEMIDLIST *ppidlItem)
533 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
534 return 0;
537 #define FM_ICON_SIZE 16
538 #define FM_Y_SPACE 4
539 #define FM_SPACE1 4
540 #define FM_SPACE2 2
541 #define FM_LEFTBORDER 2
542 #define FM_RIGHTBORDER 8
543 /*************************************************************************
544 * FileMenu_MeasureItem [SHELL32.112]
546 LRESULT WINAPI FileMenu_MeasureItem(
547 HWND hWnd,
548 LPMEASUREITEMSTRUCT lpmis)
550 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
551 HDC hdc = GetDC(hWnd);
552 SIZE size;
553 LPFMINFO menuinfo;
555 TRACE("%p %p %s\n", hWnd, lpmis, pMyItem->szItemText);
557 GetTextExtentPoint32A(hdc, pMyItem->szItemText, pMyItem->cchItemText, &size);
559 lpmis->itemWidth = size.cx + FM_LEFTBORDER + FM_ICON_SIZE + FM_SPACE1 + FM_SPACE2 + FM_RIGHTBORDER;
560 lpmis->itemHeight = (size.cy > (FM_ICON_SIZE + FM_Y_SPACE)) ? size.cy : (FM_ICON_SIZE + FM_Y_SPACE);
562 /* add the menubitmap */
563 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
564 if (menuinfo->nBorderWidth)
565 lpmis->itemWidth += menuinfo->nBorderWidth;
567 TRACE("-- 0x%04x 0x%04x\n", lpmis->itemWidth, lpmis->itemHeight);
568 ReleaseDC (hWnd, hdc);
569 return 0;
571 /*************************************************************************
572 * FileMenu_DrawItem [SHELL32.105]
574 LRESULT WINAPI FileMenu_DrawItem(
575 HWND hWnd,
576 LPDRAWITEMSTRUCT lpdis)
578 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
579 COLORREF clrPrevText, clrPrevBkgnd;
580 int xi,yi,xt,yt;
581 HIMAGELIST hImageList;
582 RECT TextRect, BorderRect;
583 LPFMINFO menuinfo;
585 TRACE("%p %p %s\n", hWnd, lpdis, pMyItem->szItemText);
587 if (lpdis->itemState & ODS_SELECTED)
589 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
590 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
592 else
594 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_MENUTEXT));
595 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_MENU));
598 CopyRect(&TextRect, &(lpdis->rcItem));
600 /* add the menubitmap */
601 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
602 if (menuinfo->nBorderWidth)
603 TextRect.left += menuinfo->nBorderWidth;
605 BorderRect.right = menuinfo->nBorderWidth;
606 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
608 TextRect.left += FM_LEFTBORDER;
609 xi = TextRect.left + FM_SPACE1;
610 yi = TextRect.top + FM_Y_SPACE/2;
611 TextRect.bottom -= FM_Y_SPACE/2;
613 xt = xi + FM_ICON_SIZE + FM_SPACE2;
614 yt = yi;
616 ExtTextOutA (lpdis->hDC, xt , yt, ETO_OPAQUE, &TextRect, pMyItem->szItemText, pMyItem->cchItemText, NULL);
618 Shell_GetImageList(0, &hImageList);
619 ImageList_Draw(hImageList, pMyItem->iIconIndex, lpdis->hDC, xi, yi, ILD_NORMAL);
621 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect.left, TextRect.top, TextRect.right, TextRect.bottom);
623 SetTextColor(lpdis->hDC, clrPrevText);
624 SetBkColor(lpdis->hDC, clrPrevBkgnd);
626 return TRUE;
629 /*************************************************************************
630 * FileMenu_InitMenuPopup [SHELL32.109]
632 * NOTES
633 * The filemenu is a ownerdrawn menu. Call this function responding to
634 * WM_INITPOPUPMENU
637 BOOL WINAPI FileMenu_InitMenuPopup (HMENU hmenu)
639 FM_InitMenuPopup(hmenu, NULL);
640 return TRUE;
643 /*************************************************************************
644 * FileMenu_HandleMenuChar [SHELL32.108]
646 LRESULT WINAPI FileMenu_HandleMenuChar(
647 HMENU hMenu,
648 WPARAM wParam)
650 FIXME("%p 0x%08x\n",hMenu,wParam);
651 return 0;
654 /*************************************************************************
655 * FileMenu_DeleteAllItems [SHELL32.104]
657 * NOTES
658 * exported by name
660 BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
662 MENUITEMINFOA mii;
663 LPFMINFO menudata;
665 int i;
667 TRACE("%p\n", hmenu);
669 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
670 mii.cbSize = sizeof(MENUITEMINFOA);
671 mii.fMask = MIIM_SUBMENU|MIIM_DATA;
673 for (i = 0; i < GetMenuItemCount( hmenu ); i++)
674 { GetMenuItemInfoA(hmenu, i, TRUE, &mii );
676 if (mii.dwItemData)
677 SHFree((LPFMINFO)mii.dwItemData);
679 if (mii.hSubMenu)
680 FileMenu_Destroy(mii.hSubMenu);
683 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
685 menudata = FM_GetMenuInfo(hmenu);
687 menudata->bInitialized = FALSE;
689 return TRUE;
692 /*************************************************************************
693 * FileMenu_DeleteItemByCmd [SHELL32.117]
696 BOOL WINAPI FileMenu_DeleteItemByCmd (HMENU hMenu, UINT uID)
698 MENUITEMINFOA mii;
700 TRACE("%p 0x%08x\n", hMenu, uID);
702 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
703 mii.cbSize = sizeof(MENUITEMINFOA);
704 mii.fMask = MIIM_SUBMENU;
706 GetMenuItemInfoA(hMenu, uID, FALSE, &mii );
707 if ( mii.hSubMenu )
709 /* FIXME: Do what? */
712 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
713 return TRUE;
716 /*************************************************************************
717 * FileMenu_DeleteItemByIndex [SHELL32.140]
719 BOOL WINAPI FileMenu_DeleteItemByIndex ( HMENU hMenu, UINT uPos)
721 MENUITEMINFOA mii;
723 TRACE("%p 0x%08x\n", hMenu, uPos);
725 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
726 mii.cbSize = sizeof(MENUITEMINFOA);
727 mii.fMask = MIIM_SUBMENU;
729 GetMenuItemInfoA(hMenu, uPos, TRUE, &mii );
730 if ( mii.hSubMenu )
732 /* FIXME: Do what? */
735 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
736 return TRUE;
739 /*************************************************************************
740 * FileMenu_DeleteItemByFirstID [SHELL32.141]
742 BOOL WINAPI FileMenu_DeleteItemByFirstID(
743 HMENU hMenu,
744 UINT uID)
746 TRACE("%p 0x%08x\n", hMenu, uID);
747 return 0;
750 /*************************************************************************
751 * FileMenu_DeleteSeparator [SHELL32.142]
753 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu)
755 TRACE("%p\n", hMenu);
756 return 0;
759 /*************************************************************************
760 * FileMenu_EnableItemByCmd [SHELL32.143]
762 BOOL WINAPI FileMenu_EnableItemByCmd(
763 HMENU hMenu,
764 UINT uID,
765 BOOL bEnable)
767 TRACE("%p 0x%08x 0x%08x\n", hMenu, uID,bEnable);
768 return 0;
771 /*************************************************************************
772 * FileMenu_GetItemExtent [SHELL32.144]
774 * NOTES
775 * if the menu is too big, entries are getting cut away!!
777 DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos)
778 { RECT rect;
780 FIXME("%p 0x%08x\n", hMenu, uPos);
782 if (GetMenuItemRect(0, hMenu, uPos, &rect))
783 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
784 rect.right, rect.left, rect.top, rect.bottom);
785 return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom);
787 return 0x00100010; /*FIXME*/
790 /*************************************************************************
791 * FileMenu_AbortInitMenu [SHELL32.120]
794 void WINAPI FileMenu_AbortInitMenu (void)
795 { TRACE("\n");
796 bAbortInit = TRUE;
799 /*************************************************************************
800 * SHFind_InitMenuPopup [SHELL32.149]
803 * PARAMETERS
804 * hMenu [in] handle of menu previously created
805 * hWndParent [in] parent window
806 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
807 * x [in] no pointer (0x226 over here)
809 * RETURNS
810 * LPXXXXX pointer to struct containing a func addr at offset 8
811 * or NULL at failure.
813 LPVOID WINAPI SHFind_InitMenuPopup (HMENU hMenu, HWND hWndParent, DWORD w, DWORD x)
814 { FIXME("hmenu=%p hwnd=%p 0x%08lx 0x%08lx stub\n",
815 hMenu,hWndParent,w,x);
816 return NULL; /* this is supposed to be a pointer */
819 /*************************************************************************
820 * Shell_MergeMenus [SHELL32.67]
823 BOOL _SHIsMenuSeparator(HMENU hm, int i)
825 MENUITEMINFOA mii;
827 mii.cbSize = sizeof(MENUITEMINFOA);
828 mii.fMask = MIIM_TYPE;
829 mii.cch = 0; /* WARNING: We MUST initialize it to 0*/
830 if (!GetMenuItemInfoA(hm, i, TRUE, &mii))
832 return(FALSE);
835 if (mii.fType & MFT_SEPARATOR)
837 return(TRUE);
840 return(FALSE);
843 /**********************************************************************/
845 HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
846 { int nItem;
847 HMENU hmSubMenu;
848 BOOL bAlreadySeparated;
849 MENUITEMINFOA miiSrc;
850 char szName[256];
851 UINT uTemp, uIDMax = uIDAdjust;
853 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04lx\n",
854 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
856 if (!hmDst || !hmSrc)
857 { return uIDMax;
860 nItem = GetMenuItemCount(hmDst);
862 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
864 uInsert = (UINT)nItem; /* append on the end */
865 bAlreadySeparated = TRUE;
867 else
869 bAlreadySeparated = _SHIsMenuSeparator(hmDst, uInsert);
872 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
874 /* Add a separator between the menus */
875 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
876 bAlreadySeparated = TRUE;
880 /* Go through the menu items and clone them*/
881 for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
883 miiSrc.cbSize = sizeof(MENUITEMINFOA);
884 miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
886 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
887 miiSrc.fType = MFT_STRING;
888 miiSrc.dwTypeData = szName;
889 miiSrc.dwItemData = 0;
890 miiSrc.cch = sizeof(szName);
892 if (!GetMenuItemInfoA(hmSrc, nItem, TRUE, &miiSrc))
894 continue;
897 /* TRACE("found menu=0x%04x %s id=0x%04x mask=0x%08x smenu=0x%04x\n", hmSrc, debugstr_a(miiSrc.dwTypeData), miiSrc.wID, miiSrc.fMask, miiSrc.hSubMenu);
899 if (miiSrc.fType & MFT_SEPARATOR)
901 /* This is a separator; don't put two of them in a row */
902 if (bAlreadySeparated)
903 continue;
905 bAlreadySeparated = TRUE;
907 else if (miiSrc.hSubMenu)
909 if (uFlags & MM_SUBMENUSHAVEIDS)
911 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
913 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
914 continue;
916 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
917 uIDMax = miiSrc.wID + 1;
919 else
921 miiSrc.fMask &= ~MIIM_ID; /* Don't set IDs for submenus that didn't have them already */
923 hmSubMenu = miiSrc.hSubMenu;
925 miiSrc.hSubMenu = CreatePopupMenu();
927 if (!miiSrc.hSubMenu) return(uIDMax);
929 uTemp = Shell_MergeMenus(miiSrc.hSubMenu, hmSubMenu, 0, uIDAdjust, uIDAdjustMax, uFlags & MM_SUBMENUSHAVEIDS);
931 if (uIDMax <= uTemp)
932 uIDMax = uTemp;
934 bAlreadySeparated = FALSE;
936 else /* normal menu item */
938 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
940 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
941 continue;
943 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
944 uIDMax = miiSrc.wID + 1;
946 bAlreadySeparated = FALSE;
949 /* TRACE("inserting menu=0x%04x %s id=0x%04x mask=0x%08x smenu=0x%04x\n", hmDst, debugstr_a(miiSrc.dwTypeData), miiSrc.wID, miiSrc.fMask, miiSrc.hSubMenu);
951 if (!InsertMenuItemA(hmDst, uInsert, TRUE, &miiSrc))
953 return(uIDMax);
957 /* Ensure the correct number of separators at the beginning of the
958 inserted menu items*/
959 if (uInsert == 0)
961 if (bAlreadySeparated)
963 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
966 else
968 if (_SHIsMenuSeparator(hmDst, uInsert-1))
970 if (bAlreadySeparated)
972 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
975 else
977 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
979 /* Add a separator between the menus*/
980 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
984 return(uIDMax);