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 
30 namespace 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 = static_cast< vcl::Window* >(&const_cast<OutputDevice&>(*oPageOutputDev));
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 
87 
89 {
90 #if HAVE_FEATURE_AVMEDIA
91  if( !mpMediaWindow )
92  return;
93 
94  mpMediaWindow->updateMediaItem( rItem );
95 
96  // show/hide is now dependent of play state
97  if(avmedia::MediaState::Stop == rItem.getState())
98  {
99  mpMediaWindow->hide();
100  }
101  else
102  {
103  basegfx::B2DRange aViewRange(getObjectRange());
104  aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation());
105 
106  const tools::Rectangle aViewRectangle(
107  static_cast<sal_Int32>(floor(aViewRange.getMinX())), static_cast<sal_Int32>(floor(aViewRange.getMinY())),
108  static_cast<sal_Int32>(ceil(aViewRange.getMaxX())), static_cast<sal_Int32>(ceil(aViewRange.getMaxY())));
109 
110  // mpMediaWindow contains a SalObject window and gtk won't accept
111  // the size until after the SalObject widget is shown but if we
112  // show it before setting a size then vcl will detect that the
113  // vcl::Window has no size and make it invisible instead. If we
114  // call setPosSize twice with the same size before and after show
115  // then the second attempt is a no-op as vcl caches the size.
116 
117  // so call it initially with a size arbitrarily 1 pixel wider than
118  // we want so we have an initial size to make vcl happy
119  tools::Rectangle aInitialRect(aViewRectangle);
120  aInitialRect.AdjustRight(1);
121  mpMediaWindow->setPosSize(aInitialRect);
122 
123  // then make it visible
124  mpMediaWindow->show();
125 
126  // set the final desired size which is different to let vcl send it
127  // through to gtk which will now accept it as the underlying
128  // m_pSocket of GtkSalObject::SetPosSize is now visible
129  mpMediaWindow->setPosSize(aViewRectangle);
130  }
131 #else
132  (void) rItem;
133 #endif
134 }
135 
136 
137 void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem )
138 {
139 #if HAVE_FEATURE_AVMEDIA
140  if( mpMediaWindow )
141  {
142  ::avmedia::MediaItem aUpdatedItem;
143 
144  mpMediaWindow->executeMediaItem( rItem );
145 
146  // query new properties after trying to set the new properties
147  updateMediaItem( aUpdatedItem );
148  static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem );
149  }
150 #else
151  (void) rItem;
152 #endif
153 }
154 
155 
156 } // end of namespace sdr::contact
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OutDevType GetOutDevType() const
void executeMediaItem(const ::avmedia::MediaItem &rItem)
void updateMediaItem(::avmedia::MediaItem &rItem) const
double getMaxX() const
const OutputDevice * getPageViewOutputDevice() const
retrieves the device which a PageView belongs to, starting from its ObjectContactOfPageView ...
ViewObjectContactOfSdrMediaObj(ObjectContact &rObjectContact, ViewContact &rViewContact, const ::avmedia::MediaItem &rMediaItem)
OUTDEV_WINDOW
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
double getMaxY() const
ObjectContact & GetObjectContact() const
double getMinY() const
MediaState getState() const
ViewContact & GetViewContact() const
double getMinX() const
const basegfx::B2DRange & getObjectRange() const
std::unique_ptr< sdr::contact::SdrMediaWindow > mpMediaWindow
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo