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