Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/embed/XEmbeddedObject.hpp>
21 : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
22 :
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>
34 :
35 : #include "client.hxx"
36 : #include "tabvwsh.hxx"
37 : #include "docsh.hxx"
38 : #include <gridwin.hxx>
39 :
40 : using namespace com::sun::star;
41 :
42 0 : ScClient::ScClient( ScTabViewShell* pViewShell, vcl::Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) :
43 : SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
44 : pModel( pSdrModel ),
45 0 : pGrafEdit( 0 )
46 : {
47 0 : SetObject( pObj->GetObjRef() );
48 0 : }
49 :
50 0 : ScClient::~ScClient()
51 : {
52 0 : }
53 :
54 0 : SdrOle2Obj* ScClient::GetDrawObj()
55 : {
56 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
57 0 : SdrOle2Obj* pOle2Obj = NULL;
58 0 : OUString aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
59 :
60 0 : sal_uInt16 nPages = pModel->GetPageCount();
61 0 : for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
62 : {
63 0 : SdrPage* pPage = pModel->GetPage(nPNr);
64 0 : SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
65 0 : SdrObject* pObject = aIter.Next();
66 0 : while (pObject && !pOle2Obj)
67 : {
68 0 : if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
69 : {
70 : // name from InfoObject is PersistName
71 0 : if ( static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == aName )
72 0 : pOle2Obj = static_cast<SdrOle2Obj*>(pObject);
73 : }
74 0 : pObject = aIter.Next();
75 : }
76 0 : }
77 0 : return pOle2Obj;
78 : }
79 :
80 0 : void ScClient::RequestNewObjectArea( Rectangle& aLogicRect )
81 : {
82 0 : SfxViewShell* pSfxViewSh = GetViewShell();
83 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
84 0 : if (!pViewSh)
85 : {
86 : OSL_FAIL("Wrong ViewShell");
87 0 : return;
88 : }
89 :
90 0 : Rectangle aOldRect = GetObjArea();
91 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
92 0 : if ( pDrawObj )
93 : {
94 0 : if ( pDrawObj->IsResizeProtect() )
95 0 : aLogicRect.SetSize( aOldRect.GetSize() );
96 :
97 0 : if ( pDrawObj->IsMoveProtect() )
98 0 : aLogicRect.SetPos( aOldRect.TopLeft() );
99 : }
100 :
101 0 : sal_uInt16 nTab = pViewSh->GetViewData().GetTabNo();
102 0 : SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
103 0 : if ( pPage && aLogicRect != aOldRect )
104 : {
105 0 : Point aPos;
106 0 : Size aSize = pPage->GetSize();
107 0 : if ( aSize.Width() < 0 )
108 : {
109 0 : aPos.X() = aSize.Width() + 1; // negative
110 0 : aSize.Width() = -aSize.Width(); // positive
111 : }
112 0 : Rectangle aPageRect( aPos, aSize );
113 :
114 0 : if (aLogicRect.Right() > aPageRect.Right())
115 : {
116 0 : long nDiff = aLogicRect.Right() - aPageRect.Right();
117 0 : aLogicRect.Left() -= nDiff;
118 0 : aLogicRect.Right() -= nDiff;
119 : }
120 0 : if (aLogicRect.Bottom() > aPageRect.Bottom())
121 : {
122 0 : long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
123 0 : aLogicRect.Top() -= nDiff;
124 0 : aLogicRect.Bottom() -= nDiff;
125 : }
126 :
127 0 : if (aLogicRect.Left() < aPageRect.Left())
128 : {
129 0 : long nDiff = aLogicRect.Left() - aPageRect.Left();
130 0 : aLogicRect.Right() -= nDiff;
131 0 : aLogicRect.Left() -= nDiff;
132 : }
133 0 : if (aLogicRect.Top() < aPageRect.Top())
134 : {
135 0 : long nDiff = aLogicRect.Top() - aPageRect.Top();
136 0 : aLogicRect.Bottom() -= nDiff;
137 0 : aLogicRect.Top() -= nDiff;
138 : }
139 : }
140 : }
141 :
142 0 : void ScClient::ObjectAreaChanged()
143 : {
144 0 : SfxViewShell* pSfxViewSh = GetViewShell();
145 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
146 0 : if (!pViewSh)
147 : {
148 : OSL_FAIL("Wrong ViewShell");
149 0 : return;
150 : }
151 :
152 : // Take over position and size into document
153 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
154 0 : if (pDrawObj)
155 : {
156 0 : Rectangle aNewRectangle(GetScaledObjArea());
157 :
158 : // #i118524# if sheared/rotated, center to non-rotated LogicRect
159 0 : pDrawObj->setSuppressSetVisAreaSize(true);
160 :
161 0 : if(pDrawObj->GetGeoStat().nRotationAngle || pDrawObj->GetGeoStat().nShearAngle)
162 : {
163 0 : pDrawObj->SetLogicRect( aNewRectangle );
164 :
165 0 : const Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
166 0 : const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
167 :
168 0 : aNewRectangle.Move(aDelta.X(), aDelta.Y());
169 : }
170 :
171 0 : pDrawObj->SetLogicRect( aNewRectangle );
172 0 : pDrawObj->setSuppressSetVisAreaSize(false);
173 :
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 0 : if (pViewSh)
179 0 : pViewSh->GetViewData().GetDocShell()->SetDrawModified();
180 : }
181 :
182 0 : if (pDrawObj)
183 0 : pViewSh->ScrollToObject( pDrawObj );
184 : }
185 :
186 0 : void ScClient::ViewChanged()
187 : {
188 0 : if ( GetAspect() == embed::Aspects::MSOLE_ICON )
189 : {
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
193 :
194 0 : return;
195 : }
196 :
197 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
198 :
199 : // TODO/LEAN: working with Visual Area can switch object to running state
200 0 : awt::Size aSz;
201 : try {
202 0 : aSz = xObj->getVisualAreaSize( GetAspect() );
203 0 : } catch ( embed::NoVisualAreaSizeException& )
204 : {
205 : OSL_FAIL("The visual area size must be available!\n");
206 : }
207 :
208 0 : MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
209 0 : Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM );
210 :
211 : // Take over position and size into document
212 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
213 0 : if (pDrawObj)
214 : {
215 0 : Rectangle aLogicRect = pDrawObj->GetLogicRect();
216 0 : Fraction aFractX = GetScaleWidth();
217 0 : Fraction aFractY = GetScaleHeight();
218 0 : aFractX *= aVisSize.Width();
219 0 : aFractY *= aVisSize.Height();
220 0 : aVisSize = Size( (long) aFractX, (long) aFractY ); // Scaled for Draw model
221 :
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 );
227 :
228 0 : SfxViewShell* pSfxViewSh = GetViewShell();
229 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
230 0 : if ( pViewSh )
231 : {
232 0 : vcl::Window* pWin = pViewSh->GetActiveWin();
233 0 : if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
234 : {
235 0 : aLogicRect.SetSize( aVisSize );
236 0 : pDrawObj->SetLogicRect( aLogicRect );
237 :
238 : // set document modified (SdrModel::SetChanged is not used)
239 0 : pViewSh->GetViewData().GetDocShell()->SetDrawModified();
240 : }
241 : }
242 0 : }
243 : }
244 :
245 0 : void ScClient::MakeVisible()
246 : {
247 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
248 0 : if (pDrawObj)
249 : {
250 0 : SfxViewShell* pSfxViewSh = GetViewShell();
251 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
252 0 : if (pViewSh)
253 0 : pViewSh->ScrollToObject( pDrawObj );
254 : }
255 228 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|