Fix French translation.
[wine/multimedia.git] / dlls / shell32 / shv_item_cmenu.c
blob593727d83ede7a14820222ab1994c80f93391df1
1 /*
2 * IContextMenu for items in the shellview
4 * Copyright 1998, 2000 Juergen Schmied <juergen.schmied@debitel.net>
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 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25 #include "winerror.h"
26 #include "wine/debug.h"
28 #include "windef.h"
29 #include "wingdi.h"
30 #include "pidl.h"
31 #include "shlguid.h"
32 #include "undocshell.h"
33 #include "shlobj.h"
35 #include "shell32_main.h"
36 #include "shellfolder.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell);
40 /**************************************************************************
41 * IContextMenu Implementation
43 typedef struct
44 { ICOM_VFIELD(IContextMenu);
45 DWORD ref;
46 IShellFolder* pSFParent;
47 LPITEMIDLIST pidl; /* root pidl */
48 LPITEMIDLIST *apidl; /* array of child pidls */
49 UINT cidl;
50 BOOL bAllValues;
51 } ItemCmImpl;
54 static struct ICOM_VTABLE(IContextMenu) cmvt;
56 /**************************************************************************
57 * ISvItemCm_CanRenameItems()
59 static BOOL ISvItemCm_CanRenameItems(ItemCmImpl *This)
60 { UINT i;
61 DWORD dwAttributes;
63 TRACE("(%p)->()\n",This);
65 if(This->apidl)
67 for(i = 0; i < This->cidl; i++){}
68 if(i > 1) return FALSE; /* can't rename more than one item at a time*/
69 dwAttributes = SFGAO_CANRENAME;
70 IShellFolder_GetAttributesOf(This->pSFParent, 1, (LPCITEMIDLIST*)This->apidl, &dwAttributes);
71 return dwAttributes & SFGAO_CANRENAME;
73 return FALSE;
76 /**************************************************************************
77 * ISvItemCm_Constructor()
79 IContextMenu *ISvItemCm_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST pidl, LPCITEMIDLIST *apidl, UINT cidl)
80 { ItemCmImpl* cm;
81 UINT u;
83 cm = (ItemCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ItemCmImpl));
84 cm->lpVtbl = &cmvt;
85 cm->ref = 1;
86 cm->pidl = ILClone(pidl);
87 cm->pSFParent = pSFParent;
89 if(pSFParent) IShellFolder_AddRef(pSFParent);
91 cm->apidl = _ILCopyaPidl(apidl, cidl);
92 cm->cidl = cidl;
94 cm->bAllValues = 1;
95 for(u = 0; u < cidl; u++)
97 cm->bAllValues &= (_ILIsValue(apidl[u]) ? 1 : 0);
100 TRACE("(%p)->()\n",cm);
102 return (IContextMenu*)cm;
105 /**************************************************************************
106 * ISvItemCm_fnQueryInterface
108 static HRESULT WINAPI ISvItemCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
110 ICOM_THIS(ItemCmImpl, iface);
112 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
114 *ppvObj = NULL;
116 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
118 *ppvObj = This;
120 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
122 *ppvObj = This;
124 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
126 FIXME("-- LPSHELLEXTINIT pointer requested\n");
129 if(*ppvObj)
131 IUnknown_AddRef((IUnknown*)*ppvObj);
132 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
133 return S_OK;
135 TRACE("-- Interface: E_NOINTERFACE\n");
136 return E_NOINTERFACE;
139 /**************************************************************************
140 * ISvItemCm_fnAddRef
142 static ULONG WINAPI ISvItemCm_fnAddRef(IContextMenu *iface)
144 ICOM_THIS(ItemCmImpl, iface);
146 TRACE("(%p)->(count=%lu)\n",This, This->ref);
148 return ++(This->ref);
151 /**************************************************************************
152 * ISvItemCm_fnRelease
154 static ULONG WINAPI ISvItemCm_fnRelease(IContextMenu *iface)
156 ICOM_THIS(ItemCmImpl, iface);
158 TRACE("(%p)->()\n",This);
160 if (!--(This->ref))
162 TRACE(" destroying IContextMenu(%p)\n",This);
164 if(This->pSFParent)
165 IShellFolder_Release(This->pSFParent);
167 if(This->pidl)
168 SHFree(This->pidl);
170 /*make sure the pidl is freed*/
171 _ILFreeaPidl(This->apidl, This->cidl);
173 HeapFree(GetProcessHeap(),0,This);
174 return 0;
176 return This->ref;
179 /**************************************************************************
180 * ICM_InsertItem()
182 void WINAPI _InsertMenuItem (
183 HMENU hmenu,
184 UINT indexMenu,
185 BOOL fByPosition,
186 UINT wID,
187 UINT fType,
188 LPSTR dwTypeData,
189 UINT fState)
191 MENUITEMINFOA mii;
193 ZeroMemory(&mii, sizeof(mii));
194 mii.cbSize = sizeof(mii);
195 if (fType == MFT_SEPARATOR)
197 mii.fMask = MIIM_ID | MIIM_TYPE;
199 else
201 mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
202 mii.dwTypeData = dwTypeData;
203 mii.fState = fState;
205 mii.wID = wID;
206 mii.fType = fType;
207 InsertMenuItemA( hmenu, indexMenu, fByPosition, &mii);
209 /**************************************************************************
210 * ISvItemCm_fnQueryContextMenu()
213 static HRESULT WINAPI ISvItemCm_fnQueryContextMenu(
214 IContextMenu *iface,
215 HMENU hmenu,
216 UINT indexMenu,
217 UINT idCmdFirst,
218 UINT idCmdLast,
219 UINT uFlags)
221 ICOM_THIS(ItemCmImpl, iface);
223 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
225 if(!(CMF_DEFAULTONLY & uFlags))
227 if(uFlags & CMF_EXPLORE)
229 if(This->bAllValues)
231 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_OPEN, MFT_STRING, "&Open", MFS_ENABLED);
232 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED|MFS_DEFAULT);
234 else
236 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED|MFS_DEFAULT);
237 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_OPEN, MFT_STRING, "&Open", MFS_ENABLED);
240 else
242 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_OPEN, MFT_STRING, "&Select", MFS_ENABLED|MFS_DEFAULT);
244 _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
245 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_COPY, MFT_STRING, "&Copy", MFS_ENABLED);
246 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_CUT, MFT_STRING, "&Cut", MFS_ENABLED);
248 _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
249 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_DELETE, MFT_STRING, "&Delete", MFS_ENABLED);
251 if(uFlags & CMF_CANRENAME)
252 _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_RENAME, MFT_STRING, "&Rename", ISvItemCm_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED);
254 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (FCIDM_SHVIEWLAST));
256 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
259 /**************************************************************************
260 * DoOpenExplore
262 * for folders only
265 static void DoOpenExplore(
266 IContextMenu *iface,
267 HWND hwnd,
268 LPCSTR verb)
270 ICOM_THIS(ItemCmImpl, iface);
272 UINT i, bFolderFound = FALSE;
273 LPITEMIDLIST pidlFQ;
274 SHELLEXECUTEINFOA sei;
276 /* Find the first item in the list that is not a value. These commands
277 should never be invoked if there isn't at least one folder item in the list.*/
279 for(i = 0; i<This->cidl; i++)
281 if(!_ILIsValue(This->apidl[i]))
283 bFolderFound = TRUE;
284 break;
288 if (!bFolderFound) return;
290 pidlFQ = ILCombine(This->pidl, This->apidl[i]);
292 ZeroMemory(&sei, sizeof(sei));
293 sei.cbSize = sizeof(sei);
294 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
295 sei.lpIDList = pidlFQ;
296 sei.lpClass = "folder";
297 sei.hwnd = hwnd;
298 sei.nShow = SW_SHOWNORMAL;
299 sei.lpVerb = verb;
300 ShellExecuteExA(&sei);
301 SHFree(pidlFQ);
304 /**************************************************************************
305 * DoRename
307 static void DoRename(
308 IContextMenu *iface,
309 HWND hwnd)
311 ICOM_THIS(ItemCmImpl, iface);
313 LPSHELLBROWSER lpSB;
314 LPSHELLVIEW lpSV;
316 TRACE("(%p)->(wnd=%p)\n",This, hwnd);
318 /* get the active IShellView */
319 if ((lpSB = (LPSHELLBROWSER)SendMessageA(hwnd, CWM_GETISHELLBROWSER,0,0)))
321 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
323 TRACE("(sv=%p)\n",lpSV);
324 IShellView_SelectItem(lpSV, This->apidl[0],
325 SVSI_DESELECTOTHERS|SVSI_EDIT|SVSI_ENSUREVISIBLE|SVSI_FOCUSED|SVSI_SELECT);
326 IShellView_Release(lpSV);
331 /**************************************************************************
332 * DoDelete
334 * deletes the currently selected items
336 static void DoDelete(IContextMenu *iface)
338 ICOM_THIS(ItemCmImpl, iface);
339 ISFHelper * psfhlp;
341 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
342 if (psfhlp)
344 ISFHelper_DeleteItems(psfhlp, This->cidl, (LPCITEMIDLIST *)This->apidl);
345 ISFHelper_Release(psfhlp);
349 /**************************************************************************
350 * DoCopyOrCut
352 * copies the currently selected items into the clipboard
354 static BOOL DoCopyOrCut(
355 IContextMenu *iface,
356 HWND hwnd,
357 BOOL bCut)
359 ICOM_THIS(ItemCmImpl, iface);
361 LPSHELLBROWSER lpSB;
362 LPSHELLVIEW lpSV;
363 LPDATAOBJECT lpDo;
365 TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This, hwnd, bCut);
367 if(GetShellOle())
369 /* get the active IShellView */
370 if ((lpSB = (LPSHELLBROWSER)SendMessageA(hwnd, CWM_GETISHELLBROWSER,0,0)))
372 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
374 if (SUCCEEDED(IShellView_GetItemObject(lpSV, SVGIO_SELECTION, &IID_IDataObject, (LPVOID*)&lpDo)))
376 pOleSetClipboard(lpDo);
377 IDataObject_Release(lpDo);
379 IShellView_Release(lpSV);
383 return TRUE;
384 #if 0
386 the following code does the copy operation witout ole32.dll
387 we might need this possibility too (js)
389 BOOL bSuccess = FALSE;
391 TRACE("(%p)\n", iface);
393 if(OpenClipboard(NULL))
395 if(EmptyClipboard())
397 IPersistFolder2 * ppf2;
398 IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2);
399 if (ppf2)
401 LPITEMIDLIST pidl;
402 IPersistFolder2_GetCurFolder(ppf2, &pidl);
403 if(pidl)
405 HGLOBAL hMem;
407 hMem = RenderHDROP(pidl, This->apidl, This->cidl);
409 if(SetClipboardData(CF_HDROP, hMem))
411 bSuccess = TRUE;
413 SHFree(pidl);
415 IPersistFolder2_Release(ppf2);
419 CloseClipboard();
421 return bSuccess;
422 #endif
424 /**************************************************************************
425 * ISvItemCm_fnInvokeCommand()
427 static HRESULT WINAPI ISvItemCm_fnInvokeCommand(
428 IContextMenu *iface,
429 LPCMINVOKECOMMANDINFO lpcmi)
431 ICOM_THIS(ItemCmImpl, iface);
433 if (lpcmi->cbSize != sizeof(CMINVOKECOMMANDINFO))
434 FIXME("Is an EX structure\n");
436 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
438 if( HIWORD(lpcmi->lpVerb)==0 && LOWORD(lpcmi->lpVerb) > FCIDM_SHVIEWLAST)
440 TRACE("Invalid Verb %x\n",LOWORD(lpcmi->lpVerb));
441 return E_INVALIDARG;
444 if (HIWORD(lpcmi->lpVerb) == 0)
446 switch(LOWORD(lpcmi->lpVerb))
448 case FCIDM_SHVIEW_EXPLORE:
449 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
450 DoOpenExplore(iface, lpcmi->hwnd, "explore");
451 break;
452 case FCIDM_SHVIEW_OPEN:
453 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
454 DoOpenExplore(iface, lpcmi->hwnd, "open");
455 break;
456 case FCIDM_SHVIEW_RENAME:
457 TRACE("Verb FCIDM_SHVIEW_RENAME\n");
458 DoRename(iface, lpcmi->hwnd);
459 break;
460 case FCIDM_SHVIEW_DELETE:
461 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
462 DoDelete(iface);
463 break;
464 case FCIDM_SHVIEW_COPY:
465 TRACE("Verb FCIDM_SHVIEW_COPY\n");
466 DoCopyOrCut(iface, lpcmi->hwnd, FALSE);
467 break;
468 case FCIDM_SHVIEW_CUT:
469 TRACE("Verb FCIDM_SHVIEW_CUT\n");
470 DoCopyOrCut(iface, lpcmi->hwnd, TRUE);
471 break;
472 default:
473 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi->lpVerb));
476 else
478 TRACE("Verb is %s\n",debugstr_a(lpcmi->lpVerb));
479 if (strcmp(lpcmi->lpVerb,"delete")==0)
480 DoDelete(iface);
481 else
482 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi->lpVerb));
484 return NOERROR;
487 /**************************************************************************
488 * ISvItemCm_fnGetCommandString()
490 static HRESULT WINAPI ISvItemCm_fnGetCommandString(
491 IContextMenu *iface,
492 UINT idCommand,
493 UINT uFlags,
494 UINT* lpReserved,
495 LPSTR lpszName,
496 UINT uMaxNameLen)
498 ICOM_THIS(ItemCmImpl, iface);
500 HRESULT hr = E_INVALIDARG;
502 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
504 switch(uFlags)
506 case GCS_HELPTEXT:
507 hr = E_NOTIMPL;
508 break;
510 case GCS_VERBA:
511 switch(idCommand)
513 case FCIDM_SHVIEW_RENAME:
514 strcpy((LPSTR)lpszName, "rename");
515 hr = NOERROR;
516 break;
518 break;
520 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
521 case, you need to do the lstrcpyW to the pointer passed.*/
522 case GCS_VERBW:
523 switch(idCommand)
524 { case FCIDM_SHVIEW_RENAME:
525 MultiByteToWideChar( CP_ACP, 0, "rename", -1, (LPWSTR)lpszName, uMaxNameLen );
526 hr = NOERROR;
527 break;
529 break;
531 case GCS_VALIDATE:
532 hr = NOERROR;
533 break;
535 TRACE("-- (%p)->(name=%s)\n",This, lpszName);
536 return hr;
539 /**************************************************************************
540 * ISvItemCm_fnHandleMenuMsg()
541 * NOTES
542 * should be only in IContextMenu2 and IContextMenu3
543 * is nevertheless called from word95
545 static HRESULT WINAPI ISvItemCm_fnHandleMenuMsg(
546 IContextMenu *iface,
547 UINT uMsg,
548 WPARAM wParam,
549 LPARAM lParam)
551 ICOM_THIS(ItemCmImpl, iface);
553 TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
555 return E_NOTIMPL;
558 static struct ICOM_VTABLE(IContextMenu) cmvt =
560 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
561 ISvItemCm_fnQueryInterface,
562 ISvItemCm_fnAddRef,
563 ISvItemCm_fnRelease,
564 ISvItemCm_fnQueryContextMenu,
565 ISvItemCm_fnInvokeCommand,
566 ISvItemCm_fnGetCommandString,
567 ISvItemCm_fnHandleMenuMsg,
568 (void *) 0xdeadbabe /* just paranoia */