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
21 #define WIN32_NO_STATUS
28 #include <undocshell.h>
30 #include <wine/debug.h>
31 #include <wine/unicode.h>
34 #include "shell32_main.h"
39 #define FM_SEPARATOR (LPCWSTR)1
41 static BOOL
FileMenu_AppendItemW(HMENU hMenu
, LPCWSTR lpText
, UINT uID
, int icon
,
42 HMENU hMenuPopup
, int nItemHeight
);
49 COLORREF crBorderColor
;
53 /* insert using pidl */
58 LPFNFMCALLBACK lpfnCallback
;
68 static BOOL bAbortInit
;
70 #define CCH_MAXITEMTEXT 256
72 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
74 static LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
79 MenuInfo
.cbSize
= sizeof(MENUINFO
);
80 MenuInfo
.fMask
= MIM_MENUDATA
;
82 if (! GetMenuInfo(hmenu
, &MenuInfo
))
85 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
87 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
89 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
96 /*************************************************************************
97 * FM_SetMenuParameter [internal]
100 static LPFMINFO
FM_SetMenuParameter(
106 LPFNFMCALLBACK lpfnCallback
)
112 menudata
= FM_GetMenuInfo(hmenu
);
114 SHFree(menudata
->pidl
);
117 menudata
->pidl
= ILClone(pidl
);
118 menudata
->uFlags
= uFlags
;
119 menudata
->uEnumFlags
= uEnumFlags
;
120 menudata
->lpfnCallback
= lpfnCallback
;
125 /*************************************************************************
126 * FM_InitMenuPopup [internal]
129 static int FM_InitMenuPopup(HMENU hmenu
, LPCITEMIDLIST pAlternatePidl
)
130 { IShellFolder
*lpsf
, *lpsf2
;
131 ULONG ulItemAttr
= SFGAO_FOLDER
;
132 UINT uID
, uEnumFlags
;
133 LPFNFMCALLBACK lpfnCallback
;
135 WCHAR sTemp
[MAX_PATH
];
136 int NumberOfItems
= 0, iIcon
;
140 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
142 MenuInfo
.cbSize
= sizeof(MENUINFO
);
143 MenuInfo
.fMask
= MIM_MENUDATA
;
145 if (! GetMenuInfo(hmenu
, &MenuInfo
))
148 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
150 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
152 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
156 if (menudata
->bInitialized
)
159 pidl
= (pAlternatePidl
? pAlternatePidl
: menudata
->pidl
);
164 uEnumFlags
= menudata
->uEnumFlags
;
165 lpfnCallback
= menudata
->lpfnCallback
;
166 menudata
->bInitialized
= FALSE
;
168 SetMenuInfo(hmenu
, &MenuInfo
);
170 if (SUCCEEDED (SHGetDesktopFolder(&lpsf
)))
172 if (SUCCEEDED(IShellFolder_BindToObject(lpsf
, pidl
,0,&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
174 IEnumIDList
*lpe
= NULL
;
176 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2
, 0, uEnumFlags
, &lpe
)))
179 LPITEMIDLIST pidlTemp
= NULL
;
182 while ((!bAbortInit
) && (S_OK
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
)))
184 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf
, 1, (LPCITEMIDLIST
*)&pidlTemp
, &ulItemAttr
)))
186 ILGetDisplayNameExW(NULL
, pidlTemp
, sTemp
, ILGDN_FORPARSING
);
187 if (! (PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, 0, &iIcon
)))
188 iIcon
= FM_BLANK_ICON
;
189 if ( SFGAO_FOLDER
& ulItemAttr
)
193 HMENU hMenuPopup
= CreatePopupMenu();
195 lpFmMi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
197 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
198 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
200 MenuInfo
.cbSize
= sizeof(MENUINFO
);
201 MenuInfo
.fMask
= MIM_MENUDATA
;
202 MenuInfo
.dwMenuData
= (ULONG_PTR
) lpFmMi
;
203 SetMenuInfo (hMenuPopup
, &MenuInfo
);
205 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
209 LPWSTR pExt
= PathFindExtensionW(sTemp
);
212 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
218 TRACE("enter callback\n");
219 lpfnCallback ( pidl
, pidlTemp
);
220 TRACE("leave callback\n");
225 IEnumIDList_Release (lpe
);
227 IShellFolder_Release(lpsf2
);
229 IShellFolder_Release(lpsf
);
232 if ( GetMenuItemCount (hmenu
) == 0 )
234 static const WCHAR szEmpty
[] = { '(','e','m','p','t','y',')',0 };
235 FileMenu_AppendItemW (hmenu
, szEmpty
, uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
239 menudata
->bInitialized
= TRUE
;
240 SetMenuInfo(hmenu
, &MenuInfo
);
242 return NumberOfItems
;
244 /*************************************************************************
245 * FileMenu_Create [SHELL32.114]
248 * for non-root menus values are
249 * (ffffffff,00000000,00000000,00000000,00000000)
251 HMENU WINAPI
FileMenu_Create (
252 COLORREF crBorderColor
,
261 HMENU hMenu
= CreatePopupMenu();
263 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
264 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
266 menudata
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(FMINFO
));
267 menudata
->crBorderColor
= crBorderColor
;
268 menudata
->nBorderWidth
= nBorderWidth
;
269 menudata
->hBorderBmp
= hBorderBmp
;
271 MenuInfo
.cbSize
= sizeof(MENUINFO
);
272 MenuInfo
.fMask
= MIM_MENUDATA
;
273 MenuInfo
.dwMenuData
= (ULONG_PTR
) menudata
;
274 SetMenuInfo (hMenu
, &MenuInfo
);
279 /*************************************************************************
280 * FileMenu_Destroy [SHELL32.118]
285 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
289 TRACE("%p\n", hmenu
);
291 FileMenu_DeleteAllItems (hmenu
);
293 menudata
= FM_GetMenuInfo(hmenu
);
295 SHFree( menudata
->pidl
);
296 HeapFree(GetProcessHeap(), 0, menudata
);
301 /*************************************************************************
302 * FileMenu_AppendItem [SHELL32.115]
305 static BOOL
FileMenu_AppendItemW(
319 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
320 hMenu
, (lpText
!=FM_SEPARATOR
) ? debugstr_w(lpText
) : NULL
,
321 uID
, icon
, hMenuPopup
, nItemHeight
);
323 ZeroMemory (&mii
, sizeof(MENUITEMINFOW
));
325 mii
.cbSize
= sizeof(MENUITEMINFOW
);
327 if (lpText
!= FM_SEPARATOR
)
329 int len
= strlenW (lpText
);
330 myItem
= SHAlloc(sizeof(FMITEM
) + len
*sizeof(WCHAR
));
331 strcpyW (myItem
->szItemText
, lpText
);
332 myItem
->cchItemText
= len
;
333 myItem
->iIconIndex
= icon
;
334 myItem
->hMenu
= hMenu
;
335 mii
.fMask
= MIIM_DATA
;
336 mii
.dwItemData
= (ULONG_PTR
) myItem
;
341 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
342 mii
.fType
= MFT_OWNERDRAW
;
343 mii
.hSubMenu
= hMenuPopup
;
345 else if (lpText
== FM_SEPARATOR
)
346 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
347 mii
.fType
= MFT_SEPARATOR
;
351 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
352 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
353 mii
.fType
= MFT_OWNERDRAW
;
357 InsertMenuItemW (hMenu
, (UINT
)-1, TRUE
, &mii
);
359 /* set bFixedItems to true */
360 MenuInfo
.cbSize
= sizeof(MENUINFO
);
361 MenuInfo
.fMask
= MIM_MENUDATA
;
363 if (! GetMenuInfo(hMenu
, &MenuInfo
))
366 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
367 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
369 ERR("menudata corrupt: %p %u\n", menudata
, MenuInfo
.cbSize
);
373 menudata
->bFixedItems
= TRUE
;
374 SetMenuInfo(hMenu
, &MenuInfo
);
380 /**********************************************************************/
382 BOOL WINAPI
FileMenu_AppendItemAW(
392 if (!lpText
) return FALSE
;
394 if (SHELL_OsIsUnicode() || lpText
== FM_SEPARATOR
)
395 ret
= FileMenu_AppendItemW(hMenu
, lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
398 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, NULL
, 0 );
399 LPWSTR lpszText
= HeapAlloc ( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
400 if (!lpszText
) return FALSE
;
401 MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, lpszText
, len
);
402 ret
= FileMenu_AppendItemW(hMenu
, lpszText
, uID
, icon
, hMenuPopup
, nItemHeight
);
403 HeapFree( GetProcessHeap(), 0, lpszText
);
409 /*************************************************************************
410 * FileMenu_InsertUsingPidl [SHELL32.110]
413 * uEnumFlags any SHCONTF flag
415 int WINAPI
FileMenu_InsertUsingPidl (
421 LPFNFMCALLBACK lpfnCallback
)
423 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
424 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
430 FM_SetMenuParameter(hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
432 return FM_InitMenuPopup(hmenu
, NULL
);
435 /*************************************************************************
436 * FileMenu_ReplaceUsingPidl [SHELL32.113]
438 * FIXME: the static items are deleted but won't be refreshed
440 int WINAPI
FileMenu_ReplaceUsingPidl(
445 LPFNFMCALLBACK lpfnCallback
)
447 TRACE("%p 0x%08x %p 0x%08x %p\n",
448 hmenu
, uID
, pidl
, uEnumFlags
, lpfnCallback
);
450 FileMenu_DeleteAllItems (hmenu
);
452 FM_SetMenuParameter(hmenu
, uID
, pidl
, 0, uEnumFlags
, lpfnCallback
);
454 return FM_InitMenuPopup(hmenu
, NULL
);
457 /*************************************************************************
458 * FileMenu_Invalidate [SHELL32.111]
460 void WINAPI
FileMenu_Invalidate (HMENU hMenu
)
465 /*************************************************************************
466 * FileMenu_FindSubMenuByPidl [SHELL32.106]
468 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
472 FIXME("%p %p\n",hMenu
, pidl
);
476 /*************************************************************************
477 * FileMenu_AppendFilesForPidl [SHELL32.124]
479 int WINAPI
FileMenu_AppendFilesForPidl(
486 menudata
= FM_GetMenuInfo(hmenu
);
488 menudata
->bInitialized
= FALSE
;
490 FM_InitMenuPopup(hmenu
, pidl
);
493 FileMenu_AppendItemW (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
495 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeparator
);
499 /*************************************************************************
500 * FileMenu_AddFilesForPidl [SHELL32.125]
503 * uEnumFlags any SHCONTF flag
505 int WINAPI
FileMenu_AddFilesForPidl (
512 LPFNFMCALLBACK lpfnCallback
)
514 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
515 hmenu
, uReserved
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
517 return FileMenu_InsertUsingPidl ( hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
522 /*************************************************************************
523 * FileMenu_TrackPopupMenuEx [SHELL32.116]
525 BOOL WINAPI
FileMenu_TrackPopupMenuEx (
533 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
534 hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
535 return TrackPopupMenuEx(hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
538 /*************************************************************************
539 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
541 BOOL WINAPI
FileMenu_GetLastSelectedItemPidls(
543 LPCITEMIDLIST
*ppidlFolder
,
544 LPCITEMIDLIST
*ppidlItem
)
546 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
550 #define FM_ICON_SIZE 16
554 #define FM_LEFTBORDER 2
555 #define FM_RIGHTBORDER 8
556 /*************************************************************************
557 * FileMenu_MeasureItem [SHELL32.112]
559 LRESULT WINAPI
FileMenu_MeasureItem(
561 LPMEASUREITEMSTRUCT lpmis
)
563 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
564 HDC hdc
= GetDC(hWnd
);
568 TRACE("%p %p %s\n", hWnd
, lpmis
, debugstr_w(pMyItem
->szItemText
));
570 GetTextExtentPoint32W(hdc
, pMyItem
->szItemText
, pMyItem
->cchItemText
, &size
);
572 lpmis
->itemWidth
= size
.cx
+ FM_LEFTBORDER
+ FM_ICON_SIZE
+ FM_SPACE1
+ FM_SPACE2
+ FM_RIGHTBORDER
;
573 lpmis
->itemHeight
= (size
.cy
> (FM_ICON_SIZE
+ FM_Y_SPACE
)) ? size
.cy
: (FM_ICON_SIZE
+ FM_Y_SPACE
);
575 /* add the menubitmap */
576 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
577 if (menuinfo
->nBorderWidth
)
578 lpmis
->itemWidth
+= menuinfo
->nBorderWidth
;
580 TRACE("-- 0x%04x 0x%04x\n", lpmis
->itemWidth
, lpmis
->itemHeight
);
581 ReleaseDC (hWnd
, hdc
);
584 /*************************************************************************
585 * FileMenu_DrawItem [SHELL32.105]
587 LRESULT WINAPI
FileMenu_DrawItem(
589 LPDRAWITEMSTRUCT lpdis
)
591 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
592 COLORREF clrPrevText
, clrPrevBkgnd
;
594 HIMAGELIST hImageList
;
598 TRACE("%p %p %s\n", hWnd
, lpdis
, debugstr_w(pMyItem
->szItemText
));
600 if (lpdis
->itemState
& ODS_SELECTED
)
602 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHTTEXT
));
603 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHT
));
607 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_MENUTEXT
));
608 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_MENU
));
611 CopyRect(&TextRect
, &(lpdis
->rcItem
));
613 /* add the menubitmap */
614 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
615 if (menuinfo
->nBorderWidth
)
616 TextRect
.left
+= menuinfo
->nBorderWidth
;
618 TextRect
.left
+= FM_LEFTBORDER
;
619 xi
= TextRect
.left
+ FM_SPACE1
;
620 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
621 TextRect
.bottom
-= FM_Y_SPACE
/2;
623 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
626 ExtTextOutW (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
628 Shell_GetImageLists(0, &hImageList
);
629 ImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
631 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect
.left
, TextRect
.top
, TextRect
.right
, TextRect
.bottom
);
633 SetTextColor(lpdis
->hDC
, clrPrevText
);
634 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
639 /*************************************************************************
640 * FileMenu_InitMenuPopup [SHELL32.109]
643 * The filemenu is an ownerdrawn menu. Call this function responding to
647 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
649 FM_InitMenuPopup(hmenu
, NULL
);
653 /*************************************************************************
654 * FileMenu_HandleMenuChar [SHELL32.108]
656 LRESULT WINAPI
FileMenu_HandleMenuChar(
660 FIXME("%p 0x%08lx\n",hMenu
,wParam
);
664 /*************************************************************************
665 * FileMenu_DeleteAllItems [SHELL32.104]
670 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
677 TRACE("%p\n", hmenu
);
679 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
680 mii
.cbSize
= sizeof(MENUITEMINFOW
);
681 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
683 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
684 { GetMenuItemInfoW(hmenu
, i
, TRUE
, &mii
);
686 SHFree((LPFMINFO
)mii
.dwItemData
);
689 FileMenu_Destroy(mii
.hSubMenu
);
692 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
694 menudata
= FM_GetMenuInfo(hmenu
);
696 menudata
->bInitialized
= FALSE
;
701 /*************************************************************************
702 * FileMenu_DeleteItemByCmd [SHELL32.117]
705 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
709 TRACE("%p 0x%08x\n", hMenu
, uID
);
711 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
712 mii
.cbSize
= sizeof(MENUITEMINFOW
);
713 mii
.fMask
= MIIM_SUBMENU
;
715 GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mii
);
718 /* FIXME: Do what? */
721 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
725 /*************************************************************************
726 * FileMenu_DeleteItemByIndex [SHELL32.140]
728 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
732 TRACE("%p 0x%08x\n", hMenu
, uPos
);
734 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
735 mii
.cbSize
= sizeof(MENUITEMINFOW
);
736 mii
.fMask
= MIIM_SUBMENU
;
738 GetMenuItemInfoW(hMenu
, uPos
, TRUE
, &mii
);
741 /* FIXME: Do what? */
744 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
748 /*************************************************************************
749 * FileMenu_DeleteItemByFirstID [SHELL32.141]
751 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
755 TRACE("%p 0x%08x\n", hMenu
, uID
);
759 /*************************************************************************
760 * FileMenu_DeleteSeparator [SHELL32.142]
762 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
764 TRACE("%p\n", hMenu
);
768 /*************************************************************************
769 * FileMenu_EnableItemByCmd [SHELL32.143]
771 BOOL WINAPI
FileMenu_EnableItemByCmd(
776 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
780 /*************************************************************************
781 * FileMenu_GetItemExtent [SHELL32.144]
784 * if the menu is too big, entries are getting cut away!!
786 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
789 FIXME("%p 0x%08x\n", hMenu
, uPos
);
791 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
792 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
793 rect
.right
, rect
.left
, rect
.top
, rect
.bottom
);
794 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
796 return 0x00100010; /*FIXME*/
799 /*************************************************************************
800 * FileMenu_AbortInitMenu [SHELL32.120]
803 void WINAPI
FileMenu_AbortInitMenu (void)
808 /*************************************************************************
809 * SHFind_InitMenuPopup [SHELL32.149]
811 * Get the IContextMenu instance for the submenu of options displayed
812 * for the Search entry in the Classic style Start menu.
815 * hMenu [in] handle of menu previously created
816 * hWndParent [in] parent window
817 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
818 * x [in] no pointer (0x226 over here)
821 * LPXXXXX pointer to struct containing a func addr at offset 8
822 * or NULL at failure.
824 IContextMenu
* WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, UINT w
, UINT x
)
826 FIXME("hmenu=%p hwnd=%p 0x%08x 0x%08x stub\n",
827 hMenu
,hWndParent
,w
,x
);
828 return NULL
; /* this is supposed to be a pointer */
831 /*************************************************************************
832 * _SHIsMenuSeparator (internal)
834 static BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
838 mii
.cbSize
= sizeof(MENUITEMINFOW
);
839 mii
.fMask
= MIIM_TYPE
;
840 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
841 if (!GetMenuItemInfoW(hm
, i
, TRUE
, &mii
))
846 if (mii
.fType
& MFT_SEPARATOR
)
854 /*************************************************************************
855 * Shell_MergeMenus [SHELL32.67]
857 UINT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
860 BOOL bAlreadySeparated
;
861 MENUITEMINFOW miiSrc
;
863 UINT uTemp
, uIDMax
= uIDAdjust
;
865 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04x\n",
866 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
868 if (!hmDst
|| !hmSrc
)
871 nItem
= GetMenuItemCount(hmDst
);
875 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
877 uInsert
= (UINT
)nItem
; /* append on the end */
878 bAlreadySeparated
= TRUE
;
882 bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);
885 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
887 /* Add a separator between the menus */
888 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
889 bAlreadySeparated
= TRUE
;
893 /* Go through the menu items and clone them*/
894 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
896 miiSrc
.cbSize
= sizeof(MENUITEMINFOW
);
897 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
899 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
900 miiSrc
.fType
= MFT_STRING
;
901 miiSrc
.dwTypeData
= szName
;
902 miiSrc
.dwItemData
= 0;
903 miiSrc
.cch
= sizeof(szName
)/sizeof(WCHAR
);
905 if (!GetMenuItemInfoW(hmSrc
, nItem
, TRUE
, &miiSrc
))
910 /* 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);
912 if (miiSrc
.fType
& MFT_SEPARATOR
)
914 /* This is a separator; don't put two of them in a row */
915 if (bAlreadySeparated
)
918 bAlreadySeparated
= TRUE
;
920 else if (miiSrc
.hSubMenu
)
922 if (uFlags
& MM_SUBMENUSHAVEIDS
)
924 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
926 if (miiSrc
.wID
> uIDAdjustMax
) /* skip IDs higher than uIDAdjustMax */
929 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
930 uIDMax
= miiSrc
.wID
+ 1;
934 miiSrc
.fMask
&= ~MIIM_ID
; /* Don't set IDs for submenus that didn't have them already */
936 hmSubMenu
= miiSrc
.hSubMenu
;
938 miiSrc
.hSubMenu
= CreatePopupMenu();
940 if (!miiSrc
.hSubMenu
) return(uIDMax
);
942 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
& MM_SUBMENUSHAVEIDS
);
947 bAlreadySeparated
= FALSE
;
949 else /* normal menu item */
951 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
953 if (miiSrc
.wID
> uIDAdjustMax
) /* skip IDs higher than uIDAdjustMax */
956 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
957 uIDMax
= miiSrc
.wID
+ 1;
959 bAlreadySeparated
= FALSE
;
962 /* 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);
964 if (!InsertMenuItemW(hmDst
, uInsert
, TRUE
, &miiSrc
))
970 /* Ensure the correct number of separators at the beginning of the
971 inserted menu items*/
974 if (bAlreadySeparated
)
976 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
981 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
983 if (bAlreadySeparated
)
985 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
990 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
992 /* Add a separator between the menus*/
993 InsertMenuW(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);