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