]>
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
)
140 wxMacFilename2FSSpec( m_sndname
, &sfFile
) ;
143 if ((nError
= NativePathNameToFSSpec ((char*) fileName
.c_str(), &sfFile
, 0)) != noErr
)
145 wxFAIL_MSG(wxString::Format(wxT("File:%s does not exist\nError:%i"),
146 fileName
.c_str(), nError
));
150 if (OpenMovieFile (&sfFile
, &movieResFile
, fsRdPerm
) != noErr
)
152 wxFAIL_MSG(wxT("Quicktime couldn't open the file"));
155 short movieResID
= 0;
158 err
= NewMovieFromFile (
166 CloseMovieFile (movieResFile
);
170 wxFAIL_MSG(wxT("Could not create movie"));
174 m_timer
= new _wxQTTimer(m_movie
, (wxMovieCtrl
*) this);
177 //get the real size of the movie
179 ::GetMovieNaturalBoundsRect (m_movie
, &outRect
);
181 m_bestSize
.x
= outRect
.right
- outRect
.left
;
182 m_bestSize
.y
= outRect
.bottom
- outRect
.top
;
185 this->Connect( wxID_ANY
,
187 (wxObjectEventFunction
) (wxEventFunction
) (wxSizeEventFunction
) &wxMovieCtrl::OnSize
);
189 //do some window stuff
190 if ( !wxControl::Create(parent
, id
, pos
, size
, wxNO_BORDER
, wxDefaultValidator
, name
) )
193 //Set our background color to black by default
194 SetBackgroundColour(*wxBLACK
);
198 CreatePortAssociation(this->GetHWND(), NULL
, 0L);
200 SetMovieGWorld(m_movie
, (CGrafPtr
)
203 GetNativeWindowPort(this->GetHWND())
216 bool wxMovieCtrl::Play()
218 ::StartMovie(m_movie
);
219 m_timer
->SetPaused(false);
220 m_timer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
221 return ::GetMoviesError() == noErr
;
224 bool wxMovieCtrl::Pause()
226 ::StopMovie(m_movie
);
227 m_timer
->SetPaused(true);
228 return ::GetMoviesError() == noErr
;
231 bool wxMovieCtrl::Stop()
233 m_timer
->SetPaused(false);
235 ::StopMovie(m_movie
);
236 if(::GetMoviesError() != noErr
)
239 ::GoToBeginningOfMovie(m_movie
);
240 return ::GetMoviesError() == noErr
;
243 double wxMovieCtrl::GetPlaybackRate()
245 return (double) (::GetMovieTimeScale(m_movie
) / 0x10000f);
248 bool wxMovieCtrl::SetPlaybackRate(double dRate
)
250 ::SetMovieTimeScale(m_movie
, (Fixed
) (dRate
* 0x10000));
251 return ::GetMoviesError() == noErr
;
256 bool wxMovieCtrl::Seek(const wxTimeSpan
& where
)
258 TimeRecord theTimeRecord
;
259 theTimeRecord
.value
.lo
= ((size_t)where
.GetMilliseconds().ToLong()) * 10;
260 theTimeRecord
.scale
= ::GetMovieTimeScale(m_movie
);
261 theTimeRecord
.base
= ::GetMovieTimeBase(m_movie
);
262 ::SetMovieTime(m_movie
, &theTimeRecord
);
264 if (::GetMoviesError() != noErr
)
270 wxTimeSpan
wxMovieCtrl::Tell()
272 return (wxTimeSpan
) ::GetMovieTime(m_movie
, NULL
);
275 wxTimeSpan
wxMovieCtrl::Length()
277 return (wxTimeSpan
) ::GetMovieDuration(m_movie
);
280 #endif // wxUSE_DATETIME
282 wxMovieCtrlState
wxMovieCtrl::GetState()
284 if( m_timer
->IsRunning() == true )
285 return wxMOVIECTRL_STOPPED
;
287 if ( m_timer
->GetPaused() == false )
288 return wxMOVIECTRL_PLAYING
;
290 return wxMOVIECTRL_PAUSED
;
293 wxMovieCtrl::~wxMovieCtrl()
300 DisposeMovie(m_movie
);
302 //Note that ExitMovies() is not neccessary, but
303 //the docs are fuzzy on whether or not TerminateQTML is
312 wxSize
wxMovieCtrl::DoGetBestSize() const
317 void wxMovieCtrl::OnSize(wxSizeEvent
& evt
)
322 theRect
.bottom
= evt
.GetSize().y
;
323 theRect
.right
= evt
.GetSize().x
;
325 ::SetMovieBox(m_movie
, &theRect
);
327 wxASSERT(::GetMoviesError() == noErr
);
331 #endif //wxUSE_MOVIECTRL