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>
33 #include <ooo/vba/excel/XApplication.hpp>
34 #include <ooo/vba/excel/XlWindowState.hpp>
35 #include <ooo/vba/excel/XlWindowView.hpp>
46 #include <unonames.hxx>
48 #include <unordered_map>
52 using namespace ::ooo::vba::excel::XlWindowState;
54 typedef std::unordered_map< OUString,
57 typedef std::vector< uno::Reference< sheet::XSpreadsheet > >
Sheets;
59 typedef ::cppu::WeakImplHelper< container::XEnumerationAccess
60 , css::container::XIndexAccess
61 , css::container::XNameAccess
66 class SelectedSheetsEnum :
public ::cppu::WeakImplHelper< container::XEnumeration >
69 uno::Reference< uno::XComponentContext >
m_xContext;
71 uno::Reference< frame::XModel >
m_xModel;
72 Sheets::const_iterator m_it;
75 SelectedSheetsEnum(
const uno::Reference< uno::XComponentContext >& xContext,
Sheets&& sheets,
const uno::Reference< frame::XModel >&
xModel )
76 : m_xContext( xContext ), m_sheets( std::move(sheets) ), m_xModel( xModel )
78 m_it = m_sheets.begin();
81 virtual sal_Bool SAL_CALL hasMoreElements( )
override
83 return m_it != m_sheets.end();
85 virtual uno::Any SAL_CALL nextElement( )
override
87 if ( !hasMoreElements() )
89 throw container::NoSuchElementException();
92 return uno::Any( uno::Reference< excel::XWorksheet > (
new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) );
99 uno::Reference< uno::XComponentContext >
m_xContext;
102 uno::Reference< frame::XModel >
m_xModel;
104 SelectedSheetsEnumAccess(
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< frame::XModel >&
xModel ):m_xContext( xContext ), m_xModel( xModel )
108 throw uno::RuntimeException(
"Cannot obtain current document" );
111 throw uno::RuntimeException(
"Cannot obtain docshell" );
114 throw uno::RuntimeException(
"Cannot obtain view shell" );
119 sheets.reserve( nTabCount );
120 uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW );
121 uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW );
122 for (
const auto& rTab : rMarkData)
124 if (rTab >= nTabCount)
126 uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( rTab ), uno::UNO_QUERY_THROW );
127 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
128 sheets.push_back( xSheet );
129 namesToIndices[ xNamed->getName() ] = nIndex++;
135 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
137 return new SelectedSheetsEnum( m_xContext, std::vector(sheets), m_xModel );
140 virtual ::sal_Int32 SAL_CALL getCount( )
override
142 return sheets.size();
144 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
148 throw lang::IndexOutOfBoundsException();
154 virtual uno::Type SAL_CALL getElementType( )
override
159 virtual sal_Bool SAL_CALL hasElements( )
override
161 return ( !sheets.empty() );
165 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
167 NameIndexHash::const_iterator it = namesToIndices.find( aName );
168 if ( it == namesToIndices.end() )
169 throw container::NoSuchElementException();
170 return uno::Any( sheets[ it->second ] );
174 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
179 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
181 NameIndexHash::const_iterator it = namesToIndices.find( aName );
182 return (it != namesToIndices.end());
190 const uno::Reference< XHelperInterface >& xParent,
191 const uno::Reference< uno::XComponentContext >& xContext,
192 const uno::Reference< frame::XModel >& xModel,
193 const uno::Reference< frame::XController >& xController ) :
200 const uno::Sequence< uno::Any >& args,
201 const uno::Reference< uno::XComponentContext >& xContext ) :
221 catch( uno::Exception& )
227 uno::Reference< beans::XPropertySet >
230 return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW );
233 uno::Reference< beans::XPropertySet >
236 return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW );
239 uno::Reference< awt::XDevice >
242 return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW );
249 throw uno::RuntimeException();
251 m_xPane->LargeScroll( Down, Up, ToRight, ToLeft );
253 m_xPane->SmallScroll( Down, Up, ToRight, ToLeft );
259 Scroll( Down, Up, ToRight, ToLeft,
false );
265 Scroll( Down, Up, ToRight, ToLeft,
true );
271 uno::Reference< container::XEnumerationAccess > xEnumAccess(
new SelectedSheetsEnumAccess(
mxContext,
m_xModel ) );
276 uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
277 return xColl->Item( aIndex,
uno::Any() );
339 sal_Int32 scrollRow = 0;
340 _scrollrow >>= scrollRow;
369 sal_Int32 scrollColumn = 0;
370 _scrollcolumn >>= scrollColumn;
373 pViewShell->
ScrollLines(scrollColumn - nOldValue, 0);
380 sal_Int32 nwindowState = xlNormal;
383 SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
388 nwindowState = xlMaximized;
390 nwindowState = xlMinimized;
398 sal_Int32 nwindowState = xlMaximized;
399 _windowstate >>= nwindowState;
402 SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame();
406 if ( nwindowState == xlMaximized)
408 else if (nwindowState == xlMinimized)
410 else if (nwindowState == xlNormal)
413 throw uno::RuntimeException(
"Invalid Parameter" );
422 workbook->Activate();
429 workbook->Close(SaveChanges, FileName, RouteWorkBook );
432 uno::Reference< excel::XPane > SAL_CALL
435 uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
439 uno::Reference< excel::XRange > SAL_CALL
442 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
443 return xApplication->getActiveCell();
449 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
450 return xApplication->getSelection();
453 uno::Reference< excel::XRange > SAL_CALL
458 return uno::Reference< excel::XRange >(
Selection(), uno::UNO_QUERY_THROW );
478 bool bHeading =
true;
492 bool bHorizontalScrollBar =
true;
494 return bHorizontalScrollBar;
506 bool bOutline =
true;
520 bool bVerticalScrollBar =
true;
522 return bVerticalScrollBar;
534 bool bWorkbookTabs =
true;
536 return bWorkbookTabs;
548 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
549 return xViewFreezable->hasFrozenPanes();
555 uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
556 uno::Reference< sheet::XViewSplitable > xViewSplitable( xViewPane, uno::UNO_QUERY_THROW );
557 uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewPane, uno::UNO_QUERY_THROW );
560 if( xViewSplitable->getIsWindowSplit() )
565 xViewFreezable->freezeAtPosition( nColumn, nRow );
570 table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange();
571 sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 );
572 sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 );
573 xViewFreezable->freezeAtPosition( nColumn, nRow );
579 xViewSplitable->splitAtPosition(0,0);
586 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
587 return xViewSplitable->getIsWindowSplit();
595 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
596 xViewSplitable->splitAtPosition(0,0);
600 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
601 uno::Reference< excel::XRange > xRange =
ActiveCell();
602 sal_Int32 nRow = xRange->getRow();
603 sal_Int32 nColumn = xRange->getColumn();
611 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
612 return xViewSplitable->getSplitColumn();
620 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
629 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
636 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
638 xViewSplitable->splitAtPosition( static_cast< sal_Int32 >( fHoriPixels ), 0 );
644 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
645 return xViewSplitable->getSplitRow();
653 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
662 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
669 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
671 xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) );
676 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
677 uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
679 if( nColumns == 0 && nRows == 0 )
682 sal_Int32 cellColumn = nColumns + 1;
683 sal_Int32 cellRow = nRows + 1;
689 xViewSplitable->splitAtPosition(0,0);
691 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
692 uno::Reference< excel::XWorksheet > xSheet( xApplication->getActiveSheet(), uno::UNO_SET_THROW );
705 sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
706 xProps->getPropertyValue( sName ) >>= nZoomType;
707 if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
711 else if( nZoomType == view::DocumentZoomType::BY_VALUE )
714 sal_Int16 nZoom = 100;
715 xProps->getPropertyValue( sName ) >>= nZoom;
723 sal_Int16 nZoom = 100;
725 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc(
m_xModel, uno::UNO_QUERY_THROW );
726 uno::Reference< excel::XWorksheet > xActiveSheet =
ActiveSheet();
729 throw uno::RuntimeException();
730 std::vector< SCTAB > vTabs { nTab };
734 uno::Reference< excel::XWorksheet > SAL_CALL
737 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
738 return xApplication->getActiveSheet();
744 bool bPageBreak =
false;
745 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
752 nWindowView = excel::XlWindowView::xlPageBreakPreview;
754 nWindowView = excel::XlWindowView::xlNormalView;
762 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
763 _view >>= nWindowView;
764 sal_uInt16 nSlot = FID_NORMALVIEWMODE;
765 switch ( nWindowView )
767 case excel::XlWindowView::xlNormalView:
768 nSlot = FID_NORMALVIEWMODE;
770 case excel::XlWindowView::xlPageBreakPreview:
771 nSlot = FID_PAGEBREAKMODE;
782 uno::Reference< excel::XRange > SAL_CALL
785 uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW );
786 uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW );
788 return xPane->getVisibleRange();
794 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
795 double fConvertFactor =
getDevice()->getInfo().PixelPerMeterX/100000;
796 return static_cast<sal_Int32
>(fConvertFactor * nHundredthsofOneMillimeters );
802 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
803 double fConvertFactor =
getDevice()->getInfo().PixelPerMeterY/100000;
804 return static_cast<sal_Int32
>(fConvertFactor * nHundredthsofOneMillimeters );
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 )
829 if ( fRatio >= 0.0 && fRatio <= 1.0 )
840 if ( fRatio >= 0.0 && fRatio <= 1.0 )
848 return "ScVbaWindow";
851 uno::Sequence< OUString >
856 "ooo.vba.excel.Window"
861 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
863 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
865 return cppu::acquire(
new ScVbaWindow(args, context));
ScMarkData & GetMarkData()
virtual void SAL_CALL Activate() override
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
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...
virtual sal_Bool SAL_CALL getDisplayVerticalScrollBar() override
virtual void SAL_CALL setDisplayGridlines(sal_Bool _displaygridlines) override
ScVSplitPos WhichV(ScSplitPos ePos)
virtual void SAL_CALL setScrollColumn(const css::uno::Any &_scrollcolumn) override
virtual css::uno::Sequence< OUString > getServiceNames() override
ScHSplitPos WhichH(ScSplitPos ePos)
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getVisibleRange() override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_ScVbaWindow_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
virtual void SAL_CALL setFreezePanes(sal_Bool _bFreezePanes) override
Sequence< OUString > aServiceNames
ScSplitPos GetActivePart() const
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
virtual void SAL_CALL ScrollWorkbookTabs(const css::uno::Any &Sheets, const css::uno::Any &Position) override
SC_DLLPUBLIC void ScrollLines(tools::Long nDeltaX, tools::Long nDeltaY)
virtual void SAL_CALL setSplit(sal_Bool _bSplit) override
virtual void SAL_CALL setTabRatio(double _tabratio) override
virtual OUString getServiceImplName() override
css::uno::Reference< css::beans::XPropertySet > getFrameProps() const
SC_DLLPUBLIC void SetRelTabBarWidth(double fRelTabBarWidth)
Sets a relative tab bar width.
SC_DLLPUBLIC SCTAB GetTableCount() const
virtual css::uno::Any SAL_CALL getView() override
std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets
SfxFrame & GetFrame() const
virtual sal_Bool SAL_CALL getDisplayHorizontalScrollBar() override
BOOL IsMinimized(HWND hWnd)
virtual double SAL_CALL getTabRatio() override
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
ScViewData & GetViewData()
virtual void SAL_CALL setSplitRow(sal_Int32 _splitrow) override
virtual sal_Bool SAL_CALL getFreezePanes() override
virtual css::uno::Any SAL_CALL getScrollRow() override
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL RangeSelection() override
::cppu::WeakImplHelper< container::XEnumerationAccess, css::container::XIndexAccess, css::container::XNameAccess > SelectedSheets_BASE
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
css::uno::Reference< css::awt::XDevice > getDevice() const
virtual void SAL_CALL setScrollRow(const css::uno::Any &_scrollrow) override
virtual sal_Int32 SAL_CALL PointsToScreenPixelsX(sal_Int32 _points) override
virtual sal_Int32 SAL_CALL PointsToScreenPixelsY(sal_Int32 _points) override
virtual sal_Bool SAL_CALL getDisplayWorkbookTabs() override
virtual void SAL_CALL setDisplayOutline(sal_Bool _bDisplayOutline) override
virtual void SAL_CALL setSplitVertical(double _splitvertical) override
SfxObjectShell * GetEmbeddedObject() const
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::unordered_map< OUString, SCTAB > NameIndexHash
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL ActiveCell() override
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
virtual sal_Int32 SAL_CALL getSplitColumn() override
static SC_DLLPUBLIC double GetRelTabBarWidth()
Returns the current tab bar width relative to the frame window width (0.0 ...
css::uno::Reference< css::beans::XPropertySet > getControllerProps() const
virtual void SAL_CALL setDisplayVerticalScrollBar(sal_Bool _bDisplayVerticalScrollBar) override
virtual void SAL_CALL setDisplayHeadings(sal_Bool _bDisplayHeadings) override
std::unordered_map< OUString, sal_Int32 > NameIndexHash
virtual void SAL_CALL setView(const css::uno::Any &_view) override
ScDBFunc * GetView() const
virtual void SAL_CALL setSplitHorizontal(double _splithorizontal) override
ScTabViewShell * getBestViewShell(const css::uno::Reference< css::frame::XModel > &xModel)
#define ERRCODE_BASIC_BAD_PARAMETER
virtual sal_Bool SAL_CALL getDisplayHeadings() override
virtual void SAL_CALL setZoom(const css::uno::Any &_zoom) override
virtual void SAL_CALL setDisplayWorkbookTabs(sal_Bool _bDisplayWorkbookTabs) override
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &FileName, const css::uno::Any &RouteWorkBook) override
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
void SplitAtDefinedPosition(sal_Int32 nColumns, sal_Int32 nRows)
virtual css::uno::Any SAL_CALL Selection() override
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
virtual css::uno::Any SAL_CALL getWindowState() override
virtual css::uno::Any SAL_CALL SelectedSheets(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL getScrollColumn() override
cppu::ImplInheritanceHelper< VbaWindowBase, ov::word::XWindow > WindowImpl_BASE
const ScDocument & GetDocument() const
void Scroll(const css::uno::Any &Down, const css::uno::Any &Up, const css::uno::Any &ToRight, const css::uno::Any &ToLeft, bool bLargeScroll)
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
virtual double SAL_CALL getSplitHorizontal() override
virtual double SAL_CALL getSplitVertical() override
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
virtual css::uno::Reference< ov::excel::XPane > SAL_CALL ActivePane() override
virtual sal_Bool SAL_CALL getSplit() override
virtual sal_Bool SAL_CALL getDisplayOutline() override
virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL ActiveSheet() override
Reference< XModel > xModel
#define SC_UNO_VERTSCROLL
virtual sal_Int32 SAL_CALL getSplitRow() override
Reference< XComponentContext > m_xContext
virtual sal_Bool SAL_CALL getDisplayGridlines() override
SystemWindow * GetSystemWindow() const
virtual css::uno::Any SAL_CALL getZoom() override
bool IsPagebreakMode() const
virtual void SAL_CALL PrintPreview(const css::uno::Any &EnableChanges) override
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)
void implSetZoom(const uno::Reference< frame::XModel > &xModel, sal_Int16 nZoom, std::vector< SCTAB > &nTabs)
virtual void SAL_CALL setSplitColumn(sal_Int32 _splitcolumn) override
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
bool m_bDetectedRangeSegmentation false
virtual void SAL_CALL setWindowState(const css::uno::Any &_windowstate) override