GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / uno / unogridcolumnfacade.cxx
blob8c936425f98090171c62554317c4bf3521134f14
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 "svtools/table/defaultinputhandler.hxx"
24 #include "svtools/table/gridtablerenderer.hxx"
25 #include "svtools/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>
36 // .....................................................................................................................
37 namespace svt { namespace table
39 // .....................................................................................................................
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;
56 //------------------------------------------------------------------------------------------------------------------
57 namespace
59 template< class ATTRIBUTE_TYPE >
60 void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( ATTRIBUTE_TYPE ),
61 ATTRIBUTE_TYPE 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;
89 //==================================================================================================================
90 //= ColumnChangeMultiplexer
91 //==================================================================================================================
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 ~ColumnChangeMultiplexer();
105 // XGridColumnListener
106 virtual void SAL_CALL columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException);
108 // XEventListener
109 virtual void SAL_CALL disposing( const EventObject& i_event ) throw (RuntimeException);
111 private:
112 UnoGridColumnFacade* m_pColumnImplementation;
115 //------------------------------------------------------------------------------------------------------------------
116 ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl )
117 :m_pColumnImplementation( &i_colImpl )
121 //------------------------------------------------------------------------------------------------------------------
122 ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
126 //------------------------------------------------------------------------------------------------------------------
127 void ColumnChangeMultiplexer::dispose()
129 DBG_TESTSOLARMUTEX();
130 m_pColumnImplementation = NULL;
133 //------------------------------------------------------------------------------------------------------------------
134 void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException)
136 if ( i_event.AttributeName == "DataColumnIndex" )
138 SolarMutexGuard aGuard;
139 if ( m_pColumnImplementation != NULL )
140 m_pColumnImplementation->dataColumnIndexChanged();
141 return;
144 ColumnAttributeGroup nChangedAttributes( COL_ATTRS_NONE );
146 if ( i_event.AttributeName == "HorizontalAlign" )
147 nChangedAttributes |= COL_ATTRS_APPEARANCE;
149 if ( i_event.AttributeName.startsWith("ColumnWidth")
150 || i_event.AttributeName.startsWith("MaxWidth")
151 || i_event.AttributeName.startsWith("MinWidth")
152 || i_event.AttributeName.startsWith("PreferredWidth")
153 || i_event.AttributeName.startsWith("Resizeable")
154 || i_event.AttributeName.startsWith("Flexibility")
156 nChangedAttributes |= COL_ATTRS_WIDTH;
158 OSL_ENSURE( nChangedAttributes != COL_ATTRS_NONE,
159 "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
161 SolarMutexGuard aGuard;
162 if ( m_pColumnImplementation != NULL )
163 m_pColumnImplementation->columnChanged( nChangedAttributes );
166 //------------------------------------------------------------------------------------------------------------------
167 void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& i_event ) throw (RuntimeException)
169 OSL_UNUSED( i_event );
172 //==================================================================================================================
173 //= UnoGridColumnFacade
174 //==================================================================================================================
175 //------------------------------------------------------------------------------------------------------------------
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();
186 //------------------------------------------------------------------------------------------------------------------
187 UnoGridColumnFacade::~UnoGridColumnFacade()
191 //------------------------------------------------------------------------------------------------------------------
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;
204 //------------------------------------------------------------------------------------------------------------------
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();
219 //------------------------------------------------------------------------------------------------------------------
220 void UnoGridColumnFacade::dataColumnIndexChanged()
222 DBG_TESTSOLARMUTEX();
223 impl_updateDataColumnIndex_nothrow();
224 if ( m_pOwner != NULL )
225 m_pOwner->notifyAllDataChanged();
228 //------------------------------------------------------------------------------------------------------------------
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 );
236 //------------------------------------------------------------------------------------------------------------------
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;
252 //------------------------------------------------------------------------------------------------------------------
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();
266 //------------------------------------------------------------------------------------------------------------------
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;
282 //------------------------------------------------------------------------------------------------------------------
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();
296 //------------------------------------------------------------------------------------------------------------------
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;
312 //------------------------------------------------------------------------------------------------------------------
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();
326 //------------------------------------------------------------------------------------------------------------------
327 bool UnoGridColumnFacade::isResizable() const
329 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false );
330 return lcl_get( m_xGridColumn, &XGridColumn::getResizeable );
333 //------------------------------------------------------------------------------------------------------------------
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, sal_Bool( i_resizable ) );
340 //------------------------------------------------------------------------------------------------------------------
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 );
347 //------------------------------------------------------------------------------------------------------------------
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 );
354 //------------------------------------------------------------------------------------------------------------------
355 TableMetrics UnoGridColumnFacade::getWidth() const
357 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
358 return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth );
361 //------------------------------------------------------------------------------------------------------------------
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 );
368 //------------------------------------------------------------------------------------------------------------------
369 TableMetrics UnoGridColumnFacade::getMinWidth() const
371 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
372 return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth );
375 //------------------------------------------------------------------------------------------------------------------
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 );
382 //------------------------------------------------------------------------------------------------------------------
383 TableMetrics UnoGridColumnFacade::getMaxWidth() const
385 ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
386 return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth );
389 //------------------------------------------------------------------------------------------------------------------
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 );
396 //------------------------------------------------------------------------------------------------------------------
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 );
403 //------------------------------------------------------------------------------------------------------------------
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 );
410 // .....................................................................................................................
411 } } // svt::table
412 // .....................................................................................................................
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */