Bump version to 5.0-14
[LibreOffice.git] / svtools / source / dialogs / insdlg.cxx
blobe7aec0197af756fc8d1bdcd6dda330654326ebb9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svtools/insdlg.hxx>
21 #include <svtools/sores.hxx>
22 #include <svtools/svtresid.hxx>
24 #include <unotools/configmgr.hxx>
25 #include <comphelper/classids.hxx>
26 #include <sot/stg.hxx>
27 #include <sal/macros.h>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/configuration/theDefaultProvider.hpp>
32 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/container/XNameAccess.hpp>
35 using namespace ::com::sun::star;
38 // this struct conforms to the Microsoft
39 // OBJECTDESCRIPTOR -> see oleidl.h
40 // (MS platform sdk)
43 struct OleObjectDescriptor
45 sal_uInt32 cbSize;
46 ClsId clsid;
47 sal_uInt32 dwDrawAspect;
48 Size sizel;
49 Point pointl;
50 sal_uInt32 dwStatus;
51 sal_uInt32 dwFullUserTypeName;
52 sal_uInt32 dwSrcOfCopy;
55 /********************** SvObjectServerList ********************************
56 **************************************************************************/
58 const SvObjectServer * SvObjectServerList::Get( const OUString & rHumanName ) const
60 for( size_t i = 0; i < aObjectServerList.size(); i++ )
62 if( rHumanName == aObjectServerList[ i ].GetHumanName() )
63 return &aObjectServerList[ i ];
65 return NULL;
68 const SvObjectServer * SvObjectServerList::Get( const SvGlobalName & rName ) const
70 for( size_t i = 0; i < aObjectServerList.size(); i++ )
72 if( rName == aObjectServerList[ i ].GetClassName() )
73 return &aObjectServerList[ i ];
75 return NULL;
78 void SvObjectServerList::Remove( const SvGlobalName & rName )
80 for( size_t i = 0; i < aObjectServerList.size(); )
82 if( aObjectServerList[ i ].GetClassName() == rName )
84 SvObjectServerList_impl::iterator it = aObjectServerList.begin() + i;
85 aObjectServerList.erase( it );
87 else
89 ++i;
95 void SvObjectServerList::FillInsertObjects()
96 /* [Description]
98 The list is filled with all types which can be selected in the insert-dialog.
101 try{
102 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
104 uno::Reference< lang::XMultiServiceFactory > sProviderMSFactory =
105 configuration::theDefaultProvider::get(xContext);
107 OUString sReaderService( "com.sun.star.configuration.ConfigurationAccess" );
108 uno::Sequence< uno::Any > aArguments( 1 );
109 beans::PropertyValue aPathProp;
110 aPathProp.Name = "nodepath";
111 aPathProp.Value <<= OUString( "/org.openoffice.Office.Embedding/ObjectNames" );
112 aArguments[0] <<= aPathProp;
114 uno::Reference< container::XNameAccess > xNameAccess(
115 sProviderMSFactory->createInstanceWithArguments( sReaderService,aArguments ),
116 uno::UNO_QUERY );
118 if( xNameAccess.is())
120 uno::Sequence< OUString > seqNames= xNameAccess->getElementNames();
121 sal_Int32 nInd;
123 OUString aStringProductName( "%PRODUCTNAME" );
124 sal_Int32 nStringProductNameLength = aStringProductName.getLength();
126 OUString aStringProductVersion( "%PRODUCTVERSION" );
127 sal_Int32 nStringProductVersionLength = aStringProductVersion.getLength();
129 for( nInd = 0; nInd < seqNames.getLength(); nInd++ )
131 uno::Reference< container::XNameAccess > xEntry ;
132 xNameAccess->getByName( seqNames[nInd] ) >>= xEntry;
133 if ( xEntry.is() )
135 OUString aUIName;
136 OUString aClassID;
137 xEntry->getByName("ObjectUIName") >>= aUIName;
138 xEntry->getByName("ClassID") >>= aClassID;
140 if ( !aUIName.isEmpty() )
142 // replace %PRODUCTNAME
143 sal_Int32 nIndex = aUIName.indexOf( aStringProductName );
144 while( nIndex != -1 )
146 aUIName = aUIName.replaceAt(
147 nIndex, nStringProductNameLength,
148 utl::ConfigManager::getProductName() );
149 nIndex = aUIName.indexOf( aStringProductName );
152 // replace %PRODUCTVERSION
153 nIndex = aUIName.indexOf( aStringProductVersion );
154 while( nIndex != -1 )
156 aUIName = aUIName.replaceAt(
157 nIndex, nStringProductVersionLength,
158 utl::ConfigManager::getProductVersion() );
159 nIndex = aUIName.indexOf( aStringProductVersion );
163 SvGlobalName aClassName;
164 if( aClassName.MakeId( aClassID) )
166 if( !Get( aClassName ) )
167 // noch nicht eingetragen
168 aObjectServerList.push_back( SvObjectServer( aClassName, aUIName ) );
175 #ifdef WNT
176 SvGlobalName aOleFact( SO3_OUT_CLASSID );
177 OUString aOleObj( SVT_RESSTR( STR_FURTHER_OBJECT ) );
178 aObjectServerList.push_back( SvObjectServer( aOleFact, aOleObj ) );
179 #endif
181 }catch(const container::NoSuchElementException&)
183 }catch(const uno::Exception&)
186 catch(...)
191 OUString SvPasteObjectHelper::GetSotFormatUIName( SotClipboardFormatId nId )
193 struct SotResourcePair
195 SotClipboardFormatId mnSotId;
196 sal_uInt16 mnResId;
199 static const SotResourcePair aSotResourcePairs[] =
201 { SotClipboardFormatId::STRING, STR_FORMAT_STRING },
202 { SotClipboardFormatId::BITMAP, STR_FORMAT_BITMAP },
203 { SotClipboardFormatId::GDIMETAFILE, STR_FORMAT_GDIMETAFILE },
204 { SotClipboardFormatId::RTF, STR_FORMAT_RTF },
205 { SotClipboardFormatId::DRAWING, STR_FORMAT_ID_DRAWING },
206 { SotClipboardFormatId::SVXB, STR_FORMAT_ID_SVXB },
207 { SotClipboardFormatId::INTERNALLINK_STATE, STR_FORMAT_ID_INTERNALLINK_STATE },
208 { SotClipboardFormatId::SOLK, STR_FORMAT_ID_SOLK },
209 { SotClipboardFormatId::NETSCAPE_BOOKMARK, STR_FORMAT_ID_NETSCAPE_BOOKMARK },
210 { SotClipboardFormatId::STARSERVER, STR_FORMAT_ID_STARSERVER },
211 { SotClipboardFormatId::STAROBJECT, STR_FORMAT_ID_STAROBJECT },
212 { SotClipboardFormatId::APPLETOBJECT, STR_FORMAT_ID_APPLETOBJECT },
213 { SotClipboardFormatId::PLUGIN_OBJECT, STR_FORMAT_ID_PLUGIN_OBJECT },
214 { SotClipboardFormatId::STARWRITER_30, STR_FORMAT_ID_STARWRITER_30 },
215 { SotClipboardFormatId::STARWRITER_40, STR_FORMAT_ID_STARWRITER_40 },
216 { SotClipboardFormatId::STARWRITER_50, STR_FORMAT_ID_STARWRITER_50 },
217 { SotClipboardFormatId::STARWRITERWEB_40, STR_FORMAT_ID_STARWRITERWEB_40 },
218 { SotClipboardFormatId::STARWRITERWEB_50, STR_FORMAT_ID_STARWRITERWEB_50 },
219 { SotClipboardFormatId::STARWRITERGLOB_40, STR_FORMAT_ID_STARWRITERGLOB_40 },
220 { SotClipboardFormatId::STARWRITERGLOB_50, STR_FORMAT_ID_STARWRITERGLOB_50 },
221 { SotClipboardFormatId::STARDRAW, STR_FORMAT_ID_STARDRAW },
222 { SotClipboardFormatId::STARDRAW_40, STR_FORMAT_ID_STARDRAW_40 },
223 { SotClipboardFormatId::STARIMPRESS_50, STR_FORMAT_ID_STARIMPRESS_50 },
224 { SotClipboardFormatId::STARDRAW_50, STR_FORMAT_ID_STARDRAW_50 },
225 { SotClipboardFormatId::STARCALC, STR_FORMAT_ID_STARCALC },
226 { SotClipboardFormatId::STARCALC_40, STR_FORMAT_ID_STARCALC_40 },
227 { SotClipboardFormatId::STARCALC_50, STR_FORMAT_ID_STARCALC_50 },
228 { SotClipboardFormatId::STARCHART, STR_FORMAT_ID_STARCHART },
229 { SotClipboardFormatId::STARCHART_40, STR_FORMAT_ID_STARCHART_40 },
230 { SotClipboardFormatId::STARCHART_50, STR_FORMAT_ID_STARCHART_50 },
231 { SotClipboardFormatId::STARIMAGE, STR_FORMAT_ID_STARIMAGE },
232 { SotClipboardFormatId::STARIMAGE_40, STR_FORMAT_ID_STARIMAGE_40 },
233 { SotClipboardFormatId::STARIMAGE_50, STR_FORMAT_ID_STARIMAGE_50 },
234 { SotClipboardFormatId::STARMATH, STR_FORMAT_ID_STARMATH },
235 { SotClipboardFormatId::STARMATH_40, STR_FORMAT_ID_STARMATH_40 },
236 { SotClipboardFormatId::STARMATH_50, STR_FORMAT_ID_STARMATH_50 },
237 { SotClipboardFormatId::STAROBJECT_PAINTDOC, STR_FORMAT_ID_STAROBJECT_PAINTDOC },
238 { SotClipboardFormatId::HTML, STR_FORMAT_ID_HTML },
239 { SotClipboardFormatId::HTML_SIMPLE, STR_FORMAT_ID_HTML_SIMPLE },
240 { SotClipboardFormatId::BIFF_5, STR_FORMAT_ID_BIFF_5 },
241 { SotClipboardFormatId::BIFF_8, STR_FORMAT_ID_BIFF_8 },
242 { SotClipboardFormatId::SYLK, STR_FORMAT_ID_SYLK },
243 { SotClipboardFormatId::LINK, STR_FORMAT_ID_LINK },
244 { SotClipboardFormatId::DIF, STR_FORMAT_ID_DIF },
245 { SotClipboardFormatId::MSWORD_DOC, STR_FORMAT_ID_MSWORD_DOC },
246 { SotClipboardFormatId::STAR_FRAMESET_DOC, STR_FORMAT_ID_STAR_FRAMESET_DOC },
247 { SotClipboardFormatId::OFFICE_DOC, STR_FORMAT_ID_OFFICE_DOC },
248 { SotClipboardFormatId::NOTES_DOCINFO, STR_FORMAT_ID_NOTES_DOCINFO },
249 { SotClipboardFormatId::SFX_DOC, STR_FORMAT_ID_SFX_DOC },
250 { SotClipboardFormatId::STARCHARTDOCUMENT_50,STR_FORMAT_ID_STARCHARTDOCUMENT_50 },
251 { SotClipboardFormatId::GRAPHOBJ, STR_FORMAT_ID_GRAPHOBJ },
252 { SotClipboardFormatId::STARWRITER_60, STR_FORMAT_ID_STARWRITER_60 },
253 { SotClipboardFormatId::STARWRITERWEB_60, STR_FORMAT_ID_STARWRITERWEB_60 },
254 { SotClipboardFormatId::STARWRITERGLOB_60, STR_FORMAT_ID_STARWRITERGLOB_60 },
255 { SotClipboardFormatId::STARDRAW_60, STR_FORMAT_ID_STARDRAW_60 },
256 { SotClipboardFormatId::STARIMPRESS_60, STR_FORMAT_ID_STARIMPRESS_60 },
257 { SotClipboardFormatId::STARCALC_60, STR_FORMAT_ID_STARCALC_60 },
258 { SotClipboardFormatId::STARCHART_60, STR_FORMAT_ID_STARCHART_60 },
259 { SotClipboardFormatId::STARMATH_60, STR_FORMAT_ID_STARMATH_60 },
260 { SotClipboardFormatId::WMF, STR_FORMAT_ID_WMF },
261 { SotClipboardFormatId::DBACCESS_QUERY, STR_FORMAT_ID_DBACCESS_QUERY },
262 { SotClipboardFormatId::DBACCESS_TABLE, STR_FORMAT_ID_DBACCESS_TABLE },
263 { SotClipboardFormatId::DBACCESS_COMMAND, STR_FORMAT_ID_DBACCESS_COMMAND },
264 { SotClipboardFormatId::DIALOG_60, STR_FORMAT_ID_DIALOG_60 },
265 { SotClipboardFormatId::FILEGRPDESCRIPTOR, STR_FORMAT_ID_FILEGRPDESCRIPTOR },
266 { SotClipboardFormatId::HTML_NO_COMMENT, STR_FORMAT_ID_HTML_NO_COMMENT }
269 OUString aUIName;
270 sal_uInt16 nResId = 0;
272 for( sal_uInt32 i = 0, nCount = SAL_N_ELEMENTS( aSotResourcePairs ); ( i < nCount ) && !nResId; i++ )
274 if( aSotResourcePairs[ i ].mnSotId == nId )
275 nResId = aSotResourcePairs[ i ].mnResId;
278 if( nResId )
279 aUIName = SVT_RESSTR( nResId );
280 else
281 aUIName = SotExchange::GetFormatName( nId );
283 return aUIName;
286 bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper& rData, OUString& _rName, OUString& _rSource, SotClipboardFormatId& _nFormat)
288 bool bRet = false;
289 if( _nFormat == SotClipboardFormatId::EMBED_SOURCE_OLE || _nFormat == SotClipboardFormatId::EMBEDDED_OBJ_OLE )
291 datatransfer::DataFlavor aFlavor;
292 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::OBJECTDESCRIPTOR_OLE, aFlavor );
294 uno::Any aAny;
295 if( rData.HasFormat( aFlavor ) &&
296 ( aAny = rData.GetAny(aFlavor, OUString()) ).hasValue() )
298 uno::Sequence< sal_Int8 > anySequence;
299 aAny >>= anySequence;
301 OleObjectDescriptor* pOleObjDescr =
302 reinterpret_cast< OleObjectDescriptor* >( anySequence.getArray( ) );
304 // determine the user friendly description of the embedded object
305 if ( pOleObjDescr->dwFullUserTypeName )
307 // we set the pointer to the start of user friendly description
308 // string. it starts at &OleObjectDescriptor + dwFullUserTypeName.
309 // dwFullUserTypeName is the offset in bytes.
310 // the user friendly description string is '\0' terminated.
311 const sal_Unicode* pUserTypeName =
312 reinterpret_cast< sal_Unicode* >(
313 reinterpret_cast< sal_Char* >( pOleObjDescr ) +
314 pOleObjDescr->dwFullUserTypeName );
316 _rName += pUserTypeName;
317 // the following statement was here for historical reasons, it is commented out since it causes bug i49460
318 // _nFormat = SotClipboardFormatId::EMBED_SOURCE_OLE;
321 // determine the source of the embedded object
322 if ( pOleObjDescr->dwSrcOfCopy )
324 // we set the pointer to the start of source string
325 // it starts at &OleObjectDescriptor + dwSrcOfCopy.
326 // dwSrcOfCopy is the offset in bytes.
327 // the source string is '\0' terminated.
328 const sal_Unicode* pSrcOfCopy =
329 reinterpret_cast< sal_Unicode* >(
330 reinterpret_cast< sal_Char* >( pOleObjDescr ) +
331 pOleObjDescr->dwSrcOfCopy );
333 _rSource += pSrcOfCopy;
335 else
336 _rSource = SVT_RESSTR(STR_UNKNOWN_SOURCE);
338 bRet = true;
340 return bRet;
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */