Build custom columns support with Makefile
[git-cheetah/bosko.git] / ext.c
blob8423f43e126500ee1287ecc15658dfe7002018d8
1 #include <shlobj.h>
2 #include <stdarg.h>
3 #include <tchar.h>
4 #include "menuengine.h"
5 #include "ext.h"
6 #include "debug.h"
7 #include "systeminfo.h"
9 DWORD object_count = 0;
10 DWORD lock_count = 0;
13 * Standard methods for the IUnknown interface:
14 * add_ref, release, query_interface and initialize.
16 * Both of our COM objects contain pointers to the git_data object.
19 inline ULONG STDMETHODCALLTYPE add_ref_git_data(struct git_data *this_)
21 return ++(this_->count);
24 inline ULONG STDMETHODCALLTYPE release_git_data(struct git_data *this_)
26 if (--(this_->count) == 0) {
27 GlobalFree(this_);
28 InterlockedDecrement(&object_count);
29 return 0;
31 return this_->count;
34 inline STDMETHODIMP query_interface_git_data(struct git_data *this_,
35 REFIID iid, LPVOID FAR *pointer)
37 if (IsEqualIID(iid, &IID_git_shell_ext) ||
38 IsEqualIID(iid, &IID_IShellExtInit) ||
39 IsEqualIID(iid, &IID_IUnknown)) {
40 *pointer = &this_->shell_ext;
41 } else if (IsEqualIID(iid, &IID_git_menu) ||
42 IsEqualIID(iid, &IID_IContextMenu)) {
43 *pointer = &this_->menu;
44 } else if (IsEqualIID(iid, &IID_git_columns) ||
45 IsEqualIID(iid, &IID_IColumnProvider)) {
46 *pointer = &this_->columns;
47 } else
48 return E_NOINTERFACE;
50 add_ref_git_data(this_);
51 return NOERROR;
54 inline STDMETHODIMP initialize_git_data(struct git_data *this_,
55 LPCITEMIDLIST folder,
56 LPDATAOBJECT data, HKEY id)
58 FORMATETC format
59 = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
60 STGMEDIUM stg = {TYMED_HGLOBAL};
61 HDROP drop;
62 UINT count;
63 HRESULT result = S_OK;
65 /* if we can't find msysPath, don't even try to do anything else */
66 if (!msys_path())
67 return E_NOTIMPL;
69 /* store the folder, if provided */
70 if (folder)
71 SHGetPathFromIDList(folder, this_->name);
73 if (!data)
74 return S_OK;
76 if (FAILED(data->lpVtbl->GetData(data, &format, &stg)))
77 return E_INVALIDARG;
79 drop = (HDROP)GlobalLock(stg.hGlobal);
81 if (!drop)
82 return E_INVALIDARG;
84 count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
86 if (count == 0)
87 result = E_INVALIDARG;
88 else if (!DragQueryFile(drop, 0, this_->name, sizeof(this_->name)))
89 result = E_INVALIDARG;
91 GlobalUnlock(stg.hGlobal);
92 ReleaseStgMedium(&stg);
94 return result;
98 * Define the shell extension.
100 * Its sole purpose is to be able to query_interface() the context menu.
102 DEFINE_STANDARD_METHODS(git_shell_ext)
104 struct git_shell_ext_virtual_table git_shell_ext_virtual_table = {
105 query_interface_git_shell_ext,
106 add_ref_git_shell_ext,
107 release_git_shell_ext,
108 initialize_git_shell_ext