Bump version to 5.0-14
[LibreOffice.git] / svtools / source / uno / unogridcolumnfacade.cxx
blob815e2b61a6629e4fb8fc0e2107e1d15ed7d09cff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "unogridcolumnfacade.hxx"
21 #include "unocontroltablemodel.hxx"
23 #include "table/defaultinputhandler.hxx"
24 #include "table/gridtablerenderer.hxx"
25 #include "table/tablecontrol.hxx"
27 #include <com/sun/star/awt/grid/XGridColumn.hpp>
28 #include <com/sun/star/view/SelectionType.hpp>
29 #include <com/sun/star/awt/grid/XGridColumnListener.hpp>
31 #include <tools/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <vcl/svapp.hxx>
34 #include <osl/mutex.hxx>
37 namespace svt { namespace table
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::RuntimeException;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::UNO_QUERY_THROW;
45 using ::com::sun::star::uno::UNO_QUERY;
46 using ::com::sun::star::awt::grid::XGridColumn;
47 using ::com::sun::star::uno::XInterface;
48 using ::com::sun::star::uno::Exception;
49 using ::com::sun::star::awt::grid::XGridColumnListener;
50 using ::com::sun::star::lang::EventObject;
51 using ::com::sun::star::awt::grid::GridColumnEvent;
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::style::HorizontalAlignment_LEFT;
54 using ::com::sun::star::style::HorizontalAlignment;
57 namespace
59 template< class T1, class T2 >
60 void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( T1 ),
61 T2 i_value )
63 try
65 (i_column.get()->*i_setter) ( i_value );
67 catch( const Exception& )
69 DBG_UNHANDLED_EXCEPTION();
73 template< class ATTRIBUTE_TYPE >
74 ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() )
76 ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE();
77 try
79 value = (i_column.get()->*i_getter)();
81 catch( const Exception& )
83 DBG_UNHANDLED_EXCEPTION();
85 return value;
90 //= ColumnChangeMultiplexer
92 typedef ::cppu::WeakImplHelper1 < XGridColumnListener
93 > ColumnChangeMultiplexer_Base;
94 class ColumnChangeMultiplexer :public ColumnChangeMultiplexer_Base
95 ,public ::boost::noncopyable
97 public:
98 ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl );
100 void dispose();
102 protected:
103 virtual ~ColumnChangeMultiplexer();
105 // XGridColumnListener
106 virtual void SAL_CALL columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
108 // XEventListener
109 virtual void SAL_CALL disposing( const EventObject& i_event ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
111 private:
112 UnoGridColumnFacade* m_pColumnImplementation;
116 ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl )
117 :m_pColumnImplementation( &i_colImpl )
122 ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
127 void ColumnChangeMultiplexer::dispose()
129 DBG_TESTSOLARMUTEX();
130 m_pColumnImplementation = NULL;
134 void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException, std::exception)
136 if ( i_event.AttributeName == "DataColumnIndex" )
138 SolarMutexGuard aGuard;
139 if ( m_pColumnImplementation != NULL )
140 m_pColumnImplementation->dataColumnIndexChanged();
141 return;
144 ColumnAttributeGroup nChangedAttributes( ColumnAttributeGroup::NONE );
146 if ( i_event.AttributeName == "HorizontalAlign" )
147 nChangedAttributes |= ColumnAttributeGroup::APPEARANCE;
149 if ( i_event.AttributeName == "ColumnWidth"
150 || i_event.AttributeName == "MaxWidth"
151 || i_event.AttributeName == "MinWidth"
152 || i_event.AttributeName == "PreferredWidth"
153 || i_event.AttributeName == "Resizeable"
154 || i_event.AttributeName == "Flexibility"
156 nChangedAttributes |= ColumnAttributeGroup::WIDTH;
158 OSL_ENSURE( nChangedAttributes != ColumnAttributeGroup::NONE,
159 "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
161 SolarMutexGuard aGuard;
162 if ( m_pColumnImplementation != NULL )
163 m_pColumnImplementation->columnChanged( nChangedAttributes );
167 void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& i_event ) throw (RuntimeException, std::exception)
169 OSL_UNUSED( i_event );
173 //= UnoGridColumnFacade
176 UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn )
177 :m_pOwner( &i_owner )
178 ,m_nDataColumnIndex( -1 )
179 ,m_xGridColumn( i_gridColumn, UNO_QUERY_THROW )
180 ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
182 m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer.get() );
183 impl_updateDataColumnIndex_nothrow();
187 UnoGridColumnFacade::~UnoGridColumnFacade()
192 void UnoGridColumnFacade::dispose()
194 DBG_TESTSOLARMUTEX();
195 ENSURE_OR_RETURN_VOID( m_pOwner != NULL, "UnoGridColumnFacade::dispose: already disposed!" );
197 m_xGridColumn->removeGridColumnListener( m_pChangeMultiplexer.get() );
198 m_pChangeMultiplexer->dispose();
199 m_pChangeMultiplexer.clear();
200 m_xGridColumn.clear();
201 m_pOwner = NULL;
205 void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow()
207 m_nDataColumnIndex = -1;
208 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
211 m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex();
213 catch( const Exception& )
215 DBG_UNHANDLED_EXCEPTION();
220 void UnoGridColumnFacade::dataColumnIndexChanged()
222 DBG_TESTSOLARMUTEX();
223 impl_updateDataColumnIndex_nothrow();
224 if ( m_pOwner != NULL )
225 m_pOwner->notifyAllDataChanged();
229 void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup const i_attributeGroup )
231 DBG_TESTSOLARMUTEX();
232 if ( m_pOwner != NULL )
233 m_pOwner->notifyColumnChange( m_pOwner->getColumnPos( *this ), i_attributeGroup );
237 Any UnoGridColumnFacade::getID() const
239 Any aID;
240 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", aID );
243 aID = m_xGridColumn->getIdentifier();
245 catch( const Exception& )
247 DBG_UNHANDLED_EXCEPTION();
249 return aID;
253 void UnoGridColumnFacade::setID( const Any& i_ID )
255 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
258 m_xGridColumn->setIdentifier( i_ID );
260 catch( const Exception& )
262 DBG_UNHANDLED_EXCEPTION();
267 OUString UnoGridColumnFacade::getName() const
269 OUString sName;
270 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sName );
273 sName = m_xGridColumn->getTitle();
275 catch( const Exception& )
277 DBG_UNHANDLED_EXCEPTION();
279 return sName;
283 void UnoGridColumnFacade::setName( const OUString& _rName )
285 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
288 m_xGridColumn->setTitle( _rName );
290 catch( const Exception& )
292 DBG_UNHANDLED_EXCEPTION();
297 OUString UnoGridColumnFacade::getHelpText() const
299 OUString sHelpText;
300 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sHelpText );
303 sHelpText = m_xGridColumn->getHelpText();
305 catch( const Exception& )
307 DBG_UNHANDLED_EXCEPTION();
309 return sHelpText;
313 void UnoGridColumnFacade::setHelpText( const OUString& i_helpText )
315 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
318 m_xGridColumn->setHelpText( i_helpText );
320 catch( const Exception& )
322 DBG_UNHANDLED_EXCEPTION();
327 bool UnoGridColumnFacade::isResizable() const
329 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false );
330 return lcl_get( m_xGridColumn, &XGridColumn::getResizeable );
334 void UnoGridColumnFacade::setResizable( bool i_resizable )
336 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
337 lcl_set( m_xGridColumn, &XGridColumn::setResizeable, i_resizable );
341 sal_Int32 UnoGridColumnFacade::getFlexibility() const
343 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 1 );
344 return lcl_get( m_xGridColumn, &XGridColumn::getFlexibility );
348 void UnoGridColumnFacade::setFlexibility( sal_Int32 const i_flexibility )
350 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
351 lcl_set( m_xGridColumn, &XGridColumn::setFlexibility, i_flexibility );
355 TableMetrics UnoGridColumnFacade::getWidth() const
357 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
358 return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth );
362 void UnoGridColumnFacade::setWidth( TableMetrics _nWidth )
364 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
365 lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth );
369 TableMetrics UnoGridColumnFacade::getMinWidth() const
371 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
372 return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth );
376 void UnoGridColumnFacade::setMinWidth( TableMetrics _nMinWidth )
378 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
379 lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMinWidth );
383 TableMetrics UnoGridColumnFacade::getMaxWidth() const
385 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
386 return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth );
390 void UnoGridColumnFacade::setMaxWidth( TableMetrics _nMaxWidth )
392 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
393 lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMaxWidth );
397 ::com::sun::star::style::HorizontalAlignment UnoGridColumnFacade::getHorizontalAlign()
399 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT );
400 return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign );
404 void UnoGridColumnFacade::setHorizontalAlign( com::sun::star::style::HorizontalAlignment _align )
406 ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
407 lcl_set( m_xGridColumn, &XGridColumn::setHorizontalAlign, _align );
411 } } // svt::table
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */