Kaydet (Commit) 3b16e997 authored tarafından Noel Grandin's avatar Noel Grandin

cleanup SwAuthEntry manual ref-counting

And remove the "handle" nonsense and just pass plain honest pointers to
a real type around

Change-Id: Ic49443f5f8b20890d8335088331fff81585e8981
Reviewed-on: https://gerrit.libreoffice.org/66615
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 2af5d600
...@@ -22,27 +22,24 @@ ...@@ -22,27 +22,24 @@
#include "swdllapi.h" #include "swdllapi.h"
#include "fldbas.hxx" #include "fldbas.hxx"
#include "toxe.hxx" #include "toxe.hxx"
#include <rtl/ref.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <memory> #include <memory>
#include <vector> #include <vector>
class SwAuthEntry class SwAuthEntry : public salhelper::SimpleReferenceObject
{ {
OUString aAuthFields[AUTH_FIELD_END]; OUString aAuthFields[AUTH_FIELD_END];
sal_uInt16 nRefCount;
public: public:
SwAuthEntry() : nRefCount(0){} SwAuthEntry() = default;
SwAuthEntry( const SwAuthEntry& rCopy ); SwAuthEntry( const SwAuthEntry& rCopy );
bool operator==(const SwAuthEntry& rComp); bool operator==(const SwAuthEntry& rComp);
inline OUString const & GetAuthorField(ToxAuthorityField ePos) const; inline OUString const & GetAuthorField(ToxAuthorityField ePos) const;
inline void SetAuthorField(ToxAuthorityField ePos, inline void SetAuthorField(ToxAuthorityField ePos,
const OUString& rField); const OUString& rField);
void AddRef() { ++nRefCount; }
void RemoveRef() { --nRefCount; }
sal_uInt16 GetRefCount() { return nRefCount; }
}; };
struct SwTOXSortKey struct SwTOXSortKey
...@@ -55,14 +52,14 @@ struct SwTOXSortKey ...@@ -55,14 +52,14 @@ struct SwTOXSortKey
}; };
typedef std::vector<SwTOXSortKey> SortKeyArr; typedef std::vector<SwTOXSortKey> SortKeyArr;
typedef std::vector<std::unique_ptr<SwAuthEntry>> SwAuthDataArr; typedef std::vector<rtl::Reference<SwAuthEntry>> SwAuthDataArr;
class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType
{ {
SwDoc* m_pDoc; SwDoc* m_pDoc;
SwAuthDataArr m_DataArr; SwAuthDataArr m_DataArr;
std::vector<sal_IntPtr> m_SequArr; std::vector<SwAuthEntry*> m_SequArr;
std::vector<sal_IntPtr> m_SequArrRLHidden; ///< hidden redlines std::vector<SwAuthEntry*> m_SequArrRLHidden; ///< hidden redlines
SortKeyArr m_SortKeyArr; SortKeyArr m_SortKeyArr;
sal_Unicode m_cPrefix; sal_Unicode m_cPrefix;
sal_Unicode m_cSuffix; sal_Unicode m_cSuffix;
...@@ -85,26 +82,23 @@ public: ...@@ -85,26 +82,23 @@ public:
void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; } void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
SwDoc* GetDoc(){ return m_pDoc; } SwDoc* GetDoc(){ return m_pDoc; }
void RemoveField(sal_IntPtr nHandle); void RemoveField(const SwAuthEntry* nHandle);
sal_IntPtr AddField(const OUString& rFieldContents); SwAuthEntry* AddField(const OUString& rFieldContents);
void AddField(sal_IntPtr nHandle);
void DelSequenceArray() void DelSequenceArray()
{ {
m_SequArr.clear(); m_SequArr.clear();
m_SequArrRLHidden.clear(); m_SequArrRLHidden.clear();
} }
const SwAuthEntry* GetEntryByHandle(sal_IntPtr nHandle) const;
void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const; void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
const SwAuthEntry* GetEntryByIdentifier(const OUString& rIdentifier) const; SwAuthEntry* GetEntryByIdentifier(const OUString& rIdentifier) const;
bool ChangeEntryContent(const SwAuthEntry* pNewEntry); bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
// import interface // import interface
sal_uInt16 AppendField(const SwAuthEntry& rInsert); sal_uInt16 AppendField(const SwAuthEntry& rInsert);
sal_IntPtr GetHandle(sal_uInt16 nPos); SwAuthEntry* GetFieldByPos(sal_uInt16 nPos);
sal_uInt16 GetSequencePos(sal_IntPtr nHandle, SwRootFrame const* pLayout); sal_uInt16 GetSequencePos(const SwAuthEntry* pAuthEntry, SwRootFrame const* pLayout);
bool IsSequence() const {return m_bIsSequence;} bool IsSequence() const {return m_bIsSequence;}
void SetSequence(bool bSet) void SetSequence(bool bSet)
...@@ -154,7 +148,7 @@ public: ...@@ -154,7 +148,7 @@ public:
*/ */
class SwAuthorityField : public SwField class SwAuthorityField : public SwField
{ {
sal_IntPtr m_nHandle; rtl::Reference<SwAuthEntry> m_xAuthEntry;
mutable sal_IntPtr m_nTempSequencePos; mutable sal_IntPtr m_nTempSequencePos;
mutable sal_IntPtr m_nTempSequencePosRLHidden; ///< hidden redlines mutable sal_IntPtr m_nTempSequencePosRLHidden; ///< hidden redlines
...@@ -169,7 +163,7 @@ public: ...@@ -169,7 +163,7 @@ public:
SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const; SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents); SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
SwAuthorityField(SwAuthorityFieldType* pType, sal_IntPtr nHandle); SwAuthorityField(SwAuthorityFieldType* pType, SwAuthEntry* pAuthEntry);
virtual ~SwAuthorityField() override; virtual ~SwAuthorityField() override;
OUString GetFieldText(ToxAuthorityField eField) const; OUString GetFieldText(ToxAuthorityField eField) const;
...@@ -180,7 +174,7 @@ public: ...@@ -180,7 +174,7 @@ public:
virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override; virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
sal_IntPtr GetHandle() const { return m_nHandle; } SwAuthEntry* GetAuthEntry() const { return m_xAuthEntry.get(); }
virtual OUString GetDescription() const override; virtual OUString GetDescription() const override;
}; };
......
...@@ -51,7 +51,6 @@ using namespace ::com::sun::star::beans; ...@@ -51,7 +51,6 @@ using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
SwAuthEntry::SwAuthEntry(const SwAuthEntry& rCopy) SwAuthEntry::SwAuthEntry(const SwAuthEntry& rCopy)
: nRefCount(0)
{ {
for(int i = 0; i < AUTH_FIELD_END; ++i) for(int i = 0; i < AUTH_FIELD_END; ++i)
aAuthFields[i] = rCopy.aAuthFields[i]; aAuthFields[i] = rCopy.aAuthFields[i];
...@@ -85,31 +84,24 @@ SwFieldType* SwAuthorityFieldType::Copy() const ...@@ -85,31 +84,24 @@ SwFieldType* SwAuthorityFieldType::Copy() const
return new SwAuthorityFieldType(m_pDoc); return new SwAuthorityFieldType(m_pDoc);
} }
void SwAuthorityFieldType::RemoveField(sal_IntPtr nHandle) void SwAuthorityFieldType::RemoveField(const SwAuthEntry* nHandle)
{ {
for(SwAuthDataArr::size_type j = 0; j < m_DataArr.size(); ++j) for(SwAuthDataArr::size_type j = 0; j < m_DataArr.size(); ++j)
{ {
SwAuthEntry* pTemp = m_DataArr[j].get(); if(m_DataArr[j].get() == nHandle)
sal_IntPtr nRet = reinterpret_cast<sal_IntPtr>(static_cast<void*>(pTemp));
if(nRet == nHandle)
{
pTemp->RemoveRef();
if(!pTemp->GetRefCount())
{ {
m_DataArr.erase(m_DataArr.begin() + j); m_DataArr.erase(m_DataArr.begin() + j);
//re-generate positions of the fields //re-generate positions of the fields
DelSequenceArray(); DelSequenceArray();
}
return; return;
} }
} }
OSL_FAIL("Field unknown" ); OSL_FAIL("Field unknown" );
} }
sal_IntPtr SwAuthorityFieldType::AddField(const OUString& rFieldContents) SwAuthEntry* SwAuthorityFieldType::AddField(const OUString& rFieldContents)
{ {
sal_IntPtr nRet = 0; rtl::Reference<SwAuthEntry> pEntry(new SwAuthEntry);
std::unique_ptr<SwAuthEntry> pEntry(new SwAuthEntry);
for( sal_Int32 i = 0; i < AUTH_FIELD_END; ++i ) for( sal_Int32 i = 0; i < AUTH_FIELD_END; ++i )
pEntry->SetAuthorField( static_cast<ToxAuthorityField>(i), pEntry->SetAuthorField( static_cast<ToxAuthorityField>(i),
rFieldContents.getToken( i, TOX_STYLE_DELIMITER )); rFieldContents.getToken( i, TOX_STYLE_DELIMITER ));
...@@ -118,50 +110,15 @@ sal_IntPtr SwAuthorityFieldType::AddField(const OUString& rFieldContents) ...@@ -118,50 +110,15 @@ sal_IntPtr SwAuthorityFieldType::AddField(const OUString& rFieldContents)
{ {
if (*rpTemp == *pEntry) if (*rpTemp == *pEntry)
{ {
nRet = reinterpret_cast<sal_IntPtr>(static_cast<void*>(rpTemp.get())); return rpTemp.get();
rpTemp->AddRef();
return nRet;
} }
} }
//if it is a new Entry - insert //if it is a new Entry - insert
nRet = reinterpret_cast<sal_IntPtr>(static_cast<void*>(pEntry.get()));
// FIXME: what is this ref-counting madness on a object owned by the container?
pEntry->AddRef();
m_DataArr.push_back(std::move(pEntry)); m_DataArr.push_back(std::move(pEntry));
//re-generate positions of the fields //re-generate positions of the fields
DelSequenceArray(); DelSequenceArray();
return nRet; return m_DataArr.back().get();
}
void SwAuthorityFieldType::AddField(sal_IntPtr nHandle)
{
for (auto &rpTemp : m_DataArr)
{
sal_IntPtr nTmp = reinterpret_cast<sal_IntPtr>(static_cast<void*>(rpTemp.get()));
if( nTmp == nHandle )
{
rpTemp->AddRef();
//re-generate positions of the fields
DelSequenceArray();
return;
}
}
OSL_FAIL("SwAuthorityFieldType::AddField(sal_IntPtr) failed");
}
const SwAuthEntry* SwAuthorityFieldType::GetEntryByHandle(sal_IntPtr nHandle) const
{
for (auto &rpTemp : m_DataArr)
{
sal_IntPtr nTmp = reinterpret_cast<sal_IntPtr>(static_cast<void const *>(rpTemp.get()));
if( nTmp == nHandle )
{
return rpTemp.get();
}
}
OSL_FAIL( "invalid Handle" );
return nullptr;
} }
void SwAuthorityFieldType::GetAllEntryIdentifiers( void SwAuthorityFieldType::GetAllEntryIdentifiers(
...@@ -173,7 +130,7 @@ void SwAuthorityFieldType::GetAllEntryIdentifiers( ...@@ -173,7 +130,7 @@ void SwAuthorityFieldType::GetAllEntryIdentifiers(
} }
} }
const SwAuthEntry* SwAuthorityFieldType::GetEntryByIdentifier( SwAuthEntry* SwAuthorityFieldType::GetEntryByIdentifier(
const OUString& rIdentifier)const const OUString& rIdentifier)const
{ {
for (const auto &rpTemp : m_DataArr) for (const auto &rpTemp : m_DataArr)
...@@ -209,30 +166,21 @@ sal_uInt16 SwAuthorityFieldType::AppendField( const SwAuthEntry& rInsert ) ...@@ -209,30 +166,21 @@ sal_uInt16 SwAuthorityFieldType::AppendField( const SwAuthEntry& rInsert )
{ {
for( SwAuthDataArr::size_type nRet = 0; nRet < m_DataArr.size(); ++nRet ) for( SwAuthDataArr::size_type nRet = 0; nRet < m_DataArr.size(); ++nRet )
{ {
SwAuthEntry* pTemp = m_DataArr[ nRet ].get(); if( *m_DataArr[ nRet ] == rInsert )
if( *pTemp == rInsert )
{
//ref count unchanged
return nRet; return nRet;
} }
}
//if it is a new Entry - insert //if it is a new Entry - insert
m_DataArr.push_back(o3tl::make_unique<SwAuthEntry>(rInsert)); m_DataArr.push_back(new SwAuthEntry(rInsert));
return m_DataArr.size()-1; return m_DataArr.size()-1;
} }
sal_IntPtr SwAuthorityFieldType::GetHandle(sal_uInt16 nPos) SwAuthEntry* SwAuthorityFieldType::GetFieldByPos(sal_uInt16 nPos)
{ {
if( nPos < m_DataArr.size() ) return m_DataArr[nPos].get();
{
SwAuthEntry* pTemp = m_DataArr[nPos].get();
return reinterpret_cast<sal_IntPtr>(static_cast<void*>(pTemp));
}
return 0;
} }
sal_uInt16 SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle, sal_uInt16 SwAuthorityFieldType::GetSequencePos(const SwAuthEntry* pAuthEntry,
SwRootFrame const*const pLayout) SwRootFrame const*const pLayout)
{ {
//find the field in a sorted array of handles, //find the field in a sorted array of handles,
...@@ -258,7 +206,7 @@ sal_uInt16 SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle, ...@@ -258,7 +206,7 @@ sal_uInt16 SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle,
if(!pTextField || !pTextField->GetpTextNode()) if(!pTextField || !pTextField->GetpTextNode())
{ {
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
if(nHandle == static_cast<SwAuthorityField*>(pFormatField->GetField())->GetHandle()) if(pAuthEntry == static_cast<SwAuthorityField*>(pFormatField->GetField())->GetAuthEntry())
bCurrentFieldWithoutTextNode = true; bCurrentFieldWithoutTextNode = true;
#endif #endif
continue; continue;
...@@ -326,20 +274,20 @@ sal_uInt16 SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle, ...@@ -326,20 +274,20 @@ sal_uInt16 SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle,
{ {
SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat(); SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField()); SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
m_SequArr.push_back(pAField->GetHandle()); m_SequArr.push_back(pAField->GetAuthEntry());
} }
for (auto & pBase : aSortArrRLHidden) for (auto & pBase : aSortArrRLHidden)
{ {
SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat(); SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField()); SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
m_SequArrRLHidden.push_back(pAField->GetHandle()); m_SequArrRLHidden.push_back(pAField->GetAuthEntry());
} }
} }
//find nHandle //find nHandle
auto const& rSequArr(pLayout && pLayout->IsHideRedlines() ? m_SequArrRLHidden : m_SequArr); auto const& rSequArr(pLayout && pLayout->IsHideRedlines() ? m_SequArrRLHidden : m_SequArr);
for (std::vector<sal_IntPtr>::size_type i = 0; i < rSequArr.size(); ++i) for (std::vector<sal_IntPtr>::size_type i = 0; i < rSequArr.size(); ++i)
{ {
if (rSequArr[i] == nHandle) if (rSequArr[i] == pAuthEntry)
{ {
return i + 1; return i + 1;
} }
...@@ -516,22 +464,21 @@ SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType, ...@@ -516,22 +464,21 @@ SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
, m_nTempSequencePos( -1 ) , m_nTempSequencePos( -1 )
, m_nTempSequencePosRLHidden( -1 ) , m_nTempSequencePosRLHidden( -1 )
{ {
m_nHandle = pInitType->AddField( rFieldContents ); m_xAuthEntry = pInitType->AddField( rFieldContents );
} }
SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType, SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
sal_IntPtr nSetHandle ) SwAuthEntry* pAuthEntry )
: SwField( pInitType ) : SwField( pInitType )
, m_nHandle( nSetHandle ) , m_xAuthEntry( pAuthEntry )
, m_nTempSequencePos( -1 ) , m_nTempSequencePos( -1 )
, m_nTempSequencePosRLHidden( -1 ) , m_nTempSequencePosRLHidden( -1 )
{ {
pInitType->AddField( m_nHandle );
} }
SwAuthorityField::~SwAuthorityField() SwAuthorityField::~SwAuthorityField()
{ {
static_cast<SwAuthorityFieldType* >(GetTyp())->RemoveField(m_nHandle); static_cast<SwAuthorityFieldType* >(GetTyp())->RemoveField(m_xAuthEntry.get());
} }
OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const pLayout) const OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const pLayout) const
...@@ -552,16 +499,15 @@ OUString SwAuthorityField::ConditionalExpandAuthIdentifier( ...@@ -552,16 +499,15 @@ OUString SwAuthorityField::ConditionalExpandAuthIdentifier(
sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines() sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
? m_nTempSequencePosRLHidden : m_nTempSequencePos); ? m_nTempSequencePosRLHidden : m_nTempSequencePos);
if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked()) if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
rnTempSequencePos = pAuthType->GetSequencePos(m_nHandle, pLayout); rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
if (0 <= rnTempSequencePos) if (0 <= rnTempSequencePos)
sRet += OUString::number(rnTempSequencePos); sRet += OUString::number(rnTempSequencePos);
} }
else else
{ {
const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle(m_nHandle);
//TODO: Expand to: identifier, number sequence, ... //TODO: Expand to: identifier, number sequence, ...
if(pEntry) if(m_xAuthEntry)
sRet += pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER); sRet += m_xAuthEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER);
} }
if(pAuthType->GetSuffix()) if(pAuthType->GetSuffix())
sRet += OUStringLiteral1(pAuthType->GetSuffix()); sRet += OUStringLiteral1(pAuthType->GetSuffix());
...@@ -579,16 +525,15 @@ OUString SwAuthorityField::ExpandCitation(ToxAuthorityField eField, ...@@ -579,16 +525,15 @@ OUString SwAuthorityField::ExpandCitation(ToxAuthorityField eField,
sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines() sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
? m_nTempSequencePosRLHidden : m_nTempSequencePos); ? m_nTempSequencePosRLHidden : m_nTempSequencePos);
if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked()) if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
rnTempSequencePos = pAuthType->GetSequencePos(m_nHandle, pLayout); rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
if (0 <= rnTempSequencePos) if (0 <= rnTempSequencePos)
sRet += OUString::number(rnTempSequencePos); sRet += OUString::number(rnTempSequencePos);
} }
else else
{ {
const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle(m_nHandle);
//TODO: Expand to: identifier, number sequence, ... //TODO: Expand to: identifier, number sequence, ...
if(pEntry) if(m_xAuthEntry)
sRet += pEntry->GetAuthorField(eField); sRet += m_xAuthEntry->GetAuthorField(eField);
} }
return sRet; return sRet;
} }
...@@ -596,21 +541,19 @@ OUString SwAuthorityField::ExpandCitation(ToxAuthorityField eField, ...@@ -596,21 +541,19 @@ OUString SwAuthorityField::ExpandCitation(ToxAuthorityField eField,
std::unique_ptr<SwField> SwAuthorityField::Copy() const std::unique_ptr<SwField> SwAuthorityField::Copy() const
{ {
SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp()); SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
return o3tl::make_unique<SwAuthorityField>(pAuthType, m_nHandle); return o3tl::make_unique<SwAuthorityField>(pAuthType, m_xAuthEntry.get());
} }
OUString SwAuthorityField::GetFieldText(ToxAuthorityField eField) const OUString SwAuthorityField::GetFieldText(ToxAuthorityField eField) const
{ {
SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp()); return m_xAuthEntry->GetAuthorField( eField );
const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle( m_nHandle );
return pEntry->GetAuthorField( eField );
} }
void SwAuthorityField::SetPar1(const OUString& rStr) void SwAuthorityField::SetPar1(const OUString& rStr)
{ {
SwAuthorityFieldType* pInitType = static_cast<SwAuthorityFieldType* >(GetTyp()); SwAuthorityFieldType* pInitType = static_cast<SwAuthorityFieldType* >(GetTyp());
pInitType->RemoveField(m_nHandle); pInitType->RemoveField(m_xAuthEntry.get());
m_nHandle = pInitType->AddField(rStr); m_xAuthEntry = pInitType->AddField(rStr);
} }
OUString SwAuthorityField::GetDescription() const OUString SwAuthorityField::GetDescription() const
...@@ -657,15 +600,14 @@ bool SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const ...@@ -657,15 +600,14 @@ bool SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const
{ {
if(!GetTyp()) if(!GetTyp())
return false; return false;
const SwAuthEntry* pAuthEntry = static_cast<SwAuthorityFieldType*>(GetTyp())->GetEntryByHandle(m_nHandle); if(!m_xAuthEntry)
if(!pAuthEntry)
return false; return false;
Sequence <PropertyValue> aRet(AUTH_FIELD_END); Sequence <PropertyValue> aRet(AUTH_FIELD_END);
PropertyValue* pValues = aRet.getArray(); PropertyValue* pValues = aRet.getArray();
for(int i = 0; i < AUTH_FIELD_END; ++i) for(int i = 0; i < AUTH_FIELD_END; ++i)
{ {
pValues[i].Name = OUString::createFromAscii(aFieldNames[i]); pValues[i].Name = OUString::createFromAscii(aFieldNames[i]);
const OUString& sField = pAuthEntry->GetAuthorField(static_cast<ToxAuthorityField>(i)); const OUString& sField = m_xAuthEntry->GetAuthorField(static_cast<ToxAuthorityField>(i));
if(i == AUTH_FIELD_AUTHORITY_TYPE) if(i == AUTH_FIELD_AUTHORITY_TYPE)
pValues[i].Value <<= sal_Int16(sField.toInt32()); pValues[i].Value <<= sal_Int16(sField.toInt32());
else else
...@@ -686,7 +628,7 @@ static sal_Int32 lcl_Find(const OUString& rFieldName) ...@@ -686,7 +628,7 @@ static sal_Int32 lcl_Find(const OUString& rFieldName)
bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ ) bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
{ {
if(!GetTyp() || !static_cast<SwAuthorityFieldType*>(GetTyp())->GetEntryByHandle(m_nHandle)) if(!GetTyp() || !m_xAuthEntry)
return false; return false;
Sequence <PropertyValue> aParam; Sequence <PropertyValue> aParam;
...@@ -715,8 +657,8 @@ bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ ) ...@@ -715,8 +657,8 @@ bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
} }
} }
static_cast<SwAuthorityFieldType*>(GetTyp())->RemoveField(m_nHandle); static_cast<SwAuthorityFieldType*>(GetTyp())->RemoveField(m_xAuthEntry.get());
m_nHandle = static_cast<SwAuthorityFieldType*>(GetTyp())->AddField(sToSet); m_xAuthEntry = static_cast<SwAuthorityFieldType*>(GetTyp())->AddField(sToSet);
/* FIXME: it is weird that we always return false here */ /* FIXME: it is weird that we always return false here */
return false; return false;
...@@ -728,12 +670,9 @@ SwFieldType* SwAuthorityField::ChgTyp( SwFieldType* pFieldTyp ) ...@@ -728,12 +670,9 @@ SwFieldType* SwAuthorityField::ChgTyp( SwFieldType* pFieldTyp )
* pDstTyp = static_cast<SwAuthorityFieldType*>(pFieldTyp); * pDstTyp = static_cast<SwAuthorityFieldType*>(pFieldTyp);
if( pSrcTyp != pDstTyp ) if( pSrcTyp != pDstTyp )
{ {
const SwAuthEntry* pSrcEntry = m_xAuthEntry.get();
const SwAuthEntry* pEntry = pSrcTyp->GetEntryByHandle( m_nHandle ); pDstTyp->AppendField( *pSrcEntry );
sal_uInt16 nHdlPos = pDstTyp->AppendField( *pEntry ); pSrcTyp->RemoveField( pSrcEntry );
pSrcTyp->RemoveField( m_nHandle );
m_nHandle = pDstTyp->GetHandle( nHdlPos );
pDstTyp->AddField( m_nHandle );
SwField::ChgTyp( pFieldTyp ); SwField::ChgTyp( pFieldTyp );
} }
return pSrcTyp; return pSrcTyp;
......
...@@ -815,8 +815,8 @@ void SwTOXAuthority::FillText( SwTextNode& rNd, ...@@ -815,8 +815,8 @@ void SwTOXAuthority::FillText( SwTextNode& rNd,
bool SwTOXAuthority::equivalent(const SwTOXSortTabBase& rCmp) bool SwTOXAuthority::equivalent(const SwTOXSortTabBase& rCmp)
{ {
return nType == rCmp.nType && return nType == rCmp.nType &&
static_cast<SwAuthorityField*>(m_rField.GetField())->GetHandle() == static_cast<SwAuthorityField*>(m_rField.GetField())->GetAuthEntry() ==
static_cast<SwAuthorityField*>(static_cast<const SwTOXAuthority&>(rCmp).m_rField.GetField())->GetHandle(); static_cast<SwAuthorityField*>(static_cast<const SwTOXAuthority&>(rCmp).m_rField.GetField())->GetAuthEntry();
} }
bool SwTOXAuthority::sort_lt(const SwTOXSortTabBase& rBase) bool SwTOXAuthority::sort_lt(const SwTOXSortTabBase& rBase)
......
...@@ -1225,10 +1225,10 @@ IMPL_LINK_NOARG(SwAuthorMarkPane, InsertHdl, weld::Button&, void) ...@@ -1225,10 +1225,10 @@ IMPL_LINK_NOARG(SwAuthorMarkPane, InsertHdl, weld::Button&, void)
{ {
if(bDifferent) if(bDifferent)
{ {
SwAuthEntry aNewData; rtl::Reference<SwAuthEntry> xNewData(new SwAuthEntry);
for(int i = 0; i < AUTH_FIELD_END; i++) for(int i = 0; i < AUTH_FIELD_END; i++)
aNewData.SetAuthorField(static_cast<ToxAuthorityField>(i), m_sFields[i]); xNewData->SetAuthorField(static_cast<ToxAuthorityField>(i), m_sFields[i]);
pSh->ChangeAuthorityData(&aNewData); pSh->ChangeAuthorityData(xNewData.get());
} }
SwInsertField_Data aData(TYP_AUTHORITY, 0, sFields.makeStringAndClear(), OUString(), 0 ); SwInsertField_Data aData(TYP_AUTHORITY, 0, sFields.makeStringAndClear(), OUString(), 0 );
aMgr.InsertField( aData ); aMgr.InsertField( aData );
...@@ -1417,8 +1417,7 @@ void SwAuthorMarkPane::InitControls() ...@@ -1417,8 +1417,7 @@ void SwAuthorMarkPane::InitControls()
if(bNewEntry || !pField || pField->GetTyp()->Which() != SwFieldIds::TableOfAuthorities) if(bNewEntry || !pField || pField->GetTyp()->Which() != SwFieldIds::TableOfAuthorities)
return; return;
const SwAuthEntry* pEntry = static_cast<SwAuthorityFieldType*>(pField->GetTyp())-> const SwAuthEntry* pEntry = static_cast<SwAuthorityField*>(pField)->GetAuthEntry();
GetEntryByHandle(static_cast<SwAuthorityField*>(pField)->GetHandle());
OSL_ENSURE(pEntry, "No authority entry found"); OSL_ENSURE(pEntry, "No authority entry found");
if(!pEntry) if(!pEntry)
......
...@@ -1653,17 +1653,17 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat, ...@@ -1653,17 +1653,17 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat,
//#i99069# changes to a bibliography field should change the field type //#i99069# changes to a bibliography field should change the field type
SwAuthorityField* pAuthorityField = static_cast<SwAuthorityField*>(pTmpField.get()); SwAuthorityField* pAuthorityField = static_cast<SwAuthorityField*>(pTmpField.get());
SwAuthorityFieldType* pAuthorityType = static_cast<SwAuthorityFieldType*>(pType); SwAuthorityFieldType* pAuthorityType = static_cast<SwAuthorityFieldType*>(pType);
SwAuthEntry aTempEntry; rtl::Reference<SwAuthEntry> xTempEntry(new SwAuthEntry);
for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i ) for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i )
aTempEntry.SetAuthorField( static_cast<ToxAuthorityField>(i), xTempEntry->SetAuthorField( static_cast<ToxAuthorityField>(i),
rPar1.getToken( i, TOX_STYLE_DELIMITER )); rPar1.getToken( i, TOX_STYLE_DELIMITER ));
if( pAuthorityType->ChangeEntryContent( &aTempEntry ) ) if( pAuthorityType->ChangeEntryContent( xTempEntry.get() ) )
{ {
pType->UpdateFields(); pType->UpdateFields();
pSh->SetModified(); pSh->SetModified();
} }
if( aTempEntry.GetAuthorField( AUTH_FIELD_IDENTIFIER ) == if( xTempEntry->GetAuthorField( AUTH_FIELD_IDENTIFIER ) ==
pAuthorityField->GetFieldText( AUTH_FIELD_IDENTIFIER ) ) pAuthorityField->GetFieldText( AUTH_FIELD_IDENTIFIER ) )
bSetPar1 = false; //otherwise it's a new or changed entry, the field needs to be updated bSetPar1 = false; //otherwise it's a new or changed entry, the field needs to be updated
bSetPar2 = false; bSetPar2 = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment