gridsort: removed XGridColumn::updateColumn

The implementation of this column was only a wrapper around what setColumnWidth/setPreferredWidth
would have done. Also, the mechanism how this method was used was really weird, effectively propagating
the (preferred) width from the ITableColumn implementation of the grid peer to the XGridColumn implementation
of the grid column model. This was done each time the (preferred) width was access for reading - not really
a clever solution.
Now, the ITableColumn knows its respective XGridColumn, and simply forwards the (preferred) width as needed.
This commit is contained in:
Frank Schoenheit [fs] 2010-12-17 14:07:29 +01:00
parent 6531aff840
commit caa7780d3a
5 changed files with 88 additions and 87 deletions

View file

@ -530,26 +530,6 @@ void SAL_CALL SVTXGridControl::columnChanged(const ::com::sun::star::awt::grid:
Event.newValue>>=hAlign; Event.newValue>>=hAlign;
m_pTableModel->getColumnModel( Event.index )->setHorizontalAlign(hAlign); m_pTableModel->getColumnModel( Event.index )->setHorizontalAlign(hAlign);
} }
else if(Event.valueName == rtl::OUString::createFromAscii("UpdateWidth"))
{
const PColumnModel pTableColumn( m_pTableModel->getColumnModel( Event.index ) );
ENSURE_OR_RETURN_VOID( !!pTableColumn, "invalid table column!" );
Reference< XGridColumn > xColumn;
try
{
xColumn.set( m_xColumnModel->getColumn( Event.index ), UNO_SET_THROW );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
return;
}
if ( pTableColumn->getPreferredWidth() != 0 )
xColumn->updateColumn(rtl::OUString::createFromAscii("PrefWidth"), pTableColumn->getPreferredWidth());
xColumn->updateColumn(rtl::OUString::createFromAscii("ColWidth"), pTableColumn->getWidth() );
}
pTable->Invalidate(); pTable->Invalidate();
} }
void SAL_CALL SVTXGridControl::dataChanged(const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL SVTXGridControl::dataChanged(const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
@ -972,13 +952,6 @@ void SVTXGridControl::impl_updateColumnsFromModel_nothrow()
UnoControlTableColumn* tableColumn = new UnoControlTableColumn( *colRef ); UnoControlTableColumn* tableColumn = new UnoControlTableColumn( *colRef );
m_pTableModel->appendColumn( PColumnModel( tableColumn ) ); m_pTableModel->appendColumn( PColumnModel( tableColumn ) );
tableColumn->setHorizontalAlign( (*colRef)->getHorizontalAlign() );
tableColumn->setWidth( (*colRef)->getColumnWidth() );
tableColumn->setResizable( (*colRef)->getResizeable() );
tableColumn->setPreferredWidth( (*colRef)->getPreferredWidth() );
tableColumn->setMaxWidth( (*colRef)->getMaxWidth() );
tableColumn->setMinWidth( (*colRef)->getMinWidth() );
} }
} }

View file

@ -43,7 +43,7 @@
using ::rtl::OUString; using ::rtl::OUString;
using namespace ::svt::table; using namespace ::svt::table;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt::grid;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
UnoControlTableColumn::UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ) UnoControlTableColumn::UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn )
@ -55,20 +55,17 @@ using namespace ::com::sun::star::uno;
,m_nMaxWidth( 0 ) ,m_nMaxWidth( 0 )
,m_nPrefWidth ( 0 ) ,m_nPrefWidth ( 0 )
,m_eHorizontalAlign( com::sun::star::style::HorizontalAlignment_LEFT ) ,m_eHorizontalAlign( com::sun::star::style::HorizontalAlignment_LEFT )
,m_xGridColumn( i_gridColumn )
{ {
ENSURE_OR_THROW( i_gridColumn.is(), "illegal column" ); m_sName = m_xGridColumn->getTitle();
m_sName = i_gridColumn->getTitle();
// don't do this here. The attribute getters at the XGridColumn implementation do some notifications, m_eHorizontalAlign = m_xGridColumn->getHorizontalAlign();
// which is absolutely weird. Sadly, this also means that we can't call the getters while we're m_nWidth = m_xGridColumn->getColumnWidth();
// being constructed, and not yet inserted into the column model. m_bIsResizable = m_xGridColumn->getResizeable();
// m_eHorizontalAlign = i_gridColumn->getHorizontalAlign();
// m_nWidth = i_gridColumn->getColumnWidth(); m_nPrefWidth = m_xGridColumn->getPreferredWidth();
// m_bIsResizable = i_gridColumn->getResizeable(); m_nMaxWidth = m_xGridColumn->getMaxWidth();
// m_nMinWidth = m_xGridColumn->getMinWidth();
// m_nPrefWidth = i_gridColumn->getPreferredWidth();
// m_nMaxWidth = i_gridColumn->getMaxWidth();
// m_nMinWidth = i_gridColumn->getMinWidth();
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -130,6 +127,15 @@ using namespace ::com::sun::star::uno;
void UnoControlTableColumn::setWidth( TableMetrics _nWidth ) void UnoControlTableColumn::setWidth( TableMetrics _nWidth )
{ {
m_nWidth = _nWidth; m_nWidth = _nWidth;
try
{
if ( m_xGridColumn.is() )
m_xGridColumn->setColumnWidth( getWidth() );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -165,6 +171,15 @@ using namespace ::com::sun::star::uno;
void UnoControlTableColumn::setPreferredWidth( TableMetrics _nPrefWidth ) void UnoControlTableColumn::setPreferredWidth( TableMetrics _nPrefWidth )
{ {
m_nPrefWidth = _nPrefWidth; m_nPrefWidth = _nPrefWidth;
try
{
if ( m_xGridColumn.is() )
m_xGridColumn->setPreferredWidth( getPreferredWidth() );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
::com::sun::star::style::HorizontalAlignment UnoControlTableColumn::getHorizontalAlign() ::com::sun::star::style::HorizontalAlignment UnoControlTableColumn::getHorizontalAlign()

View file

@ -47,8 +47,6 @@
using namespace ::svt::table; using namespace ::svt::table;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt::grid;
class UnoControlTableColumn : public IColumnModel class UnoControlTableColumn : public IColumnModel
{ {
@ -62,8 +60,11 @@ class UnoControlTableColumn : public IColumnModel
TableMetrics m_nPrefWidth; TableMetrics m_nPrefWidth;
::com::sun::star::style::HorizontalAlignment m_eHorizontalAlign; ::com::sun::star::style::HorizontalAlignment m_eHorizontalAlign;
const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn >
m_xGridColumn;
public: public:
UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ); UnoControlTableColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn >& i_gridColumn );
UnoControlTableColumn(); UnoControlTableColumn();
// IColumnModel overridables // IColumnModel overridables
@ -154,7 +155,7 @@ class UnoControlTableModel : public ITableModel
void setRowHeaderName(const std::vector<rtl::OUString>& cellColumnContent); void setRowHeaderName(const std::vector<rtl::OUString>& cellColumnContent);
void setVerticalScrollbarVisibility(bool _bVScroll) const; void setVerticalScrollbarVisibility(bool _bVScroll) const;
void setHorizontalScrollbarVisibility(bool _bHScroll) const; void setHorizontalScrollbarVisibility(bool _bHScroll) const;
void setCellContent(const std::vector<std::vector< Any > >& cellContent); void setCellContent(const std::vector<std::vector< ::com::sun::star::uno::Any > >& cellContent);
void setColumnCount(TableSize _nColCount); void setColumnCount(TableSize _nColCount);
void setRowHeaders(bool _bRowHeaders); void setRowHeaders(bool _bRowHeaders);
void setColumnHeaders(bool _bColumnHeaders); void setColumnHeaders(bool _bColumnHeaders);

View file

@ -38,7 +38,6 @@
#define HALIGN ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HAlign" )) #define HALIGN ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HAlign" ))
#define TITLE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" )) #define TITLE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" ))
#define COLRESIZE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnResize" )) #define COLRESIZE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnResize" ))
#define UPDATE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UpdateWidth" ))
namespace toolkit namespace toolkit
{ {
@ -71,43 +70,22 @@ namespace toolkit
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void GridColumn::broadcast( broadcast_column_type eType, const GridColumnEvent& aEvent ) void GridColumn::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue, ::osl::ClearableMutexGuard& i_Guard )
{
::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() );
if( pIter )
{
::cppu::OInterfaceIteratorHelper aListIter(*pIter);
while(aListIter.hasMoreElements())
{
XGridColumnListener* pListener = static_cast<XGridColumnListener*>(aListIter.next());
switch( eType )
{
case column_attribute_changed: pListener->columnChanged(aEvent); break;
}
}
}
}
//------------------------------------------------------------------------------------------------------------------
void GridColumn::broadcast_changed(::rtl::OUString name, Any oldValue, Any newValue)
{ {
Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
GridColumnEvent aEvent( xSource, name, oldValue, newValue, m_nIndex); GridColumnEvent aEvent( xSource, name, oldValue, newValue, m_nIndex);
broadcast( column_attribute_changed, aEvent);
}
//------------------------------------------------------------------------------------------------------------------ ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() );
void SAL_CALL GridColumn::updateColumn(const ::rtl::OUString& name, sal_Int32 width) throw (::com::sun::star::uno::RuntimeException)
{ i_Guard.clear();
if(PREFWIDTH == name) if( pIter )
m_nPreferredWidth = width; pIter->notifyEach( &XGridColumnListener::columnChanged, aEvent );
else if (COLWIDTH == name)
m_nColumnWidth = width;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException) ::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::MutexGuard aGuard( m_aMutex );
return m_aIdentifier; return m_aIdentifier;
} }
@ -120,94 +98,127 @@ namespace toolkit
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException) ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException)
{ {
broadcast_changed(UPDATE, Any(m_nColumnWidth), Any()); ::osl::MutexGuard aGuard( m_aMutex );
return m_nColumnWidth; return m_nColumnWidth;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_nColumnWidth == value )
return;
m_nColumnWidth = value; m_nColumnWidth = value;
broadcast_changed(COLWIDTH, Any(m_nColumnWidth),Any(value)); broadcast_changed( COLWIDTH, Any( m_nColumnWidth ), Any( value ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
::sal_Int32 SAL_CALL GridColumn::getPreferredWidth() throw (::com::sun::star::uno::RuntimeException) ::sal_Int32 SAL_CALL GridColumn::getPreferredWidth() throw (::com::sun::star::uno::RuntimeException)
{ {
broadcast_changed(UPDATE, Any(m_nPreferredWidth), Any()); ::osl::MutexGuard aGuard( m_aMutex );
return m_nPreferredWidth; return m_nPreferredWidth;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setPreferredWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setPreferredWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_nPreferredWidth == value )
return;
m_nPreferredWidth = value; m_nPreferredWidth = value;
broadcast_changed(PREFWIDTH, Any(m_nPreferredWidth),Any(value)); broadcast_changed( PREFWIDTH, Any( m_nPreferredWidth ), Any( value ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
::sal_Int32 SAL_CALL GridColumn::getMaxWidth() throw (::com::sun::star::uno::RuntimeException) ::sal_Int32 SAL_CALL GridColumn::getMaxWidth() throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::MutexGuard aGuard( m_aMutex );
return m_nMaxWidth; return m_nMaxWidth;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_nMaxWidth == value )
return;
m_nMaxWidth = value; m_nMaxWidth = value;
broadcast_changed(MAXWIDTH, Any(m_nMaxWidth),Any(value)); broadcast_changed( MAXWIDTH, Any( m_nMaxWidth ), Any( value ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
::sal_Int32 SAL_CALL GridColumn::getMinWidth() throw (::com::sun::star::uno::RuntimeException) ::sal_Int32 SAL_CALL GridColumn::getMinWidth() throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::MutexGuard aGuard( m_aMutex );
return m_nMinWidth; return m_nMinWidth;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_nMinWidth == value )
return;
m_nMinWidth = value; m_nMinWidth = value;
broadcast_changed(MINWIDTH, Any(m_nMinWidth),Any(value)); broadcast_changed( MINWIDTH, Any( m_nMinWidth ), Any( value ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
::rtl::OUString SAL_CALL GridColumn::getTitle() throw (::com::sun::star::uno::RuntimeException) ::rtl::OUString SAL_CALL GridColumn::getTitle() throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::MutexGuard aGuard( m_aMutex );
return m_sTitle; return m_sTitle;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_sTitle == value )
return;
m_sTitle = value; m_sTitle = value;
broadcast_changed(TITLE, Any(m_sTitle),Any(value)); broadcast_changed( TITLE, Any( m_sTitle ), Any( value ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::RuntimeException) sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::MutexGuard aGuard( m_aMutex );
return m_bResizeable; return m_bResizeable;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_bResizeable == value )
return;
m_bResizeable = value; m_bResizeable = value;
broadcast_changed(COLRESIZE, Any(m_bResizeable),Any(value)); broadcast_changed( COLRESIZE, Any( m_bResizeable ), Any( value ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException) HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::MutexGuard aGuard( m_aMutex );
return m_eHorizontalAlign; return m_eHorizontalAlign;
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException) void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException)
{ {
::osl::ClearableMutexGuard aGuard( m_aMutex );
if ( m_eHorizontalAlign == align )
return;
m_eHorizontalAlign = align; m_eHorizontalAlign = align;
broadcast_changed(HALIGN, Any(m_eHorizontalAlign),Any(align)); broadcast_changed( HALIGN, Any( m_eHorizontalAlign ), Any( align ), aGuard );
} }
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------

View file

@ -43,8 +43,6 @@
namespace toolkit namespace toolkit
{ {
enum broadcast_column_type { column_attribute_changed};
typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::awt::grid::XGridColumn typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::awt::grid::XGridColumn
, ::com::sun::star::lang::XServiceInfo , ::com::sun::star::lang::XServiceInfo
> GridColumn_Base; > GridColumn_Base;
@ -74,7 +72,6 @@ public:
virtual void SAL_CALL setHorizontalAlign(::com::sun::star::style::HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setHorizontalAlign(::com::sun::star::style::HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL addColumnListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL addColumnListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeColumnListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL removeColumnListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL updateColumn( const ::rtl::OUString& name, ::sal_Int32 width ) throw (::com::sun::star::uno::RuntimeException);
// XComponent (base of XGridColumn) // XComponent (base of XGridColumn)
virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException);
@ -88,8 +85,12 @@ public:
virtual void SAL_CALL setIndex(sal_Int32 _nIndex)throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setIndex(sal_Int32 _nIndex)throw (::com::sun::star::uno::RuntimeException);
private: private:
void broadcast( broadcast_column_type eType, const ::com::sun::star::awt::grid::GridColumnEvent& aEvent ); void broadcast_changed(
void broadcast_changed( ::rtl::OUString name, ::com::sun::star::uno::Any oldValue, ::com::sun::star::uno::Any newValue); ::rtl::OUString name,
::com::sun::star::uno::Any oldValue,
::com::sun::star::uno::Any newValue,
::osl::ClearableMutexGuard& i_Guard
);
::com::sun::star::uno::Any m_aIdentifier; ::com::sun::star::uno::Any m_aIdentifier;
sal_Int32 m_nIndex; sal_Int32 m_nIndex;