CreateMovieControl change for wxMediaCtrl on OSX 10.2 and up

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31721 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
2005-02-03 11:11:36 +00:00
parent 3aa79a0117
commit 3b5023b99a
3 changed files with 118 additions and 31 deletions

View File

@@ -32,7 +32,7 @@ wxMediaCtrl is not currently available on unix systems.
\membersection{Rendering media}\label{renderingmediawxmediactrl} \membersection{Rendering media}\label{renderingmediawxmediactrl}
wxMediaCtrl can generally, depending upon the backend, render Depending upon the backend, wxMediaCtrl can render
and display pretty much any kind of media that the native system can - and display pretty much any kind of media that the native system can -
such as an image, mpeg video, or mp3 (without license restrictions - such as an image, mpeg video, or mp3 (without license restrictions -
sense it relies on native system calls that may not technically sense it relies on native system calls that may not technically
@@ -104,7 +104,7 @@ Use ActiveMovie/DirectShow. Requires wxUSE\_DIRECTSHOW to be
enabled, requires linkage with the static library strmiids.lib, enabled, requires linkage with the static library strmiids.lib,
and is available on Windows Only.} and is available on Windows Only.}
\twocolitem{{\bf wxMEDIABACKEND\_QUICKTIME}}{ \twocolitem{{\bf wxMEDIABACKEND\_QUICKTIME}}{
Use QuickTime. Windows and Mac Only. } Use QuickTime. Windows and Mac Only. WARNING: On Mac Systems lower than OSX 10.2 this defaults to emulating window positioning and suffers from several bugs, including not working correctly embedded in a wxNotebook. }
\twocolitem{{\bf wxMEDIABACKEND\_MCI}}{ \twocolitem{{\bf wxMEDIABACKEND\_MCI}}{
Use Media Command Interface. Windows Only. } Use Media Command Interface. Windows Only. }
\end{twocollist} \end{twocollist}

View File

@@ -190,6 +190,9 @@ protected:
virtual void DoMoveWindow(int x, int y, int w, int h); virtual void DoMoveWindow(int x, int y, int w, int h);
wxSize DoGetBestSize() const; wxSize DoGetBestSize() const;
#ifdef __WXMAC__
friend class wxMediaBackend;
#endif
class wxMediaBackend* m_imp; class wxMediaBackend* m_imp;
bool m_bLoaded; bool m_bLoaded;
bool m_bLoop; bool m_bLoop;
@@ -256,6 +259,11 @@ public:
virtual wxMediaState GetState() virtual wxMediaState GetState()
{ return wxMEDIASTATE_STOPPED; } { return wxMEDIASTATE_STOPPED; }
#ifdef __WXMAC__
wxMacControl* GetControlPeer(wxControl* ctrl)
{ return ((wxMediaCtrl*)ctrl)->m_peer; }
#endif
DECLARE_CLASS(wxMediaBackend) DECLARE_CLASS(wxMediaBackend)
}; };

View File

@@ -5,7 +5,7 @@
// Modified by: // Modified by:
// Created: 11/07/04 // Created: 11/07/04
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Ryan Norton // Copyright: (c) 2004-2005 Ryan Norton, portions (c) 2004 Kevin Olliver
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -38,6 +38,18 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#if wxUSE_MEDIACTRL #if wxUSE_MEDIACTRL
//---------------------------------------------------------------------------
// Whether or not to use OSX 10.2's CreateMovieControl for native QuickTime
// 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
//=========================================================================== //===========================================================================
// BACKEND DECLARATIONS // BACKEND DECLARATIONS
//=========================================================================== //===========================================================================
@@ -58,7 +70,7 @@
#include <Gestalt.h> #include <Gestalt.h>
#include <QuickTimeComponents.h> //Standard QT stuff #include <QuickTimeComponents.h> //Standard QT stuff
//Determines whether version 6 of QT is installed //Determines whether version 4 of QT is installed (Pretty much for classic only)
Boolean _wxIsQuickTime4Installed (void) Boolean _wxIsQuickTime4Installed (void)
{ {
short error; short error;
@@ -119,8 +131,6 @@ public:
// //
// wxQTMediaBackend // wxQTMediaBackend
// //
// TODO: Use a less cludgy way to pause/get state/set state
// TODO: Dynamically load from qtml.dll
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend); IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend);
@@ -228,8 +238,11 @@ 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
#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_2 )
if (!_wxIsQuickTime4Installed()) if (!_wxIsQuickTime4Installed())
return false; return false;
#endif
EnterMovies(); EnterMovies();
@@ -241,15 +254,19 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
// 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 ( !
m_ctrl->MacRemoveBordersFromStyle(style),
validator, name) )
return false;
// #if wxUSE_CREATEMOVIECONTROL
//Set our background color to black by default ctrl->wxControl::Create(parent, id, pos, size,
// m_ctrl->MacRemoveBordersFromStyle(style),
ctrl->SetBackgroundColour(*wxBLACK); validator, name)
#else
ctrl->wxWindow::Create(parent, id, pos, size,
m_ctrl->MacRemoveBordersFromStyle(style),
name)
#endif
)
return false;
m_ctrl = ctrl; m_ctrl = ctrl;
return true; return true;
@@ -261,7 +278,8 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
// 1) Get an FSSpec from the Windows path name // 1) Get an FSSpec from the Windows path name
// 2) Open the movie // 2) Open the movie
// 3) Obtain the movie instance from the movie resource // 3) Obtain the movie instance from the movie resource
// 4) // 4) Close the movie resource
// 5) Finish loading
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Load(const wxString& fileName) bool wxQTMediaBackend::Load(const wxString& fileName)
{ {
@@ -299,9 +317,15 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Load // wxQTMediaBackend::Load (URL Version)
// //
// TODO // 1) Build an escaped URI from location
// 2) Create a handle to store the URI string
// 3) Put the URI string inside the handle
// 4) Make a QuickTime URL data ref from the handle with the URI in it
// 5) Clean up the URI string handle
// 6) Do some prerolling
// 7) Finish Loading
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Load(const wxURI& location) bool wxQTMediaBackend::Load(const wxURI& location)
{ {
@@ -328,7 +352,7 @@ bool wxQTMediaBackend::Load(const wxURI& location)
return false; return false;
//preroll movie for streaming //preroll movie for streaming
//TODO:Async this? //TODO:Async this using threads?
TimeValue timeNow; TimeValue timeNow;
Fixed playRate; Fixed playRate;
timeNow = GetMovieTime(m_movie, NULL); timeNow = GetMovieTime(m_movie, NULL);
@@ -345,7 +369,13 @@ bool wxQTMediaBackend::Load(const wxURI& location)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::FinishLoad // wxQTMediaBackend::FinishLoad
// //
// TODO // 1) Create the movie timer
// 2) Get real size of movie for GetBestSize/sizers
// 3) See if there is video in the movie, and if so then either
// SetMovieGWorld if < 10.2 or use Native CreateMovieControl
// 4) Set the movie time scale to something usable so that seeking
// etc. will work correctly
// 5) Refresh parent window
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::FinishLoad() void wxQTMediaBackend::FinishLoad()
{ {
@@ -366,6 +396,40 @@ void wxQTMediaBackend::FinishLoad()
movieTrackCharacteristic | movieTrackCharacteristic |
movieTrackEnabledOnly) != NULL) movieTrackEnabledOnly) != NULL)
{ {
#if wxUSE_CREATEMOVIECONTROL
//
//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());
//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
GetControlPeer(m_ctrl)->GetControlRefAddr() );
::EmbedControl(GetControlPeer(m_ctrl)->GetControlRef(),
(ControlRef) m_ctrl->GetParent()->GetHandle());
#else
//
//"Emulation"
//
SetMovieGWorld(m_movie, SetMovieGWorld(m_movie,
(CGrafPtr) (CGrafPtr)
GetWindowPort( GetWindowPort(
@@ -373,6 +437,7 @@ void wxQTMediaBackend::FinishLoad()
m_ctrl->MacGetTopLevelWindowRef() m_ctrl->MacGetTopLevelWindowRef()
), ),
nil); nil);
#endif
} }
//we want millisecond precision //we want millisecond precision
@@ -393,7 +458,8 @@ void wxQTMediaBackend::FinishLoad()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Play // wxQTMediaBackend::Play
// //
// TODO // 1) Start the QT movie
// 2) Start the movie loading timer
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Play() bool wxQTMediaBackend::Play()
{ {
@@ -406,7 +472,8 @@ bool wxQTMediaBackend::Play()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Pause // wxQTMediaBackend::Pause
// //
// TODO // 1) Stop the movie
// 2) Stop the movie timer
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Pause() bool wxQTMediaBackend::Pause()
{ {
@@ -419,7 +486,9 @@ bool wxQTMediaBackend::Pause()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Stop // wxQTMediaBackend::Stop
// //
// TODO // 1) Stop the movie
// 2) Stop the movie timer
// 3) Seek to the beginning of the movie
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::Stop() bool wxQTMediaBackend::Stop()
{ {
@@ -437,7 +506,7 @@ bool wxQTMediaBackend::Stop()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::GetPlaybackRate // wxQTMediaBackend::GetPlaybackRate
// //
// TODO // 1) Get the movie playback rate from ::GetMovieRate
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
double wxQTMediaBackend::GetPlaybackRate() double wxQTMediaBackend::GetPlaybackRate()
{ {
@@ -447,7 +516,7 @@ double wxQTMediaBackend::GetPlaybackRate()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::SetPlaybackRate // wxQTMediaBackend::SetPlaybackRate
// //
// TODO // 1) Convert dRate to Fixed and Set the movie rate through SetMovieRate
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::SetPlaybackRate(double dRate) bool wxQTMediaBackend::SetPlaybackRate(double dRate)
{ {
@@ -458,7 +527,8 @@ bool wxQTMediaBackend::SetPlaybackRate(double dRate)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::SetPosition // wxQTMediaBackend::SetPosition
// //
// TODO // 1) Create a time record struct (TimeRecord) with appropriate values
// 2) Pass struct to SetMovieTime
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxQTMediaBackend::SetPosition(wxLongLong where) bool wxQTMediaBackend::SetPosition(wxLongLong where)
{ {
@@ -478,7 +548,7 @@ bool wxQTMediaBackend::SetPosition(wxLongLong where)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::GetPosition // wxQTMediaBackend::GetPosition
// //
// TODO // Calls GetMovieTime
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxLongLong wxQTMediaBackend::GetPosition() wxLongLong wxQTMediaBackend::GetPosition()
{ {
@@ -488,7 +558,7 @@ wxLongLong wxQTMediaBackend::GetPosition()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::GetDuration // wxQTMediaBackend::GetDuration
// //
// TODO // Calls GetMovieDuration
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxLongLong wxQTMediaBackend::GetDuration() wxLongLong wxQTMediaBackend::GetDuration()
{ {
@@ -498,7 +568,8 @@ wxLongLong wxQTMediaBackend::GetDuration()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::GetState // wxQTMediaBackend::GetState
// //
// TODO // Determines the current state - the timer keeps track of whether or not
// we are paused or stopped (if the timer is running we are playing)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxMediaState wxQTMediaBackend::GetState() wxMediaState wxQTMediaBackend::GetState()
{ {
@@ -515,13 +586,18 @@ wxMediaState wxQTMediaBackend::GetState()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Cleanup // wxQTMediaBackend::Cleanup
// //
// TODO // Diposes of the movie timer, Control if native, and stops and disposes
// of the QT movie
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void wxQTMediaBackend::Cleanup() void wxQTMediaBackend::Cleanup()
{ {
delete m_timer; delete m_timer;
m_timer = NULL; m_timer = NULL;
#if wxUSE_CREATEMOVIECONTROL
DisposeControl(GetControlPeer(m_ctrl)->GetControlRef());
#endif
StopMovie(m_movie); StopMovie(m_movie);
DisposeMovie(m_movie); DisposeMovie(m_movie);
} }
@@ -529,7 +605,7 @@ void wxQTMediaBackend::Cleanup()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::GetVideoSize // wxQTMediaBackend::GetVideoSize
// //
// TODO // Returns the actual size of the QT movie
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxSize wxQTMediaBackend::GetVideoSize() const wxSize wxQTMediaBackend::GetVideoSize() const
{ {
@@ -539,10 +615,12 @@ wxSize wxQTMediaBackend::GetVideoSize() const
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// wxQTMediaBackend::Move // wxQTMediaBackend::Move
// //
// TODO // If not using a native 10.2 QT control performs some emulated window
// movement stuff
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
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)
{ {
if ( m_ctrl ) if ( m_ctrl )
@@ -555,6 +633,7 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h)
::SetMovieBox(m_movie, &theRect); ::SetMovieBox(m_movie, &theRect);
wxASSERT(::GetMoviesError() == noErr); wxASSERT(::GetMoviesError() == noErr);
} }
#endif
} }