source: trunk/src/shell32/shlmenu.cpp@ 3243

Last change on this file since 3243 was 3243, checked in by cbratschi, 25 years ago

merged with Corel WINE 20000324

File size: 26.6 KB
Line 
1/* $Id: shlmenu.cpp,v 1.5 2000-03-26 16:34:53 cbratschi Exp $ */
2
3/*
4 * Win32 SHELL32 for OS/2
5 *
6 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 * Path Functions
10 *
11 * Many of this functions are in SHLWAPI.DLL also
12 *
13 * Corel WINE 20000324 level
14 */
15
16/*
17 * see www.geocities.com/SiliconValley/4942/filemenu.html
18 */
19
20
21/*****************************************************************************
22 * Includes *
23 *****************************************************************************/
24
25#include <odin.h>
26#include <odinwrap.h>
27#include <os2sel.h>
28
29#include <assert.h>
30#include <string.h>
31#include <odin.h>
32
33#define ICOM_CINTERFACE 1
34#define CINTERFACE 1
35
36#include "wine/obj_base.h"
37#include "wine/obj_enumidlist.h"
38#include "wine/obj_shellfolder.h"
39#include "wine/undocshell.h"
40
41#include "heap.h"
42#include "debugtools.h"
43#include "winversion.h"
44#include "shell32_main.h"
45
46#include "pidl.h"
47
48#include <heapstring.h>
49#include <misc.h>
50
51
52ODINDEBUGCHANNEL(SHELL32-SHLMENU)
53
54
55/*****************************************************************************
56 * Implementation *
57 *****************************************************************************/
58
59BOOL WINAPI FileMenu_DeleteAllItems (HMENU hMenu);
60BOOL WINAPI FileMenu_AppendItemA(HMENU hMenu, LPCSTR lpText, UINT uID, int icon, HMENU hMenuPopup, int nItemHeight);
61
62typedef struct
63{
64 BOOL bInitialized;
65 BOOL bFixedItems;
66
67 /* create */
68 COLORREF crBorderColor;
69 int nBorderWidth;
70 HBITMAP hBorderBmp;
71
72 /* insert using pidl */
73 LPITEMIDLIST pidl;
74 UINT uID;
75 UINT uFlags;
76 UINT uEnumFlags;
77 LPFNFMCALLBACK lpfnCallback;
78} FMINFO, *LPFMINFO;
79
80typedef struct
81{ int cchItemText;
82 int iIconIndex;
83 HMENU hMenu;
84 char szItemText[1];
85} FMITEM, * LPFMITEM;
86
87static BOOL bAbortInit;
88
89#define CCH_MAXITEMTEXT 256
90
91LPFMINFO FM_GetMenuInfo(HMENU hmenu)
92{ MENUINFO MenuInfo;
93 LPFMINFO menudata;
94
95 MenuInfo.cbSize = sizeof(MENUINFO);
96 MenuInfo.fMask = MIM_MENUDATA;
97
98 if (! GetMenuInfo(hmenu, &MenuInfo))
99 return NULL;
100
101 menudata = (LPFMINFO)MenuInfo.dwMenuData;
102
103 assert ((menudata != 0) && (MenuInfo.cbSize == sizeof(MENUINFO)));
104
105 return menudata;
106
107}
108/*************************************************************************
109 * FM_SetMenuParameter [internal]
110 *
111 */
112static LPFMINFO FM_SetMenuParameter(
113 HMENU hmenu,
114 UINT uID,
115 LPCITEMIDLIST pidl,
116 UINT uFlags,
117 UINT uEnumFlags,
118 LPFNFMCALLBACK lpfnCallback)
119{
120 LPFMINFO menudata;
121
122 TRACE("\n");
123
124 menudata = FM_GetMenuInfo(hmenu);
125
126 if ( menudata->pidl)
127 { SHFree(menudata->pidl);
128 }
129
130 menudata->uID = uID;
131 menudata->pidl = ILClone(pidl);
132 menudata->uFlags = uFlags;
133 menudata->uEnumFlags = uEnumFlags;
134 menudata->lpfnCallback = lpfnCallback;
135
136 return menudata;
137}
138
139/*************************************************************************
140 * FM_InitMenuPopup [internal]
141 *
142 */
143static int FM_InitMenuPopup(HMENU hmenu, LPITEMIDLIST pAlternatePidl)
144{ IShellFolder *lpsf, *lpsf2;
145 ULONG ulItemAttr;
146 UINT uID, uFlags, uEnumFlags;
147 LPFNFMCALLBACK lpfnCallback;
148 LPITEMIDLIST pidl;
149 char sTemp[MAX_PATH];
150 int NumberOfItems = 0, iIcon;
151 MENUINFO MenuInfo;
152 LPFMINFO menudata;
153
154 TRACE("0x%04x %p\n", hmenu, pAlternatePidl);
155
156 MenuInfo.cbSize = sizeof(MENUINFO);
157 MenuInfo.fMask = MIM_MENUDATA;
158
159 if (! GetMenuInfo(hmenu, &MenuInfo))
160 return FALSE;
161
162 menudata = (LPFMINFO)MenuInfo.dwMenuData;
163
164 assert ((menudata != 0) && (MenuInfo.cbSize == sizeof(MENUINFO)));
165
166 if (menudata->bInitialized)
167 return 0;
168
169 pidl = ((pAlternatePidl) ? pAlternatePidl : menudata->pidl);
170 if (!pidl)
171 return 0;
172
173 uID = menudata->uID;
174 uFlags = menudata->uFlags;
175 uEnumFlags = menudata->uEnumFlags;
176 lpfnCallback = menudata->lpfnCallback;
177
178 menudata->bInitialized = FALSE;
179 SetMenuInfo(hmenu, &MenuInfo);
180
181 if (SUCCEEDED (SHGetDesktopFolder(&lpsf)))
182 {
183 if (SUCCEEDED(IShellFolder_BindToObject(lpsf, pidl,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2)))
184 {
185 IEnumIDList *lpe = NULL;
186
187 if (SUCCEEDED (IShellFolder_EnumObjects(lpsf2, 0, uEnumFlags, &lpe )))
188 {
189
190 LPITEMIDLIST pidlTemp = NULL;
191 ULONG ulFetched;
192
193 while ((!bAbortInit) && (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)))
194 {
195 if (SUCCEEDED (IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulItemAttr)))
196 {
197 ILGetDisplayName( pidlTemp, sTemp);
198 if (! (PidlToSicIndex(lpsf, pidlTemp, FALSE, (UINT*)&iIcon)))
199 iIcon = FM_BLANK_ICON;
200 if ( SFGAO_FOLDER & ulItemAttr)
201 {
202 LPFMINFO lpFmMi;
203 MENUINFO MenuInfo;
204 HMENU hMenuPopup = CreatePopupMenu();
205
206 lpFmMi = (LPFMINFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
207
208 lpFmMi->pidl = ILCombine(pidl, pidlTemp);
209 lpFmMi->uEnumFlags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
210
211 MenuInfo.cbSize = sizeof(MENUINFO);
212 MenuInfo.fMask = MIM_MENUDATA;
213 MenuInfo.dwMenuData = (DWORD) lpFmMi;
214 SetMenuInfo (hMenuPopup, &MenuInfo);
215
216 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, hMenuPopup, FM_DEFAULT_HEIGHT);
217 }
218 else
219 {
220 ((LPSTR)PathFindExtensionA(sTemp))[0] = 0x00;
221 FileMenu_AppendItemA (hmenu, sTemp, uID, iIcon, 0, FM_DEFAULT_HEIGHT);
222 }
223 }
224
225 if (lpfnCallback)
226 {
227 TRACE("enter callback\n");
228 lpfnCallback ( pidl, pidlTemp);
229 TRACE("leave callback\n");
230 }
231
232 NumberOfItems++;
233 }
234 IEnumIDList_Release (lpe);
235 }
236 IShellFolder_Release(lpsf2);
237 }
238 IShellFolder_Release(lpsf);
239 }
240
241 if ( GetMenuItemCount (hmenu) == 0 )
242 { FileMenu_AppendItemA (hmenu, "(empty)", uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
243 NumberOfItems++;
244 }
245
246 menudata->bInitialized = TRUE;
247 SetMenuInfo(hmenu, &MenuInfo);
248
249 return NumberOfItems;
250}
251/*************************************************************************
252 * FileMenu_Create [SHELL32.114]
253 *
254 * NOTES
255 * for non-root menus values are
256 * (ffffffff,00000000,00000000,00000000,00000000)
257 */
258ODINFUNCTION5(HMENU, FileMenu_Create,
259 COLORREF, crBorderColor,
260 int, nBorderWidth,
261 HBITMAP, hBorderBmp,
262 int, nSelHeight,
263 UINT, uFlags)
264{
265 MENUINFO MenuInfo;
266 LPFMINFO menudata;
267
268 HMENU hMenu = CreatePopupMenu();
269
270 TRACE("0x%08lx 0x%08x 0x%08x 0x%08x 0x%08x hMenu=0x%08x\n",
271 crBorderColor, nBorderWidth, hBorderBmp, nSelHeight, uFlags, hMenu);
272
273 menudata = (LPFMINFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FMINFO));
274 menudata->crBorderColor = crBorderColor;
275 menudata->nBorderWidth = nBorderWidth;
276 menudata->hBorderBmp = hBorderBmp;
277
278 MenuInfo.cbSize = sizeof(MENUINFO);
279 MenuInfo.fMask = MIM_MENUDATA;
280 MenuInfo.dwMenuData = (DWORD) menudata;
281 SetMenuInfo (hMenu, &MenuInfo);
282
283 return hMenu;
284}
285
286/*************************************************************************
287 * FileMenu_Destroy [SHELL32.118]
288 *
289 * NOTES
290 * exported by name
291 */
292ODINPROCEDURE1(FileMenu_Destroy,
293 HMENU, hmenu)
294{
295 LPFMINFO menudata;
296
297 TRACE("0x%08x\n", hmenu);
298
299 FileMenu_DeleteAllItems (hmenu);
300
301 menudata = FM_GetMenuInfo(hmenu);
302
303 if ( menudata->pidl)
304 { SHFree( menudata->pidl);
305 }
306 HeapFree(GetProcessHeap(), 0, menudata);
307
308 DestroyMenu (hmenu);
309}
310
311/*************************************************************************
312 * FileMenu_AppendItemAW [SHELL32.115]
313 *
314 */
315ODINFUNCTION6(BOOL, FileMenu_AppendItemA,
316 HMENU, hMenu,
317 LPCSTR, lpText,
318 UINT, uID,
319 int, icon,
320 HMENU, hMenuPopup,
321 int, nItemHeight)
322{
323 LPSTR lpszText = (LPSTR)lpText;
324 MENUITEMINFOA mii;
325 LPFMITEM myItem;
326 LPFMINFO menudata;
327 MENUINFO MenuInfo;
328
329 TRACE("0x%08x %s 0x%08x 0x%08x 0x%08x 0x%08x\n",
330 hMenu, (lpszText!=FM_SEPARATOR) ? lpText: NULL,
331 uID, icon, hMenuPopup, nItemHeight);
332
333 ZeroMemory (&mii, sizeof(MENUITEMINFOA));
334
335 mii.cbSize = sizeof(MENUITEMINFOA);
336
337 if (lpText != FM_SEPARATOR)
338 { int len = strlen (lpText);
339 myItem = (LPFMITEM) SHAlloc( sizeof(FMITEM) + len);
340 strcpy (myItem->szItemText, lpText);
341 myItem->cchItemText = len;
342 myItem->iIconIndex = icon;
343 myItem->hMenu = hMenu;
344 mii.fMask = MIIM_DATA;
345 mii.dwItemData = (DWORD) myItem;
346 }
347
348 if ( hMenuPopup )
349 { /* sub menu */
350 mii.fMask |= MIIM_TYPE | MIIM_SUBMENU;
351 mii.fType = MFT_OWNERDRAW;
352 mii.hSubMenu = hMenuPopup;
353 }
354 else if (lpText == FM_SEPARATOR )
355 { mii.fMask |= MIIM_ID | MIIM_TYPE;
356 mii.fType = MFT_SEPARATOR;
357 }
358 else
359 { /* normal item */
360 mii.fMask |= MIIM_ID | MIIM_TYPE | MIIM_STATE;
361 mii.fState = MFS_ENABLED | MFS_DEFAULT;
362 mii.fType = MFT_OWNERDRAW;
363 }
364 mii.wID = uID;
365
366 InsertMenuItemA (hMenu, (UINT)-1, TRUE, &mii);
367
368 /* set bFixedItems to true */
369 MenuInfo.cbSize = sizeof(MENUINFO);
370 MenuInfo.fMask = MIM_MENUDATA;
371
372 if (! GetMenuInfo(hMenu, &MenuInfo))
373 return FALSE;
374
375 menudata = (LPFMINFO)MenuInfo.dwMenuData;
376 assert ((menudata != 0) && (MenuInfo.cbSize == sizeof(MENUINFO)));
377 menudata->bFixedItems = TRUE;
378 SetMenuInfo(hMenu, &MenuInfo);
379
380 return TRUE;
381
382}
383ODINFUNCTION6(BOOL, FileMenu_AppendItemAW,
384 HMENU, hMenu,
385 LPCVOID, lpText,
386 UINT, uID,
387 int, icon,
388 HMENU, hMenuPopup,
389 int, nItemHeight)
390{
391 BOOL ret;
392 LPSTR lpszText=NULL;
393
394 if (VERSION_OsIsUnicode() && (lpText!=FM_SEPARATOR))
395 lpszText = (LPSTR)HEAP_strdupWtoA ( GetProcessHeap(),0, (LPCWSTR)lpText);
396
397 ret = FileMenu_AppendItemA(hMenu, (lpszText) ? lpszText : (LPCSTR)lpText, uID, icon, hMenuPopup, nItemHeight);
398
399 if (lpszText)
400 HeapFree( GetProcessHeap(), 0, lpszText );
401
402 return ret;
403}
404/*************************************************************************
405 * FileMenu_InsertUsingPidl [SHELL32.110]
406 *
407 * NOTES
408 * uEnumFlags any SHCONTF flag
409 */
410ODINFUNCTION6(int, FileMenu_InsertUsingPidl,
411 HMENU, hmenu,
412 UINT, uID,
413 LPCITEMIDLIST, pidl,
414 UINT, uFlags,
415 UINT, uEnumFlags,
416 LPFNFMCALLBACK, lpfnCallback)
417{
418 TRACE("0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
419 hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
420
421 pdump (pidl);
422
423 bAbortInit = FALSE;
424
425 FM_SetMenuParameter(hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
426
427 return FM_InitMenuPopup(hmenu, NULL);
428}
429
430/*************************************************************************
431 * FileMenu_ReplaceUsingPidl [SHELL32.113]
432 *
433 * FIXME: the static items are deleted but wont be refreshed
434 */
435ODINFUNCTION5(int, FileMenu_ReplaceUsingPidl,
436 HMENU, hmenu,
437 UINT, uID,
438 LPCITEMIDLIST, pidl,
439 UINT, uEnumFlags,
440 LPFNFMCALLBACK, lpfnCallback)
441{
442 TRACE("0x%08x 0x%08x %p 0x%08x %p\n",
443 hmenu, uID, pidl, uEnumFlags, lpfnCallback);
444
445 FileMenu_DeleteAllItems (hmenu);
446
447 FM_SetMenuParameter(hmenu, uID, pidl, 0, uEnumFlags, lpfnCallback);
448
449 return FM_InitMenuPopup(hmenu, NULL);
450}
451
452/*************************************************************************
453 * FileMenu_Invalidate [SHELL32.111]
454 */
455ODINPROCEDURE1(FileMenu_Invalidate,
456 HMENU, hMenu)
457{
458 FIXME("0x%08x\n",hMenu);
459}
460
461/*************************************************************************
462 * FileMenu_FindSubMenuByPidl [SHELL32.106]
463 */
464ODINFUNCTION2(HMENU, FileMenu_FindSubMenuByPidl,
465 HMENU, hMenu,
466 LPCITEMIDLIST, pidl)
467{
468 FIXME("0x%08x %p\n",hMenu, pidl);
469 return 0;
470}
471
472/*************************************************************************
473 * FileMenu_AppendFilesForPidl [SHELL32.124]
474 */
475ODINFUNCTION3(HMENU, FileMenu_AppendFilesForPidl,
476 HMENU, hmenu,
477 LPCITEMIDLIST, pidl,
478 BOOL, bAddSeperator)
479{
480 LPFMINFO menudata;
481
482 menudata = FM_GetMenuInfo(hmenu);
483
484 menudata->bInitialized = FALSE;
485
486 FM_InitMenuPopup(hmenu, pidl);
487
488 if (bAddSeperator)
489 FileMenu_AppendItemA (hmenu, FM_SEPARATOR, 0, 0, 0, FM_DEFAULT_HEIGHT);
490
491 TRACE("0x%08x %p 0x%08x\n",hmenu, pidl,bAddSeperator);
492
493 return 0;
494}
495/*************************************************************************
496 * FileMenu_AddFilesForPidl [SHELL32.125]
497 *
498 * NOTES
499 * uEnumFlags any SHCONTF flag
500 */
501ODINFUNCTION7(int, FileMenu_AddFilesForPidl,
502 HMENU, hmenu,
503 UINT, uReserved,
504 UINT, uID,
505 LPCITEMIDLIST, pidl,
506 UINT, uFlags,
507 UINT, uEnumFlags,
508 LPFNFMCALLBACK, lpfnCallback)
509{
510 TRACE("0x%08x 0x%08x 0x%08x %p 0x%08x 0x%08x %p\n",
511 hmenu, uReserved, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
512
513 return FileMenu_InsertUsingPidl ( hmenu, uID, pidl, uFlags, uEnumFlags, lpfnCallback);
514
515}
516
517
518/*************************************************************************
519 * FileMenu_TrackPopupMenuEx [SHELL32.116]
520 */
521ODINFUNCTION6(HRESULT, FileMenu_TrackPopupMenuEx,
522 HMENU, hMenu,
523 UINT, uFlags,
524 int, x,
525 int, y,
526 HWND, hWnd,
527 LPTPMPARAMS, lptpm)
528{
529 TRACE("0x%08x 0x%08x 0x%x 0x%x 0x%08x %p\n",
530 hMenu, uFlags, x, y, hWnd, lptpm);
531 return TrackPopupMenuEx(hMenu, uFlags, x, y, hWnd, lptpm);
532}
533
534/*************************************************************************
535 * FileMenu_GetLastSelectedItemPidls [SHELL32.107]
536 */
537ODINFUNCTION3(BOOL, FileMenu_GetLastSelectedItemPidls,
538 UINT, uReserved,
539 LPCITEMIDLIST *, ppidlFolder,
540 LPCITEMIDLIST *, ppidlItem)
541{
542 FIXME("0x%08x %p %p\n",uReserved, ppidlFolder, ppidlItem);
543 return 0;
544}
545
546#define FM_ICON_SIZE 16
547#define FM_Y_SPACE 4
548#define FM_SPACE1 4
549#define FM_SPACE2 2
550#define FM_LEFTBORDER 2
551#define FM_RIGHTBORDER 8
552/*************************************************************************
553 * FileMenu_MeasureItem [SHELL32.112]
554 */
555ODINFUNCTION2(LRESULT, FileMenu_MeasureItem,
556 HWND, hWnd,
557 LPMEASUREITEMSTRUCT, lpmis)
558{
559 LPFMITEM pMyItem = (LPFMITEM)(lpmis->itemData);
560 HDC hdc = GetDC(hWnd);
561 SIZE size;
562 LPFMINFO menuinfo;
563
564 TRACE("0x%08x %p %s\n", hWnd, lpmis, pMyItem->szItemText);
565
566 GetTextExtentPoint32A(hdc, pMyItem->szItemText, pMyItem->cchItemText, &size);
567
568 lpmis->itemWidth = size.cx + FM_LEFTBORDER + FM_ICON_SIZE + FM_SPACE1 + FM_SPACE2 + FM_RIGHTBORDER;
569 lpmis->itemHeight = (size.cy > (FM_ICON_SIZE + FM_Y_SPACE)) ? size.cy : (FM_ICON_SIZE + FM_Y_SPACE);
570
571 /* add the menubitmap */
572 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
573 if (menuinfo->nBorderWidth)
574 lpmis->itemWidth += menuinfo->nBorderWidth;
575
576 TRACE("-- 0x%04x 0x%04x\n", lpmis->itemWidth, lpmis->itemHeight);
577 ReleaseDC (hWnd, hdc);
578 return 0;
579}
580/*************************************************************************
581 * FileMenu_DrawItem [SHELL32.105]
582 */
583ODINFUNCTION2(LRESULT, FileMenu_DrawItem,
584 HWND, hWnd,
585 LPDRAWITEMSTRUCT, lpdis)
586{
587 LPFMITEM pMyItem = (LPFMITEM)(lpdis->itemData);
588 COLORREF clrPrevText, clrPrevBkgnd;
589 int xi,yi,xt,yt;
590 HIMAGELIST hImageList;
591 RECT TextRect, BorderRect;
592 LPFMINFO menuinfo;
593
594 TRACE("0x%08x %p %s\n", hWnd, lpdis, pMyItem->szItemText);
595
596 if (lpdis->itemState & ODS_SELECTED)
597 {
598 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
599 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
600 }
601 else
602 {
603 clrPrevText = SetTextColor(lpdis->hDC, GetSysColor (COLOR_MENUTEXT));
604 clrPrevBkgnd = SetBkColor(lpdis->hDC, GetSysColor (COLOR_MENU));
605 }
606
607 CopyRect(&TextRect, &(lpdis->rcItem));
608
609 /* add the menubitmap */
610 menuinfo = FM_GetMenuInfo(pMyItem->hMenu);
611 if (menuinfo->nBorderWidth)
612 TextRect.left += menuinfo->nBorderWidth;
613
614 BorderRect.right = menuinfo->nBorderWidth;
615/* FillRect(lpdis->hDC, &BorderRect, CreateSolidBrush( menuinfo->crBorderColor));
616*/
617 TextRect.left += FM_LEFTBORDER;
618 xi = TextRect.left + FM_SPACE1;
619 yi = TextRect.top + FM_Y_SPACE/2;
620 TextRect.bottom -= FM_Y_SPACE/2;
621
622 xt = xi + FM_ICON_SIZE + FM_SPACE2;
623 yt = yi;
624
625 ExtTextOutA (lpdis->hDC, xt , yt, ETO_OPAQUE, &TextRect, pMyItem->szItemText, pMyItem->cchItemText, NULL);
626
627 Shell_GetImageList(0, &hImageList);
628 pImageList_Draw(hImageList, pMyItem->iIconIndex, lpdis->hDC, xi, yi, ILD_NORMAL);
629
630 TRACE("-- 0x%04x 0x%04x 0x%04x 0x%04x\n", TextRect.left, TextRect.top, TextRect.right, TextRect.bottom);
631
632 SetTextColor(lpdis->hDC, clrPrevText);
633 SetBkColor(lpdis->hDC, clrPrevBkgnd);
634
635 return TRUE;
636}
637
638/*************************************************************************
639 * FileMenu_InitMenuPopup [SHELL32.109]
640 *
641 * NOTES
642 * The filemenu is a ownerdrawn menu. Call this function responding to
643 * WM_INITPOPUPMENU
644 *
645 */
646ODINFUNCTION1(BOOL, FileMenu_InitMenuPopup,
647 HMENU, hmenu)
648{
649 FM_InitMenuPopup(hmenu, NULL);
650 return TRUE;
651}
652
653/*************************************************************************
654 * FileMenu_HandleMenuChar [SHELL32.108]
655 */
656ODINFUNCTION2(LRESULT, FileMenu_HandleMenuChar,
657 HMENU, hMenu,
658 WPARAM, wParam)
659{
660 FIXME("0x%08x 0x%08x\n",hMenu,wParam);
661 return 0;
662}
663
664/*************************************************************************
665 * FileMenu_DeleteAllItems [SHELL32.104]
666 *
667 * NOTES
668 * exported by name
669 */
670ODINFUNCTION1(BOOL, FileMenu_DeleteAllItems,
671 HMENU, hmenu)
672{
673 MENUITEMINFOA mii;
674 LPFMINFO menudata;
675
676 int i;
677
678 TRACE("0x%08x\n", hmenu);
679
680 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
681 mii.cbSize = sizeof(MENUITEMINFOA);
682 mii.fMask = MIIM_SUBMENU|MIIM_DATA;
683
684 for (i = 0; i < GetMenuItemCount( hmenu ); i++)
685 { GetMenuItemInfoA(hmenu, i, TRUE, &mii );
686
687 if (mii.dwItemData)
688 SHFree((LPFMINFO)mii.dwItemData);
689
690 if (mii.hSubMenu)
691 FileMenu_Destroy(mii.hSubMenu);
692 }
693
694 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)){};
695
696 menudata = FM_GetMenuInfo(hmenu);
697
698 menudata->bInitialized = FALSE;
699
700 return TRUE;
701}
702
703/*************************************************************************
704 * FileMenu_DeleteItemByCmd [SHELL32.]
705 *
706 */
707ODINFUNCTION2(BOOL, FileMenu_DeleteItemByCmd,
708 HMENU, hMenu,
709 UINT, uID)
710{
711 MENUITEMINFOA mii;
712
713 TRACE("0x%08x 0x%08x\n", hMenu, uID);
714
715 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
716 mii.cbSize = sizeof(MENUITEMINFOA);
717 mii.fMask = MIIM_SUBMENU;
718
719 GetMenuItemInfoA(hMenu, uID, FALSE, &mii );
720 if ( mii.hSubMenu );
721
722 DeleteMenu(hMenu, MF_BYCOMMAND, uID);
723 return TRUE;
724}
725
726/*************************************************************************
727 * FileMenu_DeleteItemByIndex [SHELL32.140]
728 */
729ODINFUNCTION2(BOOL, FileMenu_DeleteItemByIndex,
730 HMENU, hMenu,
731 UINT, uPos)
732{
733 MENUITEMINFOA mii;
734
735 TRACE("0x%08x 0x%08x\n", hMenu, uPos);
736
737 ZeroMemory ( &mii, sizeof(MENUITEMINFOA));
738 mii.cbSize = sizeof(MENUITEMINFOA);
739 mii.fMask = MIIM_SUBMENU;
740
741 GetMenuItemInfoA(hMenu, uPos, TRUE, &mii );
742 if ( mii.hSubMenu );
743
744 DeleteMenu(hMenu, MF_BYPOSITION, uPos);
745 return TRUE;
746}
747
748/*************************************************************************
749 * FileMenu_DeleteItemByFirstID [SHELL32.141]
750 */
751ODINFUNCTION2(BOOL, FileMenu_DeleteItemByFirstID,
752 HMENU, hMenu,
753 UINT, uID)
754{
755 TRACE("0x%08x 0x%08x\n", hMenu, uID);
756 return 0;
757}
758
759/*************************************************************************
760 * FileMenu_DeleteSeparator [SHELL32.142]
761 */
762ODINFUNCTION1(BOOL, FileMenu_DeleteSeparator,
763 HMENU, hMenu)
764{
765 TRACE("0x%08x\n", hMenu);
766 return 0;
767}
768
769/*************************************************************************
770 * FileMenu_EnableItemByCmd [SHELL32.143]
771 */
772ODINFUNCTION3(BOOL, FileMenu_EnableItemByCmd,
773 HMENU, hMenu,
774 UINT, uID,
775 BOOL, bEnable)
776{
777 TRACE("0x%08x 0x%08x 0x%08x\n", hMenu, uID,bEnable);
778 return 0;
779}
780
781/*************************************************************************
782 * FileMenu_GetItemExtent [SHELL32.144]
783 *
784 * NOTES
785 * if the menu is to big, entrys are getting cut away!!
786 */
787ODINFUNCTION2(DWORD, FileMenu_GetItemExtent,
788 HMENU, hMenu,
789 UINT, uPos)
790{ RECT rect;
791
792 FIXME("0x%08x 0x%08x\n", hMenu, uPos);
793
794 if (GetMenuItemRect(0, hMenu, uPos, &rect))
795 { FIXME("0x%04x 0x%04x 0x%04x 0x%04x\n",
796 rect.right, rect.left, rect.top, rect.bottom);
797 return ((rect.right-rect.left)<<16) + (rect.top-rect.bottom);
798 }
799 return 0x00100010; /*fixme*/
800}
801
802/*************************************************************************
803 * FileMenu_AbortInitMenu [SHELL32.120]
804 *
805 */
806ODINPROCEDURE0(FileMenu_AbortInitMenu)
807{
808 bAbortInit = TRUE;
809}
810
811/*************************************************************************
812 * SHFind_InitMenuPopup [SHELL32.149]
813 *
814 *
815 * PARAMETERS
816 * hMenu [in] handle of menu previously created
817 * hWndParent [in] parent window
818 * w [in] no pointer (0x209 over here) perhaps menu IDs ???
819 * x [in] no pointer (0x226 over here)
820 *
821 * RETURNS
822 * LPXXXXX pointer to struct containing a func addr at offset 8
823 * or NULL at failure.
824 */
825ODINFUNCTION4(HRESULT, SHFind_InitMenuPopup,
826 HMENU, hMenu,
827 HWND, hWndParent,
828 DWORD, w,
829 DWORD, x)
830{ FIXME("hmenu=0x%08x hwnd=0x%08x 0x%08lx 0x%08lx stub\n",
831 hMenu,hWndParent,w,x);
832 return NULL; /* this is supposed to be a pointer */
833}
834
835/*************************************************************************
836 * Shell_MergeMenus [SHELL32.67]
837 *
838 */
839BOOL _SHIsMenuSeparator(HMENU hm, int i)
840{
841 MENUITEMINFOA mii;
842
843 mii.cbSize = sizeof(MENUITEMINFOA);
844 mii.fMask = MIIM_TYPE;
845 mii.cch = 0; /* WARNING: We MUST initialize it to 0*/
846 if (!GetMenuItemInfoA(hm, i, TRUE, &mii))
847 {
848 return(FALSE);
849 }
850
851 if (mii.fType & MFT_SEPARATOR)
852 {
853 return(TRUE);
854 }
855
856 return(FALSE);
857}
858
859ODINFUNCTION6(HRESULT, Shell_MergeMenus,
860 HMENU, hmDst,
861 HMENU, hmSrc,
862 UINT, uInsert,
863 UINT, uIDAdjust,
864 UINT, uIDAdjustMax,
865 ULONG, uFlags)
866{ int nItem;
867 HMENU hmSubMenu;
868 BOOL bAlreadySeparated;
869 MENUITEMINFOA miiSrc;
870 char szName[256];
871 UINT uTemp, uIDMax = uIDAdjust;
872
873 TRACE("hmenu1=0x%04x hmenu2=0x%04x 0x%04x 0x%04x 0x%04x 0x%04lx\n",
874 hmDst, hmSrc, uInsert, uIDAdjust, uIDAdjustMax, uFlags);
875
876 if (!hmDst || !hmSrc)
877 { return uIDMax;
878 }
879
880 nItem = GetMenuItemCount(hmDst);
881
882 if (uInsert >= (UINT)nItem) /* insert position inside menu? */
883 {
884 uInsert = (UINT)nItem; /* append on the end */
885 bAlreadySeparated = TRUE;
886 }
887 else
888 {
889 bAlreadySeparated = _SHIsMenuSeparator(hmDst, uInsert);;
890 }
891
892 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
893 {
894 /* Add a separator between the menus */
895 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
896 bAlreadySeparated = TRUE;
897 }
898
899
900 /* Go through the menu items and clone them*/
901 for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
902 {
903 miiSrc.cbSize = sizeof(MENUITEMINFOA);
904 miiSrc.fMask = MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
905
906 /* We need to reset this every time through the loop in case menus DON'T have IDs*/
907 miiSrc.fType = MFT_STRING;
908 miiSrc.dwTypeData = szName;
909 miiSrc.dwItemData = 0;
910 miiSrc.cch = sizeof(szName);
911
912 if (!GetMenuItemInfoA(hmSrc, nItem, TRUE, &miiSrc))
913 {
914 continue;
915 }
916
917/* 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);
918*/
919 if (miiSrc.fType & MFT_SEPARATOR)
920 {
921 /* This is a separator; don't put two of them in a row */
922 if (bAlreadySeparated)
923 continue;
924
925 bAlreadySeparated = TRUE;
926 }
927 else if (miiSrc.hSubMenu)
928 {
929 if (uFlags & MM_SUBMENUSHAVEIDS)
930 {
931 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
932
933 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
934 continue;
935
936 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
937 uIDMax = miiSrc.wID + 1;
938 }
939 else
940 {
941 miiSrc.fMask &= ~MIIM_ID; /* Don't set IDs for submenus that didn't have them already */
942 }
943 hmSubMenu = miiSrc.hSubMenu;
944
945 miiSrc.hSubMenu = CreatePopupMenu();
946
947 if (!miiSrc.hSubMenu) return(uIDMax);
948
949 uTemp = Shell_MergeMenus(miiSrc.hSubMenu, hmSubMenu, 0, uIDAdjust, uIDAdjustMax, uFlags & MM_SUBMENUSHAVEIDS);
950
951 if (uIDMax <= uTemp)
952 uIDMax = uTemp;
953
954 bAlreadySeparated = FALSE;
955 }
956 else /* normal menu item */
957 {
958 miiSrc.wID += uIDAdjust; /* add uIDAdjust to the ID */
959
960 if (miiSrc.wID > uIDAdjustMax) /* skip ID's higher uIDAdjustMax */
961 continue;
962
963 if (uIDMax <= miiSrc.wID) /* remember the highest ID */
964 uIDMax = miiSrc.wID + 1;
965
966 bAlreadySeparated = FALSE;
967 }
968
969/* 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);
970*/
971 if (!InsertMenuItemA(hmDst, uInsert, TRUE, &miiSrc))
972 {
973 return(uIDMax);
974 }
975 }
976
977 /* Ensure the correct number of separators at the beginning of the
978 inserted menu items*/
979 if (uInsert == 0)
980 {
981 if (bAlreadySeparated)
982 {
983 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
984 }
985 }
986 else
987 {
988 if (_SHIsMenuSeparator(hmDst, uInsert-1))
989 {
990 if (bAlreadySeparated)
991 {
992 DeleteMenu(hmDst, uInsert, MF_BYPOSITION);
993 }
994 }
995 else
996 {
997 if ((uFlags & MM_ADDSEPARATOR) && !bAlreadySeparated)
998 {
999 /* Add a separator between the menus*/
1000 InsertMenuA(hmDst, uInsert, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
1001 }
1002 }
1003 }
1004 return(uIDMax);
1005}
1006
Note: See TracBrowser for help on using the repository browser.