20#include <config_features.h>
24#include <com/sun/star/text/GraphicCrop.hpp>
26#include <rtl/ustring.hxx>
32#include <LibreOfficeKit/LibreOfficeKitEnums.h>
35#include <boost/property_tree/json_parser.hpp>
41#include <svx/strings.hrc>
52#if HAVE_FEATURE_AVMEDIA
56 std::shared_ptr< ::avmedia::MediaTempFile > m_pTempFile;
73#if HAVE_FEATURE_AVMEDIA
107 return std::make_unique<sdr::contact::ViewContactOfSdrMediaObj>( *
this );
143 if (!
aName.isEmpty())
151 return SvxResId(STR_ObjNamePluralMEDIA);
161#if HAVE_FEATURE_AVMEDIA
162 if( !
m_xImpl->m_xCachedSnapshot.is() )
169 const text::GraphicCrop& rCrop =
m_xImpl->m_MediaProperties.getCrop();
170 if (rCrop.Bottom > 0 || rCrop.Left > 0 || rCrop.Right > 0 || rCrop.Top > 0)
178 aGraphic = aBitmapEx;
184 return m_xImpl->m_xCachedSnapshot;
187 OUString aRealURL =
m_xImpl->m_MediaProperties.getTempURL();
188 if( aRealURL.isEmpty() )
189 aRealURL =
m_xImpl->m_MediaProperties.getURL();
190 OUString sReferer =
m_xImpl->m_MediaProperties.getReferer();
191 OUString sMimeType =
m_xImpl->m_MediaProperties.getMimeType();
192 uno::Reference<graphic::XGraphic> xCachedSnapshot =
m_xImpl->m_xCachedSnapshot;
195 [
this, xCachedSnapshot, aRealURL, sReferer, sMimeType](
const css::uno::Reference<css::media::XPlayer>& rPlayer){
197 uno::Reference<graphic::XGraphic> xGraphic
198 =
m_xImpl->m_MediaProperties.getGraphic().GetXGraphic();
206 return m_xImpl->m_xCachedSnapshot;
213 MapMode(MapUnit::Map100thMM)) );
222 if ( (!bShrinkOnly ||
227 float fGrfWH =
static_cast<float>(aSize.
Width()) /
228 static_cast<float>(aSize.
Height());
229 float fWinWH =
static_cast<float>(aMaxSize.
Width()) /
230 static_cast<float>(aMaxSize.
Height());
233 if ( fGrfWH < fWinWH )
238 else if ( fGrfWH > 0.F )
250 aPos.AdjustX( -(aSize.
Width() / 2) );
251 aPos.AdjustY( -(aSize.
Height() / 2) );
258#if HAVE_FEATURE_AVMEDIA
259 if( !rMimeType.isEmpty() )
260 m_xImpl->m_MediaProperties.setMimeType(rMimeType);
261 aURLItem.
setURL( rURL,
"", rReferer );
272#if HAVE_FEATURE_AVMEDIA
273 return m_xImpl->m_MediaProperties.getURL();
282#if HAVE_FEATURE_AVMEDIA
283 return m_xImpl->m_MediaProperties.getTempURL();
298 return m_xImpl->m_MediaProperties;
303#if HAVE_FEATURE_AVMEDIA
306 SAL_WARN(
"svx",
"this is only intended for embedded media");
310 uno::Reference<ucb::XCommandEnvironment>(),
320#if !HAVE_FEATURE_AVMEDIA
323 if (
m_xImpl->m_pTempFile ||
m_xImpl->m_LastFailedPkgURL.isEmpty())
325 SAL_WARN(
"svx",
"this is only intended for embedded media");
329 OUString tempFileURL;
331 ::avmedia::CreateMediaTempFile(
338 m_xImpl->m_pTempFile = std::make_shared<::avmedia::MediaTempFile>(tempFileURL);
339 m_xImpl->m_MediaProperties.setURL(
340 m_xImpl->m_LastFailedPkgURL, tempFileURL,
"");
342 m_xImpl->m_LastFailedPkgURL.clear();
347#if HAVE_FEATURE_AVMEDIA
348static bool lcl_HandlePackageURL(
349 OUString
const & rURL,
351 OUString & o_rTempFileURL)
354 uno::Reference<io::XInputStream> xInStream;
358 catch (container::NoSuchElementException
const&)
360 SAL_INFO(
"svx",
"not found: '" << rURL <<
"'");
363 catch (uno::Exception
const&)
376 sal_Int32 nLastDot = rURL.lastIndexOf(
'.');
377 sal_Int32 nLastSlash = rURL.lastIndexOf(
'/');
378 OUString sDesiredExtension;
379 if (nLastDot > nLastSlash && nLastDot+1 < rURL.getLength())
380 sDesiredExtension = rURL.copy(nLastDot);
381 return ::avmedia::CreateMediaTempFile(xInStream, o_rTempFileURL, sDesiredExtension);
387 bool bBroadcastChanged =
false;
388#if HAVE_FEATURE_AVMEDIA
392 if( AVMediaSetMask::MIME_TYPE & nMaskSet )
393 m_xImpl->m_MediaProperties.setMimeType( rNewProperties.getMimeType() );
395 if (nMaskSet & AVMediaSetMask::GRAPHIC)
397 m_xImpl->m_MediaProperties.setGraphic(rNewProperties.getGraphic());
400 if (nMaskSet & AVMediaSetMask::CROP)
402 m_xImpl->m_MediaProperties.setCrop(rNewProperties.getCrop());
405 if( ( AVMediaSetMask::URL & nMaskSet ) &&
406 ( rNewProperties.getURL() !=
getURL() ))
408 m_xImpl->m_xCachedSnapshot.clear();
409 m_xImpl->m_xPlayerListener.clear();
410 OUString
const& url(rNewProperties.getURL());
411 if (url.startsWithIgnoreAsciiCase(
"vnd.sun.star.Package:"))
414 || (
m_xImpl->m_pTempFile->m_TempFileURL !=
415 rNewProperties.getTempURL()))
417 OUString tempFileURL;
419 lcl_HandlePackageURL(
427 std::make_shared<::avmedia::MediaTempFile>(tempFileURL);
428 m_xImpl->m_MediaProperties.setURL(url, tempFileURL,
"");
433 m_xImpl->m_MediaProperties.setURL(
"",
"",
"");
436 m_xImpl->m_LastFailedPkgURL = url;
441 m_xImpl->m_MediaProperties.setURL(url,
442 rNewProperties.getTempURL(),
"");
448 m_xImpl->m_MediaProperties.setURL(url,
"", rNewProperties.getReferer());
450 bBroadcastChanged =
true;
453 if( AVMediaSetMask::LOOP & nMaskSet )
454 m_xImpl->m_MediaProperties.setLoop( rNewProperties.isLoop() );
456 if( AVMediaSetMask::MUTE & nMaskSet )
457 m_xImpl->m_MediaProperties.setMute( rNewProperties.isMute() );
459 if( AVMediaSetMask::VOLUMEDB & nMaskSet )
460 m_xImpl->m_MediaProperties.setVolumeDB( rNewProperties.getVolumeDB() );
462 if( AVMediaSetMask::ZOOM & nMaskSet )
463 m_xImpl->m_MediaProperties.setZoom( rNewProperties.getZoom() );
465 (void) rNewProperties;
468 if( bBroadcastChanged )
477 if (!
m_xImpl->m_MediaProperties.getTempURL().isEmpty())
479 const auto mediaId =
reinterpret_cast<std::size_t
>(
this);
481 boost::property_tree::ptree json;
482 json.put(
"action",
"update");
483 json.put(
"id", mediaId);
484 json.put(
"url",
m_xImpl->m_MediaProperties.getTempURL());
487 json.put(
"x", aRect.
getX());
488 json.put(
"y", aRect.
getY());
static OutputDevice * GetDefaultDevice()
bool Crop(const tools::Rectangle &rRectPixel)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Size GetSizePixel(const OutputDevice *pRefDevice=nullptr) const
css::uno::Reference< css::io::XInputStream > GetDocumentStream(OUString const &rURL, ::comphelper::LifecycleProxy const &rProxy) const
void EnableUndo(bool bEnable)
enables (true) or disables (false) recording of undo actions If undo actions are added while undo is ...
bool IsUndoEnabled() const
returns true if undo is currently enabled This returns false if undo was disabled using EnableUndo( f...
void ActionChanged() const
void BroadcastObjectChange() const
SdrModel & getSdrModelFromSdrObject() const
virtual void SetLogicRect(const tools::Rectangle &rRect)
virtual const OUString & GetName() const
sdr::contact::ViewContact & GetViewContact() const
virtual void SetChanged()
Rectangle objects (rectangle, circle, ...)
static void notifyMediaUpdate(boost::property_tree::ptree &json)
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long getWidth() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
oslInterlockedCount m_refCount
css::uno::Reference< css::io::XInputStream > openStream()
#define TOOLS_WARN_EXCEPTION(area, stream)
OUString SvxResId(TranslateId aId)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
Reference< XComponentContext > getProcessComponentContext()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)