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
26 #include <commoncontrols.h>
27 #include <shlwapi_undoc.h>
30 HRESULT
CreateAddressEditBox(REFIID riid
, void **ppv
);
33 HRESULT WINAPI
SHGetImageList(
41 ****Add command handler for show/hide Go button to OnWinEvent
42 ****Add tooltip notify handler
43 **Properly implement GetBandInfo
44 **Add support for showing/hiding Go button
45 **Fix so Go button will be shown/hidden properly on load
46 **Add correct text to Go button
47 **Implement TranslateAcceleratorIO
49 Implement QueryService
54 CAddressBand::CAddressBand()
59 fGoButtonShown
= false;
63 CAddressBand::~CAddressBand()
67 void CAddressBand::FocusChange(BOOL bFocus
)
71 //Inform the input object site that the focus has changed.
75 fSite
->OnFocusChangeIS((IDockingWindow
*)this, bFocus
);
80 HRESULT STDMETHODCALLTYPE
CAddressBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
*pdbi
)
82 if (pdbi
->dwMask
& DBIM_MINSIZE
)
84 pdbi
->ptMinSize
.x
= 400;
85 pdbi
->ptMinSize
.y
= 22;
87 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
89 pdbi
->ptMaxSize
.x
= 0;
90 pdbi
->ptMaxSize
.y
= 0;
92 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
94 pdbi
->ptIntegral
.x
= 0;
95 pdbi
->ptIntegral
.y
= 0;
97 if (pdbi
->dwMask
& DBIM_ACTUAL
)
99 pdbi
->ptActual
.x
= 400;
100 pdbi
->ptActual
.y
= 22;
102 if (pdbi
->dwMask
& DBIM_TITLE
)
103 wcscpy(pdbi
->wszTitle
, L
"Address");
104 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
105 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
106 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
111 HRESULT STDMETHODCALLTYPE
CAddressBand::SetSite(IUnknown
*pUnkSite
)
113 CComPtr
<IBrowserService
> browserService
;
114 CComPtr
<IOleWindow
> oleWindow
;
115 CComPtr
<IShellService
> shellService
;
116 CComPtr
<IUnknown
> offset34
;
119 static const TBBUTTON buttonInfo
[] = { {0, 1, TBSTATE_ENABLED
, 0} };
120 HIMAGELIST normalImagelist
;
121 HIMAGELIST hotImageList
;
122 HINSTANCE shellInstance
;
125 if (pUnkSite
== NULL
)
127 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
134 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
138 // get window handle of parent
140 hResult
= IUnknown_GetWindow(pUnkSite
, &parentWindow
);
142 if (!::IsWindow(parentWindow
))
145 // create combo box ex
146 combobox
= CreateWindowEx(WS_EX_TOOLWINDOW
, WC_COMBOBOXEXW
, NULL
, WS_CHILD
| WS_VISIBLE
|
147 WS_CLIPCHILDREN
| WS_TABSTOP
| CCS_NODIVIDER
| CCS_NOMOVEY
| CBS_OWNERDRAWFIXED
,
148 0, 0, 500, 250, parentWindow
, (HMENU
)0xa205, _AtlBaseModule
.GetModuleInstance(), 0);
149 if (combobox
== NULL
)
151 SubclassWindow(combobox
);
153 SendMessage(CBEM_SETEXTENDEDSTYLE
,
154 CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
, CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
);
156 fEditControl
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETEDITCONTROL
, 0, 0));
157 fComboBox
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETCOMBOCONTROL
, 0, 0));
159 hResult
= CoCreateInstance(CLSID_AddressEditBox
, NULL
, CLSCTX_INPROC_SERVER
,
160 IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
166 // instantiate new version
167 hResult
= CreateAddressEditBox(IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
172 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &shellService
));
175 hResult
= fAddressEditBox
->Init(combobox
, fEditControl
, 8, pUnkSite
/*(IAddressBand *)this*/);
178 hResult
= shellService
->SetOwner(pUnkSite
);
182 // TODO: properly initialize this from registry
183 fGoButtonShown
= true;
185 shellInstance
= GetModuleHandle(_T("shell32.dll"));
186 normalImagelist
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
187 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
188 hotImageList
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
189 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
191 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
192 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
193 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
194 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
195 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
196 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
198 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(normalImagelist
));
200 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(hotImageList
));
201 SendMessage(fGoButton
, TB_ADDSTRINGW
,
202 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
203 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
)&buttonInfo
);
206 HRESULT hr
= SHGetImageList(SHIL_SMALL
, IID_PPV_ARG(IImageList
, &piml
));
207 if (FAILED_UNEXPECTEDLY(hr
))
209 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, 0);
213 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(piml
));
216 // take advice to watch events
217 hResult
= IUnknown_QueryService(pUnkSite
, SID_SShellBrowser
, IID_PPV_ARG(IBrowserService
, &browserService
));
218 if (SUCCEEDED(hResult
))
220 if (SUCCEEDED(hResult
))
221 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
227 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
231 return fSite
->QueryInterface(riid
, ppvSite
);
234 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
242 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
247 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
259 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
260 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
265 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
277 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
278 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
280 CComPtr
<IOleCommandTarget
> oleCommandTarget
;
283 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IOleCommandTarget
, &oleCommandTarget
));
286 return oleCommandTarget
->QueryStatus(pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
289 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
290 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
296 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
298 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
303 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
309 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
311 CComPtr
<IInputObjectSite
> inputObjectSite
;
316 hResult
= fSite
->QueryInterface(IID_PPV_ARG(IInputObjectSite
, &inputObjectSite
));
319 hResult
= inputObjectSite
->OnFocusChangeIS(static_cast<IDeskBand
*>(this), fActivate
);
325 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
326 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
328 CComPtr
<IWinEventHandler
> winEventHandler
;
333 case WM_WININICHANGE
:
336 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
338 // toggle whether the Go button is displayed
339 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
340 // broadcast change notification to all explorer windows
344 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
347 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
350 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
352 CComPtr
<IWinEventHandler
> winEventHandler
;
357 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
360 return winEventHandler
->IsWindowOwner(hWnd
);
365 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
367 CComPtr
<IAddressBand
> addressBand
;
370 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
373 return addressBand
->FileSysChange(param8
, paramC
);
376 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
378 CComPtr
<IAddressBand
> addressBand
;
381 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
384 return addressBand
->Refresh(param8
);
387 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
392 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
397 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
399 if (pClassID
== NULL
)
401 *pClassID
= CLSID_SH_AddressBand
;
405 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
410 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
416 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
422 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
428 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfoCount(UINT
*pctinfo
)
433 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
438 HRESULT STDMETHODCALLTYPE
CAddressBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
439 LCID lcid
, DISPID
*rgDispId
)
444 HRESULT STDMETHODCALLTYPE
CAddressBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
445 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
447 CComPtr
<IBrowserService
> isb
;
448 CComPtr
<IShellFolder
> sf
;
450 INT indexClosed
, indexOpen
, itemExists
, oldIndex
;
452 COMBOBOXEXITEMW item
;
453 PIDLIST_ABSOLUTE absolutePIDL
;
454 LPCITEMIDLIST pidlChild
;
455 LPITEMIDLIST pidlPrevious
;
459 if (pDispParams
== NULL
)
462 switch (dispIdMember
)
464 case DISPID_NAVIGATECOMPLETE2
:
465 case DISPID_DOCUMENTCOMPLETE
:
467 oldIndex
= SendMessage(m_hWnd
, CB_GETCURSEL
, 0, 0);
469 item
.mask
= CBEIF_LPARAM
;
471 itemExists
= SendMessage(m_hWnd
, CBEM_GETITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
474 pidlPrevious
= reinterpret_cast<LPITEMIDLIST
>(item
.lParam
);
477 hr
= IUnknown_QueryService(fSite
, SID_STopLevelBrowser
, IID_PPV_ARG(IBrowserService
, &isb
));
480 isb
->GetPidl(&absolutePIDL
);
482 SHBindToParent(absolutePIDL
, IID_PPV_ARG(IShellFolder
, &sf
), &pidlChild
);
484 sf
->GetDisplayNameOf(pidlChild
, SHGDN_FORADDRESSBAR
| SHGDN_FORPARSING
, &ret
);
486 StrRetToBufW(&ret
, pidlChild
, buf
, 4095);
488 indexClosed
= SHMapPIDLToSystemImageListIndex(sf
, pidlChild
, &indexOpen
);
490 item
.mask
= CBEIF_IMAGE
| CBEIF_SELECTEDIMAGE
| CBEIF_TEXT
| CBEIF_LPARAM
;
492 item
.iImage
= indexClosed
;
493 item
.iSelectedImage
= indexOpen
;
495 item
.lParam
= reinterpret_cast<LPARAM
>(absolutePIDL
);
499 result
= SendMessage(m_hWnd
, CBEM_SETITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
503 ILFree(pidlPrevious
);
508 oldIndex
= SendMessage(m_hWnd
, CBEM_INSERTITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
511 DbgPrint("ERROR %d\n", GetLastError());
514 SendMessage(m_hWnd
, CB_SETCURSEL
, oldIndex
, 0);
516 //fAddressEditBox->SetCurrentDir(index);
523 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
525 if (notifyHeader
->hwndFrom
== fGoButton
)
527 fAddressEditBox
->ParseNow(0);
528 fAddressEditBox
->Execute(0);
533 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
535 if (notifyHeader
->hwndFrom
== fGoButton
)
538 // Go to "destination path"
543 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
550 if (fGoButtonShown
== false)
557 parentWindow
= GetParent();
558 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
559 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
560 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
561 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
570 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
580 if (fGoButtonShown
== false)
586 newHeight
= HIWORD(lParam
);
587 newWidth
= LOWORD(lParam
);
589 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
590 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
591 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
593 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
594 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
595 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
596 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
598 goButtonBounds
.left
= newWidth
- buttonWidth
;
599 goButtonBounds
.top
= 0;
600 goButtonBounds
.right
= newWidth
- buttonWidth
;
601 goButtonBounds
.bottom
= newHeight
;
602 InvalidateRect(&goButtonBounds
, TRUE
);
604 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
608 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
615 WINDOWPOS positionInfoCopy
;
625 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
626 newHeight
= positionInfoCopy
.cy
;
627 newWidth
= positionInfoCopy
.cx
;
628 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
630 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
631 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
632 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
633 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
634 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
635 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
636 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
638 goButtonBounds
.left
= newWidth
- buttonWidth
;
639 goButtonBounds
.top
= 0;
640 goButtonBounds
.right
= newWidth
- buttonWidth
;
641 goButtonBounds
.bottom
= newHeight
;
642 InvalidateRect(&goButtonBounds
, TRUE
);
644 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
648 HRESULT
CreateAddressBand(REFIID riid
, void **ppv
)
650 CComObject
<CAddressBand
> *theMenuBar
;
656 ATLTRY (theMenuBar
= new CComObject
<CAddressBand
>);
657 if (theMenuBar
== NULL
)
658 return E_OUTOFMEMORY
;
659 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));