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