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 "vbaborders.hxx"
29 #include "vbapalette.hxx"
30 #include "vbarows.hxx"
31 #include "vbacolumns.hxx"
32 
33 using namespace ::ooo::vba;
34 using namespace ::com::sun::star;
35 
36 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 )
37 {
38  mxTextTable.set( xTextTable, uno::UNO_SET_THROW );
39 }
40 
41 uno::Reference< word::XRange > SAL_CALL
43 {
44  return new SwVbaRange( mxParent, mxContext, mxTextDocument, mxTextTable->getAnchor() );
45 }
46 
47 void SAL_CALL
49 {
50  uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
51  uno::Reference< frame::XController > xController = xModel->getCurrentController();
52 
53  uno::Reference< text::XTextViewCursorSupplier > xViewCursorSupplier( xController, uno::UNO_QUERY_THROW );
54  uno::Reference< view::XSelectionSupplier > xSelectionSupplier( xController, uno::UNO_QUERY_THROW );
55 
56  // set the view cursor to the start of the table.
57  xSelectionSupplier->select( uno::makeAny( mxTextTable ) );
58 
59  // go to the end of the table and span the view
60  uno::Reference< text::XTextViewCursor > xCursor = xViewCursorSupplier->getViewCursor();
61  xCursor->gotoEnd(true);
62 
63 }
64 
65 void SAL_CALL
67 {
68  uno::Reference< table::XTableRows > xRows( mxTextTable->getRows() );
69  xRows->removeByIndex( 0, xRows->getCount() );
70 }
71 
72 OUString SAL_CALL
74 {
75  uno::Reference< container::XNamed > xNamed( mxTextTable, uno::UNO_QUERY_THROW );
76  return xNamed->getName();
77 }
78 
79 uno::Any SAL_CALL
81 {
82  uno::Reference< table::XCellRange > aCellRange( mxTextTable, uno::UNO_QUERY_THROW );
83  VbaPalette aPalette;
84  uno::Reference< XCollection > xCol( new SwVbaBorders( this, mxContext, aCellRange, aPalette ) );
85  if ( index.hasValue() )
86  return xCol->Item( index, uno::Any() );
87  return uno::makeAny( xCol );
88 }
89 
90 uno::Any SAL_CALL
91 SwVbaTable::Rows( const uno::Any& index )
92 {
93  uno::Reference< table::XTableRows > xTableRows( mxTextTable->getRows(), uno::UNO_SET_THROW );
94  uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, mxTextTable, xTableRows ) );
95  if ( index.hasValue() )
96  return xCol->Item( index, uno::Any() );
97  return uno::makeAny( xCol );
98 }
99 
100 uno::Any SAL_CALL
102 {
103  uno::Reference< table::XTableColumns > xTableColumns( mxTextTable->getColumns(), uno::UNO_SET_THROW );
104  uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, mxTextTable, xTableColumns ) );
105  if ( index.hasValue() )
106  return xCol->Item( index, uno::Any() );
107  return uno::makeAny( xCol );
108 }
109 
110 // XHelperInterface
111 OUString
113 {
114  return "SwVbaTable";
115 }
116 
117 uno::Sequence<OUString>
119 {
120  static uno::Sequence< OUString > const aServiceNames
121  {
122  "ooo.vba.word.Table"
123  };
124  return aServiceNames;
125 }
126 
127 /* 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:36
css::uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbatable.hxx:33
Sequence< OUString > aServiceNames
Reference< XController > xController
css::uno::Reference< css::text::XTextDocument > mxTextDocument
Definition: vbatable.hxx:32
virtual OUString SAL_CALL getName() override
Definition: vbatable.cxx:73
virtual void SAL_CALL Delete() override
Definition: vbatable.cxx:66
virtual css::uno::Reference< ::ooo::vba::word::XRange > SAL_CALL Range() override
Definition: vbatable.cxx:42
virtual css::uno::Any SAL_CALL Rows(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:91
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbatable.cxx:118
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:80
virtual OUString getServiceImplName() override
Definition: vbatable.cxx:112
Reference< XModel > xModel
virtual void SAL_CALL Select() override
Definition: vbatable.cxx:48
virtual css::uno::Any SAL_CALL Columns(const css::uno::Any &aIndex) override
Definition: vbatable.cxx:101