new 818051de2c8769029049ce3d36c6b856f47496c9
[wine/hacks.git] / dlls / shell32 / shlmenu.c
blobcdd08c9fcc4c981e1dc32d8a1a0dd8d563245c21
1 /*
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 #include <stdarg.h>
22 #include <string.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "shlobj.h"
32 #include "undocshell.h"
33 #include "shlwapi.h"
34 #include "shell32_main.h"
36 #include "pidl.h"
37 #include "wine/debug.h"
39 #ifdef FM_SEPARATOR
40 #undef FM_SEPARATOR
41 #endif
42 #define FM_SEPARATOR (LPCWSTR)1
44 static BOOL FileMenu_AppendItemW(HMENU hMenu, LPCWSTR lpText, UINT uID, int icon,
45 HMENU hMenuPopup, int nItemHeight);
47 typedef struct
49 BOOL bInitialized;
50 BOOL bFixedItems;
51 /* create */
52 COLORREF crBorderColor;
53 int nBorderWidth;
54 HBITMAP hBorderBmp;
56 /* insert using pidl */
57 LPITEMIDLIST pidl;
58 UINT uID;
59 UINT uFlags;
60 UINT uEnumFlags;
61 LPFNFMCALLBACK lpfnCallback;
62 } FMINFO, *LPFMINFO;
64 typedef struct
65 { int cchItemText;
66 int iIconIndex;
67 HMENU hMenu;
68 WCHAR szItemText[1];
69 } FMITEM, * LPFMITEM;
71 static BOOL bAbortInit;
73 #define CCH_MAXITEMTEXT 256
75 WINE_DEFAULT_DEBUG_CHANNEL(shell);
77 static LPFMINFO FM_GetMenuInfo(HMENU hmenu)
79 MENUINFO MenuInfo;
80 LPFMINFO menudata;
82 MenuInfo.cbSize = sizeof(MENUINFO);
83 MenuInfo.fMask = MIM_MENUDATA;
85 if (! GetMenuInfo(hmenu, &MenuInfo))
86 return NULL;
88 menudata = (LPFMINFO)MenuInfo.dwMenuData;
90 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
92 ERR("menudata corrupt: %p %u\n", menudata, MenuInfo.cbSize);
93 return 0;
96 return menudata;
99 /*************************************************************************
100 * FM_SetMenuParameter [internal]
103 static LPFMINFO FM_SetMenuParameter(
104 HMENU hmenu,
105 UINT uID,
106 LPCITEMIDLIST pidl,
107 UINT uFlags,
108 UINT uEnumFlags,
109 LPFNFMCALLBACK lpfnCallback)
111 LPFMINFO menudata;
113 TRACE("\n");
115 menudata = FM_GetMenuInfo(hmenu);
117 SHFree(menudata->pidl);
119 menudata->uID = uID;
120 menudata->pidl = ILClone(pidl);
121 menudata->uFlags = uFlags;
122 menudata->uEnumFlags = uEnumFlags;
123 menudata->lpfnCallback = lpfnCallback;
125 return menudata;
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;
137 LPCITEMIDLIST pidl;
138 WCHAR sTemp[MAX_PATH];
139 int NumberOfItems = 0, iIcon;
140 MENUINFO MenuInfo;
141 LPFMINFO menudata;
143 TRACE("%p %p\n", hmenu, pAlternatePidl);
145 MenuInfo.cbSize = sizeof(MENUINFO);
146 MenuInfo.fMask = MIM_MENUDATA;
148 if (! GetMenuInfo(hmenu, &MenuInfo))
149 return FALSE;
151 menudata = (LPFMINFO)MenuInfo.dwMenuData;
153 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
155 ERR("menudata corrupt: %p %u\n", menudata, MenuInfo.cbSize);
156 return 0;
159 if (menudata->bInitialized)
160 return 0;
162 pidl = (pAlternatePidl? pAlternatePidl: menudata->pidl);
163 if (!pidl)
164 return 0;
166 uID = menudata->uID;
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;
184 ULONG ulFetched;
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)
195 LPFMINFO lpFmMi;
196 MENUINFO MenuInfo;
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);
211 else
213 LPWSTR pExt = PathFindExtensionW(sTemp);
214 if (pExt)
215 *pExt = 0;
216 FileMenu_AppendItemW (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
220 if (lpfnCallback)
222 TRACE("enter callback\n");
223 lpfnCallback ( pidl, pidlTemp);
224 TRACE("leave callback\n");
227 NumberOfItems++;
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);
240 NumberOfItems++;
243 menudata->bInitialized = TRUE;
244 SetMenuInfo(hmenu, &MenuInfo);
246 return NumberOfItems;
248 /*************************************************************************
249 * FileMenu_Create [SHELL32.114]
251 * NOTES
252 * for non-root menus values are
253 * (ffffffff,00000000,00000000,00000000,00000000)
255 HMENU WINAPI FileMenu_Create (
256 COLORREF crBorderColor,
257 int nBorderWidth,
258 HBITMAP hBorderBmp,
259 int nSelHeight,
260 UINT uFlags)
262 MENUINFO MenuInfo;
263 LPFMINFO menudata;
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);
280 return hMenu;
283 /*************************************************************************
284 * FileMenu_Destroy [SHELL32.118]
286 * NOTES
287 * exported by name
289 void WINAPI FileMenu_Destroy (HMENU hmenu)
291 LPFMINFO menudata;
293 TRACE("%p\n", hmenu);
295 FileMenu_DeleteAllItems (hmenu);
297 menudata = FM_GetMenuInfo(hmenu);
299 SHFree( menudata->pidl);
300 HeapFree(GetProcessHeap(), 0, menudata);
302 DestroyMenu (hmenu);
305 /*************************************************************************
306 * FileMenu_AppendItem [SHELL32.115]
309 static BOOL FileMenu_AppendItemW(
310 HMENU hMenu,
311 LPCWSTR lpText,
312 UINT uID,
313 int icon,
314 HMENU hMenuPopup,
315 int nItemHeight)
317 MENUITEMINFOW mii;
318 LPFMITEM myItem;
319 LPFMINFO menudata;
320 MENUINFO MenuInfo;
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;
343 if ( hMenuPopup )
344 { /* sub menu */
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;
353 else
354 { /* normal item */
355 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
356 mii.fState = MFS_ENABLED | MFS_DEFAULT;
357 mii.fType = MFT_OWNERDRAW;
359 mii.wID = uID;
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))
368 return FALSE;
370 menudata = (LPFMINFO)MenuInfo.dwMenuData;
371 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
373 ERR("menudata corrupt: %p %u\n", menudata, MenuInfo.cbSize);
374 return 0;
377 menudata->bFixedItems = TRUE;
378 SetMenuInfo(hMenu, &MenuInfo);
380 return TRUE;
384 /**********************************************************************/
386 BOOL WINAPI FileMenu_AppendItemAW(
387 HMENU hMenu,
388 LPCVOID lpText,
389 UINT uID,
390 int icon,
391 HMENU hMenuPopup,
392 int nItemHeight)
394 BOOL ret;
396 if ((SHELL_OsIsUnicode() && (lpText!=FM_SEPARATOR)) || (lpText == NULL))
397 ret = FileMenu_AppendItemW(hMenu, lpText, uID, icon, hMenuPopup, nItemHeight);
398 else
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 );
407 return ret;
410 /*************************************************************************
411 * FileMenu_InsertUsingPidl [SHELL32.110]
413 * NOTES
414 * uEnumFlags any SHCONTF flag
416 int WINAPI FileMenu_InsertUsingPidl (
417 HMENU hmenu,
418 UINT uID,
419 LPCITEMIDLIST pidl,
420 UINT uFlags,
421 UINT uEnumFlags,
422 LPFNFMCALLBACK lpfnCallback)
424 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
425 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
427 pdump (pidl);
429 bAbortInit = FALSE;
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(
442 HMENU hmenu,
443 UINT uID,
444 LPCITEMIDLIST pidl,
445 UINT uEnumFlags,
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)
463 FIXME("%p\n",hMenu);
466 /*************************************************************************
467 * FileMenu_FindSubMenuByPidl [SHELL32.106]
469 HMENU WINAPI FileMenu_FindSubMenuByPidl(
470 HMENU hMenu,
471 LPCITEMIDLIST pidl)
473 FIXME("%p %p\n",hMenu, pidl);
474 return 0;
477 /*************************************************************************
478 * FileMenu_AppendFilesForPidl [SHELL32.124]
480 int WINAPI FileMenu_AppendFilesForPidl(
481 HMENU hmenu,
482 LPCITEMIDLIST pidl,
483 BOOL bAddSeparator)
485 LPFMINFO menudata;
487 menudata = FM_GetMenuInfo(hmenu);
489 menudata->bInitialized = FALSE;
491 FM_InitMenuPopup(hmenu, pidl);
493 if (bAddSeparator)
494 FileMenu_AppendItemW (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
496 TRACE("%p %p 0x%08x\n",hmenu, pidl,bAddSeparator);
498 return 0;
500 /*************************************************************************
501 * FileMenu_AddFilesForPidl [SHELL32.125]
503 * NOTES
504 * uEnumFlags any SHCONTF flag
506 int WINAPI FileMenu_AddFilesForPidl (
507 HMENU hmenu,
508 UINT uReserved,
509 UINT uID,
510 LPCITEMIDLIST pidl,
511 UINT uFlags,
512 UINT uEnumFlags,
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 (
527 HMENU hMenu,
528 UINT uFlags,
529 int x,
530 int y,
531 HWND hWnd,
532 LPTPMPARAMS lptpm)
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(
543 UINT uReserved,
544 LPCITEMIDLIST *ppidlFolder,
545 LPCITEMIDLIST *ppidlItem)
547 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
548 return 0;
551 #define FM_ICON_SIZE 16
552 #define FM_Y_SPACE 4
553 #define FM_SPACE1 4
554 #define FM_SPACE2 2
555 #define FM_LEFTBORDER 2
556 #define FM_RIGHTBORDER 8
557 /*************************************************************************
558 * FileMenu_MeasureItem [SHELL32.112]
560 LRESULT WINAPI FileMenu_MeasureItem(
561 HWND hWnd,
562 LPMEASUREITEMSTRUCT lpmis)
564 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
565 HDC hdc = GetDC(hWnd);
566 SIZE size;
567 LPFMINFO menuinfo;
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);
583 return 0;
585 /*************************************************************************
586 * FileMenu_DrawItem [SHELL32.105]
588 LRESULT WINAPI FileMenu_DrawItem(
589 HWND hWnd,
590 LPDRAWITEMSTRUCT lpdis)
592 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
593 COLORREF clrPrevText, clrPrevBkgnd;
594 int xi,yi,xt,yt;
595 HIMAGELIST hImageList;
596 RECT TextRect, BorderRect;
597 LPFMINFO menuinfo;
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));
606 else
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;
628 yt = yi;
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);
640 return TRUE;
643 /*************************************************************************
644 * FileMenu_InitMenuPopup [SHELL32.109]
646 * NOTES
647 * The filemenu is an ownerdrawn menu. Call this function responding to
648 * WM_INITPOPUPMENU
651 BOOL WINAPI FileMenu_InitMenuPopup (HMENU hmenu)
653 FM_InitMenuPopup(hmenu, NULL);
654 return TRUE;
657 /*************************************************************************
658 * FileMenu_HandleMenuChar [SHELL32.108]
660 LRESULT WINAPI FileMenu_HandleMenuChar(
661 HMENU hMenu,
662 WPARAM wParam)
664 FIXME("%p 0x%08lx\n",hMenu,wParam);
665 return 0;
668 /*************************************************************************
669 * FileMenu_DeleteAllItems [SHELL32.104]
671 * NOTES
672 * exported by name
674 BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
676 MENUITEMINFOW mii;
677 LPFMINFO menudata;
679 int i;
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);
692 if (mii.hSubMenu)
693 FileMenu_Destroy(mii.hSubMenu);
696 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
698 menudata = FM_GetMenuInfo(hmenu);
700 menudata->bInitialized = FALSE;
702 return TRUE;
705 /*************************************************************************
706 * FileMenu_DeleteItemByCmd [SHELL32.117]
709 BOOL WINAPI FileMenu_DeleteItemByCmd (HMENU hMenu, UINT uID)
711 MENUITEMINFOW mii;
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 );
720 if ( mii.hSubMenu )
722 /* FIXME: Do what? */
725 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
726 return TRUE;
729 /*************************************************************************
730 * FileMenu_DeleteItemByIndex [SHELL32.140]
732 BOOL WINAPI FileMenu_DeleteItemByIndex ( HMENU hMenu, UINT uPos)
734 MENUITEMINFOW mii;
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 );
743 if ( mii.hSubMenu )
745 /* FIXME: Do what? */
748 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
749 return TRUE;
752 /*************************************************************************
753 * FileMenu_DeleteItemByFirstID [SHELL32.141]
755 BOOL WINAPI FileMenu_DeleteItemByFirstID(
756 HMENU hMenu,
757 UINT uID)
759 TRACE("%p 0x%08x\n", hMenu, uID);
760 return 0;
763 /*************************************************************************
764 * FileMenu_DeleteSeparator [SHELL32.142]
766 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu)
768 TRACE("%p\n", hMenu);
769 return 0;
772 /*************************************************************************
773 * FileMenu_EnableItemByCmd [SHELL32.143]
775 BOOL WINAPI FileMenu_EnableItemByCmd(
776 HMENU hMenu,
777 UINT uID,
778 BOOL bEnable)
780 TRACE("%p 0x%08x 0x%08x\n", hMenu, uID,bEnable);
781 return 0;
784 /*************************************************************************
785 * FileMenu_GetItemExtent [SHELL32.144]
787 * NOTES
788 * if the menu is too big, entries are getting cut away!!
790 DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos)
791 { RECT rect;
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)
808 { TRACE("\n");
809 bAbortInit = TRUE;
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.
818 * PARAMETERS
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)
824 * RETURNS
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)
840 MENUITEMINFOW mii;
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))
847 return(FALSE);
850 if (mii.fType & MFT_SEPARATOR)
852 return(TRUE);
855 return(FALSE);
858 /*************************************************************************
859 * Shell_MergeMenus [SHELL32.67]
861 HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
862 { int nItem;
863 HMENU hmSubMenu;
864 BOOL bAlreadySeparated;
865 MENUITEMINFOW miiSrc;
866 WCHAR szName[256];
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)
873 { return uIDMax;
876 nItem = GetMenuItemCount(hmDst);
878 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
880 uInsert = (UINT)nItem; /* append on the end */
881 bAlreadySeparated = TRUE;
883 else
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))
910 continue;
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)
919 continue;
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 */
930 continue;
932 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
933 uIDMax = miiSrc.wID + 1;
935 else
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);
947 if (uIDMax <= uTemp)
948 uIDMax = uTemp;
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 */
957 continue;
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))
969 return(uIDMax);
973 /* Ensure the correct number of separators at the beginning of the
974 inserted menu items*/
975 if (uInsert == 0)
977 if (bAlreadySeparated)
979 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
982 else
984 if (_SHIsMenuSeparator(hmDst, uInsert-1))
986 if (bAlreadySeparated)
988 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
991 else
993 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
995 /* Add a separator between the menus*/
996 InsertMenuW(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
1000 return(uIDMax);