[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 if (SUCCEEDED(hResult))
221 hResult = AtlAdvise(browserService, static_cast<IDispatch *>(this), DIID_DWebBrowserEvents, &fAdviseCookie);
222 }
223
224 return hResult;
225 }
226
227 HRESULT STDMETHODCALLTYPE CAddressBand::GetSite(REFIID riid, void **ppvSite)
228 {
229 if (fSite == NULL)
230 return E_FAIL;
231 return fSite->QueryInterface(riid, ppvSite);
232 }
233
234 HRESULT STDMETHODCALLTYPE CAddressBand::GetWindow(HWND *lphwnd)
235 {
236 if (lphwnd == NULL)
237 return E_POINTER;
238 *lphwnd = m_hWnd;
239 return S_OK;
240 }
241
242 HRESULT STDMETHODCALLTYPE CAddressBand::ContextSensitiveHelp(BOOL fEnterMode)
243 {
244 return E_NOTIMPL;
245 }
246
247 HRESULT STDMETHODCALLTYPE CAddressBand::CloseDW(DWORD dwReserved)
248 {
249 ShowDW(FALSE);
250
251 if (IsWindow())
252 DestroyWindow();
253
254 m_hWnd = NULL;
255
256 return S_OK;
257 }
258
259 HRESULT STDMETHODCALLTYPE CAddressBand::ResizeBorderDW(
260 const RECT *prcBorder, IUnknown *punkToolbarSite, BOOL fReserved)
261 {
262 return E_NOTIMPL;
263 }
264
265 HRESULT STDMETHODCALLTYPE CAddressBand::ShowDW(BOOL fShow)
266 {
267 if (m_hWnd)
268 {
269 if (fShow)
270 ShowWindow(SW_SHOW);
271 else
272 ShowWindow(SW_HIDE);
273 }
274 return S_OK;
275 }
276
277 HRESULT STDMETHODCALLTYPE CAddressBand::QueryStatus(
278 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText)
279 {
280 CComPtr<IOleCommandTarget> oleCommandTarget;
281 HRESULT hResult;
282
283 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &oleCommandTarget));
284 if (FAILED(hResult))
285 return hResult;
286 return oleCommandTarget->QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
287 }
288
289 HRESULT STDMETHODCALLTYPE CAddressBand::Exec(const GUID *pguidCmdGroup,
290 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
291 {
292 // incomplete
293 return E_NOTIMPL;
294 }
295
296 HRESULT STDMETHODCALLTYPE CAddressBand::HasFocusIO()
297 {
298 if (GetFocus() == fEditControl || SendMessage(CB_GETDROPPEDSTATE, 0, 0))
299 return S_OK;
300 return S_FALSE;
301 }
302
303 HRESULT STDMETHODCALLTYPE CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg)
304 {
305 // incomplete
306 return S_FALSE;
307 }
308
309 HRESULT STDMETHODCALLTYPE CAddressBand::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
310 {
311 CComPtr<IInputObjectSite> inputObjectSite;
312 HRESULT hResult;
313
314 if (fActivate)
315 {
316 hResult = fSite->QueryInterface(IID_PPV_ARG(IInputObjectSite, &inputObjectSite));
317 if (FAILED(hResult))
318 return hResult;
319 hResult = inputObjectSite->OnFocusChangeIS(static_cast<IDeskBand *>(this), fActivate);
320 SetFocus();
321 }
322 return S_OK;
323 }
324
325 HRESULT STDMETHODCALLTYPE CAddressBand::OnWinEvent(
326 HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
327 {
328 CComPtr<IWinEventHandler> winEventHandler;
329 HRESULT hResult;
330
331 switch (uMsg)
332 {
333 case WM_WININICHANGE:
334 break;
335 case WM_COMMAND:
336 if (wParam == IDM_TOOLBARS_GOBUTTON)
337 {
338 // toggle whether the Go button is displayed
339 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
340 // broadcast change notification to all explorer windows
341 }
342 break;
343 }
344 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IWinEventHandler, &winEventHandler));
345 if (FAILED(hResult))
346 return hResult;
347 return winEventHandler->OnWinEvent(hWnd, uMsg, wParam, lParam, theResult);
348 }
349
350 HRESULT STDMETHODCALLTYPE CAddressBand::IsWindowOwner(HWND hWnd)
351 {
352 CComPtr<IWinEventHandler> winEventHandler;
353 HRESULT hResult;
354
355 if (fAddressEditBox)
356 {
357 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IWinEventHandler, &winEventHandler));
358 if (FAILED(hResult))
359 return hResult;
360 return winEventHandler->IsWindowOwner(hWnd);
361 }
362 return S_FALSE;
363 }
364
365 HRESULT STDMETHODCALLTYPE CAddressBand::FileSysChange(long param8, long paramC)
366 {
367 CComPtr<IAddressBand> addressBand;
368 HRESULT hResult;
369
370 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IAddressBand, &addressBand));
371 if (FAILED(hResult))
372 return hResult;
373 return addressBand->FileSysChange(param8, paramC);
374 }
375
376 HRESULT STDMETHODCALLTYPE CAddressBand::Refresh(long param8)
377 {
378 CComPtr<IAddressBand> addressBand;
379 HRESULT hResult;
380
381 hResult = fAddressEditBox->QueryInterface(IID_PPV_ARG(IAddressBand, &addressBand));
382 if (FAILED(hResult))
383 return hResult;
384 return addressBand->Refresh(param8);
385 }
386
387 HRESULT STDMETHODCALLTYPE CAddressBand::QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
388 {
389 return E_NOTIMPL;
390 }
391
392 HRESULT STDMETHODCALLTYPE CAddressBand::OnFocusChangeIS(IUnknown *punkObj, BOOL fSetFocus)
393 {
394 return E_NOTIMPL;
395 }
396
397 HRESULT STDMETHODCALLTYPE CAddressBand::GetClassID(CLSID *pClassID)
398 {
399 if (pClassID == NULL)
400 return E_POINTER;
401 *pClassID = CLSID_SH_AddressBand;
402 return S_OK;
403 }
404
405 HRESULT STDMETHODCALLTYPE CAddressBand::IsDirty()
406 {
407 return E_NOTIMPL;
408 }
409
410 HRESULT STDMETHODCALLTYPE CAddressBand::Load(IStream *pStm)
411 {
412 // incomplete
413 return E_NOTIMPL;
414 }
415
416 HRESULT STDMETHODCALLTYPE CAddressBand::Save(IStream *pStm, BOOL fClearDirty)
417 {
418 // incomplete
419 return E_NOTIMPL;
420 }
421
422 HRESULT STDMETHODCALLTYPE CAddressBand::GetSizeMax(ULARGE_INTEGER *pcbSize)
423 {
424 // incomplete
425 return E_NOTIMPL;
426 }
427
428 HRESULT STDMETHODCALLTYPE CAddressBand::GetTypeInfoCount(UINT *pctinfo)
429 {
430 return E_NOTIMPL;
431 }
432
433 HRESULT STDMETHODCALLTYPE CAddressBand::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
434 {
435 return E_NOTIMPL;
436 }
437
438 HRESULT STDMETHODCALLTYPE CAddressBand::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames,
439 LCID lcid, DISPID *rgDispId)
440 {
441 return E_NOTIMPL;
442 }
443
444 HRESULT STDMETHODCALLTYPE CAddressBand::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
445 DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
446 {
447 CComPtr<IBrowserService> isb;
448 CComPtr<IShellFolder> sf;
449 HRESULT hr;
450 INT indexClosed, indexOpen, itemExists, oldIndex;
451 DWORD result;
452 COMBOBOXEXITEMW item;
453 PIDLIST_ABSOLUTE absolutePIDL;
454 LPCITEMIDLIST pidlChild;
455 LPITEMIDLIST pidlPrevious;
456 STRRET ret;
457 WCHAR buf[4096];
458
459 if (pDispParams == NULL)
460 return E_INVALIDARG;
461
462 switch (dispIdMember)
463 {
464 case DISPID_NAVIGATECOMPLETE2:
465 case DISPID_DOCUMENTCOMPLETE:
466
467 oldIndex = SendMessage(m_hWnd, CB_GETCURSEL, 0, 0);
468
469 item.mask = CBEIF_LPARAM;
470 item.iItem = 0;
471 itemExists = SendMessage(m_hWnd, CBEM_GETITEM, 0, reinterpret_cast<LPARAM>(&item));
472 if (itemExists)
473 {
474 pidlPrevious = reinterpret_cast<LPITEMIDLIST>(item.lParam);
475 }
476
477 hr = IUnknown_QueryService(fSite, SID_STopLevelBrowser, IID_PPV_ARG(IBrowserService, &isb));
478 if (FAILED(hr))
479 return hr;
480 isb->GetPidl(&absolutePIDL);
481
482 SHBindToParent(absolutePIDL, IID_PPV_ARG(IShellFolder, &sf), &pidlChild);
483
484 sf->GetDisplayNameOf(pidlChild, SHGDN_FORADDRESSBAR | SHGDN_FORPARSING, &ret);
485
486 StrRetToBufW(&ret, pidlChild, buf, 4095);
487
488 indexClosed = SHMapPIDLToSystemImageListIndex(sf, pidlChild, &indexOpen);
489
490 item.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
491 item.iItem = 0;
492 item.iImage = indexClosed;
493 item.iSelectedImage = indexOpen;
494 item.pszText = buf;
495 item.lParam = reinterpret_cast<LPARAM>(absolutePIDL);
496
497 if (itemExists)
498 {
499 result = SendMessage(m_hWnd, CBEM_SETITEM, 0, reinterpret_cast<LPARAM>(&item));
500
501 if (result)
502 {
503 ILFree(pidlPrevious);
504 }
505 }
506 else
507 {
508 oldIndex = SendMessage(m_hWnd, CBEM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&item));
509
510 if (oldIndex < 0)
511 DbgPrint("ERROR %d\n", GetLastError());
512 }
513
514 SendMessage(m_hWnd, CB_SETCURSEL, oldIndex, 0);
515
516 //fAddressEditBox->SetCurrentDir(index);
517
518 break;
519 }
520 return S_OK;
521 }
522
523 LRESULT CAddressBand::OnNotifyClick(WPARAM wParam, NMHDR *notifyHeader, BOOL &bHandled)
524 {
525 if (notifyHeader->hwndFrom == fGoButton)
526 {
527 fAddressEditBox->ParseNow(0);
528 fAddressEditBox->Execute(0);
529 }
530 return 0;
531 }
532
533 LRESULT CAddressBand::OnTipText(UINT idControl, NMHDR *notifyHeader, BOOL &bHandled)
534 {
535 if (notifyHeader->hwndFrom == fGoButton)
536 {
537 // TODO
538 // Go to "destination path"
539 }
540 return 0;
541 }
542
543 LRESULT CAddressBand::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
544 {
545 POINT pt;
546 POINT ptOrig;
547 HWND parentWindow;
548 LRESULT result;
549
550 if (fGoButtonShown == false)
551 {
552 bHandled = FALSE;
553 return 0;
554 }
555 pt.x = 0;
556 pt.y = 0;
557 parentWindow = GetParent();
558 ::MapWindowPoints(m_hWnd, parentWindow, &pt, 1);
559 OffsetWindowOrgEx(reinterpret_cast<HDC>(wParam), pt.x, pt.y, &ptOrig);
560 result = SendMessage(parentWindow, WM_ERASEBKGND, wParam, 0);
561 SetWindowOrgEx(reinterpret_cast<HDC>(wParam), ptOrig.x, ptOrig.y, NULL);
562 if (result == 0)
563 {
564 bHandled = FALSE;
565 return 0;
566 }
567 return result;
568 }
569
570 LRESULT CAddressBand::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
571 {
572 RECT goButtonBounds;
573 RECT buttonBounds;
574 long buttonWidth;
575 long buttonHeight;
576 RECT comboBoxBounds;
577 long newHeight;
578 long newWidth;
579
580 if (fGoButtonShown == false)
581 {
582 bHandled = FALSE;
583 return 0;
584 }
585
586 newHeight = HIWORD(lParam);
587 newWidth = LOWORD(lParam);
588
589 SendMessage(fGoButton, TB_GETITEMRECT, 0, reinterpret_cast<LPARAM>(&buttonBounds));
590 buttonWidth = buttonBounds.right - buttonBounds.left;
591 buttonHeight = buttonBounds.bottom - buttonBounds.top;
592
593 DefWindowProc(WM_SIZE, wParam, MAKELONG(newWidth - buttonWidth - 2, newHeight));
594 ::GetWindowRect(fComboBox, &comboBoxBounds);
595 ::SetWindowPos(fGoButton, NULL, newWidth - buttonWidth, (comboBoxBounds.bottom - comboBoxBounds.top - buttonHeight) / 2,
596 buttonWidth, buttonHeight, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
597
598 goButtonBounds.left = newWidth - buttonWidth;
599 goButtonBounds.top = 0;
600 goButtonBounds.right = newWidth - buttonWidth;
601 goButtonBounds.bottom = newHeight;
602 InvalidateRect(&goButtonBounds, TRUE);
603
604 SendMessage(fComboBox, CB_SETDROPPEDWIDTH, 200, 0);
605 return 0;
606 }
607
608 LRESULT CAddressBand::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
609 {
610 RECT goButtonBounds;
611 RECT buttonBounds;
612 long buttonWidth;
613 long buttonHeight;
614 RECT comboBoxBounds;
615 WINDOWPOS positionInfoCopy;
616 long newHeight;
617 long newWidth;
618
619 if (!fGoButtonShown)
620 {
621 bHandled = FALSE;
622 return 0;
623 }
624
625 positionInfoCopy = *reinterpret_cast<WINDOWPOS *>(lParam);
626 newHeight = positionInfoCopy.cy;
627 newWidth = positionInfoCopy.cx;
628 SendMessage(fGoButton, TB_GETITEMRECT, 0, reinterpret_cast<LPARAM>(&buttonBounds));
629
630 buttonWidth = buttonBounds.right - buttonBounds.left;
631 buttonHeight = buttonBounds.bottom - buttonBounds.top;
632 positionInfoCopy.cx = newWidth - 2 - buttonWidth;
633 DefWindowProc(WM_WINDOWPOSCHANGING, wParam, reinterpret_cast<LPARAM>(&positionInfoCopy));
634 ::GetWindowRect(fComboBox, &comboBoxBounds);
635 ::SetWindowPos(fGoButton, NULL, newWidth - buttonWidth, (comboBoxBounds.bottom - comboBoxBounds.top - buttonHeight) / 2,
636 buttonWidth, buttonHeight, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
637
638 goButtonBounds.left = newWidth - buttonWidth;
639 goButtonBounds.top = 0;
640 goButtonBounds.right = newWidth - buttonWidth;
641 goButtonBounds.bottom = newHeight;
642 InvalidateRect(&goButtonBounds, TRUE);
643
644 SendMessage(fComboBox, CB_SETDROPPEDWIDTH, 200, 0);
645 return 0;
646 }
647
648 HRESULT CreateAddressBand(REFIID riid, void **ppv)
649 {
650 CComObject<CAddressBand> *theMenuBar;
651 HRESULT hResult;
652
653 if (ppv == NULL)
654 return E_POINTER;
655 *ppv = NULL;
656 ATLTRY (theMenuBar = new CComObject<CAddressBand>);
657 if (theMenuBar == NULL)
658 return E_OUTOFMEMORY;
659 hResult = theMenuBar->QueryInterface(riid, reinterpret_cast<void **>(ppv));
660 if (FAILED(hResult))
661 {
662 delete theMenuBar;
663 return hResult;
664 }
665 return S_OK;
666 }