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 41 : DrawModelWrapper::DrawModelWrapper(
110 : uno::Reference<uno::XComponentContext> const & xContext )
111 82 : : SdrModel( SvtPathOptions().GetPalettePath() )
112 : , m_xMCF(0)
113 : , m_pChartItemPool(0)
114 : , m_xMainDrawPage(0)
115 : , m_xHiddenDrawPage(0)
116 82 : , m_apRefDevice(0)
117 : {
118 41 : m_pChartItemPool = ChartItemPool::CreateChartItemPool();
119 :
120 41 : m_xMCF = xContext->getServiceManager();
121 :
122 41 : SetScaleUnit(MAP_100TH_MM);
123 41 : SetScaleFraction(Fraction(1, 1));
124 41 : SetDefaultFontHeight(423); // 12pt
125 :
126 41 : SfxItemPool* pMasterPool = &GetItemPool();
127 41 : pMasterPool->SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
128 41 : pMasterPool->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, sal_True) );
129 41 : pMasterPool->SetPoolDefaultItem(Svx3DPercentDiagonalItem (5));
130 :
131 41 : SfxItemPool* pPool = pMasterPool;
132 : // append chart pool to end of pool chain
133 41 : for (;;)
134 : {
135 82 : SfxItemPool* pSecondary = pPool->GetSecondaryPool();
136 82 : if (!pSecondary)
137 41 : break;
138 :
139 41 : pPool = pSecondary;
140 : }
141 41 : pPool->SetSecondaryPool(m_pChartItemPool);
142 41 : 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 41 : if(!b3dFactoryInitialized)
148 : {
149 1 : E3dObjFactory aObjFactory;
150 1 : b3dFactoryInitialized = true;
151 : }
152 :
153 : //Hyphenyation and spellchecking
154 41 : SdrOutliner& rOutliner = GetDrawOutliner();
155 : try
156 : {
157 41 : uno::Reference< linguistic2::XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
158 41 : if( xHyphenator.is() )
159 41 : rOutliner.SetHyphenator( xHyphenator );
160 :
161 41 : uno::Reference< linguistic2::XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
162 41 : if ( xSpellChecker.is() )
163 41 : 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 41 : OutputDevice* pDefaultDevice = rOutliner.GetRefDevice();
172 41 : if( !pDefaultDevice )
173 0 : pDefaultDevice = Application::GetDefaultDevice();
174 41 : m_apRefDevice = std::auto_ptr< OutputDevice >( new VirtualDevice( *pDefaultDevice ) );
175 41 : MapMode aMapMode = m_apRefDevice->GetMapMode();
176 41 : aMapMode.SetMapUnit(MAP_100TH_MM);
177 41 : m_apRefDevice->SetMapMode(aMapMode);
178 41 : SetRefDevice(m_apRefDevice.get());
179 41 : rOutliner.SetRefDevice(m_apRefDevice.get());
180 41 : }
181 :
182 123 : DrawModelWrapper::~DrawModelWrapper()
183 : {
184 : //remove m_pChartItemPool from pool chain
185 41 : if(m_pChartItemPool)
186 : {
187 41 : SfxItemPool* pPool = &GetItemPool();
188 41 : for (;;)
189 : {
190 82 : SfxItemPool* pSecondary = pPool->GetSecondaryPool();
191 82 : if(pSecondary == m_pChartItemPool)
192 : {
193 41 : pPool->SetSecondaryPool (NULL);
194 41 : break;
195 : }
196 41 : pPool = pSecondary;
197 : }
198 41 : SfxItemPool::Free(m_pChartItemPool);
199 : }
200 82 : }
201 :
202 41 : uno::Reference< uno::XInterface > DrawModelWrapper
203 : ::createUnoModel()
204 : {
205 41 : 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 41 : return uno::Reference< uno::XInterface >::query( xComponent );
207 : }
208 :
209 325 : uno::Reference< frame::XModel > DrawModelWrapper::getUnoModel()
210 : {
211 325 : uno::Reference< uno::XInterface > xI = this->SdrModel::getUnoModel();
212 325 : return uno::Reference<frame::XModel>::query( xI );
213 : }
214 :
215 369 : SdrModel& DrawModelWrapper::getSdrModel()
216 : {
217 369 : return *this;
218 : }
219 :
220 202 : uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory()
221 : {
222 202 : uno::Reference< lang::XMultiServiceFactory > xShapeFactory( this->getUnoModel(), uno::UNO_QUERY );
223 202 : return xShapeFactory;
224 : }
225 :
226 161 : uno::Reference< drawing::XDrawPage > DrawModelWrapper::getMainDrawPage()
227 : {
228 : //create draw page:
229 161 : if( !m_xMainDrawPage.is() )
230 : {
231 41 : uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSuplier( this->getUnoModel(), uno::UNO_QUERY );
232 41 : if( xDrawPagesSuplier.is() )
233 : {
234 41 : uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSuplier->getDrawPages () );
235 41 : if( xDrawPages->getCount()>1 )
236 : {
237 0 : uno::Any aPage = xDrawPages->getByIndex( 0 ) ;
238 0 : aPage >>= m_xMainDrawPage;
239 : }
240 41 : if(!m_xMainDrawPage.is())
241 : {
242 41 : m_xMainDrawPage = xDrawPages->insertNewByIndex( 0 );
243 41 : }
244 41 : }
245 : }
246 : //ensure that additional shapes are in front of the chart objects so create the chart root before
247 161 : ShapeFactory(this->getShapeFactory()).getOrCreateChartRootShape( m_xMainDrawPage );
248 161 : 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 41 : void DrawModelWrapper::clearMainDrawPage()
275 : {
276 : //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY );
277 41 : uno::Reference<drawing::XShapes> xChartRoot( ShapeFactory::getChartRootShape( m_xMainDrawPage ) );
278 41 : if( xChartRoot.is() )
279 : {
280 41 : sal_Int32 nSubCount = xChartRoot->getCount();
281 41 : uno::Reference< drawing::XShape > xShape;
282 82 : for( sal_Int32 nS = nSubCount; nS--; )
283 : {
284 0 : if( xChartRoot->getByIndex( nS ) >>= xShape )
285 0 : xChartRoot->remove( xShape );
286 41 : }
287 41 : }
288 41 : }
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 41 : void DrawModelWrapper::lockControllers()
297 : {
298 41 : uno::Reference< frame::XModel > xDrawModel( this->getUnoModel() );
299 41 : if( xDrawModel.is())
300 41 : xDrawModel->lockControllers();
301 41 : }
302 41 : void DrawModelWrapper::unlockControllers()
303 : {
304 41 : uno::Reference< frame::XModel > xDrawModel( this->getUnoModel() );
305 41 : if( xDrawModel.is())
306 41 : xDrawModel->unlockControllers();
307 41 : }
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 164 : SfxItemPool& DrawModelWrapper::GetItemPool()
324 : {
325 164 : 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 1380 : SdrObject* DrawModelWrapper::getNamedSdrObject( const String& rObjectCID, SdrObjList* pSearchList )
364 : {
365 1380 : if(!pSearchList || rObjectCID.Len()==0)
366 860 : return 0;
367 520 : sal_uLong nCount = pSearchList->GetObjCount();
368 1880 : for( sal_uLong nN=0; nN<nCount; nN++ )
369 : {
370 1360 : SdrObject* pObj = pSearchList->GetObj(nN);
371 1360 : if(!pObj)
372 0 : continue;
373 1360 : if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) )
374 0 : return pObj;
375 1360 : pObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() );
376 1360 : if(pObj)
377 0 : return pObj;
378 : }
379 520 : 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: */
|