2 * see www.geocities.com/SiliconValley/4942/filemenu.html
4 * Copyright 1999, 2000 Juergen Schmied
5 * Copyright 2011 Jay Yang
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "shell32_main.h"
37 #include "wine/debug.h"
40 /* FileMenu_Create nSelHeight constants */
41 #define FM_DEFAULT_SELHEIGHT -1
42 #define FM_FULL_SELHEIGHT 0
44 /* FileMenu_Create flags */
45 #define FMF_SMALL_ICONS 0x00
46 #define FMF_LARGE_ICONS 0x08
47 #define FMF_NO_COLUMN_BREAK 0x10
49 /* FileMenu_AppendItem constants */
50 #define FM_SEPARATOR ((const WCHAR *)1)
51 #define FM_BLANK_ICON -1
52 #define FM_DEFAULT_HEIGHT 0
54 /* FileMenu_InsertUsingPidl flags */
55 #define FMF_NO_EMPTY_ITEM 0x01
56 #define FMF_NO_PROGRAM_GROUPS 0x04
58 /* FileMenu_InsertUsingPidl callback function */
59 typedef void (CALLBACK
*LPFNFMCALLBACK
)(LPCITEMIDLIST pidlFolder
, LPCITEMIDLIST pidlFile
);
61 static BOOL
FileMenu_AppendItemW(HMENU hMenu
, LPCWSTR lpText
, UINT uID
, int icon
,
62 HMENU hMenuPopup
, int nItemHeight
);
63 BOOL WINAPI
FileMenu_DeleteAllItems(HMENU hMenu
);
70 COLORREF crBorderColor
;
74 /* insert using pidl */
79 LPFNFMCALLBACK lpfnCallback
;
89 static BOOL bAbortInit
;
91 #define CCH_MAXITEMTEXT 256
93 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
95 static LPFMINFO
FM_GetMenuInfo(HMENU hmenu
)
100 MenuInfo
.cbSize
= sizeof(MENUINFO
);
101 MenuInfo
.fMask
= MIM_MENUDATA
;
103 if (! GetMenuInfo(hmenu
, &MenuInfo
))
106 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
108 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
110 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
117 /*************************************************************************
118 * FM_SetMenuParameter [internal]
121 static LPFMINFO
FM_SetMenuParameter(
127 LPFNFMCALLBACK lpfnCallback
)
133 menudata
= FM_GetMenuInfo(hmenu
);
135 SHFree(menudata
->pidl
);
138 menudata
->pidl
= ILClone(pidl
);
139 menudata
->uFlags
= uFlags
;
140 menudata
->uEnumFlags
= uEnumFlags
;
141 menudata
->lpfnCallback
= lpfnCallback
;
146 /*************************************************************************
147 * FM_InitMenuPopup [internal]
150 static int FM_InitMenuPopup(HMENU hmenu
, LPCITEMIDLIST pAlternatePidl
)
151 { IShellFolder
*lpsf
, *lpsf2
;
152 ULONG ulItemAttr
= SFGAO_FOLDER
;
153 UINT uID
, uEnumFlags
;
154 LPFNFMCALLBACK lpfnCallback
;
156 WCHAR sTemp
[MAX_PATH
];
157 int NumberOfItems
= 0, iIcon
;
161 TRACE("%p %p\n", hmenu
, pAlternatePidl
);
163 MenuInfo
.cbSize
= sizeof(MENUINFO
);
164 MenuInfo
.fMask
= MIM_MENUDATA
;
166 if (! GetMenuInfo(hmenu
, &MenuInfo
))
169 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
171 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
173 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
177 if (menudata
->bInitialized
)
180 pidl
= (pAlternatePidl
? pAlternatePidl
: menudata
->pidl
);
185 uEnumFlags
= menudata
->uEnumFlags
;
186 lpfnCallback
= menudata
->lpfnCallback
;
187 menudata
->bInitialized
= FALSE
;
189 SetMenuInfo(hmenu
, &MenuInfo
);
191 if (SUCCEEDED (SHGetDesktopFolder(&lpsf
)))
193 if (SUCCEEDED(IShellFolder_BindToObject(lpsf
, pidl
,0,&IID_IShellFolder
,(LPVOID
*)&lpsf2
)))
195 IEnumIDList
*lpe
= NULL
;
197 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2
, 0, uEnumFlags
, &lpe
)))
200 LPITEMIDLIST pidlTemp
= NULL
;
203 while ((!bAbortInit
) && (S_OK
== IEnumIDList_Next(lpe
,1,&pidlTemp
,&ulFetched
)))
205 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf
, 1, (LPCITEMIDLIST
*)&pidlTemp
, &ulItemAttr
)))
207 ILGetDisplayNameExW(NULL
, pidlTemp
, sTemp
, ILGDN_FORPARSING
);
208 if (! (PidlToSicIndex(lpsf
, pidlTemp
, FALSE
, 0, &iIcon
)))
209 iIcon
= FM_BLANK_ICON
;
210 if ( SFGAO_FOLDER
& ulItemAttr
)
214 HMENU hMenuPopup
= CreatePopupMenu();
216 lpFmMi
= heap_alloc_zero(sizeof(*lpFmMi
));
218 lpFmMi
->pidl
= ILCombine(pidl
, pidlTemp
);
219 lpFmMi
->uEnumFlags
= SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
;
221 MenuInfo
.cbSize
= sizeof(MENUINFO
);
222 MenuInfo
.fMask
= MIM_MENUDATA
;
223 MenuInfo
.dwMenuData
= (ULONG_PTR
) lpFmMi
;
224 SetMenuInfo (hMenuPopup
, &MenuInfo
);
226 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, hMenuPopup
, FM_DEFAULT_HEIGHT
);
230 LPWSTR pExt
= PathFindExtensionW(sTemp
);
233 FileMenu_AppendItemW (hmenu
, sTemp
, uID
, iIcon
, 0, FM_DEFAULT_HEIGHT
);
239 TRACE("enter callback\n");
240 lpfnCallback ( pidl
, pidlTemp
);
241 TRACE("leave callback\n");
246 IEnumIDList_Release (lpe
);
248 IShellFolder_Release(lpsf2
);
250 IShellFolder_Release(lpsf
);
253 if ( GetMenuItemCount (hmenu
) == 0 )
255 FileMenu_AppendItemW (hmenu
, L
"(empty)", uID
, FM_BLANK_ICON
, 0, FM_DEFAULT_HEIGHT
);
259 menudata
->bInitialized
= TRUE
;
260 SetMenuInfo(hmenu
, &MenuInfo
);
262 return NumberOfItems
;
264 /*************************************************************************
265 * FileMenu_Create [SHELL32.114]
268 * for non-root menus values are
269 * (ffffffff,00000000,00000000,00000000,00000000)
271 HMENU WINAPI
FileMenu_Create (
272 COLORREF crBorderColor
,
281 HMENU hMenu
= CreatePopupMenu();
283 TRACE("0x%08lx 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
284 crBorderColor
, nBorderWidth
, hBorderBmp
, nSelHeight
, uFlags
, hMenu
);
286 menudata
= heap_alloc_zero(sizeof(*menudata
));
287 menudata
->crBorderColor
= crBorderColor
;
288 menudata
->nBorderWidth
= nBorderWidth
;
289 menudata
->hBorderBmp
= hBorderBmp
;
291 MenuInfo
.cbSize
= sizeof(MENUINFO
);
292 MenuInfo
.fMask
= MIM_MENUDATA
;
293 MenuInfo
.dwMenuData
= (ULONG_PTR
) menudata
;
294 SetMenuInfo (hMenu
, &MenuInfo
);
299 /*************************************************************************
300 * FileMenu_Destroy [SHELL32.118]
305 void WINAPI
FileMenu_Destroy (HMENU hmenu
)
309 TRACE("%p\n", hmenu
);
311 FileMenu_DeleteAllItems (hmenu
);
313 menudata
= FM_GetMenuInfo(hmenu
);
315 SHFree( menudata
->pidl
);
321 /*************************************************************************
322 * FileMenu_AppendItem [SHELL32.115]
325 static BOOL
FileMenu_AppendItemW(
339 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
340 hMenu
, (lpText
!=FM_SEPARATOR
) ? debugstr_w(lpText
) : NULL
,
341 uID
, icon
, hMenuPopup
, nItemHeight
);
343 ZeroMemory (&mii
, sizeof(MENUITEMINFOW
));
345 mii
.cbSize
= sizeof(MENUITEMINFOW
);
347 if (lpText
!= FM_SEPARATOR
)
349 int len
= lstrlenW (lpText
);
350 myItem
= SHAlloc(sizeof(FMITEM
) + len
*sizeof(WCHAR
));
351 lstrcpyW (myItem
->szItemText
, lpText
);
352 myItem
->cchItemText
= len
;
353 myItem
->iIconIndex
= icon
;
354 myItem
->hMenu
= hMenu
;
355 mii
.fMask
= MIIM_DATA
;
356 mii
.dwItemData
= (ULONG_PTR
) myItem
;
361 mii
.fMask
|= MIIM_TYPE
| MIIM_SUBMENU
;
362 mii
.fType
= MFT_OWNERDRAW
;
363 mii
.hSubMenu
= hMenuPopup
;
365 else if (lpText
== FM_SEPARATOR
)
366 { mii
.fMask
|= MIIM_ID
| MIIM_TYPE
;
367 mii
.fType
= MFT_SEPARATOR
;
371 mii
.fMask
|= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
372 mii
.fState
= MFS_ENABLED
| MFS_DEFAULT
;
373 mii
.fType
= MFT_OWNERDRAW
;
377 InsertMenuItemW (hMenu
, (UINT
)-1, TRUE
, &mii
);
379 /* set bFixedItems to true */
380 MenuInfo
.cbSize
= sizeof(MENUINFO
);
381 MenuInfo
.fMask
= MIM_MENUDATA
;
383 if (! GetMenuInfo(hMenu
, &MenuInfo
))
386 menudata
= (LPFMINFO
)MenuInfo
.dwMenuData
;
387 if ((menudata
== 0) || (MenuInfo
.cbSize
!= sizeof(MENUINFO
)))
389 ERR("menudata corrupt: %p %lu\n", menudata
, MenuInfo
.cbSize
);
393 menudata
->bFixedItems
= TRUE
;
394 SetMenuInfo(hMenu
, &MenuInfo
);
400 /**********************************************************************/
402 BOOL WINAPI
FileMenu_AppendItemAW(
412 if (!lpText
) return FALSE
;
414 if (SHELL_OsIsUnicode() || lpText
== FM_SEPARATOR
)
415 ret
= FileMenu_AppendItemW(hMenu
, lpText
, uID
, icon
, hMenuPopup
, nItemHeight
);
418 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, NULL
, 0 );
419 LPWSTR lpszText
= heap_alloc( len
*sizeof(WCHAR
) );
420 if (!lpszText
) return FALSE
;
421 MultiByteToWideChar( CP_ACP
, 0, lpText
, -1, lpszText
, len
);
422 ret
= FileMenu_AppendItemW(hMenu
, lpszText
, uID
, icon
, hMenuPopup
, nItemHeight
);
423 heap_free( lpszText
);
429 /*************************************************************************
430 * FileMenu_InsertUsingPidl [SHELL32.110]
433 * uEnumFlags any SHCONTF flag
435 int WINAPI
FileMenu_InsertUsingPidl (
441 LPFNFMCALLBACK lpfnCallback
)
443 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
444 hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
450 FM_SetMenuParameter(hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
452 return FM_InitMenuPopup(hmenu
, NULL
);
455 /*************************************************************************
456 * FileMenu_ReplaceUsingPidl [SHELL32.113]
458 * FIXME: the static items are deleted but won't be refreshed
460 int WINAPI
FileMenu_ReplaceUsingPidl(
465 LPFNFMCALLBACK lpfnCallback
)
467 TRACE("%p 0x%08x %p 0x%08x %p\n",
468 hmenu
, uID
, pidl
, uEnumFlags
, lpfnCallback
);
470 FileMenu_DeleteAllItems (hmenu
);
472 FM_SetMenuParameter(hmenu
, uID
, pidl
, 0, uEnumFlags
, lpfnCallback
);
474 return FM_InitMenuPopup(hmenu
, NULL
);
477 /*************************************************************************
478 * FileMenu_Invalidate [SHELL32.111]
480 void WINAPI
FileMenu_Invalidate (HMENU hMenu
)
485 /*************************************************************************
486 * FileMenu_FindSubMenuByPidl [SHELL32.106]
488 HMENU WINAPI
FileMenu_FindSubMenuByPidl(
492 FIXME("%p %p\n",hMenu
, pidl
);
496 /*************************************************************************
497 * FileMenu_AppendFilesForPidl [SHELL32.124]
499 int WINAPI
FileMenu_AppendFilesForPidl(
506 menudata
= FM_GetMenuInfo(hmenu
);
508 menudata
->bInitialized
= FALSE
;
510 FM_InitMenuPopup(hmenu
, pidl
);
513 FileMenu_AppendItemW (hmenu
, FM_SEPARATOR
, 0, 0, 0, FM_DEFAULT_HEIGHT
);
515 TRACE("%p %p 0x%08x\n",hmenu
, pidl
,bAddSeparator
);
519 /*************************************************************************
520 * FileMenu_AddFilesForPidl [SHELL32.125]
523 * uEnumFlags any SHCONTF flag
525 int WINAPI
FileMenu_AddFilesForPidl (
532 LPFNFMCALLBACK lpfnCallback
)
534 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
535 hmenu
, uReserved
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
537 return FileMenu_InsertUsingPidl ( hmenu
, uID
, pidl
, uFlags
, uEnumFlags
, lpfnCallback
);
542 /*************************************************************************
543 * FileMenu_TrackPopupMenuEx [SHELL32.116]
545 BOOL WINAPI
FileMenu_TrackPopupMenuEx (
553 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
554 hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
555 return TrackPopupMenuEx(hMenu
, uFlags
, x
, y
, hWnd
, lptpm
);
558 /*************************************************************************
559 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
561 BOOL WINAPI
FileMenu_GetLastSelectedItemPidls(
563 LPCITEMIDLIST
*ppidlFolder
,
564 LPCITEMIDLIST
*ppidlItem
)
566 FIXME("0x%08x %p %p\n",uReserved
, ppidlFolder
, ppidlItem
);
570 #define FM_ICON_SIZE 16
574 #define FM_LEFTBORDER 2
575 #define FM_RIGHTBORDER 8
576 /*************************************************************************
577 * FileMenu_MeasureItem [SHELL32.112]
579 LRESULT WINAPI
FileMenu_MeasureItem(
581 LPMEASUREITEMSTRUCT lpmis
)
583 LPFMITEM pMyItem
= (LPFMITEM
)(lpmis
->itemData
);
584 HDC hdc
= GetDC(hWnd
);
588 TRACE("%p %p %s\n", hWnd
, lpmis
, debugstr_w(pMyItem
->szItemText
));
590 GetTextExtentPoint32W(hdc
, pMyItem
->szItemText
, pMyItem
->cchItemText
, &size
);
592 lpmis
->itemWidth
= size
.cx
+ FM_LEFTBORDER
+ FM_ICON_SIZE
+ FM_SPACE1
+ FM_SPACE2
+ FM_RIGHTBORDER
;
593 lpmis
->itemHeight
= (size
.cy
> (FM_ICON_SIZE
+ FM_Y_SPACE
)) ? size
.cy
: (FM_ICON_SIZE
+ FM_Y_SPACE
);
595 /* add the menubitmap */
596 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
597 if (menuinfo
->nBorderWidth
)
598 lpmis
->itemWidth
+= menuinfo
->nBorderWidth
;
600 TRACE("-- 0x%04x 0x%04x\n", lpmis
->itemWidth
, lpmis
->itemHeight
);
601 ReleaseDC (hWnd
, hdc
);
604 /*************************************************************************
605 * FileMenu_DrawItem [SHELL32.105]
607 LRESULT WINAPI
FileMenu_DrawItem(
609 LPDRAWITEMSTRUCT lpdis
)
611 LPFMITEM pMyItem
= (LPFMITEM
)(lpdis
->itemData
);
612 COLORREF clrPrevText
, clrPrevBkgnd
;
614 HIMAGELIST hImageList
;
618 TRACE("%p %p %s\n", hWnd
, lpdis
, debugstr_w(pMyItem
->szItemText
));
620 if (lpdis
->itemState
& ODS_SELECTED
)
622 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHTTEXT
));
623 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_HIGHLIGHT
));
627 clrPrevText
= SetTextColor(lpdis
->hDC
, GetSysColor (COLOR_MENUTEXT
));
628 clrPrevBkgnd
= SetBkColor(lpdis
->hDC
, GetSysColor (COLOR_MENU
));
631 TextRect
= lpdis
->rcItem
;
633 /* add the menubitmap */
634 menuinfo
= FM_GetMenuInfo(pMyItem
->hMenu
);
635 if (menuinfo
->nBorderWidth
)
636 TextRect
.left
+= menuinfo
->nBorderWidth
;
638 TextRect
.left
+= FM_LEFTBORDER
;
639 xi
= TextRect
.left
+ FM_SPACE1
;
640 yi
= TextRect
.top
+ FM_Y_SPACE
/2;
641 TextRect
.bottom
-= FM_Y_SPACE
/2;
643 xt
= xi
+ FM_ICON_SIZE
+ FM_SPACE2
;
646 ExtTextOutW (lpdis
->hDC
, xt
, yt
, ETO_OPAQUE
, &TextRect
, pMyItem
->szItemText
, pMyItem
->cchItemText
, NULL
);
648 Shell_GetImageLists(0, &hImageList
);
649 ImageList_Draw(hImageList
, pMyItem
->iIconIndex
, lpdis
->hDC
, xi
, yi
, ILD_NORMAL
);
651 TRACE("-- %s\n", wine_dbgstr_rect(&TextRect
));
653 SetTextColor(lpdis
->hDC
, clrPrevText
);
654 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
659 /*************************************************************************
660 * FileMenu_InitMenuPopup [SHELL32.109]
663 * The filemenu is an ownerdrawn menu. Call this function responding to
667 BOOL WINAPI
FileMenu_InitMenuPopup (HMENU hmenu
)
669 FM_InitMenuPopup(hmenu
, NULL
);
673 /*************************************************************************
674 * FileMenu_HandleMenuChar [SHELL32.108]
676 LRESULT WINAPI
FileMenu_HandleMenuChar(
680 FIXME("%p 0x%08Ix\n",hMenu
,wParam
);
684 /*************************************************************************
685 * FileMenu_DeleteAllItems [SHELL32.104]
690 BOOL WINAPI
FileMenu_DeleteAllItems (HMENU hmenu
)
697 TRACE("%p\n", hmenu
);
699 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
700 mii
.cbSize
= sizeof(MENUITEMINFOW
);
701 mii
.fMask
= MIIM_SUBMENU
|MIIM_DATA
;
703 for (i
= 0; i
< GetMenuItemCount( hmenu
); i
++)
704 { GetMenuItemInfoW(hmenu
, i
, TRUE
, &mii
);
706 SHFree((LPFMINFO
)mii
.dwItemData
);
709 FileMenu_Destroy(mii
.hSubMenu
);
712 while (DeleteMenu (hmenu
, 0, MF_BYPOSITION
)){};
714 menudata
= FM_GetMenuInfo(hmenu
);
716 menudata
->bInitialized
= FALSE
;
721 /*************************************************************************
722 * FileMenu_DeleteItemByCmd [SHELL32.117]
725 BOOL WINAPI
FileMenu_DeleteItemByCmd (HMENU hMenu
, UINT uID
)
729 TRACE("%p 0x%08x\n", hMenu
, uID
);
731 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
732 mii
.cbSize
= sizeof(MENUITEMINFOW
);
733 mii
.fMask
= MIIM_SUBMENU
;
735 GetMenuItemInfoW(hMenu
, uID
, FALSE
, &mii
);
738 /* FIXME: Do what? */
741 DeleteMenu(hMenu
, MF_BYCOMMAND
, uID
);
745 /*************************************************************************
746 * FileMenu_DeleteItemByIndex [SHELL32.140]
748 BOOL WINAPI
FileMenu_DeleteItemByIndex ( HMENU hMenu
, UINT uPos
)
752 TRACE("%p 0x%08x\n", hMenu
, uPos
);
754 ZeroMemory ( &mii
, sizeof(MENUITEMINFOW
));
755 mii
.cbSize
= sizeof(MENUITEMINFOW
);
756 mii
.fMask
= MIIM_SUBMENU
;
758 GetMenuItemInfoW(hMenu
, uPos
, TRUE
, &mii
);
761 /* FIXME: Do what? */
764 DeleteMenu(hMenu
, MF_BYPOSITION
, uPos
);
768 /*************************************************************************
769 * FileMenu_DeleteItemByFirstID [SHELL32.141]
771 BOOL WINAPI
FileMenu_DeleteItemByFirstID(
775 TRACE("%p 0x%08x\n", hMenu
, uID
);
779 /*************************************************************************
780 * FileMenu_DeleteSeparator [SHELL32.142]
782 BOOL WINAPI
FileMenu_DeleteSeparator(HMENU hMenu
)
784 TRACE("%p\n", hMenu
);
788 /*************************************************************************
789 * FileMenu_EnableItemByCmd [SHELL32.143]
791 BOOL WINAPI
FileMenu_EnableItemByCmd(
796 TRACE("%p 0x%08x 0x%08x\n", hMenu
, uID
,bEnable
);
800 /*************************************************************************
801 * FileMenu_GetItemExtent [SHELL32.144]
804 * if the menu is too big, entries are getting cut away!!
806 DWORD WINAPI
FileMenu_GetItemExtent (HMENU hMenu
, UINT uPos
)
809 FIXME("%p 0x%08x\n", hMenu
, uPos
);
811 if (GetMenuItemRect(0, hMenu
, uPos
, &rect
))
813 FIXME("%s\n", wine_dbgstr_rect(&rect
));
814 return ((rect
.right
-rect
.left
)<<16) + (rect
.top
-rect
.bottom
);
816 return 0x00100010; /*FIXME*/
819 /*************************************************************************
820 * FileMenu_AbortInitMenu [SHELL32.120]
823 void WINAPI
FileMenu_AbortInitMenu (void)
828 /*************************************************************************
829 * SHFind_InitMenuPopup [SHELL32.149]
831 * Get the IContextMenu instance for the submenu of options displayed
832 * for the Search entry in the Classic style Start menu.
835 * hMenu [in] handle of menu previously created
836 * hWndParent [in] parent window
837 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
838 * x [in] no pointer (0x226 over here)
841 * LPXXXXX pointer to struct containing a func addr at offset 8
842 * or NULL at failure.
844 LPVOID WINAPI
SHFind_InitMenuPopup (HMENU hMenu
, HWND hWndParent
, DWORD w
, DWORD x
)
846 FIXME("hmenu=%p hwnd=%p 0x%08lx 0x%08lx stub\n",
847 hMenu
,hWndParent
,w
,x
);
848 return NULL
; /* this is supposed to be a pointer */
851 /*************************************************************************
852 * _SHIsMenuSeparator (internal)
854 static BOOL
_SHIsMenuSeparator(HMENU hm
, int i
)
858 mii
.cbSize
= sizeof(MENUITEMINFOW
);
859 mii
.fMask
= MIIM_TYPE
;
860 mii
.cch
= 0; /* WARNING: We MUST initialize it to 0*/
861 if (!GetMenuItemInfoW(hm
, i
, TRUE
, &mii
))
866 if (mii
.fType
& MFT_SEPARATOR
)
874 /*************************************************************************
875 * Shell_MergeMenus [SHELL32.67]
877 UINT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
)
880 BOOL bAlreadySeparated
;
881 MENUITEMINFOW miiSrc
;
883 UINT uTemp
, uIDMax
= uIDAdjust
;
885 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04lx\n",
886 hmDst
, hmSrc
, uInsert
, uIDAdjust
, uIDAdjustMax
, uFlags
);
888 if (!hmDst
|| !hmSrc
)
891 nItem
= GetMenuItemCount(hmDst
);
895 if (uInsert
>= (UINT
)nItem
) /* insert position inside menu? */
897 uInsert
= (UINT
)nItem
; /* append on the end */
898 bAlreadySeparated
= TRUE
;
902 bAlreadySeparated
= _SHIsMenuSeparator(hmDst
, uInsert
);
905 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
907 /* Add a separator between the menus */
908 InsertMenuA(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
909 bAlreadySeparated
= TRUE
;
913 /* Go through the menu items and clone them*/
914 for (nItem
= GetMenuItemCount(hmSrc
) - 1; nItem
>= 0; nItem
--)
916 miiSrc
.cbSize
= sizeof(MENUITEMINFOW
);
917 miiSrc
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_SUBMENU
| MIIM_CHECKMARKS
| MIIM_TYPE
| MIIM_DATA
;
919 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
920 miiSrc
.fType
= MFT_STRING
;
921 miiSrc
.dwTypeData
= szName
;
922 miiSrc
.dwItemData
= 0;
923 miiSrc
.cch
= ARRAY_SIZE(szName
);
925 if (!GetMenuItemInfoW(hmSrc
, nItem
, TRUE
, &miiSrc
))
930 /* 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);
932 if (miiSrc
.fType
& MFT_SEPARATOR
)
934 /* This is a separator; don't put two of them in a row */
935 if (bAlreadySeparated
)
938 bAlreadySeparated
= TRUE
;
940 else if (miiSrc
.hSubMenu
)
942 if (uFlags
& MM_SUBMENUSHAVEIDS
)
944 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
946 if (miiSrc
.wID
> uIDAdjustMax
) /* skip IDs higher than uIDAdjustMax */
949 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
950 uIDMax
= miiSrc
.wID
+ 1;
954 miiSrc
.fMask
&= ~MIIM_ID
; /* Don't set IDs for submenus that didn't have them already */
956 hmSubMenu
= miiSrc
.hSubMenu
;
958 miiSrc
.hSubMenu
= CreatePopupMenu();
960 if (!miiSrc
.hSubMenu
) return(uIDMax
);
962 uTemp
= Shell_MergeMenus(miiSrc
.hSubMenu
, hmSubMenu
, 0, uIDAdjust
, uIDAdjustMax
, uFlags
& MM_SUBMENUSHAVEIDS
);
967 bAlreadySeparated
= FALSE
;
969 else /* normal menu item */
971 miiSrc
.wID
+= uIDAdjust
; /* add uIDAdjust to the ID */
973 if (miiSrc
.wID
> uIDAdjustMax
) /* skip IDs higher than uIDAdjustMax */
976 if (uIDMax
<= miiSrc
.wID
) /* remember the highest ID */
977 uIDMax
= miiSrc
.wID
+ 1;
979 bAlreadySeparated
= FALSE
;
982 /* 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);
984 if (!InsertMenuItemW(hmDst
, uInsert
, TRUE
, &miiSrc
))
990 /* Ensure the correct number of separators at the beginning of the
991 inserted menu items*/
994 if (bAlreadySeparated
)
996 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
1001 if (_SHIsMenuSeparator(hmDst
, uInsert
-1))
1003 if (bAlreadySeparated
)
1005 DeleteMenu(hmDst
, uInsert
, MF_BYPOSITION
);
1010 if ((uFlags
& MM_ADDSEPARATOR
) && !bAlreadySeparated
)
1012 /* Add a separator between the menus*/
1013 InsertMenuW(hmDst
, uInsert
, MF_BYPOSITION
| MF_SEPARATOR
, 0, NULL
);
1022 IContextMenu3 IContextMenu3_iface
;
1023 IContextMenu
**menus
;
1029 static const IContextMenu3Vtbl CompositeCMenuVtbl
;
1031 static CompositeCMenu
* impl_from_IContextMenu3(IContextMenu3
* iface
)
1033 return CONTAINING_RECORD(iface
, CompositeCMenu
, IContextMenu3_iface
);
1036 static HRESULT
CompositeCMenu_Constructor(IContextMenu
**menus
,UINT menu_count
, REFIID riid
, void **ppv
)
1038 CompositeCMenu
*ret
;
1041 TRACE("(%p,%u,%s,%p)\n",menus
,menu_count
,shdebugstr_guid(riid
),ppv
);
1043 ret
= heap_alloc(sizeof(*ret
));
1045 return E_OUTOFMEMORY
;
1046 ret
->IContextMenu3_iface
.lpVtbl
= &CompositeCMenuVtbl
;
1047 ret
->menu_count
= menu_count
;
1048 ret
->menus
= heap_alloc(menu_count
*sizeof(IContextMenu
*));
1052 return E_OUTOFMEMORY
;
1054 ret
->offsets
= heap_alloc_zero(menu_count
*sizeof(UINT
));
1057 heap_free(ret
->menus
);
1059 return E_OUTOFMEMORY
;
1062 memcpy(ret
->menus
,menus
,menu_count
*sizeof(IContextMenu
*));
1063 for(i
=0;i
<menu_count
;i
++)
1064 IContextMenu_AddRef(menus
[i
]);
1065 return IContextMenu3_QueryInterface(&(ret
->IContextMenu3_iface
),riid
,ppv
);
1068 static void CompositeCMenu_Destroy(CompositeCMenu
*This
)
1071 for(i
=0;i
<This
->menu_count
;i
++)
1072 IContextMenu_Release(This
->menus
[i
]);
1073 heap_free(This
->menus
);
1074 heap_free(This
->offsets
);
1078 static HRESULT WINAPI
CompositeCMenu_QueryInterface(IContextMenu3
*iface
, REFIID riid
, void **ppv
)
1080 TRACE("(%p)->(%s,%p)\n",iface
,shdebugstr_guid(riid
),ppv
);
1082 return E_INVALIDARG
;
1083 if(IsEqualIID(riid
,&IID_IUnknown
) || IsEqualIID(riid
,&IID_IContextMenu
) ||
1084 IsEqualIID(riid
,&IID_IContextMenu2
) || IsEqualIID(riid
,&IID_IContextMenu3
))
1087 return E_NOINTERFACE
;
1088 IContextMenu3_AddRef(iface
);
1092 static ULONG WINAPI
CompositeCMenu_AddRef(IContextMenu3
*iface
)
1094 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1095 TRACE("(%p)->()\n",iface
);
1096 return ++This
->refCount
;
1099 static ULONG WINAPI
CompositeCMenu_Release(IContextMenu3
*iface
)
1101 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1102 TRACE("(%p)->()\n",iface
);
1103 if(--This
->refCount
)
1104 return This
->refCount
;
1105 CompositeCMenu_Destroy(This
);
1109 static UINT
CompositeCMenu_GetIndexForCommandId(CompositeCMenu
*This
,UINT id
)
1112 UINT high
=This
->menu_count
;
1115 UINT i
=(high
+low
)/2;
1116 if(This
->offsets
[i
]<=id
)
1124 static HRESULT WINAPI
CompositeCMenu_GetCommandString(IContextMenu3
* iface
, UINT_PTR idCmd
, UINT uFlags
, UINT
*pwReserved
, LPSTR pszName
, UINT cchMax
)
1126 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1127 UINT index
= CompositeCMenu_GetIndexForCommandId(This
,idCmd
);
1128 TRACE("(%p)->(%Ix,%x,%p,%s,%u)\n",iface
,idCmd
,uFlags
,pwReserved
,pszName
,cchMax
);
1129 return IContextMenu_GetCommandString(This
->menus
[index
],idCmd
,uFlags
,pwReserved
,pszName
,cchMax
);
1132 static HRESULT WINAPI
CompositeCMenu_InvokeCommand(IContextMenu3
* iface
,LPCMINVOKECOMMANDINFO pici
)
1134 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1136 TRACE("(%p)->(%p)\n", iface
, pici
);
1138 if (IS_INTRESOURCE(pici
->lpVerb
))
1140 UINT id
= (UINT_PTR
)pici
->lpVerb
;
1141 UINT index
= CompositeCMenu_GetIndexForCommandId(This
, id
);
1142 return IContextMenu_InvokeCommand(This
->menus
[index
], pici
);
1146 /*call each handler until one of them succeeds*/
1149 for (i
= 0; i
< This
->menu_count
; i
++)
1152 if (SUCCEEDED(hres
= IContextMenu_InvokeCommand(This
->menus
[i
], pici
)))
1159 static HRESULT WINAPI
CompositeCMenu_QueryContextMenu(IContextMenu3
*iface
, HMENU hmenu
,UINT indexMenu
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
1161 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1163 UINT id_offset
=idCmdFirst
;
1164 TRACE("(%p)->(%p,%u,%u,%u,%x)\n",iface
,hmenu
,indexMenu
,idCmdFirst
,idCmdLast
,uFlags
);
1165 for(;i
<This
->menu_count
;i
++)
1168 This
->offsets
[i
]=id_offset
;
1169 hres
= IContextMenu_QueryContextMenu(This
->menus
[i
],hmenu
,indexMenu
,id_offset
,idCmdLast
,uFlags
);
1173 return MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, id_offset
-idCmdFirst
);
1176 static HRESULT WINAPI
CompositeCMenu_HandleMenuMsg(IContextMenu3
*iface
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1178 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1182 IContextMenu2
*handler
;
1184 TRACE("(%p)->(%x,%Ix,%Ix)\n",iface
,uMsg
,wParam
,lParam
);
1187 case WM_INITMENUPOPUP
:
1188 menu
= (HMENU
)wParam
;
1189 id
= GetMenuItemID(menu
,LOWORD(lParam
));
1192 id
= ((DRAWITEMSTRUCT
*)lParam
)->itemID
;
1194 case WM_MEASUREITEM
:
1195 id
= ((MEASUREITEMSTRUCT
*)lParam
)->itemID
;
1198 WARN("Unimplemented uMsg: 0x%x\n",uMsg
);
1201 index
= CompositeCMenu_GetIndexForCommandId(This
,id
);
1202 hres
= IContextMenu_QueryInterface(This
->menus
[index
],&IID_IContextMenu2
,
1205 return IContextMenu2_HandleMenuMsg(handler
,uMsg
,wParam
,lParam
);
1209 static HRESULT WINAPI
CompositeCMenu_HandleMenuMsg2(IContextMenu3
*iface
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
,LRESULT
*plResult
)
1211 CompositeCMenu
*This
= impl_from_IContextMenu3(iface
);
1215 IContextMenu3
*handler
;
1218 TRACE("(%p)->(%x,%Ix,%Ix,%p)\n",iface
,uMsg
,wParam
,lParam
,plResult
);
1223 case WM_INITMENUPOPUP
:
1224 menu
= (HMENU
)wParam
;
1225 id
= GetMenuItemID(menu
,LOWORD(lParam
));
1228 id
= ((DRAWITEMSTRUCT
*)lParam
)->itemID
;
1230 case WM_MEASUREITEM
:
1231 id
= ((MEASUREITEMSTRUCT
*)lParam
)->itemID
;
1236 for(;i
<This
->menu_count
;i
++)
1238 hres
= IContextMenu_QueryInterface(This
->menus
[i
],&IID_IContextMenu3
,(void**)&handler
);
1241 hres
= IContextMenu3_HandleMenuMsg2(handler
,uMsg
,wParam
,lParam
,plResult
);
1242 if(SUCCEEDED(hres
) && HIWORD(*plResult
))
1248 WARN("Unimplemented uMsg: 0x%x\n",uMsg
);
1251 index
= CompositeCMenu_GetIndexForCommandId(This
,id
);
1252 hres
= IContextMenu_QueryInterface(This
->menus
[index
],&IID_IContextMenu3
,(void**)&handler
);
1254 return IContextMenu3_HandleMenuMsg2(handler
,uMsg
,wParam
,lParam
,plResult
);
1258 static const IContextMenu3Vtbl CompositeCMenuVtbl
=
1260 CompositeCMenu_QueryInterface
,
1261 CompositeCMenu_AddRef
,
1262 CompositeCMenu_Release
,
1263 CompositeCMenu_QueryContextMenu
,
1264 CompositeCMenu_InvokeCommand
,
1265 CompositeCMenu_GetCommandString
,
1266 CompositeCMenu_HandleMenuMsg
,
1267 CompositeCMenu_HandleMenuMsg2
1270 static HRESULT
SHELL_CreateContextMenu(HWND hwnd
, IContextMenu
* system_menu
,
1271 IShellFolder
*folder
, LPCITEMIDLIST folder_pidl
,
1272 LPCITEMIDLIST
*apidl
, UINT cidl
, const HKEY
*aKeys
,
1273 UINT cKeys
,REFIID riid
, void** ppv
)
1276 TRACE("(%p,%p,%p,%p,%p,%u,%p,%u,%s,%p)\n",hwnd
,system_menu
,folder
,folder_pidl
,apidl
,cidl
,aKeys
,cKeys
,shdebugstr_guid(riid
),ppv
);
1277 ret
= CompositeCMenu_Constructor(&system_menu
,1,riid
,ppv
);
1281 HRESULT WINAPI
CDefFolderMenu_Create2(LPCITEMIDLIST pidlFolder
, HWND hwnd
, UINT cidl
,
1282 LPCITEMIDLIST
*apidl
, IShellFolder
*psf
,
1283 LPFNDFMCALLBACK lpfn
, UINT nKeys
, const HKEY
*ahkeys
,
1284 IContextMenu
**ppcm
)
1286 IContextMenu
*system_menu
;
1288 LPITEMIDLIST folder_pidl
;
1289 TRACE("(%p,%p,%u,%p,%p,%u,%p,%p)\n",pidlFolder
,hwnd
,cidl
,apidl
,psf
,nKeys
,ahkeys
,ppcm
);
1292 IPersistFolder2
*persist
;
1293 IShellFolder_QueryInterface(psf
,&IID_IPersistFolder2
,(void**)&persist
);
1294 IPersistFolder2_GetCurFolder(persist
,&folder_pidl
);
1295 IPersistFolder2_Release(persist
);
1298 folder_pidl
=ILClone(pidlFolder
);
1300 ItemMenu_Constructor(psf
, folder_pidl
, (const LPCITEMIDLIST
*)apidl
, cidl
, &IID_IContextMenu
, (void**)&system_menu
);
1301 hres
= SHELL_CreateContextMenu(hwnd
,system_menu
,psf
,folder_pidl
,apidl
,cidl
,ahkeys
,nKeys
,&IID_IContextMenu
,(void**)ppcm
);
1302 IContextMenu_Release(system_menu
);
1303 ILFree(folder_pidl
);
1307 HRESULT WINAPI
SHCreateDefaultContextMenu(const DEFCONTEXTMENU
*pdcm
, REFIID riid
, void **ppv
)
1309 IShellFolder
*folder
=pdcm
->psf
;
1310 LPITEMIDLIST folder_pidl
;
1312 IContextMenu
*system_menu
;
1313 TRACE("(%p,%s,%p)\n",pdcm
,shdebugstr_guid(riid
),ppv
);
1314 if(!pdcm
->pidlFolder
)
1316 IPersistFolder2
*persist
;
1317 IShellFolder_QueryInterface(folder
,&IID_IPersistFolder2
,(void**)&persist
);
1318 IPersistFolder2_GetCurFolder(persist
,&folder_pidl
);
1319 IPersistFolder2_Release(persist
);
1322 folder_pidl
=ILClone(pdcm
->pidlFolder
);
1324 FIXME("Loading shell extensions using IQueryAssociations not yet supported\n");
1326 ItemMenu_Constructor(folder
, folder_pidl
, (const LPCITEMIDLIST
*)pdcm
->apidl
, pdcm
->cidl
, &IID_IContextMenu
, (void**)&system_menu
);
1327 ret
= SHELL_CreateContextMenu(pdcm
->hwnd
,system_menu
,folder
,folder_pidl
,(LPCITEMIDLIST
*)pdcm
->apidl
,pdcm
->cidl
,pdcm
->aKeys
,pdcm
->cKeys
,riid
,ppv
);
1328 IContextMenu_Release(system_menu
);
1329 ILFree(folder_pidl
);