android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbatable.cxx
blob25e370a1c5050dc2a60a01282f10c2e85422be0d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
37 #include <tools/UnitConversion.hxx>
39 #include <sal/log.hxx>
41 using namespace ::ooo::vba;
42 using namespace ::com::sun::star;
44 SwVbaTable::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 ))
46 mxTextTable.set( xTextTable, uno::UNO_SET_THROW );
49 uno::Reference< word::XRange > SAL_CALL
50 SwVbaTable::Range( )
52 return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
55 void SAL_CALL
56 SwVbaTable::Select( )
58 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
59 uno::Reference< frame::XController > xController = xModel->getCurrentController();
61 uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( xController, uno::UNO_QUERY_THROW );
62 uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY_THROW );
64 // set the view cursor to the start of the table.
65 xSelectionSupplier->select( uno::Any( mxTextTable ) );
67 // go to the end of the table and span the view
68 uno::Reference< text::XTextViewCursor > xCursor = xViewCursorSupplier->getViewCursor();
69 xCursor->gotoEnd(true);
73 void SAL_CALL
74 SwVbaTable::Delete( )
76 uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
77 xRows->removeByIndex( 0, xRows->getCount() );
80 OUString SAL_CALL
81 SwVbaTable::getName( )
83 uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
84 return xNamed->getName();
87 uno::Any SAL_CALL
88 SwVbaTable::Borders( const uno::Any& index )
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 );
98 double SAL_CALL
99 SwVbaTable::getBottomPadding()
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);
107 void SAL_CALL
108 SwVbaTable::setBottomPadding( double fValue )
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 ) );
117 double SAL_CALL
118 SwVbaTable::getLeftPadding()
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);
126 void SAL_CALL
127 SwVbaTable::setLeftPadding( double fValue )
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 ) );
136 double SAL_CALL
137 SwVbaTable::getRightPadding()
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);
145 void SAL_CALL
146 SwVbaTable::setRightPadding( double fValue )
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 ) );
155 double SAL_CALL
156 SwVbaTable::getTopPadding()
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);
164 void SAL_CALL
165 SwVbaTable::setTopPadding( double fValue )
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 ) );
174 uno::Any SAL_CALL
175 SwVbaTable::Rows( const uno::Any& index )
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 );
184 uno::Any SAL_CALL
185 SwVbaTable::Columns( const uno::Any& index )
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 );
194 // XHelperInterface
195 OUString
196 SwVbaTable::getServiceImplName()
198 return "SwVbaTable";
201 uno::Sequence<OUString>
202 SwVbaTable::getServiceNames()
204 static uno::Sequence< OUString > const aServiceNames
206 "ooo.vba.word.Table"
208 return aServiceNames;
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */