LibreOffice Module svx (master) 1
viewobjectcontactofsdrmediaobj.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_features.h>
21
25#include <vcl/outdev.hxx>
26#include <vcl/window.hxx>
27#include <avmedia/mediaitem.hxx>
28#include "sdrmediawindow.hxx"
29
30namespace sdr::contact {
31
33 ViewContact& rViewContact,
34 const ::avmedia::MediaItem& rMediaItem ) :
35 ViewObjectContactOfSdrObj( rObjectContact, rViewContact )
36{
37#if HAVE_FEATURE_AVMEDIA
38 vcl::Window* pWindow = getWindow();
39
40 if( pWindow )
41 {
42 mpMediaWindow.reset( new SdrMediaWindow( pWindow, *this ) );
43 mpMediaWindow->hide();
44 executeMediaItem( rMediaItem );
45 }
46#else
47 (void) rMediaItem;
48#endif
49}
50
52{
53}
54
55
57{
58 vcl::Window* pRetval = nullptr;
59
60 const OutputDevice* oPageOutputDev = getPageViewOutputDevice();
61 if( oPageOutputDev )
62 {
63 if(OUTDEV_WINDOW == oPageOutputDev->GetOutDevType())
64 {
65 pRetval = oPageOutputDev->GetOwnerWindow();
66 }
67 }
68
69 return pRetval;
70}
71
72
74{
75 Size aRet;
76
77#if HAVE_FEATURE_AVMEDIA
78 if( mpMediaWindow )
79 aRet = mpMediaWindow->getPreferredSize();
80#else
81 aRet = Size(0,0);
82#endif
83
84 return aRet;
85}
86
88{
90 updateMediaWindow(false);
91}
92
94{
95#if HAVE_FEATURE_AVMEDIA
96 if (!mpMediaWindow || (!bShow && !mpMediaWindow->isVisible()))
97 return;
98
100 aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation());
101
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())));
105
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.
112
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);
118
119 // then make it visible
120 mpMediaWindow->show();
121
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);
126#else
127 (void) bShow;
128#endif
129}
130
132{
133#if HAVE_FEATURE_AVMEDIA
134 if( !mpMediaWindow )
135 return;
136
137 mpMediaWindow->updateMediaItem( rItem );
138
139 // show/hide is now dependent of play state
141 {
142 mpMediaWindow->hide();
143 }
144 else
145 {
146 updateMediaWindow(true);
147 }
148#else
149 (void) rItem;
150#endif
151}
152
153
154void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem )
155{
156#if HAVE_FEATURE_AVMEDIA
157 if( mpMediaWindow )
158 {
159 ::avmedia::MediaItem aUpdatedItem;
160
161 mpMediaWindow->executeMediaItem( rItem );
162
163 // query new properties after trying to set the new properties
164 updateMediaItem( aUpdatedItem );
165 static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem );
166 }
167#else
168 (void) rItem;
169#endif
170}
171
172
173} // end of namespace sdr::contact
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OutDevType GetOutDevType() const
virtual vcl::Window * GetOwnerWindow() const
MediaState getState() const
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
TYPE getMaxX() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getMaxY() const
ViewObjectContactOfSdrMediaObj(ObjectContact &rObjectContact, ViewContact &rViewContact, const ::avmedia::MediaItem &rMediaItem)
void updateMediaItem(::avmedia::MediaItem &rItem) const
void executeMediaItem(const ::avmedia::MediaItem &rItem)
const OutputDevice * getPageViewOutputDevice() const
retrieves the device which a PageView belongs to, starting from its ObjectContactOfPageView
ViewContact & GetViewContact() const
ObjectContact & GetObjectContact() const
const basegfx::B2DRange & getObjectRange() const
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
OUTDEV_WINDOW