diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index 050e938d2487..512eb347f577 100644 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -530,26 +530,6 @@ void SAL_CALL SVTXGridControl::columnChanged(const ::com::sun::star::awt::grid: Event.newValue>>=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(); } 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 ); 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() ); } } diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx index e8ebd029884c..ff246be0c3ae 100644 --- a/svtools/source/uno/unocontroltablemodel.cxx +++ b/svtools/source/uno/unocontroltablemodel.cxx @@ -43,7 +43,7 @@ using ::rtl::OUString; using namespace ::svt::table; using namespace ::com::sun::star::uno; - +using namespace ::com::sun::star::awt::grid; //-------------------------------------------------------------------- UnoControlTableColumn::UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ) @@ -55,20 +55,17 @@ using namespace ::com::sun::star::uno; ,m_nMaxWidth( 0 ) ,m_nPrefWidth ( 0 ) ,m_eHorizontalAlign( com::sun::star::style::HorizontalAlignment_LEFT ) + ,m_xGridColumn( i_gridColumn ) { - ENSURE_OR_THROW( i_gridColumn.is(), "illegal column" ); - m_sName = i_gridColumn->getTitle(); + m_sName = m_xGridColumn->getTitle(); - // don't do this here. The attribute getters at the XGridColumn implementation do some notifications, - // which is absolutely weird. Sadly, this also means that we can't call the getters while we're - // being constructed, and not yet inserted into the column model. -// m_eHorizontalAlign = i_gridColumn->getHorizontalAlign(); -// m_nWidth = i_gridColumn->getColumnWidth(); -// m_bIsResizable = i_gridColumn->getResizeable(); -// -// m_nPrefWidth = i_gridColumn->getPreferredWidth(); -// m_nMaxWidth = i_gridColumn->getMaxWidth(); -// m_nMinWidth = i_gridColumn->getMinWidth(); + m_eHorizontalAlign = m_xGridColumn->getHorizontalAlign(); + m_nWidth = m_xGridColumn->getColumnWidth(); + m_bIsResizable = m_xGridColumn->getResizeable(); + + m_nPrefWidth = m_xGridColumn->getPreferredWidth(); + m_nMaxWidth = m_xGridColumn->getMaxWidth(); + m_nMinWidth = m_xGridColumn->getMinWidth(); } //-------------------------------------------------------------------- @@ -130,6 +127,15 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setWidth( TableMetrics _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 ) { 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() diff --git a/svtools/source/uno/unocontroltablemodel.hxx b/svtools/source/uno/unocontroltablemodel.hxx index 18f20043d1be..fc6e90f16f6a 100644 --- a/svtools/source/uno/unocontroltablemodel.hxx +++ b/svtools/source/uno/unocontroltablemodel.hxx @@ -47,8 +47,6 @@ using namespace ::svt::table; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::awt::grid; class UnoControlTableColumn : public IColumnModel { @@ -62,8 +60,11 @@ class UnoControlTableColumn : public IColumnModel TableMetrics m_nPrefWidth; ::com::sun::star::style::HorizontalAlignment m_eHorizontalAlign; + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > + m_xGridColumn; + public: - UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ); + UnoControlTableColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn >& i_gridColumn ); UnoControlTableColumn(); // IColumnModel overridables @@ -154,7 +155,7 @@ class UnoControlTableModel : public ITableModel void setRowHeaderName(const std::vector& cellColumnContent); void setVerticalScrollbarVisibility(bool _bVScroll) const; void setHorizontalScrollbarVisibility(bool _bHScroll) const; - void setCellContent(const std::vector >& cellContent); + void setCellContent(const std::vector >& cellContent); void setColumnCount(TableSize _nColCount); void setRowHeaders(bool _bRowHeaders); void setColumnHeaders(bool _bColumnHeaders); diff --git a/toolkit/source/controls/grid/gridcolumn.cxx b/toolkit/source/controls/grid/gridcolumn.cxx index 4094f4433538..0503c69b0493 100644 --- a/toolkit/source/controls/grid/gridcolumn.cxx +++ b/toolkit/source/controls/grid/gridcolumn.cxx @@ -38,7 +38,6 @@ #define HALIGN ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HAlign" )) #define TITLE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" )) #define COLRESIZE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnResize" )) -#define UPDATE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UpdateWidth" )) namespace toolkit { @@ -71,43 +70,22 @@ namespace toolkit } //------------------------------------------------------------------------------------------------------------------ - void GridColumn::broadcast( broadcast_column_type eType, const GridColumnEvent& aEvent ) - { - ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() ); - if( pIter ) - { - ::cppu::OInterfaceIteratorHelper aListIter(*pIter); - while(aListIter.hasMoreElements()) - { - XGridColumnListener* pListener = static_cast(aListIter.next()); - switch( eType ) - { - case column_attribute_changed: pListener->columnChanged(aEvent); break; - } - } - } - } - - //------------------------------------------------------------------------------------------------------------------ - void GridColumn::broadcast_changed(::rtl::OUString name, Any oldValue, Any newValue) + void GridColumn::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue, ::osl::ClearableMutexGuard& i_Guard ) { Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); GridColumnEvent aEvent( xSource, name, oldValue, newValue, m_nIndex); - broadcast( column_attribute_changed, aEvent); - } - //------------------------------------------------------------------------------------------------------------------ - void SAL_CALL GridColumn::updateColumn(const ::rtl::OUString& name, sal_Int32 width) throw (::com::sun::star::uno::RuntimeException) - { - if(PREFWIDTH == name) - m_nPreferredWidth = width; - else if (COLWIDTH == name) - m_nColumnWidth = width; + ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( XGridColumnListener::static_type() ); + + i_Guard.clear(); + if( pIter ) + pIter->notifyEach( &XGridColumnListener::columnChanged, aEvent ); } //------------------------------------------------------------------------------------------------------------------ ::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException) { + ::osl::MutexGuard aGuard( m_aMutex ); return m_aIdentifier; } @@ -120,94 +98,127 @@ namespace toolkit //------------------------------------------------------------------------------------------------------------------ ::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; } //------------------------------------------------------------------------------------------------------------------ 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; - 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) { - broadcast_changed(UPDATE, Any(m_nPreferredWidth), Any()); + ::osl::MutexGuard aGuard( m_aMutex ); return m_nPreferredWidth; } //------------------------------------------------------------------------------------------------------------------ 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; - 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) { + ::osl::MutexGuard aGuard( m_aMutex ); return m_nMaxWidth; } //------------------------------------------------------------------------------------------------------------------ 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; - 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) { + ::osl::MutexGuard aGuard( m_aMutex ); return m_nMinWidth; } //------------------------------------------------------------------------------------------------------------------ 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; - 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) { + ::osl::MutexGuard aGuard( m_aMutex ); return m_sTitle; } //------------------------------------------------------------------------------------------------------------------ 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; - 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) { + ::osl::MutexGuard aGuard( m_aMutex ); return m_bResizeable; } //------------------------------------------------------------------------------------------------------------------ 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; - 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) { + ::osl::MutexGuard aGuard( m_aMutex ); return m_eHorizontalAlign; } //------------------------------------------------------------------------------------------------------------------ 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; - broadcast_changed(HALIGN, Any(m_eHorizontalAlign),Any(align)); + broadcast_changed( HALIGN, Any( m_eHorizontalAlign ), Any( align ), aGuard ); } //------------------------------------------------------------------------------------------------------------------ diff --git a/toolkit/source/controls/grid/gridcolumn.hxx b/toolkit/source/controls/grid/gridcolumn.hxx index 4a47f44ce674..51f9ccf8e4b2 100644 --- a/toolkit/source/controls/grid/gridcolumn.hxx +++ b/toolkit/source/controls/grid/gridcolumn.hxx @@ -43,8 +43,6 @@ namespace toolkit { -enum broadcast_column_type { column_attribute_changed}; - typedef ::cppu::WeakComponentImplHelper2 < ::com::sun::star::awt::grid::XGridColumn , ::com::sun::star::lang::XServiceInfo > 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 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 updateColumn( const ::rtl::OUString& name, ::sal_Int32 width ) throw (::com::sun::star::uno::RuntimeException); // XComponent (base of XGridColumn) 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); private: - void broadcast( broadcast_column_type eType, const ::com::sun::star::awt::grid::GridColumnEvent& aEvent ); - void broadcast_changed( ::rtl::OUString name, ::com::sun::star::uno::Any oldValue, ::com::sun::star::uno::Any newValue); + void broadcast_changed( + ::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; sal_Int32 m_nIndex;