1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
32 #include <svx/svdomedia.hxx>
33 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
34 #include <drawinglayer/primitive2d/mediaprimitive2d.hxx>
35 
36 namespace sdr { namespace contact {
37 
38 // ----------------------------
39 // - ViewContactOfSdrMediaObj -
40 // ----------------------------
41 
42 ViewContactOfSdrMediaObj::ViewContactOfSdrMediaObj( SdrMediaObj& rMediaObj ) :
43 	ViewContactOfSdrObj( rMediaObj )
44 {
45 }
46 
47 // ------------------------------------------------------------------------------
48 
49 ViewContactOfSdrMediaObj::~ViewContactOfSdrMediaObj()
50 {
51 }
52 
53 // ------------------------------------------------------------------------------
54 
55 ViewObjectContact& ViewContactOfSdrMediaObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
56 {
57 	return *( new ViewObjectContactOfSdrMediaObj( rObjectContact, *this, static_cast< SdrMediaObj& >( GetSdrObject() ).getMediaProperties() ) );
58 }
59 
60 // ------------------------------------------------------------------------------
61 
62 bool ViewContactOfSdrMediaObj::hasPreferredSize() const
63 {
64 	// #i71805# Since we may have a whole bunch of VOCs here, make a loop
65 	// return true if all have their preferred size
66 	const sal_uInt32 nCount(getViewObjectContactCount());
67 	bool bRetval(true);
68 
69 	for(sal_uInt32 a(0); bRetval && a < nCount; a++)
70 	{
71 		ViewObjectContact* pCandidate = getViewObjectContact(a);
72 
73 		if(pCandidate && !static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->hasPreferredSize())
74 		{
75 			bRetval = false;
76 		}
77 	}
78 
79 	return bRetval;
80 }
81 
82 // ------------------------------------------------------------------------------
83 
84 Size ViewContactOfSdrMediaObj::getPreferredSize() const
85 {
86 	// #i71805# Since we may have a whole bunch of VOCs here, make a loop
87 	// return first useful size -> the size from the first which is visualized as a window
88 	const sal_uInt32 nCount(getViewObjectContactCount());
89 
90 	for(sal_uInt32 a(0); a < nCount; a++)
91 	{
92 		ViewObjectContact* pCandidate = getViewObjectContact(a);
93 		Size aSize(pCandidate ? static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->getPreferredSize() : Size());
94 
95 		if(0 != aSize.getWidth() || 0 != aSize.getHeight())
96 		{
97 			return aSize;
98 		}
99 	}
100 
101 	return Size();
102 }
103 
104 // ------------------------------------------------------------------------------
105 
106 void ViewContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const
107 {
108 	// #i71805# Since we may have a whole bunch of VOCs here, make a loop
109 	const sal_uInt32 nCount(getViewObjectContactCount());
110 
111 	for(sal_uInt32 a(0); a < nCount; a++)
112 	{
113 		ViewObjectContact* pCandidate = getViewObjectContact(a);
114 
115 		if(pCandidate)
116 		{
117 			static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->updateMediaItem(rItem);
118 		}
119 	}
120 }
121 
122 // ------------------------------------------------------------------------------
123 
124 void ViewContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem )
125 {
126 	const sal_uInt32 nCount(getViewObjectContactCount());
127 
128 	for(sal_uInt32 a(0); a < nCount; a++)
129 	{
130 		ViewObjectContact* pCandidate = getViewObjectContact(a);
131 
132 		if(pCandidate)
133 		{
134 			static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->executeMediaItem(rItem);
135 		}
136 	}
137 }
138 
139 // ------------------------------------------------------------------------------
140 
141 void ViewContactOfSdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewState )
142 {
143 	static_cast< SdrMediaObj& >(GetSdrObject()).mediaPropertiesChanged(rNewState);
144 }
145 
146 }} // end of namespace sdr::contact
147 
148 namespace sdr
149 {
150 	namespace contact
151 	{
152 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrMediaObj::createViewIndependentPrimitive2DSequence() const
153 		{
154 			// create range using the model data directly. This is in SdrTextObj::aRect which i will access using
155             // GetGeoRect() to not trigger any calculations. It's the unrotated geometry which is okay for MediaObjects ATM.
156 			const Rectangle& rRectangle(GetSdrMediaObj().GetGeoRect());
157 			const basegfx::B2DRange aRange(
158                 rRectangle.Left(), rRectangle.Top(),
159                 rRectangle.Right(), rRectangle.Bottom());
160 
161 			// create object transform
162 			basegfx::B2DHomMatrix aTransform;
163 			aTransform.set(0, 0, aRange.getWidth());
164 			aTransform.set(1, 1, aRange.getHeight());
165 			aTransform.set(0, 2, aRange.getMinX());
166 			aTransform.set(1, 2, aRange.getMinY());
167 
168 			// create media primitive. Always create primitives to allow the
169 			// decomposition of MediaPrimitive2D to create needed invisible elements for HitTest
170 			// and/or BoundRect
171 			const basegfx::BColor aBackgroundColor(67.0 / 255.0, 67.0 / 255.0, 67.0 / 255.0);
172 			const rtl::OUString& rURL(GetSdrMediaObj().getURL());
173 			const sal_uInt32 nPixelBorder(4L);
174 			const drawinglayer::primitive2d::Primitive2DReference xRetval(
175                 new drawinglayer::primitive2d::MediaPrimitive2D(
176 				    aTransform, rURL, aBackgroundColor, nPixelBorder));
177 
178 			return drawinglayer::primitive2d::Primitive2DSequence(&xRetval, 1);
179 		}
180 	} // end of namespace contact
181 } // end of namespace sdr
182 
183 //////////////////////////////////////////////////////////////////////////////
184 // eof
185