GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / dialogs / insdlg.cxx
bloba9e441a6b319434ceacf0afe734ba5634369d08c
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;
37 //---------------------------------------------
38 // this struct conforms to the Microsoft
39 // OBJECTDESCRIPTOR -> see oleidl.h
40 // (MS platform sdk)
41 //---------------------------------------------
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;
94 //---------------------------------------------------------------------
95 void SvObjectServerList::FillInsertObjects()
96 /* [Beschreibung]
98 Die Liste wird mit allen Typen gef"ullt, die im Insert-Dialog
99 ausgew"ahlt werden k"onnen.
102 try{
103 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
105 uno::Reference< lang::XMultiServiceFactory > sProviderMSFactory =
106 configuration::theDefaultProvider::get(xContext);
108 OUString sReaderService( "com.sun.star.configuration.ConfigurationAccess" );
109 uno::Sequence< uno::Any > aArguments( 1 );
110 beans::PropertyValue aPathProp;
111 aPathProp.Name = "nodepath";
112 aPathProp.Value <<= OUString( "/org.openoffice.Office.Embedding/ObjectNames" );
113 aArguments[0] <<= aPathProp;
115 uno::Reference< container::XNameAccess > xNameAccess(
116 sProviderMSFactory->createInstanceWithArguments( sReaderService,aArguments ),
117 uno::UNO_QUERY );
119 if( xNameAccess.is())
121 uno::Sequence< OUString > seqNames= xNameAccess->getElementNames();
122 sal_Int32 nInd;
124 OUString aStringProductName( "%PRODUCTNAME" );
125 sal_Int32 nStringProductNameLength = aStringProductName.getLength();
127 OUString aStringProductVersion( "%PRODUCTVERSION" );
128 sal_Int32 nStringProductVersionLength = aStringProductVersion.getLength();
130 for( nInd = 0; nInd < seqNames.getLength(); nInd++ )
132 uno::Reference< container::XNameAccess > xEntry ;
133 xNameAccess->getByName( seqNames[nInd] ) >>= xEntry;
134 if ( xEntry.is() )
136 OUString aUIName;
137 OUString aClassID;
138 xEntry->getByName("ObjectUIName") >>= aUIName;
139 xEntry->getByName("ClassID") >>= aClassID;
141 if ( !aUIName.isEmpty() )
143 // replace %PRODUCTNAME
144 sal_Int32 nIndex = aUIName.indexOf( aStringProductName );
145 while( nIndex != -1 )
147 aUIName = aUIName.replaceAt(
148 nIndex, nStringProductNameLength,
149 utl::ConfigManager::getProductName() );
150 nIndex = aUIName.indexOf( aStringProductName );
153 // replace %PRODUCTVERSION
154 nIndex = aUIName.indexOf( aStringProductVersion );
155 while( nIndex != -1 )
157 aUIName = aUIName.replaceAt(
158 nIndex, nStringProductVersionLength,
159 utl::ConfigManager::getProductVersion() );
160 nIndex = aUIName.indexOf( aStringProductVersion );
164 SvGlobalName aClassName;
165 if( aClassName.MakeId( aClassID) )
167 if( !Get( aClassName ) )
168 // noch nicht eingetragen
169 aObjectServerList.push_back( SvObjectServer( aClassName, aUIName ) );
176 #ifdef WNT
177 SvGlobalName aOleFact( SO3_OUT_CLASSID );
178 OUString aOleObj( SVT_RESSTR( STR_FURTHER_OBJECT ) );
179 aObjectServerList.push_back( SvObjectServer( aOleFact, aOleObj ) );
180 #endif
182 }catch(const container::NoSuchElementException&)
184 }catch(const uno::Exception&)
187 catch(...)
192 OUString SvPasteObjectHelper::GetSotFormatUIName( SotFormatStringId nId )
194 struct SotResourcePair
196 SotFormatStringId mnSotId;
197 sal_uInt16 mnResId;
200 static const SotResourcePair aSotResourcePairs[] =
202 { SOT_FORMAT_STRING, STR_FORMAT_STRING },
203 { SOT_FORMAT_BITMAP, STR_FORMAT_BITMAP },
204 { SOT_FORMAT_GDIMETAFILE, STR_FORMAT_GDIMETAFILE },
205 { SOT_FORMAT_RTF, STR_FORMAT_RTF },
206 { SOT_FORMATSTR_ID_DRAWING, STR_FORMAT_ID_DRAWING },
207 { SOT_FORMATSTR_ID_SVXB, STR_FORMAT_ID_SVXB },
208 { SOT_FORMATSTR_ID_INTERNALLINK_STATE, STR_FORMAT_ID_INTERNALLINK_STATE },
209 { SOT_FORMATSTR_ID_SOLK, STR_FORMAT_ID_SOLK },
210 { SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, STR_FORMAT_ID_NETSCAPE_BOOKMARK },
211 { SOT_FORMATSTR_ID_STARSERVER, STR_FORMAT_ID_STARSERVER },
212 { SOT_FORMATSTR_ID_STAROBJECT, STR_FORMAT_ID_STAROBJECT },
213 { SOT_FORMATSTR_ID_APPLETOBJECT, STR_FORMAT_ID_APPLETOBJECT },
214 { SOT_FORMATSTR_ID_PLUGIN_OBJECT, STR_FORMAT_ID_PLUGIN_OBJECT },
215 { SOT_FORMATSTR_ID_STARWRITER_30, STR_FORMAT_ID_STARWRITER_30 },
216 { SOT_FORMATSTR_ID_STARWRITER_40, STR_FORMAT_ID_STARWRITER_40 },
217 { SOT_FORMATSTR_ID_STARWRITER_50, STR_FORMAT_ID_STARWRITER_50 },
218 { SOT_FORMATSTR_ID_STARWRITERWEB_40, STR_FORMAT_ID_STARWRITERWEB_40 },
219 { SOT_FORMATSTR_ID_STARWRITERWEB_50, STR_FORMAT_ID_STARWRITERWEB_50 },
220 { SOT_FORMATSTR_ID_STARWRITERGLOB_40, STR_FORMAT_ID_STARWRITERGLOB_40 },
221 { SOT_FORMATSTR_ID_STARWRITERGLOB_50, STR_FORMAT_ID_STARWRITERGLOB_50 },
222 { SOT_FORMATSTR_ID_STARDRAW, STR_FORMAT_ID_STARDRAW },
223 { SOT_FORMATSTR_ID_STARDRAW_40, STR_FORMAT_ID_STARDRAW_40 },
224 { SOT_FORMATSTR_ID_STARIMPRESS_50, STR_FORMAT_ID_STARIMPRESS_50 },
225 { SOT_FORMATSTR_ID_STARDRAW_50, STR_FORMAT_ID_STARDRAW_50 },
226 { SOT_FORMATSTR_ID_STARCALC, STR_FORMAT_ID_STARCALC },
227 { SOT_FORMATSTR_ID_STARCALC_40, STR_FORMAT_ID_STARCALC_40 },
228 { SOT_FORMATSTR_ID_STARCALC_50, STR_FORMAT_ID_STARCALC_50 },
229 { SOT_FORMATSTR_ID_STARCHART, STR_FORMAT_ID_STARCHART },
230 { SOT_FORMATSTR_ID_STARCHART_40, STR_FORMAT_ID_STARCHART_40 },
231 { SOT_FORMATSTR_ID_STARCHART_50, STR_FORMAT_ID_STARCHART_50 },
232 { SOT_FORMATSTR_ID_STARIMAGE, STR_FORMAT_ID_STARIMAGE },
233 { SOT_FORMATSTR_ID_STARIMAGE_40, STR_FORMAT_ID_STARIMAGE_40 },
234 { SOT_FORMATSTR_ID_STARIMAGE_50, STR_FORMAT_ID_STARIMAGE_50 },
235 { SOT_FORMATSTR_ID_STARMATH, STR_FORMAT_ID_STARMATH },
236 { SOT_FORMATSTR_ID_STARMATH_40, STR_FORMAT_ID_STARMATH_40 },
237 { SOT_FORMATSTR_ID_STARMATH_50, STR_FORMAT_ID_STARMATH_50 },
238 { SOT_FORMATSTR_ID_STAROBJECT_PAINTDOC, STR_FORMAT_ID_STAROBJECT_PAINTDOC },
239 { SOT_FORMATSTR_ID_HTML, STR_FORMAT_ID_HTML },
240 { SOT_FORMATSTR_ID_HTML_SIMPLE, STR_FORMAT_ID_HTML_SIMPLE },
241 { SOT_FORMATSTR_ID_BIFF_5, STR_FORMAT_ID_BIFF_5 },
242 { SOT_FORMATSTR_ID_BIFF_8, STR_FORMAT_ID_BIFF_8 },
243 { SOT_FORMATSTR_ID_SYLK, STR_FORMAT_ID_SYLK },
244 { SOT_FORMATSTR_ID_LINK, STR_FORMAT_ID_LINK },
245 { SOT_FORMATSTR_ID_DIF, STR_FORMAT_ID_DIF },
246 { SOT_FORMATSTR_ID_MSWORD_DOC, STR_FORMAT_ID_MSWORD_DOC },
247 { SOT_FORMATSTR_ID_STAR_FRAMESET_DOC, STR_FORMAT_ID_STAR_FRAMESET_DOC },
248 { SOT_FORMATSTR_ID_OFFICE_DOC, STR_FORMAT_ID_OFFICE_DOC },
249 { SOT_FORMATSTR_ID_NOTES_DOCINFO, STR_FORMAT_ID_NOTES_DOCINFO },
250 { SOT_FORMATSTR_ID_SFX_DOC, STR_FORMAT_ID_SFX_DOC },
251 { SOT_FORMATSTR_ID_STARCHARTDOCUMENT_50,STR_FORMAT_ID_STARCHARTDOCUMENT_50 },
252 { SOT_FORMATSTR_ID_GRAPHOBJ, STR_FORMAT_ID_GRAPHOBJ },
253 { SOT_FORMATSTR_ID_STARWRITER_60, STR_FORMAT_ID_STARWRITER_60 },
254 { SOT_FORMATSTR_ID_STARWRITERWEB_60, STR_FORMAT_ID_STARWRITERWEB_60 },
255 { SOT_FORMATSTR_ID_STARWRITERGLOB_60, STR_FORMAT_ID_STARWRITERGLOB_60 },
256 { SOT_FORMATSTR_ID_STARDRAW_60, STR_FORMAT_ID_STARDRAW_60 },
257 { SOT_FORMATSTR_ID_STARIMPRESS_60, STR_FORMAT_ID_STARIMPRESS_60 },
258 { SOT_FORMATSTR_ID_STARCALC_60, STR_FORMAT_ID_STARCALC_60 },
259 { SOT_FORMATSTR_ID_STARCHART_60, STR_FORMAT_ID_STARCHART_60 },
260 { SOT_FORMATSTR_ID_STARMATH_60, STR_FORMAT_ID_STARMATH_60 },
261 { SOT_FORMATSTR_ID_WMF, STR_FORMAT_ID_WMF },
262 { SOT_FORMATSTR_ID_DBACCESS_QUERY, STR_FORMAT_ID_DBACCESS_QUERY },
263 { SOT_FORMATSTR_ID_DBACCESS_TABLE, STR_FORMAT_ID_DBACCESS_TABLE },
264 { SOT_FORMATSTR_ID_DBACCESS_COMMAND, STR_FORMAT_ID_DBACCESS_COMMAND },
265 { SOT_FORMATSTR_ID_DIALOG_60, STR_FORMAT_ID_DIALOG_60 },
266 { SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, STR_FORMAT_ID_FILEGRPDESCRIPTOR },
267 { SOT_FORMATSTR_ID_HTML_NO_COMMENT, STR_FORMAT_ID_HTML_NO_COMMENT }
270 OUString aUIName;
271 sal_uInt16 nResId = 0;
273 for( sal_uInt32 i = 0, nCount = SAL_N_ELEMENTS( aSotResourcePairs ); ( i < nCount ) && !nResId; i++ )
275 if( aSotResourcePairs[ i ].mnSotId == nId )
276 nResId = aSotResourcePairs[ i ].mnResId;
279 if( nResId )
280 aUIName = SVT_RESSTR( nResId );
281 else
282 aUIName = SotExchange::GetFormatName( nId );
284 return aUIName;
286 // -----------------------------------------------------------------------------
287 sal_Bool SvPasteObjectHelper::GetEmbeddedName(const TransferableDataHelper& rData, OUString& _rName, OUString& _rSource, SotFormatStringId& _nFormat)
289 sal_Bool bRet = sal_False;
290 if( _nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE || _nFormat == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE )
292 datatransfer::DataFlavor aFlavor;
293 SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aFlavor );
295 uno::Any aAny;
296 if( rData.HasFormat( aFlavor ) &&
297 ( aAny = rData.GetAny( aFlavor ) ).hasValue() )
299 uno::Sequence< sal_Int8 > anySequence;
300 aAny >>= anySequence;
302 OleObjectDescriptor* pOleObjDescr =
303 reinterpret_cast< OleObjectDescriptor* >( anySequence.getArray( ) );
305 // determine the user friendly description of the embedded object
306 if ( pOleObjDescr->dwFullUserTypeName )
308 // we set the pointer to the start of user friendly description
309 // string. it starts at &OleObjectDescriptor + dwFullUserTypeName.
310 // dwFullUserTypeName is the offset in bytes.
311 // the user friendly description string is '\0' terminated.
312 const sal_Unicode* pUserTypeName =
313 reinterpret_cast< sal_Unicode* >(
314 reinterpret_cast< sal_Char* >( pOleObjDescr ) +
315 pOleObjDescr->dwFullUserTypeName );
317 _rName += pUserTypeName;
318 // the following statement was here for historical reasons, it is commented out since it causes bug i49460
319 // _nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
322 // determine the source of the embedded object
323 if ( pOleObjDescr->dwSrcOfCopy )
325 // we set the pointer to the start of source string
326 // it starts at &OleObjectDescriptor + dwSrcOfCopy.
327 // dwSrcOfCopy is the offset in bytes.
328 // the source string is '\0' terminated.
329 const sal_Unicode* pSrcOfCopy =
330 reinterpret_cast< sal_Unicode* >(
331 reinterpret_cast< sal_Char* >( pOleObjDescr ) +
332 pOleObjDescr->dwSrcOfCopy );
334 _rSource += pSrcOfCopy;
336 else
337 _rSource = SVT_RESSTR(STR_UNKNOWN_SOURCE);
339 bRet = sal_True;
341 return bRet;
343 // -----------------------------------------------------------------------------
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */