xref: /aoo42x/main/svx/source/svdraw/svdomedia.cxx (revision f6e50924)
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 <vcl/svapp.hxx>
28 
29 #include <svx/svdomedia.hxx>
30 #include "svx/svdglob.hxx"
31 #include "svx/svdstr.hrc"
32 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
33 #include <avmedia/mediawindow.hxx>
34 
35 // ---------------
36 // - SdrMediaObj -
37 // ---------------
38 
39 TYPEINIT1( SdrMediaObj, SdrRectObj );
40 
41 // ------------------------------------------------------------------------------
42 
SdrMediaObj()43 SdrMediaObj::SdrMediaObj()
44 {
45 }
46 
47 // ------------------------------------------------------------------------------
48 
SdrMediaObj(const Rectangle & rRect)49 SdrMediaObj::SdrMediaObj( const Rectangle& rRect ) :
50 	SdrRectObj( rRect )
51 {
52 }
53 
54 // ------------------------------------------------------------------------------
55 
~SdrMediaObj()56 SdrMediaObj::~SdrMediaObj()
57 {
58 }
59 
60 // ------------------------------------------------------------------------------
61 
HasTextEdit() const62 FASTBOOL SdrMediaObj::HasTextEdit() const
63 {
64 	return sal_False;
65 }
66 
67 // ------------------------------------------------------------------------------
68 
CreateObjectSpecificViewContact()69 sdr::contact::ViewContact* SdrMediaObj::CreateObjectSpecificViewContact()
70 {
71 	return new ::sdr::contact::ViewContactOfSdrMediaObj( *this );
72 }
73 
74 // ------------------------------------------------------------------------------
75 
TakeObjInfo(SdrObjTransformInfoRec & rInfo) const76 void SdrMediaObj::TakeObjInfo( SdrObjTransformInfoRec& rInfo ) const
77 {
78 	rInfo.bSelectAllowed = true;
79 	rInfo.bMoveAllowed = true;
80 	rInfo.bResizeFreeAllowed = true;
81 	rInfo.bResizePropAllowed = true;
82 	rInfo.bRotateFreeAllowed = false;
83 	rInfo.bRotate90Allowed = false;
84 	rInfo.bMirrorFreeAllowed = false;
85 	rInfo.bMirror45Allowed = false;
86 	rInfo.bMirror90Allowed = false;
87 	rInfo.bTransparenceAllowed = false;
88 	rInfo.bGradientAllowed = false;
89 	rInfo.bShearAllowed = false;
90 	rInfo.bEdgeRadiusAllowed = false;
91 	rInfo.bNoOrthoDesired = false;
92 	rInfo.bNoContortion = false;
93 	rInfo.bCanConvToPath = false;
94 	rInfo.bCanConvToPoly = false;
95 	rInfo.bCanConvToContour = false;
96 	rInfo.bCanConvToPathLineToArea = false;
97 	rInfo.bCanConvToPolyLineToArea = false;
98 }
99 
100 // ------------------------------------------------------------------------------
101 
GetObjIdentifier() const102 sal_uInt16 SdrMediaObj::GetObjIdentifier() const
103 {
104 	return sal_uInt16( OBJ_MEDIA );
105 }
106 
107 // ------------------------------------------------------------------------------
108 
TakeObjNameSingul(XubString & rName) const109 void SdrMediaObj::TakeObjNameSingul(XubString& rName) const
110 {
111 	rName=ImpGetResStr(STR_ObjNameSingulMEDIA);
112 
113 	String aName( GetName() );
114 
115 	if(aName.Len())
116 	{
117 		rName += sal_Unicode(' ');
118 		rName += sal_Unicode('\'');
119 		rName += aName;
120 		rName += sal_Unicode('\'');
121 	}
122 }
123 
124 // ------------------------------------------------------------------------------
125 
TakeObjNamePlural(XubString & rName) const126 void SdrMediaObj::TakeObjNamePlural(XubString& rName) const
127 {
128 	rName=ImpGetResStr(STR_ObjNamePluralMEDIA);
129 }
130 
131 // ------------------------------------------------------------------------------
132 
operator =(const SdrObject & rObj)133 void SdrMediaObj::operator=(const SdrObject& rObj)
134 {
135 	SdrRectObj::operator=( rObj );
136 
137 	if( rObj.ISA( SdrMediaObj ) )
138     {
139         const SdrMediaObj& rMediaObj = static_cast< const SdrMediaObj& >( rObj );
140 
141         setMediaProperties( rMediaObj.getMediaProperties() );
142         setGraphic( rMediaObj.mapGraphic.get() );
143     }
144 }
145 
146 // ------------------------------------------------------------------------------
147 
AdjustToMaxRect(const Rectangle & rMaxRect,bool bShrinkOnly)148 void SdrMediaObj::AdjustToMaxRect( const Rectangle& rMaxRect, bool bShrinkOnly /* = false */ )
149 {
150 	Size aSize( Application::GetDefaultDevice()->PixelToLogic( getPreferredSize(), MAP_100TH_MM ) );
151 	Size aMaxSize( rMaxRect.GetSize() );
152 
153 	if( aSize.Height() != 0 && aSize.Width() != 0 )
154 	{
155 		Point aPos( rMaxRect.TopLeft() );
156 
157 		// Falls Grafik zu gross, wird die Grafik
158 		// in die Seite eingepasst
159 		if ( (!bShrinkOnly                          ||
160 	    	 ( aSize.Height() > aMaxSize.Height() ) ||
161 		 	( aSize.Width()  > aMaxSize.Width()  ) )&&
162 		 	aSize.Height() && aMaxSize.Height() )
163 		{
164 			float fGrfWH =	(float)aSize.Width() /
165 							(float)aSize.Height();
166 			float fWinWH =	(float)aMaxSize.Width() /
167 							(float)aMaxSize.Height();
168 
169 			// Grafik an Pagesize anpassen (skaliert)
170 			if ( fGrfWH < fWinWH )
171 			{
172 				aSize.Width() = (long)(aMaxSize.Height() * fGrfWH);
173 				aSize.Height()= aMaxSize.Height();
174 			}
175 			else if ( fGrfWH > 0.F )
176 			{
177 				aSize.Width() = aMaxSize.Width();
178 				aSize.Height()= (long)(aMaxSize.Width() / fGrfWH);
179 			}
180 
181 			aPos = rMaxRect.Center();
182 		}
183 
184 		if( bShrinkOnly )
185 			aPos = aRect.TopLeft();
186 
187 		aPos.X() -= aSize.Width() / 2;
188 		aPos.Y() -= aSize.Height() / 2;
189 		SetLogicRect( Rectangle( aPos, aSize ) );
190 	}
191 }
192 
193 // ------------------------------------------------------------------------------
194 
setURL(const::rtl::OUString & rURL)195 void SdrMediaObj::setURL( const ::rtl::OUString& rURL )
196 {
197 	::avmedia::MediaItem aURLItem;
198 
199 	aURLItem.setURL( rURL );
200 	setMediaProperties( aURLItem );
201 }
202 
203 // ------------------------------------------------------------------------------
204 
getURL() const205 const ::rtl::OUString& SdrMediaObj::getURL() const
206 {
207 	return getMediaProperties().getURL();
208 }
209 
210 // ------------------------------------------------------------------------------
211 
setMediaProperties(const::avmedia::MediaItem & rState)212 void SdrMediaObj::setMediaProperties( const ::avmedia::MediaItem& rState )
213 {
214 	mediaPropertiesChanged( rState );
215 	static_cast< ::sdr::contact::ViewContactOfSdrMediaObj& >( GetViewContact() ).executeMediaItem( getMediaProperties() );
216 }
217 
218 // ------------------------------------------------------------------------------
219 
getMediaProperties() const220 const ::avmedia::MediaItem& SdrMediaObj::getMediaProperties() const
221 {
222 	return maMediaProperties;
223 }
224 
225 // ------------------------------------------------------------------------------
226 
hasPreferredSize() const227 bool SdrMediaObj::hasPreferredSize() const
228 {
229 	return static_cast< ::sdr::contact::ViewContactOfSdrMediaObj& >( GetViewContact() ).hasPreferredSize();
230 }
231 
232 // ------------------------------------------------------------------------------
233 
getPreferredSize() const234 Size SdrMediaObj::getPreferredSize() const
235 {
236 	return static_cast< ::sdr::contact::ViewContactOfSdrMediaObj& >( GetViewContact() ).getPreferredSize();
237 }
238 
239 // ------------------------------------------------------------------------------
240 
getGraphic() const241 const Graphic& SdrMediaObj::getGraphic() const
242 {
243     if( !mapGraphic.get() )
244         const_cast< SdrMediaObj* >( this )->mapGraphic.reset( new Graphic( ::avmedia::MediaWindow::grabFrame( getURL(), true ) ) );
245 
246     return *mapGraphic;
247 }
248 
249 // ------------------------------------------------------------------------------
250 
setGraphic(const Graphic * pGraphic)251 void SdrMediaObj::setGraphic( const Graphic* pGraphic )
252 {
253     mapGraphic.reset( pGraphic ? new Graphic( *pGraphic ) : NULL );
254 }
255 
256 // ------------------------------------------------------------------------------
257 
mediaPropertiesChanged(const::avmedia::MediaItem & rNewProperties)258 void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProperties )
259 {
260 	const sal_uInt32 nMaskSet = rNewProperties.getMaskSet();
261 
262 	// use only a subset of MediaItem properties for own own properties
263 	if( ( AVMEDIA_SETMASK_URL & nMaskSet ) &&
264         ( rNewProperties.getURL() != getURL() ) )
265     {
266         setGraphic();
267     	maMediaProperties.setURL( rNewProperties.getURL() );
268     }
269 
270 	if( AVMEDIA_SETMASK_LOOP & nMaskSet )
271 		maMediaProperties.setLoop( rNewProperties.isLoop() );
272 
273 	if( AVMEDIA_SETMASK_MUTE & nMaskSet )
274 		maMediaProperties.setMute( rNewProperties.isMute() );
275 
276 	if( AVMEDIA_SETMASK_VOLUMEDB & nMaskSet )
277 		maMediaProperties.setVolumeDB( rNewProperties.getVolumeDB() );
278 
279 	if( AVMEDIA_SETMASK_ZOOM & nMaskSet )
280 		maMediaProperties.setZoom( rNewProperties.getZoom() );
281 }
282