1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: client.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
37 #include <com/sun/star/embed/XEmbeddedObject.hpp>
38 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <sot/sotref.hxx>
44 #include <svx/svditer.hxx>
45 #include <svx/svdobj.hxx>
46 #include <svx/svdmodel.hxx>
47 #include <svx/svdpage.hxx>
48 #include <svx/svdoole2.hxx>
49 #include <svx/svdview.hxx>
50 #include <svx/svdograf.hxx>
51 #include <svtools/embedhlp.hxx>
54 #include "tabvwsh.hxx"
57 using namespace com::sun::star
;
59 //------------------------------------------------------------------------
61 ScClient::ScClient( ScTabViewShell
* pViewShell
, Window
* pDraw
, SdrModel
* pSdrModel
, SdrOle2Obj
* pObj
) :
62 SfxInPlaceClient( pViewShell
, pDraw
, pObj
->GetAspect() ),
66 SetObject( pObj
->GetObjRef() );
69 __EXPORT
ScClient::~ScClient()
73 SdrOle2Obj
* ScClient::GetDrawObj()
75 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObject();
76 SdrOle2Obj
* pOle2Obj
= NULL
;
77 String aName
= GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj
);
79 USHORT nPages
= pModel
->GetPageCount();
80 for (USHORT nPNr
=0; nPNr
<nPages
&& !pOle2Obj
; nPNr
++)
82 SdrPage
* pPage
= pModel
->GetPage(nPNr
);
83 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
84 SdrObject
* pObject
= aIter
.Next();
85 while (pObject
&& !pOle2Obj
)
87 if ( pObject
->GetObjIdentifier() == OBJ_OLE2
)
89 // name from InfoObject is PersistName
90 if ( ((SdrOle2Obj
*)pObject
)->GetPersistName() == aName
)
91 pOle2Obj
= (SdrOle2Obj
*)pObject
;
93 pObject
= aIter
.Next();
99 void __EXPORT
ScClient::RequestNewObjectArea( Rectangle
& aLogicRect
)
101 SfxViewShell
* pSfxViewSh
= GetViewShell();
102 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
105 DBG_ERROR("Wrong ViewShell");
109 Rectangle aOldRect
= GetObjArea();
110 SdrOle2Obj
* pDrawObj
= GetDrawObj();
113 if ( pDrawObj
->IsResizeProtect() )
114 aLogicRect
.SetSize( aOldRect
.GetSize() );
116 if ( pDrawObj
->IsMoveProtect() )
117 aLogicRect
.SetPos( aOldRect
.TopLeft() );
120 USHORT nTab
= pViewSh
->GetViewData()->GetTabNo();
121 SdrPage
* pPage
= pModel
->GetPage(static_cast<sal_uInt16
>(static_cast<sal_Int16
>(nTab
)));
122 if ( pPage
&& aLogicRect
!= aOldRect
)
125 Size aSize
= pPage
->GetSize();
126 if ( aSize
.Width() < 0 )
128 aPos
.X() = aSize
.Width() + 1; // negative
129 aSize
.Width() = -aSize
.Width(); // positive
131 Rectangle
aPageRect( aPos
, aSize
);
133 if (aLogicRect
.Right() > aPageRect
.Right())
135 long nDiff
= aLogicRect
.Right() - aPageRect
.Right();
136 aLogicRect
.Left() -= nDiff
;
137 aLogicRect
.Right() -= nDiff
;
139 if (aLogicRect
.Bottom() > aPageRect
.Bottom())
141 long nDiff
= aLogicRect
.Bottom() - aPageRect
.Bottom();
142 aLogicRect
.Top() -= nDiff
;
143 aLogicRect
.Bottom() -= nDiff
;
146 if (aLogicRect
.Left() < aPageRect
.Left())
148 long nDiff
= aLogicRect
.Left() - aPageRect
.Left();
149 aLogicRect
.Right() -= nDiff
;
150 aLogicRect
.Left() -= nDiff
;
152 if (aLogicRect
.Top() < aPageRect
.Top())
154 long nDiff
= aLogicRect
.Top() - aPageRect
.Top();
155 aLogicRect
.Bottom() -= nDiff
;
156 aLogicRect
.Top() -= nDiff
;
161 void __EXPORT
ScClient::ObjectAreaChanged()
163 SfxViewShell
* pSfxViewSh
= GetViewShell();
164 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
167 DBG_ERROR("Wrong ViewShell");
171 // Position und Groesse ins Dokument uebernehmen
172 SdrOle2Obj
* pDrawObj
= GetDrawObj();
175 pDrawObj
->SetLogicRect( GetScaledObjArea() );
177 // set document modified (SdrModel::SetChanged is not used)
178 // TODO/LATER: is there a reason that this code is not executed in Draw?
179 // SfxViewShell* pSfxViewSh = GetViewShell();
180 // ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
182 pViewSh
->GetViewData()->GetDocShell()->SetDrawModified();
186 pViewSh
->ScrollToObject( pDrawObj
);
189 void __EXPORT
ScClient::ViewChanged()
191 if ( GetAspect() == embed::Aspects::MSOLE_ICON
)
193 // the iconified object seems not to need such a scaling handling
194 // since the replacement image and the size a completely controlled by the container
195 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
200 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObject();
202 // TODO/LEAN: working with Visual Area can switch object to running state
205 aSz
= xObj
->getVisualAreaSize( GetAspect() );
206 } catch ( embed::NoVisualAreaSizeException
& )
208 DBG_ERROR("The visual area size must be available!\n");
211 MapUnit aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( GetAspect() ) );
212 Size aVisSize
= OutputDevice::LogicToLogic( Size( aSz
.Width
, aSz
.Height
), aMapUnit
, MAP_100TH_MM
);
214 // Groesse ins Dokument uebernehmen
215 SdrOle2Obj
* pDrawObj
= GetDrawObj();
218 Rectangle aLogicRect
= pDrawObj
->GetLogicRect();
219 Fraction aFractX
= GetScaleWidth();
220 Fraction aFractY
= GetScaleHeight();
221 aFractX
*= aVisSize
.Width();
222 aFractY
*= aVisSize
.Height();
223 aVisSize
= Size( (long) aFractX
, (long) aFractY
); // skaliert fuer Draw-Model
225 // pClientData->SetObjArea vor pDrawObj->SetLogicRect, damit keine
226 // falschen Skalierungen ausgerechnet werden:
227 //Rectangle aObjArea = aLogicRect;
228 //aObjArea.SetSize( aVisSize ); // Dokument-Groesse vom Server
229 //SetObjArea( aObjArea );
231 SfxViewShell
* pSfxViewSh
= GetViewShell();
232 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
235 Window
* pWin
= pViewSh
->GetActiveWin();
236 if ( pWin
->LogicToPixel( aVisSize
) != pWin
->LogicToPixel( aLogicRect
.GetSize() ) )
238 aLogicRect
.SetSize( aVisSize
);
239 pDrawObj
->SetLogicRect( aLogicRect
);
241 // set document modified (SdrModel::SetChanged is not used)
242 pViewSh
->GetViewData()->GetDocShell()->SetDrawModified();
248 void __EXPORT
ScClient::MakeVisible()
250 SdrOle2Obj
* pDrawObj
= GetDrawObj();
253 SfxViewShell
* pSfxViewSh
= GetViewShell();
254 ScTabViewShell
* pViewSh
= PTR_CAST( ScTabViewShell
, pSfxViewSh
);
256 pViewSh
->ScrollToObject( pDrawObj
);