update dev300-m58
[ooovba.git] / sw / source / ui / uiview / swcli.cxx
blobdd1a9603b858653077f480551671f48c07fce080
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swcli.cxx,v $
10 * $Revision: 1.14 $
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_sw.hxx"
33 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
36 #include <wrtsh.hxx>
37 #include <swtypes.hxx>
38 #ifndef _VIEW_HXX
39 #include <view.hxx>
40 #endif
41 #include <edtwin.hxx>
42 #include <swcli.hxx>
44 #include <toolkit/helper/vclunohelper.hxx>
46 using namespace com::sun::star;
48 SwOleClient::SwOleClient( SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj ) :
49 SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() ), bInDoVerb( FALSE ),
50 bOldCheckForOLEInCaption( pView->GetWrtShell().IsCheckForOLEInCaption() )
52 SetObject( xObj.GetObject() );
55 void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect )
57 //Der Server moechte die Clientgrosse verandern.
58 //Wir stecken die Wunschgroesse in die Core. Die Attribute des Rahmens
59 //werden auf den Wunschwert eingestellt. Dieser Wert wird also auch an
60 //den InPlaceClient weitergegeben.
61 //Die Core aktzeptiert bzw. formatiert die eingestellten Werte nicht
62 //zwangslaeufig. Wenn der Ole-Frm formatiert wurde wird das CalcAndSetScale()
63 //der WrtShell gerufen. Dort wird ggf. die Scalierung des SwOleClient
64 //eingestellt.
66 SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
68 rSh.StartAllAction();
70 // the aLogRect will get the preliminary size now
71 aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
73 // the EndAllAction() call will trigger CalcAndSetScale() call,
74 // so the embedded object must get the correct size before
75 if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
77 // size has changed, so first change visual area of the object before we resize its view
78 // without this the object always would be scaled - now it has the choice
80 // TODO/LEAN: getMapUnit can switch object to running state
81 MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
82 MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
84 Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(),
85 Fraction( aLogRect.GetHeight() ) / GetScaleHeight() );
87 // convert to logical coordinates of the embedded object
88 Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
89 GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
92 rSh.EndAllAction();
94 SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )),
95 aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
96 aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() );
97 aLogRect.SetSize( aPrt.SSize() );
100 void SwOleClient::ObjectAreaChanged()
102 SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
103 SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )),
104 aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
105 if ( !aFrm.IsOver( rSh.VisArea() ) )
106 rSh.MakeVisible( aFrm );
109 void SwOleClient::ViewChanged()
111 if ( bInDoVerb )
112 return;
114 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
116 // the iconified object seems not to need such a scaling handling
117 // since the replacement image and the size a completely controlled by the container
118 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
119 return;
122 SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
124 //Einstellen der Groesse des Objektes in der Core. Die Scalierung muss
125 //beruecksichtigt werden. Rueckwirkung auf das Objekt werden von
126 //CalcAndSetScale() der WrtShell beruecksichtig, wenn die Groesse/Pos des
127 //Rahmens in der Core sich veraendert.
129 // TODO/LEAN: getMapUnit can switch object to running state
130 awt::Size aSz;
133 aSz = GetObject()->getVisualAreaSize( GetAspect() );
135 catch( embed::NoVisualAreaSizeException& )
137 // Nothing will be done
139 catch( uno::Exception& )
141 // this is an error
142 OSL_ENSURE( sal_False, "Something goes wrong on requesting object size!\n" );
145 Size aVisSize( aSz.Width, aSz.Height );
147 // Bug 24833: solange keine vernuenftige Size vom Object kommt,
148 // kann nichts skaliert werden
149 if( !aVisSize.Width() || !aVisSize.Height() )
150 return;
152 // first convert to TWIPS before scaling, because scaling factors are calculated for
153 // the TWIPS mapping and so they will produce the best results if applied to TWIPS based
154 // coordinates
155 const MapMode aMyMap ( MAP_TWIP );
156 const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
157 aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
159 aVisSize.Width() = Fraction( aVisSize.Width() ) * GetScaleWidth();
160 aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight();
162 SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
163 rSh.LockView( TRUE ); //Scrollen im EndAction verhindern
164 rSh.StartAllAction();
165 rSh.RequestObjectResize( aRect, GetObject() );
166 rSh.EndAllAction();
167 rSh.LockView( FALSE );
170 void SwOleClient::MakeVisible()
172 const SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
173 rSh.MakeObjVisible( GetObject() );