]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/moviectrl.cpp
db687e759ca1eb9055bcf002e84dec33119a93ea
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
);
33 BEGIN_EVENT_TABLE(wxMovieCtrl
, wxControl
)
34 EVT_SIZE(wxMovieCtrl::OnSize
)
39 #include "wx/mac/uma.h"
44 //quicktime media layer only required for mac emulation on pc
49 #include <QuickTimeComponents.h>
51 //Time between timer calls
52 #define MOVIE_DELAY 100
54 // ------------------------------------------------------------------
55 // wxQTTimer - Handle Asyncronous Playing
56 // ------------------------------------------------------------------
57 class _wxQTTimer
: public wxTimer
60 _wxQTTimer(Movie movie
) :
61 m_movie(movie
), m_bPaused(false)
69 bool GetPaused() {return m_bPaused
;}
70 void SetPaused(bool bPaused
) {m_bPaused
= bPaused
;}
76 if(!IsMovieDone(m_movie
))
77 MoviesTask(m_movie
, MOVIE_DELAY
); //Give QT time to play movie
88 //Determines whether version 3 of QT is installed
89 Boolean
wxIsQuickTime3Installed (void)
95 error
= Gestalt (gestaltQuickTime
, &result
);
96 return (error
== noErr
) && (((result
>> 16) & 0xffff) >= 0x0300);
102 bool wxMovieCtrl::InitQT ()
104 if (wxIsQuickTime3Installed())
109 if ((nError
= InitializeQTML(0)) != noErr
)
111 wxFAIL_MSG(wxString::Format(wxT("Couldn't Initialize Quicktime-%i"), nError
));
119 wxFAIL_MSG(wxT("Quicktime is not installed, or Your Version of Quicktime is <= 4."));
124 bool wxMovieCtrl::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& fileName
,
125 const wxString
& label
, const wxPoint
& pos
, const wxSize
& size
,
126 long WXUNUSED(style
), const wxString
& name
)
135 wxMacFilename2FSSpec( m_sndname
, &sfFile
) ;
138 if ((nError
= NativePathNameToFSSpec ((char*) fileName
.c_str(), &sfFile
, 0)) != noErr
)
140 wxFAIL_MSG(wxString::Format(wxT("File:%s does not exist\nError:%i"),
141 fileName
.c_str(), nError
));
145 if (OpenMovieFile (&sfFile
, &movieResFile
, fsRdPerm
) != noErr
)
147 wxFAIL_MSG(wxT("Quicktime couldn't open the file"));
150 short movieResID
= 0;
153 err
= NewMovieFromFile (
161 CloseMovieFile (movieResFile
);
165 wxFAIL_MSG(wxT("Could not create movie"));
169 m_timer
= new _wxQTTimer(m_movie
);
172 //get the real size of the movie
174 ::GetMovieNaturalBoundsRect (m_movie
, &outRect
);
176 m_bestSize
.x
= outRect
.right
- outRect
.left
;
177 m_bestSize
.y
= outRect
.bottom
- outRect
.top
;
179 //do some window stuff
180 if ( !wxControl::Create(parent
, id
, pos
, size
, wxNO_BORDER
, wxDefaultValidator
, name
) )
183 //Set our background color to black by default
184 SetBackgroundColour(*wxBLACK
);
188 CreatePortAssociation(this->GetHWND(), NULL
, 0L);
190 SetMovieGWorld(m_movie
, (CGrafPtr
)
193 GetNativeWindowPort(this->GetHWND())
206 void wxMovieCtrl::SetLabel(const wxString
& label
)
208 wxControl::SetLabel(label
);
211 bool wxMovieCtrl::Play()
213 ::StartMovie(m_movie
);
214 m_timer
->SetPaused(false);
215 m_timer
->Start(MOVIE_DELAY
, wxTIMER_CONTINUOUS
);
216 return ::GetMoviesError() == noErr
;
219 bool wxMovieCtrl::Pause()
221 ::StopMovie(m_movie
);
222 m_timer
->SetPaused(true);
223 return ::GetMoviesError() == noErr
;
226 bool wxMovieCtrl::Stop()
228 m_timer
->SetPaused(false);
230 ::StopMovie(m_movie
);
231 if(::GetMoviesError() != noErr
)
234 ::GoToEndOfMovie(m_movie
);
235 return ::GetMoviesError() == noErr
;
240 bool wxMovieCtrl::Seek(const wxTimeSpan
& where
)
242 TimeRecord theTimeRecord
;
243 theTimeRecord
.value
.lo
= ((size_t)where
.GetMilliseconds().ToLong()) * 10;
244 theTimeRecord
.scale
= ::GetMovieTimeScale(m_movie
);
245 theTimeRecord
.base
= ::GetMovieTimeBase(m_movie
);
246 ::SetMovieTime(m_movie
, &theTimeRecord
);
248 if (::GetMoviesError() != noErr
)
254 #endif // wxUSE_DATETIME
256 wxMovieCtrlState
wxMovieCtrl::GetState()
258 if( m_timer
->IsRunning() == true )
259 return wxMOVIECTRL_STOPPED
;
261 if ( m_timer
->GetPaused() == false )
262 return wxMOVIECTRL_PLAYING
;
264 return wxMOVIECTRL_PAUSED
;
267 wxMovieCtrl::~wxMovieCtrl()
274 DisposeMovie(m_movie
);
276 //Note that ExitMovies() is not neccessary, but
277 //the docs are fuzzy on whether or not TerminateQTML is
286 wxSize
wxMovieCtrl::DoGetBestSize() const
291 void wxMovieCtrl::OnSize(wxSizeEvent
& evt
)
296 theRect
.bottom
= evt
.GetSize().y
;
297 theRect
.right
= evt
.GetSize().x
;
299 ::SetMovieBox(m_movie
, &theRect
);
301 wxASSERT(::GetMoviesError() == noErr
);
304 #endif //wxUSE_MOVIECTRL