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 : #include <vbahelper/helperdecl.hxx>
20 : #include "vbawindow.hxx"
21 : #include "vbaworksheets.hxx"
22 : #include "vbaworksheet.hxx"
23 : #include "vbaglobals.hxx"
24 : #include "vbapane.hxx"
25 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
27 : #include <com/sun/star/container/XNamed.hpp>
28 : #include <com/sun/star/view/DocumentZoomType.hpp>
29 : #include <com/sun/star/table/CellRangeAddress.hpp>
30 : #include <ooo/vba/excel/XlWindowState.hpp>
31 : #include <ooo/vba/excel/XlWindowView.hpp>
32 : #include <ooo/vba/excel/Constants.hpp>
33 : #include <com/sun/star/awt/XWindow.hpp>
34 : #include <com/sun/star/awt/XWindow2.hpp>
35 : #include <com/sun/star/awt/PosSize.hpp>
36 :
37 : #include <docsh.hxx>
38 : #include <tabvwsh.hxx>
39 : #include <docuno.hxx>
40 : #include <sc.hrc>
41 : #include <boost/unordered_map.hpp>
42 : #include <sfx2/viewfrm.hxx>
43 : #include <vcl/wrkwin.hxx>
44 : #include "unonames.hxx"
45 : #include "markdata.hxx"
46 :
47 : using namespace ::com::sun::star;
48 : using namespace ::ooo::vba;
49 : using namespace ::ooo::vba::excel::XlWindowState;
50 :
51 : typedef boost::unordered_map< OUString,
52 : SCTAB, OUStringHash,
53 : ::std::equal_to< OUString > > NameIndexHash;
54 :
55 : typedef std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets;
56 :
57 : typedef ::cppu::WeakImplHelper1< container::XEnumeration > Enumeration_BASE;
58 :
59 : typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess
60 : , com::sun::star::container::XIndexAccess
61 : , com::sun::star::container::XNameAccess
62 : > SelectedSheets_BASE;
63 :
64 :
65 0 : class SelectedSheetsEnum : public Enumeration_BASE
66 : {
67 : public:
68 : uno::Reference< uno::XComponentContext > m_xContext;
69 : Sheets m_sheets;
70 : uno::Reference< frame::XModel > m_xModel;
71 : Sheets::const_iterator m_it;
72 :
73 0 : SelectedSheetsEnum( const uno::Reference< uno::XComponentContext >& xContext, const Sheets& sheets, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : m_xContext( xContext ), m_sheets( sheets ), m_xModel( xModel )
74 : {
75 0 : m_it = m_sheets.begin();
76 0 : }
77 : // XEnumeration
78 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
79 : {
80 0 : return m_it != m_sheets.end();
81 : }
82 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
83 : {
84 0 : if ( !hasMoreElements() )
85 : {
86 0 : throw container::NoSuchElementException();
87 : }
88 : // #FIXME needs ThisWorkbook as parent
89 0 : return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) );
90 : }
91 :
92 :
93 : };
94 :
95 0 : class SelectedSheetsEnumAccess : public SelectedSheets_BASE
96 : {
97 : uno::Reference< uno::XComponentContext > m_xContext;
98 : NameIndexHash namesToIndices;
99 : Sheets sheets;
100 : uno::Reference< frame::XModel > m_xModel;
101 : public:
102 0 : SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel )
103 : {
104 0 : ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() );
105 0 : if ( !pModel )
106 0 : throw uno::RuntimeException("Cannot obtain current document", uno::Reference< uno::XInterface >() );
107 0 : ScDocShell* pDocShell = (ScDocShell*)pModel->GetEmbeddedObject();
108 0 : if ( !pDocShell )
109 0 : throw uno::RuntimeException("Cannot obtain docshell", uno::Reference< uno::XInterface >() );
110 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
111 0 : if ( !pViewShell )
112 0 : throw uno::RuntimeException("Cannot obtain view shell", uno::Reference< uno::XInterface >() );
113 :
114 0 : SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
115 0 : uno::Sequence<sal_Int32> aSheets( nTabCount );
116 0 : SCTAB nIndex = 0;
117 0 : const ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData();
118 0 : sheets.reserve( nTabCount );
119 0 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW );
120 0 : uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW );
121 0 : ScMarkData::const_iterator itr = rMarkData.begin(), itrEnd = rMarkData.end();
122 0 : for (; itr != itrEnd && *itr < nTabCount; ++itr)
123 : {
124 0 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( *itr ), uno::UNO_QUERY_THROW );
125 0 : uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
126 0 : sheets.push_back( xSheet );
127 0 : namesToIndices[ xNamed->getName() ] = nIndex++;
128 0 : }
129 :
130 0 : }
131 :
132 : //XEnumerationAccess
133 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
134 : {
135 0 : return new SelectedSheetsEnum( m_xContext, sheets, m_xModel );
136 : }
137 : // XIndexAccess
138 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
139 : {
140 0 : return sheets.size();
141 : }
142 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
143 : {
144 0 : if ( Index < 0
145 0 : || static_cast< Sheets::size_type >( Index ) >= sheets.size() )
146 0 : throw lang::IndexOutOfBoundsException();
147 :
148 0 : return uno::makeAny( sheets[ Index ] );
149 : }
150 :
151 : //XElementAccess
152 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
153 : {
154 0 : return excel::XWorksheet::static_type(0);
155 : }
156 :
157 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
158 : {
159 0 : return ( !sheets.empty() );
160 : }
161 :
162 : //XNameAccess
163 0 : virtual uno::Any SAL_CALL getByName( const OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
164 : {
165 0 : NameIndexHash::const_iterator it = namesToIndices.find( aName );
166 0 : if ( it == namesToIndices.end() )
167 0 : throw container::NoSuchElementException();
168 0 : return uno::makeAny( sheets[ it->second ] );
169 :
170 : }
171 :
172 0 : virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
173 : {
174 0 : uno::Sequence< OUString > names( namesToIndices.size() );
175 0 : OUString* pString = names.getArray();
176 0 : NameIndexHash::const_iterator it = namesToIndices.begin();
177 0 : NameIndexHash::const_iterator it_end = namesToIndices.end();
178 0 : for ( ; it != it_end; ++it, ++pString )
179 0 : *pString = it->first;
180 0 : return names;
181 : }
182 :
183 0 : virtual ::sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (uno::RuntimeException)
184 : {
185 0 : NameIndexHash::const_iterator it = namesToIndices.find( aName );
186 0 : return (it != namesToIndices.end());
187 : }
188 :
189 :
190 : };
191 :
192 59 : ScVbaWindow::ScVbaWindow(
193 : const uno::Reference< XHelperInterface >& xParent,
194 : const uno::Reference< uno::XComponentContext >& xContext,
195 : const uno::Reference< frame::XModel >& xModel,
196 : const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) :
197 59 : WindowImpl_BASE( xParent, xContext, xModel, xController )
198 : {
199 59 : init();
200 59 : }
201 :
202 0 : ScVbaWindow::ScVbaWindow(
203 : const uno::Sequence< uno::Any >& args,
204 : const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) :
205 0 : WindowImpl_BASE( args, xContext )
206 : {
207 0 : init();
208 0 : }
209 :
210 : void
211 59 : ScVbaWindow::init()
212 : {
213 : /* This method is called from the constructor, thus the own refcount is
214 : still zero. The implementation of ActivePane() uses a UNO reference of
215 : this (to set this window as parent of the pane obejct). This requires
216 : the own refcount to be non-zero, otherwise this instance will be
217 : desctructed immediately! Guard the call to ActivePane() in try/catch to
218 : not miss the decrementation of the reference count on exception. */
219 59 : osl_atomic_increment( &m_refCount );
220 : try
221 : {
222 59 : m_xPane = ActivePane();
223 : }
224 0 : catch( uno::Exception& )
225 : {
226 : }
227 59 : osl_atomic_decrement( &m_refCount );
228 59 : }
229 :
230 : uno::Reference< beans::XPropertySet >
231 44 : ScVbaWindow::getControllerProps() throw (uno::RuntimeException)
232 : {
233 44 : return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW );
234 : }
235 :
236 : uno::Reference< beans::XPropertySet >
237 29 : ScVbaWindow::getFrameProps() throw (uno::RuntimeException)
238 : {
239 29 : return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW );
240 : }
241 :
242 : uno::Reference< awt::XDevice >
243 6 : ScVbaWindow::getDevice() throw (uno::RuntimeException)
244 : {
245 6 : return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW );
246 : }
247 :
248 : void
249 6 : ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException)
250 : {
251 6 : if( !m_xPane.is() )
252 0 : throw uno::RuntimeException();
253 6 : if( bLargeScroll )
254 4 : m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
255 : else
256 2 : m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
257 6 : }
258 :
259 : void SAL_CALL
260 2 : ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
261 : {
262 2 : Scroll( Down, Up, ToRight, ToLeft );
263 2 : }
264 :
265 : void SAL_CALL
266 4 : ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
267 : {
268 4 : Scroll( Down, Up, ToRight, ToLeft, true );
269 4 : }
270 :
271 : uno::Any SAL_CALL
272 0 : ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
273 : {
274 0 : uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) );
275 : // #FIXME needs a workbook as a parent
276 0 : uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) );
277 0 : if ( aIndex.hasValue() )
278 : {
279 0 : uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
280 0 : return xColl->Item( aIndex, uno::Any() );
281 : }
282 0 : return uno::makeAny( xSheets );
283 : }
284 :
285 : void SAL_CALL
286 0 : ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ ) throw (uno::RuntimeException)
287 : {
288 : // #TODO #FIXME need some implementation to scroll through the tabs
289 : // but where is this done?
290 : /*
291 : sal_Int32 nSheets = 0;
292 : sal_Int32 nPosition = 0;
293 : throw uno::RuntimeException("No Implemented", uno::Reference< uno::XInterface >() );
294 : sal_Bool bSheets = ( Sheets >>= nSheets );
295 : sal_Bool bPosition = ( Position >>= nPosition );
296 : if ( bSheets || bPosition ) // at least one param specified
297 : if ( bSheets )
298 : ;// use sheets
299 : else if ( bPosition )
300 : ; //use position
301 : */
302 :
303 0 : }
304 :
305 : uno::Any SAL_CALL
306 28 : ScVbaWindow::getCaption() throw (uno::RuntimeException)
307 : {
308 28 : static OUString sCrud(" - OpenOffice.org Calc" );
309 28 : static sal_Int32 nCrudLen = sCrud.getLength();
310 :
311 28 : OUString sTitle;
312 28 : getFrameProps()->getPropertyValue( OUString( SC_UNONAME_TITLE ) ) >>= sTitle;
313 28 : sal_Int32 nCrudIndex = sTitle.indexOf( sCrud );
314 : // adjust title ( by removing crud )
315 : // sCrud string present
316 28 : if ( nCrudIndex != -1 )
317 : {
318 : // and ends with sCrud
319 0 : if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() )
320 : {
321 0 : sTitle = sTitle.copy( 0, nCrudIndex );
322 0 : ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
323 0 : OUString sName = workbook.getName();
324 : // rather bizare hack to make sure the name behavior
325 : // is like XL
326 : // if the adjusted title == workbook name, use name
327 : // if the adjusted title != workbook name but ...
328 : // name == title + extension ( .csv, ,odt, .xls )
329 : // etc. then also use the name
330 :
331 0 : if ( !sTitle.equals( sName ) )
332 : {
333 0 : static OUString sDot(".");
334 : // starts with title
335 0 : if ( sName.indexOf( sTitle ) == 0 )
336 : // extention starts immediately after
337 0 : if ( sName.match( sDot, sTitle.getLength() ) )
338 0 : sTitle = sName;
339 0 : }
340 : }
341 : }
342 28 : return uno::makeAny( sTitle );
343 : }
344 :
345 : void SAL_CALL
346 1 : ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException)
347 : {
348 1 : getFrameProps()->setPropertyValue( OUString( SC_UNONAME_TITLE ), _caption );
349 1 : }
350 :
351 : uno::Any SAL_CALL
352 8 : ScVbaWindow::getScrollRow() throw (uno::RuntimeException)
353 : {
354 8 : sal_Int32 nValue = 0;
355 : // !! TODO !! get view shell from controller
356 8 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
357 8 : if ( pViewShell )
358 : {
359 8 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
360 8 : nValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich));
361 : }
362 :
363 8 : return uno::makeAny( nValue + 1);
364 : }
365 :
366 : void SAL_CALL
367 3 : ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException)
368 : {
369 : // !! TODO !! get view shell from controller
370 3 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
371 3 : if ( pViewShell )
372 : {
373 3 : sal_Int32 scrollRow = 0;
374 3 : _scrollrow >>= scrollRow;
375 3 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
376 3 : sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)) + 1;
377 3 : pViewShell->ScrollLines(0, scrollRow - nOldValue);
378 : }
379 3 : }
380 :
381 : uno::Any SAL_CALL
382 10 : ScVbaWindow::getScrollColumn() throw (uno::RuntimeException)
383 : {
384 10 : sal_Int32 nValue = 0;
385 : // !! TODO !! get view shell from controller
386 10 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
387 10 : if ( pViewShell )
388 : {
389 10 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
390 10 : nValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich));
391 : }
392 :
393 10 : return uno::makeAny( nValue + 1);
394 : }
395 :
396 : void SAL_CALL
397 3 : ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException)
398 : {
399 : // !! TODO !! get view shell from controller
400 3 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
401 3 : if ( pViewShell )
402 : {
403 3 : sal_Int32 scrollColumn = 0;
404 3 : _scrollcolumn >>= scrollColumn;
405 3 : ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart();
406 3 : sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)) + 1;
407 3 : pViewShell->ScrollLines(scrollColumn - nOldValue, 0);
408 : }
409 3 : }
410 :
411 : uno::Any SAL_CALL
412 0 : ScVbaWindow::getWindowState() throw (uno::RuntimeException)
413 : {
414 0 : sal_Int32 nwindowState = xlNormal;
415 : // !! TODO !! get view shell from controller
416 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
417 0 : SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
418 0 : WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow();
419 0 : if ( pWork )
420 : {
421 0 : if ( pWork -> IsMaximized())
422 0 : nwindowState = xlMaximized;
423 0 : else if (pWork -> IsMinimized())
424 0 : nwindowState = xlMinimized;
425 : }
426 0 : return uno::makeAny( nwindowState );
427 : }
428 :
429 : void SAL_CALL
430 0 : ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException)
431 : {
432 0 : sal_Int32 nwindowState = xlMaximized;
433 0 : _windowstate >>= nwindowState;
434 : // !! TODO !! get view shell from controller
435 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
436 0 : SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
437 0 : WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow();
438 0 : if ( pWork )
439 : {
440 0 : if ( nwindowState == xlMaximized)
441 0 : pWork -> Maximize();
442 0 : else if (nwindowState == xlMinimized)
443 0 : pWork -> Minimize();
444 0 : else if (nwindowState == xlNormal)
445 0 : pWork -> Restore();
446 : else
447 0 : throw uno::RuntimeException("Invalid Parameter", uno::Reference< uno::XInterface >() );
448 : }
449 0 : }
450 :
451 : void
452 1 : ScVbaWindow::Activate() throw (css::uno::RuntimeException)
453 : {
454 1 : ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
455 :
456 1 : workbook.Activate();
457 1 : }
458 :
459 : void
460 0 : ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook ) throw (uno::RuntimeException)
461 : {
462 0 : ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel );
463 0 : workbook.Close(SaveChanges, FileName, RouteWorkBook );
464 0 : }
465 :
466 : uno::Reference< excel::XPane > SAL_CALL
467 60 : ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException)
468 : {
469 60 : uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
470 60 : return new ScVbaPane( this, mxContext, m_xModel, xViewPane );
471 : }
472 :
473 : uno::Reference< excel::XRange > SAL_CALL
474 6 : ScVbaWindow::ActiveCell( ) throw (script::BasicErrorException, uno::RuntimeException)
475 : {
476 6 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
477 6 : return xApplication->getActiveCell();
478 : }
479 :
480 : uno::Any SAL_CALL
481 3 : ScVbaWindow::Selection( ) throw (script::BasicErrorException, uno::RuntimeException)
482 : {
483 3 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
484 3 : return xApplication->getSelection();
485 : }
486 :
487 : uno::Reference< excel::XRange > SAL_CALL
488 0 : ScVbaWindow::RangeSelection() throw (script::BasicErrorException, uno::RuntimeException)
489 : {
490 : /* TODO / FIXME: According to documentation, this method returns the range
491 : selection even if shapes are selected. */
492 0 : return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW );
493 : }
494 :
495 : ::sal_Bool SAL_CALL
496 2 : ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException)
497 : {
498 2 : OUString sName( SC_UNO_SHOWGRID );
499 2 : sal_Bool bGrid = sal_True;
500 2 : getControllerProps()->getPropertyValue( sName ) >>= bGrid;
501 2 : return bGrid;
502 : }
503 :
504 :
505 : void SAL_CALL
506 2 : ScVbaWindow::setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (uno::RuntimeException)
507 : {
508 2 : OUString sName( SC_UNO_SHOWGRID );
509 2 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _displaygridlines ));
510 2 : }
511 :
512 : ::sal_Bool SAL_CALL
513 6 : ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException)
514 : {
515 6 : OUString sName( SC_UNO_COLROWHDR );
516 6 : sal_Bool bHeading = sal_True;
517 6 : getControllerProps()->getPropertyValue( sName ) >>= bHeading;
518 6 : return bHeading;
519 : }
520 :
521 : void SAL_CALL
522 4 : ScVbaWindow::setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException)
523 : {
524 4 : OUString sName( SC_UNO_COLROWHDR );
525 4 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings ));
526 4 : }
527 :
528 : ::sal_Bool SAL_CALL
529 4 : ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException)
530 : {
531 4 : OUString sName( SC_UNO_HORSCROLL );
532 4 : sal_Bool bHorizontalScrollBar = sal_True;
533 4 : getControllerProps()->getPropertyValue( sName ) >>= bHorizontalScrollBar;
534 4 : return bHorizontalScrollBar;
535 : }
536 :
537 : void SAL_CALL
538 2 : ScVbaWindow::setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException)
539 : {
540 2 : OUString sName( SC_UNO_HORSCROLL );
541 2 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar ));
542 2 : }
543 :
544 : ::sal_Bool SAL_CALL
545 4 : ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException)
546 : {
547 4 : OUString sName( SC_UNO_OUTLSYMB );
548 4 : sal_Bool bOutline = sal_True;
549 4 : getControllerProps()->getPropertyValue( sName ) >>= bOutline;
550 4 : return bOutline;
551 : }
552 :
553 : void SAL_CALL
554 2 : ScVbaWindow::setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (uno::RuntimeException)
555 : {
556 2 : OUString sName( SC_UNO_OUTLSYMB );
557 2 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayOutline ));
558 2 : }
559 :
560 : ::sal_Bool SAL_CALL
561 4 : ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException)
562 : {
563 4 : OUString sName( SC_UNO_VERTSCROLL );
564 4 : sal_Bool bVerticalScrollBar = sal_True;
565 4 : getControllerProps()->getPropertyValue( sName ) >>= bVerticalScrollBar;
566 4 : return bVerticalScrollBar;
567 : }
568 :
569 : void SAL_CALL
570 2 : ScVbaWindow::setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException)
571 : {
572 2 : OUString sName( SC_UNO_VERTSCROLL );
573 2 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar ));
574 2 : }
575 :
576 : ::sal_Bool SAL_CALL
577 4 : ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException)
578 : {
579 4 : OUString sName( SC_UNO_SHEETTABS );
580 4 : sal_Bool bWorkbookTabs = sal_True;
581 4 : getControllerProps()->getPropertyValue( sName ) >>= bWorkbookTabs;
582 4 : return bWorkbookTabs;
583 : }
584 :
585 : void SAL_CALL
586 2 : ScVbaWindow::setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException)
587 : {
588 2 : OUString sName( SC_UNO_SHEETTABS );
589 2 : getControllerProps()->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs ));
590 2 : }
591 :
592 : ::sal_Bool SAL_CALL
593 3 : ScVbaWindow::getFreezePanes() throw (uno::RuntimeException)
594 : {
595 3 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
596 3 : return xViewFreezable->hasFrozenPanes();
597 : }
598 :
599 : void SAL_CALL
600 4 : ScVbaWindow::setFreezePanes( ::sal_Bool _bFreezePanes ) throw (uno::RuntimeException)
601 : {
602 4 : uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
603 8 : uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW );
604 8 : uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW );
605 4 : if( _bFreezePanes )
606 : {
607 2 : if( xViewSplitable->getIsWindowSplit() )
608 : {
609 : // if there is a split we freeze at the split
610 1 : sal_Int32 nColumn = getSplitColumn();
611 1 : sal_Int32 nRow = getSplitRow();
612 1 : xViewFreezable->freezeAtPosition( nColumn, nRow );
613 : }
614 : else
615 : {
616 : // otherwise we freeze in the center of the visible sheet
617 1 : table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange();
618 1 : sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
619 1 : sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
620 1 : xViewFreezable->freezeAtPosition( nColumn, nRow );
621 : }
622 : }
623 : else
624 : {
625 : //remove the freeze panes
626 2 : xViewSplitable->splitAtPosition(0,0);
627 4 : }
628 4 : }
629 :
630 : ::sal_Bool SAL_CALL
631 0 : ScVbaWindow::getSplit() throw (uno::RuntimeException)
632 : {
633 0 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
634 0 : return xViewSplitable->getIsWindowSplit();
635 : }
636 :
637 : void SAL_CALL
638 3 : ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException)
639 : {
640 3 : if( !_bSplit )
641 : {
642 2 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
643 2 : xViewSplitable->splitAtPosition(0,0);
644 : }
645 : else
646 : {
647 1 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
648 2 : uno::Reference< excel::XRange > xRange = ActiveCell();
649 1 : sal_Int32 nRow = xRange->getRow();
650 1 : sal_Int32 nColumn = xRange->getColumn();
651 2 : SplitAtDefinedPosition( nColumn-1, nRow-1 );
652 : }
653 3 : }
654 :
655 : sal_Int32 SAL_CALL
656 6 : ScVbaWindow::getSplitColumn() throw (uno::RuntimeException)
657 : {
658 6 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
659 6 : return xViewSplitable->getSplitColumn();
660 : }
661 :
662 : void SAL_CALL
663 1 : ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeException)
664 : {
665 1 : if( getSplitColumn() != _splitcolumn )
666 : {
667 1 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
668 1 : sal_Int32 nRow = getSplitRow();
669 1 : SplitAtDefinedPosition( _splitcolumn, nRow );
670 : }
671 1 : }
672 :
673 : double SAL_CALL
674 2 : ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException)
675 : {
676 2 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
677 2 : return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), sal_True );
678 : }
679 :
680 : void SAL_CALL
681 1 : ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException)
682 : {
683 1 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
684 1 : double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, sal_True );
685 1 : xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 );
686 1 : }
687 :
688 : sal_Int32 SAL_CALL
689 6 : ScVbaWindow::getSplitRow() throw (uno::RuntimeException)
690 : {
691 6 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
692 6 : return xViewSplitable->getSplitRow();
693 : }
694 :
695 : void SAL_CALL
696 2 : ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException)
697 : {
698 2 : if( getSplitRow() != _splitrow )
699 : {
700 2 : uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
701 2 : sal_Int32 nColumn = getSplitColumn();
702 2 : SplitAtDefinedPosition( nColumn, _splitrow );
703 : }
704 2 : }
705 :
706 : double SAL_CALL
707 2 : ScVbaWindow::getSplitVertical() throw (uno::RuntimeException)
708 : {
709 2 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
710 2 : return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), sal_False );
711 : }
712 :
713 : void SAL_CALL
714 1 : ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException)
715 : {
716 1 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
717 1 : double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, sal_False );
718 1 : xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
719 1 : }
720 :
721 4 : void ScVbaWindow::SplitAtDefinedPosition( sal_Int32 nColumns, sal_Int32 nRows )
722 : {
723 4 : uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
724 8 : uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
725 : // nColumns and nRows means split columns/rows
726 4 : if( nColumns == 0 && nRows == 0 )
727 4 : return;
728 :
729 4 : sal_Int32 cellColumn = nColumns + 1;
730 4 : sal_Int32 cellRow = nRows + 1;
731 :
732 4 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
733 4 : if ( pViewShell )
734 : {
735 : //firstly remove the old splitter
736 4 : xViewSplitable->splitAtPosition(0,0);
737 :
738 4 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
739 8 : uno::Reference< excel::XWorksheet > xSheet( xApplication->getActiveSheet(), uno::UNO_QUERY_THROW );
740 4 : xSheet->Cells(uno::makeAny(cellRow), uno::makeAny(cellColumn))->Select();
741 :
742 : //pViewShell->FreezeSplitters( FALSE );
743 8 : dispatchExecute( pViewShell, SID_WINDOW_SPLIT );
744 4 : }
745 : }
746 :
747 : uno::Any SAL_CALL
748 6 : ScVbaWindow::getZoom() throw (uno::RuntimeException)
749 : {
750 6 : uno::Reference< beans::XPropertySet > xProps = getControllerProps();
751 12 : OUString sName( SC_UNO_ZOOMTYPE );
752 6 : sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
753 6 : xProps->getPropertyValue( sName ) >>= nZoomType;
754 6 : if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
755 : {
756 0 : return uno::makeAny( sal_True );
757 : }
758 6 : else if( nZoomType == view::DocumentZoomType::BY_VALUE )
759 : {
760 6 : sName = OUString( SC_UNO_ZOOMVALUE);
761 6 : sal_Int16 nZoom = 100;
762 6 : xProps->getPropertyValue( sName ) >>= nZoom;
763 6 : return uno::makeAny( nZoom );
764 : }
765 6 : return uno::Any();
766 : }
767 :
768 : void SAL_CALL
769 2 : ScVbaWindow::setZoom( const uno::Any& _zoom ) throw (uno::RuntimeException)
770 : {
771 2 : sal_Int16 nZoom = 100;
772 2 : _zoom >>= nZoom;
773 2 : uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
774 4 : uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
775 2 : SCTAB nTab = 0;
776 2 : if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) )
777 0 : throw uno::RuntimeException();
778 4 : std::vector< SCTAB > vTabs;
779 2 : vTabs.push_back( nTab );
780 4 : excel::implSetZoom( m_xModel, nZoom, vTabs );
781 2 : }
782 :
783 : uno::Reference< excel::XWorksheet > SAL_CALL
784 4 : ScVbaWindow::ActiveSheet( ) throw (script::BasicErrorException, uno::RuntimeException)
785 : {
786 4 : uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
787 4 : return xApplication->getActiveSheet();
788 : }
789 :
790 : uno::Any SAL_CALL
791 2 : ScVbaWindow::getView() throw (uno::RuntimeException)
792 : {
793 2 : sal_Bool bPageBreak = sal_False;
794 2 : sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
795 :
796 2 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
797 2 : if (pViewShell)
798 2 : bPageBreak = pViewShell->GetViewData()->IsPagebreakMode();
799 :
800 2 : if( bPageBreak )
801 1 : nWindowView = excel::XlWindowView::xlPageBreakPreview;
802 : else
803 1 : nWindowView = excel::XlWindowView::xlNormalView;
804 :
805 2 : return uno::makeAny( nWindowView );
806 : }
807 :
808 : void SAL_CALL
809 2 : ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException)
810 : {
811 2 : sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
812 2 : _view >>= nWindowView;
813 2 : sal_uInt16 nSlot = FID_NORMALVIEWMODE;
814 2 : switch ( nWindowView )
815 : {
816 : case excel::XlWindowView::xlNormalView:
817 1 : nSlot = FID_NORMALVIEWMODE;
818 1 : break;
819 : case excel::XlWindowView::xlPageBreakPreview:
820 1 : nSlot = FID_PAGEBREAKMODE;
821 1 : break;
822 : default:
823 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, OUString() );
824 : }
825 : // !! TODO !! get view shell from controller
826 2 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
827 2 : if ( pViewShell )
828 2 : dispatchExecute( pViewShell, nSlot );
829 2 : }
830 :
831 : uno::Reference< excel::XRange > SAL_CALL
832 0 : ScVbaWindow::getVisibleRange() throw (uno::RuntimeException)
833 : {
834 0 : uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW );
835 0 : uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW );
836 0 : uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) );
837 0 : return xPane->getVisibleRange();
838 : }
839 :
840 : sal_Int32 SAL_CALL
841 0 : ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException)
842 : {
843 0 : sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
844 0 : double fConvertFactor = (getDevice()->getInfo().PixelPerMeterX/100000);
845 0 : return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
846 : }
847 :
848 : sal_Int32 SAL_CALL
849 0 : ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException)
850 : {
851 0 : sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
852 0 : double fConvertFactor = (getDevice()->getInfo().PixelPerMeterY/100000);
853 0 : return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
854 : }
855 :
856 : void SAL_CALL
857 0 : ScVbaWindow::PrintOut( const css::uno::Any& From, const css::uno::Any&To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
858 : {
859 : // need test, print current active sheet
860 : // !! TODO !! get view shell from controller
861 0 : PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True );
862 0 : }
863 :
864 : void SAL_CALL
865 0 : ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
866 : {
867 : // need test, print preview current active sheet
868 : // !! TODO !! get view shell from controller
869 0 : PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) );
870 0 : }
871 :
872 0 : double SAL_CALL ScVbaWindow::getTabRatio() throw (css::uno::RuntimeException)
873 : {
874 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
875 0 : if ( pViewShell && pViewShell->GetViewData() && pViewShell->GetViewData()->GetView() )
876 : {
877 0 : double fRatio = pViewShell->GetViewData()->GetView()->GetRelTabBarWidth();
878 0 : if ( fRatio >= 0.0 && fRatio <= 1.0 )
879 0 : return fRatio;
880 : }
881 0 : return 0.0;
882 : }
883 :
884 0 : void SAL_CALL ScVbaWindow::setTabRatio( double fRatio ) throw (css::uno::RuntimeException)
885 : {
886 0 : ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
887 0 : if ( pViewShell && pViewShell->GetViewData() && pViewShell->GetViewData()->GetView() )
888 : {
889 0 : if ( fRatio >= 0.0 && fRatio <= 1.0 )
890 0 : pViewShell->GetViewData()->GetView()->SetRelTabBarWidth( fRatio );
891 : }
892 0 : }
893 :
894 : OUString
895 0 : ScVbaWindow::getServiceImplName()
896 : {
897 0 : return OUString("ScVbaWindow");
898 : }
899 :
900 : uno::Sequence< OUString >
901 0 : ScVbaWindow::getServiceNames()
902 : {
903 0 : static uno::Sequence< OUString > aServiceNames;
904 0 : if ( aServiceNames.getLength() == 0 )
905 : {
906 0 : aServiceNames.realloc( 1 );
907 0 : aServiceNames[ 0 ] = OUString("ooo.vba.excel.Window" );
908 : }
909 0 : return aServiceNames;
910 : }
911 : namespace window
912 : {
913 : namespace sdecl = comphelper::service_decl;
914 2 : sdecl::vba_service_class_<ScVbaWindow, sdecl::with_args<true> > serviceImpl;
915 2 : extern sdecl::ServiceDecl const serviceDecl(
916 : serviceImpl,
917 : "ScVbaWindow",
918 : "ooo.vba.excel.Window" );
919 6 : }
920 :
921 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|