home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 14.6 KB | 497 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: MoviePar.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Lonnie Millett
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef _MOVIEPAR_
- #include "MoviePar.h"
- #endif
-
- #ifndef _MOVIEFRA_
- #include "MovieFra.h"
- #endif
-
- #ifndef _MOVIEFAC_
- #include "MovieFac.h"
- #endif
-
- #ifndef _MOVIESEL_
- #include "MovieSel.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWMEMMGR_H
- #include <FWMemMgr.h>
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _STORAGEU_
- #include <StorageU.h>
- #endif
-
- #ifndef _FRAME_
- #include <Frame.h>
- #endif
-
- #ifndef _FACET_
- #include <Facet.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _XMPSESSM_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _TRANSLAT_
- #include <Translat.h>
- #endif
-
- #ifndef _ARBITRAT_
- #include <Arbitrat.h>
- #endif
-
- #ifndef _DISPTCH_
- #include <Disptch.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _WINSTAT_
- #include <WinStat.h>
- #endif
-
- #ifndef _STDTYPES_
- #include <StdTypes.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _CMDDEFS_
- #include <CmdDefs.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__GESTALTEQU__)
- #include <GestaltEqu.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
- #include <Errors.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- #pragma segment MoviePart
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const short kChooseMovieItemID = 1;
- const short kStartMovieItemID = 3;
- const short kStopMovieItemID = 4;
- const short kSetMovieLoopingItemID = 6;
-
- const short kDefaultMoviePicture = 2128;
-
- const short kMovieIdleFreq = 1;
-
- // Property for annotating our external movie information
- const XMPPropertyName kPropQTMovieLooping = "Apple:OpenDoc:Quality:kQTMovieLooping";
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::CMoviePart
- //----------------------------------------------------------------------------------------
- CMoviePart::CMoviePart()
- {
- fQuickTimeInstalled = FALSE;
- fMovieHandle = NULL;
- fLooping = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::~CMoviePart
- //----------------------------------------------------------------------------------------
- CMoviePart::~CMoviePart()
- {
- if (fMovieHandle)
- {
- FW_CMemoryManager::FreeSystemHandle(fMovieHandle);
- fMovieHandle = NULL;
- }
-
- if (fQuickTimeInstalled)
- ExitMovies();
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::Release
- //----------------------------------------------------------------------------------------
- void CMoviePart::Release()
- {
- FW_CPart::Release();
-
- if (this->GetRefCount() == 1)
- {
- this->GetSession()->GetDispatcher()->UnregisterIdle(this, NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::Initialize
- //----------------------------------------------------------------------------------------
- void CMoviePart::Initialize()
- {
- FW_CPart::Initialize();
-
- short error;
- long result;
-
- XMPSession* session = this->GetSession();
-
- error = Gestalt(gestaltQuickTime, &result);
- fQuickTimeInstalled = (error == noErr);
-
- if (fQuickTimeInstalled)
- THROW_IF_ERROR(EnterMovies());
- else
- THROW_IF_ERROR(envNotPresent, "MoviePart:Init:Quicktime not available");
-
- FW_CAcquireASLMResourceAccess aq;
-
- XMPMenuBar *menuBar = this->GetMenuBar();
- menuBar->AddMenuLast(kMovieMenu, GetMenu(kMovieMenu), this);
-
- menuBar->RegisterCommand(cChooseMovie, kMovieMenu, kChooseMovieItemID);
- menuBar->RegisterCommand(cStartMovie, kMovieMenu, kStartMovieItemID);
- menuBar->RegisterCommand(cStopMovie, kMovieMenu, kStopMovieItemID);
- menuBar->RegisterCommand(cSetMovieLooping, kMovieMenu, kSetMovieLoopingItemID);
-
- this->GetSession()->GetDispatcher()->RegisterIdle(this, NULL, kMovieIdleFreq);
-
- FW_PlatformPict picture = ::GetPicture(kDefaultMoviePicture);
- ::DetachResource((Handle)picture);
- FW_CPictShape pictShape(picture);
- fDefaultPicture = pictShape;
- }
-
- //------------------------------------------------------------------------------
- // CMoviePart::InternalizeContent
- //------------------------------------------------------------------------------
- void CMoviePart::InternalizeContent(XMPStorageUnit* storageUnit)
- {
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
-
- unsigned long movieSize = storageUnit->GetSize();
- if (movieSize)
- {
- FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(movieSize);
- THROW_IF_NULL(movieHandle);
-
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- storageUnit->GetValue(movieSize, (XMPValue)*movieHandle);
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
- this->SetMovieHandle(movieHandle);
-
- storageUnit->Focus(kContentAnnotationProp, kXMPPosUndefined, kContentAnnotationValue, (XMPValueIndex)0, kXMPPosFirstSib);
- storageUnit->GetValue(sizeof(FW_Boolean), (XMPValue)&fLooping);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::ExternalizeContent
- //----------------------------------------------------------------------------------------
- void CMoviePart::ExternalizeContent(XMPStorageUnit* storageUnit)
- {
- CMovieFacet* facet = (CMovieFacet*)this->GetActiveFacet();
- if (facet != NULL && facet->GetMovie())
- {
- FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(0);
- THROW_IF_NULL(movieHandle);
- THROW_IF_ERROR(::PutMovieIntoHandle(facet->GetMovie(), movieHandle));
-
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, this->GetContentPropertyValueType(), 0, kXMPPosUndefined);
- storageUnit->DeleteValue(storageUnit->GetSize());
- storageUnit->SetValue(FW_CMemoryManager::GetSystemHandleSize(movieHandle), (XMPValue)*movieHandle);
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
-
- storageUnit->Focus(kContentAnnotationProp, kXMPPosUndefined, kContentAnnotationValue, (XMPValueIndex)0, kXMPPosFirstSib);
- storageUnit->SetValue(sizeof(FW_Boolean), (XMPValue)&fLooping);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::AddProperties
- //----------------------------------------------------------------------------------------
- void CMoviePart::AddProperties(XMPStorageUnit* storageUnit)
- {
- storageUnit->AddProperty(kContentAnnotationProp)->AddValue(kContentAnnotationValue);
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetContentPropertyValueType
- //----------------------------------------------------------------------------------------
- XMPValueType CMoviePart::GetContentPropertyValueType() const
- {
- // Our content type is the standard type for movies
- return kSampleMovieKind;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::SetMovieHandle
- //----------------------------------------------------------------------------------------
- void CMoviePart::SetMovieHandle(FW_PlatformHandle movieHandle)
- {
- if (fMovieHandle)
- FW_CMemoryManager::FreeSystemHandle(fMovieHandle);
-
- fMovieHandle = movieHandle;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::SetMovieLooping
- //----------------------------------------------------------------------------------------
- void CMoviePart::SetMovieLooping(FW_Boolean loop)
- {
- fLooping = loop;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetNewMovieFromMovieHandle
- //----------------------------------------------------------------------------------------
- Movie CMoviePart::GetNewMovieFromMovieHandle()
- {
- Movie newMovie;
- FW_Boolean dataRefChanged;
-
- THROW_IF_ERROR(::NewMovieFromHandle(&newMovie, fMovieHandle, newMovieActive, &dataRefChanged));
-
- return newMovie;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::NewFrame
- //----------------------------------------------------------------------------------------
- FW_CFrame* CMoviePart::NewFrame(XMPFrame* xmpFrame, XMPTypeToken presentation)
- {
- FW_UNUSED(presentation);
-
- CMovieFrame *frame = new CMovieFrame();
- frame->InitMovieFrame(xmpFrame, this);
- return frame;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::NewSelection
- //----------------------------------------------------------------------------------------
- FW_CSelection* CMoviePart::NewSelection()
- {
- CMovieSelection* movieSelection = new CMovieSelection;
- movieSelection->InitMovieSelection(this);
- return movieSelection;
- }
-
- //------------------------------------------------------------------------------
- // CMoviePart::DoMenuEvent
- //------------------------------------------------------------------------------
-
- FW_Boolean CMoviePart::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
- {
- FW_UNUSED(menuBar);
- FW_Boolean menuHandled = FALSE;
-
- switch (commandID)
- {
- case cChooseMovie:
- {
- AliasHandle movieAlias = this->GetMovieFileFromUser();
- if (movieAlias)
- {
- FW_CPartFrameIterator iter(this, this->GetDefaultPresentation());
- CMovieFrame* frame;
- while (!iter.IsDone())
- {
- frame = (CMovieFrame*)iter.CurrentItem();
- Movie newMovie = this->GetMovieFromAlias(movieAlias);
- frame->SetNewMovie(newMovie);
- iter.Next();
- }
- FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle)movieAlias);
- }
- }
- menuHandled = TRUE;
- break;
-
- case cSetMovieLooping:
- this->ToggleLooping();
- menuHandled = TRUE;
- break;
-
- default:
- menuHandled = FW_CPart::DoMenuEvent(menuBar, commandID);
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
- void CMoviePart::DoAdjustMenus(XMPMenuBar* menuBar)
- {
- FW_CPart::DoAdjustMenus(menuBar);
-
- if (HasPropertyOnClipboard(kXMPPropContents, this->GetContentPropertyValueType()))
- menuBar->EnableCommand(kXMPCommandPaste, TRUE);
-
- if (((CMovieFacet*)this->GetActiveFacet())->GetMovie())
- {
- XMPTranslation *translate = GetSession()->GetTranslation();
- XMPType PICTType = translate->GetISOTypeFromPlatformType('PICT', kXMPPlatformDataType);
- XMPType TEXTType = translate->GetISOTypeFromPlatformType('TEXT', kXMPPlatformDataType);
- XMPType sndType = translate->GetISOTypeFromPlatformType('snd ', kXMPPlatformDataType);
-
- if (HasPropertyOnClipboard(kXMPPropContents, PICTType) ||
- HasPropertyOnClipboard(kXMPPropContents, TEXTType) ||
- HasPropertyOnClipboard(kXMPPropContents, sndType))
- menuBar->EnableCommand(kXMPCommandPaste, TRUE);
- menuBar->EnableCommand(cSetMovieLooping, TRUE);
- menuBar->EnableCommand(kXMPCommandSelectAll, TRUE);
- }
- else
- {
- menuBar->EnableCommand(kXMPCommandPaste, FALSE);
- menuBar->EnableCommand(kXMPCommandSelectAll, FALSE);
- menuBar->EnableCommand(cSetMovieLooping, FALSE);
- }
-
- menuBar->EnableCommand(cChooseMovie, TRUE);
- menuBar->CheckCommand(cSetMovieLooping, fLooping);
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::DoIdle
- //----------------------------------------------------------------------------------------
- FW_Boolean CMoviePart::DoIdle()
- {
- // Update all the display frames of the same type
- FW_CPartFrameIterator iter(this, this->GetDefaultPresentation());
- while (!iter.IsDone())
- {
- ((CMovieFrame*)iter.CurrentItem())->UpdateMovie();
- iter.Next();
- }
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetMovieFromUser
- //----------------------------------------------------------------------------------------
- AliasHandle CMoviePart::GetMovieFileFromUser()
- {
- SFTypeList typeList;
- StandardFileReply reply;
- AliasHandle movieFileAlias = NULL;
-
- typeList[0] = MovieFileType;
-
- this->GetSession()->GetWindowState()->DeactivateFrontWindows();
- ::StandardGetFilePreview ((FileFilterProcPtr)NULL, 1, typeList, &reply);
- this->GetSession()->GetWindowState()->ActivateFrontWindows();
-
- if (reply.sfGood == true)
- THROW_IF_ERROR(::NewAlias(NULL, &reply.sfFile, &movieFileAlias));
- return movieFileAlias;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetMovieFromAlias
- //----------------------------------------------------------------------------------------
- Movie CMoviePart::GetMovieFromAlias(AliasHandle movieAlias)
- {
- Movie aMovie;
- short movieResFile;
- short movieResID;
- Str255 movieName;
- FW_Boolean wasChanged;
- FSSpec movieFile;
-
- aMovie = NULL;
- THROW_IF_ERROR(::ResolveAlias(NULL, movieAlias, &movieFile, &wasChanged));
- THROW_IF_ERROR(::OpenMovieFile(&movieFile, &movieResFile, fsRdPerm));
- movieResID = 0; // First movie found
- THROW_IF_ERROR(::NewMovieFromFile(&aMovie, movieResFile,
- &movieResID,
- movieName, newMovieActive,
- &wasChanged));
- THROW_IF_ERROR(::CloseMovieFile(movieResFile));
- return aMovie;
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::ToggleLooping
- //----------------------------------------------------------------------------------------
- void CMoviePart::ToggleLooping()
- {
- fLooping = !fLooping;
-
- FW_CPartFrameIterator iter(this, this->GetDefaultPresentation());
- while (!iter.IsDone())
- {
- ((CMovieFrame*)iter.CurrentItem())->ToggleLooping(fLooping);
- iter.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMoviePart::GetAnyExistingFacet
- //----------------------------------------------------------------------------------------
- FW_CFacet* CMoviePart::GetAnyExistingFacet()
- {
- FW_CFacet* facet = NULL;
- FW_CPartFrameIterator iter1(this, this->GetDefaultPresentation());
- while (!iter1.IsDone())
- {
- FW_CFrameFacetIterator iter2(iter1.CurrentItem());
- if (!iter2.IsDone())
- return iter2.CurrentItem();
- iter1.Next();
- }
- return facet;
- }
-