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 <com/sun/star/awt/grid/XGridColumn.hpp>
24 #include <com/sun/star/awt/grid/XGridColumnListener.hpp>
26 #include <tools/debug.hxx>
27 #include <comphelper/diagnose_ex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <cppuhelper/implbase.hxx>
36 using css::uno::Reference
;
37 using css::awt::grid::XGridColumn
;
38 using css::uno::Exception
;
39 using css::awt::grid::XGridColumnListener
;
40 using css::lang::EventObject
;
41 using css::awt::grid::GridColumnEvent
;
42 using css::style::HorizontalAlignment_LEFT
;
43 using css::style::HorizontalAlignment
;
48 template< class T1
, class T2
>
49 void lcl_set( Reference
< XGridColumn
> const & i_column
, void ( SAL_CALL
XGridColumn::*i_setter
)( T1
),
54 (i_column
.get()->*i_setter
) ( i_value
);
56 catch( const Exception
& )
58 DBG_UNHANDLED_EXCEPTION("svtools.uno");
62 template< class ATTRIBUTE_TYPE
>
63 ATTRIBUTE_TYPE
lcl_get( Reference
< XGridColumn
> const & i_column
, ATTRIBUTE_TYPE ( SAL_CALL
XGridColumn::*i_getter
)() )
65 ATTRIBUTE_TYPE value
= ATTRIBUTE_TYPE();
68 value
= (i_column
.get()->*i_getter
)();
70 catch( const Exception
& )
72 DBG_UNHANDLED_EXCEPTION("svtools.uno");
79 //= ColumnChangeMultiplexer
81 typedef ::cppu::WeakImplHelper
< XGridColumnListener
82 > ColumnChangeMultiplexer_Base
;
83 class ColumnChangeMultiplexer
:public ColumnChangeMultiplexer_Base
86 explicit ColumnChangeMultiplexer( UnoGridColumnFacade
& i_colImpl
);
87 ColumnChangeMultiplexer(const ColumnChangeMultiplexer
&) = delete;
88 ColumnChangeMultiplexer
& operator=(const ColumnChangeMultiplexer
&) = delete;
93 virtual ~ColumnChangeMultiplexer() override
;
95 // XGridColumnListener
96 virtual void SAL_CALL
columnChanged( const GridColumnEvent
& i_event
) override
;
99 virtual void SAL_CALL
disposing( const EventObject
& i_event
) override
;
102 UnoGridColumnFacade
* m_pColumnImplementation
;
106 ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade
& i_colImpl
)
107 :m_pColumnImplementation( &i_colImpl
)
112 ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
117 void ColumnChangeMultiplexer::dispose()
119 DBG_TESTSOLARMUTEX();
120 m_pColumnImplementation
= nullptr;
124 void SAL_CALL
ColumnChangeMultiplexer::columnChanged( const GridColumnEvent
& i_event
)
126 if ( i_event
.AttributeName
== "DataColumnIndex" )
128 SolarMutexGuard aGuard
;
129 if ( m_pColumnImplementation
!= nullptr )
130 m_pColumnImplementation
->dataColumnIndexChanged();
134 ColumnAttributeGroup
nChangedAttributes( ColumnAttributeGroup::NONE
);
136 if ( i_event
.AttributeName
== "HorizontalAlign" )
137 nChangedAttributes
|= ColumnAttributeGroup::APPEARANCE
;
139 if ( i_event
.AttributeName
== "ColumnWidth"
140 || i_event
.AttributeName
== "MaxWidth"
141 || i_event
.AttributeName
== "MinWidth"
142 || i_event
.AttributeName
== "PreferredWidth"
143 || i_event
.AttributeName
== "Resizeable"
144 || i_event
.AttributeName
== "Flexibility"
146 nChangedAttributes
|= ColumnAttributeGroup::WIDTH
;
148 OSL_ENSURE( nChangedAttributes
!= ColumnAttributeGroup::NONE
,
149 "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
151 SolarMutexGuard aGuard
;
152 if ( m_pColumnImplementation
!= nullptr )
153 m_pColumnImplementation
->columnChanged( nChangedAttributes
);
157 void SAL_CALL
ColumnChangeMultiplexer::disposing( const EventObject
& )
162 //= UnoGridColumnFacade
165 UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel
const & i_owner
, Reference
< XGridColumn
> const & i_gridColumn
)
166 :m_pOwner( &i_owner
)
167 ,m_nDataColumnIndex( -1 )
168 ,m_xGridColumn( i_gridColumn
, css::uno::UNO_SET_THROW
)
169 ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
171 m_xGridColumn
->addGridColumnListener( m_pChangeMultiplexer
);
172 impl_updateDataColumnIndex_nothrow();
176 UnoGridColumnFacade::~UnoGridColumnFacade()
181 void UnoGridColumnFacade::dispose()
183 DBG_TESTSOLARMUTEX();
184 ENSURE_OR_RETURN_VOID( m_pOwner
!= nullptr, "UnoGridColumnFacade::dispose: already disposed!" );
186 m_xGridColumn
->removeGridColumnListener( m_pChangeMultiplexer
);
187 m_pChangeMultiplexer
->dispose();
188 m_pChangeMultiplexer
.clear();
189 m_xGridColumn
.clear();
194 void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow()
196 m_nDataColumnIndex
= -1;
197 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
200 m_nDataColumnIndex
= m_xGridColumn
->getDataColumnIndex();
202 catch( const Exception
& )
204 DBG_UNHANDLED_EXCEPTION("svtools.uno");
209 void UnoGridColumnFacade::dataColumnIndexChanged()
211 DBG_TESTSOLARMUTEX();
212 impl_updateDataColumnIndex_nothrow();
213 if ( m_pOwner
!= nullptr )
214 m_pOwner
->notifyAllDataChanged();
218 void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup
const i_attributeGroup
)
220 DBG_TESTSOLARMUTEX();
221 if ( m_pOwner
!= nullptr )
222 m_pOwner
->notifyColumnChange( m_pOwner
->getColumnPos( *this ), i_attributeGroup
);
226 OUString
UnoGridColumnFacade::getName() const
229 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", sName
);
232 sName
= m_xGridColumn
->getTitle();
234 catch( const Exception
& )
236 DBG_UNHANDLED_EXCEPTION("svtools.uno");
242 OUString
UnoGridColumnFacade::getHelpText() const
245 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", sHelpText
);
248 sHelpText
= m_xGridColumn
->getHelpText();
250 catch( const Exception
& )
252 DBG_UNHANDLED_EXCEPTION("svtools.uno");
258 bool UnoGridColumnFacade::isResizable() const
260 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", false );
261 return lcl_get( m_xGridColumn
, &XGridColumn::getResizeable
);
265 sal_Int32
UnoGridColumnFacade::getFlexibility() const
267 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 1 );
268 return lcl_get( m_xGridColumn
, &XGridColumn::getFlexibility
);
272 TableMetrics
UnoGridColumnFacade::getWidth() const
274 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 0 );
275 return lcl_get( m_xGridColumn
, &XGridColumn::getColumnWidth
);
279 void UnoGridColumnFacade::setWidth( TableMetrics _nWidth
)
281 ENSURE_OR_RETURN_VOID( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!" );
282 lcl_set( m_xGridColumn
, &XGridColumn::setColumnWidth
, _nWidth
);
286 TableMetrics
UnoGridColumnFacade::getMinWidth() const
288 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 0 );
289 return lcl_get( m_xGridColumn
, &XGridColumn::getMinWidth
);
293 TableMetrics
UnoGridColumnFacade::getMaxWidth() const
295 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", 0 );
296 return lcl_get( m_xGridColumn
, &XGridColumn::getMaxWidth
);
300 css::style::HorizontalAlignment
UnoGridColumnFacade::getHorizontalAlign()
302 ENSURE_OR_RETURN( m_xGridColumn
.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT
);
303 return lcl_get( m_xGridColumn
, &XGridColumn::getHorizontalAlign
);
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */