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