Branch data 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 : :
21 : : #include "chartview/DrawModelWrapper.hxx"
22 : : #include "macros.hxx"
23 : : #include "ShapeFactory.hxx"
24 : : #include "ChartItemPool.hxx"
25 : : #include "ObjectIdentifier.hxx"
26 : : #include <svx/unomodel.hxx>
27 : : #include <svl/itempool.hxx>
28 : : // header for class SfxBoolItem
29 : : #include <svl/eitem.hxx>
30 : : // header for define EE_PARA_HYPHENATE
31 : : #include <editeng/eeitem.hxx>
32 : : // header for class Svx3DPercentDiagonalItem
33 : : #include <svx/svx3ditems.hxx>
34 : : // header for class SvtPathOptions
35 : : #include <unotools/pathoptions.hxx>
36 : : // header E3dObjFactory
37 : : #include <svx/objfac3d.hxx>
38 : : // header for class SdrObjList
39 : : #include <svx/svdpage.hxx>
40 : : // header for SvxUnoXDashTable_createInstance
41 : : #include <svx/XPropertyTable.hxx>
42 : : // header for class XDashList
43 : : #include <svx/xtable.hxx>
44 : : // header for class SdrOutliner
45 : : #include <svx/svdoutl.hxx>
46 : : // header for class LinguMgr
47 : : #include <editeng/unolingu.hxx>
48 : : // header for class Application
49 : : #include <vcl/svapp.hxx>
50 : : // header for class VirtualDevice
51 : : #include <vcl/virdev.hxx>
52 : :
53 : : #include <com/sun/star/container/XChild.hpp>
54 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
55 : :
56 : : #include <sfx2/objsh.hxx>
57 : : #include <com/sun/star/linguistic2/XHyphenator.hpp>
58 : : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
59 : :
60 : : using namespace ::com::sun::star;
61 : :
62 : : //.............................................................................
63 : : namespace
64 : : {
65 : : // this code is copied from sfx2/source/doc/objembed.cxx
66 : 0 : SfxObjectShell * lcl_GetParentObjectShell( const uno::Reference< frame::XModel > & xModel )
67 : : {
68 : 0 : SfxObjectShell* pResult = NULL;
69 : :
70 : : try
71 : : {
72 [ # # ]: 0 : uno::Reference< container::XChild > xChildModel( xModel, uno::UNO_QUERY );
73 [ # # ]: 0 : if ( xChildModel.is() )
74 : : {
75 [ # # ][ # # ]: 0 : uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
[ # # ]
76 [ # # ]: 0 : if ( xParentTunnel.is() )
77 : : {
78 [ # # ]: 0 : SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
79 : : pResult = reinterpret_cast< SfxObjectShell * >(
80 [ # # ][ # # ]: 0 : xParentTunnel->getSomething( uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
[ # # ][ # # ]
[ # # ]
81 : 0 : }
82 [ # # ]: 0 : }
83 : : }
84 : 0 : catch( const uno::Exception& )
85 : : {
86 : : // TODO: error handling
87 : : }
88 : :
89 : 0 : return pResult;
90 : : }
91 : :
92 : : // this code is copied from sfx2/source/doc/objembed.cxx. It is a workaround to
93 : : // get the reference device (e.g. printer) fromthe parent document
94 : 0 : OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & xModel )
95 : : {
96 : 0 : SfxObjectShell * pParent = lcl_GetParentObjectShell( xModel );
97 [ # # ]: 0 : if ( pParent )
98 : 0 : return pParent->GetDocumentRefDev();
99 : 0 : return NULL;
100 : : }
101 : :
102 : : } // anonymous namespace
103 : :
104 : : //.. ...........................................................................
105 : : namespace chart
106 : : {
107 : : //.............................................................................
108 : :
109 : 56 : DrawModelWrapper::DrawModelWrapper(
110 : : uno::Reference<uno::XComponentContext> const & xContext )
111 [ + - ]: 112 : : SdrModel( SvtPathOptions().GetPalettePath() )
112 : : , m_xMCF(0)
113 : : , m_pChartItemPool(0)
114 : : , m_xMainDrawPage(0)
115 : : , m_xHiddenDrawPage(0)
116 [ + - + - ]: 112 : , m_apRefDevice(0)
[ + - ][ + - ]
117 : : {
118 [ + - ]: 56 : m_pChartItemPool = ChartItemPool::CreateChartItemPool();
119 : :
120 [ + - ][ + - ]: 56 : m_xMCF = xContext->getServiceManager();
[ + - ]
121 : :
122 [ + - ]: 56 : SetScaleUnit(MAP_100TH_MM);
123 [ + - ][ + - ]: 56 : SetScaleFraction(Fraction(1, 1));
124 [ + - ]: 56 : SetDefaultFontHeight(423); // 12pt
125 : :
126 [ + - ]: 56 : SfxItemPool* pMasterPool = &GetItemPool();
127 [ + - ]: 56 : pMasterPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
128 [ + - ][ + - ]: 56 : pMasterPool->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, sal_True) );
[ + - ]
129 [ + - ][ + - ]: 56 : pMasterPool->SetPoolDefaultItem(Svx3DPercentDiagonalItem (5));
[ + - ]
130 : :
131 : 56 : SfxItemPool* pPool = pMasterPool;
132 : : // append chart pool to end of pool chain
133 : 56 : for (;;)
134 : : {
135 [ + - ]: 112 : SfxItemPool* pSecondary = pPool->GetSecondaryPool();
136 [ + + ]: 112 : if (!pSecondary)
137 : 56 : break;
138 : :
139 : 56 : pPool = pSecondary;
140 : : }
141 [ + - ]: 56 : pPool->SetSecondaryPool(m_pChartItemPool);
142 [ + - ]: 56 : pMasterPool->FreezeIdRanges();
143 : :
144 : : //this factory needs to be created before first use of 3D scenes once upon an office runtime
145 : : //@todo in future this should be done by drawing engine itself on demand
146 : : static bool b3dFactoryInitialized = false;
147 [ + + ]: 56 : if(!b3dFactoryInitialized)
148 : : {
149 [ + - ]: 14 : E3dObjFactory aObjFactory;
150 [ + - ]: 14 : b3dFactoryInitialized = true;
151 : : }
152 : :
153 : : //Hyphenyation and spellchecking
154 [ + - ]: 56 : SdrOutliner& rOutliner = GetDrawOutliner();
155 : : try
156 : : {
157 [ + - ]: 56 : uno::Reference< linguistic2::XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
158 [ + - ]: 56 : if( xHyphenator.is() )
159 [ + - ]: 56 : rOutliner.SetHyphenator( xHyphenator );
160 : :
161 [ + - ]: 56 : uno::Reference< linguistic2::XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
162 [ + - ]: 56 : if ( xSpellChecker.is() )
163 [ + - ]: 56 : rOutliner.SetSpeller( xSpellChecker );
164 : : }
165 [ # # ]: 0 : catch(...)
166 : : {
167 : : OSL_FAIL("Can't get Hyphenator or SpellChecker for chart");
168 : : }
169 : :
170 : : //ref device for font rendering
171 [ + - ]: 56 : OutputDevice* pDefaultDevice = rOutliner.GetRefDevice();
172 [ - + ]: 56 : if( !pDefaultDevice )
173 [ # # ]: 0 : pDefaultDevice = Application::GetDefaultDevice();
174 [ + - ][ + - ]: 56 : m_apRefDevice = std::auto_ptr< OutputDevice >( new VirtualDevice( *pDefaultDevice ) );
[ + - ]
175 [ + - ]: 56 : MapMode aMapMode = m_apRefDevice->GetMapMode();
176 [ + - ]: 56 : aMapMode.SetMapUnit(MAP_100TH_MM);
177 [ + - ]: 56 : m_apRefDevice->SetMapMode(aMapMode);
178 [ + - ]: 56 : SetRefDevice(m_apRefDevice.get());
179 [ + - ][ + - ]: 56 : rOutliner.SetRefDevice(m_apRefDevice.get());
180 : 56 : }
181 : :
182 [ + - ]: 56 : DrawModelWrapper::~DrawModelWrapper()
183 : : {
184 : : //remove m_pChartItemPool from pool chain
185 [ + - ]: 56 : if(m_pChartItemPool)
186 : : {
187 [ + - ]: 56 : SfxItemPool* pPool = &GetItemPool();
188 : 56 : for (;;)
189 : : {
190 [ + - ]: 112 : SfxItemPool* pSecondary = pPool->GetSecondaryPool();
191 [ + + ]: 112 : if(pSecondary == m_pChartItemPool)
192 : : {
193 [ + - ]: 56 : pPool->SetSecondaryPool (NULL);
194 : 56 : break;
195 : : }
196 : 56 : pPool = pSecondary;
197 : : }
198 [ + - ]: 56 : SfxItemPool::Free(m_pChartItemPool);
199 : : }
200 [ - + ]: 112 : }
201 : :
202 : 56 : uno::Reference< uno::XInterface > DrawModelWrapper
203 : : ::createUnoModel()
204 : : {
205 [ + - ][ + - ]: 56 : uno::Reference< lang::XComponent > xComponent = new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer
206 [ + - ]: 56 : return uno::Reference< uno::XInterface >::query( xComponent );
207 : : }
208 : :
209 : 1917 : uno::Reference< frame::XModel > DrawModelWrapper::getUnoModel()
210 : : {
211 [ + - ]: 1917 : uno::Reference< uno::XInterface > xI = this->SdrModel::getUnoModel();
212 [ + - ]: 1917 : return uno::Reference<frame::XModel>::query( xI );
213 : : }
214 : :
215 : 2612 : SdrModel& DrawModelWrapper::getSdrModel()
216 : : {
217 : 2612 : return *this;
218 : : }
219 : :
220 : 175 : uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory()
221 : : {
222 [ + - ]: 175 : uno::Reference< lang::XMultiServiceFactory > xShapeFactory( this->getUnoModel(), uno::UNO_QUERY );
223 : 175 : return xShapeFactory;
224 : : }
225 : :
226 : 106 : uno::Reference< drawing::XDrawPage > DrawModelWrapper::getMainDrawPage()
227 : : {
228 : : //create draw page:
229 [ + + ]: 106 : if( !m_xMainDrawPage.is() )
230 : : {
231 [ + - ][ + - ]: 56 : uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( this->getUnoModel(), uno::UNO_QUERY );
232 [ + - ]: 56 : if( xDrawPagesSuplier.is() )
233 : : {
234 [ + - ][ + - ]: 56 : uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
235 [ + - ][ + - ]: 56 : if( xDrawPages->getCount()>1 )
[ - + ]
236 : : {
237 [ # # ][ # # ]: 0 : uno::Any aPage = xDrawPages->getByIndex( 0 ) ;
238 [ # # ]: 0 : aPage >>= m_xMainDrawPage;
239 : : }
240 [ + - ]: 56 : if(!m_xMainDrawPage.is())
241 : : {
242 [ + - ][ + - ]: 56 : m_xMainDrawPage = xDrawPages->insertNewByIndex( 0 );
[ + - ]
243 : 56 : }
244 : 56 : }
245 : : }
246 : : //ensure that additional shapes are in front of the chart objects so create the chart root before
247 [ + - ][ + - ]: 106 : ShapeFactory(this->getShapeFactory()).getOrCreateChartRootShape( m_xMainDrawPage );
[ + - ]
248 : 106 : return m_xMainDrawPage;
249 : : }
250 : 0 : uno::Reference< drawing::XDrawPage > DrawModelWrapper::getHiddenDrawPage()
251 : : {
252 [ # # ]: 0 : if( !m_xHiddenDrawPage.is() )
253 : : {
254 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( this->getUnoModel(), uno::UNO_QUERY );
255 [ # # ]: 0 : if( xDrawPagesSuplier.is() )
256 : : {
257 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
258 [ # # ][ # # ]: 0 : if( xDrawPages->getCount()>1 )
[ # # ]
259 : : {
260 [ # # ][ # # ]: 0 : uno::Any aPage = xDrawPages->getByIndex( 1 ) ;
261 [ # # ]: 0 : aPage >>= m_xHiddenDrawPage;
262 : : }
263 : :
264 [ # # ]: 0 : if(!m_xHiddenDrawPage.is())
265 : : {
266 [ # # ][ # # ]: 0 : if( xDrawPages->getCount()==0 )
[ # # ]
267 [ # # ][ # # ]: 0 : m_xMainDrawPage = xDrawPages->insertNewByIndex( 0 );
[ # # ]
268 [ # # ][ # # ]: 0 : m_xHiddenDrawPage = xDrawPages->insertNewByIndex( 1 );
[ # # ]
269 : 0 : }
270 : 0 : }
271 : : }
272 : 0 : return m_xHiddenDrawPage;
273 : : }
274 : 1071 : void DrawModelWrapper::clearMainDrawPage()
275 : : {
276 : : //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY );
277 [ + - ]: 1071 : uno::Reference<drawing::XShapes> xChartRoot( ShapeFactory::getChartRootShape( m_xMainDrawPage ) );
278 [ + - ]: 1071 : if( xChartRoot.is() )
279 : : {
280 [ + - ][ + - ]: 1071 : sal_Int32 nSubCount = xChartRoot->getCount();
281 : 1071 : uno::Reference< drawing::XShape > xShape;
282 [ + + ]: 4917 : for( sal_Int32 nS = nSubCount; nS--; )
283 : : {
284 [ + - ][ + - ]: 3846 : if( xChartRoot->getByIndex( nS ) >>= xShape )
[ + - ][ + - ]
285 [ + - ][ + - ]: 3846 : xChartRoot->remove( xShape );
286 : 1071 : }
287 : 1071 : }
288 : 1071 : }
289 : :
290 : 41 : uno::Reference< drawing::XShapes > DrawModelWrapper::getChartRootShape(
291 : : const uno::Reference< drawing::XDrawPage>& xDrawPage )
292 : : {
293 : 41 : return ShapeFactory::getChartRootShape( xDrawPage );
294 : : }
295 : :
296 : 843 : void DrawModelWrapper::lockControllers()
297 : : {
298 [ + - ]: 843 : uno::Reference< frame::XModel > xDrawModel( this->getUnoModel() );
299 [ + - ]: 843 : if( xDrawModel.is())
300 [ + - ][ + - ]: 843 : xDrawModel->lockControllers();
301 : 843 : }
302 : 843 : void DrawModelWrapper::unlockControllers()
303 : : {
304 [ + - ]: 843 : uno::Reference< frame::XModel > xDrawModel( this->getUnoModel() );
305 [ + - ]: 843 : if( xDrawModel.is())
306 [ + - ][ + - ]: 843 : xDrawModel->unlockControllers();
307 : 843 : }
308 : :
309 : 0 : void DrawModelWrapper::attachParentReferenceDevice( const uno::Reference< frame::XModel > & xChartModel )
310 : : {
311 : 0 : OutputDevice * pParentRefDev( lcl_GetParentRefDevice( xChartModel ));
312 [ # # ]: 0 : if( pParentRefDev )
313 : : {
314 : 0 : SetRefDevice( pParentRefDev );
315 : : }
316 : 0 : }
317 : :
318 : 0 : OutputDevice* DrawModelWrapper::getReferenceDevice() const
319 : : {
320 : 0 : return SdrModel::GetRefDevice();
321 : : }
322 : :
323 : 1118 : SfxItemPool& DrawModelWrapper::GetItemPool()
324 : : {
325 : 1118 : return this->SdrModel::GetItemPool();
326 : : }
327 : 0 : const SfxItemPool& DrawModelWrapper::GetItemPool() const
328 : : {
329 : 0 : return this->SdrModel::GetItemPool();
330 : : }
331 : 0 : XColorListRef DrawModelWrapper::GetColorList() const
332 : : {
333 : 0 : return this->SdrModel::GetColorList();
334 : : }
335 : 0 : XDashListRef DrawModelWrapper::GetDashList() const
336 : : {
337 : 0 : return this->SdrModel::GetDashList();
338 : : }
339 : 0 : XLineEndListRef DrawModelWrapper::GetLineEndList() const
340 : : {
341 : 0 : return this->SdrModel::GetLineEndList();
342 : : }
343 : 0 : XGradientListRef DrawModelWrapper::GetGradientList() const
344 : : {
345 : 0 : return this->SdrModel::GetGradientList();
346 : : }
347 : 0 : XHatchListRef DrawModelWrapper::GetHatchList() const
348 : : {
349 : 0 : return this->SdrModel::GetHatchList();
350 : : }
351 : 0 : XBitmapListRef DrawModelWrapper::GetBitmapList() const
352 : : {
353 : 0 : return this->SdrModel::GetBitmapList();
354 : : }
355 : :
356 : 0 : SdrObject* DrawModelWrapper::getNamedSdrObject( const rtl::OUString& rName )
357 : : {
358 [ # # ]: 0 : if( rName.isEmpty() )
359 : 0 : return 0;
360 [ # # ]: 0 : return getNamedSdrObject( rName, GetPage(0) );
361 : : }
362 : :
363 : 5211 : SdrObject* DrawModelWrapper::getNamedSdrObject( const String& rObjectCID, SdrObjList* pSearchList )
364 : : {
365 [ + + ][ - + ]: 5211 : if(!pSearchList || rObjectCID.Len()==0)
[ + + ]
366 : 1574 : return 0;
367 : 3637 : sal_uLong nCount = pSearchList->GetObjCount();
368 [ + + ]: 5419 : for( sal_uLong nN=0; nN<nCount; nN++ )
369 : : {
370 : 5211 : SdrObject* pObj = pSearchList->GetObj(nN);
371 [ - + ]: 5211 : if(!pObj)
372 : 0 : continue;
373 [ + - ][ + - ]: 5211 : if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) )
[ + + ]
374 : 1152 : return pObj;
375 : 4059 : pObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() );
376 [ + + ]: 4059 : if(pObj)
377 : 2277 : return pObj;
378 : : }
379 : 5211 : return 0;
380 : : }
381 : :
382 : 0 : bool DrawModelWrapper::removeShape( const uno::Reference< drawing::XShape >& xShape )
383 : : {
384 [ # # ]: 0 : uno::Reference< container::XChild > xChild( xShape, uno::UNO_QUERY );
385 [ # # ]: 0 : if( xChild.is() )
386 : : {
387 [ # # ][ # # ]: 0 : uno::Reference<drawing::XShapes> xShapes( xChild->getParent(), uno::UNO_QUERY );
[ # # ]
388 [ # # ]: 0 : if( xShapes.is() )
389 : : {
390 [ # # ][ # # ]: 0 : xShapes->remove(xShape);
391 : 0 : return true;
392 [ # # ]: 0 : }
393 : : }
394 : 0 : return false;
395 : : }
396 : :
397 : : //.............................................................................
398 : : } //namespace chart
399 : : //.............................................................................
400 : :
401 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|