xref: /aoo42x/main/sw/source/ui/uiview/swcli.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <wrtsh.hxx>
30cdf0e10cSrcweir #include <doc.hxx>
31cdf0e10cSrcweir #include <swtypes.hxx>
32cdf0e10cSrcweir #include <view.hxx>
33cdf0e10cSrcweir #include <edtwin.hxx>
34cdf0e10cSrcweir #include <swcli.hxx>
35cdf0e10cSrcweir #include <cmdid.h>
36cdf0e10cSrcweir #include <cfgitems.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace com::sun::star;
41cdf0e10cSrcweir 
SwOleClient(SwView * pView,SwEditWin * pWin,const svt::EmbeddedObjectRef & xObj)42cdf0e10cSrcweir SwOleClient::SwOleClient( SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj ) :
43cdf0e10cSrcweir     SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() ), bInDoVerb( sal_False ),
44cdf0e10cSrcweir 	bOldCheckForOLEInCaption( pView->GetWrtShell().IsCheckForOLEInCaption() )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     SetObject( xObj.GetObject() );
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
RequestNewObjectArea(Rectangle & aLogRect)49cdf0e10cSrcweir void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	//Der Server moechte die Clientgrosse verandern.
52cdf0e10cSrcweir 	//Wir stecken die Wunschgroesse in die Core. Die Attribute des Rahmens
53cdf0e10cSrcweir 	//werden auf den Wunschwert eingestellt. Dieser Wert wird also auch an
54cdf0e10cSrcweir 	//den InPlaceClient weitergegeben.
55cdf0e10cSrcweir 	//Die Core aktzeptiert bzw. formatiert die eingestellten Werte nicht
56cdf0e10cSrcweir 	//zwangslaeufig. Wenn der Ole-Frm formatiert wurde wird das CalcAndSetScale()
57cdf0e10cSrcweir 	//der WrtShell gerufen. Dort wird ggf. die Scalierung des SwOleClient
58cdf0e10cSrcweir 	//eingestellt.
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	rSh.StartAllAction();
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	// the aLogRect will get the preliminary size now
65cdf0e10cSrcweir 	aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	// the EndAllAction() call will trigger CalcAndSetScale() call,
68cdf0e10cSrcweir 	// so the embedded object must get the correct size before
69cdf0e10cSrcweir 	if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		// size has changed, so first change visual area of the object before we resize its view
72cdf0e10cSrcweir 		// without this the object always would be scaled - now it has the choice
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		// TODO/LEAN: getMapUnit can switch object to running state
75cdf0e10cSrcweir 		MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
76cdf0e10cSrcweir 		MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 		Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(),
79cdf0e10cSrcweir 						  Fraction( aLogRect.GetHeight() ) / GetScaleHeight() );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		// convert to logical coordinates of the embedded object
82cdf0e10cSrcweir 		Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
83cdf0e10cSrcweir 		GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	rSh.EndAllAction();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED,     0, GetObject() )),
89cdf0e10cSrcweir            aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
90cdf0e10cSrcweir     aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() );
91cdf0e10cSrcweir     aLogRect.SetSize( aPrt.SSize() );
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
ObjectAreaChanged()94cdf0e10cSrcweir void SwOleClient::ObjectAreaChanged()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
97cdf0e10cSrcweir     SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED,     0, GetObject() )),
98cdf0e10cSrcweir            aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
99cdf0e10cSrcweir 	if ( !aFrm.IsOver( rSh.VisArea() ) )
100cdf0e10cSrcweir 		rSh.MakeVisible( aFrm );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
ViewChanged()103cdf0e10cSrcweir void SwOleClient::ViewChanged()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     if ( bInDoVerb )
106cdf0e10cSrcweir 		return;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	if ( GetAspect() == embed::Aspects::MSOLE_ICON )
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		// the iconified object seems not to need such a scaling handling
111cdf0e10cSrcweir 		// since the replacement image and the size a completely controlled by the container
112cdf0e10cSrcweir 		// TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
113cdf0e10cSrcweir 		return;
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	//Einstellen der Groesse des Objektes in der Core. Die Scalierung muss
119cdf0e10cSrcweir 	//beruecksichtigt werden. Rueckwirkung auf das Objekt werden von
120cdf0e10cSrcweir 	//CalcAndSetScale() der WrtShell beruecksichtig, wenn die Groesse/Pos des
121cdf0e10cSrcweir 	//Rahmens in der Core sich veraendert.
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // TODO/LEAN: getMapUnit can switch object to running state
124cdf0e10cSrcweir     awt::Size aSz;
125cdf0e10cSrcweir 	try
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		aSz = GetObject()->getVisualAreaSize( GetAspect() );
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 	catch( embed::NoVisualAreaSizeException& )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		// Nothing will be done
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir 	catch( uno::Exception& )
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		// this is an error
136cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "Something goes wrong on requesting object size!\n" );
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     Size aVisSize( aSz.Width, aSz.Height );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 	// Bug 24833: solange keine vernuenftige Size vom Object kommt,
142cdf0e10cSrcweir 	// 				kann nichts skaliert werden
143cdf0e10cSrcweir 	if( !aVisSize.Width() || !aVisSize.Height() )
144cdf0e10cSrcweir 		return;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // first convert to TWIPS before scaling, because scaling factors are calculated for
147cdf0e10cSrcweir     // the TWIPS mapping and so they will produce the best results if applied to TWIPS based
148cdf0e10cSrcweir     // coordinates
149cdf0e10cSrcweir     const MapMode aMyMap ( MAP_TWIP );
150cdf0e10cSrcweir     const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
151cdf0e10cSrcweir 	aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     aVisSize.Width() = Fraction( aVisSize.Width()  ) * GetScaleWidth();
154cdf0e10cSrcweir     aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
157cdf0e10cSrcweir 	rSh.LockView( sal_True );	//Scrollen im EndAction verhindern
158cdf0e10cSrcweir 	rSh.StartAllAction();
159cdf0e10cSrcweir     rSh.RequestObjectResize( aRect, GetObject() );
160cdf0e10cSrcweir 	rSh.EndAllAction();
161cdf0e10cSrcweir 	rSh.LockView( sal_False );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
MakeVisible()164cdf0e10cSrcweir void SwOleClient::MakeVisible()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	const SwWrtShell &rSh  = ((SwView*)GetViewShell())->GetWrtShell();
167cdf0e10cSrcweir     rSh.MakeObjVisible( GetObject() );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir // --> #i972#
FormatChanged()171cdf0e10cSrcweir void SwOleClient::FormatChanged()
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
174cdf0e10cSrcweir     SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
175cdf0e10cSrcweir     if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         SwWrtShell & rWrtSh = pView->GetWrtShell();
178cdf0e10cSrcweir         if (rWrtSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ))
179cdf0e10cSrcweir             rWrtSh.AlignFormulaToBaseline( xObj );
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir // <--
183cdf0e10cSrcweir 
184