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_sw.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <wrtsh.hxx> 34*cdf0e10cSrcweir #include <doc.hxx> 35*cdf0e10cSrcweir #include <swtypes.hxx> 36*cdf0e10cSrcweir #include <view.hxx> 37*cdf0e10cSrcweir #include <edtwin.hxx> 38*cdf0e10cSrcweir #include <swcli.hxx> 39*cdf0e10cSrcweir #include <cmdid.h> 40*cdf0e10cSrcweir #include <cfgitems.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using namespace com::sun::star; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir SwOleClient::SwOleClient( SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj ) : 47*cdf0e10cSrcweir SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() ), bInDoVerb( sal_False ), 48*cdf0e10cSrcweir bOldCheckForOLEInCaption( pView->GetWrtShell().IsCheckForOLEInCaption() ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir SetObject( xObj.GetObject() ); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir //Der Server moechte die Clientgrosse verandern. 56*cdf0e10cSrcweir //Wir stecken die Wunschgroesse in die Core. Die Attribute des Rahmens 57*cdf0e10cSrcweir //werden auf den Wunschwert eingestellt. Dieser Wert wird also auch an 58*cdf0e10cSrcweir //den InPlaceClient weitergegeben. 59*cdf0e10cSrcweir //Die Core aktzeptiert bzw. formatiert die eingestellten Werte nicht 60*cdf0e10cSrcweir //zwangslaeufig. Wenn der Ole-Frm formatiert wurde wird das CalcAndSetScale() 61*cdf0e10cSrcweir //der WrtShell gerufen. Dort wird ggf. die Scalierung des SwOleClient 62*cdf0e10cSrcweir //eingestellt. 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell(); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir rSh.StartAllAction(); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // the aLogRect will get the preliminary size now 69*cdf0e10cSrcweir aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) ); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // the EndAllAction() call will trigger CalcAndSetScale() call, 72*cdf0e10cSrcweir // so the embedded object must get the correct size before 73*cdf0e10cSrcweir if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir // size has changed, so first change visual area of the object before we resize its view 76*cdf0e10cSrcweir // without this the object always would be scaled - now it has the choice 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // TODO/LEAN: getMapUnit can switch object to running state 79*cdf0e10cSrcweir MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) ); 80*cdf0e10cSrcweir MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(), 83*cdf0e10cSrcweir Fraction( aLogRect.GetHeight() ) / GetScaleHeight() ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // convert to logical coordinates of the embedded object 86*cdf0e10cSrcweir Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap ); 87*cdf0e10cSrcweir GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir rSh.EndAllAction(); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )), 93*cdf0e10cSrcweir aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() )); 94*cdf0e10cSrcweir aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() ); 95*cdf0e10cSrcweir aLogRect.SetSize( aPrt.SSize() ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir void SwOleClient::ObjectAreaChanged() 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell(); 101*cdf0e10cSrcweir SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )), 102*cdf0e10cSrcweir aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() )); 103*cdf0e10cSrcweir if ( !aFrm.IsOver( rSh.VisArea() ) ) 104*cdf0e10cSrcweir rSh.MakeVisible( aFrm ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void SwOleClient::ViewChanged() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir if ( bInDoVerb ) 110*cdf0e10cSrcweir return; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if ( GetAspect() == embed::Aspects::MSOLE_ICON ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir // the iconified object seems not to need such a scaling handling 115*cdf0e10cSrcweir // since the replacement image and the size a completely controlled by the container 116*cdf0e10cSrcweir // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here 117*cdf0e10cSrcweir return; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell(); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //Einstellen der Groesse des Objektes in der Core. Die Scalierung muss 123*cdf0e10cSrcweir //beruecksichtigt werden. Rueckwirkung auf das Objekt werden von 124*cdf0e10cSrcweir //CalcAndSetScale() der WrtShell beruecksichtig, wenn die Groesse/Pos des 125*cdf0e10cSrcweir //Rahmens in der Core sich veraendert. 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // TODO/LEAN: getMapUnit can switch object to running state 128*cdf0e10cSrcweir awt::Size aSz; 129*cdf0e10cSrcweir try 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir aSz = GetObject()->getVisualAreaSize( GetAspect() ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir catch( embed::NoVisualAreaSizeException& ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir // Nothing will be done 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir catch( uno::Exception& ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir // this is an error 140*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Something goes wrong on requesting object size!\n" ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir Size aVisSize( aSz.Width, aSz.Height ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // Bug 24833: solange keine vernuenftige Size vom Object kommt, 146*cdf0e10cSrcweir // kann nichts skaliert werden 147*cdf0e10cSrcweir if( !aVisSize.Width() || !aVisSize.Height() ) 148*cdf0e10cSrcweir return; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // first convert to TWIPS before scaling, because scaling factors are calculated for 151*cdf0e10cSrcweir // the TWIPS mapping and so they will produce the best results if applied to TWIPS based 152*cdf0e10cSrcweir // coordinates 153*cdf0e10cSrcweir const MapMode aMyMap ( MAP_TWIP ); 154*cdf0e10cSrcweir const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) ); 155*cdf0e10cSrcweir aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir aVisSize.Width() = Fraction( aVisSize.Width() ) * GetScaleWidth(); 158*cdf0e10cSrcweir aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight(); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize ); 161*cdf0e10cSrcweir rSh.LockView( sal_True ); //Scrollen im EndAction verhindern 162*cdf0e10cSrcweir rSh.StartAllAction(); 163*cdf0e10cSrcweir rSh.RequestObjectResize( aRect, GetObject() ); 164*cdf0e10cSrcweir rSh.EndAllAction(); 165*cdf0e10cSrcweir rSh.LockView( sal_False ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir void SwOleClient::MakeVisible() 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir const SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell(); 171*cdf0e10cSrcweir rSh.MakeObjVisible( GetObject() ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // --> #i972# 175*cdf0e10cSrcweir void SwOleClient::FormatChanged() 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() ); 178*cdf0e10cSrcweir SwView * pView = dynamic_cast< SwView * >( GetViewShell() ); 179*cdf0e10cSrcweir if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir SwWrtShell & rWrtSh = pView->GetWrtShell(); 182*cdf0e10cSrcweir if (rWrtSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT )) 183*cdf0e10cSrcweir rWrtSh.AlignFormulaToBaseline( xObj ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir // <-- 187*cdf0e10cSrcweir 188