1   /************************************************************************
  2           Copy Handler 1.x - program for copying data     in Microsoft Windows
  3                                                    systems.
  4           Copyright (C) 2001-2004 Ixen Gerthannes (copyhandler@o2.pl)
  5  
  6           This program is free software; you can redistribute it and/or modify
  7           it under the terms of the GNU General Public License as published by
  8           the Free Software Foundation; either version 2 of the License, or
  9           (at your option) any later version.
  10  
  11           This program 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
  14           GNU General Public License for more details.
  15  
  16           You should have received a copy of the GNU General Public License
  17           along with this program; if not, write to the Free Software
  18           Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19   *************************************************************************/
  20  
  21   #ifndef __MENUEXT_H_
  22   #define __MENUEXT_H_
  23  
  24   #include "resource.h"       // main symbols
  25   #include "comdef.h"
  26  
  27   #include "IShellExtInitImpl.h"
  28   #include "IContextMenuImpl.h"
  29  
  30   ///////
  31   // globals
  32   void CutAmpersands(LPTSTR lpszString);
  33  
  34   /////////////////////////////////////////////////////////////////////////////
  35   // CMenuExt
  36   class ATL_NO_VTABLE CMenuExt :
  37           public CComObjectRootEx<CComSingleThreadModel>,
  38           public CComCoClass<CMenuExt, &CLSID_MenuExt>,
  39           public IObjectWithSiteImpl<CMenuExt>,
  40           public IDispatchImpl<IMenuExt, &IID_IMenuExt, &LIBID_COPYHANDLERSHELLEXTLib>,
  41           public IShellExtInitImpl,
  42           public IContextMenuImpl
  43   {
  44   public:
  45           CMenuExt()
  46           {
  47           }
  48   public:
  49           // class for making sure memory is freed
  50           class CBuffer
  51           {
  52           public:
  53                   CBuffer() { m_pszFiles=NULL; m_iDataSize=0; };
  54                   void Destroy() { delete [] m_pszFiles; m_pszFiles=NULL; m_iDataSize=0; };
  55                   ~CBuffer() { Destroy(); };
  56  
  57           public:
  58                   TCHAR *m_pszFiles;
  59                   UINT m_iDataSize;
  60           } m_bBuffer;
  61  
  62           TCHAR m_szDstPath[_MAX_PATH];
  63  
  64           // for making sure DestroyMenu would be called
  65           class CSubMenus
  66           {
  67           public:
  68                   CSubMenus() { hShortcuts[0]=NULL; hShortcuts[1]=NULL; hShortcuts[2]=NULL; };
  69                   void Destroy() { for (int i=0;i<3;i++) { if (hShortcuts[i] != NULL) DestroyMenu(hShortcuts[i]); } };
  70                   ~CSubMenus() { Destroy(); };
  71  
  72           public:
  73                   HMENU hShortcuts[3];
  74           } m_mMenus;
  75  
  76           bool m_bBackground;             // folder or folder background
  77           bool m_bGroupFiles;             // if the group of files have a files in it
  78  
  79           UINT m_uiFirstID;               // first menu ID
  80           bool m_bShown;                  // have the menu been already shown ?czy pokazano ju� menu
  81  
  82   DECLARE_REGISTRY_RESOURCEID(IDR_MENUEXT)
  83   DECLARE_NOT_AGGREGATABLE(CMenuExt)
  84  
  85   DECLARE_PROTECT_FINAL_CONSTRUCT()
  86  
  87   BEGIN_COM_MAP(CMenuExt)
  88           COM_INTERFACE_ENTRY(IMenuExt)
  89           COM_INTERFACE_ENTRY(IDispatch)
  90           COM_INTERFACE_ENTRY(IShellExtInit)
  91           COM_INTERFACE_ENTRY(IContextMenu)
  92           COM_INTERFACE_ENTRY(IContextMenu2)
  93           COM_INTERFACE_ENTRY(IContextMenu3)
  94           COM_INTERFACE_ENTRY(IObjectWithSite)
  95   END_COM_MAP()
  96  
  97   // IMenuExt
  98   public:
  99           STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/);
  100           STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici);
  101           STDMETHOD(GetCommandString)(UINT idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax);
  102           STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/);
  103           STDMETHOD(HandleMenuMsg)(UINT uMsg, WPARAM wParam, LPARAM lParam);
  104           STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult);
  105  
  106   protected:
  107           void DrawMenuItem(LPDRAWITEMSTRUCT lpdis);
  108           void CreateShortcutsMenu(UINT uiIDBase, bool bOwnerDrawn);
  109   };
  110  
  111   #endif //__MENUEXT_H_