ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

addressband.cpp
Go to the documentation of this file.
00001 /*
00002  * ReactOS Explorer
00003  *
00004  * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022 Implements the navigation band of the cabinet window
00023 */
00024 #include "precomp.h"
00025 
00026 /*
00027 TODO:
00028 ****Add command handler for show/hide Go button to OnWinEvent
00029 ****Add tooltip notify handler
00030   **Properly implement GetBandInfo
00031   **Add support for showing/hiding Go button
00032   **Fix so Go button will be shown/hidden properly on load
00033   **Add correct text to Go button
00034   **Implement TranslateAcceleratorIO
00035     Implement Exec
00036     Implement QueryService
00037     Implement Load
00038     Implement Save
00039 */
00040 
00041 CAddressBand::CAddressBand()
00042 {
00043     fEditControl = NULL;
00044     fGoButton = NULL;
00045     fComboBox = NULL;
00046     fGoButtonShown = false;
00047 }
00048 
00049 CAddressBand::~CAddressBand()
00050 {
00051 }
00052 
00053 void CAddressBand::FocusChange(BOOL bFocus)
00054 {
00055 //  m_bFocus = bFocus;
00056 
00057     //Inform the input object site that the focus has changed.
00058     if (fSite)
00059     {
00060 #if 0
00061         fSite->OnFocusChangeIS((IDockingWindow *)this, bFocus);
00062 #endif
00063     }
00064 }
00065 
00066 HRESULT STDMETHODCALLTYPE CAddressBand::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi)
00067 {
00068     if (pdbi->dwMask & DBIM_MINSIZE)
00069     {
00070         pdbi->ptMinSize.x = 400;
00071         pdbi->ptMinSize.y = 22;
00072     }
00073     if (pdbi->dwMask & DBIM_MAXSIZE)
00074     {
00075         pdbi->ptMaxSize.x = 0;
00076         pdbi->ptMaxSize.y = 0;
00077     }
00078     if (pdbi->dwMask & DBIM_INTEGRAL)
00079     {
00080         pdbi->ptIntegral.x = 0;
00081         pdbi->ptIntegral.y = 0;
00082     }
00083     if (pdbi->dwMask & DBIM_ACTUAL)
00084     {
00085         pdbi->ptActual.x = 400;
00086         pdbi->ptActual.y = 22;
00087     }
00088     if (pdbi->dwMask & DBIM_TITLE)
00089         wcscpy(pdbi->wszTitle, L"Address");
00090     if (pdbi->dwMask & DBIM_MODEFLAGS)
00091         pdbi->dwModeFlags = DBIMF_UNDELETEABLE;
00092     if (pdbi->dwMask & DBIM_BKCOLOR)
00093         pdbi->crBkgnd = 0;
00094     return S_OK;
00095 }
00096 
00097 HRESULT STDMETHODCALLTYPE CAddressBand::SetSite(IUnknown *pUnkSite)
00098 {
00099     CComPtr<IShellService>                  shellService;
00100     CComPtr<IUnknown>                       offset34;
00101     HWND                                    parentWindow;
00102     IOleWindow                              *oleWindow;
00103     HWND                                    toolbar;
00104     static const TBBUTTON                   buttonInfo[] = { {0, 1, TBSTATE_ENABLED, 0} };
00105     HIMAGELIST                              normalImagelist;
00106     HIMAGELIST                              hotImageList;
00107     HINSTANCE                               shellInstance;
00108     HRESULT                                 hResult;
00109 
00110     fSite.Release();
00111     if (pUnkSite == NULL)
00112         return S_OK;
00113     hResult = pUnkSite->QueryInterface(IID_IDockingWindowSite, (void **)&fSite);
00114     if (FAILED(hResult))
00115         return hResult;
00116     parentWindow = NULL;
00117     hResult = pUnkSite->QueryInterface(IID_IOleWindow, (void **)&oleWindow);
00118     if (SUCCEEDED(hResult))
00119     {
00120         oleWindow->GetWindow(&parentWindow);
00121         oleWindow->Release();
00122     }
00123     if (!::IsWindow(parentWindow))
00124         return E_FAIL;
00125 
00126     toolbar = CreateWindowEx(WS_EX_TOOLWINDOW, WC_COMBOBOXEXW, NULL, WS_CHILD | WS_VISIBLE |
00127                     WS_CLIPCHILDREN | WS_TABSTOP | CCS_NODIVIDER | CCS_NOMOVEY,
00128                     0, 0, 500, 250, parentWindow, (HMENU)0xa205, _AtlBaseModule.GetModuleInstance(), 0);
00129     if (toolbar == NULL)
00130         return E_FAIL;
00131     SubclassWindow(toolbar);
00132     SendMessage(CBEM_SETEXTENDEDSTYLE, CBES_EX_CASESENSITIVE | CBES_EX_NOSIZELIMIT, CBES_EX_CASESENSITIVE | CBES_EX_NOSIZELIMIT);
00133     fEditControl = (HWND)SendMessage(CBEM_GETEDITCONTROL, 0, 0);
00134     fComboBox = (HWND)SendMessage(CBEM_GETCOMBOCONTROL, 0, 0);
00135 #if 1
00136     hResult = CoCreateInstance(CLSID_AddressEditBox, NULL, CLSCTX_INPROC_SERVER, IID_IAddressEditBox, (void **)&fAddressEditBox);
00137     if (FAILED(hResult))
00138         return hResult;
00139 #else
00140     // instantiate new version
00141 #endif
00142     hResult = fAddressEditBox->QueryInterface(IID_IShellService, (void **)&shellService);
00143     if (FAILED(hResult))
00144         return hResult;
00145     hResult = fAddressEditBox->Init(toolbar, fEditControl, 8, pUnkSite /*(IAddressBand *)this*/ );
00146     if (FAILED(hResult))
00147         return hResult;
00148     hResult = shellService->SetOwner(pUnkSite);
00149     if (FAILED(hResult))
00150         return hResult;
00151 
00152     // TODO: properly initialize this from registry
00153     fGoButtonShown = true;
00154 
00155     shellInstance = GetModuleHandle(_T("shell32.dll"));
00156     normalImagelist = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL), 20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
00157     hotImageList = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_HOT), 20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION);
00158 
00159     fGoButton = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAMEW, 0, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TBSTYLE_LIST |
00160                         TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE,
00161                         0, 0, 0, 0, m_hWnd, NULL, _AtlBaseModule.GetModuleInstance(), NULL);
00162     SendMessage(fGoButton, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
00163     SendMessage(fGoButton, TB_SETMAXTEXTROWS, 1, 0);
00164     SendMessage(fGoButton, TB_SETIMAGELIST, 0, (LPARAM)normalImagelist);
00165     SendMessage(fGoButton, TB_SETHOTIMAGELIST, 0, (LPARAM)hotImageList);
00166     SendMessage(fGoButton, TB_ADDSTRINGW, (WPARAM)_AtlBaseModule.GetResourceInstance(), IDS_GOBUTTONLABEL);
00167     SendMessage(fGoButton, TB_ADDBUTTONSW, 1, (LPARAM)&buttonInfo);
00168 
00169     return hResult;
00170 }
00171 
00172 HRESULT STDMETHODCALLTYPE CAddressBand::GetSite(REFIID riid, void **ppvSite)
00173 {
00174     if (fSite == NULL)
00175         return E_FAIL;
00176     return fSite->QueryInterface(riid, ppvSite);
00177 }
00178 
00179 HRESULT STDMETHODCALLTYPE CAddressBand::GetWindow(HWND *lphwnd)
00180 {
00181     if (lphwnd == NULL)
00182         return E_POINTER;
00183     *lphwnd = m_hWnd;
00184     return S_OK;
00185 }
00186 
00187 HRESULT STDMETHODCALLTYPE CAddressBand::ContextSensitiveHelp(BOOL fEnterMode)
00188 {
00189     return E_NOTIMPL;
00190 }
00191 
00192 HRESULT STDMETHODCALLTYPE CAddressBand::CloseDW(DWORD dwReserved)
00193 {
00194     ShowDW(FALSE);
00195 
00196     if (IsWindow())
00197         DestroyWindow();
00198 
00199     m_hWnd = NULL;
00200 
00201     return S_OK;
00202 }
00203 
00204 HRESULT STDMETHODCALLTYPE CAddressBand::ResizeBorderDW(const RECT *prcBorder, IUnknown *punkToolbarSite, BOOL fReserved)
00205 {
00206     return E_NOTIMPL;
00207 }
00208 
00209 HRESULT STDMETHODCALLTYPE CAddressBand::ShowDW(BOOL fShow)
00210 {
00211     if (m_hWnd)
00212     {
00213         if (fShow)
00214             ShowWindow(SW_SHOW);
00215         else
00216             ShowWindow(SW_HIDE);
00217     }
00218     return S_OK;
00219 }
00220 
00221 HRESULT STDMETHODCALLTYPE CAddressBand::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[  ], OLECMDTEXT *pCmdText)
00222 {
00223     CComPtr<IOleCommandTarget>              oleCommandTarget;
00224     HRESULT                                 hResult;
00225 
00226     hResult = fAddressEditBox->QueryInterface(IID_IOleCommandTarget, (void **)&oleCommandTarget);
00227     if (FAILED(hResult))
00228         return hResult;
00229     return oleCommandTarget->QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
00230 }
00231 
00232 HRESULT STDMETHODCALLTYPE CAddressBand::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
00233 {
00234     // incomplete
00235     return E_NOTIMPL;
00236 }
00237 
00238 HRESULT STDMETHODCALLTYPE CAddressBand::HasFocusIO()
00239 {
00240     if (GetFocus() == fEditControl || SendMessage(CB_GETDROPPEDSTATE, 0, 0))
00241         return S_OK;
00242     return S_FALSE;
00243 }
00244 
00245 HRESULT STDMETHODCALLTYPE CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg)
00246 {
00247     // incomplete
00248     return S_FALSE;
00249 }
00250 
00251 HRESULT STDMETHODCALLTYPE CAddressBand::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
00252 {
00253     CComPtr<IInputObjectSite>               inputObjectSite;
00254     HRESULT                                 hResult;
00255 
00256     if (fActivate)
00257     {
00258         hResult = fSite->QueryInterface(IID_IInputObjectSite, (void **)&inputObjectSite);
00259         if (FAILED(hResult))
00260             return hResult;
00261         hResult = inputObjectSite->OnFocusChangeIS((IDeskBand *)this, fActivate);
00262         SetFocus();
00263     }
00264     return S_OK;
00265 }
00266 
00267 HRESULT STDMETHODCALLTYPE CAddressBand::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
00268 {
00269     CComPtr<IWinEventHandler>               winEventHandler;
00270     HRESULT                                 hResult;
00271 
00272     switch (uMsg)
00273     {
00274         case WM_WININICHANGE:
00275             break;
00276         case WM_COMMAND:
00277             if (wParam == IDM_TOOLBARS_GOBUTTON)
00278             {
00279                 // toggle whether the Go button is displayed
00280                 // setting is Yes or No, stored in key "Software\Microsoft\Internet Explorer\Main" in value ShowGoButton
00281                 // broadcast change notification to all explorer windows
00282             }
00283             break;
00284     }
00285     hResult = fAddressEditBox->QueryInterface(IID_IWinEventHandler, (void **)&winEventHandler);
00286     if (FAILED(hResult))
00287         return hResult;
00288     return winEventHandler->OnWinEvent(hWnd, uMsg, wParam, lParam, theResult);
00289 }
00290 
00291 HRESULT STDMETHODCALLTYPE CAddressBand::IsWindowOwner(HWND hWnd)
00292 {
00293     CComPtr<IWinEventHandler>               winEventHandler;
00294     HRESULT                                 hResult;
00295 
00296     hResult = fAddressEditBox->QueryInterface(IID_IWinEventHandler, (void **)&winEventHandler);
00297     if (FAILED(hResult))
00298         return hResult;
00299     return winEventHandler->IsWindowOwner(hWnd);
00300 }
00301 
00302 HRESULT STDMETHODCALLTYPE CAddressBand::FileSysChange(long param8, long paramC)
00303 {
00304     CComPtr<IAddressBand>                   addressBand;
00305     HRESULT                                 hResult;
00306 
00307     hResult = fAddressEditBox->QueryInterface(IID_IAddressBand, (void **)&addressBand);
00308     if (FAILED(hResult))
00309         return hResult;
00310     return addressBand->FileSysChange(param8, paramC);
00311 }
00312 
00313 HRESULT STDMETHODCALLTYPE CAddressBand::Refresh(long param8)
00314 {
00315     CComPtr<IAddressBand>                   addressBand;
00316     HRESULT                                 hResult;
00317 
00318     hResult = fAddressEditBox->QueryInterface(IID_IAddressBand, (void **)&addressBand);
00319     if (FAILED(hResult))
00320         return hResult;
00321     return addressBand->Refresh(param8);
00322 }
00323 
00324 HRESULT STDMETHODCALLTYPE CAddressBand::QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
00325 {
00326     return E_NOTIMPL;
00327 }
00328 
00329 HRESULT STDMETHODCALLTYPE CAddressBand::OnFocusChangeIS(IUnknown *punkObj, BOOL fSetFocus)
00330 {
00331     return E_NOTIMPL;
00332 }
00333 
00334 HRESULT STDMETHODCALLTYPE CAddressBand::GetClassID(CLSID *pClassID)
00335 {
00336     if (pClassID == NULL)
00337         return E_POINTER;
00338     *pClassID = CLSID_SH_AddressBand;
00339     return S_OK;
00340 }
00341 
00342 HRESULT STDMETHODCALLTYPE CAddressBand::IsDirty()
00343 {
00344     return E_NOTIMPL;
00345 }
00346 
00347 HRESULT STDMETHODCALLTYPE CAddressBand::Load(IStream *pStm)
00348 {
00349     // incomplete
00350     return E_NOTIMPL;
00351 }
00352 
00353 HRESULT STDMETHODCALLTYPE CAddressBand::Save(IStream *pStm, BOOL fClearDirty)
00354 {
00355     // incomplete
00356     return E_NOTIMPL;
00357 }
00358 
00359 HRESULT STDMETHODCALLTYPE CAddressBand::GetSizeMax(ULARGE_INTEGER *pcbSize)
00360 {
00361     // incomplete
00362     return E_NOTIMPL;
00363 }
00364 
00365 LRESULT CAddressBand::OnNotifyClick(WPARAM wParam, NMHDR *notifyHeader, BOOL &bHandled)
00366 {
00367     if (notifyHeader->hwndFrom == fGoButton)
00368     {
00369         SendMessage(fEditControl, WM_KEYDOWN, 13, 0);
00370         SendMessage(fEditControl, WM_KEYUP, 13, 0);
00371     }
00372     return 0;
00373 }
00374 
00375 LRESULT CAddressBand::OnTipText(UINT idControl, NMHDR *notifyHeader, BOOL &bHandled)
00376 {
00377     if (notifyHeader->hwndFrom == fGoButton)
00378     {
00379         // TODO
00380         // Go to "destination path"
00381     }
00382     return 0;
00383 }
00384 
00385 LRESULT CAddressBand::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
00386 {
00387     POINT                                   pt;
00388     POINT                                   ptOrig;
00389     HWND                                    parentWindow;
00390     LRESULT                                 result;
00391 
00392     if (fGoButtonShown == false)
00393     {
00394         bHandled = FALSE;
00395         return 0;
00396     }
00397     pt.x = 0;
00398     pt.y = 0;
00399     parentWindow = GetParent();
00400     ::MapWindowPoints(m_hWnd, parentWindow, &pt, 1);
00401     OffsetWindowOrgEx((HDC)wParam, pt.x, pt.y, &ptOrig);
00402     result = SendMessage(parentWindow, WM_ERASEBKGND, wParam, 0);
00403     SetWindowOrgEx((HDC)wParam, ptOrig.x, ptOrig.y, NULL);
00404     if (result == 0)
00405     {
00406         bHandled = FALSE;
00407         return 0;
00408     }
00409     return result;
00410 }
00411 
00412 LRESULT CAddressBand::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
00413 {
00414     RECT                                    goButtonBounds;
00415     RECT                                    buttonBounds;
00416     long                                    buttonWidth;
00417     long                                    buttonHeight;
00418     RECT                                    comboBoxBounds;
00419     long                                    newHeight;
00420     long                                    newWidth;
00421 
00422     if (fGoButtonShown == false)
00423     {
00424         bHandled = FALSE;
00425         return 0;
00426     }
00427     newHeight = HIWORD(lParam);
00428     newWidth = LOWORD(lParam);
00429     SendMessage(fGoButton, TB_GETITEMRECT, 0, (LPARAM)&buttonBounds);
00430     buttonWidth = buttonBounds.right - buttonBounds.left;
00431     buttonHeight = buttonBounds.bottom - buttonBounds.top;
00432     DefWindowProc(WM_SIZE, wParam, MAKELONG(newWidth - buttonWidth - 2, newHeight));
00433     ::GetWindowRect(fComboBox, &comboBoxBounds);
00434     ::SetWindowPos(fGoButton, NULL, newWidth - buttonWidth, (comboBoxBounds.bottom - comboBoxBounds.top - buttonHeight) / 2,
00435                     buttonWidth, buttonHeight, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
00436     goButtonBounds.left = newWidth - buttonWidth;
00437     goButtonBounds.top = 0;
00438     goButtonBounds.right = newWidth - buttonWidth;
00439     goButtonBounds.bottom = newHeight;
00440     InvalidateRect(&goButtonBounds, TRUE);
00441     SendMessage(fComboBox, CB_SETDROPPEDWIDTH, 200, 0);
00442     return 0;
00443 }
00444 
00445 LRESULT CAddressBand::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
00446 {
00447     RECT                                    goButtonBounds;
00448     RECT                                    buttonBounds;
00449     long                                    buttonWidth;
00450     long                                    buttonHeight;
00451     RECT                                    comboBoxBounds;
00452     WINDOWPOS                               positionInfoCopy;
00453     long                                    newHeight;
00454     long                                    newWidth;
00455 
00456     if (fGoButtonShown == false)
00457     {
00458         bHandled = FALSE;
00459         return 0;
00460     }
00461     positionInfoCopy = *(WINDOWPOS *)lParam;
00462     newHeight = positionInfoCopy.cy;
00463     newWidth = positionInfoCopy.cx;
00464     SendMessage(fGoButton, TB_GETITEMRECT, 0, (LPARAM)&buttonBounds);
00465     buttonWidth = buttonBounds.right - buttonBounds.left;
00466     buttonHeight = buttonBounds.bottom - buttonBounds.top;
00467     positionInfoCopy.cx = newWidth - 2 - buttonWidth;
00468     DefWindowProc(WM_WINDOWPOSCHANGING, wParam, (LPARAM)&positionInfoCopy);
00469     ::GetWindowRect(fComboBox, &comboBoxBounds);
00470     ::SetWindowPos(fGoButton, NULL, newWidth - buttonWidth, (comboBoxBounds.bottom - comboBoxBounds.top - buttonHeight) / 2,
00471                     buttonWidth, buttonHeight, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
00472     goButtonBounds.left = newWidth - buttonWidth;
00473     goButtonBounds.top = 0;
00474     goButtonBounds.right = newWidth - buttonWidth;
00475     goButtonBounds.bottom = newHeight;
00476     InvalidateRect(&goButtonBounds, TRUE);
00477     SendMessage(fComboBox, CB_SETDROPPEDWIDTH, 200, 0);
00478     return 0;
00479 }
00480 
00481 HRESULT CreateAddressBand(REFIID riid, void **ppv)
00482 {
00483     CComObject<CAddressBand>                *theMenuBar;
00484     HRESULT                                 hResult;
00485 
00486     if (ppv == NULL)
00487         return E_POINTER;
00488     *ppv = NULL;
00489     ATLTRY (theMenuBar = new CComObject<CAddressBand>);
00490     if (theMenuBar == NULL)
00491         return E_OUTOFMEMORY;
00492     hResult = theMenuBar->QueryInterface (riid, (void **)ppv);
00493     if (FAILED (hResult))
00494     {
00495         delete theMenuBar;
00496         return hResult;
00497     }
00498     return S_OK;
00499 }

Generated on Sat May 26 2012 04:21:24 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.