fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / app / client.cxx
blob97665f04fa364925732bab2cd46e92be32a30d4f
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 <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>
35 #include "client.hxx"
36 #include "tabvwsh.hxx"
37 #include "docsh.hxx"
38 #include <gridwin.hxx>
40 using namespace com::sun::star;
42 ScClient::ScClient( ScTabViewShell* pViewShell, vcl::Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) :
43 SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
44 pModel( pSdrModel ),
45 pGrafEdit( 0 )
47 SetObject( pObj->GetObjRef() );
50 ScClient::~ScClient()
54 SdrOle2Obj* ScClient::GetDrawObj()
56 uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
57 SdrOle2Obj* pOle2Obj = NULL;
58 OUString aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
60 sal_uInt16 nPages = pModel->GetPageCount();
61 for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
63 SdrPage* pPage = pModel->GetPage(nPNr);
64 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
65 SdrObject* pObject = aIter.Next();
66 while (pObject && !pOle2Obj)
68 if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
70 // name from InfoObject is PersistName
71 if ( static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == aName )
72 pOle2Obj = static_cast<SdrOle2Obj*>(pObject);
74 pObject = aIter.Next();
77 return pOle2Obj;
80 void ScClient::RequestNewObjectArea( Rectangle& aLogicRect )
82 SfxViewShell* pSfxViewSh = GetViewShell();
83 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
84 if (!pViewSh)
86 OSL_FAIL("Wrong ViewShell");
87 return;
90 Rectangle aOldRect = GetObjArea();
91 SdrOle2Obj* pDrawObj = GetDrawObj();
92 if ( pDrawObj )
94 if ( pDrawObj->IsResizeProtect() )
95 aLogicRect.SetSize( aOldRect.GetSize() );
97 if ( pDrawObj->IsMoveProtect() )
98 aLogicRect.SetPos( aOldRect.TopLeft() );
101 sal_uInt16 nTab = pViewSh->GetViewData().GetTabNo();
102 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
103 if ( pPage && aLogicRect != aOldRect )
105 Point aPos;
106 Size aSize = pPage->GetSize();
107 if ( aSize.Width() < 0 )
109 aPos.X() = aSize.Width() + 1; // negative
110 aSize.Width() = -aSize.Width(); // positive
112 Rectangle aPageRect( aPos, aSize );
114 if (aLogicRect.Right() > aPageRect.Right())
116 long nDiff = aLogicRect.Right() - aPageRect.Right();
117 aLogicRect.Left() -= nDiff;
118 aLogicRect.Right() -= nDiff;
120 if (aLogicRect.Bottom() > aPageRect.Bottom())
122 long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
123 aLogicRect.Top() -= nDiff;
124 aLogicRect.Bottom() -= nDiff;
127 if (aLogicRect.Left() < aPageRect.Left())
129 long nDiff = aLogicRect.Left() - aPageRect.Left();
130 aLogicRect.Right() -= nDiff;
131 aLogicRect.Left() -= nDiff;
133 if (aLogicRect.Top() < aPageRect.Top())
135 long nDiff = aLogicRect.Top() - aPageRect.Top();
136 aLogicRect.Bottom() -= nDiff;
137 aLogicRect.Top() -= nDiff;
142 void ScClient::ObjectAreaChanged()
144 SfxViewShell* pSfxViewSh = GetViewShell();
145 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
146 if (!pViewSh)
148 OSL_FAIL("Wrong ViewShell");
149 return;
152 // Take over position and size into document
153 SdrOle2Obj* pDrawObj = GetDrawObj();
154 if (pDrawObj)
156 Rectangle aNewRectangle(GetScaledObjArea());
158 // #i118524# if sheared/rotated, center to non-rotated LogicRect
159 pDrawObj->setSuppressSetVisAreaSize(true);
161 if(pDrawObj->GetGeoStat().nRotationAngle || pDrawObj->GetGeoStat().nShearAngle)
163 pDrawObj->SetLogicRect( aNewRectangle );
165 const Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
166 const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
168 aNewRectangle.Move(aDelta.X(), aDelta.Y());
171 pDrawObj->SetLogicRect( aNewRectangle );
172 pDrawObj->setSuppressSetVisAreaSize(false);
174 // set document modified (SdrModel::SetChanged is not used)
175 // TODO/LATER: is there a reason that this code is not executed in Draw?
176 // SfxViewShell* pSfxViewSh = GetViewShell();
177 // ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
178 if (pViewSh)
179 pViewSh->GetViewData().GetDocShell()->SetDrawModified();
182 if (pDrawObj)
183 pViewSh->ScrollToObject( pDrawObj );
186 void ScClient::ViewChanged()
188 if ( GetAspect() == embed::Aspects::MSOLE_ICON )
190 // the iconified object seems not to need such a scaling handling
191 // since the replacement image and the size a completely controlled by the container
192 // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
194 return;
197 uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
199 // TODO/LEAN: working with Visual Area can switch object to running state
200 awt::Size aSz;
201 try {
202 aSz = xObj->getVisualAreaSize( GetAspect() );
203 } catch ( embed::NoVisualAreaSizeException& )
205 OSL_FAIL("The visual area size must be available!\n");
208 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
209 Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM );
211 // Take over position and size into document
212 SdrOle2Obj* pDrawObj = GetDrawObj();
213 if (pDrawObj)
215 Rectangle aLogicRect = pDrawObj->GetLogicRect();
216 Fraction aFractX = GetScaleWidth();
217 Fraction aFractY = GetScaleHeight();
218 aFractX *= aVisSize.Width();
219 aFractY *= aVisSize.Height();
220 aVisSize = Size( (long) aFractX, (long) aFractY ); // Scaled for Draw model
222 // pClientData->SetObjArea before pDrawObj->SetLogicRect, so that we don't
223 // calculate wrong scalings:
224 //Rectangle aObjArea = aLogicRect;
225 //aObjArea.SetSize( aVisSize ); // Document size from the server
226 //SetObjArea( aObjArea );
228 SfxViewShell* pSfxViewSh = GetViewShell();
229 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
230 if ( pViewSh )
232 vcl::Window* pWin = pViewSh->GetActiveWin();
233 if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
235 aLogicRect.SetSize( aVisSize );
236 pDrawObj->SetLogicRect( aLogicRect );
238 // set document modified (SdrModel::SetChanged is not used)
239 pViewSh->GetViewData().GetDocShell()->SetDrawModified();
245 void ScClient::MakeVisible()
247 SdrOle2Obj* pDrawObj = GetDrawObj();
248 if (pDrawObj)
250 SfxViewShell* pSfxViewSh = GetViewShell();
251 ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
252 if (pViewSh)
253 pViewSh->ScrollToObject( pDrawObj );
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */