1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include <sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
23 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
24 #include <svx/sdr/contact/objectcontact.hxx>
25 #include <vcl/outdev.hxx>
26 #include <vcl/window.hxx>
27 #include <avmedia/mediaitem.hxx>
28 #include "sdrmediawindow.hxx"
30 namespace sdr::contact
{
32 ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact
& rObjectContact
,
33 ViewContact
& rViewContact
,
34 const ::avmedia::MediaItem
& rMediaItem
) :
35 ViewObjectContactOfSdrObj( rObjectContact
, rViewContact
)
37 #if HAVE_FEATURE_AVMEDIA
38 vcl::Window
* pWindow
= getWindow();
42 mpMediaWindow
.reset( new SdrMediaWindow( pWindow
, *this ) );
43 mpMediaWindow
->hide();
44 executeMediaItem( rMediaItem
);
51 ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj()
56 vcl::Window
* ViewObjectContactOfSdrMediaObj::getWindow() const
58 vcl::Window
* pRetval
= nullptr;
60 const OutputDevice
* oPageOutputDev
= getPageViewOutputDevice();
63 if(OUTDEV_WINDOW
== oPageOutputDev
->GetOutDevType())
65 pRetval
= oPageOutputDev
->GetOwnerWindow();
73 Size
ViewObjectContactOfSdrMediaObj::getPreferredSize() const
77 #if HAVE_FEATURE_AVMEDIA
79 aRet
= mpMediaWindow
->getPreferredSize();
87 void ViewObjectContactOfSdrMediaObj::ActionChanged()
89 ViewObjectContactOfSdrObj::ActionChanged();
90 updateMediaWindow(false);
93 void ViewObjectContactOfSdrMediaObj::updateMediaWindow(bool bShow
) const
95 #if HAVE_FEATURE_AVMEDIA
96 if (!mpMediaWindow
|| (!bShow
&& !mpMediaWindow
->isVisible()))
99 basegfx::B2DRange
aViewRange(getObjectRange());
100 aViewRange
.transform(GetObjectContact().getViewInformation2D().getViewTransformation());
102 const tools::Rectangle
aViewRectangle(
103 static_cast<sal_Int32
>(floor(aViewRange
.getMinX())), static_cast<sal_Int32
>(floor(aViewRange
.getMinY())),
104 static_cast<sal_Int32
>(ceil(aViewRange
.getMaxX())), static_cast<sal_Int32
>(ceil(aViewRange
.getMaxY())));
106 // mpMediaWindow contains a SalObject window and gtk won't accept
107 // the size until after the SalObject widget is shown but if we
108 // show it before setting a size then vcl will detect that the
109 // vcl::Window has no size and make it invisible instead. If we
110 // call setPosSize twice with the same size before and after show
111 // then the second attempt is a no-op as vcl caches the size.
113 // so call it initially with a size arbitrarily 1 pixel wider than
114 // we want so we have an initial size to make vcl happy
115 tools::Rectangle
aInitialRect(aViewRectangle
);
116 aInitialRect
.AdjustRight(1);
117 mpMediaWindow
->setPosSize(aInitialRect
);
119 // then make it visible
120 mpMediaWindow
->show();
122 // set the final desired size which is different to let vcl send it
123 // through to gtk which will now accept it as the underlying
124 // m_pSocket of GtkSalObject::SetPosSize is now visible
125 mpMediaWindow
->setPosSize(aViewRectangle
);
131 void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem
& rItem
) const
133 #if HAVE_FEATURE_AVMEDIA
137 mpMediaWindow
->updateMediaItem( rItem
);
139 // show/hide is now dependent of play state
140 if(avmedia::MediaState::Stop
== rItem
.getState())
142 mpMediaWindow
->hide();
146 updateMediaWindow(true);
154 void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem
& rItem
)
156 #if HAVE_FEATURE_AVMEDIA
159 ::avmedia::MediaItem aUpdatedItem
;
161 mpMediaWindow
->executeMediaItem( rItem
);
163 // query new properties after trying to set the new properties
164 updateMediaItem( aUpdatedItem
);
165 static_cast< ViewContactOfSdrMediaObj
& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem
);
173 } // end of namespace sdr::contact
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */