]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/mediactrl.cpp
Include wx/font.h according to precompiled headers of wx/wx.h (with other minor clean...
[wxWidgets.git] / src / mac / carbon / mediactrl.cpp
CommitLineData
1a680109 1/////////////////////////////////////////////////////////////////////////////
987e9419 2// Name: src/mac/carbon/mediactrl.cpp
ff4aedc5 3// Purpose: Built-in Media Backends for Mac
1a680109 4// Author: Ryan Norton <wxprojects@comcast.net>
ff4aedc5 5// Modified by:
1a680109
RN
6// Created: 11/07/04
7// RCS-ID: $Id$
0c81ef7f 8// Copyright: (c) 2004-2006 Ryan Norton
1a680109
RN
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
bf354396 12//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0c81ef7f
SC
13// OK, a casual overseer of this file may wonder why we don't use
14// either CreateMovieControl or HIMovieView...
557002cf 15//
0c81ef7f
SC
16// CreateMovieControl
17// 1) Need to dispose and create each time a new movie is loaded
18// 2) Not that many real advantages
19// 3) Progressively buggier in higher OSX versions
20// (see main.c of QTCarbonShell sample for details)
21// HIMovieView
22// 1) Crashes on destruction in ALL cases on quite a few systems!
23// (With the only real "alternative" is to simply not
24// dispose of it and let it leak...)
25// 2) Massive refreshing bugs with its movie controller between
26// movies
557002cf 27//
0c81ef7f
SC
28// At one point we had a complete implementation for CreateMovieControl
29// and on my (RN) local copy I had one for HIMovieView - but they
30// were simply deemed to be too buggy/unuseful. HIMovieView could
31// have been useful as well because it uses OpenGL contexts instead
32// of GWorlds. Perhaps someday when someone comes out with some
33// ingenious workarounds :).
bf354396
VZ
34//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
1a680109
RN
36// For compilers that support precompilation, includes "wx.h".
37#include "wx/wxprec.h"
38
987e9419
WS
39#if wxUSE_MEDIACTRL
40
ff4aedc5 41#include "wx/mediactrl.h"
1a680109 42
987e9419
WS
43#ifndef WX_PRECOMP
44 #include "wx/log.h"
c0badb70 45 #include "wx/timer.h"
987e9419
WS
46#endif
47
9419b0d6
DS
48// uma is for wxMacFSSpec
49#include "wx/mac/uma.h"
9419b0d6 50
9419b0d6 51// standard QT stuff
0c81ef7f 52#ifndef __DARWIN__
9419b0d6
DS
53#include <Movies.h>
54#include <Gestalt.h>
55#include <QuickTimeComponents.h>
56#else
57#include <QuickTime/QuickTimeComponents.h>
58#endif
59
3b5023b9 60//---------------------------------------------------------------------------
0c81ef7f 61// Height and Width of movie controller in the movie control (apple samples)
bf354396
VZ
62//---------------------------------------------------------------------------
63#define wxMCWIDTH 320
64#define wxMCHEIGHT 16
65
ff4aedc5
RN
66//===========================================================================
67// BACKEND DECLARATIONS
68//===========================================================================
212945de 69
ff4aedc5 70//---------------------------------------------------------------------------
ff4aedc5 71// wxQTMediaBackend
ff4aedc5 72//---------------------------------------------------------------------------
1a680109 73
bf354396 74class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase
ff4aedc5
RN
75{
76public:
ff4aedc5
RN
77 wxQTMediaBackend();
78 ~wxQTMediaBackend();
79
d0ee33f5 80 virtual bool CreateControl(wxControl* ctrl, wxWindow* parent,
ff4aedc5 81 wxWindowID id,
d0ee33f5 82 const wxPoint& pos,
ff4aedc5 83 const wxSize& size,
d0ee33f5 84 long style,
ff4aedc5
RN
85 const wxValidator& validator,
86 const wxString& name);
87
0c81ef7f
SC
88 virtual bool Load(const wxString& fileName);
89 virtual bool Load(const wxURI& location);
90
ff4aedc5
RN
91 virtual bool Play();
92 virtual bool Pause();
93 virtual bool Stop();
94
ff4aedc5
RN
95 virtual wxMediaState GetState();
96
97 virtual bool SetPosition(wxLongLong where);
98 virtual wxLongLong GetPosition();
99 virtual wxLongLong GetDuration();
100
101 virtual void Move(int x, int y, int w, int h);
102 wxSize GetVideoSize() const;
103
104 virtual double GetPlaybackRate();
105 virtual bool SetPlaybackRate(double dRate);
106
c5191fbd
VZ
107 virtual double GetVolume();
108 virtual bool SetVolume(double);
109
ff4aedc5
RN
110 void Cleanup();
111 void FinishLoad();
112
bf354396 113 virtual bool ShowPlayerControls(wxMediaCtrlPlayerControls flags);
9419b0d6 114
557002cf
VZ
115 virtual wxLongLong GetDownloadProgress();
116 virtual wxLongLong GetDownloadTotal();
bf354396 117
0c81ef7f
SC
118 virtual void MacVisibilityChanged();
119
557002cf 120 //
bf354396 121 // ------ Implementation from now on --------
557002cf
VZ
122 //
123 bool DoPause();
124 bool DoStop();
592a247d 125
bf354396
VZ
126 void DoLoadBestSize();
127 void DoSetControllerVisible(wxMediaCtrlPlayerControls flags);
128
557002cf
VZ
129 wxLongLong GetDataSizeFromStart(TimeValue end);
130
0c81ef7f
SC
131 Boolean IsQuickTime4Installed();
132 void DoNewMovieController();
133
134 static pascal void PPRMProc(
135 Movie theMovie, OSErr theErr, void* theRefCon);
136
bf354396 137 //TODO: Last param actually long - does this work on 64bit machines?
9419b0d6 138 static pascal Boolean MCFilterProc(MovieController theController,
bf354396
VZ
139 short action, void *params, long refCon);
140
0c81ef7f
SC
141 static pascal OSStatus WindowEventHandler(
142 EventHandlerCallRef inHandlerCallRef,
143 EventRef inEvent, void *inUserData );
bf354396
VZ
144
145 wxSize m_bestSize; // Original movie size
bf354396 146 Movie m_movie; // Movie instance
bf354396
VZ
147 bool m_bPlaying; // Whether media is playing or not
148 class wxTimer* m_timer; // Timer for streaming the movie
149 MovieController m_mc; // MovieController instance
150 wxMediaCtrlPlayerControls m_interfaceflags; // Saved interface flags
9419b0d6 151
0c81ef7f 152 // Event handlers and UPPs/Callbacks
987e9419 153 EventHandlerRef m_windowEventHandler;
0c81ef7f
SC
154 EventHandlerUPP m_windowUPP;
155
557002cf 156 MoviePrePrerollCompleteUPP m_preprerollupp;
557002cf 157 MCActionFilterWithRefConUPP m_mcactionupp;
ff4aedc5 158
987e9419 159 GWorldPtr m_movieWorld; //Offscreen movie GWorld
0c81ef7f 160
bf354396 161 friend class wxQTMediaEvtHandler;
9419b0d6 162
d0ee33f5 163 DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
ff4aedc5
RN
164};
165
bf354396
VZ
166// helper to hijack background erasing for the QT window
167class WXDLLIMPEXP_MEDIA wxQTMediaEvtHandler : public wxEvtHandler
168{
169public:
170 wxQTMediaEvtHandler(wxQTMediaBackend *qtb)
171 {
172 m_qtb = qtb;
173
9419b0d6
DS
174 qtb->m_ctrl->Connect(
175 qtb->m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND,
bf354396
VZ
176 wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground),
177 NULL, this);
178 }
179
180 void OnEraseBackground(wxEraseEvent& event);
181
182private:
183 wxQTMediaBackend *m_qtb;
184
185 DECLARE_NO_COPY_CLASS(wxQTMediaEvtHandler)
186};
187
bf354396
VZ
188//===========================================================================
189// IMPLEMENTATION
190//===========================================================================
191
ff4aedc5
RN
192
193//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0c81ef7f 194//
ff4aedc5 195// wxQTMediaBackend
0c81ef7f 196//
ff4aedc5
RN
197//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
198
412e0d47 199IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend)
1a680109 200
bf354396
VZ
201//Time between timer calls - this is the Apple recommondation to the TCL
202//team I believe
203#define MOVIE_DELAY 20
1a680109 204
bf354396
VZ
205//---------------------------------------------------------------------------
206// wxQTMediaLoadTimer
207//
208// QT, esp. QT for Windows is very picky about how you go about
209// async loading. If you were to go through a Windows message loop
210// or a MoviesTask or both and then check the movie load state
211// it would still return 1000 (loading)... even (pre)prerolling doesn't
212// help. However, making a load timer like this works
213//---------------------------------------------------------------------------
214class wxQTMediaLoadTimer : public wxTimer
1a680109
RN
215{
216public:
0c81ef7f
SC
217 wxQTMediaLoadTimer(wxQTMediaBackend* parent) :
218 m_parent(parent) {}
1a680109 219
bf354396
VZ
220 void Notify()
221 {
bf354396 222 ::MCIdle(m_parent->m_mc);
9419b0d6
DS
223
224 // kMovieLoadStatePlayable is not enough on MAC:
225 // it plays, but IsMovieDone might return true (!)
226 // sure we need to wait until kMovieLoadStatePlaythroughOK
0c81ef7f 227 if (::GetMovieLoadState(m_parent->m_movie) >= 20000)
9419b0d6 228 {
bf354396
VZ
229 m_parent->FinishLoad();
230 delete this;
9419b0d6 231 }
1a680109
RN
232 }
233
bf354396 234protected:
9419b0d6 235 wxQTMediaBackend *m_parent; // Backend pointer
bf354396
VZ
236};
237
238// --------------------------------------------------------------------------
239// wxQTMediaPlayTimer - Handle Asyncronous Playing
240//
241// 1) Checks to see if the movie is done, and if not continues
242// streaming the movie
243// 2) Sends the wxEVT_MEDIA_STOP event if we have reached the end of
244// the movie.
245// --------------------------------------------------------------------------
246class wxQTMediaPlayTimer : public wxTimer
247{
248public:
0c81ef7f
SC
249 wxQTMediaPlayTimer(wxQTMediaBackend* parent) :
250 m_parent(parent) {}
1a680109
RN
251
252 void Notify()
9419b0d6 253 {
bf354396
VZ
254 //
255 // OK, a little explaining - basically originally
256 // we only called MoviesTask if the movie was actually
257 // playing (not paused or stopped)... this was before
258 // we realized MoviesTask actually handles repainting
259 // of the current frame - so if you were to resize
260 // or something it would previously not redraw that
261 // portion of the movie.
262 //
263 // So now we call MoviesTask always so that it repaints
264 // correctly.
265 //
266 ::MCIdle(m_parent->m_mc);
ff4aedc5 267
0c81ef7f 268 //
bf354396
VZ
269 // Handle the stop event - if the movie has reached
270 // the end, notify our handler
0c81ef7f
SC
271 //
272 if (::IsMovieDone(m_parent->m_movie))
9419b0d6 273 {
bf354396
VZ
274 if ( m_parent->SendStopEvent() )
275 {
ff4aedc5
RN
276 m_parent->Stop();
277 wxASSERT(::GetMoviesError() == noErr);
278
bf354396 279 m_parent->QueueFinishEvent();
1a680109
RN
280 }
281 }
282 }
283
284protected:
9419b0d6 285 wxQTMediaBackend* m_parent; // Backend pointer
1a680109
RN
286};
287
bf354396 288
ff4aedc5 289//---------------------------------------------------------------------------
e7b97da3 290// wxQTMediaBackend Constructor
ff4aedc5
RN
291//
292// Sets m_timer to NULL signifying we havn't loaded anything yet
293//---------------------------------------------------------------------------
9419b0d6 294wxQTMediaBackend::wxQTMediaBackend()
bf354396
VZ
295 : m_movie(NULL), m_bPlaying(false), m_timer(NULL)
296 , m_mc(NULL), m_interfaceflags(wxMEDIACTRLPLAYERCONTROLS_NONE)
0c81ef7f 297 , m_preprerollupp(NULL), m_movieWorld(NULL)
1a680109 298{
1a680109
RN
299}
300
ff4aedc5
RN
301//---------------------------------------------------------------------------
302// wxQTMediaBackend Destructor
303//
304// 1) Cleans up the QuickTime movie instance
305// 2) Decrements the QuickTime reference counter - if this reaches
306// 0, QuickTime shuts down
307// 3) Decrements the QuickTime Windows Media Layer reference counter -
308// if this reaches 0, QuickTime shuts down the Windows Media Layer
309//---------------------------------------------------------------------------
310wxQTMediaBackend::~wxQTMediaBackend()
1a680109 311{
9419b0d6 312 if (m_movie)
ff4aedc5 313 Cleanup();
1a680109 314
bf354396 315 // Cleanup for moviecontroller
9419b0d6 316 if (m_mc)
bf354396
VZ
317 {
318 // destroy wxQTMediaEvtHandler we pushed on it
319 m_ctrl->PopEventHandler(true);
0c81ef7f
SC
320 RemoveEventHandler(m_windowEventHandler);
321 DisposeEventHandlerUPP(m_windowUPP);
557002cf
VZ
322
323 // Dispose of the movie controller
bf354396 324 ::DisposeMovieController(m_mc);
0c81ef7f 325 m_mc = NULL;
557002cf 326 DisposeMCActionFilterWithRefConUPP(m_mcactionupp);
987e9419 327
0c81ef7f
SC
328 // Dispose of offscreen GWorld
329 ::DisposeGWorld(m_movieWorld);
bf354396 330 }
bf354396 331
9419b0d6 332 // Note that ExitMovies() is not necessary...
ff4aedc5 333 ExitMovies();
1a680109
RN
334}
335
ff4aedc5
RN
336//---------------------------------------------------------------------------
337// wxQTMediaBackend::CreateControl
338//
339// 1) Intializes QuickTime
340// 2) Creates the control window
341//---------------------------------------------------------------------------
9419b0d6
DS
342bool wxQTMediaBackend::CreateControl(
343 wxControl* ctrl,
344 wxWindow* parent,
345 wxWindowID id,
346 const wxPoint& pos,
347 const wxSize& size,
348 long style,
349 const wxValidator& validator,
350 const wxString& name)
1a680109 351{
bf354396 352 if (!IsQuickTime4Installed())
1a680109 353 return false;
1a680109 354
ff4aedc5
RN
355 EnterMovies();
356
0c81ef7f
SC
357 wxMediaCtrl* mediactrl = (wxMediaCtrl*)ctrl;
358
359 //
ff4aedc5
RN
360 // Create window
361 // By default wxWindow(s) is created with a border -
362 // so we need to get rid of those
363 //
364 // Since we don't have a child window like most other
365 // backends, we don't need wxCLIP_CHILDREN
0c81ef7f
SC
366 //
367 if ( !mediactrl->wxControl::Create(
9419b0d6
DS
368 parent, id, pos, size,
369 wxWindow::MacRemoveBordersFromStyle(style),
370 validator, name))
371 {
1a680109 372 return false;
9419b0d6 373 }
1a680109 374
ecd20d4a 375#if wxUSE_VALIDATORS
0c81ef7f 376 mediactrl->SetValidator(validator);
ecd20d4a
RN
377#endif
378
0c81ef7f 379 m_ctrl = mediactrl;
1a680109
RN
380 return true;
381}
382
bf354396
VZ
383//---------------------------------------------------------------------------
384// wxQTMediaBackend::IsQuickTime4Installed
385//
9419b0d6
DS
386// Determines whether version 4 of QT is installed
387// (Pretty much for Classic only)
bf354396 388//---------------------------------------------------------------------------
bf354396
VZ
389Boolean wxQTMediaBackend::IsQuickTime4Installed()
390{
9419b0d6 391 OSErr error;
bf354396
VZ
392 long result;
393
9419b0d6 394 error = Gestalt(gestaltQuickTime, &result);
bf354396
VZ
395 return (error == noErr) && (((result >> 16) & 0xffff) >= 0x0400);
396}
bf354396 397
ff4aedc5
RN
398//---------------------------------------------------------------------------
399// wxQTMediaBackend::Load (file version)
400//
401// 1) Get an FSSpec from the Windows path name
402// 2) Open the movie
403// 3) Obtain the movie instance from the movie resource
3b5023b9
RN
404// 4) Close the movie resource
405// 5) Finish loading
ff4aedc5
RN
406//---------------------------------------------------------------------------
407bool wxQTMediaBackend::Load(const wxString& fileName)
1a680109 408{
9419b0d6 409 if (m_movie)
1a680109
RN
410 Cleanup();
411
987e9419 412 ::ClearMoviesStickyError(); // clear previous errors so
0c81ef7f 413 // GetMoviesStickyError is useful
987e9419 414
1a680109
RN
415 OSErr err = noErr;
416 short movieResFile;
417 FSSpec sfFile;
d0ee33f5 418
9419b0d6
DS
419 wxMacFilename2FSSpec( fileName, &sfFile );
420 if (OpenMovieFile( &sfFile, &movieResFile, fsRdPerm ) != noErr)
1a680109
RN
421 return false;
422
423 short movieResID = 0;
424 Str255 movieName;
557002cf 425
9419b0d6
DS
426 err = NewMovieFromFile(
427 &m_movie,
428 movieResFile,
429 &movieResID,
430 movieName,
431 newMovieActive,
432 NULL); // wasChanged
557002cf 433
0c81ef7f
SC
434 //
435 // check GetMoviesStickyError() because it may not find the
436 // proper codec and play black video and other strange effects,
437 // not to mention mess up the dynamic backend loading scheme
438 // of wxMediaCtrl - so it just does what the QuickTime player does
439 //
440 if (err == noErr && ::GetMoviesStickyError() == noErr)
bf354396 441 {
9419b0d6 442 ::CloseMovieFile(movieResFile);
1a680109 443
bf354396 444 // Create movie controller/control
bf354396 445 DoNewMovieController();
9419b0d6
DS
446
447 FinishLoad();
0c81ef7f 448 return true;
bf354396 449 }
9419b0d6 450
0c81ef7f 451 return false;
bf354396 452}
1a680109 453
ff4aedc5 454//---------------------------------------------------------------------------
3b5023b9 455// wxQTMediaBackend::Load (URL Version)
ff4aedc5 456//
3b5023b9
RN
457// 1) Build an escaped URI from location
458// 2) Create a handle to store the URI string
459// 3) Put the URI string inside the handle
460// 4) Make a QuickTime URL data ref from the handle with the URI in it
461// 5) Clean up the URI string handle
462// 6) Do some prerolling
463// 7) Finish Loading
ff4aedc5
RN
464//---------------------------------------------------------------------------
465bool wxQTMediaBackend::Load(const wxURI& location)
1a680109 466{
9419b0d6 467 if (m_movie)
1a680109
RN
468 Cleanup();
469
987e9419 470 ::ClearMoviesStickyError(); // clear previous errors so
0c81ef7f
SC
471 // GetMoviesStickyError is useful
472
1a680109 473 wxString theURI = location.BuildURI();
0c81ef7f 474 OSErr err;
1a680109 475
0c81ef7f
SC
476 size_t len;
477 const char* theURIString;
478
479#if wxUSE_UNICODE
480 wxCharBuffer buf = wxConvLocal.cWC2MB(theURI, theURI.length(), &len);
481 theURIString = buf;
482#else
483 theURIString = theURI;
484 len = theURI.length();
485#endif
1a680109 486
0c81ef7f 487 Handle theHandle = ::NewHandleClear(len + 1);
1a680109
RN
488 wxASSERT(theHandle);
489
0c81ef7f 490 ::BlockMoveData(theURIString, *theHandle, len + 1);
1a680109 491
9419b0d6
DS
492 // create the movie from the handle that refers to the URI
493 err = ::NewMovieFromDataRef(
494 &m_movie,
495 newMovieActive | newMovieAsyncOK /* | newMovieIdleImportOK*/,
496 NULL, theHandle,
497 URLDataHandlerSubType);
1a680109 498
bf354396 499 ::DisposeHandle(theHandle);
1a680109 500
0c81ef7f 501 if (err == noErr && ::GetMoviesStickyError() == noErr)
bf354396 502 {
9419b0d6 503 // Movie controller resets prerolling, so we must create first
bf354396 504 DoNewMovieController();
9419b0d6 505
bf354396 506 long timeNow;
9419b0d6 507 Fixed playRate;
1a680109 508
bf354396
VZ
509 timeNow = ::GetMovieTime(m_movie, NULL);
510 wxASSERT(::GetMoviesError() == noErr);
1a680109 511
bf354396
VZ
512 playRate = ::GetMoviePreferredRate(m_movie);
513 wxASSERT(::GetMoviesError() == noErr);
514
0c81ef7f 515 //
bf354396
VZ
516 // Note that the callback here is optional,
517 // but without it PrePrerollMovie can be buggy
518 // (see Apple ml). Also, some may wonder
519 // why we need this at all - this is because
520 // Apple docs say QuickTime streamed movies
521 // require it if you don't use a Movie Controller,
522 // which we don't by default.
523 //
987e9419 524 m_preprerollupp =
0c81ef7f 525 NewMoviePrePrerollCompleteUPP( wxQTMediaBackend::PPRMProc );
987e9419 526 ::PrePrerollMovie( m_movie, timeNow, playRate,
0c81ef7f 527 m_preprerollupp, (void*)this);
9419b0d6 528
0c81ef7f
SC
529 return true;
530 }
1a680109 531
0c81ef7f 532 return false;
bf354396 533}
bf354396
VZ
534
535//---------------------------------------------------------------------------
536// wxQTMediaBackend::DoNewMovieController
537//
538// Attaches movie to moviecontroller or creates moviecontroller
539// if not created yet
540//---------------------------------------------------------------------------
bf354396
VZ
541void wxQTMediaBackend::DoNewMovieController()
542{
9419b0d6 543 if (!m_mc)
bf354396
VZ
544 {
545 // Get top level window ref for some mac functions
546 WindowRef wrTLW = (WindowRef) m_ctrl->MacGetTopLevelWindowRef();
9419b0d6
DS
547
548 // MovieController not set up yet, so we need to create a new one.
549 // You have to pass a valid movie to NewMovieController, evidently
bf354396
VZ
550 ::SetMovieGWorld(m_movie,
551 (CGrafPtr) GetWindowPort(wrTLW),
552 NULL);
553 wxASSERT(::GetMoviesError() == noErr);
554
9419b0d6
DS
555 Rect bounds = wxMacGetBoundsForControl(
556 m_ctrl,
557 m_ctrl->GetPosition(),
558 m_ctrl->GetSize());
bf354396 559
9419b0d6
DS
560 m_mc = ::NewMovieController(
561 m_movie, &bounds,
562 mcTopLeftMovie | mcNotVisible /* | mcWithFrame */ );
bf354396 563 wxASSERT(::GetMoviesError() == noErr);
9419b0d6
DS
564
565 ::MCDoAction(m_mc, 32, (void*)true); // mcActionSetKeysEnabled
bf354396
VZ
566 wxASSERT(::GetMoviesError() == noErr);
567
568 // Setup a callback so we can tell when the user presses
569 // play on the player controls
987e9419 570 m_mcactionupp =
0c81ef7f 571 NewMCActionFilterWithRefConUPP( wxQTMediaBackend::MCFilterProc );
9419b0d6 572 ::MCSetActionFilterWithRefCon( m_mc, m_mcactionupp, (long)this );
bf354396
VZ
573 wxASSERT(::GetMoviesError() == noErr);
574
9419b0d6 575 // Part of a suggestion from Greg Hazel to repaint movie when idle
bf354396 576 m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this));
9419b0d6 577
0c81ef7f
SC
578 // Create offscreen GWorld for where to "show" when window is hidden
579 Rect worldRect;
580 worldRect.left = worldRect.top = 0;
581 worldRect.right = worldRect.bottom = 1;
582 ::NewGWorld(&m_movieWorld, 0, &worldRect, NULL, NULL, 0);
583
584 // Catch window messages:
585 // if we do not do this and if the user clicks the play
586 // button on the controller, for instance, nothing will happen...
587 EventTypeSpec theWindowEventTypes[] =
9419b0d6
DS
588 {
589 { kEventClassMouse, kEventMouseDown },
590 { kEventClassMouse, kEventMouseUp },
591 { kEventClassMouse, kEventMouseDragged },
592 { kEventClassKeyboard, kEventRawKeyDown },
593 { kEventClassKeyboard, kEventRawKeyRepeat },
594 { kEventClassKeyboard, kEventRawKeyUp },
595 { kEventClassWindow, kEventWindowUpdate },
596 { kEventClassWindow, kEventWindowActivated },
597 { kEventClassWindow, kEventWindowDeactivated }
598 };
987e9419 599 m_windowUPP =
0c81ef7f 600 NewEventHandlerUPP( wxQTMediaBackend::WindowEventHandler );
9419b0d6
DS
601 InstallWindowEventHandler(
602 wrTLW,
0c81ef7f
SC
603 m_windowUPP,
604 GetEventTypeCount( theWindowEventTypes ), theWindowEventTypes,
987e9419 605 this,
0c81ef7f 606 &m_windowEventHandler );
bf354396
VZ
607 }
608 else
609 {
9419b0d6 610 // MovieController already created:
bf354396
VZ
611 // Just change the movie in it and we're good to go
612 Point thePoint;
613 thePoint.h = thePoint.v = 0;
9419b0d6 614 ::MCSetMovie(m_mc, m_movie,
bf354396 615 (WindowRef)m_ctrl->MacGetTopLevelWindowRef(),
9419b0d6 616 thePoint);
bf354396 617 wxASSERT(::GetMoviesError() == noErr);
1a680109 618 }
bf354396 619}
bf354396
VZ
620
621//---------------------------------------------------------------------------
622// wxQTMediaBackend::FinishLoad
623//
624// Performs operations after a movie ready to play/loaded.
625//---------------------------------------------------------------------------
626void wxQTMediaBackend::FinishLoad()
9419b0d6
DS
627{
628 // Dispose of the PrePrerollMovieUPP if we used it
557002cf 629 DisposeMoviePrePrerollCompleteUPP(m_preprerollupp);
9419b0d6 630
bf354396
VZ
631 // get the real size of the movie
632 DoLoadBestSize();
633
9419b0d6
DS
634 // show the player controls if the user wants to
635 if (m_interfaceflags)
bf354396 636 DoSetControllerVisible(m_interfaceflags);
1a680109 637
9419b0d6 638 // we want millisecond precision
1a680109 639 ::SetMovieTimeScale(m_movie, 1000);
ff4aedc5
RN
640 wxASSERT(::GetMoviesError() == noErr);
641
9419b0d6 642 // start movie progress timer
0c81ef7f 643 m_timer = new wxQTMediaPlayTimer(this);
bf354396
VZ
644 wxASSERT(m_timer);
645 m_timer->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS);
646
9419b0d6 647 // send loaded event and refresh size
bf354396
VZ
648 NotifyMovieLoaded();
649}
650
651//---------------------------------------------------------------------------
652// wxQTMediaBackend::DoLoadBestSize
653//
654// Sets the best size of the control from the real size of the movie
655//---------------------------------------------------------------------------
656void wxQTMediaBackend::DoLoadBestSize()
657{
9419b0d6 658 // get the real size of the movie
bf354396 659 Rect outRect;
9419b0d6 660 ::GetMovieNaturalBoundsRect(m_movie, &outRect);
bf354396
VZ
661 wxASSERT(::GetMoviesError() == noErr);
662
9419b0d6 663 // determine best size
bf354396
VZ
664 m_bestSize.x = outRect.right - outRect.left;
665 m_bestSize.y = outRect.bottom - outRect.top;
1a680109
RN
666}
667
ff4aedc5 668//---------------------------------------------------------------------------
e7b97da3 669// wxQTMediaBackend::Play
ff4aedc5 670//
bf354396 671// Start the QT movie
557002cf 672// (Apple recommends mcActionPrerollAndPlay but that's QT 4.1+)
ff4aedc5
RN
673//---------------------------------------------------------------------------
674bool wxQTMediaBackend::Play()
1a680109 675{
bf354396 676 Fixed fixRate = (Fixed) (wxQTMediaBackend::GetPlaybackRate() * 0x10000);
9419b0d6 677 if (!fixRate)
bf354396 678 fixRate = ::GetMoviePreferredRate(m_movie);
9419b0d6 679
bf354396
VZ
680 wxASSERT(fixRate != 0);
681
9419b0d6
DS
682 if (!m_bPlaying)
683 ::MCDoAction( m_mc, 8 /* mcActionPlay */, (void*) fixRate);
557002cf 684
9419b0d6
DS
685 bool result = (::GetMoviesError() == noErr);
686 if (result)
557002cf 687 {
9419b0d6 688 m_bPlaying = true;
557002cf 689 QueuePlayEvent();
557002cf 690 }
9419b0d6
DS
691
692 return result;
1a680109
RN
693}
694
ff4aedc5 695//---------------------------------------------------------------------------
e7b97da3 696// wxQTMediaBackend::Pause
ff4aedc5 697//
bf354396 698// Stop the movie
ff4aedc5 699//---------------------------------------------------------------------------
557002cf 700bool wxQTMediaBackend::DoPause()
1a680109 701{
9419b0d6
DS
702 // Stop the movie A.K.A. ::StopMovie(m_movie);
703 if (m_bPlaying)
bf354396 704 {
9419b0d6 705 ::MCDoAction( m_mc, 8 /*mcActionPlay*/, (void *) 0);
bf354396 706 m_bPlaying = false;
9419b0d6 707 return ::GetMoviesError() == noErr;
bf354396 708 }
9419b0d6
DS
709
710 // already paused
711 return true;
557002cf 712}
592a247d 713
557002cf
VZ
714bool wxQTMediaBackend::Pause()
715{
716 bool bSuccess = DoPause();
9419b0d6 717 if (bSuccess)
557002cf 718 this->QueuePauseEvent();
9419b0d6
DS
719
720 return bSuccess;
1a680109
RN
721}
722
ff4aedc5 723//---------------------------------------------------------------------------
e7b97da3 724// wxQTMediaBackend::Stop
ff4aedc5 725//
3b5023b9 726// 1) Stop the movie
bf354396 727// 2) Seek to the beginning of the movie
ff4aedc5 728//---------------------------------------------------------------------------
4ac483eb 729bool wxQTMediaBackend::DoStop()
1a680109 730{
4ac483eb 731 if (!wxQTMediaBackend::DoPause())
1a680109 732 return false;
d0ee33f5 733
1a680109
RN
734 ::GoToBeginningOfMovie(m_movie);
735 return ::GetMoviesError() == noErr;
736}
737
557002cf
VZ
738bool wxQTMediaBackend::Stop()
739{
740 bool bSuccess = DoStop();
9419b0d6 741 if (bSuccess)
557002cf 742 QueueStopEvent();
9419b0d6
DS
743
744 return bSuccess;
557002cf
VZ
745}
746
ff4aedc5 747//---------------------------------------------------------------------------
e7b97da3 748// wxQTMediaBackend::GetPlaybackRate
ff4aedc5 749//
3b5023b9 750// 1) Get the movie playback rate from ::GetMovieRate
ff4aedc5
RN
751//---------------------------------------------------------------------------
752double wxQTMediaBackend::GetPlaybackRate()
1a680109 753{
1a680109
RN
754 return ( ((double)::GetMovieRate(m_movie)) / 0x10000);
755}
756
ff4aedc5 757//---------------------------------------------------------------------------
e7b97da3 758// wxQTMediaBackend::SetPlaybackRate
ff4aedc5 759//
3b5023b9 760// 1) Convert dRate to Fixed and Set the movie rate through SetMovieRate
ff4aedc5
RN
761//---------------------------------------------------------------------------
762bool wxQTMediaBackend::SetPlaybackRate(double dRate)
1a680109 763{
1a680109
RN
764 ::SetMovieRate(m_movie, (Fixed) (dRate * 0x10000));
765 return ::GetMoviesError() == noErr;
766}
767
ff4aedc5 768//---------------------------------------------------------------------------
e7b97da3 769// wxQTMediaBackend::SetPosition
ff4aedc5 770//
3b5023b9
RN
771// 1) Create a time record struct (TimeRecord) with appropriate values
772// 2) Pass struct to SetMovieTime
ff4aedc5
RN
773//---------------------------------------------------------------------------
774bool wxQTMediaBackend::SetPosition(wxLongLong where)
1a680109 775{
1a680109
RN
776 TimeRecord theTimeRecord;
777 memset(&theTimeRecord, 0, sizeof(TimeRecord));
ff4aedc5 778 theTimeRecord.value.lo = where.GetValue();
1a680109
RN
779 theTimeRecord.scale = ::GetMovieTimeScale(m_movie);
780 theTimeRecord.base = ::GetMovieTimeBase(m_movie);
781 ::SetMovieTime(m_movie, &theTimeRecord);
782
783 if (::GetMoviesError() != noErr)
784 return false;
785
786 return true;
787}
788
ff4aedc5 789//---------------------------------------------------------------------------
e7b97da3 790// wxQTMediaBackend::GetPosition
ff4aedc5 791//
3b5023b9 792// Calls GetMovieTime
ff4aedc5
RN
793//---------------------------------------------------------------------------
794wxLongLong wxQTMediaBackend::GetPosition()
1a680109 795{
1a680109
RN
796 return ::GetMovieTime(m_movie, NULL);
797}
798
ff4aedc5 799//---------------------------------------------------------------------------
c5191fbd
VZ
800// wxQTMediaBackend::GetVolume
801//
802// Gets the volume through GetMovieVolume - which returns a 16 bit short -
803//
804// +--------+--------+
805// + (1) + (2) +
806// +--------+--------+
807//
808// (1) first 8 bits are value before decimal
809// (2) second 8 bits are value after decimal
810//
811// Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
812// 1 (full gain and sound)
813//---------------------------------------------------------------------------
814double wxQTMediaBackend::GetVolume()
815{
bf354396 816 short sVolume = ::GetMovieVolume(m_movie);
c5191fbd 817
9419b0d6 818 if (sVolume & (128 << 8)) //negative - no sound
c5191fbd
VZ
819 return 0.0;
820
9419b0d6 821 return sVolume / 256.0;
c5191fbd
VZ
822}
823
824//---------------------------------------------------------------------------
825// wxQTMediaBackend::SetVolume
826//
827// Sets the volume through SetMovieVolume - which takes a 16 bit short -
828//
829// +--------+--------+
830// + (1) + (2) +
831// +--------+--------+
832//
833// (1) first 8 bits are value before decimal
834// (2) second 8 bits are value after decimal
835//
836// Volume ranges from -1.0 (gain but no sound), 0 (no sound and no gain) to
837// 1 (full gain and sound)
838//---------------------------------------------------------------------------
839bool wxQTMediaBackend::SetVolume(double dVolume)
840{
bf354396 841 ::SetMovieVolume(m_movie, (short) (dVolume * 256));
c5191fbd
VZ
842 return true;
843}
9419b0d6
DS
844
845//---------------------------------------------------------------------------
e7b97da3 846// wxQTMediaBackend::GetDuration
ff4aedc5 847//
3b5023b9 848// Calls GetMovieDuration
ff4aedc5
RN
849//---------------------------------------------------------------------------
850wxLongLong wxQTMediaBackend::GetDuration()
1a680109 851{
1a680109
RN
852 return ::GetMovieDuration(m_movie);
853}
854
ff4aedc5 855//---------------------------------------------------------------------------
e7b97da3 856// wxQTMediaBackend::GetState
ff4aedc5 857//
3b5023b9
RN
858// Determines the current state - the timer keeps track of whether or not
859// we are paused or stopped (if the timer is running we are playing)
ff4aedc5
RN
860//---------------------------------------------------------------------------
861wxMediaState wxQTMediaBackend::GetState()
1a680109 862{
bf354396 863 // Could use
9419b0d6 864 // GetMovieActive/IsMovieDone/SetMovieActive
bf354396 865 // combo if implemented that way
9419b0d6 866 if (m_bPlaying)
1a680109 867 return wxMEDIASTATE_PLAYING;
0c81ef7f 868 else if (!m_movie || wxQTMediaBackend::GetPosition() == 0)
bf354396 869 return wxMEDIASTATE_STOPPED;
1a680109
RN
870 else
871 return wxMEDIASTATE_PAUSED;
872}
873
ff4aedc5 874//---------------------------------------------------------------------------
e7b97da3 875// wxQTMediaBackend::Cleanup
ff4aedc5 876//
3b5023b9
RN
877// Diposes of the movie timer, Control if native, and stops and disposes
878// of the QT movie
ff4aedc5
RN
879//---------------------------------------------------------------------------
880void wxQTMediaBackend::Cleanup()
1a680109 881{
bf354396 882 m_bPlaying = false;
9419b0d6 883 if (m_timer)
bf354396 884 {
9419b0d6
DS
885 delete m_timer;
886 m_timer = NULL;
bf354396 887 }
d0ee33f5 888
9419b0d6 889 // Stop the movie:
bf354396
VZ
890 // Apple samples with CreateMovieControl typically
891 // install a event handler and do this on the dispose
892 // event, but we do it here for simplicity
893 // (It might keep playing for several seconds after
9419b0d6 894 // control destruction if not)
bf354396 895 wxQTMediaBackend::Pause();
9419b0d6 896
bf354396 897 // Dispose of control or remove movie from MovieController
bf354396
VZ
898 Point thePoint;
899 thePoint.h = thePoint.v = 0;
900 ::MCSetVisible(m_mc, false);
901 ::MCSetMovie(m_mc, NULL, NULL, thePoint);
1a680109 902
bf354396 903 ::DisposeMovie(m_movie);
9419b0d6 904 m_movie = NULL;
bf354396
VZ
905}
906
ff4aedc5 907//---------------------------------------------------------------------------
e7b97da3 908// wxQTMediaBackend::GetVideoSize
ff4aedc5 909//
3b5023b9 910// Returns the actual size of the QT movie
ff4aedc5
RN
911//---------------------------------------------------------------------------
912wxSize wxQTMediaBackend::GetVideoSize() const
1a680109
RN
913{
914 return m_bestSize;
915}
916
ff4aedc5
RN
917//---------------------------------------------------------------------------
918// wxQTMediaBackend::Move
919//
557002cf
VZ
920// Move the movie controller or movie control
921// (we need to actually move the movie control manually...)
922// Top 10 things to do with quicktime in March 93's issue
923// of DEVELOP - very useful
924// http:// www.mactech.com/articles/develop/issue_13/031-033_QuickTime_column.html
925// OLD NOTE: Calling MCSetControllerBoundsRect without detaching
926// supposively resulted in a crash back then. Current code even
927// with CFM classic runs fine. If there is ever a problem,
928// take out the if 0 lines below
ff4aedc5
RN
929//---------------------------------------------------------------------------
930void wxQTMediaBackend::Move(int x, int y, int w, int h)
1a680109 931{
9419b0d6 932 if (m_timer)
1a680109 933 {
9419b0d6
DS
934 m_ctrl->GetParent()->MacWindowToRootWindow(&x, &y);
935 Rect theRect = {y, x, y + h, x + w};
936
0c81ef7f 937#if 0 // see note above
9419b0d6
DS
938 ::MCSetControllerAttached(m_mc, false);
939 wxASSERT(::GetMoviesError() == noErr);
557002cf 940#endif
9419b0d6 941
bf354396 942 ::MCSetControllerBoundsRect(m_mc, &theRect);
1a680109 943 wxASSERT(::GetMoviesError() == noErr);
557002cf
VZ
944
945#if 0 // see note above
9419b0d6 946 if (m_interfaceflags)
557002cf 947 {
9419b0d6
DS
948 ::MCSetVisible(m_mc, true);
949 wxASSERT(::GetMoviesError() == noErr);
950 }
557002cf 951#endif
1a680109
RN
952 }
953}
954
bf354396
VZ
955//---------------------------------------------------------------------------
956// wxQTMediaBackend::DoSetControllerVisible
957//
958// Utility function that takes care of showing the moviecontroller
959// and showing/hiding the particular controls on it
960//---------------------------------------------------------------------------
0c81ef7f
SC
961void wxQTMediaBackend::DoSetControllerVisible(
962 wxMediaCtrlPlayerControls flags)
9419b0d6
DS
963{
964 ::MCSetVisible(m_mc, true);
965
bf354396 966 // Take care of subcontrols
9419b0d6 967 if (::GetMoviesError() == noErr)
bf354396
VZ
968 {
969 long mcFlags = 0;
970 ::MCDoAction(m_mc, 39/*mcActionGetFlags*/, (void*)&mcFlags);
9419b0d6
DS
971
972 if (::GetMoviesError() == noErr)
973 {
bf354396 974 mcFlags |= ( //(1<<0)/*mcFlagSuppressMovieFrame*/ |
9419b0d6 975 (1 << 3)/*mcFlagsUseWindowPalette*/
bf354396 976 | ((flags & wxMEDIACTRLPLAYERCONTROLS_STEP)
9419b0d6 977 ? 0 : (1 << 1)/*mcFlagSuppressStepButtons*/)
bf354396 978 | ((flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME)
9419b0d6 979 ? 0 : (1 << 2)/*mcFlagSuppressSpeakerButton*/)
0c81ef7f 980 //if we take care of repainting ourselves
987e9419 981 // | (1 << 4) /*mcFlagDontInvalidate*/
bf354396 982 );
9419b0d6
DS
983
984 ::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags);
bf354396 985 }
9419b0d6
DS
986 }
987
988 // Adjust height and width of best size for movie controller
989 // if the user wants it shown
bf354396
VZ
990 m_bestSize.x = m_bestSize.x > wxMCWIDTH ? m_bestSize.x : wxMCWIDTH;
991 m_bestSize.y += wxMCHEIGHT;
992}
993
994//---------------------------------------------------------------------------
995// wxQTMediaBackend::ShowPlayerControls
996//
997// Shows/Hides subcontrols on the media control
998//---------------------------------------------------------------------------
999bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
1000{
9419b0d6
DS
1001 if (!m_mc)
1002 return false; // no movie controller...
1003
bf354396 1004 bool bSizeChanged = false;
9419b0d6
DS
1005
1006 // if the controller is visible and we want to hide it do so
1007 if (m_interfaceflags && !flags)
bf354396
VZ
1008 {
1009 bSizeChanged = true;
1010 DoLoadBestSize();
9419b0d6 1011 ::MCSetVisible(m_mc, false);
bf354396 1012 }
9419b0d6 1013 else if (!m_interfaceflags && flags) // show controller if hidden
bf354396
VZ
1014 {
1015 bSizeChanged = true;
1016 DoSetControllerVisible(flags);
1017 }
9419b0d6
DS
1018
1019 // readjust parent sizers
1020 if (bSizeChanged)
bf354396 1021 {
9419b0d6
DS
1022 NotifyMovieSizeChanged();
1023
1024 // remember state in case of loading new media
bf354396 1025 m_interfaceflags = flags;
9419b0d6
DS
1026 }
1027
557002cf
VZ
1028 return ::GetMoviesError() == noErr;
1029}
1030
1031//---------------------------------------------------------------------------
1032// wxQTMediaBackend::GetDataSizeFromStart
1033//
1034// Calls either GetMovieDataSize or GetMovieDataSize64 with a value
1035// of 0 for the starting value
1036//---------------------------------------------------------------------------
1037wxLongLong wxQTMediaBackend::GetDataSizeFromStart(TimeValue end)
1038{
1039#if 0 // old pre-qt4 way
1040 return ::GetMovieDataSize(m_movie, 0, end)
1041#else // qt4 way
1042 wide llDataSize;
1043 ::GetMovieDataSize64(m_movie, 0, end, &llDataSize);
1044 return wxLongLong(llDataSize.hi, llDataSize.lo);
1045#endif
1046}
1047
1048//---------------------------------------------------------------------------
1049// wxQTMediaBackend::GetDownloadProgress
1050//---------------------------------------------------------------------------
1051wxLongLong wxQTMediaBackend::GetDownloadProgress()
1052{
1053#if 0 // hackish and slow
1054 Handle hMovie = NewHandle(0);
1055 PutMovieIntoHandle(m_movie, hMovie);
1056 long lSize = GetHandleSize(hMovie);
1057 DisposeHandle(hMovie);
9419b0d6 1058
557002cf
VZ
1059 return lSize;
1060#else
1061 TimeValue tv;
9419b0d6 1062 if (::GetMaxLoadedTimeInMovie(m_movie, &tv) != noErr)
557002cf
VZ
1063 {
1064 wxLogDebug(wxT("GetMaxLoadedTimeInMovie failed"));
1065 return 0;
592a247d 1066 }
9419b0d6 1067
557002cf
VZ
1068 return wxQTMediaBackend::GetDataSizeFromStart(tv);
1069#endif
1070}
592a247d 1071
557002cf
VZ
1072//---------------------------------------------------------------------------
1073// wxQTMediaBackend::GetDownloadTotal
1074//---------------------------------------------------------------------------
1075wxLongLong wxQTMediaBackend::GetDownloadTotal()
1076{
987e9419
WS
1077 return wxQTMediaBackend::GetDataSizeFromStart(
1078 ::GetMovieDuration(m_movie)
0c81ef7f
SC
1079 );
1080}
1081
1082//---------------------------------------------------------------------------
1083// wxQTMediaBackend::MacVisibilityChanged
1084//
1085// The main problem here is that Windows quicktime, for example,
1086// renders more directly to a HWND. Mac quicktime does not do this
1087// and instead renders to the port of the WindowRef/WindowPtr on top
1088// of everything else/all other windows.
1089//
1090// So, for example, if you were to have a CreateTabsControl/wxNotebook
1091// and change pages, even if you called HIViewSetVisible/SetControlVisibility
1092// directly the movie will still continue playing on top of everything else
1093// if you went to a different tab.
1094//
1095// Note that another issue, and why we call MCSetControllerPort instead
1096// of SetMovieGWorld directly, is that in addition to rendering on
1097// top of everything else the last created controller steals mouse and
1098// other input from everything else in the window, including other
1099// controllers. Setting the port of it releases this behaviour.
1100//---------------------------------------------------------------------------
1101void wxQTMediaBackend::MacVisibilityChanged()
1102{
1103 if(!m_mc || !m_ctrl->m_bLoaded)
1104 return; //not initialized yet
987e9419 1105
0c81ef7f
SC
1106 if(m_ctrl->MacIsReallyShown())
1107 {
1108 //The window is being shown again, so set the GWorld of the
1109 //controller back to the port of the parent WindowRef
987e9419 1110 WindowRef wrTLW =
0c81ef7f
SC
1111 (WindowRef) m_ctrl->MacGetTopLevelWindowRef();
1112
1113 ::MCSetControllerPort(m_mc, (CGrafPtr) GetWindowPort(wrTLW));
1114 wxASSERT(::GetMoviesError() == noErr);
1115 }
1116 else
1117 {
1118 //We are being hidden - set the GWorld of the controller
1119 //to the offscreen GWorld
1120 ::MCSetControllerPort(m_mc, m_movieWorld);
987e9419 1121 wxASSERT(::GetMoviesError() == noErr);
0c81ef7f 1122 }
bf354396
VZ
1123}
1124
1125//---------------------------------------------------------------------------
1126// wxQTMediaBackend::OnEraseBackground
1127//
1128// Suggestion from Greg Hazel to repaint the movie when idle
1129// (on pause also)
1130//---------------------------------------------------------------------------
bf354396
VZ
1131void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
1132{
9419b0d6 1133 // Work around Nasty OSX drawing bug:
bf354396 1134 // http://lists.apple.com/archives/QuickTime-API/2002/Feb/msg00311.html
9419b0d6 1135 WindowRef wrTLW = (WindowRef) m_qtb->m_ctrl->MacGetTopLevelWindowRef();
bf354396 1136
0c81ef7f
SC
1137 RgnHandle region = ::MCGetControllerBoundsRgn(m_qtb->m_mc);
1138 ::MCInvalidate(m_qtb->m_mc, wrTLW, region);
1139 ::MCIdle(m_qtb->m_mc);
1140}
1141
1142//---------------------------------------------------------------------------
1143// wxQTMediaBackend::PPRMProc (static)
1144//
1145// Called when done PrePrerolling the movie.
1146// Note that in 99% of the cases this does nothing...
1147// Anyway we set up the loading timer here to tell us when the movie is done
1148//---------------------------------------------------------------------------
1149pascal void wxQTMediaBackend::PPRMProc(
1150 Movie theMovie,
1151 OSErr WXUNUSED_UNLESS_DEBUG(theErr),
1152 void* theRefCon)
1153{
1154 wxASSERT( theMovie );
1155 wxASSERT( theRefCon );
1156 wxASSERT( theErr == noErr );
1157
1158 wxQTMediaBackend* pBE = (wxQTMediaBackend*) theRefCon;
1159
1160 long lTime = ::GetMovieTime(theMovie,NULL);
1161 Fixed rate = ::GetMoviePreferredRate(theMovie);
1162 ::PrerollMovie(theMovie,lTime,rate);
1163 pBE->m_timer = new wxQTMediaLoadTimer(pBE);
1164 pBE->m_timer->Start(MOVIE_DELAY);
bf354396 1165}
bf354396
VZ
1166
1167//---------------------------------------------------------------------------
0c81ef7f
SC
1168// wxQTMediaBackend::MCFilterProc (static)
1169//
1170// Callback for when the movie controller recieves a message
1171//---------------------------------------------------------------------------
1172pascal Boolean wxQTMediaBackend::MCFilterProc(
1173 MovieController WXUNUSED(theController),
1174 short action,
1175 void * WXUNUSED(params),
1176 long refCon)
1177{
1178 wxQTMediaBackend* pThis = (wxQTMediaBackend*)refCon;
1179
1180 switch (action)
1181 {
1182 case 1:
1183 // don't process idle events
1184 break;
1185
1186 case 8:
1187 // play button triggered - MC will set movie to opposite state
1188 // of current - playing ? paused : playing
1189 pThis->m_bPlaying = !(pThis->m_bPlaying);
1190 break;
1191
1192 default:
1193 break;
1194 }
1195
1196 return 0;
1197}
1198
1199//---------------------------------------------------------------------------
1200// wxQTMediaBackend::WindowEventHandler [static]
bf354396
VZ
1201//
1202// Event callback for the top level window of our control that passes
9419b0d6 1203// messages to our moviecontroller so it can receive mouse clicks etc.
bf354396 1204//---------------------------------------------------------------------------
0c81ef7f 1205pascal OSStatus wxQTMediaBackend::WindowEventHandler(
9419b0d6
DS
1206 EventHandlerCallRef inHandlerCallRef,
1207 EventRef inEvent,
1208 void *inUserData)
bf354396 1209{
0c81ef7f 1210 wxQTMediaBackend* be = (wxQTMediaBackend*) inUserData;
987e9419 1211
0c81ef7f
SC
1212 // Only process keyboard messages on this window if it actually
1213 // has focus, otherwise it will steal keystrokes from other windows!
1214 // As well as when it is not loaded properly as it
1215 // will crash in MCIsPlayerEvent
1216 if((GetEventClass(inEvent) == kEventClassKeyboard &&
987e9419 1217 wxWindow::FindFocus() != be->m_ctrl)
0c81ef7f 1218 || !be->m_ctrl->m_bLoaded)
557002cf 1219 return eventNotHandledErr;
9419b0d6 1220
0c81ef7f 1221 // Pass the event onto the movie controller
bf354396
VZ
1222 EventRecord theEvent;
1223 ConvertEventRefToEventRecord( inEvent, &theEvent );
1224 OSStatus err;
592a247d 1225
987e9419 1226 // TODO: Apple says MCIsPlayerEvent is depreciated and
0c81ef7f
SC
1227 // MCClick, MCKey, MCIdle etc. should be used
1228 // (RN: Of course that's what they say about
1229 // CreateMovieControl and HIMovieView as well, LOL!)
1230 err = ::MCIsPlayerEvent( be->m_mc, &theEvent );
9419b0d6 1231
0c81ef7f 1232 // Pass on to other event handlers if not handled- i.e. wx
9419b0d6 1233 if (err != noErr)
bf354396
VZ
1234 return noErr;
1235 else
1236 return eventNotHandledErr;
1237}
ff4aedc5 1238
9419b0d6 1239// in source file that contains stuff you don't directly use
f572d649 1240#include "wx/html/forcelnk.h"
412e0d47 1241FORCE_LINK_ME(basewxmediabackends)
ff4aedc5 1242
9419b0d6 1243#endif // wxUSE_MEDIACTRL