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