home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / PictPlayer / CPictControlBSC.cpp < prev    next >
Encoding:
Text File  |  1996-12-31  |  3.1 KB  |  151 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //
  3. //    CPictControlBSC.cpp                ©1996 Microsoft Corporation All rights reserved.
  4. //
  5. // =================================================================================
  6.  
  7. #include "ocheaders.h"
  8. #include "CPictControl.h"
  9. #include "CPictControlBSC.h"
  10.  
  11. #pragma mark === CPictControlBSC::Construction & Destruction ===
  12.  
  13. //
  14. //    CPictControlBSC::CPictControlBSC
  15. //
  16. //    initialize our members
  17. //
  18.  
  19. CPictControlBSC::CPictControlBSC(CPictControl* OwningControl, Uint32 RefCon)
  20.     : CBaseBindStatusCallback()
  21. {
  22.     mOwningControl = OwningControl;
  23.     mOwningControlRefCon = RefCon;
  24.  
  25.     mData = NULL;
  26.  
  27.     mBindSiteP = NULL;
  28. }
  29.  
  30. //
  31. //    CPictControlBSC::~CPictControlBSC
  32. //
  33. //    release the control
  34. //
  35. CPictControlBSC::~CPictControlBSC()
  36. {
  37.     mOwningControl->Release();
  38. }
  39.  
  40. #pragma mark === CPictControlBSC::IBindStatusCallback ===
  41.  
  42. //
  43. //    CPictControlBSC::IBindStatusCallback::OnStopBinding
  44. //
  45. //    wrap up the stream
  46. //
  47.  
  48. STDMETHODIMP
  49. CPictControlBSC::OnStopBinding(ErrorCode Result, const Char8* Error)
  50. {
  51.     Int32        PictBytes;
  52.  
  53.     CBaseBindStatusCallback::OnStopBinding(Result, Error);
  54.     
  55.     if (mBindSiteP)
  56.     {
  57.         mBindSiteP->Release();
  58.         mBindSiteP = 0;
  59.     }
  60.  
  61.     if (mData)
  62.     {
  63.         //    stip off the first 512 bytes
  64.         //    do it this way so that the OnDataAvailable routine is general purpose
  65.         if ((PictBytes = ::GetHandleSize(mData) - 512) > 0)
  66.         {
  67.             ::HLock(mData);
  68.             ::BlockMove(*mData + 512, *mData, PictBytes);
  69.             ::HUnlock(mData);
  70.         }
  71.         else
  72.         {
  73.             ::DisposeHandle(mData);
  74.             mData = NULL;
  75.         }
  76.     }
  77.  
  78.     //    tell the owning control what data we accumulated
  79.     AddRef();
  80.     mOwningControl->SetData(mData, mOwningControlRefCon);
  81.     Release();
  82.  
  83.     return S_OK;
  84. }
  85.  
  86.  
  87. //
  88. //    CPictControlBSC::IBindStatusCallback::OnDataAvailable
  89. //
  90. //    data has become available - put it into our buffer
  91. //
  92.  
  93. STDMETHODIMP
  94. CPictControlBSC::OnDataAvailable(Uint32 BSCF, Uint32 Size, FORMATETC* FormatEtc, STGMEDIUM* StgMedium)
  95. {
  96.     OSErr Err = noErr;
  97.     
  98.     CBaseBindStatusCallback::OnDataAvailable(BSCF, Size, FormatEtc, StgMedium);
  99.     
  100.     if (StgMedium->tymed == TYMED_ISTREAM)
  101.     {
  102.         //    if the data handle hasn't been allocated and this is our first data make the handle
  103.         if (!mData && mTotalStreamLen == Size)
  104.             mData = ::NewHandle(0);
  105.  
  106.         if (mData)
  107.         {
  108.             //    grow the handle to accomodate more data
  109.             Uint32    InDataSize = ::GetHandleSize(mData);
  110.             ::SetHandleSize(mData, mTotalStreamLen);
  111.             if (::MemError() != noErr)
  112.             {
  113.                 //    if we can't grow the handle then release the memory
  114.                 ::DisposeHandle(mData);
  115.                 mData = NULL;
  116.             }
  117.             else
  118.             {
  119.                 //    get the data from the stream
  120.                 ::HLock(mData);
  121.                 StgMedium->pstm->Read(*mData + InDataSize, mDataSize, NULL);
  122.                 ::HUnlock(mData);
  123.             }
  124.         }
  125.     }
  126. #ifdef DEBUG
  127.     else
  128.         DebugStr("\pBad Storage Medium tymed");
  129. #endif
  130.  
  131.     if (StgMedium->pUnkForRelease != NULL)
  132.         StgMedium->pUnkForRelease->Release();
  133.  
  134.     return S_OK;
  135. }
  136.  
  137.  
  138. #pragma mark === CPictControlBSC::Public methods ===
  139.  
  140. //
  141. //    CPictControlBSC::OpenURL
  142. //
  143. //    open up a url stream
  144. //
  145.  
  146. ErrorCode
  147. CPictControlBSC::OpenURL(IContainerSite* inContainerSite, Char8* inURL, Boolean8 BindFile)
  148. {
  149.     return OpenStream(inContainerSite, inURL, BindFile);
  150. }
  151.