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