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
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
36using namespace com::sun::star;
37
38ScClient::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() == SdrObjKind::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)
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
206 {
207 pDrawObj->ActionChanged();
208 return;
209 }
210
211 tools::Rectangle aLogicRect = pDrawObj->GetLogicRect();
212 Fraction aFractX = GetScaleWidth() * aVisSize.Width();
213 Fraction aFractY = GetScaleHeight() * aVisSize.Height();
214 aVisSize = Size( static_cast<tools::Long>(aFractX), static_cast<tools::Long>(aFractY) ); // Scaled for Draw model
215
216 // pClientData->SetObjArea before pDrawObj->SetLogicRect, so that we don't
217 // calculate wrong scalings:
218 //Rectangle aObjArea = aLogicRect;
219 //aObjArea.SetSize( aVisSize ); // Document size from the server
220 //SetObjArea( aObjArea );
221
222 SfxViewShell* pSfxViewSh = GetViewShell();
223 ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( pSfxViewSh );
224 if ( pViewSh )
225 {
226 vcl::Window* pWin = pViewSh->GetActiveWin();
227 if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
228 {
229 aLogicRect.SetSize( aVisSize );
230 pDrawObj->SetLogicRect( aLogicRect );
231
232 // set document modified (SdrModel::SetChanged is not used)
234 }
235 }
236}
237
238/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Degree100 nShearAngle
Degree100 nRotationAngle
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
virtual void ObjectAreaChanged() override
Definition: client.cxx:137
ScClient(ScTabViewShell *pViewShell, vcl::Window *pDraw, SdrModel *pSdrModel, const SdrOle2Obj *pObj)
Definition: client.cxx:38
virtual void RequestNewObjectArea(tools::Rectangle &) override
Definition: client.cxx:75
SdrModel * pModel
Definition: client.hxx:31
SdrOle2Obj * GetDrawObj()
Definition: client.cxx:49
virtual void ViewChanged() override
Definition: client.cxx:175
virtual ~ScClient() override
Definition: client.cxx:45
void SetDrawModified()
SetDrawModified - without Formula update.
Definition: docsh.cxx:3023
void ScrollToObject(const SdrObject *pDrawObj)
Definition: tabview5.cxx:549
ScViewData & GetViewData()
Definition: tabview.hxx:341
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:878
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
SdrObject * Next()
bool IsResizeProtect() const
void ActionChanged() const
bool IsMoveProtect() const
virtual const tools::Rectangle & GetCurrentBoundRect() const
virtual void SetLogicRect(const tools::Rectangle &rRect)
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
void setSuppressSetVisAreaSize(bool bNew)
Size GetSize() const
virtual const tools::Rectangle & GetLogicRect() const override
const GeoStat & GetGeoStat() const
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
const Fraction & GetScaleHeight() const
void SetObject(const css::uno::Reference< css::embed::XEmbeddedObject > &rObject)
const tools::Rectangle & GetObjArea() const
tools::Rectangle GetScaledObjArea() const
bool IsObjectInPlaceActive() const
const Fraction & GetScaleWidth() const
SfxViewShell * GetViewShell() const
sal_Int64 GetAspect() const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
virtual SfxObjectShell * GetObjectShell() override
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
constexpr tools::Long Width() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
OUString GetEmbeddedObjectName(const css::uno::Reference< css::embed::XEmbeddedObject > &) const
constexpr Point Center() const
constexpr tools::Long Top() const
void SetSize(const Size &)
constexpr Point TopLeft() const
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Right() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
Point LogicToPixel(const Point &rLogicPt) const
#define TOOLS_WARN_EXCEPTION(area, stream)
EmbeddedObjectRef * pObject
OUString aName
MapUnit
long Long