From 99d003c030ec5d547c452efdc42be3a3fa6810fa Mon Sep 17 00:00:00 2001 From: Mihaela Kedikova Date: Mon, 22 Mar 2010 11:17:10 +0100 Subject: recent changes for grid control --- svtools/inc/svtools/accessibletable.hxx | 3 +- svtools/inc/svtools/table/tablecontrol.hxx | 16 +- svtools/inc/svtools/table/tabledatawindow.hxx | 10 +- svtools/source/table/gridtablerenderer.cxx | 22 +- svtools/source/table/tablecontrol.cxx | 66 +++- svtools/source/table/tablecontrol_impl.cxx | 335 ++++++++--------- svtools/source/table/tablecontrol_impl.hxx | 14 +- svtools/source/table/tabledatawindow.cxx | 10 +- svtools/source/uno/svtxgridcontrol.cxx | 407 ++++++++++++++------- svtools/source/uno/svtxgridcontrol.hxx | 33 +- svtools/source/uno/unocontroltablemodel.cxx | 93 +---- svtools/source/uno/unocontroltablemodel.hxx | 5 +- toolkit/inc/toolkit/helper/listenermultiplexer.hxx | 10 +- toolkit/inc/toolkit/helper/property.hxx | 1 + .../controls/grid/defaultgridcolumnmodel.cxx | 170 +++++---- .../controls/grid/defaultgridcolumnmodel.hxx | 20 +- .../source/controls/grid/defaultgriddatamodel.cxx | 7 +- toolkit/source/controls/grid/gridcolumn.cxx | 79 +++- toolkit/source/controls/grid/gridcolumn.hxx | 12 +- toolkit/source/controls/grid/gridcontrol.cxx | 58 ++- toolkit/source/controls/grid/gridcontrol.hxx | 7 +- toolkit/source/helper/listenermultiplexer.cxx | 5 + toolkit/source/helper/property.cxx | 5 +- vcl/inc/vcl/vclevent.hxx | 1 + 24 files changed, 794 insertions(+), 595 deletions(-) diff --git a/svtools/inc/svtools/accessibletable.hxx b/svtools/inc/svtools/accessibletable.hxx index e13a0afe9469..86bd2cbbcea1 100755 --- a/svtools/inc/svtools/accessibletable.hxx +++ b/svtools/inc/svtools/accessibletable.hxx @@ -34,7 +34,6 @@ #include #include #include -#include // ============================================================================ @@ -128,6 +127,8 @@ public: virtual ::rtl::OUString GetColumnName( sal_Int32 _nIndex ) const = 0; virtual ::com::sun::star::uno::Any GetCellContent( sal_Int32 _nRowPos, sal_Int32 _nColPos) const = 0; virtual std::vector& GetSelectedRows() = 0; + virtual void RemoveSelectedRow(sal_Int32 _nRowPos) = 0; + virtual ::rtl::OUString GetAccessibleCellText(sal_Int32 _nRowPos, sal_Int32 _nColPos) = 0; }; // ---------------------------------------------------------------------------- diff --git a/svtools/inc/svtools/table/tablecontrol.hxx b/svtools/inc/svtools/table/tablecontrol.hxx index 59720cfd0602..b3aeb9d587e3 100644 --- a/svtools/inc/svtools/table/tablecontrol.hxx +++ b/svtools/inc/svtools/table/tablecontrol.hxx @@ -67,12 +67,13 @@ namespace svt { namespace table class TableControl : public Control, public IAccessibleTable { private: - DECL_LINK( ImplMouseButtonDownHdl, MouseEvent* ); - DECL_LINK( ImplMouseButtonUpHdl, MouseEvent* ); + DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* ); TableControl_Impl* m_pImpl; ::com::sun::star::uno::Sequence< sal_Int32 >& m_nCols; ::com::sun::star::uno::Sequence< ::rtl::OUString >& m_aText; + Link m_aSelectHdl; + bool m_bSelectionChanged; public: ::std::auto_ptr< AccessibleTableControl_Impl > m_pAccessTable; @@ -152,16 +153,19 @@ namespace svt { namespace table } virtual void Resize(); + virtual void Select(); + void SetSelectHdl( const Link& rLink ) { m_aSelectHdl = rLink; } + const Link& GetSelectHdl() const { return m_aSelectHdl; } + /**invalidates the table if table has been changed e.g. new row added */ - void InvalidateDataWindow(RowPos _nRowStart, bool _bRemoved); + void InvalidateDataWindow(RowPos _nRowStart, RowPos _nRowEnd, bool _bRemoved); /**gets the vector, which contains the selected rows */ std::vector& GetSelectedRows(); /**after removing a row, updates the vector which contains the selected rows if the row, which should be removed, is selected, it will be erased from the vector */ - void removeSelectedRow(RowPos _nRowPos); SelectionEngine* getSelEngine(); TableDataWindow* getDataWindow(); @@ -209,10 +213,12 @@ namespace svt { namespace table virtual sal_Bool HasColHeader(); virtual sal_Bool isAccessibleAlive( ) const; virtual void commitGridControlEvent( sal_Int16 _nEventId, const com::sun::star::uno::Any& _rNewValue, const com::sun::star::uno::Any& _rOldValue ); - + virtual void RemoveSelectedRow(RowPos _nRowPos); + virtual ::rtl::OUString GetAccessibleCellText(sal_Int32 _nRowPos, sal_Int32 _nColPos); ::com::sun::star::uno::Sequence< sal_Int32 >& getColumnsForTooltip(); ::com::sun::star::uno::Sequence< ::rtl::OUString >& getTextForTooltip(); void setTooltip(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aText, const ::com::sun::star::uno::Sequence< sal_Int32 >& nCols); + void selectionChanged(bool _bChanged); protected: /// retrieves the XAccessible implementation associated with the GridControl instance diff --git a/svtools/inc/svtools/table/tabledatawindow.hxx b/svtools/inc/svtools/table/tabledatawindow.hxx index 564680a39347..1cf98300d790 100644 --- a/svtools/inc/svtools/table/tabledatawindow.hxx +++ b/svtools/inc/svtools/table/tabledatawindow.hxx @@ -51,15 +51,11 @@ namespace svt { namespace table friend class TableFunctionSet; private: TableControl_Impl& m_rTableControl; - Link m_aMouseButtonDownHdl; - Link m_aMouseButtonUpHdl; - + Link m_aSelectHdl; public: TableDataWindow( TableControl_Impl& _rTableControl ); - inline void SetMouseButtonDownHdl( const Link& rLink ) { m_aMouseButtonDownHdl = rLink; } - inline const Link& GetMouseButtonDownHdl() const { return m_aMouseButtonDownHdl; } - inline void SetMouseButtonUpHdl( const Link& rLink ) { m_aMouseButtonUpHdl = rLink; } - inline const Link& GetMouseButtonUpHdl() const { return m_aMouseButtonUpHdl; } + inline void SetSelectHdl( const Link& rLink ) { m_aSelectHdl = rLink; } + inline const Link& GetSelectHdl() const { return m_aSelectHdl; } // Window overridables virtual void Paint( const Rectangle& rRect ); diff --git a/svtools/source/table/gridtablerenderer.cxx b/svtools/source/table/gridtablerenderer.cxx index 7e721832c04c..313a5e842547 100644 --- a/svtools/source/table/gridtablerenderer.cxx +++ b/svtools/source/table/gridtablerenderer.cxx @@ -80,11 +80,7 @@ namespace svt { namespace table // fill the rows with alternating background colors _rDevice.Push( PUSH_FILLCOLOR | PUSH_LINECOLOR); - //default background and line color is white - //background and lines should have same color, that's means lines aren't visible - //in case line color isn't set and background color is set, this should be changed Color background = m_pImpl->rModel.getHeaderBackgroundColor(); - //Color background = _rStyle.GetBackgroundColor(); Color line = m_pImpl->rModel.getLineColor(); //default background and line color is white //background and lines should have same color, that's means lines aren't visible @@ -102,7 +98,6 @@ namespace svt { namespace table _rDevice.SetFillColor(background); } _rDevice.DrawRect( _rArea ); - // delimiter lines at bottom/right _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() ); _rDevice.DrawLine( _rArea.BottomRight(), _rArea.TopRight() ); @@ -147,7 +142,10 @@ namespace svt { namespace table nHorFlag = TEXT_DRAW_CENTER; else if(m_pImpl->rModel.getColumnModel(_nCol)->getHorizontalAlign() == 2) nHorFlag = TEXT_DRAW_RIGHT; - _rDevice.DrawText( _rArea, sHeaderText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); + Rectangle aRect(_rArea); + aRect.Left()+=4; aRect.Right()-=4; + aRect.Top()+=4; aRect.Bottom()-=4; + _rDevice.DrawText( aRect, sHeaderText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); _rDevice.DrawLine( _rArea.BottomLeft(), _rArea.BottomRight() ); _rDevice.Pop(); @@ -250,7 +248,10 @@ namespace svt { namespace table nHorFlag = TEXT_DRAW_CENTER; else if(m_pImpl->rModel.getColumnModel(0)->getHorizontalAlign() == 2) nHorFlag = TEXT_DRAW_RIGHT; - _rDevice.DrawText( _rArea, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); + Rectangle aRect(_rArea); + aRect.Left()+=4; aRect.Right()-=4; + aRect.Top()+=4; aRect.Bottom()-=4; + _rDevice.DrawText( aRect, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); // TODO: active? selected? (void)_bActive; (void)_bSelected; @@ -374,8 +375,6 @@ namespace svt { namespace table Rectangle aRect( _rArea ); ++aRect.Left(); --aRect.Right(); aRect.Top(); aRect.Bottom(); - - String sText; if(_bSelected) { _rDevice.SetTextColor(_rStyle.GetHighlightTextColor()); @@ -394,7 +393,10 @@ namespace svt { namespace table nHorFlag = TEXT_DRAW_CENTER; else if(m_pImpl->rModel.getColumnModel(_nColumn)->getHorizontalAlign() == 2) nHorFlag = TEXT_DRAW_RIGHT; - _rDevice.DrawText( aRect, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); + Rectangle textRect(_rArea); + textRect.Left()+=4; textRect.Right()-=4; + textRect.Top()+=4; textRect.Bottom()-=4; + _rDevice.DrawText( textRect, _rText, nHorFlag | nVerFlag | TEXT_DRAW_CLIP); } _rDevice.Pop(); diff --git a/svtools/source/table/tablecontrol.cxx b/svtools/source/table/tablecontrol.cxx index 427f65557e52..635008d94f94 100644 --- a/svtools/source/table/tablecontrol.cxx +++ b/svtools/source/table/tablecontrol.cxx @@ -69,15 +69,16 @@ namespace svt { namespace table ,m_pImpl( new TableControl_Impl( *this ) ) ,m_nCols(*( new ::com::sun::star::uno::Sequence< sal_Int32 >(0) )) ,m_aText(*( new ::com::sun::star::uno::Sequence< ::rtl::OUString >(0) )) + ,m_bSelectionChanged(false) { - m_pImpl->getDataWindow()->SetMouseButtonDownHdl( LINK( this, TableControl, ImplMouseButtonDownHdl ) ); - m_pImpl->getDataWindow()->SetMouseButtonUpHdl( LINK( this, TableControl, ImplMouseButtonUpHdl ) ); + m_pImpl->getDataWindow()->SetSelectHdl( LINK( this, TableControl, ImplSelectHdl ) ); m_pAccessTable.reset(new ::svt::table::AccessibleTableControl_Impl()); } //-------------------------------------------------------------------- TableControl::~TableControl() { + ImplCallEventListeners( VCLEVENT_OBJECT_DYING ); DELETEZ( m_pImpl ); if ( m_pAccessTable->m_pAccessible ) { @@ -107,6 +108,14 @@ namespace svt { namespace table { if ( !m_pImpl->getInputHandler()->KeyInput( *m_pImpl, rKEvt ) ) Control::KeyInput( rKEvt ); + else + { + if(m_bSelectionChanged) + { + Select(); + m_bSelectionChanged = false; + } + } } //-------------------------------------------------------------------- void TableControl::Resize() @@ -163,13 +172,21 @@ namespace svt { namespace table return m_pImpl->goTo( _nColPos, _nRowPos ); } //-------------------------------------------------------------------- - void TableControl::InvalidateDataWindow(RowPos _nRowStart, bool _bRemoved) + void TableControl::InvalidateDataWindow(RowPos _nRowStart, RowPos _nRowEnd, bool _bRemoved) { Rectangle _rRect; if(_bRemoved) - return m_pImpl->invalidateRows(_nRowStart, _rRect); + m_pImpl->invalidateRows(_nRowStart, _rRect); else - return m_pImpl->invalidateRow(_nRowStart, _rRect); + { + if(m_bSelectionChanged) + { + m_pImpl->invalidateSelectedRegion(_nRowStart, _nRowEnd, _rRect); + m_bSelectionChanged = false; + } + else + m_pImpl->invalidateRow(_nRowStart, _rRect); + } } //-------------------------------------------------------------------- std::vector& TableControl::GetSelectedRows() @@ -177,7 +194,7 @@ namespace svt { namespace table return m_pImpl->getSelectedRows(); } //-------------------------------------------------------------------- - void TableControl::removeSelectedRow(RowPos _nRowPos) + void TableControl::RemoveSelectedRow(RowPos _nRowPos) { m_pImpl->removeSelectedRow(_nRowPos); } @@ -188,20 +205,6 @@ namespace svt { namespace table return m_pImpl->getCurrentRow( rPoint ); } - //-------------------------------------------------------------------- - - IMPL_LINK( TableControl, ImplMouseButtonDownHdl, MouseEvent*, pData ) - { - CallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, pData ); - return 1; - } - - IMPL_LINK( TableControl, ImplMouseButtonUpHdl, MouseEvent*, pData ) - { - CallEventListeners( VCLEVENT_WINDOW_MOUSEBUTTONUP, pData ); - return 1; - } - SelectionEngine* TableControl::getSelEngine() { return m_pImpl->getSelEngine(); @@ -345,6 +348,13 @@ namespace svt { namespace table } // ----------------------------------------------------------------------------- +::rtl::OUString TableControl::GetAccessibleCellText( sal_Int32 _nRowPos, sal_Int32 _nColPos) +{ + ::com::sun::star::uno::Any cellContent = GetCellContent(_nRowPos, _nColPos); + return m_pImpl->impl_convertToString(cellContent); +} +// ----------------------------------------------------------------------------- + void TableControl::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& rStateSet, AccessibleTableControlObjType eObjType ) const @@ -553,7 +563,23 @@ void TableControl::setTooltip(const ::com::sun::star::uno::Sequence< ::rtl::OUSt m_aText = aText; m_nCols = nCols; } +// ----------------------------------------------------------------------- +void TableControl::selectionChanged(bool _bChanged) +{ + m_bSelectionChanged = _bChanged; +} +// ----------------------------------------------------------------------- +IMPL_LINK( TableControl, ImplSelectHdl, void*, EMPTYARG ) +{ + Select(); + return 1; +} +// ----------------------------------------------------------------------- +void TableControl::Select() +{ + ImplCallEventListenersAndHandler( VCLEVENT_TABLEROW_SELECT, m_aSelectHdl, this ); +} //........................................................................ }} // namespace svt::table //........................................................................ diff --git a/svtools/source/table/tablecontrol_impl.cxx b/svtools/source/table/tablecontrol_impl.cxx index 9bc8644276f1..aa22a8239375 100644 --- a/svtools/source/table/tablecontrol_impl.cxx +++ b/svtools/source/table/tablecontrol_impl.cxx @@ -284,8 +284,8 @@ namespace svt { namespace table :m_rTable( _rTable ) ,m_nSuspendFlags( _nSuspendFlags ) { - DBG_ASSERT( ( m_rTable.m_nRequiredInvariants & m_nSuspendFlags ) == m_nSuspendFlags, - "SuspendInvariants: cannot suspend what is already suspended!" ); + //DBG_ASSERT( ( m_rTable.m_nRequiredInvariants & m_nSuspendFlags ) == m_nSuspendFlags, + // "SuspendInvariants: cannot suspend what is already suspended!" ); const_cast< TableControl_Impl& >( m_rTable ).m_nRequiredInvariants &= ~m_nSuspendFlags; } ~SuspendInvariants() @@ -365,7 +365,6 @@ namespace svt { namespace table // m_nColHeaderHeightPixel consistent with the model's value? { TableMetrics nHeaderHeight = m_pModel->hasColumnHeaders() ? m_pModel->getColumnHeaderHeight() : 0; - // nHeaderHeight = m_rAntiImpl.LogicToPixel( Size( 0, nHeaderHeight ), MAP_100TH_MM ).Height(); nHeaderHeight = m_rAntiImpl.LogicToPixel( Size( 0, nHeaderHeight ), MAP_APPFONT ).Height(); if ( nHeaderHeight != m_nColHeaderHeightPixel ) return "column header heights are inconsistent!"; @@ -375,7 +374,6 @@ namespace svt { namespace table if ( !isDummyModel ) { TableMetrics nRowHeight = m_pModel->getRowHeight(); - // nRowHeight = m_rAntiImpl.LogicToPixel( Size( 0, nRowHeight ), MAP_100TH_MM ).Height(); nRowHeight = m_rAntiImpl.LogicToPixel( Size( 0, nRowHeight ), MAP_APPFONT).Height(); if ( nRowHeight != m_nRowHeightPixel ) return "row heights are inconsistent!"; @@ -384,14 +382,12 @@ namespace svt { namespace table // m_nRowHeaderWidthPixel consistent with the model's value? { TableMetrics nHeaderWidth = m_pModel->hasRowHeaders() ? m_pModel->getRowHeaderWidth() : 0; - //nHeaderWidth = m_rAntiImpl.LogicToPixel( Size( nHeaderWidth, 0 ), MAP_100TH_MM ).Width(); nHeaderWidth = m_rAntiImpl.LogicToPixel( Size( nHeaderWidth, 0 ), MAP_APPFONT ).Width(); if ( nHeaderWidth != m_nRowHeaderWidthPixel ) return "row header widths are inconsistent!"; } // TODO: check m_aColumnWidthsPixel and m_aAccColumnWidthsPixel - if ( m_nCursorHidden < 0 ) return "invalid hidden count for the cursor!"; @@ -453,6 +449,7 @@ namespace svt { namespace table ,m_nAnchor (-1 ) ,m_bResizing ( false ) ,m_nResizingColumn ( 0 ) + ,m_bResizingGrid ( false ) #if DBG_UTIL ,m_nRequiredInvariants ( INV_SCROLL_POSITION ) #endif @@ -494,14 +491,10 @@ namespace svt { namespace table TempHideCursor aHideCursor( *this ); - // TODO: revoke as table listener from the model - m_pModel = _pModel; if ( !m_pModel) m_pModel.reset( new EmptyTableModel ); - // TODO: register as table listener - //m_pModel->addTableModelListener(PTableModelListener(m_pTableModelListener)); m_nCurRow = ROW_INVALID; m_nCurColumn = COL_INVALID; @@ -571,11 +564,9 @@ namespace svt { namespace table m_pInputHandler.reset(); m_nColumnCount = m_nRowCount = 0; - //m_nRowHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getRowHeight() ), MAP_100TH_MM ).Height(); m_nRowHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getRowHeight() ), MAP_APPFONT ).Height(); if ( m_pModel->hasColumnHeaders() ) - //m_nColHeaderHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getColumnHeaderHeight() ), MAP_100TH_MM ).Height(); - m_nColHeaderHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getColumnHeaderHeight() ), MAP_APPFONT ).Height(); + m_nColHeaderHeightPixel = m_rAntiImpl.LogicToPixel( Size( 0, m_pModel->getColumnHeaderHeight() ), MAP_APPFONT ).Height(); if ( m_pModel->hasRowHeaders() ) m_nRowHeaderWidthPixel = m_rAntiImpl.LogicToPixel( Size( m_pModel->getRowHeaderWidth(), 0 ), MAP_APPFONT).Width(); @@ -602,7 +593,7 @@ namespace svt { namespace table m_aColumnWidthsPixel.reserve( colCount ); m_aAccColumnWidthsPixel.reserve( colCount ); long accumulatedPixelWidth = 0; - double gridWidth = m_rAntiImpl.GetSizePixel().Width()-1; + double gridWidth = m_rAntiImpl.GetSizePixel().Width()-4; if(m_pModel->hasRowHeaders()) { TableMetrics rowHeaderWidth = m_pModel->getRowHeaderWidth(); @@ -612,10 +603,10 @@ namespace svt { namespace table { sal_Int32 scrollbarWidth = m_rAntiImpl.GetSettings().GetStyleSettings().GetScrollBarSize(); gridWidth-=scrollbarWidth; - //m_rAntiImpl.LogicToPixel( Size( scrollbarWidth, 0 ), MAP_APPFONT ).Width(); } double colWidthsSum = 0.0; double colWithoutFixedWidthsSum = 0.0; + double minColWithoutFixedSum = 0.0; for ( ColPos col = 0; col < colCount; ++col ) { PColumnModel pColumn = m_pModel->getColumnModel( col ); @@ -624,74 +615,65 @@ namespace svt { namespace table continue; TableMetrics colWidth = 0; TableMetrics colPrefWidth = pColumn->getPreferredWidth(); + bool bResizable = pColumn->isResizable(); + if(pColumn->getMinWidth() == 0 && bResizable) + { + pColumn->setMinWidth(1); + minColWithoutFixedSum+=m_rAntiImpl.LogicToPixel( Size( 1, 0 ), MAP_APPFONT ).Width(); + } + if(pColumn->getMaxWidth() == 0 && bResizable) + pColumn->setMaxWidth(m_rAntiImpl.LogicToPixel( Size( (int)gridWidth, 0 ), MAP_APPFONT ).Width()); if( colPrefWidth != 0) { - colWidth = colPrefWidth; - pColumn->setWidth(colPrefWidth); + if(m_bResizingGrid) + { + colWidth = pColumn->getWidth(); + pColumn->setPreferredWidth(0); + } + else + { + colWidth = colPrefWidth; + pColumn->setWidth(colPrefWidth); + } } else colWidth = pColumn->getWidth(); long pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width(); - if(pColumn->isResizable() && colPrefWidth == 0) + if(bResizable && colPrefWidth == 0) colWithoutFixedWidthsSum+=pixelWidth; colWidthsSum+=pixelWidth; } - if(colWidthsSum < gridWidth) + gridWidth = gridWidth - colWidthsSum + colWithoutFixedWidthsSum; + double scalingFactor = 1.0; + if(m_bResizingGrid) { - gridWidth = gridWidth - colWidthsSum + colWithoutFixedWidthsSum; - double scalingFactor = 1.0; - if(colWithoutFixedWidthsSum>0) + if(gridWidth > (minColWithoutFixedSum+colWidthsSum - colWithoutFixedWidthsSum)) scalingFactor = gridWidth/colWithoutFixedWidthsSum; - long pixelWidth = 0; - for ( ColPos col = 0; col < colCount; ++col ) + } + else + { + if(colWidthsSum < gridWidth) { - PColumnModel pColumn = m_pModel->getColumnModel( col ); - DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); - if ( !pColumn ) - continue; - TableMetrics colWidth = pColumn->getWidth(); - //if(pColumn->getPreferredWidth() != 0) - // colWidth = pColumn->getPreferredWidth(); - if(pColumn->isResizable() && pColumn->getPreferredWidth() == 0) - { - colWidth*=scalingFactor; - pColumn->setWidth(colWidth); - } - pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width(); - m_aColumnWidthsPixel.push_back( pixelWidth ); - m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += pixelWidth ); + if(colWithoutFixedWidthsSum>0) + scalingFactor = gridWidth/colWithoutFixedWidthsSum; } - //m_rAntiImpl.SetModel(m_pModel); - } - else + long pixelWidth = 0; + for ( ColPos col = 0; col < colCount; ++col ) { - for ( ColPos col = 0; col < colCount; ++col ) + PColumnModel pColumn = m_pModel->getColumnModel( col ); + DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); + if ( !pColumn ) + continue; + TableMetrics colWidth = pColumn->getWidth(); + if(pColumn->isResizable() && pColumn->getPreferredWidth() == 0) { - PColumnModel pColumn = m_pModel->getColumnModel( col ); - DBG_ASSERT( !!pColumn, "TableControl_Impl::impl_ni_updateColumnWidths: invalid column returned by the model!" ); - if ( !pColumn ) - continue; - - TableMetrics colWidth = pColumn->getWidth(); - DBG_ASSERT( ( colWidth == COLWIDTH_FIT_TO_VIEW ) || ( colWidth > 0 ), - "TableControl_Impl::impl_ni_updateColumnWidths: invalid column width!" ); - - long pixelWidth = 0; - if ( colWidth == COLWIDTH_FIT_TO_VIEW ) - { - // TODO - DBG_ERROR( "TableControl_Impl::impl_ni_updateColumnWidths: COLWIDTH_FIT_TO_VIEW not implemented, yet!" ); - } - else - { - //pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_100TH_MM ).Width(); - pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width(); - } - m_aColumnWidthsPixel.push_back( pixelWidth ); - - m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += pixelWidth ); + colWidth*=scalingFactor; + pColumn->setWidth(colWidth); } + pixelWidth = m_rAntiImpl.LogicToPixel( Size( colWidth, 0 ), MAP_APPFONT ).Width(); + m_aColumnWidthsPixel.push_back( pixelWidth ); + m_aAccColumnWidthsPixel.push_back( accumulatedPixelWidth += pixelWidth ); } } @@ -925,11 +907,16 @@ namespace svt { namespace table void TableControl_Impl::onResize() { DBG_CHECK_ME(); - if(m_nColumnCount != 0) - impl_ni_updateScrollbars(); - //Rectangle aAllCells; - // impl_getAllVisibleCellsArea( aAllCells ); - //m_pSelEngine->SetVisibleArea(aAllCells); + if(m_nRowCount != 0) + { + if(m_nColumnCount != 0) + { + if(m_bResizingGrid) + impl_ni_updateColumnWidths(); + impl_ni_updateScrollbars(); + m_bResizingGrid = true; + } + } } //-------------------------------------------------------------------- @@ -1061,9 +1048,12 @@ namespace svt { namespace table { if ( _rUpdateRect.GetIntersection( aRowIterator.getRect() ).IsEmpty() ) { - if(m_pModel->hasRowHeaders()) - ++itRowName; - ++it; + if(it < aCellContent.end()-1) + { + if(m_pModel->hasRowHeaders()) + ++itRowName; + ++it; + } continue; } bool isActiveRow = ( aRowIterator.getRow() == getCurRow() ); @@ -1081,7 +1071,8 @@ namespace svt { namespace table if(it != aCellContent.begin()+m_nTopRow+nActualRows) { aCellData = *it; - ++it; + if(it < aCellContent.end()-1) + ++it; } ::std::vector< ::com::sun::star::uno::Any >::iterator iter = aCellData.begin()+m_nLeftColumn; @@ -1096,7 +1087,8 @@ namespace svt { namespace table if(itRowName != aRowHeaderContent.begin()+m_nTopRow+nActualRows) { rowHeaderName = *itRowName; - ++itRowName; + if(itRowName < m_pModel->getRowHeaderName().end()-1) + ++itRowName; } Rectangle aCurrentRowHeader( aRowHeaderArea.GetIntersection( aRowIterator.getRect() ) ); //rStyle.SetBackgroundColor(m_rAntiImpl.getHeaderBackgroundColor()); @@ -1120,7 +1112,8 @@ namespace svt { namespace table TableSize nPartlyVisibleCols = impl_getVisibleColumns(false); TableSize nPartlyVisibleRows = impl_getVisibleRows(false); rCellData = *iter; - ++iter; + if(iter < aCellData.end()-1) + ++iter; Size siz = m_rAntiImpl.GetSizePixel(); ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; if(rCellData>>=xGraphic) @@ -1177,8 +1170,8 @@ namespace svt { namespace table for(std::vector::iterator it=m_nRowSelected.begin(); it!=m_nRowSelected.end();++it) { - invalidateSelectedRow(*it,rCells); - m_pDataWindow->Invalidate(rCells); + invalidateSelectedRegion(*it, *it, rCells); + //m_pDataWindow->Invalidate(rCells); } m_nRowSelected.clear(); } @@ -1189,8 +1182,9 @@ namespace svt { namespace table } else m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); ensureVisible(m_nCurColumn,m_nCurRow,false); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } else @@ -1198,8 +1192,6 @@ namespace svt { namespace table if ( m_nCurRow < m_nRowCount - 1 ) { bSuccess = goTo( m_nCurColumn, m_nCurRow + 1 ); - if(m_pSelEngine->GetSelectionMode() == MULTIPLE_SELECTION) - m_nAnchor = m_nCurRow; } } break; @@ -1212,8 +1204,8 @@ namespace svt { namespace table for(std::vector::iterator it=m_nRowSelected.begin(); it!=m_nRowSelected.end();++it) { - invalidateSelectedRow(*it,rCells); - m_pDataWindow->Invalidate(rCells); + invalidateSelectedRegion(*it, *it, rCells); + //m_pDataWindow->Invalidate(rCells); } m_nRowSelected.clear(); } @@ -1221,14 +1213,15 @@ namespace svt { namespace table { --m_nCurRow; m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } else { m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } ensureVisible(m_nCurColumn,m_nCurRow,false); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } else @@ -1236,8 +1229,6 @@ namespace svt { namespace table if ( m_nCurRow > 0 ) { bSuccess = goTo( m_nCurColumn, m_nCurRow - 1 ); - if(m_pSelEngine->GetSelectionMode() == MULTIPLE_SELECTION) - m_nAnchor = m_nCurRow; } } break; @@ -1303,11 +1294,16 @@ namespace svt { namespace table int pos = getRowSelectedNumber(m_nRowSelected, m_nCurRow); //if current row is selected, it should be deselected, when ALT+SPACE are pressed if(pos>-1) + { m_nRowSelected.erase(m_nRowSelected.begin()+pos); + if(m_nRowSelected.empty() && m_nAnchor != -1) + m_nAnchor = -1; + } //else select the row->put it in the vector else m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } break; @@ -1325,19 +1321,19 @@ namespace svt { namespace table //there are other selected rows if(m_nRowSelected.size()>0) { - //the anchor wasn't set -> a region is not selected, that's why clear all selection - //and select the current row + // the anchor wasn't set -> a region is not selected, that's why clear all selection + // and select the current row if(m_nAnchor==-1) { for(std::vector::iterator it=m_nRowSelected.begin(); it!=m_nRowSelected.end();++it) { - invalidateSelectedRow(*it,rCells); - m_pDataWindow->Invalidate(rCells); + invalidateSelectedRegion(*it, *it, rCells); + //m_pDataWindow->Invalidate(rCells); } m_nRowSelected.clear(); m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } else { @@ -1352,17 +1348,27 @@ namespace svt { namespace table else return bSuccess = true; //if nextRow already selected, deselect it, otherwise select it - if(m_nRowSelected[nextRow] == m_nCurRow) + if(nextRow>-1 && m_nRowSelected[nextRow] == m_nCurRow) { m_nRowSelected.erase(m_nRowSelected.begin()+prevRow); - invalidateSelectedRow(m_nCurRow+1, rCells); + invalidateSelectedRegion(m_nCurRow+1, m_nCurRow+1, rCells); } else { m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } } + else + { + if(m_nCurRow>0) + { + m_nRowSelected.push_back(m_nCurRow); + m_nCurRow--; + m_nRowSelected.push_back(m_nCurRow); + invalidateSelectedRegion(m_nCurRow+1, m_nCurRow, rCells); + } + } } } else @@ -1380,12 +1386,13 @@ namespace svt { namespace table else { m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } } m_pSelEngine->SetAnchor(TRUE); m_nAnchor = m_nCurRow; ensureVisible(m_nCurColumn, m_nCurRow, false); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } } @@ -1409,12 +1416,12 @@ namespace svt { namespace table for(std::vector::iterator it=m_nRowSelected.begin(); it!=m_nRowSelected.end();++it) { - invalidateSelectedRow(*it,rCells); - m_pDataWindow->Invalidate(rCells); + invalidateSelectedRegion(*it, *it, rCells); + //m_pDataWindow->Invalidate(rCells); } m_nRowSelected.clear(); m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } else { @@ -1424,27 +1431,37 @@ namespace svt { namespace table if(prevRow>-1) { //if m_nCurRow isn't the last one, can move down, otherwise not - if(m_nCurRow-1 && m_nRowSelected[nextRow] == m_nCurRow) { m_nRowSelected.erase(m_nRowSelected.begin()+prevRow); - invalidateSelectedRow(m_nCurRow-1, rCells); + invalidateSelectedRegion(m_nCurRow-1, m_nCurRow-1, rCells); } else { m_nRowSelected.push_back(m_nCurRow); - invalidateSelectedRow(m_nCurRow, rCells); + invalidateSelectedRegion(m_nCurRow, m_nCurRow, rCells); } } + else + { + if(m_nCurRowSetAnchor(TRUE); m_nAnchor = m_nCurRow; ensureVisible(m_nCurColumn, m_nCurRow, false); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } } @@ -1487,6 +1505,7 @@ namespace svt { namespace table m_nAnchor = m_nCurRow; m_pSelEngine->SetAnchor(TRUE); ensureVisible(m_nCurColumn, 0, false); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } } @@ -1510,7 +1529,8 @@ namespace svt { namespace table m_nCurRow = m_nRowCount-1; m_nAnchor = m_nCurRow; m_pSelEngine->SetAnchor(TRUE); - ensureVisible(m_nCurColumn, m_nRowCount, false); + ensureVisible(m_nCurColumn, m_nRowCount-1, false); + m_rAntiImpl.selectionChanged(true); bSuccess = true; } break; @@ -1555,11 +1575,6 @@ namespace svt { namespace table return; } - //DBG_ASSERT( ( _nColumn >= 0 ) && ( _nColumn < m_pModel->getColumnCount() ), - // "TableControl_Impl::impl_getCellRect: invalid column index!" ); - //DBG_ASSERT( ( _nRow >= 0 ) && ( _nRow < m_pModel->getRowCount() ), - // "TableControl_Impl::impl_getCellRect: invalid row index!" ); - Rectangle aAllCells; impl_getAllVisibleCellsArea( aAllCells ); @@ -1573,7 +1588,6 @@ namespace svt { namespace table Rectangle rCellRect; RowPos newRowPos = -2;//-1 is HeaderRow ColPos newColPos = 0; - //To Do: when only row position needed, the second loop isn't necessary, Please proove this!!! for(int i=-1;iInvalidate(_rCellRect); } - //------------------------------------------------------------------------------- - //To Do: not really needed, because in method above one row can be invalidate. Please Prove this!!! - void TableControl_Impl::invalidateSelectedRow(RowPos _nCurRow, Rectangle& _rCellRect) - { - DBG_CHECK_ME(); - Rectangle aAllCells; - impl_getAllVisibleCellsArea( aAllCells ); - _rCellRect.Left() = aAllCells.Left(); - _rCellRect.Right() = aAllCells.Right(); - Rectangle rCells; - impl_getCellRect(m_nCurColumn,_nCurRow,rCells); - _rCellRect.Top()=--rCells.Top(); - _rCellRect.Bottom()=rCells.Bottom(); - m_pDataWindow->Invalidate(_rCellRect); - } //------------------------------------------------------------------------------- //this method is to be called, when a new row is added void TableControl_Impl::invalidateRow(RowPos _nRowPos, Rectangle& _rCellRect) { //DBG_CHECK_ME(); - TempHideCursor aHideCursor( *this ); + if(m_nCurRow < 0) + m_nCurRow = 0; + if(m_nCursorHidden == 2) + --m_nCursorHidden; impl_getAllVisibleCellsArea( _rCellRect ); TableRowGeometry _rRow( *this, _rCellRect, _nRowPos); impl_ni_updateScrollbars(); @@ -1723,28 +1724,6 @@ namespace svt { namespace table //DBG_CHECK_ME(); (void)_nRowStart; (void)_rCellRect; - /*TempHideCursor aHideCursor(*this); - Rectangle aAllCells; - impl_getAllVisibleCellsArea( aAllCells ); - TableRowGeometry _rRow( *this, aAllCells, _nRowStart); - _rCellRect = _rRow.getRect(); - Rectangle rCells1; - impl_getCellRect(m_nCurColumn,m_nRowCount,rCells1); - _rCellRect.Bottom() = rCells1.Bottom();*/ - /*if(_nRowStart != _nRowEnd) - { - TableRowGeometry _rRow( *this, aAllCells, _nRowEnd); - _rCellRect.Bottom() = _rRow.getRect().Bottom(); - } - */ - //_rCellRect.Right() = aAllCells.Right(); - //_rCellRect.Left() = aAllCells.Left(); - //Rectangle rCells1; - //impl_getCellRect(m_nCurColumn,_nRowStart,rCells1); - //_rCellRect.Top()=rCells1.Top(); - //Rectangle rCells2; - //impl_getCellRect(m_nCurColumn,_nRowEnd,rCells2); - //_rCellRect.Bottom()=rCells2.Bottom(); impl_ni_updateScrollbars(); TableSize nVisibleRows = impl_getVisibleRows(true); if(m_nTopRow+nVisibleRows>m_nRowCount && m_nRowCount>=nVisibleRows) @@ -1802,20 +1781,6 @@ namespace svt { namespace table // ensure that the new cell is visible ensureVisible( m_nCurColumn, m_nCurRow, false ); - - // TODO: invalidate all and new column/row header, if present, to enforce - // re-painting them - //if(!m_nRowSelected.empty()) - //{ - // Rectangle rCells; - // for(std::vector::iterator it=m_nRowSelected.begin(); - // it!=m_nRowSelected.end();++it) - // { - // invalidateSelectedRow(*it,rCells); - // } - // m_nRowSelected.clear(); - //} - // TODO: notify listeners about new position return true; } @@ -1986,7 +1951,7 @@ namespace svt { namespace table ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]]; ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; if(content>>=xGraphic) - aTooltipText=::rtl::OUString::createFromAscii("IMAGE"); + aTooltipText=::rtl::OUString::createFromAscii(""); else aTooltipText = impl_convertToString(content); } @@ -1996,7 +1961,7 @@ namespace svt { namespace table ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]]; ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; if(content>>=xGraphic) - aTooltipText += ::rtl::OUString::createFromAscii("IMAGE"); + aTooltipText += ::rtl::OUString::createFromAscii(""); else aTooltipText += impl_convertToString(content); } @@ -2034,7 +1999,7 @@ namespace svt { namespace table ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]]; ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; if(content>>=xGraphic) - aTooltipText = ::rtl::OUString::createFromAscii("IMAGE"); + aTooltipText = ::rtl::OUString::createFromAscii(""); else aTooltipText = text[i] + impl_convertToString(content); } @@ -2047,7 +2012,7 @@ namespace svt { namespace table ::com::sun::star::uno::Any content = m_pModel->getCellContent()[current][cols[i]]; ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >xGraphic; if(content>>=xGraphic) - aTooltipText +=::rtl::OUString::createFromAscii("IMAGE"); + aTooltipText +=::rtl::OUString::createFromAscii(""); else aTooltipText += impl_convertToString(content); } @@ -2097,6 +2062,7 @@ namespace svt { namespace table //-------------------------------------------------------------------- bool TableControl_Impl::startResizeColumn(const Point& rPoint) { + m_bResizingGrid = false; m_nResizingColumn = m_nCurColumn; PColumnModel pColumn = m_pModel->getColumnModel(m_nResizingColumn); sal_Int32 colWidth = pColumn->getWidth(); @@ -2126,7 +2092,7 @@ namespace svt { namespace table int oldX = m_aVisibleColumnWidthsPixel[resizeCol]; //position of left border if cursor in the first cell int leftX = 0; - if(m_nResizingColumn-1 > 0 && m_nResizingColumn > m_nLeftColumn) + if(m_nResizingColumn > m_nLeftColumn) leftX = m_aVisibleColumnWidthsPixel[resizeCol-1]; else if(m_nResizingColumn == 0 && m_pModel->hasRowHeaders()) leftX = m_rAntiImpl.LogicToPixel( Size( m_pModel->getRowHeaderWidth(), 0 ), MAP_APPFONT ).Width(); @@ -2135,11 +2101,6 @@ namespace svt { namespace table //minimize the column width if(oldX > actX && actX >= leftX) { - if(minWidth == 0 && pColumn->isResizable()) - { - minWidth = 1; - //TO DO: set it back to model - } if(minWidth < actWidth) { newActWidth = m_rAntiImpl.PixelToLogic( Size( actWidth, 0 ), MAP_APPFONT ).Width(); @@ -2152,11 +2113,6 @@ namespace svt { namespace table } else if(oldX < actX) { - if(maxWidth == 0 && pColumn->isResizable()) - { - maxWidth = m_pDataWindow->GetSizePixel().Width()-1; - //TO DO: set it back to model - } if(actWidth < maxWidth) { newActWidth = m_rAntiImpl.PixelToLogic( Size( actWidth, 0 ), MAP_APPFONT ).Width(); @@ -2171,6 +2127,7 @@ namespace svt { namespace table m_pDataWindow->Invalidate(INVALIDATE_UPDATE); m_pDataWindow->SetPointer(Pointer()); m_bResizing = false; + m_bResizingGrid = true; } m_pDataWindow->ReleaseMouse(); return m_bResizing; @@ -2362,7 +2319,7 @@ namespace svt { namespace table } if(m_pTableControl->m_nRowSelected.size()>1 && m_pTableControl->m_pSelEngine->GetSelectionMode()!=SINGLE_SELECTION) m_pTableControl->m_pSelEngine->AddAlways(TRUE); - m_pTableControl->invalidateSelectedRow(curRow,rCells); + m_pTableControl->invalidateSelectedRegion(curRow, curRow, rCells); bHandled = TRUE; } m_pTableControl->m_nCurRow = curRow; @@ -2397,7 +2354,7 @@ namespace svt { namespace table if(*it == m_nCurrentRow) { pos = i; - m_pTableControl->invalidateSelectedRow(*it,rCells); + m_pTableControl->invalidateSelectedRegion(*it, *it, rCells); } ++i; } @@ -2411,7 +2368,7 @@ namespace svt { namespace table for(std::vector::iterator it=m_pTableControl->m_nRowSelected.begin(); it!=m_pTableControl->m_nRowSelected.end();++it) { - m_pTableControl->invalidateSelectedRow(*it,rCells); + m_pTableControl->invalidateSelectedRegion(*it, *it, rCells); } m_pTableControl->m_nRowSelected.clear(); } diff --git a/svtools/source/table/tablecontrol_impl.hxx b/svtools/source/table/tablecontrol_impl.hxx index a26079a37827..dffa69422599 100644 --- a/svtools/source/table/tablecontrol_impl.hxx +++ b/svtools/source/table/tablecontrol_impl.hxx @@ -118,6 +118,7 @@ namespace svt { namespace table RowPos m_nAnchor; bool m_bResizing; ColPos m_nResizingColumn; + bool m_bResizingGrid; #if DBG_UTIL #define INV_SCROLL_POSITION 1 @@ -186,15 +187,12 @@ namespace svt { namespace table virtual RowPos getCurrentRow (const Point& rPoint); void setCursorAtCurrentCell(const Point& rPoint); - /** proves whether the vector with the selected rows contains the current row*/ + /** checks whether the vector with the selected rows contains the current row*/ BOOL isRowSelected(::std::vector selectedRows, RowPos current); - /** returns the position of the current row in the selecttion vector */ + /** returns the position of the current row in the selection vector */ int getRowSelectedNumber(::std::vector selectedRows, RowPos current); - /** _rCellRect contains the region, which should be invalidate after some action e.g. selectiong row*/ + /** _rCellRect contains the region, which should be invalidate after some action e.g. selecting row*/ void invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow, Rectangle& _rCellRect ); - /** _rCellRect contains the region, which should be invalidate after some action e.g. selectiong row*/ - //vielleicht kann man mit den anderen verschmelzen, mit einer Überprüfung ob prev==curr? - void invalidateSelectedRow( 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*/ @@ -202,7 +200,6 @@ namespace svt { namespace table /** updates the vector, which contains the selected rows after removing the row nRowPos*/ void removeSelectedRow(RowPos _nRowPos); void invalidateRows(RowPos _nRowStart, Rectangle& _rCellRect ); - //virtual void DoubleClick(); // IAbstractTableControl virtual void hideCursor(); @@ -232,6 +229,8 @@ namespace svt { namespace table minus the row and column header areas. */ void impl_getAllVisibleDataCellArea( Rectangle& _rCellArea ) const; + + ::rtl::OUString impl_convertToString(::com::sun::star::uno::Any _value); private: /** toggles the cursor visibility @@ -319,7 +318,6 @@ namespace svt { namespace table void impl_ni_getAccVisibleColWidths(); void impl_updateLeftColumn(); - ::rtl::OUString impl_convertToString(::com::sun::star::uno::Any _value); DECL_LINK( OnScroll, ScrollBar* ); }; diff --git a/svtools/source/table/tabledatawindow.cxx b/svtools/source/table/tabledatawindow.cxx index 8631ed76a6c0..6ae2a39443d1 100644 --- a/svtools/source/table/tabledatawindow.cxx +++ b/svtools/source/table/tabledatawindow.cxx @@ -44,6 +44,8 @@ namespace svt { namespace table :Window( &_rTableControl.getAntiImpl() ) ,m_rTableControl ( _rTableControl ) { + //Color backgroundColor = GetControlBackground(); + //SetBackground( backgroundColor ); } //-------------------------------------------------------------------- @@ -75,15 +77,17 @@ namespace svt { namespace table if ( !m_rTableControl.getInputHandler()->MouseButtonDown( m_rTableControl, rMEvt ) ) Window::MouseButtonDown( rMEvt ); else - m_aMouseButtonDownHdl.Call( (MouseEvent*) &rMEvt); + { + Point aPoint = rMEvt.GetPosPixel(); + if(m_rTableControl.getCurrentRow(aPoint) >= 0) + m_aSelectHdl.Call( NULL ); + } m_rTableControl.getAntiImpl().LoseFocus(); } void TableDataWindow::MouseButtonUp( const MouseEvent& rMEvt ) { if ( !m_rTableControl.getInputHandler()->MouseButtonUp( m_rTableControl, rMEvt ) ) Window::MouseButtonUp( rMEvt ); - else - m_aMouseButtonUpHdl.Call( (MouseEvent*) &rMEvt); m_rTableControl.getAntiImpl().GetFocus(); } void TableDataWindow::SetPointer( const Pointer& rPointer ) diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index ce04078687b1..4cad623ff3a0 100755 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -50,6 +50,7 @@ #include #include #include +#include using ::rtl::OUString; using namespace ::svt::table; @@ -70,7 +71,10 @@ SVTXGridControl::SVTXGridControl() m_bHasColumnHeaders(false), m_bHasRowHeaders(false), m_bVScroll(false), - m_bHScroll(false) + m_bHScroll(false), + m_bUpdate(false), + m_nSelectedRowCount(0), + m_aSelectionListeners( *this ) { } @@ -85,6 +89,7 @@ SVTXGridControl::~SVTXGridControl() ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( ::com::sun::star::awt::grid::XGridControl*, this ), SAL_STATIC_CAST( ::com::sun::star::awt::grid::XGridDataListener*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::grid::XGridColumnListener*, this ), SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); } @@ -113,12 +118,12 @@ void SAL_CALL SVTXGridControl::setToolTip(const ::com::sun::star::uno::Sequence< void SAL_CALL SVTXGridControl::addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) { - (void)listener; + m_aSelectionListeners.addInterface(listener); } void SAL_CALL SVTXGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) { - (void) listener; + m_aSelectionListeners.removeInterface(listener); } void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const Any& aValue) throw(RuntimeException) @@ -126,6 +131,8 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An ::vos::OGuard aGuard( GetMutex() ); TableControl* pTable = (TableControl*)GetWindow(); + const StyleSettings& rStyleSettings = GetWindow()->GetSettings().GetStyleSettings(); + com::sun::star::awt::FontDescriptor& aFont = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); switch( GetPropertyId( PropertyName ) ) { @@ -205,7 +212,7 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An } break; } - case BASEPROPERTY_BACKGROUNDCOLOR: + case BASEPROPERTY_GRID_ROW_BACKGROUND: { sal_Int32 colorBackground = 0x000000; if( aValue >>= colorBackground ) @@ -250,26 +257,6 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An } case BASEPROPERTY_GRID_DATAMODEL: { - //m_xDataModel = Reference< XGridDataModel >( aValue, UNO_QUERY ); - //Sequence > cellData = m_xDataModel->getData(); - //Sequence rowData(0); - //std::vector< std::vector< Window* > > aCellContent(0); - //for(int i = 0; i< m_xDataModel->getRowCount();++i) - //{ - // rowData = cellData[i]; - // std::vector newRow( - // comphelper::sequenceToContainer< std::vector >(rowData)); - // if(newRow.size() < (unsigned)m_pTableModel->getColumnCount()) - // newRow.resize( m_pTableModel->getColumnCount(),rtl::OUString::createFromAscii("")); - // aCellContent.push_back(newRow); - //} - //m_pTableModel->setCellContent(aCellContent); - //Sequence< ::rtl::OUString > rowHeaders = m_xDataModel->getRowHeaders(); - //std::vector< rtl::OUString > newRow( - // comphelper::sequenceToContainer< std::vector >(rowHeaders)); - //m_pTableModel->setRowCount(m_xDataModel->getRowCount()); - //m_pTableModel->setRowHeaderName(newRow); - //break; { m_xDataModel = Reference< XGridDataModel >( aValue, UNO_QUERY ); if(m_xDataModel != NULL) @@ -308,12 +295,16 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An comphelper::sequenceToContainer< std::vector >(rowHeaders)); m_pTableModel->setRowCount(m_xDataModel->getRowCount()); m_pTableModel->setRowHeaderName(newRow); - m_pTableModel->setRowHeight(m_xDataModel->getRowHeight()); - m_pTableModel->setRowHeaderWidth(m_xDataModel->getRowHeaderWidth()); } } else throw GridInvalidDataException(rtl::OUString::createFromAscii("The data model isn't set!"), m_xDataModel); + sal_Int32 fontHeight = aFont.Height+8; + if(m_xDataModel->getRowHeight() == 0) + m_pTableModel->setRowHeight(fontHeight); + else + m_pTableModel->setRowHeight(m_xDataModel->getRowHeight()); + m_pTableModel->setRowHeaderWidth(m_xDataModel->getRowHeaderWidth()); } break; } @@ -327,7 +318,11 @@ void SVTXGridControl::setProperty( const ::rtl::OUString& PropertyName, const An Sequence > columns = m_xColumnModel->getColumns(); std::vector > aNewColumns( comphelper::sequenceToContainer > >(columns)); - m_pTableModel->setColumnHeaderHeight(m_xColumnModel->getColumnHeaderHeight()); + sal_Int32 fontHeight = aFont.Height+8; + if(m_xColumnModel->getColumnHeaderHeight() == 0) + m_pTableModel->setColumnHeaderHeight(fontHeight); + else + m_pTableModel->setColumnHeaderHeight(m_xColumnModel->getColumnHeaderHeight()); for ( ::svt::table::ColPos col = 0; col < m_xColumnModel->getColumnCount(); ++col ) { UnoControlTableColumn* tableColumn = new UnoControlTableColumn(aNewColumns[col]); @@ -405,6 +400,7 @@ void SVTXGridControl::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) BASEPROPERTY_GRID_EVEN_ROW_BACKGROUND, BASEPROPERTY_GRID_HEADER_BACKGROUND, BASEPROPERTY_GRID_LINE_COLOR, + BASEPROPERTY_GRID_ROW_BACKGROUND, 0); VCLXWindow::ImplGetPropertyIds( rIds, true ); } @@ -415,17 +411,6 @@ void SAL_CALL SVTXGridControl::setVisible( sal_Bool bVisible ) throw(::com::sun: { pTable->SetModel(PTableModel(m_pTableModel)); pTable->Show( bVisible ); - if(m_xColumnModel != NULL) - { - for ( ::svt::table::ColPos col = 0; col < m_xColumnModel->getColumnCount(); ++col ) - { - //set the new widths, which are computed to fill the width of grid, back to uno awt gridcolumn - //so funktioniert es nicht!!! Die Toolkit Klassen müssen notifiziert werden, sonst kommt es nicht an - //herausfinden wie es gehen soll! - m_xColumnModel->getColumn(col)->setColumnWidth(m_pTableModel->getColumnModel()[col]->getWidth()); - } - } - //TO DO: notify uno awt GridModel about hor. /vert. scrollbars } } void SAL_CALL SVTXGridControl::setFocus() throw(::com::sun::star::uno::RuntimeException) @@ -438,49 +423,30 @@ void SAL_CALL SVTXGridControl::rowAdded(const ::com::sun::star::awt::grid::GridD { std::vector< Any > newRow; Sequence< Any > rawRowData = Event.rowData; - if(m_xColumnModel->getColumnCount() == 0) + int colCount = m_xColumnModel->getColumnCount(); + if(colCount == 0) { + Reference 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->getColumnModel().push_back((PColumnModel)tableColumn); + m_xColumnModel->getColumn(col)->addColumnListener(listener); } - m_xColumnModel->setDefaultColumns(rawRowData.getLength()); + } - else if((unsigned int)rawRowData.getLength()!=(unsigned)m_xColumnModel->getColumnCount()) + else if((unsigned int)rawRowData.getLength()!=(unsigned)colCount) 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++) - { - ::rtl::OUString xCellType; - ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic> xGraphic; - /*if(xCellType.CellControl!= NULL) - { - xCellType.CellControl->createPeer( getToolkit(), this); - Window* pVclPeer = VCLUnoHelper::GetWindow( xCellType.CellControl->getPeer() ); - xTableCellType->pWindow = pVclPeer; - xTableCellType->pWindow->Hide(); - newRow.push_back(xTableCellType); - } - else - {*/ 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()); - //if(m_pTableModel->hasVerticalScrollbar()) - m_bVScroll = m_pTableModel->hasVerticalScrollbar(); - com::sun::star::uno::Any aAny; - aAny <<= m_bVScroll; - setProperty(rtl::OUString::createFromAscii("VScroll"),aAny); - //Reference < XGridControl >( getPeer(), UNO_QUERY_THROW )->ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VSCROLL ), aAny, sal_True ); - - - m_bHScroll = m_pTableModel->hasHorizontalScrollbar(); TableControl* pTable = (TableControl*)GetWindow(); - pTable->InvalidateDataWindow(m_pTableModel->getCellContent().size()-1, false); + pTable->InvalidateDataWindow(m_pTableModel->getCellContent().size()-1, 0, false); if(pTable->isAccessibleAlive()) { pTable->commitGridControlEvent(TABLE_MODEL_CHANGED, @@ -501,93 +467,79 @@ void SAL_CALL SVTXGridControl::rowAdded(const ::com::sun::star::awt::grid::GridD void SAL_CALL SVTXGridControl::rowRemoved(const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException) { - //TableControl* pTable = (TableControl*)GetWindow(); - ////unsigned int rows =m_pImpl->aCellContent.size()-1; - //if(Event.index == -1) - //{ - // if(m_pTableModel->hasRowHeaders()) - // m_pTableModel->getRowHeaderName().clear(); - // m_pTableModel->getCellContent().clear(); - // if(pTable->isAccessibleAlive()) - // { - // pTable->commitGridControlEvent(TABLE_MODEL_CHANGED, - // makeAny( AccessibleTableModelChange(DELETE, 0, m_pTableModel->getColumnCount(), 0, m_pTableModel->getColumnCount())), - // Any()); - // } - //} - //else - //{ - // pTable->removeSelectedRow(Event.index); - // if(m_pTableModel->getCellContent().size()>1) - // { - // if(m_pTableModel->hasRowHeaders()) - // m_pTableModel->getRowHeaderName().erase(m_pTableModel->getRowHeaderName().begin()+Event.index); - // m_pTableModel->getCellContent().erase(m_pTableModel->getCellContent().begin()+Event.index); - // - // } - // else - // { - // if(m_pTableModel->hasRowHeaders()) - // m_pTableModel->getRowHeaderName().clear(); - // m_pTableModel->getCellContent().clear(); - // //m_pImpl->nRowCount=0; - // } - //} - ////pTable->InvalidateDataWindow(Event.index, true); - //m_pTableModel->setRowCount(m_pTableModel->getCellContent().size()); - //pTable->InvalidateDataWindow(Event.index, true); TableControl* pTable = (TableControl*)GetWindow(); if(Event.index == -1) { if(m_pTableModel->hasRowHeaders()) m_pTableModel->getRowHeaderName().clear(); - //::std::vector >::iterator iter = m_pTableModel->getCellContent().begin(); - //for(;iter!=m_pTableModel->getCellContent().end();++iter) - //{ - // std::vector vectIn = *iter; - // std::vector::iterator iterIn = vectIn.begin(); - // for(;iterIn!=vectIn.end();++iterIn) - // DELETEZ(*iterIn); - //} m_pTableModel->getCellContent().clear(); } else if(Event.index >= 0 && Event.index < m_pTableModel->getRowCount()) { - pTable->removeSelectedRow(Event.index); + pTable->RemoveSelectedRow(Event.index); if(m_pTableModel->hasRowHeaders()) m_pTableModel->getRowHeaderName().erase(m_pTableModel->getRowHeaderName().begin()+Event.index); std::vector >::iterator rowPos =m_pTableModel->getCellContent().begin() + Event.index; - //for ( std::vector::iterator iterIn = rowPos->begin(); - // iterIn != rowPos->end(); - // ++iterIn - // ) - //{ - // DELETEZ(*iterIn); - //} m_pTableModel->getCellContent().erase( rowPos ); } m_pTableModel->setRowCount(m_pTableModel->getCellContent().size()); - pTable->InvalidateDataWindow(Event.index, true); + pTable->InvalidateDataWindow(Event.index, Event.index, true); if(pTable->isAccessibleAlive()) { pTable->commitGridControlEvent(TABLE_MODEL_CHANGED, makeAny( AccessibleTableModelChange(DELETE, Event.index, Event.index+1, 0, m_pTableModel->getColumnCount())), Any()); - //pTable->commitGridControlEvent(CHILD, - // makeAny( pTable->m_pAccessTable->m_pAccessible->getTableHeader(TCTYPE_ROWHEADERBAR)), - // Any()); - //for (sal_Int32 i = 0 ; i <= m_pTableModel->getColumnCount() ; ++i) - //{ - // pTable->commitGridControlEvent( - // CHILD, - // makeAny( pTable->m_pAccessTable->m_pAccessible->getTable() ), - // Any()); - //} } - //pTable->Invalidate(); } +void SAL_CALL SVTXGridControl::columnChanged(const ::com::sun::star::awt::grid::GridColumnEvent& Event ) throw (::com::sun::star::uno::RuntimeException) +{ + TableControl* pTable = (TableControl*)GetWindow(); + if(Event.valueName == rtl::OUString::createFromAscii("ColumnResize")) + { + bool resizable = m_pTableModel->getColumnModel()[Event.index]->isResizable(); + Event.newValue>>=resizable; + m_pTableModel->getColumnModel()[Event.index]->setResizable(resizable); + } + else if(Event.valueName == rtl::OUString::createFromAscii("ColWidth")) + { + sal_Int32 colWidth = m_pTableModel->getColumnModel()[Event.index]->getWidth(); + Event.newValue>>=colWidth; + m_pTableModel->getColumnModel()[Event.index]->setWidth(colWidth); + } + else if(Event.valueName == rtl::OUString::createFromAscii("MaxWidth")) + { + sal_Int32 maxWidth = m_pTableModel->getColumnModel()[Event.index]->getMaxWidth(); + Event.newValue>>=maxWidth; + m_pTableModel->getColumnModel()[Event.index]->setMaxWidth(maxWidth); + } + else if(Event.valueName == rtl::OUString::createFromAscii("MinWidth")) + { + sal_Int32 minWidth = m_pTableModel->getColumnModel()[Event.index]->getMinWidth(); + Event.newValue>>=minWidth; + m_pTableModel->getColumnModel()[Event.index]->setMinWidth(minWidth); + } + else if(Event.valueName == rtl::OUString::createFromAscii("PrefWidth")) + { + sal_Int32 prefWidth = m_pTableModel->getColumnModel()[Event.index]->getPreferredWidth(); + Event.newValue>>=prefWidth; + m_pTableModel->getColumnModel()[Event.index]->setPreferredWidth(prefWidth); + } + else if(Event.valueName == rtl::OUString::createFromAscii("HAlign")) + { + ::com::sun::star::style::HorizontalAlignment hAlign = m_pTableModel->getColumnModel()[Event.index]->getHorizontalAlign(); + Event.newValue>>=hAlign; + m_pTableModel->getColumnModel()[Event.index]->setHorizontalAlign(hAlign); + } + else if(Event.valueName == rtl::OUString::createFromAscii("UpdateWidth")) + { + if(m_pTableModel->getColumnModel()[Event.index]->getPreferredWidth() != 0) + m_xColumnModel->getColumn(Event.index)->updateColumn(rtl::OUString::createFromAscii("PrefWidth"), m_pTableModel->getColumnModel()[Event.index]->getPreferredWidth()); + m_xColumnModel->getColumn(Event.index)->updateColumn(rtl::OUString::createFromAscii("ColWidth"), m_pTableModel->getColumnModel()[Event.index]->getWidth()); + } + pTable->Invalidate(); +} void SAL_CALL SVTXGridControl::dataChanged(const ::com::sun::star::awt::grid::GridDataEvent& Event ) throw (::com::sun::star::uno::RuntimeException) { (void) Event; @@ -600,24 +552,91 @@ void SAL_CALL SVTXGridControl::dataChanged(const ::com::sun::star::awt::grid::G ::sal_Int32 SAL_CALL SVTXGridControl::getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException) { - return 0; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(selectedRows.empty()) + return -1; + else + { + std::vector::iterator itStart = selectedRows.begin(); + std::vector::iterator itEnd = selectedRows.end(); + return *(std::min_element(itStart, itEnd)); + } } ::sal_Int32 SAL_CALL SVTXGridControl::getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException) { - return 0; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(selectedRows.empty()) + return -1; + else + { + std::vector::iterator itStart = selectedRows.begin(); + std::vector::iterator itEnd = selectedRows.end(); + return *(std::max_element(itStart, itEnd)); + } } -void SAL_CALL SVTXGridControl::insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL SVTXGridControl::selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException) { - (void)length; - (void)start; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(!selectedRows.empty()) + selectedRows.clear(); + sal_Int32 start = rangeOfRows[0]; + int seqSize = rangeOfRows.getLength(); + sal_Int32 end = rangeOfRows[seqSize-1]; + for(int i=0;iselectionChanged(true); + pTable->InvalidateDataWindow(start, end, false); + SetSynthesizingVCLEvent( sal_True ); + pTable->Select(); + SetSynthesizingVCLEvent( sal_False ); + } -void SAL_CALL SVTXGridControl::removeIndexIntervall(::sal_Int32 start, ::sal_Int32 end) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL SVTXGridControl::selectAllRows() throw (::com::sun::star::uno::RuntimeException) { - (void)end; - (void)start; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(!selectedRows.empty()) + selectedRows.clear(); + for(int i=0;igetRowCount();i++) + selectedRows.push_back(i); + pTable->Invalidate(); + SetSynthesizingVCLEvent( sal_True ); + pTable->Select(); + SetSynthesizingVCLEvent( sal_False ); +} +void SAL_CALL SVTXGridControl::deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException) +{ + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + std::vector::iterator itStart = selectedRows.begin(); + std::vector::iterator itEnd = selectedRows.end(); + sal_Int32 start = rangeOfRows[0]; + sal_Int32 end = rangeOfRows[rangeOfRows.getLength()-1]; + std::vector::iterator iter = std::find(itStart, itEnd, start); + selectedRows.erase(iter, iter+(end-start)+1); + pTable->selectionChanged(true); + pTable->InvalidateDataWindow(start, end, false); + SetSynthesizingVCLEvent( sal_True ); + pTable->Select(); + SetSynthesizingVCLEvent( sal_False ); +} + +void SAL_CALL SVTXGridControl::deselectAllRows() throw (::com::sun::star::uno::RuntimeException) +{ + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(!selectedRows.empty()) + selectedRows.clear(); + pTable->Invalidate(); + SetSynthesizingVCLEvent( sal_True ); + pTable->Select(); + SetSynthesizingVCLEvent( sal_False ); } ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL SVTXGridControl::getSelection() throw (::com::sun::star::uno::RuntimeException) @@ -635,21 +654,125 @@ void SAL_CALL SVTXGridControl::removeIndexIntervall(::sal_Int32 start, ::sal_Int ::sal_Bool SAL_CALL SVTXGridControl::isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException) { - return sal_False; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(selectedRows.empty()) + return sal_True; + else + return sal_False; } ::sal_Bool SAL_CALL SVTXGridControl::isSelectedIndex(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) { - (void)index; - return sal_False; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + ::std::vector::iterator iter = selectedRows.begin(); + sal_Bool bSelected = sal_False; + for(;iter!=selectedRows.end();iter++) + { + if(*iter == index) + bSelected = sal_True; + } + return bSelected; } -void SAL_CALL SVTXGridControl::selectRow(::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL SVTXGridControl::selectRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) { - (void)y; + if(index<0 || index>=m_pTableModel->getRowCount()) + return; + TableControl* pTable = (TableControl*)GetWindow(); + std::vector& selectedRows = pTable->GetSelectedRows(); + if(!isSelectedIndex(index)) + selectedRows.push_back(index); + pTable->selectionChanged(true); + pTable->InvalidateDataWindow(index, index, false); + SetSynthesizingVCLEvent( sal_True ); + pTable->Select(); + SetSynthesizingVCLEvent( sal_False ); } void SAL_CALL SVTXGridControl::selectColumn(::sal_Int32 x) throw (::com::sun::star::uno::RuntimeException) { (void)x; } +void SVTXGridControl::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + m_aSelectionListeners.disposeAndClear( aObj ); + VCLXWindow::dispose(); +} + +void SVTXGridControl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_TABLEROW_SELECT: + { + TableControl* pTable = (TableControl*)GetWindow(); + + if( pTable ) + { + if ( m_aSelectionListeners.getLength() ) + { + ImplCallItemListeners(); + } + } + } + break; + + default: + VCLXWindow::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +void SVTXGridControl::ImplCallItemListeners() +{ + TableControl* pTable = (TableControl*) GetWindow(); + if ( pTable && m_aSelectionListeners.getLength() ) + { + ::std::vector selRows = pTable->GetSelectedRows(); + ::com::sun::star::awt::grid::GridSelectionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Column = 0; + sal_Int32 actSelRowCount = selRows.size(); + sal_Int32 diff = actSelRowCount - m_nSelectedRowCount; + //row added to selection + if(diff >= 1) + { + aEvent.Action = com::sun::star::awt::grid::SelectionEventType(0); + aEvent.Row = selRows[actSelRowCount-1]; + aEvent.Range = diff; + } + //selected row changed + else if(diff == 0) + { + aEvent.Row = selRows[actSelRowCount-1]; + aEvent.Action = com::sun::star::awt::grid::SelectionEventType(2); + aEvent.Range = 0; + } + else + { + //selection changed: multiple row deselected, only 1 row is selected + if(actSelRowCount == 1) + { + aEvent.Row = selRows[actSelRowCount-1]; + aEvent.Action = com::sun::star::awt::grid::SelectionEventType(2); + } + //row is deselected + else + { + aEvent.Row = pTable->GetCurrentRow(); + aEvent.Action = com::sun::star::awt::grid::SelectionEventType(1); + } + aEvent.Range = 0; + } + m_nSelectedRowCount=actSelRowCount; + m_aSelectionListeners.selectionChanged( aEvent ); + } +} diff --git a/svtools/source/uno/svtxgridcontrol.hxx b/svtools/source/uno/svtxgridcontrol.hxx index c8b8af574a61..cd4dc698f8db 100755 --- a/svtools/source/uno/svtxgridcontrol.hxx +++ b/svtools/source/uno/svtxgridcontrol.hxx @@ -35,21 +35,23 @@ #include #include #include +#include #include +#include #include #include #include #include #include #include -#include -//#include +#include +#include using namespace ::svt::table; -class SVTXGridControl : public ::cppu::ImplInheritanceHelper2< VCLXWindow, ::com::sun::star::awt::grid::XGridControl, - ::com::sun::star::awt::grid::XGridDataListener> +class SVTXGridControl : public ::cppu::ImplInheritanceHelper3< VCLXWindow, ::com::sun::star::awt::grid::XGridControl, + ::com::sun::star::awt::grid::XGridDataListener, ::com::sun::star::awt::grid::XGridColumnListener> { private: UnoControlTableModel* m_pTableModel; @@ -59,6 +61,13 @@ private: bool m_bHasRowHeaders; bool m_bVScroll; bool m_bHScroll; + bool m_bUpdate; + sal_Int32 m_nSelectedRowCount; + SelectionListenerMultiplexer m_aSelectionListeners; + +protected: + virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ); + void ImplCallItemListeners(); public: SVTXGridControl(); @@ -67,6 +76,12 @@ public: virtual void SAL_CALL rowAdded(const ::com::sun::star::awt::grid::GridDataEvent& Event) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL rowRemoved(const ::com::sun::star::awt::grid::GridDataEvent & Event) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL dataChanged(const ::com::sun::star::awt::grid::GridDataEvent & Event) throw (::com::sun::star::uno::RuntimeException); + + //XGridColumnListener overridables + //virtual void SAL_CALL columnAdded(const ::com::sun::star::awt::grid::GridColumnEvent& Event) throw (::com::sun::star::uno::RuntimeException); + //virtual void SAL_CALL columnRemoved(const ::com::sun::star::awt::grid::GridColumnEvent & Event) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL columnChanged(const ::com::sun::star::awt::grid::GridColumnEvent & Event) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); @@ -80,8 +95,10 @@ public: //::com::sun::star::awt::grid::XGridControl virtual ::sal_Int32 SAL_CALL getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeIndexIntervall(::sal_Int32 start, ::sal_Int32 end) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectAllRows() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectAllRows() throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL getSelection() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isCellEditable() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException); @@ -98,6 +115,8 @@ public: static void ImplGetPropertyIds( std::list< sal_uInt16 > &aIds ); void SAL_CALL setVisible(sal_Bool bVisible) throw(::com::sun::star::uno::RuntimeException); void SAL_CALL setFocus() throw(::com::sun::star::uno::RuntimeException); - ::rtl::OUString impl_convertToString(::com::sun::star::uno::Any _value); + + // ::com::sun::star::lang::XComponent + void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); }; #endif // _SVT_GRIDCONTROL_HXX_ diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx index d1eaee98e7bb..2b53b65de471 100644 --- a/svtools/source/uno/unocontroltablemodel.cxx +++ b/svtools/source/uno/unocontroltablemodel.cxx @@ -70,6 +70,7 @@ using namespace ::com::sun::star::uno; ,m_nWidth( 4 ) ,m_nMinWidth( 0 ) // no min width ,m_nMaxWidth( 0 ) // no max width + ,m_nPrefWidth ( 0 ) ,m_xHorizontalAlign(com::sun::star::style::HorizontalAlignment(0)) { } @@ -83,11 +84,7 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- bool UnoControlTableColumn::setID( const ColumnID _nID ) { - // TODO: conflict check - m_nID = _nID; - // TODO: notifications? - return true; } @@ -101,7 +98,6 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setName( const String& _rName ) { m_sName = _rName; - // TODO: notifications? } //-------------------------------------------------------------------- bool UnoControlTableColumn::isResizable() const @@ -113,7 +109,6 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setResizable( bool _bResizable ) { m_bIsResizable = _bResizable; - // TODO: notifications? } //-------------------------------------------------------------------- @@ -126,7 +121,6 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setWidth( TableMetrics _nWidth ) { m_nWidth = _nWidth; - // TODO: notifications? } //-------------------------------------------------------------------- @@ -139,7 +133,6 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setMinWidth( TableMetrics _nMinWidth ) { m_nMinWidth = _nMinWidth; - // TODO: notifications? } //-------------------------------------------------------------------- @@ -152,7 +145,6 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setMaxWidth( TableMetrics _nMaxWidth ) { m_nMaxWidth = _nMaxWidth; - // TODO: notifications? } //-------------------------------------------------------------------- TableMetrics UnoControlTableColumn::getPreferredWidth() const @@ -164,7 +156,6 @@ using namespace ::com::sun::star::uno; void UnoControlTableColumn::setPreferredWidth( TableMetrics _nPrefWidth ) { m_nPrefWidth = _nPrefWidth; - // TODO: notifications? } //-------------------------------------------------------------------- ::com::sun::star::style::HorizontalAlignment UnoControlTableColumn::getHorizontalAlign() @@ -195,7 +186,6 @@ using namespace ::com::sun::star::uno; TableMetrics nColumnHeaderHeight; TableMetrics nRowHeaderWidth; std::vector& aRowHeadersTitle; - //std::vector >& aCellContent; std::vector >& aCellContent; ::com::sun::star::util::Color m_xLineColor; ::com::sun::star::util::Color m_xHeaderColor; @@ -213,11 +203,10 @@ using namespace ::com::sun::star::uno; ,bHScroll ( false ) ,pRenderer ( ) ,pInputHandler ( ) - ,nRowHeight ( 15 ) // 40 mm - ,nColumnHeaderHeight( 10 ) // 50 mm - ,nRowHeaderWidth ( 10 ) // 50 mm + ,nRowHeight ( 0 ) + ,nColumnHeaderHeight( 0 ) + ,nRowHeaderWidth ( 10 ) ,aRowHeadersTitle ( *(new std::vector(0))) - //,aCellContent ( *(new std::vector >(0))) ,aCellContent ( *(new std::vector >(0)) ) ,m_xLineColor( 0xFFFFFF ) ,m_xHeaderColor( 0xFFFFFF ) @@ -245,24 +234,12 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- UnoControlTableModel::~UnoControlTableModel() { - //if(!m_pImpl->aCellContent.empty()) - //{ - // ::std::vector >::iterator iter = m_pImpl->aCellContent.begin(); - // for(;iter!=m_pImpl->aCellContent.end();++iter) - // { - // std::vector vectIn = *iter; - // std::vector::iterator iterIn = vectIn.begin(); - // for(;iterIn!=vectIn.end();++iterIn) - // DELETEZ(*iterIn); - // } - //} DELETEZ( m_pImpl ); } //-------------------------------------------------------------------- TableSize UnoControlTableModel::getColumnCount() const { - //m_pImpl->aColumns.resize( m_xColumnModel->getColumnCount()); return (TableSize)m_pImpl->aColumns.size(); } @@ -454,54 +431,9 @@ using namespace ::com::sun::star::uno; return m_pImpl->bHScroll; } //-------------------------------------------------------------------- - // void UnoControlTableModel::setCellContent(std::vector > cellContent) - // { - // //if(cellContent.empty()) - // //{ - // // unsigned int i = m_pImpl->aColumns.size(); - // // std::vector& emptyCells; - // // while(i!=0) - // // { - // // cellContent.push_back(emptyCells); - // // --i; - // // } - // //} - // //std::vector cCC; - // //for(::std::vector >::iterator iter = cellContent.begin(); iter!= cellContent.end();++iter) - // //{ - // // cCC = *iter; - // // m_pImpl->aCellContent.push_back(cCC); - // //} - // m_pImpl->aCellContent.swap( cellContent ); - // } - - //std::vector >& UnoControlTableModel::getCellContent() - // { - // return m_pImpl->aCellContent; - // } - //-------------------------------------------------------------------- void UnoControlTableModel::setCellContent(std::vector > cellContent) { - //::vos::OGuard aGuard( GetMutex() ); - /* - if(cellContent.empty()) - { - unsigned int i = m_pImpl->aColumns.size(); - std::vector emptyCells; - while(i!=0) - { - cellContent.push_back(emptyCells); - --i; - } - } - */ - - m_pImpl->aCellContent.swap( cellContent ); - - /*for(::std::vector >::iterator iter = cellContent.begin(); iter!= cellContent.end();++iter) - { - m_pImpl->aCellContent.push_back(*iter); - }*/ + m_pImpl->aCellContent = cellContent; } std::vector >& UnoControlTableModel::getCellContent() @@ -512,20 +444,7 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- void UnoControlTableModel::setRowHeaderName(std::vector cellColumnContent) { - if(cellColumnContent.empty()) - { - unsigned int i = m_pImpl->aColumns.size(); - while(i!=0) - { - cellColumnContent.push_back(rtl::OUString::createFromAscii("")); - --i; - } - } - for(::std::vector::iterator iter = cellColumnContent.begin(); iter!= cellColumnContent.end();++iter) - { - rtl::OUString s = *iter; - m_pImpl->aRowHeadersTitle.push_back(*iter); - } + m_pImpl->aRowHeadersTitle = cellColumnContent; } std::vector& UnoControlTableModel::getRowHeaderName() diff --git a/svtools/source/uno/unocontroltablemodel.hxx b/svtools/source/uno/unocontroltablemodel.hxx index cff18f4d9be2..ae0a5ce76a9e 100644 --- a/svtools/source/uno/unocontroltablemodel.hxx +++ b/svtools/source/uno/unocontroltablemodel.hxx @@ -47,7 +47,6 @@ #include #include #include -//#include using namespace ::svt::table; @@ -55,7 +54,7 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::awt::grid; class UnoControlTableColumn : public IColumnModel - { +{ private: ColumnID m_nID; String m_sName; @@ -124,8 +123,6 @@ class UnoControlTableColumn : public IColumnModel /// retrieves the width of a column, in 1/100th millimeters inline TableMetrics GetColumnWidth( ColPos _nColumn ); - // TODO: setters and getters for ID, Name, Resizable, MinWidth, MaxWidth - public: // ITableModel overridables virtual TableSize getColumnCount() const; diff --git a/toolkit/inc/toolkit/helper/listenermultiplexer.hxx b/toolkit/inc/toolkit/helper/listenermultiplexer.hxx index 543c8a85c401..0c1c5b631fee 100644 --- a/toolkit/inc/toolkit/helper/listenermultiplexer.hxx +++ b/toolkit/inc/toolkit/helper/listenermultiplexer.hxx @@ -57,7 +57,7 @@ #include #include #include - +#include // ---------------------------------------------------- // class ListenerMultiplexerBase // ---------------------------------------------------- @@ -247,8 +247,12 @@ DECL_LISTENERMULTIPLEXER_START_DLLPUB( TreeEditListenerMultiplexer, ::com::sun:: virtual void SAL_CALL nodeEdited( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node, const ::rtl::OUString& NewText ) throw (::com::sun::star::uno::RuntimeException); DECL_LISTENERMULTIPLEXER_END - - +// ---------------------------------------------------- +// class SelectionListenerMultiplexer +// ---------------------------------------------------- +DECL_LISTENERMULTIPLEXER_START_DLLPUB( SelectionListenerMultiplexer, ::com::sun::star::awt::grid::XGridSelectionListener ) + void SAL_CALL selectionChanged( const ::com::sun::star::awt::grid::GridSelectionEvent& aEvent ) throw (::com::sun::star::uno::RuntimeException); +DECL_LISTENERMULTIPLEXER_END #endif // _TOOLKIT_HELPER_LISTENERMULTIPLEXER_HXX_ diff --git a/toolkit/inc/toolkit/helper/property.hxx b/toolkit/inc/toolkit/helper/property.hxx index 6fa223cc7b26..cbc0dd05248c 100644 --- a/toolkit/inc/toolkit/helper/property.hxx +++ b/toolkit/inc/toolkit/helper/property.hxx @@ -201,6 +201,7 @@ namespace rtl { #define BASEPROPERTY_GRID_EVEN_ROW_BACKGROUND 147 #define BASEPROPERTY_GRID_HEADER_BACKGROUND 148 #define BASEPROPERTY_GRID_LINE_COLOR 149 +#define BASEPROPERTY_GRID_ROW_BACKGROUND 150 // Keine gebundenen Properties, werden immer aus der Property BASEPROPERTY_FONTDESCRIPTOR entnommen. diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx index 337076bdfaa9..f68239f9712c 100644 --- a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx @@ -33,6 +33,7 @@ #include "defaultgridcolumnmodel.hxx" #include #include +#include #include using ::rtl::OUString; @@ -42,7 +43,8 @@ using namespace ::com::sun::star::awt; using namespace ::com::sun::star::awt::grid; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::style; -#define COLUMNSELECTIONALLOWED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnSelectionAllowed" )) +//#define COLUMNSELECTIONALLOWED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnSelectionAllowed" )) +//#define COLUMNRESIZED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnResized" )) namespace toolkit { @@ -53,7 +55,7 @@ namespace toolkit DefaultGridColumnModel::DefaultGridColumnModel(const Reference< XMultiServiceFactory >& xFactory) : columns(std::vector< Reference< XGridColumn > >()) - ,m_nColumnHeaderHeight(10) + ,m_nColumnHeaderHeight(0) ,m_xFactory(xFactory) { } @@ -66,68 +68,68 @@ DefaultGridColumnModel::~DefaultGridColumnModel() //--------------------------------------------------------------------- -void DefaultGridColumnModel::broadcast( broadcast_type eType, const GridColumnEvent& aEvent ) -{ - ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridColumnListener::static_type() ); - if( pIter ) - { - ::cppu::OInterfaceIteratorHelper aListIter(*pIter); - while(aListIter.hasMoreElements()) - { - XGridColumnListener* pListener = static_cast(aListIter.next()); - switch( eType ) - { - case column_added: pListener->columnAdded(aEvent); break; - case column_removed: pListener->columnRemoved(aEvent); break; - case column_changed: pListener->columnChanged(aEvent); break; - } - } - } -} - -//--------------------------------------------------------------------- - -void DefaultGridColumnModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) -{ - Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridColumnEvent aEvent( xSource, name, oldValue, newValue, 0, NULL ); - broadcast( column_changed, aEvent); -} - -//--------------------------------------------------------------------- - -void DefaultGridColumnModel::broadcast_add( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) -{ - Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); - broadcast( column_added, aEvent); -} - -//--------------------------------------------------------------------- - -void DefaultGridColumnModel::broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) -{ - Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); - GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); - broadcast( column_removed, aEvent); -} +//void DefaultGridColumnModel::broadcast( broadcast_type eType, const GridColumnEvent& aEvent ) +//{ +// ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridColumnListener::static_type() ); +// if( pIter ) +// { +// ::cppu::OInterfaceIteratorHelper aListIter(*pIter); +// while(aListIter.hasMoreElements()) +// { +// XGridColumnListener* pListener = static_cast(aListIter.next()); +// switch( eType ) +// { +// case column_added: pListener->columnAdded(aEvent); break; +// case column_removed: pListener->columnRemoved(aEvent); break; +// case column_changed: pListener->columnChanged(aEvent); break; +// } +// } +// } +//} +// +////--------------------------------------------------------------------- +// +//void DefaultGridColumnModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue) +//{ +// Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); +// GridColumnEvent aEvent( xSource, name, oldValue, newValue, 0, NULL ); +// broadcast( column_changed, aEvent); +//} +// +////--------------------------------------------------------------------- +// +//void DefaultGridColumnModel::broadcast_add( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) +//{ +// Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); +// GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); +// broadcast( column_added, aEvent); +//} +// +////--------------------------------------------------------------------- +// +//void DefaultGridColumnModel::broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) +//{ +// Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); +// GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); +// broadcast( column_removed, aEvent); +//} //--------------------------------------------------------------------- // XDefaultGridColumnModel //--------------------------------------------------------------------- -::sal_Bool SAL_CALL DefaultGridColumnModel::getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException) -{ - return selectionAllowed; -} - -//--------------------------------------------------------------------- - -void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value) throw (::com::sun::star::uno::RuntimeException) -{ - sal_Bool oldValue = selectionAllowed; - selectionAllowed = value; - broadcast_changed( COLUMNSELECTIONALLOWED, Any(oldValue) , Any(selectionAllowed)); -} +//::sal_Bool SAL_CALL DefaultGridColumnModel::getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException) +//{ +// return selectionAllowed; +//} +// +////--------------------------------------------------------------------- +// +//void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value) throw (::com::sun::star::uno::RuntimeException) +//{ +// sal_Bool oldValue = selectionAllowed; +// selectionAllowed = value; +// broadcast_changed( COLUMNSELECTIONALLOWED, Any(oldValue) , Any(selectionAllowed)); +//} //--------------------------------------------------------------------- @@ -141,10 +143,10 @@ void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value ::sal_Int32 SAL_CALL DefaultGridColumnModel::addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException) { ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - - columns.push_back(column); + Reference xColumn(column); + columns.push_back(xColumn); sal_Int32 index = columns.size() - 1; - broadcast_add(index, column ); + xColumn->setIndex(index); return index; } @@ -160,22 +162,24 @@ void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL DefaultGridColumnModel::getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) { if ( index >=0 && index < ((sal_Int32)columns.size())) + { return columns[index]; + } else return Reference< XGridColumn >(); } //--------------------------------------------------------------------- -void SAL_CALL DefaultGridColumnModel::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) -{ - BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener ); -} - -//--------------------------------------------------------------------- - -void SAL_CALL DefaultGridColumnModel::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) -{ - BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener ); -} +//void SAL_CALL DefaultGridColumnModel::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +//{ +// BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener ); +//} +// +////--------------------------------------------------------------------- +// +//void SAL_CALL DefaultGridColumnModel::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +//{ +// BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener ); +//} //--------------------------------------------------------------------- void SAL_CALL DefaultGridColumnModel::setColumnHeaderHeight(sal_Int32 _value) throw (::com::sun::star::uno::RuntimeException) @@ -193,9 +197,25 @@ void SAL_CALL DefaultGridColumnModel::setDefaultColumns(sal_Int32 rowElements) t { ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); - Reference xColumn( m_xFactory->createInstance ( OUString::createFromAscii( "com.sun.star.awt.grid.GridColumn" ) ), UNO_QUERY ); for(sal_Int32 i=0;i xColumn( m_xFactory->createInstance ( OUString::createFromAscii( "com.sun.star.awt.grid.GridColumn" ) ), UNO_QUERY ); columns.push_back(xColumn); + xColumn->setIndex(i); + } +} +::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL DefaultGridColumnModel::copyColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException) +{ + Reference xColumn( m_xFactory->createInstance ( OUString::createFromAscii( "com.sun.star.awt.grid.GridColumn" ) ), UNO_QUERY ); + xColumn->setColumnWidth(column->getColumnWidth()); + xColumn->setPreferredWidth(column->getPreferredWidth()); + xColumn->setMaxWidth(column->getMaxWidth()); + xColumn->setMinWidth(column->getMinWidth()); + xColumn->setPreferredWidth(column->getPreferredWidth()); + xColumn->setResizeable(column->getResizeable()); + xColumn->setTitle(column->getTitle()); + xColumn->setHorizontalAlign(column->getHorizontalAlign()); + return xColumn; } //--------------------------------------------------------------------- // XComponent diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx index d700a6b07b5d..bfa9892b3777 100644 --- a/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx @@ -32,7 +32,7 @@ #include "precompiled_toolkit.hxx" #include #include -#include +//#include #include #include #include @@ -43,6 +43,7 @@ #include #include #include +#include using ::rtl::OUString; using namespace ::com::sun::star; @@ -54,7 +55,7 @@ using namespace ::com::sun::star::lang; namespace toolkit { -enum broadcast_type { column_added, column_removed, column_changed}; +//enum broadcast_type { column_added, column_removed, column_changed}; class DefaultGridColumnModel : public ::cppu::WeakImplHelper2< XGridColumnModel, XServiceInfo >, public MutexAndBroadcastHelper @@ -65,17 +66,18 @@ public: // XGridColumnModel - virtual ::sal_Bool SAL_CALL getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setColumnSelectionAllowed(::sal_Bool the_value) throw (::com::sun::star::uno::RuntimeException); + //virtual ::sal_Bool SAL_CALL getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException); + //virtual void SAL_CALL setColumnSelectionAllowed(::sal_Bool the_value) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); - virtual void SAL_CALL removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); + //virtual void SAL_CALL addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); + //virtual void SAL_CALL removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); virtual void SAL_CALL setColumnHeaderHeight( sal_Int32 _value) throw (com::sun::star::uno::RuntimeException); virtual sal_Int32 SAL_CALL getColumnHeaderHeight() throw (com::sun::star::uno::RuntimeException); virtual void SAL_CALL setDefaultColumns(sal_Int32 rowElements) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL copyColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException); // XComponent virtual void SAL_CALL dispose( ) throw (RuntimeException); virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); @@ -87,10 +89,10 @@ public: virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); private: - void broadcast( broadcast_type eType, const GridColumnEvent& aEvent ); - void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ); + /*void broadcast( broadcast_type eType, const GridColumnEvent& aEvent ); + void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue, sal_Int32 index,const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); void broadcast_add( sal_Int32 index,const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); - void broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); + void broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn );*/ std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > columns; sal_Bool selectionAllowed; diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx index 2d695a9bad0a..528e0e17c3e0 100644 --- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx +++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx @@ -35,9 +35,6 @@ #include #include -#include -#include - using ::rtl::OUString; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -57,9 +54,9 @@ namespace toolkit /////////////////////////////////////////////////////////////////////// DefaultGridDataModel::DefaultGridDataModel() -: rowHeight(10), +: rowHeight(0), rowHeaders(std::vector< ::rtl::OUString >()), - m_nRowHeaderWidth(7) + m_nRowHeaderWidth(10) { } diff --git a/toolkit/source/controls/grid/gridcolumn.cxx b/toolkit/source/controls/grid/gridcolumn.cxx index 40c2018c4cc5..b367ee908f3a 100644 --- a/toolkit/source/controls/grid/gridcolumn.cxx +++ b/toolkit/source/controls/grid/gridcolumn.cxx @@ -43,6 +43,15 @@ using namespace ::com::sun::star::awt::grid; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::style; +#define COLWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColWidth" )) +#define MAXWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MaxWidth" )) +#define MINWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "MinWidth" )) +#define PREFWIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PrefWidth" )) +#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 { @@ -54,7 +63,9 @@ GridColumn::GridColumn() : identifier(Any()) ,horizontalAlign(HorizontalAlignment(0)) ,columnWidth(4) +,preferredWidth(0) ,bResizeable(true) +,index(0) { } @@ -66,6 +77,39 @@ GridColumn::~GridColumn() //--------------------------------------------------------------------- +void GridColumn::broadcast( broadcast_column_type eType, const GridColumnEvent& aEvent ) +{ + ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.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) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridColumnEvent aEvent( xSource, name, oldValue, newValue, index); + 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) + preferredWidth = width; + else if (COLWIDTH == name) + columnWidth = width; +} //--------------------------------------------------------------------- // XGridColumn //--------------------------------------------------------------------- @@ -86,6 +130,7 @@ void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException) { + broadcast_changed(UPDATE, Any(columnWidth), Any()); return columnWidth; } @@ -94,11 +139,13 @@ void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) { columnWidth = value; + broadcast_changed(COLWIDTH, Any(columnWidth),Any(value)); } //-------------------------------------------------------------------- ::sal_Int32 SAL_CALL GridColumn::getPreferredWidth() throw (::com::sun::star::uno::RuntimeException) { + broadcast_changed(UPDATE, Any(preferredWidth), Any()); return preferredWidth; } @@ -107,6 +154,7 @@ void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::s void SAL_CALL GridColumn::setPreferredWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) { preferredWidth = value; + broadcast_changed(PREFWIDTH, Any(preferredWidth),Any(value)); } //-------------------------------------------------------------------- @@ -120,6 +168,7 @@ void SAL_CALL GridColumn::setPreferredWidth(::sal_Int32 value) throw (::com::sun void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) { maxWidth = value; + broadcast_changed(MAXWIDTH, Any(maxWidth),Any(value)); } //-------------------------------------------------------------------- @@ -133,6 +182,7 @@ void SAL_CALL GridColumn::setMaxWidth(::sal_Int32 value) throw (::com::sun::star void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) { minWidth = value; + broadcast_changed(MINWIDTH, Any(minWidth),Any(value)); } //-------------------------------------------------------------------- @@ -147,6 +197,7 @@ void SAL_CALL GridColumn::setMinWidth(::sal_Int32 value) throw (::com::sun::star void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException) { title = value; + broadcast_changed(TITLE, Any(title),Any(value)); } //-------------------------------------------------------------------- @@ -160,6 +211,7 @@ sal_Bool SAL_CALL GridColumn::getResizeable() throw (::com::sun::star::uno::Runt void SAL_CALL GridColumn::setResizeable(sal_Bool value) throw (::com::sun::star::uno::RuntimeException) { bResizeable = value; + broadcast_changed(COLRESIZE, Any(bResizeable),Any(value)); } //--------------------------------------------------------------------- HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun::star::uno::RuntimeException) @@ -171,6 +223,19 @@ HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() throw (::com::sun: void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (::com::sun::star::uno::RuntimeException) { horizontalAlign = align; + broadcast_changed(HALIGN, Any(horizontalAlign),Any(align)); +} +//--------------------------------------------------------------------- +void SAL_CALL GridColumn::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener ); } //--------------------------------------------------------------------- @@ -179,22 +244,30 @@ void SAL_CALL GridColumn::setHorizontalAlign(HorizontalAlignment align) throw (: void SAL_CALL GridColumn::dispose() throw (RuntimeException) { + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) ); + BrdcstHelper.aLC.disposeAndClear( aEvent ); } //--------------------------------------------------------------------- void SAL_CALL GridColumn::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) { - (void) xListener; + BrdcstHelper.addListener( XEventListener::static_type(), xListener ); } //--------------------------------------------------------------------- void SAL_CALL GridColumn::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) { - (void) xListener; + BrdcstHelper.removeListener( XEventListener::static_type(), xListener ); +} +void SAL_CALL GridColumn::setIndex(sal_Int32 _nIndex) throw (::com::sun::star::uno::RuntimeException) +{ + index = _nIndex; } - //--------------------------------------------------------------------- // XServiceInfo //--------------------------------------------------------------------- diff --git a/toolkit/source/controls/grid/gridcolumn.hxx b/toolkit/source/controls/grid/gridcolumn.hxx index a458a07ffda8..d7651a2e00ab 100644 --- a/toolkit/source/controls/grid/gridcolumn.hxx +++ b/toolkit/source/controls/grid/gridcolumn.hxx @@ -31,6 +31,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_toolkit.hxx" #include +#include +#include #include #include #include @@ -51,6 +53,7 @@ using namespace ::com::sun::star::lang; namespace toolkit { +enum broadcast_column_type { column_attribute_changed}; class GridColumn : public ::cppu::WeakImplHelper2< XGridColumn, XServiceInfo >, public MutexAndBroadcastHelper { @@ -75,6 +78,9 @@ public: virtual void SAL_CALL setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::style::HorizontalAlignment SAL_CALL getHorizontalAlign() 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 Reference< XGridColumnListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeColumnListener( const Reference< 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 virtual void SAL_CALL dispose( ) throw (RuntimeException); virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); @@ -85,9 +91,13 @@ public: virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); - + virtual void SAL_CALL setIndex(sal_Int32 _nIndex)throw (::com::sun::star::uno::RuntimeException); private: + void broadcast( broadcast_column_type eType, const GridColumnEvent& aEvent ); + void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue); + Any identifier; + sal_Int32 index; sal_Int32 columnWidth; sal_Int32 preferredWidth; sal_Int32 maxWidth; diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx index fa0c3de3adb3..b279ace0ef12 100644 --- a/toolkit/source/controls/grid/gridcontrol.cxx +++ b/toolkit/source/controls/grid/gridcontrol.cxx @@ -86,7 +86,7 @@ UnoGridModel::UnoGridModel() ImplRegisterProperty( BASEPROPERTY_GRID_EVEN_ROW_BACKGROUND ); ImplRegisterProperty( BASEPROPERTY_GRID_HEADER_BACKGROUND ); ImplRegisterProperty( BASEPROPERTY_GRID_LINE_COLOR ); - + ImplRegisterProperty( BASEPROPERTY_GRID_ROW_BACKGROUND ); } UnoGridModel::UnoGridModel( const UnoGridModel& rModel ) @@ -112,6 +112,22 @@ Any UnoGridModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_GridControl ) ); case BASEPROPERTY_GRID_SELECTIONMODE: return uno::makeAny( SelectionType(1) ); + case BASEPROPERTY_GRID_SHOWROWHEADER: + return uno::makeAny( (sal_Bool)sal_False ); + case BASEPROPERTY_GRID_SHOWCOLUMNHEADER: + return uno::makeAny( (sal_Bool)sal_False ); + case BASEPROPERTY_GRID_DATAMODEL: + return uno::makeAny( Reference ()); + case BASEPROPERTY_GRID_COLUMNMODEL: + return uno::makeAny(Reference() ); + case BASEPROPERTY_GRID_EVEN_ROW_BACKGROUND: + return uno::makeAny( com::sun::star::util::Color(0xFFFFFF) ); + case BASEPROPERTY_GRID_HEADER_BACKGROUND: + return uno::makeAny( com::sun::star::util::Color(0xFFFFFF) ); + case BASEPROPERTY_GRID_LINE_COLOR: + return uno::makeAny( com::sun::star::util::Color(0xFFFFFF) ); + case BASEPROPERTY_GRID_ROW_BACKGROUND: + return uno::makeAny(com::sun::star::util::Color(0xFFFFFF) ); default: return UnoControlModel::ImplGetDefaultValue( nPropId ); } @@ -141,7 +157,8 @@ Reference< XPropertySetInfo > UnoGridModel::getPropertySetInfo( ) throw(Runtime // class UnoGridControl // ---------------------------------------------------- UnoGridControl::UnoGridControl() -: mSelectionMode(SelectionType(1)) +: mSelectionMode(SelectionType(1)), + m_aSelectionListeners( *this ) { } @@ -152,6 +169,9 @@ OUString UnoGridControl::GetComponentServiceName() void SAL_CALL UnoGridControl::dispose( ) throw(RuntimeException) { + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + m_aSelectionListeners.disposeAndClear( aEvt ); UnoControl::dispose(); } @@ -160,17 +180,23 @@ void UnoGridControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolk UnoControlBase::createPeer( rxToolkit, rParentPeer ); Reference< XGridControl > xGrid( getPeer(), UNO_QUERY_THROW ); + xGrid->addSelectionListener(&m_aSelectionListeners); Reference xListener ( getPeer(), UNO_QUERY_THROW ); - //Reference xColListener ( getPeer(), UNO_QUERY_THROW ); + Reference xColListener ( getPeer(), UNO_QUERY_THROW ); Reference xPropSet ( getModel(), UNO_QUERY_THROW ); Reference xGridDataModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW ); if(xGridDataModel != NULL) xGridDataModel->addDataListener(xListener); - //Reference xGridColumnModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "ColumnModel" )), UNO_QUERY_THROW ); - //if(xGridColumnModel != NULL) - // xGridColumnModel->addColumnListener(xColListener); + Reference xGridColumnModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "ColumnModel" )), UNO_QUERY_THROW ); + if(xGridColumnModel != NULL) + { + for(int i = 0;igetColumnCount();i++) + { + xGridColumnModel->getColumn(i)->addColumnListener(xColListener); + } + } } @@ -212,16 +238,24 @@ void SAL_CALL UnoGridControl::removeMouseListener(const ::com::sun::star::uno::R return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getMaxSelectionIndex(); } -void SAL_CALL UnoGridControl::insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL UnoGridControl::selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->insertIndexIntervall( start, length); + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->selectRows( rangeOfRows); } -void SAL_CALL UnoGridControl::removeIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +void SAL_CALL UnoGridControl::selectAllRows() throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeIndexIntervall( start, length ); + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->selectAllRows(); +} +void SAL_CALL UnoGridControl::deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->deselectRows( rangeOfRows); } +void SAL_CALL UnoGridControl::deselectAllRows() throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->deselectAllRows(); +} ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL UnoGridControl::getSelection() throw (::com::sun::star::uno::RuntimeException) { return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); @@ -244,12 +278,12 @@ void SAL_CALL UnoGridControl::selectRow(::sal_Int32 y) throw (::com::sun::star:: void SAL_CALL UnoGridControl::addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->addSelectionListener( listener ); + m_aSelectionListeners.addInterface( listener ); } void SAL_CALL UnoGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) { - Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeSelectionListener( listener ); + m_aSelectionListeners.removeInterface( listener ); } }//namespace toolkit diff --git a/toolkit/source/controls/grid/gridcontrol.hxx b/toolkit/source/controls/grid/gridcontrol.hxx index 8b219e70a0f2..c566569d7dbf 100644 --- a/toolkit/source/controls/grid/gridcontrol.hxx +++ b/toolkit/source/controls/grid/gridcontrol.hxx @@ -101,8 +101,10 @@ public: virtual ::sal_Int32 SAL_CALL getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectAllRows() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectRows(const ::com::sun::star::uno::Sequence< ::sal_Int32 >& rangeOfRows) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL deselectAllRows() throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL getSelection() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isSelectedIndex(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); @@ -116,6 +118,7 @@ public: using UnoControl::getPeer; private: ::com::sun::star::view::SelectionType mSelectionMode; + SelectionListenerMultiplexer m_aSelectionListeners; }; } // toolkit diff --git a/toolkit/source/helper/listenermultiplexer.cxx b/toolkit/source/helper/listenermultiplexer.cxx index cdbb156cd0f5..ee4c9bf4c144 100644 --- a/toolkit/source/helper/listenermultiplexer.cxx +++ b/toolkit/source/helper/listenermultiplexer.cxx @@ -209,3 +209,8 @@ IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TreeExpansionListenerMultiplexer, ::com // ---------------------------------------------------- IMPL_LISTENERMULTIPLEXER_BASEMETHODS( TreeEditListenerMultiplexer, ::com::sun::star::awt::tree::XTreeEditListener ) +// ---------------------------------------------------- +// class SelectionListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( SelectionListenerMultiplexer, ::com::sun::star::awt::grid::XGridSelectionListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( SelectionListenerMultiplexer, ::com::sun::star::awt::grid::XGridSelectionListener, selectionChanged, ::com::sun::star::awt::grid::GridSelectionEvent ) \ No newline at end of file diff --git a/toolkit/source/helper/property.cxx b/toolkit/source/helper/property.cxx index 9438cb93541b..beb746e02f36 100644 --- a/toolkit/source/helper/property.cxx +++ b/toolkit/source/helper/property.cxx @@ -286,8 +286,9 @@ ImplPropertyInfo* ImplGetPropertyInfos( sal_uInt16& rElementCount ) DECL_PROP_3 ( "ReferenceDevice", REFERENCE_DEVICE, Reference< XDevice >,BOUND, MAYBEDEFAULT, TRANSIENT ), DECL_PROP_3 ( "EvenRowBackgroundColor", GRID_EVEN_ROW_BACKGROUND, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), DECL_PROP_3 ( "HeaderBackgroundColor", GRID_HEADER_BACKGROUND, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), - DECL_PROP_3 ( "LineColor", GRID_LINE_COLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ) - }; + DECL_PROP_3 ( "LineColor", GRID_LINE_COLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "RowBackgroundColor", GRID_ROW_BACKGROUND, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ) + }; pPropertyInfos = aImplPropertyInfos; nElements = sizeof( aImplPropertyInfos ) / sizeof( ImplPropertyInfo ); } diff --git a/vcl/inc/vcl/vclevent.hxx b/vcl/inc/vcl/vclevent.hxx index 570c8ad0a342..fe9e566f75e3 100644 --- a/vcl/inc/vcl/vclevent.hxx +++ b/vcl/inc/vcl/vclevent.hxx @@ -195,6 +195,7 @@ namespace com { namespace sun { namespace star { #define VCLEVENT_TOOLBOX_BUTTONSTATECHANGED 1223 // pData = itempos #define VCLEVENT_TABLECELL_NAMECHANGED 1224 // pData = struct(Entry, Column, oldText) +#define VCLEVENT_TABLEROW_SELECT 1225 class VCL_DLLPUBLIC VclSimpleEvent { -- cgit