1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 #include "Globals.h"
\r
22 #include "registry.h"
\r
23 #include "resource.h"
\r
24 #include "ShellCache.h"
\r
25 #include "RemoteCacheLink.h"
\r
26 #include "GitStatus.h"
\r
27 #include "GitFolderStatus.h"
\r
28 #include "uxtheme.h"
\r
30 extern UINT g_cRefThisDll; // Reference count of this DLL.
\r
31 extern HINSTANCE g_hmodThisDll; // Instance handle for this DLL
\r
32 extern ShellCache g_ShellCache; // caching of registry entries, ...
\r
33 extern DWORD g_langid;
\r
34 extern DWORD g_langTimeout;
\r
35 extern HINSTANCE g_hResInst;
\r
36 extern stdstring g_filepath;
\r
37 extern git_wc_status_kind g_filestatus; ///< holds the corresponding status to the file/dir above
\r
38 extern bool g_readonlyoverlay; ///< whether to show the read only overlay or not
\r
39 extern bool g_lockedoverlay; ///< whether to show the locked overlay or not
\r
41 extern bool g_normalovlloaded;
\r
42 extern bool g_modifiedovlloaded;
\r
43 extern bool g_conflictedovlloaded;
\r
44 extern bool g_readonlyovlloaded;
\r
45 extern bool g_deletedovlloaded;
\r
46 extern bool g_lockedovlloaded;
\r
47 extern bool g_addedovlloaded;
\r
48 extern bool g_ignoredovlloaded;
\r
49 extern bool g_unversionedovlloaded;
\r
50 extern LPCTSTR g_MenuIDString;
\r
52 extern void LoadLangDll();
\r
53 extern CComCriticalSection g_csGlobalCOMGuard;
\r
54 typedef CComCritSecLock<CComCriticalSection> AutoLocker;
\r
58 typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow);
\r
59 typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc);
\r
60 typedef HRESULT (WINAPI *FN_EndBufferedPaint) (HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget);
\r
63 // The actual OLE Shell context menu handler
\r
65 * \ingroup TortoiseShell
\r
66 * The main class of our COM object / Shell Extension.
\r
67 * It contains all Interfaces we implement for the shell to use.
\r
68 * \remark The implementations of the different interfaces are
\r
69 * split into several *.cpp files to keep them in a reasonable size.
\r
71 class CShellExt : public IContextMenu3,
\r
75 IShellIconOverlayIdentifier,
\r
79 // COMPILER ERROR? You need the latest version of the
\r
80 // platform SDK which has references to IColumnProvider
\r
81 // in the header files. Download it here:
\r
82 // http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
\r
93 ShellSubMenuMultiple,
\r
98 ShellMenuAddAsReplacement,
\r
106 ShellMenuCreateRepos,
\r
112 ShellMenuRemoveKeep,
\r
114 ShellMenuUpdateExt,
\r
119 ShellMenuDropCopyAdd,
\r
120 ShellMenuDropMoveAdd,
\r
122 ShellMenuDropMoveRename,
\r
124 ShellMenuDropCopyRename,
\r
125 ShellMenuDropExport,
\r
126 ShellMenuDropExportExtended,
\r
128 ShellMenuConflictEditor,
\r
131 ShellMenuShowChanged,
\r
132 ShellMenuIgnoreSub,
\r
134 ShellMenuIgnoreFile,
\r
135 ShellMenuIgnoreCaseSensitive,
\r
136 ShellMenuIgnoreCaseInsensitive,
\r
138 ShellMenuRefBrowse,
\r
140 ShellMenuApplyPatch,
\r
141 ShellMenuCreatePatch,
\r
142 ShellMenuRevisionGraph,
\r
143 ShellMenuUnIgnoreSub,
\r
144 ShellMenuUnIgnoreCaseSensitive,
\r
147 // ShellMenuUnlock,
\r
148 // ShellMenuUnlockForce,
\r
149 ShellMenuProperties,
\r
150 ShellMenuDelUnversioned,
\r
151 ShellMenuClipPaste,
\r
157 ShellMenuFormatPatch,
\r
158 ShellMenuImportPatch,
\r
159 ShellMenuCherryPick,
\r
162 ShellMenuStashSave,
\r
163 ShellMenuStashApply,
\r
164 ShellMenuStashList,
\r
169 ShellMenuGitSVNRebase,
\r
170 ShellMenuGitSVNDCommit,
\r
171 ShellMenuGitSVNIgnore, //import svn ignore
\r
173 ShellMenuLastEntry // used to mark the menu array end
\r
176 // helper struct for context menu entries
\r
177 typedef struct MenuInfo
\r
179 GitCommands command; ///< the command which gets executed for this menu entry
\r
180 unsigned __int64 menuID; ///< the menu ID to recognize the entry. NULL if it shouldn't be added to the context menu automatically
\r
181 UINT iconID; ///< the icon to show for the menu entry
\r
182 UINT menuTextID; ///< the text of the menu entry
\r
183 UINT menuDescID; ///< the description text for the menu entry
\r
184 /// the following 8 params are for checking whether the menu entry should
\r
185 /// be added automatically, based on states of the selected item(s).
\r
186 /// The 'yes' states must be set, the 'no' states must not be set
\r
187 /// the four pairs are OR'ed together, the 'yes'/'no' states are AND'ed together.
\r
198 static MenuInfo menuInfo[];
\r
202 //std::map<int,std::string> verbMap;
\r
203 std::map<UINT_PTR, UINT_PTR> myIDMap;
\r
204 std::map<UINT_PTR, UINT_PTR> mySubMenuMap;
\r
205 std::map<stdstring, UINT_PTR> myVerbsMap;
\r
206 std::map<UINT_PTR, stdstring> myVerbsIDMap;
\r
208 std::vector<stdstring> files_;
\r
209 DWORD itemStates; ///< see the globals.h file for the ITEMIS_* defines
\r
210 DWORD itemStatesFolder; ///< used for states of the folder_ (folder background and/or drop target folder)
\r
211 stdstring uuidSource;
\r
212 stdstring uuidTarget;
\r
214 TCHAR stringtablebuffer[255];
\r
215 stdstring columnfilepath; ///< holds the last file/dir path for the column provider
\r
216 stdstring columnauthor; ///< holds the corresponding author of the file/dir above
\r
218 stdstring itemshorturl;
\r
219 stdstring ignoredprops;
\r
221 git_revnum_t columnrev; ///< holds the corresponding revision to the file/dir above
\r
222 git_wc_status_kind filestatus;
\r
223 std::map<UINT, HBITMAP> bitmaps;
\r
225 GitFolderStatus m_CachedStatus; // status cache
\r
226 CRemoteCacheLink m_remoteCacheLink;
\r
228 FN_GetBufferedPaintBits pfnGetBufferedPaintBits;
\r
229 FN_BeginBufferedPaint pfnBeginBufferedPaint;
\r
230 FN_EndBufferedPaint pfnEndBufferedPaint;
\r
232 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, sizeof(stringtablebuffer)/sizeof(TCHAR), (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
\r
234 void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);
\r
235 void InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);
\r
236 stdstring WriteFileListToTempFile();
\r
237 bool WriteClipboardPathsToTempFile(stdstring& tempfile);
\r
238 LPCTSTR GetMenuTextFromResource(int id);
\r
239 void GetColumnStatus(const TCHAR * path, BOOL bIsDir);
\r
240 HBITMAP IconToBitmap(UINT uIcon);
\r
241 STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);
\r
242 bool IsIllegalFolder(std::wstring folder, int * cslidarray);
\r
243 HBITMAP IconToBitmapPARGB32(UINT uIcon);
\r
244 HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp);
\r
245 HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon);
\r
246 bool HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow);
\r
247 HRESULT ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow);
\r
251 CShellExt(FileState state);
\r
252 virtual ~CShellExt();
\r
254 /** \name IUnknown
\r
258 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
\r
259 STDMETHODIMP_(ULONG) AddRef();
\r
260 STDMETHODIMP_(ULONG) Release();
\r
263 /** \name IContextMenu2
\r
264 * IContextMenu2 members
\r
267 STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
\r
268 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
\r
269 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
\r
270 STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
\r
273 /** \name IContextMenu3
\r
274 * IContextMenu3 members
\r
277 STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
\r
280 /** \name IColumnProvider
\r
281 * IColumnProvider members
\r
284 STDMETHODIMP GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci);
\r
285 STDMETHODIMP GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
\r
286 STDMETHODIMP Initialize(LPCSHCOLUMNINIT psci);
\r
289 /** \name IShellExtInit
\r
290 * IShellExtInit methods
\r
293 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
\r
296 /** \name IPersistFile
\r
297 * IPersistFile methods
\r
300 STDMETHODIMP GetClassID(CLSID *pclsid);
\r
301 STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
\r
302 STDMETHODIMP IsDirty(void) { return S_OK; };
\r
303 STDMETHODIMP Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) { return S_OK; };
\r
304 STDMETHODIMP SaveCompleted(LPCOLESTR /*pszFileName*/) { return S_OK; };
\r
305 STDMETHODIMP GetCurFile(LPOLESTR * /*ppszFileName*/) { return S_OK; };
\r
308 /** \name IShellIconOverlayIdentifier
\r
309 * IShellIconOverlayIdentifier methods
\r
312 STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
\r
313 STDMETHODIMP GetPriority(int *pPriority);
\r
314 STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);
\r
317 /** \name IShellPropSheetExt
\r
318 * IShellPropSheetExt methods
\r
321 STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
\r
322 STDMETHODIMP ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM);
\r
325 /** \name ICopyHook
\r
326 * ICopyHook members
\r
329 STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
\r