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
25 #include "wine/obj_base.h"
26 #include "wine/obj_enumidlist.h"
27 #include "wine/obj_shellfolder.h"
28 #include "undocshell.h"
31 #include "shell32_main.h"
35 #include "wine/debug.h"
37 static BOOL FileMenu_AppendItemA(HMENU hMenu, LPCSTR lpText, UINT uID, int icon,
38 HMENU hMenuPopup, int nItemHeight);
45 COLORREF crBorderColor;
49 /* insert using pidl */
54 LPFNFMCALLBACK lpfnCallback;
64 static BOOL bAbortInit;
66 #define CCH_MAXITEMTEXT 256
68 WINE_DEFAULT_DEBUG_CHANNEL(shell);
70 LPFMINFO FM_GetMenuInfo(HMENU hmenu)
74 MenuInfo.cbSize = sizeof(MENUINFO);
75 MenuInfo.fMask = MIM_MENUDATA;
77 if (! GetMenuInfo(hmenu, &MenuInfo))
80 menudata = (LPFMINFO)MenuInfo.dwMenuData;
82 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
84 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
91 /*************************************************************************
92 * FM_SetMenuParameter [internal]
95 static LPFMINFO FM_SetMenuParameter(
101 LPFNFMCALLBACK lpfnCallback)
107 menudata = FM_GetMenuInfo(hmenu);
110 { SHFree(menudata->pidl);
114 menudata->pidl = ILClone(pidl);
115 menudata->uFlags = uFlags;
116 menudata->uEnumFlags = uEnumFlags;
117 menudata->lpfnCallback = lpfnCallback;
122 /*************************************************************************
123 * FM_InitMenuPopup [internal]
126 static int FM_InitMenuPopup(HMENU hmenu, LPITEMIDLIST pAlternatePidl)
127 { IShellFolder *lpsf, *lpsf2;
128 ULONG ulItemAttr = SFGAO_FOLDER;
129 UINT uID, uFlags, uEnumFlags;
130 LPFNFMCALLBACK lpfnCallback;
132 char sTemp[MAX_PATH];
133 int NumberOfItems = 0, iIcon;
137 TRACE("0x%04x %p\n", hmenu, pAlternatePidl);
139 MenuInfo.cbSize = sizeof(MENUINFO);
140 MenuInfo.fMask = MIM_MENUDATA;
142 if (! GetMenuInfo(hmenu, &MenuInfo))
145 menudata = (LPFMINFO)MenuInfo.dwMenuData;
147 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
149 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
153 if (menudata->bInitialized)
156 pidl = ((pAlternatePidl) ? pAlternatePidl : menudata->pidl);
161 uFlags = menudata->uFlags;
162 uEnumFlags = menudata->uEnumFlags;
163 lpfnCallback = menudata->lpfnCallback;
164 menudata->bInitialized = FALSE;
166 SetMenuInfo(hmenu, &MenuInfo);
168 if (SUCCEEDED (SHGetDesktopFolder(&lpsf)))
170 if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
172 IEnumIDList *lpe = NULL;
174 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe )))
177 LPITEMIDLIST pidlTemp = NULL;
180 while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)))
182 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulItemAttr)))
184 ILGetDisplayName( pidlTemp, sTemp);
185 if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon)))
186 iIcon = FM_BLANK_ICON;
187 if ( SFGAO_FOLDER & ulItemAttr)
191 HMENU hMenuPopup = CreatePopupMenu();
193 lpFmMi = (LPFMINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
195 lpFmMi->pidl = ILCombine(pidl, pidlTemp);
196 lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
198 MenuInfo.cbSize = sizeof(MENUINFO);
199 MenuInfo.fMask = MIM_MENUDATA;
200 MenuInfo.dwMenuData = (DWORD) lpFmMi;
201 SetMenuInfo (hMenuPopup, &MenuInfo);
203 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT);
207 ((LPSTR)PathFindExtensionA(sTemp))[0] = 0x00;
208 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
214 TRACE("enter callback\n");
215 lpfnCallback ( pidl, pidlTemp);
216 TRACE("leave callback\n");
221 IEnumIDList_Release (lpe);
223 IShellFolder_Release(lpsf2);
225 IShellFolder_Release(lpsf);
228 if ( GetMenuItemCount (hmenu) == 0 )
229 { FileMenu_AppendItemA (hmenu, "(empty)", uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
233 menudata->bInitialized = TRUE;
234 SetMenuInfo(hmenu, &MenuInfo);
236 return NumberOfItems;
238 /*************************************************************************
239 * FileMenu_Create [SHELL32.114]
242 * for non-root menus values are
243 * (ffffffff,00000000,00000000,00000000,00000000)
245 HMENU WINAPI FileMenu_Create (
246 COLORREF crBorderColor,
255 HMENU hMenu = CreatePopupMenu();
257 TRACE("0x%08lx 0x%08x 0x%08x 0x%08x 0x%08x hMenu=0x%08x\n",
258 crBorderColor, nBorderWidth, hBorderBmp, nSelHeight, uFlags, hMenu);
260 menudata = (LPFMINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
261 menudata->crBorderColor = crBorderColor;
262 menudata->nBorderWidth = nBorderWidth;
263 menudata->hBorderBmp = hBorderBmp;
265 MenuInfo.cbSize = sizeof(MENUINFO);
266 MenuInfo.fMask = MIM_MENUDATA;
267 MenuInfo.dwMenuData = (DWORD) menudata;
268 SetMenuInfo (hMenu, &MenuInfo);
273 /*************************************************************************
274 * FileMenu_Destroy [SHELL32.118]
279 void WINAPI FileMenu_Destroy (HMENU hmenu)
283 TRACE("0x%08x\n", hmenu);
285 FileMenu_DeleteAllItems (hmenu);
287 menudata = FM_GetMenuInfo(hmenu);
290 { SHFree( menudata->pidl);
292 HeapFree(GetProcessHeap(), 0, menudata);
297 /*************************************************************************
298 * FileMenu_AppendItem [SHELL32.115]
301 static BOOL FileMenu_AppendItemA(
309 LPSTR lpszText = (LPSTR)lpText;
316 TRACE("0x%08x %s 0x%08x 0x%08x 0x%08x 0x%08x\n",
317 hMenu, (lpszText!=FM_SEPARATOR) ? lpText: NULL,
318 uID, icon, hMenuPopup, nItemHeight);
320 ZeroMemory (&mii, sizeof(MENUITEMINFOA));
322 mii.cbSize = sizeof(MENUITEMINFOA);
324 if (lpText != FM_SEPARATOR)
325 { int len = strlen (lpText);
326 myItem = (LPFMITEM) SHAlloc( sizeof(FMITEM) + len);
327 strcpy (myItem->szItemText, lpText);
328 myItem->cchItemText = len;
329 myItem->iIconIndex = icon;
330 myItem->hMenu = hMenu;
331 mii.fMask = MIIM_DATA;
332 mii.dwItemData = (DWORD) myItem;
337 mii.fMask |= MIIM_TYPE | MIIM_SUBMENU;
338 mii.fType = MFT_OWNERDRAW;
339 mii.hSubMenu = hMenuPopup;
341 else if (lpText == FM_SEPARATOR )
342 { mii.fMask |= MIIM_ID | MIIM_TYPE;
343 mii.fType = MFT_SEPARATOR;
347 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
348 mii.fState = MFS_ENABLED | MFS_DEFAULT;
349 mii.fType = MFT_OWNERDRAW;
353 InsertMenuItemA (hMenu, (UINT)-1, TRUE, &mii);
355 /* set bFixedItems to true */
356 MenuInfo.cbSize = sizeof(MENUINFO);
357 MenuInfo.fMask = MIM_MENUDATA;
359 if (! GetMenuInfo(hMenu, &MenuInfo))
362 menudata = (LPFMINFO)MenuInfo.dwMenuData;
363 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
365 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
369 menudata->bFixedItems = TRUE;
370 SetMenuInfo(hMenu, &MenuInfo);
376 /**********************************************************************/
378 BOOL WINAPI FileMenu_AppendItemAW(
389 if (SHELL_OsIsUnicode() && (lpText!=FM_SEPARATOR))
390 lpszText = HEAP_strdupWtoA ( GetProcessHeap(),0, lpText);
392 ret = FileMenu_AppendItemA(hMenu, (lpszText) ? lpszText : lpText, uID, icon, hMenuPopup, nItemHeight);
395 HeapFree( GetProcessHeap(), 0, lpszText );
399 /*************************************************************************
400 * FileMenu_InsertUsingPidl [SHELL32.110]
403 * uEnumFlags any SHCONTF flag
405 int WINAPI FileMenu_InsertUsingPidl (
411 LPFNFMCALLBACK lpfnCallback)
413 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
414 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
420 FM_SetMenuParameter(hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
422 return FM_InitMenuPopup(hmenu, NULL);
425 /*************************************************************************
426 * FileMenu_ReplaceUsingPidl [SHELL32.113]
428 * FIXME: the static items are deleted but wont be refreshed
430 int WINAPI FileMenu_ReplaceUsingPidl(
435 LPFNFMCALLBACK lpfnCallback)
437 TRACE("0x%08x 0x%08x %p 0x%08x %p\n",
438 hmenu, uID, pidl, uEnumFlags, lpfnCallback);
440 FileMenu_DeleteAllItems (hmenu);
442 FM_SetMenuParameter(hmenu, uID, pidl, 0, uEnumFlags, lpfnCallback);
444 return FM_InitMenuPopup(hmenu, NULL);
447 /*************************************************************************
448 * FileMenu_Invalidate [SHELL32.111]
450 void WINAPI FileMenu_Invalidate (HMENU hMenu)
452 FIXME("0x%08x\n",hMenu);
455 /*************************************************************************
456 * FileMenu_FindSubMenuByPidl [SHELL32.106]
458 HMENU WINAPI FileMenu_FindSubMenuByPidl(
462 FIXME("0x%08x %p\n",hMenu, pidl);
466 /*************************************************************************
467 * FileMenu_AppendFilesForPidl [SHELL32.124]
469 int WINAPI FileMenu_AppendFilesForPidl(
476 menudata = FM_GetMenuInfo(hmenu);
478 menudata->bInitialized = FALSE;
480 FM_InitMenuPopup(hmenu, pidl);
483 FileMenu_AppendItemA (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
485 TRACE("0x%08x %p 0x%08x\n",hmenu, pidl,bAddSeperator);
489 /*************************************************************************
490 * FileMenu_AddFilesForPidl [SHELL32.125]
493 * uEnumFlags any SHCONTF flag
495 int WINAPI FileMenu_AddFilesForPidl (
502 LPFNFMCALLBACK lpfnCallback)
504 TRACE("0x%08x 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
505 hmenu, uReserved, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
507 return FileMenu_InsertUsingPidl ( hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
512 /*************************************************************************
513 * FileMenu_TrackPopupMenuEx [SHELL32.116]
515 BOOL WINAPI FileMenu_TrackPopupMenuEx (
523 TRACE("0x%08x 0x%08x 0x%x 0x%x 0x%08x %p\n",
524 hMenu, uFlags, x, y, hWnd, lptpm);
525 return TrackPopupMenuEx(hMenu, uFlags, x, y, hWnd, lptpm);
528 /*************************************************************************
529 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
531 BOOL WINAPI FileMenu_GetLastSelectedItemPidls(
533 LPCITEMIDLIST *ppidlFolder,
534 LPCITEMIDLIST *ppidlItem)
536 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
540 #define FM_ICON_SIZE 16
544 #define FM_LEFTBORDER 2
545 #define FM_RIGHTBORDER 8
546 /*************************************************************************
547 * FileMenu_MeasureItem [SHELL32.112]
549 LRESULT WINAPI FileMenu_MeasureItem(
551 LPMEASUREITEMSTRUCT lpmis)
553 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
554 HDC hdc = GetDC(hWnd);
558 TRACE("0x%08x %p %s\n", hWnd, lpmis, pMyItem->szItemText);
560 GetTextExtentPoint32A(hdc, pMyItem->szItemText, pMyItem->cchItemText, &size);
562 lpmis->itemWidth = size.cx + FM_LEFTBORDER + FM_ICON_SIZE + FM_SPACE1 + FM_SPACE2 + FM_RIGHTBORDER;
563 lpmis->itemHeight = (size.cy > (FM_ICON_SIZE + FM_Y_SPACE)) ? size.cy : (FM_ICON_SIZE + FM_Y_SPACE);
565 /* add the menubitmap */
566 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
567 if (menuinfo->nBorderWidth)
568 lpmis->itemWidth += menuinfo->nBorderWidth;
570 TRACE("-- 0x%04x 0x%04x\n", lpmis->itemWidth, lpmis->itemHeight);
571 ReleaseDC (hWnd, hdc);
574 /*************************************************************************
575 * FileMenu_DrawItem [SHELL32.105]
577 LRESULT WINAPI FileMenu_DrawItem(
579 LPDRAWITEMSTRUCT lpdis)
581 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
582 COLORREF clrPrevText, clrPrevBkgnd;
584 HIMAGELIST hImageList;
585 RECT TextRect, BorderRect;
588 TRACE("0x%08x %p %s\n", hWnd, lpdis, pMyItem->szItemText);
590 if (lpdis->itemState & ODS_SELECTED)
592 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
593 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
597 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_MENUTEXT));
598 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_MENU));
601 CopyRect(&TextRect, &(lpdis->rcItem));
603 /* add the menubitmap */
604 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
605 if (menuinfo->nBorderWidth)
606 TextRect.left += menuinfo->nBorderWidth;
608 BorderRect.right = menuinfo->nBorderWidth;
609 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
611 TextRect.left += FM_LEFTBORDER;
612 xi = TextRect.left + FM_SPACE1;
613 yi = TextRect.top + FM_Y_SPACE/2;
614 TextRect.bottom -= FM_Y_SPACE/2;
616 xt = xi + FM_ICON_SIZE + FM_SPACE2;
619 ExtTextOutA (lpdis->hDC, xt , yt, ETO_OPAQUE, &TextRect, pMyItem->szItemText, pMyItem->cchItemText, NULL);
621 Shell_GetImageList(0, &hImageList);
622 ImageList_Draw(hImageList, pMyItem->iIconIndex, lpdis->hDC, xi, yi, ILD_NORMAL);
624 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect.left, TextRect.top, TextRect.right, TextRect.bottom);
626 SetTextColor(lpdis->hDC, clrPrevText);
627 SetBkColor(lpdis->hDC, clrPrevBkgnd);
632 /*************************************************************************
633 * FileMenu_InitMenuPopup [SHELL32.109]
636 * The filemenu is a ownerdrawn menu. Call this function responding to
640 BOOL WINAPI FileMenu_InitMenuPopup (HMENU hmenu)
642 FM_InitMenuPopup(hmenu, NULL);
646 /*************************************************************************
647 * FileMenu_HandleMenuChar [SHELL32.108]
649 LRESULT WINAPI FileMenu_HandleMenuChar(
653 FIXME("0x%08x 0x%08x\n",hMenu,wParam);
657 /*************************************************************************
658 * FileMenu_DeleteAllItems [SHELL32.104]
663 BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
670 TRACE("0x%08x\n", hmenu);
672 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
673 mii.cbSize = sizeof(MENUITEMINFOA);
674 mii.fMask = MIIM_SUBMENU|MIIM_DATA;
676 for (i = 0; i < GetMenuItemCount( hmenu ); i++)
677 { GetMenuItemInfoA(hmenu, i, TRUE, &mii );
680 SHFree((LPFMINFO)mii.dwItemData);
683 FileMenu_Destroy(mii.hSubMenu);
686 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
688 menudata = FM_GetMenuInfo(hmenu);
690 menudata->bInitialized = FALSE;
695 /*************************************************************************
696 * FileMenu_DeleteItemByCmd [SHELL32.117]
699 BOOL WINAPI FileMenu_DeleteItemByCmd (HMENU hMenu, UINT uID)
703 TRACE("0x%08x 0x%08x\n", hMenu, uID);
705 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
706 mii.cbSize = sizeof(MENUITEMINFOA);
707 mii.fMask = MIIM_SUBMENU;
709 GetMenuItemInfoA(hMenu, uID, FALSE, &mii );
712 /* FIXME: Do what? */
715 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
719 /*************************************************************************
720 * FileMenu_DeleteItemByIndex [SHELL32.140]
722 BOOL WINAPI FileMenu_DeleteItemByIndex ( HMENU hMenu, UINT uPos)
726 TRACE("0x%08x 0x%08x\n", hMenu, uPos);
728 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
729 mii.cbSize = sizeof(MENUITEMINFOA);
730 mii.fMask = MIIM_SUBMENU;
732 GetMenuItemInfoA(hMenu, uPos, TRUE, &mii );
735 /* FIXME: Do what? */
738 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
742 /*************************************************************************
743 * FileMenu_DeleteItemByFirstID [SHELL32.141]
745 BOOL WINAPI FileMenu_DeleteItemByFirstID(
749 TRACE("0x%08x 0x%08x\n", hMenu, uID);
753 /*************************************************************************
754 * FileMenu_DeleteSeparator [SHELL32.142]
756 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu)
758 TRACE("0x%08x\n", hMenu);
762 /*************************************************************************
763 * FileMenu_EnableItemByCmd [SHELL32.143]
765 BOOL WINAPI FileMenu_EnableItemByCmd(
770 TRACE("0x%08x 0x%08x 0x%08x\n", hMenu, uID,bEnable);
774 /*************************************************************************
775 * FileMenu_GetItemExtent [SHELL32.144]
778 * if the menu is too big, entries are getting cut away!!
780 DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos)
783 FIXME("0x%08x 0x%08x\n", hMenu, uPos);
785 if (GetMenuItemRect(0, hMenu, uPos, &rect))
786 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
787 rect.right, rect.left, rect.top, rect.bottom);
788 return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom);
790 return 0x00100010; /*FIXME*/
793 /*************************************************************************
794 * FileMenu_AbortInitMenu [SHELL32.120]
797 void WINAPI FileMenu_AbortInitMenu (void)
802 /*************************************************************************
803 * SHFind_InitMenuPopup [SHELL32.149]
807 * hMenu [in] handle of menu previously created
808 * hWndParent [in] parent window
809 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
810 * x [in] no pointer (0x226 over here)
813 * LPXXXXX pointer to struct containing a func addr at offset 8
814 * or NULL at failure.
816 LPVOID WINAPI SHFind_InitMenuPopup (HMENU hMenu, HWND hWndParent, DWORD w, DWORD x)
817 { FIXME("hmenu=0x%08x hwnd=0x%08x 0x%08lx 0x%08lx stub\n",
818 hMenu,hWndParent,w,x);
819 return NULL; /* this is supposed to be a pointer */
822 /*************************************************************************
823 * Shell_MergeMenus [SHELL32.67]
826 BOOL _SHIsMenuSeparator(HMENU hm, int i)
830 mii.cbSize = sizeof(MENUITEMINFOA);
831 mii.fMask = MIIM_TYPE;
832 mii.cch = 0; /* WARNING: We MUST initialize it to 0*/
833 if (!GetMenuItemInfoA(hm, i, TRUE, &mii))
838 if (mii.fType & MFT_SEPARATOR)
846 /**********************************************************************/
848 HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
851 BOOL bAlreadySeparated;
852 MENUITEMINFOA miiSrc;
854 UINT uTemp, uIDMax = uIDAdjust;
856 TRACE("hmenu1=0x%04x hmenu2=0x%04x 0x%04x 0x%04x 0x%04x 0x%04lx\n",
857 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
859 if (!hmDst || !hmSrc)
863 nItem = GetMenuItemCount(hmDst);
865 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
867 uInsert = (UINT)nItem; /* append on the end */
868 bAlreadySeparated = TRUE;
872 bAlreadySeparated = _SHIsMenuSeparator(hmDst, uInsert);;
875 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
877 /* Add a separator between the menus */
878 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
879 bAlreadySeparated = TRUE;
883 /* Go through the menu items and clone them*/
884 for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
886 miiSrc.cbSize = sizeof(MENUITEMINFOA);
887 miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
889 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
890 miiSrc.fType = MFT_STRING;
891 miiSrc.dwTypeData = szName;
892 miiSrc.dwItemData = 0;
893 miiSrc.cch = sizeof(szName);
895 if (!GetMenuItemInfoA(hmSrc, nItem, TRUE, &miiSrc))
900 /* 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);
902 if (miiSrc.fType & MFT_SEPARATOR)
904 /* This is a separator; don't put two of them in a row */
905 if (bAlreadySeparated)
908 bAlreadySeparated = TRUE;
910 else if (miiSrc.hSubMenu)
912 if (uFlags & MM_SUBMENUSHAVEIDS)
914 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
916 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
919 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
920 uIDMax = miiSrc.wID + 1;
924 miiSrc.fMask &= ~MIIM_ID; /* Don't set IDs for submenus that didn't have them already */
926 hmSubMenu = miiSrc.hSubMenu;
928 miiSrc.hSubMenu = CreatePopupMenu();
930 if (!miiSrc.hSubMenu) return(uIDMax);
932 uTemp = Shell_MergeMenus(miiSrc.hSubMenu, hmSubMenu, 0, uIDAdjust, uIDAdjustMax, uFlags & MM_SUBMENUSHAVEIDS);
937 bAlreadySeparated = FALSE;
939 else /* normal menu item */
941 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
943 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
946 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
947 uIDMax = miiSrc.wID + 1;
949 bAlreadySeparated = FALSE;
952 /* 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);
954 if (!InsertMenuItemA(hmDst, uInsert, TRUE, &miiSrc))
960 /* Ensure the correct number of separators at the beginning of the
961 inserted menu items*/
964 if (bAlreadySeparated)
966 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
971 if (_SHIsMenuSeparator(hmDst, uInsert-1))
973 if (bAlreadySeparated)
975 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
980 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
982 /* Add a separator between the menus*/
983 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);