sync master with lastest vba changes
[ooovba.git] / sc / source / ui / unoobj / docuno.cxx
blobaf7864808bdac0952cd13d82f8519891c7610292
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docuno.cxx,v $
10 * $Revision: 1.68.52.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "scitems.hxx"
37 #include <svx/fmdpage.hxx>
38 #include <svx/fmview.hxx>
39 #include <svx/svditer.hxx>
40 #include <svx/svdpage.hxx>
41 #include <svx/svxids.hrc>
43 #include <svtools/numuno.hxx>
44 #include <svtools/smplhint.hxx>
45 #include <svtools/undoopt.hxx>
46 #include <sfx2/printer.hxx>
47 #include <sfx2/bindings.hxx>
48 #include <vcl/pdfextoutdevdata.hxx>
49 #include <vcl/waitobj.hxx>
50 #include <unotools/charclass.hxx>
51 #include <tools/multisel.hxx>
52 #include <toolkit/awt/vclxdevice.hxx>
53 #include <ctype.h>
54 #include <float.h> // DBL_MAX
56 #include <com/sun/star/util/Date.hpp>
57 #include <com/sun/star/sheet/XNamedRanges.hpp>
58 #include <com/sun/star/sheet/XLabelRanges.hpp>
59 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
60 #include <com/sun/star/script/XLibraryContainer.hpp>
61 #include <com/sun/star/lang/XInitialization.hpp>
62 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
63 #include <comphelper/processfactory.hxx>
65 #include "docuno.hxx"
66 #include "cellsuno.hxx"
67 #include "nameuno.hxx"
68 #include "datauno.hxx"
69 #include "miscuno.hxx"
70 #include "notesuno.hxx"
71 #include "styleuno.hxx"
72 #include "linkuno.hxx"
73 #include "servuno.hxx"
74 #include "targuno.hxx"
75 #include "convuno.hxx"
76 #include "optuno.hxx"
77 #include "forbiuno.hxx"
78 #include "docsh.hxx"
79 #include "hints.hxx"
80 #include "docfunc.hxx"
81 #include "dociter.hxx"
82 #include "cell.hxx"
83 #include "drwlayer.hxx"
84 #include "rangeutl.hxx"
85 #include "markdata.hxx"
86 #include "docoptio.hxx"
87 #include "unoguard.hxx"
88 #include "unonames.hxx"
89 #include "shapeuno.hxx"
90 #include "printfun.hxx"
91 #include "pfuncache.hxx"
92 #include "scmod.hxx"
93 #include "rangeutl.hxx"
94 #include "ViewSettingsSequenceDefines.hxx"
96 #ifndef _SVX_UNOSHAPE_HXX
97 #include <svx/unoshape.hxx>
98 #endif
100 #include <com/sun/star/document/XVbaEventsHelper.hpp>
101 #include <com/sun/star/document/VbaEventId.hpp>
102 using namespace com::sun::star;
103 using namespace com::sun::star::document::VbaEventId;
105 //------------------------------------------------------------------------
107 // alles ohne Which-ID, Map nur fuer PropertySetInfo
109 //! umbenennen, sind nicht mehr nur Options
110 const SfxItemPropertyMap* lcl_GetDocOptPropertyMap()
112 static SfxItemPropertyMap aDocOptPropertyMap_Impl[] =
114 {MAP_CHAR_LEN(SC_UNO_APPLYFMDES), 0, &getBooleanCppuType(), 0, 0},
115 {MAP_CHAR_LEN(SC_UNO_AREALINKS), 0, &getCppuType((uno::Reference<sheet::XAreaLinks>*)0), 0, 0},
116 {MAP_CHAR_LEN(SC_UNO_AUTOCONTFOC), 0, &getBooleanCppuType(), 0, 0},
117 {MAP_CHAR_LEN(SC_UNO_BASICLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
118 {MAP_CHAR_LEN(SC_UNO_DIALOGLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
119 {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), 0, &getBooleanCppuType(), 0, 0},
120 {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
121 {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
122 {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
123 {MAP_CHAR_LEN(SC_UNO_COLLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0, 0},
124 {MAP_CHAR_LEN(SC_UNO_DDELINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
125 {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), 0, &getCppuType((sal_Int16*)0), 0, 0},
126 {MAP_CHAR_LEN(SC_UNO_EXTERNALDOCLINKS), 0, &getCppuType((uno::Reference<sheet::XExternalDocLinks>*)0), 0, 0},
127 {MAP_CHAR_LEN(SC_UNO_FORBIDDEN), 0, &getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0), beans::PropertyAttribute::READONLY, 0},
128 {MAP_CHAR_LEN(SC_UNO_HASDRAWPAGES), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
129 {MAP_CHAR_LEN(SC_UNO_IGNORECASE), 0, &getBooleanCppuType(), 0, 0},
130 {MAP_CHAR_LEN(SC_UNO_ITERENABLED), 0, &getBooleanCppuType(), 0, 0},
131 {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), 0, &getCppuType((sal_Int32*)0), 0, 0},
132 {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), 0, &getCppuType((double*)0), 0, 0},
133 {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), 0, &getBooleanCppuType(), 0, 0},
134 {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), 0, &getBooleanCppuType(), 0, 0},
135 {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES), 0, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0), 0, 0},
136 {MAP_CHAR_LEN(SC_UNO_DATABASERNG), 0, &getCppuType((uno::Reference<sheet::XDatabaseRanges>*)0), 0, 0},
137 {MAP_CHAR_LEN(SC_UNO_NULLDATE), 0, &getCppuType((util::Date*)0), 0, 0},
138 {MAP_CHAR_LEN(SC_UNO_ROWLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0, 0},
139 {MAP_CHAR_LEN(SC_UNO_SHEETLINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
140 {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), 0, &getBooleanCppuType(), 0, 0},
141 {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), 0, &getCppuType((sal_Int16*)0), 0, 0},
142 {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), 0, &getBooleanCppuType(), 0, 0},
143 {MAP_CHAR_LEN(SC_UNO_RUNTIMEUID), 0, &getCppuType(static_cast< const rtl::OUString * >(0)), beans::PropertyAttribute::READONLY, 0},
144 {MAP_CHAR_LEN(SC_UNO_HASVALIDSIGNATURES),0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
145 {MAP_CHAR_LEN(SC_UNO_ISLOADED), 0, &getBooleanCppuType(), 0, 0},
146 {MAP_CHAR_LEN(SC_UNO_ISUNDOENABLED), 0, &getBooleanCppuType(), 0, 0},
147 {MAP_CHAR_LEN(SC_UNO_ISADJUSTHEIGHTENABLED), 0, &getBooleanCppuType(), 0, 0},
148 {MAP_CHAR_LEN(SC_UNO_ISEXECUTELINKENABLED), 0, &getBooleanCppuType(), 0, 0},
149 {MAP_CHAR_LEN(SC_UNO_ISCHANGEREADONLYENABLED), 0, &getBooleanCppuType(), 0, 0},
150 {MAP_CHAR_LEN(SC_UNO_REFERENCEDEVICE), 0, &getCppuType((uno::Reference<awt::XDevice>*)0), beans::PropertyAttribute::READONLY, 0},
151 {MAP_CHAR_LEN("BuildId"), 0, &::getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0},
153 {0,0,0,0,0,0}
155 return aDocOptPropertyMap_Impl;
158 //! StandardDecimals als Property und vom NumberFormatter ????????
160 const SfxItemPropertyMap* lcl_GetColumnsPropertyMap()
162 static SfxItemPropertyMap aColumnsPropertyMap_Impl[] =
164 {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 },
165 {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 },
166 {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 },
167 {MAP_CHAR_LEN(SC_UNONAME_OWIDTH), 0, &getBooleanCppuType(), 0, 0 },
168 {MAP_CHAR_LEN(SC_UNONAME_CELLWID), 0, &getCppuType((sal_Int32*)0), 0, 0 },
169 {0,0,0,0,0,0}
171 return aColumnsPropertyMap_Impl;
174 const SfxItemPropertyMap* lcl_GetRowsPropertyMap()
176 static SfxItemPropertyMap aRowsPropertyMap_Impl[] =
178 {MAP_CHAR_LEN(SC_UNONAME_CELLHGT), 0, &getCppuType((sal_Int32*)0), 0, 0 },
179 {MAP_CHAR_LEN(SC_UNONAME_CELLFILT), 0, &getBooleanCppuType(), 0, 0 },
180 {MAP_CHAR_LEN(SC_UNONAME_OHEIGHT), 0, &getBooleanCppuType(), 0, 0 },
181 {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 },
182 {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 },
183 {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 },
184 {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR },
185 {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT },
186 // not sorted, not used with SfxItemPropertyMap::GetByName
187 {0,0,0,0,0,0}
189 return aRowsPropertyMap_Impl;
192 //! move these functions to a header file
193 inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; }
194 inline long HMMToTwips(long nHMM) { return (nHMM * 72 + 63) / 127; }
196 //------------------------------------------------------------------------
198 #define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument"
199 #define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings"
200 #define SCDOC_SERVICE "com.sun.star.document.OfficeDocument"
202 SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
203 SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
204 SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" )
205 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" )
206 SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" )
207 SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" )
208 SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" )
210 //------------------------------------------------------------------------
212 // static
213 void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
215 if (pDocSh)
216 pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
219 ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
220 SfxBaseModel( pDocSh ),
221 aPropSet( lcl_GetDocOptPropertyMap() ),
222 pDocShell( pDocSh ),
223 pPrintFuncCache( NULL ),
224 maChangesListeners( m_aMutex )
226 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
227 if ( pDocShell )
229 pDocShell->GetDocument()->AddUnoObject(*this); // SfxModel is derived from SfxListener
231 // setDelegator veraendert den RefCount, darum eine Referenz selber halten
232 // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen)
233 comphelper::increment( m_refCount );
235 // waehrend des queryInterface braucht man ein Ref auf das
236 // SvNumberFormatsSupplierObj, sonst wird es geloescht.
237 uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(
238 pDocShell->GetDocument()->GetFormatTable() ));
240 xNumberAgg.set(uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ));
241 // extra block to force deletion of the temporary before setDelegator
244 // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren
245 xFormatter = NULL;
247 if (xNumberAgg.is())
248 xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
250 comphelper::decrement( m_refCount );
254 ScModelObj::~ScModelObj()
256 if (pDocShell)
257 pDocShell->GetDocument()->RemoveUnoObject(*this);
259 if (xNumberAgg.is())
260 xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
262 delete pPrintFuncCache;
265 ScDocument* ScModelObj::GetDocument() const
267 if (pDocShell)
268 return pDocShell->GetDocument();
269 return NULL;
272 SfxObjectShell* ScModelObj::GetEmbeddedObject() const
274 return pDocShell;
277 void ScModelObj::UpdateAllRowHeights()
279 if (pDocShell)
280 pDocShell->UpdateAllRowHeights();
283 ScDrawLayer* ScModelObj::MakeDrawLayer()
285 if (pDocShell)
286 return pDocShell->MakeDrawLayer();
287 return NULL;
290 void ScModelObj::BeforeXMLLoading()
292 if (pDocShell)
293 pDocShell->BeforeXMLLoading();
296 void ScModelObj::AfterXMLLoading(sal_Bool bRet)
298 if (pDocShell)
299 pDocShell->AfterXMLLoading(bRet);
302 uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
303 throw(uno::RuntimeException)
305 SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
306 SC_QUERYINTERFACE( document::XActionLockable )
307 SC_QUERYINTERFACE( sheet::XCalculatable )
308 SC_QUERYINTERFACE( util::XProtectable )
309 SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
310 SC_QUERYINTERFACE( sheet::XGoalSeek )
311 SC_QUERYINTERFACE( sheet::XConsolidatable )
312 SC_QUERYINTERFACE( sheet::XDocumentAuditing )
313 SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
314 SC_QUERYINTERFACE( view::XRenderable )
315 SC_QUERYINTERFACE( document::XLinkTargetSupplier )
316 SC_QUERYINTERFACE( beans::XPropertySet )
317 SC_QUERYINTERFACE( document::XDocumentEventCompatibleHelper)
318 SC_QUERYINTERFACE( lang::XMultiServiceFactory )
319 SC_QUERYINTERFACE( lang::XServiceInfo )
320 SC_QUERYINTERFACE( util::XChangesNotifier )
322 uno::Any aRet(SfxBaseModel::queryInterface( rType ));
323 if ( !aRet.hasValue() && xNumberAgg.is() )
324 aRet = xNumberAgg->queryAggregation( rType );
326 return aRet;
329 void SAL_CALL ScModelObj::acquire() throw()
331 SfxBaseModel::acquire();
334 void SAL_CALL ScModelObj::release() throw()
336 SfxBaseModel::release();
339 uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException)
341 static uno::Sequence<uno::Type> aTypes;
342 if ( aTypes.getLength() == 0 )
344 uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
345 long nParentLen = aParentTypes.getLength();
346 const uno::Type* pParentPtr = aParentTypes.getConstArray();
348 uno::Sequence<uno::Type> aAggTypes;
349 if ( xNumberAgg.is() )
351 const uno::Type& rProvType = ::getCppuType((uno::Reference<lang::XTypeProvider>*) 0);
352 uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
353 if(aNumProv.getValueType() == rProvType)
355 uno::Reference<lang::XTypeProvider> xNumProv(
356 *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue());
357 aAggTypes = xNumProv->getTypes();
360 long nAggLen = aAggTypes.getLength();
361 const uno::Type* pAggPtr = aAggTypes.getConstArray();
363 const long nThisLen = 15;
364 aTypes.realloc( nParentLen + nAggLen + nThisLen );
365 uno::Type* pPtr = aTypes.getArray();
366 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetDocument>*)0);
367 pPtr[nParentLen + 1] = getCppuType((const uno::Reference<document::XActionLockable>*)0);
368 pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XCalculatable>*)0);
369 pPtr[nParentLen + 3] = getCppuType((const uno::Reference<util::XProtectable>*)0);
370 pPtr[nParentLen + 4] = getCppuType((const uno::Reference<drawing::XDrawPagesSupplier>*)0);
371 pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XGoalSeek>*)0);
372 pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XConsolidatable>*)0);
373 pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XDocumentAuditing>*)0);
374 pPtr[nParentLen + 8] = getCppuType((const uno::Reference<style::XStyleFamiliesSupplier>*)0);
375 pPtr[nParentLen + 9] = getCppuType((const uno::Reference<view::XRenderable>*)0);
376 pPtr[nParentLen +10] = getCppuType((const uno::Reference<document::XLinkTargetSupplier>*)0);
377 pPtr[nParentLen +11] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
378 pPtr[nParentLen +12] = getCppuType((const uno::Reference<lang::XMultiServiceFactory>*)0);
379 pPtr[nParentLen +13] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
380 pPtr[nParentLen +14] = getCppuType((const uno::Reference<util::XChangesNotifier>*)0);
382 long i;
383 for (i=0; i<nParentLen; i++)
384 pPtr[i] = pParentPtr[i]; // parent types first
386 for (i=0; i<nAggLen; i++)
387 pPtr[nParentLen+nThisLen+i] = pAggPtr[i]; // aggregated types last
389 return aTypes;
392 uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId()
393 throw(uno::RuntimeException)
395 static uno::Sequence< sal_Int8 > aId;
396 if( aId.getLength() == 0 )
398 aId.realloc( 16 );
399 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
401 return aId;
404 void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
406 // Not interested in reference update hints here
408 if ( rHint.ISA( SfxSimpleHint ) )
410 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
411 if ( nId == SFX_HINT_DYING )
413 pDocShell = NULL; // has become invalid
414 if (xNumberAgg.is())
416 SvNumberFormatsSupplierObj* pNumFmt =
417 SvNumberFormatsSupplierObj::getImplementation(
418 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
419 if ( pNumFmt )
420 pNumFmt->SetNumberFormatter( NULL );
423 DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell
425 else if ( nId == SFX_HINT_DATACHANGED )
427 // cached data for rendering become invalid when contents change
428 // (if a broadcast is added to SetDrawModified, is has to be tested here, too)
430 DELETEZ( pPrintFuncCache );
433 else if ( rHint.ISA( ScPointerChangedHint ) )
435 USHORT nFlags = ((const ScPointerChangedHint&)rHint).GetFlags();
436 if (nFlags & SC_POINTERCHANGED_NUMFMT)
438 // NumberFormatter-Pointer am Uno-Objekt neu setzen
440 if (xNumberAgg.is())
442 SvNumberFormatsSupplierObj* pNumFmt =
443 SvNumberFormatsSupplierObj::getImplementation(
444 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
445 if ( pNumFmt && pDocShell )
446 pNumFmt->SetNumberFormatter( pDocShell->GetDocument()->GetFormatTable() );
451 // always call parent - SfxBaseModel might need to handle the same hints again
452 SfxBaseModel::Notify( rBC, rHint ); // SfxBaseModel is derived from SfxListener
455 // XSpreadsheetDocument
457 uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException)
459 ScUnoGuard aGuard;
460 if (pDocShell)
461 return new ScTableSheetsObj(pDocShell);
462 return NULL;
465 // XStyleFamiliesSupplier
467 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
468 throw(uno::RuntimeException)
470 ScUnoGuard aGuard;
471 if (pDocShell)
472 return new ScStyleFamiliesObj(pDocShell);
473 return NULL;
476 // XRenderable
478 OutputDevice* lcl_GetRenderDevice( const uno::Sequence<beans::PropertyValue>& rOptions )
480 OutputDevice* pRet = NULL;
481 const beans::PropertyValue* pPropArray = rOptions.getConstArray();
482 long nPropCount = rOptions.getLength();
483 for (long i = 0; i < nPropCount; i++)
485 const beans::PropertyValue& rProp = pPropArray[i];
486 String aPropName(rProp.Name);
488 if (aPropName.EqualsAscii( SC_UNONAME_RENDERDEV ))
490 uno::Reference<awt::XDevice> xRenderDevice(rProp.Value, uno::UNO_QUERY);
491 if ( xRenderDevice.is() )
493 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
494 if ( pDevice )
496 pRet = pDevice->GetOutputDevice();
497 pRet->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
502 return pRet;
505 bool lcl_ParseTarget( const String& rTarget, ScRange& rTargetRange, Rectangle& rTargetRect,
506 bool& rIsSheet, ScDocument* pDoc, SCTAB nSourceTab )
508 // test in same order as in SID_CURRENTCELL execute
510 ScAddress aAddress;
511 ScRangeUtil aRangeUtil;
512 SCTAB nNameTab;
513 sal_Int32 nNumeric = 0;
515 bool bRangeValid = false;
516 bool bRectValid = false;
518 if ( rTargetRange.Parse( rTarget, pDoc ) & SCA_VALID )
520 bRangeValid = true; // range reference
522 else if ( aAddress.Parse( rTarget, pDoc ) & SCA_VALID )
524 rTargetRange = aAddress;
525 bRangeValid = true; // cell reference
527 else if ( aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_NAMES ) ||
528 aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_DBASE ) )
530 bRangeValid = true; // named range or database range
532 else if ( ByteString( rTarget, RTL_TEXTENCODING_ASCII_US ).IsNumericAscii() &&
533 ( nNumeric = rTarget.ToInt32() ) > 0 && nNumeric <= MAXROW+1 )
535 // row number is always mapped to cell A(row) on the same sheet
536 rTargetRange = ScAddress( 0, (SCROW)(nNumeric-1), nSourceTab ); // target row number is 1-based
537 bRangeValid = true; // row number
539 else if ( pDoc->GetTable( rTarget, nNameTab ) )
541 rTargetRange = ScAddress(0,0,nNameTab);
542 bRangeValid = true; // sheet name
543 rIsSheet = true; // needs special handling (first page of the sheet)
545 else
547 // look for named drawing object
549 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
550 if ( pDrawLayer )
552 SCTAB nTabCount = pDoc->GetTableCount();
553 for (SCTAB i=0; i<nTabCount && !bRangeValid; i++)
555 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
556 DBG_ASSERT(pPage,"Page ?");
557 if (pPage)
559 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
560 SdrObject* pObject = aIter.Next();
561 while (pObject && !bRangeValid)
563 if ( ScDrawLayer::GetVisibleName( pObject ) == rTarget )
565 rTargetRect = pObject->GetLogicRect(); // 1/100th mm
566 rTargetRange = pDoc->GetRange( i, rTargetRect ); // underlying cells
567 bRangeValid = bRectValid = true; // rectangle is valid
569 pObject = aIter.Next();
575 if ( bRangeValid && !bRectValid )
577 // get rectangle for cell range
578 rTargetRect = pDoc->GetMMRect( rTargetRange.aStart.Col(), rTargetRange.aStart.Row(),
579 rTargetRange.aEnd.Col(), rTargetRange.aEnd.Row(),
580 rTargetRange.aStart.Tab() );
583 return bRangeValid;
586 BOOL ScModelObj::FillRenderMarkData( const uno::Any& aSelection, ScMarkData& rMark,
587 ScPrintSelectionStatus& rStatus ) const
589 DBG_ASSERT( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
590 DBG_ASSERT( pDocShell, "FillRenderMarkData: DocShell must be set" );
592 BOOL bDone = FALSE;
594 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
595 if ( xInterface.is() )
597 ScCellRangesBase* pSelObj = ScCellRangesBase::getImplementation( xInterface );
598 uno::Reference< drawing::XShapes > xShapes( xInterface, uno::UNO_QUERY );
600 if ( pSelObj && pSelObj->GetDocShell() == pDocShell )
602 BOOL bSheet = ( ScTableSheetObj::getImplementation( xInterface ) != NULL );
603 BOOL bCursor = pSelObj->IsCursorOnly();
604 const ScRangeList& rRanges = pSelObj->GetRangeList();
606 rMark.MarkFromRangeList( rRanges, FALSE );
607 rMark.MarkToSimple();
609 if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
611 // a sheet object is treated like an empty selection: print the used area of the sheet
613 if ( bCursor || bSheet ) // nothing selected -> use whole tables
615 rMark.ResetMark(); // doesn't change table selection
616 rStatus.SetMode( SC_PRINTSEL_CURSOR );
618 else
619 rStatus.SetMode( SC_PRINTSEL_RANGE );
621 rStatus.SetRanges( rRanges );
622 bDone = TRUE;
624 // multi selection isn't supported
626 else if( xShapes.is() )
628 //print a selected ole object
629 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY );
630 if( xIndexAccess.is() )
632 // multi selection isn't supported yet
633 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
634 SvxShape* pShape = SvxShape::getImplementation( xShape );
635 if( pShape )
637 SdrObject *pSdrObj = pShape->GetSdrObject();
638 if( pDocShell )
640 ScDocument* pDoc = pDocShell->GetDocument();
641 if( pDoc && pSdrObj )
643 Rectangle aObjRect = pSdrObj->GetCurrentBoundRect();
644 SCTAB nCurrentTab = ScDocShell::GetCurTab();
645 ScRange aRange = pDoc->GetRange( nCurrentTab, aObjRect );
646 rMark.SetMarkArea( aRange );
648 if( rMark.IsMarked() && !rMark.IsMultiMarked() )
650 rStatus.SetMode( SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS );
651 bDone = TRUE;
658 else if ( ScModelObj::getImplementation( xInterface ) == this )
660 // render the whole document
661 // -> no selection, all sheets
663 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
664 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
665 rMark.SelectTable( nTab, TRUE );
666 rStatus.SetMode( SC_PRINTSEL_DOCUMENT );
667 bDone = TRUE;
669 // other selection types aren't supported
672 return bDone;
676 sal_Int32 SAL_CALL ScModelObj::getRendererCount( const uno::Any& aSelection,
677 const uno::Sequence<beans::PropertyValue>& /* xOptions */ )
678 throw (lang::IllegalArgumentException, uno::RuntimeException)
680 ScUnoGuard aGuard;
681 if (!pDocShell)
682 throw uno::RuntimeException();
684 ScMarkData aMark;
685 ScPrintSelectionStatus aStatus;
686 if ( !FillRenderMarkData( aSelection, aMark, aStatus ) )
687 return 0;
689 // The same ScPrintFuncCache object in pPrintFuncCache is used as long as
690 // the same selection is used (aStatus) and the document isn't changed
691 // (pPrintFuncCache is cleared in Notify handler)
693 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
695 delete pPrintFuncCache;
696 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
698 return pPrintFuncCache->GetPageCount();
701 uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nRenderer,
702 const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& /* xOptions */ )
703 throw (lang::IllegalArgumentException, uno::RuntimeException)
705 ScUnoGuard aGuard;
706 if (!pDocShell)
707 throw uno::RuntimeException();
709 ScMarkData aMark;
710 ScPrintSelectionStatus aStatus;
711 if ( !FillRenderMarkData( aSelection, aMark, aStatus ) )
712 throw lang::IllegalArgumentException();
714 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
716 delete pPrintFuncCache;
717 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
719 long nTotalPages = pPrintFuncCache->GetPageCount();
720 if ( nRenderer >= nTotalPages )
721 throw lang::IllegalArgumentException();
723 // printer is used as device (just for page layout), draw view is not needed
725 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
727 ScRange aRange;
728 const ScRange* pSelRange = NULL;
729 if ( aMark.IsMarked() )
731 aMark.GetMarkArea( aRange );
732 pSelRange = &aRange;
734 ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
735 pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange );
736 aFunc.SetRenderFlag( TRUE );
738 Range aPageRange( nRenderer+1, nRenderer+1 );
739 MultiSelection aPage( aPageRange );
740 aPage.SetTotalRange( Range(0,RANGE_MAX) );
741 aPage.Select( aPageRange );
743 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
744 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
746 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, FALSE, NULL, NULL );
748 ScRange aCellRange;
749 BOOL bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
750 Size aTwips = aFunc.GetPageSize();
751 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
753 long nPropCount = bWasCellRange ? 2 : 1;
754 uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
755 beans::PropertyValue* pArray = aSequence.getArray();
756 pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_PAGESIZE );
757 pArray[0].Value <<= aPageSize;
758 if ( bWasCellRange )
760 table::CellRangeAddress aRangeAddress( nTab,
761 aCellRange.aStart.Col(), aCellRange.aStart.Row(),
762 aCellRange.aEnd.Col(), aCellRange.aEnd.Row() );
763 pArray[1].Name = rtl::OUString::createFromAscii( SC_UNONAME_SOURCERANGE );
764 pArray[1].Value <<= aRangeAddress;
766 return aSequence;
769 void SAL_CALL ScModelObj::render( sal_Int32 nRenderer, const uno::Any& aSelection,
770 const uno::Sequence<beans::PropertyValue>& rOptions )
771 throw(lang::IllegalArgumentException, uno::RuntimeException)
773 ScUnoGuard aGuard;
774 if (!pDocShell)
775 throw uno::RuntimeException();
777 ScMarkData aMark;
778 ScPrintSelectionStatus aStatus;
779 if ( !FillRenderMarkData( aSelection, aMark, aStatus ) )
780 throw lang::IllegalArgumentException();
782 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
784 delete pPrintFuncCache;
785 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
787 long nTotalPages = pPrintFuncCache->GetPageCount();
788 if ( nRenderer >= nTotalPages )
789 throw lang::IllegalArgumentException();
791 OutputDevice* pDev = lcl_GetRenderDevice( rOptions );
792 if ( !pDev )
793 throw lang::IllegalArgumentException();
795 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
796 ScDocument* pDoc = pDocShell->GetDocument();
798 FmFormView* pDrawView = NULL;
799 Rectangle aFull( 0, 0, LONG_MAX, LONG_MAX );
801 // #114135#
802 ScDrawLayer* pModel = pDoc->GetDrawLayer();
804 if( pModel )
806 pDrawView = new FmFormView( pModel, pDev );
807 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
808 pDrawView->SetPrintPreview( TRUE );
811 ScRange aRange;
812 const ScRange* pSelRange = NULL;
813 if ( aMark.IsMarked() )
815 aMark.GetMarkArea( aRange );
816 pSelRange = &aRange;
819 // to increase performance, ScPrintState might be used here for subsequent
820 // pages of the same sheet
822 ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange );
823 aFunc.SetDrawView( pDrawView );
824 aFunc.SetRenderFlag( TRUE );
825 if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
826 aFunc.SetExclusivelyDrawOleAndDrawObjects();
828 Range aPageRange( nRenderer+1, nRenderer+1 );
829 MultiSelection aPage( aPageRange );
830 aPage.SetTotalRange( Range(0,RANGE_MAX) );
831 aPage.Select( aPageRange );
833 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
834 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
836 if ( nRenderer == nTabStart )
838 // first page of a sheet: add outline item for the sheet name
840 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
841 if ( pPDFData && pPDFData->GetIsExportBookmarks() )
843 // the sheet starts at the top of the page
844 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
845 sal_Int32 nDestID = pPDFData->CreateDest( aArea );
846 String aTabName;
847 pDoc->GetName( nTab, aTabName );
848 sal_Int32 nParent = -1; // top-level
849 pPDFData->CreateOutlineItem( nParent, aTabName, nDestID );
851 //--->i56629
852 // add the named destination stuff
853 if( pPDFData->GetIsExportNamedDestinations() )
855 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
856 String aTabName;
857 pDoc->GetName( nTab, aTabName );
858 //need the PDF page number here
859 pPDFData->CreateNamedDest( aTabName, aArea );
861 //<---i56629
864 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, TRUE, NULL, NULL );
866 // resolve the hyperlinks for PDF export
868 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
869 if ( pPDFData )
871 // iterate over the hyperlinks that were output for this page
873 std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFData->GetBookmarks();
874 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIter = rBookmarks.begin();
875 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
876 while ( aIter != aIEnd )
878 rtl::OUString aBookmark = aIter->aBookmark;
879 if ( aBookmark.toChar() == (sal_Unicode) '#' )
881 // try to resolve internal link
883 String aTarget( aBookmark.copy( 1 ) );
885 ScRange aTargetRange;
886 Rectangle aTargetRect; // 1/100th mm
887 bool bIsSheet = false;
888 bool bValid = lcl_ParseTarget( aTarget, aTargetRange, aTargetRect, bIsSheet, pDoc, nTab );
890 if ( bValid )
892 sal_Int32 nPage = -1;
893 Rectangle aArea;
894 if ( bIsSheet )
896 // Get first page for sheet (if nothing from that sheet is printed,
897 // this page can show a different sheet)
898 nPage = pPrintFuncCache->GetTabStart( aTargetRange.aStart.Tab() );
899 aArea = pDev->PixelToLogic( Rectangle( 0,0,0,0 ) );
901 else
903 pPrintFuncCache->InitLocations( aMark, pDev ); // does nothing if already initialized
905 ScPrintPageLocation aLocation;
906 if ( pPrintFuncCache->FindLocation( aTargetRange.aStart, aLocation ) )
908 nPage = aLocation.nPage;
910 // get the rectangle of the page's cell range in 1/100th mm
911 ScRange aLocRange = aLocation.aCellRange;
912 Rectangle aLocationMM = pDoc->GetMMRect(
913 aLocRange.aStart.Col(), aLocRange.aStart.Row(),
914 aLocRange.aEnd.Col(), aLocRange.aEnd.Row(),
915 aLocRange.aStart.Tab() );
916 Rectangle aLocationPixel = aLocation.aRectangle;
918 // Scale and move the target rectangle from aLocationMM to aLocationPixel,
919 // to get the target rectangle in pixels.
921 Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
922 Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );
924 long nX1 = aLocationPixel.Left() + (long)
925 ( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
926 long nX2 = aLocationPixel.Left() + (long)
927 ( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
928 long nY1 = aLocationPixel.Top() + (long)
929 ( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
930 long nY2 = aLocationPixel.Top() + (long)
931 ( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
933 if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
934 if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
935 if ( nY1 > aLocationPixel.Bottom() ) nY1 = aLocationPixel.Bottom();
936 if ( nY2 > aLocationPixel.Bottom() ) nY2 = aLocationPixel.Bottom();
938 // The link target area is interpreted using the device's MapMode at
939 // the time of the CreateDest call, so PixelToLogic can be used here,
940 // regardless of the MapMode that is actually selected.
942 aArea = pDev->PixelToLogic( Rectangle( nX1, nY1, nX2, nY2 ) );
946 if ( nPage >= 0 )
947 pPDFData->SetLinkDest( aIter->nLinkId, pPDFData->CreateDest( aArea, nPage ) );
950 else
952 // external link, use as-is
953 pPDFData->SetLinkURL( aIter->nLinkId, aBookmark );
955 aIter++;
957 rBookmarks.clear();
960 delete pDrawView;
963 // XLinkTargetSupplier
965 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException)
967 ScUnoGuard aGuard;
968 if (pDocShell)
969 return new ScLinkTargetTypesObj(pDocShell);
970 return NULL;
973 // XActionLockable
975 sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException)
977 ScUnoGuard aGuard;
978 BOOL bLocked = FALSE;
979 if (pDocShell)
980 bLocked = ( pDocShell->GetLockCount() != 0 );
981 return bLocked;
984 void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException)
986 ScUnoGuard aGuard;
987 if (pDocShell)
988 pDocShell->LockDocument();
991 void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException)
993 ScUnoGuard aGuard;
994 if (pDocShell)
995 pDocShell->UnlockDocument();
998 void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException)
1000 ScUnoGuard aGuard;
1001 if (pDocShell)
1002 pDocShell->SetLockCount(nLock);
1005 sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException)
1007 ScUnoGuard aGuard;
1008 USHORT nRet = 0;
1009 if (pDocShell)
1011 nRet = pDocShell->GetLockCount();
1012 pDocShell->SetLockCount(0);
1014 return nRet;
1017 void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException)
1019 ScUnoGuard aGuard;
1020 SfxBaseModel::lockControllers();
1021 if (pDocShell)
1022 pDocShell->LockPaint();
1025 void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException)
1027 ScUnoGuard aGuard;
1028 if (hasControllersLocked())
1030 SfxBaseModel::unlockControllers();
1031 if (pDocShell)
1032 pDocShell->UnlockPaint();
1036 // XCalculate
1038 void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException)
1040 ScUnoGuard aGuard;
1041 if (pDocShell)
1042 pDocShell->DoRecalc(TRUE);
1043 else
1045 DBG_ERROR("keine DocShell"); //! Exception oder so?
1049 void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException)
1051 ScUnoGuard aGuard;
1052 if (pDocShell)
1053 pDocShell->DoHardRecalc(TRUE);
1054 else
1056 DBG_ERROR("keine DocShell"); //! Exception oder so?
1060 sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException)
1062 ScUnoGuard aGuard;
1063 if (pDocShell)
1064 return pDocShell->GetDocument()->GetAutoCalc();
1066 DBG_ERROR("keine DocShell"); //! Exception oder so?
1067 return FALSE;
1070 void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabled )
1071 throw(uno::RuntimeException)
1073 ScUnoGuard aGuard;
1074 if (pDocShell)
1076 ScDocument* pDoc = pDocShell->GetDocument();
1077 if ( pDoc->GetAutoCalc() != bEnabled )
1079 pDoc->SetAutoCalc( bEnabled );
1080 pDocShell->SetDocumentModified();
1083 else
1085 DBG_ERROR("keine DocShell"); //! Exception oder so?
1089 // XProtectable
1091 void SAL_CALL ScModelObj::protect( const rtl::OUString& aPassword ) throw(uno::RuntimeException)
1093 ScUnoGuard aGuard;
1094 if (pDocShell)
1096 String aString(aPassword);
1098 ScDocFunc aFunc(*pDocShell);
1099 aFunc.Protect( TABLEID_DOC, aString, TRUE );
1103 void SAL_CALL ScModelObj::unprotect( const rtl::OUString& aPassword )
1104 throw(lang::IllegalArgumentException, uno::RuntimeException)
1106 ScUnoGuard aGuard;
1107 if (pDocShell)
1109 String aString(aPassword);
1111 ScDocFunc aFunc(*pDocShell);
1112 aFunc.Unprotect( TABLEID_DOC, aString, TRUE );
1114 //! Rueckgabewert auswerten, Exception oder so
1118 sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException)
1120 ScUnoGuard aGuard;
1121 if (pDocShell)
1122 return pDocShell->GetDocument()->IsDocProtected();
1124 DBG_ERROR("keine DocShell"); //! Exception oder so?
1125 return FALSE;
1128 // XDrawPagesSupplier
1130 uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException)
1132 ScUnoGuard aGuard;
1133 if (pDocShell)
1134 return new ScDrawPagesObj(pDocShell);
1136 DBG_ERROR("keine DocShell"); //! Exception oder so?
1137 return NULL;
1140 #if 0
1141 // XPrintable
1143 rtl::OUString ScModelObj::getPrinterName(void) const
1145 ScUnoGuard aGuard;
1146 if (pDocShell)
1148 SfxPrinter* pPrinter = pDocShell->GetPrinter();
1149 if (pPrinter)
1150 return pPrinter->GetName();
1153 DBG_ERROR("getPrinterName: keine DocShell oder kein Printer");
1154 return rtl::OUString();
1157 void ScModelObj::setPrinterName(const rtl::OUString& PrinterName)
1159 ScUnoGuard aGuard;
1160 // Drucker setzen - wie in SfxViewShell::ExecPrint_Impl
1162 if (pDocShell)
1164 SfxPrinter* pPrinter = pDocShell->GetPrinter();
1165 if (pPrinter)
1167 String aString(PrinterName);
1168 SfxPrinter* pNewPrinter = new SfxPrinter( pPrinter->GetOptions().Clone(), aString );
1169 if (pNewPrinter->IsKnown())
1170 pDocShell->SetPrinter( pNewPrinter, SFX_PRINTER_PRINTER );
1171 else
1172 delete pNewPrinter;
1177 XPropertySetRef ScModelObj::createPrintOptions(void)
1179 ScUnoGuard aGuard;
1180 return new ScPrintSettingsObj; //! ScPrintSettingsObj implementieren!
1183 void ScModelObj::print(const XPropertySetRef& xOptions)
1185 ScUnoGuard aGuard;
1186 if (pDocShell)
1188 //! xOptions auswerten (wie denn?)
1190 //! muss noch
1193 #endif
1195 // XGoalSeek
1197 sheet::GoalResult SAL_CALL ScModelObj::seekGoal(
1198 const table::CellAddress& aFormulaPosition,
1199 const table::CellAddress& aVariablePosition,
1200 const ::rtl::OUString& aGoalValue )
1201 throw(uno::RuntimeException)
1203 ScUnoGuard aGuard;
1204 sheet::GoalResult aResult;
1205 aResult.Divergence = DBL_MAX; // nichts gefunden
1206 if (pDocShell)
1208 WaitObject aWait( pDocShell->GetActiveDialogParent() );
1209 String aGoalString(aGoalValue);
1210 ScDocument* pDoc = pDocShell->GetDocument();
1211 double fValue = 0.0;
1212 BOOL bFound = pDoc->Solver(
1213 (SCCOL)aFormulaPosition.Column, (SCROW)aFormulaPosition.Row, aFormulaPosition.Sheet,
1214 (SCCOL)aVariablePosition.Column, (SCROW)aVariablePosition.Row, aVariablePosition.Sheet,
1215 aGoalString, fValue );
1216 aResult.Result = fValue;
1217 if (bFound)
1218 aResult.Divergence = 0.0; //! das ist gelogen
1220 return aResult;
1223 // XConsolidatable
1225 uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
1226 sal_Bool bEmpty ) throw(uno::RuntimeException)
1228 ScUnoGuard aGuard;
1229 ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
1230 if ( pDocShell && !bEmpty )
1232 ScDocument* pDoc = pDocShell->GetDocument();
1233 const ScConsolidateParam* pParam = pDoc->GetConsolidateDlgData();
1234 if (pParam)
1235 pNew->SetParam( *pParam );
1237 return pNew;
1240 void SAL_CALL ScModelObj::consolidate(
1241 const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
1242 throw(uno::RuntimeException)
1244 ScUnoGuard aGuard;
1245 // das koennte theoretisch ein fremdes Objekt sein, also nur das
1246 // oeffentliche XConsolidationDescriptor Interface benutzen, um
1247 // die Daten in ein ScConsolidationDescriptor Objekt zu kopieren:
1248 //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation?
1250 ScConsolidationDescriptor aImpl;
1251 aImpl.setFunction( xDescriptor->getFunction() );
1252 aImpl.setSources( xDescriptor->getSources() );
1253 aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
1254 aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
1255 aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
1256 aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
1258 if (pDocShell)
1260 const ScConsolidateParam& rParam = aImpl.GetParam();
1261 pDocShell->DoConsolidate( rParam, TRUE );
1262 pDocShell->GetDocument()->SetConsolidateDlgData( &rParam );
1266 // XDocumentAuditing
1268 void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException)
1270 ScUnoGuard aGuard;
1271 if (pDocShell)
1273 ScDocFunc aFunc(*pDocShell);
1274 aFunc.DetectiveRefresh();
1278 // XViewDataSupplier
1279 uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData( )
1280 throw (uno::RuntimeException)
1282 uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
1284 if( !xRet.is() )
1286 ScUnoGuard aGuard;
1287 if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
1289 xRet.set(uno::Reference < container::XIndexAccess >::query(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")))));
1291 uno::Reference < container::XIndexContainer > xCont( xRet, uno::UNO_QUERY );
1292 DBG_ASSERT( xCont.is(), "ScModelObj::getViewData() failed for OLE object" );
1293 if( xCont.is() )
1295 uno::Sequence< beans::PropertyValue > aSeq;
1296 aSeq.realloc(1);
1297 String sName;
1298 pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName );
1299 rtl::OUString sOUName(sName);
1300 aSeq[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ACTIVETABLE));
1301 aSeq[0].Value <<= sOUName;
1302 xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
1307 return xRet;
1310 // XPropertySet (Doc-Optionen)
1311 //! auch an der Applikation anbieten?
1313 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
1314 throw(uno::RuntimeException)
1316 ScUnoGuard aGuard;
1317 static uno::Reference<beans::XPropertySetInfo> aRef(
1318 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1319 return aRef;
1322 void SAL_CALL ScModelObj::setPropertyValue(
1323 const rtl::OUString& aPropertyName, const uno::Any& aValue )
1324 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1325 lang::IllegalArgumentException, lang::WrappedTargetException,
1326 uno::RuntimeException)
1328 ScUnoGuard aGuard;
1329 String aString(aPropertyName);
1331 if (pDocShell)
1333 ScDocument* pDoc = pDocShell->GetDocument();
1334 const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1335 ScDocOptions aNewOpt = rOldOpt;
1337 BOOL bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropertyName, aValue );
1338 if (bOpt)
1340 // done...
1342 else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) )
1344 lang::Locale aLocale;
1345 if ( aValue >>= aLocale )
1347 LanguageType eLatin, eCjk, eCtl;
1348 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1349 eLatin = ScUnoConversion::GetLanguage(aLocale);
1350 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1353 else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) )
1355 lang::Locale aLocale;
1356 if ( aValue >>= aLocale )
1358 LanguageType eLatin, eCjk, eCtl;
1359 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1360 eCjk = ScUnoConversion::GetLanguage(aLocale);
1361 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1364 else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) )
1366 lang::Locale aLocale;
1367 if ( aValue >>= aLocale )
1369 LanguageType eLatin, eCjk, eCtl;
1370 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1371 eCtl = ScUnoConversion::GetLanguage(aLocale);
1372 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1375 else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) )
1377 // model is created if not there
1378 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1379 pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1381 SfxBindings* pBindings = pDocShell->GetViewBindings();
1382 if (pBindings)
1383 pBindings->Invalidate( SID_FM_OPEN_READONLY );
1385 else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) )
1387 // model is created if not there
1388 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1389 pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1391 SfxBindings* pBindings = pDocShell->GetViewBindings();
1392 if (pBindings)
1393 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
1395 else if ( aString.EqualsAscii( SC_UNO_ISLOADED ) )
1397 pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1399 else if ( aString.EqualsAscii( SC_UNO_ISUNDOENABLED ) )
1401 BOOL bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1402 pDoc->EnableUndo( bUndoEnabled );
1403 USHORT nCount = ( bUndoEnabled ?
1404 static_cast< USHORT >( SvtUndoOptions().GetUndoCount() ) : 0 );
1405 pDocShell->GetUndoManager()->SetMaxUndoActionCount( nCount );
1407 else if ( aString.EqualsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1409 bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1410 pDoc->EnableAdjustHeight( bAdjustHeightEnabled );
1411 if ( bAdjustHeightEnabled )
1413 for ( SCTAB nTab = 0; nTab < pDoc->GetTableCount(); ++nTab )
1415 pDocShell->AdjustRowHeight( 0, MAXROW, nTab );
1419 else if ( aString.EqualsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1421 pDoc->EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1423 else if ( aString.EqualsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1425 pDoc->EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1427 else if ( aString.EqualsAscii( "BuildId" ) )
1429 aValue >>= maBuildId;
1431 else if ( aString.EqualsAscii( "SavedObject" ) ) // set from chart after saving
1433 rtl::OUString aObjName;
1434 aValue >>= aObjName;
1435 if ( aObjName.getLength() )
1436 pDoc->RestoreChartListener( aObjName );
1439 if ( aNewOpt != rOldOpt )
1441 pDoc->SetDocOptions( aNewOpt );
1442 // Don't recalculate while loading XML, when the formula text is stored.
1443 // Recalculation after loading is handled separately.
1444 //! Recalc only for options that need it?
1445 if ( !pDoc->IsImportingXML() )
1446 pDocShell->DoHardRecalc( TRUE );
1447 pDocShell->SetDocumentModified();
1452 uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyName )
1453 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1454 uno::RuntimeException)
1456 ScUnoGuard aGuard;
1457 String aString(aPropertyName);
1458 uno::Any aRet;
1460 if (pDocShell)
1462 ScDocument* pDoc = pDocShell->GetDocument();
1463 const ScDocOptions& rOpt = pDoc->GetDocOptions();
1464 aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropertyName );
1465 if ( aRet.hasValue() )
1467 // done...
1469 else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) )
1471 LanguageType eLatin, eCjk, eCtl;
1472 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1474 lang::Locale aLocale;
1475 ScUnoConversion::FillLocale( aLocale, eLatin );
1476 aRet <<= aLocale;
1478 else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) )
1480 LanguageType eLatin, eCjk, eCtl;
1481 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1483 lang::Locale aLocale;
1484 ScUnoConversion::FillLocale( aLocale, eCjk );
1485 aRet <<= aLocale;
1487 else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) )
1489 LanguageType eLatin, eCjk, eCtl;
1490 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1492 lang::Locale aLocale;
1493 ScUnoConversion::FillLocale( aLocale, eCtl );
1494 aRet <<= aLocale;
1496 else if ( aString.EqualsAscii( SC_UNO_NAMEDRANGES ) )
1498 aRet <<= uno::Reference<sheet::XNamedRanges>(new ScNamedRangesObj( pDocShell ));
1500 else if ( aString.EqualsAscii( SC_UNO_DATABASERNG ) )
1502 aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
1504 else if ( aString.EqualsAscii( SC_UNO_COLLABELRNG ) )
1506 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, TRUE ));
1508 else if ( aString.EqualsAscii( SC_UNO_ROWLABELRNG ) )
1510 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, FALSE ));
1512 else if ( aString.EqualsAscii( SC_UNO_AREALINKS ) )
1514 aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
1516 else if ( aString.EqualsAscii( SC_UNO_DDELINKS ) )
1518 aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
1520 else if ( aString.EqualsAscii( SC_UNO_EXTERNALDOCLINKS ) )
1522 aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
1524 else if ( aString.EqualsAscii( SC_UNO_SHEETLINKS ) )
1526 aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
1528 else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) )
1530 // default for no model is TRUE
1531 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1532 sal_Bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True;
1533 ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
1535 else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) )
1537 // default for no model is FALSE
1538 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1539 sal_Bool bAutoControlFocus = pModel ? pModel->GetAutoControlFocus() : sal_False;
1540 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
1542 else if ( aString.EqualsAscii( SC_UNO_FORBIDDEN ) )
1544 aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
1546 else if ( aString.EqualsAscii( SC_UNO_HASDRAWPAGES ) )
1548 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) );
1550 else if ( aString.EqualsAscii( SC_UNO_BASICLIBRARIES ) )
1552 aRet <<= pDocShell->GetBasicContainer();
1554 else if ( aString.EqualsAscii( SC_UNO_DIALOGLIBRARIES ) )
1556 aRet <<= pDocShell->GetDialogContainer();
1558 else if ( aString.EqualsAscii( SC_UNO_RUNTIMEUID ) )
1560 aRet <<= getRuntimeUID();
1562 else if ( aString.EqualsAscii( SC_UNO_HASVALIDSIGNATURES ) )
1564 aRet <<= hasValidSignatures();
1566 else if ( aString.EqualsAscii( SC_UNO_ISLOADED ) )
1568 ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
1570 else if ( aString.EqualsAscii( SC_UNO_ISUNDOENABLED ) )
1572 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsUndoEnabled() );
1574 else if ( aString.EqualsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1576 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsAdjustHeightEnabled() );
1578 else if ( aString.EqualsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1580 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsExecuteLinkEnabled() );
1582 else if ( aString.EqualsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1584 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsChangeReadOnlyEnabled() );
1586 else if ( aString.EqualsAscii( SC_UNO_REFERENCEDEVICE ) )
1588 VCLXDevice* pXDev = new VCLXDevice();
1589 pXDev->SetOutputDevice( pDoc->GetRefDevice() );
1590 aRet <<= uno::Reference< awt::XDevice >( pXDev );
1592 else if (aString.EqualsAscii(SC_UNO_ALWAYS_ALLOW_SAVE))
1593 ScUnoHelpFunctions::SetBoolInAny(aRet, pDocShell->GetApplicationFlag(SFX_APPFLAG_ALWAYS_ALLOW_SAVE));
1594 else if ( aString.EqualsAscii( "BuildId" ) )
1596 aRet <<= maBuildId;
1598 else if ( aString.EqualsAscii( "InternalDocument" ) )
1600 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL) );
1604 return aRet;
1607 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
1609 // XMultiServiceFactory
1611 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
1612 const rtl::OUString& aServiceSpecifier )
1613 throw(uno::Exception, uno::RuntimeException)
1615 ScUnoGuard aGuard;
1616 uno::Reference<uno::XInterface> xRet;
1617 String aNameStr(aServiceSpecifier);
1618 USHORT nType = ScServiceProvider::GetProviderType(aNameStr);
1619 if ( nType != SC_SERVICE_INVALID )
1621 // drawing layer tables must be kept as long as the model is alive
1622 // return stored instance if already set
1623 switch ( nType )
1625 case SC_SERVICE_GRADTAB: xRet.set(xDrawGradTab); break;
1626 case SC_SERVICE_HATCHTAB: xRet.set(xDrawHatchTab); break;
1627 case SC_SERVICE_BITMAPTAB: xRet.set(xDrawBitmapTab); break;
1628 case SC_SERVICE_TRGRADTAB: xRet.set(xDrawTrGradTab); break;
1629 case SC_SERVICE_MARKERTAB: xRet.set(xDrawMarkerTab); break;
1630 case SC_SERVICE_DASHTAB: xRet.set(xDrawDashTab); break;
1631 case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv); break;
1634 // #i64497# If a chart is in a temporary document during clipoard paste,
1635 // there should be no data provider, so that own data is used
1636 bool bCreate =
1637 ! ( nType == SC_SERVICE_CHDATAPROV &&
1638 ( pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL ));
1639 // this should never happen, i.e. the temporary document should never be
1640 // loaded, becuase this unlinks the data
1641 OSL_ASSERT( bCreate );
1643 if ( !xRet.is() && bCreate )
1645 xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
1647 // store created instance
1648 switch ( nType )
1650 case SC_SERVICE_GRADTAB: xDrawGradTab.set(xRet); break;
1651 case SC_SERVICE_HATCHTAB: xDrawHatchTab.set(xRet); break;
1652 case SC_SERVICE_BITMAPTAB: xDrawBitmapTab.set(xRet); break;
1653 case SC_SERVICE_TRGRADTAB: xDrawTrGradTab.set(xRet); break;
1654 case SC_SERVICE_MARKERTAB: xDrawMarkerTab.set(xRet); break;
1655 case SC_SERVICE_DASHTAB: xDrawDashTab.set(xRet); break;
1656 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet); break;
1660 else
1662 // alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals,
1663 // da wird dann 'ne Exception geworfen, wenn's nicht passt...
1667 xRet.set(SvxFmMSFactory::createInstance(aServiceSpecifier));
1668 // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
1670 catch ( lang::ServiceNotRegisteredException & )
1674 // #96117# if the drawing factory created a shape, a ScShapeObj has to be used
1675 // to support own properties like ImageMap:
1677 uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
1678 if ( xShape.is() )
1680 xRet.clear(); // for aggregation, xShape must be the object's only ref
1681 new ScShapeObj( xShape ); // aggregates object and modifies xShape
1682 xRet.set(xShape);
1685 return xRet;
1688 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments(
1689 const rtl::OUString& ServiceSpecifier,
1690 const uno::Sequence<uno::Any>& aArgs )
1691 throw(uno::Exception, uno::RuntimeException)
1693 //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer?
1695 ScUnoGuard aGuard;
1696 uno::Reference<uno::XInterface> xInt(createInstance(ServiceSpecifier));
1698 if ( aArgs.getLength() )
1700 // used only for cell value binding so far - it can be initialized after creating
1702 uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
1703 if ( xInit.is() )
1704 xInit->initialize( aArgs );
1707 return xInt;
1710 uno::Sequence<rtl::OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
1711 throw(uno::RuntimeException)
1713 ScUnoGuard aGuard;
1715 //! warum sind die Parameter bei concatServiceNames nicht const ???
1716 //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
1717 //! SvxFmMSFactory::getAvailableServiceNames() );
1719 uno::Sequence<rtl::OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
1720 uno::Sequence<rtl::OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
1722 return concatServiceNames( aMyServices, aDrawServices );
1725 // XVbaEventHelper
1726 // For Vba Event
1727 sal_Bool SAL_CALL
1728 ScModelObj::processCompatibleEvent( sal_Int16 nSlotId ) throw( ::com::sun::star::uno::RuntimeException )
1730 USHORT nId = (USHORT)nSlotId;
1731 uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper( GetDocument()->GetVbaEventsHelper(), uno::UNO_QUERY );
1732 if( xVbaEventsHelper.is() )
1734 switch( nId )
1736 case SID_SAVEDOC:
1738 uno::Sequence< uno::Any > aArgs(1);
1739 aArgs[0] <<= sal_False;
1740 return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORESAVE, aArgs );
1742 case SID_SAVEASDOC:
1744 uno::Sequence< uno::Any > aArgs(1);
1745 aArgs[0] <<= sal_True;
1746 return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORESAVE, aArgs );
1748 case SID_PRINTDOC:
1749 case SID_PRINTDOCDIRECT:
1751 uno::Sequence< uno::Any > aArgs;
1752 return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFOREPRINT, aArgs );
1756 return sal_False;
1758 // XServiceInfo
1760 rtl::OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException)
1762 return rtl::OUString::createFromAscii( "ScModelObj" );
1765 sal_Bool SAL_CALL ScModelObj::supportsService( const rtl::OUString& rServiceName )
1766 throw(uno::RuntimeException)
1768 String aServiceStr(rServiceName);
1769 return aServiceStr.EqualsAscii( SCMODELOBJ_SERVICE ) ||
1770 aServiceStr.EqualsAscii( SCDOCSETTINGS_SERVICE ) ||
1771 aServiceStr.EqualsAscii( SCDOC_SERVICE );
1774 uno::Sequence<rtl::OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
1775 throw(uno::RuntimeException)
1777 uno::Sequence<rtl::OUString> aRet(2);
1778 rtl::OUString* pArray = aRet.getArray();
1779 pArray[0] = rtl::OUString::createFromAscii( SCMODELOBJ_SERVICE );
1780 pArray[1] = rtl::OUString::createFromAscii( SCDOCSETTINGS_SERVICE );
1781 return aRet;
1784 // XUnoTunnel
1786 sal_Int64 SAL_CALL ScModelObj::getSomething(
1787 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
1789 if ( rId.getLength() == 16 &&
1790 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1791 rId.getConstArray(), 16 ) )
1793 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1796 // aggregated number formats supplier has XUnoTunnel, too
1797 // interface from aggregated object must be obtained via queryAggregation
1799 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
1800 if ( nRet )
1801 return nRet;
1803 if ( xNumberAgg.is() )
1805 const uno::Type& rTunnelType = ::getCppuType((uno::Reference<lang::XUnoTunnel>*) 0);
1806 uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
1807 if(aNumTunnel.getValueType() == rTunnelType)
1809 uno::Reference<lang::XUnoTunnel> xTunnelAgg(
1810 *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue());
1811 return xTunnelAgg->getSomething( rId );
1815 return 0;
1818 // static
1819 const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
1821 static uno::Sequence<sal_Int8> * pSeq = 0;
1822 if( !pSeq )
1824 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1825 if( !pSeq )
1827 static uno::Sequence< sal_Int8 > aSeq( 16 );
1828 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1829 pSeq = &aSeq;
1832 return *pSeq;
1835 // static
1836 ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
1838 ScModelObj* pRet = NULL;
1839 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
1840 if (xUT.is())
1841 pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1842 return pRet;
1845 // XChangesNotifier
1847 void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
1848 throw (uno::RuntimeException)
1850 ScUnoGuard aGuard;
1851 maChangesListeners.addInterface( aListener );
1854 void ScModelObj::removeChangesListener( const uno::Reference< util::XChangesListener >& aListener )
1855 throw (uno::RuntimeException)
1857 ScUnoGuard aGuard;
1858 maChangesListeners.removeInterface( aListener );
1861 bool ScModelObj::HasChangesListeners() const
1863 return ( maChangesListeners.getLength() > 0 );
1866 void ScModelObj::NotifyChanges( const ::rtl::OUString& rOperation, const ScRangeList& rRanges,
1867 const uno::Sequence< beans::PropertyValue >& rProperties )
1869 if ( pDocShell && HasChangesListeners() )
1871 util::ChangesEvent aEvent;
1872 aEvent.Source.set( static_cast< cppu::OWeakObject* >( this ) );
1873 aEvent.Base <<= aEvent.Source;
1875 ULONG nRangeCount = rRanges.Count();
1876 aEvent.Changes.realloc( static_cast< sal_Int32 >( nRangeCount ) );
1877 for ( ULONG nIndex = 0; nIndex < nRangeCount; ++nIndex )
1879 uno::Reference< table::XCellRange > xRangeObj;
1881 ScRange aRange( *rRanges.GetObject( nIndex ) );
1882 if ( aRange.aStart == aRange.aEnd )
1884 xRangeObj.set( new ScCellObj( pDocShell, aRange.aStart ) );
1886 else
1888 xRangeObj.set( new ScCellRangeObj( pDocShell, aRange ) );
1891 util::ElementChange& rChange = aEvent.Changes[ static_cast< sal_Int32 >( nIndex ) ];
1892 rChange.Accessor <<= rOperation;
1893 rChange.Element <<= rProperties;
1894 rChange.ReplacedElement <<= xRangeObj;
1897 ::cppu::OInterfaceIteratorHelper aIter( maChangesListeners );
1898 while ( aIter.hasMoreElements() )
1902 static_cast< util::XChangesListener* >( aIter.next() )->changesOccurred( aEvent );
1904 catch( uno::Exception& )
1911 //------------------------------------------------------------------------
1913 ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
1914 pDocShell( pDocSh )
1916 pDocShell->GetDocument()->AddUnoObject(*this);
1919 ScDrawPagesObj::~ScDrawPagesObj()
1921 if (pDocShell)
1922 pDocShell->GetDocument()->RemoveUnoObject(*this);
1925 void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1927 // Referenz-Update interessiert hier nicht
1929 if ( rHint.ISA( SfxSimpleHint ) &&
1930 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1932 pDocShell = NULL; // ungueltig geworden
1936 uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(INT32 nIndex) const
1938 if (pDocShell)
1940 ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
1941 DBG_ASSERT(pDrawLayer,"kann Draw-Layer nicht anlegen");
1942 if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
1944 SdrPage* pPage = pDrawLayer->GetPage((USHORT)nIndex);
1945 DBG_ASSERT(pPage,"Draw-Page nicht gefunden");
1946 if (pPage)
1948 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
1952 return NULL;
1955 // XDrawPages
1957 uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
1958 throw(uno::RuntimeException)
1960 ScUnoGuard aGuard;
1961 uno::Reference<drawing::XDrawPage> xRet;
1962 if (pDocShell)
1964 String aNewName;
1965 pDocShell->GetDocument()->CreateValidTabName(aNewName);
1966 ScDocFunc aFunc(*pDocShell);
1967 if ( aFunc.InsertTable( (SCTAB)nPos, aNewName, TRUE, TRUE ) )
1968 xRet.set(GetObjectByIndex_Impl( nPos ));
1970 return xRet;
1973 void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
1974 throw(uno::RuntimeException)
1976 ScUnoGuard aGuard;
1977 SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
1978 if ( pDocShell && pImp )
1980 SdrPage* pPage = pImp->GetSdrPage();
1981 if (pPage)
1983 SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
1984 ScDocFunc aFunc(*pDocShell);
1985 aFunc.DeleteTable( nPageNum, TRUE, TRUE );
1990 // XIndexAccess
1992 sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException)
1994 ScUnoGuard aGuard;
1995 if (pDocShell)
1996 return pDocShell->GetDocument()->GetTableCount();
1997 return 0;
2000 uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
2001 throw(lang::IndexOutOfBoundsException,
2002 lang::WrappedTargetException, uno::RuntimeException)
2004 ScUnoGuard aGuard;
2005 uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
2006 if (xPage.is())
2007 return uno::makeAny(xPage);
2008 else
2009 throw lang::IndexOutOfBoundsException();
2010 // return uno::Any();
2013 uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException)
2015 ScUnoGuard aGuard;
2016 return getCppuType((uno::Reference<drawing::XDrawPage>*)0);
2019 sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException)
2021 ScUnoGuard aGuard;
2022 return ( getCount() != 0 );
2025 //------------------------------------------------------------------------
2027 ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
2028 pDocShell( pDocSh )
2030 pDocShell->GetDocument()->AddUnoObject(*this);
2033 ScTableSheetsObj::~ScTableSheetsObj()
2035 if (pDocShell)
2036 pDocShell->GetDocument()->RemoveUnoObject(*this);
2039 void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2041 // Referenz-Update interessiert hier nicht
2043 if ( rHint.ISA( SfxSimpleHint ) &&
2044 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2046 pDocShell = NULL; // ungueltig geworden
2050 // XSpreadsheets
2052 ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2054 if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
2055 return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
2057 return NULL;
2060 ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
2062 if (pDocShell)
2064 SCTAB nIndex;
2065 String aString(aName);
2066 if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) )
2067 return new ScTableSheetObj( pDocShell, nIndex );
2069 return NULL;
2072 void SAL_CALL ScTableSheetsObj::insertNewByName( const rtl::OUString& aName, sal_Int16 nPosition )
2073 throw(uno::RuntimeException)
2075 ScUnoGuard aGuard;
2076 BOOL bDone = FALSE;
2077 if (pDocShell)
2079 String aNamStr(aName);
2080 ScDocFunc aFunc(*pDocShell);
2081 bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE );
2083 if (!bDone)
2084 throw uno::RuntimeException(); // no other exceptions specified
2087 void SAL_CALL ScTableSheetsObj::moveByName( const rtl::OUString& aName, sal_Int16 nDestination )
2088 throw(uno::RuntimeException)
2090 ScUnoGuard aGuard;
2091 BOOL bDone = FALSE;
2092 if (pDocShell)
2094 String aNamStr(aName);
2095 SCTAB nSource;
2096 if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) )
2097 bDone = pDocShell->MoveTable( nSource, nDestination, FALSE, TRUE );
2099 if (!bDone)
2100 throw uno::RuntimeException(); // no other exceptions specified
2103 void SAL_CALL ScTableSheetsObj::copyByName( const rtl::OUString& aName,
2104 const rtl::OUString& aCopy, sal_Int16 nDestination )
2105 throw(uno::RuntimeException)
2107 ScUnoGuard aGuard;
2108 BOOL bDone = FALSE;
2109 if (pDocShell)
2111 String aNamStr(aName);
2112 String aNewStr(aCopy);
2113 SCTAB nSource;
2114 if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) )
2116 bDone = pDocShell->MoveTable( nSource, nDestination, TRUE, TRUE );
2117 if (bDone)
2119 // #i92477# any index past the last sheet means "append" in MoveTable
2120 SCTAB nResultTab = static_cast<SCTAB>(nDestination);
2121 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount(); // count after copying
2122 if (nResultTab >= nTabCount)
2123 nResultTab = nTabCount - 1;
2125 ScDocFunc aFunc(*pDocShell);
2126 bDone = aFunc.RenameTable( nResultTab, aNewStr, TRUE, TRUE );
2130 if (!bDone)
2131 throw uno::RuntimeException(); // no other exceptions specified
2134 void SAL_CALL ScTableSheetsObj::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
2135 throw(lang::IllegalArgumentException, container::ElementExistException,
2136 lang::WrappedTargetException, uno::RuntimeException)
2138 ScUnoGuard aGuard;
2139 BOOL bDone = FALSE;
2140 BOOL bIllArg = FALSE;
2142 //! Type of aElement can be some specific interface instead of XInterface
2144 if ( pDocShell )
2146 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2147 if ( xInterface.is() )
2149 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2150 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2152 ScDocument* pDoc = pDocShell->GetDocument();
2153 String aNamStr(aName);
2154 SCTAB nDummy;
2155 if ( pDoc->GetTable( aNamStr, nDummy ) )
2157 // name already exists
2158 throw container::ElementExistException();
2160 else
2162 SCTAB nPosition = pDoc->GetTableCount();
2163 ScDocFunc aFunc(*pDocShell);
2164 bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE );
2165 if (bDone)
2166 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2167 // Dokument und neuen Range am Objekt setzen
2170 else
2171 bIllArg = TRUE;
2173 else
2174 bIllArg = TRUE;
2177 if (!bDone)
2179 if (bIllArg)
2180 throw lang::IllegalArgumentException();
2181 else
2182 throw uno::RuntimeException(); // ElementExistException is handled above
2186 void SAL_CALL ScTableSheetsObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement )
2187 throw(lang::IllegalArgumentException, container::NoSuchElementException,
2188 lang::WrappedTargetException, uno::RuntimeException)
2190 ScUnoGuard aGuard;
2191 BOOL bDone = FALSE;
2192 BOOL bIllArg = FALSE;
2194 //! Type of aElement can be some specific interface instead of XInterface
2196 if ( pDocShell )
2198 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2199 if ( xInterface.is() )
2201 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2202 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2204 String aNamStr(aName);
2205 SCTAB nPosition;
2206 if ( pDocShell->GetDocument()->GetTable( aNamStr, nPosition ) )
2208 ScDocFunc aFunc(*pDocShell);
2209 if ( aFunc.DeleteTable( nPosition, TRUE, TRUE ) )
2211 // InsertTable kann jetzt eigentlich nicht schiefgehen...
2212 bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE );
2213 if (bDone)
2214 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2217 else
2219 // not found
2220 throw container::NoSuchElementException();
2223 else
2224 bIllArg = TRUE;
2226 else
2227 bIllArg = TRUE;
2230 if (!bDone)
2232 if (bIllArg)
2233 throw lang::IllegalArgumentException();
2234 else
2235 throw uno::RuntimeException(); // NoSuchElementException is handled above
2239 void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName )
2240 throw(container::NoSuchElementException,
2241 lang::WrappedTargetException, uno::RuntimeException)
2243 ScUnoGuard aGuard;
2244 BOOL bDone = FALSE;
2245 if (pDocShell)
2247 SCTAB nIndex;
2248 String aString(aName);
2249 if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) )
2251 ScDocFunc aFunc(*pDocShell);
2252 bDone = aFunc.DeleteTable( nIndex, TRUE, TRUE );
2254 else
2256 // not found
2257 throw container::NoSuchElementException();
2261 if (!bDone)
2262 throw uno::RuntimeException(); // NoSuchElementException is handled above
2265 // XCellRangesAccess
2267 uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet )
2268 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2270 ScUnoGuard aGuard;
2271 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((USHORT)nSheet)));
2272 if (! xSheet.is())
2273 throw lang::IndexOutOfBoundsException();
2275 return xSheet->getCellByPosition(nColumn, nRow);
2278 uno::Reference< table::XCellRange > SAL_CALL ScTableSheetsObj::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom, sal_Int32 nSheet )
2279 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2281 ScUnoGuard aGuard;
2282 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((USHORT)nSheet)));
2283 if (! xSheet.is())
2284 throw lang::IndexOutOfBoundsException();
2286 return xSheet->getCellRangeByPosition(nLeft, nTop, nRight, nBottom);
2289 uno::Sequence < uno::Reference< table::XCellRange > > SAL_CALL ScTableSheetsObj::getCellRangesByName( const rtl::OUString& aRange )
2290 throw (lang::IllegalArgumentException, uno::RuntimeException)
2292 ScUnoGuard aGuard;
2293 uno::Sequence < uno::Reference < table::XCellRange > > xRet;
2295 ScRangeList aRangeList;
2296 ScDocument* pDoc = pDocShell->GetDocument();
2297 if (ScRangeStringConverter::GetRangeListFromString( aRangeList, aRange, pDoc, ::formula::FormulaGrammar::CONV_OOO, ';' ))
2299 sal_Int32 nCount = aRangeList.Count();
2300 if (nCount)
2302 xRet.realloc(nCount);
2303 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
2305 const ScRange* pRange = aRangeList.GetObject( nIndex );
2306 if( pRange )
2307 xRet[nIndex] = new ScCellRangeObj(pDocShell, *pRange);
2310 else
2311 throw lang::IllegalArgumentException();
2313 else
2314 throw lang::IllegalArgumentException();
2315 return xRet;
2318 // XEnumerationAccess
2320 uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
2321 throw(uno::RuntimeException)
2323 ScUnoGuard aGuard;
2324 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetsEnumeration")));
2327 // XIndexAccess
2329 sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException)
2331 ScUnoGuard aGuard;
2332 if (pDocShell)
2333 return pDocShell->GetDocument()->GetTableCount();
2334 return 0;
2337 uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
2338 throw(lang::IndexOutOfBoundsException,
2339 lang::WrappedTargetException, uno::RuntimeException)
2341 ScUnoGuard aGuard;
2342 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
2343 if (xSheet.is())
2344 return uno::makeAny(xSheet);
2345 else
2346 throw lang::IndexOutOfBoundsException();
2347 // return uno::Any();
2350 uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException)
2352 ScUnoGuard aGuard;
2353 return getCppuType((uno::Reference<sheet::XSpreadsheet>*)0);
2356 sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException)
2358 ScUnoGuard aGuard;
2359 return ( getCount() != 0 );
2362 // XNameAccess
2364 uno::Any SAL_CALL ScTableSheetsObj::getByName( const rtl::OUString& aName )
2365 throw(container::NoSuchElementException,
2366 lang::WrappedTargetException, uno::RuntimeException)
2368 ScUnoGuard aGuard;
2369 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
2370 if (xSheet.is())
2371 return uno::makeAny(xSheet);
2372 else
2373 throw container::NoSuchElementException();
2374 // return uno::Any();
2377 uno::Sequence<rtl::OUString> SAL_CALL ScTableSheetsObj::getElementNames()
2378 throw(uno::RuntimeException)
2380 ScUnoGuard aGuard;
2381 if (pDocShell)
2383 ScDocument* pDoc = pDocShell->GetDocument();
2384 SCTAB nCount = pDoc->GetTableCount();
2385 String aName;
2386 uno::Sequence<rtl::OUString> aSeq(nCount);
2387 rtl::OUString* pAry = aSeq.getArray();
2388 for (SCTAB i=0; i<nCount; i++)
2390 pDoc->GetName( i, aName );
2391 pAry[i] = aName;
2393 return aSeq;
2395 return uno::Sequence<rtl::OUString>();
2398 sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const rtl::OUString& aName )
2399 throw(uno::RuntimeException)
2401 ScUnoGuard aGuard;
2402 if (pDocShell)
2404 SCTAB nIndex;
2405 if ( pDocShell->GetDocument()->GetTable( String(aName), nIndex ) )
2406 return TRUE;
2408 return FALSE;
2411 //------------------------------------------------------------------------
2413 ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
2414 pDocShell( pDocSh ),
2415 nTab ( nT ),
2416 nStartCol( nSC ),
2417 nEndCol ( nEC )
2419 pDocShell->GetDocument()->AddUnoObject(*this);
2422 ScTableColumnsObj::~ScTableColumnsObj()
2424 if (pDocShell)
2425 pDocShell->GetDocument()->RemoveUnoObject(*this);
2428 void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2430 if ( rHint.ISA( ScUpdateRefHint ) )
2432 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
2434 //! Referenz-Update fuer Tab und Start/Ende
2436 else if ( rHint.ISA( SfxSimpleHint ) &&
2437 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2439 pDocShell = NULL; // ungueltig geworden
2443 // XTableColumns
2445 ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2447 SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
2448 if ( pDocShell && nCol <= nEndCol )
2449 return new ScTableColumnObj( pDocShell, nCol, nTab );
2451 return NULL; // falscher Index
2454 ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
2456 SCCOL nCol = 0;
2457 String aString(aName);
2458 if ( ::AlphaToCol( nCol, aString) )
2459 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
2460 return new ScTableColumnObj( pDocShell, nCol, nTab );
2462 return NULL;
2465 void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
2466 throw(uno::RuntimeException)
2468 ScUnoGuard aGuard;
2469 BOOL bDone = FALSE;
2470 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
2471 nStartCol+nPosition+nCount-1 <= MAXCOL )
2473 ScDocFunc aFunc(*pDocShell);
2474 ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
2475 (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
2476 bDone = aFunc.InsertCells( aRange, NULL, INS_INSCOLS, TRUE, TRUE );
2478 if (!bDone)
2479 throw uno::RuntimeException(); // no other exceptions specified
2482 void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
2483 throw(uno::RuntimeException)
2485 ScUnoGuard aGuard;
2486 BOOL bDone = FALSE;
2487 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
2488 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
2490 ScDocFunc aFunc(*pDocShell);
2491 ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
2492 (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
2493 bDone = aFunc.DeleteCells( aRange, NULL, DEL_DELCOLS, TRUE, TRUE );
2495 if (!bDone)
2496 throw uno::RuntimeException(); // no other exceptions specified
2499 // XEnumerationAccess
2501 uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
2502 throw(uno::RuntimeException)
2504 ScUnoGuard aGuard;
2505 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableColumnsEnumeration")));
2508 // XIndexAccess
2510 sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException)
2512 ScUnoGuard aGuard;
2513 return nEndCol - nStartCol + 1;
2516 uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
2517 throw(lang::IndexOutOfBoundsException,
2518 lang::WrappedTargetException, uno::RuntimeException)
2520 ScUnoGuard aGuard;
2521 uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
2522 if (xColumn.is())
2523 return uno::makeAny(xColumn);
2524 else
2525 throw lang::IndexOutOfBoundsException();
2526 // return uno::Any();
2529 uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException)
2531 ScUnoGuard aGuard;
2532 return getCppuType((uno::Reference<table::XCellRange>*)0);
2535 sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException)
2537 ScUnoGuard aGuard;
2538 return ( getCount() != 0 );
2541 uno::Any SAL_CALL ScTableColumnsObj::getByName( const rtl::OUString& aName )
2542 throw(container::NoSuchElementException,
2543 lang::WrappedTargetException, uno::RuntimeException)
2545 ScUnoGuard aGuard;
2546 uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
2547 if (xColumn.is())
2548 return uno::makeAny(xColumn);
2549 else
2550 throw container::NoSuchElementException();
2551 // return uno::Any();
2554 uno::Sequence<rtl::OUString> SAL_CALL ScTableColumnsObj::getElementNames()
2555 throw(uno::RuntimeException)
2557 ScUnoGuard aGuard;
2558 SCCOL nCount = nEndCol - nStartCol + 1;
2559 uno::Sequence<rtl::OUString> aSeq(nCount);
2560 rtl::OUString* pAry = aSeq.getArray();
2561 for (SCCOL i=0; i<nCount; i++)
2562 pAry[i] = ::ScColToAlpha( nStartCol + i );
2564 return aSeq;
2567 sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const rtl::OUString& aName )
2568 throw(uno::RuntimeException)
2570 ScUnoGuard aGuard;
2571 SCCOL nCol = 0;
2572 String aString(aName);
2573 if ( ::AlphaToCol( nCol, aString) )
2574 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
2575 return TRUE;
2577 return FALSE; // nicht gefunden
2580 // XPropertySet
2582 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
2583 throw(uno::RuntimeException)
2585 ScUnoGuard aGuard;
2586 static uno::Reference<beans::XPropertySetInfo> aRef(
2587 new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
2588 return aRef;
2591 void SAL_CALL ScTableColumnsObj::setPropertyValue(
2592 const rtl::OUString& aPropertyName, const uno::Any& aValue )
2593 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2594 lang::IllegalArgumentException, lang::WrappedTargetException,
2595 uno::RuntimeException)
2597 ScUnoGuard aGuard;
2598 if (!pDocShell)
2599 throw uno::RuntimeException();
2601 ScDocFunc aFunc(*pDocShell);
2602 SCCOLROW nColArr[2];
2603 nColArr[0] = nStartCol;
2604 nColArr[1] = nEndCol;
2605 String aNameString(aPropertyName);
2607 if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) )
2609 sal_Int32 nNewWidth = 0;
2610 if ( aValue >>= nNewWidth )
2611 aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, SC_SIZE_ORIGINAL,
2612 (USHORT)HMMToTwips(nNewWidth), TRUE, TRUE );
2614 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2616 BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2617 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
2618 aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, eMode, 0, TRUE, TRUE );
2619 // SC_SIZE_DIRECT with size 0: hide
2621 else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) )
2623 BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2624 if (bOpt)
2625 aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab,
2626 SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, TRUE, TRUE );
2627 // FALSE for columns currently has no effect
2629 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
2631 //! single function to set/remove all breaks?
2632 BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2633 for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
2634 if (bSet)
2635 aFunc.InsertPageBreak( TRUE, ScAddress(nCol,0,nTab), TRUE, TRUE, TRUE );
2636 else
2637 aFunc.RemovePageBreak( TRUE, ScAddress(nCol,0,nTab), TRUE, TRUE, TRUE );
2641 uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const rtl::OUString& aPropertyName )
2642 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2643 uno::RuntimeException)
2645 ScUnoGuard aGuard;
2646 if (!pDocShell)
2647 throw uno::RuntimeException();
2649 ScDocument* pDoc = pDocShell->GetDocument();
2650 String aNameString(aPropertyName);
2651 uno::Any aAny;
2653 //! loop over all columns for current state?
2655 if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) )
2657 // for hidden column, return original height
2658 USHORT nWidth = pDoc->GetOriginalWidth( nStartCol, nTab );
2659 aAny <<= (sal_Int32)TwipsToHMM(nWidth);
2661 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2663 BOOL bVis = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_HIDDEN);
2664 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
2666 else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) )
2668 BOOL bOpt = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE);
2669 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
2671 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) )
2673 BOOL bBreak = ( 0 != (pDoc->GetColFlags( nStartCol, nTab ) & (CR_PAGEBREAK|CR_MANUALBREAK)) );
2674 ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak );
2676 else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
2678 BOOL bBreak = ( 0 != (pDoc->GetColFlags( nStartCol, nTab ) & (CR_MANUALBREAK)) );
2679 ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak );
2682 return aAny;
2685 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
2687 //------------------------------------------------------------------------
2689 ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
2690 pDocShell( pDocSh ),
2691 nTab ( nT ),
2692 nStartRow( nSR ),
2693 nEndRow ( nER )
2695 pDocShell->GetDocument()->AddUnoObject(*this);
2698 ScTableRowsObj::~ScTableRowsObj()
2700 if (pDocShell)
2701 pDocShell->GetDocument()->RemoveUnoObject(*this);
2704 void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2706 if ( rHint.ISA( ScUpdateRefHint ) )
2708 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
2710 //! Referenz-Update fuer Tab und Start/Ende
2712 else if ( rHint.ISA( SfxSimpleHint ) &&
2713 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2715 pDocShell = NULL; // ungueltig geworden
2719 // XTableRows
2721 ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2723 SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
2724 if ( pDocShell && nRow <= nEndRow )
2725 return new ScTableRowObj( pDocShell, nRow, nTab );
2727 return NULL; // falscher Index
2730 void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
2731 throw(uno::RuntimeException)
2733 ScUnoGuard aGuard;
2734 BOOL bDone = FALSE;
2735 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
2736 nStartRow+nPosition+nCount-1 <= MAXROW )
2738 ScDocFunc aFunc(*pDocShell);
2739 ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
2740 MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
2741 bDone = aFunc.InsertCells( aRange, NULL, INS_INSROWS, TRUE, TRUE );
2743 if (!bDone)
2744 throw uno::RuntimeException(); // no other exceptions specified
2747 void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
2748 throw(uno::RuntimeException)
2750 ScUnoGuard aGuard;
2751 BOOL bDone = FALSE;
2752 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
2753 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
2755 ScDocFunc aFunc(*pDocShell);
2756 ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
2757 MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
2758 bDone = aFunc.DeleteCells( aRange, NULL, DEL_DELROWS, TRUE, TRUE );
2760 if (!bDone)
2761 throw uno::RuntimeException(); // no other exceptions specified
2764 // XEnumerationAccess
2766 uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
2767 throw(uno::RuntimeException)
2769 ScUnoGuard aGuard;
2770 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableRowsEnumeration")));
2773 // XIndexAccess
2775 sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException)
2777 ScUnoGuard aGuard;
2778 return nEndRow - nStartRow + 1;
2781 uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
2782 throw(lang::IndexOutOfBoundsException,
2783 lang::WrappedTargetException, uno::RuntimeException)
2785 ScUnoGuard aGuard;
2786 uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
2787 if (xRow.is())
2788 return uno::makeAny(xRow);
2789 else
2790 throw lang::IndexOutOfBoundsException();
2791 // return uno::Any();
2794 uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException)
2796 ScUnoGuard aGuard;
2797 return getCppuType((uno::Reference<table::XCellRange>*)0);
2800 sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException)
2802 ScUnoGuard aGuard;
2803 return ( getCount() != 0 );
2806 // XPropertySet
2808 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
2809 throw(uno::RuntimeException)
2811 ScUnoGuard aGuard;
2812 static uno::Reference<beans::XPropertySetInfo> aRef(
2813 new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
2814 return aRef;
2817 void SAL_CALL ScTableRowsObj::setPropertyValue(
2818 const rtl::OUString& aPropertyName, const uno::Any& aValue )
2819 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2820 lang::IllegalArgumentException, lang::WrappedTargetException,
2821 uno::RuntimeException)
2823 ScUnoGuard aGuard;
2824 if (!pDocShell)
2825 throw uno::RuntimeException();
2827 ScDocFunc aFunc(*pDocShell);
2828 ScDocument* pDoc = pDocShell->GetDocument();
2829 SCCOLROW nRowArr[2];
2830 nRowArr[0] = nStartRow;
2831 nRowArr[1] = nEndRow;
2832 String aNameString(aPropertyName);
2834 if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) )
2836 sal_Int32 nNewHeight = 0;
2837 if ( aValue >>= nNewHeight )
2838 aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_ORIGINAL,
2839 (USHORT)HMMToTwips(nNewHeight), TRUE, TRUE );
2841 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2843 BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2844 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
2845 aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, eMode, 0, TRUE, TRUE );
2846 // SC_SIZE_DIRECT with size 0: hide
2848 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) )
2850 //! undo etc.
2851 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
2852 pDoc->GetRowFlagsArrayModifiable( nTab).OrValue( nStartRow, nEndRow, CR_FILTERED);
2853 else
2854 pDoc->GetRowFlagsArrayModifiable( nTab).AndValue( nStartRow, nEndRow, sal::static_int_cast<BYTE>(~CR_FILTERED) );
2856 else if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) )
2858 BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2859 if (bOpt)
2860 aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, TRUE, TRUE );
2861 else
2863 //! manually set old heights again?
2866 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE) )
2868 //! single function to set/remove all breaks?
2869 BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2870 for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
2871 if (bSet)
2872 aFunc.InsertPageBreak( FALSE, ScAddress(0,nRow,nTab), TRUE, TRUE, TRUE );
2873 else
2874 aFunc.RemovePageBreak( FALSE, ScAddress(0,nRow,nTab), TRUE, TRUE, TRUE );
2876 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLBACK ) || aNameString.EqualsAscii( SC_UNONAME_CELLTRAN ) )
2878 // #i57867# Background color is specified for row styles in the file format,
2879 // so it has to be supported along with the row properties (import only).
2881 // Use ScCellRangeObj to set the property for all cells in the rows
2882 // (this means, the "row attribute" must be set before individual cell attributes).
2884 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
2885 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
2886 xRangeObj->setPropertyValue( aPropertyName, aValue );
2890 uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const rtl::OUString& aPropertyName )
2891 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2892 uno::RuntimeException)
2894 ScUnoGuard aGuard;
2895 if (!pDocShell)
2896 throw uno::RuntimeException();
2898 ScDocument* pDoc = pDocShell->GetDocument();
2899 String aNameString(aPropertyName);
2900 uno::Any aAny;
2902 //! loop over all rows for current state?
2904 if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) )
2906 // for hidden row, return original height
2907 USHORT nHeight = pDoc->GetOriginalHeight( nStartRow, nTab );
2908 aAny <<= (sal_Int32)TwipsToHMM(nHeight);
2910 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2912 BOOL bVis = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_HIDDEN);
2913 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
2915 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) )
2917 BOOL bVis = ((pDoc->GetRowFlags( nStartRow, nTab ) & CR_FILTERED) != 0);
2918 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
2920 else if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) )
2922 BOOL bOpt = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE);
2923 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
2925 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) )
2927 BOOL bBreak = ( 0 != (pDoc->GetRowFlags( nStartRow, nTab ) & (CR_PAGEBREAK|CR_MANUALBREAK)) );
2928 ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak );
2930 else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
2932 BOOL bBreak = ( 0 != (pDoc->GetRowFlags( nStartRow, nTab ) & (CR_MANUALBREAK)) );
2933 ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak );
2935 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLBACK ) || aNameString.EqualsAscii( SC_UNONAME_CELLTRAN ) )
2937 // Use ScCellRangeObj to get the property from the cell range
2938 // (for completeness only, this is not used by the XML filter).
2940 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
2941 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
2942 aAny = xRangeObj->getPropertyValue( aPropertyName );
2945 return aAny;
2948 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj )
2950 //------------------------------------------------------------------------
2952 //UNUSED2008-05 ScSpreadsheetSettingsObj::ScSpreadsheetSettingsObj(ScDocShell* pDocSh) :
2953 //UNUSED2008-05 pDocShell( pDocSh )
2954 //UNUSED2008-05 {
2955 //UNUSED2008-05 pDocShell->GetDocument()->AddUnoObject(*this);
2956 //UNUSED2008-05 }
2958 ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj()
2960 if (pDocShell)
2961 pDocShell->GetDocument()->RemoveUnoObject(*this);
2964 void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2966 // Referenz-Update interessiert hier nicht
2968 if ( rHint.ISA( SfxSimpleHint ) &&
2969 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2971 pDocShell = NULL; // ungueltig geworden
2975 // XPropertySet
2977 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo()
2978 throw(uno::RuntimeException)
2980 //! muss noch
2981 return NULL;
2984 void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue(
2985 const rtl::OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
2986 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2987 lang::IllegalArgumentException, lang::WrappedTargetException,
2988 uno::RuntimeException)
2990 //! muss noch
2993 uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const rtl::OUString& /* aPropertyName */ )
2994 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2995 uno::RuntimeException)
2997 //! muss noch
2998 return uno::Any();
3001 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj )
3003 //------------------------------------------------------------------------
3005 ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
3006 pDocShell( pDocSh ),
3007 nTab( nT )
3009 pDocShell->GetDocument()->AddUnoObject(*this);
3012 ScAnnotationsObj::~ScAnnotationsObj()
3014 if (pDocShell)
3015 pDocShell->GetDocument()->RemoveUnoObject(*this);
3018 void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3020 //! nTab bei Referenz-Update anpassen!!!
3022 if ( rHint.ISA( SfxSimpleHint ) &&
3023 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3025 pDocShell = NULL; // ungueltig geworden
3029 bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
3031 if (pDocShell)
3033 sal_Int32 nFound = 0;
3034 ScDocument* pDoc = pDocShell->GetDocument();
3035 ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab );
3036 for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext() )
3038 if (pCell->HasNote())
3040 if (nFound == nIndex)
3042 rPos = ScAddress( aCellIter.GetCol(), aCellIter.GetRow(), aCellIter.GetTab() );
3043 return true;
3045 ++nFound;
3049 return false;
3052 ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
3054 if (pDocShell)
3056 ScAddress aPos;
3057 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3058 return new ScAnnotationObj( pDocShell, aPos );
3060 return NULL;
3063 // XSheetAnnotations
3065 void SAL_CALL ScAnnotationsObj::insertNew(
3066 const table::CellAddress& aPosition, const ::rtl::OUString& rText )
3067 throw(uno::RuntimeException)
3069 ScUnoGuard aGuard;
3070 if (pDocShell)
3072 DBG_ASSERT( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
3073 ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
3075 ScDocFunc aFunc( *pDocShell );
3076 aFunc.ReplaceNote( aPos, rText, 0, 0, TRUE );
3080 void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException)
3082 ScUnoGuard aGuard;
3083 if (pDocShell)
3085 ScAddress aPos;
3086 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3088 ScMarkData aMarkData;
3089 aMarkData.SelectTable( aPos.Tab(), TRUE );
3090 aMarkData.SetMultiMarkArea( ScRange(aPos) );
3092 ScDocFunc aFunc(*pDocShell);
3093 aFunc.DeleteContents( aMarkData, IDF_NOTE, TRUE, TRUE );
3098 // XEnumerationAccess
3100 uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
3101 throw(uno::RuntimeException)
3103 //! iterate directly (more efficiently)?
3105 ScUnoGuard aGuard;
3106 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.CellAnnotationsEnumeration")));
3109 // XIndexAccess
3111 sal_Int32 SAL_CALL ScAnnotationsObj::getCount() throw(uno::RuntimeException)
3113 ScUnoGuard aGuard;
3114 ULONG nCount = 0;
3115 if (pDocShell)
3117 ScCellIterator aCellIter( pDocShell->GetDocument(), 0,0, nTab, MAXCOL,MAXROW, nTab );
3118 for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext() )
3119 if (pCell->HasNote())
3120 ++nCount;
3122 return nCount;
3125 uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
3126 throw(lang::IndexOutOfBoundsException,
3127 lang::WrappedTargetException, uno::RuntimeException)
3129 ScUnoGuard aGuard;
3130 uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
3131 if (xAnnotation.is())
3132 return uno::makeAny(xAnnotation);
3133 else
3134 throw lang::IndexOutOfBoundsException();
3135 // return uno::Any();
3138 uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException)
3140 ScUnoGuard aGuard;
3141 return getCppuType((uno::Reference<sheet::XSheetAnnotation>*)0);
3144 sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException)
3146 ScUnoGuard aGuard;
3147 return ( getCount() != 0 );
3150 //------------------------------------------------------------------------
3152 ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
3153 pDocShell( pDocSh ),
3154 nTab ( nT )
3156 pDocShell->GetDocument()->AddUnoObject(*this);
3159 ScScenariosObj::~ScScenariosObj()
3161 if (pDocShell)
3162 pDocShell->GetDocument()->RemoveUnoObject(*this);
3165 void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3167 if ( rHint.ISA( ScUpdateRefHint ) )
3169 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
3171 //! Referenz-Update fuer Tab und Start/Ende
3173 else if ( rHint.ISA( SfxSimpleHint ) &&
3174 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3176 pDocShell = NULL; // ungueltig geworden
3180 // XScenarios
3182 BOOL ScScenariosObj::GetScenarioIndex_Impl( const rtl::OUString& rName, SCTAB& rIndex )
3184 //! Case-insensitiv ????
3186 if ( pDocShell )
3188 String aString(rName);
3190 String aTabName;
3191 ScDocument* pDoc = pDocShell->GetDocument();
3192 SCTAB nCount = (SCTAB)getCount();
3193 for (SCTAB i=0; i<nCount; i++)
3194 if (pDoc->GetName( nTab+i+1, aTabName ))
3195 if ( aTabName == aString )
3197 rIndex = i;
3198 return TRUE;
3202 return FALSE;
3205 ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
3207 USHORT nCount = (USHORT)getCount();
3208 if ( pDocShell && nIndex >= 0 && nIndex < nCount )
3209 return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
3211 return NULL; // kein Dokument oder falscher Index
3214 ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const rtl::OUString& aName)
3216 SCTAB nIndex;
3217 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3218 return new ScTableSheetObj( pDocShell, nTab+nIndex+1 );
3220 return NULL; // nicht gefunden
3223 void SAL_CALL ScScenariosObj::addNewByName( const rtl::OUString& aName,
3224 const uno::Sequence<table::CellRangeAddress>& aRanges,
3225 const rtl::OUString& aComment )
3226 throw(uno::RuntimeException)
3228 ScUnoGuard aGuard;
3229 if ( pDocShell )
3231 ScMarkData aMarkData;
3232 aMarkData.SelectTable( nTab, TRUE );
3234 USHORT nRangeCount = (USHORT)aRanges.getLength();
3235 if (nRangeCount)
3237 const table::CellRangeAddress* pAry = aRanges.getConstArray();
3238 for (USHORT i=0; i<nRangeCount; i++)
3240 DBG_ASSERT( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
3241 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
3242 (SCCOL)pAry[i].EndColumn, (SCROW)pAry[i].EndRow, nTab );
3244 aMarkData.SetMultiMarkArea( aRange );
3248 String aNameStr(aName);
3249 String aCommStr(aComment);
3251 Color aColor( COL_LIGHTGRAY ); // Default
3252 USHORT nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
3254 pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
3258 void SAL_CALL ScScenariosObj::removeByName( const rtl::OUString& aName )
3259 throw(uno::RuntimeException)
3261 ScUnoGuard aGuard;
3262 SCTAB nIndex;
3263 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3265 ScDocFunc aFunc(*pDocShell);
3266 aFunc.DeleteTable( nTab+nIndex+1, TRUE, TRUE );
3270 // XEnumerationAccess
3272 uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
3273 throw(uno::RuntimeException)
3275 ScUnoGuard aGuard;
3276 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.ScenariosEnumeration")));
3279 // XIndexAccess
3281 sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException)
3283 ScUnoGuard aGuard;
3284 SCTAB nCount = 0;
3285 if ( pDocShell )
3287 ScDocument* pDoc = pDocShell->GetDocument();
3288 if (!pDoc->IsScenario(nTab))
3290 SCTAB nTabCount = pDoc->GetTableCount();
3291 SCTAB nNext = nTab + 1;
3292 while (nNext < nTabCount && pDoc->IsScenario(nNext))
3294 ++nCount;
3295 ++nNext;
3299 return nCount;
3302 uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
3303 throw(lang::IndexOutOfBoundsException,
3304 lang::WrappedTargetException, uno::RuntimeException)
3306 ScUnoGuard aGuard;
3307 uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
3308 if (xScen.is())
3309 return uno::makeAny(xScen);
3310 else
3311 throw lang::IndexOutOfBoundsException();
3312 // return uno::Any();
3315 uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException)
3317 ScUnoGuard aGuard;
3318 return getCppuType((uno::Reference<sheet::XScenario>*)0);
3321 sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException)
3323 ScUnoGuard aGuard;
3324 return ( getCount() != 0 );
3327 uno::Any SAL_CALL ScScenariosObj::getByName( const rtl::OUString& aName )
3328 throw(container::NoSuchElementException,
3329 lang::WrappedTargetException, uno::RuntimeException)
3331 ScUnoGuard aGuard;
3332 uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
3333 if (xScen.is())
3334 return uno::makeAny(xScen);
3335 else
3336 throw container::NoSuchElementException();
3337 // return uno::Any();
3340 uno::Sequence<rtl::OUString> SAL_CALL ScScenariosObj::getElementNames()
3341 throw(uno::RuntimeException)
3343 ScUnoGuard aGuard;
3344 SCTAB nCount = (SCTAB)getCount();
3345 uno::Sequence<rtl::OUString> aSeq(nCount);
3347 if ( pDocShell ) // sonst ist auch Count = 0
3349 String aTabName;
3350 ScDocument* pDoc = pDocShell->GetDocument();
3351 rtl::OUString* pAry = aSeq.getArray();
3352 for (SCTAB i=0; i<nCount; i++)
3353 if (pDoc->GetName( nTab+i+1, aTabName ))
3354 pAry[i] = aTabName;
3357 return aSeq;
3360 sal_Bool SAL_CALL ScScenariosObj::hasByName( const rtl::OUString& aName )
3361 throw(uno::RuntimeException)
3363 ScUnoGuard aGuard;
3364 SCTAB nIndex;
3365 return GetScenarioIndex_Impl( aName, nIndex );