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 .
20 #include <com/sun/star/embed/XEmbeddedObject.hpp>
21 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <svx/svditer.hxx>
27 #include <svx/svdobj.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/svdview.hxx>
32 #include <svx/svdograf.hxx>
33 #include <svtools/embedhlp.hxx>
36 #include "tabvwsh.hxx"
39 using namespace com::sun::star
;
41 //------------------------------------------------------------------------
43 ScClient::ScClient( ScTabViewShell
* pViewShell
, Window
* pDraw
, SdrModel
* pSdrModel
, SdrOle2Obj
* pObj
) :
44 SfxInPlaceClient( pViewShell
, pDraw
, pObj
->GetAspect() ),
48 SetObject( pObj
->GetObjRef() );
55 SdrOle2Obj
* ScClient::GetDrawObj()
57 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObject();
58 SdrOle2Obj
* pOle2Obj
= NULL
;
59 OUString aName
= GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj
);
61 sal_uInt16 nPages
= pModel
->GetPageCount();
62 for (sal_uInt16 nPNr
=0; nPNr
<nPages
&& !pOle2Obj
; nPNr
++)
64 SdrPage
* pPage
= pModel
->GetPage(nPNr
);
65 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
66 SdrObject
* pObject
= aIter
.Next();
67 while (pObject
&& !pOle2Obj
)
69 if ( pObject
->GetObjIdentifier() == OBJ_OLE2
)
71 // name from InfoObject is PersistName
72 if ( ((SdrOle2Obj
*)pObject
)->GetPersistName() == aName
)
73 pOle2Obj
= (SdrOle2Obj
*)pObject
;
75 pObject
= aIter
.Next();
81 void ScClient::RequestNewObjectArea( Rectangle
& aLogicRect
)
83 SfxViewShell
* pSfxViewSh
= GetViewShell();
84 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
87 OSL_FAIL("Wrong ViewShell");
91 Rectangle aOldRect
= GetObjArea();
92 SdrOle2Obj
* pDrawObj
= GetDrawObj();
95 if ( pDrawObj
->IsResizeProtect() )
96 aLogicRect
.SetSize( aOldRect
.GetSize() );
98 if ( pDrawObj
->IsMoveProtect() )
99 aLogicRect
.SetPos( aOldRect
.TopLeft() );
102 sal_uInt16 nTab
= pViewSh
->GetViewData()->GetTabNo();
103 SdrPage
* pPage
= pModel
->GetPage(static_cast<sal_uInt16
>(static_cast<sal_Int16
>(nTab
)));
104 if ( pPage
&& aLogicRect
!= aOldRect
)
107 Size aSize
= pPage
->GetSize();
108 if ( aSize
.Width() < 0 )
110 aPos
.X() = aSize
.Width() + 1; // negative
111 aSize
.Width() = -aSize
.Width(); // positive
113 Rectangle
aPageRect( aPos
, aSize
);
115 if (aLogicRect
.Right() > aPageRect
.Right())
117 long nDiff
= aLogicRect
.Right() - aPageRect
.Right();
118 aLogicRect
.Left() -= nDiff
;
119 aLogicRect
.Right() -= nDiff
;
121 if (aLogicRect
.Bottom() > aPageRect
.Bottom())
123 long nDiff
= aLogicRect
.Bottom() - aPageRect
.Bottom();
124 aLogicRect
.Top() -= nDiff
;
125 aLogicRect
.Bottom() -= nDiff
;
128 if (aLogicRect
.Left() < aPageRect
.Left())
130 long nDiff
= aLogicRect
.Left() - aPageRect
.Left();
131 aLogicRect
.Right() -= nDiff
;
132 aLogicRect
.Left() -= nDiff
;
134 if (aLogicRect
.Top() < aPageRect
.Top())
136 long nDiff
= aLogicRect
.Top() - aPageRect
.Top();
137 aLogicRect
.Bottom() -= nDiff
;
138 aLogicRect
.Top() -= nDiff
;
143 void ScClient::ObjectAreaChanged()
145 SfxViewShell
* pSfxViewSh
= GetViewShell();
146 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
149 OSL_FAIL("Wrong ViewShell");
153 // Position und Groesse ins Dokument uebernehmen
154 SdrOle2Obj
* pDrawObj
= GetDrawObj();
157 Rectangle
aNewRectangle(GetScaledObjArea());
159 // #i118524# if sheared/rotated, center to non-rotated LogicRect
160 pDrawObj
->setSuppressSetVisAreaSize(true);
162 if(pDrawObj
->GetGeoStat().nDrehWink
|| pDrawObj
->GetGeoStat().nShearWink
)
164 pDrawObj
->SetLogicRect( aNewRectangle
);
166 const Rectangle
& rBoundRect
= pDrawObj
->GetCurrentBoundRect();
167 const Point
aDelta(aNewRectangle
.Center() - rBoundRect
.Center());
169 aNewRectangle
.Move(aDelta
.X(), aDelta
.Y());
172 pDrawObj
->SetLogicRect( aNewRectangle
);
173 pDrawObj
->setSuppressSetVisAreaSize(false);
175 // set document modified (SdrModel::SetChanged is not used)
176 // TODO/LATER: is there a reason that this code is not executed in Draw?
177 // SfxViewShell* pSfxViewSh = GetViewShell();
178 // ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
180 pViewSh
->GetViewData()->GetDocShell()->SetDrawModified();
184 pViewSh
->ScrollToObject( pDrawObj
);
187 void ScClient::ViewChanged()
189 if ( GetAspect() == embed::Aspects::MSOLE_ICON
)
191 // the iconified object seems not to need such a scaling handling
192 // since the replacement image and the size a completely controlled by the container
193 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
198 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObject();
200 // TODO/LEAN: working with Visual Area can switch object to running state
203 aSz
= xObj
->getVisualAreaSize( GetAspect() );
204 } catch ( embed::NoVisualAreaSizeException
& )
206 OSL_FAIL("The visual area size must be available!\n");
209 MapUnit aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( GetAspect() ) );
210 Size aVisSize
= OutputDevice::LogicToLogic( Size( aSz
.Width
, aSz
.Height
), aMapUnit
, MAP_100TH_MM
);
212 // Groesse ins Dokument uebernehmen
213 SdrOle2Obj
* pDrawObj
= GetDrawObj();
216 Rectangle aLogicRect
= pDrawObj
->GetLogicRect();
217 Fraction aFractX
= GetScaleWidth();
218 Fraction aFractY
= GetScaleHeight();
219 aFractX
*= aVisSize
.Width();
220 aFractY
*= aVisSize
.Height();
221 aVisSize
= Size( (long) aFractX
, (long) aFractY
); // skaliert fuer Draw-Model
223 // pClientData->SetObjArea vor pDrawObj->SetLogicRect, damit keine
224 // falschen Skalierungen ausgerechnet werden:
225 //Rectangle aObjArea = aLogicRect;
226 //aObjArea.SetSize( aVisSize ); // Dokument-Groesse vom Server
227 //SetObjArea( aObjArea );
229 SfxViewShell
* pSfxViewSh
= GetViewShell();
230 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
233 Window
* pWin
= pViewSh
->GetActiveWin();
234 if ( pWin
->LogicToPixel( aVisSize
) != pWin
->LogicToPixel( aLogicRect
.GetSize() ) )
236 aLogicRect
.SetSize( aVisSize
);
237 pDrawObj
->SetLogicRect( aLogicRect
);
239 // set document modified (SdrModel::SetChanged is not used)
240 pViewSh
->GetViewData()->GetDocShell()->SetDrawModified();
246 void ScClient::MakeVisible()
248 SdrOle2Obj
* pDrawObj
= GetDrawObj();
251 SfxViewShell
* pSfxViewSh
= GetViewShell();
252 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
254 pViewSh
->ScrollToObject( pDrawObj
);
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */