4 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
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.
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.
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
22 This class handles the combo box of the address band.
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
42 CAddressEditBox::CAddressEditBox() :
43 fCombobox(NULL
, this, 1),
44 fEditWindow(NULL
, this, 1),
49 CAddressEditBox::~CAddressEditBox()
53 HRESULT STDMETHODCALLTYPE
CAddressEditBox::SetOwner(IUnknown
*)
55 // connect to browser connection point
59 HRESULT STDMETHODCALLTYPE
CAddressEditBox::FileSysChange(long param8
, long paramC
)
64 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Refresh(long param8
)
69 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Init(HWND comboboxEx
, HWND editControl
, long param14
, IUnknown
*param18
)
71 CComPtr
<IBrowserService
> browserService
;
73 fCombobox
.SubclassWindow(comboboxEx
);
74 fEditWindow
.SubclassWindow(editControl
);
77 SHAutoComplete(fEditWindow
.m_hWnd
, SHACF_FILESYSTEM
| SHACF_URLALL
| SHACF_USETAB
);
79 // take advice to watch events
80 HRESULT hResult
= IUnknown_QueryService(param18
, SID_SShellBrowser
, IID_PPV_ARG(IBrowserService
, &browserService
));
81 if (SUCCEEDED(hResult
))
83 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
89 HRESULT STDMETHODCALLTYPE
CAddressEditBox::SetCurrentDir(long paramC
)
94 HRESULT STDMETHODCALLTYPE
CAddressEditBox::ParseNow(long paramC
)
101 CComPtr
<IShellBrowser
> pisb
;
102 hr
= IUnknown_QueryService(fSite
, SID_SShellBrowser
, IID_PPV_ARG(IShellBrowser
, &pisb
));
103 if (FAILED_UNEXPECTEDLY(hr
))
106 hr
= IUnknown_GetWindow(pisb
, &topLevelWindow
);
107 if (FAILED_UNEXPECTEDLY(hr
))
111 int inputLength
= fCombobox
.GetWindowTextLength() + 2;
113 input
= new WCHAR
[inputLength
];
114 fCombobox
.GetWindowText(input
, inputLength
);
117 int addressLength
= ExpandEnvironmentStrings(input
, NULL
, 0);
119 if (addressLength
<= 0)
126 address
= new WCHAR
[addressLength
];
127 if (!ExpandEnvironmentStrings(input
, address
, addressLength
))
134 CComPtr
<IShellFolder
> psfDesktop
;
135 hr
= SHGetDesktopFolder(&psfDesktop
);
138 hr
= psfDesktop
->ParseDisplayName(topLevelWindow
, NULL
, address
, &eaten
, &pidlLastParsed
, &attributes
);
141 if (address
!= input
)
148 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Execute(long paramC
)
153 * Parse the path is it wasn't parsed
162 * Get the IShellBrowser and IBrowserService interfaces of the shell browser
164 CComPtr
<IShellBrowser
> pisb
;
165 hr
= IUnknown_QueryService(fSite
, SID_SShellBrowser
, IID_PPV_ARG(IShellBrowser
, &pisb
));
169 CComPtr
<IBrowserService
> pbs
;
170 pisb
->QueryInterface(IID_PPV_ARG(IBrowserService
, &pbs
));
175 * Get the current pidl of the shellbrowser and check if it is the same with the parsed one
177 PIDLIST_ABSOLUTE pidl
;
178 hr
= pbs
->GetPidl(&pidl
);
182 CComPtr
<IShellFolder
> psf
;
183 hr
= SHGetDesktopFolder(&psf
);
187 hr
= psf
->CompareIDs(0, pidl
, pidlLastParsed
);
194 * Attempt to browse to the parsed pidl
196 hr
= pisb
->BrowseObject(pidlLastParsed
, 0);
201 * Browsing to the pidl failed so it's not a folder. So invoke its defaule command.
204 hr
= IUnknown_GetWindow(pisb
, &topLevelWindow
);
208 LPCITEMIDLIST pidlChild
;
209 CComPtr
<IShellFolder
> sf
;
210 hr
= SHBindToParent(pidlLastParsed
, IID_PPV_ARG(IShellFolder
, &sf
), &pidlChild
);
214 hr
= SHInvokeDefaultCommand(topLevelWindow
, sf
, pidlChild
);
221 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Save(long paramC
)
226 HRESULT STDMETHODCALLTYPE
CAddressEditBox::OnWinEvent(
227 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
236 hdr
= (LPNMHDR
) lParam
;
237 if (hdr
->code
== CBEN_ENDEDIT
)
239 NMCBEENDEDITW
*endEdit
= (NMCBEENDEDITW
*) lParam
;
240 if (endEdit
->iWhy
== CBENF_RETURN
)
244 else if (endEdit
->iWhy
== CBENF_ESCAPE
)
246 /* Reset the contents of the combo box */
254 HRESULT STDMETHODCALLTYPE
CAddressEditBox::IsWindowOwner(HWND hWnd
)
256 if (fCombobox
.m_hWnd
== hWnd
)
258 if (fEditWindow
.m_hWnd
== hWnd
)
263 HRESULT STDMETHODCALLTYPE
CAddressEditBox::QueryStatus(
264 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
269 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Exec(const GUID
*pguidCmdGroup
, DWORD nCmdID
,
270 DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
275 HRESULT STDMETHODCALLTYPE
CAddressEditBox::GetTypeInfoCount(UINT
*pctinfo
)
280 HRESULT STDMETHODCALLTYPE
CAddressEditBox::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
285 HRESULT STDMETHODCALLTYPE
CAddressEditBox::GetIDsOfNames(
286 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
291 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
292 WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
294 if (pDispParams
== NULL
)
297 switch (dispIdMember
)
299 case DISPID_NAVIGATECOMPLETE2
:
300 case DISPID_DOCUMENTCOMPLETE
:
301 pidlLastParsed
= NULL
;
306 HRESULT STDMETHODCALLTYPE
CAddressEditBox::GetClassID(CLSID
*pClassID
)
308 if (pClassID
== NULL
)
310 *pClassID
= CLSID_AddressEditBox
;
314 HRESULT STDMETHODCALLTYPE
CAddressEditBox::IsDirty()
319 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Load(IStream
*pStm
)
324 HRESULT STDMETHODCALLTYPE
CAddressEditBox::Save(IStream
*pStm
, BOOL fClearDirty
)
329 HRESULT STDMETHODCALLTYPE
CAddressEditBox::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
334 HRESULT
CreateAddressEditBox(REFIID riid
, void **ppv
)
336 return ShellObjectCreator
<CAddressEditBox
>(riid
, ppv
);