Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / docuno.cxx
blob8cbd9fb68be19f3391c89cb488d427a29b02f8df
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>
61 #include "docuno.hxx"
62 #include "cellsuno.hxx"
63 #include "nameuno.hxx"
64 #include "datauno.hxx"
65 #include "miscuno.hxx"
66 #include "notesuno.hxx"
67 #include "styleuno.hxx"
68 #include "linkuno.hxx"
69 #include "servuno.hxx"
70 #include "targuno.hxx"
71 #include "convuno.hxx"
72 #include "optuno.hxx"
73 #include "forbiuno.hxx"
74 #include "docsh.hxx"
75 #include "hints.hxx"
76 #include "docfunc.hxx"
77 #include "postit.hxx"
78 #include "dociter.hxx"
79 #include "formulacell.hxx"
80 #include "drwlayer.hxx"
81 #include "rangeutl.hxx"
82 #include "markdata.hxx"
83 #include "docoptio.hxx"
84 #include "unonames.hxx"
85 #include "shapeuno.hxx"
86 #include "viewuno.hxx"
87 #include "tabvwsh.hxx"
88 #include "printfun.hxx"
89 #include "pfuncache.hxx"
90 #include "scmod.hxx"
91 #include "ViewSettingsSequenceDefines.hxx"
92 #include "sheetevents.hxx"
93 #include "sc.hrc"
94 #include "scresid.hxx"
95 #include "platforminfo.hxx"
96 #include "interpre.hxx"
97 #include "formulagroup.hxx"
99 using namespace com::sun::star;
101 // #i111553# provides the name of the VBA constant for this document type (e.g. 'ThisExcelDoc' for Calc)
102 #define SC_UNO_VBAGLOBNAME "VBAGlobalConstantName"
104 //------------------------------------------------------------------------
106 #ifndef SEQTYPE
107 #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
108 #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
109 #else
110 #define SEQTYPE(x) &(x)
111 #endif
112 #endif
114 // alles ohne Which-ID, Map nur fuer PropertySetInfo
116 //! umbenennen, sind nicht mehr nur Options
117 static const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap()
119 static const SfxItemPropertyMapEntry aDocOptPropertyMap_Impl[] =
121 {MAP_CHAR_LEN(SC_UNO_APPLYFMDES), 0, &getBooleanCppuType(), 0, 0},
122 {MAP_CHAR_LEN(SC_UNO_AREALINKS), 0, &getCppuType((uno::Reference<sheet::XAreaLinks>*)0), 0, 0},
123 {MAP_CHAR_LEN(SC_UNO_AUTOCONTFOC), 0, &getBooleanCppuType(), 0, 0},
124 {MAP_CHAR_LEN(SC_UNO_BASICLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
125 {MAP_CHAR_LEN(SC_UNO_DIALOGLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
126 {MAP_CHAR_LEN(SC_UNO_VBAGLOBNAME), 0, &getCppuType(static_cast< const OUString * >(0)), beans::PropertyAttribute::READONLY, 0},
127 {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN, &getBooleanCppuType(), 0, 0},
128 {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
129 {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
130 {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
131 {MAP_CHAR_LEN(SC_UNO_COLLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0, 0},
132 {MAP_CHAR_LEN(SC_UNO_DDELINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
133 {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP, &getCppuType((sal_Int16*)0), 0, 0},
134 {MAP_CHAR_LEN(SC_UNO_EXTERNALDOCLINKS), 0, &getCppuType((uno::Reference<sheet::XExternalDocLinks>*)0), 0, 0},
135 {MAP_CHAR_LEN(SC_UNO_FORBIDDEN), 0, &getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0), beans::PropertyAttribute::READONLY, 0},
136 {MAP_CHAR_LEN(SC_UNO_HASDRAWPAGES), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
137 {MAP_CHAR_LEN(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE, &getBooleanCppuType(), 0, 0},
138 {MAP_CHAR_LEN(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED, &getBooleanCppuType(), 0, 0},
139 {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT, &getCppuType((sal_Int32*)0), 0, 0},
140 {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON, &getCppuType((double*)0), 0, 0},
141 {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, &getBooleanCppuType(), 0, 0},
142 {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE, &getBooleanCppuType(), 0, 0},
143 {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES), 0, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0), 0, 0},
144 {MAP_CHAR_LEN(SC_UNO_DATABASERNG), 0, &getCppuType((uno::Reference<sheet::XDatabaseRanges>*)0), 0, 0},
145 {MAP_CHAR_LEN(SC_UNO_NULLDATE), PROP_UNO_NULLDATE, &getCppuType((util::Date*)0), 0, 0},
146 {MAP_CHAR_LEN(SC_UNO_ROWLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0, 0},
147 {MAP_CHAR_LEN(SC_UNO_SHEETLINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
148 {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE, &getBooleanCppuType(), 0, 0},
149 {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC, &getCppuType((sal_Int16*)0), 0, 0},
150 {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, &getBooleanCppuType(), 0, 0},
151 {MAP_CHAR_LEN(SC_UNO_RUNTIMEUID), 0, &getCppuType(static_cast< const OUString * >(0)), beans::PropertyAttribute::READONLY, 0},
152 {MAP_CHAR_LEN(SC_UNO_HASVALIDSIGNATURES), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
153 {MAP_CHAR_LEN(SC_UNO_ISLOADED), 0, &getBooleanCppuType(), 0, 0},
154 {MAP_CHAR_LEN(SC_UNO_ISUNDOENABLED), 0, &getBooleanCppuType(), 0, 0},
155 {MAP_CHAR_LEN(SC_UNO_ISADJUSTHEIGHTENABLED), 0, &getBooleanCppuType(), 0, 0},
156 {MAP_CHAR_LEN(SC_UNO_ISEXECUTELINKENABLED), 0, &getBooleanCppuType(), 0, 0},
157 {MAP_CHAR_LEN(SC_UNO_ISCHANGEREADONLYENABLED), 0, &getBooleanCppuType(), 0, 0},
158 {MAP_CHAR_LEN(SC_UNO_REFERENCEDEVICE), 0, &getCppuType((uno::Reference<awt::XDevice>*)0), beans::PropertyAttribute::READONLY, 0},
159 {MAP_CHAR_LEN("BuildId"), 0, &::getCppuType(static_cast< const OUString * >(0)), 0, 0},
160 {MAP_CHAR_LEN(SC_UNO_CODENAME), 0, &getCppuType(static_cast< const OUString * >(0)), 0, 0},
161 {MAP_CHAR_LEN(SC_UNO_INTEROPGRABBAG), 0, SEQTYPE(::getCppuType((uno::Sequence< beans::PropertyValue >*)0)), 0, 0},
163 {0,0,0,0,0,0}
165 return aDocOptPropertyMap_Impl;
168 //! StandardDecimals als Property und vom NumberFormatter ????????
170 static const SfxItemPropertyMapEntry* lcl_GetColumnsPropertyMap()
172 static const SfxItemPropertyMapEntry aColumnsPropertyMap_Impl[] =
174 {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 },
175 {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 },
176 {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 },
177 {MAP_CHAR_LEN(SC_UNONAME_OWIDTH), 0, &getBooleanCppuType(), 0, 0 },
178 {MAP_CHAR_LEN(SC_UNONAME_CELLWID), 0, &getCppuType((sal_Int32*)0), 0, 0 },
179 {0,0,0,0,0,0}
181 return aColumnsPropertyMap_Impl;
184 static const SfxItemPropertyMapEntry* lcl_GetRowsPropertyMap()
186 static const SfxItemPropertyMapEntry aRowsPropertyMap_Impl[] =
188 {MAP_CHAR_LEN(SC_UNONAME_CELLHGT), 0, &getCppuType((sal_Int32*)0), 0, 0 },
189 {MAP_CHAR_LEN(SC_UNONAME_CELLFILT), 0, &getBooleanCppuType(), 0, 0 },
190 {MAP_CHAR_LEN(SC_UNONAME_OHEIGHT), 0, &getBooleanCppuType(), 0, 0 },
191 {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 },
192 {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 },
193 {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 },
194 {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR },
195 {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT },
196 // not sorted, not used with SfxItemPropertyMapEntry::GetByName
197 {0,0,0,0,0,0}
199 return aRowsPropertyMap_Impl;
202 using sc::HMMToTwips;
203 using sc::TwipsToHMM;
205 //------------------------------------------------------------------------
207 #define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument"
208 #define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings"
209 #define SCDOC_SERVICE "com.sun.star.document.OfficeDocument"
211 SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
212 SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
213 SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" )
214 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" )
215 SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" )
216 SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" )
217 SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" )
219 //------------------------------------------------------------------------
221 class ScPrintUIOptions : public vcl::PrinterOptionsHelper
223 public:
224 ScPrintUIOptions();
225 void SetDefaults();
228 ScPrintUIOptions::ScPrintUIOptions()
230 const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
231 sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
232 sal_Bool bSuppress = rPrintOpt.GetSkipEmpty();
234 ResStringArray aStrings( ScResId( SCSTR_PRINT_OPTIONS ) );
235 OSL_ENSURE( aStrings.Count() >= 10, "resource incomplete" );
236 if( aStrings.Count() < 10 ) // bad resource ?
237 return;
239 sal_Int32 nNumProps= 9, nIdx = 0;
241 m_aUIProperties.realloc(nNumProps);
243 // load the writer PrinterOptions into the custom tab
244 m_aUIProperties[nIdx].Name = "OptionsUIFile";
245 m_aUIProperties[nIdx++].Value <<= OUString("modules/scalc/ui/printeroptions.ui");
247 // create Section for spreadsheet (results in an extra tab page in dialog)
248 SvtModuleOptions aOpt;
249 OUString aAppGroupname( aStrings.GetString( 9 ) );
250 aAppGroupname = aAppGroupname.replaceFirst( "%s", aOpt.GetModuleName( SvtModuleOptions::E_SCALC ) );
251 m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, OUString());
253 // show subgroup for pages
254 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("pages", OUString(aStrings.GetString(0)), OUString());
256 // create a bool option for empty pages
257 m_aUIProperties[nIdx++].Value = setBoolControlOpt("includeemptypages", OUString( aStrings.GetString( 1 ) ),
258 ".HelpID:vcl:PrintDialog:IsIncludeEmptyPages:CheckBox",
259 "IsIncludeEmptyPages",
260 ! bSuppress);
261 // show Subgroup for print content
262 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
263 aPrintRangeOpt.maGroupHint = "PrintRange";
264 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("printrange", OUString(aStrings.GetString(2)),
265 OUString(),
266 aPrintRangeOpt);
268 // create a choice for the content to create
269 uno::Sequence< OUString > aChoices( 3 ), aHelpIds( 3 ), aWidgetIds( 3 );
270 aChoices[0] = aStrings.GetString( 3 );
271 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0";
272 aWidgetIds[0] = "printallsheets";
273 aChoices[1] = aStrings.GetString( 4 );
274 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1";
275 aWidgetIds[1] = "printselectedsheets";
276 aChoices[2] = aStrings.GetString( 5 );
277 aHelpIds[2] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2";
278 aWidgetIds[2] = "printselectedcells";
279 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
280 aHelpIds, "PrintContent",
281 aChoices, nContent );
283 // show Subgroup for print range
284 aPrintRangeOpt.mbInternalOnly = sal_True;
285 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("fromwhich", OUString(aStrings.GetString(6)),
286 OUString(),
287 aPrintRangeOpt);
289 // create a choice for the range to print
290 OUString aPrintRangeName( "PrintRange" );
291 aChoices.realloc( 2 );
292 aHelpIds.realloc( 2 );
293 aWidgetIds.realloc( 2 );
294 aChoices[0] = aStrings.GetString( 7 );
295 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:0";
296 aWidgetIds[0] = "printallpages";
297 aChoices[1] = aStrings.GetString( 8 );
298 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:1";
299 aWidgetIds[1] = "printpages";
300 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
301 aHelpIds,
302 aPrintRangeName,
303 aChoices,
304 0 );
306 // create a an Edit dependent on "Pages" selected
307 vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintRangeName, 1, sal_True );
308 m_aUIProperties[nIdx++].Value = setEditControlOpt("pagerange", OUString(),
309 ".HelpID:vcl:PrintDialog:PageRange:Edit",
310 "PageRange", OUString(), aPageRangeOpt);
312 assert(nIdx == nNumProps);
315 void ScPrintUIOptions::SetDefaults()
317 // re-initialize the default values from print options
319 const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
320 sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
321 sal_Bool bSuppress = rPrintOpt.GetSkipEmpty();
323 for (sal_Int32 nUIPos=0; nUIPos<m_aUIProperties.getLength(); ++nUIPos)
325 uno::Sequence<beans::PropertyValue> aUIProp;
326 if ( m_aUIProperties[nUIPos].Value >>= aUIProp )
328 for (sal_Int32 nPropPos=0; nPropPos<aUIProp.getLength(); ++nPropPos)
330 OUString aName = aUIProp[nPropPos].Name;
331 if ( aName == "Property" )
333 beans::PropertyValue aPropertyValue;
334 if ( aUIProp[nPropPos].Value >>= aPropertyValue )
336 if ( aPropertyValue.Name == "PrintContent" )
338 aPropertyValue.Value <<= nContent;
339 aUIProp[nPropPos].Value <<= aPropertyValue;
341 else if ( aPropertyValue.Name == "IsIncludeEmptyPages" )
343 ScUnoHelpFunctions::SetBoolInAny( aPropertyValue.Value, ! bSuppress );
344 aUIProp[nPropPos].Value <<= aPropertyValue;
349 m_aUIProperties[nUIPos].Value <<= aUIProp;
354 void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
356 if (pDocSh)
357 pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
360 ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
361 SfxBaseModel( pDocSh ),
362 aPropSet( lcl_GetDocOptPropertyMap() ),
363 pDocShell( pDocSh ),
364 pPrintFuncCache( NULL ),
365 pPrinterOptions( NULL ),
366 maChangesListeners( m_aMutex )
368 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
369 if ( pDocShell )
371 pDocShell->GetDocument()->AddUnoObject(*this); // SfxModel is derived from SfxListener
375 ScModelObj::~ScModelObj()
377 if (pDocShell)
378 pDocShell->GetDocument()->RemoveUnoObject(*this);
380 if (xNumberAgg.is())
381 xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
383 delete pPrintFuncCache;
384 delete pPrinterOptions;
387 uno::Reference< uno::XAggregation> ScModelObj::GetFormatter()
389 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
390 if ( !xNumberAgg.is() && pDocShell )
392 // setDelegator veraendert den RefCount, darum eine Referenz selber halten
393 // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen)
394 comphelper::increment( m_refCount );
395 // waehrend des queryInterface braucht man ein Ref auf das
396 // SvNumberFormatsSupplierObj, sonst wird es geloescht.
397 uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument()->GetFormatTable() ));
399 xNumberAgg.set(uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ));
400 // extra block to force deletion of the temporary before setDelegator
403 // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren
404 xFormatter = NULL;
406 if (xNumberAgg.is())
407 xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
408 comphelper::decrement( m_refCount );
409 } // if ( !xNumberAgg.is() )
410 return xNumberAgg;
413 ScDocument* ScModelObj::GetDocument() const
415 if (pDocShell)
416 return pDocShell->GetDocument();
417 return NULL;
420 SfxObjectShell* ScModelObj::GetEmbeddedObject() const
422 return pDocShell;
425 void ScModelObj::UpdateAllRowHeights()
427 if (pDocShell)
428 pDocShell->UpdateAllRowHeights(NULL);
431 void ScModelObj::BeforeXMLLoading()
433 if (pDocShell)
434 pDocShell->BeforeXMLLoading();
437 void ScModelObj::AfterXMLLoading(sal_Bool bRet)
439 if (pDocShell)
440 pDocShell->AfterXMLLoading(bRet);
443 ScSheetSaveData* ScModelObj::GetSheetSaveData()
445 if (pDocShell)
446 return pDocShell->GetSheetSaveData();
447 return NULL;
450 void ScModelObj::RepaintRange( const ScRange& rRange )
452 if (pDocShell)
453 pDocShell->PostPaint( rRange, PAINT_GRID );
456 void ScModelObj::RepaintRange( const ScRangeList& rRange )
458 if (pDocShell)
459 pDocShell->PostPaint( rRange, PAINT_GRID );
462 uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
463 throw(uno::RuntimeException)
465 SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
466 SC_QUERYINTERFACE( document::XActionLockable )
467 SC_QUERYINTERFACE( sheet::XCalculatable )
468 SC_QUERYINTERFACE( util::XProtectable )
469 SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
470 SC_QUERYINTERFACE( sheet::XGoalSeek )
471 SC_QUERYINTERFACE( sheet::XConsolidatable )
472 SC_QUERYINTERFACE( sheet::XDocumentAuditing )
473 SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
474 SC_QUERYINTERFACE( view::XRenderable )
475 SC_QUERYINTERFACE( document::XLinkTargetSupplier )
476 SC_QUERYINTERFACE( beans::XPropertySet )
477 SC_QUERYINTERFACE( lang::XMultiServiceFactory )
478 SC_QUERYINTERFACE( lang::XServiceInfo )
479 SC_QUERYINTERFACE( util::XChangesNotifier )
480 SC_QUERYINTERFACE( sheet::opencl::XOpenCLSelection )
482 uno::Any aRet(SfxBaseModel::queryInterface( rType ));
483 if ( !aRet.hasValue()
484 && rType != ::getCppuType((uno::Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
485 && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XController>*)0)
486 && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XFrame>*)0)
487 && rType != ::getCppuType((uno::Reference< com::sun::star::script::XInvocation>*)0)
488 && rType != ::getCppuType((uno::Reference< com::sun::star::beans::XFastPropertySet>*)0)
489 && rType != ::getCppuType((uno::Reference< com::sun::star::awt::XWindow>*)0))
491 GetFormatter();
492 if ( xNumberAgg.is() )
493 aRet = xNumberAgg->queryAggregation( rType );
496 return aRet;
499 void SAL_CALL ScModelObj::acquire() throw()
501 SfxBaseModel::acquire();
504 void SAL_CALL ScModelObj::release() throw()
506 SfxBaseModel::release();
509 uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException)
511 static uno::Sequence<uno::Type> aTypes;
512 if ( aTypes.getLength() == 0 )
514 uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
515 long nParentLen = aParentTypes.getLength();
516 const uno::Type* pParentPtr = aParentTypes.getConstArray();
518 uno::Sequence<uno::Type> aAggTypes;
519 if ( GetFormatter().is() )
521 const uno::Type& rProvType = ::getCppuType((uno::Reference<lang::XTypeProvider>*) 0);
522 uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
523 if(aNumProv.getValueType() == rProvType)
525 uno::Reference<lang::XTypeProvider> xNumProv(
526 *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue());
527 aAggTypes = xNumProv->getTypes();
530 long nAggLen = aAggTypes.getLength();
531 const uno::Type* pAggPtr = aAggTypes.getConstArray();
533 const long nThisLen = 16;
534 aTypes.realloc( nParentLen + nAggLen + nThisLen );
535 uno::Type* pPtr = aTypes.getArray();
536 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetDocument>*)0);
537 pPtr[nParentLen + 1] = getCppuType((const uno::Reference<document::XActionLockable>*)0);
538 pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XCalculatable>*)0);
539 pPtr[nParentLen + 3] = getCppuType((const uno::Reference<util::XProtectable>*)0);
540 pPtr[nParentLen + 4] = getCppuType((const uno::Reference<drawing::XDrawPagesSupplier>*)0);
541 pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XGoalSeek>*)0);
542 pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XConsolidatable>*)0);
543 pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XDocumentAuditing>*)0);
544 pPtr[nParentLen + 8] = getCppuType((const uno::Reference<style::XStyleFamiliesSupplier>*)0);
545 pPtr[nParentLen + 9] = getCppuType((const uno::Reference<view::XRenderable>*)0);
546 pPtr[nParentLen +10] = getCppuType((const uno::Reference<document::XLinkTargetSupplier>*)0);
547 pPtr[nParentLen +11] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
548 pPtr[nParentLen +12] = getCppuType((const uno::Reference<lang::XMultiServiceFactory>*)0);
549 pPtr[nParentLen +13] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
550 pPtr[nParentLen +14] = getCppuType((const uno::Reference<util::XChangesNotifier>*)0);
551 pPtr[nParentLen +15] = getCppuType((const uno::Reference<sheet::opencl::XOpenCLSelection>*)0);
553 long i;
554 for (i=0; i<nParentLen; i++)
555 pPtr[i] = pParentPtr[i]; // parent types first
557 for (i=0; i<nAggLen; i++)
558 pPtr[nParentLen+nThisLen+i] = pAggPtr[i]; // aggregated types last
560 return aTypes;
563 namespace
565 class theScModelObjImplementationId : public rtl::Static< UnoTunnelIdInit, theScModelObjImplementationId > {};
568 uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId()
569 throw(uno::RuntimeException)
571 return theScModelObjImplementationId::get().getSeq();
574 void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
576 // Not interested in reference update hints here
578 if ( rHint.ISA( SfxSimpleHint ) )
580 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
581 if ( nId == SFX_HINT_DYING )
583 pDocShell = NULL; // has become invalid
584 if (xNumberAgg.is())
586 SvNumberFormatsSupplierObj* pNumFmt =
587 SvNumberFormatsSupplierObj::getImplementation(
588 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
589 if ( pNumFmt )
590 pNumFmt->SetNumberFormatter( NULL );
593 DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell
595 else if ( nId == SFX_HINT_DATACHANGED )
597 // cached data for rendering become invalid when contents change
598 // (if a broadcast is added to SetDrawModified, is has to be tested here, too)
600 DELETEZ( pPrintFuncCache );
602 // handle "OnCalculate" sheet events (search also for VBA event handlers)
603 if ( pDocShell )
605 ScDocument* pDoc = pDocShell->GetDocument();
606 if ( pDoc->GetVbaEventProcessor().is() )
608 // If the VBA event processor is set, HasAnyCalcNotification is much faster than HasAnySheetEventScript
609 if ( pDoc->HasAnyCalcNotification() && pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) )
610 HandleCalculateEvents();
612 else
614 if ( pDoc->HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE ) )
615 HandleCalculateEvents();
620 else if ( rHint.ISA( ScPointerChangedHint ) )
622 sal_uInt16 nFlags = ((const ScPointerChangedHint&)rHint).GetFlags();
623 if (nFlags & SC_POINTERCHANGED_NUMFMT)
625 // NumberFormatter-Pointer am Uno-Objekt neu setzen
627 if (GetFormatter().is())
629 SvNumberFormatsSupplierObj* pNumFmt =
630 SvNumberFormatsSupplierObj::getImplementation(
631 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
632 if ( pNumFmt && pDocShell )
633 pNumFmt->SetNumberFormatter( pDocShell->GetDocument()->GetFormatTable() );
638 // always call parent - SfxBaseModel might need to handle the same hints again
639 SfxBaseModel::Notify( rBC, rHint ); // SfxBaseModel is derived from SfxListener
642 // XSpreadsheetDocument
644 uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException)
646 SolarMutexGuard aGuard;
647 if (pDocShell)
648 return new ScTableSheetsObj(pDocShell);
649 return NULL;
652 // XStyleFamiliesSupplier
654 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
655 throw(uno::RuntimeException)
657 SolarMutexGuard aGuard;
658 if (pDocShell)
659 return new ScStyleFamiliesObj(pDocShell);
660 return NULL;
663 // XRenderable
665 static OutputDevice* lcl_GetRenderDevice( const uno::Sequence<beans::PropertyValue>& rOptions )
667 OutputDevice* pRet = NULL;
668 const beans::PropertyValue* pPropArray = rOptions.getConstArray();
669 long nPropCount = rOptions.getLength();
670 for (long i = 0; i < nPropCount; i++)
672 const beans::PropertyValue& rProp = pPropArray[i];
673 OUString aPropName(rProp.Name);
675 if (aPropName.equalsAscii( SC_UNONAME_RENDERDEV ))
677 uno::Reference<awt::XDevice> xRenderDevice(rProp.Value, uno::UNO_QUERY);
678 if ( xRenderDevice.is() )
680 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
681 if ( pDevice )
683 pRet = pDevice->GetOutputDevice();
684 pRet->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
689 return pRet;
692 static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, Rectangle& rTargetRect,
693 bool& rIsSheet, ScDocument* pDoc, SCTAB nSourceTab )
695 // test in same order as in SID_CURRENTCELL execute
697 ScAddress aAddress;
698 ScRangeUtil aRangeUtil;
699 SCTAB nNameTab;
700 sal_Int32 nNumeric = 0;
702 bool bRangeValid = false;
703 bool bRectValid = false;
705 if ( rTargetRange.Parse( rTarget, pDoc ) & SCA_VALID )
707 bRangeValid = true; // range reference
709 else if ( aAddress.Parse( rTarget, pDoc ) & SCA_VALID )
711 rTargetRange = aAddress;
712 bRangeValid = true; // cell reference
714 else if ( aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_NAMES ) ||
715 aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_DBASE ) )
717 bRangeValid = true; // named range or database range
719 else if ( comphelper::string::isdigitAsciiString(rTarget) &&
720 ( nNumeric = rTarget.toInt32() ) > 0 && nNumeric <= MAXROW+1 )
722 // row number is always mapped to cell A(row) on the same sheet
723 rTargetRange = ScAddress( 0, (SCROW)(nNumeric-1), nSourceTab ); // target row number is 1-based
724 bRangeValid = true; // row number
726 else if ( pDoc->GetTable( rTarget, nNameTab ) )
728 rTargetRange = ScAddress(0,0,nNameTab);
729 bRangeValid = true; // sheet name
730 rIsSheet = true; // needs special handling (first page of the sheet)
732 else
734 // look for named drawing object
736 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
737 if ( pDrawLayer )
739 SCTAB nTabCount = pDoc->GetTableCount();
740 for (SCTAB i=0; i<nTabCount && !bRangeValid; i++)
742 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
743 OSL_ENSURE(pPage,"Page ?");
744 if (pPage)
746 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
747 SdrObject* pObject = aIter.Next();
748 while (pObject && !bRangeValid)
750 if ( ScDrawLayer::GetVisibleName( pObject ) == rTarget )
752 rTargetRect = pObject->GetLogicRect(); // 1/100th mm
753 rTargetRange = pDoc->GetRange( i, rTargetRect ); // underlying cells
754 bRangeValid = bRectValid = true; // rectangle is valid
756 pObject = aIter.Next();
762 if ( bRangeValid && !bRectValid )
764 // get rectangle for cell range
765 rTargetRect = pDoc->GetMMRect( rTargetRange.aStart.Col(), rTargetRange.aStart.Row(),
766 rTargetRange.aEnd.Col(), rTargetRange.aEnd.Row(),
767 rTargetRange.aStart.Tab() );
770 return bRangeValid;
773 bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
774 const uno::Sequence< beans::PropertyValue >& rOptions,
775 ScMarkData& rMark,
776 ScPrintSelectionStatus& rStatus, OUString& rPagesStr ) const
778 OSL_ENSURE( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
779 OSL_ENSURE( pDocShell, "FillRenderMarkData: DocShell must be set" );
781 bool bDone = false;
783 uno::Reference<frame::XController> xView;
785 // defaults when no options are passed: all sheets, include empty pages
786 sal_Bool bSelectedSheetsOnly = false;
787 sal_Bool bIncludeEmptyPages = true;
789 bool bHasPrintContent = false;
790 sal_Int32 nPrintContent = 0; // all sheets / selected sheets / selected cells
791 sal_Int32 nPrintRange = 0; // all pages / pages
792 OUString aPageRange; // "pages" edit value
794 for( sal_Int32 i = 0, nLen = rOptions.getLength(); i < nLen; i++ )
796 if ( rOptions[i].Name == "IsOnlySelectedSheets" )
798 rOptions[i].Value >>= bSelectedSheetsOnly;
800 else if ( rOptions[i].Name == "IsIncludeEmptyPages" )
802 rOptions[i].Value >>= bIncludeEmptyPages;
804 else if ( rOptions[i].Name == "PageRange" )
806 rOptions[i].Value >>= aPageRange;
808 else if ( rOptions[i].Name == "PrintRange" )
810 rOptions[i].Value >>= nPrintRange;
812 else if ( rOptions[i].Name == "PrintContent" )
814 bHasPrintContent = true;
815 rOptions[i].Value >>= nPrintContent;
817 else if ( rOptions[i].Name == "View" )
819 rOptions[i].Value >>= xView;
823 // "Print Content" selection wins over "Selected Sheets" option
824 if ( bHasPrintContent )
825 bSelectedSheetsOnly = ( nPrintContent != 0 );
827 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
828 if ( xInterface.is() )
830 ScCellRangesBase* pSelObj = ScCellRangesBase::getImplementation( xInterface );
831 uno::Reference< drawing::XShapes > xShapes( xInterface, uno::UNO_QUERY );
832 if ( pSelObj && pSelObj->GetDocShell() == pDocShell )
834 bool bSheet = ( ScTableSheetObj::getImplementation( xInterface ) != NULL );
835 bool bCursor = pSelObj->IsCursorOnly();
836 const ScRangeList& rRanges = pSelObj->GetRangeList();
838 rMark.MarkFromRangeList( rRanges, false );
839 rMark.MarkToSimple();
841 if ( rMark.IsMultiMarked() )
843 // #i115266# copy behavior of old printing:
844 // treat multiple selection like a single selection with the enclosing range
845 ScRange aMultiMarkArea;
846 rMark.GetMultiMarkArea( aMultiMarkArea );
847 rMark.ResetMark();
848 rMark.SetMarkArea( aMultiMarkArea );
851 if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
853 // a sheet object is treated like an empty selection: print the used area of the sheet
855 if ( bCursor || bSheet ) // nothing selected -> use whole tables
857 rMark.ResetMark(); // doesn't change table selection
858 rStatus.SetMode( SC_PRINTSEL_CURSOR );
860 else
861 rStatus.SetMode( SC_PRINTSEL_RANGE );
863 rStatus.SetRanges( rRanges );
864 bDone = true;
866 // multi selection isn't supported
868 else if( xShapes.is() )
870 //print a selected ole object
871 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY );
872 if( xIndexAccess.is() )
874 // multi selection isn't supported yet
875 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
876 SvxShape* pShape = SvxShape::getImplementation( xShape );
877 if( pShape )
879 SdrObject *pSdrObj = pShape->GetSdrObject();
880 if( pDocShell )
882 ScDocument* pDoc = pDocShell->GetDocument();
883 if( pDoc && pSdrObj )
885 Rectangle aObjRect = pSdrObj->GetCurrentBoundRect();
886 SCTAB nCurrentTab = ScDocShell::GetCurTab();
887 ScRange aRange = pDoc->GetRange( nCurrentTab, aObjRect );
888 rMark.SetMarkArea( aRange );
890 if( rMark.IsMarked() && !rMark.IsMultiMarked() )
892 rStatus.SetMode( SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS );
893 bDone = true;
900 else if ( ScModelObj::getImplementation( xInterface ) == this )
902 // render the whole document
903 // -> no selection, all sheets
905 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
906 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
907 rMark.SelectTable( nTab, sal_True );
908 rStatus.SetMode( SC_PRINTSEL_DOCUMENT );
909 bDone = true;
911 // other selection types aren't supported
914 // restrict to selected sheets if a view is available
915 uno::Reference<sheet::XSelectedSheetsSupplier> xSelectedSheets(xView, uno::UNO_QUERY);
916 if (bSelectedSheetsOnly && xSelectedSheets.is())
918 uno::Sequence<sal_Int32> aSelected = xSelectedSheets->getSelectedSheets();
919 ScMarkData::MarkedTabsType aSelectedTabs;
920 SCTAB nMaxTab = pDocShell->GetDocument()->GetTableCount() -1;
921 for (sal_Int32 i = 0, n = aSelected.getLength(); i < n; ++i)
923 SCTAB nSelected = static_cast<SCTAB>(aSelected[i]);
924 if (ValidTab(nSelected, nMaxTab))
925 aSelectedTabs.insert(static_cast<SCTAB>(aSelected[i]));
927 rMark.SetSelectedTabs(aSelectedTabs);
930 ScPrintOptions aNewOptions;
931 aNewOptions.SetSkipEmpty( !bIncludeEmptyPages );
932 aNewOptions.SetAllSheets( !bSelectedSheetsOnly );
933 rStatus.SetOptions( aNewOptions );
935 // "PrintRange" enables (1) or disables (0) the "PageRange" edit
936 if ( nPrintRange == 1 )
937 rPagesStr = aPageRange;
938 else
939 rPagesStr = "";
941 return bDone;
945 sal_Int32 SAL_CALL ScModelObj::getRendererCount( const uno::Any& aSelection,
946 const uno::Sequence<beans::PropertyValue>& rOptions )
947 throw (lang::IllegalArgumentException, uno::RuntimeException)
949 SolarMutexGuard aGuard;
950 if (!pDocShell)
952 throw lang::DisposedException( OUString(),
953 static_cast< sheet::XSpreadsheetDocument* >(this) );
956 ScMarkData aMark;
957 ScPrintSelectionStatus aStatus;
958 OUString aPagesStr;
959 if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
960 return 0;
962 // The same ScPrintFuncCache object in pPrintFuncCache is used as long as
963 // the same selection is used (aStatus) and the document isn't changed
964 // (pPrintFuncCache is cleared in Notify handler)
966 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
968 delete pPrintFuncCache;
969 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
971 sal_Int32 nPages = pPrintFuncCache->GetPageCount();
973 sal_Int32 nSelectCount = nPages;
974 if ( !aPagesStr.isEmpty() )
976 StringRangeEnumerator aRangeEnum( aPagesStr, 0, nPages-1 );
977 nSelectCount = aRangeEnum.size();
979 return nSelectCount;
982 static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, const OUString& rPagesStr, sal_Int32 nTotalPages )
984 if ( rPagesStr.isEmpty() )
985 return nSelRenderer;
987 StringRangeEnumerator aRangeEnum( rPagesStr, 0, nTotalPages-1 );
988 StringRangeEnumerator::Iterator aIter = aRangeEnum.begin();
989 StringRangeEnumerator::Iterator aEnd = aRangeEnum.end();
990 for ( ; nSelRenderer > 0 && aIter != aEnd; --nSelRenderer )
991 ++aIter;
993 return *aIter; // returns -1 if reached the end
996 uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nSelRenderer,
997 const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& rOptions )
998 throw (lang::IllegalArgumentException, uno::RuntimeException)
1000 SolarMutexGuard aGuard;
1001 if (!pDocShell)
1003 throw lang::DisposedException( OUString(),
1004 static_cast< sheet::XSpreadsheetDocument* >(this) );
1007 ScMarkData aMark;
1008 ScPrintSelectionStatus aStatus;
1009 OUString aPagesStr;
1010 // #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
1011 long nTotalPages = 0;
1012 if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
1014 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1016 delete pPrintFuncCache;
1017 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1019 nTotalPages = pPrintFuncCache->GetPageCount();
1021 sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
1022 if ( nRenderer < 0 )
1024 if ( nSelRenderer == 0 )
1026 // getRenderer(0) is used to query the settings, so it must always return something
1028 SCTAB nCurTab = 0; //! use current sheet from view?
1029 ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
1030 Size aTwips = aDefaultFunc.GetPageSize();
1031 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
1033 uno::Sequence<beans::PropertyValue> aSequence(1);
1034 beans::PropertyValue* pArray = aSequence.getArray();
1035 pArray[0].Name = SC_UNONAME_PAGESIZE;
1036 pArray[0].Value <<= aPageSize;
1038 if( ! pPrinterOptions )
1039 pPrinterOptions = new ScPrintUIOptions;
1040 else
1041 pPrinterOptions->SetDefaults();
1042 pPrinterOptions->appendPrintUIOptions( aSequence );
1043 return aSequence;
1045 else
1046 throw lang::IllegalArgumentException();
1049 // printer is used as device (just for page layout), draw view is not needed
1051 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
1053 ScRange aRange;
1054 const ScRange* pSelRange = NULL;
1055 if ( aMark.IsMarked() )
1057 aMark.GetMarkArea( aRange );
1058 pSelRange = &aRange;
1060 ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
1061 pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
1062 aFunc.SetRenderFlag( sal_True );
1064 Range aPageRange( nRenderer+1, nRenderer+1 );
1065 MultiSelection aPage( aPageRange );
1066 aPage.SetTotalRange( Range(0,RANGE_MAX) );
1067 aPage.Select( aPageRange );
1069 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
1070 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
1072 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, NULL );
1074 ScRange aCellRange;
1075 sal_Bool bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
1076 Size aTwips = aFunc.GetPageSize();
1077 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
1079 long nPropCount = bWasCellRange ? 3 : 2;
1080 uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
1081 beans::PropertyValue* pArray = aSequence.getArray();
1082 pArray[0].Name = SC_UNONAME_PAGESIZE;
1083 pArray[0].Value <<= aPageSize;
1084 // #i111158# all positions are relative to the whole page, including non-printable area
1085 pArray[1].Name = SC_UNONAME_INC_NP_AREA;
1086 pArray[1].Value = uno::makeAny( sal_True );
1087 if ( bWasCellRange )
1089 table::CellRangeAddress aRangeAddress( nTab,
1090 aCellRange.aStart.Col(), aCellRange.aStart.Row(),
1091 aCellRange.aEnd.Col(), aCellRange.aEnd.Row() );
1092 pArray[2].Name = SC_UNONAME_SOURCERANGE;
1093 pArray[2].Value <<= aRangeAddress;
1096 if( ! pPrinterOptions )
1097 pPrinterOptions = new ScPrintUIOptions;
1098 else
1099 pPrinterOptions->SetDefaults();
1100 pPrinterOptions->appendPrintUIOptions( aSequence );
1101 return aSequence;
1104 void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelection,
1105 const uno::Sequence<beans::PropertyValue>& rOptions )
1106 throw(lang::IllegalArgumentException, uno::RuntimeException)
1108 SolarMutexGuard aGuard;
1109 if (!pDocShell)
1111 throw lang::DisposedException( OUString(),
1112 static_cast< sheet::XSpreadsheetDocument* >(this) );
1115 ScMarkData aMark;
1116 ScPrintSelectionStatus aStatus;
1117 OUString aPagesStr;
1118 if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
1119 throw lang::IllegalArgumentException();
1121 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1123 delete pPrintFuncCache;
1124 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1126 long nTotalPages = pPrintFuncCache->GetPageCount();
1127 sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
1128 if ( nRenderer < 0 )
1129 throw lang::IllegalArgumentException();
1131 OutputDevice* pDev = lcl_GetRenderDevice( rOptions );
1132 if ( !pDev )
1133 throw lang::IllegalArgumentException();
1135 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
1136 ScDocument* pDoc = pDocShell->GetDocument();
1138 FmFormView* pDrawView = NULL;
1140 // #114135#
1141 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1143 if( pModel )
1145 pDrawView = new FmFormView( pModel, pDev );
1146 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
1147 pDrawView->SetPrintPreview( sal_True );
1150 ScRange aRange;
1151 const ScRange* pSelRange = NULL;
1152 if ( aMark.IsMarked() )
1154 aMark.GetMarkArea( aRange );
1155 pSelRange = &aRange;
1158 // to increase performance, ScPrintState might be used here for subsequent
1159 // pages of the same sheet
1161 ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
1162 aFunc.SetDrawView( pDrawView );
1163 aFunc.SetRenderFlag( sal_True );
1164 if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
1165 aFunc.SetExclusivelyDrawOleAndDrawObjects();
1167 Range aPageRange( nRenderer+1, nRenderer+1 );
1168 MultiSelection aPage( aPageRange );
1169 aPage.SetTotalRange( Range(0,RANGE_MAX) );
1170 aPage.Select( aPageRange );
1172 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
1173 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
1175 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
1176 if ( nRenderer == nTabStart )
1178 // first page of a sheet: add outline item for the sheet name
1180 if ( pPDFData && pPDFData->GetIsExportBookmarks() )
1182 // the sheet starts at the top of the page
1183 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
1184 sal_Int32 nDestID = pPDFData->CreateDest( aArea );
1185 OUString aTabName;
1186 pDoc->GetName( nTab, aTabName );
1187 sal_Int32 nParent = -1; // top-level
1188 pPDFData->CreateOutlineItem( nParent, aTabName, nDestID );
1190 // #i56629# add the named destination stuff
1191 if( pPDFData && pPDFData->GetIsExportNamedDestinations() )
1193 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
1194 OUString aTabName;
1195 pDoc->GetName( nTab, aTabName );
1196 //need the PDF page number here
1197 pPDFData->CreateNamedDest( aTabName, aArea );
1201 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, true, NULL );
1203 // resolve the hyperlinks for PDF export
1205 if ( pPDFData )
1207 // iterate over the hyperlinks that were output for this page
1209 std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFData->GetBookmarks();
1210 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIter = rBookmarks.begin();
1211 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
1212 while ( aIter != aIEnd )
1214 OUString aBookmark = aIter->aBookmark;
1215 if ( aBookmark.toChar() == (sal_Unicode) '#' )
1217 // try to resolve internal link
1219 OUString aTarget( aBookmark.copy( 1 ) );
1221 ScRange aTargetRange;
1222 Rectangle aTargetRect; // 1/100th mm
1223 bool bIsSheet = false;
1224 bool bValid = lcl_ParseTarget( aTarget, aTargetRange, aTargetRect, bIsSheet, pDoc, nTab );
1226 if ( bValid )
1228 sal_Int32 nPage = -1;
1229 Rectangle aArea;
1230 if ( bIsSheet )
1232 // Get first page for sheet (if nothing from that sheet is printed,
1233 // this page can show a different sheet)
1234 nPage = pPrintFuncCache->GetTabStart( aTargetRange.aStart.Tab() );
1235 aArea = pDev->PixelToLogic( Rectangle( 0,0,0,0 ) );
1237 else
1239 pPrintFuncCache->InitLocations( aMark, pDev ); // does nothing if already initialized
1241 ScPrintPageLocation aLocation;
1242 if ( pPrintFuncCache->FindLocation( aTargetRange.aStart, aLocation ) )
1244 nPage = aLocation.nPage;
1246 // get the rectangle of the page's cell range in 1/100th mm
1247 ScRange aLocRange = aLocation.aCellRange;
1248 Rectangle aLocationMM = pDoc->GetMMRect(
1249 aLocRange.aStart.Col(), aLocRange.aStart.Row(),
1250 aLocRange.aEnd.Col(), aLocRange.aEnd.Row(),
1251 aLocRange.aStart.Tab() );
1252 Rectangle aLocationPixel = aLocation.aRectangle;
1254 // Scale and move the target rectangle from aLocationMM to aLocationPixel,
1255 // to get the target rectangle in pixels.
1257 Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
1258 Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );
1260 long nX1 = aLocationPixel.Left() + (long)
1261 ( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
1262 long nX2 = aLocationPixel.Left() + (long)
1263 ( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
1264 long nY1 = aLocationPixel.Top() + (long)
1265 ( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
1266 long nY2 = aLocationPixel.Top() + (long)
1267 ( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
1269 if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
1270 if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
1271 if ( nY1 > aLocationPixel.Bottom() ) nY1 = aLocationPixel.Bottom();
1272 if ( nY2 > aLocationPixel.Bottom() ) nY2 = aLocationPixel.Bottom();
1274 // The link target area is interpreted using the device's MapMode at
1275 // the time of the CreateDest call, so PixelToLogic can be used here,
1276 // regardless of the MapMode that is actually selected.
1278 aArea = pDev->PixelToLogic( Rectangle( nX1, nY1, nX2, nY2 ) );
1282 if ( nPage >= 0 )
1283 pPDFData->SetLinkDest( aIter->nLinkId, pPDFData->CreateDest( aArea, nPage ) );
1286 else
1288 // external link, use as-is
1289 pPDFData->SetLinkURL( aIter->nLinkId, aBookmark );
1291 ++aIter;
1293 rBookmarks.clear();
1296 if ( pDrawView )
1297 pDrawView->HideSdrPage();
1298 delete pDrawView;
1301 // XLinkTargetSupplier
1303 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException)
1305 SolarMutexGuard aGuard;
1306 if (pDocShell)
1307 return new ScLinkTargetTypesObj(pDocShell);
1308 return NULL;
1311 // XActionLockable
1313 sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException)
1315 SolarMutexGuard aGuard;
1316 sal_Bool bLocked = false;
1317 if (pDocShell)
1318 bLocked = ( pDocShell->GetLockCount() != 0 );
1319 return bLocked;
1322 void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException)
1324 SolarMutexGuard aGuard;
1325 if (pDocShell)
1326 pDocShell->LockDocument();
1329 void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException)
1331 SolarMutexGuard aGuard;
1332 if (pDocShell)
1333 pDocShell->UnlockDocument();
1336 void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException)
1338 SolarMutexGuard aGuard;
1339 if (pDocShell)
1340 pDocShell->SetLockCount(nLock);
1343 sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException)
1345 SolarMutexGuard aGuard;
1346 sal_uInt16 nRet = 0;
1347 if (pDocShell)
1349 nRet = pDocShell->GetLockCount();
1350 pDocShell->SetLockCount(0);
1352 return nRet;
1355 void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException)
1357 SolarMutexGuard aGuard;
1358 SfxBaseModel::lockControllers();
1359 if (pDocShell)
1360 pDocShell->LockPaint();
1363 void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException)
1365 SolarMutexGuard aGuard;
1366 if (hasControllersLocked())
1368 SfxBaseModel::unlockControllers();
1369 if (pDocShell)
1370 pDocShell->UnlockPaint();
1374 // XCalculate
1376 void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException)
1378 SolarMutexGuard aGuard;
1379 if (pDocShell)
1380 pDocShell->DoRecalc(sal_True);
1381 else
1383 OSL_FAIL("keine DocShell"); //! Exception oder so?
1387 void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException)
1389 SolarMutexGuard aGuard;
1390 if (pDocShell)
1391 pDocShell->DoHardRecalc(sal_True);
1392 else
1394 OSL_FAIL("keine DocShell"); //! Exception oder so?
1398 sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException)
1400 SolarMutexGuard aGuard;
1401 if (pDocShell)
1402 return pDocShell->GetDocument()->GetAutoCalc();
1404 OSL_FAIL("keine DocShell"); //! Exception oder so?
1405 return false;
1408 void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabledIn )
1409 throw(uno::RuntimeException)
1411 bool bEnabled(bEnabledIn);
1412 SolarMutexGuard aGuard;
1413 if (pDocShell)
1415 ScDocument* pDoc = pDocShell->GetDocument();
1416 if ( pDoc->GetAutoCalc() != bEnabled )
1418 pDoc->SetAutoCalc( bEnabled );
1419 pDocShell->SetDocumentModified();
1422 else
1424 OSL_FAIL("keine DocShell"); //! Exception oder so?
1428 // XProtectable
1430 void SAL_CALL ScModelObj::protect( const OUString& aPassword ) throw(uno::RuntimeException)
1432 SolarMutexGuard aGuard;
1433 // #i108245# if already protected, don't change anything
1434 if ( pDocShell && !pDocShell->GetDocument()->IsDocProtected() )
1436 OUString aString(aPassword);
1437 pDocShell->GetDocFunc().Protect( TABLEID_DOC, aString, sal_True );
1441 void SAL_CALL ScModelObj::unprotect( const OUString& aPassword )
1442 throw(lang::IllegalArgumentException, uno::RuntimeException)
1444 SolarMutexGuard aGuard;
1445 if (pDocShell)
1447 OUString aString(aPassword);
1448 sal_Bool bDone = pDocShell->GetDocFunc().Unprotect( TABLEID_DOC, aString, sal_True );
1449 if (!bDone)
1450 throw lang::IllegalArgumentException();
1454 sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException)
1456 SolarMutexGuard aGuard;
1457 if (pDocShell)
1458 return pDocShell->GetDocument()->IsDocProtected();
1460 OSL_FAIL("keine DocShell"); //! Exception oder so?
1461 return false;
1464 // XDrawPagesSupplier
1466 uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException)
1468 SolarMutexGuard aGuard;
1469 if (pDocShell)
1470 return new ScDrawPagesObj(pDocShell);
1472 OSL_FAIL("keine DocShell"); //! Exception oder so?
1473 return NULL;
1476 // XGoalSeek
1478 sheet::GoalResult SAL_CALL ScModelObj::seekGoal(
1479 const table::CellAddress& aFormulaPosition,
1480 const table::CellAddress& aVariablePosition,
1481 const OUString& aGoalValue )
1482 throw(uno::RuntimeException)
1484 SolarMutexGuard aGuard;
1485 sheet::GoalResult aResult;
1486 aResult.Divergence = DBL_MAX; // nichts gefunden
1487 if (pDocShell)
1489 WaitObject aWait( pDocShell->GetActiveDialogParent() );
1490 OUString aGoalString(aGoalValue);
1491 ScDocument* pDoc = pDocShell->GetDocument();
1492 double fValue = 0.0;
1493 sal_Bool bFound = pDoc->Solver(
1494 (SCCOL)aFormulaPosition.Column, (SCROW)aFormulaPosition.Row, aFormulaPosition.Sheet,
1495 (SCCOL)aVariablePosition.Column, (SCROW)aVariablePosition.Row, aVariablePosition.Sheet,
1496 aGoalString, fValue );
1497 aResult.Result = fValue;
1498 if (bFound)
1499 aResult.Divergence = 0.0; //! das ist gelogen
1501 return aResult;
1504 // XConsolidatable
1506 uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
1507 sal_Bool bEmpty ) throw(uno::RuntimeException)
1509 SolarMutexGuard aGuard;
1510 ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
1511 if ( pDocShell && !bEmpty )
1513 ScDocument* pDoc = pDocShell->GetDocument();
1514 const ScConsolidateParam* pParam = pDoc->GetConsolidateDlgData();
1515 if (pParam)
1516 pNew->SetParam( *pParam );
1518 return pNew;
1521 void SAL_CALL ScModelObj::consolidate(
1522 const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
1523 throw(uno::RuntimeException)
1525 SolarMutexGuard aGuard;
1526 // das koennte theoretisch ein fremdes Objekt sein, also nur das
1527 // oeffentliche XConsolidationDescriptor Interface benutzen, um
1528 // die Daten in ein ScConsolidationDescriptor Objekt zu kopieren:
1529 //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation?
1531 ScConsolidationDescriptor aImpl;
1532 aImpl.setFunction( xDescriptor->getFunction() );
1533 aImpl.setSources( xDescriptor->getSources() );
1534 aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
1535 aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
1536 aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
1537 aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
1539 if (pDocShell)
1541 const ScConsolidateParam& rParam = aImpl.GetParam();
1542 pDocShell->DoConsolidate( rParam, sal_True );
1543 pDocShell->GetDocument()->SetConsolidateDlgData( &rParam );
1547 // XDocumentAuditing
1549 void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException)
1551 SolarMutexGuard aGuard;
1552 if (pDocShell)
1553 pDocShell->GetDocFunc().DetectiveRefresh();
1556 // XViewDataSupplier
1557 uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData( )
1558 throw (uno::RuntimeException)
1560 uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
1562 if( !xRet.is() )
1564 SolarMutexGuard aGuard;
1565 if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
1567 uno::Reference < container::XIndexContainer > xCont = document::IndexedPropertyValues::create( ::comphelper::getProcessComponentContext() );
1568 xRet.set( xCont, uno::UNO_QUERY_THROW );
1570 uno::Sequence< beans::PropertyValue > aSeq;
1571 aSeq.realloc(1);
1572 OUString sName;
1573 pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName );
1574 OUString sOUName(sName);
1575 aSeq[0].Name = SC_ACTIVETABLE;
1576 aSeq[0].Value <<= sOUName;
1577 xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
1581 return xRet;
1584 // XPropertySet (Doc-Optionen)
1585 //! auch an der Applikation anbieten?
1587 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
1588 throw(uno::RuntimeException)
1590 SolarMutexGuard aGuard;
1591 static uno::Reference<beans::XPropertySetInfo> aRef(
1592 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1593 return aRef;
1596 void SAL_CALL ScModelObj::setPropertyValue(
1597 const OUString& aPropertyName, const uno::Any& aValue )
1598 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1599 lang::IllegalArgumentException, lang::WrappedTargetException,
1600 uno::RuntimeException)
1602 SolarMutexGuard aGuard;
1603 OUString aString(aPropertyName);
1605 if (pDocShell)
1607 ScDocument* pDoc = pDocShell->GetDocument();
1608 const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1609 ScDocOptions aNewOpt = rOldOpt;
1610 // Don't recalculate while loading XML, when the formula text is stored
1611 // Recalculation after loading is handled separately.
1612 bool bHardRecalc = !pDoc->IsImportingXML();
1614 sal_Bool bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropSet.getPropertyMap(), aPropertyName, aValue );
1615 if (bOpt)
1617 // done...
1618 if ( aString.equalsAscii( SC_UNO_IGNORECASE ) ||
1619 aString.equalsAscii( SC_UNONAME_REGEXP ) ||
1620 aString.equalsAscii( SC_UNO_LOOKUPLABELS ) )
1621 bHardRecalc = false;
1623 else if ( aString.equalsAscii( SC_UNONAME_CLOCAL ) )
1625 lang::Locale aLocale;
1626 if ( aValue >>= aLocale )
1628 LanguageType eLatin, eCjk, eCtl;
1629 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1630 eLatin = ScUnoConversion::GetLanguage(aLocale);
1631 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1634 else if ( aString.equalsAscii( SC_UNO_CODENAME ) )
1636 OUString sCodeName;
1637 if ( aValue >>= sCodeName )
1638 pDoc->SetCodeName( sCodeName );
1640 else if ( aString.equalsAscii( SC_UNO_CJK_CLOCAL ) )
1642 lang::Locale aLocale;
1643 if ( aValue >>= aLocale )
1645 LanguageType eLatin, eCjk, eCtl;
1646 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1647 eCjk = ScUnoConversion::GetLanguage(aLocale);
1648 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1651 else if ( aString.equalsAscii( SC_UNO_CTL_CLOCAL ) )
1653 lang::Locale aLocale;
1654 if ( aValue >>= aLocale )
1656 LanguageType eLatin, eCjk, eCtl;
1657 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1658 eCtl = ScUnoConversion::GetLanguage(aLocale);
1659 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1662 else if ( aString.equalsAscii( SC_UNO_APPLYFMDES ) )
1664 // model is created if not there
1665 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1666 pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1668 SfxBindings* pBindings = pDocShell->GetViewBindings();
1669 if (pBindings)
1670 pBindings->Invalidate( SID_FM_OPEN_READONLY );
1672 else if ( aString.equalsAscii( SC_UNO_AUTOCONTFOC ) )
1674 // model is created if not there
1675 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1676 pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1678 SfxBindings* pBindings = pDocShell->GetViewBindings();
1679 if (pBindings)
1680 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
1682 else if ( aString.equalsAscii( SC_UNO_ISLOADED ) )
1684 pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1686 else if ( aString.equalsAscii( SC_UNO_ISUNDOENABLED ) )
1688 sal_Bool bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1689 pDoc->EnableUndo( bUndoEnabled );
1690 pDocShell->GetUndoManager()->SetMaxUndoActionCount(
1691 bUndoEnabled
1692 ? officecfg::Office::Common::Undo::Steps::get() : 0);
1694 else if ( aString.equalsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1696 bool bOldAdjustHeightEnabled = pDoc->IsAdjustHeightEnabled();
1697 bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1698 if( bOldAdjustHeightEnabled != bAdjustHeightEnabled )
1699 pDoc->EnableAdjustHeight( bAdjustHeightEnabled );
1701 else if ( aString.equalsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1703 pDoc->EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1705 else if ( aString.equalsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1707 pDoc->EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1709 else if ( aString.equalsAscii( "BuildId" ) )
1711 aValue >>= maBuildId;
1713 else if ( aString.equalsAscii( "SavedObject" ) ) // set from chart after saving
1715 OUString aObjName;
1716 aValue >>= aObjName;
1717 if ( !aObjName.isEmpty() )
1718 pDoc->RestoreChartListener( aObjName );
1720 else if ( aString.equalsAscii( SC_UNO_INTEROPGRABBAG ) )
1722 setGrabBagItem(aValue);
1725 if ( aNewOpt != rOldOpt )
1727 pDoc->SetDocOptions( aNewOpt );
1728 //! Recalc only for options that need it?
1729 if ( bHardRecalc )
1730 pDocShell->DoHardRecalc( sal_True );
1731 pDocShell->SetDocumentModified();
1736 uno::Any SAL_CALL ScModelObj::getPropertyValue( const OUString& aPropertyName )
1737 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1738 uno::RuntimeException)
1740 SolarMutexGuard aGuard;
1741 OUString aString(aPropertyName);
1742 uno::Any aRet;
1744 if (pDocShell)
1746 ScDocument* pDoc = pDocShell->GetDocument();
1747 const ScDocOptions& rOpt = pDoc->GetDocOptions();
1748 aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropSet.getPropertyMap(), aPropertyName );
1749 if ( aRet.hasValue() )
1751 // done...
1753 else if ( aString.equalsAscii( SC_UNONAME_CLOCAL ) )
1755 LanguageType eLatin, eCjk, eCtl;
1756 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1758 lang::Locale aLocale;
1759 ScUnoConversion::FillLocale( aLocale, eLatin );
1760 aRet <<= aLocale;
1762 else if ( aString.equalsAscii( SC_UNO_CODENAME ) )
1764 OUString sCodeName = pDoc->GetCodeName();
1765 aRet <<= sCodeName;
1768 else if ( aString.equalsAscii( SC_UNO_CJK_CLOCAL ) )
1770 LanguageType eLatin, eCjk, eCtl;
1771 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1773 lang::Locale aLocale;
1774 ScUnoConversion::FillLocale( aLocale, eCjk );
1775 aRet <<= aLocale;
1777 else if ( aString.equalsAscii( SC_UNO_CTL_CLOCAL ) )
1779 LanguageType eLatin, eCjk, eCtl;
1780 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1782 lang::Locale aLocale;
1783 ScUnoConversion::FillLocale( aLocale, eCtl );
1784 aRet <<= aLocale;
1786 else if ( aString.equalsAscii( SC_UNO_NAMEDRANGES ) )
1788 aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
1790 else if ( aString.equalsAscii( SC_UNO_DATABASERNG ) )
1792 aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
1794 else if ( aString.equalsAscii( SC_UNO_UNNAMEDDBRNG ) )
1796 aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell));
1798 else if ( aString.equalsAscii( SC_UNO_COLLABELRNG ) )
1800 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, sal_True ));
1802 else if ( aString.equalsAscii( SC_UNO_ROWLABELRNG ) )
1804 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, false ));
1806 else if ( aString.equalsAscii( SC_UNO_AREALINKS ) )
1808 aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
1810 else if ( aString.equalsAscii( SC_UNO_DDELINKS ) )
1812 aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
1814 else if ( aString.equalsAscii( SC_UNO_EXTERNALDOCLINKS ) )
1816 aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
1818 else if ( aString.equalsAscii( SC_UNO_SHEETLINKS ) )
1820 aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
1822 else if ( aString.equalsAscii( SC_UNO_APPLYFMDES ) )
1824 // default for no model is TRUE
1825 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1826 sal_Bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True;
1827 ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
1829 else if ( aString.equalsAscii( SC_UNO_AUTOCONTFOC ) )
1831 // default for no model is FALSE
1832 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1833 sal_Bool bAutoControlFocus = pModel ? pModel->GetAutoControlFocus() : false;
1834 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
1836 else if ( aString.equalsAscii( SC_UNO_FORBIDDEN ) )
1838 aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
1840 else if ( aString.equalsAscii( SC_UNO_HASDRAWPAGES ) )
1842 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) );
1844 else if ( aString.equalsAscii( SC_UNO_BASICLIBRARIES ) )
1846 aRet <<= pDocShell->GetBasicContainer();
1848 else if ( aString.equalsAscii( SC_UNO_DIALOGLIBRARIES ) )
1850 aRet <<= pDocShell->GetDialogContainer();
1852 else if ( aString.equalsAscii( SC_UNO_VBAGLOBNAME ) )
1854 /* #i111553# This property provides the name of the constant that
1855 will be used to store this model in the global Basic manager.
1856 That constant will be equivelant to 'ThisComponent' but for
1857 each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
1858 constant can co-exist, as required by VBA. */
1859 aRet <<= OUString( "ThisExcelDoc" );
1861 else if ( aString.equalsAscii( SC_UNO_RUNTIMEUID ) )
1863 aRet <<= getRuntimeUID();
1865 else if ( aString.equalsAscii( SC_UNO_HASVALIDSIGNATURES ) )
1867 aRet <<= hasValidSignatures();
1869 else if ( aString.equalsAscii( SC_UNO_ISLOADED ) )
1871 ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
1873 else if ( aString.equalsAscii( SC_UNO_ISUNDOENABLED ) )
1875 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsUndoEnabled() );
1877 else if ( aString.equalsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1879 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsAdjustHeightEnabled() );
1881 else if ( aString.equalsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1883 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsExecuteLinkEnabled() );
1885 else if ( aString.equalsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1887 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsChangeReadOnlyEnabled() );
1889 else if ( aString.equalsAscii( SC_UNO_REFERENCEDEVICE ) )
1891 VCLXDevice* pXDev = new VCLXDevice();
1892 pXDev->SetOutputDevice( pDoc->GetRefDevice() );
1893 aRet <<= uno::Reference< awt::XDevice >( pXDev );
1895 else if ( aString.equalsAscii( "BuildId" ) )
1897 aRet <<= maBuildId;
1899 else if ( aString.equalsAscii( "InternalDocument" ) )
1901 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL) );
1903 else if ( aString.equalsAscii( SC_UNO_INTEROPGRABBAG ) )
1905 getGrabBagItem(aRet);
1909 return aRet;
1912 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
1914 // XMultiServiceFactory
1916 css::uno::Reference<css::uno::XInterface> ScModelObj::create(
1917 OUString const & aServiceSpecifier,
1918 css::uno::Sequence<css::uno::Any> const * arguments)
1920 uno::Reference<uno::XInterface> xRet;
1921 OUString aNameStr(aServiceSpecifier);
1922 sal_uInt16 nType = ScServiceProvider::GetProviderType(aNameStr);
1923 if ( nType != SC_SERVICE_INVALID )
1925 // drawing layer tables must be kept as long as the model is alive
1926 // return stored instance if already set
1927 switch ( nType )
1929 case SC_SERVICE_GRADTAB: xRet.set(xDrawGradTab); break;
1930 case SC_SERVICE_HATCHTAB: xRet.set(xDrawHatchTab); break;
1931 case SC_SERVICE_BITMAPTAB: xRet.set(xDrawBitmapTab); break;
1932 case SC_SERVICE_TRGRADTAB: xRet.set(xDrawTrGradTab); break;
1933 case SC_SERVICE_MARKERTAB: xRet.set(xDrawMarkerTab); break;
1934 case SC_SERVICE_DASHTAB: xRet.set(xDrawDashTab); break;
1935 case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv); break;
1936 case SC_SERVICE_VBAOBJECTPROVIDER: xRet.set(xObjProvider); break;
1939 // #i64497# If a chart is in a temporary document during clipoard paste,
1940 // there should be no data provider, so that own data is used
1941 bool bCreate =
1942 ! ( nType == SC_SERVICE_CHDATAPROV &&
1943 ( pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL ));
1944 // this should never happen, i.e. the temporary document should never be
1945 // loaded, because this unlinks the data
1946 OSL_ASSERT( bCreate );
1948 if ( !xRet.is() && bCreate )
1950 xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
1952 // store created instance
1953 switch ( nType )
1955 case SC_SERVICE_GRADTAB: xDrawGradTab.set(xRet); break;
1956 case SC_SERVICE_HATCHTAB: xDrawHatchTab.set(xRet); break;
1957 case SC_SERVICE_BITMAPTAB: xDrawBitmapTab.set(xRet); break;
1958 case SC_SERVICE_TRGRADTAB: xDrawTrGradTab.set(xRet); break;
1959 case SC_SERVICE_MARKERTAB: xDrawMarkerTab.set(xRet); break;
1960 case SC_SERVICE_DASHTAB: xDrawDashTab.set(xRet); break;
1961 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet); break;
1962 case SC_SERVICE_VBAOBJECTPROVIDER: xObjProvider.set(xRet); break;
1966 else
1968 // alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals,
1969 // da wird dann 'ne Exception geworfen, wenn's nicht passt...
1973 xRet = arguments == 0
1974 ? SvxFmMSFactory::createInstance(aServiceSpecifier)
1975 : SvxFmMSFactory::createInstanceWithArguments(
1976 aServiceSpecifier, *arguments);
1977 // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
1979 catch ( lang::ServiceNotRegisteredException & )
1983 // if the drawing factory created a shape, a ScShapeObj has to be used
1984 // to support own properties like ImageMap:
1986 uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
1987 if ( xShape.is() )
1989 xRet.clear(); // for aggregation, xShape must be the object's only ref
1990 new ScShapeObj( xShape ); // aggregates object and modifies xShape
1991 xRet.set(xShape);
1994 return xRet;
1997 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
1998 const OUString& aServiceSpecifier )
1999 throw(uno::Exception, uno::RuntimeException)
2001 SolarMutexGuard aGuard;
2002 return create(aServiceSpecifier, 0);
2005 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments(
2006 const OUString& ServiceSpecifier,
2007 const uno::Sequence<uno::Any>& aArgs )
2008 throw(uno::Exception, uno::RuntimeException)
2010 //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer?
2012 SolarMutexGuard aGuard;
2013 uno::Reference<uno::XInterface> xInt(create(ServiceSpecifier, &aArgs));
2015 if ( aArgs.getLength() )
2017 // used only for cell value binding so far - it can be initialized after creating
2019 uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
2020 if ( xInit.is() )
2021 xInit->initialize( aArgs );
2024 return xInt;
2027 uno::Sequence<OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
2028 throw(uno::RuntimeException)
2030 SolarMutexGuard aGuard;
2032 //! warum sind die Parameter bei concatServiceNames nicht const ???
2033 //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
2034 //! SvxFmMSFactory::getAvailableServiceNames() );
2036 uno::Sequence<OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
2037 uno::Sequence<OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
2039 return concatServiceNames( aMyServices, aDrawServices );
2042 // XServiceInfo
2044 OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException)
2046 return OUString( "ScModelObj" );
2049 sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName )
2050 throw(uno::RuntimeException)
2052 return rServiceName.equalsAscii( SCMODELOBJ_SERVICE ) ||
2053 rServiceName.equalsAscii( SCDOCSETTINGS_SERVICE ) ||
2054 rServiceName.equalsAscii( SCDOC_SERVICE );
2057 uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
2058 throw(uno::RuntimeException)
2060 uno::Sequence<OUString> aRet(2);
2061 aRet[0] = SCMODELOBJ_SERVICE;
2062 aRet[1] = SCDOCSETTINGS_SERVICE;
2063 return aRet;
2066 // XUnoTunnel
2068 sal_Int64 SAL_CALL ScModelObj::getSomething(
2069 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
2071 if ( rId.getLength() == 16 &&
2072 0 == memcmp( getUnoTunnelId().getConstArray(),
2073 rId.getConstArray(), 16 ) )
2075 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2078 if ( rId.getLength() == 16 &&
2079 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
2080 rId.getConstArray(), 16 ) )
2082 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
2085 // aggregated number formats supplier has XUnoTunnel, too
2086 // interface from aggregated object must be obtained via queryAggregation
2088 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
2089 if ( nRet )
2090 return nRet;
2092 if ( GetFormatter().is() )
2094 const uno::Type& rTunnelType = ::getCppuType((uno::Reference<lang::XUnoTunnel>*) 0);
2095 uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
2096 if(aNumTunnel.getValueType() == rTunnelType)
2098 uno::Reference<lang::XUnoTunnel> xTunnelAgg(
2099 *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue());
2100 return xTunnelAgg->getSomething( rId );
2104 return 0;
2107 namespace
2109 class theScModelObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScModelObjUnoTunnelId> {};
2112 const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
2114 return theScModelObjUnoTunnelId::get().getSeq();
2117 ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
2119 ScModelObj* pRet = NULL;
2120 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
2121 if (xUT.is())
2122 pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2123 return pRet;
2126 // XChangesNotifier
2128 void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
2129 throw (uno::RuntimeException)
2131 SolarMutexGuard aGuard;
2132 maChangesListeners.addInterface( aListener );
2135 void ScModelObj::removeChangesListener( const uno::Reference< util::XChangesListener >& aListener )
2136 throw (uno::RuntimeException)
2138 SolarMutexGuard aGuard;
2139 maChangesListeners.removeInterface( aListener );
2142 bool ScModelObj::HasChangesListeners() const
2144 if ( maChangesListeners.getLength() > 0 )
2145 return true;
2147 // "change" event set in any sheet?
2148 return pDocShell && pDocShell->GetDocument()->HasAnySheetEventScript(SC_SHEETEVENT_CHANGE);
2151 void ScModelObj::NotifyChanges( const OUString& rOperation, const ScRangeList& rRanges,
2152 const uno::Sequence< beans::PropertyValue >& rProperties )
2154 if ( pDocShell && HasChangesListeners() )
2156 util::ChangesEvent aEvent;
2157 aEvent.Source.set( static_cast< cppu::OWeakObject* >( this ) );
2158 aEvent.Base <<= aEvent.Source;
2160 size_t nRangeCount = rRanges.size();
2161 aEvent.Changes.realloc( static_cast< sal_Int32 >( nRangeCount ) );
2162 for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
2164 uno::Reference< table::XCellRange > xRangeObj;
2166 ScRange aRange( *rRanges[ nIndex ] );
2167 if ( aRange.aStart == aRange.aEnd )
2169 xRangeObj.set( new ScCellObj( pDocShell, aRange.aStart ) );
2171 else
2173 xRangeObj.set( new ScCellRangeObj( pDocShell, aRange ) );
2176 util::ElementChange& rChange = aEvent.Changes[ static_cast< sal_Int32 >( nIndex ) ];
2177 rChange.Accessor <<= rOperation;
2178 rChange.Element <<= rProperties;
2179 rChange.ReplacedElement <<= xRangeObj;
2182 ::cppu::OInterfaceIteratorHelper aIter( maChangesListeners );
2183 while ( aIter.hasMoreElements() )
2187 static_cast< util::XChangesListener* >( aIter.next() )->changesOccurred( aEvent );
2189 catch( uno::Exception& )
2195 // handle sheet events
2196 //! separate method with ScMarkData? Then change HasChangesListeners back.
2197 if ( rOperation.equalsAscii("cell-change") && pDocShell )
2199 ScMarkData aMarkData;
2200 aMarkData.MarkFromRangeList( rRanges, false );
2201 ScDocument* pDoc = pDocShell->GetDocument();
2202 SCTAB nTabCount = pDoc->GetTableCount();
2203 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
2204 for (; itr != itrEnd && *itr < nTabCount; ++itr)
2206 SCTAB nTab = *itr;
2207 const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
2208 if (pEvents)
2210 const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CHANGE);
2211 if (pScript)
2213 ScRangeList aTabRanges; // collect ranges on this sheet
2214 size_t nRangeCount = rRanges.size();
2215 for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
2217 ScRange aRange( *rRanges[ nIndex ] );
2218 if ( aRange.aStart.Tab() == nTab )
2219 aTabRanges.Append( aRange );
2221 size_t nTabRangeCount = aTabRanges.size();
2222 if ( nTabRangeCount > 0 )
2224 uno::Reference<uno::XInterface> xTarget;
2225 if ( nTabRangeCount == 1 )
2227 ScRange aRange( *aTabRanges[ 0 ] );
2228 if ( aRange.aStart == aRange.aEnd )
2229 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellObj( pDocShell, aRange.aStart ) ) );
2230 else
2231 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangeObj( pDocShell, aRange ) ) );
2233 else
2234 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangesObj( pDocShell, aTabRanges ) ) );
2236 uno::Sequence<uno::Any> aParams(1);
2237 aParams[0] <<= xTarget;
2239 uno::Any aRet;
2240 uno::Sequence<sal_Int16> aOutArgsIndex;
2241 uno::Sequence<uno::Any> aOutArgs;
2243 /*ErrCode eRet =*/ pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
2251 void ScModelObj::HandleCalculateEvents()
2253 if (pDocShell)
2255 ScDocument* pDoc = pDocShell->GetDocument();
2256 // don't call events before the document is visible
2257 // (might also set a flag on SFX_EVENT_LOADFINISHED and only disable while loading)
2258 if ( pDoc->IsDocVisible() )
2260 SCTAB nTabCount = pDoc->GetTableCount();
2261 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
2263 if (pDoc->HasCalcNotification(nTab))
2265 if (const ScSheetEvents* pEvents = pDoc->GetSheetEvents( nTab ))
2267 if (const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CALCULATE))
2269 uno::Any aRet;
2270 uno::Sequence<uno::Any> aParams;
2271 uno::Sequence<sal_Int16> aOutArgsIndex;
2272 uno::Sequence<uno::Any> aOutArgs;
2273 pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
2279 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pDoc->GetVbaEventProcessor(), uno::UNO_SET_THROW );
2280 uno::Sequence< uno::Any > aArgs( 1 );
2281 aArgs[ 0 ] <<= nTab;
2282 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_CALCULATE ), aArgs );
2284 catch( uno::Exception& )
2290 pDoc->ResetCalcNotifications();
2294 // XOpenCLSelection
2296 sal_Bool ScModelObj::isOpenCLEnabled()
2297 throw (uno::RuntimeException)
2299 return ScInterpreter::GetGlobalConfig().mbOpenCLEnabled;
2302 void ScModelObj::enableOpenCL(sal_Bool bEnable)
2303 throw (uno::RuntimeException)
2305 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2306 aConfig.mbOpenCLEnabled = bEnable;
2307 ScInterpreter::SetGlobalConfig(aConfig);
2310 void ScModelObj::enableAutomaticDeviceSelection(sal_Bool bForce)
2311 throw (uno::RuntimeException)
2313 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2314 aConfig.mbOpenCLAutoSelect = true;
2315 ScInterpreter::SetGlobalConfig(aConfig);
2316 ScFormulaOptions aOptions = SC_MOD()->GetFormulaOptions();
2317 aOptions.SetCalcConfig(aConfig);
2318 SC_MOD()->SetFormulaOptions(aOptions);
2319 sc::FormulaGroupInterpreter::switchOpenCLDevice(OUString(), true, bForce);
2322 void ScModelObj::disableAutomaticDeviceSelection()
2323 throw (uno::RuntimeException)
2325 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2326 aConfig.mbOpenCLAutoSelect = false;
2327 ScInterpreter::SetGlobalConfig(aConfig);
2328 ScFormulaOptions aOptions = SC_MOD()->GetFormulaOptions();
2329 aOptions.SetCalcConfig(aConfig);
2330 SC_MOD()->SetFormulaOptions(aOptions);
2333 void ScModelObj::selectOpenCLDevice( sal_Int32 nPlatform, sal_Int32 nDevice )
2334 throw (uno::RuntimeException)
2336 if(nPlatform < 0 || nDevice < 0)
2337 throw uno::RuntimeException();
2339 std::vector<sc::OpenclPlatformInfo> aPlatformInfo;
2340 sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
2341 if(size_t(nPlatform) >= aPlatformInfo.size())
2342 throw uno::RuntimeException();
2344 if(size_t(nDevice) >= aPlatformInfo[nPlatform].maDevices.size())
2345 throw uno::RuntimeException();
2347 OUString aDeviceString = aPlatformInfo[nPlatform].maVendor + " " + aPlatformInfo[nPlatform].maDevices[nDevice].maName;
2348 sc::FormulaGroupInterpreter::switchOpenCLDevice(aDeviceString, false);
2351 sal_Int32 ScModelObj::getPlatformID()
2352 throw (uno::RuntimeException)
2354 sal_Int32 nPlatformId;
2355 sal_Int32 nDeviceId;
2356 sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId);
2357 return nPlatformId;
2360 sal_Int32 ScModelObj::getDeviceID()
2361 throw (uno::RuntimeException)
2363 sal_Int32 nPlatformId;
2364 sal_Int32 nDeviceId;
2365 sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId);
2366 return nDeviceId;
2369 uno::Sequence< sheet::opencl::OpenCLPlatform > ScModelObj::getOpenCLPlatforms()
2370 throw (uno::RuntimeException)
2372 std::vector<sc::OpenclPlatformInfo> aPlatformInfo;
2373 sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
2375 uno::Sequence<sheet::opencl::OpenCLPlatform> aRet(aPlatformInfo.size());
2376 for(size_t i = 0; i < aPlatformInfo.size(); ++i)
2378 aRet[i].Name = aPlatformInfo[i].maName;
2379 aRet[i].Vendor = aPlatformInfo[i].maVendor;
2381 aRet[i].Devices.realloc(aPlatformInfo[i].maDevices.size());
2382 for(size_t j = 0; j < aPlatformInfo[i].maDevices.size(); ++j)
2384 const sc::OpenclDeviceInfo& rDevice = aPlatformInfo[i].maDevices[j];
2385 aRet[i].Devices[j].Name = rDevice.maName;
2386 aRet[i].Devices[j].Vendor = rDevice.maVendor;
2387 aRet[i].Devices[j].Driver = rDevice.maDriver;
2391 return aRet;
2395 //------------------------------------------------------------------------
2397 ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
2398 pDocShell( pDocSh )
2400 pDocShell->GetDocument()->AddUnoObject(*this);
2403 ScDrawPagesObj::~ScDrawPagesObj()
2405 if (pDocShell)
2406 pDocShell->GetDocument()->RemoveUnoObject(*this);
2409 void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2411 // Referenz-Update interessiert hier nicht
2413 if ( rHint.ISA( SfxSimpleHint ) &&
2414 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2416 pDocShell = NULL; // ungueltig geworden
2420 uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2422 if (pDocShell)
2424 ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
2425 OSL_ENSURE(pDrawLayer,"kann Draw-Layer nicht anlegen");
2426 if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
2428 SdrPage* pPage = pDrawLayer->GetPage((sal_uInt16)nIndex);
2429 OSL_ENSURE(pPage,"Draw-Page nicht gefunden");
2430 if (pPage)
2432 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
2436 return NULL;
2439 // XDrawPages
2441 uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
2442 throw(uno::RuntimeException)
2444 SolarMutexGuard aGuard;
2445 uno::Reference<drawing::XDrawPage> xRet;
2446 if (pDocShell)
2448 OUString aNewName;
2449 pDocShell->GetDocument()->CreateValidTabName(aNewName);
2450 if ( pDocShell->GetDocFunc().InsertTable( static_cast<SCTAB>(nPos),
2451 aNewName, true, true ) )
2452 xRet.set(GetObjectByIndex_Impl( nPos ));
2454 return xRet;
2457 void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
2458 throw(uno::RuntimeException)
2460 SolarMutexGuard aGuard;
2461 SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
2462 if ( pDocShell && pImp )
2464 SdrPage* pPage = pImp->GetSdrPage();
2465 if (pPage)
2467 SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
2468 pDocShell->GetDocFunc().DeleteTable( nPageNum, sal_True, sal_True );
2473 // XIndexAccess
2475 sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException)
2477 SolarMutexGuard aGuard;
2478 if (pDocShell)
2479 return pDocShell->GetDocument()->GetTableCount();
2480 return 0;
2483 uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
2484 throw(lang::IndexOutOfBoundsException,
2485 lang::WrappedTargetException, uno::RuntimeException)
2487 SolarMutexGuard aGuard;
2488 uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
2489 if (xPage.is())
2490 return uno::makeAny(xPage);
2491 else
2492 throw lang::IndexOutOfBoundsException();
2495 uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException)
2497 SolarMutexGuard aGuard;
2498 return getCppuType((uno::Reference<drawing::XDrawPage>*)0);
2501 sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException)
2503 SolarMutexGuard aGuard;
2504 return ( getCount() != 0 );
2507 //------------------------------------------------------------------------
2509 ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
2510 pDocShell( pDocSh )
2512 pDocShell->GetDocument()->AddUnoObject(*this);
2515 ScTableSheetsObj::~ScTableSheetsObj()
2517 if (pDocShell)
2518 pDocShell->GetDocument()->RemoveUnoObject(*this);
2521 void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2523 // Referenz-Update interessiert hier nicht
2525 if ( rHint.ISA( SfxSimpleHint ) &&
2526 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2528 pDocShell = NULL; // ungueltig geworden
2532 // XSpreadsheets
2534 ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2536 if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
2537 return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
2539 return NULL;
2542 ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const OUString& aName) const
2544 if (pDocShell)
2546 SCTAB nIndex;
2547 if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
2548 return new ScTableSheetObj( pDocShell, nIndex );
2550 return NULL;
2553 void SAL_CALL ScTableSheetsObj::insertNewByName( const OUString& aName, sal_Int16 nPosition )
2554 throw(uno::RuntimeException)
2556 SolarMutexGuard aGuard;
2557 sal_Bool bDone = false;
2558 if (pDocShell)
2560 OUString aNamStr(aName);
2561 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, sal_True, sal_True );
2563 if (!bDone)
2564 throw uno::RuntimeException(); // no other exceptions specified
2567 void SAL_CALL ScTableSheetsObj::moveByName( const OUString& aName, sal_Int16 nDestination )
2568 throw(uno::RuntimeException)
2570 SolarMutexGuard aGuard;
2571 sal_Bool bDone = false;
2572 if (pDocShell)
2574 SCTAB nSource;
2575 if ( pDocShell->GetDocument()->GetTable( aName, nSource ) )
2576 bDone = pDocShell->MoveTable( nSource, nDestination, false, sal_True );
2578 if (!bDone)
2579 throw uno::RuntimeException(); // no other exceptions specified
2582 void SAL_CALL ScTableSheetsObj::copyByName( const OUString& aName,
2583 const OUString& aCopy, sal_Int16 nDestination )
2584 throw(uno::RuntimeException)
2586 SolarMutexGuard aGuard;
2587 sal_Bool bDone = false;
2588 if (pDocShell)
2590 OUString aNewStr(aCopy);
2591 SCTAB nSource;
2592 if ( pDocShell->GetDocument()->GetTable( aName, nSource ) )
2594 bDone = pDocShell->MoveTable( nSource, nDestination, sal_True, sal_True );
2595 if (bDone)
2597 // #i92477# any index past the last sheet means "append" in MoveTable
2598 SCTAB nResultTab = static_cast<SCTAB>(nDestination);
2599 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount(); // count after copying
2600 if (nResultTab >= nTabCount)
2601 nResultTab = nTabCount - 1;
2603 bDone = pDocShell->GetDocFunc().RenameTable( nResultTab, aNewStr,
2604 sal_True, sal_True );
2608 if (!bDone)
2609 throw uno::RuntimeException(); // no other exceptions specified
2612 void SAL_CALL ScTableSheetsObj::insertByName( const OUString& aName, const uno::Any& aElement )
2613 throw(lang::IllegalArgumentException, container::ElementExistException,
2614 lang::WrappedTargetException, uno::RuntimeException)
2616 SolarMutexGuard aGuard;
2617 sal_Bool bDone = false;
2618 sal_Bool bIllArg = false;
2620 //! Type of aElement can be some specific interface instead of XInterface
2622 if ( pDocShell )
2624 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2625 if ( xInterface.is() )
2627 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2628 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2630 ScDocument* pDoc = pDocShell->GetDocument();
2631 OUString aNamStr(aName);
2632 SCTAB nDummy;
2633 if ( pDoc->GetTable( aNamStr, nDummy ) )
2635 // name already exists
2636 throw container::ElementExistException();
2638 else
2640 SCTAB nPosition = pDoc->GetTableCount();
2641 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr,
2642 sal_True, sal_True );
2643 if (bDone)
2644 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2645 // Dokument und neuen Range am Objekt setzen
2648 else
2649 bIllArg = sal_True;
2651 else
2652 bIllArg = sal_True;
2655 if (!bDone)
2657 if (bIllArg)
2658 throw lang::IllegalArgumentException();
2659 else
2660 throw uno::RuntimeException(); // ElementExistException is handled above
2664 void SAL_CALL ScTableSheetsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
2665 throw(lang::IllegalArgumentException, container::NoSuchElementException,
2666 lang::WrappedTargetException, uno::RuntimeException)
2668 SolarMutexGuard aGuard;
2669 sal_Bool bDone = false;
2670 sal_Bool bIllArg = false;
2672 //! Type of aElement can be some specific interface instead of XInterface
2674 if ( pDocShell )
2676 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2677 if ( xInterface.is() )
2679 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2680 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2682 SCTAB nPosition;
2683 if ( pDocShell->GetDocument()->GetTable( aName, nPosition ) )
2685 if ( pDocShell->GetDocFunc().DeleteTable( nPosition, sal_True, sal_True ) )
2687 // InsertTable kann jetzt eigentlich nicht schiefgehen...
2688 OUString aNamStr(aName);
2689 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, sal_True, sal_True );
2690 if (bDone)
2691 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2694 else
2696 // not found
2697 throw container::NoSuchElementException();
2700 else
2701 bIllArg = sal_True;
2703 else
2704 bIllArg = sal_True;
2707 if (!bDone)
2709 if (bIllArg)
2710 throw lang::IllegalArgumentException();
2711 else
2712 throw uno::RuntimeException(); // NoSuchElementException is handled above
2716 void SAL_CALL ScTableSheetsObj::removeByName( const OUString& aName )
2717 throw(container::NoSuchElementException,
2718 lang::WrappedTargetException, uno::RuntimeException)
2720 SolarMutexGuard aGuard;
2721 sal_Bool bDone = false;
2722 if (pDocShell)
2724 SCTAB nIndex;
2725 if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
2726 bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, sal_True, sal_True );
2727 else // not found
2728 throw container::NoSuchElementException();
2731 if (!bDone)
2732 throw uno::RuntimeException(); // NoSuchElementException is handled above
2735 sal_Int32 ScTableSheetsObj::importSheet(
2736 const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc,
2737 const OUString& srcName, const sal_Int32 nDestPosition )
2738 throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException )
2740 //pDocShell is the destination
2741 ScDocument* pDocDest = pDocShell->GetDocument();
2743 // Source document docShell
2744 if ( !xDocSrc.is() )
2745 throw uno::RuntimeException();
2746 ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc);
2747 ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject());
2749 // SourceSheet Position and does srcName exists ?
2750 SCTAB nIndexSrc;
2751 if ( !pDocShellSrc->GetDocument()->GetTable( srcName, nIndexSrc ) )
2752 throw lang::IllegalArgumentException();
2754 // Check the validity of destination index.
2755 SCTAB nCount = pDocDest->GetTableCount();
2756 SCTAB nIndexDest = static_cast<SCTAB>(nDestPosition);
2757 if (nIndexDest > nCount || nIndexDest < 0)
2758 throw lang::IndexOutOfBoundsException();
2760 // Transfert Tab
2761 bool bInsertNew = true;
2762 bool bNotifyAndPaint = true;
2763 pDocShell->TransferTab(
2764 *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint );
2766 return nIndexDest;
2769 // XCellRangesAccess
2771 uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet )
2772 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2774 SolarMutexGuard aGuard;
2775 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
2776 if (! xSheet.is())
2777 throw lang::IndexOutOfBoundsException();
2779 return xSheet->getCellByPosition(nColumn, nRow);
2782 uno::Reference< table::XCellRange > SAL_CALL ScTableSheetsObj::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom, sal_Int32 nSheet )
2783 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2785 SolarMutexGuard aGuard;
2786 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
2787 if (! xSheet.is())
2788 throw lang::IndexOutOfBoundsException();
2790 return xSheet->getCellRangeByPosition(nLeft, nTop, nRight, nBottom);
2793 uno::Sequence < uno::Reference< table::XCellRange > > SAL_CALL ScTableSheetsObj::getCellRangesByName( const OUString& aRange )
2794 throw (lang::IllegalArgumentException, uno::RuntimeException)
2796 SolarMutexGuard aGuard;
2797 uno::Sequence < uno::Reference < table::XCellRange > > xRet;
2799 ScRangeList aRangeList;
2800 ScDocument* pDoc = pDocShell->GetDocument();
2801 if (ScRangeStringConverter::GetRangeListFromString( aRangeList, aRange, pDoc, ::formula::FormulaGrammar::CONV_OOO, ';' ))
2803 size_t nCount = aRangeList.size();
2804 if (nCount)
2806 xRet.realloc(nCount);
2807 for( size_t nIndex = 0; nIndex < nCount; nIndex++ )
2809 const ScRange* pRange = aRangeList[ nIndex ];
2810 if( pRange )
2811 xRet[nIndex] = new ScCellRangeObj(pDocShell, *pRange);
2814 else
2815 throw lang::IllegalArgumentException();
2817 else
2818 throw lang::IllegalArgumentException();
2819 return xRet;
2822 // XEnumerationAccess
2824 uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
2825 throw(uno::RuntimeException)
2827 SolarMutexGuard aGuard;
2828 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetsEnumeration"));
2831 // XIndexAccess
2833 sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException)
2835 SolarMutexGuard aGuard;
2836 if (pDocShell)
2837 return pDocShell->GetDocument()->GetTableCount();
2838 return 0;
2841 uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
2842 throw(lang::IndexOutOfBoundsException,
2843 lang::WrappedTargetException, uno::RuntimeException)
2845 SolarMutexGuard aGuard;
2846 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
2847 if (xSheet.is())
2848 return uno::makeAny(xSheet);
2849 else
2850 throw lang::IndexOutOfBoundsException();
2851 // return uno::Any();
2854 uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException)
2856 SolarMutexGuard aGuard;
2857 return getCppuType((uno::Reference<sheet::XSpreadsheet>*)0);
2860 sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException)
2862 SolarMutexGuard aGuard;
2863 return ( getCount() != 0 );
2866 // XNameAccess
2868 uno::Any SAL_CALL ScTableSheetsObj::getByName( const OUString& aName )
2869 throw(container::NoSuchElementException,
2870 lang::WrappedTargetException, uno::RuntimeException)
2872 SolarMutexGuard aGuard;
2873 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
2874 if (xSheet.is())
2875 return uno::makeAny(xSheet);
2876 else
2877 throw container::NoSuchElementException();
2880 uno::Sequence<OUString> SAL_CALL ScTableSheetsObj::getElementNames()
2881 throw(uno::RuntimeException)
2883 SolarMutexGuard aGuard;
2884 if (pDocShell)
2886 ScDocument* pDoc = pDocShell->GetDocument();
2887 SCTAB nCount = pDoc->GetTableCount();
2888 OUString aName;
2889 uno::Sequence<OUString> aSeq(nCount);
2890 OUString* pAry = aSeq.getArray();
2891 for (SCTAB i=0; i<nCount; i++)
2893 pDoc->GetName( i, aName );
2894 pAry[i] = aName;
2896 return aSeq;
2898 return uno::Sequence<OUString>();
2901 sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const OUString& aName )
2902 throw(uno::RuntimeException)
2904 SolarMutexGuard aGuard;
2905 if (pDocShell)
2907 SCTAB nIndex;
2908 if ( pDocShell->GetDocument()->GetTable( aName, nIndex ) )
2909 return sal_True;
2911 return false;
2914 //------------------------------------------------------------------------
2916 ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
2917 pDocShell( pDocSh ),
2918 nTab ( nT ),
2919 nStartCol( nSC ),
2920 nEndCol ( nEC )
2922 pDocShell->GetDocument()->AddUnoObject(*this);
2925 ScTableColumnsObj::~ScTableColumnsObj()
2927 if (pDocShell)
2928 pDocShell->GetDocument()->RemoveUnoObject(*this);
2931 void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2933 if ( rHint.ISA( ScUpdateRefHint ) )
2935 //! Referenz-Update fuer Tab und Start/Ende
2937 else if ( rHint.ISA( SfxSimpleHint ) &&
2938 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2940 pDocShell = NULL; // ungueltig geworden
2944 // XTableColumns
2946 ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2948 SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
2949 if ( pDocShell && nCol <= nEndCol )
2950 return new ScTableColumnObj( pDocShell, nCol, nTab );
2952 return NULL; // falscher Index
2955 ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const OUString& aName) const
2957 SCCOL nCol = 0;
2958 OUString aString(aName);
2959 if ( ::AlphaToCol( nCol, aString) )
2960 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
2961 return new ScTableColumnObj( pDocShell, nCol, nTab );
2963 return NULL;
2966 void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
2967 throw(uno::RuntimeException)
2969 SolarMutexGuard aGuard;
2970 sal_Bool bDone = false;
2971 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
2972 nStartCol+nPosition+nCount-1 <= MAXCOL )
2974 ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
2975 (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
2976 bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSCOLS, sal_True, sal_True );
2978 if (!bDone)
2979 throw uno::RuntimeException(); // no other exceptions specified
2982 void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
2983 throw(uno::RuntimeException)
2985 SolarMutexGuard aGuard;
2986 sal_Bool bDone = false;
2987 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
2988 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
2990 ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
2991 (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
2992 bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELCOLS, sal_True, sal_True );
2994 if (!bDone)
2995 throw uno::RuntimeException(); // no other exceptions specified
2998 // XEnumerationAccess
3000 uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
3001 throw(uno::RuntimeException)
3003 SolarMutexGuard aGuard;
3004 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableColumnsEnumeration"));
3007 // XIndexAccess
3009 sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException)
3011 SolarMutexGuard aGuard;
3012 return nEndCol - nStartCol + 1;
3015 uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
3016 throw(lang::IndexOutOfBoundsException,
3017 lang::WrappedTargetException, uno::RuntimeException)
3019 SolarMutexGuard aGuard;
3020 uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
3021 if (xColumn.is())
3022 return uno::makeAny(xColumn);
3023 else
3024 throw lang::IndexOutOfBoundsException();
3027 uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException)
3029 SolarMutexGuard aGuard;
3030 return getCppuType((uno::Reference<table::XCellRange>*)0);
3033 sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException)
3035 SolarMutexGuard aGuard;
3036 return ( getCount() != 0 );
3039 uno::Any SAL_CALL ScTableColumnsObj::getByName( const OUString& aName )
3040 throw(container::NoSuchElementException,
3041 lang::WrappedTargetException, uno::RuntimeException)
3043 SolarMutexGuard aGuard;
3044 uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
3045 if (xColumn.is())
3046 return uno::makeAny(xColumn);
3047 else
3048 throw container::NoSuchElementException();
3051 uno::Sequence<OUString> SAL_CALL ScTableColumnsObj::getElementNames()
3052 throw(uno::RuntimeException)
3054 SolarMutexGuard aGuard;
3055 SCCOL nCount = nEndCol - nStartCol + 1;
3056 uno::Sequence<OUString> aSeq(nCount);
3057 OUString* pAry = aSeq.getArray();
3058 for (SCCOL i=0; i<nCount; i++)
3059 pAry[i] = ::ScColToAlpha( nStartCol + i );
3061 return aSeq;
3064 sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const OUString& aName )
3065 throw(uno::RuntimeException)
3067 SolarMutexGuard aGuard;
3068 SCCOL nCol = 0;
3069 OUString aString(aName);
3070 if ( ::AlphaToCol( nCol, aString) )
3071 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
3072 return sal_True;
3074 return false; // nicht gefunden
3077 // XPropertySet
3079 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
3080 throw(uno::RuntimeException)
3082 SolarMutexGuard aGuard;
3083 static uno::Reference<beans::XPropertySetInfo> aRef(
3084 new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
3085 return aRef;
3088 void SAL_CALL ScTableColumnsObj::setPropertyValue(
3089 const OUString& aPropertyName, const uno::Any& aValue )
3090 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3091 lang::IllegalArgumentException, lang::WrappedTargetException,
3092 uno::RuntimeException)
3094 SolarMutexGuard aGuard;
3095 if (!pDocShell)
3096 throw uno::RuntimeException();
3098 SCCOLROW nColArr[2];
3099 nColArr[0] = nStartCol;
3100 nColArr[1] = nEndCol;
3101 OUString aNameString(aPropertyName);
3102 ScDocFunc& rFunc = pDocShell->GetDocFunc();
3104 if ( aNameString.equalsAscii( SC_UNONAME_CELLWID ) )
3106 sal_Int32 nNewWidth = 0;
3107 if ( aValue >>= nNewWidth )
3108 rFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab, SC_SIZE_ORIGINAL,
3109 (sal_uInt16)HMMToTwips(nNewWidth), sal_True, sal_True );
3111 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3113 sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3114 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
3115 rFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab, eMode, 0, sal_True, sal_True );
3116 // SC_SIZE_DIRECT with size 0: hide
3118 else if ( aNameString.equalsAscii( SC_UNONAME_OWIDTH ) )
3120 sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3121 if (bOpt)
3122 rFunc.SetWidthOrHeight( sal_True, 1, nColArr, nTab,
3123 SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, sal_True, sal_True );
3124 // sal_False for columns currently has no effect
3126 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) || aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
3128 //! single function to set/remove all breaks?
3129 sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3130 for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
3131 if (bSet)
3132 rFunc.InsertPageBreak( sal_True, ScAddress(nCol,0,nTab), sal_True, sal_True, sal_True );
3133 else
3134 rFunc.RemovePageBreak( sal_True, ScAddress(nCol,0,nTab), sal_True, sal_True, sal_True );
3138 uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const OUString& aPropertyName )
3139 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3140 uno::RuntimeException)
3142 SolarMutexGuard aGuard;
3143 if (!pDocShell)
3144 throw uno::RuntimeException();
3146 ScDocument* pDoc = pDocShell->GetDocument();
3147 OUString aNameString(aPropertyName);
3148 uno::Any aAny;
3150 //! loop over all columns for current state?
3152 if ( aNameString.equalsAscii( SC_UNONAME_CELLWID ) )
3154 // for hidden column, return original height
3155 sal_uInt16 nWidth = pDoc->GetOriginalWidth( nStartCol, nTab );
3156 aAny <<= (sal_Int32)TwipsToHMM(nWidth);
3158 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3160 bool bVis = !pDoc->ColHidden(nStartCol, nTab);
3161 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3163 else if ( aNameString.equalsAscii( SC_UNONAME_OWIDTH ) )
3165 sal_Bool bOpt = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE);
3166 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
3168 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) )
3170 ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
3171 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
3173 else if ( aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
3175 ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
3176 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) );
3179 return aAny;
3182 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
3184 //------------------------------------------------------------------------
3186 ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
3187 pDocShell( pDocSh ),
3188 nTab ( nT ),
3189 nStartRow( nSR ),
3190 nEndRow ( nER )
3192 pDocShell->GetDocument()->AddUnoObject(*this);
3195 ScTableRowsObj::~ScTableRowsObj()
3197 if (pDocShell)
3198 pDocShell->GetDocument()->RemoveUnoObject(*this);
3201 void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3203 if ( rHint.ISA( ScUpdateRefHint ) )
3205 //! Referenz-Update fuer Tab und Start/Ende
3207 else if ( rHint.ISA( SfxSimpleHint ) &&
3208 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3210 pDocShell = NULL; // ungueltig geworden
3214 // XTableRows
3216 ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
3218 SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
3219 if ( pDocShell && nRow <= nEndRow )
3220 return new ScTableRowObj( pDocShell, nRow, nTab );
3222 return NULL; // falscher Index
3225 void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
3226 throw(uno::RuntimeException)
3228 SolarMutexGuard aGuard;
3229 sal_Bool bDone = false;
3230 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
3231 nStartRow+nPosition+nCount-1 <= MAXROW )
3233 ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
3234 MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
3235 bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSROWS, sal_True, sal_True );
3237 if (!bDone)
3238 throw uno::RuntimeException(); // no other exceptions specified
3241 void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
3242 throw(uno::RuntimeException)
3244 SolarMutexGuard aGuard;
3245 sal_Bool bDone = false;
3246 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
3247 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
3249 ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
3250 MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
3251 bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELROWS, sal_True, sal_True );
3253 if (!bDone)
3254 throw uno::RuntimeException(); // no other exceptions specified
3257 // XEnumerationAccess
3259 uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
3260 throw(uno::RuntimeException)
3262 SolarMutexGuard aGuard;
3263 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableRowsEnumeration"));
3266 // XIndexAccess
3268 sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException)
3270 SolarMutexGuard aGuard;
3271 return nEndRow - nStartRow + 1;
3274 uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
3275 throw(lang::IndexOutOfBoundsException,
3276 lang::WrappedTargetException, uno::RuntimeException)
3278 SolarMutexGuard aGuard;
3279 uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
3280 if (xRow.is())
3281 return uno::makeAny(xRow);
3282 else
3283 throw lang::IndexOutOfBoundsException();
3286 uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException)
3288 SolarMutexGuard aGuard;
3289 return getCppuType((uno::Reference<table::XCellRange>*)0);
3292 sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException)
3294 SolarMutexGuard aGuard;
3295 return ( getCount() != 0 );
3298 // XPropertySet
3300 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
3301 throw(uno::RuntimeException)
3303 SolarMutexGuard aGuard;
3304 static uno::Reference<beans::XPropertySetInfo> aRef(
3305 new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
3306 return aRef;
3309 void SAL_CALL ScTableRowsObj::setPropertyValue(
3310 const OUString& aPropertyName, const uno::Any& aValue )
3311 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3312 lang::IllegalArgumentException, lang::WrappedTargetException,
3313 uno::RuntimeException)
3315 SolarMutexGuard aGuard;
3316 if (!pDocShell)
3317 throw uno::RuntimeException();
3319 ScDocFunc& rFunc = pDocShell->GetDocFunc();
3320 ScDocument* pDoc = pDocShell->GetDocument();
3321 SCCOLROW nRowArr[2];
3322 nRowArr[0] = nStartRow;
3323 nRowArr[1] = nEndRow;
3324 OUString aNameString(aPropertyName);
3326 if ( aNameString.equalsAscii( SC_UNONAME_OHEIGHT ) )
3328 sal_Int32 nNewHeight = 0;
3329 if ( pDoc->IsImportingXML() && ( aValue >>= nNewHeight ) )
3331 // used to set the stored row height for rows with optimal height when loading.
3333 // TODO: It's probably cleaner to use a different property name
3334 // for this.
3335 pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
3337 else
3339 sal_Bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3340 if (bOpt)
3341 rFunc.SetWidthOrHeight( false, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, sal_True, sal_True );
3342 else
3344 //! manually set old heights again?
3348 else if ( aNameString.equalsAscii( SC_UNONAME_CELLHGT ) )
3350 sal_Int32 nNewHeight = 0;
3351 if ( aValue >>= nNewHeight )
3353 if (pDoc->IsImportingXML())
3355 // TODO: This is a band-aid fix. Eventually we need to
3356 // re-work ods' style import to get it to set styles to
3357 // ScDocument directly.
3358 pDoc->SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
3359 pDoc->SetManualHeight( nStartRow, nEndRow, nTab, true );
3361 else
3362 rFunc.SetWidthOrHeight( false, 1, nRowArr, nTab, SC_SIZE_ORIGINAL,
3363 (sal_uInt16)HMMToTwips(nNewHeight), sal_True, sal_True );
3366 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3368 sal_Bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3369 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
3370 rFunc.SetWidthOrHeight( false, 1, nRowArr, nTab, eMode, 0, sal_True, sal_True );
3371 // SC_SIZE_DIRECT with size 0: hide
3373 else if ( aNameString.equalsAscii( SC_UNONAME_VISFLAG ) )
3375 // #i116460# Shortcut to only set the flag, without drawing layer update etc.
3376 // Should only be used from import filters.
3377 pDoc->SetRowHidden(nStartRow, nEndRow, nTab, !ScUnoHelpFunctions::GetBoolFromAny( aValue ));
3379 else if ( aNameString.equalsAscii( SC_UNONAME_CELLFILT ) )
3381 //! undo etc.
3382 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
3383 pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, true);
3384 else
3385 pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, false);
3387 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE) || aNameString.equalsAscii( SC_UNONAME_MANPAGE) )
3389 //! single function to set/remove all breaks?
3390 sal_Bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3391 for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
3392 if (bSet)
3393 rFunc.InsertPageBreak( false, ScAddress(0,nRow,nTab), sal_True, sal_True, sal_True );
3394 else
3395 rFunc.RemovePageBreak( false, ScAddress(0,nRow,nTab), sal_True, sal_True, sal_True );
3397 else if ( aNameString.equalsAscii( SC_UNONAME_CELLBACK ) || aNameString.equalsAscii( SC_UNONAME_CELLTRAN ) )
3399 // #i57867# Background color is specified for row styles in the file format,
3400 // so it has to be supported along with the row properties (import only).
3402 // Use ScCellRangeObj to set the property for all cells in the rows
3403 // (this means, the "row attribute" must be set before individual cell attributes).
3405 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3406 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3407 xRangeObj->setPropertyValue( aPropertyName, aValue );
3411 uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const OUString& aPropertyName )
3412 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3413 uno::RuntimeException)
3415 SolarMutexGuard aGuard;
3416 if (!pDocShell)
3417 throw uno::RuntimeException();
3419 ScDocument* pDoc = pDocShell->GetDocument();
3420 OUString aNameString(aPropertyName);
3421 uno::Any aAny;
3423 //! loop over all rows for current state?
3425 if ( aNameString.equalsAscii( SC_UNONAME_CELLHGT ) )
3427 // for hidden row, return original height
3428 sal_uInt16 nHeight = pDoc->GetOriginalHeight( nStartRow, nTab );
3429 aAny <<= (sal_Int32)TwipsToHMM(nHeight);
3431 else if ( aNameString.equalsAscii( SC_UNONAME_CELLVIS ) )
3433 SCROW nLastRow;
3434 bool bVis = !pDoc->RowHidden(nStartRow, nTab, NULL, &nLastRow);
3435 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3437 else if ( aNameString.equalsAscii( SC_UNONAME_CELLFILT ) )
3439 bool bVis = pDoc->RowFiltered(nStartRow, nTab);
3440 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3442 else if ( aNameString.equalsAscii( SC_UNONAME_OHEIGHT ) )
3444 sal_Bool bOpt = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE);
3445 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
3447 else if ( aNameString.equalsAscii( SC_UNONAME_NEWPAGE ) )
3449 ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
3450 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
3452 else if ( aNameString.equalsAscii( SC_UNONAME_MANPAGE ) )
3454 ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
3455 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) );
3457 else if ( aNameString.equalsAscii( SC_UNONAME_CELLBACK ) || aNameString.equalsAscii( SC_UNONAME_CELLTRAN ) )
3459 // Use ScCellRangeObj to get the property from the cell range
3460 // (for completeness only, this is not used by the XML filter).
3462 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3463 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3464 aAny = xRangeObj->getPropertyValue( aPropertyName );
3467 return aAny;
3470 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj )
3472 //------------------------------------------------------------------------
3474 ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj()
3476 if (pDocShell)
3477 pDocShell->GetDocument()->RemoveUnoObject(*this);
3480 void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3482 // Referenz-Update interessiert hier nicht
3484 if ( rHint.ISA( SfxSimpleHint ) &&
3485 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3487 pDocShell = NULL; // ungueltig geworden
3491 // XPropertySet
3493 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo()
3494 throw(uno::RuntimeException)
3496 //! muss noch
3497 return NULL;
3500 void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue(
3501 const OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
3502 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3503 lang::IllegalArgumentException, lang::WrappedTargetException,
3504 uno::RuntimeException)
3506 //! muss noch
3509 uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const OUString& /* aPropertyName */ )
3510 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3511 uno::RuntimeException)
3513 //! muss noch
3514 return uno::Any();
3517 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj )
3519 //------------------------------------------------------------------------
3521 ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
3522 pDocShell( pDocSh ),
3523 nTab( nT )
3525 pDocShell->GetDocument()->AddUnoObject(*this);
3528 ScAnnotationsObj::~ScAnnotationsObj()
3530 if (pDocShell)
3531 pDocShell->GetDocument()->RemoveUnoObject(*this);
3534 void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3536 //! nTab bei Referenz-Update anpassen!!!
3538 if ( rHint.ISA( SfxSimpleHint ) &&
3539 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3541 pDocShell = NULL; // ungueltig geworden
3545 bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
3547 if (!pDocShell)
3548 return false;
3550 ScDocument* pDoc = pDocShell->GetDocument();
3551 rPos = pDoc->GetNotePosition(nIndex);
3552 return rPos.IsValid();
3555 ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
3557 if (pDocShell)
3559 ScAddress aPos;
3560 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3561 return new ScAnnotationObj( pDocShell, aPos );
3563 return NULL;
3566 // XSheetAnnotations
3568 void SAL_CALL ScAnnotationsObj::insertNew(
3569 const table::CellAddress& aPosition, const OUString& rText )
3570 throw(uno::RuntimeException)
3572 SolarMutexGuard aGuard;
3573 if (pDocShell)
3575 OSL_ENSURE( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
3576 ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
3577 pDocShell->GetDocFunc().ReplaceNote( aPos, rText, 0, 0, sal_True );
3581 void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException)
3583 SolarMutexGuard aGuard;
3584 if (pDocShell)
3586 ScAddress aPos;
3587 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3589 ScMarkData aMarkData;
3590 aMarkData.SelectTable( aPos.Tab(), sal_True );
3591 aMarkData.SetMultiMarkArea( ScRange(aPos) );
3593 pDocShell->GetDocFunc().DeleteContents( aMarkData, IDF_NOTE, sal_True, sal_True );
3598 // XEnumerationAccess
3600 uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
3601 throw(uno::RuntimeException)
3603 //! iterate directly (more efficiently)?
3605 SolarMutexGuard aGuard;
3606 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.CellAnnotationsEnumeration"));
3609 // XIndexAccess
3611 sal_Int32 SAL_CALL ScAnnotationsObj::getCount() throw(uno::RuntimeException)
3613 SolarMutexGuard aGuard;
3614 sal_Int32 nCount = 0;
3615 if (pDocShell)
3617 ScDocument* pDoc = pDocShell->GetDocument();
3618 const ScRangeList aRangeList( ScRange( 0, 0, nTab, MAXCOL, MAXROW, nTab) );
3619 std::vector<sc::NoteEntry> rNotes;
3620 pDoc->GetNotesInRange(aRangeList, rNotes);
3621 nCount = rNotes.size();
3623 return nCount;
3626 uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
3627 throw(lang::IndexOutOfBoundsException,
3628 lang::WrappedTargetException, uno::RuntimeException)
3630 SolarMutexGuard aGuard;
3631 uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
3632 if (xAnnotation.is())
3633 return uno::makeAny(xAnnotation);
3634 else
3635 throw lang::IndexOutOfBoundsException();
3638 uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException)
3640 SolarMutexGuard aGuard;
3641 return getCppuType((uno::Reference<sheet::XSheetAnnotation>*)0);
3644 sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException)
3646 SolarMutexGuard aGuard;
3647 return ( getCount() != 0 );
3650 //------------------------------------------------------------------------
3652 ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
3653 pDocShell( pDocSh ),
3654 nTab ( nT )
3656 pDocShell->GetDocument()->AddUnoObject(*this);
3659 ScScenariosObj::~ScScenariosObj()
3661 if (pDocShell)
3662 pDocShell->GetDocument()->RemoveUnoObject(*this);
3665 void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3667 if ( rHint.ISA( ScUpdateRefHint ) )
3669 //! Referenz-Update fuer Tab und Start/Ende
3671 else if ( rHint.ISA( SfxSimpleHint ) &&
3672 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3674 pDocShell = NULL; // ungueltig geworden
3678 // XScenarios
3680 sal_Bool ScScenariosObj::GetScenarioIndex_Impl( const OUString& rName, SCTAB& rIndex )
3682 //! Case-insensitiv ????
3684 if ( pDocShell )
3686 OUString aTabName;
3687 ScDocument* pDoc = pDocShell->GetDocument();
3688 SCTAB nCount = (SCTAB)getCount();
3689 for (SCTAB i=0; i<nCount; i++)
3690 if (pDoc->GetName( nTab+i+1, aTabName ))
3691 if (aTabName.equals(rName))
3693 rIndex = i;
3694 return sal_True;
3698 return false;
3701 ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
3703 sal_uInt16 nCount = (sal_uInt16)getCount();
3704 if ( pDocShell && nIndex >= 0 && nIndex < nCount )
3705 return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
3707 return NULL; // kein Dokument oder falscher Index
3710 ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const OUString& aName)
3712 SCTAB nIndex;
3713 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3714 return new ScTableSheetObj( pDocShell, nTab+nIndex+1 );
3716 return NULL; // nicht gefunden
3719 void SAL_CALL ScScenariosObj::addNewByName( const OUString& aName,
3720 const uno::Sequence<table::CellRangeAddress>& aRanges,
3721 const OUString& aComment )
3722 throw(uno::RuntimeException)
3724 SolarMutexGuard aGuard;
3725 if ( pDocShell )
3727 ScMarkData aMarkData;
3728 aMarkData.SelectTable( nTab, sal_True );
3730 sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
3731 if (nRangeCount)
3733 const table::CellRangeAddress* pAry = aRanges.getConstArray();
3734 for (sal_uInt16 i=0; i<nRangeCount; i++)
3736 OSL_ENSURE( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
3737 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
3738 (SCCOL)pAry[i].EndColumn, (SCROW)pAry[i].EndRow, nTab );
3740 aMarkData.SetMultiMarkArea( aRange );
3744 OUString aNameStr(aName);
3745 OUString aCommStr(aComment);
3747 Color aColor( COL_LIGHTGRAY ); // Default
3748 sal_uInt16 nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
3750 pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
3754 void SAL_CALL ScScenariosObj::removeByName( const OUString& aName )
3755 throw(uno::RuntimeException)
3757 SolarMutexGuard aGuard;
3758 SCTAB nIndex;
3759 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3760 pDocShell->GetDocFunc().DeleteTable( nTab+nIndex+1, sal_True, sal_True );
3763 // XEnumerationAccess
3765 uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
3766 throw(uno::RuntimeException)
3768 SolarMutexGuard aGuard;
3769 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.ScenariosEnumeration"));
3772 // XIndexAccess
3774 sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException)
3776 SolarMutexGuard aGuard;
3777 SCTAB nCount = 0;
3778 if ( pDocShell )
3780 ScDocument* pDoc = pDocShell->GetDocument();
3781 if (!pDoc->IsScenario(nTab))
3783 SCTAB nTabCount = pDoc->GetTableCount();
3784 SCTAB nNext = nTab + 1;
3785 while (nNext < nTabCount && pDoc->IsScenario(nNext))
3787 ++nCount;
3788 ++nNext;
3792 return nCount;
3795 uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
3796 throw(lang::IndexOutOfBoundsException,
3797 lang::WrappedTargetException, uno::RuntimeException)
3799 SolarMutexGuard aGuard;
3800 uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
3801 if (xScen.is())
3802 return uno::makeAny(xScen);
3803 else
3804 throw lang::IndexOutOfBoundsException();
3807 uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException)
3809 SolarMutexGuard aGuard;
3810 return getCppuType((uno::Reference<sheet::XScenario>*)0);
3813 sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException)
3815 SolarMutexGuard aGuard;
3816 return ( getCount() != 0 );
3819 uno::Any SAL_CALL ScScenariosObj::getByName( const OUString& aName )
3820 throw(container::NoSuchElementException,
3821 lang::WrappedTargetException, uno::RuntimeException)
3823 SolarMutexGuard aGuard;
3824 uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
3825 if (xScen.is())
3826 return uno::makeAny(xScen);
3827 else
3828 throw container::NoSuchElementException();
3831 uno::Sequence<OUString> SAL_CALL ScScenariosObj::getElementNames()
3832 throw(uno::RuntimeException)
3834 SolarMutexGuard aGuard;
3835 SCTAB nCount = (SCTAB)getCount();
3836 uno::Sequence<OUString> aSeq(nCount);
3838 if ( pDocShell ) // sonst ist auch Count = 0
3840 OUString aTabName;
3841 ScDocument* pDoc = pDocShell->GetDocument();
3842 OUString* pAry = aSeq.getArray();
3843 for (SCTAB i=0; i<nCount; i++)
3844 if (pDoc->GetName( nTab+i+1, aTabName ))
3845 pAry[i] = aTabName;
3848 return aSeq;
3851 sal_Bool SAL_CALL ScScenariosObj::hasByName( const OUString& aName )
3852 throw(uno::RuntimeException)
3854 SolarMutexGuard aGuard;
3855 SCTAB nIndex;
3856 return GetScenarioIndex_Impl( aName, nIndex );
3863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */