Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "vbatable.hxx"
21 : #include "vbarange.hxx"
22 : #include <com/sun/star/frame/XModel.hpp>
23 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
24 : #include <com/sun/star/view/XSelectionSupplier.hpp>
25 : #include <com/sun/star/text/XTextTable.hpp>
26 : #include <com/sun/star/text/XTextTablesSupplier.hpp>
27 : #include <com/sun/star/table/XTableRows.hpp>
28 : #include <com/sun/star/container/XNamed.hpp>
29 : #include "vbaborders.hxx"
30 : #include "vbapalette.hxx"
31 : #include "vbarows.hxx"
32 : #include "vbacolumns.hxx"
33 :
34 : using namespace ::ooo::vba;
35 : using namespace ::com::sun::star;
36 :
37 0 : SwVbaTable::SwVbaTable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& rDocument, const uno::Reference< text::XTextTable >& xTextTable) throw ( uno::RuntimeException ) : SwVbaTable_BASE( rParent, rContext ), mxTextDocument( rDocument )
38 : {
39 0 : mxTextTable.set( xTextTable, uno::UNO_QUERY_THROW );
40 0 : }
41 :
42 : uno::Reference< word::XRange > SAL_CALL
43 0 : SwVbaTable::Range( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
44 : {
45 0 : return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
46 : }
47 :
48 : void SAL_CALL
49 0 : SwVbaTable::Select( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
50 : {
51 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
52 0 : uno::Reference< frame::XController > xController = xModel->getCurrentController();
53 :
54 0 : uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( xController, uno::UNO_QUERY_THROW );
55 0 : uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY_THROW );
56 :
57 : // set the view cursor to the start of the table.
58 0 : xSelectionSupplier->select( uno::makeAny( mxTextTable ) );
59 :
60 : // go to the end of the table and span the view
61 0 : uno::Reference< text::XTextViewCursor > xCursor = xViewCursorSupplier->getViewCursor();
62 0 : xCursor->gotoEnd(sal_True);
63 :
64 0 : }
65 :
66 : void SAL_CALL
67 0 : SwVbaTable::Delete( ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
68 : {
69 0 : uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
70 0 : xRows->removeByIndex( 0, xRows->getCount() );
71 0 : }
72 :
73 : OUString SAL_CALL
74 0 : SwVbaTable::getName() throw (uno::RuntimeException, std::exception)
75 : {
76 0 : uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
77 0 : return xNamed->getName();
78 : }
79 :
80 : uno::Any SAL_CALL
81 0 : SwVbaTable::Borders( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
82 : {
83 0 : uno::Reference< table::XCellRange > aCellRange( mxTextTable, uno::UNO_QUERY_THROW );
84 0 : VbaPalette aPalette;
85 0 : uno::Reference< XCollection > xCol( new SwVbaBorders( this, mxContext, aCellRange, aPalette ) );
86 0 : if ( index.hasValue() )
87 0 : return xCol->Item( index, uno::Any() );
88 0 : return uno::makeAny( xCol );
89 : }
90 :
91 : uno::Any SAL_CALL
92 0 : SwVbaTable::Rows( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
93 : {
94 0 : uno::Reference< table::XTableRows > xTableRows( mxTextTable->getRows(), uno::UNO_QUERY_THROW );
95 0 : uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, mxTextTable, xTableRows ) );
96 0 : if ( index.hasValue() )
97 0 : return xCol->Item( index, uno::Any() );
98 0 : return uno::makeAny( xCol );
99 : }
100 :
101 : uno::Any SAL_CALL
102 0 : SwVbaTable::Columns( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
103 : {
104 0 : uno::Reference< table::XTableColumns > xTableColumns( mxTextTable->getColumns(), uno::UNO_QUERY_THROW );
105 0 : uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, mxTextTable, xTableColumns ) );
106 0 : if ( index.hasValue() )
107 0 : return xCol->Item( index, uno::Any() );
108 0 : return uno::makeAny( xCol );
109 : }
110 :
111 : // XHelperInterface
112 : OUString
113 0 : SwVbaTable::getServiceImplName()
114 : {
115 0 : return OUString("SwVbaTable");
116 : }
117 :
118 : uno::Sequence<OUString>
119 0 : SwVbaTable::getServiceNames()
120 : {
121 0 : static uno::Sequence< OUString > aServiceNames;
122 0 : if ( aServiceNames.getLength() == 0 )
123 : {
124 0 : aServiceNames.realloc( 1 );
125 0 : aServiceNames[ 0 ] = "ooo.vba.word.Table";
126 : }
127 0 : return aServiceNames;
128 : }
129 :
130 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|