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 : :
30 : : #include <sal/macros.h>
31 : : #include <svtools/unoimap.hxx>
32 : : #include <svx/unofill.hxx>
33 : : #include <editeng/unonrule.hxx>
34 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
35 : : #include <com/sun/star/container/XNameAccess.hpp>
36 : : #include <com/sun/star/text/textfield/Type.hpp>
37 : :
38 : : #include "servuno.hxx"
39 : : #include "unonames.hxx"
40 : : #include "cellsuno.hxx"
41 : : #include "fielduno.hxx"
42 : : #include "styleuno.hxx"
43 : : #include "afmtuno.hxx"
44 : : #include "defltuno.hxx"
45 : : #include "drdefuno.hxx"
46 : : #include "docsh.hxx"
47 : : #include "drwlayer.hxx"
48 : : #include "confuno.hxx"
49 : : #include "shapeuno.hxx"
50 : : #include "cellvaluebinding.hxx"
51 : : #include "celllistsource.hxx"
52 : : #include "addruno.hxx"
53 : : #include "chart2uno.hxx"
54 : : #include "tokenuno.hxx"
55 : :
56 : : // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
57 : : #include <svx/xmleohlp.hxx>
58 : : #include <svx/xmlgrhlp.hxx>
59 : : #include <sfx2/docfile.hxx>
60 : : #include <sfx2/docfilt.hxx>
61 : : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
62 : : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
63 : : #include <com/sun/star/document/XCodeNameQuery.hpp>
64 : : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
65 : : #include <com/sun/star/form/XFormsSupplier.hpp>
66 : : #include <svx/unomod.hxx>
67 : : #include <vbahelper/vbaaccesshelper.hxx>
68 : :
69 : : #include <comphelper/processfactory.hxx>
70 : : #include <basic/basmgr.hxx>
71 : : #include <sfx2/app.hxx>
72 : :
73 : : #include <comphelper/componentcontext.hxx>
74 : : #include <cppuhelper/component_context.hxx>
75 : : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
76 : :
77 : : using namespace ::com::sun::star;
78 : :
79 : 2 : bool isInVBAMode( ScDocShell& rDocSh )
80 : : {
81 [ + - ]: 2 : uno::Reference<script::XLibraryContainer> xLibContainer = rDocSh.GetBasicContainer();
82 [ + - ]: 2 : uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY );
83 [ + - ]: 2 : if ( xVBACompat.is() )
84 [ + - ][ + - ]: 2 : return xVBACompat->getVBACompatibilityMode();
85 : 2 : return false;
86 : : }
87 : :
88 [ # # ]: 0 : class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
89 : : {
90 : : uno::Any maWorkbook;
91 : : uno::Any maCachedObject;
92 : : ScDocShell* mpDocShell;
93 : : public:
94 : 22 : ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
95 : : {
96 : 13 : ScDocument* pDoc = mpDocShell->GetDocument();
97 [ - + ]: 13 : if ( !pDoc )
98 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
99 : :
100 [ + - ]: 13 : uno::Sequence< uno::Any > aArgs(2);
101 : : // access the application object ( parent for workbook )
102 [ + - ][ + + ]: 13 : aArgs[0] = uno::Any( ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.Application", uno::Sequence< uno::Any >() ) );
[ + - ][ + - ]
[ + - ]
103 [ + - ][ + - ]: 4 : aArgs[1] = uno::Any( mpDocShell->GetModel() );
[ + - ]
104 [ + - ][ + - ]: 13 : maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
[ + - ]
105 : 4 : }
106 : :
107 : 16 : virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
108 : : {
109 [ + - ]: 16 : SolarMutexGuard aGuard;
110 : 16 : maCachedObject = uno::Any(); // clear cached object
111 [ + - ]: 16 : String sName = aName;
112 : :
113 : 16 : ScDocument* pDoc = mpDocShell->GetDocument();
114 [ - + ]: 16 : if ( !pDoc )
115 [ # # ]: 0 : throw uno::RuntimeException();
116 : : // aName ( sName ) is generated from the stream name which can be different ( case-wise )
117 : : // from the code name
118 [ + - ][ + - ]: 16 : if( sName.EqualsIgnoreCaseAscii( pDoc->GetCodeName() ) )
[ + - ][ + + ]
119 : 4 : maCachedObject = maWorkbook;
120 : : else
121 : : {
122 : 12 : rtl::OUString sCodeName;
123 [ + - ]: 12 : SCTAB nCount = pDoc->GetTableCount();
124 [ + - ]: 24 : for( SCTAB i = 0; i < nCount; i++ )
125 : : {
126 [ + - ]: 24 : pDoc->GetCodeName( i, sCodeName );
127 : : // aName ( sName ) is generated from the stream name which can be different ( case-wise )
128 : : // from the code name
129 [ + - ][ + - ]: 24 : if( String(sCodeName).EqualsIgnoreCaseAscii( sName ) )
[ + - ][ + + ]
130 : : {
131 : 12 : rtl::OUString sSheetName;
132 [ + - ][ + - ]: 12 : if( pDoc->GetName( i, sSheetName ) )
133 : : {
134 [ + - ]: 12 : uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
135 [ + - ]: 12 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
136 [ + - ][ + - ]: 12 : uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
[ + - ]
137 [ + - ]: 12 : uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
138 [ + - ][ + - ]: 12 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
[ + - ]
139 [ + - ]: 12 : uno::Sequence< uno::Any > aArgs(3);
140 [ + - ]: 12 : aArgs[0] = maWorkbook;
141 [ + - ][ + - ]: 12 : aArgs[1] = uno::Any( xModel );
142 [ + - ][ + - ]: 12 : aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
143 : : // use the convience function
144 [ + - ][ + - ]: 12 : maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
145 [ + - ]: 12 : break;
146 [ - + ]: 12 : }
147 : : }
148 : 12 : }
149 : : }
150 [ + - ][ + - ]: 16 : return maCachedObject.hasValue();
151 : :
152 : : }
153 : 16 : ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
154 : : {
155 [ + - ]: 16 : SolarMutexGuard aGuard;
156 : : OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
157 : : rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
158 [ + - ][ - + ]: 16 : if ( !hasByName( aName ) )
159 [ # # ]: 0 : throw ::com::sun::star::container::NoSuchElementException();
160 [ + - ]: 16 : return maCachedObject;
161 : : }
162 : 0 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException)
163 : : {
164 [ # # ]: 0 : SolarMutexGuard aGuard;
165 : 0 : ScDocument* pDoc = mpDocShell->GetDocument();
166 [ # # ]: 0 : if ( !pDoc )
167 [ # # ]: 0 : throw uno::RuntimeException();
168 [ # # ]: 0 : SCTAB nCount = pDoc->GetTableCount();
169 [ # # ]: 0 : uno::Sequence< rtl::OUString > aNames( nCount + 1 );
170 : 0 : SCTAB index = 0;
171 : 0 : rtl::OUString sCodeName;
172 [ # # ]: 0 : for( ; index < nCount; ++index )
173 : : {
174 [ # # ]: 0 : pDoc->GetCodeName( index, sCodeName );
175 [ # # ]: 0 : aNames[ index ] = sCodeName;
176 : : }
177 [ # # ]: 0 : aNames[ index ] = pDoc->GetCodeName();
178 [ # # ]: 0 : return aNames;
179 : : }
180 : : // XElemenAccess
181 : 0 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
182 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
183 : :
184 : : };
185 : :
186 [ - + ]: 4 : class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
187 : : {
188 : : ScDocShell& mrDocShell;
189 : : public:
190 : 2 : ScVbaCodeNameProvider( ScDocShell& rDocShell ) : mrDocShell(rDocShell) {}
191 : : // XCodeNameQuery
192 : 0 : rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
193 : : {
194 [ # # ]: 0 : SolarMutexGuard aGuard;
195 : 0 : rtl::OUString sCodeName;
196 : :
197 : : // need to find the page ( and index ) for this control
198 [ # # ][ # # ]: 0 : uno::Reference< drawing::XDrawPagesSupplier > xSupplier( mrDocShell.GetModel(), uno::UNO_QUERY_THROW );
199 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
[ # # ]
200 [ # # ][ # # ]: 0 : sal_Int32 nLen = xIndex->getCount();
201 : 0 : bool bMatched = false;
202 [ # # ]: 0 : uno::Sequence< script::ScriptEventDescriptor > aFakeEvents;
203 [ # # ]: 0 : for ( sal_Int32 index = 0; index < nLen; ++index )
204 : : {
205 : : try
206 : : {
207 [ # # ][ # # ]: 0 : uno::Reference< form::XFormsSupplier > xFormSupplier( xIndex->getByIndex( index ), uno::UNO_QUERY_THROW );
[ # # ]
208 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xFormIndex( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
[ # # ]
209 : : // get the www-standard container
210 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xFormControls( xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW );
[ # # ]
211 [ # # ][ # # ]: 0 : sal_Int32 nCntrls = xFormControls->getCount();
212 [ # # ]: 0 : for( sal_Int32 cIndex = 0; cIndex < nCntrls; ++cIndex )
213 : : {
214 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface > xControl( xFormControls->getByIndex( cIndex ), uno::UNO_QUERY_THROW );
[ # # ]
215 [ # # ]: 0 : bMatched = ( xControl == xIf );
216 [ # # ]: 0 : if ( bMatched )
217 : : {
218 : 0 : rtl::OUString sName;
219 [ # # ]: 0 : mrDocShell.GetDocument()->GetCodeName( static_cast<SCTAB>( index ), sName );
220 : 0 : sCodeName = sName;
221 : : }
222 [ # # ]: 0 : }
223 : : }
224 [ # # ]: 0 : catch( uno::Exception& ) {}
225 [ # # ]: 0 : if ( bMatched )
226 : 0 : break;
227 : : }
228 : : // Probably should throw here ( if !bMatched )
229 [ # # ][ # # ]: 0 : return sCodeName;
230 : : }
231 : :
232 : 2 : rtl::OUString SAL_CALL getCodeNameForContainer( const uno::Reference<uno::XInterface>& xContainer )
233 : : throw( uno::RuntimeException )
234 : : {
235 [ + - ]: 2 : SolarMutexGuard aGuard;
236 [ + - ][ + - ]: 2 : uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mrDocShell.GetModel(), uno::UNO_QUERY_THROW);
237 [ + - ][ + - ]: 2 : uno::Reference<container::XIndexAccess> xIndex(xSupplier->getDrawPages(), uno::UNO_QUERY_THROW);
[ + - ]
238 : :
239 [ + - ][ + - ]: 2 : for (sal_Int32 i = 0, n = xIndex->getCount(); i < n; ++i)
[ + - ]
240 : : {
241 : : try
242 : : {
243 [ + - ][ + - ]: 2 : uno::Reference<form::XFormsSupplier> xFormSupplier(xIndex->getByIndex(i), uno::UNO_QUERY_THROW);
[ + - ]
244 [ + - ][ + - ]: 2 : uno::Reference<container::XIndexAccess> xFormIndex(xFormSupplier->getForms(), uno::UNO_QUERY_THROW);
[ + - ]
245 : : // get the www-standard container
246 [ + - ][ + - ]: 2 : uno::Reference<container::XIndexAccess> xFormControls(xFormIndex->getByIndex(0), uno::UNO_QUERY_THROW);
[ + - ]
247 [ + - ][ + - ]: 2 : if (xFormControls == xContainer)
248 : : {
249 : 2 : rtl::OUString aName;
250 [ + - ][ + - ]: 2 : if (mrDocShell.GetDocument()->GetCodeName(static_cast<SCTAB>(i), aName))
251 [ - + ]: 2 : return aName;
252 [ + - ][ + - ]: 2 : }
[ - + ][ # # ]
253 : : }
254 [ # # ]: 0 : catch( uno::Exception& ) {}
255 : : }
256 [ + - ]: 2 : return rtl::OUString();
257 : : }
258 : : };
259 : :
260 : : //------------------------------------------------------------------------
261 : : //
262 : : struct ProvNamesId_Type
263 : : {
264 : : const char * pName;
265 : : sal_uInt16 nType;
266 : : };
267 : :
268 : : static const ProvNamesId_Type aProvNamesId[] =
269 : : {
270 : : { "com.sun.star.sheet.Spreadsheet", SC_SERVICE_SHEET },
271 : : { "com.sun.star.text.TextField.URL", SC_SERVICE_URLFIELD },
272 : : { "com.sun.star.text.TextField.PageNumber", SC_SERVICE_PAGEFIELD },
273 : : { "com.sun.star.text.TextField.PageCount", SC_SERVICE_PAGESFIELD },
274 : : { "com.sun.star.text.TextField.Date", SC_SERVICE_DATEFIELD },
275 : : { "com.sun.star.text.TextField.Time", SC_SERVICE_TIMEFIELD },
276 : : { "com.sun.star.text.TextField.DateTime", SC_SERVICE_EXT_TIMEFIELD },
277 : : { "com.sun.star.text.TextField.DocInfo.Title", SC_SERVICE_TITLEFIELD },
278 : : { "com.sun.star.text.TextField.FileName", SC_SERVICE_FILEFIELD },
279 : : { "com.sun.star.text.TextField.SheetName", SC_SERVICE_SHEETFIELD },
280 : : { "com.sun.star.style.CellStyle", SC_SERVICE_CELLSTYLE },
281 : : { "com.sun.star.style.PageStyle", SC_SERVICE_PAGESTYLE },
282 : : { "com.sun.star.sheet.TableAutoFormat", SC_SERVICE_AUTOFORMAT },
283 : : { "com.sun.star.sheet.SheetCellRanges", SC_SERVICE_CELLRANGES },
284 : : { "com.sun.star.drawing.GradientTable", SC_SERVICE_GRADTAB },
285 : : { "com.sun.star.drawing.HatchTable", SC_SERVICE_HATCHTAB },
286 : : { "com.sun.star.drawing.BitmapTable", SC_SERVICE_BITMAPTAB },
287 : : { "com.sun.star.drawing.TransparencyGradientTable", SC_SERVICE_TRGRADTAB },
288 : : { "com.sun.star.drawing.MarkerTable", SC_SERVICE_MARKERTAB },
289 : : { "com.sun.star.drawing.DashTable", SC_SERVICE_DASHTAB },
290 : : { "com.sun.star.text.NumberingRules", SC_SERVICE_NUMRULES },
291 : : { "com.sun.star.sheet.Defaults", SC_SERVICE_DOCDEFLTS },
292 : : { "com.sun.star.drawing.Defaults", SC_SERVICE_DRAWDEFLTS },
293 : : { "com.sun.star.comp.SpreadsheetSettings", SC_SERVICE_DOCSPRSETT },
294 : : { "com.sun.star.document.Settings", SC_SERVICE_DOCCONF },
295 : : { "com.sun.star.image.ImageMapRectangleObject", SC_SERVICE_IMAP_RECT },
296 : : { "com.sun.star.image.ImageMapCircleObject", SC_SERVICE_IMAP_CIRC },
297 : : { "com.sun.star.image.ImageMapPolygonObject", SC_SERVICE_IMAP_POLY },
298 : :
299 : : // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
300 : : { "com.sun.star.document.ExportGraphicObjectResolver", SC_SERVICE_EXPORT_GOR },
301 : : { "com.sun.star.document.ImportGraphicObjectResolver", SC_SERVICE_IMPORT_GOR },
302 : : { "com.sun.star.document.ExportEmbeddedObjectResolver", SC_SERVICE_EXPORT_EOR },
303 : : { "com.sun.star.document.ImportEmbeddedObjectResolver", SC_SERVICE_IMPORT_EOR },
304 : :
305 : : { SC_SERVICENAME_VALBIND, SC_SERVICE_VALBIND },
306 : : { SC_SERVICENAME_LISTCELLBIND, SC_SERVICE_LISTCELLBIND },
307 : : { SC_SERVICENAME_LISTSOURCE, SC_SERVICE_LISTSOURCE },
308 : : { SC_SERVICENAME_CELLADDRESS, SC_SERVICE_CELLADDRESS },
309 : : { SC_SERVICENAME_RANGEADDRESS, SC_SERVICE_RANGEADDRESS },
310 : :
311 : : { "com.sun.star.sheet.DocumentSettings",SC_SERVICE_SHEETDOCSET },
312 : :
313 : : { SC_SERVICENAME_CHDATAPROV, SC_SERVICE_CHDATAPROV },
314 : : { SC_SERVICENAME_FORMULAPARS, SC_SERVICE_FORMULAPARS },
315 : : { SC_SERVICENAME_OPCODEMAPPER, SC_SERVICE_OPCODEMAPPER },
316 : : { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER },
317 : : { "ooo.vba.VBACodeNameProvider", SC_SERVICE_VBACODENAMEPROVIDER },
318 : : { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS },
319 : :
320 : : // case-correct versions of the service names (#i102468#)
321 : : { "com.sun.star.text.textfield.URL", SC_SERVICE_URLFIELD },
322 : : { "com.sun.star.text.textfield.PageNumber", SC_SERVICE_PAGEFIELD },
323 : : { "com.sun.star.text.textfield.PageCount", SC_SERVICE_PAGESFIELD },
324 : : { "com.sun.star.text.textfield.Date", SC_SERVICE_DATEFIELD },
325 : : { "com.sun.star.text.textfield.Time", SC_SERVICE_TIMEFIELD },
326 : : { "com.sun.star.text.textfield.DateTime", SC_SERVICE_EXT_TIMEFIELD },
327 : : { "com.sun.star.text.textfield.docinfo.Title", SC_SERVICE_TITLEFIELD },
328 : : { "com.sun.star.text.textfield.FileName", SC_SERVICE_FILEFIELD },
329 : : { "com.sun.star.text.textfield.SheetName", SC_SERVICE_SHEETFIELD },
330 : : { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS },
331 : : };
332 : :
333 : : //
334 : : // old service names that were in 567 still work in createInstance,
335 : : // in case some macro is still using them
336 : : //
337 : :
338 : : static const sal_Char* aOldNames[SC_SERVICE_COUNT] =
339 : : {
340 : : "", // SC_SERVICE_SHEET
341 : : "stardiv.one.text.TextField.URL", // SC_SERVICE_URLFIELD
342 : : "stardiv.one.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD
343 : : "stardiv.one.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD
344 : : "stardiv.one.text.TextField.Date", // SC_SERVICE_DATEFIELD
345 : : "stardiv.one.text.TextField.Time", // SC_SERVICE_TIMEFIELD
346 : : "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD
347 : : "stardiv.one.text.TextField.FileName", // SC_SERVICE_FILEFIELD
348 : : "stardiv.one.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD
349 : : "stardiv.one.style.CellStyle", // SC_SERVICE_CELLSTYLE
350 : : "stardiv.one.style.PageStyle", // SC_SERVICE_PAGESTYLE
351 : : "", // SC_SERVICE_AUTOFORMAT
352 : : "", // SC_SERVICE_CELLRANGES
353 : : "", // SC_SERVICE_GRADTAB
354 : : "", // SC_SERVICE_HATCHTAB
355 : : "", // SC_SERVICE_BITMAPTAB
356 : : "", // SC_SERVICE_TRGRADTAB
357 : : "", // SC_SERVICE_MARKERTAB
358 : : "", // SC_SERVICE_DASHTAB
359 : : "", // SC_SERVICE_NUMRULES
360 : : "", // SC_SERVICE_DOCDEFLTS
361 : : "", // SC_SERVICE_DRAWDEFLTS
362 : : "", // SC_SERVICE_DOCSPRSETT
363 : : "", // SC_SERVICE_DOCCONF
364 : : "", // SC_SERVICE_IMAP_RECT
365 : : "", // SC_SERVICE_IMAP_CIRC
366 : : "", // SC_SERVICE_IMAP_POLY
367 : :
368 : : // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
369 : : "", // SC_SERVICE_EXPORT_GOR
370 : : "", // SC_SERVICE_IMPORT_GOR
371 : : "", // SC_SERVICE_EXPORT_EOR
372 : : "", // SC_SERVICE_IMPORT_EOR
373 : :
374 : : "", // SC_SERVICE_VALBIND
375 : : "", // SC_SERVICE_LISTCELLBIND
376 : : "", // SC_SERVICE_LISTSOURCE
377 : : "", // SC_SERVICE_CELLADDRESS
378 : : "", // SC_SERVICE_RANGEADDRESS
379 : : "", // SC_SERVICE_SHEETDOCSET
380 : : "", // SC_SERVICE_CHDATAPROV
381 : : "", // SC_SERVICE_FORMULAPARS
382 : : "", // SC_SERVICE_OPCODEMAPPER
383 : : "", // SC_SERVICE_VBAOBJECTPROVIDER
384 : : "", // SC_SERVICE_VBACODENAMEPROVIDER
385 : : "", // SC_SERVICE_VBAGLOBALS
386 : : "", // SC_SERVICE_EXT_TIMEFIELD
387 : : };
388 : :
389 : :
390 : :
391 : :
392 : : //------------------------------------------------------------------------
393 : :
394 : : // alles static
395 : :
396 : :
397 : 2810 : sal_uInt16 ScServiceProvider::GetProviderType(const String& rServiceName)
398 : : {
399 [ + - ]: 2810 : if (rServiceName.Len())
400 : : {
401 : : const sal_uInt16 nEntries =
402 : 2810 : sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
403 [ + + ]: 54120 : for (sal_uInt16 i = 0; i < nEntries; i++)
404 : : {
405 [ + + ]: 53895 : if (rServiceName.EqualsAscii( aProvNamesId[i].pName ))
406 : : {
407 : 2585 : return aProvNamesId[i].nType;
408 : : }
409 : : }
410 : :
411 : : sal_uInt16 i;
412 [ + + ]: 10125 : for (i=0; i<SC_SERVICE_COUNT; i++)
413 : : {
414 : : OSL_ENSURE( aOldNames[i], "ScServiceProvider::GetProviderType: no oldname => crash");
415 [ - + ]: 9900 : if (rServiceName.EqualsAscii( aOldNames[i] ))
416 : : {
417 : : OSL_FAIL("old service name used");
418 : 0 : return i;
419 : : }
420 : : }
421 : : }
422 : 2810 : return SC_SERVICE_INVALID;
423 : : }
424 : :
425 : : namespace {
426 : :
427 : 917 : sal_Int32 getFieldType(sal_uInt16 nOldType)
428 : : {
429 [ + + + + : 917 : switch (nOldType)
+ + + + +
- ]
430 : : {
431 : : case SC_SERVICE_URLFIELD:
432 : 16 : return text::textfield::Type::URL;
433 : : case SC_SERVICE_PAGEFIELD:
434 : 251 : return text::textfield::Type::PAGE;
435 : : case SC_SERVICE_PAGESFIELD:
436 : 95 : return text::textfield::Type::PAGES;
437 : : case SC_SERVICE_DATEFIELD:
438 : 4 : return text::textfield::Type::DATE;
439 : : case SC_SERVICE_TIMEFIELD:
440 : 7 : return text::textfield::Type::TIME;
441 : : case SC_SERVICE_EXT_TIMEFIELD:
442 : 194 : return text::textfield::Type::EXTENDED_TIME;
443 : : case SC_SERVICE_TITLEFIELD:
444 : 97 : return text::textfield::Type::DOCINFO_TITLE;
445 : : case SC_SERVICE_FILEFIELD:
446 : 2 : return text::textfield::Type::EXTENDED_FILE;
447 : : case SC_SERVICE_SHEETFIELD:
448 : 251 : return text::textfield::Type::TABLE;
449 : : default:
450 : : ;
451 : : }
452 : :
453 : 917 : return text::textfield::Type::URL; // default to URL for no reason whatsoever.
454 : : }
455 : :
456 : : }
457 : :
458 : 2570 : uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
459 : : sal_uInt16 nType, ScDocShell* pDocShell )
460 : : {
461 : 2570 : uno::Reference<uno::XInterface> xRet;
462 [ + + + + : 2570 : switch (nType)
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + - ]
463 : : {
464 : : case SC_SERVICE_SHEET:
465 : : // noch nicht eingefuegt - DocShell=Null
466 [ + - ][ + - ]: 1 : xRet.set((sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0));
[ + - ]
467 : 1 : break;
468 : : case SC_SERVICE_URLFIELD:
469 : : case SC_SERVICE_PAGEFIELD:
470 : : case SC_SERVICE_PAGESFIELD:
471 : : case SC_SERVICE_DATEFIELD:
472 : : case SC_SERVICE_TIMEFIELD:
473 : : case SC_SERVICE_EXT_TIMEFIELD:
474 : : case SC_SERVICE_TITLEFIELD:
475 : : case SC_SERVICE_FILEFIELD:
476 : : case SC_SERVICE_SHEETFIELD:
477 : : {
478 : 917 : uno::Reference<text::XTextRange> xNullContent;
479 : : xRet.set(static_cast<text::XTextField*>(
480 [ + - ][ + - ]: 917 : new ScEditFieldObj(xNullContent, NULL, getFieldType(nType), ESelection())));
[ + - ]
481 : : }
482 : 917 : break;
483 : : case SC_SERVICE_CELLSTYLE:
484 [ + - ][ + - ]: 62 : xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ));
[ + - ][ + - ]
[ + - ]
485 : 62 : break;
486 : : case SC_SERVICE_PAGESTYLE:
487 [ + - ][ + - ]: 67 : xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, String() ));
[ + - ][ + - ]
[ + - ]
488 : 67 : break;
489 : : case SC_SERVICE_AUTOFORMAT:
490 [ + - ][ + - ]: 3 : xRet.set((container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ));
[ + - ]
491 : 3 : break;
492 : : case SC_SERVICE_CELLRANGES:
493 : : // wird nicht eingefuegt, sondern gefuellt
494 : : // -> DocShell muss gesetzt sein, aber leere Ranges
495 [ + - ]: 754 : if (pDocShell)
496 [ + - ][ + - ]: 754 : xRet.set((sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ));
[ + - ][ + - ]
[ + - ]
497 : 754 : break;
498 : :
499 : : case SC_SERVICE_DOCDEFLTS:
500 [ + - ]: 98 : if (pDocShell)
501 [ + - ][ + - ]: 98 : xRet.set((beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ));
[ + - ]
502 : 98 : break;
503 : : case SC_SERVICE_DRAWDEFLTS:
504 [ + - ]: 10 : if (pDocShell)
505 [ + - ][ + - ]: 10 : xRet.set((beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ));
[ + - ]
506 : 10 : break;
507 : :
508 : : // Drawing layer tables are not in SvxUnoDrawMSFactory,
509 : : // because SvxUnoDrawMSFactory doesn't have a SdrModel pointer.
510 : : // Drawing layer is always allocated if not there (MakeDrawLayer).
511 : :
512 : : case SC_SERVICE_GRADTAB:
513 [ + - ]: 3 : if (pDocShell)
514 [ + - ][ + - ]: 3 : xRet.set(SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
[ + - ]
515 : 3 : break;
516 : : case SC_SERVICE_HATCHTAB:
517 [ + - ]: 3 : if (pDocShell)
518 [ + - ][ + - ]: 3 : xRet.set(SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ));
[ + - ]
519 : 3 : break;
520 : : case SC_SERVICE_BITMAPTAB:
521 [ + - ]: 3 : if (pDocShell)
522 [ + - ][ + - ]: 3 : xRet.set(SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ));
[ + - ]
523 : 3 : break;
524 : : case SC_SERVICE_TRGRADTAB:
525 [ + - ]: 4 : if (pDocShell)
526 [ + - ][ + - ]: 4 : xRet.set(SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ));
[ + - ]
527 : 4 : break;
528 : : case SC_SERVICE_MARKERTAB:
529 [ + - ]: 14 : if (pDocShell)
530 [ + - ][ + - ]: 14 : xRet.set(SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ));
[ + - ]
531 : 14 : break;
532 : : case SC_SERVICE_DASHTAB:
533 [ + - ]: 3 : if (pDocShell)
534 [ + - ][ + - ]: 3 : xRet.set(SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ));
[ + - ]
535 : 3 : break;
536 : : case SC_SERVICE_NUMRULES:
537 [ + - ]: 1 : if (pDocShell)
538 [ + - ][ + - ]: 1 : xRet.set(SvxCreateNumRule( pDocShell->MakeDrawLayer() ));
539 : 1 : break;
540 : : case SC_SERVICE_DOCSPRSETT:
541 : : case SC_SERVICE_SHEETDOCSET:
542 : : case SC_SERVICE_DOCCONF:
543 [ + - ]: 104 : if (pDocShell)
544 [ + - ][ + - ]: 104 : xRet.set((beans::XPropertySet*)new ScDocumentConfiguration(pDocShell));
[ + - ]
545 : 104 : break;
546 : :
547 : : case SC_SERVICE_IMAP_RECT:
548 [ + - ][ + - ]: 1 : xRet.set(SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
[ + - ]
549 : 1 : break;
550 : : case SC_SERVICE_IMAP_CIRC:
551 [ + - ][ + - ]: 1 : xRet.set(SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
[ + - ]
552 : 1 : break;
553 : : case SC_SERVICE_IMAP_POLY:
554 [ + - ][ + - ]: 1 : xRet.set(SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ));
[ + - ]
555 : 1 : break;
556 : :
557 : : // Support creation of GraphicObjectResolver and EmbeddedObjectResolver
558 : : case SC_SERVICE_EXPORT_GOR:
559 [ + - ][ + - ]: 9 : xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ));
560 : 9 : break;
561 : :
562 : : case SC_SERVICE_IMPORT_GOR:
563 [ + - ][ + - ]: 188 : xRet.set((::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ));
564 : 188 : break;
565 : :
566 : : case SC_SERVICE_EXPORT_EOR:
567 [ + - ]: 9 : if (pDocShell)
568 [ + - ][ + - ]: 9 : xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ));
569 : 9 : break;
570 : :
571 : : case SC_SERVICE_IMPORT_EOR:
572 [ + - ]: 188 : if (pDocShell)
573 [ + - ][ + - ]: 188 : xRet.set((::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ));
574 : 188 : break;
575 : :
576 : : case SC_SERVICE_VALBIND:
577 : : case SC_SERVICE_LISTCELLBIND:
578 [ + - ]: 14 : if (pDocShell)
579 : : {
580 : 14 : sal_Bool bListPos = ( nType == SC_SERVICE_LISTCELLBIND );
581 [ + - ][ + - ]: 14 : uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
582 [ + - ][ + - ]: 14 : xRet.set(*new calc::OCellValueBinding( xDoc, bListPos ));
[ + - ]
583 : : }
584 : 14 : break;
585 : : case SC_SERVICE_LISTSOURCE:
586 [ + - ]: 1 : if (pDocShell)
587 : : {
588 [ + - ][ + - ]: 1 : uno::Reference<sheet::XSpreadsheetDocument> xDoc( pDocShell->GetBaseModel(), uno::UNO_QUERY );
589 [ + - ][ + - ]: 1 : xRet.set(*new calc::OCellListSource( xDoc ));
[ + - ]
590 : : }
591 : 1 : break;
592 : : case SC_SERVICE_CELLADDRESS:
593 : : case SC_SERVICE_RANGEADDRESS:
594 [ + - ]: 2 : if (pDocShell)
595 : : {
596 : 2 : sal_Bool bRange = ( nType == SC_SERVICE_RANGEADDRESS );
597 [ + - ][ + - ]: 2 : xRet.set(*new ScAddressConversionObj( pDocShell, bRange ));
[ + - ]
598 : : }
599 : 2 : break;
600 : :
601 : : case SC_SERVICE_CHDATAPROV:
602 [ + - ][ + - ]: 4 : if (pDocShell && pDocShell->GetDocument())
[ + - ]
603 [ + - ][ + - ]: 4 : xRet = *new ScChart2DataProvider( pDocShell->GetDocument() );
[ + - ]
604 : 4 : break;
605 : :
606 : : case SC_SERVICE_FORMULAPARS:
607 [ + - ]: 25 : if (pDocShell)
608 [ + - ][ + - ]: 25 : xRet.set(static_cast<sheet::XFormulaParser*>(new ScFormulaParserObj( pDocShell )));
[ + - ]
609 : 25 : break;
610 : :
611 : : case SC_SERVICE_OPCODEMAPPER:
612 [ + - ]: 25 : if (pDocShell)
613 : : {
614 : 25 : ScDocument* pDoc = pDocShell->GetDocument();
615 : 25 : ScAddress aAddress;
616 [ + - ][ + - ]: 25 : ScCompiler* pComp = new ScCompiler(pDoc,aAddress);
617 [ + - ][ + - ]: 25 : pComp->SetGrammar( pDoc->GetGrammar() );
618 [ + - ][ + - ]: 25 : xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
[ + - ][ + - ]
[ + - ]
619 : : break;
620 : : }
621 : : #ifndef DISABLE_SCRIPTING
622 : : case SC_SERVICE_VBAOBJECTPROVIDER:
623 [ + - ][ + - ]: 14 : if (pDocShell && pDocShell->GetDocument()->IsInVBAMode())
[ + + ][ + + ]
624 : : {
625 : : OSL_TRACE("**** creating VBA Object mapper");
626 [ + + ][ + - ]: 13 : xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
[ + - ]
627 : : }
628 : 5 : break;
629 : : case SC_SERVICE_VBACODENAMEPROVIDER:
630 [ + - ][ + - ]: 22 : if ( pDocShell && ooo::vba::isAlienExcelDoc( *pDocShell ) && isInVBAMode( *pDocShell ) )
[ + + ][ + - ]
[ + - ][ + + ]
631 : : {
632 : : OSL_TRACE("**** creating VBA Object provider");
633 [ + - ][ + - ]: 2 : xRet.set(static_cast<document::XCodeNameQuery*>(new ScVbaCodeNameProvider(*pDocShell)));
[ + - ]
634 : : }
635 : 22 : break;
636 : : case SC_SERVICE_VBAGLOBALS:
637 [ + - ]: 19 : if (pDocShell)
638 : : {
639 : 19 : uno::Any aGlobs;
640 [ + - ][ + + ]: 19 : if ( !pDocShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aGlobs ) )
[ + - ]
641 : : {
642 [ + - ]: 14 : uno::Sequence< uno::Any > aArgs(1);
643 [ + - ][ + - ]: 14 : aArgs[ 0 ] <<= pDocShell->GetModel();
[ + - ]
644 [ + - ][ + - ]: 14 : xRet = ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
[ + - ][ + - ]
[ + - ]
645 [ + - ][ + - ]: 14 : pDocShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", uno::Any( xRet ) );
[ + - ]
646 [ + - ][ + - ]: 14 : BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
647 [ + - ]: 14 : if ( pAppMgr )
648 [ + - ][ + - ]: 14 : pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
649 : :
650 : : // create the VBA document event processor
651 : : uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents(
652 [ + + ][ + - ]: 14 : ::ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBASpreadsheetEventProcessor", aArgs ), uno::UNO_QUERY );
653 [ + - ][ + - ]: 14 : pDocShell->GetDocument()->SetVbaEventProcessor( xVbaEvents );
654 : 19 : }
655 : : }
656 : 10 : break;
657 : : #endif
658 : : }
659 : :
660 : 2570 : return xRet;
661 : : }
662 : :
663 : 10 : uno::Sequence<rtl::OUString> ScServiceProvider::GetAllServiceNames()
664 : : {
665 : 10 : const sal_uInt16 nEntries = sizeof(aProvNamesId) / sizeof(aProvNamesId[0]);
666 : 10 : uno::Sequence<rtl::OUString> aRet(nEntries);
667 [ + - ]: 10 : rtl::OUString* pArray = aRet.getArray();
668 [ + + ]: 550 : for (sal_uInt16 i = 0; i < nEntries; i++)
669 : : {
670 : 540 : pArray[i] = rtl::OUString::createFromAscii( aProvNamesId[i].pName );
671 : : }
672 : 10 : return aRet;
673 : : }
674 : :
675 : :
676 : :
677 : :
678 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|