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