xref: /aoo42x/main/svx/source/table/tablecolumns.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <com/sun/star/lang/DisposedException.hpp>
32 
33 #include "tablecolumns.hxx"
34 #include "tablecolumn.hxx"
35 
36 // -----------------------------------------------------------------------------
37 
38 using ::rtl::OUString;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::table;
43 
44 // -----------------------------------------------------------------------------
45 
46 namespace sdr { namespace table {
47 
48 // -----------------------------------------------------------------------------
49 // TableColumns
50 // -----------------------------------------------------------------------------
51 
52 TableColumns::TableColumns( const TableModelRef& xTableModel )
53 : mxTableModel( xTableModel )
54 {
55 }
56 
57 // -----------------------------------------------------------------------------
58 
59 TableColumns::~TableColumns()
60 {
61 	dispose();
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 void TableColumns::dispose()
67 {
68 	mxTableModel.clear();
69 }
70 
71 // -----------------------------------------------------------------------------
72 
73 void TableColumns::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
74 {
75 	if( !mxTableModel.is() )
76 		throw DisposedException();
77 }
78 
79 // -----------------------------------------------------------------------------
80 // XTableRows
81 // -----------------------------------------------------------------------------
82 
83 void SAL_CALL TableColumns::insertByIndex( sal_Int32 nIndex, sal_Int32 nCount ) throw (RuntimeException)
84 {
85 	throwIfDisposed();
86 	mxTableModel->insertColumns( nIndex, nCount );
87 }
88 
89 // -----------------------------------------------------------------------------
90 
91 void SAL_CALL TableColumns::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount ) throw (RuntimeException)
92 {
93 	throwIfDisposed();
94 	mxTableModel->removeColumns( nIndex, nCount );
95 }
96 
97 // -----------------------------------------------------------------------------
98 // XIndexAccess
99 // -----------------------------------------------------------------------------
100 
101 sal_Int32 SAL_CALL TableColumns::getCount() throw (RuntimeException)
102 {
103 	throwIfDisposed();
104 	return mxTableModel->getColumnCount();
105 }
106 
107 // -----------------------------------------------------------------------------
108 
109 Any SAL_CALL TableColumns::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
110 {
111 	throwIfDisposed();
112 
113 	if( ( Index < 0 ) || ( Index >= mxTableModel->getColumnCount() ) )
114 		throw IndexOutOfBoundsException();
115 
116 	return Any( Reference< XCellRange >( mxTableModel->getColumn( Index ).get() ) );
117 }
118 
119 // -----------------------------------------------------------------------------
120 // XElementAccess
121 // -----------------------------------------------------------------------------
122 
123 Type SAL_CALL TableColumns::getElementType() throw (RuntimeException)
124 {
125 	throwIfDisposed();
126 
127 	return XCellRange::static_type();
128 }
129 
130 // -----------------------------------------------------------------------------
131 
132 sal_Bool SAL_CALL TableColumns::hasElements() throw (RuntimeException)
133 {
134 	throwIfDisposed();
135 
136 	return mxTableModel->getColumnCount() != 0;
137 }
138 
139 // -----------------------------------------------------------------------------
140 
141 } }
142