[BROWSEUI]
[reactos.git] / dll / win32 / browseui / addressband.cpp
1 /*
2 * ReactOS Explorer
3 *
4 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
5 *
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.
10 *
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.
15 *
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
19 */
20
21 /*
22 Implements the navigation band of the cabinet window
23 */
24
25 #include "precomp.h"
26 #include <commoncontrols.h>
27 #include <shlwapi_undoc.h>
28 #include <shellapi.h>
29
30 HRESULT CreateAddressEditBox(REFIID riid, void **ppv);
31
32 extern "C"
33 HRESULT WINAPI SHGetImageList(
34 _In_ int iImageList,
35 _In_ REFIID riid,
36 _Out_ void **ppv
37 );
38
39 /*
40 TODO:
41 ****Add command handler for show/hide Go button to OnWinEvent
42 ****Add tooltip notify handler
43 **Properly implement GetBandInfo
44 **Add support for showing/hiding Go button
45 **Fix so Go button will be shown/hidden properly on load
46 **Add correct text to Go button
47 **Implement TranslateAcceleratorIO
48 Implement Exec
49 Implement QueryService
50 Implement Load
51 Implement Save
52 */
53
54 CAddressBand::CAddressBand()
55 {
56 fEditControl = NULL;
57 fGoButton = NULL;
58 fComboBox = NULL;
59 fGoButtonShown = false;
60 fAdviseCookie = 0;
61 }
62
63 CAddressBand::~CAddressBand()
64 {
65 }
66
67 void CAddressBand::FocusChange(BOOL bFocus)
68 {
69 // m_bFocus = bFocus;
70
71 //Inform the input object site that the focus has changed.
72 if (fSite)
73 {
74 #if 0
75 fSite->OnFocusChangeIS((IDockingWindow *)this, bFocus);
76 #endif
77 }
78 }
79
80 HRESULT STDMETHODCALLTYPE CAddressBand::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi)
81 {
82 if (pdbi->dwMask & DBIM_MINSIZE)
83 {
84 pdbi->ptMinSize.x = 400;
85 pdbi->ptMinSize.y = 22;
86 }
87 if (pdbi->dwMask & DBIM_MAXSIZE)
88 {
89 pdbi->ptMaxSize.x = 0;
90 pdbi->ptMaxSize.y = 0;
91 }
92 if (pdbi->dwMask & DBIM_INTEGRAL)
93 {
94 pdbi->ptIntegral.x = 0;
95 pdbi->ptIntegral.y = 0;
96 }
97 if (pdbi->dwMask & DBIM_ACTUAL)
98 {
99 pdbi->ptActual.x = 400;
100 pdbi->ptActual.y = 22;
101 }
102 if (pdbi->dwMask & DBIM_TITLE)
103 wcscpy(pdbi->wszTitle, L"Address");
104 if (pdbi->dwMask & DBIM_MODEFLAGS)
105 pdbi->dwModeFlags = DBIMF_UNDELETEABLE;
106 if (pdbi->dwMask & DBIM_BKCOLOR)
107 pdbi->crBkgnd = 0;
108 return S_OK;
109 }
110
111 HRESULT STDMETHODCALLTYPE CAddressBand::SetSite(IUnknown *pUnkSite)
112 {
113 CComPtr<IBrowserService> browserService;
114 CComPtr<IOleWindow> oleWindow;
115 CComPtr<IShellService> shellService;
116 CComPtr<IUnknown> offset34;
117 HWND parentWindow;
118 HWND combobox;
119 static const TBBUTTON buttonInfo[] = { {0, 1, TBSTATE_ENABLED, 0} };
120 HIMAGELIST normalImagelist;
121 HIMAGELIST hotImageList;
122 HINSTANCE shellInstance;
123 HRESULT hResult;
124
125 if (pUnkSite == NULL)
126 {
127 hResult = AtlUnadvise(fSite, DIID_DWebBrowserEvents, fAdviseCookie);
128 fSite.Release();
129 return S_OK;
130 }
131
132 fSite.Release();
133
134 hResult = pUnkSite->QueryInterface(IID_PPV_ARG(IDockingWindowSite, &fSite));
135 if (FAILED(hResult))
136 return hResult;
137
138 // get window handle of parent
139 parentWindow = NULL;
140 hResult = IUnknown_GetWindow(pUnkSite, &parentWindow);
141
142 if (!::IsWindow(parentWindow))
143 return E_FAIL;
144
145 // create combo box ex
146 combobox = CreateWindowEx(WS_EX_TOOLWINDOW, WC_COMBOBOXEXW, NULL, WS_CHILD | WS_VISIBLE |
147 WS_CLIPCHILDREN | WS_TABSTOP | CCS_NODIVIDER | CCS_NOMOVEY | CBS_OWNERDRAWFIXED,
148 0, 0, 500, 250, parentWindow, (HMENU)0xa205, _AtlBaseModule.GetModuleInstance(), 0);
149 if (combobox == NULL)
150 return E_FAIL;
151 SubclassWindow(combobox);
152
153 SendMessage(CBEM_SETEXTENDEDSTYLE,
154 CBES_EX_CASESENSITIVE | CBES_EX_NOSIZELIMIT, CBES_EX_CASESENSITIVE | CBES_EX_NOSIZELIMIT);
155
156 fEditControl = reinterpret_cast<HWND>(SendMessage(CBEM_GETEDITCONTROL, 0, 0));
157 fComboBox = reinterpret_cast<HWND>(SendMessage(CBEM_GETCOMBOCONTROL, 0, 0));
158 #if 1
159 hResult = CoCreateInstance(CLSID_AddressEditBox, NULL, CLSCTX_INPROC_SERVER,
160 IID_PPV_ARG(IAddressEditBox, &fAddressEditBox));
161 #else
162 hResult = E_FAIL;
163 #endif
164 if (FAILED(hResult))
165 {
166 // instantiate new version
167 hResult = CreateAddressEditBox(IID_PPV_ARG(IAddressEditBox, &fAddressEditBox));
168 if (FAILED(hResult))
169 return hResult;
170 }
171
172 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IShellService, &shellService));
173 if (FAILED(hResult))
174 return hResult;
175 hResult = fAddressEditBox->Init(combobox, fEditControl, 8, pUnkSite /*(IAddressBand *)this*/);
176 if (FAILED(hResult))
177 return hResult;
178 hResult = shellService->SetOwner(pUnkSite);
179 if (FAILED(hResult))
180 return hResult;
181
182 // TODO: properly initialize this from registry
183 fGoButtonShown = true;
184
185 shellInstance = GetModuleHandle(_T("shell32.dll"));
186 normalImagelist = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL),
187 20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
188 hotImageList = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_HOT),
189 20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
190
191 fGoButton = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAMEW, 0, WS_CHILD | WS_CLIPSIBLINGS |
192 WS_CLIPCHILDREN | TBSTYLE_LIST | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NODIVIDER |
193 CCS_NOPARENTALIGN | CCS_NORESIZE,
194 0, 0, 0, 0, m_hWnd, NULL, _AtlBaseModule.GetModuleInstance(), NULL);
195 SendMessage(fGoButton, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
196 SendMessage(fGoButton, TB_SETMAXTEXTROWS, 1, 0);
197 if (normalImagelist)
198 SendMessage(fGoButton, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(normalImagelist));
199 if (hotImageList)
200 SendMessage(fGoButton, TB_SETHOTIMAGELIST, 0, reinterpret_cast<LPARAM>(hotImageList));
201 SendMessage(fGoButton, TB_ADDSTRINGW,
202 reinterpret_cast<WPARAM>(_AtlBaseModule.GetResourceInstance()), IDS_GOBUTTONLABEL);
203 SendMessage(fGoButton, TB_ADDBUTTONSW, 1, (LPARAM)&buttonInfo);
204
205 IImageList * piml;
206 HRESULT hr = SHGetImageList(SHIL_SMALL, IID_PPV_ARG(IImageList, &piml));
207 if (FAILED_UNEXPECTEDLY(hr))
208 {
209 SendMessageW(combobox, CBEM_SETIMAGELIST, 0, 0);
210 }
211 else
212 {
213 SendMessageW(combobox, CBEM_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(piml));
214 }
215
216 // take advice to watch events
217 hResult = IUnknown_QueryService(pUnkSite, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &browserService));
218 if (SUCCEEDED(hResult))
219 {
220 hResult = AtlAdvise(browserService, static_cast<IDispatch *>(this), DIID_DWebBrowserEvents, &fAdviseCookie);
221 }
222
223 return hResult;
224 }
225
226 HRESULT STDMETHODCALLTYPE CAddressBand::GetSite(REFIID riid, void **ppvSite)
227 {
228 if (fSite == NULL)
229 return E_FAIL;
230 return fSite->QueryInterface(riid, ppvSite);
231 }
232
233 HRESULT STDMETHODCALLTYPE CAddressBand::GetWindow(HWND *lphwnd)
234 {
235 if (lphwnd == NULL)
236 return E_POINTER;
237 *lphwnd = m_hWnd;
238 return S_OK;
239 }
240
241 HRESULT STDMETHODCALLTYPE CAddressBand::ContextSensitiveHelp(BOOL fEnterMode)
242 {
243 return E_NOTIMPL;
244 }
245
246 HRESULT STDMETHODCALLTYPE CAddressBand::CloseDW(DWORD dwReserved)
247 {
248 ShowDW(FALSE);
249
250 if (IsWindow())
251 DestroyWindow();
252
253 m_hWnd = NULL;
254
255 return S_OK;
256 }
257
258 HRESULT STDMETHODCALLTYPE CAddressBand::ResizeBorderDW(
259 const RECT *prcBorder, IUnknown *punkToolbarSite, BOOL fReserved)
260 {
261 return E_NOTIMPL;
262 }
263
264 HRESULT STDMETHODCALLTYPE CAddressBand::ShowDW(BOOL fShow)
265 {
266 if (m_hWnd)
267 {
268 if (fShow)
269 ShowWindow(SW_SHOW);
270 else
271 ShowWindow(SW_HIDE);
272 }
273 return S_OK;
274 }
275
276 HRESULT STDMETHODCALLTYPE CAddressBand::QueryStatus(
277 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText)
278 {
279 CComPtr<IOleCommandTarget> oleCommandTarget;
280 HRESULT hResult;
281
282 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &oleCommandTarget));
283 if (FAILED(hResult))
284 return hResult;
285 return oleCommandTarget->QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
286 }
287
288 HRESULT STDMETHODCALLTYPE CAddressBand::Exec(const GUID *pguidCmdGroup,
289 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
290 {
291 // incomplete
292 return E_NOTIMPL;
293 }
294
295 HRESULT STDMETHODCALLTYPE CAddressBand::HasFocusIO()
296 {
297 if (GetFocus() == fEditControl || SendMessage(CB_GETDROPPEDSTATE, 0, 0))
298 return S_OK;
299 return S_FALSE;
300 }
301
302 HRESULT STDMETHODCALLTYPE CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg)
303 {
304 // incomplete
305 return S_FALSE;
306 }
307
308 HRESULT STDMETHODCALLTYPE CAddressBand::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
309 {
310 CComPtr<IInputObjectSite> inputObjectSite;
311 HRESULT hResult;
312
313 if (fActivate)
314 {
315 hResult = fSite->QueryInterface(IID_PPV_ARG(IInputObjectSite, &inputObjectSite));
316 if (FAILED(hResult))
317 return hResult;
318 hResult = inputObjectSite->OnFocusChangeIS(static_cast<IDeskBand *>(this), fActivate);
319 SetFocus();
320 }
321 return S_OK;
322 }
323
324 HRESULT STDMETHODCALLTYPE CAddressBand::OnWinEvent(
325 HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
326 {
327 CComPtr<IWinEventHandler> winEventHandler;
328 HRESULT hResult;
329
330 switch (uMsg)
331 {
332 case WM_WININICHANGE:
333 break;
334 case WM_COMMAND:
335 if (wParam == IDM_TOOLBARS_GOBUTTON)
336 {
337 // toggle whether the Go button is displayed
338 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
339 // broadcast change notification to all explorer windows
340 }
341 break;
342 }
343 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IWinEventHandler, &winEventHandler));
344 if (FAILED(hResult))
345 return hResult;
346 return winEventHandler->OnWinEvent(hWnd, uMsg, wParam, lParam, theResult);
347 }
348
349 HRESULT STDMETHODCALLTYPE CAddressBand::IsWindowOwner(HWND hWnd)
350 {
351 CComPtr<IWinEventHandler> winEventHandler;
352 HRESULT hResult;
353
354 if (fAddressEditBox)
355 {
356 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IWinEventHandler, &winEventHandler));
357 if (FAILED(hResult))
358 return hResult;
359 return winEventHandler->IsWindowOwner(hWnd);
360 }
361 return S_FALSE;
362 }
363
364 HRESULT STDMETHODCALLTYPE CAddressBand::FileSysChange(long param8, long paramC)
365 {
366 CComPtr<IAddressBand> addressBand;
367 HRESULT hResult;
368
369 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IAddressBand, &addressBand));
370 if (FAILED(hResult))
371 return hResult;
372 return addressBand->FileSysChange(param8, paramC);
373 }
374
375 HRESULT STDMETHODCALLTYPE CAddressBand::Refresh(long param8)
376 {
377 CComPtr<IAddressBand> addressBand;
378 HRESULT hResult;
379
380 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IAddressBand, &addressBand));
381 if (FAILED(hResult))
382 return hResult;
383 return addressBand->Refresh(param8);
384 }
385
386 HRESULT STDMETHODCALLTYPE CAddressBand::QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
387 {
388 return E_NOTIMPL;
389 }
390
391 HRESULT STDMETHODCALLTYPE CAddressBand::OnFocusChangeIS(IUnknown *punkObj, BOOL fSetFocus)
392 {
393 return E_NOTIMPL;
394 }
395
396 HRESULT STDMETHODCALLTYPE CAddressBand::GetClassID(CLSID *pClassID)
397 {
398 if (pClassID == NULL)
399 return E_POINTER;
400 *pClassID = CLSID_SH_AddressBand;
401 return S_OK;
402 }
403
404 HRESULT STDMETHODCALLTYPE CAddressBand::IsDirty()
405 {
406 return E_NOTIMPL;
407 }
408
409 HRESULT STDMETHODCALLTYPE CAddressBand::Load(IStream *pStm)
410 {
411 // incomplete
412 return E_NOTIMPL;
413 }
414
415 HRESULT STDMETHODCALLTYPE CAddressBand::Save(IStream *pStm, BOOL fClearDirty)
416 {
417 // incomplete
418 return E_NOTIMPL;
419 }
420
421 HRESULT STDMETHODCALLTYPE CAddressBand::GetSizeMax(ULARGE_INTEGER *pcbSize)
422 {
423 // incomplete
424 return E_NOTIMPL;
425 }
426
427 HRESULT STDMETHODCALLTYPE CAddressBand::GetTypeInfoCount(UINT *pctinfo)
428 {
429 return E_NOTIMPL;
430 }
431
432 HRESULT STDMETHODCALLTYPE CAddressBand::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
433 {
434 return E_NOTIMPL;
435 }
436
437 HRESULT STDMETHODCALLTYPE CAddressBand::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames,
438 LCID lcid, DISPID *rgDispId)
439 {
440 return E_NOTIMPL;
441 }
442
443 HRESULT STDMETHODCALLTYPE CAddressBand::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
444 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
445 {
446 CComPtr<IBrowserService> isb;
447 CComPtr<IShellFolder> sf;
448 HRESULT hr;
449 INT indexClosed, indexOpen, itemExists, oldIndex;
450 DWORD result;
451 COMBOBOXEXITEMW item;
452 PIDLIST_ABSOLUTE absolutePIDL;
453 LPCITEMIDLIST pidlChild;
454 LPITEMIDLIST pidlPrevious;
455 STRRET ret;
456 WCHAR buf[4096];
457
458 if (pDispParams == NULL)
459 return E_INVALIDARG;
460
461 switch (dispIdMember)
462 {
463 case DISPID_NAVIGATECOMPLETE2:
464 case DISPID_DOCUMENTCOMPLETE:
465
466 oldIndex = SendMessage(m_hWnd, CB_GETCURSEL, 0, 0);
467
468 item.mask = CBEIF_LPARAM;
469 item.iItem = 0;
470 itemExists = SendMessage(m_hWnd, CBEM_GETITEM, 0, reinterpret_cast<LPARAM>(&item));
471 if (itemExists)
472 {
473 pidlPrevious = reinterpret_cast<LPITEMIDLIST>(item.lParam);
474 }
475
476 hr = IUnknown_QueryService(fSite, SID_STopLevelBrowser, IID_PPV_ARG(IBrowserService, &isb));
477 if (FAILED(hr))
478 return hr;
479 isb->GetPidl(&absolutePIDL);
480
481 SHBindToParent(absolutePIDL, IID_PPV_ARG(IShellFolder, &sf), &pidlChild);
482
483 sf->GetDisplayNameOf(pidlChild, SHGDN_FORADDRESSBAR | SHGDN_FORPARSING, &ret);
484
485 StrRetToBufW(&ret, pidlChild, buf, 4095);
486
487 indexClosed = SHMapPIDLToSystemImageListIndex(sf, pidlChild, &indexOpen);
488
489 item.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
490 item.iItem = 0;
491 item.iImage = indexClosed;
492 item.iSelectedImage = indexOpen;
493 item.pszText = buf;
494 item.lParam = reinterpret_cast<LPARAM>(absolutePIDL);
495
496 if (itemExists)
497 {
498 result = SendMessage(m_hWnd, CBEM_SETITEM, 0, reinterpret_cast<LPARAM>(&item));
499
500 if (result)
501 {
502 ILFree(pidlPrevious);
503 }
504 }
505 else
506 {
507 oldIndex = SendMessage(m_hWnd, CBEM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&item));
508
509 if (oldIndex < 0)
510 DbgPrint("ERROR %d\n", GetLastError());
511 }
512
513 SendMessage(m_hWnd, CB_SETCURSEL, oldIndex, 0);
514
515 //fAddressEditBox->SetCurrentDir(index);
516
517 break;
518 }
519 return S_OK;
520 }
521
522 LRESULT CAddressBand::OnNotifyClick(WPARAM wParam, NMHDR *notifyHeader, BOOL &bHandled)
523 {
524 if (notifyHeader->hwndFrom == fGoButton)
525 {
526 fAddressEditBox->ParseNow(0);
527 fAddressEditBox->Execute(0);
528 }
529 return 0;
530 }
531
532 LRESULT CAddressBand::OnTipText(UINT idControl, NMHDR *notifyHeader, BOOL &bHandled)
533 {
534 if (notifyHeader->hwndFrom == fGoButton)
535 {
536 // TODO
537 // Go to "destination path"
538 }
539 return 0;
540 }
541
542 LRESULT CAddressBand::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
543 {
544 POINT pt;
545 POINT ptOrig;
546 HWND parentWindow;
547 LRESULT result;
548
549 if (fGoButtonShown == false)
550 {
551 bHandled = FALSE;
552 return 0;
553 }
554 pt.x = 0;
555 pt.y = 0;
556 parentWindow = GetParent();
557 ::MapWindowPoints(m_hWnd, parentWindow, &pt, 1);
558 OffsetWindowOrgEx(reinterpret_cast<HDC>(wParam), pt.x, pt.y, &ptOrig);
559 result = SendMessage(parentWindow, WM_ERASEBKGND, wParam, 0);
560 SetWindowOrgEx(reinterpret_cast<HDC>(wParam), ptOrig.x, ptOrig.y, NULL);
561 if (result == 0)
562 {
563 bHandled = FALSE;
564 return 0;
565 }
566 return result;
567 }
568
569 LRESULT CAddressBand::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
570 {
571 RECT goButtonBounds;
572 RECT buttonBounds;
573 long buttonWidth;
574 long buttonHeight;
575 RECT comboBoxBounds;
576 long newHeight;
577 long newWidth;
578
579 if (fGoButtonShown == false)
580 {
581 bHandled = FALSE;
582 return 0;
583 }
584
585 newHeight = HIWORD(lParam);
586 newWidth = LOWORD(lParam);
587
588 SendMessage(fGoButton, TB_GETITEMRECT, 0, reinterpret_cast<LPARAM>(&buttonBounds));
589 buttonWidth = buttonBounds.right - buttonBounds.left;
590 buttonHeight = buttonBounds.bottom - buttonBounds.top;
591
592 DefWindowProc(WM_SIZE, wParam, MAKELONG(newWidth - buttonWidth - 2, newHeight));
593 ::GetWindowRect(fComboBox, &comboBoxBounds);
594 ::SetWindowPos(fGoButton, NULL, newWidth - buttonWidth, (comboBoxBounds.bottom - comboBoxBounds.top - buttonHeight) / 2,
595 buttonWidth, buttonHeight, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
596
597 goButtonBounds.left = newWidth - buttonWidth;
598 goButtonBounds.top = 0;
599 goButtonBounds.right = newWidth - buttonWidth;
600 goButtonBounds.bottom = newHeight;
601 InvalidateRect(&goButtonBounds, TRUE);
602
603 SendMessage(fComboBox, CB_SETDROPPEDWIDTH, 200, 0);
604 return 0;
605 }
606
607 LRESULT CAddressBand::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
608 {
609 RECT goButtonBounds;
610 RECT buttonBounds;
611 long buttonWidth;
612 long buttonHeight;
613 RECT comboBoxBounds;
614 WINDOWPOS positionInfoCopy;
615 long newHeight;
616 long newWidth;
617
618 if (!fGoButtonShown)
619 {
620 bHandled = FALSE;
621 return 0;
622 }
623
624 positionInfoCopy = *reinterpret_cast<WINDOWPOS *>(lParam);
625 newHeight = positionInfoCopy.cy;
626 newWidth = positionInfoCopy.cx;
627 SendMessage(fGoButton, TB_GETITEMRECT, 0, reinterpret_cast<LPARAM>(&buttonBounds));
628
629 buttonWidth = buttonBounds.right - buttonBounds.left;
630 buttonHeight = buttonBounds.bottom - buttonBounds.top;
631 positionInfoCopy.cx = newWidth - 2 - buttonWidth;
632 DefWindowProc(WM_WINDOWPOSCHANGING, wParam, reinterpret_cast<LPARAM>(&positionInfoCopy));
633 ::GetWindowRect(fComboBox, &comboBoxBounds);
634 ::SetWindowPos(fGoButton, NULL, newWidth - buttonWidth, (comboBoxBounds.bottom - comboBoxBounds.top - buttonHeight) / 2,
635 buttonWidth, buttonHeight, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
636
637 goButtonBounds.left = newWidth - buttonWidth;
638 goButtonBounds.top = 0;
639 goButtonBounds.right = newWidth - buttonWidth;
640 goButtonBounds.bottom = newHeight;
641 InvalidateRect(&goButtonBounds, TRUE);
642
643 SendMessage(fComboBox, CB_SETDROPPEDWIDTH, 200, 0);
644 return 0;
645 }
646
647 HRESULT CreateAddressBand(REFIID riid, void **ppv)
648 {
649 CComObject<CAddressBand> *theMenuBar;
650 HRESULT hResult;
651
652 if (ppv == NULL)
653 return E_POINTER;
654 *ppv = NULL;
655 ATLTRY (theMenuBar = new CComObject<CAddressBand>);
656 if (theMenuBar == NULL)
657 return E_OUTOFMEMORY;
658 hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
659 if (FAILED(hResult))
660 {
661 delete theMenuBar;
662 return hResult;
663 }
664 return S_OK;
665 }