/src/libreoffice/svtools/source/dialogs/insdlg.cxx
Line | Count | Source |
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 | | |
24 | | #include <unotools/configmgr.hxx> |
25 | | #include <comphelper/classids.hxx> |
26 | | #include <sot/stg.hxx> |
27 | | #include <sal/macros.h> |
28 | | #include <vcl/transfer.hxx> |
29 | | |
30 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
31 | | #include <com/sun/star/configuration/theDefaultProvider.hpp> |
32 | | #include <comphelper/processfactory.hxx> |
33 | | #include <comphelper/propertysequence.hxx> |
34 | | #include <com/sun/star/container/XNameAccess.hpp> |
35 | | #include <officecfg/Office/Embedding.hxx> |
36 | | |
37 | | #if defined _WIN32 |
38 | | #include <prewin.h> |
39 | | #include <oleidl.h> |
40 | | #include <postwin.h> |
41 | | #else |
42 | | typedef Size SIZEL; |
43 | | typedef Point POINTL; |
44 | | #endif |
45 | | |
46 | | using namespace ::com::sun::star; |
47 | | |
48 | | // this struct conforms to the Microsoft |
49 | | // OBJECTDESCRIPTOR -> see oleidl.h |
50 | | // (MS platform sdk) |
51 | | |
52 | | namespace { |
53 | | |
54 | | struct OleObjectDescriptor |
55 | | { |
56 | | sal_uInt32 cbSize; |
57 | | ClsId clsid; |
58 | | sal_uInt32 dwDrawAspect; |
59 | | SIZEL sizel; |
60 | | POINTL pointl; |
61 | | sal_uInt32 dwStatus; |
62 | | sal_uInt32 dwFullUserTypeName; |
63 | | sal_uInt32 dwSrcOfCopy; |
64 | | }; |
65 | | |
66 | | #if defined _WIN32 |
67 | | static_assert(sizeof(OleObjectDescriptor) == sizeof(OBJECTDESCRIPTOR)); |
68 | | // check the two fields that we use here |
69 | | static_assert(offsetof(OleObjectDescriptor, dwFullUserTypeName) |
70 | | == offsetof(OBJECTDESCRIPTOR, dwFullUserTypeName)); |
71 | | static_assert(offsetof(OleObjectDescriptor, dwSrcOfCopy) |
72 | | == offsetof(OBJECTDESCRIPTOR, dwSrcOfCopy)); |
73 | | #endif |
74 | | |
75 | | } |
76 | | |
77 | | /********************** SvObjectServerList ******************************** |
78 | | **************************************************************************/ |
79 | | |
80 | | const SvObjectServer * SvObjectServerList::Get( std::u16string_view rHumanName ) const |
81 | 0 | { |
82 | 0 | for(const auto & i : aObjectServerList) |
83 | 0 | { |
84 | 0 | if( rHumanName == i.GetHumanName() ) |
85 | 0 | return &i; |
86 | 0 | } |
87 | 0 | return nullptr; |
88 | 0 | } |
89 | | |
90 | | const SvObjectServer * SvObjectServerList::Get( const SvGlobalName & rName ) const |
91 | 0 | { |
92 | 0 | for(const auto & i : aObjectServerList) |
93 | 0 | { |
94 | 0 | if( rName == i.GetClassName() ) |
95 | 0 | return &i; |
96 | 0 | } |
97 | 0 | return nullptr; |
98 | 0 | } |
99 | | |
100 | | void SvObjectServerList::Remove( const SvGlobalName & rName ) |
101 | 0 | { |
102 | 0 | std::erase_if(aObjectServerList, [rName](const SvObjectServer& rServer) { return rServer.GetClassName() == rName; }); |
103 | 0 | } |
104 | | |
105 | | |
106 | | void SvObjectServerList::FillInsertObjects() |
107 | | /* [Description] |
108 | | |
109 | | The list is filled with all types which can be selected in the insert-dialog. |
110 | | */ |
111 | 0 | { |
112 | 0 | try{ |
113 | 0 | uno::Reference< container::XNameAccess > xNameAccess = officecfg::Office::Embedding::ObjectNames::get(); |
114 | |
|
115 | 0 | const uno::Sequence< OUString > seqNames= xNameAccess->getElementNames(); |
116 | |
|
117 | 0 | for( const auto& rName : seqNames ) |
118 | 0 | { |
119 | 0 | uno::Reference< container::XNameAccess > xEntry ; |
120 | 0 | xNameAccess->getByName( rName ) >>= xEntry; |
121 | 0 | if ( xEntry.is() ) |
122 | 0 | { |
123 | 0 | OUString aUIName; |
124 | 0 | OUString aClassID; |
125 | 0 | xEntry->getByName(u"ObjectUIName"_ustr) >>= aUIName; |
126 | 0 | xEntry->getByName(u"ClassID"_ustr) >>= aClassID; |
127 | |
|
128 | 0 | if ( !aUIName.isEmpty() ) |
129 | 0 | { |
130 | 0 | aUIName = aUIName.replaceAll("%PRODUCTNAME", utl::ConfigManager::getProductName()); |
131 | 0 | aUIName = aUIName.replaceAll("%PRODUCTVERSION", utl::ConfigManager::getProductVersion()); |
132 | 0 | } |
133 | |
|
134 | 0 | SvGlobalName aClassName; |
135 | 0 | if( aClassName.MakeId( aClassID) ) |
136 | 0 | { |
137 | 0 | if( !Get( aClassName ) ) |
138 | | // not entered yet |
139 | 0 | aObjectServerList.emplace_back( aClassName, aUIName ); |
140 | 0 | } |
141 | 0 | } |
142 | 0 | } |
143 | | |
144 | |
|
145 | | #ifdef _WIN32 |
146 | | SvGlobalName aOleFact( SO3_OUT_CLASSID ); |
147 | | OUString aOleObj( SvtResId( STR_FURTHER_OBJECT ) ); |
148 | | aObjectServerList.push_back( SvObjectServer( aOleFact, aOleObj ) ); |
149 | | #endif |
150 | |
|
151 | 0 | }catch(const container::NoSuchElementException&) |
152 | 0 | { |
153 | 0 | }catch(const uno::Exception&) |
154 | 0 | { |
155 | 0 | } |
156 | 0 | catch(...) |
157 | 0 | { |
158 | 0 | } |
159 | 0 | } |
160 | | |
161 | | OUString SvPasteObjectHelper::GetSotFormatUIName( SotClipboardFormatId nId ) |
162 | 0 | { |
163 | 0 | struct SotResourcePair |
164 | 0 | { |
165 | 0 | SotClipboardFormatId mnSotId; |
166 | 0 | TranslateId mpResId; |
167 | 0 | }; |
168 | |
|
169 | 0 | static const SotResourcePair aSotResourcePairs[] = |
170 | 0 | { |
171 | 0 | { SotClipboardFormatId::STRING, STR_FORMAT_STRING }, |
172 | 0 | { SotClipboardFormatId::BITMAP, STR_FORMAT_BITMAP }, |
173 | 0 | { SotClipboardFormatId::GDIMETAFILE, STR_FORMAT_GDIMETAFILE }, |
174 | 0 | { SotClipboardFormatId::RTF, STR_FORMAT_RTF }, |
175 | 0 | { SotClipboardFormatId::DRAWING, STR_FORMAT_ID_DRAWING }, |
176 | 0 | { SotClipboardFormatId::SVXB, STR_FORMAT_ID_SVXB }, |
177 | 0 | { SotClipboardFormatId::INTERNALLINK_STATE, STR_FORMAT_ID_INTERNALLINK_STATE }, |
178 | 0 | { SotClipboardFormatId::SOLK, STR_FORMAT_ID_SOLK }, |
179 | 0 | { SotClipboardFormatId::NETSCAPE_BOOKMARK, STR_FORMAT_ID_NETSCAPE_BOOKMARK }, |
180 | 0 | { SotClipboardFormatId::STARSERVER, STR_FORMAT_ID_STARSERVER }, |
181 | 0 | { SotClipboardFormatId::STAROBJECT, STR_FORMAT_ID_STAROBJECT }, |
182 | 0 | { SotClipboardFormatId::APPLETOBJECT, STR_FORMAT_ID_APPLETOBJECT }, |
183 | 0 | { SotClipboardFormatId::PLUGIN_OBJECT, STR_FORMAT_ID_PLUGIN_OBJECT }, |
184 | 0 | { SotClipboardFormatId::STARWRITER_30, STR_FORMAT_ID_STARWRITER_30 }, |
185 | 0 | { SotClipboardFormatId::STARWRITER_40, STR_FORMAT_ID_STARWRITER_40 }, |
186 | 0 | { SotClipboardFormatId::STARWRITER_50, STR_FORMAT_ID_STARWRITER_50 }, |
187 | 0 | { SotClipboardFormatId::STARWRITERWEB_40, STR_FORMAT_ID_STARWRITERWEB_40 }, |
188 | 0 | { SotClipboardFormatId::STARWRITERWEB_50, STR_FORMAT_ID_STARWRITERWEB_50 }, |
189 | 0 | { SotClipboardFormatId::STARWRITERGLOB_40, STR_FORMAT_ID_STARWRITERGLOB_40 }, |
190 | 0 | { SotClipboardFormatId::STARWRITERGLOB_50, STR_FORMAT_ID_STARWRITERGLOB_50 }, |
191 | 0 | { SotClipboardFormatId::STARDRAW, STR_FORMAT_ID_STARDRAW }, |
192 | 0 | { SotClipboardFormatId::STARDRAW_40, STR_FORMAT_ID_STARDRAW_40 }, |
193 | 0 | { SotClipboardFormatId::STARIMPRESS_50, STR_FORMAT_ID_STARIMPRESS_50 }, |
194 | 0 | { SotClipboardFormatId::STARDRAW_50, STR_FORMAT_ID_STARDRAW_50 }, |
195 | 0 | { SotClipboardFormatId::STARCALC, STR_FORMAT_ID_STARCALC }, |
196 | 0 | { SotClipboardFormatId::STARCALC_40, STR_FORMAT_ID_STARCALC_40 }, |
197 | 0 | { SotClipboardFormatId::STARCALC_50, STR_FORMAT_ID_STARCALC_50 }, |
198 | 0 | { SotClipboardFormatId::STARCHART, STR_FORMAT_ID_STARCHART }, |
199 | 0 | { SotClipboardFormatId::STARCHART_40, STR_FORMAT_ID_STARCHART_40 }, |
200 | 0 | { SotClipboardFormatId::STARCHART_50, STR_FORMAT_ID_STARCHART_50 }, |
201 | 0 | { SotClipboardFormatId::STARIMAGE, STR_FORMAT_ID_STARIMAGE }, |
202 | 0 | { SotClipboardFormatId::STARIMAGE_40, STR_FORMAT_ID_STARIMAGE_40 }, |
203 | 0 | { SotClipboardFormatId::STARIMAGE_50, STR_FORMAT_ID_STARIMAGE_50 }, |
204 | 0 | { SotClipboardFormatId::STARMATH, STR_FORMAT_ID_STARMATH }, |
205 | 0 | { SotClipboardFormatId::STARMATH_40, STR_FORMAT_ID_STARMATH_40 }, |
206 | 0 | { SotClipboardFormatId::STARMATH_50, STR_FORMAT_ID_STARMATH_50 }, |
207 | 0 | { SotClipboardFormatId::STAROBJECT_PAINTDOC, STR_FORMAT_ID_STAROBJECT_PAINTDOC }, |
208 | 0 | { SotClipboardFormatId::HTML, STR_FORMAT_ID_HTML }, |
209 | 0 | { SotClipboardFormatId::HTML_SIMPLE, STR_FORMAT_ID_HTML_SIMPLE }, |
210 | 0 | { SotClipboardFormatId::BIFF_5, STR_FORMAT_ID_BIFF_5 }, |
211 | 0 | { SotClipboardFormatId::BIFF_8, STR_FORMAT_ID_BIFF_8 }, |
212 | 0 | { SotClipboardFormatId::BIFF_12, STR_FORMAT_ID_BIFF_12 }, |
213 | 0 | { SotClipboardFormatId::SYLK, STR_FORMAT_ID_SYLK }, |
214 | 0 | { SotClipboardFormatId::LINK, STR_FORMAT_ID_LINK }, |
215 | 0 | { SotClipboardFormatId::DIF, STR_FORMAT_ID_DIF }, |
216 | 0 | { SotClipboardFormatId::MSWORD_DOC, STR_FORMAT_ID_MSWORD_DOC }, |
217 | 0 | { SotClipboardFormatId::STAR_FRAMESET_DOC, STR_FORMAT_ID_STAR_FRAMESET_DOC }, |
218 | 0 | { SotClipboardFormatId::OFFICE_DOC, STR_FORMAT_ID_OFFICE_DOC }, |
219 | 0 | { SotClipboardFormatId::NOTES_DOCINFO, STR_FORMAT_ID_NOTES_DOCINFO }, |
220 | 0 | { SotClipboardFormatId::SFX_DOC, STR_FORMAT_ID_SFX_DOC }, |
221 | 0 | { SotClipboardFormatId::STARCHARTDOCUMENT_50,STR_FORMAT_ID_STARCHARTDOCUMENT_50 }, |
222 | 0 | { SotClipboardFormatId::GRAPHOBJ, STR_FORMAT_ID_GRAPHOBJ }, |
223 | 0 | { SotClipboardFormatId::STARWRITER_60, STR_FORMAT_ID_STARWRITER_60 }, |
224 | 0 | { SotClipboardFormatId::STARWRITERWEB_60, STR_FORMAT_ID_STARWRITERWEB_60 }, |
225 | 0 | { SotClipboardFormatId::STARWRITERGLOB_60, STR_FORMAT_ID_STARWRITERGLOB_60 }, |
226 | 0 | { SotClipboardFormatId::STARDRAW_60, STR_FORMAT_ID_STARDRAW_60 }, |
227 | 0 | { SotClipboardFormatId::STARIMPRESS_60, STR_FORMAT_ID_STARIMPRESS_60 }, |
228 | 0 | { SotClipboardFormatId::STARCALC_60, STR_FORMAT_ID_STARCALC_60 }, |
229 | 0 | { SotClipboardFormatId::STARCHART_60, STR_FORMAT_ID_STARCHART_60 }, |
230 | 0 | { SotClipboardFormatId::STARMATH_60, STR_FORMAT_ID_STARMATH_60 }, |
231 | 0 | { SotClipboardFormatId::WMF, STR_FORMAT_ID_WMF }, |
232 | 0 | { SotClipboardFormatId::DBACCESS_QUERY, STR_FORMAT_ID_DBACCESS_QUERY }, |
233 | 0 | { SotClipboardFormatId::DBACCESS_TABLE, STR_FORMAT_ID_DBACCESS_TABLE }, |
234 | 0 | { SotClipboardFormatId::DBACCESS_COMMAND, STR_FORMAT_ID_DBACCESS_COMMAND }, |
235 | 0 | { SotClipboardFormatId::DIALOG_60, STR_FORMAT_ID_DIALOG_60 }, |
236 | 0 | { SotClipboardFormatId::FILEGRPDESCRIPTOR, STR_FORMAT_ID_FILEGRPDESCRIPTOR }, |
237 | 0 | { SotClipboardFormatId::HTML_NO_COMMENT, STR_FORMAT_ID_HTML_NO_COMMENT }, |
238 | 0 | { SotClipboardFormatId::RICHTEXT, STR_FORMAT_ID_RICHTEXT }, |
239 | 0 | { SotClipboardFormatId::STRING_TSVC, STR_FORMAT_ID_STRING_TSVC }, |
240 | 0 | { SotClipboardFormatId::PNG, STR_FORMAT_ID_PNG_BITMAP }, |
241 | 0 | { SotClipboardFormatId::MARKDOWN, STR_FORMAT_ID_MARKDOWN}, |
242 | 0 | }; |
243 | |
|
244 | 0 | TranslateId pResId; |
245 | |
|
246 | 0 | sal_uInt32 const nCount = SAL_N_ELEMENTS( aSotResourcePairs ); |
247 | 0 | for (sal_uInt32 i = 0; ( i < nCount ) && !pResId; ++i) |
248 | 0 | { |
249 | 0 | if( aSotResourcePairs[ i ].mnSotId == nId ) |
250 | 0 | pResId = aSotResourcePairs[ i ].mpResId; |
251 | 0 | } |
252 | |
|
253 | 0 | OUString aUIName; |
254 | 0 | if (pResId) |
255 | 0 | aUIName = SvtResId(pResId); |
256 | 0 | else |
257 | 0 | aUIName = SotExchange::GetFormatName( nId ); |
258 | |
|
259 | 0 | return aUIName; |
260 | 0 | } |
261 | | |
262 | | bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper& rData, OUString& _rName, OUString& _rSource, SotClipboardFormatId const & _nFormat) |
263 | 0 | { |
264 | 0 | if( _nFormat != SotClipboardFormatId::EMBED_SOURCE_OLE && _nFormat != SotClipboardFormatId::EMBEDDED_OBJ_OLE ) |
265 | 0 | return false; |
266 | | |
267 | 0 | datatransfer::DataFlavor aFlavor; |
268 | 0 | SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE, aFlavor ); |
269 | |
|
270 | 0 | if( !rData.HasFormat( aFlavor ) ) |
271 | 0 | return false; |
272 | | |
273 | 0 | uno::Any aAny = rData.GetAny(aFlavor, OUString()); |
274 | 0 | if (!aAny.hasValue()) |
275 | 0 | return false; |
276 | | |
277 | 0 | uno::Sequence< sal_Int8 > anySequence; |
278 | 0 | aAny >>= anySequence; |
279 | |
|
280 | 0 | OleObjectDescriptor* pOleObjDescr = |
281 | 0 | reinterpret_cast< OleObjectDescriptor* >( anySequence.getArray( ) ); |
282 | | |
283 | | // determine the user friendly description of the embedded object |
284 | 0 | if ( pOleObjDescr->dwFullUserTypeName ) |
285 | 0 | { |
286 | | // we set the pointer to the start of user friendly description |
287 | | // string. it starts at &OleObjectDescriptor + dwFullUserTypeName. |
288 | | // dwFullUserTypeName is the offset in bytes. |
289 | | // the user friendly description string is '\0' terminated. |
290 | 0 | const sal_Unicode* pUserTypeName = |
291 | 0 | reinterpret_cast< sal_Unicode* >( |
292 | 0 | reinterpret_cast< char* >( pOleObjDescr ) + |
293 | 0 | pOleObjDescr->dwFullUserTypeName ); |
294 | |
|
295 | 0 | _rName += pUserTypeName; |
296 | | // the following statement was here for historical reasons, it is commented out since it causes bug i49460 |
297 | | // _nFormat = SotClipboardFormatId::EMBED_SOURCE_OLE; |
298 | 0 | } |
299 | | |
300 | | // determine the source of the embedded object |
301 | 0 | if ( pOleObjDescr->dwSrcOfCopy ) |
302 | 0 | { |
303 | | // we set the pointer to the start of source string |
304 | | // it starts at &OleObjectDescriptor + dwSrcOfCopy. |
305 | | // dwSrcOfCopy is the offset in bytes. |
306 | | // the source string is '\0' terminated. |
307 | 0 | const sal_Unicode* pSrcOfCopy = |
308 | 0 | reinterpret_cast< sal_Unicode* >( |
309 | 0 | reinterpret_cast< char* >( pOleObjDescr ) + |
310 | 0 | pOleObjDescr->dwSrcOfCopy ); |
311 | |
|
312 | 0 | _rSource += pSrcOfCopy; |
313 | 0 | } |
314 | 0 | else |
315 | 0 | _rSource = SvtResId(STR_UNKNOWN_SOURCE); |
316 | |
|
317 | 0 | return true; |
318 | 0 | } |
319 | | |
320 | | |
321 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |