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