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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "undocshell.h"
34 #include "shell32_main.h"
37 #include "wine/debug.h"
42 #define FM_SEPARATOR (LPCWSTR)1
44 static BOOL
FileMenu_AppendItemW(HMENU hMenu
, LPCWSTR lpText
, UINT uID
, int icon
,
45 HMENU hMenuPopup
, int nItemHeight
);
52 COLORREF crBorderColor
;
56 /* insert using pidl */
61 LPFNFMCALLBACK lpfnCallback
;
71 static BOOL bAbortInit
;
73 #define CCH_MAXITEMTEXT 256
75 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
77 static 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 %u\n", menudata
, MenuInfo
.cbSize
);
99 /*************************************************************************
100 * FM_SetMenuParameter [internal]
103 static LPFMINFO
FM_SetMenuParameter(
109 LPFNFMCALLBACK lpfnCallback
)
115 menudata
= FM_GetMenuInfo(hmenu
);
117 SHFree(menudata
->pidl
);
120 menudata
->pidl
= ILClone(pidl
);
121 menudata
->uFlags
= uFlags
;
122 menudata
->uEnumFlags
= uEnumFlags
;
123 menudata
->lpfnCallback
= lpfnCallback
;
128 /*************************************************************************
129 * FM_InitMenuPopup [internal]
132 static int FM_InitMenuPopup(HMENU hmenu
, LPCITEMIDLIST pAlternatePidl
)
133 { IShellFolder
*lpsf
, *lpsf2
;
134 ULONG ulItemAttr
= SFGAO_FOLDER
;
135 UINT uID
, uFlags
, uEnumFlags
;
136 LPFNFMCALLBACK lpfnCallback
;
138 WCHAR sTemp
[MAX_PATH
];
139 int NumberOfItems
= 0, iIcon
;
143 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
145 MenuInfo
.cbSize
= sizeof(MENUINFO
);
146 MenuInfo
.fMask
= MIM_MENUDATA
;
148 if (! GetMenuInfo(hmenu
, &MenuInfo
))
151 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
153 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
155 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
159 if (menudata
->bInitialized
)
162 pidl
= (pAlternatePidl
? pAlternatePidl
: menudata
->pidl
);
167 uFlags
= menudata
->uFlags
;
168 uEnumFlags
= menudata
->uEnumFlags
;
169 lpfnCallback
= menudata
->lpfnCallback
;
170 menudata
->bInitialized
= FALSE
;
172 SetMenuInfo(hmenu
, &MenuInfo
);
174 if (SUCCEEDED (SHGetDesktopFolder(&lpsf
)))
176 if (SUCCEEDED(IShellFolder_BindToObject(lpsf
, pidl
,0,(REFIID
)&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
178 IEnumIDList
*lpe
= NULL
;
180 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2
, 0, uEnumFlags
, &lpe
)))
183 LPITEMIDLIST pidlTemp
= NULL
;
186 while ((!bAbortInit
) && (NOERROR
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
)))
188 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf
, 1, (LPCITEMIDLIST
*)&pidlTemp
, &ulItemAttr
)))
190 ILGetDisplayNameExW(NULL
, pidlTemp
, sTemp
, ILGDN_FORPARSING
);
191 if (! (PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, 0, &iIcon
)))
192 iIcon
= FM_BLANK_ICON
;
193 if ( SFGAO_FOLDER
& ulItemAttr
)
197 HMENU hMenuPopup
= CreatePopupMenu();
199 lpFmMi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
201 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
202 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
204 MenuInfo
.cbSize
= sizeof(MENUINFO
);
205 MenuInfo
.fMask
= MIM_MENUDATA
;
206 MenuInfo
.dwMenuData
= (ULONG_PTR
) lpFmMi
;
207 SetMenuInfo (hMenuPopup
, &MenuInfo
);
209 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
213 LPWSTR pExt
= PathFindExtensionW(sTemp
);
216 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
222 TRACE("enter callback\n");
223 lpfnCallback ( pidl
, pidlTemp
);
224 TRACE("leave callback\n");
229 IEnumIDList_Release (lpe
);
231 IShellFolder_Release(lpsf2
);
233 IShellFolder_Release(lpsf
);
236 if ( GetMenuItemCount (hmenu
) == 0 )
238 static const WCHAR szEmpty
[] = { '(','e','m','p','t','y',')',0 };
239 FileMenu_AppendItemW (hmenu
, szEmpty
, uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
243 menudata
->bInitialized
= TRUE
;
244 SetMenuInfo(hmenu
, &MenuInfo
);
246 return NumberOfItems
;
248 /*************************************************************************
249 * FileMenu_Create [SHELL32.114]
252 * for non-root menus values are
253 * (ffffffff,00000000,00000000,00000000,00000000)
255 HMENU WINAPI
FileMenu_Create (
256 COLORREF crBorderColor
,
265 HMENU hMenu
= CreatePopupMenu();
267 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
268 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
270 menudata
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
271 menudata
->crBorderColor
= crBorderColor
;
272 menudata
->nBorderWidth
= nBorderWidth
;
273 menudata
->hBorderBmp
= hBorderBmp
;
275 MenuInfo
.cbSize
= sizeof(MENUINFO
);
276 MenuInfo
.fMask
= MIM_MENUDATA
;
277 MenuInfo
.dwMenuData
= (ULONG_PTR
) menudata
;
278 SetMenuInfo (hMenu
, &MenuInfo
);
283 /*************************************************************************
284 * FileMenu_Destroy [SHELL32.118]
289 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
293 TRACE("%p\n", hmenu
);
295 FileMenu_DeleteAllItems (hmenu
);
297 menudata
= FM_GetMenuInfo(hmenu
);
299 SHFree( menudata
->pidl
);
300 HeapFree(GetProcessHeap(), 0, menudata
);
305 /*************************************************************************
306 * FileMenu_AppendItem [SHELL32.115]
309 static BOOL
FileMenu_AppendItemW(
323 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
324 hMenu
, (lpText
!=FM_SEPARATOR
) ? debugstr_w(lpText
) : NULL
,
325 uID
, icon
, hMenuPopup
, nItemHeight
);
327 ZeroMemory (&mii
, sizeof(MENUITEMINFOW
));
329 mii
.cbSize
= sizeof(MENUITEMINFOW
);
331 if (lpText
!= FM_SEPARATOR
)
333 int len
= strlenW (lpText
);
334 myItem
= (LPFMITEM
) SHAlloc( sizeof(FMITEM
) + len
*sizeof(WCHAR
));
335 strcpyW (myItem
->szItemText
, lpText
);
336 myItem
->cchItemText
= len
;
337 myItem
->iIconIndex
= icon
;
338 myItem
->hMenu
= hMenu
;
339 mii
.fMask
= MIIM_DATA
;
340 mii
.dwItemData
= (ULONG_PTR
) myItem
;
345 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
346 mii
.fType
= MFT_OWNERDRAW
;
347 mii
.hSubMenu
= hMenuPopup
;
349 else if (lpText
== FM_SEPARATOR
)
350 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
351 mii
.fType
= MFT_SEPARATOR
;
355 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
356 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
357 mii
.fType
= MFT_OWNERDRAW
;
361 InsertMenuItemW (hMenu
, (UINT
)-1, TRUE
, &mii
);
363 /* set bFixedItems to true */
364 MenuInfo
.cbSize
= sizeof(MENUINFO
);
365 MenuInfo
.fMask
= MIM_MENUDATA
;
367 if (! GetMenuInfo(hMenu
, &MenuInfo
))
370 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
371 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
373 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
377 menudata
->bFixedItems
= TRUE
;
378 SetMenuInfo(hMenu
, &MenuInfo
);
384 /**********************************************************************/
386 BOOL WINAPI
FileMenu_AppendItemAW(
396 if ((SHELL_OsIsUnicode() && (lpText
!=FM_SEPARATOR
)) || (lpText
== NULL
))
397 ret
= FileMenu_AppendItemW(hMenu
, lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
400 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, NULL
, 0 );
401 LPWSTR lpszText
= HeapAlloc ( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
402 MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, lpszText
, len
);
403 ret
= FileMenu_AppendItemW(hMenu
, lpszText
, uID
, icon
, hMenuPopup
, nItemHeight
);
404 HeapFree( GetProcessHeap(), 0, lpszText
);
410 /*************************************************************************
411 * FileMenu_InsertUsingPidl [SHELL32.110]
414 * uEnumFlags any SHCONTF flag
416 int WINAPI
FileMenu_InsertUsingPidl (
422 LPFNFMCALLBACK lpfnCallback
)
424 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
425 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
431 FM_SetMenuParameter(hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
433 return FM_InitMenuPopup(hmenu
, NULL
);
436 /*************************************************************************
437 * FileMenu_ReplaceUsingPidl [SHELL32.113]
439 * FIXME: the static items are deleted but won't be refreshed
441 int WINAPI
FileMenu_ReplaceUsingPidl(
446 LPFNFMCALLBACK lpfnCallback
)
448 TRACE("%p 0x%08x %p 0x%08x %p\n",
449 hmenu
, uID
, pidl
, uEnumFlags
, lpfnCallback
);
451 FileMenu_DeleteAllItems (hmenu
);
453 FM_SetMenuParameter(hmenu
, uID
, pidl
, 0, uEnumFlags
, lpfnCallback
);
455 return FM_InitMenuPopup(hmenu
, NULL
);
458 /*************************************************************************
459 * FileMenu_Invalidate [SHELL32.111]
461 void WINAPI
FileMenu_Invalidate (HMENU hMenu
)
466 /*************************************************************************
467 * FileMenu_FindSubMenuByPidl [SHELL32.106]
469 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
473 FIXME("%p %p\n",hMenu
, pidl
);
477 /*************************************************************************
478 * FileMenu_AppendFilesForPidl [SHELL32.124]
480 int WINAPI
FileMenu_AppendFilesForPidl(
487 menudata
= FM_GetMenuInfo(hmenu
);
489 menudata
->bInitialized
= FALSE
;
491 FM_InitMenuPopup(hmenu
, pidl
);
494 FileMenu_AppendItemW (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
496 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeparator
);
500 /*************************************************************************
501 * FileMenu_AddFilesForPidl [SHELL32.125]
504 * uEnumFlags any SHCONTF flag
506 int WINAPI
FileMenu_AddFilesForPidl (
513 LPFNFMCALLBACK lpfnCallback
)
515 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
516 hmenu
, uReserved
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
518 return FileMenu_InsertUsingPidl ( hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
523 /*************************************************************************
524 * FileMenu_TrackPopupMenuEx [SHELL32.116]
526 BOOL WINAPI
FileMenu_TrackPopupMenuEx (
534 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
535 hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
536 return TrackPopupMenuEx(hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
539 /*************************************************************************
540 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
542 BOOL WINAPI
FileMenu_GetLastSelectedItemPidls(
544 LPCITEMIDLIST
*ppidlFolder
,
545 LPCITEMIDLIST
*ppidlItem
)
547 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
551 #define FM_ICON_SIZE 16
555 #define FM_LEFTBORDER 2
556 #define FM_RIGHTBORDER 8
557 /*************************************************************************
558 * FileMenu_MeasureItem [SHELL32.112]
560 LRESULT WINAPI
FileMenu_MeasureItem(
562 LPMEASUREITEMSTRUCT lpmis
)
564 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
565 HDC hdc
= GetDC(hWnd
);
569 TRACE("%p %p %s\n", hWnd
, lpmis
, debugstr_w(pMyItem
->szItemText
));
571 GetTextExtentPoint32W(hdc
, pMyItem
->szItemText
, pMyItem
->cchItemText
, &size
);
573 lpmis
->itemWidth
= size
.cx
+ FM_LEFTBORDER
+ FM_ICON_SIZE
+ FM_SPACE1
+ FM_SPACE2
+ FM_RIGHTBORDER
;
574 lpmis
->itemHeight
= (size
.cy
> (FM_ICON_SIZE
+ FM_Y_SPACE
)) ? size
.cy
: (FM_ICON_SIZE
+ FM_Y_SPACE
);
576 /* add the menubitmap */
577 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
578 if (menuinfo
->nBorderWidth
)
579 lpmis
->itemWidth
+= menuinfo
->nBorderWidth
;
581 TRACE("-- 0x%04x 0x%04x\n", lpmis
->itemWidth
, lpmis
->itemHeight
);
582 ReleaseDC (hWnd
, hdc
);
585 /*************************************************************************
586 * FileMenu_DrawItem [SHELL32.105]
588 LRESULT WINAPI
FileMenu_DrawItem(
590 LPDRAWITEMSTRUCT lpdis
)
592 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
593 COLORREF clrPrevText
, clrPrevBkgnd
;
595 HIMAGELIST hImageList
;
596 RECT TextRect
, BorderRect
;
599 TRACE("%p %p %s\n", hWnd
, lpdis
, debugstr_w(pMyItem
->szItemText
));
601 if (lpdis
->itemState
& ODS_SELECTED
)
603 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHTTEXT
));
604 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHT
));
608 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_MENUTEXT
));
609 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_MENU
));
612 CopyRect(&TextRect
, &(lpdis
->rcItem
));
614 /* add the menubitmap */
615 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
616 if (menuinfo
->nBorderWidth
)
617 TextRect
.left
+= menuinfo
->nBorderWidth
;
619 BorderRect
.right
= menuinfo
->nBorderWidth
;
620 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
622 TextRect
.left
+= FM_LEFTBORDER
;
623 xi
= TextRect
.left
+ FM_SPACE1
;
624 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
625 TextRect
.bottom
-= FM_Y_SPACE
/2;
627 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
630 ExtTextOutW (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
632 Shell_GetImageList(0, &hImageList
);
633 ImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
635 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
637 SetTextColor(lpdis
->hDC
, clrPrevText
);
638 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
643 /*************************************************************************
644 * FileMenu_InitMenuPopup [SHELL32.109]
647 * The filemenu is an ownerdrawn menu. Call this function responding to
651 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
653 FM_InitMenuPopup(hmenu
, NULL
);
657 /*************************************************************************
658 * FileMenu_HandleMenuChar [SHELL32.108]
660 LRESULT WINAPI
FileMenu_HandleMenuChar(
664 FIXME("%p 0x%08lx\n",hMenu
,wParam
);
668 /*************************************************************************
669 * FileMenu_DeleteAllItems [SHELL32.104]
674 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
681 TRACE("%p\n", hmenu
);
683 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
684 mii
.cbSize
= sizeof(MENUITEMINFOW
);
685 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
687 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
688 { GetMenuItemInfoW(hmenu
, i
, TRUE
, &mii
);
690 SHFree((LPFMINFO
)mii
.dwItemData
);
693 FileMenu_Destroy(mii
.hSubMenu
);
696 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
698 menudata
= FM_GetMenuInfo(hmenu
);
700 menudata
->bInitialized
= FALSE
;
705 /*************************************************************************
706 * FileMenu_DeleteItemByCmd [SHELL32.117]
709 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
713 TRACE("%p 0x%08x\n", hMenu
, uID
);
715 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
716 mii
.cbSize
= sizeof(MENUITEMINFOW
);
717 mii
.fMask
= MIIM_SUBMENU
;
719 GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mii
);
722 /* FIXME: Do what? */
725 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
729 /*************************************************************************
730 * FileMenu_DeleteItemByIndex [SHELL32.140]
732 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
736 TRACE("%p 0x%08x\n", hMenu
, uPos
);
738 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
739 mii
.cbSize
= sizeof(MENUITEMINFOW
);
740 mii
.fMask
= MIIM_SUBMENU
;
742 GetMenuItemInfoW(hMenu
, uPos
, TRUE
, &mii
);
745 /* FIXME: Do what? */
748 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
752 /*************************************************************************
753 * FileMenu_DeleteItemByFirstID [SHELL32.141]
755 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
759 TRACE("%p 0x%08x\n", hMenu
, uID
);
763 /*************************************************************************
764 * FileMenu_DeleteSeparator [SHELL32.142]
766 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
768 TRACE("%p\n", hMenu
);
772 /*************************************************************************
773 * FileMenu_EnableItemByCmd [SHELL32.143]
775 BOOL WINAPI
FileMenu_EnableItemByCmd(
780 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
784 /*************************************************************************
785 * FileMenu_GetItemExtent [SHELL32.144]
788 * if the menu is too big, entries are getting cut away!!
790 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
793 FIXME("%p 0x%08x\n", hMenu
, uPos
);
795 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
796 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
797 rect
.right
, rect
.left
, rect
.top
, rect
.bottom
);
798 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
800 return 0x00100010; /*FIXME*/
803 /*************************************************************************
804 * FileMenu_AbortInitMenu [SHELL32.120]
807 void WINAPI
FileMenu_AbortInitMenu (void)
812 /*************************************************************************
813 * SHFind_InitMenuPopup [SHELL32.149]
815 * Get the IContextMenu instance for the submenu of options displayed
816 * for the Search entry in the Classic style Start menu.
819 * hMenu [in] handle of menu previously created
820 * hWndParent [in] parent window
821 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
822 * x [in] no pointer (0x226 over here)
825 * LPXXXXX pointer to struct containing a func addr at offset 8
826 * or NULL at failure.
828 LPVOID WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, DWORD w
, DWORD x
)
830 FIXME("hmenu=%p hwnd=%p 0x%08x 0x%08x stub\n",
831 hMenu
,hWndParent
,w
,x
);
832 return NULL
; /* this is supposed to be a pointer */
835 /*************************************************************************
836 * _SHIsMenuSeparator (internal)
838 static BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
842 mii
.cbSize
= sizeof(MENUITEMINFOW
);
843 mii
.fMask
= MIIM_TYPE
;
844 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
845 if (!GetMenuItemInfoW(hm
, i
, TRUE
, &mii
))
850 if (mii
.fType
& MFT_SEPARATOR
)
858 /*************************************************************************
859 * Shell_MergeMenus [SHELL32.67]
861 HRESULT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
864 BOOL bAlreadySeparated
;
865 MENUITEMINFOW miiSrc
;
867 UINT uTemp
, uIDMax
= uIDAdjust
;
869 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04x\n",
870 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
872 if (!hmDst
|| !hmSrc
)
876 nItem
= GetMenuItemCount(hmDst
);
878 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
880 uInsert
= (UINT
)nItem
; /* append on the end */
881 bAlreadySeparated
= TRUE
;
885 bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);
888 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
890 /* Add a separator between the menus */
891 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
892 bAlreadySeparated
= TRUE
;
896 /* Go through the menu items and clone them*/
897 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
899 miiSrc
.cbSize
= sizeof(MENUITEMINFOW
);
900 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
902 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
903 miiSrc
.fType
= MFT_STRING
;
904 miiSrc
.dwTypeData
= szName
;
905 miiSrc
.dwItemData
= 0;
906 miiSrc
.cch
= sizeof(szName
)/sizeof(WCHAR
);
908 if (!GetMenuItemInfoW(hmSrc
, nItem
, TRUE
, &miiSrc
))
913 /* 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);
915 if (miiSrc
.fType
& MFT_SEPARATOR
)
917 /* This is a separator; don't put two of them in a row */
918 if (bAlreadySeparated
)
921 bAlreadySeparated
= TRUE
;
923 else if (miiSrc
.hSubMenu
)
925 if (uFlags
& MM_SUBMENUSHAVEIDS
)
927 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
929 if (miiSrc
.wID
> uIDAdjustMax
) /* skip ID's higher uIDAdjustMax */
932 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
933 uIDMax
= miiSrc
.wID
+ 1;
937 miiSrc
.fMask
&= ~MIIM_ID
; /* Don't set IDs for submenus that didn't have them already */
939 hmSubMenu
= miiSrc
.hSubMenu
;
941 miiSrc
.hSubMenu
= CreatePopupMenu();
943 if (!miiSrc
.hSubMenu
) return(uIDMax
);
945 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
& MM_SUBMENUSHAVEIDS
);
950 bAlreadySeparated
= FALSE
;
952 else /* normal menu item */
954 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
956 if (miiSrc
.wID
> uIDAdjustMax
) /* skip ID's higher uIDAdjustMax */
959 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
960 uIDMax
= miiSrc
.wID
+ 1;
962 bAlreadySeparated
= FALSE
;
965 /* 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);
967 if (!InsertMenuItemW(hmDst
, uInsert
, TRUE
, &miiSrc
))
973 /* Ensure the correct number of separators at the beginning of the
974 inserted menu items*/
977 if (bAlreadySeparated
)
979 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
984 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
986 if (bAlreadySeparated
)
988 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
993 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
995 /* Add a separator between the menus*/
996 InsertMenuW(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);