home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / BOCOLE.PAK / BOLEIPS.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  20KB  |  779 lines

  1. //
  2. //**************************************************************************
  3. //
  4. // BOleIPS.cpp --    Implements the Bolero half of the OLE2 in-process
  5. //                server object.
  6. //
  7. //                BOleIps objects impersonate the client application
  8. //                from the point of view of the Bolero customer who's
  9. //                writing a server object (IPart)
  10. //
  11. // Copyright (c) 1993,94 by Borland International, Inc. All rights reserved
  12. //
  13. //**************************************************************************
  14.  
  15. #include "BOleIPS.h"
  16. #include "BOleCMan.h"
  17.  
  18.  
  19. //**************************************************************************
  20. //
  21. // BOleInProcHandler implementation
  22. //
  23. //**************************************************************************
  24.  
  25. BOleInProcHandler::BOleInProcHandler(BOleClassManager *pFact,
  26.     IBUnknownMain * pOuter, BOleService *pSvc ) : BOleComponent(pFact, pOuter)
  27. {
  28.     pService = pSvc;
  29.     pDefHandler = NULL;
  30.     pDefIPAO = NULL;
  31.     pDefSite = NULL;
  32.     pAdviseView = NULL;
  33.     dwAdviseFlags = 0L;
  34.     dwAdviseAspects = 0L;
  35. }
  36.  
  37. BOleInProcHandler::~BOleInProcHandler ()
  38. {
  39.     if (pDefHandler)
  40.         pDefHandler->Release();
  41. }
  42.  
  43. HRESULT _IFUNC BOleInProcHandler::QueryInterfaceMain(REFIID iid, LPVOID FAR *ppv)
  44. {
  45.     HRESULT hr = ResultFromScode(E_NOINTERFACE);
  46.     *ppv = NULL;
  47.  
  48.     // interfaces
  49.     if (SUCCEEDED(hr = IViewObject2_QueryInterface(this, iid, ppv))) {
  50.     }
  51.     else if (SUCCEEDED(hr = IOleInPlaceActiveObject_QueryInterface(this, iid, ppv))) {
  52.     }
  53.     else if (SUCCEEDED(hr = IBSite_QueryInterface(this, iid, ppv))) {
  54.     }
  55.     // base classes
  56.     else if (SUCCEEDED(hr = BOleComponent::QueryInterfaceMain(iid, ppv))) {
  57.     }
  58.     // helpers
  59.     else if (pDefHandler && SUCCEEDED(hr = pDefHandler->QueryInterface(iid, ppv))) {
  60.     }
  61.     return hr;
  62. }
  63.  
  64.  
  65. //**************************************************************************
  66. //
  67. //  IViewObject implementation
  68. //
  69. //**************************************************************************
  70.  
  71. HRESULT _IFUNC BOleInProcHandler::Draw (DWORD dwDrawAspect, LONG lindex,
  72.     void FAR* pvAspect, DVTARGETDEVICE FAR * ptd,
  73.     HDC hicTargetDev,
  74.     HDC hdcDraw,
  75.     LPCRECTL lprcBounds,
  76.     LPCRECTL lprcWBounds,
  77.     BOOL(CALLBACK * pfnContinue)(DWORD),
  78.     DWORD dwContinue)
  79. {
  80.     HRESULT hr = ResultFromScode(VIEW_E_DRAW);
  81.     // Let provider Draw
  82.     // unless its iconic which the handler does for us
  83.     //
  84.     if (dwDrawAspect != DVASPECT_ICON) {
  85.         if (SUCCEEDED(pProvider->Draw(hdcDraw, lprcBounds,
  86.             // lprcWBounds is NULL unless this is a metafile
  87.             //
  88.             lprcWBounds ? lprcWBounds : lprcBounds,
  89.             (BOleAspect) dwDrawAspect))) {
  90.             hr = NOERROR;
  91.         }
  92.     }
  93.     
  94.     // If this failed let the default handler render the Metafile
  95.     //
  96.     if (!SUCCEEDED(hr)) {
  97.         IViewObject *pVO;
  98.         if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject, &(LPVOID)pVO))) {
  99.             hr = pVO->Draw(dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue);
  100.             pVO->Release();
  101.         }
  102.     }
  103.     return hr;
  104. }
  105.  
  106. HRESULT _IFUNC BOleInProcHandler::GetColorSet (
  107.     DWORD dwDrawAspect,
  108.     LONG lindex,
  109.     void FAR* pvAspect,
  110.     DVTARGETDEVICE FAR * ptd,
  111.     HDC hicTargetDev,
  112.     LPLOGPALETTE FAR* ppColorSet)
  113. {
  114.     // what color pallete will the object use when rendering
  115.     return pPart->GetPalette (ppColorSet);
  116. }
  117.  
  118. HRESULT _IFUNC BOleInProcHandler::Freeze (
  119.     DWORD dwDrawAspect,
  120.     LONG lindex,
  121.     void FAR* pvAspect,
  122.     DWORD FAR* pdwFreeze)
  123. {
  124.     HRESULT hr;
  125.     IViewObject *pVO;
  126.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject, &(LPVOID)pVO))) {
  127.         hr = pVO->Freeze(dwDrawAspect, lindex, pvAspect, pdwFreeze);
  128.         pVO->Release();
  129.         return hr;
  130.     }
  131.     // the object shouldn't change the rendering
  132.     return ResultFromScode (E_FAIL);
  133. }
  134.  
  135. HRESULT _IFUNC BOleInProcHandler::Unfreeze (DWORD dwFreeze)
  136. {
  137.     HRESULT hr;
  138.     IViewObject *pVO;
  139.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject, &(LPVOID)pVO))) {
  140.         hr = pVO->Unfreeze(dwFreeze);
  141.         pVO->Release();
  142.         return hr;
  143.     }
  144.     // ok it can change again
  145.     return NOERROR;
  146. }
  147.  
  148. HRESULT _IFUNC BOleInProcHandler::SetAdvise (DWORD aspects, DWORD advf, LPADVISESINK pAdvSink)
  149. {
  150.     dwAdviseAspects = aspects;
  151.     dwAdviseFlags = advf;
  152.     if (pAdviseView)
  153.         pAdviseView->Release();
  154.     pAdviseView = pAdvSink;
  155.  
  156. //
  157. //
  158. //
  159. //
  160. //
  161. //
  162. //
  163.  
  164.     if (advf | ADVF_PRIMEFIRST)
  165.         // Cause advises now
  166.         //
  167.         Invalidate(BOLE_INVAL_DATA | BOLE_INVAL_VIEW);
  168.  
  169.     return NOERROR;
  170. }
  171.  
  172. HRESULT _IFUNC BOleInProcHandler::GetAdvise (DWORD FAR* pAspects,
  173.     DWORD FAR* pAdvf, LPADVISESINK FAR* ppAdvSink)
  174. {
  175.     pAdviseView->AddRef();
  176.     
  177.     *ppAdvSink = pAdviseView;
  178.     *pAspects = dwAdviseAspects;
  179.     *pAdvf = dwAdviseFlags;
  180.     return NOERROR;
  181. }
  182.     
  183. HRESULT _IFUNC BOleInProcHandler::GetExtent(DWORD dwDrawAspect,
  184.     LONG lindex, DVTARGETDEVICE FAR *ptd, LPSIZEL lpsizel)
  185. {
  186.     if (dwDrawAspect != DVASPECT_CONTENT)
  187.         return ResultFromScode (E_FAIL);
  188.  
  189.     if (!lpsizel)
  190.         return ResultFromScode (E_INVALIDARG);
  191.  
  192.     SIZE s;
  193.     HRESULT hr = pProvider->GetPartSize (&s);
  194.  
  195.     lpsizel->cx = MAP_PIX_TO_LOGHIM (s.cx, BOleService::pixPerIn.x);
  196.     lpsizel->cy = MAP_PIX_TO_LOGHIM (s.cy, BOleService::pixPerIn.y);
  197.  
  198.     return hr;
  199. }
  200.  
  201. //**************************************************************************
  202. //
  203. // IBSite methods (override this interface on aggregated BOleIPSServer
  204. // to implement Invalidate).
  205. //
  206. //**************************************************************************
  207.  
  208. HRESULT _IFUNC BOleInProcHandler::Init(PIBDataProvider pDP, 
  209.     PIBPart pP, LPCOLESTR szProgId, BOOL fHatchWnd)
  210. {
  211.     HRESULT hr;
  212.     // Initialize back pointers
  213.     //
  214.     pProvider = pDP;
  215.     pPart = pP;
  216.  
  217.     CLSID cid;
  218.     if (SUCCEEDED(hr = CLSIDFromProgID(szProgId, &cid))) {
  219.     
  220.         // create the default handler, which will launch the exe server
  221.         //
  222.         OleCreateEmbeddingHelper(cid, AsPIUnknown(pObjOuter),
  223.             EMBDHLP_INPROC_HANDLER | EMBDHLP_DELAYCREATE, NULL, IID_IUnknown,
  224.             &(LPVOID)pDefHandler);
  225.  
  226.         // initialize default IPS  
  227.         //
  228.         hr = pDefHandler->QueryInterface(IID_IBSite, &(LPVOID)pDefSite);
  229.         if (SUCCEEDED(hr)) {
  230.             pDefSite->Release();     // prevent aggregation deadlock
  231.             //
  232.             hr = pDefSite->Init(pDP, pP, szProgId, fHatchWnd);
  233.         }
  234.     }
  235.     return hr;
  236. }
  237.  
  238. HRESULT _IFUNC BOleInProcHandler::SiteShow(BOOL b)
  239. {
  240.     return pDefSite->SiteShow(b);
  241. }
  242.  
  243.  
  244.  
  245. HRESULT _IFUNC BOleInProcHandler::DiscardUndo()
  246. {
  247.     return pDefSite->DiscardUndo();
  248. }
  249.  
  250. HRESULT _IFUNC BOleInProcHandler::GetSiteRect(LPRECT r1, LPRECT r2)
  251. {
  252.     return pDefSite->GetSiteRect(r1,r2);
  253. }
  254.  
  255. HRESULT _IFUNC BOleInProcHandler::SetSiteRect(LPCRECT r)
  256. {
  257.     return pDefSite->SetSiteRect(r);
  258. }
  259.  
  260. HRESULT _IFUNC BOleInProcHandler::SetSiteExtent(LPCSIZE s)
  261. {
  262.     return pDefSite->SetSiteExtent(s);
  263. }
  264.  
  265. void _IFUNC BOleInProcHandler::OnSetFocus(BOOL b)
  266. {
  267.     pDefSite->OnSetFocus(b);
  268. }
  269.  
  270. void _IFUNC BOleInProcHandler::Disconnect ()
  271. {
  272.     pDefSite->Disconnect ();
  273. }
  274.  
  275. HRESULT _IFUNC BOleInProcHandler::GetZoom( BOleScaleFactor *pScale)
  276. {
  277.     return pDefSite->GetZoom(pScale);
  278. }
  279.  
  280. void _IFUNC BOleInProcHandler::Invalidate( BOleInvalidate b)
  281. {
  282.     if ((b & BOLE_INVAL_VIEW) && pAdviseView) {
  283.         pAdviseView->OnViewChange(dwAdviseAspects, -1);
  284.         if (dwAdviseFlags == ADVF_ONLYONCE) {
  285.             pAdviseView->Release();
  286.             pAdviseView = NULL;
  287.             dwAdviseAspects = 0L;
  288.             dwAdviseFlags = 0L;
  289. //
  290.         }
  291.     }
  292.     if (b)  // VIEW or DATA or PERSIST remains invalid
  293.         pDefSite->Invalidate(b);
  294. }
  295.  
  296. //**************************************************************************
  297. //
  298. // IOleInPlaceActiveObject
  299. //
  300. // This interface is overridden to pre-process translator and other messages
  301. // from the container's message loop.
  302. //
  303. //**************************************************************************
  304.  
  305. IOleInPlaceActiveObject * BOleInProcHandler::DefaultIPAO()
  306. {
  307.     if (!pDefIPAO) {
  308.         // Initialize pointer to default in place active object implementation
  309.         // 
  310.         if (SUCCEEDED(pDefHandler->QueryInterface(IID_IOleInPlaceActiveObject,
  311.             &(LPVOID) pDefIPAO))) {
  312.             pDefIPAO->Release();    // prevent aggregation deadlock
  313.         }
  314.     }
  315.     return pDefIPAO;
  316. }
  317.  
  318. HRESULT _IFUNC BOleInProcHandler::GetWindow(HWND FAR *phwnd)
  319. {
  320.     return DefaultIPAO()->GetWindow (phwnd);
  321. }
  322.  
  323. HRESULT _IFUNC BOleInProcHandler::ContextSensitiveHelp(BOOL fEnterMode)
  324. {
  325.     return DefaultIPAO()->ContextSensitiveHelp (fEnterMode);
  326. }
  327.  
  328. //    Allow DLL Server to translate accelerators
  329. //
  330. HRESULT _IFUNC BOleInProcHandler::TranslateAccelerator (LPMSG lpmsg)
  331. {
  332.     return pService->GetApplication()->Accelerator(lpmsg);
  333. //
  334. }
  335.  
  336. HRESULT _IFUNC BOleInProcHandler::OnFrameWindowActivate (BOOL fActivate)
  337. {
  338.     return DefaultIPAO()->OnFrameWindowActivate (fActivate);
  339. }
  340.  
  341. HRESULT _IFUNC BOleInProcHandler::OnDocWindowActivate (BOOL fActivate)
  342. {
  343.     return DefaultIPAO()->OnDocWindowActivate (fActivate);
  344. }
  345.  
  346. HRESULT _IFUNC BOleInProcHandler::ResizeBorder (LPCRECT lprectBorder,
  347.         LPOLEINPLACEUIWINDOW lpUIWindow, BOOL fFrameWindow)         
  348. {
  349.     return DefaultIPAO()->ResizeBorder (lprectBorder, lpUIWindow, fFrameWindow);
  350. }
  351.  
  352. HRESULT _IFUNC BOleInProcHandler::EnableModeless (BOOL fEnable)
  353. {
  354.     return DefaultIPAO()->EnableModeless (fEnable);
  355. }
  356.             
  357.         
  358.  
  359. //**************************************************************************
  360. //
  361. // BOleInProcServer implementation
  362. //
  363. //**************************************************************************
  364.  
  365. BOleInProcServer::BOleInProcServer(BOleClassManager *pFact,
  366.     IBUnknownMain * pOuter, BOleService *pSvc ) : BOleSite(pFact, pOuter, pSvc)
  367. {
  368.     pService = pSvc;
  369.     pDefHandler = NULL;
  370.     pAdviseView = NULL;
  371.     dwAdviseFlags = 0L;
  372.     dwAdviseAspects = 0L;
  373.     exCon = 0L;
  374.     fRunningMode = FALSE;
  375. }
  376.  
  377. BOleInProcServer::~BOleInProcServer ()
  378. {
  379.     if (pDefHandler)
  380.         pDefHandler->Release();
  381. }
  382.  
  383. HRESULT _IFUNC BOleInProcServer::QueryInterfaceMain(REFIID iid, LPVOID FAR *ppv)
  384. {
  385.     HRESULT hr = ResultFromScode(E_NOINTERFACE);
  386.     *ppv = NULL;
  387.  
  388.     // interfaces
  389.     if (SUCCEEDED(hr = IViewObject2_QueryInterface(this, iid, ppv))) {
  390.     }
  391.     else if (SUCCEEDED(hr = IRunnableObject_QueryInterface(this, iid, ppv))) {
  392.     }
  393.     else if (SUCCEEDED(hr = IExternalConnection_QueryInterface(this, iid, ppv))) {
  394.     }
  395.     // base classes
  396.     else if (SUCCEEDED(hr = BOleSite::QueryInterfaceMain(iid, ppv))) {
  397.     }
  398.     // helpers
  399.     else if (pDefHandler && SUCCEEDED(hr = pDefHandler->QueryInterface(iid, ppv))) {
  400.     }
  401.     return hr;
  402. }
  403.  
  404.  
  405. //**************************************************************************
  406. //
  407. //  IViewObject implementation
  408. //
  409. //**************************************************************************
  410.  
  411. HRESULT _IFUNC BOleInProcServer::Draw (DWORD dwDrawAspect, LONG lindex,
  412.     void FAR* pvAspect, DVTARGETDEVICE FAR * ptd,
  413.     HDC hicTargetDev,
  414.     HDC hdcDraw,
  415.     LPCRECTL lprcBounds,
  416.     LPCRECTL lprcWBounds,
  417.     BOOL(CALLBACK * pfnContinue)(DWORD),
  418.     DWORD dwContinue)
  419. {
  420.     HRESULT hr = ResultFromScode(VIEW_E_DRAW);
  421.     // Let provider Draw unless its iconic which the handler does for us
  422.     //
  423.     if (dwDrawAspect == DVASPECT_CONTENT) {
  424.         if (SUCCEEDED(pProvider->Draw(hdcDraw, lprcBounds,
  425.             // lprcWBounds is NULL unless this is a metafile
  426.             //
  427.             lprcWBounds ? lprcWBounds : lprcBounds,
  428.             (BOleAspect) dwDrawAspect))) {
  429.             hr = NOERROR;
  430.         }
  431.     }
  432.     
  433.     // If this failed let the default handler render the Metafile
  434.     //
  435.     if (!SUCCEEDED(hr)) {
  436.         IViewObject *pVO;
  437.         if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject, &(LPVOID)pVO))) {
  438.             hr = pVO->Draw(dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev,
  439.                            hdcDraw, lprcBounds, lprcWBounds, pfnContinue,
  440.                            dwContinue);
  441.             pVO->Release();
  442.         }
  443.     }
  444.     return hr;
  445. }
  446.  
  447. HRESULT _IFUNC BOleInProcServer::GetColorSet (
  448.     DWORD dwDrawAspect,
  449.     LONG lindex,
  450.     void FAR* pvAspect,
  451.     DVTARGETDEVICE FAR * ptd,
  452.     HDC hicTargetDev,
  453.     LPLOGPALETTE FAR* ppColorSet)
  454. {
  455.     // what color pallete will the object use when rendering
  456.     return pPart->GetPalette (ppColorSet);
  457. }
  458.  
  459. HRESULT _IFUNC BOleInProcServer::Freeze (
  460.     DWORD dwDrawAspect,
  461.     LONG lindex,
  462.     void FAR* pvAspect,
  463.     DWORD FAR* pdwFreeze)
  464. {
  465.     HRESULT hr;
  466.     IViewObject *pVO;
  467.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject, &(LPVOID)pVO))) {
  468.         hr = pVO->Freeze(dwDrawAspect, lindex, pvAspect, pdwFreeze);
  469.         pVO->Release();
  470.         return hr;
  471.     }
  472.     // the object shouldn't change the rendering
  473.     return ResultFromScode (E_FAIL);
  474. }
  475.  
  476. HRESULT _IFUNC BOleInProcServer::Unfreeze (DWORD dwFreeze)
  477. {
  478.     HRESULT hr;
  479.     IViewObject *pVO;
  480.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject, &(LPVOID)pVO))) {
  481.         hr = pVO->Unfreeze(dwFreeze);
  482.         pVO->Release();
  483.         return hr;
  484.     }
  485.     // ok it can change again
  486.     return NOERROR;
  487. }
  488.  
  489. HRESULT _IFUNC BOleInProcServer::SetAdvise (DWORD aspects, DWORD advf, LPADVISESINK pAdvSink)
  490. {
  491.     dwAdviseAspects = aspects;
  492.     dwAdviseFlags = advf;
  493.     if (pAdviseView)
  494.         pAdviseView->Release();
  495.     pAdviseView = pAdvSink;
  496.  
  497. //
  498. //
  499. //
  500. //
  501. //
  502. //
  503. //
  504.  
  505.     if (advf & ADVF_PRIMEFIRST)
  506.         // Cause advises now
  507.         //
  508.         Invalidate(BOLE_INVAL_DATA | BOLE_INVAL_VIEW);
  509.  
  510.     return NOERROR;
  511. }
  512.  
  513. HRESULT _IFUNC BOleInProcServer::GetAdvise (DWORD FAR* pAspects,
  514.     DWORD FAR* pAdvf, LPADVISESINK FAR* ppAdvSink)
  515. {
  516.     pAdviseView->AddRef();
  517.     
  518.     *ppAdvSink = pAdviseView;
  519.     *pAspects = dwAdviseAspects;
  520.     *pAdvf = dwAdviseFlags;
  521.     return NOERROR;
  522. }
  523.     
  524. HRESULT _IFUNC BOleInProcServer::GetExtent(DWORD dwDrawAspect,
  525.     LONG lindex, DVTARGETDEVICE FAR *ptd, LPSIZEL lpsizel)
  526. {
  527.     HRESULT hr;
  528.     if (dwDrawAspect != DVASPECT_CONTENT) {
  529.         // Get extent from the cache.
  530.         //
  531.         IViewObject2 *pVO;
  532.         if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject2, &(LPVOID)pVO))) {
  533.             hr = pVO->GetExtent(dwDrawAspect, lindex, ptd, lpsizel);
  534.             pVO->Release();
  535.         }
  536.     }
  537.     else {
  538.         hr = BOleSite::GetExtent(dwDrawAspect, lpsizel);
  539.     }
  540.     return hr;
  541. }
  542.  
  543. HRESULT _IFUNC BOleInProcServer::GetExtent(DWORD dwDrawAspect, LPSIZEL lpsizel)
  544. {
  545.     HRESULT hr;
  546.     if (dwDrawAspect != DVASPECT_CONTENT) {
  547.         // Get extent from the cache.
  548.         //
  549.         IViewObject2 *pVO;
  550.         if (SUCCEEDED(pDefHandler->QueryInterface(IID_IViewObject2, &(LPVOID)pVO))) {
  551.             hr = pVO->GetExtent(dwDrawAspect, -1, NULL, lpsizel);
  552.             pVO->Release();
  553.         }
  554.     }
  555.     else {
  556.         hr = BOleSite::GetExtent(dwDrawAspect, lpsizel);
  557.     }
  558.     return hr;
  559. }
  560.  
  561. //**************************************************************************
  562. //  Override IPersistStorage to allow OleCache to be persistent.
  563. //
  564.  
  565. HRESULT _IFUNC BOleInProcServer::InitNew(IStorage* pStg)
  566. {
  567.     LPPERSISTSTORAGE pPersistCache;
  568.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IPersistStorage, &(LPVOID) pPersistCache))) {
  569.         pPersistCache->InitNew(pStg);
  570.         pPersistCache->Release();
  571.     }
  572.     return BOleSite::InitNew(pStg);
  573. }
  574.  
  575. HRESULT _IFUNC BOleInProcServer::Load(IStorage* pStg)
  576. {
  577.     LPPERSISTSTORAGE pPersistCache;
  578.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IPersistStorage, &(LPVOID) pPersistCache))) {
  579.         pPersistCache->Load(pStg);
  580.         pPersistCache->Release();
  581.     }
  582.     return BOleSite::Load(pStg);
  583. }
  584.  
  585. HRESULT _IFUNC BOleInProcServer::Save(IStorage* pStgSave,BOOL fSameAsLoad)
  586. {
  587.     LPOLECACHE2 pCache;
  588.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IOleCache2, &(LPVOID)pCache))) {
  589.         pCache->UpdateCache(this, ADVFCACHE_ONSAVE, NULL);
  590.         pCache->Release();
  591.     }
  592.     LPPERSISTSTORAGE pPersistCache;
  593.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IPersistStorage, &(LPVOID)pPersistCache))) {
  594.         pPersistCache->Save(pStgSave, fSameAsLoad);
  595.         pPersistCache->Release();
  596.     }
  597.     return BOleSite::Save(pStgSave, fSameAsLoad);
  598. }
  599.  
  600. HRESULT _IFUNC BOleInProcServer::SaveCompleted(IStorage* pStgSaved)
  601. {
  602.     LPPERSISTSTORAGE pPersistCache;
  603.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IPersistStorage, &(LPVOID) pPersistCache))) {
  604.         pPersistCache->SaveCompleted(pStgSaved);
  605.         pPersistCache->Release();
  606.     }
  607.     return BOleSite::SaveCompleted(pStgSaved);
  608. }
  609.  
  610. HRESULT _IFUNC BOleInProcServer::HandsOffStorage()
  611. {
  612.     LPPERSISTSTORAGE pPersistCache;
  613.     if (SUCCEEDED(pDefHandler->QueryInterface(IID_IPersistStorage, &(LPVOID) pPersistCache))) {
  614.         pPersistCache->HandsOffStorage();
  615.         pPersistCache->Release();
  616.     }
  617.     return BOleSite::HandsOffStorage();
  618. }
  619.  
  620.  
  621. //**************************************************************************
  622. //
  623. // IBSite methods (override this interface on aggregated BOleIPSServer
  624. // to implement Invalidate).
  625. //
  626. //**************************************************************************
  627.  
  628. HRESULT _IFUNC BOleInProcServer::Init(PIBDataProvider pDP, 
  629.     PIBPart pP, LPCOLESTR szProgId, BOOL fHatchWnd)
  630. {
  631.     // Initialize back pointers
  632.     //
  633.     pProvider = pDP;
  634.     pPart = pP;
  635.  
  636.     CLSID cid = CLSID_NULL;
  637.     
  638.     if (SUCCEEDED(CLSIDFromProgID(szProgId, &cid))) {
  639.         // create the default handler
  640.         //
  641.         CreateDataCache(AsPIUnknown(pObjOuter),cid, IID_IUnknown,
  642.             &(LPVOID)pDefHandler);
  643. //
  644. //
  645. //
  646.     }
  647.  
  648.     // initialize default IPS
  649.     //
  650.     return BOleSite::Init(pDP, pP, szProgId, fHatchWnd);
  651. }
  652.  
  653. void _IFUNC BOleInProcServer::Invalidate( BOleInvalidate b)
  654. {
  655.     if ((b & BOLE_INVAL_VIEW) && pAdviseView) {
  656.         pAdviseView->OnViewChange(dwAdviseAspects, -1);
  657.         if (dwAdviseFlags == ADVF_ONLYONCE) {
  658.             pAdviseView->Release();
  659.             pAdviseView = NULL;
  660.             dwAdviseAspects = 0L;
  661.             dwAdviseFlags = 0L;
  662. //
  663.         }
  664.     }
  665.     if (b)  // VIEW or DATA or PERSIST remains invalid
  666.         BOleSite::Invalidate(b);
  667. }
  668.  
  669. //**************************************************************************
  670. //
  671. // IOleInPlaceActiveObject
  672. //
  673. // This interface is overridden to pre-process translator and other messages
  674. // from the container's message loop.
  675. //
  676. //**************************************************************************
  677.  
  678.  
  679. //    Allow DLL Server to translate accelerators
  680. //
  681. HRESULT _IFUNC BOleInProcServer::TranslateAccelerator (LPMSG lpmsg)
  682. {
  683.     return pService->GetApplication()->Accelerator(lpmsg);
  684. }
  685.  
  686. HRESULT _IFUNC BOleInProcServer::EnumVerbs(IEnumOLEVERB* FAR* ppenumOleVerb)
  687. {
  688.     return OleRegEnumVerbs(cid, ppenumOleVerb);
  689. }
  690.  
  691. HRESULT _IFUNC BOleInProcServer::GetUserType(DWORD dwFormOfType, LPOLESTR FAR* pszUserType)
  692. {
  693.     return OleRegGetUserType(cid, dwFormOfType, pszUserType);
  694. }
  695.  
  696. HRESULT _IFUNC BOleInProcServer::GetMiscStatus(DWORD dwAspect, DWORD FAR* pdwStatus)
  697. {
  698.     return OleRegGetMiscStatus(cid, dwAspect, pdwStatus);
  699. }    
  700.  
  701. HRESULT _IFUNC BOleInProcServer::SetExtent (DWORD dwDrawAspect, LPSIZEL lpsizel)
  702. {
  703.     HRESULT hr = BOleSite::SetExtent(dwDrawAspect, lpsizel);
  704.     return hr;
  705. }
  706.  
  707. // IRunnableObject methods
  708. //
  709. HRESULT _IFUNC BOleInProcServer::GetRunningClass(LPCLSID lpClassID)
  710. {
  711.     *lpClassID = cid;
  712.     return NOERROR;
  713. }
  714.  
  715. HRESULT _IFUNC BOleInProcServer::Run(LPBINDCTX pbc)
  716. {
  717.     // Enter running mode by setting a flag and locking the container
  718.     //
  719.     if (!fRunningMode) {
  720.         fRunningMode = TRUE;
  721. //
  722. //
  723. //
  724. //
  725. //
  726. //
  727. //
  728.         // Should register the moniker here.
  729.         // Don't register if this is a clone (pPart is NULL)
  730.         // otherwise we would link to what's on the clipboard...
  731.         //
  732.         if (pPart)
  733.             SetMoniker(OLEWHICHMK_OBJFULL, NULLP);        // register
  734.     }
  735.     
  736.     return NOERROR;
  737. }
  738.  
  739. BOOL _IFUNC BOleInProcServer::IsRunning()
  740. {
  741.     return fRunningMode;
  742. }
  743.  
  744. HRESULT _IFUNC BOleInProcServer::LockRunning(BOOL fLock, BOOL fLastCloses)
  745. {
  746.     return Lock(fLock, fLastCloses);
  747. }
  748.  
  749. HRESULT _IFUNC BOleInProcServer::SetContainedObject(BOOL fContained)
  750. {
  751.     return NOERROR;
  752. }
  753.  
  754. // IExternalConnection implementation
  755. //
  756. DWORD _IFUNC BOleInProcServer::AddConnection (DWORD flag, DWORD reserved)
  757. {
  758.      return (flag & EXTCONN_STRONG) ? ++exCon : 0;
  759. }
  760.  
  761. DWORD _IFUNC BOleInProcServer::ReleaseConnection (DWORD flag, DWORD reserved, BOOL fLastReleaseCloses)
  762. {
  763.      if (flag & EXTCONN_STRONG) {
  764.          --exCon;
  765.          if( exCon == 0 && fLastReleaseCloses){
  766.             Close(OLECLOSE_SAVEIFDIRTY);
  767.          }
  768.          return exCon;
  769.      }
  770.     return 0;
  771. }
  772.  
  773. HRESULT _IFUNC BOleInProcServer::Close (DWORD dwSaveOption)
  774. {
  775.     fRunningMode = FALSE;
  776.     return BOleSite::Close(dwSaveOption);
  777. }
  778.  
  779.