LibreOffice Module svtools (master) 1
insdlg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <svtools/insdlg.hxx>
21#include <svtools/strings.hrc>
22#include <svtools/svtresid.hxx>
23
26#include <sot/stg.hxx>
27#include <sal/macros.h>
28
29#include <com/sun/star/lang/XMultiServiceFactory.hpp>
30#include <com/sun/star/configuration/theDefaultProvider.hpp>
33#include <com/sun/star/container/XNameAccess.hpp>
34
35using namespace ::com::sun::star;
36
37#if defined _WIN32
38#include <prewin.h>
39#include <oleidl.h>
40#include <postwin.h>
41#else
42typedef Size SIZEL;
43typedef Point POINTL;
44#endif
45
46// this struct conforms to the Microsoft
47// OBJECTDESCRIPTOR -> see oleidl.h
48// (MS platform sdk)
49
50namespace {
51
52struct OleObjectDescriptor
53{
54 sal_uInt32 cbSize;
55 ClsId clsid;
56 sal_uInt32 dwDrawAspect;
57 SIZEL sizel;
58 POINTL pointl;
59 sal_uInt32 dwStatus;
60 sal_uInt32 dwFullUserTypeName;
61 sal_uInt32 dwSrcOfCopy;
62};
63
64#if defined _WIN32
65static_assert(sizeof(OleObjectDescriptor) == sizeof(OBJECTDESCRIPTOR));
66// check the two fields that we use here
67static_assert(offsetof(OleObjectDescriptor, dwFullUserTypeName)
68 == offsetof(OBJECTDESCRIPTOR, dwFullUserTypeName));
69static_assert(offsetof(OleObjectDescriptor, dwSrcOfCopy)
70 == offsetof(OBJECTDESCRIPTOR, dwSrcOfCopy));
71#endif
72
73}
74
75/********************** SvObjectServerList ********************************
76**************************************************************************/
77
78const SvObjectServer * SvObjectServerList::Get( std::u16string_view rHumanName ) const
79{
80 for(const auto & i : aObjectServerList)
81 {
82 if( rHumanName == i.GetHumanName() )
83 return &i;
84 }
85 return nullptr;
86}
87
89{
90 for(const auto & i : aObjectServerList)
91 {
92 if( rName == i.GetClassName() )
93 return &i;
94 }
95 return nullptr;
96}
97
99{
100 aObjectServerList.erase(std::remove_if(aObjectServerList.begin(), aObjectServerList.end(),
101 [rName](const SvObjectServer& rServer) { return rServer.GetClassName() == rName; }),
102 aObjectServerList.end());
103}
104
105
107/* [Description]
108
109 The list is filled with all types which can be selected in the insert-dialog.
110*/
111{
112 try{
113 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
114
115 uno::Reference< lang::XMultiServiceFactory > sProviderMSFactory =
116 configuration::theDefaultProvider::get(xContext);
117
118 uno::Sequence<uno::Any> aArguments(comphelper::InitAnyPropertySequence(
119 {
120 {"nodepath", uno::Any(OUString( "/org.openoffice.Office.Embedding/ObjectNames" ))}
121 }));
122 uno::Reference< container::XNameAccess > xNameAccess(
123 sProviderMSFactory->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArguments ),
124 uno::UNO_QUERY );
125
126 if( xNameAccess.is())
127 {
128 const uno::Sequence< OUString > seqNames= xNameAccess->getElementNames();
129
130 for( const auto& rName : seqNames )
131 {
132 uno::Reference< container::XNameAccess > xEntry ;
133 xNameAccess->getByName( rName ) >>= xEntry;
134 if ( xEntry.is() )
135 {
136 OUString aUIName;
137 OUString aClassID;
138 xEntry->getByName("ObjectUIName") >>= aUIName;
139 xEntry->getByName("ClassID") >>= aClassID;
140
141 if ( !aUIName.isEmpty() )
142 {
143 aUIName = aUIName.replaceAll("%PRODUCTNAME", utl::ConfigManager::getProductName());
144 aUIName = aUIName.replaceAll("%PRODUCTVERSION", utl::ConfigManager::getProductVersion());
145 }
146
147 SvGlobalName aClassName;
148 if( aClassName.MakeId( aClassID) )
149 {
150 if( !Get( aClassName ) )
151 // not entered yet
152 aObjectServerList.emplace_back( aClassName, aUIName );
153 }
154 }
155 }
156 }
157
158
159#ifdef _WIN32
160 SvGlobalName aOleFact( SO3_OUT_CLASSID );
161 OUString aOleObj( SvtResId( STR_FURTHER_OBJECT ) );
162 aObjectServerList.push_back( SvObjectServer( aOleFact, aOleObj ) );
163#endif
164
165 }catch(const container::NoSuchElementException&)
166 {
167 }catch(const uno::Exception&)
168 {
169 }
170 catch(...)
171 {
172 }
173}
174
176{
177 struct SotResourcePair
178 {
179 SotClipboardFormatId mnSotId;
180 TranslateId mpResId;
181 };
182
183 static const SotResourcePair aSotResourcePairs[] =
184 {
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 },
254 };
255
256 TranslateId pResId;
257
258 sal_uInt32 const nCount = SAL_N_ELEMENTS( aSotResourcePairs );
259 for (sal_uInt32 i = 0; ( i < nCount ) && !pResId; ++i)
260 {
261 if( aSotResourcePairs[ i ].mnSotId == nId )
262 pResId = aSotResourcePairs[ i ].mpResId;
263 }
264
265 OUString aUIName;
266 if (pResId)
267 aUIName = SvtResId(pResId);
268 else
270
271 return aUIName;
272}
273
274bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper& rData, OUString& _rName, OUString& _rSource, SotClipboardFormatId const & _nFormat)
275{
276 if( _nFormat != SotClipboardFormatId::EMBED_SOURCE_OLE && _nFormat != SotClipboardFormatId::EMBEDDED_OBJ_OLE )
277 return false;
278
279 datatransfer::DataFlavor aFlavor;
280 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE, aFlavor );
281
282 if( !rData.HasFormat( aFlavor ) )
283 return false;
284
285 uno::Any aAny = rData.GetAny(aFlavor, OUString());
286 if (!aAny.hasValue())
287 return false;
288
289 uno::Sequence< sal_Int8 > anySequence;
290 aAny >>= anySequence;
291
292 OleObjectDescriptor* pOleObjDescr =
293 reinterpret_cast< OleObjectDescriptor* >( anySequence.getArray( ) );
294
295 // determine the user friendly description of the embedded object
296 if ( pOleObjDescr->dwFullUserTypeName )
297 {
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 );
306
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;
310 }
311
312 // determine the source of the embedded object
313 if ( pOleObjDescr->dwSrcOfCopy )
314 {
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 );
323
324 _rSource += pSrcOfCopy;
325 }
326 else
327 _rSource = SvtResId(STR_UNKNOWN_SOURCE);
328
329 return true;
330}
331
332
333/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static OUString GetFormatName(SotClipboardFormatId nFormat)
bool MakeId(std::u16string_view rId)
const SvObjectServer * Get(std::u16string_view rHumanName) const
Definition: insdlg.cxx:78
void Remove(const SvGlobalName &)
Definition: insdlg.cxx:98
void FillInsertObjects()
Definition: insdlg.cxx:106
std::vector< SvObjectServer > aObjectServerList
Definition: insdlg.hxx:47
static bool GetEmbeddedName(const TransferableDataHelper &rData, OUString &_rName, OUString &_rSource, SotClipboardFormatId const &_nFormat)
Definition: insdlg.cxx:274
static OUString GetSotFormatUIName(SotClipboardFormatId nId)
Definition: insdlg.cxx:175
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool HasFormat(SotClipboardFormatId nFormat) const
#define SO3_OUT_CLASSID
static OUString getProductVersion()
static OUString getProductName()
int nCount
OUString aUIName
SotClipboardFormatId
Point POINTL
Definition: insdlg.cxx:43
Size SIZEL
Definition: insdlg.cxx:42
Sequence< PropertyValue > aArguments
#define SAL_N_ELEMENTS(arr)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference< XComponentContext > getProcessComponentContext()
int i
sal_Int16 nId
const char *const aClassID
bool hasValue()
OUString SvtResId(TranslateId aId)
Definition: svtresid.cxx:24
sal_uInt16 sal_Unicode