bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / docshell / sdclient.cxx
blobfc6887d9e87851272f3ea6f68e25b5020f52aad8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "Client.hxx"
21 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
22 #include <svx/svdoole2.hxx>
23 #include <svx/svdograf.hxx>
24 #include <svx/svdpagv.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
28 #include "strings.hrc"
29 #include "ViewShell.hxx"
30 #include "DrawViewShell.hxx"
31 #include "View.hxx"
32 #include "Window.hxx"
33 #include "sdresid.hxx"
34 #include <vcl/svapp.hxx>
36 using namespace com::sun::star;
38 namespace sd {
40 Client::Client(SdrOle2Obj* pObj, ViewShell* pViewShell, vcl::Window* pWindow) :
41 SfxInPlaceClient(pViewShell->GetViewShell(), pWindow, pObj->GetAspect() ),
42 mpViewShell(pViewShell),
43 pSdrOle2Obj(pObj),
44 pSdrGrafObj(NULL),
45 pOutlinerParaObj (NULL)
47 SetObject( pObj->GetObjRef() );
48 DBG_ASSERT( GetObject().is(), "No object connected!" );
51 Client::~Client()
55 /**
56 * If IP active, then we get this request to increase the visible section of the
57 * object.
59 void Client::RequestNewObjectArea( Rectangle& aObjRect )
61 ::sd::View* pView = mpViewShell->GetView();
63 bool bSizeProtect = false;
64 bool bPosProtect = false;
66 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
67 if (rMarkList.GetMarkCount() == 1)
69 SdrMark* pMark = rMarkList.GetMark(0);
70 SdrObject* pObj = pMark->GetMarkedSdrObj();
72 // no need to check for changes, this method is called only if the area really changed
73 bSizeProtect = pObj->IsResizeProtect();
74 bPosProtect = pObj->IsMoveProtect();
77 Rectangle aOldRect = GetObjArea();
78 if ( bPosProtect )
79 aObjRect.SetPos( aOldRect.TopLeft() );
81 if ( bSizeProtect )
82 aObjRect.SetSize( aOldRect.GetSize() );
84 Rectangle aWorkArea( pView->GetWorkArea() );
85 if ( !aWorkArea.IsInside(aObjRect) && !bPosProtect && aObjRect != aOldRect )
87 // correct position
88 Point aPos = aObjRect.TopLeft();
89 Size aSize = aObjRect.GetSize();
90 Point aWorkAreaTL = aWorkArea.TopLeft();
91 Point aWorkAreaBR = aWorkArea.BottomRight();
93 aPos.X() = std::max(aPos.X(), aWorkAreaTL.X());
94 aPos.X() = std::min(aPos.X(), aWorkAreaBR.X()-aSize.Width());
95 aPos.Y() = std::max(aPos.Y(), aWorkAreaTL.Y());
96 aPos.Y() = std::min(aPos.Y(), aWorkAreaBR.Y()-aSize.Height());
98 aObjRect.SetPos(aPos);
102 void Client::ObjectAreaChanged()
104 ::sd::View* pView = mpViewShell->GetView();
105 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
106 if (rMarkList.GetMarkCount() == 1)
108 SdrMark* pMark = rMarkList.GetMark(0);
109 SdrOle2Obj* pObj = dynamic_cast< SdrOle2Obj* >(pMark->GetMarkedSdrObj());
111 if(pObj)
113 // no need to check for changes, this method is called only if the area really changed
114 Rectangle aNewRectangle(GetScaledObjArea());
116 // #i118524# if sheared/rotated, center to non-rotated LogicRect
117 pObj->setSuppressSetVisAreaSize(true);
119 if(pObj->GetGeoStat().nRotationAngle || pObj->GetGeoStat().nShearAngle)
121 pObj->SetLogicRect( aNewRectangle );
123 const Rectangle& rBoundRect = pObj->GetCurrentBoundRect();
124 const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
126 aNewRectangle.Move(aDelta.X(), aDelta.Y());
129 pObj->SetLogicRect( aNewRectangle );
130 pObj->setSuppressSetVisAreaSize(false);
135 void Client::ViewChanged()
137 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
139 // the iconified object seems not to need such a scaling handling
140 // since the replacement image and the size a completely controlled by the container
141 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
143 pSdrOle2Obj->ActionChanged(); // draw needs it to remove lines in slide preview
144 return;
147 //TODO/LATER: should we try to avoid the recalculation of the visareasize
148 //if we know that it didn't change?
149 if (mpViewShell->GetActiveWindow())
151 ::sd::View* pView = mpViewShell->GetView();
152 if (pView)
154 Rectangle aLogicRect( pSdrOle2Obj->GetLogicRect() );
155 Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
157 if( pSdrOle2Obj->IsChart() )
159 //charts never should be stretched see #i84323# for example
160 pSdrOle2Obj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
161 pSdrOle2Obj->BroadcastObjectChange();
162 return;
165 // TODO/LEAN: maybe we can do this without requesting the VisualArea?
166 // working with the visual area might need running state, so the object may switch itself to this state
167 MapMode aMap100( MAP_100TH_MM );
168 Rectangle aVisArea;
169 Size aSize = pSdrOle2Obj->GetOrigObjSize( &aMap100 );
171 aVisArea.SetSize( aSize );
172 Size aScaledSize( static_cast< long >( GetScaleWidth() * Fraction( aVisArea.GetWidth() ) ),
173 static_cast< long >( GetScaleHeight() * Fraction( aVisArea.GetHeight() ) ) );
175 // react to the change if the difference is bigger than one pixel
176 Size aPixelDiff =
177 Application::GetDefaultDevice()->LogicToPixel(
178 Size( aLogicRect.GetWidth() - aScaledSize.Width(),
179 aLogicRect.GetHeight() - aScaledSize.Height() ),
180 aMap100 );
181 if( aPixelDiff.Width() || aPixelDiff.Height() )
183 pSdrOle2Obj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
184 pSdrOle2Obj->BroadcastObjectChange();
186 else
187 pSdrOle2Obj->ActionChanged();
193 * Scroll object into visible area.
195 void Client::MakeVisible()
197 if (mpViewShell->ISA(DrawViewShell))
199 static_cast<DrawViewShell*>(mpViewShell)->MakeVisible(
200 pSdrOle2Obj->GetLogicRect(),
201 *mpViewShell->GetActiveWindow());
205 } // end of namespace sd
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */