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