Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/embed/XEmbeddedObject.hpp>
30 : : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
31 : :
32 : : #include <toolkit/helper/vclunohelper.hxx>
33 : : #include <sfx2/objsh.hxx>
34 : : #include <sfx2/viewfrm.hxx>
35 : : #include <svx/svditer.hxx>
36 : : #include <svx/svdobj.hxx>
37 : : #include <svx/svdmodel.hxx>
38 : : #include <svx/svdpage.hxx>
39 : : #include <svx/svdoole2.hxx>
40 : : #include <svx/svdview.hxx>
41 : : #include <svx/svdograf.hxx>
42 : : #include <svtools/embedhlp.hxx>
43 : :
44 : : #include "client.hxx"
45 : : #include "tabvwsh.hxx"
46 : : #include "docsh.hxx"
47 : :
48 : : using namespace com::sun::star;
49 : :
50 : : //------------------------------------------------------------------------
51 : :
52 : 0 : ScClient::ScClient( ScTabViewShell* pViewShell, Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) :
53 : : SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
54 : : pModel( pSdrModel ),
55 : 0 : pGrafEdit( 0 )
56 : : {
57 [ # # ][ # # ]: 0 : SetObject( pObj->GetObjRef() );
58 : 0 : }
59 : :
60 : 0 : ScClient::~ScClient()
61 : : {
62 [ # # ]: 0 : }
63 : :
64 : 0 : SdrOle2Obj* ScClient::GetDrawObj()
65 : : {
66 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
67 : 0 : SdrOle2Obj* pOle2Obj = NULL;
68 [ # # ][ # # ]: 0 : String aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
[ # # ][ # # ]
69 : :
70 [ # # ]: 0 : sal_uInt16 nPages = pModel->GetPageCount();
71 [ # # ][ # # ]: 0 : for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
[ # # ]
72 : : {
73 [ # # ]: 0 : SdrPage* pPage = pModel->GetPage(nPNr);
74 [ # # ]: 0 : SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
75 [ # # ]: 0 : SdrObject* pObject = aIter.Next();
76 [ # # ][ # # ]: 0 : while (pObject && !pOle2Obj)
[ # # ]
77 : : {
78 [ # # ][ # # ]: 0 : if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
79 : : {
80 : : // name from InfoObject is PersistName
81 [ # # ][ # # ]: 0 : if ( ((SdrOle2Obj*)pObject)->GetPersistName() == aName )
[ # # ][ # # ]
82 : 0 : pOle2Obj = (SdrOle2Obj*)pObject;
83 : : }
84 [ # # ]: 0 : pObject = aIter.Next();
85 : : }
86 : 0 : }
87 [ # # ]: 0 : return pOle2Obj;
88 : : }
89 : :
90 : 0 : void ScClient::RequestNewObjectArea( Rectangle& aLogicRect )
91 : : {
92 : 0 : SfxViewShell* pSfxViewSh = GetViewShell();
93 [ # # ][ # # ]: 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
[ # # ][ # # ]
94 [ # # ]: 0 : if (!pViewSh)
95 : : {
96 : : OSL_FAIL("Wrong ViewShell");
97 : 0 : return;
98 : : }
99 : :
100 [ # # ]: 0 : Rectangle aOldRect = GetObjArea();
101 [ # # ]: 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
102 [ # # ]: 0 : if ( pDrawObj )
103 : : {
104 [ # # ][ # # ]: 0 : if ( pDrawObj->IsResizeProtect() )
105 [ # # ][ # # ]: 0 : aLogicRect.SetSize( aOldRect.GetSize() );
106 : :
107 [ # # ][ # # ]: 0 : if ( pDrawObj->IsMoveProtect() )
108 : 0 : aLogicRect.SetPos( aOldRect.TopLeft() );
109 : : }
110 : :
111 : 0 : sal_uInt16 nTab = pViewSh->GetViewData()->GetTabNo();
112 [ # # ]: 0 : SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
113 [ # # ][ # # ]: 0 : if ( pPage && aLogicRect != aOldRect )
[ # # ][ # # ]
114 : : {
115 : 0 : Point aPos;
116 [ # # ]: 0 : Size aSize = pPage->GetSize();
117 [ # # ]: 0 : if ( aSize.Width() < 0 )
118 : : {
119 : 0 : aPos.X() = aSize.Width() + 1; // negative
120 : 0 : aSize.Width() = -aSize.Width(); // positive
121 : : }
122 [ # # ]: 0 : Rectangle aPageRect( aPos, aSize );
123 : :
124 [ # # ]: 0 : if (aLogicRect.Right() > aPageRect.Right())
125 : : {
126 : 0 : long nDiff = aLogicRect.Right() - aPageRect.Right();
127 : 0 : aLogicRect.Left() -= nDiff;
128 : 0 : aLogicRect.Right() -= nDiff;
129 : : }
130 [ # # ]: 0 : if (aLogicRect.Bottom() > aPageRect.Bottom())
131 : : {
132 : 0 : long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
133 : 0 : aLogicRect.Top() -= nDiff;
134 : 0 : aLogicRect.Bottom() -= nDiff;
135 : : }
136 : :
137 [ # # ]: 0 : if (aLogicRect.Left() < aPageRect.Left())
138 : : {
139 : 0 : long nDiff = aLogicRect.Left() - aPageRect.Left();
140 : 0 : aLogicRect.Right() -= nDiff;
141 : 0 : aLogicRect.Left() -= nDiff;
142 : : }
143 [ # # ]: 0 : if (aLogicRect.Top() < aPageRect.Top())
144 : : {
145 : 0 : long nDiff = aLogicRect.Top() - aPageRect.Top();
146 : 0 : aLogicRect.Bottom() -= nDiff;
147 : 0 : aLogicRect.Top() -= nDiff;
148 : : }
149 : : }
150 : : }
151 : :
152 : 0 : void ScClient::ObjectAreaChanged()
153 : : {
154 : 0 : SfxViewShell* pSfxViewSh = GetViewShell();
155 [ # # ][ # # ]: 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
156 [ # # ]: 0 : if (!pViewSh)
157 : : {
158 : : OSL_FAIL("Wrong ViewShell");
159 : 0 : return;
160 : : }
161 : :
162 : : // Position und Groesse ins Dokument uebernehmen
163 : 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
164 [ # # ]: 0 : if (pDrawObj)
165 : : {
166 [ # # ]: 0 : pDrawObj->SetLogicRect( GetScaledObjArea() );
167 : :
168 : : // set document modified (SdrModel::SetChanged is not used)
169 : : // TODO/LATER: is there a reason that this code is not executed in Draw?
170 : : // SfxViewShell* pSfxViewSh = GetViewShell();
171 : : // ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
172 [ # # ]: 0 : if (pViewSh)
173 : 0 : pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
174 : : }
175 : :
176 [ # # ]: 0 : if (pDrawObj)
177 : 0 : pViewSh->ScrollToObject( pDrawObj );
178 : : }
179 : :
180 : 0 : void ScClient::ViewChanged()
181 : : {
182 [ # # ][ # # ]: 0 : if ( GetAspect() == embed::Aspects::MSOLE_ICON )
183 : : {
184 : : // the iconified object seems not to need such a scaling handling
185 : : // since the replacement image and the size a completely controlled by the container
186 : : // TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
187 : :
188 [ # # ]: 0 : return;
189 : : }
190 : :
191 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
192 : :
193 : : // TODO/LEAN: working with Visual Area can switch object to running state
194 : 0 : awt::Size aSz;
195 : : try {
196 [ # # ][ # # ]: 0 : aSz = xObj->getVisualAreaSize( GetAspect() );
[ # # ]
197 [ # # ]: 0 : } catch ( embed::NoVisualAreaSizeException& )
198 : : {
199 : : OSL_FAIL("The visual area size must be available!\n");
200 : : }
201 : :
202 [ # # ][ # # ]: 0 : MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
[ # # ][ # # ]
203 [ # # ][ # # ]: 0 : Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM );
[ # # ][ # # ]
[ # # ]
204 : :
205 : : // Groesse ins Dokument uebernehmen
206 [ # # ]: 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
207 [ # # ]: 0 : if (pDrawObj)
208 : : {
209 [ # # ]: 0 : Rectangle aLogicRect = pDrawObj->GetLogicRect();
210 [ # # ][ # # ]: 0 : Fraction aFractX = GetScaleWidth();
211 [ # # ][ # # ]: 0 : Fraction aFractY = GetScaleHeight();
212 [ # # ][ # # ]: 0 : aFractX *= aVisSize.Width();
213 [ # # ][ # # ]: 0 : aFractY *= aVisSize.Height();
214 [ # # ][ # # ]: 0 : aVisSize = Size( (long) aFractX, (long) aFractY ); // skaliert fuer Draw-Model
215 : :
216 : : // pClientData->SetObjArea vor pDrawObj->SetLogicRect, damit keine
217 : : // falschen Skalierungen ausgerechnet werden:
218 : : //Rectangle aObjArea = aLogicRect;
219 : : //aObjArea.SetSize( aVisSize ); // Dokument-Groesse vom Server
220 : : //SetObjArea( aObjArea );
221 : :
222 : 0 : SfxViewShell* pSfxViewSh = GetViewShell();
223 [ # # ][ # # ]: 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
[ # # ][ # # ]
224 [ # # ]: 0 : if ( pViewSh )
225 : : {
226 [ # # ]: 0 : Window* pWin = pViewSh->GetActiveWin();
227 [ # # ][ # # ]: 0 : if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
[ # # ][ # # ]
228 : : {
229 [ # # ]: 0 : aLogicRect.SetSize( aVisSize );
230 [ # # ]: 0 : pDrawObj->SetLogicRect( aLogicRect );
231 : :
232 : : // set document modified (SdrModel::SetChanged is not used)
233 [ # # ]: 0 : pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
234 : : }
235 : : }
236 : 0 : }
237 : : }
238 : :
239 : 0 : void ScClient::MakeVisible()
240 : : {
241 : 0 : SdrOle2Obj* pDrawObj = GetDrawObj();
242 [ # # ]: 0 : if (pDrawObj)
243 : : {
244 : 0 : SfxViewShell* pSfxViewSh = GetViewShell();
245 [ # # ][ # # ]: 0 : ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
246 [ # # ]: 0 : if (pViewSh)
247 : 0 : pViewSh->ScrollToObject( pDrawObj );
248 : : }
249 : 0 : }
250 : :
251 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|