From 149f3804a895ceaa05feccb0118de5ac0efbaa5b Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Fri, 22 Oct 2021 20:10:14 -0400 Subject: [PATCH 1/3] Add style for manually resizing wxMediaCtrl Previously, wxMediaCtrl would always automatically resize itself whenever a video was loaded. If a wide video was loaded, this could cause wxMediaCtrl to take up the entire space, hiding any other widget(s) that might exist within the same sizer. Allow avoiding this behavior by adding a new style, wxMC_NO_AUTORESIZE, which disables this automatic resize behavior and allows handling the resize behavior manually. --- include/wx/mediactrl.h | 2 ++ interface/wx/mediactrl.h | 12 ++++++++++++ src/common/mediactrlcmn.cpp | 3 +++ 3 files changed, 17 insertions(+) diff --git a/include/wx/mediactrl.h b/include/wx/mediactrl.h index 17b359dc15..ff159817ee 100644 --- a/include/wx/mediactrl.h +++ b/include/wx/mediactrl.h @@ -37,6 +37,8 @@ #include "wx/control.h" #include "wx/uri.h" +#define wxMC_NO_AUTORESIZE 0x0001 + // ============================================================================ // Declarations // ============================================================================ diff --git a/interface/wx/mediactrl.h b/interface/wx/mediactrl.h index 27eb3b0761..4287ab8588 100644 --- a/interface/wx/mediactrl.h +++ b/interface/wx/mediactrl.h @@ -5,6 +5,8 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +#define wxMC_NO_AUTORESIZE 0x0001 + /** Describes the current state of the media. @@ -225,6 +227,16 @@ public: wxActiveXContainer documentation. + @beginStyleTable + @style{wxMC_NO_AUTORESIZE} + By default, the control will automatically adjust its size to + exactly fit the size of a loaded video as soon as a video is loaded. + If this flag is given, the control will not change its size + automatically and must be done manually (if desired) using Layout(). + It is strongly recommended to use this flag and handle control + resizing manually. + @endStyleTable + @library{wxmedia} @category{media} diff --git a/src/common/mediactrlcmn.cpp b/src/common/mediactrlcmn.cpp index 70413a28ca..e4bc3f2a7e 100644 --- a/src/common/mediactrlcmn.cpp +++ b/src/common/mediactrlcmn.cpp @@ -466,6 +466,9 @@ void wxMediaCtrl::DoMoveWindow(int x, int y, int w, int h) void wxMediaBackendCommonBase::NotifyMovieSizeChanged() { + if ( m_ctrl->HasFlag(wxMC_NO_AUTORESIZE) ) + return; + // our best size changed after opening a new file m_ctrl->InvalidateBestSize(); m_ctrl->SetSize(m_ctrl->GetSize()); From 9d69bb55efdce96f3d80f07e02cf665bde4228db Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Fri, 22 Oct 2021 20:15:47 -0400 Subject: [PATCH 2/3] Fix some sizing issues with mediaplayer sample Switch to the newly added wxMC_NO_AUTORESIZE mode, make the entire window larger and let the sliders use their natural size. --- samples/mediaplayer/mediaplayer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/mediaplayer/mediaplayer.cpp b/samples/mediaplayer/mediaplayer.cpp index 691537b6e9..aa9c8c13cf 100644 --- a/samples/mediaplayer/mediaplayer.cpp +++ b/samples/mediaplayer/mediaplayer.cpp @@ -500,7 +500,7 @@ void wxMediaPlayerApp::MacOpenFiles(const wxArrayString & fileNames ) // ---------------------------------------------------------------------------- wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title) - : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(600,600)) + : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(1366,768)) { SetIcon(wxICON(sample)); @@ -1492,7 +1492,8 @@ wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentF // Make sure creation was successful bool bOK = m_mediactrl->Create(this, wxID_MEDIACTRL, wxEmptyString, - wxDefaultPosition, wxDefaultSize, 0, + wxDefaultPosition, wxDefaultSize, + wxMC_NO_AUTORESIZE, // you could specify a macro backend here like // wxMEDIABACKEND_WMP10); // "wxPDFMediaBackend"); @@ -1608,14 +1609,14 @@ wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentF m_volSlider = new wxSlider(this, wxID_VOLSLIDER, 100, // init 0, // start 100, // end - wxDefaultPosition, wxSize(250,20), + wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL ); horsizer3->Add(m_volSlider, 1, wxALL, 5); m_pbSlider = new wxSlider(this, wxID_PBSLIDER, 4, // init 1, // start 16, // end - wxDefaultPosition, wxSize(250,20), + wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL ); horsizer3->Add(m_pbSlider, 1, wxALL, 5); sizer->Add(horsizer3, 1, wxCENTRE | wxALL, 5); From cffb866edf5f44c11003dc6047b94bfcd87c7c6f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Nov 2021 21:41:28 +0100 Subject: [PATCH 3/3] Minor additions to wxMC_NO_AUTORESIZE documentation Mention that this flag is new in 3.1.6 and also point to it in ctor and Create() documentation. --- interface/wx/mediactrl.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/interface/wx/mediactrl.h b/interface/wx/mediactrl.h index 4287ab8588..32e3e4ef91 100644 --- a/interface/wx/mediactrl.h +++ b/interface/wx/mediactrl.h @@ -232,9 +232,11 @@ public: By default, the control will automatically adjust its size to exactly fit the size of a loaded video as soon as a video is loaded. If this flag is given, the control will not change its size - automatically and must be done manually (if desired) using Layout(). + automatically and it must be done manually (if desired) using Layout(). It is strongly recommended to use this flag and handle control - resizing manually. + resizing manually (note that this style is only available in + wxWidgets 3.1.6, so it is only possible to do it when using this or + later version). @endStyleTable @library{wxmedia} @@ -267,7 +269,8 @@ public: @param size Size to put the control at and to stretch movie to. @param style - Optional styles. + Optional styles. It is recommended to use ::wxMC_NO_AUTORESIZE, + although it is not used by default for compatibility reasons. @param szBackend Name of backend you want to use, leave blank to make wxMediaCtrl figure it out. @param validator @@ -301,7 +304,8 @@ public: @param size Size to put the control at and to stretch movie to. @param style - Optional styles. + Optional styles. It is recommended to use ::wxMC_NO_AUTORESIZE, + although it is not used by default for compatibility reasons. @param szBackend Name of backend you want to use, leave blank to make wxMediaCtrl figure it out. @param validator