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  static const char sCrud[] = " - OpenOffice.org Calc";
305  static const sal_Int32 nCrudLen = strlen(sCrud);
306 
307  OUString sTitle;
308  getFrameProps()->getPropertyValue( SC_UNONAME_TITLE ) >>= sTitle;
309  sal_Int32 nCrudIndex = sTitle.indexOf( sCrud );
310  // adjust title ( by removing crud )
311  // sCrud string present
312  if ( nCrudIndex != -1 )
313  {
314  // and ends with sCrud
315  if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() )
316  {
317  sTitle = sTitle.copy( 0, nCrudIndex );
318  rtl::Reference< ScVbaWorkbook > workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
319  OUString sName = workbook->getName();
320  // rather bizarre 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  if ( sTitle != sName )
328  {
329  // starts with title
330  if ( sName.startsWith( sTitle ) )
331  // extension starts immediately after
332  if ( sName.match( ".", sTitle.getLength() ) )
333  sTitle = sName;
334  }
335  }
336  }
337  return uno::makeAny( sTitle );
338 }
339 
340 void SAL_CALL
342 {
343  getFrameProps()->setPropertyValue( SC_UNONAME_TITLE, _caption );
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().GetPosY(WhichV(eWhich));
356  }
357 
358  return uno::makeAny( nValue + 1);
359 }
360 
361 void SAL_CALL
363 {
364  // !! TODO !! get view shell from controller
366  if ( pViewShell )
367  {
368  sal_Int32 scrollRow = 0;
369  _scrollrow >>= scrollRow;
370  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
371  sal_Int32 nOldValue = pViewShell->GetViewData().GetPosY(WhichV(eWhich)) + 1;
372  pViewShell->ScrollLines(0, scrollRow - nOldValue);
373  }
374 }
375 
376 uno::Any SAL_CALL
378 {
379  sal_Int32 nValue = 0;
380  // !! TODO !! get view shell from controller
382  if ( pViewShell )
383  {
384  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
385  nValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich));
386  }
387 
388  return uno::makeAny( nValue + 1);
389 }
390 
391 void SAL_CALL
392 ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn )
393 {
394  // !! TODO !! get view shell from controller
396  if ( pViewShell )
397  {
398  sal_Int32 scrollColumn = 0;
399  _scrollcolumn >>= scrollColumn;
400  ScSplitPos eWhich = pViewShell->GetViewData().GetActivePart();
401  sal_Int32 nOldValue = pViewShell->GetViewData().GetPosX(WhichH(eWhich)) + 1;
402  pViewShell->ScrollLines(scrollColumn - nOldValue, 0);
403  }
404 }
405 
406 uno::Any SAL_CALL
408 {
409  sal_Int32 nwindowState = xlNormal;
410  // !! TODO !! get view shell from controller
412  SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
413  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
414  if ( pWork )
415  {
416  if ( pWork -> IsMaximized())
417  nwindowState = xlMaximized;
418  else if (pWork -> IsMinimized())
419  nwindowState = xlMinimized;
420  }
421  return uno::makeAny( nwindowState );
422 }
423 
424 void SAL_CALL
425 ScVbaWindow::setWindowState( const uno::Any& _windowstate )
426 {
427  sal_Int32 nwindowState = xlMaximized;
428  _windowstate >>= nwindowState;
429  // !! TODO !! get view shell from controller
431  SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
432  WorkWindow* pWork = static_cast<WorkWindow*>( pViewFrame->GetFrame().GetSystemWindow() );
433  if ( pWork )
434  {
435  if ( nwindowState == xlMaximized)
436  pWork -> Maximize();
437  else if (nwindowState == xlMinimized)
438  pWork -> Minimize();
439  else if (nwindowState == xlNormal)
440  pWork -> Restore();
441  else
442  throw uno::RuntimeException("Invalid Parameter" );
443  }
444 }
445 
446 void
448 {
449  rtl::Reference<ScVbaWorkbook> workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
450 
451  workbook->Activate();
452 }
453 
454 void
455 ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook )
456 {
457  rtl::Reference< ScVbaWorkbook > workbook( new ScVbaWorkbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ) );
458  workbook->Close(SaveChanges, FileName, RouteWorkBook );
459 }
460 
461 uno::Reference< excel::XPane > SAL_CALL
463 {
464  uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
465  return new ScVbaPane( this, mxContext, m_xModel, xViewPane );
466 }
467 
468 uno::Reference< excel::XRange > SAL_CALL
470 {
471  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
472  return xApplication->getActiveCell();
473 }
474 
475 uno::Any SAL_CALL
477 {
478  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
479  return xApplication->getSelection();
480 }
481 
482 uno::Reference< excel::XRange > SAL_CALL
484 {
485  /* TODO / FIXME: According to documentation, this method returns the range
486  selection even if shapes are selected. */
487  return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW );
488 }
489 
490 sal_Bool SAL_CALL
492 {
493  bool bGrid = true;
494  getControllerProps()->getPropertyValue( SC_UNO_SHOWGRID ) >>= bGrid;
495  return bGrid;
496 }
497 
498 void SAL_CALL
500 {
501  getControllerProps()->setPropertyValue( SC_UNO_SHOWGRID, uno::makeAny( _displaygridlines ));
502 }
503 
504 sal_Bool SAL_CALL
506 {
507  bool bHeading = true;
508  getControllerProps()->getPropertyValue( SC_UNO_COLROWHDR ) >>= bHeading;
509  return bHeading;
510 }
511 
512 void SAL_CALL
514 {
515  getControllerProps()->setPropertyValue( SC_UNO_COLROWHDR, uno::makeAny( _bDisplayHeadings ));
516 }
517 
518 sal_Bool SAL_CALL
520 {
521  bool bHorizontalScrollBar = true;
522  getControllerProps()->getPropertyValue( SC_UNO_HORSCROLL ) >>= bHorizontalScrollBar;
523  return bHorizontalScrollBar;
524 }
525 
526 void SAL_CALL
528 {
529  getControllerProps()->setPropertyValue( SC_UNO_HORSCROLL, uno::makeAny( _bDisplayHorizontalScrollBar ));
530 }
531 
532 sal_Bool SAL_CALL
534 {
535  bool bOutline = true;
536  getControllerProps()->getPropertyValue( SC_UNO_OUTLSYMB ) >>= bOutline;
537  return bOutline;
538 }
539 
540 void SAL_CALL
542 {
543  getControllerProps()->setPropertyValue( SC_UNO_OUTLSYMB, uno::makeAny( _bDisplayOutline ));
544 }
545 
546 sal_Bool SAL_CALL
548 {
549  bool bVerticalScrollBar = true;
550  getControllerProps()->getPropertyValue( SC_UNO_VERTSCROLL ) >>= bVerticalScrollBar;
551  return bVerticalScrollBar;
552 }
553 
554 void SAL_CALL
556 {
557  getControllerProps()->setPropertyValue( SC_UNO_VERTSCROLL, uno::makeAny( _bDisplayVerticalScrollBar ));
558 }
559 
560 sal_Bool SAL_CALL
562 {
563  bool bWorkbookTabs = true;
564  getControllerProps()->getPropertyValue( SC_UNO_SHEETTABS ) >>= bWorkbookTabs;
565  return bWorkbookTabs;
566 }
567 
568 void SAL_CALL
570 {
571  getControllerProps()->setPropertyValue( SC_UNO_SHEETTABS, uno::makeAny( _bDisplayWorkbookTabs ));
572 }
573 
574 sal_Bool SAL_CALL
576 {
577  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
578  return xViewFreezable->hasFrozenPanes();
579 }
580 
581 void SAL_CALL
583 {
584  uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
585  uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW );
586  uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW );
587  if( _bFreezePanes )
588  {
589  if( xViewSplitable->getIsWindowSplit() )
590  {
591  // if there is a split we freeze at the split
592  sal_Int32 nColumn = getSplitColumn();
593  sal_Int32 nRow = getSplitRow();
594  xViewFreezable->freezeAtPosition( nColumn, nRow );
595  }
596  else
597  {
598  // otherwise we freeze in the center of the visible sheet
599  table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange();
600  sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
601  sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
602  xViewFreezable->freezeAtPosition( nColumn, nRow );
603  }
604  }
605  else
606  {
607  //remove the freeze panes
608  xViewSplitable->splitAtPosition(0,0);
609  }
610 }
611 
612 sal_Bool SAL_CALL
614 {
615  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
616  return xViewSplitable->getIsWindowSplit();
617 }
618 
619 void SAL_CALL
621 {
622  if( !_bSplit )
623  {
624  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
625  xViewSplitable->splitAtPosition(0,0);
626  }
627  else
628  {
629  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
630  uno::Reference< excel::XRange > xRange = ActiveCell();
631  sal_Int32 nRow = xRange->getRow();
632  sal_Int32 nColumn = xRange->getColumn();
633  SplitAtDefinedPosition( nColumn-1, nRow-1 );
634  }
635 }
636 
637 sal_Int32 SAL_CALL
639 {
640  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
641  return xViewSplitable->getSplitColumn();
642 }
643 
644 void SAL_CALL
645 ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn )
646 {
647  if( getSplitColumn() != _splitcolumn )
648  {
649  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
650  sal_Int32 nRow = getSplitRow();
651  SplitAtDefinedPosition( _splitcolumn, nRow );
652  }
653 }
654 
655 double SAL_CALL
657 {
658  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
659  return PixelsToPoints( getDevice(), xViewSplitable->getSplitHorizontal(), true );
660 }
661 
662 void SAL_CALL
663 ScVbaWindow::setSplitHorizontal( double _splithorizontal )
664 {
665  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
666  double fHoriPixels = PointsToPixels( getDevice(), _splithorizontal, true );
667  xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 );
668 }
669 
670 sal_Int32 SAL_CALL
672 {
673  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
674  return xViewSplitable->getSplitRow();
675 }
676 
677 void SAL_CALL
678 ScVbaWindow::setSplitRow( sal_Int32 _splitrow )
679 {
680  if( getSplitRow() != _splitrow )
681  {
682  uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
683  sal_Int32 nColumn = getSplitColumn();
684  SplitAtDefinedPosition( nColumn, _splitrow );
685  }
686 }
687 
688 double SAL_CALL
690 {
691  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
692  return PixelsToPoints( getDevice(), xViewSplitable->getSplitVertical(), false );
693 }
694 
695 void SAL_CALL
696 ScVbaWindow::setSplitVertical(double _splitvertical )
697 {
698  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
699  double fVertiPixels = PointsToPixels( getDevice(), _splitvertical, false );
700  xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
701 }
702 
703 void ScVbaWindow::SplitAtDefinedPosition( sal_Int32 nColumns, sal_Int32 nRows )
704 {
705  uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
706  uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
707  // nColumns and nRows means split columns/rows
708  if( nColumns == 0 && nRows == 0 )
709  return;
710 
711  sal_Int32 cellColumn = nColumns + 1;
712  sal_Int32 cellRow = nRows + 1;
713 
715  if ( pViewShell )
716  {
717  //firstly remove the old splitter
718  xViewSplitable->splitAtPosition(0,0);
719 
720  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
721  uno::Reference< excel::XWorksheet > xSheet( xApplication->getActiveSheet(), uno::UNO_SET_THROW );
722  xSheet->Cells(uno::makeAny(cellRow), uno::makeAny(cellColumn))->Select();
723 
724  //pViewShell->FreezeSplitters( FALSE );
725  dispatchExecute( pViewShell, SID_WINDOW_SPLIT );
726  }
727 }
728 
729 uno::Any SAL_CALL
731 {
732  uno::Reference< beans::XPropertySet > xProps = getControllerProps();
733  OUString sName( SC_UNO_ZOOMTYPE );
734  sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
735  xProps->getPropertyValue( sName ) >>= nZoomType;
736  if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
737  {
738  return uno::makeAny( true );
739  }
740  else if( nZoomType == view::DocumentZoomType::BY_VALUE )
741  {
742  sName = SC_UNO_ZOOMVALUE;
743  sal_Int16 nZoom = 100;
744  xProps->getPropertyValue( sName ) >>= nZoom;
745  return uno::makeAny( nZoom );
746  }
747  return uno::Any();
748 }
749 
750 void SAL_CALL ScVbaWindow::setZoom(const uno::Any& _zoom)
751 {
752  sal_Int16 nZoom = 100;
753  _zoom >>= nZoom;
754  uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW );
755  uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet();
756  SCTAB nTab = 0;
757  if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) )
758  throw uno::RuntimeException();
759  std::vector< SCTAB > vTabs;
760  vTabs.push_back( nTab );
761  excel::implSetZoom( m_xModel, nZoom, vTabs );
762 }
763 
764 uno::Reference< excel::XWorksheet > SAL_CALL
766 {
767  uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
768  return xApplication->getActiveSheet();
769 }
770 
771 uno::Any SAL_CALL
773 {
774  bool bPageBreak = false;
775  sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
776 
778  if (pViewShell)
779  bPageBreak = pViewShell->GetViewData().IsPagebreakMode();
780 
781  if( bPageBreak )
782  nWindowView = excel::XlWindowView::xlPageBreakPreview;
783  else
784  nWindowView = excel::XlWindowView::xlNormalView;
785 
786  return uno::makeAny( nWindowView );
787 }
788 
789 void SAL_CALL
791 {
792  sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
793  _view >>= nWindowView;
794  sal_uInt16 nSlot = FID_NORMALVIEWMODE;
795  switch ( nWindowView )
796  {
797  case excel::XlWindowView::xlNormalView:
798  nSlot = FID_NORMALVIEWMODE;
799  break;
800  case excel::XlWindowView::xlPageBreakPreview:
801  nSlot = FID_PAGEBREAKMODE;
802  break;
803  default:
804  DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_PARAMETER);
805  }
806  // !! TODO !! get view shell from controller
808  if ( pViewShell )
809  dispatchExecute( pViewShell, nSlot );
810 }
811 
812 uno::Reference< excel::XRange > SAL_CALL
814 {
815  uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW );
816  uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW );
817  uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) );
818  return xPane->getVisibleRange();
819 }
820 
821 sal_Int32 SAL_CALL
823 {
824  sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
825  double fConvertFactor = getDevice()->getInfo().PixelPerMeterX/100000;
826  return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
827 }
828 
829 sal_Int32 SAL_CALL
831 {
832  sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
833  double fConvertFactor = getDevice()->getInfo().PixelPerMeterY/100000;
834  return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters );
835 }
836 
837 void SAL_CALL
838 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 )
839 {
840  // need test, print current active sheet
841  // !! TODO !! get view shell from controller
842  PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, true );
843 }
844 
845 void SAL_CALL
846 ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges )
847 {
848  // need test, print preview current active sheet
849  // !! TODO !! get view shell from controller
851 }
852 
853 double SAL_CALL ScVbaWindow::getTabRatio()
854 {
856  if ( pViewShell && pViewShell->GetViewData().GetView() )
857  {
858  double fRatio = ScTabView::GetRelTabBarWidth();
859  if ( fRatio >= 0.0 && fRatio <= 1.0 )
860  return fRatio;
861  }
862  return 0.0;
863 }
864 
865 void SAL_CALL ScVbaWindow::setTabRatio( double fRatio )
866 {
868  if ( pViewShell && pViewShell->GetViewData().GetView() )
869  {
870  if ( fRatio >= 0.0 && fRatio <= 1.0 )
871  pViewShell->GetViewData().GetView()->SetRelTabBarWidth( fRatio );
872  }
873 }
874 
875 OUString
877 {
878  return "ScVbaWindow";
879 }
880 
881 uno::Sequence< OUString >
883 {
884  static uno::Sequence< OUString > const aServiceNames
885  {
886  "ooo.vba.excel.Window"
887  };
888  return aServiceNames;
889 }
890 
891 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
893  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
894 {
895  return cppu::acquire(new ScVbaWindow(args, context));
896 }
897 
898 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
virtual void SAL_CALL Activate() override
Definition: vbawindow.cxx:447
#define SC_UNO_COLROWHDR
Definition: unonames.hxx:535
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:36
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:43
virtual sal_Bool SAL_CALL getDisplayVerticalScrollBar() override
Definition: vbawindow.cxx:547
virtual void SAL_CALL setDisplayGridlines(sal_Bool _displaygridlines) override
Definition: vbawindow.cxx:499
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:710
#define SC_UNO_ZOOMVALUE
Definition: unonames.hxx:570
virtual void SAL_CALL setScrollColumn(const css::uno::Any &_scrollcolumn) override
Definition: vbawindow.cxx:392
uno::Reference< uno::XComponentContext > mxContext
ULONG m_refCount
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbawindow.cxx:882
ScHSplitPos WhichH(ScSplitPos ePos)
Definition: viewdata.hxx:704
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getVisibleRange() override
Definition: vbawindow.cxx:813
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:892
virtual void SAL_CALL setFreezePanes(sal_Bool _bFreezePanes) override
Definition: vbawindow.cxx:582
Sequence< OUString > aServiceNames
void init()
Definition: vbawindow.cxx:207
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1341
virtual void SAL_CALL ScrollWorkbookTabs(const css::uno::Any &Sheets, const css::uno::Any &Position) override
Definition: vbawindow.cxx:282
ScSplitPos
Definition: viewdata.hxx:45
static bool nameExists(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xSpreadDoc, const OUString &name, SCTAB &nTab)
virtual void SAL_CALL setSplit(sal_Bool _bSplit) override
Definition: vbawindow.cxx:620
virtual void SAL_CALL setTabRatio(double _tabratio) override
Definition: vbawindow.cxx:865
virtual OUString getServiceImplName() override
Definition: vbawindow.cxx:876
css::uno::Reference< css::beans::XPropertySet > getFrameProps() const
Definition: vbawindow.cxx:233
#define SC_UNO_SHOWGRID
Definition: unonames.hxx:545
SC_DLLPUBLIC void SetRelTabBarWidth(double fRelTabBarWidth)
Sets a relative tab bar width.
Definition: tabview.cxx:860
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
virtual css::uno::Any SAL_CALL getView() override
Definition: vbawindow.cxx:772
std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets
Definition: vbawindow.cxx:57
SfxFrame & GetFrame() const
virtual sal_Bool SAL_CALL getDisplayHorizontalScrollBar() override
Definition: vbawindow.cxx:519
BOOL IsMinimized(HWND hWnd)
virtual double SAL_CALL getTabRatio() override
Definition: vbawindow.cxx:853
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1355
const char * sName
ScViewData & GetViewData()
Definition: tabview.hxx:332
virtual void SAL_CALL setSplitRow(sal_Int32 _splitrow) override
Definition: vbawindow.cxx:678
virtual sal_Bool SAL_CALL getFreezePanes() override
Definition: vbawindow.cxx:575
virtual css::uno::Any SAL_CALL getScrollRow() override
Definition: vbawindow.cxx:347
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL RangeSelection() override
Definition: vbawindow.cxx:483
::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:638
virtual void SAL_CALL setScrollRow(const css::uno::Any &_scrollrow) override
Definition: vbawindow.cxx:362
virtual sal_Int32 SAL_CALL PointsToScreenPixelsX(sal_Int32 _points) override
Definition: vbawindow.cxx:822
virtual sal_Int32 SAL_CALL PointsToScreenPixelsY(sal_Int32 _points) override
Definition: vbawindow.cxx:830
virtual sal_Bool SAL_CALL getDisplayWorkbookTabs() override
Definition: vbawindow.cxx:561
virtual void SAL_CALL setDisplayOutline(sal_Bool _bDisplayOutline) override
Definition: vbawindow.cxx:541
virtual void SAL_CALL setSplitVertical(double _splitvertical) override
Definition: vbawindow.cxx:696
SfxObjectShell * GetEmbeddedObject() const
Definition: docuno.cxx:455
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:469
css::uno::Type const & get()
virtual css::uno::Any SAL_CALL getCaption() override
Definition: vbawindow.cxx:302
virtual sal_Int32 SAL_CALL getSplitColumn() override
Definition: vbawindow.cxx:638
SC_DLLPUBLIC void ScrollLines(long nDeltaX, long nDeltaY)
Definition: tabview.cxx:1313
static SC_DLLPUBLIC double GetRelTabBarWidth()
Returns the current tab bar width relative to the frame window width (0.0 ...
Definition: tabview.cxx:878
css::uno::Reference< css::beans::XPropertySet > getControllerProps() const
Definition: vbawindow.cxx:227
virtual void SAL_CALL setDisplayVerticalScrollBar(sal_Bool _bDisplayVerticalScrollBar) override
Definition: vbawindow.cxx:555
#define SC_UNO_ZOOMTYPE
Definition: unonames.hxx:569
virtual void SAL_CALL setDisplayHeadings(sal_Bool _bDisplayHeadings) override
Definition: vbawindow.cxx:513
#define SC_UNO_HORSCROLL
Definition: unonames.hxx:538
std::unordered_map< OUString, sal_Int32 > NameIndexHash
virtual void SAL_CALL setView(const css::uno::Any &_view) override
Definition: vbawindow.cxx:790
ScDBFunc * GetView() const
Definition: viewdata.cxx:852
virtual void SAL_CALL setSplitHorizontal(double _splithorizontal) override
Definition: vbawindow.cxx:663
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:505
virtual void SAL_CALL setZoom(const css::uno::Any &_zoom) override
Definition: vbawindow.cxx:750
virtual void SAL_CALL setDisplayWorkbookTabs(sal_Bool _bDisplayWorkbookTabs) override
Definition: vbawindow.cxx:569
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &FileName, const css::uno::Any &RouteWorkBook) override
Definition: vbawindow.cxx:455
#define SC_UNO_SHEETTABS
Definition: unonames.hxx:540
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:341
void SplitAtDefinedPosition(sal_Int32 nColumns, sal_Int32 nRows)
Definition: vbawindow.cxx:703
OUString aName
virtual css::uno::Any SAL_CALL Selection() override
Definition: vbawindow.cxx:476
#define SC_UNO_OUTLSYMB
Definition: unonames.hxx:539
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:838
virtual css::uno::Any SAL_CALL getWindowState() override
Definition: vbawindow.cxx:407
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:377
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:527
virtual double SAL_CALL getSplitHorizontal() override
Definition: vbawindow.cxx:656
virtual double SAL_CALL getSplitVertical() override
Definition: vbawindow.cxx:689
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:462
virtual sal_Bool SAL_CALL getSplit() override
Definition: vbawindow.cxx:613
virtual sal_Bool SAL_CALL getDisplayOutline() override
Definition: vbawindow.cxx:533
virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL ActiveSheet() override
Definition: vbawindow.cxx:765
Reference< XModel > xModel
#define SC_UNO_VERTSCROLL
Definition: unonames.hxx:552
virtual sal_Int32 SAL_CALL getSplitRow() override
Definition: vbawindow.cxx:671
Reference< XComponentContext > m_xContext
virtual sal_Bool SAL_CALL getDisplayGridlines() override
Definition: vbawindow.cxx:491
SystemWindow * GetSystemWindow() const
virtual css::uno::Any SAL_CALL getZoom() override
Definition: vbawindow.cxx:730
bool IsPagebreakMode() const
Definition: viewdata.hxx:425
virtual void SAL_CALL PrintPreview(const css::uno::Any &EnableChanges) override
Definition: vbawindow.cxx:846
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:645
sal_Int16 SCTAB
Definition: types.hxx:23
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:425