From 6f938dce6eaa927cfde39491ef7a0bc1d07df66b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 18 Feb 2022 21:09:30 +0000 Subject: update video pos and size after change if currently playing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'd prefer if it changed size during the resizing/repositioning, but at least make it immediately take the final size after the resize/reposition has happened. Change-Id: Ic3b4dd23921ad5cf6092f1514dd6538f9946998a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130178 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- .../sdr/contact/viewobjectcontactofsdrmediaobj.hxx | 4 ++ .../sdr/contact/viewobjectcontactofsdrmediaobj.cxx | 65 +++++++++++++--------- 2 files changed, 42 insertions(+), 27 deletions(-) (limited to 'svx') diff --git a/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx b/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx index 21fbed38142c..d362048df3db 100644 --- a/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx +++ b/svx/inc/sdr/contact/viewobjectcontactofsdrmediaobj.hxx @@ -51,7 +51,11 @@ namespace sdr::contact void updateMediaItem( ::avmedia::MediaItem& rItem ) const; void executeMediaItem( const ::avmedia::MediaItem& rItem ); + virtual void ActionChanged() override; + private: + void updateMediaWindow() const; + #if HAVE_FEATURE_AVMEDIA std::unique_ptr mpMediaWindow; #endif diff --git a/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx b/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx index 27768ff0777f..0241fabd5661 100644 --- a/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx +++ b/svx/source/sdr/contact/viewobjectcontactofsdrmediaobj.cxx @@ -84,6 +84,43 @@ Size ViewObjectContactOfSdrMediaObj::getPreferredSize() const return aRet; } +void ViewObjectContactOfSdrMediaObj::ActionChanged() +{ + ViewObjectContactOfSdrObj::ActionChanged(); + if (mpMediaWindow && mpMediaWindow->isVisible()) + updateMediaWindow(); +} + +void ViewObjectContactOfSdrMediaObj::updateMediaWindow() const +{ + basegfx::B2DRange aViewRange(getObjectRange()); + aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation()); + + const tools::Rectangle aViewRectangle( + static_cast(floor(aViewRange.getMinX())), static_cast(floor(aViewRange.getMinY())), + static_cast(ceil(aViewRange.getMaxX())), static_cast(ceil(aViewRange.getMaxY()))); + + // mpMediaWindow contains a SalObject window and gtk won't accept + // the size until after the SalObject widget is shown but if we + // show it before setting a size then vcl will detect that the + // vcl::Window has no size and make it invisible instead. If we + // call setPosSize twice with the same size before and after show + // then the second attempt is a no-op as vcl caches the size. + + // so call it initially with a size arbitrarily 1 pixel wider than + // we want so we have an initial size to make vcl happy + tools::Rectangle aInitialRect(aViewRectangle); + aInitialRect.AdjustRight(1); + mpMediaWindow->setPosSize(aInitialRect); + + // then make it visible + mpMediaWindow->show(); + + // set the final desired size which is different to let vcl send it + // through to gtk which will now accept it as the underlying + // m_pSocket of GtkSalObject::SetPosSize is now visible + mpMediaWindow->setPosSize(aViewRectangle); +} void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const { @@ -100,33 +137,7 @@ void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rIte } else { - basegfx::B2DRange aViewRange(getObjectRange()); - aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation()); - - const tools::Rectangle aViewRectangle( - static_cast(floor(aViewRange.getMinX())), static_cast(floor(aViewRange.getMinY())), - static_cast(ceil(aViewRange.getMaxX())), static_cast(ceil(aViewRange.getMaxY()))); - - // mpMediaWindow contains a SalObject window and gtk won't accept - // the size until after the SalObject widget is shown but if we - // show it before setting a size then vcl will detect that the - // vcl::Window has no size and make it invisible instead. If we - // call setPosSize twice with the same size before and after show - // then the second attempt is a no-op as vcl caches the size. - - // so call it initially with a size arbitrarily 1 pixel wider than - // we want so we have an initial size to make vcl happy - tools::Rectangle aInitialRect(aViewRectangle); - aInitialRect.AdjustRight(1); - mpMediaWindow->setPosSize(aInitialRect); - - // then make it visible - mpMediaWindow->show(); - - // set the final desired size which is different to let vcl send it - // through to gtk which will now accept it as the underlying - // m_pSocket of GtkSalObject::SetPosSize is now visible - mpMediaWindow->setPosSize(aViewRectangle); + updateMediaWindow(); } #else (void) rItem; -- cgit