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, const Sheets& sheets, const uno::Reference< frame::XModel >& xModel ) : m_xContext( xContext ), m_sheets( sheets ), m_xModel( xModel )
76  {
77  m_it = m_sheets.begin();
78  }
79  // XEnumeration
80  virtual sal_Bool SAL_CALL hasMoreElements( ) override
81  {
82  return m_it != m_sheets.end();
83  }
84  virtual uno::Any SAL_CALL nextElement( ) override
85  {
86  if ( !hasMoreElements() )
87  {
88  throw container::NoSuchElementException();
89  }
90  // #FIXME needs ThisWorkbook as parent
91  return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) );
92  }
93 
94 };
95 
96 class SelectedSheetsEnumAccess : public SelectedSheets_BASE
97 {
98  uno::Reference< uno::XComponentContext > m_xContext;
99  NameIndexHash namesToIndices;
100  Sheets sheets;
101  uno::Reference< frame::XModel > m_xModel;
102 public:
103  SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel )
104  {
105  ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() );
106  if ( !pModel )
107  throw uno::RuntimeException("Cannot obtain current document" );
108  ScDocShell* pDocShell = static_cast<ScDocShell*>(pModel->GetEmbeddedObject());
109  if ( !pDocShell )
110  throw uno::RuntimeException("Cannot obtain docshell" );
111  ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel );
112  if ( !pViewShell )
113  throw uno::RuntimeException("Cannot obtain view shell" );
114 
115  SCTAB nTabCount = pDocShell->GetDocument().GetTableCount();
116  SCTAB nIndex = 0;
117  const ScMarkData& rMarkData = pViewShell->GetViewData().GetMarkData();
118  sheets.reserve( nTabCount );
119  uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW );
120  uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW );
121  for (const auto& rTab : rMarkData)
122  {
123  if (rTab >= nTabCount)
124  break;
125  uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( rTab ), uno::UNO_QUERY_THROW );
126  uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
127  sheets.push_back( xSheet );
128  namesToIndices[ xNamed->getName() ] = nIndex++;
129  }
130 
131  }
132 
133  //XEnumerationAccess
134  virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) override
135  {
136  return new SelectedSheetsEnum( m_xContext, sheets, m_xModel );
137  }
138  // XIndexAccess
139  virtual ::sal_Int32 SAL_CALL getCount( ) override
140  {
141  return sheets.size();
142  }
143  virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
144  {
145  if ( Index < 0
146  || o3tl::make_unsigned( Index ) >= sheets.size() )
147  throw lang::IndexOutOfBoundsException();
148 
149  return uno::makeAny( sheets[ Index ] );
150  }
151 
152  //XElementAccess
153  virtual uno::Type SAL_CALL getElementType( ) override
154  {
156  }
157 
158  virtual sal_Bool SAL_CALL hasElements( ) override
159  {
160  return ( !sheets.empty() );
161  }
162 
163  //XNameAccess
164  virtual uno::Any SAL_CALL getByName( const OUString& aName ) override
165  {
166  NameIndexHash::const_iterator it = namesToIndices.find( aName );
167  if ( it == namesToIndices.end() )
168  throw container::NoSuchElementException();
169  return uno::makeAny( sheets[ it->second ] );
170 
171  }
172 
173  virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) override
174  {
175  return comphelper::mapKeysToSequence( namesToIndices );
176  }
177 
178  virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override
179  {
180  NameIndexHash::const_iterator it = namesToIndices.find( aName );
181  return (it != namesToIndices.end());
182  }
183 
184 };
185 
186 }
187 
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 ) :
193  WindowImpl_BASE( xParent, xContext, xModel, xController )
194 {
195  init();
196 }
197 
199  const uno::Sequence< uno::Any >& args,
200  const uno::Reference< uno::XComponentContext >& xContext ) :
201  WindowImpl_BASE( args, xContext )
202 {
203  init();
204 }
205 
206 void
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  destructed immediately! Guard the call to ActivePane() in try/catch to
214  not miss the decrementation of the reference count on exception. */
215  osl_atomic_increment( &m_refCount );
216  try
217  {
218  m_xPane = ActivePane();
219  }
220  catch( uno::Exception& )
221  {
222  }
223  osl_atomic_decrement( &m_refCount );
224 }
225 
226 uno::Reference< beans::XPropertySet >
228 {
229  return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW );
230 }
231 
232 uno::Reference< beans::XPropertySet >
234 {
235  return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW );
236 }
237 
238 uno::Reference< awt::XDevice >
240 {
241  return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW );
242 }
243 
244 void
245 ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll )
246 {
247  if( !m_xPane.is() )
248  throw uno::RuntimeException();
249  if( bLargeScroll )
250  m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
251  else
252  m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
253 }
254 
255 void SAL_CALL
256 ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
257 {
258  Scroll( Down, Up, ToRight, ToLeft, false );
259 }
260 
261 void SAL_CALL
262 ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
263 {
264  Scroll( Down, Up, ToRight, ToLeft, true );
265 }
266 
267 uno::Any SAL_CALL
269 {
270  uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) );
271  // #FIXME needs a workbook as a parent
272  uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) );
273  if ( aIndex.hasValue() )
274  {
275  uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
276  return xColl->Item( aIndex, uno::Any() );
277  }
278  return uno::makeAny( xSheets );
279 }
280 
281 void SAL_CALL
282 ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ )
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 }
300 
301 uno::Any SAL_CALL
303 {
304  // tdf#118129 - return only the caption property of the frame
305  OUString sTitle;
306  getFrameProps()->getPropertyValue(SC_UNONAME_TITLE) >>= sTitle;
307  return uno::makeAny( sTitle );
308 }
309 
310 void SAL_CALL
312 {
313  getFrameProps()->setPropertyValue( SC_UNONAME_TITLE, _caption );
314 }
315 
316 uno::Any SAL_CALL
318 {
319  sal_Int32 nValue = 0;
320  // !! TODO !! get view shell from controller
322  if ( pViewShell )
323  {
324  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
325  nValue = pViewShell->GetViewData().GetPosY(WhichV(eWhich));
326  }
327 
328  return uno::makeAny( nValue + 1);
329 }
330 
331 void SAL_CALL
333 {
334  // !! TODO !! get view shell from controller
336  if ( pViewShell )
337  {
338  sal_Int32 scrollRow = 0;
339  _scrollrow >>= scrollRow;
340  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
341  sal_Int32 nOldValue = pViewShell->GetViewData().GetPosY(WhichV(eWhich)) + 1;
342  pViewShell->ScrollLines(0, scrollRow - nOldValue);
343  }
344 }
345 
346 uno::Any SAL_CALL
348 {
349  sal_Int32 nValue = 0;
350  // !! TODO !! get view shell from controller
352  if ( pViewShell )
353  {
354  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
355  nValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich));
356  }
357 
358  return uno::makeAny( nValue + 1);
359 }
360 
361 void SAL_CALL
362 ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn )
363 {
364  // !! TODO !! get view shell from controller
366  if ( pViewShell )
367  {
368  sal_Int32 scrollColumn = 0;
369  _scrollcolumn >>= scrollColumn;
370  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
371  sal_Int32 nOldValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich)) + 1;
372  pViewShell->ScrollLines(scrollColumn - nOldValue, 0);
373  }
374 }
375 
376 uno::Any SAL_CALL
378 {
379  sal_Int32 nwindowState = xlNormal;
380  // !! TODO !! get view shell from controller
382  SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
383  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
384  if ( pWork )
385  {
386  if ( pWork -> IsMaximized())
387  nwindowState = xlMaximized;
388  else if (pWork -> IsMinimized())
389  nwindowState = xlMinimized;
390  }
391  return uno::makeAny( nwindowState );
392 }
393 
394 void SAL_CALL
395 ScVbaWindow::setWindowState( const uno::Any& _windowstate )
396 {
397  sal_Int32 nwindowState = xlMaximized;
398  _windowstate >>= nwindowState;
399  // !! TODO !! get view shell from controller
401  SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
402  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
403  if ( pWork )
404  {
405  if ( nwindowState == xlMaximized)
406  pWork -> Maximize();
407  else if (nwindowState == xlMinimized)
408  pWork -> Minimize();
409  else if (nwindowState == xlNormal)
410  pWork -> Restore();
411  else
412  throw uno::RuntimeException("Invalid Parameter" );
413  }
414 }
415 
416 void
418 {
419  rtl::Reference<ScVbaWorkbook> workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
420 
421  workbook->Activate();
422 }
423 
424 void
425 ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook )
426 {
427  rtl::Reference< ScVbaWorkbook > workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
428  workbook->Close(SaveChanges, FileName, RouteWorkBook );
429 }
430 
431 uno::Reference< excel::XPane > SAL_CALL
433 {
434  uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
435  return new ScVbaPane( this, mxContext, m_xModel, xViewPane );
436 }
437 
438 uno::Reference< excel::XRange > SAL_CALL
440 {
441  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
442  return xApplication->getActiveCell();
443 }
444 
445 uno::Any SAL_CALL
447 {
448  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
449  return xApplication->getSelection();
450 }
451 
452 uno::Reference< excel::XRange > SAL_CALL
454 {
455  /* TODO / FIXME: According to documentation, this method returns the range
456  selection even if shapes are selected. */
457  return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW );
458 }
459 
460 sal_Bool SAL_CALL
462 {
463  bool bGrid = true;
464  getControllerProps()->getPropertyValue( SC_UNO_SHOWGRID ) >>= bGrid;
465  return bGrid;
466 }
467 
468 void SAL_CALL
470 {
471  getControllerProps()->setPropertyValue( SC_UNO_SHOWGRID, uno::makeAny( _displaygridlines ));
472 }
473 
474 sal_Bool SAL_CALL
476 {
477  bool bHeading = true;
478  getControllerProps()->getPropertyValue( SC_UNO_COLROWHDR ) >>= bHeading;
479  return bHeading;
480 }
481 
482 void SAL_CALL
484 {
485  getControllerProps()->setPropertyValue( SC_UNO_COLROWHDR, uno::makeAny( _bDisplayHeadings ));
486 }
487 
488 sal_Bool SAL_CALL
490 {
491  bool bHorizontalScrollBar = true;
492  getControllerProps()->getPropertyValue( SC_UNO_HORSCROLL ) >>= bHorizontalScrollBar;
493  return bHorizontalScrollBar;
494 }
495 
496 void SAL_CALL
498 {
499  getControllerProps()->setPropertyValue( SC_UNO_HORSCROLL, uno::makeAny( _bDisplayHorizontalScrollBar ));
500 }
501 
502 sal_Bool SAL_CALL
504 {
505  bool bOutline = true;
506  getControllerProps()->getPropertyValue( SC_UNO_OUTLSYMB ) >>= bOutline;
507  return bOutline;
508 }
509 
510 void SAL_CALL
512 {
513  getControllerProps()->setPropertyValue( SC_UNO_OUTLSYMB, uno::makeAny( _bDisplayOutline ));
514 }
515 
516 sal_Bool SAL_CALL
518 {
519  bool bVerticalScrollBar = true;
520  getControllerProps()->getPropertyValue( SC_UNO_VERTSCROLL ) >>= bVerticalScrollBar;
521  return bVerticalScrollBar;
522 }
523 
524 void SAL_CALL
526 {
527  getControllerProps()->setPropertyValue( SC_UNO_VERTSCROLL, uno::makeAny( _bDisplayVerticalScrollBar ));
528 }
529 
530 sal_Bool SAL_CALL
532 {
533  bool bWorkbookTabs = true;
534  getControllerProps()->getPropertyValue( SC_UNO_SHEETTABS ) >>= bWorkbookTabs;
535  return bWorkbookTabs;
536 }
537 
538 void SAL_CALL
540 {
541  getControllerProps()->setPropertyValue( SC_UNO_SHEETTABS, uno::makeAny( _bDisplayWorkbookTabs ));
542 }
543 
544 sal_Bool SAL_CALL
546 {
547  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
548  return xViewFreezable->hasFrozenPanes();
549 }
550 
551 void SAL_CALL
553 {
554  uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
555  uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW );
556  uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW );
557  if( _bFreezePanes )
558  {
559  if( xViewSplitable->getIsWindowSplit() )
560  {
561  // if there is a split we freeze at the split
562  sal_Int32 nColumn = getSplitColumn();
563  sal_Int32 nRow = getSplitRow();
564  xViewFreezable->freezeAtPosition( nColumn, nRow );
565  }
566  else
567  {
568  // otherwise we freeze in the center of the visible sheet
569  table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange();
570  sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
571  sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
572  xViewFreezable->freezeAtPosition( nColumn, nRow );
573  }
574  }
575  else
576  {
577  //remove the freeze panes
578  xViewSplitable->splitAtPosition(0,0);
579  }
580 }
581 
582 sal_Bool SAL_CALL
584 {
585  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
586  return xViewSplitable->getIsWindowSplit();
587 }
588 
589 void SAL_CALL
591 {
592  if( !_bSplit )
593  {
594  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
595  xViewSplitable->splitAtPosition(0,0);
596  }
597  else
598  {
599  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
600  uno::Reference< excel::XRange > xRange = ActiveCell();
601  sal_Int32 nRow = xRange->getRow();
602  sal_Int32 nColumn = xRange->getColumn();
603  SplitAtDefinedPosition( nColumn-1, nRow-1 );
604  }
605 }
606 
607 sal_Int32 SAL_CALL
609 {
610  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
611  return xViewSplitable->getSplitColumn();
612 }
613 
614 void SAL_CALL
615 ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn )
616 {
617  if( getSplitColumn() != _splitcolumn )
618  {
619  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
620  sal_Int32 nRow = getSplitRow();
621  SplitAtDefinedPosition( _splitcolumn, nRow );
622  }
623 }
624 
625 double SAL_CALL
627 {
628  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
629  return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), true );
630 }
631 
632 void SAL_CALL
633 ScVbaWindow::setSplitHorizontal( double _splithorizontal )
634 {
635  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
636  double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, true );
637  xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 );
638 }
639 
640 sal_Int32 SAL_CALL
642 {
643  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
644  return xViewSplitable->getSplitRow();
645 }
646 
647 void SAL_CALL
648 ScVbaWindow::setSplitRow( sal_Int32 _splitrow )
649 {
650  if( getSplitRow() != _splitrow )
651  {
652  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
653  sal_Int32 nColumn = getSplitColumn();
654  SplitAtDefinedPosition( nColumn, _splitrow );
655  }
656 }
657 
658 double SAL_CALL
660 {
661  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
662  return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), false );
663 }
664 
665 void SAL_CALL
666 ScVbaWindow::setSplitVertical(double _splitvertical )
667 {
668  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
669  double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, false );
670  xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
671 }
672 
673 void ScVbaWindow::SplitAtDefinedPosition( sal_Int32 nColumns, sal_Int32 nRows )
674 {
675  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
676  uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
677  // nColumns and nRows means split columns/rows
678  if( nColumns == 0 && nRows == 0 )
679  return;
680 
681  sal_Int32 cellColumn = nColumns + 1;
682  sal_Int32 cellRow = nRows + 1;
683 
685  if ( pViewShell )
686  {
687  //firstly remove the old splitter
688  xViewSplitable->splitAtPosition(0,0);
689 
690  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
691  uno::Reference< excel::XWorksheet > xSheet( xApplication->getActiveSheet(), uno::UNO_SET_THROW );
692  xSheet->Cells(uno::makeAny(cellRow), uno::makeAny(cellColumn))->Select();
693 
694  //pViewShell->FreezeSplitters( FALSE );
695  dispatchExecute( pViewShell, SID_WINDOW_SPLIT );
696  }
697 }
698 
699 uno::Any SAL_CALL
701 {
702  uno::Reference< beans::XPropertySet > xProps = getControllerProps();
703  OUString sName( SC_UNO_ZOOMTYPE );
704  sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
705  xProps->getPropertyValue( sName ) >>= nZoomType;
706  if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
707  {
708  return uno::makeAny( true );
709  }
710  else if( nZoomType == view::DocumentZoomType::BY_VALUE )
711  {
712  sName = SC_UNO_ZOOMVALUE;
713  sal_Int16 nZoom = 100;
714  xProps->getPropertyValue( sName ) >>= nZoom;
715  return uno::makeAny( nZoom );
716  }
717  return uno::Any();
718 }
719 
720 void SAL_CALL ScVbaWindow::setZoom(const uno::Any& _zoom)
721 {
722  sal_Int16 nZoom = 100;
723  _zoom >>= nZoom;
724  uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
725  uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
726  SCTAB nTab = 0;
727  if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) )
728  throw uno::RuntimeException();
729  std::vector< SCTAB > vTabs;
730  vTabs.push_back( 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::makeAny( 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:3108
virtual void SAL_CALL Activate() override
Definition: vbawindow.cxx:417
#define SC_UNO_COLROWHDR
Definition: unonames.hxx:538
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:517
virtual void SAL_CALL setDisplayGridlines(sal_Bool _displaygridlines) override
Definition: vbawindow.cxx:469
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:718
#define SC_UNO_ZOOMVALUE
Definition: unonames.hxx:573
virtual void SAL_CALL setScrollColumn(const css::uno::Any &_scrollcolumn) override
Definition: vbawindow.cxx:362
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:712
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:552
Sequence< OUString > aServiceNames
void init()
Definition: vbawindow.cxx:207
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:397
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1400
virtual void SAL_CALL ScrollWorkbookTabs(const css::uno::Any &Sheets, const css::uno::Any &Position) override
Definition: vbawindow.cxx:282
SC_DLLPUBLIC void ScrollLines(tools::Long nDeltaX, tools::Long nDeltaY)
Definition: tabview.cxx:1318
ScSplitPos
Definition: viewdata.hxx:44
virtual void SAL_CALL setSplit(sal_Bool _bSplit) override
Definition: vbawindow.cxx:590
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:233
#define SC_UNO_SHOWGRID
Definition: unonames.hxx:548
SC_DLLPUBLIC void SetRelTabBarWidth(double fRelTabBarWidth)
Sets a relative tab bar width.
Definition: tabview.cxx:863
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
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:489
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:1414
const char * sName
ScViewData & GetViewData()
Definition: tabview.hxx:333
virtual void SAL_CALL setSplitRow(sal_Int32 _splitrow) override
Definition: vbawindow.cxx:648
virtual sal_Bool SAL_CALL getFreezePanes() override
Definition: vbawindow.cxx:545
virtual css::uno::Any SAL_CALL getScrollRow() override
Definition: vbawindow.cxx:317
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL RangeSelection() override
Definition: vbawindow.cxx:453
::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:256
css::uno::Reference< css::awt::XDevice > getDevice() const
Definition: vbawindow.cxx:239
#define SC_UNONAME_TITLE
Definition: unonames.hxx:641
virtual void SAL_CALL setScrollRow(const css::uno::Any &_scrollrow) override
Definition: vbawindow.cxx:332
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:531
virtual void SAL_CALL setDisplayOutline(sal_Bool _bDisplayOutline) override
Definition: vbawindow.cxx:511
virtual void SAL_CALL setSplitVertical(double _splitvertical) override
Definition: vbawindow.cxx:666
SfxObjectShell * GetEmbeddedObject() const
Definition: docuno.cxx:452
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:439
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:302
virtual sal_Int32 SAL_CALL getSplitColumn() override
Definition: vbawindow.cxx:608
static SC_DLLPUBLIC double GetRelTabBarWidth()
Returns the current tab bar width relative to the frame window width (0.0 ...
Definition: tabview.cxx:881
css::uno::Reference< css::beans::XPropertySet > getControllerProps() const
Definition: vbawindow.cxx:227
virtual void SAL_CALL setDisplayVerticalScrollBar(sal_Bool _bDisplayVerticalScrollBar) override
Definition: vbawindow.cxx:525
#define SC_UNO_ZOOMTYPE
Definition: unonames.hxx:572
virtual void SAL_CALL setDisplayHeadings(sal_Bool _bDisplayHeadings) override
Definition: vbawindow.cxx:483
#define SC_UNO_HORSCROLL
Definition: unonames.hxx:541
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:861
virtual void SAL_CALL setSplitHorizontal(double _splithorizontal) override
Definition: vbawindow.cxx:633
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:475
virtual void SAL_CALL setZoom(const css::uno::Any &_zoom) override
Definition: vbawindow.cxx:720
virtual void SAL_CALL setDisplayWorkbookTabs(sal_Bool _bDisplayWorkbookTabs) override
Definition: vbawindow.cxx:539
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &FileName, const css::uno::Any &RouteWorkBook) override
Definition: vbawindow.cxx:425
#define SC_UNO_SHEETTABS
Definition: unonames.hxx:543
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:311
void SplitAtDefinedPosition(sal_Int32 nColumns, sal_Int32 nRows)
Definition: vbawindow.cxx:673
OUString aName
virtual css::uno::Any SAL_CALL Selection() override
Definition: vbawindow.cxx:446
#define SC_UNO_OUTLSYMB
Definition: unonames.hxx:542
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:377
virtual css::uno::Any SAL_CALL SelectedSheets(const css::uno::Any &aIndex) override
Definition: vbawindow.cxx:268
virtual css::uno::Any SAL_CALL getScrollColumn() override
Definition: vbawindow.cxx:347
cppu::ImplInheritanceHelper< VbaWindowBase, ov::word::XWindow > WindowImpl_BASE
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
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:245
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:497
virtual double SAL_CALL getSplitHorizontal() override
Definition: vbawindow.cxx:626
virtual double SAL_CALL getSplitVertical() override
Definition: vbawindow.cxx:659
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:262
virtual css::uno::Reference< ov::excel::XPane > SAL_CALL ActivePane() override
Definition: vbawindow.cxx:432
virtual sal_Bool SAL_CALL getSplit() override
Definition: vbawindow.cxx:583
virtual sal_Bool SAL_CALL getDisplayOutline() override
Definition: vbawindow.cxx:503
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:555
virtual sal_Int32 SAL_CALL getSplitRow() override
Definition: vbawindow.cxx:641
Reference< XComponentContext > m_xContext
virtual sal_Bool SAL_CALL getDisplayGridlines() override
Definition: vbawindow.cxx:461
SystemWindow * GetSystemWindow() const
virtual css::uno::Any SAL_CALL getZoom() override
Definition: vbawindow.cxx:700
bool IsPagebreakMode() const
Definition: viewdata.hxx:424
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:615
sal_Int16 SCTAB
Definition: types.hxx:22
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
sal_Int16 nValue
virtual void SAL_CALL setWindowState(const css::uno::Any &_windowstate) override
Definition: vbawindow.cxx:395