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
;
104 static const TBBUTTON buttonInfo
[] = { {0, 1, TBSTATE_ENABLED
, 0} };
105 HIMAGELIST normalImagelist
;
106 HIMAGELIST hotImageList
;
107 HINSTANCE shellInstance
;
111 if (pUnkSite
== NULL
)
114 hResult
= pUnkSite
->QueryInterface(IID_PPV_ARG(IDockingWindowSite
, &fSite
));
118 // get window handle of parent
120 hResult
= IUnknown_GetWindow(pUnkSite
, &parentWindow
);
122 if (!::IsWindow(parentWindow
))
125 // create combo box ex
126 combobox
= CreateWindowEx(WS_EX_TOOLWINDOW
, WC_COMBOBOXEXW
, NULL
, WS_CHILD
| WS_VISIBLE
|
127 WS_CLIPCHILDREN
| WS_TABSTOP
| CCS_NODIVIDER
| CCS_NOMOVEY
,
128 0, 0, 500, 250, parentWindow
, (HMENU
)0xa205, _AtlBaseModule
.GetModuleInstance(), 0);
129 if (combobox
== NULL
)
131 SubclassWindow(combobox
);
133 SendMessage(CBEM_SETEXTENDEDSTYLE
,
134 CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
, CBES_EX_CASESENSITIVE
| CBES_EX_NOSIZELIMIT
);
136 fEditControl
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETEDITCONTROL
, 0, 0));
137 fComboBox
= reinterpret_cast<HWND
>(SendMessage(CBEM_GETCOMBOCONTROL
, 0, 0));
139 hResult
= CoCreateInstance(CLSID_AddressEditBox
, NULL
, CLSCTX_INPROC_SERVER
,
140 IID_PPV_ARG(IAddressEditBox
, &fAddressEditBox
));
144 // instantiate new version
147 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IShellService
, &shellService
));
150 hResult
= fAddressEditBox
->Init(combobox
, fEditControl
, 8, pUnkSite
/*(IAddressBand *)this*/);
153 hResult
= shellService
->SetOwner(pUnkSite
);
157 // TODO: properly initialize this from registry
158 fGoButtonShown
= true;
160 shellInstance
= GetModuleHandle(_T("shell32.dll"));
161 normalImagelist
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL
),
162 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
163 hotImageList
= ImageList_LoadImageW(shellInstance
, MAKEINTRESOURCE(IDB_GOBUTTON_HOT
),
164 20, 0, RGB(255, 0, 255), IMAGE_BITMAP
, LR_CREATEDIBSECTION
);
166 fGoButton
= CreateWindowEx(WS_EX_TOOLWINDOW
, TOOLBARCLASSNAMEW
, 0, WS_CHILD
| WS_CLIPSIBLINGS
|
167 WS_CLIPCHILDREN
| TBSTYLE_LIST
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
|
168 CCS_NOPARENTALIGN
| CCS_NORESIZE
,
169 0, 0, 0, 0, m_hWnd
, NULL
, _AtlBaseModule
.GetModuleInstance(), NULL
);
170 SendMessage(fGoButton
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
171 SendMessage(fGoButton
, TB_SETMAXTEXTROWS
, 1, 0);
172 SendMessage(fGoButton
, TB_SETIMAGELIST
, 0, reinterpret_cast<LPARAM
>(normalImagelist
));
173 SendMessage(fGoButton
, TB_SETHOTIMAGELIST
, 0, reinterpret_cast<LPARAM
>(hotImageList
));
174 SendMessage(fGoButton
, TB_ADDSTRINGW
,
175 reinterpret_cast<WPARAM
>(_AtlBaseModule
.GetResourceInstance()), IDS_GOBUTTONLABEL
);
176 SendMessage(fGoButton
, TB_ADDBUTTONSW
, 1, (LPARAM
)&buttonInfo
);
181 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSite(REFIID riid
, void **ppvSite
)
185 return fSite
->QueryInterface(riid
, ppvSite
);
188 HRESULT STDMETHODCALLTYPE
CAddressBand::GetWindow(HWND
*lphwnd
)
196 HRESULT STDMETHODCALLTYPE
CAddressBand::ContextSensitiveHelp(BOOL fEnterMode
)
201 HRESULT STDMETHODCALLTYPE
CAddressBand::CloseDW(DWORD dwReserved
)
213 HRESULT STDMETHODCALLTYPE
CAddressBand::ResizeBorderDW(
214 const RECT
*prcBorder
, IUnknown
*punkToolbarSite
, BOOL fReserved
)
219 HRESULT STDMETHODCALLTYPE
CAddressBand::ShowDW(BOOL fShow
)
231 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryStatus(
232 const GUID
*pguidCmdGroup
, ULONG cCmds
, OLECMD prgCmds
[ ], OLECMDTEXT
*pCmdText
)
234 CComPtr
<IOleCommandTarget
> oleCommandTarget
;
237 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IOleCommandTarget
, &oleCommandTarget
));
240 return oleCommandTarget
->QueryStatus(pguidCmdGroup
, cCmds
, prgCmds
, pCmdText
);
243 HRESULT STDMETHODCALLTYPE
CAddressBand::Exec(const GUID
*pguidCmdGroup
,
244 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
250 HRESULT STDMETHODCALLTYPE
CAddressBand::HasFocusIO()
252 if (GetFocus() == fEditControl
|| SendMessage(CB_GETDROPPEDSTATE
, 0, 0))
257 HRESULT STDMETHODCALLTYPE
CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg
)
263 HRESULT STDMETHODCALLTYPE
CAddressBand::UIActivateIO(BOOL fActivate
, LPMSG lpMsg
)
265 CComPtr
<IInputObjectSite
> inputObjectSite
;
270 hResult
= fSite
->QueryInterface(IID_PPV_ARG(IInputObjectSite
, &inputObjectSite
));
273 hResult
= inputObjectSite
->OnFocusChangeIS(static_cast<IDeskBand
*>(this), fActivate
);
279 HRESULT STDMETHODCALLTYPE
CAddressBand::OnWinEvent(
280 HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*theResult
)
282 CComPtr
<IWinEventHandler
> winEventHandler
;
287 case WM_WININICHANGE
:
290 if (wParam
== IDM_TOOLBARS_GOBUTTON
)
292 // toggle whether the Go button is displayed
293 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
294 // broadcast change notification to all explorer windows
298 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
301 return winEventHandler
->OnWinEvent(hWnd
, uMsg
, wParam
, lParam
, theResult
);
304 HRESULT STDMETHODCALLTYPE
CAddressBand::IsWindowOwner(HWND hWnd
)
306 CComPtr
<IWinEventHandler
> winEventHandler
;
311 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IWinEventHandler
, &winEventHandler
));
314 return winEventHandler
->IsWindowOwner(hWnd
);
319 HRESULT STDMETHODCALLTYPE
CAddressBand::FileSysChange(long param8
, long paramC
)
321 CComPtr
<IAddressBand
> addressBand
;
324 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
327 return addressBand
->FileSysChange(param8
, paramC
);
330 HRESULT STDMETHODCALLTYPE
CAddressBand::Refresh(long param8
)
332 CComPtr
<IAddressBand
> addressBand
;
335 hResult
= fAddressEditBox
->QueryInterface(IID_PPV_ARG(IAddressBand
, &addressBand
));
338 return addressBand
->Refresh(param8
);
341 HRESULT STDMETHODCALLTYPE
CAddressBand::QueryService(REFGUID guidService
, REFIID riid
, void **ppvObject
)
346 HRESULT STDMETHODCALLTYPE
CAddressBand::OnFocusChangeIS(IUnknown
*punkObj
, BOOL fSetFocus
)
351 HRESULT STDMETHODCALLTYPE
CAddressBand::GetClassID(CLSID
*pClassID
)
353 if (pClassID
== NULL
)
355 *pClassID
= CLSID_SH_AddressBand
;
359 HRESULT STDMETHODCALLTYPE
CAddressBand::IsDirty()
364 HRESULT STDMETHODCALLTYPE
CAddressBand::Load(IStream
*pStm
)
370 HRESULT STDMETHODCALLTYPE
CAddressBand::Save(IStream
*pStm
, BOOL fClearDirty
)
376 HRESULT STDMETHODCALLTYPE
CAddressBand::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
382 LRESULT
CAddressBand::OnNotifyClick(WPARAM wParam
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
384 if (notifyHeader
->hwndFrom
== fGoButton
)
386 SendMessage(fEditControl
, WM_KEYDOWN
, 13, 0);
387 SendMessage(fEditControl
, WM_KEYUP
, 13, 0);
392 LRESULT
CAddressBand::OnTipText(UINT idControl
, NMHDR
*notifyHeader
, BOOL
&bHandled
)
394 if (notifyHeader
->hwndFrom
== fGoButton
)
397 // Go to "destination path"
402 LRESULT
CAddressBand::OnEraseBackground(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
409 if (fGoButtonShown
== false)
416 parentWindow
= GetParent();
417 ::MapWindowPoints(m_hWnd
, parentWindow
, &pt
, 1);
418 OffsetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), pt
.x
, pt
.y
, &ptOrig
);
419 result
= SendMessage(parentWindow
, WM_ERASEBKGND
, wParam
, 0);
420 SetWindowOrgEx(reinterpret_cast<HDC
>(wParam
), ptOrig
.x
, ptOrig
.y
, NULL
);
429 LRESULT
CAddressBand::OnSize(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
439 if (fGoButtonShown
== false)
445 newHeight
= HIWORD(lParam
);
446 newWidth
= LOWORD(lParam
);
448 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
449 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
450 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
452 DefWindowProc(WM_SIZE
, wParam
, MAKELONG(newWidth
- buttonWidth
- 2, newHeight
));
453 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
454 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
455 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
457 goButtonBounds
.left
= newWidth
- buttonWidth
;
458 goButtonBounds
.top
= 0;
459 goButtonBounds
.right
= newWidth
- buttonWidth
;
460 goButtonBounds
.bottom
= newHeight
;
461 InvalidateRect(&goButtonBounds
, TRUE
);
463 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
467 LRESULT
CAddressBand::OnWindowPosChanging(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
&bHandled
)
474 WINDOWPOS positionInfoCopy
;
484 positionInfoCopy
= *reinterpret_cast<WINDOWPOS
*>(lParam
);
485 newHeight
= positionInfoCopy
.cy
;
486 newWidth
= positionInfoCopy
.cx
;
487 SendMessage(fGoButton
, TB_GETITEMRECT
, 0, reinterpret_cast<LPARAM
>(&buttonBounds
));
489 buttonWidth
= buttonBounds
.right
- buttonBounds
.left
;
490 buttonHeight
= buttonBounds
.bottom
- buttonBounds
.top
;
491 positionInfoCopy
.cx
= newWidth
- 2 - buttonWidth
;
492 DefWindowProc(WM_WINDOWPOSCHANGING
, wParam
, reinterpret_cast<LPARAM
>(&positionInfoCopy
));
493 ::GetWindowRect(fComboBox
, &comboBoxBounds
);
494 ::SetWindowPos(fGoButton
, NULL
, newWidth
- buttonWidth
, (comboBoxBounds
.bottom
- comboBoxBounds
.top
- buttonHeight
) / 2,
495 buttonWidth
, buttonHeight
, SWP_NOOWNERZORDER
| SWP_SHOWWINDOW
| SWP_NOACTIVATE
| SWP_NOZORDER
);
497 goButtonBounds
.left
= newWidth
- buttonWidth
;
498 goButtonBounds
.top
= 0;
499 goButtonBounds
.right
= newWidth
- buttonWidth
;
500 goButtonBounds
.bottom
= newHeight
;
501 InvalidateRect(&goButtonBounds
, TRUE
);
503 SendMessage(fComboBox
, CB_SETDROPPEDWIDTH
, 200, 0);
507 HRESULT
CreateAddressBand(REFIID riid
, void **ppv
)
509 CComObject
<CAddressBand
> *theMenuBar
;
515 ATLTRY (theMenuBar
= new CComObject
<CAddressBand
>);
516 if (theMenuBar
== NULL
)
517 return E_OUTOFMEMORY
;
518 hResult
= theMenuBar
->QueryInterface(riid
, reinterpret_cast<void **>(ppv
));