summaryrefslogtreecommitdiff
path: root/sw/source/ui/vba/vbatables.cxx
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2010-10-06 10:16:50 +0100
committerNoel Power <noel.power@novell.com>2010-10-06 10:16:50 +0100
commit9a3f243c89bd53b0dc06c19bdccaa402c9e32c14 (patch)
tree136e33fe6d405ea1175c45246c8e13385fc28a4b /sw/source/ui/vba/vbatables.cxx
parentc1369970be1d2c0cb19edcac4e1d010635c89730 (diff)
initial commit for vba blob ( not including container_control stuff )
Diffstat (limited to 'sw/source/ui/vba/vbatables.cxx')
-rw-r--r--sw/source/ui/vba/vbatables.cxx93
1 files changed, 92 insertions, 1 deletions
diff --git a/sw/source/ui/vba/vbatables.cxx b/sw/source/ui/vba/vbatables.cxx
index 9a10622400d3..9ca798a6ce6a 100644
--- a/sw/source/ui/vba/vbatables.cxx
+++ b/sw/source/ui/vba/vbatables.cxx
@@ -4,6 +4,9 @@
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/table/XCellRange.hpp>
#include <comphelper/componentcontext.hxx>
using namespace ::ooo::vba;
@@ -26,7 +29,89 @@ uno::Any lcl_createTable( const uno::Reference< XHelperInterface >& xParent, con
return uno::makeAny( xTable );
}
+sal_Bool lcl_isInHeaderFooter( const uno::Reference< text::XTextTable >& xTable )
+{
+ uno::Reference< text::XTextContent > xTextContent( xTable, uno::UNO_QUERY_THROW );
+ uno::Reference< text::XText > xText = xTextContent->getAnchor()->getText();
+ uno::Reference< lang::XServiceInfo > xServiceInfo( xText, uno::UNO_QUERY_THROW );
+ rtl::OUString aImplName = xServiceInfo->getImplementationName();
+ if( aImplName.equalsAscii("SwXHeadFootText") )
+ return sal_True;
+ return sal_False;
+}
+
typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > EnumBase;
+typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XNameAccess > TableCollectionHelper_Base;
+typedef std::vector< uno::Reference< text::XTextTable > > XTextTableVec;
+
+class TableCollectionHelper : public TableCollectionHelper_Base
+{
+ XTextTableVec mxTables;
+ XTextTableVec::iterator cachePos;
+
+public:
+ TableCollectionHelper( const uno::Reference< frame::XModel >& xDocument )
+ {
+ // only count the tables in the body text, not in the header/footer
+ uno::Reference< container::XIndexAccess > xTables = lcl_getTables( xDocument );
+ sal_Int32 nCount = xTables->getCount();
+ for( sal_Int32 i = 0; i < nCount; i++ )
+ {
+ uno::Reference< text::XTextTable > xTable( xTables->getByIndex( i ) , uno::UNO_QUERY_THROW );
+ if( !lcl_isInHeaderFooter( xTable ) )
+ mxTables.push_back( xTable );
+ }
+ cachePos = mxTables.begin();
+ }
+ // XIndexAccess
+ virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
+ {
+ return mxTables.size();
+ }
+ virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
+ {
+ if ( Index < 0 || Index >= getCount() )
+ throw lang::IndexOutOfBoundsException();
+ uno::Reference< text::XTextTable > xTable( mxTables[ Index ], uno::UNO_QUERY_THROW );
+ return uno::makeAny( xTable );
+ }
+ // XElementAccess
+ virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return text::XTextTable::static_type(0); }
+ virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return getCount() > 0 ; }
+ // XNameAcess
+ virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
+ {
+ if ( !hasByName(aName) )
+ throw container::NoSuchElementException();
+ uno::Reference< text::XTextTable > xTable( *cachePos, uno::UNO_QUERY_THROW );
+ return uno::makeAny( xTable );
+ }
+ virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
+ {
+ uno::Sequence< rtl::OUString > sNames( mxTables.size() );
+ rtl::OUString* pString = sNames.getArray();
+ XTextTableVec::iterator it = mxTables.begin();
+ XTextTableVec::iterator it_end = mxTables.end();
+ for ( ; it != it_end; ++it, ++pString )
+ {
+ uno::Reference< container::XNamed > xName( *it, uno::UNO_QUERY_THROW );
+ *pString = xName->getName();
+ }
+ return sNames;
+ }
+ virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
+ {
+ cachePos = mxTables.begin();
+ XTextTableVec::iterator it_end = mxTables.end();
+ for ( ; cachePos != it_end; ++cachePos )
+ {
+ uno::Reference< container::XNamed > xName( *cachePos, uno::UNO_QUERY_THROW );
+ if ( aName.equalsIgnoreAsciiCase( xName->getName() ) )
+ break;
+ }
+ return ( cachePos != it_end );
+ }
+};
class TableEnumerationImpl : public EnumBase
{
@@ -52,7 +137,7 @@ public:
};
-SwVbaTables::SwVbaTables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xDocument ) : SwVbaTables_BASE( xParent, xContext , lcl_getTables( xDocument ) ), mxDocument( xDocument )
+SwVbaTables::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 )
{
}
@@ -85,6 +170,12 @@ SwVbaTables::Add( const uno::Reference< word::XRange >& Range, const uno::Any& N
uno::Reference< text::XTextContent > xContext( xTable, uno::UNO_QUERY_THROW );
xText->insertTextContent( xTextRange, xContext, true );
+
+ // move the current cursor to the first table cell
+ uno::Reference< table::XCellRange > xCellRange( xTable, uno::UNO_QUERY_THROW );
+ uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
+ word::getXTextViewCursor( mxDocument )->gotoRange( xFirstCellText->getStart(), sal_False );
+
uno::Reference< word::XTable > xVBATable( new SwVbaTable( mxParent, mxContext, pVbaRange->getDocument(), xTable ) );
return xVBATable;
}