[Libreoffice-commits] core.git: include/svtools svtools/source
Takeshi Abe
tabe at fixedpoint.jp
Tue Dec 26 06:18:00 UTC 2017
include/svtools/ctrlbox.hxx | 5 -
svtools/source/control/ctrlbox.cxx | 98 ++++++++++++++-----------------------
2 files changed, 41 insertions(+), 62 deletions(-)
New commits:
commit c2ae5bc29b7064a599871358e6a4bb7b1dec2b85
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Sun Dec 24 20:46:53 2017 +0900
svtools: Use std::unique_ptr for LineListBox
This also inlines LineListBox::ImplInit(). Note that m_vLineList
never contains nullptr.
Change-Id: Ia4798943fbb53e1720d51faff7643e46d2cd2585
Reviewed-on: https://gerrit.libreoffice.org/47046
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx
index 6e0358721885..b446b7a0503d 100644
--- a/include/svtools/ctrlbox.hxx
+++ b/include/svtools/ctrlbox.hxx
@@ -31,12 +31,12 @@
#include <com/sun/star/table/BorderLineStyle.hpp>
#include <o3tl/typed_flags_set.hxx>
+#include <memory>
class FontList;
class ImpLineListData;
enum class SvxBorderLineStyle : sal_Int16;
-typedef ::std::vector< ImpLineListData* > ImpLineList;
typedef ::std::vector< FontMetric > ImplFontList;
/*************************************************************************
@@ -232,7 +232,6 @@ private:
Color nColor1, Color nColor2, Color nColorDist,
SvxBorderLineStyle nStyle, Bitmap& rBmp );
using Window::ImplInit;
- SVT_DLLPRIVATE void ImplInit();
void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
@@ -247,7 +246,7 @@ private:
LineListBox( const LineListBox& ) = delete;
LineListBox& operator =( const LineListBox& ) = delete;
- ImpLineList* pLineList;
+ std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
long m_nWidth;
OUString m_sNone;
ScopedVclPtr<VirtualDevice> aVirDev;
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index b7b3ceae461a..16c6fdcb7310 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -470,11 +470,16 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
rBmp = aVirDev->GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
}
-void LineListBox::ImplInit()
+LineListBox::LineListBox( vcl::Window* pParent, WinBits nWinStyle ) :
+ ListBox( pParent, nWinStyle ),
+ m_nWidth( 5 ),
+ m_sNone( ),
+ aVirDev( VclPtr<VirtualDevice>::Create() ),
+ aColor( COL_BLACK ),
+ maPaintCol( COL_BLACK )
{
aTxtSize.Width() = GetTextWidth( " " );
aTxtSize.Height() = GetTextHeight();
- pLineList = new ImpLineList;
eSourceUnit = FUNIT_POINT;
aVirDev->SetLineColor();
@@ -483,17 +488,6 @@ void LineListBox::ImplInit()
UpdatePaintLineColor();
}
-LineListBox::LineListBox( vcl::Window* pParent, WinBits nWinStyle ) :
- ListBox( pParent, nWinStyle ),
- m_nWidth( 5 ),
- m_sNone( ),
- aVirDev( VclPtr<VirtualDevice>::Create() ),
- aColor( COL_BLACK ),
- maPaintCol( COL_BLACK )
-{
- ImplInit();
-}
-
extern "C" SAL_DLLPUBLIC_EXPORT void makeLineListBox(VclPtr<vcl::Window> & rRet, VclPtr<vcl::Window> & pParent, VclBuilder::stringmap & rMap)
{
bool bDropdown = BuilderUtils::extractDropdown(rMap);
@@ -513,10 +507,7 @@ LineListBox::~LineListBox()
void LineListBox::dispose()
{
- for (ImpLineListData* p : *pLineList)
- delete p;
- pLineList->clear();
- delete pLineList;
+ m_vLineList.clear();
ListBox::dispose();
}
@@ -528,11 +519,11 @@ sal_Int32 LineListBox::GetStylePos( sal_Int32 nListPos, long nWidth )
sal_Int32 n = 0;
size_t i = 0;
- size_t nCount = pLineList->size();
+ size_t nCount = m_vLineList.size();
while ( nPos == LISTBOX_ENTRY_NOTFOUND && i < nCount )
{
- ImpLineListData* pData = (*pLineList)[ i ];
- if ( pData && pData->GetMinWidth() <= nWidth )
+ auto& pData = m_vLineList[ i ];
+ if ( pData->GetMinWidth() <= nWidth )
{
if ( nListPos == n )
nPos = static_cast<sal_Int32>(i);
@@ -555,26 +546,22 @@ void LineListBox::InsertEntry(
const BorderWidthImpl& rWidthImpl, SvxBorderLineStyle nStyle, long nMinWidth,
ColorFunc pColor1Fn, ColorFunc pColor2Fn, ColorDistFunc pColorDistFn )
{
- ImpLineListData* pData = new ImpLineListData(
- rWidthImpl, nStyle, nMinWidth, pColor1Fn, pColor2Fn, pColorDistFn);
- pLineList->push_back( pData );
+ m_vLineList.emplace_back(new ImpLineListData(
+ rWidthImpl, nStyle, nMinWidth, pColor1Fn, pColor2Fn, pColorDistFn));
}
sal_Int32 LineListBox::GetEntryPos( SvxBorderLineStyle nStyle ) const
{
if(nStyle == SvxBorderLineStyle::NONE && !m_sNone.isEmpty())
return 0;
- for ( size_t i = 0, n = pLineList->size(); i < n; ++i ) {
- ImpLineListData* pData = (*pLineList)[ i ];
- if ( pData )
+ for ( size_t i = 0, n = m_vLineList.size(); i < n; ++i ) {
+ auto& pData = m_vLineList[ i ];
+ if ( pData->GetStyle() == nStyle )
{
- if ( GetEntryStyle( i ) == nStyle )
- {
- size_t nPos = i;
- if (!m_sNone.isEmpty())
- nPos ++;
- return (sal_Int32)nPos;
- }
+ size_t nPos = i;
+ if (!m_sNone.isEmpty())
+ nPos ++;
+ return (sal_Int32)nPos;
}
}
return LISTBOX_ENTRY_NOTFOUND;
@@ -582,7 +569,7 @@ sal_Int32 LineListBox::GetEntryPos( SvxBorderLineStyle nStyle ) const
SvxBorderLineStyle LineListBox::GetEntryStyle( sal_Int32 nPos ) const
{
- ImpLineListData* pData = (0 <= nPos && static_cast<size_t>(nPos) < pLineList->size()) ? (*pLineList)[ nPos ] : nullptr;
+ ImpLineListData* pData = (0 <= nPos && static_cast<size_t>(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr;
return pData ? pData->GetStyle() : SvxBorderLineStyle::NONE;
}
@@ -615,11 +602,11 @@ void LineListBox::UpdateEntries( long nOldWidth )
ListBox::InsertEntry( m_sNone );
sal_uInt16 n = 0;
- sal_uInt16 nCount = pLineList->size( );
+ sal_uInt16 nCount = m_vLineList.size( );
while ( n < nCount )
{
- ImpLineListData* pData = (*pLineList)[ n ];
- if ( pData && pData->GetMinWidth() <= m_nWidth )
+ auto& pData = m_vLineList[ n ];
+ if ( pData->GetMinWidth() <= m_nWidth )
{
Bitmap aBmp;
ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
@@ -644,38 +631,31 @@ void LineListBox::UpdateEntries( long nOldWidth )
Color LineListBox::GetColorLine1( sal_Int32 nPos )
{
- Color rResult = GetPaintColor( );
-
- sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
- ImpLineListData* pData = (*pLineList)[ nStyle ];
- if ( pData )
- rResult = pData->GetColorLine1( GetColor( ) );
-
- return rResult;
+ sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
+ if (nStyle == LISTBOX_ENTRY_NOTFOUND)
+ return GetPaintColor( );
+ auto& pData = m_vLineList[ nStyle ];
+ return pData->GetColorLine1( GetColor( ) );
}
Color LineListBox::GetColorLine2( sal_Int32 nPos )
{
- Color rResult = GetPaintColor( );
-
- sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
- ImpLineListData* pData = (*pLineList)[ nStyle ];
- if ( pData )
- rResult = pData->GetColorLine2( GetColor( ) );
-
- return rResult;
+ sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
+ if (nStyle == LISTBOX_ENTRY_NOTFOUND)
+ return GetPaintColor( );
+ auto& pData = m_vLineList[ nStyle ];
+ return pData->GetColorLine2( GetColor( ) );
}
Color LineListBox::GetColorDist( sal_Int32 nPos )
{
Color rResult = GetSettings().GetStyleSettings().GetFieldColor();
- sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
- ImpLineListData* pData = (*pLineList)[ nStyle ];
- if ( pData )
- rResult = pData->GetColorDist( GetColor( ), rResult );
-
- return rResult;
+ sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
+ if (nStyle == LISTBOX_ENTRY_NOTFOUND)
+ return rResult;
+ auto& pData = m_vLineList[ nStyle ];
+ return pData->GetColorDist( GetColor( ), rResult );
}
void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
More information about the Libreoffice-commits
mailing list