Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svtools/insdlg.hxx>
30 : : #include <svtools/sores.hxx>
31 : : #include <svtools/svtresid.hxx>
32 : :
33 : : #include <unotools/configmgr.hxx>
34 : : #include <sot/clsids.hxx>
35 : : #include <sot/stg.hxx>
36 : : #include <sal/macros.h>
37 : :
38 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 : : #include <com/sun/star/beans/PropertyValue.hpp>
40 : : #include <comphelper/processfactory.hxx>
41 : : #include <com/sun/star/container/XNameAccess.hpp>
42 : :
43 : : using namespace ::com::sun::star;
44 : :
45 : : //---------------------------------------------
46 : : // this struct conforms to the Microsoft
47 : : // OBJECTDESCRIPTOR -> see oleidl.h
48 : : // (MS platform sdk)
49 : : //---------------------------------------------
50 : :
51 : : struct OleObjectDescriptor
52 : : {
53 : : sal_uInt32 cbSize;
54 : : ClsId clsid;
55 : : sal_uInt32 dwDrawAspect;
56 : : Size sizel;
57 : : Point pointl;
58 : : sal_uInt32 dwStatus;
59 : : sal_uInt32 dwFullUserTypeName;
60 : : sal_uInt32 dwSrcOfCopy;
61 : : };
62 : :
63 : : /********************** SvObjectServerList ********************************
64 : : **************************************************************************/
65 : :
66 : : /*************************************************************************
67 : : |* SvObjectServerList::SvObjectServerList()
68 : : |*
69 : : |* Beschreibung
70 : : *************************************************************************/
71 : 0 : const SvObjectServer * SvObjectServerList::Get( const String & rHumanName ) const
72 : : {
73 [ # # ]: 0 : for( size_t i = 0; i < aObjectServerList.size(); i++ )
74 : : {
75 [ # # ]: 0 : if( rHumanName == aObjectServerList[ i ].GetHumanName() )
76 : 0 : return &aObjectServerList[ i ];
77 : : }
78 : 0 : return NULL;
79 : : }
80 : :
81 : : /*************************************************************************
82 : : |* SvObjectServerList::SvObjectServerList()
83 : : |*
84 : : |* Beschreibung
85 : : *************************************************************************/
86 : 0 : const SvObjectServer * SvObjectServerList::Get( const SvGlobalName & rName ) const
87 : : {
88 [ # # ]: 0 : for( size_t i = 0; i < aObjectServerList.size(); i++ )
89 : : {
90 [ # # ]: 0 : if( rName == aObjectServerList[ i ].GetClassName() )
91 : 0 : return &aObjectServerList[ i ];
92 : : }
93 : 0 : return NULL;
94 : : }
95 : :
96 : 0 : void SvObjectServerList::Remove( const SvGlobalName & rName )
97 : : {
98 [ # # ]: 0 : for( size_t i = 0; i < aObjectServerList.size(); )
99 : : {
100 [ # # ]: 0 : if( aObjectServerList[ i ].GetClassName() == rName )
101 : : {
102 [ # # ]: 0 : SvObjectServerList_impl::iterator it = aObjectServerList.begin() + i;
103 [ # # ]: 0 : aObjectServerList.erase( it );
104 : : }
105 : : else
106 : : {
107 : 0 : ++i;
108 : : }
109 : : }
110 : 0 : }
111 : :
112 : : //---------------------------------------------------------------------
113 : 0 : void SvObjectServerList::FillInsertObjects()
114 : : /* [Beschreibung]
115 : :
116 : : Die Liste wird mit allen Typen gef"ullt, die im Insert-Dialog
117 : : ausgew"ahlt werden k"onnen.
118 : : */
119 : : {
120 : : try{
121 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > _globalMSFactory= comphelper::getProcessServiceFactory();
122 [ # # ]: 0 : if( _globalMSFactory.is())
123 : : {
124 [ # # ]: 0 : ::rtl::OUString sProviderService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ));
125 : : uno::Reference< lang::XMultiServiceFactory > sProviderMSFactory(
126 [ # # ][ # # ]: 0 : _globalMSFactory->createInstance( sProviderService ), uno::UNO_QUERY );
[ # # ]
127 : :
128 [ # # ]: 0 : if( sProviderMSFactory.is())
129 : : {
130 [ # # ]: 0 : ::rtl::OUString sReaderService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ));
131 [ # # ]: 0 : uno::Sequence< uno::Any > aArguments( 1 );
132 : 0 : beans::PropertyValue aPathProp;
133 [ # # ]: 0 : aPathProp.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
134 [ # # ][ # # ]: 0 : aPathProp.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Embedding/ObjectNames" ));
135 [ # # ][ # # ]: 0 : aArguments[0] <<= aPathProp;
136 : :
137 : : uno::Reference< container::XNameAccess > xNameAccess(
138 [ # # ]: 0 : sProviderMSFactory->createInstanceWithArguments( sReaderService,aArguments ),
139 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
140 : :
141 [ # # ]: 0 : if( xNameAccess.is())
142 : : {
143 [ # # ][ # # ]: 0 : uno::Sequence< ::rtl::OUString > seqNames= xNameAccess->getElementNames();
144 : : sal_Int32 nInd;
145 : :
146 [ # # ]: 0 : ::rtl::OUString aStringProductName( RTL_CONSTASCII_USTRINGPARAM( "%PRODUCTNAME" ) );
147 : 0 : sal_Int32 nStringProductNameLength = aStringProductName.getLength();
148 : :
149 [ # # ]: 0 : ::rtl::OUString aStringProductVersion( RTL_CONSTASCII_USTRINGPARAM( "%PRODUCTVERSION" ) );
150 : 0 : sal_Int32 nStringProductVersionLength = aStringProductVersion.getLength();
151 : :
152 [ # # ]: 0 : for( nInd = 0; nInd < seqNames.getLength(); nInd++ )
153 : : {
154 : 0 : uno::Reference< container::XNameAccess > xEntry ;
155 [ # # ][ # # ]: 0 : xNameAccess->getByName( seqNames[nInd] ) >>= xEntry;
[ # # ][ # # ]
156 [ # # ]: 0 : if ( xEntry.is() )
157 : : {
158 : 0 : ::rtl::OUString aUIName;
159 : 0 : ::rtl::OUString aClassID;
160 [ # # ][ # # ]: 0 : xEntry->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ObjectUIName" )) ) >>= aUIName;
[ # # ]
161 [ # # ][ # # ]: 0 : xEntry->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ClassID" )) ) >>= aClassID;
[ # # ]
162 : :
163 [ # # ]: 0 : if ( !aUIName.isEmpty() )
164 : : {
165 : : // replace %PRODUCTNAME
166 : 0 : sal_Int32 nIndex = aUIName.indexOf( aStringProductName );
167 [ # # ]: 0 : while( nIndex != -1 )
168 : : {
169 : : aUIName = aUIName.replaceAt(
170 : : nIndex, nStringProductNameLength,
171 [ # # ]: 0 : utl::ConfigManager::getProductName() );
172 : 0 : nIndex = aUIName.indexOf( aStringProductName );
173 : : }
174 : :
175 : : // replace %PRODUCTVERSION
176 : 0 : nIndex = aUIName.indexOf( aStringProductVersion );
177 [ # # ]: 0 : while( nIndex != -1 )
178 : : {
179 : : aUIName = aUIName.replaceAt(
180 : : nIndex, nStringProductVersionLength,
181 [ # # ]: 0 : utl::ConfigManager::getProductVersion() );
182 : 0 : nIndex = aUIName.indexOf( aStringProductVersion );
183 : : }
184 : : }
185 : :
186 [ # # ]: 0 : SvGlobalName aClassName;
187 [ # # ][ # # ]: 0 : if( aClassName.MakeId( String( aClassID )))
[ # # ][ # # ]
188 : : {
189 [ # # ][ # # ]: 0 : if( !Get( aClassName ) )
190 : : // noch nicht eingetragen
191 [ # # ][ # # ]: 0 : aObjectServerList.push_back( SvObjectServer( aClassName, aUIName ) );
[ # # ][ # # ]
[ # # ]
192 [ # # ]: 0 : }
193 : : }
194 [ # # ]: 0 : }
195 [ # # ]: 0 : }
196 : 0 : }
197 [ # # # ]: 0 : }
198 : :
199 : :
200 : : #ifdef WNT
201 : : SvGlobalName aOleFact( SO3_OUT_CLASSID );
202 : : String aOleObj( SVT_RESSTR( STR_FURTHER_OBJECT ) );
203 : : aObjectServerList.push_back( SvObjectServer( aOleFact, aOleObj ) );
204 : : #endif
205 : :
206 : 0 : }catch(const container::NoSuchElementException&)
207 : : {
208 : 0 : }catch(const uno::Exception&)
209 : : {
210 : : }
211 : 0 : catch(...)
212 : : {
213 : : }
214 : 0 : }
215 : :
216 : 0 : String SvPasteObjectHelper::GetSotFormatUIName( SotFormatStringId nId )
217 : : {
218 : : struct SotResourcePair
219 : : {
220 : : SotFormatStringId mnSotId;
221 : : sal_uInt16 mnResId;
222 : : };
223 : :
224 : : static const SotResourcePair aSotResourcePairs[] =
225 : : {
226 : : { SOT_FORMAT_STRING, STR_FORMAT_STRING },
227 : : { SOT_FORMAT_BITMAP, STR_FORMAT_BITMAP },
228 : : { SOT_FORMAT_GDIMETAFILE, STR_FORMAT_GDIMETAFILE },
229 : : { SOT_FORMAT_RTF, STR_FORMAT_RTF },
230 : : { SOT_FORMATSTR_ID_DRAWING, STR_FORMAT_ID_DRAWING },
231 : : { SOT_FORMATSTR_ID_SVXB, STR_FORMAT_ID_SVXB },
232 : : { SOT_FORMATSTR_ID_INTERNALLINK_STATE, STR_FORMAT_ID_INTERNALLINK_STATE },
233 : : { SOT_FORMATSTR_ID_SOLK, STR_FORMAT_ID_SOLK },
234 : : { SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, STR_FORMAT_ID_NETSCAPE_BOOKMARK },
235 : : { SOT_FORMATSTR_ID_STARSERVER, STR_FORMAT_ID_STARSERVER },
236 : : { SOT_FORMATSTR_ID_STAROBJECT, STR_FORMAT_ID_STAROBJECT },
237 : : { SOT_FORMATSTR_ID_APPLETOBJECT, STR_FORMAT_ID_APPLETOBJECT },
238 : : { SOT_FORMATSTR_ID_PLUGIN_OBJECT, STR_FORMAT_ID_PLUGIN_OBJECT },
239 : : { SOT_FORMATSTR_ID_STARWRITER_30, STR_FORMAT_ID_STARWRITER_30 },
240 : : { SOT_FORMATSTR_ID_STARWRITER_40, STR_FORMAT_ID_STARWRITER_40 },
241 : : { SOT_FORMATSTR_ID_STARWRITER_50, STR_FORMAT_ID_STARWRITER_50 },
242 : : { SOT_FORMATSTR_ID_STARWRITERWEB_40, STR_FORMAT_ID_STARWRITERWEB_40 },
243 : : { SOT_FORMATSTR_ID_STARWRITERWEB_50, STR_FORMAT_ID_STARWRITERWEB_50 },
244 : : { SOT_FORMATSTR_ID_STARWRITERGLOB_40, STR_FORMAT_ID_STARWRITERGLOB_40 },
245 : : { SOT_FORMATSTR_ID_STARWRITERGLOB_50, STR_FORMAT_ID_STARWRITERGLOB_50 },
246 : : { SOT_FORMATSTR_ID_STARDRAW, STR_FORMAT_ID_STARDRAW },
247 : : { SOT_FORMATSTR_ID_STARDRAW_40, STR_FORMAT_ID_STARDRAW_40 },
248 : : { SOT_FORMATSTR_ID_STARIMPRESS_50, STR_FORMAT_ID_STARIMPRESS_50 },
249 : : { SOT_FORMATSTR_ID_STARDRAW_50, STR_FORMAT_ID_STARDRAW_50 },
250 : : { SOT_FORMATSTR_ID_STARCALC, STR_FORMAT_ID_STARCALC },
251 : : { SOT_FORMATSTR_ID_STARCALC_40, STR_FORMAT_ID_STARCALC_40 },
252 : : { SOT_FORMATSTR_ID_STARCALC_50, STR_FORMAT_ID_STARCALC_50 },
253 : : { SOT_FORMATSTR_ID_STARCHART, STR_FORMAT_ID_STARCHART },
254 : : { SOT_FORMATSTR_ID_STARCHART_40, STR_FORMAT_ID_STARCHART_40 },
255 : : { SOT_FORMATSTR_ID_STARCHART_50, STR_FORMAT_ID_STARCHART_50 },
256 : : { SOT_FORMATSTR_ID_STARIMAGE, STR_FORMAT_ID_STARIMAGE },
257 : : { SOT_FORMATSTR_ID_STARIMAGE_40, STR_FORMAT_ID_STARIMAGE_40 },
258 : : { SOT_FORMATSTR_ID_STARIMAGE_50, STR_FORMAT_ID_STARIMAGE_50 },
259 : : { SOT_FORMATSTR_ID_STARMATH, STR_FORMAT_ID_STARMATH },
260 : : { SOT_FORMATSTR_ID_STARMATH_40, STR_FORMAT_ID_STARMATH_40 },
261 : : { SOT_FORMATSTR_ID_STARMATH_50, STR_FORMAT_ID_STARMATH_50 },
262 : : { SOT_FORMATSTR_ID_STAROBJECT_PAINTDOC, STR_FORMAT_ID_STAROBJECT_PAINTDOC },
263 : : { SOT_FORMATSTR_ID_HTML, STR_FORMAT_ID_HTML },
264 : : { SOT_FORMATSTR_ID_HTML_SIMPLE, STR_FORMAT_ID_HTML_SIMPLE },
265 : : { SOT_FORMATSTR_ID_BIFF_5, STR_FORMAT_ID_BIFF_5 },
266 : : { SOT_FORMATSTR_ID_BIFF_8, STR_FORMAT_ID_BIFF_8 },
267 : : { SOT_FORMATSTR_ID_SYLK, STR_FORMAT_ID_SYLK },
268 : : { SOT_FORMATSTR_ID_LINK, STR_FORMAT_ID_LINK },
269 : : { SOT_FORMATSTR_ID_DIF, STR_FORMAT_ID_DIF },
270 : : { SOT_FORMATSTR_ID_MSWORD_DOC, STR_FORMAT_ID_MSWORD_DOC },
271 : : { SOT_FORMATSTR_ID_STAR_FRAMESET_DOC, STR_FORMAT_ID_STAR_FRAMESET_DOC },
272 : : { SOT_FORMATSTR_ID_OFFICE_DOC, STR_FORMAT_ID_OFFICE_DOC },
273 : : { SOT_FORMATSTR_ID_NOTES_DOCINFO, STR_FORMAT_ID_NOTES_DOCINFO },
274 : : { SOT_FORMATSTR_ID_SFX_DOC, STR_FORMAT_ID_SFX_DOC },
275 : : { SOT_FORMATSTR_ID_STARCHARTDOCUMENT_50,STR_FORMAT_ID_STARCHARTDOCUMENT_50 },
276 : : { SOT_FORMATSTR_ID_GRAPHOBJ, STR_FORMAT_ID_GRAPHOBJ },
277 : : { SOT_FORMATSTR_ID_STARWRITER_60, STR_FORMAT_ID_STARWRITER_60 },
278 : : { SOT_FORMATSTR_ID_STARWRITERWEB_60, STR_FORMAT_ID_STARWRITERWEB_60 },
279 : : { SOT_FORMATSTR_ID_STARWRITERGLOB_60, STR_FORMAT_ID_STARWRITERGLOB_60 },
280 : : { SOT_FORMATSTR_ID_STARDRAW_60, STR_FORMAT_ID_STARDRAW_60 },
281 : : { SOT_FORMATSTR_ID_STARIMPRESS_60, STR_FORMAT_ID_STARIMPRESS_60 },
282 : : { SOT_FORMATSTR_ID_STARCALC_60, STR_FORMAT_ID_STARCALC_60 },
283 : : { SOT_FORMATSTR_ID_STARCHART_60, STR_FORMAT_ID_STARCHART_60 },
284 : : { SOT_FORMATSTR_ID_STARMATH_60, STR_FORMAT_ID_STARMATH_60 },
285 : : { SOT_FORMATSTR_ID_WMF, STR_FORMAT_ID_WMF },
286 : : { SOT_FORMATSTR_ID_DBACCESS_QUERY, STR_FORMAT_ID_DBACCESS_QUERY },
287 : : { SOT_FORMATSTR_ID_DBACCESS_TABLE, STR_FORMAT_ID_DBACCESS_TABLE },
288 : : { SOT_FORMATSTR_ID_DBACCESS_COMMAND, STR_FORMAT_ID_DBACCESS_COMMAND },
289 : : { SOT_FORMATSTR_ID_DIALOG_60, STR_FORMAT_ID_DIALOG_60 },
290 : : { SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, STR_FORMAT_ID_FILEGRPDESCRIPTOR },
291 : : { SOT_FORMATSTR_ID_HTML_NO_COMMENT, STR_FORMAT_ID_HTML_NO_COMMENT }
292 : : };
293 : :
294 : 0 : String aUIName;
295 : 0 : sal_uInt16 nResId = 0;
296 : :
297 [ # # ][ # # ]: 0 : for( sal_uInt32 i = 0, nCount = SAL_N_ELEMENTS( aSotResourcePairs ); ( i < nCount ) && !nResId; i++ )
[ # # ]
298 : : {
299 [ # # ]: 0 : if( aSotResourcePairs[ i ].mnSotId == nId )
300 : 0 : nResId = aSotResourcePairs[ i ].mnResId;
301 : : }
302 : :
303 [ # # ]: 0 : if( nResId )
304 [ # # ][ # # ]: 0 : aUIName = SVT_RESSTR( nResId );
[ # # ]
305 : : else
306 [ # # ][ # # ]: 0 : aUIName = SotExchange::GetFormatName( nId );
[ # # ]
307 : :
308 : 0 : return aUIName;
309 : : }
310 : : // -----------------------------------------------------------------------------
311 : 0 : sal_Bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper& rData,String& _rName,String& _rSource,SotFormatStringId& _nFormat)
312 : : {
313 : 0 : sal_Bool bRet = sal_False;
314 [ # # ][ # # ]: 0 : if( _nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE || _nFormat == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE )
315 : : {
316 : 0 : datatransfer::DataFlavor aFlavor;
317 [ # # ]: 0 : SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aFlavor );
318 : :
319 : 0 : uno::Any aAny;
320 [ # # # # ]: 0 : if( rData.HasFormat( aFlavor ) &&
[ # # ][ # # ]
321 [ # # ][ # # ]: 0 : ( aAny = rData.GetAny( aFlavor ) ).hasValue() )
[ # # ]
322 : : {
323 [ # # ]: 0 : uno::Sequence< sal_Int8 > anySequence;
324 [ # # ]: 0 : aAny >>= anySequence;
325 : :
326 : : OleObjectDescriptor* pOleObjDescr =
327 [ # # ]: 0 : reinterpret_cast< OleObjectDescriptor* >( anySequence.getArray( ) );
328 : :
329 : : // determine the user friendly description of the embedded object
330 [ # # ]: 0 : if ( pOleObjDescr->dwFullUserTypeName )
331 : : {
332 : : // we set the pointer to the start of user friendly description
333 : : // string. it starts at &OleObjectDescriptor + dwFullUserTypeName.
334 : : // dwFullUserTypeName is the offset in bytes.
335 : : // the user friendly description string is '\0' terminated.
336 : : const sal_Unicode* pUserTypeName =
337 : : reinterpret_cast< sal_Unicode* >(
338 : : reinterpret_cast< sal_Char* >( pOleObjDescr ) +
339 : 0 : pOleObjDescr->dwFullUserTypeName );
340 : :
341 [ # # ]: 0 : _rName.Append( pUserTypeName );
342 : : // the following statement was here for historical reasons, it is commented out since it causes bug i49460
343 : : // _nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
344 : : }
345 : :
346 : : // determine the source of the embedded object
347 [ # # ]: 0 : if ( pOleObjDescr->dwSrcOfCopy )
348 : : {
349 : : // we set the pointer to the start of source string
350 : : // it starts at &OleObjectDescriptor + dwSrcOfCopy.
351 : : // dwSrcOfCopy is the offset in bytes.
352 : : // the source string is '\0' terminated.
353 : : const sal_Unicode* pSrcOfCopy =
354 : : reinterpret_cast< sal_Unicode* >(
355 : : reinterpret_cast< sal_Char* >( pOleObjDescr ) +
356 : 0 : pOleObjDescr->dwSrcOfCopy );
357 : :
358 [ # # ]: 0 : _rSource.Append( pSrcOfCopy );
359 : : }
360 : : else
361 [ # # ][ # # ]: 0 : _rSource = SVT_RESSTR(STR_UNKNOWN_SOURCE);
[ # # ][ # # ]
362 : : }
363 : 0 : bRet = sal_True;
364 : : }
365 : 0 : return bRet;
366 : : }
367 : : // -----------------------------------------------------------------------------
368 : :
369 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|