[Libreoffice-commits] core.git: svtools/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Dec 11 06:33:29 UTC 2018
svtools/source/contnr/imivctl.hxx | 52 +---------------
svtools/source/contnr/imivctl1.cxx | 114 ++++++++++++++-----------------------
svtools/source/contnr/imivctl2.cxx | 20 +++---
svtools/source/contnr/ivctrl.cxx | 2
4 files changed, 61 insertions(+), 127 deletions(-)
New commits:
commit 99111155770183ce3239dc2a074a8aa344233cab
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Dec 10 14:13:24 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Dec 11 07:33:08 2018 +0100
loplugin:useuniqueptr in SvxIconChoiceCtrl_Impl
Change-Id: I5bd4fb6b4942cea02168a8a92682fa215deae8cf
Reviewed-on: https://gerrit.libreoffice.org/64878
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/svtools/source/contnr/imivctl.hxx b/svtools/source/contnr/imivctl.hxx
index b02ab4539b07..b0a8530787bd 100644
--- a/svtools/source/contnr/imivctl.hxx
+++ b/svtools/source/contnr/imivctl.hxx
@@ -97,45 +97,6 @@ struct LocalFocus
};
-// Entry-List
-
-class EntryList_Impl
-{
-private:
- std::vector< SvxIconChoiceCtrlEntry* > maIconChoiceCtrlEntryList;
- SvxIconChoiceCtrl_Impl* _pOwner;
-
-public:
- explicit EntryList_Impl( SvxIconChoiceCtrl_Impl* );
- ~EntryList_Impl();
-
- void clear();
-
- size_t size()
- {
- return maIconChoiceCtrlEntryList.size();
- }
- size_t size() const
- {
- return maIconChoiceCtrlEntryList.size();
- }
-
- SvxIconChoiceCtrlEntry* operator[]( size_t nPos )
- {
- return ( nPos < maIconChoiceCtrlEntryList.size() )
- ? maIconChoiceCtrlEntryList[ nPos ]
- : nullptr;
- }
- SvxIconChoiceCtrlEntry* operator[]( size_t nPos ) const
- {
- return ( nPos < maIconChoiceCtrlEntryList.size() )
- ? maIconChoiceCtrlEntryList[ nPos ]
- : nullptr;
- }
- void insert( size_t nPos, SvxIconChoiceCtrlEntry* pEntry );
-};
-
-
// Implementation-class of IconChoiceCtrl
@@ -145,11 +106,10 @@ typedef std::vector<SvxIconChoiceCtrlEntry*> SvxIconChoiceCtrlEntryPtrVec;
class SvxIconChoiceCtrl_Impl
{
friend class IcnCursor_Impl;
- friend class EntryList_Impl;
friend class IcnGridMap_Impl;
bool bChooseWithCursor;
- EntryList_Impl aEntries;
+ std::vector< std::unique_ptr<SvxIconChoiceCtrlEntry> > maEntries;
VclPtr<ScrollBar> aVerSBar;
VclPtr<ScrollBar> aHorSBar;
VclPtr<ScrollBarBox> aScrBarBox;
@@ -177,7 +137,7 @@ class SvxIconChoiceCtrl_Impl
ImplSVEvent * nUserEventAdjustScrBars;
SvxIconChoiceCtrlEntry* pCurHighlightFrame;
bool bHighlightFramePressed;
- SvxIconChoiceCtrlEntry* pHead; // top left entry
+ SvxIconChoiceCtrlEntry* pHead = nullptr; // top left entry
SvxIconChoiceCtrlEntry* pCursor;
SvxIconChoiceCtrlEntry* pHdlEntry;
VclPtr<VirtualDevice> pDDDev;
@@ -302,7 +262,7 @@ public:
void Clear( bool bInCtor );
void SetStyle( WinBits nWinStyle );
WinBits GetStyle() const { return nWinBits; }
- void InsertEntry( SvxIconChoiceCtrlEntry*, size_t nPos );
+ void InsertEntry( std::unique_ptr<SvxIconChoiceCtrlEntry>, size_t nPos );
void CreateAutoMnemonics( MnemonicGenerator* _pGenerator );
void FontModified();
void SelectAll();
@@ -421,14 +381,14 @@ public:
SvxIconChoiceCtrlEntry* pEntry
);
#endif
- size_t GetEntryCount() const { return aEntries.size(); }
+ size_t GetEntryCount() const { return maEntries.size(); }
SvxIconChoiceCtrlEntry* GetEntry( size_t nPos )
{
- return aEntries[ nPos ];
+ return maEntries[ nPos ].get();
}
SvxIconChoiceCtrlEntry* GetEntry( size_t nPos ) const
{
- return aEntries[ nPos ];
+ return maEntries[ nPos ].get();
}
SvxIconChoiceCtrlEntry* GetFirstSelectedEntry() const;
void SetSelectionMode( SelectionMode eMode ) { eSelectionMode=eMode; }
diff --git a/svtools/source/contnr/imivctl1.cxx b/svtools/source/contnr/imivctl1.cxx
index ca8f3a124611..8c867d5d2904 100644
--- a/svtools/source/contnr/imivctl1.cxx
+++ b/svtools/source/contnr/imivctl1.cxx
@@ -56,7 +56,6 @@ SvxIconChoiceCtrl_Impl::SvxIconChoiceCtrl_Impl(
SvtIconChoiceCtrl* pCurView,
WinBits nWinStyle
) :
- aEntries( this ),
aVerSBar( VclPtr<ScrollBar>::Create(pCurView, WB_DRAG | WB_VSCROLL) ),
aHorSBar( VclPtr<ScrollBar>::Create(pCurView, WB_DRAG | WB_HSCROLL) ),
aScrBarBox( VclPtr<ScrollBarBox>::Create(pCurView) ),
@@ -167,13 +166,7 @@ void SvxIconChoiceCtrl_Impl::Clear( bool bInCtor )
pView->Invalidate(InvalidateFlags::NoChildren);
}
AdjustScrollBars();
- size_t nCount = aEntries.size();
- for( size_t nCur = 0; nCur < nCount; nCur++ )
- {
- SvxIconChoiceCtrlEntry* pCur = aEntries[ nCur ];
- delete pCur;
- }
- aEntries.clear();
+ maEntries.clear();
DocRectChanged();
VisRectChanged();
}
@@ -220,11 +213,21 @@ void SvxIconChoiceCtrl_Impl::FontModified()
ShowCursor( true );
}
-void SvxIconChoiceCtrl_Impl::InsertEntry( SvxIconChoiceCtrlEntry* pEntry, size_t nPos)
+void SvxIconChoiceCtrl_Impl::InsertEntry( std::unique_ptr<SvxIconChoiceCtrlEntry> pEntry1, size_t nPos)
{
- aEntries.insert( nPos, pEntry );
- if( (nFlags & IconChoiceFlags::EntryListPosValid) && nPos >= aEntries.size() - 1 )
- pEntry->nPos = aEntries.size() - 1;
+ auto pEntry = pEntry1.get();
+
+ if ( nPos < maEntries.size() ) {
+ maEntries.insert( maEntries.begin() + nPos, std::move(pEntry1) );
+ } else {
+ maEntries.push_back( std::move(pEntry1) );
+ }
+
+ if( pHead )
+ pEntry->SetBacklink( pHead->pblink );
+
+ if( (nFlags & IconChoiceFlags::EntryListPosValid) && nPos >= maEntries.size() - 1 )
+ pEntry->nPos = maEntries.size() - 1;
else
nFlags &= ~IconChoiceFlags::EntryListPosValid;
@@ -292,11 +295,10 @@ void SvxIconChoiceCtrl_Impl::SetListPositions()
if( nFlags & IconChoiceFlags::EntryListPosValid )
return;
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
- pEntry->nPos = nCur;
+ maEntries[ nCur ]->nPos = nCur;
}
nFlags |= IconChoiceFlags::EntryListPosValid;
}
@@ -373,10 +375,10 @@ void SvxIconChoiceCtrl_Impl::ResetVirtSize()
{
aVirtOutputSize.setWidth( 0 );
aVirtOutputSize.setHeight( 0 );
- const size_t nCount = aEntries.size();
+ const size_t nCount = maEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pCur = aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pCur = maEntries[ nCur ].get();
pCur->ClearFlags( SvxIconViewFlags::POS_MOVED );
if( pCur->IsPosLocked() )
{
@@ -445,24 +447,24 @@ void SvxIconChoiceCtrl_Impl::AdjustVirtSize( const tools::Rectangle& rRect )
void SvxIconChoiceCtrl_Impl::InitPredecessors()
{
DBG_ASSERT(!pHead,"SvxIconChoiceCtrl_Impl::InitPredecessors() >> Already initialized");
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
if( nCount )
{
- SvxIconChoiceCtrlEntry* pPrev = aEntries[ 0 ];
+ SvxIconChoiceCtrlEntry* pPrev = maEntries[ 0 ].get();
for( size_t nCur = 1; nCur <= nCount; nCur++ )
{
pPrev->ClearFlags( SvxIconViewFlags::POS_LOCKED | SvxIconViewFlags::POS_MOVED );
SvxIconChoiceCtrlEntry* pNext;
if( nCur == nCount )
- pNext = aEntries[ 0 ];
+ pNext = maEntries[ 0 ].get();
else
- pNext = aEntries[ nCur ];
+ pNext = maEntries[ nCur ].get();
pPrev->pflink = pNext;
pNext->pblink = pPrev;
pPrev = pNext;
}
- pHead = aEntries[ 0 ];
+ pHead = maEntries[ 0 ].get();
}
else
pHead = nullptr;
@@ -472,10 +474,10 @@ void SvxIconChoiceCtrl_Impl::ClearPredecessors()
{
if( pHead )
{
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pCur = aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pCur = maEntries[ nCur ].get();
pCur->pflink = nullptr;
pCur->pblink = nullptr;
}
@@ -572,7 +574,7 @@ void SvxIconChoiceCtrl_Impl::Paint(vcl::RenderContext& rRenderContext, const too
rRenderContext.SetLineColor(aOldColor);
#endif
- if (!aEntries.size())
+ if (!maEntries.size())
return;
if (!pCursor)
{
@@ -589,7 +591,7 @@ void SvxIconChoiceCtrl_Impl::Paint(vcl::RenderContext& rRenderContext, const too
}
if (!bfound)
- pCursor = aEntries[ 0 ];
+ pCursor = maEntries[ 0 ].get();
}
size_t nCount = maZOrderList.size();
@@ -1089,7 +1091,7 @@ bool SvxIconChoiceCtrl_Impl::KeyInput( const KeyEvent& rKEvt )
case KEY_END:
if( pCursor )
{
- pNewCursor = aEntries[ aEntries.size() - 1 ];
+ pNewCursor = maEntries.back().get();
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift );
}
break;
@@ -1097,7 +1099,7 @@ bool SvxIconChoiceCtrl_Impl::KeyInput( const KeyEvent& rKEvt )
case KEY_HOME:
if( pCursor )
{
- pNewCursor = aEntries[ 0 ];
+ pNewCursor = maEntries[ 0 ].get();
SetCursor_Impl( pOldCursor, pNewCursor, bMod1, bShift );
}
break;
@@ -1789,13 +1791,13 @@ void SvxIconChoiceCtrl_Impl::RecalcAllBoundingRectsSmart()
maZOrderList.clear();
size_t nCur;
SvxIconChoiceCtrlEntry* pEntry;
- const size_t nCount = aEntries.size();
+ const size_t nCount = maEntries.size();
if( !IsAutoArrange() || !pHead )
{
for( nCur = 0; nCur < nCount; nCur++ )
{
- pEntry = aEntries[ nCur ];
+ pEntry = maEntries[ nCur ].get();
if( IsBoundingRectValid( pEntry->aRect ))
{
Size aBoundSize( pEntry->aRect.GetSize() );
@@ -2141,10 +2143,10 @@ void SvxIconChoiceCtrl_Impl::DeselectAllBut( SvxIconChoiceCtrlEntry const * pThi
// TODO: work through z-order list, if necessary!
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pEntry = maEntries[ nCur ].get();
if( pEntry != pThisEntryNot && pEntry->IsSelected() )
SelectEntry( pEntry, false, true );
}
@@ -2650,12 +2652,12 @@ SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::GetFirstSelectedEntry() const
return pCurHighlightFrame;
}
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
if( !pHead )
{
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pEntry = maEntries[ nCur ].get();
if( pEntry->IsSelected() )
{
return pEntry;
@@ -2684,10 +2686,10 @@ SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::GetFirstSelectedEntry() const
void SvxIconChoiceCtrl_Impl::SelectAll()
{
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pEntry = maEntries[ nCur ].get();
SelectEntry( pEntry, true/*bSelect*/, true );
}
nFlags &= ~IconChoiceFlags::AddMode;
@@ -2740,34 +2742,6 @@ void SvxIconChoiceCtrl_Impl::InitSettings()
AdjustScrollBars();
}
-EntryList_Impl::EntryList_Impl( SvxIconChoiceCtrl_Impl* pOwner ) :
- _pOwner( pOwner )
-{
- _pOwner->pHead = nullptr;
-}
-
-EntryList_Impl::~EntryList_Impl()
-{
- _pOwner->pHead = nullptr;
-}
-
-void EntryList_Impl::clear()
-{
- _pOwner->pHead = nullptr;
- maIconChoiceCtrlEntryList.clear();
-}
-
-void EntryList_Impl::insert( size_t nPos, SvxIconChoiceCtrlEntry* pEntry )
-{
- if ( nPos < maIconChoiceCtrlEntryList.size() ) {
- maIconChoiceCtrlEntryList.insert( maIconChoiceCtrlEntryList.begin() + nPos, pEntry );
- } else {
- maIconChoiceCtrlEntryList.push_back( pEntry );
- }
- if( _pOwner->pHead )
- pEntry->SetBacklink( _pOwner->pHead->pblink );
-}
-
void SvxIconChoiceCtrl_Impl::SetPositionMode( SvxIconChoiceCtrlPositionMode eMode )
{
if( eMode == ePositionMode )
@@ -2775,14 +2749,14 @@ void SvxIconChoiceCtrl_Impl::SetPositionMode( SvxIconChoiceCtrlPositionMode eMod
SvxIconChoiceCtrlPositionMode eOldMode = ePositionMode;
ePositionMode = eMode;
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
if( eOldMode == SvxIconChoiceCtrlPositionMode::AutoArrange )
{
// when positioning moved entries "hard", there are problems with
// unwanted overlaps, as these entries aren't taken into account in
// Arrange.
- if( aEntries.size() )
+ if( maEntries.size() )
aAutoArrangeIdle.Start();
return;
}
@@ -2791,12 +2765,12 @@ void SvxIconChoiceCtrl_Impl::SetPositionMode( SvxIconChoiceCtrlPositionMode eMod
{
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pEntry = aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pEntry = maEntries[ nCur ].get();
if( pEntry->GetFlags() & SvxIconViewFlags(SvxIconViewFlags::POS_LOCKED | SvxIconViewFlags::POS_MOVED))
SetEntryPos(pEntry, GetEntryBoundRect( pEntry ).TopLeft());
}
- if( aEntries.size() )
+ if( maEntries.size() )
aAutoArrangeIdle.Start();
}
}
@@ -2857,13 +2831,13 @@ SvxIconChoiceCtrlEntry* SvxIconChoiceCtrl_Impl::FindEntryPredecessor( SvxIconCho
tools::Rectangle aCenterRect( CalcBmpRect( pEntry, &aPos ));
Point aNewPos( aCenterRect.Center() );
sal_uLong nGrid = GetPredecessorGrid( aNewPos );
- size_t nCount = aEntries.size();
+ size_t nCount = maEntries.size();
if( nGrid == ULONG_MAX )
return nullptr;
if( nGrid >= nCount )
nGrid = nCount - 1;
if( !pHead )
- return aEntries[ nGrid ];
+ return maEntries[ nGrid ].get();
SvxIconChoiceCtrlEntry* pCur = pHead; // Grid 0
// TODO: go through list from the end if nGrid > nCount/2
diff --git a/svtools/source/contnr/imivctl2.cxx b/svtools/source/contnr/imivctl2.cxx
index 1a452e9e5cee..57135065a120 100644
--- a/svtools/source/contnr/imivctl2.cxx
+++ b/svtools/source/contnr/imivctl2.cxx
@@ -70,10 +70,10 @@ void IcnCursor_Impl::ImplCreate()
xColumns.reset(new IconChoiceMap);
xRows.reset(new IconChoiceMap);
- size_t nCount = pView->aEntries.size();
+ size_t nCount = pView->maEntries.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
- SvxIconChoiceCtrlEntry* pEntry = pView->aEntries[ nCur ];
+ SvxIconChoiceCtrlEntry* pEntry = pView->maEntries[ nCur ].get();
// const Rectangle& rRect = pView->GetEntryBoundRect( pEntry );
tools::Rectangle rRect( pView->CalcBmpRect( pEntry ) );
short nY = static_cast<short>( ((rRect.Top()+rRect.Bottom())/2) / nDeltaHeight );
@@ -341,8 +341,8 @@ SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoPageUpDown( SvxIconChoiceCtrlEntry* pS
if( bDown )
{
nNewPos += nEntriesInView;
- if( nNewPos >= static_cast<long>(pView->aEntries.size()) )
- nNewPos = pView->aEntries.size() - 1;
+ if( nNewPos >= static_cast<long>(pView->maEntries.size()) )
+ nNewPos = pView->maEntries.size() - 1;
}
else
{
@@ -351,7 +351,7 @@ SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoPageUpDown( SvxIconChoiceCtrlEntry* pS
nNewPos = 0;
}
if( nPos != nNewPos )
- return pView->aEntries[ static_cast<size_t>(nNewPos) ];
+ return pView->maEntries[ static_cast<size_t>(nNewPos) ].get();
return nullptr;
}
long nOpt = pView->GetEntryBoundRect( pStart ).Top();
@@ -394,10 +394,10 @@ SvxIconChoiceCtrlEntry* IcnCursor_Impl::GoUpDown( SvxIconChoiceCtrlEntry* pCtrlE
if( pView->IsAutoArrange() && !(pView->nWinBits & WB_ALIGN_TOP) )
{
sal_uLong nPos = pView->GetEntryListPos( pCtrlEntry );
- if( bDown && nPos < (pView->aEntries.size() - 1) )
- return pView->aEntries[ nPos + 1 ];
+ if( bDown && nPos < (pView->maEntries.size() - 1) )
+ return pView->maEntries[ nPos + 1 ].get();
else if( !bDown && nPos > 0 )
- return pView->aEntries[ nPos - 1 ];
+ return pView->maEntries[ nPos - 1 ].get();
return nullptr;
}
@@ -524,9 +524,9 @@ void IcnGridMap_Impl::Create_Impl()
_pGridMap.reset( new bool[nCellCount] );
memset(_pGridMap.get(), 0, nCellCount * sizeof(bool));
- const size_t nCount = _pView->aEntries.size();
+ const size_t nCount = _pView->maEntries.size();
for( size_t nCur=0; nCur < nCount; nCur++ )
- OccupyGrids( _pView->aEntries[ nCur ] );
+ OccupyGrids( _pView->maEntries[ nCur ].get() );
}
void IcnGridMap_Impl::GetMinMapSize( sal_uInt16& rDX, sal_uInt16& rDY ) const
diff --git a/svtools/source/contnr/ivctrl.cxx b/svtools/source/contnr/ivctrl.cxx
index 64f03e372d4e..82d027d2fdf7 100644
--- a/svtools/source/contnr/ivctrl.cxx
+++ b/svtools/source/contnr/ivctrl.cxx
@@ -98,7 +98,7 @@ SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const OUString& rText, c
{
SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage);
- _pImpl->InsertEntry(pEntry, _pImpl->GetEntryCount());
+ _pImpl->InsertEntry(std::unique_ptr<SvxIconChoiceCtrlEntry>(pEntry), _pImpl->GetEntryCount());
return pEntry;
}
More information about the Libreoffice-commits
mailing list