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
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//===========================================================================
// DECLARATIONS
//===========================================================================
//---------------------------------------------------------------------------
// Pre-compiled header stuff
//---------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
@@ -29,14 +21,20 @@
#pragma hdrstop
#endif
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "wx/mediactrl.h"
//---------------------------------------------------------------------------
// Compilation guard
//---------------------------------------------------------------------------
// 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
#if wxUSE_MEDIACTRL
//---------------------------------------------------------------------------
@@ -63,24 +61,9 @@
//===========================================================================
//---------------------------------------------------------------------------
//
// 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
{
@@ -123,10 +106,8 @@ public:
virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags);
//
// ------ Implementation from now on --------
//
void DoLoadBestSize();
void DoSetControllerVisible(wxMediaCtrlPlayerControls flags);
@@ -143,20 +124,24 @@ public:
#endif
wxSize m_bestSize; // Original movie size
#ifdef __WXMAC_OSX__
struct MovieType** m_movie; // QT Movie handle/instance
#else
Movie m_movie; // Movie instance
#endif
bool m_bPlaying; // Whether media is playing or not
class wxTimer* m_timer; // Timer for streaming the movie
MovieController m_mc; // MovieController instance
wxMediaCtrlPlayerControls m_interfaceflags; // Saved interface flags
#if !wxUSE_CREATEMOVIECONTROL
EventHandlerRef m_pEventHandlerRef; // Event handler to cleanup
friend class wxQTMediaEvtHandler;
#endif
DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
};
@@ -169,7 +154,8 @@ public:
{
m_qtb = qtb;
qtb->m_ctrl->Connect(qtb->m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND,
qtb->m_ctrl->Connect(
qtb->m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND,
wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground),
NULL, this);
}
@@ -196,9 +182,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxQTMediaWindowEventHandler );
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// wxQTMediaBackend
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
@@ -229,8 +213,9 @@ public:
#if !wxUSE_CREATEMOVIECONTROL
::MCIdle(m_parent->m_mc);
#endif
//kMovieLoadStatePlayable is not enough on MAC
//- it plays, but IsMovieDone might return true (!)
// kMovieLoadStatePlayable is not enough on MAC:
// it plays, but IsMovieDone might return true (!)
// sure we need to wait until kMovieLoadStatePlaythroughOK
if (::GetMovieLoadState(m_movie) >= 20000)
{
@@ -277,10 +262,8 @@ public:
::MCIdle(m_parent->m_mc);
#endif
//
// Handle the stop event - if the movie has reached
// the end, notify our handler
//
if (::IsMovieDone(m_movie))
{
if ( m_parent->SendStopEvent() )
@@ -345,7 +328,9 @@ wxQTMediaBackend::~wxQTMediaBackend()
// 1) Intializes QuickTime
// 2) Creates the control window
//---------------------------------------------------------------------------
bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
bool wxQTMediaBackend::CreateControl(
wxControl* ctrl,
wxWindow* parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
@@ -361,19 +346,18 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
EnterMovies();
//
// Create window
// By default wxWindow(s) is created with a border -
// so we need to get rid of those
//
// Since we don't have a child window like most other
// backends, we don't need wxCLIP_CHILDREN
//
if ( !ctrl->wxControl::Create(parent, id, pos, size,
wxWindow::MacRemoveBordersFromStyle(style),
validator, name)
)
validator, name))
{
return false;
}
#if wxUSE_VALIDATORS
ctrl->SetValidator(validator);
@@ -392,7 +376,7 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
#if !wxUSE_CREATEMOVIECONTROL
Boolean wxQTMediaBackend::IsQuickTime4Installed()
{
short error;
OSErr error;
long result;
error = Gestalt(gestaltQuickTime, &result);
@@ -431,6 +415,7 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
short movieResID = 0;
Str255 movieName;
bool result;
err = NewMovieFromFile(
&m_movie,
@@ -439,10 +424,11 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
movieName,
newMovieActive,
NULL); // wasChanged
result = (err == noErr);
// No ::GetMoviesStickyError() here because it returns -2009
// a.k.a. invalid track on valid mpegs
if(err == noErr)
if (result)
{
::CloseMovieFile(movieResFile);
@@ -452,13 +438,11 @@ bool wxQTMediaBackend::Load(const wxString& fileName)
#else
DoNewMovieController();
#endif
FinishLoad();
return true;
}
else
{
return false;
}
return result;
}
//---------------------------------------------------------------------------
@@ -506,11 +490,13 @@ bool wxQTMediaBackend::Load(const wxURI& location)
wxString theURI = location.BuildURI();
OSErr err = noErr;
bool result;
// FIXME: lurking Unicode problem here
Handle theHandle = ::NewHandleClear(theURI.length() + 1);
wxASSERT(theHandle);
::BlockMove(theURI.mb_str(), *theHandle, theURI.length() + 1);
::BlockMoveData(theURI.mb_str(), *theHandle, theURI.length() + 1);
// create the movie from the handle that refers to the URI
err = ::NewMovieFromDataRef(&m_movie, newMovieActive |
@@ -521,7 +507,8 @@ bool wxQTMediaBackend::Load(const wxURI& location)
::DisposeHandle(theHandle);
if (err == noErr)
result = (err == noErr);
if (result)
{
#if wxUSE_CREATEMOVIECONTROL
// Movie control resets prerolling, so we must create first
@@ -543,7 +530,6 @@ bool wxQTMediaBackend::Load(const wxURI& location)
playRate = ::GetMoviePreferredRate(m_movie);
wxASSERT(::GetMoviesError() == noErr);
//
// Note that the callback here is optional,
// but without it PrePrerollMovie can be buggy
// (see Apple ml). Also, some may wonder
@@ -552,14 +538,14 @@ bool wxQTMediaBackend::Load(const wxURI& location)
// require it if you don't use a Movie Controller,
// which we don't by default.
//
::PrePrerollMovie(m_movie, timeNow, playRate,
::PrePrerollMovie(
m_movie, timeNow, playRate,
wxQTMediaBackend::PPRMProc,
(void*)this);
#endif
return true;
}
else
return false;
return result;
}
//---------------------------------------------------------------------------
@@ -576,11 +562,10 @@ bool wxQTMediaBackend::Load(const wxURI& location)
#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,
Rect bounds = wxMacGetBoundsForControl(
m_ctrl,
m_ctrl->GetPosition(),
m_ctrl->GetSize());
@@ -588,7 +573,7 @@ void wxQTMediaBackend::DoCreateMovieControl()
if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() )
m_ctrl->m_peer->Dispose();
//Options-
// Options:
// kMovieControlOptionXXX
// HideController - hide the movie controller
// LocateTopLeft - movie is pinned to top left rather than centered in the control
@@ -608,16 +593,16 @@ void wxQTMediaBackend::DoCreateMovieControl()
, // flags
m_ctrl->m_peer->GetControlRefAddr() );
::EmbedControl(m_ctrl->m_peer->GetControlRef(),
::EmbedControl(
m_ctrl->m_peer->GetControlRef(),
(ControlRef)m_ctrl->GetParent()->GetHandle());
//
// Setup MovieController for the new movie
//
// set up MovieController for the new movie
long dataSize;
// Get movie controller from our control
::GetControlData( m_ctrl->m_peer->GetControlRef(), 0,
::GetControlData(
m_ctrl->m_peer->GetControlRef(), 0,
kMovieControlDataMovieController,
sizeof(MovieController), (Ptr)&m_mc, &dataSize );
@@ -642,7 +627,7 @@ void wxQTMediaBackend::DoNewMovieController()
// Get top level window ref for some mac functions
WindowRef wrTLW = (WindowRef) m_ctrl->MacGetTopLevelWindowRef();
// MovieController not setup yet -
// MovieController not setup yet:
// so we need to create a new one.
// You have to pass a valid movie to
// NewMovieController, evidently
@@ -651,14 +636,16 @@ void wxQTMediaBackend::DoNewMovieController()
NULL);
wxASSERT(::GetMoviesError() == noErr);
Rect bounds = wxMacGetBoundsForControl(m_ctrl,
Rect bounds = wxMacGetBoundsForControl(
m_ctrl,
m_ctrl->GetPosition(),
m_ctrl->GetSize());
m_mc = ::NewMovieController(m_movie, &bounds, mcTopLeftMovie |
//mcWithFrame |
mcNotVisible);
m_mc = ::NewMovieController(
m_movie, &bounds,
mcTopLeftMovie | mcNotVisible /* | mcWithFrame */ );
wxASSERT(::GetMoviesError() == noErr);
::MCDoAction(m_mc, 32, (void*)true); //mcActionSetKeysEnabled
wxASSERT(::GetMoviesError() == noErr);
@@ -674,7 +661,8 @@ void wxQTMediaBackend::DoNewMovieController()
// Event types to catch from the TLW
// for the moviecontroller
EventTypeSpec theEventTypes[] = {
EventTypeSpec theEventTypes[] =
{
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp },
{ kEventClassKeyboard, kEventRawKeyDown },
@@ -685,7 +673,7 @@ void wxQTMediaBackend::DoNewMovieController()
{ kEventClassWindow, kEventWindowDeactivated }
};
// Catch window messages -
// 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...
InstallWindowEventHandler( wrTLW,
@@ -695,13 +683,14 @@ void wxQTMediaBackend::DoNewMovieController()
}
else
{
// MovieController already created -
// MovieController already created:
// Just change the movie in it and we're good to go
Point thePoint;
thePoint.h = thePoint.v = 0;
::MCSetMovie(m_mc, m_movie,
(WindowRef)m_ctrl->MacGetTopLevelWindowRef(),
thePoint);
wxASSERT(::GetMoviesError() == noErr);
}
}
@@ -717,7 +706,7 @@ void wxQTMediaBackend::FinishLoad()
// get the real size of the movie
DoLoadBestSize();
// Show the player controls if the user wants to
// show the player controls if the user wants to
if (m_interfaceflags)
DoSetControllerVisible(m_interfaceflags);
@@ -725,7 +714,7 @@ void wxQTMediaBackend::FinishLoad()
::SetMovieTimeScale(m_movie, 1000);
wxASSERT(::GetMoviesError() == noErr);
// Start movie progress timer
// start movie progress timer
m_timer = new wxQTMediaPlayTimer(m_movie, (wxQTMediaBackend*) this);
wxASSERT(m_timer);
m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
@@ -765,8 +754,7 @@ bool wxQTMediaBackend::Play()
wxASSERT(fixRate != 0);
if (!m_bPlaying)
::MCDoAction( m_mc, 8, // mcActionPlay
(void *) fixRate);
::MCDoAction( m_mc, 8 /* mcActionPlay */, (void*) fixRate);
m_bPlaying = true;
return ::GetMoviesError() == noErr;
@@ -782,12 +770,13 @@ bool wxQTMediaBackend::Pause()
// Stop the movie A.K.A. ::StopMovie(m_movie);
if (m_bPlaying)
{
::MCDoAction( m_mc, 8 /*mcActionPlay*/,
(void *) 0);
::MCDoAction( m_mc, 8 /*mcActionPlay*/, (void*) 0);
m_bPlaying = false;
return ::GetMoviesError() == noErr;
}
return true; //already paused
// already paused
return true;
}
//---------------------------------------------------------------------------
@@ -924,7 +913,7 @@ wxMediaState wxQTMediaBackend::GetState()
// Could use
// GetMovieActive/IsMovieDone/SetMovieActive
// combo if implemented that way
if (m_bPlaying == true)
if (m_bPlaying)
return wxMEDIASTATE_PLAYING;
else if ( !m_movie || wxQTMediaBackend::GetPosition() == 0)
return wxMEDIASTATE_STOPPED;
@@ -947,7 +936,7 @@ void wxQTMediaBackend::Cleanup()
m_timer = NULL;
}
// Stop the movie
// Stop the movie:
// Apple samples with CreateMovieControl typically
// install a event handler and do this on the dispose
// event, but we do it here for simplicity
@@ -955,9 +944,7 @@ void wxQTMediaBackend::Cleanup()
// control destruction if not)
wxQTMediaBackend::Pause();
//
// Dispose of control or remove movie from MovieController
//
#if wxUSE_CREATEMOVIECONTROL
if (m_ctrl->m_peer && m_ctrl->m_peer->Ok() )
m_ctrl->m_peer->Dispose();
@@ -969,6 +956,7 @@ void wxQTMediaBackend::Cleanup()
#endif
::DisposeMovie(m_movie);
m_movie = NULL;
}
//---------------------------------------------------------------------------
@@ -981,21 +969,25 @@ Boolean wxQTMediaBackend::MCFilterProc(
short action,
void * WXUNUSED(params),
long refCon)
{
if(action != 1) //don't process idle events
{
wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon;
switch (action)
{
case 8: //play button triggered - MC will set movie to opposite state
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;
}
@@ -1046,11 +1038,9 @@ void wxQTMediaBackend::Move(int x, int y, int w, int h)
//---------------------------------------------------------------------------
void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags)
{
::MCSetVisible(m_mc, TRUE);
::MCSetVisible(m_mc, true);
//
// Take care of subcontrols
//
if (::GetMoviesError() == noErr)
{
long mcFlags = 0;
@@ -1066,14 +1056,13 @@ void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags)
? 0 : (1 << 2)/*mcFlagSuppressSpeakerButton*/)
// | (1 << 4) /*mcFlagDontInvalidate*/ //if we take care of repainting ourselves
);
::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags);
}
}
//
// Adjust height and width of best size for movie controller
// if the user wants it shown
//
m_bestSize.x = m_bestSize.x > wxMCWIDTH ? m_bestSize.x : wxMCWIDTH;
m_bestSize.y += wxMCHEIGHT;
}
@@ -1095,7 +1084,7 @@ bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
{
bSizeChanged = true;
DoLoadBestSize();
::MCSetVisible(m_mc, FALSE);
::MCSetVisible(m_mc, false);
}
else if (!m_interfaceflags && flags) //show controller if hidden
{
@@ -1142,7 +1131,8 @@ void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
// messages to our moviecontroller so it can recieve mouse clicks etc.
//---------------------------------------------------------------------------
#if !wxUSE_CREATEMOVIECONTROL
OSStatus wxQTMediaWindowEventHandler(EventHandlerCallRef inHandlerCallRef,
OSStatus wxQTMediaWindowEventHandler(
EventHandlerCallRef inHandlerCallRef,
EventRef inEvent, void *inUserData)
{
EventRecord theEvent;
@@ -1151,7 +1141,7 @@ OSStatus wxQTMediaWindowEventHandler(EventHandlerCallRef inHandlerCallRef,
err = ::MCIsPlayerEvent( (MovieController) inUserData, &theEvent );
// pass on to other event handlers if not handled- i.e. wx
if(err)
if (err != noErr)
return noErr;
else
return eventNotHandledErr;