X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/557002cf8162a0073dbc7050732cb6d75e184148..7e81aa035ccbe28af54822e40607779d57d1b004:/src/mac/carbon/mediactrl.cpp diff --git a/src/mac/carbon/mediactrl.cpp b/src/mac/carbon/mediactrl.cpp index e77383dd49..d8cd5c284f 100644 --- a/src/mac/carbon/mediactrl.cpp +++ b/src/mac/carbon/mediactrl.cpp @@ -14,32 +14,31 @@ // on systems > 10.2 - see main.c of QTCarbonShell sample for details // // Also, with either version it will overdraw anything below its TLW - so -// its relatively useless on a notebook page (this happens in Opera too). +// it's relatively useless on a notebook page (this happens in Opera too). // // Even though though the CreateMovieControl version is the default // for OSX, the MovieController version is heavily tested and works // just as well... //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -//=========================================================================== -// DECLARATIONS -//=========================================================================== - -//--------------------------------------------------------------------------- -// Pre-compiled header stuff -//--------------------------------------------------------------------------- - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -//--------------------------------------------------------------------------- -// Includes -//--------------------------------------------------------------------------- #include "wx/mediactrl.h" -//--------------------------------------------------------------------------- -// Compilation guard -//--------------------------------------------------------------------------- +// uma is for wxMacFSSpec +#include "wx/mac/uma.h" +#include "wx/timer.h" + +#ifndef __DARWIN__ +// standard QT stuff +#include +#include +#include +#else +#include +#endif + #if wxUSE_MEDIACTRL //--------------------------------------------------------------------------- @@ -66,24 +65,9 @@ //=========================================================================== //--------------------------------------------------------------------------- -// // wxQTMediaBackend -// //--------------------------------------------------------------------------- -//--------------------------------------------------------------------------- -// QT Includes -//--------------------------------------------------------------------------- -//uma is for wxMacFSSpec -#include "wx/mac/uma.h" -#include "wx/timer.h" -#ifndef __DARWIN__ -#include -#include -#include //Standard QT stuff -#else -#include -#endif class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase { @@ -125,7 +109,7 @@ public: void FinishLoad(); virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags); - + virtual wxLongLong GetDownloadProgress(); virtual wxLongLong GetDownloadTotal(); @@ -141,28 +125,30 @@ public: wxLongLong GetDataSizeFromStart(TimeValue end); //TODO: Last param actually long - does this work on 64bit machines? - static pascal Boolean MCFilterProc (MovieController theController, + static pascal Boolean MCFilterProc(MovieController theController, short action, void *params, long refCon); #if wxUSE_CREATEMOVIECONTROL - void DoCreateMovieControl(); + void DoCreateMovieControl(); #else Boolean IsQuickTime4Installed(); void DoNewMovieController(); - static pascal void PPRMProc (Movie theMovie, - OSErr theErr, void* theRefCon); + static pascal void PPRMProc(Movie theMovie, OSErr theErr, void* theRefCon); #endif wxSize m_bestSize; // Original movie size + #ifdef __WXMAC_OSX__ struct MovieType** m_movie; // QT Movie handle/instance #else Movie m_movie; // Movie instance #endif + bool m_bPlaying; // Whether media is playing or not class wxTimer* m_timer; // Timer for streaming the movie MovieController m_mc; // MovieController instance wxMediaCtrlPlayerControls m_interfaceflags; // Saved interface flags + #if !wxUSE_CREATEMOVIECONTROL EventHandlerRef m_pEventHandlerRef; // Event handler to cleanup MoviePrePrerollCompleteUPP m_preprerollupp; @@ -170,7 +156,8 @@ public: MCActionFilterWithRefConUPP m_mcactionupp; friend class wxQTMediaEvtHandler; -#endif +#endif + DECLARE_DYNAMIC_CLASS(wxQTMediaBackend) }; @@ -183,7 +170,8 @@ public: { m_qtb = qtb; - qtb->m_ctrl->Connect(qtb->m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND, + qtb->m_ctrl->Connect( + qtb->m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground), NULL, this); } @@ -198,8 +186,8 @@ private: // Window event handler static pascal OSStatus wxQTMediaWindowEventHandler( - EventHandlerCallRef inHandlerCallRef, - EventRef inEvent, void *inUserData); + EventHandlerCallRef inHandlerCallRef, + EventRef inEvent, void *inUserData); #endif @@ -209,9 +197,7 @@ static pascal OSStatus wxQTMediaWindowEventHandler( //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -// // wxQTMediaBackend -// //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend) @@ -237,24 +223,25 @@ public: void Notify() { - //Note that the CreateMovieControl variety performs - //its own custom idleing + // Note that the CreateMovieControl variety performs + // its own custom idling #if !wxUSE_CREATEMOVIECONTROL ::MCIdle(m_parent->m_mc); #endif - //kMovieLoadStatePlayable is not enough on MAC - //- it plays, but IsMovieDone might return true (!) - //sure we need to wait until kMovieLoadStatePlaythroughOK - if(::GetMovieLoadState(m_movie) >= 20000) - { + + // kMovieLoadStatePlayable is not enough on MAC: + // it plays, but IsMovieDone might return true (!) + // sure we need to wait until kMovieLoadStatePlaythroughOK + if (::GetMovieLoadState(m_movie) >= 20000) + { m_parent->FinishLoad(); delete this; - } + } } protected: - Movie m_movie; //Our movie instance - wxQTMediaBackend* m_parent; //Backend pointer + Movie m_movie; // Our movie instance + wxQTMediaBackend *m_parent; // Backend pointer }; // -------------------------------------------------------------------------- @@ -272,7 +259,7 @@ public: m_movie(movie), m_parent(parent) {} void Notify() - { + { //Note that CreateMovieControl performs its own idleing #if !wxUSE_CREATEMOVIECONTROL // @@ -290,12 +277,10 @@ public: ::MCIdle(m_parent->m_mc); #endif - // // Handle the stop event - if the movie has reached // the end, notify our handler - // - if(::IsMovieDone(m_movie)) - { + if (::IsMovieDone(m_movie)) + { if ( m_parent->SendStopEvent() ) { m_parent->Stop(); @@ -307,8 +292,8 @@ public: } protected: - Movie m_movie; //Our movie instance - wxQTMediaBackend* m_parent; //Backend pointer + Movie m_movie; // Our movie instance + wxQTMediaBackend* m_parent; // Backend pointer }; @@ -317,7 +302,7 @@ protected: // // Sets m_timer to NULL signifying we havn't loaded anything yet //--------------------------------------------------------------------------- -wxQTMediaBackend::wxQTMediaBackend() +wxQTMediaBackend::wxQTMediaBackend() : m_movie(NULL), m_bPlaying(false), m_timer(NULL) , m_mc(NULL), m_interfaceflags(wxMEDIACTRLPLAYERCONTROLS_NONE) #if !wxUSE_CREATEMOVIECONTROL @@ -337,12 +322,12 @@ wxQTMediaBackend::wxQTMediaBackend() //--------------------------------------------------------------------------- wxQTMediaBackend::~wxQTMediaBackend() { - if(m_movie) + if (m_movie) Cleanup(); #if !wxUSE_CREATEMOVIECONTROL // Cleanup for moviecontroller - if(m_mc) + if (m_mc) { // destroy wxQTMediaEvtHandler we pushed on it m_ctrl->PopEventHandler(true); @@ -355,7 +340,7 @@ wxQTMediaBackend::~wxQTMediaBackend() } #endif - //Note that ExitMovies() is not necessary... + // Note that ExitMovies() is not necessary... ExitMovies(); } @@ -365,15 +350,17 @@ wxQTMediaBackend::~wxQTMediaBackend() // 1) Intializes QuickTime // 2) Creates the control window //--------------------------------------------------------------------------- -bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, - wxWindowID id, - const wxPoint& pos, - const wxSize& size, - long style, - const wxValidator& validator, - const wxString& name) +bool wxQTMediaBackend::CreateControl( + wxControl* ctrl, + wxWindow* parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) { - //Don't bother in Native control mode + // Don't bother in Native control mode #if !wxUSE_CREATEMOVIECONTROL if (!IsQuickTime4Installed()) return false; @@ -381,19 +368,19 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, EnterMovies(); - // // Create window // By default wxWindow(s) is created with a border - // so we need to get rid of those // // Since we don't have a child window like most other // backends, we don't need wxCLIP_CHILDREN - // - if ( !ctrl->wxControl::Create(parent, id, pos, size, - wxWindow::MacRemoveBordersFromStyle(style), - validator, name) - ) + if ( !ctrl->wxControl::Create( + parent, id, pos, size, + wxWindow::MacRemoveBordersFromStyle(style), + validator, name)) + { return false; + } #if wxUSE_VALIDATORS ctrl->SetValidator(validator); @@ -406,16 +393,16 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, //--------------------------------------------------------------------------- // wxQTMediaBackend::IsQuickTime4Installed // -// Determines whether version 4 of QT is installed -// (Pretty much for classic only) +// Determines whether version 4 of QT is installed +// (Pretty much for Classic only) //--------------------------------------------------------------------------- #if !wxUSE_CREATEMOVIECONTROL Boolean wxQTMediaBackend::IsQuickTime4Installed() { - short error; + OSErr error; long result; - error = Gestalt (gestaltQuickTime, &result); + error = Gestalt(gestaltQuickTime, &result); return (error == noErr) && (((result >> 16) & 0xffff) >= 0x0400); } #endif @@ -431,40 +418,41 @@ Boolean wxQTMediaBackend::IsQuickTime4Installed() //--------------------------------------------------------------------------- bool wxQTMediaBackend::Load(const wxString& fileName) { - if(m_movie) + if (m_movie) Cleanup(); OSErr err = noErr; short movieResFile; FSSpec sfFile; - //FIXME:wxMacFilename2FSSpec crashes on empty string - - //does it crash on other strings too and should this - //"fix" be put in the carbon wxSound? + // FIXME:wxMacFilename2FSSpec crashes on empty string - + // does it crash on other strings too and should this + // "fix" be put in the Carbon wxSound? if (fileName.empty()) return false; - wxMacFilename2FSSpec( fileName , &sfFile ); - - if (OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr) + wxMacFilename2FSSpec( fileName, &sfFile ); + if (OpenMovieFile( &sfFile, &movieResFile, fsRdPerm ) != noErr) return false; short movieResID = 0; Str255 movieName; + bool result; - err = NewMovieFromFile ( - &m_movie, - movieResFile, - &movieResID, - movieName, - newMovieActive, - NULL); //wasChanged + err = NewMovieFromFile( + &m_movie, + movieResFile, + &movieResID, + movieName, + newMovieActive, + NULL); // wasChanged - //No ::GetMoviesStickyError() here because it returns -2009 + // No ::GetMoviesStickyError() here because it returns -2009 // a.k.a. invalid track on valid mpegs - if(err == noErr) + result = (err == noErr); + if (result) { - ::CloseMovieFile (movieResFile); + ::CloseMovieFile(movieResFile); // Create movie controller/control #if wxUSE_CREATEMOVIECONTROL @@ -472,13 +460,11 @@ bool wxQTMediaBackend::Load(const wxString& fileName) #else DoNewMovieController(); #endif - FinishLoad(); - return true; - } - else - { - return false; + + FinishLoad(); } + + return result; } //--------------------------------------------------------------------------- @@ -489,9 +475,10 @@ bool wxQTMediaBackend::Load(const wxString& fileName) // Anyway we set up the loading timer here to tell us when the movie is done //--------------------------------------------------------------------------- #if !wxUSE_CREATEMOVIECONTROL -pascal void wxQTMediaBackend::PPRMProc (Movie theMovie, - OSErr WXUNUSED_UNLESS_DEBUG(theErr), - void* theRefCon) +pascal void wxQTMediaBackend::PPRMProc( + Movie theMovie, + OSErr WXUNUSED_UNLESS_DEBUG(theErr), + void* theRefCon) { wxASSERT( theMovie ); wxASSERT( theRefCon ); @@ -520,43 +507,46 @@ pascal void wxQTMediaBackend::PPRMProc (Movie theMovie, //--------------------------------------------------------------------------- bool wxQTMediaBackend::Load(const wxURI& location) { - if(m_movie) + if (m_movie) Cleanup(); wxString theURI = location.BuildURI(); OSErr err = noErr; + bool result; + // FIXME: lurking Unicode problem here Handle theHandle = ::NewHandleClear(theURI.length() + 1); wxASSERT(theHandle); - ::BlockMove(theURI.mb_str(), *theHandle, theURI.length() + 1); + ::BlockMoveData(theURI.mb_str(), *theHandle, theURI.length() + 1); - //create the movie from the handle that refers to the URI - err = ::NewMovieFromDataRef(&m_movie, newMovieActive | - newMovieAsyncOK - /*|newMovieIdleImportOK*/, - NULL, theHandle, - URLDataHandlerSubType); + // create the movie from the handle that refers to the URI + err = ::NewMovieFromDataRef( + &m_movie, + newMovieActive | newMovieAsyncOK /* | newMovieIdleImportOK*/, + NULL, theHandle, + URLDataHandlerSubType); ::DisposeHandle(theHandle); - if (err == noErr) + result = (err == noErr); + if (result) { #if wxUSE_CREATEMOVIECONTROL // Movie control does its own "(pre)prerolling" - // but we still need to buffer the movie for the url + // but we still need to buffer the movie for the URL DoCreateMovieControl(); // Setup timer to catch load event m_timer = new wxQTMediaLoadTimer(m_movie, this); m_timer->Start(MOVIE_DELAY); #else - // Movie controller resets prerolling, so we must create first + // Movie controller resets prerolling, so we must create first DoNewMovieController(); - + long timeNow; - Fixed playRate; + Fixed playRate; timeNow = ::GetMovieTime(m_movie, NULL); wxASSERT(::GetMoviesError() == noErr); @@ -564,7 +554,6 @@ bool wxQTMediaBackend::Load(const wxURI& location) playRate = ::GetMoviePreferredRate(m_movie); wxASSERT(::GetMoviesError() == noErr); - // // Note that the callback here is optional, // but without it PrePrerollMovie can be buggy // (see Apple ml). Also, some may wonder @@ -573,19 +562,12 @@ bool wxQTMediaBackend::Load(const wxURI& location) // require it if you don't use a Movie Controller, // which we don't by default. // - m_preprerollupp = - NewMoviePrePrerollCompleteUPP( - wxQTMediaBackend::PPRMProc - ); - - ::PrePrerollMovie(m_movie, timeNow, playRate, - m_preprerollupp, - (void*)this); + m_preprerollupp = NewMoviePrePrerollCompleteUPP( wxQTMediaBackend::PPRMProc ); + ::PrePrerollMovie( m_movie, timeNow, playRate, m_preprerollupp, (void*)this); #endif - return true; } - else - return false; + + return result; } //--------------------------------------------------------------------------- @@ -602,54 +584,51 @@ bool wxQTMediaBackend::Load(const wxURI& location) #if wxUSE_CREATEMOVIECONTROL void wxQTMediaBackend::DoCreateMovieControl() { - // - //Native CreateMovieControl QT control (Thanks to Kevin Olliver's - // wxQTMovie for how to do some of this). - // - Rect bounds = wxMacGetBoundsForControl(m_ctrl, - m_ctrl->GetPosition(), - m_ctrl->GetSize()); - - //Dispose of old control for new one + // Native CreateMovieControl QT control (Thanks to Kevin Olliver's + // wxQTMovie for some of this). + Rect bounds = wxMacGetBoundsForControl( + m_ctrl, + m_ctrl->GetPosition(), + m_ctrl->GetSize()); + + // Dispose of old control for new one if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() ) m_ctrl->m_peer->Dispose(); - //Options- - //kMovieControlOptionXXX - //HideController - hide the movie controller - //LocateTopLeft - movie is pinned to top left rather than centered in the control - //EnableEditing - Allows programmatic editing and dragn'drop - //HandleEditingHI- Installs event stuff for edit menu - forces EnableEditing also - //SetKeysEnabled - Allows keyboard input - //ManuallyIdled - app handles movie idling rather than internal timer event loop - ::CreateMovieControl( - (WindowRef) - m_ctrl->MacGetTopLevelWindowRef(), //parent - &bounds, //control bounds - m_movie, //movie handle - kMovieControlOptionHideController - | kMovieControlOptionLocateTopLeft - | kMovieControlOptionSetKeysEnabled - // | kMovieControlOptionManuallyIdled - , //flags - m_ctrl->m_peer->GetControlRefAddr() ); - - ::EmbedControl(m_ctrl->m_peer->GetControlRef(), - (ControlRef)m_ctrl->GetParent()->GetHandle()); - - // - // Setup MovieController for the new movie - // + // Options: + // kMovieControlOptionXXX + // HideController - hide the movie controller + // LocateTopLeft - movie is pinned to top left rather than centered in the control + // EnableEditing - Allows programmatic editing and dragn'drop + // HandleEditingHI- Installs event stuff for edit menu - forces EnableEditing also + // SetKeysEnabled - Allows keyboard input + // ManuallyIdled - app handles movie idling rather than internal timer event loop + ::CreateMovieControl( + (WindowRef) m_ctrl->MacGetTopLevelWindowRef(), //parent + &bounds, // control bounds + m_movie, // movie handle + kMovieControlOptionHideController// flags + // | kMovieControlOptionManuallyIdled + | kMovieControlOptionLocateTopLeft + | kMovieControlOptionSetKeysEnabled, + m_ctrl->m_peer->GetControlRefAddr() ); + + ::EmbedControl( + m_ctrl->m_peer->GetControlRef(), + (ControlRef)m_ctrl->GetParent()->GetHandle()); + + // set up MovieController for the new movie long dataSize; - //Get movie controller from our control - ::GetControlData( m_ctrl->m_peer->GetControlRef(), 0, - kMovieControlDataMovieController, - sizeof(MovieController), (Ptr)&m_mc, &dataSize ); + // Get movie controller from our control + ::GetControlData( + m_ctrl->m_peer->GetControlRef(), 0, + kMovieControlDataMovieController, + sizeof(MovieController), (Ptr)&m_mc, &dataSize ); // Setup a callback so we can tell when the user presses // play on the player controls - ::MCSetActionFilterWithRefCon(m_mc, + ::MCSetActionFilterWithRefCon(m_mc, (MCActionFilterWithRefConUPP)wxQTMediaBackend::MCFilterProc, (long)this); } @@ -664,80 +643,74 @@ void wxQTMediaBackend::DoCreateMovieControl() #if !wxUSE_CREATEMOVIECONTROL void wxQTMediaBackend::DoNewMovieController() { - if(!m_mc) + if (!m_mc) { // Get top level window ref for some mac functions WindowRef wrTLW = (WindowRef) m_ctrl->MacGetTopLevelWindowRef(); - - // MovieController not setup yet - - // so we need to create a new one. - // You have to pass a valid movie to - // NewMovieController, evidently + + // MovieController not set up yet, so we need to create a new one. + // You have to pass a valid movie to NewMovieController, evidently ::SetMovieGWorld(m_movie, (CGrafPtr) GetWindowPort(wrTLW), NULL); wxASSERT(::GetMoviesError() == noErr); - Rect bounds = wxMacGetBoundsForControl(m_ctrl, - m_ctrl->GetPosition(), - m_ctrl->GetSize()); + Rect bounds = wxMacGetBoundsForControl( + m_ctrl, + m_ctrl->GetPosition(), + m_ctrl->GetSize()); - m_mc = ::NewMovieController(m_movie, &bounds, mcTopLeftMovie | - //mcWithFrame | - mcNotVisible); + m_mc = ::NewMovieController( + m_movie, &bounds, + mcTopLeftMovie | mcNotVisible /* | mcWithFrame */ ); wxASSERT(::GetMoviesError() == noErr); - ::MCDoAction(m_mc, 32, (void*)true); //mcActionSetKeysEnabled + + ::MCDoAction(m_mc, 32, (void*)true); // mcActionSetKeysEnabled wxASSERT(::GetMoviesError() == noErr); // Setup a callback so we can tell when the user presses // play on the player controls - m_mcactionupp = - NewMCActionFilterWithRefConUPP( - wxQTMediaBackend::MCFilterProc - ); - ::MCSetActionFilterWithRefCon(m_mc, - m_mcactionupp, - (long)this); + m_mcactionupp = NewMCActionFilterWithRefConUPP( wxQTMediaBackend::MCFilterProc ); + ::MCSetActionFilterWithRefCon( m_mc, m_mcactionupp, (long)this ); wxASSERT(::GetMoviesError() == noErr); - //Part of a suggestion from Greg Hazel to repaint - //movie when idle + // Part of a suggestion from Greg Hazel to repaint movie when idle m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this)); - + // Event types to catch from the TLW // for the moviecontroller - EventTypeSpec theEventTypes[] = { - { kEventClassMouse, kEventMouseDown }, - { kEventClassMouse, kEventMouseUp }, - { kEventClassMouse, kEventMouseDragged }, - { kEventClassKeyboard, kEventRawKeyDown }, - { kEventClassKeyboard, kEventRawKeyRepeat }, - { kEventClassKeyboard, kEventRawKeyUp }, - { kEventClassWindow, kEventWindowUpdate }, - { kEventClassWindow, kEventWindowActivated }, - { kEventClassWindow, kEventWindowDeactivated } - }; - - // Catch window messages - + EventTypeSpec theEventTypes[] = + { + { kEventClassMouse, kEventMouseDown }, + { kEventClassMouse, kEventMouseUp }, + { kEventClassMouse, kEventMouseDragged }, + { kEventClassKeyboard, kEventRawKeyDown }, + { kEventClassKeyboard, kEventRawKeyRepeat }, + { kEventClassKeyboard, kEventRawKeyUp }, + { kEventClassWindow, kEventWindowUpdate }, + { kEventClassWindow, kEventWindowActivated }, + { kEventClassWindow, kEventWindowDeactivated } + }; + + // Catch window messages: // if we do not do this and if the user clicks the play // button on the controller, for instance, nothing will happen... - m_eventupp = NewEventHandlerUPP( - wxQTMediaWindowEventHandler - ); - InstallWindowEventHandler( wrTLW, - m_eventupp, - GetEventTypeCount( theEventTypes ), theEventTypes, - m_mc, (&(EventHandlerRef&)m_pEventHandlerRef) ); + m_eventupp = NewEventHandlerUPP( wxQTMediaWindowEventHandler ); + InstallWindowEventHandler( + wrTLW, + m_eventupp, + GetEventTypeCount( theEventTypes ), theEventTypes, + m_mc, (&(EventHandlerRef&)m_pEventHandlerRef) ); } else { - // MovieController already created - + // MovieController already created: // Just change the movie in it and we're good to go Point thePoint; thePoint.h = thePoint.v = 0; - ::MCSetMovie(m_mc, m_movie, + ::MCSetMovie(m_mc, m_movie, (WindowRef)m_ctrl->MacGetTopLevelWindowRef(), - thePoint); + thePoint); wxASSERT(::GetMoviesError() == noErr); } } @@ -749,28 +722,29 @@ void wxQTMediaBackend::DoNewMovieController() // Performs operations after a movie ready to play/loaded. //--------------------------------------------------------------------------- void wxQTMediaBackend::FinishLoad() -{ - // Dispose of the Preprerollmovieupp if we used it +{ + // Dispose of the PrePrerollMovieUPP if we used it #if !wxUSE_CREATEMOVIECONTROL DisposeMoviePrePrerollCompleteUPP(m_preprerollupp); #endif + // get the real size of the movie DoLoadBestSize(); - // Show the player controls if the user wants to - if(m_interfaceflags) + // show the player controls if the user wants to + if (m_interfaceflags) DoSetControllerVisible(m_interfaceflags); - //we want millisecond precision + // we want millisecond precision ::SetMovieTimeScale(m_movie, 1000); wxASSERT(::GetMoviesError() == noErr); - // Start movie progress timer + // start movie progress timer m_timer = new wxQTMediaPlayTimer(m_movie, (wxQTMediaBackend*) this); wxASSERT(m_timer); m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); - //send loaded event & refresh size + // send loaded event and refresh size NotifyMovieLoaded(); } @@ -781,12 +755,12 @@ void wxQTMediaBackend::FinishLoad() //--------------------------------------------------------------------------- void wxQTMediaBackend::DoLoadBestSize() { - //get the real size of the movie + // get the real size of the movie Rect outRect; - ::GetMovieNaturalBoundsRect (m_movie, &outRect); + ::GetMovieNaturalBoundsRect(m_movie, &outRect); wxASSERT(::GetMoviesError() == noErr); - //determine best size + // determine best size m_bestSize.x = outRect.right - outRect.left; m_bestSize.y = outRect.bottom - outRect.top; } @@ -800,24 +774,22 @@ void wxQTMediaBackend::DoLoadBestSize() bool wxQTMediaBackend::Play() { Fixed fixRate = (Fixed) (wxQTMediaBackend::GetPlaybackRate() * 0x10000); - if(!fixRate) + if (!fixRate) fixRate = ::GetMoviePreferredRate(m_movie); - + wxASSERT(fixRate != 0); - if(!m_bPlaying) - ::MCDoAction( m_mc, 8, // mcActionPlay - (void *) fixRate); + if (!m_bPlaying) + ::MCDoAction( m_mc, 8 /* mcActionPlay */, (void*) fixRate); - if(::GetMoviesError() == noErr) + bool result = (::GetMoviesError() == noErr); + if (result) { - - m_bPlaying = true; + m_bPlaying = true; QueuePlayEvent(); - return true; } - else - return false; + + return result; } //--------------------------------------------------------------------------- @@ -827,27 +799,25 @@ bool wxQTMediaBackend::Play() //--------------------------------------------------------------------------- bool wxQTMediaBackend::DoPause() { - //Stop the movie A.K.A. ::StopMovie(m_movie); - if(m_bPlaying) + // Stop the movie A.K.A. ::StopMovie(m_movie); + if (m_bPlaying) { - ::MCDoAction( m_mc, 8 /*mcActionPlay*/, - (void *) 0); + ::MCDoAction( m_mc, 8 /*mcActionPlay*/, (void *) 0); m_bPlaying = false; - return ::GetMoviesError() == noErr; + return ::GetMoviesError() == noErr; } - return true; //already paused + + // already paused + return true; } bool wxQTMediaBackend::Pause() { bool bSuccess = DoPause(); - if(bSuccess) - { + if (bSuccess) this->QueuePauseEvent(); - return true; - } - else - return false; + + return bSuccess; } //--------------------------------------------------------------------------- @@ -858,7 +828,7 @@ bool wxQTMediaBackend::Pause() //--------------------------------------------------------------------------- bool wxQTMediaBackend::DoStop() { - if(!wxQTMediaBackend::DoPause()) + if (!wxQTMediaBackend::DoPause()) return false; ::GoToBeginningOfMovie(m_movie); @@ -868,13 +838,10 @@ bool wxQTMediaBackend::DoStop() bool wxQTMediaBackend::Stop() { bool bSuccess = DoStop(); - if(bSuccess) - { + if (bSuccess) QueueStopEvent(); - return true; - } - else - return false; + + return bSuccess; } //--------------------------------------------------------------------------- @@ -948,10 +915,10 @@ double wxQTMediaBackend::GetVolume() { short sVolume = ::GetMovieVolume(m_movie); - if(sVolume & (128 << 8)) //negative - no sound + if (sVolume & (128 << 8)) //negative - no sound return 0.0; - return sVolume/256.0; + return sVolume / 256.0; } //--------------------------------------------------------------------------- @@ -974,8 +941,8 @@ bool wxQTMediaBackend::SetVolume(double dVolume) ::SetMovieVolume(m_movie, (short) (dVolume * 256)); return true; } - - //--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- // wxQTMediaBackend::GetDuration // // Calls GetMovieDuration @@ -994,9 +961,9 @@ wxLongLong wxQTMediaBackend::GetDuration() wxMediaState wxQTMediaBackend::GetState() { // Could use - // GetMovieActive/IsMovieDone/SetMovieActive + // GetMovieActive/IsMovieDone/SetMovieActive // combo if implemented that way - if (m_bPlaying == true) + if (m_bPlaying) return wxMEDIASTATE_PLAYING; else if ( !m_movie || wxQTMediaBackend::GetPosition() == 0) return wxMEDIASTATE_STOPPED; @@ -1013,23 +980,21 @@ wxMediaState wxQTMediaBackend::GetState() void wxQTMediaBackend::Cleanup() { m_bPlaying = false; - if(m_timer) + if (m_timer) { - delete m_timer; - m_timer = NULL; + delete m_timer; + m_timer = NULL; } - // Stop the movie + // Stop the movie: // Apple samples with CreateMovieControl typically // install a event handler and do this on the dispose // event, but we do it here for simplicity // (It might keep playing for several seconds after - // control destruction if not) + // control destruction if not) wxQTMediaBackend::Pause(); - - // + // Dispose of control or remove movie from MovieController - // #if wxUSE_CREATEMOVIECONTROL if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() ) m_ctrl->m_peer->Dispose(); @@ -1041,6 +1006,7 @@ void wxQTMediaBackend::Cleanup() #endif ::DisposeMovie(m_movie); + m_movie = NULL; } //--------------------------------------------------------------------------- @@ -1049,25 +1015,29 @@ void wxQTMediaBackend::Cleanup() // Callback for when the movie controller recieves a message //--------------------------------------------------------------------------- pascal Boolean wxQTMediaBackend::MCFilterProc( - MovieController WXUNUSED(theController), - short action, - void * WXUNUSED(params), - long refCon) + MovieController WXUNUSED(theController), + short action, + void * WXUNUSED(params), + long refCon) { - if(action != 1) //don't process idle events - { - wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon; + wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon; - switch(action) - { - case 8: //play button triggered - MC will set movie to opposite state - //of current - playing ? paused : playing - pThis->m_bPlaying = !(pThis->m_bPlaying); - break; - default: - break; - } + switch (action) + { + case 1: + // don't process idle events + break; + + case 8: + // play button triggered - MC will set movie to opposite state + // of current - playing ? paused : playing + pThis->m_bPlaying = !(pThis->m_bPlaying); + break; + + default: + break; } + return 0; } @@ -1097,30 +1067,33 @@ wxSize wxQTMediaBackend::GetVideoSize() const void wxQTMediaBackend::Move(int x, int y, int w, int h) { #if !wxUSE_CREATEMOVIECONTROL - if(m_timer) + if (m_timer) { - m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y); - Rect theRect = {y, x, y+h, x+w}; -#if 0 // see note above - ::MCSetControllerAttached(m_mc, FALSE); - wxASSERT(::GetMoviesError() == noErr); + m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y); + Rect theRect = {y, x, y + h, x + w}; + +#if 0 + // see note above + ::MCSetControllerAttached(m_mc, false); + wxASSERT(::GetMoviesError() == noErr); #endif + ::MCSetControllerBoundsRect(m_mc, &theRect); wxASSERT(::GetMoviesError() == noErr); #if 0 // see note above - if(m_interfaceflags) + if (m_interfaceflags) { - ::MCSetVisible(m_mc, TRUE); - wxASSERT(::GetMoviesError() == noErr); - } + ::MCSetVisible(m_mc, true); + wxASSERT(::GetMoviesError() == noErr); + } #endif } #else - if(m_timer && m_ctrl) - { - m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y); + if (m_timer && m_ctrl) + { + m_ctrl->GetParent()->MacWindowToRootWindow( &x, &y ); ::MoveControl( (ControlRef) m_ctrl->GetHandle(), x, y ); m_ctrl->GetParent()->Refresh(); m_ctrl->GetParent()->Update(); @@ -1135,35 +1108,32 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h) // and showing/hiding the particular controls on it //--------------------------------------------------------------------------- void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags) -{ - ::MCSetVisible(m_mc, TRUE); - - // +{ + ::MCSetVisible(m_mc, true); + // Take care of subcontrols - // - if(::GetMoviesError() == noErr) + if (::GetMoviesError() == noErr) { long mcFlags = 0; ::MCDoAction(m_mc, 39/*mcActionGetFlags*/, (void*)&mcFlags); - - if(::GetMoviesError() == noErr) - { + + if (::GetMoviesError() == noErr) + { mcFlags |= ( //(1<<0)/*mcFlagSuppressMovieFrame*/ | - (1<<3)/*mcFlagsUseWindowPalette*/ + (1 << 3)/*mcFlagsUseWindowPalette*/ | ((flags & wxMEDIACTRLPLAYERCONTROLS_STEP) - ? 0 : (1<<1)/*mcFlagSuppressStepButtons*/) + ? 0 : (1 << 1)/*mcFlagSuppressStepButtons*/) | ((flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME) - ? 0 : (1<<2)/*mcFlagSuppressSpeakerButton*/) - // | (1<<4) /*mcFlagDontInvalidate*/ //if we take care of repainting ourselves + ? 0 : (1 << 2)/*mcFlagSuppressSpeakerButton*/) + // | (1 << 4) /*mcFlagDontInvalidate*/ //if we take care of repainting ourselves ); - ::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags); + + ::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags); } - } - - // - //Adjust height and width of best size for movie controller - //if the user wants it shown - // + } + + // Adjust height and width of best size for movie controller + // if the user wants it shown m_bestSize.x = m_bestSize.x > wxMCWIDTH ? m_bestSize.x : wxMCWIDTH; m_bestSize.y += wxMCHEIGHT; } @@ -1175,32 +1145,33 @@ void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags) //--------------------------------------------------------------------------- bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags) { - if(!m_mc) - return false; //no movie controller... - + if (!m_mc) + return false; // no movie controller... + bool bSizeChanged = false; - - //if the controller is visible and we want to hide it do so - if(m_interfaceflags && !flags) + + // if the controller is visible and we want to hide it do so + if (m_interfaceflags && !flags) { bSizeChanged = true; DoLoadBestSize(); - ::MCSetVisible(m_mc, FALSE); + ::MCSetVisible(m_mc, false); } - else if(!m_interfaceflags && flags) //show controller if hidden + else if (!m_interfaceflags && flags) // show controller if hidden { bSizeChanged = true; DoSetControllerVisible(flags); } - - //readjust parent sizers - if(bSizeChanged) + + // readjust parent sizers + if (bSizeChanged) { - NotifyMovieSizeChanged(); - - //remember state in case of loading new media + NotifyMovieSizeChanged(); + + // remember state in case of loading new media m_interfaceflags = flags; - } + } + return ::GetMoviesError() == noErr; } @@ -1231,14 +1202,16 @@ wxLongLong wxQTMediaBackend::GetDownloadProgress() PutMovieIntoHandle(m_movie, hMovie); long lSize = GetHandleSize(hMovie); DisposeHandle(hMovie); + return lSize; #else TimeValue tv; - if(::GetMaxLoadedTimeInMovie(m_movie, &tv) != noErr) + if (::GetMaxLoadedTimeInMovie(m_movie, &tv) != noErr) { wxLogDebug(wxT("GetMaxLoadedTimeInMovie failed")); return 0; } + return wxQTMediaBackend::GetDataSizeFromStart(tv); #endif } @@ -1248,12 +1221,9 @@ wxLongLong wxQTMediaBackend::GetDownloadProgress() //--------------------------------------------------------------------------- wxLongLong wxQTMediaBackend::GetDownloadTotal() { - return wxQTMediaBackend::GetDataSizeFromStart( - ::GetMovieDuration(m_movie) - ); + return wxQTMediaBackend::GetDataSizeFromStart( ::GetMovieDuration(m_movie) ); } - //--------------------------------------------------------------------------- // wxQTMediaBackend::OnEraseBackground // @@ -1263,14 +1233,13 @@ wxLongLong wxQTMediaBackend::GetDownloadTotal() #if !wxUSE_CREATEMOVIECONTROL void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt) { - // Work around Nasty OSX drawing bug - + // Work around Nasty OSX drawing bug: // http://lists.apple.com/archives/QuickTime-API/2002/Feb/msg00311.html - WindowRef wrTLW = - (WindowRef) m_qtb->m_ctrl->MacGetTopLevelWindowRef(); + WindowRef wrTLW = (WindowRef) m_qtb->m_ctrl->MacGetTopLevelWindowRef(); - RgnHandle region = ::MCGetControllerBoundsRgn(m_qtb->m_mc); - ::MCInvalidate(m_qtb->m_mc, wrTLW, region); - ::MCIdle(m_qtb->m_mc); + RgnHandle region = MCGetControllerBoundsRgn(m_qtb->m_mc); + MCInvalidate(m_qtb->m_mc, wrTLW, region); + MCIdle(m_qtb->m_mc); } #endif @@ -1278,19 +1247,20 @@ void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt) // wxQTMediaWindowEventHandler // // Event callback for the top level window of our control that passes -// messages to our moviecontroller so it can recieve mouse clicks etc. +// messages to our moviecontroller so it can receive mouse clicks etc. //--------------------------------------------------------------------------- #if !wxUSE_CREATEMOVIECONTROL static pascal OSStatus wxQTMediaWindowEventHandler( - EventHandlerCallRef inHandlerCallRef, - EventRef inEvent, void *inUserData) + EventHandlerCallRef inHandlerCallRef, + EventRef inEvent, + void *inUserData) { // for the overly paranoid.... #if 0 UInt32 eventClass = GetEventClass( eventRef ); UInt32 eventKind = GetEventKind( inEvent ); - if(eventKind != kEventMouseDown && + if (eventKind != kEventMouseDown && eventKind != kEventMouseUp && eventKind != kEventMouseDragged && eventKind != kEventRawKeyDown && @@ -1298,25 +1268,26 @@ static pascal OSStatus wxQTMediaWindowEventHandler( eventKind != kEventRawKeyUp && eventKind != kEventWindowUpdate && eventKind != kEventWindowActivated && - eventKind != kEventWindowDeactivated ) + eventKind != kEventWindowDeactivated) return eventNotHandledErr; #endif + EventRecord theEvent; ConvertEventRefToEventRecord( inEvent, &theEvent ); OSStatus err; err = ::MCIsPlayerEvent( (MovieController) inUserData, &theEvent ); - + // pass on to other event handlers if not handled- i.e. wx - if(err) + if (err != noErr) return noErr; else return eventNotHandledErr; } #endif -//in source file that contains stuff you don't directly use +// in source file that contains stuff you don't directly use #include "wx/html/forcelnk.h" FORCE_LINK_ME(basewxmediabackends) -#endif //wxUSE_MEDIACTRL +#endif // wxUSE_MEDIACTRL