1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26
27 #define _INSDLG_CXX
28
29 // include ---------------------------------------------------------------
30
31 #include <svtools/insdlg.hxx>
32 #include <svtools/sores.hxx>
33 #include <svtools/svtdata.hxx>
34
35 #include <tools/rc.hxx>
36 #include <unotools/configmgr.hxx>
37 #include <sot/clsids.hxx>
38 #include <sot/stg.hxx>
39
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <comphelper/processfactory.hxx>
43 #include <com/sun/star/container/XNameAccess.hpp>
44
45 using namespace ::com::sun::star;
46
47 //---------------------------------------------
48 // this struct conforms to the Microsoft
49 // OBJECTDESCRIPTOR -> see oleidl.h
50 // (MS platform sdk)
51 //---------------------------------------------
52
53 struct OleObjectDescriptor
54 {
55 sal_uInt32 cbSize;
56 ClsId clsid;
57 sal_uInt32 dwDrawAspect;
58 Size sizel;
59 Point pointl;
60 sal_uInt32 dwStatus;
61 sal_uInt32 dwFullUserTypeName;
62 sal_uInt32 dwSrcOfCopy;
63 };
64
65 /********************** SvObjectServerList ********************************
66 **************************************************************************/
PRV_SV_IMPL_OWNER_LIST(SvObjectServerList,SvObjectServer) const67 PRV_SV_IMPL_OWNER_LIST( SvObjectServerList, SvObjectServer )
68
69 /*************************************************************************
70 |* SvObjectServerList::SvObjectServerList()
71 |*
72 |* Beschreibung
73 *************************************************************************/
74 const SvObjectServer * SvObjectServerList::Get( const String & rHumanName ) const
75 {
76 for( sal_uLong i = 0; i < Count(); i++ )
77 {
78 if( rHumanName == GetObject( i ).GetHumanName() )
79 return &GetObject( i );
80 }
81 return NULL;
82 }
83
84 /*************************************************************************
85 |* SvObjectServerList::SvObjectServerList()
86 |*
87 |* Beschreibung
88 *************************************************************************/
Get(const SvGlobalName & rName) const89 const SvObjectServer * SvObjectServerList::Get( const SvGlobalName & rName ) const
90 {
91 for( sal_uLong i = 0; i < Count(); i++ )
92 {
93 if( rName == GetObject( i ).GetClassName() )
94 return &GetObject( i );
95 }
96 return NULL;
97 }
98
Remove(const SvGlobalName & rName)99 void SvObjectServerList::Remove( const SvGlobalName & rName )
100 {
101 SvObjectServer * pS = (SvObjectServer *)aTypes.First();
102 while( pS )
103 {
104 if( rName == pS->GetClassName() )
105 {
106 Remove();
107 pS = (SvObjectServer *)aTypes.GetCurObject();
108 }
109 else
110 pS = (SvObjectServer *)aTypes.Next();
111 }
112 }
113
114 //---------------------------------------------------------------------
FillInsertObjects()115 void SvObjectServerList::FillInsertObjects()
116 /* [Beschreibung]
117
118 Die Liste wird mit allen Typen gef"ullt, die im Insert-Dialog
119 ausgew"ahlt werden k"onnen.
120 */
121 {
122 try{
123 uno::Reference< lang::XMultiServiceFactory > _globalMSFactory= comphelper::getProcessServiceFactory();
124 if( _globalMSFactory.is())
125 {
126 ::rtl::OUString sProviderService =
127 ::rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" );
128 uno::Reference< lang::XMultiServiceFactory > sProviderMSFactory(
129 _globalMSFactory->createInstance( sProviderService ), uno::UNO_QUERY );
130
131 if( sProviderMSFactory.is())
132 {
133 ::rtl::OUString sReaderService =
134 ::rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" );
135 uno::Sequence< uno::Any > aArguments( 1 );
136 beans::PropertyValue aPathProp;
137 aPathProp.Name = ::rtl::OUString::createFromAscii( "nodepath" );
138 aPathProp.Value <<= ::rtl::OUString::createFromAscii( "/org.openoffice.Office.Embedding/ObjectNames");
139 aArguments[0] <<= aPathProp;
140
141 uno::Reference< container::XNameAccess > xNameAccess(
142 sProviderMSFactory->createInstanceWithArguments( sReaderService,aArguments ),
143 uno::UNO_QUERY );
144
145 if( xNameAccess.is())
146 {
147 uno::Sequence< ::rtl::OUString > seqNames= xNameAccess->getElementNames();
148 sal_Int32 nInd;
149
150 ::rtl::OUString aStringProductName( RTL_CONSTASCII_USTRINGPARAM( "%PRODUCTNAME" ) );
151 sal_Int32 nStringProductNameLength = aStringProductName.getLength();
152
153 ::rtl::OUString aStringProductVersion( RTL_CONSTASCII_USTRINGPARAM( "%PRODUCTVERSION" ) );
154 sal_Int32 nStringProductVersionLength = aStringProductVersion.getLength();
155
156 // TODO/LATER: Do the request only once ( needs incompatible change )
157 ::rtl::OUString aProductName;
158 ::rtl::OUString aProductVersion;
159 uno::Any aProperty =
160 ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME );
161 if ( !( aProperty >>= aProductName ) )
162 {
163 OSL_ENSURE( sal_False, "Coudn't get PRODUCTNAME variable!\n" );
164 aProductName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StarOffice" ) );
165 }
166 aProperty = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTVERSION );
167 if ( !( aProperty >>= aProductVersion ) )
168 {
169 OSL_ENSURE( sal_False, "Coudn't get PRODUCTVERSION variable!\n" );
170 }
171
172 for( nInd = 0; nInd < seqNames.getLength(); nInd++ )
173 {
174 uno::Reference< container::XNameAccess > xEntry ;
175 xNameAccess->getByName( seqNames[nInd] ) >>= xEntry;
176 if ( xEntry.is() )
177 {
178 ::rtl::OUString aUIName;
179 ::rtl::OUString aClassID;
180 xEntry->getByName( ::rtl::OUString::createFromAscii("ObjectUIName") ) >>= aUIName;
181 xEntry->getByName( ::rtl::OUString::createFromAscii("ClassID") ) >>= aClassID;
182
183 if ( aUIName.getLength() )
184 {
185 // replace %PRODUCTNAME
186 sal_Int32 nIndex = aUIName.indexOf( aStringProductName );
187 while( nIndex != -1 )
188 {
189 aUIName = aUIName.replaceAt( nIndex, nStringProductNameLength, aProductName );
190 nIndex = aUIName.indexOf( aStringProductName );
191 }
192
193 // replace %PRODUCTVERSION
194 nIndex = aUIName.indexOf( aStringProductVersion );
195 while( nIndex != -1 )
196 {
197 aUIName = aUIName.replaceAt( nIndex, nStringProductVersionLength, aProductVersion );
198 nIndex = aUIName.indexOf( aStringProductVersion );
199 }
200 }
201
202 SvGlobalName aClassName;
203 if( aClassName.MakeId( String( aClassID )))
204 {
205 if( !Get( aClassName ) )
206 // noch nicht eingetragen
207 Append( SvObjectServer( aClassName, String( aUIName.getStr() ) ) );
208 }
209 }
210 }
211 }
212 }
213 }
214
215
216 #ifdef WNT
217 SvGlobalName aOleFact( SO3_OUT_CLASSID );
218 String aOleObj( SvtResId( STR_FURTHER_OBJECT ) );
219 Append( SvObjectServer( aOleFact, aOleObj ) );
220 #endif
221
222 }catch( container::NoSuchElementException)
223 {
224 }catch( uno::Exception)
225 {
226 }
227 catch(...)
228 {
229 }
230 }
231
GetSotFormatUIName(SotFormatStringId nId)232 String SvPasteObjectHelper::GetSotFormatUIName( SotFormatStringId nId )
233 {
234 struct SotResourcePair
235 {
236 SotFormatStringId mnSotId;
237 sal_uInt16 mnResId;
238 };
239
240 static const SotResourcePair aSotResourcePairs[] =
241 {
242 { SOT_FORMAT_STRING, STR_FORMAT_STRING },
243 { SOT_FORMAT_BITMAP, STR_FORMAT_BITMAP },
244 { SOT_FORMAT_GDIMETAFILE, STR_FORMAT_GDIMETAFILE },
245 { SOT_FORMAT_RTF, STR_FORMAT_RTF },
246 { SOT_FORMATSTR_ID_DRAWING, STR_FORMAT_ID_DRAWING },
247 { SOT_FORMATSTR_ID_SVXB, STR_FORMAT_ID_SVXB },
248 { SOT_FORMATSTR_ID_INTERNALLINK_STATE, STR_FORMAT_ID_INTERNALLINK_STATE },
249 { SOT_FORMATSTR_ID_SOLK, STR_FORMAT_ID_SOLK },
250 { SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, STR_FORMAT_ID_NETSCAPE_BOOKMARK },
251 { SOT_FORMATSTR_ID_STARSERVER, STR_FORMAT_ID_STARSERVER },
252 { SOT_FORMATSTR_ID_STAROBJECT, STR_FORMAT_ID_STAROBJECT },
253 { SOT_FORMATSTR_ID_APPLETOBJECT, STR_FORMAT_ID_APPLETOBJECT },
254 { SOT_FORMATSTR_ID_PLUGIN_OBJECT, STR_FORMAT_ID_PLUGIN_OBJECT },
255 { SOT_FORMATSTR_ID_STARWRITER_30, STR_FORMAT_ID_STARWRITER_30 },
256 { SOT_FORMATSTR_ID_STARWRITER_40, STR_FORMAT_ID_STARWRITER_40 },
257 { SOT_FORMATSTR_ID_STARWRITER_50, STR_FORMAT_ID_STARWRITER_50 },
258 { SOT_FORMATSTR_ID_STARWRITERWEB_40, STR_FORMAT_ID_STARWRITERWEB_40 },
259 { SOT_FORMATSTR_ID_STARWRITERWEB_50, STR_FORMAT_ID_STARWRITERWEB_50 },
260 { SOT_FORMATSTR_ID_STARWRITERGLOB_40, STR_FORMAT_ID_STARWRITERGLOB_40 },
261 { SOT_FORMATSTR_ID_STARWRITERGLOB_50, STR_FORMAT_ID_STARWRITERGLOB_50 },
262 { SOT_FORMATSTR_ID_STARDRAW, STR_FORMAT_ID_STARDRAW },
263 { SOT_FORMATSTR_ID_STARDRAW_40, STR_FORMAT_ID_STARDRAW_40 },
264 { SOT_FORMATSTR_ID_STARIMPRESS_50, STR_FORMAT_ID_STARIMPRESS_50 },
265 { SOT_FORMATSTR_ID_STARDRAW_50, STR_FORMAT_ID_STARDRAW_50 },
266 { SOT_FORMATSTR_ID_STARCALC, STR_FORMAT_ID_STARCALC },
267 { SOT_FORMATSTR_ID_STARCALC_40, STR_FORMAT_ID_STARCALC_40 },
268 { SOT_FORMATSTR_ID_STARCALC_50, STR_FORMAT_ID_STARCALC_50 },
269 { SOT_FORMATSTR_ID_STARCHART, STR_FORMAT_ID_STARCHART },
270 { SOT_FORMATSTR_ID_STARCHART_40, STR_FORMAT_ID_STARCHART_40 },
271 { SOT_FORMATSTR_ID_STARCHART_50, STR_FORMAT_ID_STARCHART_50 },
272 { SOT_FORMATSTR_ID_STARIMAGE, STR_FORMAT_ID_STARIMAGE },
273 { SOT_FORMATSTR_ID_STARIMAGE_40, STR_FORMAT_ID_STARIMAGE_40 },
274 { SOT_FORMATSTR_ID_STARIMAGE_50, STR_FORMAT_ID_STARIMAGE_50 },
275 { SOT_FORMATSTR_ID_STARMATH, STR_FORMAT_ID_STARMATH },
276 { SOT_FORMATSTR_ID_STARMATH_40, STR_FORMAT_ID_STARMATH_40 },
277 { SOT_FORMATSTR_ID_STARMATH_50, STR_FORMAT_ID_STARMATH_50 },
278 { SOT_FORMATSTR_ID_STAROBJECT_PAINTDOC, STR_FORMAT_ID_STAROBJECT_PAINTDOC },
279 { SOT_FORMATSTR_ID_HTML, STR_FORMAT_ID_HTML },
280 { SOT_FORMATSTR_ID_HTML_SIMPLE, STR_FORMAT_ID_HTML_SIMPLE },
281 { SOT_FORMATSTR_ID_BIFF_5, STR_FORMAT_ID_BIFF_5 },
282 { SOT_FORMATSTR_ID_BIFF_8, STR_FORMAT_ID_BIFF_8 },
283 { SOT_FORMATSTR_ID_SYLK, STR_FORMAT_ID_SYLK },
284 { SOT_FORMATSTR_ID_LINK, STR_FORMAT_ID_LINK },
285 { SOT_FORMATSTR_ID_DIF, STR_FORMAT_ID_DIF },
286 { SOT_FORMATSTR_ID_MSWORD_DOC, STR_FORMAT_ID_MSWORD_DOC },
287 { SOT_FORMATSTR_ID_STAR_FRAMESET_DOC, STR_FORMAT_ID_STAR_FRAMESET_DOC },
288 { SOT_FORMATSTR_ID_OFFICE_DOC, STR_FORMAT_ID_OFFICE_DOC },
289 { SOT_FORMATSTR_ID_NOTES_DOCINFO, STR_FORMAT_ID_NOTES_DOCINFO },
290 { SOT_FORMATSTR_ID_SFX_DOC, STR_FORMAT_ID_SFX_DOC },
291 { SOT_FORMATSTR_ID_STARCHARTDOCUMENT_50,STR_FORMAT_ID_STARCHARTDOCUMENT_50 },
292 { SOT_FORMATSTR_ID_GRAPHOBJ, STR_FORMAT_ID_GRAPHOBJ },
293 { SOT_FORMATSTR_ID_STARWRITER_60, STR_FORMAT_ID_STARWRITER_60 },
294 { SOT_FORMATSTR_ID_STARWRITERWEB_60, STR_FORMAT_ID_STARWRITERWEB_60 },
295 { SOT_FORMATSTR_ID_STARWRITERGLOB_60, STR_FORMAT_ID_STARWRITERGLOB_60 },
296 { SOT_FORMATSTR_ID_STARDRAW_60, STR_FORMAT_ID_STARDRAW_60 },
297 { SOT_FORMATSTR_ID_STARIMPRESS_60, STR_FORMAT_ID_STARIMPRESS_60 },
298 { SOT_FORMATSTR_ID_STARCALC_60, STR_FORMAT_ID_STARCALC_60 },
299 { SOT_FORMATSTR_ID_STARCHART_60, STR_FORMAT_ID_STARCHART_60 },
300 { SOT_FORMATSTR_ID_STARMATH_60, STR_FORMAT_ID_STARMATH_60 },
301 { SOT_FORMATSTR_ID_WMF, STR_FORMAT_ID_WMF },
302 { SOT_FORMATSTR_ID_DBACCESS_QUERY, STR_FORMAT_ID_DBACCESS_QUERY },
303 { SOT_FORMATSTR_ID_DBACCESS_TABLE, STR_FORMAT_ID_DBACCESS_TABLE },
304 { SOT_FORMATSTR_ID_DBACCESS_COMMAND, STR_FORMAT_ID_DBACCESS_COMMAND },
305 { SOT_FORMATSTR_ID_DIALOG_60, STR_FORMAT_ID_DIALOG_60 },
306 { SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, STR_FORMAT_ID_FILEGRPDESCRIPTOR },
307 { SOT_FORMATSTR_ID_HTML_NO_COMMENT, STR_FORMAT_ID_HTML_NO_COMMENT }
308 };
309
310 String aUIName;
311 sal_uInt16 nResId = 0;
312
313 for( sal_uInt32 i = 0, nCount = sizeof( aSotResourcePairs ) / sizeof( aSotResourcePairs[ 0 ] ); ( i < nCount ) && !nResId; i++ )
314 {
315 if( aSotResourcePairs[ i ].mnSotId == nId )
316 nResId = aSotResourcePairs[ i ].mnResId;
317 }
318
319 if( nResId )
320 aUIName = String( SvtResId( nResId ) );
321 else
322 aUIName = SotExchange::GetFormatName( nId );
323
324 return aUIName;
325 }
326 // -----------------------------------------------------------------------------
GetEmbeddedName(const TransferableDataHelper & rData,String & _rName,String & _rSource,SotFormatStringId & _nFormat)327 sal_Bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper& rData,String& _rName,String& _rSource,SotFormatStringId& _nFormat)
328 {
329 sal_Bool bRet = sal_False;
330 if( _nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE || _nFormat == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE )
331 {
332 datatransfer::DataFlavor aFlavor;
333 SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aFlavor );
334
335 uno::Any aAny;
336 if( rData.HasFormat( aFlavor ) &&
337 ( aAny = rData.GetAny( aFlavor ) ).hasValue() )
338 {
339 uno::Sequence< sal_Int8 > anySequence;
340 aAny >>= anySequence;
341
342 OleObjectDescriptor* pOleObjDescr =
343 reinterpret_cast< OleObjectDescriptor* >( anySequence.getArray( ) );
344
345 // determine the user friendly description of the embedded object
346 if ( pOleObjDescr->dwFullUserTypeName )
347 {
348 // we set the pointer to the start of user friendly description
349 // string. it starts at &OleObjectDescriptor + dwFullUserTypeName.
350 // dwFullUserTypeName is the offset in bytes.
351 // the user friendly description string is '\0' terminated.
352 const sal_Unicode* pUserTypeName =
353 reinterpret_cast< sal_Unicode* >(
354 reinterpret_cast< sal_Char* >( pOleObjDescr ) +
355 pOleObjDescr->dwFullUserTypeName );
356
357 _rName.Append( pUserTypeName );
358 // the following statement was here for historical reasons, it is commented out since it causes bug i49460
359 // _nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
360 }
361
362 // determine the source of the embedded object
363 if ( pOleObjDescr->dwSrcOfCopy )
364 {
365 // we set the pointer to the start of source string
366 // it starts at &OleObjectDescriptor + dwSrcOfCopy.
367 // dwSrcOfCopy is the offset in bytes.
368 // the source string is '\0' terminated.
369 const sal_Unicode* pSrcOfCopy =
370 reinterpret_cast< sal_Unicode* >(
371 reinterpret_cast< sal_Char* >( pOleObjDescr ) +
372 pOleObjDescr->dwSrcOfCopy );
373
374 _rSource.Append( pSrcOfCopy );
375 }
376 else
377 _rSource =
378 String( SvtResId( STR_UNKNOWN_SOURCE ) );
379 }
380 bRet = sal_True;
381 }
382 return bRet;
383 }
384 // -----------------------------------------------------------------------------
385
386