+//---------------------------------------------------------------------------
+// wxQTMediaBackend::DoSetControllerVisible
+//
+// Utility function that takes care of showing the moviecontroller
+// and showing/hiding the particular controls on it
+//---------------------------------------------------------------------------
+void wxQTMediaBackend::DoSetControllerVisible(wxMediaCtrlPlayerControls flags)
+{
+ ::MCSetVisible(m_mc, true);
+
+ // Take care of subcontrols
+ if (::GetMoviesError() == noErr)
+ {
+ long mcFlags = 0;
+ ::MCDoAction(m_mc, 39/*mcActionGetFlags*/, (void*)&mcFlags);
+
+ if (::GetMoviesError() == noErr)
+ {
+ mcFlags |= ( //(1<<0)/*mcFlagSuppressMovieFrame*/ |
+ (1 << 3)/*mcFlagsUseWindowPalette*/
+ | ((flags & wxMEDIACTRLPLAYERCONTROLS_STEP)
+ ? 0 : (1 << 1)/*mcFlagSuppressStepButtons*/)
+ | ((flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME)
+ ? 0 : (1 << 2)/*mcFlagSuppressSpeakerButton*/)
+ // | (1 << 4) /*mcFlagDontInvalidate*/ //if we take care of repainting ourselves
+ );
+
+ ::MCDoAction(m_mc, 38/*mcActionSetFlags*/, (void*)mcFlags);
+ }
+ }
+
+ // Adjust height and width of best size for movie controller
+ // if the user wants it shown
+ m_bestSize.x = m_bestSize.x > wxMCWIDTH ? m_bestSize.x : wxMCWIDTH;
+ m_bestSize.y += wxMCHEIGHT;
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::ShowPlayerControls
+//
+// Shows/Hides subcontrols on the media control
+//---------------------------------------------------------------------------
+bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags)
+{
+ if (!m_mc)
+ return false; // no movie controller...
+
+ bool bSizeChanged = false;
+
+ // if the controller is visible and we want to hide it do so
+ if (m_interfaceflags && !flags)
+ {
+ bSizeChanged = true;
+ DoLoadBestSize();
+ ::MCSetVisible(m_mc, false);
+ }
+ else if (!m_interfaceflags && flags) // show controller if hidden
+ {
+ bSizeChanged = true;
+ DoSetControllerVisible(flags);
+ }
+
+ // readjust parent sizers
+ if (bSizeChanged)
+ {
+ NotifyMovieSizeChanged();
+
+ // remember state in case of loading new media
+ m_interfaceflags = flags;
+ }
+
+ return ::GetMoviesError() == noErr;
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::GetDataSizeFromStart
+//
+// Calls either GetMovieDataSize or GetMovieDataSize64 with a value
+// of 0 for the starting value
+//---------------------------------------------------------------------------
+wxLongLong wxQTMediaBackend::GetDataSizeFromStart(TimeValue end)
+{
+#if 0 // old pre-qt4 way
+ return ::GetMovieDataSize(m_movie, 0, end)
+#else // qt4 way
+ wide llDataSize;
+ ::GetMovieDataSize64(m_movie, 0, end, &llDataSize);
+ return wxLongLong(llDataSize.hi, llDataSize.lo);
+#endif
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::GetDownloadProgress
+//---------------------------------------------------------------------------
+wxLongLong wxQTMediaBackend::GetDownloadProgress()
+{
+#if 0 // hackish and slow
+ Handle hMovie = NewHandle(0);
+ PutMovieIntoHandle(m_movie, hMovie);
+ long lSize = GetHandleSize(hMovie);
+ DisposeHandle(hMovie);
+
+ return lSize;
+#else
+ TimeValue tv;
+ if (::GetMaxLoadedTimeInMovie(m_movie, &tv) != noErr)
+ {
+ wxLogDebug(wxT("GetMaxLoadedTimeInMovie failed"));
+ return 0;
+ }
+
+ return wxQTMediaBackend::GetDataSizeFromStart(tv);
+#endif
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::GetDownloadTotal
+//---------------------------------------------------------------------------
+wxLongLong wxQTMediaBackend::GetDownloadTotal()
+{
+ return wxQTMediaBackend::GetDataSizeFromStart( ::GetMovieDuration(m_movie) );
+}
+
+//---------------------------------------------------------------------------
+// wxQTMediaBackend::OnEraseBackground
+//
+// Suggestion from Greg Hazel to repaint the movie when idle
+// (on pause also)
+//---------------------------------------------------------------------------
+#if !wxUSE_CREATEMOVIECONTROL
+void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
+{
+ // Work around Nasty OSX drawing bug:
+ // http://lists.apple.com/archives/QuickTime-API/2002/Feb/msg00311.html
+ WindowRef wrTLW = (WindowRef) m_qtb->m_ctrl->MacGetTopLevelWindowRef();
+
+ RgnHandle region = MCGetControllerBoundsRgn(m_qtb->m_mc);
+ MCInvalidate(m_qtb->m_mc, wrTLW, region);
+ MCIdle(m_qtb->m_mc);
+}
+#endif
+
+//---------------------------------------------------------------------------
+// wxQTMediaWindowEventHandler
+//
+// Event callback for the top level window of our control that passes
+// messages to our moviecontroller so it can receive mouse clicks etc.
+//---------------------------------------------------------------------------
+#if !wxUSE_CREATEMOVIECONTROL
+static pascal OSStatus wxQTMediaWindowEventHandler(
+ EventHandlerCallRef inHandlerCallRef,
+ EventRef inEvent,
+ void *inUserData)
+{
+ // for the overly paranoid....
+#if 0
+ UInt32 eventClass = GetEventClass( eventRef );
+ UInt32 eventKind = GetEventKind( inEvent );
+
+ if (eventKind != kEventMouseDown &&
+ eventKind != kEventMouseUp &&
+ eventKind != kEventMouseDragged &&
+ eventKind != kEventRawKeyDown &&
+ eventKind != kEventRawKeyRepeat &&
+ eventKind != kEventRawKeyUp &&
+ eventKind != kEventWindowUpdate &&
+ eventKind != kEventWindowActivated &&
+ eventKind != kEventWindowDeactivated)
+ return eventNotHandledErr;
+#endif
+
+ EventRecord theEvent;
+ ConvertEventRefToEventRecord( inEvent, &theEvent );
+ OSStatus err;
+
+ err = ::MCIsPlayerEvent( (MovieController) inUserData, &theEvent );
+
+ // pass on to other event handlers if not handled- i.e. wx
+ if (err != noErr)
+ return noErr;
+ else
+ return eventNotHandledErr;
+}
+#endif