home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / BOCOLE.PAK / BOLECMAN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.1 KB  |  209 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents
  3. // Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   2.10  $
  6. //
  7. //  Declares an IBClassMgr "factory" which can create Bolero helper objects.
  8. //
  9. //    Since callers of BOleClassManager don't have the class
  10. //    definition, they can't call operator new to create a
  11. //    helper object.
  12. //
  13. //    BOleClassMgr has a pointer to the service, so you need a
  14. //    BOleClassMgr for every Bolero connection you maintain.
  15. //----------------------------------------------------------------------------
  16. #include "BOleCMan.h"
  17. #include "BOleSvc.h"
  18. #include "BOleDoc.h"
  19. #include "BOleIPS.h"
  20. #include "BOleSite.h"
  21. #include "BOleCtrl.h"
  22. #include "BOleFont.h"
  23. #include "BOlePict.h"
  24. #include "BOleCont.h"
  25. #include "BOleData.h"
  26. #include "BOleFact.h"
  27. #include "BOcxCtrl.h"
  28.  
  29. HRESULT _IFUNC BOleClassManager::QueryInterfaceMain(REFIID iid, LPVOID FAR *ppv)
  30. {
  31.     HRESULT hr = ResultFromScode(E_NOINTERFACE);
  32.     *ppv = NULL;
  33.     
  34.     // interfaces
  35.     SUCCEEDED(hr = IBClassMgr_QueryInterface(this, iid, ppv))
  36.  
  37.     // base classes    
  38.     || SUCCEEDED(hr = BOleComponent::QueryInterfaceMain(iid, ppv))
  39.  
  40.     // helpers
  41.     ;
  42.         
  43.     return hr;
  44. }
  45.  
  46.  
  47. BOleClassManager::BOleClassManager(IBUnknownMain *pObj) :
  48.     pSvc (NULLP), pFont (NULLP), BOleComponent(this, pObj)
  49. {
  50.     nServerCount = 0;
  51. }
  52.  
  53.  
  54. BOleClassManager::~BOleClassManager()
  55. {
  56.     if (pSvc != NULLP) {
  57.         pSvc->ReleaseMain();
  58.         pSvc = NULLP;
  59.     }
  60.  
  61.     if (pFont != NULLP) {
  62.         pFont->ReleaseMain();
  63.         pFont = NULLP;
  64.     }
  65.  
  66.     OLE::OleUninitialize (); // Req'd to free OLE2's clipboard window
  67. }
  68.  
  69. int _IFUNC BOleClassManager::ServerCount (int nDelta)
  70. {
  71.     nServerCount += nDelta;
  72.     if (nServerCount == 0) {
  73.         if (pSvc && (nDelta != 0))
  74.             // call ShutdownMaybe on TRANSITION to 0
  75.             (pSvc->GetApplication())->ShutdownMaybe();
  76.     }
  77.     return nServerCount;
  78. }
  79.  
  80. HRESULT _IFUNC BOleClassManager::ComponentCreate( PIUnknown FAR * ppObj, PIUnknown pO, BCID cid)
  81. {
  82.     *ppObj = NULL;
  83.     PIBUnknownMain pOuter = AsPIUnknownMain(pO);
  84.     
  85.     switch (cid) {
  86.         case cidBOleService:
  87.             {
  88.                 if (pSvc != NULLP)
  89.                     pSvc->ReleaseMain();    // ref count on helper (not aggregator)
  90.                 pSvc = new BOleService(this, pOuter);
  91.                 *ppObj = AsPIUnknown(pSvc);
  92.                 if (pSvc != NULLP)
  93.                     pSvc->AddRefMain();
  94.                 break;
  95.             }
  96.         case cidBOleDocument:
  97.             {
  98.                 if (pSvc != NULLP)
  99.                     *ppObj = AsPIUnknown(new BOleDocument(this, pOuter, pSvc));
  100.                 break;
  101.             }
  102.         case cidBOleContainer:
  103.             {
  104.                 *ppObj = AsPIUnknown(new BOleContainer(this, pOuter));
  105.                 break;
  106.             }
  107.         case cidBOlePart:
  108.             {
  109.                 if (pSvc != NULLP)
  110.                     *ppObj = AsPIUnknown(new BOlePart(this, pOuter, pSvc->pActiveDoc));
  111.                 break;
  112.             }
  113.         case cidBOleControl:
  114.             {
  115.                 if (pSvc != NULLP)
  116.                     *ppObj = AsPIUnknown(new BOleControl(this, pOuter, pSvc->pActiveDoc));
  117.                 break;
  118.             }
  119.         case cidBOleSite:
  120.             {
  121.                 *ppObj = AsPIUnknown(new BOleSite(this, pOuter, pSvc));
  122.                 break;
  123.             }
  124.         case cidBOleInProcSite:
  125.             {
  126.                 *ppObj = AsPIUnknown(new BOleInProcServer(this, pOuter, pSvc));
  127.                 break;
  128.             }
  129.         case cidBOleInProcHandler:
  130.             {
  131.                 *ppObj = AsPIUnknown(new BOleInProcHandler(this, pOuter, pSvc));
  132.                 break;
  133.             }
  134.  
  135.         case cidBOleControlSite:
  136.             {
  137.                 *ppObj = AsPIUnknown(new BOleControlSite(this, pOuter));
  138.                 break;
  139.             }
  140.         case cidBOleData:
  141.             *ppObj = AsPIUnknown (new BOleData(this, pOuter));
  142.             break;
  143.  
  144.         case cidBOleFactory:
  145.             // not aggregated directly by clients
  146.             // we create one on the clients behalf in IService::RegisterClass
  147.             // and release it in IService::UnregisterClass
  148.             {
  149.                 *ppObj = AsPIUnknown (new BOleFact(this, pOuter));
  150.                 break;
  151.             }
  152.         case cidBOleControlFactory:
  153.             // not aggregated directly by clients
  154.             // we create one on the clients behalf in IService::RegisterControlClass
  155.             // and release it in IService::UnregisterControlClass
  156.             {
  157.                 *ppObj = AsPIUnknown (new BOleControlFact(this, pOuter));
  158.                 break;
  159.             }
  160.         case cidBOleFont:
  161.             {
  162.                *ppObj = AsPIUnknown(new BOleFont (this, pOuter));
  163.                 break;
  164.             }
  165.         case cidBOlePicture:
  166.             {
  167.                *ppObj = AsPIUnknown(new BOlePicture (this, pOuter));
  168.                 break;
  169.             }
  170.     }
  171.     return (*ppObj) ? NOERROR : ResultFromScode (E_FAIL);
  172. }
  173.  
  174.  
  175. void BOleClassManager::SetFontCache(BOleFontObj *pFontObj)
  176. {
  177.   if (!pFontObj || (pFontObj == pFont)) {
  178.     if (pFont) {
  179.       pFont = pFont->GetNext ();
  180.       if (pFont)
  181.         pFont->SetPrev (NULL);
  182.     }
  183.   } else if (pFontObj) {
  184.     if (pFont) 
  185.       pFont->SetPrev (pFontObj);
  186.     pFontObj->SetNext (pFont);
  187.     pFontObj->SetPrev (NULL);
  188.     pFont = pFontObj;
  189.   }
  190. }
  191.  
  192.  
  193.  
  194. // CreateClassMgr -- This is the way to initiate a connection with Bolero.
  195. //                   To help us be version-resilient, it's the only exported
  196. //                   function which is visible to Bolero customers
  197. //
  198. extern "C"
  199.  
  200. HRESULT PASCAL FAR _export _loadds CreateClassMgr (
  201.     PIUnknown FAR *pCM,
  202.     PIUnknown pOuter,
  203.     IMalloc FAR *pMalloc)
  204. {
  205.     OLE::OleInitialize(pMalloc);
  206.     *pCM = new BOleClassManager (AsPIUnknownMain(pOuter));
  207.     return (*pCM) ?NOERROR:ResultFromScode(E_OUTOFMEMORY);
  208. }
  209.