fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / docuno.cxx
blobe1235b90cb7a4c35acc09ef9019a0a064c48b5d6
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 <config_features.h>
22 #include "scitems.hxx"
23 #include <editeng/editview.hxx>
24 #include <editeng/outliner.hxx>
25 #include <svx/fmdpage.hxx>
26 #include <svx/fmview.hxx>
27 #include <svx/svditer.hxx>
28 #include <svx/svdpage.hxx>
29 #include <svx/svxids.hrc>
30 #include <svx/unoshape.hxx>
32 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
33 #include <officecfg/Office/Common.hxx>
34 #include <officecfg/Office/Calc.hxx>
35 #include <svl/numuno.hxx>
36 #include <svl/smplhint.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <sfx2/printer.hxx>
39 #include <sfx2/bindings.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <vcl/pdfextoutdevdata.hxx>
42 #include <vcl/waitobj.hxx>
43 #include <unotools/charclass.hxx>
44 #include <tools/multisel.hxx>
45 #include <tools/resary.hxx>
46 #include <toolkit/awt/vclxdevice.hxx>
48 #include <ctype.h>
49 #include <float.h>
51 #include <com/sun/star/util/Date.hpp>
52 #include <com/sun/star/sheet/XNamedRanges.hpp>
53 #include <com/sun/star/sheet/XLabelRanges.hpp>
54 #include <com/sun/star/sheet/XSelectedSheetsSupplier.hpp>
55 #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
56 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
57 #include <com/sun/star/script/XLibraryContainer.hpp>
58 #include <com/sun/star/lang/XInitialization.hpp>
59 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
60 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
61 #include <com/sun/star/document/IndexedPropertyValues.hpp>
62 #include <com/sun/star/script/XInvocation.hpp>
63 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
64 #include <comphelper/processfactory.hxx>
65 #include <comphelper/servicehelper.hxx>
66 #include <comphelper/string.hxx>
67 #include <cppuhelper/supportsservice.hxx>
68 #if HAVE_FEATURE_OPENCL
69 #include <opencl/platforminfo.hxx>
70 #endif
72 #include "cellsuno.hxx"
73 #include <columnspanset.hxx>
74 #include "convuno.hxx"
75 #include "datauno.hxx"
76 #include "docfunc.hxx"
77 #include "dociter.hxx"
78 #include "docoptio.hxx"
79 #include "docsh.hxx"
80 #include "docuno.hxx"
81 #include "drwlayer.hxx"
82 #include "forbiuno.hxx"
83 #include "formulacell.hxx"
84 #include "formulagroup.hxx"
85 #include "gridwin.hxx"
86 #include "hints.hxx"
87 #include <inputhdl.hxx>
88 #include <inputopt.hxx>
89 #include "interpre.hxx"
90 #include "linkuno.hxx"
91 #include "markdata.hxx"
92 #include "miscuno.hxx"
93 #include "nameuno.hxx"
94 #include "notesuno.hxx"
95 #include "optuno.hxx"
96 #include "pfuncache.hxx"
97 #include "postit.hxx"
98 #include "printfun.hxx"
99 #include "rangeutl.hxx"
100 #include "scmod.hxx"
101 #include "scresid.hxx"
102 #include "servuno.hxx"
103 #include "shapeuno.hxx"
104 #include "sheetevents.hxx"
105 #include "styleuno.hxx"
106 #include "tabvwsh.hxx"
107 #include "targuno.hxx"
108 #include "unonames.hxx"
109 #include "ViewSettingsSequenceDefines.hxx"
110 #include "viewuno.hxx"
111 #include "editsh.hxx"
112 #include "drawsh.hxx"
113 #include "drtxtob.hxx"
114 #include "transobj.hxx"
116 #include "sc.hrc"
118 using namespace com::sun::star;
120 // #i111553# provides the name of the VBA constant for this document type (e.g. 'ThisExcelDoc' for Calc)
121 #define SC_UNO_VBAGLOBNAME "VBAGlobalConstantName"
123 // alles ohne Which-ID, Map nur fuer PropertySetInfo
125 //! umbenennen, sind nicht mehr nur Options
126 static const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap()
128 static const SfxItemPropertyMapEntry aDocOptPropertyMap_Impl[] =
130 {OUString(SC_UNO_APPLYFMDES), 0, cppu::UnoType<bool>::get(), 0, 0},
131 {OUString(SC_UNO_AREALINKS), 0, cppu::UnoType<sheet::XAreaLinks>::get(), 0, 0},
132 {OUString(SC_UNO_AUTOCONTFOC), 0, cppu::UnoType<bool>::get(), 0, 0},
133 {OUString(SC_UNO_BASICLIBRARIES), 0, cppu::UnoType<script::XLibraryContainer>::get(), beans::PropertyAttribute::READONLY, 0},
134 {OUString(SC_UNO_DIALOGLIBRARIES), 0, cppu::UnoType<script::XLibraryContainer>::get(), beans::PropertyAttribute::READONLY, 0},
135 {OUString(SC_UNO_VBAGLOBNAME), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0},
136 {OUString(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN, cppu::UnoType<bool>::get(), 0, 0},
137 {OUString(SC_UNONAME_CLOCAL), 0, cppu::UnoType<lang::Locale>::get(), 0, 0},
138 {OUString(SC_UNO_CJK_CLOCAL), 0, cppu::UnoType<lang::Locale>::get(), 0, 0},
139 {OUString(SC_UNO_CTL_CLOCAL), 0, cppu::UnoType<lang::Locale>::get(), 0, 0},
140 {OUString(SC_UNO_COLLABELRNG), 0, cppu::UnoType<sheet::XLabelRanges>::get(), 0, 0},
141 {OUString(SC_UNO_DDELINKS), 0, cppu::UnoType<container::XNameAccess>::get(), 0, 0},
142 {OUString(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP, cppu::UnoType<sal_Int16>::get(), 0, 0},
143 {OUString(SC_UNO_EXTERNALDOCLINKS), 0, cppu::UnoType<sheet::XExternalDocLinks>::get(), 0, 0},
144 {OUString(SC_UNO_FORBIDDEN), 0, cppu::UnoType<i18n::XForbiddenCharacters>::get(), beans::PropertyAttribute::READONLY, 0},
145 {OUString(SC_UNO_HASDRAWPAGES), 0, cppu::UnoType<bool>::get(), beans::PropertyAttribute::READONLY, 0},
146 {OUString(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE, cppu::UnoType<bool>::get(), 0, 0},
147 {OUString(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED, cppu::UnoType<bool>::get(), 0, 0},
148 {OUString(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT, cppu::UnoType<sal_Int32>::get(), 0, 0},
149 {OUString(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON, cppu::UnoType<double>::get(), 0, 0},
150 {OUString(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, cppu::UnoType<bool>::get(), 0, 0},
151 {OUString(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE, cppu::UnoType<bool>::get(), 0, 0},
152 {OUString(SC_UNO_NAMEDRANGES), 0, cppu::UnoType<sheet::XNamedRanges>::get(), 0, 0},
153 {OUString(SC_UNO_DATABASERNG), 0, cppu::UnoType<sheet::XDatabaseRanges>::get(), 0, 0},
154 {OUString(SC_UNO_NULLDATE), PROP_UNO_NULLDATE, cppu::UnoType<util::Date>::get(), 0, 0},
155 {OUString(SC_UNO_ROWLABELRNG), 0, cppu::UnoType<sheet::XLabelRanges>::get(), 0, 0},
156 {OUString(SC_UNO_SHEETLINKS), 0, cppu::UnoType<container::XNameAccess>::get(), 0, 0},
157 {OUString(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE, cppu::UnoType<bool>::get(), 0, 0},
158 {OUString(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC, cppu::UnoType<sal_Int16>::get(), 0, 0},
159 {OUString(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, cppu::UnoType<bool>::get(), 0, 0},
160 {OUString(SC_UNO_RUNTIMEUID), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0},
161 {OUString(SC_UNO_HASVALIDSIGNATURES), 0, cppu::UnoType<bool>::get(), beans::PropertyAttribute::READONLY, 0},
162 {OUString(SC_UNO_ISLOADED), 0, cppu::UnoType<bool>::get(), 0, 0},
163 {OUString(SC_UNO_ISUNDOENABLED), 0, cppu::UnoType<bool>::get(), 0, 0},
164 {OUString(SC_UNO_RECORDCHANGES), 0, cppu::UnoType<bool>::get(), 0, 0},
165 {OUString(SC_UNO_ISRECORDCHANGESPROTECTED),0, cppu::UnoType<bool>::get(), beans::PropertyAttribute::READONLY, 0},
166 {OUString(SC_UNO_ISADJUSTHEIGHTENABLED), 0, cppu::UnoType<bool>::get(), 0, 0},
167 {OUString(SC_UNO_ISEXECUTELINKENABLED), 0, cppu::UnoType<bool>::get(), 0, 0},
168 {OUString(SC_UNO_ISCHANGEREADONLYENABLED), 0, cppu::UnoType<bool>::get(), 0, 0},
169 {OUString(SC_UNO_REFERENCEDEVICE), 0, cppu::UnoType<awt::XDevice>::get(), beans::PropertyAttribute::READONLY, 0},
170 {OUString("BuildId"), 0, ::cppu::UnoType<OUString>::get(), 0, 0},
171 {OUString(SC_UNO_CODENAME), 0, cppu::UnoType<OUString>::get(), 0, 0},
172 {OUString(SC_UNO_INTEROPGRABBAG), 0, cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), 0, 0},
173 { OUString(), 0, css::uno::Type(), 0, 0 }
175 return aDocOptPropertyMap_Impl;
178 //! StandardDecimals als Property und vom NumberFormatter ????????
180 static const SfxItemPropertyMapEntry* lcl_GetColumnsPropertyMap()
182 static const SfxItemPropertyMapEntry aColumnsPropertyMap_Impl[] =
184 {OUString(SC_UNONAME_MANPAGE), 0, cppu::UnoType<bool>::get(), 0, 0 },
185 {OUString(SC_UNONAME_NEWPAGE), 0, cppu::UnoType<bool>::get(), 0, 0 },
186 {OUString(SC_UNONAME_CELLVIS), 0, cppu::UnoType<bool>::get(), 0, 0 },
187 {OUString(SC_UNONAME_OWIDTH), 0, cppu::UnoType<bool>::get(), 0, 0 },
188 {OUString(SC_UNONAME_CELLWID), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
189 { OUString(), 0, css::uno::Type(), 0, 0 }
191 return aColumnsPropertyMap_Impl;
194 static const SfxItemPropertyMapEntry* lcl_GetRowsPropertyMap()
196 static const SfxItemPropertyMapEntry aRowsPropertyMap_Impl[] =
198 {OUString(SC_UNONAME_CELLHGT), 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
199 {OUString(SC_UNONAME_CELLFILT), 0, cppu::UnoType<bool>::get(), 0, 0 },
200 {OUString(SC_UNONAME_OHEIGHT), 0, cppu::UnoType<bool>::get(), 0, 0 },
201 {OUString(SC_UNONAME_MANPAGE), 0, cppu::UnoType<bool>::get(), 0, 0 },
202 {OUString(SC_UNONAME_NEWPAGE), 0, cppu::UnoType<bool>::get(), 0, 0 },
203 {OUString(SC_UNONAME_CELLVIS), 0, cppu::UnoType<bool>::get(), 0, 0 },
204 {OUString(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, ::cppu::UnoType<sal_Int32>::get(), 0, MID_BACK_COLOR },
205 {OUString(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, cppu::UnoType<bool>::get(), 0, MID_GRAPHIC_TRANSPARENT },
206 // not sorted, not used with SfxItemPropertyMapEntry::GetByName
207 { OUString(), 0, css::uno::Type(), 0, 0 }
209 return aRowsPropertyMap_Impl;
212 using sc::HMMToTwips;
213 using sc::TwipsToHMM;
215 #define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument"
216 #define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings"
217 #define SCDOC_SERVICE "com.sun.star.document.OfficeDocument"
219 SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
220 SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
221 SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" )
222 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" )
223 SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" )
224 SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" )
225 SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" )
227 class ScPrintUIOptions : public vcl::PrinterOptionsHelper
229 public:
230 ScPrintUIOptions();
231 void SetDefaults();
234 ScPrintUIOptions::ScPrintUIOptions()
236 const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
237 sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
238 bool bSuppress = rPrintOpt.GetSkipEmpty();
240 ResStringArray aStrings( ScResId( SCSTR_PRINT_OPTIONS ) );
241 OSL_ENSURE( aStrings.Count() >= 10, "resource incomplete" );
242 if( aStrings.Count() < 10 ) // bad resource ?
243 return;
245 sal_Int32 nNumProps= 9, nIdx = 0;
247 m_aUIProperties.realloc(nNumProps);
249 // load the writer PrinterOptions into the custom tab
250 m_aUIProperties[nIdx].Name = "OptionsUIFile";
251 m_aUIProperties[nIdx++].Value <<= OUString("modules/scalc/ui/printeroptions.ui");
253 // create Section for spreadsheet (results in an extra tab page in dialog)
254 SvtModuleOptions aOpt;
255 OUString aAppGroupname( aStrings.GetString( 9 ) );
256 aAppGroupname = aAppGroupname.replaceFirst( "%s", aOpt.GetModuleName( SvtModuleOptions::EModule::CALC ) );
257 m_aUIProperties[nIdx++].Value = setGroupControlOpt("tabcontrol-page2", aAppGroupname, OUString());
259 // show subgroup for pages
260 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("pages", OUString(aStrings.GetString(0)), OUString());
262 // create a bool option for empty pages
263 m_aUIProperties[nIdx++].Value = setBoolControlOpt("suppressemptypages", OUString( aStrings.GetString( 1 ) ),
264 ".HelpID:vcl:PrintDialog:IsSuppressEmptyPages:CheckBox",
265 "IsSuppressEmptyPages",
266 bSuppress);
267 // show Subgroup for print content
268 vcl::PrinterOptionsHelper::UIControlOptions aPrintRangeOpt;
269 aPrintRangeOpt.maGroupHint = "PrintRange";
270 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("printrange", OUString(aStrings.GetString(2)),
271 OUString(),
272 aPrintRangeOpt);
274 // create a choice for the content to create
275 uno::Sequence< OUString > aChoices( 3 ), aHelpIds( 3 ), aWidgetIds( 3 );
276 aChoices[0] = aStrings.GetString( 3 );
277 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0";
278 aWidgetIds[0] = "printallsheets";
279 aChoices[1] = aStrings.GetString( 4 );
280 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1";
281 aWidgetIds[1] = "printselectedsheets";
282 aChoices[2] = aStrings.GetString( 5 );
283 aHelpIds[2] = ".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2";
284 aWidgetIds[2] = "printselectedcells";
285 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
286 aHelpIds, "PrintContent",
287 aChoices, nContent );
289 // show Subgroup for print range
290 aPrintRangeOpt.mbInternalOnly = true;
291 m_aUIProperties[nIdx++].Value = setSubgroupControlOpt("fromwhich", OUString(aStrings.GetString(6)),
292 OUString(),
293 aPrintRangeOpt);
295 // create a choice for the range to print
296 OUString aPrintRangeName( "PrintRange" );
297 aChoices.realloc( 2 );
298 aHelpIds.realloc( 2 );
299 aWidgetIds.realloc( 2 );
300 aChoices[0] = aStrings.GetString( 7 );
301 aHelpIds[0] = ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:0";
302 aWidgetIds[0] = "printallpages";
303 aChoices[1] = aStrings.GetString( 8 );
304 aHelpIds[1] = ".HelpID:vcl:PrintDialog:PrintRange:RadioButton:1";
305 aWidgetIds[1] = "printpages";
306 m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
307 aHelpIds,
308 aPrintRangeName,
309 aChoices,
310 0 );
312 // create a an Edit dependent on "Pages" selected
313 vcl::PrinterOptionsHelper::UIControlOptions aPageRangeOpt( aPrintRangeName, 1, true );
314 m_aUIProperties[nIdx++].Value = setEditControlOpt("pagerange", OUString(),
315 ".HelpID:vcl:PrintDialog:PageRange:Edit",
316 "PageRange", OUString(), aPageRangeOpt);
318 assert(nIdx == nNumProps);
321 void ScPrintUIOptions::SetDefaults()
323 // re-initialize the default values from print options
325 const ScPrintOptions& rPrintOpt = SC_MOD()->GetPrintOptions();
326 sal_Int32 nContent = rPrintOpt.GetAllSheets() ? 0 : 1;
327 bool bSuppress = rPrintOpt.GetSkipEmpty();
329 for (sal_Int32 nUIPos=0; nUIPos<m_aUIProperties.getLength(); ++nUIPos)
331 uno::Sequence<beans::PropertyValue> aUIProp;
332 if ( m_aUIProperties[nUIPos].Value >>= aUIProp )
334 for (sal_Int32 nPropPos=0; nPropPos<aUIProp.getLength(); ++nPropPos)
336 OUString aName = aUIProp[nPropPos].Name;
337 if ( aName == "Property" )
339 beans::PropertyValue aPropertyValue;
340 if ( aUIProp[nPropPos].Value >>= aPropertyValue )
342 if ( aPropertyValue.Name == "PrintContent" )
344 aPropertyValue.Value <<= nContent;
345 aUIProp[nPropPos].Value <<= aPropertyValue;
347 else if ( aPropertyValue.Name == "IsSuppressEmptyPages" )
349 ScUnoHelpFunctions::SetBoolInAny( aPropertyValue.Value, bSuppress );
350 aUIProp[nPropPos].Value <<= aPropertyValue;
355 m_aUIProperties[nUIPos].Value <<= aUIProp;
360 void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
362 if (pDocSh)
363 pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
366 ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
367 SfxBaseModel( pDocSh ),
368 aPropSet( lcl_GetDocOptPropertyMap() ),
369 pDocShell( pDocSh ),
370 pPrintFuncCache( NULL ),
371 pPrinterOptions( NULL ),
372 maChangesListeners( m_aMutex )
374 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
375 if ( pDocShell )
377 pDocShell->GetDocument().AddUnoObject(*this); // SfxModel is derived from SfxListener
381 ScModelObj::~ScModelObj()
383 SolarMutexGuard g;
385 if (pDocShell)
386 pDocShell->GetDocument().RemoveUnoObject(*this);
388 if (xNumberAgg.is())
389 xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
391 delete pPrintFuncCache;
392 delete pPrinterOptions;
395 uno::Reference< uno::XAggregation> ScModelObj::GetFormatter()
397 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
398 if ( !xNumberAgg.is() && pDocShell )
400 // setDelegator veraendert den RefCount, darum eine Referenz selber halten
401 // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen)
402 osl_atomic_increment( &m_refCount );
403 // waehrend des queryInterface braucht man ein Ref auf das
404 // SvNumberFormatsSupplierObj, sonst wird es geloescht.
405 uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument().GetFormatTable() ));
407 xNumberAgg.set(uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ));
408 // extra block to force deletion of the temporary before setDelegator
411 // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren
412 xFormatter = NULL;
414 if (xNumberAgg.is())
415 xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
416 osl_atomic_decrement( &m_refCount );
417 } // if ( !xNumberAgg.is() )
418 return xNumberAgg;
421 ScDocument* ScModelObj::GetDocument() const
423 if (pDocShell)
424 return &pDocShell->GetDocument();
425 return NULL;
428 SfxObjectShell* ScModelObj::GetEmbeddedObject() const
430 return pDocShell;
433 void ScModelObj::UpdateAllRowHeights()
435 if (pDocShell)
436 pDocShell->UpdateAllRowHeights(NULL);
439 void ScModelObj::BeforeXMLLoading()
441 if (pDocShell)
442 pDocShell->BeforeXMLLoading();
445 void ScModelObj::AfterXMLLoading(bool bRet)
447 if (pDocShell)
448 pDocShell->AfterXMLLoading(bRet);
451 ScSheetSaveData* ScModelObj::GetSheetSaveData()
453 if (pDocShell)
454 return pDocShell->GetSheetSaveData();
455 return NULL;
458 void ScModelObj::RepaintRange( const ScRange& rRange )
460 if (pDocShell)
461 pDocShell->PostPaint( rRange, PAINT_GRID );
464 void ScModelObj::RepaintRange( const ScRangeList& rRange )
466 if (pDocShell)
467 pDocShell->PostPaint( rRange, PAINT_GRID );
470 void ScModelObj::paintTile( VirtualDevice& rDevice,
471 int nOutputWidth, int nOutputHeight,
472 int nTilePosX, int nTilePosY,
473 long nTileWidth, long nTileHeight )
475 // There seems to be no clear way of getting the grid window for this
476 // particular document, hence we need to hope we get the right window.
477 ScViewData* pViewData = ScDocShell::GetViewData();
478 ScGridWindow* pGridWindow = pViewData->GetActiveWin();
480 // update the size of the area we are painting
481 // FIXME we want to use only the minimal necessary size, like the
482 // following; but for the moment there is too many problems with that and
483 // interaction with editeng used for the cell editing
484 //Size aTileSize(nOutputWidth, nOutputHeight);
485 //if (pGridWindow->GetOutputSizePixel() != aTileSize)
486 // pGridWindow->SetOutputSizePixel(Size(nOutputWidth, nOutputHeight));
487 // so instead for now, set the viewport size to document size
488 Size aDocSize = getDocumentSize();
489 pGridWindow->SetOutputSizePixel(Size(aDocSize.Width() * pViewData->GetPPTX(), aDocSize.Height() * pViewData->GetPPTY()));
491 pGridWindow->PaintTile( rDevice, nOutputWidth, nOutputHeight,
492 nTilePosX, nTilePosY, nTileWidth, nTileHeight );
495 void ScModelObj::setPart( int nPart )
497 ScViewData* pViewData = ScDocShell::GetViewData();
498 pViewData->SetTabNo( nPart );
501 int ScModelObj::getParts()
503 ScDocument& rDoc = pDocShell->GetDocument();
504 return rDoc.GetTableCount();
507 int ScModelObj::getPart()
509 ScViewData* pViewData = ScDocShell::GetViewData();
510 return pViewData->GetTabNo();
513 OUString ScModelObj::getPartName( int nPart )
515 OUString sTabName;
516 ScViewData* pViewData = ScDocShell::GetViewData();
517 pViewData->GetDocument()->GetName(nPart, sTabName);
518 return sTabName;
521 Size ScModelObj::getDocumentSize()
523 Size aSize(10, 10); // minimum size
525 const ScViewData* pViewData = ScDocShell::GetViewData();
526 if (!pViewData)
527 return aSize;
529 SCTAB nTab = pViewData->GetTabNo();
530 SCCOL nEndCol = 0;
531 SCROW nEndRow = 0;
532 const ScDocument& rDoc = pDocShell->GetDocument();
534 if (!rDoc.GetTiledRenderingArea(nTab, nEndCol, nEndRow))
535 return aSize;
537 // convert to twips
538 aSize.setWidth(rDoc.GetColWidth(0, nEndCol, nTab, true));
539 aSize.setHeight(rDoc.GetRowHeight(0, nEndRow, nTab, true));
541 return aSize;
544 void ScModelObj::registerCallback(LibreOfficeKitCallback pCallback, void* pData)
546 SolarMutexGuard aGuard;
547 pDocShell->GetDocument().GetDrawLayer()->registerLibreOfficeKitCallback(pCallback, pData);
550 void ScModelObj::postKeyEvent(int nType, int nCharCode, int nKeyCode)
552 SolarMutexGuard aGuard;
554 // There seems to be no clear way of getting the grid window for this
555 // particular document, hence we need to hope we get the right window.
556 ScViewData* pViewData = ScDocShell::GetViewData();
557 ScGridWindow* pGridWindow = pViewData->GetActiveWin();
559 if (!pGridWindow)
560 return;
562 KeyEvent aEvent(nCharCode, nKeyCode, 0);
564 switch (nType)
566 case LOK_KEYEVENT_KEYINPUT:
567 pGridWindow->KeyInput(aEvent);
568 break;
569 case LOK_KEYEVENT_KEYUP:
570 pGridWindow->KeyUp(aEvent);
571 break;
572 default:
573 assert(false);
574 break;
578 void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount)
580 SolarMutexGuard aGuard;
582 // There seems to be no clear way of getting the grid window for this
583 // particular document, hence we need to hope we get the right window.
584 ScViewData* pViewData = ScDocShell::GetViewData();
585 ScGridWindow* pGridWindow = pViewData->GetActiveWin();
587 if (!pGridWindow)
588 return;
590 // update the aLogicMode in ScViewData to something predictable
591 pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true);
593 // Calc operates in pixels...
594 MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
596 switch (nType)
598 case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
599 pGridWindow->MouseButtonDown(aEvent);
600 break;
601 case LOK_MOUSEEVENT_MOUSEBUTTONUP:
602 pGridWindow->MouseButtonUp(aEvent);
604 // sometimes MouseButtonDown captures mouse and starts tracking, and VCL
605 // will not take care of releasing that with tiled rendering
606 if (pGridWindow->IsTracking())
607 pGridWindow->EndTracking(TrackingEventFlags::DontCallHdl);
609 break;
610 default:
611 assert(false);
612 break;
616 void ScModelObj::setTextSelection(int nType, int nX, int nY)
618 SolarMutexGuard aGuard;
620 ScViewData* pViewData = ScDocShell::GetViewData();
621 ScTabViewShell* pViewShell = pViewData->GetViewShell();
622 ScInputHandler* pInputHandler = SC_MOD()->GetInputHdl(pViewShell);
623 ScDrawView* pDrawView = pViewData->GetScDrawView();
625 // update the aLogicMode in ScViewData to something predictable
626 pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true);
628 bool bHandled = false;
630 if (pInputHandler && pInputHandler->IsInputMode())
632 // forwarding to editeng - we are editing the cell content
633 EditView* pTableView = pInputHandler->GetTableView();
634 assert(pTableView);
636 Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
638 if (pTableView->GetOutputArea().IsInside(aPoint))
640 switch (nType)
642 case LOK_SETTEXTSELECTION_START:
643 pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
644 break;
645 case LOK_SETTEXTSELECTION_END:
646 pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
647 break;
648 case LOK_SETTEXTSELECTION_RESET:
649 pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
650 break;
651 default:
652 assert(false);
653 break;
655 bHandled = true;
658 else if (pDrawView && pDrawView->IsTextEdit())
660 // forwarding to editeng - we are editing the text in shape
661 OutlinerView* pOutlinerView = pDrawView->GetTextEditOutlinerView();
662 EditView& rEditView = pOutlinerView->GetEditView();
664 Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
665 switch (nType)
667 case LOK_SETTEXTSELECTION_START:
668 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
669 break;
670 case LOK_SETTEXTSELECTION_END:
671 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
672 break;
673 case LOK_SETTEXTSELECTION_RESET:
674 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
675 break;
676 default:
677 assert(false);
678 break;
680 bHandled = true;
683 if (!bHandled)
685 // just update the cell selection
686 ScGridWindow* pGridWindow = pViewData->GetActiveWin();
687 if (!pGridWindow)
688 return;
690 // move the cell selection handles
691 pGridWindow->SetCellSelectionPixel(nType, nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY());
695 OString ScModelObj::getTextSelection(const char* pMimeType, OString& rUsedMimeType)
697 SolarMutexGuard aGuard;
699 ScEditShell* pShell;
700 ScDrawShell* pDrawShell;
701 ScDrawTextObjectBar* pTextShell;
702 TransferableDataHelper aDataHelper;
703 ScViewData* pViewData = ScDocShell::GetViewData();
704 uno::Reference<datatransfer::XTransferable> xTransferable;
706 if (( pShell = PTR_CAST( ScEditShell, pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) )))
707 xTransferable = pShell->GetEditView()->GetTransferable();
708 else if (( pTextShell = PTR_CAST( ScDrawTextObjectBar, pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) )))
710 ScDrawView* pView = pViewData->GetScDrawView();
711 OutlinerView* pOutView = pView->GetTextEditOutlinerView();
712 if (pOutView)
713 xTransferable = pOutView->GetEditView().GetTransferable();
715 else if (( pDrawShell = PTR_CAST( ScDrawShell, pViewData->GetViewShell()->GetViewFrame()->GetDispatcher()->GetShell(0) )))
716 xTransferable = pDrawShell->GetDrawView()->CopyToTransferable();
717 else
719 ScTransferObj* pObj = pViewData->GetViewShell()->CopyToTransferable();
720 xTransferable.set( pObj );
723 if (!xTransferable.is())
724 xTransferable.set( aDataHelper.GetTransferable() );
726 // Take care of UTF-8 text here.
727 OString aMimeType(pMimeType);
728 bool bConvert = false;
729 sal_Int32 nIndex = 0;
730 if (aMimeType.getToken(0, ';', nIndex) == "text/plain")
732 if (aMimeType.getToken(0, ';', nIndex) == "charset=utf-8")
734 aMimeType = "text/plain;charset=utf-16";
735 bConvert = true;
739 datatransfer::DataFlavor aFlavor;
740 aFlavor.MimeType = OUString::fromUtf8(aMimeType.getStr());
741 if (aMimeType == "text/plain;charset=utf-16")
742 aFlavor.DataType = cppu::UnoType<OUString>::get();
743 else
744 aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
746 if (!xTransferable->isDataFlavorSupported(aFlavor))
747 return OString();
749 uno::Any aAny(xTransferable->getTransferData(aFlavor));
751 OString aRet;
752 if (aFlavor.DataType == cppu::UnoType<OUString>::get())
754 OUString aString;
755 aAny >>= aString;
756 if (bConvert)
757 aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8);
758 else
759 aRet = OString(reinterpret_cast<const sal_Char *>(aString.getStr()), aString.getLength() * sizeof(sal_Unicode));
761 else
763 uno::Sequence<sal_Int8> aSequence;
764 aAny >>= aSequence;
765 aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
768 rUsedMimeType = pMimeType;
769 return aRet;
772 void ScModelObj::setGraphicSelection(int nType, int nX, int nY)
774 SolarMutexGuard aGuard;
776 // There seems to be no clear way of getting the grid window for this
777 // particular document, hence we need to hope we get the right window.
778 ScViewData* pViewData = ScDocShell::GetViewData();
779 ScGridWindow* pGridWindow = pViewData->GetActiveWin();
781 // update the aLogicMode in ScViewData to something predictable
782 pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true);
784 int nPixelX = nX * pViewData->GetPPTX();
785 int nPixelY = nY * pViewData->GetPPTY();
787 switch (nType)
789 case LOK_SETGRAPHICSELECTION_START:
791 MouseEvent aClickEvent(Point(nPixelX, nPixelY), 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
792 pGridWindow->MouseButtonDown(aClickEvent);
793 MouseEvent aMoveEvent(Point(nPixelX, nPixelY), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
794 pGridWindow->MouseMove(aMoveEvent);
796 break;
797 case LOK_SETGRAPHICSELECTION_END:
799 MouseEvent aMoveEvent(Point(nPixelX, nPixelY), 0, MouseEventModifiers::SIMPLEMOVE, MOUSE_LEFT);
800 pGridWindow->MouseMove(aMoveEvent);
801 MouseEvent aClickEvent(Point(nPixelX, nPixelY), 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
802 pGridWindow->MouseButtonUp(aClickEvent);
804 break;
805 default:
806 assert(false);
807 break;
811 void ScModelObj::resetSelection()
813 SolarMutexGuard aGuard;
815 ScViewData* pViewData = ScDocShell::GetViewData();
816 ScTabViewShell* pViewShell = pViewData->GetViewShell();
818 // deselect the shapes & texts
819 ScDrawView* pDrawView = pViewShell->GetScDrawView();
820 if (pDrawView)
822 pDrawView->ScEndTextEdit();
823 pDrawView->UnmarkAll();
825 else
826 pViewShell->Unmark();
828 // and hide the cell and text selection
829 pDocShell->GetDocument().GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, "");
832 void ScModelObj::initializeForTiledRendering()
834 SolarMutexGuard aGuard;
835 pDocShell->GetDocument().GetDrawLayer()->setTiledRendering(true);
837 // show us the text exactly
838 ScInputOptions aInputOptions(SC_MOD()->GetInputOptions());
839 aInputOptions.SetTextWysiwyg(true);
840 SC_MOD()->SetInputOptions(aInputOptions);
841 pDocShell->CalcOutputFactor();
844 uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
845 throw(uno::RuntimeException, std::exception)
847 SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
848 SC_QUERYINTERFACE( document::XActionLockable )
849 SC_QUERYINTERFACE( sheet::XCalculatable )
850 SC_QUERYINTERFACE( util::XProtectable )
851 SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
852 SC_QUERYINTERFACE( sheet::XGoalSeek )
853 SC_QUERYINTERFACE( sheet::XConsolidatable )
854 SC_QUERYINTERFACE( sheet::XDocumentAuditing )
855 SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
856 SC_QUERYINTERFACE( view::XRenderable )
857 SC_QUERYINTERFACE( document::XLinkTargetSupplier )
858 SC_QUERYINTERFACE( beans::XPropertySet )
859 SC_QUERYINTERFACE( lang::XMultiServiceFactory )
860 SC_QUERYINTERFACE( lang::XServiceInfo )
861 SC_QUERYINTERFACE( util::XChangesNotifier )
862 SC_QUERYINTERFACE( sheet::opencl::XOpenCLSelection )
864 uno::Any aRet(SfxBaseModel::queryInterface( rType ));
865 if ( !aRet.hasValue()
866 && rType != cppu::UnoType<com::sun::star::document::XDocumentEventBroadcaster>::get()
867 && rType != cppu::UnoType<com::sun::star::frame::XController>::get()
868 && rType != cppu::UnoType<com::sun::star::frame::XFrame>::get()
869 && rType != cppu::UnoType<com::sun::star::script::XInvocation>::get()
870 && rType != cppu::UnoType<com::sun::star::beans::XFastPropertySet>::get()
871 && rType != cppu::UnoType<com::sun::star::awt::XWindow>::get())
873 GetFormatter();
874 if ( xNumberAgg.is() )
875 aRet = xNumberAgg->queryAggregation( rType );
878 return aRet;
881 void SAL_CALL ScModelObj::acquire() throw()
883 SfxBaseModel::acquire();
886 void SAL_CALL ScModelObj::release() throw()
888 SfxBaseModel::release();
891 uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException, std::exception)
893 static uno::Sequence<uno::Type> aTypes;
894 if ( aTypes.getLength() == 0 )
896 uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
897 long nParentLen = aParentTypes.getLength();
898 const uno::Type* pParentPtr = aParentTypes.getConstArray();
900 uno::Sequence<uno::Type> aAggTypes;
901 if ( GetFormatter().is() )
903 const uno::Type& rProvType = cppu::UnoType<lang::XTypeProvider>::get();
904 uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
905 if(aNumProv.getValueType() == rProvType)
907 uno::Reference<lang::XTypeProvider> xNumProv(
908 *static_cast<uno::Reference<lang::XTypeProvider> const *>(aNumProv.getValue()));
909 aAggTypes = xNumProv->getTypes();
912 long nAggLen = aAggTypes.getLength();
913 const uno::Type* pAggPtr = aAggTypes.getConstArray();
915 const long nThisLen = 16;
916 aTypes.realloc( nParentLen + nAggLen + nThisLen );
917 uno::Type* pPtr = aTypes.getArray();
918 pPtr[nParentLen + 0] = cppu::UnoType<sheet::XSpreadsheetDocument>::get();
919 pPtr[nParentLen + 1] = cppu::UnoType<document::XActionLockable>::get();
920 pPtr[nParentLen + 2] = cppu::UnoType<sheet::XCalculatable>::get();
921 pPtr[nParentLen + 3] = cppu::UnoType<util::XProtectable>::get();
922 pPtr[nParentLen + 4] = cppu::UnoType<drawing::XDrawPagesSupplier>::get();
923 pPtr[nParentLen + 5] = cppu::UnoType<sheet::XGoalSeek>::get();
924 pPtr[nParentLen + 6] = cppu::UnoType<sheet::XConsolidatable>::get();
925 pPtr[nParentLen + 7] = cppu::UnoType<sheet::XDocumentAuditing>::get();
926 pPtr[nParentLen + 8] = cppu::UnoType<style::XStyleFamiliesSupplier>::get();
927 pPtr[nParentLen + 9] = cppu::UnoType<view::XRenderable>::get();
928 pPtr[nParentLen +10] = cppu::UnoType<document::XLinkTargetSupplier>::get();
929 pPtr[nParentLen +11] = cppu::UnoType<beans::XPropertySet>::get();
930 pPtr[nParentLen +12] = cppu::UnoType<lang::XMultiServiceFactory>::get();
931 pPtr[nParentLen +13] = cppu::UnoType<lang::XServiceInfo>::get();
932 pPtr[nParentLen +14] = cppu::UnoType<util::XChangesNotifier>::get();
933 pPtr[nParentLen +15] = cppu::UnoType<sheet::opencl::XOpenCLSelection>::get();
935 long i;
936 for (i=0; i<nParentLen; i++)
937 pPtr[i] = pParentPtr[i]; // parent types first
939 for (i=0; i<nAggLen; i++)
940 pPtr[nParentLen+nThisLen+i] = pAggPtr[i]; // aggregated types last
942 return aTypes;
945 uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId()
946 throw(uno::RuntimeException, std::exception)
948 return css::uno::Sequence<sal_Int8>();
951 void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
953 // Not interested in reference update hints here
955 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
956 if ( pSimpleHint )
958 sal_uLong nId = pSimpleHint->GetId();
959 if ( nId == SFX_HINT_DYING )
961 pDocShell = NULL; // has become invalid
962 if (xNumberAgg.is())
964 SvNumberFormatsSupplierObj* pNumFmt =
965 SvNumberFormatsSupplierObj::getImplementation(
966 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
967 if ( pNumFmt )
968 pNumFmt->SetNumberFormatter( NULL );
971 DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell
973 else if ( nId == SFX_HINT_DATACHANGED )
975 // cached data for rendering become invalid when contents change
976 // (if a broadcast is added to SetDrawModified, is has to be tested here, too)
978 DELETEZ( pPrintFuncCache );
980 // handle "OnCalculate" sheet events (search also for VBA event handlers)
981 if ( pDocShell )
983 ScDocument& rDoc = pDocShell->GetDocument();
984 if ( rDoc.GetVbaEventProcessor().is() )
986 // If the VBA event processor is set, HasAnyCalcNotification is much faster than HasAnySheetEventScript
987 if ( rDoc.HasAnyCalcNotification() && rDoc.HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true ) )
988 HandleCalculateEvents();
990 else
992 if ( rDoc.HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE ) )
993 HandleCalculateEvents();
998 else if ( dynamic_cast<const ScPointerChangedHint*>(&rHint) )
1000 sal_uInt16 nFlags = static_cast<const ScPointerChangedHint&>(rHint).GetFlags();
1001 if (nFlags & SC_POINTERCHANGED_NUMFMT)
1003 // NumberFormatter-Pointer am Uno-Objekt neu setzen
1005 if (GetFormatter().is())
1007 SvNumberFormatsSupplierObj* pNumFmt =
1008 SvNumberFormatsSupplierObj::getImplementation(
1009 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
1010 if ( pNumFmt && pDocShell )
1011 pNumFmt->SetNumberFormatter( pDocShell->GetDocument().GetFormatTable() );
1016 // always call parent - SfxBaseModel might need to handle the same hints again
1017 SfxBaseModel::Notify( rBC, rHint ); // SfxBaseModel is derived from SfxListener
1020 // XSpreadsheetDocument
1022 uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException, std::exception)
1024 SolarMutexGuard aGuard;
1025 if (pDocShell)
1026 return new ScTableSheetsObj(pDocShell);
1027 return NULL;
1030 // XStyleFamiliesSupplier
1032 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
1033 throw(uno::RuntimeException, std::exception)
1035 SolarMutexGuard aGuard;
1036 if (pDocShell)
1037 return new ScStyleFamiliesObj(pDocShell);
1038 return NULL;
1041 // XRenderable
1043 static OutputDevice* lcl_GetRenderDevice( const uno::Sequence<beans::PropertyValue>& rOptions )
1045 OutputDevice* pRet = NULL;
1046 const beans::PropertyValue* pPropArray = rOptions.getConstArray();
1047 long nPropCount = rOptions.getLength();
1048 for (long i = 0; i < nPropCount; i++)
1050 const beans::PropertyValue& rProp = pPropArray[i];
1051 OUString aPropName(rProp.Name);
1053 if (aPropName == SC_UNONAME_RENDERDEV)
1055 uno::Reference<awt::XDevice> xRenderDevice(rProp.Value, uno::UNO_QUERY);
1056 if ( xRenderDevice.is() )
1058 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
1059 if ( pDevice )
1061 pRet = pDevice->GetOutputDevice();
1062 pRet->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
1067 return pRet;
1070 static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, Rectangle& rTargetRect,
1071 bool& rIsSheet, ScDocument* pDoc, SCTAB nSourceTab )
1073 // test in same order as in SID_CURRENTCELL execute
1075 ScAddress aAddress;
1076 ScRangeUtil aRangeUtil;
1077 SCTAB nNameTab;
1078 sal_Int32 nNumeric = 0;
1080 bool bRangeValid = false;
1081 bool bRectValid = false;
1083 if ( rTargetRange.Parse( rTarget, pDoc ) & SCA_VALID )
1085 bRangeValid = true; // range reference
1087 else if ( aAddress.Parse( rTarget, pDoc ) & SCA_VALID )
1089 rTargetRange = aAddress;
1090 bRangeValid = true; // cell reference
1092 else if ( ScRangeUtil::MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_NAMES ) ||
1093 ScRangeUtil::MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_DBASE ) )
1095 bRangeValid = true; // named range or database range
1097 else if ( comphelper::string::isdigitAsciiString(rTarget) &&
1098 ( nNumeric = rTarget.toInt32() ) > 0 && nNumeric <= MAXROW+1 )
1100 // row number is always mapped to cell A(row) on the same sheet
1101 rTargetRange = ScAddress( 0, (SCROW)(nNumeric-1), nSourceTab ); // target row number is 1-based
1102 bRangeValid = true; // row number
1104 else if ( pDoc->GetTable( rTarget, nNameTab ) )
1106 rTargetRange = ScAddress(0,0,nNameTab);
1107 bRangeValid = true; // sheet name
1108 rIsSheet = true; // needs special handling (first page of the sheet)
1110 else
1112 // look for named drawing object
1114 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1115 if ( pDrawLayer )
1117 SCTAB nTabCount = pDoc->GetTableCount();
1118 for (SCTAB i=0; i<nTabCount && !bRangeValid; i++)
1120 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
1121 OSL_ENSURE(pPage,"Page ?");
1122 if (pPage)
1124 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
1125 SdrObject* pObject = aIter.Next();
1126 while (pObject && !bRangeValid)
1128 if ( ScDrawLayer::GetVisibleName( pObject ) == rTarget )
1130 rTargetRect = pObject->GetLogicRect(); // 1/100th mm
1131 rTargetRange = pDoc->GetRange( i, rTargetRect ); // underlying cells
1132 bRangeValid = bRectValid = true; // rectangle is valid
1134 pObject = aIter.Next();
1140 if ( bRangeValid && !bRectValid )
1142 // get rectangle for cell range
1143 rTargetRect = pDoc->GetMMRect( rTargetRange.aStart.Col(), rTargetRange.aStart.Row(),
1144 rTargetRange.aEnd.Col(), rTargetRange.aEnd.Row(),
1145 rTargetRange.aStart.Tab() );
1148 return bRangeValid;
1151 bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
1152 const uno::Sequence< beans::PropertyValue >& rOptions,
1153 ScMarkData& rMark,
1154 ScPrintSelectionStatus& rStatus, OUString& rPagesStr ) const
1156 OSL_ENSURE( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
1157 OSL_ENSURE( pDocShell, "FillRenderMarkData: DocShell must be set" );
1159 bool bDone = false;
1161 uno::Reference<frame::XController> xView;
1163 // defaults when no options are passed: all sheets, include empty pages
1164 bool bSelectedSheetsOnly = false;
1165 bool bSuppressEmptyPages = true;
1167 bool bHasPrintContent = false;
1168 sal_Int32 nPrintContent = 0; // all sheets / selected sheets / selected cells
1169 sal_Int32 nPrintRange = 0; // all pages / pages
1170 OUString aPageRange; // "pages" edit value
1172 for( sal_Int32 i = 0, nLen = rOptions.getLength(); i < nLen; i++ )
1174 if ( rOptions[i].Name == "IsOnlySelectedSheets" )
1176 rOptions[i].Value >>= bSelectedSheetsOnly;
1178 else if ( rOptions[i].Name == "IsSuppressEmptyPages" )
1180 rOptions[i].Value >>= bSuppressEmptyPages;
1182 else if ( rOptions[i].Name == "PageRange" )
1184 rOptions[i].Value >>= aPageRange;
1186 else if ( rOptions[i].Name == "PrintRange" )
1188 rOptions[i].Value >>= nPrintRange;
1190 else if ( rOptions[i].Name == "PrintContent" )
1192 bHasPrintContent = true;
1193 rOptions[i].Value >>= nPrintContent;
1195 else if ( rOptions[i].Name == "View" )
1197 rOptions[i].Value >>= xView;
1201 // "Print Content" selection wins over "Selected Sheets" option
1202 if ( bHasPrintContent )
1203 bSelectedSheetsOnly = ( nPrintContent != 0 );
1205 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
1206 if ( xInterface.is() )
1208 ScCellRangesBase* pSelObj = ScCellRangesBase::getImplementation( xInterface );
1209 uno::Reference< drawing::XShapes > xShapes( xInterface, uno::UNO_QUERY );
1210 if ( pSelObj && pSelObj->GetDocShell() == pDocShell )
1212 bool bSheet = ( ScTableSheetObj::getImplementation( xInterface ) != NULL );
1213 bool bCursor = pSelObj->IsCursorOnly();
1214 const ScRangeList& rRanges = pSelObj->GetRangeList();
1216 rMark.MarkFromRangeList( rRanges, false );
1217 rMark.MarkToSimple();
1219 if ( rMark.IsMultiMarked() )
1221 // #i115266# copy behavior of old printing:
1222 // treat multiple selection like a single selection with the enclosing range
1223 ScRange aMultiMarkArea;
1224 rMark.GetMultiMarkArea( aMultiMarkArea );
1225 rMark.ResetMark();
1226 rMark.SetMarkArea( aMultiMarkArea );
1229 if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
1231 // a sheet object is treated like an empty selection: print the used area of the sheet
1233 if ( bCursor || bSheet ) // nothing selected -> use whole tables
1235 rMark.ResetMark(); // doesn't change table selection
1236 rStatus.SetMode( SC_PRINTSEL_CURSOR );
1238 else
1239 rStatus.SetMode( SC_PRINTSEL_RANGE );
1241 rStatus.SetRanges( rRanges );
1242 bDone = true;
1244 // multi selection isn't supported
1246 else if( xShapes.is() )
1248 //print a selected ole object
1249 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY );
1250 if( xIndexAccess.is() )
1252 // multi selection isn't supported yet
1253 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
1254 SvxShape* pShape = SvxShape::getImplementation( xShape );
1255 if( pShape )
1257 SdrObject *pSdrObj = pShape->GetSdrObject();
1258 if( pDocShell )
1260 ScDocument& rDoc = pDocShell->GetDocument();
1261 if( pSdrObj )
1263 Rectangle aObjRect = pSdrObj->GetCurrentBoundRect();
1264 SCTAB nCurrentTab = ScDocShell::GetCurTab();
1265 ScRange aRange = rDoc.GetRange( nCurrentTab, aObjRect );
1266 rMark.SetMarkArea( aRange );
1268 if( rMark.IsMarked() && !rMark.IsMultiMarked() )
1270 rStatus.SetMode( SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS );
1271 bDone = true;
1278 else if ( ScModelObj::getImplementation( xInterface ) == this )
1280 // render the whole document
1281 // -> no selection, all sheets
1283 SCTAB nTabCount = pDocShell->GetDocument().GetTableCount();
1284 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
1285 rMark.SelectTable( nTab, true );
1286 rStatus.SetMode( SC_PRINTSEL_DOCUMENT );
1287 bDone = true;
1289 // other selection types aren't supported
1292 // restrict to selected sheets if a view is available
1293 uno::Reference<sheet::XSelectedSheetsSupplier> xSelectedSheets(xView, uno::UNO_QUERY);
1294 if (bSelectedSheetsOnly && xSelectedSheets.is())
1296 uno::Sequence<sal_Int32> aSelected = xSelectedSheets->getSelectedSheets();
1297 ScMarkData::MarkedTabsType aSelectedTabs;
1298 SCTAB nMaxTab = pDocShell->GetDocument().GetTableCount() -1;
1299 for (sal_Int32 i = 0, n = aSelected.getLength(); i < n; ++i)
1301 SCTAB nSelected = static_cast<SCTAB>(aSelected[i]);
1302 if (ValidTab(nSelected, nMaxTab))
1303 aSelectedTabs.insert(static_cast<SCTAB>(aSelected[i]));
1305 rMark.SetSelectedTabs(aSelectedTabs);
1308 ScPrintOptions aNewOptions;
1309 aNewOptions.SetSkipEmpty( bSuppressEmptyPages );
1310 aNewOptions.SetAllSheets( !bSelectedSheetsOnly );
1311 rStatus.SetOptions( aNewOptions );
1313 // "PrintRange" enables (1) or disables (0) the "PageRange" edit
1314 if ( nPrintRange == 1 )
1315 rPagesStr = aPageRange;
1316 else
1317 rPagesStr.clear();
1319 return bDone;
1322 sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
1323 const uno::Sequence<beans::PropertyValue>& rOptions)
1324 throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1326 SolarMutexGuard aGuard;
1327 if (!pDocShell)
1329 throw lang::DisposedException( OUString(),
1330 static_cast< sheet::XSpreadsheetDocument* >(this) );
1333 ScMarkData aMark;
1334 ScPrintSelectionStatus aStatus;
1335 OUString aPagesStr;
1336 if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
1337 return 0;
1339 // The same ScPrintFuncCache object in pPrintFuncCache is used as long as
1340 // the same selection is used (aStatus) and the document isn't changed
1341 // (pPrintFuncCache is cleared in Notify handler)
1343 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1345 delete pPrintFuncCache;
1346 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1348 sal_Int32 nPages = pPrintFuncCache->GetPageCount();
1350 sal_Int32 nSelectCount = nPages;
1351 if ( !aPagesStr.isEmpty() )
1353 StringRangeEnumerator aRangeEnum( aPagesStr, 0, nPages-1 );
1354 nSelectCount = aRangeEnum.size();
1356 return (nSelectCount > 0) ? nSelectCount : 1;
1359 static sal_Int32 lcl_GetRendererNum( sal_Int32 nSelRenderer, const OUString& rPagesStr, sal_Int32 nTotalPages )
1361 if ( rPagesStr.isEmpty() )
1362 return nSelRenderer;
1364 StringRangeEnumerator aRangeEnum( rPagesStr, 0, nTotalPages-1 );
1365 StringRangeEnumerator::Iterator aIter = aRangeEnum.begin();
1366 StringRangeEnumerator::Iterator aEnd = aRangeEnum.end();
1367 for ( ; nSelRenderer > 0 && aIter != aEnd; --nSelRenderer )
1368 ++aIter;
1370 return *aIter; // returns -1 if reached the end
1373 uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nSelRenderer,
1374 const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& rOptions )
1375 throw (lang::IllegalArgumentException,
1376 uno::RuntimeException,
1377 std::exception)
1379 SolarMutexGuard aGuard;
1380 if (!pDocShell)
1382 throw lang::DisposedException( OUString(),
1383 static_cast< sheet::XSpreadsheetDocument* >(this) );
1386 ScMarkData aMark;
1387 ScPrintSelectionStatus aStatus;
1388 OUString aPagesStr;
1389 // #i115266# if FillRenderMarkData fails, keep nTotalPages at 0, but still handle getRenderer(0) below
1390 long nTotalPages = 0;
1391 if ( FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
1393 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1395 delete pPrintFuncCache;
1396 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1398 nTotalPages = pPrintFuncCache->GetPageCount();
1400 sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
1401 if ( nRenderer < 0 )
1403 if ( nSelRenderer == 0 )
1405 // getRenderer(0) is used to query the settings, so it must always return something
1407 SCTAB nCurTab = 0; //! use current sheet from view?
1408 ScPrintFunc aDefaultFunc( pDocShell, pDocShell->GetPrinter(), nCurTab );
1409 Size aTwips = aDefaultFunc.GetPageSize();
1410 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
1412 uno::Sequence<beans::PropertyValue> aSequence(1);
1413 beans::PropertyValue* pArray = aSequence.getArray();
1414 pArray[0].Name = SC_UNONAME_PAGESIZE;
1415 pArray[0].Value <<= aPageSize;
1417 if( ! pPrinterOptions )
1418 pPrinterOptions = new ScPrintUIOptions;
1419 else
1420 pPrinterOptions->SetDefaults();
1421 pPrinterOptions->appendPrintUIOptions( aSequence );
1422 return aSequence;
1424 else
1425 throw lang::IllegalArgumentException();
1428 // printer is used as device (just for page layout), draw view is not needed
1430 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
1432 ScRange aRange;
1433 const ScRange* pSelRange = NULL;
1434 if ( aMark.IsMarked() )
1436 aMark.GetMarkArea( aRange );
1437 pSelRange = &aRange;
1439 ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
1440 pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
1441 aFunc.SetRenderFlag( true );
1443 Range aPageRange( nRenderer+1, nRenderer+1 );
1444 MultiSelection aPage( aPageRange );
1445 aPage.SetTotalRange( Range(0,RANGE_MAX) );
1446 aPage.Select( aPageRange );
1448 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
1449 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
1451 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, false, NULL );
1453 ScRange aCellRange;
1454 bool bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
1455 Size aTwips = aFunc.GetPageSize();
1456 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
1458 long nPropCount = bWasCellRange ? 3 : 2;
1459 uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
1460 beans::PropertyValue* pArray = aSequence.getArray();
1461 pArray[0].Name = SC_UNONAME_PAGESIZE;
1462 pArray[0].Value <<= aPageSize;
1463 // #i111158# all positions are relative to the whole page, including non-printable area
1464 pArray[1].Name = SC_UNONAME_INC_NP_AREA;
1465 pArray[1].Value = uno::makeAny( sal_True );
1466 if ( bWasCellRange )
1468 table::CellRangeAddress aRangeAddress( nTab,
1469 aCellRange.aStart.Col(), aCellRange.aStart.Row(),
1470 aCellRange.aEnd.Col(), aCellRange.aEnd.Row() );
1471 pArray[2].Name = SC_UNONAME_SOURCERANGE;
1472 pArray[2].Value <<= aRangeAddress;
1475 if( ! pPrinterOptions )
1476 pPrinterOptions = new ScPrintUIOptions;
1477 else
1478 pPrinterOptions->SetDefaults();
1479 pPrinterOptions->appendPrintUIOptions( aSequence );
1480 return aSequence;
1483 void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelection,
1484 const uno::Sequence<beans::PropertyValue>& rOptions )
1485 throw(lang::IllegalArgumentException,
1486 uno::RuntimeException,
1487 std::exception)
1489 SolarMutexGuard aGuard;
1490 if (!pDocShell)
1492 throw lang::DisposedException( OUString(),
1493 static_cast< sheet::XSpreadsheetDocument* >(this) );
1496 ScMarkData aMark;
1497 ScPrintSelectionStatus aStatus;
1498 OUString aPagesStr;
1499 if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr ) )
1500 throw lang::IllegalArgumentException();
1502 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
1504 delete pPrintFuncCache;
1505 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
1507 long nTotalPages = pPrintFuncCache->GetPageCount();
1508 sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages );
1509 if ( nRenderer < 0 )
1510 throw lang::IllegalArgumentException();
1512 OutputDevice* pDev = lcl_GetRenderDevice( rOptions );
1513 if ( !pDev )
1514 throw lang::IllegalArgumentException();
1516 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
1517 ScDocument& rDoc = pDocShell->GetDocument();
1519 FmFormView* pDrawView = NULL;
1521 // #114135#
1522 ScDrawLayer* pModel = rDoc.GetDrawLayer();
1524 if( pModel )
1526 pDrawView = new FmFormView( pModel, pDev );
1527 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
1528 pDrawView->SetPrintPreview( true );
1531 ScRange aRange;
1532 const ScRange* pSelRange = NULL;
1533 if ( aMark.IsMarked() )
1535 aMark.GetMarkArea( aRange );
1536 pSelRange = &aRange;
1539 // to increase performance, ScPrintState might be used here for subsequent
1540 // pages of the same sheet
1542 ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions() );
1543 aFunc.SetDrawView( pDrawView );
1544 aFunc.SetRenderFlag( true );
1545 if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
1546 aFunc.SetExclusivelyDrawOleAndDrawObjects();
1548 Range aPageRange( nRenderer+1, nRenderer+1 );
1549 MultiSelection aPage( aPageRange );
1550 aPage.SetTotalRange( Range(0,RANGE_MAX) );
1551 aPage.Select( aPageRange );
1553 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
1554 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
1556 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
1557 if ( nRenderer == nTabStart )
1559 // first page of a sheet: add outline item for the sheet name
1561 if ( pPDFData && pPDFData->GetIsExportBookmarks() )
1563 // the sheet starts at the top of the page
1564 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
1565 sal_Int32 nDestID = pPDFData->CreateDest( aArea );
1566 OUString aTabName;
1567 rDoc.GetName( nTab, aTabName );
1568 sal_Int32 nParent = -1; // top-level
1569 pPDFData->CreateOutlineItem( nParent, aTabName, nDestID );
1571 // #i56629# add the named destination stuff
1572 if( pPDFData && pPDFData->GetIsExportNamedDestinations() )
1574 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
1575 OUString aTabName;
1576 rDoc.GetName( nTab, aTabName );
1577 //need the PDF page number here
1578 pPDFData->CreateNamedDest( aTabName, aArea );
1582 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, true, NULL );
1584 // resolve the hyperlinks for PDF export
1586 if ( pPDFData )
1588 // iterate over the hyperlinks that were output for this page
1590 std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFData->GetBookmarks();
1591 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIter = rBookmarks.begin();
1592 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
1593 while ( aIter != aIEnd )
1595 OUString aBookmark = aIter->aBookmark;
1596 if ( aBookmark.toChar() == (sal_Unicode) '#' )
1598 // try to resolve internal link
1600 OUString aTarget( aBookmark.copy( 1 ) );
1602 ScRange aTargetRange;
1603 Rectangle aTargetRect; // 1/100th mm
1604 bool bIsSheet = false;
1605 bool bValid = lcl_ParseTarget( aTarget, aTargetRange, aTargetRect, bIsSheet, &rDoc, nTab );
1607 if ( bValid )
1609 sal_Int32 nPage = -1;
1610 Rectangle aArea;
1611 if ( bIsSheet )
1613 // Get first page for sheet (if nothing from that sheet is printed,
1614 // this page can show a different sheet)
1615 nPage = pPrintFuncCache->GetTabStart( aTargetRange.aStart.Tab() );
1616 aArea = pDev->PixelToLogic( Rectangle( 0,0,0,0 ) );
1618 else
1620 pPrintFuncCache->InitLocations( aMark, pDev ); // does nothing if already initialized
1622 ScPrintPageLocation aLocation;
1623 if ( pPrintFuncCache->FindLocation( aTargetRange.aStart, aLocation ) )
1625 nPage = aLocation.nPage;
1627 // get the rectangle of the page's cell range in 1/100th mm
1628 ScRange aLocRange = aLocation.aCellRange;
1629 Rectangle aLocationMM = rDoc.GetMMRect(
1630 aLocRange.aStart.Col(), aLocRange.aStart.Row(),
1631 aLocRange.aEnd.Col(), aLocRange.aEnd.Row(),
1632 aLocRange.aStart.Tab() );
1633 Rectangle aLocationPixel = aLocation.aRectangle;
1635 // Scale and move the target rectangle from aLocationMM to aLocationPixel,
1636 // to get the target rectangle in pixels.
1638 Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
1639 Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );
1641 long nX1 = aLocationPixel.Left() + (long)
1642 ( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
1643 long nX2 = aLocationPixel.Left() + (long)
1644 ( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
1645 long nY1 = aLocationPixel.Top() + (long)
1646 ( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
1647 long nY2 = aLocationPixel.Top() + (long)
1648 ( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
1650 if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
1651 if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
1652 if ( nY1 > aLocationPixel.Bottom() ) nY1 = aLocationPixel.Bottom();
1653 if ( nY2 > aLocationPixel.Bottom() ) nY2 = aLocationPixel.Bottom();
1655 // The link target area is interpreted using the device's MapMode at
1656 // the time of the CreateDest call, so PixelToLogic can be used here,
1657 // regardless of the MapMode that is actually selected.
1659 aArea = pDev->PixelToLogic( Rectangle( nX1, nY1, nX2, nY2 ) );
1663 if ( nPage >= 0 )
1664 pPDFData->SetLinkDest( aIter->nLinkId, pPDFData->CreateDest( aArea, nPage ) );
1667 else
1669 // external link, use as-is
1670 pPDFData->SetLinkURL( aIter->nLinkId, aBookmark );
1672 ++aIter;
1674 rBookmarks.clear();
1677 if ( pDrawView )
1678 pDrawView->HideSdrPage();
1679 delete pDrawView;
1682 // XLinkTargetSupplier
1684 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException, std::exception)
1686 SolarMutexGuard aGuard;
1687 if (pDocShell)
1688 return new ScLinkTargetTypesObj(pDocShell);
1689 return NULL;
1692 // XActionLockable
1694 sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException, std::exception)
1696 SolarMutexGuard aGuard;
1697 bool bLocked = false;
1698 if (pDocShell)
1699 bLocked = ( pDocShell->GetLockCount() != 0 );
1700 return bLocked;
1703 void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException, std::exception)
1705 SolarMutexGuard aGuard;
1706 if (pDocShell)
1707 pDocShell->LockDocument();
1710 void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException, std::exception)
1712 SolarMutexGuard aGuard;
1713 if (pDocShell)
1714 pDocShell->UnlockDocument();
1717 void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException, std::exception)
1719 SolarMutexGuard aGuard;
1720 if (pDocShell)
1721 pDocShell->SetLockCount(nLock);
1724 sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException, std::exception)
1726 SolarMutexGuard aGuard;
1727 sal_uInt16 nRet = 0;
1728 if (pDocShell)
1730 nRet = pDocShell->GetLockCount();
1731 pDocShell->SetLockCount(0);
1733 return nRet;
1736 void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException, std::exception)
1738 SolarMutexGuard aGuard;
1739 SfxBaseModel::lockControllers();
1740 if (pDocShell)
1741 pDocShell->LockPaint();
1744 void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException, std::exception)
1746 SolarMutexGuard aGuard;
1747 if (hasControllersLocked())
1749 SfxBaseModel::unlockControllers();
1750 if (pDocShell)
1751 pDocShell->UnlockPaint();
1755 // XCalculate
1757 void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException, std::exception)
1759 SolarMutexGuard aGuard;
1760 if (pDocShell)
1761 pDocShell->DoRecalc(true);
1762 else
1764 OSL_FAIL("keine DocShell"); //! Exception oder so?
1768 void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException, std::exception)
1770 SolarMutexGuard aGuard;
1771 if (pDocShell)
1772 pDocShell->DoHardRecalc(true);
1773 else
1775 OSL_FAIL("keine DocShell"); //! Exception oder so?
1779 sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException, std::exception)
1781 SolarMutexGuard aGuard;
1782 if (pDocShell)
1783 return pDocShell->GetDocument().GetAutoCalc();
1785 OSL_FAIL("keine DocShell"); //! Exception oder so?
1786 return false;
1789 void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabledIn )
1790 throw(uno::RuntimeException, std::exception)
1792 bool bEnabled(bEnabledIn);
1793 SolarMutexGuard aGuard;
1794 if (pDocShell)
1796 ScDocument& rDoc = pDocShell->GetDocument();
1797 if ( rDoc.GetAutoCalc() != bEnabled )
1799 rDoc.SetAutoCalc( bEnabled );
1800 pDocShell->SetDocumentModified();
1803 else
1805 OSL_FAIL("keine DocShell"); //! Exception oder so?
1809 // XProtectable
1811 void SAL_CALL ScModelObj::protect( const OUString& aPassword ) throw(uno::RuntimeException, std::exception)
1813 SolarMutexGuard aGuard;
1814 // #i108245# if already protected, don't change anything
1815 if ( pDocShell && !pDocShell->GetDocument().IsDocProtected() )
1817 OUString aString(aPassword);
1818 pDocShell->GetDocFunc().Protect( TABLEID_DOC, aString, true );
1822 void SAL_CALL ScModelObj::unprotect( const OUString& aPassword )
1823 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1825 SolarMutexGuard aGuard;
1826 if (pDocShell)
1828 OUString aString(aPassword);
1829 bool bDone = pDocShell->GetDocFunc().Unprotect( TABLEID_DOC, aString, true );
1830 if (!bDone)
1831 throw lang::IllegalArgumentException();
1835 sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException, std::exception)
1837 SolarMutexGuard aGuard;
1838 if (pDocShell)
1839 return pDocShell->GetDocument().IsDocProtected();
1841 OSL_FAIL("keine DocShell"); //! Exception oder so?
1842 return false;
1845 // XDrawPagesSupplier
1847 uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException, std::exception)
1849 SolarMutexGuard aGuard;
1850 if (pDocShell)
1851 return new ScDrawPagesObj(pDocShell);
1853 OSL_FAIL("keine DocShell"); //! Exception oder so?
1854 return NULL;
1857 // XGoalSeek
1859 sheet::GoalResult SAL_CALL ScModelObj::seekGoal(
1860 const table::CellAddress& aFormulaPosition,
1861 const table::CellAddress& aVariablePosition,
1862 const OUString& aGoalValue )
1863 throw (uno::RuntimeException,
1864 std::exception)
1866 SolarMutexGuard aGuard;
1867 sheet::GoalResult aResult;
1868 aResult.Divergence = DBL_MAX; // nichts gefunden
1869 if (pDocShell)
1871 WaitObject aWait( ScDocShell::GetActiveDialogParent() );
1872 OUString aGoalString(aGoalValue);
1873 ScDocument& rDoc = pDocShell->GetDocument();
1874 double fValue = 0.0;
1875 bool bFound = rDoc.Solver(
1876 (SCCOL)aFormulaPosition.Column, (SCROW)aFormulaPosition.Row, aFormulaPosition.Sheet,
1877 (SCCOL)aVariablePosition.Column, (SCROW)aVariablePosition.Row, aVariablePosition.Sheet,
1878 aGoalString, fValue );
1879 aResult.Result = fValue;
1880 if (bFound)
1881 aResult.Divergence = 0.0; //! das ist gelogen
1883 return aResult;
1886 // XConsolidatable
1888 uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
1889 sal_Bool bEmpty ) throw(uno::RuntimeException, std::exception)
1891 SolarMutexGuard aGuard;
1892 ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
1893 if ( pDocShell && !bEmpty )
1895 ScDocument& rDoc = pDocShell->GetDocument();
1896 const ScConsolidateParam* pParam = rDoc.GetConsolidateDlgData();
1897 if (pParam)
1898 pNew->SetParam( *pParam );
1900 return pNew;
1903 void SAL_CALL ScModelObj::consolidate(
1904 const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
1905 throw (uno::RuntimeException, std::exception)
1907 SolarMutexGuard aGuard;
1908 // das koennte theoretisch ein fremdes Objekt sein, also nur das
1909 // oeffentliche XConsolidationDescriptor Interface benutzen, um
1910 // die Daten in ein ScConsolidationDescriptor Objekt zu kopieren:
1911 //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation?
1913 ScConsolidationDescriptor aImpl;
1914 aImpl.setFunction( xDescriptor->getFunction() );
1915 aImpl.setSources( xDescriptor->getSources() );
1916 aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
1917 aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
1918 aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
1919 aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
1921 if (pDocShell)
1923 const ScConsolidateParam& rParam = aImpl.GetParam();
1924 pDocShell->DoConsolidate( rParam, true );
1925 pDocShell->GetDocument().SetConsolidateDlgData( &rParam );
1929 // XDocumentAuditing
1931 void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException, std::exception)
1933 SolarMutexGuard aGuard;
1934 if (pDocShell)
1935 pDocShell->GetDocFunc().DetectiveRefresh();
1938 // XViewDataSupplier
1939 uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData( )
1940 throw (uno::RuntimeException, std::exception)
1942 uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
1944 if( !xRet.is() )
1946 SolarMutexGuard aGuard;
1947 if (pDocShell && pDocShell->GetCreateMode() == SfxObjectCreateMode::EMBEDDED)
1949 uno::Reference < container::XIndexContainer > xCont = document::IndexedPropertyValues::create( ::comphelper::getProcessComponentContext() );
1950 xRet.set( xCont, uno::UNO_QUERY_THROW );
1952 uno::Sequence< beans::PropertyValue > aSeq;
1953 aSeq.realloc(1);
1954 OUString sName;
1955 pDocShell->GetDocument().GetName( pDocShell->GetDocument().GetVisibleTab(), sName );
1956 OUString sOUName(sName);
1957 aSeq[0].Name = SC_ACTIVETABLE;
1958 aSeq[0].Value <<= sOUName;
1959 xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
1963 return xRet;
1966 // XPropertySet (Doc-Optionen)
1967 //! auch an der Applikation anbieten?
1969 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
1970 throw(uno::RuntimeException, std::exception)
1972 SolarMutexGuard aGuard;
1973 static uno::Reference<beans::XPropertySetInfo> aRef(
1974 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1975 return aRef;
1978 void SAL_CALL ScModelObj::setPropertyValue(
1979 const OUString& aPropertyName, const uno::Any& aValue )
1980 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1981 lang::IllegalArgumentException, lang::WrappedTargetException,
1982 uno::RuntimeException, std::exception)
1984 SolarMutexGuard aGuard;
1985 OUString aString(aPropertyName);
1987 if (pDocShell)
1989 ScDocument& rDoc = pDocShell->GetDocument();
1990 const ScDocOptions& rOldOpt = rDoc.GetDocOptions();
1991 ScDocOptions aNewOpt = rOldOpt;
1992 // Don't recalculate while loading XML, when the formula text is stored
1993 // Recalculation after loading is handled separately.
1994 bool bHardRecalc = !rDoc.IsImportingXML();
1996 bool bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropSet.getPropertyMap(), aPropertyName, aValue );
1997 if (bOpt)
1999 // done...
2000 if ( aString == SC_UNO_IGNORECASE ||
2001 aString == SC_UNONAME_REGEXP ||
2002 aString == SC_UNO_LOOKUPLABELS )
2003 bHardRecalc = false;
2005 else if ( aString == SC_UNONAME_CLOCAL )
2007 lang::Locale aLocale;
2008 if ( aValue >>= aLocale )
2010 LanguageType eLatin, eCjk, eCtl;
2011 rDoc.GetLanguage( eLatin, eCjk, eCtl );
2012 eLatin = ScUnoConversion::GetLanguage(aLocale);
2013 rDoc.SetLanguage( eLatin, eCjk, eCtl );
2016 else if ( aString == SC_UNO_CODENAME )
2018 OUString sCodeName;
2019 if ( aValue >>= sCodeName )
2020 rDoc.SetCodeName( sCodeName );
2022 else if ( aString == SC_UNO_CJK_CLOCAL )
2024 lang::Locale aLocale;
2025 if ( aValue >>= aLocale )
2027 LanguageType eLatin, eCjk, eCtl;
2028 rDoc.GetLanguage( eLatin, eCjk, eCtl );
2029 eCjk = ScUnoConversion::GetLanguage(aLocale);
2030 rDoc.SetLanguage( eLatin, eCjk, eCtl );
2033 else if ( aString == SC_UNO_CTL_CLOCAL )
2035 lang::Locale aLocale;
2036 if ( aValue >>= aLocale )
2038 LanguageType eLatin, eCjk, eCtl;
2039 rDoc.GetLanguage( eLatin, eCjk, eCtl );
2040 eCtl = ScUnoConversion::GetLanguage(aLocale);
2041 rDoc.SetLanguage( eLatin, eCjk, eCtl );
2044 else if ( aString == SC_UNO_APPLYFMDES )
2046 // model is created if not there
2047 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
2048 pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2050 SfxBindings* pBindings = pDocShell->GetViewBindings();
2051 if (pBindings)
2052 pBindings->Invalidate( SID_FM_OPEN_READONLY );
2054 else if ( aString == SC_UNO_AUTOCONTFOC )
2056 // model is created if not there
2057 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
2058 pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2060 SfxBindings* pBindings = pDocShell->GetViewBindings();
2061 if (pBindings)
2062 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
2064 else if ( aString == SC_UNO_ISLOADED )
2066 pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2068 else if ( aString == SC_UNO_ISUNDOENABLED )
2070 bool bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2071 rDoc.EnableUndo( bUndoEnabled );
2072 pDocShell->GetUndoManager()->SetMaxUndoActionCount(
2073 bUndoEnabled
2074 ? officecfg::Office::Common::Undo::Steps::get() : 0);
2076 else if ( aString == SC_UNO_RECORDCHANGES )
2078 bool bRecordChangesEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2080 bool bChangeAllowed = true;
2081 if (!bRecordChangesEnabled)
2082 bChangeAllowed = !pDocShell->HasChangeRecordProtection();
2084 if (bChangeAllowed)
2085 pDocShell->SetChangeRecording(bRecordChangesEnabled);
2087 else if ( aString == SC_UNO_ISADJUSTHEIGHTENABLED )
2089 bool bOldAdjustHeightEnabled = rDoc.IsAdjustHeightEnabled();
2090 bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2091 if( bOldAdjustHeightEnabled != bAdjustHeightEnabled )
2092 rDoc.EnableAdjustHeight( bAdjustHeightEnabled );
2094 else if ( aString == SC_UNO_ISEXECUTELINKENABLED )
2096 rDoc.EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2098 else if ( aString == SC_UNO_ISCHANGEREADONLYENABLED )
2100 rDoc.EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
2102 else if ( aString == "BuildId" )
2104 aValue >>= maBuildId;
2106 else if ( aString == "SavedObject" ) // set from chart after saving
2108 OUString aObjName;
2109 aValue >>= aObjName;
2110 if ( !aObjName.isEmpty() )
2111 rDoc.RestoreChartListener( aObjName );
2113 else if ( aString == SC_UNO_INTEROPGRABBAG )
2115 setGrabBagItem(aValue);
2118 if ( aNewOpt != rOldOpt )
2120 rDoc.SetDocOptions( aNewOpt );
2121 //! Recalc only for options that need it?
2122 if ( bHardRecalc )
2123 pDocShell->DoHardRecalc( true );
2124 pDocShell->SetDocumentModified();
2129 uno::Any SAL_CALL ScModelObj::getPropertyValue( const OUString& aPropertyName )
2130 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2131 uno::RuntimeException, std::exception)
2133 SolarMutexGuard aGuard;
2134 OUString aString(aPropertyName);
2135 uno::Any aRet;
2137 if (pDocShell)
2139 ScDocument& rDoc = pDocShell->GetDocument();
2140 const ScDocOptions& rOpt = rDoc.GetDocOptions();
2141 aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropSet.getPropertyMap(), aPropertyName );
2142 if ( aRet.hasValue() )
2144 // done...
2146 else if ( aString == SC_UNONAME_CLOCAL )
2148 LanguageType eLatin, eCjk, eCtl;
2149 rDoc.GetLanguage( eLatin, eCjk, eCtl );
2151 lang::Locale aLocale;
2152 ScUnoConversion::FillLocale( aLocale, eLatin );
2153 aRet <<= aLocale;
2155 else if ( aString == SC_UNO_CODENAME )
2157 OUString sCodeName = rDoc.GetCodeName();
2158 aRet <<= sCodeName;
2161 else if ( aString == SC_UNO_CJK_CLOCAL )
2163 LanguageType eLatin, eCjk, eCtl;
2164 rDoc.GetLanguage( eLatin, eCjk, eCtl );
2166 lang::Locale aLocale;
2167 ScUnoConversion::FillLocale( aLocale, eCjk );
2168 aRet <<= aLocale;
2170 else if ( aString == SC_UNO_CTL_CLOCAL )
2172 LanguageType eLatin, eCjk, eCtl;
2173 rDoc.GetLanguage( eLatin, eCjk, eCtl );
2175 lang::Locale aLocale;
2176 ScUnoConversion::FillLocale( aLocale, eCtl );
2177 aRet <<= aLocale;
2179 else if ( aString == SC_UNO_NAMEDRANGES )
2181 aRet <<= uno::Reference<sheet::XNamedRanges>(new ScGlobalNamedRangesObj( pDocShell ));
2183 else if ( aString == SC_UNO_DATABASERNG )
2185 aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
2187 else if ( aString == SC_UNO_UNNAMEDDBRNG )
2189 aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell));
2191 else if ( aString == SC_UNO_COLLABELRNG )
2193 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, true ));
2195 else if ( aString == SC_UNO_ROWLABELRNG )
2197 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, false ));
2199 else if ( aString == SC_UNO_AREALINKS )
2201 aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
2203 else if ( aString == SC_UNO_DDELINKS )
2205 aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
2207 else if ( aString == SC_UNO_EXTERNALDOCLINKS )
2209 aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
2211 else if ( aString == SC_UNO_SHEETLINKS )
2213 aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
2215 else if ( aString == SC_UNO_APPLYFMDES )
2217 // default for no model is TRUE
2218 ScDrawLayer* pModel = rDoc.GetDrawLayer();
2219 bool bOpenInDesign = pModel == nullptr || pModel->GetOpenInDesignMode();
2220 ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
2222 else if ( aString == SC_UNO_AUTOCONTFOC )
2224 // default for no model is FALSE
2225 ScDrawLayer* pModel = rDoc.GetDrawLayer();
2226 bool bAutoControlFocus = pModel && pModel->GetAutoControlFocus();
2227 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
2229 else if ( aString == SC_UNO_FORBIDDEN )
2231 aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
2233 else if ( aString == SC_UNO_HASDRAWPAGES )
2235 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument().GetDrawLayer() != 0) );
2237 else if ( aString == SC_UNO_BASICLIBRARIES )
2239 aRet <<= pDocShell->GetBasicContainer();
2241 else if ( aString == SC_UNO_DIALOGLIBRARIES )
2243 aRet <<= pDocShell->GetDialogContainer();
2245 else if ( aString == SC_UNO_VBAGLOBNAME )
2247 /* #i111553# This property provides the name of the constant that
2248 will be used to store this model in the global Basic manager.
2249 That constant will be equivalent to 'ThisComponent' but for
2250 each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
2251 constant can co-exist, as required by VBA. */
2252 aRet <<= OUString( "ThisExcelDoc" );
2254 else if ( aString == SC_UNO_RUNTIMEUID )
2256 aRet <<= getRuntimeUID();
2258 else if ( aString == SC_UNO_HASVALIDSIGNATURES )
2260 aRet <<= hasValidSignatures();
2262 else if ( aString == SC_UNO_ISLOADED )
2264 ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
2266 else if ( aString == SC_UNO_ISUNDOENABLED )
2268 ScUnoHelpFunctions::SetBoolInAny( aRet, rDoc.IsUndoEnabled() );
2270 else if ( aString == SC_UNO_RECORDCHANGES )
2272 ScUnoHelpFunctions::SetBoolInAny( aRet, pDocShell->IsChangeRecording() );
2274 else if ( aString == SC_UNO_ISRECORDCHANGESPROTECTED )
2276 ScUnoHelpFunctions::SetBoolInAny( aRet, pDocShell->HasChangeRecordProtection() );
2278 else if ( aString == SC_UNO_ISADJUSTHEIGHTENABLED )
2280 ScUnoHelpFunctions::SetBoolInAny( aRet, rDoc.IsAdjustHeightEnabled() );
2282 else if ( aString == SC_UNO_ISEXECUTELINKENABLED )
2284 ScUnoHelpFunctions::SetBoolInAny( aRet, rDoc.IsExecuteLinkEnabled() );
2286 else if ( aString == SC_UNO_ISCHANGEREADONLYENABLED )
2288 ScUnoHelpFunctions::SetBoolInAny( aRet, rDoc.IsChangeReadOnlyEnabled() );
2290 else if ( aString == SC_UNO_REFERENCEDEVICE )
2292 VCLXDevice* pXDev = new VCLXDevice();
2293 pXDev->SetOutputDevice( rDoc.GetRefDevice() );
2294 aRet <<= uno::Reference< awt::XDevice >( pXDev );
2296 else if ( aString == "BuildId" )
2298 aRet <<= maBuildId;
2300 else if ( aString == "InternalDocument" )
2302 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SfxObjectCreateMode::INTERNAL) );
2304 else if ( aString == SC_UNO_INTEROPGRABBAG )
2306 getGrabBagItem(aRet);
2310 return aRet;
2313 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
2315 // XMultiServiceFactory
2317 css::uno::Reference<css::uno::XInterface> ScModelObj::create(
2318 OUString const & aServiceSpecifier,
2319 css::uno::Sequence<css::uno::Any> const * arguments)
2321 uno::Reference<uno::XInterface> xRet;
2322 OUString aNameStr(aServiceSpecifier);
2323 sal_uInt16 nType = ScServiceProvider::GetProviderType(aNameStr);
2324 if ( nType != SC_SERVICE_INVALID )
2326 // drawing layer tables must be kept as long as the model is alive
2327 // return stored instance if already set
2328 switch ( nType )
2330 case SC_SERVICE_GRADTAB: xRet.set(xDrawGradTab); break;
2331 case SC_SERVICE_HATCHTAB: xRet.set(xDrawHatchTab); break;
2332 case SC_SERVICE_BITMAPTAB: xRet.set(xDrawBitmapTab); break;
2333 case SC_SERVICE_TRGRADTAB: xRet.set(xDrawTrGradTab); break;
2334 case SC_SERVICE_MARKERTAB: xRet.set(xDrawMarkerTab); break;
2335 case SC_SERVICE_DASHTAB: xRet.set(xDrawDashTab); break;
2336 case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv); break;
2337 case SC_SERVICE_VBAOBJECTPROVIDER: xRet.set(xObjProvider); break;
2340 // #i64497# If a chart is in a temporary document during clipoard paste,
2341 // there should be no data provider, so that own data is used
2342 bool bCreate =
2343 ! ( nType == SC_SERVICE_CHDATAPROV &&
2344 ( pDocShell->GetCreateMode() == SfxObjectCreateMode::INTERNAL ));
2345 // this should never happen, i.e. the temporary document should never be
2346 // loaded, because this unlinks the data
2347 OSL_ASSERT( bCreate );
2349 if ( !xRet.is() && bCreate )
2351 xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
2353 // store created instance
2354 switch ( nType )
2356 case SC_SERVICE_GRADTAB: xDrawGradTab.set(xRet); break;
2357 case SC_SERVICE_HATCHTAB: xDrawHatchTab.set(xRet); break;
2358 case SC_SERVICE_BITMAPTAB: xDrawBitmapTab.set(xRet); break;
2359 case SC_SERVICE_TRGRADTAB: xDrawTrGradTab.set(xRet); break;
2360 case SC_SERVICE_MARKERTAB: xDrawMarkerTab.set(xRet); break;
2361 case SC_SERVICE_DASHTAB: xDrawDashTab.set(xRet); break;
2362 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet); break;
2363 case SC_SERVICE_VBAOBJECTPROVIDER: xObjProvider.set(xRet); break;
2367 else
2369 // alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals,
2370 // da wird dann 'ne Exception geworfen, wenn's nicht passt...
2374 xRet = arguments == 0
2375 ? SvxFmMSFactory::createInstance(aServiceSpecifier)
2376 : SvxFmMSFactory::createInstanceWithArguments(
2377 aServiceSpecifier, *arguments);
2378 // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
2380 catch ( lang::ServiceNotRegisteredException & )
2384 // if the drawing factory created a shape, a ScShapeObj has to be used
2385 // to support own properties like ImageMap:
2387 uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
2388 if ( xShape.is() )
2390 xRet.clear(); // for aggregation, xShape must be the object's only ref
2391 new ScShapeObj( xShape ); // aggregates object and modifies xShape
2392 xRet.set(xShape);
2395 return xRet;
2398 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
2399 const OUString& aServiceSpecifier )
2400 throw(uno::Exception, uno::RuntimeException, std::exception)
2402 SolarMutexGuard aGuard;
2403 return create(aServiceSpecifier, 0);
2406 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments(
2407 const OUString& ServiceSpecifier,
2408 const uno::Sequence<uno::Any>& aArgs )
2409 throw(uno::Exception, uno::RuntimeException, std::exception)
2411 //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer?
2413 SolarMutexGuard aGuard;
2414 uno::Reference<uno::XInterface> xInt(create(ServiceSpecifier, &aArgs));
2416 if ( aArgs.getLength() )
2418 // used only for cell value binding so far - it can be initialized after creating
2420 uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
2421 if ( xInit.is() )
2422 xInit->initialize( aArgs );
2425 return xInt;
2428 uno::Sequence<OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
2429 throw(uno::RuntimeException, std::exception)
2431 SolarMutexGuard aGuard;
2433 //! warum sind die Parameter bei concatServiceNames nicht const ???
2434 //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
2435 //! SvxFmMSFactory::getAvailableServiceNames() );
2437 uno::Sequence<OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
2438 uno::Sequence<OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
2440 return concatServiceNames( aMyServices, aDrawServices );
2443 // XServiceInfo
2444 OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException, std::exception)
2446 return OUString( "ScModelObj" );
2447 /* // Matching the .component information:
2448 return OUString( "com.sun.star.comp.Calc.SpreadsheetDocument" );
2452 sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName )
2453 throw(uno::RuntimeException, std::exception)
2455 return cppu::supportsService(this, rServiceName);
2458 uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
2459 throw(uno::RuntimeException, std::exception)
2461 uno::Sequence<OUString> aRet(3);
2462 aRet[0] = SCMODELOBJ_SERVICE;
2463 aRet[1] = SCDOCSETTINGS_SERVICE;
2464 aRet[2] = SCDOC_SERVICE;
2465 return aRet;
2468 // XUnoTunnel
2470 sal_Int64 SAL_CALL ScModelObj::getSomething(
2471 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
2473 if ( rId.getLength() == 16 &&
2474 0 == memcmp( getUnoTunnelId().getConstArray(),
2475 rId.getConstArray(), 16 ) )
2477 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
2480 if ( rId.getLength() == 16 &&
2481 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
2482 rId.getConstArray(), 16 ) )
2484 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
2487 // aggregated number formats supplier has XUnoTunnel, too
2488 // interface from aggregated object must be obtained via queryAggregation
2490 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
2491 if ( nRet )
2492 return nRet;
2494 if ( GetFormatter().is() )
2496 const uno::Type& rTunnelType = cppu::UnoType<lang::XUnoTunnel>::get();
2497 uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
2498 if(aNumTunnel.getValueType() == rTunnelType)
2500 uno::Reference<lang::XUnoTunnel> xTunnelAgg(
2501 *static_cast<uno::Reference<lang::XUnoTunnel> const *>(aNumTunnel.getValue()));
2502 return xTunnelAgg->getSomething( rId );
2506 return 0;
2509 namespace
2511 class theScModelObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScModelObjUnoTunnelId> {};
2514 const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
2516 return theScModelObjUnoTunnelId::get().getSeq();
2519 ScModelObj* ScModelObj::getImplementation(const uno::Reference<uno::XInterface>& rObj)
2521 ScModelObj* pRet = NULL;
2522 uno::Reference<lang::XUnoTunnel> xUT(rObj, uno::UNO_QUERY);
2523 if (xUT.is())
2524 pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
2525 return pRet;
2528 // XChangesNotifier
2530 void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
2531 throw (uno::RuntimeException, std::exception)
2533 SolarMutexGuard aGuard;
2534 maChangesListeners.addInterface( aListener );
2537 void ScModelObj::removeChangesListener( const uno::Reference< util::XChangesListener >& aListener )
2538 throw (uno::RuntimeException, std::exception)
2540 SolarMutexGuard aGuard;
2541 maChangesListeners.removeInterface( aListener );
2544 bool ScModelObj::HasChangesListeners() const
2546 if ( maChangesListeners.getLength() > 0 )
2547 return true;
2549 // "change" event set in any sheet?
2550 return pDocShell && pDocShell->GetDocument().HasAnySheetEventScript(SC_SHEETEVENT_CHANGE);
2553 void ScModelObj::NotifyChanges( const OUString& rOperation, const ScRangeList& rRanges,
2554 const uno::Sequence< beans::PropertyValue >& rProperties )
2556 if ( pDocShell && HasChangesListeners() )
2558 util::ChangesEvent aEvent;
2559 aEvent.Source.set( static_cast< cppu::OWeakObject* >( this ) );
2560 aEvent.Base <<= aEvent.Source;
2562 size_t nRangeCount = rRanges.size();
2563 aEvent.Changes.realloc( static_cast< sal_Int32 >( nRangeCount ) );
2564 for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
2566 uno::Reference< table::XCellRange > xRangeObj;
2568 ScRange aRange( *rRanges[ nIndex ] );
2569 if ( aRange.aStart == aRange.aEnd )
2571 xRangeObj.set( new ScCellObj( pDocShell, aRange.aStart ) );
2573 else
2575 xRangeObj.set( new ScCellRangeObj( pDocShell, aRange ) );
2578 util::ElementChange& rChange = aEvent.Changes[ static_cast< sal_Int32 >( nIndex ) ];
2579 rChange.Accessor <<= rOperation;
2580 rChange.Element <<= rProperties;
2581 rChange.ReplacedElement <<= xRangeObj;
2584 ::cppu::OInterfaceIteratorHelper aIter( maChangesListeners );
2585 while ( aIter.hasMoreElements() )
2589 static_cast< util::XChangesListener* >( aIter.next() )->changesOccurred( aEvent );
2591 catch( uno::Exception& )
2597 // handle sheet events
2598 //! separate method with ScMarkData? Then change HasChangesListeners back.
2599 if ( rOperation == "cell-change" && pDocShell )
2601 ScMarkData aMarkData;
2602 aMarkData.MarkFromRangeList( rRanges, false );
2603 ScDocument& rDoc = pDocShell->GetDocument();
2604 SCTAB nTabCount = rDoc.GetTableCount();
2605 ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
2606 for (; itr != itrEnd && *itr < nTabCount; ++itr)
2608 SCTAB nTab = *itr;
2609 const ScSheetEvents* pEvents = rDoc.GetSheetEvents(nTab);
2610 if (pEvents)
2612 const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CHANGE);
2613 if (pScript)
2615 ScRangeList aTabRanges; // collect ranges on this sheet
2616 size_t nRangeCount = rRanges.size();
2617 for ( size_t nIndex = 0; nIndex < nRangeCount; ++nIndex )
2619 ScRange aRange( *rRanges[ nIndex ] );
2620 if ( aRange.aStart.Tab() == nTab )
2621 aTabRanges.Append( aRange );
2623 size_t nTabRangeCount = aTabRanges.size();
2624 if ( nTabRangeCount > 0 )
2626 uno::Reference<uno::XInterface> xTarget;
2627 if ( nTabRangeCount == 1 )
2629 ScRange aRange( *aTabRanges[ 0 ] );
2630 if ( aRange.aStart == aRange.aEnd )
2631 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellObj( pDocShell, aRange.aStart ) ) );
2632 else
2633 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangeObj( pDocShell, aRange ) ) );
2635 else
2636 xTarget.set( static_cast<cppu::OWeakObject*>( new ScCellRangesObj( pDocShell, aTabRanges ) ) );
2638 uno::Sequence<uno::Any> aParams(1);
2639 aParams[0] <<= xTarget;
2641 uno::Any aRet;
2642 uno::Sequence<sal_Int16> aOutArgsIndex;
2643 uno::Sequence<uno::Any> aOutArgs;
2645 /*ErrCode eRet =*/ pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
2653 void ScModelObj::HandleCalculateEvents()
2655 if (pDocShell)
2657 ScDocument& rDoc = pDocShell->GetDocument();
2658 // don't call events before the document is visible
2659 // (might also set a flag on SFX_EVENT_LOADFINISHED and only disable while loading)
2660 if ( rDoc.IsDocVisible() )
2662 SCTAB nTabCount = rDoc.GetTableCount();
2663 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
2665 if (rDoc.HasCalcNotification(nTab))
2667 if (const ScSheetEvents* pEvents = rDoc.GetSheetEvents( nTab ))
2669 if (const OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_CALCULATE))
2671 uno::Any aRet;
2672 uno::Sequence<uno::Any> aParams;
2673 uno::Sequence<sal_Int16> aOutArgsIndex;
2674 uno::Sequence<uno::Any> aOutArgs;
2675 pDocShell->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
2681 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( rDoc.GetVbaEventProcessor(), uno::UNO_SET_THROW );
2682 uno::Sequence< uno::Any > aArgs( 1 );
2683 aArgs[ 0 ] <<= nTab;
2684 xVbaEvents->processVbaEvent( ScSheetEvents::GetVbaSheetEventId( SC_SHEETEVENT_CALCULATE ), aArgs );
2686 catch( uno::Exception& )
2692 rDoc.ResetCalcNotifications();
2696 // XOpenCLSelection
2698 sal_Bool ScModelObj::isOpenCLEnabled()
2699 throw (uno::RuntimeException, std::exception)
2701 return officecfg::Office::Common::Misc::UseOpenCL::get();
2704 void ScModelObj::enableOpenCL(sal_Bool bEnable)
2705 throw (uno::RuntimeException, std::exception)
2707 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
2708 officecfg::Office::Common::Misc::UseOpenCL::set(bEnable, batch);
2709 batch->commit();
2711 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2712 if (bEnable)
2713 aConfig.setOpenCLConfigToDefault();
2714 ScInterpreter::SetGlobalConfig(aConfig);
2717 void ScModelObj::enableAutomaticDeviceSelection(sal_Bool bForce)
2718 throw (uno::RuntimeException, std::exception)
2720 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2721 aConfig.mbOpenCLAutoSelect = true;
2722 ScInterpreter::SetGlobalConfig(aConfig);
2723 ScFormulaOptions aOptions = SC_MOD()->GetFormulaOptions();
2724 aOptions.SetCalcConfig(aConfig);
2725 SC_MOD()->SetFormulaOptions(aOptions);
2726 #if !HAVE_FEATURE_OPENCL
2727 (void) bForce;
2728 #else
2729 sc::FormulaGroupInterpreter::switchOpenCLDevice(OUString(), true, bForce);
2730 #endif
2733 void ScModelObj::disableAutomaticDeviceSelection()
2734 throw (uno::RuntimeException, std::exception)
2736 ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig();
2737 aConfig.mbOpenCLAutoSelect = false;
2738 ScInterpreter::SetGlobalConfig(aConfig);
2739 ScFormulaOptions aOptions = SC_MOD()->GetFormulaOptions();
2740 aOptions.SetCalcConfig(aConfig);
2741 SC_MOD()->SetFormulaOptions(aOptions);
2744 void ScModelObj::selectOpenCLDevice( sal_Int32 nPlatform, sal_Int32 nDevice )
2745 throw (uno::RuntimeException, std::exception)
2747 if(nPlatform < 0 || nDevice < 0)
2748 throw uno::RuntimeException();
2750 #if !HAVE_FEATURE_OPENCL
2751 throw uno::RuntimeException();
2752 #else
2753 std::vector<OpenCLPlatformInfo> aPlatformInfo;
2754 sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
2755 if(size_t(nPlatform) >= aPlatformInfo.size())
2756 throw uno::RuntimeException();
2758 if(size_t(nDevice) >= aPlatformInfo[nPlatform].maDevices.size())
2759 throw uno::RuntimeException();
2761 OUString aDeviceString = aPlatformInfo[nPlatform].maVendor + " " + aPlatformInfo[nPlatform].maDevices[nDevice].maName;
2762 sc::FormulaGroupInterpreter::switchOpenCLDevice(aDeviceString, false);
2763 #endif
2766 sal_Int32 ScModelObj::getPlatformID()
2767 throw (uno::RuntimeException, std::exception)
2769 #if !HAVE_FEATURE_OPENCL
2770 return -1;
2771 #else
2772 sal_Int32 nPlatformId;
2773 sal_Int32 nDeviceId;
2774 sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId);
2775 return nPlatformId;
2776 #endif
2779 sal_Int32 ScModelObj::getDeviceID()
2780 throw (uno::RuntimeException, std::exception)
2782 #if !HAVE_FEATURE_OPENCL
2783 return -1;
2784 #else
2785 sal_Int32 nPlatformId;
2786 sal_Int32 nDeviceId;
2787 sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId);
2788 return nDeviceId;
2789 #endif
2792 uno::Sequence< sheet::opencl::OpenCLPlatform > ScModelObj::getOpenCLPlatforms()
2793 throw (uno::RuntimeException, std::exception)
2795 #if !HAVE_FEATURE_OPENCL
2796 return uno::Sequence<sheet::opencl::OpenCLPlatform>();
2797 #else
2798 std::vector<OpenCLPlatformInfo> aPlatformInfo;
2799 sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
2801 uno::Sequence<sheet::opencl::OpenCLPlatform> aRet(aPlatformInfo.size());
2802 for(size_t i = 0; i < aPlatformInfo.size(); ++i)
2804 aRet[i].Name = aPlatformInfo[i].maName;
2805 aRet[i].Vendor = aPlatformInfo[i].maVendor;
2807 aRet[i].Devices.realloc(aPlatformInfo[i].maDevices.size());
2808 for(size_t j = 0; j < aPlatformInfo[i].maDevices.size(); ++j)
2810 const OpenCLDeviceInfo& rDevice = aPlatformInfo[i].maDevices[j];
2811 aRet[i].Devices[j].Name = rDevice.maName;
2812 aRet[i].Devices[j].Vendor = rDevice.maVendor;
2813 aRet[i].Devices[j].Driver = rDevice.maDriver;
2817 return aRet;
2818 #endif
2821 namespace {
2823 void setOpcodeSubsetTest(bool bFlag)
2824 throw (uno::RuntimeException, std::exception)
2826 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
2827 officecfg::Office::Calc::Formula::Calculation::OpenCLSubsetOnly::set(bFlag, batch);
2828 batch->commit();
2833 void ScModelObj::enableOpcodeSubsetTest()
2834 throw (uno::RuntimeException, std::exception)
2836 setOpcodeSubsetTest(true);
2839 void ScModelObj::disableOpcodeSubsetTest()
2840 throw (uno::RuntimeException, std::exception)
2842 setOpcodeSubsetTest(false);
2845 sal_Bool ScModelObj::isOpcodeSubsetTested()
2846 throw (uno::RuntimeException, std::exception)
2848 return officecfg::Office::Calc::Formula::Calculation::OpenCLSubsetOnly::get();
2851 void ScModelObj::setFormulaCellNumberLimit( sal_Int32 number )
2852 throw (uno::RuntimeException, std::exception)
2854 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
2855 officecfg::Office::Calc::Formula::Calculation::OpenCLMinimumDataSize::set(number, batch);
2856 batch->commit();
2859 sal_Int32 ScModelObj::getFormulaCellNumberLimit()
2860 throw (uno::RuntimeException, std::exception)
2862 return officecfg::Office::Calc::Formula::Calculation::OpenCLMinimumDataSize::get().get();
2865 ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
2866 pDocShell( pDocSh )
2868 pDocShell->GetDocument().AddUnoObject(*this);
2871 ScDrawPagesObj::~ScDrawPagesObj()
2873 SolarMutexGuard g;
2875 if (pDocShell)
2876 pDocShell->GetDocument().RemoveUnoObject(*this);
2879 void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2881 // Referenz-Update interessiert hier nicht
2883 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
2884 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
2886 pDocShell = NULL; // ungueltig geworden
2890 uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2892 if (pDocShell)
2894 ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
2895 OSL_ENSURE(pDrawLayer,"kann Draw-Layer nicht anlegen");
2896 if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument().GetTableCount() )
2898 SdrPage* pPage = pDrawLayer->GetPage((sal_uInt16)nIndex);
2899 OSL_ENSURE(pPage,"Draw-Page nicht gefunden");
2900 if (pPage)
2902 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
2906 return NULL;
2909 // XDrawPages
2911 uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
2912 throw(uno::RuntimeException, std::exception)
2914 SolarMutexGuard aGuard;
2915 uno::Reference<drawing::XDrawPage> xRet;
2916 if (pDocShell)
2918 OUString aNewName;
2919 pDocShell->GetDocument().CreateValidTabName(aNewName);
2920 if ( pDocShell->GetDocFunc().InsertTable( static_cast<SCTAB>(nPos),
2921 aNewName, true, true ) )
2922 xRet.set(GetObjectByIndex_Impl( nPos ));
2924 return xRet;
2927 void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
2928 throw(uno::RuntimeException, std::exception)
2930 SolarMutexGuard aGuard;
2931 SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
2932 if ( pDocShell && pImp )
2934 SdrPage* pPage = pImp->GetSdrPage();
2935 if (pPage)
2937 SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
2938 pDocShell->GetDocFunc().DeleteTable( nPageNum, true, true );
2943 // XIndexAccess
2945 sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException, std::exception)
2947 SolarMutexGuard aGuard;
2948 if (pDocShell)
2949 return pDocShell->GetDocument().GetTableCount();
2950 return 0;
2953 uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
2954 throw(lang::IndexOutOfBoundsException,
2955 lang::WrappedTargetException, uno::RuntimeException, std::exception)
2957 SolarMutexGuard aGuard;
2958 uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
2959 if (xPage.is())
2960 return uno::makeAny(xPage);
2961 else
2962 throw lang::IndexOutOfBoundsException();
2965 uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException, std::exception)
2967 SolarMutexGuard aGuard;
2968 return cppu::UnoType<drawing::XDrawPage>::get();
2971 sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException, std::exception)
2973 SolarMutexGuard aGuard;
2974 return ( getCount() != 0 );
2977 ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
2978 pDocShell( pDocSh )
2980 pDocShell->GetDocument().AddUnoObject(*this);
2983 ScTableSheetsObj::~ScTableSheetsObj()
2985 SolarMutexGuard g;
2987 if (pDocShell)
2988 pDocShell->GetDocument().RemoveUnoObject(*this);
2991 void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2993 // Referenz-Update interessiert hier nicht
2995 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
2996 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
2998 pDocShell = NULL; // ungueltig geworden
3002 // XSpreadsheets
3004 ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
3006 if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument().GetTableCount() )
3007 return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
3009 return NULL;
3012 ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const OUString& aName) const
3014 if (pDocShell)
3016 SCTAB nIndex;
3017 if ( pDocShell->GetDocument().GetTable( aName, nIndex ) )
3018 return new ScTableSheetObj( pDocShell, nIndex );
3020 return NULL;
3023 void SAL_CALL ScTableSheetsObj::insertNewByName( const OUString& aName, sal_Int16 nPosition )
3024 throw(uno::RuntimeException, std::exception)
3026 SolarMutexGuard aGuard;
3027 bool bDone = false;
3028 if (pDocShell)
3030 OUString aNamStr(aName);
3031 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, true, true );
3033 if (!bDone)
3034 throw uno::RuntimeException(); // no other exceptions specified
3037 void SAL_CALL ScTableSheetsObj::moveByName( const OUString& aName, sal_Int16 nDestination )
3038 throw(uno::RuntimeException, std::exception)
3040 SolarMutexGuard aGuard;
3041 bool bDone = false;
3042 if (pDocShell)
3044 SCTAB nSource;
3045 if ( pDocShell->GetDocument().GetTable( aName, nSource ) )
3046 bDone = pDocShell->MoveTable( nSource, nDestination, false, true );
3048 if (!bDone)
3049 throw uno::RuntimeException(); // no other exceptions specified
3052 void SAL_CALL ScTableSheetsObj::copyByName( const OUString& aName,
3053 const OUString& aCopy, sal_Int16 nDestination )
3054 throw(uno::RuntimeException, std::exception)
3056 SolarMutexGuard aGuard;
3057 bool bDone = false;
3058 if (pDocShell)
3060 OUString aNewStr(aCopy);
3061 SCTAB nSource;
3062 if ( pDocShell->GetDocument().GetTable( aName, nSource ) )
3064 bDone = pDocShell->MoveTable( nSource, nDestination, true, true );
3065 if (bDone)
3067 // #i92477# any index past the last sheet means "append" in MoveTable
3068 SCTAB nResultTab = static_cast<SCTAB>(nDestination);
3069 SCTAB nTabCount = pDocShell->GetDocument().GetTableCount(); // count after copying
3070 if (nResultTab >= nTabCount)
3071 nResultTab = nTabCount - 1;
3073 bDone = pDocShell->GetDocFunc().RenameTable( nResultTab, aNewStr,
3074 true, true );
3078 if (!bDone)
3079 throw uno::RuntimeException(); // no other exceptions specified
3082 void SAL_CALL ScTableSheetsObj::insertByName( const OUString& aName, const uno::Any& aElement )
3083 throw(lang::IllegalArgumentException, container::ElementExistException,
3084 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3086 SolarMutexGuard aGuard;
3087 bool bDone = false;
3088 bool bIllArg = false;
3090 //! Type of aElement can be some specific interface instead of XInterface
3092 if ( pDocShell )
3094 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
3095 if ( xInterface.is() )
3097 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
3098 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
3100 ScDocument& rDoc = pDocShell->GetDocument();
3101 OUString aNamStr(aName);
3102 SCTAB nDummy;
3103 if ( rDoc.GetTable( aNamStr, nDummy ) )
3105 // name already exists
3106 throw container::ElementExistException();
3108 else
3110 SCTAB nPosition = rDoc.GetTableCount();
3111 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr,
3112 true, true );
3113 if (bDone)
3114 pSheetObj->InitInsertSheet( pDocShell, nPosition );
3115 // Dokument und neuen Range am Objekt setzen
3118 else
3119 bIllArg = true;
3121 else
3122 bIllArg = true;
3125 if (!bDone)
3127 if (bIllArg)
3128 throw lang::IllegalArgumentException();
3129 else
3130 throw uno::RuntimeException(); // ElementExistException is handled above
3134 void SAL_CALL ScTableSheetsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
3135 throw(lang::IllegalArgumentException, container::NoSuchElementException,
3136 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3138 SolarMutexGuard aGuard;
3139 bool bDone = false;
3140 bool bIllArg = false;
3142 //! Type of aElement can be some specific interface instead of XInterface
3144 if ( pDocShell )
3146 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
3147 if ( xInterface.is() )
3149 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
3150 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
3152 SCTAB nPosition;
3153 if ( pDocShell->GetDocument().GetTable( aName, nPosition ) )
3155 if ( pDocShell->GetDocFunc().DeleteTable( nPosition, true, true ) )
3157 // InsertTable kann jetzt eigentlich nicht schiefgehen...
3158 OUString aNamStr(aName);
3159 bDone = pDocShell->GetDocFunc().InsertTable( nPosition, aNamStr, true, true );
3160 if (bDone)
3161 pSheetObj->InitInsertSheet( pDocShell, nPosition );
3164 else
3166 // not found
3167 throw container::NoSuchElementException();
3170 else
3171 bIllArg = true;
3173 else
3174 bIllArg = true;
3177 if (!bDone)
3179 if (bIllArg)
3180 throw lang::IllegalArgumentException();
3181 else
3182 throw uno::RuntimeException(); // NoSuchElementException is handled above
3186 void SAL_CALL ScTableSheetsObj::removeByName( const OUString& aName )
3187 throw(container::NoSuchElementException,
3188 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3190 SolarMutexGuard aGuard;
3191 bool bDone = false;
3192 if (pDocShell)
3194 SCTAB nIndex;
3195 if ( pDocShell->GetDocument().GetTable( aName, nIndex ) )
3196 bDone = pDocShell->GetDocFunc().DeleteTable( nIndex, true, true );
3197 else // not found
3198 throw container::NoSuchElementException();
3201 if (!bDone)
3202 throw uno::RuntimeException(); // NoSuchElementException is handled above
3205 sal_Int32 ScTableSheetsObj::importSheet(
3206 const uno::Reference < sheet::XSpreadsheetDocument > & xDocSrc,
3207 const OUString& srcName, const sal_Int32 nDestPosition )
3208 throw( lang::IllegalArgumentException, lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
3210 //pDocShell is the destination
3211 ScDocument& rDocDest = pDocShell->GetDocument();
3213 // Source document docShell
3214 if ( !xDocSrc.is() )
3215 throw uno::RuntimeException();
3216 ScModelObj* pObj = ScModelObj::getImplementation(xDocSrc);
3217 ScDocShell* pDocShellSrc = static_cast<ScDocShell*>(pObj->GetEmbeddedObject());
3219 // SourceSheet Position and does srcName exists ?
3220 SCTAB nIndexSrc;
3221 if ( !pDocShellSrc->GetDocument().GetTable( srcName, nIndexSrc ) )
3222 throw lang::IllegalArgumentException();
3224 // Check the validity of destination index.
3225 SCTAB nCount = rDocDest.GetTableCount();
3226 SCTAB nIndexDest = static_cast<SCTAB>(nDestPosition);
3227 if (nIndexDest > nCount || nIndexDest < 0)
3228 throw lang::IndexOutOfBoundsException();
3230 // Transfert Tab
3231 bool bInsertNew = true;
3232 bool bNotifyAndPaint = true;
3233 pDocShell->TransferTab(
3234 *pDocShellSrc, nIndexSrc, nIndexDest, bInsertNew, bNotifyAndPaint );
3236 return nIndexDest;
3239 // XCellRangesAccess
3241 uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet )
3242 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
3244 SolarMutexGuard aGuard;
3245 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
3246 if (! xSheet.is())
3247 throw lang::IndexOutOfBoundsException();
3249 return xSheet->getCellByPosition(nColumn, nRow);
3252 uno::Reference< table::XCellRange > SAL_CALL ScTableSheetsObj::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom, sal_Int32 nSheet )
3253 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
3255 SolarMutexGuard aGuard;
3256 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((sal_uInt16)nSheet)));
3257 if (! xSheet.is())
3258 throw lang::IndexOutOfBoundsException();
3260 return xSheet->getCellRangeByPosition(nLeft, nTop, nRight, nBottom);
3263 uno::Sequence < uno::Reference< table::XCellRange > > SAL_CALL ScTableSheetsObj::getCellRangesByName( const OUString& aRange )
3264 throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
3266 SolarMutexGuard aGuard;
3267 uno::Sequence < uno::Reference < table::XCellRange > > xRet;
3269 ScRangeList aRangeList;
3270 ScDocument& rDoc = pDocShell->GetDocument();
3271 if (ScRangeStringConverter::GetRangeListFromString( aRangeList, aRange, &rDoc, ::formula::FormulaGrammar::CONV_OOO, ';' ))
3273 size_t nCount = aRangeList.size();
3274 if (nCount)
3276 xRet.realloc(nCount);
3277 for( size_t nIndex = 0; nIndex < nCount; nIndex++ )
3279 const ScRange* pRange = aRangeList[ nIndex ];
3280 if( pRange )
3281 xRet[nIndex] = new ScCellRangeObj(pDocShell, *pRange);
3284 else
3285 throw lang::IllegalArgumentException();
3287 else
3288 throw lang::IllegalArgumentException();
3289 return xRet;
3292 // XEnumerationAccess
3294 uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
3295 throw(uno::RuntimeException, std::exception)
3297 SolarMutexGuard aGuard;
3298 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.SpreadsheetsEnumeration"));
3301 // XIndexAccess
3303 sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException, std::exception)
3305 SolarMutexGuard aGuard;
3306 if (pDocShell)
3307 return pDocShell->GetDocument().GetTableCount();
3308 return 0;
3311 uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
3312 throw(lang::IndexOutOfBoundsException,
3313 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3315 SolarMutexGuard aGuard;
3316 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
3317 if (xSheet.is())
3318 return uno::makeAny(xSheet);
3319 else
3320 throw lang::IndexOutOfBoundsException();
3321 // return uno::Any();
3324 uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException, std::exception)
3326 SolarMutexGuard aGuard;
3327 return cppu::UnoType<sheet::XSpreadsheet>::get();
3330 sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException, std::exception)
3332 SolarMutexGuard aGuard;
3333 return ( getCount() != 0 );
3336 // XNameAccess
3338 uno::Any SAL_CALL ScTableSheetsObj::getByName( const OUString& aName )
3339 throw(container::NoSuchElementException,
3340 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3342 SolarMutexGuard aGuard;
3343 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
3344 if (xSheet.is())
3345 return uno::makeAny(xSheet);
3346 else
3347 throw container::NoSuchElementException();
3350 uno::Sequence<OUString> SAL_CALL ScTableSheetsObj::getElementNames()
3351 throw(uno::RuntimeException, std::exception)
3353 SolarMutexGuard aGuard;
3354 if (pDocShell)
3356 ScDocument& rDoc = pDocShell->GetDocument();
3357 SCTAB nCount = rDoc.GetTableCount();
3358 OUString aName;
3359 uno::Sequence<OUString> aSeq(nCount);
3360 OUString* pAry = aSeq.getArray();
3361 for (SCTAB i=0; i<nCount; i++)
3363 rDoc.GetName( i, aName );
3364 pAry[i] = aName;
3366 return aSeq;
3368 return uno::Sequence<OUString>();
3371 sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const OUString& aName )
3372 throw(uno::RuntimeException, std::exception)
3374 SolarMutexGuard aGuard;
3375 if (pDocShell)
3377 SCTAB nIndex;
3378 if ( pDocShell->GetDocument().GetTable( aName, nIndex ) )
3379 return sal_True;
3381 return false;
3384 ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
3385 pDocShell( pDocSh ),
3386 nTab ( nT ),
3387 nStartCol( nSC ),
3388 nEndCol ( nEC )
3390 pDocShell->GetDocument().AddUnoObject(*this);
3393 ScTableColumnsObj::~ScTableColumnsObj()
3395 SolarMutexGuard g;
3397 if (pDocShell)
3398 pDocShell->GetDocument().RemoveUnoObject(*this);
3401 void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3403 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
3405 //! Referenz-Update fuer Tab und Start/Ende
3407 else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) &&
3408 static_cast<const SfxSimpleHint&>(rHint).GetId() == SFX_HINT_DYING )
3410 pDocShell = NULL; // ungueltig geworden
3414 // XTableColumns
3416 ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
3418 SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
3419 if ( pDocShell && nCol <= nEndCol )
3420 return new ScTableColumnObj( pDocShell, nCol, nTab );
3422 return NULL; // falscher Index
3425 ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const OUString& aName) const
3427 SCCOL nCol = 0;
3428 OUString aString(aName);
3429 if ( ::AlphaToCol( nCol, aString) )
3430 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
3431 return new ScTableColumnObj( pDocShell, nCol, nTab );
3433 return NULL;
3436 void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
3437 throw(uno::RuntimeException, std::exception)
3439 SolarMutexGuard aGuard;
3440 bool bDone = false;
3441 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
3442 nStartCol+nPosition+nCount-1 <= MAXCOL )
3444 ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
3445 (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
3446 bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSCOLS, true, true );
3448 if (!bDone)
3449 throw uno::RuntimeException(); // no other exceptions specified
3452 void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
3453 throw(uno::RuntimeException, std::exception)
3455 SolarMutexGuard aGuard;
3456 bool bDone = false;
3457 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
3458 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
3460 ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
3461 (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
3462 bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELCOLS, true, true );
3464 if (!bDone)
3465 throw uno::RuntimeException(); // no other exceptions specified
3468 // XEnumerationAccess
3470 uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
3471 throw(uno::RuntimeException, std::exception)
3473 SolarMutexGuard aGuard;
3474 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableColumnsEnumeration"));
3477 // XIndexAccess
3479 sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException, std::exception)
3481 SolarMutexGuard aGuard;
3482 return nEndCol - nStartCol + 1;
3485 uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
3486 throw(lang::IndexOutOfBoundsException,
3487 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3489 SolarMutexGuard aGuard;
3490 uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
3491 if (xColumn.is())
3492 return uno::makeAny(xColumn);
3493 else
3494 throw lang::IndexOutOfBoundsException();
3497 uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException, std::exception)
3499 SolarMutexGuard aGuard;
3500 return cppu::UnoType<table::XCellRange>::get();
3503 sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException, std::exception)
3505 SolarMutexGuard aGuard;
3506 return ( getCount() != 0 );
3509 uno::Any SAL_CALL ScTableColumnsObj::getByName( const OUString& aName )
3510 throw(container::NoSuchElementException,
3511 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3513 SolarMutexGuard aGuard;
3514 uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
3515 if (xColumn.is())
3516 return uno::makeAny(xColumn);
3517 else
3518 throw container::NoSuchElementException();
3521 uno::Sequence<OUString> SAL_CALL ScTableColumnsObj::getElementNames()
3522 throw(uno::RuntimeException, std::exception)
3524 SolarMutexGuard aGuard;
3525 SCCOL nCount = nEndCol - nStartCol + 1;
3526 uno::Sequence<OUString> aSeq(nCount);
3527 OUString* pAry = aSeq.getArray();
3528 for (SCCOL i=0; i<nCount; i++)
3529 pAry[i] = ::ScColToAlpha( nStartCol + i );
3531 return aSeq;
3534 sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const OUString& aName )
3535 throw(uno::RuntimeException, std::exception)
3537 SolarMutexGuard aGuard;
3538 SCCOL nCol = 0;
3539 OUString aString(aName);
3540 if ( ::AlphaToCol( nCol, aString) )
3541 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
3542 return sal_True;
3544 return false; // nicht gefunden
3547 // XPropertySet
3549 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
3550 throw(uno::RuntimeException, std::exception)
3552 SolarMutexGuard aGuard;
3553 static uno::Reference<beans::XPropertySetInfo> aRef(
3554 new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
3555 return aRef;
3558 void SAL_CALL ScTableColumnsObj::setPropertyValue(
3559 const OUString& aPropertyName, const uno::Any& aValue )
3560 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3561 lang::IllegalArgumentException, lang::WrappedTargetException,
3562 uno::RuntimeException, std::exception)
3564 SolarMutexGuard aGuard;
3565 if (!pDocShell)
3566 throw uno::RuntimeException();
3568 std::vector<sc::ColRowSpan> aColArr(1, sc::ColRowSpan(nStartCol,nEndCol));
3569 OUString aNameString(aPropertyName);
3570 ScDocFunc& rFunc = pDocShell->GetDocFunc();
3572 if ( aNameString == SC_UNONAME_CELLWID )
3574 sal_Int32 nNewWidth = 0;
3575 if ( aValue >>= nNewWidth )
3576 rFunc.SetWidthOrHeight(
3577 true, aColArr, nTab, SC_SIZE_ORIGINAL, (sal_uInt16)HMMToTwips(nNewWidth), true, true);
3579 else if ( aNameString == SC_UNONAME_CELLVIS )
3581 bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3582 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
3583 rFunc.SetWidthOrHeight(true, aColArr, nTab, eMode, 0, true, true);
3584 // SC_SIZE_DIRECT with size 0: hide
3586 else if ( aNameString == SC_UNONAME_OWIDTH )
3588 bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3589 if (bOpt)
3590 rFunc.SetWidthOrHeight(
3591 true, aColArr, nTab, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, true, true);
3592 // sal_False for columns currently has no effect
3594 else if ( aNameString == SC_UNONAME_NEWPAGE || aNameString == SC_UNONAME_MANPAGE )
3596 //! single function to set/remove all breaks?
3597 bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3598 for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
3599 if (bSet)
3600 rFunc.InsertPageBreak( true, ScAddress(nCol,0,nTab), true, true, true );
3601 else
3602 rFunc.RemovePageBreak( true, ScAddress(nCol,0,nTab), true, true, true );
3606 uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const OUString& aPropertyName )
3607 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3608 uno::RuntimeException, std::exception)
3610 SolarMutexGuard aGuard;
3611 if (!pDocShell)
3612 throw uno::RuntimeException();
3614 ScDocument& rDoc = pDocShell->GetDocument();
3615 OUString aNameString(aPropertyName);
3616 uno::Any aAny;
3618 //! loop over all columns for current state?
3620 if ( aNameString == SC_UNONAME_CELLWID )
3622 // for hidden column, return original height
3623 sal_uInt16 nWidth = rDoc.GetOriginalWidth( nStartCol, nTab );
3624 aAny <<= (sal_Int32)TwipsToHMM(nWidth);
3626 else if ( aNameString == SC_UNONAME_CELLVIS )
3628 bool bVis = !rDoc.ColHidden(nStartCol, nTab);
3629 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3631 else if ( aNameString == SC_UNONAME_OWIDTH )
3633 bool bOpt = !(rDoc.GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE);
3634 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
3636 else if ( aNameString == SC_UNONAME_NEWPAGE )
3638 ScBreakType nBreak = rDoc.HasColBreak(nStartCol, nTab);
3639 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak != BREAK_NONE );
3641 else if ( aNameString == SC_UNONAME_MANPAGE )
3643 ScBreakType nBreak = rDoc.HasColBreak(nStartCol, nTab);
3644 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) != 0 );
3647 return aAny;
3650 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
3652 ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
3653 pDocShell( pDocSh ),
3654 nTab ( nT ),
3655 nStartRow( nSR ),
3656 nEndRow ( nER )
3658 pDocShell->GetDocument().AddUnoObject(*this);
3661 ScTableRowsObj::~ScTableRowsObj()
3663 SolarMutexGuard g;
3665 if (pDocShell)
3666 pDocShell->GetDocument().RemoveUnoObject(*this);
3669 void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3671 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
3673 //! Referenz-Update fuer Tab und Start/Ende
3675 else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) &&
3676 static_cast<const SfxSimpleHint&>(rHint).GetId() == SFX_HINT_DYING )
3678 pDocShell = NULL; // ungueltig geworden
3682 // XTableRows
3684 ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
3686 SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
3687 if ( pDocShell && nRow <= nEndRow )
3688 return new ScTableRowObj( pDocShell, nRow, nTab );
3690 return NULL; // falscher Index
3693 void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
3694 throw(uno::RuntimeException, std::exception)
3696 SolarMutexGuard aGuard;
3697 bool bDone = false;
3698 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
3699 nStartRow+nPosition+nCount-1 <= MAXROW )
3701 ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
3702 MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
3703 bDone = pDocShell->GetDocFunc().InsertCells( aRange, NULL, INS_INSROWS, true, true );
3705 if (!bDone)
3706 throw uno::RuntimeException(); // no other exceptions specified
3709 void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
3710 throw(uno::RuntimeException, std::exception)
3712 SolarMutexGuard aGuard;
3713 bool bDone = false;
3714 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
3715 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
3717 ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
3718 MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
3719 bDone = pDocShell->GetDocFunc().DeleteCells( aRange, NULL, DEL_DELROWS, true, true );
3721 if (!bDone)
3722 throw uno::RuntimeException(); // no other exceptions specified
3725 // XEnumerationAccess
3727 uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
3728 throw(uno::RuntimeException, std::exception)
3730 SolarMutexGuard aGuard;
3731 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableRowsEnumeration"));
3734 // XIndexAccess
3736 sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException, std::exception)
3738 SolarMutexGuard aGuard;
3739 return nEndRow - nStartRow + 1;
3742 uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
3743 throw(lang::IndexOutOfBoundsException,
3744 lang::WrappedTargetException, uno::RuntimeException, std::exception)
3746 SolarMutexGuard aGuard;
3747 uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
3748 if (xRow.is())
3749 return uno::makeAny(xRow);
3750 else
3751 throw lang::IndexOutOfBoundsException();
3754 uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException, std::exception)
3756 SolarMutexGuard aGuard;
3757 return cppu::UnoType<table::XCellRange>::get();
3760 sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException, std::exception)
3762 SolarMutexGuard aGuard;
3763 return ( getCount() != 0 );
3766 // XPropertySet
3768 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
3769 throw(uno::RuntimeException, std::exception)
3771 SolarMutexGuard aGuard;
3772 static uno::Reference<beans::XPropertySetInfo> aRef(
3773 new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
3774 return aRef;
3777 void SAL_CALL ScTableRowsObj::setPropertyValue(
3778 const OUString& aPropertyName, const uno::Any& aValue )
3779 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3780 lang::IllegalArgumentException, lang::WrappedTargetException,
3781 uno::RuntimeException, std::exception)
3783 SolarMutexGuard aGuard;
3784 if (!pDocShell)
3785 throw uno::RuntimeException();
3787 ScDocFunc& rFunc = pDocShell->GetDocFunc();
3788 ScDocument& rDoc = pDocShell->GetDocument();
3789 std::vector<sc::ColRowSpan> aRowArr(1, sc::ColRowSpan(nStartRow,nEndRow));
3790 OUString aNameString(aPropertyName);
3792 if ( aNameString == SC_UNONAME_OHEIGHT )
3794 sal_Int32 nNewHeight = 0;
3795 if ( rDoc.IsImportingXML() && ( aValue >>= nNewHeight ) )
3797 // used to set the stored row height for rows with optimal height when loading.
3799 // TODO: It's probably cleaner to use a different property name
3800 // for this.
3801 rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
3803 else
3805 bool bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3806 if (bOpt)
3807 rFunc.SetWidthOrHeight(false, aRowArr, nTab, SC_SIZE_OPTIMAL, 0, true, true);
3808 else
3810 //! manually set old heights again?
3814 else if ( aNameString == SC_UNONAME_CELLHGT )
3816 sal_Int32 nNewHeight = 0;
3817 if ( aValue >>= nNewHeight )
3819 if (rDoc.IsImportingXML())
3821 // TODO: This is a band-aid fix. Eventually we need to
3822 // re-work ods' style import to get it to set styles to
3823 // ScDocument directly.
3824 rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)HMMToTwips(nNewHeight) );
3825 rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true );
3827 else
3828 rFunc.SetWidthOrHeight(
3829 false, aRowArr, nTab, SC_SIZE_ORIGINAL, (sal_uInt16)HMMToTwips(nNewHeight), true, true);
3832 else if ( aNameString == SC_UNONAME_CELLVIS )
3834 bool bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3835 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
3836 rFunc.SetWidthOrHeight(false, aRowArr, nTab, eMode, 0, true, true);
3837 // SC_SIZE_DIRECT with size 0: hide
3839 else if ( aNameString == SC_UNONAME_VISFLAG )
3841 // #i116460# Shortcut to only set the flag, without drawing layer update etc.
3842 // Should only be used from import filters.
3843 rDoc.SetRowHidden(nStartRow, nEndRow, nTab, !ScUnoHelpFunctions::GetBoolFromAny( aValue ));
3845 else if ( aNameString == SC_UNONAME_CELLFILT )
3847 //! undo etc.
3848 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
3849 rDoc.SetRowFiltered(nStartRow, nEndRow, nTab, true);
3850 else
3851 rDoc.SetRowFiltered(nStartRow, nEndRow, nTab, false);
3853 else if ( aNameString == SC_UNONAME_NEWPAGE || aNameString == SC_UNONAME_MANPAGE )
3855 //! single function to set/remove all breaks?
3856 bool bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
3857 for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
3858 if (bSet)
3859 rFunc.InsertPageBreak( false, ScAddress(0,nRow,nTab), true, true, true );
3860 else
3861 rFunc.RemovePageBreak( false, ScAddress(0,nRow,nTab), true, true, true );
3863 else if ( aNameString == SC_UNONAME_CELLBACK || aNameString == SC_UNONAME_CELLTRAN )
3865 // #i57867# Background color is specified for row styles in the file format,
3866 // so it has to be supported along with the row properties (import only).
3868 // Use ScCellRangeObj to set the property for all cells in the rows
3869 // (this means, the "row attribute" must be set before individual cell attributes).
3871 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3872 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3873 xRangeObj->setPropertyValue( aPropertyName, aValue );
3877 uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const OUString& aPropertyName )
3878 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3879 uno::RuntimeException, std::exception)
3881 SolarMutexGuard aGuard;
3882 if (!pDocShell)
3883 throw uno::RuntimeException();
3885 ScDocument& rDoc = pDocShell->GetDocument();
3886 OUString aNameString(aPropertyName);
3887 uno::Any aAny;
3889 //! loop over all rows for current state?
3891 if ( aNameString == SC_UNONAME_CELLHGT )
3893 // for hidden row, return original height
3894 sal_uInt16 nHeight = rDoc.GetOriginalHeight( nStartRow, nTab );
3895 aAny <<= (sal_Int32)TwipsToHMM(nHeight);
3897 else if ( aNameString == SC_UNONAME_CELLVIS )
3899 SCROW nLastRow;
3900 bool bVis = !rDoc.RowHidden(nStartRow, nTab, NULL, &nLastRow);
3901 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3903 else if ( aNameString == SC_UNONAME_CELLFILT )
3905 bool bVis = rDoc.RowFiltered(nStartRow, nTab);
3906 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
3908 else if ( aNameString == SC_UNONAME_OHEIGHT )
3910 bool bOpt = !(rDoc.GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE);
3911 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
3913 else if ( aNameString == SC_UNONAME_NEWPAGE )
3915 ScBreakType nBreak = rDoc.HasRowBreak(nStartRow, nTab);
3916 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak != BREAK_NONE );
3918 else if ( aNameString == SC_UNONAME_MANPAGE )
3920 ScBreakType nBreak = rDoc.HasRowBreak(nStartRow, nTab);
3921 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) != 0 );
3923 else if ( aNameString == SC_UNONAME_CELLBACK || aNameString == SC_UNONAME_CELLTRAN )
3925 // Use ScCellRangeObj to get the property from the cell range
3926 // (for completeness only, this is not used by the XML filter).
3928 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3929 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3930 aAny = xRangeObj->getPropertyValue( aPropertyName );
3933 return aAny;
3936 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj )
3938 ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj()
3940 SolarMutexGuard g;
3942 if (pDocShell)
3943 pDocShell->GetDocument().RemoveUnoObject(*this);
3946 void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3948 // Referenz-Update interessiert hier nicht
3950 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
3951 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
3953 pDocShell = NULL; // ungueltig geworden
3957 // XPropertySet
3959 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo()
3960 throw(uno::RuntimeException, std::exception)
3962 //! muss noch
3963 return NULL;
3966 void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue(
3967 const OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
3968 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3969 lang::IllegalArgumentException, lang::WrappedTargetException,
3970 uno::RuntimeException, std::exception)
3972 //! muss noch
3975 uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const OUString& /* aPropertyName */ )
3976 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3977 uno::RuntimeException, std::exception)
3979 //! muss noch
3980 return uno::Any();
3983 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj )
3985 ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
3986 pDocShell( pDocSh ),
3987 nTab( nT )
3989 pDocShell->GetDocument().AddUnoObject(*this);
3992 ScAnnotationsObj::~ScAnnotationsObj()
3994 SolarMutexGuard g;
3996 if (pDocShell)
3997 pDocShell->GetDocument().RemoveUnoObject(*this);
4000 void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
4002 //! nTab bei Referenz-Update anpassen!!!
4004 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
4005 if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
4007 pDocShell = NULL; // ungueltig geworden
4011 bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
4013 if (!pDocShell)
4014 return false;
4016 ScDocument& rDoc = pDocShell->GetDocument();
4017 rPos = rDoc.GetNotePosition(nIndex, nTab);
4018 return rPos.IsValid();
4021 ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
4023 if (pDocShell)
4025 ScAddress aPos;
4026 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
4027 return new ScAnnotationObj( pDocShell, aPos );
4029 return NULL;
4032 // XSheetAnnotations
4034 void SAL_CALL ScAnnotationsObj::insertNew(
4035 const table::CellAddress& aPosition, const OUString& rText )
4036 throw(uno::RuntimeException, std::exception)
4038 SolarMutexGuard aGuard;
4039 if (pDocShell)
4041 OSL_ENSURE( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
4042 ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
4043 pDocShell->GetDocFunc().ReplaceNote( aPos, rText, 0, 0, true );
4047 void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException, std::exception)
4049 SolarMutexGuard aGuard;
4050 if (pDocShell)
4052 ScAddress aPos;
4053 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
4055 ScMarkData aMarkData;
4056 aMarkData.SelectTable( aPos.Tab(), true );
4057 aMarkData.SetMultiMarkArea( ScRange(aPos) );
4059 pDocShell->GetDocFunc().DeleteContents( aMarkData, IDF_NOTE, true, true );
4064 // XEnumerationAccess
4066 uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
4067 throw(uno::RuntimeException, std::exception)
4069 //! iterate directly (more efficiently)?
4071 SolarMutexGuard aGuard;
4072 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.CellAnnotationsEnumeration"));
4075 // XIndexAccess
4077 sal_Int32 SAL_CALL ScAnnotationsObj::getCount()
4078 throw(uno::RuntimeException, std::exception)
4080 SolarMutexGuard aGuard;
4081 sal_Int32 nCount = 0;
4082 if (pDocShell)
4084 ScDocument& rDoc = pDocShell->GetDocument();
4085 const ScRangeList aRangeList( ScRange( 0, 0, nTab, MAXCOL, MAXROW, nTab) );
4086 std::vector<sc::NoteEntry> rNotes;
4087 rDoc.GetNotesInRange(aRangeList, rNotes);
4088 nCount = rNotes.size();
4090 return nCount;
4093 uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
4094 throw(lang::IndexOutOfBoundsException,
4095 lang::WrappedTargetException, uno::RuntimeException, std::exception)
4097 SolarMutexGuard aGuard;
4098 uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
4099 if (xAnnotation.is())
4100 return uno::makeAny(xAnnotation);
4101 else
4102 throw lang::IndexOutOfBoundsException();
4105 uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException, std::exception)
4107 SolarMutexGuard aGuard;
4108 return cppu::UnoType<sheet::XSheetAnnotation>::get();
4111 sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException, std::exception)
4113 SolarMutexGuard aGuard;
4114 return ( getCount() != 0 );
4117 ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
4118 pDocShell( pDocSh ),
4119 nTab ( nT )
4121 pDocShell->GetDocument().AddUnoObject(*this);
4124 ScScenariosObj::~ScScenariosObj()
4126 SolarMutexGuard g;
4128 if (pDocShell)
4129 pDocShell->GetDocument().RemoveUnoObject(*this);
4132 void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
4134 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
4136 //! Referenz-Update fuer Tab und Start/Ende
4138 else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) &&
4139 static_cast<const SfxSimpleHint&>(rHint).GetId() == SFX_HINT_DYING )
4141 pDocShell = NULL; // ungueltig geworden
4145 // XScenarios
4147 bool ScScenariosObj::GetScenarioIndex_Impl( const OUString& rName, SCTAB& rIndex )
4149 //! Case-insensitiv ????
4151 if ( pDocShell )
4153 OUString aTabName;
4154 ScDocument& rDoc = pDocShell->GetDocument();
4155 SCTAB nCount = (SCTAB)getCount();
4156 for (SCTAB i=0; i<nCount; i++)
4157 if (rDoc.GetName( nTab+i+1, aTabName ))
4158 if (aTabName.equals(rName))
4160 rIndex = i;
4161 return true;
4165 return false;
4168 ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
4170 sal_uInt16 nCount = (sal_uInt16)getCount();
4171 if ( pDocShell && nIndex >= 0 && nIndex < nCount )
4172 return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
4174 return NULL; // kein Dokument oder falscher Index
4177 ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const OUString& aName)
4179 SCTAB nIndex;
4180 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
4181 return new ScTableSheetObj( pDocShell, nTab+nIndex+1 );
4183 return NULL; // nicht gefunden
4186 void SAL_CALL ScScenariosObj::addNewByName( const OUString& aName,
4187 const uno::Sequence<table::CellRangeAddress>& aRanges,
4188 const OUString& aComment )
4189 throw(uno::RuntimeException, std::exception)
4191 SolarMutexGuard aGuard;
4192 if ( pDocShell )
4194 ScMarkData aMarkData;
4195 aMarkData.SelectTable( nTab, true );
4197 sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
4198 if (nRangeCount)
4200 const table::CellRangeAddress* pAry = aRanges.getConstArray();
4201 for (sal_uInt16 i=0; i<nRangeCount; i++)
4203 OSL_ENSURE( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
4204 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
4205 (SCCOL)pAry[i].EndColumn, (SCROW)pAry[i].EndRow, nTab );
4207 aMarkData.SetMultiMarkArea( aRange );
4211 OUString aNameStr(aName);
4212 OUString aCommStr(aComment);
4214 Color aColor( COL_LIGHTGRAY ); // Default
4215 sal_uInt16 nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
4217 pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
4221 void SAL_CALL ScScenariosObj::removeByName( const OUString& aName )
4222 throw(uno::RuntimeException, std::exception)
4224 SolarMutexGuard aGuard;
4225 SCTAB nIndex;
4226 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
4227 pDocShell->GetDocFunc().DeleteTable( nTab+nIndex+1, true, true );
4230 // XEnumerationAccess
4232 uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
4233 throw(uno::RuntimeException, std::exception)
4235 SolarMutexGuard aGuard;
4236 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.ScenariosEnumeration"));
4239 // XIndexAccess
4241 sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException, std::exception)
4243 SolarMutexGuard aGuard;
4244 SCTAB nCount = 0;
4245 if ( pDocShell )
4247 ScDocument& rDoc = pDocShell->GetDocument();
4248 if (!rDoc.IsScenario(nTab))
4250 SCTAB nTabCount = rDoc.GetTableCount();
4251 SCTAB nNext = nTab + 1;
4252 while (nNext < nTabCount && rDoc.IsScenario(nNext))
4254 ++nCount;
4255 ++nNext;
4259 return nCount;
4262 uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
4263 throw(lang::IndexOutOfBoundsException,
4264 lang::WrappedTargetException, uno::RuntimeException, std::exception)
4266 SolarMutexGuard aGuard;
4267 uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
4268 if (xScen.is())
4269 return uno::makeAny(xScen);
4270 else
4271 throw lang::IndexOutOfBoundsException();
4274 uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException, std::exception)
4276 SolarMutexGuard aGuard;
4277 return cppu::UnoType<sheet::XScenario>::get();
4280 sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException, std::exception)
4282 SolarMutexGuard aGuard;
4283 return ( getCount() != 0 );
4286 uno::Any SAL_CALL ScScenariosObj::getByName( const OUString& aName )
4287 throw(container::NoSuchElementException,
4288 lang::WrappedTargetException, uno::RuntimeException, std::exception)
4290 SolarMutexGuard aGuard;
4291 uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
4292 if (xScen.is())
4293 return uno::makeAny(xScen);
4294 else
4295 throw container::NoSuchElementException();
4298 uno::Sequence<OUString> SAL_CALL ScScenariosObj::getElementNames()
4299 throw(uno::RuntimeException, std::exception)
4301 SolarMutexGuard aGuard;
4302 SCTAB nCount = (SCTAB)getCount();
4303 uno::Sequence<OUString> aSeq(nCount);
4305 if ( pDocShell ) // sonst ist auch Count = 0
4307 OUString aTabName;
4308 ScDocument& rDoc = pDocShell->GetDocument();
4309 OUString* pAry = aSeq.getArray();
4310 for (SCTAB i=0; i<nCount; i++)
4311 if (rDoc.GetName( nTab+i+1, aTabName ))
4312 pAry[i] = aTabName;
4315 return aSeq;
4318 sal_Bool SAL_CALL ScScenariosObj::hasByName( const OUString& aName )
4319 throw(uno::RuntimeException, std::exception)
4321 SolarMutexGuard aGuard;
4322 SCTAB nIndex;
4323 return GetScenarioIndex_Impl( aName, nIndex );
4326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */