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>
47#include <unonames.hxx>
49#include <unordered_map>
53using namespace ::ooo::vba::excel::XlWindowState;
55typedef std::unordered_map< OUString,
58typedef std::vector< uno::Reference< sheet::XSpreadsheet > >
Sheets;
60typedef ::cppu::WeakImplHelper< container::XEnumerationAccess
61 , css::container::XIndexAccess
62 , css::container::XNameAccess
67class SelectedSheetsEnum :
public ::cppu::WeakImplHelper< container::XEnumeration >
70 uno::Reference< uno::XComponentContext >
m_xContext;
72 uno::Reference< frame::XModel >
m_xModel;
73 Sheets::const_iterator m_it;
76 SelectedSheetsEnum( uno::Reference< uno::XComponentContext > xContext,
Sheets&& sheets, uno::Reference< frame::XModel >
xModel )
79 m_it = m_sheets.begin();
82 virtual sal_Bool SAL_CALL hasMoreElements( )
override
84 return m_it != m_sheets.end();
86 virtual uno::Any SAL_CALL nextElement( )
override
88 if ( !hasMoreElements() )
90 throw container::NoSuchElementException();
100 uno::Reference< uno::XComponentContext >
m_xContext;
103 uno::Reference< frame::XModel >
m_xModel;
105 SelectedSheetsEnumAccess( uno::Reference< uno::XComponentContext > xContext, uno::Reference< frame::XModel >
xModel ):
m_xContext(std::move( xContext )),
m_xModel(std::move(
xModel ))
109 throw uno::RuntimeException(
"Cannot obtain current document" );
112 throw uno::RuntimeException(
"Cannot obtain docshell" );
115 throw uno::RuntimeException(
"Cannot obtain view shell" );
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)
125 if (rTab >= nTabCount)
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++;
136 virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( )
override
141 virtual ::sal_Int32 SAL_CALL getCount( )
override
143 return sheets.size();
145 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
149 throw lang::IndexOutOfBoundsException();
155 virtual uno::Type SAL_CALL getElementType( )
override
160 virtual sal_Bool SAL_CALL hasElements( )
override
162 return ( !sheets.empty() );
166 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override
168 NameIndexHash::const_iterator it = namesToIndices.find(
aName );
169 if ( it == namesToIndices.end() )
170 throw container::NoSuchElementException();
171 return uno::Any( sheets[ it->second ] );
175 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
180 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override
182 NameIndexHash::const_iterator it = namesToIndices.find(
aName );
183 return (it != namesToIndices.end());
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 ) :
201 const uno::Sequence< uno::Any >& args,
202 const uno::Reference< uno::XComponentContext >& xContext ) :
222 catch( uno::Exception& )
228uno::Reference< beans::XPropertySet >
231 return uno::Reference< beans::XPropertySet >( getController(), uno::UNO_QUERY_THROW );
234uno::Reference< beans::XPropertySet >
237 return uno::Reference< beans::XPropertySet >( getController()->getFrame(), uno::UNO_QUERY_THROW );
240uno::Reference< awt::XDevice >
243 return uno::Reference< awt::XDevice >( getWindow(), uno::UNO_QUERY_THROW );
250 throw uno::RuntimeException();
272 uno::Reference< container::XEnumerationAccess > xEnumAccess(
new SelectedSheetsEnumAccess(
mxContext,
m_xModel ) );
277 uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW );
340 sal_Int32 scrollRow = 0;
341 _scrollrow >>= scrollRow;
370 sal_Int32 scrollColumn = 0;
371 _scrollcolumn >>= scrollColumn;
374 pViewShell->
ScrollLines(scrollColumn - nOldValue, 0);
381 sal_Int32 nwindowState = xlNormal;
389 nwindowState = xlMaximized;
391 nwindowState = xlMinimized;
399 sal_Int32 nwindowState = xlMaximized;
400 _windowstate >>= nwindowState;
407 if ( nwindowState == xlMaximized)
409 else if (nwindowState == xlMinimized)
411 else if (nwindowState == xlNormal)
414 throw uno::RuntimeException(
"Invalid Parameter" );
423 workbook->Activate();
430 workbook->Close(SaveChanges, FileName, RouteWorkBook );
433uno::Reference< excel::XPane > SAL_CALL
436 uno::Reference< sheet::XViewPane > xViewPane( getController(), uno::UNO_QUERY_THROW );
440uno::Reference< excel::XRange > SAL_CALL
443 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
444 return xApplication->getActiveCell();
450 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
451 return xApplication->getSelection();
454uno::Reference< excel::XRange > SAL_CALL
459 return uno::Reference< excel::XRange >(
Selection(), uno::UNO_QUERY_THROW );
479 bool bHeading =
true;
493 bool bHorizontalScrollBar =
true;
495 return bHorizontalScrollBar;
507 bool bOutline =
true;
521 bool bVerticalScrollBar =
true;
523 return bVerticalScrollBar;
535 bool bWorkbookTabs =
true;
537 return bWorkbookTabs;
549 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
550 return xViewFreezable->hasFrozenPanes();
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 );
561 if( xViewSplitable->getIsWindowSplit() )
566 xViewFreezable->freezeAtPosition( nColumn, nRow );
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 );
580 xViewSplitable->splitAtPosition(0,0);
587 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
588 return xViewSplitable->getIsWindowSplit();
596 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
597 xViewSplitable->splitAtPosition(0,0);
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();
612 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
613 return xViewSplitable->getSplitColumn();
621 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
630 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
637 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
639 xViewSplitable->splitAtPosition(
static_cast< sal_Int32
>( fHoriPixels ), 0 );
645 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
646 return xViewSplitable->getSplitRow();
654 uno::Reference< sheet::XViewFreezable > xViewFreezable( getController(), uno::UNO_QUERY_THROW );
663 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
670 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
672 xViewSplitable->splitAtPosition( 0,
static_cast<sal_Int32
>( fVertiPixels ) );
677 uno::Reference< sheet::XViewSplitable > xViewSplitable( getController(), uno::UNO_QUERY_THROW );
678 uno::Reference< sheet::XViewFreezable > xViewFreezable( xViewSplitable, uno::UNO_QUERY_THROW );
680 if( nColumns == 0 && nRows == 0 )
683 sal_Int32 cellColumn = nColumns + 1;
684 sal_Int32 cellRow = nRows + 1;
690 xViewSplitable->splitAtPosition(0,0);
692 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
693 uno::Reference< excel::XWorksheet > xSheet( xApplication->getActiveSheet(), uno::UNO_SET_THROW );
706 sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH;
707 xProps->getPropertyValue(
sName ) >>= nZoomType;
708 if( nZoomType == view::DocumentZoomType::PAGE_WIDTH )
712 else if( nZoomType == view::DocumentZoomType::BY_VALUE )
715 sal_Int16 nZoom = 100;
716 xProps->getPropertyValue(
sName ) >>= nZoom;
724 sal_Int16 nZoom = 100;
726 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc(
m_xModel, uno::UNO_QUERY_THROW );
727 uno::Reference< excel::XWorksheet > xActiveSheet =
ActiveSheet();
730 throw uno::RuntimeException();
731 std::vector< SCTAB > vTabs { nTab };
735uno::Reference< excel::XWorksheet > SAL_CALL
738 uno::Reference< excel::XApplication > xApplication(
Application(), uno::UNO_QUERY_THROW );
739 return xApplication->getActiveSheet();
745 bool bPageBreak =
false;
746 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
753 nWindowView = excel::XlWindowView::xlPageBreakPreview;
755 nWindowView = excel::XlWindowView::xlNormalView;
763 sal_Int32 nWindowView = excel::XlWindowView::xlNormalView;
764 _view >>= nWindowView;
765 sal_uInt16 nSlot = FID_NORMALVIEWMODE;
766 switch ( nWindowView )
768 case excel::XlWindowView::xlNormalView:
769 nSlot = FID_NORMALVIEWMODE;
771 case excel::XlWindowView::xlPageBreakPreview:
772 nSlot = FID_PAGEBREAKMODE;
783uno::Reference< excel::XRange > SAL_CALL
786 uno::Reference< container::XIndexAccess > xPanesIA( getController(), uno::UNO_QUERY_THROW );
787 uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW );
789 return xPane->getVisibleRange();
795 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
796 double fConvertFactor =
getDevice()->getInfo().PixelPerMeterX/100000;
797 return static_cast<sal_Int32
>(fConvertFactor * nHundredthsofOneMillimeters );
803 sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points );
804 double fConvertFactor =
getDevice()->getInfo().PixelPerMeterY/100000;
805 return static_cast<sal_Int32
>(fConvertFactor * nHundredthsofOneMillimeters );
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 )
830 if ( fRatio >= 0.0 && fRatio <= 1.0 )
841 if ( fRatio >= 0.0 && fRatio <= 1.0 )
849 return "ScVbaWindow";
852uno::Sequence< OUString >
857 "ooo.vba.excel.Window"
862extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
864 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
Reference< XComponentContext > m_xContext
FILE * init(int, char **)
const ScDocument & GetDocument() const
SC_DLLPUBLIC SCTAB GetTableCount() const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
SfxObjectShell * GetEmbeddedObject() const
SC_DLLPUBLIC void SetRelTabBarWidth(double fRelTabBarWidth)
Sets a relative tab bar width.
static SC_DLLPUBLIC double GetRelTabBarWidth()
Returns the current tab bar width relative to the frame window width (0.0 ... 1.0).
SC_DLLPUBLIC void ScrollLines(tools::Long nDeltaX, tools::Long nDeltaY)
ScViewData & GetViewData()
virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL ActiveSheet() override
virtual void SAL_CALL setDisplayOutline(sal_Bool _bDisplayOutline) override
virtual sal_Bool SAL_CALL getDisplayHeadings() override
css::uno::Reference< ov::excel::XPane > m_xPane
virtual double SAL_CALL getTabRatio() override
virtual void SAL_CALL setFreezePanes(sal_Bool _bFreezePanes) override
virtual sal_Int32 SAL_CALL getSplitColumn() override
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &FileName, const css::uno::Any &RouteWorkBook) override
virtual double SAL_CALL getSplitVertical() override
virtual void SAL_CALL setDisplayVerticalScrollBar(sal_Bool _bDisplayVerticalScrollBar) override
void Scroll(const css::uno::Any &Down, const css::uno::Any &Up, const css::uno::Any &ToRight, const css::uno::Any &ToLeft, bool bLargeScroll)
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 getZoom() override
virtual css::uno::Any SAL_CALL getWindowState() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL getCaption() override
virtual sal_Bool SAL_CALL getDisplayWorkbookTabs() override
virtual void SAL_CALL setTabRatio(double _tabratio) override
virtual double SAL_CALL getSplitHorizontal() override
virtual void SAL_CALL setSplit(sal_Bool _bSplit) override
virtual void SAL_CALL setSplitHorizontal(double _splithorizontal) 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 void SAL_CALL Activate() override
virtual void SAL_CALL setDisplayHeadings(sal_Bool _bDisplayHeadings) override
virtual css::uno::Any SAL_CALL Selection() override
virtual sal_Int32 SAL_CALL PointsToScreenPixelsX(sal_Int32 _points) override
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL ActiveCell() override
virtual void SAL_CALL PrintPreview(const css::uno::Any &EnableChanges) override
virtual sal_Bool SAL_CALL getDisplayVerticalScrollBar() override
virtual void SAL_CALL setSplitVertical(double _splitvertical) override
virtual void SAL_CALL setZoom(const css::uno::Any &_zoom) override
virtual sal_Bool SAL_CALL getSplit() override
virtual sal_Int32 SAL_CALL getSplitRow() override
virtual sal_Bool SAL_CALL getDisplayOutline() override
void SplitAtDefinedPosition(sal_Int32 nColumns, sal_Int32 nRows)
virtual OUString getServiceImplName() override
css::uno::Reference< css::beans::XPropertySet > getControllerProps() const
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL RangeSelection() override
virtual void SAL_CALL setScrollColumn(const css::uno::Any &_scrollcolumn) override
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
virtual css::uno::Any SAL_CALL getScrollRow() override
virtual void SAL_CALL setSplitColumn(sal_Int32 _splitcolumn) override
virtual css::uno::Any SAL_CALL getView() override
virtual void SAL_CALL setView(const css::uno::Any &_view) override
virtual sal_Bool SAL_CALL getDisplayHorizontalScrollBar() override
virtual void SAL_CALL setSplitRow(sal_Int32 _splitrow) override
virtual void SAL_CALL setDisplayWorkbookTabs(sal_Bool _bDisplayWorkbookTabs) override
virtual void SAL_CALL ScrollWorkbookTabs(const css::uno::Any &Sheets, const css::uno::Any &Position) override
virtual void SAL_CALL setDisplayGridlines(sal_Bool _displaygridlines) override
virtual sal_Bool SAL_CALL getDisplayGridlines() override
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getVisibleRange() override
virtual css::uno::Any SAL_CALL SelectedSheets(const css::uno::Any &aIndex) override
virtual void SAL_CALL setScrollRow(const css::uno::Any &_scrollrow) override
virtual void SAL_CALL setCaption(const css::uno::Any &_caption) override
virtual void SAL_CALL setWindowState(const css::uno::Any &_windowstate) override
virtual void SAL_CALL setDisplayHorizontalScrollBar(sal_Bool _bDisplayHorizontalScrollBar) 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)
css::uno::Reference< css::awt::XDevice > getDevice() const
virtual sal_Bool SAL_CALL getFreezePanes() override
css::uno::Reference< css::beans::XPropertySet > getFrameProps() const
virtual sal_Int32 SAL_CALL PointsToScreenPixelsY(sal_Int32 _points) override
virtual css::uno::Reference< ov::excel::XPane > SAL_CALL ActivePane() override
virtual css::uno::Any SAL_CALL getScrollColumn() override
static bool nameExists(const css::uno::Reference< css::sheet::XSpreadsheetDocument > &xSpreadDoc, std::u16string_view name, SCTAB &nTab)
ScMarkData & GetMarkData()
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
ScDBFunc * GetView() const
ScSplitPos GetActivePart() const
bool IsPagebreakMode() const
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
SystemWindow * GetSystemWindow() const
SfxFrame & GetFrame() const
SfxViewFrame & GetViewFrame() const
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
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)
#define ERRCODE_BASIC_BAD_PARAMETER
Reference< XController > xController
Reference< XModel > xModel
constexpr OUStringLiteral SC_UNO_ZOOMVALUE
constexpr OUStringLiteral SC_UNO_SHOWGRID
constexpr OUStringLiteral SC_UNO_ZOOMTYPE
constexpr OUStringLiteral SC_UNO_OUTLSYMB
constexpr OUStringLiteral SC_UNO_SHEETTABS
constexpr OUStringLiteral SC_UNO_COLROWHDR
constexpr OUStringLiteral SC_UNO_VERTSCROLL
constexpr OUStringLiteral SC_UNONAME_TITLE
constexpr OUStringLiteral SC_UNO_HORSCROLL
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)
std::unordered_map< OUString, SCTAB > NameIndexHash
std::vector< uno::Reference< sheet::XSpreadsheet > > Sheets
::cppu::WeakImplHelper< container::XEnumerationAccess, css::container::XIndexAccess, css::container::XNameAccess > SelectedSheets_BASE
cppu::ImplInheritanceHelper< VbaWindowBase, ov::word::XWindow > WindowImpl_BASE
ScHSplitPos WhichH(ScSplitPos ePos)
ScVSplitPos WhichV(ScSplitPos ePos)
BOOL IsMinimized(HWND hWnd)
BOOL IsMaximized(HWND hWnd)