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/table/XTableRows.hpp>
27#include <com/sun/star/container/XNamed.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/table/TableBorderDistances.hpp>
30#include <utility>
31#include "vbaborders.hxx"
32#include "vbapalette.hxx"
33#include "vbarows.hxx"
34#include "vbacolumns.hxx"
35#include "vbaapplication.hxx"
36
38
39#include <sal/log.hxx>
40
41using namespace ::ooo::vba;
42using namespace ::com::sun::star;
43
44SwVbaTable::SwVbaTable( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, uno::Reference< text::XTextDocument > xDocument, const uno::Reference< text::XTextTable >& xTextTable) : SwVbaTable_BASE( rParent, rContext ), mxTextDocument(std::move( xDocument ))
45{
46 mxTextTable.set( xTextTable, uno::UNO_SET_THROW );
47}
48
49uno::Reference< word::XRange > SAL_CALL
51{
52 return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
53}
54
55void SAL_CALL
57{
58 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
59 uno::Reference< frame::XController > xController = xModel->getCurrentController();
60
61 uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( xController, uno::UNO_QUERY_THROW );
62 uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY_THROW );
63
64 // set the view cursor to the start of the table.
65 xSelectionSupplier->select( uno::Any( mxTextTable ) );
66
67 // go to the end of the table and span the view
68 uno::Reference< text::XTextViewCursor > xCursor = xViewCursorSupplier->getViewCursor();
69 xCursor->gotoEnd(true);
70
71}
72
73void SAL_CALL
75{
76 uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
77 xRows->removeByIndex( 0, xRows->getCount() );
78}
79
80OUString SAL_CALL
82{
83 uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
84 return xNamed->getName();
85}
86
87uno::Any SAL_CALL
89{
90 uno::Reference< table::XCellRange > aCellRange( mxTextTable, uno::UNO_QUERY_THROW );
91 VbaPalette aPalette;
92 uno::Reference< XCollection > xCol( new SwVbaBorders( this, mxContext, aCellRange, aPalette ) );
93 if ( index.hasValue() )
94 return xCol->Item( index, uno::Any() );
95 return uno::Any( xCol );
96}
97
98double SAL_CALL
100{
101 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
102 table::TableBorderDistances aTableBorderDistances;
103 xPropertySet->getPropertyValue("TableBorderDistances") >>= aTableBorderDistances;
104 return convertMm100ToPoint(aTableBorderDistances.BottomDistance);
105}
106
107void SAL_CALL
109{
110 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
111 table::TableBorderDistances aTableBorderDistances;
112 aTableBorderDistances.IsBottomDistanceValid = true;
113 aTableBorderDistances.BottomDistance = convertPointToMm100(fValue);
114 xPropertySet->setPropertyValue( "TableBorderDistances", uno::Any( aTableBorderDistances ) );
115}
116
117double SAL_CALL
119{
120 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
121 table::TableBorderDistances aTableBorderDistances;
122 xPropertySet->getPropertyValue("TableBorderDistances") >>= aTableBorderDistances;
123 return convertMm100ToPoint(aTableBorderDistances.LeftDistance);
124}
125
126void SAL_CALL
128{
129 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
130 table::TableBorderDistances aTableBorderDistances;
131 aTableBorderDistances.IsLeftDistanceValid = true;
132 aTableBorderDistances.LeftDistance = convertPointToMm100(fValue);
133 xPropertySet->setPropertyValue( "TableBorderDistances", uno::Any( aTableBorderDistances ) );
134}
135
136double SAL_CALL
138{
139 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
140 table::TableBorderDistances aTableBorderDistances;
141 xPropertySet->getPropertyValue("TableBorderDistances") >>= aTableBorderDistances;
142 return convertMm100ToPoint(aTableBorderDistances.RightDistance);
143}
144
145void SAL_CALL
147{
148 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
149 table::TableBorderDistances aTableBorderDistances;
150 aTableBorderDistances.IsRightDistanceValid = true;
151 aTableBorderDistances.RightDistance = convertPointToMm100(fValue);
152 xPropertySet->setPropertyValue( "TableBorderDistances", uno::Any( aTableBorderDistances ) );
153}
154
155double SAL_CALL
157{
158 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
159 table::TableBorderDistances aTableBorderDistances;
160 xPropertySet->getPropertyValue("TableBorderDistances") >>= aTableBorderDistances;
161 return convertMm100ToPoint(aTableBorderDistances.TopDistance);
162}
163
164void SAL_CALL
166{
167 uno::Reference< beans::XPropertySet > xPropertySet( mxTextTable, uno::UNO_QUERY_THROW);
168 table::TableBorderDistances aTableBorderDistances;
169 aTableBorderDistances.IsTopDistanceValid = true;
170 aTableBorderDistances.TopDistance = convertPointToMm100(fValue);
171 xPropertySet->setPropertyValue( "TableBorderDistances", uno::Any( aTableBorderDistances ) );
172}
173
174uno::Any SAL_CALL
176{
177 uno::Reference< table::XTableRows > xTableRows( mxTextTable->getRows(), uno::UNO_SET_THROW );
178 uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, mxTextTable, xTableRows ) );
179 if ( index.hasValue() )
180 return xCol->Item( index, uno::Any() );
181 return uno::Any( xCol );
182}
183
184uno::Any SAL_CALL
186{
187 uno::Reference< table::XTableColumns > xTableColumns( mxTextTable->getColumns(), uno::UNO_SET_THROW );
188 uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, mxTextTable, xTableColumns ) );
189 if ( index.hasValue() )
190 return xCol->Item( index, uno::Any() );
191 return uno::Any( xCol );
192}
193
194// XHelperInterface
195OUString
197{
198 return "SwVbaTable";
199}
200
201uno::Sequence<OUString>
203{
204 static uno::Sequence< OUString > const aServiceNames
205 {
206 "ooo.vba.word.Table"
207 };
208 return aServiceNames;
209}
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr auto convertPointToMm100(N n)
constexpr auto convertMm100ToPoint(N n)
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::WeakReference< ov::XHelperInterface > mxParent
virtual double SAL_CALL getBottomPadding() override
Definition: vbatable.cxx:99
virtual css::uno::Any SAL_CALL Borders(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:88
SwVbaTable(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, css::uno::Reference< css::text::XTextDocument > xDocument, const css::uno::Reference< css::text::XTextTable > &xTextTable)
Definition: vbatable.cxx:44
virtual void SAL_CALL Select() override
Definition: vbatable.cxx:56
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbatable.cxx:202
virtual void SAL_CALL setTopPadding(double fValue) override
Definition: vbatable.cxx:165
virtual double SAL_CALL getRightPadding() override
Definition: vbatable.cxx:137
virtual css::uno::Any SAL_CALL Columns(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:185
virtual void SAL_CALL Delete() override
Definition: vbatable.cxx:74
css::uno::Reference< css::text::XTextDocument > mxTextDocument
Definition: vbatable.hxx:32
virtual double SAL_CALL getTopPadding() override
Definition: vbatable.cxx:156
virtual OUString SAL_CALL getName() override
Definition: vbatable.cxx:81
virtual void SAL_CALL setLeftPadding(double fValue) override
Definition: vbatable.cxx:127
virtual css::uno::Reference< ::ooo::vba::word::XRange > SAL_CALL Range() override
Definition: vbatable.cxx:50
virtual void SAL_CALL setBottomPadding(double fValue) override
Definition: vbatable.cxx:108
virtual css::uno::Any SAL_CALL Rows(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:175
virtual double SAL_CALL getLeftPadding() override
Definition: vbatable.cxx:118
virtual void SAL_CALL setRightPadding(double fValue) override
Definition: vbatable.cxx:146
virtual OUString getServiceImplName() override
Definition: vbatable.cxx:196
css::uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbatable.hxx:33
Sequence< OUString > aServiceNames
index
Reference< XController > xController
Reference< XModel > xModel