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>
34 #include <officecfg/Office/Embedding.hxx>
45 using namespace ::com::sun::star
;
47 // this struct conforms to the Microsoft
48 // OBJECTDESCRIPTOR -> see oleidl.h
53 struct OleObjectDescriptor
57 sal_uInt32 dwDrawAspect
;
61 sal_uInt32 dwFullUserTypeName
;
62 sal_uInt32 dwSrcOfCopy
;
66 static_assert(sizeof(OleObjectDescriptor
) == sizeof(OBJECTDESCRIPTOR
));
67 // check the two fields that we use here
68 static_assert(offsetof(OleObjectDescriptor
, dwFullUserTypeName
)
69 == offsetof(OBJECTDESCRIPTOR
, dwFullUserTypeName
));
70 static_assert(offsetof(OleObjectDescriptor
, dwSrcOfCopy
)
71 == offsetof(OBJECTDESCRIPTOR
, dwSrcOfCopy
));
76 /********************** SvObjectServerList ********************************
77 **************************************************************************/
79 const SvObjectServer
* SvObjectServerList::Get( std::u16string_view rHumanName
) const
81 for(const auto & i
: aObjectServerList
)
83 if( rHumanName
== i
.GetHumanName() )
89 const SvObjectServer
* SvObjectServerList::Get( const SvGlobalName
& rName
) const
91 for(const auto & i
: aObjectServerList
)
93 if( rName
== i
.GetClassName() )
99 void SvObjectServerList::Remove( const SvGlobalName
& rName
)
101 std::erase_if(aObjectServerList
, [rName
](const SvObjectServer
& rServer
) { return rServer
.GetClassName() == rName
; });
105 void SvObjectServerList::FillInsertObjects()
108 The list is filled with all types which can be selected in the insert-dialog.
112 uno::Reference
< container::XNameAccess
> xNameAccess
= officecfg::Office::Embedding::ObjectNames::get();
114 const uno::Sequence
< OUString
> seqNames
= xNameAccess
->getElementNames();
116 for( const auto& rName
: seqNames
)
118 uno::Reference
< container::XNameAccess
> xEntry
;
119 xNameAccess
->getByName( rName
) >>= xEntry
;
124 xEntry
->getByName(u
"ObjectUIName"_ustr
) >>= aUIName
;
125 xEntry
->getByName(u
"ClassID"_ustr
) >>= aClassID
;
127 if ( !aUIName
.isEmpty() )
129 aUIName
= aUIName
.replaceAll("%PRODUCTNAME", utl::ConfigManager::getProductName());
130 aUIName
= aUIName
.replaceAll("%PRODUCTVERSION", utl::ConfigManager::getProductVersion());
133 SvGlobalName aClassName
;
134 if( aClassName
.MakeId( aClassID
) )
136 if( !Get( aClassName
) )
138 aObjectServerList
.emplace_back( aClassName
, aUIName
);
145 SvGlobalName
aOleFact( SO3_OUT_CLASSID
);
146 OUString
aOleObj( SvtResId( STR_FURTHER_OBJECT
) );
147 aObjectServerList
.push_back( SvObjectServer( aOleFact
, aOleObj
) );
150 }catch(const container::NoSuchElementException
&)
152 }catch(const uno::Exception
&)
160 OUString
SvPasteObjectHelper::GetSotFormatUIName( SotClipboardFormatId nId
)
162 struct SotResourcePair
164 SotClipboardFormatId mnSotId
;
168 static const SotResourcePair aSotResourcePairs
[] =
170 { SotClipboardFormatId::STRING
, STR_FORMAT_STRING
},
171 { SotClipboardFormatId::BITMAP
, STR_FORMAT_BITMAP
},
172 { SotClipboardFormatId::GDIMETAFILE
, STR_FORMAT_GDIMETAFILE
},
173 { SotClipboardFormatId::RTF
, STR_FORMAT_RTF
},
174 { SotClipboardFormatId::DRAWING
, STR_FORMAT_ID_DRAWING
},
175 { SotClipboardFormatId::SVXB
, STR_FORMAT_ID_SVXB
},
176 { SotClipboardFormatId::INTERNALLINK_STATE
, STR_FORMAT_ID_INTERNALLINK_STATE
},
177 { SotClipboardFormatId::SOLK
, STR_FORMAT_ID_SOLK
},
178 { SotClipboardFormatId::NETSCAPE_BOOKMARK
, STR_FORMAT_ID_NETSCAPE_BOOKMARK
},
179 { SotClipboardFormatId::STARSERVER
, STR_FORMAT_ID_STARSERVER
},
180 { SotClipboardFormatId::STAROBJECT
, STR_FORMAT_ID_STAROBJECT
},
181 { SotClipboardFormatId::APPLETOBJECT
, STR_FORMAT_ID_APPLETOBJECT
},
182 { SotClipboardFormatId::PLUGIN_OBJECT
, STR_FORMAT_ID_PLUGIN_OBJECT
},
183 { SotClipboardFormatId::STARWRITER_30
, STR_FORMAT_ID_STARWRITER_30
},
184 { SotClipboardFormatId::STARWRITER_40
, STR_FORMAT_ID_STARWRITER_40
},
185 { SotClipboardFormatId::STARWRITER_50
, STR_FORMAT_ID_STARWRITER_50
},
186 { SotClipboardFormatId::STARWRITERWEB_40
, STR_FORMAT_ID_STARWRITERWEB_40
},
187 { SotClipboardFormatId::STARWRITERWEB_50
, STR_FORMAT_ID_STARWRITERWEB_50
},
188 { SotClipboardFormatId::STARWRITERGLOB_40
, STR_FORMAT_ID_STARWRITERGLOB_40
},
189 { SotClipboardFormatId::STARWRITERGLOB_50
, STR_FORMAT_ID_STARWRITERGLOB_50
},
190 { SotClipboardFormatId::STARDRAW
, STR_FORMAT_ID_STARDRAW
},
191 { SotClipboardFormatId::STARDRAW_40
, STR_FORMAT_ID_STARDRAW_40
},
192 { SotClipboardFormatId::STARIMPRESS_50
, STR_FORMAT_ID_STARIMPRESS_50
},
193 { SotClipboardFormatId::STARDRAW_50
, STR_FORMAT_ID_STARDRAW_50
},
194 { SotClipboardFormatId::STARCALC
, STR_FORMAT_ID_STARCALC
},
195 { SotClipboardFormatId::STARCALC_40
, STR_FORMAT_ID_STARCALC_40
},
196 { SotClipboardFormatId::STARCALC_50
, STR_FORMAT_ID_STARCALC_50
},
197 { SotClipboardFormatId::STARCHART
, STR_FORMAT_ID_STARCHART
},
198 { SotClipboardFormatId::STARCHART_40
, STR_FORMAT_ID_STARCHART_40
},
199 { SotClipboardFormatId::STARCHART_50
, STR_FORMAT_ID_STARCHART_50
},
200 { SotClipboardFormatId::STARIMAGE
, STR_FORMAT_ID_STARIMAGE
},
201 { SotClipboardFormatId::STARIMAGE_40
, STR_FORMAT_ID_STARIMAGE_40
},
202 { SotClipboardFormatId::STARIMAGE_50
, STR_FORMAT_ID_STARIMAGE_50
},
203 { SotClipboardFormatId::STARMATH
, STR_FORMAT_ID_STARMATH
},
204 { SotClipboardFormatId::STARMATH_40
, STR_FORMAT_ID_STARMATH_40
},
205 { SotClipboardFormatId::STARMATH_50
, STR_FORMAT_ID_STARMATH_50
},
206 { SotClipboardFormatId::STAROBJECT_PAINTDOC
, STR_FORMAT_ID_STAROBJECT_PAINTDOC
},
207 { SotClipboardFormatId::HTML
, STR_FORMAT_ID_HTML
},
208 { SotClipboardFormatId::HTML_SIMPLE
, STR_FORMAT_ID_HTML_SIMPLE
},
209 { SotClipboardFormatId::BIFF_5
, STR_FORMAT_ID_BIFF_5
},
210 { SotClipboardFormatId::BIFF_8
, STR_FORMAT_ID_BIFF_8
},
211 { SotClipboardFormatId::SYLK
, STR_FORMAT_ID_SYLK
},
212 { SotClipboardFormatId::LINK
, STR_FORMAT_ID_LINK
},
213 { SotClipboardFormatId::DIF
, STR_FORMAT_ID_DIF
},
214 { SotClipboardFormatId::MSWORD_DOC
, STR_FORMAT_ID_MSWORD_DOC
},
215 { SotClipboardFormatId::STAR_FRAMESET_DOC
, STR_FORMAT_ID_STAR_FRAMESET_DOC
},
216 { SotClipboardFormatId::OFFICE_DOC
, STR_FORMAT_ID_OFFICE_DOC
},
217 { SotClipboardFormatId::NOTES_DOCINFO
, STR_FORMAT_ID_NOTES_DOCINFO
},
218 { SotClipboardFormatId::SFX_DOC
, STR_FORMAT_ID_SFX_DOC
},
219 { SotClipboardFormatId::STARCHARTDOCUMENT_50
,STR_FORMAT_ID_STARCHARTDOCUMENT_50
},
220 { SotClipboardFormatId::GRAPHOBJ
, STR_FORMAT_ID_GRAPHOBJ
},
221 { SotClipboardFormatId::STARWRITER_60
, STR_FORMAT_ID_STARWRITER_60
},
222 { SotClipboardFormatId::STARWRITERWEB_60
, STR_FORMAT_ID_STARWRITERWEB_60
},
223 { SotClipboardFormatId::STARWRITERGLOB_60
, STR_FORMAT_ID_STARWRITERGLOB_60
},
224 { SotClipboardFormatId::STARDRAW_60
, STR_FORMAT_ID_STARDRAW_60
},
225 { SotClipboardFormatId::STARIMPRESS_60
, STR_FORMAT_ID_STARIMPRESS_60
},
226 { SotClipboardFormatId::STARCALC_60
, STR_FORMAT_ID_STARCALC_60
},
227 { SotClipboardFormatId::STARCHART_60
, STR_FORMAT_ID_STARCHART_60
},
228 { SotClipboardFormatId::STARMATH_60
, STR_FORMAT_ID_STARMATH_60
},
229 { SotClipboardFormatId::WMF
, STR_FORMAT_ID_WMF
},
230 { SotClipboardFormatId::DBACCESS_QUERY
, STR_FORMAT_ID_DBACCESS_QUERY
},
231 { SotClipboardFormatId::DBACCESS_TABLE
, STR_FORMAT_ID_DBACCESS_TABLE
},
232 { SotClipboardFormatId::DBACCESS_COMMAND
, STR_FORMAT_ID_DBACCESS_COMMAND
},
233 { SotClipboardFormatId::DIALOG_60
, STR_FORMAT_ID_DIALOG_60
},
234 { SotClipboardFormatId::FILEGRPDESCRIPTOR
, STR_FORMAT_ID_FILEGRPDESCRIPTOR
},
235 { SotClipboardFormatId::HTML_NO_COMMENT
, STR_FORMAT_ID_HTML_NO_COMMENT
},
236 { SotClipboardFormatId::RICHTEXT
, STR_FORMAT_ID_RICHTEXT
},
237 { SotClipboardFormatId::STRING_TSVC
, STR_FORMAT_ID_STRING_TSVC
},
238 { SotClipboardFormatId::PNG
, STR_FORMAT_ID_PNG_BITMAP
},
243 sal_uInt32
const nCount
= SAL_N_ELEMENTS( aSotResourcePairs
);
244 for (sal_uInt32 i
= 0; ( i
< nCount
) && !pResId
; ++i
)
246 if( aSotResourcePairs
[ i
].mnSotId
== nId
)
247 pResId
= aSotResourcePairs
[ i
].mpResId
;
252 aUIName
= SvtResId(pResId
);
254 aUIName
= SotExchange::GetFormatName( nId
);
259 bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper
& rData
, OUString
& _rName
, OUString
& _rSource
, SotClipboardFormatId
const & _nFormat
)
261 if( _nFormat
!= SotClipboardFormatId::EMBED_SOURCE_OLE
&& _nFormat
!= SotClipboardFormatId::EMBEDDED_OBJ_OLE
)
264 datatransfer::DataFlavor aFlavor
;
265 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE
, aFlavor
);
267 if( !rData
.HasFormat( aFlavor
) )
270 uno::Any aAny
= rData
.GetAny(aFlavor
, OUString());
271 if (!aAny
.hasValue())
274 uno::Sequence
< sal_Int8
> anySequence
;
275 aAny
>>= anySequence
;
277 OleObjectDescriptor
* pOleObjDescr
=
278 reinterpret_cast< OleObjectDescriptor
* >( anySequence
.getArray( ) );
280 // determine the user friendly description of the embedded object
281 if ( pOleObjDescr
->dwFullUserTypeName
)
283 // we set the pointer to the start of user friendly description
284 // string. it starts at &OleObjectDescriptor + dwFullUserTypeName.
285 // dwFullUserTypeName is the offset in bytes.
286 // the user friendly description string is '\0' terminated.
287 const sal_Unicode
* pUserTypeName
=
288 reinterpret_cast< sal_Unicode
* >(
289 reinterpret_cast< char* >( pOleObjDescr
) +
290 pOleObjDescr
->dwFullUserTypeName
);
292 _rName
+= pUserTypeName
;
293 // the following statement was here for historical reasons, it is commented out since it causes bug i49460
294 // _nFormat = SotClipboardFormatId::EMBED_SOURCE_OLE;
297 // determine the source of the embedded object
298 if ( pOleObjDescr
->dwSrcOfCopy
)
300 // we set the pointer to the start of source string
301 // it starts at &OleObjectDescriptor + dwSrcOfCopy.
302 // dwSrcOfCopy is the offset in bytes.
303 // the source string is '\0' terminated.
304 const sal_Unicode
* pSrcOfCopy
=
305 reinterpret_cast< sal_Unicode
* >(
306 reinterpret_cast< char* >( pOleObjDescr
) +
307 pOleObjDescr
->dwSrcOfCopy
);
309 _rSource
+= pSrcOfCopy
;
312 _rSource
= SvtResId(STR_UNKNOWN_SOURCE
);
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */