simplify, its just a vector of colors

Change-Id: I7d388739225d371090872a33d30aa3178b20ca6e
This commit is contained in:
Caolán McNamara 2016-11-04 15:06:55 +00:00
parent df738e0f8c
commit 351a97ce6b
3 changed files with 15 additions and 57 deletions

View File

@ -28,12 +28,7 @@
class ColorLB : public ListBox class ColorLB : public ListBox
{ {
ImpColorList* pColorList; // separate liste, in case of user data are required from outside ImpColorList aColorList; // separate liste, in case of user data are required from outside
Size aImageSize;
using Window::ImplInit;
SVT_DLLPRIVATE void ImplInit();
SVT_DLLPRIVATE void ImplDestroyColorEntries();
public: public:
ColorLB(vcl::Window* pParent, WinBits nWinStyle = WB_BORDER); ColorLB(vcl::Window* pParent, WinBits nWinStyle = WB_BORDER);
@ -76,35 +71,9 @@ VCL_BUILDER_DECL_FACTORY(ColorLB)
rRet = pListBox; rRet = pListBox;
} }
class ImplColorListData
{
public:
Color aColor;
bool bColor;
ImplColorListData() : aColor( COL_BLACK ) { bColor = false; }
explicit ImplColorListData( const Color& rColor ) : aColor( rColor ) { bColor = true; }
};
void ColorLB::ImplInit()
{
pColorList = new ImpColorList();
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
aImageSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
}
void ColorLB::ImplDestroyColorEntries()
{
for ( size_t n = pColorList->size(); n; )
delete (*pColorList)[ --n ];
pColorList->clear();
}
ColorLB::ColorLB( vcl::Window* pParent, WinBits nWinStyle ) : ColorLB::ColorLB( vcl::Window* pParent, WinBits nWinStyle ) :
ListBox( pParent, nWinStyle ) ListBox( pParent, nWinStyle )
{ {
ImplInit();
SetEdgeBlending(true); SetEdgeBlending(true);
} }
@ -115,12 +84,6 @@ ColorLB::~ColorLB()
void ColorLB::dispose() void ColorLB::dispose()
{ {
if ( pColorList )
{
ImplDestroyColorEntries();
delete pColorList;
pColorList = nullptr;
}
ListBox::dispose(); ListBox::dispose();
} }
@ -128,6 +91,7 @@ sal_Int32 ColorLB::InsertEntry( const Color& rColor, const OUString& rStr,
sal_Int32 nPos ) sal_Int32 nPos )
{ {
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Size aImageSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
VclPtr<VirtualDevice> xDevice = VclPtr<VirtualDevice>::Create(); VclPtr<VirtualDevice> xDevice = VclPtr<VirtualDevice>::Create();
xDevice->SetOutputSize(aImageSize); xDevice->SetOutputSize(aImageSize);
@ -140,17 +104,16 @@ sal_Int32 ColorLB::InsertEntry( const Color& rColor, const OUString& rStr,
nPos = ListBox::InsertEntry(rStr, Image(aBitmap), nPos); nPos = ListBox::InsertEntry(rStr, Image(aBitmap), nPos);
if ( nPos != LISTBOX_ERROR ) if ( nPos != LISTBOX_ERROR )
{ {
ImplColorListData* pData = new ImplColorListData( rColor ); if ( static_cast<size_t>(nPos) < aColorList.size() )
if ( static_cast<size_t>(nPos) < pColorList->size() )
{ {
ImpColorList::iterator it = pColorList->begin(); ImpColorList::iterator it = aColorList.begin();
::std::advance( it, nPos ); ::std::advance( it, nPos );
pColorList->insert( it, pData ); aColorList.insert( it, rColor );
} }
else else
{ {
pColorList->push_back( pData ); aColorList.push_back( rColor );
nPos = pColorList->size() - 1; nPos = aColorList.size() - 1;
} }
} }
return nPos; return nPos;
@ -159,28 +122,25 @@ sal_Int32 ColorLB::InsertEntry( const Color& rColor, const OUString& rStr,
void ColorLB::RemoveEntry( sal_Int32 nPos ) void ColorLB::RemoveEntry( sal_Int32 nPos )
{ {
ListBox::RemoveEntry( nPos ); ListBox::RemoveEntry( nPos );
if ( 0 <= nPos && static_cast<size_t>(nPos) < pColorList->size() ) if ( 0 <= nPos && static_cast<size_t>(nPos) < aColorList.size() )
{ {
ImpColorList::iterator it = pColorList->begin(); ImpColorList::iterator it = aColorList.begin();
::std::advance( it, nPos ); std::advance(it, nPos);
delete *it; aColorList.erase(it);
pColorList->erase( it );
} }
} }
void ColorLB::Clear() void ColorLB::Clear()
{ {
ImplDestroyColorEntries(); aColorList.clear();
ListBox::Clear(); ListBox::Clear();
} }
Color ColorLB::GetEntryColor( sal_Int32 nPos ) const Color ColorLB::GetEntryColor( sal_Int32 nPos ) const
{ {
Color aColor; Color aColor;
ImplColorListData* pData = ( 0 <= nPos && static_cast<size_t>(nPos) < pColorList->size() ) ? if (0 <= nPos && static_cast<size_t>(nPos) < aColorList.size())
(*pColorList)[ nPos ] : nullptr; aColor = aColorList[nPos];
if ( pData && pData->bColor )
aColor = pData->aColor;
return aColor; return aColor;
} }

View File

@ -29,11 +29,11 @@
#include "cfgchart.hxx" #include "cfgchart.hxx"
typedef std::vector<Color> ImpColorList;
class ColorLB; class ColorLB;
class SvxDefaultColorOptPage : public SfxTabPage class SvxDefaultColorOptPage : public SfxTabPage
{ {
private: private:
VclPtr<ColorLB> m_pLbChartColors; VclPtr<ColorLB> m_pLbChartColors;
VclPtr<ValueSet> m_pValSetColorBox; VclPtr<ValueSet> m_pValSetColorBox;

View File

@ -33,10 +33,8 @@
#include <o3tl/typed_flags_set.hxx> #include <o3tl/typed_flags_set.hxx>
class FontList; class FontList;
class ImplColorListData;
class ImpLineListData; class ImpLineListData;
typedef ::std::vector< ImplColorListData* > ImpColorList;
typedef ::std::vector< ImpLineListData* > ImpLineList; typedef ::std::vector< ImpLineListData* > ImpLineList;
typedef ::std::vector< FontMetric > ImplFontList; typedef ::std::vector< FontMetric > ImplFontList;