Avoid crashing when releasing an NdrCStdStubBuffer that had been
[wine/dcerpc.git] / dlls / shell32 / shlmenu.c
blobb81ac3b0272915152caaa253dd059ecf0bcc46cb
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 <string.h>
23 #include "winreg.h"
24 #include "shlobj.h"
25 #include "wine/obj_base.h"
26 #include "wine/obj_enumidlist.h"
27 #include "wine/obj_shellfolder.h"
28 #include "undocshell.h"
29 #include "shlwapi.h"
30 #include "heap.h"
31 #include "shell32_main.h"
32 #include "shlguid.h"
34 #include "pidl.h"
35 #include "wine/debug.h"
37 static BOOL FileMenu_AppendItemA(HMENU hMenu, LPCSTR lpText, UINT uID, int icon,
38 HMENU hMenuPopup, int nItemHeight);
40 typedef struct
42 BOOL bInitialized;
43 BOOL bFixedItems;
44 /* create */
45 COLORREF crBorderColor;
46 int nBorderWidth;
47 HBITMAP hBorderBmp;
49 /* insert using pidl */
50 LPITEMIDLIST pidl;
51 UINT uID;
52 UINT uFlags;
53 UINT uEnumFlags;
54 LPFNFMCALLBACK lpfnCallback;
55 } FMINFO, *LPFMINFO;
57 typedef struct
58 { int cchItemText;
59 int iIconIndex;
60 HMENU hMenu;
61 char szItemText[1];
62 } FMITEM, * LPFMITEM;
64 static BOOL bAbortInit;
66 #define CCH_MAXITEMTEXT 256
68 WINE_DEFAULT_DEBUG_CHANNEL(shell);
70 LPFMINFO FM_GetMenuInfo(HMENU hmenu)
71 { MENUINFO MenuInfo;
72 LPFMINFO menudata;
74 MenuInfo.cbSize = sizeof(MENUINFO);
75 MenuInfo.fMask = MIM_MENUDATA;
77 if (! GetMenuInfo(hmenu, &MenuInfo))
78 return NULL;
80 menudata = (LPFMINFO)MenuInfo.dwMenuData;
82 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
84 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
85 return 0;
88 return menudata;
91 /*************************************************************************
92 * FM_SetMenuParameter [internal]
95 static LPFMINFO FM_SetMenuParameter(
96 HMENU hmenu,
97 UINT uID,
98 LPCITEMIDLIST pidl,
99 UINT uFlags,
100 UINT uEnumFlags,
101 LPFNFMCALLBACK lpfnCallback)
103 LPFMINFO menudata;
105 TRACE("\n");
107 menudata = FM_GetMenuInfo(hmenu);
109 if ( menudata->pidl)
110 { SHFree(menudata->pidl);
113 menudata->uID = uID;
114 menudata->pidl = ILClone(pidl);
115 menudata->uFlags = uFlags;
116 menudata->uEnumFlags = uEnumFlags;
117 menudata->lpfnCallback = lpfnCallback;
119 return menudata;
122 /*************************************************************************
123 * FM_InitMenuPopup [internal]
126 static int FM_InitMenuPopup(HMENU hmenu, LPITEMIDLIST pAlternatePidl)
127 { IShellFolder *lpsf, *lpsf2;
128 ULONG ulItemAttr = SFGAO_FOLDER;
129 UINT uID, uFlags, uEnumFlags;
130 LPFNFMCALLBACK lpfnCallback;
131 LPITEMIDLIST pidl;
132 char sTemp[MAX_PATH];
133 int NumberOfItems = 0, iIcon;
134 MENUINFO MenuInfo;
135 LPFMINFO menudata;
137 TRACE("0x%04x %p\n", hmenu, pAlternatePidl);
139 MenuInfo.cbSize = sizeof(MENUINFO);
140 MenuInfo.fMask = MIM_MENUDATA;
142 if (! GetMenuInfo(hmenu, &MenuInfo))
143 return FALSE;
145 menudata = (LPFMINFO)MenuInfo.dwMenuData;
147 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
149 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
150 return 0;
153 if (menudata->bInitialized)
154 return 0;
156 pidl = ((pAlternatePidl) ? pAlternatePidl : menudata->pidl);
157 if (!pidl)
158 return 0;
160 uID = menudata->uID;
161 uFlags = menudata->uFlags;
162 uEnumFlags = menudata->uEnumFlags;
163 lpfnCallback = menudata->lpfnCallback;
164 menudata->bInitialized = FALSE;
166 SetMenuInfo(hmenu, &MenuInfo);
168 if (SUCCEEDED (SHGetDesktopFolder(&lpsf)))
170 if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
172 IEnumIDList *lpe = NULL;
174 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe )))
177 LPITEMIDLIST pidlTemp = NULL;
178 ULONG ulFetched;
180 while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)))
182 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulItemAttr)))
184 ILGetDisplayName( pidlTemp, sTemp);
185 if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, 0, &iIcon)))
186 iIcon = FM_BLANK_ICON;
187 if ( SFGAO_FOLDER & ulItemAttr)
189 LPFMINFO lpFmMi;
190 MENUINFO MenuInfo;
191 HMENU hMenuPopup = CreatePopupMenu();
193 lpFmMi = (LPFMINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
195 lpFmMi->pidl = ILCombine(pidl, pidlTemp);
196 lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
198 MenuInfo.cbSize = sizeof(MENUINFO);
199 MenuInfo.fMask = MIM_MENUDATA;
200 MenuInfo.dwMenuData = (DWORD) lpFmMi;
201 SetMenuInfo (hMenuPopup, &MenuInfo);
203 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT);
205 else
207 ((LPSTR)PathFindExtensionA(sTemp))[0] = 0x00;
208 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
212 if (lpfnCallback)
214 TRACE("enter callback\n");
215 lpfnCallback ( pidl, pidlTemp);
216 TRACE("leave callback\n");
219 NumberOfItems++;
221 IEnumIDList_Release (lpe);
223 IShellFolder_Release(lpsf2);
225 IShellFolder_Release(lpsf);
228 if ( GetMenuItemCount (hmenu) == 0 )
229 { FileMenu_AppendItemA (hmenu, "(empty)", uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
230 NumberOfItems++;
233 menudata->bInitialized = TRUE;
234 SetMenuInfo(hmenu, &MenuInfo);
236 return NumberOfItems;
238 /*************************************************************************
239 * FileMenu_Create [SHELL32.114]
241 * NOTES
242 * for non-root menus values are
243 * (ffffffff,00000000,00000000,00000000,00000000)
245 HMENU WINAPI FileMenu_Create (
246 COLORREF crBorderColor,
247 int nBorderWidth,
248 HBITMAP hBorderBmp,
249 int nSelHeight,
250 UINT uFlags)
252 MENUINFO MenuInfo;
253 LPFMINFO menudata;
255 HMENU hMenu = CreatePopupMenu();
257 TRACE("0x%08lx 0x%08x 0x%08x 0x%08x 0x%08x hMenu=0x%08x\n",
258 crBorderColor, nBorderWidth, hBorderBmp, nSelHeight, uFlags, hMenu);
260 menudata = (LPFMINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
261 menudata->crBorderColor = crBorderColor;
262 menudata->nBorderWidth = nBorderWidth;
263 menudata->hBorderBmp = hBorderBmp;
265 MenuInfo.cbSize = sizeof(MENUINFO);
266 MenuInfo.fMask = MIM_MENUDATA;
267 MenuInfo.dwMenuData = (DWORD) menudata;
268 SetMenuInfo (hMenu, &MenuInfo);
270 return hMenu;
273 /*************************************************************************
274 * FileMenu_Destroy [SHELL32.118]
276 * NOTES
277 * exported by name
279 void WINAPI FileMenu_Destroy (HMENU hmenu)
281 LPFMINFO menudata;
283 TRACE("0x%08x\n", hmenu);
285 FileMenu_DeleteAllItems (hmenu);
287 menudata = FM_GetMenuInfo(hmenu);
289 if ( menudata->pidl)
290 { SHFree( menudata->pidl);
292 HeapFree(GetProcessHeap(), 0, menudata);
294 DestroyMenu (hmenu);
297 /*************************************************************************
298 * FileMenu_AppendItem [SHELL32.115]
301 static BOOL FileMenu_AppendItemA(
302 HMENU hMenu,
303 LPCSTR lpText,
304 UINT uID,
305 int icon,
306 HMENU hMenuPopup,
307 int nItemHeight)
309 LPSTR lpszText = (LPSTR)lpText;
310 MENUITEMINFOA mii;
311 LPFMITEM myItem;
312 LPFMINFO menudata;
313 MENUINFO MenuInfo;
316 TRACE("0x%08x %s 0x%08x 0x%08x 0x%08x 0x%08x\n",
317 hMenu, (lpszText!=FM_SEPARATOR) ? lpText: NULL,
318 uID, icon, hMenuPopup, nItemHeight);
320 ZeroMemory (&mii, sizeof(MENUITEMINFOA));
322 mii.cbSize = sizeof(MENUITEMINFOA);
324 if (lpText != FM_SEPARATOR)
325 { int len = strlen (lpText);
326 myItem = (LPFMITEM) SHAlloc( sizeof(FMITEM) + len);
327 strcpy (myItem->szItemText, lpText);
328 myItem->cchItemText = len;
329 myItem->iIconIndex = icon;
330 myItem->hMenu = hMenu;
331 mii.fMask = MIIM_DATA;
332 mii.dwItemData = (DWORD) myItem;
335 if ( hMenuPopup )
336 { /* sub menu */
337 mii.fMask |= MIIM_TYPE | MIIM_SUBMENU;
338 mii.fType = MFT_OWNERDRAW;
339 mii.hSubMenu = hMenuPopup;
341 else if (lpText == FM_SEPARATOR )
342 { mii.fMask |= MIIM_ID | MIIM_TYPE;
343 mii.fType = MFT_SEPARATOR;
345 else
346 { /* normal item */
347 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
348 mii.fState = MFS_ENABLED | MFS_DEFAULT;
349 mii.fType = MFT_OWNERDRAW;
351 mii.wID = uID;
353 InsertMenuItemA (hMenu, (UINT)-1, TRUE, &mii);
355 /* set bFixedItems to true */
356 MenuInfo.cbSize = sizeof(MENUINFO);
357 MenuInfo.fMask = MIM_MENUDATA;
359 if (! GetMenuInfo(hMenu, &MenuInfo))
360 return FALSE;
362 menudata = (LPFMINFO)MenuInfo.dwMenuData;
363 if ((menudata == 0) || (MenuInfo.cbSize != sizeof(MENUINFO)))
365 ERR("menudata corrupt: %p %lu\n", menudata, MenuInfo.cbSize);
366 return 0;
369 menudata->bFixedItems = TRUE;
370 SetMenuInfo(hMenu, &MenuInfo);
372 return TRUE;
376 /**********************************************************************/
378 BOOL WINAPI FileMenu_AppendItemAW(
379 HMENU hMenu,
380 LPCVOID lpText,
381 UINT uID,
382 int icon,
383 HMENU hMenuPopup,
384 int nItemHeight)
386 BOOL ret;
387 LPSTR lpszText=NULL;
389 if (SHELL_OsIsUnicode() && (lpText!=FM_SEPARATOR))
390 lpszText = HEAP_strdupWtoA ( GetProcessHeap(),0, lpText);
392 ret = FileMenu_AppendItemA(hMenu, (lpszText) ? lpszText : lpText, uID, icon, hMenuPopup, nItemHeight);
394 if (lpszText)
395 HeapFree( GetProcessHeap(), 0, lpszText );
397 return ret;
399 /*************************************************************************
400 * FileMenu_InsertUsingPidl [SHELL32.110]
402 * NOTES
403 * uEnumFlags any SHCONTF flag
405 int WINAPI FileMenu_InsertUsingPidl (
406 HMENU hmenu,
407 UINT uID,
408 LPCITEMIDLIST pidl,
409 UINT uFlags,
410 UINT uEnumFlags,
411 LPFNFMCALLBACK lpfnCallback)
413 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
414 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
416 pdump (pidl);
418 bAbortInit = FALSE;
420 FM_SetMenuParameter(hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
422 return FM_InitMenuPopup(hmenu, NULL);
425 /*************************************************************************
426 * FileMenu_ReplaceUsingPidl [SHELL32.113]
428 * FIXME: the static items are deleted but wont be refreshed
430 int WINAPI FileMenu_ReplaceUsingPidl(
431 HMENU hmenu,
432 UINT uID,
433 LPCITEMIDLIST pidl,
434 UINT uEnumFlags,
435 LPFNFMCALLBACK lpfnCallback)
437 TRACE("0x%08x 0x%08x %p 0x%08x %p\n",
438 hmenu, uID, pidl, uEnumFlags, lpfnCallback);
440 FileMenu_DeleteAllItems (hmenu);
442 FM_SetMenuParameter(hmenu, uID, pidl, 0, uEnumFlags, lpfnCallback);
444 return FM_InitMenuPopup(hmenu, NULL);
447 /*************************************************************************
448 * FileMenu_Invalidate [SHELL32.111]
450 void WINAPI FileMenu_Invalidate (HMENU hMenu)
452 FIXME("0x%08x\n",hMenu);
455 /*************************************************************************
456 * FileMenu_FindSubMenuByPidl [SHELL32.106]
458 HMENU WINAPI FileMenu_FindSubMenuByPidl(
459 HMENU hMenu,
460 LPCITEMIDLIST pidl)
462 FIXME("0x%08x %p\n",hMenu, pidl);
463 return 0;
466 /*************************************************************************
467 * FileMenu_AppendFilesForPidl [SHELL32.124]
469 int WINAPI FileMenu_AppendFilesForPidl(
470 HMENU hmenu,
471 LPCITEMIDLIST pidl,
472 BOOL bAddSeperator)
474 LPFMINFO menudata;
476 menudata = FM_GetMenuInfo(hmenu);
478 menudata->bInitialized = FALSE;
480 FM_InitMenuPopup(hmenu, pidl);
482 if (bAddSeperator)
483 FileMenu_AppendItemA (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
485 TRACE("0x%08x %p 0x%08x\n",hmenu, pidl,bAddSeperator);
487 return 0;
489 /*************************************************************************
490 * FileMenu_AddFilesForPidl [SHELL32.125]
492 * NOTES
493 * uEnumFlags any SHCONTF flag
495 int WINAPI FileMenu_AddFilesForPidl (
496 HMENU hmenu,
497 UINT uReserved,
498 UINT uID,
499 LPCITEMIDLIST pidl,
500 UINT uFlags,
501 UINT uEnumFlags,
502 LPFNFMCALLBACK lpfnCallback)
504 TRACE("0x%08x 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
505 hmenu, uReserved, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
507 return FileMenu_InsertUsingPidl ( hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
512 /*************************************************************************
513 * FileMenu_TrackPopupMenuEx [SHELL32.116]
515 BOOL WINAPI FileMenu_TrackPopupMenuEx (
516 HMENU hMenu,
517 UINT uFlags,
518 int x,
519 int y,
520 HWND hWnd,
521 LPTPMPARAMS lptpm)
523 TRACE("0x%08x 0x%08x 0x%x 0x%x 0x%08x %p\n",
524 hMenu, uFlags, x, y, hWnd, lptpm);
525 return TrackPopupMenuEx(hMenu, uFlags, x, y, hWnd, lptpm);
528 /*************************************************************************
529 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
531 BOOL WINAPI FileMenu_GetLastSelectedItemPidls(
532 UINT uReserved,
533 LPCITEMIDLIST *ppidlFolder,
534 LPCITEMIDLIST *ppidlItem)
536 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
537 return 0;
540 #define FM_ICON_SIZE 16
541 #define FM_Y_SPACE 4
542 #define FM_SPACE1 4
543 #define FM_SPACE2 2
544 #define FM_LEFTBORDER 2
545 #define FM_RIGHTBORDER 8
546 /*************************************************************************
547 * FileMenu_MeasureItem [SHELL32.112]
549 LRESULT WINAPI FileMenu_MeasureItem(
550 HWND hWnd,
551 LPMEASUREITEMSTRUCT lpmis)
553 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
554 HDC hdc = GetDC(hWnd);
555 SIZE size;
556 LPFMINFO menuinfo;
558 TRACE("0x%08x %p %s\n", hWnd, lpmis, pMyItem->szItemText);
560 GetTextExtentPoint32A(hdc, pMyItem->szItemText, pMyItem->cchItemText, &size);
562 lpmis->itemWidth = size.cx + FM_LEFTBORDER + FM_ICON_SIZE + FM_SPACE1 + FM_SPACE2 + FM_RIGHTBORDER;
563 lpmis->itemHeight = (size.cy > (FM_ICON_SIZE + FM_Y_SPACE)) ? size.cy : (FM_ICON_SIZE + FM_Y_SPACE);
565 /* add the menubitmap */
566 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
567 if (menuinfo->nBorderWidth)
568 lpmis->itemWidth += menuinfo->nBorderWidth;
570 TRACE("-- 0x%04x 0x%04x\n", lpmis->itemWidth, lpmis->itemHeight);
571 ReleaseDC (hWnd, hdc);
572 return 0;
574 /*************************************************************************
575 * FileMenu_DrawItem [SHELL32.105]
577 LRESULT WINAPI FileMenu_DrawItem(
578 HWND hWnd,
579 LPDRAWITEMSTRUCT lpdis)
581 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
582 COLORREF clrPrevText, clrPrevBkgnd;
583 int xi,yi,xt,yt;
584 HIMAGELIST hImageList;
585 RECT TextRect, BorderRect;
586 LPFMINFO menuinfo;
588 TRACE("0x%08x %p %s\n", hWnd, lpdis, pMyItem->szItemText);
590 if (lpdis->itemState & ODS_SELECTED)
592 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
593 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
595 else
597 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_MENUTEXT));
598 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_MENU));
601 CopyRect(&TextRect, &(lpdis->rcItem));
603 /* add the menubitmap */
604 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
605 if (menuinfo->nBorderWidth)
606 TextRect.left += menuinfo->nBorderWidth;
608 BorderRect.right = menuinfo->nBorderWidth;
609 /* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
611 TextRect.left += FM_LEFTBORDER;
612 xi = TextRect.left + FM_SPACE1;
613 yi = TextRect.top + FM_Y_SPACE/2;
614 TextRect.bottom -= FM_Y_SPACE/2;
616 xt = xi + FM_ICON_SIZE + FM_SPACE2;
617 yt = yi;
619 ExtTextOutA (lpdis->hDC, xt , yt, ETO_OPAQUE, &TextRect, pMyItem->szItemText, pMyItem->cchItemText, NULL);
621 Shell_GetImageList(0, &hImageList);
622 ImageList_Draw(hImageList, pMyItem->iIconIndex, lpdis->hDC, xi, yi, ILD_NORMAL);
624 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect.left, TextRect.top, TextRect.right, TextRect.bottom);
626 SetTextColor(lpdis->hDC, clrPrevText);
627 SetBkColor(lpdis->hDC, clrPrevBkgnd);
629 return TRUE;
632 /*************************************************************************
633 * FileMenu_InitMenuPopup [SHELL32.109]
635 * NOTES
636 * The filemenu is a ownerdrawn menu. Call this function responding to
637 * WM_INITPOPUPMENU
640 BOOL WINAPI FileMenu_InitMenuPopup (HMENU hmenu)
642 FM_InitMenuPopup(hmenu, NULL);
643 return TRUE;
646 /*************************************************************************
647 * FileMenu_HandleMenuChar [SHELL32.108]
649 LRESULT WINAPI FileMenu_HandleMenuChar(
650 HMENU hMenu,
651 WPARAM wParam)
653 FIXME("0x%08x 0x%08x\n",hMenu,wParam);
654 return 0;
657 /*************************************************************************
658 * FileMenu_DeleteAllItems [SHELL32.104]
660 * NOTES
661 * exported by name
663 BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
665 MENUITEMINFOA mii;
666 LPFMINFO menudata;
668 int i;
670 TRACE("0x%08x\n", hmenu);
672 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
673 mii.cbSize = sizeof(MENUITEMINFOA);
674 mii.fMask = MIIM_SUBMENU|MIIM_DATA;
676 for (i = 0; i < GetMenuItemCount( hmenu ); i++)
677 { GetMenuItemInfoA(hmenu, i, TRUE, &mii );
679 if (mii.dwItemData)
680 SHFree((LPFMINFO)mii.dwItemData);
682 if (mii.hSubMenu)
683 FileMenu_Destroy(mii.hSubMenu);
686 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
688 menudata = FM_GetMenuInfo(hmenu);
690 menudata->bInitialized = FALSE;
692 return TRUE;
695 /*************************************************************************
696 * FileMenu_DeleteItemByCmd [SHELL32.117]
699 BOOL WINAPI FileMenu_DeleteItemByCmd (HMENU hMenu, UINT uID)
701 MENUITEMINFOA mii;
703 TRACE("0x%08x 0x%08x\n", hMenu, uID);
705 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
706 mii.cbSize = sizeof(MENUITEMINFOA);
707 mii.fMask = MIIM_SUBMENU;
709 GetMenuItemInfoA(hMenu, uID, FALSE, &mii );
710 if ( mii.hSubMenu )
712 /* FIXME: Do what? */
715 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
716 return TRUE;
719 /*************************************************************************
720 * FileMenu_DeleteItemByIndex [SHELL32.140]
722 BOOL WINAPI FileMenu_DeleteItemByIndex ( HMENU hMenu, UINT uPos)
724 MENUITEMINFOA mii;
726 TRACE("0x%08x 0x%08x\n", hMenu, uPos);
728 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
729 mii.cbSize = sizeof(MENUITEMINFOA);
730 mii.fMask = MIIM_SUBMENU;
732 GetMenuItemInfoA(hMenu, uPos, TRUE, &mii );
733 if ( mii.hSubMenu )
735 /* FIXME: Do what? */
738 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
739 return TRUE;
742 /*************************************************************************
743 * FileMenu_DeleteItemByFirstID [SHELL32.141]
745 BOOL WINAPI FileMenu_DeleteItemByFirstID(
746 HMENU hMenu,
747 UINT uID)
749 TRACE("0x%08x 0x%08x\n", hMenu, uID);
750 return 0;
753 /*************************************************************************
754 * FileMenu_DeleteSeparator [SHELL32.142]
756 BOOL WINAPI FileMenu_DeleteSeparator(HMENU hMenu)
758 TRACE("0x%08x\n", hMenu);
759 return 0;
762 /*************************************************************************
763 * FileMenu_EnableItemByCmd [SHELL32.143]
765 BOOL WINAPI FileMenu_EnableItemByCmd(
766 HMENU hMenu,
767 UINT uID,
768 BOOL bEnable)
770 TRACE("0x%08x 0x%08x 0x%08x\n", hMenu, uID,bEnable);
771 return 0;
774 /*************************************************************************
775 * FileMenu_GetItemExtent [SHELL32.144]
777 * NOTES
778 * if the menu is too big, entries are getting cut away!!
780 DWORD WINAPI FileMenu_GetItemExtent (HMENU hMenu, UINT uPos)
781 { RECT rect;
783 FIXME("0x%08x 0x%08x\n", hMenu, uPos);
785 if (GetMenuItemRect(0, hMenu, uPos, &rect))
786 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
787 rect.right, rect.left, rect.top, rect.bottom);
788 return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom);
790 return 0x00100010; /*FIXME*/
793 /*************************************************************************
794 * FileMenu_AbortInitMenu [SHELL32.120]
797 void WINAPI FileMenu_AbortInitMenu (void)
798 { TRACE("\n");
799 bAbortInit = TRUE;
802 /*************************************************************************
803 * SHFind_InitMenuPopup [SHELL32.149]
806 * PARAMETERS
807 * hMenu [in] handle of menu previously created
808 * hWndParent [in] parent window
809 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
810 * x [in] no pointer (0x226 over here)
812 * RETURNS
813 * LPXXXXX pointer to struct containing a func addr at offset 8
814 * or NULL at failure.
816 LPVOID WINAPI SHFind_InitMenuPopup (HMENU hMenu, HWND hWndParent, DWORD w, DWORD x)
817 { FIXME("hmenu=0x%08x hwnd=0x%08x 0x%08lx 0x%08lx stub\n",
818 hMenu,hWndParent,w,x);
819 return NULL; /* this is supposed to be a pointer */
822 /*************************************************************************
823 * Shell_MergeMenus [SHELL32.67]
826 BOOL _SHIsMenuSeparator(HMENU hm, int i)
828 MENUITEMINFOA mii;
830 mii.cbSize = sizeof(MENUITEMINFOA);
831 mii.fMask = MIIM_TYPE;
832 mii.cch = 0; /* WARNING: We MUST initialize it to 0*/
833 if (!GetMenuItemInfoA(hm, i, TRUE, &mii))
835 return(FALSE);
838 if (mii.fType & MFT_SEPARATOR)
840 return(TRUE);
843 return(FALSE);
846 /**********************************************************************/
848 HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
849 { int nItem;
850 HMENU hmSubMenu;
851 BOOL bAlreadySeparated;
852 MENUITEMINFOA miiSrc;
853 char szName[256];
854 UINT uTemp, uIDMax = uIDAdjust;
856 TRACE("hmenu1=0x%04x hmenu2=0x%04x 0x%04x 0x%04x 0x%04x 0x%04lx\n",
857 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
859 if (!hmDst || !hmSrc)
860 { return uIDMax;
863 nItem = GetMenuItemCount(hmDst);
865 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
867 uInsert = (UINT)nItem; /* append on the end */
868 bAlreadySeparated = TRUE;
870 else
872 bAlreadySeparated = _SHIsMenuSeparator(hmDst, uInsert);
875 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
877 /* Add a separator between the menus */
878 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
879 bAlreadySeparated = TRUE;
883 /* Go through the menu items and clone them*/
884 for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
886 miiSrc.cbSize = sizeof(MENUITEMINFOA);
887 miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
889 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
890 miiSrc.fType = MFT_STRING;
891 miiSrc.dwTypeData = szName;
892 miiSrc.dwItemData = 0;
893 miiSrc.cch = sizeof(szName);
895 if (!GetMenuItemInfoA(hmSrc, nItem, TRUE, &miiSrc))
897 continue;
900 /* 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);
902 if (miiSrc.fType & MFT_SEPARATOR)
904 /* This is a separator; don't put two of them in a row */
905 if (bAlreadySeparated)
906 continue;
908 bAlreadySeparated = TRUE;
910 else if (miiSrc.hSubMenu)
912 if (uFlags & MM_SUBMENUSHAVEIDS)
914 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
916 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
917 continue;
919 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
920 uIDMax = miiSrc.wID + 1;
922 else
924 miiSrc.fMask &= ~MIIM_ID; /* Don't set IDs for submenus that didn't have them already */
926 hmSubMenu = miiSrc.hSubMenu;
928 miiSrc.hSubMenu = CreatePopupMenu();
930 if (!miiSrc.hSubMenu) return(uIDMax);
932 uTemp = Shell_MergeMenus(miiSrc.hSubMenu, hmSubMenu, 0, uIDAdjust, uIDAdjustMax, uFlags & MM_SUBMENUSHAVEIDS);
934 if (uIDMax <= uTemp)
935 uIDMax = uTemp;
937 bAlreadySeparated = FALSE;
939 else /* normal menu item */
941 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
943 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
944 continue;
946 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
947 uIDMax = miiSrc.wID + 1;
949 bAlreadySeparated = FALSE;
952 /* 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);
954 if (!InsertMenuItemA(hmDst, uInsert, TRUE, &miiSrc))
956 return(uIDMax);
960 /* Ensure the correct number of separators at the beginning of the
961 inserted menu items*/
962 if (uInsert == 0)
964 if (bAlreadySeparated)
966 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
969 else
971 if (_SHIsMenuSeparator(hmDst, uInsert-1))
973 if (bAlreadySeparated)
975 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
978 else
980 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
982 /* Add a separator between the menus*/
983 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
987 return(uIDMax);