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.
24 #include "ShellCache.h"
25 #include "RemoteCacheLink.h"
26 #include "GitStatus.h"
27 #include "GitFolderStatus.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
;
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
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
,
76 IShellIconOverlayIdentifier
,
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/
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
;
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)
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
105 stdstring itemshorturl
;
106 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 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, _countof(stringtablebuffer), (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
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 HBITMAP
IconToBitmap(UINT uIcon
);
129 STDMETHODIMP
QueryDropContext(UINT uFlags
, UINT idCmdFirst
, HMENU hMenu
, UINT
&indexMenu
);
130 bool IsIllegalFolder(std::wstring folder
, int * cslidarray
);
131 HBITMAP
IconToBitmapPARGB32(UINT uIcon
);
132 HRESULT
Create32BitHBITMAP(HDC hdc
, const SIZE
*psize
, __deref_opt_out
void **ppvBits
, __out HBITMAP
* phBmp
);
133 HRESULT
ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer
, HDC hdc
, HICON hicon
, SIZE
& sizIcon
);
134 bool HasAlpha(__in ARGB
*pargb
, SIZE
& sizImage
, int cxRow
);
135 HRESULT
ConvertToPARGB32(HDC hdc
, __inout ARGB
*pargb
, HBITMAP hbmp
, SIZE
& sizImage
, int cxRow
);
139 CShellExt(FileState state
);
140 virtual ~CShellExt();
146 STDMETHODIMP
QueryInterface(REFIID
, LPVOID FAR
*);
147 STDMETHODIMP_(ULONG
) AddRef();
148 STDMETHODIMP_(ULONG
) Release();
151 /** \name IContextMenu2
152 * IContextMenu2 members
155 STDMETHODIMP
QueryContextMenu(HMENU hMenu
, UINT indexMenu
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
);
156 STDMETHODIMP
InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi
);
157 STDMETHODIMP
GetCommandString(UINT_PTR idCmd
, UINT uFlags
, UINT FAR
*reserved
, LPSTR pszName
, UINT cchMax
);
158 STDMETHODIMP
HandleMenuMsg(UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
161 /** \name IContextMenu3
162 * IContextMenu3 members
165 STDMETHODIMP
HandleMenuMsg2(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*pResult
);
168 /** \name IColumnProvider
169 * IColumnProvider members
172 STDMETHODIMP
GetColumnInfo(DWORD dwIndex
, SHCOLUMNINFO
*psci
);
173 STDMETHODIMP
GetItemData(LPCSHCOLUMNID pscid
, LPCSHCOLUMNDATA pscd
, VARIANT
*pvarData
);
174 STDMETHODIMP
Initialize(LPCSHCOLUMNINIT psci
);
177 /** \name IShellExtInit
178 * IShellExtInit methods
181 STDMETHODIMP
Initialize(LPCITEMIDLIST pIDFolder
, LPDATAOBJECT pDataObj
, HKEY hKeyID
);
184 /** \name IPersistFile
185 * IPersistFile methods
188 STDMETHODIMP
GetClassID(CLSID
*pclsid
);
189 STDMETHODIMP
Load(LPCOLESTR pszFileName
, DWORD dwMode
);
190 STDMETHODIMP
IsDirty(void) { return S_OK
; };
191 STDMETHODIMP
Save(LPCOLESTR
/*pszFileName*/, BOOL
/*fRemember*/) { return S_OK
; };
192 STDMETHODIMP
SaveCompleted(LPCOLESTR
/*pszFileName*/) { return S_OK
; };
193 STDMETHODIMP
GetCurFile(LPOLESTR
* /*ppszFileName*/) { return S_OK
; };
196 /** \name IShellIconOverlayIdentifier
197 * IShellIconOverlayIdentifier methods
200 STDMETHODIMP
GetOverlayInfo(LPWSTR pwszIconFile
, int cchMax
, int *pIndex
, DWORD
*pdwFlags
);
201 STDMETHODIMP
GetPriority(int *pPriority
);
202 STDMETHODIMP
IsMemberOf(LPCWSTR pwszPath
, DWORD dwAttrib
);
205 /** \name IShellPropSheetExt
206 * IShellPropSheetExt methods
209 STDMETHODIMP
AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage
, LPARAM lParam
);
210 STDMETHODIMP
ReplacePage (UINT
, LPFNADDPROPSHEETPAGE
, LPARAM
);
217 STDMETHODIMP_(UINT
) CopyCallback(HWND hWnd
, UINT wFunc
, UINT wFlags
, LPCTSTR pszSrcFile
, DWORD dwSrcAttribs
, LPCTSTR pszDestFile
, DWORD dwDestAttribs
);