Update ooo320-m1
[ooovba.git] / chart2 / source / model / main / InternalData.cxx
blobca18b4e07445457797926463e428010331b4540a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: InternalData.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "InternalData.hxx"
35 #include "macros.hxx"
36 #include <com/sun/star/embed/XEmbedPersist.hpp>
37 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
38 #include <com/sun/star/chart2/data/XDataProvider.hpp>
39 #include <com/sun/star/util/XCloseable.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #include <sot/clsids.hxx>
44 using namespace ::com::sun::star;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Sequence;
48 using ::rtl::OUString;
50 namespace
52 /** convert a class-id macro into a byte-sequence
53 call e.g. lcl_GetSequenceClassID( SO3_SC_CLASSID_60 )
55 Sequence< sal_Int8 > lcl_GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3,
56 sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11,
57 sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 )
59 Sequence< sal_Int8 > aResult( 16 );
60 aResult[0] = static_cast<sal_Int8>(n1 >> 24);
61 aResult[1] = static_cast<sal_Int8>(( n1 << 8 ) >> 24);
62 aResult[2] = static_cast<sal_Int8>(( n1 << 16 ) >> 24);
63 aResult[3] = static_cast<sal_Int8>(( n1 << 24 ) >> 24);
64 aResult[4] = n2 >> 8;
65 aResult[5] = ( n2 << 8 ) >> 8;
66 aResult[6] = n3 >> 8;
67 aResult[7] = ( n3 << 8 ) >> 8;
68 aResult[8] = b8;
69 aResult[9] = b9;
70 aResult[10] = b10;
71 aResult[11] = b11;
72 aResult[12] = b12;
73 aResult[13] = b13;
74 aResult[14] = b14;
75 aResult[15] = b15;
77 return aResult;
80 Reference< embed::XStorage > lcl_CreateTempStorage(
81 const Reference< lang::XMultiServiceFactory > & rFactory )
83 Reference< embed::XStorage > xResult;
85 try
87 Reference< lang::XSingleServiceFactory > xStorageFact(
88 rFactory->createInstance( C2U( "com.sun.star.embed.StorageFactory" )),
89 uno::UNO_QUERY_THROW );
90 xResult.set( xStorageFact->createInstance(), uno::UNO_QUERY_THROW );
92 catch( uno::Exception & ex )
94 ASSERT_EXCEPTION( ex );
97 return xResult;
100 } // anonymous namespace
104 namespace chart
107 //explicit
108 InternalData::InternalData(
109 const Reference< uno::XComponentContext > & xContext,
110 const Reference< embed::XStorage > & xParentStorage ) :
111 m_aDataStorageName( RTL_CONSTASCII_USTRINGPARAM("ChartData")),
112 m_xContext( xContext ),
113 m_xParentStorage( xParentStorage )
116 InternalData::~InternalData()
120 void SAL_CALL InternalData::saveObject()
121 throw (embed::ObjectSaveVetoException,
122 uno::Exception,
123 uno::RuntimeException)
125 if( m_xInternalData.is())
129 Reference< embed::XEmbedPersist > xPersist( m_xInternalData, uno::UNO_QUERY_THROW );
130 xPersist->storeOwn();
132 catch( uno::Exception & ex )
134 ASSERT_EXCEPTION( ex );
139 void SAL_CALL InternalData::visibilityChanged( sal_Bool bVisible )
140 throw (embed::WrongStateException,
141 uno::RuntimeException)
143 // ignore (this is for swapping OLE objects?)
146 Reference< util::XCloseable > SAL_CALL InternalData::getComponent()
147 throw (uno::RuntimeException)
149 return Reference< util::XCloseable >( m_xInternalData, uno::UNO_QUERY );
152 // ____ XCloseListener ____
153 void SAL_CALL InternalData::queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership )
154 throw (util::CloseVetoException,
155 uno::RuntimeException)
157 // empty
160 void SAL_CALL InternalData::notifyClosing( const lang::EventObject& Source )
161 throw (uno::RuntimeException)
165 Reference< util::XCloseable > xCloseable( m_xInternalData, uno::UNO_QUERY );
166 if( xCloseable.is())
167 xCloseable->close( /* DeliverOwnership */ sal_False );
169 Reference< lang::XComponent > xComp( m_xInternalData, uno::UNO_QUERY );
170 if( xComp.is())
171 xComp->dispose();
172 m_xInternalData = 0;
174 catch( const util::CloseVetoException & )
176 throw;
178 catch( const uno::Exception & ex )
180 ASSERT_EXCEPTION( ex );
184 // ____ XEventListener ____
185 void SAL_CALL InternalData::disposing(
186 const lang::EventObject& Source )
187 throw (uno::RuntimeException)
189 // empty
192 Reference< chart2::data::XDataProvider > InternalData::createEmbeddedObject() throw()
194 OSL_ASSERT( m_xContext.is());
195 Reference< chart2::data::XDataProvider > xResult;
199 if( ! m_xInternalData.is() && m_xContext.is())
201 Reference< lang::XMultiServiceFactory > xFactory(
202 m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
203 Reference< embed::XEmbedObjectCreator > xCreator(
204 xFactory->createInstance(
205 C2U( "com.sun.star.embed.EmbeddedObjectCreator")), uno::UNO_QUERY_THROW );
207 Reference< embed::XStorage > xStorage( m_xParentStorage );
208 if( !xStorage.is())
210 // as we don't store the spreadsheet as substorage in the final
211 // document, it is ok, or maybe even better to create a
212 // temporary storage
213 // OSL_ENSURE( false, "Using temporary storage for chart data!" );
214 xStorage.set( lcl_CreateTempStorage( xFactory ));
217 m_xInternalData.set(
218 xCreator->createInstanceInitNew(
219 lcl_GetSequenceClassID( SO3_SC_CLASSID_60 ),
220 C2U( "ChartDataEditor" ),
221 xStorage,
222 m_aDataStorageName,
223 Sequence< beans::PropertyValue >() ), uno::UNO_QUERY_THROW );
225 m_xInternalData->setClientSite( this );
227 xFactory.set( m_xInternalData->getComponent(), uno::UNO_QUERY_THROW );
228 xResult.set(
229 xFactory->createInstance( C2U( "com.sun.star.chart2.data.DataProvider" )), uno::UNO_QUERY_THROW );
232 catch( uno::Exception & ex )
234 ASSERT_EXCEPTION( ex );
237 return xResult;
240 void InternalData::removeEmbeddedObject() throw()
242 if( m_xParentStorage.is())
246 m_xParentStorage->removeElement( m_aDataStorageName );
248 catch( uno::Exception & ex )
250 ASSERT_EXCEPTION( ex );
255 Reference< embed::XEmbeddedObject > InternalData::getEmbeddedObject() const throw()
257 return m_xInternalData;
260 } // namespace chart