1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include "vbatable.hxx"
23 #include "vbarange.hxx"
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
26 #include <com/sun/star/view/XSelectionSupplier.hpp>
27 #include <com/sun/star/text/XTextTable.hpp>
28 #include <com/sun/star/text/XTextTablesSupplier.hpp>
29 #include <com/sun/star/table/XTableRows.hpp>
30 #include <com/sun/star/container/XNamed.hpp>
31 #include "vbaborders.hxx"
32 #include "vbapalette.hxx"
33
34 using namespace ::ooo::vba;
35 using namespace ::com::sun::star;
36
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)37 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 )
38 {
39 mxTextTable.set( xTextTable, uno::UNO_QUERY_THROW );
40 }
41
42 uno::Reference< word::XRange > SAL_CALL
Range()43 SwVbaTable::Range( ) throw (script::BasicErrorException, uno::RuntimeException)
44 {
45 return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
46 }
47
48 void SAL_CALL
Select()49 SwVbaTable::Select( ) throw (script::BasicErrorException, uno::RuntimeException)
50 {
51 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
52 uno::Reference< frame::XController > xController = xModel->getCurrentController();
53
54 uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( xController, uno::UNO_QUERY_THROW );
55 uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY_THROW );
56
57 // set the view cursor to the start of the table.
58 xSelectionSupplier->select( uno::makeAny( mxTextTable ) );
59
60 // go to the end of the table and span the view
61 uno::Reference< text::XTextViewCursor > xCursor = xViewCursorSupplier->getViewCursor();
62 xCursor->gotoEnd(sal_True);
63
64 }
65
66 void SAL_CALL
Delete()67 SwVbaTable::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
68 {
69 uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
70 xRows->removeByIndex( 0, xRows->getCount() );
71 }
72
73 uno::Reference< word::XRange > SAL_CALL
ConvertToText(const uno::Any &,const uno::Any &)74 SwVbaTable::ConvertToText( const uno::Any& /*Separator*/, const uno::Any& /*NestedTables*/ ) throw (script::BasicErrorException, uno::RuntimeException)
75 {
76 // #FIXME the helper api uses the dreaded dispatch mechanism, holding off
77 // implementation while I look for alternative solution
78 throw uno::RuntimeException();
79 }
80
81 rtl::OUString SAL_CALL
getName()82 SwVbaTable::getName() throw (uno::RuntimeException)
83 {
84 uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
85 return xNamed->getName();
86 }
87
88 uno::Any SAL_CALL
Borders(const uno::Any & index)89 SwVbaTable::Borders( const uno::Any& index ) throw (uno::RuntimeException)
90 {
91 uno::Reference< table::XCellRange > aCellRange( mxTextTable, uno::UNO_QUERY_THROW );
92 VbaPalette aPalette;
93 uno::Reference< XCollection > xCol( new SwVbaBorders( this, mxContext, aCellRange, aPalette ) );
94 if ( index.hasValue() )
95 return xCol->Item( index, uno::Any() );
96 return uno::makeAny( xCol );
97 }
98
99 // XHelperInterface
100 rtl::OUString&
getServiceImplName()101 SwVbaTable::getServiceImplName()
102 {
103 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTable") );
104 return sImplName;
105 }
106
107 uno::Sequence<rtl::OUString>
getServiceNames()108 SwVbaTable::getServiceNames()
109 {
110 static uno::Sequence< rtl::OUString > aServiceNames;
111 if ( aServiceNames.getLength() == 0 )
112 {
113 aServiceNames.realloc( 1 );
114 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Table" ) );
115 }
116 return aServiceNames;
117 }
118
119