1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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 <ViewShell.hxx>
27 #include <DrawViewShell.hxx>
30 #include <vcl/svapp.hxx>
32 using namespace com::sun::star
;
36 Client::Client(SdrOle2Obj
* pObj
, ViewShell
* pViewShell
, vcl::Window
* pWindow
) :
37 SfxInPlaceClient(pViewShell
->GetViewShell(), pWindow
, pObj
->GetAspect() ),
38 mpViewShell(pViewShell
),
41 SetObject( pObj
->GetObjRef() );
42 DBG_ASSERT( GetObject().is(), "No object connected!" );
50 * If IP active, then we get this request to increase the visible section of the
53 void Client::RequestNewObjectArea( ::tools::Rectangle
& aObjRect
)
55 ::sd::View
* pView
= mpViewShell
->GetView();
57 bool bSizeProtect
= false;
58 bool bPosProtect
= false;
60 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
61 if (rMarkList
.GetMarkCount() == 1)
63 SdrMark
* pMark
= rMarkList
.GetMark(0);
64 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
66 // no need to check for changes, this method is called only if the area really changed
67 bSizeProtect
= pObj
->IsResizeProtect();
68 bPosProtect
= pObj
->IsMoveProtect();
71 ::tools::Rectangle aOldRect
= GetObjArea();
73 aObjRect
.SetPos( aOldRect
.TopLeft() );
76 aObjRect
.SetSize( aOldRect
.GetSize() );
78 ::tools::Rectangle
aWorkArea( pView
->GetWorkArea() );
79 if ( !aWorkArea
.IsInside(aObjRect
) && !bPosProtect
&& aObjRect
!= aOldRect
)
82 Point aPos
= aObjRect
.TopLeft();
83 Size aSize
= aObjRect
.GetSize();
84 Point aWorkAreaTL
= aWorkArea
.TopLeft();
85 Point aWorkAreaBR
= aWorkArea
.BottomRight();
87 aPos
.setX( std::max(aPos
.X(), aWorkAreaTL
.X()) );
88 aPos
.setX( std::min(aPos
.X(), aWorkAreaBR
.X()-aSize
.Width()) );
89 aPos
.setY( std::max(aPos
.Y(), aWorkAreaTL
.Y()) );
90 aPos
.setY( std::min(aPos
.Y(), aWorkAreaBR
.Y()-aSize
.Height()) );
92 aObjRect
.SetPos(aPos
);
96 void Client::ObjectAreaChanged()
98 ::sd::View
* pView
= mpViewShell
->GetView();
99 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
100 if (rMarkList
.GetMarkCount() == 1)
102 SdrMark
* pMark
= rMarkList
.GetMark(0);
103 SdrOle2Obj
* pObj
= dynamic_cast< SdrOle2Obj
* >(pMark
->GetMarkedSdrObj());
107 // no need to check for changes, this method is called only if the area really changed
108 ::tools::Rectangle
aNewRectangle(GetScaledObjArea());
110 // #i118524# if sheared/rotated, center to non-rotated LogicRect
111 pObj
->setSuppressSetVisAreaSize(true);
113 if(pObj
->GetGeoStat().nRotationAngle
|| pObj
->GetGeoStat().nShearAngle
)
115 pObj
->SetLogicRect( aNewRectangle
);
117 const ::tools::Rectangle
& rBoundRect
= pObj
->GetCurrentBoundRect();
118 const Point
aDelta(aNewRectangle
.Center() - rBoundRect
.Center());
120 aNewRectangle
.Move(aDelta
.X(), aDelta
.Y());
123 pObj
->SetLogicRect( aNewRectangle
);
124 pObj
->setSuppressSetVisAreaSize(false);
129 void Client::ViewChanged()
131 if ( GetAspect() == embed::Aspects::MSOLE_ICON
)
133 // the iconified object seems not to need such a scaling handling
134 // since the replacement image and the size a completely controlled by the container
135 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
137 pSdrOle2Obj
->ActionChanged(); // draw needs it to remove lines in slide preview
141 //TODO/LATER: should we try to avoid the recalculation of the visareasize
142 //if we know that it didn't change?
143 if (mpViewShell
->GetActiveWindow())
145 ::sd::View
* pView
= mpViewShell
->GetView();
148 ::tools::Rectangle
aLogicRect( pSdrOle2Obj
->GetLogicRect() );
149 Size
aLogicSize( aLogicRect
.GetWidth(), aLogicRect
.GetHeight() );
151 if( pSdrOle2Obj
->IsChart() )
153 //charts never should be stretched see #i84323# for example
154 pSdrOle2Obj
->SetLogicRect( ::tools::Rectangle( aLogicRect
.TopLeft(), aLogicSize
) );
155 pSdrOle2Obj
->BroadcastObjectChange();
159 // TODO/LEAN: maybe we can do this without requesting the VisualArea?
160 // working with the visual area might need running state, so the object may switch itself to this state
161 MapMode
aMap100( MapUnit::Map100thMM
);
162 ::tools::Rectangle aVisArea
;
163 Size aSize
= pSdrOle2Obj
->GetOrigObjSize( &aMap100
);
165 aVisArea
.SetSize( aSize
);
166 Size
aScaledSize( static_cast< long >( GetScaleWidth() * Fraction( aVisArea
.GetWidth() ) ),
167 static_cast< long >( GetScaleHeight() * Fraction( aVisArea
.GetHeight() ) ) );
169 // react to the change if the difference is bigger than one pixel
171 Application::GetDefaultDevice()->LogicToPixel(
172 Size( aLogicRect
.GetWidth() - aScaledSize
.Width(),
173 aLogicRect
.GetHeight() - aScaledSize
.Height() ),
175 if( aPixelDiff
.Width() || aPixelDiff
.Height() )
177 pSdrOle2Obj
->SetLogicRect( ::tools::Rectangle( aLogicRect
.TopLeft(), aScaledSize
) );
178 pSdrOle2Obj
->BroadcastObjectChange();
181 pSdrOle2Obj
->ActionChanged();
186 } // end of namespace sd
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */