]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/mediactrl.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[wxWidgets.git] / src / msw / mediactrl.cpp
index 84f5bc6888a4521374b644e9a4dba9e3dbef8dd5..605366a6d272b920158f9c9f83a88b372acfb41e 100644 (file)
@@ -38,6 +38,8 @@
 //---------------------------------------------------------------------------
 #if wxUSE_MEDIACTRL
 
+#include "wx/dcclient.h"
+
 //---------------------------------------------------------------------------
 // Externals (somewhere in src/msw/app.cpp)
 //---------------------------------------------------------------------------
@@ -578,6 +580,7 @@ public:
     IMediaControl* m_pMC;
     IMediaEvent* m_pME;
     IMediaPosition* m_pMS;
+    bool m_bVideo;
     
     wxAMMediaThread* m_pThread;
 
@@ -1075,13 +1078,20 @@ bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent,
     //
     // Connect Events
     //
-//TODO:  Greg Hazel reports problems with this... but win2k seems fine on mine...
-//    m_ctrl->Connect(m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND, 
-//        wxEraseEventHandler(wxAMMediaEvtHandler::OnEraseBackground),
-//        NULL, (wxEvtHandler*) this);
-    m_ctrl->Connect(m_ctrl->GetId(), wxEVT_PAINT, 
-        wxPaintEventHandler(wxAMMediaEvtHandler::OnPaint),
+    //TODO:  Greg Hazel reports problems with this... but win2k seems fine on mine...
+    //-------------------------------------------------------------------------------
+    // My problem with this was only with a previous patch, probably the third rewrite
+    // fixed it as a side-effect. In fact, the erase background style of drawing not 
+    // only works now, but is much better than paint-based updates (the paint event 
+    // handler flickers if the wxMediaCtrl shares a sizer with another child window, 
+    // or is on a notebook)
+    //  - Greg Hazel
+    m_ctrl->Connect(m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND, 
+        wxEraseEventHandler(wxAMMediaEvtHandler::OnEraseBackground),
         NULL, (wxEvtHandler*) this);
+    //m_ctrl->Connect(m_ctrl->GetId(), wxEVT_PAINT, 
+    //    wxPaintEventHandler(wxAMMediaEvtHandler::OnPaint),
+    //    NULL, (wxEvtHandler*) this);
 
     //
     // As noted below, we need to catch the Top Level Window's
@@ -1231,6 +1241,11 @@ bool wxAMMediaBackend::Load(const wxString& fileName)
         wxASSERT(false);
     }
 
+    if(m_bestSize.x == 0 && m_bestSize.y == 0)
+        m_bVideo = false;
+    else
+        m_bVideo = true;
+
     //
     // Force the parent window of this control to recalculate
     // the size of this if sizers are being used
@@ -1484,7 +1499,7 @@ wxSize wxAMMediaBackend::GetVideoSize() const
 void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y), 
                             int w, int h)
 {
-    if(m_pVMC)
+    if(m_pVMC && m_bVideo)
     {
         RECT srcRect, destRect;
         
@@ -1492,6 +1507,16 @@ void wxAMMediaBackend::Move(int WXUNUSED(x), int WXUNUSED(y),
         srcRect.top = 0; srcRect.left = 0;
         srcRect.bottom = m_bestSize.y; srcRect.right = m_bestSize.x;
 
+        //it happens.
+        if (w < 0)
+        {
+            w = 0;
+        }
+        if (h < 0)
+        {
+            h = 0;
+        }
+
         //position in window client coordinates to display and stretch to
         destRect.top = 0; destRect.left = 0;
         destRect.bottom = h; destRect.right = w;
@@ -1589,22 +1614,22 @@ wxThread::ExitCode wxAMMediaThread::Entry()
 //---------------------------------------------------------------------------
 void wxAMMediaBackend::OnStop()
 {
-                //send the event to our child
-                wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId());
-                m_ctrl->ProcessEvent(theEvent);
+    //send the event to our child
+    wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId());
+    m_ctrl->ProcessEvent(theEvent);
 
-                //if the user didn't veto it, stop the stream
-                if (theEvent.IsAllowed())
-                {
-                    //Interestingly enough, DirectShow does not actually stop
-                    //the filters - even when it reaches the end!
-                    wxVERIFY( Stop() );
-
-                    //send the event to our child
-                    wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
-                                          m_ctrl->GetId());
-                    m_ctrl->ProcessEvent(theEvent);
-                }
+    //if the user didn't veto it, stop the stream
+    if (theEvent.IsAllowed())
+    {
+        //Interestingly enough, DirectShow does not actually stop
+        //the filters - even when it reaches the end!
+        wxVERIFY( Stop() );
+
+        //send the event to our child
+        wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
+                              m_ctrl->GetId());
+        m_ctrl->ProcessEvent(theEvent);
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -1615,19 +1640,21 @@ void wxAMMediaBackend::OnStop()
 void wxAMMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
 {
     wxAMMediaBackend* pThis = (wxAMMediaBackend*) this;
-    if(pThis->m_pVMC)
+    if(pThis->m_pVMC && pThis->m_bVideo)
     {
         //TODO: Use wxClientDC?
         HDC hdc = ::GetDC((HWND)pThis->m_ctrl->GetHandle());
         if( pThis->m_pVMC->RepaintVideo((HWND)pThis->m_ctrl->GetHandle(), 
-                                                hdc)  != 0 )
+                                        hdc)  != 0 )
         {
             wxASSERT(false);
-    }
+        }
         ::ReleaseDC((HWND)pThis->m_ctrl->GetHandle(), hdc);
     }
     else
+    {
         evt.Skip();
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -1639,10 +1666,13 @@ void wxAMMediaEvtHandler::OnPaint(wxPaintEvent& WXUNUSED(evt))
 {
     wxAMMediaBackend* pThis = (wxAMMediaBackend*) this;
     wxPaintDC dc(pThis->m_ctrl);
-    if( pThis->m_pVMC->RepaintVideo((HWND)pThis->m_ctrl->GetHandle(), 
-                                            (HDC)dc.GetHDC())  != 0 )
+    if( pThis->m_pVMC && pThis->m_bVideo)
     {
-        wxASSERT(false);
+        if( pThis->m_pVMC->RepaintVideo((HWND)pThis->m_ctrl->GetHandle(), 
+                                                (HDC)dc.GetHDC())  != 0 )
+        {
+            wxASSERT(false);
+        }
     }
 }