]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/moviectrl.cpp
ba21a9a1d4cc13d540421c829908d71393dd1d0a
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 ::GoToBeginningOfMovie(m_movie
);
78 wxASSERT( ::GetMoviesError() == noErr
);
79 wxMovieEvent
theEvent(wxEVT_MOVIE_FINISHED
, m_parent
->GetId());
80 m_parent
->GetParent()->ProcessEvent(theEvent
);
88 wxMovieCtrl
* m_parent
;
91 //Determines whether version 3 of QT is installed
92 Boolean
wxIsQuickTime3Installed (void)
98 error
= Gestalt (gestaltQuickTime
, &result
);
99 return (error
== noErr
) && (((result
>> 16) & 0xffff) >= 0x0300);
105 bool wxMovieCtrl::InitQT ()
107 if (wxIsQuickTime3Installed())
112 if ((nError
= InitializeQTML(0)) != noErr
)
114 wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError
));
122 wxFAIL_MSG(wxT("Quicktime is not installed, or Your Version of Quicktime is <= 4."));
127 bool wxMovieCtrl::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& fileName
,
128 const wxString
& label
, const wxPoint
& pos
, const wxSize
& size
,
129 long WXUNUSED(style
), const wxString
& name
)
131 //do some window stuff
132 if ( !wxControl::Create(parent
, id
, pos
, size
, wxNO_BORDER
, wxDefaultValidator
, name
) )
135 //Set our background color to black by default
136 SetBackgroundColour(*wxBLACK
);
138 if(!fileName
.empty())
149 wxControl::SetLabel(label
);
154 bool wxMovieCtrl::Load(const wxString
& fileName
)
166 wxMacFilename2FSSpec( m_sndname
, &sfFile
) ;
169 if ((nError
= NativePathNameToFSSpec ((char*) fileName
.c_str(), &sfFile
, 0)) != noErr
)
171 wxFAIL_MSG(wxString::Format(wxT("File:%s does not exist\nError:%i"),
172 fileName
.c_str(), nError
));
176 if (OpenMovieFile (&sfFile
, &movieResFile
, fsRdPerm
) != noErr
)
178 wxFAIL_MSG(wxT("Quicktime couldn't open the file"));
181 short movieResID
= 0;
184 err
= NewMovieFromFile (
192 CloseMovieFile (movieResFile
);
196 wxFAIL_MSG(wxT("Could not create movie"));
200 m_timer
= new _wxQTTimer(m_movie
, (wxMovieCtrl
*) this);
203 //get the real size of the movie
205 ::GetMovieNaturalBoundsRect (m_movie
, &outRect
);
207 m_bestSize
.x
= outRect
.right
- outRect
.left
;
208 m_bestSize
.y
= outRect
.bottom
- outRect
.top
;
211 this->Connect( wxID_ANY
,
213 (wxObjectEventFunction
) (wxEventFunction
) (wxSizeEventFunction
) &wxMovieCtrl::OnSize
);
217 CreatePortAssociation(this->GetHWND(), NULL
, 0L);
219 SetMovieGWorld(m_movie
, (CGrafPtr
)
222 GetNativeWindowPort(this->GetHWND())
232 bool wxMovieCtrl::Play()
234 ::StartMovie(m_movie
);
235 m_timer
->SetPaused(false);
236 m_timer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
237 return ::GetMoviesError() == noErr
;
240 bool wxMovieCtrl::Pause()
242 ::StopMovie(m_movie
);
243 m_timer
->SetPaused(true);
244 return ::GetMoviesError() == noErr
;
247 bool wxMovieCtrl::Stop()
249 m_timer
->SetPaused(false);
251 ::StopMovie(m_movie
);
252 if(::GetMoviesError() != noErr
)
255 ::GoToBeginningOfMovie(m_movie
);
256 return ::GetMoviesError() == noErr
;
259 double wxMovieCtrl::GetPlaybackRate()
261 return (double) (::GetMovieTimeScale(m_movie
) / 0x10000f);
264 bool wxMovieCtrl::SetPlaybackRate(double dRate
)
266 ::SetMovieTimeScale(m_movie
, (Fixed
) (dRate
* 0x10000));
267 return ::GetMoviesError() == noErr
;
272 bool wxMovieCtrl::Seek(const wxTimeSpan
& where
)
274 TimeRecord theTimeRecord
;
275 theTimeRecord
.value
.lo
= ((size_t)where
.GetMilliseconds().ToLong()) * 10;
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
) ::GetMovieTime(m_movie
, NULL
);
291 wxTimeSpan
wxMovieCtrl::Length()
293 return (wxTimeSpan
) ::GetMovieDuration(m_movie
);
296 #endif // wxUSE_DATETIME
298 wxMovieCtrlState
wxMovieCtrl::GetState()
300 if( m_timer
->IsRunning() == true )
301 return wxMOVIECTRL_STOPPED
;
303 if ( m_timer
->GetPaused() == false )
304 return wxMOVIECTRL_PLAYING
;
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