1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svtools/insdlg.hxx>
21 #include <svtools/strings.hrc>
22 #include <svtools/svtresid.hxx>
24 #include <unotools/configmgr.hxx>
25 #include <comphelper/classids.hxx>
26 #include <sot/stg.hxx>
27 #include <sal/macros.h>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/configuration/theDefaultProvider.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/propertysequence.hxx>
33 #include <com/sun/star/container/XNameAccess.hpp>
44 using namespace ::com::sun::star
;
46 // this struct conforms to the Microsoft
47 // OBJECTDESCRIPTOR -> see oleidl.h
52 struct OleObjectDescriptor
56 sal_uInt32 dwDrawAspect
;
60 sal_uInt32 dwFullUserTypeName
;
61 sal_uInt32 dwSrcOfCopy
;
65 static_assert(sizeof(OleObjectDescriptor
) == sizeof(OBJECTDESCRIPTOR
));
66 // check the two fields that we use here
67 static_assert(offsetof(OleObjectDescriptor
, dwFullUserTypeName
)
68 == offsetof(OBJECTDESCRIPTOR
, dwFullUserTypeName
));
69 static_assert(offsetof(OleObjectDescriptor
, dwSrcOfCopy
)
70 == offsetof(OBJECTDESCRIPTOR
, dwSrcOfCopy
));
75 /********************** SvObjectServerList ********************************
76 **************************************************************************/
78 const SvObjectServer
* SvObjectServerList::Get( std::u16string_view rHumanName
) const
80 for(const auto & i
: aObjectServerList
)
82 if( rHumanName
== i
.GetHumanName() )
88 const SvObjectServer
* SvObjectServerList::Get( const SvGlobalName
& rName
) const
90 for(const auto & i
: aObjectServerList
)
92 if( rName
== i
.GetClassName() )
98 void SvObjectServerList::Remove( const SvGlobalName
& rName
)
100 aObjectServerList
.erase(std::remove_if(aObjectServerList
.begin(), aObjectServerList
.end(),
101 [rName
](const SvObjectServer
& rServer
) { return rServer
.GetClassName() == rName
; }),
102 aObjectServerList
.end());
106 void SvObjectServerList::FillInsertObjects()
109 The list is filled with all types which can be selected in the insert-dialog.
113 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
115 uno::Reference
< lang::XMultiServiceFactory
> sProviderMSFactory
=
116 configuration::theDefaultProvider::get(xContext
);
118 uno::Sequence
<uno::Any
> aArguments(comphelper::InitAnyPropertySequence(
120 {"nodepath", uno::Any(OUString( "/org.openoffice.Office.Embedding/ObjectNames" ))}
122 uno::Reference
< container::XNameAccess
> xNameAccess(
123 sProviderMSFactory
->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArguments
),
126 if( xNameAccess
.is())
128 const uno::Sequence
< OUString
> seqNames
= xNameAccess
->getElementNames();
130 for( const auto& rName
: seqNames
)
132 uno::Reference
< container::XNameAccess
> xEntry
;
133 xNameAccess
->getByName( rName
) >>= xEntry
;
138 xEntry
->getByName("ObjectUIName") >>= aUIName
;
139 xEntry
->getByName("ClassID") >>= aClassID
;
141 if ( !aUIName
.isEmpty() )
143 aUIName
= aUIName
.replaceAll("%PRODUCTNAME", utl::ConfigManager::getProductName());
144 aUIName
= aUIName
.replaceAll("%PRODUCTVERSION", utl::ConfigManager::getProductVersion());
147 SvGlobalName aClassName
;
148 if( aClassName
.MakeId( aClassID
) )
150 if( !Get( aClassName
) )
152 aObjectServerList
.emplace_back( aClassName
, aUIName
);
160 SvGlobalName
aOleFact( SO3_OUT_CLASSID
);
161 OUString
aOleObj( SvtResId( STR_FURTHER_OBJECT
) );
162 aObjectServerList
.push_back( SvObjectServer( aOleFact
, aOleObj
) );
165 }catch(const container::NoSuchElementException
&)
167 }catch(const uno::Exception
&)
175 OUString
SvPasteObjectHelper::GetSotFormatUIName( SotClipboardFormatId nId
)
177 struct SotResourcePair
179 SotClipboardFormatId mnSotId
;
183 static const SotResourcePair aSotResourcePairs
[] =
185 { SotClipboardFormatId::STRING
, STR_FORMAT_STRING
},
186 { SotClipboardFormatId::BITMAP
, STR_FORMAT_BITMAP
},
187 { SotClipboardFormatId::GDIMETAFILE
, STR_FORMAT_GDIMETAFILE
},
188 { SotClipboardFormatId::RTF
, STR_FORMAT_RTF
},
189 { SotClipboardFormatId::DRAWING
, STR_FORMAT_ID_DRAWING
},
190 { SotClipboardFormatId::SVXB
, STR_FORMAT_ID_SVXB
},
191 { SotClipboardFormatId::INTERNALLINK_STATE
, STR_FORMAT_ID_INTERNALLINK_STATE
},
192 { SotClipboardFormatId::SOLK
, STR_FORMAT_ID_SOLK
},
193 { SotClipboardFormatId::NETSCAPE_BOOKMARK
, STR_FORMAT_ID_NETSCAPE_BOOKMARK
},
194 { SotClipboardFormatId::STARSERVER
, STR_FORMAT_ID_STARSERVER
},
195 { SotClipboardFormatId::STAROBJECT
, STR_FORMAT_ID_STAROBJECT
},
196 { SotClipboardFormatId::APPLETOBJECT
, STR_FORMAT_ID_APPLETOBJECT
},
197 { SotClipboardFormatId::PLUGIN_OBJECT
, STR_FORMAT_ID_PLUGIN_OBJECT
},
198 { SotClipboardFormatId::STARWRITER_30
, STR_FORMAT_ID_STARWRITER_30
},
199 { SotClipboardFormatId::STARWRITER_40
, STR_FORMAT_ID_STARWRITER_40
},
200 { SotClipboardFormatId::STARWRITER_50
, STR_FORMAT_ID_STARWRITER_50
},
201 { SotClipboardFormatId::STARWRITERWEB_40
, STR_FORMAT_ID_STARWRITERWEB_40
},
202 { SotClipboardFormatId::STARWRITERWEB_50
, STR_FORMAT_ID_STARWRITERWEB_50
},
203 { SotClipboardFormatId::STARWRITERGLOB_40
, STR_FORMAT_ID_STARWRITERGLOB_40
},
204 { SotClipboardFormatId::STARWRITERGLOB_50
, STR_FORMAT_ID_STARWRITERGLOB_50
},
205 { SotClipboardFormatId::STARDRAW
, STR_FORMAT_ID_STARDRAW
},
206 { SotClipboardFormatId::STARDRAW_40
, STR_FORMAT_ID_STARDRAW_40
},
207 { SotClipboardFormatId::STARIMPRESS_50
, STR_FORMAT_ID_STARIMPRESS_50
},
208 { SotClipboardFormatId::STARDRAW_50
, STR_FORMAT_ID_STARDRAW_50
},
209 { SotClipboardFormatId::STARCALC
, STR_FORMAT_ID_STARCALC
},
210 { SotClipboardFormatId::STARCALC_40
, STR_FORMAT_ID_STARCALC_40
},
211 { SotClipboardFormatId::STARCALC_50
, STR_FORMAT_ID_STARCALC_50
},
212 { SotClipboardFormatId::STARCHART
, STR_FORMAT_ID_STARCHART
},
213 { SotClipboardFormatId::STARCHART_40
, STR_FORMAT_ID_STARCHART_40
},
214 { SotClipboardFormatId::STARCHART_50
, STR_FORMAT_ID_STARCHART_50
},
215 { SotClipboardFormatId::STARIMAGE
, STR_FORMAT_ID_STARIMAGE
},
216 { SotClipboardFormatId::STARIMAGE_40
, STR_FORMAT_ID_STARIMAGE_40
},
217 { SotClipboardFormatId::STARIMAGE_50
, STR_FORMAT_ID_STARIMAGE_50
},
218 { SotClipboardFormatId::STARMATH
, STR_FORMAT_ID_STARMATH
},
219 { SotClipboardFormatId::STARMATH_40
, STR_FORMAT_ID_STARMATH_40
},
220 { SotClipboardFormatId::STARMATH_50
, STR_FORMAT_ID_STARMATH_50
},
221 { SotClipboardFormatId::STAROBJECT_PAINTDOC
, STR_FORMAT_ID_STAROBJECT_PAINTDOC
},
222 { SotClipboardFormatId::HTML
, STR_FORMAT_ID_HTML
},
223 { SotClipboardFormatId::HTML_SIMPLE
, STR_FORMAT_ID_HTML_SIMPLE
},
224 { SotClipboardFormatId::BIFF_5
, STR_FORMAT_ID_BIFF_5
},
225 { SotClipboardFormatId::BIFF_8
, STR_FORMAT_ID_BIFF_8
},
226 { SotClipboardFormatId::SYLK
, STR_FORMAT_ID_SYLK
},
227 { SotClipboardFormatId::LINK
, STR_FORMAT_ID_LINK
},
228 { SotClipboardFormatId::DIF
, STR_FORMAT_ID_DIF
},
229 { SotClipboardFormatId::MSWORD_DOC
, STR_FORMAT_ID_MSWORD_DOC
},
230 { SotClipboardFormatId::STAR_FRAMESET_DOC
, STR_FORMAT_ID_STAR_FRAMESET_DOC
},
231 { SotClipboardFormatId::OFFICE_DOC
, STR_FORMAT_ID_OFFICE_DOC
},
232 { SotClipboardFormatId::NOTES_DOCINFO
, STR_FORMAT_ID_NOTES_DOCINFO
},
233 { SotClipboardFormatId::SFX_DOC
, STR_FORMAT_ID_SFX_DOC
},
234 { SotClipboardFormatId::STARCHARTDOCUMENT_50
,STR_FORMAT_ID_STARCHARTDOCUMENT_50
},
235 { SotClipboardFormatId::GRAPHOBJ
, STR_FORMAT_ID_GRAPHOBJ
},
236 { SotClipboardFormatId::STARWRITER_60
, STR_FORMAT_ID_STARWRITER_60
},
237 { SotClipboardFormatId::STARWRITERWEB_60
, STR_FORMAT_ID_STARWRITERWEB_60
},
238 { SotClipboardFormatId::STARWRITERGLOB_60
, STR_FORMAT_ID_STARWRITERGLOB_60
},
239 { SotClipboardFormatId::STARDRAW_60
, STR_FORMAT_ID_STARDRAW_60
},
240 { SotClipboardFormatId::STARIMPRESS_60
, STR_FORMAT_ID_STARIMPRESS_60
},
241 { SotClipboardFormatId::STARCALC_60
, STR_FORMAT_ID_STARCALC_60
},
242 { SotClipboardFormatId::STARCHART_60
, STR_FORMAT_ID_STARCHART_60
},
243 { SotClipboardFormatId::STARMATH_60
, STR_FORMAT_ID_STARMATH_60
},
244 { SotClipboardFormatId::WMF
, STR_FORMAT_ID_WMF
},
245 { SotClipboardFormatId::DBACCESS_QUERY
, STR_FORMAT_ID_DBACCESS_QUERY
},
246 { SotClipboardFormatId::DBACCESS_TABLE
, STR_FORMAT_ID_DBACCESS_TABLE
},
247 { SotClipboardFormatId::DBACCESS_COMMAND
, STR_FORMAT_ID_DBACCESS_COMMAND
},
248 { SotClipboardFormatId::DIALOG_60
, STR_FORMAT_ID_DIALOG_60
},
249 { SotClipboardFormatId::FILEGRPDESCRIPTOR
, STR_FORMAT_ID_FILEGRPDESCRIPTOR
},
250 { SotClipboardFormatId::HTML_NO_COMMENT
, STR_FORMAT_ID_HTML_NO_COMMENT
},
251 { SotClipboardFormatId::RICHTEXT
, STR_FORMAT_ID_RICHTEXT
},
252 { SotClipboardFormatId::STRING_TSVC
, STR_FORMAT_ID_STRING_TSVC
},
253 { SotClipboardFormatId::PNG
, STR_FORMAT_ID_PNG_BITMAP
},
258 sal_uInt32
const nCount
= SAL_N_ELEMENTS( aSotResourcePairs
);
259 for (sal_uInt32 i
= 0; ( i
< nCount
) && !pResId
; ++i
)
261 if( aSotResourcePairs
[ i
].mnSotId
== nId
)
262 pResId
= aSotResourcePairs
[ i
].mpResId
;
267 aUIName
= SvtResId(pResId
);
269 aUIName
= SotExchange::GetFormatName( nId
);
274 bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper
& rData
, OUString
& _rName
, OUString
& _rSource
, SotClipboardFormatId
const & _nFormat
)
276 if( _nFormat
!= SotClipboardFormatId::EMBED_SOURCE_OLE
&& _nFormat
!= SotClipboardFormatId::EMBEDDED_OBJ_OLE
)
279 datatransfer::DataFlavor aFlavor
;
280 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE
, aFlavor
);
282 if( !rData
.HasFormat( aFlavor
) )
285 uno::Any aAny
= rData
.GetAny(aFlavor
, OUString());
286 if (!aAny
.hasValue())
289 uno::Sequence
< sal_Int8
> anySequence
;
290 aAny
>>= anySequence
;
292 OleObjectDescriptor
* pOleObjDescr
=
293 reinterpret_cast< OleObjectDescriptor
* >( anySequence
.getArray( ) );
295 // determine the user friendly description of the embedded object
296 if ( pOleObjDescr
->dwFullUserTypeName
)
298 // we set the pointer to the start of user friendly description
299 // string. it starts at &OleObjectDescriptor + dwFullUserTypeName.
300 // dwFullUserTypeName is the offset in bytes.
301 // the user friendly description string is '\0' terminated.
302 const sal_Unicode
* pUserTypeName
=
303 reinterpret_cast< sal_Unicode
* >(
304 reinterpret_cast< char* >( pOleObjDescr
) +
305 pOleObjDescr
->dwFullUserTypeName
);
307 _rName
+= pUserTypeName
;
308 // the following statement was here for historical reasons, it is commented out since it causes bug i49460
309 // _nFormat = SotClipboardFormatId::EMBED_SOURCE_OLE;
312 // determine the source of the embedded object
313 if ( pOleObjDescr
->dwSrcOfCopy
)
315 // we set the pointer to the start of source string
316 // it starts at &OleObjectDescriptor + dwSrcOfCopy.
317 // dwSrcOfCopy is the offset in bytes.
318 // the source string is '\0' terminated.
319 const sal_Unicode
* pSrcOfCopy
=
320 reinterpret_cast< sal_Unicode
* >(
321 reinterpret_cast< char* >( pOleObjDescr
) +
322 pOleObjDescr
->dwSrcOfCopy
);
324 _rSource
+= pSrcOfCopy
;
327 _rSource
= SvtResId(STR_UNKNOWN_SOURCE
);
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */