Kaydet (Commit) 34040b3e authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

use UnoCursorPointer in SwXCellRange and SwChartDataSequence

Change-Id: I23d75d094c2b2dd8d234b608556a8b2339b7f166
üst 30f3315d
...@@ -50,12 +50,12 @@ ...@@ -50,12 +50,12 @@
#include <calbck.hxx> #include <calbck.hxx>
#include <frmfmt.hxx> #include <frmfmt.hxx>
#include <unocrsr.hxx>
class SfxItemPropertySet; class SfxItemPropertySet;
class SwDoc; class SwDoc;
class SwTable; class SwTable;
class SwTableBox; class SwTableBox;
class SwUnoCrsr;
struct SwRangeDescriptor; struct SwRangeDescriptor;
class SwSelBoxes; class SwSelBoxes;
class SwFrameFormat; class SwFrameFormat;
...@@ -265,8 +265,7 @@ class SwChartDataSequence : ...@@ -265,8 +265,7 @@ class SwChartDataSequence :
::com::sun::star::uno::Reference< com::sun::star::chart2::data::XDataProvider > xDataProvider; ::com::sun::star::uno::Reference< com::sun::star::chart2::data::XDataProvider > xDataProvider;
SwChartDataProvider * pDataProvider; SwChartDataProvider * pDataProvider;
std::shared_ptr<SwUnoCrsr> pTableCrsr; // cursor spanned over cells to use sw::UnoCursorPointer pTableCrsr; // cursor spanned over cells to use
SwDepend aCursorDepend; //the cursor is removed after the doc has been removed
const SfxItemPropertySet* _pPropSet; const SfxItemPropertySet* _pPropSet;
...@@ -278,7 +277,6 @@ class SwChartDataSequence : ...@@ -278,7 +277,6 @@ class SwChartDataSequence :
protected: protected:
//SwClient //SwClient
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE;
virtual void SwClientNotify(const SwModify&, const SfxHint&) SAL_OVERRIDE;
public: public:
SwChartDataSequence( SwChartDataProvider &rProvider, SwChartDataSequence( SwChartDataProvider &rProvider,
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
#include <tuple> #include <tuple>
#include <unocrsr.hxx> #include <unocrsr.hxx>
class SwUnoCrsr;
class SwTable; class SwTable;
class SwTableBox; class SwTableBox;
class SwTableLine; class SwTableLine;
...@@ -456,14 +455,13 @@ class SwXCellRange : public cppu::WeakImplHelper ...@@ -456,14 +455,13 @@ class SwXCellRange : public cppu::WeakImplHelper
>, >,
public SwClient public SwClient
{ {
SwDepend aCursorDepend; //the cursor is removed after the doc has been removed
::osl::Mutex m_Mutex; ::osl::Mutex m_Mutex;
::cppu::OInterfaceContainerHelper m_ChartListeners; ::cppu::OInterfaceContainerHelper m_ChartListeners;
SwRangeDescriptor aRgDesc; SwRangeDescriptor aRgDesc;
const SfxItemPropertySet* m_pPropSet; const SfxItemPropertySet* m_pPropSet;
std::shared_ptr<SwUnoCrsr> m_pTableCrsr; sw::UnoCursorPointer m_pTableCrsr;
bool m_bFirstRowAsLabel; bool m_bFirstRowAsLabel;
bool m_bFirstColumnAsLabel; bool m_bFirstColumnAsLabel;
...@@ -472,14 +470,10 @@ class SwXCellRange : public cppu::WeakImplHelper ...@@ -472,14 +470,10 @@ class SwXCellRange : public cppu::WeakImplHelper
void setLabelDescriptions(const css::uno::Sequence<OUString>& rDesc, bool bRow); void setLabelDescriptions(const css::uno::Sequence<OUString>& rDesc, bool bRow);
public: public:
SwXCellRange(std::shared_ptr<SwUnoCrsr> pCrsr, SwFrameFormat& rFrameFormat, SwRangeDescriptor& rDesc); SwXCellRange(sw::UnoCursorPointer pCrsr, SwFrameFormat& rFrameFormat, SwRangeDescriptor& rDesc);
void SetLabels(bool bFirstRowAsLabel, bool bFirstColumnAsLabel) void SetLabels(bool bFirstRowAsLabel, bool bFirstColumnAsLabel)
{ m_bFirstRowAsLabel = bFirstRowAsLabel, m_bFirstColumnAsLabel = bFirstColumnAsLabel; } { m_bFirstRowAsLabel = bFirstRowAsLabel, m_bFirstColumnAsLabel = bFirstColumnAsLabel; }
virtual ~SwXCellRange() virtual ~SwXCellRange() {};
{
if(m_pTableCrsr)
m_pTableCrsr->Remove(&aCursorDepend);
}
std::vector< css::uno::Reference< css::table::XCell > > getCells(); std::vector< css::uno::Reference< css::table::XCell > > getCells();
TYPEINFO_OVERRIDE(); TYPEINFO_OVERRIDE();
...@@ -547,7 +541,6 @@ public: ...@@ -547,7 +541,6 @@ public:
//SwClient //SwClient
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE;
virtual void SwClientNotify(const SwModify&, const SfxHint&) SAL_OVERRIDE;
SwFrameFormat* GetFrameFormat() const { return const_cast<SwFrameFormat*>(static_cast<const SwFrameFormat*>(GetRegisteredIn())); } SwFrameFormat* GetFrameFormat() const { return const_cast<SwFrameFormat*>(static_cast<const SwFrameFormat*>(GetRegisteredIn())); }
sal_uInt16 getRowCount(); sal_uInt16 getRowCount();
......
...@@ -1900,7 +1900,6 @@ SwChartDataSequence::SwChartDataSequence( ...@@ -1900,7 +1900,6 @@ SwChartDataSequence::SwChartDataSequence(
xDataProvider( &rProvider ), xDataProvider( &rProvider ),
pDataProvider( &rProvider ), pDataProvider( &rProvider ),
pTableCrsr( pTableCursor ), pTableCrsr( pTableCursor ),
aCursorDepend( this, pTableCursor.get() ),
_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_CHART2_DATA_SEQUENCE ) ) _pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_CHART2_DATA_SEQUENCE ) )
{ {
bDisposed = false; bDisposed = false;
...@@ -1931,7 +1930,7 @@ SwChartDataSequence::SwChartDataSequence( ...@@ -1931,7 +1930,7 @@ SwChartDataSequence::SwChartDataSequence(
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
// check if it can properly convert into a SwUnoTableCrsr // check if it can properly convert into a SwUnoTableCrsr
// which is required for some functions // which is required for some functions
SwUnoTableCrsr* pUnoTableCrsr = dynamic_cast<SwUnoTableCrsr*>(pTableCrsr.get()); SwUnoTableCrsr* pUnoTableCrsr = dynamic_cast<SwUnoTableCrsr*>(&(*pTableCrsr));
OSL_ENSURE(pUnoTableCrsr, "SwChartDataSequence: cursor not SwUnoTableCrsr"); OSL_ENSURE(pUnoTableCrsr, "SwChartDataSequence: cursor not SwUnoTableCrsr");
(void) pUnoTableCrsr; (void) pUnoTableCrsr;
#endif #endif
...@@ -1947,8 +1946,7 @@ SwChartDataSequence::SwChartDataSequence( const SwChartDataSequence &rObj ) : ...@@ -1947,8 +1946,7 @@ SwChartDataSequence::SwChartDataSequence( const SwChartDataSequence &rObj ) :
aColLabelText( SW_RES(STR_CHART2_COL_LABEL_TEXT) ), aColLabelText( SW_RES(STR_CHART2_COL_LABEL_TEXT) ),
xDataProvider( rObj.pDataProvider ), xDataProvider( rObj.pDataProvider ),
pDataProvider( rObj.pDataProvider ), pDataProvider( rObj.pDataProvider ),
pTableCrsr( dynamic_cast<SwUnoTableCrsr&>(*rObj.pTableCrsr.get()).Clone() ), pTableCrsr( rObj.pTableCrsr ),
aCursorDepend( this, pTableCrsr.get() ),
_pPropSet( rObj._pPropSet ) _pPropSet( rObj._pPropSet )
{ {
bDisposed = false; bDisposed = false;
...@@ -1979,7 +1977,7 @@ SwChartDataSequence::SwChartDataSequence( const SwChartDataSequence &rObj ) : ...@@ -1979,7 +1977,7 @@ SwChartDataSequence::SwChartDataSequence( const SwChartDataSequence &rObj ) :
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
// check if it can properly convert into a SwUnoTableCrsr // check if it can properly convert into a SwUnoTableCrsr
// which is required for some functions // which is required for some functions
SwUnoTableCrsr* pUnoTableCrsr = dynamic_cast<SwUnoTableCrsr*>(pTableCrsr.get()); SwUnoTableCrsr* pUnoTableCrsr = dynamic_cast<SwUnoTableCrsr*>(&(*pTableCrsr));
OSL_ENSURE(pUnoTableCrsr, "SwChartDataSequence: cursor not SwUnoTableCrsr"); OSL_ENSURE(pUnoTableCrsr, "SwChartDataSequence: cursor not SwUnoTableCrsr");
(void) pUnoTableCrsr; (void) pUnoTableCrsr;
#endif #endif
...@@ -2028,11 +2026,7 @@ uno::Sequence< uno::Any > SAL_CALL SwChartDataSequence::getData() ...@@ -2028,11 +2026,7 @@ uno::Sequence< uno::Any > SAL_CALL SwChartDataSequence::getData()
SwRangeDescriptor aDesc; SwRangeDescriptor aDesc;
if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) )) if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) ))
{ {
//!! make copy of pTableCrsr (SwUnoCrsr ) SwXCellRange aRange(pTableCrsr, *pTableFormat, aDesc );
// keep original cursor and make copy of it that gets handed
// over to the SwXCellRange object which takes ownership and
// thus will destroy the copy later.
SwXCellRange aRange( dynamic_cast<SwUnoTableCrsr&>(*pTableCrsr.get()).Clone(), *pTableFormat, aDesc );
aRange.GetDataSequence( &aRes, 0, 0 ); aRange.GetDataSequence( &aRes, 0, 0 );
} }
} }
...@@ -2188,11 +2182,7 @@ uno::Sequence< OUString > SAL_CALL SwChartDataSequence::getTextualData() ...@@ -2188,11 +2182,7 @@ uno::Sequence< OUString > SAL_CALL SwChartDataSequence::getTextualData()
SwRangeDescriptor aDesc; SwRangeDescriptor aDesc;
if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) )) if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) ))
{ {
//!! make copy of pTableCrsr (SwUnoCrsr ) SwXCellRange aRange(pTableCrsr, *pTableFormat, aDesc );
// keep original cursor and make copy of it that gets handed
// over to the SwXCellRange object which takes ownership and
// thus will destroy the copy later.
SwXCellRange aRange( dynamic_cast<SwUnoTableCrsr&>(*pTableCrsr.get()).Clone(), *pTableFormat, aDesc );
aRange.GetDataSequence( 0, &aRes, 0 ); aRange.GetDataSequence( 0, &aRes, 0 );
} }
} }
...@@ -2217,11 +2207,7 @@ uno::Sequence< double > SAL_CALL SwChartDataSequence::getNumericalData() ...@@ -2217,11 +2207,7 @@ uno::Sequence< double > SAL_CALL SwChartDataSequence::getNumericalData()
SwRangeDescriptor aDesc; SwRangeDescriptor aDesc;
if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) )) if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) ))
{ {
//!! make copy of pTableCrsr (SwUnoCrsr ) SwXCellRange aRange(pTableCrsr, *pTableFormat, aDesc );
// keep original cursor and make copy of it that gets handed
// over to the SwXCellRange object which takes ownership and
// thus will destroy the copy later.
SwXCellRange aRange( dynamic_cast<SwUnoTableCrsr&>(*pTableCrsr.get()).Clone(), *pTableFormat, aDesc );
// get numerical values and make an effort to return the // get numerical values and make an effort to return the
// numerical value for text formatted cells // numerical value for text formatted cells
...@@ -2345,9 +2331,9 @@ void SwChartDataSequence::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pN ...@@ -2345,9 +2331,9 @@ void SwChartDataSequence::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pN
ClientModify(this, pOld, pNew ); ClientModify(this, pOld, pNew );
// table was deleted or cursor was deleted // table was deleted or cursor was deleted
if(!GetRegisteredIn() || !aCursorDepend.GetRegisteredIn()) if(!GetRegisteredIn() || !pTableCrsr)
{ {
pTableCrsr.reset(); pTableCrsr.reset(nullptr);
dispose(); dispose();
} }
else else
...@@ -2356,16 +2342,6 @@ void SwChartDataSequence::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pN ...@@ -2356,16 +2342,6 @@ void SwChartDataSequence::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pN
} }
} }
void SwChartDataSequence::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{
SwClient::SwClientNotify(rModify, rHint);
if(typeid(rHint) == typeid(sw::DocDisposingHint))
{
pTableCrsr.reset();
dispose();
}
}
sal_Bool SAL_CALL SwChartDataSequence::isModified( ) sal_Bool SAL_CALL SwChartDataSequence::isModified( )
throw (uno::RuntimeException, std::exception) throw (uno::RuntimeException, std::exception)
{ {
...@@ -2463,7 +2439,7 @@ void SAL_CALL SwChartDataSequence::dispose( ) ...@@ -2463,7 +2439,7 @@ void SAL_CALL SwChartDataSequence::dispose( )
if (pLclRegisteredIn && pLclRegisteredIn->HasWriterListeners()) if (pLclRegisteredIn && pLclRegisteredIn->HasWriterListeners())
{ {
pLclRegisteredIn->Remove(this); pLclRegisteredIn->Remove(this);
pTableCrsr = nullptr; pTableCrsr.reset(nullptr);
} }
} }
...@@ -2629,7 +2605,7 @@ void SwChartDataSequence::FillRangeDesc( SwRangeDescriptor &rRangeDesc ) const ...@@ -2629,7 +2605,7 @@ void SwChartDataSequence::FillRangeDesc( SwRangeDescriptor &rRangeDesc ) const
bool SwChartDataSequence::ExtendTo( bool bExtendCol, bool SwChartDataSequence::ExtendTo( bool bExtendCol,
sal_Int32 nFirstNew, sal_Int32 nCount ) sal_Int32 nFirstNew, sal_Int32 nCount )
{ {
SwUnoTableCrsr* pUnoTableCrsr = dynamic_cast<SwUnoTableCrsr*>(pTableCrsr.get()); SwUnoTableCrsr* pUnoTableCrsr = dynamic_cast<SwUnoTableCrsr*>(&(*pTableCrsr));
if (!pUnoTableCrsr) if (!pUnoTableCrsr)
return false; return false;
......
...@@ -3138,10 +3138,9 @@ uno::Sequence<OUString> SwXCellRange::getSupportedServiceNames() throw( uno::Run ...@@ -3138,10 +3138,9 @@ uno::Sequence<OUString> SwXCellRange::getSupportedServiceNames() throw( uno::Run
"com.sun.star.style.ParagraphPropertiesComplex" }; "com.sun.star.style.ParagraphPropertiesComplex" };
} }
SwXCellRange::SwXCellRange(std::shared_ptr<SwUnoCrsr> pCrsr, SwFrameFormat& rFrameFormat, SwXCellRange::SwXCellRange(sw::UnoCursorPointer pCrsr, SwFrameFormat& rFrameFormat,
SwRangeDescriptor& rDesc) SwRangeDescriptor& rDesc)
: SwClient(&rFrameFormat) : SwClient(&rFrameFormat)
, aCursorDepend(this, nullptr)
, m_ChartListeners(m_Mutex) , m_ChartListeners(m_Mutex)
, aRgDesc(rDesc) , aRgDesc(rDesc)
, m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_RANGE)) , m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_RANGE))
...@@ -3149,7 +3148,6 @@ SwXCellRange::SwXCellRange(std::shared_ptr<SwUnoCrsr> pCrsr, SwFrameFormat& rFra ...@@ -3149,7 +3148,6 @@ SwXCellRange::SwXCellRange(std::shared_ptr<SwUnoCrsr> pCrsr, SwFrameFormat& rFra
, m_bFirstRowAsLabel(false) , m_bFirstRowAsLabel(false)
, m_bFirstColumnAsLabel(false) , m_bFirstColumnAsLabel(false)
{ {
m_pTableCrsr->Add(&aCursorDepend);
aRgDesc.Normalize(); aRgDesc.Normalize();
} }
...@@ -3450,7 +3448,7 @@ uno::Any SwXCellRange::getPropertyValue(const OUString& rPropertyName) ...@@ -3450,7 +3448,7 @@ uno::Any SwXCellRange::getPropertyValue(const OUString& rPropertyName)
RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
0L); 0L);
// first look at the attributes of the cursor // first look at the attributes of the cursor
SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(m_pTableCrsr.get()); SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(&(*m_pTableCrsr));
SwUnoCursorHelper::GetCrsrAttr(pCrsr->GetSelRing(), aSet); SwUnoCursorHelper::GetCrsrAttr(pCrsr->GetSelRing(), aSet);
m_pPropSet->getPropertyValue(*pEntry, aSet, aRet); m_pPropSet->getPropertyValue(*pEntry, aSet, aRet);
} }
...@@ -3865,21 +3863,15 @@ sal_uInt16 SwXCellRange::getRowCount() ...@@ -3865,21 +3863,15 @@ sal_uInt16 SwXCellRange::getRowCount()
const SwUnoCrsr* SwXCellRange::GetTableCrsr() const const SwUnoCrsr* SwXCellRange::GetTableCrsr() const
{ {
SwFrameFormat* pFormat = GetFrameFormat(); SwFrameFormat* pFormat = GetFrameFormat();
return pFormat ? m_pTableCrsr.get() : nullptr; return pFormat ? &(*m_pTableCrsr) : nullptr;
} }
void SwXCellRange::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) void SwXCellRange::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
{ {
ClientModify(this, pOld, pNew ); ClientModify(this, pOld, pNew );
if(!GetRegisteredIn() || !aCursorDepend.GetRegisteredIn()) if(!GetRegisteredIn() || !m_pTableCrsr)
{ {
/* m_pTableCrsr.reset(nullptr);
* Not sure if this will cause a memory leak - this pTableCrsr
* is deleted in SwDoc and segfaults here when deleted again
* if(!aCursorDepend.GetRegisteredIn())
delete pTableCrsr;
*/
m_pTableCrsr.reset();
lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this)); lang::EventObject const ev(static_cast< ::cppu::OWeakObject&>(*this));
m_ChartListeners.disposeAndClear(ev); m_ChartListeners.disposeAndClear(ev);
} }
...@@ -3889,17 +3881,6 @@ void SwXCellRange::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) ...@@ -3889,17 +3881,6 @@ void SwXCellRange::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
} }
} }
void SwXCellRange::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{
//assert(m_pTblCrsr->m_bSaneOwnership);
SwClient::SwClientNotify(rModify, rHint);
if(m_pTableCrsr && typeid(rHint) == typeid(sw::DocDisposingHint))
{
m_pTableCrsr->Remove(&aCursorDepend);
m_pTableCrsr.reset();
}
}
// SwXTableRows // SwXTableRows
OUString SwXTableRows::getImplementationName() throw( uno::RuntimeException, std::exception ) OUString SwXTableRows::getImplementationName() throw( uno::RuntimeException, std::exception )
......
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