LibreOffice Module sw (master)  1
vbatable.cxx
Go to the documentation of this file.
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 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) : SwVbaTable_BASE( rParent, rContext ), mxTextDocument( rDocument )
38 {
39  mxTextTable.set( xTextTable, uno::UNO_SET_THROW );
40 }
41 
42 uno::Reference< word::XRange > SAL_CALL
44 {
45  return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
46 }
47 
48 void SAL_CALL
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(true);
63 
64 }
65 
66 void SAL_CALL
68 {
69  uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
70  xRows->removeByIndex( 0, xRows->getCount() );
71 }
72 
73 OUString SAL_CALL
75 {
76  uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
77  return xNamed->getName();
78 }
79 
80 uno::Any SAL_CALL
82 {
83  uno::Reference< table::XCellRange > aCellRange( mxTextTable, uno::UNO_QUERY_THROW );
84  VbaPalette aPalette;
85  uno::Reference< XCollection > xCol( new SwVbaBorders( this, mxContext, aCellRange, aPalette ) );
86  if ( index.hasValue() )
87  return xCol->Item( index, uno::Any() );
88  return uno::makeAny( xCol );
89 }
90 
91 uno::Any SAL_CALL
92 SwVbaTable::Rows( const uno::Any& index )
93 {
94  uno::Reference< table::XTableRows > xTableRows( mxTextTable->getRows(), uno::UNO_SET_THROW );
95  uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, mxTextTable, xTableRows ) );
96  if ( index.hasValue() )
97  return xCol->Item( index, uno::Any() );
98  return uno::makeAny( xCol );
99 }
100 
101 uno::Any SAL_CALL
103 {
104  uno::Reference< table::XTableColumns > xTableColumns( mxTextTable->getColumns(), uno::UNO_SET_THROW );
105  uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, mxTextTable, xTableColumns ) );
106  if ( index.hasValue() )
107  return xCol->Item( index, uno::Any() );
108  return uno::makeAny( xCol );
109 }
110 
111 // XHelperInterface
112 OUString
114 {
115  return "SwVbaTable";
116 }
117 
118 uno::Sequence<OUString>
120 {
121  static uno::Sequence< OUString > const aServiceNames
122  {
123  "ooo.vba.word.Table"
124  };
125  return aServiceNames;
126 }
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool hasValue()
SwVbaTable(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::text::XTextDocument > &rDocument, const css::uno::Reference< css::text::XTextTable > &xTextTable)
Definition: vbatable.cxx:37
css::uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbatable.hxx:33
Reference< XController > xController
css::uno::Reference< css::text::XTextDocument > mxTextDocument
Definition: vbatable.hxx:32
virtual OUString SAL_CALL getName() override
Definition: vbatable.cxx:74
virtual void SAL_CALL Delete() override
Definition: vbatable.cxx:67
virtual css::uno::Reference< ::ooo::vba::word::XRange > SAL_CALL Range() override
Definition: vbatable.cxx:43
virtual css::uno::Any SAL_CALL Rows(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:92
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbatable.cxx:119
css::uno::WeakReference< ov::XHelperInterface > mxParent
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Any SAL_CALL Borders(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:81
virtual OUString getServiceImplName() override
Definition: vbatable.cxx:113
Reference< XModel > xModel
virtual void SAL_CALL Select() override
Definition: vbatable.cxx:49
virtual css::uno::Any SAL_CALL Columns(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:102