Fixed issue #916: Fixed wrong contextmenu icon display position with installed TSVN 1.7
[TortoiseGit.git] / src / TortoiseShell / ShellExt.h
blobaf79489c9ff4eb457e13757e8d94fcd29cb67a0e
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"
29 #include "MenuInfo.h"
31 extern UINT g_cRefThisDll; // Reference count of this DLL.
32 extern HINSTANCE g_hmodThisDll; // Instance handle for this DLL
33 extern ShellCache g_ShellCache; // caching of registry entries, ...
34 extern DWORD g_langid;
35 extern DWORD g_langTimeout;
36 extern HINSTANCE g_hResInst;
37 extern stdstring g_filepath;
38 extern git_wc_status_kind g_filestatus; ///< holds the corresponding status to the file/dir above
39 extern bool g_readonlyoverlay; ///< whether to show the read only overlay or not
40 extern bool g_lockedoverlay; ///< whether to show the locked overlay or not
42 extern bool g_normalovlloaded;
43 extern bool g_modifiedovlloaded;
44 extern bool g_conflictedovlloaded;
45 extern bool g_readonlyovlloaded;
46 extern bool g_deletedovlloaded;
47 extern bool g_lockedovlloaded;
48 extern bool g_addedovlloaded;
49 extern bool g_ignoredovlloaded;
50 extern bool g_unversionedovlloaded;
51 extern LPCTSTR g_MenuIDString;
53 extern void LoadLangDll();
54 extern CComCriticalSection g_csGlobalCOMGuard;
55 typedef CComCritSecLock<CComCriticalSection> AutoLocker;
57 typedef DWORD ARGB;
59 typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow);
60 typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc);
61 typedef HRESULT (WINAPI *FN_EndBufferedPaint) (HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget);
64 // The actual OLE Shell context menu handler
65 /**
66 * \ingroup TortoiseShell
67 * The main class of our COM object / Shell Extension.
68 * It contains all Interfaces we implement for the shell to use.
69 * \remark The implementations of the different interfaces are
70 * split into several *.cpp files to keep them in a reasonable size.
72 class CShellExt : public IContextMenu3,
73 IPersistFile,
74 IColumnProvider,
75 IShellExtInit,
76 IShellIconOverlayIdentifier,
77 IShellPropSheetExt,
78 ICopyHookW
80 // COMPILER ERROR? You need the latest version of the
81 // platform SDK which has references to IColumnProvider
82 // in the header files. Download it here:
83 // http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
85 protected:
87 FileState m_State;
88 ULONG m_cRef;
89 //std::map<int,std::string> verbMap;
90 std::map<UINT_PTR, UINT_PTR> myIDMap;
91 std::map<UINT_PTR, UINT_PTR> mySubMenuMap;
92 std::map<stdstring, UINT_PTR> myVerbsMap;
93 std::map<UINT_PTR, stdstring> myVerbsIDMap;
94 stdstring folder_;
95 std::vector<stdstring> files_;
96 DWORD itemStates; ///< see the globals.h file for the ITEMIS_* defines
97 DWORD itemStatesFolder; ///< used for states of the folder_ (folder background and/or drop target folder)
98 stdstring uuidSource;
99 stdstring uuidTarget;
100 int space;
101 TCHAR stringtablebuffer[255];
102 stdstring columnfilepath; ///< holds the last file/dir path for the column provider
103 stdstring columnauthor; ///< holds the corresponding author of the file/dir above
104 stdstring itemurl;
105 stdstring itemshorturl;
106 stdstring ignoredprops;
107 stdstring owner;
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 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, _countof(stringtablebuffer), (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
120 private:
121 void InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);
122 bool InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);
123 stdstring WriteFileListToTempFile();
124 bool WriteClipboardPathsToTempFile(stdstring& tempfile);
125 LPCTSTR GetMenuTextFromResource(int id);
126 void GetColumnStatus(const TCHAR * path, BOOL bIsDir);
127 void GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci, UINT characterCount, UINT title, UINT description);
128 void TweakMenu(HMENU menu);
129 HBITMAP IconToBitmap(UINT uIcon);
130 STDMETHODIMP QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);
131 bool IsIllegalFolder(std::wstring folder, int * cslidarray);
132 HBITMAP IconToBitmapPARGB32(UINT uIcon);
133 HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp);
134 HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon);
135 bool HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow);
136 HRESULT ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow);
139 public:
140 CShellExt(FileState state);
141 virtual ~CShellExt();
143 /** \name IUnknown
144 * IUnknown members
146 //@{
147 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
148 STDMETHODIMP_(ULONG) AddRef();
149 STDMETHODIMP_(ULONG) Release();
150 //@}
152 /** \name IContextMenu2
153 * IContextMenu2 members
155 //@{
156 STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
157 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
158 STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);
159 STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
160 //@}
162 /** \name IContextMenu3
163 * IContextMenu3 members
165 //@{
166 STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
167 //@}
169 /** \name IColumnProvider
170 * IColumnProvider members
172 //@{
173 STDMETHODIMP GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci);
174 STDMETHODIMP GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);
175 STDMETHODIMP Initialize(LPCSHCOLUMNINIT psci);
176 //@}
178 /** \name IShellExtInit
179 * IShellExtInit methods
181 //@{
182 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);
183 //@}
185 /** \name IPersistFile
186 * IPersistFile methods
188 //@{
189 STDMETHODIMP GetClassID(CLSID *pclsid);
190 STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode);
191 STDMETHODIMP IsDirty(void) { return S_OK; };
192 STDMETHODIMP Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) { return S_OK; };
193 STDMETHODIMP SaveCompleted(LPCOLESTR /*pszFileName*/) { return S_OK; };
194 STDMETHODIMP GetCurFile(LPOLESTR * /*ppszFileName*/) { return S_OK; };
195 //@}
197 /** \name IShellIconOverlayIdentifier
198 * IShellIconOverlayIdentifier methods
200 //@{
201 STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
202 STDMETHODIMP GetPriority(int *pPriority);
203 STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);
204 //@}
206 /** \name IShellPropSheetExt
207 * IShellPropSheetExt methods
209 //@{
210 STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
211 STDMETHODIMP ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM);
212 //@}
214 /** \name ICopyHook
215 * ICopyHook members
217 //@{
218 STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);
219 //@}