Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
21 : #include <wrtsh.hxx>
22 : #include <doc.hxx>
23 : #include <swtypes.hxx>
24 : #include <view.hxx>
25 : #include <edtwin.hxx>
26 : #include <swcli.hxx>
27 : #include <cmdid.h>
28 : #include <cfgitems.hxx>
29 :
30 : #include <toolkit/helper/vclunohelper.hxx>
31 :
32 : using namespace com::sun::star;
33 :
34 0 : SwOleClient::SwOleClient( SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj ) :
35 : SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() ), bInDoVerb( sal_False ),
36 0 : bOldCheckForOLEInCaption( pView->GetWrtShell().IsCheckForOLEInCaption() )
37 : {
38 0 : SetObject( xObj.GetObject() );
39 0 : }
40 :
41 0 : void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect )
42 : {
43 : // The server wants to change the client size.
44 : // We put the desired size in the core. The attributes of the frame
45 : // are set to the desired value. This value will be passed on to the
46 : // InPlaceClient.
47 : // The core accepts or formats the adjusted values not necessarily.
48 : // If the Ole-Frm is formatted, then the CalcAndSetScale() of the WrtShell
49 : // will be called. There the scaling of the SwOleClient is set if necessary.
50 :
51 0 : SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
52 :
53 0 : rSh.StartAllAction();
54 :
55 : // the aLogRect will get the preliminary size now
56 0 : aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
57 :
58 : // the EndAllAction() call will trigger CalcAndSetScale() call,
59 : // so the embedded object must get the correct size before
60 0 : if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
61 : {
62 : // size has changed, so first change visual area of the object before we resize its view
63 : // without this the object always would be scaled - now it has the choice
64 :
65 : // TODO/LEAN: getMapUnit can switch object to running state
66 0 : MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
67 0 : MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
68 :
69 0 : Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(),
70 0 : Fraction( aLogRect.GetHeight() ) / GetScaleHeight() );
71 :
72 : // convert to logical coordinates of the embedded object
73 0 : Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
74 0 : GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
75 : }
76 :
77 0 : rSh.EndAllAction();
78 :
79 0 : SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )),
80 0 : aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
81 0 : aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() );
82 0 : aLogRect.SetSize( aPrt.SSize() );
83 0 : }
84 :
85 0 : void SwOleClient::ObjectAreaChanged()
86 : {
87 0 : SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
88 0 : SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() ));
89 0 : if ( !aFrm.IsOver( rSh.VisArea() ) )
90 0 : rSh.MakeVisible( aFrm );
91 0 : }
92 :
93 0 : void SwOleClient::ViewChanged()
94 : {
95 0 : if ( bInDoVerb )
96 0 : return;
97 :
98 0 : if ( GetAspect() == embed::Aspects::MSOLE_ICON )
99 : {
100 : // the iconified object seems not to need such a scaling handling
101 : // since the replacement image and the size a completely controlled by the container
102 : // TODO/LATER: when the icon exchange is implemented the scaling handling
103 : // might be required again here
104 0 : return;
105 : }
106 :
107 0 : SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
108 :
109 : // Adjust the size of the object in the core. The Scaling must
110 : // be considered. Repercussions on the object are considered by
111 : // CalcAndSetScale() of the WrtShell if the size / position of
112 : // the frame in the core changes.
113 :
114 : // TODO/LEAN: getMapUnit can switch object to running state
115 0 : awt::Size aSz;
116 : try
117 : {
118 0 : aSz = GetObject()->getVisualAreaSize( GetAspect() );
119 : }
120 0 : catch (const embed::NoVisualAreaSizeException&)
121 : {
122 : // Nothing will be done
123 : }
124 0 : catch (const uno::Exception&)
125 : {
126 : OSL_FAIL( "Something goes wrong on requesting object size!\n" );
127 : }
128 :
129 0 : Size aVisSize( aSz.Width, aSz.Height );
130 :
131 : // As long as from the object comes no reasonable size
132 : // nothing can be scaled.
133 0 : if( !aVisSize.Width() || !aVisSize.Height() )
134 0 : return;
135 :
136 : // first convert to TWIPS before scaling, because scaling factors are calculated for
137 : // the TWIPS mapping and so they will produce the best results if applied to TWIPS based
138 : // coordinates
139 0 : const MapMode aMyMap ( MAP_TWIP );
140 0 : const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
141 0 : aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
142 :
143 0 : aVisSize.Width() = Fraction( aVisSize.Width() ) * GetScaleWidth();
144 0 : aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight();
145 :
146 0 : SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
147 0 : rSh.LockView( sal_True ); // Prevent scrolling in the EndAction
148 0 : rSh.StartAllAction();
149 0 : rSh.RequestObjectResize( aRect, GetObject() );
150 0 : rSh.EndAllAction();
151 0 : rSh.LockView( sal_False );
152 : }
153 :
154 0 : void SwOleClient::MakeVisible()
155 : {
156 0 : const SwWrtShell &rSh = ((SwView*)GetViewShell())->GetWrtShell();
157 0 : rSh.MakeObjVisible( GetObject() );
158 0 : }
159 :
160 0 : void SwOleClient::FormatChanged()
161 : {
162 0 : const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
163 0 : SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
164 0 : if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
165 : {
166 0 : SwWrtShell & rWrtSh = pView->GetWrtShell();
167 0 : if (rWrtSh.GetDoc()->get( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT ))
168 0 : rWrtSh.AlignFormulaToBaseline( xObj );
169 0 : }
170 0 : }
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|