From 9180b5352f9d5b5bcccee563e9b3c0f68c4f1303 Mon Sep 17 00:00:00 2001
From: Ryan Norton <wxprojects@comcast.net>
Date: Fri, 17 Dec 2004 16:07:21 +0000
Subject: [PATCH] wxMediaCtrl API changes for 2.5.x/2.6

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/mediactrl.tex         | 12 ++++----
 include/wx/mediactrl.h              | 28 +++++-------------
 samples/mediaplayer/mediaplayer.cpp |  9 +++---
 src/common/mediactrlcmn.cpp         | 46 ++++++++++++++++++++---------
 4 files changed, 51 insertions(+), 44 deletions(-)

diff --git a/docs/latex/wx/mediactrl.tex b/docs/latex/wx/mediactrl.tex
index 77c4ffe93e..f12d8b0ab6 100644
--- a/docs/latex/wx/mediactrl.tex
+++ b/docs/latex/wx/mediactrl.tex
@@ -172,16 +172,16 @@ wxMediaCtrl figure it out.}
 \docparam{name}{Window name.}
 
 
-\membersection{wxMediaCtrl::GetDuration}\label{wxmediactrlgetduration}
+\membersection{wxMediaCtrl::Length}\label{wxmediactrlgetduration}
 
-\func{wxLongLong}{GetDuration}{\void}
+\func{wxFileOffset}{GetDuration}{\void}
 
 Obtains the length - the total amount of time the movie has in milliseconds.
 
 
-\membersection{wxMediaCtrl::GetPosition}\label{wxmediactrlgetposition}
+\membersection{wxMediaCtrl::Tell}\label{wxmediactrlgetposition}
 
-\func{wxLongLong}{GetPosition}{\void}
+\func{wxFileOffset}{GetPosition}{\void}
 
 Obtains the current position in time within the movie in milliseconds.
 
@@ -220,9 +220,9 @@ Pauses playback of the movie.
 Resumes playback of the movie.
 
 
-\membersection{wxMediaCtrl::SetPosition}\label{wxmediactrlsetposition}
+\membersection{wxMediaCtrl::Seek}\label{wxmediactrlsetposition}
 
-\func{bool}{SetPosition}{\param{wxLongLong }{where}}
+\func{wxFileOffset}{SetPosition}{\param{wxFileOffset }{where}, \param{wxSeekMode }{mode}}
 
 Seeks to a position within the movie.
 
diff --git a/include/wx/mediactrl.h b/include/wx/mediactrl.h
index 7994c83ea2..7ee066d29f 100644
--- a/include/wx/mediactrl.h
+++ b/include/wx/mediactrl.h
@@ -55,11 +55,6 @@ enum wxMediaState
     wxMEDIASTATE_PLAYING
 };
 
-enum wxMediaTimeFormat
-{
-    wxMEDIATIMEFORMAT_TIME
-};
-
 #define wxMEDIABACKEND_DIRECTSHOW   wxT("wxAMMediaBackend")
 #define wxMEDIABACKEND_MCI          wxT("wxMCIMediaBackend")
 #define wxMEDIABACKEND_QUICKTIME    wxT("wxQTMediaBackend")
@@ -159,7 +154,7 @@ public:
                 long style = 0,
                 const wxString& szBackend = wxT(""),
                 const wxValidator& validator = wxDefaultValidator,
-                const wxString& name = wxT("mediaCtrl"));
+                const wxString& name = wxT("mediaCtrl")); //DirectShow only
 
     bool DoCreate(wxClassInfo* instance,
                 wxWindow* parent, wxWindowID id,
@@ -174,26 +169,19 @@ public:
     bool Stop();
 
     bool Load(const wxString& fileName);
-    bool Load(const wxURI& location);
+    bool Load(const wxURI& location); //DirectShow only
 
     void Loop(bool bLoop = true);
     bool IsLooped();
 
     wxMediaState GetState();
 
-    double GetPlaybackRate();
-    bool SetPlaybackRate(double dRate);
-
-    bool SetPosition(wxLongLong where);
-    wxLongLong GetPosition();
-    wxLongLong GetDuration();
-
-    //The following two prevent function hiding
-    void GetPosition(int* x, int* y) const
-    {       wxControl::GetPosition(x, y);           }
+    double GetPlaybackRate();           //All but MCI
+    bool SetPlaybackRate(double dRate); //All but MCI
 
-    wxPoint GetPosition() const
-    {       return wxControl::GetPosition();        }  
+    wxFileOffset Seek(wxFileOffset where, wxSeekMode mode = wxFromStart);
+    wxFileOffset Tell(); //FIXME: This should be const
+    wxFileOffset Length(); //FIXME: This should be const
 
 protected:
     static wxClassInfo* NextBackend();
@@ -213,7 +201,7 @@ protected:
 //
 // wxMediaBackend
 //
-// Currently an internal class - API stability not gauranteed.
+// Currently an internal class - API stability not guaranteed.
 //
 // ----------------------------------------------------------------------------
 
diff --git a/samples/mediaplayer/mediaplayer.cpp b/samples/mediaplayer/mediaplayer.cpp
index 87561fd4f9..d24c54c84d 100644
--- a/samples/mediaplayer/mediaplayer.cpp
+++ b/samples/mediaplayer/mediaplayer.cpp
@@ -244,6 +244,7 @@ bool MyApp::OnInit()
 // 4) Connect our events
 // 5) Start our timer
 // ----------------------------------------------------------------------------
+
 MyFrame::MyFrame(const wxString& title)
        : wxFrame(NULL, wxID_ANY, title)
 {
@@ -482,11 +483,11 @@ void MyFrame::ResetStatus()
                                     _T("Length(Seconds):%u Speed:%1.1fx"),
     m_mediactrl->GetBestSize().x,
     m_mediactrl->GetBestSize().y,
-    (unsigned)((m_mediactrl->GetDuration() / 1000).ToLong()),
+    (unsigned)((m_mediactrl->Length() / 1000)),
     m_mediactrl->GetPlaybackRate()
     );
 
-    m_slider->SetRange(0, (m_mediactrl->GetDuration() / 1000).ToLong());
+    m_slider->SetRange(0, (m_mediactrl->Length() / 1000));
 
     m_nLoops = 0;
 }
@@ -599,7 +600,7 @@ void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
 // ----------------------------------------------------------------------------
 void MyFrame::OnSeek(wxCommandEvent& WXUNUSED(event))
 {
-    if( !m_mediactrl->SetPosition( m_slider->GetValue() * 1000 ) )
+    if( m_mediactrl->Seek( m_slider->GetValue() * 1000 ) == wxInvalidOffset )
         wxMessageBox(wxT("Couldn't seek in movie!"));
 }
 
@@ -630,7 +631,7 @@ void MyFrame::OnMediaStop(wxMediaEvent& WXUNUSED(event))
 // ----------------------------------------------------------------------------
 void MyTimer::Notify()
 {
-    long lPosition = (m_frame->m_mediactrl->GetPosition() / 1000).ToLong();
+    long lPosition = (m_frame->m_mediactrl->Tell() / 1000);
     m_frame->m_slider->SetValue(lPosition);
 
 #if wxUSE_STATUSBAR
diff --git a/src/common/mediactrlcmn.cpp b/src/common/mediactrlcmn.cpp
index 0a6665b373..51ba32f6c8 100644
--- a/src/common/mediactrlcmn.cpp
+++ b/src/common/mediactrlcmn.cpp
@@ -70,7 +70,7 @@ DEFINE_EVENT_TYPE(wxEVT_MEDIA_STOP);
 //
 // This searches by searching the global RTTI hashtable, class by class,
 // attempting to call CreateControl on each one found that is a derivative
-// of wxMediaBackend - if it succeededs Create returns true, otherwise
+// of wxMediaBackend - if it succeeded Create returns true, otherwise
 // it keeps iterating through the hashmap.
 //---------------------------------------------------------------------------
 bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id,
@@ -301,9 +301,9 @@ bool wxMediaCtrl::Load(const wxURI& location)
 // wxMediaCtrl::Stop
 // wxMediaCtrl::GetPlaybackRate
 // wxMediaCtrl::SetPlaybackRate
-// wxMediaCtrl::SetPosition
-// wxMediaCtrl::GetPosition
-// wxMediaCtrl::GetDuration
+// wxMediaCtrl::Seek --> SetPosition
+// wxMediaCtrl::Tell --> GetPosition
+// wxMediaCtrl::Length --> GetDuration
 // wxMediaCtrl::GetState
 // wxMediaCtrl::DoGetBestSize
 //
@@ -346,25 +346,43 @@ bool wxMediaCtrl::SetPlaybackRate(double dRate)
     return false;
 }
 
-bool wxMediaCtrl::SetPosition(wxLongLong where)
+wxFileOffset wxMediaCtrl::Seek(wxFileOffset where, wxSeekMode mode)
 {
-    if(m_imp && m_bLoaded)
-        return m_imp->SetPosition(where);
-    return false;
+    wxFileOffset offset;
+
+    switch (mode)
+    {
+    case wxFromStart:
+        offset = where;
+        break;
+    case wxFromEnd:
+        offset = Length() - where;
+        break;
+//    case wxFromCurrent:
+    default:
+        offset = Tell() + where;
+        break;
+    }
+
+    if(m_imp && m_bLoaded && m_imp->SetPosition(offset))
+        return offset;
+    return wxInvalidOffset;
 }
 
-wxLongLong wxMediaCtrl::GetPosition()
+wxFileOffset wxMediaCtrl::Tell()
 {
+    //FIXME
     if(m_imp && m_bLoaded)
-        return m_imp->GetPosition();
-    return 0;
+        return (wxFileOffset) m_imp->GetPosition().ToLong();
+    return wxInvalidOffset;
 }
 
-wxLongLong wxMediaCtrl::GetDuration()
+wxFileOffset wxMediaCtrl::Length()
 {
+    //FIXME
     if(m_imp && m_bLoaded)
-        return m_imp->GetDuration();
-    return 0;
+        return (wxFileOffset) m_imp->GetDuration().ToLong();
+    return wxInvalidOffset;
 }
 
 wxMediaState wxMediaCtrl::GetState()
-- 
2.50.0

