Kaydet (Commit) 69f68677 authored tarafından Michael Stahl's avatar Michael Stahl

SfxBoolItem: cut out the middle man

CntBoolItem adds no value at all.

Change-Id: I41a22fc11cca270e792f2a2f81e3638b54dc1d24
üst 35223e5f
...@@ -117,54 +117,6 @@ inline void CntEnumItem::SetValue(sal_uInt16 nTheValue) ...@@ -117,54 +117,6 @@ inline void CntEnumItem::SetValue(sal_uInt16 nTheValue)
m_nValue = nTheValue; m_nValue = nTheValue;
} }
//============================================================================
DBG_NAMEEX(CntBoolItem)
class SVL_DLLPUBLIC CntBoolItem: public SfxPoolItem
{
sal_Bool m_bValue;
public:
TYPEINFO();
explicit CntBoolItem(sal_uInt16 which = 0, sal_Bool bTheValue = sal_False):
SfxPoolItem(which), m_bValue(bTheValue) {}
CntBoolItem(sal_uInt16 nWhich, SvStream & rStream);
CntBoolItem(const CntBoolItem & rItem):
SfxPoolItem(rItem), m_bValue(rItem.m_bValue) {}
virtual int operator ==(const SfxPoolItem & rItem) const;
using SfxPoolItem::Compare;
virtual int Compare(const SfxPoolItem & rWith) const;
virtual SfxItemPresentation GetPresentation(SfxItemPresentation,
SfxMapUnit, SfxMapUnit,
OUString & rText,
const IntlWrapper * = 0)
const;
virtual bool QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8 = 0) const;
virtual bool PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 = 0);
virtual SfxPoolItem * Create(SvStream & rStream, sal_uInt16) const;
virtual SvStream & Store(SvStream & rStream, sal_uInt16) const;
virtual SfxPoolItem * Clone(SfxItemPool * = 0) const;
virtual sal_uInt16 GetValueCount() const;
virtual OUString GetValueTextByVal(sal_Bool bTheValue) const;
sal_Bool GetValue() const { return m_bValue; }
void SetValue(sal_Bool bTheValue) { m_bValue = bTheValue; }
};
#endif // _SVTOOLS_CENUMITM_HXX #endif // _SVTOOLS_CENUMITM_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifndef _SFXENUMITEM_HXX #ifndef SFXENUMITEM_HXX
#define _SFXENUMITEM_HXX #define SFXENUMITEM_HXX
#include "svl/svldllapi.h" #include "svl/svldllapi.h"
#include <svl/cenumitm.hxx> #include <svl/cenumitm.hxx>
...@@ -39,24 +39,63 @@ public: ...@@ -39,24 +39,63 @@ public:
}; };
//============================================================================ //============================================================================
class SVL_DLLPUBLIC SfxBoolItem: public CntBoolItem
class SVL_DLLPUBLIC SfxBoolItem
: public SfxPoolItem
{ {
bool m_bValue;
public: public:
TYPEINFO(); TYPEINFO();
explicit SfxBoolItem(sal_uInt16 which = 0, sal_Bool bValue = sal_False): explicit SfxBoolItem(sal_uInt16 const nWhich = 0, bool const bValue = false)
CntBoolItem(which, bValue) {} : SfxPoolItem(nWhich)
, m_bValue(bValue)
{ }
SfxBoolItem(SfxBoolItem const& rItem)
: SfxPoolItem(rItem)
, m_bValue(rItem.m_bValue)
{ }
SfxBoolItem(sal_uInt16 nWhich, SvStream & rStream);
bool GetValue() const { return m_bValue; }
void SetValue(bool const bTheValue) { m_bValue = bTheValue; }
// SfxPoolItem
virtual int operator ==(const SfxPoolItem & rItem) const SAL_OVERRIDE;
using SfxPoolItem::Compare;
virtual int Compare(const SfxPoolItem & rWith) const SAL_OVERRIDE;
virtual SfxItemPresentation GetPresentation(SfxItemPresentation,
SfxMapUnit, SfxMapUnit,
OUString & rText,
const IntlWrapper * = 0)
const SAL_OVERRIDE;
virtual bool QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8 = 0)
const SAL_OVERRIDE;
virtual bool PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 = 0)
SAL_OVERRIDE;
SfxBoolItem(sal_uInt16 which, SvStream & rStream):
CntBoolItem(which, rStream) {}
virtual SfxPoolItem * Create(SvStream & rStream, sal_uInt16) const virtual SfxPoolItem * Create(SvStream & rStream, sal_uInt16) const
{ return new SfxBoolItem(Which(), rStream); } SAL_OVERRIDE;
virtual SvStream & Store(SvStream & rStream, sal_uInt16) const SAL_OVERRIDE;
virtual SfxPoolItem * Clone(SfxItemPool * = 0) const SAL_OVERRIDE;
virtual sal_uInt16 GetValueCount() const;
virtual OUString GetValueTextByVal(sal_Bool bTheValue) const;
virtual SfxPoolItem * Clone(SfxItemPool * = 0) const
{ return new SfxBoolItem(*this); }
}; };
#endif // _SFXENUMITEM_HXX #endif // SFXENUMITEM_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Any.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <svl/cenumitm.hxx> #include <svl/cenumitm.hxx>
#include <svl/eitem.hxx>
#include <whassert.hxx> #include <whassert.hxx>
#include <comphelper/extract.hxx> #include <comphelper/extract.hxx>
...@@ -152,38 +153,39 @@ void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue) ...@@ -152,38 +153,39 @@ void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue)
} }
// //
// class CntBoolItem // class SfxBoolItem
// //
DBG_NAME(CntBoolItem) DBG_NAME(SfxBoolItem)
TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem) TYPEINIT1_AUTOFACTORY(SfxBoolItem, SfxPoolItem);
CntBoolItem::CntBoolItem(sal_uInt16 which, SvStream & rStream): SfxBoolItem::SfxBoolItem(sal_uInt16 const nWhich, SvStream & rStream)
SfxPoolItem(which) : SfxPoolItem(nWhich)
{ {
m_bValue = false; sal_Bool tmp = false;
rStream >> m_bValue; rStream >> tmp;
m_bValue = tmp;
} }
// virtual // virtual
int CntBoolItem::operator ==(const SfxPoolItem & rItem) const int SfxBoolItem::operator ==(const SfxPoolItem & rItem) const
{ {
DBG_ASSERT(rItem.ISA(CntBoolItem), DBG_ASSERT(rItem.ISA(SfxBoolItem),
"CntBoolItem::operator ==(): Bad type"); "SfxBoolItem::operator ==(): Bad type");
return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue; return m_bValue == static_cast< SfxBoolItem const * >(&rItem)->m_bValue;
} }
// virtual // virtual
int CntBoolItem::Compare(const SfxPoolItem & rWith) const int SfxBoolItem::Compare(const SfxPoolItem & rWith) const
{ {
DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type"); DBG_ASSERT(rWith.ISA(SfxBoolItem), "SfxBoolItem::Compare(): Bad type");
return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ? return (m_bValue == static_cast<SfxBoolItem const*>(&rWith)->m_bValue) ?
0 : m_bValue ? -1 : 1; 0 : m_bValue ? -1 : 1;
} }
// virtual // virtual
SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation, SfxItemPresentation SfxBoolItem::GetPresentation(SfxItemPresentation,
SfxMapUnit, SfxMapUnit, SfxMapUnit, SfxMapUnit,
OUString & rText, OUString & rText,
const IntlWrapper *) const const IntlWrapper *) const
...@@ -193,14 +195,14 @@ SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation, ...@@ -193,14 +195,14 @@ SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation,
} }
// virtual // virtual
bool CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const bool SfxBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
{ {
rVal <<= sal_Bool(m_bValue); rVal <<= m_bValue;
return true; return true;
} }
// virtual // virtual
bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) bool SfxBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
{ {
sal_Bool bTheValue = sal_Bool(); sal_Bool bTheValue = sal_Bool();
if (rVal >>= bTheValue) if (rVal >>= bTheValue)
...@@ -208,37 +210,37 @@ bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) ...@@ -208,37 +210,37 @@ bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
m_bValue = bTheValue; m_bValue = bTheValue;
return true; return true;
} }
OSL_FAIL("CntBoolItem::PutValue(): Wrong type"); OSL_FAIL("SfxBoolItem::PutValue(): Wrong type");
return false; return false;
} }
// virtual // virtual
SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const SfxPoolItem * SfxBoolItem::Create(SvStream & rStream, sal_uInt16) const
{ {
return new CntBoolItem(Which(), rStream); return new SfxBoolItem(Which(), rStream);
} }
// virtual // virtual
SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const SvStream & SfxBoolItem::Store(SvStream & rStream, sal_uInt16) const
{ {
rStream << m_bValue; rStream << static_cast<sal_Bool>(m_bValue); // not bool for serialization!
return rStream; return rStream;
} }
// virtual // virtual
SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const SfxPoolItem * SfxBoolItem::Clone(SfxItemPool *) const
{ {
return new CntBoolItem(*this); return new SfxBoolItem(*this);
} }
// virtual // virtual
sal_uInt16 CntBoolItem::GetValueCount() const sal_uInt16 SfxBoolItem::GetValueCount() const
{ {
return 2; return 2;
} }
// virtual // virtual
OUString CntBoolItem::GetValueTextByVal(sal_Bool bTheValue) const OUString SfxBoolItem::GetValueTextByVal(sal_Bool bTheValue) const
{ {
return bTheValue ? OUString("TRUE") : OUString("FALSE"); return bTheValue ? OUString("TRUE") : OUString("FALSE");
} }
......
...@@ -24,11 +24,4 @@ ...@@ -24,11 +24,4 @@
TYPEINIT1(SfxEnumItem, CntEnumItem); TYPEINIT1(SfxEnumItem, CntEnumItem);
//
// class SfxBoolItem
//
TYPEINIT1_AUTOFACTORY(SfxBoolItem, CntBoolItem);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment