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 "undocshell.h"
28 #include "shell32_main.h"
32 #include "wine/debug.h"
34 static BOOL
FileMenu_AppendItemA(HMENU hMenu
, LPCSTR lpText
, UINT uID
, int icon
,
35 HMENU hMenuPopup
, int nItemHeight
);
42 COLORREF crBorderColor
;
46 /* insert using pidl */
51 LPFNFMCALLBACK lpfnCallback
;
61 static BOOL bAbortInit
;
63 #define CCH_MAXITEMTEXT 256
65 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
67 LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
71 MenuInfo
.cbSize
= sizeof(MENUINFO
);
72 MenuInfo
.fMask
= MIM_MENUDATA
;
74 if (! GetMenuInfo(hmenu
, &MenuInfo
))
77 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
79 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
81 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
88 /*************************************************************************
89 * FM_SetMenuParameter [internal]
92 static LPFMINFO
FM_SetMenuParameter(
98 LPFNFMCALLBACK lpfnCallback
)
104 menudata
= FM_GetMenuInfo(hmenu
);
107 { SHFree(menudata
->pidl
);
111 menudata
->pidl
= ILClone(pidl
);
112 menudata
->uFlags
= uFlags
;
113 menudata
->uEnumFlags
= uEnumFlags
;
114 menudata
->lpfnCallback
= lpfnCallback
;
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
;
129 char sTemp
[MAX_PATH
];
130 int NumberOfItems
= 0, iIcon
;
134 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
136 MenuInfo
.cbSize
= sizeof(MENUINFO
);
137 MenuInfo
.fMask
= MIM_MENUDATA
;
139 if (! GetMenuInfo(hmenu
, &MenuInfo
))
142 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
144 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
146 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
150 if (menudata
->bInitialized
)
153 pidl
= ((pAlternatePidl
) ? pAlternatePidl
: menudata
->pidl
);
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
;
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
)
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
);
204 ((LPSTR
)PathFindExtensionA(sTemp
))[0] = 0x00;
205 FileMenu_AppendItemA (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
211 TRACE("enter callback\n");
212 lpfnCallback ( pidl
, pidlTemp
);
213 TRACE("leave callback\n");
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
);
230 menudata
->bInitialized
= TRUE
;
231 SetMenuInfo(hmenu
, &MenuInfo
);
233 return NumberOfItems
;
235 /*************************************************************************
236 * FileMenu_Create [SHELL32.114]
239 * for non-root menus values are
240 * (ffffffff,00000000,00000000,00000000,00000000)
242 HMENU WINAPI
FileMenu_Create (
243 COLORREF crBorderColor
,
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
);
270 /*************************************************************************
271 * FileMenu_Destroy [SHELL32.118]
276 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
280 TRACE("%p\n", hmenu
);
282 FileMenu_DeleteAllItems (hmenu
);
284 menudata
= FM_GetMenuInfo(hmenu
);
287 { SHFree( menudata
->pidl
);
289 HeapFree(GetProcessHeap(), 0, menudata
);
294 /*************************************************************************
295 * FileMenu_AppendItem [SHELL32.115]
298 static BOOL
FileMenu_AppendItemA(
306 LPSTR lpszText
= (LPSTR
)lpText
;
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
;
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
;
344 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
345 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
346 mii
.fType
= MFT_OWNERDRAW
;
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
))
359 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
360 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
362 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
366 menudata
->bFixedItems
= TRUE
;
367 SetMenuInfo(hMenu
, &MenuInfo
);
373 /**********************************************************************/
375 BOOL WINAPI
FileMenu_AppendItemAW(
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
);
392 HeapFree( GetProcessHeap(), 0, lpszText
);
396 /*************************************************************************
397 * FileMenu_InsertUsingPidl [SHELL32.110]
400 * uEnumFlags any SHCONTF flag
402 int WINAPI
FileMenu_InsertUsingPidl (
408 LPFNFMCALLBACK lpfnCallback
)
410 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
411 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
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(
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
)
452 /*************************************************************************
453 * FileMenu_FindSubMenuByPidl [SHELL32.106]
455 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
459 FIXME("%p %p\n",hMenu
, pidl
);
463 /*************************************************************************
464 * FileMenu_AppendFilesForPidl [SHELL32.124]
466 int WINAPI
FileMenu_AppendFilesForPidl(
473 menudata
= FM_GetMenuInfo(hmenu
);
475 menudata
->bInitialized
= FALSE
;
477 FM_InitMenuPopup(hmenu
, pidl
);
480 FileMenu_AppendItemA (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
482 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeperator
);
486 /*************************************************************************
487 * FileMenu_AddFilesForPidl [SHELL32.125]
490 * uEnumFlags any SHCONTF flag
492 int WINAPI
FileMenu_AddFilesForPidl (
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 (
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(
530 LPCITEMIDLIST
*ppidlFolder
,
531 LPCITEMIDLIST
*ppidlItem
)
533 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
537 #define FM_ICON_SIZE 16
541 #define FM_LEFTBORDER 2
542 #define FM_RIGHTBORDER 8
543 /*************************************************************************
544 * FileMenu_MeasureItem [SHELL32.112]
546 LRESULT WINAPI
FileMenu_MeasureItem(
548 LPMEASUREITEMSTRUCT lpmis
)
550 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
551 HDC hdc
= GetDC(hWnd
);
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
);
571 /*************************************************************************
572 * FileMenu_DrawItem [SHELL32.105]
574 LRESULT WINAPI
FileMenu_DrawItem(
576 LPDRAWITEMSTRUCT lpdis
)
578 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
579 COLORREF clrPrevText
, clrPrevBkgnd
;
581 HIMAGELIST hImageList
;
582 RECT TextRect
, BorderRect
;
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
));
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
;
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%04lx 0x%04lx 0x%04lx 0x%04lx\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
623 SetTextColor(lpdis
->hDC
, clrPrevText
);
624 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
629 /*************************************************************************
630 * FileMenu_InitMenuPopup [SHELL32.109]
633 * The filemenu is a ownerdrawn menu. Call this function responding to
637 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
639 FM_InitMenuPopup(hmenu
, NULL
);
643 /*************************************************************************
644 * FileMenu_HandleMenuChar [SHELL32.108]
646 LRESULT WINAPI
FileMenu_HandleMenuChar(
650 FIXME("%p 0x%08x\n",hMenu
,wParam
);
654 /*************************************************************************
655 * FileMenu_DeleteAllItems [SHELL32.104]
660 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
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
);
677 SHFree((LPFMINFO
)mii
.dwItemData
);
680 FileMenu_Destroy(mii
.hSubMenu
);
683 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
685 menudata
= FM_GetMenuInfo(hmenu
);
687 menudata
->bInitialized
= FALSE
;
692 /*************************************************************************
693 * FileMenu_DeleteItemByCmd [SHELL32.117]
696 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
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
);
709 /* FIXME: Do what? */
712 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
716 /*************************************************************************
717 * FileMenu_DeleteItemByIndex [SHELL32.140]
719 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
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
);
732 /* FIXME: Do what? */
735 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
739 /*************************************************************************
740 * FileMenu_DeleteItemByFirstID [SHELL32.141]
742 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
746 TRACE("%p 0x%08x\n", hMenu
, uID
);
750 /*************************************************************************
751 * FileMenu_DeleteSeparator [SHELL32.142]
753 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
755 TRACE("%p\n", hMenu
);
759 /*************************************************************************
760 * FileMenu_EnableItemByCmd [SHELL32.143]
762 BOOL WINAPI
FileMenu_EnableItemByCmd(
767 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
771 /*************************************************************************
772 * FileMenu_GetItemExtent [SHELL32.144]
775 * if the menu is too big, entries are getting cut away!!
777 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
780 FIXME("%p 0x%08x\n", hMenu
, uPos
);
782 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
783 { FIXME("0x%04lx 0x%04lx 0x%04lx 0x%04lx\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)
799 /*************************************************************************
800 * SHFind_InitMenuPopup [SHELL32.149]
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)
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
)
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
))
835 if (mii
.fType
& MFT_SEPARATOR
)
843 /**********************************************************************/
845 HRESULT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
848 BOOL bAlreadySeparated
;
849 MENUITEMINFOA miiSrc
;
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
)
860 nItem
= GetMenuItemCount(hmDst
);
862 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
864 uInsert
= (UINT
)nItem
; /* append on the end */
865 bAlreadySeparated
= TRUE
;
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
))
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
)
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 */
916 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
917 uIDMax
= miiSrc
.wID
+ 1;
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
);
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 */
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
))
957 /* Ensure the correct number of separators at the beginning of the
958 inserted menu items*/
961 if (bAlreadySeparated
)
963 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
968 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
970 if (bAlreadySeparated
)
972 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
977 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
979 /* Add a separator between the menus*/
980 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);