Add context menu to delete all tags in Reference Browser
[TortoiseGit.git] / src / TortoiseShell / ShellExt.h
blobf8230958950d83f7ca53dfc701d73033d55108c0
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
21 #include "Globals.h"
22 #include "registry.h"
23 #include "resource.h"
24 #include "ShellCache.h"
25 #include "RemoteCacheLink.h"
26 #include "GitStatus.h"
27 #include "GitFolderStatus.h"
28 #include "uxtheme.h"
29 #include "MenuInfo.h"
30 #include "CrashReport.h"
32 extern volatile LONG g_cRefThisDll; // Reference count of this DLL.
33 extern HINSTANCE g_hmodThisDll; // Instance handle for this DLL
34 extern ShellCache g_ShellCache; // caching of registry entries, ...
35 extern DWORD g_langid;
36 extern DWORD g_langTimeout;
37 extern HINSTANCE g_hResInst;
38 extern stdstring g_filepath;
39 extern git_wc_status_kind g_filestatus; ///< holds the corresponding status to the file/dir above
40 extern bool g_readonlyoverlay; ///< whether to show the read only overlay or not
41 extern bool g_lockedoverlay; ///< whether to show the locked overlay or not
43 extern bool g_normalovlloaded;
44 extern bool g_modifiedovlloaded;
45 extern bool g_conflictedovlloaded;
46 extern bool g_readonlyovlloaded;
47 extern bool g_deletedovlloaded;
48 extern bool g_lockedovlloaded;
49 extern bool g_addedovlloaded;
50 extern bool g_ignoredovlloaded;
51 extern bool g_unversionedovlloaded;
52 extern LPCTSTR g_MenuIDString;
54 extern void LoadLangDll();
55 extern CComCriticalSection g_csGlobalCOMGuard;
56 typedef CComCritSecLock<CComCriticalSection> AutoLocker;
58 typedef DWORD ARGB;
60 typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow);
61 typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc);
62 typedef HRESULT (WINAPI *FN_EndBufferedPaint) (HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget);
65 // The actual OLE Shell context menu handler
66 /**
67 * \ingroup TortoiseShell
68 * The main class of our COM object / Shell Extension.
69 * It contains all Interfaces we implement for the shell to use.
70 * \remark The implementations of the different interfaces are
71 * split into several *.cpp files to keep them in a reasonable size.
73 class CShellExt : public IContextMenu3,
74 IPersistFile,
75 IColumnProvider,
76 IShellExtInit,
77 IShellIconOverlayIdentifier,
78 IShellPropSheetExt,
79 ICopyHookW
81 // COMPILER ERROR? You need the latest version of the
82 // platform SDK which has references to IColumnProvider
83 // in the header files. Download it here:
84 // http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
86 protected:
88 FileState m_State;
89 ULONG m_cRef;
90 //std::map<int,std::string> verbMap;
91 std::map<UINT_PTR, UINT_PTR> myIDMap;
92 std::map<UINT_PTR, UINT_PTR> mySubMenuMap;
93 std::map<stdstring, UINT_PTR> myVerbsMap;
94 std::map<UINT_PTR, stdstring> myVerbsIDMap;
95 stdstring folder_;
96 std::vector<stdstring> files_;
97 DWORD itemStates; ///< see the globals.h file for the ITEMIS_* defines
98 DWORD itemStatesFolder; ///< used for states of the folder_ (folder background and/or drop target folder)
99 stdstring uuidSource;
100 stdstring uuidTarget;
101 int space;
102 TCHAR stringtablebuffer[255];
103 stdstring columnfilepath; ///< holds the last file/dir path for the column provider
104 stdstring columnauthor; ///< holds the corresponding author of the file/dir above
105 stdstring itemurl;
106 stdstring itemshorturl;
107 stdstring ignoredprops;
108 git_revnum_t columnrev; ///< holds the corresponding revision to the file/dir above
109 git_wc_status_kind filestatus;
110 std::map<UINT, HBITMAP> bitmaps;
112 GitFolderStatus m_CachedStatus; // status cache
113 CRemoteCacheLink m_remoteCacheLink;
115 FN_GetBufferedPaintBits pfnGetBufferedPaintBits;
116 FN_BeginBufferedPaint pfnBeginBufferedPaint;
117 FN_EndBufferedPaint pfnEndBufferedPaint;
119 CCrashReportTGit m_crasher;
121 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, _countof(stringtablebuffer), (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
122 private:
123 void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);
124 bool InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);
125 stdstring WriteFileListToTempFile();
126 bool WriteClipboardPathsToTempFile(stdstring& tempfile);
127 LPCTSTR GetMenuTextFromResource(int id);
128 void GetColumnStatus(const TCHAR * path, BOOL bIsDir);
129 void GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci, UINT characterCount, UINT title, UINT description);
130 bool ShouldInsertItem(const MenuInfo& pair) const;
131 bool ShouldEnableMenu(const YesNoPair& pair) const;
132 void TweakMenu(HMENU menu);
133 void AddPathCommand(tstring& gitCmd, LPCTSTR command, bool bFilesAllowed);
134 void AddPathFileCommand(tstring& gitCmd, LPCTSTR command);
135 void AddPathFileDropCommand(tstring& gitCmd, LPCTSTR command);
136 HBITMAP IconToBitmap(UINT uIcon);
137 STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);
138 bool IsIllegalFolder(std::wstring folder, int * cslidarray);
139 static void RunCommand(const tstring& path, const tstring& command, LPCTSTR errorMessage);
140 HBITMAP IconToBitmapPARGB32(UINT uIcon);
141 HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp);
142 HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon);
143 bool HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow);
144 HRESULT ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow);
146 /** \name IContextMenu2 wrappers
147 * IContextMenu2 wrapper functions to catch exceptions and send crash reports
149 //@{
150 STDMETHODIMP QueryContextMenu_Wrap(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
151 STDMETHODIMP InvokeCommand_Wrap(LPCMINVOKECOMMANDINFO lpcmi);
152 STDMETHODIMP GetCommandString_Wrap(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
153 STDMETHODIMP HandleMenuMsg_Wrap(UINT uMsg, WPARAM wParam, LPARAM lParam);
154 //@}
156 /** \name IContextMenu3 wrappers
157 * IContextMenu3 wrapper functions to catch exceptions and send crash reports
159 //@{
160 STDMETHODIMP HandleMenuMsg2_Wrap(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
161 //@}
163 /** \name IColumnProvider wrappers
164 * IColumnProvider wrapper functions to catch exceptions and send crash reports
166 //@{
167 STDMETHODIMP GetColumnInfo_Wrap(DWORD dwIndex, SHCOLUMNINFO *psci);
168 STDMETHODIMP GetItemData_Wrap(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
169 STDMETHODIMP Initialize_Wrap(LPCSHCOLUMNINIT psci);
170 //@}
172 /** \name IShellExtInit wrappers
173 * IShellExtInit wrapper functions to catch exceptions and send crash reports
175 //@{
176 STDMETHODIMP Initialize_Wrap(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
177 //@}
179 /** \name IShellIconOverlayIdentifier wrappers
180 * IShellIconOverlayIdentifier wrapper functions to catch exceptions and send crash reports
182 //@{
183 STDMETHODIMP GetOverlayInfo_Wrap(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
184 STDMETHODIMP GetPriority_Wrap(int *pPriority);
185 STDMETHODIMP IsMemberOf_Wrap(LPCWSTR pwszPath, DWORD dwAttrib);
186 //@}
188 /** \name IShellPropSheetExt wrappers
189 * IShellPropSheetExt wrapper functions to catch exceptions and send crash reports
191 //@{
192 STDMETHODIMP AddPages_Wrap(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
193 //STDMETHODIMP ReplacePage_Wrap(UINT, LPFNADDPROPSHEETPAGE, LPARAM);
194 //@}
196 /** \name ICopyHook wrapper
197 * ICopyHook wrapper functions to catch exceptions and send crash reports
199 //@{
200 STDMETHODIMP_(UINT) CopyCallback_Wrap(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
201 //@}
203 public:
204 CShellExt(FileState state);
205 virtual ~CShellExt();
207 /** \name IUnknown
208 * IUnknown members
210 //@{
211 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
212 STDMETHODIMP_(ULONG) AddRef();
213 STDMETHODIMP_(ULONG) Release();
214 //@}
216 /** \name IContextMenu2
217 * IContextMenu2 members
219 //@{
220 STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
221 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
222 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
223 STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
224 //@}
226 /** \name IContextMenu3
227 * IContextMenu3 members
229 //@{
230 STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
231 //@}
233 /** \name IColumnProvider
234 * IColumnProvider members
236 //@{
237 STDMETHODIMP GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci);
238 STDMETHODIMP GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
239 STDMETHODIMP Initialize(LPCSHCOLUMNINIT psci);
240 //@}
242 /** \name IShellExtInit
243 * IShellExtInit methods
245 //@{
246 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
247 //@}
249 /** \name IPersistFile
250 * IPersistFile methods
252 //@{
253 STDMETHODIMP GetClassID(CLSID *pclsid);
254 STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
255 STDMETHODIMP IsDirty(void) { return S_OK; };
256 STDMETHODIMP Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) { return S_OK; };
257 STDMETHODIMP SaveCompleted(LPCOLESTR /*pszFileName*/) { return S_OK; };
258 STDMETHODIMP GetCurFile(LPOLESTR * /*ppszFileName*/) { return S_OK; };
259 //@}
261 /** \name IShellIconOverlayIdentifier
262 * IShellIconOverlayIdentifier methods
264 //@{
265 STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
266 STDMETHODIMP GetPriority(int *pPriority);
267 STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);
268 //@}
270 /** \name IShellPropSheetExt
271 * IShellPropSheetExt methods
273 //@{
274 STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
275 STDMETHODIMP ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM);
276 //@}
278 /** \name ICopyHook
279 * ICopyHook members
281 //@{
282 STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
283 //@}