]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/moviectrl.cpp
9b8aba6d0a6451118c44d5591985c9c4a3d36a7b
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"
25 #include "wx/moviectrl.h"
29 IMPLEMENT_CLASS(wxMovieCtrl
, wxControl
);
30 IMPLEMENT_DYNAMIC_CLASS(wxMovieEvent
, wxEvent
);
31 DEFINE_EVENT_TYPE(wxEVT_MOVIE_FINISHED
);
35 #include "wx/mac/uma.h"
40 //quicktime media layer only required for mac emulation on pc
45 #include <QuickTimeComponents.h>
47 //Time between timer calls
48 #define MOVIE_DELAY 100
50 // ------------------------------------------------------------------
51 // wxQTTimer - Handle Asyncronous Playing
52 // ------------------------------------------------------------------
53 class _wxQTTimer
: public wxTimer
56 _wxQTTimer(Movie movie
, wxMovieCtrl
* parent
) :
57 m_movie(movie
), m_bPaused(false), m_parent(parent
)
65 bool GetPaused() {return m_bPaused
;}
66 void SetPaused(bool bPaused
) {m_bPaused
= bPaused
;}
72 if(!IsMovieDone(m_movie
))
73 MoviesTask(m_movie
, MOVIE_DELAY
); //Give QT time to play movie
77 wxMovieEvent
theEvent(wxEVT_MOVIE_FINISHED
, m_parent
->GetId());
78 m_parent
->GetParent()->ProcessEvent(theEvent
);
86 wxMovieCtrl
* m_parent
;
89 //Determines whether version 3 of QT is installed
90 Boolean
wxIsQuickTime3Installed (void)
96 error
= Gestalt (gestaltQuickTime
, &result
);
97 return (error
== noErr
) && (((result
>> 16) & 0xffff) >= 0x0300);
103 bool wxMovieCtrl::InitQT ()
105 if (wxIsQuickTime3Installed())
110 if ((nError
= InitializeQTML(0)) != noErr
)
112 wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError
));
120 wxFAIL_MSG(wxT("Quicktime is not installed, or Your Version of Quicktime is <= 4."));
125 bool wxMovieCtrl::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& fileName
,
126 const wxString
& label
, const wxPoint
& pos
, const wxSize
& size
,
127 long WXUNUSED(style
), const wxString
& name
)
129 //do some window stuff
130 if ( !wxControl::Create(parent
, id
, pos
, size
, wxNO_BORDER
, wxDefaultValidator
, name
) )
133 //Set our background color to black by default
134 SetBackgroundColour(*wxBLACK
);
136 if(!fileName
.empty())
147 wxControl::SetLabel(label
);
152 bool wxMovieCtrl::Load(const wxString
& fileName
)
164 wxMacFilename2FSSpec( m_sndname
, &sfFile
) ;
167 if ((nError
= NativePathNameToFSSpec ((char*) fileName
.c_str(), &sfFile
, 0)) != noErr
)
169 wxFAIL_MSG(wxString::Format(wxT("File:%s does not exist\nError:%i"),
170 fileName
.c_str(), nError
));
174 if (OpenMovieFile (&sfFile
, &movieResFile
, fsRdPerm
) != noErr
)
176 wxFAIL_MSG(wxT("Quicktime couldn't open the file"));
179 short movieResID
= 0;
182 err
= NewMovieFromFile (
190 CloseMovieFile (movieResFile
);
194 wxFAIL_MSG(wxT("Could not create movie"));
198 m_timer
= new _wxQTTimer(m_movie
, (wxMovieCtrl
*) this);
201 //get the real size of the movie
203 ::GetMovieNaturalBoundsRect (m_movie
, &outRect
);
205 m_bestSize
.x
= outRect
.right
- outRect
.left
;
206 m_bestSize
.y
= outRect
.bottom
- outRect
.top
;
209 this->Connect( wxID_ANY
,
211 (wxObjectEventFunction
) (wxEventFunction
) (wxSizeEventFunction
) &wxMovieCtrl::OnSize
);
215 CreatePortAssociation(this->GetHWND(), NULL
, 0L);
217 SetMovieGWorld(m_movie
, (CGrafPtr
)
220 GetNativeWindowPort(this->GetHWND())
230 bool wxMovieCtrl::Play()
232 ::StartMovie(m_movie
);
233 m_timer
->SetPaused(false);
234 m_timer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
235 return ::GetMoviesError() == noErr
;
238 bool wxMovieCtrl::Pause()
240 ::StopMovie(m_movie
);
241 m_timer
->SetPaused(true);
242 return ::GetMoviesError() == noErr
;
245 bool wxMovieCtrl::Stop()
247 m_timer
->SetPaused(false);
250 ::StopMovie(m_movie
);
251 if(::GetMoviesError() != noErr
)
254 ::GoToEndOfMovie(m_movie
);
255 return ::GetMoviesError() == noErr
;
258 double wxMovieCtrl::GetPlaybackRate()
260 return (double) (::GetMovieTimeScale(m_movie
) / 0x10000f);
263 bool wxMovieCtrl::SetPlaybackRate(double dRate
)
265 ::SetMovieTimeScale(m_movie
, (Fixed
) (dRate
* 0x10000));
266 return ::GetMoviesError() == noErr
;
271 bool wxMovieCtrl::Seek(const wxTimeSpan
& where
)
273 TimeRecord theTimeRecord
;
274 memset(&theTimeRecord
, 0, sizeof(TimeRecord
));
275 theTimeRecord
.value
.lo
= ((size_t)where
.GetMilliseconds().ToLong());
276 theTimeRecord
.scale
= ::GetMovieTimeScale(m_movie
);
277 theTimeRecord
.base
= ::GetMovieTimeBase(m_movie
);
278 ::SetMovieTime(m_movie
, &theTimeRecord
);
280 if (::GetMoviesError() != noErr
)
286 wxTimeSpan
wxMovieCtrl::Tell()
288 return wxTimeSpan(0,0,0, ::GetMovieTime(m_movie
, NULL
));
291 wxTimeSpan
wxMovieCtrl::Length()
293 return wxTimeSpan(0,0,0, ::GetMovieDuration(m_movie
));
296 #endif // wxUSE_DATETIME
298 wxMovieCtrlState
wxMovieCtrl::GetState()
300 if( m_timer
->IsRunning() == true )
301 return wxMOVIECTRL_PLAYING
;
303 if ( m_timer
->GetPaused() == false )
304 return wxMOVIECTRL_STOPPED
;
306 return wxMOVIECTRL_PAUSED
;
309 void wxMovieCtrl::Cleanup()
312 this->Disconnect( wxID_ANY
,
314 (wxObjectEventFunction
) (wxEventFunction
) (wxSizeEventFunction
) &wxMovieCtrl::OnSize
);
319 DisposeMovie(m_movie
);
321 //Note that ExitMovies() is not neccessary, but
322 //the docs are fuzzy on whether or not TerminateQTML is
330 wxMovieCtrl::~wxMovieCtrl()
336 wxSize
wxMovieCtrl::DoGetBestSize() const
341 void wxMovieCtrl::OnSize(wxSizeEvent
& evt
)
346 theRect
.bottom
= evt
.GetSize().y
;
347 theRect
.right
= evt
.GetSize().x
;
349 ::SetMovieBox(m_movie
, &theRect
);
351 wxASSERT(::GetMoviesError() == noErr
);
355 #endif //wxUSE_MOVIECTRL