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 LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
82 MenuInfo
.cbSize
= sizeof(MENUINFO
);
83 MenuInfo
.fMask
= MIM_MENUDATA
;
85 if (! GetMenuInfo(hmenu
, &MenuInfo
))
88 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
90 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
92 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
99 /*************************************************************************
100 * FM_SetMenuParameter [internal]
103 static LPFMINFO
FM_SetMenuParameter(
109 LPFNFMCALLBACK lpfnCallback
)
115 menudata
= FM_GetMenuInfo(hmenu
);
118 { SHFree(menudata
->pidl
);
122 menudata
->pidl
= ILClone(pidl
);
123 menudata
->uFlags
= uFlags
;
124 menudata
->uEnumFlags
= uEnumFlags
;
125 menudata
->lpfnCallback
= lpfnCallback
;
130 /*************************************************************************
131 * FM_InitMenuPopup [internal]
134 static int FM_InitMenuPopup(HMENU hmenu
, LPCITEMIDLIST pAlternatePidl
)
135 { IShellFolder
*lpsf
, *lpsf2
;
136 ULONG ulItemAttr
= SFGAO_FOLDER
;
137 UINT uID
, uFlags
, uEnumFlags
;
138 LPFNFMCALLBACK lpfnCallback
;
140 WCHAR sTemp
[MAX_PATH
];
141 int NumberOfItems
= 0, iIcon
;
145 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
147 MenuInfo
.cbSize
= sizeof(MENUINFO
);
148 MenuInfo
.fMask
= MIM_MENUDATA
;
150 if (! GetMenuInfo(hmenu
, &MenuInfo
))
153 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
155 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
157 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
161 if (menudata
->bInitialized
)
164 pidl
= (pAlternatePidl
? pAlternatePidl
: menudata
->pidl
);
169 uFlags
= menudata
->uFlags
;
170 uEnumFlags
= menudata
->uEnumFlags
;
171 lpfnCallback
= menudata
->lpfnCallback
;
172 menudata
->bInitialized
= FALSE
;
174 SetMenuInfo(hmenu
, &MenuInfo
);
176 if (SUCCEEDED (SHGetDesktopFolder(&lpsf
)))
178 if (SUCCEEDED(IShellFolder_BindToObject(lpsf
, pidl
,0,(REFIID
)&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
180 IEnumIDList
*lpe
= NULL
;
182 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2
, 0, uEnumFlags
, &lpe
)))
185 LPITEMIDLIST pidlTemp
= NULL
;
188 while ((!bAbortInit
) && (NOERROR
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
)))
190 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf
, 1, (LPCITEMIDLIST
*)&pidlTemp
, &ulItemAttr
)))
192 ILGetDisplayNameExW(NULL
, pidlTemp
, sTemp
, ILGDN_FORPARSING
);
193 if (! (PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, 0, &iIcon
)))
194 iIcon
= FM_BLANK_ICON
;
195 if ( SFGAO_FOLDER
& ulItemAttr
)
199 HMENU hMenuPopup
= CreatePopupMenu();
201 lpFmMi
= (LPFMINFO
) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
203 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
204 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
206 MenuInfo
.cbSize
= sizeof(MENUINFO
);
207 MenuInfo
.fMask
= MIM_MENUDATA
;
208 MenuInfo
.dwMenuData
= (DWORD
) lpFmMi
;
209 SetMenuInfo (hMenuPopup
, &MenuInfo
);
211 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
215 LPWSTR pExt
= PathFindExtensionW(sTemp
);
218 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
224 TRACE("enter callback\n");
225 lpfnCallback ( pidl
, pidlTemp
);
226 TRACE("leave callback\n");
231 IEnumIDList_Release (lpe
);
233 IShellFolder_Release(lpsf2
);
235 IShellFolder_Release(lpsf
);
238 if ( GetMenuItemCount (hmenu
) == 0 )
240 static const WCHAR szEmpty
[] = { '(','e','m','p','t','y',')',0 };
241 FileMenu_AppendItemW (hmenu
, szEmpty
, uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
245 menudata
->bInitialized
= TRUE
;
246 SetMenuInfo(hmenu
, &MenuInfo
);
248 return NumberOfItems
;
250 /*************************************************************************
251 * FileMenu_Create [SHELL32.114]
254 * for non-root menus values are
255 * (ffffffff,00000000,00000000,00000000,00000000)
257 HMENU WINAPI
FileMenu_Create (
258 COLORREF crBorderColor
,
267 HMENU hMenu
= CreatePopupMenu();
269 TRACE("0x%08lx 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
270 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
272 menudata
= (LPFMINFO
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
273 menudata
->crBorderColor
= crBorderColor
;
274 menudata
->nBorderWidth
= nBorderWidth
;
275 menudata
->hBorderBmp
= hBorderBmp
;
277 MenuInfo
.cbSize
= sizeof(MENUINFO
);
278 MenuInfo
.fMask
= MIM_MENUDATA
;
279 MenuInfo
.dwMenuData
= (DWORD
) menudata
;
280 SetMenuInfo (hMenu
, &MenuInfo
);
285 /*************************************************************************
286 * FileMenu_Destroy [SHELL32.118]
291 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
295 TRACE("%p\n", hmenu
);
297 FileMenu_DeleteAllItems (hmenu
);
299 menudata
= FM_GetMenuInfo(hmenu
);
302 { SHFree( menudata
->pidl
);
304 HeapFree(GetProcessHeap(), 0, menudata
);
309 /*************************************************************************
310 * FileMenu_AppendItem [SHELL32.115]
313 static BOOL
FileMenu_AppendItemW(
327 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
328 hMenu
, (lpText
!=FM_SEPARATOR
) ? debugstr_w(lpText
) : NULL
,
329 uID
, icon
, hMenuPopup
, nItemHeight
);
331 ZeroMemory (&mii
, sizeof(MENUITEMINFOW
));
333 mii
.cbSize
= sizeof(MENUITEMINFOW
);
335 if (lpText
!= FM_SEPARATOR
)
337 int len
= strlenW (lpText
);
338 myItem
= (LPFMITEM
) SHAlloc( sizeof(FMITEM
) + len
*sizeof(WCHAR
));
339 strcpyW (myItem
->szItemText
, lpText
);
340 myItem
->cchItemText
= len
;
341 myItem
->iIconIndex
= icon
;
342 myItem
->hMenu
= hMenu
;
343 mii
.fMask
= MIIM_DATA
;
344 mii
.dwItemData
= (DWORD
) myItem
;
349 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
350 mii
.fType
= MFT_OWNERDRAW
;
351 mii
.hSubMenu
= hMenuPopup
;
353 else if (lpText
== FM_SEPARATOR
)
354 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
355 mii
.fType
= MFT_SEPARATOR
;
359 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
360 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
361 mii
.fType
= MFT_OWNERDRAW
;
365 InsertMenuItemW (hMenu
, (UINT
)-1, TRUE
, &mii
);
367 /* set bFixedItems to true */
368 MenuInfo
.cbSize
= sizeof(MENUINFO
);
369 MenuInfo
.fMask
= MIM_MENUDATA
;
371 if (! GetMenuInfo(hMenu
, &MenuInfo
))
374 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
375 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
377 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
381 menudata
->bFixedItems
= TRUE
;
382 SetMenuInfo(hMenu
, &MenuInfo
);
388 /**********************************************************************/
390 BOOL WINAPI
FileMenu_AppendItemAW(
400 if ((SHELL_OsIsUnicode() && (lpText
!=FM_SEPARATOR
)) || (lpText
== NULL
))
401 ret
= FileMenu_AppendItemW(hMenu
, lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
404 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, NULL
, 0 );
405 LPWSTR lpszText
= HeapAlloc ( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
406 MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, lpszText
, len
);
407 ret
= FileMenu_AppendItemW(hMenu
, lpszText
, uID
, icon
, hMenuPopup
, nItemHeight
);
408 HeapFree( GetProcessHeap(), 0, lpszText
);
413 /*************************************************************************
414 * FileMenu_InsertUsingPidl [SHELL32.110]
417 * uEnumFlags any SHCONTF flag
419 int WINAPI
FileMenu_InsertUsingPidl (
425 LPFNFMCALLBACK lpfnCallback
)
427 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
428 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
434 FM_SetMenuParameter(hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
436 return FM_InitMenuPopup(hmenu
, NULL
);
439 /*************************************************************************
440 * FileMenu_ReplaceUsingPidl [SHELL32.113]
442 * FIXME: the static items are deleted but won't be refreshed
444 int WINAPI
FileMenu_ReplaceUsingPidl(
449 LPFNFMCALLBACK lpfnCallback
)
451 TRACE("%p 0x%08x %p 0x%08x %p\n",
452 hmenu
, uID
, pidl
, uEnumFlags
, lpfnCallback
);
454 FileMenu_DeleteAllItems (hmenu
);
456 FM_SetMenuParameter(hmenu
, uID
, pidl
, 0, uEnumFlags
, lpfnCallback
);
458 return FM_InitMenuPopup(hmenu
, NULL
);
461 /*************************************************************************
462 * FileMenu_Invalidate [SHELL32.111]
464 void WINAPI
FileMenu_Invalidate (HMENU hMenu
)
469 /*************************************************************************
470 * FileMenu_FindSubMenuByPidl [SHELL32.106]
472 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
476 FIXME("%p %p\n",hMenu
, pidl
);
480 /*************************************************************************
481 * FileMenu_AppendFilesForPidl [SHELL32.124]
483 int WINAPI
FileMenu_AppendFilesForPidl(
490 menudata
= FM_GetMenuInfo(hmenu
);
492 menudata
->bInitialized
= FALSE
;
494 FM_InitMenuPopup(hmenu
, pidl
);
497 FileMenu_AppendItemW (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
499 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeperator
);
503 /*************************************************************************
504 * FileMenu_AddFilesForPidl [SHELL32.125]
507 * uEnumFlags any SHCONTF flag
509 int WINAPI
FileMenu_AddFilesForPidl (
516 LPFNFMCALLBACK lpfnCallback
)
518 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
519 hmenu
, uReserved
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
521 return FileMenu_InsertUsingPidl ( hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
526 /*************************************************************************
527 * FileMenu_TrackPopupMenuEx [SHELL32.116]
529 BOOL WINAPI
FileMenu_TrackPopupMenuEx (
537 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
538 hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
539 return TrackPopupMenuEx(hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
542 /*************************************************************************
543 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
545 BOOL WINAPI
FileMenu_GetLastSelectedItemPidls(
547 LPCITEMIDLIST
*ppidlFolder
,
548 LPCITEMIDLIST
*ppidlItem
)
550 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
554 #define FM_ICON_SIZE 16
558 #define FM_LEFTBORDER 2
559 #define FM_RIGHTBORDER 8
560 /*************************************************************************
561 * FileMenu_MeasureItem [SHELL32.112]
563 LRESULT WINAPI
FileMenu_MeasureItem(
565 LPMEASUREITEMSTRUCT lpmis
)
567 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
568 HDC hdc
= GetDC(hWnd
);
572 TRACE("%p %p %s\n", hWnd
, lpmis
, debugstr_w(pMyItem
->szItemText
));
574 GetTextExtentPoint32W(hdc
, pMyItem
->szItemText
, pMyItem
->cchItemText
, &size
);
576 lpmis
->itemWidth
= size
.cx
+ FM_LEFTBORDER
+ FM_ICON_SIZE
+ FM_SPACE1
+ FM_SPACE2
+ FM_RIGHTBORDER
;
577 lpmis
->itemHeight
= (size
.cy
> (FM_ICON_SIZE
+ FM_Y_SPACE
)) ? size
.cy
: (FM_ICON_SIZE
+ FM_Y_SPACE
);
579 /* add the menubitmap */
580 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
581 if (menuinfo
->nBorderWidth
)
582 lpmis
->itemWidth
+= menuinfo
->nBorderWidth
;
584 TRACE("-- 0x%04x 0x%04x\n", lpmis
->itemWidth
, lpmis
->itemHeight
);
585 ReleaseDC (hWnd
, hdc
);
588 /*************************************************************************
589 * FileMenu_DrawItem [SHELL32.105]
591 LRESULT WINAPI
FileMenu_DrawItem(
593 LPDRAWITEMSTRUCT lpdis
)
595 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
596 COLORREF clrPrevText
, clrPrevBkgnd
;
598 HIMAGELIST hImageList
;
599 RECT TextRect
, BorderRect
;
602 TRACE("%p %p %s\n", hWnd
, lpdis
, debugstr_w(pMyItem
->szItemText
));
604 if (lpdis
->itemState
& ODS_SELECTED
)
606 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHTTEXT
));
607 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHT
));
611 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_MENUTEXT
));
612 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_MENU
));
615 CopyRect(&TextRect
, &(lpdis
->rcItem
));
617 /* add the menubitmap */
618 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
619 if (menuinfo
->nBorderWidth
)
620 TextRect
.left
+= menuinfo
->nBorderWidth
;
622 BorderRect
.right
= menuinfo
->nBorderWidth
;
623 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
625 TextRect
.left
+= FM_LEFTBORDER
;
626 xi
= TextRect
.left
+ FM_SPACE1
;
627 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
628 TextRect
.bottom
-= FM_Y_SPACE
/2;
630 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
633 ExtTextOutW (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
635 Shell_GetImageList(0, &hImageList
);
636 ImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
638 TRACE("-- 0x%04lx 0x%04lx 0x%04lx 0x%04lx\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
640 SetTextColor(lpdis
->hDC
, clrPrevText
);
641 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
646 /*************************************************************************
647 * FileMenu_InitMenuPopup [SHELL32.109]
650 * The filemenu is a ownerdrawn menu. Call this function responding to
654 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
656 FM_InitMenuPopup(hmenu
, NULL
);
660 /*************************************************************************
661 * FileMenu_HandleMenuChar [SHELL32.108]
663 LRESULT WINAPI
FileMenu_HandleMenuChar(
667 FIXME("%p 0x%08x\n",hMenu
,wParam
);
671 /*************************************************************************
672 * FileMenu_DeleteAllItems [SHELL32.104]
677 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
684 TRACE("%p\n", hmenu
);
686 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
687 mii
.cbSize
= sizeof(MENUITEMINFOW
);
688 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
690 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
691 { GetMenuItemInfoW(hmenu
, i
, TRUE
, &mii
);
694 SHFree((LPFMINFO
)mii
.dwItemData
);
697 FileMenu_Destroy(mii
.hSubMenu
);
700 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
702 menudata
= FM_GetMenuInfo(hmenu
);
704 menudata
->bInitialized
= FALSE
;
709 /*************************************************************************
710 * FileMenu_DeleteItemByCmd [SHELL32.117]
713 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
717 TRACE("%p 0x%08x\n", hMenu
, uID
);
719 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
720 mii
.cbSize
= sizeof(MENUITEMINFOW
);
721 mii
.fMask
= MIIM_SUBMENU
;
723 GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mii
);
726 /* FIXME: Do what? */
729 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
733 /*************************************************************************
734 * FileMenu_DeleteItemByIndex [SHELL32.140]
736 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
740 TRACE("%p 0x%08x\n", hMenu
, uPos
);
742 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
743 mii
.cbSize
= sizeof(MENUITEMINFOW
);
744 mii
.fMask
= MIIM_SUBMENU
;
746 GetMenuItemInfoW(hMenu
, uPos
, TRUE
, &mii
);
749 /* FIXME: Do what? */
752 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
756 /*************************************************************************
757 * FileMenu_DeleteItemByFirstID [SHELL32.141]
759 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
763 TRACE("%p 0x%08x\n", hMenu
, uID
);
767 /*************************************************************************
768 * FileMenu_DeleteSeparator [SHELL32.142]
770 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
772 TRACE("%p\n", hMenu
);
776 /*************************************************************************
777 * FileMenu_EnableItemByCmd [SHELL32.143]
779 BOOL WINAPI
FileMenu_EnableItemByCmd(
784 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
788 /*************************************************************************
789 * FileMenu_GetItemExtent [SHELL32.144]
792 * if the menu is too big, entries are getting cut away!!
794 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
797 FIXME("%p 0x%08x\n", hMenu
, uPos
);
799 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
800 { FIXME("0x%04lx 0x%04lx 0x%04lx 0x%04lx\n",
801 rect
.right
, rect
.left
, rect
.top
, rect
.bottom
);
802 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
804 return 0x00100010; /*FIXME*/
807 /*************************************************************************
808 * FileMenu_AbortInitMenu [SHELL32.120]
811 void WINAPI
FileMenu_AbortInitMenu (void)
816 /*************************************************************************
817 * SHFind_InitMenuPopup [SHELL32.149]
821 * hMenu [in] handle of menu previously created
822 * hWndParent [in] parent window
823 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
824 * x [in] no pointer (0x226 over here)
827 * LPXXXXX pointer to struct containing a func addr at offset 8
828 * or NULL at failure.
830 LPVOID WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, DWORD w
, DWORD x
)
831 { FIXME("hmenu=%p hwnd=%p 0x%08lx 0x%08lx stub\n",
832 hMenu
,hWndParent
,w
,x
);
833 return NULL
; /* this is supposed to be a pointer */
836 /*************************************************************************
837 * Shell_MergeMenus [SHELL32.67]
840 BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
844 mii
.cbSize
= sizeof(MENUITEMINFOW
);
845 mii
.fMask
= MIIM_TYPE
;
846 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
847 if (!GetMenuItemInfoW(hm
, i
, TRUE
, &mii
))
852 if (mii
.fType
& MFT_SEPARATOR
)
860 /**********************************************************************/
862 HRESULT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
865 BOOL bAlreadySeparated
;
866 MENUITEMINFOW miiSrc
;
868 UINT uTemp
, uIDMax
= uIDAdjust
;
870 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04lx\n",
871 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
873 if (!hmDst
|| !hmSrc
)
877 nItem
= GetMenuItemCount(hmDst
);
879 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
881 uInsert
= (UINT
)nItem
; /* append on the end */
882 bAlreadySeparated
= TRUE
;
886 bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);
889 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
891 /* Add a separator between the menus */
892 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
893 bAlreadySeparated
= TRUE
;
897 /* Go through the menu items and clone them*/
898 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
900 miiSrc
.cbSize
= sizeof(MENUITEMINFOW
);
901 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
903 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
904 miiSrc
.fType
= MFT_STRING
;
905 miiSrc
.dwTypeData
= szName
;
906 miiSrc
.dwItemData
= 0;
907 miiSrc
.cch
= sizeof(szName
)/sizeof(WCHAR
);
909 if (!GetMenuItemInfoW(hmSrc
, nItem
, TRUE
, &miiSrc
))
914 /* 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);
916 if (miiSrc
.fType
& MFT_SEPARATOR
)
918 /* This is a separator; don't put two of them in a row */
919 if (bAlreadySeparated
)
922 bAlreadySeparated
= TRUE
;
924 else if (miiSrc
.hSubMenu
)
926 if (uFlags
& MM_SUBMENUSHAVEIDS
)
928 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
930 if (miiSrc
.wID
> uIDAdjustMax
) /* skip ID's higher uIDAdjustMax */
933 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
934 uIDMax
= miiSrc
.wID
+ 1;
938 miiSrc
.fMask
&= ~MIIM_ID
; /* Don't set IDs for submenus that didn't have them already */
940 hmSubMenu
= miiSrc
.hSubMenu
;
942 miiSrc
.hSubMenu
= CreatePopupMenu();
944 if (!miiSrc
.hSubMenu
) return(uIDMax
);
946 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
& MM_SUBMENUSHAVEIDS
);
951 bAlreadySeparated
= FALSE
;
953 else /* normal menu item */
955 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
957 if (miiSrc
.wID
> uIDAdjustMax
) /* skip ID's higher uIDAdjustMax */
960 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
961 uIDMax
= miiSrc
.wID
+ 1;
963 bAlreadySeparated
= FALSE
;
966 /* 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);
968 if (!InsertMenuItemW(hmDst
, uInsert
, TRUE
, &miiSrc
))
974 /* Ensure the correct number of separators at the beginning of the
975 inserted menu items*/
978 if (bAlreadySeparated
)
980 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
985 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
987 if (bAlreadySeparated
)
989 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
994 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
996 /* Add a separator between the menus*/
997 InsertMenuW(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);