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
);
34 ****Add command handler for show/hide Go button to OnWinEvent
35 ****Add tooltip notify handler
36 **Properly implement GetBandInfo
37 **Add correct text to Go button
38 **Implement TranslateAcceleratorIO
40 Implement QueryService
45 CAddressBand::CAddressBand()
50 fGoButtonShown
= false;
54 CAddressBand::~CAddressBand()
58 void CAddressBand::FocusChange(BOOL bFocus
)
62 //Inform the input object site that the focus has changed.
66 fSite
->OnFocusChangeIS((IDockingWindow
*)this, bFocus
);
71 HRESULT STDMETHODCALLTYPE
CAddressBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
*pdbi
)
73 if (pdbi
->dwMask
& DBIM_MINSIZE
)
75 pdbi
->ptMinSize
.x
= 400;
76 pdbi
->ptMinSize
.y
= 22;
78 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
80 pdbi
->ptMaxSize
.x
= 0;
81 pdbi
->ptMaxSize
.y
= 0;
83 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
85 pdbi
->ptIntegral
.x
= 0;
86 pdbi
->ptIntegral
.y
= 0;
88 if (pdbi
->dwMask
& DBIM_ACTUAL
)
90 pdbi
->ptActual
.x
= 400;
91 pdbi
->ptActual
.y
= 22;
93 if (pdbi
->dwMask
& DBIM_TITLE
)
95 if (!LoadStringW(_AtlBaseModule
.GetResourceInstance(), IDS_ADDRESSBANDLABEL
, pdbi
->wszTitle
, _countof(pdbi
->wszTitle
)))
96 return HRESULT_FROM_WIN32(GetLastError());
99 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
100 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
101 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
106 HRESULT STDMETHODCALLTYPE
CAddressBand::SetSite(IUnknown
*pUnkSite
)
108 CComPtr
<IBrowserService
> browserService
;
109 CComPtr
<IShellService
> shellService
;
115 if (pUnkSite
== NULL
)
117 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
124 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
125 if (FAILED_UNEXPECTEDLY(hResult
))
128 // get window handle of parent
130 hResult
= IUnknown_GetWindow(fSite
, &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
| CBS_OWNERDRAWFIXED
,
138 0, 0, 500, 250, parentWindow
, (HMENU
)IDM_TOOLBARS_ADDRESSBAR
, _AtlBaseModule
.GetModuleInstance(), 0);
139 if (combobox
== NULL
)
141 SubclassWindow(combobox
);
143 HRESULT hr
= SHGetImageList(SHIL_SMALL
, IID_PPV_ARG(IImageList
, &piml
));
144 if (FAILED_UNEXPECTEDLY(hr
))
146 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, 0);
150 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(piml
));
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
));
164 if (FAILED_UNEXPECTEDLY(hResult
))
166 // instantiate new version
167 hResult
= CreateAddressEditBox(IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
168 if (FAILED_UNEXPECTEDLY(hResult
))
172 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &shellService
));
173 if (FAILED_UNEXPECTEDLY(hResult
))
175 hResult
= fAddressEditBox
->Init(combobox
, fEditControl
, 8, fSite
/*(IAddressBand *)this*/);
176 if (FAILED_UNEXPECTEDLY(hResult
))
178 hResult
= shellService
->SetOwner(fSite
);
179 if (FAILED_UNEXPECTEDLY(hResult
))
182 fGoButtonShown
= SHRegGetBoolUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", FALSE
, TRUE
);
186 // take advice to watch events
187 hResult
= IUnknown_QueryService(pUnkSite
, SID_SShellBrowser
, IID_PPV_ARG(IBrowserService
, &browserService
));
188 if (SUCCEEDED(hResult
))
190 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
196 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
200 return fSite
->QueryInterface(riid
, ppvSite
);
203 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
211 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
216 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
225 IUnknown_SetSite(fAddressEditBox
, NULL
);
227 if (fAddressEditBox
) fAddressEditBox
.Release();
228 if (fSite
) fSite
.Release();
233 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
234 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
239 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
251 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
252 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
254 return IUnknown_QueryStatus(fAddressEditBox
, *pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
257 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
258 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
264 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
266 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
271 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
273 if (lpMsg
->hwnd
== fEditControl
)
275 switch (lpMsg
->message
)
285 TranslateMessage(lpMsg
);
286 DispatchMessage(lpMsg
);
292 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
296 IUnknown_OnFocusChangeIS(fSite
, static_cast<IDeskBand
*>(this), fActivate
);
302 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
303 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
305 CComPtr
<IWinEventHandler
> winEventHandler
;
313 case WM_WININICHANGE
:
316 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
318 fGoButtonShown
= !SHRegGetBoolUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", FALSE
, TRUE
);
319 SHRegSetUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", REG_SZ
, fGoButtonShown
? (LPVOID
)L
"yes" : (LPVOID
)L
"no", fGoButtonShown
? 8 : 6, SHREGSET_FORCE_HKCU
);
322 ::ShowWindow(fGoButton
,fGoButtonShown
? SW_HIDE
: SW_SHOW
);
323 GetWindowRect(&rect
);
324 SendMessage(m_hWnd
,WM_SIZE
,0,MAKELPARAM(rect
.right
-rect
.left
,rect
.bottom
-rect
.top
));
325 // broadcast change notification to all explorer windows
329 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
330 if (FAILED_UNEXPECTEDLY(hResult
))
332 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
335 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
337 CComPtr
<IWinEventHandler
> winEventHandler
;
342 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
343 if (FAILED_UNEXPECTEDLY(hResult
))
345 return winEventHandler
->IsWindowOwner(hWnd
);
350 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
352 CComPtr
<IAddressBand
> addressBand
;
355 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
356 if (FAILED_UNEXPECTEDLY(hResult
))
358 return addressBand
->FileSysChange(param8
, paramC
);
361 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
363 CComPtr
<IAddressBand
> addressBand
;
366 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
367 if (FAILED_UNEXPECTEDLY(hResult
))
369 return addressBand
->Refresh(param8
);
372 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
377 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
382 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
384 if (pClassID
== NULL
)
386 *pClassID
= CLSID_SH_AddressBand
;
390 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
395 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
401 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
407 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
413 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfoCount(UINT
*pctinfo
)
418 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
423 HRESULT STDMETHODCALLTYPE
CAddressBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
424 LCID lcid
, DISPID
*rgDispId
)
429 HRESULT STDMETHODCALLTYPE
CAddressBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
430 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
432 CComPtr
<IBrowserService
> isb
;
433 CComPtr
<IShellFolder
> sf
;
435 INT indexClosed
, indexOpen
, itemExists
, oldIndex
;
437 COMBOBOXEXITEMW item
;
438 PIDLIST_ABSOLUTE absolutePIDL
;
439 LPCITEMIDLIST pidlChild
;
440 LPITEMIDLIST pidlPrevious
;
444 if (pDispParams
== NULL
)
447 switch (dispIdMember
)
449 case DISPID_NAVIGATECOMPLETE2
:
450 case DISPID_DOCUMENTCOMPLETE
:
452 oldIndex
= SendMessage(m_hWnd
, CB_GETCURSEL
, 0, 0);
457 ZeroMemory(&item
, sizeof(item
));
458 item
.mask
= CBEIF_LPARAM
;
460 if (SendMessage(m_hWnd
, CBEM_GETITEM
, 0, reinterpret_cast<LPARAM
>(&item
)))
462 pidlPrevious
= reinterpret_cast<LPITEMIDLIST
>(item
.lParam
);
467 hr
= IUnknown_QueryService(fSite
, SID_STopLevelBrowser
, IID_PPV_ARG(IBrowserService
, &isb
));
468 if (FAILED_UNEXPECTEDLY(hr
))
470 isb
->GetPidl(&absolutePIDL
);
472 SHBindToParent(absolutePIDL
, IID_PPV_ARG(IShellFolder
, &sf
), &pidlChild
);
474 sf
->GetDisplayNameOf(pidlChild
, SHGDN_FORADDRESSBAR
| SHGDN_FORPARSING
, &ret
);
476 StrRetToBufW(&ret
, pidlChild
, buf
, 4095);
478 indexClosed
= SHMapPIDLToSystemImageListIndex(sf
, pidlChild
, &indexOpen
);
480 item
.mask
= CBEIF_IMAGE
| CBEIF_SELECTEDIMAGE
| CBEIF_TEXT
| CBEIF_LPARAM
;
482 item
.iImage
= indexClosed
;
483 item
.iSelectedImage
= indexOpen
;
485 item
.lParam
= reinterpret_cast<LPARAM
>(absolutePIDL
);
489 result
= SendMessage(m_hWnd
, CBEM_SETITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
494 ILFree(pidlPrevious
);
499 oldIndex
= SendMessage(m_hWnd
, CBEM_INSERTITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
502 DbgPrint("ERROR %d\n", GetLastError());
505 SendMessage(m_hWnd
, CB_SETCURSEL
, -1, 0);
506 SendMessage(m_hWnd
, CB_SETCURSEL
, oldIndex
, 0);
508 //fAddressEditBox->SetCurrentDir(index);
515 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
517 if (notifyHeader
->hwndFrom
== fGoButton
)
519 fAddressEditBox
->Execute(0);
524 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
526 if (notifyHeader
->hwndFrom
== fGoButton
)
529 // Go to "destination path"
534 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
541 if (fGoButtonShown
== false)
548 parentWindow
= GetParent();
549 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
550 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
551 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
552 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
561 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
571 if (fGoButtonShown
== false)
577 newHeight
= HIWORD(lParam
);
578 newWidth
= LOWORD(lParam
);
583 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
584 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
585 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
587 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
588 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
589 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
590 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
592 goButtonBounds
.left
= newWidth
- buttonWidth
;
593 goButtonBounds
.top
= 0;
594 goButtonBounds
.right
= newWidth
- buttonWidth
;
595 goButtonBounds
.bottom
= newHeight
;
596 InvalidateRect(&goButtonBounds
, TRUE
);
598 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
602 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
609 WINDOWPOS positionInfoCopy
;
622 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
623 newHeight
= positionInfoCopy
.cy
;
624 newWidth
= positionInfoCopy
.cx
;
625 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
627 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
628 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
629 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
630 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
631 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
632 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
633 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
635 goButtonBounds
.left
= newWidth
- buttonWidth
;
636 goButtonBounds
.top
= 0;
637 goButtonBounds
.right
= newWidth
- buttonWidth
;
638 goButtonBounds
.bottom
= newHeight
;
639 InvalidateRect(&goButtonBounds
, TRUE
);
641 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
645 HRESULT
CreateAddressBand(REFIID riid
, void **ppv
)
647 return ShellObjectCreator
<CAddressBand
>(riid
, ppv
);
650 void CAddressBand::CreateGoButton()
652 const TBBUTTON buttonInfo
[] = { { 0, 1, TBSTATE_ENABLED
, 0 } };
653 HIMAGELIST normalImagelist
;
654 HIMAGELIST hotImageList
;
655 HINSTANCE shellInstance
;
658 shellInstance
= GetModuleHandle(_T("shell32.dll"));
659 normalImagelist
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
660 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
661 hotImageList
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
662 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
664 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
665 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
666 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
667 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
668 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
669 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
671 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(normalImagelist
));
673 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(hotImageList
));
674 SendMessage(fGoButton
, TB_ADDSTRINGW
,
675 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
676 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
) &buttonInfo
);