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