24#include <com/sun/star/embed/EmbeddedObjectCreator.hpp>
25#include <com/sun/star/embed/XEmbeddedObject.hpp>
26#include <com/sun/star/embed/EntryInitModes.hpp>
27#include <com/sun/star/embed/OLEEmbeddedObjectFactory.hpp>
28#include <com/sun/star/beans/PropertyValue.hpp>
29#include <com/sun/star/datatransfer/DataFlavor.hpp>
30#include <com/sun/star/lang/IllegalArgumentException.hpp>
31#include <com/sun/star/ucb/CommandAbortedException.hpp>
32#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
34#include <osl/thread.h>
35#include <osl/file.hxx>
36#include <osl/module.hxx>
58class InitializedOleGuard
63 if ( !SUCCEEDED( OleInitialize(
nullptr ) ) )
64 throw css::uno::RuntimeException();
67 ~InitializedOleGuard()
76typedef UINT STDAPICALLTYPE OleUIInsertObjectA_Type(LPOLEUIINSERTOBJECTA);
122 const uno::Reference< embed::XStorage >& xStorage,
123 const OUString& sEntName,
124 const uno::Sequence< beans::PropertyValue >& aInObjArgs )
126 embed::InsertedObjectInfo aObjectInfo;
127 uno::Sequence< beans::PropertyValue > aObjArgs( aInObjArgs );
131 if ( !xStorage.is() )
132 throw lang::IllegalArgumentException(
"No parent storage is provided!",
136 if ( !sEntName.getLength() )
137 throw lang::IllegalArgumentException(
"Empty element name is provided!",
141 InitializedOleGuard aGuard;
143 OLEUIINSERTOBJECT io = {};
147 io.cbStruct =
sizeof(io);
148 io.hWndOwner = GetActiveWindow();
151 io.lpszFile = szFile;
154 io.dwFlags = IOF_SELECTCREATENEW | IOF_DISABLELINK;
157 ::osl::Module aOleDlgLib;
158 if( !aOleDlgLib.load(
"oledlg" ))
159 throw uno::RuntimeException();
161 OleUIInsertObjectA_Type * pInsertFct =
reinterpret_cast<OleUIInsertObjectA_Type *
>(
162 aOleDlgLib.getSymbol(
"OleUIInsertObjectA" ));
164 throw uno::RuntimeException();
168 WinScheduler::SetForceRealTimer();
170 uTemp=pInsertFct(&io);
172 if ( OLEUI_OK != uTemp )
173 throw ucb::CommandAbortedException();
175 if (io.dwFlags & IOF_SELECTCREATENEW)
177 uno::Reference< embed::XEmbeddedObjectCreator > xEmbCreator = embed::EmbeddedObjectCreator::create(
m_xContext );
179 uno::Sequence< sal_Int8 >
aClassID = MimeConfigurationHelper::GetSequenceClassID( io.clsid.Data1,
194 aObjectInfo.Object.set( xEmbCreator->createInstanceInitNew(
aClassID, OUString(), xStorage, sEntName, aObjArgs ),
200 = OStringToOUString( std::string_view( szFile ), osl_getThreadTextEncoding() );
202 if ( osl::FileBase::getFileURLFromSystemPath( aFileName, aFileURL ) != osl::FileBase::E_None )
203 throw uno::RuntimeException();
209 uno::Reference< embed::XEmbeddedObjectCreator > xEmbCreator;
212 if (
aHelper.AddFilterNameCheckOwnFile( aMediaDescr ) )
213 xEmbCreator = embed::EmbeddedObjectCreator::create(
m_xContext );
215 xEmbCreator = embed::OLEEmbeddedObjectFactory::create(
m_xContext );
217 if ( !xEmbCreator.is() )
218 throw uno::RuntimeException();
220 uno::Reference<task::XStatusIndicator> xProgress;
221 OUString aProgressText;
223 auto it =
aMap.find(
"StatusIndicator");
224 if (it !=
aMap.end())
226 it->second >>= xProgress;
228 it =
aMap.find(
"StatusIndicatorText");
229 if (it !=
aMap.end())
231 it->second >>= aProgressText;
235 xProgress->start(aProgressText, 100);
238 aObjectInfo.Object.set( xEmbCreator->createInstanceInitFromMediaDescriptor( xStorage, sEntName, aMediaDescr, aObjArgs ),
247 if ( ( io.dwFlags & IOF_CHECKDISPLAYASICON) && io.hMetaPict !=
nullptr )
249 METAFILEPICT* pMF =
static_cast<METAFILEPICT*
>(GlobalLock( io.hMetaPict ));
252 sal_uInt32 nBufSize = GetMetaFileBitsEx( pMF->hMF, 0,
nullptr );
253 uno::Sequence< sal_Int8 > aMetafile( nBufSize + 22 );
254 sal_Int8* pBuf = aMetafile.getArray();
255 *
reinterpret_cast<long*
>( pBuf ) = 0x9ac6cdd7L;
256 *
reinterpret_cast<short*
>( pBuf+6 ) = SHORT(0);
257 *
reinterpret_cast<short*
>( pBuf+8 ) = SHORT(0);
258 *
reinterpret_cast<short*
>( pBuf+10 ) =
static_cast<SHORT
>(pMF->xExt);
259 *
reinterpret_cast<short*
>( pBuf+12 ) =
static_cast<SHORT
>(pMF->yExt);
260 *
reinterpret_cast<short*
>( pBuf+14 ) = USHORT(2540);
262 if ( nBufSize && nBufSize == GetMetaFileBitsEx( pMF->hMF, nBufSize, pBuf+22 ) )
264 datatransfer::DataFlavor aFlavor(
265 "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"",
269 aObjectInfo.Options = { {
"Icon", css::uno::Any(aMetafile) },
270 {
"IconFormat", css::uno::Any(aFlavor) } };
273 GlobalUnlock( io.hMetaPict );
277 OSL_ENSURE( aObjectInfo.Object.is(),
"No object was created!" );
278 if ( !aObjectInfo.Object.is() )
279 throw uno::RuntimeException();
283 throw lang::NoSupportException();
289 const uno::Reference< embed::XStorage >& xStorage,
290 const OUString& sEntryName,
291 const uno::Sequence< beans::PropertyValue >& aObjectArgs )
293 embed::InsertedObjectInfo aObjectInfo;
296 if ( !xStorage.is() )
297 throw lang::IllegalArgumentException(
"No parent storage is provided!",
301 if ( !sEntryName.getLength() )
302 throw lang::IllegalArgumentException(
"Empty element name is provided!",
306 uno::Reference< embed::XEmbeddedObject > xResult(
309 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
310 xPersist->setPersistentEntry( xStorage,
312 embed::EntryInitModes::DEFAULT_INIT,
313 uno::Sequence< beans::PropertyValue >(),
316 aObjectInfo.Object = xResult;
320 OSL_ENSURE( aObjectInfo.Object.is(),
"No object was created!" );
321 if ( !aObjectInfo.Object.is() )
322 throw uno::RuntimeException();
326 throw lang::NoSupportException();
333 return "com.sun.star.comp.embed.MSOLEObjectSystemCreator";
345 return {
"com.sun.star.embed.MSOLEObjectSystemCreator",
346 "com.sun.star.comp.embed.MSOLEObjectSystemCreator" };
349extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
351 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::embed::InsertedObjectInfo SAL_CALL createInstanceInitFromClipboard(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntryName, const css::uno::Sequence< css::beans::PropertyValue > &aObjectArgs) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::embed::InsertedObjectInfo SAL_CALL createInstanceByDialog(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
Represents an OLE object that has native data and we try to let an external application handle that d...
#define SO3_SDRAW_OLE_EMBED_CLASSID_60
#define SO3_SIMPRESS_OLE_EMBED_CLASSID_60
#define SO3_SDRAW_CLASSID_60
#define SO3_SC_CLASSID_60
#define SO3_SM_CLASSID_60
#define SO3_SW_OLE_EMBED_CLASSID_8
#define SO3_SW_OLE_EMBED_CLASSID_60
#define SO3_SW_CLASSID_60
#define SO3_SCH_OLE_EMBED_CLASSID_60
#define SO3_SCH_CLASSID_60
#define SO3_SM_OLE_EMBED_CLASSID_60
#define SO3_SC_OLE_EMBED_CLASSID_60
#define SO3_SIMPRESS_CLASSID_60
#define SO3_SM_OLE_EMBED_CLASSID_8
#define SO3_SDRAW_OLE_EMBED_CLASSID_8
#define SO3_SCH_OLE_EMBED_CLASSID_8
#define SO3_SC_OLE_EMBED_CLASSID_8
#define SO3_SIMPRESS_OLE_EMBED_CLASSID_8
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
HashMap_OWString_Interface aMap
const char *const aClassID
static uno::Sequence< sal_Int8 > GetRelatedInternalID_Impl(const uno::Sequence< sal_Int8 > &aClassID)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * embeddedobj_MSOLEDialogObjectCreator_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)