xref: /trunk/main/embeddedobj/source/msole/xdialogcreator.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*bfd08df8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*bfd08df8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*bfd08df8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*bfd08df8SAndrew Rist  * distributed with this work for additional information
6*bfd08df8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*bfd08df8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*bfd08df8SAndrew Rist  * "License"); you may not use this file except in compliance
9*bfd08df8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*bfd08df8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*bfd08df8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*bfd08df8SAndrew Rist  * software distributed under the License is distributed on an
15*bfd08df8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*bfd08df8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*bfd08df8SAndrew Rist  * specific language governing permissions and limitations
18*bfd08df8SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*bfd08df8SAndrew Rist  *************************************************************/
21*bfd08df8SAndrew Rist 
22*bfd08df8SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
26cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
30cdf0e10cSrcweir #include <com/sun/star/datatransfer/DataFlavor.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <osl/thread.h>
35cdf0e10cSrcweir #include <osl/file.hxx>
36cdf0e10cSrcweir #include <vos/module.hxx>
37cdf0e10cSrcweir #include <comphelper/classids.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "platform.h"
40cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "xdialogcreator.hxx"
43cdf0e10cSrcweir #include "oleembobj.hxx"
44cdf0e10cSrcweir // LLA: tip from FS
45cdf0e10cSrcweir // #include <confighelper.hxx>
46cdf0e10cSrcweir #include <xdialogcreator.hxx>
47cdf0e10cSrcweir #include <oleembobj.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #ifdef WNT
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include <oledlg.h>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class InitializedOleGuard
55cdf0e10cSrcweir {
56cdf0e10cSrcweir public:
InitializedOleGuard()57cdf0e10cSrcweir     InitializedOleGuard()
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         if ( !SUCCEEDED( OleInitialize( NULL ) ) )
60cdf0e10cSrcweir             throw ::com::sun::star::uno::RuntimeException();
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir 
~InitializedOleGuard()63cdf0e10cSrcweir     ~InitializedOleGuard()
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         OleUninitialize();
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir extern "C" {
70cdf0e10cSrcweir typedef UINT STDAPICALLTYPE OleUIInsertObjectA_Type(LPOLEUIINSERTOBJECTA);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir using namespace ::com::sun::star;
77cdf0e10cSrcweir using namespace ::comphelper;
78cdf0e10cSrcweir //-------------------------------------------------------------------------
GetRelatedInternalID_Impl(const uno::Sequence<sal_Int8> & aClassID)79cdf0e10cSrcweir uno::Sequence< sal_Int8 > GetRelatedInternalID_Impl( const uno::Sequence< sal_Int8 >& aClassID )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     // Writer
82cdf0e10cSrcweir     if ( MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SW_OLE_EMBED_CLASSID_60 ) )
83cdf0e10cSrcweir       || MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SW_OLE_EMBED_CLASSID_8 ) ) )
84cdf0e10cSrcweir         return MimeConfigurationHelper::GetSequenceClassID( SO3_SW_CLASSID_60 );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     // Calc
87cdf0e10cSrcweir     if ( MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SC_OLE_EMBED_CLASSID_60 ) )
88cdf0e10cSrcweir       || MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SC_OLE_EMBED_CLASSID_8 ) ) )
89cdf0e10cSrcweir         return MimeConfigurationHelper::GetSequenceClassID( SO3_SC_CLASSID_60 );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     // Impress
92cdf0e10cSrcweir     if ( MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SIMPRESS_OLE_EMBED_CLASSID_60 ) )
93cdf0e10cSrcweir       || MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SIMPRESS_OLE_EMBED_CLASSID_8 ) ) )
94cdf0e10cSrcweir         return MimeConfigurationHelper::GetSequenceClassID( SO3_SIMPRESS_CLASSID_60 );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     // Draw
97cdf0e10cSrcweir     if ( MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SDRAW_OLE_EMBED_CLASSID_60 ) )
98cdf0e10cSrcweir       || MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SDRAW_OLE_EMBED_CLASSID_8 ) ) )
99cdf0e10cSrcweir         return MimeConfigurationHelper::GetSequenceClassID( SO3_SDRAW_CLASSID_60 );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     // Chart
102cdf0e10cSrcweir     if ( MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SCH_OLE_EMBED_CLASSID_60 ) )
103cdf0e10cSrcweir       || MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SCH_OLE_EMBED_CLASSID_8 ) ) )
104cdf0e10cSrcweir         return MimeConfigurationHelper::GetSequenceClassID( SO3_SCH_CLASSID_60 );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     // Math
107cdf0e10cSrcweir     if ( MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SM_OLE_EMBED_CLASSID_60 ) )
108cdf0e10cSrcweir       || MimeConfigurationHelper::ClassIDsEqual( aClassID, MimeConfigurationHelper::GetSequenceClassID( SO3_SM_OLE_EMBED_CLASSID_8 ) ) )
109cdf0e10cSrcweir         return MimeConfigurationHelper::GetSequenceClassID( SO3_SM_CLASSID_60 );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     return aClassID;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticGetSupportedServiceNames()115cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL MSOLEDialogObjectCreator::impl_staticGetSupportedServiceNames()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aRet(2);
118cdf0e10cSrcweir     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.MSOLEObjectSystemCreator");
119cdf0e10cSrcweir     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.MSOLEObjectSystemCreator");
120cdf0e10cSrcweir     return aRet;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticGetImplementationName()124cdf0e10cSrcweir ::rtl::OUString SAL_CALL MSOLEDialogObjectCreator::impl_staticGetImplementationName()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.MSOLEObjectSystemCreator");
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)130cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL MSOLEDialogObjectCreator::impl_staticCreateSelfInstance(
131cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     return uno::Reference< uno::XInterface >( *new MSOLEDialogObjectCreator( xServiceManager ) );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //-------------------------------------------------------------------------
createInstanceByDialog(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> & aInObjArgs)137cdf0e10cSrcweir embed::InsertedObjectInfo SAL_CALL MSOLEDialogObjectCreator::createInstanceByDialog(
138cdf0e10cSrcweir             const uno::Reference< embed::XStorage >& xStorage,
139cdf0e10cSrcweir             const ::rtl::OUString& sEntName,
140cdf0e10cSrcweir             const uno::Sequence< beans::PropertyValue >& aInObjArgs )
141cdf0e10cSrcweir     throw ( lang::IllegalArgumentException,
142cdf0e10cSrcweir             io::IOException,
143cdf0e10cSrcweir             uno::Exception,
144cdf0e10cSrcweir             uno::RuntimeException )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     embed::InsertedObjectInfo aObjectInfo;
147cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aObjArgs( aInObjArgs );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir #ifdef WNT
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     if ( !xStorage.is() )
152cdf0e10cSrcweir         throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
153cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
154cdf0e10cSrcweir                                             1 );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     if ( !sEntName.getLength() )
157cdf0e10cSrcweir         throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
158cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
159cdf0e10cSrcweir                                             2 );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     InitializedOleGuard aGuard;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     OLEUIINSERTOBJECT io;
164cdf0e10cSrcweir     char szFile[MAX_PATH];
165cdf0e10cSrcweir     UINT uTemp;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     memset(&io, 0, sizeof(io));
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     io.cbStruct = sizeof(io);
170cdf0e10cSrcweir     io.hWndOwner = GetActiveWindow();
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     szFile[0] = 0;
173cdf0e10cSrcweir     io.lpszFile = szFile;
174cdf0e10cSrcweir     io.cchFile = MAX_PATH;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     io.dwFlags = IOF_SELECTCREATENEW | IOF_DISABLELINK;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     ::vos::OModule aOleDlgLib;
180cdf0e10cSrcweir     if( !aOleDlgLib.load( ::rtl::OUString::createFromAscii( "oledlg" ) ) )
181cdf0e10cSrcweir         throw uno::RuntimeException();
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     OleUIInsertObjectA_Type * pInsertFct = (OleUIInsertObjectA_Type *)
184cdf0e10cSrcweir                                 aOleDlgLib.getSymbol( ::rtl::OUString::createFromAscii( "OleUIInsertObjectA" ) );
185cdf0e10cSrcweir     if( !pInsertFct )
186cdf0e10cSrcweir         throw uno::RuntimeException();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     uTemp=pInsertFct(&io);
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     if ( OLEUI_OK == uTemp )
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         if (io.dwFlags & IOF_SELECTCREATENEW)
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             uno::Reference< embed::XEmbedObjectCreator > xEmbCreator(
195cdf0e10cSrcweir                         m_xFactory->createInstance(
196cdf0e10cSrcweir                                 ::rtl::OUString::createFromAscii( "com.sun.star.embed.EmbeddedObjectCreator" ) ),
197cdf0e10cSrcweir                         uno::UNO_QUERY );
198cdf0e10cSrcweir             if ( !xEmbCreator.is() )
199cdf0e10cSrcweir                 throw uno::RuntimeException();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir             uno::Sequence< sal_Int8 > aClassID = MimeConfigurationHelper::GetSequenceClassID( io.clsid.Data1,
202cdf0e10cSrcweir                                                                      io.clsid.Data2,
203cdf0e10cSrcweir                                                                      io.clsid.Data3,
204cdf0e10cSrcweir                                                                      io.clsid.Data4[0],
205cdf0e10cSrcweir                                                                      io.clsid.Data4[1],
206cdf0e10cSrcweir                                                                      io.clsid.Data4[2],
207cdf0e10cSrcweir                                                                      io.clsid.Data4[3],
208cdf0e10cSrcweir                                                                      io.clsid.Data4[4],
209cdf0e10cSrcweir                                                                      io.clsid.Data4[5],
210cdf0e10cSrcweir                                                                      io.clsid.Data4[6],
211cdf0e10cSrcweir                                                                      io.clsid.Data4[7] );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir             aClassID = GetRelatedInternalID_Impl( aClassID );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir             //TODO: retrieve ClassName
216cdf0e10cSrcweir             ::rtl::OUString aClassName;
217cdf0e10cSrcweir             aObjectInfo.Object = uno::Reference< embed::XEmbeddedObject >(
218cdf0e10cSrcweir                             xEmbCreator->createInstanceInitNew( aClassID, aClassName, xStorage, sEntName, aObjArgs ),
219cdf0e10cSrcweir                             uno::UNO_QUERY );
220cdf0e10cSrcweir         }
221cdf0e10cSrcweir         else
222cdf0e10cSrcweir         {
223cdf0e10cSrcweir             ::rtl::OUString aFileName = ::rtl::OStringToOUString( ::rtl::OString( szFile ), osl_getThreadTextEncoding() );
224cdf0e10cSrcweir             rtl::OUString aFileURL;
225cdf0e10cSrcweir             if ( osl::FileBase::getFileURLFromSystemPath( aFileName, aFileURL ) != osl::FileBase::E_None )
226cdf0e10cSrcweir                 throw uno::RuntimeException();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
229cdf0e10cSrcweir             aMediaDescr[0].Name = ::rtl::OUString::createFromAscii( "URL" );
230cdf0e10cSrcweir             aMediaDescr[0].Value <<= aFileURL;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir             // TODO: use config helper for type detection
233cdf0e10cSrcweir             uno::Reference< embed::XEmbedObjectCreator > xEmbCreator;
234cdf0e10cSrcweir             ::comphelper::MimeConfigurationHelper aHelper( m_xFactory );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir             if ( aHelper.AddFilterNameCheckOwnFile( aMediaDescr ) )
237cdf0e10cSrcweir                 xEmbCreator = uno::Reference< embed::XEmbedObjectCreator >(
238cdf0e10cSrcweir                         m_xFactory->createInstance(
239cdf0e10cSrcweir                                 ::rtl::OUString::createFromAscii( "com.sun.star.embed.EmbeddedObjectCreator" ) ),
240cdf0e10cSrcweir                         uno::UNO_QUERY );
241cdf0e10cSrcweir             else
242cdf0e10cSrcweir                 xEmbCreator = uno::Reference< embed::XEmbedObjectCreator >(
243cdf0e10cSrcweir                         m_xFactory->createInstance(
244cdf0e10cSrcweir                                 ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLEEmbeddedObjectFactory" ) ),
245cdf0e10cSrcweir                         uno::UNO_QUERY );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir             if ( !xEmbCreator.is() )
248cdf0e10cSrcweir                 throw uno::RuntimeException();
249cdf0e10cSrcweir 
250cdf0e10cSrcweir             aObjectInfo.Object = uno::Reference< embed::XEmbeddedObject >(
251cdf0e10cSrcweir                             xEmbCreator->createInstanceInitFromMediaDescriptor( xStorage, sEntName, aMediaDescr, aObjArgs ),
252cdf0e10cSrcweir                             uno::UNO_QUERY );
253cdf0e10cSrcweir         }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         if ( ( io.dwFlags & IOF_CHECKDISPLAYASICON) && io.hMetaPict != NULL )
256cdf0e10cSrcweir         {
257cdf0e10cSrcweir             METAFILEPICT* pMF = ( METAFILEPICT* )GlobalLock( io.hMetaPict );
258cdf0e10cSrcweir             if ( pMF )
259cdf0e10cSrcweir             {
260cdf0e10cSrcweir                 sal_uInt32 nBufSize = GetMetaFileBitsEx( pMF->hMF, 0, NULL );
261cdf0e10cSrcweir                 uno::Sequence< sal_Int8 > aMetafile( nBufSize + 22 );
262cdf0e10cSrcweir                 sal_uInt8* pBuf = (sal_uInt8*)( aMetafile.getArray() );
263cdf0e10cSrcweir                 *( (long* )pBuf ) = 0x9ac6cdd7L;
264cdf0e10cSrcweir                 *( (short* )( pBuf+6 )) = ( SHORT ) 0;
265cdf0e10cSrcweir                 *( (short* )( pBuf+8 )) = ( SHORT ) 0;
266cdf0e10cSrcweir                 *( (short* )( pBuf+10 )) = ( SHORT ) pMF->xExt;
267cdf0e10cSrcweir                 *( (short* )( pBuf+12 )) = ( SHORT ) pMF->yExt;
268cdf0e10cSrcweir                 *( (short* )( pBuf+14 )) = ( USHORT ) 2540;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir                 if ( nBufSize && nBufSize == GetMetaFileBitsEx( pMF->hMF, nBufSize, pBuf+22 ) )
271cdf0e10cSrcweir                 {
272cdf0e10cSrcweir                     datatransfer::DataFlavor aFlavor(
273cdf0e10cSrcweir                         ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ),
274cdf0e10cSrcweir                         ::rtl::OUString::createFromAscii( "Image WMF" ),
275cdf0e10cSrcweir                         getCppuType( ( const uno::Sequence< sal_Int8 >* ) 0 ) );
276cdf0e10cSrcweir 
277cdf0e10cSrcweir                     aObjectInfo.Options.realloc( 2 );
278cdf0e10cSrcweir                     aObjectInfo.Options[0].Name = ::rtl::OUString::createFromAscii( "Icon" );
279cdf0e10cSrcweir                     aObjectInfo.Options[0].Value <<= aMetafile;
280cdf0e10cSrcweir                     aObjectInfo.Options[1].Name = ::rtl::OUString::createFromAscii( "IconFormat" );
281cdf0e10cSrcweir                     aObjectInfo.Options[1].Value <<= aFlavor;
282cdf0e10cSrcweir                 }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir                 GlobalUnlock( io.hMetaPict );
285cdf0e10cSrcweir             }
286cdf0e10cSrcweir         }
287cdf0e10cSrcweir     }
288cdf0e10cSrcweir     else
289cdf0e10cSrcweir         throw ucb::CommandAbortedException();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir #else
292cdf0e10cSrcweir     throw lang::NoSupportException(); // TODO:
293cdf0e10cSrcweir #endif
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     OSL_ENSURE( aObjectInfo.Object.is(), "No object was created!\n" );
296cdf0e10cSrcweir     if ( !aObjectInfo.Object.is() )
297cdf0e10cSrcweir         throw uno::RuntimeException();
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     return aObjectInfo;
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir //-------------------------------------------------------------------------
createInstanceInitFromClipboard(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntryName,const uno::Sequence<beans::PropertyValue> & aObjectArgs)303cdf0e10cSrcweir embed::InsertedObjectInfo SAL_CALL MSOLEDialogObjectCreator::createInstanceInitFromClipboard(
304cdf0e10cSrcweir                 const uno::Reference< embed::XStorage >& xStorage,
305cdf0e10cSrcweir                 const ::rtl::OUString& sEntryName,
306cdf0e10cSrcweir                 const uno::Sequence< beans::PropertyValue >& aObjectArgs )
307cdf0e10cSrcweir         throw ( lang::IllegalArgumentException,
308cdf0e10cSrcweir                 io::IOException,
309cdf0e10cSrcweir                 uno::Exception,
310cdf0e10cSrcweir                 uno::RuntimeException )
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     embed::InsertedObjectInfo aObjectInfo;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir #ifdef WNT
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     if ( !xStorage.is() )
317cdf0e10cSrcweir         throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
318cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
319cdf0e10cSrcweir                                             1 );
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     if ( !sEntryName.getLength() )
322cdf0e10cSrcweir         throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
323cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
324cdf0e10cSrcweir                                             2 );
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     uno::Reference< embed::XEmbeddedObject > xResult(
327cdf0e10cSrcweir                     static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory ) ),
328cdf0e10cSrcweir                     uno::UNO_QUERY );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     if ( !xPersist.is() )
333cdf0e10cSrcweir         throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     xPersist->setPersistentEntry( xStorage,
336cdf0e10cSrcweir                                     sEntryName,
337cdf0e10cSrcweir                                     embed::EntryInitModes::DEFAULT_INIT,
338cdf0e10cSrcweir                                     uno::Sequence< beans::PropertyValue >(),
339cdf0e10cSrcweir                                     aObjectArgs );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     aObjectInfo.Object = xResult;
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     // TODO/LATER: in case of iconifie object the icon should be stored in aObjectInfo
344cdf0e10cSrcweir #else
345cdf0e10cSrcweir     throw lang::NoSupportException(); // TODO:
346cdf0e10cSrcweir #endif
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     OSL_ENSURE( aObjectInfo.Object.is(), "No object was created!\n" );
349cdf0e10cSrcweir     if ( !aObjectInfo.Object.is() )
350cdf0e10cSrcweir         throw uno::RuntimeException();
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     return aObjectInfo;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir //-------------------------------------------------------------------------
getImplementationName()356cdf0e10cSrcweir ::rtl::OUString SAL_CALL MSOLEDialogObjectCreator::getImplementationName()
357cdf0e10cSrcweir     throw ( uno::RuntimeException )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     return impl_staticGetImplementationName();
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir //-------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)363cdf0e10cSrcweir sal_Bool SAL_CALL MSOLEDialogObjectCreator::supportsService( const ::rtl::OUString& ServiceName )
364cdf0e10cSrcweir     throw ( uno::RuntimeException )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
369cdf0e10cSrcweir         if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
370cdf0e10cSrcweir             return sal_True;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     return sal_False;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir //-------------------------------------------------------------------------
getSupportedServiceNames()376cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL MSOLEDialogObjectCreator::getSupportedServiceNames()
377cdf0e10cSrcweir     throw ( uno::RuntimeException )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     return impl_staticGetSupportedServiceNames();
380cdf0e10cSrcweir }
381