diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-24 12:10:32 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-30 08:38:43 +0200 |
commit | 6b2e5bce6e658a6e6c202ed801052da14b5f87be (patch) | |
tree | e7fcca57571e14ffb8a076e6586c62ca568164ae | |
parent | f15ea6fa71e66bfea373a01580e76c7d8b69d3cb (diff) |
loplugin:useuniqueptr in BrowseBox
Change-Id: I079009f5e9f5e8c8d2666f79e2bfcefe662acf6a
Reviewed-on: https://gerrit.libreoffice.org/53591
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/svtools/brwbox.hxx | 7 | ||||
-rw-r--r-- | svtools/source/brwbox/brwbox1.cxx | 148 | ||||
-rw-r--r-- | svtools/source/brwbox/brwbox2.cxx | 113 | ||||
-rw-r--r-- | svtools/source/brwbox/datwin.cxx | 16 |
4 files changed, 131 insertions, 153 deletions
diff --git a/include/svtools/brwbox.hxx b/include/svtools/brwbox.hxx index 4bfad8d4633a..a4aa7a8ac5e0 100644 --- a/include/svtools/brwbox.hxx +++ b/include/svtools/brwbox.hxx @@ -39,7 +39,6 @@ class BrowserColumn; class BrowserDataWin; class MultiSelection; class BrowserHeader; -typedef ::std::vector< BrowserColumn* > BrowserColumns; namespace svt { class BrowseBoxImpl; @@ -239,13 +238,13 @@ private: TriState bHideCursor; // hide cursor (frame) Range aSelRange; // for selection expansion - BrowserColumns pCols; // array of column-descriptions + ::std::vector< std::unique_ptr<BrowserColumn> > mvCols; // array of column-descriptions union { MultiSelection* pSel; // selected rows for multi-selection long nSel; // selected row for single-selection } uRow; - MultiSelection* pColSel; // selected column-ids + std::unique_ptr<MultiSelection> pColSel; // selected column-ids // fdo#83943, detect if making the cursor position visible is impossible to achieve struct CursorMoveAttempt @@ -487,7 +486,7 @@ public: long FirstSelectedRow(); long LastSelectedRow(); long NextSelectedRow(); - const MultiSelection* GetColumnSelection() const { return pColSel; } + const MultiSelection* GetColumnSelection() const { return pColSel.get(); } const MultiSelection* GetSelection() const { return bMultiSelection ? uRow.pSel : nullptr; } diff --git a/svtools/source/brwbox/brwbox1.cxx b/svtools/source/brwbox/brwbox1.cxx index ee4326154038..634469df1ae7 100644 --- a/svtools/source/brwbox/brwbox1.cxx +++ b/svtools/source/brwbox/brwbox1.cxx @@ -139,10 +139,8 @@ void BrowseBox::dispose() aHScroll.disposeAndClear(); // free columns-space - for (BrowserColumn* pCol : pCols) - delete pCol; - pCols.clear(); - delete pColSel; + mvCols.clear(); + pColSel.reset(); if ( bMultiSelection ) delete uRow.pSel; DragSourceHelper::dispose(); @@ -218,14 +216,14 @@ void BrowseBox::InsertHandleColumn( sal_uLong nWidth ) { #if OSL_DEBUG_LEVEL > 0 - OSL_ENSURE( ColCount() == 0 || pCols[0]->GetId() != HandleColumnId , "BrowseBox::InsertHandleColumn: there is already a handle column" ); + OSL_ENSURE( ColCount() == 0 || mvCols[0]->GetId() != HandleColumnId , "BrowseBox::InsertHandleColumn: there is already a handle column" ); { - for (auto const col : pCols) + for (auto const & col : mvCols) OSL_ENSURE( col->GetId() != HandleColumnId, "BrowseBox::InsertHandleColumn: there is a non-Handle column with handle ID" ); } #endif - pCols.insert( pCols.begin(), new BrowserColumn( 0, OUString(), nWidth, GetZoom() ) ); + mvCols.insert( mvCols.begin(), std::unique_ptr<BrowserColumn>(new BrowserColumn( 0, OUString(), nWidth, GetZoom() )) ); FreezeColumn( 0 ); // adjust headerbar @@ -250,20 +248,18 @@ void BrowseBox::InsertDataColumn( sal_uInt16 nItemId, const OUString& rText, #if OSL_DEBUG_LEVEL > 0 { - for (auto const& col : pCols) + for (auto const& col : mvCols) OSL_ENSURE( col->GetId() != nItemId, "BrowseBox::InsertDataColumn: duplicate column Id" ); } #endif - if ( nPos < pCols.size() ) + if ( nPos < mvCols.size() ) { - BrowserColumns::iterator it = pCols.begin(); - ::std::advance( it, nPos ); - pCols.insert( it, new BrowserColumn( nItemId, rText, nWidth, GetZoom() ) ); + mvCols.emplace( mvCols.begin() + nPos, new BrowserColumn( nItemId, rText, nWidth, GetZoom() ) ); } else { - pCols.push_back( new BrowserColumn( nItemId, rText, nWidth, GetZoom() ) ); + mvCols.emplace_back( new BrowserColumn( nItemId, rText, nWidth, GetZoom() ) ); } if ( nCurColId == 0 ) nCurColId = nItemId; @@ -289,7 +285,7 @@ sal_uInt16 BrowseBox::ToggleSelectedColumn() ToggleSelection(); long nSelected = pColSel->FirstSelected(); if (nSelected != static_cast<long>(SFX_ENDOFSELECTION)) - nSelectedColId = pCols[nSelected]->GetId(); + nSelectedColId = mvCols[nSelected]->GetId(); pColSel->SelectAll(false); } return nSelectedColId; @@ -310,30 +306,26 @@ void BrowseBox::FreezeColumn( sal_uInt16 nItemId ) { // get the position in the current array size_t nItemPos = GetColumnPos( nItemId ); - if ( nItemPos >= pCols.size() ) + if ( nItemPos >= mvCols.size() ) // not available! return; // doesn't the state change? - if ( pCols[ nItemPos ]->IsFrozen() ) + if ( mvCols[ nItemPos ]->IsFrozen() ) return; // remark the column selection sal_uInt16 nSelectedColId = ToggleSelectedColumn(); // to be moved? - if ( nItemPos != 0 && !pCols[ nItemPos-1 ]->IsFrozen() ) + if ( nItemPos != 0 && !mvCols[ nItemPos-1 ]->IsFrozen() ) { // move to the right of the last frozen column sal_uInt16 nFirstScrollable = FrozenColCount(); - BrowserColumn *pColumn = pCols[ nItemPos ]; - BrowserColumns::iterator it = pCols.begin(); - ::std::advance( it, nItemPos ); - pCols.erase( it ); + std::unique_ptr<BrowserColumn> pColumn = std::move(mvCols[ nItemPos ]); + mvCols.erase( mvCols.begin() + nItemPos ); nItemPos = nFirstScrollable; - it = pCols.begin(); - ::std::advance( it, nItemPos ); - pCols.insert( it, pColumn ); + mvCols.insert( mvCols.begin() + nItemPos, std::move(pColumn) ); } // adjust the number of the first scrollable and visible column @@ -341,7 +333,7 @@ void BrowseBox::FreezeColumn( sal_uInt16 nItemId ) nFirstCol = nItemPos + 1; // toggle the freeze-state of the column - pCols[ nItemPos ]->Freeze(); + mvCols[ nItemPos ]->Freeze(); // align the scrollbar-range UpdateScrollbars(); @@ -363,7 +355,7 @@ void BrowseBox::SetColumnPos( sal_uInt16 nColumnId, sal_uInt16 nPos ) // get the position in the current array sal_uInt16 nOldPos = GetColumnPos( nColumnId ); - if ( nOldPos >= pCols.size() ) + if ( nOldPos >= mvCols.size() ) // not available! return; @@ -386,18 +378,14 @@ void BrowseBox::SetColumnPos( sal_uInt16 nColumnId, sal_uInt16 nPos ) if ( nOldPos > nPos ) nNextPos = nOldPos - 1; - BrowserColumn *pNextCol = pCols[ nNextPos ]; + BrowserColumn *pNextCol = mvCols[ nNextPos ].get(); tools::Rectangle aNextRect(GetFieldRect( pNextCol->GetId() )); // move column internally { - BrowserColumns::iterator it = pCols.begin(); - ::std::advance( it, nOldPos ); - BrowserColumn* pTemp = *it; - pCols.erase( it ); - it = pCols.begin(); - ::std::advance( it, nPos ); - pCols.insert( it, pTemp ); + std::unique_ptr<BrowserColumn> pTemp = std::move(mvCols[nOldPos]); + mvCols.erase( mvCols.begin() + nOldPos ); + mvCols.insert( mvCols.begin() + nPos, std::move(pTemp) ); } // determine new column area @@ -482,12 +470,12 @@ void BrowseBox::SetColumnTitle( sal_uInt16 nItemId, const OUString& rTitle ) // get the position in the current array sal_uInt16 nItemPos = GetColumnPos( nItemId ); - if ( nItemPos >= pCols.size() ) + if ( nItemPos >= mvCols.size() ) // not available! return; // does the state change? - BrowserColumn *pCol = pCols[ nItemPos ]; + BrowserColumn *pCol = mvCols[ nItemPos ].get(); if ( pCol->Title() == rTitle ) return; @@ -521,17 +509,17 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth ) // get the position in the current array size_t nItemPos = GetColumnPos( nItemId ); - if ( nItemPos >= pCols.size() ) + if ( nItemPos >= mvCols.size() ) return; // does the state change? - if ( !(nWidth >= LONG_MAX || pCols[ nItemPos ]->Width() != nWidth) ) + if ( !(nWidth >= LONG_MAX || mvCols[ nItemPos ]->Width() != nWidth) ) return; - long nOldWidth = pCols[ nItemPos ]->Width(); + long nOldWidth = mvCols[ nItemPos ]->Width(); // adjust last column, if necessary - if ( IsVisible() && nItemPos == pCols.size() - 1 ) + if ( IsVisible() && nItemPos == mvCols.size() - 1 ) { long nMaxWidth = pDataWin->GetSizePixel().Width(); nMaxWidth -= pDataWin->bAutoSizeLastCol @@ -551,7 +539,7 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth ) // do we want to display the change immediately? bool bUpdate = GetUpdateMode() && - ( pCols[ nItemPos ]->IsFrozen() || nItemPos >= nFirstCol ); + ( mvCols[ nItemPos ]->IsFrozen() || nItemPos >= nFirstCol ); if ( bUpdate ) { @@ -563,7 +551,7 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth ) } // set width - pCols[ nItemPos ]->SetWidth(nWidth, GetZoom()); + mvCols[ nItemPos ]->SetWidth(nWidth, GetZoom()); // scroll and invalidate if ( bUpdate ) @@ -572,7 +560,7 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth ) long nX = 0; for ( size_t nCol = 0; nCol < nItemPos; ++nCol ) { - BrowserColumn *pCol = pCols[ nCol ]; + BrowserColumn *pCol = mvCols[ nCol ].get(); if ( pCol->IsFrozen() || nCol >= nFirstCol ) nX += pCol->Width(); } @@ -615,7 +603,7 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth ) nItemId ? nItemId : USHRT_MAX - 1, nWidth ); // adjust last column - if ( nItemPos != pCols.size() - 1 ) + if ( nItemPos != mvCols.size() - 1 ) AutoSizeLastColumn(); } @@ -625,7 +613,7 @@ void BrowseBox::AutoSizeLastColumn() if ( pDataWin->bAutoSizeLastCol && pDataWin->GetUpdateMode() ) { - sal_uInt16 nId = GetColumnId( static_cast<sal_uInt16>(pCols.size()) - 1 ); + sal_uInt16 nId = GetColumnId( static_cast<sal_uInt16>(mvCols.size()) - 1 ); SetColumnWidth( nId, LONG_MAX ); ColumnResized( nId ); } @@ -650,10 +638,7 @@ void BrowseBox::RemoveColumn( sal_uInt16 nItemId ) nCurColId = 0; // delete column - BrowserColumns::iterator it = pCols.begin(); - ::std::advance( it, nPos ); - delete *it; - pCols.erase( it ); + mvCols.erase( mvCols.begin() + nPos ); if ( nFirstCol >= nPos && nFirstCol > FrozenColCount() ) { OSL_ENSURE(nFirstCol > 0,"FirstCol must be greater zero!"); @@ -716,12 +701,10 @@ void BrowseBox::RemoveColumn( sal_uInt16 nItemId ) void BrowseBox::RemoveColumns() { - size_t nOldCount = pCols.size(); + size_t nOldCount = mvCols.size(); // remove all columns - for ( size_t i = 0; i < nOldCount; ++i ) - delete pCols[ i ]; - pCols.clear(); + mvCols.clear(); // correct column selection if ( pColSel ) @@ -750,7 +733,7 @@ void BrowseBox::RemoveColumns() if ( !isAccessibleAlive() ) return; - if ( pCols.size() == nOldCount ) + if ( mvCols.size() == nOldCount ) return; // all columns should be removed, so we remove the column header bar and append it again @@ -787,9 +770,9 @@ OUString BrowseBox::GetColumnTitle( sal_uInt16 nId ) const { sal_uInt16 nItemPos = GetColumnPos( nId ); - if ( nItemPos >= pCols.size() ) + if ( nItemPos >= mvCols.size() ) return OUString(); - return pCols[ nItemPos ]->Title(); + return mvCols[ nItemPos ]->Title(); } @@ -802,7 +785,7 @@ long BrowseBox::GetRowCount() const sal_uInt16 BrowseBox::ColCount() const { - return static_cast<sal_uInt16>(pCols.size()); + return static_cast<sal_uInt16>(mvCols.size()); } @@ -837,7 +820,7 @@ long BrowseBox::ScrollColumns( long nCols ) { if ( nFirstCol + nCols < 0 || - nFirstCol + nCols >= static_cast<long>(pCols.size()) ) + nFirstCol + nCols >= static_cast<long>(mvCols.size()) ) return 0; // implicitly hides cursor while scrolling @@ -859,7 +842,7 @@ long BrowseBox::ScrollColumns( long nCols ) } else { - long nDelta = pCols[ nFirstCol-1 ]->Width(); + long nDelta = mvCols[ nFirstCol-1 ]->Width(); long nFrozenWidth = GetFrozenWidth(); tools::Rectangle aScrollRect( Point( nFrozenWidth + nDelta, 0 ), @@ -905,7 +888,7 @@ long BrowseBox::ScrollColumns( long nCols ) } else { - long nDelta = pCols[ nFirstCol ]->Width(); + long nDelta = mvCols[ nFirstCol ]->Width(); long nFrozenWidth = GetFrozenWidth(); tools::Rectangle aScrollRect( Point( nFrozenWidth, 0 ), @@ -945,12 +928,12 @@ long BrowseBox::ScrollColumns( long nCols ) { long nWidth = 0; for ( size_t nCol = 0; - nCol < pCols.size() && nCol < nFirstCol; + nCol < mvCols.size() && nCol < nFirstCol; ++nCol ) { // not the handle column - if ( pCols[ nCol ]->GetId() ) - nWidth += pCols[ nCol ]->Width(); + if ( mvCols[ nCol ]->GetId() ) + nWidth += mvCols[ nCol ]->Width(); } pDataWin->pHeaderBar->SetOffset( nWidth ); @@ -1500,7 +1483,7 @@ bool BrowseBox::GoToColumnId( sal_uInt16 nColId, bool bMakeVisible, bool bRowCol if ( nColId != nCurColId || (bMakeVisible && !IsFieldVisible(nCurRow, nColId, true))) { sal_uInt16 nNewPos = GetColumnPos(nColId); - BrowserColumn* pColumn = (nNewPos < pCols.size()) ? pCols[ nNewPos ] : nullptr; + BrowserColumn* pColumn = (nNewPos < mvCols.size()) ? mvCols[ nNewPos ].get() : nullptr; DBG_ASSERT( pColumn, "no column object - invalid id?" ); if ( !pColumn ) return false; @@ -1631,7 +1614,7 @@ void BrowseBox::SelectAll() uRow.pSel->SelectAll(); // don't highlight handle column - BrowserColumn *pFirstCol = pCols[ 0 ]; + BrowserColumn *pFirstCol = mvCols[ 0 ].get(); long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width(); // highlight the row selection @@ -1718,7 +1701,7 @@ void BrowseBox::SelectRow( long nRow, bool _bSelect, bool bExpand ) ) { // don't highlight handle column - BrowserColumn *pFirstCol = pCols[ 0 ]; + BrowserColumn *pFirstCol = mvCols[ 0 ].get(); long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width(); // highlight only newly selected part @@ -1770,12 +1753,12 @@ void BrowseBox::SelectColumnPos( sal_uInt16 nNewColPos, bool _bSelect, bool bMak if ( !bMultiSelection ) { if ( _bSelect ) - GoToColumnId( pCols[ nNewColPos ]->GetId(), bMakeVisible ); + GoToColumnId( mvCols[ nNewColPos ]->GetId(), bMakeVisible ); return; } else { - if ( !GoToColumnId( pCols[ nNewColPos ]->GetId(), bMakeVisible ) ) + if ( !GoToColumnId( mvCols[ nNewColPos ]->GetId(), bMakeVisible ) ) return; } @@ -1789,14 +1772,14 @@ void BrowseBox::SelectColumnPos( sal_uInt16 nNewColPos, bool _bSelect, bool bMak if ( pColSel->Select( nNewColPos, _bSelect ) ) { - // GoToColumnId( pCols->GetObject(nNewColPos)->GetId(), bMakeVisible ); + // GoToColumnId( mvCols->GetObject(nNewColPos)->GetId(), bMakeVisible ); // only highlight painted areas pDataWin->Update(); tools::Rectangle aFieldRectPix( GetFieldRectPixel( nCurRow, nCurColId, false ) ); tools::Rectangle aRect( Point( aFieldRectPix.Left() - MIN_COLUMNWIDTH, 0 ), - Size( pCols[ nNewColPos ]->Width(), + Size( mvCols[ nNewColPos ]->Width(), pDataWin->GetOutputSizePixel().Height() ) ); pDataWin->Invalidate( aRect ); if ( !bSelecting ) @@ -2018,12 +2001,12 @@ tools::Rectangle BrowseBox::ImplFieldRectPixel( long nRow, sal_uInt16 nColumnId sal_uInt16 nFrozenCols = FrozenColCount(); size_t nCol; for ( nCol = 0; - nCol < pCols.size() && pCols[ nCol ]->GetId() != nColumnId; + nCol < mvCols.size() && mvCols[ nCol ]->GetId() != nColumnId; ++nCol ) - if ( pCols[ nCol ]->IsFrozen() || nCol >= nFirstCol ) - nColX += pCols[ nCol ]->Width(); + if ( mvCols[ nCol ]->IsFrozen() || nCol >= nFirstCol ) + nColX += mvCols[ nCol ]->Width(); - if ( nCol >= pCols.size() || ( nCol >= nFrozenCols && nCol < nFirstCol ) ) + if ( nCol >= mvCols.size() || ( nCol >= nFrozenCols && nCol < nFirstCol ) ) return tools::Rectangle(); // compute the Y-coordinate relative to DataWin @@ -2034,8 +2017,8 @@ tools::Rectangle BrowseBox::ImplFieldRectPixel( long nRow, sal_uInt16 nColumnId // assemble the Rectangle relative to DataWin return tools::Rectangle( Point( nColX + MIN_COLUMNWIDTH, nRowY ), - Size( (pCols[nCol]->Width() == LONG_MAX - ? LONG_MAX - (nColX + MIN_COLUMNWIDTH) : pCols[ nCol ]->Width() - 2*MIN_COLUMNWIDTH), + Size( (mvCols[nCol]->Width() == LONG_MAX + ? LONG_MAX - (nColX + MIN_COLUMNWIDTH) : mvCols[ nCol ]->Width() - 2*MIN_COLUMNWIDTH), GetDataRowHeight() - 1 ) ); } @@ -2071,9 +2054,9 @@ sal_uInt16 BrowseBox::GetColumnAtXPosPixel( long nX ) const // accumulate the widths of the visible columns long nColX = 0; - for ( size_t nCol = 0; nCol < pCols.size(); ++nCol ) + for ( size_t nCol = 0; nCol < mvCols.size(); ++nCol ) { - BrowserColumn *pCol = pCols[ nCol ]; + BrowserColumn *pCol = mvCols[ nCol ].get(); if ( pCol->IsFrozen() || nCol >= nFirstCol ) nColX += pCol->Width(); @@ -2132,7 +2115,6 @@ void BrowseBox::SetMode( BrowserMode nMode ) long nOldRowSel = bMultiSelection ? uRow.pSel->FirstSelected() : uRow.nSel; MultiSelection *pOldRowSel = bMultiSelection ? uRow.pSel : nullptr; - MultiSelection *pOldColSel = pColSel; pVScroll.disposeAndClear(); @@ -2188,13 +2170,13 @@ void BrowseBox::SetMode( BrowserMode nMode ) if ( bColumnCursor ) { - pColSel = pOldColSel ? pOldColSel : new MultiSelection; - pColSel->SetTotalRange( Range( 0, pCols.size()-1 ) ); + if (!pColSel) + pColSel.reset(new MultiSelection); + pColSel->SetTotalRange( Range( 0, mvCols.size()-1 ) ); } else { - delete pColSel; - pColSel = nullptr; + pColSel.reset(); } if ( bMultiSelection ) diff --git a/svtools/source/brwbox/brwbox2.cxx b/svtools/source/brwbox/brwbox2.cxx index 89c3babea3c7..0963e067a1da 100644 --- a/svtools/source/brwbox/brwbox2.cxx +++ b/svtools/source/brwbox/brwbox2.cxx @@ -138,7 +138,7 @@ void BrowseBox::StateChanged( StateChangedType nStateChange ) pHeaderBar->SetZoom(GetZoom()); // let the columns calculate their new widths and adjust the header bar - for (BrowserColumn* pCol : pCols) + for (auto & pCol : mvCols) { pCol->ZoomChanged(GetZoom()); if ( pHeaderBar ) @@ -151,7 +151,7 @@ void BrowseBox::StateChanged( StateChangedType nStateChange ) else if (StateChangedType::Enable == nStateChange) { // do we have a handle column? - bool bHandleCol = !pCols.empty() && (0 == pCols[ 0 ]->GetId()); + bool bHandleCol = !mvCols.empty() && (0 == mvCols[ 0 ]->GetId()); // do we have a header bar? bool bHeaderBar = (nullptr != pDataWin->pHeaderBar.get()); @@ -239,7 +239,7 @@ void BrowseBox::ToggleSelection() long nLastRowInRect = 0; // for the CFront // don't highlight handle column - BrowserColumn *pFirstCol = pCols.empty() ? nullptr : pCols[ 0 ]; + BrowserColumn *pFirstCol = mvCols.empty() ? nullptr : mvCols[ 0 ].get(); long nOfsX = (!pFirstCol || pFirstCol->GetId()) ? 0 : pFirstCol->Width(); // accumulate old row selection @@ -277,7 +277,7 @@ void BrowseBox::ToggleSelection() nColId = pColSel->NextSelected() ) { tools::Rectangle aRect( GetFieldRectPixel(nCurRow, - pCols[ nColId ]->GetId(), + mvCols[ nColId ]->GetId(), false ) ); aRect.AdjustLeft( -(MIN_COLUMNWIDTH) ); aRect.AdjustRight(MIN_COLUMNWIDTH ); @@ -325,8 +325,8 @@ void BrowseBox::DrawCursor() } else aCursor = tools::Rectangle( - Point( ( !pCols.empty() && pCols[ 0 ]->GetId() == 0 ) ? - pCols[ 0 ]->Width() : 0, + Point( ( !mvCols.empty() && mvCols[ 0 ]->GetId() == 0 ) ? + mvCols[ 0 ]->Width() : 0, (nCurRow - nTopRow) * GetDataRowHeight() + 1 ), Size( pDataWin->GetOutputSizePixel().Width() + 1, GetDataRowHeight() - 2 ) ); @@ -363,26 +363,25 @@ sal_uLong BrowseBox::GetColumnWidth( sal_uInt16 nId ) const { sal_uInt16 nItemPos = GetColumnPos( nId ); - if ( nItemPos >= pCols.size() ) + if ( nItemPos >= mvCols.size() ) return 0; - return pCols[ nItemPos ]->Width(); + return mvCols[ nItemPos ]->Width(); } sal_uInt16 BrowseBox::GetColumnId( sal_uInt16 nPos ) const { - if ( nPos >= pCols.size() ) + if ( nPos >= mvCols.size() ) return BROWSER_INVALIDID; - return pCols[ nPos ]->GetId(); + return mvCols[ nPos ]->GetId(); } sal_uInt16 BrowseBox::GetColumnPos( sal_uInt16 nId ) const { - - for ( size_t nPos = 0; nPos < pCols.size(); ++nPos ) - if ( pCols[ nPos ]->GetId() == nId ) + for ( size_t nPos = 0; nPos < mvCols.size(); ++nPos ) + if ( mvCols[ nPos ]->GetId() == nId ) return nPos; return BROWSER_INVALIDID; } @@ -390,8 +389,7 @@ sal_uInt16 BrowseBox::GetColumnPos( sal_uInt16 nId ) const bool BrowseBox::IsFrozen( sal_uInt16 nColumnId ) const { - - for (BrowserColumn* pCol : pCols) + for (auto const & pCol : mvCols) if ( pCol->GetId() == nColumnId ) return pCol->IsFrozen(); return false; @@ -466,7 +464,7 @@ void BrowseBox::Resize() { if ( !bBootstrapped && IsReallyVisible() ) BrowseBox::StateChanged( StateChangedType::InitShow ); - if ( pCols.empty() ) + if ( mvCols.empty() ) { pDataWin->bResizeOnPaint = true; return; @@ -488,7 +486,7 @@ void BrowseBox::Resize() // did we need a horizontal scroll bar or is there a Control Area? if ( !pDataWin->bNoHScroll && - ( ( pCols.size() - FrozenColCount() ) > 1 ) ) + ( ( mvCols.size() - FrozenColCount() ) > 1 ) ) aHScroll->Show(); else aHScroll->Hide(); @@ -529,7 +527,7 @@ void BrowseBox::Resize() if ( pHeaderBar ) { // take the handle column into account - BrowserColumn *pFirstCol = pCols[ 0 ]; + BrowserColumn *pFirstCol = mvCols[ 0 ].get(); long nOfsX = pFirstCol->GetId() ? 0 : pFirstCol->Width(); pHeaderBar->SetPosSizePixel( Point( nOfsX, 0 ), Size( GetOutputSizePixel().Width() - nOfsX, GetTitleHeight() ) ); } @@ -545,10 +543,10 @@ void BrowseBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle // initializations if (!bBootstrapped && IsReallyVisible()) BrowseBox::StateChanged(StateChangedType::InitShow); - if (pCols.empty()) + if (mvCols.empty()) return; - BrowserColumn *pFirstCol = pCols[ 0 ]; + BrowserColumn *pFirstCol = mvCols[ 0 ].get(); bool bHandleCol = pFirstCol && pFirstCol->GetId() == 0; bool bHeaderBar = pDataWin->pHeaderBar.get() != nullptr; @@ -581,17 +579,17 @@ void BrowseBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle // iterate through columns to redraw long nX = 0; size_t nCol; - for (nCol = 0; nCol < pCols.size() && nX < rRect.Right(); ++nCol) + for (nCol = 0; nCol < mvCols.size() && nX < rRect.Right(); ++nCol) { // skip invisible columns between frozen and scrollable area - if (nCol < nFirstCol && !pCols[nCol]->IsFrozen()) + if (nCol < nFirstCol && !mvCols[nCol]->IsFrozen()) nCol = nFirstCol; // only the handle column? if (bHeaderBar && bHandleCol && nCol > 0) break; - BrowserColumn* pCol = pCols[nCol]; + BrowserColumn* pCol = mvCols[nCol].get(); // draw the column and increment position if ( pCol->Width() > 4 ) @@ -616,7 +614,7 @@ void BrowseBox::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle } // retouching - if ( !bHeaderBar && nCol == pCols.size() ) + if ( !bHeaderBar && nCol == mvCols.size() ) { const StyleSettings &rSettings = rRenderContext.GetSettings().GetStyleSettings(); Color aColFace(rSettings.GetFaceColor()); @@ -677,9 +675,9 @@ void BrowseBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, // this counts for the column widths, too size_t nPos; - for ( nPos = 0; nPos < pCols.size(); ++nPos ) + for ( nPos = 0; nPos < mvCols.size(); ++nPos ) { - BrowserColumn* pCurrent = pCols[ nPos ]; + BrowserColumn* pCurrent = mvCols[ nPos ].get(); long nWidthLogic = PixelToLogic(Size(pCurrent->Width(), 0), MapMode(MapUnit::Map10thMM)).Width(); long nForeignWidthPixel = pDev->LogicToPixel(Size(nWidthLogic, 0), MapMode(MapUnit::Map10thMM)).Width(); @@ -702,7 +700,7 @@ void BrowseBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, long nTitleHeight = PixelToLogic(Size(0, GetTitleHeight()), MapMode(MapUnit::Map10thMM)).Height(); nTitleHeight = pDev->LogicToPixel(Size(0, nTitleHeight), MapMode(MapUnit::Map10thMM)).Height(); - BrowserColumn* pFirstCol = !pCols.empty() ? pCols[ 0 ] : nullptr; + BrowserColumn* pFirstCol = !mvCols.empty() ? mvCols[ 0 ].get() : nullptr; Point aHeaderPos(pFirstCol && (pFirstCol->GetId() == 0) ? pFirstCol->Width() : 0, 0); Size aHeaderSize(aRealSize.Width() - aHeaderPos.X(), nTitleHeight); @@ -756,9 +754,9 @@ void BrowseBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, // restore the column widths/data row height nDataRowHeight = nOriginalHeight; - for ( nPos = 0; nPos < pCols.size(); ++nPos ) + for ( nPos = 0; nPos < mvCols.size(); ++nPos ) { - BrowserColumn* pCurrent = pCols[ nPos ]; + BrowserColumn* pCurrent = mvCols[ nPos ].get(); long nForeignWidthLogic = pDev->PixelToLogic(Size(pCurrent->Width(), 0), MapMode(MapUnit::Map10thMM)).Width(); long nWidthPixel = LogicToPixel(Size(nForeignWidthLogic, 0), MapMode(MapUnit::Map10thMM)).Width(); @@ -799,7 +797,7 @@ void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRec Color aOldTextColor = _rOut.GetTextColor(); Color aOldFillColor = _rOut.GetFillColor(); Color aOldLineColor = _rOut.GetLineColor(); - long nHLineX = 0 == pCols[ 0 ]->GetId() ? pCols[ 0 ]->Width() : 0; + long nHLineX = 0 == mvCols[ 0 ]->GetId() ? mvCols[ 0 ]->Width() : 0; nHLineX += aOverallAreaPos.X(); Color aDelimiterLineColor( ::svtools::ColorConfig().GetColorValue( ::svtools::CALCGRID ).nColor ); @@ -842,10 +840,10 @@ void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRec // iterate through columns to redraw size_t nCol; - for ( nCol = 0; nCol < pCols.size(); ++nCol ) + for ( nCol = 0; nCol < mvCols.size(); ++nCol ) { // get column - BrowserColumn *pCol = pCols[ nCol ]; + BrowserColumn *pCol = mvCols[ nCol ].get(); // at end of invalid area if ( aPos.X() >= _rRect.Right() ) @@ -855,7 +853,7 @@ void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRec if ( nCol < nFirstCol && !pCol->IsFrozen() ) { nCol = nFirstCol; - pCol = (nCol < pCols.size() ) ? pCols[ nCol ] : nullptr; + pCol = (nCol < mvCols.size() ) ? mvCols[ nCol ].get() : nullptr; if (!pCol) { // FS - 21.05.99 - 66325 // actually this has been fixed elsewhere (in the right place), @@ -957,14 +955,14 @@ void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRec aOldLineColor = _rOut.GetLineColor(); aOldFillColor = _rOut.GetFillColor(); _rOut.SetFillColor( rSettings.GetFaceColor() ); - if ( !pCols.empty() && ( pCols[ 0 ]->GetId() == 0 ) && ( aPos.Y() <= _rRect.Bottom() ) ) + if ( !mvCols.empty() && ( mvCols[ 0 ]->GetId() == 0 ) && ( aPos.Y() <= _rRect.Bottom() ) ) { // fill rectangle gray below handle column // DG: fill it only until the end of the drawing rect and not to the end, as this may overpaint handle columns _rOut.SetLineColor( COL_BLACK ); _rOut.DrawRect( tools::Rectangle( Point( aOverallAreaPos.X() - 1, aPos.Y() - 1 ), - Point( aOverallAreaPos.X() + pCols[ 0 ]->Width() - 1, + Point( aOverallAreaPos.X() + mvCols[ 0 ]->Width() - 1, _rRect.Bottom() + 1) ) ); } _rOut.SetFillColor( aOldFillColor ); @@ -983,16 +981,16 @@ void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRec _rOut.SetLineColor( aDelimiterLineColor ); Point aVertPos( aOverallAreaPos.X() - 1, aOverallAreaPos.Y() ); long nDeltaY = aOverallAreaBRPos.Y(); - for ( size_t nCol = 0; nCol < pCols.size(); ++nCol ) + for ( size_t nCol = 0; nCol < mvCols.size(); ++nCol ) { // get column - BrowserColumn *pCol = pCols[ nCol ]; + BrowserColumn *pCol = mvCols[ nCol ].get(); // skip invisible columns between frozen and scrollable area if ( nCol < nFirstCol && !pCol->IsFrozen() ) { nCol = nFirstCol; - pCol = pCols[ nCol ]; + pCol = mvCols[ nCol ].get(); } // skip column @@ -1022,7 +1020,7 @@ void BrowseBox::PaintData( vcl::Window const & rWin, vcl::RenderContext& rRender BrowseBox::StateChanged(StateChangedType::InitShow); // initializations - if (pCols.empty() || !rWin.IsUpdateMode()) + if (mvCols.empty() || !rWin.IsUpdateMode()) return; if (pDataWin->bResizeOnPaint) Resize(); @@ -1083,7 +1081,7 @@ void BrowseBox::UpdateScrollbars() sal_uInt16 nFrozenCols = FrozenColCount(); bool bNeedsHScroll = pDataWin->bAutoHScroll - ? ( nFirstCol > nFrozenCols ) || ( nLastCol <= pCols.size() ) + ? ( nFirstCol > nFrozenCols ) || ( nLastCol <= mvCols.size() ) : !pDataWin->bNoHScroll; if ( !bNeedsHScroll ) { @@ -1112,11 +1110,11 @@ void BrowseBox::UpdateScrollbars() Size( aDataWinSize.Width() - nHScrX, nCornerSize ) ); // total scrollable columns - short nScrollCols = short(pCols.size()) - static_cast<short>(nFrozenCols); + short nScrollCols = short(mvCols.size()) - static_cast<short>(nFrozenCols); // visible columns short nVisibleHSize = nLastCol == BROWSER_INVALIDID - ? static_cast<short>( pCols.size() - nFirstCol ) + ? static_cast<short>( mvCols.size() - nFirstCol ) : static_cast<short>( nLastCol - nFirstCol ); short nRange = std::max( nScrollCols, short(0) ); @@ -1183,12 +1181,12 @@ void BrowseBox::UpdateScrollbars() { long nWidth = 0; for ( size_t nCol = 0; - nCol < pCols.size() && nCol < nFirstCol; + nCol < mvCols.size() && nCol < nFirstCol; ++nCol ) { // not the handle column - if ( pCols[ nCol ]->GetId() ) - nWidth += pCols[ nCol ]->Width(); + if ( mvCols[ nCol ]->GetId() ) + nWidth += mvCols[ nCol ]->Width(); } pDataWin->pHeaderBar->SetOffset( nWidth ); @@ -1244,16 +1242,15 @@ long BrowseBox::GetFrozenWidth() const long nWidth = 0; for ( size_t nCol = 0; - nCol < pCols.size() && pCols[ nCol ]->IsFrozen(); + nCol < mvCols.size() && mvCols[ nCol ]->IsFrozen(); ++nCol ) - nWidth += pCols[ nCol ]->Width(); + nWidth += mvCols[ nCol ]->Width(); return nWidth; } void BrowseBox::ColumnInserted( sal_uInt16 nPos ) { - if ( pColSel ) pColSel->Insert( nPos ); UpdateScrollbars(); @@ -1262,9 +1259,9 @@ void BrowseBox::ColumnInserted( sal_uInt16 nPos ) sal_uInt16 BrowseBox::FrozenColCount() const { - BrowserColumns::size_type nCol; + std::size_t nCol; for ( nCol = 0; - nCol < pCols.size() && pCols[ nCol ]->IsFrozen(); + nCol < mvCols.size() && mvCols[ nCol ]->IsFrozen(); ++nCol ) /* empty loop */; return nCol; //TODO: BrowserColumns::size_type -> sal_uInt16! @@ -1321,10 +1318,10 @@ void BrowseBox::MouseButtonDown( const MouseEvent& rEvt ) long nX = 0; long nWidth = GetOutputSizePixel().Width(); - for ( size_t nCol = 0; nCol < pCols.size() && nX < nWidth; ++nCol ) + for ( size_t nCol = 0; nCol < mvCols.size() && nX < nWidth; ++nCol ) { // is this column visible? - BrowserColumn *pCol = pCols[ nCol ]; + BrowserColumn *pCol = mvCols[ nCol ].get(); if ( pCol->IsFrozen() || nCol >= nFirstCol ) { // compute right end of column @@ -1371,14 +1368,14 @@ void BrowseBox::MouseMove( const MouseEvent& rEvt ) sal_uInt16 nX = 0; for ( size_t nCol = 0; - nCol < pCols.size() && - ( nX + pCols[ nCol ]->Width() ) < sal_uInt16(GetOutputSizePixel().Width()); + nCol < mvCols.size() && + ( nX + mvCols[ nCol ]->Width() ) < sal_uInt16(GetOutputSizePixel().Width()); ++nCol ) // is this column visible? - if ( pCols[ nCol ]->IsFrozen() || nCol >= nFirstCol ) + if ( mvCols[ nCol ]->IsFrozen() || nCol >= nFirstCol ) { // compute right end of column - BrowserColumn *pCol = pCols[ nCol ]; + BrowserColumn *pCol = mvCols[ nCol ].get(); sal_uInt16 nR = static_cast<sal_uInt16>(nX + pCol->Width() - 1); // show resize-pointer? @@ -1423,7 +1420,7 @@ void BrowseBox::MouseButtonUp( const MouseEvent & rEvt ) // width changed? nDragX = std::max( rEvt.GetPosPixel().X(), nMinResizeX ); - if ( (nDragX - nResizeX) != static_cast<long>(pCols[ nResizeCol ]->Width()) ) + if ( (nDragX - nResizeX) != static_cast<long>(mvCols[ nResizeCol ]->Width()) ) { // resize column long nMaxX = pDataWin->GetSizePixel().Width(); @@ -1469,7 +1466,7 @@ void BrowseBox::MouseButtonDown( const BrowserMouseEvent& rEvt ) { if ( bColumnCursor && rEvt.GetColumn() != 0 ) { - if ( rEvt.GetColumn() < pCols.size() ) + if ( rEvt.GetColumn() < mvCols.size() ) SelectColumnPos( rEvt.GetColumn(), true, false); } } diff --git a/svtools/source/brwbox/datwin.cxx b/svtools/source/brwbox/datwin.cxx index 881396dfa853..7b9101d4584f 100644 --- a/svtools/source/brwbox/datwin.cxx +++ b/svtools/source/brwbox/datwin.cxx @@ -311,26 +311,26 @@ BrowseEvent BrowserDataWin::CreateBrowseEvent( const Point& rPosPixel ) long nColX = 0; size_t nCol; for ( nCol = 0; - nCol < pBox->pCols.size() && nColX < GetSizePixel().Width(); + nCol < pBox->mvCols.size() && nColX < GetSizePixel().Width(); ++nCol ) - if ( pBox->pCols[ nCol ]->IsFrozen() || nCol >= pBox->nFirstCol ) + if ( pBox->mvCols[ nCol ]->IsFrozen() || nCol >= pBox->nFirstCol ) { - nColX += pBox->pCols[ nCol ]->Width(); + nColX += pBox->mvCols[ nCol ]->Width(); if ( nMouseX < nColX ) break; } sal_uInt16 nColId = BROWSER_INVALIDID; - if ( nCol < pBox->pCols.size() ) - nColId = pBox->pCols[ nCol ]->GetId(); + if ( nCol < pBox->mvCols.size() ) + nColId = pBox->mvCols[ nCol ]->GetId(); // compute the field rectangle and field relative MouseEvent tools::Rectangle aFieldRect; - if ( nCol < pBox->pCols.size() ) + if ( nCol < pBox->mvCols.size() ) { - nColX -= pBox->pCols[ nCol ]->Width(); + nColX -= pBox->mvCols[ nCol ]->Width(); aFieldRect = tools::Rectangle( Point( nColX, nRelRow * pBox->GetDataRowHeight() ), - Size( pBox->pCols[ nCol ]->Width(), + Size( pBox->mvCols[ nCol ]->Width(), pBox->GetDataRowHeight() ) ); } |