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
32 #include "undocshell.h"
34 #include "shell32_main.h"
38 #include "wine/debug.h"
43 #define FM_SEPARATOR (LPCWSTR)1
45 static BOOL
FileMenu_AppendItemW(HMENU hMenu
, LPCWSTR lpText
, UINT uID
, int icon
,
46 HMENU hMenuPopup
, int nItemHeight
);
53 COLORREF crBorderColor
;
57 /* insert using pidl */
62 LPFNFMCALLBACK lpfnCallback
;
72 static BOOL bAbortInit
;
74 #define CCH_MAXITEMTEXT 256
76 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
78 static LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
83 MenuInfo
.cbSize
= sizeof(MENUINFO
);
84 MenuInfo
.fMask
= MIM_MENUDATA
;
86 if (! GetMenuInfo(hmenu
, &MenuInfo
))
89 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
91 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
93 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
100 /*************************************************************************
101 * FM_SetMenuParameter [internal]
104 static LPFMINFO
FM_SetMenuParameter(
110 LPFNFMCALLBACK lpfnCallback
)
116 menudata
= FM_GetMenuInfo(hmenu
);
119 { SHFree(menudata
->pidl
);
123 menudata
->pidl
= ILClone(pidl
);
124 menudata
->uFlags
= uFlags
;
125 menudata
->uEnumFlags
= uEnumFlags
;
126 menudata
->lpfnCallback
= lpfnCallback
;
131 /*************************************************************************
132 * FM_InitMenuPopup [internal]
135 static int FM_InitMenuPopup(HMENU hmenu
, LPCITEMIDLIST pAlternatePidl
)
136 { IShellFolder
*lpsf
, *lpsf2
;
137 ULONG ulItemAttr
= SFGAO_FOLDER
;
138 UINT uID
, uFlags
, uEnumFlags
;
139 LPFNFMCALLBACK lpfnCallback
;
141 WCHAR sTemp
[MAX_PATH
];
142 int NumberOfItems
= 0, iIcon
;
146 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
148 MenuInfo
.cbSize
= sizeof(MENUINFO
);
149 MenuInfo
.fMask
= MIM_MENUDATA
;
151 if (! GetMenuInfo(hmenu
, &MenuInfo
))
154 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
156 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
158 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
162 if (menudata
->bInitialized
)
165 pidl
= (pAlternatePidl
? pAlternatePidl
: menudata
->pidl
);
170 uFlags
= menudata
->uFlags
;
171 uEnumFlags
= menudata
->uEnumFlags
;
172 lpfnCallback
= menudata
->lpfnCallback
;
173 menudata
->bInitialized
= FALSE
;
175 SetMenuInfo(hmenu
, &MenuInfo
);
177 if (SUCCEEDED (SHGetDesktopFolder(&lpsf
)))
179 if (SUCCEEDED(IShellFolder_BindToObject(lpsf
, pidl
,0,(REFIID
)&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
181 IEnumIDList
*lpe
= NULL
;
183 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2
, 0, uEnumFlags
, &lpe
)))
186 LPITEMIDLIST pidlTemp
= NULL
;
189 while ((!bAbortInit
) && (NOERROR
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
)))
191 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf
, 1, (LPCITEMIDLIST
*)&pidlTemp
, &ulItemAttr
)))
193 ILGetDisplayNameExW(NULL
, pidlTemp
, sTemp
, ILGDN_FORPARSING
);
194 if (! (PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, 0, &iIcon
)))
195 iIcon
= FM_BLANK_ICON
;
196 if ( SFGAO_FOLDER
& ulItemAttr
)
200 HMENU hMenuPopup
= CreatePopupMenu();
202 lpFmMi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
204 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
205 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
207 MenuInfo
.cbSize
= sizeof(MENUINFO
);
208 MenuInfo
.fMask
= MIM_MENUDATA
;
209 MenuInfo
.dwMenuData
= (ULONG_PTR
) lpFmMi
;
210 SetMenuInfo (hMenuPopup
, &MenuInfo
);
212 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
216 LPWSTR pExt
= PathFindExtensionW(sTemp
);
219 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
225 TRACE("enter callback\n");
226 lpfnCallback ( pidl
, pidlTemp
);
227 TRACE("leave callback\n");
232 IEnumIDList_Release (lpe
);
234 IShellFolder_Release(lpsf2
);
236 IShellFolder_Release(lpsf
);
239 if ( GetMenuItemCount (hmenu
) == 0 )
241 static const WCHAR szEmpty
[] = { '(','e','m','p','t','y',')',0 };
242 FileMenu_AppendItemW (hmenu
, szEmpty
, uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
246 menudata
->bInitialized
= TRUE
;
247 SetMenuInfo(hmenu
, &MenuInfo
);
249 return NumberOfItems
;
251 /*************************************************************************
252 * FileMenu_Create [SHELL32.114]
255 * for non-root menus values are
256 * (ffffffff,00000000,00000000,00000000,00000000)
258 HMENU WINAPI
FileMenu_Create (
259 COLORREF crBorderColor
,
268 HMENU hMenu
= CreatePopupMenu();
270 TRACE("0x%08lx 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
271 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
273 menudata
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
274 menudata
->crBorderColor
= crBorderColor
;
275 menudata
->nBorderWidth
= nBorderWidth
;
276 menudata
->hBorderBmp
= hBorderBmp
;
278 MenuInfo
.cbSize
= sizeof(MENUINFO
);
279 MenuInfo
.fMask
= MIM_MENUDATA
;
280 MenuInfo
.dwMenuData
= (ULONG_PTR
) menudata
;
281 SetMenuInfo (hMenu
, &MenuInfo
);
286 /*************************************************************************
287 * FileMenu_Destroy [SHELL32.118]
292 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
296 TRACE("%p\n", hmenu
);
298 FileMenu_DeleteAllItems (hmenu
);
300 menudata
= FM_GetMenuInfo(hmenu
);
303 { SHFree( menudata
->pidl
);
305 HeapFree(GetProcessHeap(), 0, menudata
);
310 /*************************************************************************
311 * FileMenu_AppendItem [SHELL32.115]
314 static BOOL
FileMenu_AppendItemW(
328 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
329 hMenu
, (lpText
!=FM_SEPARATOR
) ? debugstr_w(lpText
) : NULL
,
330 uID
, icon
, hMenuPopup
, nItemHeight
);
332 ZeroMemory (&mii
, sizeof(MENUITEMINFOW
));
334 mii
.cbSize
= sizeof(MENUITEMINFOW
);
336 if (lpText
!= FM_SEPARATOR
)
338 int len
= strlenW (lpText
);
339 myItem
= (LPFMITEM
) SHAlloc( sizeof(FMITEM
) + len
*sizeof(WCHAR
));
340 strcpyW (myItem
->szItemText
, lpText
);
341 myItem
->cchItemText
= len
;
342 myItem
->iIconIndex
= icon
;
343 myItem
->hMenu
= hMenu
;
344 mii
.fMask
= MIIM_DATA
;
345 mii
.dwItemData
= (ULONG_PTR
) myItem
;
350 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
351 mii
.fType
= MFT_OWNERDRAW
;
352 mii
.hSubMenu
= hMenuPopup
;
354 else if (lpText
== FM_SEPARATOR
)
355 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
356 mii
.fType
= MFT_SEPARATOR
;
360 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
361 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
362 mii
.fType
= MFT_OWNERDRAW
;
366 InsertMenuItemW (hMenu
, (UINT
)-1, TRUE
, &mii
);
368 /* set bFixedItems to true */
369 MenuInfo
.cbSize
= sizeof(MENUINFO
);
370 MenuInfo
.fMask
= MIM_MENUDATA
;
372 if (! GetMenuInfo(hMenu
, &MenuInfo
))
375 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
376 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
378 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
382 menudata
->bFixedItems
= TRUE
;
383 SetMenuInfo(hMenu
, &MenuInfo
);
389 /**********************************************************************/
391 BOOL WINAPI
FileMenu_AppendItemAW(
401 if ((SHELL_OsIsUnicode() && (lpText
!=FM_SEPARATOR
)) || (lpText
== NULL
))
402 ret
= FileMenu_AppendItemW(hMenu
, lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
405 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, NULL
, 0 );
406 LPWSTR lpszText
= HeapAlloc ( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
407 MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, lpszText
, len
);
408 ret
= FileMenu_AppendItemW(hMenu
, lpszText
, uID
, icon
, hMenuPopup
, nItemHeight
);
409 HeapFree( GetProcessHeap(), 0, lpszText
);
415 /*************************************************************************
416 * FileMenu_InsertUsingPidl [SHELL32.110]
419 * uEnumFlags any SHCONTF flag
421 int WINAPI
FileMenu_InsertUsingPidl (
427 LPFNFMCALLBACK lpfnCallback
)
429 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
430 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
436 FM_SetMenuParameter(hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
438 return FM_InitMenuPopup(hmenu
, NULL
);
441 /*************************************************************************
442 * FileMenu_ReplaceUsingPidl [SHELL32.113]
444 * FIXME: the static items are deleted but won't be refreshed
446 int WINAPI
FileMenu_ReplaceUsingPidl(
451 LPFNFMCALLBACK lpfnCallback
)
453 TRACE("%p 0x%08x %p 0x%08x %p\n",
454 hmenu
, uID
, pidl
, uEnumFlags
, lpfnCallback
);
456 FileMenu_DeleteAllItems (hmenu
);
458 FM_SetMenuParameter(hmenu
, uID
, pidl
, 0, uEnumFlags
, lpfnCallback
);
460 return FM_InitMenuPopup(hmenu
, NULL
);
463 /*************************************************************************
464 * FileMenu_Invalidate [SHELL32.111]
466 void WINAPI
FileMenu_Invalidate (HMENU hMenu
)
471 /*************************************************************************
472 * FileMenu_FindSubMenuByPidl [SHELL32.106]
474 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
478 FIXME("%p %p\n",hMenu
, pidl
);
482 /*************************************************************************
483 * FileMenu_AppendFilesForPidl [SHELL32.124]
485 int WINAPI
FileMenu_AppendFilesForPidl(
492 menudata
= FM_GetMenuInfo(hmenu
);
494 menudata
->bInitialized
= FALSE
;
496 FM_InitMenuPopup(hmenu
, pidl
);
499 FileMenu_AppendItemW (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
501 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeperator
);
505 /*************************************************************************
506 * FileMenu_AddFilesForPidl [SHELL32.125]
509 * uEnumFlags any SHCONTF flag
511 int WINAPI
FileMenu_AddFilesForPidl (
518 LPFNFMCALLBACK lpfnCallback
)
520 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
521 hmenu
, uReserved
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
523 return FileMenu_InsertUsingPidl ( hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
528 /*************************************************************************
529 * FileMenu_TrackPopupMenuEx [SHELL32.116]
531 BOOL WINAPI
FileMenu_TrackPopupMenuEx (
539 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
540 hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
541 return TrackPopupMenuEx(hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
544 /*************************************************************************
545 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
547 BOOL WINAPI
FileMenu_GetLastSelectedItemPidls(
549 LPCITEMIDLIST
*ppidlFolder
,
550 LPCITEMIDLIST
*ppidlItem
)
552 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
556 #define FM_ICON_SIZE 16
560 #define FM_LEFTBORDER 2
561 #define FM_RIGHTBORDER 8
562 /*************************************************************************
563 * FileMenu_MeasureItem [SHELL32.112]
565 LRESULT WINAPI
FileMenu_MeasureItem(
567 LPMEASUREITEMSTRUCT lpmis
)
569 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
570 HDC hdc
= GetDC(hWnd
);
574 TRACE("%p %p %s\n", hWnd
, lpmis
, debugstr_w(pMyItem
->szItemText
));
576 GetTextExtentPoint32W(hdc
, pMyItem
->szItemText
, pMyItem
->cchItemText
, &size
);
578 lpmis
->itemWidth
= size
.cx
+ FM_LEFTBORDER
+ FM_ICON_SIZE
+ FM_SPACE1
+ FM_SPACE2
+ FM_RIGHTBORDER
;
579 lpmis
->itemHeight
= (size
.cy
> (FM_ICON_SIZE
+ FM_Y_SPACE
)) ? size
.cy
: (FM_ICON_SIZE
+ FM_Y_SPACE
);
581 /* add the menubitmap */
582 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
583 if (menuinfo
->nBorderWidth
)
584 lpmis
->itemWidth
+= menuinfo
->nBorderWidth
;
586 TRACE("-- 0x%04x 0x%04x\n", lpmis
->itemWidth
, lpmis
->itemHeight
);
587 ReleaseDC (hWnd
, hdc
);
590 /*************************************************************************
591 * FileMenu_DrawItem [SHELL32.105]
593 LRESULT WINAPI
FileMenu_DrawItem(
595 LPDRAWITEMSTRUCT lpdis
)
597 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
598 COLORREF clrPrevText
, clrPrevBkgnd
;
600 HIMAGELIST hImageList
;
601 RECT TextRect
, BorderRect
;
604 TRACE("%p %p %s\n", hWnd
, lpdis
, debugstr_w(pMyItem
->szItemText
));
606 if (lpdis
->itemState
& ODS_SELECTED
)
608 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHTTEXT
));
609 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHT
));
613 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_MENUTEXT
));
614 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_MENU
));
617 CopyRect(&TextRect
, &(lpdis
->rcItem
));
619 /* add the menubitmap */
620 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
621 if (menuinfo
->nBorderWidth
)
622 TextRect
.left
+= menuinfo
->nBorderWidth
;
624 BorderRect
.right
= menuinfo
->nBorderWidth
;
625 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
627 TextRect
.left
+= FM_LEFTBORDER
;
628 xi
= TextRect
.left
+ FM_SPACE1
;
629 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
630 TextRect
.bottom
-= FM_Y_SPACE
/2;
632 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
635 ExtTextOutW (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
637 Shell_GetImageList(0, &hImageList
);
638 ImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
640 TRACE("-- 0x%04lx 0x%04lx 0x%04lx 0x%04lx\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
642 SetTextColor(lpdis
->hDC
, clrPrevText
);
643 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
648 /*************************************************************************
649 * FileMenu_InitMenuPopup [SHELL32.109]
652 * The filemenu is an ownerdrawn menu. Call this function responding to
656 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
658 FM_InitMenuPopup(hmenu
, NULL
);
662 /*************************************************************************
663 * FileMenu_HandleMenuChar [SHELL32.108]
665 LRESULT WINAPI
FileMenu_HandleMenuChar(
669 FIXME("%p 0x%08x\n",hMenu
,wParam
);
673 /*************************************************************************
674 * FileMenu_DeleteAllItems [SHELL32.104]
679 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
686 TRACE("%p\n", hmenu
);
688 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
689 mii
.cbSize
= sizeof(MENUITEMINFOW
);
690 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
692 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
693 { GetMenuItemInfoW(hmenu
, i
, TRUE
, &mii
);
696 SHFree((LPFMINFO
)mii
.dwItemData
);
699 FileMenu_Destroy(mii
.hSubMenu
);
702 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
704 menudata
= FM_GetMenuInfo(hmenu
);
706 menudata
->bInitialized
= FALSE
;
711 /*************************************************************************
712 * FileMenu_DeleteItemByCmd [SHELL32.117]
715 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
719 TRACE("%p 0x%08x\n", hMenu
, uID
);
721 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
722 mii
.cbSize
= sizeof(MENUITEMINFOW
);
723 mii
.fMask
= MIIM_SUBMENU
;
725 GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mii
);
728 /* FIXME: Do what? */
731 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
735 /*************************************************************************
736 * FileMenu_DeleteItemByIndex [SHELL32.140]
738 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
742 TRACE("%p 0x%08x\n", hMenu
, uPos
);
744 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
745 mii
.cbSize
= sizeof(MENUITEMINFOW
);
746 mii
.fMask
= MIIM_SUBMENU
;
748 GetMenuItemInfoW(hMenu
, uPos
, TRUE
, &mii
);
751 /* FIXME: Do what? */
754 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
758 /*************************************************************************
759 * FileMenu_DeleteItemByFirstID [SHELL32.141]
761 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
765 TRACE("%p 0x%08x\n", hMenu
, uID
);
769 /*************************************************************************
770 * FileMenu_DeleteSeparator [SHELL32.142]
772 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
774 TRACE("%p\n", hMenu
);
778 /*************************************************************************
779 * FileMenu_EnableItemByCmd [SHELL32.143]
781 BOOL WINAPI
FileMenu_EnableItemByCmd(
786 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
790 /*************************************************************************
791 * FileMenu_GetItemExtent [SHELL32.144]
794 * if the menu is too big, entries are getting cut away!!
796 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
799 FIXME("%p 0x%08x\n", hMenu
, uPos
);
801 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
802 { FIXME("0x%04lx 0x%04lx 0x%04lx 0x%04lx\n",
803 rect
.right
, rect
.left
, rect
.top
, rect
.bottom
);
804 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
806 return 0x00100010; /*FIXME*/
809 /*************************************************************************
810 * FileMenu_AbortInitMenu [SHELL32.120]
813 void WINAPI
FileMenu_AbortInitMenu (void)
818 /*************************************************************************
819 * SHFind_InitMenuPopup [SHELL32.149]
823 * hMenu [in] handle of menu previously created
824 * hWndParent [in] parent window
825 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
826 * x [in] no pointer (0x226 over here)
829 * LPXXXXX pointer to struct containing a func addr at offset 8
830 * or NULL at failure.
832 LPVOID WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, DWORD w
, DWORD x
)
834 FIXME("hmenu=%p hwnd=%p 0x%08lx 0x%08lx stub\n",
835 hMenu
,hWndParent
,w
,x
);
836 return NULL
; /* this is supposed to be a pointer */
839 /*************************************************************************
840 * _SHIsMenuSeparator (internal)
842 static BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
846 mii
.cbSize
= sizeof(MENUITEMINFOW
);
847 mii
.fMask
= MIIM_TYPE
;
848 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
849 if (!GetMenuItemInfoW(hm
, i
, TRUE
, &mii
))
854 if (mii
.fType
& MFT_SEPARATOR
)
862 /*************************************************************************
863 * Shell_MergeMenus [SHELL32.67]
865 HRESULT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
868 BOOL bAlreadySeparated
;
869 MENUITEMINFOW miiSrc
;
871 UINT uTemp
, uIDMax
= uIDAdjust
;
873 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04lx\n",
874 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
876 if (!hmDst
|| !hmSrc
)
880 nItem
= GetMenuItemCount(hmDst
);
882 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
884 uInsert
= (UINT
)nItem
; /* append on the end */
885 bAlreadySeparated
= TRUE
;
889 bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);
892 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
894 /* Add a separator between the menus */
895 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
896 bAlreadySeparated
= TRUE
;
900 /* Go through the menu items and clone them*/
901 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
903 miiSrc
.cbSize
= sizeof(MENUITEMINFOW
);
904 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
906 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
907 miiSrc
.fType
= MFT_STRING
;
908 miiSrc
.dwTypeData
= szName
;
909 miiSrc
.dwItemData
= 0;
910 miiSrc
.cch
= sizeof(szName
)/sizeof(WCHAR
);
912 if (!GetMenuItemInfoW(hmSrc
, nItem
, TRUE
, &miiSrc
))
917 /* 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);
919 if (miiSrc
.fType
& MFT_SEPARATOR
)
921 /* This is a separator; don't put two of them in a row */
922 if (bAlreadySeparated
)
925 bAlreadySeparated
= TRUE
;
927 else if (miiSrc
.hSubMenu
)
929 if (uFlags
& MM_SUBMENUSHAVEIDS
)
931 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
933 if (miiSrc
.wID
> uIDAdjustMax
) /* skip ID's higher uIDAdjustMax */
936 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
937 uIDMax
= miiSrc
.wID
+ 1;
941 miiSrc
.fMask
&= ~MIIM_ID
; /* Don't set IDs for submenus that didn't have them already */
943 hmSubMenu
= miiSrc
.hSubMenu
;
945 miiSrc
.hSubMenu
= CreatePopupMenu();
947 if (!miiSrc
.hSubMenu
) return(uIDMax
);
949 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
& MM_SUBMENUSHAVEIDS
);
954 bAlreadySeparated
= FALSE
;
956 else /* normal menu item */
958 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
960 if (miiSrc
.wID
> uIDAdjustMax
) /* skip ID's higher uIDAdjustMax */
963 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
964 uIDMax
= miiSrc
.wID
+ 1;
966 bAlreadySeparated
= FALSE
;
969 /* 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);
971 if (!InsertMenuItemW(hmDst
, uInsert
, TRUE
, &miiSrc
))
977 /* Ensure the correct number of separators at the beginning of the
978 inserted menu items*/
981 if (bAlreadySeparated
)
983 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
988 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
990 if (bAlreadySeparated
)
992 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
997 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
999 /* Add a separator between the menus*/
1000 InsertMenuW(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);