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
29 ****Add command handler for show/hide Go button to OnWinEvent
30 ****Add tooltip notify handler
31 **Properly implement GetBandInfo
32 **Add support for showing/hiding Go button
33 **Fix so Go button will be shown/hidden properly on load
34 **Add correct text to Go button
35 **Implement TranslateAcceleratorIO
37 Implement QueryService
42 CAddressBand::CAddressBand()
47 fGoButtonShown
= false;
50 CAddressBand::~CAddressBand()
54 void CAddressBand::FocusChange(BOOL bFocus
)
58 //Inform the input object site that the focus has changed.
62 fSite
->OnFocusChangeIS((IDockingWindow
*)this, bFocus
);
67 HRESULT STDMETHODCALLTYPE
CAddressBand::GetBandInfo(DWORD dwBandID
, DWORD dwViewMode
, DESKBANDINFO
*pdbi
)
69 if (pdbi
->dwMask
& DBIM_MINSIZE
)
71 pdbi
->ptMinSize
.x
= 400;
72 pdbi
->ptMinSize
.y
= 22;
74 if (pdbi
->dwMask
& DBIM_MAXSIZE
)
76 pdbi
->ptMaxSize
.x
= 0;
77 pdbi
->ptMaxSize
.y
= 0;
79 if (pdbi
->dwMask
& DBIM_INTEGRAL
)
81 pdbi
->ptIntegral
.x
= 0;
82 pdbi
->ptIntegral
.y
= 0;
84 if (pdbi
->dwMask
& DBIM_ACTUAL
)
86 pdbi
->ptActual
.x
= 400;
87 pdbi
->ptActual
.y
= 22;
89 if (pdbi
->dwMask
& DBIM_TITLE
)
90 wcscpy(pdbi
->wszTitle
, L
"Address");
91 if (pdbi
->dwMask
& DBIM_MODEFLAGS
)
92 pdbi
->dwModeFlags
= DBIMF_UNDELETEABLE
;
93 if (pdbi
->dwMask
& DBIM_BKCOLOR
)
98 HRESULT STDMETHODCALLTYPE
CAddressBand::SetSite(IUnknown
*pUnkSite
)
100 CComPtr
<IShellService
> shellService
;
101 CComPtr
<IUnknown
> offset34
;
103 IOleWindow
*oleWindow
;
105 static const TBBUTTON buttonInfo
[] = { {0, 1, TBSTATE_ENABLED
, 0} };
106 HIMAGELIST normalImagelist
;
107 HIMAGELIST hotImageList
;
108 HINSTANCE shellInstance
;
112 if (pUnkSite
== NULL
)
115 hResult
= pUnkSite
->QueryInterface(IID_IDockingWindowSite
, reinterpret_cast<void **>(&fSite
));
119 // get window handle of parent
121 hResult
= pUnkSite
->QueryInterface(IID_IOleWindow
, reinterpret_cast<void **>(&oleWindow
));
122 if (SUCCEEDED(hResult
))
124 oleWindow
->GetWindow(&parentWindow
);
125 oleWindow
->Release();
127 if (!::IsWindow(parentWindow
))
130 // create combo box ex
131 toolbar
= CreateWindowEx(WS_EX_TOOLWINDOW
, WC_COMBOBOXEXW
, NULL
, WS_CHILD
| WS_VISIBLE
|
132 WS_CLIPCHILDREN
| WS_TABSTOP
| CCS_NODIVIDER
| CCS_NOMOVEY
,
133 0, 0, 500, 250, parentWindow
, (HMENU
)0xa205, _AtlBaseModule
.GetModuleInstance(), 0);
136 SubclassWindow(toolbar
);
138 SendMessage(CBEM_SETEXTENDEDSTYLE
,
139 CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
, CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
);
141 fEditControl
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETEDITCONTROL
, 0, 0));
142 fComboBox
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETCOMBOCONTROL
, 0, 0));
144 hResult
= CoCreateInstance(CLSID_AddressEditBox
, NULL
, CLSCTX_INPROC_SERVER
,
145 IID_IAddressEditBox
, reinterpret_cast<void **>(&fAddressEditBox
));
149 // instantiate new version
152 hResult
= fAddressEditBox
->QueryInterface(IID_IShellService
, reinterpret_cast<void **>(&shellService
));
155 hResult
= fAddressEditBox
->Init(toolbar
, fEditControl
, 8, pUnkSite
/*(IAddressBand *)this*/ );
158 hResult
= shellService
->SetOwner(pUnkSite
);
162 // TODO: properly initialize this from registry
163 fGoButtonShown
= true;
165 shellInstance
= GetModuleHandle(_T("shell32.dll"));
166 normalImagelist
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
167 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
168 hotImageList
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
169 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
171 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
172 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
173 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
174 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
175 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
176 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
177 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(normalImagelist
));
178 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(hotImageList
));
179 SendMessage(fGoButton
, TB_ADDSTRINGW
,
180 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
181 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
)&buttonInfo
);
186 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
190 return fSite
->QueryInterface(riid
, ppvSite
);
193 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
201 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
206 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
218 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
219 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
224 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
236 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
237 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
239 CComPtr
<IOleCommandTarget
> oleCommandTarget
;
242 hResult
= fAddressEditBox
->QueryInterface(IID_IOleCommandTarget
, reinterpret_cast<void **>(&oleCommandTarget
));
245 return oleCommandTarget
->QueryStatus(pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
248 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
249 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
255 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
257 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
262 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
268 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
270 CComPtr
<IInputObjectSite
> inputObjectSite
;
275 hResult
= fSite
->QueryInterface(IID_IInputObjectSite
, reinterpret_cast<void **>(&inputObjectSite
));
278 hResult
= inputObjectSite
->OnFocusChangeIS(static_cast<IDeskBand
*>(this), fActivate
);
284 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
285 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
287 CComPtr
<IWinEventHandler
> winEventHandler
;
292 case WM_WININICHANGE
:
295 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
297 // toggle whether the Go button is displayed
298 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
299 // broadcast change notification to all explorer windows
303 hResult
= fAddressEditBox
->QueryInterface(IID_IWinEventHandler
, reinterpret_cast<void **>(&winEventHandler
));
306 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
309 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
311 CComPtr
<IWinEventHandler
> winEventHandler
;
314 hResult
= fAddressEditBox
->QueryInterface(IID_IWinEventHandler
, reinterpret_cast<void **>(&winEventHandler
));
317 return winEventHandler
->IsWindowOwner(hWnd
);
320 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
322 CComPtr
<IAddressBand
> addressBand
;
325 hResult
= fAddressEditBox
->QueryInterface(IID_IAddressBand
, reinterpret_cast<void **>(&addressBand
));
328 return addressBand
->FileSysChange(param8
, paramC
);
331 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
333 CComPtr
<IAddressBand
> addressBand
;
336 hResult
= fAddressEditBox
->QueryInterface(IID_IAddressBand
, reinterpret_cast<void **>(&addressBand
));
339 return addressBand
->Refresh(param8
);
342 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
347 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
352 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
354 if (pClassID
== NULL
)
356 *pClassID
= CLSID_SH_AddressBand
;
360 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
365 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
371 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
377 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
383 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
385 if (notifyHeader
->hwndFrom
== fGoButton
)
387 SendMessage(fEditControl
, WM_KEYDOWN
, 13, 0);
388 SendMessage(fEditControl
, WM_KEYUP
, 13, 0);
393 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
395 if (notifyHeader
->hwndFrom
== fGoButton
)
398 // Go to "destination path"
403 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
410 if (fGoButtonShown
== false)
417 parentWindow
= GetParent();
418 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
419 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
420 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
421 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
430 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
440 if (fGoButtonShown
== false)
446 newHeight
= HIWORD(lParam
);
447 newWidth
= LOWORD(lParam
);
449 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
450 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
451 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
453 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
454 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
455 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
456 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
458 goButtonBounds
.left
= newWidth
- buttonWidth
;
459 goButtonBounds
.top
= 0;
460 goButtonBounds
.right
= newWidth
- buttonWidth
;
461 goButtonBounds
.bottom
= newHeight
;
462 InvalidateRect(&goButtonBounds
, TRUE
);
464 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
468 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
475 WINDOWPOS positionInfoCopy
;
485 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
486 newHeight
= positionInfoCopy
.cy
;
487 newWidth
= positionInfoCopy
.cx
;
488 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
490 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
491 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
492 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
493 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
494 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
495 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
496 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
498 goButtonBounds
.left
= newWidth
- buttonWidth
;
499 goButtonBounds
.top
= 0;
500 goButtonBounds
.right
= newWidth
- buttonWidth
;
501 goButtonBounds
.bottom
= newHeight
;
502 InvalidateRect(&goButtonBounds
, TRUE
);
504 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
508 HRESULT
CreateAddressBand(REFIID riid
, void **ppv
)
510 CComObject
<CAddressBand
> *theMenuBar
;
516 ATLTRY (theMenuBar
= new CComObject
<CAddressBand
>);
517 if (theMenuBar
== NULL
)
518 return E_OUTOFMEMORY
;
519 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));