1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/stlunosequence.hxx>
32 #include <tools/debug.hxx>
33 #include <tools/diagnose_ex.h>
34 #include <vcl/svapp.hxx>
35 #include <osl/mutex.hxx>
37 // .....................................................................................................................
38 namespace svt
{ namespace table
40 // .....................................................................................................................
42 using ::com::sun::star::uno::Reference
;
43 using ::com::sun::star::uno::RuntimeException
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::uno::UNO_QUERY_THROW
;
46 using ::com::sun::star::uno::UNO_QUERY
;
47 using ::com::sun::star::awt::grid::XGridColumn
;
48 using ::com::sun::star::uno::XInterface
;
49 using ::com::sun::star::uno::Exception
;
50 using ::com::sun::star::awt::grid::XGridColumnListener
;
51 using ::com::sun::star::lang::EventObject
;
52 using ::com::sun::star::awt::grid::GridColumnEvent
;
53 using ::com::sun::star::uno::Any
;
54 using ::com::sun::star::style::HorizontalAlignment_LEFT
;
55 using ::com::sun::star::style::HorizontalAlignment
;
57 //------------------------------------------------------------------------------------------------------------------
60 template< class ATTRIBUTE_TYPE
>
61 void lcl_set( Reference
< XGridColumn
> const & i_column
, void ( SAL_CALL
XGridColumn::*i_setter
)( ATTRIBUTE_TYPE
),
62 ATTRIBUTE_TYPE i_value
)
66 (i_column
.get()->*i_setter
) ( i_value
);
68 catch( const Exception
& )
70 DBG_UNHANDLED_EXCEPTION();
74 template< class ATTRIBUTE_TYPE
>
75 ATTRIBUTE_TYPE
lcl_get( Reference
< XGridColumn
> const & i_column
, ATTRIBUTE_TYPE ( SAL_CALL
XGridColumn::*i_getter
)() )
77 ATTRIBUTE_TYPE value
= ATTRIBUTE_TYPE();
80 value
= (i_column
.get()->*i_getter
)();
82 catch( const Exception
& )
84 DBG_UNHANDLED_EXCEPTION();
90 //==================================================================================================================
91 //= ColumnChangeMultiplexer
92 //==================================================================================================================
93 typedef ::cppu::WeakImplHelper1
< XGridColumnListener
94 > ColumnChangeMultiplexer_Base
;
95 class ColumnChangeMultiplexer
:public ColumnChangeMultiplexer_Base
96 ,public ::boost::noncopyable
99 ColumnChangeMultiplexer( UnoGridColumnFacade
& i_colImpl
);
104 ~ColumnChangeMultiplexer();
106 // XGridColumnListener
107 virtual void SAL_CALL
columnChanged( const GridColumnEvent
& i_event
) throw (RuntimeException
);
110 virtual void SAL_CALL
disposing( const EventObject
& i_event
) throw (RuntimeException
);
113 UnoGridColumnFacade
* m_pColumnImplementation
;
116 //------------------------------------------------------------------------------------------------------------------
117 ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade
& i_colImpl
)
118 :m_pColumnImplementation( &i_colImpl
)
122 //------------------------------------------------------------------------------------------------------------------
123 ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
127 //------------------------------------------------------------------------------------------------------------------
128 void ColumnChangeMultiplexer::dispose()
130 DBG_TESTSOLARMUTEX();
131 m_pColumnImplementation
= NULL
;
134 //------------------------------------------------------------------------------------------------------------------
135 void SAL_CALL
ColumnChangeMultiplexer::columnChanged( const GridColumnEvent
& i_event
) throw (RuntimeException
)
137 if ( i_event
.AttributeName
== "DataColumnIndex" )
139 SolarMutexGuard aGuard
;
140 if ( m_pColumnImplementation
!= NULL
)
141 m_pColumnImplementation
->dataColumnIndexChanged();
145 ColumnAttributeGroup
nChangedAttributes( COL_ATTRS_NONE
);
147 if ( i_event
.AttributeName
== "HorizontalAlign" )
148 nChangedAttributes
|= COL_ATTRS_APPEARANCE
;
150 if ( i_event
.AttributeName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ColumnWidth"))
151 || i_event
.AttributeName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MaxWidth"))
152 || i_event
.AttributeName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MinWidth"))
153 || i_event
.AttributeName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PreferredWidth"))
154 || i_event
.AttributeName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Resizeable"))
155 || i_event
.AttributeName
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Flexibility"))
157 nChangedAttributes
|= COL_ATTRS_WIDTH
;
159 OSL_ENSURE( nChangedAttributes
!= COL_ATTRS_NONE
,
160 "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
162 SolarMutexGuard aGuard
;
163 if ( m_pColumnImplementation
!= NULL
)
164 m_pColumnImplementation
->columnChanged( nChangedAttributes
);
167 //------------------------------------------------------------------------------------------------------------------
168 void SAL_CALL
ColumnChangeMultiplexer::disposing( const EventObject
& i_event
) throw (RuntimeException
)
170 OSL_UNUSED( i_event
);
173 //==================================================================================================================
174 //= UnoGridColumnFacade
175 //==================================================================================================================
176 //------------------------------------------------------------------------------------------------------------------
177 UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel
const & i_owner
, Reference
< XGridColumn
> const & i_gridColumn
)
178 :m_pOwner( &i_owner
)
179 ,m_nDataColumnIndex( -1 )
180 ,m_xGridColumn( i_gridColumn
, UNO_QUERY_THROW
)
181 ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
183 m_xGridColumn
->addGridColumnListener( m_pChangeMultiplexer
.get() );
184 impl_updateDataColumnIndex_nothrow();
187 //------------------------------------------------------------------------------------------------------------------
188 UnoGridColumnFacade::~UnoGridColumnFacade()
192 //------------------------------------------------------------------------------------------------------------------
193 void UnoGridColumnFacade::dispose()
195 DBG_TESTSOLARMUTEX();
196 ENSURE_OR_RETURN_VOID( m_pOwner
!= NULL
, "UnoGridColumnFacade::dispose: already disposed!" );
198 m_xGridColumn
->removeGridColumnListener( m_pChangeMultiplexer
.get() );
199 m_pChangeMultiplexer
->dispose();
200 m_pChangeMultiplexer
.clear();
201 m_xGridColumn
.clear();
205 //------------------------------------------------------------------------------------------------------------------
206 void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow()
208 m_nDataColumnIndex
= -1;
209 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
212 m_nDataColumnIndex
= m_xGridColumn
->getDataColumnIndex();
214 catch( const Exception
& )
216 DBG_UNHANDLED_EXCEPTION();
220 //------------------------------------------------------------------------------------------------------------------
221 void UnoGridColumnFacade::dataColumnIndexChanged()
223 DBG_TESTSOLARMUTEX();
224 impl_updateDataColumnIndex_nothrow();
225 if ( m_pOwner
!= NULL
)
226 m_pOwner
->notifyAllDataChanged();
229 //------------------------------------------------------------------------------------------------------------------
230 void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup
const i_attributeGroup
)
232 DBG_TESTSOLARMUTEX();
233 if ( m_pOwner
!= NULL
)
234 m_pOwner
->notifyColumnChange( m_pOwner
->getColumnPos( *this ), i_attributeGroup
);
237 //------------------------------------------------------------------------------------------------------------------
238 Any
UnoGridColumnFacade::getID() const
241 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", aID
);
244 aID
= m_xGridColumn
->getIdentifier();
246 catch( const Exception
& )
248 DBG_UNHANDLED_EXCEPTION();
253 //------------------------------------------------------------------------------------------------------------------
254 void UnoGridColumnFacade::setID( const Any
& i_ID
)
256 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
259 m_xGridColumn
->setIdentifier( i_ID
);
261 catch( const Exception
& )
263 DBG_UNHANDLED_EXCEPTION();
267 //------------------------------------------------------------------------------------------------------------------
268 String
UnoGridColumnFacade::getName() const
271 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", sName
);
274 sName
= m_xGridColumn
->getTitle();
276 catch( const Exception
& )
278 DBG_UNHANDLED_EXCEPTION();
283 //------------------------------------------------------------------------------------------------------------------
284 void UnoGridColumnFacade::setName( const String
& _rName
)
286 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
289 m_xGridColumn
->setTitle( _rName
);
291 catch( const Exception
& )
293 DBG_UNHANDLED_EXCEPTION();
297 //------------------------------------------------------------------------------------------------------------------
298 String
UnoGridColumnFacade::getHelpText() const
301 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", sHelpText
);
304 sHelpText
= m_xGridColumn
->getHelpText();
306 catch( const Exception
& )
308 DBG_UNHANDLED_EXCEPTION();
313 //------------------------------------------------------------------------------------------------------------------
314 void UnoGridColumnFacade::setHelpText( const String
& i_helpText
)
316 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
319 m_xGridColumn
->setHelpText( i_helpText
);
321 catch( const Exception
& )
323 DBG_UNHANDLED_EXCEPTION();
327 //------------------------------------------------------------------------------------------------------------------
328 bool UnoGridColumnFacade::isResizable() const
330 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", false );
331 return lcl_get( m_xGridColumn
, &XGridColumn::getResizeable
);
334 //------------------------------------------------------------------------------------------------------------------
335 void UnoGridColumnFacade::setResizable( bool i_resizable
)
337 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
338 lcl_set( m_xGridColumn
, &XGridColumn::setResizeable
, sal_Bool( i_resizable
) );
341 //------------------------------------------------------------------------------------------------------------------
342 sal_Int32
UnoGridColumnFacade::getFlexibility() const
344 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 1 );
345 return lcl_get( m_xGridColumn
, &XGridColumn::getFlexibility
);
348 //------------------------------------------------------------------------------------------------------------------
349 void UnoGridColumnFacade::setFlexibility( sal_Int32
const i_flexibility
)
351 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
352 lcl_set( m_xGridColumn
, &XGridColumn::setFlexibility
, i_flexibility
);
355 //------------------------------------------------------------------------------------------------------------------
356 TableMetrics
UnoGridColumnFacade::getWidth() const
358 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 0 );
359 return lcl_get( m_xGridColumn
, &XGridColumn::getColumnWidth
);
362 //------------------------------------------------------------------------------------------------------------------
363 void UnoGridColumnFacade::setWidth( TableMetrics _nWidth
)
365 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
366 lcl_set( m_xGridColumn
, &XGridColumn::setColumnWidth
, _nWidth
);
369 //------------------------------------------------------------------------------------------------------------------
370 TableMetrics
UnoGridColumnFacade::getMinWidth() const
372 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 0 );
373 return lcl_get( m_xGridColumn
, &XGridColumn::getMinWidth
);
376 //------------------------------------------------------------------------------------------------------------------
377 void UnoGridColumnFacade::setMinWidth( TableMetrics _nMinWidth
)
379 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
380 lcl_set( m_xGridColumn
, &XGridColumn::setMinWidth
, _nMinWidth
);
383 //------------------------------------------------------------------------------------------------------------------
384 TableMetrics
UnoGridColumnFacade::getMaxWidth() const
386 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 0 );
387 return lcl_get( m_xGridColumn
, &XGridColumn::getMaxWidth
);
390 //------------------------------------------------------------------------------------------------------------------
391 void UnoGridColumnFacade::setMaxWidth( TableMetrics _nMaxWidth
)
393 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
394 lcl_set( m_xGridColumn
, &XGridColumn::setMinWidth
, _nMaxWidth
);
397 //------------------------------------------------------------------------------------------------------------------
398 ::com::sun::star::style::HorizontalAlignment
UnoGridColumnFacade::getHorizontalAlign()
400 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT
);
401 return lcl_get( m_xGridColumn
, &XGridColumn::getHorizontalAlign
);
404 //------------------------------------------------------------------------------------------------------------------
405 void UnoGridColumnFacade::setHorizontalAlign( com::sun::star::style::HorizontalAlignment _align
)
407 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
408 lcl_set( m_xGridColumn
, &XGridColumn::setHorizontalAlign
, _align
);
411 // .....................................................................................................................
413 // .....................................................................................................................
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */