Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbasebar.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 This class knows how to contain base bar site in a cabinet window. 00023 */ 00024 #include "precomp.h" 00025 00026 /* 00027 Base bar that contains a vertical or horizontal explorer band. It also 00028 provides resizing abilities. 00029 */ 00030 /* 00031 TODO: 00032 **Make base bar support resizing 00033 Add context menu for base bar 00034 Fix base bar to correctly initialize fVertical field 00035 Fix base bar to correctly reposition its base bar site when resized 00036 00037 */ 00038 00039 class CBaseBar : 00040 public CWindowImpl<CBaseBar, CWindow, CControlWinTraits>, 00041 public CComObjectRootEx<CComMultiThreadModelNoCS>, 00042 public IInputObjectSite, 00043 public IOleCommandTarget, 00044 public IServiceProvider, 00045 public IInputObject, 00046 public IDeskBar, 00047 public IDockingWindow, 00048 public IPersistStream, 00049 public IPersistStreamInit, 00050 public IPersistPropertyBag, 00051 public IObjectWithSite 00052 { 00053 public: 00054 CComPtr<IUnknown> fSite; 00055 CComPtr<IUnknown> fClient; 00056 HWND fClientWindow; 00057 bool fVertical; 00058 bool fVisible; 00059 int fNeededSize; // width or height 00060 00061 // used by resize tracking loop 00062 bool fTracking; 00063 POINT fLastLocation; 00064 public: 00065 CBaseBar(); 00066 ~CBaseBar(); 00067 public: 00068 HRESULT ReserveBorderSpace(); 00069 00070 // *** IOleWindow methods *** 00071 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd); 00072 virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode); 00073 00074 // *** IInputObjectSite specific methods *** 00075 virtual HRESULT STDMETHODCALLTYPE OnFocusChangeIS (IUnknown *punkObj, BOOL fSetFocus); 00076 00077 // *** IOleCommandTarget specific methods *** 00078 virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText); 00079 virtual HRESULT STDMETHODCALLTYPE Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut); 00080 00081 // *** IServiceProvider methods *** 00082 virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject); 00083 00084 // *** IInputObject methods *** 00085 // forward the methods to the contained active bar 00086 virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg); 00087 virtual HRESULT STDMETHODCALLTYPE HasFocusIO(); 00088 virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg); 00089 00090 // *** IDeskBar methods *** 00091 virtual HRESULT STDMETHODCALLTYPE SetClient(IUnknown *punkClient); 00092 virtual HRESULT STDMETHODCALLTYPE GetClient(IUnknown **ppunkClient); 00093 virtual HRESULT STDMETHODCALLTYPE OnPosRectChangeDB(LPRECT prc); 00094 00095 // *** IDockingWindow methods *** 00096 virtual HRESULT STDMETHODCALLTYPE ShowDW(BOOL fShow); 00097 virtual HRESULT STDMETHODCALLTYPE CloseDW(DWORD dwReserved); 00098 virtual HRESULT STDMETHODCALLTYPE ResizeBorderDW(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved); 00099 00100 // *** IObjectWithSite methods *** 00101 virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite); 00102 virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, void **ppvSite); 00103 00104 // *** IPersist methods *** 00105 virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID); 00106 00107 // *** IPersistStream methods *** 00108 virtual HRESULT STDMETHODCALLTYPE IsDirty(); 00109 virtual HRESULT STDMETHODCALLTYPE Load(IStream *pStm); 00110 virtual HRESULT STDMETHODCALLTYPE Save(IStream *pStm, BOOL fClearDirty); 00111 virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize); 00112 00113 // *** IPersistStreamInit methods *** 00114 virtual HRESULT STDMETHODCALLTYPE InitNew(); 00115 00116 // *** IPersistPropertyBag methods *** 00117 virtual HRESULT STDMETHODCALLTYPE Load(IPropertyBag *pPropBag, IErrorLog *pErrorLog); 00118 virtual HRESULT STDMETHODCALLTYPE Save(IPropertyBag *pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties); 00119 00120 // message handlers 00121 LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00122 LRESULT OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00123 LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00124 LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00125 LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00126 LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00127 LRESULT OnCancelMode(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00128 LRESULT OnCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 00129 00130 DECLARE_WND_CLASS_EX(_T("BaseBar"), 0, COLOR_3DFACE) 00131 00132 BEGIN_MSG_MAP(CBaseBar) 00133 MESSAGE_HANDLER(WM_SIZE, OnSize) 00134 MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor) 00135 MESSAGE_HANDLER(WM_NOTIFY, OnNotify) 00136 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown) 00137 MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp) 00138 MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove) 00139 MESSAGE_HANDLER(WM_CANCELMODE, OnCancelMode) 00140 MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged) 00141 END_MSG_MAP() 00142 00143 BEGIN_COM_MAP(CBaseBar) 00144 COM_INTERFACE_ENTRY2_IID(IID_IOleWindow, IOleWindow, IDockingWindow) 00145 COM_INTERFACE_ENTRY_IID(IID_IInputObjectSite, IInputObjectSite) 00146 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget) 00147 COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider) 00148 COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject) 00149 COM_INTERFACE_ENTRY_IID(IID_IDeskBar, IDeskBar) 00150 COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow) 00151 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite) 00152 COM_INTERFACE_ENTRY2_IID(IID_IPersist, IPersist, IPersistStream) 00153 COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream) 00154 COM_INTERFACE_ENTRY_IID(IID_IPersistStreamInit, IPersistStreamInit) 00155 COM_INTERFACE_ENTRY_IID(IID_IPersistPropertyBag, IPersistPropertyBag) 00156 END_COM_MAP() 00157 }; 00158 00159 CBaseBar::CBaseBar() 00160 { 00161 fClientWindow = NULL; 00162 fVertical = true; 00163 fVisible = false; 00164 fNeededSize = 200; 00165 fTracking = false; 00166 } 00167 00168 CBaseBar::~CBaseBar() 00169 { 00170 } 00171 00172 HRESULT CBaseBar::ReserveBorderSpace() 00173 { 00174 CComPtr<IDockingWindowSite> dockingWindowSite; 00175 RECT availableBorderSpace; 00176 RECT neededBorderSpace; 00177 HRESULT hResult; 00178 00179 hResult = fSite->QueryInterface(IID_IDockingWindowSite, (void **)&dockingWindowSite); 00180 if (FAILED(hResult)) 00181 return hResult; 00182 hResult = dockingWindowSite->GetBorderDW((IDeskBar *)this, &availableBorderSpace); 00183 if (FAILED(hResult)) 00184 return hResult; 00185 memset(&neededBorderSpace, 0, sizeof(neededBorderSpace)); 00186 if (fVisible) 00187 { 00188 if (fVertical) 00189 neededBorderSpace.left = fNeededSize + GetSystemMetrics(SM_CXFRAME); 00190 else 00191 neededBorderSpace.bottom = fNeededSize + GetSystemMetrics(SM_CXFRAME); 00192 } 00193 hResult = dockingWindowSite->SetBorderSpaceDW((IDeskBar *)this, &neededBorderSpace); 00194 if (FAILED(hResult)) 00195 return hResult; 00196 return S_OK; 00197 } 00198 00199 // current bar size is stored in the registry under 00200 // key=HKCU\Software\Microsoft\Internet Explorer\Explorer Bars 00201 // value=current bar GUID 00202 // result is 8 bytes of binary data, 2 longs. First is the size, second is reserved and will always be 0 00203 /*HRESULT CBaseBar::StopCurrentBar() 00204 { 00205 CComPtr<IOleCommandTarget> commandTarget; 00206 HRESULT hResult; 00207 00208 if (fCurrentBar.p != NULL) 00209 { 00210 hResult = fCurrentBar->QueryInterface(IID_IOleCommandTarget, (void **)&commandTarget); 00211 hResult = commandTarget->Exec(NULL, 0x17, 0, NULL, NULL); 00212 } 00213 // hide the current bar 00214 memcpy(&fCurrentActiveClass, &GUID_NULL, sizeof(fCurrentActiveClass)); 00215 return S_OK; 00216 }*/ 00217 00218 HRESULT STDMETHODCALLTYPE CBaseBar::GetWindow(HWND *lphwnd) 00219 { 00220 if (lphwnd == NULL) 00221 return E_POINTER; 00222 *lphwnd = m_hWnd; 00223 return S_OK; 00224 } 00225 00226 HRESULT STDMETHODCALLTYPE CBaseBar::ContextSensitiveHelp(BOOL fEnterMode) 00227 { 00228 return E_NOTIMPL; 00229 } 00230 00231 HRESULT STDMETHODCALLTYPE CBaseBar::OnFocusChangeIS (IUnknown *punkObj, BOOL fSetFocus) 00232 { 00233 // forward to owner 00234 return E_NOTIMPL; 00235 } 00236 00237 HRESULT STDMETHODCALLTYPE CBaseBar::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText) 00238 { 00239 return E_NOTIMPL; 00240 } 00241 00242 HRESULT STDMETHODCALLTYPE CBaseBar::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) 00243 { 00244 if (IsEqualIID(*pguidCmdGroup, CGID_Explorer)) 00245 { 00246 } 00247 else if (IsEqualIID(*pguidCmdGroup, IID_IDeskBarClient)) 00248 { 00249 switch (nCmdID) 00250 { 00251 case 0: 00252 // hide current band 00253 break; 00254 case 2: 00255 break; 00256 case 3: 00257 break; 00258 } 00259 } 00260 return E_NOTIMPL; 00261 } 00262 00263 HRESULT STDMETHODCALLTYPE CBaseBar::QueryService(REFGUID guidService, REFIID riid, void **ppvObject) 00264 { 00265 CComPtr<IServiceProvider> serviceProvider; 00266 HRESULT hResult; 00267 00268 if (fSite == NULL) 00269 return E_FAIL; 00270 hResult = fSite->QueryInterface(IID_IServiceProvider, (void **)&serviceProvider); 00271 if (FAILED(hResult)) 00272 return hResult; 00273 // called for SID_STopLevelBrowser, IID_IBrowserService to find top level browser 00274 // called for SID_IWebBrowserApp, IID_IConnectionPointContainer 00275 // connection point called for DIID_DWebBrowserEvents2 to establish connection 00276 return serviceProvider->QueryService(guidService, riid, ppvObject); 00277 } 00278 00279 HRESULT STDMETHODCALLTYPE CBaseBar::UIActivateIO(BOOL fActivate, LPMSG lpMsg) 00280 { 00281 // forward to contained bar 00282 return S_OK; 00283 } 00284 00285 HRESULT STDMETHODCALLTYPE CBaseBar::HasFocusIO() 00286 { 00287 // forward to contained bar 00288 return S_OK; 00289 } 00290 00291 HRESULT STDMETHODCALLTYPE CBaseBar::TranslateAcceleratorIO(LPMSG lpMsg) 00292 { 00293 // forward to contained bar 00294 return S_OK; 00295 } 00296 00297 HRESULT STDMETHODCALLTYPE CBaseBar::SetClient(IUnknown *punkClient) 00298 { 00299 CComPtr<IOleWindow> oleWindow; 00300 HWND ownerWindow; 00301 HRESULT hResult; 00302 00303 if (punkClient == NULL) 00304 fClient.Release(); 00305 else 00306 { 00307 hResult = punkClient->QueryInterface(IID_IUnknown, (void **)&fClient); 00308 if (FAILED(hResult)) 00309 return hResult; 00310 hResult = fSite->QueryInterface(IID_IOleWindow, (void **)&oleWindow); 00311 if (FAILED(hResult)) 00312 return hResult; 00313 hResult = oleWindow->GetWindow(&ownerWindow); 00314 if (FAILED(hResult)) 00315 return hResult; 00316 Create(ownerWindow, 0, NULL, WS_VISIBLE | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_TOOLWINDOW); 00317 ReserveBorderSpace(); 00318 } 00319 return S_OK; 00320 } 00321 00322 HRESULT STDMETHODCALLTYPE CBaseBar::GetClient(IUnknown **ppunkClient) 00323 { 00324 if (ppunkClient == NULL) 00325 return E_POINTER; 00326 *ppunkClient = fClient; 00327 if (fClient.p != NULL) 00328 fClient.p->AddRef(); 00329 return S_OK; 00330 } 00331 00332 HRESULT STDMETHODCALLTYPE CBaseBar::OnPosRectChangeDB(LPRECT prc) 00333 { 00334 if (prc == NULL) 00335 return E_POINTER; 00336 if (fVertical) 00337 fNeededSize = prc->right - prc->left; 00338 else 00339 fNeededSize = prc->bottom - prc->top; 00340 ReserveBorderSpace(); 00341 return S_OK; 00342 } 00343 00344 HRESULT STDMETHODCALLTYPE CBaseBar::ShowDW(BOOL fShow) 00345 { 00346 fVisible = fShow ? true : false; 00347 ReserveBorderSpace(); 00348 return S_OK; 00349 } 00350 00351 HRESULT STDMETHODCALLTYPE CBaseBar::CloseDW(DWORD dwReserved) 00352 { 00353 fVisible = false; 00354 ReserveBorderSpace(); 00355 return S_OK; 00356 } 00357 00358 HRESULT STDMETHODCALLTYPE CBaseBar::ResizeBorderDW(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved) 00359 { 00360 ReserveBorderSpace(); 00361 return S_OK; 00362 } 00363 00364 HRESULT STDMETHODCALLTYPE CBaseBar::SetSite(IUnknown *pUnkSite) 00365 { 00366 fSite = pUnkSite; 00367 return S_OK; 00368 } 00369 00370 HRESULT STDMETHODCALLTYPE CBaseBar::GetSite(REFIID riid, void **ppvSite) 00371 { 00372 if (ppvSite == NULL) 00373 return E_POINTER; 00374 *ppvSite = fSite; 00375 if (fSite.p != NULL) 00376 fSite.p->AddRef(); 00377 return S_OK; 00378 } 00379 00380 HRESULT STDMETHODCALLTYPE CBaseBar::GetClassID(CLSID *pClassID) 00381 { 00382 if (pClassID == NULL) 00383 return E_POINTER; 00384 // TODO: what class to return here? 00385 return E_NOTIMPL; 00386 } 00387 00388 HRESULT STDMETHODCALLTYPE CBaseBar::IsDirty() 00389 { 00390 return E_NOTIMPL; 00391 } 00392 00393 HRESULT STDMETHODCALLTYPE CBaseBar::Load(IStream *pStm) 00394 { 00395 return E_NOTIMPL; 00396 } 00397 00398 HRESULT STDMETHODCALLTYPE CBaseBar::Save(IStream *pStm, BOOL fClearDirty) 00399 { 00400 return E_NOTIMPL; 00401 } 00402 00403 HRESULT STDMETHODCALLTYPE CBaseBar::GetSizeMax(ULARGE_INTEGER *pcbSize) 00404 { 00405 if (pcbSize == NULL) 00406 return E_POINTER; 00407 return E_NOTIMPL; 00408 } 00409 00410 HRESULT STDMETHODCALLTYPE CBaseBar::InitNew() 00411 { 00412 return E_NOTIMPL; 00413 } 00414 00415 HRESULT STDMETHODCALLTYPE CBaseBar::Load(IPropertyBag *pPropBag, IErrorLog *pErrorLog) 00416 { 00417 return E_NOTIMPL; 00418 } 00419 00420 HRESULT STDMETHODCALLTYPE CBaseBar::Save(IPropertyBag *pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties) 00421 { 00422 return E_NOTIMPL; 00423 } 00424 00425 LRESULT CBaseBar::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00426 { 00427 /* CComPtr<IOleWindow> oleWindow; 00428 RECT clientRect; 00429 HRESULT hResult; 00430 00431 if (fClientWindow == NULL && fClient.p != NULL) 00432 { 00433 hResult = fClient->QueryInterface(IID_IOleWindow, (void **)&oleWindow); 00434 hResult = oleWindow->GetWindow(&fClientWindow); 00435 } 00436 if (fClientWindow != NULL) 00437 { 00438 GetClientRect(&clientRect); 00439 ::SetWindowPos(fClientWindow, NULL, clientRect.left, clientRect.top, clientRect.right - clientRect.left - GetSystemMetrics(SM_CXFRAME), 00440 clientRect.bottom - clientRect.top, SWP_NOOWNERZORDER | SWP_NOZORDER); 00441 }*/ 00442 return 0; 00443 } 00444 00445 LRESULT CBaseBar::OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00446 { 00447 if ((short)lParam != HTCLIENT || (HWND)wParam != m_hWnd) 00448 { 00449 bHandled = FALSE; 00450 return 0; 00451 } 00452 if (fVertical) 00453 SetCursor(LoadCursor(NULL, IDC_SIZEWE)); 00454 else 00455 SetCursor(LoadCursor(NULL, IDC_SIZENS)); 00456 return 1; 00457 } 00458 00459 LRESULT CBaseBar::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00460 { 00461 CComPtr<IWinEventHandler> winEventHandler; 00462 LRESULT result; 00463 HRESULT hResult; 00464 00465 result = 0; 00466 if (fClient.p != NULL) 00467 { 00468 hResult = fClient->QueryInterface(IID_IWinEventHandler, (void **)&winEventHandler); 00469 if (SUCCEEDED(hResult) && winEventHandler.p != NULL) 00470 hResult = winEventHandler->OnWinEvent(NULL, uMsg, wParam, lParam, &result); 00471 } 00472 return result; 00473 } 00474 00475 LRESULT CBaseBar::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00476 { 00477 SetCapture(); 00478 fTracking = true; 00479 fLastLocation.x = (short)LOWORD(lParam); 00480 fLastLocation.y = (short)HIWORD(lParam); 00481 return 0; 00482 } 00483 00484 LRESULT CBaseBar::OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00485 { 00486 ReleaseCapture(); 00487 fTracking = false; 00488 return 0; 00489 } 00490 00491 LRESULT CBaseBar::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00492 { 00493 POINT newLocation; 00494 //int delta; 00495 00496 if (fTracking) 00497 { 00498 newLocation.x = (short)LOWORD(lParam); 00499 newLocation.y = (short)HIWORD(lParam); 00500 #if 0 00501 if (fVertical) 00502 delta = newLocation.x - fLastLocation.x; 00503 else 00504 delta = newLocation.y - fLastLocation.y; 00505 00506 #endif 00507 fLastLocation = newLocation; 00508 } 00509 return 0; 00510 } 00511 00512 LRESULT CBaseBar::OnCancelMode(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00513 { 00514 fTracking = false; 00515 return 0; 00516 } 00517 00518 LRESULT CBaseBar::OnCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) 00519 { 00520 fTracking = false; 00521 return 0; 00522 } 00523 00524 HRESULT CreateBaseBar(REFIID riid, void **ppv) 00525 { 00526 CComObject<CBaseBar> *theBaseBar; 00527 HRESULT hResult; 00528 00529 if (ppv == NULL) 00530 return E_POINTER; 00531 *ppv = NULL; 00532 ATLTRY (theBaseBar = new CComObject<CBaseBar>); 00533 if (theBaseBar == NULL) 00534 return E_OUTOFMEMORY; 00535 hResult = theBaseBar->QueryInterface (riid, (void **)ppv); 00536 if (FAILED (hResult)) 00537 { 00538 delete theBaseBar; 00539 return hResult; 00540 } 00541 return S_OK; 00542 } Generated on Sun May 27 2012 04:22:53 for ReactOS by
1.7.6.1
|