diff options
-rw-r--r-- | svtools/inc/svtools/table/gridtablerenderer.hxx | 7 | ||||
-rwxr-xr-x | svtools/inc/svtools/table/tablemodel.hxx | 9 | ||||
-rw-r--r-- | svtools/inc/svtools/table/tablerenderer.hxx | 6 | ||||
-rw-r--r-- | svtools/source/table/gridtablerenderer.cxx | 6 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol.cxx | 16 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.cxx | 67 | ||||
-rwxr-xr-x | svtools/source/table/tablecontrol_impl.hxx | 10 | ||||
-rw-r--r-- | svtools/source/uno/svtxgridcontrol.cxx | 160 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.cxx | 161 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.hxx | 23 | ||||
-rw-r--r-- | toolkit/source/controls/grid/defaultgriddatamodel.cxx | 19 |
11 files changed, 303 insertions, 181 deletions
diff --git a/svtools/inc/svtools/table/gridtablerenderer.hxx b/svtools/inc/svtools/table/gridtablerenderer.hxx index e474306c0423..01a2e308f3c0 100644 --- a/svtools/inc/svtools/table/gridtablerenderer.hxx +++ b/svtools/inc/svtools/table/gridtablerenderer.hxx @@ -87,17 +87,18 @@ namespace svt { namespace table OutputDevice& _rDevice, const Rectangle& _rRowArea, const StyleSettings& _rStyle ); virtual void PaintRowHeader( + RowPos const i_rowPos, bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea, - const StyleSettings& _rStyle, rtl::OUString& _rText ); + const StyleSettings& _rStyle ); virtual void PaintCellImage( ColPos _nColumn, bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea, const StyleSettings& _rStyle, Image* _pCellData ); - virtual void PaintCellString( ColPos _nColumn, + virtual void PaintCellString( ColPos _nColumn, bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea, - const StyleSettings& _rStyle, rtl::OUString& _rText ); + const StyleSettings& _rStyle, rtl::OUString& _rText ); virtual void ShowCellCursor( Window& _rView, const Rectangle& _rCursorRect); virtual void HideCellCursor( Window& _rView, const Rectangle& _rCursorRect); }; diff --git a/svtools/inc/svtools/table/tablemodel.hxx b/svtools/inc/svtools/table/tablemodel.hxx index 72438bd0e357..273ed003d7aa 100755 --- a/svtools/inc/svtools/table/tablemodel.hxx +++ b/svtools/inc/svtools/table/tablemodel.hxx @@ -405,13 +405,14 @@ namespace svt { namespace table */ virtual void removeTableModelListener( const PTableModelListener& i_listener ) = 0; - /** gets the content of the cells + /** retrieves the content of the given cell */ - virtual std::vector< std::vector< ::com::sun::star::uno::Any > >& getCellContent() = 0; + virtual void getCellContent( RowPos const i_row, ColPos const i_col, ::com::sun::star::uno::Any& o_cellContent ) = 0; - /** gets title of header rows + /** retrieves title of a given row */ - virtual std::vector<rtl::OUString>& getRowHeaderName() = 0; + virtual ::rtl::OUString getRowHeader( RowPos const i_rowPos ) const = 0; + virtual ::com::sun::star::util::Color getLineColor() = 0; virtual ::com::sun::star::util::Color getHeaderBackgroundColor() = 0; virtual ::com::sun::star::util::Color getTextColor() = 0; diff --git a/svtools/inc/svtools/table/tablerenderer.hxx b/svtools/inc/svtools/table/tablerenderer.hxx index f81771dd22e6..a0c54f7a9538 100644 --- a/svtools/inc/svtools/table/tablerenderer.hxx +++ b/svtools/inc/svtools/table/tablerenderer.hxx @@ -175,12 +175,10 @@ namespace svt { namespace table the are into which the row header should be painted @param _rStyle the style to be used for drawing - @param _rText - the title of the header row */ - virtual void PaintRowHeader( bool _bActive, bool _bSelected, + virtual void PaintRowHeader( RowPos const i_rowPos, bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea, - const StyleSettings& _rStyle, rtl::OUString& _rText ) = 0; + const StyleSettings& _rStyle ) = 0; /** paints a certain cell diff --git a/svtools/source/table/gridtablerenderer.cxx b/svtools/source/table/gridtablerenderer.cxx index 8e5bd181a583..869c6c0a6fca 100644 --- a/svtools/source/table/gridtablerenderer.cxx +++ b/svtools/source/table/gridtablerenderer.cxx @@ -197,8 +197,8 @@ namespace svt { namespace table } //-------------------------------------------------------------------- - void GridTableRenderer::PaintRowHeader( bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea, - const StyleSettings& _rStyle, rtl::OUString& _rText ) + void GridTableRenderer::PaintRowHeader( RowPos const i_rowPos, bool _bActive, bool _bSelected, OutputDevice& _rDevice, const Rectangle& _rArea, + const StyleSettings& _rStyle ) { _rDevice.Push( PUSH_LINECOLOR); _rDevice.SetLineColor(_rStyle.GetSeparatorColor()); @@ -220,7 +220,7 @@ namespace svt { namespace table Rectangle aRect(_rArea); aRect.Left()+=4; aRect.Right()-=4; aRect.Bottom()-=2; - _rDevice.DrawText( aRect, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); + _rDevice.DrawText( aRect, m_pImpl->rModel.getRowHeader( i_rowPos ), nHorFlag | nVerFlag | TEXT_DRAW_CLIP); // TODO: active? selected? (void)_bActive; (void)_bSelected; diff --git a/svtools/source/table/tablecontrol.cxx b/svtools/source/table/tablecontrol.cxx index 24486d024091..94932fdcdd01 100644 --- a/svtools/source/table/tablecontrol.cxx +++ b/svtools/source/table/tablecontrol.cxx @@ -363,7 +363,7 @@ namespace svt { namespace table ::rtl::OUString TableControl::GetRowName( sal_Int32 _nIndex) const { - return GetModel()->getRowHeaderName()[_nIndex]; + return GetModel()->getRowHeader( _nIndex ); } // ----------------------------------------------------------------------------- @@ -381,20 +381,18 @@ namespace svt { namespace table // ----------------------------------------------------------------------------- -::com::sun::star::uno::Any TableControl::GetCellContent( sal_Int32 _nRowPos, sal_Int32 _nColPos) const +::com::sun::star::uno::Any TableControl::GetCellContent( sal_Int32 _nRowPos, sal_Int32 _nColPos ) const { - ::com::sun::star::uno::Any cellContent(::com::sun::star::uno::Any(::rtl::OUString::createFromAscii(""))); - std::vector<std::vector< ::com::sun::star::uno::Any > >& aTableContent = GetModel()->getCellContent(); - if(&aTableContent) - cellContent = aTableContent[_nRowPos][_nColPos]; - return cellContent; + Any aCellContent; + GetModel()->getCellContent( _nRowPos, _nColPos, aCellContent ); + return aCellContent; } + // ----------------------------------------------------------------------------- ::rtl::OUString TableControl::GetAccessibleCellText( sal_Int32 _nRowPos, sal_Int32 _nColPos) const { - const ::com::sun::star::uno::Any cellContent = GetCellContent(_nRowPos, _nColPos); - return m_pImpl->convertToString(cellContent); + return m_pImpl->getCellContentAsString( _nRowPos, _nColPos ); } // ----------------------------------------------------------------------------- diff --git a/svtools/source/table/tablecontrol_impl.cxx b/svtools/source/table/tablecontrol_impl.cxx index fbc5e29d1a02..81d188745f69 100755 --- a/svtools/source/table/tablecontrol_impl.cxx +++ b/svtools/source/table/tablecontrol_impl.cxx @@ -50,6 +50,12 @@ namespace svt { namespace table { //........................................................................ + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::graphic::XGraphic; + using ::com::sun::star::uno::Any; + /** === end UNO using === **/ + //==================================================================== //= TempHideCursor //==================================================================== @@ -179,19 +185,17 @@ namespace svt { namespace table { return -1; } - virtual std::vector<std::vector< ::com::sun::star::uno::Any > >& getCellContent() + virtual void getCellContent( RowPos const i_row, ColPos const i_col, ::com::sun::star::uno::Any& o_cellContent ) { - return m_aCellContent; + (void)i_row; + (void)i_col; + o_cellContent.clear(); } - virtual std::vector<rtl::OUString>& getRowHeaderName() + virtual ::rtl::OUString getRowHeader( RowPos const i_rowPos ) const { - aRowHeaderNames.clear(); - aRowHeaderNames.push_back(rtl::OUString::createFromAscii("")); - return aRowHeaderNames; + (void)i_rowPos; + return ::rtl::OUString(); } - private: - std::vector<rtl::OUString> aRowHeaderNames; - std::vector<std::vector< ::com::sun::star::uno::Any > > m_aCellContent; }; @@ -1094,7 +1098,6 @@ namespace svt { namespace table // paint all rows Rectangle aAllDataCellsArea; impl_getAllVisibleDataCellArea( aAllDataCellsArea ); - ::std::vector< std::vector< ::com::sun::star::uno::Any > >& aCellContent = m_pModel->getCellContent(); for ( TableRowGeometry aRowIterator( *this, aAllCellsWithHeaders, getTopRow() ); aRowIterator.isValid(); aRowIterator.moveDown() ) @@ -1132,10 +1135,9 @@ namespace svt { namespace table // paint the row header if ( m_pModel->hasRowHeaders() ) { - Rectangle aCurrentRowHeader( aRowHeaderArea.GetIntersection( aRowIterator.getRect() ) ); - rtl::OUString rowHeaderName = m_pModel->getRowHeaderName()[aRowIterator.getRow()]; - pRenderer->PaintRowHeader( isActiveRow, isSelectedRow, *m_pDataWindow, aCurrentRowHeader, - rStyle, rowHeaderName ); + const Rectangle aCurrentRowHeader( aRowHeaderArea.GetIntersection( aRowIterator.getRect() ) ); + pRenderer->PaintRowHeader( aRowIterator.getRow(), isActiveRow, isSelectedRow, *m_pDataWindow, aCurrentRowHeader, + rStyle ); } if ( !colCount ) continue; @@ -1146,9 +1148,12 @@ namespace svt { namespace table ) { bool isSelectedColumn = false; - ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; - ::com::sun::star::uno::Any rCellData = aCellContent[aRowIterator.getRow()][aCell.getColumn()]; - if(rCellData>>=xGraphic) + + Any aCellContent; + m_pModel->getCellContent( aRowIterator.getRow(), aCell.getColumn(), aCellContent ); + + Reference< XGraphic > xGraphic; + if ( aCellContent >>= xGraphic ) { Image* pImage = new Image(xGraphic); if(pImage!=NULL) @@ -1157,7 +1162,7 @@ namespace svt { namespace table } else { - ::rtl::OUString sContent = convertToString(rCellData); + ::rtl::OUString sContent = convertToString( aCellContent ); pRenderer->PaintCellString( aCell.getColumn(), isSelectedRow || isSelectedColumn, isActiveRow, *m_pDataWindow, aCell.getRect(), rStyle, sContent ); } @@ -1863,6 +1868,14 @@ namespace svt { namespace table } //-------------------------------------------------------------------- + ::rtl::OUString TableControl_Impl::getCellContentAsString( RowPos const i_row, ColPos const i_col ) + { + ::com::sun::star::uno::Any content; + m_pModel->getCellContent( i_row, i_col, content ); + return convertToString( content ); + } + + //-------------------------------------------------------------------- TableSize TableControl_Impl::impl_ni_ScrollRows( TableSize _nRowDelta ) { // compute new top row @@ -2043,8 +2056,7 @@ namespace svt { namespace table com::sun::star::uno::Sequence< ::rtl::OUString > text = m_rAntiImpl.getTextForTooltip(); if(text.getLength()==0 && cols.getLength()==0) { - ::com::sun::star::uno::Any content = m_pModel->getCellContent()[hitRow][hitCol]; - aTooltipText = convertToString(content); + aTooltipText = getCellContentAsString( hitRow, hitCol ); } else if(text.getLength() == 0) { @@ -2052,14 +2064,12 @@ namespace svt { namespace table { if(i==0) { - ::com::sun::star::uno::Any content = m_pModel->getCellContent()[hitRow][cols[i]]; - aTooltipText = convertToString(content); + aTooltipText = getCellContentAsString( hitRow, cols[i] ); } else { - aTooltipText+= ::rtl::OUString::createFromAscii("\n"); - ::com::sun::star::uno::Any content = m_pModel->getCellContent()[hitRow][cols[i]]; - aTooltipText += convertToString(content); + aTooltipText += ::rtl::OUString::createFromAscii("\n"); + aTooltipText += getCellContentAsString( hitRow, cols[i] ); } } } @@ -2088,8 +2098,7 @@ namespace svt { namespace table { if(i==0) { - ::com::sun::star::uno::Any content = m_pModel->getCellContent()[hitRow][cols[i]]; - aTooltipText = text[i] + convertToString(content); + aTooltipText = text[i] + getCellContentAsString( hitRow, cols[i] ); } else { @@ -2097,9 +2106,7 @@ namespace svt { namespace table aTooltipText+= text[i]; if(nCols > i) { - ::com::sun::star::uno::Any content = m_pModel->getCellContent()[hitRow][cols[i]]; - ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; - aTooltipText += convertToString(content); + aTooltipText += getCellContentAsString( hitRow, cols[i] ); } } } diff --git a/svtools/source/table/tablecontrol_impl.hxx b/svtools/source/table/tablecontrol_impl.hxx index 91a57752fca2..9276f8ab95c7 100755 --- a/svtools/source/table/tablecontrol_impl.hxx +++ b/svtools/source/table/tablecontrol_impl.hxx @@ -222,22 +222,32 @@ namespace svt { namespace table */ void ensureVisible( ColPos _nColumn, RowPos _nRow, bool _bAcceptPartialVisibility ); + /** retrieves the content of the given cell, converted to a string + */ + ::rtl::OUString getCellContentAsString( RowPos const i_row, ColPos const i_col ); + /** checks whether the vector with the selected rows contains the current row*/ BOOL isRowSelected(const ::std::vector<RowPos>& selectedRows, RowPos current); bool isRowSelected(RowPos current); + /** returns the position of the current row in the selection vector */ int getRowSelectedNumber(const ::std::vector<RowPos>& selectedRows, RowPos current); + /** _rCellRect contains the region, which should be invalidate after some action e.g. selecting row*/ void invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow, Rectangle& _rCellRect ); + /** to be called when a new row is added to the control*/ void invalidateRow(RowPos _nRowPos, Rectangle& _rCellRect ); + /** returns the vector, which contains the selected rows*/ std::vector<RowPos>& getSelectedRows(); + /** updates the vector, which contains the selected rows after removing the row nRowPos*/ void removeSelectedRow(RowPos _nRowPos); void invalidateRows(); void clearSelection(); + // IAbstractTableControl virtual void hideCursor(); virtual void showCursor(); diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index 12b10f755318..5f3dce2668a7 100644 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -271,32 +271,44 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An Sequence< Sequence< Any > > cellData = m_xDataModel->getData(); if ( cellData.getLength() != 0 ) { - for (int i = 0; i < cellData.getLength(); i++) + const sal_Int32 nDataRowCount = cellData.getLength(); + + const Sequence< ::rtl::OUString > rowHeaders = m_xDataModel->getRowHeaders(); + const sal_Int32 nRowHeaderCount = rowHeaders.getLength(); + + if ( ( nRowHeaderCount != 0 ) && ( nRowHeaderCount != nDataRowCount ) ) + throw GridInvalidDataException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "row header / content data inconsistency" ) ), *this ); + + // check data consistency + sal_Int32 nDataColumnCount = 0; + for ( sal_Int32 i=0; i<nDataRowCount; ++i ) { - std::vector< Any > newRow; - Sequence< Any > rawRowData = cellData[i]; - //check whether the data row vector length matches with the column count - if(m_xColumnModel->getColumnCount() == 0) - { - 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()) - throw GridInvalidDataException(rtl::OUString::createFromAscii("The column count doesn't match with the length of row data"), m_xDataModel); - - for ( int k = 0; k < rawRowData.getLength(); k++) - { - newRow.push_back(rawRowData[k]); - } - m_pTableModel->getCellContent().push_back(newRow); + const Sequence< Any >& rRawRowData = cellData[i]; + if ( ( i > 0 ) && ( rRawRowData.getLength() != nDataColumnCount ) ) + throw GridInvalidDataException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "inconsistent column counts in the row data" ) ), *this ); + nDataColumnCount = rRawRowData.getLength(); } - Sequence< ::rtl::OUString > rowHeaders = m_xDataModel->getRowHeaders(); - std::vector< rtl::OUString > newRow( - comphelper::sequenceToContainer< std::vector<rtl::OUString > >(rowHeaders)); - m_pTableModel->setRowCount(m_xDataModel->getRowCount()); - m_pTableModel->setRowHeaderName(newRow); + // ensure default columns exist, if they have not previously been added + if ( ( nDataColumnCount > 0 ) && ( m_xColumnModel->getColumnCount() == 0 ) ) + m_xColumnModel->setDefaultColumns( nDataColumnCount ); + // this will trigger notifications, which in turn will let us update our m_pTableModel + + // ensure the row data has as much columns as indicate by our model + if ( nDataColumnCount != m_pTableModel->getColumnCount() ) + throw GridInvalidDataException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Grid model's column count doesn't match the row data's column count." ) ), + *this ); + + // finally add the rows + // TODO: suspend the model's notifications for the single rows, do one notification after all + // rows have been inserted + for ( TableSize i = 0; i < nDataRowCount; ++i ) + { + m_pTableModel->appendRow( cellData[i], rowHeaders[i] ); + } } sal_Int32 fontHeight = pTable->PixelToLogic( Size( 0, pTable->GetTextHeight()+3 ), MAP_APPFONT ).Height(); @@ -391,29 +403,23 @@ void SAL_CALL SVTXGridControl::rowAdded(const ::com::sun::star::awt::grid::GridD { ::vos::OGuard aGuard( GetMutex() ); - std::vector< Any > newRow; - Sequence< Any > rawRowData = Event.rowData; - int colCount = m_xColumnModel->getColumnCount(); - if(colCount == 0) + const TableSize rowDataLength = (TableSize)Event.rowData.getLength(); + const TableSize colCount = m_xColumnModel->getColumnCount(); + if ( colCount == 0 ) { - m_xColumnModel->setDefaultColumns(rawRowData.getLength()); + m_xColumnModel->setDefaultColumns( rowDataLength ); // this will trigger notifications, which in turn will let us update our m_pTableModel } - else if((unsigned int)rawRowData.getLength()!=(unsigned)colCount) + if ( rowDataLength != colCount ) throw GridInvalidDataException( ::rtl::OUString::createFromAscii("The column count doesn't match with the length of row data"), *this ); - for ( int k = 0; k < rawRowData.getLength(); k++) - newRow.push_back(rawRowData[k]); - m_pTableModel->getCellContent().push_back(newRow); - if(m_pTableModel->hasRowHeaders()) - m_pTableModel->getRowHeaderName().push_back(Event.headerName); - m_pTableModel->setRowCount(m_pTableModel->getCellContent().size()); + m_pTableModel->appendRow( Event.rowData, Event.headerName ); TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::rowAdded: no control (anymore)!" ); - pTable->InvalidateDataWindow(m_pTableModel->getCellContent().size()-1, 0, false); - if(pTable->isAccessibleAlive()) + pTable->InvalidateDataWindow( m_pTableModel->getRowCount() - 1, 0, false ); + if ( pTable->isAccessibleAlive() ) { pTable->commitGridControlEvent(TABLE_MODEL_CHANGED, makeAny( AccessibleTableModelChange(INSERT, m_pTableModel->getRowCount()-1, m_pTableModel->getRowCount(), 0, m_pTableModel->getColumnCount())), @@ -440,33 +446,30 @@ void SAL_CALL SVTXGridControl::rowRemoved(const ::com::sun::star::awt::grid::Gri if(Event.index == -1) { - if(!isSelectionEmpty()) + if ( !isSelectionEmpty() ) deselectAllRows(); - if(m_pTableModel->hasRowHeaders()) - m_pTableModel->getRowHeaderName().clear(); + + m_pTableModel->clearAllRows(); + pTable->clearSelection(); - m_pTableModel->getCellContent().clear(); - if(pTable->isAccessibleAlive()) + + if ( pTable->isAccessibleAlive() ) { pTable->commitGridControlEvent(TABLE_MODEL_CHANGED, makeAny( AccessibleTableModelChange(DELETE, 0, m_pTableModel->getColumnCount(), 0, m_pTableModel->getColumnCount())), Any()); } } - else if(Event.index >= 0 && Event.index < m_pTableModel->getRowCount()) + else if ( Event.index >= 0 && Event.index < m_pTableModel->getRowCount() ) { - if(isSelectedIndex(Event.index)) + if ( isSelectedIndex( Event.index ) ) { - Sequence<sal_Int32> selected(1); + Sequence< sal_Int32 > selected(1); selected[0]=Event.index; - deselectRows(selected); + deselectRows( selected ); } - if(m_pTableModel->hasRowHeaders()) - m_pTableModel->getRowHeaderName().erase(m_pTableModel->getRowHeaderName().begin()+Event.index); - std::vector<std::vector<Any> >::iterator rowPos =m_pTableModel->getCellContent().begin() + Event.index; - m_pTableModel->getCellContent().erase( rowPos ); + m_pTableModel->removeRow( Event.index ); } - m_pTableModel->setRowCount(m_pTableModel->getCellContent().size()); pTable->InvalidateDataWindow(Event.index, Event.index, true); if(pTable->isAccessibleAlive()) { @@ -521,58 +524,63 @@ void SAL_CALL SVTXGridControl::columnChanged(const ::com::sun::star::awt::grid: } 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) { ::vos::OGuard aGuard( GetMutex() ); TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::dataChanged: no control (anymore)!" ); - if(Event.valueName == rtl::OUString::createFromAscii("RowHeight")) + if ( Event.valueName.equalsAscii( "RowHeight" ) ) { sal_Int32 rowHeight = m_pTableModel->getRowHeight(); Event.newValue>>=rowHeight; m_pTableModel->setRowHeight(rowHeight); pTable->Invalidate(); } - else if(Event.valueName == rtl::OUString::createFromAscii("RowHeaderWidth")) + else if ( Event.valueName.equalsAscii( "RowHeaderWidth" ) ) { sal_Int32 rowHeaderWidth = m_pTableModel->getRowHeaderWidth(); Event.newValue>>=rowHeaderWidth; m_pTableModel->setRowHeaderWidth(rowHeaderWidth); pTable->Invalidate(); } - else if(Event.valueName == rtl::OUString::createFromAscii("RowHeaders")) + else if ( Event.valueName.equalsAscii( "RowHeaders" ) ) { - Sequence< rtl::OUString > headers(0); - Event.newValue>>=headers; - std::vector< rtl::OUString > headerNames( comphelper::sequenceToContainer <std::vector< rtl::OUString > >(headers) ); - m_pTableModel->setRowHeaderName(headerNames); + Sequence< rtl::OUString > rowHeaders; + OSL_VERIFY( Event.newValue >>= rowHeaders ); + m_pTableModel->setRowHeaderNames( rowHeaders ); pTable->Invalidate(); } - else if(Event.valueName == rtl::OUString::createFromAscii("CellUpdated")) + else if ( Event.valueName.equalsAscii( "CellUpdated" ) ) { - std::vector< std::vector< Any > >& rowContent = m_pTableModel->getCellContent(); sal_Int32 col = -1; - Event.oldValue>>=col; - rowContent[Event.index][col] = Event.newValue; - pTable->InvalidateDataWindow(Event.index, Event.index, false); + OSL_VERIFY( Event.oldValue >>= col ); + + m_pTableModel->updateCellContent( Event.index, col, Event.newValue ); + pTable->InvalidateDataWindow( Event.index, Event.index, false ); } - else if(Event.valueName == rtl::OUString::createFromAscii("RowUpdated")) + else if ( Event.valueName.equalsAscii( "RowUpdated" ) ) { - std::vector<std::vector< Any > >& rowContent = m_pTableModel->getCellContent(); - Sequence< sal_Int32 > cols(0); - Sequence< Any > values(0); - Event.oldValue>>=cols; - Event.newValue>>=values; - for(int i = 0; i< cols.getLength(); i++) + Sequence< sal_Int32 > cols; + OSL_VERIFY( Event.oldValue >>= cols ); + + Sequence< Any > values; + OSL_VERIFY( Event.newValue >>= values ); + + ENSURE_OR_RETURN_VOID( cols.getLength() == values.getLength(), "SVTXGridControl::dataChanged: inconsistent array lengths!" ); + + const TableSize columnCount = m_pTableModel->getColumnCount(); + // TODO: suspend listener notification, so that the table model doesn't notify |cols.size()| different events. + // Instead, only one event should be broadcasted. + for ( ColPos i = 0; i< cols.getLength(); ++i ) { - if(cols[i]>=0 && cols[i]<m_pTableModel->getColumnCount()) - rowContent[Event.index][cols[i]]=values[i]; - else - break; + ENSURE_OR_CONTINUE( ( cols[i] >= 0 ) && ( cols[i] < columnCount ), "illegal column index" ); + m_pTableModel->updateCellContent( Event.index, cols[i], values[i] ); } - pTable->InvalidateDataWindow(Event.index, Event.index, false); + + pTable->InvalidateDataWindow( Event.index, Event.index, false ); } } diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx index aa00f799dfd0..ed297b42dcf8 100644 --- a/svtools/source/uno/unocontroltablemodel.cxx +++ b/svtools/source/uno/unocontroltablemodel.cxx @@ -27,17 +27,20 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svtools.hxx" -#include "unocontroltablemodel.hxx" -#include <com/sun/star/view/SelectionType.hpp> -#include "svtools/table/gridtablerenderer.hxx" #include "svtools/table/defaultinputhandler.hxx" +#include "svtools/table/gridtablerenderer.hxx" #include "svtools/table/tablecontrol.hxx" +#include "unocontroltablemodel.hxx" + +#include <com/sun/star/awt/grid/XGridColumn.hpp> +#include <com/sun/star/view/SelectionType.hpp> +#include <comphelper/processfactory.hxx> + #include <comphelper/sequence.hxx> +#include <comphelper/stlunosequence.hxx> #include <rtl/ref.hxx> -#include <tools/debug.hxx> #include <toolkit/helper/property.hxx> -#include <comphelper/processfactory.hxx> -#include <com/sun/star/awt/grid/XGridColumn.hpp> +#include <tools/debug.hxx> #include <tools/diagnose_ex.h> using ::rtl::OUString; @@ -204,26 +207,26 @@ using namespace ::com::sun::star::awt::grid; typedef ::std::vector< PTableModelListener > ModellListeners; struct UnoControlTableModel_Impl { - ::std::vector< PColumnModel > aColumns; - TableSize nRowCount; - bool bHasColumnHeaders; - bool bHasRowHeaders; - ScrollbarVisibility eVScrollMode; - ScrollbarVisibility eHScrollMode; - PTableRenderer pRenderer; - PTableInputHandler pInputHandler; - TableMetrics nRowHeight; - TableMetrics nColumnHeaderHeight; - TableMetrics nRowHeaderWidth; - ::std::vector<rtl::OUString > aRowHeadersTitle; - ::std::vector<std::vector< Any > > aCellContent; - ::com::sun::star::util::Color m_nLineColor; - ::com::sun::star::util::Color m_nHeaderColor; - ::com::sun::star::util::Color m_nTextColor; - ::com::sun::star::util::Color m_nRowColor1; - ::com::sun::star::util::Color m_nRowColor2; + ::std::vector< PColumnModel > aColumns; + TableSize nRowCount; + bool bHasColumnHeaders; + bool bHasRowHeaders; + ScrollbarVisibility eVScrollMode; + ScrollbarVisibility eHScrollMode; + PTableRenderer pRenderer; + PTableInputHandler pInputHandler; + TableMetrics nRowHeight; + TableMetrics nColumnHeaderHeight; + TableMetrics nRowHeaderWidth; + ::std::vector< ::rtl::OUString > aRowHeadersTitle; + ::std::vector< ::std::vector< Any > > aCellContent; + ::com::sun::star::util::Color m_nLineColor; + ::com::sun::star::util::Color m_nHeaderColor; + ::com::sun::star::util::Color m_nTextColor; + ::com::sun::star::util::Color m_nRowColor1; + ::com::sun::star::util::Color m_nRowColor2; ::com::sun::star::style::VerticalAlignment m_eVerticalAlign; - ModellListeners m_aListeners; + ModellListeners m_aListeners; UnoControlTableModel_Impl() :aColumns ( ) @@ -308,11 +311,6 @@ using namespace ::com::sun::star::awt::grid; m_pImpl->aColumns.resize( _nColCount); } //-------------------------------------------------------------------- - void UnoControlTableModel::setRowCount(TableSize _nRowCount) - { - m_pImpl->nRowCount = _nRowCount; - } - //-------------------------------------------------------------------- bool UnoControlTableModel::isCellEditable( ColPos col, RowPos row ) const { (void)col; @@ -490,20 +488,111 @@ using namespace ::com::sun::star::awt::grid; m_pImpl->aCellContent = cellContent; } - std::vector<std::vector< Any > >& UnoControlTableModel::getCellContent() + //-------------------------------------------------------------------- + void UnoControlTableModel::getCellContent( RowPos const i_row, ColPos const i_col, Any& o_cellContent ) + { + ENSURE_OR_RETURN_VOID( ( i_row >= 0 ) && ( i_row < m_pImpl->aCellContent.size() ), + "UnoControlTableModel::getCellContent: illegal row index!" ); + ::std::vector< Any >& rRowContent( m_pImpl->aCellContent[ i_row ] ); + ENSURE_OR_RETURN_VOID( ( i_col >= 0 ) && ( i_col < rRowContent.size() ), + "UnoControlTableModel::getCellContent: illegal column index" ); + o_cellContent = rRowContent[ i_col ]; + } + + //-------------------------------------------------------------------- + void UnoControlTableModel::updateCellContent( RowPos const i_row, ColPos const i_col, Any const & i_cellContent ) + { + ENSURE_OR_RETURN_VOID( ( i_row >= 0 ) && ( i_row < m_pImpl->aCellContent.size() ), + "UnoControlTableModel::getCellContent: illegal row index!" ); + ::std::vector< Any >& rRowContent( m_pImpl->aCellContent[ i_row ] ); + ENSURE_OR_RETURN_VOID( ( i_col >= 0 ) && ( i_col < rRowContent.size() ), + "UnoControlTableModel::getCellContent: illegal column index" ); + rRowContent[ i_col ] = i_cellContent; + + // TODO: listener notification + } + + //-------------------------------------------------------------------- + void UnoControlTableModel::setRowHeaderNames( const Sequence< ::rtl::OUString >& i_rowHeaders ) + { + ENSURE_OR_RETURN_VOID( size_t( i_rowHeaders.getLength() ) == m_pImpl->aRowHeadersTitle.size(), + "UnoControlTableModel::setRowHeaderNames: illegal number of row headers!" ); + // this method is not intended to set a new row count, but only to modify the existing row headers + + ::std::copy( + ::comphelper::stl_begin( i_rowHeaders ), + ::comphelper::stl_end( i_rowHeaders ), + m_pImpl->aRowHeadersTitle.begin() + ); + + // TODO: listener notification + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoControlTableModel::getRowHeader( RowPos const i_rowPos ) const { - return m_pImpl->aCellContent; + ENSURE_OR_RETURN( ( i_rowPos >= 0 ) && ( i_rowPos < m_pImpl->aRowHeadersTitle.size() ), + "UnoControlTableModel::getRowHeader: illegal row position!", ::rtl::OUString() ); + return m_pImpl->aRowHeadersTitle[ i_rowPos ]; } + //-------------------------------------------------------------------- - void UnoControlTableModel::setRowHeaderName(const std::vector<rtl::OUString>& cellColumnContent) + void UnoControlTableModel::appendRow( Sequence< Any > const & i_rowData, ::rtl::OUString const & i_rowHeader ) { - m_pImpl->aRowHeadersTitle = cellColumnContent; + ENSURE_OR_RETURN_VOID( i_rowData.getLength() == getColumnCount(), "UnoControlTableModel::appendRow: invalid row data!" ); + + // add row data + ::std::vector< Any > newRow( i_rowData.getLength() ); + if ( !newRow.empty() ) + ::std::copy( + ::comphelper::stl_begin( i_rowData ), + ::comphelper::stl_end( i_rowData ), + newRow.begin() + ); + + m_pImpl->aCellContent.push_back( newRow ); + + if ( hasRowHeaders() ) + m_pImpl->aRowHeadersTitle.push_back( i_rowHeader ); + + ++m_pImpl->nRowCount; + + // TODO: listener notification } - std::vector<rtl::OUString>& UnoControlTableModel::getRowHeaderName() + //-------------------------------------------------------------------- + void UnoControlTableModel::removeRow( RowPos const i_rowPos ) { - return m_pImpl->aRowHeadersTitle; + ENSURE_OR_RETURN_VOID( ( i_rowPos >= 0 ) && ( i_rowPos < getRowCount() ), "UnoControlTableModel::removeRow: illegal row position!" ); + + if ( hasRowHeaders() ) + m_pImpl->aRowHeadersTitle.erase( m_pImpl->aRowHeadersTitle.begin() + i_rowPos ); + + const ::std::vector< ::std::vector< Any > >::iterator contentPos = m_pImpl->aCellContent.begin() + i_rowPos; + m_pImpl->aCellContent.erase( contentPos ); + + --m_pImpl->nRowCount; + + // TODO: listener notification } + + //-------------------------------------------------------------------- + void UnoControlTableModel::clearAllRows() + { + if ( hasRowHeaders() ) + { + ::std::vector< ::rtl::OUString > aEmpty; + m_pImpl->aRowHeadersTitle.swap( aEmpty ); + } + + ::std::vector< ::std::vector< Any > > aEmptyContent; + m_pImpl->aCellContent.swap( aEmptyContent ); + + m_pImpl->nRowCount = 0; + + // TODO: listener notification + } + //-------------------------------------------------------------------- ::com::sun::star::util::Color UnoControlTableModel::getLineColor() { diff --git a/svtools/source/uno/unocontroltablemodel.hxx b/svtools/source/uno/unocontroltablemodel.hxx index ac943200b77a..d7192cbd7a9b 100644 --- a/svtools/source/uno/unocontroltablemodel.hxx +++ b/svtools/source/uno/unocontroltablemodel.hxx @@ -133,8 +133,8 @@ class UnoControlTableModel : public ITableModel virtual ScrollbarVisibility getHorizontalScrollbarVisibility() const; virtual void addTableModelListener( const PTableModelListener& i_listener ); virtual void removeTableModelListener( const PTableModelListener& i_listener ); - virtual std::vector< std::vector< ::com::sun::star::uno::Any > >& getCellContent(); - virtual std::vector<rtl::OUString>& getRowHeaderName(); + virtual void getCellContent( RowPos const i_row, ColPos const i_col, ::com::sun::star::uno::Any& o_cellContent ); + virtual ::rtl::OUString getRowHeader( RowPos const i_rowPos ) const; virtual ::com::sun::star::util::Color getLineColor(); virtual ::com::sun::star::util::Color getHeaderBackgroundColor(); virtual ::com::sun::star::util::Color getTextColor(); @@ -143,9 +143,21 @@ class UnoControlTableModel : public ITableModel virtual ::com::sun::star::style::VerticalAlignment getVerticalAlign(); + // column write access + void appendColumn( const PColumnModel& i_column ); + void insertColumn( ColPos const i_position, const PColumnModel& i_column ); + void removeAllColumns(); + + // row write access + void setRowHeaderNames( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& i_rowHeaders ); + void appendRow( ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > const & i_rowData, ::rtl::OUString const & i_rowHeader ); + void removeRow( RowPos const i_rowPos ); + void clearAllRows(); + + // cell data write access + void updateCellContent( RowPos const i_rowPos, ColPos const i_colPos, ::com::sun::star::uno::Any const & i_cellContent ); + // other operations - void setRowCount(TableSize _nRowCount); - void setRowHeaderName(const std::vector<rtl::OUString>& cellColumnContent); void setVerticalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const; void setHorizontalScrollbarVisibility( ScrollbarVisibility const i_visibility ) const; void setCellContent(const std::vector<std::vector< ::com::sun::star::uno::Any > >& cellContent); @@ -158,9 +170,6 @@ class UnoControlTableModel : public ITableModel void setOddRowBackgroundColor(::com::sun::star::util::Color _rColor); void setEvenRowBackgroundColor(::com::sun::star::util::Color _rColor); void setVerticalAlign(::com::sun::star::style::VerticalAlignment _rAlign); - void appendColumn( const PColumnModel& i_column ); - void insertColumn( ColPos const i_position, const PColumnModel& i_column ); - void removeAllColumns(); }; inline void UnoControlTableModel::SetColumnWidth( ColPos _nColumn, TableMetrics _nWidth100thMM ) diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx index bf6eb5ed501c..6adf7b994035 100644 --- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx +++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx @@ -149,24 +149,25 @@ void SAL_CALL DefaultGridDataModel::setRowHeight(::sal_Int32 value) throw (::com //--------------------------------------------------------------------- -void SAL_CALL DefaultGridDataModel::setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & value) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL DefaultGridDataModel::setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & i_rowHeaders ) throw (::com::sun::star::uno::RuntimeException) { - ::com::sun::star::uno::Sequence< ::rtl::OUString > oldValue( comphelper::containerToSequence(rowHeaders) ); + ::com::sun::star::uno::Sequence< ::rtl::OUString > oldValue( comphelper::containerToSequence( rowHeaders ) ); - std::vector< rtl::OUString>::iterator iterator; - int i = 0; - int sequenceSize = value.getLength(); + const sal_Int32 sequenceSize = i_rowHeaders.getLength(); - for(iterator = rowHeaders.begin(); iterator != rowHeaders.end(); iterator++) + sal_Int32 i = 0; + for ( std::vector< rtl::OUString >::iterator iterator = rowHeaders.begin(); + iterator != rowHeaders.end(); + ++iterator, ++i + ) { if ( sequenceSize > i ) - *iterator = value[i]; + *iterator = i_rowHeaders[i]; else *iterator = ::rtl::OUString(); - i++; } - broadcast_changed( ROWHEADERS, 0, Any(oldValue), Any(comphelper::containerToSequence(rowHeaders)) ); + broadcast_changed( ROWHEADERS, 0, Any( oldValue ), Any( comphelper::containerToSequence( rowHeaders ) ) ); } //--------------------------------------------------------------------- |