LibreOffice Module sc (master)  1
client.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/XEmbeddedObject.hpp>
21 
23 #include <tools/diagnose_ex.h>
24 #include <sfx2/objsh.hxx>
25 #include <svx/svditer.hxx>
26 #include <svx/svdobj.hxx>
27 #include <svx/svdmodel.hxx>
28 #include <svx/svdpage.hxx>
29 #include <svx/svdoole2.hxx>
30 
31 #include <client.hxx>
32 #include <tabvwsh.hxx>
33 #include <docsh.hxx>
34 #include <gridwin.hxx>
35 
36 using namespace com::sun::star;
37 
38 ScClient::ScClient( ScTabViewShell* pViewShell, vcl::Window* pDraw, SdrModel* pSdrModel, const SdrOle2Obj* pObj ) :
39  SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
40  pModel( pSdrModel )
41 {
42  SetObject( pObj->GetObjRef() );
43 }
44 
46 {
47 }
48 
50 {
51  uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
52  SdrOle2Obj* pOle2Obj = nullptr;
54 
55  sal_uInt16 nPages = pModel->GetPageCount();
56  for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
57  {
58  SdrPage* pPage = pModel->GetPage(nPNr);
59  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
60  SdrObject* pObject = aIter.Next();
61  while (pObject && !pOle2Obj)
62  {
63  if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
64  {
65  // name from InfoObject is PersistName
66  if ( static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == aName )
67  pOle2Obj = static_cast<SdrOle2Obj*>(pObject);
68  }
69  pObject = aIter.Next();
70  }
71  }
72  return pOle2Obj;
73 }
74 
76 {
77  SfxViewShell* pSfxViewSh = GetViewShell();
78  ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
79  if (!pViewSh)
80  {
81  OSL_FAIL("Wrong ViewShell");
82  return;
83  }
84 
85  tools::Rectangle aOldRect = GetObjArea();
86  SdrOle2Obj* pDrawObj = GetDrawObj();
87  if ( pDrawObj )
88  {
89  if ( pDrawObj->IsResizeProtect() )
90  aLogicRect.SetSize( aOldRect.GetSize() );
91 
92  if ( pDrawObj->IsMoveProtect() )
93  aLogicRect.SetPos( aOldRect.TopLeft() );
94  }
95 
96  sal_uInt16 nTab = pViewSh->GetViewData().GetTabNo();
97  SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
98  if ( !(pPage && aLogicRect != aOldRect) )
99  return;
100 
101  Point aPos;
102  Size aSize = pPage->GetSize();
103  if ( aSize.Width() < 0 )
104  {
105  aPos.setX( aSize.Width() + 1 ); // negative
106  aSize.setWidth( -aSize.Width() ); // positive
107  }
108  tools::Rectangle aPageRect( aPos, aSize );
109 
110  if (aLogicRect.Right() > aPageRect.Right())
111  {
112  tools::Long nDiff = aLogicRect.Right() - aPageRect.Right();
113  aLogicRect.AdjustLeft( -nDiff );
114  aLogicRect.AdjustRight( -nDiff );
115  }
116  if (aLogicRect.Bottom() > aPageRect.Bottom())
117  {
118  tools::Long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
119  aLogicRect.AdjustTop( -nDiff );
120  aLogicRect.AdjustBottom( -nDiff );
121  }
122 
123  if (aLogicRect.Left() < aPageRect.Left())
124  {
125  tools::Long nDiff = aLogicRect.Left() - aPageRect.Left();
126  aLogicRect.AdjustRight( -nDiff );
127  aLogicRect.AdjustLeft( -nDiff );
128  }
129  if (aLogicRect.Top() < aPageRect.Top())
130  {
131  tools::Long nDiff = aLogicRect.Top() - aPageRect.Top();
132  aLogicRect.AdjustBottom( -nDiff );
133  aLogicRect.AdjustTop( -nDiff );
134  }
135 }
136 
138 {
139  SfxViewShell* pSfxViewSh = GetViewShell();
140  ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
141  if (!pViewSh)
142  {
143  OSL_FAIL("Wrong ViewShell");
144  return;
145  }
146 
147  // Take over position and size into document
148  SdrOle2Obj* pDrawObj = GetDrawObj();
149  if (!pDrawObj)
150  return;
151 
152  tools::Rectangle aNewRectangle(GetScaledObjArea());
153 
154  // #i118524# if sheared/rotated, center to non-rotated LogicRect
155  pDrawObj->setSuppressSetVisAreaSize(true);
156 
157  if(pDrawObj->GetGeoStat().nRotationAngle || pDrawObj->GetGeoStat().nShearAngle)
158  {
159  pDrawObj->SetLogicRect( aNewRectangle );
160 
161  const tools::Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
162  const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
163 
164  aNewRectangle.Move(aDelta.X(), aDelta.Y());
165  }
166 
167  pDrawObj->SetLogicRect( aNewRectangle );
168  pDrawObj->setSuppressSetVisAreaSize(false);
169 
170  // set document modified (SdrModel::SetChanged is not used)
171  pViewSh->GetViewData().GetDocShell()->SetDrawModified();
172  pViewSh->ScrollToObject(pDrawObj);
173 }
174 
176 {
177  if ( GetAspect() == embed::Aspects::MSOLE_ICON )
178  {
179  // the iconified object seems not to need such a scaling handling
180  // since the replacement image and the size a completely controlled by the container
181  // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
182 
183  return;
184  }
185 
186  uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
187 
188  // TODO/LEAN: working with Visual Area can switch object to running state
189  awt::Size aSz;
190  try {
191  aSz = xObj->getVisualAreaSize( GetAspect() );
192  } catch (const uno::Exception&) {
193  TOOLS_WARN_EXCEPTION("sc", "The visual area size must be available!");
194  return; // leave it unchanged on failure
195  }
196 
197  MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
198  Size aVisSize = OutputDevice::LogicToLogic(Size(aSz.Width, aSz.Height), MapMode(aMapUnit), MapMode(MapUnit::Map100thMM));
199 
200  // Take over position and size into document
201  SdrOle2Obj* pDrawObj = GetDrawObj();
202  if (!pDrawObj)
203  return;
204 
205  tools::Rectangle aLogicRect = pDrawObj->GetLogicRect();
206  Fraction aFractX = GetScaleWidth() * aVisSize.Width();
207  Fraction aFractY = GetScaleHeight() * aVisSize.Height();
208  aVisSize = Size( static_cast<tools::Long>(aFractX), static_cast<tools::Long>(aFractY) ); // Scaled for Draw model
209 
210  // pClientData->SetObjArea before pDrawObj->SetLogicRect, so that we don't
211  // calculate wrong scalings:
212  //Rectangle aObjArea = aLogicRect;
213  //aObjArea.SetSize( aVisSize ); // Document size from the server
214  //SetObjArea( aObjArea );
215 
216  SfxViewShell* pSfxViewSh = GetViewShell();
217  ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
218  if ( pViewSh )
219  {
220  vcl::Window* pWin = pViewSh->GetActiveWin();
221  if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
222  {
223  aLogicRect.SetSize( aVisSize );
224  pDrawObj->SetLogicRect( aLogicRect );
225 
226  // set document modified (SdrModel::SetChanged is not used)
227  pViewSh->GetViewData().GetDocShell()->SetDrawModified();
228  }
229  }
230 }
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Fraction & GetScaleWidth() const
void SetPos(const Point &rPoint)
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
virtual const tools::Rectangle & GetCurrentBoundRect() const
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
void setWidth(tools::Long nWidth)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Left() const
long Long
virtual void RequestNewObjectArea(tools::Rectangle &) override
Definition: client.cxx:75
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
virtual SdrObjKind GetObjIdentifier() const
EmbeddedObjectRef * pObject
constexpr tools::Long Width() const
virtual ~ScClient() override
Definition: client.cxx:45
virtual void ObjectAreaChanged() override
Definition: client.cxx:137
const GeoStat & GetGeoStat() const
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Rectangle GetScaledObjArea() const
ScViewData & GetViewData()
Definition: tabview.hxx:333
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:886
void ScrollToObject(const SdrObject *pDrawObj)
Definition: tabview5.cxx:551
#define TOOLS_WARN_EXCEPTION(area, stream)
Point LogicToPixel(const Point &rLogicPt) const
Size GetSize() const
void SetSize(const Size &rSize)
const SdrPage * GetPage(sal_uInt16 nPgNum) const
constexpr tools::Long Right() const
ScClient(ScTabViewShell *pViewShell, vcl::Window *pDraw, SdrModel *pSdrModel, const SdrOle2Obj *pObj)
Definition: client.cxx:38
constexpr tools::Long Top() const
virtual void SetLogicRect(const tools::Rectangle &rRect)
bool IsResizeProtect() const
constexpr Point Center() const
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
constexpr tools::Long Bottom() const
SdrOle2Obj * GetDrawObj()
Definition: client.cxx:49
OUString GetEmbeddedObjectName(const css::uno::Reference< css::embed::XEmbeddedObject > &) const
SdrObject * Next()
SfxViewShell * GetViewShell() const
constexpr Size GetSize() const
virtual void ViewChanged() override
Definition: client.cxx:175
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
Degree100 nRotationAngle
OUString aName
const tools::Rectangle & GetObjArea() const
sal_Int64 GetAspect() const
void setSuppressSetVisAreaSize(bool bNew)
void SetObject(const css::uno::Reference< css::embed::XEmbeddedObject > &rObject)
virtual SfxObjectShell * GetObjectShell() override
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
MapUnit
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
SdrModel * pModel
Definition: client.hxx:31
void SetDrawModified()
SetDrawModified - without Formula update.
Definition: docsh.cxx:3005
const Fraction & GetScaleHeight() const
OBJ_OLE2
Degree100 nShearAngle
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
sal_uInt16 GetPageCount() const
bool IsMoveProtect() const
virtual const tools::Rectangle & GetLogicRect() const override