diff options
Diffstat (limited to 'svl/source/items')
45 files changed, 16177 insertions, 0 deletions
diff --git a/svl/source/items/aeitem.cxx b/svl/source/items/aeitem.cxx new file mode 100644 index 000000000000..63fbd1db6227 --- /dev/null +++ b/svl/source/items/aeitem.cxx @@ -0,0 +1,317 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: aeitem.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#ifndef GCC +#endif + +#include <tools/string.hxx> + +#define _SVSTDARR_USHORTS +#include <svtools/svstdarr.hxx> +#include <svtools/svarray.hxx> +#include <svtools/aeitem.hxx> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxAllEnumItem) + +TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem) + +// ----------------------------------------------------------------------- + +struct SfxAllEnumValue_Impl +{ + USHORT nValue; + XubString aText; +}; + +SV_DECL_PTRARR_DEL(SfxAllEnumValueArr, SfxAllEnumValue_Impl*, 0, 8) +SV_IMPL_PTRARR(SfxAllEnumValueArr, SfxAllEnumValue_Impl*) + +// ----------------------------------------------------------------------- + +SfxAllEnumItem::SfxAllEnumItem() : + SfxEnumItem(), + pValues( 0 ), + pDisabledValues( 0 ) +{ +} + +SfxAllEnumItem::SfxAllEnumItem( USHORT which, USHORT nVal, const XubString &rText ): + SfxEnumItem(which, nVal), + pValues( 0 ), + pDisabledValues( 0 ) +{ + DBG_CTOR(SfxAllEnumItem, 0); + InsertValue( nVal, rText ); +} + +// ----------------------------------------------------------------------- + +SfxAllEnumItem::SfxAllEnumItem(USHORT which, USHORT nVal): + SfxEnumItem(which, nVal), + pValues( 0 ), + pDisabledValues( 0 ) +{ + DBG_CTOR(SfxAllEnumItem, 0); + InsertValue( nVal ); +} + +// ----------------------------------------------------------------------- + +SfxAllEnumItem::SfxAllEnumItem( USHORT which, SvStream &rStream ): + SfxEnumItem(which, rStream), + pValues( 0 ), + pDisabledValues( 0 ) +{ + DBG_CTOR(SfxAllEnumItem, 0); + InsertValue( GetValue() ); +} + +// ----------------------------------------------------------------------- + + +SfxAllEnumItem::SfxAllEnumItem(USHORT which): + SfxEnumItem(which, 0), + pValues( 0 ), + pDisabledValues( 0 ) +{ + DBG_CTOR(SfxAllEnumItem, 0); +} + + +// ----------------------------------------------------------------------- + +SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy): + SfxEnumItem(rCopy), + pValues(0), + pDisabledValues( 0 ) +{ + DBG_CTOR(SfxAllEnumItem, 0); + if ( !rCopy.pValues ) + return; + + pValues = new SfxAllEnumValueArr; + + for ( USHORT nPos = 0; nPos < rCopy.pValues->Count(); ++nPos ) + { + SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; + pVal->nValue = rCopy.pValues->GetObject(nPos)->nValue; + pVal->aText = rCopy.pValues->GetObject(nPos)->aText; + const SfxAllEnumValue_Impl *pTemp = pVal; + pValues->Insert( pTemp, nPos ); + } + + if( rCopy.pDisabledValues ) + { + pDisabledValues = new SvUShorts; + for ( USHORT nPos = 0; nPos < rCopy.pDisabledValues->Count(); ++nPos ) + { + pDisabledValues->Insert( rCopy.pDisabledValues->GetObject(nPos), + nPos ); + } + } +} + +// ----------------------------------------------------------------------- + +SfxAllEnumItem::~SfxAllEnumItem() +{ + DBG_DTOR(SfxAllEnumItem, 0); + delete pValues; + delete pDisabledValues; +} + +// ----------------------------------------------------------------------- + +USHORT SfxAllEnumItem::GetValueCount() const +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + return pValues ? pValues->Count() : 0; +} + +// ----------------------------------------------------------------------- + +XubString SfxAllEnumItem::GetValueTextByPos( USHORT nPos ) const +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" ); + return pValues->GetObject(nPos)->aText; +} + +// ----------------------------------------------------------------------- + +USHORT SfxAllEnumItem::GetValueByPos( USHORT nPos ) const +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" ); + return pValues->GetObject(nPos)->nValue; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + return new SfxAllEnumItem(*this); +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxAllEnumItem::Create( SvStream & rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + return new SfxAllEnumItem( Which(), rStream ); +} + + +// ----------------------------------------------------------------------- + +USHORT SfxAllEnumItem::_GetPosByValue( USHORT nVal ) const + +/* [Beschreibung] + + Im Ggs. zu <SfxEnumItemInterface::GetPosByValue(USHORT)const> liefert + diese interne Methode bei nicht vorhandenen Values die Position, + an der der Wert liegen w"urde. +*/ + +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + + if ( !pValues ) + return 0; + + //!O: binaere Suche oder SortArray verwenden + USHORT nPos; + for ( nPos = 0; nPos < pValues->Count(); ++nPos ) + if ( pValues->GetObject(nPos)->nValue >= nVal ) + return nPos; + return nPos; +} + +// ----------------------------------------------------------------------- + +USHORT SfxAllEnumItem::GetPosByValue( USHORT nValue ) const + +/* [Beschreibung] + + Liefert im Gegensatz zu <SfxEnumItemInterface::GetPosByValue(USHORT)const> + immer nValue zur"uck, solange nicht mindestens ein Wert mit einer der + Methoden <SfxAllEnumItem::InsertValue()> eingef"ugt wurde. +*/ + +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + + if ( !pValues || !pValues->Count() ) + return nValue; + + return SfxEnumItem::GetPosByValue( nValue ); +} + +// ----------------------------------------------------------------------- + +void SfxAllEnumItem::InsertValue( USHORT nValue, const XubString &rValue ) +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; + pVal->nValue = nValue; + pVal->aText = rValue; + const SfxAllEnumValue_Impl *pTemp = pVal; + if ( !pValues ) + pValues = new SfxAllEnumValueArr; + else if ( GetPosByValue( nValue ) != USHRT_MAX ) + // remove when exists + RemoveValue( nValue ); + // then insert + pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?! +} + +// ----------------------------------------------------------------------- + +void SfxAllEnumItem::InsertValue( USHORT nValue ) +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; + pVal->nValue = nValue; + pVal->aText = XubString::CreateFromInt32( nValue ); + const SfxAllEnumValue_Impl *pTemp = pVal; + if ( !pValues ) + pValues = new SfxAllEnumValueArr; + + pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?! +} + +void SfxAllEnumItem::DisableValue( USHORT nValue ) +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + if ( !pDisabledValues ) + pDisabledValues = new SvUShorts; + + pDisabledValues->Insert( nValue, pDisabledValues->Count() ); +} + +BOOL SfxAllEnumItem::IsEnabled( USHORT nValue ) const +{ + if ( pDisabledValues ) + { + for ( USHORT i=0; i<pDisabledValues->Count(); i++ ) + if ( (*pDisabledValues)[i] == nValue ) + return FALSE; + } + + return TRUE; +} + +// ----------------------------------------------------------------------- + +void SfxAllEnumItem::RemoveValue( USHORT nValue ) +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + USHORT nPos = GetPosByValue(nValue); + DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" ); + pValues->Remove( nPos ); +} + +// ----------------------------------------------------------------------- + + +void SfxAllEnumItem::RemoveAllValues() +{ + DBG_CHKTHIS(SfxAllEnumItem, 0); + if ( pValues ) + pValues->DeleteAndDestroy( 0, pValues->Count() ); +} + + + diff --git a/svl/source/items/bintitem.cxx b/svl/source/items/bintitem.cxx new file mode 100644 index 000000000000..a3b6c1c2b54d --- /dev/null +++ b/svl/source/items/bintitem.cxx @@ -0,0 +1,169 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: bintitem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <tools/stream.hxx> +#include <tools/bigint.hxx> +#include <svtools/bintitem.hxx> + +// STATIC DATA + +DBG_NAME(SfxBigIntItem) + +// RTTI +TYPEINIT1_AUTOFACTORY(SfxBigIntItem, SfxPoolItem); + +// SfxBigIntItem + +//============================================================================ +SfxBigIntItem::SfxBigIntItem() + : SfxPoolItem(0), + aVal(0) +{ + DBG_CTOR(SfxBigIntItem, 0); +} + +//============================================================================ +SfxBigIntItem::SfxBigIntItem(USHORT which, const BigInt& rValue) + : SfxPoolItem(which), + aVal(rValue) +{ + DBG_CTOR(SfxBigIntItem, 0); +} + +//============================================================================ +SfxBigIntItem::SfxBigIntItem(USHORT which, SvStream &rStream) + : SfxPoolItem(which) +{ + DBG_CTOR(SfxBigIntItem, 0); + ByteString sTmp; + rStream.ReadByteString(sTmp); + BigInt aTmp(sTmp); + aVal = aTmp; +} + +//============================================================================ +SfxBigIntItem::SfxBigIntItem(const SfxBigIntItem& rItem) + : SfxPoolItem(rItem), + aVal(rItem.aVal) +{ + DBG_CTOR(SfxBigIntItem, 0); +} + +//============================================================================ +SfxItemPresentation SfxBigIntItem::GetPresentation( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * ) const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + rText = aVal.GetString(); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +int SfxBigIntItem::operator==(const SfxPoolItem& rItem) const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + DBG_ASSERT(SfxPoolItem::operator==(rItem), "unequal type"); + return ((SfxBigIntItem&)rItem).aVal == aVal; +} + +//============================================================================ +int SfxBigIntItem::Compare(const SfxPoolItem& rItem) const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + DBG_ASSERT(SfxPoolItem::operator==(rItem), "unequal type"); + + if (((const SfxBigIntItem&)rItem ).aVal < aVal ) + return -1; + else if (((const SfxBigIntItem&)rItem ).aVal == aVal) + return 0; + else + return 1; +} + +//============================================================================ +SfxPoolItem* SfxBigIntItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + return new SfxBigIntItem(*this); +} + +//============================================================================ +SfxPoolItem* SfxBigIntItem::Create(SvStream &rStream, USHORT) const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + return new SfxBigIntItem(Which(), rStream); +} + +//============================================================================ +SvStream& SfxBigIntItem::Store(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + rStream.WriteByteString( aVal.GetByteString() ); + return rStream; +} + +//============================================================================ +SfxFieldUnit SfxBigIntItem::GetUnit() const +{ + DBG_CHKTHIS(SfxBigIntItem, 0); + return SFX_FUNIT_NONE; +} + +//============================================================================ +// virtual +BOOL SfxBigIntItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE ) +{ + double aValue = 0.0; + if ( rVal >>= aValue ) + { + SetValue( aValue ); + return TRUE; + } + + DBG_ERROR( "SfxBigIntItem::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +BOOL SfxBigIntItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const +{ + double aValue = GetValue(); + rVal <<= aValue; + return TRUE; +} + diff --git a/svl/source/items/cenumitm.cxx b/svl/source/items/cenumitm.cxx new file mode 100644 index 000000000000..1906e62a8cf8 --- /dev/null +++ b/svl/source/items/cenumitm.cxx @@ -0,0 +1,297 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cenumitm.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <tools/stream.hxx> +#include <svtools/cenumitm.hxx> +#include <whassert.hxx> + +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +//============================================================================ +// +// class SfxEnumItemInterface +// +//============================================================================ + +DBG_NAME(SfxEnumItemInterface) + +//============================================================================ +TYPEINIT1(SfxEnumItemInterface, SfxPoolItem) + +//============================================================================ +// virtual +int SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const +{ + SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type"); + return GetEnumValue() + == static_cast< const SfxEnumItemInterface * >(&rItem)-> + GetEnumValue(); +} + +//============================================================================ +// virtual +SfxItemPresentation +SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit, + SfxMapUnit, XubString & rText, + const IntlWrapper *) const +{ + rText = XubString::CreateFromInt32(GetEnumValue()); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, BYTE) + const +{ + rVal <<= sal_Int32(GetEnumValue()); + return true; +} + +//============================================================================ +// virtual +BOOL SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal, + BYTE) +{ + sal_Int32 nTheValue = 0; + + if ( ::cppu::enum2int( nTheValue, rVal ) ) + { + SetEnumValue(USHORT(nTheValue)); + return true; + } + DBG_ERROR("SfxEnumItemInterface::PutValue(): Wrong type"); + return false; +} + +//============================================================================ +XubString SfxEnumItemInterface::GetValueTextByPos(USHORT) const +{ + DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual"); + return XubString(); +} + +//============================================================================ +// virtual +USHORT SfxEnumItemInterface::GetValueByPos(USHORT nPos) const +{ + return nPos; +} + +//============================================================================ +// virtual +USHORT SfxEnumItemInterface::GetPosByValue(USHORT nValue) const +{ + USHORT nCount = GetValueCount(); + for (USHORT i = 0; i < nCount; ++i) + if (GetValueByPos(i) == nValue) + return i; + return USHRT_MAX; +} + +BOOL SfxEnumItemInterface::IsEnabled(USHORT) const +{ + return TRUE; +} + +//============================================================================ +// virtual +int SfxEnumItemInterface::HasBoolValue() const +{ + return false; +} + +//============================================================================ +// virtual +BOOL SfxEnumItemInterface::GetBoolValue() const +{ + return false; +} + +//============================================================================ +// virtual +void SfxEnumItemInterface::SetBoolValue(BOOL) +{} + +//============================================================================ +// +// class CntEnumItem +// +//============================================================================ + +DBG_NAME(CntEnumItem) + +//============================================================================ +CntEnumItem::CntEnumItem(USHORT which, SvStream & rStream): + SfxEnumItemInterface(which) +{ + m_nValue = 0; + rStream >> m_nValue; +} + +//============================================================================ +TYPEINIT1(CntEnumItem, SfxEnumItemInterface) + +//============================================================================ +// virtual +SvStream & CntEnumItem::Store(SvStream & rStream, USHORT) const +{ + rStream << m_nValue; + return rStream; +} + +//============================================================================ +// virtual +USHORT CntEnumItem::GetEnumValue() const +{ + return GetValue(); +} + +//============================================================================ +// virtual +void CntEnumItem::SetEnumValue(USHORT nTheValue) +{ + SetValue(nTheValue); +} + +//============================================================================ +// +// class CntBoolItem +// +//============================================================================ + +DBG_NAME(CntBoolItem) + +//============================================================================ +TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem) + +//============================================================================ +CntBoolItem::CntBoolItem(USHORT which, SvStream & rStream): + SfxPoolItem(which) +{ + m_bValue = false; + rStream >> m_bValue; +} + +//============================================================================ +// virtual +int CntBoolItem::operator ==(const SfxPoolItem & rItem) const +{ + DBG_ASSERT(rItem.ISA(CntBoolItem), + "CntBoolItem::operator ==(): Bad type"); + return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue; +} + +//============================================================================ +// virtual +int CntBoolItem::Compare(const SfxPoolItem & rWith) const +{ + DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type"); + return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ? + 0 : m_bValue ? -1 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + UniString & rText, + const IntlWrapper *) const +{ + rText = GetValueTextByVal(m_bValue); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, BYTE) const +{ + rVal <<= sal_Bool(m_bValue); + return true; +} + +//============================================================================ +// virtual +BOOL CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, BYTE) +{ + sal_Bool bTheValue = sal_Bool(); + if (rVal >>= bTheValue) + { + m_bValue = bTheValue; + return true; + } + DBG_ERROR("CntBoolItem::PutValue(): Wrong type"); + return false; +} + +//============================================================================ +// virtual +SfxPoolItem * CntBoolItem::Create(SvStream & rStream, USHORT) const +{ + return new CntBoolItem(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & CntBoolItem::Store(SvStream & rStream, USHORT) const +{ + rStream << m_bValue; + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const +{ + return new CntBoolItem(*this); +} + +//============================================================================ +// virtual +USHORT CntBoolItem::GetValueCount() const +{ + return 2; +} + +//============================================================================ +// virtual +UniString CntBoolItem::GetValueTextByVal(BOOL bTheValue) const +{ + return + bTheValue ? + UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("TRUE")) : + UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("FALSE")); +} + diff --git a/svl/source/items/cintitem.cxx b/svl/source/items/cintitem.cxx new file mode 100644 index 000000000000..97cce9b75591 --- /dev/null +++ b/svl/source/items/cintitem.cxx @@ -0,0 +1,565 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cintitem.cxx,v $ + * $Revision: 1.10 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <tools/stream.hxx> +#include <svtools/cintitem.hxx> + +//============================================================================ +// +// class CntByteItem +// +//============================================================================ + +DBG_NAME(CntByteItem) + +//============================================================================ +TYPEINIT1_AUTOFACTORY(CntByteItem, SfxPoolItem); + +//============================================================================ +CntByteItem::CntByteItem(USHORT which, SvStream & rStream): + SfxPoolItem(which) +{ + DBG_CTOR(CntByteItem, 0); + rStream >> m_nValue; +} + +//============================================================================ +// virtual +int CntByteItem::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(CntByteItem, 0); + DBG_ASSERT(rItem.ISA(CntByteItem), + "CntByteItem::operator ==(): Bad type"); + return m_nValue == SAL_STATIC_CAST(const CntByteItem *, &rItem)->m_nValue; +} + +//============================================================================ +// virtual +int CntByteItem::Compare(const SfxPoolItem & rWith) const +{ + DBG_CHKTHIS(CntByteItem, 0); + DBG_ASSERT(rWith.ISA(CntByteItem), "CntByteItem::Compare(): Bad type"); + return SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue < m_nValue ? + -1 : + SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue + == m_nValue ? + 0 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation CntByteItem::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + XubString & rText, + const IntlWrapper *) const +{ + DBG_CHKTHIS(CntByteItem, 0); + rText = XubString::CreateFromInt32(m_nValue); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL CntByteItem::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const +{ + sal_Int8 nValue = m_nValue; + rVal <<= nValue; + return TRUE; +} + +//============================================================================ +// virtual +BOOL CntByteItem::PutValue(const com::sun::star::uno::Any& rVal,BYTE) +{ + sal_Int8 nValue = sal_Int8(); + if (rVal >>= nValue) + { + m_nValue = nValue; + return TRUE; + } + + DBG_ERROR( "CntByteItem::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +SfxPoolItem * CntByteItem::Create(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(CntByteItem, 0); + short nTheValue = 0; + rStream >> nTheValue; + return new CntByteItem(Which(), BYTE(nTheValue)); +} + +//============================================================================ +// virtual +SvStream & CntByteItem::Store(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(CntByteItem, 0); + rStream << short(m_nValue); + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * CntByteItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(CntByteItem, 0); + return new CntByteItem(*this); +} + +//============================================================================ +// virtual +BYTE CntByteItem::GetMin() const +{ + DBG_CHKTHIS(CntByteItem, 0); + return 0; +} + +//============================================================================ +// virtual +BYTE CntByteItem::GetMax() const +{ + DBG_CHKTHIS(CntByteItem, 0); + return 255; +} + +//============================================================================ +// virtual +SfxFieldUnit CntByteItem::GetUnit() const +{ + DBG_CHKTHIS(CntByteItem, 0); + return SFX_FUNIT_NONE; +} + +//============================================================================ +// +// class CntUInt16Item +// +//============================================================================ + +DBG_NAME(CntUInt16Item); + +//============================================================================ +TYPEINIT1_AUTOFACTORY(CntUInt16Item, SfxPoolItem); + +//============================================================================ +CntUInt16Item::CntUInt16Item(USHORT which, SvStream & rStream) : + SfxPoolItem(which) +{ + DBG_CTOR(CntUInt16Item, 0); + USHORT nTheValue = 0; + rStream >> nTheValue; + m_nValue = nTheValue; +} + +//============================================================================ +// virtual +int CntUInt16Item::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + DBG_ASSERT(rItem.ISA(CntUInt16Item), + "CntUInt16Item::operator ==(): Bad type"); + return m_nValue == SAL_STATIC_CAST(const CntUInt16Item *, &rItem)-> + m_nValue; +} + +//============================================================================ +// virtual +int CntUInt16Item::Compare(const SfxPoolItem & rWith) const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + DBG_ASSERT(rWith.ISA(CntUInt16Item), + "CntUInt16Item::Compare(): Bad type"); + return SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue + < m_nValue ? + -1 : + SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue + == m_nValue ? + 0 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation CntUInt16Item::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + XubString & rText, + const IntlWrapper *) + const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + rText = XubString::CreateFromInt32(m_nValue); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL CntUInt16Item::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const +{ + sal_Int32 nValue = m_nValue; + rVal <<= nValue; + return TRUE; +} + +//============================================================================ +// virtual +BOOL CntUInt16Item::PutValue(const com::sun::star::uno::Any& rVal,BYTE) +{ + sal_Int32 nValue = 0; + if (rVal >>= nValue) + { + DBG_ASSERT( nValue <= USHRT_MAX, "Overflow in UInt16 value!"); + m_nValue = (sal_uInt16)nValue; + return TRUE; + } + + DBG_ERROR( "CntUInt16Item::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +SfxPoolItem * CntUInt16Item::Create(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + return new CntUInt16Item(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & CntUInt16Item::Store(SvStream &rStream, USHORT) const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + rStream << USHORT(m_nValue); + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * CntUInt16Item::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + return new CntUInt16Item(*this); +} + +//============================================================================ +// virtual +UINT16 CntUInt16Item::GetMin() const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + return 0; +} + +//============================================================================ +// virtual +UINT16 CntUInt16Item::GetMax() const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + return 65535; +} + +//============================================================================ +// virtual +SfxFieldUnit CntUInt16Item::GetUnit() const +{ + DBG_CHKTHIS(CntUInt16Item, 0); + return SFX_FUNIT_NONE; +} + +//============================================================================ +// +// class CntInt32Item +// +//============================================================================ + +DBG_NAME(CntInt32Item); + +//============================================================================ +TYPEINIT1_AUTOFACTORY(CntInt32Item, SfxPoolItem); + +//============================================================================ +CntInt32Item::CntInt32Item(USHORT which, SvStream & rStream) : + SfxPoolItem(which) +{ + DBG_CTOR(CntInt32Item, 0); + long nTheValue = 0; + rStream >> nTheValue; + m_nValue = nTheValue; +} + +//============================================================================ +// virtual +int CntInt32Item::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(CntInt32Item, 0); + DBG_ASSERT(rItem.ISA(CntInt32Item), + "CntInt32Item::operator ==(): Bad type"); + return m_nValue == SAL_STATIC_CAST(const CntInt32Item *, &rItem)-> + m_nValue; +} + +//============================================================================ +// virtual +int CntInt32Item::Compare(const SfxPoolItem & rWith) const +{ + DBG_CHKTHIS(CntInt32Item, 0); + DBG_ASSERT(rWith.ISA(CntInt32Item), "CntInt32Item::Compare(): Bad type"); + return SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue + < m_nValue ? + -1 : + SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue + == m_nValue ? + 0 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation CntInt32Item::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + XubString & rText, + const IntlWrapper *) const +{ + DBG_CHKTHIS(CntInt32Item, 0); + rText = XubString::CreateFromInt32(m_nValue); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL CntInt32Item::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const +{ + sal_Int32 nValue = m_nValue; + rVal <<= nValue; + return TRUE; +} + +//============================================================================ +// virtual +BOOL CntInt32Item::PutValue(const com::sun::star::uno::Any& rVal,BYTE) +{ + sal_Int32 nValue = 0; + if (rVal >>= nValue) + { + m_nValue = nValue; + return TRUE; + } + + DBG_ERROR( "CntInt32Item::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +SfxPoolItem * CntInt32Item::Create(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(CntInt32Item, 0); + return new CntInt32Item(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & CntInt32Item::Store(SvStream &rStream, USHORT) const +{ + DBG_CHKTHIS(CntInt32Item, 0); + rStream << long(m_nValue); + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * CntInt32Item::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(CntInt32Item, 0); + return new CntInt32Item(*this); +} + +//============================================================================ +// virtual +INT32 CntInt32Item::GetMin() const +{ + DBG_CHKTHIS(CntInt32Item, 0); + return INT32(0x80000000); +} + +//============================================================================ +// virtual +INT32 CntInt32Item::GetMax() const +{ + DBG_CHKTHIS(CntInt32Item, 0); + return 0x7FFFFFFF; +} + +//============================================================================ +// virtual +SfxFieldUnit CntInt32Item::GetUnit() const +{ + DBG_CHKTHIS(CntInt32Item, 0); + return SFX_FUNIT_NONE; +} + +//============================================================================ +// +// class CntUInt32Item +// +//============================================================================ + +DBG_NAME(CntUInt32Item); + +//============================================================================ +TYPEINIT1_AUTOFACTORY(CntUInt32Item, SfxPoolItem); + +//============================================================================ +CntUInt32Item::CntUInt32Item(USHORT which, SvStream & rStream) : + SfxPoolItem(which) +{ + DBG_CTOR(CntUInt32Item, 0); + sal_uInt32 nTheValue = 0; + rStream >> nTheValue; + m_nValue = nTheValue; +} + +//============================================================================ +// virtual +int CntUInt32Item::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + DBG_ASSERT(rItem.ISA(CntUInt32Item), + "CntUInt32Item::operator ==(): Bad type"); + return m_nValue == SAL_STATIC_CAST(const CntUInt32Item *, &rItem)-> + m_nValue; +} + +//============================================================================ +// virtual +int CntUInt32Item::Compare(const SfxPoolItem & rWith) const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + DBG_ASSERT(rWith.ISA(CntUInt32Item), + "CntUInt32Item::operator ==(): Bad type"); + return SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue + < m_nValue ? + -1 : + SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue + == m_nValue ? + 0 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation CntUInt32Item::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + XubString & rText, + const IntlWrapper *) + const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + rText = XubString::CreateFromInt64(m_nValue); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL CntUInt32Item::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const +{ + sal_Int32 nValue = m_nValue; + DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!"); + rVal <<= nValue; + return TRUE; +} + +//============================================================================ +// virtual +BOOL CntUInt32Item::PutValue(const com::sun::star::uno::Any& rVal,BYTE) +{ + sal_Int32 nValue = 0; + if (rVal >>= nValue) + { + DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!"); + m_nValue = nValue; + return TRUE; + } + + DBG_ERROR( "CntUInt32Item::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +SfxPoolItem * CntUInt32Item::Create(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + return new CntUInt32Item(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & CntUInt32Item::Store(SvStream &rStream, USHORT) const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + rStream << static_cast<sal_uInt32>(m_nValue); + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * CntUInt32Item::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + return new CntUInt32Item(*this); +} + +//============================================================================ +// virtual +UINT32 CntUInt32Item::GetMin() const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + return 0; +} + +//============================================================================ +// virtual +UINT32 CntUInt32Item::GetMax() const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + return 0xFFFFFFFF; +} + +//============================================================================ +// virtual +SfxFieldUnit CntUInt32Item::GetUnit() const +{ + DBG_CHKTHIS(CntUInt32Item, 0); + return SFX_FUNIT_NONE; +} + diff --git a/svl/source/items/cntwall.cxx b/svl/source/items/cntwall.cxx new file mode 100644 index 000000000000..67e9387fbe26 --- /dev/null +++ b/svl/source/items/cntwall.cxx @@ -0,0 +1,170 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cntwall.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <tools/debug.hxx> +#include <tools/string.hxx> +#include <tools/stream.hxx> +#include <tools/vcompat.hxx> + +#include <svtools/cntwall.hxx> + +#define CNTWALLPAPERITEM_STREAM_MAGIC ( (UINT32)0xfefefefe ) +#define CNTWALLPAPERITEM_STREAM_SEEKREL (-( (long)( sizeof( UINT32 ) ) ) ) + +TYPEINIT1( CntWallpaperItem, SfxPoolItem ); + +// ----------------------------------------------------------------------- +CntWallpaperItem::CntWallpaperItem( USHORT which ) + : SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 ) +{ +} + +// ----------------------------------------------------------------------- +CntWallpaperItem::CntWallpaperItem( USHORT which, SvStream& rStream, USHORT nVersion ) + : SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 ) +{ + UINT32 nMagic = 0; + rStream >> nMagic; + if ( nMagic == CNTWALLPAPERITEM_STREAM_MAGIC ) + { + // Okay, data were stored by CntWallpaperItem. + + readUnicodeString(rStream, _aURL, nVersion >= 1); + // !!! Color stream operators do not work - they discard any + // transparency info !!! + _nColor.Read( rStream, TRUE ); + rStream >> _nStyle; + } + else + { + rStream.SeekRel( CNTWALLPAPERITEM_STREAM_SEEKREL ); + + // Data were stored by SfxWallpaperItem ( SO < 6.0 ). The only + // thing we can do here is to get the URL and to position the stream. + + { + // "Read" Wallpaper member - The version compat object positions + // the stream after the wallpaper data in its dtor. We must use + // this trick here as no VCL must be used here ( No Wallpaper + // object allowed ). + VersionCompat aCompat( rStream, STREAM_READ ); + } + + // Read SfxWallpaperItem's string member _aURL. + readUnicodeString(rStream, _aURL, false); + + // "Read" SfxWallpaperItem's string member _aFilter. + ByteString aDummy; + rStream.ReadByteString(aDummy); + } +} + +// ----------------------------------------------------------------------- +CntWallpaperItem::CntWallpaperItem( const CntWallpaperItem& rItem ) : + SfxPoolItem( rItem ), + _aURL( rItem._aURL ), + _nColor( rItem._nColor ), + _nStyle( rItem._nStyle ) +{ +} + +// ----------------------------------------------------------------------- +CntWallpaperItem::~CntWallpaperItem() +{ +} + +// ----------------------------------------------------------------------- +int CntWallpaperItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + const CntWallpaperItem& rWallItem = (const CntWallpaperItem&)rItem; + + if( ( rWallItem._nStyle == _nStyle ) && + ( rWallItem._nColor == _nColor ) && + ( rWallItem._aURL == _aURL ) ) + return TRUE; + else + return FALSE; +} + +//============================================================================ +// virtual +USHORT CntWallpaperItem::GetVersion(USHORT) const +{ + return 1; // because it uses SfxPoolItem::read/writeUnicodeString() +} + +// ----------------------------------------------------------------------- +SfxPoolItem* CntWallpaperItem::Create( SvStream& rStream, USHORT nVersion) const +{ + return new CntWallpaperItem( Which(), rStream, nVersion ); +} + +// ----------------------------------------------------------------------- +SvStream& CntWallpaperItem::Store( SvStream& rStream, USHORT ) const +{ + rStream << CNTWALLPAPERITEM_STREAM_MAGIC; + writeUnicodeString(rStream, _aURL); + // !!! Color stream operators do not work - they discard any + // transparency info !!! + // ??? Why the hell Color::Write(...) isn't const ??? + SAL_CONST_CAST( CntWallpaperItem*, this )->_nColor.Write( rStream, TRUE ); + rStream << _nStyle; + + return rStream; +} + +// ----------------------------------------------------------------------- +SfxPoolItem* CntWallpaperItem::Clone( SfxItemPool* ) const +{ + return new CntWallpaperItem( *this ); +} + +//---------------------------------------------------------------------------- +// virtual +BOOL CntWallpaperItem::QueryValue( com::sun::star::uno::Any&,BYTE ) const +{ + DBG_ERROR("Not implemented!"); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL CntWallpaperItem::PutValue( const com::sun::star::uno::Any&,BYTE ) +{ + DBG_ERROR("Not implemented!"); + return FALSE; +} + + diff --git a/svl/source/items/cstitem.cxx b/svl/source/items/cstitem.cxx new file mode 100644 index 000000000000..9755f4bb9944 --- /dev/null +++ b/svl/source/items/cstitem.cxx @@ -0,0 +1,252 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cstitem.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> + +#include <unotools/intlwrapper.hxx> + +#include <tools/stream.hxx> +#include <tools/debug.hxx> +#include <tools/datetime.hxx> + +#include <svtools/svtdata.hxx> +#include <svtools/cstitem.hxx> + +#include <svtools/svtools.hrc> +#include <com/sun/star/lang/Locale.hpp> + +DBG_NAME( SfxCrawlStatusItem ) +TYPEINIT1( SfxCrawlStatusItem, SfxPoolItem ); + +// ----------------------------------------------------------------------- + +SfxCrawlStatusItem::SfxCrawlStatusItem( USHORT which ) : + SfxPoolItem( which ) +{ + DBG_CTOR( SfxCrawlStatusItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxCrawlStatusItem::SfxCrawlStatusItem( USHORT which, CrawlStatus eStat ) : + SfxPoolItem( which ), + eStatus( eStat ) +{ + DBG_CTOR( SfxCrawlStatusItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxCrawlStatusItem::SfxCrawlStatusItem( const SfxCrawlStatusItem& rItem ) : + SfxPoolItem( rItem ), + eStatus( rItem.eStatus ) +{ + DBG_CTOR( SfxCrawlStatusItem, 0 ); +} + +// ----------------------------------------------------------------------- + +int SfxCrawlStatusItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS( SfxCrawlStatusItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + return ((SfxCrawlStatusItem&)rItem).eStatus == eStatus; +} + +// ----------------------------------------------------------------------- + +int SfxCrawlStatusItem::Compare( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS( SfxCrawlStatusItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + if( ((const SfxCrawlStatusItem&)rItem).eStatus < eStatus ) + return -1; + else if( ((const SfxCrawlStatusItem&)rItem).eStatus == eStatus ) + return 0; + else + return 1; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxCrawlStatusItem::Create( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxCrawlStatusItem, 0); + + USHORT _eStatus; + rStream >> _eStatus; + + return new SfxCrawlStatusItem( Which(), (CrawlStatus)_eStatus ); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxCrawlStatusItem::Store( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS( SfxCrawlStatusItem, 0 ); + + USHORT nStatus = (USHORT)eStatus; + rStream << (USHORT) nStatus; + + return rStream; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxCrawlStatusItem::Clone( SfxItemPool* ) const +{ + DBG_CHKTHIS( SfxCrawlStatusItem, 0 ); + return new SfxCrawlStatusItem( *this ); +} +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxCrawlStatusItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * pIntlWrapper +) const +{ + DBG_CHKTHIS(SfxCrawlStatusItem, 0); + DBG_ASSERT(pIntlWrapper, + "SfxCrawlStatusItem::GetPresentation():" + " Using default IntlWrapper"); + + ::com::sun::star::lang::Locale aLocale; + + switch (eStatus) + { + case CSTAT_NEVER_UPD: + rText = String(SvtResId(STR_CSTAT_NEVER_UPD, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_IN_UPD: + rText = String(SvtResId(STR_CSTAT_IN_UPD, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_UPD_NEWER: + rText = String(SvtResId(STR_CSTAT_UPD_NEWER, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_UPD_NOT_NEWER: + rText = String(SvtResId(STR_CSTAT_UPD_NOT_NEWER, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_UPD_CANCEL: + rText = String(SvtResId(STR_CSTAT_UPD_CANCEL, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_ERR_GENERAL: + rText = String(SvtResId(STR_CSTAT_ERR_GENERAL, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_ERR_NOTEXISTS: + rText = String(SvtResId(STR_CSTAT_ERR_NOTEXISTS, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_ERR_NOTREACHED: + rText = String(SvtResId(STR_CSTAT_ERR_NOTREACHED, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_UPD_IMMEDIATELY: + rText = String(SvtResId(STR_CSTAT_UPD_IMMEDIATELY, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + case CSTAT_ERR_OFFLINE: + rText = String(SvtResId(STR_CSTAT_ERR_OFFLINE, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + break; + + default: + rText.Erase(); + break; + } + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxCrawlStatusItem::PutValue( const com::sun::star::uno::Any& rVal,BYTE ) +{ + sal_Int16 aValue = sal_Int16(); + if ( rVal >>= aValue ) + { + SetStatus( static_cast< CrawlStatus >( aValue ) ); + return TRUE; + } + + DBG_ERROR( "SfxCrawlStatusItem::PutValue - Wrong type!" ); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxCrawlStatusItem::QueryValue( com::sun::star::uno::Any& rVal,BYTE ) const +{ + sal_Int16 aValue = sal::static_int_cast< sal_Int16 >(GetStatus()); + rVal <<= aValue; + return TRUE; +} + diff --git a/svl/source/items/cstitem.src b/svl/source/items/cstitem.src new file mode 100644 index 000000000000..8d6e2d0280c0 --- /dev/null +++ b/svl/source/items/cstitem.src @@ -0,0 +1,112 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: cstitem.src,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <svtools/svtools.hrc> +String STR_CSTAT_NEVER_UPD +{ + Text [ en-US ] = "No update has occurred" ; +}; +String STR_CSTAT_IN_UPD +{ + Text [ en-US ] = "Updating in progress" ; +}; +String STR_CSTAT_UPD_NEWER +{ + Text [ en-US ] = "Changes discovered" ; +}; +String STR_CSTAT_UPD_NOT_NEWER +{ + Text [ en-US ] = "No changes discovered" ; +}; +String STR_CSTAT_UPD_CANCEL +{ + Text [ en-US ] = "Canceled by user" ; +}; +String STR_CSTAT_UPD_IMMEDIATELY +{ + Text [ en-US ] = "Updating immediately" ; +}; +String STR_CSTAT_ERR_OFFLINE +{ + Text [ en-US ] = "failed, you have not been online" ; +}; +String STR_CSTAT_ERR_GENERAL +{ + Text [ en-US ] = "General error" ; +}; +String STR_CSTAT_ERR_NOTEXISTS +{ + Text [ en-US ] = "Server does not exist" ; +}; +String STR_CSTAT_ERR_NOTREACHED +{ + Text [ en-US ] = "Server not available" ; +}; +String STR_COLUM_DT_AUTO +{ + Text [ en-US ] = "automatic" ; +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svl/source/items/ctypeitm.cxx b/svl/source/items/ctypeitm.cxx new file mode 100644 index 000000000000..552d4a6a9041 --- /dev/null +++ b/svl/source/items/ctypeitm.cxx @@ -0,0 +1,254 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ctypeitm.cxx,v $ + * $Revision: 1.7.136.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> + +#include <unotools/intlwrapper.hxx> +#include <tools/stream.hxx> +#include <svtools/ctypeitm.hxx> + +//============================================================================ +// The following defines are copied from chaos/source/items/cstritem.cxx: +#define CNTSTRINGITEM_STREAM_MAGIC ( (UINT32)0xfefefefe ) +#define CNTSTRINGITEM_STREAM_SEEKREL (-( (long)( sizeof( UINT32 ) ) ) ) + +//============================================================================ +// +// class CntContentTypeItem Implementation. +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY( CntContentTypeItem, CntUnencodedStringItem ); + +#define CONTENT_TYPE_NOT_INIT ( (INetContentType)-1 ) + +//---------------------------------------------------------------------------- +CntContentTypeItem::CntContentTypeItem() +: CntUnencodedStringItem(), + _eType( CONTENT_TYPE_NOT_INIT ) +{ +} + +//---------------------------------------------------------------------------- +CntContentTypeItem::CntContentTypeItem( USHORT which, const XubString& rType ) +: CntUnencodedStringItem( which, rType ), + _eType( CONTENT_TYPE_NOT_INIT ) +{ +} + +//---------------------------------------------------------------------------- +CntContentTypeItem::CntContentTypeItem( USHORT which, + const INetContentType eType ) +: CntUnencodedStringItem( which, INetContentTypes::GetContentType( eType ) ), + _eType( eType ) +{ +} + +//---------------------------------------------------------------------------- +CntContentTypeItem::CntContentTypeItem( const CntContentTypeItem& rOrig ) +: CntUnencodedStringItem( rOrig ), + _eType( rOrig._eType ), + _aPresentation( rOrig._aPresentation ) +{ +} + +//============================================================================ +// virtual +USHORT CntContentTypeItem::GetVersion(USHORT) const +{ + return 1; // because it uses SfxPoolItem::read/writeUnicodeString() +} + +//---------------------------------------------------------------------------- +// virtual +SfxPoolItem* CntContentTypeItem::Create( SvStream& rStream, + USHORT nItemVersion ) const +{ + // CntContentTypeItem used to be derived from CntStringItem, so take that + // into account: + UniString aValue; + readUnicodeString(rStream, aValue, nItemVersion >= 1); + UINT32 nMagic = 0; + rStream >> nMagic; + if (nMagic == CNTSTRINGITEM_STREAM_MAGIC) + { + BOOL bEncrypted = FALSE; + rStream >> bEncrypted; + DBG_ASSERT(!bEncrypted, + "CntContentTypeItem::Create() reads encrypted data"); + } + else + rStream.SeekRel(CNTSTRINGITEM_STREAM_SEEKREL); + + return new CntContentTypeItem(Which(), aValue); +} + +//---------------------------------------------------------------------------- +// virtual +SvStream & CntContentTypeItem::Store(SvStream & rStream, USHORT) const +{ + // CntContentTypeItem used to be derived from CntStringItem, so take that + // into account: + writeUnicodeString(rStream, GetValue()); + rStream << CNTSTRINGITEM_STREAM_MAGIC << BOOL(FALSE); + return rStream; +} + +//---------------------------------------------------------------------------- +// virtual +int CntContentTypeItem::operator==( const SfxPoolItem& rOrig ) const +{ + const CntContentTypeItem& rOther = (const CntContentTypeItem&)rOrig; + + if ( ( _eType != CONTENT_TYPE_NOT_INIT ) && + ( rOther._eType != CONTENT_TYPE_NOT_INIT ) ) + return _eType == rOther._eType; + else + return CntUnencodedStringItem::operator==( rOther ); +} + +//---------------------------------------------------------------------------- +// virtual +SfxPoolItem* CntContentTypeItem::Clone( SfxItemPool* /* pPool */ ) const +{ + return new CntContentTypeItem( *this ); +} + +//---------------------------------------------------------------------------- +void CntContentTypeItem::SetValue( const XubString& rNewVal ) +{ + // De-initialize enum type and presentation. + _eType = CONTENT_TYPE_NOT_INIT; + _aPresentation.Erase(); + + CntUnencodedStringItem::SetValue( rNewVal ); +} + +//---------------------------------------------------------------------------- +void CntContentTypeItem::SetPresentation( const XubString& rNewVal ) +{ + _aPresentation = rNewVal; +} + +//---------------------------------------------------------------------------- +int CntContentTypeItem::Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const +{ + String aOwnText, aWithText; + GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS, + SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aOwnText, &rIntlWrapper ); + rWith.GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS, + SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aWithText, &rIntlWrapper ); + return rIntlWrapper.getCollator()->compareString( aOwnText, aWithText ); +} + +//---------------------------------------------------------------------------- +SfxItemPresentation CntContentTypeItem::GetPresentation( + SfxItemPresentation ePres, + SfxMapUnit eCoreMetric, + SfxMapUnit ePresMetric, + XubString & rText, + const IntlWrapper * pIntlWrapper) const +{ + if (_aPresentation.Len() == 0) + { + DBG_ASSERT(pIntlWrapper, + "CntContentTypeItem::GetPresentation(): No IntlWrapper"); + if (pIntlWrapper) + SAL_CONST_CAST(CntContentTypeItem *, this)->_aPresentation + = INetContentTypes::GetPresentation(GetEnumValue(), + pIntlWrapper-> + getLocale()); + } + if (_aPresentation.Len() > 0) + { + rText = _aPresentation; + return SFX_ITEM_PRESENTATION_COMPLETE; + } + else + return CntUnencodedStringItem::GetPresentation(ePres, eCoreMetric, + ePresMetric, rText, + pIntlWrapper); +} + +//---------------------------------------------------------------------------- +INetContentType CntContentTypeItem::GetEnumValue() const +{ + if ( _eType == CONTENT_TYPE_NOT_INIT ) + { + // Not yet initialized... Get enum value for string content type. + + CntContentTypeItem* pVarThis = SAL_CONST_CAST( CntContentTypeItem*, this ); + + pVarThis->_eType = INetContentTypes::GetContentType( GetValue() ); + } + + return _eType; +} + +//---------------------------------------------------------------------------- +void CntContentTypeItem::SetValue( const INetContentType eType ) +{ + SetValue( INetContentTypes::GetContentType( eType ) ); + + // Note: SetValue( const String& ....) resets _eType. Set new enum value + // after(!) calling it. + _eType = eType; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL CntContentTypeItem::QueryValue( com::sun::star::uno::Any& rVal,BYTE ) const +{ + rVal <<= rtl::OUString(GetValue()); + return true; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL CntContentTypeItem::PutValue( const com::sun::star::uno::Any& rVal,BYTE ) +{ + rtl::OUString aValue; + if ( rVal >>= aValue ) + { + // SetValue with an empty string resets the item; so call that + // function when PutValue is called with an empty string + if (aValue.getLength() == 0) + SetValue(aValue); + else + SetValue( + INetContentTypes::RegisterContentType(aValue, UniString())); + return true; + } + + DBG_ERROR( "CntContentTypeItem::PutValue - Wrong type!" ); + return false; +} diff --git a/svl/source/items/custritm.cxx b/svl/source/items/custritm.cxx new file mode 100644 index 000000000000..9f573beb56fd --- /dev/null +++ b/svl/source/items/custritm.cxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: custritm.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> + +#include <unotools/intlwrapper.hxx> +#include <tools/stream.hxx> +#include <svtools/custritm.hxx> + +//============================================================================ +// +// class CntUnencodedStringItem +// +//============================================================================ + +DBG_NAME(CntUnencodedStringItem) + +//============================================================================ +TYPEINIT1_AUTOFACTORY(CntUnencodedStringItem, SfxPoolItem) + +//============================================================================ +// virtual +int CntUnencodedStringItem::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(CntUnencodedStringItem, 0); + DBG_ASSERT(rItem.ISA(CntUnencodedStringItem), + "CntUnencodedStringItem::operator ==(): Bad type"); + return m_aValue + == SAL_STATIC_CAST(const CntUnencodedStringItem *, &rItem)-> + m_aValue; +} + +//============================================================================ +// virtual +int CntUnencodedStringItem::Compare(SfxPoolItem const & rWith) const +{ + DBG_ERROR("CntUnencodedStringItem::Compare(): No international"); + DBG_CHKTHIS(CntUnencodedStringItem, 0); + DBG_ASSERT(rWith.ISA(CntUnencodedStringItem), + "CntUnencodedStringItem::Compare(): Bad type"); + switch (m_aValue.CompareTo(static_cast< CntUnencodedStringItem const * >( + &rWith)-> + m_aValue)) + { + case COMPARE_LESS: + return -1; + + case COMPARE_EQUAL: + return 0; + + default: // COMPARE_GREATER + return 1; + } +} + +//============================================================================ +// virtual +int CntUnencodedStringItem::Compare(SfxPoolItem const & rWith, + IntlWrapper const & rIntlWrapper) + const +{ + DBG_CHKTHIS(CntUnencodedStringItem, 0); + DBG_ASSERT(rWith.ISA(CntUnencodedStringItem), + "CntUnencodedStringItem::Compare(): Bad type"); + return rIntlWrapper.getCollator()->compareString( m_aValue, + static_cast< CntUnencodedStringItem const * >(&rWith)->m_aValue ); +} + +//============================================================================ +// virtual +SfxItemPresentation +CntUnencodedStringItem::GetPresentation(SfxItemPresentation, SfxMapUnit, + SfxMapUnit, XubString & rText, + const IntlWrapper *) const +{ + DBG_CHKTHIS(CntUnencodedStringItem, 0); + rText = m_aValue; + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//============================================================================ +// virtual +BOOL CntUnencodedStringItem::QueryValue(com::sun::star::uno::Any& rVal, BYTE) + const +{ + rVal <<= rtl::OUString(m_aValue); + return true; +} + +//============================================================================ +// virtual +BOOL CntUnencodedStringItem::PutValue(const com::sun::star::uno::Any& rVal, + BYTE) +{ + rtl::OUString aTheValue; + if (rVal >>= aTheValue) + { + m_aValue = UniString(aTheValue); + return true; + } + DBG_ERROR("CntUnencodedStringItem::PutValue(): Wrong type"); + return false; +} + +//============================================================================ +// virtual +SfxPoolItem * CntUnencodedStringItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(CntUnencodedStringItem, 0); + return new CntUnencodedStringItem(*this); +} + diff --git a/svl/source/items/dateitem.cxx b/svl/source/items/dateitem.cxx new file mode 100644 index 000000000000..4ba6e1d460f9 --- /dev/null +++ b/svl/source/items/dateitem.cxx @@ -0,0 +1,284 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dateitem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +// include --------------------------------------------------------------- + +#define _DATETIMEITEM_CXX +#include <svtools/dateitem.hxx> + +#include <unotools/intlwrapper.hxx> +#include <comphelper/processfactory.hxx> + + +#include <tools/stream.hxx> +#include <tools/debug.hxx> +#include <tools/datetime.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/lang/Locale.hpp> + + +#include <vcl/svapp.hxx> + +#include <svtools/svtdata.hxx> +#include <svtools/svtools.hrc> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxDateTimeItem) + + +// ----------------------------------------------------------------------- + +TYPEINIT1(SfxDateTimeItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxDateTimeItem::SfxDateTimeItem( USHORT which ) : + SfxPoolItem( which ) +{ + DBG_CTOR(SfxDateTimeItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxDateTimeItem::SfxDateTimeItem( USHORT which, const DateTime& rDT ) : + SfxPoolItem( which ), + aDateTime( rDT ) + +{ + DBG_CTOR(SfxDateTimeItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem& rItem ) : + SfxPoolItem( rItem ), + aDateTime( rItem.aDateTime ) +{ + DBG_CTOR(SfxDateTimeItem, 0); +} + +// ----------------------------------------------------------------------- + +int SfxDateTimeItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS(SfxDateTimeItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + return ( ( (SfxDateTimeItem&)rItem ).aDateTime == aDateTime ); +} + +// ----------------------------------------------------------------------- + +int SfxDateTimeItem::Compare( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS(SfxDateTimeItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + // da X.Compare( Y ) am String einem Compare( Y, X ) entspricht, + // vergleichen wir hier Y mit X + if ( ( (const SfxDateTimeItem&)rItem ).aDateTime < aDateTime ) + return -1; + else if ( ( (const SfxDateTimeItem&)rItem ).aDateTime == aDateTime ) + return 0; + else + return 1; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxDateTimeItem::Create( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxDateTimeItem, 0); + sal_uInt32 nDate = 0; + sal_Int32 nTime = 0; + rStream >> nDate; + rStream >> nTime; + DateTime aDT(nDate, nTime); + return new SfxDateTimeItem( Which(), aDT ); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxDateTimeItem::Store( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxDateTimeItem, 0); + rStream << aDateTime.GetDate(); + rStream << aDateTime.GetTime(); + return rStream; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxDateTimeItem::Clone( SfxItemPool* ) const +{ + DBG_CHKTHIS(SfxDateTimeItem, 0); + return new SfxDateTimeItem( *this ); +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxDateTimeItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * pIntlWrapper +) const +{ + DBG_CHKTHIS(SfxDateTimeItem, 0); + if (aDateTime.IsValid()) + if (pIntlWrapper) + { + rText = pIntlWrapper->getLocaleData()->getDate(aDateTime); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += pIntlWrapper->getLocaleData()->getTime(aDateTime); + } + else + { + DBG_WARNING("SfxDateTimeItem::GetPresentation():" + " Using default en_US IntlWrapper"); + const IntlWrapper aIntlWrapper( + ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US ); + rText = aIntlWrapper.getLocaleData()->getDate(aDateTime); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += aIntlWrapper.getLocaleData()->getTime(aDateTime); + } + else + rText.Erase(); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxDateTimeItem::PutValue( const com::sun::star::uno::Any& rVal, + BYTE nMemberId ) +{ + nMemberId &= ~CONVERT_TWIPS; + com::sun::star::util::DateTime aValue; + if ( rVal >>= aValue ) + { + aDateTime = DateTime( Date( aValue.Day, + aValue.Month, + aValue.Year ), + Time( aValue.Hours, + aValue.Minutes, + aValue.Seconds, + aValue.HundredthSeconds ) ); + return TRUE; + } + + DBG_ERROR( "SfxDateTimeItem::PutValue - Wrong type!" ); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxDateTimeItem::QueryValue( com::sun::star::uno::Any& rVal, + BYTE nMemberId ) const +{ + nMemberId &= ~CONVERT_TWIPS; + com::sun::star::util::DateTime aValue( aDateTime.Get100Sec(), + aDateTime.GetSec(), + aDateTime.GetMin(), + aDateTime.GetHour(), + aDateTime.GetDay(), + aDateTime.GetMonth(), + aDateTime.GetYear() ); + rVal <<= aValue; + return TRUE; +} + +// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- + +TYPEINIT1(SfxColumnDateTimeItem, SfxDateTimeItem); + + +SfxColumnDateTimeItem::SfxColumnDateTimeItem( USHORT which ) : + SfxDateTimeItem( which ) +{} + +SfxColumnDateTimeItem::SfxColumnDateTimeItem( USHORT which, const DateTime& rDT ) : + SfxDateTimeItem( which, rDT ) +{} + +SfxColumnDateTimeItem::SfxColumnDateTimeItem( const SfxDateTimeItem& rCpy ) : + SfxDateTimeItem( rCpy ) +{} + +SfxPoolItem* SfxColumnDateTimeItem::Clone( SfxItemPool* ) const +{ + return new SfxColumnDateTimeItem( *this ); +} + +SfxItemPresentation SfxColumnDateTimeItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * pIntlWrapper +) const +{ + DBG_ASSERT(pIntlWrapper, + "SfxColumnDateTimeItem::GetPresentation():" + " Using default en_US IntlWrapper"); + + ::com::sun::star::lang::Locale aLocale; + if (GetDateTime() == DateTime(Date(1, 2, 3), Time(3, 2, 1))) + rText = String(SvtResId(STR_COLUM_DT_AUTO, + pIntlWrapper ? + pIntlWrapper->getLocale() : + aLocale)); + else if (pIntlWrapper) + { + rText = pIntlWrapper->getLocaleData()->getDate(GetDateTime()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += pIntlWrapper->getLocaleData()->getTime(GetDateTime()); + } + else + { + const IntlWrapper aIntlWrapper( + ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US ); + rText = aIntlWrapper.getLocaleData()->getDate(GetDateTime()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += aIntlWrapper.getLocaleData()->getTime(GetDateTime()); + } + return SFX_ITEM_PRESENTATION_NAMELESS; +} + + + diff --git a/svl/source/items/dtritem.cxx b/svl/source/items/dtritem.cxx new file mode 100644 index 000000000000..fa3a36b762f5 --- /dev/null +++ b/svl/source/items/dtritem.cxx @@ -0,0 +1,244 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dtritem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/util/DateTimeRange.hpp> + +#include <unotools/intlwrapper.hxx> +#include <comphelper/processfactory.hxx> + +#include <tools/stream.hxx> +#include <tools/debug.hxx> +#include <tools/datetime.hxx> +#include <rtl/math.hxx> + +#include <vcl/svapp.hxx> + +#include <svtools/dtritem.hxx> + + +DBG_NAME( SfxDateTimeRangeItem ) +TYPEINIT1( SfxDateTimeRangeItem, SfxPoolItem ); + +// ----------------------------------------------------------------------- + +SfxDateTimeRangeItem::SfxDateTimeRangeItem( USHORT which ) : + SfxPoolItem( which ) +{ + DBG_CTOR( SfxDateTimeRangeItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxDateTimeRangeItem::SfxDateTimeRangeItem( USHORT which, const DateTime& rStartDT, + const DateTime& rEndDT ) : + SfxPoolItem( which ), + aStartDateTime( rStartDT ), + aEndDateTime( rEndDT ) +{ + DBG_CTOR( SfxDateTimeRangeItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxDateTimeRangeItem::SfxDateTimeRangeItem( const SfxDateTimeRangeItem& rItem ) : + SfxPoolItem( rItem ), + aStartDateTime( rItem.aStartDateTime ), + aEndDateTime( rItem.aEndDateTime ) +{ + DBG_CTOR( SfxDateTimeRangeItem, 0 ); +} + +// ----------------------------------------------------------------------- + +int SfxDateTimeRangeItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS( SfxDateTimeRangeItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + return ((SfxDateTimeRangeItem&)rItem ).aStartDateTime == aStartDateTime && + ((SfxDateTimeRangeItem&)rItem ).aEndDateTime == aEndDateTime; +} + +// ----------------------------------------------------------------------- + +int SfxDateTimeRangeItem::Compare( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS( SfxDateTimeRangeItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + double fThisRange = aEndDateTime - aStartDateTime; + double fRange = ((const SfxDateTimeRangeItem&)rItem).aEndDateTime - + ((const SfxDateTimeRangeItem&)rItem).aStartDateTime; + + if ( ::rtl::math::approxEqual( fRange, fThisRange ) ) + return 0; + else if ( fRange < fThisRange ) + return -1; + else + return 1; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxDateTimeRangeItem::Create( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxDateTimeRangeItem, 0); + + sal_uInt32 nStartDate, nEndDate; + sal_Int32 nStartTime, nEndTime; + + rStream >> nStartDate; + rStream >> nStartTime; + + rStream >> nEndDate; + rStream >> nEndTime; + + DateTime aStartDT, aEndDT; + + aStartDT.SetDate( nStartDate ); + aStartDT.SetTime( nStartTime ); + + aEndDT.SetDate( nEndDate ); + aEndDT.SetTime( nEndTime ); + + return new SfxDateTimeRangeItem( Which(), aStartDT, aEndDT ); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxDateTimeRangeItem::Store( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS( SfxDateTimeRangeItem, 0 ); + + rStream << aStartDateTime.GetDate(); + rStream << aStartDateTime.GetTime(); + + rStream << aEndDateTime.GetDate(); + rStream << aEndDateTime.GetTime(); + + return rStream; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxDateTimeRangeItem::Clone( SfxItemPool* ) const +{ + DBG_CHKTHIS( SfxDateTimeRangeItem, 0 ); + + return new SfxDateTimeRangeItem( *this ); +} +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxDateTimeRangeItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * pIntlWrapper +) const +{ + DBG_CHKTHIS(SfxDateTimeRangeItem, 0); + DateTime aRange(aEndDateTime - (const Time&)aStartDateTime); + if (pIntlWrapper) + { + rText = pIntlWrapper->getLocaleData()->getDate(aRange); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += pIntlWrapper->getLocaleData()->getTime(aRange); + } + else + { + DBG_WARNING("SfxDateTimeRangeItem::GetPresentation():" + " Using default en_US IntlWrapper"); + const IntlWrapper aIntlWrapper( + ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US ); + rText = aIntlWrapper.getLocaleData()->getDate(aRange); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += aIntlWrapper.getLocaleData()->getTime(aRange); + } + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxDateTimeRangeItem::PutValue( const com::sun::star::uno::Any& rVal,BYTE ) +{ + com::sun::star::util::DateTimeRange aValue; + if ( rVal >>= aValue ) + { + aStartDateTime = DateTime( Date( aValue.StartDay, + aValue.StartMonth, + aValue.StartYear ), + Time( aValue.StartHours, + aValue.StartMinutes, + aValue.StartSeconds, + aValue.StartHundredthSeconds ) ); + aEndDateTime = DateTime( Date( aValue.EndDay, + aValue.EndMonth, + aValue.EndYear ), + Time( aValue.EndHours, + aValue.EndMinutes, + aValue.EndSeconds, + aValue.EndHundredthSeconds ) ); + return TRUE; + } + + DBG_ERROR( "SfxDateTimeRangeItem::PutValue - Wrong type!" ); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxDateTimeRangeItem::QueryValue( com::sun::star::uno::Any& rVal, + BYTE nMemberId ) const +{ + nMemberId &= ~CONVERT_TWIPS; + com::sun::star::util::DateTimeRange aValue( aStartDateTime.Get100Sec(), + aStartDateTime.GetSec(), + aStartDateTime.GetMin(), + aStartDateTime.GetHour(), + aStartDateTime.GetDay(), + aStartDateTime.GetMonth(), + aStartDateTime.GetYear(), + aEndDateTime.Get100Sec(), + aEndDateTime.GetSec(), + aEndDateTime.GetMin(), + aEndDateTime.GetHour(), + aEndDateTime.GetDay(), + aEndDateTime.GetMonth(), + aEndDateTime.GetYear() ); + rVal <<= aValue; + return TRUE; +} + + diff --git a/svl/source/items/eitem.cxx b/svl/source/items/eitem.cxx new file mode 100644 index 000000000000..f7b95665391d --- /dev/null +++ b/svl/source/items/eitem.cxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: eitem.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <svtools/eitem.hxx> +//============================================================================ +// +// class SfxEnumItem +// +//============================================================================ + +TYPEINIT1(SfxEnumItem, CntEnumItem); + +//============================================================================ +// +// class SfxBoolItem +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(SfxBoolItem, CntBoolItem); + + diff --git a/svl/source/items/flagitem.cxx b/svl/source/items/flagitem.cxx new file mode 100644 index 000000000000..e59f981c5afa --- /dev/null +++ b/svl/source/items/flagitem.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: flagitem.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/flagitem.hxx> +#include <svtools/poolitem.hxx> +#include <tools/stream.hxx> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxFlagItem) + +USHORT nSfxFlagVal[16] = +{ + 0x0001, 0x0002, 0x0004, 0x0008, + 0x0010, 0x0020, 0x0040, 0x0080, + 0x0100, 0x0200, 0x0400, 0x0800, + 0x1000, 0x2000, 0x4000, 0x8000 +}; + + +// ----------------------------------------------------------------------- + +TYPEINIT1(SfxFlagItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxFlagItem::SfxFlagItem( USHORT nW, USHORT nV ) : + SfxPoolItem( nW ), + nVal(nV) +{ + DBG_CTOR(SfxFlagItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxFlagItem::SfxFlagItem( USHORT nW, SvStream &rStream) : + SfxPoolItem( nW ) +{ + DBG_CTOR(SfxFlagItem, 0); + rStream >> nVal; +} + +// ----------------------------------------------------------------------- + +SfxFlagItem::SfxFlagItem( const SfxFlagItem& rItem ) : + SfxPoolItem( rItem ), + nVal( rItem.nVal ) +{ + DBG_CTOR(SfxFlagItem, 0); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxFlagItem::Store(SvStream &rStream, USHORT) const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + rStream << nVal; + return rStream; +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxFlagItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + rText.Erase(); + for ( BYTE nFlag = 0; nFlag < GetFlagCount(); ++nFlag ) + rText += XubString::CreateFromInt32( GetFlag(nFlag) ); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ----------------------------------------------------------------------- + +XubString SfxFlagItem::GetFlagText( BYTE ) const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + DBG_WARNING( "calling GetValueText(USHORT) on SfxFlagItem -- overload!" ); + return XubString(); +} + +// ----------------------------------------------------------------------- + +BYTE SfxFlagItem::GetFlagCount() const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + DBG_WARNING( "calling GetValueText(USHORT) on SfxFlagItem -- overload!" ); + return 0; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxFlagItem::Create(SvStream &, USHORT) const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + DBG_WARNING( "calling Create() on SfxFlagItem -- overload!" ); + return 0; +} + +// ----------------------------------------------------------------------- + +int SfxFlagItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + return (((SfxFlagItem&)rItem).nVal == nVal); +} + +// ----------------------------------------------------------------------- + +void SfxFlagItem::SetFlag( BYTE nFlag, int bVal ) +{ + if ( bVal ) + nVal |= nSfxFlagVal[nFlag]; + else + nVal &= ~nSfxFlagVal[nFlag]; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxFlagItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxFlagItem, 0); + return new SfxFlagItem( *this ); +} + + + + + diff --git a/svl/source/items/frqitem.cxx b/svl/source/items/frqitem.cxx new file mode 100644 index 000000000000..4068ef8f97f1 --- /dev/null +++ b/svl/source/items/frqitem.cxx @@ -0,0 +1,580 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: frqitem.cxx,v $ + * $Revision: 1.8.136.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#ifndef GCC +#endif + +#include <unotools/intlwrapper.hxx> + +#include <tools/stream.hxx> +#include <tools/debug.hxx> +#include <tools/datetime.hxx> + +#include <svtools/frqitem.hxx> + +DBG_NAME( SfxFrequencyItem ) + +TYPEINIT1( SfxFrequencyItem, SfxPoolItem ); + +#define MAX_GOTO 32000 + +#define DECL_SAVE_GOTO() \ + ULONG nSafetyMeasures = 0; + +#define SAVE_GOTO(tag) \ + if(nSafetyMeasures < MAX_GOTO) \ + { nSafetyMeasures++; goto tag; } + +// ----------------------------------------------------------------------- + +SfxFrequencyItem::SfxFrequencyItem( USHORT which ) : + SfxPoolItem ( which ), + eFrqMode ( FRQ_DAILY ), + eFrqTimeMode ( FRQ_TIME_AT ), + nDInterval1 ( 1 ), + nDInterval2 ( 0 ), + nDInterval3 ( 0 ), + nTInterval1 ( 1 ), + aTime1 ( Time( 12, 0, 0 ) ), + aTime2 ( Time( 12, 0, 0 ) ), + bMissingDate ( FALSE ), + aMissingDate ( DateTime(0, 0) ) +{ + DBG_CTOR( SfxFrequencyItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxFrequencyItem::SfxFrequencyItem( USHORT which, FrequencyMode eMode, FrequencyTimeMode eTMode, + USHORT nDI1, USHORT nDI2, USHORT nDI3, USHORT nTI1, + const Time& rT1, const Time& rT2 ) : + SfxPoolItem ( which ), + eFrqMode ( eMode ), + eFrqTimeMode ( eTMode ), + nDInterval1 ( nDI1 ), + nDInterval2 ( nDI2 ), + nDInterval3 ( nDI3 ), + nTInterval1 ( nTI1 ), + aTime1 ( rT1 ), + aTime2 ( rT2 ), + bMissingDate ( FALSE ) +{ + DBG_CTOR( SfxFrequencyItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxFrequencyItem::SfxFrequencyItem( const SfxFrequencyItem& rItem ) : + SfxPoolItem ( rItem ), + eFrqMode ( rItem.eFrqMode ), + eFrqTimeMode ( rItem.eFrqTimeMode ), + nDInterval1 ( rItem.nDInterval1 ), + nDInterval2 ( rItem.nDInterval2 ), + nDInterval3 ( rItem.nDInterval3 ), + nTInterval1 ( rItem.nTInterval1 ), + aTime1 ( rItem.aTime1 ), + aTime2 ( rItem.aTime2 ), + bMissingDate ( rItem.bMissingDate ) +{ + DBG_CTOR( SfxFrequencyItem, 0 ); +} + +// ----------------------------------------------------------------------- + +int SfxFrequencyItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS( SfxFrequencyItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + return ((SfxFrequencyItem&)rItem ).eFrqMode == eFrqMode && + ((SfxFrequencyItem&)rItem ).eFrqTimeMode == eFrqTimeMode && + ((SfxFrequencyItem&)rItem ).nDInterval1 == nDInterval1 && + ((SfxFrequencyItem&)rItem ).nDInterval2 == nDInterval2 && + ((SfxFrequencyItem&)rItem ).nDInterval3 == nDInterval3 && + ((SfxFrequencyItem&)rItem ).nTInterval1 == nTInterval1 && + ((SfxFrequencyItem&)rItem ).aTime1 == aTime1 && + ((SfxFrequencyItem&)rItem ).aTime2 == aTime2; +} + +// ----------------------------------------------------------------------- + +int SfxFrequencyItem::Compare( const SfxPoolItem& +#ifdef DBG_UTIL +rItem +#endif +) const +{ + DBG_CHKTHIS( SfxFrequencyItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + +/* DateTime aThisRange( aEndDateTime - aStartDateTime ); + DateTime aRange(((const SfxFrequencyItem&)rItem).aEndDateTime - + ((const SfxFrequencyItem&)rItem).aStartDateTime ); + if( aRange < aThisRange ) + return -1; + else if( aRange == aThisRange ) + return 0; + else +*/ + return 1; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxFrequencyItem::Create( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxFrequencyItem, 0); + + USHORT _eFrqMode; + USHORT _eFrqTimeMode; + USHORT _nDInterval1; + USHORT _nDInterval2; + USHORT _nDInterval3; + USHORT _nTInterval1; + long _nTime1; + long _nTime2; + + rStream >> _eFrqMode; + rStream >> _eFrqTimeMode; + rStream >> _nDInterval1; + rStream >> _nDInterval2; + rStream >> _nDInterval3; + rStream >> _nTInterval1; + rStream >> _nTime1; + rStream >> _nTime2; + + return new SfxFrequencyItem( Which(), (FrequencyMode)_eFrqMode, + (FrequencyTimeMode) _eFrqTimeMode, _nDInterval1, _nDInterval2, _nDInterval3, + _nTInterval1, Time(_nTime1), Time(_nTime2) ); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxFrequencyItem::Store( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS( SfxFrequencyItem, 0 ); + + USHORT nEMode = (USHORT)eFrqMode; + USHORT nETimeMode = (USHORT)eFrqTimeMode; + + rStream << (USHORT) nEMode; + rStream << (USHORT) nETimeMode; + + rStream << nDInterval1; + rStream << nDInterval2; + rStream << nDInterval3; + + rStream << nTInterval1; + rStream << aTime1.GetTime(); + rStream << aTime2.GetTime(); + + return rStream; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxFrequencyItem::Clone( SfxItemPool* ) const +{ + DBG_CHKTHIS( SfxFrequencyItem, 0 ); + return new SfxFrequencyItem( *this ); +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxFrequencyItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxFrequencyItem, 0); + rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("SNIY")); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ----------------------------------------------------------------------- + +Time SfxFrequencyItem::_CalcTime( BOOL bForToday ) const +{ + Time aNow; + Time aTime; + + DECL_SAVE_GOTO(); + + switch( eFrqTimeMode ) + { + ////////////////////////////////////////////////////////// + // FRQ_TIME_AT + // + // Update um Uhrzeit + // nTime1 = 00:00:00 - 24:00:00 + // + case FRQ_TIME_AT : + aTime = aTime1; + break; + + ////////////////////////////////////////////////////////// + // FRQ_TIME_REPEAT + // + // Wiederhole alle X Stunden + // nTInterval1 = 1 .. 8 + // + case FRQ_TIME_REPEAT : + aTime = Time( 0, 0 ); + if( bForToday ) + { + + RECALC_TIME_REPEAT: + if( aNow > aTime ) + { + aTime += Time( nTInterval1, 0 ); + SAVE_GOTO( RECALC_TIME_REPEAT ); + } + break; + } + break; + + ////////////////////////////////////////////////////////// + // FRQ_TIME_REPEAT_RANGE + // + // FRQ_TIME_REPEAT zwischen Uhrzeit 1 und 2 + // nTime1 = 00:00:00 - 24:00:00 + // nTime2 = 00:00:00 - 24:00:00 + // + case FRQ_TIME_REPEAT_RANGE : + aTime = aTime1; + if( bForToday ) + { + if( aNow > aTime2 ) + return aTime1; + + RECALC_TIME_REPEAT_RANGE: + if( aNow > aTime ) + { + aTime += Time( nTInterval1, 0 ); + if( aTime > aTime2 ) + return aTime1; + SAVE_GOTO( RECALC_TIME_REPEAT_RANGE ); + } + break; + } + break; + } + return aTime; +} + +DateTime SfxFrequencyItem::CalcNextTick( const DateTime& rBase, BOOL bFirst ) +{ + Date aDateToday; + Time aTimeToday; + Date aDateBase; + Time aTimeBase; + + if( bFirst ) + { + aDateBase = Date( 17, 2, 1969 ); + aTimeBase = Time( 8, 0, 0 ); + } + else + { + aDateBase = rBase.GetDate(); + aTimeBase = rBase.GetTime(); + } + + Time aNextTime( _CalcTime(FALSE) ); + Date aNextDate( aDateBase ); + bMissingDate = FALSE; + + DECL_SAVE_GOTO(); + + switch( eFrqMode ) + { + ////////////////////////////////////////////////////////// + // FRQ_DAILY + // + // jeden X'ten Tag + // nInterval1 = 1 .. 999 + // + // jeden Wochentag + // nInterval1 = USHRT_MAX + // + case FRQ_DAILY : + { + if( bFirst ) + { + aNextTime = _CalcTime( TRUE ); + if( aNextTime < aTimeToday ) + { + aNextTime = _CalcTime( FALSE ); + aNextDate = aDateToday + (USHORT) + ((nDInterval1 == USHRT_MAX)? 1 : nDInterval1); + } + else + aNextDate = aDateToday; + break; + } + + RECALC_FRQ_DAILY: + if( aNextDate < aDateToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + aNextDate += (USHORT)((nDInterval1 == USHRT_MAX)? 1 : nDInterval1); + SAVE_GOTO( RECALC_FRQ_DAILY ); + } + + if( aNextDate == aDateToday ) + { + aNextTime = _CalcTime( TRUE ); + if( aNextTime < aTimeToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + aNextDate += (USHORT)((nDInterval1 == USHRT_MAX)? 1 : nDInterval1); + aNextTime = _CalcTime( FALSE ); + } + } + else + aNextTime = _CalcTime( FALSE ); + } break; + + ////////////////////////////////////////////////////////// + // FRQ_WEEKLY + // wiederhole jede X'te Woche + // nInterval1 = 1 .. 99 + // + // an SU, MO, TU, WE, TH, FR, SA + // nInterval2 = WD_SUNDAY | WD_MONDAY | WD_TUESDAY | + // WD_WEDNESDAY | WD_THURSDAY | WD_FRIDAY | + // WD_SATURDAY + // + case FRQ_WEEKLY : + { + BOOL bInRecalc = FALSE; + + RECALC_FRQ_WEEKLY: + if( !bFirst || bInRecalc ) + aNextDate += (nDInterval1 - 1) * 7; + + aNextDate -= (USHORT) ((aNextDate.GetDayOfWeek() != SUNDAY) ? + aNextDate.GetDayOfWeek() + 1 : 0); + + if( nDInterval2 & WD_SUNDAY && (aNextDate >= aDateToday) ) + aNextDate += 0; + else if( nDInterval2 & WD_MONDAY && (aNextDate + 1 >= aDateToday) ) + aNextDate += 1; + else if( nDInterval2 & WD_TUESDAY && (aNextDate + 2 >= aDateToday) ) + aNextDate += 2; + else if( nDInterval2 & WD_WEDNESDAY && (aNextDate + 3 >= aDateToday) ) + aNextDate += 3; + else if( nDInterval2 & WD_THURSDAY && (aNextDate + 4 >= aDateToday) ) + aNextDate += 4; + else if( nDInterval2 & WD_FRIDAY && (aNextDate + 5 >= aDateToday) ) + aNextDate += 5; + else if( nDInterval2 & WD_SATURDAY && (aNextDate + 6 >= aDateToday) ) + aNextDate += 6; + + if( aNextDate < aDateToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + bInRecalc = TRUE; + aNextDate += 7; + SAVE_GOTO( RECALC_FRQ_WEEKLY ); + } + if( aNextDate == aDateToday ) + { + aNextTime = _CalcTime( TRUE ); + if( aNextTime < aTimeToday ) + { + bInRecalc = TRUE; + aNextDate += 7; + SAVE_GOTO( RECALC_FRQ_WEEKLY ); + } + } + else + aNextTime = _CalcTime( FALSE ); + } break; + + ////////////////////////////////////////////////////////// + // FRQ_MONTHLY_DAILY + // + // jeden X'ten Tag von jedem X'ten Monat + // nInterval1 = 1 .. 31 + // nInterval2 = 1 .. 6 + // + case FRQ_MONTHLY_DAILY : + { + BOOL bInRecalc = FALSE; + aNextDate.SetDay( nDInterval1 ); + + RECALC_FRQ_MONTHLY_DAILY: + if( nDInterval2 > 1 || bInRecalc ) + { + long nMonth = aNextDate.GetMonth() - 1; + nMonth += nDInterval2; + aNextDate.SetYear( + sal::static_int_cast< USHORT >( + aNextDate.GetYear() + nMonth / 12 ) ); + aNextDate.SetMonth( + sal::static_int_cast< USHORT >( ( nMonth % 12 ) + 1 ) ); + } + + if( aNextDate < aDateToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + bInRecalc = TRUE; + SAVE_GOTO( RECALC_FRQ_MONTHLY_DAILY ); + } + + if( aNextDate == aDateToday ) + { + aNextTime = _CalcTime( TRUE ); + if( aNextTime < aTimeToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + bInRecalc = TRUE; + SAVE_GOTO( RECALC_FRQ_MONTHLY_DAILY ); + } + } + else + aNextTime = _CalcTime( FALSE ); + } break; + + ////////////////////////////////////////////////////////// + // FRQ_MONTHLY_LOGIC + // + // jeden ersten, zweiten, dritten, vierten oder letzten + // Wochentag jeden X'ten Monats + // nInterval1 = 0 .. 4 + // nInterval2 = WD_SUNDAY | WD_MONDAY | WD_TUESDAY | + // WD_WEDNESDAY | WD_THURSDAY | WD_FRIDAY | + // WD_SATURDAY + // nInterval3 = 1 .. 6 + // + case FRQ_MONTHLY_LOGIC : + { + BOOL bInRecalc = FALSE; + + RECALC_FRQ_MONTHLY_LOGIC: + if( nDInterval3 > 1 || bInRecalc ) + { + long nMonth = aNextDate.GetMonth() - 1; + nMonth += nDInterval3; + aNextDate.SetYear( + sal::static_int_cast< USHORT >( + aNextDate.GetYear() + nMonth / 12 ) ); + aNextDate.SetMonth( + sal::static_int_cast< USHORT >( ( nMonth % 12 ) + 1 ) ); + } + + USHORT nDay; + if( nDInterval2 & WD_SUNDAY ) + nDay = 6; + else if( nDInterval2 & WD_MONDAY ) + nDay = 0; + else if( nDInterval2 & WD_TUESDAY ) + nDay = 1; + else if( nDInterval2 & WD_WEDNESDAY ) + nDay = 2; + else if( nDInterval2 & WD_THURSDAY ) + nDay = 3; + else if( nDInterval2 & WD_FRIDAY ) + nDay = 4; + else nDay = 5; + + if( nDInterval1 == 4 ) + { + DateTime aDT = aNextDate; + aDT.SetDay( 1 ); + aDT += (long)(aNextDate.GetDaysInMonth() - 1); + if( aDT.GetDayOfWeek() != nDay ) + for( aDT--; aDT.GetDayOfWeek() != nDay; aDT-- ) ; + aNextDate = aDT; + } + else + { + DateTime aDT = aNextDate; + aDT.SetDay( 1 ); + aDT += (long)(nDay - USHORT(aDT.GetDayOfWeek())); + if( aDT.GetMonth() != aNextDate.GetMonth() ) + aDT += 7L; + aDT += (long)(nDInterval1 * 7); + aNextDate = aDT; + } + + if( aNextDate < aDateToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + bInRecalc = TRUE; + SAVE_GOTO( RECALC_FRQ_MONTHLY_LOGIC ); + } + + if( aNextDate == aDateToday ) + { + aNextTime = _CalcTime( TRUE ); + if( aNextTime < aTimeToday ) + { + bMissingDate = TRUE; + aMissingDate.SetDate(aNextDate.GetDate()); + aMissingDate.SetTime(_CalcTime(FALSE).GetTime()); + + bInRecalc = TRUE; + SAVE_GOTO( RECALC_FRQ_MONTHLY_LOGIC ); + } + } + else + aNextTime = _CalcTime( FALSE ); + } break; + } + + return DateTime( aNextDate, aNextTime ); +} + diff --git a/svl/source/items/globalnameitem.cxx b/svl/source/items/globalnameitem.cxx new file mode 100644 index 000000000000..6a8359fb39b8 --- /dev/null +++ b/svl/source/items/globalnameitem.cxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: globalnameitem.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/script/XTypeConverter.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <comphelper/processfactory.hxx> + +#include <svtools/globalnameitem.hxx> + +// STATIC DATA ----------------------------------------------------------- + + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxGlobalNameItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxGlobalNameItem::SfxGlobalNameItem() +{ +} + +// ----------------------------------------------------------------------- + +SfxGlobalNameItem::SfxGlobalNameItem( USHORT nW, const SvGlobalName& rName ) +: SfxPoolItem( nW ), + m_aName( rName ) +{ +} + +// ----------------------------------------------------------------------- + +SfxGlobalNameItem::~SfxGlobalNameItem() +{ +} + +// ----------------------------------------------------------------------- + +int SfxGlobalNameItem::operator==( const SfxPoolItem& rItem ) const +{ + return ((SfxGlobalNameItem&)rItem).m_aName == m_aName; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxGlobalNameItem::Clone(SfxItemPool *) const +{ + return new SfxGlobalNameItem( *this ); +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxGlobalNameItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE ) +{ + com::sun::star::uno::Reference < com::sun::star::script::XTypeConverter > xConverter + ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), + com::sun::star::uno::UNO_QUERY ); + com::sun::star::uno::Sequence< sal_Int8 > aSeq; + com::sun::star::uno::Any aNew; + + try { aNew = xConverter->convertTo( rVal, ::getCppuType((const com::sun::star::uno::Sequence < sal_Int8 >*)0) ); } + catch (com::sun::star::uno::Exception&) {} + aNew >>= aSeq; + if ( aSeq.getLength() == 16 ) + { + m_aName.MakeFromMemory( (void*) aSeq.getConstArray() ); + return TRUE; + } + + DBG_ERROR( "SfxGlobalNameItem::PutValue - Wrong type!" ); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxGlobalNameItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const +{ + com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); + void* pData = ( void* ) &m_aName.GetCLSID(); + memcpy( aSeq.getArray(), pData, 16 ); + rVal <<= aSeq; + return TRUE; +} + diff --git a/svl/source/items/ilstitem.cxx b/svl/source/items/ilstitem.cxx new file mode 100644 index 000000000000..a26c054eeadb --- /dev/null +++ b/svl/source/items/ilstitem.cxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ilstitem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/script/XTypeConverter.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <comphelper/processfactory.hxx> + +#include <svtools/ilstitem.hxx> + +#define _SVSTDARR_ULONGS +#include <svtools/svstdarr.hxx> + +TYPEINIT1_AUTOFACTORY(SfxIntegerListItem, SfxPoolItem); + +SfxIntegerListItem::SfxIntegerListItem() +{ +} + +SfxIntegerListItem::SfxIntegerListItem( USHORT which, const SvULongs& rList ) + : SfxPoolItem( which ) +{ + m_aList.realloc( rList.Count() ); + for ( USHORT n=0; n<rList.Count(); n++ ) + m_aList[n] = rList[n]; +} + +SfxIntegerListItem::SfxIntegerListItem( const SfxIntegerListItem& rItem ) + : SfxPoolItem( rItem ) +{ + m_aList = rItem.m_aList; +} + +SfxIntegerListItem::~SfxIntegerListItem() +{ +} + +int SfxIntegerListItem::operator==( const SfxPoolItem& rPoolItem ) const +{ + if ( !rPoolItem.ISA( SfxIntegerListItem ) ) + return FALSE; + + const SfxIntegerListItem rItem = (const SfxIntegerListItem&) rPoolItem; + return rItem.m_aList == m_aList; +} + +SfxPoolItem* SfxIntegerListItem::Clone( SfxItemPool * ) const +{ + return new SfxIntegerListItem( *this ); +} + +BOOL SfxIntegerListItem::PutValue ( const com::sun::star::uno::Any& rVal, BYTE ) +{ + ::com::sun::star::uno::Reference < ::com::sun::star::script::XTypeConverter > xConverter + ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), + ::com::sun::star::uno::UNO_QUERY ); + ::com::sun::star::uno::Any aNew; + try { aNew = xConverter->convertTo( rVal, ::getCppuType((const ::com::sun::star::uno::Sequence < sal_Int32 >*)0) ); } + catch (::com::sun::star::uno::Exception&) + { + return FALSE; + } + + return ( aNew >>= m_aList ); +} + +BOOL SfxIntegerListItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const +{ + rVal <<= m_aList; + return TRUE; +} + +void SfxIntegerListItem::GetList( SvULongs& rList ) const +{ + for ( sal_Int32 n=0; n<m_aList.getLength(); n++ ) + rList.Insert( m_aList[n], sal::static_int_cast< USHORT >(n) ); +} diff --git a/svl/source/items/imageitm.cxx b/svl/source/items/imageitm.cxx new file mode 100644 index 000000000000..cc4a2ebd4f3b --- /dev/null +++ b/svl/source/items/imageitm.cxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: imageitm.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/imageitm.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +TYPEINIT1( SfxImageItem, SfxInt16Item ); + +struct SfxImageItem_Impl +{ + String aURL; + long nAngle; + BOOL bMirrored; + int operator == ( const SfxImageItem_Impl& rOther ) const + { return nAngle == rOther.nAngle && bMirrored == rOther.bMirrored; } +}; + +//--------------------------------------------------------- + +SfxImageItem::SfxImageItem( USHORT which, UINT16 nImage ) + : SfxInt16Item( which, nImage ) +{ + pImp = new SfxImageItem_Impl; + pImp->nAngle = 0; + pImp->bMirrored = FALSE; +} + +SfxImageItem::SfxImageItem( USHORT which, const String& rURL ) + : SfxInt16Item( which, 0 ) +{ + pImp = new SfxImageItem_Impl; + pImp->nAngle = 0; + pImp->bMirrored = FALSE; + pImp->aURL = rURL; +} + +SfxImageItem::SfxImageItem( const SfxImageItem& rItem ) + : SfxInt16Item( rItem ) +{ + pImp = new SfxImageItem_Impl( *(rItem.pImp) ); +} + +//--------------------------------------------------------- +SfxImageItem::~SfxImageItem() +{ + delete pImp; +} + +//--------------------------------------------------------- + +SfxPoolItem* SfxImageItem::Clone( SfxItemPool* ) const +{ + return new SfxImageItem( *this ); +} + +//--------------------------------------------------------- + +int SfxImageItem::operator==( const SfxPoolItem& rItem ) const +{ + return( ((SfxImageItem&) rItem).GetValue() == GetValue() && (*pImp == *(((SfxImageItem&)rItem).pImp) ) ); +} + +BOOL SfxImageItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE ) const +{ + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq( 4 ); + aSeq[0] = ::com::sun::star::uno::makeAny( GetValue() ); + aSeq[1] = ::com::sun::star::uno::makeAny( pImp->nAngle ); + aSeq[2] = ::com::sun::star::uno::makeAny( pImp->bMirrored ); + aSeq[3] = ::com::sun::star::uno::makeAny( rtl::OUString( pImp->aURL )); + + rVal = ::com::sun::star::uno::makeAny( aSeq ); + return TRUE; +} + +BOOL SfxImageItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE ) +{ + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq; + if (( rVal >>= aSeq ) && ( aSeq.getLength() == 4 )) + { + sal_Int16 nVal = sal_Int16(); + rtl::OUString aURL; + if ( aSeq[0] >>= nVal ) + SetValue( nVal ); + aSeq[1] >>= pImp->nAngle; + aSeq[2] >>= pImp->bMirrored; + if ( aSeq[3] >>= aURL ) + pImp->aURL = aURL; + return TRUE; + } + + return FALSE; +} + +void SfxImageItem::SetRotation( long nValue ) +{ + pImp->nAngle = nValue; +} + +long SfxImageItem::GetRotation() const +{ + return pImp->nAngle; +} + +void SfxImageItem::SetMirrored( BOOL bSet ) +{ + pImp->bMirrored = bSet; +} + +BOOL SfxImageItem::IsMirrored() const +{ + return pImp->bMirrored; +} + +String SfxImageItem::GetURL() const +{ + return pImp->aURL; +} + diff --git a/svl/source/items/intitem.cxx b/svl/source/items/intitem.cxx new file mode 100644 index 000000000000..b20f245f964b --- /dev/null +++ b/svl/source/items/intitem.cxx @@ -0,0 +1,261 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: intitem.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/intitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <tools/bigint.hxx> +#include <tools/stream.hxx> +#include <svtools/metitem.hxx> + +//============================================================================ +// +// class SfxByteItem +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem); + +//============================================================================ +// virtual +SfxPoolItem * SfxByteItem::Create(SvStream & rStream, USHORT) const +{ + short nValue = 0; + rStream >> nValue; + return new SfxByteItem(Which(), BYTE(nValue)); +} + +//============================================================================ +// +// class SfxInt16Item +// +//============================================================================ + +DBG_NAME(SfxInt16Item); + +//============================================================================ +TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem); + +//============================================================================ +SfxInt16Item::SfxInt16Item(USHORT which, SvStream & rStream): + SfxPoolItem(which) +{ + DBG_CTOR(SfxInt16Item, 0); + short nTheValue = 0; + rStream >> nTheValue; + m_nValue = nTheValue; +} + +//============================================================================ +// virtual +int SfxInt16Item::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type"); + return m_nValue == SAL_STATIC_CAST(const SfxInt16Item *, &rItem)-> + m_nValue; +} + +//============================================================================ +// virtual +int SfxInt16Item::Compare(const SfxPoolItem & rWith) const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type"); + return SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue + < m_nValue ? + -1 : + SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue + == m_nValue ? + 0 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation SfxInt16Item::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + XubString & rText, + const IntlWrapper *) const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + rText = UniString::CreateFromInt32(m_nValue); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + + +//============================================================================ +// virtual +BOOL SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, BYTE) const +{ + sal_Int16 nValue = m_nValue; + rVal <<= nValue; + return TRUE; +} + +//============================================================================ +// virtual +BOOL SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, BYTE ) +{ + sal_Int16 nValue = sal_Int16(); + if (rVal >>= nValue) + { + m_nValue = nValue; + return TRUE; + } + + DBG_ERROR( "SfxInt16Item::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + return new SfxInt16Item(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & SfxInt16Item::Store(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + rStream << short(m_nValue); + return rStream; +} + +//============================================================================ +SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + return new SfxInt16Item(*this); +} + +//============================================================================ +INT16 SfxInt16Item::GetMin() const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + return -32768; +} + +//============================================================================ +INT16 SfxInt16Item::GetMax() const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + return 32767; +} + +//============================================================================ +SfxFieldUnit SfxInt16Item::GetUnit() const +{ + DBG_CHKTHIS(SfxInt16Item, 0); + return SFX_FUNIT_NONE; +} + +//============================================================================ +// +// class SfxUInt16Item +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item); + + +//============================================================================ +// +// class SfxInt32Item +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item); + + +//============================================================================ +// +// class SfxUInt32Item +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item); + + +//============================================================================ +// +// class SfxMetricItem +// +//============================================================================ + +DBG_NAME(SfxMetricItem); + +//============================================================================ +TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item); + +//============================================================================ +SfxMetricItem::SfxMetricItem(USHORT which, UINT32 nValue): + SfxInt32Item(which, nValue) +{ + DBG_CTOR(SfxMetricItem, 0); +} + +//============================================================================ +SfxMetricItem::SfxMetricItem(USHORT which, SvStream & rStream): + SfxInt32Item(which, rStream) +{ + DBG_CTOR(SfxMetricItem, 0); +} + +//============================================================================ +SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem): + SfxInt32Item(rItem) +{ + DBG_CTOR(SfxMetricItem, 0); +} + +//============================================================================ +// virtual +int SfxMetricItem::ScaleMetrics(long nMult, long nDiv) +{ + BigInt aTheValue(GetValue()); + aTheValue *= nMult; + aTheValue += nDiv / 2; + aTheValue /= nDiv; + SetValue(aTheValue); + return 1; +} + +//============================================================================ +// virtual +int SfxMetricItem::HasMetrics() const +{ + return 1; +} + diff --git a/svl/source/items/itemiter.cxx b/svl/source/items/itemiter.cxx new file mode 100644 index 000000000000..9a7fa4d72c88 --- /dev/null +++ b/svl/source/items/itemiter.cxx @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: itemiter.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#ifndef GCC +#endif + +#include <svtools/itemiter.hxx> +#include <svtools/itempool.hxx> +#include <svtools/itemset.hxx> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxItemIter); + + +// -------------------------------------------------------------------------- + + +SfxItemIter::SfxItemIter( const SfxItemSet& rItemSet ) + : _rSet( rItemSet ) +{ + DBG_CTOR(SfxItemIter, 0); + DBG_ASSERTWARNING( _rSet.Count(), "es gibt gar keine Attribute" ); + + if ( !_rSet._nCount ) + { + _nStt = 1; + _nEnd = 0; + } + else + { + SfxItemArray ppFnd = _rSet._aItems; + + // suche das 1. gesetzte Item + for ( _nStt = 0; !*(ppFnd + _nStt ); ++_nStt ) + ; // empty loop + if ( 1 < _rSet.Count() ) + for( _nEnd = _rSet.TotalCount(); !*( ppFnd + --_nEnd); ) + ; // empty loop + else + _nEnd = _nStt; + } + + _nAkt = _nStt; +} + +// -------------------------------------------------------------------------- + + +SfxItemIter::~SfxItemIter() +{ + DBG_DTOR(SfxItemIter, 0); +} + +// -------------------------------------------------------------------------- + + +const SfxPoolItem* SfxItemIter::NextItem() +{ + DBG_CHKTHIS(SfxItemIter, 0); + SfxItemArray ppFnd = _rSet._aItems; + + if( _nAkt < _nEnd ) + { + do { + _nAkt++; + } while( _nAkt < _nEnd && !*(ppFnd + _nAkt ) ); + return *(ppFnd+_nAkt); + } + return 0; +} + +// -------------------------------------------------------------------------- + + +const SfxPoolItem* SfxItemIter::PrevItem() +{ + DBG_CHKTHIS(SfxItemIter, 0); + SfxItemArray ppFnd = _rSet._aItems; + + if ( _nAkt > _nStt ) + { + do { + --_nAkt; + } while( _nAkt && !*(ppFnd + _nAkt )); + return *(ppFnd+_nAkt); + } + return 0; +} + + + diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx new file mode 100644 index 000000000000..823658132fe0 --- /dev/null +++ b/svl/source/items/itempool.cxx @@ -0,0 +1,1176 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: itempool.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <string.h> +#include <stdio.h> +#ifndef GCC +#endif + +#include <svtools/itempool.hxx> +#include "whassert.hxx" +#include <svtools/brdcst.hxx> +#include <svtools/smplhint.hxx> +#include "poolio.hxx" +#include <algorithm> + +// STATIC DATA ----------------------------------------------------------- + + +//======================================================================== + +SV_IMPL_PTRARR( SfxPoolVersionArr_Impl, SfxPoolVersion_Impl* ); + +//======================================================================== + + +void SfxItemPool::AddSfxItemPoolUser(SfxItemPoolUser& rNewUser) +{ + maSfxItemPoolUsers.push_back(&rNewUser); +} + +void SfxItemPool::RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser) +{ + const SfxItemPoolUserVector::iterator aFindResult = ::std::find(maSfxItemPoolUsers.begin(), maSfxItemPoolUsers.end(), &rOldUser); + if(aFindResult != maSfxItemPoolUsers.end()) + { + maSfxItemPoolUsers.erase(aFindResult); + } +} + +const SfxPoolItem* SfxItemPool::GetPoolDefaultItem( USHORT nWhich ) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + const SfxPoolItem* pRet; + if( IsInRange( nWhich ) ) + pRet = *(ppPoolDefaults + GetIndex_Impl( nWhich )); + else if( pSecondary ) + pRet = pSecondary->GetPoolDefaultItem( nWhich ); + else + { + SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get pool default" ); + pRet = 0; + } + return pRet; +} + +// ----------------------------------------------------------------------- + +inline FASTBOOL SfxItemPool::IsItemFlag_Impl( USHORT nPos, USHORT nFlag ) const +{ + USHORT nItemFlag = pItemInfos[nPos]._nFlags; + return nFlag == (nItemFlag & nFlag); +} + +// ----------------------------------------------------------------------- + +FASTBOOL SfxItemPool::IsItemFlag( USHORT nWhich, USHORT nFlag ) const +{ + for ( const SfxItemPool *pPool = this; pPool; pPool = pPool->pSecondary ) + { + if ( pPool->IsInRange(nWhich) ) + return pPool->IsItemFlag_Impl( pPool->GetIndex_Impl(nWhich), nFlag); + } + DBG_ASSERT( !IsWhich(nWhich), "unknown which-id" ); + return FALSE; +} + +// ----------------------------------------------------------------------- + +SfxBroadcaster& SfxItemPool::BC() +{ + return pImp->aBC; +} + +// ----------------------------------------------------------------------- + + +SfxItemPool::SfxItemPool +( + UniString const & rName, /* Name des Pools zur Idetifikation + im File-Format */ + USHORT nStartWhich, /* erste Which-Id des Pools */ + USHORT nEndWhich, /* letzte Which-Id des Pools */ +#ifdef TF_POOLABLE + const SfxItemInfo* pInfos, /* SID-Map und Item-Flags */ +#endif + SfxPoolItem** pDefaults, /* Pointer auf statische Defaults, + wird direkt vom Pool referenziert, + jedoch kein Eigent"umer"ubergang */ +#ifndef TF_POOLABLE + USHORT* pSlotIdArray, /* Zuordnung von Slot-Ids zu Which-Ids */ +#endif + FASTBOOL bLoadRefCounts /* Ref-Counts mitladen oder auf 1 setzen */ +) + +/* [Beschreibung] + + Der im Normalfall verwendete Konstruktor der Klasse SfxItemPool. Es + wird eine SfxItemPool-Instanz initialisiert, die Items im b"undigen + Which-Bereich von 'nStartWhich' bis 'nEndWhich' verwalten kann. + + F"ur jede dieser Which-Ids mu\s ein statischer Default im Array 'pDefaults' + vorhanden sein, die dort beginnend mit einem <SfxPoolItem> mit der + Which-Id 'nStartWhich' nach Which-Ids sortiert aufeinanderfolgend + eingetragen sein m"ussen. + + 'pItemInfos' ist ein identisch angeordnetes Array von USHORTs, die + Slot-Ids darstellen und Flags. Die Slot-Ids k"onnen 0 sein, wenn die + betreffenden Items ausschlie\slich in der Core verwendet werden. + "Uber die Flags kann z.B. bestimmt werden, ob Value-Sharing + (SFX_ITEM_POOLABLE) stattfinden soll. + + [Anmerkung] + + Wenn der Pool <SfxSetItem>s enthalten soll, k"onnen im Konstruktor noch + keine static-Defaults angegeben werden. Dies mu\s dann nachtr"aglich + mit <SfxItemPool::SetDefaults(SfxItemPool**)> geschehen. + + + [Querverweise] + + <SfxItemPool::SetDefaults(SfxItemPool**)> + <SfxItemPool::ReleaseDefaults(SfxPoolItem**,USHORT,BOOL)> + <SfxItemPool::ReldaseDefaults(BOOL)> +*/ + +: aName(rName), + nStart(nStartWhich), + nEnd(nEndWhich), +#ifdef TF_POOLABLE + pItemInfos(pInfos), +#else + pSlotIds(pSlotIdArray), +#endif + pImp( new SfxItemPool_Impl( nStart, nEnd ) ), + ppStaticDefaults(0), + ppPoolDefaults(new SfxPoolItem* [ nEndWhich - nStartWhich + 1]), + pSecondary(0), + pMaster(this), + _pPoolRanges( 0 ), + bPersistentRefCounts(bLoadRefCounts), + maSfxItemPoolUsers() +{ + DBG_CTOR(SfxItemPool, 0); + DBG_ASSERT(nStart, "Start-Which-Id must be greater 0" ); + + pImp->eDefMetric = SFX_MAPUNIT_TWIP; + pImp->nVersion = 0; + pImp->bStreaming = FALSE; + pImp->nLoadingVersion = 0; + pImp->nInitRefCount = 1; + pImp->nVerStart = nStart; + pImp->nVerEnd = nEnd; + pImp->bInSetItem = FALSE; + pImp->nStoringStart = nStartWhich; + pImp->nStoringEnd = nEndWhich; + + memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1)); + + if ( pDefaults ) + SetDefaults(pDefaults); +} + +// ----------------------------------------------------------------------- + + +SfxItemPool::SfxItemPool +( + const SfxItemPool& rPool, // von dieser Instanz kopieren + BOOL bCloneStaticDefaults /* TRUE + statische Defaults kopieren + + FALSE + statische Defaults + "ubernehehmen */ +) + +/* [Beschreibung] + + Copy-Konstruktor der Klasse SfxItemPool. + + + [Querverweise] + + <SfxItemPool::Clone()const> +*/ + +: aName(rPool.aName), + nStart(rPool.nStart), + nEnd(rPool.nEnd), +#ifdef TF_POOLABLE + pItemInfos(rPool.pItemInfos), +#else + pSlotIds(rPool.pSlotIds), +#endif + pImp( new SfxItemPool_Impl( nStart, nEnd ) ), + ppStaticDefaults(0), + ppPoolDefaults(new SfxPoolItem* [ nEnd - nStart + 1]), + pSecondary(0), + pMaster(this), + _pPoolRanges( 0 ), + bPersistentRefCounts(rPool.bPersistentRefCounts ), + maSfxItemPoolUsers() +{ + DBG_CTOR(SfxItemPool, 0); + pImp->eDefMetric = rPool.pImp->eDefMetric; + pImp->nVersion = rPool.pImp->nVersion; + pImp->bStreaming = FALSE; + pImp->nLoadingVersion = 0; + pImp->nInitRefCount = 1; + pImp->nVerStart = rPool.pImp->nVerStart; + pImp->nVerEnd = rPool.pImp->nVerEnd; + pImp->bInSetItem = FALSE; + pImp->nStoringStart = nStart; + pImp->nStoringEnd = nEnd; + + memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1)); + + // Static Defaults "ubernehmen + if ( bCloneStaticDefaults ) + { + SfxPoolItem **ppDefaults = new SfxPoolItem*[nEnd-nStart+1]; + for ( USHORT n = 0; n <= nEnd - nStart; ++n ) + { + (*( ppDefaults + n )) = (*( rPool.ppStaticDefaults + n ))->Clone(this); + (*( ppDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); + } + + SetDefaults( ppDefaults ); + } + else + SetDefaults( rPool.ppStaticDefaults ); + + // Pool Defaults kopieren + for ( USHORT n = 0; n <= nEnd - nStart; ++n ) + if ( (*( rPool.ppPoolDefaults + n )) ) + { + (*( ppPoolDefaults + n )) = (*( rPool.ppPoolDefaults + n ))->Clone(this); + (*( ppPoolDefaults + n ))->SetKind( SFX_ITEMS_POOLDEFAULT ); + } + + // Version-Map kopieren + USHORT nVerCount = rPool.pImp->aVersions.Count(); + for ( USHORT nVer = 0; nVer < nVerCount; ++nVer ) + { + const SfxPoolVersion_Impl *pOld = rPool.pImp->aVersions.GetObject(nVer); + const SfxPoolVersion_Impl *pNew = new SfxPoolVersion_Impl( *pOld ); + pImp->aVersions.Insert( pNew, nVer ); + } + + // Verkettung wiederherstellen + if ( rPool.pSecondary ) + SetSecondaryPool( rPool.pSecondary->Clone() ); +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::SetDefaults( SfxPoolItem **pDefaults ) +{ + DBG_CHKTHIS(SfxItemPool, 0); + DBG_ASSERT( pDefaults, "erst wollen, dann nichts geben..." ); + DBG_ASSERT( !ppStaticDefaults, "habe schon defaults" ); + + ppStaticDefaults = pDefaults; + //! if ( (*ppStaticDefaults)->GetKind() != SFX_ITEMS_STATICDEFAULT ) + //! geht wohl nicht im Zshg mit SetItems, die hinten stehen + { + DBG_ASSERT( (*ppStaticDefaults)->GetRefCount() == 0 || + IsDefaultItem( (*ppStaticDefaults) ), + "das sind keine statics" ); + for ( USHORT n = 0; n <= nEnd - nStart; ++n ) + { + SFX_ASSERT( (*( ppStaticDefaults + n ))->Which() == n + nStart, + n + nStart, "static defaults not sorted" ); + (*( ppStaticDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); + DBG_ASSERT( !(pImp->ppPoolItems[n]), "defaults with setitems with items?!" ); + } + } +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::ReleaseDefaults +( + BOOL bDelete /* TRUE + l"oscht sowohl das Array als auch die einzelnen + statischen Defaults + + FALSE + l"oscht weder das Array noch die einzelnen + statischen Defaults */ +) + +/* [Beschreibung] + + Gibt die statischen Defaults der betreffenden SfxItemPool-Instanz frei + und l"oscht ggf. die statischen Defaults. + + Nach Aufruf dieser Methode darf die SfxItemPool-Instanz nicht mehr + verwendet werden, einzig ist der Aufruf des Destruktors zu"lassig. +*/ + +{ + DBG_ASSERT( ppStaticDefaults, "keine Arme keine Kekse" ); + ReleaseDefaults( ppStaticDefaults, nEnd - nStart + 1, bDelete ); + + // KSO (22.10.98): ppStaticDefaults zeigt auf geloeschten Speicher, + // wenn bDelete == TRUE. + if ( bDelete ) + ppStaticDefaults = 0; +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::ReleaseDefaults +( + SfxPoolItem** pDefaults, /* freizugebende statische Defaults */ + + USHORT nCount, /* Anzahl der statischen Defaults */ + + BOOL bDelete /* TRUE + l"oscht sowohl das Array als auch die + einzelnen statischen Defaults + + FALSE + l"oscht weder das Array noch die + einzelnen statischen Defaults */ +) + +/* [Beschreibung] + + Gibt die angegebenen statischen Defaults frei und l"oscht ggf. + die statischen Defaults. + + Diese Methode darf erst nach Zerst"orung aller SfxItemPool-Instanzen, + welche die angegebenen statischen Defaults 'pDefault' verwenden, + aufgerufen werden. +*/ + +{ + DBG_ASSERT( pDefaults, "erst wollen, dann nichts geben..." ); + + for ( USHORT n = 0; n < nCount; ++n ) + { + SFX_ASSERT( IsStaticDefaultItem( *(pDefaults+n) ), + n, "das ist kein static-default" ); + (*( pDefaults + n ))->SetRefCount( 0 ); + if ( bDelete ) + { delete *( pDefaults + n ); *(pDefaults + n) = 0; } + } + + if ( bDelete ) + { delete[] pDefaults; pDefaults = 0; } +} + +// ----------------------------------------------------------------------- + +SfxItemPool::~SfxItemPool() +{ + DBG_DTOR(SfxItemPool, 0); + DBG_ASSERT( pMaster == this, "destroying active Secondary-Pool" ); + + if ( pImp->ppPoolItems && ppPoolDefaults ) + Delete(); + delete[] _pPoolRanges; + delete pImp; +} + +void SfxItemPool::Free(SfxItemPool* pPool) +{ + if(pPool) + { + // tell all the registered SfxItemPoolUsers that the pool is in destruction + SfxItemPoolUserVector aListCopy(pPool->maSfxItemPoolUsers.begin(), pPool->maSfxItemPoolUsers.end()); + for(SfxItemPoolUserVector::iterator aIterator = aListCopy.begin(); aIterator != aListCopy.end(); aIterator++) + { + SfxItemPoolUser* pSfxItemPoolUser = *aIterator; + DBG_ASSERT(pSfxItemPoolUser, "corrupt SfxItemPoolUser list (!)"); + pSfxItemPoolUser->ObjectInDestruction(*pPool); + } + + // Clear the vector. This means that user do not need to call RemoveSfxItemPoolUser() + // when they get called from ObjectInDestruction(). + pPool->maSfxItemPoolUsers.clear(); + + // delete pool + delete pPool; + } +} + +// ----------------------------------------------------------------------- + + +void SfxItemPool::SetSecondaryPool( SfxItemPool *pPool ) +{ + // ggf. an abgeh"angten Pools den Master zur"ucksetzen + if ( pSecondary ) + { +#ifdef DBG_UTIL + HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) + if ( ppStaticDefaults ) + { + // Delete() ist noch nicht gelaufen? + if ( pImp->ppPoolItems && pSecondary->pImp->ppPoolItems ) + { + // hat der master SetItems? + BOOL bHasSetItems = FALSE; + for ( USHORT i = 0; !bHasSetItems && i < nEnd-nStart; ++i ) + bHasSetItems = ppStaticDefaults[i]->ISA(SfxSetItem); + + // abgehaengte Pools muessen leer sein + BOOL bOK = bHasSetItems; + for ( USHORT n = 0; + bOK && n <= pSecondary->nEnd - pSecondary->nStart; + ++n ) + { + SfxPoolItemArray_Impl** ppItemArr = + pSecondary->pImp->ppPoolItems + n; + if ( *ppItemArr ) + { + SfxPoolItem** ppHtArr = + (SfxPoolItem**)(*ppItemArr)->GetData(); + for( USHORT i = (*ppItemArr)->Count(); i; ++ppHtArr, --i ) + if ( !(*ppHtArr) ) + { + DBG_ERROR( "old secondary pool must be empty" ); + bOK = FALSE; + break; + } + } + } + } + } +#endif + + pSecondary->pMaster = pSecondary; + for ( SfxItemPool *p = pSecondary->pSecondary; p; p = p->pSecondary ) + p->pMaster = pSecondary; + } + + // ggf. den Master der neuen Secondary-Pools setzen + DBG_ASSERT( !pPool || pPool->pMaster == pPool, "Secondary tanzt auf zwei Hochzeiten " ); + SfxItemPool *pNewMaster = pMaster ? pMaster : this; + for ( SfxItemPool *p = pPool; p; p = p->pSecondary ) + p->pMaster = pNewMaster; + + // neuen Secondary-Pool merken + pSecondary = pPool; +} + +// ----------------------------------------------------------------------- + +SfxMapUnit SfxItemPool::GetMetric( USHORT ) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + + return pImp->eDefMetric; +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::SetDefaultMetric( SfxMapUnit eNewMetric ) +{ + DBG_CHKTHIS(SfxItemPool, 0); + + pImp->eDefMetric = eNewMetric; +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxItemPool::GetPresentation +( + const SfxPoolItem& rItem, /* IN: <SfxPoolItem>, dessen textuelle + Wert-Darstellung geliefert werden + soll */ + SfxItemPresentation ePresent, /* IN: gew"unschte Art der Darstellung; + siehe <SfxItemPresentation> */ + SfxMapUnit eMetric, /* IN: gew"unschte Ma\seinheit der Darstellung */ + XubString& rText, /* OUT: textuelle Darstellung von 'rItem' */ + const IntlWrapper * pIntlWrapper +) const + +/* [Beschreibung] + + "Uber diese virtuelle Methode k"onnen textuelle Darstellungen der + von der jeweilige SfxItemPool-Subklasse verwalteten SfxPoolItems + angefordert werden. + + In Ableitungen sollte diese Methode "uberladen werden und auf + SfxPoolItems reagiert werden, die bei <SfxPoolItem::GetPresentation()const> + keine vollst"andige Information liefern k"onnen. + + Die Basisklasse liefert die unver"anderte Presentation von 'rItem'. +*/ + +{ + DBG_CHKTHIS(SfxItemPool, 0); + return rItem.GetPresentation( + ePresent, GetMetric(rItem.Which()), eMetric, rText, pIntlWrapper ); +} + + +// ----------------------------------------------------------------------- + +SfxItemPool* SfxItemPool::Clone() const +{ + DBG_CHKTHIS(SfxItemPool, 0); + + SfxItemPool *pPool = new SfxItemPool( *this ); + return pPool; +} + +// ---------------------------------------------------------------------- + +void SfxItemPool::Delete() +{ + DBG_CHKTHIS(SfxItemPool, 0); + + // schon deleted? + if ( !pImp->ppPoolItems || !ppPoolDefaults ) + return; + + // z.B. laufenden Requests bescheidsagen + pImp->aBC.Broadcast( SfxSimpleHint( SFX_HINT_DYING ) ); + + //MA 16. Apr. 97: Zweimal durchlaufen, in der ersten Runde fuer die SetItems. + //Der Klarheit halber wird das jetzt in zwei besser lesbare Schleifen aufgeteilt. + + SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; + SfxPoolItem** ppDefaultItem = ppPoolDefaults; + SfxPoolItem** ppStaticDefaultItem = ppStaticDefaults; + USHORT nArrCnt; + + //Erst die SetItems abraeumen + HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) + if ( ppStaticDefaults ) + { + for ( nArrCnt = GetSize_Impl(); + nArrCnt; + --nArrCnt, ++ppItemArr, ++ppDefaultItem, ++ppStaticDefaultItem ) + { + // KSO (22.10.98): *ppStaticDefaultItem kann im dtor einer + // von SfxItemPool abgeleiteten Klasse bereits geloescht worden + // sein! -> CHAOS Itempool + if ( *ppStaticDefaultItem && (*ppStaticDefaultItem)->ISA(SfxSetItem) ) + { + if ( *ppItemArr ) + { + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for ( USHORT n = (*ppItemArr)->Count(); n; --n, ++ppHtArr ) + if (*ppHtArr) + { +#ifdef DBG_UTIL + ReleaseRef( **ppHtArr, (*ppHtArr)->GetRefCount() ); +#endif + delete *ppHtArr; + } + DELETEZ( *ppItemArr ); + } + if ( *ppDefaultItem ) + { +#ifdef DBG_UTIL + SetRefCount( **ppDefaultItem, 0 ); +#endif + DELETEZ( *ppDefaultItem ); + } + } + } + } + + ppItemArr = pImp->ppPoolItems; + ppDefaultItem = ppPoolDefaults; + + //Jetzt die 'einfachen' Items + for ( nArrCnt = GetSize_Impl(); + nArrCnt; + --nArrCnt, ++ppItemArr, ++ppDefaultItem ) + { + if ( *ppItemArr ) + { + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for ( USHORT n = (*ppItemArr)->Count(); n; --n, ++ppHtArr ) + if (*ppHtArr) + { +#ifdef DBG_UTIL + ReleaseRef( **ppHtArr, (*ppHtArr)->GetRefCount() ); +#endif + delete *ppHtArr; + } + delete *ppItemArr; + } + if ( *ppDefaultItem ) + { +#ifdef DBG_UTIL + SetRefCount( **ppDefaultItem, 0 ); +#endif + delete *ppDefaultItem; + } + } + + pImp->DeleteItems(); + delete[] ppPoolDefaults; ppPoolDefaults = 0; +} + +// ---------------------------------------------------------------------- + +void SfxItemPool::Cleanup() +{ + DBG_CHKTHIS(SfxItemPool, 0); + + //MA 16. Apr. 97: siehe ::Delete() + + SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; + SfxPoolItem** ppDefaultItem = ppPoolDefaults; + SfxPoolItem** ppStaticDefaultItem = ppStaticDefaults; + USHORT nArrCnt; + + HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) + if ( ppStaticDefaults ) //HACK fuer Image, dort gibt es keine Statics!! + { + for ( nArrCnt = GetSize_Impl(); + nArrCnt; + --nArrCnt, ++ppItemArr, ++ppDefaultItem, ++ppStaticDefaultItem ) + { + //Fuer jedes Item gibt es entweder ein Default oder ein static Default! + if ( *ppItemArr && + ((*ppDefaultItem && (*ppDefaultItem)->ISA(SfxSetItem)) || + (*ppStaticDefaultItem)->ISA(SfxSetItem)) ) + { + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for ( USHORT n = (*ppItemArr)->Count(); n; --n, ++ppHtArr ) + if ( *ppHtArr && !(*ppHtArr)->GetRefCount() ) + { + DELETEZ(*ppHtArr); + } + } + } + } + + ppItemArr = pImp->ppPoolItems; + + for ( nArrCnt = GetSize_Impl(); + nArrCnt; + --nArrCnt, ++ppItemArr ) + { + if ( *ppItemArr ) + { + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for ( USHORT n = (*ppItemArr)->Count(); n; --n, ++ppHtArr ) + if ( *ppHtArr && !(*ppHtArr)->GetRefCount() ) + DELETEZ( *ppHtArr ); + } + } +} + +// ---------------------------------------------------------------------- + +void SfxItemPool::SetPoolDefaultItem(const SfxPoolItem &rItem) +{ + DBG_CHKTHIS(SfxItemPool, 0); + if ( IsInRange(rItem.Which()) ) + { + SfxPoolItem **ppOldDefault = + ppPoolDefaults + GetIndex_Impl(rItem.Which()); + SfxPoolItem *pNewDefault = rItem.Clone(this); + pNewDefault->SetKind(SFX_ITEMS_POOLDEFAULT); + if ( *ppOldDefault ) + { + (*ppOldDefault)->SetRefCount(0); + DELETEZ( *ppOldDefault ); + } + *ppOldDefault = pNewDefault; + } + else if ( pSecondary ) + pSecondary->SetPoolDefaultItem(rItem); + else + { + SFX_ASSERT( 0, rItem.Which(), "unknown Which-Id - cannot set pool default" ); + } +} + +/* + * Resets the default of the given <Which-Id> back to the static default. + * If a pool default exists it is removed. + */ +void SfxItemPool::ResetPoolDefaultItem( USHORT nWhichId ) +{ + DBG_CHKTHIS(SfxItemPool, 0); + if ( IsInRange(nWhichId) ) + { + SfxPoolItem **ppOldDefault = + ppPoolDefaults + GetIndex_Impl( nWhichId ); + if ( *ppOldDefault ) + { + (*ppOldDefault)->SetRefCount(0); + DELETEZ( *ppOldDefault ); + } + } + else if ( pSecondary ) + pSecondary->ResetPoolDefaultItem(nWhichId); + else + { + SFX_ASSERT( 0, nWhichId, "unknown Which-Id - cannot set pool default" ); + } +} + +// ----------------------------------------------------------------------- + +const SfxPoolItem& SfxItemPool::Put( const SfxPoolItem& rItem, USHORT nWhich ) +{ + DBG_ASSERT( !rItem.ISA(SfxSetItem) || + 0 != &((const SfxSetItem&)rItem).GetItemSet(), + "SetItem without ItemSet" ); + + DBG_CHKTHIS(SfxItemPool, 0); + if ( 0 == nWhich ) + nWhich = rItem.Which(); + + // richtigen Secondary-Pool finden + BOOL bSID = nWhich > SFX_WHICH_MAX; + if ( !bSID && !IsInRange(nWhich) ) + { + if ( pSecondary ) + return pSecondary->Put( rItem, nWhich ); + DBG_ERROR( "unknown Which-Id - cannot put item" ); + } + + // SID oder nicht poolable (neue Definition)? + USHORT nIndex = bSID ? USHRT_MAX : GetIndex_Impl(nWhich); + if ( USHRT_MAX == nIndex || + IsItemFlag_Impl( nIndex, SFX_ITEM_NOT_POOLABLE ) ) + { + SFX_ASSERT( USHRT_MAX != nIndex || rItem.Which() != nWhich || + !IsDefaultItem(&rItem) || rItem.GetKind() == SFX_ITEMS_DELETEONIDLE, + nWhich, "ein nicht Pool-Item ist Default?!" ); + SfxPoolItem *pPoolItem = rItem.Clone(pMaster); + pPoolItem->SetWhich(nWhich); + AddRef( *pPoolItem ); + return *pPoolItem; + } + + SFX_ASSERT( rItem.IsA(GetDefaultItem(nWhich).Type()), nWhich, + "SFxItemPool: wrong item type in Put" ); + + SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems + nIndex; + if( !*ppItemArr ) + *ppItemArr = new SfxPoolItemArray_Impl; + + SfxPoolItem **ppFree = 0; + SfxPoolItem** ppHtArray = (SfxPoolItem**)(*ppItemArr)->GetData(); + if ( IsItemFlag_Impl( nIndex, SFX_ITEM_POOLABLE ) ) + { + // wenn es ueberhaupt gepoolt ist, koennte es schon drin sein + if ( IsPooledItem(&rItem) ) + { + // 1. Schleife: teste ob der Pointer vorhanden ist. + for( USHORT n = (*ppItemArr)->Count(); n; ++ppHtArray, --n ) + if( &rItem == (*ppHtArray) ) + { + AddRef( **ppHtArray ); + return **ppHtArray; + } + } + + // 2. Schleife: dann muessen eben die Attribute verglichen werden + USHORT n; + for ( n = (*ppItemArr)->Count(), ppHtArray = (SfxPoolItem**)(*ppItemArr)->GetData(); + n; ++ppHtArray, --n ) + { + if ( *ppHtArray ) + { + if( **ppHtArray == rItem ) + { + AddRef( **ppHtArray ); + return **ppHtArray; + } + } + else + if ( !ppFree ) + ppFree = ppHtArray; + } + } + else + { + // freien Platz suchen + SfxPoolItem** ppHtArr; + USHORT n, nCount = (*ppItemArr)->Count(); + for ( n = (*ppItemArr)->nFirstFree, + ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData() + n; + n < nCount; + ++ppHtArr, ++n ) + if ( !*ppHtArr ) + { + ppFree = ppHtArr; + break; + } + + // naechstmoeglichen freien Platz merken + (*ppItemArr)->nFirstFree = n; + } + + // nicht vorhanden, also im PtrArray eintragen + SfxPoolItem* pNewItem = rItem.Clone(pMaster); + pNewItem->SetWhich(nWhich); +#ifdef DBG_UTIL + SFX_ASSERT( rItem.Type() == pNewItem->Type(), nWhich, "unequal types in Put(): no Clone()?" ) +#ifdef TF_POOLABLE + if ( !rItem.ISA(SfxSetItem) ) + { + SFX_ASSERT( !IsItemFlag(nWhich, SFX_ITEM_POOLABLE) || + rItem == *pNewItem, + nWhich, "unequal items in Put(): no operator==?" ); + SFX_ASSERT( !IsItemFlag(*pNewItem, SFX_ITEM_POOLABLE) || + *pNewItem == rItem, + nWhich, "unequal items in Put(): no operator==?" ); + } +#endif +#endif + AddRef( *pNewItem, pImp->nInitRefCount ); + const SfxPoolItem* pTemp = pNewItem; + if ( !ppFree ) + (*ppItemArr)->Insert( pTemp, (*ppItemArr)->Count() ); + else + { + DBG_ASSERT( *ppFree == 0, "using surrogate in use" ); + *ppFree = pNewItem; + } + return *pNewItem; +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::Remove( const SfxPoolItem& rItem ) +{ + DBG_CHKTHIS(SfxItemPool, 0); + + DBG_ASSERT( !rItem.ISA(SfxSetItem) || + 0 != &((const SfxSetItem&)rItem).GetItemSet(), + "SetItem without ItemSet" ); + + SFX_ASSERT( !IsPoolDefaultItem(&rItem), rItem.Which(), + "wo kommt denn hier ein Pool-Default her" ); + + // richtigen Secondary-Pool finden + const USHORT nWhich = rItem.Which(); + BOOL bSID = nWhich > SFX_WHICH_MAX; + if ( !bSID && !IsInRange(nWhich) ) + { + if ( pSecondary ) + { + pSecondary->Remove( rItem ); + return; + } + DBG_ERROR( "unknown Which-Id - cannot remove item" ); + } + + // SID oder nicht poolable (neue Definition)? + USHORT nIndex = bSID ? USHRT_MAX : GetIndex_Impl(nWhich); + if ( bSID || IsItemFlag_Impl( nIndex, SFX_ITEM_NOT_POOLABLE ) ) + { + SFX_ASSERT( USHRT_MAX != nIndex || + !IsDefaultItem(&rItem), rItem.Which(), + "ein nicht Pool-Item ist Default?!" ); + if ( 0 == ReleaseRef(rItem) ) + { + SfxPoolItem *pItem = &(SfxPoolItem &)rItem; + delete pItem; + } + return; + } + + SFX_ASSERT( rItem.GetRefCount(), rItem.Which(), "RefCount == 0, Remove unmoeglich" ); + + // statische Defaults sind eben einfach da + if ( rItem.GetKind() == SFX_ITEMS_STATICDEFAULT && + &rItem == *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) + return; + + // Item im eigenen Pool suchen + SfxPoolItemArray_Impl** ppItemArr = (pImp->ppPoolItems + nIndex); + SFX_ASSERT( *ppItemArr, rItem.Which(), "removing Item not in Pool" ); + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for( USHORT n = (*ppItemArr)->Count(); n; ++ppHtArr, --n ) + if( *ppHtArr == &rItem ) + { + if ( (*ppHtArr)->GetRefCount() ) //! + ReleaseRef( **ppHtArr ); + else + { + SFX_ASSERT( 0, rItem.Which(), "removing Item without ref" ); + SFX_TRACE( "to be removed, but not no refs: ", *ppHtArr ); + } + + // ggf. kleinstmoegliche freie Position merken + USHORT nPos = (*ppItemArr)->Count() - n; + if ( (*ppItemArr)->nFirstFree > nPos ) + (*ppItemArr)->nFirstFree = nPos; + + //! MI: Hack, solange wir das Problem mit dem Outliner haben + //! siehe anderes MI-REF + if ( 0 == (*ppHtArr)->GetRefCount() && nWhich < 4000 ) + DELETEZ(*ppHtArr); + return; + } + + // nicht vorhanden + SFX_ASSERT( 0, rItem.Which(), "removing Item not in Pool" ); + SFX_TRACE( "to be removed, but not in pool: ", &rItem ); +} + +// ----------------------------------------------------------------------- + +const SfxPoolItem& SfxItemPool::GetDefaultItem( USHORT nWhich ) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + + if ( !IsInRange(nWhich) ) + { + if ( pSecondary ) + return pSecondary->GetDefaultItem( nWhich ); + SFX_ASSERT( 0, nWhich, "unknown which - dont ask me for defaults" ); + } + + DBG_ASSERT( ppStaticDefaults, "no defaults known - dont ask me for defaults" ); + USHORT nPos = GetIndex_Impl(nWhich); + SfxPoolItem *pDefault = *(ppPoolDefaults + nPos); + if ( pDefault ) + return *pDefault; + return **(ppStaticDefaults + nPos); +} + +// ----------------------------------------------------------------------- + + +void SfxItemPool::FreezeIdRanges() + +/* [Beschreibung] + + This method should be called at the master pool, when all secondary + pools are appended to it. + + It calculates the ranges of 'which-ids' for fast construction of + item-sets, which contains all 'which-ids'. +*/ + +{ + FillItemIdRanges_Impl( _pPoolRanges ); +} + + +// ----------------------------------------------------------------------- + +void SfxItemPool::FillItemIdRanges_Impl( USHORT*& pWhichRanges ) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + DBG_ASSERT( !_pPoolRanges, "GetFrozenRanges() would be faster!" ); + + const SfxItemPool *pPool; + USHORT nLevel = 0; + for( pPool = this; pPool; pPool = pPool->pSecondary ) + ++nLevel; + + pWhichRanges = new USHORT[ 2*nLevel + 1 ]; + + nLevel = 0; + for( pPool = this; pPool; pPool = pPool->pSecondary ) + { + *(pWhichRanges+(nLevel++)) = pPool->nStart; + *(pWhichRanges+(nLevel++)) = pPool->nEnd; + *(pWhichRanges+nLevel) = 0; + } +} + +// ----------------------------------------------------------------------- + +const SfxPoolItem *SfxItemPool::GetItem(USHORT nWhich, USHORT nOfst) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + + if ( !IsInRange(nWhich) ) + { + if ( pSecondary ) + return pSecondary->GetItem( nWhich, nOfst ); + SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot resolve surrogate" ); + return 0; + } + + // dflt-Attribut? + if ( nOfst == SFX_ITEMS_STATICDEFAULT ) + return *(ppStaticDefaults + GetIndex_Impl(nWhich)); + + SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(nWhich)); + if( pItemArr && nOfst < pItemArr->Count() ) + return (*pItemArr)[nOfst]; + + return 0; +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetItemCount(USHORT nWhich) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + + if ( !IsInRange(nWhich) ) + { + if ( pSecondary ) + return pSecondary->GetItemCount( nWhich ); + SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot resolve surrogate" ); + return 0; + } + + SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(nWhich)); + if ( pItemArr ) + return pItemArr->Count(); + return 0; +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetWhich( USHORT nSlotId, BOOL bDeep ) const +{ + if ( !IsSlot(nSlotId) ) + return nSlotId; + +#ifdef TF_POOLABLE + USHORT nCount = nEnd - nStart + 1; + for ( USHORT nOfs = 0; nOfs < nCount; ++nOfs ) + if ( pItemInfos[nOfs]._nSID == nSlotId ) + return nOfs + nStart; +#else + if ( pSlotIds ) + { + USHORT nCount = nEnd - nStart + 1; + for ( USHORT nOfs = 0; nOfs < nCount; ++nOfs ) + if ( pSlotIds[nOfs] == nSlotId ) + return nOfs + nStart; + } +#endif + if ( pSecondary && bDeep ) + return pSecondary->GetWhich(nSlotId); + return nSlotId; +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetSlotId( USHORT nWhich, BOOL bDeep ) const +{ + if ( !IsWhich(nWhich) ) + return nWhich; + + if ( !IsInRange( nWhich ) ) + { + if ( pSecondary && bDeep ) + return pSecondary->GetSlotId(nWhich); + SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get slot-id" ); + return 0; + } +#ifdef TF_POOLABLE + + USHORT nSID = pItemInfos[nWhich - nStart]._nSID; + return nSID ? nSID : nWhich; +#else + else if ( pSlotIds ) + return pSlotIds[nWhich - nStart]; + return nWhich; +#endif +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetTrueWhich( USHORT nSlotId, BOOL bDeep ) const +{ + if ( !IsSlot(nSlotId) ) + return 0; + +#ifdef TF_POOLABLE + USHORT nCount = nEnd - nStart + 1; + for ( USHORT nOfs = 0; nOfs < nCount; ++nOfs ) + if ( pItemInfos[nOfs]._nSID == nSlotId ) + return nOfs + nStart; +#else + if ( pSlotIds ) + { + USHORT nCount = nEnd - nStart + 1; + for ( USHORT nOfs = 0; nOfs < nCount; ++nOfs ) + if ( pSlotIds[nOfs] == nSlotId ) + return nOfs + nStart; + } +#endif + if ( pSecondary && bDeep ) + return pSecondary->GetTrueWhich(nSlotId); + return 0; +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetTrueSlotId( USHORT nWhich, BOOL bDeep ) const +{ + if ( !IsWhich(nWhich) ) + return 0; + + if ( !IsInRange( nWhich ) ) + { + if ( pSecondary && bDeep ) + return pSecondary->GetTrueSlotId(nWhich); + SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get slot-id" ); + return 0; + } +#ifdef TF_POOLABLE + return pItemInfos[nWhich - nStart]._nSID; +#else + else if ( pSlotIds ) + return pSlotIds[nWhich - nStart]; + else + return 0; +#endif +} +// ----------------------------------------------------------------------- +void SfxItemPool::SetFileFormatVersion( USHORT nFileFormatVersion ) + +/* [Description] + + You must call this function to set the file format version after + concatenating your secondary-pools but before you store any + pool, itemset or item. Only set the version at the master pool, + never at any secondary pool. +*/ + +{ + DBG_ASSERT( this == pMaster, + "SfxItemPool::SetFileFormatVersion() but not a master pool" ); + for ( SfxItemPool *pPool = this; pPool; pPool = pPool->pSecondary ) + pPool->_nFileFormatVersion = nFileFormatVersion; +} + + diff --git a/svl/source/items/itemprop.cxx b/svl/source/items/itemprop.cxx new file mode 100644 index 000000000000..354e0a1441ba --- /dev/null +++ b/svl/source/items/itemprop.cxx @@ -0,0 +1,506 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: itemprop.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/itemprop.hxx> +#include <svtools/itempool.hxx> +#include <svtools/itemset.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <hash_map> +/************************************************************************* + UNO III Implementation +*************************************************************************/ +using namespace com::sun::star; +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::uno; +using namespace ::rtl; +/*-- 16.02.2009 10:03:55--------------------------------------------------- + + -----------------------------------------------------------------------*/ + +struct equalOUString +{ + bool operator()(const ::rtl::OUString& r1, const ::rtl::OUString& r2) const + { + return r1.equals( r2 ); + } +}; + +typedef ::std::hash_map< ::rtl::OUString, + SfxItemPropertySimpleEntry, + ::rtl::OUStringHash, + equalOUString > SfxItemPropertyHashMap_t; + +class SfxItemPropertyMap_Impl : public SfxItemPropertyHashMap_t +{ +public: + mutable uno::Sequence< beans::Property > m_aPropSeq; + + SfxItemPropertyMap_Impl(){} + SfxItemPropertyMap_Impl( const SfxItemPropertyMap_Impl* pSource ); +}; +SfxItemPropertyMap_Impl::SfxItemPropertyMap_Impl( const SfxItemPropertyMap_Impl* pSource ) +{ + this->SfxItemPropertyHashMap_t::operator=( *pSource ); + m_aPropSeq = pSource->m_aPropSeq; +} + +/*-- 16.02.2009 10:03:51--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertyMap::SfxItemPropertyMap( const SfxItemPropertyMapEntry* pEntries ) : + m_pImpl( new SfxItemPropertyMap_Impl ) +{ + while( pEntries->pName ) + { + ::rtl::OUString sEntry(pEntries->pName, pEntries->nNameLen, RTL_TEXTENCODING_ASCII_US ); + (*m_pImpl) [ sEntry ] = pEntries; + ++pEntries; + } +} +/*-- 16.02.2009 12:46:41--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertyMap::SfxItemPropertyMap( const SfxItemPropertyMap* pSource ) : + m_pImpl( new SfxItemPropertyMap_Impl( pSource->m_pImpl ) ) +{ +} +/*-- 16.02.2009 10:03:51--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertyMap::~SfxItemPropertyMap() +{ + delete m_pImpl; +} +/*-- 16.02.2009 10:03:51--------------------------------------------------- + + -----------------------------------------------------------------------*/ +const SfxItemPropertySimpleEntry* SfxItemPropertyMap::getByName( const ::rtl::OUString &rName ) const +{ + SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName); + if( aIter == m_pImpl->end() ) + return 0; + return &aIter->second; +} + +/*-- 16.02.2009 10:44:24--------------------------------------------------- + + -----------------------------------------------------------------------*/ +uno::Sequence<beans::Property> SfxItemPropertyMap::getProperties() const +{ + if( !m_pImpl->m_aPropSeq.getLength() ) + { + m_pImpl->m_aPropSeq.realloc( m_pImpl->size() ); + beans::Property* pPropArray = m_pImpl->m_aPropSeq.getArray(); + sal_uInt32 n = 0; + SfxItemPropertyHashMap_t::const_iterator aIt = m_pImpl->begin(); + while( aIt != m_pImpl->end() ) + //for ( const SfxItemPropertyMap *pMap = _pMap; pMap->pName; ++pMap ) + { + const SfxItemPropertySimpleEntry* pEntry = &(*aIt).second; + pPropArray[n].Name = (*aIt).first; + pPropArray[n].Handle = pEntry->nWID; + if(pEntry->pType) + pPropArray[n].Type = *pEntry->pType; + pPropArray[n].Attributes = + sal::static_int_cast< sal_Int16 >(pEntry->nFlags); + n++; + ++aIt; + } + } + + return m_pImpl->m_aPropSeq; +} +/*-- 16.02.2009 11:04:31--------------------------------------------------- + + -----------------------------------------------------------------------*/ +beans::Property SfxItemPropertyMap::getPropertyByName( const ::rtl::OUString rName ) const + throw( beans::UnknownPropertyException ) +{ + SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName); + if( aIter == m_pImpl->end() ) + throw UnknownPropertyException(); + const SfxItemPropertySimpleEntry* pEntry = &aIter->second; + beans::Property aProp; + aProp.Name = rName; + aProp.Handle = pEntry->nWID; + if(pEntry->pType) + aProp.Type = *pEntry->pType; + aProp.Attributes = sal::static_int_cast< sal_Int16 >(pEntry->nFlags); + return aProp; +} +/*-- 16.02.2009 11:09:16--------------------------------------------------- + + -----------------------------------------------------------------------*/ +sal_Bool SfxItemPropertyMap::hasPropertyByName( const ::rtl::OUString& rName ) const +{ + SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName); + return aIter != m_pImpl->end(); +} +/*-- 16.02.2009 11:25:14--------------------------------------------------- + + -----------------------------------------------------------------------*/ +void SfxItemPropertyMap::mergeProperties( const uno::Sequence< beans::Property >& rPropSeq ) +{ + const beans::Property* pPropArray = rPropSeq.getConstArray(); + sal_uInt32 nElements = rPropSeq.getLength(); + for( sal_uInt32 nElement = 0; nElement < nElements; ++nElement ) + { + SfxItemPropertySimpleEntry aTemp( + sal::static_int_cast< sal_Int16 >( pPropArray[nElement].Handle ), //nWID + &pPropArray[nElement].Type, //pType + pPropArray[nElement].Attributes, //nFlags + 0 ); //nMemberId + (*m_pImpl)[pPropArray[nElement].Name] = aTemp; + } +} +/*-- 18.02.2009 12:04:42--------------------------------------------------- + + -----------------------------------------------------------------------*/ +PropertyEntryVector_t SfxItemPropertyMap::getPropertyEntries() const +{ + PropertyEntryVector_t aRet; + aRet.reserve(m_pImpl->size()); + + SfxItemPropertyHashMap_t::const_iterator aIt = m_pImpl->begin(); + while( aIt != m_pImpl->end() ) + { + const SfxItemPropertySimpleEntry* pEntry = &(*aIt).second; + aRet.push_back( SfxItemPropertyNamedEntry( (*aIt).first, * pEntry ) ); + ++aIt; + } + return aRet; +} +/*-- 18.02.2009 15:11:06--------------------------------------------------- + + -----------------------------------------------------------------------*/ +sal_uInt32 SfxItemPropertyMap::getSize() const +{ + return m_pImpl->size(); +} +/*-- 16.02.2009 13:44:54--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertySet::~SfxItemPropertySet() +{ +} +/* -----------------------------21.02.00 11:26-------------------------------- + + ---------------------------------------------------------------------------*/ +BOOL SfxItemPropertySet::FillItem(SfxItemSet&, USHORT, BOOL) const +{ + return FALSE; +} +/* -----------------------------06.06.01 12:32-------------------------------- + + ---------------------------------------------------------------------------*/ +void SfxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry& rEntry, + const SfxItemSet& rSet, Any& rAny ) const + throw(RuntimeException) +{ + // get the SfxPoolItem + const SfxPoolItem* pItem = 0; + SfxItemState eState = rSet.GetItemState( rEntry.nWID, TRUE, &pItem ); + if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID ) + pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID); + // return item values as uno::Any + if(eState >= SFX_ITEM_DEFAULT && pItem) + { + pItem->QueryValue( rAny, rEntry.nMemberId ); + } + else + { + SfxItemSet aSet(*rSet.GetPool(), rEntry.nWID, rEntry.nWID); + if(FillItem(aSet, rEntry.nWID, TRUE)) + { + const SfxPoolItem& rItem = aSet.Get(rEntry.nWID); + rItem.QueryValue( rAny, rEntry.nMemberId ); + } + else if(0 == (rEntry.nFlags & PropertyAttribute::MAYBEVOID)) + throw RuntimeException(); + } + + + // convert general SfxEnumItem values to specific values + if( rEntry.pType && TypeClass_ENUM == rEntry.pType->getTypeClass() && + rAny.getValueTypeClass() == TypeClass_LONG ) + { + INT32 nTmp = *(INT32*)rAny.getValue(); + rAny.setValue( &nTmp, *rEntry.pType ); + } +} +/* -----------------------------06.06.01 12:32-------------------------------- + + ---------------------------------------------------------------------------*/ +void SfxItemPropertySet::getPropertyValue( const OUString &rName, + const SfxItemSet& rSet, Any& rAny ) const + throw(RuntimeException, UnknownPropertyException) +{ + // detect which-id + const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName ); + if ( !pEntry ) + throw UnknownPropertyException(); + getPropertyValue( *pEntry,rSet, rAny ); +} +/* -----------------------------21.02.00 11:26-------------------------------- + + ---------------------------------------------------------------------------*/ +Any SfxItemPropertySet::getPropertyValue( const OUString &rName, + const SfxItemSet& rSet ) const + throw(RuntimeException, UnknownPropertyException) +{ + Any aVal; + getPropertyValue( rName,rSet, aVal ); + return aVal; +} +/* -----------------------------15.11.00 14:46-------------------------------- + + ---------------------------------------------------------------------------*/ +void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEntry, + const Any& aVal, + SfxItemSet& rSet ) const + throw(RuntimeException, + IllegalArgumentException) +{ + // get the SfxPoolItem + const SfxPoolItem* pItem = 0; + SfxPoolItem *pNewItem = 0; + SfxItemState eState = rSet.GetItemState( rEntry.nWID, TRUE, &pItem ); + if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID ) + pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID); + //maybe there's another way to find an Item + if(eState < SFX_ITEM_DEFAULT) + { + SfxItemSet aSet(*rSet.GetPool(), rEntry.nWID, rEntry.nWID); + if(FillItem(aSet, rEntry.nWID, FALSE)) + { + const SfxPoolItem &rItem = aSet.Get(rEntry.nWID); + pNewItem = rItem.Clone(); + } + } + if(!pNewItem && pItem) + { + pNewItem = pItem->Clone(); + } + if(pNewItem) + { + if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) ) + { + DELETEZ(pNewItem); + throw IllegalArgumentException(); + } + // apply new item + rSet.Put( *pNewItem, rEntry.nWID ); + delete pNewItem; + } +} +/* -----------------------------21.02.00 11:26-------------------------------- + + ---------------------------------------------------------------------------*/ +void SfxItemPropertySet::setPropertyValue( const OUString &rName, + const Any& aVal, + SfxItemSet& rSet ) const + throw(RuntimeException, + IllegalArgumentException, + UnknownPropertyException) +{ + const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName ); + if ( !pEntry ) + { + throw UnknownPropertyException(); + } + setPropertyValue(*pEntry, aVal, rSet); +} +/* -----------------------------21.02.00 11:26-------------------------------- + + ---------------------------------------------------------------------------*/ +PropertyState SfxItemPropertySet::getPropertyState(const SfxItemPropertySimpleEntry& rEntry, const SfxItemSet& rSet) const + throw() +{ + PropertyState eRet = PropertyState_DIRECT_VALUE; + USHORT nWhich = rEntry.nWID; + + // item state holen + SfxItemState eState = rSet.GetItemState( nWhich, FALSE ); + // item-Wert als UnoAny zurueckgeben + if(eState == SFX_ITEM_DEFAULT) + eRet = PropertyState_DEFAULT_VALUE; + else if(eState < SFX_ITEM_DEFAULT) + eRet = PropertyState_AMBIGUOUS_VALUE; + return eRet; +} +PropertyState SfxItemPropertySet::getPropertyState( + const OUString& rName, const SfxItemSet& rSet) const + throw(UnknownPropertyException) +{ + PropertyState eRet = PropertyState_DIRECT_VALUE; + + // which-id ermitteln + const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName ); + if( !pEntry || !pEntry->nWID ) + { + throw UnknownPropertyException(); + } + USHORT nWhich = pEntry->nWID; + + // item holen + const SfxPoolItem* pItem = 0; + SfxItemState eState = rSet.GetItemState( nWhich, FALSE, &pItem ); + if(!pItem && nWhich != rSet.GetPool()->GetSlotId(nWhich)) + pItem = &rSet.GetPool()->GetDefaultItem(nWhich); + // item-Wert als UnoAny zurueckgeben + if(eState == SFX_ITEM_DEFAULT) + eRet = PropertyState_DEFAULT_VALUE; + else if(eState < SFX_ITEM_DEFAULT) + eRet = PropertyState_AMBIGUOUS_VALUE; + return eRet; +} +/* -----------------------------21.02.00 11:26-------------------------------- + + ---------------------------------------------------------------------------*/ +Reference<XPropertySetInfo> + SfxItemPropertySet::getPropertySetInfo() const +{ + if( !m_xInfo.is() ) + m_xInfo = new SfxItemPropertySetInfo( &m_aMap ); + return m_xInfo; +} +/*-- 16.02.2009 13:49:25--------------------------------------------------- + + -----------------------------------------------------------------------*/ +struct SfxItemPropertySetInfo_Impl +{ + SfxItemPropertyMap* m_pOwnMap; +}; +/*-- 16.02.2009 13:49:24--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertySetInfo::SfxItemPropertySetInfo(const SfxItemPropertyMap *pMap ) : + m_pImpl( new SfxItemPropertySetInfo_Impl ) +{ + m_pImpl->m_pOwnMap = new SfxItemPropertyMap( pMap ); +} +/*-- 16.02.2009 13:49:25--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertySetInfo::SfxItemPropertySetInfo(const SfxItemPropertyMapEntry *pEntries ) : + m_pImpl( new SfxItemPropertySetInfo_Impl ) +{ + m_pImpl->m_pOwnMap = new SfxItemPropertyMap( pEntries ); +} +/* -----------------------------21.02.00 11:09-------------------------------- + + ---------------------------------------------------------------------------*/ +Sequence< Property > SAL_CALL + SfxItemPropertySetInfo::getProperties( ) + throw(RuntimeException) +{ + return m_pImpl->m_pOwnMap->getProperties(); +} +/*-- 16.02.2009 13:49:27--------------------------------------------------- + + -----------------------------------------------------------------------*/ +const SfxItemPropertyMap* SfxItemPropertySetInfo::getMap() const +{ + return m_pImpl->m_pOwnMap; +} + +/*-- 16.02.2009 12:43:36--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxItemPropertySetInfo::~SfxItemPropertySetInfo() +{ + delete m_pImpl->m_pOwnMap; + delete m_pImpl; +} +/* -----------------------------21.02.00 11:27-------------------------------- + + ---------------------------------------------------------------------------*/ +Property SAL_CALL + SfxItemPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName ) + throw(UnknownPropertyException, RuntimeException) +{ + return m_pImpl->m_pOwnMap->getPropertyByName( rName ); +} +/* -----------------------------21.02.00 11:28-------------------------------- + + ---------------------------------------------------------------------------*/ +sal_Bool SAL_CALL + SfxItemPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName ) + throw(RuntimeException) +{ + return m_pImpl->m_pOwnMap->hasPropertyByName( rName ); +} +/* -----------------------------21.02.00 12:03-------------------------------- + + ---------------------------------------------------------------------------*/ +SfxExtItemPropertySetInfo::SfxExtItemPropertySetInfo( + const SfxItemPropertyMapEntry *pMap, + const Sequence<Property>& rPropSeq ) : + aExtMap( pMap ) +{ + aExtMap.mergeProperties( rPropSeq ); +} +/*-- 16.02.2009 12:06:49--------------------------------------------------- + + -----------------------------------------------------------------------*/ +SfxExtItemPropertySetInfo::~SfxExtItemPropertySetInfo() +{ +} +/* -----------------------------21.02.00 12:03-------------------------------- + + ---------------------------------------------------------------------------*/ +Sequence< Property > SAL_CALL + SfxExtItemPropertySetInfo::getProperties( ) throw(RuntimeException) +{ + return aExtMap.getProperties(); +} +/* -----------------------------21.02.00 12:03-------------------------------- + + ---------------------------------------------------------------------------*/ +Property SAL_CALL + SfxExtItemPropertySetInfo::getPropertyByName( const OUString& rPropertyName ) + throw(UnknownPropertyException, RuntimeException) +{ + return aExtMap.getPropertyByName( rPropertyName ); +} +/* -----------------------------21.02.00 12:03-------------------------------- + + ---------------------------------------------------------------------------*/ +sal_Bool SAL_CALL + SfxExtItemPropertySetInfo::hasPropertyByName( const OUString& rPropertyName ) + throw(RuntimeException) +{ + return aExtMap.hasPropertyByName( rPropertyName ); +} + diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx new file mode 100644 index 000000000000..fee00dca854a --- /dev/null +++ b/svl/source/items/itemset.cxx @@ -0,0 +1,2128 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: itemset.cxx,v $ + * $Revision: 1.9 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <string.h> + +#if STLPORT_VERSION>=321 +#include <cstdarg> +#endif + +#ifndef GCC +#endif + +#define _SVSTDARR_USHORTS +#define _SVSTDARR_ULONGS + +#include <svtools/svstdarr.hxx> +#include <svtools/itemset.hxx> +#include <svtools/itempool.hxx> +#include <svtools/itemiter.hxx> +#include "whiter.hxx" +#include <svtools/nranges.hxx> +#include "whassert.hxx" + +#include <tools/stream.hxx> +#include <tools/solar.h> + +// STATIC DATA ----------------------------------------------------------- + +static const USHORT nInitCount = 10; // einzelne USHORTs => 5 Paare ohne '0' +#ifdef DBG_UTIL +static ULONG nRangesCopyCount = 0; // wie oft wurden Ranges kopiert +#endif + +DBG_NAME(SfxItemSet) + +//======================================================================== + +#define NUMTYPE USHORT +#define SvNums SvUShorts +#define SfxNumRanges SfxUShortRanges +#include "nranges.cxx" +#undef NUMTYPE +#undef SvNums +#undef SfxNumRanges + +#define NUMTYPE ULONG +#define SvNums SvULongs +#define SfxNumRanges SfxULongRanges +#include "nranges.cxx" +#undef NUMTYPE +#undef SvNums +#undef SfxNumRanges + +//======================================================================== + +#ifdef DBG_UTIL + + +const sal_Char *DbgCheckItemSet( const void* pVoid ) +{ + const SfxItemSet *pSet = (const SfxItemSet*) pVoid; + SfxWhichIter aIter( *pSet ); + USHORT nCount = 0, n = 0; + for ( USHORT nWh = aIter.FirstWhich(); nWh; nWh = aIter.NextWhich(), ++n ) + { + const SfxPoolItem *pItem = pSet->_aItems[n]; + if ( pItem ) + { + ++nCount; + DBG_ASSERT( IsInvalidItem(pItem) || + pItem->Which() == 0 || pItem->Which() == nWh, + "SfxItemSet: invalid which-id" ); + DBG_ASSERT( IsInvalidItem(pItem) || !pItem->Which() || + !SfxItemPool::IsWhich(pItem->Which()) || + pSet->GetPool()->IsItemFlag(nWh, SFX_ITEM_NOT_POOLABLE) || + SFX_ITEMS_NULL != pSet->GetPool()->GetSurrogate(pItem), + "SfxItemSet: item in set which is not in pool" ); + } + + } + DBG_ASSERT( pSet->_nCount == nCount, "wrong SfxItemSet::nCount detected" ); + + return 0; +} + +#endif +// ----------------------------------------------------------------------- + +SfxItemSet::SfxItemSet +( + SfxItemPool& rPool, /* der Pool, in dem die SfxPoolItems, + welche in dieses SfxItemSet gelangen, + aufgenommen werden sollen */ + BOOL +#ifdef DBG_UTIL +#ifdef SFX_ITEMSET_NO_DEFAULT_CTOR + + bTotalRanges /* komplette Pool-Ranges uebernehmen, + muss auf TRUE gesetzt werden */ +#endif +#endif +) +/* [Beschreibung] + + Konstruktor fuer ein SfxItemSet mit genau den Which-Bereichen, welche + dem angegebenen <SfxItemPool> bekannt sind. + + + [Anmerkung] + + F"ur Sfx-Programmierer ein derart konstruiertes SfxItemSet kann + keinerlei Items mit Slot-Ids als Which-Werte aufnehmen! +*/ + +: _pPool( &rPool ), + _pParent( 0 ), + _nCount( 0 ) +{ + DBG_CTOR(SfxItemSet, DbgCheckItemSet); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); + DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); +// DBG_ASSERT( bTotalRanges || abs( &bTotalRanges - this ) < 1000, +// "please use suitable ranges" ); +#ifdef DBG_UTIL +#ifdef SFX_ITEMSET_NO_DEFAULT_CTOR + if ( !bTotalRanges ) + *(int*)0 = 0; // GPF +#endif +#endif + + _pWhichRanges = (USHORT*) _pPool->GetFrozenIdRanges(); + DBG_ASSERT( _pWhichRanges, "don't create ItemSets with full range before FreezeIdRanges()" ); + if ( !_pWhichRanges ) + _pPool->FillItemIdRanges_Impl( _pWhichRanges ); + + const USHORT nSize = TotalCount(); + _aItems = new const SfxPoolItem* [ nSize ]; + memset( (void*) _aItems, 0, nSize * sizeof( SfxPoolItem* ) ); +} + +// ----------------------------------------------------------------------- + +SfxItemSet::SfxItemSet( SfxItemPool& rPool, USHORT nWhich1, USHORT nWhich2 ): + _pPool( &rPool ), + _pParent( 0 ), + _nCount( 0 ) +{ + DBG_CTOR(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( nWhich1 <= nWhich2, "Ungueltiger Bereich" ); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); + DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); + + InitRanges_Impl(nWhich1, nWhich2); +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::InitRanges_Impl(USHORT nWh1, USHORT nWh2) +{ + DBG_CHKTHIS(SfxItemSet, 0); + _pWhichRanges = new USHORT[ 3 ]; + *(_pWhichRanges+0) = nWh1; + *(_pWhichRanges+1) = nWh2; + *(_pWhichRanges+2) = 0; + const USHORT nRg = nWh2 - nWh1 + 1; + _aItems = new const SfxPoolItem* [ nRg ]; + memset( (void*) _aItems, 0, nRg * sizeof( SfxPoolItem* ) ); +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::InitRanges_Impl(va_list pArgs, USHORT nWh1, USHORT nWh2, USHORT nNull) +{ + DBG_CHKTHIS(SfxItemSet, 0); + + USHORT nSize = InitializeRanges_Impl( _pWhichRanges, pArgs, nWh1, nWh2, nNull ); + _aItems = new const SfxPoolItem* [ nSize ]; + memset( (void*) _aItems, 0, sizeof( SfxPoolItem* ) * nSize ); +} + +// ----------------------------------------------------------------------- + +SfxItemSet::SfxItemSet( SfxItemPool& rPool, + USHORT_ARG nWh1, USHORT_ARG nWh2, USHORT_ARG nNull, ... ): + _pPool( &rPool ), + _pParent( 0 ), + _pWhichRanges( 0 ), + _nCount( 0 ) +{ + DBG_CTOR(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( nWh1 <= nWh2, "Ungueltiger Bereich" ); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); + DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); + + if(!nNull) + InitRanges_Impl( + sal::static_int_cast< USHORT >(nWh1), + sal::static_int_cast< USHORT >(nWh2)); + else { + va_list pArgs; + va_start( pArgs, nNull ); + InitRanges_Impl( + pArgs, sal::static_int_cast< USHORT >(nWh1), + sal::static_int_cast< USHORT >(nWh2), + sal::static_int_cast< USHORT >(nNull)); + } +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::InitRanges_Impl(const USHORT *pWhichPairTable) +{ + DBG_CHKTHIS(SfxItemSet, 0); + DBG_TRACE1("SfxItemSet: Ranges-CopyCount==%ul", ++nRangesCopyCount); + + USHORT nCnt = 0; + const USHORT* pPtr = pWhichPairTable; + while( *pPtr ) + { + nCnt += ( *(pPtr+1) - *pPtr ) + 1; + pPtr += 2; + } + + _aItems = new const SfxPoolItem* [ nCnt ]; + memset( (void*) _aItems, 0, sizeof( SfxPoolItem* ) * nCnt ); + + std::ptrdiff_t cnt = pPtr - pWhichPairTable +1; + _pWhichRanges = new USHORT[ cnt ]; + memcpy( _pWhichRanges, pWhichPairTable, sizeof( USHORT ) * cnt ); +} + + +// ----------------------------------------------------------------------- + +SfxItemSet::SfxItemSet( SfxItemPool& rPool, const USHORT* pWhichPairTable ): + _pPool( &rPool ), + _pParent( 0 ), + _pWhichRanges(0), + _nCount( 0 ) +{ + DBG_CTOR(SfxItemSet, 0); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); + DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); + + // pWhichPairTable == 0 ist f"ur das SfxAllEnumItemSet + if ( pWhichPairTable ) + InitRanges_Impl(pWhichPairTable); +} + +// ----------------------------------------------------------------------- + +SfxItemSet::SfxItemSet( const SfxItemSet& rASet ): + _pPool( rASet._pPool ), + _pParent( rASet._pParent ), + _nCount( rASet._nCount ) +{ + DBG_CTOR(SfxItemSet, DbgCheckItemSet); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); + DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); + DBG( ++*_pChildCount(_pParent) ); + + // errechne die Anzahl von Attributen + USHORT nCnt = 0; + USHORT* pPtr = rASet._pWhichRanges; + while( *pPtr ) + { + nCnt += ( *(pPtr+1) - *pPtr ) + 1; + pPtr += 2; + } + + _aItems = new const SfxPoolItem* [ nCnt ]; + + // Attribute kopieren + SfxItemArray ppDst = _aItems, ppSrc = rASet._aItems; + for( USHORT n = nCnt; n; --n, ++ppDst, ++ppSrc ) + if ( 0 == *ppSrc || // aktueller Default? + IsInvalidItem(*ppSrc) || // Dont Care? + IsStaticDefaultItem(*ppSrc) ) // nicht zu poolende Defaults + // einfach Pointer kopieren + *ppDst = *ppSrc; + else if ( _pPool->IsItemFlag( **ppSrc, SFX_ITEM_POOLABLE ) ) + { + // einfach Pointer kopieren und Ref-Count erh"ohen + *ppDst = *ppSrc; + ( (SfxPoolItem*) (*ppDst) )->AddRef(); + } + else if ( !(*ppSrc)->Which() ) + *ppDst = (*ppSrc)->Clone(); + else + // !IsPoolable() => via Pool zuweisen + *ppDst = &_pPool->Put( **ppSrc ); + + // dann noch die Which Ranges kopieren + DBG_TRACE1("SfxItemSet: Ranges-CopyCount==%ul", ++nRangesCopyCount); + std::ptrdiff_t cnt = pPtr - rASet._pWhichRanges+1; + _pWhichRanges = new USHORT[ cnt ]; + memcpy( _pWhichRanges, rASet._pWhichRanges, sizeof( USHORT ) * cnt); +} + +// ----------------------------------------------------------------------- + +SfxItemSet::~SfxItemSet() +{ + DBG_DTOR(SfxItemSet, DbgCheckItemSet); +#ifdef DBG_UTIL + DBG( DBG_ASSERT( 0 == *_pChildCount(this), "SfxItemSet: deleting parent-itemset" ) ) +#endif + + USHORT nCount = TotalCount(); + if( Count() ) + { + SfxItemArray ppFnd = _aItems; + for( USHORT nCnt = nCount; nCnt; --nCnt, ++ppFnd ) + if( *ppFnd && !IsInvalidItem(*ppFnd) ) + { + if( !(*ppFnd)->Which() ) + delete (SfxPoolItem*) *ppFnd; + else { + // noch mehrer Referenzen vorhanden, also nur den + // ReferenzCounter manipulieren + if ( 1 < (*ppFnd)->GetRefCount() && !IsDefaultItem(*ppFnd) ) + (*ppFnd)->ReleaseRef(); + else + if ( !IsDefaultItem(*ppFnd) ) + // aus dem Pool loeschen + _pPool->Remove( **ppFnd ); + } + } + } + + // FIXME: could be delete[] (SfxPoolItem **)_aItems; + delete[] _aItems; + if ( _pWhichRanges != _pPool->GetFrozenIdRanges() ) + delete[] _pWhichRanges; + _pWhichRanges = 0; // for invariant-testing + + DBG( --*_pChildCount(_pParent) ); + DBG( delete _pChildCount(this); _pChildCountDtor ); +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemSet::ClearItem( USHORT nWhich ) + +// einzelnes Item oder alle Items (nWhich==0) l"oschen + +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + if( !Count() ) + return 0; + + USHORT nDel = 0; + SfxItemArray ppFnd = _aItems; + + if( nWhich ) + { + const USHORT* pPtr = _pWhichRanges; + while( *pPtr ) + { + // in diesem Bereich? + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // "uberhaupt gesetzt? + ppFnd += nWhich - *pPtr; + if( *ppFnd ) + { + // wegen der Assertions ins Sub-Calls mu\s das hier sein + --_nCount; + const SfxPoolItem *pItemToClear = *ppFnd; + *ppFnd = 0; + + if ( !IsInvalidItem(pItemToClear) ) + { + if ( nWhich <= SFX_WHICH_MAX ) + { + const SfxPoolItem& rNew = _pParent + ? _pParent->Get( nWhich, TRUE ) + : _pPool->GetDefaultItem( nWhich ); + + Changed( *pItemToClear, rNew ); + } + if ( pItemToClear->Which() ) + _pPool->Remove( *pItemToClear ); + } + ++nDel; + } + + // gefunden => raus + break; + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + } + else + { + nDel = _nCount; + + USHORT* pPtr = _pWhichRanges; + while( *pPtr ) + { + for( nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) + if( *ppFnd ) + { + // wegen der Assertions ins Sub-Calls mu\s das hier sein + --_nCount; + const SfxPoolItem *pItemToClear = *ppFnd; + *ppFnd = 0; + + if ( !IsInvalidItem(pItemToClear) ) + { + if ( nWhich <= SFX_WHICH_MAX ) + { + const SfxPoolItem& rNew = _pParent + ? _pParent->Get( nWhich, TRUE ) + : _pPool->GetDefaultItem( nWhich ); + + Changed( *pItemToClear, rNew ); + } + + // #i32448# + // Take care of disabled items, too. + if(!pItemToClear->nWhich) + { + // item is disabled, delete it + delete pItemToClear; + } + else + { + // remove item from pool + _pPool->Remove( *pItemToClear ); + } + } + } + pPtr += 2; + } + } + return nDel; +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::ClearInvalidItems( BOOL bHardDefault ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + USHORT* pPtr = _pWhichRanges; + SfxItemArray ppFnd = _aItems; + if ( bHardDefault ) + while( *pPtr ) + { + for ( USHORT nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) + if ( IsInvalidItem(*ppFnd) ) + *ppFnd = &_pPool->Put( _pPool->GetDefaultItem(nWhich) ); + pPtr += 2; + } + else + while( *pPtr ) + { + for( USHORT nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) + if( IsInvalidItem(*ppFnd) ) + { + *ppFnd = 0; + --_nCount; + } + pPtr += 2; + } +} + +//------------------------------------------------------------------------ + + +void SfxItemSet::InvalidateAllItems() +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( !_nCount, "Es sind noch Items gesetzt" ); + + memset( (void*)_aItems, -1, ( _nCount = TotalCount() ) * sizeof( SfxPoolItem*) ); +} + +// ----------------------------------------------------------------------- + +SfxItemState SfxItemSet::GetItemState( USHORT nWhich, + BOOL bSrchInParent, + const SfxPoolItem **ppItem ) const +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + // suche den Bereich in dem das Which steht: + const SfxItemSet* pAktSet = this; + SfxItemState eRet = SFX_ITEM_UNKNOWN; + do + { + SfxItemArray ppFnd = pAktSet->_aItems; + const USHORT* pPtr = pAktSet->_pWhichRanges; + if (pPtr) + { + while ( *pPtr ) + { + if ( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // in diesem Bereich + ppFnd += nWhich - *pPtr; + if ( !*ppFnd ) + { + eRet = SFX_ITEM_DEFAULT; + if( !bSrchInParent ) + return eRet; // nicht vorhanden + break; // JP: in den Parents weitersuchen !!! + } + + if ( (SfxPoolItem*) -1 == *ppFnd ) + // Unterschiedlich vorhanden + return SFX_ITEM_DONTCARE; + + if ( (*ppFnd)->Type() == TYPE(SfxVoidItem) ) + return SFX_ITEM_DISABLED; + + if (ppItem) + { + #ifdef DBG_UTIL + const SfxPoolItem *pItem = *ppFnd; + DBG_ASSERT( !pItem->ISA(SfxSetItem) || + 0 != &((const SfxSetItem*)pItem)->GetItemSet(), + "SetItem without ItemSet" ); + #endif + *ppItem = *ppFnd; + } + return SFX_ITEM_SET; + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + } + } while( bSrchInParent && 0 != ( pAktSet = pAktSet->_pParent )); + return eRet; +} + +// ----------------------------------------------------------------------- + +const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, USHORT nWhich ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( !rItem.ISA(SfxSetItem) || + 0 != &((const SfxSetItem&)rItem).GetItemSet(), + "SetItem without ItemSet" ); + if ( !nWhich ) + return 0; //! nur wegen Outliner-Bug + SfxItemArray ppFnd = _aItems; + const USHORT* pPtr = _pWhichRanges; + while( *pPtr ) + { + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // in diesem Bereich + ppFnd += nWhich - *pPtr; + if( *ppFnd ) // schon einer vorhanden + { + // selbes Item bereits vorhanden? + if ( *ppFnd == &rItem ) + return 0; + + // wird dontcare oder disabled mit was echtem ueberschrieben? + if ( rItem.Which() && ( IsInvalidItem(*ppFnd) || !(*ppFnd)->Which() ) ) + { + *ppFnd = &_pPool->Put( rItem, nWhich ); + return *ppFnd; + } + + // wird disabled? + if( !rItem.Which() ) + { + *ppFnd = rItem.Clone(_pPool); + return 0; + } + else + { + // selber Wert bereits vorhanden? + if ( rItem == **ppFnd ) + return 0; + + // den neuen eintragen, den alten austragen + const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich ); + const SfxPoolItem* pOld = *ppFnd; + *ppFnd = &rNew; + if(nWhich <= SFX_WHICH_MAX) + Changed( *pOld, rNew ); + _pPool->Remove( *pOld ); + } + } + else + { + ++_nCount; + if( !rItem.Which() ) + *ppFnd = rItem.Clone(_pPool); + else { + const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich ); + *ppFnd = &rNew; + if (nWhich <= SFX_WHICH_MAX ) + { + const SfxPoolItem& rOld = _pParent + ? _pParent->Get( nWhich, TRUE ) + : _pPool->GetDefaultItem( nWhich ); + Changed( rOld, rNew ); + } + } + } + SFX_ASSERT( !_pPool->IsItemFlag(nWhich, SFX_ITEM_POOLABLE) || + rItem.ISA(SfxSetItem) || **ppFnd == rItem, + nWhich, "putted Item unequal" ); + return *ppFnd; + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + return 0; +} + +// ----------------------------------------------------------------------- + +int SfxItemSet::Put( const SfxItemSet& rSet, BOOL bInvalidAsDefault ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + BOOL bRet = FALSE; + if( rSet.Count() ) + { + SfxItemArray ppFnd = rSet._aItems; + const USHORT* pPtr = rSet._pWhichRanges; + while ( *pPtr ) + { + for ( USHORT nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) + if( *ppFnd ) + { + if ( IsInvalidItem( *ppFnd ) ) + { + if ( bInvalidAsDefault ) + bRet |= 0 != ClearItem( nWhich ); + // gab GPF bei non.WIDs: + // bRet |= 0 != Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich ); + else + InvalidateItem( nWhich ); + } + else + bRet |= 0 != Put( **ppFnd, nWhich ); + } + pPtr += 2; + } + } + return bRet; +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::PutExtended +( + const SfxItemSet& rSet, // Quelle der zu puttenden Items + SfxItemState eDontCareAs, // was mit DontCare-Items passiert + SfxItemState eDefaultAs // was mit Default-Items passiert +) + +/* [Beschreibung] + + Diese Methode "ubernimmt die Items aus 'rSet' in '*this'. Die + Which-Bereiche in '*this', die in 'rSet' nicht vorkommen bleiben unver- + "andert. Der Which-Bereich von '*this' bleibt auch unver"andert. + + In 'rSet' gesetzte Items werden auch in '*this*' gesetzt. Default- + (0 Pointer) und Invalid- (-1 Pointer) Items werden je nach Parameter + ('eDontCareAs' und 'eDefaultAs' behandelt: + + SFX_ITEM_SET: hart auf Default des Pools gesetzt + SFX_ITEM_DEFAULT: gel"oscht (0 Pointer) + SFX_ITEM_DONTCARE: invalidiert (-1 Pointer) + + Alle anderen Werte f"ur 'eDontCareAs' und 'eDefaultAs' sind ung"ultig. +*/ + +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + + // don't "optimize" with "if( rSet.Count()" because of dont-care + defaults + SfxItemArray ppFnd = rSet._aItems; + const USHORT* pPtr = rSet._pWhichRanges; + while ( *pPtr ) + { + for ( USHORT nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) + if( *ppFnd ) + { + if ( IsInvalidItem( *ppFnd ) ) + { + // Item ist DontCare: + switch ( eDontCareAs ) + { + case SFX_ITEM_SET: + Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich ); + break; + + case SFX_ITEM_DEFAULT: + ClearItem( nWhich ); + break; + + case SFX_ITEM_DONTCARE: + InvalidateItem( nWhich ); + break; + + default: + DBG_ERROR( "invalid Argument for eDontCareAs" ); + } + } + else + // Item ist gesetzt: + Put( **ppFnd, nWhich ); + } + else + { + // Item ist Default: + switch ( eDefaultAs ) + { + case SFX_ITEM_SET: + Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich ); + break; + + case SFX_ITEM_DEFAULT: + ClearItem( nWhich ); + break; + + case SFX_ITEM_DONTCARE: + InvalidateItem( nWhich ); + break; + + default: + DBG_ERROR( "invalid Argument for eDefaultAs" ); + } + } + pPtr += 2; + } +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::MergeRange( USHORT nFrom, USHORT nTo ) +/** <H3>Description</H3> + + Expands the ranges of settable items by 'nFrom' to 'nTo'. Keeps state of + items which are new ranges too. +*/ + +{ + // special case: exactly one USHORT which is already included? + if ( nFrom == nTo && SFX_ITEM_AVAILABLE <= GetItemState(nFrom, FALSE) ) + return; + + // merge new range + SfxUShortRanges aRanges( _pWhichRanges ); + aRanges += SfxUShortRanges( nFrom, nTo ); + SetRanges( aRanges ); +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::SetRanges( const USHORT *pNewRanges ) + +/** <H3>Description</H3> + + Modifies the ranges of settable items. Keeps state of items which + are new ranges too. +*/ + +{ + // identische Ranges? + if ( _pWhichRanges == pNewRanges ) + return; + const USHORT* pOld = _pWhichRanges; + const USHORT* pNew = pNewRanges; + while ( *pOld == *pNew ) + { + if ( !*pOld && !*pNew ) + return; + ++pOld, ++pNew; + } + + // create new item-array (by iterating through all new ranges) + ULONG nSize = Capacity_Impl(pNewRanges); + SfxItemArray aNewItems = new const SfxPoolItem* [ nSize ]; + USHORT n = 0, nNewCount = 0; + if ( _nCount == 0 ) + memset( aNewItems, 0, nSize * sizeof( SfxPoolItem* ) ); + else + { + for ( const USHORT *pRange = pNewRanges; *pRange; pRange += 2 ) + { + // iterate through all ids in the range + for ( USHORT nWID = *pRange; nWID <= pRange[1]; ++nWID, ++n ) + { + // direct move of pointer (not via pool) + SfxItemState eState = GetItemState( nWID, FALSE, aNewItems+n ); + if ( SFX_ITEM_SET == eState ) + { + // increment new item count and possibly increment ref count + ++nNewCount; + aNewItems[n]->AddRef(); + } + else if ( SFX_ITEM_DISABLED == eState ) + { + // put "disabled" item + ++nNewCount; + aNewItems[n] = new SfxVoidItem(0); + } + else if ( SFX_ITEM_DONTCARE == eState ) + { + ++nNewCount; + aNewItems[n] = (SfxPoolItem*)-1; + } + else + { + // default + aNewItems[n] = 0; + } + } + } + // free old items + USHORT nOldTotalCount = TotalCount(); + for ( USHORT nItem = 0; nItem < nOldTotalCount; ++nItem ) + { + const SfxPoolItem *pItem = _aItems[nItem]; + if ( pItem && !IsInvalidItem(pItem) && pItem->Which() ) + _pPool->Remove(*pItem); + } + } + + // replace old items-array and ranges + delete[] _aItems; + _aItems = aNewItems; + _nCount = nNewCount; + + if( pNewRanges == GetPool()->GetFrozenIdRanges() ) + { + delete[] _pWhichRanges; + _pWhichRanges = ( USHORT* ) pNewRanges; + } + else + { + USHORT nCount = Count_Impl(pNewRanges) + 1; + if ( _pWhichRanges != _pPool->GetFrozenIdRanges() ) + delete[] _pWhichRanges; + _pWhichRanges = new USHORT[ nCount ]; + memcpy( _pWhichRanges, pNewRanges, sizeof( USHORT ) * nCount ); + } +} + +// ----------------------------------------------------------------------- + +int SfxItemSet::Set +( + const SfxItemSet& rSet, /* das SfxItemSet, dessen SfxPoolItems + "ubernommen werden sollen */ + + BOOL bDeep /* TRUE (default) + auch die SfxPoolItems aus den ggf. an + rSet vorhandenen Parents werden direkt + in das SfxItemSet "ubernommen + + FALSE + die SfxPoolItems aus den Parents von + rSet werden nicht ber"ucksichtigt */ +) + +/* [Beschreibung] + + Das SfxItemSet nimmt genau die SfxPoolItems an, die auch in + rSet gesetzt sind und im eigenen <Which-Bereich> liegen. Alle + anderen werden entfernt. Der SfxItemPool wird dabei beibehalten, + so da"s die "ubernommenen SfxPoolItems dabei ggf. vom SfxItemPool + von rSet in den SfxItemPool von *this "ubernommen werden. + + SfxPoolItems, f"ur die in rSet IsInvalidItem() == TRUE gilt, + werden als Invalid-Item "ubernommen. + + + [R"uckgabewert] + + int TRUE + es wurden SfxPoolItems "ubernommen + + FALSE + es wurden keine SfxPoolItems "ubernommen, + da z.B. die Which-Bereiche der SfxItemSets + keine Schnittmenge haben oder in der + Schnittmenge keine SfxPoolItems in rSet + gesetzt sind + +*/ + +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + int bRet = FALSE; + if ( _nCount ) + ClearItem(); + if ( bDeep ) + { + SfxWhichIter aIter(*this); + USHORT nWhich = aIter.FirstWhich(); + while ( nWhich ) + { + const SfxPoolItem* pItem; + if( SFX_ITEM_SET == rSet.GetItemState( nWhich, TRUE, &pItem ) ) + bRet |= 0 != Put( *pItem, pItem->Which() ); + nWhich = aIter.NextWhich(); + } + } + else + bRet = Put(rSet, FALSE); + + return bRet; +} + +//------------------------------------------------------------------------ + +const SfxPoolItem* SfxItemSet::GetItem +( + USHORT nId, // Slot-Id oder Which-Id des Items + BOOL bSrchInParent, // TRUE: auch in Parent-ItemSets suchen + TypeId aItemType // != 0 => RTTI Pruefung mit Assertion +) const + +/* [Beschreibung] + + Mit dieser Methode wird der Zugriff auf einzelne Items im + SfxItemSet wesentlich vereinfacht. Insbesondere wird die Typpr"ufung + (per Assertion) durchgef"uhrt, wodurch die Applikations-Sourcen + wesentlich "ubersichtlicher werden. In der PRODUCT-Version wird + eine 0 zur"uckgegeben, wenn das gefundene Item nicht von der + angegebenen Klasse ist. Ist kein Item mit der Id 'nWhich' in dem ItemSet, + so wird 0 zurueckgegeben. +*/ + +{ + // ggf. in Which-Id umrechnen + USHORT nWhich = GetPool()->GetWhich(nId); + + // ist das Item gesetzt oder bei bDeep==TRUE verf"ugbar? + const SfxPoolItem *pItem = 0; + SfxItemState eState = GetItemState( nWhich, bSrchInParent, &pItem ); + if ( bSrchInParent && SFX_ITEM_AVAILABLE == eState && + nWhich <= SFX_WHICH_MAX ) + pItem = &_pPool->GetDefaultItem(nWhich); + if ( pItem ) + { + // stimmt der Typ "uberein? + if ( !aItemType || pItem->IsA(aItemType) ) + return pItem; + + // sonst Fehler melden + DBG_ERROR( "invalid argument type" ); + } + + // kein Item gefunden oder falschen Typ gefunden + return 0; +} + + +//------------------------------------------------------------------------ + + +const SfxPoolItem& SfxItemSet::Get( USHORT nWhich, BOOL bSrchInParent) const +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + // suche den Bereich in dem das Which steht: + const SfxItemSet* pAktSet = this; + do + { + if( pAktSet->Count() ) + { + SfxItemArray ppFnd = pAktSet->_aItems; + const USHORT* pPtr = pAktSet->_pWhichRanges; + while( *pPtr ) + { + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // in diesem Bereich + ppFnd += nWhich - *pPtr; + if( *ppFnd ) + { + if( (SfxPoolItem*)-1 == *ppFnd ) { + //?MI: folgender code ist Doppelt (unten) + SFX_ASSERT(_pPool, nWhich, "kein Pool, aber Status uneindeutig"); + //!((SfxAllItemSet *)this)->aDefault.SetWhich(nWhich); + //!return aDefault; + return _pPool->GetDefaultItem( nWhich ); + } +#ifdef DBG_UTIL + const SfxPoolItem *pItem = *ppFnd; + DBG_ASSERT( !pItem->ISA(SfxSetItem) || + 0 != &((const SfxSetItem*)pItem)->GetItemSet(), + "SetItem without ItemSet" ); + if ( pItem->ISA(SfxVoidItem) || !pItem->Which() ) + DBG_WARNING( "SFX_WARNING: Getting disabled Item" ); +#endif + return **ppFnd; + } + break; // dann beim Parent suchen + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + } +// bis zum Ende vom Such-Bereich: was nun ? zum Parent, oder Default ?? +// if( !*pPtr ) // bis zum Ende vom Such-Bereich ? +// break; + } while( bSrchInParent && 0 != ( pAktSet = pAktSet->_pParent )); + + // dann das Default vom Pool holen und returnen + SFX_ASSERT(_pPool, nWhich, "kein Pool, aber Status uneindeutig"); + const SfxPoolItem *pItem = &_pPool->GetDefaultItem( nWhich ); + DBG_ASSERT( !pItem->ISA(SfxSetItem) || + 0 != &((const SfxSetItem*)pItem)->GetItemSet(), + "SetItem without ItemSet" ); + return *pItem; +} + + // Notification-Callback +// ----------------------------------------------------------------------- + +void SfxItemSet::Changed( const SfxPoolItem&, const SfxPoolItem& ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemSet::TotalCount() const +{ + DBG_CHKTHIS(SfxItemSet, 0); // wird im Ctor benutzt bevor vollst. init. + USHORT nRet = 0; + USHORT* pPtr = _pWhichRanges; + while( *pPtr ) + { + nRet += ( *(pPtr+1) - *pPtr ) + 1; + pPtr += 2; + } + return nRet; +} +// ----------------------------------------------------------------------- + +// behalte nur die Items, die auch in rSet enthalten sein (Wert egal) + +void SfxItemSet::Intersect( const SfxItemSet& rSet ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT(_pPool, "nicht implementiert ohne Pool"); + if( !Count() ) // gar keine gesetzt ? + return; + + // loesche alle Items, die im rSet nicht mehr vorhanden sind + if( !rSet.Count() ) + { + ClearItem(); // alles loeschen + return; + } + + // teste mal, ob sich die Which-Bereiche unterscheiden. + BOOL bEqual = TRUE; + USHORT* pWh1 = _pWhichRanges; + USHORT* pWh2 = rSet._pWhichRanges; + USHORT nSize = 0; + + for( USHORT n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n ) + { + if( *pWh1 != *pWh2 ) + { + bEqual = FALSE; + break; + } + if( n & 1 ) + nSize += ( *(pWh1) - *(pWh1-1) ) + 1; + } + bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen + + // sind die Bereiche identisch, ist es einfacher zu handhaben ! + if( bEqual ) + { + SfxItemArray ppFnd1 = _aItems; + SfxItemArray ppFnd2 = rSet._aItems; + + for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 ) + if( *ppFnd1 && !*ppFnd2 ) + { + // aus dem Pool loeschen + if( !IsInvalidItem( *ppFnd1 ) ) + { + USHORT nWhich = (*ppFnd1)->Which(); + if(nWhich <= SFX_WHICH_MAX) + { + const SfxPoolItem& rNew = _pParent + ? _pParent->Get( nWhich, TRUE ) + : _pPool->GetDefaultItem( nWhich ); + + Changed( **ppFnd1, rNew ); + } + _pPool->Remove( **ppFnd1 ); + } + *ppFnd1 = 0; + --_nCount; + } + } + else + { + SfxItemIter aIter( *this ); + const SfxPoolItem* pItem = aIter.GetCurItem(); + while( TRUE ) + { + USHORT nWhich = IsInvalidItem( pItem ) + ? GetWhichByPos( aIter.GetCurPos() ) + : pItem->Which(); + if( 0 == rSet.GetItemState( nWhich, FALSE ) ) + ClearItem( nWhich ); // loeschen + if( aIter.IsAtEnd() ) + break; + pItem = aIter.NextItem(); + } + } +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::Differentiate( const SfxItemSet& rSet ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + if( !Count() || !rSet.Count() ) // gar keine gesetzt ? + return; + + // teste mal, ob sich die Which-Bereiche unterscheiden. + BOOL bEqual = TRUE; + USHORT* pWh1 = _pWhichRanges; + USHORT* pWh2 = rSet._pWhichRanges; + USHORT nSize = 0; + + for( USHORT n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n ) + { + if( *pWh1 != *pWh2 ) + { + bEqual = FALSE; + break; + } + if( n & 1 ) + nSize += ( *(pWh1) - *(pWh1-1) ) + 1; + } + bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen + + // sind die Bereiche identisch, ist es einfacher zu handhaben ! + if( bEqual ) + { + SfxItemArray ppFnd1 = _aItems; + SfxItemArray ppFnd2 = rSet._aItems; + + for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 ) + if( *ppFnd1 && *ppFnd2 ) + { + // aus dem Pool loeschen + if( !IsInvalidItem( *ppFnd1 ) ) + { + USHORT nWhich = (*ppFnd1)->Which(); + if(nWhich <= SFX_WHICH_MAX) + { + const SfxPoolItem& rNew = _pParent + ? _pParent->Get( nWhich, TRUE ) + : _pPool->GetDefaultItem( nWhich ); + + Changed( **ppFnd1, rNew ); + } + _pPool->Remove( **ppFnd1 ); + } + *ppFnd1 = 0; + --_nCount; + } + } + else + { + SfxItemIter aIter( *this ); + const SfxPoolItem* pItem = aIter.GetCurItem(); + while( TRUE ) + { + USHORT nWhich = IsInvalidItem( pItem ) + ? GetWhichByPos( aIter.GetCurPos() ) + : pItem->Which(); + if( SFX_ITEM_SET == rSet.GetItemState( nWhich, FALSE ) ) + ClearItem( nWhich ); // loeschen + if( aIter.IsAtEnd() ) + break; + pItem = aIter.NextItem(); + } + + } +} + +// ----------------------------------------------------------------------- +/* Entscheidungstabelle fuer MergeValue[s] + +Grundsaetze: + 1. Ist der Which-Wert im 1.Set "unknown", dann folgt niemals eine Aktion. + 2. Ist der Which-Wert im 2.Set "unknown", dann gilt er als "default". + 3. Es gelten fuer Vergleiche die Werte der "default"-Items. + +1.-Item 2.-Item Values bIgnoreDefs Remove Assign Add + +set set == FALSE - - - +default set == FALSE - - - +dontcare set == FALSE - - - +unknown set == FALSE - - - +set default == FALSE - - - +default default == FALSE - - - +dontcare default == FALSE - - - +unknown default == FALSE - - - +set dontcare == FALSE 1.-Item -1 - +default dontcare == FALSE - -1 - +dontcare dontcare == FALSE - - - +unknown dontcare == FALSE - - - +set unknown == FALSE 1.-Item -1 - +default unknown == FALSE - - - +dontcare unknown == FALSE - - - +unknown unknown == FALSE - - - + +set set != FALSE 1.-Item -1 - +default set != FALSE - -1 - +dontcare set != FALSE - - - +unknown set != FALSE - - - +set default != FALSE 1.-Item -1 - +default default != FALSE - - - +dontcare default != FALSE - - - +unknown default != FALSE - - - +set dontcare != FALSE 1.-Item -1 - +default dontcare != FALSE - -1 - +dontcare dontcare != FALSE - - - +unknown dontcare != FALSE - - - +set unknown != FALSE 1.-Item -1 - +default unknown != FALSE - - - +dontcare unknown != FALSE - - - +unknown unknown != FALSE - - - + +set set == TRUE - - - +default set == TRUE - 2.-Item 2.-Item +dontcare set == TRUE - - - +unknown set == TRUE - - - +set default == TRUE - - - +default default == TRUE - - - +dontcare default == TRUE - - - +unknown default == TRUE - - - +set dontcare == TRUE - - - +default dontcare == TRUE - -1 - +dontcare dontcare == TRUE - - - +unknown dontcare == TRUE - - - +set unknown == TRUE - - - +default unknown == TRUE - - - +dontcare unknown == TRUE - - - +unknown unknown == TRUE - - - + +set set != TRUE 1.-Item -1 - +default set != TRUE - 2.-Item 2.-Item +dontcare set != TRUE - - - +unknown set != TRUE - - - +set default != TRUE - - - +default default != TRUE - - - +dontcare default != TRUE - - - +unknown default != TRUE - - - +set dontcare != TRUE 1.-Item -1 - +default dontcare != TRUE - -1 - +dontcare dontcare != TRUE - - - +unknown dontcare != TRUE - - - +set unknown != TRUE - - - +default unknown != TRUE - - - +dontcare unknown != TRUE - - - +unknown unknown != TRUE - - - +*/ + + +static void MergeItem_Impl( SfxItemPool *_pPool, USHORT &rCount, + const SfxPoolItem **ppFnd1, const SfxPoolItem *pFnd2, + BOOL bIgnoreDefaults ) +{ + DBG_ASSERT( ppFnd1 != 0, "Merging to 0-Item" ); + + // 1. Item ist default? + if ( !*ppFnd1 ) + { + if ( IsInvalidItem(pFnd2) ) + // Entscheidungstabelle: default, dontcare, egal, egal + *ppFnd1 = (SfxPoolItem*) -1; + + else if ( pFnd2 && !bIgnoreDefaults && + _pPool->GetDefaultItem(pFnd2->Which()) != *pFnd2 ) + // Entscheidungstabelle: default, set, !=, FALSE + *ppFnd1 = (SfxPoolItem*) -1; + + else if ( pFnd2 && bIgnoreDefaults ) + // Entscheidungstabelle: default, set, egal, TRUE + *ppFnd1 = &_pPool->Put( *pFnd2 ); + + if ( *ppFnd1 ) + ++rCount; + } + + // 1. Item ist gesetzt? + else if ( !IsInvalidItem(*ppFnd1) ) + { + if ( !pFnd2 ) + { + // 2. Item ist default + if ( !bIgnoreDefaults && + **ppFnd1 != _pPool->GetDefaultItem((*ppFnd1)->Which()) ) + { + // Entscheidungstabelle: set, default, !=, FALSE + _pPool->Remove( **ppFnd1 ); + *ppFnd1 = (SfxPoolItem*) -1; + } + } + else if ( IsInvalidItem(pFnd2) ) + { + // 2. Item ist dontcare + if ( !bIgnoreDefaults || + **ppFnd1 != _pPool->GetDefaultItem( (*ppFnd1)->Which()) ) + { + // Entscheidungstabelle: set, dontcare, egal, FALSE + // oder: set, dontcare, !=, TRUE + _pPool->Remove( **ppFnd1 ); + *ppFnd1 = (SfxPoolItem*) -1; + } + } + else + { + // 2. Item ist gesetzt + if ( **ppFnd1 != *pFnd2 ) + { + // Entscheidungstabelle: set, set, !=, egal + _pPool->Remove( **ppFnd1 ); + *ppFnd1 = (SfxPoolItem*) -1; + } + } + } +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::MergeValues( const SfxItemSet& rSet, BOOL bIgnoreDefaults ) +{ + // Achtung!!! Bei Aenderungen/Bugfixes immer obenstehende Tabelle pflegen! + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( GetPool() == rSet.GetPool(), "MergeValues mit verschiedenen Pools" ); + + // teste mal, ob sich die Which-Bereiche unterscheiden. + BOOL bEqual = TRUE; + USHORT* pWh1 = _pWhichRanges; + USHORT* pWh2 = rSet._pWhichRanges; + USHORT nSize = 0; + + for( USHORT n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n ) + { + if( *pWh1 != *pWh2 ) + { + bEqual = FALSE; + break; + } + if( n & 1 ) + nSize += ( *(pWh1) - *(pWh1-1) ) + 1; + } + bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen + + // sind die Bereiche identisch, ist es effizieter zu handhaben ! + if( bEqual ) + { + SfxItemArray ppFnd1 = _aItems; + SfxItemArray ppFnd2 = rSet._aItems; + + for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 ) + MergeItem_Impl( _pPool, _nCount, ppFnd1, *ppFnd2, bIgnoreDefaults ); + } + else + { + SfxWhichIter aIter( rSet ); + register USHORT nWhich; + while( 0 != ( nWhich = aIter.NextWhich() ) ) + { + const SfxPoolItem* pItem = 0; + rSet.GetItemState( nWhich, TRUE, &pItem ); + if( !pItem ) + { + // nicht gesetzt, also default + if ( !bIgnoreDefaults ) + MergeValue( rSet.GetPool()->GetDefaultItem( nWhich ), bIgnoreDefaults ); + } + else if( IsInvalidItem( pItem ) ) + // dont care + InvalidateItem( nWhich ); + else + MergeValue( *pItem, bIgnoreDefaults ); + } + } +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::MergeValue( const SfxPoolItem& rAttr, BOOL bIgnoreDefaults ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + SfxItemArray ppFnd = _aItems; + const USHORT* pPtr = _pWhichRanges; + const USHORT nWhich = rAttr.Which(); + while( *pPtr ) + { + // in diesem Bereich? + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + ppFnd += nWhich - *pPtr; + MergeItem_Impl( _pPool, _nCount, ppFnd, &rAttr, bIgnoreDefaults ); + break; + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } +} + +// ----------------------------------------------------------------------- + +void SfxItemSet::InvalidateItem( USHORT nWhich ) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + SfxItemArray ppFnd = _aItems; + const USHORT* pPtr = _pWhichRanges; + while( *pPtr ) + { + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // in diesem Bereich + ppFnd += nWhich - *pPtr; + + if( *ppFnd ) // bei mir gesetzt + { + if( (SfxPoolItem*)-1 != *ppFnd ) // noch nicht dontcare ! + { + _pPool->Remove( **ppFnd ); + *ppFnd = (SfxPoolItem*)-1; + } + } + else + { + *ppFnd = (SfxPoolItem*)-1; + ++_nCount; + } + break; + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemSet::GetWhichByPos( USHORT nPos ) const +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + USHORT n = 0; + USHORT* pPtr = _pWhichRanges; + while( *pPtr ) + { + n = ( *(pPtr+1) - *pPtr ) + 1; + if( nPos < n ) + return *(pPtr)+nPos; + nPos = nPos - n; + pPtr += 2; + } + DBG_ASSERT( FALSE, "Hier sind wir falsch" ); + return 0; +} + +// ----------------------------------------------------------------------- + +SvStream &SfxItemSet::Store +( + SvStream& rStream, // Zielstream f"ur normale Items + FASTBOOL bDirect // TRUE: Items direkt speicher, FALSE: Surrogate +) const + +/* [Beschreibung] + + Speichert die <SfxItemSet>-Instanz in den angegebenen Stream. Dabei + werden die Surrorage der gesetzten <SfxPoolItem>s bzw. ('bDirect==TRUE') + die gesetzten Items selbst wie folgt im Stream abgelegt: + + USHORT (Count) Anzahl der gesetzten Items + Count* _pPool->StoreItem() siehe <SfxItemPool::StoreItem()const> + + + [Querverweise] + + <SfxItemSet::Load(SvStream&,BOOL,const SfxItemPool*)> +*/ + +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( _pPool, "Kein Pool" ); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); + + // Position des Counts merken, um ggf. zu korrigieren + ULONG nCountPos = rStream.Tell(); + rStream << _nCount; + + // wenn nichts zu speichern ist, auch keinen ItemIter aufsetzen! + if ( _nCount ) + { + // mitz"ahlen wieviel Items tats"achlich gespeichert werden + USHORT nWrittenCount = 0; // Anzahl in 'rStream' gestreamter Items + + // "uber alle gesetzten Items iterieren + SfxItemIter aIter(*this); + for ( const SfxPoolItem *pItem = aIter.FirstItem(); + pItem; + pItem = aIter.NextItem() ) + { + // Item (ggf. als Surrogat) via Pool speichern lassen + DBG_ASSERT( !IsInvalidItem(pItem), "can't store invalid items" ); + if ( !IsInvalidItem(pItem) && + _pPool->StoreItem( rStream, *pItem, bDirect ) ) + // Item wurde in 'rStream' gestreamt + ++nWrittenCount; + }; + + // weniger geschrieben als enthalten (z.B. altes Format) + if ( nWrittenCount != _nCount ) + { + // tats"achlichen Count im Stream ablegen + ULONG nPos = rStream.Tell(); + rStream.Seek( nCountPos ); + rStream << nWrittenCount; + rStream.Seek( nPos ); + } + } + + return rStream; +} + +// ----------------------------------------------------------------------- + +SvStream &SfxItemSet::Load +( + SvStream& rStream, // Stream, aus dem geladen werden soll + + FASTBOOL bDirect, /* TRUE + Items werden direkt aus dem Stream + gelesen, nicht "uber Surrogate + + FALSE (default) + Items werden "uber Surrogate gelesen */ + + const SfxItemPool* pRefPool /* Pool, der die Surrogate aufl"osen kann + (z.B. zum Einf"ugen von Dokumenten) */ +) + +/* [Beschreibung] + + Diese Methode l"adt ein <SfxItemSet> aus einem Stream. Falls der + <SfxItemPool> ohne Ref-Counts geladen wurde, werden die geladenen + Item-Referenzen in den Items hochgez"ahlt, ansonsten wird vorausgesetzt, + da\s sie schon beim Laden des SfxItemPools ber"ucksichtigt waren. + + [Querverweise] + + <SfxItemSet::Store(Stream&,BOOL)const> +*/ + +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_ASSERT( _pPool, "Kein Pool"); + DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "Kein Master-Pool"); + + // kein Ref-Pool => Surrogate mit Pool des ItemSets aufl"osen + if ( !pRefPool ) + pRefPool = _pPool; + + // Anzahl der zu ladenden Items laden und dann ebensoviele Items + USHORT nCount = 0; + rStream >> nCount; + for ( USHORT i = 0; i < nCount; ++i ) + { + // Surrogat/Item laden und (Surrogat) aufl"osen lassen + const SfxPoolItem *pItem = + _pPool->LoadItem( rStream, bDirect, pRefPool ); + + // konnte ein Item geladen oder via Surrogat aufgel"ost werden? + if ( pItem ) + { + // Position f"ur Item-Pointer im Set suchen + USHORT nWhich = pItem->Which(); + SfxItemArray ppFnd = _aItems; + const USHORT* pPtr = _pWhichRanges; + while ( *pPtr ) + { + // in diesem Bereich? + if ( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // Item-Pointer im Set merken + ppFnd += nWhich - *pPtr; + SFX_ASSERT( !*ppFnd, nWhich, "Item doppelt eingetragen"); + *ppFnd = pItem; + ++_nCount; + break; + } + + // im Range-Array und Item-Array zum n"achsten Which-Range + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + } + } + + return rStream; +} + +// ----------------------------------------------------------------------- + +int SfxItemSet::operator==(const SfxItemSet &rCmp) const +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + DBG_CHKOBJ(&rCmp, SfxItemSet, DbgCheckItemSet); + + // besonders schnell zu ermittelnde Werte muessen gleich sein + if ( _pParent != rCmp._pParent || + _pPool != rCmp._pPool || + Count() != rCmp.Count() ) + return FALSE; + + // Ranges durchzaehlen lassen dauert laenger, muss aber auch gleich sein + USHORT nCount1 = TotalCount(); + USHORT nCount2 = rCmp.TotalCount(); + if ( nCount1 != nCount2 ) + return FALSE; + + // sind die Ranges selbst ungleich? + for ( USHORT nRange = 0; _pWhichRanges[nRange]; nRange += 2 ) + if ( _pWhichRanges[nRange] != rCmp._pWhichRanges[nRange] || + _pWhichRanges[nRange+1] != rCmp._pWhichRanges[nRange+1] ) + { + // dann m"ussen wir die langsame Methode verwenden + SfxWhichIter aIter( *this ); + for ( USHORT nWh = aIter.FirstWhich(); + nWh; + nWh = aIter.NextWhich() ) + { + // wenn die Pointer von poolable Items ungleich sind, + // muessen die Items gleich sein + const SfxPoolItem *pItem1 = 0, *pItem2 = 0; + if ( GetItemState( nWh, FALSE, &pItem1 ) != + rCmp.GetItemState( nWh, FALSE, &pItem2 ) || + ( pItem1 != pItem2 && + ( !pItem1 || IsInvalidItem(pItem1) || + ( _pPool->IsItemFlag(*pItem1, SFX_ITEM_POOLABLE) && + *pItem1 != *pItem2 ) ) ) ) + return FALSE; + } + + return TRUE; + } + + // Pointer alle gleich? + if ( 0 == memcmp( _aItems, rCmp._aItems, nCount1 * sizeof(_aItems[0]) ) ) + return TRUE; + + // dann werden wir wohl alle einzeln vergleichen muessen + const SfxPoolItem **ppItem1 = (const SfxPoolItem**) _aItems; + const SfxPoolItem **ppItem2 = (const SfxPoolItem**) rCmp._aItems; + for ( USHORT nPos = 0; nPos < nCount1; ++nPos ) + { + // wenn die Pointer von poolable Items ungleich sind, + // muessen die Items gleich sein + if ( *ppItem1 != *ppItem2 && + ( ( !*ppItem1 || !*ppItem2 ) || + ( IsInvalidItem(*ppItem1) || IsInvalidItem(*ppItem2) ) || + ( _pPool->IsItemFlag(**ppItem1, SFX_ITEM_POOLABLE) ) || + **ppItem1 != **ppItem2 ) ) + return FALSE; + + ++ppItem1; + ++ppItem2; + } + + return TRUE; +} + +// ----------------------------------------------------------------------- + +SfxItemSet *SfxItemSet::Clone(BOOL bItems, SfxItemPool *pToPool ) const +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + if ( pToPool && pToPool != _pPool ) + { + SfxItemSet *pNewSet = new SfxItemSet( *pToPool, _pWhichRanges ); + if ( bItems ) + { + SfxWhichIter aIter(*pNewSet); + USHORT nWhich = aIter.FirstWhich(); + while ( nWhich ) + { + const SfxPoolItem* pItem; + if ( SFX_ITEM_SET == GetItemState( nWhich, FALSE, &pItem ) ) + pNewSet->Put( *pItem, pItem->Which() ); + nWhich = aIter.NextWhich(); + } + } + return pNewSet; + } + else + return bItems + ? new SfxItemSet(*this) + : new SfxItemSet(*_pPool, _pWhichRanges); +} + +// ----------------------------------------------------------------------- + +int SfxItemSet::PutDirect(const SfxPoolItem &rItem) +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + SfxItemArray ppFnd = _aItems; + const USHORT* pPtr = _pWhichRanges; + const USHORT nWhich = rItem.Which(); +#ifdef DBG_UTIL + IsPoolDefaultItem(&rItem) || _pPool->GetSurrogate(&rItem); + // nur Assertion in den callees provozieren +#endif + while( *pPtr ) + { + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // in diesem Bereich + ppFnd += nWhich - *pPtr; + const SfxPoolItem* pOld = *ppFnd; + if( pOld ) // schon einer vorhanden + { + if( rItem == **ppFnd ) + return FALSE; // schon vorhanden ! + _pPool->Remove( *pOld ); + } + else + ++_nCount; + + // den neuen eintragen + if( IsPoolDefaultItem(&rItem) ) + *ppFnd = &_pPool->Put( rItem ); + else + { + *ppFnd = &rItem; + if( !IsStaticDefaultItem( &rItem ) ) + rItem.AddRef(); + } + + return TRUE; + } + ppFnd += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + return FALSE; +} + +// ----------------------------------------------------------------------- + +SfxAllItemSet::SfxAllItemSet( SfxItemPool &rPool ) +: SfxItemSet(rPool, (const USHORT*) 0), + aDefault(0), + nFree(nInitCount) +{ + // initial keine Items + _aItems = 0; + + // nInitCount Paare an USHORTs fuer Ranges allozieren + _pWhichRanges = new USHORT[ nInitCount + 1 ]; + memset( _pWhichRanges, 0, ( nInitCount + 1 ) * sizeof(USHORT) ); +} + + +// ----------------------------------------------------------------------- + + +SfxAllItemSet::SfxAllItemSet(const SfxItemSet &rCopy) +: SfxItemSet(rCopy), + aDefault(0), + nFree(0) +{ +} + +// ----------------------------------------------------------------------- + + + +SfxAllItemSet::SfxAllItemSet(const SfxAllItemSet &rCopy) +: SfxItemSet(rCopy), + aDefault(0), + nFree(0) +/* [Anmerkung] + + Der mu\s sein, da sonst vom Compiler einer generiert wird, er nimmt + nicht den Ctor mit der 'const SfxItemSet&'! +*/ +{ +} + +// ----------------------------------------------------------------------- + +static USHORT *AddRanges_Impl( + USHORT *pUS, std::ptrdiff_t nOldSize, USHORT nIncr) + +/* Diese interne Funktion erzeugt ein neues Which-Range-Array, welches von + dem 'nOldSize'-USHORTs langen 'pUS' kopiert wird und hinten an Platz + f"ur 'nIncr' neue USHORTs hat. Das terminierende USHORT mit der '0' + wird weder in 'nOldSize' noch in 'nIncr' mitgez"ahlt, sondern implizit + hinzugerechnet. + + Das neue Which-Range-Array wird als Returnwert zur"uckgegeben, das alte + 'pUS' freigegeben. +*/ + +{ + // neues Which-Range-Array anlegen + USHORT *pNew = new USHORT[ nOldSize + nIncr + 1 ]; + + // die alten Ranges "ubernehmen + memcpy( pNew, pUS, nOldSize * sizeof(USHORT) ); + + // die neuen auf 0 initialisieren + memset( pNew + nOldSize, 0, ( nIncr + 1 ) * sizeof(USHORT) ); + + // das alte Array freigeben + delete[] pUS; + + return pNew; +} + +// ----------------------------------------------------------------------- + +static SfxItemArray AddItem_Impl(SfxItemArray pItems, USHORT nOldSize, USHORT nPos) + +/* Diese interne Funktion erzeugt ein neues ItemArray, welches von 'pItems' + kopiert wird, an der Position 'nPos' jedoch Platz f"ur einen neuen + ItemPointer hat. + + Das neue ItemArray wird als Returnwert zur"uckgegeben, das alte 'pItems' + wird freigegeben. +*/ + +{ + // neues ItemArray anlegen + SfxItemArray pNew = new const SfxPoolItem*[nOldSize+1]; + + // war schon vorher eins da? + if ( pItems ) + { + // alte Items vor nPos kopieren + if ( nPos ) + memcpy( (void*) pNew, pItems, nPos * sizeof(SfxPoolItem **) ); + + // alte Items hinter nPos kopieren + if ( nPos < nOldSize ) + memcpy( (void*) (pNew + nPos + 1), pItems + nPos, + (nOldSize-nPos) * sizeof(SfxPoolItem **) ); + } + + // neues Item initialisieren + *(pNew + nPos) = 0; + + // altes ItemArray freigeben + delete[] pItems; + + return pNew; +} + +// ----------------------------------------------------------------------- + +const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, USHORT nWhich ) + +// Putten mit automatischer Erweiterung der Whichs-Ids um die ID +// des Items. + +{ + USHORT nPos = 0; // Position f"ur 'rItem' in '_aItems' + const USHORT nItemCount = TotalCount(); + + // erstmal sehen, ob es schon einen passenden Bereich gibt + USHORT *pPtr = _pWhichRanges; + while ( *pPtr ) + { + // Which-Id liegt in diesem Bereich? + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + // Einfuegen + nPos += nWhich - *pPtr; + break; + } + + // Position des Items in _aItems mitf"uhren + nPos += *(pPtr+1) - *pPtr + 1; + + // zum n"achsten Bereich + pPtr += 2; + } + + // Which-Id noch nicht vorhanden? + if ( !*pPtr ) + { + // suchen, ob man sie irgendwo dranpacken kann + pPtr = _pWhichRanges; + nPos = 0; + while ( *pPtr ) + { + // Which-Id liegt exakt vor diesem Bereich? + if ( (nWhich+1) == *pPtr ) + { + // Bereich waechst nach unten + (*pPtr)--; + + // vor erstem Item dieses Bereichs Platz schaffen + _aItems = AddItem_Impl(_aItems, nItemCount, nPos); + break; + } + + // Which-Id liegt exakt hinter diesem Bereich? + else if ( (nWhich-1) == *(pPtr+1) ) + { + // Bereich waechst nach oben + (*(pPtr+1))++; + + // hinter letztem Item dieses Bereichs Platz schaffen + nPos += nWhich - *pPtr; + _aItems = AddItem_Impl(_aItems, nItemCount, nPos); + break; + } + + // Position des Items in _aItems mitf"uhren + nPos += *(pPtr+1) - *pPtr + 1; + + // zum n"achsten Bereich + pPtr += 2; + } + } + + // keinen erweiterbaren Bereich gefunden? + if ( !*pPtr ) + { + // kein Platz mehr in _pWhichRanges => erweitern + std::ptrdiff_t nSize = pPtr - _pWhichRanges; + if( !nFree ) + { + _pWhichRanges = AddRanges_Impl(_pWhichRanges, nSize, nInitCount); + nFree += nInitCount; + } + + // neuen Which-Range anh"angen + pPtr = _pWhichRanges + nSize; + *pPtr++ = nWhich; + *pPtr = nWhich; + nFree -= 2; + + // Itemarray vergroessern + nPos = nItemCount; + _aItems = AddItem_Impl(_aItems, nItemCount, nPos); + } + + // neues Item in Pool aufnehmen + const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich ); + + // altes Item merken + BOOL bIncrementCount = FALSE; + const SfxPoolItem* pOld = *( _aItems + nPos ); + if ( reinterpret_cast< SfxPoolItem* >( -1 ) == pOld ) // state "dontcare" + pOld = NULL; + if ( !pOld ) + { + bIncrementCount = TRUE; + pOld = _pParent ? + &_pParent->Get( nWhich, TRUE ) + : nWhich <= SFX_WHICH_MAX ? &_pPool->GetDefaultItem( nWhich ) : 0; + } + + // neue Item in ItemSet aufnehmen + *(_aItems + nPos) = &rNew; + + // Changed Notification versenden + if ( pOld ) + { + Changed( *pOld, rNew ); + if ( !IsDefaultItem(pOld) ) + _pPool->Remove( *pOld ); + } + + if ( bIncrementCount ) + ++_nCount; + + return &rNew; +} + +// ----------------------------------------------------------------------- + + +/* Diese Methode wird forwarded, damit sie nicht durch die anderen + Put-Methoden dieser SubClass gehided wird. +*/ + +int SfxAllItemSet::Put( const SfxItemSet& rSet, BOOL bInvalidAsDefault ) +{ + //? pruefen, ob Which-Ranges erweitert werden + return SfxItemSet::Put( rSet, bInvalidAsDefault ); +} + +// ----------------------------------------------------------------------- +// Item disablen, wenn durch ein VoidItem mit dem Which-Wert 0 ausgedrueckt + +void SfxItemSet::DisableItem(USHORT nWhich) +{ + DBG_CHKTHIS(SfxItemSet, 0); + Put( SfxVoidItem(0), nWhich ); +} + +// ----------------------------------------------------------------------- + +#if 0 +BOOL SfxAllItemSet::Remove(USHORT nWhich) +{ + DBG_CHKTHIS(SfxAllItemSet, 0); + USHORT *pPtr = _pWhichRanges; + USHORT nPos = 0; + while( *pPtr ) + { + if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) + { + USHORT *pTmp = pPtr; + USHORT nLeft = 0; + USHORT nRest = 0; + while(*++pTmp){ + if( nLeft & 1 ) + nRest = *pTmp - *(pTmp-1) + 1; + ++nLeft; + } + + // in diesem Bereich + nPos += nWhich - *pPtr; + nRest -= nWhich - *pPtr; + // 3,3 + if(*pPtr == nWhich && *(pPtr+1) == nWhich) { + memmove(pPtr, pPtr + 2, nLeft * sizeof(USHORT)); + nFree += 2; + } + // Anfang + else if(*pPtr == nWhich) + (*pPtr)++; + // Ende + else if(*(pPtr+1) == nWhich) + (*(pPtr+1))--; + else { + if(nPos + nRest + 2 > nFree) { + USHORT nOf = pPtr - _pWhichRanges; + _pWhichRanges = IncrSize(_pWhichRanges, nPos + nRest, nInitCount); + nFree += nInitCount; + pPtr = _pWhichRanges + nOf; + } + memmove(pPtr +2, pPtr, (nLeft+2) * sizeof(USHORT)); + *++pPtr = nWhich-1; + *++pPtr = nWhich+1; + nFree -= 2; + } + SfxPoolItem* pItem = *( _aItems + nPos ); + if( pItem ) + { + if(_pPool) + _pPool->Remove(*pItem ); + else + delete pItem; + --_nCount; + } + memmove(_aItems + nPos +1, _aItems + nPos, + sizeof(SfxPoolItem *) * (nRest - 1)); + break; // dann beim Parent suchen + } + nPos += *(pPtr+1) - *pPtr + 1; + pPtr += 2; + } + return *pPtr? TRUE: FALSE; +} +#endif + +// ----------------------------------------------------------------------- + +SfxItemSet *SfxAllItemSet::Clone(BOOL bItems, SfxItemPool *pToPool ) const +{ + DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); + if ( pToPool && pToPool != _pPool ) + { + SfxAllItemSet *pNewSet = new SfxAllItemSet( *pToPool ); + if ( bItems ) + pNewSet->Set( *this ); + return pNewSet; + } + else + return bItems ? new SfxAllItemSet(*this) : new SfxAllItemSet(*_pPool); +} + diff --git a/svl/source/items/lckbitem.cxx b/svl/source/items/lckbitem.cxx new file mode 100644 index 000000000000..c848e377b257 --- /dev/null +++ b/svl/source/items/lckbitem.cxx @@ -0,0 +1,194 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: lckbitem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#define _LCKBITEM_CXX +#include <svtools/lckbitem.hxx> +#include <svtools/poolitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <tools/cachestr.hxx> + +// STATIC DATA ----------------------------------------------------------- + + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxLockBytesItem::SfxLockBytesItem() +{ +} + +// ----------------------------------------------------------------------- + +SfxLockBytesItem::SfxLockBytesItem( USHORT nW, SvLockBytes *pLockBytes ) +: SfxPoolItem( nW ), + _xVal( pLockBytes ) +{ +} + +// ----------------------------------------------------------------------- + +SfxLockBytesItem::SfxLockBytesItem( USHORT nW, SvStream &rStream ) +: SfxPoolItem( nW ) +{ + rStream.Seek( 0L ); + _xVal = new SvLockBytes( new SvCacheStream(), TRUE ); + + SvStream aLockBytesStream( _xVal ); + rStream >> aLockBytesStream; +} + +// ----------------------------------------------------------------------- + +SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem ) +: SfxPoolItem( rItem ), + _xVal( rItem._xVal ) +{ +} + +// ----------------------------------------------------------------------- + +SfxLockBytesItem::~SfxLockBytesItem() +{ +} + +// ----------------------------------------------------------------------- + +int SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const +{ + return ((SfxLockBytesItem&)rItem)._xVal == _xVal; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const +{ + return new SfxLockBytesItem( *this ); +} + +// ----------------------------------------------------------------------- + +#define MAX_BUF 32000 + +SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, USHORT ) const +{ + sal_uInt32 nSize = 0; + ULONG nActRead = 0; + sal_Char cTmpBuf[MAX_BUF]; + SvMemoryStream aNewStream; + rStream >> nSize; + + do { + ULONG nToRead; + if( (nSize - nActRead) > MAX_BUF ) + nToRead = MAX_BUF; + else + nToRead = nSize - nActRead; + nActRead += rStream.Read( cTmpBuf, nToRead ); + aNewStream.Write( cTmpBuf, nToRead ); + } while( nSize > nActRead ); + + return new SfxLockBytesItem( Which(), aNewStream ); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxLockBytesItem::Store(SvStream &rStream, USHORT ) const +{ + SvStream aLockBytesStream( _xVal ); + sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END ); + aLockBytesStream.Seek( 0L ); + + rStream << nSize; + rStream << aLockBytesStream; + + return rStream; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE ) +{ + com::sun::star::uno::Sequence< sal_Int8 > aSeq; + if ( rVal >>= aSeq ) + { + if ( aSeq.getLength() ) + { + SvCacheStream* pStream = new SvCacheStream; + pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() ); + pStream->Seek(0); + + _xVal = new SvLockBytes( pStream, TRUE ); + } + else + _xVal = NULL; + + return TRUE; + } + + DBG_ERROR( "SfxLockBytesItem::PutValue - Wrong type!" ); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal,BYTE ) const +{ + if ( _xVal.Is() ) + { + sal_uInt32 nLen; + SvLockBytesStat aStat; + + if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE ) + nLen = aStat.nSize; + else + return FALSE; + + ULONG nRead = 0; + com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen ); + + _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead ); + rVal <<= aSeq; + } + else + { + com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 ); + rVal <<= aSeq; + } + + return TRUE; +} + diff --git a/svl/source/items/macitem.cxx b/svl/source/items/macitem.cxx new file mode 100644 index 000000000000..480fb844ccc7 --- /dev/null +++ b/svl/source/items/macitem.cxx @@ -0,0 +1,298 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: macitem.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <tools/stream.hxx> + +#ifndef GCC +#endif + +#include <svtools/macitem.hxx> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SvxMacroItem); + +// ----------------------------------------------------------------------- + +TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0)); + +// ----------------------------------------------------------------------- + + +SjJSbxObjectBase::~SjJSbxObjectBase() +{ +} + +SjJSbxObjectBase* SjJSbxObjectBase::Clone( void ) +{ + return NULL; +} + +SvxMacro::SvxMacro( const String &rMacName, const String &rLanguage) + : aMacName( rMacName ), aLibName( rLanguage), + pFunctionObject(NULL), eType( EXTENDED_STYPE) +{ + if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_STARBASIC)) + eType=STARBASIC; + else if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT)) + eType=JAVASCRIPT; +} + + +SvxMacro::~SvxMacro() +{ + delete pFunctionObject; +} + +String SvxMacro::GetLanguage()const +{ + if(eType==STARBASIC) + { + return UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_STARBASIC)); + } + else if(eType==JAVASCRIPT) + { + return UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_JAVASCRIPT)); + } + else if(eType==EXTENDED_STYPE) + { + return UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_SF)); + + } + return aLibName; +} + + + +SvxMacro& SvxMacro::operator=( const SvxMacro& rBase ) +{ + if( this != &rBase ) + { + aMacName = rBase.aMacName; + aLibName = rBase.aLibName; + delete pFunctionObject; + pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL; + eType = rBase.eType; + } + return *this; +} + + +SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl ) +{ + DelDtor(); + SvxMacro* pTmp = ((SvxMacroTableDtor&)rTbl).First(); + while( pTmp ) + { + SvxMacro *pNew = new SvxMacro( *pTmp ); + Insert( rTbl.GetCurKey(), pNew ); + pTmp = ((SvxMacroTableDtor&)rTbl).Next(); + } + return *this; +} + + +SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, USHORT nVersion ) +{ + if( SVX_MACROTBL_VERSION40 <= nVersion ) + rStrm >> nVersion; + short nMacro; + rStrm >> nMacro; + + for( short i = 0; i < nMacro; ++i ) + { + USHORT nCurKey, eType = STARBASIC; + String aLibName, aMacName; + rStrm >> nCurKey; + SfxPoolItem::readByteString(rStrm, aLibName); + SfxPoolItem::readByteString(rStrm, aMacName); + + if( SVX_MACROTBL_VERSION40 <= nVersion ) + rStrm >> eType; + + SvxMacro* pNew = new SvxMacro( aMacName, aLibName, (ScriptType)eType ); + + SvxMacro *pOld = Get( nCurKey ); + if( pOld ) + { + delete pOld; + Replace( nCurKey, pNew ); + } + else + Insert( nCurKey, pNew ); + } + return rStrm; +} + + +SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const +{ + USHORT nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion() + ? SVX_MACROTBL_VERSION31 + : SVX_MACROTBL_AKTVERSION; + + if( SVX_MACROTBL_VERSION40 <= nVersion ) + rStream << nVersion; + + rStream << (USHORT)Count(); + + SvxMacro* pMac = ((SvxMacroTableDtor*)this)->First(); + while( pMac && rStream.GetError() == SVSTREAM_OK ) + { + rStream << (short)GetCurKey(); + SfxPoolItem::writeByteString(rStream, pMac->GetLibName()); + SfxPoolItem::writeByteString(rStream, pMac->GetMacName()); + + if( SVX_MACROTBL_VERSION40 <= nVersion ) + rStream << (USHORT)pMac->GetScriptType(); + pMac = ((SvxMacroTableDtor*)this)->Next(); + } + return rStream; +} + +// ----------------------------------------------------------------------- + +void SvxMacroTableDtor::DelDtor() +{ + SvxMacro* pTmp = First(); + while( pTmp ) + { + delete pTmp; + pTmp = Next(); + } + Clear(); +} + +// ----------------------------------------------------------------------- + +int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const +{ + DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); + + const SvxMacroTableDtor& rOwn = aMacroTable; + const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable; + + // Anzahl unterschiedlich => auf jeden Fall ungleich + if ( rOwn.Count() != rOther.Count() ) + return FALSE; + + // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig + for ( USHORT nNo = 0; nNo < rOwn.Count(); ++nNo ) + { + const SvxMacro *pOwnMac = rOwn.GetObject(nNo); + const SvxMacro *pOtherMac = rOther.GetObject(nNo); + if ( rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac) || + pOwnMac->GetLibName() != pOtherMac->GetLibName() || + pOwnMac->GetMacName() != pOtherMac->GetMacName() ) + return FALSE; + } + + return TRUE; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const +{ + return new SvxMacroItem( *this ); +} + +//------------------------------------------------------------------------ + +SfxItemPresentation SvxMacroItem::GetPresentation +( + SfxItemPresentation /*ePres*/, + SfxMapUnit /*eCoreUnit*/, + SfxMapUnit /*ePresUnit*/, + XubString& rText, + const IntlWrapper * +) const +{ +/*!!! + SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable(); + SvxMacro* pMac = rTbl.First(); + + while ( pMac ) + { + rText += pMac->GetLibName(); + rText += cpDelim; + rText += pMac->GetMacName(); + pMac = rTbl.Next(); + if ( pMac ) + rText += cpDelim; + } +*/ + rText.Erase(); + return SFX_ITEM_PRESENTATION_NONE; +} + +// ----------------------------------------------------------------------- + +SvStream& SvxMacroItem::Store( SvStream& rStrm , USHORT ) const +{ + return aMacroTable.Write( rStrm ); +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, USHORT nVersion ) const +{ + SvxMacroItem* pAttr = new SvxMacroItem( Which() ); + pAttr->aMacroTable.Read( rStrm, nVersion ); + return pAttr; +} + +// ----------------------------------------------------------------------- + +void SvxMacroItem::SetMacro( USHORT nEvent, const SvxMacro& rMacro ) +{ + SvxMacro *pMacro; + if ( 0 != (pMacro=aMacroTable.Get(nEvent)) ) + { + delete pMacro; + aMacroTable.Replace(nEvent, new SvxMacro( rMacro ) ); + } + else + aMacroTable.Insert(nEvent, new SvxMacro( rMacro ) ); +} + +// ----------------------------------------------------------------------- + +USHORT SvxMacroItem::GetVersion( USHORT nFileFormatVersion ) const +{ + return SOFFICE_FILEFORMAT_31 == nFileFormatVersion + ? 0 : aMacroTable.GetVersion(); +} + diff --git a/svl/source/items/makefile.mk b/svl/source/items/makefile.mk new file mode 100644 index 000000000000..651e54bb7e23 --- /dev/null +++ b/svl/source/items/makefile.mk @@ -0,0 +1,65 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.13 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=svtools +TARGET=items +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/svt.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES=\ + $(SLO)$/aeitem.obj \ + $(SLO)$/eitem.obj \ + $(SLO)$/flagitem.obj \ + $(SLO)$/globalnameitem.obj \ + $(SLO)$/imageitm.obj \ + $(SLO)$/intitem.obj \ + $(SLO)$/itemdel.obj \ + $(SLO)$/macitem.obj \ + $(SLO)$/poolcach.obj \ + $(SLO)$/ptitem.obj \ + $(SLO)$/rectitem.obj \ + $(SLO)$/rngitem.obj \ + $(SLO)$/stritem.obj \ + $(SLO)$/style.obj \ + $(SLO)$/szitem.obj \ + $(SLO)$/wallitem.obj + +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/svl/source/items/nranges.cxx b/svl/source/items/nranges.cxx new file mode 100644 index 000000000000..e12c7428d513 --- /dev/null +++ b/svl/source/items/nranges.cxx @@ -0,0 +1,853 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: nranges.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +// compiled via include from itemset.cxx only! + +//======================================================================== + +#ifdef DBG_UTIL + +#define DBG_CHECK_RANGES(NUMTYPE, pArr) \ + for ( const NUMTYPE *pRange = pArr; *pRange; pRange += 2 ) \ + { \ + DBG_ASSERT( pRange[0] <= pRange[1], "ranges must be sorted" ); \ + DBG_ASSERT( !pRange[2] || ( pRange[2] - pRange[1] ) > 1, \ + "ranges must be sorted and discrete" ); \ + } + +#else + +#define DBG_CHECK_RANGES(NUMTYPE,pArr) + +#endif + +//============================================================================ +inline void Swap_Impl(const NUMTYPE *& rp1, const NUMTYPE *& rp2) +{ + const NUMTYPE * pTemp = rp1; + rp1 = rp2; + rp2 = pTemp; +} + +//======================================================================== + +NUMTYPE InitializeRanges_Impl( NUMTYPE *&rpRanges, va_list pArgs, + NUMTYPE nWh1, NUMTYPE nWh2, NUMTYPE nNull ) + +/** <H3>Description</H3> + + Creates an USHORT-ranges-array in 'rpRanges' using 'nWh1' and 'nWh2' as + first range, 'nNull' as terminator or start of 2nd range and 'pArgs' as + remaider. + + It returns the number of NUMTYPEs which are contained in the described + set of NUMTYPEs. +*/ + +{ + NUMTYPE nSize = 0, nIns = 0; + USHORT nCnt = 0; + SvNums aNumArr( 11, 8 ); + aNumArr.Insert( nWh1, nCnt++ ); + aNumArr.Insert( nWh2, nCnt++ ); + DBG_ASSERT( nWh1 <= nWh2, "Ungueltiger Bereich" ); + nSize += nWh2 - nWh1 + 1; + aNumArr.Insert( nNull, nCnt++ ); + while ( 0 != + ( nIns = + sal::static_int_cast< NUMTYPE >( + va_arg( pArgs, NUMTYPE_ARG ) ) ) ) + { + aNumArr.Insert( nIns, nCnt++ ); + if ( 0 == (nCnt & 1) ) // 4,6,8, usw. + { + DBG_ASSERT( aNumArr[ nCnt-2 ] <= nIns, "Ungueltiger Bereich" ); + nSize += nIns - aNumArr[ nCnt-2 ] + 1; + } + } + va_end( pArgs ); + + DBG_ASSERT( 0 == (nCnt & 1), "ungerade Anzahl von Which-Paaren!" ); + + // so, jetzt sind alle Bereiche vorhanden und + rpRanges = new NUMTYPE[ nCnt+1 ]; + memcpy( rpRanges, aNumArr.GetData(), sizeof(NUMTYPE) * nCnt ); + *(rpRanges+nCnt) = 0; + + return nSize; +} + +//------------------------------------------------------------------------ + +NUMTYPE Count_Impl( const NUMTYPE *pRanges ) + +/** <H3>Description</H3> + + Determines the number of NUMTYPEs in an 0-terminated array of pairs of + NUMTYPEs. The terminating 0 is not included in the count. +*/ + +{ + NUMTYPE nCount = 0; + while ( *pRanges ) + { + nCount += 2; + pRanges += 2; + } + return nCount; +} + +//------------------------------------------------------------------------ + +NUMTYPE Capacity_Impl( const NUMTYPE *pRanges ) + +/** <H3>Description</H3> + + Determines the total number of NUMTYPEs described in an 0-terminated + array of pairs of NUMTYPEs, each representing an range of NUMTYPEs. +*/ + +{ + NUMTYPE nCount = 0; + + if ( pRanges ) + { + while ( *pRanges ) + { + nCount += pRanges[1] - pRanges[0] + 1; + pRanges += 2; + } + } + return nCount; +} + +//------------------------------------------------------------------------ + +SfxNumRanges::SfxNumRanges( const SfxNumRanges &rOrig ) + +/** <H3>Description</H3> + + Copy-Ctor. +*/ + +{ + if ( rOrig._pRanges ) + { + NUMTYPE nCount = Count_Impl( rOrig._pRanges ) + 1; + _pRanges = new NUMTYPE[nCount]; + memcpy( _pRanges, rOrig._pRanges, sizeof(NUMTYPE) * nCount ); + } + else + _pRanges = 0; +} + +//------------------------------------------------------------------------ + +SfxNumRanges::SfxNumRanges( NUMTYPE nWhich1, NUMTYPE nWhich2 ) + +/** <H3>Description</H3> + + Constructs an SfxNumRanges-instance from one range of NUMTYPEs. + + precondition: + nWhich1 <= nWhich2 +*/ + +: _pRanges( new NUMTYPE[3] ) +{ + _pRanges[0] = nWhich1; + _pRanges[1] = nWhich2; + _pRanges[2] = 0; +} + +//------------------------------------------------------------------------ + +SfxNumRanges::SfxNumRanges( NUMTYPE_ARG nWh0, NUMTYPE_ARG nWh1, NUMTYPE_ARG nNull, ... ) + +/** <H3>Description</H3> + + Constructs an SfxNumRanges-instance from more than one sorted ranges of + NUMTYPEs terminated with one 0. + + precondition: for each n >= 0 && n < nArgs + nWh(2n) <= nWh(2n+1) && ( nWh(2n+2)-nWh(2n+1) ) > 1 +*/ + +{ + va_list pArgs; + va_start( pArgs, nNull ); + InitializeRanges_Impl( + _pRanges, pArgs, sal::static_int_cast< NUMTYPE >(nWh0), + sal::static_int_cast< NUMTYPE >(nWh1), + sal::static_int_cast< NUMTYPE >(nNull)); + DBG_CHECK_RANGES(NUMTYPE, _pRanges); +} + +//------------------------------------------------------------------------ + +SfxNumRanges::SfxNumRanges( const NUMTYPE* pArr ) + +/** <H3>Description</H3> + + Constcurts an SfxNumRanges-instance from an sorted ranges of NUMTYPEs, + terminates with on 0. + + precondition: for each n >= 0 && n < (sizeof(pArr)-1) + pArr[2n] <= pArr[2n+1] && ( pArr[2n+2]-pArr[2n+1] ) > 1 +*/ + +{ + DBG_CHECK_RANGES(NUMTYPE, pArr); + NUMTYPE nCount = Count_Impl(pArr) + 1; + _pRanges = new NUMTYPE[ nCount ]; + memcpy( _pRanges, pArr, sizeof(NUMTYPE) * nCount ); +} + +//------------------------------------------------------------------------ + +BOOL SfxNumRanges::operator==( const SfxNumRanges &rOther ) const +{ + // Object pointers equal? + if ( this == &rOther ) + return TRUE; + + // Ranges pointers equal? + if ( _pRanges == rOther._pRanges ) + return TRUE; + + // Counts equal? + NUMTYPE nCount = Count(); + if ( nCount != rOther.Count() ) + return FALSE; + + // Check arrays. + NUMTYPE n = 0; + while( _pRanges[ n ] != 0 ) + { + // Elements at current position equal? + if ( _pRanges[ n ] != rOther._pRanges[ n ] ) + return FALSE; + + ++n; + } + + return TRUE; +} + +//------------------------------------------------------------------------ + +SfxNumRanges& SfxNumRanges::operator = +( + const SfxNumRanges &rRanges +) + +/** <H3>Description</H3> + + Assigns ranges from 'rRanges' to '*this'. +*/ + +{ + // special case: assign itself + if ( &rRanges == this ) + return *this; + + delete[] _pRanges; + + // special case: 'rRanges' is empty + if ( rRanges.IsEmpty() ) + _pRanges = 0; + else + { + // copy ranges + NUMTYPE nCount = Count_Impl( rRanges._pRanges ) + 1; + _pRanges = new NUMTYPE[ nCount ]; + memcpy( _pRanges, rRanges._pRanges, sizeof(NUMTYPE) * nCount ); + } + return *this; +} + +//------------------------------------------------------------------------ + +SfxNumRanges& SfxNumRanges::operator += +( + const SfxNumRanges &rRanges +) + +/** <H3>Description</H3> + + Merges *this with 'rRanges'. + + for each NUMTYPE n: + this->Contains( n ) || rRanges.Contains( n ) => this'->Contains( n ) + !this->Contains( n ) && !rRanges.Contains( n ) => !this'->Contains( n ) +*/ + +{ + // special cases: one is empty + if ( rRanges.IsEmpty() ) + return *this; + if ( IsEmpty() ) + return *this = rRanges; + + // First, run thru _pRanges and rRanges._pRanges and determine the size of + // the new, merged ranges: + NUMTYPE nCount = 0; + const NUMTYPE * pRA = _pRanges; + const NUMTYPE * pRB = rRanges._pRanges; + + for (;;) + { + // The first pair of pRA has a lower lower bound than the first pair + // of pRB: + if (pRA[0] > pRB[0]) + Swap_Impl(pRA, pRB); + + // We are done with the merging if at least pRA is exhausted: + if (!pRA[0]) + break; + + for (;;) + { + // Skip those pairs in pRB that completely lie in the first pair + // of pRA: + while (pRB[1] <= pRA[1]) + { + pRB += 2; + + // Watch out for exhaustion of pRB: + if (!pRB[0]) + { + Swap_Impl(pRA, pRB); + goto count_rest; + } + } + + // If the next pair of pRA does not at least touch the current new + // pair, we are done with the current new pair: + if (pRB[0] > pRA[1] + 1) + break; + + // The next pair of pRB extends the current new pair; first, + // extend the current new pair (we are done if pRB is then + // exhausted); second, switch the roles of pRA and pRB in order to + // merge in those following pairs of the original pRA that will + // lie in the (now larger) current new pair or will even extend it + // further: + pRA += 2; + if (!pRA[0]) + goto count_rest; + Swap_Impl(pRA, pRB); + } + + // Done with the current new pair: + pRA += 2; + nCount += 2; + } + + // Only pRB has more pairs available, pRA is already exhausted: +count_rest: + for (; pRB[0]; pRB += 2) + nCount += 2; + + // Now, create new ranges of the correct size and, on a second run thru + // _pRanges and rRanges._pRanges, copy the merged pairs into the new + // ranges: + NUMTYPE * pNew = new NUMTYPE[nCount + 1]; + pRA = _pRanges; + pRB = rRanges._pRanges; + NUMTYPE * pRN = pNew; + + for (;;) + { + // The first pair of pRA has a lower lower bound than the first pair + // of pRB: + if (pRA[0] > pRB[0]) + Swap_Impl(pRA, pRB); + + // We are done with the merging if at least pRA is exhausted: + if (!pRA[0]) + break; + + // Lower bound of current new pair is already known: + *pRN++ = pRA[0]; + + for (;;) + { + // Skip those pairs in pRB that completely lie in the first pair + // of pRA: + while (pRB[1] <= pRA[1]) + { + pRB += 2; + + // Watch out for exhaustion of pRB: + if (!pRB[0]) + { + Swap_Impl(pRA, pRB); + ++pRB; + goto copy_rest; + } + } + + // If the next pair of pRA does not at least touch the current new + // pair, we are done with the current new pair: + if (pRB[0] > pRA[1] + 1) + break; + + // The next pair of pRB extends the current new pair; first, + // extend the current new pair (we are done if pRB is then + // exhausted); second, switch the roles of pRA and pRB in order to + // merge in those following pairs of the original pRA that will + // lie in the (now larger) current new pair or will even extend it + // further: + pRA += 2; + if (!pRA[0]) + { + ++pRB; + goto copy_rest; + } + Swap_Impl(pRA, pRB); + } + + // Done with the current new pair, now upper bound is also known: + *pRN++ = pRA[1]; + pRA += 2; + } + + // Only pRB has more pairs available (which are copied to the new ranges + // unchanged), pRA is already exhausted: +copy_rest: + for (; *pRB;) + *pRN++ = *pRB++; + *pRN = 0; + + delete[] _pRanges; + _pRanges = pNew; + + return *this; +} + +//------------------------------------------------------------------------ + +SfxNumRanges& SfxNumRanges::operator -= +( + const SfxNumRanges &rRanges +) + +/** <H3>Description</H3> + + Removes 'rRanges' from '*this'. + + for each NUMTYPE n: + this->Contains( n ) && rRanges.Contains( n ) => !this'->Contains( n ) + this->Contains( n ) && !rRanges.Contains( n ) => this'->Contains( n ) + !this->Contains( n ) => !this'->Contains( n ) +*/ + +{ + // special cases: one is empty + if ( rRanges.IsEmpty() || IsEmpty() ) + return *this; + + // differentiate 'rRanges' in a temporary copy of '*this' + // (size is computed for maximal possibly split-count plus terminating 0) + NUMTYPE nThisSize = Count_Impl(_pRanges); + NUMTYPE nTargetSize = 1 + ( nThisSize + Count_Impl(rRanges._pRanges) ); + NUMTYPE *pTarget = new NUMTYPE[ nTargetSize ]; + memset( pTarget, sizeof(NUMTYPE)*nTargetSize, 0 ); + memcpy( pTarget, _pRanges, sizeof(NUMTYPE)*nThisSize ); + + NUMTYPE nPos1 = 0, nPos2 = 0, nTargetPos = 0; + while( _pRanges[ nPos1 ] ) + { + NUMTYPE l1 = _pRanges[ nPos1 ]; // lower bound of interval 1 + NUMTYPE u1 = _pRanges[ nPos1+1 ]; // upper bound of interval 1 + NUMTYPE l2 = rRanges._pRanges[ nPos2 ]; // lower bound of interval 2 + NUMTYPE u2 = rRanges._pRanges[ nPos2+1 ]; // upper bound of interval 2 + + // boundary cases + // * subtrahend is empty -> copy the minuend + if( !l2 ) + { + pTarget[ nTargetPos ] = l1; + pTarget[ nTargetPos+1 ] = u1; + nTargetPos += 2; + nPos1 += 2; + continue; + } + // * next subtrahend interval is completely higher -> copy the minuend + if( u1 < l2 ) + { + pTarget[ nTargetPos ] = l1; + pTarget[ nTargetPos+1 ] = u1; + nTargetPos += 2; + nPos1 += 2; + continue; + } + + // * next subtrahend interval is completely lower -> try next + if( u2 < l1 ) + { + nPos2 += 2; + continue; + } + + // intersecting cases + // * subtrahend cuts out from the beginning of the minuend + if( l2 <= l1 && u2 <= u1 ) + { + // reduce minuend interval, try again (minuend might be affected by other subtrahend intervals) + _pRanges[ nPos1 ] = u2 + 1; + nPos2 += 2; // this cannot hurt any longer + continue; + } + + // * subtrahend cuts out from the end of the minuend + if( l1 <= l2 && u1 <= u2 ) + { + // copy remaining part of minuend (cannot be affected by other intervals) + if( l1 < l2 ) // anything left at all? + { + pTarget[ nTargetPos ] = l1; + pTarget[ nTargetPos+1 ] = l2 - 1; + nTargetPos += 2; + // do not increment nPos2, might affect next minuend interval, too + } + nPos1 += 2; // nothing left at all + continue; + } + + // * subtrahend completely deletes minuend (larger or same at both ends) + if( l1 >= l2 && u1 <= u2 ) + { + nPos1 += 2; // minuend deleted + // do not increment nPos2, might affect next minuend interval, too + continue; + } + + // * subtrahend divides minuend into two pieces + if( l1 <= l2 && u1 >= u2 ) // >= and <= since they may be something left only at one side + { + // left side + if( l1 < l2 ) // anything left at all + { + pTarget[ nTargetPos ] = l1; + pTarget[ nTargetPos+1 ] = l2 - 1; + nTargetPos += 2; + } + + // right side + if( u1 > u2 ) // anything left at all + { + // reduce minuend interval, try again (minuend might be affected by other subtrahend itnervals ) + _pRanges[ nPos1 ] = u2 + 1; + } + + // subtrahend is completely used + nPos2 += 2; + continue; + } + + // we should never be here + DBG_ERROR( "SfxNumRanges::operator-=: internal error" ); + } // while + + pTarget[ nTargetPos ] = 0; + + // assign the differentiated ranges + delete[] _pRanges; + + NUMTYPE nUShorts = Count_Impl(pTarget) + 1; + if ( 1 != nUShorts ) + { + _pRanges = new NUMTYPE[ nUShorts ]; + memcpy( _pRanges, pTarget, nUShorts * sizeof(NUMTYPE) ); + } + else + _pRanges = 0; + + delete [] pTarget; + return *this; + + /* untested code from MI commented out (MDA, 28.01.97) + do + { + // 1st range is smaller than 2nd range? + if ( pRange1[1] < pRange2[0] ) + // => keep 1st range + pRange1 += 2; + + // 2nd range is smaller than 1st range? + else if ( pRange2[1] < pRange1[0] ) + // => skip 2nd range + pRange2 += 2; + + // 2nd range totally overlaps the 1st range? + else if ( pRange2[0] <= pRange1[0] && pRange2[1] >= pRange1[1] ) + // => remove 1st range + memmove( pRange1, pRange1+2, sizeof(NUMTYPE) * (pEndOfTarget-pRange1+2) ); + + // 2nd range overlaps only the beginning of 1st range? + else if ( pRange2[0] <= pRange1[0] && pRange2[1] < pRange1[1] ) + { + // => cut the beginning of 1st range and goto next 2nd range + pRange1[0] = pRange2[1] + 1; + pRange2 += 2; + } + + // 2nd range overlaps only the end of 1st range? + else if ( pRange2[0] > pRange1[0] && pRange2[1] >= pRange1[0] ) + // => cut the beginning of 1st range + pRange1[0] = pRange2[1]+1; + + // 2nd range is a real subset of 1st range + else + { + // => split 1st range and goto next 2nd range + memmove( pRange1+3, pRange1+1, sizeof(NUMTYPE) * (pEndOfTarget-pRange1-1) ); + pRange1[1] = pRange2[0] - 1; + pRange1[2] = pRange2[1] + 1; + pRange1 += 2; + pRange2 += 2; + } + } + while ( *pRange1 && *pRange2 ); + + // assign the differentiated ranges + delete[] _pRanges; + NUMTYPE nUShorts = Count_Impl(pTarget) + 1; + if ( 1 != nUShorts ) + { + _pRanges = new NUMTYPE[ nUShorts ]; + memcpy( _pRanges, pTarget, nUShorts * sizeof(NUMTYPE) ); + _pRanges[ nUShorts-1 ] = 0; + } + else + _pRanges = 0; + return *this; + */ +} + +//------------------------------------------------------------------------ + +SfxNumRanges& SfxNumRanges::operator /= +( + const SfxNumRanges &rRanges +) + +/** <H3>Description</H3> + + Determines intersection of '*this' with 'rRanges'. + + for each NUMTYPE n: + this->Contains( n ) && rRanges.Contains( n ) => this'->Contains( n ) + !this->Contains( n ) => !this'->Contains( n ) + !rRanges.Contains( n ) => !this'->Contains( n ) +*/ + +{ + // boundary cases + // * first set is empty -> nothing to be done + // * second set is empty -> delete first set + if( rRanges.IsEmpty() ) + { + delete[] _pRanges; + + _pRanges = new NUMTYPE[1]; + _pRanges[0] = 0; + + return *this; + } + + // intersect 'rRanges' in a temporary copy of '*this' + // (size is computed for maximal possibly split-count plus terminating 0) + NUMTYPE nThisSize = Count_Impl(_pRanges); + NUMTYPE nTargetSize = 1 + ( nThisSize + Count_Impl(rRanges._pRanges) ); + NUMTYPE *pTarget = new NUMTYPE[ nTargetSize ]; + memset( pTarget, sizeof(NUMTYPE)*nTargetSize, 0 ); + memcpy( pTarget, _pRanges, sizeof(NUMTYPE)*nThisSize ); + + NUMTYPE nPos1 = 0, nPos2 = 0, nTargetPos = 0; + while( _pRanges[ nPos1 ] != 0 && rRanges._pRanges[ nPos2 ] != 0 ) + { + NUMTYPE l1 = _pRanges[ nPos1 ]; // lower bound of interval 1 + NUMTYPE u1 = _pRanges[ nPos1+1 ]; // upper bound of interval 1 + NUMTYPE l2 = rRanges._pRanges[ nPos2 ]; // lower bound of interval 2 + NUMTYPE u2 = rRanges._pRanges[ nPos2+1 ]; // upper bound of interval 2 + + if( u1 < l2 ) + { + // current interval in s1 is completely before ci in s2 + nPos1 += 2; + continue; + } + if( u2 < l1 ) + { + // ci in s2 is completely before ci in s1 + nPos2 += 2; + continue; + } + + // assert: there exists an intersection between ci1 and ci2 + + if( l1 <= l2 ) + { + // c1 "is more to the left" than c2 + + if( u1 <= u2 ) + { + pTarget[ nTargetPos ] = l2; + pTarget[ nTargetPos+1 ] = u1; + nTargetPos += 2; + nPos1 += 2; + continue; + } + else + { + pTarget[ nTargetPos ] = l2; + pTarget[ nTargetPos+1 ] = u2; + nTargetPos += 2; + nPos2 += 2; + } + } + else + { + // c2 "is more to the left" than c1" + + if( u1 > u2 ) + { + pTarget[ nTargetPos ] = l1; + pTarget[ nTargetPos+1 ] = u2; + nTargetPos += 2; + nPos2 += 2; + } + else + { + pTarget[ nTargetPos ] = l1; + pTarget[ nTargetPos+1 ] = u1; + nTargetPos += 2; + nPos1 += 2; + } + } + }; // while + pTarget[ nTargetPos ] = 0; + + // assign the intersected ranges + delete[] _pRanges; + + NUMTYPE nUShorts = Count_Impl(pTarget) + 1; + if ( 1 != nUShorts ) + { + _pRanges = new NUMTYPE[ nUShorts ]; + memcpy( _pRanges, pTarget, nUShorts * sizeof(NUMTYPE) ); + } + else + _pRanges = 0; + + delete [] pTarget; + return *this; +} + +//------------------------------------------------------------------------ + +BOOL SfxNumRanges::Intersects( const SfxNumRanges &rRanges ) const + +/** <H3>Description</H3> + + Determines if at least one range in 'rRanges' intersects with one + range in '*this'. + + TRUE, if there is at least one with: + this->Contains( n ) && rRanges.Contains( n ) +*/ + +{ + // special cases: one is empty + if ( rRanges.IsEmpty() || IsEmpty() ) + return FALSE; + + // find at least one intersecting range + const NUMTYPE *pRange1 = _pRanges; + const NUMTYPE *pRange2 = rRanges._pRanges; + + do + { + // 1st range is smaller than 2nd range? + if ( pRange1[1] < pRange2[0] ) + // => keep 1st range + pRange1 += 2; + + // 2nd range is smaller than 1st range? + else if ( pRange2[1] < pRange1[0] ) + // => skip 2nd range + pRange2 += 2; + + // the ranges are overlappung + else + return TRUE; + } + while ( *pRange2 ); + + // no intersection found + return FALSE; +} + +//------------------------------------------------------------------------ + +NUMTYPE SfxNumRanges::Count() const + +/** <H3>Description</H3> + + Determines the number of USHORTs in the set described by the ranges + of USHORTs in '*this'. +*/ + +{ + return Capacity_Impl( _pRanges ); +} + +//------------------------------------------------------------------------ + +BOOL SfxNumRanges::Contains( NUMTYPE n ) const + +/** <H3>Description</H3> + + Determines if '*this' contains 'n'. +*/ + +{ + for ( NUMTYPE *pRange = _pRanges; *pRange && *pRange <= n; pRange += 2 ) + if ( pRange[0] <= n && n <= pRange[1] ) + return TRUE; + return FALSE; + +} diff --git a/svl/source/items/poolcach.cxx b/svl/source/items/poolcach.cxx new file mode 100644 index 000000000000..2c758a7e25fa --- /dev/null +++ b/svl/source/items/poolcach.cxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: poolcach.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <limits.h> + +#ifndef GCC +#endif + +#include <svtools/itempool.hxx> +#include <svtools/itemset.hxx> +#include "poolcach.hxx" + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxItemPoolCache) + + +//------------------------------------------------------------------------ + +struct SfxItemModifyImpl +{ + const SfxSetItem *pOrigItem; + SfxSetItem *pPoolItem; +}; + +SV_DECL_VARARR( SfxItemModifyArr_Impl, SfxItemModifyImpl, 8, 8 ) +SV_IMPL_VARARR( SfxItemModifyArr_Impl, SfxItemModifyImpl); + +//------------------------------------------------------------------------ + +SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool, + const SfxPoolItem *pPutItem ): + pPool(pItemPool), + pCache(new SfxItemModifyArr_Impl), + pSetToPut( 0 ), + pItemToPut( &pItemPool->Put(*pPutItem) ) +{ + DBG_CTOR(SfxItemPoolCache, 0); + DBG_ASSERT(pItemPool, "kein Pool angegeben"); +} + +//------------------------------------------------------------------------ + +SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool, + const SfxItemSet *pPutSet ): + pPool(pItemPool), + pCache(new SfxItemModifyArr_Impl), + pSetToPut( pPutSet ), + pItemToPut( 0 ) +{ + DBG_CTOR(SfxItemPoolCache, 0); + DBG_ASSERT(pItemPool, "kein Pool angegeben"); +} + +//------------------------------------------------------------------------ + +SfxItemPoolCache::~SfxItemPoolCache() +{ + DBG_DTOR(SfxItemPoolCache, 0); + for ( USHORT nPos = 0; nPos < pCache->Count(); ++nPos ) { + pPool->Remove( *(*pCache)[nPos].pPoolItem ); + pPool->Remove( *(*pCache)[nPos].pOrigItem ); + } + delete pCache; pCache = 0; + + if ( pItemToPut ) + pPool->Remove( *pItemToPut ); +} + +//------------------------------------------------------------------------ + +const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem, BOOL bNew ) +{ + DBG_CHKTHIS(SfxItemPoolCache, 0); + DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" ); + DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ), + "original not in pool" ); + + // Suchen, ob diese Transformations schon einmal vorkam + for ( USHORT nPos = 0; nPos < pCache->Count(); ++nPos ) + { + SfxItemModifyImpl &rMapEntry = (*pCache)[nPos]; + if ( rMapEntry.pOrigItem == &rOrigItem ) + { + // aendert sich ueberhaupt etwas? + if ( rMapEntry.pPoolItem != &rOrigItem ) + { + rMapEntry.pPoolItem->AddRef(2); // einen davon fuer den Cache + if ( bNew ) + pPool->Put( rOrigItem ); //! AddRef?? + } + return *rMapEntry.pPoolItem; + } + } + + // die neue Attributierung in einem neuen Set eintragen + SfxSetItem *pNewItem = (SfxSetItem *)rOrigItem.Clone(); + if ( pItemToPut ) + { + pNewItem->GetItemSet().PutDirect( *pItemToPut ); + DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut, + "wrong item in temporary set" ); + } + else + pNewItem->GetItemSet().Put( *pSetToPut ); + const SfxSetItem* pNewPoolItem = (const SfxSetItem*) &pPool->Put( *pNewItem ); + DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: rein == raus?" ); + delete pNewItem; + + // Refernzzaehler anpassen, je einen davon fuer den Cache + pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 ); + if ( bNew ) + pPool->Put( rOrigItem ); //! AddRef?? + + // die Transformation im Cache eintragen + SfxItemModifyImpl aModify; + aModify.pOrigItem = &rOrigItem; + aModify.pPoolItem = (SfxSetItem*) pNewPoolItem; + pCache->Insert( aModify, pCache->Count() ); + + DBG_ASSERT( !pItemToPut || + &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut, + "wrong item in resulting set" ); + + return *pNewPoolItem; +} + + + diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx new file mode 100644 index 000000000000..f2eb94ef7f67 --- /dev/null +++ b/svl/source/items/poolio.cxx @@ -0,0 +1,1715 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: poolio.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <string.h> +#include <stdio.h> + +#ifndef GCC +#endif + +#include <tools/solar.h> +#include <svtools/itempool.hxx> +#include "whassert.hxx" +#include <svtools/brdcst.hxx> +#include <svtools/filerec.hxx> +#include <svtools/svtdata.hxx> +#include "poolio.hxx" + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxItemPool); + +//======================================================================== + +void SfxItemPool::SetStoringPool( const SfxItemPool *pStoringPool ) + +/* [Beschreibung] + + Diese Methode setzt den <SfxItemPool>, der gerade gespeichert wird. + Sie sollte nur in Notf"allen verwendet werden, um z.B. File-Format- + Kompatibilit"at zu gew"ahrleisten o."o. - z.B. in der "uberladung eines + <SfxPoolItem::Store()> zus"atzliche Daten aus dem dazuge"horigen + Pool mit <SfxItemPool::GetStoringPool()> zu besorgen. + + Sie wird von <SfxItemPool::Store()> bedient, kann jedoch f"ur nicht + poolable Items auch direkt gerufen werden. Bitte m"oglichst nicht + f"ur jedes Item einzeln, da 2 Calls! +*/ + +{ + ImpSvtData::GetSvtData().pStoringPool = pStoringPool; +} + +//------------------------------------------------------------------------- + +const SfxItemPool* SfxItemPool::GetStoringPool() + +/* [Beschreibung] + + Diese Methode liefert den <SfxItemPool>, der gerade gespeichert wird. + Sie sollte nur in Notf"allen verwendet werden, um z.B. File-Format- + Kompatibilit"at zu gew"ahrleisten o."o. - z.B. in der "uberladung eines + <SfxPoolItem::Store()> zus"atzliche Daten aus dem dazuge"horigen + Pool zu besorgen. +*/ + +{ + return ImpSvtData::GetSvtData().pStoringPool; +} + +//------------------------------------------------------------------------- + +SvStream &SfxItemPool::Store(SvStream &rStream) const + +/* [Beschreibung] + + Der SfxItemPool wird inklusive aller seiner Sekund"arpools mit + Pool-Defaults und gepoolten Items in dem angegebenen Stream gespeichert. + Die statischen Defaults werden nicht gespeichert. + + + [Fileformat] + + ;zun"achst ein Kompatiblit"ats-Header-Block + Start: 0x1111 SFX_ITEMPOOL_TAG_STARTPOOLS(_4/_5) + BYTE MAJOR_VER ;SfxItemPool-Version + BYTE MINOR_VER ;" + 0xFFFF SFX_ITEMPOOL_TAG_TRICK4OLD ;ex. GetVersion() + USHORT 0x0000 ;Pseudo-StyleSheetPool + USHORT 0x0000 ;Pseudo-StyleSheetPool + + ;den ganzen Pool in einen Record + record SfxMiniRecod(SFX_ITEMPOOL_REC) + + ;je ein Header vorweg + Header: record SfxMiniRecord(SFX_ITEMPOOL_REC_HEADER) + USHORT GetVersion() ;Which-Ranges etc. + String GetName() ;Pool-Name + + ;die Versions-Map, um WhichIds neuer File-Versionen mappen zu k"onnen + Versions: record SfxMultiRecord(SFX_ITEMPOOL_REC_VERSIONS, 0) + USHORT OldVersion + USHORT OldStartWhich + USHORT OldEndWhich + USHORT[] NewWhich (OldEndWhich-OldStartWhich+1) + + ;jetzt die gepoolten Items (zuerst nicht-SfxSetItems) + Items: record SfxMultiRecord(SFX_ITEMPOOL_REC_WHICHIDS, 0) + content SlotId, 0 + USHORT WhichId + USHORT pItem->GetVersion() + USHORT Array-Size + record SfxMultiRecord(SFX_, 0) + content Surrogate + USHORT RefCount + unknown pItem->Store() + + ;jetzt die gesetzten Pool-Defaults + Defaults: record SfxMultiRecord(SFX_ITEMPOOL_REC_DEFAULTS, 0) + content SlotId, 0 + USHORT WhichId + USHORT pPoolDef->GetVersion() + unknown pPoolDef->Store(); + + ;dahinter folgt ggf. der Secondary ohne Kompatiblit"ats-Header-Block +*/ + +{ + DBG_CHKTHIS(SfxItemPool, 0); + + // Store-Master finden + SfxItemPool *pStoreMaster = pMaster != this ? pMaster : 0; + while ( pStoreMaster && !pStoreMaster->pImp->bStreaming ) + pStoreMaster = pStoreMaster->pSecondary; + + // Alter-Header (Version des Pools an sich und Inhalts-Version 0xffff) + pImp->bStreaming = TRUE; + if ( !pStoreMaster ) + { + rStream << ( rStream.GetVersion() >= SOFFICE_FILEFORMAT_50 + ? SFX_ITEMPOOL_TAG_STARTPOOL_5 + : SFX_ITEMPOOL_TAG_STARTPOOL_4 ); + rStream << SFX_ITEMPOOL_VER_MAJOR << SFX_ITEMPOOL_VER_MINOR; + rStream << SFX_ITEMPOOL_TAG_TRICK4OLD; + + // SfxStyleSheet-Bug umgehen + rStream << UINT16(0); // Version + rStream << UINT16(0); // Count (2. Schleife f"allt sonst auf die Fresse) + } + + // jeder Pool ist als ganzes ein Record + SfxMiniRecordWriter aPoolRec( &rStream, SFX_ITEMPOOL_REC ); + ImpSvtData::GetSvtData().pStoringPool = this; + + // Einzel-Header (Version des Inhalts und Name) + { + SfxMiniRecordWriter aPoolHeaderRec( &rStream, SFX_ITEMPOOL_REC_HEADER); + rStream << pImp->nVersion; + SfxPoolItem::writeByteString(rStream, aName); + } + + // Version-Maps + { + SfxMultiVarRecordWriter aVerRec( &rStream, SFX_ITEMPOOL_REC_VERSIONMAP, 0 ); + for ( USHORT nVerNo = 0; nVerNo < pImp->aVersions.Count(); ++nVerNo ) + { + aVerRec.NewContent(); + SfxPoolVersion_Impl *pVer = pImp->aVersions[nVerNo]; + rStream << pVer->_nVer << pVer->_nStart << pVer->_nEnd; + USHORT nCount = pVer->_nEnd - pVer->_nStart + 1; + USHORT nNewWhich = 0; + for ( USHORT n = 0; n < nCount; ++n ) + { + nNewWhich = pVer->_pMap[n]; + rStream << nNewWhich; + } + + // Workaround gegen Bug in SetVersionMap der 312 + if ( SOFFICE_FILEFORMAT_31 == _nFileFormatVersion ) + rStream << USHORT(nNewWhich+1); + } + } + + // gepoolte Items + { + SfxMultiMixRecordWriter aWhichIdsRec( &rStream, SFX_ITEMPOOL_REC_WHICHIDS, 0 ); + + // erst Atomaren-Items und dann die Sets schreiben (wichtig beim Laden) + for ( pImp->bInSetItem = FALSE; pImp->bInSetItem <= TRUE && !rStream.GetError(); ++pImp->bInSetItem ) + { + SfxPoolItemArray_Impl **pArr = pImp->ppPoolItems; + SfxPoolItem **ppDefItem = ppStaticDefaults; + const USHORT nSize = GetSize_Impl(); + for ( USHORT i = 0; i < nSize && !rStream.GetError(); ++i, ++pArr, ++ppDefItem ) + { + // Version des Items feststellen + USHORT nItemVersion = (*ppDefItem)->GetVersion( _nFileFormatVersion ); + if ( USHRT_MAX == nItemVersion ) + // => kam in zu exportierender Version gar nicht vor + continue; + + // !poolable wird gar nicht im Pool gespeichert + // und itemsets/plain-items je nach Runde +#ifdef TF_POOLABLE + if ( *pArr && IsItemFlag(**ppDefItem, SFX_ITEM_POOLABLE) && +#else + if ( *pArr && (*ppDefItem)->IsPoolable() && +#endif + pImp->bInSetItem == (*ppDefItem)->ISA(SfxSetItem) ) + { + // eigene Kennung, globale Which-Id und Item-Version + USHORT nSlotId = GetSlotId( (*ppDefItem)->Which(), FALSE ); + aWhichIdsRec.NewContent(nSlotId, 0); + rStream << (*ppDefItem)->Which(); + rStream << nItemVersion; + const USHORT nCount = (*pArr)->Count(); + DBG_ASSERT(nCount, "ItemArr ist leer"); + rStream << nCount; + + // Items an sich schreiben + SfxMultiMixRecordWriter aItemsRec( &rStream, SFX_ITEMPOOL_REC_ITEMS, 0 ); + for ( USHORT j = 0; j < nCount; ++j ) + { + // Item selbst besorgen + const SfxPoolItem *pItem = (*pArr)->GetObject(j); + if ( pItem && pItem->GetRefCount() ) //! siehe anderes MI-REF + { + aItemsRec.NewContent(j, 'X' ); + + if ( pItem->GetRefCount() == SFX_ITEMS_SPECIAL ) + rStream << (USHORT) pItem->GetKind(); + else + { + rStream << (USHORT) pItem->GetRefCount(); + if( pItem->GetRefCount() > SFX_ITEMS_OLD_MAXREF ) + rStream.SetError( ERRCODE_IO_NOTSTORABLEINBINARYFORMAT ); + } + + if ( !rStream.GetError() ) + pItem->Store(rStream, nItemVersion); + else + break; +#ifdef DBG_UTIL_MI + if ( !pItem->ISA(SfxSetItem) ) + { + ULONG nMark = rStream.Tell(); + rStream.Seek( nItemStartPos + sizeof(USHORT) ); + SfxPoolItem *pClone = pItem->Create(rStream, nItemVersion ); + USHORT nWh = pItem->Which(); + SFX_ASSERT( rStream.Tell() == nMark, nWh,"asymmetric store/create" ); + SFX_ASSERT( *pClone == *pItem, nWh, "unequal after store/create" ); + delete pClone; + } +#endif + } + } + } + } + } + + pImp->bInSetItem = FALSE; + } + + // die gesetzten Defaults speichern (Pool-Defaults) + if ( !rStream.GetError() ) + { + SfxMultiMixRecordWriter aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS, 0 ); + USHORT nCount = GetSize_Impl(); + for ( USHORT n = 0; n < nCount; ++n ) + { + const SfxPoolItem* pDefaultItem = ppPoolDefaults[n]; + if ( pDefaultItem ) + { + // Version ermitteln + USHORT nItemVersion = pDefaultItem->GetVersion( _nFileFormatVersion ); + if ( USHRT_MAX == nItemVersion ) + // => gab es in der Version noch nicht + continue; + + // eigene Kennung, globale Kennung, Version + USHORT nSlotId = GetSlotId( pDefaultItem->Which(), FALSE ); + aDefsRec.NewContent( nSlotId, 0 ); + rStream << pDefaultItem->Which(); + rStream << nItemVersion; + + // Item an sich + pDefaultItem->Store( rStream, nItemVersion ); + } + } + } + + // weitere Pools rausschreiben + ImpSvtData::GetSvtData().pStoringPool = 0; + aPoolRec.Close(); + if ( !rStream.GetError() && pSecondary ) + pSecondary->Store( rStream ); + + pImp->bStreaming = FALSE; + return rStream; +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::LoadCompleted() + +/* [Beschreibung] + + Wurde der SfxItemPool mit 'bRefCounts' == FALSE geladen, mu\s das + Laden der Dokumentinhalte mit einem Aufruf dieser Methode beendet + werden. Ansonsten hat der Aufruf dieser Methode keine Funktion. + + + [Anmerkung] + + Beim Laden ohne Ref-Counts werden diese tats"achlich auf 1 gesetzt, + damit nicht w"ahrend des Ladevorgangs SfxPoolItems gel"oscht werden, + die danach, aber auch noch beim Ladevorgang, ben"otigt werden. Diese + Methode setzt den Ref-Count wieder zur"uck und entfernt dabei + gleichzeitig alle nicht mehr ben"otigten Items. + + + [Querverweise] + + <SfxItemPool::Load()> +*/ + +{ + // wurden keine Ref-Counts mitgeladen? + if ( pImp->nInitRefCount > 1 ) + { + + // "uber alle Which-Werte iterieren + SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; + for( USHORT nArrCnt = GetSize_Impl(); nArrCnt; --nArrCnt, ++ppItemArr ) + { + // ist "uberhaupt ein Item mit dem Which-Wert da? + if ( *ppItemArr ) + { + // "uber alle Items mit dieser Which-Id iterieren + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for( USHORT n = (*ppItemArr)->Count(); n; --n, ++ppHtArr ) + if (*ppHtArr) + { + #ifdef DBG_UTIL + const SfxPoolItem &rItem = **ppHtArr; + DBG_ASSERT( !rItem.ISA(SfxSetItem) || + 0 != &((const SfxSetItem&)rItem).GetItemSet(), + "SetItem without ItemSet" ); + #endif + + if ( !ReleaseRef( **ppHtArr, 1 ) ) + DELETEZ( *ppHtArr ); + } + } + } + + // from now on normal initial ref count + pImp->nInitRefCount = 1; + } + + // notify secondary pool + if ( pSecondary ) + pSecondary->LoadCompleted(); +} + +//============================================================================ +// This had to be moved to a method of its own to keep Solaris GCC happy: +void SfxItemPool::readTheItems ( + SvStream & rStream, USHORT nItemCount, USHORT nVersion, + SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** ppArr) +{ + SfxMultiRecordReader aItemsRec( &rStream, SFX_ITEMPOOL_REC_ITEMS ); + + SfxPoolItemArray_Impl *pNewArr = new SfxPoolItemArray_Impl( nItemCount ); + SfxPoolItem *pItem = 0; + + USHORT n, nLastSurrogate = USHORT(-1); + while (aItemsRec.GetContent()) + { + // n"achstes Surrogat holen + USHORT nSurrogate = aItemsRec.GetContentTag(); + DBG_ASSERT( aItemsRec.GetContentVersion() == 'X', + "not an item content" ); + + // fehlende auff"ullen + for ( pItem = 0, n = nLastSurrogate+1; n < nSurrogate; ++n ) + pNewArr->C40_INSERT(SfxPoolItem, pItem, n); + nLastSurrogate = nSurrogate; + + // Ref-Count und Item laden + USHORT nRef; + rStream >> nRef; + + pItem = pDefItem->Create(rStream, nVersion); + pNewArr->C40_INSERT(SfxPoolItem, pItem, nSurrogate); + + if ( !bPersistentRefCounts ) + // bis <SfxItemPool::LoadCompleted()> festhalten + AddRef(*pItem, 1); + else + { + if ( nRef > SFX_ITEMS_OLD_MAXREF ) + pItem->SetKind( nRef ); + else + AddRef(*pItem, nRef); + } + } + + // fehlende auff"ullen + for ( pItem = 0, n = nLastSurrogate+1; n < nItemCount; ++n ) + pNewArr->C40_INSERT(SfxPoolItem, pItem, n); + + SfxPoolItemArray_Impl *pOldArr = *ppArr; + *ppArr = pNewArr; + + // die Items merken, die schon im Pool sind + int bEmpty = TRUE; + if ( 0 != pOldArr ) + for ( n = 0; bEmpty && n < pOldArr->Count(); ++n ) + bEmpty = pOldArr->GetObject(n) == 0; + DBG_ASSERTWARNING( bEmpty, "loading non-empty pool" ); + if ( !bEmpty ) + { + // f"ur alle alten suchen, ob ein gleiches neues existiert + for ( USHORT nOld = 0; nOld < pOldArr->Count(); ++nOld ) + { + SfxPoolItem *pOldItem = (*pOldArr)[nOld]; + if ( pOldItem ) + { + USHORT nFree = USHRT_MAX; + int bFound = FALSE; + USHORT nCount = (*ppArr)->Count(); + for ( USHORT nNew = nCount; !bFound && nNew--; ) + { + // geladenes Item + SfxPoolItem *&rpNewItem = + (SfxPoolItem*&)(*ppArr)->GetData()[nNew]; + + // surrogat unbenutzt? + if ( !rpNewItem ) + nFree = nNew; + + // gefunden? + else if ( *rpNewItem == *pOldItem ) + { + // wiederverwenden + AddRef( *pOldItem, rpNewItem->GetRefCount() ); + SetRefCount( *rpNewItem, 0 ); + delete rpNewItem; + rpNewItem = pOldItem; + bFound = TRUE; + } + } + + // vorhervorhandene, nicht geladene uebernehmen + if ( !bFound ) + { + if ( nFree != USHRT_MAX ) + (SfxPoolItem*&)(*ppArr)->GetData()[nFree] = pOldItem; + else + (*ppArr)->C40_INSERT( SfxPoolItem, pOldItem, nCount ); + } + } + } + } + delete pOldArr; +} + +// ----------------------------------------------------------------------- + +SvStream &SfxItemPool::Load(SvStream &rStream) +{ + DBG_CHKTHIS(SfxItemPool, 0); + DBG_ASSERT(ppStaticDefaults, "kein DefaultArray"); + + // protect items by increasing ref count + if ( !bPersistentRefCounts ) + { + + // "uber alle Which-Werte iterieren + SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; + for( USHORT nArrCnt = GetSize_Impl(); nArrCnt; --nArrCnt, ++ppItemArr ) + { + // ist "uberhaupt ein Item mit dem Which-Wert da? + if ( *ppItemArr ) + { + // "uber alle Items mit dieser Which-Id iterieren + SfxPoolItem** ppHtArr = (SfxPoolItem**)(*ppItemArr)->GetData(); + for( USHORT n = (*ppItemArr)->Count(); n; --n, ++ppHtArr ) + if (*ppHtArr) + { + #ifdef DBG_UTIL + const SfxPoolItem &rItem = **ppHtArr; + DBG_ASSERT( !rItem.ISA(SfxSetItem) || + 0 != &((const SfxSetItem&)rItem).GetItemSet(), + "SetItem without ItemSet" ); + DBG_WARNING( "loading non-empty ItemPool" ); + #endif + + AddRef( **ppHtArr, 1 ); + } + } + } + + // during loading (until LoadCompleted()) protect all items + pImp->nInitRefCount = 2; + } + + // Load-Master finden + SfxItemPool *pLoadMaster = pMaster != this ? pMaster : 0; + while ( pLoadMaster && !pLoadMaster->pImp->bStreaming ) + pLoadMaster = pLoadMaster->pSecondary; + + // Gesamt Header einlesen + pImp->bStreaming = TRUE; + if ( !pLoadMaster ) + { + // Format-Version laden + CHECK_FILEFORMAT2( rStream, + SFX_ITEMPOOL_TAG_STARTPOOL_5, SFX_ITEMPOOL_TAG_STARTPOOL_4 ); + rStream >> pImp->nMajorVer >> pImp->nMinorVer; + + // Format-Version in Master-Pool "ubertragen + pMaster->pImp->nMajorVer = pImp->nMajorVer; + pMaster->pImp->nMinorVer = pImp->nMinorVer; + + // altes Format? + if ( pImp->nMajorVer < 2 ) + // pImp->bStreaming wird von Load1_Impl() zur"uckgesetzt + return Load1_Impl( rStream ); + + // zu neues Format? + if ( pImp->nMajorVer > SFX_ITEMPOOL_VER_MAJOR ) + { + rStream.SetError(SVSTREAM_FILEFORMAT_ERROR); + pImp->bStreaming = FALSE; + return rStream; + } + + // Version 1.2-Trick-Daten "uberspringen + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_TRICK4OLD ); + rStream.SeekRel( 4 ); // Hack-Daten wegen SfxStyleSheetPool-Bug skippen + } + + // neues Record-orientiertes Format + SfxMiniRecordReader aPoolRec( &rStream, SFX_ITEMPOOL_REC ); + if ( rStream.GetError() ) + { + pImp->bStreaming = FALSE; + return rStream; + } + + // Einzel-Header + int bOwnPool = TRUE; + UniString aExternName; + { + // Header-Record suchen + SfxMiniRecordReader aPoolHeaderRec( &rStream, SFX_ITEMPOOL_REC_HEADER ); + if ( rStream.GetError() ) + { + pImp->bStreaming = FALSE; + return rStream; + } + + // Header-lesen + rStream >> pImp->nLoadingVersion; + SfxPoolItem::readByteString(rStream, aExternName); + bOwnPool = aExternName == aName; + + //! solange wir keine fremden Pools laden k"onnen + if ( !bOwnPool ) + { + rStream.SetError(SVSTREAM_FILEFORMAT_ERROR); + aPoolRec.Skip(); + pImp->bStreaming = FALSE; + return rStream; + } + } + + // Version-Maps + { + SfxMultiRecordReader aVerRec( &rStream, SFX_ITEMPOOL_REC_VERSIONMAP ); + if ( rStream.GetError() ) + { + pImp->bStreaming = FALSE; + return rStream; + } + + // Versions-Maps einlesen + USHORT nOwnVersion = pImp->nVersion; + for ( USHORT nVerNo = 0; aVerRec.GetContent(); ++nVerNo ) + { + // Header f"ur einzelne Version einlesen + USHORT nVersion, nHStart, nHEnd; + rStream >> nVersion >> nHStart >> nHEnd; + USHORT nCount = nHEnd - nHStart + 1; + + // Version neuer als bekannt? + if ( nVerNo >= pImp->aVersions.Count() ) + { + // neue Version hinzufuegen + USHORT *pMap = new USHORT[nCount]; + for ( USHORT n = 0; n < nCount; ++n ) + rStream >> pMap[n]; + SetVersionMap( nVersion, nHStart, nHEnd, pMap ); + } + } + pImp->nVersion = nOwnVersion; + } + + // Items laden + FASTBOOL bSecondaryLoaded = FALSE; + long nSecondaryEnd = 0; + { + SfxMultiRecordReader aWhichIdsRec( &rStream, SFX_ITEMPOOL_REC_WHICHIDS); + while ( aWhichIdsRec.GetContent() ) + { + // SlotId, Which-Id und Item-Version besorgen + USHORT nCount, nVersion, nWhich; + //!USHORT nSlotId = aWhichIdsRec.GetContentTag(); + rStream >> nWhich; + if ( pImp->nLoadingVersion != pImp->nVersion ) + // Which-Id aus File-Version in Pool-Version verschieben + nWhich = GetNewWhich( nWhich ); + + // unbekanntes Item aus neuerer Version + if ( !IsInRange(nWhich) ) + continue; + + rStream >> nVersion; + rStream >> nCount; + //!SFX_ASSERTWARNING( !nSlotId || !HasMap() || + //! ( nSlotId == GetSlotId( nWhich, FALSE ) ) || + //! !GetSlotId( nWhich, FALSE ), + //! nWhich, "Slot/Which mismatch" ); + + USHORT nIndex = GetIndex_Impl(nWhich); + SfxPoolItemArray_Impl **ppArr = pImp->ppPoolItems + nIndex; + + // SfxSetItems k"onnten Items aus Sekund"arpools beinhalten + SfxPoolItem *pDefItem = *(ppStaticDefaults + nIndex); + pImp->bInSetItem = pDefItem->ISA(SfxSetItem); + if ( !bSecondaryLoaded && pSecondary && pImp->bInSetItem ) + { + // an das Ende des eigenen Pools seeken + ULONG nLastPos = rStream.Tell(); + aPoolRec.Skip(); + + // Sekund"arpool einlesen + pSecondary->Load( rStream ); + bSecondaryLoaded = TRUE; + nSecondaryEnd = rStream.Tell(); + + // zur"uck zu unseren eigenen Items + rStream.Seek(nLastPos); + } + + // Items an sich lesen + readTheItems(rStream, nCount, nVersion, pDefItem, ppArr); + + pImp->bInSetItem = FALSE; + } + } + + // Pool-Defaults lesen + { + SfxMultiRecordReader aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS ); + + while ( aDefsRec.GetContent() ) + { + // SlotId, Which-Id und Item-Version besorgen + USHORT nVersion, nWhich; + //!USHORT nSlotId = aDefsRec.GetContentTag(); + rStream >> nWhich; + if ( pImp->nLoadingVersion != pImp->nVersion ) + // Which-Id aus File-Version in Pool-Version verschieben + nWhich = GetNewWhich( nWhich ); + + // unbekanntes Item aus neuerer Version + if ( !IsInRange(nWhich) ) + continue; + + rStream >> nVersion; + //!SFX_ASSERTWARNING( !HasMap() || ( nSlotId == GetSlotId( nWhich, FALSE ) ), + //! nWhich, "Slot/Which mismatch" ); + + // Pool-Default-Item selbst laden + SfxPoolItem *pItem = + ( *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) + ->Create( rStream, nVersion ); + pItem->SetKind( SFX_ITEMS_POOLDEFAULT ); + *( ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem; + } + } + + // ggf. Secondary-Pool laden + aPoolRec.Skip(); + if ( pSecondary ) + { + if ( !bSecondaryLoaded ) + pSecondary->Load( rStream ); + else + rStream.Seek( nSecondaryEnd ); + } + + // wenn nicht own-Pool, dann kein Name + if ( aExternName != aName ) + aName.Erase(); + + pImp->bStreaming = FALSE; + return rStream; +}; + +// ----------------------------------------------------------------------- + +SvStream &SfxItemPool::Load1_Impl(SvStream &rStream) +{ + // beim Master ist der Header schon von <Load()> geladen worden + if ( !pImp->bStreaming ) + { + // Header des Secondary lesen + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_STARTPOOL_4 ); + rStream >> pImp->nMajorVer >> pImp->nMinorVer; + } + sal_uInt32 nAttribSize; + int bOwnPool = TRUE; + UniString aExternName; + if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 2 ) + rStream >> pImp->nLoadingVersion; + SfxPoolItem::readByteString(rStream, aExternName); + bOwnPool = aExternName == aName; + pImp->bStreaming = TRUE; + + //! solange wir keine fremden laden k"onnen + if ( !bOwnPool ) + { + rStream.SetError(SVSTREAM_FILEFORMAT_ERROR); + pImp->bStreaming = FALSE; + return rStream; + } + + // Versionen bis 1.3 k"onnen noch keine Which-Verschiebungen lesen + if ( pImp->nMajorVer == 1 && pImp->nMinorVer <= 2 && + pImp->nVersion < pImp->nLoadingVersion ) + { + rStream.SetError(ERRCODE_IO_WRONGVERSION); + pImp->bStreaming = FALSE; + return rStream; + } + + // Size-Table liegt hinter den eigentlichen Attributen + rStream >> nAttribSize; + + // Size-Table einlesen + ULONG nStartPos = rStream.Tell(); + rStream.SeekRel( nAttribSize ); + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_SIZES ); + sal_uInt32 nSizeTableLen; + rStream >> nSizeTableLen; + sal_Char *pBuf = new sal_Char[nSizeTableLen]; + rStream.Read( pBuf, nSizeTableLen ); + ULONG nEndOfSizes = rStream.Tell(); + SvMemoryStream aSizeTable( pBuf, nSizeTableLen, STREAM_READ ); + + // ab Version 1.3 steht in der Size-Table eine Versions-Map + if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 3 ) + { + // Version-Map finden (letztes ULONG der Size-Table gibt Pos an) + rStream.Seek( nEndOfSizes - sizeof(sal_uInt32) ); + sal_uInt32 nVersionMapPos; + rStream >> nVersionMapPos; + rStream.Seek( nVersionMapPos ); + + // Versions-Maps einlesen + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_VERSIONMAP ); + USHORT nVerCount; + rStream >> nVerCount; + for ( USHORT nVerNo = 0; nVerNo < nVerCount; ++nVerNo ) + { + // Header f"ur einzelne Version einlesen + USHORT nVersion, nHStart, nHEnd; + rStream >> nVersion >> nHStart >> nHEnd; + USHORT nCount = nHEnd - nHStart + 1; + USHORT nBytes = (nCount)*sizeof(USHORT); + + // Version neuer als bekannt? + if ( nVerNo >= pImp->aVersions.Count() ) + { + // neue Version hinzufuegen + USHORT *pMap = new USHORT[nCount]; + for ( USHORT n = 0; n < nCount; ++n ) + rStream >> pMap[n]; + SetVersionMap( nVersion, nHStart, nHEnd, pMap ); + } + else + // Version schon bekannt => "uberspringen + rStream.SeekRel( nBytes ); + } + } + + // Items laden + rStream.Seek( nStartPos ); + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ITEMS ); + FASTBOOL bSecondaryLoaded = FALSE; + long nSecondaryEnd = 0; + USHORT nWhich, nSlot; + while ( rStream >> nWhich, nWhich ) + { + // ggf. Which-Id aus alter Version verschieben? + if ( pImp->nLoadingVersion != pImp->nVersion ) + nWhich = GetNewWhich( nWhich ); + + rStream >> nSlot; + USHORT nMappedWhich = GetWhich(nSlot, FALSE); + int bKnownItem = bOwnPool || IsWhich(nMappedWhich); + + USHORT nRef, nCount, nVersion; + sal_uInt32 nAttrSize; + rStream >> nVersion >> nCount; + + SfxPoolItemArray_Impl **ppArr = 0; + SfxPoolItemArray_Impl *pNewArr = 0; + SfxPoolItem *pDefItem = 0; + if ( bKnownItem ) + { + if ( !bOwnPool ) + nWhich = nMappedWhich; + + //!SFX_ASSERTWARNING( !nSlot || !HasMap() || + //! ( nSlot == GetSlotId( nWhich, FALSE ) ) || + //! !GetSlotId( nWhich, FALSE ), + //! nWhich, "Slot/Which mismatch" ); + + USHORT nIndex = GetIndex_Impl(nWhich); + ppArr = pImp->ppPoolItems + nIndex; + pNewArr = new SfxPoolItemArray_Impl( nCount ); + pDefItem = *(ppStaticDefaults + nIndex); + } + + // Position vor ersten Item merken + ULONG nLastPos = rStream.Tell(); + + // SfxSetItems k"onnten Items aus Sekund"arpools beinhalten + if ( !bSecondaryLoaded && pSecondary && pDefItem->ISA(SfxSetItem) ) + { + // an das Ende des eigenen Pools seeken + rStream.Seek(nEndOfSizes); + CHECK_FILEFORMAT_RELEASE( rStream, SFX_ITEMPOOL_TAG_ENDPOOL, pNewArr ); + CHECK_FILEFORMAT_RELEASE( rStream, SFX_ITEMPOOL_TAG_ENDPOOL, pNewArr ); + + // Sekund"arpool einlesen + pSecondary->Load1_Impl( rStream ); + bSecondaryLoaded = TRUE; + nSecondaryEnd = rStream.Tell(); + + // zur"uck zu unseren eigenen Items + rStream.Seek(nLastPos); + } + + // Items an sich lesen + for ( USHORT j = 0; j < nCount; ++j ) + { + ULONG nPos = nLastPos; + rStream >> nRef; + + if ( bKnownItem ) + { + SfxPoolItem *pItem = 0; + if ( nRef ) + { + pItem = pDefItem->Create(rStream, nVersion); + + if ( !bPersistentRefCounts ) + // bis <SfxItemPool::LoadCompleted()> festhalten + AddRef(*pItem, 1); + else + { + if ( nRef > SFX_ITEMS_OLD_MAXREF ) + pItem->SetKind( nRef ); + else + AddRef(*pItem, nRef); + } + } + + pNewArr->C40_INSERT( SfxPoolItem, pItem, j); + + // restliche gespeicherte Laenge skippen (neueres Format) + nLastPos = rStream.Tell(); + } + + aSizeTable >> nAttrSize; + SFX_ASSERT( !bKnownItem || ( nPos + nAttrSize) >= nLastPos, + nPos, + "too many bytes read - version mismatch?" ); + + if ( !bKnownItem || ( nLastPos < (nPos + nAttrSize) ) ) + { + nLastPos = nPos + nAttrSize; + rStream.Seek( nLastPos ); + } + } + + if ( bKnownItem ) + { + SfxPoolItemArray_Impl *pOldArr = *ppArr; + *ppArr = pNewArr; + + // die Items merken, die schon im Pool sind + int bEmpty = TRUE; + if ( 0 != pOldArr ) + for ( USHORT n = 0; bEmpty && n < pOldArr->Count(); ++n ) + bEmpty = pOldArr->GetObject(n) == 0; + DBG_ASSERTWARNING( bEmpty, "loading non-empty pool" ); + if ( !bEmpty ) + { + // f"ur alle alten suchen, ob ein gleiches neues existiert + for ( USHORT nOld = 0; nOld < pOldArr->Count(); ++nOld ) + { + SfxPoolItem *pOldItem = (*pOldArr)[nOld]; + if ( pOldItem ) + { + int bFound = FALSE; + for ( USHORT nNew = 0; + !bFound && nNew < (*ppArr)->Count(); + ++nNew ) + { + SfxPoolItem *&rpNewItem = + (SfxPoolItem*&)(*ppArr)->GetData()[nNew]; + + if ( rpNewItem && *rpNewItem == *pOldItem ) + { + AddRef( *pOldItem, rpNewItem->GetRefCount() ); + SetRefCount( *rpNewItem, 0 ); + delete rpNewItem; + rpNewItem = pOldItem; + bFound = TRUE; + SFX_TRACE( "reusing item", pOldItem ); + } + } + //! DBG_ASSERT( bFound, "old-item not found in file" ); + if ( !bFound ) + { + SFX_TRACE( "item not found: ", pOldItem ); + } + } + } + } + delete pOldArr; /* @@@ */ + } + } + + // Pool-Defaults lesen + if ( pImp->nMajorVer > 1 || pImp->nMinorVer > 0 ) + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_DEFAULTS ); + + ULONG nLastPos = rStream.Tell(); + while ( rStream >> nWhich, nWhich ) + { + // ggf. Which-Id aus alter Version verschieben? + if ( pImp->nLoadingVersion != pImp->nVersion ) + nWhich = GetNewWhich( nWhich ); + + rStream >> nSlot; + USHORT nMappedWhich = GetWhich(nSlot, FALSE); + int bKnownItem = bOwnPool || IsWhich(nMappedWhich); + + ULONG nPos = nLastPos; + sal_uInt32 nSize; + USHORT nVersion; + rStream >> nVersion; + + if ( bKnownItem ) + { + if ( !bOwnPool ) + nWhich = nMappedWhich; + SfxPoolItem *pItem = + ( *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) + ->Create( rStream, nVersion ); + pItem->SetKind( SFX_ITEMS_POOLDEFAULT ); + *( ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem; + } + + nLastPos = rStream.Tell(); + aSizeTable >> nSize; + SFX_ASSERT( ( nPos + nSize) >= nLastPos, nPos, + "too many bytes read - version mismatch?" ); + if ( nLastPos < (nPos + nSize) ) + rStream.Seek( nPos + nSize ); + } + + delete[] pBuf; + rStream.Seek(nEndOfSizes); + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL ); + CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL ); + + if ( pSecondary ) + { + if ( !bSecondaryLoaded ) + pSecondary->Load1_Impl( rStream ); + else + rStream.Seek( nSecondaryEnd ); + } + + if ( aExternName != aName ) + aName.Erase(); + + pImp->bStreaming = FALSE; + return rStream; +} + +// ----------------------------------------------------------------------- + +const SfxPoolItem* SfxItemPool::LoadSurrogate +( + SvStream& rStream, // vor einem Surrogat positionierter Stream + USHORT& rWhich, // Which-Id des zu ladenden <SfxPoolItem>s + USHORT nSlotId, // Slot-Id des zu ladenden <SfxPoolItem>s + const SfxItemPool* pRefPool // <SfxItemPool> in dem das Surrogat gilt +) + +/* [Beschreibung] + + L"adt Surrogat aus 'rStream' und liefert das dadurch in 'rRefPool' + repr"asentierte SfxPoolItem zu"ruck. Ist das im Stream befindliche + Surrogat == SFX_ITEMS_DIRECT (!SFX_ITEM_POOLABLE) wird 0 zur"uckgegeben, + das Item ist direkt aus dem Stream zu laden. Bei 0xfff0 (SFX_ITEMS_NULL) + wird auch 0 zurueckgegeben und rWhich auf 0 gesetzt, das Item ist nicht + verfuegbar. + + Ansonsten wird ber"ucksichtigt, ob der betroffene Pool ohne Ref-Counts + geladen wird, ob aus einem neuen Pool nachgeladen wird (&rRefPool != this) + oder ob aus einem g"anzlich anders aufgebauten Pool geladen wird. + + Wird aus einem anders aufgebauten Pool geladen und die 'nSlotId' kann + nicht in eine Which-Id dieses Pools gemappt werden, wird ebenfalls 0 + zur"uckgeliefert. + + Preconditions: - Pool mu\s geladen sein + - LoadCompleted darf noch nicht gerufen worden sein + - 'rStream' steht genau an der Position, an der ein + Surrogat f"ur ein Item mit der SlotId 'nSlotId' und + der WhichId 'rWhichId' mit StoreSurrogate gepeichert + wurde + + Postconditions: - 'rStream' ist so positioniert, wie auch StoreSurrogate + sein speichern beendet hatte + - konnte ein Item geladen werden, befindet es sich + in diesem SfxItemPool + - 'rWhichId' enth"alt die ggf. gemappte Which-Id + Laufzeit: Tiefe des Ziel Sekund"arpools * 10 + 10 + + [Querverweise] + + <SfxItemPool::StoreSurrogate(SvStream&,const SfxPoolItem &)const> +*/ + +{ + // erstmal das Surrogat lesen + USHORT nSurrogat; + rStream >> nSurrogat; + + // direkt gespeichertes Item? + if ( SFX_ITEMS_DIRECT == nSurrogat ) + return 0; + + // nicht vorhandenes Item? + if ( SFX_ITEMS_NULL == nSurrogat ) + { + rWhich = 0; + return 0; + } + + // Bei einem identisch aufgebauten Pool (im Stream) kann das Surrogat + // auf jeden Fall aufgel"ost werden. + if ( !pRefPool ) + pRefPool = this; + FASTBOOL bResolvable = pRefPool->GetName().Len() > 0; + if ( !bResolvable ) + { + // Bei einem anders aufgebauten Pool im Stream, mu\s die SlotId + // aus dem Stream in eine Which-Id gemappt werden k"onnen. + USHORT nMappedWhich = nSlotId ? GetWhich(nSlotId, TRUE) : 0; + if ( IsWhich(nMappedWhich) ) + { + // gemappte SlotId kann "ubernommen werden + rWhich = nMappedWhich; + bResolvable = TRUE; + } + } + + // kann Surrogat aufgel"ost werden? + const SfxPoolItem *pItem = 0; + if ( bResolvable ) + { + for ( SfxItemPool *pTarget = this; pTarget; pTarget = pTarget->pSecondary ) + { + // richtigen (Folge-) Pool gefunden? + if ( pTarget->IsInRange(rWhich) ) + { + // dflt-Attribut? + if ( SFX_ITEMS_STATICDEFAULT == nSurrogat ) + return *(pTarget->ppStaticDefaults + + pTarget->GetIndex_Impl(rWhich)); + + SfxPoolItemArray_Impl* pItemArr = *(pTarget->pImp->ppPoolItems + + pTarget->GetIndex_Impl(rWhich)); + pItem = pItemArr && nSurrogat < pItemArr->Count() + ? (*pItemArr)[nSurrogat] + : 0; + if ( !pItem ) + { + DBG_ERROR( "can't resolve surrogate" ); + rWhich = 0; // nur zur Sicherheit fuer richtige Stream-Pos + return 0; + } + + // Nachladen aus Ref-Pool? + if ( pRefPool != pMaster ) + return &pTarget->Put( *pItem ); + + // Referenzen sind NICHT schon mit Pool geladen worden? + if ( !pTarget->HasPersistentRefCounts() ) + AddRef( *pItem, 1 ); + else + return pItem; + + return pItem; + } + } + + SFX_ASSERT( FALSE, rWhich, "can't resolve Which-Id in LoadSurrogate" ); + } + + return 0; +} + +//------------------------------------------------------------------------- + + +FASTBOOL SfxItemPool::StoreSurrogate +( + SvStream& rStream, + const SfxPoolItem* pItem +) const + +/* [Beschreibung] + + Speichert ein Surrogat f"ur '*pItem' in 'rStream'. + + + [R"uckgabewert] + + FASTBOOL TRUE + es wurde ein echtes Surrogat gespeichert, auch + SFX_ITEMS_NULL bei 'pItem==0', + SFX_ITEMS_STATICDEFAULT und SFX_ITEMS_POOLDEFAULT + gelten als 'echte' Surrogate + + FALSE + es wurde ein Dummy-Surrogat (SFX_ITEMS_DIRECT) + gespeichert, das eigentliche Item mu\s direkt + hinterher selbst gespeichert werden +*/ + +{ + if ( pItem ) + { + FASTBOOL bRealSurrogate = IsItemFlag(*pItem, SFX_ITEM_POOLABLE); + rStream << ( bRealSurrogate + ? GetSurrogate( pItem ) + : (UINT16) SFX_ITEMS_DIRECT ); + return bRealSurrogate; + } + + rStream << (UINT16) SFX_ITEMS_NULL; + return TRUE; +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetSurrogate(const SfxPoolItem *pItem) const +{ + DBG_CHKTHIS(SfxItemPool, 0); + DBG_ASSERT( pItem, "no 0-Pointer Surrogate" ); + DBG_ASSERT( !IsInvalidItem(pItem), "no Invalid-Item Surrogate" ); + DBG_ASSERT( !IsPoolDefaultItem(pItem), "no Pool-Default-Item Surrogate" ); + + if ( !IsInRange(pItem->Which()) ) + { + if ( pSecondary ) + return pSecondary->GetSurrogate( pItem ); + SFX_ASSERT( 0, pItem->Which(), "unknown Which-Id - dont ask me for surrogates" ); + } + + // Pointer auf static- oder pool-dflt-Attribut? + if( IsStaticDefaultItem(pItem) || IsPoolDefaultItem(pItem) ) + return SFX_ITEMS_STATICDEFAULT; + + SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(pItem->Which())); + DBG_ASSERT(pItemArr, "ItemArr nicht vorhanden"); + const USHORT nCount = pItemArr->Count(); + for ( USHORT i = 0; i < nCount; ++i ) + { + const SfxPoolItem *p = (*pItemArr)[i]; + if ( p == pItem ) + return i; + } + SFX_ASSERT( 0, pItem->Which(), "Item nicht im Pool"); + return SFX_ITEMS_NULL; +} + +// ----------------------------------------------------------------------- + +FASTBOOL SfxItemPool::IsInStoringRange( USHORT nWhich ) const +{ + return nWhich >= pImp->nStoringStart && + nWhich <= pImp->nStoringEnd; +} + +//------------------------------------------------------------------------ + +void SfxItemPool::SetStoringRange( USHORT nFrom, USHORT nTo ) + +/* [Beschreibung] + + Mit dieser Methode kann der Which-Bereich eingeengt werden, der + von ItemSets dieses Pool (und dem Pool selbst) gespeichert wird. + Die Methode muss dazu vor <SfxItemPool::Store()> gerufen werden + und die Werte muessen auch noch gesetzt sein, wenn das eigentliche + Dokument (also die ItemSets gespeicher werden). + + Ein Zuruecksetzen ist dann nicht noetig, wenn dieser Range vor + JEDEM Speichern richtig gesetzt wird, da er nur beim Speichern + beruecksichtigt wird. + + Dieses muss fuer das 3.1-Format gemacht werden, da dort eine + Bug in der Pool-Lade-Methode vorliegt. +*/ + +{ + pImp->nStoringStart = nFrom; + pImp->nStoringEnd = nTo; +} + +// ----------------------------------------------------------------------- + +void SfxItemPool::SetVersionMap +( + USHORT nVer, /* neue Versionsnummer */ + USHORT nOldStart, /* alte erste Which-Id */ + USHORT nOldEnd, /* alte letzte Which-Id */ + USHORT* pOldWhichIdTab /* Array mit genau dem Aufbau der Which-Ids + der vorhergehenden Version, in denen + die jeweils neue Which-Id steht. */ +) + +/* [Beschreibung] + + Mit dieser Methode k"onnen neue, inkompatible Which-Id-Folgen oder + Verteilungen realisiert werden. Pools, die noch mit alten Versionen + gespeichert wurden, werden dann "uber die angegebene Tabelle solange + gemappt, bis die aktuelle Version erreicht ist. Neuere Pools k"onnen + unter Verlust neuer Attribute geladen werden, da die Map mit dem Pool + gespeichert wird. + + Precondition: Pool darf noch nicht geladen sein + Postcondition: Which-Ids aus fr"uheren Versionen k"onnen bei Laden auf + Version 'nVer' gemappt werden + Laufzeit: 1.5 * new + 10 + + [Anmerkung] + + F"ur neue Which-Ranges (nStart,nEnd) m"ssen im Vergleich zur Vorg"anger- + Version (nOldStart,nOldEnd) immer gelten, da\s (nOldStart,nOldEnd) + vollst"andig in (nStart,nEnd) enthalten ist. Es ist also zul"assig, den + Which-Range in beide Richtungen zu erweitern, auch durch Einf"ugung + von Which-Ids, nicht aber ihn zu beschneiden. + + Diese Methode sollte nur im oder direkt nach Aufruf des Konstruktors + gerufen werden. + + Das Array mu\s statisch sein, da es nicht kopiert wird und au\serdem + im Copy-Ctor des SfxItemPool wiederverwendet wird. + + + [Beispiel] + + Urspr"unglich (Version 0) hatte der Pool folgende Which-Ids: + + 1:A, 2:B, 3:C, 4:D + + Nun soll eine neue Version (Version 1) zwei zus"atzliche Ids X und Y + zwischen B und C erhalten, also wie folgt aussehen: + + 1:A, 2:B, 3:X, 4:Y, 5:C, 6:D + + Dabei haben sich also die Ids 3 und 4 ge"andert. F"ur die neue Version + m"u\ste am Pool folgendes gesetzt werden: + + static USHORT nVersion1Map = { 1, 2, 5, 6 }; + pPool->SetVersionMap( 1, 1, 4, &nVersion1Map ); + + + [Querverweise] + + <SfxItemPool::IsLoadingVersionCurrent()const> + <SfxItemPool::GetNewWhich(USHORT)> + <SfxItemPool::GetVersion()const> + <SfxItemPool::GetLoadingVersion()const> +*/ + +{ + // neuen Map-Eintrag erzeugen und einf"ugen + const SfxPoolVersion_Impl *pVerMap = new SfxPoolVersion_Impl( + nVer, nOldStart, nOldEnd, pOldWhichIdTab ); + pImp->aVersions.Insert( pVerMap, pImp->aVersions.Count() ); + + DBG_ASSERT( nVer > pImp->nVersion, "Versions not sorted" ); + pImp->nVersion = nVer; + + // Versions-Range anpassen + for ( USHORT n = 0; n < nOldEnd-nOldStart+1; ++n ) + { + USHORT nWhich = pOldWhichIdTab[n]; + if ( nWhich < pImp->nVerStart ) + { + if ( !nWhich ) + nWhich = 0; + pImp->nVerStart = nWhich; + } + else if ( nWhich > pImp->nVerEnd ) + pImp->nVerEnd = nWhich; + } +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetNewWhich +( + USHORT nFileWhich // die aus dem Stream geladene Which-Id +) const + +/* [Beschreibung] + + Diese Methoden rechnet Which-Ids aus einem File-Format in die der + aktuellen Pool-Version um. Ist das File-Format "alter, werden die vom + Pool-Entwickler mit SetVersion() gesetzten Tabellen verwendet, + ist das File-Format neuer, dann die aus dem File geladenen Tabellen. + Im letzteren Fall kann ggf. nicht jede Which-Id gemappt werden, + so da\s 0 zur"uckgeliefert wird. + + Die Berechnung ist nur f"ur Which-Ids definiert, die in der betreffenden + File-Version unterst"utzt wurden. Dies ist per Assertion abgesichert. + + Precondition: Pool mu\s geladen sein + Postcondition: unver"andert + Laufzeit: linear(Anzahl der Sekund"arpools) + + linear(Differenz zwischen alter und neuer Version) + + + [Querverweise] + + <SfxItemPool::IsLoadingVersionCurrent()const> + <SfxItemPool::SetVersionMap(USHORT,USHORT,USHORT,USHORT*)> + <SfxItemPool::GetVersion()const> + <SfxItemPool::GetLoadingVersion()const> +*/ + +{ + // (Sekund"ar-) Pool bestimmen + if ( !IsInVersionsRange(nFileWhich) ) + { + if ( pSecondary ) + return pSecondary->GetNewWhich( nFileWhich ); + SFX_ASSERT( 0, nFileWhich, "unknown which in GetNewWhich()" ); + } + + // Version neuer/gleich/"alter? + short nDiff = (short)pImp->nLoadingVersion - (short)pImp->nVersion; + + // Which-Id einer neueren Version? + if ( nDiff > 0 ) + { + // von der Top-Version bis runter zur File-Version stufenweise mappen + for ( USHORT nMap = pImp->aVersions.Count(); nMap > 0; --nMap ) + { + SfxPoolVersion_Impl *pVerInfo = pImp->aVersions[nMap-1]; + if ( pVerInfo->_nVer > pImp->nVersion ) + { USHORT nOfs; + USHORT nCount = pVerInfo->_nEnd - pVerInfo->_nStart + 1; + for ( nOfs = 0; + nOfs <= nCount && + pVerInfo->_pMap[nOfs] != nFileWhich; + ++nOfs ) + continue; + + if ( pVerInfo->_pMap[nOfs] == nFileWhich ) + nFileWhich = pVerInfo->_nStart + nOfs; + else + return 0; + } + else + break; + } + } + + // Which-Id einer neueren Version? + else if ( nDiff < 0 ) + { + // von der File-Version bis zur aktuellen Version stufenweise mappen + for ( USHORT nMap = 0; nMap < pImp->aVersions.Count(); ++nMap ) + { + SfxPoolVersion_Impl *pVerInfo = pImp->aVersions[nMap]; + if ( pVerInfo->_nVer > pImp->nLoadingVersion ) + { + DBG_ASSERT( nFileWhich >= pVerInfo->_nStart && + nFileWhich <= pVerInfo->_nEnd, + "which-id unknown in version" ); + nFileWhich = pVerInfo->_pMap[nFileWhich - pVerInfo->_nStart]; + } + } + } + + // originale (nDiff==0) bzw. gemappte (nDiff!=0) Id zur"uckliefern + return nFileWhich; +} + +// ----------------------------------------------------------------------- + + +FASTBOOL SfxItemPool::IsInVersionsRange( USHORT nWhich ) const +{ + return nWhich >= pImp->nVerStart && nWhich <= pImp->nVerEnd; +} + +// ----------------------------------------------------------------------- + +FASTBOOL SfxItemPool::IsCurrentVersionLoading() const + +/* [Beschreibung] + + Mit dieser Methode kann festgestellt werden, ob die geladene Pool-Version + dem aktuellen Pool-Aufbau entspricht. + + Precondition: Pool mu\s geladen sein + Postcondition: unver"andert + Laufzeit: linear(Anzahl der Sekund"arpools) + + + [Querverweise] + + <SfxItemPool::SetVersionMap(USHORT,USHORT,USHORT,USHORT*)> + <SfxItemPool::GetNewWhich(USHORT)const> + <SfxItemPool::GetVersion()const> + <SfxItemPool::GetLoadingVersion()const> +*/ + +{ + return ( pImp->nVersion == pImp->nLoadingVersion ) && + ( !pSecondary || pSecondary->IsCurrentVersionLoading() ); +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetVersion() const + +/* [Beschreibung] + + Diese Methode liefert die aktuelle Versionsnummer des SfxItemPool-Aufbaus + (also des Which-Bereichs). + + Precondition: keine + Postcondition: unver"andert + Laufzeit: 2 + + + [Anmerkung] + + Achtung: Es mu\s ggf. die Versionsnummer von Sekund"arpools + ber"ucksichtigt werden. + + + [Querverweise] + + <SfxItemPool::IsLoadingVersionCurrent()const> + <SfxItemPool::SetVersionMap(USHORT,USHORT,USHORT,USHORT*)> + <SfxItemPool::GetNewWhich(USHORT)const> + <SfxItemPool::GetLoadingVersion()const> +*/ + +{ + return pImp->nVersion; +} + +// ----------------------------------------------------------------------- + +USHORT SfxItemPool::GetLoadingVersion() const + +/* [Beschreibung] + + Diese Methode liefert die Versionsnummer des SfxItemPool-Aufbaus + (also des Which-Bereichs), die bei Laden vorgefunden wurde. + + Precondition: Pool mu\s geladen sein + Postcondition: unver"andert + Laufzeit: 2 + + + [Anmerkung] + + Achtung: Es mu\s ggf. die Versionsnummer von Sekund"arpools + ber"ucksichtigt werden. + + + [Querverweise] + + <SfxItemPool::IsLoadingVersionCurrent()const> + <SfxItemPool::SetVersionMap(USHORT,USHORT,USHORT,USHORT*)> + <SfxItemPool::GetNewWhich(USHORT)const> + <SfxItemPool::GetVersion()const> +*/ + +{ + return pImp->nLoadingVersion; +} + +//------------------------------------------------------------------------- + +FASTBOOL SfxItemPool::IsVer2_Impl() const +{ + return pMaster->pImp->nMajorVer >= 2; +} + +//------------------------------------------------------------------------- + + +FASTBOOL SfxItemPool::StoreItem( SvStream &rStream, const SfxPoolItem &rItem, + FASTBOOL bDirect ) const + +/* [Beschreibung] + + Speichert das <SfxPoolItem> 'rItem' in den <SvStream> 'rStream' + entweder als Surrogat ('bDirect == FALSE') oder direkt mit 'rItem.Store()'. + Nicht poolable Items werden immer direkt gespeichert. Items ohne Which-Id, + also SID-Items, werden nicht gespeichert, ebenso wenn Items, die in der + File-Format-Version noch nicht vorhanden waren (return FALSE). + + Das Item wird im Stream wie folgt abgelegt: + + USHORT rItem.Which() + USHORT GetSlotId( rItem.Which() ) bzw. 0 falls nicht verf"urbar + USHORT GetSurrogate( &rItem ) bzw. SFX_ITEM_DIRECT bei '!SFX_ITEM_POOLBLE' + + optional (falls 'bDirect == TRUE' oder '!rItem.IsPoolable()': + + USHORT rItem.GetVersion() + ULONG Size + Size rItem.Store() + + + [Querverweise] + + <SfxItemPool::LoadItem(SvStream&,FASTBOOL)const> +*/ + +{ + DBG_ASSERT( !IsInvalidItem(&rItem), "cannot store invalid items" ); + + if ( IsSlot( rItem.Which() ) ) + return FALSE; + const SfxItemPool *pPool = this; + while ( !pPool->IsInStoringRange(rItem.Which()) ) + if ( 0 == ( pPool = pPool->pSecondary ) ) + return FALSE; + + DBG_ASSERT( !pImp->bInSetItem || !rItem.ISA(SfxSetItem), + "SetItem contains ItemSet with SetItem" ); + + USHORT nSlotId = pPool->GetSlotId( rItem.Which(), TRUE ); + USHORT nItemVersion = rItem.GetVersion(_nFileFormatVersion); + if ( USHRT_MAX == nItemVersion ) + return FALSE; + + rStream << rItem.Which() << nSlotId; + if ( bDirect || !pPool->StoreSurrogate( rStream, &rItem ) ) + { + rStream << nItemVersion; + rStream << (UINT32) 0L; // Platz fuer Laenge in Bytes + ULONG nIStart = rStream.Tell(); + rItem.Store(rStream, nItemVersion); + ULONG nIEnd = rStream.Tell(); + rStream.Seek( nIStart-4 ); + rStream << (INT32) ( nIEnd-nIStart ); + rStream.Seek( nIEnd ); + } + + return TRUE; +} + +//------------------------------------------------------------------------- + + +const SfxPoolItem* SfxItemPool::LoadItem( SvStream &rStream, FASTBOOL bDirect, + const SfxItemPool *pRefPool ) + +// pRefPool==-1 => nicht putten! + +{ + USHORT nWhich, nSlot; // nSurrogate; + rStream >> nWhich >> nSlot; + + BOOL bDontPut = (SfxItemPool*)-1 == pRefPool; + if ( bDontPut || !pRefPool ) + pRefPool = this; + + // richtigen Sekund"ar-Pool finden + while ( !pRefPool->IsInVersionsRange(nWhich) ) + { + if ( pRefPool->pSecondary ) + pRefPool = pRefPool->pSecondary; + else + { + // WID in der Version nicht vorhanden => ueberspringen + USHORT nSurro, nVersion, nLen; + rStream >> nSurro; + if ( SFX_ITEMS_DIRECT == nSurro ) + { + rStream >> nVersion >> nLen; + rStream.SeekRel( nLen ); + } + return 0; + } + } + + // wird eine andere Version geladen? + FASTBOOL bCurVersion = pRefPool->IsCurrentVersionLoading(); + if ( !bCurVersion ) + // Which-Id auf neue Version mappen + nWhich = pRefPool->GetNewWhich( nWhich ); + + DBG_ASSERT( !nWhich || !pImp->bInSetItem || + !pRefPool->ppStaticDefaults[pRefPool->GetIndex_Impl(nWhich)]->ISA(SfxSetItem), + "loading SetItem in ItemSet of SetItem" ); + + // soll "uber Surrogat geladen werden? + const SfxPoolItem *pItem = 0; + if ( !bDirect ) + { + // Which-Id in dieser Version bekannt? + if ( nWhich ) + // Surrogat laden, reagieren falls keins vorhanden + pItem = LoadSurrogate( rStream, nWhich, nSlot, pRefPool ); + else + // sonst "uberspringen + rStream.SeekRel( sizeof(USHORT) ); + } + + // wird direkt, also nicht "uber Surrogat geladen? + if ( bDirect || ( nWhich && !pItem ) ) + { + // bDirekt bzw. nicht IsPoolable() => Item direkt laden + USHORT nVersion; + sal_uInt32 nLen; + rStream >> nVersion >> nLen; + ULONG nIStart = rStream.Tell(); + + // Which-Id in dieser Version bekannt? + if ( nWhich ) + { + // Item direkt laden + SfxPoolItem *pNewItem = + pRefPool->GetDefaultItem(nWhich).Create(rStream, nVersion); + if ( bDontPut ) + pItem = pNewItem; + else + if ( pNewItem ) + { + pItem = &Put(*pNewItem); + delete pNewItem; + } + else + pItem = 0; + ULONG nIEnd = rStream.Tell(); + DBG_ASSERT( nIEnd <= (nIStart+nLen), "read past end of item" ); + if ( (nIStart+nLen) != nIEnd ) + rStream.Seek( nIStart+nLen ); + } + else + // Item "uberspringen + rStream.Seek( nIStart+nLen ); + } + + return pItem; +} + + diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx new file mode 100644 index 000000000000..ef160b4a8b4c --- /dev/null +++ b/svl/source/items/poolitem.cxx @@ -0,0 +1,527 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: poolitem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/poolitem.hxx> +#include <tools/stream.hxx> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxPoolItem) +DBG_NAME(SfxVoidItem) +// @@@ DBG_NAME(SfxInvalidItem); +DBG_NAME(SfxItemHandle) + +BYTE nSfxFlag8Val[8] = +{ + 1, 2, 4, 8, 16, 32, 64, 128 +}; + +USHORT nSfxFlag16Val[16] = +{ + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, + 1024, 2048, 4096, 8192, 16384, 32768 +}; + +ULONG nSfxFlag32Val[32] = +{ + 0x1L, 0x2L, 0x4L, 0x8L, + 0x10L, 0x20L, 0x40L, 0x80L, + 0x100L, 0x200L, 0x400L, 0x800L, + 0x1000L, 0x2000L, 0x40000L, 0x8000L, + 0x10000L, 0x20000L, 0x40000L, 0x80000L, + 0x100000L, 0x200000L, 0x400000L, 0x800000L, + 0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L, + 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L +}; + +// RTTI ------------------------------------------------------------------ + +TYPEINIT0(SfxPoolItem); +TYPEINIT1(SfxVoidItem, SfxPoolItem); +// @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem); +TYPEINIT1(SfxSetItem, SfxPoolItem); +// @@@ TYPEINIT1(SfxItemChangedHint, SfxHint); + +// ------------------------------------------------------------------------ +#if OSL_DEBUG_LEVEL > 1 +static ULONG nItemCount = 0; + +const char* pw1 = "Wow! 10.000 items!"; +const char* pw2 = "Wow! 100.000 items!"; +const char* pw3 = "Wow! 1.000.000 items!"; +const char* pw4 = "Wow! 50.000.000 items!"; +const char* pw5 = "Wow! 10.000.000 items!"; +#endif + +IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem) + +// SfxPoolItem ----------------------------------------------------------- +SfxPoolItem::SfxPoolItem( USHORT nW ) + : nRefCount( 0 ), + nWhich( nW ) + , nKind( 0 ) +{ + DBG_CTOR(SfxPoolItem, 0); + DBG_ASSERT(nW <= SHRT_MAX, "Which Bereich ueberschritten"); +#if OSL_DEBUG_LEVEL > 1 + ++nItemCount; + if ( pw1 && nItemCount>=10000 ) + { + DBG_WARNING( pw1 ); + pw1 = NULL; + } + if ( pw2 && nItemCount>=100000 ) + { + DBG_WARNING( pw2 ); + pw2 = NULL; + } + if ( pw3 && nItemCount>=1000000 ) + { + DBG_WARNING( pw3 ); + pw3 = NULL; + } + if ( pw4 && nItemCount>=5000000 ) + { + DBG_WARNING( pw4 ); + pw4 = NULL; + } + if ( pw5 && nItemCount>=10000000 ) + { + DBG_WARNING( pw5 ); + pw5 = NULL; + } +#endif +} + +// ----------------------------------------------------------------------- +SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy ) + : nRefCount( 0 ), // wird ja ein neues Object! + nWhich( rCpy.Which() ) // Funktion rufen wg. ChkThis() + , nKind( 0 ) +{ + DBG_CTOR(SfxPoolItem, 0); +#if OSL_DEBUG_LEVEL > 1 + ++nItemCount; + if ( pw1 && nItemCount>=10000 ) + { + DBG_WARNING( pw1 ); + pw1 = NULL; + } + if ( pw2 && nItemCount>=100000 ) + { + DBG_WARNING( pw2 ); + pw2 = NULL; + } + if ( pw3 && nItemCount>=1000000 ) + { + DBG_WARNING( pw3 ); + pw3 = NULL; + } + if ( pw4 && nItemCount>=5000000 ) + { + DBG_WARNING( pw4 ); + pw4 = NULL; + } + if ( pw5 && nItemCount>=10000000 ) + { + DBG_WARNING( pw5 ); + pw5 = NULL; + } +#endif +} + +// ------------------------------------------------------------------------ +SfxPoolItem::~SfxPoolItem() +{ + DBG_DTOR(SfxPoolItem, 0); + DBG_ASSERT(nRefCount == 0 || nRefCount > SFX_ITEMS_MAXREF, "destroying item in use" ); +#if OSL_DEBUG_LEVEL > 1 + --nItemCount; +#endif +} + +// ------------------------------------------------------------------------ +int SfxPoolItem::Compare( const SfxPoolItem& ) const +{ + return 0; +} + +// ------------------------------------------------------------------------ +int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const +{ + return Compare( rWith ); +} + +// ------------------------------------------------------------------------ +int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const +{ + DBG_CHKTHIS(SfxPoolItem, 0); + return rCmp.Type() == Type(); +} + +// ----------------------------------------------------------------------- +#ifndef TF_POOLABLE + +int SfxPoolItem::IsPoolable() const +{ + DBG_CHKTHIS(SfxPoolItem, 0); + return TRUE; +} +#endif + +// ----------------------------------------------------------------------- +SfxPoolItem* SfxPoolItem::Create(SvStream &, USHORT) const +{ + DBG_CHKTHIS(SfxPoolItem, 0); + return Clone(0); +} + +// ----------------------------------------------------------------------- +USHORT SfxPoolItem::GetVersion( USHORT ) const +{ + DBG_CHKTHIS(SfxPoolItem, 0); + return 0; +} + +// ----------------------------------------------------------------------- +SvStream& SfxPoolItem::Store(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxPoolItem, 0); + return rStream; +} + +//============================================================================ +// static +bool SfxPoolItem::readByteString(SvStream & rStream, UniString & rString) +{ + rStream.ReadByteString(rString); + return rStream.GetError() == ERRCODE_NONE; +} + +//============================================================================ +// static +void SfxPoolItem::writeByteString(SvStream & rStream, + UniString const & rString) +{ + rStream.WriteByteString(rString); +} + +//============================================================================ +// static +bool SfxPoolItem::readUnicodeString(SvStream & rStream, UniString & rString, + bool bUnicode) +{ + rStream.ReadByteString(rString, + bUnicode ? RTL_TEXTENCODING_UCS2 : + rStream.GetStreamCharSet()); + return rStream.GetError() == ERRCODE_NONE; +} + +//============================================================================ +// static +void SfxPoolItem::writeUnicodeString(SvStream & rStream, + UniString const & rString) +{ + rStream.WriteByteString(rString, RTL_TEXTENCODING_UCS2); +} + +// ------------------------------------------------------------------------ +SfxItemPresentation SfxPoolItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, // IN: wie formatiert werden soll + SfxMapUnit /*eCoreMetric*/, // IN: Ma\seinheit des SfxPoolItems + SfxMapUnit /*ePresentationMetric*/, // IN: Wunsch-Ma\einheit der Darstellung + XubString& /*rText*/, // OUT: textuelle Darstellung + const IntlWrapper * +) const + +/* [Beschreibung] + + "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen + eine textuelle Datstellung des Wertes erhalten werden. Sie sollte + von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden. + + Da die Ma\seinheit des Wertes im SfxItemPool nur "uber + <SfxItemPool::GetMetric(USHORT)const> erfragbar ist, und nicht etwa + in der SfxPoolItem-Instanz oder -Subklasse verf"ugbar ist, wird die + eigene Ma\seinheit als 'eCoreMetric' "ubergeben. + + Die darzustellende Ma\seinheit wird als 'ePresentationMetric' + "ubergeben. + + + [R"uckgabewert] + + SfxItemPresentation SFX_ITEM_PRESENTATION_NONE + es konnte keine Text-Darstellung erzeugt werden + + SFX_ITEM_PRESENTATION_NAMELESS + es konnte eine Text-Darstellung (ggf. mit + Ma\seinheit) erzeugt werden, die jedoch keine + semantische Bedeutung enth"alt + + SFX_ITEM_PRESENTATION_COMPLETE + es konnte eine komplette Text-Darstellung mit + semantischer Bedeutung (und ggf. Ma\seinheit) + erzeugt werden + + + [Beispiele] + + pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... ) + "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS + + pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... ) + "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS + (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt, + kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird. + + pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... ) + "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..." +*/ + +{ + return SFX_ITEM_PRESENTATION_NONE; +} + +// SfxVoidItem ------------------------------------------------------------ +SfxVoidItem::SfxVoidItem( USHORT which ): + SfxPoolItem(which) +{ + DBG_CTOR(SfxVoidItem, 0); +} + +// SfxVoidItem ------------------------------------------------------------ +SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy): + SfxPoolItem(rCopy) +{ + DBG_CTOR(SfxVoidItem, 0); +} + +// ------------------------------------------------------------------------ +int SfxVoidItem::operator==( const SfxPoolItem& +#ifdef DBG_UTIL +rCmp +#endif +) const +{ + DBG_CHKTHIS(SfxVoidItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" ); + return TRUE; +} + +// ------------------------------------------------------------------------ +SfxItemPresentation SfxVoidItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxVoidItem, 0); + rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Void")); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ------------------------------------------------------------------------ +SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxVoidItem, 0); + return new SfxVoidItem(*this); +} + +// SfxInvalidItem --------------------------------------------------------- +#if 0 /* @@@ NOT USED @@@ */ +SfxInvalidItem::SfxInvalidItem( USHORT nWhich, const SfxPoolItem &rDefault ): + SfxPoolItem(nWhich), + pDefaultItem(&rDefault) +{ + DBG_CTOR(SfxInvalidItem, 0); +} + +// ------------------------------------------------------------------------ +SfxInvalidItem::SfxInvalidItem( const SfxInvalidItem& rCopy): + SfxPoolItem(rCopy), + pDefaultItem(rCopy.pDefaultItem) +{ + DBG_CTOR(SfxInvalidItem, 0); + //! pDefaultItem->ReleaseRef? +} + +// ------------------------------------------------------------------------ +SfxInvalidItem::~SfxInvalidItem() +{ + DBG_DTOR(SfxInvalidItem, 0); +} + +// ------------------------------------------------------------------------ +int SfxInvalidItem::operator==( const SfxPoolItem& rCmp) const +{ + DBG_CHKTHIS(SfxInvalidItem, 0); + DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal type" ); + return *pDefaultItem == *((SfxInvalidItem&)rCmp).pDefaultItem; +} + +// ------------------------------------------------------------------------ +SfxItemPresentation SfxInvalidItem::GetPresentation +( + SfxItemPresentation ePresentation, + SfxMapUnit eCoreMetric, + SfxMapUnit ePresentationMetric, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxInvalidItem, 0); + rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Invalid")); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ------------------------------------------------------------------------ +SfxPoolItem* SfxInvalidItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxInvalidItem, 0); + return new SfxInvalidItem(*this); +} + +// ------------------------------------------------------------------------ +SfxPoolItem* SfxInvalidItem::Create(SvStream &, USHORT nVersion) const +{ + DBG_CHKTHIS(SfxInvalidItem, 0); + DBG_ERROR("SfxInvalidItem::Create() ist sinnlos"); + return Clone(); +} + +// ------------------------------------------------------------------------ +SvStream& SfxInvalidItem::Store(SvStream &rStream, USHORT nItemVersion ) const +{ + DBG_CHKTHIS(SfxInvalidItem, 0); + DBG_ERROR("SfxInvalidItem::Store() ist sinnlos"); + return rStream; +} +#endif /* @@@ NOT USED @@@ */ + +// SfxItemHandle ---------------------------------------------------------- +SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem): + pRef(new USHORT(1)), + pItem(rItem.Clone(0)) +{ + DBG_CTOR(SfxItemHandle, 0); +} + +// ------------------------------------------------------------------------ +SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy): + pRef(rCopy.pRef), + pItem(rCopy.pItem) +{ + DBG_CTOR(SfxItemHandle, 0); + ++(*pRef); +} + +// ------------------------------------------------------------------------ +const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy) +{ + DBG_CHKTHIS(SfxItemHandle, 0); + if(&rCopy == this || pItem == rCopy.pItem) + return *this; + --(*pRef); + if(!(*pRef)) + { + delete pItem; + pItem = 0; + } + pRef = rCopy.pRef; + ++(*pRef); + pItem = rCopy.pItem; + return *this; +} + +// ------------------------------------------------------------------------ +SfxItemHandle::~SfxItemHandle() +{ + DBG_DTOR(SfxItemHandle, 0); + --(*pRef); + if(!(*pRef)) { + delete pRef; pRef = 0; + delete pItem; pItem = 0; + } +} + +// ------------------------------------------------------------------------ +int SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ ) +{ + return 0; +} + +// ------------------------------------------------------------------------ +int SfxPoolItem::HasMetrics() const +{ + return 0; +} + +// ----------------------------------------------------------------------- +#if 0 /* @@@ NOT USED @@@ */ +void SfxPoolItem::GetVersion() const +{ + DBG_ERROR( "dummy called" ); +} + +// ----------------------------------------------------------------------- +void SfxPoolItem::Store(SvStream &rStream) const +{ + DBG_ERROR( "dummy called" ); +} +#endif /* @@@ NOT USED @@@ */ + +// ----------------------------------------------------------------------- + +BOOL SfxPoolItem::QueryValue( com::sun::star::uno::Any&, BYTE ) const +{ + DBG_ERROR("There is no implementation for QueryValue for this item!"); + return FALSE; +} + +// ----------------------------------------------------------------------- + +BOOL SfxPoolItem::PutValue( const com::sun::star::uno::Any&, BYTE ) +{ + DBG_ERROR("There is no implementation for PutValue for this item!"); + return FALSE; +} + +SfxVoidItem::~SfxVoidItem() +{ + DBG_DTOR(SfxVoidItem, 0); +} diff --git a/svl/source/items/ptitem.cxx b/svl/source/items/ptitem.cxx new file mode 100644 index 000000000000..ac1e94fd1727 --- /dev/null +++ b/svl/source/items/ptitem.cxx @@ -0,0 +1,208 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ptitem.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/ptitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/awt/Point.hpp> +#include <tools/stream.hxx> + +#include <svtools/poolitem.hxx> +#include "memberid.hrc" + +using namespace ::com::sun::star; +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxPointItem) + +#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L)) +#define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L)) + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxPointItem::SfxPointItem() +{ + DBG_CTOR(SfxPointItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxPointItem::SfxPointItem( USHORT nW, const Point& rVal ) : + SfxPoolItem( nW ), + aVal( rVal ) +{ + DBG_CTOR(SfxPointItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxPointItem::SfxPointItem( USHORT nW, SvStream &rStream ) : + SfxPoolItem( nW ) +{ + DBG_CTOR(SfxPointItem, 0); + rStream >> aVal; +} + +// ----------------------------------------------------------------------- + +SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) : + SfxPoolItem( rItem ), + aVal( rItem.aVal ) +{ + DBG_CTOR(SfxPointItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxPointItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxPointItem, 0); + rText = UniString::CreateFromInt32(aVal.X()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += UniString::CreateFromInt32(aVal.Y()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ----------------------------------------------------------------------- + +int SfxPointItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS(SfxPointItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + return ((SfxPointItem&)rItem).aVal == aVal; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxPointItem, 0); + return new SfxPointItem( *this ); +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxPointItem::Create(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxPointItem, 0); + Point aStr; + rStream >> aStr; + return new SfxPointItem(Which(), aStr); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxPointItem::Store(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxPointItem, 0); + rStream << aVal; + return rStream; +} + +// ----------------------------------------------------------------------- + +BOOL SfxPointItem::QueryValue( uno::Any& rVal, + BYTE nMemberId ) const +{ + sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); + awt::Point aTmp(aVal.X(), aVal.Y()); + if( bConvert ) + { + aTmp.X = TWIP_TO_MM100(aTmp.X); + aTmp.Y = TWIP_TO_MM100(aTmp.Y); + } + nMemberId &= ~CONVERT_TWIPS; + switch ( nMemberId ) + { + case 0: rVal <<= aTmp; break; + case MID_X: rVal <<= aTmp.X; break; + case MID_Y: rVal <<= aTmp.Y; break; + default: DBG_ERROR("Wrong MemberId!"); return FALSE; + } + + return TRUE; +} + +// ----------------------------------------------------------------------- + +BOOL SfxPointItem::PutValue( const uno::Any& rVal, + BYTE nMemberId ) +{ + sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); + nMemberId &= ~CONVERT_TWIPS; + BOOL bRet = FALSE; + awt::Point aValue; + sal_Int32 nVal = 0; + if ( !nMemberId ) + { + bRet = ( rVal >>= aValue ); + if( bConvert ) + { + aValue.X = MM100_TO_TWIP(aValue.X); + aValue.Y = MM100_TO_TWIP(aValue.Y); + } + } + else + { + bRet = ( rVal >>= nVal ); + if( bConvert ) + nVal = MM100_TO_TWIP( nVal ); + } + + if ( bRet ) + { + switch ( nMemberId ) + { + case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break; + case MID_X: aVal.setX( nVal ); break; + case MID_Y: aVal.setY( nVal ); break; + default: DBG_ERROR("Wrong MemberId!"); return FALSE; + } + } + + return bRet; +} + + + diff --git a/svl/source/items/rectitem.cxx b/svl/source/items/rectitem.cxx new file mode 100644 index 000000000000..f9faeeeaa824 --- /dev/null +++ b/svl/source/items/rectitem.cxx @@ -0,0 +1,204 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rectitem.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/rectitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/awt/Rectangle.hpp> +#include <tools/stream.hxx> + +#include <svtools/poolitem.hxx> +#include "memberid.hrc" + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxRectangleItem) + + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxRectangleItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxRectangleItem::SfxRectangleItem() +{ + DBG_CTOR(SfxRectangleItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxRectangleItem::SfxRectangleItem( USHORT nW, const Rectangle& rVal ) : + SfxPoolItem( nW ), + aVal( rVal ) +{ + DBG_CTOR(SfxRectangleItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxRectangleItem::SfxRectangleItem( USHORT nW, SvStream &rStream ) : + SfxPoolItem( nW ) +{ + DBG_CTOR(SfxRectangleItem, 0); + rStream >> aVal; +} + +// ----------------------------------------------------------------------- + +SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem& rItem ) : + SfxPoolItem( rItem ), + aVal( rItem.aVal ) +{ + DBG_CTOR(SfxRectangleItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxRectangleItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxRectangleItem, 0); + rText = UniString::CreateFromInt32(aVal.Top()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += UniString::CreateFromInt32(aVal.Left()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += UniString::CreateFromInt32(aVal.Bottom()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += UniString::CreateFromInt32(aVal.Right()); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ----------------------------------------------------------------------- + +int SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS(SfxRectangleItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + return ((SfxRectangleItem&)rItem).aVal == aVal; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxRectangleItem, 0); + return new SfxRectangleItem( *this ); +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxRectangleItem, 0); + Rectangle aStr; + rStream >> aStr; + return new SfxRectangleItem(Which(), aStr); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxRectangleItem::Store(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxRectangleItem, 0); + rStream << aVal; + return rStream; +} + + +// ----------------------------------------------------------------------- +BOOL SfxRectangleItem::QueryValue( com::sun::star::uno::Any& rVal, + BYTE nMemberId) const +{ + nMemberId &= ~CONVERT_TWIPS; + switch ( nMemberId ) + { + case 0: + { + rVal <<= com::sun::star::awt::Rectangle( aVal.getX(), + aVal.getY(), + aVal.getWidth(), + aVal.getHeight() ); + break; + } + case MID_RECT_LEFT: rVal <<= aVal.getX(); break; + case MID_RECT_RIGHT: rVal <<= aVal.getY(); break; + case MID_WIDTH: rVal <<= aVal.getWidth(); break; + case MID_HEIGHT: rVal <<= aVal.getHeight(); break; + default: DBG_ERROR("Wrong MemberID!"); return FALSE; + } + + return TRUE; +} + +// ----------------------------------------------------------------------- +BOOL SfxRectangleItem::PutValue( const com::sun::star::uno::Any& rVal, + BYTE nMemberId ) +{ + BOOL bRet = FALSE; + nMemberId &= ~CONVERT_TWIPS; + com::sun::star::awt::Rectangle aValue; + sal_Int32 nVal = 0; + if ( !nMemberId ) + bRet = (rVal >>= aValue); + else + bRet = (rVal >>= nVal); + + if ( bRet ) + { + switch ( nMemberId ) + { + case 0: + aVal.setX( aValue.X ); + aVal.setY( aValue.Y ); + aVal.setWidth( aValue.Width ); + aVal.setHeight( aValue.Height ); + break; + case MID_RECT_LEFT: aVal.setX( nVal ); break; + case MID_RECT_RIGHT: aVal.setY( nVal ); break; + case MID_WIDTH: aVal.setWidth( nVal ); break; + case MID_HEIGHT: aVal.setHeight( nVal ); break; + default: DBG_ERROR("Wrong MemberID!"); return FALSE; + } + } + + return bRet; +} + + + diff --git a/svl/source/items/rngitem.cxx b/svl/source/items/rngitem.cxx new file mode 100644 index 000000000000..0c62de7229f4 --- /dev/null +++ b/svl/source/items/rngitem.cxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rngitem.cxx,v $ + * $Revision: 1.12 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <tools/stream.hxx> + +#ifndef NUMTYPE + +#define NUMTYPE USHORT +#define SfxXRangeItem SfxRangeItem +#define SfxXRangesItem SfxUShortRangesItem +#include <svtools/rngitem.hxx> +#include "rngitem_inc.cxx" + +#define NUMTYPE sal_uInt32 +#define SfxXRangeItem SfxULongRangeItem +#define SfxXRangesItem SfxULongRangesItem +#include <svtools/rngitem.hxx> +#include "rngitem_inc.cxx" + +#else + +// We leave this condition just in case NUMTYPE has been defined externally to this +// file and we are supposed to define the SfxXRangeItem based on that. + +#include "rngitem_inc.cxx" + +#endif + diff --git a/svl/source/items/rngitem_inc.cxx b/svl/source/items/rngitem_inc.cxx new file mode 100755 index 000000000000..d8cc7ed185ae --- /dev/null +++ b/svl/source/items/rngitem_inc.cxx @@ -0,0 +1,243 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: rngitem_inc.cxx,v $ + * $Revision: 1.3 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// This snippet of code is included by rngitem.cxx but not compiled directly. +// Ugly hack, probably due to lack of templates in the 20th century. + +static inline NUMTYPE Count_Impl(const NUMTYPE * pRanges) +{ + NUMTYPE nCount = 0; + for (; *pRanges; pRanges += 2) nCount += 2; + return nCount; +} + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxXRangeItem, SfxPoolItem); +TYPEINIT1_AUTOFACTORY(SfxXRangesItem, SfxPoolItem); + +NUMTYPE Count_Impl( const NUMTYPE *pRanges ); + +// ----------------------------------------------------------------------- + +SfxXRangeItem::SfxXRangeItem() +{ + nFrom = 0; + nTo = 0; +} + +// ----------------------------------------------------------------------- + +SfxXRangeItem::SfxXRangeItem( USHORT which, NUMTYPE from, NUMTYPE to ): + SfxPoolItem( which ), + nFrom( from ), + nTo( to ) +{ +} + + +// ----------------------------------------------------------------------- + +SfxXRangeItem::SfxXRangeItem( USHORT nW, SvStream &rStream ) : + SfxPoolItem( nW ) +{ + rStream >> nFrom; + rStream >> nTo; +} + +// ----------------------------------------------------------------------- + +SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem& rItem ) : + SfxPoolItem( rItem ) +{ + nFrom = rItem.nFrom; + nTo = rItem.nTo; +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxXRangeItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + rText = UniString::CreateFromInt64(nFrom); + rText += ':'; + rText += UniString::CreateFromInt64(nTo); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ----------------------------------------------------------------------- + +int SfxXRangeItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + SfxXRangeItem* pT = (SfxXRangeItem*)&rItem; + if( nFrom==pT->nFrom && nTo==pT->nTo ) + return 1; + return 0; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxXRangeItem::Clone(SfxItemPool *) const +{ + return new SfxXRangeItem( Which(), nFrom, nTo ); +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxXRangeItem::Create(SvStream &rStream, USHORT) const +{ + NUMTYPE nVon, nBis; + rStream >> nVon; + rStream >> nBis; + return new SfxXRangeItem( Which(), nVon, nBis ); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxXRangeItem::Store(SvStream &rStream, USHORT) const +{ + rStream << nFrom; + rStream << nTo; + return rStream; +} + +//========================================================================= + +SfxXRangesItem::SfxXRangesItem() +: _pRanges(0) +{ +} + +//------------------------------------------------------------------------- + +SfxXRangesItem::SfxXRangesItem( USHORT nWID, const NUMTYPE *pRanges ) +: SfxPoolItem( nWID ) +{ + NUMTYPE nCount = Count_Impl(pRanges) + 1; + _pRanges = new NUMTYPE[nCount]; + memcpy( _pRanges, pRanges, sizeof(NUMTYPE) * nCount ); +} + +//------------------------------------------------------------------------- + +SfxXRangesItem::SfxXRangesItem( USHORT nWID, SvStream &rStream ) +: SfxPoolItem( nWID ) +{ + NUMTYPE nCount; + rStream >> nCount; + _pRanges = new NUMTYPE[nCount + 1]; + for ( NUMTYPE n = 0; n < nCount; ++n ) + rStream >> _pRanges[n]; + _pRanges[nCount] = 0; +} + +//------------------------------------------------------------------------- + +SfxXRangesItem::SfxXRangesItem( const SfxXRangesItem& rItem ) +: SfxPoolItem( rItem ) +{ + NUMTYPE nCount = Count_Impl(rItem._pRanges) + 1; + _pRanges = new NUMTYPE[nCount]; + memcpy( _pRanges, rItem._pRanges, sizeof(NUMTYPE) * nCount ); +} + +//------------------------------------------------------------------------- + +SfxXRangesItem::~SfxXRangesItem() +{ + delete _pRanges; +} + +//------------------------------------------------------------------------- + +int SfxXRangesItem::operator==( const SfxPoolItem &rItem ) const +{ + const SfxXRangesItem &rOther = (const SfxXRangesItem&) rItem; + if ( !_pRanges && !rOther._pRanges ) + return TRUE; + if ( _pRanges || rOther._pRanges ) + return FALSE; + + NUMTYPE n; + for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n ) + if ( *_pRanges != rOther._pRanges[n] ) + return 0; + + return !_pRanges[n] && !rOther._pRanges[n]; +} + +//------------------------------------------------------------------------- + +SfxItemPresentation SfxXRangesItem::GetPresentation( SfxItemPresentation /*ePres*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresMetric*/, + XubString &/*rText*/, + const IntlWrapper * ) const +{ + HACK(n. i.) + return SFX_ITEM_PRESENTATION_NONE; +} + +//------------------------------------------------------------------------- + +SfxPoolItem* SfxXRangesItem::Clone( SfxItemPool * ) const +{ + return new SfxXRangesItem( *this ); +} + +//------------------------------------------------------------------------- + +SfxPoolItem* SfxXRangesItem::Create( SvStream &rStream, USHORT ) const +{ + return new SfxXRangesItem( Which(), rStream ); +} + +//------------------------------------------------------------------------- + +SvStream& SfxXRangesItem::Store( SvStream &rStream, USHORT ) const +{ + NUMTYPE nCount = Count_Impl( _pRanges ); + rStream >> nCount; + for ( NUMTYPE n = 0; _pRanges[n]; ++n ) + rStream >> _pRanges[n]; + return rStream; +} + + +#undef NUMTYPE +#undef SfxXRangeItem +#undef SfxXRangesItem diff --git a/svl/source/items/sfontitm.cxx b/svl/source/items/sfontitm.cxx new file mode 100644 index 000000000000..ee7119c95e1c --- /dev/null +++ b/svl/source/items/sfontitm.cxx @@ -0,0 +1,142 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: sfontitm.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <tools/stream.hxx> +#include <tools/vcompat.hxx> +#include <svtools/sfontitm.hxx> + +//============================================================================ +// +// class SfxFontItem +// +//============================================================================ + +TYPEINIT1(SfxFontItem, SfxPoolItem); + +//============================================================================ +// virtual +int SfxFontItem::operator ==(const SfxPoolItem & rItem) const +{ + const SfxFontItem * pFontItem = PTR_CAST(SfxFontItem, &rItem); + return pFontItem && m_bHasFont == pFontItem->m_bHasFont + && m_bHasColor == pFontItem->m_bHasColor + && m_bHasFillColor == pFontItem->m_bHasFillColor + && (!m_bHasColor || m_aColor == pFontItem->m_aColor) + && (!m_bHasFillColor || m_aFillColor == pFontItem->m_aFillColor) + && (!m_bHasFont || (m_bKerning == pFontItem->m_bKerning + && m_bShadow == pFontItem->m_bShadow + && m_bOutline == pFontItem->m_bOutline + && m_bWordLine == pFontItem->m_bWordLine + && m_nOrientation == pFontItem->m_nOrientation + && m_nStrikeout == pFontItem->m_nStrikeout + && m_nUnderline == pFontItem->m_nUnderline + && m_nItalic == pFontItem->m_nItalic + && m_nWidthType == pFontItem->m_nWidthType + && m_nWeight == pFontItem->m_nWeight + && m_nPitch == pFontItem->m_nPitch + && m_nFamily == pFontItem->m_nFamily + && m_nLanguage == pFontItem->m_nLanguage + && m_nCharSet == pFontItem->m_nCharSet + && m_aFillColor == pFontItem->m_aFillColor + && m_aColor == pFontItem->m_aColor + && m_aSize == pFontItem->m_aSize + && m_aStyleName == pFontItem->m_aStyleName + && m_aName == pFontItem->m_aName)); +} + +//============================================================================ +// virtual +SfxPoolItem * SfxFontItem::Create(SvStream & rStream, USHORT) const +{ + VersionCompat aItemCompat(rStream, STREAM_READ); + SfxFontItem * pItem = new SfxFontItem(Which()); + { + VersionCompat aFontCompat(rStream, STREAM_READ); + readByteString(rStream, pItem->m_aName); + readByteString(rStream, pItem->m_aStyleName); + rStream >> pItem->m_aSize; + sal_Int16 nCharSet = 0; + rStream >> nCharSet; + pItem->m_nCharSet = rtl_TextEncoding(nCharSet); + rStream >> pItem->m_nFamily >> pItem->m_nPitch >> pItem->m_nWeight + >> pItem->m_nUnderline >> pItem->m_nStrikeout + >> pItem->m_nItalic; + sal_Int16 nLanguage = 0; + rStream >> nLanguage; + pItem->m_nLanguage = LanguageType(nLanguage); + rStream >> pItem->m_nWidthType >> pItem->m_nOrientation; + sal_Int8 nWordLine = 0; + rStream >> nWordLine; + pItem->m_bWordLine = nWordLine != 0; + sal_Int8 nOutline = 0; + rStream >> nOutline; + pItem->m_bOutline = nOutline != 0; + sal_Int8 nShadow = 0; + rStream >> nShadow; + pItem->m_bShadow = nShadow != 0; + sal_Int8 nKerning = 0; + rStream >> nKerning; + pItem->m_bKerning = nKerning != 0; + } + pItem->m_aColor.Read(rStream, TRUE); + pItem->m_aFillColor.Read(rStream, TRUE); + sal_Int16 nFlags = 0; + rStream >> nFlags; + pItem->m_bHasFont = (nFlags & 4) != 0; + pItem->m_bHasColor = (nFlags & 1) != 0; + pItem->m_bHasFillColor = (nFlags & 2) != 0; + return pItem; +} + +//============================================================================ +// virtual +SvStream & SfxFontItem::Store(SvStream & rStream, USHORT) const +{ + VersionCompat aItemCompat(rStream, STREAM_WRITE, 1); + { + VersionCompat aFontCompat(rStream, STREAM_WRITE, 1); + writeByteString(rStream, m_aName); + writeByteString(rStream, m_aStyleName); + rStream << m_aSize << sal_Int16(m_nCharSet) + << m_nFamily << m_nPitch << m_nWeight << m_nUnderline + << m_nStrikeout << m_nItalic << sal_Int16(m_nLanguage) + << m_nWidthType << m_nOrientation << sal_Int8(m_bWordLine) + << sal_Int8(m_bOutline) << sal_Int8(m_bShadow) + << sal_Int8(m_bKerning); + } + SAL_CONST_CAST(Color &, m_aColor).Write(rStream, TRUE); + SAL_CONST_CAST(Color &, m_aFillColor).Write(rStream, TRUE); + rStream << sal_Int16(m_bHasFont << 2 | m_bHasColor + | m_bHasFillColor << 1); + return rStream; +} + diff --git a/svl/source/items/sitem.cxx b/svl/source/items/sitem.cxx new file mode 100644 index 000000000000..2a917e93bb79 --- /dev/null +++ b/svl/source/items/sitem.cxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: sitem.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +// INCLUDE --------------------------------------------------------------- + +#ifndef GCC +#endif + +#include <tools/string.hxx> +#include <tools/stream.hxx> + +#include <svtools/poolitem.hxx> +#include <svtools/itemset.hxx> + + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxSetItem) + +// -------------------------------------------------------------------------- + +SfxSetItem::SfxSetItem( USHORT which, const SfxItemSet &rSet) : + SfxPoolItem(which), + pSet(rSet.Clone(TRUE)) +{ + DBG_CTOR(SfxSetItem, 0); +} + +// -------------------------------------------------------------------------- + +SfxSetItem::SfxSetItem( USHORT which, SfxItemSet *pS) : + SfxPoolItem(which), + pSet(pS) +{ + DBG_CTOR(SfxSetItem, 0); + DBG_ASSERT(pS, "SfxSetItem without set constructed" ); +} + +// -------------------------------------------------------------------------- + +SfxSetItem::SfxSetItem( const SfxSetItem& rCopy, SfxItemPool *pPool ) : + SfxPoolItem(rCopy.Which()), + pSet(rCopy.pSet->Clone(TRUE, pPool)) +{ + DBG_CTOR(SfxSetItem, 0); +} + +// -------------------------------------------------------------------------- + +SfxSetItem::~SfxSetItem() +{ + DBG_DTOR(SfxSetItem, 0); + delete pSet; pSet = 0; +} + +// -------------------------------------------------------------------------- + +int SfxSetItem::operator==( const SfxPoolItem& rCmp) const +{ + DBG_CHKTHIS(SfxSetItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" ); + return *pSet == *(((const SfxSetItem &)rCmp).pSet); +} + +// -------------------------------------------------------------------------- + +SfxItemPresentation SfxSetItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& /*rText*/, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxSetItem, 0); + return SFX_ITEM_PRESENTATION_NONE; +} + +// -------------------------------------------------------------------------- + +SvStream& SfxSetItem::Store(SvStream& rStream, USHORT) const +{ + GetItemSet().Store(rStream); + return rStream; +} + diff --git a/svl/source/items/slstitm.cxx b/svl/source/items/slstitm.cxx new file mode 100644 index 000000000000..87163d41e033 --- /dev/null +++ b/svl/source/items/slstitm.cxx @@ -0,0 +1,425 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: slstitm.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/slstitm.hxx> +#include <svtools/poolitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <tools/stream.hxx> + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxStringListItem) + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxStringListItem, SfxPoolItem); + +class SfxImpStringList +{ +public: + USHORT nRefCount; + List aList; + + SfxImpStringList() { nRefCount = 1; } + ~SfxImpStringList(); + void Sort( BOOL bAscending, List* ); +}; + +//------------------------------------------------------------------------ + +SfxImpStringList::~SfxImpStringList() +{ + DBG_ASSERT(nRefCount!=0xffff,"ImpList already deleted"); + String* pStr = (String*)aList.First(); + while( pStr ) + { + delete pStr; + pStr = (String*)aList.Next(); + } + nRefCount = 0xffff; +} + +//------------------------------------------------------------------------ + +void SfxImpStringList::Sort( BOOL bAscending, List* pParallelList ) +{ + DBG_ASSERT(!pParallelList || pParallelList->Count() >= aList.Count(),"Sort:ParallelList too small"); + ULONG nCount = aList.Count(); + if( nCount > 1 ) + { + nCount -= 2; + // Bubble Dir Einen + BOOL bSwapped = TRUE; + while( bSwapped ) + { + bSwapped = FALSE; + for( ULONG nCur = 0; nCur <= nCount; nCur++ ) + { + String* pStr1 = (String*)aList.GetObject( nCur ); + String* pStr2 = (String*)aList.GetObject( nCur+1 ); + // COMPARE_GREATER => pStr2 ist groesser als pStr1 + StringCompare eCompare = pStr1->CompareIgnoreCaseToAscii( *pStr2 ); //@@@ + BOOL bSwap = FALSE; + if( bAscending ) + { + if( eCompare == COMPARE_LESS ) + bSwap = TRUE; + } + else if( eCompare == COMPARE_GREATER ) + bSwap = TRUE; + + if( bSwap ) + { + bSwapped = TRUE; + aList.Replace( pStr1, nCur + 1 ); + aList.Replace( pStr2, nCur ); + if( pParallelList ) + { + void* p1 = pParallelList->GetObject( nCur ); + void* p2 = pParallelList->GetObject( nCur + 1 ); + pParallelList->Replace( p1, nCur + 1 ); + pParallelList->Replace( p2, nCur ); + } + } + } + } + } +} + +// class SfxStringListItem ----------------------------------------------- + +SfxStringListItem::SfxStringListItem() : + pImp(NULL) +{ +} + +//------------------------------------------------------------------------ + +SfxStringListItem::SfxStringListItem( USHORT which, const List* pList ) : + SfxPoolItem( which ), + pImp(NULL) +{ + // PB: das Putten einer leeren Liste funktionierte nicht, + // deshalb habe ich hier die Abfrage nach dem Count auskommentiert + if( pList /*!!! && pList->Count() */ ) + { + pImp = new SfxImpStringList; + + long i, nCount = pList->Count(); + String *pStr1, *pStr2; + for( i=0; i < nCount; i++ ) + { + pStr1 = (String*)pList->GetObject(i); + pStr2 = new String( *pStr1 ); + pImp->aList.Insert( pStr2, LIST_APPEND ); + } + } +} + +//------------------------------------------------------------------------ + +SfxStringListItem::SfxStringListItem( USHORT which, SvStream& rStream ) : + SfxPoolItem( which ), + pImp(NULL) +{ + long nEntryCount; + rStream >> nEntryCount; + + if( nEntryCount ) + pImp = new SfxImpStringList; + + long i; + String* pStr; + for( i=0; i < nEntryCount; i++ ) + { + pStr = new String; + readByteString(rStream, *pStr); + pImp->aList.Insert( pStr, LIST_APPEND ); + } +} + +//------------------------------------------------------------------------ + +SfxStringListItem::SfxStringListItem( const SfxStringListItem& rItem ) : + SfxPoolItem( rItem ), + pImp(NULL) +{ + pImp = rItem.pImp; + + if( pImp ) + { + DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); + pImp->nRefCount++; + } +} + +//------------------------------------------------------------------------ + +SfxStringListItem::~SfxStringListItem() +{ + if( pImp ) + { + DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); + if( pImp->nRefCount > 1 ) + pImp->nRefCount--; + else + delete pImp; + } +} + +//------------------------------------------------------------------------ + +List* SfxStringListItem::GetList() +{ + if( !pImp ) + pImp = new SfxImpStringList; + DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); + return &(pImp->aList); +} + +//------------------------------------------------------------------------ + +int SfxStringListItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + SfxStringListItem* pItem = (SfxStringListItem*)&rItem; + + if( pImp == pItem->pImp ) + return TRUE; + else + return FALSE; +} + +//------------------------------------------------------------------------ + +SfxItemPresentation SfxStringListItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("(List)")); + return SFX_ITEM_PRESENTATION_NONE; +} + +//------------------------------------------------------------------------ + +SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const +{ + return new SfxStringListItem( *this ); + /* + if( pImp ) + return new SfxStringListItem( Which(), &(pImp->aList) ); + else + return new SfxStringListItem( Which(), NULL ); + */ + +} + +//------------------------------------------------------------------------ + +SfxPoolItem* SfxStringListItem::Create( SvStream & rStream, USHORT ) const +{ + return new SfxStringListItem( Which(), rStream ); +} + +//------------------------------------------------------------------------ + +SvStream& SfxStringListItem::Store( SvStream & rStream, USHORT ) const +{ + if( !pImp ) + { + rStream << 0L; + return rStream; + } + + DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); + + long nCount = pImp->aList.Count(); + rStream << nCount; + + long i; + String* pStr; + for( i=0; i < nCount; i++ ) + { + pStr = (String*)(pImp->aList.GetObject( i )); + writeByteString(rStream, *pStr); + } + + return rStream; +} + +//------------------------------------------------------------------------ + +void SfxStringListItem::SetString( const XubString& rStr ) +{ + DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0"); + + if ( pImp && (pImp->nRefCount == 1) ) + delete pImp; + else + if( pImp ) + pImp->nRefCount--; + pImp = new SfxImpStringList; + + xub_StrLen nStart = 0; + xub_StrLen nDelimPos; + XubString aStr(rStr); + aStr.ConvertLineEnd(LINEEND_CR); + do + { + nDelimPos = aStr.Search( _CR, nStart ); + xub_StrLen nLen; + if ( nDelimPos == STRING_NOTFOUND ) + nLen = 0xffff; + else + nLen = nDelimPos - nStart; + + XubString* pStr = new XubString(aStr.Copy(nStart, nLen)); + // String gehoert der Liste + pImp->aList.Insert( pStr, LIST_APPEND ); + + nStart += nLen + 1 ; // delimiter ueberspringen + } while( nDelimPos != STRING_NOTFOUND ); + + // Kein Leerstring am Ende + if( pImp->aList.Last() && + !((XubString*)pImp->aList.Last())->Len() ) + delete (XubString*)pImp->aList.Remove( pImp->aList.Count()-1 ); +} + +//------------------------------------------------------------------------ + +XubString SfxStringListItem::GetString() +{ + XubString aStr; + if ( pImp ) + { + DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); + XubString* pStr = (XubString*)(pImp->aList.First()); + while( pStr ) + { + aStr += *pStr; + pStr = (XubString*)(pImp->aList.Next()); + if ( pStr ) + aStr += '\r'; + } + } + aStr.ConvertLineEnd(); + return aStr; +} + +//------------------------------------------------------------------------ + +#ifndef TF_POOLABLE + +int SfxStringListItem::IsPoolable() const +{ + return FALSE; +} + +#endif + +//------------------------------------------------------------------------ + +void SfxStringListItem::Sort( BOOL bAscending, List* pParallelList ) +{ + DBG_ASSERT(GetRefCount()==0,"Sort:RefCount!=0"); + if( pImp ) + pImp->Sort( bAscending, pParallelList ); +} + +//---------------------------------------------------------------------------- +void SfxStringListItem::SetStringList( const com::sun::star::uno::Sequence< rtl::OUString >& rList ) +{ + DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0"); + + if ( pImp && (pImp->nRefCount == 1) ) + delete pImp; + else + if( pImp ) + pImp->nRefCount--; + pImp = new SfxImpStringList; + + for ( sal_Int32 n = 0; n < rList.getLength(); n++ ) + { + XubString* pStr = new XubString( rList[n] ); + // String gehoert der Liste + pImp->aList.Insert( pStr, LIST_APPEND ); + } +} + +//---------------------------------------------------------------------------- +void SfxStringListItem::GetStringList( com::sun::star::uno::Sequence< rtl::OUString >& rList ) const +{ + long nCount = pImp->aList.Count(); + + rList.realloc( nCount ); + for( long i=0; i < nCount; i++ ) + rList[i] = *(String*)(pImp->aList.GetObject( i )); +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxStringListItem::PutValue( const com::sun::star::uno::Any& rVal,BYTE ) +{ + com::sun::star::uno::Sequence< rtl::OUString > aValue; + if ( rVal >>= aValue ) + { + SetStringList( aValue ); + return TRUE; + } + + DBG_ERROR( "SfxStringListItem::PutValue - Wrong type!" ); + return FALSE; +} + +//---------------------------------------------------------------------------- +// virtual +BOOL SfxStringListItem::QueryValue( com::sun::star::uno::Any& rVal,BYTE ) const +{ + // GetString() is not const!!! + SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this ); + + com::sun::star::uno::Sequence< rtl::OUString > aStringList; + pThis->GetStringList( aStringList ); + rVal = ::com::sun::star::uno::makeAny( aStringList ); + return TRUE; +} + + diff --git a/svl/source/items/stritem.cxx b/svl/source/items/stritem.cxx new file mode 100644 index 000000000000..37968dc3ee1d --- /dev/null +++ b/svl/source/items/stritem.cxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: stritem.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <svtools/stritem.hxx> + +//============================================================================ +// +// class SfxStringItem +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(SfxStringItem, CntUnencodedStringItem) + +//============================================================================ +// virtual +SfxStringItem::SfxStringItem(USHORT which, SvStream & rStream): + CntUnencodedStringItem(which) +{ + UniString aValue; + readByteString(rStream, aValue); + SetValue(aValue); +} + + +//============================================================================ +// virtual +SfxPoolItem * SfxStringItem::Create(SvStream & rStream, USHORT) const +{ + return new SfxStringItem(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & SfxStringItem::Store(SvStream & rStream, USHORT) const +{ + writeByteString(rStream, GetValue()); + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * SfxStringItem::Clone(SfxItemPool *) const +{ + return new SfxStringItem(*this); +} + diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx new file mode 100644 index 000000000000..ad11f1527ce7 --- /dev/null +++ b/svl/source/items/style.cxx @@ -0,0 +1,1381 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: style.cxx,v $ + * $Revision: 1.19.60.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#ifndef GCC +#endif + +#define _SVSTDARR_STRINGS +#define _SVSTDARR_STRINGSSORTDTOR +#define _SVSTDARR_BYTESTRINGS +#define _SVSTDARR_BYTESTRINGSSORTDTOR + +#include <rtl/uuid.h> +#include <tools/tenccvt.hxx> +#include <comphelper/processfactory.hxx> +#include <unotools/intlwrapper.hxx> +#include <svtools/smplhint.hxx> +#include <svtools/poolitem.hxx> +#include <svtools/itemset.hxx> +#include <svtools/itempool.hxx> +#include <poolio.hxx> +#include <svtools/filerec.hxx> +#include <svtools/itemiter.hxx> +#include <svtools/style.hxx> +#include <svtools/svstdarr.hxx> +#include <vcl/svapp.hxx> + +#include <algorithm> + +#define STYLESTREAM "SfxStyleSheets" +#define STYLESTREAM_VERSION USHORT(50) + +#ifdef DBG_UTIL +class DbgStyleSheetReferences +{ +public: + DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {} + ~DbgStyleSheetReferences() + { + OSL_TRACE("DbgStyleSheetReferences\nSfxStyleSheetBase left %ld\nSfxStyleSheetBasePool left %ld\n", mnStyles, mnPools ); + } + + sal_uInt32 mnStyles; + sal_uInt32 mnPools; +} +aDbgStyleSheetReferences; + +#endif + +TYPEINIT0(SfxStyleSheetBase) + +TYPEINIT3(SfxStyleSheet, SfxStyleSheetBase, SfxListener, SfxBroadcaster) + + +//========================================================================= + +TYPEINIT1(SfxStyleSheetHint, SfxHint); +TYPEINIT1(SfxStyleSheetHintExtended, SfxStyleSheetHint); +TYPEINIT1(SfxStyleSheetPoolHint, SfxHint); + +SfxStyleSheetHintExtended::SfxStyleSheetHintExtended +( + USHORT nAction, // SFX_STYLESHEET_... (s.o.) + const String& rOldName +) +: SfxStyleSheetHint( nAction ), + aName( rOldName ) +{} +SfxStyleSheetHintExtended::SfxStyleSheetHintExtended +( + USHORT nAction, // SFX_STYLESHEET_... (s.o.) + const String& rOldName, + SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer +) +: SfxStyleSheetHint( nAction, rStyleSheet ), + aName( rOldName ) +{} + +//------------------------------------------------------------------------- + +SfxStyleSheetHint::SfxStyleSheetHint +( + USHORT nAction, // SFX_STYLESHEET_... (s.o.) + SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer +) +: pStyleSh( &rStyleSheet ), + nHint( nAction ) +{} + +SfxStyleSheetHint::SfxStyleSheetHint +( + USHORT nAction // SFX_STYLESHEET_... (s.o.) +) +: pStyleSh( NULL ), + nHint( nAction ) +{} + +//========================================================================= + +class SfxStyleSheetBasePool_Impl +{ + public: + SfxStyles aStyles; + SfxStyleSheetIterator *pIter; + SfxStyleSheetBasePool_Impl() : pIter(0){} + ~SfxStyleSheetBasePool_Impl(){delete pIter;} +}; + + +//////////////////////////// SfxStyleSheetBase /////////////////////////////// + +// Konstruktoren + +SfxStyleSheetBase::SfxStyleSheetBase( const XubString& rName, SfxStyleSheetBasePool& r, SfxStyleFamily eFam, USHORT mask ) + : rPool( r ) + , nFamily( eFam ) + , aName( rName ) + , aParent() + , aFollow( rName ) + , pSet( NULL ) + , nMask(mask) + , nHelpId( 0 ) + , bMySet( FALSE ) +{ +#ifdef DBG_UTIL + aDbgStyleSheetReferences.mnStyles++; +#endif +} + +SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase& r ) + : comphelper::OWeakTypeObject() + , rPool( r.rPool ) + , nFamily( r.nFamily ) + , aName( r.aName ) + , aParent( r.aParent ) + , aFollow( r.aFollow ) + , aHelpFile( r.aHelpFile ) + , nMask( r.nMask ) + , nHelpId( r.nHelpId ) + , bMySet( r.bMySet ) +{ +#ifdef DBG_UTIL + aDbgStyleSheetReferences.mnStyles++; +#endif + if( r.pSet ) + pSet = bMySet ? new SfxItemSet( *r.pSet ) : r.pSet; + else + pSet = NULL; +} + +static SfxStyleSheetBasePool& implGetStaticPool() +{ + static SfxStyleSheetBasePool* pSheetPool = 0; + static SfxItemPool* pBasePool = 0; + if( !pSheetPool ) + { + UniString aName; + pBasePool = new SfxItemPool( aName, 0, 0, 0 ); + pSheetPool = new SfxStyleSheetBasePool(*pBasePool); + } + return *pSheetPool; +} + +SfxStyleSheetBase::SfxStyleSheetBase() +: comphelper::OWeakTypeObject() +, rPool( implGetStaticPool() ) +{ +} + +SfxStyleSheetBase::~SfxStyleSheetBase() +{ +#ifdef DBG_UTIL + --aDbgStyleSheetReferences.mnStyles; +#endif + + if( bMySet ) + { + delete pSet; + pSet = 0; + } +} + +USHORT SfxStyleSheetBase::GetVersion() const +{ + return 0x0000; +} + +// Namen aendern + +const XubString& SfxStyleSheetBase::GetName() const +{ + return aName; +} + +BOOL SfxStyleSheetBase::SetName( const XubString& rName ) +{ + if(rName.Len() == 0) + return FALSE; + if( aName != rName ) + { + String aOldName = aName; + SfxStyleSheetBase *pOther = rPool.Find( rName, nFamily ) ; + if ( pOther && pOther != this ) + return FALSE; + + SfxStyleFamily eTmpFam=rPool.GetSearchFamily(); + USHORT nTmpMask=rPool.GetSearchMask(); + + rPool.SetSearchMask(nFamily); + + if ( aName.Len() ) + rPool.ChangeParent( aName, rName, FALSE ); + if ( aFollow.Equals( aName ) ) + aFollow = rName; + aName = rName; + rPool.SetSearchMask(eTmpFam, nTmpMask); + rPool.Broadcast( SfxStyleSheetHintExtended( + SFX_STYLESHEET_MODIFIED, aOldName, *this ) ); + } + return TRUE; +} + +rtl::OUString SfxStyleSheetBase::GetDisplayName() const +{ + if( maDisplayName.getLength() == 0 ) + { + return aName; + } + else + { + return maDisplayName; + } +} + +void SfxStyleSheetBase::SetDisplayName( const rtl::OUString& rDisplayName ) +{ + maDisplayName = rDisplayName; +} + +// Parent aendern + +const XubString& SfxStyleSheetBase::GetParent() const +{ + return aParent; +} + +BOOL SfxStyleSheetBase::SetParent( const XubString& rName ) +{ + if ( rName == aName ) + return FALSE; + + if( aParent != rName ) + { + SfxStyleSheetBase* pIter = rPool.Find(rName, nFamily); + if( rName.Len() && !pIter ) + { + DBG_ERROR( "StyleSheet-Parent nicht gefunden" ); + return FALSE; + } + // rekursive Verknuepfungen verhindern + if( aName.Len() ) + while(pIter) + { + if(pIter->GetName() == aName && aName != rName) + return FALSE; + pIter = rPool.Find(pIter->GetParent(), nFamily); + } + aParent = rName; + } + rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); + return TRUE; +} + +// Follow aendern + +const XubString& SfxStyleSheetBase::GetFollow() const +{ + return aFollow; +} + +BOOL SfxStyleSheetBase::SetFollow( const XubString& rName ) +{ + if( aFollow != rName ) + { + if( !rPool.Find( rName, nFamily ) ) + { + DBG_ERROR( "StyleSheet-Follow nicht gefunden" ); + return FALSE; + } + aFollow = rName; + } + rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); + return TRUE; +} + +// Itemset setzen. Die Dflt-Implementation legt ein neues Set an. + +SfxItemSet& SfxStyleSheetBase::GetItemSet() +{ + if( !pSet ) + { + pSet = new SfxItemSet( rPool.GetPool() ); + bMySet = TRUE; + } + return *pSet; +} + +// Hilfe-Datei und -ID setzen und abfragen + +ULONG SfxStyleSheetBase::GetHelpId( String& rFile ) +{ + rFile = aHelpFile; + return nHelpId; +} + +void SfxStyleSheetBase::SetHelpId( const String& rFile, ULONG nId ) +{ + aHelpFile = rFile; + nHelpId = nId; +} + +// Folgevorlage m"oglich? Default: Ja + +BOOL SfxStyleSheetBase::HasFollowSupport() const +{ + return TRUE; +} + +// Basisvorlage m"oglich? Default: Ja + +BOOL SfxStyleSheetBase::HasParentSupport() const +{ + return TRUE; +} + +// Basisvorlage uf NULL setzen m"oglich? Default: Nein + +BOOL SfxStyleSheetBase::HasClearParentSupport() const +{ + return FALSE; +} + +// Defaultmaessig sind alle StyleSheets Used + +BOOL SfxStyleSheetBase::IsUsed() const +{ + return TRUE; +} + +// eingestellte Attribute ausgeben + + +XubString SfxStyleSheetBase::GetDescription() +{ + return GetDescription( SFX_MAPUNIT_CM ); +} + +// eingestellte Attribute ausgeben + +XubString SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric ) +{ + SfxItemIter aIter( GetItemSet() ); + XubString aDesc; + const SfxPoolItem* pItem = aIter.FirstItem(); + + IntlWrapper aIntlWrapper(comphelper::getProcessServiceFactory(), + Application::GetSettings().GetLanguage()); + while ( pItem ) + { + XubString aItemPresentation; + + if ( !IsInvalidItem( pItem ) && + rPool.GetPool().GetPresentation( + *pItem, SFX_ITEM_PRESENTATION_COMPLETE, + eMetric, aItemPresentation, &aIntlWrapper ) ) + { + if ( aDesc.Len() && aItemPresentation.Len() ) + aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" + ")); + if ( aItemPresentation.Len() ) + aDesc += aItemPresentation; + } + pItem = aIter.NextItem(); + } + return aDesc; +} + +/////////////////////////// SfxStyleSheetIterator /////////////////////////////// + +SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const +{ + return nSearchFamily; +} + +inline BOOL SfxStyleSheetIterator::IsTrivialSearch() +{ + return nMask == 0xFFFF && GetSearchFamily() == SFX_STYLE_FAMILY_ALL; +} + +BOOL SfxStyleSheetIterator::DoesStyleMatch(SfxStyleSheetBase *pStyle) +{ + return ((GetSearchFamily() == SFX_STYLE_FAMILY_ALL) || + ( pStyle->GetFamily() == GetSearchFamily() )) + && (( pStyle->GetMask() & ( GetSearchMask() & ~SFXSTYLEBIT_USED )) || + ( bSearchUsed ? pStyle->IsUsed() : FALSE ) || + GetSearchMask() == SFXSTYLEBIT_ALL ); +} + + +SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase, + SfxStyleFamily eFam, USHORT n) +{ + pBasePool=pBase; + nSearchFamily=eFam; + bSearchUsed=FALSE; + if((n != SFXSTYLEBIT_ALL ) && ((n & SFXSTYLEBIT_USED) == SFXSTYLEBIT_USED)) + { + bSearchUsed = TRUE; + n &= ~SFXSTYLEBIT_USED; + } + nMask=n; +} + +SfxStyleSheetIterator::~SfxStyleSheetIterator() +{ +} + + +USHORT SfxStyleSheetIterator::Count() +{ + USHORT n = 0; + if( IsTrivialSearch()) + n = (USHORT) pBasePool->aStyles.size(); + else + for(USHORT i=0; i<pBasePool->aStyles.size(); i++) + { + SfxStyleSheetBase* pStyle = pBasePool->aStyles[i].get(); + if(DoesStyleMatch(pStyle)) + n++; + } + return n; +} + +SfxStyleSheetBase* SfxStyleSheetIterator::operator[](USHORT nIdx) +{ + if( IsTrivialSearch()) + return pBasePool->aStyles[nIdx].get(); + + USHORT z = 0; + for(USHORT n=0; n<pBasePool->aStyles.size(); n++) + { + SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); + if( DoesStyleMatch(pStyle)) + { + if(z == nIdx) + { + nAktPosition=n; + return pAktStyle=pStyle; + } + ++z; + } + } + DBG_ERROR("falscher Index"); + return 0; +} + +SfxStyleSheetBase* SfxStyleSheetIterator::First() +{ + INT32 nIdx = -1; + + if ( IsTrivialSearch() && pBasePool->aStyles.size() ) + nIdx = 0; + else + for( USHORT n = 0; n < pBasePool->aStyles.size(); n++ ) + { + SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); + + if ( DoesStyleMatch( pStyle ) ) + { + nIdx = n; + break; + } + } + + if ( nIdx != -1 ) + { + nAktPosition = (USHORT)nIdx; + return pAktStyle = pBasePool->aStyles[nIdx].get(); + } + return 0; +} + + +SfxStyleSheetBase* SfxStyleSheetIterator::Next() +{ + INT32 nIdx = -1; + + if ( IsTrivialSearch() && + (USHORT)pBasePool->aStyles.size() > nAktPosition + 1 ) + nIdx = nAktPosition + 1; + else + for( USHORT n = nAktPosition + 1; n < pBasePool->aStyles.size(); n++ ) + { + SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); + + if ( DoesStyleMatch( pStyle ) ) + { + nIdx = n; + break; + } + } + + if ( nIdx != -1 ) + { + nAktPosition = (USHORT)nIdx; + return pAktStyle = pBasePool->aStyles[nIdx].get(); + } + return 0; +} + + +SfxStyleSheetBase* SfxStyleSheetIterator::Find(const XubString& rStr) +{ + for ( USHORT n = 0; n < pBasePool->aStyles.size(); n++ ) + { + SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); + + // #98454# performance: in case of bSearchUsed==TRUE it may be + // significant to first compare the name and only if it matches to call + // the style sheet IsUsed() method in DoesStyleMatch(). + if ( pStyle->GetName().Equals( rStr ) && DoesStyleMatch( pStyle ) ) + { + nAktPosition = n; + return pAktStyle = pStyle; + } + } + return 0; +} + + +USHORT SfxStyleSheetIterator::GetSearchMask() const +{ + USHORT mask = nMask; + + if ( bSearchUsed ) + mask |= SFXSTYLEBIT_USED; + return mask; +} + +/////////////////////////// SfxStyleSheetBasePool /////////////////////////////// + +void SfxStyleSheetBasePool::Replace( + SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget ) +{ + rTarget.SetFollow( rSource.GetFollow() ); + rTarget.SetParent( rSource.GetParent() ); + SfxItemSet& rSourceSet = rSource.GetItemSet(); + SfxItemSet& rTargetSet = rTarget.GetItemSet(); + rTargetSet.Intersect( rSourceSet ); + rTargetSet.Put( rSourceSet ); +} + +SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl() +{ + SfxStyleSheetIterator*& rpIter = pImp->pIter; + if( !rpIter || (rpIter->GetSearchMask() != nMask) || (rpIter->GetSearchFamily() != nSearchFamily) ) + { + delete rpIter; + rpIter = CreateIterator( nSearchFamily, nMask ); + } + return *rpIter; +} + + +SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r ) + : aAppName(r.GetName()) + , rPool(r) + , nSearchFamily(SFX_STYLE_FAMILY_PARA) + , nMask(0xFFFF) +{ +#ifdef DBG_UTIL + aDbgStyleSheetReferences.mnPools++; +#endif + + pImp = new SfxStyleSheetBasePool_Impl; +} + +SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool& r ) + : SfxBroadcaster( r ) + , comphelper::OWeakTypeObject() + , aAppName(r.aAppName) + , rPool(r.rPool) + , nSearchFamily(r.nSearchFamily) + , nMask( r.nMask ) +{ +#ifdef DBG_UTIL + aDbgStyleSheetReferences.mnPools++; +#endif + + pImp = new SfxStyleSheetBasePool_Impl; + *this += r; +} + +SfxStyleSheetBasePool::~SfxStyleSheetBasePool() +{ +#ifdef DBG_UTIL + aDbgStyleSheetReferences.mnPools--; +#endif + + Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); + Clear(); + delete pImp; +} + +BOOL SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam, const XubString& rStyle, const XubString& rParent) +{ + SfxStyleSheetIterator aIter(this,eFam,SFXSTYLEBIT_ALL); + SfxStyleSheetBase *pStyle = + aIter.Find(rStyle); + DBG_ASSERT(pStyle, "Vorlage nicht gefunden. Writer mit Solar <2541??"); + if(pStyle) + return pStyle->SetParent(rParent); + else + return FALSE; +} + + +void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam, USHORT n) +{ + nSearchFamily = eFam; nMask = n; +} + +USHORT SfxStyleSheetBasePool::GetSearchMask() const +{ + return nMask; +} + + +// Der Name des Streams + +String SfxStyleSheetBasePool::GetStreamName() +{ + return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STYLESTREAM)); +} + +/////////////////////////////////// Factory //////////////////////////////// + + + +SfxStyleSheetIterator* SfxStyleSheetBasePool::CreateIterator +( + SfxStyleFamily eFam, + USHORT mask +) +{ + return new SfxStyleSheetIterator(this,eFam,mask); +} + + +SfxStyleSheetBase* SfxStyleSheetBasePool::Create +( + const XubString& rName, + SfxStyleFamily eFam, + USHORT mask +) +{ + return new SfxStyleSheetBase( rName, *this, eFam, mask ); +} + +SfxStyleSheetBase* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase& r ) +{ + return new SfxStyleSheetBase( r ); +} + +SfxStyleSheetBase& SfxStyleSheetBasePool::Make( const XubString& rName, SfxStyleFamily eFam, USHORT mask, USHORT nPos) +{ + DBG_ASSERT( eFam != SFX_STYLE_FAMILY_ALL, "svtools::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" ); + + SfxStyleSheetIterator aIter(this, eFam, mask); + rtl::Reference< SfxStyleSheetBase > xStyle( aIter.Find( rName ) ); + DBG_ASSERT( !xStyle.is(), "svtools::SfxStyleSheetBasePool::Make(), StyleSheet already exists" ); + SfxStyleSheetIterator& rIter = GetIterator_Impl(); + + if( !xStyle.is() ) + { + xStyle = Create( rName, eFam, mask ); + if(0xffff == nPos || nPos == aStyles.size() || nPos == rIter.Count()) + { + aStyles.push_back( xStyle ); + } + else + { + rIter[nPos]; + aStyles.insert( aStyles.begin() + rIter.GetPos(), xStyle ); + } + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xStyle.get() ) ); + } + return *xStyle.get(); +} + +/////////////////////////////// Kopieren /////////////////////////////////// + +// Hilfsroutine: Falls eine Vorlage dieses Namens existiert, wird +// sie neu erzeugt. Alle Vorlagen, die diese Vorlage zum Parent haben, +// werden umgehaengt. + +SfxStyleSheetBase& SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet ) +{ + SfxStyleSheetIterator aIter(this, rSheet.GetFamily(), nMask); + SfxStyleSheetBase* pOld = aIter.Find( rSheet.GetName() ); + Remove( pOld ); + rtl::Reference< SfxStyleSheetBase > xNew( Create( rSheet ) ); + aStyles.push_back( xNew ); + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *xNew.get() ) ); + return *xNew.get(); +} + +SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool& r ) +{ + if( &r != this ) + { + Clear(); + *this += r; + } + return *this; +} + +SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool& r ) +{ + if( &r != this ) + { + SfxStyles::const_iterator aIter( r.aStyles.begin() ); + while( aIter != r.aStyles.end() ) + { + Add(*(*aIter++).get()); + } + } + return *this; +} + +//////////////////////////////// Suchen //////////////////////////////////// + +USHORT SfxStyleSheetBasePool::Count() +{ + return GetIterator_Impl().Count(); +} + +SfxStyleSheetBase *SfxStyleSheetBasePool::operator[](USHORT nIdx) +{ + return GetIterator_Impl()[nIdx]; +} + +SfxStyleSheetBase* SfxStyleSheetBasePool::Find(const XubString& rName, + SfxStyleFamily eFam, + USHORT mask) +{ + SfxStyleSheetIterator aIter(this,eFam,mask); + return aIter.Find(rName); +} + +const SfxStyles& SfxStyleSheetBasePool::GetStyles() +{ + return aStyles; +} + +SfxStyleSheetBase* SfxStyleSheetBasePool::First() +{ + return GetIterator_Impl().First(); +} + +SfxStyleSheetBase* SfxStyleSheetBasePool::Next() +{ + return GetIterator_Impl().Next(); +} + +//////////////////////////////// Loeschen ///////////////////////////////// + +void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p ) +{ + if( p ) + { + SfxStyles::iterator aIter( std::find( aStyles.begin(), aStyles.end(), rtl::Reference< SfxStyleSheetBase >( p ) ) ); + if( aIter != aStyles.end() ) + { + // Alle Styles umsetzen, deren Parent dieser hier ist + ChangeParent( p->GetName(), p->GetParent() ); + aStyles.erase(aIter); + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) ); + } + } +} + +void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p ) +{ + DBG_ASSERT( p, "svtools::SfxStyleSheetBasePool::Insert(), no stylesheet?" ); + + SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask()); + SfxStyleSheetBase* pOld = aIter.Find( p->GetName() ); + DBG_ASSERT( !pOld, "svtools::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" ); + if( p->GetParent().Len() ) + { + pOld = aIter.Find( p->GetParent() ); + DBG_ASSERT( pOld, "svtools::SfxStyleSheetBasePool::Insert(), Parent not found!" ); + } + aStyles.push_back( rtl::Reference< SfxStyleSheetBase >( p ) ); + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) ); +} + +void SfxStyleSheetBasePool::Clear() +{ + SfxStyles aClearStyles; + aClearStyles.swap( aStyles ); + + SfxStyles::iterator aIter( aClearStyles.begin() ); + while( aIter != aClearStyles.end() ) + { + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *(*aIter++).get() ) ); + } +} + +/////////////////////////// Parents umsetzen //////////////////////////////// + +void SfxStyleSheetBasePool::ChangeParent(const XubString& rOld, + const XubString& rNew, + BOOL bVirtual) +{ + const USHORT nTmpMask = GetSearchMask(); + SetSearchMask(GetSearchFamily(), 0xffff); + for( SfxStyleSheetBase* p = First(); p; p = Next() ) + { + if( p->GetParent().Equals( rOld ) ) + { + if(bVirtual) + p->SetParent( rNew ); + else + p->aParent = rNew; + } + } + SetSearchMask(GetSearchFamily(), nTmpMask); +} + +/////////////////////////// Laden/Speichern ///////////////////////////////// + +void SfxStyleSheetBase::Load( SvStream&, USHORT ) +{ +} + +void SfxStyleSheetBase::Store( SvStream& ) +{ +} + + +BOOL SfxStyleSheetBasePool::Load( SvStream& rStream ) +{ + // alte Version? + if ( !rPool.IsVer2_Impl() ) + return Load1_Impl( rStream ); + + // gesamten StyleSheetPool in neuer Version aus einem MiniRecord lesen + SfxMiniRecordReader aPoolRec( &rStream, SFX_STYLES_REC ); + + // Header-Record lesen + short nCharSet = 0; + if ( !rStream.GetError() ) + { + SfxSingleRecordReader aHeaderRec( &rStream, SFX_STYLES_REC_HEADER ); + if ( !aHeaderRec.IsValid() ) + return FALSE; + + aAppName = rPool.GetName(); + rStream >> nCharSet; + } + + // Styles-Record lesen + if ( !rStream.GetError() ) + { + SfxMultiRecordReader aStylesRec( &rStream, SFX_STYLES_REC_STYLES ); + if ( !aStylesRec.IsValid() ) + return FALSE; + + rtl_TextEncoding eEnc = GetSOLoadTextEncoding( + (rtl_TextEncoding)nCharSet, + sal::static_int_cast< USHORT >(rStream.GetVersion()) ); + rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); + rStream.SetStreamCharSet( eEnc ); + + USHORT nStyles; + for ( nStyles = 0; aStylesRec.GetContent(); nStyles++ ) + { + // kann nicht mehr weiterlesen? + if ( rStream.GetError() ) + break; + + // Globale Teile + XubString aName, aParent, aFollow; + String aHelpFile; + USHORT nFamily, nStyleMask,nCount; + sal_uInt32 nHelpId; + rStream.ReadByteString(aName, eEnc ); + rStream.ReadByteString(aParent, eEnc ); + rStream.ReadByteString(aFollow, eEnc ); + rStream >> nFamily >> nStyleMask; + SfxPoolItem::readByteString(rStream, aHelpFile); + rStream >> nHelpId; + + SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask); + rSheet.SetHelpId( aHelpFile, nHelpId ); + // Hier erst einmal Parent und Follow zwischenspeichern + rSheet.aParent = aParent; + rSheet.aFollow = aFollow; + UINT32 nPos = rStream.Tell(); + rStream >> nCount; + if(nCount) + { + rStream.Seek( nPos ); + // Das Laden des ItemSets bedient sich der Methode GetItemSet(), + // damit eigene ItemSets untergeschoben werden koennen + SfxItemSet& rSet = rSheet.GetItemSet(); + rSet.ClearItem(); + //! SfxItemSet aTmpSet( *pTmpPool ); + /*!aTmpSet*/ rSet.Load( rStream ); + //! rSet.Put( aTmpSet ); + } + // Lokale Teile + UINT32 nSize; + USHORT nVer; + rStream >> nVer >> nSize; + nPos = rStream.Tell() + nSize; + rSheet.Load( rStream, nVer ); + rStream.Seek( nPos ); + } + + // #72939# only loop through the styles that were really inserted + ULONG n = aStyles.size(); + + //! delete pTmpPool; + // Jetzt Parent und Follow setzen. Alle Sheets sind geladen. + // Mit Setxxx() noch einmal den String eintragen, da diese + // virtuellen Methoden evtl. ueberlagert sind. + for ( ULONG i = 0; i < n; i++ ) + { + SfxStyleSheetBase* p = aStyles[ i ].get(); + XubString aText = p->aParent; + p->aParent.Erase(); + p->SetParent( aText ); + aText = p->aFollow; + p->aFollow.Erase(); + p->SetFollow( aText ); + } + + rStream.SetStreamCharSet( eOldEnc ); + } + + // alles klar? + return BOOL( rStream.GetError() == SVSTREAM_OK ); +} + +BOOL SfxStyleSheetBasePool::Load1_Impl( SvStream& rStream ) +{ + aAppName = rPool.GetName(); + USHORT nVersion; + short nCharSet; + rStream >> nVersion; + + if(nVersion!=STYLESTREAM_VERSION) + nCharSet=nVersion; + else + rStream >> nCharSet; + + rtl_TextEncoding eEnc = GetSOLoadTextEncoding( + (rtl_TextEncoding)nCharSet, + sal::static_int_cast< USHORT >(rStream.GetVersion()) ); + rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); + rStream.SetStreamCharSet( eEnc ); + + USHORT nStyles; + rStream >> nStyles; + USHORT i; + for ( i = 0; i < nStyles; i++ ) + { + // kann nicht mehr weiterlesen? + if ( rStream.GetError() ) + { + nStyles = i; + break; + } + + // Globale Teile + XubString aName, aParent, aFollow; + String aHelpFile; + USHORT nFamily, nStyleMask,nCount; + sal_uInt32 nHelpId; + rStream.ReadByteString(aName, eEnc ); + rStream.ReadByteString(aParent, eEnc ); + rStream.ReadByteString(aFollow, eEnc ); + rStream >> nFamily >> nStyleMask; + SfxPoolItem::readByteString(rStream, aHelpFile); + if(nVersion!=STYLESTREAM_VERSION) + { + USHORT nTmpHelpId; + rStream >> nTmpHelpId; + nHelpId=nTmpHelpId; + } + else + rStream >> nHelpId; + + SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask); + rSheet.SetHelpId( aHelpFile, nHelpId ); + // Hier erst einmal Parent und Follow zwischenspeichern + rSheet.aParent = aParent; + rSheet.aFollow = aFollow; + UINT32 nPos = rStream.Tell(); + rStream >> nCount; + if(nCount) { + rStream.Seek( nPos ); + // Das Laden des ItemSets bedient sich der Methode GetItemSet(), + // damit eigene ItemSets untergeschoben werden koennen + SfxItemSet& rSet = rSheet.GetItemSet(); + rSet.ClearItem(); +//! SfxItemSet aTmpSet( *pTmpPool ); + /*!aTmpSet*/ rSet.Load( rStream ); + //! rSet.Put( aTmpSet ); + } + // Lokale Teile + UINT32 nSize; + USHORT nVer; + rStream >> nVer >> nSize; + nPos = rStream.Tell() + nSize; + rSheet.Load( rStream, nVer ); + rStream.Seek( nPos ); + } + + //! delete pTmpPool; + // Jetzt Parent und Follow setzen. Alle Sheets sind geladen. + // Mit Setxxx() noch einmal den String eintragen, da diese + // virtuellen Methoden evtl. ueberlagert sind. + for ( i = 0; i < nStyles; i++ ) + { + SfxStyleSheetBase* p = aStyles[ i ].get(); + XubString aText = p->aParent; + p->aParent.Erase(); + p->SetParent( aText ); + aText = p->aFollow; + p->aFollow.Erase(); + p->SetFollow( aText ); + } + + rStream.SetStreamCharSet( eOldEnc ); + + return BOOL( rStream.GetError() == SVSTREAM_OK ); +} + +BOOL SfxStyleSheetBasePool::Store( SvStream& rStream, BOOL bUsed ) +{ + // den ganzen StyleSheet-Pool in einen Mini-Record + SfxMiniRecordWriter aPoolRec( &rStream, SFX_STYLES_REC ); + + // Erst einmal die Dummies rauszaehlen; die werden nicht gespeichert + USHORT nCount = 0; + for( SfxStyleSheetBase* p = First(); p; p = Next() ) + { + if(!bUsed || p->IsUsed()) + nCount++; + } + + // einen Header-Record vorweg + rtl_TextEncoding eEnc + = ::GetSOStoreTextEncoding( + rStream.GetStreamCharSet(), + sal::static_int_cast< USHORT >(rStream.GetVersion()) ); + rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); + rStream.SetStreamCharSet( eEnc ); + + { + SfxSingleRecordWriter aHeaderRec( &rStream, + SFX_STYLES_REC_HEADER, + STYLESTREAM_VERSION ); + rStream << (short) eEnc; + } + + // die StyleSheets in einen MultiVarRecord + { + // Bug 79478: + // make a check loop, to be shure, that the converted names are also + // unique like the originals! In other cases we get a loop. + SvStringsSortDtor aSortOrigNames( 0, 128 ); + SvStrings aOrigNames( 0, 128 ); + SvByteStringsSortDtor aSortConvNames( 0, 128 ); + SvByteStrings aConvNames( 0, 128 ); + + { + + for( SfxStyleSheetBase* p = First(); p; p = Next() ) + { + if(!bUsed || p->IsUsed()) + { + USHORT nFamily = (USHORT)p->GetFamily(); + String* pName = new String( p->GetName() ); + ByteString* pConvName = new ByteString( *pName, eEnc ); + + pName->Insert( (sal_Unicode)nFamily, 0 ); + pConvName->Insert( " ", 0 ); + pConvName->SetChar( + 0, + sal::static_int_cast< char >(0xff & (nFamily >> 8)) ); + pConvName->SetChar( + 1, sal::static_int_cast< char >(0xff & nFamily) ); + + USHORT nInsPos, nAdd = aSortConvNames.Count(); + while( !aSortConvNames.Insert( pConvName, nInsPos ) ) + (pConvName->Append( '_' )).Append( + ByteString::CreateFromInt32( nAdd++ )); + aOrigNames.Insert( pName, nInsPos ); + } + } + + // now we have the list of the names, sorted by convertede names + // But now we need the sorted list of orignames. + { + USHORT nInsPos, nEnd = aOrigNames.Count(); + const ByteStringPtr* ppB = aSortConvNames.GetData(); + for( USHORT n = 0; n < nEnd; ++n, ++ppB ) + { + String* p = aOrigNames.GetObject( n ); + aSortOrigNames.Insert( p, nInsPos ); + aConvNames.Insert( *ppB, nInsPos ); + } + + } + } + + + ByteString sEmpty; + USHORT nFndPos; + String sNm; + SfxMultiVarRecordWriter aStylesRec( &rStream, SFX_STYLES_REC_STYLES, 0 ); + for( SfxStyleSheetBase* p = First(); p; p = Next() ) + { + if(!bUsed || p->IsUsed()) + { + aStylesRec.NewContent(); + + // Globale Teile speichern + String aHelpFile; + sal_uInt32 nHelpId = p->GetHelpId( aHelpFile ); + USHORT nFamily = sal::static_int_cast< USHORT >(p->GetFamily()); + String sFamily( (sal_Unicode)nFamily ); + + (sNm = sFamily) += p->GetName(); + if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) + rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); + else + rStream.WriteByteString( sEmpty ); + + (sNm = sFamily) += p->GetParent(); + if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) + rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); + else + rStream.WriteByteString( sEmpty ); + + (sNm = sFamily) += p->GetFollow(); + if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) + rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); + else + rStream.WriteByteString( sEmpty ); + + rStream << nFamily << p->GetMask(); + SfxPoolItem::writeByteString(rStream, aHelpFile); + rStream << nHelpId; + if(p->pSet) + p->pSet->Store( rStream ); + else + rStream << (USHORT)0; + + // Lokale Teile speichern + // Vor dem lokalen Teil wird die Laenge der lokalen Daten + // als UINT32 sowie die Versionsnummer gespeichert. + rStream << (USHORT) p->GetVersion(); + ULONG nPos1 = rStream.Tell(); + rStream << (UINT32) 0; + p->Store( rStream ); + ULONG nPos2 = rStream.Tell(); + rStream.Seek( nPos1 ); + rStream << (UINT32) ( nPos2 - nPos1 - sizeof( UINT32 ) ); + rStream.Seek( nPos2 ); + if( rStream.GetError() != SVSTREAM_OK ) + break; + } + } + } + + rStream.SetStreamCharSet( eOldEnc ); + + return BOOL( rStream.GetError() == SVSTREAM_OK ); +} + +SfxItemPool& SfxStyleSheetBasePool::GetPool() +{ + return rPool; +} + +const SfxItemPool& SfxStyleSheetBasePool::GetPool() const +{ + return rPool; +} + +/////////////////////// SfxStyleSheet ///////////////////////////////// + +SfxStyleSheet::SfxStyleSheet(const XubString &rName, + const SfxStyleSheetBasePool& r_Pool, + SfxStyleFamily eFam, + USHORT mask ): + SfxStyleSheetBase(rName, const_cast< SfxStyleSheetBasePool& >( r_Pool ), eFam, mask) +{} + +SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet& rStyle) : + SfxStyleSheetBase(rStyle), + SfxListener( rStyle ), + SfxBroadcaster( rStyle ) +{} + +SfxStyleSheet::SfxStyleSheet() +{ +} + +SfxStyleSheet::~SfxStyleSheet() +{ + Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_INDESTRUCTION, *this ) ); +} + + +BOOL SfxStyleSheet::SetParent( const XubString& rName ) +{ + if(aParent == rName) + return TRUE; + const XubString aOldParent(aParent); + if(SfxStyleSheetBase::SetParent(rName)) { + // aus der Benachrichtigungskette des alten + // Parents gfs. austragen + if(aOldParent.Len()) { + SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aOldParent, nFamily, 0xffff); + if(pParent) + EndListening(*pParent); + } + // in die Benachrichtigungskette des neuen + // Parents eintragen + if(aParent.Len()) { + SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aParent, nFamily, 0xffff); + if(pParent) + StartListening(*pParent); + } + return TRUE; + } + return FALSE; +} + +// alle Zuhoerer benachtichtigen + +void SfxStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + Forward(rBC, rHint); +} + +//////////////////////// SfxStyleSheetPool /////////////////////////////// + +SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet) +: SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) ) +{ +} + +/////////////////////////////////// Factory //////////////////////////////// + +SfxStyleSheetBase* SfxStyleSheetPool::Create( const XubString& rName, + SfxStyleFamily eFam, USHORT mask ) +{ + return new SfxStyleSheet( rName, *this, eFam, mask ); +} + +SfxStyleSheetBase* SfxStyleSheetPool::Create( const SfxStyleSheet& r ) +{ + return new SfxStyleSheet( r ); +} +/* +BOOL SfxStyleSheetPool::CopyTo(SfxStyleSheetPool &, const String &) +{ + return FALSE; +} +*/ + +// -------------------------------------------------------------------- +// class SfxUnoStyleSheet +// -------------------------------------------------------------------- + +SfxUnoStyleSheet::SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, USHORT _nMaske ) +: ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rName, _rPool, _eFamily, _nMaske ) +{ +} + +// -------------------------------------------------------------------- +SfxUnoStyleSheet::SfxUnoStyleSheet( const SfxStyleSheet& _rSheet ) +: ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rSheet ) +{ +} + +// -------------------------------------------------------------------- + +SfxUnoStyleSheet* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle ) +{ + SfxUnoStyleSheet* pRet = dynamic_cast< SfxUnoStyleSheet* >( xStyle.get() ); + if( !pRet ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xStyle, ::com::sun::star::uno::UNO_QUERY ); + if( xUT.is() ) + pRet = reinterpret_cast<SfxUnoStyleSheet*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SfxUnoStyleSheet::getIdentifier()))); + } + return pRet; +} + +// -------------------------------------------------------------------- +// XUnoTunnel +// -------------------------------------------------------------------- + +::sal_Int64 SAL_CALL SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException) +{ + if( rId.getLength() == 16 && 0 == rtl_compareMemory( getIdentifier().getConstArray(), rId.getConstArray(), 16 ) ) + { + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this)); + } + else + { + return 0; + } +} + +// -------------------------------------------------------------------- + +const ::com::sun::star::uno::Sequence< ::sal_Int8 >& SfxUnoStyleSheet::getIdentifier() +{ + static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = 0; + if( !pSeq ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// -------------------------------------------------------------------- diff --git a/svl/source/items/stylepool.cxx b/svl/source/items/stylepool.cxx new file mode 100644 index 000000000000..5f31500be73c --- /dev/null +++ b/svl/source/items/stylepool.cxx @@ -0,0 +1,542 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: stylepool.cxx,v $ + * $Revision: 1.10.78.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <vector> +#include <map> + +#include "stylepool.hxx" +#include <svtools/itemiter.hxx> +#include <svtools/itempool.hxx> + + +using namespace boost; + +namespace { + // A "Node" represents a subset of inserted SfxItemSets + // The root node represents the empty set + // The other nodes contain a SfxPoolItem and represents an item set which contains their + // pool item and the pool items of their parents. + class Node + { + std::vector<Node*> mChildren; // child nodes, create by findChildNode(..) + // container of shared pointers of inserted item sets; for non-poolable + // items more than one item set is needed + std::vector< StylePool::SfxItemSet_Pointer_t > maItemSet; + const SfxPoolItem *mpItem; // my pool item + Node *mpUpper; // if I'm a child node that's my parent node + // --> OD 2008-03-07 #i86923# + const bool mbIsItemIgnorable; + // <-- + public: + // --> OD 2008-03-07 #i86923# + Node() // root node Ctor + : mChildren(), + maItemSet(), + mpItem( 0 ), + mpUpper( 0 ), + mbIsItemIgnorable( false ) + {} + Node( const SfxPoolItem& rItem, Node* pParent, const bool bIgnorable ) // child node Ctor + : mChildren(), + maItemSet(), + mpItem( rItem.Clone() ), + mpUpper( pParent ), + mbIsItemIgnorable( bIgnorable ) + {} + // <-- + ~Node(); + // --> OD 2008-03-11 #i86923# + bool hasItemSet( const bool bCheckUsage ) const; + // <-- + // --> OD 2008-04-29 #i87808# +// const StylePool::SfxItemSet_Pointer_t getItemSet() const { return aItemSet[aItemSet.size()-1]; } + const StylePool::SfxItemSet_Pointer_t getItemSet() const + { + return maItemSet.back(); + } + const StylePool::SfxItemSet_Pointer_t getUsedOrLastAddedItemSet() const; + // <-- + void setItemSet( const SfxItemSet& rSet ){ maItemSet.push_back( StylePool::SfxItemSet_Pointer_t( rSet.Clone() ) ); } + // --> OD 2008-03-11 #i86923# + Node* findChildNode( const SfxPoolItem& rItem, + const bool bIsItemIgnorable = false ); + Node* nextItemSet( Node* pLast, + const bool bSkipUnusedItemSet, + const bool bSkipIgnorable ); + // <-- + const SfxPoolItem& getPoolItem() const { return *mpItem; } + // --> OD 2008-03-11 #i86923# + bool hasIgnorableChildren( const bool bCheckUsage ) const; + const StylePool::SfxItemSet_Pointer_t getItemSetOfIgnorableChild( + const bool bSkipUnusedItemSets ) const; + // <-- + }; + + // --> OD 2008-04-29 #i87808# + const StylePool::SfxItemSet_Pointer_t Node::getUsedOrLastAddedItemSet() const + { + std::vector< StylePool::SfxItemSet_Pointer_t >::const_reverse_iterator aIter; + + for ( aIter = maItemSet.rbegin(); aIter != maItemSet.rend(); ++aIter ) + { + if ( (*aIter).use_count() > 1 ) + { + return *aIter; + } + } + + return maItemSet.back(); + } + // <-- + + // --> OD 2008-05-06 #i86923# + bool Node::hasItemSet( const bool bCheckUsage ) const + { + bool bHasItemSet = false; + + if ( maItemSet.size() > 0 ) + { + if ( bCheckUsage ) + { + std::vector< StylePool::SfxItemSet_Pointer_t >::const_reverse_iterator aIter; + + for ( aIter = maItemSet.rbegin(); aIter != maItemSet.rend(); ++aIter ) + { + if ( (*aIter).use_count() > 1 ) + { + bHasItemSet = true; + break; + } + } + } + else + { + bHasItemSet = true; + } + } + return bHasItemSet; + } + // <-- + + // --> OD 2008-03-07 #i86923# + Node* Node::findChildNode( const SfxPoolItem& rItem, + const bool bIsItemIgnorable ) + // <-- + { + Node* pNextNode = this; + std::vector<Node*>::iterator aIter = mChildren.begin(); + while( aIter != mChildren.end() ) + { + if( rItem.Which() == (*aIter)->getPoolItem().Which() && + rItem == (*aIter)->getPoolItem() ) + return *aIter; + ++aIter; + } + // --> OD 2008-03-07 #i86923# + pNextNode = new Node( rItem, pNextNode, bIsItemIgnorable ); + // <-- + mChildren.push_back( pNextNode ); + return pNextNode; + } + + /* Find the next node which has a SfxItemSet. + The input parameter pLast has a sophisticated meaning: + downstairs only: + pLast == 0 => scan your children and their children + but neither your parents neither your siblings + downstairs and upstairs: + pLast == this => scan your children, their children, + the children of your parent behind you, and so on + partial downstairs and upstairs + pLast != 0 && pLast != this => scan your children behind the given children, + the children of your parent behind you and so on. + + OD 2008-03-11 #i86923# + introduce parameters <bSkipUnusedItemSets> and <bSkipIgnorable> + and its handling. + */ + Node* Node::nextItemSet( Node* pLast, + const bool bSkipUnusedItemSets, + const bool bSkipIgnorable ) + { + // Searching downstairs + std::vector<Node*>::iterator aIter = mChildren.begin(); + // For pLast == 0 and pLast == this all children are of interest + // for another pLast the search starts behind pLast... + if( pLast && pLast != this ) + { + aIter = std::find( mChildren.begin(), mChildren.end(), pLast ); + if( aIter != mChildren.end() ) + ++aIter; + } + Node *pNext = 0; + while( aIter != mChildren.end() ) + { + // --> OD 2008-03-11 #i86923# + if ( bSkipIgnorable && (*aIter)->mbIsItemIgnorable ) + { + ++aIter; + continue; + } + // <-- + pNext = *aIter; + // --> OD 2008-03-11 #i86923# + if ( pNext->hasItemSet( bSkipUnusedItemSets ) ) + { + return pNext; + } + if ( bSkipIgnorable && + pNext->hasIgnorableChildren( bSkipUnusedItemSets ) ) + { + return pNext; + } + pNext = pNext->nextItemSet( 0, bSkipUnusedItemSets, bSkipIgnorable ); // 0 => downstairs only + // <-- + if( pNext ) + return pNext; + ++aIter; + } + // Searching upstairs + if( pLast && mpUpper ) + { + // --> OD 2008-03-11 #i86923# + pNext = mpUpper->nextItemSet( this, bSkipUnusedItemSets, bSkipIgnorable ); + // <-- + } + return pNext; + } + + // --> OD 2008-03-11 #i86923# + bool Node::hasIgnorableChildren( const bool bCheckUsage ) const + { + bool bHasIgnorableChildren( false ); + + std::vector<Node*>::const_iterator aIter = mChildren.begin(); + while( aIter != mChildren.end() && !bHasIgnorableChildren ) + { + Node* pChild = *aIter; + if ( pChild->mbIsItemIgnorable ) + { + bHasIgnorableChildren = + !bCheckUsage || + ( pChild->hasItemSet( bCheckUsage /* == true */ ) || + pChild->hasIgnorableChildren( bCheckUsage /* == true */ ) ); + } + ++aIter; + } + + return bHasIgnorableChildren; + } + + const StylePool::SfxItemSet_Pointer_t Node::getItemSetOfIgnorableChild( + const bool bSkipUnusedItemSets ) const + { + DBG_ASSERT( hasIgnorableChildren( bSkipUnusedItemSets ), + "<Node::getItemSetOfIgnorableChild> - node has no ignorable children" ); + + std::vector<Node*>::const_iterator aIter = mChildren.begin(); + while( aIter != mChildren.end() ) + { + Node* pChild = *aIter; + if ( pChild->mbIsItemIgnorable ) + { + if ( pChild->hasItemSet( bSkipUnusedItemSets ) ) + { + return pChild->getUsedOrLastAddedItemSet(); + } + else + { + pChild = pChild->nextItemSet( 0, bSkipUnusedItemSets, false ); + if ( pChild ) + { + return pChild->getUsedOrLastAddedItemSet(); + } + } + } + ++aIter; + } + + StylePool::SfxItemSet_Pointer_t pReturn; + return pReturn; + } + // <-- + + Node::~Node() + { + std::vector<Node*>::iterator aIter = mChildren.begin(); + while( aIter != mChildren.end() ) + { + delete *aIter; + ++aIter; + } + delete mpItem; + } + + class Iterator : public IStylePoolIteratorAccess + { + std::map< const SfxItemSet*, Node >& mrRoot; + std::map< const SfxItemSet*, Node >::iterator mpCurrNode; + Node* mpNode; + const bool mbSkipUnusedItemSets; + const bool mbSkipIgnorable; + public: + // --> OD 2008-03-07 #i86923# + Iterator( std::map< const SfxItemSet*, Node >& rR, + const bool bSkipUnusedItemSets, + const bool bSkipIgnorable ) + : mrRoot( rR ), + mpCurrNode( rR.begin() ), + mpNode(0), + mbSkipUnusedItemSets( bSkipUnusedItemSets ), + mbSkipIgnorable( bSkipIgnorable ) + {} + // <-- + virtual StylePool::SfxItemSet_Pointer_t getNext(); + virtual ::rtl::OUString getName(); + }; + + StylePool::SfxItemSet_Pointer_t Iterator::getNext() + { + StylePool::SfxItemSet_Pointer_t pReturn; + while( mpNode || mpCurrNode != mrRoot.end() ) + { + if( !mpNode ) + { + mpNode = &mpCurrNode->second; + ++mpCurrNode; + // --> OD 2008-03-11 #i86923# + if ( mpNode->hasItemSet( mbSkipUnusedItemSets ) ) + { + // --> OD 2008-04-30 #i87808# +// return pNode->getItemSet(); + return mpNode->getUsedOrLastAddedItemSet(); + // <-- + } + // <-- + } + // --> OD 2008-03-11 #i86923# + mpNode = mpNode->nextItemSet( mpNode, mbSkipUnusedItemSets, mbSkipIgnorable ); + if ( mpNode && mpNode->hasItemSet( mbSkipUnusedItemSets ) ) + { + // --> OD 2008-04-30 #i87808# +// return pNode->getItemSet(); + return mpNode->getUsedOrLastAddedItemSet(); + // <-- + } + if ( mbSkipIgnorable && + mpNode && mpNode->hasIgnorableChildren( mbSkipUnusedItemSets ) ) + { + return mpNode->getItemSetOfIgnorableChild( mbSkipUnusedItemSets ); + } + // <-- + } + return pReturn; + } + + ::rtl::OUString Iterator::getName() + { + ::rtl::OUString aString; + if( mpNode && mpNode->hasItemSet( false ) ) + { + // --> OD 2008-04-30 #i87808# +// aString = StylePool::nameOf( pNode->getItemSet() ); + aString = StylePool::nameOf( mpNode->getUsedOrLastAddedItemSet() ); + // <-- + } + return aString; + } + +} + +/* This static method creates a unique name from a shared pointer to a SfxItemSet + The name is the memory address of the SfxItemSet itself. */ + +::rtl::OUString StylePool::nameOf( SfxItemSet_Pointer_t pSet ) +{ + return ::rtl::OUString::valueOf( reinterpret_cast<sal_IntPtr>( pSet.get() ), 16 ); +} + +// class StylePoolImpl organized a tree-structure where every node represents a SfxItemSet. +// The insertItemSet method adds a SfxItemSet into the tree if necessary and returns a shared_ptr +// to a copy of the SfxItemSet. +// The aRoot-Node represents an empty SfxItemSet. + +class StylePoolImpl +{ +private: + std::map< const SfxItemSet*, Node > maRoot; + sal_Int32 mnCount; + // --> OD 2008-03-07 #i86923# + SfxItemSet* mpIgnorableItems; + // <-- +public: + // --> OD 2008-03-07 #i86923# + explicit StylePoolImpl( SfxItemSet* pIgnorableItems = 0 ) + : maRoot(), + mnCount(0), + mpIgnorableItems( pIgnorableItems != 0 + ? pIgnorableItems->Clone( FALSE ) + : 0 ) + { + DBG_ASSERT( !pIgnorableItems || !pIgnorableItems->Count(), + "<StylePoolImpl::StylePoolImpl(..)> - misusage: item set for ignorable item should be empty. Please correct usage." ); + DBG_ASSERT( !mpIgnorableItems || !mpIgnorableItems->Count(), + "<StylePoolImpl::StylePoolImpl(..)> - <SfxItemSet::Clone( FALSE )> does not work as excepted - <mpIgnorableItems> is not empty. Please inform OD." ); + } + + ~StylePoolImpl() + { + delete mpIgnorableItems; + } + // <-- + + StylePool::SfxItemSet_Pointer_t insertItemSet( const SfxItemSet& rSet ); + + // --> OD 2008-03-07 #i86923# + IStylePoolIteratorAccess* createIterator( bool bSkipUnusedItemSets = false, + bool bSkipIgnorableItems = false ); + // <-- + sal_Int32 getCount() const { return mnCount; } +}; + +StylePool::SfxItemSet_Pointer_t StylePoolImpl::insertItemSet( const SfxItemSet& rSet ) +{ + bool bNonPoolable = false; + Node* pCurNode = &maRoot[ rSet.GetParent() ]; + SfxItemIter aIter( rSet ); + const SfxPoolItem* pItem = aIter.GetCurItem(); + // Every SfxPoolItem in the SfxItemSet causes a step deeper into the tree, + // a complete empty SfxItemSet would stay at the root node. + // --> OD 2008-03-07 #i86923# + // insert ignorable items to the tree leaves. + std::auto_ptr<SfxItemSet> pFoundIgnorableItems; + if ( mpIgnorableItems ) + { + pFoundIgnorableItems.reset( new SfxItemSet( *mpIgnorableItems ) ); + } + while( pItem ) + { + if( !rSet.GetPool()->IsItemFlag(pItem->Which(), SFX_ITEM_POOLABLE ) ) + bNonPoolable = true; + if ( !pFoundIgnorableItems.get() || + ( pFoundIgnorableItems.get() && + pFoundIgnorableItems->Put( *pItem ) == 0 ) ) + { + pCurNode = pCurNode->findChildNode( *pItem ); + } + pItem = aIter.NextItem(); + } + if ( pFoundIgnorableItems.get() && + pFoundIgnorableItems->Count() > 0 ) + { + SfxItemIter aIgnorableItemsIter( *pFoundIgnorableItems ); + pItem = aIgnorableItemsIter.GetCurItem(); + while( pItem ) + { + if( !rSet.GetPool()->IsItemFlag(pItem->Which(), SFX_ITEM_POOLABLE ) ) + bNonPoolable = true; + pCurNode = pCurNode->findChildNode( *pItem, true ); + pItem = aIgnorableItemsIter.NextItem(); + } + } + // <-- + // Every leaf node represents an inserted item set, but "non-leaf" nodes represents subsets + // of inserted itemsets. + // These nodes could have but does not need to have a shared_ptr to a item set. + if( !pCurNode->hasItemSet( false ) ) + { + pCurNode->setItemSet( rSet ); + bNonPoolable = false; // to avoid a double insertion + ++mnCount; + } + // If rSet contains at least one non poolable item, a new itemset has to be inserted + if( bNonPoolable ) + pCurNode->setItemSet( rSet ); +#ifdef DEBUG + { + sal_Int32 nCheck = -1; + sal_Int32 nNo = -1; + IStylePoolIteratorAccess* pIter = createIterator(); + StylePool::SfxItemSet_Pointer_t pTemp; + do + { + ++nCheck; + pTemp = pIter->getNext(); + if( pCurNode->hasItemSet( false ) && pTemp.get() == pCurNode->getItemSet().get() ) + { + ::rtl::OUString aStr = StylePool::nameOf( pTemp ); + nNo = nCheck; + } + } while( pTemp.get() ); + DBG_ASSERT( mnCount == nCheck, "Wrong counting"); + delete pIter; + } +#endif + return pCurNode->getItemSet(); +} + +// --> OD 2008-03-07 #i86923# +IStylePoolIteratorAccess* StylePoolImpl::createIterator( bool bSkipUnusedItemSets, + bool bSkipIgnorableItems ) +{ + return new Iterator( maRoot, bSkipUnusedItemSets, bSkipIgnorableItems ); +} +// <-- + +// Ctor, Dtor and redirected methods of class StylePool, nearly inline ;-) + +// --> OD 2008-03-07 #i86923# +StylePool::StylePool( SfxItemSet* pIgnorableItems ) + : pImpl( new StylePoolImpl( pIgnorableItems ) ) +{} +// <-- + +StylePool::SfxItemSet_Pointer_t StylePool::insertItemSet( const SfxItemSet& rSet ) +{ return pImpl->insertItemSet( rSet ); } + +// --> OD 2008-03-11 #i86923# +IStylePoolIteratorAccess* StylePool::createIterator( const bool bSkipUnusedItemSets, + const bool bSkipIgnorableItems ) +{ + return pImpl->createIterator( bSkipUnusedItemSets, bSkipIgnorableItems ); +} +// <-- + +sal_Int32 StylePool::getCount() const +{ return pImpl->getCount(); } + +StylePool::~StylePool() { delete pImpl; } + +// End of class StylePool + diff --git a/svl/source/items/szitem.cxx b/svl/source/items/szitem.cxx new file mode 100644 index 000000000000..ec3ff83dd2ec --- /dev/null +++ b/svl/source/items/szitem.cxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: szitem.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include <svtools/szitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/awt/Size.hpp> +#include <tools/stream.hxx> +#include <tools/gen.hxx> + +#include <svtools/poolitem.hxx> +#include "memberid.hrc" + +// STATIC DATA ----------------------------------------------------------- + +DBG_NAME(SfxSizeItem) + +// ----------------------------------------------------------------------- + +TYPEINIT1_AUTOFACTORY(SfxSizeItem, SfxPoolItem); + +// ----------------------------------------------------------------------- + +SfxSizeItem::SfxSizeItem() +{ + DBG_CTOR(SfxSizeItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxSizeItem::SfxSizeItem( USHORT nW, const Size& rVal ) : + SfxPoolItem( nW ), + aVal( rVal ) +{ + DBG_CTOR(SfxSizeItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxSizeItem::SfxSizeItem( USHORT nW, SvStream &rStream ) : + SfxPoolItem( nW ) +{ + DBG_CTOR(SfxSizeItem, 0); + rStream >> aVal; +} + +// ----------------------------------------------------------------------- + +SfxSizeItem::SfxSizeItem( const SfxSizeItem& rItem ) : + SfxPoolItem( rItem ), + aVal( rItem.aVal ) +{ + DBG_CTOR(SfxSizeItem, 0); +} + +// ----------------------------------------------------------------------- + +SfxItemPresentation SfxSizeItem::GetPresentation +( + SfxItemPresentation /*ePresentation*/, + SfxMapUnit /*eCoreMetric*/, + SfxMapUnit /*ePresentationMetric*/, + XubString& rText, + const IntlWrapper * +) const +{ + DBG_CHKTHIS(SfxSizeItem, 0); + rText = UniString::CreateFromInt32(aVal.Width()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + rText += UniString::CreateFromInt32(aVal.Height()); + rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + +// ----------------------------------------------------------------------- + +int SfxSizeItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS(SfxSizeItem, 0); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + return ((SfxSizeItem&)rItem).aVal == aVal; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxSizeItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxSizeItem, 0); + return new SfxSizeItem( *this ); +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxSizeItem::Create(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxSizeItem, 0); + Size aStr; + rStream >> aStr; + return new SfxSizeItem(Which(), aStr); +} + +// ----------------------------------------------------------------------- + +SvStream& SfxSizeItem::Store(SvStream &rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxSizeItem, 0); + rStream << aVal; + return rStream; +} + +// ----------------------------------------------------------------------- +BOOL SfxSizeItem::QueryValue( com::sun::star::uno::Any& rVal, + BYTE nMemberId ) const +{ + sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); + nMemberId &= ~CONVERT_TWIPS; + + Size aTmp(aVal); + if( bConvert ) + { + aTmp.Height() = ( aTmp.Height() * 127 + 36) / 72; + aTmp.Width() = ( aTmp.Width() * 127 + 36) / 72; + } + + switch ( nMemberId ) + { + case 0: + { + rVal <<= com::sun::star::awt::Size( aTmp.getWidth(), aTmp.getHeight() ); + break; + } + case MID_WIDTH: + rVal <<= aTmp.getWidth(); break; + case MID_HEIGHT: + rVal <<= aTmp.getHeight(); break; + default: DBG_ERROR("Wrong MemberId!"); return FALSE; + } + + return TRUE; +} + +// ----------------------------------------------------------------------- +BOOL SfxSizeItem::PutValue( const com::sun::star::uno::Any& rVal, + BYTE nMemberId ) +{ + sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); + nMemberId &= ~CONVERT_TWIPS; + + BOOL bRet = FALSE; + com::sun::star::awt::Size aValue; + sal_Int32 nVal = 0; + if ( !nMemberId ) + bRet = ( rVal >>= aValue ); + else + { + bRet = ( rVal >>= nVal ); + if ( nMemberId == MID_WIDTH ) + { + aValue.Width = nVal; + aValue.Height = aVal.Height(); + } + else + { + aValue.Height = nVal; + aValue.Width = aVal.Width(); + } + } + + if ( bRet ) + { + Size aTmp( aValue.Width, aValue.Height ); + if( bConvert ) + { + aTmp.Height() = ( aTmp.Height() * 72 + 63) / 127; + aTmp.Width() = ( aTmp.Width() * 72 + 63) / 127; + } + + aVal = aTmp; + } + + return bRet; +} + + + diff --git a/svl/source/items/tfrmitem.cxx b/svl/source/items/tfrmitem.cxx new file mode 100644 index 000000000000..a7019ff69947 --- /dev/null +++ b/svl/source/items/tfrmitem.cxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tfrmitem.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <com/sun/star/uno/Any.hxx> + +#include <tools/stream.hxx> +#include <tools/debug.hxx> +#include <tools/string.hxx> + +#include <svtools/tfrmitem.hxx> + +DBG_NAME( SfxTargetFrameItem ) +TYPEINIT1( SfxTargetFrameItem, SfxPoolItem ); + +// ----------------------------------------------------------------------- + +SfxTargetFrameItem::SfxTargetFrameItem( USHORT which ) : + SfxPoolItem( which ) +{ + DBG_CTOR( SfxTargetFrameItem, 0 ); +} + +// ----------------------------------------------------------------------- + +SfxTargetFrameItem::SfxTargetFrameItem( const SfxTargetFrameItem& rItem ) : + SfxPoolItem( rItem ) +{ + DBG_CTOR( SfxTargetFrameItem, 0 ); + for( USHORT nCur = 0; nCur <= (USHORT)SfxOpenModeLast; nCur++ ) + _aFrames[nCur] = rItem._aFrames[nCur]; +} + +// ----------------------------------------------------------------------- + +SfxTargetFrameItem::SfxTargetFrameItem( USHORT which, + const String& rOpenSelectFrame, const String& rOpenOpenFrame, + const String& rOpenAddTaskFrame ) : SfxPoolItem( which ) +{ + DBG_CTOR( SfxTargetFrameItem, 0 ); + _aFrames[ (USHORT)SfxOpenSelect ] = rOpenSelectFrame; + _aFrames[ (USHORT)SfxOpenOpen ] = rOpenOpenFrame; + _aFrames[ (USHORT)SfxOpenAddTask ] = rOpenAddTaskFrame; +} + +// ----------------------------------------------------------------------- + +SfxTargetFrameItem::~SfxTargetFrameItem() +{ + DBG_DTOR(SfxTargetFrameItem, 0); +} + +// ----------------------------------------------------------------------- + +String SfxTargetFrameItem::GetTargetFrame( SfxOpenMode eMode ) const +{ + DBG_CHKTHIS( SfxTargetFrameItem, 0 ); + if( eMode <= SfxOpenModeLast ) + return _aFrames[ (USHORT)eMode ]; + String aResult; + return aResult; +} + +// ----------------------------------------------------------------------- + +int SfxTargetFrameItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_CHKTHIS( SfxTargetFrameItem, 0 ); + DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); + + for( USHORT nCur = 0; nCur <= (USHORT)SfxOpenModeLast; nCur++ ) + { + if( _aFrames[nCur] != ((const SfxTargetFrameItem&)rItem)._aFrames[nCur] ) + return 0; + } + return 1; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxTargetFrameItem::Create( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS(SfxTargetFrameItem, 0); + SfxTargetFrameItem* pItem = new SfxTargetFrameItem( Which() ); + USHORT nCount = 0; + rStream >> nCount; + for(USHORT nCur=0; nCur<= (USHORT)SfxOpenModeLast && nCount; nCur++,nCount--) + { + readByteString(rStream, pItem->_aFrames[ nCur ]); + } + // die uebriggebliebenen ueberspringen + String aTemp; + while( nCount ) + { + readByteString(rStream, aTemp); + nCount--; + } + return pItem; +} + +// ----------------------------------------------------------------------- + +SvStream& SfxTargetFrameItem::Store( SvStream& rStream, USHORT ) const +{ + DBG_CHKTHIS( SfxTargetFrameItem, 0 ); + USHORT nCount = (USHORT)(SfxOpenModeLast+1); + rStream << nCount; + for( USHORT nCur = 0; nCur <= (USHORT)SfxOpenModeLast; nCur++ ) + { + writeByteString(rStream, _aFrames[ nCur ]); + } + return rStream; +} + +// ----------------------------------------------------------------------- + +SfxPoolItem* SfxTargetFrameItem::Clone( SfxItemPool* ) const +{ + DBG_CHKTHIS( SfxTargetFrameItem, 0 ); + return new SfxTargetFrameItem( *this ); +} + +// ----------------------------------------------------------------------- +// virtual +BOOL SfxTargetFrameItem::QueryValue( com::sun::star::uno::Any& rVal,BYTE ) const +{ + String aVal; + for ( int i = 0; i <= SfxOpenModeLast; i++ ) + { + aVal += _aFrames[ i ]; + aVal += ';' ; + } + + rVal <<= rtl::OUString( aVal ); + return TRUE; +} + +// ----------------------------------------------------------------------- +// virtual +BOOL SfxTargetFrameItem::PutValue( const com::sun::star::uno::Any& rVal,BYTE ) +{ + rtl::OUString aValue; + if ( rVal >>= aValue ) + { + const String aVal( aValue ); + + for ( USHORT i = 0; i <= SfxOpenModeLast; i++ ) + _aFrames[ i ] = aVal.GetToken( i ); + + return TRUE; + } + + DBG_ERROR( "SfxTargetFrameItem::PutValue - Wrong type!" ); + return FALSE; +} + diff --git a/svl/source/items/tresitem.cxx b/svl/source/items/tresitem.cxx new file mode 100644 index 000000000000..6e70c82a4d03 --- /dev/null +++ b/svl/source/items/tresitem.cxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: tresitem.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <svtools/tresitem.hxx> + +using namespace com::sun::star; + +//============================================================================ +// +// CntTransferResultItem +// +//============================================================================ + +TYPEINIT1_AUTOFACTORY(CntTransferResultItem, SfxPoolItem) + +//============================================================================ +// virtual +int CntTransferResultItem::operator ==(SfxPoolItem const & rItem) const +{ + if (CntTransferResultItem * pResultItem = PTR_CAST(CntTransferResultItem, + &rItem)) + return m_aResult.Source == pResultItem->m_aResult.Source + && m_aResult.Target == pResultItem->m_aResult.Target + && m_aResult.Result == pResultItem->m_aResult.Result; + return false; +} + +//============================================================================ +// virtual +BOOL CntTransferResultItem::QueryValue(uno::Any & rVal, BYTE) const +{ + rVal <<= m_aResult; + return true; +} + +//============================================================================ +// virtual +BOOL CntTransferResultItem::PutValue(uno::Any const & rVal, BYTE) +{ + return rVal >>= m_aResult; +} + +//============================================================================ +// virtual +SfxPoolItem * CntTransferResultItem::Clone(SfxItemPool *) const +{ + return new CntTransferResultItem(*this); +} + diff --git a/svl/source/items/visitem.cxx b/svl/source/items/visitem.cxx new file mode 100644 index 000000000000..112b223a8be0 --- /dev/null +++ b/svl/source/items/visitem.cxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: visitem.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +#include <svtools/visitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <tools/stream.hxx> + +//============================================================================ +// +// class SfxVisibilityItem +// +//============================================================================ + +DBG_NAME(SfxVisibilityItem) + +//============================================================================ +TYPEINIT1_AUTOFACTORY(SfxVisibilityItem, SfxPoolItem); + +//============================================================================ +SfxVisibilityItem::SfxVisibilityItem(USHORT which, SvStream & rStream): + SfxPoolItem(which) +{ + DBG_CTOR(SfxVisibilityItem, 0); + sal_Bool bValue = 0; + rStream >> bValue; + m_nValue.bVisible = bValue; +} + +//============================================================================ +// virtual +int SfxVisibilityItem::operator ==(const SfxPoolItem & rItem) const +{ + DBG_CHKTHIS(SfxVisibilityItem, 0); + DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type"); + return m_nValue.bVisible == SAL_STATIC_CAST(const SfxVisibilityItem *, &rItem)-> + m_nValue.bVisible; +} + +//============================================================================ +// virtual +int SfxVisibilityItem::Compare(const SfxPoolItem & rWith) const +{ + DBG_ASSERT(rWith.ISA(SfxVisibilityItem), "SfxVisibilityItem::Compare(): Bad type"); + return m_nValue.bVisible == static_cast< SfxVisibilityItem const * >(&rWith)->m_nValue.bVisible ? + 0 : m_nValue.bVisible ? -1 : 1; +} + +//============================================================================ +// virtual +SfxItemPresentation SfxVisibilityItem::GetPresentation(SfxItemPresentation, + SfxMapUnit, SfxMapUnit, + XubString & rText, + const IntlWrapper *) const +{ + rText = GetValueTextByVal(m_nValue.bVisible); + return SFX_ITEM_PRESENTATION_NAMELESS; +} + + +//============================================================================ +// virtual +BOOL SfxVisibilityItem::QueryValue(com::sun::star::uno::Any& rVal,BYTE) const +{ + rVal <<= m_nValue; + return TRUE; +} + +//============================================================================ +// virtual +BOOL SfxVisibilityItem::PutValue(const com::sun::star::uno::Any& rVal,BYTE) +{ + if (rVal >>= m_nValue) + return TRUE; + + DBG_ERROR( "SfxInt16Item::PutValue - Wrong type!" ); + return FALSE; +} + +//============================================================================ +// virtual +SfxPoolItem * SfxVisibilityItem::Create(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(SfxVisibilityItem, 0); + return new SfxVisibilityItem(Which(), rStream); +} + +//============================================================================ +// virtual +SvStream & SfxVisibilityItem::Store(SvStream & rStream, USHORT) const +{ + DBG_CHKTHIS(SfxVisibilityItem, 0); + rStream << m_nValue.bVisible; + return rStream; +} + +//============================================================================ +// virtual +SfxPoolItem * SfxVisibilityItem::Clone(SfxItemPool *) const +{ + DBG_CHKTHIS(SfxVisibilityItem, 0); + return new SfxVisibilityItem(*this); +} + +//============================================================================ +// virtual +USHORT SfxVisibilityItem::GetValueCount() const +{ + return 2; +} + +//============================================================================ +// virtual +UniString SfxVisibilityItem::GetValueTextByVal(BOOL bTheValue) const +{ + return + bTheValue ? + UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("TRUE")) : + UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("FALSE")); +} diff --git a/svl/source/items/whassert.hxx b/svl/source/items/whassert.hxx new file mode 100644 index 000000000000..fe9a834816c2 --- /dev/null +++ b/svl/source/items/whassert.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: whassert.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _SFX_WHASSERT_HXX +#define _SFX_WHASSERT_HXX + +#include <tools/debug.hxx> +#include <tools/string.hxx> + +//------------------------------------------------------------------------ + +#ifdef DBG_UTIL +#define SFX_ASSERT( bCondition, nId, sMessage ) \ +{ \ + if ( DbgIsAssert() ) \ + { \ + if ( !(bCondition) ) \ + { \ + ByteString aMsg( sMessage ); \ + aMsg.Append(RTL_CONSTASCII_STRINGPARAM("\nwith Id/Pos: ")); \ + aMsg += ByteString::CreateFromInt32( nId ); \ + DbgOut( aMsg.GetBuffer(), DBG_OUT_ERROR, __FILE__, __LINE__); \ + } \ + } \ +} +#else +#define SFX_ASSERT( bCondition, nId, sMessage ) +#endif + + +#endif diff --git a/svl/source/items/whiter.cxx b/svl/source/items/whiter.cxx new file mode 100644 index 000000000000..461daf7ac012 --- /dev/null +++ b/svl/source/items/whiter.cxx @@ -0,0 +1,127 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: whiter.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" +// INCLUDE --------------------------------------------------------------- +#ifndef GCC +#endif + +#include "whiter.hxx" +#include <svtools/itemset.hxx> + +DBG_NAME(SfxWhichIter) + +// ----------------------------------------------------------------------- + +SfxWhichIter::SfxWhichIter( const SfxItemSet& rSet, USHORT nFromWh, USHORT nToWh ): + pRanges(rSet.GetRanges()), + pStart(rSet.GetRanges()), + nOfst(0), nFrom(nFromWh), nTo(nToWh) +{ + DBG_CTOR(SfxWhichIter, 0); + if ( nFrom > 0 ) + FirstWhich(); +} + +// ----------------------------------------------------------------------- + +SfxWhichIter::~SfxWhichIter() +{ + DBG_DTOR(SfxWhichIter, 0); +} + +// ----------------------------------------------------------------------- + +USHORT SfxWhichIter::NextWhich() +{ + DBG_CHKTHIS(SfxWhichIter, 0); + while ( 0 != *pRanges ) + { + const USHORT nLastWhich = *pRanges + nOfst; + ++nOfst; + if (*(pRanges+1) == nLastWhich) + { + pRanges += 2; + nOfst = 0; + } + USHORT nWhich = *pRanges + nOfst; + if ( 0 == nWhich || ( nWhich >= nFrom && nWhich <= nTo ) ) + return nWhich; + } + return 0; +} + +// ----------------------------------------------------------------------- + +USHORT SfxWhichIter::PrevWhich() +{ + DBG_CHKTHIS(SfxWhichIter, 0); + while ( pRanges != pStart || 0 != nOfst ) + { + if(nOfst) + --nOfst; + else { + pRanges -= 2; + nOfst = *(pRanges+1) - (*pRanges); + } + USHORT nWhich = *pRanges + nOfst; + if ( nWhich >= nFrom && nWhich <= nTo ) + return nWhich; + } + return 0; +} + +// ----------------------------------------------------------------------- + +USHORT SfxWhichIter::FirstWhich() +{ + DBG_CHKTHIS(SfxWhichIter, 0); + pRanges = pStart; + nOfst = 0; + if ( *pRanges >= nFrom && *pRanges <= nTo ) + return *pRanges; + return NextWhich(); +} + +// ----------------------------------------------------------------------- + +USHORT SfxWhichIter::LastWhich() +{ + DBG_CHKTHIS(SfxWhichIter, 0); + while(*pRanges) + ++pRanges; + nOfst = 0; + USHORT nWhich = *(pRanges-1); + if ( nWhich >= nFrom && nWhich <= nTo ) + return nWhich; + return PrevWhich(); +} + |