summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-04-15 14:32:24 +0200
committerMichael Stahl <mstahl@redhat.com>2013-04-16 20:24:41 +0000
commitc6e9926468b1ab7eade9c1afc9e2216dd7c97330 (patch)
tree65c13a0d71b77da40523e95357d353333542fc70 /starmath
parent70b45b2f55174bbdbf254f3efa755ffddb3d2721 (diff)
Convert SmFontPickList from SfxPtrArr to std::vector
- removing SmPickList in the process, since it's only used as a base class for SmFontPickList - and remove dynamic allocation, since we're always making our own copy, just store the data inline in the vector Change-Id: Idedff240456788c473ac49bdaa3f6d27a217e3d6 Reviewed-on: https://gerrit.libreoffice.org/3398 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/utility.hxx104
-rw-r--r--starmath/source/utility.cxx150
2 files changed, 64 insertions, 190 deletions
diff --git a/starmath/inc/utility.hxx b/starmath/inc/utility.hxx
index 0f4a7484f105..01a41cd03d4e 100644
--- a/starmath/inc/utility.hxx
+++ b/starmath/inc/utility.hxx
@@ -19,12 +19,12 @@
#ifndef UTILITY_HXX
#define UTILITY_HXX
-#include <sfx2/minarray.hxx>
#include <vcl/font.hxx>
#include <vcl/fixed.hxx>
#include <vcl/combobox.hxx>
#include <vcl/lstbox.hxx>
#include <tools/fract.hxx>
+#include <deque>
inline long SmPtsTo100th_mm(long nNumPts)
@@ -114,115 +114,39 @@ SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
////////////////////////////////////////////////////////////
//
-// SmPickList
-//
-
-class SmPickList : public SfxPtrArr
-{
-protected:
- sal_uInt16 nSize;
-
- virtual void *CreateItem(const void *pItem) = 0;
- virtual void DestroyItem(void *pItem) = 0;
-
- virtual bool CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0;
-
- virtual OUString GetStringItem(void *pItem) = 0;
-
- void *GetPtr(sal_uInt16 nPos) const { return SfxPtrArr::GetObject(nPos); }
- void *&GetPtr(sal_uInt16 nPos) { return SfxPtrArr::GetObject(nPos); }
- void InsertPtr(sal_uInt16 nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); }
- void RemovePtr(sal_uInt16 nPos, sal_uInt16 nCount = 1) { SfxPtrArr::Remove(nPos, nCount); }
-
-public:
- SmPickList(sal_uInt16 nInitSize = 0, sal_uInt16 nMaxSize = 5);
- virtual ~SmPickList();
-
- SmPickList& operator = (const SmPickList& rList);
-
- void *Get(sal_uInt16 nPos = 0) const { return GetPtr(nPos); }
- using SfxPtrArr::Insert;
- void Insert(const void* pItem);
- void Update(const void* pItem, const void *pNewItem);
- using SfxPtrArr::Remove;
- void Remove(const void* pItem);
-
- using SfxPtrArr::operator [];
- void *operator [] (sal_uInt16 nPos) const { return GetPtr(nPos); }
-
- sal_uInt16 GetSize() const { return nSize; }
- sal_uInt16 Count() const { return SfxPtrArr::Count(); }
-
- void Clear();
-};
-
-
-////////////////////////////////////////////////////////////
-//
// SmFontPickList
//
class SmFontDialog;
-class SmFontPickList : public SmPickList
+class SmFontPickList
{
protected:
- virtual void *CreateItem(const void *pItem);
- virtual void DestroyItem(void *pItem);
+ sal_uInt16 nMaxItems;
+ std::deque<Font> aFontVec;
- virtual bool CompareItem(const void *pFirstItem, const void *pSecondItem) const;
-
- virtual OUString GetStringItem(void *pItem);
+ bool CompareItem(const Font & rFirstFont, const Font & rSecondFont) const;
+ OUString GetStringItem(const Font &rItem);
public:
- SmFontPickList()
- : SmPickList(0, 5) {}
- SmFontPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize)
- : SmPickList(nInitSize, nMaxSize) {}
- SmFontPickList(const SmPickList& rOrig )
- : SmPickList(rOrig) {}
+ SmFontPickList(sal_uInt16 nMax = 5) : nMaxItems(nMax) {}
virtual ~SmFontPickList() { Clear(); }
- using SfxPtrArr::Insert;
virtual void Insert(const Font &rFont);
- using SmPickList::Update;
virtual void Update(const Font &rFont, const Font &rNewFont);
- using SfxPtrArr::Remove;
virtual void Remove(const Font &rFont);
- using SmPickList::Contains;
- inline bool Contains(const Font &rFont) const;
- inline Font Get(sal_uInt16 nPos = 0) const;
+ void Clear();
+ bool Contains(const Font &rFont) const;
+ Font Get(sal_uInt16 nPos = 0) const;
- inline SmFontPickList& operator = (const SmFontPickList& rList);
- using SfxPtrArr::operator [];
- inline Font operator [] (sal_uInt16 nPos) const;
+ SmFontPickList& operator = (const SmFontPickList& rList);
+ Font operator [] (sal_uInt16 nPos) const;
void ReadFrom(const SmFontDialog& rDialog);
void WriteTo(SmFontDialog& rDialog) const;
};
-inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
-{
- *(SmPickList *)this = *(SmPickList *)&rList; return *this;
-}
-
-inline Font SmFontPickList::operator [] (sal_uInt16 nPos) const
-{
- return *((Font *)SmPickList::operator[](nPos));
-}
-
-inline Font SmFontPickList::Get(sal_uInt16 nPos) const
-{
- return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font();
-}
-
-inline bool SmFontPickList::Contains(const Font &rFont) const
-{
- return SmPickList::Contains((void *)&rFont);
-}
-
-
////////////////////////////////////////////////////////////
//
// SmFontPickListBox
@@ -234,15 +158,13 @@ protected:
DECL_LINK(SelectHdl, ListBox *);
public:
- SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax = 4);
+ SmFontPickListBox(Window* pParent, const ResId& rResId);
SmFontPickListBox& operator = (const SmFontPickList& rList);
- using SfxPtrArr::Insert;
virtual void Insert(const Font &rFont);
using Window::Update;
virtual void Update(const Font &rFont, const Font &rNewFont);
- using SfxPtrArr::Remove;
virtual void Remove(const Font &rFont);
};
diff --git a/starmath/source/utility.cxx b/starmath/source/utility.cxx
index cde1b35a4769..1d450ecb0475 100644
--- a/starmath/source/utility.cxx
+++ b/starmath/source/utility.cxx
@@ -50,122 +50,58 @@ SmViewShell * SmGetActiveView()
/**************************************************************************/
-SmPickList::SmPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize) :
- SfxPtrArr((sal_uInt8) nInitSize, 1)
+void SmFontPickList::Clear()
{
- nSize = nMaxSize;
+ aFontVec.clear();
}
-
-SmPickList::~SmPickList()
-{
- Clear();
-}
-
-
-SmPickList& SmPickList::operator=(const SmPickList& rList)
+SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
{
- sal_uInt16 nPos;
-
Clear();
- nSize = rList.nSize;
- for (nPos = 0; nPos < rList.Count(); nPos++)
- InsertPtr(nPos, CreateItem(rList.Get(nPos)));
+ nMaxItems = rList.nMaxItems;
+ for (sal_uInt16 nPos = 0; nPos < rList.aFontVec.size(); nPos++)
+ aFontVec.push_back( rList.aFontVec[nPos] );
return *this;
}
-
-void SmPickList::Insert(const void *pItem)
+Font SmFontPickList::operator [] (sal_uInt16 nPos) const
{
- Remove(pItem);
- InsertPtr(0, CreateItem(pItem));
-
- if (Count() > nSize)
- {
- DestroyItem(GetPtr(nSize));
- RemovePtr(nSize, 1);
- }
+ return aFontVec[nPos];
}
-
-void SmPickList::Update(const void *pItem, const void *pNewItem)
+Font SmFontPickList::Get(sal_uInt16 nPos) const
{
- sal_uInt16 nPos;
-
- for (nPos = 0; nPos < Count(); nPos++)
- if (CompareItem(GetPtr(nPos), pItem))
- {
- DestroyItem(GetPtr(nPos));
- GetPtr(nPos) = CreateItem(pNewItem);
- break;
- }
+ return nPos < aFontVec.size() ? aFontVec[nPos] : Font();
}
-void SmPickList::Remove(const void *pItem)
+bool SmFontPickList::Contains(const Font &rFont) const
{
- sal_uInt16 nPos;
-
- for (nPos = 0; nPos < Count(); nPos++)
- if (CompareItem(GetPtr(nPos), pItem))
- {
- DestroyItem(GetPtr(nPos));
- RemovePtr(nPos, 1);
- break;
- }
-}
-
-void SmPickList::Clear()
-{
- sal_uInt16 nPos;
-
- for (nPos = 0; nPos < Count(); nPos++)
- DestroyItem(GetPtr(nPos));
-
- RemovePtr(0, Count());
+ return std::find( aFontVec.begin(), aFontVec.end(), rFont ) != aFontVec.end();
}
-/**************************************************************************/
-void * SmFontPickList::CreateItem(const void *pItem)
-{
- return new Font(*((Font *) pItem));
-}
-void SmFontPickList::DestroyItem(void *pItem)
+bool SmFontPickList::CompareItem(const Font & rFirstFont, const Font & rSecondFont) const
{
- delete (Font *)pItem;
+ return rFirstFont.GetName() == rSecondFont.GetName() &&
+ rFirstFont.GetFamily() == rSecondFont.GetFamily() &&
+ rFirstFont.GetCharSet() == rSecondFont.GetCharSet() &&
+ rFirstFont.GetWeight() == rSecondFont.GetWeight() &&
+ rFirstFont.GetItalic() == rSecondFont.GetItalic();
}
-bool SmFontPickList::CompareItem(const void *pFirstItem, const void *pSecondItem) const
+OUString SmFontPickList::GetStringItem(const Font &rFont)
{
- Font *pFirstFont, *pSecondFont;
-
- pFirstFont = (Font *)pFirstItem;
- pSecondFont = (Font *)pSecondItem;
-
- if (pFirstFont->GetName() == pSecondFont->GetName())
- if ((pFirstFont->GetFamily() == pSecondFont->GetFamily()) &&
- (pFirstFont->GetCharSet() == pSecondFont->GetCharSet()) &&
- (pFirstFont->GetWeight() == pSecondFont->GetWeight()) &&
- (pFirstFont->GetItalic() == pSecondFont->GetItalic()))
- return (true);
-
- return false;
-}
+ OUStringBuffer aString(rFont.GetName());
-OUString SmFontPickList::GetStringItem(void *pItem)
-{
- Font *pFont = (Font *)pItem;
- OUStringBuffer aString(pFont->GetName());
-
- if (IsItalic( *pFont ))
+ if (IsItalic( rFont ))
{
aString.append(", ");
aString.append(SM_RESSTR(RID_FONTITALIC));
}
- if (IsBold( *pFont ))
+ if (IsBold( rFont ))
{
aString.append(", ");
aString.append(SM_RESSTR(RID_FONTBOLD));
@@ -176,17 +112,33 @@ OUString SmFontPickList::GetStringItem(void *pItem)
void SmFontPickList::Insert(const Font &rFont)
{
- SmPickList::Insert((void *)&rFont);
+ Remove(rFont);
+ aFontVec.push_front( rFont );
+
+ if (aFontVec.size() > nMaxItems)
+ {
+ aFontVec.pop_back();
+ }
}
void SmFontPickList::Update(const Font &rFont, const Font &rNewFont)
{
- SmPickList::Update((void *)&rFont, (void *)&rNewFont);
+ for (sal_uInt16 nPos = 0; nPos < aFontVec.size(); nPos++)
+ if (CompareItem( aFontVec[nPos], rFont ))
+ {
+ aFontVec[nPos] = rNewFont;
+ break;
+ }
}
void SmFontPickList::Remove(const Font &rFont)
{
- SmPickList::Remove((void *)&rFont);
+ for (sal_uInt16 nPos = 0; nPos < aFontVec.size(); nPos++)
+ if (CompareItem( aFontVec[nPos], rFont))
+ {
+ aFontVec.erase( aFontVec.begin() + nPos );
+ break;
+ }
}
@@ -225,8 +177,8 @@ IMPL_LINK( SmFontPickListBox, SelectHdl, ListBox *, /*pListBox*/ )
}
-SmFontPickListBox::SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax) :
- SmFontPickList(nMax, nMax),
+SmFontPickListBox::SmFontPickListBox(Window* pParent, const ResId& rResId) :
+ SmFontPickList(4),
ListBox(pParent, rResId)
{
SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
@@ -239,11 +191,11 @@ SmFontPickListBox& SmFontPickListBox::operator=(const SmFontPickList& rList)
*(SmFontPickList *)this = rList;
- for (nPos = 0; nPos < Count(); nPos++)
- InsertEntry(GetStringItem(GetPtr(nPos)), nPos);
+ for (nPos = 0; nPos < aFontVec.size(); nPos++)
+ InsertEntry(GetStringItem(aFontVec[nPos]), nPos);
- if (Count() > 0)
- SelectEntry(GetStringItem(GetPtr(0)));
+ if (aFontVec.size() > 0)
+ SelectEntry(GetStringItem(aFontVec.front()));
return *this;
}
@@ -252,11 +204,11 @@ void SmFontPickListBox::Insert(const Font &rFont)
{
SmFontPickList::Insert(rFont);
- RemoveEntry(GetStringItem(GetPtr(0)));
- InsertEntry(GetStringItem(GetPtr(0)), 0);
- SelectEntry(GetStringItem(GetPtr(0)));
+ RemoveEntry(GetStringItem(aFontVec.front()));
+ InsertEntry(GetStringItem(aFontVec.front()), 0);
+ SelectEntry(GetStringItem(aFontVec.front()));
- while (GetEntryCount() > nSize)
+ while (GetEntryCount() > nMaxItems)
RemoveEntry(GetEntryCount() - 1);
return;