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