+//---------------------------------------------------------------------------
+// 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*/)
+ //if we take care of repainting ourselves
+ // | (1 << 4) /*mcFlagDontInvalidate*/
+ );
+
+ ::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::MacVisibilityChanged
+//
+// The main problem here is that Windows quicktime, for example,
+// renders more directly to a HWND. Mac quicktime does not do this
+// and instead renders to the port of the WindowRef/WindowPtr on top
+// of everything else/all other windows.
+//
+// So, for example, if you were to have a CreateTabsControl/wxNotebook
+// and change pages, even if you called HIViewSetVisible/SetControlVisibility
+// directly the movie will still continue playing on top of everything else
+// if you went to a different tab.
+//
+// Note that another issue, and why we call MCSetControllerPort instead
+// of SetMovieGWorld directly, is that in addition to rendering on
+// top of everything else the last created controller steals mouse and
+// other input from everything else in the window, including other
+// controllers. Setting the port of it releases this behaviour.
+//---------------------------------------------------------------------------
+void wxQTMediaBackend::MacVisibilityChanged()
+{
+ if(!m_mc || !m_ctrl->m_bLoaded)
+ return; //not initialized yet
+
+ if(m_ctrl->IsShownOnScreen())
+ {
+ //The window is being shown again, so set the GWorld of the
+ //controller back to the port of the parent WindowRef
+ WindowRef wrTLW =
+ (WindowRef) m_ctrl->MacGetTopLevelWindowRef();
+
+ ::MCSetControllerPort(m_mc, (CGrafPtr) GetWindowPort(wrTLW));