source: trunk/eraser/Eraser.Shell/CtxMenu.h @ 2120

Revision 2120, 4.0 KB checked in by lowjoel, 4 years ago (diff)

Addresses #60: Eraser Secure Cut.

  • Implemented the display and the invocation of the Eraser Secure Paste command.
  • Only respond to Cut operations, ignore copy operations (otherwise we will be cutting the file, not copying it when we paste)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev
RevLine 
[696]1/*
2 * $Id$
[1675]3 * Copyright 2008-2010 The Eraser Project
[696]4 * Original Author: Kasra Nassiri <cjax@users.sourceforge.net>
5 * Modified By: Joel Low <lowjoel@users.sourceforge.net>
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "resource.h"
[703]25#include "ShellExt_i.h"
[696]26
27#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
28#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
29#endif
30
[700]31#include <list>
32#include <vector>
[696]33#include <string>
34
[705]35namespace Eraser
[696]36{
37    class ATL_NO_VTABLE CCtxMenu :
38        public CComObjectRootEx<CComSingleThreadModel>,
39        public CComCoClass<CCtxMenu, &CLSID_CtxMenu>,
40        public IShellExtInit,
41        public IContextMenu3
42    {
43    public:
44        CCtxMenu()
45        {
46        }
47
[715]48        /// The place where the context menu extension was invoked.
49        enum InvokeReasons
50        {
51            INVOKEREASON_FILEFOLDER,
[2119]52            INVOKEREASON_DIRECTORY_BACKGROUND,
[715]53            INVOKEREASON_DRAGDROP,
54            INVOKEREASON_RECYCLEBIN
55        };
56
[2015]57        /// This has the equivalent in Eraser.Program.ShellActions
[716]58        enum Actions
[696]59        {
[716]60            ACTION_ERASE                = 1 << 0,
61            ACTION_ERASE_ON_RESTART     = 1 << 1,
62            ACTION_ERASE_UNUSED_SPACE   = 1 << 2,
63            ACTION_SEPERATOR_1,
64            ACTION_SECURE_MOVE          = 1 << 3,
[2119]65            ACTION_SECURE_PASTE         = 1 << 4
[696]66        };
67
68    public:
69        //IShellExtInit
70        STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY);
71
72        //IContextMenu3
[711]73        STDMETHOD(GetCommandString)(UINT_PTR, UINT, UINT*, LPSTR, UINT);
[696]74        STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO);
75        STDMETHOD(QueryContextMenu)(HMENU, UINT, UINT, UINT, UINT);
76        STDMETHOD(HandleMenuMsg)(UINT, WPARAM, LPARAM);
77        STDMETHOD(HandleMenuMsg2)(UINT, WPARAM, LPARAM, LRESULT*);
78
79    protected:
80        bool OnMeasureItem(UINT& itemWidth, UINT& itemHeight);
81        bool OnDrawItem(HDC hdc, RECT rect, UINT action, UINT state);
82
[716]83        Actions GetApplicableActions();
[698]84
[722]85        static std::wstring LoadString(UINT stringID);
[789]86        static std::wstring FormatString(const std::wstring& formatString, ...);
[1299]87        static std::wstring FormatError(DWORD lastError = static_cast<DWORD>(-1));
[715]88        static std::wstring GetHKeyPath(HKEY handle);
[2120]89        static std::list<std::wstring> GetHDropPaths(HDROP hDrop);
[872]90
91        static bool IsUserAdmin();
[2015]92        static void RunEraser(Actions action, const std::wstring& parameters,
[789]93            bool elevated, HWND parent, int show);
94
[868]95        static void InsertSeparator(HMENU menu);
[696]96        static HICON GetMenuIcon();
[868]97        static HBITMAP GetMenuBitmapFromIcon(HICON icon);
[696]98        static HBITMAP CreateDIB(LONG width, LONG height, char** bitmapBits);
99
100    protected:
[736]101        wchar_t*                    MenuTitle;
[720]102        InvokeReasons               InvokeReason;
103        std::wstring                DragDropDestinationDirectory;
104        std::list<std::wstring>     SelectedFiles;
105        std::vector<Actions>        VerbMenuIndices;
[735]106        UINT                        MenuID;
[696]107
108    public:
[704]109        DECLARE_REGISTRY_RESOURCEID(IDR_ERASERSHELLEXT)
[696]110        DECLARE_NOT_AGGREGATABLE(CCtxMenu)
111        BEGIN_COM_MAP(CCtxMenu)
112            COM_INTERFACE_ENTRY(IShellExtInit)
113            COM_INTERFACE_ENTRY(IContextMenu)
114            COM_INTERFACE_ENTRY(IContextMenu2)
115            COM_INTERFACE_ENTRY(IContextMenu3)
116        END_COM_MAP()
117
118        DECLARE_PROTECT_FINAL_CONSTRUCT()
[735]119        HRESULT FinalConstruct();
120        HRESULT FinalRelease();
[696]121    };
122
123    OBJECT_ENTRY_AUTO(__uuidof(CtxMenu), CCtxMenu)
124}
Note: See TracBrowser for help on using the repository browser.