| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * Copyright 2008 The Eraser Project |
|---|
| 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" |
|---|
| 25 | #include "ShellExt_i.h" |
|---|
| 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 | |
|---|
| 31 | #include <list> |
|---|
| 32 | #include <vector> |
|---|
| 33 | #include <string> |
|---|
| 34 | |
|---|
| 35 | namespace Eraser |
|---|
| 36 | { |
|---|
| 37 | typedef std::wstring string_type; |
|---|
| 38 | typedef std::list<string_type> string_list; |
|---|
| 39 | |
|---|
| 40 | class ATL_NO_VTABLE CCtxMenu : |
|---|
| 41 | public CComObjectRootEx<CComSingleThreadModel>, |
|---|
| 42 | public CComCoClass<CCtxMenu, &CLSID_CtxMenu>, |
|---|
| 43 | public IShellExtInit, |
|---|
| 44 | public IContextMenu3 |
|---|
| 45 | { |
|---|
| 46 | public: |
|---|
| 47 | CCtxMenu() |
|---|
| 48 | { |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /// The place where the context menu extension was invoked. |
|---|
| 52 | enum InvokeReasons |
|---|
| 53 | { |
|---|
| 54 | INVOKEREASON_FILEFOLDER, |
|---|
| 55 | INVOKEREASON_DRAGDROP, |
|---|
| 56 | INVOKEREASON_RECYCLEBIN |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | enum Actions |
|---|
| 60 | { |
|---|
| 61 | ACTION_ERASE = 1 << 0, |
|---|
| 62 | ACTION_ERASE_ON_RESTART = 1 << 1, |
|---|
| 63 | ACTION_ERASE_UNUSED_SPACE = 1 << 2, |
|---|
| 64 | ACTION_SEPERATOR_1, |
|---|
| 65 | ACTION_SECURE_MOVE = 1 << 3, |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | public: |
|---|
| 69 | //IShellExtInit |
|---|
| 70 | STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY); |
|---|
| 71 | |
|---|
| 72 | //IContextMenu3 |
|---|
| 73 | STDMETHOD(GetCommandString)(UINT_PTR, UINT, UINT*, LPSTR, UINT); |
|---|
| 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 | |
|---|
| 83 | Actions GetApplicableActions(); |
|---|
| 84 | |
|---|
| 85 | static std::wstring GetHKeyPath(HKEY handle); |
|---|
| 86 | static MENUITEMINFO* GetSeparator(); |
|---|
| 87 | static HICON GetMenuIcon(); |
|---|
| 88 | static HBITMAP GetMenuBitmap(); |
|---|
| 89 | static HBITMAP CreateDIB(LONG width, LONG height, char** bitmapBits); |
|---|
| 90 | |
|---|
| 91 | protected: |
|---|
| 92 | static const wchar_t* MenuTitle; |
|---|
| 93 | |
|---|
| 94 | InvokeReasons InvokeReason; |
|---|
| 95 | UINT MenuID; |
|---|
| 96 | std::wstring DragDropDestinationDirectory; |
|---|
| 97 | std::list<std::wstring> SelectedFiles; |
|---|
| 98 | std::vector<Actions> VerbMenuIndices; |
|---|
| 99 | |
|---|
| 100 | public: |
|---|
| 101 | DECLARE_REGISTRY_RESOURCEID(IDR_ERASERSHELLEXT) |
|---|
| 102 | DECLARE_NOT_AGGREGATABLE(CCtxMenu) |
|---|
| 103 | BEGIN_COM_MAP(CCtxMenu) |
|---|
| 104 | COM_INTERFACE_ENTRY(IShellExtInit) |
|---|
| 105 | COM_INTERFACE_ENTRY(IContextMenu) |
|---|
| 106 | COM_INTERFACE_ENTRY(IContextMenu2) |
|---|
| 107 | COM_INTERFACE_ENTRY(IContextMenu3) |
|---|
| 108 | END_COM_MAP() |
|---|
| 109 | |
|---|
| 110 | DECLARE_PROTECT_FINAL_CONSTRUCT() |
|---|
| 111 | HRESULT FinalConstruct() |
|---|
| 112 | { |
|---|
| 113 | return S_OK; |
|---|
| 114 | } |
|---|
| 115 | }; |
|---|
| 116 | |
|---|
| 117 | OBJECT_ENTRY_AUTO(__uuidof(CtxMenu), CCtxMenu) |
|---|
| 118 | } |
|---|