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
30 #include "undocshell.h"
33 #include "shell32_main.h"
37 #include "wine/debug.h"
39 static BOOL FileMenu_AppendItemA(HMENU hMenu, LPCSTR lpText, UINT uID, int icon,
40 HMENU hMenuPopup, int nItemHeight);
47 COLORREF crBorderColor;
51 /* insert using pidl */
56 LPFNFMCALLBACK lpfnCallback;
66 static BOOL bAbortInit;
68 #define CCH_MAXITEMTEXT 256
70 WINE_DEFAULT_DEBUG_CHANNEL(shell);
72 LPFMINFO FM_GetMenuInfo(HMENU hmenu)
76 MenuInfo.cbSize = sizeof(MENUINFO);
77 MenuInfo.fMask = MIM_MENUDATA;
79 if (! GetMenuInfo(hmenu, &MenuInfo))
82 menudata = (LPFMINFO)MenuInfo.dwMenuData;
84 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
86 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
93 /*************************************************************************
94 * FM_SetMenuParameter [internal]
97 static LPFMINFO FM_SetMenuParameter(
103 LPFNFMCALLBACK lpfnCallback)
109 menudata = FM_GetMenuInfo(hmenu);
112 { SHFree(menudata->pidl);
116 menudata->pidl = ILClone(pidl);
117 menudata->uFlags = uFlags;
118 menudata->uEnumFlags = uEnumFlags;
119 menudata->lpfnCallback = lpfnCallback;
124 /*************************************************************************
125 * FM_InitMenuPopup [internal]
128 static int FM_InitMenuPopup(HMENU hmenu, LPCITEMIDLIST pAlternatePidl)
129 { IShellFolder *lpsf, *lpsf2;
130 ULONG ulItemAttr = SFGAO_FOLDER;
131 UINT uID, uFlags, uEnumFlags;
132 LPFNFMCALLBACK lpfnCallback;
134 char sTemp[MAX_PATH];
135 int NumberOfItems = 0, iIcon;
139 TRACE("%p %p\n", hmenu, pAlternatePidl);
141 MenuInfo.cbSize = sizeof(MENUINFO);
142 MenuInfo.fMask = MIM_MENUDATA;
144 if (! GetMenuInfo(hmenu, &MenuInfo))
147 menudata = (LPFMINFO)MenuInfo.dwMenuData;
149 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
151 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
155 if (menudata->bInitialized)
158 pidl = (pAlternatePidl? pAlternatePidl: menudata->pidl);
163 uFlags = menudata->uFlags;
164 uEnumFlags = menudata->uEnumFlags;
165 lpfnCallback = menudata->lpfnCallback;
166 menudata->bInitialized = FALSE;
168 SetMenuInfo(hmenu, &MenuInfo);
170 if (SUCCEEDED (SHGetDesktopFolder(&lpsf)))
172 if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
174 IEnumIDList *lpe = NULL;
176 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe )))
179 LPITEMIDLIST pidlTemp = NULL;
182 while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)))
184 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, (LPCITEMIDLIST*)&pidlTemp, &ulItemAttr)))
186 ILGetDisplayNameExA(NULL, pidlTemp, sTemp, ILGDN_FORPARSING);
187 if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon)))
188 iIcon = FM_BLANK_ICON;
189 if ( SFGAO_FOLDER & ulItemAttr)
193 HMENU hMenuPopup = CreatePopupMenu();
195 lpFmMi = (LPFMINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
197 lpFmMi->pidl = ILCombine(pidl, pidlTemp);
198 lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
200 MenuInfo.cbSize = sizeof(MENUINFO);
201 MenuInfo.fMask = MIM_MENUDATA;
202 MenuInfo.dwMenuData = (DWORD) lpFmMi;
203 SetMenuInfo (hMenuPopup, &MenuInfo);
205 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT);
209 ((LPSTR)PathFindExtensionA(sTemp))[0] = 0x00;
210 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
216 TRACE("enter callback\n");
217 lpfnCallback ( pidl, pidlTemp);
218 TRACE("leave callback\n");
223 IEnumIDList_Release (lpe);
225 IShellFolder_Release(lpsf2);
227 IShellFolder_Release(lpsf);
230 if ( GetMenuItemCount (hmenu) == 0 )
231 { FileMenu_AppendItemA (hmenu, "(empty)", uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
235 menudata->bInitialized = TRUE;
236 SetMenuInfo(hmenu, &MenuInfo);
238 return NumberOfItems;
240 /*************************************************************************
241 * FileMenu_Create [SHELL32.114]
244 * for non-root menus values are
245 * (ffffffff,00000000,00000000,00000000,00000000)
247 HMENU WINAPI FileMenu_Create (
248 COLORREF crBorderColor,
257 HMENU hMenu = CreatePopupMenu();
259 TRACE("0x%08lx 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
260 crBorderColor, nBorderWidth, hBorderBmp, nSelHeight, uFlags, hMenu);
262 menudata = (LPFMINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
263 menudata->crBorderColor = crBorderColor;
264 menudata->nBorderWidth = nBorderWidth;
265 menudata->hBorderBmp = hBorderBmp;
267 MenuInfo.cbSize = sizeof(MENUINFO);
268 MenuInfo.fMask = MIM_MENUDATA;
269 MenuInfo.dwMenuData = (DWORD) menudata;
270 SetMenuInfo (hMenu, &MenuInfo);
275 /*************************************************************************
276 * FileMenu_Destroy [SHELL32.118]
281 void WINAPI FileMenu_Destroy (HMENU hmenu)
285 TRACE("%p\n", hmenu);
287 FileMenu_DeleteAllItems (hmenu);
289 menudata = FM_GetMenuInfo(hmenu);
292 { SHFree( menudata->pidl);
294 HeapFree(GetProcessHeap(), 0, menudata);
299 /*************************************************************************
300 * FileMenu_AppendItem [SHELL32.115]
303 static BOOL FileMenu_AppendItemA(
311 LPSTR lpszText = (LPSTR)lpText;
318 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
319 hMenu, (lpszText!=FM_SEPARATOR) ? lpText: NULL,
320 uID, icon, hMenuPopup, nItemHeight);
322 ZeroMemory (&mii, sizeof(MENUITEMINFOA));
324 mii.cbSize = sizeof(MENUITEMINFOA);
326 if (lpText != FM_SEPARATOR)
327 { int len = strlen (lpText);
328 myItem = (LPFMITEM) SHAlloc( sizeof(FMITEM) + len);
329 strcpy (myItem->szItemText, lpText);
330 myItem->cchItemText = len;
331 myItem->iIconIndex = icon;
332 myItem->hMenu = hMenu;
333 mii.fMask = MIIM_DATA;
334 mii.dwItemData = (DWORD) myItem;
339 mii.fMask |= MIIM_TYPE | MIIM_SUBMENU;
340 mii.fType = MFT_OWNERDRAW;
341 mii.hSubMenu = hMenuPopup;
343 else if (lpText == FM_SEPARATOR )
344 { mii.fMask |= MIIM_ID | MIIM_TYPE;
345 mii.fType = MFT_SEPARATOR;
349 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
350 mii.fState = MFS_ENABLED | MFS_DEFAULT;
351 mii.fType = MFT_OWNERDRAW;
355 InsertMenuItemA (hMenu, (UINT)-1, TRUE, &mii);
357 /* set bFixedItems to true */
358 MenuInfo.cbSize = sizeof(MENUINFO);
359 MenuInfo.fMask = MIM_MENUDATA;
361 if (! GetMenuInfo(hMenu, &MenuInfo))
364 menudata = (LPFMINFO)MenuInfo.dwMenuData;
365 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
367 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
371 menudata->bFixedItems = TRUE;
372 SetMenuInfo(hMenu, &MenuInfo);
378 /**********************************************************************/
380 BOOL WINAPI FileMenu_AppendItemAW(
391 if (SHELL_OsIsUnicode() && (lpText!=FM_SEPARATOR))
392 lpszText = HEAP_strdupWtoA ( GetProcessHeap(),0, lpText);
394 ret = FileMenu_AppendItemA(hMenu, (lpszText) ? lpszText : lpText, uID, icon, hMenuPopup, nItemHeight);
397 HeapFree( GetProcessHeap(), 0, lpszText );
401 /*************************************************************************
402 * FileMenu_InsertUsingPidl [SHELL32.110]
405 * uEnumFlags any SHCONTF flag
407 int WINAPI FileMenu_InsertUsingPidl (
413 LPFNFMCALLBACK lpfnCallback)
415 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
416 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
422 FM_SetMenuParameter(hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
424 return FM_InitMenuPopup(hmenu, NULL);
427 /*************************************************************************
428 * FileMenu_ReplaceUsingPidl [SHELL32.113]
430 * FIXME: the static items are deleted but won't be refreshed
432 int WINAPI FileMenu_ReplaceUsingPidl(
437 LPFNFMCALLBACK lpfnCallback)
439 TRACE("%p 0x%08x %p 0x%08x %p\n",
440 hmenu, uID, pidl, uEnumFlags, lpfnCallback);
442 FileMenu_DeleteAllItems (hmenu);
444 FM_SetMenuParameter(hmenu, uID, pidl, 0, uEnumFlags, lpfnCallback);
446 return FM_InitMenuPopup(hmenu, NULL);
449 /*************************************************************************
450 * FileMenu_Invalidate [SHELL32.111]
452 void WINAPI FileMenu_Invalidate (HMENU hMenu)
457 /*************************************************************************
458 * FileMenu_FindSubMenuByPidl [SHELL32.106]
460 HMENU WINAPI FileMenu_FindSubMenuByPidl(
464 FIXME("%p %p\n",hMenu, pidl);
468 /*************************************************************************
469 * FileMenu_AppendFilesForPidl [SHELL32.124]
471 int WINAPI FileMenu_AppendFilesForPidl(
478 menudata = FM_GetMenuInfo(hmenu);
480 menudata->bInitialized = FALSE;
482 FM_InitMenuPopup(hmenu, pidl);
485 FileMenu_AppendItemA (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
487 TRACE("%p %p 0x%08x\n",hmenu, pidl,bAddSeperator);
491 /*************************************************************************
492 * FileMenu_AddFilesForPidl [SHELL32.125]
495 * uEnumFlags any SHCONTF flag
497 int WINAPI FileMenu_AddFilesForPidl (
504 LPFNFMCALLBACK lpfnCallback)
506 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
507 hmenu, uReserved, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
509 return FileMenu_InsertUsingPidl ( hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
514 /*************************************************************************
515 * FileMenu_TrackPopupMenuEx [SHELL32.116]
517 BOOL WINAPI FileMenu_TrackPopupMenuEx (
525 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
526 hMenu, uFlags, x, y, hWnd, lptpm);
527 return TrackPopupMenuEx(hMenu, uFlags, x, y, hWnd, lptpm);
530 /*************************************************************************
531 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
533 BOOL WINAPI FileMenu_GetLastSelectedItemPidls(
535 LPCITEMIDLIST *ppidlFolder,
536 LPCITEMIDLIST *ppidlItem)
538 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
542 #define FM_ICON_SIZE 16
546 #define FM_LEFTBORDER 2
547 #define FM_RIGHTBORDER 8
548 /*************************************************************************
549 * FileMenu_MeasureItem [SHELL32.112]
551 LRESULT WINAPI FileMenu_MeasureItem(
553 LPMEASUREITEMSTRUCT lpmis)
555 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
556 HDC hdc = GetDC(hWnd);
560 TRACE("%p %p %s\n", hWnd, lpmis, pMyItem->szItemText);
562 GetTextExtentPoint32A(hdc, pMyItem->szItemText, pMyItem->cchItemText, &size);
564 lpmis->itemWidth = size.cx + FM_LEFTBORDER + FM_ICON_SIZE + FM_SPACE1 + FM_SPACE2 + FM_RIGHTBORDER;
565 lpmis->itemHeight = (size.cy > (FM_ICON_SIZE + FM_Y_SPACE)) ? size.cy : (FM_ICON_SIZE + FM_Y_SPACE);
567 /* add the menubitmap */
568 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
569 if (menuinfo->nBorderWidth)
570 lpmis->itemWidth += menuinfo->nBorderWidth;
572 TRACE("-- 0x%04x 0x%04x\n", lpmis->itemWidth, lpmis->itemHeight);
573 ReleaseDC (hWnd, hdc);
576 /*************************************************************************
577 * FileMenu_DrawItem [SHELL32.105]
579 LRESULT WINAPI FileMenu_DrawItem(
581 LPDRAWITEMSTRUCT lpdis)
583 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
584 COLORREF clrPrevText, clrPrevBkgnd;
586 HIMAGELIST hImageList;
587 RECT TextRect, BorderRect;
590 TRACE("%p %p %s\n", hWnd, lpdis, pMyItem->szItemText);
592 if (lpdis->itemState & ODS_SELECTED)
594 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
595 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
599 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_MENUTEXT));
600 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_MENU));
603 CopyRect(&TextRect, &(lpdis->rcItem));
605 /* add the menubitmap */
606 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
607 if (menuinfo->nBorderWidth)
608 TextRect.left += menuinfo->nBorderWidth;
610 BorderRect.right = menuinfo->nBorderWidth;
611 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
613 TextRect.left += FM_LEFTBORDER;
614 xi = TextRect.left + FM_SPACE1;
615 yi = TextRect.top + FM_Y_SPACE/2;
616 TextRect.bottom -= FM_Y_SPACE/2;
618 xt = xi + FM_ICON_SIZE + FM_SPACE2;
621 ExtTextOutA (lpdis->hDC, xt , yt, ETO_OPAQUE, &TextRect, pMyItem->szItemText, pMyItem->cchItemText, NULL);
623 Shell_GetImageList(0, &hImageList);
624 ImageList_Draw(hImageList, pMyItem->iIconIndex, lpdis->hDC, xi, yi, ILD_NORMAL);
626 TRACE("-- 0x%04lx 0x%04lx 0x%04lx 0x%04lx\n", TextRect.left, TextRect.top, TextRect.right, TextRect.bottom);
628 SetTextColor(lpdis->hDC, clrPrevText);
629 SetBkColor(lpdis->hDC, clrPrevBkgnd);
634 /*************************************************************************
635 * FileMenu_InitMenuPopup [SHELL32.109]
638 * The filemenu is a ownerdrawn menu. Call this function responding to
642 BOOL WINAPI FileMenu_InitMenuPopup (HMENU hmenu)
644 FM_InitMenuPopup(hmenu, NULL);
648 /*************************************************************************
649 * FileMenu_HandleMenuChar [SHELL32.108]
651 LRESULT WINAPI FileMenu_HandleMenuChar(
655 FIXME("%p 0x%08x\n",hMenu,wParam);
659 /*************************************************************************
660 * FileMenu_DeleteAllItems [SHELL32.104]
665 BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
672 TRACE("%p\n", hmenu);
674 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
675 mii.cbSize = sizeof(MENUITEMINFOA);
676 mii.fMask = MIIM_SUBMENU|MIIM_DATA;
678 for (i = 0; i < GetMenuItemCount( hmenu ); i++)
679 { GetMenuItemInfoA(hmenu, i, TRUE, &mii );
682 SHFree((LPFMINFO)mii.dwItemData);
685 FileMenu_Destroy(mii.hSubMenu);
688 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
690 menudata = FM_GetMenuInfo(hmenu);
692 menudata->bInitialized = FALSE;
697 /*************************************************************************
698 * FileMenu_DeleteItemByCmd [SHELL32.117]
701 BOOL WINAPI FileMenu_DeleteItemByCmd (HMENU hMenu, UINT uID)
705 TRACE("%p 0x%08x\n", hMenu, uID);
707 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
708 mii.cbSize = sizeof(MENUITEMINFOA);
709 mii.fMask = MIIM_SUBMENU;
711 GetMenuItemInfoA(hMenu, uID, FALSE, &mii );
714 /* FIXME: Do what? */
717 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
721 /*************************************************************************
722 * FileMenu_DeleteItemByIndex [SHELL32.140]
724 BOOL WINAPI FileMenu_DeleteItemByIndex ( HMENU hMenu, UINT uPos)
728 TRACE("%p 0x%08x\n", hMenu, uPos);
730 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
731 mii.cbSize = sizeof(MENUITEMINFOA);
732 mii.fMask = MIIM_SUBMENU;
734 GetMenuItemInfoA(hMenu, uPos, TRUE, &mii );
737 /* FIXME: Do what? */
740 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
744 /*************************************************************************
745 * FileMenu_DeleteItemByFirstID [SHELL32.141]
747 BOOL WINAPI FileMenu_DeleteItemByFirstID(
751 TRACE("%p 0x%08x\n", hMenu, uID);
755 /*************************************************************************
756 * FileMenu_DeleteSeparator [SHELL32.142]
758 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu)
760 TRACE("%p\n", hMenu);
764 /*************************************************************************
765 * FileMenu_EnableItemByCmd [SHELL32.143]
767 BOOL WINAPI FileMenu_EnableItemByCmd(
772 TRACE("%p 0x%08x 0x%08x\n", hMenu, uID,bEnable);
776 /*************************************************************************
777 * FileMenu_GetItemExtent [SHELL32.144]
780 * if the menu is too big, entries are getting cut away!!
782 DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos)
785 FIXME("%p 0x%08x\n", hMenu, uPos);
787 if (GetMenuItemRect(0, hMenu, uPos, &rect))
788 { FIXME("0x%04lx 0x%04lx 0x%04lx 0x%04lx\n",
789 rect.right, rect.left, rect.top, rect.bottom);
790 return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom);
792 return 0x00100010; /*FIXME*/
795 /*************************************************************************
796 * FileMenu_AbortInitMenu [SHELL32.120]
799 void WINAPI FileMenu_AbortInitMenu (void)
804 /*************************************************************************
805 * SHFind_InitMenuPopup [SHELL32.149]
809 * hMenu [in] handle of menu previously created
810 * hWndParent [in] parent window
811 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
812 * x [in] no pointer (0x226 over here)
815 * LPXXXXX pointer to struct containing a func addr at offset 8
816 * or NULL at failure.
818 LPVOID WINAPI SHFind_InitMenuPopup (HMENU hMenu, HWND hWndParent, DWORD w, DWORD x)
819 { FIXME("hmenu=%p hwnd=%p 0x%08lx 0x%08lx stub\n",
820 hMenu,hWndParent,w,x);
821 return NULL; /* this is supposed to be a pointer */
824 /*************************************************************************
825 * Shell_MergeMenus [SHELL32.67]
828 BOOL _SHIsMenuSeparator(HMENU hm, int i)
832 mii.cbSize = sizeof(MENUITEMINFOA);
833 mii.fMask = MIIM_TYPE;
834 mii.cch = 0; /* WARNING: We MUST initialize it to 0*/
835 if (!GetMenuItemInfoA(hm, i, TRUE, &mii))
840 if (mii.fType & MFT_SEPARATOR)
848 /**********************************************************************/
850 HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
853 BOOL bAlreadySeparated;
854 MENUITEMINFOA miiSrc;
856 UINT uTemp, uIDMax = uIDAdjust;
858 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04lx\n",
859 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
861 if (!hmDst || !hmSrc)
865 nItem = GetMenuItemCount(hmDst);
867 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
869 uInsert = (UINT)nItem; /* append on the end */
870 bAlreadySeparated = TRUE;
874 bAlreadySeparated = _SHIsMenuSeparator(hmDst, uInsert);
877 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
879 /* Add a separator between the menus */
880 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
881 bAlreadySeparated = TRUE;
885 /* Go through the menu items and clone them*/
886 for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
888 miiSrc.cbSize = sizeof(MENUITEMINFOA);
889 miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
891 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
892 miiSrc.fType = MFT_STRING;
893 miiSrc.dwTypeData = szName;
894 miiSrc.dwItemData = 0;
895 miiSrc.cch = sizeof(szName);
897 if (!GetMenuItemInfoA(hmSrc, nItem, TRUE, &miiSrc))
902 /* 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);
904 if (miiSrc.fType & MFT_SEPARATOR)
906 /* This is a separator; don't put two of them in a row */
907 if (bAlreadySeparated)
910 bAlreadySeparated = TRUE;
912 else if (miiSrc.hSubMenu)
914 if (uFlags & MM_SUBMENUSHAVEIDS)
916 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
918 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
921 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
922 uIDMax = miiSrc.wID + 1;
926 miiSrc.fMask &= ~MIIM_ID; /* Don't set IDs for submenus that didn't have them already */
928 hmSubMenu = miiSrc.hSubMenu;
930 miiSrc.hSubMenu = CreatePopupMenu();
932 if (!miiSrc.hSubMenu) return(uIDMax);
934 uTemp = Shell_MergeMenus(miiSrc.hSubMenu, hmSubMenu, 0, uIDAdjust, uIDAdjustMax, uFlags & MM_SUBMENUSHAVEIDS);
939 bAlreadySeparated = FALSE;
941 else /* normal menu item */
943 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
945 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
948 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
949 uIDMax = miiSrc.wID + 1;
951 bAlreadySeparated = FALSE;
954 /* 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);
956 if (!InsertMenuItemA(hmDst, uInsert, TRUE, &miiSrc))
962 /* Ensure the correct number of separators at the beginning of the
963 inserted menu items*/
966 if (bAlreadySeparated)
968 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
973 if (_SHIsMenuSeparator(hmDst, uInsert-1))
975 if (bAlreadySeparated)
977 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
982 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
984 /* Add a separator between the menus*/
985 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);