home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Movie / Sources / MovieSel.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  12.1 KB  |  389 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                MovieSel.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Lonnie Millett
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef MOVIESEL_H
  14. #include "MovieSel.h"
  15. #endif
  16.  
  17. #ifndef MOVIEPAR_H
  18. #include "MoviePar.h"
  19. #endif
  20.  
  21. #ifndef MOVIEFRA_H
  22. #include "MovieFra.h"
  23. #endif
  24.  
  25. #ifndef MOVIEFAC_H
  26. #include "MovieFac.h"
  27. #endif
  28.  
  29. // ----- Framework Includes -----
  30.  
  31. #ifndef FWMEMMGR_H
  32. #include <FWMemMgr.h>
  33. #endif
  34.  
  35. #ifndef FWPART_H
  36. #include "FWPart.h"
  37. #endif
  38.  
  39. // ----- OpenDoc Includes -----
  40.  
  41. #ifndef _SHAPE_
  42. #include <Shape.h>
  43. #endif
  44.  
  45. #ifndef _DRAGDROP_
  46. #include <DragDrop.h>
  47. #endif
  48.  
  49. #ifndef _XMPSESSM_
  50. #include <XMPSessM.h>
  51. #endif
  52.  
  53. #ifndef _STDPROPS_
  54. #include <StdProps.h>
  55. #endif
  56.  
  57. #ifndef _STDTYPES_
  58. #include <StdTypes.h>
  59. #endif
  60.  
  61. #ifndef _TRNSFORM_
  62. #include <Trnsform.h>
  63. #endif
  64.  
  65. #ifndef _STORAGEU_
  66. #include <StorageU.h>
  67. #endif
  68.  
  69. #ifndef _EXCEPT_
  70. #include <Except.h>
  71. #endif
  72.  
  73. #ifndef _TRANSLAT_
  74. #include <Translat.h>
  75. #endif
  76.  
  77. // ----- Macintosh Includes -----
  78.  
  79. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  80. #include <Drag.h>
  81. #endif
  82.  
  83. #if defined(FW_BUILD_MAC) && !defined(__MOVIES__)
  84. #include <Movies.h>
  85. #endif
  86.  
  87. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  88. #include <math routines.h>
  89. #endif
  90.  
  91. #pragma segment MoviePart
  92.  
  93. //==============================================================================
  94. //    •• class CMovieSelection
  95. //==============================================================================
  96.  
  97. //---------------------------------------------------------------------------------------
  98. //    • CMovieSelection::CMovieSelection
  99. //---------------------------------------------------------------------------------------
  100.  
  101. CMovieSelection::CMovieSelection()
  102. {
  103.     fMoviePart = NULL;
  104. }
  105.  
  106. //---------------------------------------------------------------------------------------
  107. //    • CMovieSelection::InitMovieSelection
  108. //---------------------------------------------------------------------------------------
  109.  
  110. void CMovieSelection::InitMovieSelection(CMoviePart* moviePart)
  111. {
  112.     InitSelection(moviePart, FALSE, FALSE);
  113.     
  114.     fMoviePart = moviePart;
  115. }
  116.  
  117. //---------------------------------------------------------------------------------------
  118. //    • CMovieSelection::~CMovieSelection
  119. //---------------------------------------------------------------------------------------
  120.  
  121. CMovieSelection::~CMovieSelection()
  122. {    
  123. }
  124.  
  125. //---------------------------------------------------------------------------------------
  126. //    • CMovieSelection::CloseSelection
  127. //---------------------------------------------------------------------------------------
  128.  
  129. void CMovieSelection::CloseSelection()
  130. {
  131.     FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  132.     while (!iter.IsDone())
  133.     {
  134.         ((CMovieFrame*)iter.CurrentItem())->CloseSelection();
  135.         iter.Next();
  136.     }
  137. }
  138.  
  139. //---------------------------------------------------------------------------------------
  140. //    • CMovieSelection::DoClear
  141. //---------------------------------------------------------------------------------------
  142.  
  143. FW_Boolean CMovieSelection::DoClear()
  144. {
  145.     TimeValue currentTime, duration;
  146.     ((CMovieFacet*)fMoviePart->GetActiveFacet())->GetCurrentSelection(¤tTime, &duration);
  147.     
  148.     FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  149.     while (!iter.IsDone())
  150.     {
  151.         ((CMovieFrame*)iter.CurrentItem())->ClearSelection(currentTime, duration);
  152.         iter.Next();
  153.     }
  154.     return FALSE;
  155. }
  156.  
  157. //---------------------------------------------------------------------------------------
  158. //    • CMovieSelection::SelectAll
  159. //---------------------------------------------------------------------------------------
  160.  
  161. void CMovieSelection::SelectAll()
  162. {
  163.     FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  164.     while (!iter.IsDone())
  165.     {
  166.         ((CMovieFrame*)iter.CurrentItem())->SelectAll();
  167.         iter.Next();
  168.     }
  169. }
  170.  
  171. //---------------------------------------------------------------------------------------
  172. //    • CMovieSelection::IsEmpty
  173. //---------------------------------------------------------------------------------------
  174.  
  175. FW_Boolean CMovieSelection::IsEmpty() const
  176. {
  177.     return ((CMovieFacet*)fMoviePart->GetActiveFacet())->IsEmpty();
  178. }
  179.  
  180. //---------------------------------------------------------------------------------------
  181. //    • CMovieSelection::ExternalizeSelection
  182. //---------------------------------------------------------------------------------------
  183.  
  184. void CMovieSelection::ExternalizeSelection(XMPStorageUnit* storageUnit, FW_CFrame* commandFrame, XMPCloneKind cloneKind)
  185. {
  186.     FW_UNUSED(commandFrame);
  187.     FW_UNUSED(cloneKind);
  188.     
  189.     CMovieFacet* movieFacet = (CMovieFacet*)fMoviePart->GetActiveFacet();
  190.     if (movieFacet)
  191.     {
  192.         XMPTranslation *translate = GetPart()->GetSession()->GetTranslation();
  193.         XMPType PICTType = translate->GetISOTypeFromPlatformType('PICT', kXMPPlatformDataType);
  194.         
  195.         // Our content type is the standard 'moov' type
  196.         storageUnit->AddProperty(kXMPPropContents)->AddValue(fMoviePart->GetContentPropertyValueType());
  197.         FW_PlatformHandle movieHandle = movieFacet->CopySelection();
  198.         FW_CMemoryManager::LockSystemHandle(movieHandle);
  199.         storageUnit->SetValue(FW_CMemoryManager::GetSystemHandleSize(movieHandle), (XMPValue)*movieHandle);
  200.         FW_CMemoryManager::UnlockSystemHandle(movieHandle);
  201.         FW_CMemoryManager::FreeSystemHandle(movieHandle);
  202.         
  203.         // Add a PICT standard type for parts that don't understand movies
  204.         storageUnit->AddProperty(kXMPPropContents)->AddValue(PICTType);
  205.         PicHandle pictHandle = ((CMovieFacet*)fMoviePart->GetActiveFacet())->GetMovieAsPict();
  206.         FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)pictHandle);
  207.         storageUnit->SetValue(FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)pictHandle), (XMPValue)*pictHandle);
  208.         FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)pictHandle);
  209.         ::KillPicture(pictHandle);
  210.     }
  211. }
  212.  
  213. //---------------------------------------------------------------------------------------
  214. //    • CMovieSelection::InternalizeSelection
  215. //---------------------------------------------------------------------------------------
  216.  
  217. FW_Boolean CMovieSelection::InternalizeSelection(XMPStorageUnit* storageUnit, XMPCloneKind cloneKind)
  218. {
  219.     FW_UNUSED(cloneKind);
  220.  
  221.     FW_Boolean internalized = FALSE;
  222.     FW_PlatformHandle movieHandle;
  223.     
  224.     XMPTranslation *translate = GetPart()->GetSession()->GetTranslation();
  225.     XMPType typeHFS = translate->GetISOTypeFromPlatformType('hfs ', kXMPPlatformDataType);
  226.     XMPType PICTType = translate->GetISOTypeFromPlatformType('PICT', kXMPPlatformDataType);
  227.     XMPType TEXTType = translate->GetISOTypeFromPlatformType('TEXT', kXMPPlatformDataType);
  228.     XMPType sndType = translate->GetISOTypeFromPlatformType('snd ', kXMPPlatformDataType);
  229.  
  230.     if (storageUnit->Exists(kXMPPropContents, fMoviePart->GetContentPropertyValueType(), 0))
  231.     {
  232.         storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, fMoviePart->GetContentPropertyValueType(), 0, kXMPPosUndefined);
  233.                        
  234.         unsigned long movieSize = storageUnit->GetSize();
  235.         movieHandle = FW_CMemoryManager::AllocateSystemHandle(movieSize);
  236.         THROW_IF_NULL(movieHandle);
  237.         
  238.         FW_CMemoryManager::LockSystemHandle(movieHandle);
  239.         storageUnit->GetValue(movieSize, (XMPValue)*movieHandle);
  240.         FW_CMemoryManager::UnlockSystemHandle(movieHandle);
  241.         
  242.         Movie newMovie;
  243.         FW_Boolean dataRefChanged;
  244.         THROW_IF_ERROR(::NewMovieFromHandle(&newMovie, movieHandle, newMovieActive, &dataRefChanged));
  245.  
  246.         CMovieFacet* movieFacet = (CMovieFacet*)fMoviePart->GetActiveFacet();
  247.         if (movieFacet->GetMovie())
  248.         {
  249.             TimeValue currentTime, duration;
  250.             movieFacet->GetCurrentSelection(¤tTime, &duration);
  251.             FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  252.             while (!iter.IsDone())
  253.             {
  254.                 ((CMovieFrame*)iter.CurrentItem())->PasteMovieToSelection(newMovie, currentTime, duration);
  255.                 iter.Next();
  256.             }
  257.             ::DisposeMovie(newMovie);
  258.         }
  259.         else
  260.         {
  261.             FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  262.             while (!iter.IsDone())
  263.             {
  264.                 ((CMovieFrame*)iter.CurrentItem())->SetNewMovie(newMovie);
  265.                 iter.Next();
  266.             }
  267.         }
  268.         
  269.         FW_CMemoryManager::FreeSystemHandle(movieHandle);
  270.             
  271.         internalized = TRUE;
  272.     }
  273.     else if (storageUnit->Exists(kXMPPropContents, typeHFS, 0))
  274.     {
  275.         storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, typeHFS, 0, kXMPPosUndefined);
  276.                        
  277.         Movie newMovie;
  278.         AliasHandle movieFileAlias = NULL;
  279.         
  280.         unsigned long fileSize = storageUnit->GetSize();
  281.         HFSFlavor* fileData = (HFSFlavor*)FW_CMemoryManager::AllocateBlock(fileSize);
  282.         storageUnit->GetValue(fileSize, (XMPValue)fileData);
  283.         
  284.         THROW_IF_ERROR(::NewAlias(NULL, (FSSpec*)&(fileData->fileSpec), &movieFileAlias));
  285.         newMovie = fMoviePart->GetMovieFromAlias(movieFileAlias);
  286.         
  287.         FW_CMemoryManager::FreeBlock(fileData);
  288.         FW_CMemoryManager::FreeSystemHandle((FW_PlatformHandle)movieFileAlias);
  289.         
  290.         CMovieFacet* movieFacet = (CMovieFacet*)fMoviePart->GetActiveFacet();
  291.         if (movieFacet->GetMovie())
  292.         {
  293.             TimeValue currentTime, duration;
  294.             movieFacet->GetCurrentSelection(¤tTime, &duration);
  295.             FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  296.             while (!iter.IsDone())
  297.             {
  298.                 ((CMovieFrame*)iter.CurrentItem())->PasteMovieToSelection(newMovie, currentTime, duration);
  299.                 iter.Next();
  300.             }
  301.             ::DisposeMovie(newMovie);
  302.         }
  303.         else
  304.         {
  305.             FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  306.             while (!iter.IsDone())
  307.             {
  308.                 ((CMovieFrame*)iter.CurrentItem())->SetNewMovie(newMovie);
  309.                 iter.Next();
  310.             }
  311.         }
  312.         
  313.         internalized = TRUE;
  314.     }
  315.     else if (storageUnit->Exists(kXMPPropContents, PICTType, 0))
  316.     {
  317.         storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, PICTType, (XMPValueIndex)0, kXMPPosUndefined);
  318.                        
  319.         unsigned long pictSize = storageUnit->GetSize();
  320.         PicHandle pictHandle = (PicHandle)FW_CMemoryManager::AllocateSystemHandle(pictSize);
  321.         THROW_IF_NULL(pictHandle);
  322.         
  323.         FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)pictHandle);
  324.         storageUnit->GetValue(pictSize, (XMPValue)*pictHandle);
  325.         FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)pictHandle);
  326.         
  327.         this->PasteOSTypeToMovies((FW_PlatformHandle)pictHandle, 'PICT');
  328.         
  329.         ::KillPicture(pictHandle);
  330.  
  331.         internalized = TRUE;
  332.     }
  333.     else if (storageUnit->Exists(kXMPPropContents, TEXTType, 0))
  334.     {
  335.         storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, TEXTType, (XMPValueIndex)0, kXMPPosUndefined);
  336.                        
  337.         unsigned long textSize = storageUnit->GetSize();
  338.         FW_PlatformHandle textHandle = FW_CMemoryManager::AllocateSystemHandle(textSize);
  339.         THROW_IF_NULL(textHandle);
  340.         
  341.         FW_CMemoryManager::LockSystemHandle(textHandle);
  342.         storageUnit->GetValue(textSize, (XMPValue)*textHandle);
  343.         FW_CMemoryManager::UnlockSystemHandle(textHandle);
  344.         
  345.         this->PasteOSTypeToMovies(textHandle, 'TEXT');
  346.         
  347.         FW_CMemoryManager::FreeSystemHandle(textHandle);
  348.  
  349.         internalized = TRUE;
  350.     }
  351.     else if (storageUnit->Exists(kXMPPropContents, sndType, 0))
  352.     {
  353.         storageUnit->Focus(kXMPPropContents, kXMPPosUndefined, sndType, (XMPValueIndex)0, kXMPPosUndefined);
  354.                        
  355.         unsigned long sndSize = storageUnit->GetSize();
  356.         FW_PlatformHandle sndHandle = FW_CMemoryManager::AllocateSystemHandle(sndSize);
  357.         THROW_IF_NULL(sndHandle);
  358.         
  359.         FW_CMemoryManager::LockSystemHandle(sndHandle);
  360.         storageUnit->GetValue(sndSize, (XMPValue)*sndHandle);
  361.         FW_CMemoryManager::UnlockSystemHandle(sndHandle);
  362.         
  363.         this->PasteOSTypeToMovies(sndHandle, 'snd ');
  364.         
  365.         FW_CMemoryManager::FreeSystemHandle(sndHandle);
  366.  
  367.         internalized = TRUE;
  368.     }
  369.         
  370.     return internalized;
  371. }
  372.  
  373. //---------------------------------------------------------------------------------------
  374. //    • CMovieSelection::PasteOSTypeToMovies
  375. //---------------------------------------------------------------------------------------
  376.  
  377. void CMovieSelection::PasteOSTypeToMovies(FW_PlatformHandle newHandle, OSType handleType)
  378. {
  379.     TimeValue currentTime, duration;
  380.     ((CMovieFacet*)fMoviePart->GetActiveFacet())->GetCurrentSelection(¤tTime, &duration);
  381.     
  382.     FW_CPartFrameIterator iter(fMoviePart, fMoviePart->GetDefaultPresentation());
  383.     while (!iter.IsDone())
  384.     {
  385.         ((CMovieFrame*)iter.CurrentItem())->PasteHandleToSelection(newHandle, handleType, currentTime, duration);
  386.         iter.Next();
  387.     }
  388. }
  389.