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 <IDocumentSettingAccess.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>
30 :
31 : #include <toolkit/helper/vclunohelper.hxx>
32 :
33 : using namespace com::sun::star;
34 :
35 8 : SwOleClient::SwOleClient(SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef& xObj)
36 : : SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() )
37 : , m_IsInDoVerb(false)
38 8 : , m_IsOldCheckForOLEInCaption(pView->GetWrtShell().IsCheckForOLEInCaption())
39 : {
40 8 : SetObject( xObj.GetObject() );
41 8 : }
42 :
43 0 : void SwOleClient::RequestNewObjectArea( Rectangle& aLogRect )
44 : {
45 : // The server wants to change the client size.
46 : // We put the desired size in the core. The attributes of the frame
47 : // are set to the desired value. This value will be passed on to the
48 : // InPlaceClient.
49 : // The core accepts or formats the adjusted values not necessarily.
50 : // If the Ole-Frm is formatted, then the CalcAndSetScale() of the WrtShell
51 : // will be called. There the scaling of the SwOleClient is set if necessary.
52 :
53 0 : SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
54 :
55 0 : rSh.StartAllAction();
56 :
57 : // the aLogRect will get the preliminary size now
58 0 : aLogRect.SetSize( rSh.RequestObjectResize( SwRect( aLogRect ), GetObject() ) );
59 :
60 : // the EndAllAction() call will trigger CalcAndSetScale() call,
61 : // so the embedded object must get the correct size before
62 0 : if ( aLogRect.GetSize() != GetScaledObjArea().GetSize() )
63 : {
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
66 :
67 : // TODO/LEAN: getMapUnit can switch object to running state
68 0 : MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
69 0 : MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
70 :
71 0 : Size aNewObjSize( Fraction( aLogRect.GetWidth() ) / GetScaleWidth(),
72 0 : Fraction( aLogRect.GetHeight() ) / GetScaleHeight() );
73 :
74 : // convert to logical coordinates of the embedded object
75 0 : Size aNewSize = GetEditWin()->LogicToLogic( aNewObjSize, &aClientMap, &aObjectMap );
76 0 : GetObject()->setVisualAreaSize( GetAspect(), awt::Size( aNewSize.Width(), aNewSize.Height() ) );
77 : }
78 :
79 0 : rSh.EndAllAction();
80 :
81 0 : SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() )),
82 0 : aPrt( rSh.GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, GetObject() ));
83 0 : aLogRect.SetPos( aPrt.Pos() + aFrm.Pos() );
84 0 : aLogRect.SetSize( aPrt.SSize() );
85 0 : }
86 :
87 0 : void SwOleClient::ObjectAreaChanged()
88 : {
89 0 : SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
90 0 : SwRect aFrm( rSh.GetAnyCurRect( RECT_FLY_EMBEDDED, 0, GetObject() ));
91 0 : if ( !aFrm.IsOver( rSh.VisArea() ) )
92 0 : rSh.MakeVisible( aFrm );
93 0 : }
94 :
95 23 : void SwOleClient::ViewChanged()
96 : {
97 23 : if (m_IsInDoVerb)
98 0 : return;
99 :
100 23 : if ( GetAspect() == embed::Aspects::MSOLE_ICON )
101 : {
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
105 : // might be required again here
106 0 : return;
107 : }
108 :
109 23 : SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
110 :
111 : // Adjust the size of the object in the core. The Scaling must
112 : // be considered. Repercussions on the object are considered by
113 : // CalcAndSetScale() of the WrtShell if the size / position of
114 : // the frame in the core changes.
115 :
116 : // TODO/LEAN: getMapUnit can switch object to running state
117 23 : awt::Size aSz;
118 : try
119 : {
120 23 : aSz = GetObject()->getVisualAreaSize( GetAspect() );
121 : }
122 0 : catch (const embed::NoVisualAreaSizeException&)
123 : {
124 : // Nothing will be done
125 : }
126 0 : catch (const uno::Exception&)
127 : {
128 : OSL_FAIL( "Something goes wrong on requesting object size!\n" );
129 : }
130 :
131 23 : Size aVisSize( aSz.Width, aSz.Height );
132 :
133 : // As long as from the object comes no reasonable size
134 : // nothing can be scaled.
135 23 : if( !aVisSize.Width() || !aVisSize.Height() )
136 0 : return;
137 :
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 23 : const MapMode aMyMap ( MAP_TWIP );
142 46 : const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
143 23 : aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
144 :
145 23 : aVisSize.Width() = Fraction( aVisSize.Width() ) * GetScaleWidth();
146 23 : aVisSize.Height()= Fraction( aVisSize.Height() ) * GetScaleHeight();
147 :
148 23 : SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
149 23 : rSh.LockView( true ); // Prevent scrolling in the EndAction
150 23 : rSh.StartAllAction();
151 23 : rSh.RequestObjectResize( aRect, GetObject() );
152 23 : rSh.EndAllAction();
153 46 : rSh.LockView( false );
154 : }
155 :
156 0 : void SwOleClient::MakeVisible()
157 : {
158 0 : const SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
159 0 : rSh.MakeObjVisible( GetObject() );
160 0 : }
161 :
162 8 : void SwOleClient::FormatChanged()
163 : {
164 8 : const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
165 8 : SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
166 8 : if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
167 : {
168 0 : SwWrtShell & rWrtSh = pView->GetWrtShell();
169 0 : if (rWrtSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ))
170 0 : rWrtSh.AlignFormulaToBaseline( xObj );
171 8 : }
172 185 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|