1 /*
2  * Copyright 2003 Martin Fuchs
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 
19 
20  //
21  // Explorer clone
22  //
23  // shellbrowserimpl.cpp
24  //
25  // Martin Fuchs, 28.09.2003
26  //
27  // Credits: Thanks to Leon Finker for his explorer cabinet window example
28  //
29 
30 
31 #include <precomp.h>
32 
33 
34 HRESULT IShellBrowserImpl::QueryInterface(REFIID iid, void** ppvObject)
35 {
36 	if (!ppvObject)
37 		return E_POINTER;
38 
39 	if (iid == IID_IUnknown)
40 		*ppvObject = (IUnknown*)static_cast<IShellBrowser*>(this);
41 	else if (iid == IID_IOleWindow)
42 		*ppvObject = static_cast<IOleWindow*>(this);
43 	else if (iid == IID_IShellBrowser)
44 		*ppvObject = static_cast<IShellBrowser*>(this);
45 	else if (iid == IID_ICommDlgBrowser)
46 		*ppvObject = static_cast<ICommDlgBrowser*>(this);
47 	else if (iid == IID_IServiceProvider)
48 		*ppvObject = static_cast<IServiceProvider*>(this);
49 	else {
50 		*ppvObject = NULL;
51 		return E_NOINTERFACE;
52 	}
53 
54 	return S_OK;
55 }
56 
57 HRESULT IShellBrowserImpl::QueryService(REFGUID guidService, REFIID riid, void** ppvObject)
58 {
59 	if (!ppvObject)
60 		return E_POINTER;
61 
62 	///@todo use guidService
63 
64 	if (riid == IID_IUnknown)
65 		*ppvObject = (IUnknown*)static_cast<IShellBrowser*>(this);
66 	else if (riid == IID_IOleWindow)
67 		*ppvObject = static_cast<IOleWindow*>(this);
68 	else if (riid == IID_IShellBrowser)
69 		*ppvObject = static_cast<IShellBrowser*>(this);
70 	else if (riid == IID_ICommDlgBrowser)
71 		*ppvObject = static_cast<ICommDlgBrowser*>(this);
72 	else if (riid == IID_IServiceProvider)
73 		*ppvObject = static_cast<IServiceProvider*>(this);
74 	else if (riid == IID_IOleCommandTarget)
75 		*ppvObject = static_cast<IOleCommandTarget*>(this);
76 	else {
77 		*ppvObject = NULL;
78 		return E_NOINTERFACE;
79 	}
80 
81 	return S_OK;
82 }
83 
84 HRESULT IShellBrowserImpl::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT* pCmdText)
85 {
86 	return E_FAIL;	///@todo implement IOleCommandTarget
87 }
88 
89 HRESULT IShellBrowserImpl::Exec(const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT* pvaIn, VARIANT* pvaOut)
90 {
91 	return E_FAIL;	///@todo implement IOleCommandTarget
92 }
93 
94 
95  // process default command: look for folders and traverse into them
96 HRESULT IShellBrowserImpl::OnDefaultCommand(IShellView* ppshv)
97 {
98 	IDataObject* selection;
99 
100 	HRESULT hr = ppshv->GetItemObject(SVGIO_SELECTION, IID_IDataObject, (void**)&selection);
101 	if (FAILED(hr))
102 		return hr;
103 
104 	PIDList pidList;
105 
106 	hr = pidList.GetData(selection);
107 	if (FAILED(hr)) {
108 		selection->Release();
109 		return hr;
110 	}
111 
112 	hr = OnDefaultCommand(pidList);
113 
114 	selection->Release();
115 
116 	return hr;
117 }
118