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 / MovieFra.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  13.5 KB  |  476 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                MovieFra.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 MOVIEFRA_H
  14. #include "MovieFra.h"
  15. #endif
  16.  
  17. #ifndef MOVIEFAC_H
  18. #include "MovieFac.h"
  19. #endif
  20.  
  21. #ifndef MOVIEPAR_H
  22. #include "MoviePar.h"
  23. #endif
  24.  
  25. // ----- Framework Includes -----
  26.  
  27. #ifndef FWMEMMGR_H
  28. #include <FWMemMgr.h>
  29. #endif
  30.  
  31. #ifndef FWUTIL_H
  32. #include "FWUtil.h"
  33. #endif
  34.  
  35. #ifndef FWRECT_H
  36. #include "FWRect.h"
  37. #endif
  38.  
  39. // ----- OpenDoc Includes -----
  40. #ifndef _FRAME_
  41. #include <Frame.h>
  42. #endif
  43.  
  44. #ifndef _SHAPE_
  45. #include <Shape.h>
  46. #endif
  47.  
  48. #ifndef _WINDOW_
  49. #include <Window.h>
  50. #endif
  51.  
  52. #ifndef _MENUBAR_
  53. #include <MenuBar.h>
  54. #endif
  55.  
  56. #ifndef _XMPSESSM_
  57. #include <XMPSessM.h>
  58. #endif
  59.  
  60. #ifndef _INFO_
  61. #include <Info.h>
  62. #endif
  63.  
  64. #ifndef _ARBITRAT_
  65. #include <Arbitrat.h>
  66. #endif
  67.  
  68. #ifndef _EXCEPT_
  69. #include <Except.h>
  70. #endif
  71.  
  72. #ifndef _STDTYPES_
  73. #include <StdTypes.h>
  74. #endif
  75.  
  76. #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
  77. #include <Quickdraw.h>
  78. #endif
  79.  
  80. #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
  81. #include <math routines.h>
  82. #endif
  83.  
  84. #pragma segment MoviePart
  85.  
  86. //==============================================================================
  87. // Constants
  88. //==============================================================================
  89.  
  90. const XMPID kCMovieFrameID = 'movi';
  91.  
  92. //----------------------------------------------------------------------------------------
  93. // CMovieFrame::CMovieFrame
  94. //----------------------------------------------------------------------------------------
  95. CMovieFrame::CMovieFrame()
  96.                       : FW_CFrame()
  97. {
  98.     fMoviePart = NULL;
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. // CMovieFrame::~CMovieFrame
  103. //----------------------------------------------------------------------------------------
  104. CMovieFrame::~CMovieFrame()
  105. {
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. // CMovieFrame::InitMovieFrame
  110. //----------------------------------------------------------------------------------------
  111. void CMovieFrame::InitMovieFrame(XMPFrame* xmpFrame, CMoviePart* moviePart)
  112. {
  113.     this->InitFrame(xmpFrame, moviePart);
  114.     
  115.     fMoviePart = moviePart;
  116.     
  117.     AddToFocusSet(fMoviePart->GetKeyFocusToken());
  118.     AddToFocusSet(fMoviePart->GetMenuFocusToken());
  119.     AddToFocusSet(fMoviePart->GetSelectionFocusToken());
  120.  
  121.     this->SetDroppable(TRUE);
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // CMovieFrame::NewFacet
  126. //----------------------------------------------------------------------------------------
  127. FW_CFacet* CMovieFrame::NewFacet(XMPFacet* xmpFacet)
  128. {
  129.     CMovieFacet* facet = new CMovieFacet;
  130.     facet->InitMovieFacet(xmpFacet, this);
  131.  
  132.     return facet;
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // CMovieFrame::FacetAdded
  137. //----------------------------------------------------------------------------------------
  138. void CMovieFrame::FacetAdded(FW_CFacet* facet)
  139. {
  140.     FW_CFrame::FacetAdded(facet);
  141.     
  142.     Movie newMovie;
  143.     
  144.     // Determine from where we should get our movie
  145.     
  146.     // Get any existing movie and use it since all movies are supposed to be in-synch
  147.     Movie currentMovie = ((CMovieFacet*)fMoviePart->GetAnyExistingFacet())->GetMovie();
  148.     if (currentMovie)
  149.     {
  150.         FW_Boolean dataRefChanged;
  151.         FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(0);
  152.         THROW_IF_NULL(movieHandle);
  153.         
  154.         THROW_IF_ERROR(::PutMovieIntoHandle(currentMovie, movieHandle));
  155.         THROW_IF_ERROR(::NewMovieFromHandle(&newMovie, movieHandle, newMovieActive, &dataRefChanged));
  156.         
  157.         FW_CMemoryManager::FreeSystemHandle(movieHandle);
  158.     }
  159.     // Otherwise look at the part to see if we have internalized a movie from storage
  160.     else if (fMoviePart->GetMovieHandle())
  161.     {
  162.         newMovie = fMoviePart->GetNewMovieFromMovieHandle();
  163.     }
  164.     // Looks like we're just starting out
  165.     else
  166.         newMovie = NULL;
  167.     
  168.     ((CMovieFacet*)facet)->SetMovie(newMovie);
  169.     ((CMovieFacet*)facet)->SetMovieLooping(fMoviePart->GetMovieLooping());
  170.     
  171.     FW_CRect movieBox;
  172.     
  173.     if (this->IsRoot())
  174.         this->GetFrameShapeBounds(&movieBox);
  175.     else
  176.         ((CMovieFacet*)facet)->GetMovieBoundingBox(&movieBox);
  177.         
  178.     this->AdjustFrameSize(movieBox);
  179.     
  180.     if (this->IsRoot())
  181.     {
  182.         ((CMovieFacet*)facet)->AdjustMovieBox();
  183.         ((CMovieFacet*)facet)->DoMovieSetVisible(TRUE);
  184.     }
  185.     
  186.     this->UpdateUsedAndActiveShapes();
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // CMovieFrame::CreateChildWindow
  191. //----------------------------------------------------------------------------------------
  192. XMPWindow* CMovieFrame::CreateChildWindow(XMPISOStr windowTitle)
  193. {
  194.     FW_CRect windRect;
  195.     CMovieFacet* movieFacet = (CMovieFacet*)this->GetActiveFacet();
  196.     movieFacet->GetMovieBoundingBox(&windRect);
  197.     windRect.Offset(ff(100), ff(100));
  198.  
  199.     return GetPart()->CreateXMPWindow(this,
  200.                                      GetPart()->GetSession()->Tokenize(kXMPViewAsFrame),
  201.                                      GetPresentation(),
  202.                                      windowTitle,
  203.                                      windRect,
  204.                                      TRUE,        // close box
  205.                                      FALSE,        // resizable
  206.                                      FALSE,        // floating
  207.                                      TRUE,        // should save
  208.                                      zoomNoGrow);
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. // CMovieFrame::FrameShapeChanged
  213. //----------------------------------------------------------------------------------------
  214. void CMovieFrame::FrameShapeChanged()
  215. {
  216.     this->UpdateUsedAndActiveShapes();
  217.  
  218.     FW_CFrameFacetIterator facets(this);
  219.     while (!facets.IsDone())
  220.     {
  221.         ((CMovieFacet*)facets.CurrentItem())->AdjustMovieBox();
  222.         facets.Next();
  223.     }
  224.     
  225.     XMPShape oldShape;
  226.     this->GetFrameShape(&oldShape);
  227.     this->Invalidate(&oldShape);
  228.     this->GetXMPFrame()->InvalidateActiveBorder();
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. // CMovieFrame::FocusStateChanged
  233. //----------------------------------------------------------------------------------------
  234. void CMovieFrame::FocusStateChanged(XMPTypeToken focus, FW_Boolean newState)
  235. {
  236.     FW_CFrame::FocusStateChanged(focus, newState);
  237.  
  238.     if (focus == this->GetPart()->GetSelectionFocusToken() && !this->IsRoot())
  239.     {
  240.         FW_CRect movieBox;
  241.         ((CMovieFacet*)this->GetActiveFacet())->GetMovieBoundingBox(&movieBox);
  242.         this->AdjustFrameSize(movieBox);
  243.         ((CMovieFacet*)this->GetActiveFacet())->ClipShapeChanged();
  244.         ((CMovieFacet*)this->GetActiveFacet())->DoMovieSetVisible(newState);
  245.     }
  246. }
  247.  
  248. //------------------------------------------------------------------------------
  249. // CMovieFrame::HandleKeyDown
  250. //------------------------------------------------------------------------------
  251. FW_Boolean CMovieFrame::HandleKeyDown(XMPEventData event)
  252. {
  253.     return ((CMovieFacet*)this->GetActiveFacet())->DoMovieKey(event);
  254. }
  255.  
  256. //------------------------------------------------------------------------------
  257. // CMovieFrame::DoMenuEvent
  258. //------------------------------------------------------------------------------
  259. FW_Boolean CMovieFrame::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
  260. {
  261.     FW_Boolean menuHandled = FALSE;
  262.     FW_CFrameFacetIterator facets(this);
  263.     CMovieFacet* movieFacet;
  264.     
  265.     switch (commandID)
  266.     {
  267.         case cStartMovie:
  268.                 while (!facets.IsDone())
  269.                 {
  270.                     ((CMovieFacet*)facets.CurrentItem())->StartMovie();
  271.                     facets.Next();
  272.                 }
  273.                 
  274.                 menuHandled = TRUE;
  275.                 break;
  276.                 
  277.         case cStopMovie:
  278.                 while (!facets.IsDone())
  279.                 {
  280.                     ((CMovieFacet*)facets.CurrentItem())->StopMovie();
  281.                     facets.Next();
  282.                 }
  283.                 
  284.                 menuHandled = TRUE;
  285.                 break;
  286.                 
  287.         default:
  288.             menuHandled = FW_CFrame::DoMenuEvent(menuBar, commandID);
  289.     }            
  290.     
  291.     return menuHandled;
  292. }
  293.  
  294. //------------------------------------------------------------------------------
  295. // CMovieFrame::DoAdjustMenus
  296. //------------------------------------------------------------------------------
  297. void CMovieFrame::DoAdjustMenus(XMPMenuBar* menuBar)
  298. {
  299.     FW_CFrame::DoAdjustMenus(menuBar);
  300.     
  301.     if (((CMovieFacet*)this->GetActiveFacet())->GetMovie())
  302.     {
  303.         menuBar->EnableCommand(cStartMovie, TRUE);
  304.         menuBar->EnableCommand(cStopMovie, TRUE);
  305.     }
  306.     else
  307.     {
  308.         menuBar->EnableCommand(cStartMovie, FALSE);
  309.         menuBar->EnableCommand(cStopMovie, FALSE);
  310.     }
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. // CMovieFrame::AdjustFrameSize
  315. //----------------------------------------------------------------------------------------
  316. void CMovieFrame::AdjustFrameSize(const FW_CRect& movieBox)
  317. {
  318.     XMPShape* newFrameShape = ::NewXMPShape(movieBox);
  319.     
  320.     this->RequestFrameShape(newFrameShape);
  321.     this->UpdateUsedAndActiveShapes();
  322.     
  323.     XMPShape oldShape;
  324.     this->GetFrameShape(&oldShape);
  325.     this->Invalidate(&oldShape);
  326.     this->GetXMPFrame()->InvalidateActiveBorder();
  327. }
  328.  
  329. //----------------------------------------------------------------------------------------
  330. // CMovieFrame::UpdateMovie
  331. //----------------------------------------------------------------------------------------
  332. void CMovieFrame::UpdateMovie()
  333. {
  334.     FW_CFrameFacetIterator facets(this);
  335.     while (!facets.IsDone())
  336.     {
  337.         ((CMovieFacet*)facets.CurrentItem())->DoMovieIdle();
  338.         facets.Next();
  339.     }
  340. }
  341.  
  342. //----------------------------------------------------------------------------------------
  343. // CMovieFrame::SetNewMovie
  344. //----------------------------------------------------------------------------------------
  345. void CMovieFrame::SetNewMovie(Movie newMovie)
  346. {
  347.     FW_CRect movieBox;
  348.     FW_CFrameFacetIterator facets(this);
  349.     CMovieFacet* movieFacet = (CMovieFacet*)facets.CurrentItem();        
  350.     
  351.     // First the first facet just use the movie we were passed
  352.     movieFacet->SetMovie(newMovie);
  353.     movieFacet->GetMovieBoundingBox(&movieBox);
  354.     this->AdjustFrameSize(movieBox);
  355.     
  356.     if (this->IsRoot())
  357.     {
  358.         FW_SPlatformRect windowRect;
  359.         XMPPlatformWindow platformWindow;
  360.         
  361.         movieBox.AsPlatformRect(windowRect);
  362.         // AMB - It may be a bad assumption that there is an active facet at this point.
  363.         platformWindow = this->GetActiveFacet()->GetXMPWindow()->GetPlatformWindow();
  364.         SizeWindow((WindowPtr)platformWindow, windowRect.right, windowRect.bottom, TRUE);
  365.         this->GetActiveFacet()->GetXMPWindow()->Resized();
  366.     }
  367.  
  368.     if (this->IsActive() || this->IsRoot())
  369.         movieFacet->DoMovieSetVisible(TRUE);
  370.         
  371.     // If there are more facets then create a handle to clone movies from
  372.     FW_PlatformHandle movieHandle = NULL;
  373.     facets.Next();
  374.     if (!facets.IsDone())
  375.     {
  376.         movieHandle = FW_CMemoryManager::AllocateSystemHandle(0);
  377.         THROW_IF_NULL(movieHandle);
  378.         THROW_IF_ERROR(::PutMovieIntoHandle(newMovie, movieHandle));
  379.         
  380.         while (!facets.IsDone())
  381.         {
  382.             movieFacet = (CMovieFacet*)facets.CurrentItem();
  383.             
  384.             FW_Boolean dataRefChanged;
  385.             THROW_IF_ERROR(::NewMovieFromHandle(&newMovie, movieHandle, newMovieActive, &dataRefChanged));
  386.             movieFacet->SetMovie(newMovie);
  387.             
  388.             if (this->IsActive() || this->IsRoot())
  389.                 movieFacet->DoMovieSetVisible(TRUE);
  390.                 
  391.             facets.Next();
  392.         }
  393.     }
  394.     
  395.     if (movieHandle)
  396.         FW_CMemoryManager::FreeSystemHandle(movieHandle);
  397. }
  398.  
  399. //----------------------------------------------------------------------------------------
  400. // CMovieFrame::CloseSelection
  401. //----------------------------------------------------------------------------------------
  402. void CMovieFrame::CloseSelection()
  403. {
  404.     FW_CFrameFacetIterator facets(this);
  405.     while (!facets.IsDone())
  406.     {
  407.         ((CMovieFacet*)facets.CurrentItem())->CloseSelection();
  408.         facets.Next();
  409.     }
  410. }
  411.  
  412. //----------------------------------------------------------------------------------------
  413. // CMovieFrame::ClearSelection
  414. //----------------------------------------------------------------------------------------
  415. void CMovieFrame::ClearSelection(TimeValue currentTime, TimeValue duration)
  416. {
  417.     FW_CFrameFacetIterator facets(this);
  418.     while (!facets.IsDone())
  419.     {
  420.         ((CMovieFacet*)facets.CurrentItem())->ClearSelection(currentTime, duration);
  421.         facets.Next();
  422.     }
  423. }
  424.  
  425. //----------------------------------------------------------------------------------------
  426. // CMovieFrame::SelectAll
  427. //----------------------------------------------------------------------------------------
  428. void CMovieFrame::SelectAll()
  429. {
  430.     FW_CFrameFacetIterator facets(this);
  431.     while (!facets.IsDone())
  432.     {
  433.         ((CMovieFacet*)facets.CurrentItem())->SelectAll();
  434.         facets.Next();
  435.     }
  436. }
  437.  
  438. //----------------------------------------------------------------------------------------
  439. // CMovieFrame::PasteMovieToSelection
  440. //----------------------------------------------------------------------------------------
  441. void CMovieFrame::PasteMovieToSelection(Movie newMovie, TimeValue currentTime, TimeValue duration)
  442. {
  443.     FW_CFrameFacetIterator facets(this);
  444.     while (!facets.IsDone())
  445.     {
  446.         ((CMovieFacet*)facets.CurrentItem())->PasteMovieToSelection(newMovie, currentTime, duration);
  447.         facets.Next();
  448.     }
  449. }
  450.  
  451. //----------------------------------------------------------------------------------------
  452. // CMovieFrame::PasteHandleToSelection
  453. //----------------------------------------------------------------------------------------
  454. void CMovieFrame::PasteHandleToSelection(FW_PlatformHandle newHandle, OSType handleType, TimeValue currentTime, TimeValue duration)
  455. {
  456.     FW_CFrameFacetIterator facets(this);
  457.     while (!facets.IsDone())
  458.     {
  459.         ((CMovieFacet*)facets.CurrentItem())->PasteHandleToSelection(newHandle, handleType, currentTime, duration);
  460.         facets.Next();
  461.     }
  462. }
  463.  
  464. //----------------------------------------------------------------------------------------
  465. // CMovieFrame::ToggleLooping
  466. //----------------------------------------------------------------------------------------
  467. void CMovieFrame::ToggleLooping(FW_Boolean looping)
  468. {
  469.     FW_CFrameFacetIterator facets(this);
  470.     while (!facets.IsDone())
  471.     {
  472.         ((CMovieFacet*)facets.CurrentItem())->SetMovieLooping(looping);
  473.         facets.Next();
  474.     }
  475. }
  476.