bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uiview / swcli.cxx
bloba8a0bf64b20b317da8f4e5ca7d8a1503b279955d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
22 #include <wrtsh.hxx>
23 #include <doc.hxx>
24 #include <swtypes.hxx>
25 #include <view.hxx>
26 #include <edtwin.hxx>
27 #include <swcli.hxx>
28 #include <cmdid.h>
29 #include <cfgitems.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
33 using namespace com::sun::star;
35 SwOleClient::SwOleClient( SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj ) :
36 SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() ), bInDoVerb( sal_False ),
37 bOldCheckForOLEInCaption( pView->GetWrtShell().IsCheckForOLEInCaption() )
39 SetObject( xObj.GetObject() );
42 void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect )
44 //Der Server moechte die Clientgrosse verandern.
45 //Wir stecken die Wunschgroesse in die Core. Die Attribute des Rahmens
46 //werden auf den Wunschwert eingestellt. Dieser Wert wird also auch an
47 //den InPlaceClient weitergegeben.
48 //Die Core aktzeptiert bzw. formatiert die eingestellten Werte nicht
49 //zwangslaeufig. Wenn der Ole-Frm formatiert wurde wird das CalcAndSetScale()
50 //der WrtShell gerufen. Dort wird ggf. die Scalierung des SwOleClient
51 //eingestellt.
53 SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
55 rSh.StartAllAction();
57 // the aLogRect will get the preliminary size now
58 aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
60 // the EndAllAction() call will trigger CalcAndSetScale() call,
61 // so the embedded object must get the correct size before
62 if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
64 // size has changed, so first change visual area of the object before we resize its view
65 // without this the object always would be scaled - now it has the choice
67 // TODO/LEAN: getMapUnit can switch object to running state
68 MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
69 MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
71 Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(),
72 Fraction( aLogRect.GetHeight() ) / GetScaleHeight() );
74 // convert to logical coordinates of the embedded object
75 Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
76 GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
79 rSh.EndAllAction();
81 SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )),
82 aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
83 aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() );
84 aLogRect.SetSize( aPrt.SSize() );
87 void SwOleClient::ObjectAreaChanged()
89 SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
90 SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() ));
91 if ( !aFrm.IsOver( rSh.VisArea() ) )
92 rSh.MakeVisible( aFrm );
95 void SwOleClient::ViewChanged()
97 if ( bInDoVerb )
98 return;
100 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
102 // the iconified object seems not to need such a scaling handling
103 // since the replacement image and the size a completely controlled by the container
104 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
105 return;
108 SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
110 //Einstellen der Groesse des Objektes in der Core. Die Scalierung muss
111 //beruecksichtigt werden. Rueckwirkung auf das Objekt werden von
112 //CalcAndSetScale() der WrtShell beruecksichtig, wenn die Groesse/Pos des
113 //Rahmens in der Core sich veraendert.
115 // TODO/LEAN: getMapUnit can switch object to running state
116 awt::Size aSz;
119 aSz = GetObject()->getVisualAreaSize( GetAspect() );
121 catch (const embed::NoVisualAreaSizeException&)
123 // Nothing will be done
125 catch (const uno::Exception&)
127 // this is an error
128 OSL_FAIL( "Something goes wrong on requesting object size!\n" );
131 Size aVisSize( aSz.Width, aSz.Height );
133 // solange keine vernuenftige Size vom Object kommt,
134 // kann nichts skaliert werden
135 if( !aVisSize.Width() || !aVisSize.Height() )
136 return;
138 // first convert to TWIPS before scaling, because scaling factors are calculated for
139 // the TWIPS mapping and so they will produce the best results if applied to TWIPS based
140 // coordinates
141 const MapMode aMyMap ( MAP_TWIP );
142 const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
143 aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
145 aVisSize.Width() = Fraction( aVisSize.Width() ) * GetScaleWidth();
146 aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight();
148 SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
149 rSh.LockView( sal_True ); //Scrollen im EndAction verhindern
150 rSh.StartAllAction();
151 rSh.RequestObjectResize( aRect, GetObject() );
152 rSh.EndAllAction();
153 rSh.LockView( sal_False );
156 void SwOleClient::MakeVisible()
158 const SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
159 rSh.MakeObjVisible( GetObject() );
162 void SwOleClient::FormatChanged()
164 const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
165 SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
166 if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
168 SwWrtShell & rWrtSh = pView->GetWrtShell();
169 if (rWrtSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ))
170 rWrtSh.AlignFormulaToBaseline( xObj );
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */