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 Implements the navigation band of the cabinet window
27 HRESULT
CreateAddressEditBox(REFIID riid
, void **ppv
);
31 ****Add command handler for show/hide Go button to OnWinEvent
32 ****Add tooltip notify handler
33 **Properly implement GetBandInfo
34 **Add support for showing/hiding Go button
35 **Fix so Go button will be shown/hidden properly on load
36 **Add correct text to Go button
37 **Implement TranslateAcceleratorIO
39 Implement QueryService
44 CAddressBand::CAddressBand()
49 fGoButtonShown
= false;
53 CAddressBand::~CAddressBand()
57 void CAddressBand::FocusChange(BOOL bFocus
)
61 //Inform the input object site that the focus has changed.
65 fSite
->OnFocusChangeIS((IDockingWindow
*)this, bFocus
);
70 HRESULT STDMETHODCALLTYPE
CAddressBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
*pdbi
)
72 if (pdbi
->dwMask
& DBIM_MINSIZE
)
74 pdbi
->ptMinSize
.x
= 400;
75 pdbi
->ptMinSize
.y
= 22;
77 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
79 pdbi
->ptMaxSize
.x
= 0;
80 pdbi
->ptMaxSize
.y
= 0;
82 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
84 pdbi
->ptIntegral
.x
= 0;
85 pdbi
->ptIntegral
.y
= 0;
87 if (pdbi
->dwMask
& DBIM_ACTUAL
)
89 pdbi
->ptActual
.x
= 400;
90 pdbi
->ptActual
.y
= 22;
92 if (pdbi
->dwMask
& DBIM_TITLE
)
93 wcscpy(pdbi
->wszTitle
, L
"Address");
94 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
95 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
96 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
101 HRESULT STDMETHODCALLTYPE
CAddressBand::SetSite(IUnknown
*pUnkSite
)
103 CComPtr
<IBrowserService
> browserService
;
104 CComPtr
<IOleWindow
> oleWindow
;
105 CComPtr
<IShellService
> shellService
;
106 CComPtr
<IUnknown
> offset34
;
109 static const TBBUTTON buttonInfo
[] = { {0, 1, TBSTATE_ENABLED
, 0} };
110 HIMAGELIST normalImagelist
;
111 HIMAGELIST hotImageList
;
112 HINSTANCE shellInstance
;
115 if (pUnkSite
== NULL
)
117 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
124 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
128 // get window handle of parent
130 hResult
= IUnknown_GetWindow(pUnkSite
, &parentWindow
);
132 if (!::IsWindow(parentWindow
))
135 // create combo box ex
136 combobox
= CreateWindowEx(WS_EX_TOOLWINDOW
, WC_COMBOBOXEXW
, NULL
, WS_CHILD
| WS_VISIBLE
|
137 WS_CLIPCHILDREN
| WS_TABSTOP
| CCS_NODIVIDER
| CCS_NOMOVEY
,
138 0, 0, 500, 250, parentWindow
, (HMENU
)0xa205, _AtlBaseModule
.GetModuleInstance(), 0);
139 if (combobox
== NULL
)
141 SubclassWindow(combobox
);
143 SendMessage(CBEM_SETEXTENDEDSTYLE
,
144 CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
, CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
);
146 fEditControl
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETEDITCONTROL
, 0, 0));
147 fComboBox
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETCOMBOCONTROL
, 0, 0));
149 hResult
= CoCreateInstance(CLSID_AddressEditBox
, NULL
, CLSCTX_INPROC_SERVER
,
150 IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
156 // instantiate new version
157 hResult
= CreateAddressEditBox(IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
162 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &shellService
));
165 hResult
= fAddressEditBox
->Init(combobox
, fEditControl
, 8, pUnkSite
/*(IAddressBand *)this*/);
168 hResult
= shellService
->SetOwner(pUnkSite
);
172 // TODO: properly initialize this from registry
173 fGoButtonShown
= true;
175 shellInstance
= GetModuleHandle(_T("shell32.dll"));
176 normalImagelist
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
177 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
178 hotImageList
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
179 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
181 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
182 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
183 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
184 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
185 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
186 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
188 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(normalImagelist
));
190 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(hotImageList
));
191 SendMessage(fGoButton
, TB_ADDSTRINGW
,
192 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
193 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
)&buttonInfo
);
195 // take advice to watch events
196 hResult
= IUnknown_QueryService(pUnkSite
, SID_SShellBrowser
, IID_PPV_ARG(IBrowserService
, &browserService
));
197 if (SUCCEEDED(hResult
))
199 if (SUCCEEDED(hResult
))
200 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
206 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
210 return fSite
->QueryInterface(riid
, ppvSite
);
213 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
221 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
226 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
238 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
239 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
244 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
256 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
257 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
259 CComPtr
<IOleCommandTarget
> oleCommandTarget
;
262 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IOleCommandTarget
, &oleCommandTarget
));
265 return oleCommandTarget
->QueryStatus(pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
268 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
269 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
275 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
277 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
282 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
288 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
290 CComPtr
<IInputObjectSite
> inputObjectSite
;
295 hResult
= fSite
->QueryInterface(IID_PPV_ARG(IInputObjectSite
, &inputObjectSite
));
298 hResult
= inputObjectSite
->OnFocusChangeIS(static_cast<IDeskBand
*>(this), fActivate
);
304 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
305 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
307 CComPtr
<IWinEventHandler
> winEventHandler
;
312 case WM_WININICHANGE
:
315 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
317 // toggle whether the Go button is displayed
318 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
319 // broadcast change notification to all explorer windows
323 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
326 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
329 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
331 CComPtr
<IWinEventHandler
> winEventHandler
;
336 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
339 return winEventHandler
->IsWindowOwner(hWnd
);
344 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
346 CComPtr
<IAddressBand
> addressBand
;
349 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
352 return addressBand
->FileSysChange(param8
, paramC
);
355 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
357 CComPtr
<IAddressBand
> addressBand
;
360 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
363 return addressBand
->Refresh(param8
);
366 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
371 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
376 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
378 if (pClassID
== NULL
)
380 *pClassID
= CLSID_SH_AddressBand
;
384 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
389 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
395 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
401 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
407 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfoCount(UINT
*pctinfo
)
412 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
417 HRESULT STDMETHODCALLTYPE
CAddressBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
418 LCID lcid
, DISPID
*rgDispId
)
423 HRESULT STDMETHODCALLTYPE
CAddressBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
424 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
426 CComPtr
<IBrowserService
> isb
;
429 if (pDispParams
== NULL
)
432 switch (dispIdMember
)
434 case DISPID_NAVIGATECOMPLETE2
:
435 case DISPID_DOCUMENTCOMPLETE
:
436 hr
= IUnknown_QueryService(fSite
, SID_STopLevelBrowser
, IID_PPV_ARG(IBrowserService
, &isb
));
439 PIDLIST_ABSOLUTE absolutePIDL
;
440 LPCITEMIDLIST pidlChild
;
441 isb
->GetPidl(&absolutePIDL
);
443 CComPtr
<IShellFolder
> sf
;
444 SHBindToParent(absolutePIDL
, IID_PPV_ARG(IShellFolder
, &sf
), &pidlChild
);
447 sf
->GetDisplayNameOf(pidlChild
, SHGDN_FORADDRESSBAR
| SHGDN_FORPARSING
, &ret
);
450 StrRetToBufW(&ret
, pidlChild
, buf
, 4095);
452 fAddressEditBox
->SetCurrentDir(reinterpret_cast<long>(buf
));
459 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
461 if (notifyHeader
->hwndFrom
== fGoButton
)
463 fAddressEditBox
->ParseNow(0);
464 //SendMessage(fEditControl, WM_KEYDOWN, 13, 0);
465 //SendMessage(fEditControl, WM_KEYUP, 13, 0);
470 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
472 if (notifyHeader
->hwndFrom
== fGoButton
)
475 // Go to "destination path"
480 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
487 if (fGoButtonShown
== false)
494 parentWindow
= GetParent();
495 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
496 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
497 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
498 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
507 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
517 if (fGoButtonShown
== false)
523 newHeight
= HIWORD(lParam
);
524 newWidth
= LOWORD(lParam
);
526 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
527 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
528 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
530 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
531 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
532 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
533 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
535 goButtonBounds
.left
= newWidth
- buttonWidth
;
536 goButtonBounds
.top
= 0;
537 goButtonBounds
.right
= newWidth
- buttonWidth
;
538 goButtonBounds
.bottom
= newHeight
;
539 InvalidateRect(&goButtonBounds
, TRUE
);
541 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
545 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
552 WINDOWPOS positionInfoCopy
;
562 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
563 newHeight
= positionInfoCopy
.cy
;
564 newWidth
= positionInfoCopy
.cx
;
565 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
567 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
568 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
569 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
570 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
571 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
572 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
573 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
575 goButtonBounds
.left
= newWidth
- buttonWidth
;
576 goButtonBounds
.top
= 0;
577 goButtonBounds
.right
= newWidth
- buttonWidth
;
578 goButtonBounds
.bottom
= newHeight
;
579 InvalidateRect(&goButtonBounds
, TRUE
);
581 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
585 HRESULT
CreateAddressBand(REFIID riid
, void **ppv
)
587 CComObject
<CAddressBand
> *theMenuBar
;
593 ATLTRY (theMenuBar
= new CComObject
<CAddressBand
>);
594 if (theMenuBar
== NULL
)
595 return E_OUTOFMEMORY
;
596 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));