Ryan's patch 1468129 ,

1) Don't hog mouse events from other windows
2) Don't crash on mouse and other events when a bad file is loaded
3) Correctly detect whether a file can be loaded or not (Forgot to call ::ClearMoviesStickyError())
4) Real workaround for the wxNotebook issue (by using offscreen GWorld)
5) Nuke of CreateMovieControl version and many other cleanups


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38673 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2006-04-11 05:53:55 +00:00
parent 786a9df157
commit 0c81ef7fce
3 changed files with 271 additions and 307 deletions

View File

@@ -215,6 +215,7 @@ public:
bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy) bool LoadURIWithProxy(const wxString& fileName, const wxString& proxy)
{ return Load(wxURI(fileName), wxURI(proxy)); } { return Load(wxURI(fileName), wxURI(proxy)); }
#endif #endif
protected: protected:
static wxClassInfo* NextBackend(); static wxClassInfo* NextBackend();
@@ -224,6 +225,9 @@ protected:
//FIXME: This is nasty... find a better way to work around //FIXME: This is nasty... find a better way to work around
//inheritance issues //inheritance issues
#if defined(__WXMAC__)
virtual void MacVisibilityChanged();
#endif
#if defined(__WXMAC__) || defined(__WXCOCOA__) #if defined(__WXMAC__) || defined(__WXCOCOA__)
friend class wxQTMediaBackend; friend class wxQTMediaBackend;
#endif #endif
@@ -318,7 +322,8 @@ public:
virtual wxLongLong GetDownloadTotal() virtual wxLongLong GetDownloadTotal()
{ return 0; } { return 0; }
virtual void RESERVED8() {} virtual void MacVisibilityChanged()
{ }
virtual void RESERVED9() {} virtual void RESERVED9() {}
DECLARE_DYNAMIC_CLASS(wxMediaBackend) DECLARE_DYNAMIC_CLASS(wxMediaBackend)

View File

@@ -468,6 +468,19 @@ void wxMediaCtrl::DoMoveWindow(int x, int y, int w, int h)
m_imp->Move(x, y, w, h); m_imp->Move(x, y, w, h);
} }
//---------------------------------------------------------------------------
// wxMediaCtrl::MacVisibilityChanged
//---------------------------------------------------------------------------
#ifdef __WXMAC__
void wxMediaCtrl::MacVisibilityChanged()
{
wxControl::MacVisibilityChanged();
if(m_imp)
m_imp->MacVisibilityChanged();
}
#endif
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// //
// wxMediaBackendCommonBase // wxMediaBackendCommonBase

View File

@@ -5,20 +5,32 @@
// Modified by: // Modified by:
// Created: 11/07/04 // Created: 11/07/04
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2004-2005 Ryan Norton // Copyright: (c) 2004-2006 Ryan Norton
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// There are several known bugs with CreateMovieControl // OK, a casual overseer of this file may wonder why we don't use
// on systems > 10.2 - see main.c of QTCarbonShell sample for details // either CreateMovieControl or HIMovieView...
// //
// Also, with either version it will overdraw anything below its TLW - so // CreateMovieControl
// it's relatively useless on a notebook page (this happens in Opera too). // 1) Need to dispose and create each time a new movie is loaded
// 2) Not that many real advantages
// 3) Progressively buggier in higher OSX versions
// (see main.c of QTCarbonShell sample for details)
// HIMovieView
// 1) Crashes on destruction in ALL cases on quite a few systems!
// (With the only real "alternative" is to simply not
// dispose of it and let it leak...)
// 2) Massive refreshing bugs with its movie controller between
// movies
// //
// Even though though the CreateMovieControl version is the default // At one point we had a complete implementation for CreateMovieControl
// for OSX, the MovieController version is heavily tested and works // and on my (RN) local copy I had one for HIMovieView - but they
// just as well... // were simply deemed to be too buggy/unuseful. HIMovieView could
// have been useful as well because it uses OpenGL contexts instead
// of GWorlds. Perhaps someday when someone comes out with some
// ingenious workarounds :).
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
@@ -30,8 +42,8 @@
#include "wx/mac/uma.h" #include "wx/mac/uma.h"
#include "wx/timer.h" #include "wx/timer.h"
#ifndef __DARWIN__
// standard QT stuff // standard QT stuff
#ifndef __DARWIN__
#include <Movies.h> #include <Movies.h>
#include <Gestalt.h> #include <Gestalt.h>
#include <QuickTimeComponents.h> #include <QuickTimeComponents.h>
@@ -42,20 +54,7 @@
#if wxUSE_MEDIACTRL #if wxUSE_MEDIACTRL
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Whether or not to use OSX 10.2's CreateMovieControl for native QuickTime // Height and Width of movie controller in the movie control (apple samples)
// control - i.e. native positioning and event handling etc..
//---------------------------------------------------------------------------
#ifndef wxUSE_CREATEMOVIECONTROL
# if defined( __WXMAC_OSX__ ) && \
( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
# define wxUSE_CREATEMOVIECONTROL 1
# else
# define wxUSE_CREATEMOVIECONTROL 0
# endif
#endif
//---------------------------------------------------------------------------
// Height and Width of movie controller in the movie control
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#define wxMCWIDTH 320 #define wxMCWIDTH 320
#define wxMCHEIGHT 16 #define wxMCHEIGHT 16
@@ -68,7 +67,6 @@
// wxQTMediaBackend // wxQTMediaBackend
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase
{ {
public: public:
@@ -83,13 +81,13 @@ public:
const wxValidator& validator, const wxValidator& validator,
const wxString& name); const wxString& name);
virtual bool Load(const wxString& fileName);
virtual bool Load(const wxURI& location);
virtual bool Play(); virtual bool Play();
virtual bool Pause(); virtual bool Pause();
virtual bool Stop(); virtual bool Stop();
virtual bool Load(const wxString& fileName);
virtual bool Load(const wxURI& location);
virtual wxMediaState GetState(); virtual wxMediaState GetState();
virtual bool SetPosition(wxLongLong where); virtual bool SetPosition(wxLongLong where);
@@ -113,6 +111,8 @@ public:
virtual wxLongLong GetDownloadProgress(); virtual wxLongLong GetDownloadProgress();
virtual wxLongLong GetDownloadTotal(); virtual wxLongLong GetDownloadTotal();
virtual void MacVisibilityChanged();
// //
// ------ Implementation from now on -------- // ------ Implementation from now on --------
// //
@@ -124,44 +124,41 @@ public:
wxLongLong GetDataSizeFromStart(TimeValue end); wxLongLong GetDataSizeFromStart(TimeValue end);
Boolean IsQuickTime4Installed();
void DoNewMovieController();
static pascal void PPRMProc(
Movie theMovie, OSErr theErr, void* theRefCon);
//TODO: Last param actually long - does this work on 64bit machines? //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); short action, void *params, long refCon);
#if wxUSE_CREATEMOVIECONTROL static pascal OSStatus WindowEventHandler(
void DoCreateMovieControl(); EventHandlerCallRef inHandlerCallRef,
#else EventRef inEvent, void *inUserData );
Boolean IsQuickTime4Installed();
void DoNewMovieController();
static pascal void PPRMProc(Movie theMovie, OSErr theErr, void* theRefCon);
#endif
wxSize m_bestSize; // Original movie size wxSize m_bestSize; // Original movie size
#ifdef __WXMAC_OSX__
struct MovieType** m_movie; // QT Movie handle/instance
#else
Movie m_movie; // Movie instance Movie m_movie; // Movie instance
#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 // Event handlers and UPPs/Callbacks
EventHandlerRef m_pEventHandlerRef; // Event handler to cleanup EventHandlerRef m_windowEventHandler;
EventHandlerUPP m_windowUPP;
MoviePrePrerollCompleteUPP m_preprerollupp; MoviePrePrerollCompleteUPP m_preprerollupp;
EventHandlerUPP m_eventupp;
MCActionFilterWithRefConUPP m_mcactionupp; MCActionFilterWithRefConUPP m_mcactionupp;
GWorldPtr m_movieWorld; //Offscreen movie GWorld
friend class wxQTMediaEvtHandler; friend class wxQTMediaEvtHandler;
#endif
DECLARE_DYNAMIC_CLASS(wxQTMediaBackend) DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
}; };
#if !wxUSE_CREATEMOVIECONTROL
// helper to hijack background erasing for the QT window // helper to hijack background erasing for the QT window
class WXDLLIMPEXP_MEDIA wxQTMediaEvtHandler : public wxEvtHandler class WXDLLIMPEXP_MEDIA wxQTMediaEvtHandler : public wxEvtHandler
{ {
@@ -184,20 +181,15 @@ private:
DECLARE_NO_COPY_CLASS(wxQTMediaEvtHandler) DECLARE_NO_COPY_CLASS(wxQTMediaEvtHandler)
}; };
// Window event handler
static pascal OSStatus wxQTMediaWindowEventHandler(
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void *inUserData);
#endif
//=========================================================================== //===========================================================================
// IMPLEMENTATION // IMPLEMENTATION
//=========================================================================== //===========================================================================
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxQTMediaBackend // wxQTMediaBackend
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend) IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
@@ -218,21 +210,17 @@ IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
class wxQTMediaLoadTimer : public wxTimer class wxQTMediaLoadTimer : public wxTimer
{ {
public: public:
wxQTMediaLoadTimer(Movie movie, wxQTMediaBackend* parent) : wxQTMediaLoadTimer(wxQTMediaBackend* parent) :
m_movie(movie), m_parent(parent) {} m_parent(parent) {}
void Notify() void Notify()
{ {
// Note that the CreateMovieControl variety performs
// its own custom idling
#if !wxUSE_CREATEMOVIECONTROL
::MCIdle(m_parent->m_mc); ::MCIdle(m_parent->m_mc);
#endif
// kMovieLoadStatePlayable is not enough on MAC: // kMovieLoadStatePlayable is not enough on MAC:
// it plays, but IsMovieDone might return true (!) // it plays, but IsMovieDone might return true (!)
// sure we need to wait until kMovieLoadStatePlaythroughOK // sure we need to wait until kMovieLoadStatePlaythroughOK
if (::GetMovieLoadState(m_movie) >= 20000) if (::GetMovieLoadState(m_parent->m_movie) >= 20000)
{ {
m_parent->FinishLoad(); m_parent->FinishLoad();
delete this; delete this;
@@ -240,7 +228,6 @@ public:
} }
protected: protected:
Movie m_movie; // Our movie instance
wxQTMediaBackend *m_parent; // Backend pointer wxQTMediaBackend *m_parent; // Backend pointer
}; };
@@ -255,13 +242,11 @@ protected:
class wxQTMediaPlayTimer : public wxTimer class wxQTMediaPlayTimer : public wxTimer
{ {
public: public:
wxQTMediaPlayTimer(Movie movie, wxQTMediaBackend* parent) : wxQTMediaPlayTimer(wxQTMediaBackend* parent) :
m_movie(movie), m_parent(parent) {} m_parent(parent) {}
void Notify() void Notify()
{ {
//Note that CreateMovieControl performs its own idleing
#if !wxUSE_CREATEMOVIECONTROL
// //
// OK, a little explaining - basically originally // OK, a little explaining - basically originally
// we only called MoviesTask if the movie was actually // we only called MoviesTask if the movie was actually
@@ -275,11 +260,12 @@ public:
// correctly. // correctly.
// //
::MCIdle(m_parent->m_mc); ::MCIdle(m_parent->m_mc);
#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_parent->m_movie))
{ {
if ( m_parent->SendStopEvent() ) if ( m_parent->SendStopEvent() )
{ {
@@ -292,7 +278,6 @@ public:
} }
protected: protected:
Movie m_movie; // Our movie instance
wxQTMediaBackend* m_parent; // Backend pointer wxQTMediaBackend* m_parent; // Backend pointer
}; };
@@ -305,9 +290,7 @@ protected:
wxQTMediaBackend::wxQTMediaBackend() wxQTMediaBackend::wxQTMediaBackend()
: m_movie(NULL), m_bPlaying(false), m_timer(NULL) : m_movie(NULL), m_bPlaying(false), m_timer(NULL)
, m_mc(NULL), m_interfaceflags(wxMEDIACTRLPLAYERCONTROLS_NONE) , m_mc(NULL), m_interfaceflags(wxMEDIACTRLPLAYERCONTROLS_NONE)
#if !wxUSE_CREATEMOVIECONTROL , m_preprerollupp(NULL), m_movieWorld(NULL)
, m_preprerollupp(NULL)
#endif
{ {
} }
@@ -325,20 +308,22 @@ wxQTMediaBackend::~wxQTMediaBackend()
if (m_movie) if (m_movie)
Cleanup(); Cleanup();
#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);
RemoveEventHandler((EventHandlerRef&)m_pEventHandlerRef); RemoveEventHandler(m_windowEventHandler);
DisposeEventHandlerUPP(m_eventupp); DisposeEventHandlerUPP(m_windowUPP);
// Dispose of the movie controller // Dispose of the movie controller
::DisposeMovieController(m_mc); ::DisposeMovieController(m_mc);
m_mc = NULL;
DisposeMCActionFilterWithRefConUPP(m_mcactionupp); DisposeMCActionFilterWithRefConUPP(m_mcactionupp);
// Dispose of offscreen GWorld
::DisposeGWorld(m_movieWorld);
} }
#endif
// Note that ExitMovies() is not necessary... // Note that ExitMovies() is not necessary...
ExitMovies(); ExitMovies();
@@ -360,21 +345,22 @@ bool wxQTMediaBackend::CreateControl(
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
// Don't bother in Native control mode
#if !wxUSE_CREATEMOVIECONTROL
if (!IsQuickTime4Installed()) if (!IsQuickTime4Installed())
return false; return false;
#endif
EnterMovies(); EnterMovies();
wxMediaCtrl* mediactrl = (wxMediaCtrl*)ctrl;
//
// 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( //
if ( !mediactrl->wxControl::Create(
parent, id, pos, size, parent, id, pos, size,
wxWindow::MacRemoveBordersFromStyle(style), wxWindow::MacRemoveBordersFromStyle(style),
validator, name)) validator, name))
@@ -383,10 +369,10 @@ bool wxQTMediaBackend::CreateControl(
} }
#if wxUSE_VALIDATORS #if wxUSE_VALIDATORS
ctrl->SetValidator(validator); mediactrl->SetValidator(validator);
#endif #endif
m_ctrl = (wxMediaCtrl*)ctrl; m_ctrl = mediactrl;
return true; return true;
} }
@@ -396,7 +382,6 @@ bool wxQTMediaBackend::CreateControl(
// Determines whether version 4 of QT is installed // Determines whether version 4 of QT is installed
// (Pretty much for Classic only) // (Pretty much for Classic only)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#if !wxUSE_CREATEMOVIECONTROL
Boolean wxQTMediaBackend::IsQuickTime4Installed() Boolean wxQTMediaBackend::IsQuickTime4Installed()
{ {
OSErr error; OSErr error;
@@ -405,7 +390,6 @@ Boolean wxQTMediaBackend::IsQuickTime4Installed()
error = Gestalt(gestaltQuickTime, &result); error = Gestalt(gestaltQuickTime, &result);
return (error == noErr) && (((result >> 16) & 0xffff) >= 0x0400); return (error == noErr) && (((result >> 16) & 0xffff) >= 0x0400);
} }
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Load (file version) // wxQTMediaBackend::Load (file version)
@@ -421,23 +405,19 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
if (m_movie) if (m_movie)
Cleanup(); Cleanup();
::ClearMoviesStickyError(); // clear previous errors so
// GetMoviesStickyError is useful
OSErr err = noErr; OSErr err = noErr;
short movieResFile; short movieResFile;
FSSpec sfFile; 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?
if (fileName.empty())
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,
@@ -447,53 +427,26 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
newMovieActive, newMovieActive,
NULL); // wasChanged NULL); // wasChanged
// No ::GetMoviesStickyError() here because it returns -2009 //
// a.k.a. invalid track on valid mpegs // check GetMoviesStickyError() because it may not find the
result = (err == noErr); // proper codec and play black video and other strange effects,
if (result) // not to mention mess up the dynamic backend loading scheme
// of wxMediaCtrl - so it just does what the QuickTime player does
//
if (err == noErr && ::GetMoviesStickyError() == noErr)
{ {
::CloseMovieFile(movieResFile); ::CloseMovieFile(movieResFile);
// Create movie controller/control // Create movie controller/control
#if wxUSE_CREATEMOVIECONTROL
DoCreateMovieControl();
#else
DoNewMovieController(); DoNewMovieController();
#endif
FinishLoad(); FinishLoad();
return true;
} }
return result; return false;
} }
//---------------------------------------------------------------------------
// wxQTMediaBackend::PPRMProc (static)
//
// Called when done PrePrerolling the movie.
// Note that in 99% of the cases this does nothing...
// 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)
{
wxASSERT( theMovie );
wxASSERT( theRefCon );
wxASSERT( theErr == noErr );
wxQTMediaBackend* pBE = (wxQTMediaBackend*) theRefCon;
long lTime = ::GetMovieTime(theMovie,NULL);
Fixed rate = ::GetMoviePreferredRate(theMovie);
::PrerollMovie(theMovie,lTime,rate);
pBE->m_timer = new wxQTMediaLoadTimer(pBE->m_movie, pBE);
pBE->m_timer->Start(MOVIE_DELAY);
}
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Load (URL Version) // wxQTMediaBackend::Load (URL Version)
// //
@@ -510,16 +463,27 @@ bool wxQTMediaBackend::Load(const wxURI& location)
if (m_movie) if (m_movie)
Cleanup(); Cleanup();
::ClearMoviesStickyError(); // clear previous errors so
// GetMoviesStickyError is useful
wxString theURI = location.BuildURI(); wxString theURI = location.BuildURI();
OSErr err;
OSErr err = noErr; size_t len;
bool result; const char* theURIString;
// FIXME: lurking Unicode problem here #if wxUSE_UNICODE
Handle theHandle = ::NewHandleClear(theURI.length() + 1); wxCharBuffer buf = wxConvLocal.cWC2MB(theURI, theURI.length(), &len);
theURIString = buf;
#else
theURIString = theURI;
len = theURI.length();
#endif
Handle theHandle = ::NewHandleClear(len + 1);
wxASSERT(theHandle); wxASSERT(theHandle);
::BlockMoveData(theURI.mb_str(), *theHandle, theURI.length() + 1); ::BlockMoveData(theURIString, *theHandle, len + 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( err = ::NewMovieFromDataRef(
@@ -530,18 +494,8 @@ bool wxQTMediaBackend::Load(const wxURI& location)
::DisposeHandle(theHandle); ::DisposeHandle(theHandle);
result = (err == noErr); if (err == noErr && ::GetMoviesStickyError() == noErr)
if (result)
{ {
#if wxUSE_CREATEMOVIECONTROL
// Movie control does its own "(pre)prerolling"
// 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(); DoNewMovieController();
@@ -554,6 +508,7 @@ 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
@@ -562,85 +517,23 @@ 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.
// //
m_preprerollupp = NewMoviePrePrerollCompleteUPP( wxQTMediaBackend::PPRMProc ); m_preprerollupp =
::PrePrerollMovie( m_movie, timeNow, playRate, m_preprerollupp, (void*)this); NewMoviePrePrerollCompleteUPP( wxQTMediaBackend::PPRMProc );
#endif ::PrePrerollMovie( m_movie, timeNow, playRate,
m_preprerollupp, (void*)this);
return true;
} }
return result; return false;
} }
//---------------------------------------------------------------------------
// wxQTMediaBackend::DoCreateMovieControl
//
// Calls CreateMovieControl and performs setup related to it
//
// Note that we always hide the controller initially becuase when loading
// from a url it displays about a 40x40 box with the word loading... in it,
// but the box is outside the range of the control, which is bad (0,0
// i believe), so we need to wait until finishload to actually display
// the movie controller in this instance
//---------------------------------------------------------------------------
#if wxUSE_CREATEMOVIECONTROL
void wxQTMediaBackend::DoCreateMovieControl()
{
// 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// 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 );
// Setup a callback so we can tell when the user presses
// play on the player controls
::MCSetActionFilterWithRefCon(m_mc,
(MCActionFilterWithRefConUPP)wxQTMediaBackend::MCFilterProc,
(long)this);
}
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::DoNewMovieController // wxQTMediaBackend::DoNewMovieController
// //
// Attaches movie to moviecontroller or creates moviecontroller // Attaches movie to moviecontroller or creates moviecontroller
// if not created yet // if not created yet
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#if !wxUSE_CREATEMOVIECONTROL
void wxQTMediaBackend::DoNewMovieController() void wxQTMediaBackend::DoNewMovieController()
{ {
if (!m_mc) if (!m_mc)
@@ -670,16 +563,24 @@ void wxQTMediaBackend::DoNewMovieController()
// Setup a callback so we can tell when the user presses // Setup a callback so we can tell when the user presses
// play on the player controls // play on the player controls
m_mcactionupp = NewMCActionFilterWithRefConUPP( wxQTMediaBackend::MCFilterProc ); m_mcactionupp =
NewMCActionFilterWithRefConUPP( wxQTMediaBackend::MCFilterProc );
::MCSetActionFilterWithRefCon( m_mc, m_mcactionupp, (long)this ); ::MCSetActionFilterWithRefCon( m_mc, m_mcactionupp, (long)this );
wxASSERT(::GetMoviesError() == noErr); 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)); m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this));
// Event types to catch from the TLW // Create offscreen GWorld for where to "show" when window is hidden
// for the moviecontroller Rect worldRect;
EventTypeSpec theEventTypes[] = worldRect.left = worldRect.top = 0;
worldRect.right = worldRect.bottom = 1;
::NewGWorld(&m_movieWorld, 0, &worldRect, NULL, NULL, 0);
// 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...
EventTypeSpec theWindowEventTypes[] =
{ {
{ kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseUp },
@@ -691,16 +592,14 @@ void wxQTMediaBackend::DoNewMovieController()
{ kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowDeactivated } { kEventClassWindow, kEventWindowDeactivated }
}; };
m_windowUPP =
// Catch window messages: NewEventHandlerUPP( wxQTMediaBackend::WindowEventHandler );
// 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( InstallWindowEventHandler(
wrTLW, wrTLW,
m_eventupp, m_windowUPP,
GetEventTypeCount( theEventTypes ), theEventTypes, GetEventTypeCount( theWindowEventTypes ), theWindowEventTypes,
m_mc, (&(EventHandlerRef&)m_pEventHandlerRef) ); this,
&m_windowEventHandler );
} }
else else
{ {
@@ -714,7 +613,6 @@ void wxQTMediaBackend::DoNewMovieController()
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
} }
} }
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::FinishLoad // wxQTMediaBackend::FinishLoad
@@ -724,9 +622,7 @@ void wxQTMediaBackend::DoNewMovieController()
void wxQTMediaBackend::FinishLoad() 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); DisposeMoviePrePrerollCompleteUPP(m_preprerollupp);
#endif
// get the real size of the movie // get the real size of the movie
DoLoadBestSize(); DoLoadBestSize();
@@ -740,7 +636,7 @@ void wxQTMediaBackend::FinishLoad()
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(this);
wxASSERT(m_timer); wxASSERT(m_timer);
m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
@@ -965,7 +861,7 @@ wxMediaState wxQTMediaBackend::GetState()
// combo if implemented that way // combo if implemented that way
if (m_bPlaying) 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;
else else
return wxMEDIASTATE_PAUSED; return wxMEDIASTATE_PAUSED;
@@ -995,52 +891,15 @@ void wxQTMediaBackend::Cleanup()
wxQTMediaBackend::Pause(); wxQTMediaBackend::Pause();
// Dispose of control or remove movie from MovieController // 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();
#else
Point thePoint; Point thePoint;
thePoint.h = thePoint.v = 0; thePoint.h = thePoint.v = 0;
::MCSetVisible(m_mc, false); ::MCSetVisible(m_mc, false);
::MCSetMovie(m_mc, NULL, NULL, thePoint); ::MCSetMovie(m_mc, NULL, NULL, thePoint);
#endif
::DisposeMovie(m_movie); ::DisposeMovie(m_movie);
m_movie = NULL; m_movie = NULL;
} }
//---------------------------------------------------------------------------
// wxQTMediaBackend::MCFilterProc (static)
//
// Callback for when the movie controller recieves a message
//---------------------------------------------------------------------------
pascal Boolean wxQTMediaBackend::MCFilterProc(
MovieController WXUNUSED(theController),
short action,
void * WXUNUSED(params),
long refCon)
{
wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon;
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;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::GetVideoSize // wxQTMediaBackend::GetVideoSize
// //
@@ -1066,14 +925,12 @@ 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 (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};
#if 0 #if 0 // see note above
// see note above
::MCSetControllerAttached(m_mc, false); ::MCSetControllerAttached(m_mc, false);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
#endif #endif
@@ -1089,16 +946,6 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h)
} }
#endif #endif
} }
#else
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();
}
#endif
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -1107,7 +954,8 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h)
// Utility function that takes care of showing the moviecontroller // Utility function that takes care of showing the moviecontroller
// and showing/hiding the particular controls on it // and showing/hiding the particular controls on it
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags) void wxQTMediaBackend::DoSetControllerVisible(
wxMediaCtrlPlayerControls flags)
{ {
::MCSetVisible(m_mc, true); ::MCSetVisible(m_mc, true);
@@ -1125,7 +973,8 @@ void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags)
? 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 //if we take care of repainting ourselves
// | (1 << 4) /*mcFlagDontInvalidate*/
); );
::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags); ::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags);
@@ -1221,7 +1070,52 @@ wxLongLong wxQTMediaBackend::GetDownloadProgress()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxLongLong wxQTMediaBackend::GetDownloadTotal() wxLongLong wxQTMediaBackend::GetDownloadTotal()
{ {
return wxQTMediaBackend::GetDataSizeFromStart( ::GetMovieDuration(m_movie) ); return wxQTMediaBackend::GetDataSizeFromStart(
::GetMovieDuration(m_movie)
);
}
//---------------------------------------------------------------------------
// wxQTMediaBackend::MacVisibilityChanged
//
// The main problem here is that Windows quicktime, for example,
// renders more directly to a HWND. Mac quicktime does not do this
// and instead renders to the port of the WindowRef/WindowPtr on top
// of everything else/all other windows.
//
// So, for example, if you were to have a CreateTabsControl/wxNotebook
// and change pages, even if you called HIViewSetVisible/SetControlVisibility
// directly the movie will still continue playing on top of everything else
// if you went to a different tab.
//
// Note that another issue, and why we call MCSetControllerPort instead
// of SetMovieGWorld directly, is that in addition to rendering on
// top of everything else the last created controller steals mouse and
// other input from everything else in the window, including other
// controllers. Setting the port of it releases this behaviour.
//---------------------------------------------------------------------------
void wxQTMediaBackend::MacVisibilityChanged()
{
if(!m_mc || !m_ctrl->m_bLoaded)
return; //not initialized yet
if(m_ctrl->MacIsReallyShown())
{
//The window is being shown again, so set the GWorld of the
//controller back to the port of the parent WindowRef
WindowRef wrTLW =
(WindowRef) m_ctrl->MacGetTopLevelWindowRef();
::MCSetControllerPort(m_mc, (CGrafPtr) GetWindowPort(wrTLW));
wxASSERT(::GetMoviesError() == noErr);
}
else
{
//We are being hidden - set the GWorld of the controller
//to the offscreen GWorld
::MCSetControllerPort(m_mc, m_movieWorld);
wxASSERT(::GetMoviesError() == noErr);
}
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -1230,61 +1124,113 @@ wxLongLong wxQTMediaBackend::GetDownloadTotal()
// Suggestion from Greg Hazel to repaint the movie when idle // Suggestion from Greg Hazel to repaint the movie when idle
// (on pause also) // (on pause also)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#if !wxUSE_CREATEMOVIECONTROL
void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt) 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 // 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); RgnHandle region = ::MCGetControllerBoundsRgn(m_qtb->m_mc);
MCInvalidate(m_qtb->m_mc, wrTLW, region); ::MCInvalidate(m_qtb->m_mc, wrTLW, region);
MCIdle(m_qtb->m_mc); ::MCIdle(m_qtb->m_mc);
} }
#endif
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaWindowEventHandler // wxQTMediaBackend::PPRMProc (static)
//
// Called when done PrePrerolling the movie.
// Note that in 99% of the cases this does nothing...
// Anyway we set up the loading timer here to tell us when the movie is done
//---------------------------------------------------------------------------
pascal void wxQTMediaBackend::PPRMProc(
Movie theMovie,
OSErr WXUNUSED_UNLESS_DEBUG(theErr),
void* theRefCon)
{
wxASSERT( theMovie );
wxASSERT( theRefCon );
wxASSERT( theErr == noErr );
wxQTMediaBackend* pBE = (wxQTMediaBackend*) theRefCon;
long lTime = ::GetMovieTime(theMovie,NULL);
Fixed rate = ::GetMoviePreferredRate(theMovie);
::PrerollMovie(theMovie,lTime,rate);
pBE->m_timer = new wxQTMediaLoadTimer(pBE);
pBE->m_timer->Start(MOVIE_DELAY);
}
//---------------------------------------------------------------------------
// wxQTMediaBackend::MCFilterProc (static)
//
// Callback for when the movie controller recieves a message
//---------------------------------------------------------------------------
pascal Boolean wxQTMediaBackend::MCFilterProc(
MovieController WXUNUSED(theController),
short action,
void * WXUNUSED(params),
long refCon)
{
wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon;
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;
}
//---------------------------------------------------------------------------
// wxQTMediaBackend::WindowEventHandler [static]
// //
// Event callback for the top level window of our control that passes // Event callback for the top level window of our control that passes
// messages to our moviecontroller so it can receive mouse clicks etc. // messages to our moviecontroller so it can receive mouse clicks etc.
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#if !wxUSE_CREATEMOVIECONTROL pascal OSStatus wxQTMediaBackend::WindowEventHandler(
static pascal OSStatus wxQTMediaWindowEventHandler(
EventHandlerCallRef inHandlerCallRef, EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, EventRef inEvent,
void *inUserData) void *inUserData)
{ {
// for the overly paranoid.... wxQTMediaBackend* be = (wxQTMediaBackend*) inUserData;
#if 0
UInt32 eventClass = GetEventClass( eventRef ); // Only process keyboard messages on this window if it actually
UInt32 eventKind = GetEventKind( inEvent ); // has focus, otherwise it will steal keystrokes from other windows!
// As well as when it is not loaded properly as it
if (eventKind != kEventMouseDown && // will crash in MCIsPlayerEvent
eventKind != kEventMouseUp && if((GetEventClass(inEvent) == kEventClassKeyboard &&
eventKind != kEventMouseDragged && wxWindow::FindFocus() != be->m_ctrl)
eventKind != kEventRawKeyDown && || !be->m_ctrl->m_bLoaded)
eventKind != kEventRawKeyRepeat &&
eventKind != kEventRawKeyUp &&
eventKind != kEventWindowUpdate &&
eventKind != kEventWindowActivated &&
eventKind != kEventWindowDeactivated)
return eventNotHandledErr; return eventNotHandledErr;
#endif
// Pass the event onto the movie controller
EventRecord theEvent; EventRecord theEvent;
ConvertEventRefToEventRecord( inEvent, &theEvent ); ConvertEventRefToEventRecord( inEvent, &theEvent );
OSStatus err; OSStatus err;
err = ::MCIsPlayerEvent( (MovieController) inUserData, &theEvent ); // TODO: Apple says MCIsPlayerEvent is depreciated and
// MCClick, MCKey, MCIdle etc. should be used
// (RN: Of course that's what they say about
// CreateMovieControl and HIMovieView as well, LOL!)
err = ::MCIsPlayerEvent( be->m_mc, &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 != noErr) if (err != noErr)
return noErr; return noErr;
else else
return eventNotHandledErr; 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" #include "wx/html/forcelnk.h"