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 <svx/svdoole2.hxx>
22 #include <tools/debug.hxx>
24 #include <ViewShell.hxx>
26 #include <vcl/svapp.hxx>
28 using namespace com::sun::star
;
32 Client::Client(SdrOle2Obj
* pObj
, ViewShell
* pViewShell
, vcl::Window
* pWindow
) :
33 SfxInPlaceClient(pViewShell
->GetViewShell(), pWindow
, pObj
->GetAspect() ),
34 mpViewShell(pViewShell
),
37 SetObject( pObj
->GetObjRef() );
38 DBG_ASSERT( GetObject().is(), "No object connected!" );
46 * If IP active, then we get this request to increase the visible section of the
49 void Client::RequestNewObjectArea( ::tools::Rectangle
& aObjRect
)
51 ::sd::View
* pView
= mpViewShell
->GetView();
53 bool bSizeProtect
= false;
54 bool bPosProtect
= false;
56 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
57 if (rMarkList
.GetMarkCount() == 1)
59 SdrMark
* pMark
= rMarkList
.GetMark(0);
60 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
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();
67 ::tools::Rectangle aOldRect
= GetObjArea();
69 aObjRect
.SetPos( aOldRect
.TopLeft() );
72 aObjRect
.SetSize( aOldRect
.GetSize() );
74 ::tools::Rectangle
aWorkArea( pView
->GetWorkArea() );
75 if ( aWorkArea
.Contains(aObjRect
) || bPosProtect
|| aObjRect
== aOldRect
)
79 Point aPos
= aObjRect
.TopLeft();
80 Size aSize
= aObjRect
.GetSize();
81 Point aWorkAreaTL
= aWorkArea
.TopLeft();
82 Point aWorkAreaBR
= aWorkArea
.BottomRight();
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()) );
89 aObjRect
.SetPos(aPos
);
92 void Client::ObjectAreaChanged()
94 ::sd::View
* pView
= mpViewShell
->GetView();
95 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
96 if (rMarkList
.GetMarkCount() != 1)
99 SdrMark
* pMark
= rMarkList
.GetMark(0);
100 SdrOle2Obj
* pObj
= dynamic_cast< SdrOle2Obj
* >(pMark
->GetMarkedSdrObj());
105 // no need to check for changes, this method is called only if the area really changed
106 ::tools::Rectangle
aNewRectangle(GetScaledObjArea());
108 // #i118524# if sheared/rotated, center to non-rotated LogicRect
109 pObj
->setSuppressSetVisAreaSize(true);
111 if(pObj
->GetGeoStat().m_nRotationAngle
|| pObj
->GetGeoStat().m_nShearAngle
)
113 pObj
->SetLogicRect( aNewRectangle
);
115 const ::tools::Rectangle
& rBoundRect
= pObj
->GetCurrentBoundRect();
116 const Point
aDelta(aNewRectangle
.Center() - rBoundRect
.Center());
118 aNewRectangle
.Move(aDelta
.X(), aDelta
.Y());
121 pObj
->SetLogicRect( aNewRectangle
);
122 pObj
->setSuppressSetVisAreaSize(false);
125 void Client::ViewChanged()
127 if ( GetAspect() == embed::Aspects::MSOLE_ICON
)
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
133 pSdrOle2Obj
->ActionChanged(); // draw needs it to remove lines in slide preview
137 //TODO/LATER: should we try to avoid the recalculation of the visareasize
138 //if we know that it didn't change?
139 if (!mpViewShell
->GetActiveWindow())
142 ::sd::View
* pView
= mpViewShell
->GetView();
146 // Do not recalculate the visareasize if the embedded object is opening in a new window.
147 if (!IsObjectInPlaceActive())
149 pSdrOle2Obj
->BroadcastObjectChange();
153 ::tools::Rectangle
aLogicRect( pSdrOle2Obj
->GetLogicRect() );
154 Size
aLogicSize( aLogicRect
.GetWidth(), aLogicRect
.GetHeight() );
156 if( pSdrOle2Obj
->IsChart() )
158 //charts never should be stretched see #i84323# for example
159 pSdrOle2Obj
->SetLogicRect( ::tools::Rectangle( aLogicRect
.TopLeft(), aLogicSize
) );
160 pSdrOle2Obj
->BroadcastObjectChange();
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
);
170 aVisArea
.SetSize( aSize
);
171 Size
aScaledSize( static_cast< ::tools::Long
>( GetScaleWidth() * Fraction( aVisArea
.GetWidth() ) ),
172 static_cast< ::tools::Long
>( GetScaleHeight() * Fraction( aVisArea
.GetHeight() ) ) );
174 // react to the change if the difference is bigger than one pixel
176 Application::GetDefaultDevice()->LogicToPixel(
177 Size( aLogicRect
.GetWidth() - aScaledSize
.Width(),
178 aLogicRect
.GetHeight() - aScaledSize
.Height() ),
180 if( aPixelDiff
.Width() || aPixelDiff
.Height() )
182 pSdrOle2Obj
->SetLogicRect( ::tools::Rectangle( aLogicRect
.TopLeft(), aScaledSize
) );
183 pSdrOle2Obj
->BroadcastObjectChange();
186 pSdrOle2Obj
->ActionChanged();
189 } // end of namespace sd
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */