Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / sc / source / ui / unoobj / docuno.cxx
blob9aeceb7c731475ace99ecc2168be29cc3bb5776d
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 "scitems.hxx"
21 #include <svx/fmdpage.hxx>
22 #include <svx/fmview.hxx>
23 #include <svx/svditer.hxx>
24 #include <svx/svdpage.hxx>
25 #include <svx/svxids.hrc>
26 #include <svx/unoshape.hxx>
28 #include <officecfg/Office/Common.hxx>
29 #include <svl/numuno.hxx>
30 #include <svl/smplhint.hxx>
31 #include <unotools/moduleoptions.hxx>
32 #include <sfx2/printer.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <vcl/pdfextoutdevdata.hxx>
35 #include <vcl/waitobj.hxx>
36 #include <unotools/charclass.hxx>
37 #include <tools/multisel.hxx>
38 #include <tools/resary.hxx>
39 #include <toolkit/awt/vclxdevice.hxx>
41 #include <ctype.h>
42 #include <float.h>
44 #include <com/sun/star/util/Date.hpp>
45 #include <com/sun/star/sheet/XNamedRanges.hpp>
46 #include <com/sun/star/sheet/XLabelRanges.hpp>
47 #include <com/sun/star/sheet/XSelectedSheetsSupplier.hpp>
48 #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
49 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
50 #include <com/sun/star/script/XLibraryContainer.hpp>
51 #include <com/sun/star/lang/XInitialization.hpp>
52 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
53 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
54 #include <com/sun/star/document/IndexedPropertyValues.hpp>
55 #include <com/sun/star/script/XInvocation.hpp>
56 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
57 #include <comphelper/processfactory.hxx>
58 #include <comphelper/servicehelper.hxx>
59 #include <comphelper/string.hxx>
60 #include <cppuhelper/supportsservice.hxx>
62 #include "docuno.hxx"
63 #include "cellsuno.hxx"
64 #include "nameuno.hxx"
65 #include "datauno.hxx"
66 #include "miscuno.hxx"
67 #include "notesuno.hxx"
68 #include "styleuno.hxx"
69 #include "linkuno.hxx"
70 #include "servuno.hxx"
71 #include "targuno.hxx"
72 #include "convuno.hxx"
73 #include "optuno.hxx"
74 #include "forbiuno.hxx"
75 #include "docsh.hxx"
76 #include "hints.hxx"
77 #include "docfunc.hxx"
78 #include "postit.hxx"
79 #include "dociter.hxx"
80 #include "formulacell.hxx"
81 #include "drwlayer.hxx"
82 #include "rangeutl.hxx"
83 #include "markdata.hxx"
84 #include "docoptio.hxx"
85 #include "unonames.hxx"
86 #include "shapeuno.hxx"
87 #include "viewuno.hxx"
88 #include "tabvwsh.hxx"
89 #include "printfun.hxx"
90 #include "pfuncache.hxx"
91 #include "scmod.hxx"
92 #include "ViewSettingsSequenceDefines.hxx"
93 #include "sheetevents.hxx"
94 #include "sc.hrc"
95 #include "scresid.hxx"
96 #include "platforminfo.hxx"
97 #include "interpre.hxx"
98 #include "formulagroup.hxx"
99 #include <columnspanset.hxx>
101 using namespace com::sun::star;
103 // #i111553# provides the name of the VBA constant for this document type (e.g. 'ThisExcelDoc' for Calc)
104 #define SC_UNO_VBAGLOBNAME "VBAGlobalConstantName"
106 // alles ohne Which-ID, Map nur fuer PropertySetInfo
108 //! umbenennen, sind nicht mehr nur Options
109 static const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap()
111 static const SfxItemPropertyMapEntry aDocOptPropertyMap_Impl[] =
113 {OUString(SC_UNO_APPLYFMDES), 0, getBooleanCppuType(), 0, 0},
114 {OUString(SC_UNO_AREALINKS), 0, cppu::UnoType<sheet::XAreaLinks>::get(), 0, 0},
115 {OUString(SC_UNO_AUTOCONTFOC), 0, getBooleanCppuType(), 0, 0},
116 {OUString(SC_UNO_BASICLIBRARIES), 0, cppu::UnoType<script::XLibraryContainer>::get(), beans::PropertyAttribute::READONLY, 0},
117 {OUString(SC_UNO_DIALOGLIBRARIES), 0, cppu::UnoType<script::XLibraryContainer>::get(), beans::PropertyAttribute::READONLY, 0},
118 {OUString(SC_UNO_VBAGLOBNAME), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0},
119 {OUString(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN, getBooleanCppuType(), 0, 0},
120 {OUString(SC_UNONAME_CLOCAL), 0, cppu::UnoType<lang::Locale>::get(), 0, 0},
121 {OUString(SC_UNO_CJK_CLOCAL), 0, cppu::UnoType<lang::Locale>::get(), 0, 0},
122 {OUString(SC_UNO_CTL_CLOCAL), 0, cppu::UnoType<lang::Locale>::get(), 0, 0},
123 {OUString(SC_UNO_COLLABELRNG), 0, cppu::UnoType<sheet::XLabelRanges>::get(), 0, 0},
124 {OUString(SC_UNO_DDELINKS), 0, cppu::UnoType<container::XNameAccess>::get(), 0, 0},
125 {OUString(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP, cppu::UnoType<sal_Int16>::get(), 0, 0},
126 {OUString(SC_UNO_EXTERNALDOCLINKS), 0, cppu::UnoType<sheet::XExternalDocLinks>::get(), 0, 0},
127 {OUString(SC_UNO_FORBIDDEN), 0, cppu::UnoType<i18n::XForbiddenCharacters>::get(), beans::PropertyAttribute::READONLY, 0},
128 {OUString(SC_UNO_HASDRAWPAGES), 0, getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
129 {OUString(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE, getBooleanCppuType(), 0, 0},
130 {OUString(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED, getBooleanCppuType(), 0, 0},
131 {OUString(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT, cppu::UnoType<sal_Int32>::get(), 0, 0},
132 {OUString(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON, cppu::UnoType<double>::get(), 0, 0},
133 {OUString(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, getBooleanCppuType(), 0, 0},
134 {OUString(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE, getBooleanCppuType(), 0, 0},
135 {OUString(SC_UNO_NAMEDRANGES), 0, cppu::UnoType<sheet::XNamedRanges>::get(), 0, 0},
136 {OUString(SC_UNO_DATABASERNG), 0, cppu::UnoType<sheet::XDatabaseRanges>::get(), 0, 0},
137 {OUString(SC_UNO_NULLDATE), PROP_UNO_NULLDATE, cppu::UnoType<util::Date>::get(), 0, 0},
138 {OUString(SC_UNO_ROWLABELRNG), 0, cppu::UnoType<sheet::XLabelRanges>::get(), 0, 0},
139 {OUString(SC_UNO_SHEETLINKS), 0, cppu::UnoType<container::XNameAccess>::get(), 0, 0},
140 {OUString(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE, getBooleanCppuType(), 0, 0},
141 {OUString(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC, cppu::UnoType<sal_Int16>::get(), 0, 0},
142 {OUString(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, getBooleanCppuType(), 0, 0},
143 {OUString(SC_UNO_RUNTIMEUID), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0},
144 {OUString(SC_UNO_HASVALIDSIGNATURES), 0, getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
145 {OUString(SC_UNO_ISLOADED), 0, getBooleanCppuType(), 0, 0},
146 {OUString(SC_UNO_ISUNDOENABLED), 0, getBooleanCppuType(), 0, 0},
147 {OUString(SC_UNO_ISADJUSTHEIGHTENABLED), 0, getBooleanCppuType(), 0, 0},
148 {OUString(SC_UNO_ISEXECUTELINKENABLED), 0, getBooleanCppuType(), 0, 0},
149 {OUString(SC_UNO_ISCHANGEREADONLYENABLED), 0, getBooleanCppuType(), 0, 0},
150 {OUString(SC_UNO_REFERENCEDEVICE), 0, cppu::UnoType<awt::XDevice>::get(), beans::PropertyAttribute::READONLY, 0},
151 {OUString("BuildId"), 0, ::cppu::UnoType<OUString>::get(), 0, 0},
152 {OUString(SC_UNO_CODENAME), 0, cppu::UnoType<OUString>::get(), 0, 0},
153 {OUString(SC_UNO_INTEROPGRABBAG), 0, ::getCppuType((uno::Sequence< beans::PropertyValue >*)0), 0, 0},
154 { OUString(), 0, css::uno::Type(), 0, 0 }
156 return aDocOptPropertyMap_Impl;
159 //! StandardDecimals als Property und vom NumberFormatter ????????
161 static const SfxItemPropertyMapEntry* lcl_GetColumnsPropertyMap()
163 static const SfxItemPropertyMapEntry aColumnsPropertyMap_Impl[] =
165 {OUString(SC_UNONAME_MANPAGE), 0, getBooleanCppuType(), 0, 0 },
166 {OUString(SC_UNONAME_NEWPAGE), 0, getBooleanCppuType(), 0, 0 },
167 {OUString(SC_UNONAME_CELLVIS), 0, getBooleanCppuType(), 0, 0 },
168 {OUString(SC_UNONAME_OWIDTH), 0, getBooleanCppuType(), 0, 0 },
169 {OUString(SC_UNONAME_CELLWID), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
170 { OUString(), 0, css::uno::Type(), 0, 0 }
172 return aColumnsPropertyMap_Impl;
175 static const SfxItemPropertyMapEntry* lcl_GetRowsPropertyMap()
177 static const SfxItemPropertyMapEntry aRowsPropertyMap_Impl[] =
179 {OUString(SC_UNONAME_CELLHGT), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
180 {OUString(SC_UNONAME_CELLFILT), 0, getBooleanCppuType(), 0, 0 },
181 {OUString(SC_UNONAME_OHEIGHT), 0, getBooleanCppuType(), 0, 0 },
182 {OUString(SC_UNONAME_MANPAGE), 0, getBooleanCppuType(), 0, 0 },
183 {OUString(SC_UNONAME_NEWPAGE), 0, getBooleanCppuType(), 0, 0 },
184 {OUString(SC_UNONAME_CELLVIS), 0, getBooleanCppuType(), 0, 0 },
185 {OUString(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, ::cppu::UnoType<sal_Int32>::get(), 0, MID_BACK_COLOR },
186 {OUString(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, ::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT },
187 // not sorted, not used with SfxItemPropertyMapEntry::GetByName
188 { OUString(), 0, css::uno::Type(), 0, 0 }
190 return aRowsPropertyMap_Impl;
193 using sc::HMMToTwips;
194 using sc::TwipsToHMM;
196 #define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument"
197 #define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings"
198 #define SCDOC_SERVICE "com.sun.star.document.OfficeDocument"
200 SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
201 SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
202 SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" )
203 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" )
204 SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" )
205 SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" )
206 SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" )
208 class ScPrintUIOptions : public vcl::PrinterOptionsHelper
210 public:
211 ScPrintUIOptions();
212 void SetDefaults();
215 ScPrintUIOptions::ScPrintUIOptions()
217 const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
218 sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
219 bool bSuppress = rPrintOpt.GetSkipEmpty();
221 ResStringArray aStrings( ScResId( SCSTR_PRINT_OPTIONS ) );
222 OSL_ENSURE( aStrings.Count() >= 10, "resource incomplete" );
223 if( aStrings.Count() < 10 ) // bad resource ?
224 return;
226 sal_Int32 nNumProps= 9, nIdx = 0;
228 m_aUIProperties.realloc(nNumProps);
230 // load the writer PrinterOptions into the custom tab
231 m_aUIProperties[nIdx].Name = "OptionsUIFile";
232 m_aUIProperties[nIdx++].Value <<= OUString("modules/scalc/ui/printeroptions.ui");
234 // create Section for spreadsheet (results in an extra tab page in dialog)
235 SvtModuleOptions aOpt;
236 OUString aAppGroupname( aStrings.GetString( 9 ) );
237 aAppGroupname = aAppGroupname.replaceFirst( "%s", aOpt.GetModuleName( SvtModuleOptions::E_SCALC ) );
238 m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, OUString());
240 // show subgroup for pages
241 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("pages", OUString(aStrings.GetString(0)), OUString());
243 // create a bool option for empty pages
244 m_aUIProperties[nIdx++].Value = setBoolControlOpt("includeemptypages", OUString( aStrings.GetString( 1 ) ),
245 ".HelpID:vcl:PrintDialog:IsIncludeEmptyPages:CheckBox",
246 "IsIncludeEmptyPages",
247 ! bSuppress);
248 // show Subgroup for print content
249 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
250 aPrintRangeOpt.maGroupHint = "PrintRange";
251 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("printrange", OUString(aStrings.GetString(2)),
252 OUString(),
253 aPrintRangeOpt);
255 // create a choice for the content to create
256 uno::Sequence< OUString > aChoices( 3 ), aHelpIds( 3 ), aWidgetIds( 3 );
257 aChoices[0] = aStrings.GetString( 3 );
258 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0";
259 aWidgetIds[0] = "printallsheets";
260 aChoices[1] = aStrings.GetString( 4 );
261 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1";
262 aWidgetIds[1] = "printselectedsheets";
263 aChoices[2] = aStrings.GetString( 5 );
264 aHelpIds[2] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2";
265 aWidgetIds[2] = "printselectedcells";
266 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
267 aHelpIds, "PrintContent",
268 aChoices, nContent );
270 // show Subgroup for print range
271 aPrintRangeOpt.mbInternalOnly = true;
272 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("fromwhich", OUString(aStrings.GetString(6)),
273 OUString(),
274 aPrintRangeOpt);
276 // create a choice for the range to print
277 OUString aPrintRangeName( "PrintRange" );
278 aChoices.realloc( 2 );
279 aHelpIds.realloc( 2 );
280 aWidgetIds.realloc( 2 );
281 aChoices[0] = aStrings.GetString( 7 );
282 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:0";
283 aWidgetIds[0] = "printallpages";
284 aChoices[1] = aStrings.GetString( 8 );
285 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:1";
286 aWidgetIds[1] = "printpages";
287 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
288 aHelpIds,
289 aPrintRangeName,
290 aChoices,
291 0 );
293 // create a an Edit dependent on "Pages" selected
294 vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintRangeName, 1, true );
295 m_aUIProperties[nIdx++].Value = setEditControlOpt("pagerange", OUString(),
296 ".HelpID:vcl:PrintDialog:PageRange:Edit",
297 "PageRange", OUString(), aPageRangeOpt);
299 assert(nIdx == nNumProps);
302 void ScPrintUIOptions::SetDefaults()
304 // re-initialize the default values from print options
306 const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
307 sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
308 bool bSuppress = rPrintOpt.GetSkipEmpty();
310 for (sal_Int32 nUIPos=0; nUIPos<m_aUIProperties.getLength(); ++nUIPos)
312 uno::Sequence<beans::PropertyValue> aUIProp;
313 if ( m_aUIProperties[nUIPos].Value >>= aUIProp )
315 for (sal_Int32 nPropPos=0; nPropPos<aUIProp.getLength(); ++nPropPos)
317 OUString aName = aUIProp[nPropPos].Name;
318 if ( aName == "Property" )
320 beans::PropertyValue aPropertyValue;
321 if ( aUIProp[nPropPos].Value >>= aPropertyValue )
323 if ( aPropertyValue.Name == "PrintContent" )
325 aPropertyValue.Value <<= nContent;
326 aUIProp[nPropPos].Value <<= aPropertyValue;
328 else if ( aPropertyValue.Name == "IsIncludeEmptyPages" )
330 ScUnoHelpFunctions::SetBoolInAny( aPropertyValue.Value, ! bSuppress );
331 aUIProp[nPropPos].Value <<= aPropertyValue;
336 m_aUIProperties[nUIPos].Value <<= aUIProp;
341 void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
343 if (pDocSh)
344 pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
347 ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
348 SfxBaseModel( pDocSh ),
349 aPropSet( lcl_GetDocOptPropertyMap() ),
350 pDocShell( pDocSh ),
351 pPrintFuncCache( NULL ),
352 pPrinterOptions( NULL ),
353 maChangesListeners( m_aMutex )
355 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
356 if ( pDocShell )
358 pDocShell->GetDocument()->AddUnoObject(*this); // SfxModel is derived from SfxListener
362 ScModelObj::~ScModelObj()
364 if (pDocShell)
365 pDocShell->GetDocument()->RemoveUnoObject(*this);
367 if (xNumberAgg.is())
368 xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
370 delete pPrintFuncCache;
371 delete pPrinterOptions;
374 uno::Reference< uno::XAggregation> ScModelObj::GetFormatter()
376 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
377 if ( !xNumberAgg.is() && pDocShell )
379 // setDelegator veraendert den RefCount, darum eine Referenz selber halten
380 // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen)
381 comphelper::increment( m_refCount );
382 // waehrend des queryInterface braucht man ein Ref auf das
383 // SvNumberFormatsSupplierObj, sonst wird es geloescht.
384 uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument()->GetFormatTable() ));
386 xNumberAgg.set(uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ));
387 // extra block to force deletion of the temporary before setDelegator
390 // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren
391 xFormatter = NULL;
393 if (xNumberAgg.is())
394 xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
395 comphelper::decrement( m_refCount );
396 } // if ( !xNumberAgg.is() )
397 return xNumberAgg;
400 ScDocument* ScModelObj::GetDocument() const
402 if (pDocShell)
403 return pDocShell->GetDocument();
404 return NULL;
407 SfxObjectShell* ScModelObj::GetEmbeddedObject() const
409 return pDocShell;
412 void ScModelObj::UpdateAllRowHeights()
414 if (pDocShell)
415 pDocShell->UpdateAllRowHeights(NULL);
418 void ScModelObj::BeforeXMLLoading()
420 if (pDocShell)
421 pDocShell->BeforeXMLLoading();
424 void ScModelObj::AfterXMLLoading(bool bRet)
426 if (pDocShell)
427 pDocShell->AfterXMLLoading(bRet);
430 ScSheetSaveData* ScModelObj::GetSheetSaveData()
432 if (pDocShell)
433 return pDocShell->GetSheetSaveData();
434 return NULL;
437 void ScModelObj::RepaintRange( const ScRange& rRange )
439 if (pDocShell)
440 pDocShell->PostPaint( rRange, PAINT_GRID );
443 void ScModelObj::RepaintRange( const ScRangeList& rRange )
445 if (pDocShell)
446 pDocShell->PostPaint( rRange, PAINT_GRID );
449 uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
450 throw(uno::RuntimeException, std::exception)
452 SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
453 SC_QUERYINTERFACE( document::XActionLockable )
454 SC_QUERYINTERFACE( sheet::XCalculatable )
455 SC_QUERYINTERFACE( util::XProtectable )
456 SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
457 SC_QUERYINTERFACE( sheet::XGoalSeek )
458 SC_QUERYINTERFACE( sheet::XConsolidatable )
459 SC_QUERYINTERFACE( sheet::XDocumentAuditing )
460 SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
461 SC_QUERYINTERFACE( view::XRenderable )
462 SC_QUERYINTERFACE( document::XLinkTargetSupplier )
463 SC_QUERYINTERFACE( beans::XPropertySet )
464 SC_QUERYINTERFACE( lang::XMultiServiceFactory )
465 SC_QUERYINTERFACE( lang::XServiceInfo )
466 SC_QUERYINTERFACE( util::XChangesNotifier )
467 SC_QUERYINTERFACE( sheet::opencl::XOpenCLSelection )
469 uno::Any aRet(SfxBaseModel::queryInterface( rType ));
470 if ( !aRet.hasValue()
471 && rType != cppu::UnoType<com::sun::star::document::XDocumentEventBroadcaster>::get()
472 && rType != cppu::UnoType<com::sun::star::frame::XController>::get()
473 && rType != cppu::UnoType<com::sun::star::frame::XFrame>::get()
474 && rType != cppu::UnoType<com::sun::star::script::XInvocation>::get()
475 && rType != cppu::UnoType<com::sun::star::beans::XFastPropertySet>::get()
476 && rType != cppu::UnoType<com::sun::star::awt::XWindow>::get())
478 GetFormatter();
479 if ( xNumberAgg.is() )
480 aRet = xNumberAgg->queryAggregation( rType );
483 return aRet;
486 void SAL_CALL ScModelObj::acquire() throw()
488 SfxBaseModel::acquire();
491 void SAL_CALL ScModelObj::release() throw()
493 SfxBaseModel::release();
496 uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException, std::exception)
498 static uno::Sequence<uno::Type> aTypes;
499 if ( aTypes.getLength() == 0 )
501 uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
502 long nParentLen = aParentTypes.getLength();
503 const uno::Type* pParentPtr = aParentTypes.getConstArray();
505 uno::Sequence<uno::Type> aAggTypes;
506 if ( GetFormatter().is() )
508 const uno::Type& rProvType = cppu::UnoType<lang::XTypeProvider>::get();
509 uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
510 if(aNumProv.getValueType() == rProvType)
512 uno::Reference<lang::XTypeProvider> xNumProv(
513 *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue());
514 aAggTypes = xNumProv->getTypes();
517 long nAggLen = aAggTypes.getLength();
518 const uno::Type* pAggPtr = aAggTypes.getConstArray();
520 const long nThisLen = 16;
521 aTypes.realloc( nParentLen + nAggLen + nThisLen );
522 uno::Type* pPtr = aTypes.getArray();
523 pPtr[nParentLen + 0] = cppu::UnoType<sheet::XSpreadsheetDocument>::get();
524 pPtr[nParentLen + 1] = cppu::UnoType<document::XActionLockable>::get();
525 pPtr[nParentLen + 2] = cppu::UnoType<sheet::XCalculatable>::get();
526 pPtr[nParentLen + 3] = cppu::UnoType<util::XProtectable>::get();
527 pPtr[nParentLen + 4] = cppu::UnoType<drawing::XDrawPagesSupplier>::get();
528 pPtr[nParentLen + 5] = cppu::UnoType<sheet::XGoalSeek>::get();
529 pPtr[nParentLen + 6] = cppu::UnoType<sheet::XConsolidatable>::get();
530 pPtr[nParentLen + 7] = cppu::UnoType<sheet::XDocumentAuditing>::get();
531 pPtr[nParentLen + 8] = cppu::UnoType<style::XStyleFamiliesSupplier>::get();
532 pPtr[nParentLen + 9] = cppu::UnoType<view::XRenderable>::get();
533 pPtr[nParentLen +10] = cppu::UnoType<document::XLinkTargetSupplier>::get();
534 pPtr[nParentLen +11] = cppu::UnoType<beans::XPropertySet>::get();
535 pPtr[nParentLen +12] = cppu::UnoType<lang::XMultiServiceFactory>::get();
536 pPtr[nParentLen +13] = cppu::UnoType<lang::XServiceInfo>::get();
537 pPtr[nParentLen +14] = cppu::UnoType<util::XChangesNotifier>::get();
538 pPtr[nParentLen +15] = cppu::UnoType<sheet::opencl::XOpenCLSelection>::get();
540 long i;
541 for (i=0; i<nParentLen; i++)
542 pPtr[i] = pParentPtr[i]; // parent types first
544 for (i=0; i<nAggLen; i++)
545 pPtr[nParentLen+nThisLen+i] = pAggPtr[i]; // aggregated types last
547 return aTypes;
550 uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId()
551 throw(uno::RuntimeException, std::exception)
553 return css::uno::Sequence<sal_Int8>();
556 void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
558 // Not interested in reference update hints here
560 if ( rHint.ISA( SfxSimpleHint ) )
562 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
563 if ( nId == SFX_HINT_DYING )
565 pDocShell = NULL; // has become invalid
566 if (xNumberAgg.is())
568 SvNumberFormatsSupplierObj* pNumFmt =
569 SvNumberFormatsSupplierObj::getImplementation(
570 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
571 if ( pNumFmt )
572 pNumFmt->SetNumberFormatter( NULL );
575 DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell
577 else if ( nId == SFX_HINT_DATACHANGED )
579 // cached data for rendering become invalid when contents change
580 // (if a broadcast is added to SetDrawModified, is has to be tested here, too)
582 DELETEZ( pPrintFuncCache );
584 // handle "OnCalculate" sheet events (search also for VBA event handlers)
585 if ( pDocShell )
587 ScDocument* pDoc = pDocShell->GetDocument();
588 if ( pDoc->GetVbaEventProcessor().is() )
590 // If the VBA event processor is set, HasAnyCalcNotification is much faster than HasAnySheetEventScript
591 if ( pDoc->HasAnyCalcNotification() && pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) )
592 HandleCalculateEvents();
594 else
596 if ( pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE ) )
597 HandleCalculateEvents();
602 else if ( rHint.ISA( ScPointerChangedHint ) )
604 sal_uInt16 nFlags = ((const ScPointerChangedHint&)rHint).GetFlags();
605 if (nFlags & SC_POINTERCHANGED_NUMFMT)
607 // NumberFormatter-Pointer am Uno-Objekt neu setzen
609 if (GetFormatter().is())
611 SvNumberFormatsSupplierObj* pNumFmt =
612 SvNumberFormatsSupplierObj::getImplementation(
613 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
614 if ( pNumFmt && pDocShell )
615 pNumFmt->SetNumberFormatter( pDocShell->GetDocument()->GetFormatTable() );
620 // always call parent - SfxBaseModel might need to handle the same hints again
621 SfxBaseModel::Notify( rBC, rHint ); // SfxBaseModel is derived from SfxListener
624 // XSpreadsheetDocument
626 uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException, std::exception)
628 SolarMutexGuard aGuard;
629 if (pDocShell)
630 return new ScTableSheetsObj(pDocShell);
631 return NULL;
634 // XStyleFamiliesSupplier
636 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
637 throw(uno::RuntimeException, std::exception)
639 SolarMutexGuard aGuard;
640 if (pDocShell)
641 return new ScStyleFamiliesObj(pDocShell);
642 return NULL;
645 // XRenderable
647 static OutputDevice* lcl_GetRenderDevice( const uno::Sequence<beans::PropertyValue>& rOptions )
649 OutputDevice* pRet = NULL;
650 const beans::PropertyValue* pPropArray = rOptions.getConstArray();
651 long nPropCount = rOptions.getLength();
652 for (long i = 0; i < nPropCount; i++)
654 const beans::PropertyValue& rProp = pPropArray[i];
655 OUString aPropName(rProp.Name);
657 if (aPropName.equalsAscii( SC_UNONAME_RENDERDEV ))
659 uno::Reference<awt::XDevice> xRenderDevice(rProp.Value, uno::UNO_QUERY);
660 if ( xRenderDevice.is() )
662 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
663 if ( pDevice )
665 pRet = pDevice->GetOutputDevice();
666 pRet->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
671 return pRet;
674 static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, Rectangle& rTargetRect,
675 bool& rIsSheet, ScDocument* pDoc, SCTAB nSourceTab )
677 // test in same order as in SID_CURRENTCELL execute
679 ScAddress aAddress;
680 ScRangeUtil aRangeUtil;
681 SCTAB nNameTab;
682 sal_Int32 nNumeric = 0;
684 bool bRangeValid = false;
685 bool bRectValid = false;
687 if ( rTargetRange.Parse( rTarget, pDoc ) & SCA_VALID )
689 bRangeValid = true; // range reference
691 else if ( aAddress.Parse( rTarget, pDoc ) & SCA_VALID )
693 rTargetRange = aAddress;
694 bRangeValid = true; // cell reference
696 else if ( aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_NAMES ) ||
697 aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_DBASE ) )
699 bRangeValid = true; // named range or database range
701 else if ( comphelper::string::isdigitAsciiString(rTarget) &&
702 ( nNumeric = rTarget.toInt32() ) > 0 && nNumeric <= MAXROW+1 )
704 // row number is always mapped to cell A(row) on the same sheet
705 rTargetRange = ScAddress( 0, (SCROW)(nNumeric-1), nSourceTab ); // target row number is 1-based
706 bRangeValid = true; // row number
708 else if ( pDoc->GetTable( rTarget, nNameTab ) )
710 rTargetRange = ScAddress(0,0,nNameTab);
711 bRangeValid = true; // sheet name
712 rIsSheet = true; // needs special handling (first page of the sheet)
714 else
716 // look for named drawing object
718 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
719 if ( pDrawLayer )
721 SCTAB nTabCount = pDoc->GetTableCount();
722 for (SCTAB i=0; i<nTabCount && !bRangeValid; i++)
724 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
725 OSL_ENSURE(pPage,"Page ?");
726 if (pPage)
728 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
729 SdrObject* pObject = aIter.Next();
730 while (pObject && !bRangeValid)
732 if ( ScDrawLayer::GetVisibleName( pObject ) == rTarget )
734 rTargetRect = pObject->GetLogicRect(); // 1/100th mm
735 rTargetRange = pDoc->GetRange( i, rTargetRect ); // underlying cells
736 bRangeValid = bRectValid = true; // rectangle is valid
738 pObject = aIter.Next();
744 if ( bRangeValid && !bRectValid )
746 // get rectangle for cell range
747 rTargetRect = pDoc->GetMMRect( rTargetRange.aStart.Col(), rTargetRange.aStart.Row(),
748 rTargetRange.aEnd.Col(), rTargetRange.aEnd.Row(),
749 rTargetRange.aStart.Tab() );
752 return bRangeValid;
755 bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
756 const uno::Sequence< beans::PropertyValue >& rOptions,
757 ScMarkData& rMark,
758 ScPrintSelectionStatus& rStatus, OUString& rPagesStr ) const
760 OSL_ENSURE( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
761 OSL_ENSURE( pDocShell, "FillRenderMarkData: DocShell must be set" );
763 bool bDone = false;
765 uno::Reference<frame::XController> xView;
767 // defaults when no options are passed: all sheets, include empty pages
768 bool bSelectedSheetsOnly = false;
769 bool bIncludeEmptyPages = true;
771 bool bHasPrintContent = false;
772 sal_Int32 nPrintContent = 0; // all sheets / selected sheets / selected cells
773 sal_Int32 nPrintRange = 0; // all pages / pages
774 OUString aPageRange; // "pages" edit value
776 for( sal_Int32 i = 0, nLen = rOptions.getLength(); i < nLen; i++ )
778 if ( rOptions[i].Name == "IsOnlySelectedSheets" )
780 rOptions[i].Value >>= bSelectedSheetsOnly;
782 else if ( rOptions[i].Name == "IsIncludeEmptyPages" )
784 rOptions[i].Value >>= bIncludeEmptyPages;
786 else if ( rOptions[i].Name == "PageRange" )
788 rOptions[i].Value >>= aPageRange;
790 else if ( rOptions[i].Name == "PrintRange" )
792 rOptions[i].Value >>= nPrintRange;
794 else if ( rOptions[i].Name == "PrintContent" )
796 bHasPrintContent = true;
797 rOptions[i].Value >>= nPrintContent;
799 else if ( rOptions[i].Name == "View" )
801 rOptions[i].Value >>= xView;
805 // "Print Content" selection wins over "Selected Sheets" option
806 if ( bHasPrintContent )
807 bSelectedSheetsOnly = ( nPrintContent != 0 );
809 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
810 if ( xInterface.is() )
812 ScCellRangesBase* pSelObj = ScCellRangesBase::getImplementation( xInterface );
813 uno::Reference< drawing::XShapes > xShapes( xInterface, uno::UNO_QUERY );
814 if ( pSelObj && pSelObj->GetDocShell() == pDocShell )
816 bool bSheet = ( ScTableSheetObj::getImplementation( xInterface ) != NULL );
817 bool bCursor = pSelObj->IsCursorOnly();
818 const ScRangeList& rRanges = pSelObj->GetRangeList();
820 rMark.MarkFromRangeList( rRanges, false );
821 rMark.MarkToSimple();
823 if ( rMark.IsMultiMarked() )
825 // #i115266# copy behavior of old printing:
826 // treat multiple selection like a single selection with the enclosing range
827 ScRange aMultiMarkArea;
828 rMark.GetMultiMarkArea( aMultiMarkArea );
829 rMark.ResetMark();
830 rMark.SetMarkArea( aMultiMarkArea );
833 if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
835 // a sheet object is treated like an empty selection: print the used area of the sheet
837 if ( bCursor || bSheet ) // nothing selected -> use whole tables
839 rMark.ResetMark(); // doesn't change table selection
840 rStatus.SetMode( SC_PRINTSEL_CURSOR );
842 else
843 rStatus.SetMode( SC_PRINTSEL_RANGE );
845 rStatus.SetRanges( rRanges );
846 bDone = true;
848 // multi selection isn't supported
850 else if( xShapes.is() )
852 //print a selected ole object
853 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY );
854 if( xIndexAccess.is() )
856 // multi selection isn't supported yet
857 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
858 SvxShape* pShape = SvxShape::getImplementation( xShape );
859 if( pShape )
861 SdrObject *pSdrObj = pShape->GetSdrObject();
862 if( pDocShell )
864 ScDocument* pDoc = pDocShell->GetDocument();
865 if( pDoc && pSdrObj )
867 Rectangle aObjRect = pSdrObj->GetCurrentBoundRect();
868 SCTAB nCurrentTab = ScDocShell::GetCurTab();
869 ScRange aRange = pDoc->GetRange( nCurrentTab, aObjRect );
870 rMark.SetMarkArea( aRange );
872 if( rMark.IsMarked() && !rMark.IsMultiMarked() )
874 rStatus.SetMode( SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS );
875 bDone = true;
882 else if ( ScModelObj::getImplementation( xInterface ) == this )
884 // render the whole document
885 // -> no selection, all sheets
887 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
888 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
889 rMark.SelectTable( nTab, true );
890 rStatus.SetMode( SC_PRINTSEL_DOCUMENT );
891 bDone = true;
893 // other selection types aren't supported
896 // restrict to selected sheets if a view is available
897 uno::Reference<sheet::XSelectedSheetsSupplier> xSelectedSheets(xView, uno::UNO_QUERY);
898 if (bSelectedSheetsOnly && xSelectedSheets.is())
900 uno::Sequence<sal_Int32> aSelected = xSelectedSheets->getSelectedSheets();
901 ScMarkData::MarkedTabsType aSelectedTabs;
902 SCTAB nMaxTab = pDocShell->GetDocument()->GetTableCount() -1;
903 for (sal_Int32 i = 0, n = aSelected.getLength(); i < n; ++i)
905 SCTAB nSelected = static_cast<SCTAB>(aSelected[i]);
906 if (ValidTab(nSelected, nMaxTab))
907 aSelectedTabs.insert(static_cast<SCTAB>(aSelected[i]));
909 rMark.SetSelectedTabs(aSelectedTabs);
912 ScPrintOptions aNewOptions;
913 aNewOptions.SetSkipEmpty( !bIncludeEmptyPages );
914 aNewOptions.SetAllSheets( !bSelectedSheetsOnly );
915 rStatus.SetOptions( aNewOptions );
917 // "PrintRange" enables (1) or disables (0) the "PageRange" edit
918 if ( nPrintRange == 1 )
919 rPagesStr = aPageRange;
920 else
921 rPagesStr = "";
923 return bDone;
927 sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
928 const uno::Sequence<beans::PropertyValue>& rOptions)
929 throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
931 SolarMutexGuard aGuard;
932 if (!pDocShell)
934 throw lang::DisposedException( OUString(),
935 static_cast< sheet::XSpreadsheetDocument* >(this) );
938 ScMarkData aMark;
939 ScPrintSelectionStatus aStatus;
940 OUString aPagesStr;
941 if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
942 return 0;
944 // The same ScPrintFuncCache object in pPrintFuncCache is used as long as
945 // the same selection is used (aStatus) and the document isn't changed
946 // (pPrintFuncCache is cleared in Notify handler)
948 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
950 delete pPrintFuncCache;
951 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
953 sal_Int32 nPages = pPrintFuncCache->GetPageCount();
955 sal_Int32 nSelectCount = nPages;
956 if ( !aPagesStr.isEmpty() )
958 StringRangeEnumerator aRangeEnum( aPagesStr, 0, nPages-1 );
959 nSelectCount = aRangeEnum.size();
961 return nSelectCount;
964 static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, const OUString& rPagesStr, sal_Int32 nTotalPages )
966 if ( rPagesStr.isEmpty() )
967 return nSelRenderer;
969 StringRangeEnumerator aRangeEnum( rPagesStr, 0, nTotalPages-1 );
970 StringRangeEnumerator::Iterator aIter = aRangeEnum.begin();
971 StringRangeEnumerator::Iterator aEnd = aRangeEnum.end();
972 for ( ; nSelRenderer > 0 && aIter != aEnd; --nSelRenderer )
973 ++aIter;
975 return *aIter; // returns -1 if reached the end
978 uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nSelRenderer,
979 const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& rOptions )
980 throw (lang::IllegalArgumentException,
981 uno::RuntimeException,
982 std::exception)
984 SolarMutexGuard aGuard;
985 if (!pDocShell)
987 throw lang::DisposedException( OUString(),
988 static_cast< sheet::XSpreadsheetDocument* >(this) );
991 ScMarkData aMark;
992 ScPrintSelectionStatus aStatus;
993 OUString aPagesStr;
994 // #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
995 long nTotalPages = 0;
996 if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
998 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1000 delete pPrintFuncCache;
1001 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1003 nTotalPages = pPrintFuncCache->GetPageCount();
1005 sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
1006 if ( nRenderer < 0 )
1008 if ( nSelRenderer == 0 )
1010 // getRenderer(0) is used to query the settings, so it must always return something
1012 SCTAB nCurTab = 0; //! use current sheet from view?
1013 ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
1014 Size aTwips = aDefaultFunc.GetPageSize();
1015 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
1017 uno::Sequence<beans::PropertyValue> aSequence(1);
1018 beans::PropertyValue* pArray = aSequence.getArray();
1019 pArray[0].Name = SC_UNONAME_PAGESIZE;
1020 pArray[0].Value <<= aPageSize;
1022 if( ! pPrinterOptions )
1023 pPrinterOptions = new ScPrintUIOptions;
1024 else
1025 pPrinterOptions->SetDefaults();
1026 pPrinterOptions->appendPrintUIOptions( aSequence );
1027 return aSequence;
1029 else
1030 throw lang::IllegalArgumentException();
1033 // printer is used as device (just for page layout), draw view is not needed
1035 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
1037 ScRange aRange;
1038 const ScRange* pSelRange = NULL;
1039 if ( aMark.IsMarked() )
1041 aMark.GetMarkArea( aRange );
1042 pSelRange = &aRange;
1044 ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
1045 pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
1046 aFunc.SetRenderFlag( true );
1048 Range aPageRange( nRenderer+1, nRenderer+1 );
1049 MultiSelection aPage( aPageRange );
1050 aPage.SetTotalRange( Range(0,RANGE_MAX) );
1051 aPage.Select( aPageRange );
1053 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
1054 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
1056 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, NULL );
1058 ScRange aCellRange;
1059 bool bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
1060 Size aTwips = aFunc.GetPageSize();
1061 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
1063 long nPropCount = bWasCellRange ? 3 : 2;
1064 uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
1065 beans::PropertyValue* pArray = aSequence.getArray();
1066 pArray[0].Name = SC_UNONAME_PAGESIZE;
1067 pArray[0].Value <<= aPageSize;
1068 // #i111158# all positions are relative to the whole page, including non-printable area
1069 pArray[1].Name = SC_UNONAME_INC_NP_AREA;
1070 pArray[1].Value = uno::makeAny( sal_True );
1071 if ( bWasCellRange )
1073 table::CellRangeAddress aRangeAddress( nTab,
1074 aCellRange.aStart.Col(), aCellRange.aStart.Row(),
1075 aCellRange.aEnd.Col(), aCellRange.aEnd.Row() );
1076 pArray[2].Name = SC_UNONAME_SOURCERANGE;
1077 pArray[2].Value <<= aRangeAddress;
1080 if( ! pPrinterOptions )
1081 pPrinterOptions = new ScPrintUIOptions;
1082 else
1083 pPrinterOptions->SetDefaults();
1084 pPrinterOptions->appendPrintUIOptions( aSequence );
1085 return aSequence;
1088 void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelection,
1089 const uno::Sequence<beans::PropertyValue>& rOptions )
1090 throw(lang::IllegalArgumentException,
1091 uno::RuntimeException,
1092 std::exception)
1094 SolarMutexGuard aGuard;
1095 if (!pDocShell)
1097 throw lang::DisposedException( OUString(),
1098 static_cast< sheet::XSpreadsheetDocument* >(this) );
1101 ScMarkData aMark;
1102 ScPrintSelectionStatus aStatus;
1103 OUString aPagesStr;
1104 if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
1105 throw lang::IllegalArgumentException();
1107 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1109 delete pPrintFuncCache;
1110 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1112 long nTotalPages = pPrintFuncCache->GetPageCount();
1113 sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
1114 if ( nRenderer < 0 )
1115 throw lang::IllegalArgumentException();
1117 OutputDevice* pDev = lcl_GetRenderDevice( rOptions );
1118 if ( !pDev )
1119 throw lang::IllegalArgumentException();
1121 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
1122 ScDocument* pDoc = pDocShell->GetDocument();
1124 FmFormView* pDrawView = NULL;
1126 // #114135#
1127 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1129 if( pModel )
1131 pDrawView = new FmFormView( pModel, pDev );
1132 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
1133 pDrawView->SetPrintPreview( true );
1136 ScRange aRange;
1137 const ScRange* pSelRange = NULL;
1138 if ( aMark.IsMarked() )
1140 aMark.GetMarkArea( aRange );
1141 pSelRange = &aRange;
1144 // to increase performance, ScPrintState might be used here for subsequent
1145 // pages of the same sheet
1147 ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
1148 aFunc.SetDrawView( pDrawView );
1149 aFunc.SetRenderFlag( true );
1150 if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
1151 aFunc.SetExclusivelyDrawOleAndDrawObjects();
1153 Range aPageRange( nRenderer+1, nRenderer+1 );
1154 MultiSelection aPage( aPageRange );
1155 aPage.SetTotalRange( Range(0,RANGE_MAX) );
1156 aPage.Select( aPageRange );
1158 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
1159 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
1161 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
1162 if ( nRenderer == nTabStart )
1164 // first page of a sheet: add outline item for the sheet name
1166 if ( pPDFData && pPDFData->GetIsExportBookmarks() )
1168 // the sheet starts at the top of the page
1169 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
1170 sal_Int32 nDestID = pPDFData->CreateDest( aArea );
1171 OUString aTabName;
1172 pDoc->GetName( nTab, aTabName );
1173 sal_Int32 nParent = -1; // top-level
1174 pPDFData->CreateOutlineItem( nParent, aTabName, nDestID );
1176 // #i56629# add the named destination stuff
1177 if( pPDFData && pPDFData->GetIsExportNamedDestinations() )
1179 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
1180 OUString aTabName;
1181 pDoc->GetName( nTab, aTabName );
1182 //need the PDF page number here
1183 pPDFData->CreateNamedDest( aTabName, aArea );
1187 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, true, NULL );
1189 // resolve the hyperlinks for PDF export
1191 if ( pPDFData )
1193 // iterate over the hyperlinks that were output for this page
1195 std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFData->GetBookmarks();
1196 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIter = rBookmarks.begin();
1197 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
1198 while ( aIter != aIEnd )
1200 OUString aBookmark = aIter->aBookmark;
1201 if ( aBookmark.toChar() == (sal_Unicode) '#' )
1203 // try to resolve internal link
1205 OUString aTarget( aBookmark.copy( 1 ) );
1207 ScRange aTargetRange;
1208 Rectangle aTargetRect; // 1/100th mm
1209 bool bIsSheet = false;
1210 bool bValid = lcl_ParseTarget( aTarget, aTargetRange, aTargetRect, bIsSheet, pDoc, nTab );
1212 if ( bValid )
1214 sal_Int32 nPage = -1;
1215 Rectangle aArea;
1216 if ( bIsSheet )
1218 // Get first page for sheet (if nothing from that sheet is printed,
1219 // this page can show a different sheet)
1220 nPage = pPrintFuncCache->GetTabStart( aTargetRange.aStart.Tab() );
1221 aArea = pDev->PixelToLogic( Rectangle( 0,0,0,0 ) );
1223 else
1225 pPrintFuncCache->InitLocations( aMark, pDev ); // does nothing if already initialized
1227 ScPrintPageLocation aLocation;
1228 if ( pPrintFuncCache->FindLocation( aTargetRange.aStart, aLocation ) )
1230 nPage = aLocation.nPage;
1232 // get the rectangle of the page's cell range in 1/100th mm
1233 ScRange aLocRange = aLocation.aCellRange;
1234 Rectangle aLocationMM = pDoc->GetMMRect(
1235 aLocRange.aStart.Col(), aLocRange.aStart.Row(),
1236 aLocRange.aEnd.Col(), aLocRange.aEnd.Row(),
1237 aLocRange.aStart.Tab() );
1238 Rectangle aLocationPixel = aLocation.aRectangle;
1240 // Scale and move the target rectangle from aLocationMM to aLocationPixel,
1241 // to get the target rectangle in pixels.
1243 Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
1244 Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );
1246 long nX1 = aLocationPixel.Left() + (long)
1247 ( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
1248 long nX2 = aLocationPixel.Left() + (long)
1249 ( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
1250 long nY1 = aLocationPixel.Top() + (long)
1251 ( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
1252 long nY2 = aLocationPixel.Top() + (long)
1253 ( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
1255 if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
1256 if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
1257 if ( nY1 > aLocationPixel.Bottom() ) nY1 = aLocationPixel.Bottom();
1258 if ( nY2 > aLocationPixel.Bottom() ) nY2 = aLocationPixel.Bottom();
1260 // The link target area is interpreted using the device's MapMode at
1261 // the time of the CreateDest call, so PixelToLogic can be used here,
1262 // regardless of the MapMode that is actually selected.
1264 aArea = pDev->PixelToLogic( Rectangle( nX1, nY1, nX2, nY2 ) );
1268 if ( nPage >= 0 )
1269 pPDFData->SetLinkDest( aIter->nLinkId, pPDFData->CreateDest( aArea, nPage ) );
1272 else
1274 // external link, use as-is
1275 pPDFData->SetLinkURL( aIter->nLinkId, aBookmark );
1277 ++aIter;
1279 rBookmarks.clear();
1282 if ( pDrawView )
1283 pDrawView->HideSdrPage();
1284 delete pDrawView;
1287 // XLinkTargetSupplier
1289 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException, std::exception)
1291 SolarMutexGuard aGuard;
1292 if (pDocShell)
1293 return new ScLinkTargetTypesObj(pDocShell);
1294 return NULL;
1297 // XActionLockable
1299 sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException, std::exception)
1301 SolarMutexGuard aGuard;
1302 bool bLocked = false;
1303 if (pDocShell)
1304 bLocked = ( pDocShell->GetLockCount() != 0 );
1305 return bLocked;
1308 void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException, std::exception)
1310 SolarMutexGuard aGuard;
1311 if (pDocShell)
1312 pDocShell->LockDocument();
1315 void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException, std::exception)
1317 SolarMutexGuard aGuard;
1318 if (pDocShell)
1319 pDocShell->UnlockDocument();
1322 void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException, std::exception)
1324 SolarMutexGuard aGuard;
1325 if (pDocShell)
1326 pDocShell->SetLockCount(nLock);
1329 sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException, std::exception)
1331 SolarMutexGuard aGuard;
1332 sal_uInt16 nRet = 0;
1333 if (pDocShell)
1335 nRet = pDocShell->GetLockCount();
1336 pDocShell->SetLockCount(0);
1338 return nRet;
1341 void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException, std::exception)
1343 SolarMutexGuard aGuard;
1344 SfxBaseModel::lockControllers();
1345 if (pDocShell)
1346 pDocShell->LockPaint();
1349 void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException, std::exception)
1351 SolarMutexGuard aGuard;
1352 if (hasControllersLocked())
1354 SfxBaseModel::unlockControllers();
1355 if (pDocShell)
1356 pDocShell->UnlockPaint();
1360 // XCalculate
1362 void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException, std::exception)
1364 SolarMutexGuard aGuard;
1365 if (pDocShell)
1366 pDocShell->DoRecalc(true);
1367 else
1369 OSL_FAIL("keine DocShell"); //! Exception oder so?
1373 void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException, std::exception)
1375 SolarMutexGuard aGuard;
1376 if (pDocShell)
1377 pDocShell->DoHardRecalc(true);
1378 else
1380 OSL_FAIL("keine DocShell"); //! Exception oder so?
1384 sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException, std::exception)
1386 SolarMutexGuard aGuard;
1387 if (pDocShell)
1388 return pDocShell->GetDocument()->GetAutoCalc();
1390 OSL_FAIL("keine DocShell"); //! Exception oder so?
1391 return false;
1394 void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabledIn )
1395 throw(uno::RuntimeException, std::exception)
1397 bool bEnabled(bEnabledIn);
1398 SolarMutexGuard aGuard;
1399 if (pDocShell)
1401 ScDocument* pDoc = pDocShell->GetDocument();
1402 if ( pDoc->GetAutoCalc() != bEnabled )
1404 pDoc->SetAutoCalc( bEnabled );
1405 pDocShell->SetDocumentModified();
1408 else
1410 OSL_FAIL("keine DocShell"); //! Exception oder so?
1414 // XProtectable
1416 void SAL_CALL ScModelObj::protect( const OUString& aPassword ) throw(uno::RuntimeException, std::exception)
1418 SolarMutexGuard aGuard;
1419 // #i108245# if already protected, don't change anything
1420 if ( pDocShell && !pDocShell->GetDocument()->IsDocProtected() )
1422 OUString aString(aPassword);
1423 pDocShell->GetDocFunc().Protect( TABLEID_DOC, aString, true );
1427 void SAL_CALL ScModelObj::unprotect( const OUString& aPassword )
1428 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1430 SolarMutexGuard aGuard;
1431 if (pDocShell)
1433 OUString aString(aPassword);
1434 bool bDone = pDocShell->GetDocFunc().Unprotect( TABLEID_DOC, aString, true );
1435 if (!bDone)
1436 throw lang::IllegalArgumentException();
1440 sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException, std::exception)
1442 SolarMutexGuard aGuard;
1443 if (pDocShell)
1444 return pDocShell->GetDocument()->IsDocProtected();
1446 OSL_FAIL("keine DocShell"); //! Exception oder so?
1447 return false;
1450 // XDrawPagesSupplier
1452 uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException, std::exception)
1454 SolarMutexGuard aGuard;
1455 if (pDocShell)
1456 return new ScDrawPagesObj(pDocShell);
1458 OSL_FAIL("keine DocShell"); //! Exception oder so?
1459 return NULL;
1462 // XGoalSeek
1464 sheet::GoalResult SAL_CALL ScModelObj::seekGoal(
1465 const table::CellAddress& aFormulaPosition,
1466 const table::CellAddress& aVariablePosition,
1467 const OUString& aGoalValue )
1468 throw (uno::RuntimeException,
1469 std::exception)
1471 SolarMutexGuard aGuard;
1472 sheet::GoalResult aResult;
1473 aResult.Divergence = DBL_MAX; // nichts gefunden
1474 if (pDocShell)
1476 WaitObject aWait( pDocShell->GetActiveDialogParent() );
1477 OUString aGoalString(aGoalValue);
1478 ScDocument* pDoc = pDocShell->GetDocument();
1479 double fValue = 0.0;
1480 bool bFound = pDoc->Solver(
1481 (SCCOL)aFormulaPosition.Column, (SCROW)aFormulaPosition.Row, aFormulaPosition.Sheet,
1482 (SCCOL)aVariablePosition.Column, (SCROW)aVariablePosition.Row, aVariablePosition.Sheet,
1483 aGoalString, fValue );
1484 aResult.Result = fValue;
1485 if (bFound)
1486 aResult.Divergence = 0.0; //! das ist gelogen
1488 return aResult;
1491 // XConsolidatable
1493 uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
1494 sal_Bool bEmpty ) throw(uno::RuntimeException, std::exception)
1496 SolarMutexGuard aGuard;
1497 ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
1498 if ( pDocShell && !bEmpty )
1500 ScDocument* pDoc = pDocShell->GetDocument();
1501 const ScConsolidateParam* pParam = pDoc->GetConsolidateDlgData();
1502 if (pParam)
1503 pNew->SetParam( *pParam );
1505 return pNew;
1508 void SAL_CALL ScModelObj::consolidate(
1509 const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
1510 throw (uno::RuntimeException, std::exception)
1512 SolarMutexGuard aGuard;
1513 // das koennte theoretisch ein fremdes Objekt sein, also nur das
1514 // oeffentliche XConsolidationDescriptor Interface benutzen, um
1515 // die Daten in ein ScConsolidationDescriptor Objekt zu kopieren:
1516 //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation?
1518 ScConsolidationDescriptor aImpl;
1519 aImpl.setFunction( xDescriptor->getFunction() );
1520 aImpl.setSources( xDescriptor->getSources() );
1521 aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
1522 aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
1523 aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
1524 aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
1526 if (pDocShell)
1528 const ScConsolidateParam& rParam = aImpl.GetParam();
1529 pDocShell->DoConsolidate( rParam, true );
1530 pDocShell->GetDocument()->SetConsolidateDlgData( &rParam );
1534 // XDocumentAuditing
1536 void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException, std::exception)
1538 SolarMutexGuard aGuard;
1539 if (pDocShell)
1540 pDocShell->GetDocFunc().DetectiveRefresh();
1543 // XViewDataSupplier
1544 uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData( )
1545 throw (uno::RuntimeException, std::exception)
1547 uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
1549 if( !xRet.is() )
1551 SolarMutexGuard aGuard;
1552 if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
1554 uno::Reference < container::XIndexContainer > xCont = document::IndexedPropertyValues::create( ::comphelper::getProcessComponentContext() );
1555 xRet.set( xCont, uno::UNO_QUERY_THROW );
1557 uno::Sequence< beans::PropertyValue > aSeq;
1558 aSeq.realloc(1);
1559 OUString sName;
1560 pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName );
1561 OUString sOUName(sName);
1562 aSeq[0].Name = SC_ACTIVETABLE;
1563 aSeq[0].Value <<= sOUName;
1564 xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
1568 return xRet;
1571 // XPropertySet (Doc-Optionen)
1572 //! auch an der Applikation anbieten?
1574 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
1575 throw(uno::RuntimeException, std::exception)
1577 SolarMutexGuard aGuard;
1578 static uno::Reference<beans::XPropertySetInfo> aRef(
1579 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1580 return aRef;
1583 void SAL_CALL ScModelObj::setPropertyValue(
1584 const OUString& aPropertyName, const uno::Any& aValue )
1585 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1586 lang::IllegalArgumentException, lang::WrappedTargetException,
1587 uno::RuntimeException, std::exception)
1589 SolarMutexGuard aGuard;
1590 OUString aString(aPropertyName);
1592 if (pDocShell)
1594 ScDocument* pDoc = pDocShell->GetDocument();
1595 const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1596 ScDocOptions aNewOpt = rOldOpt;
1597 // Don't recalculate while loading XML, when the formula text is stored
1598 // Recalculation after loading is handled separately.
1599 bool bHardRecalc = !pDoc->IsImportingXML();
1601 bool bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropSet.getPropertyMap(), aPropertyName, aValue );
1602 if (bOpt)
1604 // done...
1605 if ( aString.equalsAscii( SC_UNO_IGNORECASE ) ||
1606 aString.equalsAscii( SC_UNONAME_REGEXP ) ||
1607 aString.equalsAscii( SC_UNO_LOOKUPLABELS ) )
1608 bHardRecalc = false;
1610 else if ( aString.equalsAscii( SC_UNONAME_CLOCAL ) )
1612 lang::Locale aLocale;
1613 if ( aValue >>= aLocale )
1615 LanguageType eLatin, eCjk, eCtl;
1616 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1617 eLatin = ScUnoConversion::GetLanguage(aLocale);
1618 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1621 else if ( aString.equalsAscii( SC_UNO_CODENAME ) )
1623 OUString sCodeName;
1624 if ( aValue >>= sCodeName )
1625 pDoc->SetCodeName( sCodeName );
1627 else if ( aString.equalsAscii( SC_UNO_CJK_CLOCAL ) )
1629 lang::Locale aLocale;
1630 if ( aValue >>= aLocale )
1632 LanguageType eLatin, eCjk, eCtl;
1633 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1634 eCjk = ScUnoConversion::GetLanguage(aLocale);
1635 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1638 else if ( aString.equalsAscii( SC_UNO_CTL_CLOCAL ) )
1640 lang::Locale aLocale;
1641 if ( aValue >>= aLocale )
1643 LanguageType eLatin, eCjk, eCtl;
1644 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1645 eCtl = ScUnoConversion::GetLanguage(aLocale);
1646 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1649 else if ( aString.equalsAscii( SC_UNO_APPLYFMDES ) )
1651 // model is created if not there
1652 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1653 pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1655 SfxBindings* pBindings = pDocShell->GetViewBindings();
1656 if (pBindings)
1657 pBindings->Invalidate( SID_FM_OPEN_READONLY );
1659 else if ( aString.equalsAscii( SC_UNO_AUTOCONTFOC ) )
1661 // model is created if not there
1662 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1663 pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1665 SfxBindings* pBindings = pDocShell->GetViewBindings();
1666 if (pBindings)
1667 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
1669 else if ( aString.equalsAscii( SC_UNO_ISLOADED ) )
1671 pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1673 else if ( aString.equalsAscii( SC_UNO_ISUNDOENABLED ) )
1675 bool bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1676 pDoc->EnableUndo( bUndoEnabled );
1677 pDocShell->GetUndoManager()->SetMaxUndoActionCount(
1678 bUndoEnabled
1679 ? officecfg::Office::Common::Undo::Steps::get() : 0);
1681 else if ( aString.equalsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1683 bool bOldAdjustHeightEnabled = pDoc->IsAdjustHeightEnabled();
1684 bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1685 if( bOldAdjustHeightEnabled != bAdjustHeightEnabled )
1686 pDoc->EnableAdjustHeight( bAdjustHeightEnabled );
1688 else if ( aString.equalsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1690 pDoc->EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1692 else if ( aString.equalsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1694 pDoc->EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1696 else if ( aString.equalsAscii( "BuildId" ) )
1698 aValue >>= maBuildId;
1700 else if ( aString.equalsAscii( "SavedObject" ) ) // set from chart after saving
1702 OUString aObjName;
1703 aValue >>= aObjName;
1704 if ( !aObjName.isEmpty() )
1705 pDoc->RestoreChartListener( aObjName );
1707 else if ( aString.equalsAscii( SC_UNO_INTEROPGRABBAG ) )
1709 setGrabBagItem(aValue);
1712 if ( aNewOpt != rOldOpt )
1714 pDoc->SetDocOptions( aNewOpt );
1715 //! Recalc only for options that need it?
1716 if ( bHardRecalc )
1717 pDocShell->DoHardRecalc( true );
1718 pDocShell->SetDocumentModified();
1723 uno::Any SAL_CALL ScModelObj::getPropertyValue( const OUString& aPropertyName )
1724 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1725 uno::RuntimeException, std::exception)
1727 SolarMutexGuard aGuard;
1728 OUString aString(aPropertyName);
1729 uno::Any aRet;
1731 if (pDocShell)
1733 ScDocument* pDoc = pDocShell->GetDocument();
1734 const ScDocOptions& rOpt = pDoc->GetDocOptions();
1735 aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropSet.getPropertyMap(), aPropertyName );
1736 if ( aRet.hasValue() )
1738 // done...
1740 else if ( aString.equalsAscii( SC_UNONAME_CLOCAL ) )
1742 LanguageType eLatin, eCjk, eCtl;
1743 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1745 lang::Locale aLocale;
1746 ScUnoConversion::FillLocale( aLocale, eLatin );
1747 aRet <<= aLocale;
1749 else if ( aString.equalsAscii( SC_UNO_CODENAME ) )
1751 OUString sCodeName = pDoc->GetCodeName();
1752 aRet <<= sCodeName;
1755 else if ( aString.equalsAscii( SC_UNO_CJK_CLOCAL ) )
1757 LanguageType eLatin, eCjk, eCtl;
1758 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1760 lang::Locale aLocale;
1761 ScUnoConversion::FillLocale( aLocale, eCjk );
1762 aRet <<= aLocale;
1764 else if ( aString.equalsAscii( SC_UNO_CTL_CLOCAL ) )
1766 LanguageType eLatin, eCjk, eCtl;
1767 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1769 lang::Locale aLocale;
1770 ScUnoConversion::FillLocale( aLocale, eCtl );
1771 aRet <<= aLocale;
1773 else if ( aString.equalsAscii( SC_UNO_NAMEDRANGES ) )
1775 aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
1777 else if ( aString.equalsAscii( SC_UNO_DATABASERNG ) )
1779 aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
1781 else if ( aString.equalsAscii( SC_UNO_UNNAMEDDBRNG ) )
1783 aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell));
1785 else if ( aString.equalsAscii( SC_UNO_COLLABELRNG ) )
1787 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, true ));
1789 else if ( aString.equalsAscii( SC_UNO_ROWLABELRNG ) )
1791 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, false ));
1793 else if ( aString.equalsAscii( SC_UNO_AREALINKS ) )
1795 aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
1797 else if ( aString.equalsAscii( SC_UNO_DDELINKS ) )
1799 aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
1801 else if ( aString.equalsAscii( SC_UNO_EXTERNALDOCLINKS ) )
1803 aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
1805 else if ( aString.equalsAscii( SC_UNO_SHEETLINKS ) )
1807 aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
1809 else if ( aString.equalsAscii( SC_UNO_APPLYFMDES ) )
1811 // default for no model is TRUE
1812 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1813 bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True;
1814 ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
1816 else if ( aString.equalsAscii( SC_UNO_AUTOCONTFOC ) )
1818 // default for no model is FALSE
1819 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1820 bool bAutoControlFocus = pModel && pModel->GetAutoControlFocus();
1821 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
1823 else if ( aString.equalsAscii( SC_UNO_FORBIDDEN ) )
1825 aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
1827 else if ( aString.equalsAscii( SC_UNO_HASDRAWPAGES ) )
1829 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) );
1831 else if ( aString.equalsAscii( SC_UNO_BASICLIBRARIES ) )
1833 aRet <<= pDocShell->GetBasicContainer();
1835 else if ( aString.equalsAscii( SC_UNO_DIALOGLIBRARIES ) )
1837 aRet <<= pDocShell->GetDialogContainer();
1839 else if ( aString.equalsAscii( SC_UNO_VBAGLOBNAME ) )
1841 /* #i111553# This property provides the name of the constant that
1842 will be used to store this model in the global Basic manager.
1843 That constant will be equivalent to 'ThisComponent' but for
1844 each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
1845 constant can co-exist, as required by VBA. */
1846 aRet <<= OUString( "ThisExcelDoc" );
1848 else if ( aString.equalsAscii( SC_UNO_RUNTIMEUID ) )
1850 aRet <<= getRuntimeUID();
1852 else if ( aString.equalsAscii( SC_UNO_HASVALIDSIGNATURES ) )
1854 aRet <<= hasValidSignatures();
1856 else if ( aString.equalsAscii( SC_UNO_ISLOADED ) )
1858 ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
1860 else if ( aString.equalsAscii( SC_UNO_ISUNDOENABLED ) )
1862 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsUndoEnabled() );
1864 else if ( aString.equalsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1866 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsAdjustHeightEnabled() );
1868 else if ( aString.equalsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1870 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsExecuteLinkEnabled() );
1872 else if ( aString.equalsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1874 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsChangeReadOnlyEnabled() );
1876 else if ( aString.equalsAscii( SC_UNO_REFERENCEDEVICE ) )
1878 VCLXDevice* pXDev = new VCLXDevice();
1879 pXDev->SetOutputDevice( pDoc->GetRefDevice() );
1880 aRet <<= uno::Reference< awt::XDevice >( pXDev );
1882 else if ( aString.equalsAscii( "BuildId" ) )
1884 aRet <<= maBuildId;
1886 else if ( aString.equalsAscii( "InternalDocument" ) )
1888 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL) );
1890 else if ( aString.equalsAscii( SC_UNO_INTEROPGRABBAG ) )
1892 getGrabBagItem(aRet);
1896 return aRet;
1899 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
1901 // XMultiServiceFactory
1903 css::uno::Reference<css::uno::XInterface> ScModelObj::create(
1904 OUString const & aServiceSpecifier,
1905 css::uno::Sequence<css::uno::Any> const * arguments)
1907 uno::Reference<uno::XInterface> xRet;
1908 OUString aNameStr(aServiceSpecifier);
1909 sal_uInt16 nType = ScServiceProvider::GetProviderType(aNameStr);
1910 if ( nType != SC_SERVICE_INVALID )
1912 // drawing layer tables must be kept as long as the model is alive
1913 // return stored instance if already set
1914 switch ( nType )
1916 case SC_SERVICE_GRADTAB: xRet.set(xDrawGradTab); break;
1917 case SC_SERVICE_HATCHTAB: xRet.set(xDrawHatchTab); break;
1918 case SC_SERVICE_BITMAPTAB: xRet.set(xDrawBitmapTab); break;
1919 case SC_SERVICE_TRGRADTAB: xRet.set(xDrawTrGradTab); break;
1920 case SC_SERVICE_MARKERTAB: xRet.set(xDrawMarkerTab); break;
1921 case SC_SERVICE_DASHTAB: xRet.set(xDrawDashTab); break;
1922 case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv); break;
1923 case SC_SERVICE_VBAOBJECTPROVIDER: xRet.set(xObjProvider); break;
1926 // #i64497# If a chart is in a temporary document during clipoard paste,
1927 // there should be no data provider, so that own data is used
1928 bool bCreate =
1929 ! ( nType == SC_SERVICE_CHDATAPROV &&
1930 ( pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL ));
1931 // this should never happen, i.e. the temporary document should never be
1932 // loaded, because this unlinks the data
1933 OSL_ASSERT( bCreate );
1935 if ( !xRet.is() && bCreate )
1937 xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
1939 // store created instance
1940 switch ( nType )
1942 case SC_SERVICE_GRADTAB: xDrawGradTab.set(xRet); break;
1943 case SC_SERVICE_HATCHTAB: xDrawHatchTab.set(xRet); break;
1944 case SC_SERVICE_BITMAPTAB: xDrawBitmapTab.set(xRet); break;
1945 case SC_SERVICE_TRGRADTAB: xDrawTrGradTab.set(xRet); break;
1946 case SC_SERVICE_MARKERTAB: xDrawMarkerTab.set(xRet); break;
1947 case SC_SERVICE_DASHTAB: xDrawDashTab.set(xRet); break;
1948 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet); break;
1949 case SC_SERVICE_VBAOBJECTPROVIDER: xObjProvider.set(xRet); break;
1953 else
1955 // alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals,
1956 // da wird dann 'ne Exception geworfen, wenn's nicht passt...
1960 xRet = arguments == 0
1961 ? SvxFmMSFactory::createInstance(aServiceSpecifier)
1962 : SvxFmMSFactory::createInstanceWithArguments(
1963 aServiceSpecifier, *arguments);
1964 // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
1966 catch ( lang::ServiceNotRegisteredException & )
1970 // if the drawing factory created a shape, a ScShapeObj has to be used
1971 // to support own properties like ImageMap:
1973 uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
1974 if ( xShape.is() )
1976 xRet.clear(); // for aggregation, xShape must be the object's only ref
1977 new ScShapeObj( xShape ); // aggregates object and modifies xShape
1978 xRet.set(xShape);
1981 return xRet;
1984 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
1985 const OUString& aServiceSpecifier )
1986 throw(uno::Exception, uno::RuntimeException, std::exception)
1988 SolarMutexGuard aGuard;
1989 return create(aServiceSpecifier, 0);
1992 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments(
1993 const OUString& ServiceSpecifier,
1994 const uno::Sequence<uno::Any>& aArgs )
1995 throw(uno::Exception, uno::RuntimeException, std::exception)
1997 //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer?
1999 SolarMutexGuard aGuard;
2000 uno::Reference<uno::XInterface> xInt(create(ServiceSpecifier, &aArgs));
2002 if ( aArgs.getLength() )
2004 // used only for cell value binding so far - it can be initialized after creating
2006 uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
2007 if ( xInit.is() )
2008 xInit->initialize( aArgs );
2011 return xInt;
2014 uno::Sequence<OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
2015 throw(uno::RuntimeException, std::exception)
2017 SolarMutexGuard aGuard;
2019 //! warum sind die Parameter bei concatServiceNames nicht const ???
2020 //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
2021 //! SvxFmMSFactory::getAvailableServiceNames() );
2023 uno::Sequence<OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
2024 uno::Sequence<OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
2026 return concatServiceNames( aMyServices, aDrawServices );
2029 // XServiceInfo
2030 OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException, std::exception)
2032 return OUString( "ScModelObj" );
2035 sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName )
2036 throw(uno::RuntimeException, std::exception)
2038 return cppu::supportsService(this, rServiceName);
2041 uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
2042 throw(uno::RuntimeException, std::exception)
2044 uno::Sequence<OUString> aRet(3);
2045 aRet[0] = SCMODELOBJ_SERVICE;
2046 aRet[1] = SCDOCSETTINGS_SERVICE;
2047 aRet[2] = SCDOC_SERVICE;
2048 return aRet;
2051 // XUnoTunnel
2053 sal_Int64 SAL_CALL ScModelObj::getSomething(
2054 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
2056 if ( rId.getLength() == 16 &&
2057 0 == memcmp( getUnoTunnelId().getConstArray(),
2058 rId.getConstArray(), 16 ) )
2060 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2063 if ( rId.getLength() == 16 &&
2064 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
2065 rId.getConstArray(), 16 ) )
2067 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
2070 // aggregated number formats supplier has XUnoTunnel, too
2071 // interface from aggregated object must be obtained via queryAggregation
2073 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
2074 if ( nRet )
2075 return nRet;
2077 if ( GetFormatter().is() )
2079 const uno::Type& rTunnelType = cppu::UnoType<lang::XUnoTunnel>::get();
2080 uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
2081 if(aNumTunnel.getValueType() == rTunnelType)
2083 uno::Reference<lang::XUnoTunnel> xTunnelAgg(
2084 *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue());
2085 return xTunnelAgg->getSomething( rId );
2089 return 0;
2092 namespace
2094 class theScModelObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScModelObjUnoTunnelId> {};
2097 const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
2099 return theScModelObjUnoTunnelId::get().getSeq();
2102 ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
2104 ScModelObj* pRet = NULL;
2105 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
2106 if (xUT.is())
2107 pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2108 return pRet;
2111 // XChangesNotifier
2113 void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
2114 throw (uno::RuntimeException, std::exception)
2116 SolarMutexGuard aGuard;
2117 maChangesListeners.addInterface( aListener );
2120 void ScModelObj::removeChangesListener( const uno::Reference< util::XChangesListener >& aListener )
2121 throw (uno::RuntimeException, std::exception)
2123 SolarMutexGuard aGuard;
2124 maChangesListeners.removeInterface( aListener );
2127 bool ScModelObj::HasChangesListeners() const
2129 if ( maChangesListeners.getLength() > 0 )
2130 return true;
2132 // "change" event set in any sheet?
2133 return pDocShell && pDocShell->GetDocument()->HasAnySheetEventScript(SC_SHEETEVENT_CHANGE);
2136 void ScModelObj::NotifyChanges( const OUString& rOperation, const ScRangeList& rRanges,
2137 const uno::Sequence< beans::PropertyValue >& rProperties )
2139 if ( pDocShell && HasChangesListeners() )
2141 util::ChangesEvent aEvent;
2142 aEvent.Source.set( static_cast< cppu::OWeakObject* >( this ) );
2143 aEvent.Base <<= aEvent.Source;
2145 size_t nRangeCount = rRanges.size();
2146 aEvent.Changes.realloc( static_cast< sal_Int32 >( nRangeCount ) );
2147 for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
2149 uno::Reference< table::XCellRange > xRangeObj;
2151 ScRange aRange( *rRanges[ nIndex ] );
2152 if ( aRange.aStart == aRange.aEnd )
2154 xRangeObj.set( new ScCellObj( pDocShell, aRange.aStart ) );
2156 else
2158 xRangeObj.set( new ScCellRangeObj( pDocShell, aRange ) );
2161 util::ElementChange& rChange = aEvent.Changes[ static_cast< sal_Int32 >( nIndex ) ];
2162 rChange.Accessor <<= rOperation;
2163 rChange.Element <<= rProperties;
2164 rChange.ReplacedElement <<= xRangeObj;
2167 ::cppu::OInterfaceIteratorHelper aIter( maChangesListeners );
2168 while ( aIter.hasMoreElements() )
2172 static_cast< util::XChangesListener* >( aIter.next() )->changesOccurred( aEvent );
2174 catch( uno::Exception& )
2180 // handle sheet events
2181 //! separate method with ScMarkData? Then change HasChangesListeners back.
2182 if ( rOperation.equalsAscii("cell-change") && pDocShell )
2184 ScMarkData aMarkData;
2185 aMarkData.MarkFromRangeList( rRanges, false );
2186 ScDocument* pDoc = pDocShell->GetDocument();
2187 SCTAB nTabCount = pDoc->GetTableCount();
2188 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
2189 for (; itr != itrEnd && *itr < nTabCount; ++itr)
2191 SCTAB nTab = *itr;
2192 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
2193 if (pEvents)
2195 const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CHANGE);
2196 if (pScript)
2198 ScRangeList aTabRanges; // collect ranges on this sheet
2199 size_t nRangeCount = rRanges.size();
2200 for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
2202 ScRange aRange( *rRanges[ nIndex ] );
2203 if ( aRange.aStart.Tab() == nTab )
2204 aTabRanges.Append( aRange );
2206 size_t nTabRangeCount = aTabRanges.size();
2207 if ( nTabRangeCount > 0 )
2209 uno::Reference<uno::XInterface> xTarget;
2210 if ( nTabRangeCount == 1 )
2212 ScRange aRange( *aTabRanges[ 0 ] );
2213 if ( aRange.aStart == aRange.aEnd )
2214 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellObj( pDocShell, aRange.aStart ) ) );
2215 else
2216 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangeObj( pDocShell, aRange ) ) );
2218 else
2219 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangesObj( pDocShell, aTabRanges ) ) );
2221 uno::Sequence<uno::Any> aParams(1);
2222 aParams[0] <<= xTarget;
2224 uno::Any aRet;
2225 uno::Sequence<sal_Int16> aOutArgsIndex;
2226 uno::Sequence<uno::Any> aOutArgs;
2228 /*ErrCode eRet =*/ pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
2236 void ScModelObj::HandleCalculateEvents()
2238 if (pDocShell)
2240 ScDocument* pDoc = pDocShell->GetDocument();
2241 // don't call events before the document is visible
2242 // (might also set a flag on SFX_EVENT_LOADFINISHED and only disable while loading)
2243 if ( pDoc->IsDocVisible() )
2245 SCTAB nTabCount = pDoc->GetTableCount();
2246 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
2248 if (pDoc->HasCalcNotification(nTab))
2250 if (const ScSheetEvents* pEvents = pDoc->GetSheetEvents( nTab ))
2252 if (const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CALCULATE))
2254 uno::Any aRet;
2255 uno::Sequence<uno::Any> aParams;
2256 uno::Sequence<sal_Int16> aOutArgsIndex;
2257 uno::Sequence<uno::Any> aOutArgs;
2258 pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
2264 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
2265 uno::Sequence< uno::Any > aArgs( 1 );
2266 aArgs[ 0 ] <<= nTab;
2267 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_CALCULATE ), aArgs );
2269 catch( uno::Exception& )
2275 pDoc->ResetCalcNotifications();
2279 // XOpenCLSelection
2281 sal_Bool ScModelObj::isOpenCLEnabled()
2282 throw (uno::RuntimeException, std::exception)
2284 return ScInterpreter::GetGlobalConfig().mbOpenCLEnabled;
2287 void ScModelObj::enableOpenCL(sal_Bool bEnable)
2288 throw (uno::RuntimeException, std::exception)
2290 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2291 aConfig.mbOpenCLEnabled = bEnable;
2292 ScInterpreter::SetGlobalConfig(aConfig);
2295 void ScModelObj::enableAutomaticDeviceSelection(sal_Bool bForce)
2296 throw (uno::RuntimeException, std::exception)
2298 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2299 aConfig.mbOpenCLAutoSelect = true;
2300 ScInterpreter::SetGlobalConfig(aConfig);
2301 ScFormulaOptions aOptions = SC_MOD()->GetFormulaOptions();
2302 aOptions.SetCalcConfig(aConfig);
2303 SC_MOD()->SetFormulaOptions(aOptions);
2304 sc::FormulaGroupInterpreter::switchOpenCLDevice(OUString(), true, bForce);
2307 void ScModelObj::disableAutomaticDeviceSelection()
2308 throw (uno::RuntimeException, std::exception)
2310 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2311 aConfig.mbOpenCLAutoSelect = false;
2312 ScInterpreter::SetGlobalConfig(aConfig);
2313 ScFormulaOptions aOptions = SC_MOD()->GetFormulaOptions();
2314 aOptions.SetCalcConfig(aConfig);
2315 SC_MOD()->SetFormulaOptions(aOptions);
2318 void ScModelObj::selectOpenCLDevice( sal_Int32 nPlatform, sal_Int32 nDevice )
2319 throw (uno::RuntimeException, std::exception)
2321 if(nPlatform < 0 || nDevice < 0)
2322 throw uno::RuntimeException();
2324 std::vector<sc::OpenclPlatformInfo> aPlatformInfo;
2325 sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
2326 if(size_t(nPlatform) >= aPlatformInfo.size())
2327 throw uno::RuntimeException();
2329 if(size_t(nDevice) >= aPlatformInfo[nPlatform].maDevices.size())
2330 throw uno::RuntimeException();
2332 OUString aDeviceString = aPlatformInfo[nPlatform].maVendor + " " + aPlatformInfo[nPlatform].maDevices[nDevice].maName;
2333 sc::FormulaGroupInterpreter::switchOpenCLDevice(aDeviceString, false);
2336 sal_Int32 ScModelObj::getPlatformID()
2337 throw (uno::RuntimeException, std::exception)
2339 sal_Int32 nPlatformId;
2340 sal_Int32 nDeviceId;
2341 sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId);
2342 return nPlatformId;
2345 sal_Int32 ScModelObj::getDeviceID()
2346 throw (uno::RuntimeException, std::exception)
2348 sal_Int32 nPlatformId;
2349 sal_Int32 nDeviceId;
2350 sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId);
2351 return nDeviceId;
2354 uno::Sequence< sheet::opencl::OpenCLPlatform > ScModelObj::getOpenCLPlatforms()
2355 throw (uno::RuntimeException, std::exception)
2357 std::vector<sc::OpenclPlatformInfo> aPlatformInfo;
2358 sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
2360 uno::Sequence<sheet::opencl::OpenCLPlatform> aRet(aPlatformInfo.size());
2361 for(size_t i = 0; i < aPlatformInfo.size(); ++i)
2363 aRet[i].Name = aPlatformInfo[i].maName;
2364 aRet[i].Vendor = aPlatformInfo[i].maVendor;
2366 aRet[i].Devices.realloc(aPlatformInfo[i].maDevices.size());
2367 for(size_t j = 0; j < aPlatformInfo[i].maDevices.size(); ++j)
2369 const sc::OpenclDeviceInfo& rDevice = aPlatformInfo[i].maDevices[j];
2370 aRet[i].Devices[j].Name = rDevice.maName;
2371 aRet[i].Devices[j].Vendor = rDevice.maVendor;
2372 aRet[i].Devices[j].Driver = rDevice.maDriver;
2376 return aRet;
2380 ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
2381 pDocShell( pDocSh )
2383 pDocShell->GetDocument()->AddUnoObject(*this);
2386 ScDrawPagesObj::~ScDrawPagesObj()
2388 if (pDocShell)
2389 pDocShell->GetDocument()->RemoveUnoObject(*this);
2392 void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2394 // Referenz-Update interessiert hier nicht
2396 if ( rHint.ISA( SfxSimpleHint ) &&
2397 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2399 pDocShell = NULL; // ungueltig geworden
2403 uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2405 if (pDocShell)
2407 ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
2408 OSL_ENSURE(pDrawLayer,"kann Draw-Layer nicht anlegen");
2409 if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
2411 SdrPage* pPage = pDrawLayer->GetPage((sal_uInt16)nIndex);
2412 OSL_ENSURE(pPage,"Draw-Page nicht gefunden");
2413 if (pPage)
2415 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
2419 return NULL;
2422 // XDrawPages
2424 uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
2425 throw(uno::RuntimeException, std::exception)
2427 SolarMutexGuard aGuard;
2428 uno::Reference<drawing::XDrawPage> xRet;
2429 if (pDocShell)
2431 OUString aNewName;
2432 pDocShell->GetDocument()->CreateValidTabName(aNewName);
2433 if ( pDocShell->GetDocFunc().InsertTable( static_cast<SCTAB>(nPos),
2434 aNewName, true, true ) )
2435 xRet.set(GetObjectByIndex_Impl( nPos ));
2437 return xRet;
2440 void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
2441 throw(uno::RuntimeException, std::exception)
2443 SolarMutexGuard aGuard;
2444 SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
2445 if ( pDocShell && pImp )
2447 SdrPage* pPage = pImp->GetSdrPage();
2448 if (pPage)
2450 SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
2451 pDocShell->GetDocFunc().DeleteTable( nPageNum, true, true );
2456 // XIndexAccess
2458 sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException, std::exception)
2460 SolarMutexGuard aGuard;
2461 if (pDocShell)
2462 return pDocShell->GetDocument()->GetTableCount();
2463 return 0;
2466 uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
2467 throw(lang::IndexOutOfBoundsException,
2468 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2470 SolarMutexGuard aGuard;
2471 uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
2472 if (xPage.is())
2473 return uno::makeAny(xPage);
2474 else
2475 throw lang::IndexOutOfBoundsException();
2478 uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException, std::exception)
2480 SolarMutexGuard aGuard;
2481 return cppu::UnoType<drawing::XDrawPage>::get();
2484 sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException, std::exception)
2486 SolarMutexGuard aGuard;
2487 return ( getCount() != 0 );
2490 ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
2491 pDocShell( pDocSh )
2493 pDocShell->GetDocument()->AddUnoObject(*this);
2496 ScTableSheetsObj::~ScTableSheetsObj()
2498 if (pDocShell)
2499 pDocShell->GetDocument()->RemoveUnoObject(*this);
2502 void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2504 // Referenz-Update interessiert hier nicht
2506 if ( rHint.ISA( SfxSimpleHint ) &&
2507 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2509 pDocShell = NULL; // ungueltig geworden
2513 // XSpreadsheets
2515 ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2517 if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
2518 return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
2520 return NULL;
2523 ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const OUString& aName) const
2525 if (pDocShell)
2527 SCTAB nIndex;
2528 if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
2529 return new ScTableSheetObj( pDocShell, nIndex );
2531 return NULL;
2534 void SAL_CALL ScTableSheetsObj::insertNewByName( const OUString& aName, sal_Int16 nPosition )
2535 throw(uno::RuntimeException, std::exception)
2537 SolarMutexGuard aGuard;
2538 bool bDone = false;
2539 if (pDocShell)
2541 OUString aNamStr(aName);
2542 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, true, true );
2544 if (!bDone)
2545 throw uno::RuntimeException(); // no other exceptions specified
2548 void SAL_CALL ScTableSheetsObj::moveByName( const OUString& aName, sal_Int16 nDestination )
2549 throw(uno::RuntimeException, std::exception)
2551 SolarMutexGuard aGuard;
2552 bool bDone = false;
2553 if (pDocShell)
2555 SCTAB nSource;
2556 if ( pDocShell->GetDocument()->GetTable( aName, nSource ) )
2557 bDone = pDocShell->MoveTable( nSource, nDestination, false, true );
2559 if (!bDone)
2560 throw uno::RuntimeException(); // no other exceptions specified
2563 void SAL_CALL ScTableSheetsObj::copyByName( const OUString& aName,
2564 const OUString& aCopy, sal_Int16 nDestination )
2565 throw(uno::RuntimeException, std::exception)
2567 SolarMutexGuard aGuard;
2568 bool bDone = false;
2569 if (pDocShell)
2571 OUString aNewStr(aCopy);
2572 SCTAB nSource;
2573 if ( pDocShell->GetDocument()->GetTable( aName, nSource ) )
2575 bDone = pDocShell->MoveTable( nSource, nDestination, true, true );
2576 if (bDone)
2578 // #i92477# any index past the last sheet means "append" in MoveTable
2579 SCTAB nResultTab = static_cast<SCTAB>(nDestination);
2580 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount(); // count after copying
2581 if (nResultTab >= nTabCount)
2582 nResultTab = nTabCount - 1;
2584 bDone = pDocShell->GetDocFunc().RenameTable( nResultTab, aNewStr,
2585 true, true );
2589 if (!bDone)
2590 throw uno::RuntimeException(); // no other exceptions specified
2593 void SAL_CALL ScTableSheetsObj::insertByName( const OUString& aName, const uno::Any& aElement )
2594 throw(lang::IllegalArgumentException, container::ElementExistException,
2595 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2597 SolarMutexGuard aGuard;
2598 bool bDone = false;
2599 bool bIllArg = false;
2601 //! Type of aElement can be some specific interface instead of XInterface
2603 if ( pDocShell )
2605 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2606 if ( xInterface.is() )
2608 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2609 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2611 ScDocument* pDoc = pDocShell->GetDocument();
2612 OUString aNamStr(aName);
2613 SCTAB nDummy;
2614 if ( pDoc->GetTable( aNamStr, nDummy ) )
2616 // name already exists
2617 throw container::ElementExistException();
2619 else
2621 SCTAB nPosition = pDoc->GetTableCount();
2622 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr,
2623 true, true );
2624 if (bDone)
2625 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2626 // Dokument und neuen Range am Objekt setzen
2629 else
2630 bIllArg = true;
2632 else
2633 bIllArg = true;
2636 if (!bDone)
2638 if (bIllArg)
2639 throw lang::IllegalArgumentException();
2640 else
2641 throw uno::RuntimeException(); // ElementExistException is handled above
2645 void SAL_CALL ScTableSheetsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
2646 throw(lang::IllegalArgumentException, container::NoSuchElementException,
2647 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2649 SolarMutexGuard aGuard;
2650 bool bDone = false;
2651 bool bIllArg = false;
2653 //! Type of aElement can be some specific interface instead of XInterface
2655 if ( pDocShell )
2657 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2658 if ( xInterface.is() )
2660 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2661 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2663 SCTAB nPosition;
2664 if ( pDocShell->GetDocument()->GetTable( aName, nPosition ) )
2666 if ( pDocShell->GetDocFunc().DeleteTable( nPosition, true, true ) )
2668 // InsertTable kann jetzt eigentlich nicht schiefgehen...
2669 OUString aNamStr(aName);
2670 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, true, true );
2671 if (bDone)
2672 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2675 else
2677 // not found
2678 throw container::NoSuchElementException();
2681 else
2682 bIllArg = true;
2684 else
2685 bIllArg = true;
2688 if (!bDone)
2690 if (bIllArg)
2691 throw lang::IllegalArgumentException();
2692 else
2693 throw uno::RuntimeException(); // NoSuchElementException is handled above
2697 void SAL_CALL ScTableSheetsObj::removeByName( const OUString& aName )
2698 throw(container::NoSuchElementException,
2699 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2701 SolarMutexGuard aGuard;
2702 bool bDone = false;
2703 if (pDocShell)
2705 SCTAB nIndex;
2706 if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
2707 bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, true, true );
2708 else // not found
2709 throw container::NoSuchElementException();
2712 if (!bDone)
2713 throw uno::RuntimeException(); // NoSuchElementException is handled above
2716 sal_Int32 ScTableSheetsObj::importSheet(
2717 const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc,
2718 const OUString& srcName, const sal_Int32 nDestPosition )
2719 throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
2721 //pDocShell is the destination
2722 ScDocument* pDocDest = pDocShell->GetDocument();
2724 // Source document docShell
2725 if ( !xDocSrc.is() )
2726 throw uno::RuntimeException();
2727 ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc);
2728 ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject());
2730 // SourceSheet Position and does srcName exists ?
2731 SCTAB nIndexSrc;
2732 if ( !pDocShellSrc->GetDocument()->GetTable( srcName, nIndexSrc ) )
2733 throw lang::IllegalArgumentException();
2735 // Check the validity of destination index.
2736 SCTAB nCount = pDocDest->GetTableCount();
2737 SCTAB nIndexDest = static_cast<SCTAB>(nDestPosition);
2738 if (nIndexDest > nCount || nIndexDest < 0)
2739 throw lang::IndexOutOfBoundsException();
2741 // Transfert Tab
2742 bool bInsertNew = true;
2743 bool bNotifyAndPaint = true;
2744 pDocShell->TransferTab(
2745 *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint );
2747 return nIndexDest;
2750 // XCellRangesAccess
2752 uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet )
2753 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2755 SolarMutexGuard aGuard;
2756 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
2757 if (! xSheet.is())
2758 throw lang::IndexOutOfBoundsException();
2760 return xSheet->getCellByPosition(nColumn, nRow);
2763 uno::Reference< table::XCellRange > SAL_CALL ScTableSheetsObj::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom, sal_Int32 nSheet )
2764 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2766 SolarMutexGuard aGuard;
2767 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
2768 if (! xSheet.is())
2769 throw lang::IndexOutOfBoundsException();
2771 return xSheet->getCellRangeByPosition(nLeft, nTop, nRight, nBottom);
2774 uno::Sequence < uno::Reference< table::XCellRange > > SAL_CALL ScTableSheetsObj::getCellRangesByName( const OUString& aRange )
2775 throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
2777 SolarMutexGuard aGuard;
2778 uno::Sequence < uno::Reference < table::XCellRange > > xRet;
2780 ScRangeList aRangeList;
2781 ScDocument* pDoc = pDocShell->GetDocument();
2782 if (ScRangeStringConverter::GetRangeListFromString( aRangeList, aRange, pDoc, ::formula::FormulaGrammar::CONV_OOO, ';' ))
2784 size_t nCount = aRangeList.size();
2785 if (nCount)
2787 xRet.realloc(nCount);
2788 for( size_t nIndex = 0; nIndex < nCount; nIndex++ )
2790 const ScRange* pRange = aRangeList[ nIndex ];
2791 if( pRange )
2792 xRet[nIndex] = new ScCellRangeObj(pDocShell, *pRange);
2795 else
2796 throw lang::IllegalArgumentException();
2798 else
2799 throw lang::IllegalArgumentException();
2800 return xRet;
2803 // XEnumerationAccess
2805 uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
2806 throw(uno::RuntimeException, std::exception)
2808 SolarMutexGuard aGuard;
2809 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetsEnumeration"));
2812 // XIndexAccess
2814 sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException, std::exception)
2816 SolarMutexGuard aGuard;
2817 if (pDocShell)
2818 return pDocShell->GetDocument()->GetTableCount();
2819 return 0;
2822 uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
2823 throw(lang::IndexOutOfBoundsException,
2824 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2826 SolarMutexGuard aGuard;
2827 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
2828 if (xSheet.is())
2829 return uno::makeAny(xSheet);
2830 else
2831 throw lang::IndexOutOfBoundsException();
2832 // return uno::Any();
2835 uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException, std::exception)
2837 SolarMutexGuard aGuard;
2838 return cppu::UnoType<sheet::XSpreadsheet>::get();
2841 sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException, std::exception)
2843 SolarMutexGuard aGuard;
2844 return ( getCount() != 0 );
2847 // XNameAccess
2849 uno::Any SAL_CALL ScTableSheetsObj::getByName( const OUString& aName )
2850 throw(container::NoSuchElementException,
2851 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2853 SolarMutexGuard aGuard;
2854 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
2855 if (xSheet.is())
2856 return uno::makeAny(xSheet);
2857 else
2858 throw container::NoSuchElementException();
2861 uno::Sequence<OUString> SAL_CALL ScTableSheetsObj::getElementNames()
2862 throw(uno::RuntimeException, std::exception)
2864 SolarMutexGuard aGuard;
2865 if (pDocShell)
2867 ScDocument* pDoc = pDocShell->GetDocument();
2868 SCTAB nCount = pDoc->GetTableCount();
2869 OUString aName;
2870 uno::Sequence<OUString> aSeq(nCount);
2871 OUString* pAry = aSeq.getArray();
2872 for (SCTAB i=0; i<nCount; i++)
2874 pDoc->GetName( i, aName );
2875 pAry[i] = aName;
2877 return aSeq;
2879 return uno::Sequence<OUString>();
2882 sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const OUString& aName )
2883 throw(uno::RuntimeException, std::exception)
2885 SolarMutexGuard aGuard;
2886 if (pDocShell)
2888 SCTAB nIndex;
2889 if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
2890 return sal_True;
2892 return false;
2895 ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
2896 pDocShell( pDocSh ),
2897 nTab ( nT ),
2898 nStartCol( nSC ),
2899 nEndCol ( nEC )
2901 pDocShell->GetDocument()->AddUnoObject(*this);
2904 ScTableColumnsObj::~ScTableColumnsObj()
2906 if (pDocShell)
2907 pDocShell->GetDocument()->RemoveUnoObject(*this);
2910 void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2912 if ( rHint.ISA( ScUpdateRefHint ) )
2914 //! Referenz-Update fuer Tab und Start/Ende
2916 else if ( rHint.ISA( SfxSimpleHint ) &&
2917 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2919 pDocShell = NULL; // ungueltig geworden
2923 // XTableColumns
2925 ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2927 SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
2928 if ( pDocShell && nCol <= nEndCol )
2929 return new ScTableColumnObj( pDocShell, nCol, nTab );
2931 return NULL; // falscher Index
2934 ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const OUString& aName) const
2936 SCCOL nCol = 0;
2937 OUString aString(aName);
2938 if ( ::AlphaToCol( nCol, aString) )
2939 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
2940 return new ScTableColumnObj( pDocShell, nCol, nTab );
2942 return NULL;
2945 void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
2946 throw(uno::RuntimeException, std::exception)
2948 SolarMutexGuard aGuard;
2949 bool bDone = false;
2950 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
2951 nStartCol+nPosition+nCount-1 <= MAXCOL )
2953 ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
2954 (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
2955 bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSCOLS, true, true );
2957 if (!bDone)
2958 throw uno::RuntimeException(); // no other exceptions specified
2961 void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
2962 throw(uno::RuntimeException, std::exception)
2964 SolarMutexGuard aGuard;
2965 bool bDone = false;
2966 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
2967 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
2969 ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
2970 (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
2971 bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELCOLS, true, true );
2973 if (!bDone)
2974 throw uno::RuntimeException(); // no other exceptions specified
2977 // XEnumerationAccess
2979 uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
2980 throw(uno::RuntimeException, std::exception)
2982 SolarMutexGuard aGuard;
2983 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableColumnsEnumeration"));
2986 // XIndexAccess
2988 sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException, std::exception)
2990 SolarMutexGuard aGuard;
2991 return nEndCol - nStartCol + 1;
2994 uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
2995 throw(lang::IndexOutOfBoundsException,
2996 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2998 SolarMutexGuard aGuard;
2999 uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
3000 if (xColumn.is())
3001 return uno::makeAny(xColumn);
3002 else
3003 throw lang::IndexOutOfBoundsException();
3006 uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException, std::exception)
3008 SolarMutexGuard aGuard;
3009 return cppu::UnoType<table::XCellRange>::get();
3012 sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException, std::exception)
3014 SolarMutexGuard aGuard;
3015 return ( getCount() != 0 );
3018 uno::Any SAL_CALL ScTableColumnsObj::getByName( const OUString& aName )
3019 throw(container::NoSuchElementException,
3020 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3022 SolarMutexGuard aGuard;
3023 uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
3024 if (xColumn.is())
3025 return uno::makeAny(xColumn);
3026 else
3027 throw container::NoSuchElementException();
3030 uno::Sequence<OUString> SAL_CALL ScTableColumnsObj::getElementNames()
3031 throw(uno::RuntimeException, std::exception)
3033 SolarMutexGuard aGuard;
3034 SCCOL nCount = nEndCol - nStartCol + 1;
3035 uno::Sequence<OUString> aSeq(nCount);
3036 OUString* pAry = aSeq.getArray();
3037 for (SCCOL i=0; i<nCount; i++)
3038 pAry[i] = ::ScColToAlpha( nStartCol + i );
3040 return aSeq;
3043 sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const OUString& aName )
3044 throw(uno::RuntimeException, std::exception)
3046 SolarMutexGuard aGuard;
3047 SCCOL nCol = 0;
3048 OUString aString(aName);
3049 if ( ::AlphaToCol( nCol, aString) )
3050 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
3051 return sal_True;
3053 return false; // nicht gefunden
3056 // XPropertySet
3058 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
3059 throw(uno::RuntimeException, std::exception)
3061 SolarMutexGuard aGuard;
3062 static uno::Reference<beans::XPropertySetInfo> aRef(
3063 new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
3064 return aRef;
3067 void SAL_CALL ScTableColumnsObj::setPropertyValue(
3068 const OUString& aPropertyName, const uno::Any& aValue )
3069 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3070 lang::IllegalArgumentException, lang::WrappedTargetException,
3071 uno::RuntimeException, std::exception)
3073 SolarMutexGuard aGuard;
3074 if (!pDocShell)
3075 throw uno::RuntimeException();
3077 std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(nStartCol,nEndCol));
3078 OUString aNameString(aPropertyName);
3079 ScDocFunc& rFunc = pDocShell->GetDocFunc();
3081 if ( aNameString.equalsAscii( SC_UNONAME_CELLWID ) )
3083 sal_Int32 nNewWidth = 0;
3084 if ( aValue >>= nNewWidth )
3085 rFunc.SetWidthOrHeight(
3086 true, aColArr, nTab, SC_SIZE_ORIGINAL, (sal_uInt16)HMMToTwips(nNewWidth), true, true);
3088 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3090 bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3091 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
3092 rFunc.SetWidthOrHeight(true, aColArr, nTab, eMode, 0, true, true);
3093 // SC_SIZE_DIRECT with size 0: hide
3095 else if ( aNameString.equalsAscii( SC_UNONAME_OWIDTH ) )
3097 bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3098 if (bOpt)
3099 rFunc.SetWidthOrHeight(
3100 true, aColArr, nTab, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, true, true);
3101 // sal_False for columns currently has no effect
3103 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) || aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
3105 //! single function to set/remove all breaks?
3106 bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3107 for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
3108 if (bSet)
3109 rFunc.InsertPageBreak( true, ScAddress(nCol,0,nTab), true, true, true );
3110 else
3111 rFunc.RemovePageBreak( true, ScAddress(nCol,0,nTab), true, true, true );
3115 uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const OUString& aPropertyName )
3116 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3117 uno::RuntimeException, std::exception)
3119 SolarMutexGuard aGuard;
3120 if (!pDocShell)
3121 throw uno::RuntimeException();
3123 ScDocument* pDoc = pDocShell->GetDocument();
3124 OUString aNameString(aPropertyName);
3125 uno::Any aAny;
3127 //! loop over all columns for current state?
3129 if ( aNameString.equalsAscii( SC_UNONAME_CELLWID ) )
3131 // for hidden column, return original height
3132 sal_uInt16 nWidth = pDoc->GetOriginalWidth( nStartCol, nTab );
3133 aAny <<= (sal_Int32)TwipsToHMM(nWidth);
3135 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3137 bool bVis = !pDoc->ColHidden(nStartCol, nTab);
3138 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3140 else if ( aNameString.equalsAscii( SC_UNONAME_OWIDTH ) )
3142 bool bOpt = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE);
3143 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
3145 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) )
3147 ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
3148 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
3150 else if ( aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
3152 ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
3153 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) != 0 );
3156 return aAny;
3159 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
3161 ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
3162 pDocShell( pDocSh ),
3163 nTab ( nT ),
3164 nStartRow( nSR ),
3165 nEndRow ( nER )
3167 pDocShell->GetDocument()->AddUnoObject(*this);
3170 ScTableRowsObj::~ScTableRowsObj()
3172 if (pDocShell)
3173 pDocShell->GetDocument()->RemoveUnoObject(*this);
3176 void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3178 if ( rHint.ISA( ScUpdateRefHint ) )
3180 //! Referenz-Update fuer Tab und Start/Ende
3182 else if ( rHint.ISA( SfxSimpleHint ) &&
3183 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3185 pDocShell = NULL; // ungueltig geworden
3189 // XTableRows
3191 ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
3193 SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
3194 if ( pDocShell && nRow <= nEndRow )
3195 return new ScTableRowObj( pDocShell, nRow, nTab );
3197 return NULL; // falscher Index
3200 void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
3201 throw(uno::RuntimeException, std::exception)
3203 SolarMutexGuard aGuard;
3204 bool bDone = false;
3205 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
3206 nStartRow+nPosition+nCount-1 <= MAXROW )
3208 ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
3209 MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
3210 bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSROWS, true, true );
3212 if (!bDone)
3213 throw uno::RuntimeException(); // no other exceptions specified
3216 void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
3217 throw(uno::RuntimeException, std::exception)
3219 SolarMutexGuard aGuard;
3220 bool bDone = false;
3221 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
3222 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
3224 ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
3225 MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
3226 bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELROWS, true, true );
3228 if (!bDone)
3229 throw uno::RuntimeException(); // no other exceptions specified
3232 // XEnumerationAccess
3234 uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
3235 throw(uno::RuntimeException, std::exception)
3237 SolarMutexGuard aGuard;
3238 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableRowsEnumeration"));
3241 // XIndexAccess
3243 sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException, std::exception)
3245 SolarMutexGuard aGuard;
3246 return nEndRow - nStartRow + 1;
3249 uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
3250 throw(lang::IndexOutOfBoundsException,
3251 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3253 SolarMutexGuard aGuard;
3254 uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
3255 if (xRow.is())
3256 return uno::makeAny(xRow);
3257 else
3258 throw lang::IndexOutOfBoundsException();
3261 uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException, std::exception)
3263 SolarMutexGuard aGuard;
3264 return cppu::UnoType<table::XCellRange>::get();
3267 sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException, std::exception)
3269 SolarMutexGuard aGuard;
3270 return ( getCount() != 0 );
3273 // XPropertySet
3275 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
3276 throw(uno::RuntimeException, std::exception)
3278 SolarMutexGuard aGuard;
3279 static uno::Reference<beans::XPropertySetInfo> aRef(
3280 new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
3281 return aRef;
3284 void SAL_CALL ScTableRowsObj::setPropertyValue(
3285 const OUString& aPropertyName, const uno::Any& aValue )
3286 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3287 lang::IllegalArgumentException, lang::WrappedTargetException,
3288 uno::RuntimeException, std::exception)
3290 SolarMutexGuard aGuard;
3291 if (!pDocShell)
3292 throw uno::RuntimeException();
3294 ScDocFunc& rFunc = pDocShell->GetDocFunc();
3295 ScDocument* pDoc = pDocShell->GetDocument();
3296 std::vector<sc::ColRowSpan> aRowArr(1, sc::ColRowSpan(nStartRow,nEndRow));
3297 OUString aNameString(aPropertyName);
3299 if ( aNameString.equalsAscii( SC_UNONAME_OHEIGHT ) )
3301 sal_Int32 nNewHeight = 0;
3302 if ( pDoc->IsImportingXML() && ( aValue >>= nNewHeight ) )
3304 // used to set the stored row height for rows with optimal height when loading.
3306 // TODO: It's probably cleaner to use a different property name
3307 // for this.
3308 pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
3310 else
3312 bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3313 if (bOpt)
3314 rFunc.SetWidthOrHeight(false, aRowArr, nTab, SC_SIZE_OPTIMAL, 0, true, true);
3315 else
3317 //! manually set old heights again?
3321 else if ( aNameString.equalsAscii( SC_UNONAME_CELLHGT ) )
3323 sal_Int32 nNewHeight = 0;
3324 if ( aValue >>= nNewHeight )
3326 if (pDoc->IsImportingXML())
3328 // TODO: This is a band-aid fix. Eventually we need to
3329 // re-work ods' style import to get it to set styles to
3330 // ScDocument directly.
3331 pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
3332 pDoc->SetManualHeight( nStartRow, nEndRow, nTab, true );
3334 else
3335 rFunc.SetWidthOrHeight(
3336 false, aRowArr, nTab, SC_SIZE_ORIGINAL, (sal_uInt16)HMMToTwips(nNewHeight), true, true);
3339 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3341 bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3342 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
3343 rFunc.SetWidthOrHeight(false, aRowArr, nTab, eMode, 0, true, true);
3344 // SC_SIZE_DIRECT with size 0: hide
3346 else if ( aNameString.equalsAscii( SC_UNONAME_VISFLAG ) )
3348 // #i116460# Shortcut to only set the flag, without drawing layer update etc.
3349 // Should only be used from import filters.
3350 pDoc->SetRowHidden(nStartRow, nEndRow, nTab, !ScUnoHelpFunctions::GetBoolFromAny( aValue ));
3352 else if ( aNameString.equalsAscii( SC_UNONAME_CELLFILT ) )
3354 //! undo etc.
3355 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
3356 pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, true);
3357 else
3358 pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, false);
3360 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE) || aNameString.equalsAscii( SC_UNONAME_MANPAGE) )
3362 //! single function to set/remove all breaks?
3363 bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3364 for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
3365 if (bSet)
3366 rFunc.InsertPageBreak( false, ScAddress(0,nRow,nTab), true, true, true );
3367 else
3368 rFunc.RemovePageBreak( false, ScAddress(0,nRow,nTab), true, true, true );
3370 else if ( aNameString.equalsAscii( SC_UNONAME_CELLBACK ) || aNameString.equalsAscii( SC_UNONAME_CELLTRAN ) )
3372 // #i57867# Background color is specified for row styles in the file format,
3373 // so it has to be supported along with the row properties (import only).
3375 // Use ScCellRangeObj to set the property for all cells in the rows
3376 // (this means, the "row attribute" must be set before individual cell attributes).
3378 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3379 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3380 xRangeObj->setPropertyValue( aPropertyName, aValue );
3384 uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const OUString& aPropertyName )
3385 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3386 uno::RuntimeException, std::exception)
3388 SolarMutexGuard aGuard;
3389 if (!pDocShell)
3390 throw uno::RuntimeException();
3392 ScDocument* pDoc = pDocShell->GetDocument();
3393 OUString aNameString(aPropertyName);
3394 uno::Any aAny;
3396 //! loop over all rows for current state?
3398 if ( aNameString.equalsAscii( SC_UNONAME_CELLHGT ) )
3400 // for hidden row, return original height
3401 sal_uInt16 nHeight = pDoc->GetOriginalHeight( nStartRow, nTab );
3402 aAny <<= (sal_Int32)TwipsToHMM(nHeight);
3404 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3406 SCROW nLastRow;
3407 bool bVis = !pDoc->RowHidden(nStartRow, nTab, NULL, &nLastRow);
3408 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3410 else if ( aNameString.equalsAscii( SC_UNONAME_CELLFILT ) )
3412 bool bVis = pDoc->RowFiltered(nStartRow, nTab);
3413 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3415 else if ( aNameString.equalsAscii( SC_UNONAME_OHEIGHT ) )
3417 bool bOpt = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE);
3418 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
3420 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) )
3422 ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
3423 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
3425 else if ( aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
3427 ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
3428 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) != 0 );
3430 else if ( aNameString.equalsAscii( SC_UNONAME_CELLBACK ) || aNameString.equalsAscii( SC_UNONAME_CELLTRAN ) )
3432 // Use ScCellRangeObj to get the property from the cell range
3433 // (for completeness only, this is not used by the XML filter).
3435 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3436 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3437 aAny = xRangeObj->getPropertyValue( aPropertyName );
3440 return aAny;
3443 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj )
3445 ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj()
3447 if (pDocShell)
3448 pDocShell->GetDocument()->RemoveUnoObject(*this);
3451 void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3453 // Referenz-Update interessiert hier nicht
3455 if ( rHint.ISA( SfxSimpleHint ) &&
3456 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3458 pDocShell = NULL; // ungueltig geworden
3462 // XPropertySet
3464 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo()
3465 throw(uno::RuntimeException, std::exception)
3467 //! muss noch
3468 return NULL;
3471 void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue(
3472 const OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
3473 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3474 lang::IllegalArgumentException, lang::WrappedTargetException,
3475 uno::RuntimeException, std::exception)
3477 //! muss noch
3480 uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const OUString& /* aPropertyName */ )
3481 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3482 uno::RuntimeException, std::exception)
3484 //! muss noch
3485 return uno::Any();
3488 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj )
3490 ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
3491 pDocShell( pDocSh ),
3492 nTab( nT )
3494 pDocShell->GetDocument()->AddUnoObject(*this);
3497 ScAnnotationsObj::~ScAnnotationsObj()
3499 if (pDocShell)
3500 pDocShell->GetDocument()->RemoveUnoObject(*this);
3503 void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3505 //! nTab bei Referenz-Update anpassen!!!
3507 if ( rHint.ISA( SfxSimpleHint ) &&
3508 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3510 pDocShell = NULL; // ungueltig geworden
3514 bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
3516 if (!pDocShell)
3517 return false;
3519 ScDocument* pDoc = pDocShell->GetDocument();
3520 rPos = pDoc->GetNotePosition(nIndex);
3521 return rPos.IsValid();
3524 ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
3526 if (pDocShell)
3528 ScAddress aPos;
3529 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3530 return new ScAnnotationObj( pDocShell, aPos );
3532 return NULL;
3535 // XSheetAnnotations
3537 void SAL_CALL ScAnnotationsObj::insertNew(
3538 const table::CellAddress& aPosition, const OUString& rText )
3539 throw(uno::RuntimeException, std::exception)
3541 SolarMutexGuard aGuard;
3542 if (pDocShell)
3544 OSL_ENSURE( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
3545 ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
3546 pDocShell->GetDocFunc().ReplaceNote( aPos, rText, 0, 0, true );
3550 void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException, std::exception)
3552 SolarMutexGuard aGuard;
3553 if (pDocShell)
3555 ScAddress aPos;
3556 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3558 ScMarkData aMarkData;
3559 aMarkData.SelectTable( aPos.Tab(), true );
3560 aMarkData.SetMultiMarkArea( ScRange(aPos) );
3562 pDocShell->GetDocFunc().DeleteContents( aMarkData, IDF_NOTE, true, true );
3567 // XEnumerationAccess
3569 uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
3570 throw(uno::RuntimeException, std::exception)
3572 //! iterate directly (more efficiently)?
3574 SolarMutexGuard aGuard;
3575 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.CellAnnotationsEnumeration"));
3578 // XIndexAccess
3580 sal_Int32 SAL_CALL ScAnnotationsObj::getCount()
3581 throw(uno::RuntimeException, std::exception)
3583 SolarMutexGuard aGuard;
3584 sal_Int32 nCount = 0;
3585 if (pDocShell)
3587 ScDocument* pDoc = pDocShell->GetDocument();
3588 const ScRangeList aRangeList( ScRange( 0, 0, nTab, MAXCOL, MAXROW, nTab) );
3589 std::vector<sc::NoteEntry> rNotes;
3590 pDoc->GetNotesInRange(aRangeList, rNotes);
3591 nCount = rNotes.size();
3593 return nCount;
3596 uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
3597 throw(lang::IndexOutOfBoundsException,
3598 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3600 SolarMutexGuard aGuard;
3601 uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
3602 if (xAnnotation.is())
3603 return uno::makeAny(xAnnotation);
3604 else
3605 throw lang::IndexOutOfBoundsException();
3608 uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException, std::exception)
3610 SolarMutexGuard aGuard;
3611 return cppu::UnoType<sheet::XSheetAnnotation>::get();
3614 sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException, std::exception)
3616 SolarMutexGuard aGuard;
3617 return ( getCount() != 0 );
3620 ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
3621 pDocShell( pDocSh ),
3622 nTab ( nT )
3624 pDocShell->GetDocument()->AddUnoObject(*this);
3627 ScScenariosObj::~ScScenariosObj()
3629 if (pDocShell)
3630 pDocShell->GetDocument()->RemoveUnoObject(*this);
3633 void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3635 if ( rHint.ISA( ScUpdateRefHint ) )
3637 //! Referenz-Update fuer Tab und Start/Ende
3639 else if ( rHint.ISA( SfxSimpleHint ) &&
3640 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3642 pDocShell = NULL; // ungueltig geworden
3646 // XScenarios
3648 bool ScScenariosObj::GetScenarioIndex_Impl( const OUString& rName, SCTAB& rIndex )
3650 //! Case-insensitiv ????
3652 if ( pDocShell )
3654 OUString aTabName;
3655 ScDocument* pDoc = pDocShell->GetDocument();
3656 SCTAB nCount = (SCTAB)getCount();
3657 for (SCTAB i=0; i<nCount; i++)
3658 if (pDoc->GetName( nTab+i+1, aTabName ))
3659 if (aTabName.equals(rName))
3661 rIndex = i;
3662 return true;
3666 return false;
3669 ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
3671 sal_uInt16 nCount = (sal_uInt16)getCount();
3672 if ( pDocShell && nIndex >= 0 && nIndex < nCount )
3673 return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
3675 return NULL; // kein Dokument oder falscher Index
3678 ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const OUString& aName)
3680 SCTAB nIndex;
3681 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3682 return new ScTableSheetObj( pDocShell, nTab+nIndex+1 );
3684 return NULL; // nicht gefunden
3687 void SAL_CALL ScScenariosObj::addNewByName( const OUString& aName,
3688 const uno::Sequence<table::CellRangeAddress>& aRanges,
3689 const OUString& aComment )
3690 throw(uno::RuntimeException, std::exception)
3692 SolarMutexGuard aGuard;
3693 if ( pDocShell )
3695 ScMarkData aMarkData;
3696 aMarkData.SelectTable( nTab, true );
3698 sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
3699 if (nRangeCount)
3701 const table::CellRangeAddress* pAry = aRanges.getConstArray();
3702 for (sal_uInt16 i=0; i<nRangeCount; i++)
3704 OSL_ENSURE( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
3705 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
3706 (SCCOL)pAry[i].EndColumn, (SCROW)pAry[i].EndRow, nTab );
3708 aMarkData.SetMultiMarkArea( aRange );
3712 OUString aNameStr(aName);
3713 OUString aCommStr(aComment);
3715 Color aColor( COL_LIGHTGRAY ); // Default
3716 sal_uInt16 nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
3718 pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
3722 void SAL_CALL ScScenariosObj::removeByName( const OUString& aName )
3723 throw(uno::RuntimeException, std::exception)
3725 SolarMutexGuard aGuard;
3726 SCTAB nIndex;
3727 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3728 pDocShell->GetDocFunc().DeleteTable( nTab+nIndex+1, true, true );
3731 // XEnumerationAccess
3733 uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
3734 throw(uno::RuntimeException, std::exception)
3736 SolarMutexGuard aGuard;
3737 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.ScenariosEnumeration"));
3740 // XIndexAccess
3742 sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException, std::exception)
3744 SolarMutexGuard aGuard;
3745 SCTAB nCount = 0;
3746 if ( pDocShell )
3748 ScDocument* pDoc = pDocShell->GetDocument();
3749 if (!pDoc->IsScenario(nTab))
3751 SCTAB nTabCount = pDoc->GetTableCount();
3752 SCTAB nNext = nTab + 1;
3753 while (nNext < nTabCount && pDoc->IsScenario(nNext))
3755 ++nCount;
3756 ++nNext;
3760 return nCount;
3763 uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
3764 throw(lang::IndexOutOfBoundsException,
3765 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3767 SolarMutexGuard aGuard;
3768 uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
3769 if (xScen.is())
3770 return uno::makeAny(xScen);
3771 else
3772 throw lang::IndexOutOfBoundsException();
3775 uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException, std::exception)
3777 SolarMutexGuard aGuard;
3778 return cppu::UnoType<sheet::XScenario>::get();
3781 sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException, std::exception)
3783 SolarMutexGuard aGuard;
3784 return ( getCount() != 0 );
3787 uno::Any SAL_CALL ScScenariosObj::getByName( const OUString& aName )
3788 throw(container::NoSuchElementException,
3789 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3791 SolarMutexGuard aGuard;
3792 uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
3793 if (xScen.is())
3794 return uno::makeAny(xScen);
3795 else
3796 throw container::NoSuchElementException();
3799 uno::Sequence<OUString> SAL_CALL ScScenariosObj::getElementNames()
3800 throw(uno::RuntimeException, std::exception)
3802 SolarMutexGuard aGuard;
3803 SCTAB nCount = (SCTAB)getCount();
3804 uno::Sequence<OUString> aSeq(nCount);
3806 if ( pDocShell ) // sonst ist auch Count = 0
3808 OUString aTabName;
3809 ScDocument* pDoc = pDocShell->GetDocument();
3810 OUString* pAry = aSeq.getArray();
3811 for (SCTAB i=0; i<nCount; i++)
3812 if (pDoc->GetName( nTab+i+1, aTabName ))
3813 pAry[i] = aTabName;
3816 return aSeq;
3819 sal_Bool SAL_CALL ScScenariosObj::hasByName( const OUString& aName )
3820 throw(uno::RuntimeException, std::exception)
3822 SolarMutexGuard aGuard;
3823 SCTAB nIndex;
3824 return GetScenarioIndex_Impl( aName, nIndex );
3829 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */