Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vbahelper/helperdecl.hxx>
21 : #include <cppuhelper/queryinterface.hxx>
22 :
23 : #include "vbaworksheet.hxx"
24 : #include "vbanames.hxx"
25 :
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
28 : #include <com/sun/star/beans/XIntrospection.hpp>
29 : #include <com/sun/star/container/XNamed.hpp>
30 : #include <com/sun/star/util/XProtectable.hpp>
31 : #include <com/sun/star/table/XCellRange.hpp>
32 : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
33 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
34 : #include <com/sun/star/sheet/XCalculatable.hpp>
35 : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
36 : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
37 : #include <com/sun/star/sheet/XSheetCellRange.hpp>
38 : #include <com/sun/star/sheet/XSheetCellCursor.hpp>
39 : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
40 : #include <com/sun/star/sheet/XUsedAreaCursor.hpp>
41 : #include <com/sun/star/sheet/XSpreadsheets.hpp>
42 : #include <com/sun/star/sheet/XSheetPastable.hpp>
43 : #include <com/sun/star/sheet/XCellAddressable.hpp>
44 : #include <com/sun/star/sheet/XSheetOutline.hpp>
45 : #include <com/sun/star/sheet/XSheetPageBreak.hpp>
46 : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
47 : #include <com/sun/star/sheet/XNamedRanges.hpp>
48 : #include <com/sun/star/util/XURLTransformer.hpp>
49 : #include <com/sun/star/frame/XDispatchProvider.hpp>
50 : #include <com/sun/star/frame/Desktop.hpp>
51 : #include <com/sun/star/table/XColumnRowRange.hpp>
52 : #include <com/sun/star/table/XTableChartsSupplier.hpp>
53 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
54 : #include <com/sun/star/drawing/XControlShape.hpp>
55 : #include <com/sun/star/form/FormComponentType.hpp>
56 : #include <com/sun/star/form/XFormsSupplier.hpp>
57 : #include <ooo/vba/excel/XlEnableSelection.hpp>
58 : #include <ooo/vba/excel/XlSheetVisibility.hpp>
59 : #include <ooo/vba/excel/XWorkbook.hpp>
60 : #include <ooo/vba/XControlProvider.hpp>
61 :
62 : #include <comphelper/processfactory.hxx>
63 : #include <comphelper/servicehelper.hxx>
64 : #include <vbahelper/vbashapes.hxx>
65 :
66 : #include <com/sun/star/script/vba/VBAEventId.hpp>
67 : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
68 : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
69 : #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
70 : #include <com/sun/star/script/ModuleInfo.hpp>
71 : #include <com/sun/star/script/ModuleType.hpp>
72 :
73 : //zhangyun showdataform
74 : #include <sfx2/sfxdlg.hxx>
75 : #include "scabstdlg.hxx"
76 : #include "tabvwsh.hxx"
77 : #include "scitems.hxx"
78 :
79 : #include <svx/svdouno.hxx>
80 : #include <svx/svdpage.hxx>
81 :
82 : #include "cellsuno.hxx"
83 : #include "drwlayer.hxx"
84 : #include "tabprotection.hxx"
85 : #include "scextopt.hxx"
86 : #include "vbaoutline.hxx"
87 : #include "vbarange.hxx"
88 : #include "vbacomments.hxx"
89 : #include "vbachartobjects.hxx"
90 : #include "vbapivottables.hxx"
91 : #include "vbaoleobject.hxx"
92 : #include "vbaoleobjects.hxx"
93 : #include "vbapagesetup.hxx"
94 : #include "vbapagebreaks.hxx"
95 : #include "vbaworksheets.hxx"
96 : #include "vbahyperlinks.hxx"
97 : #include "vbasheetobjects.hxx"
98 : #include "markdata.hxx"
99 : #include "dbdata.hxx"
100 :
101 : #include "attrib.hxx"
102 :
103 : #define STANDARDWIDTH 2267
104 : #define STANDARDHEIGHT 427
105 :
106 : using namespace com::sun::star;
107 : using namespace ooo::vba;
108 :
109 0 : static void getNewSpreadsheetName (OUString &aNewName, const OUString& aOldName, uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc )
110 : {
111 0 : if (!xSpreadDoc.is())
112 0 : throw lang::IllegalArgumentException( "getNewSpreadsheetName() xSpreadDoc is null", uno::Reference< uno::XInterface >(), 1 );
113 : static const char aUnderScore[] = "_";
114 0 : int currentNum =2;
115 0 : aNewName = aOldName + aUnderScore + OUString::number(currentNum) ;
116 0 : SCTAB nTab = 0;
117 0 : while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) )
118 : {
119 0 : aNewName = aOldName + aUnderScore + OUString::number(++currentNum);
120 : }
121 0 : }
122 :
123 0 : static void removeAllSheets( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, const OUString& aSheetName)
124 : {
125 0 : if (!xSpreadDoc.is())
126 0 : throw lang::IllegalArgumentException( "removeAllSheets() xSpreadDoc is null", uno::Reference< uno::XInterface >(), 1 );
127 0 : uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
128 0 : uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
129 :
130 0 : if ( xIndex.is() )
131 : {
132 0 : uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
133 0 : for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--)
134 : {
135 0 : uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY);
136 0 : uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
137 0 : if (xNamed.is())
138 : {
139 0 : xNameContainer->removeByName(xNamed->getName());
140 : }
141 0 : }
142 :
143 0 : uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY);
144 0 : uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
145 0 : if (xNamed.is())
146 : {
147 0 : xNamed->setName(aSheetName);
148 0 : }
149 0 : }
150 0 : }
151 :
152 : static uno::Reference<frame::XModel>
153 0 : openNewDoc(const OUString& aSheetName )
154 : {
155 0 : uno::Reference<frame::XModel> xModel;
156 : try
157 : {
158 : uno::Reference< uno::XComponentContext > xContext(
159 0 : comphelper::getProcessComponentContext() );
160 :
161 0 : uno::Reference <frame::XDesktop2 > xComponentLoader = frame::Desktop::create(xContext);
162 :
163 0 : uno::Reference<lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL(
164 : OUString( "private:factory/scalc" ),
165 : OUString( "_blank" ), 0,
166 0 : uno::Sequence < ::com::sun::star::beans::PropertyValue >() ) );
167 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xComponent, uno::UNO_QUERY_THROW );
168 0 : if ( xSpreadDoc.is() )
169 : {
170 0 : removeAllSheets(xSpreadDoc,aSheetName);
171 : }
172 0 : xModel.set(xSpreadDoc,uno::UNO_QUERY_THROW);
173 : }
174 0 : catch ( uno::Exception & /*e*/ )
175 : {
176 : }
177 0 : return xModel;
178 : }
179 :
180 4 : ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
181 : const uno::Reference< sheet::XSpreadsheet >& xSheet,
182 4 : const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false )
183 : {
184 4 : }
185 :
186 82 : ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args,
187 82 : uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException, uno::RuntimeException ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false )
188 : {
189 82 : if ( args.getLength() < 3 )
190 0 : throw lang::IllegalArgumentException();
191 :
192 82 : OUString sSheetName;
193 82 : args[2] >>= sSheetName;
194 :
195 164 : uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc( mxModel, uno::UNO_QUERY_THROW );
196 164 : uno::Reference< container::XNameAccess > xNameAccess( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
197 164 : mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW );
198 82 : }
199 :
200 8 : ScVbaWorksheet::~ScVbaWorksheet()
201 : {
202 8 : }
203 :
204 : namespace
205 : {
206 : class theScVbaWorksheetUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScVbaWorksheetUnoTunnelId > {};
207 : }
208 :
209 0 : const uno::Sequence<sal_Int8>& ScVbaWorksheet::getUnoTunnelId()
210 : {
211 0 : return theScVbaWorksheetUnoTunnelId::get().getSeq();
212 : }
213 :
214 : uno::Reference< ov::excel::XWorksheet >
215 0 : ScVbaWorksheet::createSheetCopyInNewDoc(const OUString& aCurrSheetName)
216 : {
217 0 : uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
218 0 : uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
219 0 : uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
220 0 : uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
221 0 : if (xRange.is())
222 0 : xRange->Select();
223 0 : excel::implnCopy(mxModel);
224 0 : uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
225 0 : if (xModel.is())
226 : {
227 0 : excel::implnPaste(xModel);
228 : }
229 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
230 0 : excel::setUpDocumentModules(xSpreadDoc);
231 0 : uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
232 0 : uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
233 0 : uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
234 :
235 0 : ScDocShell* pShell = excel::getDocShell( xModel );
236 0 : OUString aCodeName;
237 0 : pShell->GetDocument().GetCodeName( 0, aCodeName );
238 0 : return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW );
239 : }
240 :
241 : css::uno::Reference< ov::excel::XWorksheet >
242 0 : ScVbaWorksheet::createSheetCopy(uno::Reference<excel::XWorksheet> xSheet, bool bAfter)
243 : {
244 0 : OUString aCurrSheetName = getName();
245 0 : ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
246 :
247 0 : uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
248 0 : uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
249 :
250 0 : SCTAB nDest = 0;
251 0 : SCTAB nSrc = 0;
252 0 : OUString aSheetName = xSheet->getName();
253 0 : bool bSameDoc = ( pDestSheet->getModel() == getModel() );
254 0 : bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
255 0 : bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
256 :
257 : // set sheet name to be newSheet name
258 0 : aSheetName = aCurrSheetName;
259 0 : if ( bSheetExists && bDestSheetExists )
260 : {
261 0 : SCTAB nDummy=0;
262 0 : if(bAfter)
263 0 : nDest++;
264 0 : uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
265 0 : if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
266 0 : getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
267 0 : if ( bSameDoc )
268 0 : xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
269 : else
270 : {
271 0 : ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
272 0 : ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
273 0 : if ( pDestDocShell && pSrcDocShell )
274 0 : pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
275 0 : }
276 : }
277 : // return new sheet
278 0 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
279 0 : uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
280 0 : return xNewSheet;
281 : }
282 :
283 : OUString
284 26 : ScVbaWorksheet::getName() throw (uno::RuntimeException, std::exception)
285 : {
286 26 : uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
287 26 : return xNamed->getName();
288 : }
289 :
290 : void
291 0 : ScVbaWorksheet::setName(const OUString &rName ) throw (uno::RuntimeException, std::exception)
292 : {
293 0 : uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
294 0 : xNamed->setName( rName );
295 0 : }
296 :
297 : sal_Int32
298 0 : ScVbaWorksheet::getVisible() throw (uno::RuntimeException, std::exception)
299 : {
300 0 : uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
301 0 : bool bVisible = false;
302 0 : xProps->getPropertyValue( "IsVisible" ) >>= bVisible;
303 : using namespace ::ooo::vba::excel::XlSheetVisibility;
304 0 : return bVisible ? xlSheetVisible : (mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden);
305 : }
306 :
307 : void
308 0 : ScVbaWorksheet::setVisible( sal_Int32 nVisible ) throw (uno::RuntimeException, std::exception)
309 : {
310 : using namespace ::ooo::vba::excel::XlSheetVisibility;
311 0 : bool bVisible = true;
312 0 : switch( nVisible )
313 : {
314 : case xlSheetVisible: case 1: // Excel accepts -1 and 1 for visible sheets
315 0 : bVisible = true;
316 0 : mbVeryHidden = false;
317 0 : break;
318 : case xlSheetHidden:
319 0 : bVisible = false;
320 0 : mbVeryHidden = false;
321 0 : break;
322 : case xlSheetVeryHidden:
323 0 : bVisible = false;
324 0 : mbVeryHidden = true;
325 0 : break;
326 : default:
327 0 : throw uno::RuntimeException();
328 : }
329 0 : uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
330 0 : xProps->setPropertyValue( "IsVisible", uno::Any( bVisible ) );
331 0 : }
332 :
333 : sal_Int16
334 582 : ScVbaWorksheet::getIndex() throw (uno::RuntimeException, std::exception)
335 : {
336 582 : return getSheetID() + 1;
337 : }
338 :
339 : sal_Int32
340 0 : ScVbaWorksheet::getEnableSelection() throw (uno::RuntimeException, std::exception)
341 : {
342 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
343 0 : SCTAB nTab = 0;
344 0 : if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
345 : {
346 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
347 0 : ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
348 0 : ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
349 0 : bool bLockedCells = false;
350 0 : bool bUnlockedCells = false;
351 0 : if( pProtect )
352 : {
353 0 : bLockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
354 0 : bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
355 : }
356 0 : if( bLockedCells )
357 0 : return excel::XlEnableSelection::xlNoRestrictions;
358 0 : if( bUnlockedCells )
359 0 : return excel::XlEnableSelection::xlUnlockedCells;
360 0 : return excel::XlEnableSelection::xlNoSelection;
361 : }
362 : else
363 0 : throw uno::RuntimeException("Sheet Name does not exist." );
364 : }
365 :
366 : void
367 0 : ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) throw (uno::RuntimeException, std::exception)
368 : {
369 0 : if( (nSelection != excel::XlEnableSelection::xlNoRestrictions) &&
370 0 : (nSelection != excel::XlEnableSelection::xlUnlockedCells) &&
371 : (nSelection != excel::XlEnableSelection::xlNoSelection) )
372 : {
373 0 : DebugHelper::runtimeexception(SbERR_BAD_PARAMETER, OUString() );
374 : }
375 :
376 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
377 0 : SCTAB nTab = 0;
378 0 : if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
379 : {
380 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
381 0 : ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
382 0 : ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
383 : // default is xlNoSelection
384 0 : bool bLockedCells = false;
385 0 : bool bUnlockedCells = false;
386 0 : if( nSelection == excel::XlEnableSelection::xlNoRestrictions )
387 : {
388 0 : bLockedCells = true;
389 0 : bUnlockedCells = true;
390 : }
391 0 : else if( nSelection == excel::XlEnableSelection::xlUnlockedCells )
392 : {
393 0 : bUnlockedCells = true;
394 : }
395 0 : if( pProtect )
396 : {
397 0 : pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells );
398 0 : pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells );
399 0 : }
400 : }
401 : else
402 0 : throw uno::RuntimeException("Sheet Name does not exist." );
403 :
404 0 : }
405 :
406 0 : sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() throw (uno::RuntimeException, std::exception)
407 : {
408 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
409 0 : ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
410 0 : ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID());
411 0 : if (pDBData)
412 0 : return pDBData->HasAutoFilter();
413 0 : return false;
414 : }
415 :
416 0 : void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) throw (uno::RuntimeException, std::exception)
417 : {
418 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
419 0 : ScDocShell* pDocShell = excel::getDocShell( xModel );
420 0 : ScDocument& rDoc = pDocShell->GetDocument();
421 0 : ScDBData* pDBData = rDoc.GetAnonymousDBData(getSheetID());
422 0 : if (pDBData)
423 : {
424 0 : pDBData->SetAutoFilter(bAutoFilterMode);
425 0 : ScRange aRange;
426 0 : pDBData->GetArea(aRange);
427 0 : if (bAutoFilterMode)
428 0 : rDoc.ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
429 0 : aRange.aEnd.Col(), aRange.aStart.Row(),
430 0 : aRange.aStart.Tab(), SC_MF_AUTO );
431 0 : else if (!bAutoFilterMode)
432 0 : rDoc.RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
433 0 : aRange.aEnd.Col(), aRange.aStart.Row(),
434 0 : aRange.aStart.Tab(), SC_MF_AUTO );
435 0 : ScRange aPaintRange(aRange.aStart, aRange.aEnd);
436 0 : aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
437 0 : pDocShell->PostPaint(aPaintRange, PAINT_GRID);
438 0 : }
439 0 : }
440 :
441 : uno::Reference< excel::XRange >
442 54 : ScVbaWorksheet::getUsedRange() throw (uno::RuntimeException, std::exception)
443 : {
444 54 : uno::Reference< sheet::XSheetCellRange > xSheetCellRange(getSheet(), uno::UNO_QUERY_THROW );
445 108 : uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor( getSheet()->createCursorByRange( xSheetCellRange ), uno::UNO_QUERY_THROW );
446 108 : uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
447 54 : xUsedCursor->gotoStartOfUsedArea( false );
448 54 : xUsedCursor->gotoEndOfUsedArea( true );
449 108 : uno::Reference< table::XCellRange > xRange( xSheetCellCursor, uno::UNO_QUERY);
450 108 : return new ScVbaRange(this, mxContext, xRange);
451 : }
452 :
453 : uno::Reference< excel::XOutline >
454 0 : ScVbaWorksheet::Outline( ) throw (uno::RuntimeException, std::exception)
455 : {
456 0 : uno::Reference<sheet::XSheetOutline> xOutline(getSheet(),uno::UNO_QUERY_THROW);
457 0 : return new ScVbaOutline( this, mxContext, xOutline);
458 : }
459 :
460 : uno::Reference< excel::XPageSetup >
461 56 : ScVbaWorksheet::PageSetup( ) throw (uno::RuntimeException, std::exception)
462 : {
463 56 : return new ScVbaPageSetup( this, mxContext, getSheet(), getModel() );
464 : }
465 :
466 : uno::Any
467 1 : ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
468 : {
469 1 : uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(getSheet(),uno::UNO_QUERY_THROW);
470 2 : uno::Reference< excel::XHPageBreaks > xHPageBreaks( new ScVbaHPageBreaks( this, mxContext, xSheetPageBreak));
471 1 : if ( aIndex.hasValue() )
472 0 : return xHPageBreaks->Item( aIndex, uno::Any());
473 2 : return uno::makeAny( xHPageBreaks );
474 : }
475 :
476 : uno::Any
477 2 : ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex ) throw ( uno::RuntimeException, std::exception )
478 : {
479 2 : uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak( getSheet(), uno::UNO_QUERY_THROW );
480 4 : uno::Reference< excel::XVPageBreaks > xVPageBreaks( new ScVbaVPageBreaks( this, mxContext, xSheetPageBreak ) );
481 2 : if( aIndex.hasValue() )
482 0 : return xVPageBreaks->Item( aIndex, uno::Any());
483 4 : return uno::makeAny( xVPageBreaks );
484 : }
485 :
486 : sal_Int32
487 0 : ScVbaWorksheet::getStandardWidth() throw (uno::RuntimeException, std::exception)
488 : {
489 0 : return STANDARDWIDTH ;
490 : }
491 :
492 : sal_Int32
493 0 : ScVbaWorksheet::getStandardHeight() throw (uno::RuntimeException, std::exception)
494 : {
495 0 : return STANDARDHEIGHT;
496 : }
497 :
498 : sal_Bool
499 0 : ScVbaWorksheet::getProtectionMode() throw (uno::RuntimeException, std::exception)
500 : {
501 0 : return false;
502 : }
503 :
504 : sal_Bool
505 0 : ScVbaWorksheet::getProtectContents()throw (uno::RuntimeException, std::exception)
506 : {
507 0 : uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
508 0 : return xProtectable->isProtected();
509 : }
510 :
511 : sal_Bool
512 0 : ScVbaWorksheet::getProtectDrawingObjects() throw (uno::RuntimeException, std::exception)
513 : {
514 0 : SCTAB nTab = 0;
515 0 : OUString aSheetName = getName();
516 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
517 0 : bool bSheetExists = ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nTab);
518 0 : if ( bSheetExists )
519 : {
520 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
521 0 : ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
522 0 : ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
523 0 : if ( pProtect )
524 0 : return pProtect->isOptionEnabled( ScTableProtection::OBJECTS );
525 : }
526 0 : return false;
527 : }
528 :
529 : sal_Bool
530 0 : ScVbaWorksheet::getProtectScenarios() throw (uno::RuntimeException, std::exception)
531 : {
532 0 : return false;
533 : }
534 :
535 : void
536 4 : ScVbaWorksheet::Activate() throw (uno::RuntimeException, std::exception)
537 : {
538 : uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
539 4 : getModel()->getCurrentController(), uno::UNO_QUERY_THROW );
540 4 : xSpreadsheet->setActiveSheet(getSheet());
541 4 : }
542 :
543 : void
544 4 : ScVbaWorksheet::Select() throw (uno::RuntimeException, std::exception)
545 : {
546 4 : Activate();
547 4 : }
548 :
549 : void
550 0 : ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException, std::exception)
551 : {
552 0 : uno::Reference<excel::XWorksheet> xSheet;
553 0 : OUString aCurrSheetName = getName();
554 :
555 0 : if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
556 : {
557 0 : uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
558 0 : uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
559 0 : uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
560 : // #FIXME needs worksheet as parent
561 0 : uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
562 0 : if (xRange.is())
563 0 : xRange->Select();
564 0 : excel::implnCopy(mxModel);
565 0 : uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
566 0 : if (xModel.is())
567 : {
568 0 : excel::implnPaste(xModel);
569 0 : Delete();
570 : }
571 0 : return ;
572 : }
573 :
574 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
575 0 : SCTAB nDest = 0;
576 0 : if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) )
577 : {
578 0 : bool bAfter = After.hasValue();
579 0 : if (bAfter)
580 0 : nDest++;
581 0 : uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
582 0 : xSheets->moveByName(aCurrSheetName,nDest);
583 0 : }
584 : }
585 :
586 : void
587 0 : ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException, std::exception)
588 : {
589 0 : uno::Reference<excel::XWorksheet> xSheet;
590 0 : if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
591 : {
592 0 : createSheetCopyInNewDoc(getName());
593 0 : return;
594 : }
595 :
596 0 : uno::Reference<excel::XWorksheet> xNewSheet = createSheetCopy(xSheet, After.hasValue());
597 0 : xNewSheet->Activate();
598 : }
599 :
600 : void
601 3 : ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) throw (uno::RuntimeException, std::exception)
602 : {
603 : // #TODO# #FIXME# Link is not used
604 3 : uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
605 3 : if ( xRange.is() )
606 1 : xRange->Select();
607 3 : excel::implnPaste( mxModel );
608 3 : }
609 :
610 : void
611 0 : ScVbaWorksheet::Delete() throw (uno::RuntimeException, std::exception)
612 : {
613 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
614 0 : OUString aSheetName = getName();
615 0 : if ( xSpreadDoc.is() )
616 : {
617 0 : SCTAB nTab = 0;
618 0 : if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab ))
619 : {
620 0 : return;
621 : }
622 0 : uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
623 0 : uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
624 0 : xNameContainer->removeByName(aSheetName);
625 0 : mxSheet.clear();
626 0 : }
627 : }
628 :
629 : uno::Reference< excel::XWorksheet >
630 4 : ScVbaWorksheet::getSheetAtOffset(SCTAB offset) throw (uno::RuntimeException)
631 : {
632 4 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
633 8 : uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
634 8 : uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
635 :
636 4 : SCTAB nIdx = 0;
637 4 : if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) )
638 0 : return uno::Reference< excel::XWorksheet >();
639 4 : nIdx = nIdx + offset;
640 8 : uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW);
641 : // parent will be the parent of 'this' worksheet
642 8 : return new ScVbaWorksheet (getParent(), mxContext, xSheet, getModel());
643 : }
644 :
645 : uno::Reference< excel::XWorksheet >
646 2 : ScVbaWorksheet::getNext() throw (uno::RuntimeException, std::exception)
647 : {
648 2 : return getSheetAtOffset(static_cast<SCTAB>(1));
649 : }
650 :
651 : uno::Reference< excel::XWorksheet >
652 2 : ScVbaWorksheet::getPrevious() throw (uno::RuntimeException, std::exception)
653 : {
654 2 : return getSheetAtOffset(-1);
655 : }
656 :
657 : void
658 0 : ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObjects*/, const uno::Any& /*Contents*/, const uno::Any& /*Scenarios*/, const uno::Any& /*UserInterfaceOnly*/ ) throw (uno::RuntimeException, std::exception)
659 : {
660 : // #TODO# #FIXME# is there anything we can do with the unused param
661 : // can the implementation use anything else here
662 0 : uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
663 0 : OUString aPasswd;
664 0 : Password >>= aPasswd;
665 0 : xProtectable->protect( aPasswd );
666 0 : }
667 :
668 : void
669 0 : ScVbaWorksheet::Unprotect( const uno::Any& Password ) throw (uno::RuntimeException, std::exception)
670 : {
671 0 : uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
672 0 : OUString aPasswd;
673 0 : Password >>= aPasswd;
674 0 : xProtectable->unprotect( aPasswd );
675 0 : }
676 :
677 : void
678 3 : ScVbaWorksheet::Calculate() throw (uno::RuntimeException, std::exception)
679 : {
680 3 : uno::Reference <sheet::XCalculatable> xReCalculate(getModel(), uno::UNO_QUERY_THROW);
681 3 : xReCalculate->calculate();
682 3 : }
683 :
684 : uno::Reference< excel::XRange >
685 255 : ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 ) throw (uno::RuntimeException, std::exception)
686 : {
687 : uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext
688 255 : , uno::Reference< table::XCellRange >( getSheet(), uno::UNO_QUERY_THROW ) ) );
689 255 : return xSheetRange->Range( Cell1, Cell2 );
690 : }
691 :
692 : void
693 0 : ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::Any& /*IgnoreUppercase*/,const uno::Any& /*AlwaysSuggest*/, const uno::Any& /*SpellingLang*/ ) throw (uno::RuntimeException, std::exception)
694 : {
695 : // #TODO# #FIXME# unused params above, can we do anything with those
696 0 : OUString url = ".uno:SpellDialog";
697 0 : uno::Reference< frame::XModel > xModel( getModel() );
698 0 : dispatchRequests(xModel,url);
699 0 : }
700 :
701 : uno::Reference< excel::XRange >
702 30 : ScVbaWorksheet::getSheetRange() throw (uno::RuntimeException)
703 : {
704 30 : uno::Reference< table::XCellRange > xRange( getSheet(),uno::UNO_QUERY_THROW );
705 30 : return uno::Reference< excel::XRange >( new ScVbaRange( this, mxContext, xRange ) );
706 : }
707 :
708 : // These are hacks - we prolly (somehow) need to inherit
709 : // the vbarange functionality here ...
710 : uno::Reference< excel::XRange >
711 226 : ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol )
712 : throw (uno::RuntimeException, std::exception)
713 : {
714 : // Performance optimization for often-called Cells method:
715 : // Use a common helper method instead of creating a new ScVbaRange object
716 226 : uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW );
717 226 : return ScVbaRange::CellsHelper( this, mxContext, xRange, nRow, nCol );
718 : }
719 :
720 : uno::Reference< excel::XRange >
721 16 : ScVbaWorksheet::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
722 : {
723 16 : return getSheetRange()->Rows( aIndex );
724 : }
725 :
726 : uno::Reference< excel::XRange >
727 14 : ScVbaWorksheet::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
728 : {
729 14 : return getSheetRange()->Columns( aIndex );
730 : }
731 :
732 : uno::Any SAL_CALL
733 0 : ScVbaWorksheet::ChartObjects( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
734 : {
735 0 : if ( !mxCharts.is() )
736 : {
737 0 : uno::Reference< table::XTableChartsSupplier > xChartSupplier( getSheet(), uno::UNO_QUERY_THROW );
738 0 : uno::Reference< table::XTableCharts > xTableCharts = xChartSupplier->getCharts();
739 :
740 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxSheet, uno::UNO_QUERY_THROW );
741 0 : mxCharts = new ScVbaChartObjects( this, mxContext, xTableCharts, xDrawPageSupplier );
742 : }
743 0 : if ( Index.hasValue() )
744 : {
745 0 : uno::Reference< XCollection > xColl( mxCharts, uno::UNO_QUERY_THROW );
746 0 : return xColl->Item( Index, uno::Any() );
747 : }
748 : else
749 0 : return uno::makeAny( mxCharts );
750 :
751 : }
752 :
753 : uno::Any SAL_CALL
754 0 : ScVbaWorksheet::PivotTables( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
755 : {
756 0 : uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
757 0 : uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
758 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
759 :
760 0 : uno::Reference< XCollection > xColl( new ScVbaPivotTables( this, mxContext, xIndexAccess ) );
761 0 : if ( Index.hasValue() )
762 0 : return xColl->Item( Index, uno::Any() );
763 0 : return uno::makeAny( xColl );
764 : }
765 :
766 : uno::Any SAL_CALL
767 0 : ScVbaWorksheet::Comments( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
768 : {
769 0 : uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
770 0 : uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
771 0 : uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
772 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xAnnos, uno::UNO_QUERY_THROW );
773 0 : uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) );
774 0 : if ( Index.hasValue() )
775 0 : return xColl->Item( Index, uno::Any() );
776 0 : return uno::makeAny( xColl );
777 : }
778 :
779 : uno::Any SAL_CALL
780 0 : ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
781 : {
782 : /* The worksheet always returns the same Hyperlinks object.
783 : See vbahyperlinks.hxx for more details. */
784 0 : if( !mxHlinks.is() )
785 0 : mxHlinks.set( new ScVbaHyperlinks( this, mxContext ) );
786 0 : if( aIndex.hasValue() )
787 0 : return uno::Reference< XCollection >( mxHlinks, uno::UNO_QUERY_THROW )->Item( aIndex, uno::Any() );
788 0 : return uno::Any( mxHlinks );
789 : }
790 :
791 : uno::Any SAL_CALL
792 0 : ScVbaWorksheet::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
793 : {
794 : // fake sheet-local names by returning all global names
795 : // #163498# initialize Names object with correct parent (this worksheet)
796 : // TODO: real sheet-local names...
797 0 : uno::Reference< beans::XPropertySet > xProps( mxModel, uno::UNO_QUERY_THROW );
798 0 : uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue("NamedRanges"), uno::UNO_QUERY_THROW );
799 0 : uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, mxModel ) );
800 0 : if ( aIndex.hasValue() )
801 0 : return uno::Any( xNames->Item( aIndex, uno::Any() ) );
802 0 : return uno::Any( xNames );
803 : }
804 :
805 : uno::Any SAL_CALL
806 1 : ScVbaWorksheet::OLEObjects( const uno::Any& Index ) throw (uno::RuntimeException, std::exception)
807 : {
808 1 : uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
809 2 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
810 2 : uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
811 2 : uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPage, uno::UNO_QUERY_THROW );
812 :
813 2 : uno::Reference< excel::XOLEObjects >xOleObjects( new ScVbaOLEObjects( this, mxContext, xIndexAccess ) );
814 1 : if( Index.hasValue() )
815 1 : return xOleObjects->Item( Index, uno::Any() );
816 1 : return uno::Any( xOleObjects );
817 : }
818 :
819 : uno::Any SAL_CALL
820 42 : ScVbaWorksheet::Shapes( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
821 : {
822 42 : uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
823 84 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
824 84 : uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
825 84 : uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
826 :
827 84 : uno::Reference< msforms::XShapes> xVbaShapes( new ScVbaShapes( this, mxContext, xIndexAccess, getModel() ) );
828 42 : if ( aIndex.hasValue() )
829 6 : return xVbaShapes->Item( aIndex, uno::Any() );
830 78 : return uno::makeAny( xVbaShapes );
831 : }
832 :
833 : uno::Any SAL_CALL
834 0 : ScVbaWorksheet::Buttons( const uno::Any& rIndex ) throw (uno::RuntimeException, std::exception)
835 : {
836 0 : if( !mxButtons.is() )
837 0 : mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
838 : else
839 0 : mxButtons->collectShapes();
840 0 : if( rIndex.hasValue() )
841 0 : return mxButtons->Item( rIndex, uno::Any() );
842 0 : return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
843 : }
844 :
845 : uno::Any SAL_CALL
846 0 : ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
847 : {
848 0 : throw uno::RuntimeException();
849 : }
850 :
851 : uno::Any SAL_CALL
852 0 : ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
853 : {
854 0 : throw uno::RuntimeException();
855 : }
856 :
857 : uno::Any SAL_CALL
858 0 : ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
859 : {
860 0 : throw uno::RuntimeException();
861 : }
862 :
863 : uno::Any SAL_CALL
864 0 : ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
865 : {
866 0 : throw uno::RuntimeException();
867 : }
868 :
869 : uno::Any SAL_CALL
870 0 : ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
871 : {
872 0 : throw uno::RuntimeException();
873 : }
874 :
875 : uno::Any SAL_CALL
876 0 : ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
877 : {
878 0 : throw uno::RuntimeException();
879 : }
880 :
881 : uno::Any SAL_CALL
882 0 : ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
883 : {
884 0 : throw uno::RuntimeException();
885 : }
886 :
887 : uno::Any SAL_CALL
888 0 : ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException, std::exception)
889 : {
890 0 : throw uno::RuntimeException();
891 : }
892 :
893 : void SAL_CALL
894 0 : ScVbaWorksheet::ShowDataForm( ) throw (uno::RuntimeException, std::exception)
895 : {
896 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
897 0 : ScTabViewShell* pTabViewShell = excel::getBestViewShell( xModel );
898 :
899 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
900 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
901 :
902 : AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg(pTabViewShell->GetDialogParent(),
903 0 : pTabViewShell);
904 : OSL_ENSURE(pDlg, "Dialog create fail!");
905 :
906 0 : pDlg->Execute();
907 0 : }
908 :
909 : uno::Any SAL_CALL
910 2 : ScVbaWorksheet::Evaluate( const OUString& Name ) throw (uno::RuntimeException, std::exception)
911 : {
912 : // #TODO Evaluate allows other things to be evaluated, e.g. functions
913 : // I think ( like SIN(3) etc. ) need to investigate that
914 : // named Ranges also? e.g. [MyRange] if so need a list of named ranges
915 2 : uno::Any aVoid;
916 2 : return uno::Any( Range( uno::Any( Name ), aVoid ) );
917 : }
918 :
919 : uno::Reference< beans::XIntrospectionAccess > SAL_CALL
920 0 : ScVbaWorksheet::getIntrospection( ) throw (uno::RuntimeException, std::exception)
921 : {
922 0 : return uno::Reference< beans::XIntrospectionAccess >();
923 : }
924 :
925 : uno::Any SAL_CALL
926 0 : ScVbaWorksheet::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
927 : {
928 : OSL_TRACE("** ScVbaWorksheet::invoke( %s ), will barf",
929 : OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
930 :
931 0 : throw uno::RuntimeException(); // unsupported operation
932 : }
933 :
934 : void SAL_CALL
935 0 : ScVbaWorksheet::setValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
936 : {
937 0 : setDefaultPropByIntrospection( getValue( aPropertyName ), aValue );
938 0 : }
939 : uno::Any SAL_CALL
940 60 : ScVbaWorksheet::getValue( const OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
941 : {
942 60 : uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
943 :
944 120 : uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
945 120 : uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext("ooo.vba.ControlProvider", mxContext ), uno::UNO_QUERY_THROW );
946 120 : uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
947 120 : return uno::makeAny( xControl );
948 : }
949 :
950 : sal_Bool SAL_CALL
951 60 : ScVbaWorksheet::hasMethod( const OUString& /*aName*/ ) throw (uno::RuntimeException, std::exception)
952 : {
953 60 : return false;
954 : }
955 :
956 : uno::Reference< container::XNameAccess >
957 7 : ScVbaWorksheet::getFormControls()
958 : {
959 7 : uno::Reference< container::XNameAccess > xFormControls;
960 : try
961 : {
962 7 : uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
963 14 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
964 14 : uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
965 14 : uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
966 : // get the www-standard container ( maybe we should access the
967 : // 'www-standard' by name rather than index, this seems an
968 : // implementation detail
969 7 : if( xIndexAccess->hasElements() )
970 14 : xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
971 :
972 : }
973 0 : catch( uno::Exception& )
974 : {
975 : }
976 7 : return xFormControls;
977 :
978 : }
979 : sal_Bool SAL_CALL
980 7 : ScVbaWorksheet::hasProperty( const OUString& aName ) throw (uno::RuntimeException, std::exception)
981 : {
982 7 : uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
983 7 : if ( xFormControls.is() )
984 7 : return xFormControls->hasByName( aName );
985 0 : return false;
986 : }
987 :
988 : uno::Any
989 60 : ScVbaWorksheet::getControlShape( const OUString& sName )
990 : {
991 : // ideally we would get an XControl object but it appears an XControl
992 : // implementation only exists for a Control implementation optained from the
993 : // view ( e.g. in basic you would get this from
994 : // thiscomponent.currentcontroller.getControl( controlModel ) )
995 : // and the thing to realise is that it is only possible to get an XControl
996 : // for a currently displayed control :-( often we would want to modify
997 : // a control not on the active sheet. But.. you can always access the
998 : // XControlShape from the DrawPage whether that is the active drawpage or not
999 :
1000 60 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getSheet(), uno::UNO_QUERY_THROW );
1001 120 : uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
1002 :
1003 60 : sal_Int32 nCount = xIndexAccess->getCount();
1004 111 : for( int index = 0; index < nCount; index++ )
1005 : {
1006 111 : uno::Any aUnoObj = xIndexAccess->getByIndex( index );
1007 : // It seems there are some drawing objects that can not query into Control shapes?
1008 162 : uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
1009 111 : if( xControlShape.is() )
1010 : {
1011 111 : uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
1012 111 : if( sName.equals( xNamed->getName() ))
1013 : {
1014 60 : return aUnoObj;
1015 51 : }
1016 : }
1017 51 : }
1018 60 : return uno::Any();
1019 : }
1020 :
1021 : OUString
1022 0 : ScVbaWorksheet::getServiceImplName()
1023 : {
1024 0 : return OUString("ScVbaWorksheet");
1025 : }
1026 :
1027 : void SAL_CALL
1028 0 : ScVbaWorksheet::setEnableCalculation( sal_Bool bEnableCalculation ) throw ( script::BasicErrorException, uno::RuntimeException, std::exception)
1029 : {
1030 0 : uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
1031 0 : xCalculatable->enableAutomaticCalculation( bEnableCalculation);
1032 0 : }
1033 : sal_Bool SAL_CALL
1034 2 : ScVbaWorksheet::getEnableCalculation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
1035 : {
1036 2 : uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
1037 2 : return xCalculatable->isAutomaticCalculationEnabled();
1038 : }
1039 :
1040 : uno::Sequence< OUString >
1041 0 : ScVbaWorksheet::getServiceNames()
1042 : {
1043 0 : static uno::Sequence< OUString > aServiceNames;
1044 0 : if ( aServiceNames.getLength() == 0 )
1045 : {
1046 0 : aServiceNames.realloc( 1 );
1047 0 : aServiceNames[ 0 ] = "ooo.vba.excel.Worksheet";
1048 : }
1049 0 : return aServiceNames;
1050 : }
1051 :
1052 : OUString SAL_CALL
1053 0 : ScVbaWorksheet::getCodeName() throw (css::uno::RuntimeException, std::exception)
1054 : {
1055 0 : uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW );
1056 0 : return xSheetProp->getPropertyValue("CodeName").get< OUString >();
1057 : }
1058 :
1059 : sal_Int16
1060 582 : ScVbaWorksheet::getSheetID() throw (uno::RuntimeException)
1061 : {
1062 582 : uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxSheet, uno::UNO_QUERY_THROW ); // if ActiveSheet, mxSheet is null.
1063 582 : return xAddressable->getRangeAddress().Sheet;
1064 : }
1065 :
1066 : void SAL_CALL
1067 0 : ScVbaWorksheet::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName, const uno::Any& IgnorePrintAreas ) throw (uno::RuntimeException, std::exception)
1068 : {
1069 0 : sal_Int32 nTo = 0;
1070 0 : sal_Int32 nFrom = 0;
1071 0 : sal_Int16 nCopies = 1;
1072 0 : bool bCollate = false;
1073 0 : bool bSelection = false;
1074 0 : bool bIgnorePrintAreas = false;
1075 0 : From >>= nFrom;
1076 0 : To >>= nTo;
1077 0 : Copies >>= nCopies;
1078 0 : IgnorePrintAreas >>= bIgnorePrintAreas;
1079 0 : if ( nCopies > 1 ) // Collate only useful when more that 1 copy
1080 0 : Collate >>= bCollate;
1081 :
1082 0 : if ( !( nFrom || nTo ) )
1083 0 : bSelection = true;
1084 :
1085 0 : uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
1086 0 : PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection );
1087 0 : }
1088 :
1089 : sal_Int64 SAL_CALL
1090 0 : ScVbaWorksheet::getSomething(const uno::Sequence<sal_Int8 > & rId) throw(uno::RuntimeException, std::exception)
1091 : {
1092 0 : if (rId.getLength() == 16 &&
1093 0 : 0 == memcmp( ScVbaWorksheet::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ))
1094 : {
1095 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1096 : }
1097 0 : return 0;
1098 : }
1099 :
1100 : namespace worksheet
1101 : {
1102 : namespace sdecl = comphelper::service_decl;
1103 3 : sdecl::vba_service_class_<ScVbaWorksheet, sdecl::with_args<true> > serviceImpl;
1104 3 : extern sdecl::ServiceDecl const serviceDecl(
1105 : serviceImpl,
1106 : "ScVbaWorksheet",
1107 : "ooo.vba.excel.Worksheet" );
1108 9 : }
1109 :
1110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|