xref: /AOO41X/main/sw/source/ui/vba/vbatable.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 #include "vbatable.hxx"
2 #include "vbarange.hxx"
3 #include <com/sun/star/frame/XModel.hpp>
4 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
5 #include <com/sun/star/view/XSelectionSupplier.hpp>
6 #include <com/sun/star/text/XTextTable.hpp>
7 #include <com/sun/star/text/XTextTablesSupplier.hpp>
8 #include <com/sun/star/table/XTableRows.hpp>
9 #include <com/sun/star/container/XNamed.hpp>
10 #include "vbaborders.hxx"
11 #include "vbapalette.hxx"
12 
13 using namespace ::ooo::vba;
14 using namespace ::com::sun::star;
15 
16 SwVbaTable::SwVbaTable(  const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& rDocument, const  uno::Reference< css::text::XTextTable >& xTextTable) throw ( uno::RuntimeException ) : SwVbaTable_BASE( rParent, rContext ), mxTextDocument( rDocument )
17 {
18     mxTextTable.set( xTextTable, uno::UNO_QUERY_THROW );
19 }
20 
21 uno::Reference< word::XRange > SAL_CALL
22 SwVbaTable::Range(  ) throw (script::BasicErrorException, uno::RuntimeException)
23 {
24     return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
25 }
26 
27 void SAL_CALL
28 SwVbaTable::Select(  ) throw (script::BasicErrorException, uno::RuntimeException)
29 {
30     uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
31     uno::Reference< frame::XController > xController = xModel->getCurrentController();
32 
33     uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( xController, uno::UNO_QUERY_THROW );
34     uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY_THROW );
35 
36     // set the view cursor to the start of the table.
37     xSelectionSupplier->select( uno::makeAny( mxTextTable ) );
38 
39     // go to the end of the table and span the view
40     uno::Reference< text::XTextViewCursor > xCursor = xViewCursorSupplier->getViewCursor();
41     xCursor->gotoEnd(sal_True);
42 
43 }
44 
45 void SAL_CALL
46 SwVbaTable::Delete(  ) throw (script::BasicErrorException, uno::RuntimeException)
47 {
48     uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
49     xRows->removeByIndex( 0, xRows->getCount() );
50 }
51 
52 uno::Reference< word::XRange > SAL_CALL
53 SwVbaTable::ConvertToText( const uno::Any& /*Separator*/, const uno::Any& /*NestedTables*/ ) throw (script::BasicErrorException, uno::RuntimeException)
54 {
55     // #FIXME the helper api uses the dreaded dispatch mechanism, holding off
56     // implementation while I look for alternative solution
57     throw uno::RuntimeException();
58 }
59 
60 rtl::OUString SAL_CALL
61 SwVbaTable::getName() throw (uno::RuntimeException)
62 {
63     uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
64     return xNamed->getName();
65 }
66 
67 uno::Any SAL_CALL
68 SwVbaTable::Borders( const uno::Any& index ) throw (uno::RuntimeException)
69 {
70     uno::Reference< table::XCellRange > aCellRange( mxTextTable, uno::UNO_QUERY_THROW );
71     VbaPalette aPalette;
72     uno::Reference< XCollection > xCol( new SwVbaBorders( this, mxContext, aCellRange, aPalette ) );
73     if ( index.hasValue() )
74         return xCol->Item( index, uno::Any() );
75     return uno::makeAny( xCol );
76 }
77 
78 // XHelperInterface
79 rtl::OUString&
80 SwVbaTable::getServiceImplName()
81 {
82     static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTable") );
83     return sImplName;
84 }
85 
86 uno::Sequence<rtl::OUString>
87 SwVbaTable::getServiceNames()
88 {
89     static uno::Sequence< rtl::OUString > aServiceNames;
90     if ( aServiceNames.getLength() == 0 )
91     {
92         aServiceNames.realloc( 1 );
93         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Table" ) );
94     }
95     return aServiceNames;
96 }
97 
98