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>
32 ****Add command handler for show/hide Go button to OnWinEvent
33 ****Add tooltip notify handler
34 **Properly implement GetBandInfo
35 **Add correct text to Go button
36 **Implement TranslateAcceleratorIO
38 Implement QueryService
43 CAddressBand::CAddressBand()
48 fGoButtonShown
= false;
52 CAddressBand::~CAddressBand()
56 void CAddressBand::FocusChange(BOOL bFocus
)
60 //Inform the input object site that the focus has changed.
64 fSite
->OnFocusChangeIS((IDockingWindow
*)this, bFocus
);
69 HRESULT STDMETHODCALLTYPE
CAddressBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
*pdbi
)
71 if (pdbi
->dwMask
& DBIM_MINSIZE
)
73 pdbi
->ptMinSize
.x
= 400;
74 pdbi
->ptMinSize
.y
= 22;
76 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
78 pdbi
->ptMaxSize
.x
= 0;
79 pdbi
->ptMaxSize
.y
= 0;
81 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
83 pdbi
->ptIntegral
.x
= 0;
84 pdbi
->ptIntegral
.y
= 0;
86 if (pdbi
->dwMask
& DBIM_ACTUAL
)
88 pdbi
->ptActual
.x
= 400;
89 pdbi
->ptActual
.y
= 22;
91 if (pdbi
->dwMask
& DBIM_TITLE
)
93 if (!LoadStringW(_AtlBaseModule
.GetResourceInstance(), IDS_ADDRESSBANDLABEL
, pdbi
->wszTitle
, _countof(pdbi
->wszTitle
)))
94 return HRESULT_FROM_WIN32(GetLastError());
97 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
98 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
99 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
104 HRESULT STDMETHODCALLTYPE
CAddressBand::SetSite(IUnknown
*pUnkSite
)
106 CComPtr
<IBrowserService
> browserService
;
107 CComPtr
<IShellService
> shellService
;
113 if (pUnkSite
== NULL
)
115 hResult
= AtlUnadvise(fSite
, DIID_DWebBrowserEvents
, fAdviseCookie
);
122 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
123 if (FAILED_UNEXPECTEDLY(hResult
))
126 // get window handle of parent
128 hResult
= IUnknown_GetWindow(fSite
, &parentWindow
);
130 if (!::IsWindow(parentWindow
))
133 // create combo box ex
134 combobox
= CreateWindowEx(WS_EX_TOOLWINDOW
, WC_COMBOBOXEXW
, NULL
, WS_CHILD
| WS_VISIBLE
|
135 WS_CLIPCHILDREN
| WS_TABSTOP
| CCS_NODIVIDER
| CCS_NOMOVEY
| CBS_OWNERDRAWFIXED
,
136 0, 0, 500, 250, parentWindow
, (HMENU
)IDM_TOOLBARS_ADDRESSBAR
, _AtlBaseModule
.GetModuleInstance(), 0);
137 if (combobox
== NULL
)
139 SubclassWindow(combobox
);
141 HRESULT hr
= SHGetImageList(SHIL_SMALL
, IID_PPV_ARG(IImageList
, &piml
));
142 if (FAILED_UNEXPECTEDLY(hr
))
144 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, 0);
148 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(piml
));
151 SendMessage(CBEM_SETEXTENDEDSTYLE
,
152 CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
, CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
);
154 fEditControl
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETEDITCONTROL
, 0, 0));
155 fComboBox
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETCOMBOCONTROL
, 0, 0));
156 hResult
= CAddressEditBox_CreateInstance(IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
157 if (FAILED_UNEXPECTEDLY(hResult
))
160 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &shellService
));
161 if (FAILED_UNEXPECTEDLY(hResult
))
163 hResult
= fAddressEditBox
->Init(combobox
, fEditControl
, 8, fSite
/*(IAddressBand *)this*/);
164 if (FAILED_UNEXPECTEDLY(hResult
))
166 hResult
= shellService
->SetOwner(fSite
);
167 if (FAILED_UNEXPECTEDLY(hResult
))
170 fGoButtonShown
= SHRegGetBoolUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", FALSE
, TRUE
);
174 // take advice to watch events
175 hResult
= IUnknown_QueryService(pUnkSite
, SID_SShellBrowser
, IID_PPV_ARG(IBrowserService
, &browserService
));
176 if (SUCCEEDED(hResult
))
178 hResult
= AtlAdvise(browserService
, static_cast<IDispatch
*>(this), DIID_DWebBrowserEvents
, &fAdviseCookie
);
184 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
188 return fSite
->QueryInterface(riid
, ppvSite
);
191 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
199 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
204 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
213 IUnknown_SetSite(fAddressEditBox
, NULL
);
215 if (fAddressEditBox
) fAddressEditBox
.Release();
216 if (fSite
) fSite
.Release();
221 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
222 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
227 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
239 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
240 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
242 return IUnknown_QueryStatus(fAddressEditBox
, *pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
245 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
246 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
252 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
254 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
259 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
261 if (lpMsg
->hwnd
== fEditControl
)
263 switch (lpMsg
->message
)
273 TranslateMessage(lpMsg
);
274 DispatchMessage(lpMsg
);
280 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
284 IUnknown_OnFocusChangeIS(fSite
, static_cast<IDeskBand
*>(this), fActivate
);
290 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
291 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
293 CComPtr
<IWinEventHandler
> winEventHandler
;
301 case WM_WININICHANGE
:
304 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
306 fGoButtonShown
= !SHRegGetBoolUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", FALSE
, TRUE
);
307 SHRegSetUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", REG_SZ
, fGoButtonShown
? (LPVOID
)L
"yes" : (LPVOID
)L
"no", fGoButtonShown
? 8 : 6, SHREGSET_FORCE_HKCU
);
310 ::ShowWindow(fGoButton
,fGoButtonShown
? SW_HIDE
: SW_SHOW
);
311 GetWindowRect(&rect
);
312 SendMessage(m_hWnd
,WM_SIZE
,0,MAKELPARAM(rect
.right
-rect
.left
,rect
.bottom
-rect
.top
));
313 // broadcast change notification to all explorer windows
317 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
318 if (FAILED_UNEXPECTEDLY(hResult
))
320 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
323 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
325 CComPtr
<IWinEventHandler
> winEventHandler
;
330 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
331 if (FAILED_UNEXPECTEDLY(hResult
))
333 return winEventHandler
->IsWindowOwner(hWnd
);
338 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
340 CComPtr
<IAddressBand
> addressBand
;
343 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
344 if (FAILED_UNEXPECTEDLY(hResult
))
346 return addressBand
->FileSysChange(param8
, paramC
);
349 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
351 CComPtr
<IAddressBand
> addressBand
;
354 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
355 if (FAILED_UNEXPECTEDLY(hResult
))
357 return addressBand
->Refresh(param8
);
360 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
365 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
370 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
372 if (pClassID
== NULL
)
374 *pClassID
= CLSID_SH_AddressBand
;
378 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
383 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
389 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
395 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
401 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfoCount(UINT
*pctinfo
)
406 HRESULT STDMETHODCALLTYPE
CAddressBand::GetTypeInfo(UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
411 HRESULT STDMETHODCALLTYPE
CAddressBand::GetIDsOfNames(REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
,
412 LCID lcid
, DISPID
*rgDispId
)
417 HRESULT STDMETHODCALLTYPE
CAddressBand::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
,
418 DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
420 CComPtr
<IBrowserService
> isb
;
421 CComPtr
<IShellFolder
> sf
;
423 INT indexClosed
, indexOpen
, itemExists
, oldIndex
;
425 COMBOBOXEXITEMW item
;
426 PIDLIST_ABSOLUTE absolutePIDL
;
427 LPCITEMIDLIST pidlChild
;
428 LPITEMIDLIST pidlPrevious
;
432 if (pDispParams
== NULL
)
435 switch (dispIdMember
)
437 case DISPID_NAVIGATECOMPLETE2
:
438 case DISPID_DOCUMENTCOMPLETE
:
440 oldIndex
= SendMessage(m_hWnd
, CB_GETCURSEL
, 0, 0);
445 ZeroMemory(&item
, sizeof(item
));
446 item
.mask
= CBEIF_LPARAM
;
448 if (SendMessage(m_hWnd
, CBEM_GETITEM
, 0, reinterpret_cast<LPARAM
>(&item
)))
450 pidlPrevious
= reinterpret_cast<LPITEMIDLIST
>(item
.lParam
);
455 hr
= IUnknown_QueryService(fSite
, SID_STopLevelBrowser
, IID_PPV_ARG(IBrowserService
, &isb
));
456 if (FAILED_UNEXPECTEDLY(hr
))
458 isb
->GetPidl(&absolutePIDL
);
460 SHBindToParent(absolutePIDL
, IID_PPV_ARG(IShellFolder
, &sf
), &pidlChild
);
462 sf
->GetDisplayNameOf(pidlChild
, SHGDN_FORADDRESSBAR
| SHGDN_FORPARSING
, &ret
);
464 StrRetToBufW(&ret
, pidlChild
, buf
, 4095);
466 indexClosed
= SHMapPIDLToSystemImageListIndex(sf
, pidlChild
, &indexOpen
);
468 item
.mask
= CBEIF_IMAGE
| CBEIF_SELECTEDIMAGE
| CBEIF_TEXT
| CBEIF_LPARAM
;
470 item
.iImage
= indexClosed
;
471 item
.iSelectedImage
= indexOpen
;
473 item
.lParam
= reinterpret_cast<LPARAM
>(absolutePIDL
);
477 result
= SendMessage(m_hWnd
, CBEM_SETITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
482 ILFree(pidlPrevious
);
487 oldIndex
= SendMessage(m_hWnd
, CBEM_INSERTITEM
, 0, reinterpret_cast<LPARAM
>(&item
));
490 DbgPrint("ERROR %d\n", GetLastError());
493 SendMessage(m_hWnd
, CB_SETCURSEL
, -1, 0);
494 SendMessage(m_hWnd
, CB_SETCURSEL
, oldIndex
, 0);
496 //fAddressEditBox->SetCurrentDir(index);
503 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
505 if (notifyHeader
->hwndFrom
== fGoButton
)
507 fAddressEditBox
->Execute(0);
512 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
514 if (notifyHeader
->hwndFrom
== fGoButton
)
517 // Go to "destination path"
522 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
529 if (fGoButtonShown
== false)
536 parentWindow
= GetParent();
537 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
538 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
539 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
540 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
549 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
559 if (fGoButtonShown
== false)
565 newHeight
= HIWORD(lParam
);
566 newWidth
= LOWORD(lParam
);
571 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
572 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
573 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
575 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
576 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
577 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
578 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
580 goButtonBounds
.left
= newWidth
- buttonWidth
;
581 goButtonBounds
.top
= 0;
582 goButtonBounds
.right
= newWidth
- buttonWidth
;
583 goButtonBounds
.bottom
= newHeight
;
584 InvalidateRect(&goButtonBounds
, TRUE
);
586 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
590 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
597 WINDOWPOS positionInfoCopy
;
610 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
611 newHeight
= positionInfoCopy
.cy
;
612 newWidth
= positionInfoCopy
.cx
;
613 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
615 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
616 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
617 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
618 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
619 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
620 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
621 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
623 goButtonBounds
.left
= newWidth
- buttonWidth
;
624 goButtonBounds
.top
= 0;
625 goButtonBounds
.right
= newWidth
- buttonWidth
;
626 goButtonBounds
.bottom
= newHeight
;
627 InvalidateRect(&goButtonBounds
, TRUE
);
629 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
633 void CAddressBand::CreateGoButton()
635 const TBBUTTON buttonInfo
[] = { { 0, 1, TBSTATE_ENABLED
, 0 } };
636 HIMAGELIST normalImagelist
;
637 HIMAGELIST hotImageList
;
638 HINSTANCE shellInstance
;
641 shellInstance
= GetModuleHandle(_T("shell32.dll"));
642 normalImagelist
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
643 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
644 hotImageList
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
645 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
647 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
648 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
649 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
650 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
651 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
652 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
654 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(normalImagelist
));
656 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(hotImageList
));
657 SendMessage(fGoButton
, TB_ADDSTRINGW
,
658 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
659 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
) &buttonInfo
);