]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 1212020 ] MediaCtrl DirectShow drawing and sample
authorJulian Smart <julian@anthemion.co.uk>
Tue, 31 May 2005 21:12:22 +0000 (21:12 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 31 May 2005 21:12:22 +0000 (21:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34472 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/mediaplayer/mediaplayer.cpp
src/msw/mediactrl.cpp

index 295d4b1bd8f14187e62ef86174142c87e54c5657..b920f8e32d677b5d218f1da5002b40fb2da5f954 100644 (file)
@@ -291,7 +291,7 @@ bool MyApp::OnInit()
 // ----------------------------------------------------------------------------
 
 MyFrame::MyFrame(const wxString& title)
-       : wxFrame(NULL, wxID_ANY, title)
+       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400,400))
 {
     //
     //  Create Menus
@@ -842,11 +842,13 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
     wxPanel(theBook, wxID_ANY), m_nLoops(0), m_bLoop(false)
 {
     //
-    //  Create and attach the first/main sizer
+    //  Create and attach the sizer
     //
-    wxBoxSizer* vertsizer = new wxBoxSizer(wxVERTICAL);
-    this->SetSizer(vertsizer);
+    wxFlexGridSizer* sizer = new wxFlexGridSizer(2, 1, 0, 0);
+    this->SetSizer(sizer);
     this->SetAutoLayout(true);
+    sizer->AddGrowableRow(0);
+    sizer->AddGrowableCol(0);
 
     //
     //  Create our media control
@@ -858,7 +860,7 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
     wxASSERT_MSG(bOK, wxT("Could not create media control!"));
     wxUnusedVar(bOK);
 
-    vertsizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
+    sizer->Add(m_mediactrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 5);
 
     //
     //  Create our slider
@@ -868,20 +870,7 @@ MyNotebookPage::MyNotebookPage(wxNotebook* theBook) :
                             0, //end
                             wxDefaultPosition, wxDefaultSize,
                             wxSL_HORIZONTAL );
-    vertsizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
-
-
-    //
-    //  Create the second sizer which will position things
-    //  vertically -
-    //
-    //  -------Menu----------
-    //  [m_mediactrl]
-    //
-    //  [m_slider]
-    //
-    wxBoxSizer* horzsizer = new wxBoxSizer(wxHORIZONTAL);
-    vertsizer->Add(horzsizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
+    sizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);
 
     //
     // Slider events
index ad5ca83d4c564c165ec5f7052207b0095b615c69..838347354f4d09bb1f73cfde4eb7dc1ce145516d 100644 (file)
@@ -1075,13 +1075,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
@@ -1492,6 +1499,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 +1606,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);
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -1620,14 +1637,16 @@ void wxAMMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
         //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();
+    }
 }
 
 //---------------------------------------------------------------------------