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 tooltip notify handler
33 **Properly implement GetBandInfo
35 Implement QueryService
40 CAddressBand::CAddressBand()
45 fGoButtonShown
= false;
48 CAddressBand::~CAddressBand()
52 void CAddressBand::FocusChange(BOOL bFocus
)
56 //Inform the input object site that the focus has changed.
60 fSite
->OnFocusChangeIS((IDockingWindow
*)this, bFocus
);
65 HRESULT STDMETHODCALLTYPE
CAddressBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
*pdbi
)
67 if (pdbi
->dwMask
& DBIM_MINSIZE
)
69 pdbi
->ptMinSize
.x
= 100;
70 pdbi
->ptMinSize
.y
= 22;
72 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
74 pdbi
->ptMaxSize
.x
= 0;
75 pdbi
->ptMaxSize
.y
= 0;
77 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
79 pdbi
->ptIntegral
.x
= 0;
80 pdbi
->ptIntegral
.y
= 0;
82 if (pdbi
->dwMask
& DBIM_ACTUAL
)
84 pdbi
->ptActual
.x
= 100;
85 pdbi
->ptActual
.y
= 22;
87 if (pdbi
->dwMask
& DBIM_TITLE
)
89 if (!LoadStringW(_AtlBaseModule
.GetResourceInstance(), IDS_ADDRESSBANDLABEL
, pdbi
->wszTitle
, _countof(pdbi
->wszTitle
)))
90 return HRESULT_FROM_WIN32(GetLastError());
93 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
94 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
95 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
100 HRESULT STDMETHODCALLTYPE
CAddressBand::SetSite(IUnknown
*pUnkSite
)
102 CComPtr
<IShellService
> shellService
;
108 if (pUnkSite
== NULL
)
116 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
117 if (FAILED_UNEXPECTEDLY(hResult
))
120 // get window handle of parent
122 hResult
= IUnknown_GetWindow(fSite
, &parentWindow
);
124 if (!::IsWindow(parentWindow
))
127 // create combo box ex
128 combobox
= CreateWindowEx(WS_EX_TOOLWINDOW
, WC_COMBOBOXEXW
, NULL
, WS_CHILD
| WS_VISIBLE
|
129 WS_CLIPCHILDREN
| WS_TABSTOP
| CCS_NODIVIDER
| CCS_NOMOVEY
| CBS_OWNERDRAWFIXED
,
130 0, 0, 500, 250, parentWindow
, (HMENU
)IDM_TOOLBARS_ADDRESSBAR
, _AtlBaseModule
.GetModuleInstance(), 0);
131 if (combobox
== NULL
)
133 SubclassWindow(combobox
);
135 HRESULT hr
= SHGetImageList(SHIL_SMALL
, IID_PPV_ARG(IImageList
, &piml
));
136 if (FAILED_UNEXPECTEDLY(hr
))
138 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, 0);
142 SendMessageW(combobox
, CBEM_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(piml
));
145 SendMessage(CBEM_SETEXTENDEDSTYLE
,
146 CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
, CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
);
148 fEditControl
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETEDITCONTROL
, 0, 0));
149 fComboBox
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETCOMBOCONTROL
, 0, 0));
150 hResult
= CAddressEditBox_CreateInstance(IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
151 if (FAILED_UNEXPECTEDLY(hResult
))
154 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &shellService
));
155 if (FAILED_UNEXPECTEDLY(hResult
))
157 hResult
= fAddressEditBox
->Init(combobox
, fEditControl
, 8, fSite
/*(IAddressBand *)this*/);
158 if (FAILED_UNEXPECTEDLY(hResult
))
160 hResult
= shellService
->SetOwner(fSite
);
161 if (FAILED_UNEXPECTEDLY(hResult
))
164 fGoButtonShown
= SHRegGetBoolUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", FALSE
, TRUE
);
171 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
175 return fSite
->QueryInterface(riid
, ppvSite
);
178 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
186 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
191 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
200 CComPtr
<IShellService
> pservice
;
201 HRESULT hres
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &pservice
));
202 if (SUCCEEDED(hres
))
203 pservice
->SetOwner(NULL
);
205 if (fAddressEditBox
) fAddressEditBox
.Release();
206 if (fSite
) fSite
.Release();
209 ImageList_Destroy(m_himlNormal
);
212 ImageList_Destroy(m_himlHot
);
217 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
218 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
223 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
235 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
236 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
238 return IUnknown_QueryStatus(fAddressEditBox
, *pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
241 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
242 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
248 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
250 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
255 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
257 if (lpMsg
->hwnd
== fEditControl
)
259 switch (lpMsg
->message
)
269 TranslateMessage(lpMsg
);
270 DispatchMessage(lpMsg
);
276 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
280 IUnknown_OnFocusChangeIS(fSite
, static_cast<IDeskBand
*>(this), fActivate
);
286 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
287 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
289 CComPtr
<IWinEventHandler
> winEventHandler
;
298 case WM_WININICHANGE
:
301 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
303 fGoButtonShown
= !SHRegGetBoolUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", FALSE
, TRUE
);
304 SHRegSetUSValueW(L
"Software\\Microsoft\\Internet Explorer\\Main", L
"ShowGoButton", REG_SZ
, fGoButtonShown
? (LPVOID
)L
"yes" : (LPVOID
)L
"no", fGoButtonShown
? 8 : 6, SHREGSET_FORCE_HKCU
);
307 ::ShowWindow(fGoButton
,fGoButtonShown
? SW_HIDE
: SW_SHOW
);
308 GetWindowRect(&rect
);
309 SendMessage(m_hWnd
,WM_SIZE
,0,MAKELPARAM(rect
.right
-rect
.left
,rect
.bottom
-rect
.top
));
310 // broadcast change notification to all explorer windows
314 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
315 if (FAILED_UNEXPECTEDLY(hResult
))
317 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
320 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
322 CComPtr
<IWinEventHandler
> winEventHandler
;
327 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
328 if (FAILED_UNEXPECTEDLY(hResult
))
330 return winEventHandler
->IsWindowOwner(hWnd
);
335 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
337 CComPtr
<IAddressBand
> addressBand
;
340 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
341 if (FAILED_UNEXPECTEDLY(hResult
))
343 return addressBand
->FileSysChange(param8
, paramC
);
346 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
348 CComPtr
<IAddressBand
> addressBand
;
351 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
352 if (FAILED_UNEXPECTEDLY(hResult
))
354 return addressBand
->Refresh(param8
);
357 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
362 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
367 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
369 if (pClassID
== NULL
)
371 *pClassID
= CLSID_SH_AddressBand
;
375 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
380 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
386 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
392 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
398 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
400 if (notifyHeader
->hwndFrom
== fGoButton
)
402 fAddressEditBox
->Execute(0);
407 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
409 if (notifyHeader
->hwndFrom
== fGoButton
)
412 // Go to "destination path"
417 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
424 if (fGoButtonShown
== false)
431 parentWindow
= GetParent();
432 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
433 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
434 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
435 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
444 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
454 if (fGoButtonShown
== false)
460 newHeight
= HIWORD(lParam
);
461 newWidth
= LOWORD(lParam
);
466 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
467 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
468 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
470 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
471 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
472 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
473 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
475 goButtonBounds
.left
= newWidth
- buttonWidth
;
476 goButtonBounds
.top
= 0;
477 goButtonBounds
.right
= newWidth
- buttonWidth
;
478 goButtonBounds
.bottom
= newHeight
;
479 InvalidateRect(&goButtonBounds
, TRUE
);
481 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
485 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
492 WINDOWPOS positionInfoCopy
;
505 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
506 newHeight
= positionInfoCopy
.cy
;
507 newWidth
= positionInfoCopy
.cx
;
508 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
510 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
511 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
512 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
513 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
514 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
515 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
516 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
518 goButtonBounds
.left
= newWidth
- buttonWidth
;
519 goButtonBounds
.top
= 0;
520 goButtonBounds
.right
= newWidth
- buttonWidth
;
521 goButtonBounds
.bottom
= newHeight
;
522 InvalidateRect(&goButtonBounds
, TRUE
);
524 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
528 void CAddressBand::CreateGoButton()
530 const TBBUTTON buttonInfo
[] = { { 0, 1, TBSTATE_ENABLED
, 0 } };
531 HINSTANCE shellInstance
;
533 shellInstance
= _AtlBaseModule
.GetResourceInstance();
534 m_himlNormal
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
535 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
536 m_himlHot
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
537 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
539 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
540 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
541 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
542 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
543 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
544 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
546 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(m_himlNormal
));
548 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(m_himlHot
));
549 SendMessage(fGoButton
, TB_ADDSTRINGW
,
550 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
551 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
) &buttonInfo
);