24#include <com/sun/star/text/XTextTable.hpp> 
   25#include <com/sun/star/text/XTextTablesSupplier.hpp> 
   26#include <com/sun/star/text/XTextDocument.hpp> 
   27#include <com/sun/star/lang/XServiceInfo.hpp> 
   28#include <com/sun/star/lang/XMultiServiceFactory.hpp> 
   29#include <com/sun/star/text/XText.hpp> 
   30#include <com/sun/star/table/XCellRange.hpp> 
   37static uno::Reference< container::XIndexAccess > 
lcl_getTables( 
const uno::Reference< frame::XModel >& xDoc )
 
   39    uno::Reference< container::XIndexAccess > xTables;
 
   40    uno::Reference< text::XTextTablesSupplier > xSupp( xDoc, uno::UNO_QUERY );
 
   42        xTables.set( xSupp->getTextTables(), uno::UNO_QUERY_THROW );
 
   46static uno::Any lcl_createTable( 
const uno::Reference< XHelperInterface >& xParent, 
const uno::Reference< uno::XComponentContext >& xContext, 
const uno::Reference< frame::XModel >& xDocument, 
const uno::Any& aSource )
 
   48    uno::Reference< text::XTextTable > xTextTable( aSource, uno::UNO_QUERY_THROW );
 
   49    uno::Reference< text::XTextDocument > xTextDocument( xDocument, uno::UNO_QUERY_THROW );
 
   50    uno::Reference< word::XTable > xTable( 
new SwVbaTable( xParent, xContext, xTextDocument, xTextTable ) );
 
   56    uno::Reference< text::XTextContent > xTextContent( xTable, uno::UNO_QUERY_THROW );
 
   57    uno::Reference< text::XText > xText = xTextContent->getAnchor()->getText();
 
   58    uno::Reference< lang::XServiceInfo > xServiceInfo( xText, uno::UNO_QUERY );
 
   61    OUString aImplName = xServiceInfo->getImplementationName();
 
   62    return aImplName == 
"SwXHeadFootText";
 
   69class TableCollectionHelper : 
public ::cppu::WeakImplHelper< container::XIndexAccess,
 
   70                                                             container::XNameAccess >
 
   73    XTextTableVec::iterator m_cachePos;
 
   76    explicit TableCollectionHelper( 
const uno::Reference< frame::XModel >& xDocument )
 
   79        uno::Reference< container::XIndexAccess > xTables = 
lcl_getTables( xDocument );
 
   80        sal_Int32 
nCount = xTables->getCount();
 
   83            uno::Reference< text::XTextTable > xTable( xTables->getByIndex( 
i ) , uno::UNO_QUERY_THROW );
 
   85                mxTables.push_back( xTable );
 
   87        m_cachePos = mxTables.begin();
 
   90    virtual sal_Int32 SAL_CALL getCount(  )
 override 
   92        return mxTables.size();
 
   94    virtual uno::Any SAL_CALL getByIndex( sal_Int32 
Index )
 override 
   97            throw lang::IndexOutOfBoundsException();
 
   98        uno::Reference< text::XTextTable > xTable( mxTables[ 
Index ], uno::UNO_SET_THROW );
 
  103    virtual sal_Bool SAL_CALL hasElements(  )
 override { 
return getCount() > 0 ; }
 
  105    virtual uno::Any SAL_CALL getByName( 
const OUString& 
aName )
 override 
  107        if ( !hasByName(
aName) )
 
  108            throw container::NoSuchElementException();
 
  109        uno::Reference< text::XTextTable > xTable( *m_cachePos, uno::UNO_SET_THROW );
 
  112    virtual uno::Sequence< OUString > SAL_CALL getElementNames(  )
 override 
  114        uno::Sequence< OUString > sNames( mxTables.size() );
 
  115        OUString* pString = sNames.getArray();
 
  116        for ( 
const auto& rxTable : mxTables )
 
  118            uno::Reference< container::XNamed > xName( rxTable, uno::UNO_QUERY_THROW );
 
  119            *pString = xName->getName();
 
  124    virtual sal_Bool SAL_CALL hasByName( 
const OUString& 
aName )
 override 
  126        m_cachePos = mxTables.begin();
 
  127        XTextTableVec::iterator it_end = mxTables.end();
 
  128        for ( ; m_cachePos != it_end; ++m_cachePos )
 
  130            uno::Reference< container::XNamed > xName( *m_cachePos, uno::UNO_QUERY_THROW );
 
  131            if ( 
aName.equalsIgnoreAsciiCase( xName->getName() ) )
 
  134        return ( m_cachePos != it_end );
 
  138class TableEnumerationImpl : 
public ::cppu::WeakImplHelper< css::container::XEnumeration >
 
  140    uno::Reference< XHelperInterface > 
mxParent;
 
  141    uno::Reference< uno::XComponentContext > 
mxContext;
 
  142    uno::Reference< frame::XModel > mxDocument;
 
  143    uno::Reference< container::XIndexAccess > mxIndexAccess;
 
  144    sal_Int32 mnCurIndex;
 
  146    TableEnumerationImpl(  uno::Reference< XHelperInterface > xParent, uno::Reference< uno::XComponentContext > xContext, uno::Reference< frame::XModel >  xDocument, uno::Reference< container::XIndexAccess >  xIndexAccess ) : 
mxParent(std::move( xParent )), 
mxContext(std::move( xContext )), mxDocument(std::move( xDocument )), mxIndexAccess(std::move( xIndexAccess )), mnCurIndex(0)
 
  149    virtual sal_Bool SAL_CALL hasMoreElements(  )
 override 
  151        return ( mnCurIndex < mxIndexAccess->getCount() );
 
  153    virtual uno::Any SAL_CALL nextElement(  )
 override 
  155        if ( !hasMoreElements() )
 
  156            throw container::NoSuchElementException();
 
  164SwVbaTables::SwVbaTables( 
const uno::Reference< XHelperInterface >& xParent, 
const uno::Reference< uno::XComponentContext > & xContext, 
const uno::Reference< frame::XModel >& xDocument ) : 
SwVbaTables_BASE( xParent, xContext , 
uno::
Reference< container::XIndexAccess >( new TableCollectionHelper( xDocument ) ) ), mxDocument( xDocument )
 
  168uno::Reference< word::XTable > SAL_CALL
 
  175    if ( !( pVbaRange && ( NumRows >>= nRows ) && ( NumColumns >>= nCols ) ) )
 
  176        throw uno::RuntimeException(); 
 
  177    if ( nCols <= 0 || nRows <= 0 )
 
  178        throw uno::RuntimeException(); 
 
  180    uno::Reference< frame::XModel > 
xModel( pVbaRange->
getDocument(), uno::UNO_QUERY_THROW );
 
  181    uno::Reference< lang::XMultiServiceFactory > xMsf( 
xModel, uno::UNO_QUERY_THROW );
 
  182    uno::Reference< text::XTextRange > xTextRange = pVbaRange->
getXTextRange();
 
  184    uno::Reference< text::XTextTable > xTable;
 
  185    xTable.set( xMsf->createInstance(
"com.sun.star.text.TextTable"), uno::UNO_QUERY_THROW );
 
  187    xTable->initialize( nRows, nCols );
 
  188    uno::Reference< text::XText > xText = xTextRange->getText();
 
  189    uno::Reference< text::XTextContent > xContext( xTable, uno::UNO_QUERY_THROW );
 
  191    xText->insertTextContent( xTextRange, xContext, 
true );
 
  194    uno::Reference< table::XCellRange > xCellRange( xTable, uno::UNO_QUERY_THROW );
 
  195    uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
 
  202uno::Reference< container::XEnumeration > SAL_CALL
 
  219    return "SwVbaTables";
 
  229uno::Sequence<OUString>
 
  234        "ooo.vba.word.Tables" 
unotools::WeakReference< AnimationNode > mxParent
 
css::uno::Reference< css::uno::XComponentContext > mxContext
 
css::uno::WeakReference< ov::XHelperInterface > mxParent
 
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
 
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getXTextRange() override
 
const css::uno::Reference< css::text::XTextDocument > & getDocument() const
 
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
 
css::uno::Reference< css::frame::XModel > mxDocument
 
virtual css::uno::Type SAL_CALL getElementType() override
 
virtual OUString getServiceImplName() override
 
virtual css::uno::Reference< ov::word::XTable > SAL_CALL Add(const css::uno::Reference< ::ooo::vba::word::XRange > &Range, const css::uno::Any &NumRows, const css::uno::Any &NumColumns, const css::uno::Any &DefaultTableBehavior, const css::uno::Any &AutoFitBehavior) override
 
virtual css::uno::Sequence< OUString > getServiceNames() override
 
SwVbaTables(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xDocument)
 
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
 
css::uno::Type const & get()
 
Sequence< OUString > aServiceNames
 
uno::Reference< text::XTextViewCursor > getXTextViewCursor(const uno::Reference< frame::XModel > &xModel)
 
Reference< XModel > xModel
 
static uno::Reference< container::XIndexAccess > lcl_getTables(const uno::Reference< frame::XModel > &xDoc)
 
std::vector< uno::Reference< text::XTextTable > > XTextTableVec
 
static bool lcl_isInHeaderFooter(const uno::Reference< text::XTextTable > &xTable)
 
static uno::Any lcl_createTable(const uno::Reference< XHelperInterface > &xParent, const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< frame::XModel > &xDocument, const uno::Any &aSource)