home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-31 | 3.1 KB | 151 lines | [TEXT/CWIE] |
- // =================================================================================
- //
- // CPictControlBSC.cpp ©1996 Microsoft Corporation All rights reserved.
- //
- // =================================================================================
-
- #include "ocheaders.h"
- #include "CPictControl.h"
- #include "CPictControlBSC.h"
-
- #pragma mark === CPictControlBSC::Construction & Destruction ===
-
- //
- // CPictControlBSC::CPictControlBSC
- //
- // initialize our members
- //
-
- CPictControlBSC::CPictControlBSC(CPictControl* OwningControl, Uint32 RefCon)
- : CBaseBindStatusCallback()
- {
- mOwningControl = OwningControl;
- mOwningControlRefCon = RefCon;
-
- mData = NULL;
-
- mBindSiteP = NULL;
- }
-
- //
- // CPictControlBSC::~CPictControlBSC
- //
- // release the control
- //
- CPictControlBSC::~CPictControlBSC()
- {
- mOwningControl->Release();
- }
-
- #pragma mark === CPictControlBSC::IBindStatusCallback ===
-
- //
- // CPictControlBSC::IBindStatusCallback::OnStopBinding
- //
- // wrap up the stream
- //
-
- STDMETHODIMP
- CPictControlBSC::OnStopBinding(ErrorCode Result, const Char8* Error)
- {
- Int32 PictBytes;
-
- CBaseBindStatusCallback::OnStopBinding(Result, Error);
-
- if (mBindSiteP)
- {
- mBindSiteP->Release();
- mBindSiteP = 0;
- }
-
- if (mData)
- {
- // stip off the first 512 bytes
- // do it this way so that the OnDataAvailable routine is general purpose
- if ((PictBytes = ::GetHandleSize(mData) - 512) > 0)
- {
- ::HLock(mData);
- ::BlockMove(*mData + 512, *mData, PictBytes);
- ::HUnlock(mData);
- }
- else
- {
- ::DisposeHandle(mData);
- mData = NULL;
- }
- }
-
- // tell the owning control what data we accumulated
- AddRef();
- mOwningControl->SetData(mData, mOwningControlRefCon);
- Release();
-
- return S_OK;
- }
-
-
- //
- // CPictControlBSC::IBindStatusCallback::OnDataAvailable
- //
- // data has become available - put it into our buffer
- //
-
- STDMETHODIMP
- CPictControlBSC::OnDataAvailable(Uint32 BSCF, Uint32 Size, FORMATETC* FormatEtc, STGMEDIUM* StgMedium)
- {
- OSErr Err = noErr;
-
- CBaseBindStatusCallback::OnDataAvailable(BSCF, Size, FormatEtc, StgMedium);
-
- if (StgMedium->tymed == TYMED_ISTREAM)
- {
- // if the data handle hasn't been allocated and this is our first data make the handle
- if (!mData && mTotalStreamLen == Size)
- mData = ::NewHandle(0);
-
- if (mData)
- {
- // grow the handle to accomodate more data
- Uint32 InDataSize = ::GetHandleSize(mData);
- ::SetHandleSize(mData, mTotalStreamLen);
- if (::MemError() != noErr)
- {
- // if we can't grow the handle then release the memory
- ::DisposeHandle(mData);
- mData = NULL;
- }
- else
- {
- // get the data from the stream
- ::HLock(mData);
- StgMedium->pstm->Read(*mData + InDataSize, mDataSize, NULL);
- ::HUnlock(mData);
- }
- }
- }
- #ifdef DEBUG
- else
- DebugStr("\pBad Storage Medium tymed");
- #endif
-
- if (StgMedium->pUnkForRelease != NULL)
- StgMedium->pUnkForRelease->Release();
-
- return S_OK;
- }
-
-
- #pragma mark === CPictControlBSC::Public methods ===
-
- //
- // CPictControlBSC::OpenURL
- //
- // open up a url stream
- //
-
- ErrorCode
- CPictControlBSC::OpenURL(IContainerSite* inContainerSite, Char8* inURL, Boolean8 BindFile)
- {
- return OpenStream(inContainerSite, inURL, BindFile);
- }
-