Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "unogridcolumnfacade.hxx"
30 : : #include "unocontroltablemodel.hxx"
31 : :
32 : : #include "svtools/table/defaultinputhandler.hxx"
33 : : #include "svtools/table/gridtablerenderer.hxx"
34 : : #include "svtools/table/tablecontrol.hxx"
35 : :
36 : : #include <com/sun/star/awt/grid/XGridColumn.hpp>
37 : : #include <com/sun/star/view/SelectionType.hpp>
38 : : #include <com/sun/star/awt/grid/XGridColumnListener.hpp>
39 : :
40 : : #include <comphelper/stlunosequence.hxx>
41 : : #include <tools/debug.hxx>
42 : : #include <tools/diagnose_ex.h>
43 : : #include <vcl/svapp.hxx>
44 : : #include <osl/mutex.hxx>
45 : :
46 : : // .....................................................................................................................
47 : : namespace svt { namespace table
48 : : {
49 : : // .....................................................................................................................
50 : :
51 : : /** === begin UNO using === **/
52 : : using ::com::sun::star::uno::Reference;
53 : : using ::com::sun::star::uno::RuntimeException;
54 : : using ::com::sun::star::uno::Sequence;
55 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
56 : : using ::com::sun::star::uno::UNO_QUERY;
57 : : using ::com::sun::star::awt::grid::XGridColumn;
58 : : using ::com::sun::star::uno::XInterface;
59 : : using ::com::sun::star::uno::Exception;
60 : : using ::com::sun::star::awt::grid::XGridColumnListener;
61 : : using ::com::sun::star::lang::EventObject;
62 : : using ::com::sun::star::awt::grid::GridColumnEvent;
63 : : using ::com::sun::star::uno::Any;
64 : : using ::com::sun::star::style::HorizontalAlignment_LEFT;
65 : : using ::com::sun::star::style::HorizontalAlignment;
66 : : /** === end UNO using === **/
67 : :
68 : : //------------------------------------------------------------------------------------------------------------------
69 : : namespace
70 : : {
71 : : template< class ATTRIBUTE_TYPE >
72 : 0 : void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( ATTRIBUTE_TYPE ),
73 : : ATTRIBUTE_TYPE i_value )
74 : : {
75 : : try
76 : : {
77 [ # # ][ # # ]: 0 : (i_column.get()->*i_setter) ( i_value );
[ # # ][ # # ]
[ # # ][ # # ]
78 : : }
79 : 0 : catch( const Exception& )
80 : : {
81 : : DBG_UNHANDLED_EXCEPTION();
82 : : }
83 [ # # ][ # # ]: 0 : }
[ # # ]
84 : :
85 : : template< class ATTRIBUTE_TYPE >
86 : 0 : ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() )
87 : : {
88 : 0 : ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE();
89 : : try
90 : : {
91 [ # # ][ # # ]: 0 : value = (i_column.get()->*i_getter)();
[ # # ][ # # ]
[ # # ][ # # ]
92 : : }
93 : 0 : catch( const Exception& )
94 : : {
95 : : DBG_UNHANDLED_EXCEPTION();
96 : : }
97 [ # # ][ # # ]: 0 : return value;
[ # # ]
98 : : }
99 : : }
100 : :
101 : : //==================================================================================================================
102 : : //= ColumnChangeMultiplexer
103 : : //==================================================================================================================
104 : : typedef ::cppu::WeakImplHelper1 < XGridColumnListener
105 : : > ColumnChangeMultiplexer_Base;
106 : : class ColumnChangeMultiplexer :public ColumnChangeMultiplexer_Base
107 : : ,public ::boost::noncopyable
108 : : {
109 : : public:
110 : : ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl );
111 : :
112 : : void dispose();
113 : :
114 : : protected:
115 : : ~ColumnChangeMultiplexer();
116 : :
117 : : // XGridColumnListener
118 : : virtual void SAL_CALL columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException);
119 : :
120 : : // XEventListener
121 : : virtual void SAL_CALL disposing( const EventObject& i_event ) throw (RuntimeException);
122 : :
123 : : private:
124 : : UnoGridColumnFacade* m_pColumnImplementation;
125 : : };
126 : :
127 : : //------------------------------------------------------------------------------------------------------------------
128 : 0 : ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl )
129 : 0 : :m_pColumnImplementation( &i_colImpl )
130 : : {
131 : 0 : }
132 : :
133 : : //------------------------------------------------------------------------------------------------------------------
134 : 0 : ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
135 : : {
136 [ # # ]: 0 : }
137 : :
138 : : //------------------------------------------------------------------------------------------------------------------
139 : 0 : void ColumnChangeMultiplexer::dispose()
140 : : {
141 : : DBG_TESTSOLARMUTEX();
142 : 0 : m_pColumnImplementation = NULL;
143 : 0 : }
144 : :
145 : : //------------------------------------------------------------------------------------------------------------------
146 : 0 : void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException)
147 : : {
148 [ # # ]: 0 : if ( i_event.AttributeName == "DataColumnIndex" )
149 : : {
150 [ # # ]: 0 : SolarMutexGuard aGuard;
151 [ # # ]: 0 : if ( m_pColumnImplementation != NULL )
152 [ # # ]: 0 : m_pColumnImplementation->dataColumnIndexChanged();
153 [ # # ]: 0 : return;
154 : : }
155 : :
156 : 0 : ColumnAttributeGroup nChangedAttributes( COL_ATTRS_NONE );
157 : :
158 [ # # ]: 0 : if ( i_event.AttributeName == "HorizontalAlign" )
159 : 0 : nChangedAttributes |= COL_ATTRS_APPEARANCE;
160 : :
161 [ # # # # : 0 : if ( i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ColumnWidth"))
# # # # #
# # # ]
[ # # ]
162 : 0 : || i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MaxWidth"))
163 : 0 : || i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MinWidth"))
164 : 0 : || i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PreferredWidth"))
165 : 0 : || i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Resizeable"))
166 : 0 : || i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Flexibility"))
167 : : )
168 : 0 : nChangedAttributes |= COL_ATTRS_WIDTH;
169 : :
170 : : OSL_ENSURE( nChangedAttributes != COL_ATTRS_NONE,
171 : : "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
172 : :
173 [ # # ]: 0 : SolarMutexGuard aGuard;
174 [ # # ]: 0 : if ( m_pColumnImplementation != NULL )
175 [ # # ][ # # ]: 0 : m_pColumnImplementation->columnChanged( nChangedAttributes );
176 : : }
177 : :
178 : : //------------------------------------------------------------------------------------------------------------------
179 : 0 : void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& i_event ) throw (RuntimeException)
180 : : {
181 : : OSL_UNUSED( i_event );
182 : 0 : }
183 : :
184 : : //==================================================================================================================
185 : : //= UnoGridColumnFacade
186 : : //==================================================================================================================
187 : : //------------------------------------------------------------------------------------------------------------------
188 : 0 : UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn )
189 : : :m_pOwner( &i_owner )
190 : : ,m_nDataColumnIndex( -1 )
191 : : ,m_xGridColumn( i_gridColumn, UNO_QUERY_THROW )
192 [ # # ][ # # ]: 0 : ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
193 : : {
194 [ # # ][ # # ]: 0 : m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer.get() );
[ # # ][ # # ]
195 [ # # ]: 0 : impl_updateDataColumnIndex_nothrow();
196 : 0 : }
197 : :
198 : : //------------------------------------------------------------------------------------------------------------------
199 : 0 : UnoGridColumnFacade::~UnoGridColumnFacade()
200 : : {
201 [ # # ]: 0 : }
202 : :
203 : : //------------------------------------------------------------------------------------------------------------------
204 : 0 : void UnoGridColumnFacade::dispose()
205 : : {
206 : : DBG_TESTSOLARMUTEX();
207 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_pOwner != NULL, "UnoGridColumnFacade::dispose: already disposed!" );
208 : :
209 [ # # ][ # # ]: 0 : m_xGridColumn->removeGridColumnListener( m_pChangeMultiplexer.get() );
210 : 0 : m_pChangeMultiplexer->dispose();
211 : 0 : m_pChangeMultiplexer.clear();
212 : 0 : m_xGridColumn.clear();
213 : 0 : m_pOwner = NULL;
214 : : }
215 : :
216 : : //------------------------------------------------------------------------------------------------------------------
217 : 0 : void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow()
218 : : {
219 : 0 : m_nDataColumnIndex = -1;
220 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
221 : : try
222 : : {
223 [ # # ][ # # ]: 0 : m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex();
224 : : }
225 : 0 : catch( const Exception& )
226 : : {
227 : : DBG_UNHANDLED_EXCEPTION();
228 : : }
229 : : }
230 : :
231 : : //------------------------------------------------------------------------------------------------------------------
232 : 0 : void UnoGridColumnFacade::dataColumnIndexChanged()
233 : : {
234 : : DBG_TESTSOLARMUTEX();
235 : 0 : impl_updateDataColumnIndex_nothrow();
236 [ # # ]: 0 : if ( m_pOwner != NULL )
237 : 0 : m_pOwner->notifyAllDataChanged();
238 : 0 : }
239 : :
240 : : //------------------------------------------------------------------------------------------------------------------
241 : 0 : void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup const i_attributeGroup )
242 : : {
243 : : DBG_TESTSOLARMUTEX();
244 [ # # ]: 0 : if ( m_pOwner != NULL )
245 : 0 : m_pOwner->notifyColumnChange( m_pOwner->getColumnPos( *this ), i_attributeGroup );
246 : 0 : }
247 : :
248 : : //------------------------------------------------------------------------------------------------------------------
249 : 0 : Any UnoGridColumnFacade::getID() const
250 : : {
251 : 0 : Any aID;
252 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", aID );
253 : : try
254 : : {
255 [ # # ][ # # ]: 0 : aID = m_xGridColumn->getIdentifier();
256 : : }
257 [ # # ]: 0 : catch( const Exception& )
258 : : {
259 : : DBG_UNHANDLED_EXCEPTION();
260 : : }
261 [ # # ]: 0 : return aID;
262 : : }
263 : :
264 : : //------------------------------------------------------------------------------------------------------------------
265 : 0 : void UnoGridColumnFacade::setID( const Any& i_ID )
266 : : {
267 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
268 : : try
269 : : {
270 [ # # ][ # # ]: 0 : m_xGridColumn->setIdentifier( i_ID );
271 : : }
272 : 0 : catch( const Exception& )
273 : : {
274 : : DBG_UNHANDLED_EXCEPTION();
275 : : }
276 : : }
277 : :
278 : : //------------------------------------------------------------------------------------------------------------------
279 : 0 : String UnoGridColumnFacade::getName() const
280 : : {
281 : 0 : ::rtl::OUString sName;
282 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sName );
283 : : try
284 : : {
285 [ # # ][ # # ]: 0 : sName = m_xGridColumn->getTitle();
286 : : }
287 [ # # ]: 0 : catch( const Exception& )
288 : : {
289 : : DBG_UNHANDLED_EXCEPTION();
290 : : }
291 [ # # ][ # # ]: 0 : return sName;
292 : : }
293 : :
294 : : //------------------------------------------------------------------------------------------------------------------
295 : 0 : void UnoGridColumnFacade::setName( const String& _rName )
296 : : {
297 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
298 : : try
299 : : {
300 [ # # ][ # # ]: 0 : m_xGridColumn->setTitle( _rName );
[ # # ][ # # ]
301 : : }
302 : 0 : catch( const Exception& )
303 : : {
304 : : DBG_UNHANDLED_EXCEPTION();
305 : : }
306 : : }
307 : :
308 : : //------------------------------------------------------------------------------------------------------------------
309 : 0 : String UnoGridColumnFacade::getHelpText() const
310 : : {
311 : 0 : ::rtl::OUString sHelpText;
312 [ # # ][ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sHelpText );
313 : : try
314 : : {
315 [ # # ][ # # ]: 0 : sHelpText = m_xGridColumn->getHelpText();
316 : : }
317 [ # # ]: 0 : catch( const Exception& )
318 : : {
319 : : DBG_UNHANDLED_EXCEPTION();
320 : : }
321 [ # # ][ # # ]: 0 : return sHelpText;
322 : : }
323 : :
324 : : //------------------------------------------------------------------------------------------------------------------
325 : 0 : void UnoGridColumnFacade::setHelpText( const String& i_helpText )
326 : : {
327 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
328 : : try
329 : : {
330 [ # # ][ # # ]: 0 : m_xGridColumn->setHelpText( i_helpText );
[ # # ][ # # ]
331 : : }
332 : 0 : catch( const Exception& )
333 : : {
334 : : DBG_UNHANDLED_EXCEPTION();
335 : : }
336 : : }
337 : :
338 : : //------------------------------------------------------------------------------------------------------------------
339 : 0 : bool UnoGridColumnFacade::isResizable() const
340 : : {
341 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false );
342 : 0 : return lcl_get( m_xGridColumn, &XGridColumn::getResizeable );
343 : : }
344 : :
345 : : //------------------------------------------------------------------------------------------------------------------
346 : 0 : void UnoGridColumnFacade::setResizable( bool i_resizable )
347 : : {
348 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
349 : 0 : lcl_set( m_xGridColumn, &XGridColumn::setResizeable, sal_Bool( i_resizable ) );
350 : : }
351 : :
352 : : //------------------------------------------------------------------------------------------------------------------
353 : 0 : sal_Int32 UnoGridColumnFacade::getFlexibility() const
354 : : {
355 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 1 );
356 : 0 : return lcl_get( m_xGridColumn, &XGridColumn::getFlexibility );
357 : : }
358 : :
359 : : //------------------------------------------------------------------------------------------------------------------
360 : 0 : void UnoGridColumnFacade::setFlexibility( sal_Int32 const i_flexibility )
361 : : {
362 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
363 : 0 : lcl_set( m_xGridColumn, &XGridColumn::setFlexibility, i_flexibility );
364 : : }
365 : :
366 : : //------------------------------------------------------------------------------------------------------------------
367 : 0 : TableMetrics UnoGridColumnFacade::getWidth() const
368 : : {
369 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
370 : 0 : return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth );
371 : : }
372 : :
373 : : //------------------------------------------------------------------------------------------------------------------
374 : 0 : void UnoGridColumnFacade::setWidth( TableMetrics _nWidth )
375 : : {
376 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
377 : 0 : lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth );
378 : : }
379 : :
380 : : //------------------------------------------------------------------------------------------------------------------
381 : 0 : TableMetrics UnoGridColumnFacade::getMinWidth() const
382 : : {
383 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
384 : 0 : return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth );
385 : : }
386 : :
387 : : //------------------------------------------------------------------------------------------------------------------
388 : 0 : void UnoGridColumnFacade::setMinWidth( TableMetrics _nMinWidth )
389 : : {
390 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
391 : 0 : lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMinWidth );
392 : : }
393 : :
394 : : //------------------------------------------------------------------------------------------------------------------
395 : 0 : TableMetrics UnoGridColumnFacade::getMaxWidth() const
396 : : {
397 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
398 : 0 : return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth );
399 : : }
400 : :
401 : : //------------------------------------------------------------------------------------------------------------------
402 : 0 : void UnoGridColumnFacade::setMaxWidth( TableMetrics _nMaxWidth )
403 : : {
404 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
405 : 0 : lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMaxWidth );
406 : : }
407 : :
408 : : //------------------------------------------------------------------------------------------------------------------
409 : 0 : ::com::sun::star::style::HorizontalAlignment UnoGridColumnFacade::getHorizontalAlign()
410 : : {
411 [ # # ]: 0 : ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT );
412 : 0 : return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign );
413 : : }
414 : :
415 : : //------------------------------------------------------------------------------------------------------------------
416 : 0 : void UnoGridColumnFacade::setHorizontalAlign( com::sun::star::style::HorizontalAlignment _align )
417 : : {
418 [ # # ]: 0 : ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
419 : 0 : lcl_set( m_xGridColumn, &XGridColumn::setHorizontalAlign, _align );
420 : : }
421 : :
422 : : // .....................................................................................................................
423 : : } } // svt::table
424 : : // .....................................................................................................................
425 : :
426 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|