OSDN Git Service

Add Stash Save\apply and Submodule Add and Update command.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseShell / ShellExt.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #pragma once\r
20 \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
29 \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
40 \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
51 \r
52 extern  void                            LoadLangDll();\r
53 extern  CComCriticalSection     g_csGlobalCOMGuard;\r
54 typedef CComCritSecLock<CComCriticalSection> AutoLocker;\r
55 \r
56 typedef DWORD ARGB;\r
57 \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
61 \r
62 \r
63 // The actual OLE Shell context menu handler\r
64 /**\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
70  */\r
71 class CShellExt : public IContextMenu3,\r
72                                                         IPersistFile,\r
73                                                         IColumnProvider,\r
74                                                         IShellExtInit,\r
75                                                         IShellIconOverlayIdentifier,\r
76                                                         IShellPropSheetExt,\r
77                                                         ICopyHookW\r
78 \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
83 {\r
84 protected:\r
85 \r
86         enum GitCommands\r
87         {\r
88                 ShellSeparator = 0,\r
89                 ShellSubMenu = 1,\r
90                 ShellSubMenuFolder,\r
91                 ShellSubMenuFile,\r
92                 ShellSubMenuLink,\r
93                 ShellSubMenuMultiple,\r
94                 ShellMenuCheckout,\r
95                 ShellMenuUpdate,\r
96                 ShellMenuCommit,\r
97                 ShellMenuAdd,\r
98                 ShellMenuAddAsReplacement,\r
99                 ShellMenuRevert,\r
100                 ShellMenuCleanup,\r
101                 ShellMenuResolve,\r
102                 ShellMenuSwitch,\r
103                 ShellMenuImport,\r
104                 ShellMenuExport,\r
105                 ShellMenuAbout,\r
106                 ShellMenuCreateRepos,\r
107                 ShellMenuCopy,\r
108                 ShellMenuMerge,\r
109                 ShellMenuMergeAll,\r
110                 ShellMenuSettings,\r
111                 ShellMenuRemove,\r
112                 ShellMenuRemoveKeep,\r
113                 ShellMenuRename,\r
114                 ShellMenuUpdateExt,\r
115                 ShellMenuDiff,\r
116                 ShellMenuPrevDiff,\r
117                 ShellMenuUrlDiff,\r
118                 ShellMenuDropCopyAdd,\r
119                 ShellMenuDropMoveAdd,\r
120                 ShellMenuDropMove,\r
121                 ShellMenuDropMoveRename,\r
122                 ShellMenuDropCopy,\r
123                 ShellMenuDropCopyRename,\r
124                 ShellMenuDropExport,\r
125                 ShellMenuDropExportExtended,\r
126                 ShellMenuLog,\r
127                 ShellMenuConflictEditor,\r
128                 ShellMenuRelocate,\r
129                 ShellMenuHelp,\r
130                 ShellMenuShowChanged,\r
131                 ShellMenuIgnoreSub,\r
132                 ShellMenuIgnore,\r
133                 ShellMenuIgnoreFile,\r
134                 ShellMenuIgnoreCaseSensitive,\r
135                 ShellMenuIgnoreCaseInsensitive,\r
136                 ShellMenuRepoBrowse,\r
137                 ShellMenuBlame,\r
138                 ShellMenuApplyPatch,\r
139                 ShellMenuCreatePatch,\r
140                 ShellMenuRevisionGraph,\r
141                 ShellMenuUnIgnoreSub,\r
142                 ShellMenuUnIgnoreCaseSensitive,\r
143                 ShellMenuUnIgnore,\r
144 //              ShellMenuLock,\r
145 //              ShellMenuUnlock,\r
146 //              ShellMenuUnlockForce,\r
147                 ShellMenuProperties,\r
148                 ShellMenuDelUnversioned,\r
149                 ShellMenuClipPaste,\r
150                 ShellMenuPull,\r
151                 ShellMenuPush,\r
152                 ShellMenuClone,\r
153                 ShellMenuBranch,\r
154                 ShellMenuTag,\r
155                 ShellMenuFormatPatch,\r
156                 ShellMenuImportPatch,\r
157                 ShellMenuCherryPick,\r
158                 ShellMenuFetch,\r
159                 ShellMenuRebase,\r
160                 ShellMenuStashSave,\r
161                 ShellMenuStashApply,\r
162                 ShellMenuSubAdd,\r
163                 ShellMenuSubSync,\r
164                 ShellMenuLastEntry                      // used to mark the menu array end\r
165         };\r
166 \r
167         // helper struct for context menu entries\r
168         typedef struct MenuInfo\r
169         {\r
170                 GitCommands                     command;                ///< the command which gets executed for this menu entry\r
171                 unsigned __int64        menuID;                 ///< the menu ID to recognize the entry. NULL if it shouldn't be added to the context menu automatically\r
172                 UINT                            iconID;                 ///< the icon to show for the menu entry\r
173                 UINT                            menuTextID;             ///< the text of the menu entry\r
174                 UINT                            menuDescID;             ///< the description text for the menu entry\r
175                 /// the following 8 params are for checking whether the menu entry should\r
176                 /// be added automatically, based on states of the selected item(s).\r
177                 /// The 'yes' states must be set, the 'no' states must not be set\r
178                 /// the four pairs are OR'ed together, the 'yes'/'no' states are AND'ed together.\r
179                 DWORD                           firstyes;\r
180                 DWORD                           firstno;\r
181                 DWORD                           secondyes;\r
182                 DWORD                           secondno;\r
183                 DWORD                           thirdyes;\r
184                 DWORD                           thirdno;\r
185                 DWORD                           fourthyes;\r
186                 DWORD                           fourthno;\r
187         };\r
188 \r
189         static MenuInfo menuInfo[];\r
190         WORD fullver;\r
191         FileState m_State;\r
192         ULONG   m_cRef;\r
193         //std::map<int,std::string> verbMap;\r
194         std::map<UINT_PTR, UINT_PTR>    myIDMap;\r
195         std::map<UINT_PTR, UINT_PTR>    mySubMenuMap;\r
196         std::map<stdstring, UINT_PTR> myVerbsMap;\r
197         std::map<UINT_PTR, stdstring> myVerbsIDMap;\r
198         stdstring       folder_;\r
199         std::vector<stdstring> files_;\r
200         DWORD itemStates;                               ///< see the globals.h file for the ITEMIS_* defines\r
201         DWORD itemStatesFolder;                 ///< used for states of the folder_ (folder background and/or drop target folder)\r
202         stdstring uuidSource;\r
203         stdstring uuidTarget;\r
204         int space;\r
205         TCHAR stringtablebuffer[255];\r
206         stdstring columnfilepath;               ///< holds the last file/dir path for the column provider\r
207         stdstring columnauthor;                 ///< holds the corresponding author of the file/dir above\r
208         stdstring itemurl;\r
209         stdstring itemshorturl;\r
210         stdstring ignoredprops;\r
211         stdstring owner;\r
212         git_revnum_t columnrev;                 ///< holds the corresponding revision to the file/dir above\r
213         git_wc_status_kind      filestatus;\r
214         std::map<UINT, HBITMAP> bitmaps;\r
215 \r
216         GitFolderStatus         m_CachedStatus;         // status cache\r
217         CRemoteCacheLink        m_remoteCacheLink;\r
218 \r
219         FN_GetBufferedPaintBits pfnGetBufferedPaintBits;\r
220         FN_BeginBufferedPaint pfnBeginBufferedPaint;\r
221         FN_EndBufferedPaint pfnEndBufferedPaint;\r
222 \r
223 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, sizeof(stringtablebuffer)/sizeof(TCHAR), (WORD)CRegStdWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))\r
224 private:\r
225         void                    InsertGitMenu(BOOL istop, HMENU menu, UINT pos, UINT_PTR id, UINT stringid, UINT icon, UINT idCmdFirst, GitCommands com, UINT uFlags);\r
226         void                    InsertIgnoreSubmenus(UINT &idCmd, UINT idCmdFirst, HMENU hMenu, HMENU subMenu, UINT &indexMenu, int &indexSubMenu, unsigned __int64 topmenu, bool bShowIcons, UINT uFlags);\r
227         stdstring               WriteFileListToTempFile();\r
228         bool                    WriteClipboardPathsToTempFile(stdstring& tempfile);\r
229         LPCTSTR                 GetMenuTextFromResource(int id);\r
230         void                    GetColumnStatus(const TCHAR * path, BOOL bIsDir);\r
231         HBITMAP                 IconToBitmap(UINT uIcon);\r
232         STDMETHODIMP    QueryDropContext(UINT uFlags, UINT idCmdFirst, HMENU hMenu, UINT &indexMenu);\r
233         bool                    IsIllegalFolder(std::wstring folder, int * cslidarray);\r
234         HBITMAP                 IconToBitmapPARGB32(UINT uIcon);\r
235         HRESULT                 Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp);\r
236         HRESULT                 ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon);\r
237         bool                    HasAlpha(__in ARGB *pargb, SIZE& sizImage, int cxRow);\r
238         HRESULT                 ConvertToPARGB32(HDC hdc, __inout ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow);\r
239 \r
240 \r
241 public:\r
242         CShellExt(FileState state);\r
243         virtual ~CShellExt();\r
244 \r
245         /** \name IUnknown \r
246          * IUnknown members\r
247          */\r
248         //@{\r
249         STDMETHODIMP         QueryInterface(REFIID, LPVOID FAR *);\r
250         STDMETHODIMP_(ULONG) AddRef();\r
251         STDMETHODIMP_(ULONG) Release();\r
252         //@}\r
253 \r
254         /** \name IContextMenu2 \r
255          * IContextMenu2 members\r
256          */\r
257         //@{\r
258         STDMETHODIMP    QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);\r
259         STDMETHODIMP    InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);\r
260         STDMETHODIMP    GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax);\r
261         STDMETHODIMP    HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);\r
262         //@}\r
263 \r
264     /** \name IContextMenu3 \r
265          * IContextMenu3 members\r
266          */\r
267         //@{\r
268         STDMETHODIMP    HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);\r
269         //@}\r
270 \r
271         /** \name IColumnProvider\r
272          * IColumnProvider members\r
273          */\r
274         //@{\r
275         STDMETHODIMP    GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO *psci);\r
276         STDMETHODIMP    GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT *pvarData);\r
277         STDMETHODIMP    Initialize(LPCSHCOLUMNINIT psci);\r
278         //@}\r
279 \r
280         /** \name IShellExtInit\r
281          * IShellExtInit methods\r
282          */\r
283         //@{\r
284         STDMETHODIMP    Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);\r
285         //@}\r
286 \r
287     /** \name IPersistFile\r
288          * IPersistFile methods\r
289          */\r
290         //@{\r
291     STDMETHODIMP        GetClassID(CLSID *pclsid);\r
292     STDMETHODIMP        Load(LPCOLESTR pszFileName, DWORD dwMode);\r
293     STDMETHODIMP        IsDirty(void) { return S_OK; };\r
294     STDMETHODIMP        Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/) { return S_OK; };\r
295     STDMETHODIMP        SaveCompleted(LPCOLESTR /*pszFileName*/) { return S_OK; };\r
296     STDMETHODIMP        GetCurFile(LPOLESTR * /*ppszFileName*/) { return S_OK; };\r
297         //@}\r
298 \r
299         /** \name IShellIconOverlayIdentifier \r
300          * IShellIconOverlayIdentifier methods\r
301          */\r
302         //@{\r
303         STDMETHODIMP    GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);\r
304         STDMETHODIMP    GetPriority(int *pPriority); \r
305         STDMETHODIMP    IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);\r
306         //@}\r
307 \r
308         /** \name IShellPropSheetExt \r
309          * IShellPropSheetExt methods\r
310          */\r
311         //@{\r
312         STDMETHODIMP    AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);\r
313         STDMETHODIMP    ReplacePage (UINT, LPFNADDPROPSHEETPAGE, LPARAM);\r
314         //@}\r
315 \r
316         /** \name ICopyHook \r
317          * ICopyHook members\r
318          */\r
319         //@{\r
320         STDMETHODIMP_(UINT) CopyCallback(HWND hWnd, UINT wFunc, UINT wFlags, LPCTSTR pszSrcFile, DWORD dwSrcAttribs, LPCTSTR pszDestFile, DWORD dwDestAttribs);\r
321         //@}\r
322 \r
323 };\r