LibreOffice Module sd (master) 1
sdclient.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 <Client.hxx>
21#include <svx/svdoole2.hxx>
22#include <tools/debug.hxx>
23
24#include <ViewShell.hxx>
25#include <View.hxx>
26#include <vcl/svapp.hxx>
27
28using namespace com::sun::star;
29
30namespace sd {
31
32Client::Client(SdrOle2Obj* pObj, ViewShell* pViewShell, vcl::Window* pWindow) :
33 SfxInPlaceClient(pViewShell->GetViewShell(), pWindow, pObj->GetAspect() ),
34 mpViewShell(pViewShell),
35 pSdrOle2Obj(pObj)
36{
37 SetObject( pObj->GetObjRef() );
38 DBG_ASSERT( GetObject().is(), "No object connected!" );
39}
40
42{
43}
44
50{
51 ::sd::View* pView = mpViewShell->GetView();
52
53 bool bSizeProtect = false;
54 bool bPosProtect = false;
55
56 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
57 if (rMarkList.GetMarkCount() == 1)
58 {
59 SdrMark* pMark = rMarkList.GetMark(0);
60 SdrObject* pObj = pMark->GetMarkedSdrObj();
61
62 // no need to check for changes, this method is called only if the area really changed
63 bSizeProtect = pObj->IsResizeProtect();
64 bPosProtect = pObj->IsMoveProtect();
65 }
66
67 ::tools::Rectangle aOldRect = GetObjArea();
68 if ( bPosProtect )
69 aObjRect.SetPos( aOldRect.TopLeft() );
70
71 if ( bSizeProtect )
72 aObjRect.SetSize( aOldRect.GetSize() );
73
74 ::tools::Rectangle aWorkArea( pView->GetWorkArea() );
75 if ( aWorkArea.Contains(aObjRect) || bPosProtect || aObjRect == aOldRect )
76 return;
77
78 // correct position
79 Point aPos = aObjRect.TopLeft();
80 Size aSize = aObjRect.GetSize();
81 Point aWorkAreaTL = aWorkArea.TopLeft();
82 Point aWorkAreaBR = aWorkArea.BottomRight();
83
84 aPos.setX( std::max(aPos.X(), aWorkAreaTL.X()) );
85 aPos.setX( std::min(aPos.X(), aWorkAreaBR.X()-aSize.Width()) );
86 aPos.setY( std::max(aPos.Y(), aWorkAreaTL.Y()) );
87 aPos.setY( std::min(aPos.Y(), aWorkAreaBR.Y()-aSize.Height()) );
88
89 aObjRect.SetPos(aPos);
90}
91
93{
94 ::sd::View* pView = mpViewShell->GetView();
95 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
96 if (rMarkList.GetMarkCount() != 1)
97 return;
98
99 SdrMark* pMark = rMarkList.GetMark(0);
100 SdrOle2Obj* pObj = dynamic_cast< SdrOle2Obj* >(pMark->GetMarkedSdrObj());
101
102 if(!pObj)
103 return;
104
105 // no need to check for changes, this method is called only if the area really changed
106 ::tools::Rectangle aNewRectangle(GetScaledObjArea());
107
108 // #i118524# if sheared/rotated, center to non-rotated LogicRect
109 pObj->setSuppressSetVisAreaSize(true);
110
112 {
113 pObj->SetLogicRect( aNewRectangle );
114
115 const ::tools::Rectangle& rBoundRect = pObj->GetCurrentBoundRect();
116 const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
117
118 aNewRectangle.Move(aDelta.X(), aDelta.Y());
119 }
120
121 pObj->SetLogicRect( aNewRectangle );
122 pObj->setSuppressSetVisAreaSize(false);
123}
124
126{
127 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
128 {
129 // the iconified object seems not to need such a scaling handling
130 // since the replacement image and the size a completely controlled by the container
131 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
132
133 pSdrOle2Obj->ActionChanged(); // draw needs it to remove lines in slide preview
134 return;
135 }
136
137 //TODO/LATER: should we try to avoid the recalculation of the visareasize
138 //if we know that it didn't change?
140 return;
141
142 ::sd::View* pView = mpViewShell->GetView();
143 if (!pView)
144 return;
145
146 // Do not recalculate the visareasize if the embedded object is opening in a new window.
148 {
150 return;
151 }
152
154 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
155
156 if( pSdrOle2Obj->IsChart() )
157 {
158 //charts never should be stretched see #i84323# for example
159 pSdrOle2Obj->SetLogicRect( ::tools::Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
161 return;
162 }
163
164 // TODO/LEAN: maybe we can do this without requesting the VisualArea?
165 // working with the visual area might need running state, so the object may switch itself to this state
166 MapMode aMap100( MapUnit::Map100thMM );
167 ::tools::Rectangle aVisArea;
168 Size aSize = pSdrOle2Obj->GetOrigObjSize( &aMap100 );
169
170 aVisArea.SetSize( aSize );
171 Size aScaledSize( static_cast< ::tools::Long >( GetScaleWidth() * Fraction( aVisArea.GetWidth() ) ),
172 static_cast< ::tools::Long >( GetScaleHeight() * Fraction( aVisArea.GetHeight() ) ) );
173
174 // react to the change if the difference is bigger than one pixel
175 Size aPixelDiff =
177 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
178 aLogicRect.GetHeight() - aScaledSize.Height() ),
179 aMap100 );
180 if( aPixelDiff.Width() || aPixelDiff.Height() )
181 {
182 pSdrOle2Obj->SetLogicRect( ::tools::Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
184 }
185 else
187}
188
189} // end of namespace sd
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
Degree100 m_nShearAngle
Degree100 m_nRotationAngle
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
const tools::Rectangle & GetWorkArea() const
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
bool IsResizeProtect() const
void ActionChanged() const
void BroadcastObjectChange() 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 GetOrigObjSize(MapMode const *pTargetMapMode=nullptr) const
bool IsChart() 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
sal_Int64 GetAspect() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
Client(SdrOle2Obj *pObj, ViewShell *pSdViewShell, vcl::Window *pWindow)
Definition: sdclient.cxx:32
virtual void ViewChanged() override
Definition: sdclient.cxx:125
virtual void ObjectAreaChanged() override
Definition: sdclient.cxx:92
ViewShell * mpViewShell
Definition: Client.hxx:31
virtual ~Client() override
Definition: sdclient.cxx:41
virtual void RequestNewObjectArea(::tools::Rectangle &) override
If IP active, then we get this request to increase the visible section of the object.
Definition: sdclient.cxx:49
SdrOle2Obj * pSdrOle2Obj
Definition: Client.hxx:32
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
::sd::View * GetView() const
Definition: ViewShell.hxx:144
constexpr Point Center() const
constexpr tools::Long GetWidth() const
bool Contains(const Point &rPOINT) 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 Point BottomRight() const
constexpr tools::Long GetHeight() const
#define DBG_ASSERT(sCon, aError)
long Long