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