1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofsdrmediaobj.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx>
35 #include <svx/svdomedia.hxx>
36 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx>
37 #include <drawinglayer/primitive2d/mediaprimitive2d.hxx>
39 namespace sdr
{ namespace contact
{
41 // ----------------------------
42 // - ViewContactOfSdrMediaObj -
43 // ----------------------------
45 ViewContactOfSdrMediaObj::ViewContactOfSdrMediaObj( SdrMediaObj
& rMediaObj
) :
46 ViewContactOfSdrObj( rMediaObj
)
50 // ------------------------------------------------------------------------------
52 ViewContactOfSdrMediaObj::~ViewContactOfSdrMediaObj()
56 // ------------------------------------------------------------------------------
58 ViewObjectContact
& ViewContactOfSdrMediaObj::CreateObjectSpecificViewObjectContact(ObjectContact
& rObjectContact
)
60 return *( new ViewObjectContactOfSdrMediaObj( rObjectContact
, *this, static_cast< SdrMediaObj
& >( GetSdrObject() ).getMediaProperties() ) );
63 // ------------------------------------------------------------------------------
65 bool ViewContactOfSdrMediaObj::hasPreferredSize() const
67 // #i71805# Since we may have a whole bunch of VOCs here, make a loop
68 // return true if all have their preferred size
69 const sal_uInt32
nCount(getViewObjectContactCount());
72 for(sal_uInt32
a(0); bRetval
&& a
< nCount
; a
++)
74 ViewObjectContact
* pCandidate
= getViewObjectContact(a
);
76 if(pCandidate
&& !static_cast< ViewObjectContactOfSdrMediaObj
* >(pCandidate
)->hasPreferredSize())
85 // ------------------------------------------------------------------------------
87 Size
ViewContactOfSdrMediaObj::getPreferredSize() const
89 // #i71805# Since we may have a whole bunch of VOCs here, make a loop
90 // return first useful size -> the size from the first which is visualized as a window
91 const sal_uInt32
nCount(getViewObjectContactCount());
93 for(sal_uInt32
a(0); a
< nCount
; a
++)
95 ViewObjectContact
* pCandidate
= getViewObjectContact(a
);
96 Size
aSize(pCandidate
? static_cast< ViewObjectContactOfSdrMediaObj
* >(pCandidate
)->getPreferredSize() : Size());
98 if(0 != aSize
.getWidth() || 0 != aSize
.getHeight())
107 // ------------------------------------------------------------------------------
109 void ViewContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem
& rItem
) const
111 // #i71805# Since we may have a whole bunch of VOCs here, make a loop
112 const sal_uInt32
nCount(getViewObjectContactCount());
114 for(sal_uInt32
a(0); a
< nCount
; a
++)
116 ViewObjectContact
* pCandidate
= getViewObjectContact(a
);
120 static_cast< ViewObjectContactOfSdrMediaObj
* >(pCandidate
)->updateMediaItem(rItem
);
125 // ------------------------------------------------------------------------------
127 void ViewContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem
& rItem
)
129 const sal_uInt32
nCount(getViewObjectContactCount());
131 for(sal_uInt32
a(0); a
< nCount
; a
++)
133 ViewObjectContact
* pCandidate
= getViewObjectContact(a
);
137 static_cast< ViewObjectContactOfSdrMediaObj
* >(pCandidate
)->executeMediaItem(rItem
);
142 // ------------------------------------------------------------------------------
144 void ViewContactOfSdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem
& rNewState
)
146 static_cast< SdrMediaObj
& >(GetSdrObject()).mediaPropertiesChanged(rNewState
);
149 }} // end of namespace sdr::contact
155 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfSdrMediaObj::createViewIndependentPrimitive2DSequence() const
157 // create range using the model data directly. This is in SdrTextObj::aRect which i will access using
158 // GetGeoRect() to not trigger any calculations. It's the unrotated geometry which is okay for MediaObjects ATM.
159 const Rectangle
& rRectangle(GetSdrMediaObj().GetGeoRect());
160 const basegfx::B2DRange
aRange(rRectangle
.Left(), rRectangle
.Top(), rRectangle
.Right(), rRectangle
.Bottom());
162 // create object transform
163 basegfx::B2DHomMatrix aTransform
;
164 aTransform
.set(0, 0, aRange
.getWidth());
165 aTransform
.set(1, 1, aRange
.getHeight());
166 aTransform
.set(0, 2, aRange
.getMinX());
167 aTransform
.set(1, 2, aRange
.getMinY());
169 // create media primitive
170 const basegfx::BColor
aBackgroundColor(67.0 / 255.0, 67.0 / 255.0, 67.0 / 255.0);
171 const rtl::OUString
& rURL(GetSdrMediaObj().getURL());
172 const sal_uInt32
nPixelBorder(4L);
173 const drawinglayer::primitive2d::Primitive2DReference
xRetval(new drawinglayer::primitive2d::MediaPrimitive2D(
174 aTransform
, rURL
, aBackgroundColor
, nPixelBorder
));
176 return drawinglayer::primitive2d::Primitive2DSequence(&xRetval
, 1);
178 } // end of namespace contact
179 } // end of namespace sdr
181 //////////////////////////////////////////////////////////////////////////////