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