LibreOffice Module sw (master)  1
swcli.cxx
Go to the documentation of this file.
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 <com/sun/star/embed/XEmbeddedObject.hpp>
22 #include <wrtsh.hxx>
23 #include <doc.hxx>
25 #include <view.hxx>
26 #include <edtwin.hxx>
27 #include <swcli.hxx>
28 #include <svtools/embedhlp.hxx>
29 #include <osl/diagnose.h>
30 
32 
33 using namespace com::sun::star;
34 
36  : SfxInPlaceClient( pView, pWin, xObj.GetViewAspect() )
37  , m_IsInDoVerb(false)
38  , m_IsOldCheckForOLEInCaption(pView->GetWrtShell().IsCheckForOLEInCaption())
39 {
40  SetObject( xObj.GetObject() );
41 }
42 
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-Frame is formatted, then the CalcAndSetScale() of the WrtShell
51  // will be called. There the scaling of the SwOleClient is set if necessary.
52 
53  SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
54 
55  rSh.StartAllAction();
56 
57  // the aLogRect will get the preliminary size now
58  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  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  MapMode aObjectMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
69  MapMode aClientMap( GetEditWin()->GetMapMode().GetMapUnit() );
70 
71  Size aNewObjSize( tools::Long( aLogRect.GetWidth() / GetScaleWidth() ),
72  tools::Long( aLogRect.GetHeight() / GetScaleHeight() ) );
73 
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() ) );
77  }
78 
79  rSh.EndAllAction();
80 
81  SwRect aFrame( rSh.GetAnyCurRect( CurRectType::FlyEmbedded, nullptr, GetObject() )),
82  aPrt( rSh.GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, GetObject() ));
83  aLogRect.SetPos( aPrt.Pos() + aFrame.Pos() );
84  aLogRect.SetSize( aPrt.SSize() );
85 }
86 
88 {
89  SwWrtShell &rSh = static_cast<SwView*>(GetViewShell())->GetWrtShell();
90  SwRect aFrame( rSh.GetAnyCurRect( CurRectType::FlyEmbedded, nullptr, GetObject() ));
91  if ( !aFrame.IsOver( rSh.VisArea() ) )
92  rSh.MakeVisible( aFrame );
93 }
94 
96 {
97  if (m_IsInDoVerb)
98  return;
99 
100  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  return;
107  }
108 
109  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  awt::Size aSz;
118  try
119  {
120  aSz = GetObject()->getVisualAreaSize( GetAspect() );
121  }
122  catch (const embed::NoVisualAreaSizeException&)
123  {
124  // Nothing will be done
125  }
126  catch (const uno::Exception&)
127  {
128  OSL_FAIL( "Something goes wrong on requesting object size!" );
129  }
130 
131  Size aVisSize( aSz.Width, aSz.Height );
132 
133  // As long as from the object comes no reasonable size
134  // nothing can be scaled.
135  if( !aVisSize.Width() || !aVisSize.Height() )
136  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  const MapMode aMyMap ( MapUnit::MapTwip );
142  const MapMode aObjMap( VCLUnoHelper::UnoEmbed2VCLMapUnit( GetObject()->getMapUnit( GetAspect() ) ) );
143  aVisSize = OutputDevice::LogicToLogic( aVisSize, aObjMap, aMyMap );
144 
145  aVisSize.setWidth( tools::Long(aVisSize.Width() * GetScaleWidth()) );
146  aVisSize.setHeight( tools::Long(aVisSize.Height() * GetScaleHeight()) );
147 
148  SwRect aRect( Point( LONG_MIN, LONG_MIN ), aVisSize );
149  rSh.LockView( true ); // Prevent scrolling in the EndAction
150  rSh.StartAllAction();
151  rSh.RequestObjectResize( aRect, GetObject() );
152  rSh.EndAllAction();
153  rSh.LockView( false );
154 }
155 
157 {
158  const uno::Reference < embed::XEmbeddedObject >& xObj( GetObject() );
159  SwView * pView = dynamic_cast< SwView * >( GetViewShell() );
160  if ( pView && xObj.is() && SotExchange::IsMath( xObj->getClassID() ) )
161  {
162  SwWrtShell & rWrtSh = pView->GetWrtShell();
164  rWrtSh.AlignFormulaToBaseline( xObj );
165  }
166 }
167 
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Fraction & GetScaleWidth() const
void SetPos(const Point &rPoint)
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
Rect of current FlyFrame.
void setWidth(tools::Long nWidth)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const SwRect & GetAnyCurRect(CurRectType eType, const Point *pPt=nullptr, const css::uno::Reference< css::embed::XEmbeddedObject > &=css::uno::Reference< css::embed::XEmbeddedObject >()) const
Definition: fews.cxx:90
long Long
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void EndAllAction()
Definition: edws.cxx:97
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
Used by the UI to modify the document model.
Definition: wrtsh.hxx:91
constexpr tools::Long Width() const
constexpr tools::Long GetWidth() const
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
static sal_uInt16 IsMath(const SvGlobalName &rName)
tools::Rectangle GetScaledObjArea() const
void MakeVisible(const SwRect &)
Definition: viewsh.cxx:570
bool m_IsInDoVerb
Definition: swcli.hxx:32
void AlignFormulaToBaseline(const css::uno::Reference< css::embed::XEmbeddedObject > &xObj)
for starmath formulas anchored 'as char' it aligns it baseline to baseline changing the previous vert...
Definition: fefly1.cxx:2026
const SwRect & VisArea() const
Definition: viewsh.cxx:563
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
void SetSize(const Size &rSize)
virtual void ObjectAreaChanged() override
Definition: swcli.cxx:87
MapUnit GetMapUnit()
vcl::Window * GetEditWin() const
SfxViewShell * GetViewShell() const
constexpr Size GetSize() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
virtual void ViewChanged() override
Definition: swcli.cxx:95
constexpr tools::Long Height() const
void LockView(bool b)
Definition: viewsh.hxx:462
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:176
virtual void FormatChanged() override
Definition: swcli.cxx:156
sal_Int64 GetAspect() const
Size RequestObjectResize(const SwRect &rRect, const css::uno::Reference< css::embed::XEmbeddedObject > &)
OLE.
Definition: fefly1.cxx:1296
void SetObject(const css::uno::Reference< css::embed::XEmbeddedObject > &rObject)
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
void setHeight(tools::Long nHeight)
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
const Fraction & GetScaleHeight() const
Rect of PrtArea of FlyFrame.
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
virtual void RequestNewObjectArea(tools::Rectangle &) override
Definition: swcli.cxx:43
Definition: view.hxx:144
SwOleClient(SwView *pView, SwEditWin *pWin, const svt::EmbeddedObjectRef &)
Definition: swcli.cxx:35
constexpr tools::Long GetHeight() const