1f6e50924SAndrew Rist /**************************************************************
2*a70413d2Smseidel  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a70413d2Smseidel  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a70413d2Smseidel  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19*a70413d2Smseidel  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofpageview.hxx>
28cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
29cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
30cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
31cdf0e10cSrcweir #include <svx/svdomedia.hxx>
32cdf0e10cSrcweir #include <svx/svdpagv.hxx>
33cdf0e10cSrcweir #include <vcl/outdev.hxx>
34cdf0e10cSrcweir #include <vcl/window.hxx>
35cdf0e10cSrcweir #include <avmedia/mediaitem.hxx>
36cdf0e10cSrcweir #include "sdrmediawindow.hxx"
37cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx>
38cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace sdr {	namespace contact {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // ----------------------------------
45cdf0e10cSrcweir // - ViewObjectContactOfSdrMediaObj -
46cdf0e10cSrcweir // ----------------------------------
47*a70413d2Smseidel 
ViewObjectContactOfSdrMediaObj(ObjectContact & rObjectContact,ViewContact & rViewContact,const::avmedia::MediaItem & rMediaItem)48*a70413d2Smseidel ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& rObjectContact,
49cdf0e10cSrcweir 																ViewContact& rViewContact,
50cdf0e10cSrcweir 																const ::avmedia::MediaItem& rMediaItem ) :
51cdf0e10cSrcweir 	ViewObjectContactOfSdrObj( rObjectContact, rViewContact ),
52cdf0e10cSrcweir 	mpMediaWindow( NULL )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	Window* pWindow = getWindow();
55*a70413d2Smseidel 
56cdf0e10cSrcweir 	if( pWindow )
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		mpMediaWindow = new SdrMediaWindow( pWindow, *this );
59cdf0e10cSrcweir 		mpMediaWindow->hide();
60cdf0e10cSrcweir 		executeMediaItem( rMediaItem );
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // ------------------------------------------------------------------------------
65cdf0e10cSrcweir 
~ViewObjectContactOfSdrMediaObj()66cdf0e10cSrcweir ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	delete mpMediaWindow;
69cdf0e10cSrcweir 	mpMediaWindow = NULL;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ------------------------------------------------------------------------------
73cdf0e10cSrcweir 
getWindow() const74cdf0e10cSrcweir Window*	ViewObjectContactOfSdrMediaObj::getWindow() const
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	Window* pRetval = 0;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	const ObjectContactOfPageView* pObjectContactOfPageView = dynamic_cast< const ObjectContactOfPageView* >(&GetObjectContact());
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	if(pObjectContactOfPageView)
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir 		const SdrPageWindow& rPageWindow = pObjectContactOfPageView->GetPageWindow();
83cdf0e10cSrcweir 		const SdrPaintWindow* pPaintWindow = &rPageWindow.GetPaintWindow();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 		if(rPageWindow.GetOriginalPaintWindow())
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			// #i83183# prefer OriginalPaintWindow if set; this is
88cdf0e10cSrcweir 			// the real target device. GetPaintWindow() may return
89cdf0e10cSrcweir 			// the current buffer device instead
90cdf0e10cSrcweir 			pPaintWindow = rPageWindow.GetOriginalPaintWindow();
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
94*a70413d2Smseidel 
95cdf0e10cSrcweir 		if(OUTDEV_WINDOW == rOutDev.GetOutDevType())
96cdf0e10cSrcweir 		{
97cdf0e10cSrcweir 			pRetval = static_cast< Window* >(&rOutDev);
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	return pRetval;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir // ------------------------------------------------------------------------------
105cdf0e10cSrcweir 
hasPreferredSize() const106cdf0e10cSrcweir bool ViewObjectContactOfSdrMediaObj::hasPreferredSize() const
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	return( mpMediaWindow != NULL && mpMediaWindow->hasPreferredSize() );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // ------------------------------------------------------------------------------
112cdf0e10cSrcweir 
getPreferredSize() const113cdf0e10cSrcweir Size ViewObjectContactOfSdrMediaObj::getPreferredSize() const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	Size aRet;
116*a70413d2Smseidel 
117cdf0e10cSrcweir 	if( mpMediaWindow )
118cdf0e10cSrcweir 		aRet = mpMediaWindow->getPreferredSize();
119*a70413d2Smseidel 
120cdf0e10cSrcweir 	return aRet;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // ------------------------------------------------------------------------------
124*a70413d2Smseidel 
updateMediaItem(::avmedia::MediaItem & rItem) const125cdf0e10cSrcweir void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 	if( mpMediaWindow )
128*a70413d2Smseidel 	{
129cdf0e10cSrcweir 		mpMediaWindow->updateMediaItem( rItem );
130cdf0e10cSrcweir 
131*a70413d2Smseidel 		// show/hide is now dependent of play state
132*a70413d2Smseidel 		if(avmedia::MEDIASTATE_STOP == rItem.getState())
133*a70413d2Smseidel 		{
134*a70413d2Smseidel 			mpMediaWindow->hide();
135*a70413d2Smseidel 		}
136*a70413d2Smseidel 		else
137*a70413d2Smseidel 		{
138cdf0e10cSrcweir 			basegfx::B2DRange aViewRange(getObjectRange());
139cdf0e10cSrcweir 			aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation());
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			const Rectangle aViewRectangle(
142cdf0e10cSrcweir 				(sal_Int32)floor(aViewRange.getMinX()), (sal_Int32)floor(aViewRange.getMinY()),
143cdf0e10cSrcweir 				(sal_Int32)ceil(aViewRange.getMaxX()), (sal_Int32)ceil(aViewRange.getMaxY()));
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			mpMediaWindow->setPosSize(aViewRectangle);
146*a70413d2Smseidel 			mpMediaWindow->show();
147*a70413d2Smseidel 		}
148*a70413d2Smseidel 	}
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir // ------------------------------------------------------------------------------
152*a70413d2Smseidel 
executeMediaItem(const::avmedia::MediaItem & rItem)153cdf0e10cSrcweir void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	if( mpMediaWindow )
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		::avmedia::MediaItem aUpdatedItem;
158*a70413d2Smseidel 
159cdf0e10cSrcweir 		mpMediaWindow->executeMediaItem( rItem );
160*a70413d2Smseidel 
161cdf0e10cSrcweir 		// query new properties after trying to set the new properties
162cdf0e10cSrcweir 		updateMediaItem( aUpdatedItem );
163cdf0e10cSrcweir 		static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem );
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir // ------------------------------------------------------------------------------
168cdf0e10cSrcweir 
169cdf0e10cSrcweir }} // end of namespace sdr::contact
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
172cdf0e10cSrcweir // eof
173