xref: /trunk/main/svx/source/table/tablecolumn.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "tablecolumn.hxx"
34 #include "tableundo.hxx"
35 #include "svx/svdmodel.hxx"
36 #include "svx/svdotable.hxx"
37 
38 // -----------------------------------------------------------------------------
39 
40 using ::rtl::OUString;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::table;
45 using namespace ::com::sun::star::beans;
46 
47 // -----------------------------------------------------------------------------
48 
49 namespace sdr { namespace table {
50 
51 const sal_Int32 Property_Width = 0;
52 const sal_Int32 Property_OptimalWidth = 1;
53 const sal_Int32 Property_IsVisible = 2;
54 const sal_Int32 Property_IsStartOfNewPage = 3;
55 
56 // -----------------------------------------------------------------------------
57 // TableRow
58 // -----------------------------------------------------------------------------
59 
60 TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
61 : TableColumnBase( getStaticPropertySetInfo() )
62 , mxTableModel( xTableModel )
63 , mnColumn( nColumn )
64 , mnWidth( 0 )
65 , mbOptimalWidth( sal_True )
66 , mbIsVisible( sal_True )
67 , mbIsStartOfNewPage( sal_False )
68 {
69 }
70 
71 // -----------------------------------------------------------------------------
72 
73 TableColumn::~TableColumn()
74 {
75 }
76 
77 // -----------------------------------------------------------------------------
78 
79 void TableColumn::dispose()
80 {
81     mxTableModel.clear();
82 }
83 
84 // -----------------------------------------------------------------------------
85 
86 void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
87 {
88     if( !mxTableModel.is() )
89         throw DisposedException();
90 }
91 
92 // -----------------------------------------------------------------------------
93 
94 TableColumn& TableColumn::operator=( const TableColumn& r )
95 {
96     mnWidth = r.mnWidth;
97     mbOptimalWidth = r.mbOptimalWidth;
98     mbIsVisible = r.mbIsVisible;
99     mbIsStartOfNewPage = r.mbIsStartOfNewPage;
100 
101     return *this;
102 }
103 
104 // -----------------------------------------------------------------------------
105 // XCellRange
106 // -----------------------------------------------------------------------------
107 
108 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
109 {
110     throwIfDisposed();
111     if( nColumn != 0 )
112         throw IndexOutOfBoundsException();
113 
114     return mxTableModel->getCellByPosition( mnColumn, nRow );
115 }
116 
117 // -----------------------------------------------------------------------------
118 
119 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
120 {
121     throwIfDisposed();
122     if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0)  )
123     {
124         return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
125     }
126     throw IndexOutOfBoundsException();
127 }
128 
129 // -----------------------------------------------------------------------------
130 
131 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
132 {
133     return Reference< XCellRange >();
134 }
135 
136 // -----------------------------------------------------------------------------
137 // XNamed
138 // -----------------------------------------------------------------------------
139 
140 OUString SAL_CALL TableColumn::getName() throw (RuntimeException)
141 {
142     return maName;
143 }
144 
145 // -----------------------------------------------------------------------------
146 
147 void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException)
148 {
149     maName = aName;
150 }
151 
152 // -----------------------------------------------------------------------------
153 // XFastPropertySet
154 // -----------------------------------------------------------------------------
155 
156 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
157 {
158     bool bOk = false;
159     bool bChange = false;
160 
161     SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
162 
163     TableColumnUndo* pUndo = 0;
164     if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
165     {
166         TableColumnRef xThis( this );
167         pUndo = new TableColumnUndo( xThis );
168     }
169 
170     switch( nHandle )
171     {
172     case Property_Width:
173         {
174             sal_Int32 nWidth = mnWidth;
175             bOk = aValue >>= nWidth;
176             if( bOk && (nWidth != mnWidth) )
177             {
178                 mnWidth = nWidth;
179                 mbOptimalWidth = mnWidth == 0;
180                 bChange = true;
181             }
182             break;
183         }
184     case Property_OptimalWidth:
185         {
186             sal_Bool bOptimalWidth = mbOptimalWidth;
187             bOk = aValue >>= bOptimalWidth;
188             if( bOk && (mbOptimalWidth != bOptimalWidth) )
189             {
190                 mbOptimalWidth = bOptimalWidth;
191                 if( bOptimalWidth )
192                     mnWidth = 0;
193                 bChange = true;
194             }
195             break;
196         }
197     case Property_IsVisible:
198         {
199             sal_Bool bIsVisible = mbIsVisible;
200             bOk = aValue >>= bIsVisible;
201             if( bOk && (mbIsVisible != bIsVisible) )
202             {
203                 mbIsVisible = bIsVisible;
204                 bChange = true;
205             }
206             break;
207         }
208 
209     case Property_IsStartOfNewPage:
210         {
211             sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
212             bOk = aValue >>= bIsStartOfNewPage;
213             if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
214             {
215                 mbIsStartOfNewPage = bIsStartOfNewPage;
216                 bChange = true;
217             }
218             break;
219         }
220     default:
221         throw UnknownPropertyException();
222     }
223     if( !bOk )
224         throw IllegalArgumentException();
225 
226     if( bChange )
227     {
228         if( pUndo )
229         {
230             pModel->AddUndo( pUndo );
231             pUndo = 0;
232         }
233         mxTableModel->setModified(sal_True);
234     }
235 
236     if( pUndo )
237         delete pUndo;
238 }
239 
240 // -----------------------------------------------------------------------------
241 
242 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
243 {
244     switch( nHandle )
245     {
246     case Property_Width:            return Any( mnWidth );
247     case Property_OptimalWidth:     return Any( mbOptimalWidth );
248     case Property_IsVisible:        return Any( mbIsVisible );
249     case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
250     default:                        throw UnknownPropertyException();
251     }
252 }
253 
254 // -----------------------------------------------------------------------------
255 
256 rtl::Reference< ::comphelper::FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
257 {
258     static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo;
259     if( !xInfo.is() )
260     {
261         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
262         if( !xInfo.is() )
263         {
264             comphelper::PropertyVector aProperties(6);
265 
266             aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
267             aProperties[0].Handle = Property_Width;
268             aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
269             aProperties[0].Attributes = 0;
270 
271             aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalWidth" ) );
272             aProperties[1].Handle = Property_OptimalWidth;
273             aProperties[1].Type = ::getBooleanCppuType();
274             aProperties[1].Attributes = 0;
275 
276             aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
277             aProperties[2].Handle = Property_IsVisible;
278             aProperties[2].Type = ::getBooleanCppuType();
279             aProperties[2].Attributes = 0;
280 
281             aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
282             aProperties[3].Handle = Property_IsStartOfNewPage;
283             aProperties[3].Type = ::getBooleanCppuType();
284             aProperties[3].Attributes = 0;
285 
286             aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
287             aProperties[4].Handle = Property_Width;
288             aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
289             aProperties[4].Attributes = 0;
290 
291             aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
292             aProperties[5].Handle = Property_OptimalWidth;
293             aProperties[5].Type = ::getBooleanCppuType();
294             aProperties[5].Attributes = 0;
295 
296             xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) );
297         }
298     }
299 
300     return xInfo;
301 }
302 
303 // -----------------------------------------------------------------------------
304 
305 } }
306