1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
28 #include <svx/svdomedia.hxx>
29 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
30 #include <drawinglayer/primitive2d/mediaprimitive2d.hxx>
31 
32 namespace sdr { namespace contact {
33 
34 // ----------------------------
35 // - ViewContactOfSdrMediaObj -
36 // ----------------------------
37 
ViewContactOfSdrMediaObj(SdrMediaObj & rMediaObj)38 ViewContactOfSdrMediaObj::ViewContactOfSdrMediaObj( SdrMediaObj& rMediaObj ) :
39 	ViewContactOfSdrObj( rMediaObj )
40 {
41 }
42 
43 // ------------------------------------------------------------------------------
44 
~ViewContactOfSdrMediaObj()45 ViewContactOfSdrMediaObj::~ViewContactOfSdrMediaObj()
46 {
47 }
48 
49 // ------------------------------------------------------------------------------
50 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)51 ViewObjectContact& ViewContactOfSdrMediaObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
52 {
53 	return *( new ViewObjectContactOfSdrMediaObj( rObjectContact, *this, static_cast< SdrMediaObj& >( GetSdrObject() ).getMediaProperties() ) );
54 }
55 
56 // ------------------------------------------------------------------------------
57 
hasPreferredSize() const58 bool ViewContactOfSdrMediaObj::hasPreferredSize() const
59 {
60 	// #i71805# Since we may have a whole bunch of VOCs here, make a loop
61 	// return true if all have their preferred size
62 	const sal_uInt32 nCount(getViewObjectContactCount());
63 	bool bRetval(true);
64 
65 	for(sal_uInt32 a(0); bRetval && a < nCount; a++)
66 	{
67 		ViewObjectContact* pCandidate = getViewObjectContact(a);
68 
69 		if(pCandidate && !static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->hasPreferredSize())
70 		{
71 			bRetval = false;
72 		}
73 	}
74 
75 	return bRetval;
76 }
77 
78 // ------------------------------------------------------------------------------
79 
getPreferredSize() const80 Size ViewContactOfSdrMediaObj::getPreferredSize() const
81 {
82 	// #i71805# Since we may have a whole bunch of VOCs here, make a loop
83 	// return first useful size -> the size from the first which is visualized as a window
84 	const sal_uInt32 nCount(getViewObjectContactCount());
85 
86 	for(sal_uInt32 a(0); a < nCount; a++)
87 	{
88 		ViewObjectContact* pCandidate = getViewObjectContact(a);
89 		Size aSize(pCandidate ? static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->getPreferredSize() : Size());
90 
91 		if(0 != aSize.getWidth() || 0 != aSize.getHeight())
92 		{
93 			return aSize;
94 		}
95 	}
96 
97 	return Size();
98 }
99 
100 // ------------------------------------------------------------------------------
101 
updateMediaItem(::avmedia::MediaItem & rItem) const102 void ViewContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const
103 {
104 	// #i71805# Since we may have a whole bunch of VOCs here, make a loop
105 	const sal_uInt32 nCount(getViewObjectContactCount());
106 
107 	for(sal_uInt32 a(0); a < nCount; a++)
108 	{
109 		ViewObjectContact* pCandidate = getViewObjectContact(a);
110 
111 		if(pCandidate)
112 		{
113 			static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->updateMediaItem(rItem);
114 		}
115 	}
116 }
117 
118 // ------------------------------------------------------------------------------
119 
executeMediaItem(const::avmedia::MediaItem & rItem)120 void ViewContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem )
121 {
122 	const sal_uInt32 nCount(getViewObjectContactCount());
123 
124 	for(sal_uInt32 a(0); a < nCount; a++)
125 	{
126 		ViewObjectContact* pCandidate = getViewObjectContact(a);
127 
128 		if(pCandidate)
129 		{
130 			static_cast< ViewObjectContactOfSdrMediaObj* >(pCandidate)->executeMediaItem(rItem);
131 		}
132 	}
133 }
134 
135 // ------------------------------------------------------------------------------
136 
mediaPropertiesChanged(const::avmedia::MediaItem & rNewState)137 void ViewContactOfSdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewState )
138 {
139 	static_cast< SdrMediaObj& >(GetSdrObject()).mediaPropertiesChanged(rNewState);
140 }
141 
142 }} // end of namespace sdr::contact
143 
144 namespace sdr
145 {
146 	namespace contact
147 	{
createViewIndependentPrimitive2DSequence() const148 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrMediaObj::createViewIndependentPrimitive2DSequence() const
149 		{
150 			// create range using the model data directly. This is in SdrTextObj::aRect which i will access using
151 			// GetGeoRect() to not trigger any calculations. It's the unrotated geometry which is okay for MediaObjects ATM.
152 			const Rectangle& rRectangle(GetSdrMediaObj().GetGeoRect());
153 			const basegfx::B2DRange aRange(
154 				rRectangle.Left(), rRectangle.Top(),
155 				rRectangle.Right(), rRectangle.Bottom());
156 
157 			// create object transform
158 			basegfx::B2DHomMatrix aTransform;
159 			aTransform.set(0, 0, aRange.getWidth());
160 			aTransform.set(1, 1, aRange.getHeight());
161 			aTransform.set(0, 2, aRange.getMinX());
162 			aTransform.set(1, 2, aRange.getMinY());
163 
164 			// create media primitive. Always create primitives to allow the
165 			// decomposition of MediaPrimitive2D to create needed invisible elements for HitTest
166 			// and/or BoundRect
167 			const basegfx::BColor aBackgroundColor(67.0 / 255.0, 67.0 / 255.0, 67.0 / 255.0);
168 			const rtl::OUString& rURL(GetSdrMediaObj().getURL());
169 			const sal_uInt32 nPixelBorder(4L);
170 			const drawinglayer::primitive2d::Primitive2DReference xRetval(
171 				new drawinglayer::primitive2d::MediaPrimitive2D(
172 					aTransform, rURL, aBackgroundColor, nPixelBorder));
173 
174 			return drawinglayer::primitive2d::Primitive2DSequence(&xRetval, 1);
175 		}
176 	} // end of namespace contact
177 } // end of namespace sdr
178 
179 //////////////////////////////////////////////////////////////////////////////
180 // eof
181