72643454b54bc48802ff5a8d016844b9347e3840
[reactos.git] / dll / win32 / browseui / addresseditbox.cpp
1 /*
2 * ReactOS Explorer
3 *
4 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*
22 This class handles the combo box of the address band.
23 */
24
25 #include "precomp.h"
26
27 /*
28 TODO:
29 Add auto completion support
30 Subclass windows in Init method
31 Connect to browser connection point
32 Handle navigation complete messages to set edit box text
33 Handle listbox dropdown message and fill contents
34 Add drag and drop of icon in edit box
35 Handle enter in edit box to browse to typed path
36 Handle change notifies to update appropriately
37 Add handling of enter in edit box
38 Fix so selection in combo listbox navigates
39 Fix so editing text and typing enter navigates
40 */
41
42 CAddressEditBox::CAddressEditBox() :
43 fCombobox(NULL, this, 1),
44 fEditWindow(NULL, this, 1),
45 fSite(NULL)
46 {
47 }
48
49 CAddressEditBox::~CAddressEditBox()
50 {
51 }
52
53 HRESULT STDMETHODCALLTYPE CAddressEditBox::SetOwner(IUnknown *)
54 {
55 // connect to browser connection point
56 return 0;
57 }
58
59 HRESULT STDMETHODCALLTYPE CAddressEditBox::FileSysChange(long param8, long paramC)
60 {
61 return E_NOTIMPL;
62 }
63
64 HRESULT STDMETHODCALLTYPE CAddressEditBox::Refresh(long param8)
65 {
66 return E_NOTIMPL;
67 }
68
69 HRESULT STDMETHODCALLTYPE CAddressEditBox::Init(HWND comboboxEx, HWND editControl, long param14, IUnknown *param18)
70 {
71 CComPtr<IBrowserService> browserService;
72
73 fCombobox.SubclassWindow(comboboxEx);
74 fEditWindow.SubclassWindow(editControl);
75 fSite = param18;
76
77 // take advice to watch events
78 HRESULT hResult = IUnknown_QueryService(param18, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &browserService));
79 if (SUCCEEDED(hResult))
80 {
81 if (SUCCEEDED(hResult))
82 hResult = AtlAdvise(browserService, static_cast<IDispatch *>(this), DIID_DWebBrowserEvents, &fAdviseCookie);
83 }
84
85 return hResult;
86 }
87
88 HRESULT STDMETHODCALLTYPE CAddressEditBox::SetCurrentDir(long paramC)
89 {
90 return E_NOTIMPL;
91 }
92
93 HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow(long paramC)
94 {
95 WCHAR address[4096];
96 ULONG eaten;
97 ULONG attributes;
98 HRESULT hr;
99 HWND topLevelWindow;
100
101 CComPtr<IShellBrowser> pisb;
102 hr = IUnknown_QueryService(fSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pisb));
103
104 IUnknown_GetWindow(pisb, &topLevelWindow);
105
106 GetWindowText(fCombobox.m_hWnd, address, 4095);
107
108 CComPtr<IShellFolder> psfDesktop;
109 hr = SHGetDesktopFolder(&psfDesktop);
110 hr = psfDesktop->ParseDisplayName(topLevelWindow, NULL, address, &eaten, &pidlLastParsed, &attributes);
111 return hr;
112 }
113
114 HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC)
115 {
116 HRESULT hr;
117
118 if (!pidlLastParsed)
119 return E_FAIL;
120
121 CComPtr<IShellBrowser> pisb;
122 hr = IUnknown_QueryService(fSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pisb));
123 if (SUCCEEDED(hr))
124 {
125 hr = pisb->BrowseObject(pidlLastParsed, 0);
126 if (FAILED(hr))
127 {
128 HWND topLevelWindow;
129 LPCITEMIDLIST pidlChild;
130 CComPtr<IShellFolder> sf;
131 CComPtr<IShellBrowser> pisb;
132
133 hr = IUnknown_QueryService(fSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pisb));
134
135 IUnknown_GetWindow(pisb, &topLevelWindow);
136
137 hr = SHBindToParent(pidlLastParsed, IID_PPV_ARG(IShellFolder, &sf), &pidlChild);
138
139 SHInvokeDefaultCommand(topLevelWindow, sf, pidlChild);
140 }
141 }
142 return hr;
143 }
144
145 HRESULT STDMETHODCALLTYPE CAddressEditBox::Save(long paramC)
146 {
147 return E_NOTIMPL;
148 }
149
150 HRESULT STDMETHODCALLTYPE CAddressEditBox::OnWinEvent(
151 HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
152 {
153 // handle fill of listbox here
154 return E_NOTIMPL;
155 }
156
157 HRESULT STDMETHODCALLTYPE CAddressEditBox::IsWindowOwner(HWND hWnd)
158 {
159 if (fCombobox.m_hWnd == hWnd)
160 return S_OK;
161 if (fEditWindow.m_hWnd == hWnd)
162 return S_OK;
163 return S_FALSE;
164 }
165
166 HRESULT STDMETHODCALLTYPE CAddressEditBox::QueryStatus(
167 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText)
168 {
169 return E_NOTIMPL;
170 }
171
172 HRESULT STDMETHODCALLTYPE CAddressEditBox::Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
173 DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
174 {
175 return E_NOTIMPL;
176 }
177
178 HRESULT STDMETHODCALLTYPE CAddressEditBox::GetTypeInfoCount(UINT *pctinfo)
179 {
180 return E_NOTIMPL;
181 }
182
183 HRESULT STDMETHODCALLTYPE CAddressEditBox::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
184 {
185 return E_NOTIMPL;
186 }
187
188 HRESULT STDMETHODCALLTYPE CAddressEditBox::GetIDsOfNames(
189 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
190 {
191 return E_NOTIMPL;
192 }
193
194 HRESULT STDMETHODCALLTYPE CAddressEditBox::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
195 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
196 {
197 if (pDispParams == NULL)
198 return E_INVALIDARG;
199
200 switch (dispIdMember)
201 {
202 case DISPID_NAVIGATECOMPLETE2:
203 case DISPID_DOCUMENTCOMPLETE:
204 pidlLastParsed = NULL;
205 }
206 return S_OK;
207 }
208
209 HRESULT STDMETHODCALLTYPE CAddressEditBox::GetClassID(CLSID *pClassID)
210 {
211 if (pClassID == NULL)
212 return E_POINTER;
213 *pClassID = CLSID_AddressEditBox;
214 return S_OK;
215 }
216
217 HRESULT STDMETHODCALLTYPE CAddressEditBox::IsDirty()
218 {
219 return E_NOTIMPL;
220 }
221
222 HRESULT STDMETHODCALLTYPE CAddressEditBox::Load(IStream *pStm)
223 {
224 return E_NOTIMPL;
225 }
226
227 HRESULT STDMETHODCALLTYPE CAddressEditBox::Save(IStream *pStm, BOOL fClearDirty)
228 {
229 return E_NOTIMPL;
230 }
231
232 HRESULT STDMETHODCALLTYPE CAddressEditBox::GetSizeMax(ULARGE_INTEGER *pcbSize)
233 {
234 return E_NOTIMPL;
235 }
236
237 HRESULT CreateAddressEditBox(REFIID riid, void **ppv)
238 {
239 CComObject<CAddressEditBox> *theMenuBar;
240 HRESULT hResult;
241
242 if (ppv == NULL)
243 return E_POINTER;
244 *ppv = NULL;
245 ATLTRY (theMenuBar = new CComObject<CAddressEditBox>);
246 if (theMenuBar == NULL)
247 return E_OUTOFMEMORY;
248 hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
249 if (FAILED(hResult))
250 {
251 delete theMenuBar;
252 return hResult;
253 }
254 return S_OK;
255 }