]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/moviectrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mac/carbon/moviectrl.cpp
3 // Purpose: wxMovieCtrl MAC CARBON QT
4 // Author: Ryan Norton <wxprojects@comcast.net>
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 //#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 //#pragma implementation "moviectrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #define wxUSE_MOVIECTRL 1
27 #include "wx/moviectrl.h"
31 IMPLEMENT_CLASS(wxMovieCtrl
, wxControl
);
32 IMPLEMENT_DYNAMIC_CLASS(wxMovieEvent
, wxEvent
);
33 DEFINE_EVENT_TYPE(wxEVT_MOVIE_FINISHED
);
37 #include "wx/mac/uma.h"
42 //quicktime media layer only required for mac emulation on pc
47 #include <QuickTimeComponents.h>
49 //Time between timer calls
50 #define MOVIE_DELAY 100
52 // ------------------------------------------------------------------
53 // wxQTTimer - Handle Asyncronous Playing
54 // ------------------------------------------------------------------
55 class _wxQTTimer
: public wxTimer
58 _wxQTTimer(Movie movie
, wxMovieCtrl
* parent
) :
59 m_movie(movie
), m_bPaused(false), m_parent(parent
)
67 bool GetPaused() {return m_bPaused
;}
68 void SetPaused(bool bPaused
) {m_bPaused
= bPaused
;}
74 if(!IsMovieDone(m_movie
))
75 MoviesTask(m_movie
, MOVIE_DELAY
); //Give QT time to play movie
79 ::GoToBeginningOfMovie(m_movie
);
80 wxASSERT( ::GetMoviesError() == noErr
);
81 wxMovieEvent
theEvent(wxEVT_MOVIE_FINISHED
, m_parent
->GetId());
82 m_parent
->GetParent()->ProcessEvent(theEvent
);
90 wxMovieCtrl
* m_parent
;
93 //Determines whether version 3 of QT is installed
94 Boolean
wxIsQuickTime3Installed (void)
100 error
= Gestalt (gestaltQuickTime
, &result
);
101 return (error
== noErr
) && (((result
>> 16) & 0xffff) >= 0x0300);
107 bool wxMovieCtrl::InitQT ()
109 if (wxIsQuickTime3Installed())
114 if ((nError
= InitializeQTML(0)) != noErr
)
116 wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError
));
124 wxFAIL_MSG(wxT("Quicktime is not installed, or Your Version of Quicktime is <= 4."));
129 bool wxMovieCtrl::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& fileName
,
130 const wxString
& label
, const wxPoint
& pos
, const wxSize
& size
,
131 long WXUNUSED(style
), const wxString
& name
)
133 //do some window stuff
134 if ( !wxControl::Create(parent
, id
, pos
, size
, wxNO_BORDER
, wxDefaultValidator
, name
) )
137 //Set our background color to black by default
138 SetBackgroundColour(*wxBLACK
);
140 if(!fileName
.empty())
151 wxControl::SetLabel(label
);
156 bool wxMovieCtrl::Load(const wxString
& fileName
)
168 wxMacFilename2FSSpec( m_sndname
, &sfFile
) ;
171 if ((nError
= NativePathNameToFSSpec ((char*) fileName
.c_str(), &sfFile
, 0)) != noErr
)
173 wxFAIL_MSG(wxString::Format(wxT("File:%s does not exist\nError:%i"),
174 fileName
.c_str(), nError
));
178 if (OpenMovieFile (&sfFile
, &movieResFile
, fsRdPerm
) != noErr
)
180 wxFAIL_MSG(wxT("Quicktime couldn't open the file"));
183 short movieResID
= 0;
186 err
= NewMovieFromFile (
194 CloseMovieFile (movieResFile
);
198 wxFAIL_MSG(wxT("Could not create movie"));
202 m_timer
= new _wxQTTimer(m_movie
, (wxMovieCtrl
*) this);
205 //get the real size of the movie
207 ::GetMovieNaturalBoundsRect (m_movie
, &outRect
);
209 m_bestSize
.x
= outRect
.right
- outRect
.left
;
210 m_bestSize
.y
= outRect
.bottom
- outRect
.top
;
213 this->Connect( wxID_ANY
,
215 (wxObjectEventFunction
) (wxEventFunction
) (wxSizeEventFunction
) &wxMovieCtrl::OnSize
);
219 CreatePortAssociation(this->GetHWND(), NULL
, 0L);
221 SetMovieGWorld(m_movie
, (CGrafPtr
)
224 GetNativeWindowPort(this->GetHWND())
234 bool wxMovieCtrl::Play()
236 ::StartMovie(m_movie
);
237 m_timer
->SetPaused(false);
238 m_timer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
239 return ::GetMoviesError() == noErr
;
242 bool wxMovieCtrl::Pause()
244 ::StopMovie(m_movie
);
245 m_timer
->SetPaused(true);
246 return ::GetMoviesError() == noErr
;
249 bool wxMovieCtrl::Stop()
251 m_timer
->SetPaused(false);
253 ::StopMovie(m_movie
);
254 if(::GetMoviesError() != noErr
)
257 ::GoToBeginningOfMovie(m_movie
);
258 return ::GetMoviesError() == noErr
;
261 double wxMovieCtrl::GetPlaybackRate()
263 return (double) (::GetMovieTimeScale(m_movie
) / 0x10000f);
266 bool wxMovieCtrl::SetPlaybackRate(double dRate
)
268 ::SetMovieTimeScale(m_movie
, (Fixed
) (dRate
* 0x10000));
269 return ::GetMoviesError() == noErr
;
274 bool wxMovieCtrl::Seek(const wxTimeSpan
& where
)
276 TimeRecord theTimeRecord
;
277 theTimeRecord
.value
.lo
= ((size_t)where
.GetMilliseconds().ToLong()) * 10;
278 theTimeRecord
.scale
= ::GetMovieTimeScale(m_movie
);
279 theTimeRecord
.base
= ::GetMovieTimeBase(m_movie
);
280 ::SetMovieTime(m_movie
, &theTimeRecord
);
282 if (::GetMoviesError() != noErr
)
288 wxTimeSpan
wxMovieCtrl::Tell()
290 return (wxTimeSpan
) ::GetMovieTime(m_movie
, NULL
);
293 wxTimeSpan
wxMovieCtrl::Length()
295 return (wxTimeSpan
) ::GetMovieDuration(m_movie
);
298 #endif // wxUSE_DATETIME
300 wxMovieCtrlState
wxMovieCtrl::GetState()
302 if( m_timer
->IsRunning() == true )
303 return wxMOVIECTRL_STOPPED
;
305 if ( m_timer
->GetPaused() == false )
306 return wxMOVIECTRL_PLAYING
;
308 return wxMOVIECTRL_PAUSED
;
311 void wxMovieCtrl::Cleanup()
314 this->Disconnect( wxID_ANY
,
316 (wxObjectEventFunction
) (wxEventFunction
) (wxSizeEventFunction
) &wxMovieCtrl::OnSize
);
321 DisposeMovie(m_movie
);
323 //Note that ExitMovies() is not neccessary, but
324 //the docs are fuzzy on whether or not TerminateQTML is
332 wxMovieCtrl::~wxMovieCtrl()
338 wxSize
wxMovieCtrl::DoGetBestSize() const
343 void wxMovieCtrl::OnSize(wxSizeEvent
& evt
)
348 theRect
.bottom
= evt
.GetSize().y
;
349 theRect
.right
= evt
.GetSize().x
;
351 ::SetMovieBox(m_movie
, &theRect
);
353 wxASSERT(::GetMoviesError() == noErr
);
357 #endif //wxUSE_MOVIECTRL