add property page winapi (not finished, I will implement it)
[reactos.git] / reactos / lib / shell32 / shv_item_cmenu.c
index c5beee9..c517691 100644 (file)
 
 #include <string.h>
 
+#define COBJMACROS
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
+
 #include "winerror.h"
 #include "wine/debug.h"
 
@@ -41,7 +43,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(shell);
 *  IContextMenu Implementation
 */
 typedef struct
-{      ICOM_VFIELD(IContextMenu2);
+{      IContextMenu2Vtbl *lpVtbl;
        DWORD           ref;
        IShellFolder*   pSFParent;
        LPITEMIDLIST    pidl;           /* root pidl */
@@ -51,7 +53,7 @@ typedef struct
 } ItemCmImpl;
 
 
-static struct ICOM_VTABLE(IContextMenu2) cmvt;
+static struct IContextMenu2Vtbl cmvt;
 
 /**************************************************************************
 * ISvItemCm_CanRenameItems()
@@ -80,7 +82,7 @@ IContextMenu2 *ISvItemCm_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST pidl
 {      ItemCmImpl* cm;
        UINT  u;
 
-       cm = (ItemCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ItemCmImpl));
+       cm = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ItemCmImpl));
        cm->lpVtbl = &cmvt;
        cm->ref = 1;
        cm->pidl = ILClone(pidl);
@@ -107,7 +109,7 @@ IContextMenu2 *ISvItemCm_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST pidl
 */
 static HRESULT WINAPI ISvItemCm_fnQueryInterface(IContextMenu2 *iface, REFIID riid, LPVOID *ppvObj)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
 
@@ -139,11 +141,12 @@ static HRESULT WINAPI ISvItemCm_fnQueryInterface(IContextMenu2 *iface, REFIID ri
 */
 static ULONG WINAPI ISvItemCm_fnAddRef(IContextMenu2 *iface)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
+       ULONG refCount = InterlockedIncrement(&This->ref);
 
-       TRACE("(%p)->(count=%lu)\n",This, This->ref);
+       TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
 
-       return ++(This->ref);
+       return refCount;
 }
 
 /**************************************************************************
@@ -151,11 +154,12 @@ static ULONG WINAPI ISvItemCm_fnAddRef(IContextMenu2 *iface)
 */
 static ULONG WINAPI ISvItemCm_fnRelease(IContextMenu2 *iface)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
+       ULONG refCount = InterlockedDecrement(&This->ref);
 
-       TRACE("(%p)->()\n",This);
+       TRACE("(%p)->(count=%li)\n", This, refCount + 1);
 
-       if (!--(This->ref))
+       if (!refCount)
        {
          TRACE(" destroying IContextMenu(%p)\n",This);
 
@@ -169,9 +173,8 @@ static ULONG WINAPI ISvItemCm_fnRelease(IContextMenu2 *iface)
          _ILFreeaPidl(This->apidl, This->cidl);
 
          HeapFree(GetProcessHeap(),0,This);
-         return 0;
        }
-       return This->ref;
+       return refCount;
 }
 
 /**************************************************************************
@@ -218,7 +221,7 @@ static HRESULT WINAPI ISvItemCm_fnQueryContextMenu(
        UINT idCmdLast,
        UINT uFlags)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
 
@@ -251,7 +254,13 @@ static HRESULT WINAPI ISvItemCm_fnQueryContextMenu(
          _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_DELETE, MFT_STRING, "&Delete", MFS_ENABLED);
 
          if(uFlags & CMF_CANRENAME)
+         {
            _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_RENAME, MFT_STRING, "&Rename", ISvItemCm_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED);
+         }
+
+         _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
+         _InsertMenuItem(hmenu, indexMenu++, TRUE, FCIDM_SHVIEW_PROPERTIES, MFT_STRING, "&Properties::", MFS_ENABLED);
+
 
          return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (FCIDM_SHVIEWLAST));
        }
@@ -269,7 +278,7 @@ static void DoOpenExplore(
        HWND hwnd,
        LPCSTR verb)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        UINT i, bFolderFound = FALSE;
        LPITEMIDLIST    pidlFQ;
@@ -310,7 +319,7 @@ static void DoRename(
        IContextMenu2 *iface,
        HWND hwnd)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        LPSHELLBROWSER  lpSB;
        LPSHELLVIEW     lpSV;
@@ -337,7 +346,7 @@ static void DoRename(
  */
 static void DoDelete(IContextMenu2 *iface)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
        ISFHelper * psfhlp;
 
        IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
@@ -358,7 +367,7 @@ static BOOL DoCopyOrCut(
        HWND hwnd,
        BOOL bCut)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        LPSHELLBROWSER  lpSB;
        LPSHELLVIEW     lpSV;
@@ -366,62 +375,20 @@ static BOOL DoCopyOrCut(
 
        TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This, hwnd, bCut);
 
-       if(GetShellOle())
+       /* get the active IShellView */
+       if ((lpSB = (LPSHELLBROWSER)SendMessageA(hwnd, CWM_GETISHELLBROWSER,0,0)))
        {
-         /* get the active IShellView */
-         if ((lpSB = (LPSHELLBROWSER)SendMessageA(hwnd, CWM_GETISHELLBROWSER,0,0)))
+         if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
          {
-           if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
+           if (SUCCEEDED(IShellView_GetItemObject(lpSV, SVGIO_SELECTION, &IID_IDataObject, (LPVOID*)&lpDo)))
            {
-             if (SUCCEEDED(IShellView_GetItemObject(lpSV, SVGIO_SELECTION, &IID_IDataObject, (LPVOID*)&lpDo)))
-             {
-               pOleSetClipboard(lpDo);
-               IDataObject_Release(lpDo);
-             }
-             IShellView_Release(lpSV);
+             OleSetClipboard(lpDo);
+             IDataObject_Release(lpDo);
            }
+           IShellView_Release(lpSV);
          }
        }
        return TRUE;
-#if 0
-/*
-  the following code does the copy operation witout ole32.dll
-  we might need this possibility too (js)
-*/
-       BOOL bSuccess = FALSE;
-
-       TRACE("(%p)\n", iface);
-
-       if(OpenClipboard(NULL))
-       {
-         if(EmptyClipboard())
-         {
-           IPersistFolder2 * ppf2;
-           IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2);
-           if (ppf2)
-           {
-             LPITEMIDLIST pidl;
-             IPersistFolder2_GetCurFolder(ppf2, &pidl);
-             if(pidl)
-             {
-               HGLOBAL hMem;
-
-               hMem = RenderHDROP(pidl, This->apidl, This->cidl);
-
-               if(SetClipboardData(CF_HDROP, hMem))
-               {
-                 bSuccess = TRUE;
-               }
-               SHFree(pidl);
-             }
-             IPersistFolder2_Release(ppf2);
-           }
-
-         }
-         CloseClipboard();
-       }
-       return bSuccess;
-#endif
 }
 /**************************************************************************
 * ISvItemCm_fnInvokeCommand()
@@ -430,7 +397,7 @@ static HRESULT WINAPI ISvItemCm_fnInvokeCommand(
        IContextMenu2 *iface,
        LPCMINVOKECOMMANDINFO lpcmi)
 {
-    ICOM_THIS(ItemCmImpl, iface);
+    ItemCmImpl *This = (ItemCmImpl *)iface;
 
     if (lpcmi->cbSize != sizeof(CMINVOKECOMMANDINFO))
         FIXME("Is an EX structure\n");
@@ -471,6 +438,11 @@ static HRESULT WINAPI ISvItemCm_fnInvokeCommand(
             TRACE("Verb FCIDM_SHVIEW_CUT\n");
             DoCopyOrCut(iface, lpcmi->hwnd, TRUE);
             break;
+        case FCIDM_SHVIEW_PROPERTIES:
+            TRACE("Verb FCIDM_SHVIEW_PROPERTIES\n");
+            /* Open the property sheet page */
+            SHObjectProperties(NULL, TEXT("SHOP_FILEPATH"), lpcmi->hwnd, NULL);
+            break;
         default:
             FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi->lpVerb));
         }
@@ -497,7 +469,7 @@ static HRESULT WINAPI ISvItemCm_fnGetCommandString(
        LPSTR lpszName,
        UINT uMaxNameLen)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        HRESULT  hr = E_INVALIDARG;
 
@@ -552,16 +524,15 @@ static HRESULT WINAPI ISvItemCm_fnHandleMenuMsg(
        WPARAM wParam,
        LPARAM lParam)
 {
-       ICOM_THIS(ItemCmImpl, iface);
+       ItemCmImpl *This = (ItemCmImpl *)iface;
 
        TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
 
        return E_NOTIMPL;
 }
 
-static struct ICOM_VTABLE(IContextMenu2) cmvt =
+static struct IContextMenu2Vtbl cmvt =
 {
-       ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
        ISvItemCm_fnQueryInterface,
        ISvItemCm_fnAddRef,
        ISvItemCm_fnRelease,