fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / model / main / ChartModel_Persistence.cxx
blob2535c7506372b35efd81deb5475a8cf676b39804
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 "ChartModel.hxx"
21 #include "MediaDescriptorHelper.hxx"
22 #include "macros.hxx"
23 #include "ChartViewHelper.hxx"
24 #include "ChartModelHelper.hxx"
25 #include "AxisHelper.hxx"
26 #include "ThreeDHelper.hxx"
28 #include <com/sun/star/chart2/LegendPosition.hpp>
29 #include <com/sun/star/container/XNameAccess.hpp>
30 #include <com/sun/star/document/XExporter.hpp>
31 #include <com/sun/star/document/XImporter.hpp>
32 #include <com/sun/star/document/XFilter.hpp>
33 #include <com/sun/star/drawing/FillStyle.hpp>
34 #include <com/sun/star/drawing/LineStyle.hpp>
35 #include <com/sun/star/drawing/ProjectionMode.hpp>
36 #include <com/sun/star/embed/ElementModes.hpp>
37 #include <com/sun/star/embed/XStorage.hpp>
38 #include <com/sun/star/embed/StorageFactory.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #include <com/sun/star/io/TempFile.hpp>
43 #include <com/sun/star/io/XSeekable.hpp>
44 #include <com/sun/star/ucb/CommandFailedException.hpp>
46 #include <ucbhelper/content.hxx>
47 #include <unotools/ucbstreamhelper.hxx>
48 #include <vcl/cvtgrf.hxx>
49 #include <comphelper/processfactory.hxx>
50 #include <comphelper/storagehelper.hxx>
51 #include <vcl/svapp.hxx>
52 #include <vcl/settings.hxx>
54 #include <algorithm>
55 #include <functional>
57 using namespace ::com::sun::star;
59 using ::com::sun::star::uno::Reference;
60 using ::com::sun::star::uno::Sequence;
61 using ::osl::MutexGuard;
63 namespace
65 struct lcl_PropNameEquals : public ::std::unary_function< beans::PropertyValue, bool >
67 lcl_PropNameEquals( const OUString & rStrToCompareWith ) :
68 m_aStr( rStrToCompareWith )
70 bool operator() ( const beans::PropertyValue & rProp )
72 return rProp.Name.equals( m_aStr );
74 private:
75 OUString m_aStr;
78 template< typename T >
79 T lcl_getProperty(
80 const Sequence< beans::PropertyValue > & rMediaDescriptor,
81 const OUString & rPropName )
83 T aResult;
84 if( rMediaDescriptor.getLength())
86 OUString aPropName( rPropName );
87 const beans::PropertyValue * pIt = rMediaDescriptor.getConstArray();
88 const beans::PropertyValue * pEndIt = pIt + + rMediaDescriptor.getLength();
89 pIt = ::std::find_if( pIt, pEndIt, lcl_PropNameEquals( aPropName ));
90 if( pIt != pEndIt )
91 (*pIt).Value >>= aResult;
93 return aResult;
96 void lcl_addStorageToMediaDescriptor(
97 Sequence< beans::PropertyValue > & rOutMD,
98 const Reference< embed::XStorage > & xStorage )
100 rOutMD.realloc( rOutMD.getLength() + 1 );
101 rOutMD[rOutMD.getLength() - 1] = beans::PropertyValue(
102 "Storage", -1, uno::makeAny( xStorage ), beans::PropertyState_DIRECT_VALUE );
105 Reference< embed::XStorage > lcl_createStorage(
106 const OUString & rURL,
107 const Reference< uno::XComponentContext > & xContext,
108 const Sequence< beans::PropertyValue > & rMediaDescriptor )
110 // create new storage
111 Reference< embed::XStorage > xStorage;
112 if( !xContext.is())
113 return xStorage;
117 Reference< io::XStream > xStream(
118 ::ucbhelper::Content( rURL, Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext()).openStream(),
119 uno::UNO_QUERY );
121 Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) );
122 Sequence< uno::Any > aStorageArgs( 3 );
123 aStorageArgs[0] <<= xStream;
124 aStorageArgs[1] <<= embed::ElementModes::READWRITE;
125 aStorageArgs[2] <<= rMediaDescriptor;
126 xStorage.set(
127 xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW );
128 OSL_ENSURE( xStorage.is(), "No Storage" );
130 catch(const css::ucb::ContentCreationException& rEx)
132 ASSERT_EXCEPTION( rEx );
134 catch(const css::ucb::CommandFailedException& rEx)
136 ASSERT_EXCEPTION( rEx );
139 return xStorage;
142 } // anonymous namespace
144 namespace chart
147 Reference< document::XFilter > ChartModel::impl_createFilter(
148 const Sequence< beans::PropertyValue > & rMediaDescriptor )
150 Reference< document::XFilter > xFilter;
152 // find FilterName in MediaDescriptor
153 OUString aFilterName(
154 lcl_getProperty< OUString >( rMediaDescriptor, "FilterName" ) );
156 // if FilterName was found, get Filter from factory
157 if( !aFilterName.isEmpty() )
161 Reference< container::XNameAccess > xFilterFact(
162 m_xContext->getServiceManager()->createInstanceWithContext(
163 "com.sun.star.document.FilterFactory", m_xContext ),
164 uno::UNO_QUERY_THROW );
165 uno::Any aFilterProps( xFilterFact->getByName( aFilterName ));
166 Sequence< beans::PropertyValue > aProps;
168 if( aFilterProps.hasValue() &&
169 (aFilterProps >>= aProps))
171 OUString aFilterServiceName(
172 lcl_getProperty< OUString >( aProps, "FilterService" ) );
174 if( !aFilterServiceName.isEmpty())
176 xFilter.set(
177 m_xContext->getServiceManager()->createInstanceWithContext(
178 aFilterServiceName, m_xContext ), uno::UNO_QUERY_THROW );
179 SAL_INFO("chart2", "Filter found for service " << aFilterServiceName );
183 catch( const uno::Exception & ex )
185 ASSERT_EXCEPTION( ex );
187 OSL_ENSURE( xFilter.is(), "Filter not found via factory" );
190 // fall-back: create XML-Filter
191 if( ! xFilter.is())
193 OSL_TRACE( "No FilterName passed in MediaDescriptor" );
194 xFilter.set(
195 m_xContext->getServiceManager()->createInstanceWithContext(
196 "com.sun.star.comp.chart2.XMLFilter", m_xContext ),
197 uno::UNO_QUERY_THROW );
200 return xFilter;
203 // frame::XStorable2
205 void SAL_CALL ChartModel::storeSelf( const Sequence< beans::PropertyValue >& rMediaDescriptor )
206 throw (lang::IllegalArgumentException,
207 io::IOException,
208 uno::RuntimeException, std::exception)
210 // only some parameters are allowed (see also SfxBaseModel)
211 // "VersionComment", "Author", "InteractionHandler", "StatusIndicator"
212 // However, they are ignored here. They would become interesting when
213 // charts support a standalone format again.
214 impl_store( rMediaDescriptor, m_xStorage );
217 // frame::XStorable (base of XStorable2)
218 sal_Bool SAL_CALL ChartModel::hasLocation()
219 throw(uno::RuntimeException, std::exception)
221 //@todo guard
222 return !m_aResource.isEmpty();
225 OUString SAL_CALL ChartModel::getLocation()
226 throw(uno::RuntimeException, std::exception)
228 return impl_g_getLocation();
231 sal_Bool SAL_CALL ChartModel::isReadonly()
232 throw(uno::RuntimeException, std::exception)
234 //@todo guard
235 return m_bReadOnly;
238 void SAL_CALL ChartModel::store()
239 throw(io::IOException,
240 uno::RuntimeException, std::exception)
242 apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
243 if(!aGuard.startApiCall(true)) //start LongLastingCall
244 return; //behave passive if already disposed or closed or throw exception @todo?
246 OUString aLocation = m_aResource;
248 if( aLocation.isEmpty() )
249 throw io::IOException( "no location specified", static_cast< ::cppu::OWeakObject* >(this));
250 //@todo check whether aLocation is something like private:factory...
251 if( m_bReadOnly )
252 throw io::IOException( "document is read only", static_cast< ::cppu::OWeakObject* >(this));
254 aGuard.clear();
256 // store
257 impl_store( m_aMediaDescriptor, m_xStorage );
260 void SAL_CALL ChartModel::storeAsURL(
261 const OUString& rURL,
262 const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
263 throw(io::IOException, uno::RuntimeException, std::exception)
265 apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
266 if(!aGuard.startApiCall(true)) //start LongLastingCall
267 return; //behave passive if already disposed or closed or throw exception @todo?
269 apphelper::MediaDescriptorHelper aMediaDescriptorHelper(rMediaDescriptor);
270 uno::Sequence< beans::PropertyValue > aReducedMediaDescriptor(
271 aMediaDescriptorHelper.getReducedForModel() );
273 m_bReadOnly = false;
274 aGuard.clear();
276 // create new storage
277 Reference< embed::XStorage > xStorage( lcl_createStorage( rURL, m_xContext, aReducedMediaDescriptor ));
279 if( xStorage.is())
281 impl_store( aReducedMediaDescriptor, xStorage );
282 attachResource( rURL, aReducedMediaDescriptor );
286 void SAL_CALL ChartModel::storeToURL(
287 const OUString& rURL,
288 const uno::Sequence< beans::PropertyValue >& rMediaDescriptor )
289 throw(io::IOException,
290 uno::RuntimeException, std::exception)
292 apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
293 if(!aGuard.startApiCall(true)) //start LongLastingCall
294 return; //behave passive if already disposed or closed or throw exception @todo?
295 //do not change the internal state of the document here
297 aGuard.clear();
299 apphelper::MediaDescriptorHelper aMediaDescriptorHelper(rMediaDescriptor);
300 uno::Sequence< beans::PropertyValue > aReducedMediaDescriptor(
301 aMediaDescriptorHelper.getReducedForModel() );
303 if ( rURL == "private:stream" )
307 if( m_xContext.is() && aMediaDescriptorHelper.ISSET_OutputStream )
309 Reference< io::XStream > xStream(
310 io::TempFile::create(m_xContext), uno::UNO_QUERY_THROW );
311 Reference< io::XInputStream > xInputStream( xStream->getInputStream());
313 Reference< embed::XStorage > xStorage(
314 ::comphelper::OStorageHelper::GetStorageFromStream( xStream, embed::ElementModes::READWRITE, m_xContext ));
315 if( xStorage.is())
317 impl_store( aReducedMediaDescriptor, xStorage );
319 Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY_THROW );
320 xSeekable->seek( 0 );
321 ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, aMediaDescriptorHelper.OutputStream );
325 catch( const uno::Exception & ex )
327 ASSERT_EXCEPTION( ex );
330 else
332 // create new storage
333 Reference< embed::XStorage > xStorage( lcl_createStorage( rURL, m_xContext, aReducedMediaDescriptor ));
335 if( xStorage.is())
336 impl_store( aReducedMediaDescriptor, xStorage );
340 void ChartModel::impl_store(
341 const Sequence< beans::PropertyValue >& rMediaDescriptor,
342 const Reference< embed::XStorage > & xStorage )
344 Reference< document::XFilter > xFilter( impl_createFilter( rMediaDescriptor));
345 if( xFilter.is() && xStorage.is())
347 Sequence< beans::PropertyValue > aMD( rMediaDescriptor );
348 lcl_addStorageToMediaDescriptor( aMD, xStorage );
351 Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY_THROW );
352 xExporter->setSourceDocument( Reference< lang::XComponent >( this ));
353 xFilter->filter( aMD );
355 catch( const uno::Exception & ex )
357 ASSERT_EXCEPTION( ex );
360 else
362 OSL_FAIL( "No filter" );
365 setModified( sal_False );
367 //#i66865#
368 //for data change notification during chart is not loaded:
369 //notify parent data provider after saving thus the parent document can store
370 //the ranges for which a load and update of the chart will be necessary
371 Reference< beans::XPropertySet > xPropSet( m_xParent, uno::UNO_QUERY );
372 if ( !hasInternalDataProvider() && xPropSet.is() )
374 apphelper::MediaDescriptorHelper aMDHelper(rMediaDescriptor);
377 xPropSet->setPropertyValue(
378 "SavedObject",
379 uno::makeAny( aMDHelper.HierarchicalDocumentName ) );
381 catch ( const uno::Exception& )
387 void ChartModel::insertDefaultChart()
389 lockControllers();
390 createInternalDataProvider( sal_False );
393 // create default chart
394 Reference< chart2::XChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() );
395 if( xTemplate.is())
399 Reference< chart2::data::XDataSource > xDataSource( impl_createDefaultData() );
400 Sequence< beans::PropertyValue > aParam;
402 bool bSupportsCategories = xTemplate->supportsCategories();
403 if( bSupportsCategories )
405 aParam.realloc( 1 );
406 aParam[0] = beans::PropertyValue( "HasCategories", -1, uno::makeAny( true ),
407 beans::PropertyState_DIRECT_VALUE );
410 Reference< chart2::XDiagram > xDiagram( xTemplate->createDiagramByDataSource( xDataSource, aParam ) );
412 setFirstDiagram( xDiagram );
414 bool bIsRTL = AllSettings::GetMathLayoutRTL();
415 //reverse x axis for rtl charts
416 if( bIsRTL )
417 AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) );
419 // create and attach legend
420 Reference< chart2::XLegend > xLegend(
421 m_xContext->getServiceManager()->createInstanceWithContext(
422 "com.sun.star.chart2.Legend", m_xContext ), uno::UNO_QUERY_THROW );
423 Reference< beans::XPropertySet > xLegendProperties( xLegend, uno::UNO_QUERY );
424 if( xLegendProperties.is() )
426 xLegendProperties->setPropertyValue( "FillStyle", uno::makeAny( drawing::FillStyle_NONE ));
427 xLegendProperties->setPropertyValue( "LineStyle", uno::makeAny( drawing::LineStyle_NONE ));
428 xLegendProperties->setPropertyValue( "LineColor", uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) )); // gray30
429 xLegendProperties->setPropertyValue( "FillColor", uno::makeAny( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10
431 if( bIsRTL )
432 xLegendProperties->setPropertyValue( "AnchorPosition", uno::makeAny( chart2::LegendPosition_LINE_START ));
434 if(xDiagram.is())
435 xDiagram->setLegend( xLegend );
437 // set simple 3D look
438 Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY );
439 if( xDiagramProperties.is() )
441 xDiagramProperties->setPropertyValue( "RightAngledAxes", uno::makeAny( sal_True ));
442 xDiagramProperties->setPropertyValue( "D3DScenePerspective", uno::makeAny( drawing::ProjectionMode_PARALLEL ));
443 ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
446 //set some new 'defaults' for wall and floor
447 if( xDiagram.is() )
449 Reference< beans::XPropertySet > xWall( xDiagram->getWall() );
450 if( xWall.is() )
452 xWall->setPropertyValue( "LineStyle", uno::makeAny( drawing::LineStyle_SOLID ) );
453 xWall->setPropertyValue( "FillStyle", uno::makeAny( drawing::FillStyle_NONE ) );
454 xWall->setPropertyValue( "LineColor", uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30
455 xWall->setPropertyValue( "FillColor", uno::makeAny( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10
457 Reference< beans::XPropertySet > xFloor( xDiagram->getFloor() );
458 if( xFloor.is() )
460 xFloor->setPropertyValue( "LineStyle", uno::makeAny( drawing::LineStyle_NONE ) );
461 xFloor->setPropertyValue( "FillStyle", uno::makeAny( drawing::FillStyle_SOLID ) );
462 xFloor->setPropertyValue( "LineColor", uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30
463 xFloor->setPropertyValue( "FillColor", uno::makeAny( static_cast< sal_Int32 >( 0xcccccc ) ) ); // gray20
468 catch( const uno::Exception & ex )
470 ASSERT_EXCEPTION( ex );
473 ChartModelHelper::setIncludeHiddenCells( false, *this );
475 catch( const uno::Exception & ex )
477 ASSERT_EXCEPTION( ex );
479 setModified( sal_False );
480 unlockControllers();
483 // frame::XLoadable
484 void SAL_CALL ChartModel::initNew()
485 throw (frame::DoubleInitializationException,
486 io::IOException,
487 uno::Exception,
488 uno::RuntimeException, std::exception)
492 void SAL_CALL ChartModel::load(
493 const Sequence< beans::PropertyValue >& rMediaDescriptor )
494 throw (frame::DoubleInitializationException,
495 io::IOException,
496 uno::Exception,
497 uno::RuntimeException, std::exception)
499 Reference< embed::XStorage > xStorage;
500 OUString aURL;
503 apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor );
504 if( aMDHelper.ISSET_Storage )
506 xStorage = aMDHelper.Storage;
508 else if( aMDHelper.ISSET_Stream ||
509 aMDHelper.ISSET_InputStream )
511 if( aMDHelper.ISSET_FilterName &&
512 (aMDHelper.FilterName == "StarChart 5.0" ||
513 aMDHelper.FilterName == "StarChart 4.0" ||
514 aMDHelper.FilterName == "StarChart 3.0" ))
516 attachResource( aMDHelper.URL, rMediaDescriptor );
517 impl_load( rMediaDescriptor, 0 ); // cannot create a storage from binary streams, but I do not need the storage here anyhow
518 m_bReadOnly = true;
519 return;
522 Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create(m_xContext) );
524 if( aMDHelper.ISSET_Stream )
526 // convert XStream to XStorage via the storage factory
527 Sequence< uno::Any > aStorageArgs( 2 );
528 aStorageArgs[0] <<= aMDHelper.Stream;
529 // todo: check if stream is read-only
530 aStorageArgs[1] <<= (embed::ElementModes::READ); //WRITE | embed::ElementModes::NOCREATE);
532 xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ),
533 uno::UNO_QUERY_THROW );
535 else
537 OSL_ASSERT( aMDHelper.ISSET_InputStream );
538 // convert XInputStream to XStorage via the storage factory
539 Sequence< uno::Any > aStorageArgs( 2 );
540 aStorageArgs[0] <<= aMDHelper.InputStream;
541 aStorageArgs[1] <<= (embed::ElementModes::READ);
543 xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ),
544 uno::UNO_QUERY_THROW );
548 if( aMDHelper.ISSET_URL )
549 aURL = aMDHelper.URL;
551 catch( const uno::Exception & ex )
553 ASSERT_EXCEPTION( ex );
556 if( xStorage.is())
558 attachResource( aURL, rMediaDescriptor );
559 impl_load( rMediaDescriptor, xStorage );
563 void ChartModel::impl_load(
564 const Sequence< beans::PropertyValue >& rMediaDescriptor,
565 const Reference< embed::XStorage >& xStorage )
568 MutexGuard aGuard( m_aModelMutex );
569 m_nInLoad++;
572 Reference< document::XFilter > xFilter( impl_createFilter( rMediaDescriptor ));
574 if( xFilter.is())
576 Reference< document::XImporter > xImporter( xFilter, uno::UNO_QUERY_THROW );
577 xImporter->setTargetDocument( this );
578 Sequence< beans::PropertyValue > aMD( rMediaDescriptor );
579 lcl_addStorageToMediaDescriptor( aMD, xStorage );
581 xFilter->filter( aMD );
582 xFilter.clear();
584 else
586 OSL_FAIL( "loadFromStorage cannot create filter" );
589 if( xStorage.is() )
590 impl_loadGraphics( xStorage );
592 setModified( sal_False );
594 // switchToStorage without notifying listeners (which shouldn't exist at
595 // this time, anyway)
596 m_xStorage = xStorage;
599 MutexGuard aGuard( m_aModelMutex );
600 m_nInLoad--;
604 void ChartModel::impl_loadGraphics(
605 const Reference< embed::XStorage >& xStorage )
609 const Reference< embed::XStorage >& xGraphicsStorage(
610 xStorage->openStorageElement( "Pictures",
611 embed::ElementModes::READ ) );
613 if( xGraphicsStorage.is() )
615 const uno::Sequence< OUString > aElementNames(
616 xGraphicsStorage->getElementNames() );
618 for( int i = 0; i < aElementNames.getLength(); ++i )
620 if( xGraphicsStorage->isStreamElement( aElementNames[ i ] ) )
622 uno::Reference< io::XStream > xElementStream(
623 xGraphicsStorage->openStreamElement(
624 aElementNames[ i ],
625 embed::ElementModes::READ ) );
627 if( xElementStream.is() )
629 boost::scoped_ptr< SvStream > apIStm(
630 ::utl::UcbStreamHelper::CreateStream(
631 xElementStream, true ) );
633 if( apIStm.get() )
635 Graphic aGraphic;
637 if( !GraphicConverter::Import(
638 *apIStm.get(),
639 aGraphic ) )
641 m_aGraphicObjectVector.push_back( aGraphic );
649 catch ( const uno::Exception& )
654 // util::XModifiable
655 void SAL_CALL ChartModel::impl_notifyModifiedListeners()
656 throw( uno::RuntimeException)
659 MutexGuard aGuard( m_aModelMutex );
660 m_bUpdateNotificationsPending = false;
663 //always notify the view first!
664 ChartViewHelper::setViewToDirtyState( this );
666 ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer
667 .getContainer( cppu::UnoType<util::XModifyListener>::get());
668 if( pIC )
670 lang::EventObject aEvent( static_cast< lang::XComponent*>(this) );
671 ::cppu::OInterfaceIteratorHelper aIt( *pIC );
672 while( aIt.hasMoreElements() )
674 uno::Reference< util::XModifyListener > xListener( aIt.next(), uno::UNO_QUERY );
675 if( xListener.is() )
676 xListener->modified( aEvent );
681 sal_Bool SAL_CALL ChartModel::isModified()
682 throw(uno::RuntimeException, std::exception)
684 //@todo guard
685 return m_bModified;
688 void SAL_CALL ChartModel::setModified( sal_Bool bModified )
689 throw(beans::PropertyVetoException,
690 uno::RuntimeException, std::exception)
692 apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager);
693 if(!aGuard.startApiCall())//@todo ? is this a long lasting call??
694 return; //behave passive if already disposed or closed or throw exception @todo?
695 m_bModified = bModified;
697 if( m_nControllerLockCount > 0 )
699 m_bUpdateNotificationsPending = true;
700 return;//don't call listeners if controllers are locked
702 aGuard.clear();
704 if(bModified)
705 impl_notifyModifiedListeners();
708 // util::XModifyBroadcaster (base of XModifiable)
709 void SAL_CALL ChartModel::addModifyListener(
710 const uno::Reference< util::XModifyListener >& xListener )
711 throw(uno::RuntimeException, std::exception)
713 if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
714 return; //behave passive if already disposed or closed
716 m_aLifeTimeManager.m_aListenerContainer.addInterface(
717 cppu::UnoType<util::XModifyListener>::get(), xListener );
720 void SAL_CALL ChartModel::removeModifyListener(
721 const uno::Reference< util::XModifyListener >& xListener )
722 throw(uno::RuntimeException, std::exception)
724 if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
725 return; //behave passive if already disposed or closed
727 m_aLifeTimeManager.m_aListenerContainer.removeInterface(
728 cppu::UnoType<util::XModifyListener>::get(), xListener );
731 // util::XModifyListener
732 void SAL_CALL ChartModel::modified( const lang::EventObject& )
733 throw (uno::RuntimeException, std::exception)
735 if( m_nInLoad == 0 )
736 setModified( sal_True );
739 // lang::XEventListener (base of util::XModifyListener)
740 void SAL_CALL ChartModel::disposing( const lang::EventObject& )
741 throw (uno::RuntimeException, std::exception)
743 // child was disposed -- should not happen from outside
746 // document::XStorageBasedDocument
747 void SAL_CALL ChartModel::loadFromStorage(
748 const Reference< embed::XStorage >& xStorage,
749 const Sequence< beans::PropertyValue >& rMediaDescriptor )
750 throw (lang::IllegalArgumentException,
751 frame::DoubleInitializationException,
752 io::IOException,
753 uno::Exception,
754 uno::RuntimeException, std::exception)
756 attachResource( OUString(), rMediaDescriptor );
757 impl_load( rMediaDescriptor, xStorage );
760 void SAL_CALL ChartModel::storeToStorage(
761 const Reference< embed::XStorage >& xStorage,
762 const Sequence< beans::PropertyValue >& rMediaDescriptor )
763 throw (lang::IllegalArgumentException,
764 io::IOException,
765 uno::Exception,
766 uno::RuntimeException, std::exception)
768 impl_store( rMediaDescriptor, xStorage );
771 void SAL_CALL ChartModel::switchToStorage( const Reference< embed::XStorage >& xStorage )
772 throw (lang::IllegalArgumentException,
773 io::IOException,
774 uno::Exception,
775 uno::RuntimeException, std::exception)
777 m_xStorage = xStorage;
778 impl_notifyStorageChangeListeners();
781 Reference< embed::XStorage > SAL_CALL ChartModel::getDocumentStorage()
782 throw (io::IOException,
783 uno::Exception,
784 uno::RuntimeException, std::exception)
786 return m_xStorage;
789 void SAL_CALL ChartModel::impl_notifyStorageChangeListeners()
790 throw( uno::RuntimeException)
792 ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer
793 .getContainer( cppu::UnoType<document::XStorageChangeListener>::get());
794 if( pIC )
796 ::cppu::OInterfaceIteratorHelper aIt( *pIC );
797 while( aIt.hasMoreElements() )
799 uno::Reference< document::XStorageChangeListener > xListener( aIt.next(), uno::UNO_QUERY );
800 if( xListener.is() )
801 xListener->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( this ), m_xStorage );
806 void SAL_CALL ChartModel::addStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener )
807 throw (uno::RuntimeException, std::exception)
809 if( m_aLifeTimeManager.impl_isDisposedOrClosed() )
810 return; //behave passive if already disposed or closed
812 m_aLifeTimeManager.m_aListenerContainer.addInterface(
813 cppu::UnoType<document::XStorageChangeListener>::get(), xListener );
816 void SAL_CALL ChartModel::removeStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener )
817 throw (uno::RuntimeException, std::exception)
819 if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) )
820 return; //behave passive if already disposed or closed
822 m_aLifeTimeManager.m_aListenerContainer.removeInterface(
823 cppu::UnoType<document::XStorageChangeListener>::get(), xListener );
826 } // namespace chart
828 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */