diff options
-rw-r--r-- | svtools/source/uno/svtxgridcontrol.cxx | 13 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.cxx | 121 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.hxx | 11 |
3 files changed, 68 insertions, 77 deletions
diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index 2dee47478120..1a6ce6ff88e5 100644 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -278,12 +278,8 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An //check whether the data row vector length matches with the column count if(m_xColumnModel->getColumnCount() == 0) { - for ( ::svt::table::ColPos col = 0; col < rawRowData.getLength(); ++col ) - { - UnoControlTableColumn* tableColumn = new UnoControlTableColumn(); - m_pTableModel->appendColumn( PColumnModel( tableColumn ) ); - } m_xColumnModel->setDefaultColumns(rawRowData.getLength()); + // this will trigger notifications, which in turn will let us update our m_pTableModel } else if((unsigned int)rawRowData.getLength()!=(unsigned)m_pTableModel->getColumnCount()) @@ -400,13 +396,8 @@ void SAL_CALL SVTXGridControl::rowAdded(const ::com::sun::star::awt::grid::GridD int colCount = m_xColumnModel->getColumnCount(); if(colCount == 0) { - Reference<XGridColumnListener> listener(*this,UNO_QUERY_THROW); m_xColumnModel->setDefaultColumns(rawRowData.getLength()); - for ( ::svt::table::ColPos col = 0; col < rawRowData.getLength(); ++col ) - { - UnoControlTableColumn* tableColumn = new UnoControlTableColumn(); - m_pTableModel->appendColumn( PColumnModel( tableColumn ) ); - } + // this will trigger notifications, which in turn will let us update our m_pTableModel } else if((unsigned int)rawRowData.getLength()!=(unsigned)colCount) diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx index 8ee40f925591..4ed310aa8b28 100644 --- a/svtools/source/uno/unocontroltablemodel.cxx +++ b/svtools/source/uno/unocontroltablemodel.cxx @@ -46,38 +46,42 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt::grid; //-------------------------------------------------------------------- - UnoControlTableColumn::UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ) - :m_nID( 0 ) - ,m_sName() - ,m_bIsResizable( true ) - ,m_nWidth( 4 ) - ,m_nMinWidth( 0 ) - ,m_nMaxWidth( 0 ) - ,m_nPrefWidth ( 0 ) - ,m_eHorizontalAlign( com::sun::star::style::HorizontalAlignment_LEFT ) - ,m_xGridColumn( i_gridColumn ) + namespace { - m_sName = m_xGridColumn->getTitle(); - - m_eHorizontalAlign = m_xGridColumn->getHorizontalAlign(); - m_nWidth = m_xGridColumn->getColumnWidth(); - m_bIsResizable = m_xGridColumn->getResizeable(); + template< class ATTRIBUTE_TYPE > + void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( ATTRIBUTE_TYPE ), + ATTRIBUTE_TYPE i_value ) + { + try + { + (i_column.get()->*i_setter) ( i_value ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } - m_nPrefWidth = m_xGridColumn->getPreferredWidth(); - m_nMaxWidth = m_xGridColumn->getMaxWidth(); - m_nMinWidth = m_xGridColumn->getMinWidth(); + template< class ATTRIBUTE_TYPE > + ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() ) + { + ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE(); + try + { + value = (i_column.get()->*i_getter)(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return value; + } } //-------------------------------------------------------------------- - UnoControlTableColumn::UnoControlTableColumn() + UnoControlTableColumn::UnoControlTableColumn( const Reference< XGridColumn >& i_gridColumn ) :m_nID( 0 ) - ,m_sName() - ,m_bIsResizable( true ) - ,m_nWidth( 4 ) - ,m_nMinWidth( 0 ) - ,m_nMaxWidth( 0 ) - ,m_nPrefWidth ( 0 ) - ,m_eHorizontalAlign(com::sun::star::style::HorizontalAlignment(0)) + ,m_xGridColumn( i_gridColumn, UNO_SET_THROW ) { } @@ -97,100 +101,101 @@ using namespace ::com::sun::star::awt::grid; //-------------------------------------------------------------------- String UnoControlTableColumn::getName() const { - return m_sName; + ::rtl::OUString sName; + try + { + sName = m_xGridColumn->getTitle(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return sName; } //-------------------------------------------------------------------- void UnoControlTableColumn::setName( const String& _rName ) { - m_sName = _rName; + try + { + m_xGridColumn->setTitle( _rName ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } + //-------------------------------------------------------------------- bool UnoControlTableColumn::isResizable() const { - return m_bIsResizable; + return lcl_get( m_xGridColumn, &XGridColumn::getResizeable ); } //-------------------------------------------------------------------- void UnoControlTableColumn::setResizable( bool _bResizable ) { - m_bIsResizable = _bResizable; + return lcl_set( m_xGridColumn, &XGridColumn::setResizeable, sal_Bool( _bResizable ) ); } //-------------------------------------------------------------------- TableMetrics UnoControlTableColumn::getWidth() const { - return m_nWidth; + return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth ); } //-------------------------------------------------------------------- void UnoControlTableColumn::setWidth( TableMetrics _nWidth ) { - m_nWidth = _nWidth; - try - { - if ( m_xGridColumn.is() ) - m_xGridColumn->setColumnWidth( getWidth() ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } + lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth ); } //-------------------------------------------------------------------- TableMetrics UnoControlTableColumn::getMinWidth() const { - return m_nMinWidth; + return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth ); } //-------------------------------------------------------------------- void UnoControlTableColumn::setMinWidth( TableMetrics _nMinWidth ) { - m_nMinWidth = _nMinWidth; + lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMinWidth ); } //-------------------------------------------------------------------- TableMetrics UnoControlTableColumn::getMaxWidth() const { - return m_nMaxWidth; + return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth ); } //-------------------------------------------------------------------- void UnoControlTableColumn::setMaxWidth( TableMetrics _nMaxWidth ) { - m_nMaxWidth = _nMaxWidth; + lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMaxWidth ); } + //-------------------------------------------------------------------- TableMetrics UnoControlTableColumn::getPreferredWidth() const { - return m_nPrefWidth; + return lcl_get( m_xGridColumn, &XGridColumn::getPreferredWidth ); } //-------------------------------------------------------------------- void UnoControlTableColumn::setPreferredWidth( TableMetrics _nPrefWidth ) { - m_nPrefWidth = _nPrefWidth; - try - { - if ( m_xGridColumn.is() ) - m_xGridColumn->setPreferredWidth( getPreferredWidth() ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } + lcl_set( m_xGridColumn, &XGridColumn::setPreferredWidth, _nPrefWidth ); } + //-------------------------------------------------------------------- ::com::sun::star::style::HorizontalAlignment UnoControlTableColumn::getHorizontalAlign() { - return m_eHorizontalAlign; + return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign ); } //-------------------------------------------------------------------- void UnoControlTableColumn::setHorizontalAlign( com::sun::star::style::HorizontalAlignment _align ) { - m_eHorizontalAlign = _align; + lcl_set( m_xGridColumn, &XGridColumn::setHorizontalAlign, _align ); } //==================================================================== diff --git a/svtools/source/uno/unocontroltablemodel.hxx b/svtools/source/uno/unocontroltablemodel.hxx index f81c0bf88433..2a627358554f 100644 --- a/svtools/source/uno/unocontroltablemodel.hxx +++ b/svtools/source/uno/unocontroltablemodel.hxx @@ -52,20 +52,12 @@ class UnoControlTableColumn : public IColumnModel { private: ColumnID m_nID; - String m_sName; - bool m_bIsResizable; - TableMetrics m_nWidth; - TableMetrics m_nMinWidth; - TableMetrics m_nMaxWidth; - 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 ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn >& i_gridColumn ); - UnoControlTableColumn(); // IColumnModel overridables virtual ColumnID getID() const; @@ -84,6 +76,9 @@ class UnoControlTableColumn : public IColumnModel virtual void setPreferredWidth( TableMetrics _nPrefWidth ); virtual ::com::sun::star::style::HorizontalAlignment getHorizontalAlign(); virtual void setHorizontalAlign(::com::sun::star::style::HorizontalAlignment _xAlign); + + private: + UnoControlTableColumn(); // not implemented }; struct UnoControlTableModel_Impl; |