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
23 WINE_DEFAULT_DEBUG_CHANNEL(shellmenu
);
28 #define FM_SEPARATOR (LPCWSTR)1
30 static BOOL
FileMenu_AppendItemW(HMENU hMenu
, LPCWSTR lpText
, UINT uID
, int icon
,
31 HMENU hMenuPopup
, int nItemHeight
);
38 COLORREF crBorderColor
;
42 /* insert using pidl */
47 LPFNFMCALLBACK lpfnCallback
;
57 static BOOL bAbortInit
;
59 #define CCH_MAXITEMTEXT 256
61 static LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
66 MenuInfo
.cbSize
= sizeof(MENUINFO
);
67 MenuInfo
.fMask
= MIM_MENUDATA
;
69 if (! GetMenuInfo(hmenu
, &MenuInfo
))
72 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
74 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
76 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
83 /*************************************************************************
84 * FM_SetMenuParameter [internal]
87 static LPFMINFO
FM_SetMenuParameter(
93 LPFNFMCALLBACK lpfnCallback
)
99 menudata
= FM_GetMenuInfo(hmenu
);
101 SHFree(menudata
->pidl
);
104 menudata
->pidl
= ILClone(pidl
);
105 menudata
->uFlags
= uFlags
;
106 menudata
->uEnumFlags
= uEnumFlags
;
107 menudata
->lpfnCallback
= lpfnCallback
;
112 /*************************************************************************
113 * FM_InitMenuPopup [internal]
116 static int FM_InitMenuPopup(HMENU hmenu
, LPCITEMIDLIST pAlternatePidl
)
118 CComPtr
<IShellFolder
> lpsf
;
119 CComPtr
<IShellFolder
> lpsf2
;
120 ULONG ulItemAttr
= SFGAO_FOLDER
;
121 UINT uID
, uEnumFlags
;
122 LPFNFMCALLBACK lpfnCallback
;
124 WCHAR sTemp
[MAX_PATH
];
125 int NumberOfItems
= 0, iIcon
;
129 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
131 MenuInfo
.cbSize
= sizeof(MENUINFO
);
132 MenuInfo
.fMask
= MIM_MENUDATA
;
134 if (!GetMenuInfo(hmenu
, &MenuInfo
))
137 menudata
= (LPFMINFO
) MenuInfo
.dwMenuData
;
139 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
141 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
145 if (menudata
->bInitialized
)
148 pidl
= (pAlternatePidl
? pAlternatePidl
: menudata
->pidl
);
153 uEnumFlags
= menudata
->uEnumFlags
;
154 lpfnCallback
= menudata
->lpfnCallback
;
155 menudata
->bInitialized
= FALSE
;
157 SetMenuInfo(hmenu
, &MenuInfo
);
159 if (SUCCEEDED(SHGetDesktopFolder(&lpsf
)))
161 if (SUCCEEDED(lpsf
->BindToObject(pidl
, 0, IID_PPV_ARG(IShellFolder
, &lpsf2
))))
163 CComPtr
<IEnumIDList
> lpe
;
165 if (SUCCEEDED(lpsf2
->EnumObjects(0, uEnumFlags
, &lpe
)))
168 LPITEMIDLIST pidlTemp
= NULL
;
171 while ((!bAbortInit
) && (S_OK
== lpe
->Next(1, &pidlTemp
, &ulFetched
)))
173 if (SUCCEEDED(lpsf
->GetAttributesOf(1, (LPCITEMIDLIST
*) &pidlTemp
, &ulItemAttr
)))
175 ILGetDisplayNameExW(NULL
, pidlTemp
, sTemp
, ILGDN_FORPARSING
);
176 if (!(PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, 0, &iIcon
)))
177 iIcon
= FM_BLANK_ICON
;
178 if (SFGAO_FOLDER
& ulItemAttr
)
182 HMENU hMenuPopup
= CreatePopupMenu();
184 lpFmMi
= (LPFMINFO
) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
186 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
187 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
189 MenuInfo
.cbSize
= sizeof(MENUINFO
);
190 MenuInfo
.fMask
= MIM_MENUDATA
;
191 MenuInfo
.dwMenuData
= (ULONG_PTR
) lpFmMi
;
192 SetMenuInfo(hMenuPopup
, &MenuInfo
);
194 FileMenu_AppendItemW(hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
198 LPWSTR pExt
= PathFindExtensionW(sTemp
);
201 FileMenu_AppendItemW(hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
207 TRACE("enter callback\n");
208 lpfnCallback(pidl
, pidlTemp
);
209 TRACE("leave callback\n");
218 if (GetMenuItemCount(hmenu
) == 0)
220 static const WCHAR szEmpty
[] = { '(', 'e', 'm', 'p', 't', 'y', ')', 0 };
221 FileMenu_AppendItemW(hmenu
, szEmpty
, uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
225 menudata
->bInitialized
= TRUE
;
226 SetMenuInfo(hmenu
, &MenuInfo
);
228 return NumberOfItems
;
231 /*************************************************************************
232 * FileMenu_Create [SHELL32.114]
235 * for non-root menus values are
236 * (ffffffff,00000000,00000000,00000000,00000000)
238 HMENU WINAPI
FileMenu_Create (
239 COLORREF crBorderColor
,
248 HMENU hMenu
= CreatePopupMenu();
250 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
251 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
253 menudata
= (LPFMINFO
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
254 menudata
->crBorderColor
= crBorderColor
;
255 menudata
->nBorderWidth
= nBorderWidth
;
256 menudata
->hBorderBmp
= hBorderBmp
;
258 MenuInfo
.cbSize
= sizeof(MENUINFO
);
259 MenuInfo
.fMask
= MIM_MENUDATA
;
260 MenuInfo
.dwMenuData
= (ULONG_PTR
) menudata
;
261 SetMenuInfo (hMenu
, &MenuInfo
);
266 /*************************************************************************
267 * FileMenu_Destroy [SHELL32.118]
272 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
276 TRACE("%p\n", hmenu
);
278 FileMenu_DeleteAllItems (hmenu
);
280 menudata
= FM_GetMenuInfo(hmenu
);
282 SHFree( menudata
->pidl
);
283 HeapFree(GetProcessHeap(), 0, menudata
);
288 /*************************************************************************
289 * FileMenu_AppendItem [SHELL32.115]
292 static BOOL
FileMenu_AppendItemW(
306 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
307 hMenu
, (lpText
!=FM_SEPARATOR
) ? debugstr_w(lpText
) : NULL
,
308 uID
, icon
, hMenuPopup
, nItemHeight
);
310 ZeroMemory (&mii
, sizeof(MENUITEMINFOW
));
312 mii
.cbSize
= sizeof(MENUITEMINFOW
);
314 if (lpText
!= FM_SEPARATOR
)
316 int len
= strlenW (lpText
);
317 myItem
= (LPFMITEM
)SHAlloc(sizeof(FMITEM
) + len
*sizeof(WCHAR
));
318 wcscpy (myItem
->szItemText
, lpText
);
319 myItem
->cchItemText
= len
;
320 myItem
->iIconIndex
= icon
;
321 myItem
->hMenu
= hMenu
;
322 mii
.fMask
= MIIM_DATA
;
323 mii
.dwItemData
= (ULONG_PTR
) myItem
;
328 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
329 mii
.fType
= MFT_OWNERDRAW
;
330 mii
.hSubMenu
= hMenuPopup
;
332 else if (lpText
== FM_SEPARATOR
)
333 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
334 mii
.fType
= MFT_SEPARATOR
;
338 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
339 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
340 mii
.fType
= MFT_OWNERDRAW
;
344 InsertMenuItemW (hMenu
, (UINT
)-1, TRUE
, &mii
);
346 /* set bFixedItems to true */
347 MenuInfo
.cbSize
= sizeof(MENUINFO
);
348 MenuInfo
.fMask
= MIM_MENUDATA
;
350 if (! GetMenuInfo(hMenu
, &MenuInfo
))
353 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
354 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
356 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
360 menudata
->bFixedItems
= TRUE
;
361 SetMenuInfo(hMenu
, &MenuInfo
);
367 /**********************************************************************/
369 EXTERN_C BOOL WINAPI
FileMenu_AppendItemAW(
379 if (!lpText
) return FALSE
;
381 if (SHELL_OsIsUnicode() || lpText
== FM_SEPARATOR
)
382 ret
= FileMenu_AppendItemW(hMenu
, (LPWSTR
)lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
385 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lpText
, -1, NULL
, 0 );
386 LPWSTR lpszText
= (LPWSTR
)HeapAlloc ( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
387 if (!lpszText
) return FALSE
;
388 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lpText
, -1, lpszText
, len
);
389 ret
= FileMenu_AppendItemW(hMenu
, lpszText
, uID
, icon
, hMenuPopup
, nItemHeight
);
390 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 won't 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_AppendItemW (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
482 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeparator
);
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
, debugstr_w(pMyItem
->szItemText
));
557 GetTextExtentPoint32W(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
;
585 TRACE("%p %p %s\n", hWnd
, lpdis
, debugstr_w(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 TextRect
.left
+= FM_LEFTBORDER
;
606 xi
= TextRect
.left
+ FM_SPACE1
;
607 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
608 TextRect
.bottom
-= FM_Y_SPACE
/2;
610 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
613 ExtTextOutW (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
615 Shell_GetImageLists(0, &hImageList
);
616 ImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
618 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
620 SetTextColor(lpdis
->hDC
, clrPrevText
);
621 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
626 /*************************************************************************
627 * FileMenu_InitMenuPopup [SHELL32.109]
630 * The filemenu is an ownerdrawn menu. Call this function responding to
634 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
636 FM_InitMenuPopup(hmenu
, NULL
);
640 /*************************************************************************
641 * FileMenu_HandleMenuChar [SHELL32.108]
643 LRESULT WINAPI
FileMenu_HandleMenuChar(
647 FIXME("%p 0x%08lx\n",hMenu
,wParam
);
651 /*************************************************************************
652 * FileMenu_DeleteAllItems [SHELL32.104]
657 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
664 TRACE("%p\n", hmenu
);
666 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
667 mii
.cbSize
= sizeof(MENUITEMINFOW
);
668 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
670 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
671 { GetMenuItemInfoW(hmenu
, i
, TRUE
, &mii
);
673 SHFree((LPFMINFO
)mii
.dwItemData
);
676 FileMenu_Destroy(mii
.hSubMenu
);
679 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
681 menudata
= FM_GetMenuInfo(hmenu
);
683 menudata
->bInitialized
= FALSE
;
688 /*************************************************************************
689 * FileMenu_DeleteItemByCmd [SHELL32.117]
692 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
696 TRACE("%p 0x%08x\n", hMenu
, uID
);
698 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
699 mii
.cbSize
= sizeof(MENUITEMINFOW
);
700 mii
.fMask
= MIIM_SUBMENU
;
702 GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mii
);
705 /* FIXME: Do what? */
708 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
712 /*************************************************************************
713 * FileMenu_DeleteItemByIndex [SHELL32.140]
715 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
719 TRACE("%p 0x%08x\n", hMenu
, uPos
);
721 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
722 mii
.cbSize
= sizeof(MENUITEMINFOW
);
723 mii
.fMask
= MIIM_SUBMENU
;
725 GetMenuItemInfoW(hMenu
, uPos
, TRUE
, &mii
);
728 /* FIXME: Do what? */
731 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
735 /*************************************************************************
736 * FileMenu_DeleteItemByFirstID [SHELL32.141]
738 EXTERN_C BOOL WINAPI
FileMenu_DeleteItemByFirstID(
742 TRACE("%p 0x%08x\n", hMenu
, uID
);
746 /*************************************************************************
747 * FileMenu_DeleteSeparator [SHELL32.142]
749 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
751 TRACE("%p\n", hMenu
);
755 /*************************************************************************
756 * FileMenu_EnableItemByCmd [SHELL32.143]
758 BOOL WINAPI
FileMenu_EnableItemByCmd(
763 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
767 /*************************************************************************
768 * FileMenu_GetItemExtent [SHELL32.144]
771 * if the menu is too big, entries are getting cut away!!
773 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
776 FIXME("%p 0x%08x\n", hMenu
, uPos
);
778 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
779 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
780 rect
.right
, rect
.left
, rect
.top
, rect
.bottom
);
781 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
783 return 0x00100010; /*FIXME*/
786 /*************************************************************************
787 * FileMenu_AbortInitMenu [SHELL32.120]
790 void WINAPI
FileMenu_AbortInitMenu (void)
795 /*************************************************************************
796 * SHFind_InitMenuPopup [SHELL32.149]
798 * Get the IContextMenu instance for the submenu of options displayed
799 * for the Search entry in the Classic style Start menu.
802 * hMenu [in] handle of menu previously created
803 * hWndParent [in] parent window
804 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
805 * x [in] no pointer (0x226 over here)
808 * LPXXXXX pointer to struct containing a func addr at offset 8
809 * or NULL at failure.
811 EXTERN_C IContextMenu
* WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, UINT w
, UINT x
)
813 FIXME("hmenu=%p hwnd=%p 0x%08x 0x%08x stub\n",
814 hMenu
,hWndParent
,w
,x
);
815 return NULL
; /* this is supposed to be a pointer */
818 /*************************************************************************
819 * _SHIsMenuSeparator (internal)
821 static BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
825 mii
.cbSize
= sizeof(MENUITEMINFOW
);
826 mii
.fMask
= MIIM_TYPE
;
827 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
828 if (!GetMenuItemInfoW(hm
, i
, TRUE
, &mii
))
833 if (mii
.fType
& MFT_SEPARATOR
)
841 /*************************************************************************
842 * Shell_MergeMenus [SHELL32.67]
844 UINT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
848 BOOL bAlreadySeparated
;
849 MENUITEMINFOW miiSrc
;
851 UINT uTemp
, uIDMax
= uIDAdjust
;
853 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04x\n",
854 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
856 if (!hmDst
|| !hmSrc
)
859 nItem
= GetMenuItemCount(hmDst
);
863 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
865 uInsert
= (UINT
)nItem
; /* append on the end */
866 bAlreadySeparated
= TRUE
;
870 bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);
873 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
875 /* Add a separator between the menus */
876 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
877 bAlreadySeparated
= TRUE
;
881 /* Go through the menu items and clone them*/
882 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
884 miiSrc
.cbSize
= sizeof(MENUITEMINFOW
);
885 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
887 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
888 miiSrc
.fType
= MFT_STRING
;
889 miiSrc
.dwTypeData
= szName
;
890 miiSrc
.dwItemData
= 0;
891 miiSrc
.cch
= sizeof(szName
)/sizeof(WCHAR
);
893 if (!GetMenuItemInfoW(hmSrc
, nItem
, TRUE
, &miiSrc
))
898 /* 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);
900 if (miiSrc
.fType
& MFT_SEPARATOR
)
902 /* This is a separator; don't put two of them in a row */
903 if (bAlreadySeparated
)
906 bAlreadySeparated
= TRUE
;
908 else if (miiSrc
.hSubMenu
)
910 if (uFlags
& MM_SUBMENUSHAVEIDS
)
912 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
914 if (miiSrc
.wID
> uIDAdjustMax
) /* skip IDs higher than uIDAdjustMax */
917 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
918 uIDMax
= miiSrc
.wID
+ 1;
922 miiSrc
.fMask
&= ~MIIM_ID
; /* Don't set IDs for submenus that didn't have them already */
924 hmSubMenu
= miiSrc
.hSubMenu
;
926 miiSrc
.hSubMenu
= CreatePopupMenu();
928 if (!miiSrc
.hSubMenu
) return(uIDMax
);
930 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
& MM_SUBMENUSHAVEIDS
);
935 bAlreadySeparated
= FALSE
;
937 else /* normal menu item */
939 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
941 if (miiSrc
.wID
> uIDAdjustMax
) /* skip IDs higher than uIDAdjustMax */
944 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
945 uIDMax
= miiSrc
.wID
+ 1;
947 bAlreadySeparated
= FALSE
;
950 /* 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);
952 if (!InsertMenuItemW(hmDst
, uInsert
, TRUE
, &miiSrc
))
958 /* Ensure the correct number of separators at the beginning of the
959 inserted menu items*/
962 if (bAlreadySeparated
)
964 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
969 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
971 if (bAlreadySeparated
)
973 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
978 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
980 /* Add a separator between the menus*/
981 InsertMenuW(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);