Break out all the file related actions and helper functions into
[wine/multimedia.git] / dlls / shell32 / shlmenu.c
blobea245f2a864a9ef866d1bc75492a7ca3e27b1fdb
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
35 #include "shlguid.h"
37 #include "pidl.h"
38 #include "wine/debug.h"
40 #ifdef FM_SEPARATOR
41 #undef FM_SEPARATOR
42 #endif
43 #define FM_SEPARATOR (LPCWSTR)1
45 static BOOL FileMenu_AppendItemW(HMENU hMenu, LPCWSTR lpText, UINT uID, int icon,
46 HMENU hMenuPopup, int nItemHeight);
48 typedef struct
50 BOOL bInitialized;
51 BOOL bFixedItems;
52 /* create */
53 COLORREF crBorderColor;
54 int nBorderWidth;
55 HBITMAP hBorderBmp;
57 /* insert using pidl */
58 LPITEMIDLIST pidl;
59 UINT uID;
60 UINT uFlags;
61 UINT uEnumFlags;
62 LPFNFMCALLBACK lpfnCallback;
63 } FMINFO, *LPFMINFO;
65 typedef struct
66 { int cchItemText;
67 int iIconIndex;
68 HMENU hMenu;
69 WCHAR szItemText[1];
70 } FMITEM, * LPFMITEM;
72 static BOOL bAbortInit;
74 #define CCH_MAXITEMTEXT 256
76 WINE_DEFAULT_DEBUG_CHANNEL(shell);
78 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 %lu\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 if ( menudata->pidl)
118 { SHFree(menudata->pidl);
121 menudata->uID = uID;
122 menudata->pidl = ILClone(pidl);
123 menudata->uFlags = uFlags;
124 menudata->uEnumFlags = uEnumFlags;
125 menudata->lpfnCallback = lpfnCallback;
127 return menudata;
130 /*************************************************************************
131 * FM_InitMenuPopup [internal]
134 static int FM_InitMenuPopup(HMENU hmenu, LPCITEMIDLIST pAlternatePidl)
135 { IShellFolder *lpsf, *lpsf2;
136 ULONG ulItemAttr = SFGAO_FOLDER;
137 UINT uID, uFlags, uEnumFlags;
138 LPFNFMCALLBACK lpfnCallback;
139 LPCITEMIDLIST pidl;
140 WCHAR sTemp[MAX_PATH];
141 int NumberOfItems = 0, iIcon;
142 MENUINFO MenuInfo;
143 LPFMINFO menudata;
145 TRACE("%p %p\n", hmenu, pAlternatePidl);
147 MenuInfo.cbSize = sizeof(MENUINFO);
148 MenuInfo.fMask = MIM_MENUDATA;
150 if (! GetMenuInfo(hmenu, &MenuInfo))
151 return FALSE;
153 menudata = (LPFMINFO)MenuInfo.dwMenuData;
155 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
157 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
158 return 0;
161 if (menudata->bInitialized)
162 return 0;
164 pidl = (pAlternatePidl? pAlternatePidl: menudata->pidl);
165 if (!pidl)
166 return 0;
168 uID = menudata->uID;
169 uFlags = menudata->uFlags;
170 uEnumFlags = menudata->uEnumFlags;
171 lpfnCallback = menudata->lpfnCallback;
172 menudata->bInitialized = FALSE;
174 SetMenuInfo(hmenu, &MenuInfo);
176 if (SUCCEEDED (SHGetDesktopFolder(&lpsf)))
178 if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
180 IEnumIDList *lpe = NULL;
182 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe )))
185 LPITEMIDLIST pidlTemp = NULL;
186 ULONG ulFetched;
188 while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)))
190 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, (LPCITEMIDLIST*)&pidlTemp, &ulItemAttr)))
192 ILGetDisplayNameExW(NULL, pidlTemp, sTemp, ILGDN_FORPARSING);
193 if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon)))
194 iIcon = FM_BLANK_ICON;
195 if ( SFGAO_FOLDER & ulItemAttr)
197 LPFMINFO lpFmMi;
198 MENUINFO MenuInfo;
199 HMENU hMenuPopup = CreatePopupMenu();
201 lpFmMi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
203 lpFmMi->pidl = ILCombine(pidl, pidlTemp);
204 lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
206 MenuInfo.cbSize = sizeof(MENUINFO);
207 MenuInfo.fMask = MIM_MENUDATA;
208 MenuInfo.dwMenuData = (DWORD) lpFmMi;
209 SetMenuInfo (hMenuPopup, &MenuInfo);
211 FileMenu_AppendItemW (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT);
213 else
215 LPWSTR pExt = PathFindExtensionW(sTemp);
216 if (pExt)
217 *pExt = 0;
218 FileMenu_AppendItemW (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
222 if (lpfnCallback)
224 TRACE("enter callback\n");
225 lpfnCallback ( pidl, pidlTemp);
226 TRACE("leave callback\n");
229 NumberOfItems++;
231 IEnumIDList_Release (lpe);
233 IShellFolder_Release(lpsf2);
235 IShellFolder_Release(lpsf);
238 if ( GetMenuItemCount (hmenu) == 0 )
240 static const WCHAR szEmpty[] = { '(','e','m','p','t','y',')',0 };
241 FileMenu_AppendItemW (hmenu, szEmpty, uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
242 NumberOfItems++;
245 menudata->bInitialized = TRUE;
246 SetMenuInfo(hmenu, &MenuInfo);
248 return NumberOfItems;
250 /*************************************************************************
251 * FileMenu_Create [SHELL32.114]
253 * NOTES
254 * for non-root menus values are
255 * (ffffffff,00000000,00000000,00000000,00000000)
257 HMENU WINAPI FileMenu_Create (
258 COLORREF crBorderColor,
259 int nBorderWidth,
260 HBITMAP hBorderBmp,
261 int nSelHeight,
262 UINT uFlags)
264 MENUINFO MenuInfo;
265 LPFMINFO menudata;
267 HMENU hMenu = CreatePopupMenu();
269 TRACE("0x%08lx 0x%08x %p 0x%08x 0x%08x hMenu=%p\n",
270 crBorderColor, nBorderWidth, hBorderBmp, nSelHeight, uFlags, hMenu);
272 menudata = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
273 menudata->crBorderColor = crBorderColor;
274 menudata->nBorderWidth = nBorderWidth;
275 menudata->hBorderBmp = hBorderBmp;
277 MenuInfo.cbSize = sizeof(MENUINFO);
278 MenuInfo.fMask = MIM_MENUDATA;
279 MenuInfo.dwMenuData = (DWORD) menudata;
280 SetMenuInfo (hMenu, &MenuInfo);
282 return hMenu;
285 /*************************************************************************
286 * FileMenu_Destroy [SHELL32.118]
288 * NOTES
289 * exported by name
291 void WINAPI FileMenu_Destroy (HMENU hmenu)
293 LPFMINFO menudata;
295 TRACE("%p\n", hmenu);
297 FileMenu_DeleteAllItems (hmenu);
299 menudata = FM_GetMenuInfo(hmenu);
301 if ( menudata->pidl)
302 { SHFree( menudata->pidl);
304 HeapFree(GetProcessHeap(), 0, menudata);
306 DestroyMenu (hmenu);
309 /*************************************************************************
310 * FileMenu_AppendItem [SHELL32.115]
313 static BOOL FileMenu_AppendItemW(
314 HMENU hMenu,
315 LPCWSTR lpText,
316 UINT uID,
317 int icon,
318 HMENU hMenuPopup,
319 int nItemHeight)
321 MENUITEMINFOW mii;
322 LPFMITEM myItem;
323 LPFMINFO menudata;
324 MENUINFO MenuInfo;
327 TRACE("%p %s 0x%08x 0x%08x %p 0x%08x\n",
328 hMenu, (lpText!=FM_SEPARATOR) ? debugstr_w(lpText) : NULL,
329 uID, icon, hMenuPopup, nItemHeight);
331 ZeroMemory (&mii, sizeof(MENUITEMINFOW));
333 mii.cbSize = sizeof(MENUITEMINFOW);
335 if (lpText != FM_SEPARATOR)
337 int len = strlenW (lpText);
338 myItem = (LPFMITEM) SHAlloc( sizeof(FMITEM) + len*sizeof(WCHAR));
339 strcpyW (myItem->szItemText, lpText);
340 myItem->cchItemText = len;
341 myItem->iIconIndex = icon;
342 myItem->hMenu = hMenu;
343 mii.fMask = MIIM_DATA;
344 mii.dwItemData = (DWORD) myItem;
347 if ( hMenuPopup )
348 { /* sub menu */
349 mii.fMask |= MIIM_TYPE | MIIM_SUBMENU;
350 mii.fType = MFT_OWNERDRAW;
351 mii.hSubMenu = hMenuPopup;
353 else if (lpText == FM_SEPARATOR )
354 { mii.fMask |= MIIM_ID | MIIM_TYPE;
355 mii.fType = MFT_SEPARATOR;
357 else
358 { /* normal item */
359 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
360 mii.fState = MFS_ENABLED | MFS_DEFAULT;
361 mii.fType = MFT_OWNERDRAW;
363 mii.wID = uID;
365 InsertMenuItemW (hMenu, (UINT)-1, TRUE, &mii);
367 /* set bFixedItems to true */
368 MenuInfo.cbSize = sizeof(MENUINFO);
369 MenuInfo.fMask = MIM_MENUDATA;
371 if (! GetMenuInfo(hMenu, &MenuInfo))
372 return FALSE;
374 menudata = (LPFMINFO)MenuInfo.dwMenuData;
375 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
377 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
378 return 0;
381 menudata->bFixedItems = TRUE;
382 SetMenuInfo(hMenu, &MenuInfo);
384 return TRUE;
388 /**********************************************************************/
390 BOOL WINAPI FileMenu_AppendItemAW(
391 HMENU hMenu,
392 LPCVOID lpText,
393 UINT uID,
394 int icon,
395 HMENU hMenuPopup,
396 int nItemHeight)
398 BOOL ret;
400 if ((SHELL_OsIsUnicode() && (lpText!=FM_SEPARATOR)) || (lpText == NULL))
401 ret = FileMenu_AppendItemW(hMenu, lpText, uID, icon, hMenuPopup, nItemHeight);
402 else
404 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpText, -1, NULL, 0 );
405 LPWSTR lpszText = HeapAlloc ( GetProcessHeap(), 0, len*sizeof(WCHAR) );
406 MultiByteToWideChar( CP_ACP, 0, lpText, -1, lpszText, len );
407 ret = FileMenu_AppendItemW(hMenu, lpszText, uID, icon, hMenuPopup, nItemHeight);
408 HeapFree( GetProcessHeap(), 0, lpszText );
411 return ret;
413 /*************************************************************************
414 * FileMenu_InsertUsingPidl [SHELL32.110]
416 * NOTES
417 * uEnumFlags any SHCONTF flag
419 int WINAPI FileMenu_InsertUsingPidl (
420 HMENU hmenu,
421 UINT uID,
422 LPCITEMIDLIST pidl,
423 UINT uFlags,
424 UINT uEnumFlags,
425 LPFNFMCALLBACK lpfnCallback)
427 TRACE("%p 0x%08x %p 0x%08x 0x%08x %p\n",
428 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
430 pdump (pidl);
432 bAbortInit = FALSE;
434 FM_SetMenuParameter(hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
436 return FM_InitMenuPopup(hmenu, NULL);
439 /*************************************************************************
440 * FileMenu_ReplaceUsingPidl [SHELL32.113]
442 * FIXME: the static items are deleted but won't be refreshed
444 int WINAPI FileMenu_ReplaceUsingPidl(
445 HMENU hmenu,
446 UINT uID,
447 LPCITEMIDLIST pidl,
448 UINT uEnumFlags,
449 LPFNFMCALLBACK lpfnCallback)
451 TRACE("%p 0x%08x %p 0x%08x %p\n",
452 hmenu, uID, pidl, uEnumFlags, lpfnCallback);
454 FileMenu_DeleteAllItems (hmenu);
456 FM_SetMenuParameter(hmenu, uID, pidl, 0, uEnumFlags, lpfnCallback);
458 return FM_InitMenuPopup(hmenu, NULL);
461 /*************************************************************************
462 * FileMenu_Invalidate [SHELL32.111]
464 void WINAPI FileMenu_Invalidate (HMENU hMenu)
466 FIXME("%p\n",hMenu);
469 /*************************************************************************
470 * FileMenu_FindSubMenuByPidl [SHELL32.106]
472 HMENU WINAPI FileMenu_FindSubMenuByPidl(
473 HMENU hMenu,
474 LPCITEMIDLIST pidl)
476 FIXME("%p %p\n",hMenu, pidl);
477 return 0;
480 /*************************************************************************
481 * FileMenu_AppendFilesForPidl [SHELL32.124]
483 int WINAPI FileMenu_AppendFilesForPidl(
484 HMENU hmenu,
485 LPCITEMIDLIST pidl,
486 BOOL bAddSeperator)
488 LPFMINFO menudata;
490 menudata = FM_GetMenuInfo(hmenu);
492 menudata->bInitialized = FALSE;
494 FM_InitMenuPopup(hmenu, pidl);
496 if (bAddSeperator)
497 FileMenu_AppendItemW (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
499 TRACE("%p %p 0x%08x\n",hmenu, pidl,bAddSeperator);
501 return 0;
503 /*************************************************************************
504 * FileMenu_AddFilesForPidl [SHELL32.125]
506 * NOTES
507 * uEnumFlags any SHCONTF flag
509 int WINAPI FileMenu_AddFilesForPidl (
510 HMENU hmenu,
511 UINT uReserved,
512 UINT uID,
513 LPCITEMIDLIST pidl,
514 UINT uFlags,
515 UINT uEnumFlags,
516 LPFNFMCALLBACK lpfnCallback)
518 TRACE("%p 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
519 hmenu, uReserved, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
521 return FileMenu_InsertUsingPidl ( hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
526 /*************************************************************************
527 * FileMenu_TrackPopupMenuEx [SHELL32.116]
529 BOOL WINAPI FileMenu_TrackPopupMenuEx (
530 HMENU hMenu,
531 UINT uFlags,
532 int x,
533 int y,
534 HWND hWnd,
535 LPTPMPARAMS lptpm)
537 TRACE("%p 0x%08x 0x%x 0x%x %p %p\n",
538 hMenu, uFlags, x, y, hWnd, lptpm);
539 return TrackPopupMenuEx(hMenu, uFlags, x, y, hWnd, lptpm);
542 /*************************************************************************
543 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
545 BOOL WINAPI FileMenu_GetLastSelectedItemPidls(
546 UINT uReserved,
547 LPCITEMIDLIST *ppidlFolder,
548 LPCITEMIDLIST *ppidlItem)
550 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
551 return 0;
554 #define FM_ICON_SIZE 16
555 #define FM_Y_SPACE 4
556 #define FM_SPACE1 4
557 #define FM_SPACE2 2
558 #define FM_LEFTBORDER 2
559 #define FM_RIGHTBORDER 8
560 /*************************************************************************
561 * FileMenu_MeasureItem [SHELL32.112]
563 LRESULT WINAPI FileMenu_MeasureItem(
564 HWND hWnd,
565 LPMEASUREITEMSTRUCT lpmis)
567 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
568 HDC hdc = GetDC(hWnd);
569 SIZE size;
570 LPFMINFO menuinfo;
572 TRACE("%p %p %s\n", hWnd, lpmis, debugstr_w(pMyItem->szItemText));
574 GetTextExtentPoint32W(hdc, pMyItem->szItemText, pMyItem->cchItemText, &size);
576 lpmis->itemWidth = size.cx + FM_LEFTBORDER + FM_ICON_SIZE + FM_SPACE1 + FM_SPACE2 + FM_RIGHTBORDER;
577 lpmis->itemHeight = (size.cy > (FM_ICON_SIZE + FM_Y_SPACE)) ? size.cy : (FM_ICON_SIZE + FM_Y_SPACE);
579 /* add the menubitmap */
580 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
581 if (menuinfo->nBorderWidth)
582 lpmis->itemWidth += menuinfo->nBorderWidth;
584 TRACE("-- 0x%04x 0x%04x\n", lpmis->itemWidth, lpmis->itemHeight);
585 ReleaseDC (hWnd, hdc);
586 return 0;
588 /*************************************************************************
589 * FileMenu_DrawItem [SHELL32.105]
591 LRESULT WINAPI FileMenu_DrawItem(
592 HWND hWnd,
593 LPDRAWITEMSTRUCT lpdis)
595 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
596 COLORREF clrPrevText, clrPrevBkgnd;
597 int xi,yi,xt,yt;
598 HIMAGELIST hImageList;
599 RECT TextRect, BorderRect;
600 LPFMINFO menuinfo;
602 TRACE("%p %p %s\n", hWnd, lpdis, debugstr_w(pMyItem->szItemText));
604 if (lpdis->itemState & ODS_SELECTED)
606 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
607 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
609 else
611 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_MENUTEXT));
612 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_MENU));
615 CopyRect(&TextRect, &(lpdis->rcItem));
617 /* add the menubitmap */
618 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
619 if (menuinfo->nBorderWidth)
620 TextRect.left += menuinfo->nBorderWidth;
622 BorderRect.right = menuinfo->nBorderWidth;
623 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
625 TextRect.left += FM_LEFTBORDER;
626 xi = TextRect.left + FM_SPACE1;
627 yi = TextRect.top + FM_Y_SPACE/2;
628 TextRect.bottom -= FM_Y_SPACE/2;
630 xt = xi + FM_ICON_SIZE + FM_SPACE2;
631 yt = yi;
633 ExtTextOutW (lpdis->hDC, xt , yt, ETO_OPAQUE, &TextRect, pMyItem->szItemText, pMyItem->cchItemText, NULL);
635 Shell_GetImageList(0, &hImageList);
636 ImageList_Draw(hImageList, pMyItem->iIconIndex, lpdis->hDC, xi, yi, ILD_NORMAL);
638 TRACE("-- 0x%04lx 0x%04lx 0x%04lx 0x%04lx\n", TextRect.left, TextRect.top, TextRect.right, TextRect.bottom);
640 SetTextColor(lpdis->hDC, clrPrevText);
641 SetBkColor(lpdis->hDC, clrPrevBkgnd);
643 return TRUE;
646 /*************************************************************************
647 * FileMenu_InitMenuPopup [SHELL32.109]
649 * NOTES
650 * The filemenu is an ownerdrawn menu. Call this function responding to
651 * WM_INITPOPUPMENU
654 BOOL WINAPI FileMenu_InitMenuPopup (HMENU hmenu)
656 FM_InitMenuPopup(hmenu, NULL);
657 return TRUE;
660 /*************************************************************************
661 * FileMenu_HandleMenuChar [SHELL32.108]
663 LRESULT WINAPI FileMenu_HandleMenuChar(
664 HMENU hMenu,
665 WPARAM wParam)
667 FIXME("%p 0x%08x\n",hMenu,wParam);
668 return 0;
671 /*************************************************************************
672 * FileMenu_DeleteAllItems [SHELL32.104]
674 * NOTES
675 * exported by name
677 BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
679 MENUITEMINFOW mii;
680 LPFMINFO menudata;
682 int i;
684 TRACE("%p\n", hmenu);
686 ZeroMemory ( &mii, sizeof(MENUITEMINFOW));
687 mii.cbSize = sizeof(MENUITEMINFOW);
688 mii.fMask = MIIM_SUBMENU|MIIM_DATA;
690 for (i = 0; i < GetMenuItemCount( hmenu ); i++)
691 { GetMenuItemInfoW(hmenu, i, TRUE, &mii );
693 if (mii.dwItemData)
694 SHFree((LPFMINFO)mii.dwItemData);
696 if (mii.hSubMenu)
697 FileMenu_Destroy(mii.hSubMenu);
700 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
702 menudata = FM_GetMenuInfo(hmenu);
704 menudata->bInitialized = FALSE;
706 return TRUE;
709 /*************************************************************************
710 * FileMenu_DeleteItemByCmd [SHELL32.117]
713 BOOL WINAPI FileMenu_DeleteItemByCmd (HMENU hMenu, UINT uID)
715 MENUITEMINFOW mii;
717 TRACE("%p 0x%08x\n", hMenu, uID);
719 ZeroMemory ( &mii, sizeof(MENUITEMINFOW));
720 mii.cbSize = sizeof(MENUITEMINFOW);
721 mii.fMask = MIIM_SUBMENU;
723 GetMenuItemInfoW(hMenu, uID, FALSE, &mii );
724 if ( mii.hSubMenu )
726 /* FIXME: Do what? */
729 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
730 return TRUE;
733 /*************************************************************************
734 * FileMenu_DeleteItemByIndex [SHELL32.140]
736 BOOL WINAPI FileMenu_DeleteItemByIndex ( HMENU hMenu, UINT uPos)
738 MENUITEMINFOW mii;
740 TRACE("%p 0x%08x\n", hMenu, uPos);
742 ZeroMemory ( &mii, sizeof(MENUITEMINFOW));
743 mii.cbSize = sizeof(MENUITEMINFOW);
744 mii.fMask = MIIM_SUBMENU;
746 GetMenuItemInfoW(hMenu, uPos, TRUE, &mii );
747 if ( mii.hSubMenu )
749 /* FIXME: Do what? */
752 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
753 return TRUE;
756 /*************************************************************************
757 * FileMenu_DeleteItemByFirstID [SHELL32.141]
759 BOOL WINAPI FileMenu_DeleteItemByFirstID(
760 HMENU hMenu,
761 UINT uID)
763 TRACE("%p 0x%08x\n", hMenu, uID);
764 return 0;
767 /*************************************************************************
768 * FileMenu_DeleteSeparator [SHELL32.142]
770 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu)
772 TRACE("%p\n", hMenu);
773 return 0;
776 /*************************************************************************
777 * FileMenu_EnableItemByCmd [SHELL32.143]
779 BOOL WINAPI FileMenu_EnableItemByCmd(
780 HMENU hMenu,
781 UINT uID,
782 BOOL bEnable)
784 TRACE("%p 0x%08x 0x%08x\n", hMenu, uID,bEnable);
785 return 0;
788 /*************************************************************************
789 * FileMenu_GetItemExtent [SHELL32.144]
791 * NOTES
792 * if the menu is too big, entries are getting cut away!!
794 DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos)
795 { RECT rect;
797 FIXME("%p 0x%08x\n", hMenu, uPos);
799 if (GetMenuItemRect(0, hMenu, uPos, &rect))
800 { FIXME("0x%04lx 0x%04lx 0x%04lx 0x%04lx\n",
801 rect.right, rect.left, rect.top, rect.bottom);
802 return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom);
804 return 0x00100010; /*FIXME*/
807 /*************************************************************************
808 * FileMenu_AbortInitMenu [SHELL32.120]
811 void WINAPI FileMenu_AbortInitMenu (void)
812 { TRACE("\n");
813 bAbortInit = TRUE;
816 /*************************************************************************
817 * SHFind_InitMenuPopup [SHELL32.149]
820 * PARAMETERS
821 * hMenu [in] handle of menu previously created
822 * hWndParent [in] parent window
823 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
824 * x [in] no pointer (0x226 over here)
826 * RETURNS
827 * LPXXXXX pointer to struct containing a func addr at offset 8
828 * or NULL at failure.
830 LPVOID WINAPI SHFind_InitMenuPopup (HMENU hMenu, HWND hWndParent, DWORD w, DWORD x)
831 { FIXME("hmenu=%p hwnd=%p 0x%08lx 0x%08lx stub\n",
832 hMenu,hWndParent,w,x);
833 return NULL; /* this is supposed to be a pointer */
836 /*************************************************************************
837 * Shell_MergeMenus [SHELL32.67]
840 BOOL _SHIsMenuSeparator(HMENU hm, int i)
842 MENUITEMINFOW mii;
844 mii.cbSize = sizeof(MENUITEMINFOW);
845 mii.fMask = MIIM_TYPE;
846 mii.cch = 0; /* WARNING: We MUST initialize it to 0*/
847 if (!GetMenuItemInfoW(hm, i, TRUE, &mii))
849 return(FALSE);
852 if (mii.fType & MFT_SEPARATOR)
854 return(TRUE);
857 return(FALSE);
860 /**********************************************************************/
862 HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
863 { int nItem;
864 HMENU hmSubMenu;
865 BOOL bAlreadySeparated;
866 MENUITEMINFOW miiSrc;
867 WCHAR szName[256];
868 UINT uTemp, uIDMax = uIDAdjust;
870 TRACE("hmenu1=%p hmenu2=%p 0x%04x 0x%04x 0x%04x 0x%04lx\n",
871 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
873 if (!hmDst || !hmSrc)
874 { return uIDMax;
877 nItem = GetMenuItemCount(hmDst);
879 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
881 uInsert = (UINT)nItem; /* append on the end */
882 bAlreadySeparated = TRUE;
884 else
886 bAlreadySeparated = _SHIsMenuSeparator(hmDst, uInsert);
889 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
891 /* Add a separator between the menus */
892 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
893 bAlreadySeparated = TRUE;
897 /* Go through the menu items and clone them*/
898 for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
900 miiSrc.cbSize = sizeof(MENUITEMINFOW);
901 miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
903 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
904 miiSrc.fType = MFT_STRING;
905 miiSrc.dwTypeData = szName;
906 miiSrc.dwItemData = 0;
907 miiSrc.cch = sizeof(szName)/sizeof(WCHAR);
909 if (!GetMenuItemInfoW(hmSrc, nItem, TRUE, &miiSrc))
911 continue;
914 /* 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);
916 if (miiSrc.fType & MFT_SEPARATOR)
918 /* This is a separator; don't put two of them in a row */
919 if (bAlreadySeparated)
920 continue;
922 bAlreadySeparated = TRUE;
924 else if (miiSrc.hSubMenu)
926 if (uFlags & MM_SUBMENUSHAVEIDS)
928 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
930 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
931 continue;
933 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
934 uIDMax = miiSrc.wID + 1;
936 else
938 miiSrc.fMask &= ~MIIM_ID; /* Don't set IDs for submenus that didn't have them already */
940 hmSubMenu = miiSrc.hSubMenu;
942 miiSrc.hSubMenu = CreatePopupMenu();
944 if (!miiSrc.hSubMenu) return(uIDMax);
946 uTemp = Shell_MergeMenus(miiSrc.hSubMenu, hmSubMenu, 0, uIDAdjust, uIDAdjustMax, uFlags & MM_SUBMENUSHAVEIDS);
948 if (uIDMax <= uTemp)
949 uIDMax = uTemp;
951 bAlreadySeparated = FALSE;
953 else /* normal menu item */
955 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
957 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
958 continue;
960 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
961 uIDMax = miiSrc.wID + 1;
963 bAlreadySeparated = FALSE;
966 /* 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);
968 if (!InsertMenuItemW(hmDst, uInsert, TRUE, &miiSrc))
970 return(uIDMax);
974 /* Ensure the correct number of separators at the beginning of the
975 inserted menu items*/
976 if (uInsert == 0)
978 if (bAlreadySeparated)
980 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
983 else
985 if (_SHIsMenuSeparator(hmDst, uInsert-1))
987 if (bAlreadySeparated)
989 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
992 else
994 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
996 /* Add a separator between the menus*/
997 InsertMenuW(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
1001 return(uIDMax);