merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / contact / viewobjectcontactofsdrmediaobj.cxx
blobe9d5188b9f510c2aabab0ff2912065d69b2a3d76
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewobjectcontactofsdrmediaobj.cxx,v $
10 * $Revision: 1.16.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/sdr/contact/objectcontactofpageview.hxx>
35 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
36 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
37 #include <svx/sdr/contact/displayinfo.hxx>
38 #include <svx/svdomedia.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <vcl/outdev.hxx>
41 #include <vcl/window.hxx>
42 #include <avmedia/mediaitem.hxx>
43 #include "sdrmediawindow.hxx"
44 #include <svx/sdrpagewindow.hxx>
45 #include <sdrpaintwindow.hxx>
47 //////////////////////////////////////////////////////////////////////////////
49 namespace sdr { namespace contact {
51 // ----------------------------------
52 // - ViewObjectContactOfSdrMediaObj -
53 // ----------------------------------
55 ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& rObjectContact,
56 ViewContact& rViewContact,
57 const ::avmedia::MediaItem& rMediaItem ) :
58 ViewObjectContactOfSdrObj( rObjectContact, rViewContact ),
59 mpMediaWindow( NULL )
61 Window* pWindow = getWindow();
63 if( pWindow )
65 mpMediaWindow = new SdrMediaWindow( pWindow, *this );
66 mpMediaWindow->hide();
67 executeMediaItem( rMediaItem );
71 // ------------------------------------------------------------------------------
73 ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj()
75 delete mpMediaWindow;
76 mpMediaWindow = NULL;
79 // ------------------------------------------------------------------------------
81 Window* ViewObjectContactOfSdrMediaObj::getWindow() const
83 Window* pRetval = 0;
85 const ObjectContactOfPageView* pObjectContactOfPageView = dynamic_cast< const ObjectContactOfPageView* >(&GetObjectContact());
87 if(pObjectContactOfPageView)
89 const SdrPageWindow& rPageWindow = pObjectContactOfPageView->GetPageWindow();
90 const SdrPaintWindow* pPaintWindow = &rPageWindow.GetPaintWindow();
92 if(rPageWindow.GetOriginalPaintWindow())
94 // #i83183# prefer OriginalPaintWindow if set; this is
95 // the real target device. GetPaintWindow() may return
96 // the current buffer device instead
97 pPaintWindow = rPageWindow.GetOriginalPaintWindow();
100 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
102 if(OUTDEV_WINDOW == rOutDev.GetOutDevType())
104 pRetval = static_cast< Window* >(&rOutDev);
108 return pRetval;
111 // ------------------------------------------------------------------------------
113 bool ViewObjectContactOfSdrMediaObj::hasPreferredSize() const
115 return( mpMediaWindow != NULL && mpMediaWindow->hasPreferredSize() );
118 // ------------------------------------------------------------------------------
120 Size ViewObjectContactOfSdrMediaObj::getPreferredSize() const
122 Size aRet;
124 if( mpMediaWindow )
125 aRet = mpMediaWindow->getPreferredSize();
127 return aRet;
130 // ------------------------------------------------------------------------------
132 void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const
134 if( mpMediaWindow )
136 mpMediaWindow->updateMediaItem( rItem );
138 // show/hide is now dependent of play state
139 if(avmedia::MEDIASTATE_STOP == rItem.getState())
141 mpMediaWindow->hide();
143 else
145 basegfx::B2DRange aViewRange(getObjectRange());
146 aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation());
148 const Rectangle aViewRectangle(
149 (sal_Int32)floor(aViewRange.getMinX()), (sal_Int32)floor(aViewRange.getMinY()),
150 (sal_Int32)ceil(aViewRange.getMaxX()), (sal_Int32)ceil(aViewRange.getMaxY()));
152 mpMediaWindow->setPosSize(aViewRectangle);
153 mpMediaWindow->show();
158 // ------------------------------------------------------------------------------
160 void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem )
162 if( mpMediaWindow )
164 ::avmedia::MediaItem aUpdatedItem;
166 mpMediaWindow->executeMediaItem( rItem );
168 // query new properties after trying to set the new properties
169 updateMediaItem( aUpdatedItem );
170 static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem );
174 // ------------------------------------------------------------------------------
176 }} // end of namespace sdr::contact
178 //////////////////////////////////////////////////////////////////////////////
179 // eof