diff options
author | Mihaela Kedikova <misheto@openoffice.org> | 2010-03-22 11:17:10 +0100 |
---|---|---|
committer | Mihaela Kedikova <misheto@openoffice.org> | 2010-03-22 11:17:10 +0100 |
commit | 99d003c030ec5d547c452efdc42be3a3fa6810fa (patch) | |
tree | c163017c3753cb4323f4ee058f4248bed8d0d0e8 /svtools | |
parent | 9945f4ca9649f961bbc6d9f5be238771e3e2b96c (diff) |
recent changes for grid control
Diffstat (limited to 'svtools')
-rwxr-xr-x | svtools/inc/svtools/accessibletable.hxx | 3 | ||||
-rw-r--r-- | svtools/inc/svtools/table/tablecontrol.hxx | 16 | ||||
-rw-r--r-- | svtools/inc/svtools/table/tabledatawindow.hxx | 10 | ||||
-rw-r--r-- | svtools/source/table/gridtablerenderer.cxx | 22 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol.cxx | 66 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol_impl.cxx | 335 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol_impl.hxx | 14 | ||||
-rw-r--r-- | svtools/source/table/tabledatawindow.cxx | 10 | ||||
-rwxr-xr-x | svtools/source/uno/svtxgridcontrol.cxx | 407 | ||||
-rwxr-xr-x | svtools/source/uno/svtxgridcontrol.hxx | 33 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.cxx | 93 | ||||
-rw-r--r-- | svtools/source/uno/unocontroltablemodel.hxx | 5 |
12 files changed, 531 insertions, 483 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 <vcl/window.hxx> #include <unotools/accessiblestatesethelper.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> -#include <svtools/table/tablemodel.hxx> // ============================================================================ @@ -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<sal_Int32>& 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<sal_Int32>& 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<sal_Int32>& 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<RowPos>::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<RowPos>::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<RowPos>::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<RowPos>::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<m_nRowCount) + if(m_nCurRow<m_nRowCount-1) m_nCurRow++; else return bSuccess = true; - //if net row already selected, deselect it, otherwise select it - if(m_nRowSelected[nextRow] == m_nCurRow) + //if next row already selected, deselect it, otherwise select it + 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<m_nRowCount-1) + { + m_nRowSelected.push_back(m_nCurRow); + m_nCurRow++; + m_nRowSelected.push_back(m_nCurRow); + invalidateSelectedRegion(m_nCurRow-1, m_nCurRow, rCells); + } + } } } else { - //there wasn't any selection, select curennt and row beneath, otherwise onlyrow beneath + //there wasn't any selection, select current and row beneath, otherwise only row beneath if(m_nCurRow<m_nRowCount-1) { m_nRowSelected.push_back(m_nCurRow); @@ -1455,12 +1472,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; } } @@ -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;i<m_nRowCount;i++) { for(int j=-1;j<m_nColumnCount;j++) @@ -1601,7 +1615,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=0;i<m_nRowCount;i++) { for(int j=-1;j<m_nColumnCount;j++) @@ -1636,14 +1649,14 @@ namespace svt { namespace table if(_nPrevRow == _nCurRow) { impl_getCellRect(m_nCurColumn,_nCurRow,rCells); - _rCellRect.Top()=rCells.Top(); + _rCellRect.Top()=--rCells.Top(); _rCellRect.Bottom()=rCells.Bottom(); } //if the region is above the current row else if(_nPrevRow < _nCurRow ) { impl_getCellRect(m_nCurColumn,_nPrevRow,rCells); - _rCellRect.Top()=rCells.Top(); + _rCellRect.Top()= --rCells.Top(); impl_getCellRect(m_nCurColumn,_nCurRow,rCells); _rCellRect.Bottom()=rCells.Bottom(); } @@ -1651,7 +1664,7 @@ namespace svt { namespace table else { impl_getCellRect(m_nCurColumn,_nCurRow,rCells); - _rCellRect.Top()=--rCells.Top(); + _rCellRect.Top()= --rCells.Top(); impl_getCellRect(m_nCurColumn,_nPrevRow,rCells); _rCellRect.Bottom()=rCells.Bottom(); } @@ -1659,26 +1672,14 @@ namespace svt { namespace table } //------------------------------------------------------------------------------- - //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<RowPos>::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<RowPos>::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<RowPos> 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<RowPos> 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 <com/sun/star/awt/grid/GridInvalidDataException.hpp> #include <com/sun/star/awt/grid/GridInvalidModelException.hpp> #include <com/sun/star/util/Color.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> 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<Sequence< ::com::sun::star::awt::XControl > > cellData = m_xDataModel->getData(); - //Sequence<Window*> rowData(0); - //std::vector< std::vector< Window* > > aCellContent(0); - //for(int i = 0; i< m_xDataModel->getRowCount();++i) - //{ - // rowData = cellData[i]; - // std::vector<Window*> newRow( - // comphelper::sequenceToContainer< std::vector<Window* > >(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<rtl::OUString > >(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<rtl::OUString > >(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<Reference< XGridColumn > > columns = m_xColumnModel->getColumns(); std::vector<Reference< XGridColumn > > aNewColumns( comphelper::sequenceToContainer<std::vector<Reference< XGridColumn > > >(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<XGridColumnListener> listener(*this,UNO_QUERY_THROW); + m_xColumnModel->setDefaultColumns(rawRowData.getLength()); for ( ::svt::table::ColPos col = 0; col < rawRowData.getLength(); ++col ) { UnoControlTableColumn* tableColumn = new UnoControlTableColumn(); m_pTableModel->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<std::vector<Any> >::iterator iter = m_pTableModel->getCellContent().begin(); - //for(;iter!=m_pTableModel->getCellContent().end();++iter) - //{ - // std::vector<Any> vectIn = *iter; - // std::vector<Any>::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<std::vector<Any> >::iterator rowPos =m_pTableModel->getCellContent().begin() + Event.index; - //for ( std::vector<TableContentType*>::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<RowPos>& selectedRows = pTable->GetSelectedRows(); + if(selectedRows.empty()) + return -1; + else + { + std::vector<RowPos>::iterator itStart = selectedRows.begin(); + std::vector<RowPos>::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<RowPos>& selectedRows = pTable->GetSelectedRows(); + if(selectedRows.empty()) + return -1; + else + { + std::vector<RowPos>::iterator itStart = selectedRows.begin(); + std::vector<RowPos>::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<RowPos>& 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;i<seqSize;i++) + selectedRows.push_back(rangeOfRows[i]); + pTable->selectionChanged(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<RowPos>& selectedRows = pTable->GetSelectedRows(); + if(!selectedRows.empty()) + selectedRows.clear(); + for(int i=0;i<m_pTableModel->getRowCount();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<RowPos>& selectedRows = pTable->GetSelectedRows(); + std::vector<RowPos>::iterator itStart = selectedRows.begin(); + std::vector<RowPos>::iterator itEnd = selectedRows.end(); + sal_Int32 start = rangeOfRows[0]; + sal_Int32 end = rangeOfRows[rangeOfRows.getLength()-1]; + std::vector<RowPos>::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<RowPos>& 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<RowPos>& 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<RowPos>& selectedRows = pTable->GetSelectedRows(); + ::std::vector<RowPos>::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<RowPos>& 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<sal_Int32> 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 <svtools/table/tablecontrol.hxx> #include <com/sun/star/awt/grid/XGridControl.hpp> #include <com/sun/star/awt/grid/XGridDataListener.hpp> +#include <com/sun/star/awt/grid/XGridColumnListener.hpp> #include <com/sun/star/awt/grid/GridDataEvent.hpp> +#include <com/sun/star/awt/grid/GridColumnEvent.hpp> #include <com/sun/star/awt/grid/XGridColumnModel.hpp> #include <com/sun/star/awt/grid/XGridDataModel.hpp> #include <com/sun/star/awt/grid/XGridSelectionListener.hpp> #include <toolkit/awt/vclxwindow.hxx> #include <toolkit/awt/vclxwindows.hxx> #include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/implbase2.hxx> -//#include <toolkit/helper/listenermultiplexer.hxx> +#include <cppuhelper/implbase3.hxx> +#include <toolkit/helper/listenermultiplexer.hxx> 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<rtl::OUString>& aRowHeadersTitle; - //std::vector<std::vector<rtl::OUString> >& aCellContent; std::vector<std::vector< Any > >& 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<rtl::OUString>(0))) - //,aCellContent ( *(new std::vector<std::vector<OUString> >(0))) ,aCellContent ( *(new std::vector<std::vector< Any > >(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<std::vector<Any> >::iterator iter = m_pImpl->aCellContent.begin(); - // for(;iter!=m_pImpl->aCellContent.end();++iter) - // { - // std::vector<Any> vectIn = *iter; - // std::vector<Any>::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<std::vector<rtl::OUString> > cellContent) - // { - // //if(cellContent.empty()) - // //{ - // // unsigned int i = m_pImpl->aColumns.size(); - // // std::vector<rtl::OUString>& emptyCells; - // // while(i!=0) - // // { - // // cellContent.push_back(emptyCells); - // // --i; - // // } - // //} - // //std::vector<rtl::OUString> cCC; - // //for(::std::vector<std::vector<rtl::OUString> >::iterator iter = cellContent.begin(); iter!= cellContent.end();++iter) - // //{ - // // cCC = *iter; - // // m_pImpl->aCellContent.push_back(cCC); - // //} - // m_pImpl->aCellContent.swap( cellContent ); - // } - - //std::vector<std::vector<rtl::OUString> >& UnoControlTableModel::getCellContent() - // { - // return m_pImpl->aCellContent; - // } - //-------------------------------------------------------------------- void UnoControlTableModel::setCellContent(std::vector<std::vector< Any > > cellContent) { - //::vos::OGuard aGuard( GetMutex() ); - /* - if(cellContent.empty()) - { - unsigned int i = m_pImpl->aColumns.size(); - std::vector<Window> emptyCells; - while(i!=0) - { - cellContent.push_back(emptyCells); - --i; - } - } - */ - - m_pImpl->aCellContent.swap( cellContent ); - - /*for(::std::vector<std::vector<Window> >::iterator iter = cellContent.begin(); iter!= cellContent.end();++iter) - { - m_pImpl->aCellContent.push_back(*iter); - }*/ + m_pImpl->aCellContent = cellContent; } std::vector<std::vector< Any > >& UnoControlTableModel::getCellContent() @@ -512,20 +444,7 @@ using namespace ::com::sun::star::uno; //-------------------------------------------------------------------- void UnoControlTableModel::setRowHeaderName(std::vector<rtl::OUString> cellColumnContent) { - if(cellColumnContent.empty()) - { - unsigned int i = m_pImpl->aColumns.size(); - while(i!=0) - { - cellColumnContent.push_back(rtl::OUString::createFromAscii("")); - --i; - } - } - for(::std::vector<rtl::OUString>::iterator iter = cellColumnContent.begin(); iter!= cellColumnContent.end();++iter) - { - rtl::OUString s = *iter; - m_pImpl->aRowHeadersTitle.push_back(*iter); - } + m_pImpl->aRowHeadersTitle = cellColumnContent; } std::vector<rtl::OUString>& 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 <com/sun/star/util/Color.hpp> #include <com/sun/star/style/VerticalAlignment.hpp> #include <com/sun/star/style/HorizontalAlignment.hpp> -//#include <toolkit/helper/listenermultiplexer.hxx> 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; |