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