xref: /trunk/main/svx/source/table/tablecolumn.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <com/sun/star/lang/DisposedException.hpp>
28 
29 #include "tablecolumn.hxx"
30 #include "tableundo.hxx"
31 #include "svx/svdmodel.hxx"
32 #include "svx/svdotable.hxx"
33 
34 // -----------------------------------------------------------------------------
35 
36 using ::rtl::OUString;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::container;
40 using namespace ::com::sun::star::table;
41 using namespace ::com::sun::star::beans;
42 
43 // -----------------------------------------------------------------------------
44 
45 namespace sdr { namespace table {
46 
47 const sal_Int32 Property_Width = 0;
48 const sal_Int32 Property_OptimalWidth = 1;
49 const sal_Int32 Property_IsVisible = 2;
50 const sal_Int32 Property_IsStartOfNewPage = 3;
51 
52 // -----------------------------------------------------------------------------
53 // TableRow
54 // -----------------------------------------------------------------------------
55 
TableColumn(const TableModelRef & xTableModel,sal_Int32 nColumn)56 TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
57 : TableColumnBase( getStaticPropertySetInfo() )
58 , mxTableModel( xTableModel )
59 , mnColumn( nColumn )
60 , mnWidth( 0 )
61 , mbOptimalWidth( sal_True )
62 , mbIsVisible( sal_True )
63 , mbIsStartOfNewPage( sal_False )
64 {
65 }
66 
67 // -----------------------------------------------------------------------------
68 
~TableColumn()69 TableColumn::~TableColumn()
70 {
71 }
72 
73 // -----------------------------------------------------------------------------
74 
dispose()75 void TableColumn::dispose()
76 {
77 	mxTableModel.clear();
78 }
79 
80 // -----------------------------------------------------------------------------
81 
throwIfDisposed() const82 void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
83 {
84 	if( !mxTableModel.is() )
85 		throw DisposedException();
86 }
87 
88 // -----------------------------------------------------------------------------
89 
operator =(const TableColumn & r)90 TableColumn& TableColumn::operator=( const TableColumn& r )
91 {
92 	mnWidth = r.mnWidth;
93 	mbOptimalWidth = r.mbOptimalWidth;
94 	mbIsVisible = r.mbIsVisible;
95 	mbIsStartOfNewPage = r.mbIsStartOfNewPage;
96 
97 	return *this;
98 }
99 
100 // -----------------------------------------------------------------------------
101 // XCellRange
102 // -----------------------------------------------------------------------------
103 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)104 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
105 {
106 	throwIfDisposed();
107 	if( nColumn != 0 )
108 		throw IndexOutOfBoundsException();
109 
110 	return mxTableModel->getCellByPosition( mnColumn, nRow );
111 }
112 
113 // -----------------------------------------------------------------------------
114 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)115 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
116 {
117 	throwIfDisposed();
118 	if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0)  )
119 	{
120 		return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
121 	}
122 	throw IndexOutOfBoundsException();
123 }
124 
125 // -----------------------------------------------------------------------------
126 
getCellRangeByName(const OUString &)127 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
128 {
129 	return Reference< XCellRange >();
130 }
131 
132 // -----------------------------------------------------------------------------
133 // XNamed
134 // -----------------------------------------------------------------------------
135 
getName()136 OUString SAL_CALL TableColumn::getName() throw (RuntimeException)
137 {
138 	return maName;
139 }
140 
141 // -----------------------------------------------------------------------------
142 
setName(const OUString & aName)143 void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException)
144 {
145 	maName = aName;
146 }
147 
148 // -----------------------------------------------------------------------------
149 // XFastPropertySet
150 // -----------------------------------------------------------------------------
151 
setFastPropertyValue(sal_Int32 nHandle,const Any & aValue)152 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
153 {
154 	bool bOk = false;
155 	bool bChange = false;
156 
157 	SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
158 
159 	TableColumnUndo* pUndo = 0;
160 	if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
161 	{
162 		TableColumnRef xThis( this );
163 		pUndo = new TableColumnUndo( xThis );
164 	}
165 
166 	switch( nHandle )
167 	{
168 	case Property_Width:
169 		{
170 			sal_Int32 nWidth = mnWidth;
171 			bOk = aValue >>= nWidth;
172 			if( bOk && (nWidth != mnWidth) )
173 			{
174 				mnWidth = nWidth;
175 				mbOptimalWidth = mnWidth == 0;
176 				bChange = true;
177 			}
178 			break;
179 		}
180 	case Property_OptimalWidth:
181 		{
182 			sal_Bool bOptimalWidth = mbOptimalWidth;
183 			bOk = aValue >>= bOptimalWidth;
184 			if( bOk && (mbOptimalWidth != bOptimalWidth) )
185 			{
186 				mbOptimalWidth = bOptimalWidth;
187 				if( bOptimalWidth )
188 					mnWidth = 0;
189 				bChange = true;
190 			}
191 			break;
192 		}
193 	case Property_IsVisible:
194 		{
195 			sal_Bool bIsVisible = mbIsVisible;
196 			bOk = aValue >>= bIsVisible;
197 			if( bOk && (mbIsVisible != bIsVisible) )
198 			{
199 				mbIsVisible = bIsVisible;
200 				bChange = true;
201 			}
202 			break;
203 		}
204 
205 	case Property_IsStartOfNewPage:
206 		{
207 			sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
208 			bOk = aValue >>= bIsStartOfNewPage;
209 			if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
210 			{
211 				mbIsStartOfNewPage = bIsStartOfNewPage;
212 				bChange = true;
213 			}
214 			break;
215 		}
216 	default:
217 		throw UnknownPropertyException();
218 	}
219 	if( !bOk )
220 		throw IllegalArgumentException();
221 
222 	if( bChange )
223 	{
224 		if( pUndo )
225 		{
226 			pModel->AddUndo( pUndo );
227 			pUndo = 0;
228 		}
229 		mxTableModel->setModified(sal_True);
230 	}
231 
232 	if( pUndo )
233 		delete pUndo;
234 }
235 
236 // -----------------------------------------------------------------------------
237 
getFastPropertyValue(sal_Int32 nHandle)238 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
239 {
240 	switch( nHandle )
241 	{
242 	case Property_Width:			return Any( mnWidth );
243 	case Property_OptimalWidth:		return Any( mbOptimalWidth );
244 	case Property_IsVisible:		return Any( mbIsVisible );
245 	case Property_IsStartOfNewPage:	return Any( mbIsStartOfNewPage );
246 	default:						throw UnknownPropertyException();
247 	}
248 }
249 
250 // -----------------------------------------------------------------------------
251 
getStaticPropertySetInfo()252 rtl::Reference< ::comphelper::FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
253 {
254 	static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo;
255 	if( !xInfo.is() )
256 	{
257         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
258 		if( !xInfo.is() )
259 		{
260 			comphelper::PropertyVector aProperties(6);
261 
262 			aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
263 			aProperties[0].Handle = Property_Width;
264 			aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
265 			aProperties[0].Attributes = 0;
266 
267 			aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalWidth" ) );
268 			aProperties[1].Handle = Property_OptimalWidth;
269 			aProperties[1].Type = ::getBooleanCppuType();
270 			aProperties[1].Attributes = 0;
271 
272 			aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
273 			aProperties[2].Handle = Property_IsVisible;
274 			aProperties[2].Type = ::getBooleanCppuType();
275 			aProperties[2].Attributes = 0;
276 
277 			aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
278 			aProperties[3].Handle = Property_IsStartOfNewPage;
279 			aProperties[3].Type = ::getBooleanCppuType();
280 			aProperties[3].Attributes = 0;
281 
282 			aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
283 			aProperties[4].Handle = Property_Width;
284 			aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
285 			aProperties[4].Attributes = 0;
286 
287 			aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
288 			aProperties[5].Handle = Property_OptimalWidth;
289 			aProperties[5].Type = ::getBooleanCppuType();
290 			aProperties[5].Attributes = 0;
291 
292 			xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) );
293 		}
294 	}
295 
296 	return xInfo;
297 }
298 
299 // -----------------------------------------------------------------------------
300 
301 } }
302