Add "Send Mail " for .patch and .diff file.
[TortoiseGit.git] / src / TortoiseShell / ShellExt.h
blob190276c827634ae1ed3bff72313814959de1c29b
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - 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"
30 extern UINT g_cRefThisDll; // Reference count of this DLL.
31 extern HINSTANCE g_hmodThisDll; // Instance handle for this DLL
32 extern ShellCache g_ShellCache; // caching of registry entries, ...
33 extern DWORD g_langid;
34 extern DWORD g_langTimeout;
35 extern HINSTANCE g_hResInst;
36 extern stdstring g_filepath;
37 extern git_wc_status_kind g_filestatus; ///< holds the corresponding status to the file/dir above
38 extern bool g_readonlyoverlay; ///< whether to show the read only overlay or not
39 extern bool g_lockedoverlay; ///< whether to show the locked overlay or not
41 extern bool g_normalovlloaded;
42 extern bool g_modifiedovlloaded;
43 extern bool g_conflictedovlloaded;
44 extern bool g_readonlyovlloaded;
45 extern bool g_deletedovlloaded;
46 extern bool g_lockedovlloaded;
47 extern bool g_addedovlloaded;
48 extern bool g_ignoredovlloaded;
49 extern bool g_unversionedovlloaded;
50 extern LPCTSTR g_MenuIDString;
52 extern void LoadLangDll();
53 extern CComCriticalSection g_csGlobalCOMGuard;
54 typedef CComCritSecLock<CComCriticalSection> AutoLocker;
56 typedef DWORD ARGB;
58 typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow);
59 typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc);
60 typedef HRESULT (WINAPI *FN_EndBufferedPaint) (HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget);
63 // The actual OLE Shell context menu handler
64 /**
65 * \ingroup TortoiseShell
66 * The main class of our COM object / Shell Extension.
67 * It contains all Interfaces we implement for the shell to use.
68 * \remark The implementations of the different interfaces are
69 * split into several *.cpp files to keep them in a reasonable size.
71 class CShellExt : public IContextMenu3,
72 IPersistFile,
73 IColumnProvider,
74 IShellExtInit,
75 IShellIconOverlayIdentifier,
76 IShellPropSheetExt,
77 ICopyHookW
79 // COMPILER ERROR? You need the latest version of the
80 // platform SDK which has references to IColumnProvider
81 // in the header files. Download it here:
82 // http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
84 protected:
86 enum GitCommands
88 ShellSeparator = 0,
89 ShellSubMenu = 1,
90 ShellSubMenuFolder,
91 ShellSubMenuFile,
92 ShellSubMenuLink,
93 ShellSubMenuMultiple,
94 ShellMenuCheckout,
95 ShellMenuUpdate,
96 ShellMenuCommit,
97 ShellMenuAdd,
98 ShellMenuAddAsReplacement,
99 ShellMenuRevert,
100 ShellMenuCleanup,
101 ShellMenuResolve,
102 ShellMenuSwitch,
103 ShellMenuImport,
104 ShellMenuExport,
105 ShellMenuAbout,
106 ShellMenuCreateRepos,
107 ShellMenuCopy,
108 ShellMenuMerge,
109 ShellMenuMergeAll,
110 ShellMenuSettings,
111 ShellMenuRemove,
112 ShellMenuRemoveKeep,
113 ShellMenuRename,
114 ShellMenuUpdateExt,
115 ShellMenuDiff,
116 ShellMenuPrevDiff,
117 ShellMenuUrlDiff,
118 ShellMenuDropCopyAdd,
119 ShellMenuDropMoveAdd,
120 ShellMenuDropMove,
121 ShellMenuDropMoveRename,
122 ShellMenuDropCopy,
123 ShellMenuDropCopyRename,
124 ShellMenuDropExport,
125 ShellMenuDropExportExtended,
126 ShellMenuLog,
127 ShellMenuConflictEditor,
128 ShellMenuRelocate,
129 ShellMenuHelp,
130 ShellMenuShowChanged,
131 ShellMenuIgnoreSub,
132 ShellMenuIgnore,
133 ShellMenuIgnoreFile,
134 ShellMenuIgnoreCaseSensitive,
135 ShellMenuIgnoreCaseInsensitive,
136 ShellMenuRefLog,
137 ShellMenuBlame,
138 ShellMenuApplyPatch,
139 ShellMenuCreatePatch,
140 ShellMenuRevisionGraph,
141 ShellMenuUnIgnoreSub,
142 ShellMenuUnIgnoreCaseSensitive,
143 ShellMenuUnIgnore,
144 // ShellMenuLock,
145 // ShellMenuUnlock,
146 // ShellMenuUnlockForce,
147 ShellMenuProperties,
148 ShellMenuDelUnversioned,
149 ShellMenuClipPaste,
150 ShellMenuPull,
151 ShellMenuPush,
152 ShellMenuClone,
153 ShellMenuBranch,
154 ShellMenuTag,
155 ShellMenuFormatPatch,
156 ShellMenuImportPatch,
157 ShellMenuCherryPick,
158 ShellMenuFetch,
159 ShellMenuRebase,
160 ShellMenuStashSave,
161 ShellMenuStashApply,
162 ShellMenuStashList,
163 ShellMenuSubAdd,
164 ShellMenuSubSync,
165 ShellMenuSendMail,
166 ShellMenuLastEntry // used to mark the menu array end
169 // helper struct for context menu entries
170 typedef struct MenuInfo
172 GitCommands command; ///< the command which gets executed for this menu entry
173 unsigned __int64 menuID; ///< the menu ID to recognize the entry. NULL if it shouldn't be added to the context menu automatically
174 UINT iconID; ///< the icon to show for the menu entry
175 UINT menuTextID; ///< the text of the menu entry
176 UINT menuDescID; ///< the description text for the menu entry
177 /// the following 8 params are for checking whether the menu entry should
178 /// be added automatically, based on states of the selected item(s).
179 /// The 'yes' states must be set, the 'no' states must not be set
180 /// the four pairs are OR'ed together, the 'yes'/'no' states are AND'ed together.
181 DWORD firstyes;
182 DWORD firstno;
183 DWORD secondyes;
184 DWORD secondno;
185 DWORD thirdyes;
186 DWORD thirdno;
187 DWORD fourthyes;
188 DWORD fourthno;
191 static MenuInfo menuInfo[];
192 WORD fullver;
193 FileState m_State;
194 ULONG m_cRef;
195 //std::map<int,std::string> verbMap;
196 std::map<UINT_PTR, UINT_PTR> myIDMap;
197 std::map<UINT_PTR, UINT_PTR> mySubMenuMap;
198 std::map<stdstring, UINT_PTR> myVerbsMap;
199 std::map<UINT_PTR, stdstring> myVerbsIDMap;
200 stdstring folder_;
201 std::vector<stdstring> files_;
202 DWORD itemStates; ///< see the globals.h file for the ITEMIS_* defines
203 DWORD itemStatesFolder; ///< used for states of the folder_ (folder background and/or drop target folder)
204 stdstring uuidSource;
205 stdstring uuidTarget;
206 int space;
207 TCHAR stringtablebuffer[255];
208 stdstring columnfilepath; ///< holds the last file/dir path for the column provider
209 stdstring columnauthor; ///< holds the corresponding author of the file/dir above
210 stdstring itemurl;
211 stdstring itemshorturl;
212 stdstring ignoredprops;
213 stdstring owner;
214 git_revnum_t columnrev; ///< holds the corresponding revision to the file/dir above
215 git_wc_status_kind filestatus;
216 std::map<UINT, HBITMAP> bitmaps;
218 GitFolderStatus m_CachedStatus; // status cache
219 CRemoteCacheLink m_remoteCacheLink;
221 FN_GetBufferedPaintBits pfnGetBufferedPaintBits;
222 FN_BeginBufferedPaint pfnBeginBufferedPaint;
223 FN_EndBufferedPaint pfnEndBufferedPaint;
225 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, sizeof(stringtablebuffer)/sizeof(TCHAR), (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
226 private:
227 void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);
228 void InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);
229 stdstring WriteFileListToTempFile();
230 bool WriteClipboardPathsToTempFile(stdstring& tempfile);
231 LPCTSTR GetMenuTextFromResource(int id);
232 void GetColumnStatus(const TCHAR * path, BOOL bIsDir);
233 HBITMAP IconToBitmap(UINT uIcon);
234 STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);
235 bool IsIllegalFolder(std::wstring folder, int * cslidarray);
236 HBITMAP IconToBitmapPARGB32(UINT uIcon);
237 HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp);
238 HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon);
239 bool HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow);
240 HRESULT ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow);
243 public:
244 CShellExt(FileState state);
245 virtual ~CShellExt();
247 /** \name IUnknown
248 * IUnknown members
250 //@{
251 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
252 STDMETHODIMP_(ULONG) AddRef();
253 STDMETHODIMP_(ULONG) Release();
254 //@}
256 /** \name IContextMenu2
257 * IContextMenu2 members
259 //@{
260 STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
261 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
262 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
263 STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
264 //@}
266 /** \name IContextMenu3
267 * IContextMenu3 members
269 //@{
270 STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
271 //@}
273 /** \name IColumnProvider
274 * IColumnProvider members
276 //@{
277 STDMETHODIMP GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci);
278 STDMETHODIMP GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
279 STDMETHODIMP Initialize(LPCSHCOLUMNINIT psci);
280 //@}
282 /** \name IShellExtInit
283 * IShellExtInit methods
285 //@{
286 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
287 //@}
289 /** \name IPersistFile
290 * IPersistFile methods
292 //@{
293 STDMETHODIMP GetClassID(CLSID *pclsid);
294 STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
295 STDMETHODIMP IsDirty(void) { return S_OK; };
296 STDMETHODIMP Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) { return S_OK; };
297 STDMETHODIMP SaveCompleted(LPCOLESTR /*pszFileName*/) { return S_OK; };
298 STDMETHODIMP GetCurFile(LPOLESTR * /*ppszFileName*/) { return S_OK; };
299 //@}
301 /** \name IShellIconOverlayIdentifier
302 * IShellIconOverlayIdentifier methods
304 //@{
305 STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
306 STDMETHODIMP GetPriority(int *pPriority);
307 STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);
308 //@}
310 /** \name IShellPropSheetExt
311 * IShellPropSheetExt methods
313 //@{
314 STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
315 STDMETHODIMP ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM);
316 //@}
318 /** \name ICopyHook
319 * ICopyHook members
321 //@{
322 STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
323 //@}