cleanup - reformatting

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Surovell
2006-02-10 17:53:02 +00:00
parent f288c87b3d
commit 592a247ddd

View File

@@ -14,14 +14,6 @@
// on systems > 10.2 - see main.c of QTCarbonShell sample for details // on systems > 10.2 - see main.c of QTCarbonShell sample for details
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//===========================================================================
// DECLARATIONS
//===========================================================================
//---------------------------------------------------------------------------
// Pre-compiled header stuff
//---------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
@@ -29,14 +21,20 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "wx/mediactrl.h" #include "wx/mediactrl.h"
//--------------------------------------------------------------------------- // uma is for wxMacFSSpec
// Compilation guard #include "wx/mac/uma.h"
//--------------------------------------------------------------------------- #include "wx/timer.h"
#ifndef __DARWIN__
#include <Movies.h>
#include <Gestalt.h>
#include <QuickTimeComponents.h> // standard QT stuff
#else
#include <QuickTime/QuickTimeComponents.h>
#endif
#if wxUSE_MEDIACTRL #if wxUSE_MEDIACTRL
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -63,24 +61,9 @@
//=========================================================================== //===========================================================================
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
//
// wxQTMediaBackend // wxQTMediaBackend
//
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// QT Includes
//---------------------------------------------------------------------------
//uma is for wxMacFSSpec
#include "wx/mac/uma.h"
#include "wx/timer.h"
#ifndef __DARWIN__
#include <Movies.h>
#include <Gestalt.h>
#include <QuickTimeComponents.h> //Standard QT stuff
#else
#include <QuickTime/QuickTimeComponents.h>
#endif
class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase
{ {
@@ -123,10 +106,8 @@ public:
virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags); virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags);
//
// ------ Implementation from now on -------- // ------ Implementation from now on --------
//
void DoLoadBestSize(); void DoLoadBestSize();
void DoSetControllerVisible(wxMediaCtrlPlayerControls flags); void DoSetControllerVisible(wxMediaCtrlPlayerControls flags);
@@ -143,20 +124,24 @@ public:
#endif #endif
wxSize m_bestSize; // Original movie size wxSize m_bestSize; // Original movie size
#ifdef __WXMAC_OSX__ #ifdef __WXMAC_OSX__
struct MovieType** m_movie; // QT Movie handle/instance struct MovieType** m_movie; // QT Movie handle/instance
#else #else
Movie m_movie; // Movie instance Movie m_movie; // Movie instance
#endif #endif
bool m_bPlaying; // Whether media is playing or not bool m_bPlaying; // Whether media is playing or not
class wxTimer* m_timer; // Timer for streaming the movie class wxTimer* m_timer; // Timer for streaming the movie
MovieController m_mc; // MovieController instance MovieController m_mc; // MovieController instance
wxMediaCtrlPlayerControls m_interfaceflags; // Saved interface flags wxMediaCtrlPlayerControls m_interfaceflags; // Saved interface flags
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
EventHandlerRef m_pEventHandlerRef; // Event handler to cleanup EventHandlerRef m_pEventHandlerRef; // Event handler to cleanup
friend class wxQTMediaEvtHandler; friend class wxQTMediaEvtHandler;
#endif #endif
DECLARE_DYNAMIC_CLASS(wxQTMediaBackend) DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
}; };
@@ -169,7 +154,8 @@ public:
{ {
m_qtb = qtb; 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), wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground),
NULL, this); NULL, this);
} }
@@ -196,9 +182,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxQTMediaWindowEventHandler );
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxQTMediaBackend // wxQTMediaBackend
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend) IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
@@ -224,15 +208,16 @@ public:
void Notify() void Notify()
{ {
//Note that the CreateMovieControl variety performs // Note that the CreateMovieControl variety performs
//its own custom idleing // its own custom idleing
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
::MCIdle(m_parent->m_mc); ::MCIdle(m_parent->m_mc);
#endif #endif
//kMovieLoadStatePlayable is not enough on MAC
//- it plays, but IsMovieDone might return true (!) // kMovieLoadStatePlayable is not enough on MAC:
//sure we need to wait until kMovieLoadStatePlaythroughOK // it plays, but IsMovieDone might return true (!)
if(::GetMovieLoadState(m_movie) >= 20000) // sure we need to wait until kMovieLoadStatePlaythroughOK
if (::GetMovieLoadState(m_movie) >= 20000)
{ {
m_parent->FinishLoad(); m_parent->FinishLoad();
delete this; delete this;
@@ -240,8 +225,8 @@ public:
} }
protected: protected:
Movie m_movie; //Our movie instance Movie m_movie; // Our movie instance
wxQTMediaBackend* m_parent; //Backend pointer wxQTMediaBackend *m_parent; // Backend pointer
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@@ -277,11 +262,9 @@ public:
::MCIdle(m_parent->m_mc); ::MCIdle(m_parent->m_mc);
#endif #endif
//
// Handle the stop event - if the movie has reached // Handle the stop event - if the movie has reached
// the end, notify our handler // the end, notify our handler
// if (::IsMovieDone(m_movie))
if(::IsMovieDone(m_movie))
{ {
if ( m_parent->SendStopEvent() ) if ( m_parent->SendStopEvent() )
{ {
@@ -294,8 +277,8 @@ public:
} }
protected: protected:
Movie m_movie; //Our movie instance Movie m_movie; // Our movie instance
wxQTMediaBackend* m_parent; //Backend pointer wxQTMediaBackend* m_parent; // Backend pointer
}; };
@@ -321,12 +304,12 @@ wxQTMediaBackend::wxQTMediaBackend()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxQTMediaBackend::~wxQTMediaBackend() wxQTMediaBackend::~wxQTMediaBackend()
{ {
if(m_movie) if (m_movie)
Cleanup(); Cleanup();
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
// Cleanup for moviecontroller // Cleanup for moviecontroller
if(m_mc) if (m_mc)
{ {
// destroy wxQTMediaEvtHandler we pushed on it // destroy wxQTMediaEvtHandler we pushed on it
m_ctrl->PopEventHandler(true); m_ctrl->PopEventHandler(true);
@@ -335,7 +318,7 @@ wxQTMediaBackend::~wxQTMediaBackend()
} }
#endif #endif
//Note that ExitMovies() is not necessary... // Note that ExitMovies() is not necessary...
ExitMovies(); ExitMovies();
} }
@@ -345,7 +328,9 @@ wxQTMediaBackend::~wxQTMediaBackend()
// 1) Intializes QuickTime // 1) Intializes QuickTime
// 2) Creates the control window // 2) Creates the control window
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, bool wxQTMediaBackend::CreateControl(
wxControl* ctrl,
wxWindow* parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
@@ -353,7 +338,7 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
//Don't bother in Native control mode // Don't bother in Native control mode
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
if (!IsQuickTime4Installed()) if (!IsQuickTime4Installed())
return false; return false;
@@ -361,19 +346,18 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
EnterMovies(); EnterMovies();
//
// Create window // Create window
// By default wxWindow(s) is created with a border - // By default wxWindow(s) is created with a border -
// so we need to get rid of those // so we need to get rid of those
// //
// Since we don't have a child window like most other // Since we don't have a child window like most other
// backends, we don't need wxCLIP_CHILDREN // backends, we don't need wxCLIP_CHILDREN
//
if ( !ctrl->wxControl::Create(parent, id, pos, size, if ( !ctrl->wxControl::Create(parent, id, pos, size,
wxWindow::MacRemoveBordersFromStyle(style), wxWindow::MacRemoveBordersFromStyle(style),
validator, name) validator, name))
) {
return false; return false;
}
#if wxUSE_VALIDATORS #if wxUSE_VALIDATORS
ctrl->SetValidator(validator); ctrl->SetValidator(validator);
@@ -392,10 +376,10 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
Boolean wxQTMediaBackend::IsQuickTime4Installed() Boolean wxQTMediaBackend::IsQuickTime4Installed()
{ {
short error; OSErr error;
long result; long result;
error = Gestalt (gestaltQuickTime, &result); error = Gestalt(gestaltQuickTime, &result);
return (error == noErr) && (((result >> 16) & 0xffff) >= 0x0400); return (error == noErr) && (((result >> 16) & 0xffff) >= 0x0400);
} }
#endif #endif
@@ -411,40 +395,42 @@ Boolean wxQTMediaBackend::IsQuickTime4Installed()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Load(const wxString& fileName) bool wxQTMediaBackend::Load(const wxString& fileName)
{ {
if(m_movie) if (m_movie)
Cleanup(); Cleanup();
OSErr err = noErr; OSErr err = noErr;
short movieResFile; short movieResFile;
FSSpec sfFile; FSSpec sfFile;
//FIXME:wxMacFilename2FSSpec crashes on empty string - // FIXME:wxMacFilename2FSSpec crashes on empty string -
//does it crash on other strings too and should this // does it crash on other strings too and should this
//"fix" be put in the carbon wxSound? // "fix" be put in the carbon wxSound?
if (fileName.empty()) if (fileName.empty())
return false; return false;
wxMacFilename2FSSpec( fileName , &sfFile ); wxMacFilename2FSSpec( fileName, &sfFile );
if (OpenMovieFile (&sfFile, &movieResFile, fsRdPerm) != noErr) if (OpenMovieFile( &sfFile, &movieResFile, fsRdPerm ) != noErr)
return false; return false;
short movieResID = 0; short movieResID = 0;
Str255 movieName; Str255 movieName;
bool result;
err = NewMovieFromFile ( err = NewMovieFromFile(
&m_movie, &m_movie,
movieResFile, movieResFile,
&movieResID, &movieResID,
movieName, movieName,
newMovieActive, newMovieActive,
NULL); //wasChanged NULL); // wasChanged
result = (err == noErr);
//No ::GetMoviesStickyError() here because it returns -2009 // No ::GetMoviesStickyError() here because it returns -2009
// a.k.a. invalid track on valid mpegs // a.k.a. invalid track on valid mpegs
if(err == noErr) if (result)
{ {
::CloseMovieFile (movieResFile); ::CloseMovieFile(movieResFile);
// Create movie controller/control // Create movie controller/control
#if wxUSE_CREATEMOVIECONTROL #if wxUSE_CREATEMOVIECONTROL
@@ -452,13 +438,11 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
#else #else
DoNewMovieController(); DoNewMovieController();
#endif #endif
FinishLoad(); FinishLoad();
return true;
}
else
{
return false;
} }
return result;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -500,28 +484,31 @@ void wxQTMediaBackend::PPRMProc (Movie theMovie,
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Load(const wxURI& location) bool wxQTMediaBackend::Load(const wxURI& location)
{ {
if(m_movie) if (m_movie)
Cleanup(); Cleanup();
wxString theURI = location.BuildURI(); wxString theURI = location.BuildURI();
OSErr err = noErr; OSErr err = noErr;
bool result;
// FIXME: lurking Unicode problem here
Handle theHandle = ::NewHandleClear(theURI.length() + 1); Handle theHandle = ::NewHandleClear(theURI.length() + 1);
wxASSERT(theHandle); 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 // create the movie from the handle that refers to the URI
err = ::NewMovieFromDataRef(&m_movie, newMovieActive | err = ::NewMovieFromDataRef(&m_movie, newMovieActive |
newMovieAsyncOK newMovieAsyncOK
/*|newMovieIdleImportOK*/, /* | newMovieIdleImportOK*/,
NULL, theHandle, NULL, theHandle,
URLDataHandlerSubType); URLDataHandlerSubType);
::DisposeHandle(theHandle); ::DisposeHandle(theHandle);
if (err == noErr) result = (err == noErr);
if (result)
{ {
#if wxUSE_CREATEMOVIECONTROL #if wxUSE_CREATEMOVIECONTROL
// Movie control resets prerolling, so we must create first // Movie control resets prerolling, so we must create first
@@ -543,7 +530,6 @@ bool wxQTMediaBackend::Load(const wxURI& location)
playRate = ::GetMoviePreferredRate(m_movie); playRate = ::GetMoviePreferredRate(m_movie);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
//
// Note that the callback here is optional, // Note that the callback here is optional,
// but without it PrePrerollMovie can be buggy // but without it PrePrerollMovie can be buggy
// (see Apple ml). Also, some may wonder // (see Apple ml). Also, some may wonder
@@ -552,14 +538,14 @@ bool wxQTMediaBackend::Load(const wxURI& location)
// require it if you don't use a Movie Controller, // require it if you don't use a Movie Controller,
// which we don't by default. // which we don't by default.
// //
::PrePrerollMovie(m_movie, timeNow, playRate, ::PrePrerollMovie(
m_movie, timeNow, playRate,
wxQTMediaBackend::PPRMProc, wxQTMediaBackend::PPRMProc,
(void*)this); (void*)this);
#endif #endif
return true;
} }
else
return false; return result;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -576,26 +562,25 @@ bool wxQTMediaBackend::Load(const wxURI& location)
#if wxUSE_CREATEMOVIECONTROL #if wxUSE_CREATEMOVIECONTROL
void wxQTMediaBackend::DoCreateMovieControl() void wxQTMediaBackend::DoCreateMovieControl()
{ {
// // Native CreateMovieControl QT control (Thanks to Kevin Olliver's
//Native CreateMovieControl QT control (Thanks to Kevin Olliver's // wxQTMovie for some of this).
//wxQTMovie for some of this). Rect bounds = wxMacGetBoundsForControl(
// m_ctrl,
Rect bounds = wxMacGetBoundsForControl(m_ctrl,
m_ctrl->GetPosition(), m_ctrl->GetPosition(),
m_ctrl->GetSize()); m_ctrl->GetSize());
//Dispose of old control for new one // Dispose of old control for new one
if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() ) if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() )
m_ctrl->m_peer->Dispose(); m_ctrl->m_peer->Dispose();
//Options- // Options:
//kMovieControlOptionXXX // kMovieControlOptionXXX
//HideController - hide the movie controller // HideController - hide the movie controller
//LocateTopLeft - movie is pinned to top left rather than centered in the control // LocateTopLeft - movie is pinned to top left rather than centered in the control
//EnableEditing - Allows programmatic editing and dragn'drop // EnableEditing - Allows programmatic editing and dragn'drop
//HandleEditingHI- Installs event stuff for edit menu - forces EnableEditing also // HandleEditingHI- Installs event stuff for edit menu - forces EnableEditing also
//SetKeysEnabled - Allows keyboard input // SetKeysEnabled - Allows keyboard input
//ManuallyIdled - app handles movie idling rather than internal timer event loop // ManuallyIdled - app handles movie idling rather than internal timer event loop
::CreateMovieControl( ::CreateMovieControl(
(WindowRef) (WindowRef)
m_ctrl->MacGetTopLevelWindowRef(), //parent m_ctrl->MacGetTopLevelWindowRef(), //parent
@@ -605,19 +590,19 @@ void wxQTMediaBackend::DoCreateMovieControl()
| kMovieControlOptionLocateTopLeft | kMovieControlOptionLocateTopLeft
| kMovieControlOptionSetKeysEnabled | kMovieControlOptionSetKeysEnabled
// | kMovieControlOptionManuallyIdled // | kMovieControlOptionManuallyIdled
, //flags , // flags
m_ctrl->m_peer->GetControlRefAddr() ); m_ctrl->m_peer->GetControlRefAddr() );
::EmbedControl(m_ctrl->m_peer->GetControlRef(), ::EmbedControl(
m_ctrl->m_peer->GetControlRef(),
(ControlRef)m_ctrl->GetParent()->GetHandle()); (ControlRef)m_ctrl->GetParent()->GetHandle());
// // set up MovieController for the new movie
// Setup MovieController for the new movie
//
long dataSize; long dataSize;
//Get movie controller from our control // Get movie controller from our control
::GetControlData( m_ctrl->m_peer->GetControlRef(), 0, ::GetControlData(
m_ctrl->m_peer->GetControlRef(), 0,
kMovieControlDataMovieController, kMovieControlDataMovieController,
sizeof(MovieController), (Ptr)&m_mc, &dataSize ); sizeof(MovieController), (Ptr)&m_mc, &dataSize );
@@ -637,12 +622,12 @@ void wxQTMediaBackend::DoCreateMovieControl()
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
void wxQTMediaBackend::DoNewMovieController() void wxQTMediaBackend::DoNewMovieController()
{ {
if(!m_mc) if (!m_mc)
{ {
// Get top level window ref for some mac functions // Get top level window ref for some mac functions
WindowRef wrTLW = (WindowRef) m_ctrl->MacGetTopLevelWindowRef(); WindowRef wrTLW = (WindowRef) m_ctrl->MacGetTopLevelWindowRef();
// MovieController not setup yet - // MovieController not setup yet:
// so we need to create a new one. // so we need to create a new one.
// You have to pass a valid movie to // You have to pass a valid movie to
// NewMovieController, evidently // NewMovieController, evidently
@@ -651,14 +636,16 @@ void wxQTMediaBackend::DoNewMovieController()
NULL); NULL);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
Rect bounds = wxMacGetBoundsForControl(m_ctrl, Rect bounds = wxMacGetBoundsForControl(
m_ctrl,
m_ctrl->GetPosition(), m_ctrl->GetPosition(),
m_ctrl->GetSize()); m_ctrl->GetSize());
m_mc = ::NewMovieController(m_movie, &bounds, mcTopLeftMovie | m_mc = ::NewMovieController(
//mcWithFrame | m_movie, &bounds,
mcNotVisible); mcTopLeftMovie | mcNotVisible /* | mcWithFrame */ );
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
::MCDoAction(m_mc, 32, (void*)true); //mcActionSetKeysEnabled ::MCDoAction(m_mc, 32, (void*)true); //mcActionSetKeysEnabled
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
@@ -668,13 +655,14 @@ void wxQTMediaBackend::DoNewMovieController()
wxQTMediaBackend::MCFilterProc, (long)this); wxQTMediaBackend::MCFilterProc, (long)this);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
//Part of a suggestion from Greg Hazel to repaint // Part of a suggestion from Greg Hazel to repaint
//movie when idle // movie when idle
m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this)); m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this));
// Event types to catch from the TLW // Event types to catch from the TLW
// for the moviecontroller // for the moviecontroller
EventTypeSpec theEventTypes[] = { EventTypeSpec theEventTypes[] =
{
{ kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseUp },
{ kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyDown },
@@ -685,7 +673,7 @@ void wxQTMediaBackend::DoNewMovieController()
{ kEventClassWindow, kEventWindowDeactivated } { kEventClassWindow, kEventWindowDeactivated }
}; };
// Catch window messages - // Catch window messages:
// if we do not do this and if the user clicks the play // if we do not do this and if the user clicks the play
// button on the controller, for instance, nothing will happen... // button on the controller, for instance, nothing will happen...
InstallWindowEventHandler( wrTLW, InstallWindowEventHandler( wrTLW,
@@ -695,13 +683,14 @@ void wxQTMediaBackend::DoNewMovieController()
} }
else else
{ {
// MovieController already created - // MovieController already created:
// Just change the movie in it and we're good to go // Just change the movie in it and we're good to go
Point thePoint; Point thePoint;
thePoint.h = thePoint.v = 0; thePoint.h = thePoint.v = 0;
::MCSetMovie(m_mc, m_movie, ::MCSetMovie(m_mc, m_movie,
(WindowRef)m_ctrl->MacGetTopLevelWindowRef(), (WindowRef)m_ctrl->MacGetTopLevelWindowRef(),
thePoint); thePoint);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
} }
} }
@@ -717,20 +706,20 @@ void wxQTMediaBackend::FinishLoad()
// get the real size of the movie // get the real size of the movie
DoLoadBestSize(); DoLoadBestSize();
// Show the player controls if the user wants to // show the player controls if the user wants to
if(m_interfaceflags) if (m_interfaceflags)
DoSetControllerVisible(m_interfaceflags); DoSetControllerVisible(m_interfaceflags);
//we want millisecond precision // we want millisecond precision
::SetMovieTimeScale(m_movie, 1000); ::SetMovieTimeScale(m_movie, 1000);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
// Start movie progress timer // start movie progress timer
m_timer = new wxQTMediaPlayTimer(m_movie, (wxQTMediaBackend*) this); m_timer = new wxQTMediaPlayTimer(m_movie, (wxQTMediaBackend*) this);
wxASSERT(m_timer); wxASSERT(m_timer);
m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
//send loaded event & refresh size // send loaded event & refresh size
NotifyMovieLoaded(); NotifyMovieLoaded();
} }
@@ -741,12 +730,12 @@ void wxQTMediaBackend::FinishLoad()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::DoLoadBestSize() void wxQTMediaBackend::DoLoadBestSize()
{ {
//get the real size of the movie // get the real size of the movie
Rect outRect; Rect outRect;
::GetMovieNaturalBoundsRect (m_movie, &outRect); ::GetMovieNaturalBoundsRect (m_movie, &outRect);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
//determine best size // determine best size
m_bestSize.x = outRect.right - outRect.left; m_bestSize.x = outRect.right - outRect.left;
m_bestSize.y = outRect.bottom - outRect.top; m_bestSize.y = outRect.bottom - outRect.top;
} }
@@ -759,14 +748,13 @@ void wxQTMediaBackend::DoLoadBestSize()
bool wxQTMediaBackend::Play() bool wxQTMediaBackend::Play()
{ {
Fixed fixRate = (Fixed) (wxQTMediaBackend::GetPlaybackRate() * 0x10000); Fixed fixRate = (Fixed) (wxQTMediaBackend::GetPlaybackRate() * 0x10000);
if(!fixRate) if (!fixRate)
fixRate = ::GetMoviePreferredRate(m_movie); fixRate = ::GetMoviePreferredRate(m_movie);
wxASSERT(fixRate != 0); wxASSERT(fixRate != 0);
if(!m_bPlaying) if (!m_bPlaying)
::MCDoAction( m_mc, 8, // mcActionPlay ::MCDoAction( m_mc, 8 /* mcActionPlay */, (void*) fixRate);
(void *) fixRate);
m_bPlaying = true; m_bPlaying = true;
return ::GetMoviesError() == noErr; return ::GetMoviesError() == noErr;
@@ -779,15 +767,16 @@ bool wxQTMediaBackend::Play()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Pause() bool wxQTMediaBackend::Pause()
{ {
//Stop the movie A.K.A. ::StopMovie(m_movie); // Stop the movie A.K.A. ::StopMovie(m_movie);
if(m_bPlaying) if (m_bPlaying)
{ {
::MCDoAction( m_mc, 8 /*mcActionPlay*/, ::MCDoAction( m_mc, 8 /*mcActionPlay*/, (void*) 0);
(void *) 0);
m_bPlaying = false; m_bPlaying = false;
return ::GetMoviesError() == noErr; return ::GetMoviesError() == noErr;
} }
return true; //already paused
// already paused
return true;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -798,7 +787,7 @@ bool wxQTMediaBackend::Pause()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Stop() bool wxQTMediaBackend::Stop()
{ {
if(!wxQTMediaBackend::Pause()) if (!wxQTMediaBackend::Pause())
return false; return false;
::GoToBeginningOfMovie(m_movie); ::GoToBeginningOfMovie(m_movie);
@@ -876,10 +865,10 @@ double wxQTMediaBackend::GetVolume()
{ {
short sVolume = ::GetMovieVolume(m_movie); short sVolume = ::GetMovieVolume(m_movie);
if(sVolume & (128 << 8)) //negative - no sound if (sVolume & (128 << 8)) //negative - no sound
return 0.0; return 0.0;
return sVolume/256.0; return sVolume / 256.0;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -924,7 +913,7 @@ wxMediaState wxQTMediaBackend::GetState()
// Could use // Could use
// GetMovieActive/IsMovieDone/SetMovieActive // GetMovieActive/IsMovieDone/SetMovieActive
// combo if implemented that way // combo if implemented that way
if (m_bPlaying == true) if (m_bPlaying)
return wxMEDIASTATE_PLAYING; return wxMEDIASTATE_PLAYING;
else if ( !m_movie || wxQTMediaBackend::GetPosition() == 0) else if ( !m_movie || wxQTMediaBackend::GetPosition() == 0)
return wxMEDIASTATE_STOPPED; return wxMEDIASTATE_STOPPED;
@@ -941,13 +930,13 @@ wxMediaState wxQTMediaBackend::GetState()
void wxQTMediaBackend::Cleanup() void wxQTMediaBackend::Cleanup()
{ {
m_bPlaying = false; m_bPlaying = false;
if(m_timer) if (m_timer)
{ {
delete m_timer; delete m_timer;
m_timer = NULL; m_timer = NULL;
} }
// Stop the movie // Stop the movie:
// Apple samples with CreateMovieControl typically // Apple samples with CreateMovieControl typically
// install a event handler and do this on the dispose // install a event handler and do this on the dispose
// event, but we do it here for simplicity // event, but we do it here for simplicity
@@ -955,9 +944,7 @@ void wxQTMediaBackend::Cleanup()
// control destruction if not) // control destruction if not)
wxQTMediaBackend::Pause(); wxQTMediaBackend::Pause();
//
// Dispose of control or remove movie from MovieController // Dispose of control or remove movie from MovieController
//
#if wxUSE_CREATEMOVIECONTROL #if wxUSE_CREATEMOVIECONTROL
if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() ) if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() )
m_ctrl->m_peer->Dispose(); m_ctrl->m_peer->Dispose();
@@ -969,6 +956,7 @@ void wxQTMediaBackend::Cleanup()
#endif #endif
::DisposeMovie(m_movie); ::DisposeMovie(m_movie);
m_movie = NULL;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -982,20 +970,24 @@ Boolean wxQTMediaBackend::MCFilterProc(
void * WXUNUSED(params), void * WXUNUSED(params),
long refCon) long refCon)
{ {
if(action != 1) //don't process idle events
{
wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon; wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon;
switch(action) switch (action)
{ {
case 8: //play button triggered - MC will set movie to opposite state case 1:
//of current - playing ? paused : playing // 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); pThis->m_bPlaying = !(pThis->m_bPlaying);
break; break;
default: default:
break; break;
} }
}
return 0; return 0;
} }
@@ -1018,7 +1010,7 @@ wxSize wxQTMediaBackend::GetVideoSize() const
void wxQTMediaBackend::Move(int x, int y, int w, int h) void wxQTMediaBackend::Move(int x, int y, int w, int h)
{ {
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
if(m_timer) if (m_timer)
{ {
m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y); m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y);
Rect theRect = {y, x, y+h, x+w}; Rect theRect = {y, x, y+h, x+w};
@@ -1027,7 +1019,7 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h)
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
} }
#else #else
if(m_timer && m_ctrl) if (m_timer && m_ctrl)
{ {
m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y); m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y);
@@ -1046,34 +1038,31 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags) void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags)
{ {
::MCSetVisible(m_mc, TRUE); ::MCSetVisible(m_mc, true);
//
// Take care of subcontrols // Take care of subcontrols
// if (::GetMoviesError() == noErr)
if(::GetMoviesError() == noErr)
{ {
long mcFlags = 0; long mcFlags = 0;
::MCDoAction(m_mc, 39/*mcActionGetFlags*/, (void*)&mcFlags); ::MCDoAction(m_mc, 39/*mcActionGetFlags*/, (void*)&mcFlags);
if(::GetMoviesError() == noErr) if (::GetMoviesError() == noErr)
{ {
mcFlags |= ( //(1<<0)/*mcFlagSuppressMovieFrame*/ | mcFlags |= ( //(1<<0)/*mcFlagSuppressMovieFrame*/ |
(1<<3)/*mcFlagsUseWindowPalette*/ (1 << 3)/*mcFlagsUseWindowPalette*/
| ((flags & wxMEDIACTRLPLAYERCONTROLS_STEP) | ((flags & wxMEDIACTRLPLAYERCONTROLS_STEP)
? 0 : (1<<1)/*mcFlagSuppressStepButtons*/) ? 0 : (1 << 1)/*mcFlagSuppressStepButtons*/)
| ((flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME) | ((flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME)
? 0 : (1<<2)/*mcFlagSuppressSpeakerButton*/) ? 0 : (1 << 2)/*mcFlagSuppressSpeakerButton*/)
// | (1<<4) /*mcFlagDontInvalidate*/ //if we take care of repainting ourselves // | (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
//Adjust height and width of best size for movie controller // if the user wants it shown
//if the user wants it shown
//
m_bestSize.x = m_bestSize.x > wxMCWIDTH ? m_bestSize.x : wxMCWIDTH; m_bestSize.x = m_bestSize.x > wxMCWIDTH ? m_bestSize.x : wxMCWIDTH;
m_bestSize.y += wxMCHEIGHT; m_bestSize.y += wxMCHEIGHT;
} }
@@ -1085,26 +1074,26 @@ void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags) bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
{ {
if(!m_mc) if (!m_mc)
return false; //no movie controller... return false; //no movie controller...
bool bSizeChanged = false; bool bSizeChanged = false;
//if the controller is visible and we want to hide it do so // if the controller is visible and we want to hide it do so
if(m_interfaceflags && !flags) if (m_interfaceflags && !flags)
{ {
bSizeChanged = true; bSizeChanged = true;
DoLoadBestSize(); 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; bSizeChanged = true;
DoSetControllerVisible(flags); DoSetControllerVisible(flags);
} }
//readjust parent sizers // readjust parent sizers
if(bSizeChanged) if (bSizeChanged)
{ {
NotifyMovieSizeChanged(); NotifyMovieSizeChanged();
@@ -1142,7 +1131,8 @@ void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
// messages to our moviecontroller so it can recieve mouse clicks etc. // messages to our moviecontroller so it can recieve mouse clicks etc.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#if !wxUSE_CREATEMOVIECONTROL #if !wxUSE_CREATEMOVIECONTROL
OSStatus wxQTMediaWindowEventHandler(EventHandlerCallRef inHandlerCallRef, OSStatus wxQTMediaWindowEventHandler(
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void *inUserData) EventRef inEvent, void *inUserData)
{ {
EventRecord theEvent; EventRecord theEvent;
@@ -1151,15 +1141,15 @@ OSStatus wxQTMediaWindowEventHandler(EventHandlerCallRef inHandlerCallRef,
err = ::MCIsPlayerEvent( (MovieController) inUserData, &theEvent ); err = ::MCIsPlayerEvent( (MovieController) inUserData, &theEvent );
// pass on to other event handlers if not handled- i.e. wx // pass on to other event handlers if not handled- i.e. wx
if(err) if (err != noErr)
return noErr; return noErr;
else else
return eventNotHandledErr; return eventNotHandledErr;
} }
#endif #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" #include "wx/html/forcelnk.h"
FORCE_LINK_ME(basewxmediabackends) FORCE_LINK_ME(basewxmediabackends)
#endif //wxUSE_MEDIACTRL #endif // wxUSE_MEDIACTRL