home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-14 | 9.4 KB | 410 lines | [TEXT/????] |
- // =================================================================================
- //
- // CMovieControl.cpp ©1996 Microsoft Corporation All rights reserved.
- //
- // =================================================================================
-
- #include "ocheaders.h"
- #include "CMovieControl.h"
-
- const Int32 DefaultIdleTime = IdleAfterAllEvents;
- const Uint32 DefaultIdleRefCon = 1;
-
- OLECHAR g_szBSCBHolder[] = "_BSCB_Holder";
- OLECHAR g_szEnumFORMATETC[] = "_EnumFORMATETC_";
-
-
- #pragma mark === CBaseControl::Construction & Destruction ===
-
- //
- // CMovieControl::CMovieControl
- //
-
- CMovieControl::CMovieControl(void)
- {
- mMovie = NULL;
- mEnterMoviesCount = 0;
- mDrawnOnce = false;
- mMovieState = MovieLoading;
- mPosterPict = NULL;
- }
-
-
- //
- // CMovieControl::~CMovieControl
- //
-
- CMovieControl::~CMovieControl()
- {
- if (mUnkForRelease)
- mUnkForRelease->Release();
- mContainerSiteP->SetIdleTime(RemoveIdler, DefaultIdleRefCon);
- while (mEnterMoviesCount--)
- ::ExitMovies();
- }
-
-
- #pragma mark === CMovieControl::IUnknown ===
-
- //
- // CMovieControl::IUnknown::QueryInterface
- //
- // Returns a pointer to the specified interface on a component to which a
- // client currently holds an interface pointer.
- //
-
- STDMETHODIMP
- CMovieControl::QueryInterface(REFIID inRefID, void** outObj)
- {
- if ( inRefID == IID_IBindStatusCallback )
- return CBaseBindStatusCallback::QueryInterface(inRefID, outObj);
- else
- return CBaseControl::QueryInterface(inRefID, outObj);
- }
-
-
- #pragma mark === CMovieControl::IControl ===
-
- //
- // CMovieControl::IControl::Draw
- //
-
- STDMETHODIMP
- CMovieControl::Draw(DrawContext* inContext)
- {
- if (inContext->DrawAspect != DVASPECT_CONTENT)
- return DV_E_DVASPECT;
-
- ::FrameRect(&inContext->Location);
- if ( mMovie && ((mMovieState == MovieReady) ||
- ((inContext->ContextID != mActiveContext->GetContextID()) && (mMovieState == MoviePlaying)) ))
- DrawMovie(inContext->Port, &inContext->Location);
-
- mDrawnOnce = true; // Flag that we have been drawn at least once
-
- return S_OK;
- }
-
-
- //
- // CMovieControl::IControl::DoMouse
- //
-
- STDMETHODIMP
- CMovieControl::DoMouse(MouseEventType inMouseET, PlatformEvent* Event)
- {
- #pragma unused(Event)
-
- switch (inMouseET)
- {
- case MouseDown:
- // if the movie has been loaded, process the click
- if ( mMovieState == MovieReady )
- StartIdling();
- break;
- }
-
- return S_OK;
- }
-
-
-
- //
- // CMovieControl::IControl::DoIdle
- //
-
- STDMETHODIMP
- CMovieControl::DoIdle(Uint32 IdleRefCon)
- {
- DrawContext Context = {BeginPortType};
-
- #pragma unused(IdleRefCon)
-
- if (mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context) == S_OK)
- {
- switch ( mMovieState )
- {
- case MovieLoaded: // Movie is loaded, initialize the movie
- InitMovie(&mMovieSpec, &mMovieSize, &Context.Location);
-
- case MovieReady: // Movie is ready to play
- if ( mDrawnOnce ) // wait until we've been drawn at least once
- {
- ::SetMovieClipRgn (mMovie, Context.Port->clipRgn);
-
- // Go to beginning of movie and play it
- ::GoToBeginningOfMovie(mMovie);
- ::StartMovie(mMovie);
-
- mMovieState = MoviePlaying;
- }
- break;
-
- case MoviePlaying:
- // Give the movie time
- ::MoviesTask(mMovie, DoTheRightThing);
-
- // if we're at the end of the movie, unschedule ourselves
- if ( IsMovieDone(mMovie) )
- {
- mMovieState = MovieReady;
- DrawMovie(Context.Port, &Context.Location);
- StopIdling();
- }
-
- break;
-
- }
-
- mContainerSiteP->ReleaseContext(&Context);
- }
-
- return S_OK;
- }
-
-
-
- #pragma mark === CMovieControl::IPersistPropertyBag ===
-
- //
- // CMovieControl::IPersistPropertyBag::Load
- //
-
- STDMETHODIMP
- CMovieControl::Load(IPropertyBag* PropertyBag, IErrorLog* ErrorLog)
- {
- ErrorCode ErrCode = E_FAIL;
-
- LoadTextState(PropertyBag, ErrorLog);
-
- ErrCode = OpenStream(mContainerSiteP, (char*)mDataURL, TRUE);
- return ErrCode;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CPictControl::LoadTextState
- //=--------------------------------------------------------------------------=
- // load in our text state for this control.
- //
- // Parameters:
- // IPropertyBag * - [in] property bag to read from
- // IErrorLog * - [in] errorlog object to use with proeprty bag
- //
- // Output:
- // ErrorCode
- //
- STDMETHODIMP CMovieControl::LoadTextState(IPropertyBag *PropertyBag, IErrorLog *ErrorLog)
- {
- VARIANT v;
- Uint32 length;
-
- // VariantInit(&v);
-
- v.vt = VT_BSTR;
- v.bstrVal = NULL;
-
- // try to load in the property. if we can't get it, then leave
- // things at their default.
- //
- PropertyBag->Read("data", &v, ErrorLog);
- if (v.bstrVal)
- {
- length = *((Uint32*) v.bstrVal) ;
- strcpy((Char8*)mDataURL, v.bstrVal + sizeof(Uint32));
- CoTaskMemFree(v.bstrVal);
- // VariantInit(&v);
- }
-
- return S_OK;
- }
-
-
- #pragma mark === CMovieControl::IBindStatusCallback ===
-
- //
- // CMovieControl::OnDataAvailable
- //
-
- STDMETHODIMP
- CMovieControl::OnDataAvailable(Uint32 BSCF, Uint32 Size, FORMATETC* FormatEtc, STGMEDIUM* StgMedium)
- {
- OSErr Err = noErr;
-
- CBaseBindStatusCallback::OnDataAvailable(BSCF, Size, FormatEtc, StgMedium);
-
- if (StgMedium->tymed == TYMED_FILE)
- {
- Str255 FileName;
-
- FileName[0] = strlen(StgMedium->lpszFileName);
- strncpy((Char8*)&FileName[1], StgMedium->lpszFileName, FileName[0]);
- FSMakeFSSpec(0, 0, FileName, &mMovieSpec);
- mMovieState = MovieLoaded;
-
- CoTaskMemFree(StgMedium->lpszFileName);
- }
- else if (StgMedium->tymed == TYMED_FSP)
- {
- BlockMove(StgMedium->pFSSpec, &mMovieSpec, sizeof(FSSpec));
- CoTaskMemFree(StgMedium->pFSSpec);
- mMovieState = MovieLoaded;
- }
- #ifdef _DEBUG
- else if (StgMedium->tymed == TYMED_ISTREAM)
- {
- Debugger();
- }
- #endif
-
- mUnkForRelease = StgMedium->pUnkForRelease;
-
- // if we have what we think is a valid movie file then play it right away
- if (mMovieState == MovieLoaded)
- mContainerSiteP->SetIdleTime(DefaultIdleTime, DefaultIdleRefCon);
-
- return S_OK;
- }
-
-
- #pragma mark === CMovieControl::CBaseControl overrides ===
-
- //
- // CMovieControl::CBaseControl::StartIdling [virtual]
- //
-
- Boolean8
- CMovieControl::StartIdling(void)
- {
- Boolean8 Result = false;
-
- if (mMovieState == MovieReady)
- Result = mContainerSiteP->SetIdleTime(DefaultIdleTime, DefaultIdleRefCon) == S_OK;
-
- return Result;
- }
-
-
- //
- // CMovieControl::CBaseControl::StopIdling [virtual]
- //
-
- Boolean8
- CMovieControl::StopIdling(void)
- {
- Boolean8 Result = false;
-
- if (mMovieState == MoviePlaying)
- ::StopMovie(mMovie);
-
- return CBaseControl::StopIdling();
- }
-
-
- #pragma mark === CMovieControl ===
-
- //
- // CMovieControl::InitMovie
- //
-
- Boolean8 CMovieControl::InitMovie(FSSpec* MovieSpec, Point* outMovieSizeP, Rect* inLocationP)
- {
- Int16 movieResRefNum;
- Int16 actualResId;
- OSErr err = noErr;
- Rect theRect;
-
- if ((err = ::EnterMovies()) == noErr)
- {
- mEnterMoviesCount++;
- if ((err = ::OpenMovieFile(MovieSpec, &movieResRefNum, fsRdPerm)) == noErr && movieResRefNum != 0)
- {
- actualResId = DoTheRightThing;
- if ((err = ::NewMovieFromFile(&mMovie, movieResRefNum, &actualResId, NULL, newMovieActive, (Boolean *)0)) == noErr)
- {
- if ( (err = ::CloseMovieFile(movieResRefNum)) == noErr)
- {
- ::GetMovieBox(mMovie, &theRect);
- outMovieSizeP->h = theRect.right - theRect.left;
- outMovieSizeP->v = theRect.bottom - theRect.top;
-
- theRect.top = inLocationP->top;
- theRect.left = inLocationP->left;
- theRect.bottom = inLocationP->top + outMovieSizeP->v;
- theRect.right = inLocationP->left + outMovieSizeP->h;
- ::SetMovieGWorld(mMovie, nil, 0);
- ::SetMovieBox(mMovie, &theRect);
- if ((err = ::GetMoviesError()) == noErr)
- {
- mMovieState = MovieReady;
- mPosterPict = ::GetMoviePosterPict(mMovie);
- }
- }
- }
- }
- }
-
- return mMovie != NULL;
- }
-
-
- //
- // CMovieControl::DrawMovie
- //
-
- void CMovieControl::DrawMovie(GrafPtr DrawPort, Rect* inLocationP)
- {
- #pragma unused (DrawPort)
- if (mPosterPict)
- {
- Rect theRect;
-
- theRect.top = inLocationP->top;
- theRect.left = inLocationP->left;
- theRect.bottom = inLocationP->top + mMovieSize.v;
- theRect.right = inLocationP->left + mMovieSize.h;
-
- ::DrawPicture(mPosterPict, &theRect);
- }
- }
-
- //=--------------------------------------------------------------------------=
- // CMovieContextInfo::CMovieControl::NewContext
- //=--------------------------------------------------------------------------=
- CBaseContextInfo*
- CMovieControl::NewContext(Uint32 inContextID)
- {
- CMovieContextInfo* ContextInfo = new CMovieContextInfo(this, inContextID);
-
- return ContextInfo;
- }
-
- //=--------------------------------------------------------------------------=
- // CMovieContextInfo::CMovieContextInfo
- //=--------------------------------------------------------------------------=
- CMovieContextInfo::CMovieContextInfo(CMovieControl* inControlP, Uint32 inContextID) :
- CBaseContextInfo (inControlP, inContextID)
- {
- mMovieControl = inControlP;
- }
-
- //=--------------------------------------------------------------------------=
- // CMovieContextInfo::Update
- //=--------------------------------------------------------------------------=
- ErrorCode
- CMovieContextInfo::Update(Boolean8 Acquired)
- {
- #pragma unused (Acquired)
- if(mMovieControl->mMovieState == MoviePlaying && mContextID == mMovieControl->mActiveContext->GetContextID())
- {
- DrawContext Context = {BeginPortType};
-
- if (mMovieControl->mContainerSiteP->AcquireContext(mContextID, &Context) == S_OK)
- {
- ::SetMovieClipRgn (mMovieControl->mMovie, Context.Port->clipRgn);
- mMovieControl->mContainerSiteP->ReleaseContext(&Context);
- }
- }
- return S_OK;
- }
-