23#include <ooo/vba/excel/XWorksheet.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/sheet/XSheetPageBreak.hpp>
26#include <com/sun/star/table/XColumnRowRange.hpp>
27#include <com/sun/star/uno/XComponentContext.hpp>
35class RangePageBreaks :
public ::cppu::WeakImplHelper<container::XIndexAccess >
38 uno::Reference< XHelperInterface >
mxParent;
39 uno::Reference< uno::XComponentContext >
mxContext;
40 uno::Reference< sheet::XSheetPageBreak > mxSheetPageBreak;
44 RangePageBreaks( uno::Reference< XHelperInterface > xParent,
45 uno::Reference< uno::XComponentContext > xContext,
46 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak,
47 bool bColumn ) :
mxParent(
std::move( xParent )),
mxContext(
std::move( xContext )), mxSheetPageBreak(
std::move( xSheetPageBreak )), m_bColumn( bColumn )
52 sal_Int32 getAPIStartofRange(
const uno::Reference< excel::XRange >& xRange )
55 return xRange->getColumn() - 1;
56 return xRange->getRow() - 1;
60 sal_Int32 getAPIEndIndexofRange(
const uno::Reference< excel::XRange >& xRange, sal_Int32 nUsedStart )
63 return nUsedStart + xRange->Columns(
uno::Any() )->getCount() - 1;
64 return nUsedStart + xRange->Rows(
uno::Any() )->getCount();
68 uno::Sequence<sheet::TablePageBreakData> getAllPageBreaks()
71 return mxSheetPageBreak->getColumnPageBreaks();
72 return mxSheetPageBreak->getRowPageBreaks();
76 uno::Reference<container::XIndexAccess> getRowColContainer()
const
78 uno::Reference< table::XColumnRowRange > xColumnRowRange( mxSheetPageBreak, uno::UNO_QUERY_THROW );
79 uno::Reference<container::XIndexAccess> xIndexAccess;
81 xIndexAccess.set( xColumnRowRange->getColumns(), uno::UNO_QUERY_THROW );
83 xIndexAccess.set( xColumnRowRange->getRows(), uno::UNO_QUERY_THROW );
88 sheet::TablePageBreakData getTablePageBreakData( sal_Int32 nAPIItemIndex );
94 virtual sal_Int32 SAL_CALL getCount( )
override;
95 virtual uno::Any SAL_CALL getByIndex( sal_Int32
Index )
override;
96 virtual uno::Type SAL_CALL getElementType( )
override
102 virtual sal_Bool SAL_CALL hasElements( )
override
115sal_Int32 SAL_CALL RangePageBreaks::getCount( )
117 uno::Reference< excel::XWorksheet > xWorksheet( mxParent, uno::UNO_QUERY_THROW );
118 uno::Reference< excel::XRange > xRange = xWorksheet->getUsedRange();
119 sal_Int32 nUsedStart = getAPIStartofRange( xRange );
120 sal_Int32 nUsedEnd = getAPIEndIndexofRange( xRange, nUsedStart );
121 const uno::Sequence<sheet::TablePageBreakData> aTablePageBreakData = getAllPageBreaks();
123 auto pPageBreak = std::find_if(aTablePageBreakData.begin(), aTablePageBreakData.end(),
124 [nUsedEnd](
const sheet::TablePageBreakData& rPageBreak) { return rPageBreak.Position > nUsedEnd + 1; });
126 return static_cast<sal_Int32
>(std::distance(aTablePageBreakData.begin(), pPageBreak));
129uno::Any SAL_CALL RangePageBreaks::getByIndex( sal_Int32
Index )
133 sheet::TablePageBreakData aTablePageBreakData = getTablePageBreakData(
Index );
134 uno::Reference< container::XIndexAccess > xIndexAccess = getRowColContainer();
135 sal_Int32
nPos = aTablePageBreakData.Position;
136 if( (nPos < xIndexAccess->getCount()) && (nPos > -1) )
138 uno::Reference< beans::XPropertySet > xRowColPropertySet( xIndexAccess->getByIndex(nPos), uno::UNO_QUERY_THROW );
140 return uno::Any( uno::Reference< excel::XVPageBreak >(
new ScVbaVPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) ));
141 return uno::Any( uno::Reference< excel::XHPageBreak >(
new ScVbaHPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) ));
144 throw lang::IndexOutOfBoundsException();
147sheet::TablePageBreakData RangePageBreaks::getTablePageBreakData( sal_Int32 nAPIItemIndex )
149 sal_Int32
index = -1;
150 sheet::TablePageBreakData aTablePageBreakData;
151 uno::Reference< excel::XWorksheet > xWorksheet( mxParent, uno::UNO_QUERY_THROW );
152 uno::Reference< excel::XRange > xRange = xWorksheet->getUsedRange();
153 sal_Int32 nUsedStart = getAPIStartofRange( xRange );
154 sal_Int32 nUsedEnd = getAPIEndIndexofRange( xRange, nUsedStart );
155 const uno::Sequence<sheet::TablePageBreakData> aTablePageBreakDataList = getAllPageBreaks();
157 for(
const auto& rTablePageBreakData : aTablePageBreakDataList )
159 aTablePageBreakData = rTablePageBreakData;
160 sal_Int32
nPos = aTablePageBreakData.Position;
161 if( nPos > nUsedEnd + 1 )
162 DebugHelper::runtimeexception(ERRCODE_BASIC_METHOD_FAILED);
164 if( index == nAPIItemIndex )
165 return aTablePageBreakData;
168 return aTablePageBreakData;
171uno::Any RangePageBreaks::Add(
const css::uno::Any& Before )
173 uno::Reference< excel::XRange > xRange;
177 DebugHelper::basicexception(ERRCODE_BASIC_BAD_ARGUMENT, {});
180 sal_Int32 nAPIRowColIndex = getAPIStartofRange( xRange );
181 uno::Reference< container::XIndexAccess > xIndexAccess = getRowColContainer();
182 uno::Reference< beans::XPropertySet > xRowColPropertySet( xIndexAccess->getByIndex(nAPIRowColIndex), uno::UNO_QUERY_THROW );
183 xRowColPropertySet->setPropertyValue(
"IsStartOfNewPage",
uno::Any(
true));
184 sheet::TablePageBreakData aTablePageBreakData;
185 aTablePageBreakData.ManualBreak =
true;
186 aTablePageBreakData.Position = nAPIRowColIndex;
188 return uno::Any( uno::Reference< excel::XVPageBreak >(
new ScVbaVPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) ));
189 return uno::Any( uno::Reference< excel::XHPageBreak >(
new ScVbaHPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) ));
196 uno::Reference<container::XIndexAccess > m_xIndexAccess;
199 explicit RangePageBreaksEnumWrapper( uno::Reference< container::XIndexAccess > xIndexAccess ) : m_xIndexAccess(
std::move( xIndexAccess )),
nIndex( 0 ) {}
200 virtual sal_Bool SAL_CALL hasMoreElements( )
override
202 return ( nIndex < m_xIndexAccess->getCount() );
205 virtual uno::Any SAL_CALL nextElement( )
override
207 if ( nIndex < m_xIndexAccess->getCount() )
208 return m_xIndexAccess->getByIndex( nIndex++ );
209 throw container::NoSuchElementException();
216 const uno::Reference< uno::XComponentContext >& xContext,
217 const uno::Reference< sheet::XSheetPageBreak >& xSheetPageBreak):
218 ScVbaHPageBreaks_BASE( xParent,xContext, new RangePageBreaks( xParent, xContext, xSheetPageBreak, false ))
224 RangePageBreaks* pPageBreaks =
dynamic_cast< RangePageBreaks*
>(
m_xIndexAccess.get() );
227 return pPageBreaks->Add(
Before );
232uno::Reference< container::XEnumeration >
253 return "ScVbaHPageBreaks";
256uno::Sequence< OUString >
261 "ooo.vba.excel.HPageBreaks"
268 const uno::Reference< uno::XComponentContext >& xContext,
269 const uno::Reference< sheet::XSheetPageBreak >& xSheetPageBreak )
270:
ScVbaVPageBreaks_BASE( xParent, xContext, new RangePageBreaks( xParent, xContext, xSheetPageBreak, true ) )
281 RangePageBreaks* pPageBreaks =
dynamic_cast< RangePageBreaks*
>(
m_xIndexAccess.get() );
284 return pPageBreaks->Add(
Before );
289uno::Reference< container::XEnumeration >
310 return "ScVbaVPageBreaks";
313uno::Sequence< OUString >
318 "ooo.vba.excel.VPageBreaks"
unotools::WeakReference< AnimationNode > mxParent
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual css::uno::Any createCollectionObject(const css::uno::Any &) override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &Before) override
virtual OUString getServiceImplName() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Type SAL_CALL getElementType() override
ScVbaHPageBreaks(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::sheet::XSheetPageBreak > &xSheetPageBreak)
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &Before) override
virtual ~ScVbaVPageBreaks() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &) override
ScVbaVPageBreaks(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::sheet::XSheetPageBreak > &xSheetPageBreak)
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Type const & get()
Sequence< OUString > aServiceNames
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE