2 * see www.geocities.com/SiliconValley/4942/filemenu.html
7 #include "wine/obj_base.h"
8 #include "wine/obj_enumidlist.h"
9 #include "wine/obj_shellfolder.h"
12 #include "debugtools.h"
13 #include "winversion.h"
14 #include "shell32_main.h"
18 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hMenu
);
19 BOOL WINAPI
FileMenu_AppendItemA(HMENU hMenu
, LPCSTR lpText
, UINT uID
, int icon
, HMENU hMenuPopup
, int nItemHeight
);
26 COLORREF crBorderColor
;
30 /* insert using pidl */
35 LPFNFMCALLBACK lpfnCallback
;
45 static BOOL bAbortInit
;
47 #define CCH_MAXITEMTEXT 256
49 DEFAULT_DEBUG_CHANNEL(shell
)
51 LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
55 MenuInfo
.cbSize
= sizeof(MENUINFO
);
56 MenuInfo
.fMask
= MIM_MENUDATA
;
58 if (! GetMenuInfo(hmenu
, &MenuInfo
))
61 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
63 assert ((menudata
!= 0) && (MenuInfo
.cbSize
== sizeof(MENUINFO
)));
68 /*************************************************************************
69 * FM_SetMenuParameter [internal]
72 static LPFMINFO
FM_SetMenuParameter(
78 LPFNFMCALLBACK lpfnCallback
)
84 menudata
= FM_GetMenuInfo(hmenu
);
87 { SHFree(menudata
->pidl
);
91 menudata
->pidl
= ILClone(pidl
);
92 menudata
->uFlags
= uFlags
;
93 menudata
->uEnumFlags
= uEnumFlags
;
94 menudata
->lpfnCallback
= lpfnCallback
;
99 /*************************************************************************
100 * FM_InitMenuPopup [internal]
103 static int FM_InitMenuPopup(HMENU hmenu
, LPITEMIDLIST pAlternatePidl
)
104 { IShellFolder
*lpsf
, *lpsf2
;
106 UINT uID
, uFlags
, uEnumFlags
;
107 LPFNFMCALLBACK lpfnCallback
;
109 char sTemp
[MAX_PATH
];
110 int NumberOfItems
= 0, iIcon
;
116 MenuInfo
.cbSize
= sizeof(MENUINFO
);
117 MenuInfo
.fMask
= MIM_MENUDATA
;
119 if (! GetMenuInfo(hmenu
, &MenuInfo
))
122 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
124 assert ((menudata
!= 0) && (MenuInfo
.cbSize
== sizeof(MENUINFO
)));
126 if (menudata
->bInitialized
)
130 pidl
= ((pAlternatePidl
) ? pAlternatePidl
: menudata
->pidl
);
131 uFlags
= menudata
->uFlags
;
132 uEnumFlags
= menudata
->uEnumFlags
;
133 lpfnCallback
= menudata
->lpfnCallback
;
135 menudata
->bInitialized
= FALSE
;
136 SetMenuInfo(hmenu
, &MenuInfo
);
138 if (SUCCEEDED (SHGetDesktopFolder(&lpsf
)))
140 if (SUCCEEDED(IShellFolder_BindToObject(lpsf
, pidl
,0,(REFIID
)&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
142 IEnumIDList
*lpe
= NULL
;
144 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2
, 0, uEnumFlags
, &lpe
)))
147 LPITEMIDLIST pidlTemp
= NULL
;
150 while ((!bAbortInit
) && (NOERROR
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
)))
152 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf
, 1, &pidlTemp
, &ulItemAttr
)))
154 ILGetDisplayName( pidlTemp
, sTemp
);
155 if (! (PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, &iIcon
)))
156 iIcon
= FM_BLANK_ICON
;
157 if ( SFGAO_FOLDER
& ulItemAttr
)
161 HMENU hMenuPopup
= CreatePopupMenu();
163 lpFmMi
= (LPFMINFO
) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
165 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
166 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
168 MenuInfo
.cbSize
= sizeof(MENUINFO
);
169 MenuInfo
.fMask
= MIM_MENUDATA
;
170 MenuInfo
.dwMenuData
= (DWORD
) lpFmMi
;
171 SetMenuInfo (hMenuPopup
, &MenuInfo
);
173 FileMenu_AppendItemA (hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
177 ((LPSTR
)PathFindExtensionA(sTemp
))[0] = 0x00;
178 FileMenu_AppendItemA (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
184 TRACE("enter callback\n");
185 lpfnCallback ( pidl
, pidlTemp
);
186 TRACE("leave callback\n");
191 IEnumIDList_Release (lpe
);
193 IShellFolder_Release(lpsf2
);
195 IShellFolder_Release(lpsf
);
198 if ( GetMenuItemCount (hmenu
) == 0 )
199 { FileMenu_AppendItemA (hmenu
, "(empty)", uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
203 menudata
->bInitialized
= TRUE
;
204 SetMenuInfo(hmenu
, &MenuInfo
);
206 return NumberOfItems
;
208 /*************************************************************************
209 * FileMenu_Create [SHELL32.114]
212 HMENU WINAPI
FileMenu_Create (
213 COLORREF crBorderColor
,
222 HMENU hMenu
= CreatePopupMenu();
224 TRACE("0x%08lx 0x%08x 0x%08x 0x%08x 0x%08x hMenu=0x%08x\n",
225 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
227 menudata
= (LPFMINFO
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
228 menudata
->bIsMagic
= TRUE
;
229 menudata
->crBorderColor
= crBorderColor
;
230 menudata
->nBorderWidth
= nBorderWidth
;
231 menudata
->hBorderBmp
= hBorderBmp
;
233 MenuInfo
.cbSize
= sizeof(MENUINFO
);
234 MenuInfo
.fMask
= MIM_MENUDATA
;
235 MenuInfo
.dwMenuData
= (DWORD
) menudata
;
236 SetMenuInfo (hMenu
, &MenuInfo
);
241 /*************************************************************************
242 * FileMenu_Destroy [SHELL32.118]
247 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
251 TRACE("0x%08x\n", hmenu
);
253 FileMenu_DeleteAllItems (hmenu
);
255 menudata
= FM_GetMenuInfo(hmenu
);
258 { SHFree( menudata
->pidl
);
260 HeapFree(GetProcessHeap(), 0, menudata
);
265 /*************************************************************************
266 * FileMenu_AppendItemAW [SHELL32.115]
269 BOOL WINAPI
FileMenu_AppendItemA(
277 LPSTR lpszText
= (LPSTR
)lpText
;
281 TRACE("0x%08x %s 0x%08x 0x%08x 0x%08x 0x%08x\n",
282 hMenu
, (lpszText
!=FM_SEPARATOR
) ? lpText
: NULL
,
283 uID
, icon
, hMenuPopup
, nItemHeight
);
285 ZeroMemory (&mii
, sizeof(MENUITEMINFOA
));
287 mii
.cbSize
= sizeof(MENUITEMINFOA
);
289 if (lpText
!= FM_SEPARATOR
)
290 { int len
= strlen (lpText
);
291 myItem
= (LPFMITEM
) SHAlloc( sizeof(FMITEM
) + len
);
292 strcpy (myItem
->szItemText
, lpText
);
293 myItem
->cchItemText
= len
;
294 myItem
->iIconIndex
= icon
;
295 myItem
->hMenu
= hMenu
;
296 mii
.fMask
= MIIM_DATA
;
297 mii
.dwItemData
= (DWORD
) myItem
;
302 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
303 mii
.fType
= MFT_OWNERDRAW
;
304 mii
.hSubMenu
= hMenuPopup
;
306 else if (lpText
== FM_SEPARATOR
)
307 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
308 mii
.fType
= MFT_SEPARATOR
;
312 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
313 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
314 mii
.fType
= MFT_OWNERDRAW
;
318 InsertMenuItemA (hMenu
, (UINT
)-1, TRUE
, &mii
);
323 BOOL WINAPI
FileMenu_AppendItemAW(
334 if (VERSION_OsIsUnicode() && (lpText
!=FM_SEPARATOR
))
335 lpszText
= HEAP_strdupWtoA ( GetProcessHeap(),0, lpText
);
337 ret
= FileMenu_AppendItemA(hMenu
, (lpszText
) ? lpszText
: lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
340 HeapFree( GetProcessHeap(), 0, lpszText
);
344 /*************************************************************************
345 * FileMenu_InsertUsingPidl [SHELL32.110]
348 * uEnumFlags any SHCONTF flag
350 int WINAPI
FileMenu_InsertUsingPidl (
356 LPFNFMCALLBACK lpfnCallback
)
358 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
359 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
365 FM_SetMenuParameter(hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
367 return FM_InitMenuPopup(hmenu
, NULL
);
370 /*************************************************************************
371 * FileMenu_ReplaceUsingPidl [SHELL32.113]
374 int WINAPI
FileMenu_ReplaceUsingPidl(
379 LPFNFMCALLBACK lpfnCallback
)
381 TRACE("0x%08x 0x%08x %p 0x%08x %p\n",
382 hmenu
, uID
, pidl
, uEnumFlags
, lpfnCallback
);
384 FileMenu_DeleteAllItems (hmenu
);
386 FM_SetMenuParameter(hmenu
, uID
, pidl
, 0, uEnumFlags
, lpfnCallback
);
388 return FM_InitMenuPopup(hmenu
, NULL
);
391 /*************************************************************************
392 * FileMenu_Invalidate [SHELL32.111]
394 void WINAPI
FileMenu_Invalidate (HMENU hMenu
)
396 FIXME("0x%08x\n",hMenu
);
399 /*************************************************************************
400 * FileMenu_FindSubMenuByPidl [SHELL32.106]
402 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
406 FIXME("0x%08x %p\n",hMenu
, pidl
);
410 /*************************************************************************
411 * FileMenu_AppendFilesForPidl [SHELL32.124]
413 HMENU WINAPI
FileMenu_AppendFilesForPidl(
420 menudata
= FM_GetMenuInfo(hmenu
);
422 menudata
->bInitialized
= FALSE
;
424 FM_InitMenuPopup(hmenu
, pidl
);
427 FileMenu_AppendItemA (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
429 TRACE("0x%08x %p 0x%08x\n",hmenu
, pidl
,bAddSeperator
);
433 /*************************************************************************
434 * FileMenu_AddFilesForPidl [SHELL32.125]
437 * uEnumFlags any SHCONTF flag
439 int WINAPI
FileMenu_AddFilesForPidl (
446 LPFNFMCALLBACK lpfnCallback
)
448 TRACE("0x%08x 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
449 hmenu
, uReserved
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
451 return FileMenu_InsertUsingPidl ( hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
456 /*************************************************************************
457 * FileMenu_TrackPopupMenuEx [SHELL32.116]
459 HRESULT WINAPI
FileMenu_TrackPopupMenuEx (
467 TRACE("0x%08x 0x%08x 0x%x 0x%x 0x%08x %p\n",
468 hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
469 return TrackPopupMenuEx(hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
472 /*************************************************************************
473 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
475 BOOL WINAPI
FileMenu_GetLastSelectedItemPidls(
477 LPCITEMIDLIST
*ppidlFolder
,
478 LPCITEMIDLIST
*ppidlItem
)
480 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
484 #define FM_ICON_SIZE 16
488 #define FM_LEFTBORDER 2
489 #define FM_RIGHTBORDER 8
490 /*************************************************************************
491 * FileMenu_MeasureItem [SHELL32.112]
493 LRESULT WINAPI
FileMenu_MeasureItem(
495 LPMEASUREITEMSTRUCT lpmis
)
497 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
498 HDC hdc
= GetDC(hWnd
);
502 TRACE("0x%08x %p %s\n", hWnd
, lpmis
, pMyItem
->szItemText
);
504 GetTextExtentPoint32A(hdc
, pMyItem
->szItemText
, pMyItem
->cchItemText
, &size
);
506 lpmis
->itemWidth
= size
.cx
+ FM_LEFTBORDER
+ FM_ICON_SIZE
+ FM_SPACE1
+ FM_SPACE2
+ FM_RIGHTBORDER
;
507 lpmis
->itemHeight
= (size
.cy
> (FM_ICON_SIZE
+ FM_Y_SPACE
)) ? size
.cy
: (FM_ICON_SIZE
+ FM_Y_SPACE
);
509 /* add the menubitmap */
510 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
511 if (menuinfo
->bIsMagic
)
512 lpmis
->itemWidth
+= menuinfo
->nBorderWidth
;
514 TRACE("-- 0x%04x 0x%04x\n", lpmis
->itemWidth
, lpmis
->itemHeight
);
515 ReleaseDC (hWnd
, hdc
);
518 /*************************************************************************
519 * FileMenu_DrawItem [SHELL32.105]
521 LRESULT WINAPI
FileMenu_DrawItem(
523 LPDRAWITEMSTRUCT lpdis
)
525 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
526 COLORREF clrPrevText
, clrPrevBkgnd
;
528 HIMAGELIST hImageList
;
529 RECT TextRect
, BorderRect
;
532 TRACE("0x%08x %p %s\n", hWnd
, lpdis
, pMyItem
->szItemText
);
534 if (lpdis
->itemState
& ODS_SELECTED
)
536 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHTTEXT
));
537 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHT
));
541 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_MENUTEXT
));
542 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_MENU
));
545 CopyRect(&TextRect
, &(lpdis
->rcItem
));
547 /* add the menubitmap */
548 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
549 if (menuinfo
->bIsMagic
)
550 TextRect
.left
+= menuinfo
->nBorderWidth
;
552 BorderRect
.right
= menuinfo
->nBorderWidth
;
553 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
555 TextRect
.left
+= FM_LEFTBORDER
;
556 xi
= TextRect
.left
+ FM_SPACE1
;
557 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
558 TextRect
.bottom
-= FM_Y_SPACE
/2;
560 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
563 ExtTextOutA (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
565 Shell_GetImageList(0, &hImageList
);
566 pImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
568 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
570 SetTextColor(lpdis
->hDC
, clrPrevText
);
571 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
576 /*************************************************************************
577 * FileMenu_InitMenuPopup [SHELL32.109]
580 * The filemenu is a ownerdrawn menu. Call this function responding to
584 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
586 FM_InitMenuPopup(hmenu
, NULL
);
590 /*************************************************************************
591 * FileMenu_HandleMenuChar [SHELL32.108]
593 LRESULT WINAPI
FileMenu_HandleMenuChar(
597 FIXME("0x%08x 0x%08x\n",hMenu
,wParam
);
601 /*************************************************************************
602 * FileMenu_DeleteAllItems [SHELL32.104]
607 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
614 TRACE("0x%08x\n", hmenu
);
616 ZeroMemory ( &mii
, sizeof(MENUITEMINFOA
));
617 mii
.cbSize
= sizeof(MENUITEMINFOA
);
618 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
620 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
621 { GetMenuItemInfoA(hmenu
, i
, TRUE
, &mii
);
624 SHFree((LPFMINFO
)mii
.dwItemData
);
627 FileMenu_Destroy(mii
.hSubMenu
);
630 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
632 menudata
= FM_GetMenuInfo(hmenu
);
634 menudata
->bInitialized
= FALSE
;
639 /*************************************************************************
640 * FileMenu_DeleteItemByCmd [SHELL32.]
643 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
647 TRACE("0x%08x 0x%08x\n", hMenu
, uID
);
649 ZeroMemory ( &mii
, sizeof(MENUITEMINFOA
));
650 mii
.cbSize
= sizeof(MENUITEMINFOA
);
651 mii
.fMask
= MIIM_SUBMENU
;
653 GetMenuItemInfoA(hMenu
, uID
, FALSE
, &mii
);
656 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
660 /*************************************************************************
661 * FileMenu_DeleteItemByIndex [SHELL32.140]
663 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
667 TRACE("0x%08x 0x%08x\n", hMenu
, uPos
);
669 ZeroMemory ( &mii
, sizeof(MENUITEMINFOA
));
670 mii
.cbSize
= sizeof(MENUITEMINFOA
);
671 mii
.fMask
= MIIM_SUBMENU
;
673 GetMenuItemInfoA(hMenu
, uPos
, TRUE
, &mii
);
676 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
680 /*************************************************************************
681 * FileMenu_DeleteItemByFirstID [SHELL32.141]
683 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
687 TRACE("0x%08x 0x%08x\n", hMenu
, uID
);
691 /*************************************************************************
692 * FileMenu_DeleteSeparator [SHELL32.142]
694 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
696 TRACE("0x%08x\n", hMenu
);
700 /*************************************************************************
701 * FileMenu_EnableItemByCmd [SHELL32.143]
703 BOOL WINAPI
FileMenu_EnableItemByCmd(
708 TRACE("0x%08x 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
712 /*************************************************************************
713 * FileMenu_GetItemExtent [SHELL32.144]
716 * if the menu is to big, entrys are getting cut away!!
718 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
721 FIXME("0x%08x 0x%08x\n", hMenu
, uPos
);
723 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
724 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
725 rect
.right
, rect
.left
, rect
.top
, rect
.bottom
);
726 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
728 return 0x00100010; /*fixme*/
731 /*************************************************************************
732 * FileMenu_AbortInitMenu [SHELL32.120]
735 void WINAPI
FileMenu_AbortInitMenu (void)
740 /*************************************************************************
741 * SHFind_InitMenuPopup [SHELL32.149]
745 * hMenu [in] handel of menu previously created
746 * hWndParent [in] parent window
750 HRESULT WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, DWORD w
, DWORD x
)
751 { FIXME("hmenu=0x%08x hwnd=0x%08x 0x%08lx 0x%08lx stub\n",
752 hMenu
,hWndParent
,w
,x
);
756 /*************************************************************************
757 * Shell_MergeMenus [SHELL32.67]
760 BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
764 mii
.cbSize
= sizeof(MENUITEMINFOA
);
765 mii
.fMask
= MIIM_TYPE
;
766 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
767 if (!GetMenuItemInfoA(hm
, i
, TRUE
, &mii
))
771 if (mii
.fType
& MFT_SEPARATOR
)
777 #define MM_ADDSEPARATOR 0x00000001L
778 #define MM_SUBMENUSHAVEIDS 0x00000002L
779 HRESULT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
782 BOOL bAlreadySeparated
;
783 MENUITEMINFOA miiSrc
;
785 UINT uTemp
, uIDMax
= uIDAdjust
;
787 FIXME("hmenu1=0x%04x hmenu2=0x%04x 0x%04x 0x%04x 0x%04x 0x%04lx stub\n",
788 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
790 if (!hmDst
|| !hmSrc
)
794 nItem
= GetMenuItemCount(hmDst
);
795 if (uInsert
>= (UINT
)nItem
)
796 { uInsert
= (UINT
)nItem
;
797 bAlreadySeparated
= TRUE
;
800 { bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);;
802 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
803 { /* Add a separator between the menus */
804 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
805 bAlreadySeparated
= TRUE
;
809 /* Go through the menu items and clone them*/
810 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
811 { miiSrc
.cbSize
= sizeof(MENUITEMINFOA
);
812 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
813 /* We need to reset this every time through the loop in case
814 menus DON'T have IDs*/
815 miiSrc
.fType
= MFT_STRING
;
816 miiSrc
.dwTypeData
= szName
;
817 miiSrc
.dwItemData
= 0;
818 miiSrc
.cch
= sizeof(szName
);
820 if (!GetMenuItemInfoA(hmSrc
, nItem
, TRUE
, &miiSrc
))
823 if (miiSrc
.fType
& MFT_SEPARATOR
)
824 { /* This is a separator; don't put two of them in a row*/
825 if (bAlreadySeparated
)
828 bAlreadySeparated
= TRUE
;
830 else if (miiSrc
.hSubMenu
)
831 { if (uFlags
& MM_SUBMENUSHAVEIDS
)
832 { /* Adjust the ID and check it*/
833 miiSrc
.wID
+= uIDAdjust
;
834 if (miiSrc
.wID
> uIDAdjustMax
)
837 if (uIDMax
<= miiSrc
.wID
)
838 { uIDMax
= miiSrc
.wID
+ 1;
842 { /* Don't set IDs for submenus that didn't have them already */
843 miiSrc
.fMask
&= ~MIIM_ID
;
845 hmSubMenu
= miiSrc
.hSubMenu
;
846 miiSrc
.hSubMenu
= CreatePopupMenu();
847 if (!miiSrc
.hSubMenu
)
850 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
&MM_SUBMENUSHAVEIDS
);
854 bAlreadySeparated
= FALSE
;
857 { /* Adjust the ID and check it*/
858 miiSrc
.wID
+= uIDAdjust
;
859 if (miiSrc
.wID
> uIDAdjustMax
)
862 if (uIDMax
<= miiSrc
.wID
)
863 { uIDMax
= miiSrc
.wID
+ 1;
865 bAlreadySeparated
= FALSE
;
867 if (!InsertMenuItemA(hmDst
, uInsert
, TRUE
, &miiSrc
))
872 /* Ensure the correct number of separators at the beginning of the
873 inserted menu items*/
875 { if (bAlreadySeparated
)
876 { DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
880 { if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
881 { if (bAlreadySeparated
)
882 { DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
886 { if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
887 { /* Add a separator between the menus*/
888 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);