merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / unoobj / docuno.cxx
blob26dbe62964f85fc1f094b4fe9f227b147db44a84
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 <com/sun/star/document/XDocumentEventBroadcaster.hpp>
64 #include <com/sun/star/script/XInvocation.hpp>
65 #include <com/sun/star/reflection/XIdlClassProvider.hpp>
66 #include <comphelper/processfactory.hxx>
68 #include "docuno.hxx"
69 #include "cellsuno.hxx"
70 #include "nameuno.hxx"
71 #include "datauno.hxx"
72 #include "miscuno.hxx"
73 #include "notesuno.hxx"
74 #include "styleuno.hxx"
75 #include "linkuno.hxx"
76 #include "servuno.hxx"
77 #include "targuno.hxx"
78 #include "convuno.hxx"
79 #include "optuno.hxx"
80 #include "forbiuno.hxx"
81 #include "docsh.hxx"
82 #include "hints.hxx"
83 #include "docfunc.hxx"
84 #include "dociter.hxx"
85 #include "cell.hxx"
86 #include "drwlayer.hxx"
87 #include "rangeutl.hxx"
88 #include "markdata.hxx"
89 #include "docoptio.hxx"
90 #include "unoguard.hxx"
91 #include "unonames.hxx"
92 #include "shapeuno.hxx"
93 #include "printfun.hxx"
94 #include "pfuncache.hxx"
95 #include "scmod.hxx"
96 #include "rangeutl.hxx"
97 #include "ViewSettingsSequenceDefines.hxx"
99 #ifndef _SVX_UNOSHAPE_HXX
100 #include <svx/unoshape.hxx>
101 #endif
103 #include <com/sun/star/document/XVbaEventsHelper.hpp>
104 #include <com/sun/star/document/VbaEventId.hpp>
105 using namespace com::sun::star;
106 using namespace com::sun::star::document::VbaEventId;
108 #define SC_UNO_VBADOCOBJ "ThisVBADocObj" // perhaps we want to actually make this ThisWorkbook ?
109 //------------------------------------------------------------------------
111 // alles ohne Which-ID, Map nur fuer PropertySetInfo
113 //! umbenennen, sind nicht mehr nur Options
114 const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap()
116 static SfxItemPropertyMapEntry aDocOptPropertyMap_Impl[] =
118 {MAP_CHAR_LEN(SC_UNO_APPLYFMDES), 0, &getBooleanCppuType(), 0, 0},
119 {MAP_CHAR_LEN(SC_UNO_AREALINKS), 0, &getCppuType((uno::Reference<sheet::XAreaLinks>*)0), 0, 0},
120 {MAP_CHAR_LEN(SC_UNO_AUTOCONTFOC), 0, &getBooleanCppuType(), 0, 0},
121 {MAP_CHAR_LEN(SC_UNO_BASICLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
122 {MAP_CHAR_LEN(SC_UNO_DIALOGLIBRARIES), 0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY, 0},
123 {MAP_CHAR_LEN(SC_UNO_VBADOCOBJ), 0, &getCppuType((beans::PropertyValue*)0), beans::PropertyAttribute::READONLY, 0},
124 {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), PROP_UNO_CALCASSHOWN, &getBooleanCppuType(), 0, 0},
125 {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
126 {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
127 {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0, 0},
128 {MAP_CHAR_LEN(SC_UNO_COLLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0, 0},
129 {MAP_CHAR_LEN(SC_UNO_DDELINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
130 {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), PROP_UNO_DEFTABSTOP, &getCppuType((sal_Int16*)0), 0, 0},
131 {MAP_CHAR_LEN(SC_UNO_EXTERNALDOCLINKS), 0, &getCppuType((uno::Reference<sheet::XExternalDocLinks>*)0), 0, 0},
132 {MAP_CHAR_LEN(SC_UNO_FORBIDDEN), 0, &getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0), beans::PropertyAttribute::READONLY, 0},
133 {MAP_CHAR_LEN(SC_UNO_HASDRAWPAGES), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
134 {MAP_CHAR_LEN(SC_UNO_IGNORECASE), PROP_UNO_IGNORECASE, &getBooleanCppuType(), 0, 0},
135 {MAP_CHAR_LEN(SC_UNO_ITERENABLED), PROP_UNO_ITERENABLED, &getBooleanCppuType(), 0, 0},
136 {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), PROP_UNO_ITERCOUNT, &getCppuType((sal_Int32*)0), 0, 0},
137 {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), PROP_UNO_ITEREPSILON, &getCppuType((double*)0), 0, 0},
138 {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), PROP_UNO_LOOKUPLABELS, &getBooleanCppuType(), 0, 0},
139 {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), PROP_UNO_MATCHWHOLE, &getBooleanCppuType(), 0, 0},
140 {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES), 0, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0), 0, 0},
141 {MAP_CHAR_LEN(SC_UNO_DATABASERNG), 0, &getCppuType((uno::Reference<sheet::XDatabaseRanges>*)0), 0, 0},
142 {MAP_CHAR_LEN(SC_UNO_NULLDATE), PROP_UNO_NULLDATE, &getCppuType((util::Date*)0), 0, 0},
143 {MAP_CHAR_LEN(SC_UNO_ROWLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0, 0},
144 {MAP_CHAR_LEN(SC_UNO_SHEETLINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0, 0},
145 {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), PROP_UNO_SPELLONLINE, &getBooleanCppuType(), 0, 0},
146 {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), PROP_UNO_STANDARDDEC, &getCppuType((sal_Int16*)0), 0, 0},
147 {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), PROP_UNO_REGEXENABLED, &getBooleanCppuType(), 0, 0},
148 {MAP_CHAR_LEN(SC_UNO_RUNTIMEUID), 0, &getCppuType(static_cast< const rtl::OUString * >(0)), beans::PropertyAttribute::READONLY, 0},
149 {MAP_CHAR_LEN(SC_UNO_HASVALIDSIGNATURES),0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0},
150 {MAP_CHAR_LEN(SC_UNO_ISLOADED), 0, &getBooleanCppuType(), 0, 0},
151 {MAP_CHAR_LEN(SC_UNO_ISUNDOENABLED), 0, &getBooleanCppuType(), 0, 0},
152 {MAP_CHAR_LEN(SC_UNO_ISADJUSTHEIGHTENABLED), 0, &getBooleanCppuType(), 0, 0},
153 {MAP_CHAR_LEN(SC_UNO_ISEXECUTELINKENABLED), 0, &getBooleanCppuType(), 0, 0},
154 {MAP_CHAR_LEN(SC_UNO_ISCHANGEREADONLYENABLED), 0, &getBooleanCppuType(), 0, 0},
155 {MAP_CHAR_LEN(SC_UNO_REFERENCEDEVICE), 0, &getCppuType((uno::Reference<awt::XDevice>*)0), beans::PropertyAttribute::READONLY, 0},
156 {MAP_CHAR_LEN("BuildId"), 0, &::getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0},
158 {0,0,0,0,0,0}
160 return aDocOptPropertyMap_Impl;
163 //! StandardDecimals als Property und vom NumberFormatter ????????
165 const SfxItemPropertyMapEntry* lcl_GetColumnsPropertyMap()
167 static SfxItemPropertyMapEntry aColumnsPropertyMap_Impl[] =
169 {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 },
170 {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 },
171 {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 },
172 {MAP_CHAR_LEN(SC_UNONAME_OWIDTH), 0, &getBooleanCppuType(), 0, 0 },
173 {MAP_CHAR_LEN(SC_UNONAME_CELLWID), 0, &getCppuType((sal_Int32*)0), 0, 0 },
174 {0,0,0,0,0,0}
176 return aColumnsPropertyMap_Impl;
179 const SfxItemPropertyMapEntry* lcl_GetRowsPropertyMap()
181 static SfxItemPropertyMapEntry aRowsPropertyMap_Impl[] =
183 {MAP_CHAR_LEN(SC_UNONAME_CELLHGT), 0, &getCppuType((sal_Int32*)0), 0, 0 },
184 {MAP_CHAR_LEN(SC_UNONAME_CELLFILT), 0, &getBooleanCppuType(), 0, 0 },
185 {MAP_CHAR_LEN(SC_UNONAME_OHEIGHT), 0, &getBooleanCppuType(), 0, 0 },
186 {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 },
187 {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 },
188 {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 },
189 {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR },
190 {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT },
191 // not sorted, not used with SfxItemPropertyMapEntry::GetByName
192 {0,0,0,0,0,0}
194 return aRowsPropertyMap_Impl;
197 //! move these functions to a header file
198 inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; }
199 inline long HMMToTwips(long nHMM) { return (nHMM * 72 + 63) / 127; }
201 //------------------------------------------------------------------------
203 #define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument"
204 #define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings"
205 #define SCDOC_SERVICE "com.sun.star.document.OfficeDocument"
207 SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
208 SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
209 SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" )
210 SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" )
211 SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" )
212 SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" )
213 SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" )
215 //------------------------------------------------------------------------
217 // static
218 void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
220 if (pDocSh)
221 pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
224 ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
225 SfxBaseModel( pDocSh ),
226 aPropSet( lcl_GetDocOptPropertyMap() ),
227 pDocShell( pDocSh ),
228 pPrintFuncCache( NULL ),
229 maChangesListeners( m_aMutex ),
230 mnXlsWriteProtPass( 0 )
232 // pDocShell may be NULL if this is the base of a ScDocOptionsObj
233 if ( pDocShell )
235 pDocShell->GetDocument()->AddUnoObject(*this); // SfxModel is derived from SfxListener
239 ScModelObj::~ScModelObj()
241 if (pDocShell)
242 pDocShell->GetDocument()->RemoveUnoObject(*this);
244 if (xNumberAgg.is())
245 xNumberAgg->setDelegator(uno::Reference<uno::XInterface>());
247 delete pPrintFuncCache;
250 uno::Reference< uno::XAggregation> ScModelObj::GetFormatter()
252 if ( !xNumberAgg.is() )
254 // setDelegator veraendert den RefCount, darum eine Referenz selber halten
255 // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen)
256 comphelper::increment( m_refCount );
257 // waehrend des queryInterface braucht man ein Ref auf das
258 // SvNumberFormatsSupplierObj, sonst wird es geloescht.
259 uno::Reference<util::XNumberFormatsSupplier> xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument()->GetFormatTable() ));
261 xNumberAgg.set(uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ));
262 // extra block to force deletion of the temporary before setDelegator
265 // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren
266 xFormatter = NULL;
268 if (xNumberAgg.is())
269 xNumberAgg->setDelegator( (cppu::OWeakObject*)this );
270 comphelper::decrement( m_refCount );
271 } // if ( !xNumberAgg.is() )
272 return xNumberAgg;
275 ScDocument* ScModelObj::GetDocument() const
277 if (pDocShell)
278 return pDocShell->GetDocument();
279 return NULL;
282 SfxObjectShell* ScModelObj::GetEmbeddedObject() const
284 return pDocShell;
287 void ScModelObj::UpdateAllRowHeights(const ScMarkData* pTabMark)
289 if (pDocShell)
290 pDocShell->UpdateAllRowHeights(pTabMark);
293 void ScModelObj::BeforeXMLLoading()
295 if (pDocShell)
296 pDocShell->BeforeXMLLoading();
299 void ScModelObj::AfterXMLLoading(sal_Bool bRet)
301 if (pDocShell)
302 pDocShell->AfterXMLLoading(bRet);
305 ScSheetSaveData* ScModelObj::GetSheetSaveData()
307 if (pDocShell)
308 return pDocShell->GetSheetSaveData();
309 return NULL;
312 uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
313 throw(uno::RuntimeException)
315 SC_QUERYINTERFACE( sheet::XSpreadsheetDocument )
316 SC_QUERYINTERFACE( document::XActionLockable )
317 SC_QUERYINTERFACE( sheet::XCalculatable )
318 SC_QUERYINTERFACE( util::XProtectable )
319 SC_QUERYINTERFACE( drawing::XDrawPagesSupplier )
320 SC_QUERYINTERFACE( sheet::XGoalSeek )
321 SC_QUERYINTERFACE( sheet::XConsolidatable )
322 SC_QUERYINTERFACE( sheet::XDocumentAuditing )
323 SC_QUERYINTERFACE( style::XStyleFamiliesSupplier )
324 SC_QUERYINTERFACE( view::XRenderable )
325 SC_QUERYINTERFACE( document::XLinkTargetSupplier )
326 SC_QUERYINTERFACE( beans::XPropertySet )
327 SC_QUERYINTERFACE( document::XDocumentEventCompatibleHelper)
328 SC_QUERYINTERFACE( lang::XMultiServiceFactory )
329 SC_QUERYINTERFACE( lang::XServiceInfo )
330 SC_QUERYINTERFACE( util::XChangesNotifier )
332 uno::Any aRet(SfxBaseModel::queryInterface( rType ));
333 if ( !aRet.hasValue()
334 && rType != ::getCppuType((uno::Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
335 && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XController>*)0)
336 && rType != ::getCppuType((uno::Reference< com::sun::star::frame::XFrame>*)0)
337 && rType != ::getCppuType((uno::Reference< com::sun::star::script::XInvocation>*)0)
338 && rType != ::getCppuType((uno::Reference< com::sun::star::reflection::XIdlClassProvider>*)0)
339 && rType != ::getCppuType((uno::Reference< com::sun::star::beans::XFastPropertySet>*)0)
340 && rType != ::getCppuType((uno::Reference< com::sun::star::awt::XWindow>*)0))
342 GetFormatter();
343 if ( xNumberAgg.is() )
344 aRet = xNumberAgg->queryAggregation( rType );
347 return aRet;
350 void SAL_CALL ScModelObj::acquire() throw()
352 SfxBaseModel::acquire();
355 void SAL_CALL ScModelObj::release() throw()
357 SfxBaseModel::release();
360 uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException)
362 static uno::Sequence<uno::Type> aTypes;
363 if ( aTypes.getLength() == 0 )
365 uno::Sequence<uno::Type> aParentTypes(SfxBaseModel::getTypes());
366 long nParentLen = aParentTypes.getLength();
367 const uno::Type* pParentPtr = aParentTypes.getConstArray();
369 uno::Sequence<uno::Type> aAggTypes;
370 if ( GetFormatter().is() )
372 const uno::Type& rProvType = ::getCppuType((uno::Reference<lang::XTypeProvider>*) 0);
373 uno::Any aNumProv(xNumberAgg->queryAggregation(rProvType));
374 if(aNumProv.getValueType() == rProvType)
376 uno::Reference<lang::XTypeProvider> xNumProv(
377 *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue());
378 aAggTypes = xNumProv->getTypes();
381 long nAggLen = aAggTypes.getLength();
382 const uno::Type* pAggPtr = aAggTypes.getConstArray();
384 const long nThisLen = 15;
385 aTypes.realloc( nParentLen + nAggLen + nThisLen );
386 uno::Type* pPtr = aTypes.getArray();
387 pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetDocument>*)0);
388 pPtr[nParentLen + 1] = getCppuType((const uno::Reference<document::XActionLockable>*)0);
389 pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XCalculatable>*)0);
390 pPtr[nParentLen + 3] = getCppuType((const uno::Reference<util::XProtectable>*)0);
391 pPtr[nParentLen + 4] = getCppuType((const uno::Reference<drawing::XDrawPagesSupplier>*)0);
392 pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XGoalSeek>*)0);
393 pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XConsolidatable>*)0);
394 pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XDocumentAuditing>*)0);
395 pPtr[nParentLen + 8] = getCppuType((const uno::Reference<style::XStyleFamiliesSupplier>*)0);
396 pPtr[nParentLen + 9] = getCppuType((const uno::Reference<view::XRenderable>*)0);
397 pPtr[nParentLen +10] = getCppuType((const uno::Reference<document::XLinkTargetSupplier>*)0);
398 pPtr[nParentLen +11] = getCppuType((const uno::Reference<beans::XPropertySet>*)0);
399 pPtr[nParentLen +12] = getCppuType((const uno::Reference<lang::XMultiServiceFactory>*)0);
400 pPtr[nParentLen +13] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0);
401 pPtr[nParentLen +14] = getCppuType((const uno::Reference<util::XChangesNotifier>*)0);
403 long i;
404 for (i=0; i<nParentLen; i++)
405 pPtr[i] = pParentPtr[i]; // parent types first
407 for (i=0; i<nAggLen; i++)
408 pPtr[nParentLen+nThisLen+i] = pAggPtr[i]; // aggregated types last
410 return aTypes;
413 uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId()
414 throw(uno::RuntimeException)
416 static uno::Sequence< sal_Int8 > aId;
417 if( aId.getLength() == 0 )
419 aId.realloc( 16 );
420 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
422 return aId;
425 void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
427 // Not interested in reference update hints here
429 if ( rHint.ISA( SfxSimpleHint ) )
431 ULONG nId = ((const SfxSimpleHint&)rHint).GetId();
432 if ( nId == SFX_HINT_DYING )
434 pDocShell = NULL; // has become invalid
435 if (xNumberAgg.is())
437 SvNumberFormatsSupplierObj* pNumFmt =
438 SvNumberFormatsSupplierObj::getImplementation(
439 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
440 if ( pNumFmt )
441 pNumFmt->SetNumberFormatter( NULL );
444 DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell
446 else if ( nId == SFX_HINT_DATACHANGED )
448 // cached data for rendering become invalid when contents change
449 // (if a broadcast is added to SetDrawModified, is has to be tested here, too)
451 DELETEZ( pPrintFuncCache );
454 else if ( rHint.ISA( ScPointerChangedHint ) )
456 USHORT nFlags = ((const ScPointerChangedHint&)rHint).GetFlags();
457 if (nFlags & SC_POINTERCHANGED_NUMFMT)
459 // NumberFormatter-Pointer am Uno-Objekt neu setzen
461 if (GetFormatter().is())
463 SvNumberFormatsSupplierObj* pNumFmt =
464 SvNumberFormatsSupplierObj::getImplementation(
465 uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) );
466 if ( pNumFmt && pDocShell )
467 pNumFmt->SetNumberFormatter( pDocShell->GetDocument()->GetFormatTable() );
472 // always call parent - SfxBaseModel might need to handle the same hints again
473 SfxBaseModel::Notify( rBC, rHint ); // SfxBaseModel is derived from SfxListener
476 // XSpreadsheetDocument
478 uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException)
480 ScUnoGuard aGuard;
481 if (pDocShell)
482 return new ScTableSheetsObj(pDocShell);
483 return NULL;
486 // XStyleFamiliesSupplier
488 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
489 throw(uno::RuntimeException)
491 ScUnoGuard aGuard;
492 if (pDocShell)
493 return new ScStyleFamiliesObj(pDocShell);
494 return NULL;
497 // XRenderable
499 OutputDevice* lcl_GetRenderDevice( const uno::Sequence<beans::PropertyValue>& rOptions )
501 OutputDevice* pRet = NULL;
502 const beans::PropertyValue* pPropArray = rOptions.getConstArray();
503 long nPropCount = rOptions.getLength();
504 for (long i = 0; i < nPropCount; i++)
506 const beans::PropertyValue& rProp = pPropArray[i];
507 String aPropName(rProp.Name);
509 if (aPropName.EqualsAscii( SC_UNONAME_RENDERDEV ))
511 uno::Reference<awt::XDevice> xRenderDevice(rProp.Value, uno::UNO_QUERY);
512 if ( xRenderDevice.is() )
514 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
515 if ( pDevice )
517 pRet = pDevice->GetOutputDevice();
518 pRet->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
523 return pRet;
526 bool lcl_ParseTarget( const String& rTarget, ScRange& rTargetRange, Rectangle& rTargetRect,
527 bool& rIsSheet, ScDocument* pDoc, SCTAB nSourceTab )
529 // test in same order as in SID_CURRENTCELL execute
531 ScAddress aAddress;
532 ScRangeUtil aRangeUtil;
533 SCTAB nNameTab;
534 sal_Int32 nNumeric = 0;
536 bool bRangeValid = false;
537 bool bRectValid = false;
539 if ( rTargetRange.Parse( rTarget, pDoc ) & SCA_VALID )
541 bRangeValid = true; // range reference
543 else if ( aAddress.Parse( rTarget, pDoc ) & SCA_VALID )
545 rTargetRange = aAddress;
546 bRangeValid = true; // cell reference
548 else if ( aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_NAMES ) ||
549 aRangeUtil.MakeRangeFromName( rTarget, pDoc, nSourceTab, rTargetRange, RUTL_DBASE ) )
551 bRangeValid = true; // named range or database range
553 else if ( ByteString( rTarget, RTL_TEXTENCODING_ASCII_US ).IsNumericAscii() &&
554 ( nNumeric = rTarget.ToInt32() ) > 0 && nNumeric <= MAXROW+1 )
556 // row number is always mapped to cell A(row) on the same sheet
557 rTargetRange = ScAddress( 0, (SCROW)(nNumeric-1), nSourceTab ); // target row number is 1-based
558 bRangeValid = true; // row number
560 else if ( pDoc->GetTable( rTarget, nNameTab ) )
562 rTargetRange = ScAddress(0,0,nNameTab);
563 bRangeValid = true; // sheet name
564 rIsSheet = true; // needs special handling (first page of the sheet)
566 else
568 // look for named drawing object
570 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
571 if ( pDrawLayer )
573 SCTAB nTabCount = pDoc->GetTableCount();
574 for (SCTAB i=0; i<nTabCount && !bRangeValid; i++)
576 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(i));
577 DBG_ASSERT(pPage,"Page ?");
578 if (pPage)
580 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
581 SdrObject* pObject = aIter.Next();
582 while (pObject && !bRangeValid)
584 if ( ScDrawLayer::GetVisibleName( pObject ) == rTarget )
586 rTargetRect = pObject->GetLogicRect(); // 1/100th mm
587 rTargetRange = pDoc->GetRange( i, rTargetRect ); // underlying cells
588 bRangeValid = bRectValid = true; // rectangle is valid
590 pObject = aIter.Next();
596 if ( bRangeValid && !bRectValid )
598 // get rectangle for cell range
599 rTargetRect = pDoc->GetMMRect( rTargetRange.aStart.Col(), rTargetRange.aStart.Row(),
600 rTargetRange.aEnd.Col(), rTargetRange.aEnd.Row(),
601 rTargetRange.aStart.Tab() );
604 return bRangeValid;
607 BOOL ScModelObj::FillRenderMarkData( const uno::Any& aSelection, ScMarkData& rMark,
608 ScPrintSelectionStatus& rStatus ) const
610 DBG_ASSERT( !rMark.IsMarked() && !rMark.IsMultiMarked(), "FillRenderMarkData: MarkData must be empty" );
611 DBG_ASSERT( pDocShell, "FillRenderMarkData: DocShell must be set" );
613 BOOL bDone = FALSE;
615 uno::Reference<uno::XInterface> xInterface(aSelection, uno::UNO_QUERY);
616 if ( xInterface.is() )
618 ScCellRangesBase* pSelObj = ScCellRangesBase::getImplementation( xInterface );
619 uno::Reference< drawing::XShapes > xShapes( xInterface, uno::UNO_QUERY );
621 if ( pSelObj && pSelObj->GetDocShell() == pDocShell )
623 BOOL bSheet = ( ScTableSheetObj::getImplementation( xInterface ) != NULL );
624 BOOL bCursor = pSelObj->IsCursorOnly();
625 const ScRangeList& rRanges = pSelObj->GetRangeList();
627 rMark.MarkFromRangeList( rRanges, FALSE );
628 rMark.MarkToSimple();
630 if ( rMark.IsMarked() && !rMark.IsMultiMarked() )
632 // a sheet object is treated like an empty selection: print the used area of the sheet
634 if ( bCursor || bSheet ) // nothing selected -> use whole tables
636 rMark.ResetMark(); // doesn't change table selection
637 rStatus.SetMode( SC_PRINTSEL_CURSOR );
639 else
640 rStatus.SetMode( SC_PRINTSEL_RANGE );
642 rStatus.SetRanges( rRanges );
643 bDone = TRUE;
645 // multi selection isn't supported
647 else if( xShapes.is() )
649 //print a selected ole object
650 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY );
651 if( xIndexAccess.is() )
653 // multi selection isn't supported yet
654 uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
655 SvxShape* pShape = SvxShape::getImplementation( xShape );
656 if( pShape )
658 SdrObject *pSdrObj = pShape->GetSdrObject();
659 if( pDocShell )
661 ScDocument* pDoc = pDocShell->GetDocument();
662 if( pDoc && pSdrObj )
664 Rectangle aObjRect = pSdrObj->GetCurrentBoundRect();
665 SCTAB nCurrentTab = ScDocShell::GetCurTab();
666 ScRange aRange = pDoc->GetRange( nCurrentTab, aObjRect );
667 rMark.SetMarkArea( aRange );
669 if( rMark.IsMarked() && !rMark.IsMultiMarked() )
671 rStatus.SetMode( SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS );
672 bDone = TRUE;
679 else if ( ScModelObj::getImplementation( xInterface ) == this )
681 // render the whole document
682 // -> no selection, all sheets
684 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
685 for (SCTAB nTab = 0; nTab < nTabCount; nTab++)
686 rMark.SelectTable( nTab, TRUE );
687 rStatus.SetMode( SC_PRINTSEL_DOCUMENT );
688 bDone = TRUE;
690 // other selection types aren't supported
693 return bDone;
697 sal_Int32 SAL_CALL ScModelObj::getRendererCount( const uno::Any& aSelection,
698 const uno::Sequence<beans::PropertyValue>& /* xOptions */ )
699 throw (lang::IllegalArgumentException, uno::RuntimeException)
701 ScUnoGuard aGuard;
702 if (!pDocShell)
703 throw uno::RuntimeException();
705 ScMarkData aMark;
706 ScPrintSelectionStatus aStatus;
707 if ( !FillRenderMarkData( aSelection, aMark, aStatus ) )
708 return 0;
710 // The same ScPrintFuncCache object in pPrintFuncCache is used as long as
711 // the same selection is used (aStatus) and the document isn't changed
712 // (pPrintFuncCache is cleared in Notify handler)
714 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
716 delete pPrintFuncCache;
717 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
719 return pPrintFuncCache->GetPageCount();
722 uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 nRenderer,
723 const uno::Any& aSelection, const uno::Sequence<beans::PropertyValue>& /* xOptions */ )
724 throw (lang::IllegalArgumentException, uno::RuntimeException)
726 ScUnoGuard aGuard;
727 if (!pDocShell)
728 throw uno::RuntimeException();
730 ScMarkData aMark;
731 ScPrintSelectionStatus aStatus;
732 if ( !FillRenderMarkData( aSelection, aMark, aStatus ) )
733 throw lang::IllegalArgumentException();
735 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
737 delete pPrintFuncCache;
738 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
740 long nTotalPages = pPrintFuncCache->GetPageCount();
741 if ( nRenderer >= nTotalPages )
742 throw lang::IllegalArgumentException();
744 // printer is used as device (just for page layout), draw view is not needed
746 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
748 ScRange aRange;
749 const ScRange* pSelRange = NULL;
750 if ( aMark.IsMarked() )
752 aMark.GetMarkArea( aRange );
753 pSelRange = &aRange;
755 ScPrintFunc aFunc( pDocShell, pDocShell->GetPrinter(), nTab,
756 pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange );
757 aFunc.SetRenderFlag( TRUE );
759 Range aPageRange( nRenderer+1, nRenderer+1 );
760 MultiSelection aPage( aPageRange );
761 aPage.SetTotalRange( Range(0,RANGE_MAX) );
762 aPage.Select( aPageRange );
764 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
765 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
767 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, FALSE, NULL, NULL );
769 ScRange aCellRange;
770 BOOL bWasCellRange = aFunc.GetLastSourceRange( aCellRange );
771 Size aTwips = aFunc.GetPageSize();
772 awt::Size aPageSize( TwipsToHMM( aTwips.Width() ), TwipsToHMM( aTwips.Height() ) );
774 long nPropCount = bWasCellRange ? 2 : 1;
775 uno::Sequence<beans::PropertyValue> aSequence(nPropCount);
776 beans::PropertyValue* pArray = aSequence.getArray();
777 pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_PAGESIZE );
778 pArray[0].Value <<= aPageSize;
779 if ( bWasCellRange )
781 table::CellRangeAddress aRangeAddress( nTab,
782 aCellRange.aStart.Col(), aCellRange.aStart.Row(),
783 aCellRange.aEnd.Col(), aCellRange.aEnd.Row() );
784 pArray[1].Name = rtl::OUString::createFromAscii( SC_UNONAME_SOURCERANGE );
785 pArray[1].Value <<= aRangeAddress;
787 return aSequence;
790 void SAL_CALL ScModelObj::render( sal_Int32 nRenderer, const uno::Any& aSelection,
791 const uno::Sequence<beans::PropertyValue>& rOptions )
792 throw(lang::IllegalArgumentException, uno::RuntimeException)
794 ScUnoGuard aGuard;
795 if (!pDocShell)
796 throw uno::RuntimeException();
798 ScMarkData aMark;
799 ScPrintSelectionStatus aStatus;
800 if ( !FillRenderMarkData( aSelection, aMark, aStatus ) )
801 throw lang::IllegalArgumentException();
803 if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
805 delete pPrintFuncCache;
806 pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus );
808 long nTotalPages = pPrintFuncCache->GetPageCount();
809 if ( nRenderer >= nTotalPages )
810 throw lang::IllegalArgumentException();
812 OutputDevice* pDev = lcl_GetRenderDevice( rOptions );
813 if ( !pDev )
814 throw lang::IllegalArgumentException();
816 SCTAB nTab = pPrintFuncCache->GetTabForPage( nRenderer );
817 ScDocument* pDoc = pDocShell->GetDocument();
819 FmFormView* pDrawView = NULL;
820 Rectangle aFull( 0, 0, LONG_MAX, LONG_MAX );
822 // #114135#
823 ScDrawLayer* pModel = pDoc->GetDrawLayer();
825 if( pModel )
827 pDrawView = new FmFormView( pModel, pDev );
828 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
829 pDrawView->SetPrintPreview( TRUE );
832 ScRange aRange;
833 const ScRange* pSelRange = NULL;
834 if ( aMark.IsMarked() )
836 aMark.GetMarkArea( aRange );
837 pSelRange = &aRange;
840 // to increase performance, ScPrintState might be used here for subsequent
841 // pages of the same sheet
843 ScPrintFunc aFunc( pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange );
844 aFunc.SetDrawView( pDrawView );
845 aFunc.SetRenderFlag( TRUE );
846 if( aStatus.GetMode() == SC_PRINTSEL_RANGE_EXCLUSIVELY_OLE_AND_DRAW_OBJECTS )
847 aFunc.SetExclusivelyDrawOleAndDrawObjects();
849 Range aPageRange( nRenderer+1, nRenderer+1 );
850 MultiSelection aPage( aPageRange );
851 aPage.SetTotalRange( Range(0,RANGE_MAX) );
852 aPage.Select( aPageRange );
854 long nDisplayStart = pPrintFuncCache->GetDisplayStart( nTab );
855 long nTabStart = pPrintFuncCache->GetTabStart( nTab );
857 if ( nRenderer == nTabStart )
859 // first page of a sheet: add outline item for the sheet name
861 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
862 if ( pPDFData && pPDFData->GetIsExportBookmarks() )
864 // the sheet starts at the top of the page
865 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
866 sal_Int32 nDestID = pPDFData->CreateDest( aArea );
867 String aTabName;
868 pDoc->GetName( nTab, aTabName );
869 sal_Int32 nParent = -1; // top-level
870 pPDFData->CreateOutlineItem( nParent, aTabName, nDestID );
872 //--->i56629
873 // add the named destination stuff
874 if( pPDFData->GetIsExportNamedDestinations() )
876 Rectangle aArea( pDev->PixelToLogic( Rectangle( 0,0,0,0 ) ) );
877 String aTabName;
878 pDoc->GetName( nTab, aTabName );
879 //need the PDF page number here
880 pPDFData->CreateNamedDest( aTabName, aArea );
882 //<---i56629
885 (void)aFunc.DoPrint( aPage, nTabStart, nDisplayStart, TRUE, NULL, NULL );
887 // resolve the hyperlinks for PDF export
889 vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, pDev->GetExtOutDevData() );
890 if ( pPDFData )
892 // iterate over the hyperlinks that were output for this page
894 std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFData->GetBookmarks();
895 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIter = rBookmarks.begin();
896 std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
897 while ( aIter != aIEnd )
899 rtl::OUString aBookmark = aIter->aBookmark;
900 if ( aBookmark.toChar() == (sal_Unicode) '#' )
902 // try to resolve internal link
904 String aTarget( aBookmark.copy( 1 ) );
906 ScRange aTargetRange;
907 Rectangle aTargetRect; // 1/100th mm
908 bool bIsSheet = false;
909 bool bValid = lcl_ParseTarget( aTarget, aTargetRange, aTargetRect, bIsSheet, pDoc, nTab );
911 if ( bValid )
913 sal_Int32 nPage = -1;
914 Rectangle aArea;
915 if ( bIsSheet )
917 // Get first page for sheet (if nothing from that sheet is printed,
918 // this page can show a different sheet)
919 nPage = pPrintFuncCache->GetTabStart( aTargetRange.aStart.Tab() );
920 aArea = pDev->PixelToLogic( Rectangle( 0,0,0,0 ) );
922 else
924 pPrintFuncCache->InitLocations( aMark, pDev ); // does nothing if already initialized
926 ScPrintPageLocation aLocation;
927 if ( pPrintFuncCache->FindLocation( aTargetRange.aStart, aLocation ) )
929 nPage = aLocation.nPage;
931 // get the rectangle of the page's cell range in 1/100th mm
932 ScRange aLocRange = aLocation.aCellRange;
933 Rectangle aLocationMM = pDoc->GetMMRect(
934 aLocRange.aStart.Col(), aLocRange.aStart.Row(),
935 aLocRange.aEnd.Col(), aLocRange.aEnd.Row(),
936 aLocRange.aStart.Tab() );
937 Rectangle aLocationPixel = aLocation.aRectangle;
939 // Scale and move the target rectangle from aLocationMM to aLocationPixel,
940 // to get the target rectangle in pixels.
942 Fraction aScaleX( aLocationPixel.GetWidth(), aLocationMM.GetWidth() );
943 Fraction aScaleY( aLocationPixel.GetHeight(), aLocationMM.GetHeight() );
945 long nX1 = aLocationPixel.Left() + (long)
946 ( Fraction( aTargetRect.Left() - aLocationMM.Left(), 1 ) * aScaleX );
947 long nX2 = aLocationPixel.Left() + (long)
948 ( Fraction( aTargetRect.Right() - aLocationMM.Left(), 1 ) * aScaleX );
949 long nY1 = aLocationPixel.Top() + (long)
950 ( Fraction( aTargetRect.Top() - aLocationMM.Top(), 1 ) * aScaleY );
951 long nY2 = aLocationPixel.Top() + (long)
952 ( Fraction( aTargetRect.Bottom() - aLocationMM.Top(), 1 ) * aScaleY );
954 if ( nX1 > aLocationPixel.Right() ) nX1 = aLocationPixel.Right();
955 if ( nX2 > aLocationPixel.Right() ) nX2 = aLocationPixel.Right();
956 if ( nY1 > aLocationPixel.Bottom() ) nY1 = aLocationPixel.Bottom();
957 if ( nY2 > aLocationPixel.Bottom() ) nY2 = aLocationPixel.Bottom();
959 // The link target area is interpreted using the device's MapMode at
960 // the time of the CreateDest call, so PixelToLogic can be used here,
961 // regardless of the MapMode that is actually selected.
963 aArea = pDev->PixelToLogic( Rectangle( nX1, nY1, nX2, nY2 ) );
967 if ( nPage >= 0 )
968 pPDFData->SetLinkDest( aIter->nLinkId, pPDFData->CreateDest( aArea, nPage ) );
971 else
973 // external link, use as-is
974 pPDFData->SetLinkURL( aIter->nLinkId, aBookmark );
976 aIter++;
978 rBookmarks.clear();
981 delete pDrawView;
984 // XLinkTargetSupplier
986 uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException)
988 ScUnoGuard aGuard;
989 if (pDocShell)
990 return new ScLinkTargetTypesObj(pDocShell);
991 return NULL;
994 // XActionLockable
996 sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException)
998 ScUnoGuard aGuard;
999 BOOL bLocked = FALSE;
1000 if (pDocShell)
1001 bLocked = ( pDocShell->GetLockCount() != 0 );
1002 return bLocked;
1005 void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException)
1007 ScUnoGuard aGuard;
1008 if (pDocShell)
1009 pDocShell->LockDocument();
1012 void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException)
1014 ScUnoGuard aGuard;
1015 if (pDocShell)
1016 pDocShell->UnlockDocument();
1019 void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException)
1021 ScUnoGuard aGuard;
1022 if (pDocShell)
1023 pDocShell->SetLockCount(nLock);
1026 sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException)
1028 ScUnoGuard aGuard;
1029 USHORT nRet = 0;
1030 if (pDocShell)
1032 nRet = pDocShell->GetLockCount();
1033 pDocShell->SetLockCount(0);
1035 return nRet;
1038 void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException)
1040 ScUnoGuard aGuard;
1041 SfxBaseModel::lockControllers();
1042 if (pDocShell)
1043 pDocShell->LockPaint();
1046 void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException)
1048 ScUnoGuard aGuard;
1049 if (hasControllersLocked())
1051 SfxBaseModel::unlockControllers();
1052 if (pDocShell)
1053 pDocShell->UnlockPaint();
1057 // XCalculate
1059 void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException)
1061 ScUnoGuard aGuard;
1062 if (pDocShell)
1063 pDocShell->DoRecalc(TRUE);
1064 else
1066 DBG_ERROR("keine DocShell"); //! Exception oder so?
1070 void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException)
1072 ScUnoGuard aGuard;
1073 if (pDocShell)
1074 pDocShell->DoHardRecalc(TRUE);
1075 else
1077 DBG_ERROR("keine DocShell"); //! Exception oder so?
1081 sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException)
1083 ScUnoGuard aGuard;
1084 if (pDocShell)
1085 return pDocShell->GetDocument()->GetAutoCalc();
1087 DBG_ERROR("keine DocShell"); //! Exception oder so?
1088 return FALSE;
1091 void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabled )
1092 throw(uno::RuntimeException)
1094 ScUnoGuard aGuard;
1095 if (pDocShell)
1097 ScDocument* pDoc = pDocShell->GetDocument();
1098 if ( pDoc->GetAutoCalc() != bEnabled )
1100 pDoc->SetAutoCalc( bEnabled );
1101 pDocShell->SetDocumentModified();
1104 else
1106 DBG_ERROR("keine DocShell"); //! Exception oder so?
1110 // XProtectable
1112 void SAL_CALL ScModelObj::protect( const rtl::OUString& aPassword ) throw(uno::RuntimeException)
1114 ScUnoGuard aGuard;
1115 if (pDocShell)
1117 String aString(aPassword);
1119 ScDocFunc aFunc(*pDocShell);
1120 aFunc.Protect( TABLEID_DOC, aString, TRUE );
1124 void SAL_CALL ScModelObj::unprotect( const rtl::OUString& aPassword )
1125 throw(lang::IllegalArgumentException, uno::RuntimeException)
1127 ScUnoGuard aGuard;
1128 if (pDocShell)
1130 String aString(aPassword);
1132 ScDocFunc aFunc(*pDocShell);
1133 aFunc.Unprotect( TABLEID_DOC, aString, TRUE );
1135 //! Rueckgabewert auswerten, Exception oder so
1139 sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException)
1141 ScUnoGuard aGuard;
1142 if (pDocShell)
1143 return pDocShell->GetDocument()->IsDocProtected();
1145 DBG_ERROR("keine DocShell"); //! Exception oder so?
1146 return FALSE;
1149 // XDrawPagesSupplier
1151 uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException)
1153 ScUnoGuard aGuard;
1154 if (pDocShell)
1155 return new ScDrawPagesObj(pDocShell);
1157 DBG_ERROR("keine DocShell"); //! Exception oder so?
1158 return NULL;
1161 #if 0
1162 // XPrintable
1164 rtl::OUString ScModelObj::getPrinterName(void) const
1166 ScUnoGuard aGuard;
1167 if (pDocShell)
1169 SfxPrinter* pPrinter = pDocShell->GetPrinter();
1170 if (pPrinter)
1171 return pPrinter->GetName();
1174 DBG_ERROR("getPrinterName: keine DocShell oder kein Printer");
1175 return rtl::OUString();
1178 void ScModelObj::setPrinterName(const rtl::OUString& PrinterName)
1180 ScUnoGuard aGuard;
1181 // Drucker setzen - wie in SfxViewShell::ExecPrint_Impl
1183 if (pDocShell)
1185 SfxPrinter* pPrinter = pDocShell->GetPrinter();
1186 if (pPrinter)
1188 String aString(PrinterName);
1189 SfxPrinter* pNewPrinter = new SfxPrinter( pPrinter->GetOptions().Clone(), aString );
1190 if (pNewPrinter->IsKnown())
1191 pDocShell->SetPrinter( pNewPrinter, SFX_PRINTER_PRINTER );
1192 else
1193 delete pNewPrinter;
1198 XPropertySetRef ScModelObj::createPrintOptions(void)
1200 ScUnoGuard aGuard;
1201 return new ScPrintSettingsObj; //! ScPrintSettingsObj implementieren!
1204 void ScModelObj::print(const XPropertySetRef& xOptions)
1206 ScUnoGuard aGuard;
1207 if (pDocShell)
1209 //! xOptions auswerten (wie denn?)
1211 //! muss noch
1214 #endif
1216 // XGoalSeek
1218 sheet::GoalResult SAL_CALL ScModelObj::seekGoal(
1219 const table::CellAddress& aFormulaPosition,
1220 const table::CellAddress& aVariablePosition,
1221 const ::rtl::OUString& aGoalValue )
1222 throw(uno::RuntimeException)
1224 ScUnoGuard aGuard;
1225 sheet::GoalResult aResult;
1226 aResult.Divergence = DBL_MAX; // nichts gefunden
1227 if (pDocShell)
1229 WaitObject aWait( pDocShell->GetActiveDialogParent() );
1230 String aGoalString(aGoalValue);
1231 ScDocument* pDoc = pDocShell->GetDocument();
1232 double fValue = 0.0;
1233 BOOL bFound = pDoc->Solver(
1234 (SCCOL)aFormulaPosition.Column, (SCROW)aFormulaPosition.Row, aFormulaPosition.Sheet,
1235 (SCCOL)aVariablePosition.Column, (SCROW)aVariablePosition.Row, aVariablePosition.Sheet,
1236 aGoalString, fValue );
1237 aResult.Result = fValue;
1238 if (bFound)
1239 aResult.Divergence = 0.0; //! das ist gelogen
1241 return aResult;
1244 // XConsolidatable
1246 uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor(
1247 sal_Bool bEmpty ) throw(uno::RuntimeException)
1249 ScUnoGuard aGuard;
1250 ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor;
1251 if ( pDocShell && !bEmpty )
1253 ScDocument* pDoc = pDocShell->GetDocument();
1254 const ScConsolidateParam* pParam = pDoc->GetConsolidateDlgData();
1255 if (pParam)
1256 pNew->SetParam( *pParam );
1258 return pNew;
1261 void SAL_CALL ScModelObj::consolidate(
1262 const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor )
1263 throw(uno::RuntimeException)
1265 ScUnoGuard aGuard;
1266 // das koennte theoretisch ein fremdes Objekt sein, also nur das
1267 // oeffentliche XConsolidationDescriptor Interface benutzen, um
1268 // die Daten in ein ScConsolidationDescriptor Objekt zu kopieren:
1269 //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation?
1271 ScConsolidationDescriptor aImpl;
1272 aImpl.setFunction( xDescriptor->getFunction() );
1273 aImpl.setSources( xDescriptor->getSources() );
1274 aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() );
1275 aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() );
1276 aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() );
1277 aImpl.setInsertLinks( xDescriptor->getInsertLinks() );
1279 if (pDocShell)
1281 const ScConsolidateParam& rParam = aImpl.GetParam();
1282 pDocShell->DoConsolidate( rParam, TRUE );
1283 pDocShell->GetDocument()->SetConsolidateDlgData( &rParam );
1287 // XDocumentAuditing
1289 void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException)
1291 ScUnoGuard aGuard;
1292 if (pDocShell)
1294 ScDocFunc aFunc(*pDocShell);
1295 aFunc.DetectiveRefresh();
1299 // XViewDataSupplier
1300 uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData( )
1301 throw (uno::RuntimeException)
1303 uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
1305 if( !xRet.is() )
1307 ScUnoGuard aGuard;
1308 if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED)
1310 xRet.set(uno::Reference < container::XIndexAccess >::query(::comphelper::getProcessServiceFactory()->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")))));
1312 uno::Reference < container::XIndexContainer > xCont( xRet, uno::UNO_QUERY );
1313 DBG_ASSERT( xCont.is(), "ScModelObj::getViewData() failed for OLE object" );
1314 if( xCont.is() )
1316 uno::Sequence< beans::PropertyValue > aSeq;
1317 aSeq.realloc(1);
1318 String sName;
1319 pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName );
1320 rtl::OUString sOUName(sName);
1321 aSeq[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ACTIVETABLE));
1322 aSeq[0].Value <<= sOUName;
1323 xCont->insertByIndex( 0, uno::makeAny( aSeq ) );
1328 return xRet;
1331 // XPropertySet (Doc-Optionen)
1332 //! auch an der Applikation anbieten?
1334 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo()
1335 throw(uno::RuntimeException)
1337 ScUnoGuard aGuard;
1338 static uno::Reference<beans::XPropertySetInfo> aRef(
1339 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
1340 return aRef;
1343 void SAL_CALL ScModelObj::setPropertyValue(
1344 const rtl::OUString& aPropertyName, const uno::Any& aValue )
1345 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
1346 lang::IllegalArgumentException, lang::WrappedTargetException,
1347 uno::RuntimeException)
1349 ScUnoGuard aGuard;
1350 String aString(aPropertyName);
1352 if (pDocShell)
1354 ScDocument* pDoc = pDocShell->GetDocument();
1355 const ScDocOptions& rOldOpt = pDoc->GetDocOptions();
1356 ScDocOptions aNewOpt = rOldOpt;
1358 BOOL bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, *aPropSet.getPropertyMap(), aPropertyName, aValue );
1359 if (bOpt)
1361 // done...
1363 else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) )
1365 lang::Locale aLocale;
1366 if ( aValue >>= aLocale )
1368 LanguageType eLatin, eCjk, eCtl;
1369 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1370 eLatin = ScUnoConversion::GetLanguage(aLocale);
1371 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1374 else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) )
1376 lang::Locale aLocale;
1377 if ( aValue >>= aLocale )
1379 LanguageType eLatin, eCjk, eCtl;
1380 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1381 eCjk = ScUnoConversion::GetLanguage(aLocale);
1382 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1385 else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) )
1387 lang::Locale aLocale;
1388 if ( aValue >>= aLocale )
1390 LanguageType eLatin, eCjk, eCtl;
1391 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1392 eCtl = ScUnoConversion::GetLanguage(aLocale);
1393 pDoc->SetLanguage( eLatin, eCjk, eCtl );
1396 else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) )
1398 // model is created if not there
1399 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1400 pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1402 SfxBindings* pBindings = pDocShell->GetViewBindings();
1403 if (pBindings)
1404 pBindings->Invalidate( SID_FM_OPEN_READONLY );
1406 else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) )
1408 // model is created if not there
1409 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
1410 pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1412 SfxBindings* pBindings = pDocShell->GetViewBindings();
1413 if (pBindings)
1414 pBindings->Invalidate( SID_FM_AUTOCONTROLFOCUS );
1416 else if ( aString.EqualsAscii( SC_UNO_ISLOADED ) )
1418 pDocShell->SetEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1420 else if ( aString.EqualsAscii( SC_UNO_ISUNDOENABLED ) )
1422 BOOL bUndoEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1423 pDoc->EnableUndo( bUndoEnabled );
1424 USHORT nCount = ( bUndoEnabled ?
1425 static_cast< USHORT >( SvtUndoOptions().GetUndoCount() ) : 0 );
1426 pDocShell->GetUndoManager()->SetMaxUndoActionCount( nCount );
1428 else if ( aString.EqualsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1430 bool bOldAdjustHeightEnabled = pDoc->IsAdjustHeightEnabled();
1431 bool bAdjustHeightEnabled = ScUnoHelpFunctions::GetBoolFromAny( aValue );
1432 if( bOldAdjustHeightEnabled != bAdjustHeightEnabled )
1434 pDoc->EnableAdjustHeight( bAdjustHeightEnabled );
1435 if( bAdjustHeightEnabled )
1436 pDocShell->UpdateAllRowHeights();
1439 else if ( aString.EqualsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1441 pDoc->EnableExecuteLink( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1443 else if ( aString.EqualsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1445 pDoc->EnableChangeReadOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
1447 else if ( aString.EqualsAscii( "BuildId" ) )
1449 aValue >>= maBuildId;
1451 else if ( aString.EqualsAscii( "SavedObject" ) ) // set from chart after saving
1453 rtl::OUString aObjName;
1454 aValue >>= aObjName;
1455 if ( aObjName.getLength() )
1456 pDoc->RestoreChartListener( aObjName );
1458 else if ( aString.EqualsAscii( "WriteProtectionPassword" ) )
1460 /* This is a hack for #160550# to preserve the write-protection
1461 password in an XLS roundtrip. This property MUST NOT be used
1462 for any other purpose. This property will be deleted when the
1463 feature "Write Protection With Password" will be implemented. */
1464 aValue >>= mnXlsWriteProtPass;
1467 if ( aNewOpt != rOldOpt )
1469 pDoc->SetDocOptions( aNewOpt );
1470 // Don't recalculate while loading XML, when the formula text is stored.
1471 // Recalculation after loading is handled separately.
1472 //! Recalc only for options that need it?
1473 if ( !pDoc->IsImportingXML() )
1474 pDocShell->DoHardRecalc( TRUE );
1475 pDocShell->SetDocumentModified();
1480 uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyName )
1481 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
1482 uno::RuntimeException)
1484 ScUnoGuard aGuard;
1485 String aString(aPropertyName);
1486 uno::Any aRet;
1488 if (pDocShell)
1490 ScDocument* pDoc = pDocShell->GetDocument();
1491 const ScDocOptions& rOpt = pDoc->GetDocOptions();
1492 aRet = ScDocOptionsHelper::getPropertyValue( rOpt, *aPropSet.getPropertyMap(), aPropertyName );
1493 if ( aRet.hasValue() )
1495 // done...
1497 else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) )
1499 LanguageType eLatin, eCjk, eCtl;
1500 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1502 lang::Locale aLocale;
1503 ScUnoConversion::FillLocale( aLocale, eLatin );
1504 aRet <<= aLocale;
1506 else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) )
1508 LanguageType eLatin, eCjk, eCtl;
1509 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1511 lang::Locale aLocale;
1512 ScUnoConversion::FillLocale( aLocale, eCjk );
1513 aRet <<= aLocale;
1515 else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) )
1517 LanguageType eLatin, eCjk, eCtl;
1518 pDoc->GetLanguage( eLatin, eCjk, eCtl );
1520 lang::Locale aLocale;
1521 ScUnoConversion::FillLocale( aLocale, eCtl );
1522 aRet <<= aLocale;
1524 else if ( aString.EqualsAscii( SC_UNO_NAMEDRANGES ) )
1526 aRet <<= uno::Reference<sheet::XNamedRanges>(new ScNamedRangesObj( pDocShell ));
1528 else if ( aString.EqualsAscii( SC_UNO_DATABASERNG ) )
1530 aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
1532 else if ( aString.EqualsAscii( SC_UNO_COLLABELRNG ) )
1534 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, TRUE ));
1536 else if ( aString.EqualsAscii( SC_UNO_ROWLABELRNG ) )
1538 aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, FALSE ));
1540 else if ( aString.EqualsAscii( SC_UNO_AREALINKS ) )
1542 aRet <<= uno::Reference<sheet::XAreaLinks>(new ScAreaLinksObj( pDocShell ));
1544 else if ( aString.EqualsAscii( SC_UNO_DDELINKS ) )
1546 aRet <<= uno::Reference<container::XNameAccess>(new ScDDELinksObj( pDocShell ));
1548 else if ( aString.EqualsAscii( SC_UNO_EXTERNALDOCLINKS ) )
1550 aRet <<= uno::Reference<sheet::XExternalDocLinks>(new ScExternalDocLinksObj(pDocShell));
1552 else if ( aString.EqualsAscii( SC_UNO_SHEETLINKS ) )
1554 aRet <<= uno::Reference<container::XNameAccess>(new ScSheetLinksObj( pDocShell ));
1556 else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) )
1558 // default for no model is TRUE
1559 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1560 sal_Bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True;
1561 ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign );
1563 else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) )
1565 // default for no model is FALSE
1566 ScDrawLayer* pModel = pDoc->GetDrawLayer();
1567 sal_Bool bAutoControlFocus = pModel ? pModel->GetAutoControlFocus() : sal_False;
1568 ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus );
1570 else if ( aString.EqualsAscii( SC_UNO_FORBIDDEN ) )
1572 aRet <<= uno::Reference<i18n::XForbiddenCharacters>(new ScForbiddenCharsObj( pDocShell ));
1574 else if ( aString.EqualsAscii( SC_UNO_HASDRAWPAGES ) )
1576 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) );
1578 else if ( aString.EqualsAscii( SC_UNO_BASICLIBRARIES ) )
1580 aRet <<= pDocShell->GetBasicContainer();
1582 else if ( aString.EqualsAscii( SC_UNO_DIALOGLIBRARIES ) )
1584 aRet <<= pDocShell->GetDialogContainer();
1586 else if ( aString.EqualsAscii( SC_UNO_VBADOCOBJ ) )
1588 beans::PropertyValue aProp;
1589 aProp.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc") );
1590 aProp.Value <<= pDocShell->GetModel();
1591 aRet <<= aProp;
1593 else if ( aString.EqualsAscii( SC_UNO_RUNTIMEUID ) )
1595 aRet <<= getRuntimeUID();
1597 else if ( aString.EqualsAscii( SC_UNO_HASVALIDSIGNATURES ) )
1599 aRet <<= hasValidSignatures();
1601 else if ( aString.EqualsAscii( SC_UNO_ISLOADED ) )
1603 ScUnoHelpFunctions::SetBoolInAny( aRet, !pDocShell->IsEmpty() );
1605 else if ( aString.EqualsAscii( SC_UNO_ISUNDOENABLED ) )
1607 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsUndoEnabled() );
1609 else if ( aString.EqualsAscii( SC_UNO_ISADJUSTHEIGHTENABLED ) )
1611 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsAdjustHeightEnabled() );
1613 else if ( aString.EqualsAscii( SC_UNO_ISEXECUTELINKENABLED ) )
1615 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsExecuteLinkEnabled() );
1617 else if ( aString.EqualsAscii( SC_UNO_ISCHANGEREADONLYENABLED ) )
1619 ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->IsChangeReadOnlyEnabled() );
1621 else if ( aString.EqualsAscii( SC_UNO_REFERENCEDEVICE ) )
1623 VCLXDevice* pXDev = new VCLXDevice();
1624 pXDev->SetOutputDevice( pDoc->GetRefDevice() );
1625 aRet <<= uno::Reference< awt::XDevice >( pXDev );
1627 else if (aString.EqualsAscii(SC_UNO_ALWAYS_ALLOW_SAVE))
1628 ScUnoHelpFunctions::SetBoolInAny(aRet, pDocShell->GetApplicationFlag(SFX_APPFLAG_ALWAYS_ALLOW_SAVE));
1629 else if ( aString.EqualsAscii( "BuildId" ) )
1631 aRet <<= maBuildId;
1633 else if ( aString.EqualsAscii( "InternalDocument" ) )
1635 ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL) );
1637 else if ( aString.EqualsAscii( "WriteProtectionPassword" ) )
1639 /* This is a hack for #160550# to preserve the write-protection
1640 password in an XLS roundtrip. This property MUST NOT be used
1641 for any other purpose. This property will be deleted when the
1642 feature "Write Protection With Password" will be implemented. */
1643 aRet <<= mnXlsWriteProtPass;
1647 return aRet;
1650 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj )
1652 // XMultiServiceFactory
1654 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance(
1655 const rtl::OUString& aServiceSpecifier )
1656 throw(uno::Exception, uno::RuntimeException)
1658 ScUnoGuard aGuard;
1659 uno::Reference<uno::XInterface> xRet;
1660 String aNameStr(aServiceSpecifier);
1661 USHORT nType = ScServiceProvider::GetProviderType(aNameStr);
1662 if ( nType != SC_SERVICE_INVALID )
1664 // drawing layer tables must be kept as long as the model is alive
1665 // return stored instance if already set
1666 switch ( nType )
1668 case SC_SERVICE_GRADTAB: xRet.set(xDrawGradTab); break;
1669 case SC_SERVICE_HATCHTAB: xRet.set(xDrawHatchTab); break;
1670 case SC_SERVICE_BITMAPTAB: xRet.set(xDrawBitmapTab); break;
1671 case SC_SERVICE_TRGRADTAB: xRet.set(xDrawTrGradTab); break;
1672 case SC_SERVICE_MARKERTAB: xRet.set(xDrawMarkerTab); break;
1673 case SC_SERVICE_DASHTAB: xRet.set(xDrawDashTab); break;
1674 case SC_SERVICE_CHDATAPROV: xRet.set(xChartDataProv); break;
1677 // #i64497# If a chart is in a temporary document during clipoard paste,
1678 // there should be no data provider, so that own data is used
1679 bool bCreate =
1680 ! ( nType == SC_SERVICE_CHDATAPROV &&
1681 ( pDocShell->GetCreateMode() == SFX_CREATE_MODE_INTERNAL ));
1682 // this should never happen, i.e. the temporary document should never be
1683 // loaded, becuase this unlinks the data
1684 OSL_ASSERT( bCreate );
1686 if ( !xRet.is() && bCreate )
1688 xRet.set(ScServiceProvider::MakeInstance( nType, pDocShell ));
1690 // store created instance
1691 switch ( nType )
1693 case SC_SERVICE_GRADTAB: xDrawGradTab.set(xRet); break;
1694 case SC_SERVICE_HATCHTAB: xDrawHatchTab.set(xRet); break;
1695 case SC_SERVICE_BITMAPTAB: xDrawBitmapTab.set(xRet); break;
1696 case SC_SERVICE_TRGRADTAB: xDrawTrGradTab.set(xRet); break;
1697 case SC_SERVICE_MARKERTAB: xDrawMarkerTab.set(xRet); break;
1698 case SC_SERVICE_DASHTAB: xDrawDashTab.set(xRet); break;
1699 case SC_SERVICE_CHDATAPROV: xChartDataProv.set(xRet); break;
1703 else
1705 // alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals,
1706 // da wird dann 'ne Exception geworfen, wenn's nicht passt...
1710 xRet.set(SvxFmMSFactory::createInstance(aServiceSpecifier));
1711 // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator)
1713 catch ( lang::ServiceNotRegisteredException & )
1717 // #96117# if the drawing factory created a shape, a ScShapeObj has to be used
1718 // to support own properties like ImageMap:
1720 uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY );
1721 if ( xShape.is() )
1723 xRet.clear(); // for aggregation, xShape must be the object's only ref
1724 new ScShapeObj( xShape ); // aggregates object and modifies xShape
1725 xRet.set(xShape);
1728 return xRet;
1731 uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments(
1732 const rtl::OUString& ServiceSpecifier,
1733 const uno::Sequence<uno::Any>& aArgs )
1734 throw(uno::Exception, uno::RuntimeException)
1736 //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer?
1738 ScUnoGuard aGuard;
1739 uno::Reference<uno::XInterface> xInt(createInstance(ServiceSpecifier));
1741 if ( aArgs.getLength() )
1743 // used only for cell value binding so far - it can be initialized after creating
1745 uno::Reference<lang::XInitialization> xInit( xInt, uno::UNO_QUERY );
1746 if ( xInit.is() )
1747 xInit->initialize( aArgs );
1750 return xInt;
1753 uno::Sequence<rtl::OUString> SAL_CALL ScModelObj::getAvailableServiceNames()
1754 throw(uno::RuntimeException)
1756 ScUnoGuard aGuard;
1758 //! warum sind die Parameter bei concatServiceNames nicht const ???
1759 //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(),
1760 //! SvxFmMSFactory::getAvailableServiceNames() );
1762 uno::Sequence<rtl::OUString> aMyServices(ScServiceProvider::GetAllServiceNames());
1763 uno::Sequence<rtl::OUString> aDrawServices(SvxFmMSFactory::getAvailableServiceNames());
1765 return concatServiceNames( aMyServices, aDrawServices );
1768 // XVbaEventHelper
1769 // For Vba Event
1770 sal_Bool SAL_CALL
1771 ScModelObj::processCompatibleEvent( sal_Int16 nSlotId ) throw( ::com::sun::star::uno::RuntimeException )
1773 USHORT nId = (USHORT)nSlotId;
1774 uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper( GetDocument()->GetVbaEventsHelper(), uno::UNO_QUERY );
1775 if( xVbaEventsHelper.is() )
1777 switch( nId )
1779 case SID_SAVEDOC:
1781 uno::Sequence< uno::Any > aArgs(1);
1782 aArgs[0] <<= sal_False;
1783 return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORESAVE, aArgs );
1785 case SID_SAVEASDOC:
1787 uno::Sequence< uno::Any > aArgs(1);
1788 aArgs[0] <<= sal_True;
1789 return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORESAVE, aArgs );
1791 case SID_PRINTDOC:
1792 case SID_PRINTDOCDIRECT:
1794 uno::Sequence< uno::Any > aArgs;
1795 return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFOREPRINT, aArgs );
1799 return sal_False;
1801 // XServiceInfo
1803 rtl::OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException)
1805 return rtl::OUString::createFromAscii( "ScModelObj" );
1808 sal_Bool SAL_CALL ScModelObj::supportsService( const rtl::OUString& rServiceName )
1809 throw(uno::RuntimeException)
1811 String aServiceStr(rServiceName);
1812 return aServiceStr.EqualsAscii( SCMODELOBJ_SERVICE ) ||
1813 aServiceStr.EqualsAscii( SCDOCSETTINGS_SERVICE ) ||
1814 aServiceStr.EqualsAscii( SCDOC_SERVICE );
1817 uno::Sequence<rtl::OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
1818 throw(uno::RuntimeException)
1820 uno::Sequence<rtl::OUString> aRet(2);
1821 rtl::OUString* pArray = aRet.getArray();
1822 pArray[0] = rtl::OUString::createFromAscii( SCMODELOBJ_SERVICE );
1823 pArray[1] = rtl::OUString::createFromAscii( SCDOCSETTINGS_SERVICE );
1824 return aRet;
1827 // XUnoTunnel
1829 sal_Int64 SAL_CALL ScModelObj::getSomething(
1830 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
1832 if ( rId.getLength() == 16 &&
1833 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1834 rId.getConstArray(), 16 ) )
1836 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1839 if ( rId.getLength() == 16 &&
1840 0 == rtl_compareMemory( SfxObjectShell::getUnoTunnelId().getConstArray(),
1841 rId.getConstArray(), 16 ) )
1843 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
1845 // aggregated number formats supplier has XUnoTunnel, too
1846 // interface from aggregated object must be obtained via queryAggregation
1848 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
1849 if ( nRet )
1850 return nRet;
1852 if ( GetFormatter().is() )
1854 const uno::Type& rTunnelType = ::getCppuType((uno::Reference<lang::XUnoTunnel>*) 0);
1855 uno::Any aNumTunnel(xNumberAgg->queryAggregation(rTunnelType));
1856 if(aNumTunnel.getValueType() == rTunnelType)
1858 uno::Reference<lang::XUnoTunnel> xTunnelAgg(
1859 *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue());
1860 return xTunnelAgg->getSomething( rId );
1864 return 0;
1867 // static
1868 const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId()
1870 static uno::Sequence<sal_Int8> * pSeq = 0;
1871 if( !pSeq )
1873 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
1874 if( !pSeq )
1876 static uno::Sequence< sal_Int8 > aSeq( 16 );
1877 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1878 pSeq = &aSeq;
1881 return *pSeq;
1884 // static
1885 ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj )
1887 ScModelObj* pRet = NULL;
1888 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
1889 if (xUT.is())
1890 pRet = reinterpret_cast<ScModelObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1891 return pRet;
1894 // XChangesNotifier
1896 void ScModelObj::addChangesListener( const uno::Reference< util::XChangesListener >& aListener )
1897 throw (uno::RuntimeException)
1899 ScUnoGuard aGuard;
1900 maChangesListeners.addInterface( aListener );
1903 void ScModelObj::removeChangesListener( const uno::Reference< util::XChangesListener >& aListener )
1904 throw (uno::RuntimeException)
1906 ScUnoGuard aGuard;
1907 maChangesListeners.removeInterface( aListener );
1910 bool ScModelObj::HasChangesListeners() const
1912 return ( maChangesListeners.getLength() > 0 );
1915 void ScModelObj::NotifyChanges( const ::rtl::OUString& rOperation, const ScRangeList& rRanges,
1916 const uno::Sequence< beans::PropertyValue >& rProperties )
1918 if ( pDocShell && HasChangesListeners() )
1920 util::ChangesEvent aEvent;
1921 aEvent.Source.set( static_cast< cppu::OWeakObject* >( this ) );
1922 aEvent.Base <<= aEvent.Source;
1924 ULONG nRangeCount = rRanges.Count();
1925 aEvent.Changes.realloc( static_cast< sal_Int32 >( nRangeCount ) );
1926 for ( ULONG nIndex = 0; nIndex < nRangeCount; ++nIndex )
1928 uno::Reference< table::XCellRange > xRangeObj;
1930 ScRange aRange( *rRanges.GetObject( nIndex ) );
1931 if ( aRange.aStart == aRange.aEnd )
1933 xRangeObj.set( new ScCellObj( pDocShell, aRange.aStart ) );
1935 else
1937 xRangeObj.set( new ScCellRangeObj( pDocShell, aRange ) );
1940 util::ElementChange& rChange = aEvent.Changes[ static_cast< sal_Int32 >( nIndex ) ];
1941 rChange.Accessor <<= rOperation;
1942 rChange.Element <<= rProperties;
1943 rChange.ReplacedElement <<= xRangeObj;
1946 ::cppu::OInterfaceIteratorHelper aIter( maChangesListeners );
1947 while ( aIter.hasMoreElements() )
1951 static_cast< util::XChangesListener* >( aIter.next() )->changesOccurred( aEvent );
1953 catch( uno::Exception& )
1960 //------------------------------------------------------------------------
1962 ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) :
1963 pDocShell( pDocSh )
1965 pDocShell->GetDocument()->AddUnoObject(*this);
1968 ScDrawPagesObj::~ScDrawPagesObj()
1970 if (pDocShell)
1971 pDocShell->GetDocument()->RemoveUnoObject(*this);
1974 void ScDrawPagesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1976 // Referenz-Update interessiert hier nicht
1978 if ( rHint.ISA( SfxSimpleHint ) &&
1979 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1981 pDocShell = NULL; // ungueltig geworden
1985 uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(INT32 nIndex) const
1987 if (pDocShell)
1989 ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer();
1990 DBG_ASSERT(pDrawLayer,"kann Draw-Layer nicht anlegen");
1991 if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
1993 SdrPage* pPage = pDrawLayer->GetPage((USHORT)nIndex);
1994 DBG_ASSERT(pPage,"Draw-Page nicht gefunden");
1995 if (pPage)
1997 return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY);
2001 return NULL;
2004 // XDrawPages
2006 uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos )
2007 throw(uno::RuntimeException)
2009 ScUnoGuard aGuard;
2010 uno::Reference<drawing::XDrawPage> xRet;
2011 if (pDocShell)
2013 String aNewName;
2014 pDocShell->GetDocument()->CreateValidTabName(aNewName);
2015 ScDocFunc aFunc(*pDocShell);
2016 if ( aFunc.InsertTable( (SCTAB)nPos, aNewName, TRUE, TRUE ) )
2017 xRet.set(GetObjectByIndex_Impl( nPos ));
2019 return xRet;
2022 void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage )
2023 throw(uno::RuntimeException)
2025 ScUnoGuard aGuard;
2026 SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage );
2027 if ( pDocShell && pImp )
2029 SdrPage* pPage = pImp->GetSdrPage();
2030 if (pPage)
2032 SCTAB nPageNum = static_cast<SCTAB>(pPage->GetPageNum());
2033 ScDocFunc aFunc(*pDocShell);
2034 aFunc.DeleteTable( nPageNum, TRUE, TRUE );
2039 // XIndexAccess
2041 sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException)
2043 ScUnoGuard aGuard;
2044 if (pDocShell)
2045 return pDocShell->GetDocument()->GetTableCount();
2046 return 0;
2049 uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex )
2050 throw(lang::IndexOutOfBoundsException,
2051 lang::WrappedTargetException, uno::RuntimeException)
2053 ScUnoGuard aGuard;
2054 uno::Reference<drawing::XDrawPage> xPage(GetObjectByIndex_Impl(nIndex));
2055 if (xPage.is())
2056 return uno::makeAny(xPage);
2057 else
2058 throw lang::IndexOutOfBoundsException();
2059 // return uno::Any();
2062 uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException)
2064 ScUnoGuard aGuard;
2065 return getCppuType((uno::Reference<drawing::XDrawPage>*)0);
2068 sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException)
2070 ScUnoGuard aGuard;
2071 return ( getCount() != 0 );
2074 //------------------------------------------------------------------------
2076 ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) :
2077 pDocShell( pDocSh )
2079 pDocShell->GetDocument()->AddUnoObject(*this);
2082 ScTableSheetsObj::~ScTableSheetsObj()
2084 if (pDocShell)
2085 pDocShell->GetDocument()->RemoveUnoObject(*this);
2088 void ScTableSheetsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2090 // Referenz-Update interessiert hier nicht
2092 if ( rHint.ISA( SfxSimpleHint ) &&
2093 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2095 pDocShell = NULL; // ungueltig geworden
2099 // XSpreadsheets
2101 ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2103 if ( pDocShell && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() )
2104 return new ScTableSheetObj( pDocShell, static_cast<SCTAB>(nIndex) );
2106 return NULL;
2109 ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
2111 if (pDocShell)
2113 SCTAB nIndex;
2114 String aString(aName);
2115 if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) )
2116 return new ScTableSheetObj( pDocShell, nIndex );
2118 return NULL;
2121 void SAL_CALL ScTableSheetsObj::insertNewByName( const rtl::OUString& aName, sal_Int16 nPosition )
2122 throw(uno::RuntimeException)
2124 ScUnoGuard aGuard;
2125 BOOL bDone = FALSE;
2126 if (pDocShell)
2128 String aNamStr(aName);
2129 ScDocFunc aFunc(*pDocShell);
2130 bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE );
2132 if (!bDone)
2133 throw uno::RuntimeException(); // no other exceptions specified
2136 void SAL_CALL ScTableSheetsObj::moveByName( const rtl::OUString& aName, sal_Int16 nDestination )
2137 throw(uno::RuntimeException)
2139 ScUnoGuard aGuard;
2140 BOOL bDone = FALSE;
2141 if (pDocShell)
2143 String aNamStr(aName);
2144 SCTAB nSource;
2145 if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) )
2146 bDone = pDocShell->MoveTable( nSource, nDestination, FALSE, TRUE );
2148 if (!bDone)
2149 throw uno::RuntimeException(); // no other exceptions specified
2152 void SAL_CALL ScTableSheetsObj::copyByName( const rtl::OUString& aName,
2153 const rtl::OUString& aCopy, sal_Int16 nDestination )
2154 throw(uno::RuntimeException)
2156 ScUnoGuard aGuard;
2157 BOOL bDone = FALSE;
2158 if (pDocShell)
2160 String aNamStr(aName);
2161 String aNewStr(aCopy);
2162 SCTAB nSource;
2163 if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) )
2165 bDone = pDocShell->MoveTable( nSource, nDestination, TRUE, TRUE );
2166 if (bDone)
2168 // #i92477# any index past the last sheet means "append" in MoveTable
2169 SCTAB nResultTab = static_cast<SCTAB>(nDestination);
2170 SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount(); // count after copying
2171 if (nResultTab >= nTabCount)
2172 nResultTab = nTabCount - 1;
2174 ScDocFunc aFunc(*pDocShell);
2175 bDone = aFunc.RenameTable( nResultTab, aNewStr, TRUE, TRUE );
2179 if (!bDone)
2180 throw uno::RuntimeException(); // no other exceptions specified
2183 void SAL_CALL ScTableSheetsObj::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
2184 throw(lang::IllegalArgumentException, container::ElementExistException,
2185 lang::WrappedTargetException, uno::RuntimeException)
2187 ScUnoGuard aGuard;
2188 BOOL bDone = FALSE;
2189 BOOL bIllArg = FALSE;
2191 //! Type of aElement can be some specific interface instead of XInterface
2193 if ( pDocShell )
2195 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2196 if ( xInterface.is() )
2198 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2199 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2201 ScDocument* pDoc = pDocShell->GetDocument();
2202 String aNamStr(aName);
2203 SCTAB nDummy;
2204 if ( pDoc->GetTable( aNamStr, nDummy ) )
2206 // name already exists
2207 throw container::ElementExistException();
2209 else
2211 SCTAB nPosition = pDoc->GetTableCount();
2212 ScDocFunc aFunc(*pDocShell);
2213 bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE );
2214 if (bDone)
2215 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2216 // Dokument und neuen Range am Objekt setzen
2219 else
2220 bIllArg = TRUE;
2222 else
2223 bIllArg = TRUE;
2226 if (!bDone)
2228 if (bIllArg)
2229 throw lang::IllegalArgumentException();
2230 else
2231 throw uno::RuntimeException(); // ElementExistException is handled above
2235 void SAL_CALL ScTableSheetsObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement )
2236 throw(lang::IllegalArgumentException, container::NoSuchElementException,
2237 lang::WrappedTargetException, uno::RuntimeException)
2239 ScUnoGuard aGuard;
2240 BOOL bDone = FALSE;
2241 BOOL bIllArg = FALSE;
2243 //! Type of aElement can be some specific interface instead of XInterface
2245 if ( pDocShell )
2247 uno::Reference<uno::XInterface> xInterface(aElement, uno::UNO_QUERY);
2248 if ( xInterface.is() )
2250 ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface );
2251 if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt?
2253 String aNamStr(aName);
2254 SCTAB nPosition;
2255 if ( pDocShell->GetDocument()->GetTable( aNamStr, nPosition ) )
2257 ScDocFunc aFunc(*pDocShell);
2258 if ( aFunc.DeleteTable( nPosition, TRUE, TRUE ) )
2260 // InsertTable kann jetzt eigentlich nicht schiefgehen...
2261 bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE );
2262 if (bDone)
2263 pSheetObj->InitInsertSheet( pDocShell, nPosition );
2266 else
2268 // not found
2269 throw container::NoSuchElementException();
2272 else
2273 bIllArg = TRUE;
2275 else
2276 bIllArg = TRUE;
2279 if (!bDone)
2281 if (bIllArg)
2282 throw lang::IllegalArgumentException();
2283 else
2284 throw uno::RuntimeException(); // NoSuchElementException is handled above
2288 void SAL_CALL ScTableSheetsObj::removeByName( const rtl::OUString& aName )
2289 throw(container::NoSuchElementException,
2290 lang::WrappedTargetException, uno::RuntimeException)
2292 ScUnoGuard aGuard;
2293 BOOL bDone = FALSE;
2294 if (pDocShell)
2296 SCTAB nIndex;
2297 String aString(aName);
2298 if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) )
2300 ScDocFunc aFunc(*pDocShell);
2301 bDone = aFunc.DeleteTable( nIndex, TRUE, TRUE );
2303 else
2305 // not found
2306 throw container::NoSuchElementException();
2310 if (!bDone)
2311 throw uno::RuntimeException(); // NoSuchElementException is handled above
2314 // XCellRangesAccess
2316 uno::Reference< table::XCell > SAL_CALL ScTableSheetsObj::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow, sal_Int32 nSheet )
2317 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2319 ScUnoGuard aGuard;
2320 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((USHORT)nSheet)));
2321 if (! xSheet.is())
2322 throw lang::IndexOutOfBoundsException();
2324 return xSheet->getCellByPosition(nColumn, nRow);
2327 uno::Reference< table::XCellRange > SAL_CALL ScTableSheetsObj::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom, sal_Int32 nSheet )
2328 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2330 ScUnoGuard aGuard;
2331 uno::Reference<table::XCellRange> xSheet(static_cast<ScCellRangeObj*>(GetObjectByIndex_Impl((USHORT)nSheet)));
2332 if (! xSheet.is())
2333 throw lang::IndexOutOfBoundsException();
2335 return xSheet->getCellRangeByPosition(nLeft, nTop, nRight, nBottom);
2338 uno::Sequence < uno::Reference< table::XCellRange > > SAL_CALL ScTableSheetsObj::getCellRangesByName( const rtl::OUString& aRange )
2339 throw (lang::IllegalArgumentException, uno::RuntimeException)
2341 ScUnoGuard aGuard;
2342 uno::Sequence < uno::Reference < table::XCellRange > > xRet;
2344 ScRangeList aRangeList;
2345 ScDocument* pDoc = pDocShell->GetDocument();
2346 if (ScRangeStringConverter::GetRangeListFromString( aRangeList, aRange, pDoc, ::formula::FormulaGrammar::CONV_OOO, ';' ))
2348 sal_Int32 nCount = aRangeList.Count();
2349 if (nCount)
2351 xRet.realloc(nCount);
2352 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
2354 const ScRange* pRange = aRangeList.GetObject( nIndex );
2355 if( pRange )
2356 xRet[nIndex] = new ScCellRangeObj(pDocShell, *pRange);
2359 else
2360 throw lang::IllegalArgumentException();
2362 else
2363 throw lang::IllegalArgumentException();
2364 return xRet;
2367 // XEnumerationAccess
2369 uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration()
2370 throw(uno::RuntimeException)
2372 ScUnoGuard aGuard;
2373 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetsEnumeration")));
2376 // XIndexAccess
2378 sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException)
2380 ScUnoGuard aGuard;
2381 if (pDocShell)
2382 return pDocShell->GetDocument()->GetTableCount();
2383 return 0;
2386 uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex )
2387 throw(lang::IndexOutOfBoundsException,
2388 lang::WrappedTargetException, uno::RuntimeException)
2390 ScUnoGuard aGuard;
2391 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByIndex_Impl(nIndex));
2392 if (xSheet.is())
2393 return uno::makeAny(xSheet);
2394 else
2395 throw lang::IndexOutOfBoundsException();
2396 // return uno::Any();
2399 uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException)
2401 ScUnoGuard aGuard;
2402 return getCppuType((uno::Reference<sheet::XSpreadsheet>*)0);
2405 sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException)
2407 ScUnoGuard aGuard;
2408 return ( getCount() != 0 );
2411 // XNameAccess
2413 uno::Any SAL_CALL ScTableSheetsObj::getByName( const rtl::OUString& aName )
2414 throw(container::NoSuchElementException,
2415 lang::WrappedTargetException, uno::RuntimeException)
2417 ScUnoGuard aGuard;
2418 uno::Reference<sheet::XSpreadsheet> xSheet(GetObjectByName_Impl(aName));
2419 if (xSheet.is())
2420 return uno::makeAny(xSheet);
2421 else
2422 throw container::NoSuchElementException();
2423 // return uno::Any();
2426 uno::Sequence<rtl::OUString> SAL_CALL ScTableSheetsObj::getElementNames()
2427 throw(uno::RuntimeException)
2429 ScUnoGuard aGuard;
2430 if (pDocShell)
2432 ScDocument* pDoc = pDocShell->GetDocument();
2433 SCTAB nCount = pDoc->GetTableCount();
2434 String aName;
2435 uno::Sequence<rtl::OUString> aSeq(nCount);
2436 rtl::OUString* pAry = aSeq.getArray();
2437 for (SCTAB i=0; i<nCount; i++)
2439 pDoc->GetName( i, aName );
2440 pAry[i] = aName;
2442 return aSeq;
2444 return uno::Sequence<rtl::OUString>();
2447 sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const rtl::OUString& aName )
2448 throw(uno::RuntimeException)
2450 ScUnoGuard aGuard;
2451 if (pDocShell)
2453 SCTAB nIndex;
2454 if ( pDocShell->GetDocument()->GetTable( String(aName), nIndex ) )
2455 return TRUE;
2457 return FALSE;
2460 //------------------------------------------------------------------------
2462 ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, SCTAB nT, SCCOL nSC, SCCOL nEC) :
2463 pDocShell( pDocSh ),
2464 nTab ( nT ),
2465 nStartCol( nSC ),
2466 nEndCol ( nEC )
2468 pDocShell->GetDocument()->AddUnoObject(*this);
2471 ScTableColumnsObj::~ScTableColumnsObj()
2473 if (pDocShell)
2474 pDocShell->GetDocument()->RemoveUnoObject(*this);
2477 void ScTableColumnsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2479 if ( rHint.ISA( ScUpdateRefHint ) )
2481 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
2483 //! Referenz-Update fuer Tab und Start/Ende
2485 else if ( rHint.ISA( SfxSimpleHint ) &&
2486 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2488 pDocShell = NULL; // ungueltig geworden
2492 // XTableColumns
2494 ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2496 SCCOL nCol = static_cast<SCCOL>(nIndex) + nStartCol;
2497 if ( pDocShell && nCol <= nEndCol )
2498 return new ScTableColumnObj( pDocShell, nCol, nTab );
2500 return NULL; // falscher Index
2503 ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
2505 SCCOL nCol = 0;
2506 String aString(aName);
2507 if ( ::AlphaToCol( nCol, aString) )
2508 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
2509 return new ScTableColumnObj( pDocShell, nCol, nTab );
2511 return NULL;
2514 void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
2515 throw(uno::RuntimeException)
2517 ScUnoGuard aGuard;
2518 BOOL bDone = FALSE;
2519 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol &&
2520 nStartCol+nPosition+nCount-1 <= MAXCOL )
2522 ScDocFunc aFunc(*pDocShell);
2523 ScRange aRange( (SCCOL)(nStartCol+nPosition), 0, nTab,
2524 (SCCOL)(nStartCol+nPosition+nCount-1), MAXROW, nTab );
2525 bDone = aFunc.InsertCells( aRange, NULL, INS_INSCOLS, TRUE, TRUE );
2527 if (!bDone)
2528 throw uno::RuntimeException(); // no other exceptions specified
2531 void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
2532 throw(uno::RuntimeException)
2534 ScUnoGuard aGuard;
2535 BOOL bDone = FALSE;
2536 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
2537 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol )
2539 ScDocFunc aFunc(*pDocShell);
2540 ScRange aRange( (SCCOL)(nStartCol+nIndex), 0, nTab,
2541 (SCCOL)(nStartCol+nIndex+nCount-1), MAXROW, nTab );
2542 bDone = aFunc.DeleteCells( aRange, NULL, DEL_DELCOLS, TRUE, TRUE );
2544 if (!bDone)
2545 throw uno::RuntimeException(); // no other exceptions specified
2548 // XEnumerationAccess
2550 uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration()
2551 throw(uno::RuntimeException)
2553 ScUnoGuard aGuard;
2554 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableColumnsEnumeration")));
2557 // XIndexAccess
2559 sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException)
2561 ScUnoGuard aGuard;
2562 return nEndCol - nStartCol + 1;
2565 uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex )
2566 throw(lang::IndexOutOfBoundsException,
2567 lang::WrappedTargetException, uno::RuntimeException)
2569 ScUnoGuard aGuard;
2570 uno::Reference<table::XCellRange> xColumn(GetObjectByIndex_Impl(nIndex));
2571 if (xColumn.is())
2572 return uno::makeAny(xColumn);
2573 else
2574 throw lang::IndexOutOfBoundsException();
2575 // return uno::Any();
2578 uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException)
2580 ScUnoGuard aGuard;
2581 return getCppuType((uno::Reference<table::XCellRange>*)0);
2584 sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException)
2586 ScUnoGuard aGuard;
2587 return ( getCount() != 0 );
2590 uno::Any SAL_CALL ScTableColumnsObj::getByName( const rtl::OUString& aName )
2591 throw(container::NoSuchElementException,
2592 lang::WrappedTargetException, uno::RuntimeException)
2594 ScUnoGuard aGuard;
2595 uno::Reference<table::XCellRange> xColumn(GetObjectByName_Impl(aName));
2596 if (xColumn.is())
2597 return uno::makeAny(xColumn);
2598 else
2599 throw container::NoSuchElementException();
2600 // return uno::Any();
2603 uno::Sequence<rtl::OUString> SAL_CALL ScTableColumnsObj::getElementNames()
2604 throw(uno::RuntimeException)
2606 ScUnoGuard aGuard;
2607 SCCOL nCount = nEndCol - nStartCol + 1;
2608 uno::Sequence<rtl::OUString> aSeq(nCount);
2609 rtl::OUString* pAry = aSeq.getArray();
2610 for (SCCOL i=0; i<nCount; i++)
2611 pAry[i] = ::ScColToAlpha( nStartCol + i );
2613 return aSeq;
2616 sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const rtl::OUString& aName )
2617 throw(uno::RuntimeException)
2619 ScUnoGuard aGuard;
2620 SCCOL nCol = 0;
2621 String aString(aName);
2622 if ( ::AlphaToCol( nCol, aString) )
2623 if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
2624 return TRUE;
2626 return FALSE; // nicht gefunden
2629 // XPropertySet
2631 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo()
2632 throw(uno::RuntimeException)
2634 ScUnoGuard aGuard;
2635 static uno::Reference<beans::XPropertySetInfo> aRef(
2636 new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ));
2637 return aRef;
2640 void SAL_CALL ScTableColumnsObj::setPropertyValue(
2641 const rtl::OUString& aPropertyName, const uno::Any& aValue )
2642 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2643 lang::IllegalArgumentException, lang::WrappedTargetException,
2644 uno::RuntimeException)
2646 ScUnoGuard aGuard;
2647 if (!pDocShell)
2648 throw uno::RuntimeException();
2650 ScDocFunc aFunc(*pDocShell);
2651 SCCOLROW nColArr[2];
2652 nColArr[0] = nStartCol;
2653 nColArr[1] = nEndCol;
2654 String aNameString(aPropertyName);
2656 if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) )
2658 sal_Int32 nNewWidth = 0;
2659 if ( aValue >>= nNewWidth )
2660 aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, SC_SIZE_ORIGINAL,
2661 (USHORT)HMMToTwips(nNewWidth), TRUE, TRUE );
2663 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2665 BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2666 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
2667 aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, eMode, 0, TRUE, TRUE );
2668 // SC_SIZE_DIRECT with size 0: hide
2670 else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) )
2672 BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2673 if (bOpt)
2674 aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab,
2675 SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, TRUE, TRUE );
2676 // FALSE for columns currently has no effect
2678 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
2680 //! single function to set/remove all breaks?
2681 BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2682 for (SCCOL nCol=nStartCol; nCol<=nEndCol; nCol++)
2683 if (bSet)
2684 aFunc.InsertPageBreak( TRUE, ScAddress(nCol,0,nTab), TRUE, TRUE, TRUE );
2685 else
2686 aFunc.RemovePageBreak( TRUE, ScAddress(nCol,0,nTab), TRUE, TRUE, TRUE );
2690 uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const rtl::OUString& aPropertyName )
2691 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2692 uno::RuntimeException)
2694 ScUnoGuard aGuard;
2695 if (!pDocShell)
2696 throw uno::RuntimeException();
2698 ScDocument* pDoc = pDocShell->GetDocument();
2699 String aNameString(aPropertyName);
2700 uno::Any aAny;
2702 //! loop over all columns for current state?
2704 if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) )
2706 // for hidden column, return original height
2707 USHORT nWidth = pDoc->GetOriginalWidth( nStartCol, nTab );
2708 aAny <<= (sal_Int32)TwipsToHMM(nWidth);
2710 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2712 SCCOL nLastCol;
2713 bool bVis = !pDoc->ColHidden(nStartCol, nTab, nLastCol);
2714 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
2716 else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) )
2718 BOOL bOpt = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE);
2719 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
2721 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) )
2723 ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
2724 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
2726 else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
2728 ScBreakType nBreak = pDoc->HasColBreak(nStartCol, nTab);
2729 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) );
2732 return aAny;
2735 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj )
2737 //------------------------------------------------------------------------
2739 ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, SCTAB nT, SCROW nSR, SCROW nER) :
2740 pDocShell( pDocSh ),
2741 nTab ( nT ),
2742 nStartRow( nSR ),
2743 nEndRow ( nER )
2745 pDocShell->GetDocument()->AddUnoObject(*this);
2748 ScTableRowsObj::~ScTableRowsObj()
2750 if (pDocShell)
2751 pDocShell->GetDocument()->RemoveUnoObject(*this);
2754 void ScTableRowsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
2756 if ( rHint.ISA( ScUpdateRefHint ) )
2758 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
2760 //! Referenz-Update fuer Tab und Start/Ende
2762 else if ( rHint.ISA( SfxSimpleHint ) &&
2763 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
2765 pDocShell = NULL; // ungueltig geworden
2769 // XTableRows
2771 ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) const
2773 SCROW nRow = static_cast<SCROW>(nIndex) + nStartRow;
2774 if ( pDocShell && nRow <= nEndRow )
2775 return new ScTableRowObj( pDocShell, nRow, nTab );
2777 return NULL; // falscher Index
2780 void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount )
2781 throw(uno::RuntimeException)
2783 ScUnoGuard aGuard;
2784 BOOL bDone = FALSE;
2785 if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow &&
2786 nStartRow+nPosition+nCount-1 <= MAXROW )
2788 ScDocFunc aFunc(*pDocShell);
2789 ScRange aRange( 0, (SCROW)(nStartRow+nPosition), nTab,
2790 MAXCOL, (SCROW)(nStartRow+nPosition+nCount-1), nTab );
2791 bDone = aFunc.InsertCells( aRange, NULL, INS_INSROWS, TRUE, TRUE );
2793 if (!bDone)
2794 throw uno::RuntimeException(); // no other exceptions specified
2797 void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount )
2798 throw(uno::RuntimeException)
2800 ScUnoGuard aGuard;
2801 BOOL bDone = FALSE;
2802 // Der zu loeschende Bereich muss innerhalb des Objekts liegen
2803 if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow )
2805 ScDocFunc aFunc(*pDocShell);
2806 ScRange aRange( 0, (SCROW)(nStartRow+nIndex), nTab,
2807 MAXCOL, (SCROW)(nStartRow+nIndex+nCount-1), nTab );
2808 bDone = aFunc.DeleteCells( aRange, NULL, DEL_DELROWS, TRUE, TRUE );
2810 if (!bDone)
2811 throw uno::RuntimeException(); // no other exceptions specified
2814 // XEnumerationAccess
2816 uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration()
2817 throw(uno::RuntimeException)
2819 ScUnoGuard aGuard;
2820 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableRowsEnumeration")));
2823 // XIndexAccess
2825 sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException)
2827 ScUnoGuard aGuard;
2828 return nEndRow - nStartRow + 1;
2831 uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex )
2832 throw(lang::IndexOutOfBoundsException,
2833 lang::WrappedTargetException, uno::RuntimeException)
2835 ScUnoGuard aGuard;
2836 uno::Reference<table::XCellRange> xRow(GetObjectByIndex_Impl(nIndex));
2837 if (xRow.is())
2838 return uno::makeAny(xRow);
2839 else
2840 throw lang::IndexOutOfBoundsException();
2841 // return uno::Any();
2844 uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException)
2846 ScUnoGuard aGuard;
2847 return getCppuType((uno::Reference<table::XCellRange>*)0);
2850 sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException)
2852 ScUnoGuard aGuard;
2853 return ( getCount() != 0 );
2856 // XPropertySet
2858 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo()
2859 throw(uno::RuntimeException)
2861 ScUnoGuard aGuard;
2862 static uno::Reference<beans::XPropertySetInfo> aRef(
2863 new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ));
2864 return aRef;
2867 void SAL_CALL ScTableRowsObj::setPropertyValue(
2868 const rtl::OUString& aPropertyName, const uno::Any& aValue )
2869 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
2870 lang::IllegalArgumentException, lang::WrappedTargetException,
2871 uno::RuntimeException)
2873 ScUnoGuard aGuard;
2874 if (!pDocShell)
2875 throw uno::RuntimeException();
2877 ScDocFunc aFunc(*pDocShell);
2878 ScDocument* pDoc = pDocShell->GetDocument();
2879 SCCOLROW nRowArr[2];
2880 nRowArr[0] = nStartRow;
2881 nRowArr[1] = nEndRow;
2882 String aNameString(aPropertyName);
2884 if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) )
2886 sal_Int32 nNewHeight = 0;
2887 if ( pDoc->IsImportingXML() && ( aValue >>= nNewHeight ) )
2889 // used to set the stored row height for rows with optimal height when loading
2890 pDoc->SetRowHeightRange( nStartRow, nEndRow, nTab, (USHORT)HMMToTwips(nNewHeight) );
2892 else
2894 BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2895 if (bOpt)
2896 aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, TRUE, TRUE );
2897 else
2899 //! manually set old heights again?
2903 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) )
2905 sal_Int32 nNewHeight = 0;
2906 if ( aValue >>= nNewHeight )
2907 aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_ORIGINAL,
2908 (USHORT)HMMToTwips(nNewHeight), TRUE, TRUE );
2910 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2912 BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2913 ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT;
2914 aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, eMode, 0, TRUE, TRUE );
2915 // SC_SIZE_DIRECT with size 0: hide
2917 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) )
2919 //! undo etc.
2920 if (ScUnoHelpFunctions::GetBoolFromAny( aValue ))
2921 pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, true);
2922 else
2923 pDoc->SetRowFiltered(nStartRow, nEndRow, nTab, false);
2925 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE) )
2927 //! single function to set/remove all breaks?
2928 BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue );
2929 for (SCROW nRow=nStartRow; nRow<=nEndRow; nRow++)
2930 if (bSet)
2931 aFunc.InsertPageBreak( FALSE, ScAddress(0,nRow,nTab), TRUE, TRUE, TRUE );
2932 else
2933 aFunc.RemovePageBreak( FALSE, ScAddress(0,nRow,nTab), TRUE, TRUE, TRUE );
2935 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLBACK ) || aNameString.EqualsAscii( SC_UNONAME_CELLTRAN ) )
2937 // #i57867# Background color is specified for row styles in the file format,
2938 // so it has to be supported along with the row properties (import only).
2940 // Use ScCellRangeObj to set the property for all cells in the rows
2941 // (this means, the "row attribute" must be set before individual cell attributes).
2943 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
2944 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
2945 xRangeObj->setPropertyValue( aPropertyName, aValue );
2949 uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const rtl::OUString& aPropertyName )
2950 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
2951 uno::RuntimeException)
2953 ScUnoGuard aGuard;
2954 if (!pDocShell)
2955 throw uno::RuntimeException();
2957 ScDocument* pDoc = pDocShell->GetDocument();
2958 String aNameString(aPropertyName);
2959 uno::Any aAny;
2961 //! loop over all rows for current state?
2963 if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) )
2965 // for hidden row, return original height
2966 USHORT nHeight = pDoc->GetOriginalHeight( nStartRow, nTab );
2967 aAny <<= (sal_Int32)TwipsToHMM(nHeight);
2969 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) )
2971 SCROW nLastRow;
2972 bool bVis = !pDoc->RowHidden(nStartRow, nTab, nLastRow);
2973 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
2975 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) )
2977 bool bVis = pDoc->RowFiltered(nStartRow, nTab);
2978 ScUnoHelpFunctions::SetBoolInAny( aAny, bVis );
2980 else if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) )
2982 BOOL bOpt = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE);
2983 ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt );
2985 else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) )
2987 ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
2988 ScUnoHelpFunctions::SetBoolInAny( aAny, nBreak );
2990 else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) )
2992 ScBreakType nBreak = pDoc->HasRowBreak(nStartRow, nTab);
2993 ScUnoHelpFunctions::SetBoolInAny( aAny, (nBreak & BREAK_MANUAL) );
2995 else if ( aNameString.EqualsAscii( SC_UNONAME_CELLBACK ) || aNameString.EqualsAscii( SC_UNONAME_CELLTRAN ) )
2997 // Use ScCellRangeObj to get the property from the cell range
2998 // (for completeness only, this is not used by the XML filter).
3000 ScRange aRange( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab );
3001 uno::Reference<beans::XPropertySet> xRangeObj = new ScCellRangeObj( pDocShell, aRange );
3002 aAny = xRangeObj->getPropertyValue( aPropertyName );
3005 return aAny;
3008 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj )
3010 //------------------------------------------------------------------------
3012 //UNUSED2008-05 ScSpreadsheetSettingsObj::ScSpreadsheetSettingsObj(ScDocShell* pDocSh) :
3013 //UNUSED2008-05 pDocShell( pDocSh )
3014 //UNUSED2008-05 {
3015 //UNUSED2008-05 pDocShell->GetDocument()->AddUnoObject(*this);
3016 //UNUSED2008-05 }
3018 ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj()
3020 if (pDocShell)
3021 pDocShell->GetDocument()->RemoveUnoObject(*this);
3024 void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3026 // Referenz-Update interessiert hier nicht
3028 if ( rHint.ISA( SfxSimpleHint ) &&
3029 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3031 pDocShell = NULL; // ungueltig geworden
3035 // XPropertySet
3037 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo()
3038 throw(uno::RuntimeException)
3040 //! muss noch
3041 return NULL;
3044 void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue(
3045 const rtl::OUString& /* aPropertyName */, const uno::Any& /* aValue */ )
3046 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
3047 lang::IllegalArgumentException, lang::WrappedTargetException,
3048 uno::RuntimeException)
3050 //! muss noch
3053 uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const rtl::OUString& /* aPropertyName */ )
3054 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
3055 uno::RuntimeException)
3057 //! muss noch
3058 return uno::Any();
3061 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj )
3063 //------------------------------------------------------------------------
3065 ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, SCTAB nT) :
3066 pDocShell( pDocSh ),
3067 nTab( nT )
3069 pDocShell->GetDocument()->AddUnoObject(*this);
3072 ScAnnotationsObj::~ScAnnotationsObj()
3074 if (pDocShell)
3075 pDocShell->GetDocument()->RemoveUnoObject(*this);
3078 void ScAnnotationsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3080 //! nTab bei Referenz-Update anpassen!!!
3082 if ( rHint.ISA( SfxSimpleHint ) &&
3083 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3085 pDocShell = NULL; // ungueltig geworden
3089 bool ScAnnotationsObj::GetAddressByIndex_Impl( sal_Int32 nIndex, ScAddress& rPos ) const
3091 if (pDocShell)
3093 sal_Int32 nFound = 0;
3094 ScDocument* pDoc = pDocShell->GetDocument();
3095 ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab );
3096 for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext() )
3098 if (pCell->HasNote())
3100 if (nFound == nIndex)
3102 rPos = ScAddress( aCellIter.GetCol(), aCellIter.GetRow(), aCellIter.GetTab() );
3103 return true;
3105 ++nFound;
3109 return false;
3112 ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl( sal_Int32 nIndex ) const
3114 if (pDocShell)
3116 ScAddress aPos;
3117 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3118 return new ScAnnotationObj( pDocShell, aPos );
3120 return NULL;
3123 // XSheetAnnotations
3125 void SAL_CALL ScAnnotationsObj::insertNew(
3126 const table::CellAddress& aPosition, const ::rtl::OUString& rText )
3127 throw(uno::RuntimeException)
3129 ScUnoGuard aGuard;
3130 if (pDocShell)
3132 DBG_ASSERT( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" );
3133 ScAddress aPos( (SCCOL)aPosition.Column, (SCROW)aPosition.Row, nTab );
3135 ScDocFunc aFunc( *pDocShell );
3136 aFunc.ReplaceNote( aPos, rText, 0, 0, TRUE );
3140 void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException)
3142 ScUnoGuard aGuard;
3143 if (pDocShell)
3145 ScAddress aPos;
3146 if ( GetAddressByIndex_Impl( nIndex, aPos ) )
3148 ScMarkData aMarkData;
3149 aMarkData.SelectTable( aPos.Tab(), TRUE );
3150 aMarkData.SetMultiMarkArea( ScRange(aPos) );
3152 ScDocFunc aFunc(*pDocShell);
3153 aFunc.DeleteContents( aMarkData, IDF_NOTE, TRUE, TRUE );
3158 // XEnumerationAccess
3160 uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration()
3161 throw(uno::RuntimeException)
3163 //! iterate directly (more efficiently)?
3165 ScUnoGuard aGuard;
3166 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.CellAnnotationsEnumeration")));
3169 // XIndexAccess
3171 sal_Int32 SAL_CALL ScAnnotationsObj::getCount() throw(uno::RuntimeException)
3173 ScUnoGuard aGuard;
3174 ULONG nCount = 0;
3175 if (pDocShell)
3177 ScCellIterator aCellIter( pDocShell->GetDocument(), 0,0, nTab, MAXCOL,MAXROW, nTab );
3178 for( ScBaseCell* pCell = aCellIter.GetFirst(); pCell; pCell = aCellIter.GetNext() )
3179 if (pCell->HasNote())
3180 ++nCount;
3182 return nCount;
3185 uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex )
3186 throw(lang::IndexOutOfBoundsException,
3187 lang::WrappedTargetException, uno::RuntimeException)
3189 ScUnoGuard aGuard;
3190 uno::Reference<sheet::XSheetAnnotation> xAnnotation(GetObjectByIndex_Impl(nIndex));
3191 if (xAnnotation.is())
3192 return uno::makeAny(xAnnotation);
3193 else
3194 throw lang::IndexOutOfBoundsException();
3195 // return uno::Any();
3198 uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException)
3200 ScUnoGuard aGuard;
3201 return getCppuType((uno::Reference<sheet::XSheetAnnotation>*)0);
3204 sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException)
3206 ScUnoGuard aGuard;
3207 return ( getCount() != 0 );
3210 //------------------------------------------------------------------------
3212 ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, SCTAB nT) :
3213 pDocShell( pDocSh ),
3214 nTab ( nT )
3216 pDocShell->GetDocument()->AddUnoObject(*this);
3219 ScScenariosObj::~ScScenariosObj()
3221 if (pDocShell)
3222 pDocShell->GetDocument()->RemoveUnoObject(*this);
3225 void ScScenariosObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
3227 if ( rHint.ISA( ScUpdateRefHint ) )
3229 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
3231 //! Referenz-Update fuer Tab und Start/Ende
3233 else if ( rHint.ISA( SfxSimpleHint ) &&
3234 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
3236 pDocShell = NULL; // ungueltig geworden
3240 // XScenarios
3242 BOOL ScScenariosObj::GetScenarioIndex_Impl( const rtl::OUString& rName, SCTAB& rIndex )
3244 //! Case-insensitiv ????
3246 if ( pDocShell )
3248 String aString(rName);
3250 String aTabName;
3251 ScDocument* pDoc = pDocShell->GetDocument();
3252 SCTAB nCount = (SCTAB)getCount();
3253 for (SCTAB i=0; i<nCount; i++)
3254 if (pDoc->GetName( nTab+i+1, aTabName ))
3255 if ( aTabName == aString )
3257 rIndex = i;
3258 return TRUE;
3262 return FALSE;
3265 ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
3267 USHORT nCount = (USHORT)getCount();
3268 if ( pDocShell && nIndex >= 0 && nIndex < nCount )
3269 return new ScTableSheetObj( pDocShell, nTab+static_cast<SCTAB>(nIndex)+1 );
3271 return NULL; // kein Dokument oder falscher Index
3274 ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const rtl::OUString& aName)
3276 SCTAB nIndex;
3277 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3278 return new ScTableSheetObj( pDocShell, nTab+nIndex+1 );
3280 return NULL; // nicht gefunden
3283 void SAL_CALL ScScenariosObj::addNewByName( const rtl::OUString& aName,
3284 const uno::Sequence<table::CellRangeAddress>& aRanges,
3285 const rtl::OUString& aComment )
3286 throw(uno::RuntimeException)
3288 ScUnoGuard aGuard;
3289 if ( pDocShell )
3291 ScMarkData aMarkData;
3292 aMarkData.SelectTable( nTab, TRUE );
3294 USHORT nRangeCount = (USHORT)aRanges.getLength();
3295 if (nRangeCount)
3297 const table::CellRangeAddress* pAry = aRanges.getConstArray();
3298 for (USHORT i=0; i<nRangeCount; i++)
3300 DBG_ASSERT( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" );
3301 ScRange aRange( (SCCOL)pAry[i].StartColumn, (SCROW)pAry[i].StartRow, nTab,
3302 (SCCOL)pAry[i].EndColumn, (SCROW)pAry[i].EndRow, nTab );
3304 aMarkData.SetMultiMarkArea( aRange );
3308 String aNameStr(aName);
3309 String aCommStr(aComment);
3311 Color aColor( COL_LIGHTGRAY ); // Default
3312 USHORT nFlags = SC_SCENARIO_SHOWFRAME | SC_SCENARIO_PRINTFRAME | SC_SCENARIO_TWOWAY | SC_SCENARIO_PROTECT;
3314 pDocShell->MakeScenario( nTab, aNameStr, aCommStr, aColor, nFlags, aMarkData );
3318 void SAL_CALL ScScenariosObj::removeByName( const rtl::OUString& aName )
3319 throw(uno::RuntimeException)
3321 ScUnoGuard aGuard;
3322 SCTAB nIndex;
3323 if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) )
3325 ScDocFunc aFunc(*pDocShell);
3326 aFunc.DeleteTable( nTab+nIndex+1, TRUE, TRUE );
3330 // XEnumerationAccess
3332 uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration()
3333 throw(uno::RuntimeException)
3335 ScUnoGuard aGuard;
3336 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.ScenariosEnumeration")));
3339 // XIndexAccess
3341 sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException)
3343 ScUnoGuard aGuard;
3344 SCTAB nCount = 0;
3345 if ( pDocShell )
3347 ScDocument* pDoc = pDocShell->GetDocument();
3348 if (!pDoc->IsScenario(nTab))
3350 SCTAB nTabCount = pDoc->GetTableCount();
3351 SCTAB nNext = nTab + 1;
3352 while (nNext < nTabCount && pDoc->IsScenario(nNext))
3354 ++nCount;
3355 ++nNext;
3359 return nCount;
3362 uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex )
3363 throw(lang::IndexOutOfBoundsException,
3364 lang::WrappedTargetException, uno::RuntimeException)
3366 ScUnoGuard aGuard;
3367 uno::Reference<sheet::XScenario> xScen(GetObjectByIndex_Impl(nIndex));
3368 if (xScen.is())
3369 return uno::makeAny(xScen);
3370 else
3371 throw lang::IndexOutOfBoundsException();
3372 // return uno::Any();
3375 uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException)
3377 ScUnoGuard aGuard;
3378 return getCppuType((uno::Reference<sheet::XScenario>*)0);
3381 sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException)
3383 ScUnoGuard aGuard;
3384 return ( getCount() != 0 );
3387 uno::Any SAL_CALL ScScenariosObj::getByName( const rtl::OUString& aName )
3388 throw(container::NoSuchElementException,
3389 lang::WrappedTargetException, uno::RuntimeException)
3391 ScUnoGuard aGuard;
3392 uno::Reference<sheet::XScenario> xScen(GetObjectByName_Impl(aName));
3393 if (xScen.is())
3394 return uno::makeAny(xScen);
3395 else
3396 throw container::NoSuchElementException();
3397 // return uno::Any();
3400 uno::Sequence<rtl::OUString> SAL_CALL ScScenariosObj::getElementNames()
3401 throw(uno::RuntimeException)
3403 ScUnoGuard aGuard;
3404 SCTAB nCount = (SCTAB)getCount();
3405 uno::Sequence<rtl::OUString> aSeq(nCount);
3407 if ( pDocShell ) // sonst ist auch Count = 0
3409 String aTabName;
3410 ScDocument* pDoc = pDocShell->GetDocument();
3411 rtl::OUString* pAry = aSeq.getArray();
3412 for (SCTAB i=0; i<nCount; i++)
3413 if (pDoc->GetName( nTab+i+1, aTabName ))
3414 pAry[i] = aTabName;
3417 return aSeq;
3420 sal_Bool SAL_CALL ScScenariosObj::hasByName( const rtl::OUString& aName )
3421 throw(uno::RuntimeException)
3423 ScUnoGuard aGuard;
3424 SCTAB nIndex;
3425 return GetScenarioIndex_Impl( aName, nIndex );